Commit 07da0372 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

i2c-parport: Various cleanups

* Fix white space.
* Rename labels to something meaningful.
* Prefix defines with PORT_ to avoid collision with macros from
  <linux/parport.h>.
* Add const markers where possible.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 8eacfceb
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
* i2c-parport-light.c I2C bus over parallel port * * i2c-parport-light.c I2C bus over parallel port *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org> Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org>
Based on older i2c-velleman.c driver Based on older i2c-velleman.c driver
Copyright (C) 1995-2000 Simon G. Vogl Copyright (C) 1995-2000 Simon G. Vogl
With some changes from: With some changes from:
Frodo Looijaard <frodol@dds.nl> Frodo Looijaard <frodol@dds.nl>
Kyösti Mälkki <kmalkki@cc.hut.fi> Kyösti Mälkki <kmalkki@cc.hut.fi>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
...@@ -114,7 +114,7 @@ static struct i2c_algo_bit_data parport_algo_data = { ...@@ -114,7 +114,7 @@ static struct i2c_algo_bit_data parport_algo_data = {
.getscl = parport_getscl, .getscl = parport_getscl,
.udelay = 50, .udelay = 50,
.timeout = HZ, .timeout = HZ,
}; };
/* ----- Driver registration ---------------------------------------------- */ /* ----- Driver registration ---------------------------------------------- */
...@@ -132,7 +132,7 @@ static struct i2c_smbus_alert_setup alert_data = { ...@@ -132,7 +132,7 @@ static struct i2c_smbus_alert_setup alert_data = {
static struct i2c_client *ara; static struct i2c_client *ara;
static struct lineop parport_ctrl_irq = { static struct lineop parport_ctrl_irq = {
.val = (1 << 4), .val = (1 << 4),
.port = CTRL, .port = PORT_CTRL,
}; };
static int __devinit i2c_parport_probe(struct platform_device *pdev) static int __devinit i2c_parport_probe(struct platform_device *pdev)
...@@ -245,7 +245,7 @@ static int __init i2c_parport_init(void) ...@@ -245,7 +245,7 @@ static int __init i2c_parport_init(void)
if (irq != 0) if (irq != 0)
pr_info(DRVNAME ": using irq %d\n", irq); pr_info(DRVNAME ": using irq %d\n", irq);
if (!adapter_parm[type].getscl.val) if (!adapter_parm[type].getscl.val)
parport_algo_data.getscl = NULL; parport_algo_data.getscl = NULL;
/* Sets global pdev as a side effect */ /* Sets global pdev as a side effect */
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
* i2c-parport.c I2C bus over parallel port * * i2c-parport.c I2C bus over parallel port *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
Copyright (C) 2003-2011 Jean Delvare <khali@linux-fr.org> Copyright (C) 2003-2011 Jean Delvare <khali@linux-fr.org>
Based on older i2c-philips-par.c driver Based on older i2c-philips-par.c driver
Copyright (C) 1995-2000 Simon G. Vogl Copyright (C) 1995-2000 Simon G. Vogl
With some changes from: With some changes from:
Frodo Looijaard <frodol@dds.nl> Frodo Looijaard <frodol@dds.nl>
Kyösti Mälkki <kmalkki@cc.hut.fi> Kyösti Mälkki <kmalkki@cc.hut.fi>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
...@@ -78,13 +78,13 @@ static unsigned char port_read_control(struct parport *p) ...@@ -78,13 +78,13 @@ static unsigned char port_read_control(struct parport *p)
return parport_read_control(p); return parport_read_control(p);
} }
static void (*port_write[])(struct parport *, unsigned char) = { static void (* const port_write[])(struct parport *, unsigned char) = {
port_write_data, port_write_data,
NULL, NULL,
port_write_control, port_write_control,
}; };
static unsigned char (*port_read[])(struct parport *) = { static unsigned char (* const port_read[])(struct parport *) = {
port_read_data, port_read_data,
port_read_status, port_read_status,
port_read_control, port_read_control,
...@@ -147,7 +147,7 @@ static const struct i2c_algo_bit_data parport_algo_data = { ...@@ -147,7 +147,7 @@ static const struct i2c_algo_bit_data parport_algo_data = {
.getscl = parport_getscl, .getscl = parport_getscl,
.udelay = 10, /* ~50 kbps */ .udelay = 10, /* ~50 kbps */
.timeout = HZ, .timeout = HZ,
}; };
/* ----- I2c and parallel port call-back functions and structures --------- */ /* ----- I2c and parallel port call-back functions and structures --------- */
...@@ -164,10 +164,10 @@ void i2c_parport_irq(void *data) ...@@ -164,10 +164,10 @@ void i2c_parport_irq(void *data)
"SMBus alert received but no ARA client!\n"); "SMBus alert received but no ARA client!\n");
} }
static void i2c_parport_attach (struct parport *port) static void i2c_parport_attach(struct parport *port)
{ {
struct i2c_par *adapter; struct i2c_par *adapter;
adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL); adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL);
if (adapter == NULL) { if (adapter == NULL) {
printk(KERN_ERR "i2c-parport: Failed to kzalloc\n"); printk(KERN_ERR "i2c-parport: Failed to kzalloc\n");
...@@ -180,7 +180,7 @@ static void i2c_parport_attach (struct parport *port) ...@@ -180,7 +180,7 @@ static void i2c_parport_attach (struct parport *port)
NULL, NULL, i2c_parport_irq, PARPORT_FLAG_EXCL, adapter); NULL, NULL, i2c_parport_irq, PARPORT_FLAG_EXCL, adapter);
if (!adapter->pdev) { if (!adapter->pdev) {
printk(KERN_ERR "i2c-parport: Unable to register with parport\n"); printk(KERN_ERR "i2c-parport: Unable to register with parport\n");
goto ERROR0; goto err_free;
} }
/* Fill the rest of the structure */ /* Fill the rest of the structure */
...@@ -200,7 +200,7 @@ static void i2c_parport_attach (struct parport *port) ...@@ -200,7 +200,7 @@ static void i2c_parport_attach (struct parport *port)
if (parport_claim_or_block(adapter->pdev) < 0) { if (parport_claim_or_block(adapter->pdev) < 0) {
printk(KERN_ERR "i2c-parport: Could not claim parallel port\n"); printk(KERN_ERR "i2c-parport: Could not claim parallel port\n");
goto ERROR1; goto err_unregister;
} }
/* Reset hardware to a sane state (SCL and SDA high) */ /* Reset hardware to a sane state (SCL and SDA high) */
...@@ -215,7 +215,7 @@ static void i2c_parport_attach (struct parport *port) ...@@ -215,7 +215,7 @@ static void i2c_parport_attach (struct parport *port)
if (i2c_bit_add_bus(&adapter->adapter) < 0) { if (i2c_bit_add_bus(&adapter->adapter) < 0) {
printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); printk(KERN_ERR "i2c-parport: Unable to register with I2C\n");
goto ERROR1; goto err_unregister;
} }
/* Setup SMBus alert if supported */ /* Setup SMBus alert if supported */
...@@ -234,16 +234,16 @@ static void i2c_parport_attach (struct parport *port) ...@@ -234,16 +234,16 @@ static void i2c_parport_attach (struct parport *port)
mutex_lock(&adapter_list_lock); mutex_lock(&adapter_list_lock);
list_add_tail(&adapter->node, &adapter_list); list_add_tail(&adapter->node, &adapter_list);
mutex_unlock(&adapter_list_lock); mutex_unlock(&adapter_list_lock);
return; return;
ERROR1: err_unregister:
parport_release(adapter->pdev); parport_release(adapter->pdev);
parport_unregister_device(adapter->pdev); parport_unregister_device(adapter->pdev);
ERROR0: err_free:
kfree(adapter); kfree(adapter);
} }
static void i2c_parport_detach (struct parport *port) static void i2c_parport_detach(struct parport *port)
{ {
struct i2c_par *adapter, *_n; struct i2c_par *adapter, *_n;
...@@ -260,7 +260,7 @@ static void i2c_parport_detach (struct parport *port) ...@@ -260,7 +260,7 @@ static void i2c_parport_detach (struct parport *port)
/* Un-init if needed (power off...) */ /* Un-init if needed (power off...) */
if (adapter_parm[type].init.val) if (adapter_parm[type].init.val)
line_set(port, 0, &adapter_parm[type].init); line_set(port, 0, &adapter_parm[type].init);
parport_release(adapter->pdev); parport_release(adapter->pdev);
parport_unregister_device(adapter->pdev); parport_unregister_device(adapter->pdev);
list_del(&adapter->node); list_del(&adapter->node);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* i2c-parport.h I2C bus over parallel port * * i2c-parport.h I2C bus over parallel port *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org> Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
...@@ -18,13 +18,9 @@ ...@@ -18,13 +18,9 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* ------------------------------------------------------------------------ */ * ------------------------------------------------------------------------ */
#ifdef DATA #define PORT_DATA 0
#undef DATA #define PORT_STAT 1
#endif #define PORT_CTRL 2
#define DATA 0
#define STAT 1
#define CTRL 2
struct lineop { struct lineop {
u8 val; u8 val;
...@@ -41,61 +37,61 @@ struct adapter_parm { ...@@ -41,61 +37,61 @@ struct adapter_parm {
unsigned int smbus_alert:1; unsigned int smbus_alert:1;
}; };
static struct adapter_parm adapter_parm[] = { static const struct adapter_parm adapter_parm[] = {
/* type 0: Philips adapter */ /* type 0: Philips adapter */
{ {
.setsda = { 0x80, DATA, 1 }, .setsda = { 0x80, PORT_DATA, 1 },
.setscl = { 0x08, CTRL, 0 }, .setscl = { 0x08, PORT_CTRL, 0 },
.getsda = { 0x80, STAT, 0 }, .getsda = { 0x80, PORT_STAT, 0 },
.getscl = { 0x08, STAT, 0 }, .getscl = { 0x08, PORT_STAT, 0 },
}, },
/* type 1: home brew teletext adapter */ /* type 1: home brew teletext adapter */
{ {
.setsda = { 0x02, DATA, 0 }, .setsda = { 0x02, PORT_DATA, 0 },
.setscl = { 0x01, DATA, 0 }, .setscl = { 0x01, PORT_DATA, 0 },
.getsda = { 0x80, STAT, 1 }, .getsda = { 0x80, PORT_STAT, 1 },
}, },
/* type 2: Velleman K8000 adapter */ /* type 2: Velleman K8000 adapter */
{ {
.setsda = { 0x02, CTRL, 1 }, .setsda = { 0x02, PORT_CTRL, 1 },
.setscl = { 0x08, CTRL, 1 }, .setscl = { 0x08, PORT_CTRL, 1 },
.getsda = { 0x10, STAT, 0 }, .getsda = { 0x10, PORT_STAT, 0 },
}, },
/* type 3: ELV adapter */ /* type 3: ELV adapter */
{ {
.setsda = { 0x02, DATA, 1 }, .setsda = { 0x02, PORT_DATA, 1 },
.setscl = { 0x01, DATA, 1 }, .setscl = { 0x01, PORT_DATA, 1 },
.getsda = { 0x40, STAT, 1 }, .getsda = { 0x40, PORT_STAT, 1 },
.getscl = { 0x08, STAT, 1 }, .getscl = { 0x08, PORT_STAT, 1 },
}, },
/* type 4: ADM1032 evaluation board */ /* type 4: ADM1032 evaluation board */
{ {
.setsda = { 0x02, DATA, 1 }, .setsda = { 0x02, PORT_DATA, 1 },
.setscl = { 0x01, DATA, 1 }, .setscl = { 0x01, PORT_DATA, 1 },
.getsda = { 0x10, STAT, 1 }, .getsda = { 0x10, PORT_STAT, 1 },
.init = { 0xf0, DATA, 0 }, .init = { 0xf0, PORT_DATA, 0 },
.smbus_alert = 1, .smbus_alert = 1,
}, },
/* type 5: ADM1025, ADM1030 and ADM1031 evaluation boards */ /* type 5: ADM1025, ADM1030 and ADM1031 evaluation boards */
{ {
.setsda = { 0x02, DATA, 1 }, .setsda = { 0x02, PORT_DATA, 1 },
.setscl = { 0x01, DATA, 1 }, .setscl = { 0x01, PORT_DATA, 1 },
.getsda = { 0x10, STAT, 1 }, .getsda = { 0x10, PORT_STAT, 1 },
}, },
/* type 6: Barco LPT->DVI (K5800236) adapter */ /* type 6: Barco LPT->DVI (K5800236) adapter */
{ {
.setsda = { 0x02, DATA, 1 }, .setsda = { 0x02, PORT_DATA, 1 },
.setscl = { 0x01, DATA, 1 }, .setscl = { 0x01, PORT_DATA, 1 },
.getsda = { 0x20, STAT, 0 }, .getsda = { 0x20, PORT_STAT, 0 },
.getscl = { 0x40, STAT, 0 }, .getscl = { 0x40, PORT_STAT, 0 },
.init = { 0xfc, DATA, 0 }, .init = { 0xfc, PORT_DATA, 0 },
}, },
/* type 7: One For All JP1 parallel port adapter */ /* type 7: One For All JP1 parallel port adapter */
{ {
.setsda = { 0x01, DATA, 0 }, .setsda = { 0x01, PORT_DATA, 0 },
.setscl = { 0x02, DATA, 0 }, .setscl = { 0x02, PORT_DATA, 0 },
.getsda = { 0x80, STAT, 1 }, .getsda = { 0x80, PORT_STAT, 1 },
.init = { 0x04, DATA, 1 }, .init = { 0x04, PORT_DATA, 1 },
}, },
}; };
......
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