micro-support-card.c 4.5 KB

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