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