i2c-parport: define ports to connect
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Wed, 20 May 2015 15:26:59 +0000 (20:56 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 31 May 2015 22:08:19 +0000 (07:08 +0900)
As of now i2c-parport was connecting to all the available parallel
ports. Lets limit that to maximum of 4 instances and at the same time
define which instance connects to which parallel port.

Tested-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Acked-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/i2c/busses/i2c-parport.c

index a1fac5a..155da95 100644 (file)
@@ -46,6 +46,9 @@ struct i2c_par {
 
 static LIST_HEAD(adapter_list);
 static DEFINE_MUTEX(adapter_list_lock);
+#define MAX_DEVICE 4
+static int parport[MAX_DEVICE] = {0, -1, -1, -1};
+
 
 /* ----- Low-level parallel port access ----------------------------------- */
 
@@ -163,6 +166,19 @@ static void i2c_parport_irq(void *data)
 static void i2c_parport_attach(struct parport *port)
 {
        struct i2c_par *adapter;
+       int i;
+       struct pardev_cb i2c_parport_cb;
+
+       for (i = 0; i < MAX_DEVICE; i++) {
+               if (parport[i] == -1)
+                       continue;
+               if (port->number == parport[i])
+                       break;
+       }
+       if (i == MAX_DEVICE) {
+               pr_debug("i2c-parport: Not using parport%d.\n", port->number);
+               return;
+       }
 
        adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL);
        if (adapter == NULL) {
@@ -298,5 +314,12 @@ MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
 MODULE_DESCRIPTION("I2C bus over parallel port");
 MODULE_LICENSE("GPL");
 
+module_param_array(parport, int, NULL, 0);
+MODULE_PARM_DESC(parport,
+                "List of parallel ports to bind to, by index.\n"
+                " Atmost " __stringify(MAX_DEVICE) " devices are supported.\n"
+                " Default is one device connected to parport0.\n"
+);
+
 module_init(i2c_parport_init);
 module_exit(i2c_parport_exit);