Lines Matching defs:isp

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