Commit 2260c419 authored by Sudip Mukherjee's avatar Sudip Mukherjee Committed by Dmitry Torokhov

Input: db9 - use parallel port device model

Modify db9 driver to use the new Parallel Port device model.
Signed-off-by: default avatarSudip Mukherjee <sudip@vectorindia.org>
Tested-By: default avatarPali Rohár <pali.rohar@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 09bb4319
...@@ -48,7 +48,7 @@ struct db9_config { ...@@ -48,7 +48,7 @@ struct db9_config {
}; };
#define DB9_MAX_PORTS 3 #define DB9_MAX_PORTS 3
static struct db9_config db9_cfg[DB9_MAX_PORTS] __initdata; static struct db9_config db9_cfg[DB9_MAX_PORTS];
module_param_array_named(dev, db9_cfg[0].args, int, &db9_cfg[0].nargs, 0); module_param_array_named(dev, db9_cfg[0].args, int, &db9_cfg[0].nargs, 0);
MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)"); MODULE_PARM_DESC(dev, "Describes first attached device (<parport#>,<type>)");
...@@ -106,6 +106,7 @@ struct db9 { ...@@ -106,6 +106,7 @@ struct db9 {
struct pardevice *pd; struct pardevice *pd;
int mode; int mode;
int used; int used;
int parportno;
struct mutex mutex; struct mutex mutex;
char phys[DB9_MAX_DEVICES][32]; char phys[DB9_MAX_DEVICES][32];
}; };
...@@ -553,54 +554,60 @@ static void db9_close(struct input_dev *dev) ...@@ -553,54 +554,60 @@ static void db9_close(struct input_dev *dev)
mutex_unlock(&db9->mutex); mutex_unlock(&db9->mutex);
} }
static struct db9 __init *db9_probe(int parport, int mode) static void db9_attach(struct parport *pp)
{ {
struct db9 *db9; struct db9 *db9;
const struct db9_mode_data *db9_mode; const struct db9_mode_data *db9_mode;
struct parport *pp;
struct pardevice *pd; struct pardevice *pd;
struct input_dev *input_dev; struct input_dev *input_dev;
int i, j; int i, j;
int err; int mode;
struct pardev_cb db9_parport_cb;
for (i = 0; i < DB9_MAX_PORTS; i++) {
if (db9_cfg[i].nargs == 0 ||
db9_cfg[i].args[DB9_ARG_PARPORT] < 0)
continue;
if (db9_cfg[i].args[DB9_ARG_PARPORT] == pp->number)
break;
}
if (i == DB9_MAX_PORTS) {
pr_debug("Not using parport%d.\n", pp->number);
return;
}
mode = db9_cfg[i].args[DB9_ARG_MODE];
if (mode < 1 || mode >= DB9_MAX_PAD || !db9_modes[mode].n_buttons) { if (mode < 1 || mode >= DB9_MAX_PAD || !db9_modes[mode].n_buttons) {
printk(KERN_ERR "db9.c: Bad device type %d\n", mode); printk(KERN_ERR "db9.c: Bad device type %d\n", mode);
err = -EINVAL; return;
goto err_out;
} }
db9_mode = &db9_modes[mode]; db9_mode = &db9_modes[mode];
pp = parport_find_number(parport);
if (!pp) {
printk(KERN_ERR "db9.c: no such parport\n");
err = -ENODEV;
goto err_out;
}
if (db9_mode->bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) { if (db9_mode->bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) {
printk(KERN_ERR "db9.c: specified parport is not bidirectional\n"); printk(KERN_ERR "db9.c: specified parport is not bidirectional\n");
err = -EINVAL; return;
goto err_put_pp;
} }
pd = parport_register_device(pp, "db9", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); db9_parport_cb.flags = PARPORT_FLAG_EXCL;
pd = parport_register_dev_model(pp, "db9", &db9_parport_cb, i);
if (!pd) { if (!pd) {
printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n"); printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n");
err = -EBUSY; return;
goto err_put_pp;
} }
db9 = kzalloc(sizeof(struct db9), GFP_KERNEL); db9 = kzalloc(sizeof(struct db9), GFP_KERNEL);
if (!db9) { if (!db9)
printk(KERN_ERR "db9.c: Not enough memory\n");
err = -ENOMEM;
goto err_unreg_pardev; goto err_unreg_pardev;
}
mutex_init(&db9->mutex); mutex_init(&db9->mutex);
db9->pd = pd; db9->pd = pd;
db9->mode = mode; db9->mode = mode;
db9->parportno = pp->number;
init_timer(&db9->timer); init_timer(&db9->timer);
db9->timer.data = (long) db9; db9->timer.data = (long) db9;
db9->timer.function = db9_timer; db9->timer.function = db9_timer;
...@@ -610,7 +617,6 @@ static struct db9 __init *db9_probe(int parport, int mode) ...@@ -610,7 +617,6 @@ static struct db9 __init *db9_probe(int parport, int mode)
db9->dev[i] = input_dev = input_allocate_device(); db9->dev[i] = input_dev = input_allocate_device();
if (!input_dev) { if (!input_dev) {
printk(KERN_ERR "db9.c: Not enough memory for input device\n"); printk(KERN_ERR "db9.c: Not enough memory for input device\n");
err = -ENOMEM;
goto err_unreg_devs; goto err_unreg_devs;
} }
...@@ -639,13 +645,12 @@ static struct db9 __init *db9_probe(int parport, int mode) ...@@ -639,13 +645,12 @@ static struct db9 __init *db9_probe(int parport, int mode)
input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0); input_set_abs_params(input_dev, db9_abs[j], 1, 255, 0, 0);
} }
err = input_register_device(input_dev); if (input_register_device(input_dev))
if (err)
goto err_free_dev; goto err_free_dev;
} }
parport_put_port(pp); db9_base[i] = db9;
return db9; return;
err_free_dev: err_free_dev:
input_free_device(db9->dev[i]); input_free_device(db9->dev[i]);
...@@ -655,15 +660,22 @@ static struct db9 __init *db9_probe(int parport, int mode) ...@@ -655,15 +660,22 @@ static struct db9 __init *db9_probe(int parport, int mode)
kfree(db9); kfree(db9);
err_unreg_pardev: err_unreg_pardev:
parport_unregister_device(pd); parport_unregister_device(pd);
err_put_pp:
parport_put_port(pp);
err_out:
return ERR_PTR(err);
} }
static void db9_remove(struct db9 *db9) static void db9_detach(struct parport *port)
{ {
int i; int i;
struct db9 *db9;
for (i = 0; i < DB9_MAX_PORTS; i++) {
if (db9_base[i] && db9_base[i]->parportno == port->number)
break;
}
if (i == DB9_MAX_PORTS)
return;
db9 = db9_base[i];
for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++) for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++)
input_unregister_device(db9->dev[i]); input_unregister_device(db9->dev[i]);
...@@ -671,11 +683,17 @@ static void db9_remove(struct db9 *db9) ...@@ -671,11 +683,17 @@ static void db9_remove(struct db9 *db9)
kfree(db9); kfree(db9);
} }
static struct parport_driver db9_parport_driver = {
.name = "db9",
.match_port = db9_attach,
.detach = db9_detach,
.devmodel = true,
};
static int __init db9_init(void) static int __init db9_init(void)
{ {
int i; int i;
int have_dev = 0; int have_dev = 0;
int err = 0;
for (i = 0; i < DB9_MAX_PORTS; i++) { for (i = 0; i < DB9_MAX_PORTS; i++) {
if (db9_cfg[i].nargs == 0 || db9_cfg[i].args[DB9_ARG_PARPORT] < 0) if (db9_cfg[i].nargs == 0 || db9_cfg[i].args[DB9_ARG_PARPORT] < 0)
...@@ -683,37 +701,21 @@ static int __init db9_init(void) ...@@ -683,37 +701,21 @@ static int __init db9_init(void)
if (db9_cfg[i].nargs < 2) { if (db9_cfg[i].nargs < 2) {
printk(KERN_ERR "db9.c: Device type must be specified.\n"); printk(KERN_ERR "db9.c: Device type must be specified.\n");
err = -EINVAL; return -EINVAL;
break;
}
db9_base[i] = db9_probe(db9_cfg[i].args[DB9_ARG_PARPORT],
db9_cfg[i].args[DB9_ARG_MODE]);
if (IS_ERR(db9_base[i])) {
err = PTR_ERR(db9_base[i]);
break;
} }
have_dev = 1; have_dev = 1;
} }
if (err) { if (!have_dev)
while (--i >= 0) return -ENODEV;
if (db9_base[i])
db9_remove(db9_base[i]);
return err;
}
return have_dev ? 0 : -ENODEV; return parport_register_driver(&db9_parport_driver);
} }
static void __exit db9_exit(void) static void __exit db9_exit(void)
{ {
int i; parport_unregister_driver(&db9_parport_driver);
for (i = 0; i < DB9_MAX_PORTS; i++)
if (db9_base[i])
db9_remove(db9_base[i]);
} }
module_init(db9_init); module_init(db9_init);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment