xref: /openbmc/linux/arch/mips/txx9/generic/setup.c (revision c49f91f5)
1 /*
2  * linux/arch/mips/txx9/generic/setup.c
3  *
4  * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
5  *	    and RBTX49xx patch from CELF patch archive.
6  *
7  * 2003-2005 (c) MontaVista Software, Inc.
8  * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
9  *
10  * This file is subject to the terms and conditions of the GNU General Public
11  * License.  See the file "COPYING" in the main directory of this archive
12  * for more details.
13  */
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/interrupt.h>
18 #include <linux/string.h>
19 #include <linux/module.h>
20 #include <linux/clk.h>
21 #include <linux/err.h>
22 #include <linux/gpio.h>
23 #include <linux/platform_device.h>
24 #include <asm/bootinfo.h>
25 #include <asm/time.h>
26 #include <asm/reboot.h>
27 #include <asm/txx9/generic.h>
28 #include <asm/txx9/pci.h>
29 #ifdef CONFIG_CPU_TX49XX
30 #include <asm/txx9/tx4938.h>
31 #endif
32 
33 /* EBUSC settings of TX4927, etc. */
34 struct resource txx9_ce_res[8];
35 static char txx9_ce_res_name[8][4];	/* "CEn" */
36 
37 /* pcode, internal register */
38 unsigned int txx9_pcode;
39 char txx9_pcode_str[8];
40 static struct resource txx9_reg_res = {
41 	.name = txx9_pcode_str,
42 	.flags = IORESOURCE_MEM,
43 };
44 void __init
45 txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
46 {
47 	int i;
48 
49 	for (i = 0; i < ARRAY_SIZE(txx9_ce_res); i++) {
50 		sprintf(txx9_ce_res_name[i], "CE%d", i);
51 		txx9_ce_res[i].flags = IORESOURCE_MEM;
52 		txx9_ce_res[i].name = txx9_ce_res_name[i];
53 	}
54 
55 	sprintf(txx9_pcode_str, "TX%x", pcode);
56 	if (base) {
57 		txx9_reg_res.start = base & 0xfffffffffULL;
58 		txx9_reg_res.end = (base & 0xfffffffffULL) + (size - 1);
59 		request_resource(&iomem_resource, &txx9_reg_res);
60 	}
61 }
62 
63 /* clocks */
64 unsigned int txx9_master_clock;
65 unsigned int txx9_cpu_clock;
66 unsigned int txx9_gbus_clock;
67 
68 int txx9_ccfg_toeon __initdata = 1;
69 
70 /* Minimum CLK support */
71 
72 struct clk *clk_get(struct device *dev, const char *id)
73 {
74 	if (!strcmp(id, "spi-baseclk"))
75 		return (struct clk *)((unsigned long)txx9_gbus_clock / 2 / 4);
76 	if (!strcmp(id, "imbus_clk"))
77 		return (struct clk *)((unsigned long)txx9_gbus_clock / 2);
78 	return ERR_PTR(-ENOENT);
79 }
80 EXPORT_SYMBOL(clk_get);
81 
82 int clk_enable(struct clk *clk)
83 {
84 	return 0;
85 }
86 EXPORT_SYMBOL(clk_enable);
87 
88 void clk_disable(struct clk *clk)
89 {
90 }
91 EXPORT_SYMBOL(clk_disable);
92 
93 unsigned long clk_get_rate(struct clk *clk)
94 {
95 	return (unsigned long)clk;
96 }
97 EXPORT_SYMBOL(clk_get_rate);
98 
99 void clk_put(struct clk *clk)
100 {
101 }
102 EXPORT_SYMBOL(clk_put);
103 
104 /* GPIO support */
105 
106 #ifdef CONFIG_GENERIC_GPIO
107 int gpio_to_irq(unsigned gpio)
108 {
109 	return -EINVAL;
110 }
111 EXPORT_SYMBOL(gpio_to_irq);
112 
113 int irq_to_gpio(unsigned irq)
114 {
115 	return -EINVAL;
116 }
117 EXPORT_SYMBOL(irq_to_gpio);
118 #endif
119 
120 extern struct txx9_board_vec jmr3927_vec;
121 extern struct txx9_board_vec rbtx4927_vec;
122 extern struct txx9_board_vec rbtx4937_vec;
123 extern struct txx9_board_vec rbtx4938_vec;
124 
125 struct txx9_board_vec *txx9_board_vec __initdata;
126 static char txx9_system_type[32];
127 
128 void __init prom_init_cmdline(void)
129 {
130 	int argc = (int)fw_arg0;
131 	char **argv = (char **)fw_arg1;
132 	int i;			/* Always ignore the "-c" at argv[0] */
133 #ifdef CONFIG_64BIT
134 	char *fixed_argv[32];
135 	for (i = 0; i < argc; i++)
136 		fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
137 	argv = fixed_argv;
138 #endif
139 
140 	/* ignore all built-in args if any f/w args given */
141 	if (argc > 1)
142 		*arcs_cmdline = '\0';
143 
144 	for (i = 1; i < argc; i++) {
145 		if (i != 1)
146 			strcat(arcs_cmdline, " ");
147 		strcat(arcs_cmdline, argv[i]);
148 	}
149 }
150 
151 void __init prom_init(void)
152 {
153 #ifdef CONFIG_CPU_TX39XX
154 	txx9_board_vec = &jmr3927_vec;
155 #endif
156 #ifdef CONFIG_CPU_TX49XX
157 	switch (TX4938_REV_PCODE()) {
158 #ifdef CONFIG_TOSHIBA_RBTX4927
159 	case 0x4927:
160 		txx9_board_vec = &rbtx4927_vec;
161 		break;
162 	case 0x4937:
163 		txx9_board_vec = &rbtx4937_vec;
164 		break;
165 #endif
166 #ifdef CONFIG_TOSHIBA_RBTX4938
167 	case 0x4938:
168 		txx9_board_vec = &rbtx4938_vec;
169 		break;
170 #endif
171 	}
172 #endif
173 
174 	strcpy(txx9_system_type, txx9_board_vec->system);
175 
176 	txx9_board_vec->prom_init();
177 }
178 
179 void __init prom_free_prom_memory(void)
180 {
181 }
182 
183 const char *get_system_type(void)
184 {
185 	return txx9_system_type;
186 }
187 
188 char * __init prom_getcmdline(void)
189 {
190 	return &(arcs_cmdline[0]);
191 }
192 
193 static void __noreturn txx9_machine_halt(void)
194 {
195 	local_irq_disable();
196 	clear_c0_status(ST0_IM);
197 	while (1) {
198 		if (cpu_wait) {
199 			(*cpu_wait)();
200 			if (cpu_has_counter) {
201 				/*
202 				 * Clear counter interrupt while it
203 				 * breaks WAIT instruction even if
204 				 * masked.
205 				 */
206 				write_c0_compare(0);
207 			}
208 		}
209 	}
210 }
211 
212 /* Watchdog support */
213 void __init txx9_wdt_init(unsigned long base)
214 {
215 	struct resource res = {
216 		.start	= base,
217 		.end	= base + 0x100 - 1,
218 		.flags	= IORESOURCE_MEM,
219 	};
220 	platform_device_register_simple("txx9wdt", -1, &res, 1);
221 }
222 
223 /* SPI support */
224 void __init txx9_spi_init(int busid, unsigned long base, int irq)
225 {
226 	struct resource res[] = {
227 		{
228 			.start	= base,
229 			.end	= base + 0x20 - 1,
230 			.flags	= IORESOURCE_MEM,
231 		}, {
232 			.start	= irq,
233 			.flags	= IORESOURCE_IRQ,
234 		},
235 	};
236 	platform_device_register_simple("spi_txx9", busid,
237 					res, ARRAY_SIZE(res));
238 }
239 
240 void __init txx9_ethaddr_init(unsigned int id, unsigned char *ethaddr)
241 {
242 	struct platform_device *pdev =
243 		platform_device_alloc("tc35815-mac", id);
244 	if (!pdev ||
245 	    platform_device_add_data(pdev, ethaddr, 6) ||
246 	    platform_device_add(pdev))
247 		platform_device_put(pdev);
248 }
249 
250 /* wrappers */
251 void __init plat_mem_setup(void)
252 {
253 	ioport_resource.start = 0;
254 	ioport_resource.end = ~0UL;	/* no limit */
255 	iomem_resource.start = 0;
256 	iomem_resource.end = ~0UL;	/* no limit */
257 
258 	/* fallback restart/halt routines */
259 	_machine_restart = (void (*)(char *))txx9_machine_halt;
260 	_machine_halt = txx9_machine_halt;
261 	pm_power_off = txx9_machine_halt;
262 
263 #ifdef CONFIG_PCI
264 	pcibios_plat_setup = txx9_pcibios_setup;
265 #endif
266 	txx9_board_vec->mem_setup();
267 }
268 
269 void __init arch_init_irq(void)
270 {
271 	txx9_board_vec->irq_setup();
272 }
273 
274 void __init plat_time_init(void)
275 {
276 	txx9_board_vec->time_init();
277 }
278 
279 static int __init _txx9_arch_init(void)
280 {
281 	if (txx9_board_vec->arch_init)
282 		txx9_board_vec->arch_init();
283 	return 0;
284 }
285 arch_initcall(_txx9_arch_init);
286 
287 static int __init _txx9_device_init(void)
288 {
289 	if (txx9_board_vec->device_init)
290 		txx9_board_vec->device_init();
291 	return 0;
292 }
293 device_initcall(_txx9_device_init);
294 
295 int (*txx9_irq_dispatch)(int pending);
296 asmlinkage void plat_irq_dispatch(void)
297 {
298 	int pending = read_c0_status() & read_c0_cause() & ST0_IM;
299 	int irq = txx9_irq_dispatch(pending);
300 
301 	if (likely(irq >= 0))
302 		do_IRQ(irq);
303 	else
304 		spurious_interrupt();
305 }
306 
307 /* see include/asm-mips/mach-tx39xx/mangle-port.h, for example. */
308 #ifdef NEEDS_TXX9_SWIZZLE_ADDR_B
309 static unsigned long __swizzle_addr_none(unsigned long port)
310 {
311 	return port;
312 }
313 unsigned long (*__swizzle_addr_b)(unsigned long port) = __swizzle_addr_none;
314 EXPORT_SYMBOL(__swizzle_addr_b);
315 #endif
316