blob: b4cf555ce58e8cd3fb7617b9f523132d7bbdb256 [file] [log] [blame]
Kuninori Morimotof1407d52011-04-04 13:44:59 +09001/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
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
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/pm_runtime.h>
20#include <linux/slab.h>
21#include <linux/sysfs.h>
22#include "./common.h"
23
Kuninori Morimoto233f5192011-07-07 00:23:24 -070024/*
25 * image of renesas_usbhs
26 *
27 * ex) gadget case
28
29 * mod.c
30 * mod_gadget.c
31 * mod_host.c pipe.c fifo.c
32 *
33 * +-------+ +-----------+
34 * | pipe0 |------>| fifo pio |
35 * +------------+ +-------+ +-----------+
36 * | mod_gadget |=====> | pipe1 |--+
37 * +------------+ +-------+ | +-----------+
38 * | pipe2 | | +-| fifo dma0 |
39 * +------------+ +-------+ | | +-----------+
40 * | mod_host | | pipe3 |<-|--+
41 * +------------+ +-------+ | +-----------+
42 * | .... | +--->| fifo dma1 |
43 * | .... | +-----------+
44 */
45
46
Kuninori Morimotob002ff62011-04-28 16:41:20 +090047#define USBHSF_RUNTIME_PWCTRL (1 << 0)
48
49/* status */
50#define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0)
51#define usbhsc_flags_set(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))
54
Kuninori Morimotof1407d52011-04-04 13:44:59 +090055/*
56 * platform call back
57 *
58 * renesas usb support platform callback function.
59 * Below macro call it.
60 * if platform doesn't have callback, it return 0 (no error)
61 */
62#define usbhs_platform_call(priv, func, args...)\
63 (!(priv) ? -ENODEV : \
Kuninori Morimoto48298202011-10-12 21:02:22 -070064 !((priv)->pfunc.func) ? 0 : \
65 (priv)->pfunc.func(args))
Kuninori Morimotof1407d52011-04-04 13:44:59 +090066
67/*
68 * common functions
69 */
70u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
71{
72 return ioread16(priv->base + reg);
73}
74
75void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
76{
77 iowrite16(data, priv->base + reg);
78}
79
80void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
81{
82 u16 val = usbhs_read(priv, reg);
83
84 val &= ~mask;
85 val |= data & mask;
86
87 usbhs_write(priv, reg, val);
88}
89
Kuninori Morimoto206dcc22011-04-28 16:40:54 +090090struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
91{
92 return dev_get_drvdata(&pdev->dev);
93}
94
Kuninori Morimotof1407d52011-04-04 13:44:59 +090095/*
96 * syscfg functions
97 */
Kuninori Morimoto76190152011-10-23 19:56:41 -070098static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
Kuninori Morimotof1407d52011-04-04 13:44:59 +090099{
100 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
101}
102
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900103void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
104{
Kuninori Morimoto3244a7b2011-10-23 19:56:30 -0700105 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
106 u16 val = DCFM | DRPD | HSE | USBE;
Kuninori Morimotof427eb62011-10-10 22:06:12 -0700107 int has_otg = usbhs_get_dparam(priv, has_otg);
108
109 if (has_otg)
110 usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN));
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900111
112 /*
113 * if enable
114 *
115 * - select Host mode
116 * - D+ Line/D- Line Pull-down
117 */
118 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
119}
120
121void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
122{
Kuninori Morimoto3244a7b2011-10-23 19:56:30 -0700123 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
124 u16 val = DPRPU | HSE | USBE;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900125
126 /*
127 * if enable
128 *
129 * - select Function mode
130 * - D+ Line Pull-up
131 */
132 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
133}
134
135/*
136 * frame functions
137 */
138int usbhs_frame_get_num(struct usbhs_priv *priv)
139{
140 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
141}
142
143/*
Kuninori Morimotoef8bedb2011-10-10 22:02:33 -0700144 * usb request functions
145 */
146void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
147{
148 u16 val;
149
150 val = usbhs_read(priv, USBREQ);
151 req->bRequest = (val >> 8) & 0xFF;
152 req->bRequestType = (val >> 0) & 0xFF;
153
154 req->wValue = usbhs_read(priv, USBVAL);
155 req->wIndex = usbhs_read(priv, USBINDX);
156 req->wLength = usbhs_read(priv, USBLENG);
157}
158
159void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
160{
161 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
162 usbhs_write(priv, USBVAL, req->wValue);
163 usbhs_write(priv, USBINDX, req->wIndex);
164 usbhs_write(priv, USBLENG, req->wLength);
165
166 usbhs_bset(priv, DCPCTR, SUREQ, SUREQ);
167}
168
169/*
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700170 * bus/vbus functions
171 */
172void usbhs_bus_send_sof_enable(struct usbhs_priv *priv)
173{
Kuninori Morimotoa9be4a42011-10-10 22:06:35 -0700174 u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT);
175
176 if (status != USBRST) {
177 struct device *dev = usbhs_priv_to_dev(priv);
178 dev_err(dev, "usbhs should be reset\n");
179 }
180
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700181 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT);
182}
183
184void usbhs_bus_send_reset(struct usbhs_priv *priv)
185{
186 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST);
187}
188
Kuninori Morimoto75587f52011-10-10 22:01:51 -0700189int usbhs_bus_get_speed(struct usbhs_priv *priv)
190{
191 u16 dvstctr = usbhs_read(priv, DVSTCTR);
192
193 switch (RHST & dvstctr) {
194 case RHST_LOW_SPEED:
195 return USB_SPEED_LOW;
196 case RHST_FULL_SPEED:
197 return USB_SPEED_FULL;
198 case RHST_HIGH_SPEED:
199 return USB_SPEED_HIGH;
200 }
201
202 return USB_SPEED_UNKNOWN;
203}
204
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700205int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable)
206{
207 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
208
209 return usbhs_platform_call(priv, set_vbus, pdev, enable);
210}
211
212static void usbhsc_bus_init(struct usbhs_priv *priv)
213{
214 usbhs_write(priv, DVSTCTR, 0);
215
216 usbhs_vbus_ctrl(priv, 0);
217}
218
219/*
Kuninori Morimotoeb051912011-10-10 22:06:46 -0700220 * device configuration
221 */
222int usbhs_set_device_speed(struct usbhs_priv *priv, int devnum,
223 u16 upphub, u16 hubport, u16 speed)
224{
225 struct device *dev = usbhs_priv_to_dev(priv);
226 u16 usbspd = 0;
227 u32 reg = DEVADD0 + (2 * devnum);
228
229 if (devnum > 10) {
230 dev_err(dev, "cannot set speed to unknown device %d\n", devnum);
231 return -EIO;
232 }
233
234 if (upphub > 0xA) {
235 dev_err(dev, "unsupported hub number %d\n", upphub);
236 return -EIO;
237 }
238
239 switch (speed) {
240 case USB_SPEED_LOW:
241 usbspd = USBSPD_SPEED_LOW;
242 break;
243 case USB_SPEED_FULL:
244 usbspd = USBSPD_SPEED_FULL;
245 break;
246 case USB_SPEED_HIGH:
247 usbspd = USBSPD_SPEED_HIGH;
248 break;
249 default:
250 dev_err(dev, "unsupported speed %d\n", speed);
251 return -EIO;
252 }
253
254 usbhs_write(priv, reg, UPPHUB(upphub) |
255 HUBPORT(hubport)|
256 USBSPD(usbspd));
257
258 return 0;
259}
260
261/*
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900262 * local functions
263 */
Kuninori Morimoto11935de2011-10-10 22:01:28 -0700264static void usbhsc_set_buswait(struct usbhs_priv *priv)
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900265{
266 int wait = usbhs_get_dparam(priv, buswait_bwait);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900267
Kuninori Morimoto11935de2011-10-10 22:01:28 -0700268 /* set bus wait if platform have */
269 if (wait)
270 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900271}
272
273/*
274 * platform default param
275 */
276static u32 usbhsc_default_pipe_type[] = {
277 USB_ENDPOINT_XFER_CONTROL,
278 USB_ENDPOINT_XFER_ISOC,
279 USB_ENDPOINT_XFER_ISOC,
280 USB_ENDPOINT_XFER_BULK,
281 USB_ENDPOINT_XFER_BULK,
282 USB_ENDPOINT_XFER_BULK,
283 USB_ENDPOINT_XFER_INT,
284 USB_ENDPOINT_XFER_INT,
285 USB_ENDPOINT_XFER_INT,
286 USB_ENDPOINT_XFER_INT,
287};
288
289/*
Kuninori Morimoto6e267da2011-04-28 16:41:02 +0900290 * power control
291 */
292static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
293{
294 struct device *dev = usbhs_priv_to_dev(priv);
295
296 if (enable) {
297 /* enable PM */
298 pm_runtime_get_sync(dev);
299
300 /* USB on */
301 usbhs_sys_clock_ctrl(priv, enable);
Kuninori Morimoto6e267da2011-04-28 16:41:02 +0900302 } else {
303 /* USB off */
Kuninori Morimoto6e267da2011-04-28 16:41:02 +0900304 usbhs_sys_clock_ctrl(priv, enable);
305
306 /* disable PM */
307 pm_runtime_put_sync(dev);
308 }
309}
310
311/*
Kuninori Morimotoca8a2822011-10-10 21:58:19 -0700312 * hotplug
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900313 */
Kuninori Morimotoca8a2822011-10-10 21:58:19 -0700314static void usbhsc_hotplug(struct usbhs_priv *priv)
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900315{
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900316 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
317 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
318 int id;
319 int enable;
320 int ret;
321
322 /*
323 * get vbus status from platform
324 */
325 enable = usbhs_platform_call(priv, get_vbus, pdev);
326
327 /*
328 * get id from platform
329 */
330 id = usbhs_platform_call(priv, get_id, pdev);
331
332 if (enable && !mod) {
333 ret = usbhs_mod_change(priv, id);
334 if (ret < 0)
335 return;
336
337 dev_dbg(&pdev->dev, "%s enable\n", __func__);
338
Kuninori Morimoto6e267da2011-04-28 16:41:02 +0900339 /* power on */
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900340 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
341 usbhsc_power_ctrl(priv, enable);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900342
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700343 /* bus init */
344 usbhsc_set_buswait(priv);
345 usbhsc_bus_init(priv);
346
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900347 /* module start */
348 usbhs_mod_call(priv, start, priv);
349
350 } else if (!enable && mod) {
351 dev_dbg(&pdev->dev, "%s disable\n", __func__);
352
353 /* module stop */
354 usbhs_mod_call(priv, stop, priv);
355
Kuninori Morimoto258485d2011-10-10 22:01:40 -0700356 /* bus init */
357 usbhsc_bus_init(priv);
358
Kuninori Morimoto6e267da2011-04-28 16:41:02 +0900359 /* power off */
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900360 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
361 usbhsc_power_ctrl(priv, enable);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900362
363 usbhs_mod_change(priv, -1);
364
365 /* reset phy for next connection */
366 usbhs_platform_call(priv, phy_reset, pdev);
367 }
368}
369
Kuninori Morimotoca8a2822011-10-10 21:58:19 -0700370/*
371 * notify hotplug
372 */
373static void usbhsc_notify_hotplug(struct work_struct *work)
374{
375 struct usbhs_priv *priv = container_of(work,
376 struct usbhs_priv,
377 notify_hotplug_work.work);
378 usbhsc_hotplug(priv);
379}
380
Kuninori Morimotobc573812011-04-28 16:41:14 +0900381int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900382{
Kuninori Morimoto206dcc22011-04-28 16:40:54 +0900383 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
Kuninori Morimotobc573812011-04-28 16:41:14 +0900384 int delay = usbhs_get_dparam(priv, detection_delay);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900385
386 /*
387 * This functions will be called in interrupt.
388 * To make sure safety context,
389 * use workqueue for usbhs_notify_hotplug
390 */
Kuninori Morimotoa49a88f2011-10-23 19:57:02 -0700391 schedule_delayed_work(&priv->notify_hotplug_work,
392 msecs_to_jiffies(delay));
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900393 return 0;
394}
395
396/*
397 * platform functions
398 */
Kuninori Morimotob7a8d172011-10-26 19:33:49 -0700399static int usbhs_probe(struct platform_device *pdev)
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900400{
401 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
402 struct renesas_usbhs_driver_callback *dfunc;
403 struct usbhs_priv *priv;
404 struct resource *res;
405 unsigned int irq;
406 int ret;
407
408 /* check platform information */
409 if (!info ||
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900410 !info->platform_callback.get_id) {
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900411 dev_err(&pdev->dev, "no platform information\n");
412 return -EINVAL;
413 }
414
415 /* platform data */
416 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
417 irq = platform_get_irq(pdev, 0);
418 if (!res || (int)irq <= 0) {
419 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
420 return -ENODEV;
421 }
422
423 /* usb private data */
424 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
425 if (!priv) {
426 dev_err(&pdev->dev, "Could not allocate priv\n");
427 return -ENOMEM;
428 }
429
430 priv->base = ioremap_nocache(res->start, resource_size(res));
431 if (!priv->base) {
432 dev_err(&pdev->dev, "ioremap error.\n");
433 ret = -ENOMEM;
434 goto probe_end_kfree;
435 }
436
437 /*
438 * care platform info
439 */
Kuninori Morimoto48298202011-10-12 21:02:22 -0700440 memcpy(&priv->pfunc,
441 &info->platform_callback,
442 sizeof(struct renesas_usbhs_platform_callback));
443 memcpy(&priv->dparam,
444 &info->driver_param,
445 sizeof(struct renesas_usbhs_driver_param));
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900446
447 /* set driver callback functions for platform */
448 dfunc = &info->driver_callback;
449 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
450
451 /* set default param if platform doesn't have */
Kuninori Morimoto48298202011-10-12 21:02:22 -0700452 if (!priv->dparam.pipe_type) {
453 priv->dparam.pipe_type = usbhsc_default_pipe_type;
454 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900455 }
Kuninori Morimoto48298202011-10-12 21:02:22 -0700456 if (!priv->dparam.pio_dma_border)
457 priv->dparam.pio_dma_border = 64; /* 64byte */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900458
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900459 /* FIXME */
460 /* runtime power control ? */
Kuninori Morimoto48298202011-10-12 21:02:22 -0700461 if (priv->pfunc.get_vbus)
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900462 usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
463
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900464 /*
465 * priv settings
466 */
467 priv->irq = irq;
468 priv->pdev = pdev;
Kuninori Morimotobc573812011-04-28 16:41:14 +0900469 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900470 spin_lock_init(usbhs_priv_to_lock(priv));
471
472 /* call pipe and module init */
473 ret = usbhs_pipe_probe(priv);
474 if (ret < 0)
Kuninori Morimoto97f93222011-05-11 16:00:15 +0900475 goto probe_end_iounmap;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900476
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900477 ret = usbhs_fifo_probe(priv);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900478 if (ret < 0)
Kuninori Morimoto97f93222011-05-11 16:00:15 +0900479 goto probe_end_pipe_exit;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900480
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900481 ret = usbhs_mod_probe(priv);
482 if (ret < 0)
483 goto probe_end_fifo_exit;
484
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900485 /* dev_set_drvdata should be called after usbhs_mod_init */
486 dev_set_drvdata(&pdev->dev, priv);
487
488 /*
489 * deviece reset here because
490 * USB device might be used in boot loader.
491 */
492 usbhs_sys_clock_ctrl(priv, 0);
493
494 /*
495 * platform call
496 *
497 * USB phy setup might depend on CPU/Board.
498 * If platform has its callback functions,
499 * call it here.
500 */
501 ret = usbhs_platform_call(priv, hardware_init, pdev);
502 if (ret < 0) {
503 dev_err(&pdev->dev, "platform prove failed.\n");
Kuninori Morimoto97f93222011-05-11 16:00:15 +0900504 goto probe_end_mod_exit;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900505 }
506
507 /* reset phy for connection */
508 usbhs_platform_call(priv, phy_reset, pdev);
509
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900510 /* power control */
511 pm_runtime_enable(&pdev->dev);
512 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
513 usbhsc_power_ctrl(priv, 1);
514 usbhs_mod_autonomy_mode(priv);
515 }
516
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900517 /*
518 * manual call notify_hotplug for cold plug
519 */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900520 ret = usbhsc_drvcllbck_notify_hotplug(pdev);
521 if (ret < 0)
522 goto probe_end_call_remove;
523
524 dev_info(&pdev->dev, "probed\n");
525
526 return ret;
527
528probe_end_call_remove:
529 usbhs_platform_call(priv, hardware_exit, pdev);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900530probe_end_mod_exit:
531 usbhs_mod_remove(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900532probe_end_fifo_exit:
533 usbhs_fifo_remove(priv);
Kuninori Morimoto97f93222011-05-11 16:00:15 +0900534probe_end_pipe_exit:
535 usbhs_pipe_remove(priv);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900536probe_end_iounmap:
537 iounmap(priv->base);
538probe_end_kfree:
539 kfree(priv);
540
541 dev_info(&pdev->dev, "probe failed\n");
542
543 return ret;
544}
545
546static int __devexit usbhs_remove(struct platform_device *pdev)
547{
Kuninori Morimoto206dcc22011-04-28 16:40:54 +0900548 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
Kuninori Morimotoaf32fe52011-04-21 14:10:16 +0900549 struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
550 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900551
552 dev_dbg(&pdev->dev, "usb remove\n");
553
Kuninori Morimotoaf32fe52011-04-21 14:10:16 +0900554 dfunc->notify_hotplug = NULL;
555
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900556 /* power off */
557 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
558 usbhsc_power_ctrl(priv, 0);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900559
Kuninori Morimotob002ff62011-04-28 16:41:20 +0900560 pm_runtime_disable(&pdev->dev);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900561
562 usbhs_platform_call(priv, hardware_exit, pdev);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900563 usbhs_mod_remove(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900564 usbhs_fifo_remove(priv);
Kuninori Morimoto97f93222011-05-11 16:00:15 +0900565 usbhs_pipe_remove(priv);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900566 iounmap(priv->base);
567 kfree(priv);
568
569 return 0;
570}
571
Kuninori Morimotoca8a2822011-10-10 21:58:19 -0700572static int usbhsc_suspend(struct device *dev)
573{
574 struct usbhs_priv *priv = dev_get_drvdata(dev);
575 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
576
577 if (mod) {
578 usbhs_mod_call(priv, stop, priv);
579 usbhs_mod_change(priv, -1);
580 }
581
582 if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
583 usbhsc_power_ctrl(priv, 0);
584
585 return 0;
586}
587
588static int usbhsc_resume(struct device *dev)
589{
590 struct usbhs_priv *priv = dev_get_drvdata(dev);
591 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
592
593 usbhs_platform_call(priv, phy_reset, pdev);
594
595 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
596 usbhsc_power_ctrl(priv, 1);
597
598 usbhsc_hotplug(priv);
599
600 return 0;
601}
602
603static int usbhsc_runtime_nop(struct device *dev)
604{
605 /* Runtime PM callback shared between ->runtime_suspend()
606 * and ->runtime_resume(). Simply returns success.
607 *
608 * This driver re-initializes all registers after
609 * pm_runtime_get_sync() anyway so there is no need
610 * to save and restore registers here.
611 */
612 return 0;
613}
614
615static const struct dev_pm_ops usbhsc_pm_ops = {
616 .suspend = usbhsc_suspend,
617 .resume = usbhsc_resume,
618 .runtime_suspend = usbhsc_runtime_nop,
619 .runtime_resume = usbhsc_runtime_nop,
620};
621
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900622static struct platform_driver renesas_usbhs_driver = {
623 .driver = {
624 .name = "renesas_usbhs",
Kuninori Morimotoca8a2822011-10-10 21:58:19 -0700625 .pm = &usbhsc_pm_ops,
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900626 },
627 .probe = usbhs_probe,
628 .remove = __devexit_p(usbhs_remove),
629};
630
631static int __init usbhs_init(void)
632{
633 return platform_driver_register(&renesas_usbhs_driver);
634}
635
636static void __exit usbhs_exit(void)
637{
638 platform_driver_unregister(&renesas_usbhs_driver);
639}
640
641module_init(usbhs_init);
642module_exit(usbhs_exit);
643
644MODULE_LICENSE("GPL");
645MODULE_DESCRIPTION("Renesas USB driver");
646MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");