Skip to content

Commit 2aba2f2

Browse files
Linus Walleijmiquelraynal
authored andcommitted
mtd: physmap_of: add a hook for Intel IXP4xx flash probing
In order to support device tree probing of IXP4xx NOR flash chips, a certain big-endian or mixed-endian memory access pattern need to be used. I have opted to use the pattern set by previous plug-ins to physmap for Gemini and Versatile, just override some functions and reuse most of the physmap core code as it is to minimize maintenance. Parts of drivers/mtd/ixp4xx.c are copied into this file. After we have IXP4xx converted fully to device tree, the drivers/mtd/ixp4xx.c file will be deleted and this will be the only access pattern to the IXP4xx flash. I did not keep the quirk in the flash write function after probe, where the old code for a while checks for access to odd addresses, fails and assigns a "faster" write function once it has convinced probe to only use 2-byte accesses. As we mandate that this device should be using bank-width = <2> this should not be a problem unless misconfigured. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 8b3cc92 commit 2aba2f2

5 files changed

Lines changed: 166 additions & 0 deletions

File tree

‎drivers/mtd/maps/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ config MTD_PHYSMAP_GEMINI
9696
platforms, some detection and setting up parallel mode on the
9797
external interface.
9898

99+
config MTD_PHYSMAP_IXP4XX
100+
bool "Intel IXP4xx OF-based physical memory map handling"
101+
depends on MTD_PHYSMAP_OF
102+
depends on ARM
103+
select MTD_COMPLEX_MAPPINGS
104+
select MTD_CFI_BE_BYTE_SWAP if CPU_BIG_ENDIAN
105+
default ARCH_IXP4XX
106+
help
107+
This provides some extra DT physmap parsing for the Intel IXP4xx
108+
platforms, some elaborate endianness handling in particular.
109+
99110
config MTD_PHYSMAP_GPIO_ADDR
100111
bool "GPIO-assisted Flash Chip Support"
101112
depends on MTD_PHYSMAP

‎drivers/mtd/maps/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ obj-$(CONFIG_MTD_PXA2XX) += pxa2xx-flash.o
2020
physmap-objs-y += physmap-core.o
2121
physmap-objs-$(CONFIG_MTD_PHYSMAP_VERSATILE) += physmap-versatile.o
2222
physmap-objs-$(CONFIG_MTD_PHYSMAP_GEMINI) += physmap-gemini.o
23+
physmap-objs-$(CONFIG_MTD_PHYSMAP_IXP4XX) += physmap-ixp4xx.o
2324
physmap-objs := $(physmap-objs-y)
2425
obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
2526
obj-$(CONFIG_MTD_PISMO) += pismo.o

‎drivers/mtd/maps/physmap-core.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/gpio/consumer.h>
4242

4343
#include "physmap-gemini.h"
44+
#include "physmap-ixp4xx.h"
4445
#include "physmap-versatile.h"
4546

