| .. | .. |
|---|
| 3 | 3 | * Renesas USB driver |
|---|
| 4 | 4 | * |
|---|
| 5 | 5 | * Copyright (C) 2011 Renesas Solutions Corp. |
|---|
| 6 | + * Copyright (C) 2019 Renesas Electronics Corporation |
|---|
| 6 | 7 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
|---|
| 7 | 8 | */ |
|---|
| 9 | +#include <linux/clk.h> |
|---|
| 8 | 10 | #include <linux/err.h> |
|---|
| 9 | | -#include <linux/gpio.h> |
|---|
| 11 | +#include <linux/gpio/consumer.h> |
|---|
| 10 | 12 | #include <linux/io.h> |
|---|
| 11 | 13 | #include <linux/module.h> |
|---|
| 12 | 14 | #include <linux/of_device.h> |
|---|
| 13 | | -#include <linux/of_gpio.h> |
|---|
| 14 | 15 | #include <linux/pm_runtime.h> |
|---|
| 16 | +#include <linux/reset.h> |
|---|
| 15 | 17 | #include <linux/slab.h> |
|---|
| 16 | 18 | #include <linux/sysfs.h> |
|---|
| 17 | 19 | #include "common.h" |
|---|
| .. | .. |
|---|
| 41 | 43 | * | .... | +-----------+ |
|---|
| 42 | 44 | */ |
|---|
| 43 | 45 | |
|---|
| 44 | | - |
|---|
| 45 | | -#define USBHSF_RUNTIME_PWCTRL (1 << 0) |
|---|
| 46 | | - |
|---|
| 47 | | -/* status */ |
|---|
| 48 | | -#define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0) |
|---|
| 49 | | -#define usbhsc_flags_set(p, b) ((p)->flags |= (b)) |
|---|
| 50 | | -#define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b)) |
|---|
| 51 | | -#define usbhsc_flags_has(p, b) ((p)->flags & (b)) |
|---|
| 52 | | - |
|---|
| 53 | 46 | /* |
|---|
| 54 | 47 | * platform call back |
|---|
| 55 | 48 | * |
|---|
| .. | .. |
|---|
| 59 | 52 | */ |
|---|
| 60 | 53 | #define usbhs_platform_call(priv, func, args...)\ |
|---|
| 61 | 54 | (!(priv) ? -ENODEV : \ |
|---|
| 62 | | - !((priv)->pfunc.func) ? 0 : \ |
|---|
| 63 | | - (priv)->pfunc.func(args)) |
|---|
| 55 | + !((priv)->pfunc->func) ? 0 : \ |
|---|
| 56 | + (priv)->pfunc->func(args)) |
|---|
| 64 | 57 | |
|---|
| 65 | 58 | /* |
|---|
| 66 | 59 | * common functions |
|---|
| .. | .. |
|---|
| 90 | 83 | return dev_get_drvdata(&pdev->dev); |
|---|
| 91 | 84 | } |
|---|
| 92 | 85 | |
|---|
| 86 | +int usbhs_get_id_as_gadget(struct platform_device *pdev) |
|---|
| 87 | +{ |
|---|
| 88 | + return USBHS_GADGET; |
|---|
| 89 | +} |
|---|
| 90 | + |
|---|
| 93 | 91 | /* |
|---|
| 94 | 92 | * syscfg functions |
|---|
| 95 | 93 | */ |
|---|
| .. | .. |
|---|
| 102 | 100 | { |
|---|
| 103 | 101 | u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; |
|---|
| 104 | 102 | u16 val = DCFM | DRPD | HSE | USBE; |
|---|
| 105 | | - int has_otg = usbhs_get_dparam(priv, has_otg); |
|---|
| 106 | | - |
|---|
| 107 | | - if (has_otg) |
|---|
| 108 | | - usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN)); |
|---|
| 109 | 103 | |
|---|
| 110 | 104 | /* |
|---|
| 111 | 105 | * if enable |
|---|
| .. | .. |
|---|
| 120 | 114 | { |
|---|
| 121 | 115 | u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; |
|---|
| 122 | 116 | u16 val = HSE | USBE; |
|---|
| 117 | + |
|---|
| 118 | + /* CNEN bit is required for function operation */ |
|---|
| 119 | + if (usbhs_get_dparam(priv, has_cnen)) { |
|---|
| 120 | + mask |= CNEN; |
|---|
| 121 | + val |= CNEN; |
|---|
| 122 | + } |
|---|
| 123 | 123 | |
|---|
| 124 | 124 | /* |
|---|
| 125 | 125 | * if enable |
|---|
| .. | .. |
|---|
| 161 | 161 | req->bRequest = (val >> 8) & 0xFF; |
|---|
| 162 | 162 | req->bRequestType = (val >> 0) & 0xFF; |
|---|
| 163 | 163 | |
|---|
| 164 | | - req->wValue = usbhs_read(priv, USBVAL); |
|---|
| 165 | | - req->wIndex = usbhs_read(priv, USBINDX); |
|---|
| 166 | | - req->wLength = usbhs_read(priv, USBLENG); |
|---|
| 164 | + req->wValue = cpu_to_le16(usbhs_read(priv, USBVAL)); |
|---|
| 165 | + req->wIndex = cpu_to_le16(usbhs_read(priv, USBINDX)); |
|---|
| 166 | + req->wLength = cpu_to_le16(usbhs_read(priv, USBLENG)); |
|---|
| 167 | 167 | } |
|---|
| 168 | 168 | |
|---|
| 169 | 169 | void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req) |
|---|
| 170 | 170 | { |
|---|
| 171 | 171 | usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType); |
|---|
| 172 | | - usbhs_write(priv, USBVAL, req->wValue); |
|---|
| 173 | | - usbhs_write(priv, USBINDX, req->wIndex); |
|---|
| 174 | | - usbhs_write(priv, USBLENG, req->wLength); |
|---|
| 172 | + usbhs_write(priv, USBVAL, le16_to_cpu(req->wValue)); |
|---|
| 173 | + usbhs_write(priv, USBINDX, le16_to_cpu(req->wIndex)); |
|---|
| 174 | + usbhs_write(priv, USBLENG, le16_to_cpu(req->wLength)); |
|---|
| 175 | 175 | |
|---|
| 176 | 176 | usbhs_bset(priv, DCPCTR, SUREQ, SUREQ); |
|---|
| 177 | 177 | } |
|---|
| .. | .. |
|---|
| 290 | 290 | usbhs_bset(priv, BUSWAIT, 0x000F, wait); |
|---|
| 291 | 291 | } |
|---|
| 292 | 292 | |
|---|
| 293 | +static bool usbhsc_is_multi_clks(struct usbhs_priv *priv) |
|---|
| 294 | +{ |
|---|
| 295 | + return priv->dparam.multi_clks; |
|---|
| 296 | +} |
|---|
| 297 | + |
|---|
| 298 | +static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv) |
|---|
| 299 | +{ |
|---|
| 300 | + if (!usbhsc_is_multi_clks(priv)) |
|---|
| 301 | + return 0; |
|---|
| 302 | + |
|---|
| 303 | + /* The first clock should exist */ |
|---|
| 304 | + priv->clks[0] = of_clk_get(dev_of_node(dev), 0); |
|---|
| 305 | + if (IS_ERR(priv->clks[0])) |
|---|
| 306 | + return PTR_ERR(priv->clks[0]); |
|---|
| 307 | + |
|---|
| 308 | + /* |
|---|
| 309 | + * To backward compatibility with old DT, this driver checks the return |
|---|
| 310 | + * value if it's -ENOENT or not. |
|---|
| 311 | + */ |
|---|
| 312 | + priv->clks[1] = of_clk_get(dev_of_node(dev), 1); |
|---|
| 313 | + if (PTR_ERR(priv->clks[1]) == -ENOENT) |
|---|
| 314 | + priv->clks[1] = NULL; |
|---|
| 315 | + else if (IS_ERR(priv->clks[1])) |
|---|
| 316 | + return PTR_ERR(priv->clks[1]); |
|---|
| 317 | + |
|---|
| 318 | + return 0; |
|---|
| 319 | +} |
|---|
| 320 | + |
|---|
| 321 | +static void usbhsc_clk_put(struct usbhs_priv *priv) |
|---|
| 322 | +{ |
|---|
| 323 | + int i; |
|---|
| 324 | + |
|---|
| 325 | + if (!usbhsc_is_multi_clks(priv)) |
|---|
| 326 | + return; |
|---|
| 327 | + |
|---|
| 328 | + for (i = 0; i < ARRAY_SIZE(priv->clks); i++) |
|---|
| 329 | + clk_put(priv->clks[i]); |
|---|
| 330 | +} |
|---|
| 331 | + |
|---|
| 332 | +static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv) |
|---|
| 333 | +{ |
|---|
| 334 | + int i, ret; |
|---|
| 335 | + |
|---|
| 336 | + if (!usbhsc_is_multi_clks(priv)) |
|---|
| 337 | + return 0; |
|---|
| 338 | + |
|---|
| 339 | + for (i = 0; i < ARRAY_SIZE(priv->clks); i++) { |
|---|
| 340 | + ret = clk_prepare_enable(priv->clks[i]); |
|---|
| 341 | + if (ret) { |
|---|
| 342 | + while (--i >= 0) |
|---|
| 343 | + clk_disable_unprepare(priv->clks[i]); |
|---|
| 344 | + return ret; |
|---|
| 345 | + } |
|---|
| 346 | + } |
|---|
| 347 | + |
|---|
| 348 | + return ret; |
|---|
| 349 | +} |
|---|
| 350 | + |
|---|
| 351 | +static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv) |
|---|
| 352 | +{ |
|---|
| 353 | + int i; |
|---|
| 354 | + |
|---|
| 355 | + if (!usbhsc_is_multi_clks(priv)) |
|---|
| 356 | + return; |
|---|
| 357 | + |
|---|
| 358 | + for (i = 0; i < ARRAY_SIZE(priv->clks); i++) |
|---|
| 359 | + clk_disable_unprepare(priv->clks[i]); |
|---|
| 360 | +} |
|---|
| 361 | + |
|---|
| 293 | 362 | /* |
|---|
| 294 | 363 | * platform default param |
|---|
| 295 | 364 | */ |
|---|
| .. | .. |
|---|
| 340 | 409 | /* enable PM */ |
|---|
| 341 | 410 | pm_runtime_get_sync(dev); |
|---|
| 342 | 411 | |
|---|
| 412 | + /* enable clks */ |
|---|
| 413 | + if (usbhsc_clk_prepare_enable(priv)) |
|---|
| 414 | + return; |
|---|
| 415 | + |
|---|
| 343 | 416 | /* enable platform power */ |
|---|
| 344 | 417 | usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); |
|---|
| 345 | 418 | |
|---|
| .. | .. |
|---|
| 351 | 424 | |
|---|
| 352 | 425 | /* disable platform power */ |
|---|
| 353 | 426 | usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); |
|---|
| 427 | + |
|---|
| 428 | + /* disable clks */ |
|---|
| 429 | + usbhsc_clk_disable_unprepare(priv); |
|---|
| 354 | 430 | |
|---|
| 355 | 431 | /* disable PM */ |
|---|
| 356 | 432 | pm_runtime_put_sync(dev); |
|---|
| .. | .. |
|---|
| 372 | 448 | /* |
|---|
| 373 | 449 | * get vbus status from platform |
|---|
| 374 | 450 | */ |
|---|
| 375 | | - enable = usbhs_platform_call(priv, get_vbus, pdev); |
|---|
| 451 | + enable = usbhs_mod_info_call(priv, get_vbus, pdev); |
|---|
| 376 | 452 | |
|---|
| 377 | 453 | /* |
|---|
| 378 | 454 | * get id from platform |
|---|
| .. | .. |
|---|
| 397 | 473 | dev_dbg(&pdev->dev, "%s enable\n", __func__); |
|---|
| 398 | 474 | |
|---|
| 399 | 475 | /* power on */ |
|---|
| 400 | | - if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) |
|---|
| 476 | + if (usbhs_get_dparam(priv, runtime_pwctrl)) |
|---|
| 401 | 477 | usbhsc_power_ctrl(priv, enable); |
|---|
| 402 | 478 | |
|---|
| 403 | 479 | /* bus init */ |
|---|
| .. | .. |
|---|
| 417 | 493 | usbhsc_bus_init(priv); |
|---|
| 418 | 494 | |
|---|
| 419 | 495 | /* power off */ |
|---|
| 420 | | - if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) |
|---|
| 496 | + if (usbhs_get_dparam(priv, runtime_pwctrl)) |
|---|
| 421 | 497 | usbhsc_power_ctrl(priv, enable); |
|---|
| 422 | 498 | |
|---|
| 423 | 499 | usbhs_mod_change(priv, -1); |
|---|
| .. | .. |
|---|
| 438 | 514 | usbhsc_hotplug(priv); |
|---|
| 439 | 515 | } |
|---|
| 440 | 516 | |
|---|
| 441 | | -static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev) |
|---|
| 517 | +int usbhsc_schedule_notify_hotplug(struct platform_device *pdev) |
|---|
| 442 | 518 | { |
|---|
| 443 | 519 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
|---|
| 444 | 520 | int delay = usbhs_get_dparam(priv, detection_delay); |
|---|
| .. | .. |
|---|
| 459 | 535 | static const struct of_device_id usbhs_of_match[] = { |
|---|
| 460 | 536 | { |
|---|
| 461 | 537 | .compatible = "renesas,usbhs-r8a774c0", |
|---|
| 462 | | - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, |
|---|
| 538 | + .data = &usbhs_rcar_gen3_with_pll_plat_info, |
|---|
| 463 | 539 | }, |
|---|
| 464 | 540 | { |
|---|
| 465 | 541 | .compatible = "renesas,usbhs-r8a7790", |
|---|
| 466 | | - .data = (void *)USBHS_TYPE_RCAR_GEN2, |
|---|
| 542 | + .data = &usbhs_rcar_gen2_plat_info, |
|---|
| 467 | 543 | }, |
|---|
| 468 | 544 | { |
|---|
| 469 | 545 | .compatible = "renesas,usbhs-r8a7791", |
|---|
| 470 | | - .data = (void *)USBHS_TYPE_RCAR_GEN2, |
|---|
| 546 | + .data = &usbhs_rcar_gen2_plat_info, |
|---|
| 471 | 547 | }, |
|---|
| 472 | 548 | { |
|---|
| 473 | 549 | .compatible = "renesas,usbhs-r8a7794", |
|---|
| 474 | | - .data = (void *)USBHS_TYPE_RCAR_GEN2, |
|---|
| 550 | + .data = &usbhs_rcar_gen2_plat_info, |
|---|
| 475 | 551 | }, |
|---|
| 476 | 552 | { |
|---|
| 477 | 553 | .compatible = "renesas,usbhs-r8a7795", |
|---|
| 478 | | - .data = (void *)USBHS_TYPE_RCAR_GEN3, |
|---|
| 554 | + .data = &usbhs_rcar_gen3_plat_info, |
|---|
| 479 | 555 | }, |
|---|
| 480 | 556 | { |
|---|
| 481 | 557 | .compatible = "renesas,usbhs-r8a7796", |
|---|
| 482 | | - .data = (void *)USBHS_TYPE_RCAR_GEN3, |
|---|
| 558 | + .data = &usbhs_rcar_gen3_plat_info, |
|---|
| 559 | + }, |
|---|
| 560 | + { |
|---|
| 561 | + .compatible = "renesas,usbhs-r8a77990", |
|---|
| 562 | + .data = &usbhs_rcar_gen3_with_pll_plat_info, |
|---|
| 483 | 563 | }, |
|---|
| 484 | 564 | { |
|---|
| 485 | 565 | .compatible = "renesas,usbhs-r8a77995", |
|---|
| 486 | | - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, |
|---|
| 566 | + .data = &usbhs_rcar_gen3_with_pll_plat_info, |
|---|
| 487 | 567 | }, |
|---|
| 488 | 568 | { |
|---|
| 489 | 569 | .compatible = "renesas,rcar-gen2-usbhs", |
|---|
| 490 | | - .data = (void *)USBHS_TYPE_RCAR_GEN2, |
|---|
| 570 | + .data = &usbhs_rcar_gen2_plat_info, |
|---|
| 491 | 571 | }, |
|---|
| 492 | 572 | { |
|---|
| 493 | 573 | .compatible = "renesas,rcar-gen3-usbhs", |
|---|
| 494 | | - .data = (void *)USBHS_TYPE_RCAR_GEN3, |
|---|
| 574 | + .data = &usbhs_rcar_gen3_plat_info, |
|---|
| 495 | 575 | }, |
|---|
| 496 | 576 | { |
|---|
| 497 | 577 | .compatible = "renesas,rza1-usbhs", |
|---|
| 498 | | - .data = (void *)USBHS_TYPE_RZA1, |
|---|
| 578 | + .data = &usbhs_rza1_plat_info, |
|---|
| 579 | + }, |
|---|
| 580 | + { |
|---|
| 581 | + .compatible = "renesas,rza2-usbhs", |
|---|
| 582 | + .data = &usbhs_rza2_plat_info, |
|---|
| 499 | 583 | }, |
|---|
| 500 | 584 | { }, |
|---|
| 501 | 585 | }; |
|---|
| 502 | 586 | MODULE_DEVICE_TABLE(of, usbhs_of_match); |
|---|
| 503 | 587 | |
|---|
| 504 | | -static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) |
|---|
| 505 | | -{ |
|---|
| 506 | | - struct renesas_usbhs_platform_info *info; |
|---|
| 507 | | - struct renesas_usbhs_driver_param *dparam; |
|---|
| 508 | | - u32 tmp; |
|---|
| 509 | | - int gpio; |
|---|
| 510 | | - |
|---|
| 511 | | - info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); |
|---|
| 512 | | - if (!info) |
|---|
| 513 | | - return NULL; |
|---|
| 514 | | - |
|---|
| 515 | | - dparam = &info->driver_param; |
|---|
| 516 | | - dparam->type = (uintptr_t)of_device_get_match_data(dev); |
|---|
| 517 | | - if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) |
|---|
| 518 | | - dparam->buswait_bwait = tmp; |
|---|
| 519 | | - gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, |
|---|
| 520 | | - NULL); |
|---|
| 521 | | - if (gpio > 0) |
|---|
| 522 | | - dparam->enable_gpio = gpio; |
|---|
| 523 | | - |
|---|
| 524 | | - if (dparam->type == USBHS_TYPE_RCAR_GEN2 || |
|---|
| 525 | | - dparam->type == USBHS_TYPE_RCAR_GEN3 || |
|---|
| 526 | | - dparam->type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) { |
|---|
| 527 | | - dparam->has_usb_dmac = 1; |
|---|
| 528 | | - dparam->pipe_configs = usbhsc_new_pipe; |
|---|
| 529 | | - dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe); |
|---|
| 530 | | - } |
|---|
| 531 | | - |
|---|
| 532 | | - if (dparam->type == USBHS_TYPE_RZA1) { |
|---|
| 533 | | - dparam->pipe_configs = usbhsc_new_pipe; |
|---|
| 534 | | - dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe); |
|---|
| 535 | | - } |
|---|
| 536 | | - |
|---|
| 537 | | - return info; |
|---|
| 538 | | -} |
|---|
| 539 | | - |
|---|
| 540 | 588 | static int usbhs_probe(struct platform_device *pdev) |
|---|
| 541 | 589 | { |
|---|
| 542 | | - struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev); |
|---|
| 543 | | - struct renesas_usbhs_driver_callback *dfunc; |
|---|
| 590 | + const struct renesas_usbhs_platform_info *info; |
|---|
| 544 | 591 | struct usbhs_priv *priv; |
|---|
| 545 | | - struct resource *res, *irq_res; |
|---|
| 592 | + struct resource *irq_res; |
|---|
| 593 | + struct device *dev = &pdev->dev; |
|---|
| 594 | + struct gpio_desc *gpiod; |
|---|
| 546 | 595 | int ret; |
|---|
| 596 | + u32 tmp; |
|---|
| 547 | 597 | |
|---|
| 548 | 598 | /* check device node */ |
|---|
| 549 | | - if (pdev->dev.of_node) |
|---|
| 550 | | - info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); |
|---|
| 599 | + if (dev_of_node(dev)) |
|---|
| 600 | + info = of_device_get_match_data(dev); |
|---|
| 601 | + else |
|---|
| 602 | + info = renesas_usbhs_get_info(pdev); |
|---|
| 551 | 603 | |
|---|
| 552 | 604 | /* check platform information */ |
|---|
| 553 | 605 | if (!info) { |
|---|
| 554 | | - dev_err(&pdev->dev, "no platform information\n"); |
|---|
| 606 | + dev_err(dev, "no platform information\n"); |
|---|
| 555 | 607 | return -EINVAL; |
|---|
| 556 | 608 | } |
|---|
| 557 | 609 | |
|---|
| 558 | 610 | /* platform data */ |
|---|
| 559 | 611 | irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
|---|
| 560 | 612 | if (!irq_res) { |
|---|
| 561 | | - dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n"); |
|---|
| 613 | + dev_err(dev, "Not enough Renesas USB platform resources.\n"); |
|---|
| 562 | 614 | return -ENODEV; |
|---|
| 563 | 615 | } |
|---|
| 564 | 616 | |
|---|
| 565 | 617 | /* usb private data */ |
|---|
| 566 | | - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 618 | + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 567 | 619 | if (!priv) |
|---|
| 568 | 620 | return -ENOMEM; |
|---|
| 569 | 621 | |
|---|
| 570 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 571 | | - priv->base = devm_ioremap_resource(&pdev->dev, res); |
|---|
| 622 | + priv->base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 572 | 623 | if (IS_ERR(priv->base)) |
|---|
| 573 | 624 | return PTR_ERR(priv->base); |
|---|
| 574 | 625 | |
|---|
| 575 | | - if (of_property_read_bool(pdev->dev.of_node, "extcon")) { |
|---|
| 576 | | - priv->edev = extcon_get_edev_by_phandle(&pdev->dev, 0); |
|---|
| 626 | + if (of_property_read_bool(dev_of_node(dev), "extcon")) { |
|---|
| 627 | + priv->edev = extcon_get_edev_by_phandle(dev, 0); |
|---|
| 577 | 628 | if (IS_ERR(priv->edev)) |
|---|
| 578 | 629 | return PTR_ERR(priv->edev); |
|---|
| 579 | 630 | } |
|---|
| 631 | + |
|---|
| 632 | + priv->rsts = devm_reset_control_array_get_optional_shared(dev); |
|---|
| 633 | + if (IS_ERR(priv->rsts)) |
|---|
| 634 | + return PTR_ERR(priv->rsts); |
|---|
| 580 | 635 | |
|---|
| 581 | 636 | /* |
|---|
| 582 | 637 | * care platform info |
|---|
| 583 | 638 | */ |
|---|
| 584 | 639 | |
|---|
| 585 | | - memcpy(&priv->dparam, |
|---|
| 586 | | - &info->driver_param, |
|---|
| 587 | | - sizeof(struct renesas_usbhs_driver_param)); |
|---|
| 640 | + priv->dparam = info->driver_param; |
|---|
| 588 | 641 | |
|---|
| 589 | | - switch (priv->dparam.type) { |
|---|
| 590 | | - case USBHS_TYPE_RCAR_GEN2: |
|---|
| 591 | | - priv->pfunc = usbhs_rcar2_ops; |
|---|
| 592 | | - break; |
|---|
| 593 | | - case USBHS_TYPE_RCAR_GEN3: |
|---|
| 594 | | - priv->pfunc = usbhs_rcar3_ops; |
|---|
| 595 | | - break; |
|---|
| 596 | | - case USBHS_TYPE_RCAR_GEN3_WITH_PLL: |
|---|
| 597 | | - priv->pfunc = usbhs_rcar3_with_pll_ops; |
|---|
| 598 | | - if (!IS_ERR_OR_NULL(priv->edev)) { |
|---|
| 599 | | - priv->nb.notifier_call = priv->pfunc.notifier; |
|---|
| 600 | | - ret = devm_extcon_register_notifier(&pdev->dev, |
|---|
| 601 | | - priv->edev, |
|---|
| 602 | | - EXTCON_USB_HOST, |
|---|
| 603 | | - &priv->nb); |
|---|
| 604 | | - if (ret < 0) |
|---|
| 605 | | - dev_err(&pdev->dev, "no notifier registered\n"); |
|---|
| 606 | | - } |
|---|
| 607 | | - break; |
|---|
| 608 | | - case USBHS_TYPE_RZA1: |
|---|
| 609 | | - priv->pfunc = usbhs_rza1_ops; |
|---|
| 610 | | - break; |
|---|
| 611 | | - default: |
|---|
| 612 | | - if (!info->platform_callback.get_id) { |
|---|
| 613 | | - dev_err(&pdev->dev, "no platform callbacks"); |
|---|
| 614 | | - return -EINVAL; |
|---|
| 615 | | - } |
|---|
| 616 | | - memcpy(&priv->pfunc, |
|---|
| 617 | | - &info->platform_callback, |
|---|
| 618 | | - sizeof(struct renesas_usbhs_platform_callback)); |
|---|
| 619 | | - break; |
|---|
| 642 | + if (!info->platform_callback.get_id) { |
|---|
| 643 | + dev_err(dev, "no platform callbacks\n"); |
|---|
| 644 | + return -EINVAL; |
|---|
| 620 | 645 | } |
|---|
| 621 | | - |
|---|
| 622 | | - /* set driver callback functions for platform */ |
|---|
| 623 | | - dfunc = &info->driver_callback; |
|---|
| 624 | | - dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug; |
|---|
| 646 | + priv->pfunc = &info->platform_callback; |
|---|
| 625 | 647 | |
|---|
| 626 | 648 | /* set default param if platform doesn't have */ |
|---|
| 627 | | - if (!priv->dparam.pipe_configs) { |
|---|
| 649 | + if (usbhs_get_dparam(priv, has_new_pipe_configs)) { |
|---|
| 650 | + priv->dparam.pipe_configs = usbhsc_new_pipe; |
|---|
| 651 | + priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_new_pipe); |
|---|
| 652 | + } else if (!priv->dparam.pipe_configs) { |
|---|
| 628 | 653 | priv->dparam.pipe_configs = usbhsc_default_pipe; |
|---|
| 629 | 654 | priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe); |
|---|
| 630 | 655 | } |
|---|
| 631 | 656 | if (!priv->dparam.pio_dma_border) |
|---|
| 632 | 657 | priv->dparam.pio_dma_border = 64; /* 64byte */ |
|---|
| 658 | + if (!of_property_read_u32(dev_of_node(dev), "renesas,buswait", &tmp)) |
|---|
| 659 | + priv->dparam.buswait_bwait = tmp; |
|---|
| 660 | + gpiod = devm_gpiod_get_optional(dev, "renesas,enable", GPIOD_IN); |
|---|
| 661 | + if (IS_ERR(gpiod)) |
|---|
| 662 | + return PTR_ERR(gpiod); |
|---|
| 633 | 663 | |
|---|
| 634 | 664 | /* FIXME */ |
|---|
| 635 | 665 | /* runtime power control ? */ |
|---|
| 636 | | - if (priv->pfunc.get_vbus) |
|---|
| 637 | | - usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL); |
|---|
| 666 | + if (priv->pfunc->get_vbus) |
|---|
| 667 | + usbhs_get_dparam(priv, runtime_pwctrl) = 1; |
|---|
| 638 | 668 | |
|---|
| 639 | 669 | /* |
|---|
| 640 | 670 | * priv settings |
|---|
| .. | .. |
|---|
| 662 | 692 | /* dev_set_drvdata should be called after usbhs_mod_init */ |
|---|
| 663 | 693 | platform_set_drvdata(pdev, priv); |
|---|
| 664 | 694 | |
|---|
| 695 | + ret = reset_control_deassert(priv->rsts); |
|---|
| 696 | + if (ret) |
|---|
| 697 | + goto probe_fail_rst; |
|---|
| 698 | + |
|---|
| 699 | + ret = usbhsc_clk_get(dev, priv); |
|---|
| 700 | + if (ret) |
|---|
| 701 | + goto probe_fail_clks; |
|---|
| 702 | + |
|---|
| 665 | 703 | /* |
|---|
| 666 | 704 | * deviece reset here because |
|---|
| 667 | 705 | * USB device might be used in boot loader. |
|---|
| .. | .. |
|---|
| 669 | 707 | usbhs_sys_clock_ctrl(priv, 0); |
|---|
| 670 | 708 | |
|---|
| 671 | 709 | /* check GPIO determining if USB function should be enabled */ |
|---|
| 672 | | - if (priv->dparam.enable_gpio) { |
|---|
| 673 | | - gpio_request_one(priv->dparam.enable_gpio, GPIOF_IN, NULL); |
|---|
| 674 | | - ret = !gpio_get_value(priv->dparam.enable_gpio); |
|---|
| 675 | | - gpio_free(priv->dparam.enable_gpio); |
|---|
| 710 | + if (gpiod) { |
|---|
| 711 | + ret = !gpiod_get_value(gpiod); |
|---|
| 676 | 712 | if (ret) { |
|---|
| 677 | | - dev_warn(&pdev->dev, |
|---|
| 678 | | - "USB function not selected (GPIO %d)\n", |
|---|
| 679 | | - priv->dparam.enable_gpio); |
|---|
| 713 | + dev_warn(dev, "USB function not selected (GPIO)\n"); |
|---|
| 680 | 714 | ret = -ENOTSUPP; |
|---|
| 681 | 715 | goto probe_end_mod_exit; |
|---|
| 682 | 716 | } |
|---|
| .. | .. |
|---|
| 691 | 725 | */ |
|---|
| 692 | 726 | ret = usbhs_platform_call(priv, hardware_init, pdev); |
|---|
| 693 | 727 | if (ret < 0) { |
|---|
| 694 | | - dev_err(&pdev->dev, "platform init failed.\n"); |
|---|
| 728 | + dev_err(dev, "platform init failed.\n"); |
|---|
| 695 | 729 | goto probe_end_mod_exit; |
|---|
| 696 | 730 | } |
|---|
| 697 | 731 | |
|---|
| .. | .. |
|---|
| 699 | 733 | usbhs_platform_call(priv, phy_reset, pdev); |
|---|
| 700 | 734 | |
|---|
| 701 | 735 | /* power control */ |
|---|
| 702 | | - pm_runtime_enable(&pdev->dev); |
|---|
| 703 | | - if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { |
|---|
| 736 | + pm_runtime_enable(dev); |
|---|
| 737 | + if (!usbhs_get_dparam(priv, runtime_pwctrl)) { |
|---|
| 704 | 738 | usbhsc_power_ctrl(priv, 1); |
|---|
| 705 | 739 | usbhs_mod_autonomy_mode(priv); |
|---|
| 740 | + } else { |
|---|
| 741 | + usbhs_mod_non_autonomy_mode(priv); |
|---|
| 706 | 742 | } |
|---|
| 707 | 743 | |
|---|
| 708 | 744 | /* |
|---|
| 709 | 745 | * manual call notify_hotplug for cold plug |
|---|
| 710 | 746 | */ |
|---|
| 711 | | - usbhsc_drvcllbck_notify_hotplug(pdev); |
|---|
| 747 | + usbhsc_schedule_notify_hotplug(pdev); |
|---|
| 712 | 748 | |
|---|
| 713 | | - dev_info(&pdev->dev, "probed\n"); |
|---|
| 749 | + dev_info(dev, "probed\n"); |
|---|
| 714 | 750 | |
|---|
| 715 | 751 | return ret; |
|---|
| 716 | 752 | |
|---|
| 717 | 753 | probe_end_mod_exit: |
|---|
| 754 | + usbhsc_clk_put(priv); |
|---|
| 755 | +probe_fail_clks: |
|---|
| 756 | + reset_control_assert(priv->rsts); |
|---|
| 757 | +probe_fail_rst: |
|---|
| 718 | 758 | usbhs_mod_remove(priv); |
|---|
| 719 | 759 | probe_end_fifo_exit: |
|---|
| 720 | 760 | usbhs_fifo_remove(priv); |
|---|
| 721 | 761 | probe_end_pipe_exit: |
|---|
| 722 | 762 | usbhs_pipe_remove(priv); |
|---|
| 723 | 763 | |
|---|
| 724 | | - dev_info(&pdev->dev, "probe failed (%d)\n", ret); |
|---|
| 764 | + dev_info(dev, "probe failed (%d)\n", ret); |
|---|
| 725 | 765 | |
|---|
| 726 | 766 | return ret; |
|---|
| 727 | 767 | } |
|---|
| .. | .. |
|---|
| 729 | 769 | static int usbhs_remove(struct platform_device *pdev) |
|---|
| 730 | 770 | { |
|---|
| 731 | 771 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
|---|
| 732 | | - struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev); |
|---|
| 733 | | - struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback; |
|---|
| 734 | 772 | |
|---|
| 735 | 773 | dev_dbg(&pdev->dev, "usb remove\n"); |
|---|
| 736 | 774 | |
|---|
| 737 | | - dfunc->notify_hotplug = NULL; |
|---|
| 738 | | - |
|---|
| 739 | 775 | /* power off */ |
|---|
| 740 | | - if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) |
|---|
| 776 | + if (!usbhs_get_dparam(priv, runtime_pwctrl)) |
|---|
| 741 | 777 | usbhsc_power_ctrl(priv, 0); |
|---|
| 742 | 778 | |
|---|
| 743 | 779 | pm_runtime_disable(&pdev->dev); |
|---|
| 744 | 780 | |
|---|
| 745 | 781 | usbhs_platform_call(priv, hardware_exit, pdev); |
|---|
| 782 | + usbhsc_clk_put(priv); |
|---|
| 783 | + reset_control_assert(priv->rsts); |
|---|
| 746 | 784 | usbhs_mod_remove(priv); |
|---|
| 747 | 785 | usbhs_fifo_remove(priv); |
|---|
| 748 | 786 | usbhs_pipe_remove(priv); |
|---|
| .. | .. |
|---|
| 750 | 788 | return 0; |
|---|
| 751 | 789 | } |
|---|
| 752 | 790 | |
|---|
| 753 | | -static int usbhsc_suspend(struct device *dev) |
|---|
| 791 | +static __maybe_unused int usbhsc_suspend(struct device *dev) |
|---|
| 754 | 792 | { |
|---|
| 755 | 793 | struct usbhs_priv *priv = dev_get_drvdata(dev); |
|---|
| 756 | 794 | struct usbhs_mod *mod = usbhs_mod_get_current(priv); |
|---|
| .. | .. |
|---|
| 760 | 798 | usbhs_mod_change(priv, -1); |
|---|
| 761 | 799 | } |
|---|
| 762 | 800 | |
|---|
| 763 | | - if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) |
|---|
| 801 | + if (mod || !usbhs_get_dparam(priv, runtime_pwctrl)) |
|---|
| 764 | 802 | usbhsc_power_ctrl(priv, 0); |
|---|
| 765 | 803 | |
|---|
| 766 | 804 | return 0; |
|---|
| 767 | 805 | } |
|---|
| 768 | 806 | |
|---|
| 769 | | -static int usbhsc_resume(struct device *dev) |
|---|
| 807 | +static __maybe_unused int usbhsc_resume(struct device *dev) |
|---|
| 770 | 808 | { |
|---|
| 771 | 809 | struct usbhs_priv *priv = dev_get_drvdata(dev); |
|---|
| 772 | 810 | struct platform_device *pdev = usbhs_priv_to_pdev(priv); |
|---|
| 773 | 811 | |
|---|
| 774 | | - if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { |
|---|
| 812 | + if (!usbhs_get_dparam(priv, runtime_pwctrl)) { |
|---|
| 775 | 813 | usbhsc_power_ctrl(priv, 1); |
|---|
| 776 | 814 | usbhs_mod_autonomy_mode(priv); |
|---|
| 777 | 815 | } |
|---|
| 778 | 816 | |
|---|
| 779 | 817 | usbhs_platform_call(priv, phy_reset, pdev); |
|---|
| 780 | 818 | |
|---|
| 781 | | - usbhsc_drvcllbck_notify_hotplug(pdev); |
|---|
| 819 | + usbhsc_schedule_notify_hotplug(pdev); |
|---|
| 782 | 820 | |
|---|
| 783 | 821 | return 0; |
|---|
| 784 | 822 | } |
|---|
| 785 | 823 | |
|---|
| 786 | | -static int usbhsc_runtime_nop(struct device *dev) |
|---|
| 787 | | -{ |
|---|
| 788 | | - /* Runtime PM callback shared between ->runtime_suspend() |
|---|
| 789 | | - * and ->runtime_resume(). Simply returns success. |
|---|
| 790 | | - * |
|---|
| 791 | | - * This driver re-initializes all registers after |
|---|
| 792 | | - * pm_runtime_get_sync() anyway so there is no need |
|---|
| 793 | | - * to save and restore registers here. |
|---|
| 794 | | - */ |
|---|
| 795 | | - return 0; |
|---|
| 796 | | -} |
|---|
| 797 | | - |
|---|
| 798 | | -static const struct dev_pm_ops usbhsc_pm_ops = { |
|---|
| 799 | | - .suspend = usbhsc_suspend, |
|---|
| 800 | | - .resume = usbhsc_resume, |
|---|
| 801 | | - .runtime_suspend = usbhsc_runtime_nop, |
|---|
| 802 | | - .runtime_resume = usbhsc_runtime_nop, |
|---|
| 803 | | -}; |
|---|
| 824 | +static SIMPLE_DEV_PM_OPS(usbhsc_pm_ops, usbhsc_suspend, usbhsc_resume); |
|---|
| 804 | 825 | |
|---|
| 805 | 826 | static struct platform_driver renesas_usbhs_driver = { |
|---|
| 806 | 827 | .driver = { |
|---|