Subject: BCR as a device

From: Chan Tak Shing Thomas <[email-masked]>
Date: Wed, 17 May 2000 20:14:08 +0800 (CST)

Hi folks,

     I've got a tiny tool for Assabet which might be useful for
some of you.  You can use this device to set the BCR bits and it
can be quite handy for debugging purposes.  Source below.

     I assume you're using linux-2.3.99-pre6-rmk1-np1 or later.

Enjoy,
Tak-Shing Chan

/*
 * arch/arm/special/cbd.c
 * Chan's BCR Device.
 * Use it to set or clear an individial bit of the BCR.
 *
 * Compiling:
 * 1. Add the following to arch/arm/special/Makefile (right in
 *    front of the ``# Common dependencies'' line):
 *
 *     ifdef CONFIG_SA1100_ASSABET
 *         L_OBJS  += cbd.o
 *     endif
 *
 * 2. Add the following to drivers/char/mem.c (right in front of
 *    the ``return 0'' line at char_dev_init()):
 *
 *     #ifdef CONFIG_SA1100_ASSABET
 *     {
 *         extern int cbd_init(void);
 *         cbd_init();
 *     }
 *     #endif
 *
 * 3. make dep && make zImage
 *
 * Usage:
 * Lookup name of the Nth bit:	echo n > /dev/bcrN
 * Turn off the Nth bit:	echo 0 > /dev/bcrN
 * Turn on the Nth bit:		echo 1 > /dev/bcrN
 *
 * Example:
 * Mess up my 16 bpp screen:	echo 1 > /dev/bcr10
 * Turn off the LCD:		echo 0 > /dev/bcr11
 */

#include <linux/fs.h>
#include <linux/errno.h>
#include <asm/hardware.h>

/*
 * Change this to anything you want.  Don't forget to
 * ``mknod /dev/bcrN c BCR_MAJOR N'' before you start (for all N
 * from 0 to 23).
 */
#define BCR_MAJOR		66

/*
 * Taken from Table 4-6 (pp. 4-11 to 4-14), Intel(R) StrongARM(R)
 * SA-1110 Microprocessor Development Board User's Guide.
 */
static const char *
bcr_name[] = {
    "CF_PWR",
    "CF_RST/GFX_RST",
    "SOFT_RST",
    "IRDA_FSEL",
    "IRDA_MD[0]",
    "IRDA_MD[1]",
    "Stereo_LB",
    "CF_Bus_On",
    "Audio_On",
    "Light",
    "LCD12or16",
    "LCD On",
    "RS232En",
    "D9_LED",
    "D8_LED",
    "Vib_On",
    "COM_DTR",
    "COM_RTS",
    "Rad_WU",
    "SMB_En",
    "TV_IR_Dec_En",
    "Qmute",
    "Rad_On",
    "Spk_Off"
};

static ssize_t
bcr_write(struct file *file, const char *buffer, size_t count, loff_t *pos)
{
    unsigned int bit = MINOR(file->f_dentry->d_inode->i_rdev);
    if (bit < 24) {
	switch (*buffer) {
	case 'n':
	    printk("ncr%u: my name is %s\n", bit, bcr_name[bit]);
	    return count;
	case '0':
	    BCR_clear(1 << bit);
	    printk("bcr%u: cleared\n", bit);
	    return count;
	case '1':
	    BCR_set(1 << bit);
	    printk("bcr%u: set\n", bit);
	    return count;
	}
    }
    return -EINVAL;
}

static struct file_operations
cbd_fops = {
    write: bcr_write
};

int
cbd_init(void)
{
    return register_chrdev(BCR_MAJOR, "cbd", &cbd_fops);
}

unsubscribe: body of `unsubscribe linux-arm-kernel' to [email-masked]