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