misc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Miscelaneous DaVinci functions.
  3. *
  4. * Copyright (C) 2009 Nick Thompson, GE Fanuc Ltd, <nick.thompson@gefanuc.com>
  5. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  6. * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
  7. * Copyright (C) 2004 Texas Instruments.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <i2c.h>
  13. #include <net.h>
  14. #include <asm/arch/hardware.h>
  15. #include <asm/io.h>
  16. #include <asm/arch/davinci_misc.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. #ifndef CONFIG_SPL_BUILD
  19. int dram_init(void)
  20. {
  21. /* dram_init must store complete ramsize in gd->ram_size */
  22. gd->ram_size = get_ram_size(
  23. (void *)CONFIG_SYS_SDRAM_BASE,
  24. CONFIG_MAX_RAM_BANK_SIZE);
  25. return 0;
  26. }
  27. int dram_init_banksize(void)
  28. {
  29. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  30. gd->bd->bi_dram[0].size = gd->ram_size;
  31. return 0;
  32. }
  33. #endif
  34. #ifdef CONFIG_DRIVER_TI_EMAC
  35. /*
  36. * Read ethernet MAC address from EEPROM for DVEVM compatible boards.
  37. * Returns 1 if found, 0 otherwise.
  38. */
  39. int dvevm_read_mac_address(uint8_t *buf)
  40. {
  41. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  42. /* Read MAC address. */
  43. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x7F00,
  44. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &buf[0], 6))
  45. goto i2cerr;
  46. /* Check that MAC address is valid. */
  47. if (!is_valid_ethaddr(buf))
  48. goto err;
  49. return 1; /* Found */
  50. i2cerr:
  51. printf("Read from EEPROM @ 0x%02x failed\n",
  52. CONFIG_SYS_I2C_EEPROM_ADDR);
  53. err:
  54. #endif /* CONFIG_SYS_I2C_EEPROM_ADDR */
  55. return 0;
  56. }
  57. /*
  58. * Set the mii mode as MII or RMII
  59. */
  60. #if defined(CONFIG_SOC_DA8XX)
  61. void davinci_emac_mii_mode_sel(int mode_sel)
  62. {
  63. int val;
  64. val = readl(&davinci_syscfg_regs->cfgchip3);
  65. if (mode_sel == 0)
  66. val &= ~(1 << 8);
  67. else
  68. val |= (1 << 8);
  69. writel(val, &davinci_syscfg_regs->cfgchip3);
  70. }
  71. #endif
  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_getenv_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_setenv_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. #if defined(CONFIG_SOC_DA8XX)
  96. #ifndef CONFIG_USE_IRQ
  97. void irq_init(void)
  98. {
  99. /*
  100. * Mask all IRQs by clearing the global enable and setting
  101. * the enable clear for all the 90 interrupts.
  102. */
  103. writel(0, &davinci_aintc_regs->ger);
  104. writel(0, &davinci_aintc_regs->hier);
  105. writel(0xffffffff, &davinci_aintc_regs->ecr1);
  106. writel(0xffffffff, &davinci_aintc_regs->ecr2);
  107. writel(0xffffffff, &davinci_aintc_regs->ecr3);
  108. }
  109. #endif
  110. /*
  111. * Enable PSC for various peripherals.
  112. */
  113. int da8xx_configure_lpsc_items(const struct lpsc_resource *item,
  114. const int n_items)
  115. {
  116. int i;
  117. for (i = 0; i < n_items; i++)
  118. lpsc_on(item[i].lpsc_no);
  119. return 0;
  120. }
  121. #endif