Lines Matching +full:usb +full:- +full:hsic +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0+
13 #include <linux/usb/chipidea.h>
14 #include <linux/usb/of.h>
81 { .compatible = "fsl,imx23-usb", .data = &imx23_usb_data},
82 { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data},
83 { .compatible = "fsl,imx27-usb", .data = &imx27_usb_data},
84 { .compatible = "fsl,imx6q-usb", .data = &imx6q_usb_data},
85 { .compatible = "fsl,imx6sl-usb", .data = &imx6sl_usb_data},
86 { .compatible = "fsl,imx6sx-usb", .data = &imx6sx_usb_data},
87 { .compatible = "fsl,imx6ul-usb", .data = &imx6ul_usb_data},
88 { .compatible = "fsl,imx7d-usb", .data = &imx7d_usb_data},
89 { .compatible = "fsl,imx7ulp-usb", .data = &imx7ulp_usb_data},
90 { .compatible = "fsl,imx8ulp-usb", .data = &imx8ulp_usb_data},
96 struct usb_phy *phy; member
111 /* --------------------------------- */
121 struct device_node *np = dev->of_node; in usbmisc_get_init_data()
135 return ERR_PTR(-ENOMEM); in usbmisc_get_init_data()
137 ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells", in usbmisc_get_init_data()
145 data->index = args.args[0]; in usbmisc_get_init_data()
151 return ERR_PTR(-EPROBE_DEFER); in usbmisc_get_init_data()
154 put_device(&misc_pdev->dev); in usbmisc_get_init_data()
155 return ERR_PTR(-EPROBE_DEFER); in usbmisc_get_init_data()
157 data->dev = &misc_pdev->dev; in usbmisc_get_init_data()
163 if (of_property_read_bool(np, "disable-over-current")) { in usbmisc_get_init_data()
164 data->disable_oc = 1; in usbmisc_get_init_data()
165 } else if (of_property_read_bool(np, "over-current-active-high")) { in usbmisc_get_init_data()
166 data->oc_pol_active_low = 0; in usbmisc_get_init_data()
167 data->oc_pol_configured = 1; in usbmisc_get_init_data()
168 } else if (of_property_read_bool(np, "over-current-active-low")) { in usbmisc_get_init_data()
169 data->oc_pol_active_low = 1; in usbmisc_get_init_data()
170 data->oc_pol_configured = 1; in usbmisc_get_init_data()
175 data->pwr_pol = of_property_read_bool(np, "power-active-high"); in usbmisc_get_init_data()
176 data->evdo = of_property_read_bool(np, "external-vbus-divider"); in usbmisc_get_init_data()
179 data->ulpi = 1; in usbmisc_get_init_data()
181 if (of_property_read_u32(np, "samsung,picophy-pre-emp-curr-control", in usbmisc_get_init_data()
182 &data->emp_curr_control)) in usbmisc_get_init_data()
183 data->emp_curr_control = -1; in usbmisc_get_init_data()
184 if (of_property_read_u32(np, "samsung,picophy-dc-vol-level-adjust", in usbmisc_get_init_data()
185 &data->dc_vol_level_adjust)) in usbmisc_get_init_data()
186 data->dc_vol_level_adjust = -1; in usbmisc_get_init_data()
187 if (of_property_read_u32(np, "fsl,picophy-rise-fall-time-adjust", in usbmisc_get_init_data()
188 &data->rise_fall_time_adjust)) in usbmisc_get_init_data()
189 data->rise_fall_time_adjust = -1; in usbmisc_get_init_data()
200 data->clk_ipg = devm_clk_get(dev, "ipg"); in imx_get_clks()
201 if (IS_ERR(data->clk_ipg)) { in imx_get_clks()
203 data->clk = devm_clk_get(dev, NULL); in imx_get_clks()
204 if (IS_ERR(data->clk)) { in imx_get_clks()
205 ret = PTR_ERR(data->clk); in imx_get_clks()
208 PTR_ERR(data->clk), PTR_ERR(data->clk_ipg)); in imx_get_clks()
214 data->clk_ahb = devm_clk_get(dev, "ahb"); in imx_get_clks()
215 if (IS_ERR(data->clk_ahb)) { in imx_get_clks()
216 ret = PTR_ERR(data->clk_ahb); in imx_get_clks()
222 data->clk_per = devm_clk_get(dev, "per"); in imx_get_clks()
223 if (IS_ERR(data->clk_per)) { in imx_get_clks()
224 ret = PTR_ERR(data->clk_per); in imx_get_clks()
230 data->need_three_clks = true; in imx_get_clks()
239 if (data->need_three_clks) { in imx_prepare_enable_clks()
240 ret = clk_prepare_enable(data->clk_ipg); in imx_prepare_enable_clks()
248 ret = clk_prepare_enable(data->clk_ahb); in imx_prepare_enable_clks()
253 clk_disable_unprepare(data->clk_ipg); in imx_prepare_enable_clks()
257 ret = clk_prepare_enable(data->clk_per); in imx_prepare_enable_clks()
262 clk_disable_unprepare(data->clk_ahb); in imx_prepare_enable_clks()
263 clk_disable_unprepare(data->clk_ipg); in imx_prepare_enable_clks()
267 ret = clk_prepare_enable(data->clk); in imx_prepare_enable_clks()
283 if (data->need_three_clks) { in imx_disable_unprepare_clks()
284 clk_disable_unprepare(data->clk_per); in imx_disable_unprepare_clks()
285 clk_disable_unprepare(data->clk_ahb); in imx_disable_unprepare_clks()
286 clk_disable_unprepare(data->clk_ipg); in imx_disable_unprepare_clks()
288 clk_disable_unprepare(data->clk); in imx_disable_unprepare_clks()
294 struct device *dev = ci->dev->parent; in ci_hdrc_imx_notify_event()
297 struct imx_usbmisc_data *mdata = data->usbmisc_data; in ci_hdrc_imx_notify_event()
301 if (data->pinctrl) { in ci_hdrc_imx_notify_event()
302 ret = pinctrl_select_state(data->pinctrl, in ci_hdrc_imx_notify_event()
303 data->pinctrl_hsic_active); in ci_hdrc_imx_notify_event()
317 if (ci->vbus_active) in ci_hdrc_imx_notify_event()
321 if (ci->usb_phy) in ci_hdrc_imx_notify_event()
322 schedule_work(&ci->usb_phy->chg_work); in ci_hdrc_imx_notify_event()
335 .name = dev_name(&pdev->dev), in ci_hdrc_imx_probe()
341 struct device_node *np = pdev->dev.of_node; in ci_hdrc_imx_probe()
342 struct device *dev = &pdev->dev; in ci_hdrc_imx_probe()
344 imx_platform_flag = of_device_get_match_data(&pdev->dev); in ci_hdrc_imx_probe()
346 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in ci_hdrc_imx_probe()
348 return -ENOMEM; in ci_hdrc_imx_probe()
350 data->plat_data = imx_platform_flag; in ci_hdrc_imx_probe()
351 pdata.flags |= imx_platform_flag->flags; in ci_hdrc_imx_probe()
353 data->usbmisc_data = usbmisc_get_init_data(dev); in ci_hdrc_imx_probe()
354 if (IS_ERR(data->usbmisc_data)) in ci_hdrc_imx_probe()
355 return PTR_ERR(data->usbmisc_data); in ci_hdrc_imx_probe()
357 if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) in ci_hdrc_imx_probe()
358 && data->usbmisc_data) { in ci_hdrc_imx_probe()
360 data->usbmisc_data->hsic = 1; in ci_hdrc_imx_probe()
361 data->pinctrl = devm_pinctrl_get(dev); in ci_hdrc_imx_probe()
362 if (PTR_ERR(data->pinctrl) == -ENODEV) in ci_hdrc_imx_probe()
363 data->pinctrl = NULL; in ci_hdrc_imx_probe()
364 else if (IS_ERR(data->pinctrl)) in ci_hdrc_imx_probe()
365 return dev_err_probe(dev, PTR_ERR(data->pinctrl), in ci_hdrc_imx_probe()
368 data->hsic_pad_regulator = in ci_hdrc_imx_probe()
369 devm_regulator_get_optional(dev, "hsic"); in ci_hdrc_imx_probe()
370 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) { in ci_hdrc_imx_probe()
372 data->hsic_pad_regulator = NULL; in ci_hdrc_imx_probe()
373 } else if (IS_ERR(data->hsic_pad_regulator)) in ci_hdrc_imx_probe()
374 return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator), in ci_hdrc_imx_probe()
375 "Get HSIC pad regulator error\n"); in ci_hdrc_imx_probe()
377 if (data->hsic_pad_regulator) { in ci_hdrc_imx_probe()
378 ret = regulator_enable(data->hsic_pad_regulator); in ci_hdrc_imx_probe()
381 "Failed to enable HSIC pad regulator\n"); in ci_hdrc_imx_probe()
387 /* HSIC pinctrl handling */ in ci_hdrc_imx_probe()
388 if (data->pinctrl) { in ci_hdrc_imx_probe()
391 pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle"); in ci_hdrc_imx_probe()
399 ret = pinctrl_select_state(data->pinctrl, pinctrl_hsic_idle); in ci_hdrc_imx_probe()
405 data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl, in ci_hdrc_imx_probe()
407 if (IS_ERR(data->pinctrl_hsic_active)) { in ci_hdrc_imx_probe()
410 PTR_ERR(data->pinctrl_hsic_active)); in ci_hdrc_imx_probe()
411 return PTR_ERR(data->pinctrl_hsic_active); in ci_hdrc_imx_probe()
416 cpu_latency_qos_add_request(&data->pm_qos_req, 0); in ci_hdrc_imx_probe()
426 data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0); in ci_hdrc_imx_probe()
427 if (IS_ERR(data->phy)) { in ci_hdrc_imx_probe()
428 ret = PTR_ERR(data->phy); in ci_hdrc_imx_probe()
429 if (ret != -ENODEV) { in ci_hdrc_imx_probe()
433 data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0); in ci_hdrc_imx_probe()
434 if (IS_ERR(data->phy)) { in ci_hdrc_imx_probe()
435 ret = PTR_ERR(data->phy); in ci_hdrc_imx_probe()
436 if (ret == -ENODEV) { in ci_hdrc_imx_probe()
437 data->phy = NULL; in ci_hdrc_imx_probe()
445 pdata.usb_phy = data->phy; in ci_hdrc_imx_probe()
446 if (data->usbmisc_data) in ci_hdrc_imx_probe()
447 data->usbmisc_data->usb_phy = data->phy; in ci_hdrc_imx_probe()
449 if ((of_device_is_compatible(np, "fsl,imx53-usb") || in ci_hdrc_imx_probe()
450 of_device_is_compatible(np, "fsl,imx51-usb")) && pdata.usb_phy && in ci_hdrc_imx_probe()
453 data->override_phy_control = true; in ci_hdrc_imx_probe()
458 data->supports_runtime_pm = true; in ci_hdrc_imx_probe()
460 ret = imx_usbmisc_init(data->usbmisc_data); in ci_hdrc_imx_probe()
466 data->ci_pdev = ci_hdrc_add_device(dev, in ci_hdrc_imx_probe()
467 pdev->resource, pdev->num_resources, in ci_hdrc_imx_probe()
469 if (IS_ERR(data->ci_pdev)) { in ci_hdrc_imx_probe()
470 ret = PTR_ERR(data->ci_pdev); in ci_hdrc_imx_probe()
475 if (data->usbmisc_data) { in ci_hdrc_imx_probe()
477 of_property_read_bool(np, "usb-role-switch")) in ci_hdrc_imx_probe()
478 data->usbmisc_data->ext_id = 1; in ci_hdrc_imx_probe()
481 of_property_read_bool(np, "usb-role-switch")) in ci_hdrc_imx_probe()
482 data->usbmisc_data->ext_vbus = 1; in ci_hdrc_imx_probe()
485 data->usbmisc_data->available_role = in ci_hdrc_imx_probe()
486 ci_hdrc_query_available_role(data->ci_pdev); in ci_hdrc_imx_probe()
489 ret = imx_usbmisc_init_post(data->usbmisc_data); in ci_hdrc_imx_probe()
495 if (data->supports_runtime_pm) { in ci_hdrc_imx_probe()
505 ci_hdrc_remove_device(data->ci_pdev); in ci_hdrc_imx_probe()
509 if (data->hsic_pad_regulator) in ci_hdrc_imx_probe()
511 regulator_disable(data->hsic_pad_regulator); in ci_hdrc_imx_probe()
513 cpu_latency_qos_remove_request(&data->pm_qos_req); in ci_hdrc_imx_probe()
514 data->ci_pdev = NULL; in ci_hdrc_imx_probe()
522 if (data->supports_runtime_pm) { in ci_hdrc_imx_remove()
523 pm_runtime_get_sync(&pdev->dev); in ci_hdrc_imx_remove()
524 pm_runtime_disable(&pdev->dev); in ci_hdrc_imx_remove()
525 pm_runtime_put_noidle(&pdev->dev); in ci_hdrc_imx_remove()
527 if (data->ci_pdev) in ci_hdrc_imx_remove()
528 ci_hdrc_remove_device(data->ci_pdev); in ci_hdrc_imx_remove()
529 if (data->override_phy_control) in ci_hdrc_imx_remove()
530 usb_phy_shutdown(data->phy); in ci_hdrc_imx_remove()
531 if (data->ci_pdev) { in ci_hdrc_imx_remove()
532 imx_disable_unprepare_clks(&pdev->dev); in ci_hdrc_imx_remove()
533 if (data->plat_data->flags & CI_HDRC_PMQOS) in ci_hdrc_imx_remove()
534 cpu_latency_qos_remove_request(&data->pm_qos_req); in ci_hdrc_imx_remove()
535 if (data->hsic_pad_regulator) in ci_hdrc_imx_remove()
536 regulator_disable(data->hsic_pad_regulator); in ci_hdrc_imx_remove()
553 ret = imx_usbmisc_suspend(data->usbmisc_data, in imx_controller_suspend()
562 if (data->plat_data->flags & CI_HDRC_PMQOS) in imx_controller_suspend()
563 cpu_latency_qos_remove_request(&data->pm_qos_req); in imx_controller_suspend()
565 data->in_lpm = true; in imx_controller_suspend()
578 if (!data->in_lpm) { in imx_controller_resume()
583 if (data->plat_data->flags & CI_HDRC_PMQOS) in imx_controller_resume()
584 cpu_latency_qos_add_request(&data->pm_qos_req, 0); in imx_controller_resume()
590 data->in_lpm = false; in imx_controller_resume()
592 ret = imx_usbmisc_resume(data->usbmisc_data, in imx_controller_resume()
612 if (data->in_lpm) in ci_hdrc_imx_suspend()
631 if (!ret && data->supports_runtime_pm) { in ci_hdrc_imx_resume()
644 if (data->in_lpm) { in ci_hdrc_imx_runtime_suspend()
675 MODULE_ALIAS("platform:imx-usb");
677 MODULE_DESCRIPTION("CI HDRC i.MX USB binding");