onenand_read.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * (C) Copyright 2005-2008 Samsung Electronis
  3. * Kyungmin Park <kyungmin.park@samsung.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/io.h>
  25. #include <asm/string.h>
  26. #include "onenand_ipl.h"
  27. #define onenand_block_address(block) (block)
  28. #define onenand_sector_address(page) (page << 2)
  29. #define onenand_buffer_address() ((1 << 3) << 8)
  30. #define onenand_bufferram_address(block) (0)
  31. #ifdef __HAVE_ARCH_MEMCPY32
  32. extern void *memcpy32(void *dest, void *src, int size);
  33. #endif
  34. /* read a page with ECC */
  35. static inline int onenand_read_page(ulong block, ulong page,
  36. u_char * buf, int pagesize)
  37. {
  38. unsigned long *base;
  39. #ifndef __HAVE_ARCH_MEMCPY32
  40. unsigned int offset, value;
  41. unsigned long *p;
  42. #endif
  43. onenand_writew(onenand_block_address(block),
  44. THIS_ONENAND(ONENAND_REG_START_ADDRESS1));
  45. onenand_writew(onenand_bufferram_address(block),
  46. THIS_ONENAND(ONENAND_REG_START_ADDRESS2));
  47. onenand_writew(onenand_sector_address(page),
  48. THIS_ONENAND(ONENAND_REG_START_ADDRESS8));
  49. onenand_writew(onenand_buffer_address(),
  50. THIS_ONENAND(ONENAND_REG_START_BUFFER));
  51. onenand_writew(ONENAND_INT_CLEAR, THIS_ONENAND(ONENAND_REG_INTERRUPT));
  52. onenand_writew(ONENAND_CMD_READ, THIS_ONENAND(ONENAND_REG_COMMAND));
  53. #ifndef __HAVE_ARCH_MEMCPY32
  54. p = (unsigned long *) buf;
  55. #endif
  56. base = (unsigned long *) (CFG_ONENAND_BASE + ONENAND_DATARAM);
  57. while (!(READ_INTERRUPT() & ONENAND_INT_READ))
  58. continue;
  59. #ifdef __HAVE_ARCH_MEMCPY32
  60. /* 32 bytes boundary memory copy */
  61. memcpy32(buf, base, pagesize);
  62. #else
  63. for (offset = 0; offset < (pagesize >> 2); offset++) {
  64. value = *(base + offset);
  65. *p++ = value;
  66. }
  67. #endif
  68. return 0;
  69. }
  70. #define ONENAND_START_PAGE 1
  71. #define ONENAND_PAGES_PER_BLOCK 64
  72. /**
  73. * onenand_read_block - Read a block data to buf
  74. * @return 0 on success
  75. */
  76. int onenand_read_block0(unsigned char *buf)
  77. {
  78. int page, offset = 0;
  79. int pagesize = ONENAND_PAGE_SIZE;
  80. /* MLC OneNAND has 4KiB page size */
  81. if (onenand_readw(THIS_ONENAND(ONENAND_REG_TECHNOLOGY)))
  82. pagesize <<= 1;
  83. /* NOTE: you must read page from page 1 of block 0 */
  84. /* read the block page by page*/
  85. for (page = ONENAND_START_PAGE;
  86. page < ONENAND_PAGES_PER_BLOCK; page++) {
  87. onenand_read_page(0, page, buf + offset, pagesize);
  88. offset += pagesize;
  89. }
  90. return 0;
  91. }