0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/export.h>
0013 #include <linux/of.h>
0014 #include <linux/of_device.h>
0015 #include <linux/mtd/map.h>
0016 #include <linux/mtd/xip.h>
0017 #include "physmap-ixp4xx.h"
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef CONFIG_CPU_BIG_ENDIAN
0039
0040 static inline u16 flash_read16(void __iomem *addr)
0041 {
0042 return be16_to_cpu(__raw_readw((void __iomem *)((unsigned long)addr ^ 0x2)));
0043 }
0044
0045 static inline void flash_write16(u16 d, void __iomem *addr)
0046 {
0047 __raw_writew(cpu_to_be16(d), (void __iomem *)((unsigned long)addr ^ 0x2));
0048 }
0049
0050 #define BYTE0(h) ((h) & 0xFF)
0051 #define BYTE1(h) (((h) >> 8) & 0xFF)
0052
0053 #else
0054
0055 static inline u16 flash_read16(const void __iomem *addr)
0056 {
0057 return __raw_readw(addr);
0058 }
0059
0060 static inline void flash_write16(u16 d, void __iomem *addr)
0061 {
0062 __raw_writew(d, addr);
0063 }
0064
0065 #define BYTE0(h) (((h) >> 8) & 0xFF)
0066 #define BYTE1(h) ((h) & 0xFF)
0067 #endif
0068
0069 static map_word ixp4xx_read16(struct map_info *map, unsigned long ofs)
0070 {
0071 map_word val;
0072
0073 val.x[0] = flash_read16(map->virt + ofs);
0074 return val;
0075 }
0076
0077
0078
0079
0080
0081
0082 static void ixp4xx_copy_from(struct map_info *map, void *to,
0083 unsigned long from, ssize_t len)
0084 {
0085 u8 *dest = (u8 *) to;
0086 void __iomem *src = map->virt + from;
0087
0088 if (len <= 0)
0089 return;
0090
0091 if (from & 1) {
0092 *dest++ = BYTE1(flash_read16(src-1));
0093 src++;
0094 --len;
0095 }
0096
0097 while (len >= 2) {
0098 u16 data = flash_read16(src);
0099 *dest++ = BYTE0(data);
0100 *dest++ = BYTE1(data);
0101 src += 2;
0102 len -= 2;
0103 }
0104
0105 if (len > 0)
0106 *dest++ = BYTE0(flash_read16(src));
0107 }
0108
0109 static void ixp4xx_write16(struct map_info *map, map_word d, unsigned long adr)
0110 {
0111 flash_write16(d.x[0], map->virt + adr);
0112 }
0113
0114 int of_flash_probe_ixp4xx(struct platform_device *pdev,
0115 struct device_node *np,
0116 struct map_info *map)
0117 {
0118 struct device *dev = &pdev->dev;
0119
0120
0121 if (!of_device_is_compatible(np, "intel,ixp4xx-flash"))
0122 return 0;
0123
0124 map->read = ixp4xx_read16;
0125 map->write = ixp4xx_write16;
0126 map->copy_from = ixp4xx_copy_from;
0127 map->copy_to = NULL;
0128
0129 dev_info(dev, "initialized Intel IXP4xx-specific physmap control\n");
0130
0131 return 0;
0132 }