misc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <environment.h>
  13. #include <i2c.h>
  14. #include <net.h>
  15. #include <asm/arch/hardware.h>
  16. #include <asm/io.h>
  17. #include <asm/arch/davinci_misc.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. #ifndef CONFIG_SPL_BUILD
  20. int dram_init(void)
  21. {
  22. /* dram_init must store complete ramsize in gd->ram_size */
  23. gd->ram_size = get_ram_size(
  24. (void *)CONFIG_SYS_SDRAM_BASE,
  25. CONFIG_MAX_RAM_BANK_SIZE);
  26. return 0;
  27. }
  28. int dram_init_banksize(void)
  29. {
  30. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  31. gd->bd->bi_dram[0].size = gd->ram_size;
  32. return 0;
  33. }
  34. #endif
  35. #ifdef CONFIG_DRIVER_TI_EMAC
  36. /*
  37. * Read ethernet MAC address from EEPROM for DVEVM compatible boards.
  38. * Returns 1 if found, 0 otherwise.
  39. */
  40. int dvevm_read_mac_address(uint8_t *buf)
  41. {
  42. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  43. /* Read MAC address. */
  44. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x7F00,
  45. CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &buf[0], 6))
  46. goto i2cerr;
  47. /* Check that MAC address is valid. */
  48. if (!is_valid_ethaddr(buf))
  49. goto err;
  50. return 1; /* Found */
  51. i2cerr:
  52. printf("Read from EEPROM @ 0x%02x failed\n",
  53. CONFIG_SYS_I2C_EEPROM_ADDR);
  54. err:
  55. #endif /* CONFIG_SYS_I2C_EEPROM_ADDR */
  56. return 0;
  57. }
  58. /*
  59. * Set the mii mode as MII or RMII
  60. */
  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. /*
  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_env_get_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_env_set_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. void irq_init(void)
  95. {
  96. /*
  97. * Mask all IRQs by clearing the global enable and setting
  98. * the enable clear for all the 90 interrupts.
  99. */
  100. writel(0, &davinci_aintc_regs->ger);
  101. writel(0, &davinci_aintc_regs->hier);
  102. writel(0xffffffff, &davinci_aintc_regs->ecr1);
  103. writel(0xffffffff, &davinci_aintc_regs->ecr2);
  104. writel(0xffffffff, &davinci_aintc_regs->ecr3);
  105. }
  106. /*
  107. * Enable PSC for various peripherals.
  108. */
  109. int da8xx_configure_lpsc_items(const struct lpsc_resource *item,
  110. const int n_items)
  111. {
  112. int i;
  113. for (i = 0; i < n_items; i++)
  114. lpsc_on(item[i].lpsc_no);
  115. return 0;
  116. }