Commit a5f08a32 authored by Felipe Balbi's avatar Felipe Balbi Committed by Jean Delvare

i2c/isp1301_omap: Convert to a new-style i2c driver, part 1

Based on David Brownell's patch for tps65010, this patch
starts converting isp1301_omap.c to new-style i2c driver.
Signed-off-by: default avatarFelipe Balbi <me@felipebalbi.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarTony Lindgren <tony@atomide.com>
parent 7591103c
...@@ -49,7 +49,8 @@ MODULE_LICENSE("GPL"); ...@@ -49,7 +49,8 @@ MODULE_LICENSE("GPL");
struct isp1301 { struct isp1301 {
struct otg_transceiver otg; struct otg_transceiver otg;
struct i2c_client client; struct i2c_client *client;
struct i2c_client c;
void (*i2c_release)(struct device *dev); void (*i2c_release)(struct device *dev);
int irq; int irq;
...@@ -153,25 +154,25 @@ static struct i2c_driver isp1301_driver; ...@@ -153,25 +154,25 @@ static struct i2c_driver isp1301_driver;
static inline u8 static inline u8
isp1301_get_u8(struct isp1301 *isp, u8 reg) isp1301_get_u8(struct isp1301 *isp, u8 reg)
{ {
return i2c_smbus_read_byte_data(&isp->client, reg + 0); return i2c_smbus_read_byte_data(isp->client, reg + 0);
} }
static inline int static inline int
isp1301_get_u16(struct isp1301 *isp, u8 reg) isp1301_get_u16(struct isp1301 *isp, u8 reg)
{ {
return i2c_smbus_read_word_data(&isp->client, reg); return i2c_smbus_read_word_data(isp->client, reg);
} }
static inline int static inline int
isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
{ {
return i2c_smbus_write_byte_data(&isp->client, reg + 0, bits); return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
} }
static inline int static inline int
isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
{ {
return i2c_smbus_write_byte_data(&isp->client, reg + 1, bits); return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -349,10 +350,10 @@ isp1301_defer_work(struct isp1301 *isp, int work) ...@@ -349,10 +350,10 @@ isp1301_defer_work(struct isp1301 *isp, int work)
int status; int status;
if (isp && !test_and_set_bit(work, &isp->todo)) { if (isp && !test_and_set_bit(work, &isp->todo)) {
(void) get_device(&isp->client.dev); (void) get_device(&isp->client->dev);
status = schedule_work(&isp->work); status = schedule_work(&isp->work);
if (!status && !isp->working) if (!status && !isp->working)
dev_vdbg(&isp->client.dev, dev_vdbg(&isp->client->dev,
"work item %d may be lost\n", work); "work item %d may be lost\n", work);
} }
} }
...@@ -1135,7 +1136,7 @@ isp1301_work(struct work_struct *work) ...@@ -1135,7 +1136,7 @@ isp1301_work(struct work_struct *work)
/* transfer state from otg engine to isp1301 */ /* transfer state from otg engine to isp1301 */
if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
otg_update_isp(isp); otg_update_isp(isp);
put_device(&isp->client.dev); put_device(&isp->client->dev);
} }
#endif #endif
/* transfer state from isp1301 to otg engine */ /* transfer state from isp1301 to otg engine */
...@@ -1143,7 +1144,7 @@ isp1301_work(struct work_struct *work) ...@@ -1143,7 +1144,7 @@ isp1301_work(struct work_struct *work)
u8 stat = isp1301_clear_latch(isp); u8 stat = isp1301_clear_latch(isp);
isp_update_otg(isp, stat); isp_update_otg(isp, stat);
put_device(&isp->client.dev); put_device(&isp->client->dev);
} }
if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
...@@ -1178,7 +1179,7 @@ isp1301_work(struct work_struct *work) ...@@ -1178,7 +1179,7 @@ isp1301_work(struct work_struct *work)
} }
host_resume(isp); host_resume(isp);
// mdelay(10); // mdelay(10);
put_device(&isp->client.dev); put_device(&isp->client->dev);
} }
if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
...@@ -1187,15 +1188,15 @@ isp1301_work(struct work_struct *work) ...@@ -1187,15 +1188,15 @@ isp1301_work(struct work_struct *work)
if (!stop) if (!stop)
mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
#endif #endif
put_device(&isp->client.dev); put_device(&isp->client->dev);
} }
if (isp->todo) if (isp->todo)
dev_vdbg(&isp->client.dev, dev_vdbg(&isp->client->dev,
"work done, todo = 0x%lx\n", "work done, todo = 0x%lx\n",
isp->todo); isp->todo);
if (stop) { if (stop) {
dev_dbg(&isp->client.dev, "stop\n"); dev_dbg(&isp->client->dev, "stop\n");
break; break;
} }
} while (isp->todo); } while (isp->todo);
...@@ -1219,7 +1220,7 @@ static void isp1301_release(struct device *dev) ...@@ -1219,7 +1220,7 @@ static void isp1301_release(struct device *dev)
{ {
struct isp1301 *isp; struct isp1301 *isp;
isp = container_of(dev, struct isp1301, client.dev); isp = dev_get_drvdata(dev);
/* ugly -- i2c hijacks our memory hook to wait_for_completion() */ /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
if (isp->i2c_release) if (isp->i2c_release)
...@@ -1233,7 +1234,7 @@ static int isp1301_detach_client(struct i2c_client *i2c) ...@@ -1233,7 +1234,7 @@ static int isp1301_detach_client(struct i2c_client *i2c)
{ {
struct isp1301 *isp; struct isp1301 *isp;
isp = container_of(i2c, struct isp1301, client); isp = i2c_get_clientdata(i2c);
isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
...@@ -1285,7 +1286,7 @@ static int isp1301_otg_enable(struct isp1301 *isp) ...@@ -1285,7 +1286,7 @@ static int isp1301_otg_enable(struct isp1301 *isp)
isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
dev_info(&isp->client.dev, "ready for dual-role USB ...\n"); dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
return 0; return 0;
} }
...@@ -1310,7 +1311,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) ...@@ -1310,7 +1311,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
#ifdef CONFIG_USB_OTG #ifdef CONFIG_USB_OTG
isp->otg.host = host; isp->otg.host = host;
dev_dbg(&isp->client.dev, "registered host\n"); dev_dbg(&isp->client->dev, "registered host\n");
host_suspend(isp); host_suspend(isp);
if (isp->otg.gadget) if (isp->otg.gadget)
return isp1301_otg_enable(isp); return isp1301_otg_enable(isp);
...@@ -1325,7 +1326,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) ...@@ -1325,7 +1326,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
if (machine_is_omap_h2()) if (machine_is_omap_h2())
isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
dev_info(&isp->client.dev, "A-Host sessions ok\n"); dev_info(&isp->client->dev, "A-Host sessions ok\n");
isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
INTR_ID_GND); INTR_ID_GND);
isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
...@@ -1343,7 +1344,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) ...@@ -1343,7 +1344,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
return 0; return 0;
#else #else
dev_dbg(&isp->client.dev, "host sessions not allowed\n"); dev_dbg(&isp->client->dev, "host sessions not allowed\n");
return -EINVAL; return -EINVAL;
#endif #endif
...@@ -1370,7 +1371,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) ...@@ -1370,7 +1371,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
#ifdef CONFIG_USB_OTG #ifdef CONFIG_USB_OTG
isp->otg.gadget = gadget; isp->otg.gadget = gadget;
dev_dbg(&isp->client.dev, "registered gadget\n"); dev_dbg(&isp->client->dev, "registered gadget\n");
/* gadget driver may be suspended until vbus_connect () */ /* gadget driver may be suspended until vbus_connect () */
if (isp->otg.host) if (isp->otg.host)
return isp1301_otg_enable(isp); return isp1301_otg_enable(isp);
...@@ -1395,7 +1396,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) ...@@ -1395,7 +1396,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
INTR_SESS_VLD); INTR_SESS_VLD);
isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
INTR_VBUS_VLD); INTR_VBUS_VLD);
dev_info(&isp->client.dev, "B-Peripheral sessions ok\n"); dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
dump_regs(isp, __func__); dump_regs(isp, __func__);
/* If this has a Mini-AB connector, this mode is highly /* If this has a Mini-AB connector, this mode is highly
...@@ -1408,7 +1409,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) ...@@ -1408,7 +1409,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
return 0; return 0;
#else #else
dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n"); dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
return -EINVAL; return -EINVAL;
#endif #endif
} }
...@@ -1528,12 +1529,12 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind) ...@@ -1528,12 +1529,12 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
isp->timer.data = (unsigned long) isp; isp->timer.data = (unsigned long) isp;
isp->irq = -1; isp->irq = -1;
isp->client.addr = address; isp->c.addr = address;
i2c_set_clientdata(&isp->client, isp); i2c_set_clientdata(&isp->c, isp);
isp->client.adapter = bus; isp->c.adapter = bus;
isp->client.driver = &isp1301_driver; isp->c.driver = &isp1301_driver;
strlcpy(isp->client.name, DRIVER_NAME, I2C_NAME_SIZE); strlcpy(isp->c.name, DRIVER_NAME, I2C_NAME_SIZE);
i2c = &isp->client; isp->client = i2c = &isp->c;
/* if this is a true probe, verify the chip ... */ /* if this is a true probe, verify the chip ... */
if (kind < 0) { if (kind < 0) {
...@@ -1618,7 +1619,7 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind) ...@@ -1618,7 +1619,7 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
goto fail1; goto fail1;
} }
isp->otg.dev = &isp->client.dev; isp->otg.dev = &isp->client->dev;
isp->otg.label = DRIVER_NAME; isp->otg.label = DRIVER_NAME;
isp->otg.set_host = isp1301_set_host, isp->otg.set_host = isp1301_set_host,
......
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