misc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/global_data.h>
  18. #include <asm/io.h>
  19. #include <asm/arch/davinci_misc.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. #ifndef CONFIG_SPL_BUILD
  22. int dram_init(void)
  23. {
  24. /* dram_init must store complete ramsize in gd->ram_size */
  25. gd->ram_size = get_ram_size(
  26. (void *)CONFIG_SYS_SDRAM_BASE,
  27. CONFIG_MAX_RAM_BANK_SIZE);
  28. return 0;
  29. }
  30. int dram_init_banksize(void)
  31. {
  32. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  33. gd->bd->bi_dram[0].size = gd->ram_size;
  34. return 0;
  35. }
  36. #endif
  37. #ifdef CONFIG_DRIVER_TI_EMAC
  38. /*
  39. * Read ethernet MAC address from EEPROM for DVEVM compatible boards.
  40. * Returns 1 if found, 0 otherwise.
  41. */
  42. int dvevm_read_mac_address(uint8_t *buf)
  43. {
  44. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  45. /* Read MAC address. */
  46. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x7F00,
  47. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &buf[0], 6))
  48. goto i2cerr;
  49. /* Check that MAC address is valid. */
  50. if (!is_valid_ethaddr(buf))
  51. goto err;
  52. return 1; /* Found */
  53. i2cerr:
  54. printf("Read from EEPROM @ 0x%02x failed\n",
  55. CONFIG_SYS_I2C_EEPROM_ADDR);
  56. err:
  57. #endif /* CONFIG_SYS_I2C_EEPROM_ADDR */
  58. return 0;
  59. }
  60. /*
  61. * Set the mii mode as MII or RMII
  62. */
  63. void davinci_emac_mii_mode_sel(int mode_sel)
  64. {
  65. int val;
  66. val = readl(&davinci_syscfg_regs->cfgchip3);
  67. if (mode_sel == 0)
  68. val &= ~(1 << 8);
  69. else
  70. val |= (1 << 8);
  71. writel(val, &davinci_syscfg_regs->cfgchip3);
  72. }
  73. /*
  74. * If there is no MAC address in the environment, then it will be initialized
  75. * (silently) from the value in the EEPROM.
  76. */
  77. void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
  78. {
  79. uint8_t env_enetaddr[6];
  80. int ret;
  81. ret = eth_env_get_enetaddr_by_index("eth", 0, env_enetaddr);
  82. if (!ret) {
  83. /*
  84. * There is no MAC address in the environment, so we
  85. * initialize it from the value in the EEPROM.
  86. */
  87. debug("### Setting environment from EEPROM MAC address = "
  88. "\"%pM\"\n",
  89. env_enetaddr);
  90. ret = !eth_env_set_enetaddr("ethaddr", rom_enetaddr);
  91. }
  92. if (!ret)
  93. printf("Failed to set mac address from EEPROM: %d\n", ret);
  94. }
  95. #endif /* CONFIG_DRIVER_TI_EMAC */
  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. /*
  109. * Enable PSC for various peripherals.
  110. */
  111. int da8xx_configure_lpsc_items(const struct lpsc_resource *item,
  112. const int n_items)
  113. {
  114. int i;
  115. for (i = 0; i < n_items; i++)
  116. lpsc_on(item[i].lpsc_no);
  117. return 0;
  118. }