Lines Matching +full:imx7d +full:- +full:usb

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},
112 /* --------------------------------- */
122 struct device_node *np = dev->of_node; in usbmisc_get_init_data()
136 return ERR_PTR(-ENOMEM); in usbmisc_get_init_data()
138 ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells", in usbmisc_get_init_data()
146 data->index = args.args[0]; in usbmisc_get_init_data()
152 return ERR_PTR(-EPROBE_DEFER); in usbmisc_get_init_data()
155 put_device(&misc_pdev->dev); in usbmisc_get_init_data()
156 return ERR_PTR(-EPROBE_DEFER); in usbmisc_get_init_data()
158 data->dev = &misc_pdev->dev; in usbmisc_get_init_data()
164 if (of_property_read_bool(np, "disable-over-current")) { in usbmisc_get_init_data()
165 data->disable_oc = 1; in usbmisc_get_init_data()
166 } else if (of_property_read_bool(np, "over-current-active-high")) { in usbmisc_get_init_data()
167 data->oc_pol_active_low = 0; in usbmisc_get_init_data()
168 data->oc_pol_configured = 1; in usbmisc_get_init_data()
169 } else if (of_property_read_bool(np, "over-current-active-low")) { in usbmisc_get_init_data()
170 data->oc_pol_active_low = 1; in usbmisc_get_init_data()
171 data->oc_pol_configured = 1; in usbmisc_get_init_data()
176 data->pwr_pol = of_property_read_bool(np, "power-active-high"); in usbmisc_get_init_data()
177 data->evdo = of_property_read_bool(np, "external-vbus-divider"); in usbmisc_get_init_data()
180 data->ulpi = 1; in usbmisc_get_init_data()
182 if (of_property_read_u32(np, "samsung,picophy-pre-emp-curr-control", in usbmisc_get_init_data()
183 &data->emp_curr_control)) in usbmisc_get_init_data()
184 data->emp_curr_control = -1; in usbmisc_get_init_data()
185 if (of_property_read_u32(np, "samsung,picophy-dc-vol-level-adjust", in usbmisc_get_init_data()
186 &data->dc_vol_level_adjust)) in usbmisc_get_init_data()
187 data->dc_vol_level_adjust = -1; in usbmisc_get_init_data()
188 if (of_property_read_u32(np, "fsl,picophy-rise-fall-time-adjust", in usbmisc_get_init_data()
189 &data->rise_fall_time_adjust)) in usbmisc_get_init_data()
190 data->rise_fall_time_adjust = -1; in usbmisc_get_init_data()
201 data->clk_ipg = devm_clk_get(dev, "ipg"); in imx_get_clks()
202 if (IS_ERR(data->clk_ipg)) { in imx_get_clks()
204 data->clk = devm_clk_get(dev, NULL); in imx_get_clks()
205 if (IS_ERR(data->clk)) { in imx_get_clks()
206 ret = PTR_ERR(data->clk); in imx_get_clks()
209 PTR_ERR(data->clk), PTR_ERR(data->clk_ipg)); in imx_get_clks()
215 data->clk_wakeup = devm_clk_get_optional(dev, "usb_wakeup"); in imx_get_clks()
216 if (IS_ERR(data->clk_wakeup)) in imx_get_clks()
217 ret = dev_err_probe(dev, PTR_ERR(data->clk_wakeup), in imx_get_clks()
222 data->clk_ahb = devm_clk_get(dev, "ahb"); in imx_get_clks()
223 if (IS_ERR(data->clk_ahb)) { in imx_get_clks()
224 ret = PTR_ERR(data->clk_ahb); in imx_get_clks()
230 data->clk_per = devm_clk_get(dev, "per"); in imx_get_clks()
231 if (IS_ERR(data->clk_per)) { in imx_get_clks()
232 ret = PTR_ERR(data->clk_per); in imx_get_clks()
238 data->need_three_clks = true; in imx_get_clks()
247 if (data->need_three_clks) { in imx_prepare_enable_clks()
248 ret = clk_prepare_enable(data->clk_ipg); in imx_prepare_enable_clks()
256 ret = clk_prepare_enable(data->clk_ahb); in imx_prepare_enable_clks()
261 clk_disable_unprepare(data->clk_ipg); in imx_prepare_enable_clks()
265 ret = clk_prepare_enable(data->clk_per); in imx_prepare_enable_clks()
270 clk_disable_unprepare(data->clk_ahb); in imx_prepare_enable_clks()
271 clk_disable_unprepare(data->clk_ipg); in imx_prepare_enable_clks()
275 ret = clk_prepare_enable(data->clk); in imx_prepare_enable_clks()
291 if (data->need_three_clks) { in imx_disable_unprepare_clks()
292 clk_disable_unprepare(data->clk_per); in imx_disable_unprepare_clks()
293 clk_disable_unprepare(data->clk_ahb); in imx_disable_unprepare_clks()
294 clk_disable_unprepare(data->clk_ipg); in imx_disable_unprepare_clks()
296 clk_disable_unprepare(data->clk); in imx_disable_unprepare_clks()
302 struct device *dev = ci->dev->parent; in ci_hdrc_imx_notify_event()
305 struct imx_usbmisc_data *mdata = data->usbmisc_data; in ci_hdrc_imx_notify_event()
309 if (data->pinctrl) { in ci_hdrc_imx_notify_event()
310 ret = pinctrl_select_state(data->pinctrl, in ci_hdrc_imx_notify_event()
311 data->pinctrl_hsic_active); in ci_hdrc_imx_notify_event()
325 if (ci->vbus_active) in ci_hdrc_imx_notify_event()
329 if (ci->usb_phy) in ci_hdrc_imx_notify_event()
330 schedule_work(&ci->usb_phy->chg_work); in ci_hdrc_imx_notify_event()
343 .name = dev_name(&pdev->dev), in ci_hdrc_imx_probe()
349 struct device_node *np = pdev->dev.of_node; in ci_hdrc_imx_probe()
350 struct device *dev = &pdev->dev; in ci_hdrc_imx_probe()
352 imx_platform_flag = of_device_get_match_data(&pdev->dev); in ci_hdrc_imx_probe()
354 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in ci_hdrc_imx_probe()
356 return -ENOMEM; in ci_hdrc_imx_probe()
358 data->plat_data = imx_platform_flag; in ci_hdrc_imx_probe()
359 pdata.flags |= imx_platform_flag->flags; in ci_hdrc_imx_probe()
361 data->usbmisc_data = usbmisc_get_init_data(dev); in ci_hdrc_imx_probe()
362 if (IS_ERR(data->usbmisc_data)) in ci_hdrc_imx_probe()
363 return PTR_ERR(data->usbmisc_data); in ci_hdrc_imx_probe()
365 if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) in ci_hdrc_imx_probe()
366 && data->usbmisc_data) { in ci_hdrc_imx_probe()
368 data->usbmisc_data->hsic = 1; in ci_hdrc_imx_probe()
369 data->pinctrl = devm_pinctrl_get(dev); in ci_hdrc_imx_probe()
370 if (PTR_ERR(data->pinctrl) == -ENODEV) in ci_hdrc_imx_probe()
371 data->pinctrl = NULL; in ci_hdrc_imx_probe()
372 else if (IS_ERR(data->pinctrl)) in ci_hdrc_imx_probe()
373 return dev_err_probe(dev, PTR_ERR(data->pinctrl), in ci_hdrc_imx_probe()
376 data->hsic_pad_regulator = in ci_hdrc_imx_probe()
378 if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) { in ci_hdrc_imx_probe()
380 data->hsic_pad_regulator = NULL; in ci_hdrc_imx_probe()
381 } else if (IS_ERR(data->hsic_pad_regulator)) in ci_hdrc_imx_probe()
382 return dev_err_probe(dev, PTR_ERR(data->hsic_pad_regulator), in ci_hdrc_imx_probe()
385 if (data->hsic_pad_regulator) { in ci_hdrc_imx_probe()
386 ret = regulator_enable(data->hsic_pad_regulator); in ci_hdrc_imx_probe()
396 if (data->pinctrl) { in ci_hdrc_imx_probe()
399 pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle"); in ci_hdrc_imx_probe()
407 ret = pinctrl_select_state(data->pinctrl, pinctrl_hsic_idle); in ci_hdrc_imx_probe()
413 data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl, in ci_hdrc_imx_probe()
415 if (IS_ERR(data->pinctrl_hsic_active)) { in ci_hdrc_imx_probe()
418 PTR_ERR(data->pinctrl_hsic_active)); in ci_hdrc_imx_probe()
419 return PTR_ERR(data->pinctrl_hsic_active); in ci_hdrc_imx_probe()
424 cpu_latency_qos_add_request(&data->pm_qos_req, 0); in ci_hdrc_imx_probe()
434 ret = clk_prepare_enable(data->clk_wakeup); in ci_hdrc_imx_probe()
438 data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0); in ci_hdrc_imx_probe()
439 if (IS_ERR(data->phy)) { in ci_hdrc_imx_probe()
440 ret = PTR_ERR(data->phy); in ci_hdrc_imx_probe()
441 if (ret != -ENODEV) { in ci_hdrc_imx_probe()
445 data->phy = devm_usb_get_phy_by_phandle(dev, "phys", 0); in ci_hdrc_imx_probe()
446 if (IS_ERR(data->phy)) { in ci_hdrc_imx_probe()
447 ret = PTR_ERR(data->phy); in ci_hdrc_imx_probe()
448 if (ret == -ENODEV) { in ci_hdrc_imx_probe()
449 data->phy = NULL; in ci_hdrc_imx_probe()
457 pdata.usb_phy = data->phy; in ci_hdrc_imx_probe()
458 if (data->usbmisc_data) in ci_hdrc_imx_probe()
459 data->usbmisc_data->usb_phy = data->phy; in ci_hdrc_imx_probe()
461 if ((of_device_is_compatible(np, "fsl,imx53-usb") || in ci_hdrc_imx_probe()
462 of_device_is_compatible(np, "fsl,imx51-usb")) && pdata.usb_phy && in ci_hdrc_imx_probe()
465 data->override_phy_control = true; in ci_hdrc_imx_probe()
470 data->supports_runtime_pm = true; in ci_hdrc_imx_probe()
472 ret = imx_usbmisc_init(data->usbmisc_data); in ci_hdrc_imx_probe()
478 data->ci_pdev = ci_hdrc_add_device(dev, in ci_hdrc_imx_probe()
479 pdev->resource, pdev->num_resources, in ci_hdrc_imx_probe()
481 if (IS_ERR(data->ci_pdev)) { in ci_hdrc_imx_probe()
482 ret = PTR_ERR(data->ci_pdev); in ci_hdrc_imx_probe()
487 if (data->usbmisc_data) { in ci_hdrc_imx_probe()
489 of_property_read_bool(np, "usb-role-switch")) in ci_hdrc_imx_probe()
490 data->usbmisc_data->ext_id = 1; in ci_hdrc_imx_probe()
493 of_property_read_bool(np, "usb-role-switch")) in ci_hdrc_imx_probe()
494 data->usbmisc_data->ext_vbus = 1; in ci_hdrc_imx_probe()
497 data->usbmisc_data->available_role = in ci_hdrc_imx_probe()
498 ci_hdrc_query_available_role(data->ci_pdev); in ci_hdrc_imx_probe()
501 ret = imx_usbmisc_init_post(data->usbmisc_data); in ci_hdrc_imx_probe()
507 if (data->supports_runtime_pm) { in ci_hdrc_imx_probe()
517 ci_hdrc_remove_device(data->ci_pdev); in ci_hdrc_imx_probe()
519 clk_disable_unprepare(data->clk_wakeup); in ci_hdrc_imx_probe()
523 if (data->hsic_pad_regulator) in ci_hdrc_imx_probe()
525 regulator_disable(data->hsic_pad_regulator); in ci_hdrc_imx_probe()
527 cpu_latency_qos_remove_request(&data->pm_qos_req); in ci_hdrc_imx_probe()
528 data->ci_pdev = NULL; in ci_hdrc_imx_probe()
536 if (data->supports_runtime_pm) { in ci_hdrc_imx_remove()
537 pm_runtime_get_sync(&pdev->dev); in ci_hdrc_imx_remove()
538 pm_runtime_disable(&pdev->dev); in ci_hdrc_imx_remove()
539 pm_runtime_put_noidle(&pdev->dev); in ci_hdrc_imx_remove()
541 if (data->ci_pdev) in ci_hdrc_imx_remove()
542 ci_hdrc_remove_device(data->ci_pdev); in ci_hdrc_imx_remove()
543 if (data->override_phy_control) in ci_hdrc_imx_remove()
544 usb_phy_shutdown(data->phy); in ci_hdrc_imx_remove()
545 if (data->ci_pdev) { in ci_hdrc_imx_remove()
546 imx_disable_unprepare_clks(&pdev->dev); in ci_hdrc_imx_remove()
547 clk_disable_unprepare(data->clk_wakeup); in ci_hdrc_imx_remove()
548 if (data->plat_data->flags & CI_HDRC_PMQOS) in ci_hdrc_imx_remove()
549 cpu_latency_qos_remove_request(&data->pm_qos_req); in ci_hdrc_imx_remove()
550 if (data->hsic_pad_regulator) in ci_hdrc_imx_remove()
551 regulator_disable(data->hsic_pad_regulator); in ci_hdrc_imx_remove()
568 ret = imx_usbmisc_suspend(data->usbmisc_data, in imx_controller_suspend()
577 if (data->plat_data->flags & CI_HDRC_PMQOS) in imx_controller_suspend()
578 cpu_latency_qos_remove_request(&data->pm_qos_req); in imx_controller_suspend()
580 data->in_lpm = true; in imx_controller_suspend()
593 if (!data->in_lpm) { in imx_controller_resume()
598 if (data->plat_data->flags & CI_HDRC_PMQOS) in imx_controller_resume()
599 cpu_latency_qos_add_request(&data->pm_qos_req, 0); in imx_controller_resume()
605 data->in_lpm = false; in imx_controller_resume()
607 ret = imx_usbmisc_resume(data->usbmisc_data, in imx_controller_resume()
627 if (data->in_lpm) in ci_hdrc_imx_suspend()
646 if (!ret && data->supports_runtime_pm) { in ci_hdrc_imx_resume()
659 if (data->in_lpm) { in ci_hdrc_imx_runtime_suspend()
689 MODULE_ALIAS("platform:imx-usb");
691 MODULE_DESCRIPTION("CI HDRC i.MX USB binding");