Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / generic / backport-4.9 / 062-v4.11-0007-mtd-spi-nor-Fix-S3AN-addressing-calculation.patch
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
6 The page calculation under spi_nor_s3an_addr_convert() was wrong. On
7 Default Address Mode we need to perform a divide by page_size.
8
9 Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
10 Acked-by: Marek Vasut <marek.vasut@gmail.com>
11 Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
12 ---
13  drivers/mtd/spi-nor/spi-nor.c | 9 ++++++---
14  1 file changed, 6 insertions(+), 3 deletions(-)
15
16 --- a/drivers/mtd/spi-nor/spi-nor.c
17 +++ b/drivers/mtd/spi-nor/spi-nor.c
18 @@ -431,11 +431,14 @@ static void spi_nor_unlock_and_unprep(st
19   */
20  static loff_t spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr)
21  {
22 -       unsigned int offset = addr;
23 +       unsigned int offset;
24 +       unsigned int page;
25  
26 -       offset %= nor->page_size;
27 +       offset = addr % nor->page_size;
28 +       page = addr / nor->page_size;
29 +       page <<= (nor->page_size > 512) ? 10 : 9;
30  
31 -       return ((addr - offset) << 1) | offset;
32 +       return page | offset;
33  }
34  
35  /*