micro-support-card.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <linux/ctype.h>
  8. #include <linux/io.h>
  9. #include "micro-support-card.h"
  10. #define MICRO_SUPPORT_CARD_BASE 0x43f00000
  11. #define SMC911X_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x00000)
  12. #define LED_BASE ((MICRO_SUPPORT_CARD_BASE) + 0x90000)
  13. #define NS16550A_BASE ((MICRO_SUPPORT_CARD_BASE) + 0xb0000)
  14. #define MICRO_SUPPORT_CARD_RESET ((MICRO_SUPPORT_CARD_BASE) + 0xd0034)
  15. #define MICRO_SUPPORT_CARD_REVISION ((MICRO_SUPPORT_CARD_BASE) + 0xd00E0)
  16. /*
  17. * 0: reset deassert, 1: reset
  18. *
  19. * bit[0]: LAN, I2C, LED
  20. * bit[1]: UART
  21. */
  22. void support_card_reset_deassert(void)
  23. {
  24. writel(0, MICRO_SUPPORT_CARD_RESET);
  25. }
  26. void support_card_reset(void)
  27. {
  28. writel(3, MICRO_SUPPORT_CARD_RESET);
  29. }
  30. static int support_card_show_revision(void)
  31. {
  32. u32 revision;
  33. revision = readl(MICRO_SUPPORT_CARD_REVISION);
  34. printf("(CPLD version %d.%d)\n", revision >> 4, revision & 0xf);
  35. return 0;
  36. }
  37. int check_support_card(void)
  38. {
  39. printf("SC: Micro Support Card ");
  40. return support_card_show_revision();
  41. }
  42. void support_card_init(void)
  43. {
  44. /*
  45. * After power on, we need to keep the LAN controller in reset state
  46. * for a while. (200 usec)
  47. * Fortunately, enough wait time is already inserted in pll_init()
  48. * function. So we do not have to wait here.
  49. */
  50. support_card_reset_deassert();
  51. }
  52. #if defined(CONFIG_SMC911X)
  53. #include <netdev.h>
  54. int board_eth_init(bd_t *bis)
  55. {
  56. return smc911x_initialize(0, SMC911X_BASE);
  57. }
  58. #endif
  59. #if !defined(CONFIG_SYS_NO_FLASH)
  60. #include <mtd/cfi_flash.h>
  61. struct memory_bank {
  62. phys_addr_t base;
  63. unsigned long size;
  64. };
  65. static int mem_is_flash(const struct memory_bank *mem)
  66. {
  67. const int loop = 128;
  68. u32 *scratch_addr;
  69. u32 saved_value;
  70. int ret = 1;
  71. int i;
  72. /* just in case, use the tail of the memory bank */
  73. scratch_addr = map_physmem(mem->base + mem->size - sizeof(u32) * loop,
  74. sizeof(u32) * loop, MAP_NOCACHE);
  75. for (i = 0; i < loop; i++, scratch_addr++) {
  76. saved_value = readl(scratch_addr);
  77. writel(~saved_value, scratch_addr);
  78. if (readl(scratch_addr) != saved_value) {
  79. /* We assume no memory or SRAM here. */
  80. writel(saved_value, scratch_addr);
  81. ret = 0;
  82. break;
  83. }
  84. }
  85. unmap_physmem(scratch_addr, MAP_NOCACHE);
  86. return ret;
  87. }
  88. /* {address, size} */
  89. static const struct memory_bank memory_banks[] = {
  90. {0x42000000, 0x01f00000},
  91. };
  92. static const struct memory_bank
  93. *flash_banks_list[CONFIG_SYS_MAX_FLASH_BANKS_DETECT];
  94. phys_addr_t cfi_flash_bank_addr(int i)
  95. {
  96. return flash_banks_list[i]->base;
  97. }
  98. unsigned long cfi_flash_bank_size(int i)
  99. {
  100. return flash_banks_list[i]->size;
  101. }
  102. static void detect_num_flash_banks(void)
  103. {
  104. const struct memory_bank *memory_bank, *end;
  105. cfi_flash_num_flash_banks = 0;
  106. memory_bank = memory_banks;
  107. end = memory_bank + ARRAY_SIZE(memory_banks);
  108. for (; memory_bank < end; memory_bank++) {
  109. if (cfi_flash_num_flash_banks >=
  110. CONFIG_SYS_MAX_FLASH_BANKS_DETECT)
  111. break;
  112. if (mem_is_flash(memory_bank)) {
  113. flash_banks_list[cfi_flash_num_flash_banks] =
  114. memory_bank;
  115. debug("flash bank found: base = 0x%lx, size = 0x%lx\n",
  116. memory_bank->base, memory_bank->size);
  117. cfi_flash_num_flash_banks++;
  118. }
  119. }
  120. debug("number of flash banks: %d\n", cfi_flash_num_flash_banks);
  121. }
  122. #else /* CONFIG_SYS_NO_FLASH */
  123. void detect_num_flash_banks(void)
  124. {
  125. };
  126. #endif /* CONFIG_SYS_NO_FLASH */
  127. void support_card_late_init(void)
  128. {
  129. detect_num_flash_banks();
  130. }
  131. static const u8 ledval_num[] = {
  132. 0x7e, /* 0 */
  133. 0x0c, /* 1 */
  134. 0xb6, /* 2 */
  135. 0x9e, /* 3 */
  136. 0xcc, /* 4 */
  137. 0xda, /* 5 */
  138. 0xfa, /* 6 */
  139. 0x4e, /* 7 */
  140. 0xfe, /* 8 */
  141. 0xde, /* 9 */
  142. };
  143. static const u8 ledval_alpha[] = {
  144. 0xee, /* A */
  145. 0xf8, /* B */
  146. 0x72, /* C */
  147. 0xbc, /* D */
  148. 0xf2, /* E */
  149. 0xe2, /* F */
  150. 0x7a, /* G */
  151. 0xe8, /* H */
  152. 0x08, /* I */
  153. 0x3c, /* J */
  154. 0xea, /* K */
  155. 0x70, /* L */
  156. 0x6e, /* M */
  157. 0xa8, /* N */
  158. 0xb8, /* O */
  159. 0xe6, /* P */
  160. 0xce, /* Q */
  161. 0xa0, /* R */
  162. 0xc8, /* S */
  163. 0x8c, /* T */
  164. 0x7c, /* U */
  165. 0x54, /* V */
  166. 0xfc, /* W */
  167. 0xec, /* X */
  168. 0xdc, /* Y */
  169. 0xa4, /* Z */
  170. };
  171. static u8 char2ledval(char c)
  172. {
  173. if (isdigit(c))
  174. return ledval_num[c - '0'];
  175. else if (isalpha(c))
  176. return ledval_alpha[toupper(c) - 'A'];
  177. return 0;
  178. }
  179. void led_puts(const char *s)
  180. {
  181. int i;
  182. u32 val = 0;
  183. if (!s)
  184. return;
  185. for (i = 0; i < 4; i++) {
  186. val <<= 8;
  187. val |= char2ledval(*s);
  188. if (*s != '\0')
  189. s++;
  190. }
  191. writel(~val, LED_BASE);
  192. }