cm_t43.c 3.3 KB

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