cm_t43.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2015 Compulab, Ltd.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <i2c.h>
  8. #include <miiphy.h>
  9. #include <cpsw.h>
  10. #include <asm/gpio.h>
  11. #include <asm/arch/sys_proto.h>
  12. #include <asm/emif.h>
  13. #include <power/pmic.h>
  14. #include <power/tps65218.h>
  15. #include "board.h"
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
  18. /* setup board specific PMIC */
  19. int power_init_board(void)
  20. {
  21. struct pmic *p;
  22. uchar tps_status = 0;
  23. power_tps65218_init(I2C_PMIC);
  24. p = pmic_get("TPS65218_PMIC");
  25. if (p && !pmic_probe(p)) {
  26. puts("PMIC: TPS65218\n");
  27. /* We don't care if fseal is locked, but we do need it set */
  28. tps65218_lock_fseal();
  29. tps65218_reg_read(TPS65218_STATUS, &tps_status);
  30. if (!(tps_status & TPS65218_FSEAL))
  31. printf("WARNING: RTC not backed by battery!\n");
  32. }
  33. return 0;
  34. }
  35. int board_init(void)
  36. {
  37. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  38. gpmc_init();
  39. set_i2c_pin_mux();
  40. i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
  41. i2c_probe(TPS65218_CHIP_PM);
  42. return 0;
  43. }
  44. #ifdef CONFIG_DRIVER_TI_CPSW
  45. static void cpsw_control(int enabled)
  46. {
  47. return;
  48. }
  49. static struct cpsw_slave_data cpsw_slaves[] = {
  50. {
  51. .slave_reg_ofs = 0x208,
  52. .sliver_reg_ofs = 0xd80,
  53. .phy_addr = 0,
  54. .phy_if = PHY_INTERFACE_MODE_RGMII,
  55. },
  56. {
  57. .slave_reg_ofs = 0x308,
  58. .sliver_reg_ofs = 0xdc0,
  59. .phy_addr = 1,
  60. .phy_if = PHY_INTERFACE_MODE_RGMII,
  61. },
  62. };
  63. static struct cpsw_platform_data cpsw_data = {
  64. .mdio_base = CPSW_MDIO_BASE,
  65. .cpsw_base = CPSW_BASE,
  66. .mdio_div = 0xff,
  67. .channels = 8,
  68. .cpdma_reg_ofs = 0x800,
  69. .slaves = 2,
  70. .slave_data = cpsw_slaves,
  71. .ale_reg_ofs = 0xd00,
  72. .ale_entries = 1024,
  73. .host_port_reg_ofs = 0x108,
  74. .hw_stats_reg_ofs = 0x900,
  75. .bd_ram_ofs = 0x2000,
  76. .mac_control = (1 << 5),
  77. .control = cpsw_control,
  78. .host_port_num = 0,
  79. .version = CPSW_CTRL_VERSION_2,
  80. };
  81. #define GPIO_PHY1_RST 170
  82. #define GPIO_PHY2_RST 168
  83. int board_phy_config(struct phy_device *phydev)
  84. {
  85. unsigned short val;
  86. /* introduce tx clock delay */
  87. phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
  88. val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
  89. val |= 0x0100;
  90. phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
  91. if (phydev->drv->config)
  92. return phydev->drv->config(phydev);
  93. return 0;
  94. }
  95. static void board_phy_init(void)
  96. {
  97. set_mdio_pin_mux();
  98. writel(0x40003, 0x44e10a74); /* Mux pin as clkout2 */
  99. writel(0x10006, 0x44df4108); /* Select EXTDEV as clock source */
  100. writel(0x4, 0x44df2e60); /* Set EXTDEV as MNbypass */
  101. /* For revision A */
  102. writel(0x2000009, 0x44df2e6c);
  103. writel(0x38a, 0x44df2e70);
  104. mdelay(10);
  105. gpio_request(GPIO_PHY1_RST, "phy1_rst");
  106. gpio_request(GPIO_PHY2_RST, "phy2_rst");
  107. gpio_direction_output(GPIO_PHY1_RST, 0);
  108. gpio_direction_output(GPIO_PHY2_RST, 0);
  109. mdelay(2);
  110. gpio_set_value(GPIO_PHY1_RST, 1);
  111. gpio_set_value(GPIO_PHY2_RST, 1);
  112. mdelay(2);
  113. }
  114. int board_eth_init(bd_t *bis)
  115. {
  116. int rv;
  117. set_rgmii_pin_mux();
  118. writel(RGMII_MODE_ENABLE | RGMII_INT_DELAY, &cdev->miisel);
  119. board_phy_init();
  120. rv = cpsw_register(&cpsw_data);
  121. if (rv < 0)
  122. printf("Error %d registering CPSW switch\n", rv);
  123. return rv;
  124. }
  125. #endif