spi-boot.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (C) 2011 Renesas Solutions Corp.
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser
  5. * General Public License. See the file "COPYING.LIB" in the main
  6. * directory of this archive for more details.
  7. */
  8. #include <common.h>
  9. #define CONFIG_RAM_BOOT_PHYS 0x4ef80000
  10. #if defined(CONFIG_SH7757_OFFSET_SPI)
  11. #define CONFIG_SPI_ADDR 0x00010000
  12. #else
  13. #define CONFIG_SPI_ADDR 0x00000000
  14. #endif
  15. #define CONFIG_SPI_LENGTH 0x00030000
  16. #define CONFIG_RAM_BOOT 0x8ef80000
  17. #define SPIWDMADR 0xFE001018
  18. #define SPIWDMCNTR 0xFE001020
  19. #define SPIDMCOR 0xFE001028
  20. #define SPIDMINTSR 0xFE001188
  21. #define SPIDMINTMR 0xFE001190
  22. #define SPIDMINTSR_DMEND 0x00000004
  23. #define TBR 0xFE002000
  24. #define RBR 0xFE002000
  25. #define CR1 0xFE002008
  26. #define CR2 0xFE002010
  27. #define CR3 0xFE002018
  28. #define CR4 0xFE002020
  29. /* CR1 */
  30. #define SPI_TBE 0x80
  31. #define SPI_TBF 0x40
  32. #define SPI_RBE 0x20
  33. #define SPI_RBF 0x10
  34. #define SPI_PFONRD 0x08
  35. #define SPI_SSDB 0x04
  36. #define SPI_SSD 0x02
  37. #define SPI_SSA 0x01
  38. /* CR2 */
  39. #define SPI_RSTF 0x80
  40. #define SPI_LOOPBK 0x40
  41. #define SPI_CPOL 0x20
  42. #define SPI_CPHA 0x10
  43. #define SPI_L1M0 0x08
  44. /* CR4 */
  45. #define SPI_TBEI 0x80
  46. #define SPI_TBFI 0x40
  47. #define SPI_RBEI 0x20
  48. #define SPI_RBFI 0x10
  49. #define SPI_SSS 0x01
  50. #define spi_write(val, addr) (*(volatile unsigned long *)(addr)) = val
  51. #define spi_read(addr) (*(volatile unsigned long *)(addr))
  52. /* M25P80 */
  53. #define M25_READ 0x03
  54. #define __uses_spiboot2 __attribute__((section(".spiboot2.text")))
  55. static void __uses_spiboot2 spi_reset(void)
  56. {
  57. spi_write(0xfe, CR1);
  58. spi_write(0, SPIDMCOR);
  59. spi_write(0x00, CR1);
  60. spi_write(spi_read(CR2) | SPI_RSTF, CR2); /* fifo reset */
  61. spi_write(spi_read(CR2) & ~SPI_RSTF, CR2);
  62. }
  63. static void __uses_spiboot2 spi_read_flash(void *buf, unsigned long addr,
  64. unsigned long len)
  65. {
  66. spi_write(M25_READ, TBR);
  67. spi_write((addr >> 16) & 0xFF, TBR);
  68. spi_write((addr >> 8) & 0xFF, TBR);
  69. spi_write(addr & 0xFF, TBR);
  70. spi_write(SPIDMINTSR_DMEND, SPIDMINTSR);
  71. spi_write((unsigned long)buf, SPIWDMADR);
  72. spi_write(len & 0xFFFFFFE0, SPIWDMCNTR);
  73. spi_write(1, SPIDMCOR);
  74. spi_write(0xff, CR3);
  75. spi_write(spi_read(CR1) | SPI_SSDB, CR1);
  76. spi_write(spi_read(CR1) | SPI_SSA, CR1);
  77. while (!(spi_read(SPIDMINTSR) & SPIDMINTSR_DMEND))
  78. ;
  79. }
  80. void __uses_spiboot2 spiboot_main(void)
  81. {
  82. void (*_start)(void) = (void *)CONFIG_SYS_TEXT_BASE;
  83. spi_reset();
  84. spi_read_flash((void *)CONFIG_RAM_BOOT_PHYS, CONFIG_SPI_ADDR,
  85. CONFIG_SPI_LENGTH);
  86. _start();
  87. }