blob: e9f65f79cf2ea0bff6393313385bbebf500db9a3 [file] [log] [blame]
Max Filippov0d456ba2012-11-05 07:37:14 +04001/*
2 *
3 * arch/xtensa/platform/xtavnet/setup.c
4 *
5 * ...
6 *
7 * Authors: Chris Zankel <chris@zankel.net>
8 * Joe Taylor <joe@tensilica.com>
9 *
10 * Copyright 2001 - 2006 Tensilica Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 */
18#include <linux/stddef.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/errno.h>
22#include <linux/reboot.h>
23#include <linux/kdev_t.h>
24#include <linux/types.h>
25#include <linux/major.h>
26#include <linux/console.h>
27#include <linux/delay.h>
28#include <linux/of.h>
29
30#include <asm/timex.h>
31#include <asm/processor.h>
32#include <asm/platform.h>
33#include <asm/bootparam.h>
34#include <platform/lcd.h>
Chris Zankel33c760f2012-11-28 16:52:09 -080035#include <platform/hardware.h>
Max Filippov0d456ba2012-11-05 07:37:14 +040036
37void platform_halt(void)
38{
39 lcd_disp_at_pos(" HALT ", 0);
40 local_irq_disable();
41 while (1)
42 cpu_relax();
43}
44
45void platform_power_off(void)
46{
47 lcd_disp_at_pos("POWEROFF", 0);
48 local_irq_disable();
49 while (1)
50 cpu_relax();
51}
52
53void platform_restart(void)
54{
55 /* Flush and reset the mmu, simulate a processor reset, and
56 * jump to the reset vector. */
57
58
59 __asm__ __volatile__ ("movi a2, 15\n\t"
60 "wsr a2, icountlevel\n\t"
61 "movi a2, 0\n\t"
62 "wsr a2, icount\n\t"
Max Filippovd83ff0b2013-03-04 03:40:42 +040063#if XCHAL_NUM_IBREAK > 0
Max Filippov0d456ba2012-11-05 07:37:14 +040064 "wsr a2, ibreakenable\n\t"
Max Filippovd83ff0b2013-03-04 03:40:42 +040065#endif
Max Filippov50296152015-09-24 23:11:53 +030066#if XCHAL_HAVE_LOOPS
Max Filippov0d456ba2012-11-05 07:37:14 +040067 "wsr a2, lcount\n\t"
Max Filippov50296152015-09-24 23:11:53 +030068#endif
Max Filippov0d456ba2012-11-05 07:37:14 +040069 "movi a2, 0x1f\n\t"
70 "wsr a2, ps\n\t"
71 "isync\n\t"
72 "jx %0\n\t"
73 :
74 : "a" (XCHAL_RESET_VECTOR_VADDR)
75 : "a2"
76 );
77
78 /* control never gets here */
79}
80
81void __init platform_setup(char **cmdline)
82{
83}
84
85#ifdef CONFIG_OF
86
87static void __init update_clock_frequency(struct device_node *node)
88{
89 struct property *newfreq;
90 u32 freq;
91
Chris Zankel33c760f2012-11-28 16:52:09 -080092 if (!of_property_read_u32(node, "clock-frequency", &freq) && freq != 0)
Max Filippov0d456ba2012-11-05 07:37:14 +040093 return;
94
95 newfreq = kzalloc(sizeof(*newfreq) + sizeof(u32), GFP_KERNEL);
96 if (!newfreq)
97 return;
98 newfreq->value = newfreq + 1;
99 newfreq->length = sizeof(freq);
100 newfreq->name = kstrdup("clock-frequency", GFP_KERNEL);
101 if (!newfreq->name) {
102 kfree(newfreq);
103 return;
104 }
105
106 *(u32 *)newfreq->value = cpu_to_be32(*(u32 *)XTFPGA_CLKFRQ_VADDR);
Max Filippov127bc792012-12-22 07:10:11 +0400107 of_update_property(node, newfreq);
Max Filippov0d456ba2012-11-05 07:37:14 +0400108}
109
Chris Zankel33c760f2012-11-28 16:52:09 -0800110#define MAC_LEN 6
111static void __init update_local_mac(struct device_node *node)
112{
113 struct property *newmac;
114 const u8* macaddr;
115 int prop_len;
116
117 macaddr = of_get_property(node, "local-mac-address", &prop_len);
118 if (macaddr == NULL || prop_len != MAC_LEN)
119 return;
120
121 newmac = kzalloc(sizeof(*newmac) + MAC_LEN, GFP_KERNEL);
122 if (newmac == NULL)
123 return;
124
125 newmac->value = newmac + 1;
126 newmac->length = MAC_LEN;
127 newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
128 if (newmac->name == NULL) {
129 kfree(newmac);
130 return;
131 }
132
133 memcpy(newmac->value, macaddr, MAC_LEN);
134 ((u8*)newmac->value)[5] = (*(u32*)DIP_SWITCHES_VADDR) & 0x3f;
Max Filippov127bc792012-12-22 07:10:11 +0400135 of_update_property(node, newmac);
Chris Zankel33c760f2012-11-28 16:52:09 -0800136}
137
Max Filippov0d456ba2012-11-05 07:37:14 +0400138static int __init machine_setup(void)
139{
Max Filippovcdc9af72014-01-29 07:42:46 +0400140 struct device_node *clock;
Chris Zankel33c760f2012-11-28 16:52:09 -0800141 struct device_node *eth = NULL;
Max Filippov0d456ba2012-11-05 07:37:14 +0400142
Max Filippovcdc9af72014-01-29 07:42:46 +0400143 for_each_node_by_name(clock, "main-oscillator")
144 update_clock_frequency(clock);
Chris Zankel33c760f2012-11-28 16:52:09 -0800145
146 if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc")))
147 update_local_mac(eth);
Max Filippov0d456ba2012-11-05 07:37:14 +0400148 return 0;
149}
150arch_initcall(machine_setup);
151
152#endif
153
154/* early initialization */
155
156void __init platform_init(bp_tag_t *first)
157{
158}
159
160/* Heartbeat. */
161
162void platform_heartbeat(void)
163{
164}
165
166#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
167
Baruch Siach54c0af92013-05-27 09:11:59 +0300168void __init platform_calibrate_ccount(void)
Max Filippov0d456ba2012-11-05 07:37:14 +0400169{
170 long clk_freq = 0;
171#ifdef CONFIG_OF
172 struct device_node *cpu =
Baruch Siach42beb762013-12-01 10:13:33 +0200173 of_find_compatible_node(NULL, NULL, "cdns,xtensa-cpu");
Max Filippov0d456ba2012-11-05 07:37:14 +0400174 if (cpu) {
175 u32 freq;
176 update_clock_frequency(cpu);
177 if (!of_property_read_u32(cpu, "clock-frequency", &freq))
178 clk_freq = freq;
179 }
180#endif
181 if (!clk_freq)
182 clk_freq = *(long *)XTFPGA_CLKFRQ_VADDR;
183
Baruch Siache504c4b2013-06-17 11:29:43 +0300184 ccount_freq = clk_freq;
Max Filippov0d456ba2012-11-05 07:37:14 +0400185}
186
187#endif
188
189#ifndef CONFIG_OF
190
191#include <linux/serial_8250.h>
192#include <linux/if.h>
193#include <net/ethoc.h>
Max Filippove0bf6c52013-09-08 06:58:38 +0400194#include <linux/usb/c67x00.h>
Max Filippov0d456ba2012-11-05 07:37:14 +0400195
196/*----------------------------------------------------------------------------
197 * Ethernet -- OpenCores Ethernet MAC (ethoc driver)
198 */
199
Max Filippova558d992013-12-25 05:20:36 +0400200static struct resource ethoc_res[] = {
Max Filippov0d456ba2012-11-05 07:37:14 +0400201 [0] = { /* register space */
202 .start = OETH_REGS_PADDR,
203 .end = OETH_REGS_PADDR + OETH_REGS_SIZE - 1,
204 .flags = IORESOURCE_MEM,
205 },
206 [1] = { /* buffer space */
207 .start = OETH_SRAMBUFF_PADDR,
208 .end = OETH_SRAMBUFF_PADDR + OETH_SRAMBUFF_SIZE - 1,
209 .flags = IORESOURCE_MEM,
210 },
211 [2] = { /* IRQ number */
212 .start = OETH_IRQ,
213 .end = OETH_IRQ,
214 .flags = IORESOURCE_IRQ,
215 },
216};
217
Max Filippova558d992013-12-25 05:20:36 +0400218static struct ethoc_platform_data ethoc_pdata = {
Max Filippov0d456ba2012-11-05 07:37:14 +0400219 /*
220 * The MAC address for these boards is 00:50:c2:13:6f:xx.
221 * The last byte (here as zero) is read from the DIP switches on the
222 * board.
223 */
224 .hwaddr = { 0x00, 0x50, 0xc2, 0x13, 0x6f, 0 },
225 .phy_id = -1,
226};
227
Max Filippova558d992013-12-25 05:20:36 +0400228static struct platform_device ethoc_device = {
Max Filippov0d456ba2012-11-05 07:37:14 +0400229 .name = "ethoc",
230 .id = -1,
231 .num_resources = ARRAY_SIZE(ethoc_res),
232 .resource = ethoc_res,
233 .dev = {
234 .platform_data = &ethoc_pdata,
235 },
236};
237
238/*----------------------------------------------------------------------------
Max Filippove0bf6c52013-09-08 06:58:38 +0400239 * USB Host/Device -- Cypress CY7C67300
240 */
241
242static struct resource c67x00_res[] = {
243 [0] = { /* register space */
244 .start = C67X00_PADDR,
245 .end = C67X00_PADDR + C67X00_SIZE - 1,
246 .flags = IORESOURCE_MEM,
247 },
248 [1] = { /* IRQ number */
249 .start = C67X00_IRQ,
250 .end = C67X00_IRQ,
251 .flags = IORESOURCE_IRQ,
252 },
253};
254
255static struct c67x00_platform_data c67x00_pdata = {
256 .sie_config = C67X00_SIE1_HOST | C67X00_SIE2_UNUSED,
257 .hpi_regstep = 4,
258};
259
260static struct platform_device c67x00_device = {
261 .name = "c67x00",
262 .id = -1,
263 .num_resources = ARRAY_SIZE(c67x00_res),
264 .resource = c67x00_res,
265 .dev = {
266 .platform_data = &c67x00_pdata,
267 },
268};
269
270/*----------------------------------------------------------------------------
Max Filippov0d456ba2012-11-05 07:37:14 +0400271 * UART
272 */
273
Max Filippova558d992013-12-25 05:20:36 +0400274static struct resource serial_resource = {
Max Filippov0d456ba2012-11-05 07:37:14 +0400275 .start = DUART16552_PADDR,
276 .end = DUART16552_PADDR + 0x1f,
277 .flags = IORESOURCE_MEM,
278};
279
Max Filippova558d992013-12-25 05:20:36 +0400280static struct plat_serial8250_port serial_platform_data[] = {
Max Filippov0d456ba2012-11-05 07:37:14 +0400281 [0] = {
282 .mapbase = DUART16552_PADDR,
283 .irq = DUART16552_INTNUM,
284 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST |
285 UPF_IOREMAP,
286 .iotype = UPIO_MEM32,
287 .regshift = 2,
288 .uartclk = 0, /* set in xtavnet_init() */
289 },
290 { },
291};
292
Max Filippova558d992013-12-25 05:20:36 +0400293static struct platform_device xtavnet_uart = {
Max Filippov0d456ba2012-11-05 07:37:14 +0400294 .name = "serial8250",
295 .id = PLAT8250_DEV_PLATFORM,
296 .dev = {
297 .platform_data = serial_platform_data,
298 },
299 .num_resources = 1,
300 .resource = &serial_resource,
301};
302
303/* platform devices */
304static struct platform_device *platform_devices[] __initdata = {
305 &ethoc_device,
Max Filippove0bf6c52013-09-08 06:58:38 +0400306 &c67x00_device,
Max Filippov0d456ba2012-11-05 07:37:14 +0400307 &xtavnet_uart,
308};
309
310
311static int __init xtavnet_init(void)
312{
313 /* Ethernet MAC address. */
314 ethoc_pdata.hwaddr[5] = *(u32 *)DIP_SWITCHES_VADDR;
315
316 /* Clock rate varies among FPGA bitstreams; board specific FPGA register
317 * reports the actual clock rate.
318 */
319 serial_platform_data[0].uartclk = *(long *)XTFPGA_CLKFRQ_VADDR;
320
321
322 /* register platform devices */
323 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
324
325 /* ETHOC driver is a bit quiet; at least display Ethernet MAC, so user
326 * knows whether they set it correctly on the DIP switches.
327 */
328 pr_info("XTFPGA: Ethernet MAC %pM\n", ethoc_pdata.hwaddr);
Max Filippov2bc2fde2014-01-29 07:53:44 +0400329 ethoc_pdata.eth_clkfreq = *(long *)XTFPGA_CLKFRQ_VADDR;
Max Filippov0d456ba2012-11-05 07:37:14 +0400330
331 return 0;
332}
333
334/*
335 * Register to be done during do_initcalls().
336 */
337arch_initcall(xtavnet_init);
338
339#endif /* CONFIG_OF */