Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: renesas_usbhs: Use specific struct instead of USBHS_TYPE_* enums

This patch adds a specific struct "usbhs_of_data" to add a new SoC
data easily instead of code basis in the future.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Yoshihiro Shimoda and committed by
Greg Kroah-Hartman
be21a02a 4e4feeec

+70 -47
+65 -47
drivers/usb/renesas_usbhs/common.c
··· 535 535 return 0; 536 536 } 537 537 538 + static const struct usbhs_of_data rcar_gen2_data = { 539 + .platform_callback = &usbhs_rcar2_ops, 540 + .param = { 541 + .type = USBHS_TYPE_RCAR_GEN2, 542 + .has_usb_dmac = 1, 543 + .pipe_configs = usbhsc_new_pipe, 544 + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), 545 + } 546 + }; 547 + 548 + static const struct usbhs_of_data rcar_gen3_data = { 549 + .platform_callback = &usbhs_rcar3_ops, 550 + .param = { 551 + .type = USBHS_TYPE_RCAR_GEN3, 552 + .has_usb_dmac = 1, 553 + .pipe_configs = usbhsc_new_pipe, 554 + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), 555 + } 556 + }; 557 + 558 + static const struct usbhs_of_data rcar_gen3_with_pll_data = { 559 + .platform_callback = &usbhs_rcar3_with_pll_ops, 560 + .param = { 561 + .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL, 562 + .has_usb_dmac = 1, 563 + .pipe_configs = usbhsc_new_pipe, 564 + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), 565 + } 566 + }; 567 + 568 + static const struct usbhs_of_data rza1_data = { 569 + .platform_callback = &usbhs_rza1_ops, 570 + .param = { 571 + .type = USBHS_TYPE_RZA1, 572 + .pipe_configs = usbhsc_new_pipe, 573 + .pipe_size = ARRAY_SIZE(usbhsc_new_pipe), 574 + } 575 + }; 576 + 538 577 /* 539 578 * platform functions 540 579 */ 541 580 static const struct of_device_id usbhs_of_match[] = { 542 581 { 543 582 .compatible = "renesas,usbhs-r8a774c0", 544 - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, 583 + .data = &rcar_gen3_with_pll_data, 545 584 }, 546 585 { 547 586 .compatible = "renesas,usbhs-r8a7790", 548 - .data = (void *)USBHS_TYPE_RCAR_GEN2, 587 + .data = &rcar_gen2_data, 549 588 }, 550 589 { 551 590 .compatible = "renesas,usbhs-r8a7791", 552 - .data = (void *)USBHS_TYPE_RCAR_GEN2, 591 + .data = &rcar_gen2_data, 553 592 }, 554 593 { 555 594 .compatible = "renesas,usbhs-r8a7794", 556 - .data = (void *)USBHS_TYPE_RCAR_GEN2, 595 + .data = &rcar_gen2_data, 557 596 }, 558 597 { 559 598 .compatible = "renesas,usbhs-r8a7795", 560 - .data = (void *)USBHS_TYPE_RCAR_GEN3, 599 + .data = &rcar_gen3_data, 561 600 }, 562 601 { 563 602 .compatible = "renesas,usbhs-r8a7796", 564 - .data = (void *)USBHS_TYPE_RCAR_GEN3, 603 + .data = &rcar_gen3_data, 565 604 }, 566 605 { 567 606 .compatible = "renesas,usbhs-r8a77990", 568 - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, 607 + .data = &rcar_gen3_with_pll_data, 569 608 }, 570 609 { 571 610 .compatible = "renesas,usbhs-r8a77995", 572 - .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL, 611 + .data = &rcar_gen3_with_pll_data, 573 612 }, 574 613 { 575 614 .compatible = "renesas,rcar-gen2-usbhs", 576 - .data = (void *)USBHS_TYPE_RCAR_GEN2, 615 + .data = &rcar_gen2_data, 577 616 }, 578 617 { 579 618 .compatible = "renesas,rcar-gen3-usbhs", 580 - .data = (void *)USBHS_TYPE_RCAR_GEN3, 619 + .data = &rcar_gen3_data, 581 620 }, 582 621 { 583 622 .compatible = "renesas,rza1-usbhs", 584 - .data = (void *)USBHS_TYPE_RZA1, 623 + .data = &rza1_data, 585 624 }, 586 625 { }, 587 626 }; ··· 630 591 { 631 592 struct renesas_usbhs_platform_info *info; 632 593 struct renesas_usbhs_driver_param *dparam; 594 + const struct usbhs_of_data *data; 633 595 u32 tmp; 634 596 int gpio; 635 597 ··· 638 598 if (!info) 639 599 return NULL; 640 600 601 + data = of_device_get_match_data(dev); 602 + if (!data) 603 + return NULL; 604 + 641 605 dparam = &info->driver_param; 642 - dparam->type = (uintptr_t)of_device_get_match_data(dev); 606 + memcpy(dparam, &data->param, sizeof(data->param)); 607 + memcpy(&info->platform_callback, data->platform_callback, 608 + sizeof(*data->platform_callback)); 609 + 643 610 if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) 644 611 dparam->buswait_bwait = tmp; 645 612 gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, 646 613 NULL); 647 614 if (gpio > 0) 648 615 dparam->enable_gpio = gpio; 649 - 650 - if (dparam->type == USBHS_TYPE_RCAR_GEN2 || 651 - dparam->type == USBHS_TYPE_RCAR_GEN3 || 652 - dparam->type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) { 653 - dparam->has_usb_dmac = 1; 654 - dparam->pipe_configs = usbhsc_new_pipe; 655 - dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe); 656 - } 657 - 658 - if (dparam->type == USBHS_TYPE_RZA1) { 659 - dparam->pipe_configs = usbhsc_new_pipe; 660 - dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe); 661 - } 662 616 663 617 return info; 664 618 } ··· 710 676 &info->driver_param, 711 677 sizeof(struct renesas_usbhs_driver_param)); 712 678 713 - switch (priv->dparam.type) { 714 - case USBHS_TYPE_RCAR_GEN2: 715 - priv->pfunc = usbhs_rcar2_ops; 716 - break; 717 - case USBHS_TYPE_RCAR_GEN3: 718 - priv->pfunc = usbhs_rcar3_ops; 719 - break; 720 - case USBHS_TYPE_RCAR_GEN3_WITH_PLL: 721 - priv->pfunc = usbhs_rcar3_with_pll_ops; 722 - break; 723 - case USBHS_TYPE_RZA1: 724 - priv->pfunc = usbhs_rza1_ops; 725 - break; 726 - default: 727 - if (!info->platform_callback.get_id) { 728 - dev_err(&pdev->dev, "no platform callbacks"); 729 - return -EINVAL; 730 - } 731 - memcpy(&priv->pfunc, 732 - &info->platform_callback, 733 - sizeof(struct renesas_usbhs_platform_callback)); 734 - break; 679 + if (!info->platform_callback.get_id) { 680 + dev_err(&pdev->dev, "no platform callbacks"); 681 + return -EINVAL; 735 682 } 683 + memcpy(&priv->pfunc, 684 + &info->platform_callback, 685 + sizeof(struct renesas_usbhs_platform_callback)); 736 686 737 687 /* set driver callback functions for platform */ 738 688 dfunc = &info->driver_callback;
+5
drivers/usb/renesas_usbhs/common.h
··· 282 282 struct clk *clks[2]; 283 283 }; 284 284 285 + struct usbhs_of_data { 286 + const struct renesas_usbhs_platform_callback *platform_callback; 287 + const struct renesas_usbhs_driver_param param; 288 + }; 289 + 285 290 /* 286 291 * common 287 292 */