[lantiq]
[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,183 @@
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 +#include <linux/mtd/cfi.h>
48 +
49 +#include <lantiq.h>
50 +#include <lantiq_platform.h>
51 +
52 +#ifdef CONFIG_SOC_LANTIQ_XWAY
53 +#include <xway.h>
54 +#endif
55 +static int ltq_mtd_probing;
56 +
57 +static map_word
58 +lq_read16(struct map_info *map, unsigned long adr)
59 +{
60 + unsigned long flags;
61 + map_word temp;
62 + spin_lock_irqsave(&ebu_lock, flags);
63 + if (ltq_mtd_probing)
64 + adr ^= 2;
65 + temp.x[0] = *((__u16 *)(map->virt + adr));
66 + spin_unlock_irqrestore(&ebu_lock, flags);
67 + return temp;
68 +}
69 +
70 +static void
71 +lq_write16(struct map_info *map, map_word d, unsigned long adr)
72 +{
73 + unsigned long flags;
74 + spin_lock_irqsave(&ebu_lock, flags);
75 + if (ltq_mtd_probing)
76 + adr ^= 2;
77 + *((__u16 *)(map->virt + adr)) = d.x[0];
78 + spin_unlock_irqrestore(&ebu_lock, flags);
79 +}
80 +
81 +void
82 +lq_copy_from(struct map_info *map, void *to,
83 + unsigned long from, ssize_t len)
84 +{
85 + unsigned char *p;
86 + unsigned char *to_8;
87 + unsigned long flags;
88 + spin_lock_irqsave(&ebu_lock, flags);
89 + from = (unsigned long)(from + map->virt);
90 + p = (unsigned char *) from;
91 + to_8 = (unsigned char *) to;
92 + while (len--)
93 + *to_8++ = *p++;
94 + spin_unlock_irqrestore(&ebu_lock, flags);
95 +}
96 +
97 +void
98 +lq_copy_to(struct map_info *map, unsigned long to,
99 + const void *from, ssize_t len)
100 +{
101 + unsigned char *p = (unsigned char *)from;
102 + unsigned char *to_8;
103 + unsigned long flags;
104 + spin_lock_irqsave(&ebu_lock, flags);
105 + to += (unsigned long) map->virt;
106 + to_8 = (unsigned char *)to;
107 + while (len--)
108 + *p++ = *to_8++;
109 + spin_unlock_irqrestore(&ebu_lock, flags);
110 +}
111 +
112 +static const char *part_probe_types[] = { "cmdlinepart", NULL };
113 +
114 +static struct map_info lq_map = {
115 + .name = "lq_nor",
116 + .bankwidth = 2,
117 + .read = lq_read16,
118 + .write = lq_write16,
119 + .copy_from = lq_copy_from,
120 + .copy_to = lq_copy_to,
121 +};
122 +
123 +static int
124 +lq_mtd_probe(struct platform_device *pdev)
125 +{
126 + struct physmap_flash_data *lq_mtd_data =
127 + (struct physmap_flash_data*) dev_get_platdata(&pdev->dev);
128 + struct mtd_info *lq_mtd = NULL;
129 + struct mtd_partition *parts = NULL;
130 + struct resource *res = 0;
131 + int nr_parts = 0;
132 + struct cfi_private *cfi;
133 +
134 +#ifdef CONFIG_SOC_LANTIQ_XWAY
135 + lq_w32(lq_r32(LQ_EBU_BUSCON0) & ~EBU_WRDIS, LQ_EBU_BUSCON0);
136 +#endif
137 +
138 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
139 + if(!res)
140 + {
141 + dev_err(&pdev->dev, "failed to get memory resource");
142 + return -ENOENT;
143 + }
144 + res = request_mem_region(res->start, resource_size(res),
145 + dev_name(&pdev->dev));
146 + if(!res)
147 + {
148 + dev_err(&pdev->dev, "failed to request mem resource");
149 + return -EBUSY;
150 + }
151 +
152 + lq_map.phys = res->start;
153 + lq_map.size = resource_size(res);
154 + lq_map.virt = ioremap_nocache(lq_map.phys, lq_map.size);
155 +
156 + if (!lq_map.virt ) {
157 + dev_err(&pdev->dev, "failed to ioremap!\n");
158 + return -EIO;
159 + }
160 +
161 + ltq_mtd_probing = 1;
162 + lq_mtd = (struct mtd_info *) do_map_probe("cfi_probe", &lq_map);
163 + ltq_mtd_probing = 0;
164 + if (!lq_mtd) {
165 + iounmap(lq_map.virt);
166 + dev_err(&pdev->dev, "probing failed\n");
167 + return -ENXIO;
168 + }
169 +
170 + lq_mtd->owner = THIS_MODULE;
171 + cfi = lq_map.fldrv_priv;
172 + cfi->addr_unlock1 ^= 1;
173 + cfi->addr_unlock2 ^= 1;
174 +
175 + nr_parts = parse_mtd_partitions(lq_mtd, part_probe_types, &parts, 0);
176 + if (nr_parts > 0) {
177 + dev_info(&pdev->dev, "using %d partitions from cmdline", nr_parts);
178 + } else {
179 + nr_parts = lq_mtd_data->nr_parts;
180 + parts = lq_mtd_data->parts;
181 + }
182 +
183 + add_mtd_partitions(lq_mtd, parts, nr_parts);
184 + return 0;
185 +}
186 +
187 +static struct platform_driver lq_mtd_driver = {
188 + .probe = lq_mtd_probe,
189 + .driver = {
190 + .name = "lq_nor",
191 + .owner = THIS_MODULE,
192 + },
193 +};
194 +
195 +int __init
196 +init_lq_mtd(void)
197 +{
198 + int ret = platform_driver_register(&lq_mtd_driver);
199 + if (ret)
200 + printk(KERN_INFO "lq_nor: error registering platfom driver");
201 + return ret;
202 +}
203 +
204 +module_init(init_lq_mtd);
205 +
206 +MODULE_LICENSE("GPL");
207 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
208 +MODULE_DESCRIPTION("Lantiq SoC NOR");