legoev3.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 David Lechner <david@lechnology.com>
  4. *
  5. * Based on da850evm.c
  6. *
  7. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  8. *
  9. * Based on da830evm.c. Original Copyrights follow:
  10. *
  11. * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
  12. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  13. */
  14. #include <common.h>
  15. #include <i2c.h>
  16. #include <spi.h>
  17. #include <spi_flash.h>
  18. #include <asm/arch/hardware.h>
  19. #include <asm/arch/pinmux_defs.h>
  20. #include <asm/io.h>
  21. #include <asm/arch/davinci_misc.h>
  22. #include <linux/errno.h>
  23. #include <hwconfig.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/setup.h>
  26. #ifdef CONFIG_MMC_DAVINCI
  27. #include <mmc.h>
  28. #include <asm/arch/sdmmc_defs.h>
  29. #endif
  30. DECLARE_GLOBAL_DATA_PTR;
  31. u8 board_rev;
  32. #define EEPROM_I2C_ADDR 0x50
  33. #define EEPROM_REV_OFFSET 0x3F00
  34. #define EEPROM_MAC_OFFSET 0x3F06
  35. #ifdef CONFIG_MMC_DAVINCI
  36. static struct davinci_mmc mmc_sd0 = {
  37. .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
  38. .host_caps = MMC_MODE_4BIT, /* DA850 supports only 4-bit SD/MMC */
  39. .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
  40. .version = MMC_CTLR_VERSION_2,
  41. };
  42. int board_mmc_init(bd_t *bis)
  43. {
  44. mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
  45. /* Add slot-0 to mmc subsystem */
  46. return davinci_mmc_init(bis, &mmc_sd0);
  47. }
  48. #endif
  49. const struct pinmux_resource pinmuxes[] = {
  50. PINMUX_ITEM(spi0_pins_base),
  51. PINMUX_ITEM(spi0_pins_scs0),
  52. PINMUX_ITEM(uart1_pins_txrx),
  53. PINMUX_ITEM(i2c0_pins),
  54. PINMUX_ITEM(mmc0_pins),
  55. };
  56. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  57. const struct lpsc_resource lpsc[] = {
  58. { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
  59. { DAVINCI_LPSC_UART1 }, /* console */
  60. { DAVINCI_LPSC_MMC_SD },
  61. };
  62. const int lpsc_size = ARRAY_SIZE(lpsc);
  63. u32 get_board_rev(void)
  64. {
  65. u8 buf[2];
  66. if (!board_rev) {
  67. if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
  68. printf("\nBoard revision read failed!\n");
  69. } else {
  70. /*
  71. * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
  72. * Other revisions have checksum at EEPROM_REV_OFFSET+1
  73. * to detect this.
  74. */
  75. if ((buf[0] ^ buf[1]) == 0xFF)
  76. board_rev = buf[0];
  77. else
  78. board_rev = 3;
  79. }
  80. }
  81. return board_rev;
  82. }
  83. /*
  84. * The Bluetooth MAC address serves as the board serial number.
  85. */
  86. void get_board_serial(struct tag_serialnr *serialnr)
  87. {
  88. u32 offset;
  89. u8 buf[6];
  90. if (!board_rev)
  91. board_rev = get_board_rev();
  92. /* Board rev 3 has MAC address where rev should be */
  93. offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
  94. if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
  95. printf("\nBoard serial read failed!\n");
  96. } else {
  97. u8 *nr;
  98. nr = (u8 *)&serialnr->low;
  99. nr[0] = buf[5];
  100. nr[1] = buf[4];
  101. nr[2] = buf[3];
  102. nr[3] = buf[2];
  103. nr = (u8 *)&serialnr->high;
  104. nr[0] = buf[1];
  105. nr[1] = buf[0];
  106. nr[2] = 0;
  107. nr[3] = 0;
  108. }
  109. }
  110. int board_early_init_f(void)
  111. {
  112. /* enable the console UART */
  113. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  114. DAVINCI_UART_PWREMU_MGMT_UTRST),
  115. &davinci_uart1_ctrl_regs->pwremu_mgmt);
  116. /*
  117. * Power on required peripherals
  118. * ARM does not have access by default to PSC0 and PSC1
  119. * assuming here that the DSP bootloader has set the IOPU
  120. * such that PSC access is available to ARM
  121. */
  122. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  123. return 1;
  124. return 0;
  125. }
  126. int board_init(void)
  127. {
  128. irq_init();
  129. /* arch number of the board */
  130. /* LEGO didn't register for a unique number and uses da850evm */
  131. gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
  132. /* address of boot parameters */
  133. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  134. /* setup the SUSPSRC for ARM to control emulation suspend */
  135. writel(readl(&davinci_syscfg_regs->suspsrc) &
  136. ~(DAVINCI_SYSCFG_SUSPSRC_I2C |
  137. DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  138. DAVINCI_SYSCFG_SUSPSRC_UART1),
  139. &davinci_syscfg_regs->suspsrc);
  140. /* configure pinmux settings */
  141. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  142. return 1;
  143. return 0;
  144. }