0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/clk.h>
0010 #include <linux/err.h>
0011 #include <linux/gpio/consumer.h>
0012 #include <linux/io.h>
0013 #include <linux/module.h>
0014 #include <linux/of_device.h>
0015 #include <linux/pm_runtime.h>
0016 #include <linux/reset.h>
0017 #include <linux/slab.h>
0018 #include <linux/sysfs.h>
0019 #include "common.h"
0020 #include "rcar2.h"
0021 #include "rcar3.h"
0022 #include "rza.h"
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 #define usbhs_platform_call(priv, func, args...)\
0054 (!(priv) ? -ENODEV : \
0055 !((priv)->pfunc->func) ? 0 : \
0056 (priv)->pfunc->func(args))
0057
0058
0059
0060
0061 u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
0062 {
0063 return ioread16(priv->base + reg);
0064 }
0065
0066 void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
0067 {
0068 iowrite16(data, priv->base + reg);
0069 }
0070
0071 void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
0072 {
0073 u16 val = usbhs_read(priv, reg);
0074
0075 val &= ~mask;
0076 val |= data & mask;
0077
0078 usbhs_write(priv, reg, val);
0079 }
0080
0081 struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
0082 {
0083 return dev_get_drvdata(&pdev->dev);
0084 }
0085
0086 int usbhs_get_id_as_gadget(struct platform_device *pdev)
0087 {
0088 return USBHS_GADGET;
0089 }
0090
0091
0092
0093
0094 static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
0095 {
0096 usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
0097 }
0098
0099 void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
0100 {
0101 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
0102 u16 val = DCFM | DRPD | HSE | USBE;
0103
0104
0105
0106
0107
0108
0109
0110 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
0111 }
0112
0113 void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
0114 {
0115 u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
0116 u16 val = HSE | USBE;
0117
0118
0119 if (usbhs_get_dparam(priv, has_cnen)) {
0120 mask |= CNEN;
0121 val |= CNEN;
0122 }
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
0133 }
0134
0135 void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable)
0136 {
0137 usbhs_bset(priv, SYSCFG, DPRPU, enable ? DPRPU : 0);
0138 }
0139
0140 void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode)
0141 {
0142 usbhs_write(priv, TESTMODE, mode);
0143 }
0144
0145
0146
0147
0148 int usbhs_frame_get_num(struct usbhs_priv *priv)
0149 {
0150 return usbhs_read(priv, FRMNUM) & FRNM_MASK;
0151 }
0152
0153
0154
0155
0156 void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
0157 {
0158 u16 val;
0159
0160 val = usbhs_read(priv, USBREQ);
0161 req->bRequest = (val >> 8) & 0xFF;
0162 req->bRequestType = (val >> 0) & 0xFF;
0163
0164 req->wValue = cpu_to_le16(usbhs_read(priv, USBVAL));
0165 req->wIndex = cpu_to_le16(usbhs_read(priv, USBINDX));
0166 req->wLength = cpu_to_le16(usbhs_read(priv, USBLENG));
0167 }
0168
0169 void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req)
0170 {
0171 usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType);
0172 usbhs_write(priv, USBVAL, le16_to_cpu(req->wValue));
0173 usbhs_write(priv, USBINDX, le16_to_cpu(req->wIndex));
0174 usbhs_write(priv, USBLENG, le16_to_cpu(req->wLength));
0175
0176 usbhs_bset(priv, DCPCTR, SUREQ, SUREQ);
0177 }
0178
0179
0180
0181
0182 void usbhs_bus_send_sof_enable(struct usbhs_priv *priv)
0183 {
0184 u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT);
0185
0186 if (status != USBRST) {
0187 struct device *dev = usbhs_priv_to_dev(priv);
0188 dev_err(dev, "usbhs should be reset\n");
0189 }
0190
0191 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT);
0192 }
0193
0194 void usbhs_bus_send_reset(struct usbhs_priv *priv)
0195 {
0196 usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST);
0197 }
0198
0199 int usbhs_bus_get_speed(struct usbhs_priv *priv)
0200 {
0201 u16 dvstctr = usbhs_read(priv, DVSTCTR);
0202
0203 switch (RHST & dvstctr) {
0204 case RHST_LOW_SPEED:
0205 return USB_SPEED_LOW;
0206 case RHST_FULL_SPEED:
0207 return USB_SPEED_FULL;
0208 case RHST_HIGH_SPEED:
0209 return USB_SPEED_HIGH;
0210 }
0211
0212 return USB_SPEED_UNKNOWN;
0213 }
0214
0215 int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable)
0216 {
0217 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
0218
0219 return usbhs_platform_call(priv, set_vbus, pdev, enable);
0220 }
0221
0222 static void usbhsc_bus_init(struct usbhs_priv *priv)
0223 {
0224 usbhs_write(priv, DVSTCTR, 0);
0225
0226 usbhs_vbus_ctrl(priv, 0);
0227 }
0228
0229
0230
0231
0232 int usbhs_set_device_config(struct usbhs_priv *priv, int devnum,
0233 u16 upphub, u16 hubport, u16 speed)
0234 {
0235 struct device *dev = usbhs_priv_to_dev(priv);
0236 u16 usbspd = 0;
0237 u32 reg = DEVADD0 + (2 * devnum);
0238
0239 if (devnum > 10) {
0240 dev_err(dev, "cannot set speed to unknown device %d\n", devnum);
0241 return -EIO;
0242 }
0243
0244 if (upphub > 0xA) {
0245 dev_err(dev, "unsupported hub number %d\n", upphub);
0246 return -EIO;
0247 }
0248
0249 switch (speed) {
0250 case USB_SPEED_LOW:
0251 usbspd = USBSPD_SPEED_LOW;
0252 break;
0253 case USB_SPEED_FULL:
0254 usbspd = USBSPD_SPEED_FULL;
0255 break;
0256 case USB_SPEED_HIGH:
0257 usbspd = USBSPD_SPEED_HIGH;
0258 break;
0259 default:
0260 dev_err(dev, "unsupported speed %d\n", speed);
0261 return -EIO;
0262 }
0263
0264 usbhs_write(priv, reg, UPPHUB(upphub) |
0265 HUBPORT(hubport)|
0266 USBSPD(usbspd));
0267
0268 return 0;
0269 }
0270
0271
0272
0273
0274 void usbhs_xxxsts_clear(struct usbhs_priv *priv, u16 sts_reg, u16 bit)
0275 {
0276 u16 pipe_mask = (u16)GENMASK(usbhs_get_dparam(priv, pipe_size), 0);
0277
0278 usbhs_write(priv, sts_reg, ~(1 << bit) & pipe_mask);
0279 }
0280
0281
0282
0283
0284 static void usbhsc_set_buswait(struct usbhs_priv *priv)
0285 {
0286 int wait = usbhs_get_dparam(priv, buswait_bwait);
0287
0288
0289 if (wait)
0290 usbhs_bset(priv, BUSWAIT, 0x000F, wait);
0291 }
0292
0293 static bool usbhsc_is_multi_clks(struct usbhs_priv *priv)
0294 {
0295 return priv->dparam.multi_clks;
0296 }
0297
0298 static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv)
0299 {
0300 if (!usbhsc_is_multi_clks(priv))
0301 return 0;
0302
0303
0304 priv->clks[0] = of_clk_get(dev_of_node(dev), 0);
0305 if (IS_ERR(priv->clks[0]))
0306 return PTR_ERR(priv->clks[0]);
0307
0308
0309
0310
0311
0312 priv->clks[1] = of_clk_get(dev_of_node(dev), 1);
0313 if (PTR_ERR(priv->clks[1]) == -ENOENT)
0314 priv->clks[1] = NULL;
0315 else if (IS_ERR(priv->clks[1]))
0316 return PTR_ERR(priv->clks[1]);
0317
0318 return 0;
0319 }
0320
0321 static void usbhsc_clk_put(struct usbhs_priv *priv)
0322 {
0323 int i;
0324
0325 if (!usbhsc_is_multi_clks(priv))
0326 return;
0327
0328 for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
0329 clk_put(priv->clks[i]);
0330 }
0331
0332 static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv)
0333 {
0334 int i, ret;
0335
0336 if (!usbhsc_is_multi_clks(priv))
0337 return 0;
0338
0339 for (i = 0; i < ARRAY_SIZE(priv->clks); i++) {
0340 ret = clk_prepare_enable(priv->clks[i]);
0341 if (ret) {
0342 while (--i >= 0)
0343 clk_disable_unprepare(priv->clks[i]);
0344 return ret;
0345 }
0346 }
0347
0348 return ret;
0349 }
0350
0351 static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv)
0352 {
0353 int i;
0354
0355 if (!usbhsc_is_multi_clks(priv))
0356 return;
0357
0358 for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
0359 clk_disable_unprepare(priv->clks[i]);
0360 }
0361
0362
0363
0364
0365
0366
0367 static struct renesas_usbhs_driver_pipe_config usbhsc_default_pipe[] = {
0368 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false),
0369 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, false),
0370 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x18, false),
0371 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x28, true),
0372 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x38, true),
0373 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true),
0374 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false),
0375 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false),
0376 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false),
0377 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x07, false),
0378 };
0379
0380
0381 static struct renesas_usbhs_driver_pipe_config usbhsc_new_pipe[] = {
0382 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false),
0383 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, true),
0384 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x28, true),
0385 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true),
0386 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x58, true),
0387 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x68, true),
0388 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false),
0389 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false),
0390 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false),
0391 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x78, true),
0392 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x88, true),
0393 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x98, true),
0394 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xa8, true),
0395 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xb8, true),
0396 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xc8, true),
0397 RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xd8, true),
0398 };
0399
0400
0401
0402
0403 static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
0404 {
0405 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
0406 struct device *dev = usbhs_priv_to_dev(priv);
0407
0408 if (enable) {
0409
0410 pm_runtime_get_sync(dev);
0411
0412
0413 if (usbhsc_clk_prepare_enable(priv))
0414 return;
0415
0416
0417 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
0418
0419
0420 usbhs_sys_clock_ctrl(priv, enable);
0421 } else {
0422
0423 usbhs_sys_clock_ctrl(priv, enable);
0424
0425
0426 usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
0427
0428
0429 usbhsc_clk_disable_unprepare(priv);
0430
0431
0432 pm_runtime_put_sync(dev);
0433 }
0434 }
0435
0436
0437
0438
0439 static void usbhsc_hotplug(struct usbhs_priv *priv)
0440 {
0441 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
0442 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
0443 int id;
0444 int enable;
0445 int cable;
0446 int ret;
0447
0448
0449
0450
0451 enable = usbhs_mod_info_call(priv, get_vbus, pdev);
0452
0453
0454
0455
0456 id = usbhs_platform_call(priv, get_id, pdev);
0457
0458 if (enable && !mod) {
0459 if (priv->edev) {
0460 cable = extcon_get_state(priv->edev, EXTCON_USB_HOST);
0461 if ((cable > 0 && id != USBHS_HOST) ||
0462 (!cable && id != USBHS_GADGET)) {
0463 dev_info(&pdev->dev,
0464 "USB cable plugged in doesn't match the selected role!\n");
0465 return;
0466 }
0467 }
0468
0469 ret = usbhs_mod_change(priv, id);
0470 if (ret < 0)
0471 return;
0472
0473 dev_dbg(&pdev->dev, "%s enable\n", __func__);
0474
0475
0476 if (usbhs_get_dparam(priv, runtime_pwctrl))
0477 usbhsc_power_ctrl(priv, enable);
0478
0479
0480 usbhsc_set_buswait(priv);
0481 usbhsc_bus_init(priv);
0482
0483
0484 usbhs_mod_call(priv, start, priv);
0485
0486 } else if (!enable && mod) {
0487 dev_dbg(&pdev->dev, "%s disable\n", __func__);
0488
0489
0490 usbhs_mod_call(priv, stop, priv);
0491
0492
0493 usbhsc_bus_init(priv);
0494
0495
0496 if (usbhs_get_dparam(priv, runtime_pwctrl))
0497 usbhsc_power_ctrl(priv, enable);
0498
0499 usbhs_mod_change(priv, -1);
0500
0501
0502 usbhs_platform_call(priv, phy_reset, pdev);
0503 }
0504 }
0505
0506
0507
0508
0509 static void usbhsc_notify_hotplug(struct work_struct *work)
0510 {
0511 struct usbhs_priv *priv = container_of(work,
0512 struct usbhs_priv,
0513 notify_hotplug_work.work);
0514 usbhsc_hotplug(priv);
0515 }
0516
0517 int usbhsc_schedule_notify_hotplug(struct platform_device *pdev)
0518 {
0519 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
0520 int delay = usbhs_get_dparam(priv, detection_delay);
0521
0522
0523
0524
0525
0526
0527 schedule_delayed_work(&priv->notify_hotplug_work,
0528 msecs_to_jiffies(delay));
0529 return 0;
0530 }
0531
0532
0533
0534
0535 static const struct of_device_id usbhs_of_match[] = {
0536 {
0537 .compatible = "renesas,usbhs-r8a774c0",
0538 .data = &usbhs_rcar_gen3_with_pll_plat_info,
0539 },
0540 {
0541 .compatible = "renesas,usbhs-r8a7790",
0542 .data = &usbhs_rcar_gen2_plat_info,
0543 },
0544 {
0545 .compatible = "renesas,usbhs-r8a7791",
0546 .data = &usbhs_rcar_gen2_plat_info,
0547 },
0548 {
0549 .compatible = "renesas,usbhs-r8a7794",
0550 .data = &usbhs_rcar_gen2_plat_info,
0551 },
0552 {
0553 .compatible = "renesas,usbhs-r8a7795",
0554 .data = &usbhs_rcar_gen3_plat_info,
0555 },
0556 {
0557 .compatible = "renesas,usbhs-r8a7796",
0558 .data = &usbhs_rcar_gen3_plat_info,
0559 },
0560 {
0561 .compatible = "renesas,usbhs-r8a77990",
0562 .data = &usbhs_rcar_gen3_with_pll_plat_info,
0563 },
0564 {
0565 .compatible = "renesas,usbhs-r8a77995",
0566 .data = &usbhs_rcar_gen3_with_pll_plat_info,
0567 },
0568 {
0569 .compatible = "renesas,rcar-gen2-usbhs",
0570 .data = &usbhs_rcar_gen2_plat_info,
0571 },
0572 {
0573 .compatible = "renesas,rcar-gen3-usbhs",
0574 .data = &usbhs_rcar_gen3_plat_info,
0575 },
0576 {
0577 .compatible = "renesas,rza1-usbhs",
0578 .data = &usbhs_rza1_plat_info,
0579 },
0580 {
0581 .compatible = "renesas,rza2-usbhs",
0582 .data = &usbhs_rza2_plat_info,
0583 },
0584 { },
0585 };
0586 MODULE_DEVICE_TABLE(of, usbhs_of_match);
0587
0588 static int usbhs_probe(struct platform_device *pdev)
0589 {
0590 const struct renesas_usbhs_platform_info *info;
0591 struct usbhs_priv *priv;
0592 struct device *dev = &pdev->dev;
0593 struct gpio_desc *gpiod;
0594 int ret;
0595 u32 tmp;
0596 int irq;
0597
0598
0599 if (dev_of_node(dev))
0600 info = of_device_get_match_data(dev);
0601 else
0602 info = renesas_usbhs_get_info(pdev);
0603
0604
0605 if (!info) {
0606 dev_err(dev, "no platform information\n");
0607 return -EINVAL;
0608 }
0609
0610
0611 irq = platform_get_irq(pdev, 0);
0612 if (irq < 0)
0613 return irq;
0614
0615
0616 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0617 if (!priv)
0618 return -ENOMEM;
0619
0620 priv->base = devm_platform_ioremap_resource(pdev, 0);
0621 if (IS_ERR(priv->base))
0622 return PTR_ERR(priv->base);
0623
0624 if (of_property_read_bool(dev_of_node(dev), "extcon")) {
0625 priv->edev = extcon_get_edev_by_phandle(dev, 0);
0626 if (IS_ERR(priv->edev))
0627 return PTR_ERR(priv->edev);
0628 }
0629
0630 priv->rsts = devm_reset_control_array_get_optional_shared(dev);
0631 if (IS_ERR(priv->rsts))
0632 return PTR_ERR(priv->rsts);
0633
0634
0635
0636
0637
0638 priv->dparam = info->driver_param;
0639
0640 if (!info->platform_callback.get_id) {
0641 dev_err(dev, "no platform callbacks\n");
0642 return -EINVAL;
0643 }
0644 priv->pfunc = &info->platform_callback;
0645
0646
0647 if (usbhs_get_dparam(priv, has_new_pipe_configs)) {
0648 priv->dparam.pipe_configs = usbhsc_new_pipe;
0649 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_new_pipe);
0650 } else if (!priv->dparam.pipe_configs) {
0651 priv->dparam.pipe_configs = usbhsc_default_pipe;
0652 priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe);
0653 }
0654 if (!priv->dparam.pio_dma_border)
0655 priv->dparam.pio_dma_border = 64;
0656 if (!of_property_read_u32(dev_of_node(dev), "renesas,buswait", &tmp))
0657 priv->dparam.buswait_bwait = tmp;
0658 gpiod = devm_gpiod_get_optional(dev, "renesas,enable", GPIOD_IN);
0659 if (IS_ERR(gpiod))
0660 return PTR_ERR(gpiod);
0661
0662
0663
0664 if (priv->pfunc->get_vbus)
0665 usbhs_get_dparam(priv, runtime_pwctrl) = 1;
0666
0667
0668
0669
0670 priv->irq = irq;
0671 priv->pdev = pdev;
0672 INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
0673 spin_lock_init(usbhs_priv_to_lock(priv));
0674
0675
0676 ret = usbhs_pipe_probe(priv);
0677 if (ret < 0)
0678 return ret;
0679
0680 ret = usbhs_fifo_probe(priv);
0681 if (ret < 0)
0682 goto probe_end_pipe_exit;
0683
0684 ret = usbhs_mod_probe(priv);
0685 if (ret < 0)
0686 goto probe_end_fifo_exit;
0687
0688
0689 platform_set_drvdata(pdev, priv);
0690
0691 ret = reset_control_deassert(priv->rsts);
0692 if (ret)
0693 goto probe_fail_rst;
0694
0695 ret = usbhsc_clk_get(dev, priv);
0696 if (ret)
0697 goto probe_fail_clks;
0698
0699
0700
0701
0702
0703 usbhs_sys_clock_ctrl(priv, 0);
0704
0705
0706 if (gpiod) {
0707 ret = !gpiod_get_value(gpiod);
0708 if (ret) {
0709 dev_warn(dev, "USB function not selected (GPIO)\n");
0710 ret = -ENOTSUPP;
0711 goto probe_end_mod_exit;
0712 }
0713 }
0714
0715
0716
0717
0718
0719
0720
0721
0722 ret = usbhs_platform_call(priv, hardware_init, pdev);
0723 if (ret < 0) {
0724 dev_err(dev, "platform init failed.\n");
0725 goto probe_end_mod_exit;
0726 }
0727
0728
0729 usbhs_platform_call(priv, phy_reset, pdev);
0730
0731
0732 pm_runtime_enable(dev);
0733 if (!usbhs_get_dparam(priv, runtime_pwctrl)) {
0734 usbhsc_power_ctrl(priv, 1);
0735 usbhs_mod_autonomy_mode(priv);
0736 } else {
0737 usbhs_mod_non_autonomy_mode(priv);
0738 }
0739
0740
0741
0742
0743 usbhsc_schedule_notify_hotplug(pdev);
0744
0745 dev_info(dev, "probed\n");
0746
0747 return ret;
0748
0749 probe_end_mod_exit:
0750 usbhsc_clk_put(priv);
0751 probe_fail_clks:
0752 reset_control_assert(priv->rsts);
0753 probe_fail_rst:
0754 usbhs_mod_remove(priv);
0755 probe_end_fifo_exit:
0756 usbhs_fifo_remove(priv);
0757 probe_end_pipe_exit:
0758 usbhs_pipe_remove(priv);
0759
0760 dev_info(dev, "probe failed (%d)\n", ret);
0761
0762 return ret;
0763 }
0764
0765 static int usbhs_remove(struct platform_device *pdev)
0766 {
0767 struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
0768
0769 dev_dbg(&pdev->dev, "usb remove\n");
0770
0771
0772 if (!usbhs_get_dparam(priv, runtime_pwctrl))
0773 usbhsc_power_ctrl(priv, 0);
0774
0775 pm_runtime_disable(&pdev->dev);
0776
0777 usbhs_platform_call(priv, hardware_exit, pdev);
0778 usbhsc_clk_put(priv);
0779 reset_control_assert(priv->rsts);
0780 usbhs_mod_remove(priv);
0781 usbhs_fifo_remove(priv);
0782 usbhs_pipe_remove(priv);
0783
0784 return 0;
0785 }
0786
0787 static __maybe_unused int usbhsc_suspend(struct device *dev)
0788 {
0789 struct usbhs_priv *priv = dev_get_drvdata(dev);
0790 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
0791
0792 if (mod) {
0793 usbhs_mod_call(priv, stop, priv);
0794 usbhs_mod_change(priv, -1);
0795 }
0796
0797 if (mod || !usbhs_get_dparam(priv, runtime_pwctrl))
0798 usbhsc_power_ctrl(priv, 0);
0799
0800 return 0;
0801 }
0802
0803 static __maybe_unused int usbhsc_resume(struct device *dev)
0804 {
0805 struct usbhs_priv *priv = dev_get_drvdata(dev);
0806 struct platform_device *pdev = usbhs_priv_to_pdev(priv);
0807
0808 if (!usbhs_get_dparam(priv, runtime_pwctrl)) {
0809 usbhsc_power_ctrl(priv, 1);
0810 usbhs_mod_autonomy_mode(priv);
0811 }
0812
0813 usbhs_platform_call(priv, phy_reset, pdev);
0814
0815 usbhsc_schedule_notify_hotplug(pdev);
0816
0817 return 0;
0818 }
0819
0820 static SIMPLE_DEV_PM_OPS(usbhsc_pm_ops, usbhsc_suspend, usbhsc_resume);
0821
0822 static struct platform_driver renesas_usbhs_driver = {
0823 .driver = {
0824 .name = "renesas_usbhs",
0825 .pm = &usbhsc_pm_ops,
0826 .of_match_table = of_match_ptr(usbhs_of_match),
0827 },
0828 .probe = usbhs_probe,
0829 .remove = usbhs_remove,
0830 };
0831
0832 module_platform_driver(renesas_usbhs_driver);
0833
0834 MODULE_LICENSE("GPL");
0835 MODULE_DESCRIPTION("Renesas USB driver");
0836 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");