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

spi/sh-msiof: Add device tree parsing to driver

This adds the capability to retrieve setup data from the device tree
node. The usage of platform data is still available.

Signed-off-by: Bastian Hecht <hechtb+renesas@gmail.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Bastian Hecht and committed by
Grant Likely
cf9c86ef aae7147d

+67 -1
+12
Documentation/devicetree/bindings/spi/sh-msiof.txt
··· 1 + Renesas MSIOF spi controller 2 + 3 + Required properties: 4 + - compatible : "renesas,sh-msiof" for SuperH or 5 + "renesas,sh-mobile-msiof" for SH Mobile series 6 + - reg : Offset and length of the register set for the device 7 + - interrupts : interrupt line used by MSIOF 8 + 9 + Optional properties: 10 + - num-cs : total number of chip-selects 11 + - renesas,tx-fifo-size : Overrides the default tx fifo size given in words 12 + - renesas,rx-fifo-size : Overrides the default rx fifo size given in words
+55 -1
drivers/spi/spi-sh-msiof.c
··· 20 20 #include <linux/io.h> 21 21 #include <linux/kernel.h> 22 22 #include <linux/module.h> 23 + #include <linux/of.h> 23 24 #include <linux/platform_device.h> 24 25 #include <linux/pm_runtime.h> 25 26 ··· 593 592 return 0; 594 593 } 595 594 595 + #ifdef CONFIG_OF 596 + static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) 597 + { 598 + struct sh_msiof_spi_info *info; 599 + struct device_node *np = dev->of_node; 600 + u32 num_cs = 0; 601 + 602 + info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL); 603 + if (!info) { 604 + dev_err(dev, "failed to allocate setup data\n"); 605 + return NULL; 606 + } 607 + 608 + /* Parse the MSIOF properties */ 609 + of_property_read_u32(np, "num-cs", &num_cs); 610 + of_property_read_u32(np, "renesas,tx-fifo-size", 611 + &info->tx_fifo_override); 612 + of_property_read_u32(np, "renesas,rx-fifo-size", 613 + &info->rx_fifo_override); 614 + 615 + info->num_chipselect = num_cs; 616 + 617 + return info; 618 + } 619 + #else 620 + static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) 621 + { 622 + return NULL; 623 + } 624 + #endif 625 + 596 626 static int sh_msiof_spi_probe(struct platform_device *pdev) 597 627 { 598 628 struct resource *r; ··· 642 610 p = spi_master_get_devdata(master); 643 611 644 612 platform_set_drvdata(pdev, p); 645 - p->info = pdev->dev.platform_data; 613 + if (pdev->dev.of_node) 614 + p->info = sh_msiof_spi_parse_dt(&pdev->dev); 615 + else 616 + p->info = pdev->dev.platform_data; 617 + 618 + if (!p->info) { 619 + dev_err(&pdev->dev, "failed to obtain device info\n"); 620 + ret = -ENXIO; 621 + goto err1; 622 + } 623 + 646 624 init_completion(&p->done); 647 625 648 626 p->clk = clk_get(&pdev->dev, NULL); ··· 757 715 return 0; 758 716 } 759 717 718 + #ifdef CONFIG_OF 719 + static const struct of_device_id sh_msiof_match[] = { 720 + { .compatible = "renesas,sh-msiof", }, 721 + { .compatible = "renesas,sh-mobile-msiof", }, 722 + {}, 723 + }; 724 + MODULE_DEVICE_TABLE(of, sh_msiof_match); 725 + #else 726 + #define sh_msiof_match NULL 727 + #endif 728 + 760 729 static struct dev_pm_ops sh_msiof_spi_dev_pm_ops = { 761 730 .runtime_suspend = sh_msiof_spi_runtime_nop, 762 731 .runtime_resume = sh_msiof_spi_runtime_nop, ··· 780 727 .name = "spi_sh_msiof", 781 728 .owner = THIS_MODULE, 782 729 .pm = &sh_msiof_spi_dev_pm_ops, 730 + .of_match_table = sh_msiof_match, 783 731 }, 784 732 }; 785 733 module_platform_driver(sh_msiof_spi_drv);