Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 4 | * Copyright (C) 2012 Marek Vasut <marex@denx.de> |
| 5 | * on behalf of DENX Software Engineering GmbH |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/of_platform.h> |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 10 | #include <linux/platform_device.h> |
| 11 | #include <linux/pm_runtime.h> |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 12 | #include <linux/usb/chipidea.h> |
Fabien Lahoudere | d13631b | 2016-09-26 13:14:19 +0200 | [diff] [blame] | 13 | #include <linux/usb/of.h> |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 14 | #include <linux/clk.h> |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 15 | #include <linux/pinctrl/consumer.h> |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 16 | #include <linux/pm_qos.h> |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 17 | |
| 18 | #include "ci.h" |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 19 | #include "ci_hdrc_imx.h" |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 20 | |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 21 | struct ci_hdrc_imx_platform_flag { |
| 22 | unsigned int flags; |
| 23 | }; |
| 24 | |
Stefan Wahren | 8134572 | 2015-12-29 16:41:08 +0000 | [diff] [blame] | 25 | static const struct ci_hdrc_imx_platform_flag imx23_usb_data = { |
| 26 | .flags = CI_HDRC_TURN_VBUS_EARLY_ON | |
| 27 | CI_HDRC_DISABLE_STREAMING, |
| 28 | }; |
| 29 | |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 30 | static const struct ci_hdrc_imx_platform_flag imx27_usb_data = { |
Sebastian Reichel | 04e1637 | 2018-03-29 17:52:48 +0800 | [diff] [blame] | 31 | .flags = CI_HDRC_DISABLE_STREAMING, |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | static const struct ci_hdrc_imx_platform_flag imx28_usb_data = { |
Li Jun | 6adb9b7b | 2015-02-11 12:45:01 +0800 | [diff] [blame] | 35 | .flags = CI_HDRC_IMX28_WRITE_FIX | |
Peter Chen | 0ef877a | 2014-10-30 11:10:04 +0800 | [diff] [blame] | 36 | CI_HDRC_TURN_VBUS_EARLY_ON | |
| 37 | CI_HDRC_DISABLE_STREAMING, |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 38 | }; |
| 39 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 40 | static const struct ci_hdrc_imx_platform_flag imx6q_usb_data = { |
Li Jun | 6adb9b7b | 2015-02-11 12:45:01 +0800 | [diff] [blame] | 41 | .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | |
Peter Chen | 0ef877a | 2014-10-30 11:10:04 +0800 | [diff] [blame] | 42 | CI_HDRC_TURN_VBUS_EARLY_ON | |
| 43 | CI_HDRC_DISABLE_STREAMING, |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | static const struct ci_hdrc_imx_platform_flag imx6sl_usb_data = { |
Li Jun | 6adb9b7b | 2015-02-11 12:45:01 +0800 | [diff] [blame] | 47 | .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | |
Peter Chen | 0ef877a | 2014-10-30 11:10:04 +0800 | [diff] [blame] | 48 | CI_HDRC_TURN_VBUS_EARLY_ON | |
| 49 | CI_HDRC_DISABLE_HOST_STREAMING, |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | static const struct ci_hdrc_imx_platform_flag imx6sx_usb_data = { |
Li Jun | 6adb9b7b | 2015-02-11 12:45:01 +0800 | [diff] [blame] | 53 | .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | |
Peter Chen | 0ef877a | 2014-10-30 11:10:04 +0800 | [diff] [blame] | 54 | CI_HDRC_TURN_VBUS_EARLY_ON | |
| 55 | CI_HDRC_DISABLE_HOST_STREAMING, |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 56 | }; |
| 57 | |
Peter Chen | 52fe568 | 2015-09-16 15:52:32 +0800 | [diff] [blame] | 58 | static const struct ci_hdrc_imx_platform_flag imx6ul_usb_data = { |
| 59 | .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | |
| 60 | CI_HDRC_TURN_VBUS_EARLY_ON, |
| 61 | }; |
| 62 | |
Peter Chen | 5cb377c | 2015-09-09 16:33:02 +0800 | [diff] [blame] | 63 | static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = { |
| 64 | .flags = CI_HDRC_SUPPORTS_RUNTIME_PM, |
| 65 | }; |
| 66 | |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 67 | static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = { |
| 68 | .flags = CI_HDRC_SUPPORTS_RUNTIME_PM | |
| 69 | CI_HDRC_PMQOS, |
| 70 | }; |
| 71 | |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 72 | static const struct of_device_id ci_hdrc_imx_dt_ids[] = { |
Stefan Wahren | 8134572 | 2015-12-29 16:41:08 +0000 | [diff] [blame] | 73 | { .compatible = "fsl,imx23-usb", .data = &imx23_usb_data}, |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 74 | { .compatible = "fsl,imx28-usb", .data = &imx28_usb_data}, |
| 75 | { .compatible = "fsl,imx27-usb", .data = &imx27_usb_data}, |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 76 | { .compatible = "fsl,imx6q-usb", .data = &imx6q_usb_data}, |
| 77 | { .compatible = "fsl,imx6sl-usb", .data = &imx6sl_usb_data}, |
Li Jun | 8315b77 | 2015-09-16 14:46:32 +0800 | [diff] [blame] | 78 | { .compatible = "fsl,imx6sx-usb", .data = &imx6sx_usb_data}, |
Peter Chen | 52fe568 | 2015-09-16 15:52:32 +0800 | [diff] [blame] | 79 | { .compatible = "fsl,imx6ul-usb", .data = &imx6ul_usb_data}, |
Peter Chen | 5cb377c | 2015-09-09 16:33:02 +0800 | [diff] [blame] | 80 | { .compatible = "fsl,imx7d-usb", .data = &imx7d_usb_data}, |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 81 | { .compatible = "fsl,imx7ulp-usb", .data = &imx7ulp_usb_data}, |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 82 | { /* sentinel */ } |
| 83 | }; |
| 84 | MODULE_DEVICE_TABLE(of, ci_hdrc_imx_dt_ids); |
| 85 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 86 | struct ci_hdrc_imx_data { |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 87 | struct usb_phy *phy; |
| 88 | struct platform_device *ci_pdev; |
| 89 | struct clk *clk; |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 90 | struct imx_usbmisc_data *usbmisc_data; |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 91 | bool supports_runtime_pm; |
Sebastian Reichel | be9cae2 | 2018-03-29 17:52:49 +0800 | [diff] [blame] | 92 | bool override_phy_control; |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 93 | bool in_lpm; |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 94 | struct pinctrl *pinctrl; |
| 95 | struct pinctrl_state *pinctrl_hsic_active; |
| 96 | struct regulator *hsic_pad_regulator; |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 97 | /* SoC before i.mx6 (except imx23/imx28) needs three clks */ |
| 98 | bool need_three_clks; |
| 99 | struct clk *clk_ipg; |
| 100 | struct clk *clk_ahb; |
| 101 | struct clk *clk_per; |
| 102 | /* --------------------------------- */ |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 103 | struct pm_qos_request pm_qos_req; |
| 104 | const struct ci_hdrc_imx_platform_flag *plat_data; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 105 | }; |
| 106 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 107 | /* Common functions shared by usbmisc drivers */ |
| 108 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 109 | static struct imx_usbmisc_data *usbmisc_get_init_data(struct device *dev) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 110 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 111 | struct platform_device *misc_pdev; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 112 | struct device_node *np = dev->of_node; |
| 113 | struct of_phandle_args args; |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 114 | struct imx_usbmisc_data *data; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 115 | int ret; |
| 116 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 117 | /* |
| 118 | * In case the fsl,usbmisc property is not present this device doesn't |
| 119 | * need usbmisc. Return NULL (which is no error here) |
| 120 | */ |
| 121 | if (!of_get_property(np, "fsl,usbmisc", NULL)) |
| 122 | return NULL; |
| 123 | |
| 124 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
| 125 | if (!data) |
| 126 | return ERR_PTR(-ENOMEM); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 127 | |
| 128 | ret = of_parse_phandle_with_args(np, "fsl,usbmisc", "#index-cells", |
| 129 | 0, &args); |
| 130 | if (ret) { |
| 131 | dev_err(dev, "Failed to parse property fsl,usbmisc, errno %d\n", |
| 132 | ret); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 133 | return ERR_PTR(ret); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 134 | } |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 135 | |
| 136 | data->index = args.args[0]; |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 137 | |
| 138 | misc_pdev = of_find_device_by_node(args.np); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 139 | of_node_put(args.np); |
| 140 | |
Tomeu Vizoso | ef12da9 | 2015-08-06 15:09:54 +0200 | [diff] [blame] | 141 | if (!misc_pdev || !platform_get_drvdata(misc_pdev)) |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 142 | return ERR_PTR(-EPROBE_DEFER); |
| 143 | |
| 144 | data->dev = &misc_pdev->dev; |
| 145 | |
Uwe Kleine-König | a82bf69 | 2018-12-04 09:31:29 +0100 | [diff] [blame] | 146 | /* |
| 147 | * Check the various over current related properties. If over current |
| 148 | * detection is disabled we're not interested in the polarity. |
| 149 | */ |
| 150 | if (of_find_property(np, "disable-over-current", NULL)) { |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 151 | data->disable_oc = 1; |
Uwe Kleine-König | a82bf69 | 2018-12-04 09:31:29 +0100 | [diff] [blame] | 152 | } else if (of_find_property(np, "over-current-active-high", NULL)) { |
| 153 | data->oc_pol_active_low = 0; |
| 154 | data->oc_pol_configured = 1; |
| 155 | } else if (of_find_property(np, "over-current-active-low", NULL)) { |
| 156 | data->oc_pol_active_low = 1; |
| 157 | data->oc_pol_configured = 1; |
Uwe Kleine-König | 1bf4743 | 2018-12-04 09:31:30 +0100 | [diff] [blame] | 158 | } else { |
| 159 | dev_warn(dev, "No over current polarity defined\n"); |
Uwe Kleine-König | a82bf69 | 2018-12-04 09:31:29 +0100 | [diff] [blame] | 160 | } |
Li Jun | 9dba516 | 2016-07-20 16:02:42 +0800 | [diff] [blame] | 161 | |
Philipp Puschmann | 5f0632c | 2019-02-27 06:51:34 +0000 | [diff] [blame] | 162 | data->pwr_pol = of_property_read_bool(np, "power-active-high"); |
| 163 | data->evdo = of_property_read_bool(np, "external-vbus-divider"); |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 164 | |
Fabien Lahoudere | d13631b | 2016-09-26 13:14:19 +0200 | [diff] [blame] | 165 | if (of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI) |
| 166 | data->ulpi = 1; |
| 167 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 168 | return data; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 169 | } |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 170 | |
| 171 | /* End of common functions shared by usbmisc drivers*/ |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 172 | static int imx_get_clks(struct device *dev) |
| 173 | { |
| 174 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 175 | int ret = 0; |
| 176 | |
| 177 | data->clk_ipg = devm_clk_get(dev, "ipg"); |
| 178 | if (IS_ERR(data->clk_ipg)) { |
| 179 | /* If the platform only needs one clocks */ |
| 180 | data->clk = devm_clk_get(dev, NULL); |
| 181 | if (IS_ERR(data->clk)) { |
| 182 | ret = PTR_ERR(data->clk); |
| 183 | dev_err(dev, |
| 184 | "Failed to get clks, err=%ld,%ld\n", |
| 185 | PTR_ERR(data->clk), PTR_ERR(data->clk_ipg)); |
| 186 | return ret; |
| 187 | } |
| 188 | return ret; |
| 189 | } |
| 190 | |
| 191 | data->clk_ahb = devm_clk_get(dev, "ahb"); |
| 192 | if (IS_ERR(data->clk_ahb)) { |
| 193 | ret = PTR_ERR(data->clk_ahb); |
| 194 | dev_err(dev, |
| 195 | "Failed to get ahb clock, err=%d\n", ret); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | data->clk_per = devm_clk_get(dev, "per"); |
| 200 | if (IS_ERR(data->clk_per)) { |
| 201 | ret = PTR_ERR(data->clk_per); |
| 202 | dev_err(dev, |
| 203 | "Failed to get per clock, err=%d\n", ret); |
| 204 | return ret; |
| 205 | } |
| 206 | |
| 207 | data->need_three_clks = true; |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | static int imx_prepare_enable_clks(struct device *dev) |
| 212 | { |
| 213 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 214 | int ret = 0; |
| 215 | |
| 216 | if (data->need_three_clks) { |
| 217 | ret = clk_prepare_enable(data->clk_ipg); |
| 218 | if (ret) { |
| 219 | dev_err(dev, |
| 220 | "Failed to prepare/enable ipg clk, err=%d\n", |
| 221 | ret); |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | ret = clk_prepare_enable(data->clk_ahb); |
| 226 | if (ret) { |
| 227 | dev_err(dev, |
| 228 | "Failed to prepare/enable ahb clk, err=%d\n", |
| 229 | ret); |
| 230 | clk_disable_unprepare(data->clk_ipg); |
| 231 | return ret; |
| 232 | } |
| 233 | |
| 234 | ret = clk_prepare_enable(data->clk_per); |
| 235 | if (ret) { |
| 236 | dev_err(dev, |
| 237 | "Failed to prepare/enable per clk, err=%d\n", |
| 238 | ret); |
| 239 | clk_disable_unprepare(data->clk_ahb); |
| 240 | clk_disable_unprepare(data->clk_ipg); |
| 241 | return ret; |
| 242 | } |
| 243 | } else { |
| 244 | ret = clk_prepare_enable(data->clk); |
| 245 | if (ret) { |
| 246 | dev_err(dev, |
| 247 | "Failed to prepare/enable clk, err=%d\n", |
| 248 | ret); |
| 249 | return ret; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | static void imx_disable_unprepare_clks(struct device *dev) |
| 257 | { |
| 258 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 259 | |
| 260 | if (data->need_three_clks) { |
| 261 | clk_disable_unprepare(data->clk_per); |
| 262 | clk_disable_unprepare(data->clk_ahb); |
| 263 | clk_disable_unprepare(data->clk_ipg); |
| 264 | } else { |
| 265 | clk_disable_unprepare(data->clk); |
| 266 | } |
| 267 | } |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 268 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 269 | static int ci_hdrc_imx_notify_event(struct ci_hdrc *ci, unsigned int event) |
| 270 | { |
| 271 | struct device *dev = ci->dev->parent; |
| 272 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 273 | int ret = 0; |
Jun Li | 746f316 | 2020-01-23 14:35:58 +0800 | [diff] [blame] | 274 | struct imx_usbmisc_data *mdata = data->usbmisc_data; |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 275 | |
| 276 | switch (event) { |
| 277 | case CI_HDRC_IMX_HSIC_ACTIVE_EVENT: |
Peter Chen | 4d61412 | 2019-10-10 09:20:26 +0800 | [diff] [blame] | 278 | if (data->pinctrl) { |
| 279 | ret = pinctrl_select_state(data->pinctrl, |
| 280 | data->pinctrl_hsic_active); |
| 281 | if (ret) |
| 282 | dev_err(dev, |
| 283 | "hsic_active select failed, err=%d\n", |
| 284 | ret); |
| 285 | } |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 286 | break; |
| 287 | case CI_HDRC_IMX_HSIC_SUSPEND_EVENT: |
Jun Li | 746f316 | 2020-01-23 14:35:58 +0800 | [diff] [blame] | 288 | ret = imx_usbmisc_hsic_set_connect(mdata); |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 289 | if (ret) |
| 290 | dev_err(dev, |
| 291 | "hsic_set_connect failed, err=%d\n", ret); |
| 292 | break; |
Jun Li | 746f316 | 2020-01-23 14:35:58 +0800 | [diff] [blame] | 293 | case CI_HDRC_CONTROLLER_VBUS_EVENT: |
| 294 | if (ci->vbus_active) |
| 295 | ret = imx_usbmisc_charger_detection(mdata, true); |
| 296 | else |
| 297 | ret = imx_usbmisc_charger_detection(mdata, false); |
| 298 | if (ci->usb_phy) |
| 299 | schedule_work(&ci->usb_phy->chg_work); |
| 300 | break; |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 301 | default: |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | return ret; |
| 306 | } |
| 307 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 308 | static int ci_hdrc_imx_probe(struct platform_device *pdev) |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 309 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 310 | struct ci_hdrc_imx_data *data; |
| 311 | struct ci_hdrc_platform_data pdata = { |
Alexander Shiyan | c844d6c | 2014-03-11 13:47:38 +0800 | [diff] [blame] | 312 | .name = dev_name(&pdev->dev), |
Michael Grzeschik | f6a3b3a | 2013-06-13 17:59:58 +0300 | [diff] [blame] | 313 | .capoffset = DEF_CAPOFFSET, |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 314 | .notify_event = ci_hdrc_imx_notify_event, |
Michael Grzeschik | f6a3b3a | 2013-06-13 17:59:58 +0300 | [diff] [blame] | 315 | }; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 316 | int ret; |
LABBE Corentin | 6f51bc3 | 2015-11-12 08:43:34 +0100 | [diff] [blame] | 317 | const struct of_device_id *of_id; |
| 318 | const struct ci_hdrc_imx_platform_flag *imx_platform_flag; |
Sebastian Reichel | be9cae2 | 2018-03-29 17:52:49 +0800 | [diff] [blame] | 319 | struct device_node *np = pdev->dev.of_node; |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 320 | struct device *dev = &pdev->dev; |
LABBE Corentin | 6f51bc3 | 2015-11-12 08:43:34 +0100 | [diff] [blame] | 321 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 322 | of_id = of_match_device(ci_hdrc_imx_dt_ids, dev); |
LABBE Corentin | 6f51bc3 | 2015-11-12 08:43:34 +0100 | [diff] [blame] | 323 | if (!of_id) |
| 324 | return -ENODEV; |
| 325 | |
| 326 | imx_platform_flag = of_id->data; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 327 | |
| 328 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
Fabio Estevam | 73529828 | 2014-11-26 13:44:24 +0800 | [diff] [blame] | 329 | if (!data) |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 330 | return -ENOMEM; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 331 | |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 332 | data->plat_data = imx_platform_flag; |
| 333 | pdata.flags |= imx_platform_flag->flags; |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 334 | platform_set_drvdata(pdev, data); |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 335 | data->usbmisc_data = usbmisc_get_init_data(dev); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 336 | if (IS_ERR(data->usbmisc_data)) |
| 337 | return PTR_ERR(data->usbmisc_data); |
| 338 | |
Peter Chen | 8ff396f | 2019-01-17 09:24:20 +0000 | [diff] [blame] | 339 | if ((of_usb_get_phy_mode(dev->of_node) == USBPHY_INTERFACE_MODE_HSIC) |
| 340 | && data->usbmisc_data) { |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 341 | pdata.flags |= CI_HDRC_IMX_IS_HSIC; |
| 342 | data->usbmisc_data->hsic = 1; |
| 343 | data->pinctrl = devm_pinctrl_get(dev); |
Peter Chen | 3f4aad6 | 2019-10-10 08:59:14 +0800 | [diff] [blame] | 344 | if (PTR_ERR(data->pinctrl) == -ENODEV) |
| 345 | data->pinctrl = NULL; |
| 346 | else if (IS_ERR(data->pinctrl)) { |
| 347 | if (PTR_ERR(data->pinctrl) != -EPROBE_DEFER) |
| 348 | dev_err(dev, "pinctrl get failed, err=%ld\n", |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 349 | PTR_ERR(data->pinctrl)); |
| 350 | return PTR_ERR(data->pinctrl); |
| 351 | } |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 352 | |
Peter Chen | 4d61412 | 2019-10-10 09:20:26 +0800 | [diff] [blame] | 353 | data->hsic_pad_regulator = |
| 354 | devm_regulator_get_optional(dev, "hsic"); |
| 355 | if (PTR_ERR(data->hsic_pad_regulator) == -ENODEV) { |
| 356 | /* no pad regualator is needed */ |
| 357 | data->hsic_pad_regulator = NULL; |
| 358 | } else if (IS_ERR(data->hsic_pad_regulator)) { |
| 359 | if (PTR_ERR(data->hsic_pad_regulator) != -EPROBE_DEFER) |
| 360 | dev_err(dev, |
| 361 | "Get HSIC pad regulator error: %ld\n", |
| 362 | PTR_ERR(data->hsic_pad_regulator)); |
| 363 | return PTR_ERR(data->hsic_pad_regulator); |
| 364 | } |
| 365 | |
| 366 | if (data->hsic_pad_regulator) { |
| 367 | ret = regulator_enable(data->hsic_pad_regulator); |
| 368 | if (ret) { |
| 369 | dev_err(dev, |
| 370 | "Failed to enable HSIC pad regulator\n"); |
| 371 | return ret; |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /* HSIC pinctrl handling */ |
| 377 | if (data->pinctrl) { |
| 378 | struct pinctrl_state *pinctrl_hsic_idle; |
| 379 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 380 | pinctrl_hsic_idle = pinctrl_lookup_state(data->pinctrl, "idle"); |
| 381 | if (IS_ERR(pinctrl_hsic_idle)) { |
| 382 | dev_err(dev, |
| 383 | "pinctrl_hsic_idle lookup failed, err=%ld\n", |
| 384 | PTR_ERR(pinctrl_hsic_idle)); |
| 385 | return PTR_ERR(pinctrl_hsic_idle); |
| 386 | } |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 387 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 388 | ret = pinctrl_select_state(data->pinctrl, pinctrl_hsic_idle); |
| 389 | if (ret) { |
| 390 | dev_err(dev, "hsic_idle select failed, err=%d\n", ret); |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | data->pinctrl_hsic_active = pinctrl_lookup_state(data->pinctrl, |
| 395 | "active"); |
| 396 | if (IS_ERR(data->pinctrl_hsic_active)) { |
| 397 | dev_err(dev, |
| 398 | "pinctrl_hsic_active lookup failed, err=%ld\n", |
| 399 | PTR_ERR(data->pinctrl_hsic_active)); |
| 400 | return PTR_ERR(data->pinctrl_hsic_active); |
| 401 | } |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 402 | } |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 403 | |
| 404 | if (pdata.flags & CI_HDRC_PMQOS) |
Rafael J. Wysocki | 77b3524 | 2020-02-12 00:28:44 +0100 | [diff] [blame] | 405 | cpu_latency_qos_add_request(&data->pm_qos_req, 0); |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 406 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 407 | ret = imx_get_clks(dev); |
| 408 | if (ret) |
| 409 | goto disable_hsic_regulator; |
| 410 | |
| 411 | ret = imx_prepare_enable_clks(dev); |
| 412 | if (ret) |
| 413 | goto disable_hsic_regulator; |
| 414 | |
| 415 | data->phy = devm_usb_get_phy_by_phandle(dev, "fsl,usbphy", 0); |
Peter Chen | af59a8b | 2013-09-24 12:47:54 +0800 | [diff] [blame] | 416 | if (IS_ERR(data->phy)) { |
| 417 | ret = PTR_ERR(data->phy); |
Markus Pargmann | 16853d7 | 2014-07-22 10:09:43 +0800 | [diff] [blame] | 418 | /* Return -EINVAL if no usbphy is available */ |
| 419 | if (ret == -ENODEV) |
Peter Chen | ed5a419 | 2019-05-07 09:53:55 +0800 | [diff] [blame] | 420 | data->phy = NULL; |
| 421 | else |
| 422 | goto err_clk; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 423 | } |
| 424 | |
Antoine Tenart | ef44cb4 | 2014-10-30 18:41:16 +0100 | [diff] [blame] | 425 | pdata.usb_phy = data->phy; |
Jun Li | 746f316 | 2020-01-23 14:35:58 +0800 | [diff] [blame] | 426 | if (data->usbmisc_data) |
| 427 | data->usbmisc_data->usb_phy = data->phy; |
Sebastian Reichel | be9cae2 | 2018-03-29 17:52:49 +0800 | [diff] [blame] | 428 | |
Andrey Smirnov | 03e6275 | 2018-05-30 10:34:14 -0700 | [diff] [blame] | 429 | if ((of_device_is_compatible(np, "fsl,imx53-usb") || |
| 430 | of_device_is_compatible(np, "fsl,imx51-usb")) && pdata.usb_phy && |
Sebastian Reichel | be9cae2 | 2018-03-29 17:52:49 +0800 | [diff] [blame] | 431 | of_usb_get_phy_mode(np) == USBPHY_INTERFACE_MODE_ULPI) { |
| 432 | pdata.flags |= CI_HDRC_OVERRIDE_PHY_CONTROL; |
| 433 | data->override_phy_control = true; |
| 434 | usb_phy_init(pdata.usb_phy); |
| 435 | } |
| 436 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 437 | if (pdata.flags & CI_HDRC_SUPPORTS_RUNTIME_PM) |
| 438 | data->supports_runtime_pm = true; |
Peter Chen | 1071055 | 2014-01-10 13:51:28 +0800 | [diff] [blame] | 439 | |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 440 | ret = imx_usbmisc_init(data->usbmisc_data); |
| 441 | if (ret) { |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 442 | dev_err(dev, "usbmisc init failed, ret=%d\n", ret); |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 443 | goto err_clk; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 444 | } |
| 445 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 446 | data->ci_pdev = ci_hdrc_add_device(dev, |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 447 | pdev->resource, pdev->num_resources, |
Michael Grzeschik | f6a3b3a | 2013-06-13 17:59:58 +0300 | [diff] [blame] | 448 | &pdata); |
Fabio Estevam | 770719d | 2013-06-13 17:59:48 +0300 | [diff] [blame] | 449 | if (IS_ERR(data->ci_pdev)) { |
| 450 | ret = PTR_ERR(data->ci_pdev); |
Stefan Agner | d3d8425 | 2016-01-27 16:55:45 -0800 | [diff] [blame] | 451 | if (ret != -EPROBE_DEFER) |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 452 | dev_err(dev, "ci_hdrc_add_device failed, err=%d\n", |
| 453 | ret); |
Peter Chen | af59a8b | 2013-09-24 12:47:54 +0800 | [diff] [blame] | 454 | goto err_clk; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 455 | } |
| 456 | |
Li Jun | df17aa9 | 2019-10-09 10:52:28 +0800 | [diff] [blame] | 457 | if (data->usbmisc_data) { |
| 458 | if (!IS_ERR(pdata.id_extcon.edev) || |
| 459 | of_property_read_bool(np, "usb-role-switch")) |
| 460 | data->usbmisc_data->ext_id = 1; |
Li Jun | 93c2c73 | 2019-09-09 14:41:41 +0800 | [diff] [blame] | 461 | |
Li Jun | df17aa9 | 2019-10-09 10:52:28 +0800 | [diff] [blame] | 462 | if (!IS_ERR(pdata.vbus_extcon.edev) || |
| 463 | of_property_read_bool(np, "usb-role-switch")) |
| 464 | data->usbmisc_data->ext_vbus = 1; |
Peter Chen | d6f93d2 | 2020-07-28 14:12:11 +0800 | [diff] [blame^] | 465 | |
| 466 | /* usbmisc needs to know dr mode to choose wakeup setting */ |
| 467 | data->usbmisc_data->available_role = |
| 468 | ci_hdrc_query_available_role(data->ci_pdev); |
Li Jun | df17aa9 | 2019-10-09 10:52:28 +0800 | [diff] [blame] | 469 | } |
Li Jun | 93c2c73 | 2019-09-09 14:41:41 +0800 | [diff] [blame] | 470 | |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 471 | ret = imx_usbmisc_init_post(data->usbmisc_data); |
| 472 | if (ret) { |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 473 | dev_err(dev, "usbmisc post failed, ret=%d\n", ret); |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 474 | goto disable_device; |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 475 | } |
| 476 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 477 | if (data->supports_runtime_pm) { |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 478 | pm_runtime_set_active(dev); |
| 479 | pm_runtime_enable(dev); |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 480 | } |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 481 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 482 | device_set_wakeup_capable(dev, true); |
Peter Chen | 6d65311 | 2015-02-11 12:44:49 +0800 | [diff] [blame] | 483 | |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 484 | return 0; |
| 485 | |
Fabio Estevam | 770719d | 2013-06-13 17:59:48 +0300 | [diff] [blame] | 486 | disable_device: |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 487 | ci_hdrc_remove_device(data->ci_pdev); |
Sascha Hauer | ea1418b | 2013-06-13 18:00:00 +0300 | [diff] [blame] | 488 | err_clk: |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 489 | imx_disable_unprepare_clks(dev); |
| 490 | disable_hsic_regulator: |
| 491 | if (data->hsic_pad_regulator) |
André Draszik | 141822a | 2019-08-10 16:07:58 +0100 | [diff] [blame] | 492 | /* don't overwrite original ret (cf. EPROBE_DEFER) */ |
| 493 | regulator_disable(data->hsic_pad_regulator); |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 494 | if (pdata.flags & CI_HDRC_PMQOS) |
Rafael J. Wysocki | 77b3524 | 2020-02-12 00:28:44 +0100 | [diff] [blame] | 495 | cpu_latency_qos_remove_request(&data->pm_qos_req); |
André Draszik | 141822a | 2019-08-10 16:07:58 +0100 | [diff] [blame] | 496 | data->ci_pdev = NULL; |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 497 | return ret; |
| 498 | } |
| 499 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 500 | static int ci_hdrc_imx_remove(struct platform_device *pdev) |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 501 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 502 | struct ci_hdrc_imx_data *data = platform_get_drvdata(pdev); |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 503 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 504 | if (data->supports_runtime_pm) { |
| 505 | pm_runtime_get_sync(&pdev->dev); |
| 506 | pm_runtime_disable(&pdev->dev); |
| 507 | pm_runtime_put_noidle(&pdev->dev); |
| 508 | } |
André Draszik | 141822a | 2019-08-10 16:07:58 +0100 | [diff] [blame] | 509 | if (data->ci_pdev) |
| 510 | ci_hdrc_remove_device(data->ci_pdev); |
Sebastian Reichel | be9cae2 | 2018-03-29 17:52:49 +0800 | [diff] [blame] | 511 | if (data->override_phy_control) |
| 512 | usb_phy_shutdown(data->phy); |
André Draszik | 141822a | 2019-08-10 16:07:58 +0100 | [diff] [blame] | 513 | if (data->ci_pdev) { |
| 514 | imx_disable_unprepare_clks(&pdev->dev); |
| 515 | if (data->plat_data->flags & CI_HDRC_PMQOS) |
Rafael J. Wysocki | 77b3524 | 2020-02-12 00:28:44 +0100 | [diff] [blame] | 516 | cpu_latency_qos_remove_request(&data->pm_qos_req); |
André Draszik | 141822a | 2019-08-10 16:07:58 +0100 | [diff] [blame] | 517 | if (data->hsic_pad_regulator) |
| 518 | regulator_disable(data->hsic_pad_regulator); |
| 519 | } |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 520 | |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 521 | return 0; |
| 522 | } |
| 523 | |
Andreas Fenkart | b09b522 | 2015-11-12 14:14:40 +0100 | [diff] [blame] | 524 | static void ci_hdrc_imx_shutdown(struct platform_device *pdev) |
| 525 | { |
| 526 | ci_hdrc_imx_remove(pdev); |
| 527 | } |
| 528 | |
Marcus Folkesson | 9f644a6 | 2018-09-02 19:37:04 +0200 | [diff] [blame] | 529 | static int __maybe_unused imx_controller_suspend(struct device *dev) |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 530 | { |
| 531 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 532 | int ret = 0; |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 533 | |
| 534 | dev_dbg(dev, "at %s\n", __func__); |
| 535 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 536 | ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, false); |
| 537 | if (ret) { |
| 538 | dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret); |
| 539 | return ret; |
| 540 | } |
| 541 | |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 542 | imx_disable_unprepare_clks(dev); |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 543 | if (data->plat_data->flags & CI_HDRC_PMQOS) |
Rafael J. Wysocki | 77b3524 | 2020-02-12 00:28:44 +0100 | [diff] [blame] | 544 | cpu_latency_qos_remove_request(&data->pm_qos_req); |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 545 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 546 | data->in_lpm = true; |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
Marcus Folkesson | 9f644a6 | 2018-09-02 19:37:04 +0200 | [diff] [blame] | 551 | static int __maybe_unused imx_controller_resume(struct device *dev) |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 552 | { |
| 553 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 554 | int ret = 0; |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 555 | |
| 556 | dev_dbg(dev, "at %s\n", __func__); |
| 557 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 558 | if (!data->in_lpm) { |
| 559 | WARN_ON(1); |
| 560 | return 0; |
| 561 | } |
| 562 | |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 563 | if (data->plat_data->flags & CI_HDRC_PMQOS) |
Rafael J. Wysocki | 77b3524 | 2020-02-12 00:28:44 +0100 | [diff] [blame] | 564 | cpu_latency_qos_add_request(&data->pm_qos_req, 0); |
Peter Chen | d1609c3 | 2019-04-28 10:35:31 +0800 | [diff] [blame] | 565 | |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 566 | ret = imx_prepare_enable_clks(dev); |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 567 | if (ret) |
| 568 | return ret; |
| 569 | |
| 570 | data->in_lpm = false; |
| 571 | |
| 572 | ret = imx_usbmisc_set_wakeup(data->usbmisc_data, false); |
| 573 | if (ret) { |
| 574 | dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret); |
| 575 | goto clk_disable; |
| 576 | } |
| 577 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 578 | ret = imx_usbmisc_hsic_set_clk(data->usbmisc_data, true); |
| 579 | if (ret) { |
| 580 | dev_err(dev, "usbmisc hsic_set_clk failed, ret=%d\n", ret); |
| 581 | goto hsic_set_clk_fail; |
| 582 | } |
| 583 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 584 | return 0; |
| 585 | |
Peter Chen | 7c8e890 | 2018-10-16 09:17:02 +0800 | [diff] [blame] | 586 | hsic_set_clk_fail: |
| 587 | imx_usbmisc_set_wakeup(data->usbmisc_data, true); |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 588 | clk_disable: |
Peter Chen | ae3e57a | 2015-09-16 09:40:51 +0800 | [diff] [blame] | 589 | imx_disable_unprepare_clks(dev); |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 590 | return ret; |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 591 | } |
| 592 | |
Marcus Folkesson | 9f644a6 | 2018-09-02 19:37:04 +0200 | [diff] [blame] | 593 | static int __maybe_unused ci_hdrc_imx_suspend(struct device *dev) |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 594 | { |
Peter Chen | 6d65311 | 2015-02-11 12:44:49 +0800 | [diff] [blame] | 595 | int ret; |
| 596 | |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 597 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 598 | |
| 599 | if (data->in_lpm) |
| 600 | /* The core's suspend doesn't run */ |
| 601 | return 0; |
| 602 | |
Peter Chen | 6d65311 | 2015-02-11 12:44:49 +0800 | [diff] [blame] | 603 | if (device_may_wakeup(dev)) { |
| 604 | ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true); |
| 605 | if (ret) { |
| 606 | dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", |
| 607 | ret); |
| 608 | return ret; |
| 609 | } |
| 610 | } |
| 611 | |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 612 | return imx_controller_suspend(dev); |
| 613 | } |
| 614 | |
Marcus Folkesson | 9f644a6 | 2018-09-02 19:37:04 +0200 | [diff] [blame] | 615 | static int __maybe_unused ci_hdrc_imx_resume(struct device *dev) |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 616 | { |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 617 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 618 | int ret; |
| 619 | |
| 620 | ret = imx_controller_resume(dev); |
| 621 | if (!ret && data->supports_runtime_pm) { |
| 622 | pm_runtime_disable(dev); |
| 623 | pm_runtime_set_active(dev); |
| 624 | pm_runtime_enable(dev); |
| 625 | } |
| 626 | |
| 627 | return ret; |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 628 | } |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 629 | |
Marcus Folkesson | 9f644a6 | 2018-09-02 19:37:04 +0200 | [diff] [blame] | 630 | static int __maybe_unused ci_hdrc_imx_runtime_suspend(struct device *dev) |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 631 | { |
| 632 | struct ci_hdrc_imx_data *data = dev_get_drvdata(dev); |
| 633 | int ret; |
| 634 | |
| 635 | if (data->in_lpm) { |
| 636 | WARN_ON(1); |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | ret = imx_usbmisc_set_wakeup(data->usbmisc_data, true); |
| 641 | if (ret) { |
| 642 | dev_err(dev, "usbmisc set_wakeup failed, ret=%d\n", ret); |
| 643 | return ret; |
| 644 | } |
| 645 | |
| 646 | return imx_controller_suspend(dev); |
| 647 | } |
| 648 | |
Marcus Folkesson | 9f644a6 | 2018-09-02 19:37:04 +0200 | [diff] [blame] | 649 | static int __maybe_unused ci_hdrc_imx_runtime_resume(struct device *dev) |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 650 | { |
| 651 | return imx_controller_resume(dev); |
| 652 | } |
| 653 | |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 654 | static const struct dev_pm_ops ci_hdrc_imx_pm_ops = { |
| 655 | SET_SYSTEM_SLEEP_PM_OPS(ci_hdrc_imx_suspend, ci_hdrc_imx_resume) |
Peter Chen | e14db48 | 2015-02-11 12:44:47 +0800 | [diff] [blame] | 656 | SET_RUNTIME_PM_OPS(ci_hdrc_imx_runtime_suspend, |
| 657 | ci_hdrc_imx_runtime_resume, NULL) |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 658 | }; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 659 | static struct platform_driver ci_hdrc_imx_driver = { |
| 660 | .probe = ci_hdrc_imx_probe, |
| 661 | .remove = ci_hdrc_imx_remove, |
Andreas Fenkart | b09b522 | 2015-11-12 14:14:40 +0100 | [diff] [blame] | 662 | .shutdown = ci_hdrc_imx_shutdown, |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 663 | .driver = { |
| 664 | .name = "imx_usb", |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 665 | .of_match_table = ci_hdrc_imx_dt_ids, |
Peter Chen | 2558c1f | 2014-11-26 13:44:30 +0800 | [diff] [blame] | 666 | .pm = &ci_hdrc_imx_pm_ops, |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 667 | }, |
| 668 | }; |
| 669 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 670 | module_platform_driver(ci_hdrc_imx_driver); |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 671 | |
| 672 | MODULE_ALIAS("platform:imx-usb"); |
Marcus Folkesson | 1f06072 | 2018-09-02 19:36:50 +0200 | [diff] [blame] | 673 | MODULE_LICENSE("GPL"); |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 674 | MODULE_DESCRIPTION("CI HDRC i.MX USB binding"); |
Richard Zhao | 1530280 | 2012-07-07 22:56:48 +0800 | [diff] [blame] | 675 | MODULE_AUTHOR("Marek Vasut <marex@denx.de>"); |
| 676 | MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>"); |