lasat_board.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * Thomas Horsten <thh@lasat.com>
  3. * Copyright (C) 2000 LASAT Networks A/S.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. *
  18. * Routines specific to the LASAT boards
  19. */
  20. #include <linux/types.h>
  21. #include <linux/crc32.h>
  22. #include <asm/lasat/lasat.h>
  23. #include <linux/kernel.h>
  24. #include <linux/string.h>
  25. #include <linux/ctype.h>
  26. #include <linux/mutex.h>
  27. #include <asm/addrspace.h>
  28. #include "at93c.h"
  29. /* New model description table */
  30. #include "lasat_models.h"
  31. static DEFINE_MUTEX(lasat_eeprom_mutex);
  32. #define EEPROM_CRC(data, len) (~crc32(~0, data, len))
  33. struct lasat_info lasat_board_info;
  34. int EEPROMRead(unsigned int pos, unsigned char *data, int len)
  35. {
  36. int i;
  37. for (i = 0; i < len; i++)
  38. *data++ = at93c_read(pos++);
  39. return 0;
  40. }
  41. int EEPROMWrite(unsigned int pos, unsigned char *data, int len)
  42. {
  43. int i;
  44. for (i = 0; i < len; i++)
  45. at93c_write(pos++, *data++);
  46. return 0;
  47. }
  48. static void init_flash_sizes(void)
  49. {
  50. unsigned long *lb = lasat_board_info.li_flashpart_base;
  51. unsigned long *ls = lasat_board_info.li_flashpart_size;
  52. int i;
  53. ls[LASAT_MTD_BOOTLOADER] = 0x40000;
  54. ls[LASAT_MTD_SERVICE] = 0xC0000;
  55. ls[LASAT_MTD_NORMAL] = 0x100000;
  56. if (!IS_LASAT_200()) {
  57. lasat_board_info.li_flash_base = 0x1e000000;
  58. lb[LASAT_MTD_BOOTLOADER] = 0x1e400000;
  59. if (lasat_board_info.li_flash_size > 0x200000) {
  60. ls[LASAT_MTD_CONFIG] = 0x100000;
  61. ls[LASAT_MTD_FS] = 0x500000;
  62. }
  63. } else {
  64. lasat_board_info.li_flash_base = 0x10000000;
  65. if (lasat_board_info.li_flash_size < 0x1000000) {
  66. lb[LASAT_MTD_BOOTLOADER] = 0x10000000;
  67. ls[LASAT_MTD_CONFIG] = 0x100000;
  68. if (lasat_board_info.li_flash_size >= 0x400000)
  69. ls[LASAT_MTD_FS] =
  70. lasat_board_info.li_flash_size - 0x300000;
  71. }
  72. }
  73. for (i = 1; i < LASAT_MTD_LAST; i++)
  74. lb[i] = lb[i-1] + ls[i-1];
  75. }
  76. int lasat_init_board_info(void)
  77. {
  78. int c;
  79. unsigned long crc;
  80. unsigned long cfg0, cfg1;
  81. const struct product_info *ppi;
  82. int i_n_base_models = N_BASE_MODELS;
  83. const char * const * i_txt_base_models = txt_base_models;
  84. int i_n_prids = N_PRIDS;
  85. memset(&lasat_board_info, 0, sizeof(lasat_board_info));
  86. /* First read the EEPROM info */
  87. EEPROMRead(0, (unsigned char *)&lasat_board_info.li_eeprom_info,
  88. sizeof(struct lasat_eeprom_struct));
  89. /* Check the CRC */
  90. crc = EEPROM_CRC((unsigned char *)(&lasat_board_info.li_eeprom_info),
  91. sizeof(struct lasat_eeprom_struct) - 4);
  92. if (crc != lasat_board_info.li_eeprom_info.crc32) {
  93. printk(KERN_WARNING "WARNING...\nWARNING...\nEEPROM CRC does "
  94. "not match calculated, attempting to soldier on...\n");
  95. }
  96. if (lasat_board_info.li_eeprom_info.version != LASAT_EEPROM_VERSION) {
  97. printk(KERN_WARNING "WARNING...\nWARNING...\nEEPROM version "
  98. "%d, wanted version %d, attempting to soldier on...\n",
  99. (unsigned int)lasat_board_info.li_eeprom_info.version,
  100. LASAT_EEPROM_VERSION);
  101. }
  102. cfg0 = lasat_board_info.li_eeprom_info.cfg[0];
  103. cfg1 = lasat_board_info.li_eeprom_info.cfg[1];
  104. if (LASAT_W0_DSCTYPE(cfg0) != 1) {
  105. printk(KERN_WARNING "WARNING...\nWARNING...\n"
  106. "Invalid configuration read from EEPROM, attempting to "
  107. "soldier on...");
  108. }
  109. /* We have a valid configuration */
  110. switch (LASAT_W0_SDRAMBANKSZ(cfg0)) {
  111. case 0:
  112. lasat_board_info.li_memsize = 0x0800000;
  113. break;
  114. case 1:
  115. lasat_board_info.li_memsize = 0x1000000;
  116. break;
  117. case 2:
  118. lasat_board_info.li_memsize = 0x2000000;
  119. break;
  120. case 3:
  121. lasat_board_info.li_memsize = 0x4000000;
  122. break;
  123. case 4:
  124. lasat_board_info.li_memsize = 0x8000000;
  125. break;
  126. default:
  127. lasat_board_info.li_memsize = 0;
  128. }
  129. switch (LASAT_W0_SDRAMBANKS(cfg0)) {
  130. case 0:
  131. break;
  132. case 1:
  133. lasat_board_info.li_memsize *= 2;
  134. break;
  135. default:
  136. break;
  137. }
  138. switch (LASAT_W0_BUSSPEED(cfg0)) {
  139. case 0x0:
  140. lasat_board_info.li_bus_hz = 60000000;
  141. break;
  142. case 0x1:
  143. lasat_board_info.li_bus_hz = 66000000;
  144. break;
  145. case 0x2:
  146. lasat_board_info.li_bus_hz = 66666667;
  147. break;
  148. case 0x3:
  149. lasat_board_info.li_bus_hz = 80000000;
  150. break;
  151. case 0x4:
  152. lasat_board_info.li_bus_hz = 83333333;
  153. break;
  154. case 0x5:
  155. lasat_board_info.li_bus_hz = 100000000;
  156. break;
  157. }
  158. switch (LASAT_W0_CPUCLK(cfg0)) {
  159. case 0x0:
  160. lasat_board_info.li_cpu_hz =
  161. lasat_board_info.li_bus_hz;
  162. break;
  163. case 0x1:
  164. lasat_board_info.li_cpu_hz =
  165. lasat_board_info.li_bus_hz +
  166. (lasat_board_info.li_bus_hz >> 1);
  167. break;
  168. case 0x2:
  169. lasat_board_info.li_cpu_hz =
  170. lasat_board_info.li_bus_hz +
  171. lasat_board_info.li_bus_hz;
  172. break;
  173. case 0x3:
  174. lasat_board_info.li_cpu_hz =
  175. lasat_board_info.li_bus_hz +
  176. lasat_board_info.li_bus_hz +
  177. (lasat_board_info.li_bus_hz >> 1);
  178. break;
  179. case 0x4:
  180. lasat_board_info.li_cpu_hz =
  181. lasat_board_info.li_bus_hz +
  182. lasat_board_info.li_bus_hz +
  183. lasat_board_info.li_bus_hz;
  184. break;
  185. }
  186. /* Flash size */
  187. switch (LASAT_W1_FLASHSIZE(cfg1)) {
  188. case 0:
  189. lasat_board_info.li_flash_size = 0x200000;
  190. break;
  191. case 1:
  192. lasat_board_info.li_flash_size = 0x400000;
  193. break;
  194. case 2:
  195. lasat_board_info.li_flash_size = 0x800000;
  196. break;
  197. case 3:
  198. lasat_board_info.li_flash_size = 0x1000000;
  199. break;
  200. case 4:
  201. lasat_board_info.li_flash_size = 0x2000000;
  202. break;
  203. }
  204. init_flash_sizes();
  205. lasat_board_info.li_bmid = LASAT_W0_BMID(cfg0);
  206. lasat_board_info.li_prid = lasat_board_info.li_eeprom_info.prid;
  207. if (lasat_board_info.li_prid == 0xffff || lasat_board_info.li_prid == 0)
  208. lasat_board_info.li_prid = lasat_board_info.li_bmid;
  209. /* Base model stuff */
  210. if (lasat_board_info.li_bmid > i_n_base_models)
  211. lasat_board_info.li_bmid = i_n_base_models;
  212. strcpy(lasat_board_info.li_bmstr,
  213. i_txt_base_models[lasat_board_info.li_bmid]);
  214. /* Product ID dependent values */
  215. c = lasat_board_info.li_prid;
  216. if (c >= i_n_prids) {
  217. strcpy(lasat_board_info.li_namestr, "Unknown Model");
  218. strcpy(lasat_board_info.li_typestr, "Unknown Type");
  219. } else {
  220. ppi = &vendor_info_table[0].vi_product_info[c];
  221. strcpy(lasat_board_info.li_namestr, ppi->pi_name);
  222. if (ppi->pi_type)
  223. strcpy(lasat_board_info.li_typestr, ppi->pi_type);
  224. else
  225. sprintf(lasat_board_info.li_typestr, "%d", 10 * c);
  226. }
  227. return 0;
  228. }
  229. void lasat_write_eeprom_info(void)
  230. {
  231. unsigned long crc;
  232. mutex_lock(&lasat_eeprom_mutex);
  233. /* Generate the CRC */
  234. crc = EEPROM_CRC((unsigned char *)(&lasat_board_info.li_eeprom_info),
  235. sizeof(struct lasat_eeprom_struct) - 4);
  236. lasat_board_info.li_eeprom_info.crc32 = crc;
  237. /* Write the EEPROM info */
  238. EEPROMWrite(0, (unsigned char *)&lasat_board_info.li_eeprom_info,
  239. sizeof(struct lasat_eeprom_struct));
  240. mutex_unlock(&lasat_eeprom_mutex);
  241. }