cm_t335.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Board functions for Compulab CM-T335 board
  3. *
  4. * Copyright (C) 2013, Compulab Ltd - http://compulab.co.il/
  5. *
  6. * Author: Ilya Ledvich <ilya@compulab.co.il>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <errno.h>
  12. #include <miiphy.h>
  13. #include <cpsw.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/arch/hardware_am33xx.h>
  16. #include <asm/io.h>
  17. #include <asm/gpio.h>
  18. #include "../common/eeprom.h"
  19. DECLARE_GLOBAL_DATA_PTR;
  20. /*
  21. * Basic board specific setup. Pinmux has been handled already.
  22. */
  23. int board_init(void)
  24. {
  25. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  26. gpmc_init();
  27. return 0;
  28. }
  29. #if defined (CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)
  30. static void cpsw_control(int enabled)
  31. {
  32. /* VTP can be added here */
  33. return;
  34. }
  35. static struct cpsw_slave_data cpsw_slave = {
  36. .slave_reg_ofs = 0x208,
  37. .sliver_reg_ofs = 0xd80,
  38. .phy_id = 0,
  39. .phy_if = PHY_INTERFACE_MODE_RGMII,
  40. };
  41. static struct cpsw_platform_data cpsw_data = {
  42. .mdio_base = CPSW_MDIO_BASE,
  43. .cpsw_base = CPSW_BASE,
  44. .mdio_div = 0xff,
  45. .channels = 8,
  46. .cpdma_reg_ofs = 0x800,
  47. .slaves = 1,
  48. .slave_data = &cpsw_slave,
  49. .ale_reg_ofs = 0xd00,
  50. .ale_entries = 1024,
  51. .host_port_reg_ofs = 0x108,
  52. .hw_stats_reg_ofs = 0x900,
  53. .bd_ram_ofs = 0x2000,
  54. .mac_control = (1 << 5),
  55. .control = cpsw_control,
  56. .host_port_num = 0,
  57. .version = CPSW_CTRL_VERSION_2,
  58. };
  59. /* PHY reset GPIO */
  60. #define GPIO_PHY_RST GPIO_PIN(3, 7)
  61. static void board_phy_init(void)
  62. {
  63. gpio_request(GPIO_PHY_RST, "phy_rst");
  64. gpio_direction_output(GPIO_PHY_RST, 0);
  65. mdelay(2);
  66. gpio_set_value(GPIO_PHY_RST, 1);
  67. mdelay(2);
  68. }
  69. static void get_efuse_mac_addr(uchar *enetaddr)
  70. {
  71. uint32_t mac_hi, mac_lo;
  72. struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  73. mac_lo = readl(&cdev->macid0l);
  74. mac_hi = readl(&cdev->macid0h);
  75. enetaddr[0] = mac_hi & 0xFF;
  76. enetaddr[1] = (mac_hi & 0xFF00) >> 8;
  77. enetaddr[2] = (mac_hi & 0xFF0000) >> 16;
  78. enetaddr[3] = (mac_hi & 0xFF000000) >> 24;
  79. enetaddr[4] = mac_lo & 0xFF;
  80. enetaddr[5] = (mac_lo & 0xFF00) >> 8;
  81. }
  82. /*
  83. * Routine: handle_mac_address
  84. * Description: prepare MAC address for on-board Ethernet.
  85. */
  86. static int handle_mac_address(void)
  87. {
  88. uchar enetaddr[6];
  89. int rv;
  90. rv = eth_getenv_enetaddr("ethaddr", enetaddr);
  91. if (rv)
  92. return 0;
  93. rv = cl_eeprom_read_mac_addr(enetaddr);
  94. if (rv)
  95. get_efuse_mac_addr(enetaddr);
  96. if (!is_valid_ether_addr(enetaddr))
  97. return -1;
  98. return eth_setenv_enetaddr("ethaddr", enetaddr);
  99. }
  100. #define AR8051_PHY_DEBUG_ADDR_REG 0x1d
  101. #define AR8051_PHY_DEBUG_DATA_REG 0x1e
  102. #define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
  103. #define AR8051_RGMII_TX_CLK_DLY 0x100
  104. int board_eth_init(bd_t *bis)
  105. {
  106. int rv, n = 0;
  107. const char *devname;
  108. struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  109. rv = handle_mac_address();
  110. if (rv)
  111. printf("No MAC address found!\n");
  112. writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel);
  113. board_phy_init();
  114. rv = cpsw_register(&cpsw_data);
  115. if (rv < 0)
  116. printf("Error %d registering CPSW switch\n", rv);
  117. else
  118. n += rv;
  119. /*
  120. * CPSW RGMII Internal Delay Mode is not supported in all PVT
  121. * operating points. So we must set the TX clock delay feature
  122. * in the AR8051 PHY. Since we only support a single ethernet
  123. * device, we only do this for the first instance.
  124. */
  125. devname = miiphy_get_current_dev();
  126. miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
  127. AR8051_DEBUG_RGMII_CLK_DLY_REG);
  128. miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
  129. AR8051_RGMII_TX_CLK_DLY);
  130. return n;
  131. }
  132. #endif /* CONFIG_DRIVER_TI_CPSW && !CONFIG_SPL_BUILD */