]>
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 | ||
1b542757 LW |
51 | static unsigned long out_low[] = { PIN_OUTPUT_LOW }; |
52 | static unsigned long out_high[] = { PIN_OUTPUT_HIGH }; | |
53 | static unsigned long in_nopull[] = { PIN_INPUT_NOPULL }; | |
54 | static unsigned long in_pullup[] = { PIN_INPUT_PULLUP }; | |
55 | ||
56 | static struct pinctrl_map __initdata nhk8815_pinmap[] = { | |
57 | PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-stn8815", "u0_a_1", "u0"), | |
58 | PIN_MAP_MUX_GROUP_DEFAULT("uart1", "pinctrl-stn8815", "u1_a_1", "u1"), | |
59 | /* Hog in MMC/SD card mux */ | |
60 | PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-stn8815", "mmcsd_a_1", "mmcsd"), | |
61 | /* MCCLK */ | |
62 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO8_B10", out_low), | |
63 | /* MCCMD */ | |
64 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO9_A10", in_pullup), | |
65 | /* MCCMDDIR */ | |
66 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO10_C11", out_high), | |
67 | /* MCDAT3-0 */ | |
68 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO11_B11", in_pullup), | |
69 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO12_A11", in_pullup), | |
70 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO13_C12", in_pullup), | |
71 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO14_B12", in_pullup), | |
72 | /* MCDAT0DIR */ | |
73 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO15_A12", out_high), | |
74 | /* MCDAT31DIR */ | |
75 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO16_C13", out_high), | |
76 | /* MCMSFBCLK */ | |
77 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO24_C15", in_pullup), | |
78 | /* CD input GPIO */ | |
79 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO111_H21", in_nopull), | |
80 | /* CD bias drive */ | |
81 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO112_J21", out_low), | |
82 | /* I2C0 */ | |
83 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO62_D3", in_pullup), | |
84 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO63_D2", in_pullup), | |
85 | /* I2C1 */ | |
86 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO53_L4", in_pullup), | |
87 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO54_L3", in_pullup), | |
88 | /* I2C2 */ | |
89 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO73_C21", in_pullup), | |
90 | PIN_MAP_CONFIGS_PIN_HOG_DEFAULT("pinctrl-stn8815", "GPIO74_C20", in_pullup), | |
91 | }; | |
92 | ||
28ad94ec AR |
93 | /* All SoC devices live in the same area (see hardware.h) */ |
94 | static struct map_desc nomadik_io_desc[] __initdata = { | |
95 | { | |
96 | .virtual = NOMADIK_IO_VIRTUAL, | |
97 | .pfn = __phys_to_pfn(NOMADIK_IO_PHYSICAL), | |
98 | .length = NOMADIK_IO_SIZE, | |
99 | .type = MT_DEVICE, | |
100 | } | |
101 | /* static ram and secured ram may be added later */ | |
102 | }; | |
103 | ||
5f66d482 | 104 | static void __init cpu8815_map_io(void) |
28ad94ec AR |
105 | { |
106 | iotable_init(nomadik_io_desc, ARRAY_SIZE(nomadik_io_desc)); | |
107 | } | |
108 | ||
5f66d482 | 109 | static void cpu8815_restart(char mode, const char *cmd) |
35b47a40 RK |
110 | { |
111 | void __iomem *src_rstsr = io_p2v(NOMADIK_SRC_BASE + 0x18); | |
112 | ||
113 | /* FIXME: use egpio when implemented */ | |
114 | ||
115 | /* Write anything to Reset status register */ | |
116 | writel(1, src_rstsr); | |
117 | } | |
f8635abd | 118 | |
f8635abd LW |
119 | /* Initial value for SRC control register: all timers use MXTAL/8 source */ |
120 | #define SRC_CR_INIT_MASK 0x00007fff | |
121 | #define SRC_CR_INIT_VAL 0x2aaa8000 | |
122 | ||
123 | static void __init cpu8815_timer_init_of(void) | |
124 | { | |
125 | struct device_node *mtu; | |
126 | void __iomem *base; | |
127 | int irq; | |
128 | u32 src_cr; | |
129 | ||
130 | /* We need this to be up now */ | |
131 | nomadik_clk_init(); | |
132 | ||
133 | mtu = of_find_node_by_path("/mtu0"); | |
134 | if (!mtu) | |
135 | return; | |
136 | base = of_iomap(mtu, 0); | |
137 | if (WARN_ON(!base)) | |
138 | return; | |
139 | irq = irq_of_parse_and_map(mtu, 0); | |
140 | ||
141 | pr_info("Remapped MTU @ %p, irq: %d\n", base, irq); | |
142 | ||
143 | /* Configure timer sources in "system reset controller" ctrl reg */ | |
144 | src_cr = readl(base); | |
145 | src_cr &= SRC_CR_INIT_MASK; | |
146 | src_cr |= SRC_CR_INIT_VAL; | |
147 | writel(src_cr, base); | |
148 | ||
149 | nmdk_timer_init(base, irq); | |
150 | } | |
151 | ||
ba785205 LW |
152 | static struct fsmc_nand_timings cpu8815_nand_timings = { |
153 | .thiz = 0, | |
154 | .thold = 0x10, | |
155 | .twait = 0x0A, | |
156 | .tset = 0, | |
157 | }; | |
158 | ||
159 | static struct fsmc_nand_platform_data cpu8815_nand_data = { | |
160 | .nand_timings = &cpu8815_nand_timings, | |
161 | }; | |
162 | ||
2ad6e398 LW |
163 | /* |
164 | * The SMSC911x IRQ is connected to a GPIO pin, but the driver expects | |
165 | * to simply request an IRQ passed as a resource. So the GPIO pin needs | |
166 | * to be requested by this hog and set as input. | |
167 | */ | |
168 | static int __init cpu8815_eth_init(void) | |
169 | { | |
170 | struct device_node *eth; | |
171 | int gpio, irq, err; | |
172 | ||
173 | eth = of_find_node_by_path("/usb-s8815/ethernet-gpio"); | |
174 | if (!eth) { | |
175 | pr_info("could not find any ethernet GPIO\n"); | |
176 | return 0; | |
177 | } | |
178 | gpio = of_get_gpio(eth, 0); | |
179 | err = gpio_request(gpio, "eth_irq"); | |
180 | if (err) { | |
181 | pr_info("failed to request ethernet GPIO\n"); | |
182 | return -ENODEV; | |
183 | } | |
184 | err = gpio_direction_input(gpio); | |
185 | if (err) { | |
186 | pr_info("failed to set ethernet GPIO as input\n"); | |
187 | return -ENODEV; | |
188 | } | |
189 | irq = gpio_to_irq(gpio); | |
190 | pr_info("enabled USB-S8815 ethernet GPIO %d, IRQ %d\n", gpio, irq); | |
191 | return 0; | |
192 | } | |
193 | device_initcall(cpu8815_eth_init); | |
194 | ||
4fd243c6 LW |
195 | /* |
196 | * TODO: | |
197 | * cannot be set from device tree, convert to a proper DT | |
198 | * binding. | |
199 | */ | |
200 | static struct mmci_platform_data mmcsd_plat_data = { | |
201 | .ocr_mask = MMC_VDD_29_30, | |
202 | }; | |
203 | ||
204 | /* | |
205 | * This GPIO pin turns on a line that is used to detect card insertion | |
206 | * on this board. | |
207 | */ | |
208 | static int __init cpu8815_mmcsd_init(void) | |
209 | { | |
210 | struct device_node *cdbias; | |
211 | int gpio, err; | |
212 | ||
213 | cdbias = of_find_node_by_path("/usb-s8815/mmcsd-gpio"); | |
214 | if (!cdbias) { | |
215 | pr_info("could not find MMC/SD card detect bias node\n"); | |
216 | return 0; | |
217 | } | |
218 | gpio = of_get_gpio(cdbias, 0); | |
219 | if (gpio < 0) { | |
220 | pr_info("could not obtain MMC/SD card detect bias GPIO\n"); | |
221 | return 0; | |
222 | } | |
223 | err = gpio_request(gpio, "card detect bias"); | |
224 | if (err) { | |
225 | pr_info("failed to request card detect bias GPIO %d\n", gpio); | |
226 | return -ENODEV; | |
227 | } | |
228 | err = gpio_direction_output(gpio, 0); | |
229 | if (err){ | |
230 | pr_info("failed to set GPIO %d as output, low\n", gpio); | |
231 | return err; | |
232 | } | |
233 | pr_info("enabled USB-S8815 CD bias GPIO %d, low\n", gpio); | |
234 | return 0; | |
235 | } | |
236 | device_initcall(cpu8815_mmcsd_init); | |
237 | ||
238 | ||
f8635abd LW |
239 | /* These are mostly to get the right device names for the clock lookups */ |
240 | static struct of_dev_auxdata cpu8815_auxdata_lookup[] __initdata = { | |
6010d403 LW |
241 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO0_BASE, |
242 | "gpio.0", NULL), | |
243 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO1_BASE, | |
244 | "gpio.1", NULL), | |
245 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO2_BASE, | |
246 | "gpio.2", NULL), | |
247 | OF_DEV_AUXDATA("st,nomadik-gpio", NOMADIK_GPIO3_BASE, | |
248 | "gpio.3", NULL), | |
249 | OF_DEV_AUXDATA("stericsson,nmk-pinctrl-stn8815", 0, | |
250 | "pinctrl-stn8815", NULL), | |
f8635abd LW |
251 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART0_BASE, |
252 | "uart0", NULL), | |
253 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_UART1_BASE, | |
254 | "uart1", NULL), | |
27bda036 LW |
255 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RNG_BASE, |
256 | "rng", NULL), | |
257 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_RTC_BASE, | |
258 | "rtc-pl031", NULL), | |
ba785205 LW |
259 | OF_DEV_AUXDATA("stericsson,fsmc-nand", NOMADIK_FSMC_BASE, |
260 | "fsmc-nand", &cpu8815_nand_data), | |
4fd243c6 LW |
261 | OF_DEV_AUXDATA("arm,primecell", NOMADIK_SDI_BASE, |
262 | "mmci", &mmcsd_plat_data), | |
f8635abd LW |
263 | { /* sentinel */ }, |
264 | }; | |
265 | ||
266 | static void __init cpu8815_init_of(void) | |
267 | { | |
268 | #ifdef CONFIG_CACHE_L2X0 | |
269 | /* At full speed latency must be >=2, so 0x249 in low bits */ | |
270 | l2x0_of_init(0x00730249, 0xfe000fff); | |
271 | #endif | |
6010d403 | 272 | pinctrl_register_mappings(nhk8815_pinmap, ARRAY_SIZE(nhk8815_pinmap)); |
f8635abd LW |
273 | of_platform_populate(NULL, of_default_bus_match_table, |
274 | cpu8815_auxdata_lookup, NULL); | |
275 | } | |
276 | ||
277 | static const char * cpu8815_board_compat[] = { | |
278 | "calaosystems,usb-s8815", | |
279 | NULL, | |
280 | }; | |
281 | ||
282 | DT_MACHINE_START(NOMADIK_DT, "Nomadik STn8815") | |
283 | .map_io = cpu8815_map_io, | |
284 | .init_irq = irqchip_init, | |
285 | .init_time = cpu8815_timer_init_of, | |
286 | .init_machine = cpu8815_init_of, | |
287 | .restart = cpu8815_restart, | |
288 | .dt_compat = cpu8815_board_compat, | |
289 | MACHINE_END |