--- zzzz-none-000/linux-3.10.107/drivers/i2c/busses/i2c-parport.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/i2c/busses/i2c-parport.c 2021-02-04 17:41:59.000000000 +0000 @@ -1,7 +1,7 @@ /* ------------------------------------------------------------------------ * * i2c-parport.c I2C bus over parallel port * * ------------------------------------------------------------------------ * - Copyright (C) 2003-2011 Jean Delvare + Copyright (C) 2003-2011 Jean Delvare Based on older i2c-philips-par.c driver Copyright (C) 1995-2000 Simon G. Vogl @@ -18,12 +18,10 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * ------------------------------------------------------------------------ */ +#define pr_fmt(fmt) "i2c-parport: " fmt + #include #include #include @@ -50,6 +48,9 @@ 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 ----------------------------------- */ @@ -167,19 +168,34 @@ static void i2c_parport_attach(struct parport *port) { struct i2c_par *adapter; + int i; + struct pardev_cb i2c_parport_cb; - adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL); - if (adapter == NULL) { - printk(KERN_ERR "i2c-parport: Failed to kzalloc\n"); + for (i = 0; i < MAX_DEVICE; i++) { + if (parport[i] == -1) + continue; + if (port->number == parport[i]) + break; + } + if (i == MAX_DEVICE) { + pr_debug("Not using parport%d.\n", port->number); return; } - pr_debug("i2c-parport: attaching to %s\n", port->name); + adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL); + if (!adapter) + return; + memset(&i2c_parport_cb, 0, sizeof(i2c_parport_cb)); + i2c_parport_cb.flags = PARPORT_FLAG_EXCL; + i2c_parport_cb.irq_func = i2c_parport_irq; + i2c_parport_cb.private = adapter; + + pr_debug("attaching to %s\n", port->name); parport_disable_irq(port); - adapter->pdev = parport_register_device(port, "i2c-parport", - NULL, NULL, i2c_parport_irq, PARPORT_FLAG_EXCL, adapter); + adapter->pdev = parport_register_dev_model(port, "i2c-parport", + &i2c_parport_cb, i); if (!adapter->pdev) { - printk(KERN_ERR "i2c-parport: Unable to register with parport\n"); + pr_err("Unable to register with parport\n"); goto err_free; } @@ -199,7 +215,8 @@ adapter->adapter.dev.parent = port->physport->dev; if (parport_claim_or_block(adapter->pdev) < 0) { - printk(KERN_ERR "i2c-parport: Could not claim parallel port\n"); + dev_err(&adapter->pdev->dev, + "Could not claim parallel port\n"); goto err_unregister; } @@ -214,7 +231,7 @@ } if (i2c_bit_add_bus(&adapter->adapter) < 0) { - printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); + dev_err(&adapter->pdev->dev, "Unable to register with I2C\n"); goto err_unregister; } @@ -226,8 +243,8 @@ if (adapter->ara) parport_enable_irq(port); else - printk(KERN_WARNING "i2c-parport: Failed to register " - "ARA client\n"); + dev_warn(&adapter->pdev->dev, + "Failed to register ARA client\n"); } /* Add the new adapter to the list */ @@ -271,9 +288,10 @@ } static struct parport_driver i2c_parport_driver = { - .name = "i2c-parport", - .attach = i2c_parport_attach, - .detach = i2c_parport_detach, + .name = "i2c-parport", + .match_port = i2c_parport_attach, + .detach = i2c_parport_detach, + .devmodel = true, }; /* ----- Module loading, unloading and information ------------------------ */ @@ -281,12 +299,12 @@ static int __init i2c_parport_init(void) { if (type < 0) { - printk(KERN_WARNING "i2c-parport: adapter type unspecified\n"); + pr_warn("adapter type unspecified\n"); return -ENODEV; } if (type >= ARRAY_SIZE(adapter_parm)) { - printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); + pr_warn("invalid type (%d)\n", type); return -ENODEV; } @@ -298,9 +316,16 @@ parport_unregister_driver(&i2c_parport_driver); } -MODULE_AUTHOR("Jean Delvare "); +MODULE_AUTHOR("Jean Delvare "); 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);