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

spi/davinci: add OF support for the spi controller

This adds OF support to DaVinci SPI controller to configure platform
data through device bindings. Also replaces clk_enable() with
of clk_prepare_enable() as well as clk_disable() with
clk_disable_unprepare().

Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Murali Karicheri and committed by
Grant Likely
aae7147d 830379e0

+88 -14
+88 -14
drivers/spi/spi-davinci.c
··· 28 28 #include <linux/dmaengine.h> 29 29 #include <linux/dma-mapping.h> 30 30 #include <linux/edma.h> 31 + #include <linux/of.h> 32 + #include <linux/of_device.h> 31 33 #include <linux/spi/spi.h> 32 34 #include <linux/spi/spi_bitbang.h> 33 35 #include <linux/slab.h> ··· 137 135 int dma_rx_chnum; 138 136 int dma_tx_chnum; 139 137 140 - struct davinci_spi_platform_data *pdata; 138 + struct davinci_spi_platform_data pdata; 141 139 142 140 void (*get_rx)(u32 rx_data, struct davinci_spi *); 143 141 u32 (*get_tx)(struct davinci_spi *); ··· 215 213 bool gpio_chipsel = false; 216 214 217 215 dspi = spi_master_get_devdata(spi->master); 218 - pdata = dspi->pdata; 216 + pdata = &dspi->pdata; 219 217 220 218 if (pdata->chip_sel && chip_sel < pdata->num_chipselect && 221 219 pdata->chip_sel[chip_sel] != SPI_INTERN_CS) ··· 394 392 struct davinci_spi_platform_data *pdata; 395 393 396 394 dspi = spi_master_get_devdata(spi->master); 397 - pdata = dspi->pdata; 395 + pdata = &dspi->pdata; 398 396 399 397 /* if bits per word length is zero then set it default 8 */ 400 398 if (!spi->bits_per_word) ··· 536 534 struct scatterlist sg_rx, sg_tx; 537 535 538 536 dspi = spi_master_get_devdata(spi->master); 539 - pdata = dspi->pdata; 537 + pdata = &dspi->pdata; 540 538 spicfg = (struct davinci_spi_config *)spi->controller_data; 541 539 if (!spicfg) 542 540 spicfg = &davinci_spi_default_cfg; ··· 760 758 return r; 761 759 } 762 760 761 + #if defined(CONFIG_OF) 762 + static const struct of_device_id davinci_spi_of_match[] = { 763 + { 764 + .compatible = "ti,dm644x-spi", 765 + }, 766 + { 767 + .compatible = "ti,da8xx-spi", 768 + .data = (void *)SPI_VERSION_2, 769 + }, 770 + { }, 771 + }; 772 + MODULE_DEVICE_TABLE(of, davini_spi_of_match); 773 + 774 + /** 775 + * spi_davinci_get_pdata - Get platform data from DTS binding 776 + * @pdev: ptr to platform data 777 + * @dspi: ptr to driver data 778 + * 779 + * Parses and populates pdata in dspi from device tree bindings. 780 + * 781 + * NOTE: Not all platform data params are supported currently. 782 + */ 783 + static int spi_davinci_get_pdata(struct platform_device *pdev, 784 + struct davinci_spi *dspi) 785 + { 786 + struct device_node *node = pdev->dev.of_node; 787 + struct davinci_spi_platform_data *pdata; 788 + unsigned int num_cs, intr_line = 0; 789 + const struct of_device_id *match; 790 + 791 + pdata = &dspi->pdata; 792 + 793 + pdata->version = SPI_VERSION_1; 794 + match = of_match_device(of_match_ptr(davinci_spi_of_match), 795 + &pdev->dev); 796 + if (!match) 797 + return -ENODEV; 798 + 799 + /* match data has the SPI version number for SPI_VERSION_2 */ 800 + if (match->data == (void *)SPI_VERSION_2) 801 + pdata->version = SPI_VERSION_2; 802 + 803 + /* 804 + * default num_cs is 1 and all chipsel are internal to the chip 805 + * indicated by chip_sel being NULL. GPIO based CS is not 806 + * supported yet in DT bindings. 807 + */ 808 + num_cs = 1; 809 + of_property_read_u32(node, "num-cs", &num_cs); 810 + pdata->num_chipselect = num_cs; 811 + of_property_read_u32(node, "ti,davinci-spi-intr-line", &intr_line); 812 + pdata->intr_line = intr_line; 813 + return 0; 814 + } 815 + #else 816 + #define davinci_spi_of_match NULL 817 + static struct davinci_spi_platform_data 818 + *spi_davinci_get_pdata(struct platform_device *pdev, 819 + struct davinci_spi *dspi) 820 + { 821 + return -ENODEV; 822 + } 823 + #endif 824 + 763 825 /** 764 826 * davinci_spi_probe - probe function for SPI Master Controller 765 827 * @pdev: platform_device structure which contains plateform specific data ··· 846 780 int i = 0, ret = 0; 847 781 u32 spipc0; 848 782 849 - pdata = pdev->dev.platform_data; 850 - if (pdata == NULL) { 851 - ret = -ENODEV; 852 - goto err; 853 - } 854 - 855 783 master = spi_alloc_master(&pdev->dev, sizeof(struct davinci_spi)); 856 784 if (master == NULL) { 857 785 ret = -ENOMEM; ··· 860 800 goto free_master; 861 801 } 862 802 803 + if (pdev->dev.platform_data) { 804 + pdata = pdev->dev.platform_data; 805 + dspi->pdata = *pdata; 806 + } else { 807 + /* update dspi pdata with that from the DT */ 808 + ret = spi_davinci_get_pdata(pdev, dspi); 809 + if (ret < 0) 810 + goto free_master; 811 + } 812 + 813 + /* pdata in dspi is now updated and point pdata to that */ 814 + pdata = &dspi->pdata; 815 + 863 816 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 864 817 if (r == NULL) { 865 818 ret = -ENOENT; ··· 880 807 } 881 808 882 809 dspi->pbase = r->start; 883 - dspi->pdata = pdata; 884 810 885 811 mem = request_mem_region(r->start, resource_size(r), pdev->name); 886 812 if (mem == NULL) { ··· 915 843 ret = -ENODEV; 916 844 goto put_master; 917 845 } 918 - clk_enable(dspi->clk); 846 + clk_prepare_enable(dspi->clk); 919 847 848 + master->dev.of_node = pdev->dev.of_node; 920 849 master->bus_num = pdev->id; 921 850 master->num_chipselect = pdata->num_chipselect; 922 851 master->setup = davinci_spi_setup; ··· 1000 927 dma_release_channel(dspi->dma_rx); 1001 928 dma_release_channel(dspi->dma_tx); 1002 929 free_clk: 1003 - clk_disable(dspi->clk); 930 + clk_disable_unprepare(dspi->clk); 1004 931 clk_put(dspi->clk); 1005 932 put_master: 1006 933 spi_master_put(master); ··· 1036 963 1037 964 spi_bitbang_stop(&dspi->bitbang); 1038 965 1039 - clk_disable(dspi->clk); 966 + clk_disable_unprepare(dspi->clk); 1040 967 clk_put(dspi->clk); 1041 968 spi_master_put(master); 1042 969 free_irq(dspi->irq, dspi); ··· 1051 978 .driver = { 1052 979 .name = "spi_davinci", 1053 980 .owner = THIS_MODULE, 981 + .of_match_table = davinci_spi_of_match, 1054 982 }, 1055 983 .probe = davinci_spi_probe, 1056 984 .remove = davinci_spi_remove,