2 * Copyright 2002 Momentum Computer Inc.
3 * Author: Matthew Dharm <mdharm@momenco.com>
5 * Louis Hamilton, Red Hat, Inc.
6 * hamilton@redhat.com [MIPS64 modifications]
8 * Based on Ocelot Linux port, which is
9 * Copyright 2001 MontaVista Software Inc.
10 * Author: jsun@mvista.com or jsun@junsun.net
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.
17 #include <linux/config.h>
18 #include <linux/init.h>
20 #include <linux/sched.h>
21 #include <linux/bootmem.h>
23 #include <asm/addrspace.h>
24 #include <asm/bootinfo.h>
25 #include <asm/mv64340.h>
27 #include "ocelot_c_fpga.h"
30 int (*open) (char*, int, int);
32 int (*read) (int, void*, int);
33 int (*write) (int, void*, int);
34 off_t (*lseek) (int, off_t, int);
35 int (*printf) (const char*, ...);
36 void (*cacheflush) (void);
37 char* (*gets) (char*);
40 struct callvectors* debug_vectors;
42 extern unsigned long mv64340_base;
43 extern unsigned long cpu_clock;
45 #ifdef CONFIG_MV64340_ETH
46 extern unsigned char prom_mac_addr_base[6];
49 const char *get_system_type(void)
51 #ifdef CONFIG_CPU_SR71000
52 return "Momentum Ocelot-CS";
54 return "Momentum Ocelot-C";
58 #ifdef CONFIG_MV64340_ETH
59 static void burn_clocks(void)
63 /* this loop should burn at least 1us -- this should be plenty */
64 for (i = 0; i < 0x10000; i++)
68 static u8 exchange_bit(u8 val, u8 cs)
71 OCELOT_FPGA_WRITE((val << 2) | cs, EEPROM_MODE);
74 /* turn the clock on */
75 OCELOT_FPGA_WRITE((val << 2) | cs | 0x2, EEPROM_MODE);
78 /* turn the clock off and read-strobe */
79 OCELOT_FPGA_WRITE((val << 2) | cs | 0x10, EEPROM_MODE);
82 return ((OCELOT_FPGA_READ(EEPROM_MODE) >> 3) & 0x1);
85 void get_mac(char dest[6])
87 u8 read_opcode[12] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
90 for (i = 0; i < 12; i++)
91 exchange_bit(read_opcode[i], 1);
93 for (j = 0; j < 6; j++) {
95 for (i = 0; i < 8; i++) {
97 dest[j] |= exchange_bit(0, 1);
109 unsigned long signext(unsigned long addr)
112 return (unsigned long)((int)addr);
115 void *get_arg(unsigned long args, int arc)
118 unsigned char *puc, uc;
121 ul = (unsigned long)signext(args);
122 puc = (unsigned char *)ul;
126 #ifdef CONFIG_CPU_LITTLE_ENDIAN
128 ul = (unsigned long)uc;
130 ul |= (((unsigned long)uc) << 8);
132 ul |= (((unsigned long)uc) << 16);
134 ul |= (((unsigned long)uc) << 24);
135 #else /* CONFIG_CPU_LITTLE_ENDIAN */
137 ul = ((unsigned long)uc) << 24;
139 ul |= (((unsigned long)uc) << 16);
141 ul |= (((unsigned long)uc) << 8);
143 ul |= ((unsigned long)uc);
144 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
149 char *arg64(unsigned long addrin, int arg_index)
153 args = signext(addrin);
154 p = (char *)get_arg(args, arg_index);
157 #endif /* CONFIG_MIPS64 */
160 /* [jsun@junsun.net] PMON passes arguments in C main() style */
161 void __init prom_init(void)
164 char **arg = (char **) fw_arg1;
165 char **env = (char **) fw_arg2;
170 printk("prom_init - MIPS64\n");
171 /* save the PROM vectors for debugging use */
172 debug_vectors = (struct callvectors *)signext((unsigned long)cv);
174 /* arg[0] is "g", the rest is boot parameters */
175 arcs_cmdline[0] = '\0';
177 for (i = 1; i < argc; i++) {
178 ptr = (char *)arg64((unsigned long)arg, i);
179 if ((strlen(arcs_cmdline) + strlen(ptr) + 1) >=
180 sizeof(arcs_cmdline))
182 strcat(arcs_cmdline, ptr);
183 strcat(arcs_cmdline, " ");
187 ptr = (char *)arg64((unsigned long)env, i);
191 if (strncmp("gtbase", ptr, strlen("gtbase")) == 0) {
192 mv64340_base = simple_strtol(ptr + strlen("gtbase="),
195 if ((mv64340_base & 0xffffffff00000000) == 0)
196 mv64340_base |= 0xffffffff00000000;
198 printk("mv64340_base set to 0x%016lx\n", mv64340_base);
200 if (strncmp("cpuclock", ptr, strlen("cpuclock")) == 0) {
201 cpu_clock = simple_strtol(ptr + strlen("cpuclock="),
203 printk("cpu_clock set to %d\n", cpu_clock);
207 printk("arcs_cmdline: %s\n", arcs_cmdline);
209 #else /* CONFIG_MIPS64 */
210 /* save the PROM vectors for debugging use */
213 /* arg[0] is "g", the rest is boot parameters */
214 arcs_cmdline[0] = '\0';
215 for (i = 1; i < argc; i++) {
216 if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
217 >= sizeof(arcs_cmdline))
219 strcat(arcs_cmdline, arg[i]);
220 strcat(arcs_cmdline, " ");
224 if (strncmp("gtbase", *env, strlen("gtbase")) == 0) {
225 mv64340_base = simple_strtol(*env + strlen("gtbase="),
228 if (strncmp("cpuclock", *env, strlen("cpuclock")) == 0) {
229 cpu_clock = simple_strtol(*env + strlen("cpuclock="),
234 #endif /* CONFIG_MIPS64 */
236 mips_machgroup = MACH_GROUP_MOMENCO;
237 mips_machtype = MACH_MOMENCO_OCELOT_C;
239 #ifdef CONFIG_MV64340_ETH
240 /* get the base MAC address for on-board ethernet ports */
241 get_mac(prom_mac_addr_base);
244 #ifndef CONFIG_MIPS64
245 debug_vectors->printf("Booting Linux kernel...\n");
249 unsigned long __init prom_free_prom_memory(void)