io64.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. * (C) Copyright 2010
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  4. *
  5. * based on kilauea.c
  6. * by Stefan Roese, DENX Software Engineering, sr@denx.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/ppc4xx.h>
  28. #include <asm/ppc405.h>
  29. #include <libfdt.h>
  30. #include <fdt_support.h>
  31. #include <asm/processor.h>
  32. #include <asm/io.h>
  33. #include <asm/errno.h>
  34. #include <asm/ppc4xx-gpio.h>
  35. #include <flash.h>
  36. #include <pca9698.h>
  37. #include "405ex.h"
  38. #include <gdsys_fpga.h>
  39. #include <miiphy.h>
  40. #include <i2c.h>
  41. #include <dtt.h>
  42. DECLARE_GLOBAL_DATA_PTR;
  43. #define PHYREG_CONTROL 0
  44. #define PHYREG_PAGE_ADDRESS 22
  45. #define PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1 16
  46. #define PHYREG_PG2_COPPER_SPECIFIC_CONTROL_2 26
  47. #define PHYREG_PG2_MAC_SPECIFIC_STATUS_1 17
  48. #define PHYREG_PG2_MAC_SPECIFIC_CONTROL 21
  49. #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
  50. #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
  51. #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
  52. #define LATCH3_BASE (CONFIG_SYS_LATCH_BASE + 0x300)
  53. enum {
  54. UNITTYPE_CCD_SWITCH = 1,
  55. };
  56. enum {
  57. HWVER_100 = 0,
  58. HWVER_110 = 1,
  59. };
  60. static inline void blank_string(int size)
  61. {
  62. int i;
  63. for (i = 0; i < size; i++)
  64. putc('\b');
  65. for (i = 0; i < size; i++)
  66. putc(' ');
  67. for (i = 0; i < size; i++)
  68. putc('\b');
  69. }
  70. /*
  71. * Board early initialization function
  72. */
  73. int misc_init_r(void)
  74. {
  75. /* startup fans */
  76. dtt_init();
  77. #ifdef CONFIG_ENV_IS_IN_FLASH
  78. /* Monitor protection ON by default */
  79. flash_protect(FLAG_PROTECT_SET,
  80. -CONFIG_SYS_MONITOR_LEN,
  81. 0xffffffff,
  82. &flash_info[0]);
  83. #endif
  84. return 0;
  85. }
  86. static void print_fpga_info(unsigned dev)
  87. {
  88. ihs_fpga_t *fpga = (ihs_fpga_t *) CONFIG_SYS_FPGA_BASE(dev);
  89. u16 versions = in_le16(&fpga->versions);
  90. u16 fpga_version = in_le16(&fpga->fpga_version);
  91. u16 fpga_features = in_le16(&fpga->fpga_features);
  92. int fpga_state = get_fpga_state(dev);
  93. unsigned unit_type;
  94. unsigned hardware_version;
  95. unsigned feature_channels;
  96. unsigned feature_expansion;
  97. printf("FPGA%d: ", dev);
  98. if (fpga_state & FPGA_STATE_PLATFORM)
  99. printf("(legacy) ");
  100. if (fpga_state & FPGA_STATE_DONE_FAILED) {
  101. printf(" done timed out\n");
  102. return;
  103. }
  104. if (fpga_state & FPGA_STATE_REFLECTION_FAILED) {
  105. printf(" refelectione test failed\n");
  106. return;
  107. }
  108. unit_type = (versions & 0xf000) >> 12;
  109. hardware_version = versions & 0x000f;
  110. feature_channels = fpga_features & 0x007f;
  111. feature_expansion = fpga_features & (1<<15);
  112. switch (unit_type) {
  113. case UNITTYPE_CCD_SWITCH:
  114. printf("CCD-Switch");
  115. break;
  116. default:
  117. printf("UnitType %d(not supported)", unit_type);
  118. break;
  119. }
  120. switch (hardware_version) {
  121. case HWVER_100:
  122. printf(" HW-Ver 1.00\n");
  123. break;
  124. case HWVER_110:
  125. printf(" HW-Ver 1.10\n");
  126. break;
  127. default:
  128. printf(" HW-Ver %d(not supported)\n",
  129. hardware_version);
  130. break;
  131. }
  132. printf(" FPGA V %d.%02d, features:",
  133. fpga_version / 100, fpga_version % 100);
  134. printf(" %d channel(s)", feature_channels);
  135. printf(", expansion %ssupported\n", feature_expansion ? "" : "un");
  136. }
  137. int checkboard(void)
  138. {
  139. char *s = getenv("serial#");
  140. printf("Board: CATCenter Io64\n");
  141. if (s != NULL) {
  142. puts(", serial# ");
  143. puts(s);
  144. }
  145. return 0;
  146. }
  147. int configure_gbit_phy(char *bus, unsigned char addr)
  148. {
  149. unsigned short value;
  150. /* select page 0 */
  151. if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0000))
  152. goto err_out;
  153. /* switch to powerdown */
  154. if (miiphy_read(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
  155. &value))
  156. goto err_out;
  157. if (miiphy_write(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
  158. value | 0x0004))
  159. goto err_out;
  160. /* select page 2 */
  161. if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0002))
  162. goto err_out;
  163. /* disable SGMII autonegotiation */
  164. if (miiphy_write(bus, addr, PHYREG_PG2_MAC_SPECIFIC_CONTROL, 48))
  165. goto err_out;
  166. /* select page 0 */
  167. if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0000))
  168. goto err_out;
  169. /* switch from powerdown to normal operation */
  170. if (miiphy_read(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
  171. &value))
  172. goto err_out;
  173. if (miiphy_write(bus, addr, PHYREG_PG0_COPPER_SPECIFIC_CONTROL_1,
  174. value & ~0x0004))
  175. goto err_out;
  176. /* reset phy so settings take effect */
  177. if (miiphy_write(bus, addr, PHYREG_CONTROL, 0x9140))
  178. goto err_out;
  179. return 0;
  180. err_out:
  181. printf("Error writing to the PHY addr=%02x\n", addr);
  182. return -1;
  183. }
  184. int verify_gbit_phy(char *bus, unsigned char addr)
  185. {
  186. unsigned short value;
  187. /* select page 2 */
  188. if (miiphy_write(bus, addr, PHYREG_PAGE_ADDRESS, 0x0002))
  189. goto err_out;
  190. /* verify SGMII link status */
  191. if (miiphy_read(bus, addr, PHYREG_PG2_MAC_SPECIFIC_STATUS_1, &value))
  192. goto err_out;
  193. if (!(value & (1 << 10)))
  194. return -2;
  195. return 0;
  196. err_out:
  197. printf("Error writing to the PHY addr=%02x\n", addr);
  198. return -1;
  199. }
  200. int last_stage_init(void)
  201. {
  202. unsigned int k;
  203. unsigned int fpga;
  204. ihs_fpga_t *fpga0 = (ihs_fpga_t *) CONFIG_SYS_FPGA_BASE(0);
  205. ihs_fpga_t *fpga1 = (ihs_fpga_t *) CONFIG_SYS_FPGA_BASE(1);
  206. int failed = 0;
  207. char str_phys[] = "Setup PHYs -";
  208. char str_serdes[] = "Start SERDES blocks";
  209. char str_channels[] = "Start FPGA channels";
  210. char str_locks[] = "Verify SERDES locks";
  211. char str_hicb[] = "Verify HICB status";
  212. char str_status[] = "Verify PHY status -";
  213. char slash[] = "\\|/-\\|/-";
  214. print_fpga_info(0);
  215. print_fpga_info(1);
  216. /* setup Gbit PHYs */
  217. puts("TRANS: ");
  218. puts(str_phys);
  219. miiphy_register(CONFIG_SYS_GBIT_MII_BUSNAME,
  220. bb_miiphy_read, bb_miiphy_write);
  221. for (k = 0; k < 32; ++k) {
  222. configure_gbit_phy(CONFIG_SYS_GBIT_MII_BUSNAME, k);
  223. putc('\b');
  224. putc(slash[k % 8]);
  225. }
  226. miiphy_register(CONFIG_SYS_GBIT_MII1_BUSNAME,
  227. bb_miiphy_read, bb_miiphy_write);
  228. for (k = 0; k < 32; ++k) {
  229. configure_gbit_phy(CONFIG_SYS_GBIT_MII1_BUSNAME, k);
  230. putc('\b');
  231. putc(slash[k % 8]);
  232. }
  233. blank_string(strlen(str_phys));
  234. /* take fpga serdes blocks out of reset */
  235. puts(str_serdes);
  236. udelay(500000);
  237. out_le16(&fpga0->quad_serdes_reset, 0);
  238. out_le16(&fpga1->quad_serdes_reset, 0);
  239. blank_string(strlen(str_serdes));
  240. /* take channels out of reset */
  241. puts(str_channels);
  242. udelay(500000);
  243. for (fpga = 0; fpga < 2; ++fpga) {
  244. u16 *ch0_config_int = &(fpga ? fpga1 : fpga0)->ch0_config_int;
  245. for (k = 0; k < 32; ++k)
  246. out_le16(ch0_config_int + 4 * k, 0);
  247. }
  248. blank_string(strlen(str_channels));
  249. /* verify channels serdes lock */
  250. puts(str_locks);
  251. udelay(500000);
  252. for (fpga = 0; fpga < 2; ++fpga) {
  253. u16 *ch0_status_int = &(fpga ? fpga1 : fpga0)->ch0_status_int;
  254. for (k = 0; k < 32; ++k) {
  255. u16 status = in_le16(ch0_status_int + 4*k);
  256. if (!(status & (1 << 4))) {
  257. failed = 1;
  258. printf("fpga %d channel %d: no serdes lock\n",
  259. fpga, k);
  260. }
  261. /* reset events */
  262. out_le16(ch0_status_int + 4*k, status);
  263. }
  264. }
  265. blank_string(strlen(str_locks));
  266. /* verify hicb_status */
  267. puts(str_hicb);
  268. for (fpga = 0; fpga < 2; ++fpga) {
  269. u16 *ch0_hicb_status_int = &(fpga ? fpga1 : fpga0)->ch0_hicb_status_int;
  270. for (k = 0; k < 32; ++k) {
  271. u16 status = in_le16(ch0_hicb_status_int + 4*k);
  272. if (status)
  273. printf("fpga %d hicb %d: hicb status %04x\n",
  274. fpga, k, status);
  275. /* reset events */
  276. out_le16(ch0_hicb_status_int + 4*k, status);
  277. }
  278. }
  279. blank_string(strlen(str_hicb));
  280. /* verify phy status */
  281. puts(str_status);
  282. for (k = 0; k < 32; ++k) {
  283. if (verify_gbit_phy(CONFIG_SYS_GBIT_MII_BUSNAME, k)) {
  284. printf("verify baseboard phy %d failed\n", k);
  285. failed = 1;
  286. }
  287. putc('\b');
  288. putc(slash[k % 8]);
  289. }
  290. for (k = 0; k < 32; ++k) {
  291. if (verify_gbit_phy(CONFIG_SYS_GBIT_MII1_BUSNAME, k)) {
  292. printf("verify extensionboard phy %d failed\n", k);
  293. failed = 1;
  294. }
  295. putc('\b');
  296. putc(slash[k % 8]);
  297. }
  298. blank_string(strlen(str_status));
  299. printf("Starting 64 channels %s\n", failed ? "failed" : "ok");
  300. return 0;
  301. }
  302. void gd405ex_init(void)
  303. {
  304. unsigned int k;
  305. if (i2c_probe(0x22)) { /* i2c_probe returns 0 on success */
  306. for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
  307. gd->fpga_state[k] |= FPGA_STATE_PLATFORM;
  308. } else {
  309. pca9698_direction_output(0x22, 39, 1);
  310. }
  311. }
  312. void gd405ex_set_fpga_reset(unsigned state)
  313. {
  314. int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
  315. if (legacy) {
  316. if (state) {
  317. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
  318. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
  319. } else {
  320. out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
  321. out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
  322. }
  323. } else {
  324. pca9698_set_value(0x22, 39, state ? 0 : 1);
  325. }
  326. }
  327. void gd405ex_setup_hw(void)
  328. {
  329. gpio_write_bit(CONFIG_SYS_GPIO_STARTUP_FINISHED_N, 0);
  330. gpio_write_bit(CONFIG_SYS_GPIO_STARTUP_FINISHED, 1);
  331. }
  332. int gd405ex_get_fpga_done(unsigned fpga)
  333. {
  334. int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
  335. if (legacy)
  336. return in_le16((void *)LATCH3_BASE)
  337. & CONFIG_SYS_FPGA_DONE(fpga);
  338. else
  339. return pca9698_get_value(0x22, fpga ? 9 : 8);
  340. }