misc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. void 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. }
  32. #endif
  33. #ifdef CONFIG_DRIVER_TI_EMAC
  34. /*
  35. * Read ethernet MAC address from EEPROM for DVEVM compatible boards.
  36. * Returns 1 if found, 0 otherwise.
  37. */
  38. int dvevm_read_mac_address(uint8_t *buf)
  39. {
  40. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  41. /* Read MAC address. */
  42. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x7F00,
  43. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &buf[0], 6))
  44. goto i2cerr;
  45. /* Check that MAC address is valid. */
  46. if (!is_valid_ethaddr(buf))
  47. goto err;
  48. return 1; /* Found */
  49. i2cerr:
  50. printf("Read from EEPROM @ 0x%02x failed\n",
  51. CONFIG_SYS_I2C_EEPROM_ADDR);
  52. err:
  53. #endif /* CONFIG_SYS_I2C_EEPROM_ADDR */
  54. return 0;
  55. }
  56. /*
  57. * Set the mii mode as MII or RMII
  58. */
  59. #if defined(CONFIG_SOC_DA8XX)
  60. void davinci_emac_mii_mode_sel(int mode_sel)
  61. {
  62. int val;
  63. val = readl(&davinci_syscfg_regs->cfgchip3);
  64. if (mode_sel == 0)
  65. val &= ~(1 << 8);
  66. else
  67. val |= (1 << 8);
  68. writel(val, &davinci_syscfg_regs->cfgchip3);
  69. }
  70. #endif
  71. /*
  72. * If there is no MAC address in the environment, then it will be initialized
  73. * (silently) from the value in the EEPROM.
  74. */
  75. void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
  76. {
  77. uint8_t env_enetaddr[6];
  78. int ret;
  79. ret = eth_getenv_enetaddr_by_index("eth", 0, env_enetaddr);
  80. if (!ret) {
  81. /*
  82. * There is no MAC address in the environment, so we
  83. * initialize it from the value in the EEPROM.
  84. */
  85. debug("### Setting environment from EEPROM MAC address = "
  86. "\"%pM\"\n",
  87. env_enetaddr);
  88. ret = !eth_setenv_enetaddr("ethaddr", rom_enetaddr);
  89. }
  90. if (!ret)
  91. printf("Failed to set mac address from EEPROM: %d\n", ret);
  92. }
  93. #endif /* CONFIG_DRIVER_TI_EMAC */
  94. #if defined(CONFIG_SOC_DA8XX)
  95. #ifndef CONFIG_USE_IRQ
  96. void irq_init(void)
  97. {
  98. /*
  99. * Mask all IRQs by clearing the global enable and setting
  100. * the enable clear for all the 90 interrupts.
  101. */
  102. writel(0, &davinci_aintc_regs->ger);
  103. writel(0, &davinci_aintc_regs->hier);
  104. writel(0xffffffff, &davinci_aintc_regs->ecr1);
  105. writel(0xffffffff, &davinci_aintc_regs->ecr2);
  106. writel(0xffffffff, &davinci_aintc_regs->ecr3);
  107. }
  108. #endif
  109. /*
  110. * Enable PSC for various peripherals.
  111. */
  112. int da8xx_configure_lpsc_items(const struct lpsc_resource *item,
  113. const int n_items)
  114. {
  115. int i;
  116. for (i = 0; i < n_items; i++)
  117. lpsc_on(item[i].lpsc_no);
  118. return 0;
  119. }
  120. #endif