#define MAX_PINS 32 /* 64 later, when known ok */
-struct nsc_gpio_ops scx200_access = {
+struct nsc_gpio_ops scx200_gpio_ops = {
.owner = THIS_MODULE,
.gpio_config = scx200_gpio_configure,
.gpio_dump = nsc_gpio_dump,
.gpio_get = scx200_gpio_get,
.gpio_set = scx200_gpio_set,
- .gpio_set_high = scx200_gpio_set_high,
- .gpio_set_low = scx200_gpio_set_low,
.gpio_change = scx200_gpio_change,
.gpio_current = scx200_gpio_current
};
-EXPORT_SYMBOL(scx200_access);
+EXPORT_SYMBOL_GPL(scx200_gpio_ops);
static int scx200_gpio_open(struct inode *inode, struct file *file)
{
unsigned m = iminor(inode);
- file->private_data = &scx200_access;
+ file->private_data = &scx200_gpio_ops;
if (m >= MAX_PINS)
return -EINVAL;
return 0;
}
-
-static const struct file_operations scx200_gpio_fops = {
+static const struct file_operations scx200_gpio_fileops = {
.owner = THIS_MODULE,
.write = nsc_gpio_write,
.read = nsc_gpio_read,
.release = scx200_gpio_release,
};
-struct cdev *scx200_devices;
+static struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
static int __init scx200_gpio_init(void)
{
- int rc, i;
+ int rc;
dev_t devid;
if (!scx200_gpio_present()) {
goto undo_malloc;
/* nsc_gpio uses dev_dbg(), so needs this */
- scx200_access.dev = &pdev->dev;
+ scx200_gpio_ops.dev = &pdev->dev;
if (major) {
devid = MKDEV(major, 0);
dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
goto undo_platform_device_add;
}
- scx200_devices = kzalloc(MAX_PINS * sizeof(struct cdev), GFP_KERNEL);
- if (!scx200_devices) {
- rc = -ENOMEM;
- goto undo_chrdev_region;
- }
- for (i = 0; i < MAX_PINS; i++) {
- struct cdev *cdev = &scx200_devices[i];
- cdev_init(cdev, &scx200_gpio_fops);
- cdev->owner = THIS_MODULE;
- rc = cdev_add(cdev, MKDEV(major, i), 1);
- /* tolerate 'minor' errors */
- if (rc)
- dev_err(&pdev->dev, "Error %d on minor %d", rc, i);
- }
+
+ cdev_init(&scx200_gpio_cdev, &scx200_gpio_fileops);
+ cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
return 0; /* succeed */
-undo_chrdev_region:
- unregister_chrdev_region(devid, MAX_PINS);
undo_platform_device_add:
platform_device_del(pdev);
undo_malloc:
static void __exit scx200_gpio_cleanup(void)
{
- kfree(scx200_devices);
+ cdev_del(&scx200_gpio_cdev);
+ /* cdev_put(&scx200_gpio_cdev); */
+
unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
platform_device_unregister(pdev);
}