/* * Determine is the charging port DCP (dedicated charger) or CDP (Host/HUB * chargers). * * REVISIT: The method is defined in Battery Charging Specification and is * applicable to any ULPI transceiver. Nothing isp170x specific here.
*/ staticinlineint isp1704_charger_type(struct isp1704_charger *isp)
{
u8 reg;
u8 func_ctrl;
u8 otg_ctrl; int type = POWER_SUPPLY_TYPE_USB_DCP;
/* full speed */
isp1704_write(isp, ULPI_CLR(ULPI_FUNC_CTRL),
ULPI_FUNC_CTRL_XCVRSEL_MASK);
isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL),
ULPI_FUNC_CTRL_FULL_SPEED);
/* Enable strong pull-up on DP (1.5K) and reset */
reg = ULPI_FUNC_CTRL_TERMSELECT | ULPI_FUNC_CTRL_RESET;
isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL), reg);
usleep_range(1000, 2000);
reg = isp1704_read(isp, ULPI_DEBUG); if ((reg & 3) != 3)
type = POWER_SUPPLY_TYPE_USB_CDP;
/* recover original state */
isp1704_write(isp, ULPI_FUNC_CTRL, func_ctrl);
isp1704_write(isp, ULPI_OTG_CTRL, otg_ctrl);
return type;
}
/* * ISP1704 detects PS/2 adapters as charger. To make sure the detected charger * is actually a dedicated charger, the following steps need to be taken.
*/ staticinlineint isp1704_charger_verify(struct isp1704_charger *isp)
{ int ret = 0;
u8 r;
/* Reset the transceiver */
r = isp1704_read(isp, ULPI_FUNC_CTRL);
r |= ULPI_FUNC_CTRL_RESET;
isp1704_write(isp, ULPI_FUNC_CTRL, r);
usleep_range(1000, 2000);
/* Set normal mode */
r &= ~(ULPI_FUNC_CTRL_RESET | ULPI_FUNC_CTRL_OPMODE_MASK);
isp1704_write(isp, ULPI_FUNC_CTRL, r);
/* Clear the DP and DM pull-down bits */
r = ULPI_OTG_CTRL_DP_PULLDOWN | ULPI_OTG_CTRL_DM_PULLDOWN;
isp1704_write(isp, ULPI_CLR(ULPI_OTG_CTRL), r);
/* Enable strong pull-up on DP (1.5K) and reset */
r = ULPI_FUNC_CTRL_TERMSELECT | ULPI_FUNC_CTRL_RESET;
isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL), r);
usleep_range(1000, 2000);
/* Read the line state */ if (!isp1704_read(isp, ULPI_DEBUG)) { /* Disable strong pull-up on DP (1.5K) */
isp1704_write(isp, ULPI_CLR(ULPI_FUNC_CTRL),
ULPI_FUNC_CTRL_TERMSELECT); return 1;
}
timeout = jiffies + msecs_to_jiffies(300); do { /* Check if there is a charger */ if (isp1704_read(isp, ISP1704_PWR_CTRL)
& ISP1704_PWR_CTRL_VDAT_DET) {
ret = isp1704_charger_verify(isp); break;
}
} while (!time_after(jiffies, timeout) && isp->online);
/* recover original state */
isp1704_write(isp, ISP1704_PWR_CTRL, pwr_ctrl);
switch (isp->phy->last_event) { case USB_EVENT_VBUS: /* do not call wall charger detection more times */ if (!isp->present) {
isp->online = true;
isp->present = 1;
isp1704_charger_set_power(isp, 1);
/* enable data pullups */ if (isp->phy->otg->gadget)
usb_gadget_connect(isp->phy->otg->gadget);
}
if (isp->psy_desc.type != POWER_SUPPLY_TYPE_USB_DCP) { /* * Only 500mA here or high speed chirp * handshaking may break
*/ if (isp->current_max > 500)
isp->current_max = 500;
/* * Disable data pullups. We need to prevent the controller from * enumerating. * * FIXME: This is here to allow charger detection with Host/HUB * chargers. The pullups may be enabled elsewhere, so this can * not be the final solution.
*/ if (isp->phy->otg->gadget)
usb_gadget_disconnect(isp->phy->otg->gadget);
isp->psy = power_supply_register(isp->dev, &isp->psy_desc, &psy_cfg); if (IS_ERR(isp->psy)) {
ret = PTR_ERR(isp->psy);
dev_err(&pdev->dev, "power_supply_register failed\n"); goto fail1;
}
/* * REVISIT: using work in order to allow the usb notifications to be * made atomically in the future.
*/
INIT_WORK(&isp->work, isp1704_charger_work);
isp->nb.notifier_call = isp1704_notifier_call;
ret = usb_register_notifier(isp->phy, &isp->nb); if (ret) {
dev_err(&pdev->dev, "usb_register_notifier failed\n"); goto fail2;
}
dev_info(isp->dev, "registered with product id %s\n", isp->model);
/* * Taking over the D+ pullup. * * FIXME: The device will be disconnected if it was already * enumerated. The charger driver should be always loaded before any * gadget is loaded.
*/ if (isp->phy->otg->gadget)
usb_gadget_disconnect(isp->phy->otg->gadget);
if (isp->phy->last_event == USB_EVENT_NONE)
isp1704_charger_set_power(isp, 0);
/* Detect charger if VBUS is valid (the cable was already plugged). */ if (isp->phy->last_event == USB_EVENT_VBUS &&
!isp->phy->otg->default_a)
schedule_work(&isp->work);
return 0;
fail2:
power_supply_unregister(isp->psy);
fail1:
isp1704_charger_set_power(isp, 0);
fail0:
dev_err(&pdev->dev, "failed to register isp1704 with error %d\n", ret);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.