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 * | .... | +-----------+
49 * renesas usb support platform callback function.
50 * Below macro call it.
51 * if platform doesn't have callback, it return 0 (no error)
53 #define usbhs_platform_call(priv, func, args...)\
54 (!(priv) ? -ENODEV : \
55 !((priv)->pfunc.func) ? 0 : \
56 (priv)->pfunc.func(args))
61 u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
63 return ioread16(priv->base + reg);
66 void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
68 iowrite16(data, priv->base + reg);
71 void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
73 u16 val = usbhs_read(priv, reg);
78 usbhs_write(priv, reg, val);
81 struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
83 return dev_get_drvdata(&pdev->dev);
89 static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
91 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
94 void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
96 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
97 u16 val = DCFM | DRPD | HSE | USBE;
98 int has_otg = usbhs_get_dparam(priv, has_otg);
101 usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN));
107 * - D+ Line/D- Line Pull-down
109 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
112 void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
114 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
115 u16 val = HSE | USBE;
120 * - select Function mode
121 * - D+ Line Pull-up is disabled
122 * When D+ Line Pull-up is enabled,
123 * calling usbhs_sys_function_pullup(,1)
125 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
128 void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable)
130 usbhs_bset(priv, SYSCFG, DPRPU, enable ? DPRPU : 0);
133 void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode)
135 usbhs_write(priv, TESTMODE, mode);
141 int usbhs_frame_get_num(struct usbhs_priv *priv)
143 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
147 * usb request functions
149 void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
153 val = usbhs_read(priv, USBREQ);
154 req->bRequest = (val >> 8) & 0xFF;
155 req->bRequestType = (val >> 0) & 0xFF;
157 req->wValue = usbhs_read(priv, USBVAL);
158 req->wIndex = usbhs_read(priv, USBINDX);
159 req->wLength = usbhs_read(priv, USBLENG);
162 void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
164 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
165 usbhs_write(priv, USBVAL, req->wValue);
166 usbhs_write(priv, USBINDX, req->wIndex);
167 usbhs_write(priv, USBLENG, req->wLength);
169 usbhs_bset(priv, DCPCTR, SUREQ, SUREQ);
175 void usbhs_bus_send_sof_enable(struct usbhs_priv *priv)
177 u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT);
179 if (status != USBRST) {
180 struct device *dev = usbhs_priv_to_dev(priv);
181 dev_err(dev, "usbhs should be reset\n");
184 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT);
187 void usbhs_bus_send_reset(struct usbhs_priv *priv)
189 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST);
192 int usbhs_bus_get_speed(struct usbhs_priv *priv)
194 u16 dvstctr = usbhs_read(priv, DVSTCTR);
196 switch (RHST & dvstctr) {
198 return USB_SPEED_LOW;
199 case RHST_FULL_SPEED:
200 return USB_SPEED_FULL;
201 case RHST_HIGH_SPEED:
202 return USB_SPEED_HIGH;
205 return USB_SPEED_UNKNOWN;
208 int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable)
210 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
212 return usbhs_platform_call(priv, set_vbus, pdev, enable);
215 static void usbhsc_bus_init(struct usbhs_priv *priv)
217 usbhs_write(priv, DVSTCTR, 0);
219 usbhs_vbus_ctrl(priv, 0);
223 * device configuration
225 int usbhs_set_device_config(struct usbhs_priv *priv, int devnum,
226 u16 upphub, u16 hubport, u16 speed)
228 struct device *dev = usbhs_priv_to_dev(priv);
230 u32 reg = DEVADD0 + (2 * devnum);
233 dev_err(dev, "cannot set speed to unknown device %d\n", devnum);
238 dev_err(dev, "unsupported hub number %d\n", upphub);
244 usbspd = USBSPD_SPEED_LOW;
247 usbspd = USBSPD_SPEED_FULL;
250 usbspd = USBSPD_SPEED_HIGH;
253 dev_err(dev, "unsupported speed %d\n", speed);
257 usbhs_write(priv, reg, UPPHUB(upphub) |
265 * interrupt functions
267 void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit)
269 u16 pipe_mask = (u16)GENMASK(usbhs_get_dparam(priv, pipe_size), 0);
271 usbhs_write(priv, sts_reg, ~(1 << bit) & pipe_mask);
277 static void usbhsc_set_buswait(struct usbhs_priv *priv)
279 int wait = usbhs_get_dparam(priv, buswait_bwait);
281 /* set bus wait if platform have */
283 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
286 static bool usbhsc_is_multi_clks(struct usbhs_priv *priv)
288 if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
289 priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL)
295 static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv)
297 if (!usbhsc_is_multi_clks(priv))
300 /* The first clock should exist */
301 priv->clks[0] = of_clk_get(dev->of_node, 0);
302 if (IS_ERR(priv->clks[0]))
303 return PTR_ERR(priv->clks[0]);
306 * To backward compatibility with old DT, this driver checks the return
307 * value if it's -ENOENT or not.
309 priv->clks[1] = of_clk_get(dev->of_node, 1);
310 if (PTR_ERR(priv->clks[1]) == -ENOENT)
311 priv->clks[1] = NULL;
312 else if (IS_ERR(priv->clks[1]))
313 return PTR_ERR(priv->clks[1]);
318 static void usbhsc_clk_put(struct usbhs_priv *priv)
322 if (!usbhsc_is_multi_clks(priv))
325 for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
326 clk_put(priv->clks[i]);
329 static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv)
333 if (!usbhsc_is_multi_clks(priv))
336 for (i = 0; i < ARRAY_SIZE(priv->clks); i++) {
337 ret = clk_prepare_enable(priv->clks[i]);
340 clk_disable_unprepare(priv->clks[i]);
348 static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv)
352 if (!usbhsc_is_multi_clks(priv))
355 for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
356 clk_disable_unprepare(priv->clks[i]);
360 * platform default param
363 /* commonly used on old SH-Mobile SoCs */
364 static struct renesas_usbhs_driver_pipe_config usbhsc_default_pipe[] = {
365 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false),
366 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, false),
367 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x18, false),
368 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x28, true),
369 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x38, true),
370 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true),
371 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false),
372 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false),
373 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false),
374 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x07, false),
377 /* commonly used on newer SH-Mobile and R-Car SoCs */
378 static struct renesas_usbhs_driver_pipe_config usbhsc_new_pipe[] = {
379 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false),
380 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, true),
381 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x28, true),
382 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true),
383 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x58, true),
384 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x68, true),
385 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false),
386 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false),
387 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false),
388 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x78, true),
389 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x88, true),
390 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x98, true),
391 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xa8, true),
392 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xb8, true),
393 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xc8, true),
394 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xd8, true),
400 static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
402 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
403 struct device *dev = usbhs_priv_to_dev(priv);
407 pm_runtime_get_sync(dev);
410 if (usbhsc_clk_prepare_enable(priv))
413 /* enable platform power */
414 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
417 usbhs_sys_clock_ctrl(priv, enable);
420 usbhs_sys_clock_ctrl(priv, enable);
422 /* disable platform power */
423 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
426 usbhsc_clk_disable_unprepare(priv);
429 pm_runtime_put_sync(dev);
436 static void usbhsc_hotplug(struct usbhs_priv *priv)
438 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
439 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
446 * get vbus status from platform
448 enable = usbhs_platform_call(priv, get_vbus, pdev);
451 * get id from platform
453 id = usbhs_platform_call(priv, get_id, pdev);
455 if (enable && !mod) {
457 cable = extcon_get_state(priv->edev, EXTCON_USB_HOST);
458 if ((cable > 0 && id != USBHS_HOST) ||
459 (!cable && id != USBHS_GADGET)) {
461 "USB cable plugged in doesn't match the selected role!\n");
466 ret = usbhs_mod_change(priv, id);
470 dev_dbg(&pdev->dev, "%s enable\n", __func__);
473 if (usbhs_get_dparam(priv, runtime_pwctrl))
474 usbhsc_power_ctrl(priv, enable);
477 usbhsc_set_buswait(priv);
478 usbhsc_bus_init(priv);
481 usbhs_mod_call(priv, start, priv);
483 } else if (!enable && mod) {
484 dev_dbg(&pdev->dev, "%s disable\n", __func__);
487 usbhs_mod_call(priv, stop, priv);
490 usbhsc_bus_init(priv);
493 if (usbhs_get_dparam(priv, runtime_pwctrl))
494 usbhsc_power_ctrl(priv, enable);
496 usbhs_mod_change(priv, -1);
498 /* reset phy for next connection */
499 usbhs_platform_call(priv, phy_reset, pdev);
506 static void usbhsc_notify_hotplug(struct work_struct *work)
508 struct usbhs_priv *priv = container_of(work,
510 notify_hotplug_work.work);
511 usbhsc_hotplug(priv);
514 static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
516 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
517 int delay = usbhs_get_dparam(priv, detection_delay);
520 * This functions will be called in interrupt.
521 * To make sure safety context,
522 * use workqueue for usbhs_notify_hotplug
524 schedule_delayed_work(&priv->notify_hotplug_work,
525 msecs_to_jiffies(delay));
529 static const struct usbhs_of_data rcar_gen2_data = {
530 .platform_callback = &usbhs_rcar2_ops,
532 .type = USBHS_TYPE_RCAR_GEN2,
534 .pipe_configs = usbhsc_new_pipe,
535 .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
539 static const struct usbhs_of_data rcar_gen3_data = {
540 .platform_callback = &usbhs_rcar3_ops,
542 .type = USBHS_TYPE_RCAR_GEN3,
544 .pipe_configs = usbhsc_new_pipe,
545 .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
549 static const struct usbhs_of_data rcar_gen3_with_pll_data = {
550 .platform_callback = &usbhs_rcar3_with_pll_ops,
552 .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL,
554 .pipe_configs = usbhsc_new_pipe,
555 .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
559 static const struct usbhs_of_data rza1_data = {
560 .platform_callback = &usbhs_rza1_ops,
562 .type = USBHS_TYPE_RZA1,
563 .pipe_configs = usbhsc_new_pipe,
564 .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
571 static const struct of_device_id usbhs_of_match[] = {
573 .compatible = "renesas,usbhs-r8a774c0",
574 .data = &rcar_gen3_with_pll_data,
577 .compatible = "renesas,usbhs-r8a7790",
578 .data = &rcar_gen2_data,
581 .compatible = "renesas,usbhs-r8a7791",
582 .data = &rcar_gen2_data,
585 .compatible = "renesas,usbhs-r8a7794",
586 .data = &rcar_gen2_data,
589 .compatible = "renesas,usbhs-r8a7795",
590 .data = &rcar_gen3_data,
593 .compatible = "renesas,usbhs-r8a7796",
594 .data = &rcar_gen3_data,
597 .compatible = "renesas,usbhs-r8a77990",
598 .data = &rcar_gen3_with_pll_data,
601 .compatible = "renesas,usbhs-r8a77995",
602 .data = &rcar_gen3_with_pll_data,
605 .compatible = "renesas,rcar-gen2-usbhs",
606 .data = &rcar_gen2_data,
609 .compatible = "renesas,rcar-gen3-usbhs",
610 .data = &rcar_gen3_data,
613 .compatible = "renesas,rza1-usbhs",
618 MODULE_DEVICE_TABLE(of, usbhs_of_match);
620 static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev)
622 struct renesas_usbhs_platform_info *info;
623 struct renesas_usbhs_driver_param *dparam;
624 const struct usbhs_of_data *data;
628 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
632 data = of_device_get_match_data(dev);
636 dparam = &info->driver_param;
637 memcpy(dparam, &data->param, sizeof(data->param));
638 memcpy(&info->platform_callback, data->platform_callback,
639 sizeof(*data->platform_callback));
641 if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp))
642 dparam->buswait_bwait = tmp;
643 gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0,
646 dparam->enable_gpio = gpio;
651 static int usbhs_probe(struct platform_device *pdev)
653 struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev);
654 struct renesas_usbhs_driver_callback *dfunc;
655 struct usbhs_priv *priv;
656 struct resource *res, *irq_res;
659 /* check device node */
660 if (pdev->dev.of_node)
661 info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev);
663 /* check platform information */
665 dev_err(&pdev->dev, "no platform information\n");
670 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
672 dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
676 /* usb private data */
677 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
681 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
682 priv->base = devm_ioremap_resource(&pdev->dev, res);
683 if (IS_ERR(priv->base))
684 return PTR_ERR(priv->base);
686 if (of_property_read_bool(pdev->dev.of_node, "extcon")) {
687 priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
688 if (IS_ERR(priv->edev))
689 return PTR_ERR(priv->edev);
692 priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
693 if (IS_ERR(priv->rsts))
694 return PTR_ERR(priv->rsts);
700 memcpy(&priv->dparam,
702 sizeof(struct renesas_usbhs_driver_param));
704 if (!info->platform_callback.get_id) {
705 dev_err(&pdev->dev, "no platform callbacks");
709 &info->platform_callback,
710 sizeof(struct renesas_usbhs_platform_callback));
712 /* set driver callback functions for platform */
713 dfunc = &info->driver_callback;
714 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug;
716 /* set default param if platform doesn't have */
717 if (!priv->dparam.pipe_configs) {
718 priv->dparam.pipe_configs = usbhsc_default_pipe;
719 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe);
721 if (!priv->dparam.pio_dma_border)
722 priv->dparam.pio_dma_border = 64; /* 64byte */
725 /* runtime power control ? */
726 if (priv->pfunc.get_vbus)
727 usbhs_get_dparam(priv, runtime_pwctrl) = 1;
732 priv->irq = irq_res->start;
733 if (irq_res->flags & IORESOURCE_IRQ_SHAREABLE)
734 priv->irqflags = IRQF_SHARED;
736 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
737 spin_lock_init(usbhs_priv_to_lock(priv));
739 /* call pipe and module init */
740 ret = usbhs_pipe_probe(priv);
744 ret = usbhs_fifo_probe(priv);
746 goto probe_end_pipe_exit;
748 ret = usbhs_mod_probe(priv);
750 goto probe_end_fifo_exit;
752 /* dev_set_drvdata should be called after usbhs_mod_init */
753 platform_set_drvdata(pdev, priv);
755 ret = reset_control_deassert(priv->rsts);
759 ret = usbhsc_clk_get(&pdev->dev, priv);
761 goto probe_fail_clks;
764 * deviece reset here because
765 * USB device might be used in boot loader.
767 usbhs_sys_clock_ctrl(priv, 0);
769 /* check GPIO determining if USB function should be enabled */
770 if (priv->dparam.enable_gpio) {
771 gpio_request_one(priv->dparam.enable_gpio, GPIOF_IN, NULL);
772 ret = !gpio_get_value(priv->dparam.enable_gpio);
773 gpio_free(priv->dparam.enable_gpio);
776 "USB function not selected (GPIO %d)\n",
777 priv->dparam.enable_gpio);
779 goto probe_end_mod_exit;
786 * USB phy setup might depend on CPU/Board.
787 * If platform has its callback functions,
790 ret = usbhs_platform_call(priv, hardware_init, pdev);
792 dev_err(&pdev->dev, "platform init failed.\n");
793 goto probe_end_mod_exit;
796 /* reset phy for connection */
797 usbhs_platform_call(priv, phy_reset, pdev);
800 pm_runtime_enable(&pdev->dev);
801 if (!usbhs_get_dparam(priv, runtime_pwctrl)) {
802 usbhsc_power_ctrl(priv, 1);
803 usbhs_mod_autonomy_mode(priv);
807 * manual call notify_hotplug for cold plug
809 usbhsc_drvcllbck_notify_hotplug(pdev);
811 dev_info(&pdev->dev, "probed\n");
816 usbhsc_clk_put(priv);
818 reset_control_assert(priv->rsts);
820 usbhs_mod_remove(priv);
822 usbhs_fifo_remove(priv);
824 usbhs_pipe_remove(priv);
826 dev_info(&pdev->dev, "probe failed (%d)\n", ret);
831 static int usbhs_remove(struct platform_device *pdev)
833 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
834 struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev);
835 struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
837 dev_dbg(&pdev->dev, "usb remove\n");
839 dfunc->notify_hotplug = NULL;
842 if (!usbhs_get_dparam(priv, runtime_pwctrl))
843 usbhsc_power_ctrl(priv, 0);
845 pm_runtime_disable(&pdev->dev);
847 usbhs_platform_call(priv, hardware_exit, pdev);
848 usbhsc_clk_put(priv);
849 reset_control_assert(priv->rsts);
850 usbhs_mod_remove(priv);
851 usbhs_fifo_remove(priv);
852 usbhs_pipe_remove(priv);
857 static __maybe_unused int usbhsc_suspend(struct device *dev)
859 struct usbhs_priv *priv = dev_get_drvdata(dev);
860 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
863 usbhs_mod_call(priv, stop, priv);
864 usbhs_mod_change(priv, -1);
867 if (mod || !usbhs_get_dparam(priv, runtime_pwctrl))
868 usbhsc_power_ctrl(priv, 0);
873 static __maybe_unused int usbhsc_resume(struct device *dev)
875 struct usbhs_priv *priv = dev_get_drvdata(dev);
876 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
878 if (!usbhs_get_dparam(priv, runtime_pwctrl)) {
879 usbhsc_power_ctrl(priv, 1);
880 usbhs_mod_autonomy_mode(priv);
883 usbhs_platform_call(priv, phy_reset, pdev);
885 usbhsc_drvcllbck_notify_hotplug(pdev);
890 static SIMPLE_DEV_PM_OPS(usbhsc_pm_ops, usbhsc_suspend, usbhsc_resume);
892 static struct platform_driver renesas_usbhs_driver = {
894 .name = "renesas_usbhs",
895 .pm = &usbhsc_pm_ops,
896 .of_match_table = of_match_ptr(usbhs_of_match),
898 .probe = usbhs_probe,
899 .remove = usbhs_remove,
902 module_platform_driver(renesas_usbhs_driver);
904 MODULE_LICENSE("GPL");
905 MODULE_DESCRIPTION("Renesas USB driver");
906 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");