prom.c 5.3 KB

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