2 * arch/sh/boards/landisk/landisk_pwb.c -- driver for the Power control switch.
4 * This driver will also support the I-O DATA Device, Inc. LANDISK Board.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copylight (C) 2002 Atom Create Engineering Co., Ltd.
12 * LED control drive function added by kogiidena
14 #include <linux/module.h>
15 #include <linux/errno.h>
16 #include <linux/signal.h>
17 #include <linux/major.h>
18 #include <linux/poll.h>
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/sched.h>
22 #include <linux/timer.h>
23 #include <linux/interrupt.h>
25 #include <asm/system.h>
28 #include <asm/uaccess.h>
29 #include <asm/landisk/iodata_landisk.h>
31 #define SHUTDOWN_BTN_MINOR 1 /* Shutdown button device minor no. */
32 #define LED_MINOR 21 /* LED minor no. */
33 #define BTN_MINOR 22 /* BUTTON minor no. */
34 #define GIO_MINOR 40 /* GIO minor no. */
37 static int openCntLED
;
38 static int openCntGio
;
39 static int openCntBtn
;
40 static int landisk_btn
;
41 static int landisk_btnctrlpid
;
43 * Functions prototypes
46 static int gio_ioctl(struct inode
*inode
, struct file
*filp
, unsigned int cmd
,
49 static int swdrv_open(struct inode
*inode
, struct file
*filp
)
53 minor
= MINOR(inode
->i_rdev
);
54 filp
->private_data
= (void *)minor
;
56 if (minor
== SHUTDOWN_BTN_MINOR
) {
63 } else if (minor
== LED_MINOR
) {
70 } else if (minor
== BTN_MINOR
) {
77 } else if (minor
== GIO_MINOR
) {
89 static int swdrv_close(struct inode
*inode
, struct file
*filp
)
93 minor
= MINOR(inode
->i_rdev
);
94 if (minor
== SHUTDOWN_BTN_MINOR
) {
96 } else if (minor
== LED_MINOR
) {
98 } else if (minor
== BTN_MINOR
) {
100 } else if (minor
== GIO_MINOR
) {
106 static int swdrv_read(struct file
*filp
, char *buff
, size_t count
,
110 minor
= (int)(filp
->private_data
);
112 if (!access_ok(VERIFY_WRITE
, (void *)buff
, count
))
115 if (minor
== SHUTDOWN_BTN_MINOR
) {
116 if (landisk_btn
& 0x10) {
126 static int swdrv_write(struct file
*filp
, const char *buff
, size_t count
,
130 minor
= (int)(filp
->private_data
);
132 if (minor
== SHUTDOWN_BTN_MINOR
) {
138 static irqreturn_t
sw_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
140 landisk_btn
= (0x0ff & (~ctrl_inb(PA_STATUS
)));
141 disable_irq(IRQ_BUTTON
);
142 disable_irq(IRQ_POWER
);
143 ctrl_outb(0x00, PA_PWRINT_CLR
);
145 if (landisk_btnctrlpid
!= 0) {
146 kill_proc(landisk_btnctrlpid
, SIGUSR1
, 1);
147 landisk_btnctrlpid
= 0;
153 static struct file_operations swdrv_fops
= {
154 .read
= swdrv_read
, /* read */
155 .write
= swdrv_write
, /* write */
156 .open
= swdrv_open
, /* open */
157 .release
= swdrv_close
, /* release */
158 .ioctl
= gio_ioctl
, /* ioctl */
162 static char banner
[] __initdata
=
163 KERN_INFO
"LANDISK and USL-5P Button, LED and GIO driver initialized\n";
165 int __init
swdrv_init(void)
169 printk("%s", banner
);
176 landisk_btnctrlpid
= 0;
178 if ((error
= register_chrdev(SHUTDOWN_BTN_MAJOR
, "swdrv", &swdrv_fops
))) {
180 "Button, LED and GIO driver:Couldn't register driver, error=%d\n",
185 if (request_irq(IRQ_POWER
, sw_interrupt
, 0, "SHUTDOWNSWITCH", NULL
)) {
186 printk(KERN_ERR
"Unable to get IRQ 11.\n");
189 if (request_irq(IRQ_BUTTON
, sw_interrupt
, 0, "USL-5P BUTTON", NULL
)) {
190 printk(KERN_ERR
"Unable to get IRQ 12.\n");
193 ctrl_outb(0x00, PA_PWRINT_CLR
);
198 module_init(swdrv_init
);
205 #include <asm/landisk/gio.h>
207 static int gio_ioctl(struct inode
*inode
, struct file
*filp
,
208 unsigned int cmd
, unsigned long arg
)
211 unsigned int data
, mask
;
212 static unsigned int addr
= 0;
214 minor
= (int)(filp
->private_data
);
217 if (minor
== GIO_MINOR
) {
219 } else if (minor
== LED_MINOR
) {
220 if (((cmd
& 0x0ff) >= 9) && ((cmd
& 0x0ff) < 20)) {
225 } else if (minor
== BTN_MINOR
) {
226 if (((cmd
& 0x0ff) >= 20) && ((cmd
& 0x0ff) < 30)) {
235 if (cmd
& 0x01) { /* write */
236 if (copy_from_user(&data
, (int *)arg
, sizeof(int))) {
242 case GIODRV_IOCSGIOSETADDR
: /* addres set */
246 case GIODRV_IOCSGIODATA1
: /* write byte */
247 ctrl_outb((unsigned char)(0x0ff & data
), addr
);
250 case GIODRV_IOCSGIODATA2
: /* write word */
254 ctrl_outw((unsigned short int)(0x0ffff & data
), addr
);
257 case GIODRV_IOCSGIODATA4
: /* write long */
261 ctrl_outl(data
, addr
);
264 case GIODRV_IOCGGIODATA1
: /* read byte */
265 data
= ctrl_inb(addr
);
268 case GIODRV_IOCGGIODATA2
: /* read word */
272 data
= ctrl_inw(addr
);
275 case GIODRV_IOCGGIODATA4
: /* read long */
279 data
= ctrl_inl(addr
);
281 case GIODRV_IOCSGIO_LED
: /* write */
282 mask
= ((data
& 0x00ffffff) << 8)
283 | ((data
& 0x0000ffff) << 16)
284 | ((data
& 0x000000ff) << 24);
285 landisk_ledparam
= data
& (~mask
);
286 if (landisk_arch
== 0) { /* arch == landisk */
287 landisk_ledparam
&= 0x03030303;
288 mask
= (~(landisk_ledparam
>> 22)) & 0x000c;
289 landisk_ledparam
|= mask
;
290 } else { /* arch == usl-5p */
291 mask
= (landisk_ledparam
>> 24) & 0x0001;
292 landisk_ledparam
|= mask
;
293 landisk_ledparam
&= 0x007f7f7f;
295 landisk_ledparam
|= 0x80;
297 case GIODRV_IOCGGIO_LED
: /* read */
298 data
= landisk_ledparam
;
299 if (landisk_arch
== 0) { /* arch == landisk */
301 } else { /* arch == usl-5p */
306 case GIODRV_IOCSGIO_BUZZER
: /* write */
307 landisk_buzzerparam
= data
;
308 landisk_ledparam
|= 0x80;
310 case GIODRV_IOCGGIO_LANDISK
: /* read */
311 data
= landisk_arch
& 0x01;
313 case GIODRV_IOCGGIO_BTN
: /* read */
314 data
= (0x0ff & ctrl_inb(PA_PWRINT_CLR
));
316 data
|= (0x0ff & ctrl_inb(PA_IMASK
));
318 data
|= (0x0ff & landisk_btn
);
320 data
|= (0x0ff & (~ctrl_inb(PA_STATUS
)));
322 case GIODRV_IOCSGIO_BTNPID
: /* write */
323 landisk_btnctrlpid
= data
;
325 if (irq_desc
[IRQ_BUTTON
].depth
) {
326 enable_irq(IRQ_BUTTON
);
328 if (irq_desc
[IRQ_POWER
].depth
) {
329 enable_irq(IRQ_POWER
);
332 case GIODRV_IOCGGIO_BTNPID
: /* read */
333 data
= landisk_btnctrlpid
;
340 if ((cmd
& 0x01) == 0) { /* read */
341 if (copy_to_user((int *)arg
, &data
, sizeof(int))) {