diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-10-14 11:30:02 -0400 |
---|---|---|
committer | Jean Delvare <khali@mahadeva.delvare> | 2008-10-14 11:30:02 -0400 |
commit | 9df013b3e46c67dd3745df91eaccdc719118e0cc (patch) | |
tree | 81fe2d8b900e6ef9508a11a7f354ace9c2e04d03 /drivers/i2c | |
parent | a5f08a327abc45eb6cb3cc1f5fabf38607ae2acc (diff) |
i2c/isp1301_omap: Convert to a new-style i2c driver, part 2
Based on David Brownell's patch for tps65010 and previous work by
Felipe Balbi, this patch finishes converting isp1301_omap to a
new-style i2c driver.
There's definitely room for further drivers cleanups, but these are
out of the scope of this patch.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/chips/isp1301_omap.c | 98 |
1 files changed, 33 insertions, 65 deletions
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c index 8444fc6fbf61..28902ebd5539 100644 --- a/drivers/i2c/chips/isp1301_omap.c +++ b/drivers/i2c/chips/isp1301_omap.c | |||
@@ -50,10 +50,8 @@ MODULE_LICENSE("GPL"); | |||
50 | struct isp1301 { | 50 | struct isp1301 { |
51 | struct otg_transceiver otg; | 51 | struct otg_transceiver otg; |
52 | struct i2c_client *client; | 52 | struct i2c_client *client; |
53 | struct i2c_client c; | ||
54 | void (*i2c_release)(struct device *dev); | 53 | void (*i2c_release)(struct device *dev); |
55 | 54 | ||
56 | int irq; | ||
57 | int irq_type; | 55 | int irq_type; |
58 | 56 | ||
59 | u32 last_otg_ctrl; | 57 | u32 last_otg_ctrl; |
@@ -139,14 +137,6 @@ static inline void notresponding(struct isp1301 *isp) | |||
139 | 137 | ||
140 | /*-------------------------------------------------------------------------*/ | 138 | /*-------------------------------------------------------------------------*/ |
141 | 139 | ||
142 | /* only two addresses possible */ | ||
143 | #define ISP_BASE 0x2c | ||
144 | static unsigned short normal_i2c[] = { | ||
145 | ISP_BASE, ISP_BASE + 1, | ||
146 | I2C_CLIENT_END }; | ||
147 | |||
148 | I2C_CLIENT_INSMOD; | ||
149 | |||
150 | static struct i2c_driver isp1301_driver; | 140 | static struct i2c_driver isp1301_driver; |
151 | 141 | ||
152 | /* smbus apis are used for portability */ | 142 | /* smbus apis are used for portability */ |
@@ -1230,7 +1220,7 @@ static void isp1301_release(struct device *dev) | |||
1230 | 1220 | ||
1231 | static struct isp1301 *the_transceiver; | 1221 | static struct isp1301 *the_transceiver; |
1232 | 1222 | ||
1233 | static int isp1301_detach_client(struct i2c_client *i2c) | 1223 | static int __exit isp1301_remove(struct i2c_client *i2c) |
1234 | { | 1224 | { |
1235 | struct isp1301 *isp; | 1225 | struct isp1301 *isp; |
1236 | 1226 | ||
@@ -1238,7 +1228,7 @@ static int isp1301_detach_client(struct i2c_client *i2c) | |||
1238 | 1228 | ||
1239 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); | 1229 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); |
1240 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); | 1230 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); |
1241 | free_irq(isp->irq, isp); | 1231 | free_irq(i2c->irq, isp); |
1242 | #ifdef CONFIG_USB_OTG | 1232 | #ifdef CONFIG_USB_OTG |
1243 | otg_unbind(isp); | 1233 | otg_unbind(isp); |
1244 | #endif | 1234 | #endif |
@@ -1253,7 +1243,7 @@ static int isp1301_detach_client(struct i2c_client *i2c) | |||
1253 | put_device(&i2c->dev); | 1243 | put_device(&i2c->dev); |
1254 | the_transceiver = 0; | 1244 | the_transceiver = 0; |
1255 | 1245 | ||
1256 | return i2c_detach_client(i2c); | 1246 | return 0; |
1257 | } | 1247 | } |
1258 | 1248 | ||
1259 | /*-------------------------------------------------------------------------*/ | 1249 | /*-------------------------------------------------------------------------*/ |
@@ -1509,12 +1499,10 @@ isp1301_start_hnp(struct otg_transceiver *dev) | |||
1509 | 1499 | ||
1510 | /*-------------------------------------------------------------------------*/ | 1500 | /*-------------------------------------------------------------------------*/ |
1511 | 1501 | ||
1512 | /* no error returns, they'd just make bus scanning stop */ | 1502 | static int __init isp1301_probe(struct i2c_client *i2c) |
1513 | static int isp1301_probe(struct i2c_adapter *bus, int address, int kind) | ||
1514 | { | 1503 | { |
1515 | int status; | 1504 | int status; |
1516 | struct isp1301 *isp; | 1505 | struct isp1301 *isp; |
1517 | struct i2c_client *i2c; | ||
1518 | 1506 | ||
1519 | if (the_transceiver) | 1507 | if (the_transceiver) |
1520 | return 0; | 1508 | return 0; |
@@ -1528,37 +1516,19 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind) | |||
1528 | isp->timer.function = isp1301_timer; | 1516 | isp->timer.function = isp1301_timer; |
1529 | isp->timer.data = (unsigned long) isp; | 1517 | isp->timer.data = (unsigned long) isp; |
1530 | 1518 | ||
1531 | isp->irq = -1; | 1519 | i2c_set_clientdata(i2c, isp); |
1532 | isp->c.addr = address; | 1520 | isp->client = i2c; |
1533 | i2c_set_clientdata(&isp->c, isp); | ||
1534 | isp->c.adapter = bus; | ||
1535 | isp->c.driver = &isp1301_driver; | ||
1536 | strlcpy(isp->c.name, DRIVER_NAME, I2C_NAME_SIZE); | ||
1537 | isp->client = i2c = &isp->c; | ||
1538 | |||
1539 | /* if this is a true probe, verify the chip ... */ | ||
1540 | if (kind < 0) { | ||
1541 | status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); | ||
1542 | if (status != I2C_VENDOR_ID_PHILIPS) { | ||
1543 | dev_dbg(&bus->dev, "addr %d not philips id: %d\n", | ||
1544 | address, status); | ||
1545 | goto fail1; | ||
1546 | } | ||
1547 | status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); | ||
1548 | if (status != I2C_PRODUCT_ID_PHILIPS_1301) { | ||
1549 | dev_dbg(&bus->dev, "%d not isp1301, %d\n", | ||
1550 | address, status); | ||
1551 | goto fail1; | ||
1552 | } | ||
1553 | } | ||
1554 | 1521 | ||
1555 | status = i2c_attach_client(i2c); | 1522 | /* verify the chip (shouldn't be necesary) */ |
1556 | if (status < 0) { | 1523 | status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); |
1557 | dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n", | 1524 | if (status != I2C_VENDOR_ID_PHILIPS) { |
1558 | DRIVER_NAME, address, status); | 1525 | dev_dbg(&i2c->dev, "not philips id: %d\n", status); |
1559 | fail1: | 1526 | goto fail; |
1560 | kfree(isp); | 1527 | } |
1561 | return 0; | 1528 | status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); |
1529 | if (status != I2C_PRODUCT_ID_PHILIPS_1301) { | ||
1530 | dev_dbg(&i2c->dev, "not isp1301, %d\n", status); | ||
1531 | goto fail; | ||
1562 | } | 1532 | } |
1563 | isp->i2c_release = i2c->dev.release; | 1533 | isp->i2c_release = i2c->dev.release; |
1564 | i2c->dev.release = isp1301_release; | 1534 | i2c->dev.release = isp1301_release; |
@@ -1587,7 +1557,7 @@ fail1: | |||
1587 | status = otg_bind(isp); | 1557 | status = otg_bind(isp); |
1588 | if (status < 0) { | 1558 | if (status < 0) { |
1589 | dev_dbg(&i2c->dev, "can't bind OTG\n"); | 1559 | dev_dbg(&i2c->dev, "can't bind OTG\n"); |
1590 | goto fail2; | 1560 | goto fail; |
1591 | } | 1561 | } |
1592 | #endif | 1562 | #endif |
1593 | 1563 | ||
@@ -1600,26 +1570,21 @@ fail1: | |||
1600 | 1570 | ||
1601 | /* IRQ wired at M14 */ | 1571 | /* IRQ wired at M14 */ |
1602 | omap_cfg_reg(M14_1510_GPIO2); | 1572 | omap_cfg_reg(M14_1510_GPIO2); |
1603 | isp->irq = OMAP_GPIO_IRQ(2); | ||
1604 | if (gpio_request(2, "isp1301") == 0) | 1573 | if (gpio_request(2, "isp1301") == 0) |
1605 | gpio_direction_input(2); | 1574 | gpio_direction_input(2); |
1606 | isp->irq_type = IRQF_TRIGGER_FALLING; | 1575 | isp->irq_type = IRQF_TRIGGER_FALLING; |
1607 | } | 1576 | } |
1608 | 1577 | ||
1609 | isp->irq_type |= IRQF_SAMPLE_RANDOM; | 1578 | isp->irq_type |= IRQF_SAMPLE_RANDOM; |
1610 | status = request_irq(isp->irq, isp1301_irq, | 1579 | status = request_irq(i2c->irq, isp1301_irq, |
1611 | isp->irq_type, DRIVER_NAME, isp); | 1580 | isp->irq_type, DRIVER_NAME, isp); |
1612 | if (status < 0) { | 1581 | if (status < 0) { |
1613 | dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", | 1582 | dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", |
1614 | isp->irq, status); | 1583 | i2c->irq, status); |
1615 | #ifdef CONFIG_USB_OTG | 1584 | goto fail; |
1616 | fail2: | ||
1617 | #endif | ||
1618 | i2c_detach_client(i2c); | ||
1619 | goto fail1; | ||
1620 | } | 1585 | } |
1621 | 1586 | ||
1622 | isp->otg.dev = &isp->client->dev; | 1587 | isp->otg.dev = &i2c->dev; |
1623 | isp->otg.label = DRIVER_NAME; | 1588 | isp->otg.label = DRIVER_NAME; |
1624 | 1589 | ||
1625 | isp->otg.set_host = isp1301_set_host, | 1590 | isp->otg.set_host = isp1301_set_host, |
@@ -1650,22 +1615,25 @@ fail2: | |||
1650 | status); | 1615 | status); |
1651 | 1616 | ||
1652 | return 0; | 1617 | return 0; |
1653 | } | ||
1654 | 1618 | ||
1655 | static int isp1301_scan_bus(struct i2c_adapter *bus) | 1619 | fail: |
1656 | { | 1620 | kfree(isp); |
1657 | if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA | 1621 | return -ENODEV; |
1658 | | I2C_FUNC_SMBUS_READ_WORD_DATA)) | ||
1659 | return -EINVAL; | ||
1660 | return i2c_probe(bus, &addr_data, isp1301_probe); | ||
1661 | } | 1622 | } |
1662 | 1623 | ||
1624 | static const struct i2c_device_id isp1301_id[] = { | ||
1625 | { "isp1301_omap", 0 }, | ||
1626 | { } | ||
1627 | }; | ||
1628 | MODULE_DEVICE_TABLE(i2c, isp1301_id); | ||
1629 | |||
1663 | static struct i2c_driver isp1301_driver = { | 1630 | static struct i2c_driver isp1301_driver = { |
1664 | .driver = { | 1631 | .driver = { |
1665 | .name = "isp1301_omap", | 1632 | .name = "isp1301_omap", |
1666 | }, | 1633 | }, |
1667 | .attach_adapter = isp1301_scan_bus, | 1634 | .probe = isp1301_probe, |
1668 | .detach_client = isp1301_detach_client, | 1635 | .remove = __exit_p(isp1301_remove), |
1636 | .id_table = isp1301_id, | ||
1669 | }; | 1637 | }; |
1670 | 1638 | ||
1671 | /*-------------------------------------------------------------------------*/ | 1639 | /*-------------------------------------------------------------------------*/ |