diff options
Diffstat (limited to 'arch/powerpc/platforms')
-rw-r--r-- | arch/powerpc/platforms/83xx/mpc832x_rdb.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c b/arch/powerpc/platforms/83xx/mpc832x_rdb.c index e1e7eeb7d3a3..567ded7c3b9b 100644 --- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c +++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/spi/mmc_spi.h> | 20 | #include <linux/spi/mmc_spi.h> |
21 | #include <linux/mmc/host.h> | 21 | #include <linux/mmc/host.h> |
22 | #include <linux/of_platform.h> | 22 | #include <linux/of_platform.h> |
23 | #include <linux/fsl_devices.h> | ||
23 | 24 | ||
24 | #include <asm/time.h> | 25 | #include <asm/time.h> |
25 | #include <asm/ipic.h> | 26 | #include <asm/ipic.h> |
@@ -39,6 +40,112 @@ | |||
39 | #endif | 40 | #endif |
40 | 41 | ||
41 | #ifdef CONFIG_QUICC_ENGINE | 42 | #ifdef CONFIG_QUICC_ENGINE |
43 | static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk, | ||
44 | struct spi_board_info *board_infos, | ||
45 | unsigned int num_board_infos, | ||
46 | void (*cs_control)(struct spi_device *dev, | ||
47 | bool on)) | ||
48 | { | ||
49 | struct device_node *np; | ||
50 | unsigned int i = 0; | ||
51 | |||
52 | for_each_compatible_node(np, type, compatible) { | ||
53 | int ret; | ||
54 | unsigned int j; | ||
55 | const void *prop; | ||
56 | struct resource res[2]; | ||
57 | struct platform_device *pdev; | ||
58 | struct fsl_spi_platform_data pdata = { | ||
59 | .cs_control = cs_control, | ||
60 | }; | ||
61 | |||
62 | memset(res, 0, sizeof(res)); | ||
63 | |||
64 | pdata.sysclk = sysclk; | ||
65 | |||
66 | prop = of_get_property(np, "reg", NULL); | ||
67 | if (!prop) | ||
68 | goto err; | ||
69 | pdata.bus_num = *(u32 *)prop; | ||
70 | |||
71 | prop = of_get_property(np, "cell-index", NULL); | ||
72 | if (prop) | ||
73 | i = *(u32 *)prop; | ||
74 | |||
75 | prop = of_get_property(np, "mode", NULL); | ||
76 | if (prop && !strcmp(prop, "cpu-qe")) | ||
77 | pdata.qe_mode = 1; | ||
78 | |||
79 | for (j = 0; j < num_board_infos; j++) { | ||
80 | if (board_infos[j].bus_num == pdata.bus_num) | ||
81 | pdata.max_chipselect++; | ||
82 | } | ||
83 | |||
84 | if (!pdata.max_chipselect) | ||
85 | continue; | ||
86 | |||
87 | ret = of_address_to_resource(np, 0, &res[0]); | ||
88 | if (ret) | ||
89 | goto err; | ||
90 | |||
91 | ret = of_irq_to_resource(np, 0, &res[1]); | ||
92 | if (ret == NO_IRQ) | ||
93 | goto err; | ||
94 | |||
95 | pdev = platform_device_alloc("mpc83xx_spi", i); | ||
96 | if (!pdev) | ||
97 | goto err; | ||
98 | |||
99 | ret = platform_device_add_data(pdev, &pdata, sizeof(pdata)); | ||
100 | if (ret) | ||
101 | goto unreg; | ||
102 | |||
103 | ret = platform_device_add_resources(pdev, res, | ||
104 | ARRAY_SIZE(res)); | ||
105 | if (ret) | ||
106 | goto unreg; | ||
107 | |||
108 | ret = platform_device_add(pdev); | ||
109 | if (ret) | ||
110 | goto unreg; | ||
111 | |||
112 | goto next; | ||
113 | unreg: | ||
114 | platform_device_del(pdev); | ||
115 | err: | ||
116 | pr_err("%s: registration failed\n", np->full_name); | ||
117 | next: | ||
118 | i++; | ||
119 | } | ||
120 | |||
121 | return i; | ||
122 | } | ||
123 | |||
124 | static int __init fsl_spi_init(struct spi_board_info *board_infos, | ||
125 | unsigned int num_board_infos, | ||
126 | void (*cs_control)(struct spi_device *spi, | ||
127 | bool on)) | ||
128 | { | ||
129 | u32 sysclk = -1; | ||
130 | int ret; | ||
131 | |||
132 | /* SPI controller is either clocked from QE or SoC clock */ | ||
133 | sysclk = get_brgfreq(); | ||
134 | if (sysclk == -1) { | ||
135 | sysclk = fsl_get_sys_freq(); | ||
136 | if (sysclk == -1) | ||
137 | return -ENODEV; | ||
138 | } | ||
139 | |||
140 | ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos, | ||
141 | num_board_infos, cs_control); | ||
142 | if (!ret) | ||
143 | of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos, | ||
144 | num_board_infos, cs_control); | ||
145 | |||
146 | return spi_register_board_info(board_infos, num_board_infos); | ||
147 | } | ||
148 | |||
42 | static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on) | 149 | static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on) |
43 | { | 150 | { |
44 | pr_debug("%s %d %d\n", __func__, spi->chip_select, on); | 151 | pr_debug("%s %d %d\n", __func__, spi->chip_select, on); |