4647
struct physmap_flash_info {
@@ -370,6 +371,10 @@ static int physmap_flash_of_init(struct platform_device *dev)
370371
if (err)
371372
return err;
372373

374+
err = of_flash_probe_ixp4xx(dev, dp, &info->maps[i]);
375+
if (err)
376+
return err;
377+
373378
err = of_flash_probe_versatile(dev, dp, &info->maps[i]);
374379
if (err)
375380
return err;

‎drivers/mtd/maps/physmap-ixp4xx.c‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Intel IXP4xx OF physmap add-on
4+
* Copyright (C) 2019 Linus Walleij <linus.walleij@linaro.org>
5+
*
6+
* Based on the ixp4xx.c map driver, originally written by:
7+
* Intel Corporation
8+
* Deepak Saxena <dsaxena@mvista.com>
9+
* Copyright (C) 2002 Intel Corporation
10+
* Copyright (C) 2003-2004 MontaVista Software, Inc.
11+
*/
12+
#include <linux/export.h>
13+
#include <linux/of.h>
14+
#include <linux/of_device.h>
15+
#include <linux/mtd/map.h>
16+
#include <linux/mtd/xip.h>
17+
#include "physmap-ixp4xx.h"
18+
19+
/*
20+
* Read/write a 16 bit word from flash address 'addr'.
21+
*
22+
* When the cpu is in little-endian mode it swizzles the address lines
23+
* ('address coherency') so we need to undo the swizzling to ensure commands
24+
* and the like end up on the correct flash address.
25+
*
26+
* To further complicate matters, due to the way the expansion bus controller
27+
* handles 32 bit reads, the byte stream ABCD is stored on the flash as:
28+
* D15 D0
29+
* +---+---+
30+
* | A | B | 0
31+
* +---+---+
32+
* | C | D | 2
33+
* +---+---+
34+
* This means that on LE systems each 16 bit word must be swapped. Note that
35+
* this requires CONFIG_MTD_CFI_BE_BYTE_SWAP to be enabled to 'unswap' the CFI
36+
* data and other flash commands which are always in D7-D0.
37+
*/
38+
#ifndef CONFIG_CPU_BIG_ENDIAN
39+
40+
static inline u16 flash_read16(void __iomem *addr)
41+
{
42+
return be16_to_cpu(__raw_readw((void __iomem *)((unsigned long)addr ^ 0x2)));
43+
}
44+
45+
static inline void flash_write16(u16 d, void __iomem *addr)
46+
{
47+
__raw_writew(cpu_to_be16(d), (void __iomem *)((unsigned long)addr ^ 0x2));
48+
}
49+
50+
#define BYTE0(h) ((h) & 0xFF)
51+
#define BYTE1(h) (((h) >> 8) & 0xFF)
52+
53+
#else
54+
55+
static inline u16 flash_read16(const void __iomem *addr)
56+
{
57+
return __raw_readw(addr);
58+
}
59+
60+
static inline void flash_write16(u16 d, void __iomem *addr)
61+
{
62+
__raw_writew(d, addr);
63+
}
64+
65+
#define BYTE0(h) (((h) >> 8) & 0xFF)
66+
#define BYTE1(h) ((h) & 0xFF)
67+
#endif
68+
69+
static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
70+
{
71+
map_word val;
72+
73+
val.x[0] = flash_read16(map->virt + ofs);
74+
return val;
75+
}
76+
77+
/*
78+
* The IXP4xx expansion bus only allows 16-bit wide acceses
79+
* when attached to a 16-bit wide device (such as the 28F128J3A),
80+
* so we can't just memcpy_fromio().
81+
*/
82+
static void ixp4xx_copy_from(struct map_info *map, void *to,
83+
unsigned long from, ssize_t len)
84+
{
85+
u8 *dest = (u8 *) to;
86+
void __iomem *src = map->virt + from;
87+
88+
if (len <= 0)
89+
return;
90+
91+
if (from & 1) {
92+
*dest++ = BYTE1(flash_read16(src-1));
93+
src++;
94+
--len;
95+
}
96+
97+
while (len >= 2) {
98+
u16 data = flash_read16(src);
99+
*dest++ = BYTE0(data);
100+
*dest++ = BYTE1(data);
101+
src += 2;
102+
len -= 2;
103+
}
104+
105+
if (len > 0)
106+
*dest++ = BYTE0(flash_read16(src));
107+
}
108+
109+
static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
110+
{
111+
flash_write16(d.x[0], map->virt + adr);
112+
}
113+
114+
int of_flash_probe_ixp4xx(struct platform_device *pdev,
115+
struct device_node *np,
116+
struct map_info *map)
117+
{
118+
struct device *dev = &pdev->dev;
119+
120+
/* Multiplatform guard */
121+
if (!of_device_is_compatible(np, "intel,ixp4xx-flash"))
122+
return 0;
123+
124+
map->read = ixp4xx_read16;
125+
map->write = ixp4xx_write16;
126+
map->copy_from = ixp4xx_copy_from;
127+
map->copy_to = NULL;
128+
129+
dev_info(dev, "initialized Intel IXP4xx-specific physmap control\n");
130+
131+
return 0;
132+
}

‎drivers/mtd/maps/physmap-ixp4xx.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#include <linux/of.h>
3+
#include <linux/mtd/map.h>
4+
5+
#ifdef CONFIG_MTD_PHYSMAP_IXP4XX
6+
int of_flash_probe_ixp4xx(struct platform_device *pdev,
7+
struct device_node *np,
8+
struct map_info *map);
9+
#else
10+
static inline
11+
int of_flash_probe_ixp4xx(struct platform_device *pdev,
12+
struct device_node *np,
13+
struct map_info *map)
14+
{
15+
return 0;
16+
}
17+
#endif

0 commit comments

Comments
 (0)