Commit 58efc77c86af5cb81d7d7ea0c3c3e675e7d121dc

Authored by Kuninori Morimoto
Committed by Greg Kroah-Hartman
1 parent 1cd572fc0c

usb: renesas_usbhs: convert to devm_xxx()

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 4 additions and 11 deletions Inline Diff

drivers/usb/renesas_usbhs/common.c
1 /* 1 /*
2 * Renesas USB driver 2 * Renesas USB driver
3 * 3 *
4 * Copyright (C) 2011 Renesas Solutions Corp. 4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 * 6 *
7 * This program is distributed in the hope that it will be useful, 7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details. 10 * GNU General Public License for more details.
11 * 11 *
12 * You should have received a copy of the GNU General Public License 12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software 13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 * 15 *
16 */ 16 */
17 #include <linux/io.h> 17 #include <linux/io.h>
18 #include <linux/module.h> 18 #include <linux/module.h>
19 #include <linux/pm_runtime.h> 19 #include <linux/pm_runtime.h>
20 #include <linux/slab.h> 20 #include <linux/slab.h>
21 #include <linux/sysfs.h> 21 #include <linux/sysfs.h>
22 #include "common.h" 22 #include "common.h"
23 23
24 /* 24 /*
25 * image of renesas_usbhs 25 * image of renesas_usbhs
26 * 26 *
27 * ex) gadget case 27 * ex) gadget case
28 28
29 * mod.c 29 * mod.c
30 * mod_gadget.c 30 * mod_gadget.c
31 * mod_host.c pipe.c fifo.c 31 * mod_host.c pipe.c fifo.c
32 * 32 *
33 * +-------+ +-----------+ 33 * +-------+ +-----------+
34 * | pipe0 |------>| fifo pio | 34 * | pipe0 |------>| fifo pio |
35 * +------------+ +-------+ +-----------+ 35 * +------------+ +-------+ +-----------+
36 * | mod_gadget |=====> | pipe1 |--+ 36 * | mod_gadget |=====> | pipe1 |--+
37 * +------------+ +-------+ | +-----------+ 37 * +------------+ +-------+ | +-----------+
38 * | pipe2 | | +-| fifo dma0 | 38 * | pipe2 | | +-| fifo dma0 |
39 * +------------+ +-------+ | | +-----------+ 39 * +------------+ +-------+ | | +-----------+
40 * | mod_host | | pipe3 |<-|--+ 40 * | mod_host | | pipe3 |<-|--+
41 * +------------+ +-------+ | +-----------+ 41 * +------------+ +-------+ | +-----------+
42 * | .... | +--->| fifo dma1 | 42 * | .... | +--->| fifo dma1 |
43 * | .... | +-----------+ 43 * | .... | +-----------+
44 */ 44 */
45 45
46 46
47 #define USBHSF_RUNTIME_PWCTRL (1 << 0) 47 #define USBHSF_RUNTIME_PWCTRL (1 << 0)
48 48
49 /* status */ 49 /* status */
50 #define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0) 50 #define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0)
51 #define usbhsc_flags_set(p, b) ((p)->flags |= (b)) 51 #define usbhsc_flags_set(p, b) ((p)->flags |= (b))
52 #define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b)) 52 #define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b))
53 #define usbhsc_flags_has(p, b) ((p)->flags & (b)) 53 #define usbhsc_flags_has(p, b) ((p)->flags & (b))
54 54
55 /* 55 /*
56 * platform call back 56 * platform call back
57 * 57 *
58 * renesas usb support platform callback function. 58 * renesas usb support platform callback function.
59 * Below macro call it. 59 * Below macro call it.
60 * if platform doesn't have callback, it return 0 (no error) 60 * if platform doesn't have callback, it return 0 (no error)
61 */ 61 */
62 #define usbhs_platform_call(priv, func, args...)\ 62 #define usbhs_platform_call(priv, func, args...)\
63 (!(priv) ? -ENODEV : \ 63 (!(priv) ? -ENODEV : \
64 !((priv)->pfunc.func) ? 0 : \ 64 !((priv)->pfunc.func) ? 0 : \
65 (priv)->pfunc.func(args)) 65 (priv)->pfunc.func(args))
66 66
67 /* 67 /*
68 * common functions 68 * common functions
69 */ 69 */
70 u16 usbhs_read(struct usbhs_priv *priv, u32 reg) 70 u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
71 { 71 {
72 return ioread16(priv->base + reg); 72 return ioread16(priv->base + reg);
73 } 73 }
74 74
75 void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data) 75 void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
76 { 76 {
77 iowrite16(data, priv->base + reg); 77 iowrite16(data, priv->base + reg);
78 } 78 }
79 79
80 void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data) 80 void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
81 { 81 {
82 u16 val = usbhs_read(priv, reg); 82 u16 val = usbhs_read(priv, reg);
83 83
84 val &= ~mask; 84 val &= ~mask;
85 val |= data & mask; 85 val |= data & mask;
86 86
87 usbhs_write(priv, reg, val); 87 usbhs_write(priv, reg, val);
88 } 88 }
89 89
90 struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev) 90 struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
91 { 91 {
92 return dev_get_drvdata(&pdev->dev); 92 return dev_get_drvdata(&pdev->dev);
93 } 93 }
94 94
95 /* 95 /*
96 * syscfg functions 96 * syscfg functions
97 */ 97 */
98 static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable) 98 static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
99 { 99 {
100 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0); 100 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
101 } 101 }
102 102
103 void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable) 103 void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
104 { 104 {
105 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; 105 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
106 u16 val = DCFM | DRPD | HSE | USBE; 106 u16 val = DCFM | DRPD | HSE | USBE;
107 int has_otg = usbhs_get_dparam(priv, has_otg); 107 int has_otg = usbhs_get_dparam(priv, has_otg);
108 108
109 if (has_otg) 109 if (has_otg)
110 usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN)); 110 usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN));
111 111
112 /* 112 /*
113 * if enable 113 * if enable
114 * 114 *
115 * - select Host mode 115 * - select Host mode
116 * - D+ Line/D- Line Pull-down 116 * - D+ Line/D- Line Pull-down
117 */ 117 */
118 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); 118 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
119 } 119 }
120 120
121 void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) 121 void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
122 { 122 {
123 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; 123 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
124 u16 val = DPRPU | HSE | USBE; 124 u16 val = DPRPU | HSE | USBE;
125 125
126 /* 126 /*
127 * if enable 127 * if enable
128 * 128 *
129 * - select Function mode 129 * - select Function mode
130 * - D+ Line Pull-up 130 * - D+ Line Pull-up
131 */ 131 */
132 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); 132 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
133 } 133 }
134 134
135 void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode) 135 void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode)
136 { 136 {
137 usbhs_write(priv, TESTMODE, mode); 137 usbhs_write(priv, TESTMODE, mode);
138 } 138 }
139 139
140 /* 140 /*
141 * frame functions 141 * frame functions
142 */ 142 */
143 int usbhs_frame_get_num(struct usbhs_priv *priv) 143 int usbhs_frame_get_num(struct usbhs_priv *priv)
144 { 144 {
145 return usbhs_read(priv, FRMNUM) & FRNM_MASK; 145 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
146 } 146 }
147 147
148 /* 148 /*
149 * usb request functions 149 * usb request functions
150 */ 150 */
151 void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req) 151 void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
152 { 152 {
153 u16 val; 153 u16 val;
154 154
155 val = usbhs_read(priv, USBREQ); 155 val = usbhs_read(priv, USBREQ);
156 req->bRequest = (val >> 8) & 0xFF; 156 req->bRequest = (val >> 8) & 0xFF;
157 req->bRequestType = (val >> 0) & 0xFF; 157 req->bRequestType = (val >> 0) & 0xFF;
158 158
159 req->wValue = usbhs_read(priv, USBVAL); 159 req->wValue = usbhs_read(priv, USBVAL);
160 req->wIndex = usbhs_read(priv, USBINDX); 160 req->wIndex = usbhs_read(priv, USBINDX);
161 req->wLength = usbhs_read(priv, USBLENG); 161 req->wLength = usbhs_read(priv, USBLENG);
162 } 162 }
163 163
164 void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req) 164 void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
165 { 165 {
166 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType); 166 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
167 usbhs_write(priv, USBVAL, req->wValue); 167 usbhs_write(priv, USBVAL, req->wValue);
168 usbhs_write(priv, USBINDX, req->wIndex); 168 usbhs_write(priv, USBINDX, req->wIndex);
169 usbhs_write(priv, USBLENG, req->wLength); 169 usbhs_write(priv, USBLENG, req->wLength);
170 170
171 usbhs_bset(priv, DCPCTR, SUREQ, SUREQ); 171 usbhs_bset(priv, DCPCTR, SUREQ, SUREQ);
172 } 172 }
173 173
174 /* 174 /*
175 * bus/vbus functions 175 * bus/vbus functions
176 */ 176 */
177 void usbhs_bus_send_sof_enable(struct usbhs_priv *priv) 177 void usbhs_bus_send_sof_enable(struct usbhs_priv *priv)
178 { 178 {
179 u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT); 179 u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT);
180 180
181 if (status != USBRST) { 181 if (status != USBRST) {
182 struct device *dev = usbhs_priv_to_dev(priv); 182 struct device *dev = usbhs_priv_to_dev(priv);
183 dev_err(dev, "usbhs should be reset\n"); 183 dev_err(dev, "usbhs should be reset\n");
184 } 184 }
185 185
186 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT); 186 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT);
187 } 187 }
188 188
189 void usbhs_bus_send_reset(struct usbhs_priv *priv) 189 void usbhs_bus_send_reset(struct usbhs_priv *priv)
190 { 190 {
191 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST); 191 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST);
192 } 192 }
193 193
194 int usbhs_bus_get_speed(struct usbhs_priv *priv) 194 int usbhs_bus_get_speed(struct usbhs_priv *priv)
195 { 195 {
196 u16 dvstctr = usbhs_read(priv, DVSTCTR); 196 u16 dvstctr = usbhs_read(priv, DVSTCTR);
197 197
198 switch (RHST & dvstctr) { 198 switch (RHST & dvstctr) {
199 case RHST_LOW_SPEED: 199 case RHST_LOW_SPEED:
200 return USB_SPEED_LOW; 200 return USB_SPEED_LOW;
201 case RHST_FULL_SPEED: 201 case RHST_FULL_SPEED:
202 return USB_SPEED_FULL; 202 return USB_SPEED_FULL;
203 case RHST_HIGH_SPEED: 203 case RHST_HIGH_SPEED:
204 return USB_SPEED_HIGH; 204 return USB_SPEED_HIGH;
205 } 205 }
206 206
207 return USB_SPEED_UNKNOWN; 207 return USB_SPEED_UNKNOWN;
208 } 208 }
209 209
210 int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable) 210 int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable)
211 { 211 {
212 struct platform_device *pdev = usbhs_priv_to_pdev(priv); 212 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
213 213
214 return usbhs_platform_call(priv, set_vbus, pdev, enable); 214 return usbhs_platform_call(priv, set_vbus, pdev, enable);
215 } 215 }
216 216
217 static void usbhsc_bus_init(struct usbhs_priv *priv) 217 static void usbhsc_bus_init(struct usbhs_priv *priv)
218 { 218 {
219 usbhs_write(priv, DVSTCTR, 0); 219 usbhs_write(priv, DVSTCTR, 0);
220 220
221 usbhs_vbus_ctrl(priv, 0); 221 usbhs_vbus_ctrl(priv, 0);
222 } 222 }
223 223
224 /* 224 /*
225 * device configuration 225 * device configuration
226 */ 226 */
227 int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, 227 int usbhs_set_device_config(struct usbhs_priv *priv, int devnum,
228 u16 upphub, u16 hubport, u16 speed) 228 u16 upphub, u16 hubport, u16 speed)
229 { 229 {
230 struct device *dev = usbhs_priv_to_dev(priv); 230 struct device *dev = usbhs_priv_to_dev(priv);
231 u16 usbspd = 0; 231 u16 usbspd = 0;
232 u32 reg = DEVADD0 + (2 * devnum); 232 u32 reg = DEVADD0 + (2 * devnum);
233 233
234 if (devnum > 10) { 234 if (devnum > 10) {
235 dev_err(dev, "cannot set speed to unknown device %d\n", devnum); 235 dev_err(dev, "cannot set speed to unknown device %d\n", devnum);
236 return -EIO; 236 return -EIO;
237 } 237 }
238 238
239 if (upphub > 0xA) { 239 if (upphub > 0xA) {
240 dev_err(dev, "unsupported hub number %d\n", upphub); 240 dev_err(dev, "unsupported hub number %d\n", upphub);
241 return -EIO; 241 return -EIO;
242 } 242 }
243 243
244 switch (speed) { 244 switch (speed) {
245 case USB_SPEED_LOW: 245 case USB_SPEED_LOW:
246 usbspd = USBSPD_SPEED_LOW; 246 usbspd = USBSPD_SPEED_LOW;
247 break; 247 break;
248 case USB_SPEED_FULL: 248 case USB_SPEED_FULL:
249 usbspd = USBSPD_SPEED_FULL; 249 usbspd = USBSPD_SPEED_FULL;
250 break; 250 break;
251 case USB_SPEED_HIGH: 251 case USB_SPEED_HIGH:
252 usbspd = USBSPD_SPEED_HIGH; 252 usbspd = USBSPD_SPEED_HIGH;
253 break; 253 break;
254 default: 254 default:
255 dev_err(dev, "unsupported speed %d\n", speed); 255 dev_err(dev, "unsupported speed %d\n", speed);
256 return -EIO; 256 return -EIO;
257 } 257 }
258 258
259 usbhs_write(priv, reg, UPPHUB(upphub) | 259 usbhs_write(priv, reg, UPPHUB(upphub) |
260 HUBPORT(hubport)| 260 HUBPORT(hubport)|
261 USBSPD(usbspd)); 261 USBSPD(usbspd));
262 262
263 return 0; 263 return 0;
264 } 264 }
265 265
266 /* 266 /*
267 * local functions 267 * local functions
268 */ 268 */
269 static void usbhsc_set_buswait(struct usbhs_priv *priv) 269 static void usbhsc_set_buswait(struct usbhs_priv *priv)
270 { 270 {
271 int wait = usbhs_get_dparam(priv, buswait_bwait); 271 int wait = usbhs_get_dparam(priv, buswait_bwait);
272 272
273 /* set bus wait if platform have */ 273 /* set bus wait if platform have */
274 if (wait) 274 if (wait)
275 usbhs_bset(priv, BUSWAIT, 0x000F, wait); 275 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
276 } 276 }
277 277
278 /* 278 /*
279 * platform default param 279 * platform default param
280 */ 280 */
281 static u32 usbhsc_default_pipe_type[] = { 281 static u32 usbhsc_default_pipe_type[] = {
282 USB_ENDPOINT_XFER_CONTROL, 282 USB_ENDPOINT_XFER_CONTROL,
283 USB_ENDPOINT_XFER_ISOC, 283 USB_ENDPOINT_XFER_ISOC,
284 USB_ENDPOINT_XFER_ISOC, 284 USB_ENDPOINT_XFER_ISOC,
285 USB_ENDPOINT_XFER_BULK, 285 USB_ENDPOINT_XFER_BULK,
286 USB_ENDPOINT_XFER_BULK, 286 USB_ENDPOINT_XFER_BULK,
287 USB_ENDPOINT_XFER_BULK, 287 USB_ENDPOINT_XFER_BULK,
288 USB_ENDPOINT_XFER_INT, 288 USB_ENDPOINT_XFER_INT,
289 USB_ENDPOINT_XFER_INT, 289 USB_ENDPOINT_XFER_INT,
290 USB_ENDPOINT_XFER_INT, 290 USB_ENDPOINT_XFER_INT,
291 USB_ENDPOINT_XFER_INT, 291 USB_ENDPOINT_XFER_INT,
292 }; 292 };
293 293
294 /* 294 /*
295 * power control 295 * power control
296 */ 296 */
297 static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable) 297 static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
298 { 298 {
299 struct platform_device *pdev = usbhs_priv_to_pdev(priv); 299 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
300 struct device *dev = usbhs_priv_to_dev(priv); 300 struct device *dev = usbhs_priv_to_dev(priv);
301 301
302 if (enable) { 302 if (enable) {
303 /* enable PM */ 303 /* enable PM */
304 pm_runtime_get_sync(dev); 304 pm_runtime_get_sync(dev);
305 305
306 /* enable platform power */ 306 /* enable platform power */
307 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); 307 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
308 308
309 /* USB on */ 309 /* USB on */
310 usbhs_sys_clock_ctrl(priv, enable); 310 usbhs_sys_clock_ctrl(priv, enable);
311 } else { 311 } else {
312 /* USB off */ 312 /* USB off */
313 usbhs_sys_clock_ctrl(priv, enable); 313 usbhs_sys_clock_ctrl(priv, enable);
314 314
315 /* disable platform power */ 315 /* disable platform power */
316 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); 316 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
317 317
318 /* disable PM */ 318 /* disable PM */
319 pm_runtime_put_sync(dev); 319 pm_runtime_put_sync(dev);
320 } 320 }
321 } 321 }
322 322
323 /* 323 /*
324 * hotplug 324 * hotplug
325 */ 325 */
326 static void usbhsc_hotplug(struct usbhs_priv *priv) 326 static void usbhsc_hotplug(struct usbhs_priv *priv)
327 { 327 {
328 struct platform_device *pdev = usbhs_priv_to_pdev(priv); 328 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
329 struct usbhs_mod *mod = usbhs_mod_get_current(priv); 329 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
330 int id; 330 int id;
331 int enable; 331 int enable;
332 int ret; 332 int ret;
333 333
334 /* 334 /*
335 * get vbus status from platform 335 * get vbus status from platform
336 */ 336 */
337 enable = usbhs_platform_call(priv, get_vbus, pdev); 337 enable = usbhs_platform_call(priv, get_vbus, pdev);
338 338
339 /* 339 /*
340 * get id from platform 340 * get id from platform
341 */ 341 */
342 id = usbhs_platform_call(priv, get_id, pdev); 342 id = usbhs_platform_call(priv, get_id, pdev);
343 343
344 if (enable && !mod) { 344 if (enable && !mod) {
345 ret = usbhs_mod_change(priv, id); 345 ret = usbhs_mod_change(priv, id);
346 if (ret < 0) 346 if (ret < 0)
347 return; 347 return;
348 348
349 dev_dbg(&pdev->dev, "%s enable\n", __func__); 349 dev_dbg(&pdev->dev, "%s enable\n", __func__);
350 350
351 /* power on */ 351 /* power on */
352 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 352 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
353 usbhsc_power_ctrl(priv, enable); 353 usbhsc_power_ctrl(priv, enable);
354 354
355 /* bus init */ 355 /* bus init */
356 usbhsc_set_buswait(priv); 356 usbhsc_set_buswait(priv);
357 usbhsc_bus_init(priv); 357 usbhsc_bus_init(priv);
358 358
359 /* module start */ 359 /* module start */
360 usbhs_mod_call(priv, start, priv); 360 usbhs_mod_call(priv, start, priv);
361 361
362 } else if (!enable && mod) { 362 } else if (!enable && mod) {
363 dev_dbg(&pdev->dev, "%s disable\n", __func__); 363 dev_dbg(&pdev->dev, "%s disable\n", __func__);
364 364
365 /* module stop */ 365 /* module stop */
366 usbhs_mod_call(priv, stop, priv); 366 usbhs_mod_call(priv, stop, priv);
367 367
368 /* bus init */ 368 /* bus init */
369 usbhsc_bus_init(priv); 369 usbhsc_bus_init(priv);
370 370
371 /* power off */ 371 /* power off */
372 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 372 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
373 usbhsc_power_ctrl(priv, enable); 373 usbhsc_power_ctrl(priv, enable);
374 374
375 usbhs_mod_change(priv, -1); 375 usbhs_mod_change(priv, -1);
376 376
377 /* reset phy for next connection */ 377 /* reset phy for next connection */
378 usbhs_platform_call(priv, phy_reset, pdev); 378 usbhs_platform_call(priv, phy_reset, pdev);
379 } 379 }
380 } 380 }
381 381
382 /* 382 /*
383 * notify hotplug 383 * notify hotplug
384 */ 384 */
385 static void usbhsc_notify_hotplug(struct work_struct *work) 385 static void usbhsc_notify_hotplug(struct work_struct *work)
386 { 386 {
387 struct usbhs_priv *priv = container_of(work, 387 struct usbhs_priv *priv = container_of(work,
388 struct usbhs_priv, 388 struct usbhs_priv,
389 notify_hotplug_work.work); 389 notify_hotplug_work.work);
390 usbhsc_hotplug(priv); 390 usbhsc_hotplug(priv);
391 } 391 }
392 392
393 static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev) 393 static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
394 { 394 {
395 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 395 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
396 int delay = usbhs_get_dparam(priv, detection_delay); 396 int delay = usbhs_get_dparam(priv, detection_delay);
397 397
398 /* 398 /*
399 * This functions will be called in interrupt. 399 * This functions will be called in interrupt.
400 * To make sure safety context, 400 * To make sure safety context,
401 * use workqueue for usbhs_notify_hotplug 401 * use workqueue for usbhs_notify_hotplug
402 */ 402 */
403 schedule_delayed_work(&priv->notify_hotplug_work, 403 schedule_delayed_work(&priv->notify_hotplug_work,
404 msecs_to_jiffies(delay)); 404 msecs_to_jiffies(delay));
405 return 0; 405 return 0;
406 } 406 }
407 407
408 /* 408 /*
409 * platform functions 409 * platform functions
410 */ 410 */
411 static int usbhs_probe(struct platform_device *pdev) 411 static int usbhs_probe(struct platform_device *pdev)
412 { 412 {
413 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data; 413 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
414 struct renesas_usbhs_driver_callback *dfunc; 414 struct renesas_usbhs_driver_callback *dfunc;
415 struct usbhs_priv *priv; 415 struct usbhs_priv *priv;
416 struct resource *res, *irq_res; 416 struct resource *res, *irq_res;
417 int ret; 417 int ret;
418 418
419 /* check platform information */ 419 /* check platform information */
420 if (!info || 420 if (!info ||
421 !info->platform_callback.get_id) { 421 !info->platform_callback.get_id) {
422 dev_err(&pdev->dev, "no platform information\n"); 422 dev_err(&pdev->dev, "no platform information\n");
423 return -EINVAL; 423 return -EINVAL;
424 } 424 }
425 425
426 /* platform data */ 426 /* platform data */
427 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 427 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
428 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 428 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
429 if (!res || !irq_res) { 429 if (!res || !irq_res) {
430 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n"); 430 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
431 return -ENODEV; 431 return -ENODEV;
432 } 432 }
433 433
434 /* usb private data */ 434 /* usb private data */
435 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 435 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
436 if (!priv) { 436 if (!priv) {
437 dev_err(&pdev->dev, "Could not allocate priv\n"); 437 dev_err(&pdev->dev, "Could not allocate priv\n");
438 return -ENOMEM; 438 return -ENOMEM;
439 } 439 }
440 440
441 priv->base = ioremap_nocache(res->start, resource_size(res)); 441 priv->base = devm_request_and_ioremap(&pdev->dev, res);
442 if (!priv->base) { 442 if (!priv->base) {
443 dev_err(&pdev->dev, "ioremap error.\n"); 443 dev_err(&pdev->dev, "ioremap error.\n");
444 ret = -ENOMEM; 444 return -ENOMEM;
445 goto probe_end_kfree;
446 } 445 }
447 446
448 /* 447 /*
449 * care platform info 448 * care platform info
450 */ 449 */
451 memcpy(&priv->pfunc, 450 memcpy(&priv->pfunc,
452 &info->platform_callback, 451 &info->platform_callback,
453 sizeof(struct renesas_usbhs_platform_callback)); 452 sizeof(struct renesas_usbhs_platform_callback));
454 memcpy(&priv->dparam, 453 memcpy(&priv->dparam,
455 &info->driver_param, 454 &info->driver_param,
456 sizeof(struct renesas_usbhs_driver_param)); 455 sizeof(struct renesas_usbhs_driver_param));
457 456
458 /* set driver callback functions for platform */ 457 /* set driver callback functions for platform */
459 dfunc = &info->driver_callback; 458 dfunc = &info->driver_callback;
460 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug; 459 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
461 460
462 /* set default param if platform doesn't have */ 461 /* set default param if platform doesn't have */
463 if (!priv->dparam.pipe_type) { 462 if (!priv->dparam.pipe_type) {
464 priv->dparam.pipe_type = usbhsc_default_pipe_type; 463 priv->dparam.pipe_type = usbhsc_default_pipe_type;
465 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type); 464 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
466 } 465 }
467 if (!priv->dparam.pio_dma_border) 466 if (!priv->dparam.pio_dma_border)
468 priv->dparam.pio_dma_border = 64; /* 64byte */ 467 priv->dparam.pio_dma_border = 64; /* 64byte */
469 468
470 /* FIXME */ 469 /* FIXME */
471 /* runtime power control ? */ 470 /* runtime power control ? */
472 if (priv->pfunc.get_vbus) 471 if (priv->pfunc.get_vbus)
473 usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL); 472 usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
474 473
475 /* 474 /*
476 * priv settings 475 * priv settings
477 */ 476 */
478 priv->irq = irq_res->start; 477 priv->irq = irq_res->start;
479 if (irq_res->flags & IORESOURCE_IRQ_SHAREABLE) 478 if (irq_res->flags & IORESOURCE_IRQ_SHAREABLE)
480 priv->irqflags = IRQF_SHARED; 479 priv->irqflags = IRQF_SHARED;
481 priv->pdev = pdev; 480 priv->pdev = pdev;
482 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug); 481 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
483 spin_lock_init(usbhs_priv_to_lock(priv)); 482 spin_lock_init(usbhs_priv_to_lock(priv));
484 483
485 /* call pipe and module init */ 484 /* call pipe and module init */
486 ret = usbhs_pipe_probe(priv); 485 ret = usbhs_pipe_probe(priv);
487 if (ret < 0) 486 if (ret < 0)
488 goto probe_end_iounmap; 487 return ret;
489 488
490 ret = usbhs_fifo_probe(priv); 489 ret = usbhs_fifo_probe(priv);
491 if (ret < 0) 490 if (ret < 0)
492 goto probe_end_pipe_exit; 491 goto probe_end_pipe_exit;
493 492
494 ret = usbhs_mod_probe(priv); 493 ret = usbhs_mod_probe(priv);
495 if (ret < 0) 494 if (ret < 0)
496 goto probe_end_fifo_exit; 495 goto probe_end_fifo_exit;
497 496
498 /* dev_set_drvdata should be called after usbhs_mod_init */ 497 /* dev_set_drvdata should be called after usbhs_mod_init */
499 dev_set_drvdata(&pdev->dev, priv); 498 dev_set_drvdata(&pdev->dev, priv);
500 499
501 /* 500 /*
502 * deviece reset here because 501 * deviece reset here because
503 * USB device might be used in boot loader. 502 * USB device might be used in boot loader.
504 */ 503 */
505 usbhs_sys_clock_ctrl(priv, 0); 504 usbhs_sys_clock_ctrl(priv, 0);
506 505
507 /* 506 /*
508 * platform call 507 * platform call
509 * 508 *
510 * USB phy setup might depend on CPU/Board. 509 * USB phy setup might depend on CPU/Board.
511 * If platform has its callback functions, 510 * If platform has its callback functions,
512 * call it here. 511 * call it here.
513 */ 512 */
514 ret = usbhs_platform_call(priv, hardware_init, pdev); 513 ret = usbhs_platform_call(priv, hardware_init, pdev);
515 if (ret < 0) { 514 if (ret < 0) {
516 dev_err(&pdev->dev, "platform prove failed.\n"); 515 dev_err(&pdev->dev, "platform prove failed.\n");
517 goto probe_end_mod_exit; 516 goto probe_end_mod_exit;
518 } 517 }
519 518
520 /* reset phy for connection */ 519 /* reset phy for connection */
521 usbhs_platform_call(priv, phy_reset, pdev); 520 usbhs_platform_call(priv, phy_reset, pdev);
522 521
523 /* power control */ 522 /* power control */
524 pm_runtime_enable(&pdev->dev); 523 pm_runtime_enable(&pdev->dev);
525 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { 524 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
526 usbhsc_power_ctrl(priv, 1); 525 usbhsc_power_ctrl(priv, 1);
527 usbhs_mod_autonomy_mode(priv); 526 usbhs_mod_autonomy_mode(priv);
528 } 527 }
529 528
530 /* 529 /*
531 * manual call notify_hotplug for cold plug 530 * manual call notify_hotplug for cold plug
532 */ 531 */
533 ret = usbhsc_drvcllbck_notify_hotplug(pdev); 532 ret = usbhsc_drvcllbck_notify_hotplug(pdev);
534 if (ret < 0) 533 if (ret < 0)
535 goto probe_end_call_remove; 534 goto probe_end_call_remove;
536 535
537 dev_info(&pdev->dev, "probed\n"); 536 dev_info(&pdev->dev, "probed\n");
538 537
539 return ret; 538 return ret;
540 539
541 probe_end_call_remove: 540 probe_end_call_remove:
542 usbhs_platform_call(priv, hardware_exit, pdev); 541 usbhs_platform_call(priv, hardware_exit, pdev);
543 probe_end_mod_exit: 542 probe_end_mod_exit:
544 usbhs_mod_remove(priv); 543 usbhs_mod_remove(priv);
545 probe_end_fifo_exit: 544 probe_end_fifo_exit:
546 usbhs_fifo_remove(priv); 545 usbhs_fifo_remove(priv);
547 probe_end_pipe_exit: 546 probe_end_pipe_exit:
548 usbhs_pipe_remove(priv); 547 usbhs_pipe_remove(priv);
549 probe_end_iounmap:
550 iounmap(priv->base);
551 probe_end_kfree:
552 kfree(priv);
553 548
554 dev_info(&pdev->dev, "probe failed\n"); 549 dev_info(&pdev->dev, "probe failed\n");
555 550
556 return ret; 551 return ret;
557 } 552 }
558 553
559 static int __devexit usbhs_remove(struct platform_device *pdev) 554 static int __devexit usbhs_remove(struct platform_device *pdev)
560 { 555 {
561 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 556 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
562 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data; 557 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
563 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback; 558 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
564 559
565 dev_dbg(&pdev->dev, "usb remove\n"); 560 dev_dbg(&pdev->dev, "usb remove\n");
566 561
567 dfunc->notify_hotplug = NULL; 562 dfunc->notify_hotplug = NULL;
568 563
569 /* power off */ 564 /* power off */
570 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 565 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
571 usbhsc_power_ctrl(priv, 0); 566 usbhsc_power_ctrl(priv, 0);
572 567
573 pm_runtime_disable(&pdev->dev); 568 pm_runtime_disable(&pdev->dev);
574 569
575 usbhs_platform_call(priv, hardware_exit, pdev); 570 usbhs_platform_call(priv, hardware_exit, pdev);
576 usbhs_mod_remove(priv); 571 usbhs_mod_remove(priv);
577 usbhs_fifo_remove(priv); 572 usbhs_fifo_remove(priv);
578 usbhs_pipe_remove(priv); 573 usbhs_pipe_remove(priv);
579 iounmap(priv->base);
580 kfree(priv);
581 574
582 return 0; 575 return 0;
583 } 576 }
584 577
585 static int usbhsc_suspend(struct device *dev) 578 static int usbhsc_suspend(struct device *dev)
586 { 579 {
587 struct usbhs_priv *priv = dev_get_drvdata(dev); 580 struct usbhs_priv *priv = dev_get_drvdata(dev);
588 struct usbhs_mod *mod = usbhs_mod_get_current(priv); 581 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
589 582
590 if (mod) { 583 if (mod) {
591 usbhs_mod_call(priv, stop, priv); 584 usbhs_mod_call(priv, stop, priv);
592 usbhs_mod_change(priv, -1); 585 usbhs_mod_change(priv, -1);
593 } 586 }
594 587
595 if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 588 if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
596 usbhsc_power_ctrl(priv, 0); 589 usbhsc_power_ctrl(priv, 0);
597 590
598 return 0; 591 return 0;
599 } 592 }
600 593
601 static int usbhsc_resume(struct device *dev) 594 static int usbhsc_resume(struct device *dev)
602 { 595 {
603 struct usbhs_priv *priv = dev_get_drvdata(dev); 596 struct usbhs_priv *priv = dev_get_drvdata(dev);
604 struct platform_device *pdev = usbhs_priv_to_pdev(priv); 597 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
605 598
606 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 599 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
607 usbhsc_power_ctrl(priv, 1); 600 usbhsc_power_ctrl(priv, 1);
608 601
609 usbhs_platform_call(priv, phy_reset, pdev); 602 usbhs_platform_call(priv, phy_reset, pdev);
610 603
611 usbhsc_drvcllbck_notify_hotplug(pdev); 604 usbhsc_drvcllbck_notify_hotplug(pdev);
612 605
613 return 0; 606 return 0;
614 } 607 }
615 608
616 static int usbhsc_runtime_nop(struct device *dev) 609 static int usbhsc_runtime_nop(struct device *dev)
617 { 610 {
618 /* Runtime PM callback shared between ->runtime_suspend() 611 /* Runtime PM callback shared between ->runtime_suspend()
619 * and ->runtime_resume(). Simply returns success. 612 * and ->runtime_resume(). Simply returns success.
620 * 613 *
621 * This driver re-initializes all registers after 614 * This driver re-initializes all registers after
622 * pm_runtime_get_sync() anyway so there is no need 615 * pm_runtime_get_sync() anyway so there is no need
623 * to save and restore registers here. 616 * to save and restore registers here.
624 */ 617 */
625 return 0; 618 return 0;
626 } 619 }
627 620
628 static const struct dev_pm_ops usbhsc_pm_ops = { 621 static const struct dev_pm_ops usbhsc_pm_ops = {
629 .suspend = usbhsc_suspend, 622 .suspend = usbhsc_suspend,
630 .resume = usbhsc_resume, 623 .resume = usbhsc_resume,
631 .runtime_suspend = usbhsc_runtime_nop, 624 .runtime_suspend = usbhsc_runtime_nop,
632 .runtime_resume = usbhsc_runtime_nop, 625 .runtime_resume = usbhsc_runtime_nop,
633 }; 626 };
634 627
635 static struct platform_driver renesas_usbhs_driver = { 628 static struct platform_driver renesas_usbhs_driver = {
636 .driver = { 629 .driver = {
637 .name = "renesas_usbhs", 630 .name = "renesas_usbhs",
638 .pm = &usbhsc_pm_ops, 631 .pm = &usbhsc_pm_ops,
639 }, 632 },
640 .probe = usbhs_probe, 633 .probe = usbhs_probe,
641 .remove = __devexit_p(usbhs_remove), 634 .remove = __devexit_p(usbhs_remove),
642 }; 635 };
643 636
644 module_platform_driver(renesas_usbhs_driver); 637 module_platform_driver(renesas_usbhs_driver);
645 638
646 MODULE_LICENSE("GPL"); 639 MODULE_LICENSE("GPL");
647 MODULE_DESCRIPTION("Renesas USB driver"); 640 MODULE_DESCRIPTION("Renesas USB driver");
648 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); 641 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
649 642