5c46879966e625e53bcc6d0da47426a26cd05ad0
[openwrt/svn-archive/archive.git] / target / linux / lantiq / patches / 210-nor.patch
1 --- a/drivers/mtd/maps/Kconfig
2 +++ b/drivers/mtd/maps/Kconfig
3 @@ -260,6 +260,12 @@
4 Support for parsing CFE image tag and creating MTD partitions on
5 Broadcom BCM63xx boards.
6
7 +config MTD_LANTIQ
8 + bool "Lantiq SoC NOR support"
9 + depends on LANTIQ && MTD_PARTITIONS
10 + help
11 + Support for NOR flsh chips on Lantiq SoC
12 +
13 config MTD_DILNETPC
14 tristate "CFI Flash device mapped on DIL/Net PC"
15 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
16 --- a/drivers/mtd/maps/Makefile
17 +++ b/drivers/mtd/maps/Makefile
18 @@ -59,3 +59,4 @@
19 obj-$(CONFIG_MTD_VMU) += vmu-flash.o
20 obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o
21 obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o
22 +obj-$(CONFIG_MTD_LANTIQ) += lantiq.o
23 --- /dev/null
24 +++ b/drivers/mtd/maps/lantiq.c
25 @@ -0,0 +1,173 @@
26 +/*
27 + * This program is free software; you can redistribute it and/or modify it
28 + * under the terms of the GNU General Public License version 2 as published
29 + * by the Free Software Foundation.
30 + *
31 + * Copyright (C) 2004 Liu Peng Infineon IFAP DC COM CPE
32 + * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
33 + */
34 +
35 +#include <linux/module.h>
36 +#include <linux/types.h>
37 +#include <linux/kernel.h>
38 +#include <linux/io.h>
39 +#include <linux/init.h>
40 +#include <linux/mtd/mtd.h>
41 +#include <linux/mtd/map.h>
42 +#include <linux/mtd/partitions.h>
43 +#include <linux/mtd/cfi.h>
44 +#include <linux/magic.h>
45 +#include <linux/platform_device.h>
46 +#include <linux/mtd/physmap.h>
47 +
48 +#include <lantiq.h>
49 +#include <lantiq_platform.h>
50 +
51 +#ifdef CONFIG_SOC_LANTIQ_XWAY
52 +#include <xway.h>
53 +#endif
54 +
55 +static map_word
56 +lq_read16(struct map_info *map, unsigned long adr)
57 +{
58 + unsigned long flags;
59 + map_word temp;
60 + spin_lock_irqsave(&ebu_lock, flags);
61 + adr ^= 2;
62 + temp.x[0] = *((__u16 *)(map->virt + adr));
63 + spin_unlock_irqrestore(&ebu_lock, flags);
64 + return temp;
65 +}
66 +
67 +static void
68 +lq_write16(struct map_info *map, map_word d, unsigned long adr)
69 +{
70 + unsigned long flags;
71 + spin_lock_irqsave(&ebu_lock, flags);
72 + adr ^= 2;
73 + *((__u16 *)(map->virt + adr)) = d.x[0];
74 + spin_unlock_irqrestore(&ebu_lock, flags);
75 +}
76 +
77 +void
78 +lq_copy_from(struct map_info *map, void *to,
79 + unsigned long from, ssize_t len)
80 +{
81 + unsigned char *p;
82 + unsigned char *to_8;
83 + unsigned long flags;
84 + spin_lock_irqsave(&ebu_lock, flags);
85 + from = (unsigned long)(from + map->virt);
86 + p = (unsigned char *) from;
87 + to_8 = (unsigned char *) to;
88 + while (len--)
89 + *to_8++ = *p++;
90 + spin_unlock_irqrestore(&ebu_lock, flags);
91 +}
92 +
93 +void
94 +lq_copy_to(struct map_info *map, unsigned long to,
95 + const void *from, ssize_t len)
96 +{
97 + unsigned char *p = (unsigned char *)from;
98 + unsigned char *to_8;
99 + unsigned long flags;
100 + spin_lock_irqsave(&ebu_lock, flags);
101 + to += (unsigned long) map->virt;
102 + to_8 = (unsigned char *)to;
103 + while (len--)
104 + *p++ = *to_8++;
105 + spin_unlock_irqrestore(&ebu_lock, flags);
106 +}
107 +
108 +static const char *part_probe_types[] = { "cmdlinepart", NULL };
109 +
110 +static struct map_info lq_map = {
111 + .name = "lq_nor",
112 + .bankwidth = 2,
113 + .read = lq_read16,
114 + .write = lq_write16,
115 + .copy_from = lq_copy_from,
116 + .copy_to = lq_copy_to,
117 +};
118 +
119 +static int
120 +lq_mtd_probe(struct platform_device *pdev)
121 +{
122 + struct physmap_flash_data *lq_mtd_data =
123 + (struct physmap_flash_data*) dev_get_platdata(&pdev->dev);
124 + struct mtd_info *lq_mtd = NULL;
125 + struct mtd_partition *parts = NULL;
126 + struct resource *res = 0;
127 + int nr_parts = 0;
128 +
129 +#ifdef CONFIG_SOC_LANTIQ_XWAY
130 + lq_w32(lq_r32(LQ_EBU_BUSCON0) & ~EBU_WRDIS, LQ_EBU_BUSCON0);
131 +#endif
132 +
133 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
134 + if(!res)
135 + {
136 + dev_err(&pdev->dev, "failed to get memory resource");
137 + return -ENOENT;
138 + }
139 + res = request_mem_region(res->start, resource_size(res),
140 + dev_name(&pdev->dev));
141 + if(!res)
142 + {
143 + dev_err(&pdev->dev, "failed to request mem resource");
144 + return -EBUSY;
145 + }
146 +
147 + lq_map.phys = res->start;
148 + lq_map.size = resource_size(res);
149 + lq_map.virt = ioremap_nocache(lq_map.phys, lq_map.size);
150 +
151 + if (!lq_map.virt ) {
152 + dev_err(&pdev->dev, "failed to ioremap!\n");
153 + return -EIO;
154 + }
155 +
156 + lq_mtd = (struct mtd_info *) do_map_probe("cfi_probe", &lq_map);
157 + if (!lq_mtd) {
158 + iounmap(lq_map.virt);
159 + dev_err(&pdev->dev, "probing failed\n");
160 + return -ENXIO;
161 + }
162 +
163 + lq_mtd->owner = THIS_MODULE;
164 +
165 + nr_parts = parse_mtd_partitions(lq_mtd, part_probe_types, &parts, 0);
166 + if (nr_parts > 0) {
167 + dev_info(&pdev->dev, "using %d partitions from cmdline", nr_parts);
168 + } else {
169 + nr_parts = lq_mtd_data->nr_parts;
170 + parts = lq_mtd_data->parts;
171 + }
172 +
173 + add_mtd_partitions(lq_mtd, parts, nr_parts);
174 + return 0;
175 +}
176 +
177 +static struct platform_driver lq_mtd_driver = {
178 + .probe = lq_mtd_probe,
179 + .driver = {
180 + .name = "lq_nor",
181 + .owner = THIS_MODULE,
182 + },
183 +};
184 +
185 +int __init
186 +init_lq_mtd(void)
187 +{
188 + int ret = platform_driver_register(&lq_mtd_driver);
189 + if (ret)
190 + printk(KERN_INFO "lq_nor: error registering platfom driver");
191 + return ret;
192 +}
193 +
194 +module_init(init_lq_mtd);
195 +
196 +MODULE_LICENSE("GPL");
197 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
198 +MODULE_DESCRIPTION("Lantiq SoC NOR");
199 --- a/drivers/mtd/chips/cfi_cmdset_0001.c
200 +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
201 @@ -40,7 +40,11 @@
202 /* #define CMDSET0001_DISABLE_WRITE_SUSPEND */
203
204 // debugging, turns off buffer write mode if set to 1
205 -#define FORCE_WORD_WRITE 0
206 +#ifdef CONFIG_LANTIQ
207 +# define FORCE_WORD_WRITE 1
208 +#else
209 +# define FORCE_WORD_WRITE 0
210 +#endif
211
212 /* Intel chips */
213 #define I82802AB 0x00ad
214 @@ -1493,6 +1497,9 @@
215 int ret=0;
216
217 adr += chip->start;
218 +#ifdef CONFIG_LANTIQ
219 + adr ^= 2;
220 +#endif
221
222 switch (mode) {
223 case FL_WRITING:
224 --- a/drivers/mtd/chips/cfi_cmdset_0002.c
225 +++ b/drivers/mtd/chips/cfi_cmdset_0002.c
226 @@ -39,7 +39,11 @@
227 #include <linux/mtd/xip.h>
228
229 #define AMD_BOOTLOC_BUG
230 -#define FORCE_WORD_WRITE 0
231 +#ifdef CONFIG_LANTIQ
232 +# define FORCE_WORD_WRITE 1
233 +#else
234 +# define FORCE_WORD_WRITE 0
235 +#endif
236
237 #define MAX_WORD_RETRIES 3
238
239 @@ -1167,6 +1171,10 @@
240
241 adr += chip->start;
242
243 +#ifdef CONFIG_LANTIQ
244 + adr ^= 2;
245 +#endif
246 +
247 mutex_lock(&chip->mutex);
248 ret = get_chip(map, chip, adr, FL_WRITING);
249 if (ret) {