micro-support-card.c 4.5 KB

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