1 // SPDX-License-Identifier: GPL-1.0+
5 * Copyright (C) 2011 Renesas Solutions Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
10 #include <linux/gpio.h>
12 #include <linux/module.h>
13 #include <linux/of_device.h>
14 #include <linux/of_gpio.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/reset.h>
17 #include <linux/slab.h>
18 #include <linux/sysfs.h>
25 * image of renesas_usbhs
31 * mod_host.c pipe.c fifo.c
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 * | .... | +-----------+
47 #define USBHSF_RUNTIME_PWCTRL (1 << 0)
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))
58 * renesas usb support platform callback function.
59 * Below macro call it.
60 * if platform doesn't have callback, it return 0 (no error)
62 #define usbhs_platform_call(priv, func, args...)\
63 (!(priv) ? -ENODEV : \
64 !((priv)->pfunc.func) ? 0 : \
65 (priv)->pfunc.func(args))
70 u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
72 return ioread16(priv->base + reg);
75 void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
77 iowrite16(data, priv->base + reg);
80 void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
82 u16 val = usbhs_read(priv, reg);
87 usbhs_write(priv, reg, val);
90 struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
92 return dev_get_drvdata(&pdev->dev);
98 static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
100 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
103 void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
105 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
106 u16 val = DCFM | DRPD | HSE | USBE;
107 int has_otg = usbhs_get_dparam(priv, has_otg);
110 usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN));
116 * - D+ Line/D- Line Pull-down
118 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
121 void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
123 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
124 u16 val = HSE | USBE;
129 * - select Function mode
130 * - D+ Line Pull-up is disabled
131 * When D+ Line Pull-up is enabled,
132 * calling usbhs_sys_function_pullup(,1)
134 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
137 void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable)
139 usbhs_bset(priv, SYSCFG, DPRPU, enable ? DPRPU : 0);
142 void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode)
144 usbhs_write(priv, TESTMODE, mode);
150 int usbhs_frame_get_num(struct usbhs_priv *priv)
152 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
156 * usb request functions
158 void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
162 val = usbhs_read(priv, USBREQ);
163 req->bRequest = (val >> 8) & 0xFF;
164 req->bRequestType = (val >> 0) & 0xFF;
166 req->wValue = usbhs_read(priv, USBVAL);
167 req->wIndex = usbhs_read(priv, USBINDX);
168 req->wLength = usbhs_read(priv, USBLENG);
171 void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
173 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
174 usbhs_write(priv, USBVAL, req->wValue);
175 usbhs_write(priv, USBINDX, req->wIndex);
176 usbhs_write(priv, USBLENG, req->wLength);
178 usbhs_bset(priv, DCPCTR, SUREQ, SUREQ);
184 void usbhs_bus_send_sof_enable(struct usbhs_priv *priv)
186 u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT);
188 if (status != USBRST) {
189 struct device *dev = usbhs_priv_to_dev(priv);
190 dev_err(dev, "usbhs should be reset\n");
193 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT);
196 void usbhs_bus_send_reset(struct usbhs_priv *priv)
198 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST);
201 int usbhs_bus_get_speed(struct usbhs_priv *priv)
203 u16 dvstctr = usbhs_read(priv, DVSTCTR);
205 switch (RHST & dvstctr) {
207 return USB_SPEED_LOW;
208 case RHST_FULL_SPEED:
209 return USB_SPEED_FULL;
210 case RHST_HIGH_SPEED:
211 return USB_SPEED_HIGH;
214 return USB_SPEED_UNKNOWN;
217 int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable)
219 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
221 return usbhs_platform_call(priv, set_vbus, pdev, enable);
224 static void usbhsc_bus_init(struct usbhs_priv *priv)
226 usbhs_write(priv, DVSTCTR, 0);
228 usbhs_vbus_ctrl(priv, 0);
232 * device configuration
234 int usbhs_set_device_config(struct usbhs_priv *priv, int devnum,
235 u16 upphub, u16 hubport, u16 speed)
237 struct device *dev = usbhs_priv_to_dev(priv);
239 u32 reg = DEVADD0 + (2 * devnum);
242 dev_err(dev, "cannot set speed to unknown device %d\n", devnum);
247 dev_err(dev, "unsupported hub number %d\n", upphub);
253 usbspd = USBSPD_SPEED_LOW;
256 usbspd = USBSPD_SPEED_FULL;
259 usbspd = USBSPD_SPEED_HIGH;
262 dev_err(dev, "unsupported speed %d\n", speed);
266 usbhs_write(priv, reg, UPPHUB(upphub) |
274 * interrupt functions
276 void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit)
278 u16 pipe_mask = (u16)GENMASK(usbhs_get_dparam(priv, pipe_size), 0);
280 usbhs_write(priv, sts_reg, ~(1 << bit) & pipe_mask);
286 static void usbhsc_set_buswait(struct usbhs_priv *priv)
288 int wait = usbhs_get_dparam(priv, buswait_bwait);
290 /* set bus wait if platform have */
292 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
295 static bool usbhsc_is_multi_clks(struct usbhs_priv *priv)
297 if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
298 priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL)
304 static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv)
306 if (!usbhsc_is_multi_clks(priv))
309 /* The first clock should exist */
310 priv->clks[0] = of_clk_get(dev->of_node, 0);
311 if (IS_ERR(priv->clks[0]))
312 return PTR_ERR(priv->clks[0]);
315 * To backward compatibility with old DT, this driver checks the return
316 * value if it's -ENOENT or not.
318 priv->clks[1] = of_clk_get(dev->of_node, 1);
319 if (PTR_ERR(priv->clks[1]) == -ENOENT)
320 priv->clks[1] = NULL;
321 else if (IS_ERR(priv->clks[1]))
322 return PTR_ERR(priv->clks[1]);
327 static void usbhsc_clk_put(struct usbhs_priv *priv)
331 if (!usbhsc_is_multi_clks(priv))
334 for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
335 clk_put(priv->clks[i]);
338 static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv)
342 if (!usbhsc_is_multi_clks(priv))
345 for (i = 0; i < ARRAY_SIZE(priv->clks); i++) {
346 ret = clk_prepare_enable(priv->clks[i]);
349 clk_disable_unprepare(priv->clks[i]);
357 static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv)
361 if (!usbhsc_is_multi_clks(priv))
364 for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
365 clk_disable_unprepare(priv->clks[i]);
369 * platform default param
372 /* commonly used on old SH-Mobile SoCs */
373 static struct renesas_usbhs_driver_pipe_config usbhsc_default_pipe[] = {
374 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false),
375 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, false),
376 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x18, false),
377 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x28, true),
378 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x38, true),
379 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true),
380 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false),
381 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false),
382 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false),
383 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x07, false),
386 /* commonly used on newer SH-Mobile and R-Car SoCs */
387 static struct renesas_usbhs_driver_pipe_config usbhsc_new_pipe[] = {
388 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false),
389 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, true),
390 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x28, true),
391 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true),
392 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x58, true),
393 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x68, true),
394 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false),
395 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false),
396 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false),
397 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x78, true),
398 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x88, true),
399 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x98, true),
400 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xa8, true),
401 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xb8, true),
402 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xc8, true),
403 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xd8, true),
409 static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
411 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
412 struct device *dev = usbhs_priv_to_dev(priv);
416 pm_runtime_get_sync(dev);
419 if (usbhsc_clk_prepare_enable(priv))
422 /* enable platform power */
423 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
426 usbhs_sys_clock_ctrl(priv, enable);
429 usbhs_sys_clock_ctrl(priv, enable);
431 /* disable platform power */
432 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
435 usbhsc_clk_disable_unprepare(priv);
438 pm_runtime_put_sync(dev);
445 static void usbhsc_hotplug(struct usbhs_priv *priv)
447 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
448 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
455 * get vbus status from platform
457 enable = usbhs_platform_call(priv, get_vbus, pdev);
460 * get id from platform
462 id = usbhs_platform_call(priv, get_id, pdev);
464 if (enable && !mod) {
466 cable = extcon_get_state(priv->edev, EXTCON_USB_HOST);
467 if ((cable > 0 && id != USBHS_HOST) ||
468 (!cable && id != USBHS_GADGET)) {
470 "USB cable plugged in doesn't match the selected role!\n");
475 ret = usbhs_mod_change(priv, id);
479 dev_dbg(&pdev->dev, "%s enable\n", __func__);
482 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
483 usbhsc_power_ctrl(priv, enable);
486 usbhsc_set_buswait(priv);
487 usbhsc_bus_init(priv);
490 usbhs_mod_call(priv, start, priv);
492 } else if (!enable && mod) {
493 dev_dbg(&pdev->dev, "%s disable\n", __func__);
496 usbhs_mod_call(priv, stop, priv);
499 usbhsc_bus_init(priv);
502 if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
503 usbhsc_power_ctrl(priv, enable);
505 usbhs_mod_change(priv, -1);
507 /* reset phy for next connection */
508 usbhs_platform_call(priv, phy_reset, pdev);
515 static void usbhsc_notify_hotplug(struct work_struct *work)
517 struct usbhs_priv *priv = container_of(work,
519 notify_hotplug_work.work);
520 usbhsc_hotplug(priv);
523 static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
525 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
526 int delay = usbhs_get_dparam(priv, detection_delay);
529 * This functions will be called in interrupt.
530 * To make sure safety context,
531 * use workqueue for usbhs_notify_hotplug
533 schedule_delayed_work(&priv->notify_hotplug_work,
534 msecs_to_jiffies(delay));
541 static const struct of_device_id usbhs_of_match[] = {
543 .compatible = "renesas,usbhs-r8a7790",
544 .data = (void *)USBHS_TYPE_RCAR_GEN2,
547 .compatible = "renesas,usbhs-r8a7791",
548 .data = (void *)USBHS_TYPE_RCAR_GEN2,
551 .compatible = "renesas,usbhs-r8a7794",
552 .data = (void *)USBHS_TYPE_RCAR_GEN2,
555 .compatible = "renesas,usbhs-r8a7795",
556 .data = (void *)USBHS_TYPE_RCAR_GEN3,
559 .compatible = "renesas,usbhs-r8a7796",
560 .data = (void *)USBHS_TYPE_RCAR_GEN3,
563 .compatible = "renesas,usbhs-r8a77990",
564 .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
567 .compatible = "renesas,usbhs-r8a77995",
568 .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
571 .compatible = "renesas,rcar-gen2-usbhs",
572 .data = (void *)USBHS_TYPE_RCAR_GEN2,
575 .compatible = "renesas,rcar-gen3-usbhs",
576 .data = (void *)USBHS_TYPE_RCAR_GEN3,
579 .compatible = "renesas,rza1-usbhs",
580 .data = (void *)USBHS_TYPE_RZA1,
584 MODULE_DEVICE_TABLE(of, usbhs_of_match);
586 static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev)
588 struct renesas_usbhs_platform_info *info;
589 struct renesas_usbhs_driver_param *dparam;
593 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
597 dparam = &info->driver_param;
598 dparam->type = (uintptr_t)of_device_get_match_data(dev);
599 if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp))
600 dparam->buswait_bwait = tmp;
601 gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0,
604 dparam->enable_gpio = gpio;
606 if (dparam->type == USBHS_TYPE_RCAR_GEN2 ||
607 dparam->type == USBHS_TYPE_RCAR_GEN3 ||
608 dparam->type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) {
609 dparam->has_usb_dmac = 1;
610 dparam->pipe_configs = usbhsc_new_pipe;
611 dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe);
614 if (dparam->type == USBHS_TYPE_RZA1) {
615 dparam->pipe_configs = usbhsc_new_pipe;
616 dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe);
622 static int usbhs_probe(struct platform_device *pdev)
624 struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev);
625 struct renesas_usbhs_driver_callback *dfunc;
626 struct usbhs_priv *priv;
627 struct resource *res, *irq_res;
630 /* check device node */
631 if (pdev->dev.of_node)
632 info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev);
634 /* check platform information */
636 dev_err(&pdev->dev, "no platform information\n");
641 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
643 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
647 /* usb private data */
648 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
652 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
653 priv->base = devm_ioremap_resource(&pdev->dev, res);
654 if (IS_ERR(priv->base))
655 return PTR_ERR(priv->base);
657 if (of_property_read_bool(pdev->dev.of_node, "extcon")) {
658 priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
659 if (IS_ERR(priv->edev))
660 return PTR_ERR(priv->edev);
663 priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
664 if (IS_ERR(priv->rsts))
665 return PTR_ERR(priv->rsts);
671 memcpy(&priv->dparam,
673 sizeof(struct renesas_usbhs_driver_param));
675 switch (priv->dparam.type) {
676 case USBHS_TYPE_RCAR_GEN2:
677 priv->pfunc = usbhs_rcar2_ops;
679 case USBHS_TYPE_RCAR_GEN3:
680 priv->pfunc = usbhs_rcar3_ops;
682 case USBHS_TYPE_RCAR_GEN3_WITH_PLL:
683 priv->pfunc = usbhs_rcar3_with_pll_ops;
685 case USBHS_TYPE_RZA1:
686 priv->pfunc = usbhs_rza1_ops;
689 if (!info->platform_callback.get_id) {
690 dev_err(&pdev->dev, "no platform callbacks");
694 &info->platform_callback,
695 sizeof(struct renesas_usbhs_platform_callback));
699 /* set driver callback functions for platform */
700 dfunc = &info->driver_callback;
701 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
703 /* set default param if platform doesn't have */
704 if (!priv->dparam.pipe_configs) {
705 priv->dparam.pipe_configs = usbhsc_default_pipe;
706 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe);
708 if (!priv->dparam.pio_dma_border)
709 priv->dparam.pio_dma_border = 64; /* 64byte */
712 /* runtime power control ? */
713 if (priv->pfunc.get_vbus)
714 usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
719 priv->irq = irq_res->start;
720 if (irq_res->flags & IORESOURCE_IRQ_SHAREABLE)
721 priv->irqflags = IRQF_SHARED;
723 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
724 spin_lock_init(usbhs_priv_to_lock(priv));
726 /* call pipe and module init */
727 ret = usbhs_pipe_probe(priv);
731 ret = usbhs_fifo_probe(priv);
733 goto probe_end_pipe_exit;
735 ret = usbhs_mod_probe(priv);
737 goto probe_end_fifo_exit;
739 /* dev_set_drvdata should be called after usbhs_mod_init */
740 platform_set_drvdata(pdev, priv);
742 ret = reset_control_deassert(priv->rsts);
746 ret = usbhsc_clk_get(&pdev->dev, priv);
748 goto probe_fail_clks;
751 * deviece reset here because
752 * USB device might be used in boot loader.
754 usbhs_sys_clock_ctrl(priv, 0);
756 /* check GPIO determining if USB function should be enabled */
757 if (priv->dparam.enable_gpio) {
758 gpio_request_one(priv->dparam.enable_gpio, GPIOF_IN, NULL);
759 ret = !gpio_get_value(priv->dparam.enable_gpio);
760 gpio_free(priv->dparam.enable_gpio);
763 "USB function not selected (GPIO %d)\n",
764 priv->dparam.enable_gpio);
766 goto probe_end_mod_exit;
773 * USB phy setup might depend on CPU/Board.
774 * If platform has its callback functions,
777 ret = usbhs_platform_call(priv, hardware_init, pdev);
779 dev_err(&pdev->dev, "platform init failed.\n");
780 goto probe_end_mod_exit;
783 /* reset phy for connection */
784 usbhs_platform_call(priv, phy_reset, pdev);
787 pm_runtime_enable(&pdev->dev);
788 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
789 usbhsc_power_ctrl(priv, 1);
790 usbhs_mod_autonomy_mode(priv);
794 * manual call notify_hotplug for cold plug
796 usbhsc_drvcllbck_notify_hotplug(pdev);
798 dev_info(&pdev->dev, "probed\n");
803 usbhsc_clk_put(priv);
805 reset_control_assert(priv->rsts);
807 usbhs_mod_remove(priv);
809 usbhs_fifo_remove(priv);
811 usbhs_pipe_remove(priv);
813 dev_info(&pdev->dev, "probe failed (%d)\n", ret);
818 static int usbhs_remove(struct platform_device *pdev)
820 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
821 struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev);
822 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
824 dev_dbg(&pdev->dev, "usb remove\n");
826 dfunc->notify_hotplug = NULL;
829 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
830 usbhsc_power_ctrl(priv, 0);
832 pm_runtime_disable(&pdev->dev);
834 usbhs_platform_call(priv, hardware_exit, pdev);
835 usbhsc_clk_put(priv);
836 reset_control_assert(priv->rsts);
837 usbhs_mod_remove(priv);
838 usbhs_fifo_remove(priv);
839 usbhs_pipe_remove(priv);
844 static int usbhsc_suspend(struct device *dev)
846 struct usbhs_priv *priv = dev_get_drvdata(dev);
847 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
850 usbhs_mod_call(priv, stop, priv);
851 usbhs_mod_change(priv, -1);
854 if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
855 usbhsc_power_ctrl(priv, 0);
860 static int usbhsc_resume(struct device *dev)
862 struct usbhs_priv *priv = dev_get_drvdata(dev);
863 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
865 if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
866 usbhsc_power_ctrl(priv, 1);
867 usbhs_mod_autonomy_mode(priv);
870 usbhs_platform_call(priv, phy_reset, pdev);
872 usbhsc_drvcllbck_notify_hotplug(pdev);
877 static int usbhsc_runtime_nop(struct device *dev)
879 /* Runtime PM callback shared between ->runtime_suspend()
880 * and ->runtime_resume(). Simply returns success.
882 * This driver re-initializes all registers after
883 * pm_runtime_get_sync() anyway so there is no need
884 * to save and restore registers here.
889 static const struct dev_pm_ops usbhsc_pm_ops = {
890 .suspend = usbhsc_suspend,
891 .resume = usbhsc_resume,
892 .runtime_suspend = usbhsc_runtime_nop,
893 .runtime_resume = usbhsc_runtime_nop,
896 static struct platform_driver renesas_usbhs_driver = {
898 .name = "renesas_usbhs",
899 .pm = &usbhsc_pm_ops,
900 .of_match_table = of_match_ptr(usbhs_of_match),
902 .probe = usbhs_probe,
903 .remove = usbhs_remove,
906 module_platform_driver(renesas_usbhs_driver);
908 MODULE_LICENSE("GPL");
909 MODULE_DESCRIPTION("Renesas USB driver");
910 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");