prom.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright 2002 Momentum Computer Inc.
  3. * Author: Matthew Dharm <mdharm@momenco.com>
  4. *
  5. * Louis Hamilton, Red Hat, Inc.
  6. * hamilton@redhat.com [MIPS64 modifications]
  7. *
  8. * Based on Ocelot Linux port, which is
  9. * Copyright 2001 MontaVista Software Inc.
  10. * Author: jsun@mvista.com or jsun@junsun.net
  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. #include <linux/config.h>
  18. #include <linux/init.h>
  19. #include <linux/mm.h>
  20. #include <linux/sched.h>
  21. #include <linux/bootmem.h>
  22. #include <asm/addrspace.h>
  23. #include <asm/bootinfo.h>
  24. #include <asm/mv64340.h>
  25. #include <asm/pmon.h>
  26. #include "ocelot_c_fpga.h"
  27. struct callvectors* debug_vectors;
  28. extern unsigned long marvell_base;
  29. extern unsigned long cpu_clock;
  30. #ifdef CONFIG_MV643XX_ETH
  31. extern unsigned char prom_mac_addr_base[6];
  32. #endif
  33. const char *get_system_type(void)
  34. {
  35. #ifdef CONFIG_CPU_SR71000
  36. return "Momentum Ocelot-CS";
  37. #else
  38. return "Momentum Ocelot-C";
  39. #endif
  40. }
  41. #ifdef CONFIG_MV643XX_ETH
  42. static void burn_clocks(void)
  43. {
  44. int i;
  45. /* this loop should burn at least 1us -- this should be plenty */
  46. for (i = 0; i < 0x10000; i++)
  47. ;
  48. }
  49. static u8 exchange_bit(u8 val, u8 cs)
  50. {
  51. /* place the data */
  52. OCELOT_FPGA_WRITE((val << 2) | cs, EEPROM_MODE);
  53. burn_clocks();
  54. /* turn the clock on */
  55. OCELOT_FPGA_WRITE((val << 2) | cs | 0x2, EEPROM_MODE);
  56. burn_clocks();
  57. /* turn the clock off and read-strobe */
  58. OCELOT_FPGA_WRITE((val << 2) | cs | 0x10, EEPROM_MODE);
  59. /* return the data */
  60. return ((OCELOT_FPGA_READ(EEPROM_MODE) >> 3) & 0x1);
  61. }
  62. void get_mac(char dest[6])
  63. {
  64. u8 read_opcode[12] = {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  65. int i,j;
  66. for (i = 0; i < 12; i++)
  67. exchange_bit(read_opcode[i], 1);
  68. for (j = 0; j < 6; j++) {
  69. dest[j] = 0;
  70. for (i = 0; i < 8; i++) {
  71. dest[j] <<= 1;
  72. dest[j] |= exchange_bit(0, 1);
  73. }
  74. }
  75. /* turn off CS */
  76. exchange_bit(0,0);
  77. }
  78. #endif
  79. #ifdef CONFIG_64BIT
  80. unsigned long signext(unsigned long addr)
  81. {
  82. addr &= 0xffffffff;
  83. return (unsigned long)((int)addr);
  84. }
  85. void *get_arg(unsigned long args, int arc)
  86. {
  87. unsigned long ul;
  88. unsigned char *puc, uc;
  89. args += (arc * 4);
  90. ul = (unsigned long)signext(args);
  91. puc = (unsigned char *)ul;
  92. if (puc == 0)
  93. return (void *)0;
  94. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  95. uc = *puc++;
  96. ul = (unsigned long)uc;
  97. uc = *puc++;
  98. ul |= (((unsigned long)uc) << 8);
  99. uc = *puc++;
  100. ul |= (((unsigned long)uc) << 16);
  101. uc = *puc++;
  102. ul |= (((unsigned long)uc) << 24);
  103. #else /* CONFIG_CPU_LITTLE_ENDIAN */
  104. uc = *puc++;
  105. ul = ((unsigned long)uc) << 24;
  106. uc = *puc++;
  107. ul |= (((unsigned long)uc) << 16);
  108. uc = *puc++;
  109. ul |= (((unsigned long)uc) << 8);
  110. uc = *puc++;
  111. ul |= ((unsigned long)uc);
  112. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  113. ul = signext(ul);
  114. return (void *)ul;
  115. }
  116. char *arg64(unsigned long addrin, int arg_index)
  117. {
  118. unsigned long args;
  119. char *p;
  120. args = signext(addrin);
  121. p = (char *)get_arg(args, arg_index);
  122. return p;
  123. }
  124. #endif /* CONFIG_64BIT */
  125. void __init prom_init(void)
  126. {
  127. int argc = fw_arg0;
  128. char **arg = (char **) fw_arg1;
  129. char **env = (char **) fw_arg2;
  130. struct callvectors *cv = (struct callvectors *) fw_arg3;
  131. int i;
  132. #ifdef CONFIG_64BIT
  133. char *ptr;
  134. printk("prom_init - MIPS64\n");
  135. /* save the PROM vectors for debugging use */
  136. debug_vectors = (struct callvectors *)signext((unsigned long)cv);
  137. /* arg[0] is "g", the rest is boot parameters */
  138. arcs_cmdline[0] = '\0';
  139. for (i = 1; i < argc; i++) {
  140. ptr = (char *)arg64((unsigned long)arg, i);
  141. if ((strlen(arcs_cmdline) + strlen(ptr) + 1) >=
  142. sizeof(arcs_cmdline))
  143. break;
  144. strcat(arcs_cmdline, ptr);
  145. strcat(arcs_cmdline, " ");
  146. }
  147. i = 0;
  148. while (1) {
  149. ptr = (char *)arg64((unsigned long)env, i);
  150. if (! ptr)
  151. break;
  152. if (strncmp("gtbase", ptr, strlen("gtbase")) == 0) {
  153. marvell_base = simple_strtol(ptr + strlen("gtbase="),
  154. NULL, 16);
  155. if ((marvell_base & 0xffffffff00000000) == 0)
  156. marvell_base |= 0xffffffff00000000;
  157. printk("marvell_base set to 0x%016lx\n", marvell_base);
  158. }
  159. if (strncmp("cpuclock", ptr, strlen("cpuclock")) == 0) {
  160. cpu_clock = simple_strtol(ptr + strlen("cpuclock="),
  161. NULL, 10);
  162. printk("cpu_clock set to %d\n", cpu_clock);
  163. }
  164. i++;
  165. }
  166. printk("arcs_cmdline: %s\n", arcs_cmdline);
  167. #else /* CONFIG_64BIT */
  168. /* save the PROM vectors for debugging use */
  169. debug_vectors = cv;
  170. /* arg[0] is "g", the rest is boot parameters */
  171. arcs_cmdline[0] = '\0';
  172. for (i = 1; i < argc; i++) {
  173. if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
  174. >= sizeof(arcs_cmdline))
  175. break;
  176. strcat(arcs_cmdline, arg[i]);
  177. strcat(arcs_cmdline, " ");
  178. }
  179. while (*env) {
  180. if (strncmp("gtbase", *env, strlen("gtbase")) == 0) {
  181. marvell_base = simple_strtol(*env + strlen("gtbase="),
  182. NULL, 16);
  183. }
  184. if (strncmp("cpuclock", *env, strlen("cpuclock")) == 0) {
  185. cpu_clock = simple_strtol(*env + strlen("cpuclock="),
  186. NULL, 10);
  187. }
  188. env++;
  189. }
  190. #endif /* CONFIG_64BIT */
  191. mips_machgroup = MACH_GROUP_MOMENCO;
  192. mips_machtype = MACH_MOMENCO_OCELOT_C;
  193. #ifdef CONFIG_MV643XX_ETH
  194. /* get the base MAC address for on-board ethernet ports */
  195. get_mac(prom_mac_addr_base);
  196. #endif
  197. #ifndef CONFIG_64BIT
  198. debug_vectors->printf("Booting Linux kernel...\n");
  199. #endif
  200. }
  201. unsigned long __init prom_free_prom_memory(void)
  202. {
  203. return 0;
  204. }