Lines Matching full:isp

61 static inline int isp1704_read(struct isp1704_charger *isp, u32 reg)  in isp1704_read()  argument
63 return usb_phy_io_read(isp->phy, reg); in isp1704_read()
66 static inline int isp1704_write(struct isp1704_charger *isp, u32 reg, u32 val) in isp1704_write() argument
68 return usb_phy_io_write(isp->phy, val, reg); in isp1704_write()
71 static void isp1704_charger_set_power(struct isp1704_charger *isp, bool on) in isp1704_charger_set_power() argument
73 gpiod_set_value(isp->enable_gpio, on); in isp1704_charger_set_power()
83 static inline int isp1704_charger_type(struct isp1704_charger *isp) in isp1704_charger_type() argument
90 func_ctrl = isp1704_read(isp, ULPI_FUNC_CTRL); in isp1704_charger_type()
91 otg_ctrl = isp1704_read(isp, ULPI_OTG_CTRL); in isp1704_charger_type()
95 isp1704_write(isp, ULPI_CLR(ULPI_OTG_CTRL), reg); in isp1704_charger_type()
98 isp1704_write(isp, ULPI_CLR(ULPI_FUNC_CTRL), in isp1704_charger_type()
100 isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL), in isp1704_charger_type()
105 isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL), reg); in isp1704_charger_type()
108 reg = isp1704_read(isp, ULPI_DEBUG); in isp1704_charger_type()
113 isp1704_write(isp, ULPI_FUNC_CTRL, func_ctrl); in isp1704_charger_type()
114 isp1704_write(isp, ULPI_OTG_CTRL, otg_ctrl); in isp1704_charger_type()
123 static inline int isp1704_charger_verify(struct isp1704_charger *isp) in isp1704_charger_verify() argument
129 r = isp1704_read(isp, ULPI_FUNC_CTRL); in isp1704_charger_verify()
131 isp1704_write(isp, ULPI_FUNC_CTRL, r); in isp1704_charger_verify()
136 isp1704_write(isp, ULPI_FUNC_CTRL, r); in isp1704_charger_verify()
140 isp1704_write(isp, ULPI_CLR(ULPI_OTG_CTRL), r); in isp1704_charger_verify()
144 isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL), r); in isp1704_charger_verify()
148 if (!isp1704_read(isp, ULPI_DEBUG)) { in isp1704_charger_verify()
150 isp1704_write(isp, ULPI_CLR(ULPI_FUNC_CTRL), in isp1704_charger_verify()
158 isp1704_write(isp, ULPI_SET(ISP1704_PWR_CTRL), in isp1704_charger_verify()
162 isp1704_write(isp, ULPI_CLR(ULPI_FUNC_CTRL), in isp1704_charger_verify()
166 isp1704_write(isp, ULPI_SET(ULPI_OTG_CTRL), in isp1704_charger_verify()
170 if (!(isp1704_read(isp, ULPI_DEBUG))) in isp1704_charger_verify()
174 isp1704_write(isp, ULPI_CLR(ISP1704_PWR_CTRL), in isp1704_charger_verify()
180 static inline int isp1704_charger_detect(struct isp1704_charger *isp) in isp1704_charger_detect() argument
186 pwr_ctrl = isp1704_read(isp, ISP1704_PWR_CTRL); in isp1704_charger_detect()
189 isp1704_write(isp, ISP1704_PWR_CTRL, in isp1704_charger_detect()
193 isp1704_write(isp, ULPI_SET(ISP1704_PWR_CTRL), in isp1704_charger_detect()
201 if (isp1704_read(isp, ISP1704_PWR_CTRL) in isp1704_charger_detect()
203 ret = isp1704_charger_verify(isp); in isp1704_charger_detect()
206 } while (!time_after(jiffies, timeout) && isp->online); in isp1704_charger_detect()
209 isp1704_write(isp, ISP1704_PWR_CTRL, pwr_ctrl); in isp1704_charger_detect()
214 static inline int isp1704_charger_detect_dcp(struct isp1704_charger *isp) in isp1704_charger_detect_dcp() argument
216 if (isp1704_charger_detect(isp) && in isp1704_charger_detect_dcp()
217 isp1704_charger_type(isp) == POWER_SUPPLY_TYPE_USB_DCP) in isp1704_charger_detect_dcp()
225 struct isp1704_charger *isp = in isp1704_charger_work() local
231 switch (isp->phy->last_event) { in isp1704_charger_work()
234 if (!isp->present) { in isp1704_charger_work()
235 isp->online = true; in isp1704_charger_work()
236 isp->present = 1; in isp1704_charger_work()
237 isp1704_charger_set_power(isp, 1); in isp1704_charger_work()
240 if (isp1704_charger_detect_dcp(isp)) { in isp1704_charger_work()
241 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB_DCP; in isp1704_charger_work()
242 isp->current_max = 1800; in isp1704_charger_work()
244 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB; in isp1704_charger_work()
245 isp->current_max = 500; in isp1704_charger_work()
249 if (isp->phy->otg->gadget) in isp1704_charger_work()
250 usb_gadget_connect(isp->phy->otg->gadget); in isp1704_charger_work()
253 if (isp->psy_desc.type != POWER_SUPPLY_TYPE_USB_DCP) { in isp1704_charger_work()
258 if (isp->current_max > 500) in isp1704_charger_work()
259 isp->current_max = 500; in isp1704_charger_work()
261 if (isp->current_max > 100) in isp1704_charger_work()
262 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB_CDP; in isp1704_charger_work()
266 isp->online = false; in isp1704_charger_work()
267 isp->present = 0; in isp1704_charger_work()
268 isp->current_max = 0; in isp1704_charger_work()
269 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB; in isp1704_charger_work()
279 if (isp->phy->otg->gadget) in isp1704_charger_work()
280 usb_gadget_disconnect(isp->phy->otg->gadget); in isp1704_charger_work()
282 isp1704_charger_set_power(isp, 0); in isp1704_charger_work()
288 power_supply_changed(isp->psy); in isp1704_charger_work()
296 struct isp1704_charger *isp = in isp1704_notifier_call() local
299 schedule_work(&isp->work); in isp1704_notifier_call()
308 struct isp1704_charger *isp = power_supply_get_drvdata(psy); in isp1704_charger_get_property() local
312 val->intval = isp->present; in isp1704_charger_get_property()
315 val->intval = isp->online; in isp1704_charger_get_property()
318 val->intval = isp->current_max; in isp1704_charger_get_property()
321 val->strval = isp->model; in isp1704_charger_get_property()
340 static inline int isp1704_test_ulpi(struct isp1704_charger *isp) in isp1704_test_ulpi() argument
348 ret = isp1704_write(isp, ULPI_SCRATCH, 0xaa); in isp1704_test_ulpi()
352 ret = isp1704_read(isp, ULPI_SCRATCH); in isp1704_test_ulpi()
360 vendor = isp1704_read(isp, ULPI_VENDOR_ID_LOW); in isp1704_test_ulpi()
361 vendor |= isp1704_read(isp, ULPI_VENDOR_ID_HIGH) << 8; in isp1704_test_ulpi()
365 product = isp1704_read(isp, ULPI_PRODUCT_ID_LOW); in isp1704_test_ulpi()
366 product |= isp1704_read(isp, ULPI_PRODUCT_ID_HIGH) << 8; in isp1704_test_ulpi()
370 sprintf(isp->model, "isp%x", product); in isp1704_test_ulpi()
375 dev_err(isp->dev, "product id %x not matching known ids", product); in isp1704_test_ulpi()
382 struct isp1704_charger *isp; in isp1704_charger_probe() local
386 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); in isp1704_charger_probe()
387 if (!isp) in isp1704_charger_probe()
390 isp->enable_gpio = devm_gpiod_get(&pdev->dev, "nxp,enable", in isp1704_charger_probe()
392 if (IS_ERR(isp->enable_gpio)) { in isp1704_charger_probe()
393 ret = PTR_ERR(isp->enable_gpio); in isp1704_charger_probe()
399 isp->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); in isp1704_charger_probe()
401 isp->phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); in isp1704_charger_probe()
403 if (IS_ERR(isp->phy)) { in isp1704_charger_probe()
404 ret = PTR_ERR(isp->phy); in isp1704_charger_probe()
409 isp->dev = &pdev->dev; in isp1704_charger_probe()
410 platform_set_drvdata(pdev, isp); in isp1704_charger_probe()
412 isp1704_charger_set_power(isp, 1); in isp1704_charger_probe()
414 ret = isp1704_test_ulpi(isp); in isp1704_charger_probe()
420 isp->psy_desc.name = "isp1704"; in isp1704_charger_probe()
421 isp->psy_desc.type = POWER_SUPPLY_TYPE_USB; in isp1704_charger_probe()
422 isp->psy_desc.properties = power_props; in isp1704_charger_probe()
423 isp->psy_desc.num_properties = ARRAY_SIZE(power_props); in isp1704_charger_probe()
424 isp->psy_desc.get_property = isp1704_charger_get_property; in isp1704_charger_probe()
426 psy_cfg.drv_data = isp; in isp1704_charger_probe()
428 isp->psy = power_supply_register(isp->dev, &isp->psy_desc, &psy_cfg); in isp1704_charger_probe()
429 if (IS_ERR(isp->psy)) { in isp1704_charger_probe()
430 ret = PTR_ERR(isp->psy); in isp1704_charger_probe()
439 INIT_WORK(&isp->work, isp1704_charger_work); in isp1704_charger_probe()
441 isp->nb.notifier_call = isp1704_notifier_call; in isp1704_charger_probe()
443 ret = usb_register_notifier(isp->phy, &isp->nb); in isp1704_charger_probe()
449 dev_info(isp->dev, "registered with product id %s\n", isp->model); in isp1704_charger_probe()
458 if (isp->phy->otg->gadget) in isp1704_charger_probe()
459 usb_gadget_disconnect(isp->phy->otg->gadget); in isp1704_charger_probe()
461 if (isp->phy->last_event == USB_EVENT_NONE) in isp1704_charger_probe()
462 isp1704_charger_set_power(isp, 0); in isp1704_charger_probe()
465 if (isp->phy->last_event == USB_EVENT_VBUS && in isp1704_charger_probe()
466 !isp->phy->otg->default_a) in isp1704_charger_probe()
467 schedule_work(&isp->work); in isp1704_charger_probe()
471 power_supply_unregister(isp->psy); in isp1704_charger_probe()
473 isp1704_charger_set_power(isp, 0); in isp1704_charger_probe()
482 struct isp1704_charger *isp = platform_get_drvdata(pdev); in isp1704_charger_remove() local
484 usb_unregister_notifier(isp->phy, &isp->nb); in isp1704_charger_remove()
485 power_supply_unregister(isp->psy); in isp1704_charger_remove()
486 isp1704_charger_set_power(isp, 0); in isp1704_charger_remove()