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

spi/imx: add device tree probe support

It adds device tree probe support for spi-imx driver.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Cc: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Shawn Guo and committed by
Grant Likely
22a85e4c c2387cb9

+53 -7
+22
Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
··· 1 + * Freescale (Enhanced) Configurable Serial Peripheral Interface 2 + (CSPI/eCSPI) for i.MX 3 + 4 + Required properties: 5 + - compatible : Should be "fsl,<soc>-cspi" or "fsl,<soc>-ecspi" 6 + - reg : Offset and length of the register set for the device 7 + - interrupts : Should contain CSPI/eCSPI interrupt 8 + - fsl,spi-num-chipselects : Contains the number of the chipselect 9 + - cs-gpios : Specifies the gpio pins to be used for chipselects. 10 + 11 + Example: 12 + 13 + ecspi@70010000 { 14 + #address-cells = <1>; 15 + #size-cells = <0>; 16 + compatible = "fsl,imx51-ecspi"; 17 + reg = <0x70010000 0x4000>; 18 + interrupts = <36>; 19 + fsl,spi-num-chipselects = <2>; 20 + cs-gpios = <&gpio3 24 0>, /* GPIO4_24 */ 21 + <&gpio3 25 0>; /* GPIO4_25 */ 22 + };
+31 -7
drivers/spi/spi-imx.c
··· 34 34 #include <linux/spi/spi.h> 35 35 #include <linux/spi/spi_bitbang.h> 36 36 #include <linux/types.h> 37 + #include <linux/of.h> 38 + #include <linux/of_device.h> 39 + #include <linux/of_gpio.h> 37 40 38 41 #include <mach/spi.h> 39 42 ··· 607 604 } 608 605 }; 609 606 607 + static const struct of_device_id spi_imx_dt_ids[] = { 608 + { .compatible = "fsl,imx1-cspi", .data = &imx1_cspi_devtype_data, }, 609 + { .compatible = "fsl,imx21-cspi", .data = &imx21_cspi_devtype_data, }, 610 + { .compatible = "fsl,imx27-cspi", .data = &imx27_cspi_devtype_data, }, 611 + { .compatible = "fsl,imx31-cspi", .data = &imx31_cspi_devtype_data, }, 612 + { .compatible = "fsl,imx35-cspi", .data = &imx35_cspi_devtype_data, }, 613 + { .compatible = "fsl,imx51-ecspi", .data = &imx51_ecspi_devtype_data, }, 614 + { /* sentinel */ } 615 + }; 616 + 610 617 static void spi_imx_chipselect(struct spi_device *spi, int is_active) 611 618 { 612 619 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); ··· 750 737 751 738 static int __devinit spi_imx_probe(struct platform_device *pdev) 752 739 { 753 - struct spi_imx_master *mxc_platform_info; 740 + struct device_node *np = pdev->dev.of_node; 741 + const struct of_device_id *of_id = 742 + of_match_device(spi_imx_dt_ids, &pdev->dev); 743 + struct spi_imx_master *mxc_platform_info = 744 + dev_get_platdata(&pdev->dev); 754 745 struct spi_master *master; 755 746 struct spi_imx_data *spi_imx; 756 747 struct resource *res; 757 748 int i, ret, num_cs; 758 749 759 - mxc_platform_info = dev_get_platdata(&pdev->dev); 760 - if (!mxc_platform_info) { 750 + if (!np && !mxc_platform_info) { 761 751 dev_err(&pdev->dev, "can't get the platform data\n"); 762 752 return -EINVAL; 763 753 } 764 754 765 - num_cs = mxc_platform_info->num_chipselect; 755 + ret = of_property_read_u32(np, "fsl,spi-num-chipselects", &num_cs); 756 + if (ret < 0) 757 + num_cs = mxc_platform_info->num_chipselect; 758 + 766 759 master = spi_alloc_master(&pdev->dev, 767 760 sizeof(struct spi_imx_data) + sizeof(int) * num_cs); 768 761 if (!master) ··· 783 764 spi_imx->bitbang.master = spi_master_get(master); 784 765 785 766 for (i = 0; i < master->num_chipselect; i++) { 786 - spi_imx->chipselect[i] = mxc_platform_info->chipselect[i]; 787 - if (spi_imx->chipselect[i] < 0) 767 + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); 768 + if (cs_gpio < 0) 769 + cs_gpio = mxc_platform_info->chipselect[i]; 770 + if (cs_gpio < 0) 788 771 continue; 772 + spi_imx->chipselect[i] = cs_gpio; 789 773 ret = gpio_request(spi_imx->chipselect[i], DRIVER_NAME); 790 774 if (ret) { 791 775 while (i > 0) { ··· 810 788 811 789 init_completion(&spi_imx->xfer_done); 812 790 813 - spi_imx->devtype_data = 791 + spi_imx->devtype_data = of_id ? of_id->data : 814 792 (struct spi_imx_devtype_data *) pdev->id_entry->driver_data; 815 793 816 794 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 858 836 859 837 spi_imx->devtype_data->intctrl(spi_imx, 0); 860 838 839 + master->dev.of_node = pdev->dev.of_node; 861 840 ret = spi_bitbang_start(&spi_imx->bitbang); 862 841 if (ret) { 863 842 dev_err(&pdev->dev, "bitbang start failed with %d\n", ret); ··· 921 898 .driver = { 922 899 .name = DRIVER_NAME, 923 900 .owner = THIS_MODULE, 901 + .of_match_table = spi_imx_dt_ids, 924 902 }, 925 903 .id_table = spi_imx_devtype, 926 904 .probe = spi_imx_probe,