misc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Miscelaneous DaVinci functions.
  4. *
  5. * Copyright (C) 2009 Nick Thompson, GE Fanuc Ltd, <nick.thompson@gefanuc.com>
  6. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  7. * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
  8. * Copyright (C) 2004 Texas Instruments.
  9. */
  10. #include <common.h>
  11. #include <env.h>
  12. #include <i2c.h>
  13. #include <init.h>
  14. #include <log.h>
  15. #include <net.h>
  16. #include <asm/arch/hardware.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/davinci_misc.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. #ifndef CONFIG_SPL_BUILD
  21. int dram_init(void)
  22. {
  23. /* dram_init must store complete ramsize in gd->ram_size */
  24. gd->ram_size = get_ram_size(
  25. (void *)CONFIG_SYS_SDRAM_BASE,
  26. CONFIG_MAX_RAM_BANK_SIZE);
  27. return 0;
  28. }
  29. int dram_init_banksize(void)
  30. {
  31. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  32. gd->bd->bi_dram[0].size = gd->ram_size;
  33. return 0;
  34. }
  35. #endif
  36. #ifdef CONFIG_DRIVER_TI_EMAC
  37. /*
  38. * Read ethernet MAC address from EEPROM for DVEVM compatible boards.
  39. * Returns 1 if found, 0 otherwise.
  40. */
  41. int dvevm_read_mac_address(uint8_t *buf)
  42. {
  43. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  44. /* Read MAC address. */
  45. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x7F00,
  46. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &buf[0], 6))
  47. goto i2cerr;
  48. /* Check that MAC address is valid. */
  49. if (!is_valid_ethaddr(buf))
  50. goto err;
  51. return 1; /* Found */
  52. i2cerr:
  53. printf("Read from EEPROM @ 0x%02x failed\n",
  54. CONFIG_SYS_I2C_EEPROM_ADDR);
  55. err:
  56. #endif /* CONFIG_SYS_I2C_EEPROM_ADDR */
  57. return 0;
  58. }
  59. /*
  60. * Set the mii mode as MII or RMII
  61. */
  62. void davinci_emac_mii_mode_sel(int mode_sel)
  63. {
  64. int val;
  65. val = readl(&davinci_syscfg_regs->cfgchip3);
  66. if (mode_sel == 0)
  67. val &= ~(1 << 8);
  68. else
  69. val |= (1 << 8);
  70. writel(val, &davinci_syscfg_regs->cfgchip3);
  71. }
  72. /*
  73. * If there is no MAC address in the environment, then it will be initialized
  74. * (silently) from the value in the EEPROM.
  75. */
  76. void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
  77. {
  78. uint8_t env_enetaddr[6];
  79. int ret;
  80. ret = eth_env_get_enetaddr_by_index("eth", 0, env_enetaddr);
  81. if (!ret) {
  82. /*
  83. * There is no MAC address in the environment, so we
  84. * initialize it from the value in the EEPROM.
  85. */
  86. debug("### Setting environment from EEPROM MAC address = "
  87. "\"%pM\"\n",
  88. env_enetaddr);
  89. ret = !eth_env_set_enetaddr("ethaddr", rom_enetaddr);
  90. }
  91. if (!ret)
  92. printf("Failed to set mac address from EEPROM: %d\n", ret);
  93. }
  94. #endif /* CONFIG_DRIVER_TI_EMAC */
  95. void irq_init(void)
  96. {
  97. /*
  98. * Mask all IRQs by clearing the global enable and setting
  99. * the enable clear for all the 90 interrupts.
  100. */
  101. writel(0, &davinci_aintc_regs->ger);
  102. writel(0, &davinci_aintc_regs->hier);
  103. writel(0xffffffff, &davinci_aintc_regs->ecr1);
  104. writel(0xffffffff, &davinci_aintc_regs->ecr2);
  105. writel(0xffffffff, &davinci_aintc_regs->ecr3);
  106. }
  107. /*
  108. * Enable PSC for various peripherals.
  109. */
  110. int da8xx_configure_lpsc_items(const struct lpsc_resource *item,
  111. const int n_items)
  112. {
  113. int i;
  114. for (i = 0; i < n_items; i++)
  115. lpsc_on(item[i].lpsc_no);
  116. return 0;
  117. }