Commit | Line | Data |
---|---|---|
28ad94ec AR |
1 | /* |
2 | * Copyright STMicroelectronics, 2007. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | */ | |
18 | ||
19 | #include <linux/types.h> | |
20 | #include <linux/init.h> | |
21 | #include <linux/device.h> | |
2ec1d359 | 22 | #include <linux/amba/bus.h> |
3e3c62ca | 23 | #include <linux/platform_device.h> |
35b47a40 | 24 | #include <linux/io.h> |
7c77852d LW |
25 | #include <linux/slab.h> |
26 | #include <linux/irq.h> | |
27 | #include <linux/dma-mapping.h> | |
f8635abd | 28 | #include <linux/irqchip.h> |
4a31bd28 | 29 | #include <linux/platform_data/clk-nomadik.h> |
bb16bd9b | 30 | #include <linux/platform_data/pinctrl-nomadik.h> |
1b542757 | 31 | #include <linux/pinctrl/machine.h> |
f8635abd LW |
32 | #include <linux/platform_data/clocksource-nomadik-mtu.h> |
33 | #include <linux/of_irq.h> | |
2ad6e398 | 34 | #include <linux/of_gpio.h> |
f8635abd LW |
35 | #include <linux/of_address.h> |
36 | #include <linux/of_platform.h> | |
ba785205 | 37 | #include <linux/mtd/fsmc.h> |
2ad6e398 | 38 | #include <linux/gpio.h> |
4fd243c6 | 39 | #include <linux/amba/mmci.h> |
28ad94ec AR |
40 | |
41 | #include <mach/hardware.h> | |
42 | #include <mach/irqs.h> | |
f8635abd | 43 | #include <asm/mach/arch.h> |
28ad94ec | 44 | #include <asm/mach/map.h> |
f8635abd | 45 | #include <asm/mach/time.h> |
27bda036 | 46 | #include <asm/mach-types.h> |
28ad94ec | 47 | |
0b260fd4 AR |
48 | #include <asm/cacheflush.h> |
49 | #include <asm/hardware/cache-l2x0.h> | |
50 | ||
61b38753 | 51 | #include "cpu-8815.h" |
ba327b1e | 52 | |
056c78d3 LW |
53 | /* The 8815 has 4 GPIO blocks, let's register them immediately */ |
54 | static resource_size_t __initdata cpu8815_gpio_base[] = { | |
55 | NOMADIK_GPIO0_BASE, | |
56 | NOMADIK_GPIO1_BASE, | |
57 | NOMADIK_GPIO2_BASE, | |
58 | NOMADIK_GPIO3_BASE, | |
3e3c62ca | 59 | }; |
2ec1d359 | 60 | |
056c78d3 LW |
61 | static struct platform_device * |
62 | cpu8815_add_gpio(int id, resource_size_t addr, int irq, | |
63 | struct nmk_gpio_platform_data *pdata) | |
64 | { | |
65 | struct resource resources[] = { | |
66 | { | |
67 | .start = addr, | |
68 | .end = addr + 127, | |
69 | .flags = IORESOURCE_MEM, | |
70 | }, | |
71 | { | |
72 | .start = irq, | |
73 | .end = irq, | |
74 | .flags = IORESOURCE_IRQ, | |
75 | } | |
76 | }; | |
77 | ||
78 | return platform_device_register_resndata(NULL, "gpio", id, | |
79 | resources, ARRAY_SIZE(resources), | |
80 | pdata, sizeof(*pdata)); | |
81 | } | |
2ec1d359 | 82 | |
056c78d3 LW |
83 | void cpu8815_add_gpios(resource_size_t *base, int num, int irq, |
84 | struct nmk_gpio_platform_data *pdata) | |
85 | { | |
86 | int first = 0; | |
87 | int i; | |
d2392ba0 | 88 | |
056c78d3 LW |
89 | for (i = 0; i < num; i++, first += 32, irq++) { |
90 | pdata->first_gpio = first; | |
91 | pdata->first_irq = NOMADIK_GPIO_TO_IRQ(first); | |
92 | pdata->num_gpio = 32; | |
3e3c62ca | 93 | |
056c78d3 LW |
94 | cpu8815_add_gpio(i, base[i], irq, pdata); |
95 | } | |
96 | } | |
2ec1d359 | 97 | |
1b542757 LW |
98 | static unsigned long out_low[] = { PIN_OUTPUT_LOW }; |
99 | static unsigned long out_high[] = { PIN_OUTPUT_HIGH }; | |
100 | static unsigned long in_nopull[] = { PIN_INPUT_NOPULL }; | |
101 | static unsigned long in_pullup[] = { PIN_INPUT_PULLUP }; | |
102 | ||
103 | static struct pinctrl_map __initdata nhk8815_pinmap[] = { | |
104 | PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"), | |
105 | PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"), | |
106 | /* Hog in MMC/SD card mux */ | |
107 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"), | |
108 | /* MCCLK */ | |
109 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low), | |
110 | /* MCCMD */ | |
111 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup), | |
112 | /* MCCMDDIR */ | |
113 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high), | |
114 | /* MCDAT3-0 */ | |
115 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup), | |
116 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup), | |
117 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup), | |
118 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup), | |
119 | /* MCDAT0DIR */ | |
120 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high), | |
121 | /* MCDAT31DIR */ | |
122 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high), | |
123 | /* MCMSFBCLK */ | |
124 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup), | |
125 | /* CD input GPIO */ | |
126 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull), | |
127 | /* CD bias drive */ | |
128 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low), | |
129 | /* I2C0 */ | |
130 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup), | |
131 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup), | |
132 | /* I2C1 */ | |
133 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup), | |
134 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup), | |
135 | /* I2C2 */ | |
136 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup), | |
137 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup), | |
138 | }; | |
139 | ||
2601ccfe LW |
140 | static inline void |
141 | cpu8815_add_pinctrl(struct device *parent, const char *name) | |
142 | { | |
143 | struct platform_device_info pdevinfo = { | |
144 | .parent = parent, | |
145 | .name = name, | |
146 | .id = -1, | |
147 | }; | |
148 | ||
1b542757 | 149 | pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap)); |
2601ccfe LW |
150 | platform_device_register_full(&pdevinfo); |
151 | } | |
152 | ||
2ec1d359 AR |
153 | static int __init cpu8815_init(void) |
154 | { | |
056c78d3 LW |
155 | struct nmk_gpio_platform_data pdata = { |
156 | /* No custom data yet */ | |
157 | }; | |
2ec1d359 | 158 | |
6010d403 LW |
159 | /* For e.g. device tree boots */ |
160 | if (!machine_is_nomadik()) | |
161 | return 0; | |
162 | ||
056c78d3 LW |
163 | cpu8815_add_gpios(cpu8815_gpio_base, ARRAY_SIZE(cpu8815_gpio_base), |
164 | IRQ_GPIO0, &pdata); | |
2601ccfe | 165 | cpu8815_add_pinctrl(NULL, "pinctrl-stn8815"); |
6010d403 LW |
166 | amba_apb_device_add(NULL, "rng", NOMADIK_RNG_BASE, SZ_4K, 0, 0, NULL, 0); |
167 | amba_apb_device_add(NULL, "rtc-pl031", NOMADIK_RTC_BASE, SZ_4K, IRQ_RTC_RTT, 0, NULL, 0); | |
2ec1d359 AR |
168 | return 0; |
169 | } | |
170 | arch_initcall(cpu8815_init); | |
171 | ||
28ad94ec AR |
172 | /* All SoC devices live in the same area (see hardware.h) */ |
173 | static struct map_desc nomadik_io_desc[] __initdata = { | |
174 | { | |
175 | .virtual = NOMADIK_IO_VIRTUAL, | |
176 | .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), | |
177 | .length = NOMADIK_IO_SIZE, | |
178 | .type = MT_DEVICE, | |
179 | } | |
180 | /* static ram and secured ram may be added later */ | |
181 | }; | |
182 | ||
183 | void __init cpu8815_map_io(void) | |
184 | { | |
185 | iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); | |
186 | } | |
187 | ||
188 | void __init cpu8815_init_irq(void) | |
189 | { | |
190 | /* This modified VIC cell has two register blocks, at 0 and 0x20 */ | |
191 | vic_init(io_p2v(NOMADIK_IC_BASE + 0x00), IRQ_VIC_START + 0, ~0, 0); | |
192 | vic_init(io_p2v(NOMADIK_IC_BASE + 0x20), IRQ_VIC_START + 32, ~0, 0); | |
ba327b1e LW |
193 | |
194 | /* | |
195 | * Init clocks here so that they are available for system timer | |
196 | * initialization. | |
197 | */ | |
4a31bd28 | 198 | nomadik_clk_init(); |
28ad94ec AR |
199 | } |
200 | ||
201 | /* | |
202 | * This function is called from the board init ("init_machine"). | |
28ad94ec AR |
203 | */ |
204 | void __init cpu8815_platform_init(void) | |
205 | { | |
0b260fd4 AR |
206 | #ifdef CONFIG_CACHE_L2X0 |
207 | /* At full speed latency must be >=2, so 0x249 in low bits */ | |
208 | l2x0_init(io_p2v(NOMADIK_L2CC_BASE), 0x00730249, 0xfe000fff); | |
209 | #endif | |
28ad94ec AR |
210 | return; |
211 | } | |
35b47a40 RK |
212 | |
213 | void cpu8815_restart(char mode, const char *cmd) | |
214 | { | |
215 | void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); | |
216 | ||
217 | /* FIXME: use egpio when implemented */ | |
218 | ||
219 | /* Write anything to Reset status register */ | |
220 | writel(1, src_rstsr); | |
221 | } | |
f8635abd LW |
222 | |
223 | #ifdef CONFIG_OF | |
224 | ||
225 | /* Initial value for SRC control register: all timers use MXTAL/8 source */ | |
226 | #define SRC_CR_INIT_MASK 0x00007fff | |
227 | #define SRC_CR_INIT_VAL 0x2aaa8000 | |
228 | ||
229 | static void __init cpu8815_timer_init_of(void) | |
230 | { | |
231 | struct device_node *mtu; | |
232 | void __iomem *base; | |
233 | int irq; | |
234 | u32 src_cr; | |
235 | ||
236 | /* We need this to be up now */ | |
237 | nomadik_clk_init(); | |
238 | ||
239 | mtu = of_find_node_by_path("/mtu0"); | |
240 | if (!mtu) | |
241 | return; | |
242 | base = of_iomap(mtu, 0); | |
243 | if (WARN_ON(!base)) | |
244 | return; | |
245 | irq = irq_of_parse_and_map(mtu, 0); | |
246 | ||
247 | pr_info("Remapped MTU @ %p, irq: %d\n", base, irq); | |
248 | ||
249 | /* Configure timer sources in "system reset controller" ctrl reg */ | |
250 | src_cr = readl(base); | |
251 | src_cr &= SRC_CR_INIT_MASK; | |
252 | src_cr |= SRC_CR_INIT_VAL; | |
253 | writel(src_cr, base); | |
254 | ||
255 | nmdk_timer_init(base, irq); | |
256 | } | |
257 | ||
ba785205 LW |
258 | static struct fsmc_nand_timings cpu8815_nand_timings = { |
259 | .thiz = 0, | |
260 | .thold = 0x10, | |
261 | .twait = 0x0A, | |
262 | .tset = 0, | |
263 | }; | |
264 | ||
265 | static struct fsmc_nand_platform_data cpu8815_nand_data = { | |
266 | .nand_timings = &cpu8815_nand_timings, | |
267 | }; | |
268 | ||
2ad6e398 LW |
269 | /* |
270 | * The SMSC911x IRQ is connected to a GPIO pin, but the driver expects | |
271 | * to simply request an IRQ passed as a resource. So the GPIO pin needs | |
272 | * to be requested by this hog and set as input. | |
273 | */ | |
274 | static int __init cpu8815_eth_init(void) | |
275 | { | |
276 | struct device_node *eth; | |
277 | int gpio, irq, err; | |
278 | ||
279 | eth = of_find_node_by_path("/usb-s8815/ethernet-gpio"); | |
280 | if (!eth) { | |
281 | pr_info("could not find any ethernet GPIO\n"); | |
282 | return 0; | |
283 | } | |
284 | gpio = of_get_gpio(eth, 0); | |
285 | err = gpio_request(gpio, "eth_irq"); | |
286 | if (err) { | |
287 | pr_info("failed to request ethernet GPIO\n"); | |
288 | return -ENODEV; | |
289 | } | |
290 | err = gpio_direction_input(gpio); | |
291 | if (err) { | |
292 | pr_info("failed to set ethernet GPIO as input\n"); | |
293 | return -ENODEV; | |
294 | } | |
295 | irq = gpio_to_irq(gpio); | |
296 | pr_info("enabled USB-S8815 ethernet GPIO %d, IRQ %d\n", gpio, irq); | |
297 | return 0; | |
298 | } | |
299 | device_initcall(cpu8815_eth_init); | |
300 | ||
4fd243c6 LW |
301 | /* |
302 | * TODO: | |
303 | * cannot be set from device tree, convert to a proper DT | |
304 | * binding. | |
305 | */ | |
306 | static struct mmci_platform_data mmcsd_plat_data = { | |
307 | .ocr_mask = MMC_VDD_29_30, | |
308 | }; | |
309 | ||
310 | /* | |
311 | * This GPIO pin turns on a line that is used to detect card insertion | |
312 | * on this board. | |
313 | */ | |
314 | static int __init cpu8815_mmcsd_init(void) | |
315 | { | |
316 | struct device_node *cdbias; | |
317 | int gpio, err; | |
318 | ||
319 | cdbias = of_find_node_by_path("/usb-s8815/mmcsd-gpio"); | |
320 | if (!cdbias) { | |
321 | pr_info("could not find MMC/SD card detect bias node\n"); | |
322 | return 0; | |
323 | } | |
324 | gpio = of_get_gpio(cdbias, 0); | |
325 | if (gpio < 0) { | |
326 | pr_info("could not obtain MMC/SD card detect bias GPIO\n"); | |
327 | return 0; | |
328 | } | |
329 | err = gpio_request(gpio, "card detect bias"); | |
330 | if (err) { | |
331 | pr_info("failed to request card detect bias GPIO %d\n", gpio); | |
332 | return -ENODEV; | |
333 | } | |
334 | err = gpio_direction_output(gpio, 0); | |
335 | if (err){ | |
336 | pr_info("failed to set GPIO %d as output, low\n", gpio); | |
337 | return err; | |
338 | } | |
339 | pr_info("enabled USB-S8815 CD bias GPIO %d, low\n", gpio); | |
340 | return 0; | |
341 | } | |
342 | device_initcall(cpu8815_mmcsd_init); | |
343 | ||
344 | ||
f8635abd LW |
345 | /* These are mostly to get the right device names for the clock lookups */ |
346 | static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = { | |
6010d403 LW |
347 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO0_BASE, |
348 | "gpio.0", NULL), | |
349 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO1_BASE, | |
350 | "gpio.1", NULL), | |
351 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO2_BASE, | |
352 | "gpio.2", NULL), | |
353 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO3_BASE, | |
354 | "gpio.3", NULL), | |
355 | OF_DEV_AUXDATA("stericsson,nmk-pinctrl-stn8815", 0, | |
356 | "pinctrl-stn8815", NULL), | |
f8635abd LW |
357 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE, |
358 | "uart0", NULL), | |
359 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE, | |
360 | "uart1", NULL), | |
27bda036 LW |
361 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE, |
362 | "rng", NULL), | |
363 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE, | |
364 | "rtc-pl031", NULL), | |
ba785205 LW |
365 | OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE, |
366 | "fsmc-nand", &cpu8815_nand_data), | |
4fd243c6 LW |
367 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_SDI_BASE, |
368 | "mmci", &mmcsd_plat_data), | |
f8635abd LW |
369 | { /* sentinel */ }, |
370 | }; | |
371 | ||
372 | static void __init cpu8815_init_of(void) | |
373 | { | |
374 | #ifdef CONFIG_CACHE_L2X0 | |
375 | /* At full speed latency must be >=2, so 0x249 in low bits */ | |
376 | l2x0_of_init(0x00730249, 0xfe000fff); | |
377 | #endif | |
6010d403 | 378 | pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap)); |
f8635abd LW |
379 | of_platform_populate(NULL, of_default_bus_match_table, |
380 | cpu8815_auxdata_lookup, NULL); | |
381 | } | |
382 | ||
383 | static const char * cpu8815_board_compat[] = { | |
384 | "calaosystems,usb-s8815", | |
385 | NULL, | |
386 | }; | |
387 | ||
388 | DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815") | |
389 | .map_io = cpu8815_map_io, | |
390 | .init_irq = irqchip_init, | |
391 | .init_time = cpu8815_timer_init_of, | |
392 | .init_machine = cpu8815_init_of, | |
393 | .restart = cpu8815_restart, | |
394 | .dt_compat = cpu8815_board_compat, | |
395 | MACHINE_END | |
396 | ||
397 | #endif |