Lines Matching +full:usb +full:- +full:sdp

1 // SPDX-License-Identifier: GPL-2.0-only
3 * tusb1210.c - TUSB1210 USB ULPI PHY driver
75 ret = ulpi_write(tusb->ulpi, reg, val); in tusb1210_ulpi_write()
77 dev_err(&tusb->ulpi->dev, "error %d writing val 0x%02x to reg 0x%02x\n", in tusb1210_ulpi_write()
87 ret = ulpi_read(tusb->ulpi, reg); in tusb1210_ulpi_read()
92 dev_err(&tusb->ulpi->dev, "error %d reading reg 0x%02x\n", ret, reg); in tusb1210_ulpi_read()
102 gpiod_set_value_cansleep(tusb->gpio_reset, 1); in tusb1210_power_on()
103 gpiod_set_value_cansleep(tusb->gpio_cs, 1); in tusb1210_power_on()
108 tusb1210_ulpi_write(tusb, TUSB1210_VENDOR_SPECIFIC2, tusb->vendor_specific2); in tusb1210_power_on()
117 gpiod_set_value_cansleep(tusb->gpio_reset, 0); in tusb1210_power_off()
118 gpiod_set_value_cansleep(tusb->gpio_cs, 0); in tusb1210_power_off()
154 tusb->otg_ctrl = reg; in tusb1210_set_mode()
172 gpiod_set_value_cansleep(tusb->gpio_reset, 0); in tusb1210_reset()
174 gpiod_set_value_cansleep(tusb->gpio_reset, 1); in tusb1210_reset()
180 dev_dbg(&tusb->ulpi->dev, "charger type: %d\n", type); in tusb1210_chg_det_set_type()
181 tusb->chg_type = type; in tusb1210_chg_det_set_type()
182 tusb->chg_det_retries = 0; in tusb1210_chg_det_set_type()
183 power_supply_changed(tusb->psy); in tusb1210_chg_det_set_type()
191 dev_dbg(&tusb->ulpi->dev, "chg_det new state %s in %d ms\n", in tusb1210_chg_det_set_state()
194 tusb->chg_det_state = new_state; in tusb1210_chg_det_set_state()
195 mod_delayed_work(system_long_wq, &tusb->chg_det_work, in tusb1210_chg_det_set_state()
202 if (tusb->chg_det_retries < TUSB1210_CHG_DET_MAX_RETRIES) { in tusb1210_chg_det_handle_ulpi_error()
203 tusb->chg_det_retries++; in tusb1210_chg_det_handle_ulpi_error()
213 * Boards using a TUSB121x for charger-detection have 3 power_supply class devs:
215 * tusb1211-charger-detect(1) -> charger -> fuel-gauge
217 * To determine if an USB charger is connected to the board, the online prop of
218 * the charger psy needs to be read. Since the tusb1211-charger-detect psy is
219 * the start of the supplier -> supplied-to chain, power_supply_am_i_supplied()
225 * (1) modelling the external USB charger
228 "bq24190-charger",
236 for (i = 0; i < ARRAY_SIZE(tusb1210_chargers) && !tusb->charger; i++) in tusb1210_get_online()
237 tusb->charger = power_supply_get_by_name(tusb1210_chargers[i]); in tusb1210_get_online()
239 if (!tusb->charger) in tusb1210_get_online()
242 if (power_supply_get_property(tusb->charger, POWER_SUPPLY_PROP_ONLINE, &val)) in tusb1210_get_online()
255 dev_dbg(&tusb->ulpi->dev, "chg_det state %s vbus_present %d\n", in tusb1210_chg_det_work()
256 tusb1210_chg_det_states[tusb->chg_det_state], vbus_present); in tusb1210_chg_det_work()
258 switch (tusb->chg_det_state) { in tusb1210_chg_det_work()
260 tusb->chg_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; in tusb1210_chg_det_work()
261 tusb->chg_det_retries = 0; in tusb1210_chg_det_work()
262 /* Power on USB controller for ulpi_read()/_write() */ in tusb1210_chg_det_work()
263 ret = pm_runtime_resume_and_get(tusb->ulpi->dev.parent); in tusb1210_chg_det_work()
265 dev_err(&tusb->ulpi->dev, "error %d runtime-resuming\n", ret); in tusb1210_chg_det_work()
275 * This only detects DCP / SDP. This is good enough for the few in tusb1210_chg_det_work()
278 mutex_lock(&tusb->phy->mutex); in tusb1210_chg_det_work()
281 mutex_unlock(&tusb->phy->mutex); in tusb1210_chg_det_work()
291 mutex_lock(&tusb->phy->mutex); in tusb1210_chg_det_work()
293 mutex_unlock(&tusb->phy->mutex); in tusb1210_chg_det_work()
307 mutex_lock(&tusb->phy->mutex); in tusb1210_chg_det_work()
309 /* Set SW_CONTROL to stop the charger-det FSM */ in tusb1210_chg_det_work()
313 /* Clear DP_VSRC_EN which may have been enabled by the charger-det FSM */ in tusb1210_chg_det_work()
317 /* Clear CHGD_IDP_SRC_EN (may have been enabled by the charger-det FSM) */ in tusb1210_chg_det_work()
327 /* Restore phy-parameters and OTG_CTRL register */ in tusb1210_chg_det_work()
328 tusb1210_ulpi_write(tusb, ULPI_OTG_CTRL, tusb->otg_ctrl); in tusb1210_chg_det_work()
330 tusb->vendor_specific2); in tusb1210_chg_det_work()
332 mutex_unlock(&tusb->phy->mutex); in tusb1210_chg_det_work()
334 pm_runtime_put(tusb->ulpi->dev.parent); in tusb1210_chg_det_work()
353 * after a Vbus-session end. Reset it to work around this. in tusb1210_chg_det_work()
372 if (psy != tusb->psy && psy->desc->type == POWER_SUPPLY_TYPE_USB) in tusb1210_psy_notifier()
373 queue_delayed_work(system_long_wq, &tusb->chg_det_work, 0); in tusb1210_psy_notifier()
386 val->intval = tusb1210_get_online(tusb); in tusb1210_psy_get_prop()
389 val->intval = tusb->chg_type; in tusb1210_psy_get_prop()
392 if (tusb->chg_type == POWER_SUPPLY_USB_TYPE_DCP) in tusb1210_psy_get_prop()
393 val->intval = 2000000; in tusb1210_psy_get_prop()
395 val->intval = 500000; in tusb1210_psy_get_prop()
398 return -EINVAL; in tusb1210_psy_get_prop()
417 .name = "tusb1211-charger-detect",
426 /* Setup charger detection if requested, on errors continue without chg-det */
430 struct device *dev = &tusb->ulpi->dev; in tusb1210_probe_charger_detect()
433 if (!device_property_read_bool(dev->parent, "linux,phy_charger_detect")) in tusb1210_probe_charger_detect()
436 if (tusb->ulpi->id.product != 0x1508) { in tusb1210_probe_charger_detect()
441 ret = tusb1210_ulpi_read(tusb, ULPI_OTG_CTRL, &tusb->otg_ctrl); in tusb1210_probe_charger_detect()
445 tusb->psy = power_supply_register(dev, &tusb1210_psy_desc, &psy_cfg); in tusb1210_probe_charger_detect()
446 if (IS_ERR(tusb->psy)) in tusb1210_probe_charger_detect()
453 tusb->chg_det_state = TUSB1210_CHG_DET_DISCONNECTED; in tusb1210_probe_charger_detect()
454 INIT_DELAYED_WORK(&tusb->chg_det_work, tusb1210_chg_det_work); in tusb1210_probe_charger_detect()
455 queue_delayed_work(system_long_wq, &tusb->chg_det_work, 2 * HZ); in tusb1210_probe_charger_detect()
457 tusb->psy_nb.notifier_call = tusb1210_psy_notifier; in tusb1210_probe_charger_detect()
458 power_supply_reg_notifier(&tusb->psy_nb); in tusb1210_probe_charger_detect()
464 if (!IS_ERR_OR_NULL(tusb->psy)) { in tusb1210_remove_charger_detect()
465 power_supply_unreg_notifier(&tusb->psy_nb); in tusb1210_remove_charger_detect()
466 cancel_delayed_work_sync(&tusb->chg_det_work); in tusb1210_remove_charger_detect()
467 power_supply_unregister(tusb->psy); in tusb1210_remove_charger_detect()
470 if (tusb->charger) in tusb1210_remove_charger_detect()
471 power_supply_put(tusb->charger); in tusb1210_remove_charger_detect()
491 tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL); in tusb1210_probe()
493 return -ENOMEM; in tusb1210_probe()
495 tusb->ulpi = ulpi; in tusb1210_probe()
497 tusb->gpio_reset = devm_gpiod_get_optional(&ulpi->dev, "reset", in tusb1210_probe()
499 if (IS_ERR(tusb->gpio_reset)) in tusb1210_probe()
500 return PTR_ERR(tusb->gpio_reset); in tusb1210_probe()
502 gpiod_set_value_cansleep(tusb->gpio_reset, 1); in tusb1210_probe()
504 tusb->gpio_cs = devm_gpiod_get_optional(&ulpi->dev, "cs", in tusb1210_probe()
506 if (IS_ERR(tusb->gpio_cs)) in tusb1210_probe()
507 return PTR_ERR(tusb->gpio_cs); in tusb1210_probe()
509 gpiod_set_value_cansleep(tusb->gpio_cs, 1); in tusb1210_probe()
521 if (!device_property_read_u8(&ulpi->dev, "ihstx", &val)) in tusb1210_probe()
525 if (!device_property_read_u8(&ulpi->dev, "zhsdrv", &val)) in tusb1210_probe()
529 if (!device_property_read_u8(&ulpi->dev, "datapolarity", &val)) in tusb1210_probe()
536 tusb->vendor_specific2 = reg; in tusb1210_probe()
540 tusb->phy = ulpi_phy_create(ulpi, &phy_ops); in tusb1210_probe()
541 if (IS_ERR(tusb->phy)) { in tusb1210_probe()
542 ret = PTR_ERR(tusb->phy); in tusb1210_probe()
546 phy_set_drvdata(tusb->phy, tusb); in tusb1210_probe()
559 ulpi_phy_destroy(ulpi, tusb->phy); in tusb1210_remove()