1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/boards/landisk/gio.c - driver for landisk
5 * This driver will also support the I-O DATA Device, Inc. LANDISK Board.
6 * LANDISK and USL-5P Button, LED and GIO driver drive function.
8 * Copylight (C) 2006 kogiidena
9 * Copylight (C) 2002 Atom Create Engineering Co., Ltd. *
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/kdev_t.h>
14 #include <linux/cdev.h>
17 #include <linux/uaccess.h>
18 #include <mach-landisk/mach/gio.h>
19 #include <mach-landisk/mach/iodata_landisk.h>
22 #define GIO_MINOR 2 /* GIO minor no. */
25 static struct cdev
*cdev_p
;
28 static int gio_open(struct inode
*inode
, struct file
*filp
)
34 minor
= MINOR(inode
->i_rdev
);
35 if (minor
< DEVCOUNT
) {
47 static int gio_close(struct inode
*inode
, struct file
*filp
)
51 minor
= MINOR(inode
->i_rdev
);
52 if (minor
< DEVCOUNT
) {
58 static long gio_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
61 static unsigned int addr
= 0;
63 if (cmd
& 0x01) { /* write */
64 if (copy_from_user(&data
, (int *)arg
, sizeof(int))) {
70 case GIODRV_IOCSGIOSETADDR
: /* address set */
74 case GIODRV_IOCSGIODATA1
: /* write byte */
75 __raw_writeb((unsigned char)(0x0ff & data
), addr
);
78 case GIODRV_IOCSGIODATA2
: /* write word */
82 __raw_writew((unsigned short int)(0x0ffff & data
), addr
);
85 case GIODRV_IOCSGIODATA4
: /* write long */
89 __raw_writel(data
, addr
);
92 case GIODRV_IOCGGIODATA1
: /* read byte */
93 data
= __raw_readb(addr
);
96 case GIODRV_IOCGGIODATA2
: /* read word */
100 data
= __raw_readw(addr
);
103 case GIODRV_IOCGGIODATA4
: /* read long */
107 data
= __raw_readl(addr
);
114 if ((cmd
& 0x01) == 0) { /* read */
115 if (copy_to_user((int *)arg
, &data
, sizeof(int))) {
122 static const struct file_operations gio_fops
= {
123 .owner
= THIS_MODULE
,
124 .open
= gio_open
, /* open */
125 .release
= gio_close
, /* release */
126 .unlocked_ioctl
= gio_ioctl
,
127 .llseek
= noop_llseek
,
130 static int __init
gio_init(void)
134 printk(KERN_INFO
"gio: driver initialized\n");
138 if ((error
= alloc_chrdev_region(&dev
, 0, DEVCOUNT
, "gio")) < 0) {
140 "gio: Couldn't alloc_chrdev_region, error=%d\n",
145 cdev_p
= cdev_alloc();
146 cdev_p
->ops
= &gio_fops
;
147 error
= cdev_add(cdev_p
, dev
, DEVCOUNT
);
150 "gio: Couldn't cdev_add, error=%d\n", error
);
157 static void __exit
gio_exit(void)
160 unregister_chrdev_region(dev
, DEVCOUNT
);
163 module_init(gio_init
);
164 module_exit(gio_exit
);
166 MODULE_LICENSE("GPL");