legoev3.c 4.0 KB

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