prom.c 5.4 KB

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