X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fi2c%2Fbusses%2Fi2c-pxa.c;h=7579f4b256a8c7ed716765adcafb59c7fdb6cfb9;hb=b4669d66fb1488fd9cebe0b8da447cfeb86109ba;hp=fdf53ce0424840757743501f9bca3b054d191a61;hpb=ddbf9ef385bfbef897210733abfb73cb9b94ecec;p=linux-2.6 diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index fdf53ce042..7579f4b256 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -860,7 +861,7 @@ static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id, struct pt_regs *r decode_ISR(isr); } - if (i2c->irqlogidx < sizeof(i2c->isrlog)/sizeof(u32)) + if (i2c->irqlogidx < ARRAY_SIZE(i2c->isrlog)) i2c->isrlog[i2c->irqlogidx++] = isr; show_state(i2c); @@ -898,6 +899,12 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num struct pxa_i2c *i2c = adap->algo_data; int ret, i; + /* If the I2C controller is disabled we need to reset it (probably due + to a suspend/resume destroying state). We do this here as we can then + avoid worrying about resuming the controller before its users. */ + if (!(ICR & ICR_IUE)) + i2c_pxa_reset(i2c); + for (i = adap->retries; i >= 0; i--) { ret = i2c_pxa_do_xfer(i2c, msgs, num); if (ret != I2C_RETRY) @@ -914,27 +921,33 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num return ret; } +static u32 i2c_pxa_functionality(struct i2c_adapter *adap) +{ + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; +} + static struct i2c_algorithm i2c_pxa_algorithm = { - .name = "PXA-I2C-Algorithm", - .id = I2C_ALGO_PXA, .master_xfer = i2c_pxa_xfer, + .functionality = i2c_pxa_functionality, }; static struct pxa_i2c i2c_pxa = { .lock = SPIN_LOCK_UNLOCKED, .wait = __WAIT_QUEUE_HEAD_INITIALIZER(i2c_pxa.wait), .adap = { - .name = "pxa2xx-i2c", - .id = I2C_ALGO_PXA, + .owner = THIS_MODULE, .algo = &i2c_pxa_algorithm, + .name = "pxa2xx-i2c", .retries = 5, }, }; -static int i2c_pxa_probe(struct device *dev) +static int i2c_pxa_probe(struct platform_device *dev) { struct pxa_i2c *i2c = &i2c_pxa; - struct i2c_pxa_platform_data *plat = dev->platform_data; +#ifdef CONFIG_I2C_PXA_SLAVE + struct i2c_pxa_platform_data *plat = dev->dev.platform_data; +#endif int ret; #ifdef CONFIG_PXA27x @@ -963,7 +976,7 @@ static int i2c_pxa_probe(struct device *dev) i2c_pxa_reset(i2c); i2c->adap.algo_data = i2c; - i2c->adap.dev.parent = dev; + i2c->adap.dev.parent = &dev->dev; ret = i2c_add_adapter(&i2c->adap); if (ret < 0) { @@ -971,7 +984,7 @@ static int i2c_pxa_probe(struct device *dev) goto err_irq; } - dev_set_drvdata(dev, i2c); + platform_set_drvdata(dev, i2c); #ifdef CONFIG_I2C_PXA_SLAVE printk(KERN_INFO "I2C: %s: PXA I2C adapter, slave address %d\n", @@ -988,11 +1001,11 @@ static int i2c_pxa_probe(struct device *dev) return ret; } -static int i2c_pxa_remove(struct device *dev) +static int i2c_pxa_remove(struct platform_device *dev) { - struct pxa_i2c *i2c = dev_get_drvdata(dev); + struct pxa_i2c *i2c = platform_get_drvdata(dev); - dev_set_drvdata(dev, NULL); + platform_set_drvdata(dev, NULL); i2c_del_adapter(&i2c->adap); free_irq(IRQ_I2C, i2c); @@ -1001,22 +1014,25 @@ static int i2c_pxa_remove(struct device *dev) return 0; } -static struct device_driver i2c_pxa_driver = { - .name = "pxa2xx-i2c", - .bus = &platform_bus_type, +static struct platform_driver i2c_pxa_driver = { .probe = i2c_pxa_probe, .remove = i2c_pxa_remove, + .driver = { + .name = "pxa2xx-i2c", + }, }; static int __init i2c_adap_pxa_init(void) { - return driver_register(&i2c_pxa_driver); + return platform_driver_register(&i2c_pxa_driver); } static void i2c_adap_pxa_exit(void) { - return driver_unregister(&i2c_pxa_driver); + return platform_driver_unregister(&i2c_pxa_driver); } +MODULE_LICENSE("GPL"); + module_init(i2c_adap_pxa_init); module_exit(i2c_adap_pxa_exit);