aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2007-08-23 07:35:56 -0400
committerKumar Gala <galak@kernel.crashing.org>2007-09-14 09:54:09 -0400
commit26f6cb999366a71b8e318bceaf8fafc1ffecae40 (patch)
tree2da19214e759df13caf4772b6936b5689ac1f070 /arch
parentaf6a9aabc106b70ab03d6665c713bca3dd3cb195 (diff)
[POWERPC] fsl_soc: add support for fsl_spi
Add helper function to setup SPI bus/device information Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/sysdev/fsl_soc.c87
-rw-r--r--arch/powerpc/sysdev/fsl_soc.h7
2 files changed, 94 insertions, 0 deletions
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 7012e51ae5c6..d028e8da027b 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -24,6 +24,7 @@
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/phy.h> 26#include <linux/phy.h>
27#include <linux/spi/spi.h>
27#include <linux/fsl_devices.h> 28#include <linux/fsl_devices.h>
28#include <linux/fs_enet_pd.h> 29#include <linux/fs_enet_pd.h>
29#include <linux/fs_uart_pd.h> 30#include <linux/fs_uart_pd.h>
@@ -1199,3 +1200,89 @@ err:
1199arch_initcall(cpm_smc_uart_of_init); 1200arch_initcall(cpm_smc_uart_of_init);
1200 1201
1201#endif /* CONFIG_8xx */ 1202#endif /* CONFIG_8xx */
1203
1204int __init fsl_spi_init(struct spi_board_info *board_infos,
1205 unsigned int num_board_infos,
1206 void (*activate_cs)(u8 cs, u8 polarity),
1207 void (*deactivate_cs)(u8 cs, u8 polarity))
1208{
1209 struct device_node *np;
1210 unsigned int i;
1211 const u32 *sysclk;
1212
1213 np = of_find_node_by_type(NULL, "qe");
1214 if (!np)
1215 return -ENODEV;
1216
1217 sysclk = of_get_property(np, "bus-frequency", NULL);
1218 if (!sysclk)
1219 return -ENODEV;
1220
1221 for (np = NULL, i = 1;
1222 (np = of_find_compatible_node(np, "spi", "fsl_spi")) != NULL;
1223 i++) {
1224 int ret = 0;
1225 unsigned int j;
1226 const void *prop;
1227 struct resource res[2];
1228 struct platform_device *pdev;
1229 struct fsl_spi_platform_data pdata = {
1230 .activate_cs = activate_cs,
1231 .deactivate_cs = deactivate_cs,
1232 };
1233
1234 memset(res, 0, sizeof(res));
1235
1236 pdata.sysclk = *sysclk;
1237
1238 prop = of_get_property(np, "reg", NULL);
1239 if (!prop)
1240 goto err;
1241 pdata.bus_num = *(u32 *)prop;
1242
1243 prop = of_get_property(np, "mode", NULL);
1244 if (prop && !strcmp(prop, "cpu-qe"))
1245 pdata.qe_mode = 1;
1246
1247 for (j = 0; j < num_board_infos; j++) {
1248 if (board_infos[j].bus_num == pdata.bus_num)
1249 pdata.max_chipselect++;
1250 }
1251
1252 if (!pdata.max_chipselect)
1253 goto err;
1254
1255 ret = of_address_to_resource(np, 0, &res[0]);
1256 if (ret)
1257 goto err;
1258
1259 ret = of_irq_to_resource(np, 0, &res[1]);
1260 if (ret == NO_IRQ)
1261 goto err;
1262
1263 pdev = platform_device_alloc("mpc83xx_spi", i);
1264 if (!pdev)
1265 goto err;
1266
1267 ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
1268 if (ret)
1269 goto unreg;
1270
1271 ret = platform_device_add_resources(pdev, res,
1272 ARRAY_SIZE(res));
1273 if (ret)
1274 goto unreg;
1275
1276 ret = platform_device_register(pdev);
1277 if (ret)
1278 goto unreg;
1279
1280 continue;
1281unreg:
1282 platform_device_del(pdev);
1283err:
1284 continue;
1285 }
1286
1287 return spi_register_board_info(board_infos, num_board_infos);
1288}
diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h
index 04e145b5fc32..618d91d1e103 100644
--- a/arch/powerpc/sysdev/fsl_soc.h
+++ b/arch/powerpc/sysdev/fsl_soc.h
@@ -8,5 +8,12 @@ extern phys_addr_t get_immrbase(void);
8extern u32 get_brgfreq(void); 8extern u32 get_brgfreq(void);
9extern u32 get_baudrate(void); 9extern u32 get_baudrate(void);
10 10
11struct spi_board_info;
12
13extern int fsl_spi_init(struct spi_board_info *board_infos,
14 unsigned int num_board_infos,
15 void (*activate_cs)(u8 cs, u8 polarity),
16 void (*deactivate_cs)(u8 cs, u8 polarity));
17
11#endif 18#endif
12#endif 19#endif