legoev3.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 <init.h>
  17. #include <spi.h>
  18. #include <spi_flash.h>
  19. #include <asm/arch/hardware.h>
  20. #include <asm/arch/pinmux_defs.h>
  21. #include <asm/io.h>
  22. #include <asm/arch/davinci_misc.h>
  23. #include <linux/errno.h>
  24. #include <hwconfig.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/setup.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. u8 board_rev;
  29. #define EEPROM_I2C_ADDR 0x50
  30. #define EEPROM_REV_OFFSET 0x3F00
  31. #define EEPROM_MAC_OFFSET 0x3F06
  32. const struct pinmux_resource pinmuxes[] = {
  33. PINMUX_ITEM(spi0_pins_base),
  34. PINMUX_ITEM(spi0_pins_scs0),
  35. PINMUX_ITEM(uart1_pins_txrx),
  36. PINMUX_ITEM(i2c0_pins),
  37. PINMUX_ITEM(mmc0_pins),
  38. };
  39. const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
  40. const struct lpsc_resource lpsc[] = {
  41. { DAVINCI_LPSC_SPI0 }, /* Serial Flash */
  42. { DAVINCI_LPSC_UART1 }, /* console */
  43. { DAVINCI_LPSC_MMC_SD },
  44. };
  45. const int lpsc_size = ARRAY_SIZE(lpsc);
  46. u32 get_board_rev(void)
  47. {
  48. u8 buf[2];
  49. if (!board_rev) {
  50. if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
  51. printf("\nBoard revision read failed!\n");
  52. } else {
  53. /*
  54. * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
  55. * Other revisions have checksum at EEPROM_REV_OFFSET+1
  56. * to detect this.
  57. */
  58. if ((buf[0] ^ buf[1]) == 0xFF)
  59. board_rev = buf[0];
  60. else
  61. board_rev = 3;
  62. }
  63. }
  64. return board_rev;
  65. }
  66. /*
  67. * The Bluetooth MAC address serves as the board serial number.
  68. */
  69. void get_board_serial(struct tag_serialnr *serialnr)
  70. {
  71. u32 offset;
  72. u8 buf[6];
  73. if (!board_rev)
  74. board_rev = get_board_rev();
  75. /* Board rev 3 has MAC address where rev should be */
  76. offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
  77. if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
  78. printf("\nBoard serial read failed!\n");
  79. } else {
  80. u8 *nr;
  81. nr = (u8 *)&serialnr->low;
  82. nr[0] = buf[5];
  83. nr[1] = buf[4];
  84. nr[2] = buf[3];
  85. nr[3] = buf[2];
  86. nr = (u8 *)&serialnr->high;
  87. nr[0] = buf[1];
  88. nr[1] = buf[0];
  89. nr[2] = 0;
  90. nr[3] = 0;
  91. }
  92. }
  93. int board_early_init_f(void)
  94. {
  95. /* enable the console UART */
  96. writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
  97. DAVINCI_UART_PWREMU_MGMT_UTRST),
  98. &davinci_uart1_ctrl_regs->pwremu_mgmt);
  99. /*
  100. * Power on required peripherals
  101. * ARM does not have access by default to PSC0 and PSC1
  102. * assuming here that the DSP bootloader has set the IOPU
  103. * such that PSC access is available to ARM
  104. */
  105. if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
  106. return 1;
  107. return 0;
  108. }
  109. int board_init(void)
  110. {
  111. irq_init();
  112. /* arch number of the board */
  113. /* LEGO didn't register for a unique number and uses da850evm */
  114. gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
  115. /* address of boot parameters */
  116. gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
  117. /* setup the SUSPSRC for ARM to control emulation suspend */
  118. writel(readl(&davinci_syscfg_regs->suspsrc) &
  119. ~(DAVINCI_SYSCFG_SUSPSRC_I2C |
  120. DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
  121. DAVINCI_SYSCFG_SUSPSRC_UART1),
  122. &davinci_syscfg_regs->suspsrc);
  123. /* configure pinmux settings */
  124. if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
  125. return 1;
  126. return 0;
  127. }