aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBenoit Cousson <b-cousson@ti.com>2012-02-15 12:37:34 -0500
committerGrant Likely <grant.likely@secretlab.ca>2012-02-15 14:57:00 -0500
commitd5a8003135da7afe311e4e13ff42000ab7cd2078 (patch)
treee003b1e3ac213aa09fdbfeee60715a2f9d7adff7 /drivers
parent14af60b6fb3b76634278364b697dae2f9f360abf (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/spi-omap2-mcspi.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 0b0dfb71c640..bb9274c2526d 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -34,6 +34,8 @@
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/pm_runtime.h> 36#include <linux/pm_runtime.h>
37#include <linux/of.h>
38#include <linux/of_device.h>
37 39
38#include <linux/spi/spi.h> 40#include <linux/spi/spi.h>
39 41
@@ -1079,15 +1081,39 @@ static int omap_mcspi_runtime_resume(struct device *dev)
1079 return 0; 1081 return 0;
1080} 1082}
1081 1083
1084static struct omap2_mcspi_platform_config omap2_pdata = {
1085 .regs_offset = 0,
1086};
1087
1088static struct omap2_mcspi_platform_config omap4_pdata = {
1089 .regs_offset = OMAP4_MCSPI_REG_OFFSET,
1090};
1091
1092static 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};
1103MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
1082 1104
1083static int __init omap2_mcspi_probe(struct platform_device *pdev) 1105static int __init omap2_mcspi_probe(struct platform_device *pdev)
1084{ 1106{
1085 struct spi_master *master; 1107 struct spi_master *master;
1086 struct omap2_mcspi_platform_config *pdata = pdev->dev.platform_data; 1108 struct omap2_mcspi_platform_config *pdata;
1087 struct omap2_mcspi *mcspi; 1109 struct omap2_mcspi *mcspi;
1088 struct resource *r; 1110 struct resource *r;
1089 int status = 0, i; 1111 int status = 0, i;
1090 char wq_name[20]; 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 master = spi_alloc_master(&pdev->dev, sizeof *mcspi); 1118 master = spi_alloc_master(&pdev->dev, sizeof *mcspi);
1093 if (master == NULL) { 1119 if (master == NULL) {
@@ -1098,13 +1124,26 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1098 /* the spi->mode bits understood by this driver: */ 1124 /* the spi->mode bits understood by this driver: */
1099 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 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 master->setup = omap2_mcspi_setup; 1127 master->setup = omap2_mcspi_setup;
1105 master->transfer = omap2_mcspi_transfer; 1128 master->transfer = omap2_mcspi_transfer;
1106 master->cleanup = omap2_mcspi_cleanup; 1129 master->cleanup = omap2_mcspi_cleanup;
1107 master->num_chipselect = pdata->num_cs; 1130 master->dev.of_node = node;
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;
1108 1147
1109 dev_set_drvdata(&pdev->dev, master); 1148 dev_set_drvdata(&pdev->dev, master);
1110 1149
@@ -1124,8 +1163,8 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1124 goto free_master; 1163 goto free_master;
1125 } 1164 }
1126 1165
1127 r->start += pdata->regs_offset; 1166 r->start += regs_offset;
1128 r->end += pdata->regs_offset; 1167 r->end += regs_offset;
1129 mcspi->phys = r->start; 1168 mcspi->phys = r->start;
1130 if (!request_mem_region(r->start, resource_size(r), 1169 if (!request_mem_region(r->start, resource_size(r),
1131 dev_name(&pdev->dev))) { 1170 dev_name(&pdev->dev))) {
@@ -1285,7 +1324,8 @@ static struct platform_driver omap2_mcspi_driver = {
1285 .driver = { 1324 .driver = {
1286 .name = "omap2_mcspi", 1325 .name = "omap2_mcspi",
1287 .owner = THIS_MODULE, 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 .remove = __exit_p(omap2_mcspi_remove), 1330 .remove = __exit_p(omap2_mcspi_remove),
1291}; 1331};