Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * The code contained herein is licensed under the GNU General Public |
| 5 | * License. You may obtain a copy of the GNU General Public License |
| 6 | * Version 2 or later at the following locations: |
| 7 | * |
| 8 | * http://www.opensource.org/licenses/gpl-license.html |
| 9 | * http://www.gnu.org/copyleft/gpl.html |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/of_platform.h> |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 14 | #include <linux/err.h> |
| 15 | #include <linux/io.h> |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 16 | #include <linux/delay.h> |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 17 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 18 | #include "ci_hdrc_imx.h" |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 19 | |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 20 | #define MX25_USB_PHY_CTRL_OFFSET 0x08 |
| 21 | #define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23) |
| 22 | |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 23 | #define MX25_EHCI_INTERFACE_SINGLE_UNI (2 << 0) |
| 24 | #define MX25_EHCI_INTERFACE_DIFF_UNI (0 << 0) |
| 25 | #define MX25_EHCI_INTERFACE_MASK (0xf) |
| 26 | |
| 27 | #define MX25_OTG_SIC_SHIFT 29 |
| 28 | #define MX25_OTG_SIC_MASK (0x3 << MX25_OTG_SIC_SHIFT) |
| 29 | #define MX25_OTG_PM_BIT BIT(24) |
| 30 | #define MX25_OTG_PP_BIT BIT(11) |
| 31 | #define MX25_OTG_OCPOL_BIT BIT(3) |
| 32 | |
| 33 | #define MX25_H1_SIC_SHIFT 21 |
| 34 | #define MX25_H1_SIC_MASK (0x3 << MX25_H1_SIC_SHIFT) |
| 35 | #define MX25_H1_PP_BIT BIT(18) |
| 36 | #define MX25_H1_PM_BIT BIT(16) |
| 37 | #define MX25_H1_IPPUE_UP_BIT BIT(7) |
| 38 | #define MX25_H1_IPPUE_DOWN_BIT BIT(6) |
| 39 | #define MX25_H1_TLL_BIT BIT(5) |
| 40 | #define MX25_H1_USBTE_BIT BIT(4) |
| 41 | #define MX25_H1_OCPOL_BIT BIT(2) |
| 42 | |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 43 | #define MX27_H1_PM_BIT BIT(8) |
| 44 | #define MX27_H2_PM_BIT BIT(16) |
| 45 | #define MX27_OTG_PM_BIT BIT(24) |
| 46 | |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 47 | #define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08 |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 48 | #define MX53_USB_OTG_PHY_CTRL_1_OFFSET 0x0c |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 49 | #define MX53_USB_UH2_CTRL_OFFSET 0x14 |
| 50 | #define MX53_USB_UH3_CTRL_OFFSET 0x18 |
| 51 | #define MX53_BM_OVER_CUR_DIS_H1 BIT(5) |
| 52 | #define MX53_BM_OVER_CUR_DIS_OTG BIT(8) |
| 53 | #define MX53_BM_OVER_CUR_DIS_UHx BIT(30) |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 54 | #define MX53_USB_PHYCTRL1_PLLDIV_MASK 0x3 |
| 55 | #define MX53_USB_PLL_DIV_24_MHZ 0x01 |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 56 | |
Peter Chen | ed6e5eb | 2014-11-05 14:58:32 +0800 | [diff] [blame] | 57 | #define MX6_BM_NON_BURST_SETTING BIT(1) |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 58 | #define MX6_BM_OVER_CUR_DIS BIT(7) |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 59 | #define MX6_BM_WAKEUP_ENABLE BIT(10) |
| 60 | #define MX6_BM_ID_WAKEUP BIT(16) |
| 61 | #define MX6_BM_VBUS_WAKEUP BIT(17) |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 62 | #define MX6SX_BM_DPDM_WAKEUP_EN BIT(29) |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 63 | #define MX6_BM_WAKEUP_INTR BIT(31) |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 64 | #define MX6_USB_OTG1_PHY_CTRL 0x18 |
| 65 | /* For imx6dql, it is host-only controller, for later imx6, it is otg's */ |
| 66 | #define MX6_USB_OTG2_PHY_CTRL 0x1c |
| 67 | #define MX6SX_USB_VBUS_WAKEUP_SOURCE(v) (v << 8) |
| 68 | #define MX6SX_USB_VBUS_WAKEUP_SOURCE_VBUS MX6SX_USB_VBUS_WAKEUP_SOURCE(0) |
| 69 | #define MX6SX_USB_VBUS_WAKEUP_SOURCE_AVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(1) |
| 70 | #define MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID MX6SX_USB_VBUS_WAKEUP_SOURCE(2) |
| 71 | #define MX6SX_USB_VBUS_WAKEUP_SOURCE_SESS_END MX6SX_USB_VBUS_WAKEUP_SOURCE(3) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 72 | |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 73 | #define VF610_OVER_CUR_DIS BIT(7) |
| 74 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 75 | struct usbmisc_ops { |
| 76 | /* It's called once when probe a usb device */ |
| 77 | int (*init)(struct imx_usbmisc_data *data); |
| 78 | /* It's called once after adding a usb device */ |
| 79 | int (*post)(struct imx_usbmisc_data *data); |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 80 | /* It's called when we need to enable/disable usb wakeup */ |
| 81 | int (*set_wakeup)(struct imx_usbmisc_data *data, bool enabled); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 82 | }; |
| 83 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 84 | struct imx_usbmisc { |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 85 | void __iomem *base; |
| 86 | spinlock_t lock; |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 87 | const struct usbmisc_ops *ops; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 88 | }; |
| 89 | |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 90 | static int usbmisc_imx25_init(struct imx_usbmisc_data *data) |
| 91 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 92 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 93 | unsigned long flags; |
| 94 | u32 val = 0; |
| 95 | |
| 96 | if (data->index > 1) |
| 97 | return -EINVAL; |
| 98 | |
| 99 | spin_lock_irqsave(&usbmisc->lock, flags); |
| 100 | switch (data->index) { |
| 101 | case 0: |
| 102 | val = readl(usbmisc->base); |
| 103 | val &= ~(MX25_OTG_SIC_MASK | MX25_OTG_PP_BIT); |
| 104 | val |= (MX25_EHCI_INTERFACE_DIFF_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_OTG_SIC_SHIFT; |
| 105 | val |= (MX25_OTG_PM_BIT | MX25_OTG_OCPOL_BIT); |
| 106 | writel(val, usbmisc->base); |
| 107 | break; |
| 108 | case 1: |
| 109 | val = readl(usbmisc->base); |
| 110 | val &= ~(MX25_H1_SIC_MASK | MX25_H1_PP_BIT | MX25_H1_IPPUE_UP_BIT); |
| 111 | val |= (MX25_EHCI_INTERFACE_SINGLE_UNI & MX25_EHCI_INTERFACE_MASK) << MX25_H1_SIC_SHIFT; |
| 112 | val |= (MX25_H1_PM_BIT | MX25_H1_OCPOL_BIT | MX25_H1_TLL_BIT | |
| 113 | MX25_H1_USBTE_BIT | MX25_H1_IPPUE_DOWN_BIT); |
| 114 | |
| 115 | writel(val, usbmisc->base); |
| 116 | |
| 117 | break; |
| 118 | } |
| 119 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 124 | static int usbmisc_imx25_post(struct imx_usbmisc_data *data) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 125 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 126 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 127 | void __iomem *reg; |
| 128 | unsigned long flags; |
| 129 | u32 val; |
| 130 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 131 | if (data->index > 2) |
| 132 | return -EINVAL; |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 133 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 134 | if (data->evdo) { |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 135 | spin_lock_irqsave(&usbmisc->lock, flags); |
Fabio Estevam | 8d1dc4d | 2014-11-26 13:44:25 +0800 | [diff] [blame] | 136 | reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET; |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 137 | val = readl(reg); |
| 138 | writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg); |
| 139 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 140 | usleep_range(5000, 10000); /* needed to stabilize voltage */ |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 146 | static int usbmisc_imx27_init(struct imx_usbmisc_data *data) |
| 147 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 148 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 149 | unsigned long flags; |
| 150 | u32 val; |
| 151 | |
| 152 | switch (data->index) { |
| 153 | case 0: |
| 154 | val = MX27_OTG_PM_BIT; |
| 155 | break; |
| 156 | case 1: |
| 157 | val = MX27_H1_PM_BIT; |
| 158 | break; |
| 159 | case 2: |
| 160 | val = MX27_H2_PM_BIT; |
| 161 | break; |
| 162 | default: |
| 163 | return -EINVAL; |
Fabio Estevam | aa90e99 | 2015-05-09 12:15:24 -0300 | [diff] [blame] | 164 | } |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 165 | |
| 166 | spin_lock_irqsave(&usbmisc->lock, flags); |
| 167 | if (data->disable_oc) |
| 168 | val = readl(usbmisc->base) | val; |
| 169 | else |
| 170 | val = readl(usbmisc->base) & ~val; |
| 171 | writel(val, usbmisc->base); |
| 172 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 177 | static int usbmisc_imx53_init(struct imx_usbmisc_data *data) |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 178 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 179 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 180 | void __iomem *reg = NULL; |
| 181 | unsigned long flags; |
| 182 | u32 val = 0; |
| 183 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 184 | if (data->index > 3) |
| 185 | return -EINVAL; |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 186 | |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 187 | /* Select a 24 MHz reference clock for the PHY */ |
Fabio Estevam | 4a1d6cf | 2014-11-26 13:44:26 +0800 | [diff] [blame] | 188 | val = readl(usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET); |
Fabio Estevam | 33f92a8 | 2014-05-04 09:24:39 +0800 | [diff] [blame] | 189 | val &= ~MX53_USB_PHYCTRL1_PLLDIV_MASK; |
| 190 | val |= MX53_USB_PLL_DIV_24_MHZ; |
| 191 | writel(val, usbmisc->base + MX53_USB_OTG_PHY_CTRL_1_OFFSET); |
| 192 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 193 | if (data->disable_oc) { |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 194 | spin_lock_irqsave(&usbmisc->lock, flags); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 195 | switch (data->index) { |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 196 | case 0: |
| 197 | reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; |
| 198 | val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG; |
| 199 | break; |
| 200 | case 1: |
| 201 | reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET; |
| 202 | val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1; |
| 203 | break; |
| 204 | case 2: |
| 205 | reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET; |
| 206 | val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx; |
| 207 | break; |
| 208 | case 3: |
| 209 | reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET; |
| 210 | val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx; |
| 211 | break; |
| 212 | } |
| 213 | if (reg && val) |
| 214 | writel(val, reg); |
| 215 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 216 | } |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 221 | static int usbmisc_imx6q_set_wakeup |
| 222 | (struct imx_usbmisc_data *data, bool enabled) |
| 223 | { |
| 224 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
| 225 | unsigned long flags; |
| 226 | u32 val; |
| 227 | u32 wakeup_setting = (MX6_BM_WAKEUP_ENABLE | |
| 228 | MX6_BM_VBUS_WAKEUP | MX6_BM_ID_WAKEUP); |
| 229 | int ret = 0; |
| 230 | |
| 231 | if (data->index > 3) |
| 232 | return -EINVAL; |
| 233 | |
| 234 | spin_lock_irqsave(&usbmisc->lock, flags); |
| 235 | val = readl(usbmisc->base + data->index * 4); |
| 236 | if (enabled) { |
| 237 | val |= wakeup_setting; |
| 238 | writel(val, usbmisc->base + data->index * 4); |
| 239 | } else { |
| 240 | if (val & MX6_BM_WAKEUP_INTR) |
| 241 | pr_debug("wakeup int at ci_hdrc.%d\n", data->index); |
| 242 | val &= ~wakeup_setting; |
| 243 | writel(val, usbmisc->base + data->index * 4); |
| 244 | } |
| 245 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 246 | |
| 247 | return ret; |
| 248 | } |
| 249 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 250 | static int usbmisc_imx6q_init(struct imx_usbmisc_data *data) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 251 | { |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 252 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 253 | unsigned long flags; |
| 254 | u32 reg; |
| 255 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 256 | if (data->index > 3) |
| 257 | return -EINVAL; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 258 | |
Peter Chen | ed6e5eb | 2014-11-05 14:58:32 +0800 | [diff] [blame] | 259 | spin_lock_irqsave(&usbmisc->lock, flags); |
| 260 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 261 | if (data->disable_oc) { |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 262 | reg = readl(usbmisc->base + data->index * 4); |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 263 | writel(reg | MX6_BM_OVER_CUR_DIS, |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 264 | usbmisc->base + data->index * 4); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 265 | } |
| 266 | |
Peter Chen | ed6e5eb | 2014-11-05 14:58:32 +0800 | [diff] [blame] | 267 | /* SoC non-burst setting */ |
| 268 | reg = readl(usbmisc->base + data->index * 4); |
| 269 | writel(reg | MX6_BM_NON_BURST_SETTING, |
| 270 | usbmisc->base + data->index * 4); |
| 271 | |
| 272 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 273 | |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 274 | usbmisc_imx6q_set_wakeup(data, false); |
| 275 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 279 | static int usbmisc_imx6sx_init(struct imx_usbmisc_data *data) |
| 280 | { |
| 281 | void __iomem *reg = NULL; |
| 282 | unsigned long flags; |
| 283 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
| 284 | u32 val; |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 285 | |
| 286 | usbmisc_imx6q_init(data); |
| 287 | |
| 288 | if (data->index == 0 || data->index == 1) { |
| 289 | reg = usbmisc->base + MX6_USB_OTG1_PHY_CTRL + data->index * 4; |
| 290 | spin_lock_irqsave(&usbmisc->lock, flags); |
| 291 | /* Set vbus wakeup source as bvalid */ |
| 292 | val = readl(reg); |
| 293 | writel(val | MX6SX_USB_VBUS_WAKEUP_SOURCE_BVALID, reg); |
| 294 | /* |
| 295 | * Disable dp/dm wakeup in device mode when vbus is |
| 296 | * not there. |
| 297 | */ |
| 298 | val = readl(usbmisc->base + data->index * 4); |
| 299 | writel(val & ~MX6SX_BM_DPDM_WAKEUP_EN, |
| 300 | usbmisc->base + data->index * 4); |
| 301 | spin_unlock_irqrestore(&usbmisc->lock, flags); |
| 302 | } |
| 303 | |
kbuild test robot | 1fcefbd | 2015-03-25 07:23:52 +0100 | [diff] [blame] | 304 | return 0; |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 305 | } |
| 306 | |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 307 | static int usbmisc_vf610_init(struct imx_usbmisc_data *data) |
| 308 | { |
| 309 | struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev); |
| 310 | u32 reg; |
| 311 | |
| 312 | /* |
| 313 | * Vybrid only has one misc register set, but in two different |
| 314 | * areas. These is reflected in two instances of this driver. |
| 315 | */ |
| 316 | if (data->index >= 1) |
| 317 | return -EINVAL; |
| 318 | |
| 319 | if (data->disable_oc) { |
| 320 | reg = readl(usbmisc->base); |
| 321 | writel(reg | VF610_OVER_CUR_DIS, usbmisc->base); |
| 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 327 | static const struct usbmisc_ops imx25_usbmisc_ops = { |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 328 | .init = usbmisc_imx25_init, |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 329 | .post = usbmisc_imx25_post, |
| 330 | }; |
| 331 | |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 332 | static const struct usbmisc_ops imx27_usbmisc_ops = { |
| 333 | .init = usbmisc_imx27_init, |
| 334 | }; |
| 335 | |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 336 | static const struct usbmisc_ops imx53_usbmisc_ops = { |
| 337 | .init = usbmisc_imx53_init, |
| 338 | }; |
| 339 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 340 | static const struct usbmisc_ops imx6q_usbmisc_ops = { |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 341 | .set_wakeup = usbmisc_imx6q_set_wakeup, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 342 | .init = usbmisc_imx6q_init, |
| 343 | }; |
| 344 | |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 345 | static const struct usbmisc_ops vf610_usbmisc_ops = { |
| 346 | .init = usbmisc_vf610_init, |
| 347 | }; |
| 348 | |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 349 | static const struct usbmisc_ops imx6sx_usbmisc_ops = { |
| 350 | .set_wakeup = usbmisc_imx6q_set_wakeup, |
| 351 | .init = usbmisc_imx6sx_init, |
| 352 | }; |
| 353 | |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 354 | int imx_usbmisc_init(struct imx_usbmisc_data *data) |
| 355 | { |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 356 | struct imx_usbmisc *usbmisc; |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 357 | |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 358 | if (!data) |
| 359 | return 0; |
| 360 | |
| 361 | usbmisc = dev_get_drvdata(data->dev); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 362 | if (!usbmisc->ops->init) |
| 363 | return 0; |
| 364 | return usbmisc->ops->init(data); |
| 365 | } |
| 366 | EXPORT_SYMBOL_GPL(imx_usbmisc_init); |
| 367 | |
| 368 | int imx_usbmisc_init_post(struct imx_usbmisc_data *data) |
| 369 | { |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 370 | struct imx_usbmisc *usbmisc; |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 371 | |
Peter Chen | a4cf1b1 | 2015-02-11 12:44:44 +0800 | [diff] [blame] | 372 | if (!data) |
| 373 | return 0; |
| 374 | |
| 375 | usbmisc = dev_get_drvdata(data->dev); |
Sascha Hauer | 05986ba | 2013-08-14 12:44:16 +0300 | [diff] [blame] | 376 | if (!usbmisc->ops->post) |
| 377 | return 0; |
| 378 | return usbmisc->ops->post(data); |
| 379 | } |
| 380 | EXPORT_SYMBOL_GPL(imx_usbmisc_init_post); |
| 381 | |
Peter Chen | f636cec | 2015-02-11 12:44:46 +0800 | [diff] [blame] | 382 | int imx_usbmisc_set_wakeup(struct imx_usbmisc_data *data, bool enabled) |
| 383 | { |
| 384 | struct imx_usbmisc *usbmisc; |
| 385 | |
| 386 | if (!data) |
| 387 | return 0; |
| 388 | |
| 389 | usbmisc = dev_get_drvdata(data->dev); |
| 390 | if (!usbmisc->ops->set_wakeup) |
| 391 | return 0; |
| 392 | return usbmisc->ops->set_wakeup(data, enabled); |
| 393 | } |
| 394 | EXPORT_SYMBOL_GPL(imx_usbmisc_set_wakeup); |
| 395 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 396 | static const struct of_device_id usbmisc_imx_dt_ids[] = { |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 397 | { |
Michael Grzeschik | a068533 | 2013-03-30 12:54:01 +0200 | [diff] [blame] | 398 | .compatible = "fsl,imx25-usbmisc", |
| 399 | .data = &imx25_usbmisc_ops, |
| 400 | }, |
| 401 | { |
Denis Carikli | 72ee92d | 2014-04-23 15:56:36 +0800 | [diff] [blame] | 402 | .compatible = "fsl,imx35-usbmisc", |
| 403 | .data = &imx25_usbmisc_ops, |
| 404 | }, |
| 405 | { |
Alexander Shiyan | 9f90e11 | 2013-12-06 16:35:14 +0800 | [diff] [blame] | 406 | .compatible = "fsl,imx27-usbmisc", |
| 407 | .data = &imx27_usbmisc_ops, |
| 408 | }, |
| 409 | { |
Alexander Shiyan | c4962e0 | 2013-12-06 16:35:15 +0800 | [diff] [blame] | 410 | .compatible = "fsl,imx51-usbmisc", |
| 411 | .data = &imx53_usbmisc_ops, |
| 412 | }, |
| 413 | { |
Michael Grzeschik | f0c910b | 2013-03-30 12:54:00 +0200 | [diff] [blame] | 414 | .compatible = "fsl,imx53-usbmisc", |
| 415 | .data = &imx53_usbmisc_ops, |
| 416 | }, |
| 417 | { |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 418 | .compatible = "fsl,imx6q-usbmisc", |
| 419 | .data = &imx6q_usbmisc_ops, |
| 420 | }, |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 421 | { |
| 422 | .compatible = "fsl,vf610-usbmisc", |
| 423 | .data = &vf610_usbmisc_ops, |
| 424 | }, |
Peter Chen | 8721a75 | 2015-02-11 12:44:53 +0800 | [diff] [blame] | 425 | { |
| 426 | .compatible = "fsl,imx6sx-usbmisc", |
| 427 | .data = &imx6sx_usbmisc_ops, |
| 428 | }, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 429 | { /* sentinel */ } |
| 430 | }; |
Arnaud Patard (Rtp) | 269b83d | 2013-06-20 23:33:25 +0200 | [diff] [blame] | 431 | MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 432 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 433 | static int usbmisc_imx_probe(struct platform_device *pdev) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 434 | { |
| 435 | struct resource *res; |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 436 | struct imx_usbmisc *data; |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 437 | struct of_device_id *tmp_dev; |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 438 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 439 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
| 440 | if (!data) |
| 441 | return -ENOMEM; |
| 442 | |
| 443 | spin_lock_init(&data->lock); |
| 444 | |
| 445 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 446 | data->base = devm_ioremap_resource(&pdev->dev, res); |
| 447 | if (IS_ERR(data->base)) |
| 448 | return PTR_ERR(data->base); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 449 | |
Marc Kleine-Budde | e609108 | 2013-03-30 12:53:59 +0200 | [diff] [blame] | 450 | tmp_dev = (struct of_device_id *) |
| 451 | of_match_device(usbmisc_imx_dt_ids, &pdev->dev); |
| 452 | data->ops = (const struct usbmisc_ops *)tmp_dev->data; |
Stefan Agner | f40017e | 2014-09-22 08:14:15 +0800 | [diff] [blame] | 453 | platform_set_drvdata(pdev, data); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 454 | |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 458 | static int usbmisc_imx_remove(struct platform_device *pdev) |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 459 | { |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 463 | static struct platform_driver usbmisc_imx_driver = { |
| 464 | .probe = usbmisc_imx_probe, |
| 465 | .remove = usbmisc_imx_remove, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 466 | .driver = { |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 467 | .name = "usbmisc_imx", |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 468 | .of_match_table = usbmisc_imx_dt_ids, |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 469 | }, |
| 470 | }; |
| 471 | |
Philipp Zabel | 0404ae0 | 2013-06-13 17:59:59 +0300 | [diff] [blame] | 472 | module_platform_driver(usbmisc_imx_driver); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 473 | |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 474 | MODULE_ALIAS("platform:usbmisc-imx"); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 475 | MODULE_LICENSE("GPL v2"); |
Michael Grzeschik | a7bc2fd | 2013-03-30 12:53:56 +0200 | [diff] [blame] | 476 | MODULE_DESCRIPTION("driver for imx usb non-core registers"); |
Richard Zhao | d142d6b | 2012-09-12 14:58:05 +0300 | [diff] [blame] | 477 | MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>"); |