062-v4.11-0007-mtd-spi-nor-Fix-S3AN-addressing-calculation.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. From 5f0e0758efddef5b06994a76d8c7f0b8a4c1daae Mon Sep 17 00:00:00 2001
  2. From: Ricardo Ribalda <ricardo.ribalda@gmail.com>
  3. Date: Wed, 18 Jan 2017 17:40:16 +0100
  4. Subject: [PATCH] mtd: spi-nor: Fix S3AN addressing calculation
  5. The page calculation under spi_nor_s3an_addr_convert() was wrong. On
  6. Default Address Mode we need to perform a divide by page_size.
  7. Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
  8. Acked-by: Marek Vasut <marek.vasut@gmail.com>
  9. Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
  10. ---
  11. drivers/mtd/spi-nor/spi-nor.c | 9 ++++++---
  12. 1 file changed, 6 insertions(+), 3 deletions(-)
  13. --- a/drivers/mtd/spi-nor/spi-nor.c
  14. +++ b/drivers/mtd/spi-nor/spi-nor.c
  15. @@ -431,11 +431,14 @@ static void spi_nor_unlock_and_unprep(st
  16. */
  17. static loff_t spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr)
  18. {
  19. - unsigned int offset = addr;
  20. + unsigned int offset;
  21. + unsigned int page;
  22. - offset %= nor->page_size;
  23. + offset = addr % nor->page_size;
  24. + page = addr / nor->page_size;
  25. + page <<= (nor->page_size > 512) ? 10 : 9;
  26. - return ((addr - offset) << 1) | offset;
  27. + return page | offset;
  28. }
  29. /*