keystone_net.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * Ethernet driver for TI K2HK EVM.
  3. *
  4. * (C) Copyright 2012-2014
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <net.h>
  12. #include <miiphy.h>
  13. #include <malloc.h>
  14. #include <asm/arch/emac_defs.h>
  15. #include <asm/arch/psc_defs.h>
  16. #include <asm/arch/keystone_nav.h>
  17. unsigned int emac_dbg;
  18. unsigned int emac_open;
  19. static unsigned int sys_has_mdio = 1;
  20. #ifdef KEYSTONE2_EMAC_GIG_ENABLE
  21. #define emac_gigabit_enable(x) keystone2_eth_gigabit_enable(x)
  22. #else
  23. #define emac_gigabit_enable(x) /* no gigabit to enable */
  24. #endif
  25. #define RX_BUFF_NUMS 24
  26. #define RX_BUFF_LEN 1520
  27. #define MAX_SIZE_STREAM_BUFFER RX_BUFF_LEN
  28. static u8 rx_buffs[RX_BUFF_NUMS * RX_BUFF_LEN] __aligned(16);
  29. struct rx_buff_desc net_rx_buffs = {
  30. .buff_ptr = rx_buffs,
  31. .num_buffs = RX_BUFF_NUMS,
  32. .buff_len = RX_BUFF_LEN,
  33. .rx_flow = 22,
  34. };
  35. static void keystone2_eth_mdio_enable(void);
  36. static int gen_get_link_speed(int phy_addr);
  37. /* EMAC Addresses */
  38. static volatile struct emac_regs *adap_emac =
  39. (struct emac_regs *)EMAC_EMACSL_BASE_ADDR;
  40. static volatile struct mdio_regs *adap_mdio =
  41. (struct mdio_regs *)EMAC_MDIO_BASE_ADDR;
  42. int keystone2_eth_read_mac_addr(struct eth_device *dev)
  43. {
  44. struct eth_priv_t *eth_priv;
  45. u32 maca = 0;
  46. u32 macb = 0;
  47. eth_priv = (struct eth_priv_t *)dev->priv;
  48. /* Read the e-fuse mac address */
  49. if (eth_priv->slave_port == 1) {
  50. maca = __raw_readl(MAC_ID_BASE_ADDR);
  51. macb = __raw_readl(MAC_ID_BASE_ADDR + 4);
  52. }
  53. dev->enetaddr[0] = (macb >> 8) & 0xff;
  54. dev->enetaddr[1] = (macb >> 0) & 0xff;
  55. dev->enetaddr[2] = (maca >> 24) & 0xff;
  56. dev->enetaddr[3] = (maca >> 16) & 0xff;
  57. dev->enetaddr[4] = (maca >> 8) & 0xff;
  58. dev->enetaddr[5] = (maca >> 0) & 0xff;
  59. return 0;
  60. }
  61. static void keystone2_eth_mdio_enable(void)
  62. {
  63. u_int32_t clkdiv;
  64. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  65. writel((clkdiv & 0xffff) |
  66. MDIO_CONTROL_ENABLE |
  67. MDIO_CONTROL_FAULT |
  68. MDIO_CONTROL_FAULT_ENABLE,
  69. &adap_mdio->control);
  70. while (readl(&adap_mdio->control) & MDIO_CONTROL_IDLE)
  71. ;
  72. }
  73. /* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise */
  74. int keystone2_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data)
  75. {
  76. int tmp;
  77. while (readl(&adap_mdio->useraccess0) & MDIO_USERACCESS0_GO)
  78. ;
  79. writel(MDIO_USERACCESS0_GO |
  80. MDIO_USERACCESS0_WRITE_READ |
  81. ((reg_num & 0x1f) << 21) |
  82. ((phy_addr & 0x1f) << 16),
  83. &adap_mdio->useraccess0);
  84. /* Wait for command to complete */
  85. while ((tmp = readl(&adap_mdio->useraccess0)) & MDIO_USERACCESS0_GO)
  86. ;
  87. if (tmp & MDIO_USERACCESS0_ACK) {
  88. *data = tmp & 0xffff;
  89. return 0;
  90. }
  91. *data = -1;
  92. return -1;
  93. }
  94. /*
  95. * Write to a PHY register via MDIO inteface.
  96. * Blocks until operation is complete.
  97. */
  98. int keystone2_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data)
  99. {
  100. while (readl(&adap_mdio->useraccess0) & MDIO_USERACCESS0_GO)
  101. ;
  102. writel(MDIO_USERACCESS0_GO |
  103. MDIO_USERACCESS0_WRITE_WRITE |
  104. ((reg_num & 0x1f) << 21) |
  105. ((phy_addr & 0x1f) << 16) |
  106. (data & 0xffff),
  107. &adap_mdio->useraccess0);
  108. /* Wait for command to complete */
  109. while (readl(&adap_mdio->useraccess0) & MDIO_USERACCESS0_GO)
  110. ;
  111. return 0;
  112. }
  113. /* PHY functions for a generic PHY */
  114. static int gen_get_link_speed(int phy_addr)
  115. {
  116. u_int16_t tmp;
  117. if ((!keystone2_eth_phy_read(phy_addr, MII_STATUS_REG, &tmp)) &&
  118. (tmp & 0x04)) {
  119. return 0;
  120. }
  121. return -1;
  122. }
  123. static void __attribute__((unused))
  124. keystone2_eth_gigabit_enable(struct eth_device *dev)
  125. {
  126. u_int16_t data;
  127. struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv;
  128. if (sys_has_mdio) {
  129. if (keystone2_eth_phy_read(eth_priv->phy_addr, 0, &data) ||
  130. !(data & (1 << 6))) /* speed selection MSB */
  131. return;
  132. }
  133. /*
  134. * Check if link detected is giga-bit
  135. * If Gigabit mode detected, enable gigbit in MAC
  136. */
  137. writel(readl(&(adap_emac[eth_priv->slave_port - 1].maccontrol)) |
  138. EMAC_MACCONTROL_GIGFORCE | EMAC_MACCONTROL_GIGABIT_ENABLE,
  139. &(adap_emac[eth_priv->slave_port - 1].maccontrol))
  140. ;
  141. }
  142. int keystone_sgmii_link_status(int port)
  143. {
  144. u32 status = 0;
  145. status = __raw_readl(SGMII_STATUS_REG(port));
  146. return status & SGMII_REG_STATUS_LINK;
  147. }
  148. int keystone_get_link_status(struct eth_device *dev)
  149. {
  150. struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv;
  151. int sgmii_link;
  152. int link_state = 0;
  153. #if CONFIG_GET_LINK_STATUS_ATTEMPTS > 1
  154. int j;
  155. for (j = 0; (j < CONFIG_GET_LINK_STATUS_ATTEMPTS) && (link_state == 0);
  156. j++) {
  157. #endif
  158. sgmii_link =
  159. keystone_sgmii_link_status(eth_priv->slave_port - 1);
  160. if (sgmii_link) {
  161. link_state = 1;
  162. if (eth_priv->sgmii_link_type == SGMII_LINK_MAC_PHY)
  163. if (gen_get_link_speed(eth_priv->phy_addr))
  164. link_state = 0;
  165. }
  166. #if CONFIG_GET_LINK_STATUS_ATTEMPTS > 1
  167. }
  168. #endif
  169. return link_state;
  170. }
  171. int keystone_sgmii_config(int port, int interface)
  172. {
  173. unsigned int i, status, mask;
  174. unsigned int mr_adv_ability, control;
  175. switch (interface) {
  176. case SGMII_LINK_MAC_MAC_AUTONEG:
  177. mr_adv_ability = (SGMII_REG_MR_ADV_ENABLE |
  178. SGMII_REG_MR_ADV_LINK |
  179. SGMII_REG_MR_ADV_FULL_DUPLEX |
  180. SGMII_REG_MR_ADV_GIG_MODE);
  181. control = (SGMII_REG_CONTROL_MASTER |
  182. SGMII_REG_CONTROL_AUTONEG);
  183. break;
  184. case SGMII_LINK_MAC_PHY:
  185. case SGMII_LINK_MAC_PHY_FORCED:
  186. mr_adv_ability = SGMII_REG_MR_ADV_ENABLE;
  187. control = SGMII_REG_CONTROL_AUTONEG;
  188. break;
  189. case SGMII_LINK_MAC_MAC_FORCED:
  190. mr_adv_ability = (SGMII_REG_MR_ADV_ENABLE |
  191. SGMII_REG_MR_ADV_LINK |
  192. SGMII_REG_MR_ADV_FULL_DUPLEX |
  193. SGMII_REG_MR_ADV_GIG_MODE);
  194. control = SGMII_REG_CONTROL_MASTER;
  195. break;
  196. case SGMII_LINK_MAC_FIBER:
  197. mr_adv_ability = 0x20;
  198. control = SGMII_REG_CONTROL_AUTONEG;
  199. break;
  200. default:
  201. mr_adv_ability = SGMII_REG_MR_ADV_ENABLE;
  202. control = SGMII_REG_CONTROL_AUTONEG;
  203. }
  204. __raw_writel(0, SGMII_CTL_REG(port));
  205. /*
  206. * Wait for the SerDes pll to lock,
  207. * but don't trap if lock is never read
  208. */
  209. for (i = 0; i < 1000; i++) {
  210. udelay(2000);
  211. status = __raw_readl(SGMII_STATUS_REG(port));
  212. if ((status & SGMII_REG_STATUS_LOCK) != 0)
  213. break;
  214. }
  215. __raw_writel(mr_adv_ability, SGMII_MRADV_REG(port));
  216. __raw_writel(control, SGMII_CTL_REG(port));
  217. mask = SGMII_REG_STATUS_LINK;
  218. if (control & SGMII_REG_CONTROL_AUTONEG)
  219. mask |= SGMII_REG_STATUS_AUTONEG;
  220. for (i = 0; i < 1000; i++) {
  221. status = __raw_readl(SGMII_STATUS_REG(port));
  222. if ((status & mask) == mask)
  223. break;
  224. }
  225. return 0;
  226. }
  227. int mac_sl_reset(u32 port)
  228. {
  229. u32 i, v;
  230. if (port >= DEVICE_N_GMACSL_PORTS)
  231. return GMACSL_RET_INVALID_PORT;
  232. /* Set the soft reset bit */
  233. writel(CPGMAC_REG_RESET_VAL_RESET,
  234. DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET);
  235. /* Wait for the bit to clear */
  236. for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) {
  237. v = readl(DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET);
  238. if ((v & CPGMAC_REG_RESET_VAL_RESET_MASK) !=
  239. CPGMAC_REG_RESET_VAL_RESET)
  240. return GMACSL_RET_OK;
  241. }
  242. /* Timeout on the reset */
  243. return GMACSL_RET_WARN_RESET_INCOMPLETE;
  244. }
  245. int mac_sl_config(u_int16_t port, struct mac_sl_cfg *cfg)
  246. {
  247. u32 v, i;
  248. int ret = GMACSL_RET_OK;
  249. if (port >= DEVICE_N_GMACSL_PORTS)
  250. return GMACSL_RET_INVALID_PORT;
  251. if (cfg->max_rx_len > CPGMAC_REG_MAXLEN_LEN) {
  252. cfg->max_rx_len = CPGMAC_REG_MAXLEN_LEN;
  253. ret = GMACSL_RET_WARN_MAXLEN_TOO_BIG;
  254. }
  255. /* Must wait if the device is undergoing reset */
  256. for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) {
  257. v = readl(DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_RESET);
  258. if ((v & CPGMAC_REG_RESET_VAL_RESET_MASK) !=
  259. CPGMAC_REG_RESET_VAL_RESET)
  260. break;
  261. }
  262. if (i == DEVICE_EMACSL_RESET_POLL_COUNT)
  263. return GMACSL_RET_CONFIG_FAIL_RESET_ACTIVE;
  264. writel(cfg->max_rx_len, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_MAXLEN);
  265. writel(cfg->ctl, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_CTL);
  266. return ret;
  267. }
  268. int ethss_config(u32 ctl, u32 max_pkt_size)
  269. {
  270. u32 i;
  271. /* Max length register */
  272. writel(max_pkt_size, DEVICE_CPSW_BASE + CPSW_REG_MAXLEN);
  273. /* Control register */
  274. writel(ctl, DEVICE_CPSW_BASE + CPSW_REG_CTL);
  275. /* All statistics enabled by default */
  276. writel(CPSW_REG_VAL_STAT_ENABLE_ALL,
  277. DEVICE_CPSW_BASE + CPSW_REG_STAT_PORT_EN);
  278. /* Reset and enable the ALE */
  279. writel(CPSW_REG_VAL_ALE_CTL_RESET_AND_ENABLE |
  280. CPSW_REG_VAL_ALE_CTL_BYPASS,
  281. DEVICE_CPSW_BASE + CPSW_REG_ALE_CONTROL);
  282. /* All ports put into forward mode */
  283. for (i = 0; i < DEVICE_CPSW_NUM_PORTS; i++)
  284. writel(CPSW_REG_VAL_PORTCTL_FORWARD_MODE,
  285. DEVICE_CPSW_BASE + CPSW_REG_ALE_PORTCTL(i));
  286. return 0;
  287. }
  288. int ethss_start(void)
  289. {
  290. int i;
  291. struct mac_sl_cfg cfg;
  292. cfg.max_rx_len = MAX_SIZE_STREAM_BUFFER;
  293. cfg.ctl = GMACSL_ENABLE | GMACSL_RX_ENABLE_EXT_CTL;
  294. for (i = 0; i < DEVICE_N_GMACSL_PORTS; i++) {
  295. mac_sl_reset(i);
  296. mac_sl_config(i, &cfg);
  297. }
  298. return 0;
  299. }
  300. int ethss_stop(void)
  301. {
  302. int i;
  303. for (i = 0; i < DEVICE_N_GMACSL_PORTS; i++)
  304. mac_sl_reset(i);
  305. return 0;
  306. }
  307. int32_t cpmac_drv_send(u32 *buffer, int num_bytes, int slave_port_num)
  308. {
  309. if (num_bytes < EMAC_MIN_ETHERNET_PKT_SIZE)
  310. num_bytes = EMAC_MIN_ETHERNET_PKT_SIZE;
  311. return netcp_send(buffer, num_bytes, (slave_port_num) << 16);
  312. }
  313. /* Eth device open */
  314. static int keystone2_eth_open(struct eth_device *dev, bd_t *bis)
  315. {
  316. u_int32_t clkdiv;
  317. int link;
  318. struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv;
  319. debug("+ emac_open\n");
  320. net_rx_buffs.rx_flow = eth_priv->rx_flow;
  321. sys_has_mdio =
  322. (eth_priv->sgmii_link_type == SGMII_LINK_MAC_PHY) ? 1 : 0;
  323. psc_enable_module(KS2_LPSC_PA);
  324. psc_enable_module(KS2_LPSC_CPGMAC);
  325. sgmii_serdes_setup_156p25mhz();
  326. if (sys_has_mdio)
  327. keystone2_eth_mdio_enable();
  328. keystone_sgmii_config(eth_priv->slave_port - 1,
  329. eth_priv->sgmii_link_type);
  330. udelay(10000);
  331. /* On chip switch configuration */
  332. ethss_config(target_get_switch_ctl(), SWITCH_MAX_PKT_SIZE);
  333. /* TODO: add error handling code */
  334. if (qm_init()) {
  335. printf("ERROR: qm_init()\n");
  336. return -1;
  337. }
  338. if (netcp_init(&net_rx_buffs)) {
  339. qm_close();
  340. printf("ERROR: netcp_init()\n");
  341. return -1;
  342. }
  343. /*
  344. * Streaming switch configuration. If not present this
  345. * statement is defined to void in target.h.
  346. * If present this is usually defined to a series of register writes
  347. */
  348. hw_config_streaming_switch();
  349. if (sys_has_mdio) {
  350. /* Init MDIO & get link state */
  351. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  352. writel((clkdiv & 0xff) | MDIO_CONTROL_ENABLE |
  353. MDIO_CONTROL_FAULT, &adap_mdio->control)
  354. ;
  355. /* We need to wait for MDIO to start */
  356. udelay(1000);
  357. link = keystone_get_link_status(dev);
  358. if (link == 0) {
  359. netcp_close();
  360. qm_close();
  361. return -1;
  362. }
  363. }
  364. emac_gigabit_enable(dev);
  365. ethss_start();
  366. debug("- emac_open\n");
  367. emac_open = 1;
  368. return 0;
  369. }
  370. /* Eth device close */
  371. void keystone2_eth_close(struct eth_device *dev)
  372. {
  373. debug("+ emac_close\n");
  374. if (!emac_open)
  375. return;
  376. ethss_stop();
  377. netcp_close();
  378. qm_close();
  379. emac_open = 0;
  380. debug("- emac_close\n");
  381. }
  382. static int tx_send_loop;
  383. /*
  384. * This function sends a single packet on the network and returns
  385. * positive number (number of bytes transmitted) or negative for error
  386. */
  387. static int keystone2_eth_send_packet(struct eth_device *dev,
  388. void *packet, int length)
  389. {
  390. int ret_status = -1;
  391. struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv;
  392. tx_send_loop = 0;
  393. if (keystone_get_link_status(dev) == 0)
  394. return -1;
  395. emac_gigabit_enable(dev);
  396. if (cpmac_drv_send((u32 *)packet, length, eth_priv->slave_port) != 0)
  397. return ret_status;
  398. if (keystone_get_link_status(dev) == 0)
  399. return -1;
  400. emac_gigabit_enable(dev);
  401. return length;
  402. }
  403. /*
  404. * This function handles receipt of a packet from the network
  405. */
  406. static int keystone2_eth_rcv_packet(struct eth_device *dev)
  407. {
  408. void *hd;
  409. int pkt_size;
  410. u32 *pkt;
  411. hd = netcp_recv(&pkt, &pkt_size);
  412. if (hd == NULL)
  413. return 0;
  414. NetReceive((uchar *)pkt, pkt_size);
  415. netcp_release_rxhd(hd);
  416. return pkt_size;
  417. }
  418. /*
  419. * This function initializes the EMAC hardware.
  420. */
  421. int keystone2_emac_initialize(struct eth_priv_t *eth_priv)
  422. {
  423. struct eth_device *dev;
  424. dev = malloc(sizeof(struct eth_device));
  425. if (dev == NULL)
  426. return -1;
  427. memset(dev, 0, sizeof(struct eth_device));
  428. strcpy(dev->name, eth_priv->int_name);
  429. dev->priv = eth_priv;
  430. keystone2_eth_read_mac_addr(dev);
  431. dev->iobase = 0;
  432. dev->init = keystone2_eth_open;
  433. dev->halt = keystone2_eth_close;
  434. dev->send = keystone2_eth_send_packet;
  435. dev->recv = keystone2_eth_rcv_packet;
  436. eth_register(dev);
  437. return 0;
  438. }
  439. void sgmii_serdes_setup_156p25mhz(void)
  440. {
  441. unsigned int cnt;
  442. /*
  443. * configure Serializer/Deserializer (SerDes) hardware. SerDes IP
  444. * hardware vendor published only register addresses and their values
  445. * to be used for configuring SerDes. So had to use hardcoded values
  446. * below.
  447. */
  448. clrsetbits_le32(0x0232a000, 0xffff0000, 0x00800000);
  449. clrsetbits_le32(0x0232a014, 0x0000ffff, 0x00008282);
  450. clrsetbits_le32(0x0232a060, 0x00ffffff, 0x00142438);
  451. clrsetbits_le32(0x0232a064, 0x00ffff00, 0x00c3c700);
  452. clrsetbits_le32(0x0232a078, 0x0000ff00, 0x0000c000);
  453. clrsetbits_le32(0x0232a204, 0xff0000ff, 0x38000080);
  454. clrsetbits_le32(0x0232a208, 0x000000ff, 0x00000000);
  455. clrsetbits_le32(0x0232a20c, 0xff000000, 0x02000000);
  456. clrsetbits_le32(0x0232a210, 0xff000000, 0x1b000000);
  457. clrsetbits_le32(0x0232a214, 0x0000ffff, 0x00006fb8);
  458. clrsetbits_le32(0x0232a218, 0xffff00ff, 0x758000e4);
  459. clrsetbits_le32(0x0232a2ac, 0x0000ff00, 0x00004400);
  460. clrsetbits_le32(0x0232a22c, 0x00ffff00, 0x00200800);
  461. clrsetbits_le32(0x0232a280, 0x00ff00ff, 0x00820082);
  462. clrsetbits_le32(0x0232a284, 0xffffffff, 0x1d0f0385);
  463. clrsetbits_le32(0x0232a404, 0xff0000ff, 0x38000080);
  464. clrsetbits_le32(0x0232a408, 0x000000ff, 0x00000000);
  465. clrsetbits_le32(0x0232a40c, 0xff000000, 0x02000000);
  466. clrsetbits_le32(0x0232a410, 0xff000000, 0x1b000000);
  467. clrsetbits_le32(0x0232a414, 0x0000ffff, 0x00006fb8);
  468. clrsetbits_le32(0x0232a418, 0xffff00ff, 0x758000e4);
  469. clrsetbits_le32(0x0232a4ac, 0x0000ff00, 0x00004400);
  470. clrsetbits_le32(0x0232a42c, 0x00ffff00, 0x00200800);
  471. clrsetbits_le32(0x0232a480, 0x00ff00ff, 0x00820082);
  472. clrsetbits_le32(0x0232a484, 0xffffffff, 0x1d0f0385);
  473. clrsetbits_le32(0x0232a604, 0xff0000ff, 0x38000080);
  474. clrsetbits_le32(0x0232a608, 0x000000ff, 0x00000000);
  475. clrsetbits_le32(0x0232a60c, 0xff000000, 0x02000000);
  476. clrsetbits_le32(0x0232a610, 0xff000000, 0x1b000000);
  477. clrsetbits_le32(0x0232a614, 0x0000ffff, 0x00006fb8);
  478. clrsetbits_le32(0x0232a618, 0xffff00ff, 0x758000e4);
  479. clrsetbits_le32(0x0232a6ac, 0x0000ff00, 0x00004400);
  480. clrsetbits_le32(0x0232a62c, 0x00ffff00, 0x00200800);
  481. clrsetbits_le32(0x0232a680, 0x00ff00ff, 0x00820082);
  482. clrsetbits_le32(0x0232a684, 0xffffffff, 0x1d0f0385);
  483. clrsetbits_le32(0x0232a804, 0xff0000ff, 0x38000080);
  484. clrsetbits_le32(0x0232a808, 0x000000ff, 0x00000000);
  485. clrsetbits_le32(0x0232a80c, 0xff000000, 0x02000000);
  486. clrsetbits_le32(0x0232a810, 0xff000000, 0x1b000000);
  487. clrsetbits_le32(0x0232a814, 0x0000ffff, 0x00006fb8);
  488. clrsetbits_le32(0x0232a818, 0xffff00ff, 0x758000e4);
  489. clrsetbits_le32(0x0232a8ac, 0x0000ff00, 0x00004400);
  490. clrsetbits_le32(0x0232a82c, 0x00ffff00, 0x00200800);
  491. clrsetbits_le32(0x0232a880, 0x00ff00ff, 0x00820082);
  492. clrsetbits_le32(0x0232a884, 0xffffffff, 0x1d0f0385);
  493. clrsetbits_le32(0x0232aa00, 0x0000ff00, 0x00000800);
  494. clrsetbits_le32(0x0232aa08, 0xffff0000, 0x38a20000);
  495. clrsetbits_le32(0x0232aa30, 0x00ffff00, 0x008a8a00);
  496. clrsetbits_le32(0x0232aa84, 0x0000ff00, 0x00000600);
  497. clrsetbits_le32(0x0232aa94, 0xff000000, 0x10000000);
  498. clrsetbits_le32(0x0232aaa0, 0xff000000, 0x81000000);
  499. clrsetbits_le32(0x0232aabc, 0xff000000, 0xff000000);
  500. clrsetbits_le32(0x0232aac0, 0x000000ff, 0x0000008b);
  501. clrsetbits_le32(0x0232ab08, 0xffff0000, 0x583f0000);
  502. clrsetbits_le32(0x0232ab0c, 0x000000ff, 0x0000004e);
  503. clrsetbits_le32(0x0232a000, 0x000000ff, 0x00000003);
  504. clrsetbits_le32(0x0232aa00, 0x000000ff, 0x0000005f);
  505. clrsetbits_le32(0x0232aa48, 0x00ffff00, 0x00fd8c00);
  506. clrsetbits_le32(0x0232aa54, 0x00ffffff, 0x002fec72);
  507. clrsetbits_le32(0x0232aa58, 0xffffff00, 0x00f92100);
  508. clrsetbits_le32(0x0232aa5c, 0xffffffff, 0x00040060);
  509. clrsetbits_le32(0x0232aa60, 0xffffffff, 0x00008000);
  510. clrsetbits_le32(0x0232aa64, 0xffffffff, 0x0c581220);
  511. clrsetbits_le32(0x0232aa68, 0xffffffff, 0xe13b0602);
  512. clrsetbits_le32(0x0232aa6c, 0xffffffff, 0xb8074cc1);
  513. clrsetbits_le32(0x0232aa70, 0xffffffff, 0x3f02e989);
  514. clrsetbits_le32(0x0232aa74, 0x000000ff, 0x00000001);
  515. clrsetbits_le32(0x0232ab20, 0x00ff0000, 0x00370000);
  516. clrsetbits_le32(0x0232ab1c, 0xff000000, 0x37000000);
  517. clrsetbits_le32(0x0232ab20, 0x000000ff, 0x0000005d);
  518. /*Bring SerDes out of Reset if SerDes is Shutdown & is in Reset Mode*/
  519. clrbits_le32(0x0232a010, 1 << 28);
  520. /* Enable TX and RX via the LANExCTL_STS 0x0000 + x*4 */
  521. clrbits_le32(0x0232a228, 1 << 29);
  522. writel(0xF800F8C0, 0x0232bfe0);
  523. clrbits_le32(0x0232a428, 1 << 29);
  524. writel(0xF800F8C0, 0x0232bfe4);
  525. clrbits_le32(0x0232a628, 1 << 29);
  526. writel(0xF800F8C0, 0x0232bfe8);
  527. clrbits_le32(0x0232a828, 1 << 29);
  528. writel(0xF800F8C0, 0x0232bfec);
  529. /*Enable pll via the pll_ctrl 0x0014*/
  530. writel(0xe0000000, 0x0232bff4)
  531. ;
  532. /*Waiting for SGMII Serdes PLL lock.*/
  533. for (cnt = 10000; cnt > 0 && ((readl(0x02090114) & 0x10) == 0); cnt--)
  534. ;
  535. for (cnt = 10000; cnt > 0 && ((readl(0x02090214) & 0x10) == 0); cnt--)
  536. ;
  537. for (cnt = 10000; cnt > 0 && ((readl(0x02090414) & 0x10) == 0); cnt--)
  538. ;
  539. for (cnt = 10000; cnt > 0 && ((readl(0x02090514) & 0x10) == 0); cnt--)
  540. ;
  541. udelay(45000);
  542. }
  543. void sgmii_serdes_shutdown(void)
  544. {
  545. /*
  546. * shutdown SerDes hardware. SerDes hardware vendor published only
  547. * register addresses and their values. So had to use hardcoded
  548. * values below.
  549. */
  550. clrbits_le32(0x0232bfe0, 3 << 29 | 3 << 13);
  551. setbits_le32(0x02320228, 1 << 29);
  552. clrbits_le32(0x0232bfe4, 3 << 29 | 3 << 13);
  553. setbits_le32(0x02320428, 1 << 29);
  554. clrbits_le32(0x0232bfe8, 3 << 29 | 3 << 13);
  555. setbits_le32(0x02320628, 1 << 29);
  556. clrbits_le32(0x0232bfec, 3 << 29 | 3 << 13);
  557. setbits_le32(0x02320828, 1 << 29);
  558. clrbits_le32(0x02320034, 3 << 29);
  559. setbits_le32(0x02320010, 1 << 28);
  560. }