22 #include <linux/kernel.h>
23 #include <linux/module.h>
25 #include <linux/slab.h>
29 #include <linux/usb/ch9.h>
33 #include <linux/i2c.h>
48 #define DRIVER_VERSION "24 August 2004"
49 #define DRIVER_NAME (isp1301_driver.driver.name)
70 # define WORK_UPDATE_ISP 0
71 # define WORK_UPDATE_OTG 1
72 # define WORK_HOST_RESUME 4
80 #define OTG_XCEIV_OUTPUTS \
81 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
82 #define OTG_XCEIV_INPUTS \
83 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
84 #define OTG_CTRL_BITS \
85 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
88 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
89 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
97 #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
99 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
107 pr_debug(
"tps65010: draw %d mA (STUB)\n", mA);
113 static void enable_vbus_draw(
struct isp1301 *isp,
unsigned mA)
117 pr_debug(
" VBUS %d mA error %d\n", mA, status);
122 static void enable_vbus_draw(
struct isp1301 *isp,
unsigned mA)
132 static void enable_vbus_source(
struct isp1301 *isp)
141 static inline void notresponding(
struct isp1301 *isp)
180 #define ISP1301_VENDOR_ID 0x00
181 #define ISP1301_PRODUCT_ID 0x02
182 #define ISP1301_BCD_DEVICE 0x14
184 #define I2C_VENDOR_ID_PHILIPS 0x04cc
185 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
188 #define ISP1301_MODE_CONTROL_1 0x04
189 # define MC1_SPEED (1 << 0)
190 # define MC1_SUSPEND (1 << 1)
191 # define MC1_DAT_SE0 (1 << 2)
192 # define MC1_TRANSPARENT (1 << 3)
193 # define MC1_BDIS_ACON_EN (1 << 4)
194 # define MC1_OE_INT_EN (1 << 5)
195 # define MC1_UART_EN (1 << 6)
196 # define MC1_MASK 0x7f
197 #define ISP1301_MODE_CONTROL_2 0x12
198 # define MC2_GLOBAL_PWR_DN (1 << 0)
199 # define MC2_SPD_SUSP_CTRL (1 << 1)
200 # define MC2_BI_DI (1 << 2)
201 # define MC2_TRANSP_BDIR0 (1 << 3)
202 # define MC2_TRANSP_BDIR1 (1 << 4)
203 # define MC2_AUDIO_EN (1 << 5)
204 # define MC2_PSW_EN (1 << 6)
205 # define MC2_EN2V7 (1 << 7)
206 #define ISP1301_OTG_CONTROL_1 0x06
207 # define OTG1_DP_PULLUP (1 << 0)
208 # define OTG1_DM_PULLUP (1 << 1)
209 # define OTG1_DP_PULLDOWN (1 << 2)
210 # define OTG1_DM_PULLDOWN (1 << 3)
211 # define OTG1_ID_PULLDOWN (1 << 4)
212 # define OTG1_VBUS_DRV (1 << 5)
213 # define OTG1_VBUS_DISCHRG (1 << 6)
214 # define OTG1_VBUS_CHRG (1 << 7)
215 #define ISP1301_OTG_STATUS 0x10
216 # define OTG_B_SESS_END (1 << 6)
217 # define OTG_B_SESS_VLD (1 << 7)
219 #define ISP1301_INTERRUPT_SOURCE 0x08
220 #define ISP1301_INTERRUPT_LATCH 0x0A
222 #define ISP1301_INTERRUPT_FALLING 0x0C
223 #define ISP1301_INTERRUPT_RISING 0x0E
226 # define INTR_VBUS_VLD (1 << 0)
227 # define INTR_SESS_VLD (1 << 1)
228 # define INTR_DP_HI (1 << 2)
229 # define INTR_ID_GND (1 << 3)
230 # define INTR_DM_HI (1 << 4)
231 # define INTR_ID_FLOAT (1 << 5)
232 # define INTR_BDIS_ACON (1 << 6)
233 # define INTR_CR_INT (1 << 7)
237 static inline const char *state_name(
struct isp1301 *isp)
263 static void power_up(
struct isp1301 *isp)
274 #define NO_HOST_SUSPEND
276 static int host_suspend(
struct isp1301 *isp)
278 #ifdef NO_HOST_SUSPEND
283 if (!isp->
phy.otg->host)
289 dev = isp->
phy.otg->host->controller;
290 return dev->
driver->suspend(dev, 3, 0);
294 static int host_resume(
struct isp1301 *isp)
296 #ifdef NO_HOST_SUSPEND
301 if (!isp->
phy.otg->host)
304 dev = isp->
phy.otg->host->controller;
305 return dev->
driver->resume(dev, 0);
309 static int gadget_suspend(
struct isp1301 *isp)
311 isp->
phy.otg->gadget->b_hnp_enable = 0;
312 isp->
phy.otg->gadget->a_hnp_support = 0;
313 isp->
phy.otg->gadget->a_alt_hnp_support = 0;
314 return usb_gadget_vbus_disconnect(isp->
phy.otg->gadget);
319 #define TIMER_MINUTES 10
320 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
326 static void isp1301_defer_work(
struct isp1301 *isp,
int work)
335 "work item %d may be lost\n", work);
340 static void a_idle(
struct isp1301 *isp,
const char *
tag)
347 isp->
phy.otg->default_a = 1;
348 if (isp->
phy.otg->host) {
349 isp->
phy.otg->host->is_b_host = 0;
352 if (isp->
phy.otg->gadget) {
353 isp->
phy.otg->gadget->is_a_peripheral = 1;
360 pr_debug(
" --> %s/%s\n", state_name(isp), tag);
364 static void b_idle(
struct isp1301 *isp,
const char *tag)
371 isp->
phy.otg->default_a = 0;
372 if (isp->
phy.otg->host) {
373 isp->
phy.otg->host->is_b_host = 1;
376 if (isp->
phy.otg->gadget) {
377 isp->
phy.otg->gadget->is_a_peripheral = 0;
384 pr_debug(
" --> %s/%s\n", state_name(isp), tag);
395 pr_debug(
"otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
404 #ifdef CONFIG_USB_OTG
416 static void check_state(
struct isp1301 *isp,
const char *tag)
481 if (isp->
phy.state == state && !extra)
483 pr_debug(
"otg: %s FSM %s/%02x, %s, %06x\n", tag,
490 static inline void check_state(
struct isp1301 *isp,
const char *tag) { }
495 static void update_otg1(
struct isp1301 *isp,
u8 int_src)
506 a_idle(isp,
"vfall");
530 static void update_otg2(
struct isp1301 *isp,
u8 otg_status)
545 static void otg_update_isp(
struct isp1301 *isp)
547 u32 otg_ctrl, otg_change;
555 switch (isp->
phy.state) {
561 if (isp->
phy.otg->gadget->b_hnp_enable) {
573 if (otg_ctrl & OTG_PULLUP)
584 # define toggle(OTG,ISP) do { \
585 if (otg_ctrl & OTG) set |= ISP; \
589 if (!(isp->
phy.otg->host))
592 switch (isp->
phy.state) {
611 if (otg_ctrl & OTG_DRV_VBUS) {
629 if (otg_change & OTG_PULLUP) {
632 switch (isp->
phy.state) {
640 if (clr & OTG1_DP_PULLUP)
653 check_state(isp, __func__);
654 dump_regs(isp,
"otg->isp1301");
657 static irqreturn_t omap_otg_irq(
int irq,
void *_isp)
681 b_idle(isp,
"srp_timeout");
688 pr_debug(
"otg: %s B_HNP_FAIL, %06x\n",
706 pr_debug(
"otg: %s SRP_DETECT, %06x\n",
710 switch (isp->
phy.state) {
734 pr_info(
"otg: BCON_TMOUT from %s, %06x\n",
735 state_name(isp), otg_ctrl);
750 state_name(isp), otg_irq, otg_ctrl);
776 switch (isp->
phy.state) {
778 b_idle(isp, __func__);
787 if (!(otg_ctrl &
OTG_ID)) {
793 switch (isp->
phy.state) {
821 check_state(isp, __func__);
827 static int isp1301_otg_init(
struct isp1301 *isp)
834 dump_regs(isp, __func__);
852 check_state(isp, __func__);
857 | B_SRP_TMROUT | B_HNP_FAIL
858 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT,
OTG_IRQ_EN);
883 .remove = otg_remove,
890 static int otg_bind(
struct isp1301 *isp)
912 static void otg_unbind(
struct isp1301 *isp)
927 static void b_peripheral(
struct isp1301 *isp)
934 usb_gadget_vbus_connect(isp->
phy.otg->gadget);
936 #ifdef CONFIG_USB_OTG
937 enable_vbus_draw(isp, 8);
940 enable_vbus_draw(isp, 100);
946 dump_regs(isp,
"2periph");
953 u8 isp_stat, isp_bstat;
957 pr_debug(
"OTG: BDIS_ACON, %s\n", state_name(isp));
961 if (isp_stat & INTR_ID_GND) {
968 enable_vbus_source(isp);
976 if (isp_stat & INTR_VBUS_VLD)
980 if (!(isp_stat & INTR_SESS_VLD))
981 a_idle(isp,
"vfell");
984 if (!(isp_stat & INTR_VBUS_VLD))
994 usb_gadget_vbus_disconnect(otg->
gadget);
1038 switch (isp->
phy.state) {
1042 if (
likely(isp_bstat & OTG_B_SESS_VLD))
1044 enable_vbus_draw(isp, 0);
1045 #ifndef CONFIG_USB_OTG
1051 dump_regs(isp, __func__);
1055 b_idle(isp, __func__);
1060 if (otg->
gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1061 #ifdef CONFIG_USB_OTG
1062 update_otg1(isp, isp_stat);
1063 update_otg2(isp, isp_bstat);
1066 }
else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1072 pr_debug(
"otg: unsupported b-device %s\n",
1078 if (state != isp->
phy.state)
1082 #ifdef CONFIG_USB_OTG
1086 update_otg1(isp, isp_stat);
1087 update_otg2(isp, isp_bstat);
1088 check_state(isp, __func__);
1091 dump_regs(isp,
"isp1301->otg");
1096 static u8 isp1301_clear_latch(
struct isp1301 *isp)
1114 #ifdef CONFIG_USB_OTG
1117 otg_update_isp(isp);
1123 u8 stat = isp1301_clear_latch(isp);
1125 isp_update_otg(isp, stat);
1136 switch (isp->
phy.state) {
1166 dump_regs(isp,
"timer");
1175 "work done, todo = 0x%lx\n",
1181 }
while (isp->
todo);
1185 static irqreturn_t isp1301_irq(
int irq,
void *isp)
1191 static void isp1301_timer(
unsigned long _isp)
1193 isp1301_defer_work((
void *)_isp,
WORK_TIMER);
1198 static void isp1301_release(
struct device *dev)
1213 static struct isp1301 *the_transceiver;
1219 isp = i2c_get_clientdata(i2c);
1224 #ifdef CONFIG_USB_OTG
1227 if (machine_is_omap_h2())
1230 isp->
timer.data = 0;
1236 the_transceiver =
NULL;
1256 #ifdef CONFIG_USB_OTG
1258 static int isp1301_otg_enable(
struct isp1301 *isp)
1261 isp1301_otg_init(isp);
1267 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1269 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1280 isp1301_set_host(
struct usb_otg *otg,
struct usb_bus *
host)
1284 if (!otg || isp != the_transceiver)
1294 #ifdef CONFIG_USB_OTG
1299 return isp1301_otg_enable(isp);
1302 #elif !defined(CONFIG_USB_GADGET_OMAP)
1308 if (machine_is_omap_h2())
1324 dump_regs(isp, __func__);
1340 if (!otg || isp != the_transceiver)
1346 enable_vbus_draw(isp, 0);
1347 usb_gadget_vbus_disconnect(otg->
gadget);
1353 #ifdef CONFIG_USB_OTG
1358 return isp1301_otg_enable(isp);
1361 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1377 if (machine_is_omap_h2() || machine_is_omap_h3())
1385 dump_regs(isp, __func__);
1397 dev_dbg(&isp->
client->dev,
"peripheral sessions not allowed\n");
1406 isp1301_set_power(
struct usb_phy *dev,
unsigned mA)
1408 if (!the_transceiver)
1411 enable_vbus_draw(the_transceiver, mA);
1416 isp1301_start_srp(
struct usb_otg *otg)
1421 if (!otg || isp != the_transceiver
1434 pr_debug(
"otg: SRP, %s ... %06x\n", state_name(isp),
1436 #ifdef CONFIG_USB_OTG
1437 check_state(isp, __func__);
1443 isp1301_start_hnp(
struct usb_otg *otg)
1445 #ifdef CONFIG_USB_OTG
1449 if (!otg || isp != the_transceiver)
1454 || !otg->
gadget->b_hnp_enable))
1460 switch (isp->
phy.state) {
1472 usb_gadget_vbus_connect(otg->
gadget);
1484 pr_debug(
"otg: HNP %s, %06x ...\n",
1486 check_state(isp, __func__);
1502 if (the_transceiver)
1510 if (!isp->
phy.otg) {
1517 isp->
timer.function = isp1301_timer;
1520 i2c_set_clientdata(i2c, isp);
1526 dev_dbg(&i2c->
dev,
"not philips id: %d\n", status);
1531 dev_dbg(&i2c->
dev,
"not isp1301, %d\n", status);
1535 i2c->
dev.release = isp1301_release;
1540 status >> 8, status & 0xff);
1557 #ifdef CONFIG_USB_OTG
1558 status = otg_bind(isp);
1565 if (machine_is_omap_h2()) {
1582 dev_dbg(&i2c->
dev,
"can't get IRQ %d, err %d\n",
1587 isp->
phy.dev = &i2c->
dev;
1589 isp->
phy.set_power = isp1301_set_power,
1591 isp->
phy.otg->phy = &isp->
phy;
1592 isp->
phy.otg->set_host = isp1301_set_host,
1593 isp->
phy.otg->set_peripheral = isp1301_set_peripheral,
1594 isp->
phy.otg->start_srp = isp1301_start_srp,
1595 isp->
phy.otg->start_hnp = isp1301_start_hnp,
1597 enable_vbus_draw(isp, 0);
1599 the_transceiver = isp;
1601 #ifdef CONFIG_USB_OTG
1606 dump_regs(isp, __func__);
1615 dev_err(&i2c->
dev,
"can't register transceiver, %d\n",
1627 {
"isp1301_omap", 0 },
1634 .name =
"isp1301_omap",
1636 .probe = isp1301_probe,
1637 .remove =
__exit_p(isp1301_remove),
1638 .id_table = isp1301_id,
1643 static int __init isp_init(
void)
1645 return i2c_add_driver(&isp1301_driver);
1649 static void __exit isp_exit(
void)
1651 if (the_transceiver)