Commit d5a8003135da7afe311e4e13ff42000ab7cd2078

Authored by Benoit Cousson
Committed by Grant Likely
1 parent 14af60b6fb

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>

Showing 2 changed files with 68 additions and 8 deletions Side-by-side Diff

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 +};
drivers/spi/spi-omap2-mcspi.c
... ... @@ -34,6 +34,8 @@
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  
40 42  
41 43  
42 44  
... ... @@ -1079,15 +1081,39 @@
1079 1081 return 0;
1080 1082 }
1081 1083  
  1084 +static struct omap2_mcspi_platform_config omap2_pdata = {
  1085 + .regs_offset = 0,
  1086 +};
1082 1087  
  1088 +static struct omap2_mcspi_platform_config omap4_pdata = {
  1089 + .regs_offset = OMAP4_MCSPI_REG_OFFSET,
  1090 +};
  1091 +
  1092 +static const struct of_device_id omap_mcspi_of_match[] = {
  1093 + {
  1094 + .compatible = "ti,omap2-mcspi",
  1095 + .data = &omap2_pdata,
  1096 + },
  1097 + {
  1098 + .compatible = "ti,omap4-mcspi",
  1099 + .data = &omap4_pdata,
  1100 + },
  1101 + { },
  1102 +};
  1103 +MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
  1104 +
1083 1105 static int __init omap2_mcspi_probe(struct platform_device *pdev)
1084 1106 {
1085 1107 struct spi_master *master;
1086   - struct omap2_mcspi_platform_config *pdata = pdev->dev.platform_data;
  1108 + struct omap2_mcspi_platform_config *pdata;
1087 1109 struct omap2_mcspi *mcspi;
1088 1110 struct resource *r;
1089 1111 int status = 0, i;
1090 1112 char wq_name[20];
  1113 + u32 regs_offset = 0;
  1114 + static int bus_num = 1;
  1115 + struct device_node *node = pdev->dev.of_node;
  1116 + const struct of_device_id *match;
1091 1117  
1092 1118 master = spi_alloc_master(&pdev->dev, sizeof *mcspi);
1093 1119 if (master == NULL) {
1094 1120  
1095 1121  
... ... @@ -1098,14 +1124,27 @@
1098 1124 /* the spi->mode bits understood by this driver: */
1099 1125 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1100 1126  
1101   - if (pdev->id != -1)
1102   - master->bus_num = pdev->id;
1103   -
1104 1127 master->setup = omap2_mcspi_setup;
1105 1128 master->transfer = omap2_mcspi_transfer;
1106 1129 master->cleanup = omap2_mcspi_cleanup;
1107   - master->num_chipselect = pdata->num_cs;
  1130 + master->dev.of_node = node;
1108 1131  
  1132 + match = of_match_device(omap_mcspi_of_match, &pdev->dev);
  1133 + if (match) {
  1134 + u32 num_cs = 1; /* default number of chipselect */
  1135 + pdata = match->data;
  1136 +
  1137 + of_property_read_u32(node, "ti,spi-num-cs", &num_cs);
  1138 + master->num_chipselect = num_cs;
  1139 + master->bus_num = bus_num++;
  1140 + } else {
  1141 + pdata = pdev->dev.platform_data;
  1142 + master->num_chipselect = pdata->num_cs;
  1143 + if (pdev->id != -1)
  1144 + master->bus_num = pdev->id;
  1145 + }
  1146 + regs_offset = pdata->regs_offset;
  1147 +
1109 1148 dev_set_drvdata(&pdev->dev, master);
1110 1149  
1111 1150 mcspi = spi_master_get_devdata(master);
... ... @@ -1124,8 +1163,8 @@
1124 1163 goto free_master;
1125 1164 }
1126 1165  
1127   - r->start += pdata->regs_offset;
1128   - r->end += pdata->regs_offset;
  1166 + r->start += regs_offset;
  1167 + r->end += regs_offset;
1129 1168 mcspi->phys = r->start;
1130 1169 if (!request_mem_region(r->start, resource_size(r),
1131 1170 dev_name(&pdev->dev))) {
... ... @@ -1285,7 +1324,8 @@
1285 1324 .driver = {
1286 1325 .name = "omap2_mcspi",
1287 1326 .owner = THIS_MODULE,
1288   - .pm = &omap2_mcspi_pm_ops
  1327 + .pm = &omap2_mcspi_pm_ops,
  1328 + .of_match_table = omap_mcspi_of_match,
1289 1329 },
1290 1330 .remove = __exit_p(omap2_mcspi_remove),
1291 1331 };