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

spi/omap: Add DT support to McSPI driver

Add device tree support to the OMAP2+ McSPI driver.
Add the bindings documentation.

Based on original code from Rajendra.

Signed-off-by: Benoit Cousson <b-cousson@ti.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Rajendra Nayak <rnayak@ti.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Benoit Cousson and committed by
Grant Likely
d5a80031 14af60b6

+68 -8
+20
Documentation/devicetree/bindings/spi/omap-spi.txt
··· 1 + OMAP2+ McSPI device 2 + 3 + Required properties: 4 + - compatible : 5 + - "ti,omap2-spi" for OMAP2 & OMAP3. 6 + - "ti,omap4-spi" for OMAP4+. 7 + - ti,spi-num-cs : Number of chipselect supported by the instance. 8 + - ti,hwmods: Name of the hwmod associated to the McSPI 9 + 10 + 11 + Example: 12 + 13 + mcspi1: mcspi@1 { 14 + #address-cells = <1>; 15 + #size-cells = <0>; 16 + compatible = "ti,omap4-mcspi"; 17 + ti,hwmods = "mcspi1"; 18 + ti,spi-num-cs = <4>; 19 + }; 20 +
+48 -8
drivers/spi/spi-omap2-mcspi.c
··· 34 34 #include <linux/io.h> 35 35 #include <linux/slab.h> 36 36 #include <linux/pm_runtime.h> 37 + #include <linux/of.h> 38 + #include <linux/of_device.h> 37 39 38 40 #include <linux/spi/spi.h> 39 41 ··· 1081 1079 return 0; 1082 1080 } 1083 1081 1082 + static struct omap2_mcspi_platform_config omap2_pdata = { 1083 + .regs_offset = 0, 1084 + }; 1085 + 1086 + static struct omap2_mcspi_platform_config omap4_pdata = { 1087 + .regs_offset = OMAP4_MCSPI_REG_OFFSET, 1088 + }; 1089 + 1090 + static const struct of_device_id omap_mcspi_of_match[] = { 1091 + { 1092 + .compatible = "ti,omap2-mcspi", 1093 + .data = &omap2_pdata, 1094 + }, 1095 + { 1096 + .compatible = "ti,omap4-mcspi", 1097 + .data = &omap4_pdata, 1098 + }, 1099 + { }, 1100 + }; 1101 + MODULE_DEVICE_TABLE(of, omap_mcspi_of_match); 1084 1102 1085 1103 static int __init omap2_mcspi_probe(struct platform_device *pdev) 1086 1104 { 1087 1105 struct spi_master *master; 1088 - struct omap2_mcspi_platform_config *pdata = pdev->dev.platform_data; 1106 + struct omap2_mcspi_platform_config *pdata; 1089 1107 struct omap2_mcspi *mcspi; 1090 1108 struct resource *r; 1091 1109 int status = 0, i; 1092 1110 char wq_name[20]; 1111 + u32 regs_offset = 0; 1112 + static int bus_num = 1; 1113 + struct device_node *node = pdev->dev.of_node; 1114 + const struct of_device_id *match; 1093 1115 1094 1116 master = spi_alloc_master(&pdev->dev, sizeof *mcspi); 1095 1117 if (master == NULL) { ··· 1124 1098 /* the spi->mode bits understood by this driver: */ 1125 1099 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 1126 1100 1127 - if (pdev->id != -1) 1128 - master->bus_num = pdev->id; 1129 - 1130 1101 master->setup = omap2_mcspi_setup; 1131 1102 master->transfer = omap2_mcspi_transfer; 1132 1103 master->cleanup = omap2_mcspi_cleanup; 1133 - master->num_chipselect = pdata->num_cs; 1104 + master->dev.of_node = node; 1105 + 1106 + match = of_match_device(omap_mcspi_of_match, &pdev->dev); 1107 + if (match) { 1108 + u32 num_cs = 1; /* default number of chipselect */ 1109 + pdata = match->data; 1110 + 1111 + of_property_read_u32(node, "ti,spi-num-cs", &num_cs); 1112 + master->num_chipselect = num_cs; 1113 + master->bus_num = bus_num++; 1114 + } else { 1115 + pdata = pdev->dev.platform_data; 1116 + master->num_chipselect = pdata->num_cs; 1117 + if (pdev->id != -1) 1118 + master->bus_num = pdev->id; 1119 + } 1120 + regs_offset = pdata->regs_offset; 1134 1121 1135 1122 dev_set_drvdata(&pdev->dev, master); 1136 1123 ··· 1163 1124 goto free_master; 1164 1125 } 1165 1126 1166 - r->start += pdata->regs_offset; 1167 - r->end += pdata->regs_offset; 1127 + r->start += regs_offset; 1128 + r->end += regs_offset; 1168 1129 mcspi->phys = r->start; 1169 1130 if (!request_mem_region(r->start, resource_size(r), 1170 1131 dev_name(&pdev->dev))) { ··· 1324 1285 .driver = { 1325 1286 .name = "omap2_mcspi", 1326 1287 .owner = THIS_MODULE, 1327 - .pm = &omap2_mcspi_pm_ops 1288 + .pm = &omap2_mcspi_pm_ops, 1289 + .of_match_table = omap_mcspi_of_match, 1328 1290 }, 1329 1291 .remove = __exit_p(omap2_mcspi_remove), 1330 1292 };