Lines Matching +full:t +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0+
3 * isp1301_omap - ISP 1301 USB transceiver, talking to OMAP OTG controller
24 #include <asm/mach-types.h>
40 struct usb_phy phy; member
59 # define WORK_STOP 7 /* don't resubmit */
78 /*-------------------------------------------------------------------------*/
80 /* board-specific PM hooks */
111 * unless the OTG port is used only in B-peripheral mode. in enable_vbus_draw()
119 /* this board won't supply more than 8mA vbus power. in enable_vbus_source()
132 /*-------------------------------------------------------------------------*/
141 return i2c_smbus_read_byte_data(isp->client, reg + 0); in isp1301_get_u8()
147 return i2c_smbus_read_word_data(isp->client, reg); in isp1301_get_u16()
153 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits); in isp1301_set_bits()
159 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits); in isp1301_clear_bits()
162 /*-------------------------------------------------------------------------*/
220 /*-------------------------------------------------------------------------*/
224 return usb_otg_state_string(isp->phy.otg->state); in state_name()
227 /*-------------------------------------------------------------------------*/
230 * not everything is guarded by board-specific checks, or even using
233 * ALSO: this currently doesn't use ISP1301 low-power modes
239 isp->phy.otg->state = OTG_STATE_UNDEFINED; in power_down()
254 * so host won't see a low speed device... in power_up()
268 if (!isp->phy.otg->host) in host_suspend()
269 return -ENODEV; in host_suspend()
274 dev = isp->phy.otg->host->controller; in host_suspend()
275 return dev->driver->suspend(dev, 3, 0); in host_suspend()
286 if (!isp->phy.otg->host) in host_resume()
287 return -ENODEV; in host_resume()
289 dev = isp->phy.otg->host->controller; in host_resume()
290 return dev->driver->resume(dev, 0); in host_resume()
296 isp->phy.otg->gadget->b_hnp_enable = 0; in gadget_suspend()
297 isp->phy.otg->gadget->a_hnp_support = 0; in gadget_suspend()
298 isp->phy.otg->gadget->a_alt_hnp_support = 0; in gadget_suspend()
299 return usb_gadget_vbus_disconnect(isp->phy.otg->gadget); in gadget_suspend()
302 /*-------------------------------------------------------------------------*/
308 * NOTE: guaranteeing certain response times might mean we shouldn't
315 if (isp && !test_and_set_bit(work, &isp->todo)) { in isp1301_defer_work()
316 (void) get_device(&isp->client->dev); in isp1301_defer_work()
317 status = schedule_work(&isp->work); in isp1301_defer_work()
318 if (!status && !isp->working) in isp1301_defer_work()
319 dev_vdbg(&isp->client->dev, in isp1301_defer_work()
329 if (isp->phy.otg->state == OTG_STATE_A_IDLE) in a_idle()
332 isp->phy.otg->default_a = 1; in a_idle()
333 if (isp->phy.otg->host) { in a_idle()
334 isp->phy.otg->host->is_b_host = 0; in a_idle()
337 if (isp->phy.otg->gadget) { in a_idle()
338 isp->phy.otg->gadget->is_a_peripheral = 1; in a_idle()
341 isp->phy.otg->state = OTG_STATE_A_IDLE; in a_idle()
344 isp->last_otg_ctrl = l; in a_idle()
345 pr_debug(" --> %s/%s\n", state_name(isp), tag); in a_idle()
353 if (isp->phy.otg->state == OTG_STATE_B_IDLE) in b_idle()
356 isp->phy.otg->default_a = 0; in b_idle()
357 if (isp->phy.otg->host) { in b_idle()
358 isp->phy.otg->host->is_b_host = 1; in b_idle()
361 if (isp->phy.otg->gadget) { in b_idle()
362 isp->phy.otg->gadget->is_a_peripheral = 0; in b_idle()
365 isp->phy.otg->state = OTG_STATE_B_IDLE; in b_idle()
368 isp->last_otg_ctrl = l; in b_idle()
369 pr_debug(" --> %s/%s\n", state_name(isp), tag); in b_idle()
382 /* mode control and irq enables don't change much */ in dump_regs()
385 /*-------------------------------------------------------------------------*/
407 /* default-b */ in check_state()
421 /* extra dual-role default-b states */ in check_state()
433 /* default-a */ in check_state()
464 if (isp->phy.otg->state == state && !extra) in check_state()
488 else if (isp->phy.otg->state == OTG_STATE_A_WAIT_VFALL) { in update_otg1()
494 if (int_src & INTR_ID_GND) { /* default-A */ in update_otg1()
495 if (isp->phy.otg->state == OTG_STATE_B_IDLE in update_otg1()
496 || isp->phy.otg->state in update_otg1()
501 } else { /* default-B */ in update_otg1()
503 if (isp->phy.otg->state == OTG_STATE_A_IDLE in update_otg1()
504 || isp->phy.otg->state == OTG_STATE_UNDEFINED) { in update_otg1()
534 otg_change = otg_ctrl ^ isp->last_otg_ctrl; in otg_update_isp()
535 isp->last_otg_ctrl = otg_ctrl; in otg_update_isp()
538 switch (isp->phy.otg->state) { in otg_update_isp()
544 if (isp->phy.otg->gadget->b_hnp_enable) { in otg_update_isp()
545 isp->phy.otg->state = OTG_STATE_B_WAIT_ACON; in otg_update_isp()
546 pr_debug(" --> b_wait_acon\n"); in otg_update_isp()
572 if (!(isp->phy.otg->host)) in otg_update_isp()
575 switch (isp->phy.otg->state) { in otg_update_isp()
586 isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL; in otg_update_isp()
587 pr_debug(" --> a_wait_vfall\n"); in otg_update_isp()
595 isp->phy.otg->state = OTG_STATE_A_WAIT_VRISE; in otg_update_isp()
596 pr_debug(" --> a_wait_vrise\n"); in otg_update_isp()
615 switch (isp->phy.otg->state) { in otg_update_isp()
619 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; in otg_update_isp()
620 pr_debug(" --> b_peripheral\n"); in otg_update_isp()
625 isp->phy.otg->state = OTG_STATE_A_PERIPHERAL; in otg_update_isp()
626 pr_debug(" --> a_peripheral\n"); in otg_update_isp()
637 dump_regs(isp, "otg->isp1301"); in otg_update_isp()
646 struct usb_otg *otg = isp->phy.otg; in omap_otg_irq()
661 * to give "check cable and A-device" messages. in omap_otg_irq()
663 if (isp->phy.otg->state == OTG_STATE_B_SRP_INIT) in omap_otg_irq()
681 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; in omap_otg_irq()
682 pr_debug(" --> b_peripheral\n"); in omap_otg_irq()
687 /* detect SRP from B-device ... */ in omap_otg_irq()
693 switch (isp->phy.otg->state) { in omap_otg_irq()
695 if (!otg->host) in omap_otg_irq()
712 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise) in omap_otg_irq()
713 * we don't track them separately in omap_otg_irq()
724 isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL; in omap_otg_irq()
729 /* A-supplied voltage fell too low; overcurrent */ in omap_otg_irq()
738 isp->phy.otg->state = OTG_STATE_A_VBUS_ERR; in omap_otg_irq()
759 switch (isp->phy.otg->state) { in omap_otg_irq()
775 if (otg->host) { in omap_otg_irq()
776 switch (isp->phy.otg->state) { in omap_otg_irq()
778 isp->phy.otg->state = OTG_STATE_B_HOST; in omap_otg_irq()
779 pr_debug(" --> b_host\n"); in omap_otg_irq()
783 isp->phy.otg->state = OTG_STATE_A_HOST; in omap_otg_irq()
784 pr_debug(" --> a_host\n"); in omap_otg_irq()
787 isp->phy.otg->state = OTG_STATE_A_WAIT_BCON; in omap_otg_irq()
788 pr_debug(" --> a_wait_bcon\n"); in omap_otg_irq()
801 usb_bus_start_enum(otg->host, otg->host->otg_port); in omap_otg_irq()
815 return -ENODEV; in isp1301_otg_init()
818 /* some of these values are board-specific... */ in isp1301_otg_init()
821 /* for B-device: */ in isp1301_otg_init()
825 /* for A-device: */ in isp1301_otg_init()
852 // struct omap_usb_config *config = dev->platform_data; in otg_probe()
877 return -EBUSY; in otg_bind()
884 status = request_irq(otg_dev->resource[1].start, omap_otg_irq, in otg_bind()
887 status = -ENODEV; in otg_bind()
898 free_irq(otg_dev->resource[1].start, isp); in otg_unbind()
903 /* OTG controller isn't clocked */
907 /*-------------------------------------------------------------------------*/
916 usb_gadget_vbus_connect(isp->phy.otg->gadget); in b_peripheral()
926 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; in b_peripheral()
927 pr_debug(" --> b_peripheral\n"); in b_peripheral()
934 struct usb_otg *otg = isp->phy.otg; in isp_update_otg()
936 enum usb_otg_state state = isp->phy.otg->state; in isp_update_otg()
944 if (otg->default_a) { in isp_update_otg()
959 isp->phy.otg->state = OTG_STATE_A_HOST; in isp_update_otg()
967 isp->phy.otg->state = OTG_STATE_A_VBUS_ERR; in isp_update_otg()
976 usb_gadget_vbus_disconnect(otg->gadget); in isp_update_otg()
983 if (otg->host && state == OTG_STATE_A_IDLE) in isp_update_otg()
990 /* if user unplugged mini-A end of cable, in isp_update_otg()
991 * don't bypass A_WAIT_VFALL. in isp_update_otg()
993 if (otg->default_a) { in isp_update_otg()
996 isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL; in isp_update_otg()
1001 * handle this disconnect, so don't go in isp_update_otg()
1009 isp->phy.otg->state = OTG_STATE_B_IDLE; in isp_update_otg()
1020 switch (isp->phy.otg->state) { in isp_update_otg()
1042 if (otg->gadget && (isp_bstat & OTG_B_SESS_VLD)) { in isp_update_otg()
1054 pr_debug("otg: unsupported b-device %s\n", in isp_update_otg()
1060 if (state != isp->phy.otg->state) in isp_update_otg()
1061 pr_debug(" isp, %s -> %s\n", in isp_update_otg()
1073 dump_regs(isp, "isp1301->otg"); in isp_update_otg()
1076 /*-------------------------------------------------------------------------*/
1092 isp->working = 1; in isp1301_work()
1094 stop = test_bit(WORK_STOP, &isp->todo); in isp1301_work()
1098 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { in isp1301_work()
1100 put_device(&isp->client->dev); in isp1301_work()
1104 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) { in isp1301_work()
1108 put_device(&isp->client->dev); in isp1301_work()
1111 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { in isp1301_work()
1118 switch (isp->phy.otg->state) { in isp1301_work()
1121 isp->phy.otg->state = OTG_STATE_A_HOST; in isp1301_work()
1122 pr_debug(" --> a_host\n"); in isp1301_work()
1130 isp->phy.otg->state = OTG_STATE_B_HOST; in isp1301_work()
1131 pr_debug(" --> b_host (acon)\n"); in isp1301_work()
1143 put_device(&isp->client->dev); in isp1301_work()
1146 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { in isp1301_work()
1150 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); in isp1301_work()
1152 put_device(&isp->client->dev); in isp1301_work()
1155 if (isp->todo) in isp1301_work()
1156 dev_vdbg(&isp->client->dev, in isp1301_work()
1158 isp->todo); in isp1301_work()
1160 dev_dbg(&isp->client->dev, "stop\n"); in isp1301_work()
1163 } while (isp->todo); in isp1301_work()
1164 isp->working = 0; in isp1301_work()
1173 static void isp1301_timer(struct timer_list *t) in isp1301_timer() argument
1175 struct isp1301 *isp = from_timer(isp, t, timer); in isp1301_timer()
1180 /*-------------------------------------------------------------------------*/
1188 /* FIXME -- not with a "new style" driver, it doesn't!! */ in isp1301_release()
1190 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ in isp1301_release()
1191 if (isp->i2c_release) in isp1301_release()
1192 isp->i2c_release(dev); in isp1301_release()
1193 kfree(isp->phy.otg); in isp1301_release()
1207 free_irq(i2c->irq, isp); in isp1301_remove()
1211 set_bit(WORK_STOP, &isp->todo); in isp1301_remove()
1212 del_timer_sync(&isp->timer); in isp1301_remove()
1213 flush_work(&isp->work); in isp1301_remove()
1215 put_device(&i2c->dev); in isp1301_remove()
1221 /*-------------------------------------------------------------------------*/
1224 * will be standards-conformant on any given system:
1226 * - OTG mode (dual-role), required if there's a Mini-AB connector
1227 * - HOST mode, for when there's one or more A (host) connectors
1228 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1230 * As a rule, you won't have an isp1301 chip unless it's there to
1243 /* NOTE: since we don't change this, this provides in isp1301_otg_enable()
1251 dev_info(&isp->client->dev, "ready for dual-role USB ...\n"); in isp1301_otg_enable()
1262 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); in isp1301_set_host()
1265 return -ENODEV; in isp1301_set_host()
1270 otg->host = NULL; in isp1301_set_host()
1275 otg->host = host; in isp1301_set_host()
1276 dev_dbg(&isp->client->dev, "registered host\n"); in isp1301_set_host()
1278 if (otg->gadget) in isp1301_set_host()
1284 otg->host = host; in isp1301_set_host()
1291 dev_info(&isp->client->dev, "A-Host sessions ok\n"); in isp1301_set_host()
1297 /* If this has a Mini-AB connector, this mode is highly in isp1301_set_host()
1299 * the Mini-A end of an OTG cable. (Or something nonstandard in isp1301_set_host()
1300 * like MiniB-to-StandardB, maybe built with a gender mender.) in isp1301_set_host()
1309 dev_dbg(&isp->client->dev, "host sessions not allowed\n"); in isp1301_set_host()
1310 return -EINVAL; in isp1301_set_host()
1318 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); in isp1301_set_peripheral()
1321 return -ENODEV; in isp1301_set_peripheral()
1325 if (!otg->default_a) in isp1301_set_peripheral()
1327 usb_gadget_vbus_disconnect(otg->gadget); in isp1301_set_peripheral()
1328 otg->gadget = NULL; in isp1301_set_peripheral()
1334 otg->gadget = gadget; in isp1301_set_peripheral()
1335 dev_dbg(&isp->client->dev, "registered gadget\n"); in isp1301_set_peripheral()
1337 if (otg->host) in isp1301_set_peripheral()
1342 otg->gadget = gadget; in isp1301_set_peripheral()
1355 isp->phy.otg->state = OTG_STATE_B_IDLE; in isp1301_set_peripheral()
1364 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n"); in isp1301_set_peripheral()
1367 /* If this has a Mini-AB connector, this mode is highly in isp1301_set_peripheral()
1369 * as you don't plug a Mini-A cable into the jack. in isp1301_set_peripheral()
1377 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n"); in isp1301_set_peripheral()
1378 return -EINVAL; in isp1301_set_peripheral()
1383 /*-------------------------------------------------------------------------*/
1389 return -ENODEV; in isp1301_set_power()
1390 if (dev->otg->state == OTG_STATE_B_PERIPHERAL) in isp1301_set_power()
1398 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); in isp1301_start_srp()
1401 if (isp != the_transceiver || isp->phy.otg->state != OTG_STATE_B_IDLE) in isp1301_start_srp()
1402 return -ENODEV; in isp1301_start_srp()
1406 return -EINVAL; in isp1301_start_srp()
1411 isp->phy.otg->state = OTG_STATE_B_SRP_INIT; in isp1301_start_srp()
1425 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy); in isp1301_start_hnp()
1429 return -ENODEV; in isp1301_start_hnp()
1430 if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable)) in isp1301_start_hnp()
1431 return -ENOTCONN; in isp1301_start_hnp()
1432 if (!otg->default_a && (otg->gadget == NULL in isp1301_start_hnp()
1433 || !otg->gadget->b_hnp_enable)) in isp1301_start_hnp()
1434 return -ENOTCONN; in isp1301_start_hnp()
1439 switch (isp->phy.otg->state) { in isp1301_start_hnp()
1441 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL; in isp1301_start_hnp()
1451 usb_gadget_vbus_connect(otg->gadget); in isp1301_start_hnp()
1458 /* initiated by B-Host suspend */ in isp1301_start_hnp()
1461 return -EILSEQ; in isp1301_start_hnp()
1468 /* srp-only */ in isp1301_start_hnp()
1469 return -EINVAL; in isp1301_start_hnp()
1473 /*-------------------------------------------------------------------------*/
1489 isp->phy.otg = kzalloc(sizeof *isp->phy.otg, GFP_KERNEL); in isp1301_probe()
1490 if (!isp->phy.otg) { in isp1301_probe()
1495 INIT_WORK(&isp->work, isp1301_work); in isp1301_probe()
1496 timer_setup(&isp->timer, isp1301_timer, 0); in isp1301_probe()
1499 isp->client = i2c; in isp1301_probe()
1501 /* verify the chip (shouldn't be necessary) */ in isp1301_probe()
1504 dev_dbg(&i2c->dev, "not philips id: %d\n", status); in isp1301_probe()
1509 dev_dbg(&i2c->dev, "not isp1301, %d\n", status); in isp1301_probe()
1512 isp->i2c_release = i2c->dev.release; in isp1301_probe()
1513 i2c->dev.release = isp1301_release; in isp1301_probe()
1517 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n", in isp1301_probe()
1520 /* make like power-on reset */ in isp1301_probe()
1538 dev_dbg(&i2c->dev, "can't bind OTG\n"); in isp1301_probe()
1552 gpiod = devm_gpiod_get(&i2c->dev, NULL, GPIOD_IN); in isp1301_probe()
1554 dev_err(&i2c->dev, "cannot obtain H2 GPIO\n"); in isp1301_probe()
1559 isp->irq_type = IRQF_TRIGGER_FALLING; in isp1301_probe()
1561 irq = i2c->irq; in isp1301_probe()
1565 isp->irq_type, DRIVER_NAME, isp); in isp1301_probe()
1567 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", in isp1301_probe()
1568 i2c->irq, status); in isp1301_probe()
1572 isp->phy.dev = &i2c->dev; in isp1301_probe()
1573 isp->phy.label = DRIVER_NAME; in isp1301_probe()
1574 isp->phy.set_power = isp1301_set_power; in isp1301_probe()
1576 isp->phy.otg->usb_phy = &isp->phy; in isp1301_probe()
1577 isp->phy.otg->set_host = isp1301_set_host; in isp1301_probe()
1578 isp->phy.otg->set_peripheral = isp1301_set_peripheral; in isp1301_probe()
1579 isp->phy.otg->start_srp = isp1301_start_srp; in isp1301_probe()
1580 isp->phy.otg->start_hnp = isp1301_start_hnp; in isp1301_probe()
1594 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); in isp1301_probe()
1595 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES); in isp1301_probe()
1598 status = usb_add_phy(&isp->phy, USB_PHY_TYPE_USB2); in isp1301_probe()
1600 dev_err(&i2c->dev, "can't register transceiver, %d\n", in isp1301_probe()
1606 kfree(isp->phy.otg); in isp1301_probe()
1608 return -ENODEV; in isp1301_probe()
1626 /*-------------------------------------------------------------------------*/
1637 usb_remove_phy(&the_transceiver->phy); in isp_exit()