Commit 5d95f8e2dd263f3e05ae4bf9a3309552363e13af
Committed by
Dominik Brodowski
1 parent
d571c79e86
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
pcmcia: convert drivers/pcmcia/* to use module_platform_driver()
This patch converts the drivers in drivers/pcmcia/* to use the module_platform_driver() macro which makes the code smaller and a bit simpler. Signed-off-by: Axel Lin <axel.lin@gmail.com> Acked-by: Wolfram Sang <w.sang@pengutronix.de> Acked-by: Olof Johansson <olof@lixom.net> Acked-by: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Marc Zyngier <maz@misterjones.org> [for the viper part] Acked-by: Manuel Lauss <manuel.lauss@googlemail.com> [for the db1xxx_ss.c part] Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Showing 6 changed files with 6 additions and 71 deletions Inline Diff
drivers/pcmcia/bfin_cf_pcmcia.c
1 | /* | 1 | /* |
2 | * file: drivers/pcmcia/bfin_cf.c | 2 | * file: drivers/pcmcia/bfin_cf.c |
3 | * | 3 | * |
4 | * based on: drivers/pcmcia/omap_cf.c | 4 | * based on: drivers/pcmcia/omap_cf.c |
5 | * omap_cf.c -- OMAP 16xx CompactFlash controller driver | 5 | * omap_cf.c -- OMAP 16xx CompactFlash controller driver |
6 | * | 6 | * |
7 | * Copyright (c) 2005 David Brownell | 7 | * Copyright (c) 2005 David Brownell |
8 | * Copyright (c) 2006-2008 Michael Hennerich Analog Devices Inc. | 8 | * Copyright (c) 2006-2008 Michael Hennerich Analog Devices Inc. |
9 | * | 9 | * |
10 | * bugs: enter bugs at http://blackfin.uclinux.org/ | 10 | * bugs: enter bugs at http://blackfin.uclinux.org/ |
11 | * | 11 | * |
12 | * this program is free software; you can redistribute it and/or modify | 12 | * this program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the gnu general public license as published by | 13 | * it under the terms of the gnu general public license as published by |
14 | * the free software foundation; either version 2, or (at your option) | 14 | * the free software foundation; either version 2, or (at your option) |
15 | * any later version. | 15 | * any later version. |
16 | * | 16 | * |
17 | * this program is distributed in the hope that it will be useful, | 17 | * this program is distributed in the hope that it will be useful, |
18 | * but without any warranty; without even the implied warranty of | 18 | * but without any warranty; without even the implied warranty of |
19 | * merchantability or fitness for a particular purpose. see the | 19 | * merchantability or fitness for a particular purpose. see the |
20 | * gnu general public license for more details. | 20 | * gnu general public license for more details. |
21 | * | 21 | * |
22 | * you should have received a copy of the gnu general public license | 22 | * you should have received a copy of the gnu general public license |
23 | * along with this program; see the file copying. | 23 | * along with this program; see the file copying. |
24 | * if not, write to the free software foundation, | 24 | * if not, write to the free software foundation, |
25 | * 59 temple place - suite 330, boston, ma 02111-1307, usa. | 25 | * 59 temple place - suite 330, boston, ma 02111-1307, usa. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/kernel.h> | 29 | #include <linux/kernel.h> |
30 | #include <linux/sched.h> | 30 | #include <linux/sched.h> |
31 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
32 | #include <linux/errno.h> | 32 | #include <linux/errno.h> |
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <linux/interrupt.h> | 36 | #include <linux/interrupt.h> |
37 | #include <linux/irq.h> | 37 | #include <linux/irq.h> |
38 | #include <linux/io.h> | 38 | #include <linux/io.h> |
39 | 39 | ||
40 | #include <pcmcia/ss.h> | 40 | #include <pcmcia/ss.h> |
41 | #include <pcmcia/cisreg.h> | 41 | #include <pcmcia/cisreg.h> |
42 | #include <asm/gpio.h> | 42 | #include <asm/gpio.h> |
43 | 43 | ||
44 | #define SZ_1K 0x00000400 | 44 | #define SZ_1K 0x00000400 |
45 | #define SZ_8K 0x00002000 | 45 | #define SZ_8K 0x00002000 |
46 | #define SZ_2K (2 * SZ_1K) | 46 | #define SZ_2K (2 * SZ_1K) |
47 | 47 | ||
48 | #define POLL_INTERVAL (2 * HZ) | 48 | #define POLL_INTERVAL (2 * HZ) |
49 | 49 | ||
50 | #define CF_ATASEL_ENA 0x20311802 /* Inverts RESET */ | 50 | #define CF_ATASEL_ENA 0x20311802 /* Inverts RESET */ |
51 | #define CF_ATASEL_DIS 0x20311800 | 51 | #define CF_ATASEL_DIS 0x20311800 |
52 | 52 | ||
53 | #define bfin_cf_present(pfx) (gpio_get_value(pfx)) | 53 | #define bfin_cf_present(pfx) (gpio_get_value(pfx)) |
54 | 54 | ||
55 | /*--------------------------------------------------------------------------*/ | 55 | /*--------------------------------------------------------------------------*/ |
56 | 56 | ||
57 | static const char driver_name[] = "bfin_cf_pcmcia"; | 57 | static const char driver_name[] = "bfin_cf_pcmcia"; |
58 | 58 | ||
59 | struct bfin_cf_socket { | 59 | struct bfin_cf_socket { |
60 | struct pcmcia_socket socket; | 60 | struct pcmcia_socket socket; |
61 | 61 | ||
62 | struct timer_list timer; | 62 | struct timer_list timer; |
63 | unsigned present:1; | 63 | unsigned present:1; |
64 | unsigned active:1; | 64 | unsigned active:1; |
65 | 65 | ||
66 | struct platform_device *pdev; | 66 | struct platform_device *pdev; |
67 | unsigned long phys_cf_io; | 67 | unsigned long phys_cf_io; |
68 | unsigned long phys_cf_attr; | 68 | unsigned long phys_cf_attr; |
69 | u_int irq; | 69 | u_int irq; |
70 | u_short cd_pfx; | 70 | u_short cd_pfx; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | /*--------------------------------------------------------------------------*/ | 73 | /*--------------------------------------------------------------------------*/ |
74 | static int bfin_cf_reset(void) | 74 | static int bfin_cf_reset(void) |
75 | { | 75 | { |
76 | outw(0, CF_ATASEL_ENA); | 76 | outw(0, CF_ATASEL_ENA); |
77 | mdelay(200); | 77 | mdelay(200); |
78 | outw(0, CF_ATASEL_DIS); | 78 | outw(0, CF_ATASEL_DIS); |
79 | 79 | ||
80 | return 0; | 80 | return 0; |
81 | } | 81 | } |
82 | 82 | ||
83 | static int bfin_cf_ss_init(struct pcmcia_socket *s) | 83 | static int bfin_cf_ss_init(struct pcmcia_socket *s) |
84 | { | 84 | { |
85 | return 0; | 85 | return 0; |
86 | } | 86 | } |
87 | 87 | ||
88 | /* the timer is primarily to kick this socket's pccardd */ | 88 | /* the timer is primarily to kick this socket's pccardd */ |
89 | static void bfin_cf_timer(unsigned long _cf) | 89 | static void bfin_cf_timer(unsigned long _cf) |
90 | { | 90 | { |
91 | struct bfin_cf_socket *cf = (void *)_cf; | 91 | struct bfin_cf_socket *cf = (void *)_cf; |
92 | unsigned short present = bfin_cf_present(cf->cd_pfx); | 92 | unsigned short present = bfin_cf_present(cf->cd_pfx); |
93 | 93 | ||
94 | if (present != cf->present) { | 94 | if (present != cf->present) { |
95 | cf->present = present; | 95 | cf->present = present; |
96 | dev_dbg(&cf->pdev->dev, ": card %s\n", | 96 | dev_dbg(&cf->pdev->dev, ": card %s\n", |
97 | present ? "present" : "gone"); | 97 | present ? "present" : "gone"); |
98 | pcmcia_parse_events(&cf->socket, SS_DETECT); | 98 | pcmcia_parse_events(&cf->socket, SS_DETECT); |
99 | } | 99 | } |
100 | 100 | ||
101 | if (cf->active) | 101 | if (cf->active) |
102 | mod_timer(&cf->timer, jiffies + POLL_INTERVAL); | 102 | mod_timer(&cf->timer, jiffies + POLL_INTERVAL); |
103 | } | 103 | } |
104 | 104 | ||
105 | static int bfin_cf_get_status(struct pcmcia_socket *s, u_int *sp) | 105 | static int bfin_cf_get_status(struct pcmcia_socket *s, u_int *sp) |
106 | { | 106 | { |
107 | struct bfin_cf_socket *cf; | 107 | struct bfin_cf_socket *cf; |
108 | 108 | ||
109 | if (!sp) | 109 | if (!sp) |
110 | return -EINVAL; | 110 | return -EINVAL; |
111 | 111 | ||
112 | cf = container_of(s, struct bfin_cf_socket, socket); | 112 | cf = container_of(s, struct bfin_cf_socket, socket); |
113 | 113 | ||
114 | if (bfin_cf_present(cf->cd_pfx)) { | 114 | if (bfin_cf_present(cf->cd_pfx)) { |
115 | *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD; | 115 | *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD; |
116 | s->pcmcia_irq = 0; | 116 | s->pcmcia_irq = 0; |
117 | s->pci_irq = cf->irq; | 117 | s->pci_irq = cf->irq; |
118 | 118 | ||
119 | } else | 119 | } else |
120 | *sp = 0; | 120 | *sp = 0; |
121 | return 0; | 121 | return 0; |
122 | } | 122 | } |
123 | 123 | ||
124 | static int | 124 | static int |
125 | bfin_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s) | 125 | bfin_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s) |
126 | { | 126 | { |
127 | 127 | ||
128 | struct bfin_cf_socket *cf; | 128 | struct bfin_cf_socket *cf; |
129 | cf = container_of(sock, struct bfin_cf_socket, socket); | 129 | cf = container_of(sock, struct bfin_cf_socket, socket); |
130 | 130 | ||
131 | switch (s->Vcc) { | 131 | switch (s->Vcc) { |
132 | case 0: | 132 | case 0: |
133 | case 33: | 133 | case 33: |
134 | break; | 134 | break; |
135 | case 50: | 135 | case 50: |
136 | break; | 136 | break; |
137 | default: | 137 | default: |
138 | return -EINVAL; | 138 | return -EINVAL; |
139 | } | 139 | } |
140 | 140 | ||
141 | if (s->flags & SS_RESET) { | 141 | if (s->flags & SS_RESET) { |
142 | disable_irq(cf->irq); | 142 | disable_irq(cf->irq); |
143 | bfin_cf_reset(); | 143 | bfin_cf_reset(); |
144 | enable_irq(cf->irq); | 144 | enable_irq(cf->irq); |
145 | } | 145 | } |
146 | 146 | ||
147 | dev_dbg(&cf->pdev->dev, ": Vcc %d, io_irq %d, flags %04x csc %04x\n", | 147 | dev_dbg(&cf->pdev->dev, ": Vcc %d, io_irq %d, flags %04x csc %04x\n", |
148 | s->Vcc, s->io_irq, s->flags, s->csc_mask); | 148 | s->Vcc, s->io_irq, s->flags, s->csc_mask); |
149 | 149 | ||
150 | return 0; | 150 | return 0; |
151 | } | 151 | } |
152 | 152 | ||
153 | static int bfin_cf_ss_suspend(struct pcmcia_socket *s) | 153 | static int bfin_cf_ss_suspend(struct pcmcia_socket *s) |
154 | { | 154 | { |
155 | return bfin_cf_set_socket(s, &dead_socket); | 155 | return bfin_cf_set_socket(s, &dead_socket); |
156 | } | 156 | } |
157 | 157 | ||
158 | /* regions are 2K each: mem, attrib, io (and reserved-for-ide) */ | 158 | /* regions are 2K each: mem, attrib, io (and reserved-for-ide) */ |
159 | 159 | ||
160 | static int bfin_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io) | 160 | static int bfin_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io) |
161 | { | 161 | { |
162 | struct bfin_cf_socket *cf; | 162 | struct bfin_cf_socket *cf; |
163 | 163 | ||
164 | cf = container_of(s, struct bfin_cf_socket, socket); | 164 | cf = container_of(s, struct bfin_cf_socket, socket); |
165 | io->flags &= MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT; | 165 | io->flags &= MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT; |
166 | io->start = cf->phys_cf_io; | 166 | io->start = cf->phys_cf_io; |
167 | io->stop = io->start + SZ_2K - 1; | 167 | io->stop = io->start + SZ_2K - 1; |
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
170 | 170 | ||
171 | static int | 171 | static int |
172 | bfin_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map) | 172 | bfin_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map) |
173 | { | 173 | { |
174 | struct bfin_cf_socket *cf; | 174 | struct bfin_cf_socket *cf; |
175 | 175 | ||
176 | if (map->card_start) | 176 | if (map->card_start) |
177 | return -EINVAL; | 177 | return -EINVAL; |
178 | cf = container_of(s, struct bfin_cf_socket, socket); | 178 | cf = container_of(s, struct bfin_cf_socket, socket); |
179 | map->static_start = cf->phys_cf_io; | 179 | map->static_start = cf->phys_cf_io; |
180 | map->flags &= MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT; | 180 | map->flags &= MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT; |
181 | if (map->flags & MAP_ATTRIB) | 181 | if (map->flags & MAP_ATTRIB) |
182 | map->static_start = cf->phys_cf_attr; | 182 | map->static_start = cf->phys_cf_attr; |
183 | 183 | ||
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | 186 | ||
187 | static struct pccard_operations bfin_cf_ops = { | 187 | static struct pccard_operations bfin_cf_ops = { |
188 | .init = bfin_cf_ss_init, | 188 | .init = bfin_cf_ss_init, |
189 | .suspend = bfin_cf_ss_suspend, | 189 | .suspend = bfin_cf_ss_suspend, |
190 | .get_status = bfin_cf_get_status, | 190 | .get_status = bfin_cf_get_status, |
191 | .set_socket = bfin_cf_set_socket, | 191 | .set_socket = bfin_cf_set_socket, |
192 | .set_io_map = bfin_cf_set_io_map, | 192 | .set_io_map = bfin_cf_set_io_map, |
193 | .set_mem_map = bfin_cf_set_mem_map, | 193 | .set_mem_map = bfin_cf_set_mem_map, |
194 | }; | 194 | }; |
195 | 195 | ||
196 | /*--------------------------------------------------------------------------*/ | 196 | /*--------------------------------------------------------------------------*/ |
197 | 197 | ||
198 | static int __devinit bfin_cf_probe(struct platform_device *pdev) | 198 | static int __devinit bfin_cf_probe(struct platform_device *pdev) |
199 | { | 199 | { |
200 | struct bfin_cf_socket *cf; | 200 | struct bfin_cf_socket *cf; |
201 | struct resource *io_mem, *attr_mem; | 201 | struct resource *io_mem, *attr_mem; |
202 | int irq; | 202 | int irq; |
203 | unsigned short cd_pfx; | 203 | unsigned short cd_pfx; |
204 | int status = 0; | 204 | int status = 0; |
205 | 205 | ||
206 | dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n"); | 206 | dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n"); |
207 | 207 | ||
208 | irq = platform_get_irq(pdev, 0); | 208 | irq = platform_get_irq(pdev, 0); |
209 | if (irq <= 0) | 209 | if (irq <= 0) |
210 | return -EINVAL; | 210 | return -EINVAL; |
211 | 211 | ||
212 | cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */ | 212 | cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */ |
213 | 213 | ||
214 | if (gpio_request(cd_pfx, "pcmcia: CD")) { | 214 | if (gpio_request(cd_pfx, "pcmcia: CD")) { |
215 | dev_err(&pdev->dev, | 215 | dev_err(&pdev->dev, |
216 | "Failed ro request Card Detect GPIO_%d\n", | 216 | "Failed ro request Card Detect GPIO_%d\n", |
217 | cd_pfx); | 217 | cd_pfx); |
218 | return -EBUSY; | 218 | return -EBUSY; |
219 | } | 219 | } |
220 | gpio_direction_input(cd_pfx); | 220 | gpio_direction_input(cd_pfx); |
221 | 221 | ||
222 | cf = kzalloc(sizeof *cf, GFP_KERNEL); | 222 | cf = kzalloc(sizeof *cf, GFP_KERNEL); |
223 | if (!cf) { | 223 | if (!cf) { |
224 | gpio_free(cd_pfx); | 224 | gpio_free(cd_pfx); |
225 | return -ENOMEM; | 225 | return -ENOMEM; |
226 | } | 226 | } |
227 | 227 | ||
228 | cf->cd_pfx = cd_pfx; | 228 | cf->cd_pfx = cd_pfx; |
229 | 229 | ||
230 | setup_timer(&cf->timer, bfin_cf_timer, (unsigned long)cf); | 230 | setup_timer(&cf->timer, bfin_cf_timer, (unsigned long)cf); |
231 | 231 | ||
232 | cf->pdev = pdev; | 232 | cf->pdev = pdev; |
233 | platform_set_drvdata(pdev, cf); | 233 | platform_set_drvdata(pdev, cf); |
234 | 234 | ||
235 | cf->irq = irq; | 235 | cf->irq = irq; |
236 | cf->socket.pci_irq = irq; | 236 | cf->socket.pci_irq = irq; |
237 | 237 | ||
238 | irq_set_irq_type(irq, IRQF_TRIGGER_LOW); | 238 | irq_set_irq_type(irq, IRQF_TRIGGER_LOW); |
239 | 239 | ||
240 | io_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 240 | io_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
241 | attr_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); | 241 | attr_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
242 | 242 | ||
243 | if (!io_mem || !attr_mem) | 243 | if (!io_mem || !attr_mem) |
244 | goto fail0; | 244 | goto fail0; |
245 | 245 | ||
246 | cf->phys_cf_io = io_mem->start; | 246 | cf->phys_cf_io = io_mem->start; |
247 | cf->phys_cf_attr = attr_mem->start; | 247 | cf->phys_cf_attr = attr_mem->start; |
248 | 248 | ||
249 | /* pcmcia layer only remaps "real" memory */ | 249 | /* pcmcia layer only remaps "real" memory */ |
250 | cf->socket.io_offset = (unsigned long) | 250 | cf->socket.io_offset = (unsigned long) |
251 | ioremap(cf->phys_cf_io, SZ_2K); | 251 | ioremap(cf->phys_cf_io, SZ_2K); |
252 | 252 | ||
253 | if (!cf->socket.io_offset) | 253 | if (!cf->socket.io_offset) |
254 | goto fail0; | 254 | goto fail0; |
255 | 255 | ||
256 | dev_err(&pdev->dev, ": on irq %d\n", irq); | 256 | dev_err(&pdev->dev, ": on irq %d\n", irq); |
257 | 257 | ||
258 | dev_dbg(&pdev->dev, ": %s\n", | 258 | dev_dbg(&pdev->dev, ": %s\n", |
259 | bfin_cf_present(cf->cd_pfx) ? "present" : "(not present)"); | 259 | bfin_cf_present(cf->cd_pfx) ? "present" : "(not present)"); |
260 | 260 | ||
261 | cf->socket.owner = THIS_MODULE; | 261 | cf->socket.owner = THIS_MODULE; |
262 | cf->socket.dev.parent = &pdev->dev; | 262 | cf->socket.dev.parent = &pdev->dev; |
263 | cf->socket.ops = &bfin_cf_ops; | 263 | cf->socket.ops = &bfin_cf_ops; |
264 | cf->socket.resource_ops = &pccard_static_ops; | 264 | cf->socket.resource_ops = &pccard_static_ops; |
265 | cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP | 265 | cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP |
266 | | SS_CAP_MEM_ALIGN; | 266 | | SS_CAP_MEM_ALIGN; |
267 | cf->socket.map_size = SZ_2K; | 267 | cf->socket.map_size = SZ_2K; |
268 | 268 | ||
269 | status = pcmcia_register_socket(&cf->socket); | 269 | status = pcmcia_register_socket(&cf->socket); |
270 | if (status < 0) | 270 | if (status < 0) |
271 | goto fail2; | 271 | goto fail2; |
272 | 272 | ||
273 | cf->active = 1; | 273 | cf->active = 1; |
274 | mod_timer(&cf->timer, jiffies + POLL_INTERVAL); | 274 | mod_timer(&cf->timer, jiffies + POLL_INTERVAL); |
275 | return 0; | 275 | return 0; |
276 | 276 | ||
277 | fail2: | 277 | fail2: |
278 | iounmap((void __iomem *)cf->socket.io_offset); | 278 | iounmap((void __iomem *)cf->socket.io_offset); |
279 | release_mem_region(cf->phys_cf_io, SZ_8K); | 279 | release_mem_region(cf->phys_cf_io, SZ_8K); |
280 | 280 | ||
281 | fail0: | 281 | fail0: |
282 | gpio_free(cf->cd_pfx); | 282 | gpio_free(cf->cd_pfx); |
283 | kfree(cf); | 283 | kfree(cf); |
284 | platform_set_drvdata(pdev, NULL); | 284 | platform_set_drvdata(pdev, NULL); |
285 | 285 | ||
286 | return status; | 286 | return status; |
287 | } | 287 | } |
288 | 288 | ||
289 | static int __devexit bfin_cf_remove(struct platform_device *pdev) | 289 | static int __devexit bfin_cf_remove(struct platform_device *pdev) |
290 | { | 290 | { |
291 | struct bfin_cf_socket *cf = platform_get_drvdata(pdev); | 291 | struct bfin_cf_socket *cf = platform_get_drvdata(pdev); |
292 | 292 | ||
293 | gpio_free(cf->cd_pfx); | 293 | gpio_free(cf->cd_pfx); |
294 | cf->active = 0; | 294 | cf->active = 0; |
295 | pcmcia_unregister_socket(&cf->socket); | 295 | pcmcia_unregister_socket(&cf->socket); |
296 | del_timer_sync(&cf->timer); | 296 | del_timer_sync(&cf->timer); |
297 | iounmap((void __iomem *)cf->socket.io_offset); | 297 | iounmap((void __iomem *)cf->socket.io_offset); |
298 | release_mem_region(cf->phys_cf_io, SZ_8K); | 298 | release_mem_region(cf->phys_cf_io, SZ_8K); |
299 | platform_set_drvdata(pdev, NULL); | 299 | platform_set_drvdata(pdev, NULL); |
300 | kfree(cf); | 300 | kfree(cf); |
301 | return 0; | 301 | return 0; |
302 | } | 302 | } |
303 | 303 | ||
304 | static struct platform_driver bfin_cf_driver = { | 304 | static struct platform_driver bfin_cf_driver = { |
305 | .driver = { | 305 | .driver = { |
306 | .name = (char *)driver_name, | 306 | .name = (char *)driver_name, |
307 | .owner = THIS_MODULE, | 307 | .owner = THIS_MODULE, |
308 | }, | 308 | }, |
309 | .probe = bfin_cf_probe, | 309 | .probe = bfin_cf_probe, |
310 | .remove = __devexit_p(bfin_cf_remove), | 310 | .remove = __devexit_p(bfin_cf_remove), |
311 | }; | 311 | }; |
312 | 312 | ||
313 | static int __init bfin_cf_init(void) | 313 | module_platform_driver(bfin_cf_driver); |
314 | { | ||
315 | return platform_driver_register(&bfin_cf_driver); | ||
316 | } | ||
317 | |||
318 | static void __exit bfin_cf_exit(void) | ||
319 | { | ||
320 | platform_driver_unregister(&bfin_cf_driver); | ||
321 | } | ||
322 | |||
323 | module_init(bfin_cf_init); | ||
324 | module_exit(bfin_cf_exit); | ||
325 | 314 | ||
326 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 315 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
327 | MODULE_DESCRIPTION("BFIN CF/PCMCIA Driver"); | 316 | MODULE_DESCRIPTION("BFIN CF/PCMCIA Driver"); |
328 | MODULE_LICENSE("GPL"); | 317 | MODULE_LICENSE("GPL"); |
329 | 318 |
drivers/pcmcia/db1xxx_ss.c
1 | /* | 1 | /* |
2 | * PCMCIA socket code for the Alchemy Db1xxx/Pb1xxx boards. | 2 | * PCMCIA socket code for the Alchemy Db1xxx/Pb1xxx boards. |
3 | * | 3 | * |
4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> | 4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> |
5 | * | 5 | * |
6 | */ | 6 | */ |
7 | 7 | ||
8 | /* This is a fairly generic PCMCIA socket driver suitable for the | 8 | /* This is a fairly generic PCMCIA socket driver suitable for the |
9 | * following Alchemy Development boards: | 9 | * following Alchemy Development boards: |
10 | * Db1000, Db/Pb1500, Db/Pb1100, Db/Pb1550, Db/Pb1200, Db1300 | 10 | * Db1000, Db/Pb1500, Db/Pb1100, Db/Pb1550, Db/Pb1200, Db1300 |
11 | * | 11 | * |
12 | * The Db1000 is used as a reference: Per-socket card-, carddetect- and | 12 | * The Db1000 is used as a reference: Per-socket card-, carddetect- and |
13 | * statuschange IRQs connected to SoC GPIOs, control and status register | 13 | * statuschange IRQs connected to SoC GPIOs, control and status register |
14 | * bits arranged in per-socket groups in an external PLD. All boards | 14 | * bits arranged in per-socket groups in an external PLD. All boards |
15 | * listed here use this layout, including bit positions and meanings. | 15 | * listed here use this layout, including bit positions and meanings. |
16 | * Of course there are exceptions in later boards: | 16 | * Of course there are exceptions in later boards: |
17 | * | 17 | * |
18 | * - Pb1100/Pb1500: single socket only; voltage key bits VS are | 18 | * - Pb1100/Pb1500: single socket only; voltage key bits VS are |
19 | * at STATUS[5:4] (instead of STATUS[1:0]). | 19 | * at STATUS[5:4] (instead of STATUS[1:0]). |
20 | * - Au1200-based: additional card-eject irqs, irqs not gpios! | 20 | * - Au1200-based: additional card-eject irqs, irqs not gpios! |
21 | * - Db1300: Db1200-like, no pwr ctrl, single socket (#1). | 21 | * - Db1300: Db1200-like, no pwr ctrl, single socket (#1). |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
27 | #include <linux/pm.h> | 27 | #include <linux/pm.h> |
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/platform_device.h> | 29 | #include <linux/platform_device.h> |
30 | #include <linux/resource.h> | 30 | #include <linux/resource.h> |
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/spinlock.h> | 32 | #include <linux/spinlock.h> |
33 | 33 | ||
34 | #include <pcmcia/ss.h> | 34 | #include <pcmcia/ss.h> |
35 | 35 | ||
36 | #include <asm/mach-au1x00/au1000.h> | 36 | #include <asm/mach-au1x00/au1000.h> |
37 | #include <asm/mach-db1x00/bcsr.h> | 37 | #include <asm/mach-db1x00/bcsr.h> |
38 | 38 | ||
39 | #define MEM_MAP_SIZE 0x400000 | 39 | #define MEM_MAP_SIZE 0x400000 |
40 | #define IO_MAP_SIZE 0x1000 | 40 | #define IO_MAP_SIZE 0x1000 |
41 | 41 | ||
42 | struct db1x_pcmcia_sock { | 42 | struct db1x_pcmcia_sock { |
43 | struct pcmcia_socket socket; | 43 | struct pcmcia_socket socket; |
44 | int nr; /* socket number */ | 44 | int nr; /* socket number */ |
45 | void *virt_io; | 45 | void *virt_io; |
46 | 46 | ||
47 | phys_addr_t phys_io; | 47 | phys_addr_t phys_io; |
48 | phys_addr_t phys_attr; | 48 | phys_addr_t phys_attr; |
49 | phys_addr_t phys_mem; | 49 | phys_addr_t phys_mem; |
50 | 50 | ||
51 | /* previous flags for set_socket() */ | 51 | /* previous flags for set_socket() */ |
52 | unsigned int old_flags; | 52 | unsigned int old_flags; |
53 | 53 | ||
54 | /* interrupt sources: linux irq numbers! */ | 54 | /* interrupt sources: linux irq numbers! */ |
55 | int insert_irq; /* default carddetect irq */ | 55 | int insert_irq; /* default carddetect irq */ |
56 | int stschg_irq; /* card-status-change irq */ | 56 | int stschg_irq; /* card-status-change irq */ |
57 | int card_irq; /* card irq */ | 57 | int card_irq; /* card irq */ |
58 | int eject_irq; /* db1200/pb1200 have these */ | 58 | int eject_irq; /* db1200/pb1200 have these */ |
59 | 59 | ||
60 | #define BOARD_TYPE_DEFAULT 0 /* most boards */ | 60 | #define BOARD_TYPE_DEFAULT 0 /* most boards */ |
61 | #define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */ | 61 | #define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */ |
62 | #define BOARD_TYPE_PB1100 2 /* VS bits slightly different */ | 62 | #define BOARD_TYPE_PB1100 2 /* VS bits slightly different */ |
63 | #define BOARD_TYPE_DB1300 3 /* no power control */ | 63 | #define BOARD_TYPE_DB1300 3 /* no power control */ |
64 | int board_type; | 64 | int board_type; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | #define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket) | 67 | #define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket) |
68 | 68 | ||
69 | static int db1300_card_inserted(struct db1x_pcmcia_sock *sock) | 69 | static int db1300_card_inserted(struct db1x_pcmcia_sock *sock) |
70 | { | 70 | { |
71 | return bcsr_read(BCSR_SIGSTAT) & (1 << 8); | 71 | return bcsr_read(BCSR_SIGSTAT) & (1 << 8); |
72 | } | 72 | } |
73 | 73 | ||
74 | /* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */ | 74 | /* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */ |
75 | static int db1200_card_inserted(struct db1x_pcmcia_sock *sock) | 75 | static int db1200_card_inserted(struct db1x_pcmcia_sock *sock) |
76 | { | 76 | { |
77 | unsigned short sigstat; | 77 | unsigned short sigstat; |
78 | 78 | ||
79 | sigstat = bcsr_read(BCSR_SIGSTAT); | 79 | sigstat = bcsr_read(BCSR_SIGSTAT); |
80 | return sigstat & 1 << (8 + 2 * sock->nr); | 80 | return sigstat & 1 << (8 + 2 * sock->nr); |
81 | } | 81 | } |
82 | 82 | ||
83 | /* carddetect gpio: low-active */ | 83 | /* carddetect gpio: low-active */ |
84 | static int db1000_card_inserted(struct db1x_pcmcia_sock *sock) | 84 | static int db1000_card_inserted(struct db1x_pcmcia_sock *sock) |
85 | { | 85 | { |
86 | return !gpio_get_value(irq_to_gpio(sock->insert_irq)); | 86 | return !gpio_get_value(irq_to_gpio(sock->insert_irq)); |
87 | } | 87 | } |
88 | 88 | ||
89 | static int db1x_card_inserted(struct db1x_pcmcia_sock *sock) | 89 | static int db1x_card_inserted(struct db1x_pcmcia_sock *sock) |
90 | { | 90 | { |
91 | switch (sock->board_type) { | 91 | switch (sock->board_type) { |
92 | case BOARD_TYPE_DB1200: | 92 | case BOARD_TYPE_DB1200: |
93 | return db1200_card_inserted(sock); | 93 | return db1200_card_inserted(sock); |
94 | case BOARD_TYPE_DB1300: | 94 | case BOARD_TYPE_DB1300: |
95 | return db1300_card_inserted(sock); | 95 | return db1300_card_inserted(sock); |
96 | default: | 96 | default: |
97 | return db1000_card_inserted(sock); | 97 | return db1000_card_inserted(sock); |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | /* STSCHG tends to bounce heavily when cards are inserted/ejected. | 101 | /* STSCHG tends to bounce heavily when cards are inserted/ejected. |
102 | * To avoid this, the interrupt is normally disabled and only enabled | 102 | * To avoid this, the interrupt is normally disabled and only enabled |
103 | * after reset to a card has been de-asserted. | 103 | * after reset to a card has been de-asserted. |
104 | */ | 104 | */ |
105 | static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en) | 105 | static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en) |
106 | { | 106 | { |
107 | if (sock->stschg_irq != -1) { | 107 | if (sock->stschg_irq != -1) { |
108 | if (en) | 108 | if (en) |
109 | enable_irq(sock->stschg_irq); | 109 | enable_irq(sock->stschg_irq); |
110 | else | 110 | else |
111 | disable_irq(sock->stschg_irq); | 111 | disable_irq(sock->stschg_irq); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data) | 115 | static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data) |
116 | { | 116 | { |
117 | struct db1x_pcmcia_sock *sock = data; | 117 | struct db1x_pcmcia_sock *sock = data; |
118 | 118 | ||
119 | pcmcia_parse_events(&sock->socket, SS_DETECT); | 119 | pcmcia_parse_events(&sock->socket, SS_DETECT); |
120 | 120 | ||
121 | return IRQ_HANDLED; | 121 | return IRQ_HANDLED; |
122 | } | 122 | } |
123 | 123 | ||
124 | static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data) | 124 | static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data) |
125 | { | 125 | { |
126 | struct db1x_pcmcia_sock *sock = data; | 126 | struct db1x_pcmcia_sock *sock = data; |
127 | 127 | ||
128 | pcmcia_parse_events(&sock->socket, SS_STSCHG); | 128 | pcmcia_parse_events(&sock->socket, SS_STSCHG); |
129 | 129 | ||
130 | return IRQ_HANDLED; | 130 | return IRQ_HANDLED; |
131 | } | 131 | } |
132 | 132 | ||
133 | static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data) | 133 | static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data) |
134 | { | 134 | { |
135 | struct db1x_pcmcia_sock *sock = data; | 135 | struct db1x_pcmcia_sock *sock = data; |
136 | 136 | ||
137 | /* Db/Pb1200 have separate per-socket insertion and ejection | 137 | /* Db/Pb1200 have separate per-socket insertion and ejection |
138 | * interrupts which stay asserted as long as the card is | 138 | * interrupts which stay asserted as long as the card is |
139 | * inserted/missing. The one which caused us to be called | 139 | * inserted/missing. The one which caused us to be called |
140 | * needs to be disabled and the other one enabled. | 140 | * needs to be disabled and the other one enabled. |
141 | */ | 141 | */ |
142 | if (irq == sock->insert_irq) { | 142 | if (irq == sock->insert_irq) { |
143 | disable_irq_nosync(sock->insert_irq); | 143 | disable_irq_nosync(sock->insert_irq); |
144 | enable_irq(sock->eject_irq); | 144 | enable_irq(sock->eject_irq); |
145 | } else { | 145 | } else { |
146 | disable_irq_nosync(sock->eject_irq); | 146 | disable_irq_nosync(sock->eject_irq); |
147 | enable_irq(sock->insert_irq); | 147 | enable_irq(sock->insert_irq); |
148 | } | 148 | } |
149 | 149 | ||
150 | pcmcia_parse_events(&sock->socket, SS_DETECT); | 150 | pcmcia_parse_events(&sock->socket, SS_DETECT); |
151 | 151 | ||
152 | return IRQ_HANDLED; | 152 | return IRQ_HANDLED; |
153 | } | 153 | } |
154 | 154 | ||
155 | static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock) | 155 | static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock) |
156 | { | 156 | { |
157 | int ret; | 157 | int ret; |
158 | 158 | ||
159 | if (sock->stschg_irq != -1) { | 159 | if (sock->stschg_irq != -1) { |
160 | ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq, | 160 | ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq, |
161 | 0, "pcmcia_stschg", sock); | 161 | 0, "pcmcia_stschg", sock); |
162 | if (ret) | 162 | if (ret) |
163 | return ret; | 163 | return ret; |
164 | } | 164 | } |
165 | 165 | ||
166 | /* Db/Pb1200 have separate per-socket insertion and ejection | 166 | /* Db/Pb1200 have separate per-socket insertion and ejection |
167 | * interrupts, which should show edge behaviour but don't. | 167 | * interrupts, which should show edge behaviour but don't. |
168 | * So interrupts are disabled until both insertion and | 168 | * So interrupts are disabled until both insertion and |
169 | * ejection handler have been registered and the currently | 169 | * ejection handler have been registered and the currently |
170 | * active one disabled. | 170 | * active one disabled. |
171 | */ | 171 | */ |
172 | if ((sock->board_type == BOARD_TYPE_DB1200) || | 172 | if ((sock->board_type == BOARD_TYPE_DB1200) || |
173 | (sock->board_type == BOARD_TYPE_DB1300)) { | 173 | (sock->board_type == BOARD_TYPE_DB1300)) { |
174 | ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq, | 174 | ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq, |
175 | 0, "pcmcia_insert", sock); | 175 | 0, "pcmcia_insert", sock); |
176 | if (ret) | 176 | if (ret) |
177 | goto out1; | 177 | goto out1; |
178 | 178 | ||
179 | ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq, | 179 | ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq, |
180 | 0, "pcmcia_eject", sock); | 180 | 0, "pcmcia_eject", sock); |
181 | if (ret) { | 181 | if (ret) { |
182 | free_irq(sock->insert_irq, sock); | 182 | free_irq(sock->insert_irq, sock); |
183 | goto out1; | 183 | goto out1; |
184 | } | 184 | } |
185 | 185 | ||
186 | /* enable the currently silent one */ | 186 | /* enable the currently silent one */ |
187 | if (db1x_card_inserted(sock)) | 187 | if (db1x_card_inserted(sock)) |
188 | enable_irq(sock->eject_irq); | 188 | enable_irq(sock->eject_irq); |
189 | else | 189 | else |
190 | enable_irq(sock->insert_irq); | 190 | enable_irq(sock->insert_irq); |
191 | } else { | 191 | } else { |
192 | /* all other (older) Db1x00 boards use a GPIO to show | 192 | /* all other (older) Db1x00 boards use a GPIO to show |
193 | * card detection status: use both-edge triggers. | 193 | * card detection status: use both-edge triggers. |
194 | */ | 194 | */ |
195 | irq_set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH); | 195 | irq_set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH); |
196 | ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq, | 196 | ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq, |
197 | 0, "pcmcia_carddetect", sock); | 197 | 0, "pcmcia_carddetect", sock); |
198 | 198 | ||
199 | if (ret) | 199 | if (ret) |
200 | goto out1; | 200 | goto out1; |
201 | } | 201 | } |
202 | 202 | ||
203 | return 0; /* all done */ | 203 | return 0; /* all done */ |
204 | 204 | ||
205 | out1: | 205 | out1: |
206 | if (sock->stschg_irq != -1) | 206 | if (sock->stschg_irq != -1) |
207 | free_irq(sock->stschg_irq, sock); | 207 | free_irq(sock->stschg_irq, sock); |
208 | 208 | ||
209 | return ret; | 209 | return ret; |
210 | } | 210 | } |
211 | 211 | ||
212 | static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock) | 212 | static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock) |
213 | { | 213 | { |
214 | if (sock->stschg_irq != -1) | 214 | if (sock->stschg_irq != -1) |
215 | free_irq(sock->stschg_irq, sock); | 215 | free_irq(sock->stschg_irq, sock); |
216 | 216 | ||
217 | free_irq(sock->insert_irq, sock); | 217 | free_irq(sock->insert_irq, sock); |
218 | if (sock->eject_irq != -1) | 218 | if (sock->eject_irq != -1) |
219 | free_irq(sock->eject_irq, sock); | 219 | free_irq(sock->eject_irq, sock); |
220 | } | 220 | } |
221 | 221 | ||
222 | /* | 222 | /* |
223 | * configure a PCMCIA socket on the Db1x00 series of boards (and | 223 | * configure a PCMCIA socket on the Db1x00 series of boards (and |
224 | * compatibles). | 224 | * compatibles). |
225 | * | 225 | * |
226 | * 2 external registers are involved: | 226 | * 2 external registers are involved: |
227 | * pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id | 227 | * pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id |
228 | * pcmcia_control(offset 0x10): | 228 | * pcmcia_control(offset 0x10): |
229 | * bits[0:1] set vcc for card | 229 | * bits[0:1] set vcc for card |
230 | * bits[2:3] set vpp for card | 230 | * bits[2:3] set vpp for card |
231 | * bit 4: enable data buffers | 231 | * bit 4: enable data buffers |
232 | * bit 7: reset# for card | 232 | * bit 7: reset# for card |
233 | * add 8 for second socket. | 233 | * add 8 for second socket. |
234 | */ | 234 | */ |
235 | static int db1x_pcmcia_configure(struct pcmcia_socket *skt, | 235 | static int db1x_pcmcia_configure(struct pcmcia_socket *skt, |
236 | struct socket_state_t *state) | 236 | struct socket_state_t *state) |
237 | { | 237 | { |
238 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | 238 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); |
239 | unsigned short cr_clr, cr_set; | 239 | unsigned short cr_clr, cr_set; |
240 | unsigned int changed; | 240 | unsigned int changed; |
241 | int v, p, ret; | 241 | int v, p, ret; |
242 | 242 | ||
243 | /* card voltage setup */ | 243 | /* card voltage setup */ |
244 | cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */ | 244 | cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */ |
245 | cr_set = 0; | 245 | cr_set = 0; |
246 | v = p = ret = 0; | 246 | v = p = ret = 0; |
247 | 247 | ||
248 | switch (state->Vcc) { | 248 | switch (state->Vcc) { |
249 | case 50: | 249 | case 50: |
250 | ++v; | 250 | ++v; |
251 | case 33: | 251 | case 33: |
252 | ++v; | 252 | ++v; |
253 | case 0: | 253 | case 0: |
254 | break; | 254 | break; |
255 | default: | 255 | default: |
256 | printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n", | 256 | printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n", |
257 | sock->nr, state->Vcc); | 257 | sock->nr, state->Vcc); |
258 | } | 258 | } |
259 | 259 | ||
260 | switch (state->Vpp) { | 260 | switch (state->Vpp) { |
261 | case 12: | 261 | case 12: |
262 | ++p; | 262 | ++p; |
263 | case 33: | 263 | case 33: |
264 | case 50: | 264 | case 50: |
265 | ++p; | 265 | ++p; |
266 | case 0: | 266 | case 0: |
267 | break; | 267 | break; |
268 | default: | 268 | default: |
269 | printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n", | 269 | printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n", |
270 | sock->nr, state->Vpp); | 270 | sock->nr, state->Vpp); |
271 | } | 271 | } |
272 | 272 | ||
273 | /* sanity check: Vpp must be 0, 12, or Vcc */ | 273 | /* sanity check: Vpp must be 0, 12, or Vcc */ |
274 | if (((state->Vcc == 33) && (state->Vpp == 50)) || | 274 | if (((state->Vcc == 33) && (state->Vpp == 50)) || |
275 | ((state->Vcc == 50) && (state->Vpp == 33))) { | 275 | ((state->Vcc == 50) && (state->Vpp == 33))) { |
276 | printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n", | 276 | printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n", |
277 | sock->nr, state->Vcc, state->Vpp); | 277 | sock->nr, state->Vcc, state->Vpp); |
278 | v = p = 0; | 278 | v = p = 0; |
279 | ret = -EINVAL; | 279 | ret = -EINVAL; |
280 | } | 280 | } |
281 | 281 | ||
282 | /* create new voltage code */ | 282 | /* create new voltage code */ |
283 | if (sock->board_type != BOARD_TYPE_DB1300) | 283 | if (sock->board_type != BOARD_TYPE_DB1300) |
284 | cr_set |= ((v << 2) | p) << (sock->nr * 8); | 284 | cr_set |= ((v << 2) | p) << (sock->nr * 8); |
285 | 285 | ||
286 | changed = state->flags ^ sock->old_flags; | 286 | changed = state->flags ^ sock->old_flags; |
287 | 287 | ||
288 | if (changed & SS_RESET) { | 288 | if (changed & SS_RESET) { |
289 | if (state->flags & SS_RESET) { | 289 | if (state->flags & SS_RESET) { |
290 | set_stschg(sock, 0); | 290 | set_stschg(sock, 0); |
291 | /* assert reset, disable io buffers */ | 291 | /* assert reset, disable io buffers */ |
292 | cr_clr |= (1 << (7 + (sock->nr * 8))); | 292 | cr_clr |= (1 << (7 + (sock->nr * 8))); |
293 | cr_clr |= (1 << (4 + (sock->nr * 8))); | 293 | cr_clr |= (1 << (4 + (sock->nr * 8))); |
294 | } else { | 294 | } else { |
295 | /* de-assert reset, enable io buffers */ | 295 | /* de-assert reset, enable io buffers */ |
296 | cr_set |= 1 << (7 + (sock->nr * 8)); | 296 | cr_set |= 1 << (7 + (sock->nr * 8)); |
297 | cr_set |= 1 << (4 + (sock->nr * 8)); | 297 | cr_set |= 1 << (4 + (sock->nr * 8)); |
298 | } | 298 | } |
299 | } | 299 | } |
300 | 300 | ||
301 | /* update PCMCIA configuration */ | 301 | /* update PCMCIA configuration */ |
302 | bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set); | 302 | bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set); |
303 | 303 | ||
304 | sock->old_flags = state->flags; | 304 | sock->old_flags = state->flags; |
305 | 305 | ||
306 | /* reset was taken away: give card time to initialize properly */ | 306 | /* reset was taken away: give card time to initialize properly */ |
307 | if ((changed & SS_RESET) && !(state->flags & SS_RESET)) { | 307 | if ((changed & SS_RESET) && !(state->flags & SS_RESET)) { |
308 | msleep(500); | 308 | msleep(500); |
309 | set_stschg(sock, 1); | 309 | set_stschg(sock, 1); |
310 | } | 310 | } |
311 | 311 | ||
312 | return ret; | 312 | return ret; |
313 | } | 313 | } |
314 | 314 | ||
315 | /* VCC bits at [3:2]/[11:10] */ | 315 | /* VCC bits at [3:2]/[11:10] */ |
316 | #define GET_VCC(cr, socknr) \ | 316 | #define GET_VCC(cr, socknr) \ |
317 | ((((cr) >> 2) >> ((socknr) * 8)) & 3) | 317 | ((((cr) >> 2) >> ((socknr) * 8)) & 3) |
318 | 318 | ||
319 | /* VS bits at [0:1]/[3:2] */ | 319 | /* VS bits at [0:1]/[3:2] */ |
320 | #define GET_VS(sr, socknr) \ | 320 | #define GET_VS(sr, socknr) \ |
321 | (((sr) >> (2 * (socknr))) & 3) | 321 | (((sr) >> (2 * (socknr))) & 3) |
322 | 322 | ||
323 | /* reset bits at [7]/[15] */ | 323 | /* reset bits at [7]/[15] */ |
324 | #define GET_RESET(cr, socknr) \ | 324 | #define GET_RESET(cr, socknr) \ |
325 | ((cr) & (1 << (7 + (8 * (socknr))))) | 325 | ((cr) & (1 << (7 + (8 * (socknr))))) |
326 | 326 | ||
327 | static int db1x_pcmcia_get_status(struct pcmcia_socket *skt, | 327 | static int db1x_pcmcia_get_status(struct pcmcia_socket *skt, |
328 | unsigned int *value) | 328 | unsigned int *value) |
329 | { | 329 | { |
330 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | 330 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); |
331 | unsigned short cr, sr; | 331 | unsigned short cr, sr; |
332 | unsigned int status; | 332 | unsigned int status; |
333 | 333 | ||
334 | status = db1x_card_inserted(sock) ? SS_DETECT : 0; | 334 | status = db1x_card_inserted(sock) ? SS_DETECT : 0; |
335 | 335 | ||
336 | cr = bcsr_read(BCSR_PCMCIA); | 336 | cr = bcsr_read(BCSR_PCMCIA); |
337 | sr = bcsr_read(BCSR_STATUS); | 337 | sr = bcsr_read(BCSR_STATUS); |
338 | 338 | ||
339 | /* PB1100/PB1500: voltage key bits are at [5:4] */ | 339 | /* PB1100/PB1500: voltage key bits are at [5:4] */ |
340 | if (sock->board_type == BOARD_TYPE_PB1100) | 340 | if (sock->board_type == BOARD_TYPE_PB1100) |
341 | sr >>= 4; | 341 | sr >>= 4; |
342 | 342 | ||
343 | /* determine card type */ | 343 | /* determine card type */ |
344 | switch (GET_VS(sr, sock->nr)) { | 344 | switch (GET_VS(sr, sock->nr)) { |
345 | case 0: | 345 | case 0: |
346 | case 2: | 346 | case 2: |
347 | status |= SS_3VCARD; /* 3V card */ | 347 | status |= SS_3VCARD; /* 3V card */ |
348 | case 3: | 348 | case 3: |
349 | break; /* 5V card: set nothing */ | 349 | break; /* 5V card: set nothing */ |
350 | default: | 350 | default: |
351 | status |= SS_XVCARD; /* treated as unsupported in core */ | 351 | status |= SS_XVCARD; /* treated as unsupported in core */ |
352 | } | 352 | } |
353 | 353 | ||
354 | /* if Vcc is not zero, we have applied power to a card */ | 354 | /* if Vcc is not zero, we have applied power to a card */ |
355 | status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0; | 355 | status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0; |
356 | 356 | ||
357 | /* DB1300: power always on, but don't tell when no card present */ | 357 | /* DB1300: power always on, but don't tell when no card present */ |
358 | if ((sock->board_type == BOARD_TYPE_DB1300) && (status & SS_DETECT)) | 358 | if ((sock->board_type == BOARD_TYPE_DB1300) && (status & SS_DETECT)) |
359 | status = SS_POWERON | SS_3VCARD | SS_DETECT; | 359 | status = SS_POWERON | SS_3VCARD | SS_DETECT; |
360 | 360 | ||
361 | /* reset de-asserted? then we're ready */ | 361 | /* reset de-asserted? then we're ready */ |
362 | status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET; | 362 | status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET; |
363 | 363 | ||
364 | *value = status; | 364 | *value = status; |
365 | 365 | ||
366 | return 0; | 366 | return 0; |
367 | } | 367 | } |
368 | 368 | ||
369 | static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt) | 369 | static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt) |
370 | { | 370 | { |
371 | return 0; | 371 | return 0; |
372 | } | 372 | } |
373 | 373 | ||
374 | static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt) | 374 | static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt) |
375 | { | 375 | { |
376 | return 0; | 376 | return 0; |
377 | } | 377 | } |
378 | 378 | ||
379 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, | 379 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, |
380 | struct pccard_io_map *map) | 380 | struct pccard_io_map *map) |
381 | { | 381 | { |
382 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | 382 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); |
383 | 383 | ||
384 | map->start = (u32)sock->virt_io; | 384 | map->start = (u32)sock->virt_io; |
385 | map->stop = map->start + IO_MAP_SIZE; | 385 | map->stop = map->start + IO_MAP_SIZE; |
386 | 386 | ||
387 | return 0; | 387 | return 0; |
388 | } | 388 | } |
389 | 389 | ||
390 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, | 390 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, |
391 | struct pccard_mem_map *map) | 391 | struct pccard_mem_map *map) |
392 | { | 392 | { |
393 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); | 393 | struct db1x_pcmcia_sock *sock = to_db1x_socket(skt); |
394 | 394 | ||
395 | if (map->flags & MAP_ATTRIB) | 395 | if (map->flags & MAP_ATTRIB) |
396 | map->static_start = sock->phys_attr + map->card_start; | 396 | map->static_start = sock->phys_attr + map->card_start; |
397 | else | 397 | else |
398 | map->static_start = sock->phys_mem + map->card_start; | 398 | map->static_start = sock->phys_mem + map->card_start; |
399 | 399 | ||
400 | return 0; | 400 | return 0; |
401 | } | 401 | } |
402 | 402 | ||
403 | static struct pccard_operations db1x_pcmcia_operations = { | 403 | static struct pccard_operations db1x_pcmcia_operations = { |
404 | .init = db1x_pcmcia_sock_init, | 404 | .init = db1x_pcmcia_sock_init, |
405 | .suspend = db1x_pcmcia_sock_suspend, | 405 | .suspend = db1x_pcmcia_sock_suspend, |
406 | .get_status = db1x_pcmcia_get_status, | 406 | .get_status = db1x_pcmcia_get_status, |
407 | .set_socket = db1x_pcmcia_configure, | 407 | .set_socket = db1x_pcmcia_configure, |
408 | .set_io_map = au1x00_pcmcia_set_io_map, | 408 | .set_io_map = au1x00_pcmcia_set_io_map, |
409 | .set_mem_map = au1x00_pcmcia_set_mem_map, | 409 | .set_mem_map = au1x00_pcmcia_set_mem_map, |
410 | }; | 410 | }; |
411 | 411 | ||
412 | static int __devinit db1x_pcmcia_socket_probe(struct platform_device *pdev) | 412 | static int __devinit db1x_pcmcia_socket_probe(struct platform_device *pdev) |
413 | { | 413 | { |
414 | struct db1x_pcmcia_sock *sock; | 414 | struct db1x_pcmcia_sock *sock; |
415 | struct resource *r; | 415 | struct resource *r; |
416 | int ret, bid; | 416 | int ret, bid; |
417 | 417 | ||
418 | sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL); | 418 | sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL); |
419 | if (!sock) | 419 | if (!sock) |
420 | return -ENOMEM; | 420 | return -ENOMEM; |
421 | 421 | ||
422 | sock->nr = pdev->id; | 422 | sock->nr = pdev->id; |
423 | 423 | ||
424 | bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); | 424 | bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); |
425 | switch (bid) { | 425 | switch (bid) { |
426 | case BCSR_WHOAMI_PB1500: | 426 | case BCSR_WHOAMI_PB1500: |
427 | case BCSR_WHOAMI_PB1500R2: | 427 | case BCSR_WHOAMI_PB1500R2: |
428 | case BCSR_WHOAMI_PB1100: | 428 | case BCSR_WHOAMI_PB1100: |
429 | sock->board_type = BOARD_TYPE_PB1100; | 429 | sock->board_type = BOARD_TYPE_PB1100; |
430 | break; | 430 | break; |
431 | case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR: | 431 | case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR: |
432 | sock->board_type = BOARD_TYPE_DEFAULT; | 432 | sock->board_type = BOARD_TYPE_DEFAULT; |
433 | break; | 433 | break; |
434 | case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200: | 434 | case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200: |
435 | sock->board_type = BOARD_TYPE_DB1200; | 435 | sock->board_type = BOARD_TYPE_DB1200; |
436 | break; | 436 | break; |
437 | case BCSR_WHOAMI_DB1300: | 437 | case BCSR_WHOAMI_DB1300: |
438 | sock->board_type = BOARD_TYPE_DB1300; | 438 | sock->board_type = BOARD_TYPE_DB1300; |
439 | break; | 439 | break; |
440 | default: | 440 | default: |
441 | printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid); | 441 | printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid); |
442 | ret = -ENODEV; | 442 | ret = -ENODEV; |
443 | goto out0; | 443 | goto out0; |
444 | }; | 444 | }; |
445 | 445 | ||
446 | /* | 446 | /* |
447 | * gather resources necessary and optional nice-to-haves to | 447 | * gather resources necessary and optional nice-to-haves to |
448 | * operate a socket: | 448 | * operate a socket: |
449 | * This includes IRQs for Carddetection/ejection, the card | 449 | * This includes IRQs for Carddetection/ejection, the card |
450 | * itself and optional status change detection. | 450 | * itself and optional status change detection. |
451 | * Also, the memory areas covered by a socket. For these | 451 | * Also, the memory areas covered by a socket. For these |
452 | * we require the real 36bit addresses (see the au1000.h | 452 | * we require the real 36bit addresses (see the au1000.h |
453 | * header for more information). | 453 | * header for more information). |
454 | */ | 454 | */ |
455 | 455 | ||
456 | /* card: irq assigned to the card itself. */ | 456 | /* card: irq assigned to the card itself. */ |
457 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card"); | 457 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card"); |
458 | sock->card_irq = r ? r->start : 0; | 458 | sock->card_irq = r ? r->start : 0; |
459 | 459 | ||
460 | /* insert: irq which triggers on card insertion/ejection */ | 460 | /* insert: irq which triggers on card insertion/ejection */ |
461 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert"); | 461 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert"); |
462 | sock->insert_irq = r ? r->start : -1; | 462 | sock->insert_irq = r ? r->start : -1; |
463 | 463 | ||
464 | /* stschg: irq which trigger on card status change (optional) */ | 464 | /* stschg: irq which trigger on card status change (optional) */ |
465 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg"); | 465 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg"); |
466 | sock->stschg_irq = r ? r->start : -1; | 466 | sock->stschg_irq = r ? r->start : -1; |
467 | 467 | ||
468 | /* eject: irq which triggers on ejection (DB1200/PB1200 only) */ | 468 | /* eject: irq which triggers on ejection (DB1200/PB1200 only) */ |
469 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject"); | 469 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject"); |
470 | sock->eject_irq = r ? r->start : -1; | 470 | sock->eject_irq = r ? r->start : -1; |
471 | 471 | ||
472 | ret = -ENODEV; | 472 | ret = -ENODEV; |
473 | 473 | ||
474 | /* 36bit PCMCIA Attribute area address */ | 474 | /* 36bit PCMCIA Attribute area address */ |
475 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); | 475 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); |
476 | if (!r) { | 476 | if (!r) { |
477 | printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n", | 477 | printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n", |
478 | sock->nr); | 478 | sock->nr); |
479 | goto out0; | 479 | goto out0; |
480 | } | 480 | } |
481 | sock->phys_attr = r->start; | 481 | sock->phys_attr = r->start; |
482 | 482 | ||
483 | /* 36bit PCMCIA Memory area address */ | 483 | /* 36bit PCMCIA Memory area address */ |
484 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); | 484 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); |
485 | if (!r) { | 485 | if (!r) { |
486 | printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n", | 486 | printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n", |
487 | sock->nr); | 487 | sock->nr); |
488 | goto out0; | 488 | goto out0; |
489 | } | 489 | } |
490 | sock->phys_mem = r->start; | 490 | sock->phys_mem = r->start; |
491 | 491 | ||
492 | /* 36bit PCMCIA IO area address */ | 492 | /* 36bit PCMCIA IO area address */ |
493 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); | 493 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); |
494 | if (!r) { | 494 | if (!r) { |
495 | printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n", | 495 | printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n", |
496 | sock->nr); | 496 | sock->nr); |
497 | goto out0; | 497 | goto out0; |
498 | } | 498 | } |
499 | sock->phys_io = r->start; | 499 | sock->phys_io = r->start; |
500 | 500 | ||
501 | /* | 501 | /* |
502 | * PCMCIA client drivers use the inb/outb macros to access | 502 | * PCMCIA client drivers use the inb/outb macros to access |
503 | * the IO registers. Since mips_io_port_base is added | 503 | * the IO registers. Since mips_io_port_base is added |
504 | * to the access address of the mips implementation of | 504 | * to the access address of the mips implementation of |
505 | * inb/outb, we need to subtract it here because we want | 505 | * inb/outb, we need to subtract it here because we want |
506 | * to access the I/O or MEM address directly, without | 506 | * to access the I/O or MEM address directly, without |
507 | * going through this "mips_io_port_base" mechanism. | 507 | * going through this "mips_io_port_base" mechanism. |
508 | */ | 508 | */ |
509 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - | 509 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - |
510 | mips_io_port_base); | 510 | mips_io_port_base); |
511 | 511 | ||
512 | if (!sock->virt_io) { | 512 | if (!sock->virt_io) { |
513 | printk(KERN_ERR "pcmcia%d: cannot remap IO area\n", | 513 | printk(KERN_ERR "pcmcia%d: cannot remap IO area\n", |
514 | sock->nr); | 514 | sock->nr); |
515 | ret = -ENOMEM; | 515 | ret = -ENOMEM; |
516 | goto out0; | 516 | goto out0; |
517 | } | 517 | } |
518 | 518 | ||
519 | sock->socket.ops = &db1x_pcmcia_operations; | 519 | sock->socket.ops = &db1x_pcmcia_operations; |
520 | sock->socket.owner = THIS_MODULE; | 520 | sock->socket.owner = THIS_MODULE; |
521 | sock->socket.pci_irq = sock->card_irq; | 521 | sock->socket.pci_irq = sock->card_irq; |
522 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | 522 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; |
523 | sock->socket.map_size = MEM_MAP_SIZE; | 523 | sock->socket.map_size = MEM_MAP_SIZE; |
524 | sock->socket.io_offset = (unsigned long)sock->virt_io; | 524 | sock->socket.io_offset = (unsigned long)sock->virt_io; |
525 | sock->socket.dev.parent = &pdev->dev; | 525 | sock->socket.dev.parent = &pdev->dev; |
526 | sock->socket.resource_ops = &pccard_static_ops; | 526 | sock->socket.resource_ops = &pccard_static_ops; |
527 | 527 | ||
528 | platform_set_drvdata(pdev, sock); | 528 | platform_set_drvdata(pdev, sock); |
529 | 529 | ||
530 | ret = db1x_pcmcia_setup_irqs(sock); | 530 | ret = db1x_pcmcia_setup_irqs(sock); |
531 | if (ret) { | 531 | if (ret) { |
532 | printk(KERN_ERR "pcmcia%d cannot setup interrupts\n", | 532 | printk(KERN_ERR "pcmcia%d cannot setup interrupts\n", |
533 | sock->nr); | 533 | sock->nr); |
534 | goto out1; | 534 | goto out1; |
535 | } | 535 | } |
536 | 536 | ||
537 | set_stschg(sock, 0); | 537 | set_stschg(sock, 0); |
538 | 538 | ||
539 | ret = pcmcia_register_socket(&sock->socket); | 539 | ret = pcmcia_register_socket(&sock->socket); |
540 | if (ret) { | 540 | if (ret) { |
541 | printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr); | 541 | printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr); |
542 | goto out2; | 542 | goto out2; |
543 | } | 543 | } |
544 | 544 | ||
545 | printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx" | 545 | printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx" |
546 | "(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d " | 546 | "(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d " |
547 | "%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io, | 547 | "%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io, |
548 | sock->phys_attr, sock->phys_mem, sock->card_irq, | 548 | sock->phys_attr, sock->phys_mem, sock->card_irq, |
549 | sock->insert_irq, sock->stschg_irq, sock->eject_irq); | 549 | sock->insert_irq, sock->stschg_irq, sock->eject_irq); |
550 | 550 | ||
551 | return 0; | 551 | return 0; |
552 | 552 | ||
553 | out2: | 553 | out2: |
554 | db1x_pcmcia_free_irqs(sock); | 554 | db1x_pcmcia_free_irqs(sock); |
555 | out1: | 555 | out1: |
556 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | 556 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); |
557 | out0: | 557 | out0: |
558 | kfree(sock); | 558 | kfree(sock); |
559 | return ret; | 559 | return ret; |
560 | } | 560 | } |
561 | 561 | ||
562 | static int __devexit db1x_pcmcia_socket_remove(struct platform_device *pdev) | 562 | static int __devexit db1x_pcmcia_socket_remove(struct platform_device *pdev) |
563 | { | 563 | { |
564 | struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev); | 564 | struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev); |
565 | 565 | ||
566 | db1x_pcmcia_free_irqs(sock); | 566 | db1x_pcmcia_free_irqs(sock); |
567 | pcmcia_unregister_socket(&sock->socket); | 567 | pcmcia_unregister_socket(&sock->socket); |
568 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | 568 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); |
569 | kfree(sock); | 569 | kfree(sock); |
570 | 570 | ||
571 | return 0; | 571 | return 0; |
572 | } | 572 | } |
573 | 573 | ||
574 | static struct platform_driver db1x_pcmcia_socket_driver = { | 574 | static struct platform_driver db1x_pcmcia_socket_driver = { |
575 | .driver = { | 575 | .driver = { |
576 | .name = "db1xxx_pcmcia", | 576 | .name = "db1xxx_pcmcia", |
577 | .owner = THIS_MODULE, | 577 | .owner = THIS_MODULE, |
578 | }, | 578 | }, |
579 | .probe = db1x_pcmcia_socket_probe, | 579 | .probe = db1x_pcmcia_socket_probe, |
580 | .remove = __devexit_p(db1x_pcmcia_socket_remove), | 580 | .remove = __devexit_p(db1x_pcmcia_socket_remove), |
581 | }; | 581 | }; |
582 | 582 | ||
583 | int __init db1x_pcmcia_socket_load(void) | 583 | module_platform_driver(db1x_pcmcia_socket_driver); |
584 | { | ||
585 | return platform_driver_register(&db1x_pcmcia_socket_driver); | ||
586 | } | ||
587 | |||
588 | void __exit db1x_pcmcia_socket_unload(void) | ||
589 | { | ||
590 | platform_driver_unregister(&db1x_pcmcia_socket_driver); | ||
591 | } | ||
592 | |||
593 | module_init(db1x_pcmcia_socket_load); | ||
594 | module_exit(db1x_pcmcia_socket_unload); | ||
595 | 584 | ||
596 | MODULE_LICENSE("GPL"); | 585 | MODULE_LICENSE("GPL"); |
597 | MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards"); | 586 | MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards"); |
598 | MODULE_AUTHOR("Manuel Lauss"); | 587 | MODULE_AUTHOR("Manuel Lauss"); |
599 | 588 |
drivers/pcmcia/electra_cf.c
1 | /* | 1 | /* |
2 | * Copyright (C) 2007 PA Semi, Inc | 2 | * Copyright (C) 2007 PA Semi, Inc |
3 | * | 3 | * |
4 | * Maintained by: Olof Johansson <olof@lixom.net> | 4 | * Maintained by: Olof Johansson <olof@lixom.net> |
5 | * | 5 | * |
6 | * Based on drivers/pcmcia/omap_cf.c | 6 | * Based on drivers/pcmcia/omap_cf.c |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. | 11 | * (at your option) any later version. |
12 | * | 12 | * |
13 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. |
17 | * | 17 | * |
18 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program; if not, write to the Free Software | 19 | * along with this program; if not, write to the Free Software |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
25 | #include <linux/sched.h> | 25 | #include <linux/sched.h> |
26 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/init.h> | 28 | #include <linux/init.h> |
29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
30 | #include <linux/interrupt.h> | 30 | #include <linux/interrupt.h> |
31 | #include <linux/mm.h> | 31 | #include <linux/mm.h> |
32 | #include <linux/vmalloc.h> | 32 | #include <linux/vmalloc.h> |
33 | #include <linux/of_platform.h> | 33 | #include <linux/of_platform.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | 35 | ||
36 | #include <pcmcia/ss.h> | 36 | #include <pcmcia/ss.h> |
37 | 37 | ||
38 | static const char driver_name[] = "electra-cf"; | 38 | static const char driver_name[] = "electra-cf"; |
39 | 39 | ||
40 | struct electra_cf_socket { | 40 | struct electra_cf_socket { |
41 | struct pcmcia_socket socket; | 41 | struct pcmcia_socket socket; |
42 | 42 | ||
43 | struct timer_list timer; | 43 | struct timer_list timer; |
44 | unsigned present:1; | 44 | unsigned present:1; |
45 | unsigned active:1; | 45 | unsigned active:1; |
46 | 46 | ||
47 | struct platform_device *ofdev; | 47 | struct platform_device *ofdev; |
48 | unsigned long mem_phys; | 48 | unsigned long mem_phys; |
49 | void __iomem * mem_base; | 49 | void __iomem * mem_base; |
50 | unsigned long mem_size; | 50 | unsigned long mem_size; |
51 | void __iomem * io_virt; | 51 | void __iomem * io_virt; |
52 | unsigned int io_base; | 52 | unsigned int io_base; |
53 | unsigned int io_size; | 53 | unsigned int io_size; |
54 | u_int irq; | 54 | u_int irq; |
55 | struct resource iomem; | 55 | struct resource iomem; |
56 | void __iomem * gpio_base; | 56 | void __iomem * gpio_base; |
57 | int gpio_detect; | 57 | int gpio_detect; |
58 | int gpio_vsense; | 58 | int gpio_vsense; |
59 | int gpio_3v; | 59 | int gpio_3v; |
60 | int gpio_5v; | 60 | int gpio_5v; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | #define POLL_INTERVAL (2 * HZ) | 63 | #define POLL_INTERVAL (2 * HZ) |
64 | 64 | ||
65 | 65 | ||
66 | static int electra_cf_present(struct electra_cf_socket *cf) | 66 | static int electra_cf_present(struct electra_cf_socket *cf) |
67 | { | 67 | { |
68 | unsigned int gpio; | 68 | unsigned int gpio; |
69 | 69 | ||
70 | gpio = in_le32(cf->gpio_base+0x40); | 70 | gpio = in_le32(cf->gpio_base+0x40); |
71 | return !(gpio & (1 << cf->gpio_detect)); | 71 | return !(gpio & (1 << cf->gpio_detect)); |
72 | } | 72 | } |
73 | 73 | ||
74 | static int electra_cf_ss_init(struct pcmcia_socket *s) | 74 | static int electra_cf_ss_init(struct pcmcia_socket *s) |
75 | { | 75 | { |
76 | return 0; | 76 | return 0; |
77 | } | 77 | } |
78 | 78 | ||
79 | /* the timer is primarily to kick this socket's pccardd */ | 79 | /* the timer is primarily to kick this socket's pccardd */ |
80 | static void electra_cf_timer(unsigned long _cf) | 80 | static void electra_cf_timer(unsigned long _cf) |
81 | { | 81 | { |
82 | struct electra_cf_socket *cf = (void *) _cf; | 82 | struct electra_cf_socket *cf = (void *) _cf; |
83 | int present = electra_cf_present(cf); | 83 | int present = electra_cf_present(cf); |
84 | 84 | ||
85 | if (present != cf->present) { | 85 | if (present != cf->present) { |
86 | cf->present = present; | 86 | cf->present = present; |
87 | pcmcia_parse_events(&cf->socket, SS_DETECT); | 87 | pcmcia_parse_events(&cf->socket, SS_DETECT); |
88 | } | 88 | } |
89 | 89 | ||
90 | if (cf->active) | 90 | if (cf->active) |
91 | mod_timer(&cf->timer, jiffies + POLL_INTERVAL); | 91 | mod_timer(&cf->timer, jiffies + POLL_INTERVAL); |
92 | } | 92 | } |
93 | 93 | ||
94 | static irqreturn_t electra_cf_irq(int irq, void *_cf) | 94 | static irqreturn_t electra_cf_irq(int irq, void *_cf) |
95 | { | 95 | { |
96 | electra_cf_timer((unsigned long)_cf); | 96 | electra_cf_timer((unsigned long)_cf); |
97 | return IRQ_HANDLED; | 97 | return IRQ_HANDLED; |
98 | } | 98 | } |
99 | 99 | ||
100 | static int electra_cf_get_status(struct pcmcia_socket *s, u_int *sp) | 100 | static int electra_cf_get_status(struct pcmcia_socket *s, u_int *sp) |
101 | { | 101 | { |
102 | struct electra_cf_socket *cf; | 102 | struct electra_cf_socket *cf; |
103 | 103 | ||
104 | if (!sp) | 104 | if (!sp) |
105 | return -EINVAL; | 105 | return -EINVAL; |
106 | 106 | ||
107 | cf = container_of(s, struct electra_cf_socket, socket); | 107 | cf = container_of(s, struct electra_cf_socket, socket); |
108 | 108 | ||
109 | /* NOTE CF is always 3VCARD */ | 109 | /* NOTE CF is always 3VCARD */ |
110 | if (electra_cf_present(cf)) { | 110 | if (electra_cf_present(cf)) { |
111 | *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD; | 111 | *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD; |
112 | 112 | ||
113 | s->pci_irq = cf->irq; | 113 | s->pci_irq = cf->irq; |
114 | } else | 114 | } else |
115 | *sp = 0; | 115 | *sp = 0; |
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | 118 | ||
119 | static int electra_cf_set_socket(struct pcmcia_socket *sock, | 119 | static int electra_cf_set_socket(struct pcmcia_socket *sock, |
120 | struct socket_state_t *s) | 120 | struct socket_state_t *s) |
121 | { | 121 | { |
122 | unsigned int gpio; | 122 | unsigned int gpio; |
123 | unsigned int vcc; | 123 | unsigned int vcc; |
124 | struct electra_cf_socket *cf; | 124 | struct electra_cf_socket *cf; |
125 | 125 | ||
126 | cf = container_of(sock, struct electra_cf_socket, socket); | 126 | cf = container_of(sock, struct electra_cf_socket, socket); |
127 | 127 | ||
128 | /* "reset" means no power in our case */ | 128 | /* "reset" means no power in our case */ |
129 | vcc = (s->flags & SS_RESET) ? 0 : s->Vcc; | 129 | vcc = (s->flags & SS_RESET) ? 0 : s->Vcc; |
130 | 130 | ||
131 | switch (vcc) { | 131 | switch (vcc) { |
132 | case 0: | 132 | case 0: |
133 | gpio = 0; | 133 | gpio = 0; |
134 | break; | 134 | break; |
135 | case 33: | 135 | case 33: |
136 | gpio = (1 << cf->gpio_3v); | 136 | gpio = (1 << cf->gpio_3v); |
137 | break; | 137 | break; |
138 | case 5: | 138 | case 5: |
139 | gpio = (1 << cf->gpio_5v); | 139 | gpio = (1 << cf->gpio_5v); |
140 | break; | 140 | break; |
141 | default: | 141 | default: |
142 | return -EINVAL; | 142 | return -EINVAL; |
143 | } | 143 | } |
144 | 144 | ||
145 | gpio |= 1 << (cf->gpio_3v + 16); /* enwr */ | 145 | gpio |= 1 << (cf->gpio_3v + 16); /* enwr */ |
146 | gpio |= 1 << (cf->gpio_5v + 16); /* enwr */ | 146 | gpio |= 1 << (cf->gpio_5v + 16); /* enwr */ |
147 | out_le32(cf->gpio_base+0x90, gpio); | 147 | out_le32(cf->gpio_base+0x90, gpio); |
148 | 148 | ||
149 | pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n", | 149 | pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n", |
150 | driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask); | 150 | driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask); |
151 | 151 | ||
152 | return 0; | 152 | return 0; |
153 | } | 153 | } |
154 | 154 | ||
155 | static int electra_cf_set_io_map(struct pcmcia_socket *s, | 155 | static int electra_cf_set_io_map(struct pcmcia_socket *s, |
156 | struct pccard_io_map *io) | 156 | struct pccard_io_map *io) |
157 | { | 157 | { |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | 160 | ||
161 | static int electra_cf_set_mem_map(struct pcmcia_socket *s, | 161 | static int electra_cf_set_mem_map(struct pcmcia_socket *s, |
162 | struct pccard_mem_map *map) | 162 | struct pccard_mem_map *map) |
163 | { | 163 | { |
164 | struct electra_cf_socket *cf; | 164 | struct electra_cf_socket *cf; |
165 | 165 | ||
166 | if (map->card_start) | 166 | if (map->card_start) |
167 | return -EINVAL; | 167 | return -EINVAL; |
168 | cf = container_of(s, struct electra_cf_socket, socket); | 168 | cf = container_of(s, struct electra_cf_socket, socket); |
169 | map->static_start = cf->mem_phys; | 169 | map->static_start = cf->mem_phys; |
170 | map->flags &= MAP_ACTIVE|MAP_ATTRIB; | 170 | map->flags &= MAP_ACTIVE|MAP_ATTRIB; |
171 | if (!(map->flags & MAP_ATTRIB)) | 171 | if (!(map->flags & MAP_ATTRIB)) |
172 | map->static_start += 0x800; | 172 | map->static_start += 0x800; |
173 | return 0; | 173 | return 0; |
174 | } | 174 | } |
175 | 175 | ||
176 | static struct pccard_operations electra_cf_ops = { | 176 | static struct pccard_operations electra_cf_ops = { |
177 | .init = electra_cf_ss_init, | 177 | .init = electra_cf_ss_init, |
178 | .get_status = electra_cf_get_status, | 178 | .get_status = electra_cf_get_status, |
179 | .set_socket = electra_cf_set_socket, | 179 | .set_socket = electra_cf_set_socket, |
180 | .set_io_map = electra_cf_set_io_map, | 180 | .set_io_map = electra_cf_set_io_map, |
181 | .set_mem_map = electra_cf_set_mem_map, | 181 | .set_mem_map = electra_cf_set_mem_map, |
182 | }; | 182 | }; |
183 | 183 | ||
184 | static int __devinit electra_cf_probe(struct platform_device *ofdev) | 184 | static int __devinit electra_cf_probe(struct platform_device *ofdev) |
185 | { | 185 | { |
186 | struct device *device = &ofdev->dev; | 186 | struct device *device = &ofdev->dev; |
187 | struct device_node *np = ofdev->dev.of_node; | 187 | struct device_node *np = ofdev->dev.of_node; |
188 | struct electra_cf_socket *cf; | 188 | struct electra_cf_socket *cf; |
189 | struct resource mem, io; | 189 | struct resource mem, io; |
190 | int status; | 190 | int status; |
191 | const unsigned int *prop; | 191 | const unsigned int *prop; |
192 | int err; | 192 | int err; |
193 | struct vm_struct *area; | 193 | struct vm_struct *area; |
194 | 194 | ||
195 | err = of_address_to_resource(np, 0, &mem); | 195 | err = of_address_to_resource(np, 0, &mem); |
196 | if (err) | 196 | if (err) |
197 | return -EINVAL; | 197 | return -EINVAL; |
198 | 198 | ||
199 | err = of_address_to_resource(np, 1, &io); | 199 | err = of_address_to_resource(np, 1, &io); |
200 | if (err) | 200 | if (err) |
201 | return -EINVAL; | 201 | return -EINVAL; |
202 | 202 | ||
203 | cf = kzalloc(sizeof *cf, GFP_KERNEL); | 203 | cf = kzalloc(sizeof *cf, GFP_KERNEL); |
204 | if (!cf) | 204 | if (!cf) |
205 | return -ENOMEM; | 205 | return -ENOMEM; |
206 | 206 | ||
207 | setup_timer(&cf->timer, electra_cf_timer, (unsigned long)cf); | 207 | setup_timer(&cf->timer, electra_cf_timer, (unsigned long)cf); |
208 | cf->irq = NO_IRQ; | 208 | cf->irq = NO_IRQ; |
209 | 209 | ||
210 | cf->ofdev = ofdev; | 210 | cf->ofdev = ofdev; |
211 | cf->mem_phys = mem.start; | 211 | cf->mem_phys = mem.start; |
212 | cf->mem_size = PAGE_ALIGN(resource_size(&mem)); | 212 | cf->mem_size = PAGE_ALIGN(resource_size(&mem)); |
213 | cf->mem_base = ioremap(cf->mem_phys, cf->mem_size); | 213 | cf->mem_base = ioremap(cf->mem_phys, cf->mem_size); |
214 | cf->io_size = PAGE_ALIGN(resource_size(&io)); | 214 | cf->io_size = PAGE_ALIGN(resource_size(&io)); |
215 | 215 | ||
216 | area = __get_vm_area(cf->io_size, 0, PHB_IO_BASE, PHB_IO_END); | 216 | area = __get_vm_area(cf->io_size, 0, PHB_IO_BASE, PHB_IO_END); |
217 | if (area == NULL) | 217 | if (area == NULL) |
218 | return -ENOMEM; | 218 | return -ENOMEM; |
219 | 219 | ||
220 | cf->io_virt = (void __iomem *)(area->addr); | 220 | cf->io_virt = (void __iomem *)(area->addr); |
221 | 221 | ||
222 | cf->gpio_base = ioremap(0xfc103000, 0x1000); | 222 | cf->gpio_base = ioremap(0xfc103000, 0x1000); |
223 | dev_set_drvdata(device, cf); | 223 | dev_set_drvdata(device, cf); |
224 | 224 | ||
225 | if (!cf->mem_base || !cf->io_virt || !cf->gpio_base || | 225 | if (!cf->mem_base || !cf->io_virt || !cf->gpio_base || |
226 | (__ioremap_at(io.start, cf->io_virt, cf->io_size, | 226 | (__ioremap_at(io.start, cf->io_virt, cf->io_size, |
227 | _PAGE_NO_CACHE | _PAGE_GUARDED) == NULL)) { | 227 | _PAGE_NO_CACHE | _PAGE_GUARDED) == NULL)) { |
228 | dev_err(device, "can't ioremap ranges\n"); | 228 | dev_err(device, "can't ioremap ranges\n"); |
229 | status = -ENOMEM; | 229 | status = -ENOMEM; |
230 | goto fail1; | 230 | goto fail1; |
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | cf->io_base = (unsigned long)cf->io_virt - VMALLOC_END; | 234 | cf->io_base = (unsigned long)cf->io_virt - VMALLOC_END; |
235 | 235 | ||
236 | cf->iomem.start = (unsigned long)cf->mem_base; | 236 | cf->iomem.start = (unsigned long)cf->mem_base; |
237 | cf->iomem.end = (unsigned long)cf->mem_base + (mem.end - mem.start); | 237 | cf->iomem.end = (unsigned long)cf->mem_base + (mem.end - mem.start); |
238 | cf->iomem.flags = IORESOURCE_MEM; | 238 | cf->iomem.flags = IORESOURCE_MEM; |
239 | 239 | ||
240 | cf->irq = irq_of_parse_and_map(np, 0); | 240 | cf->irq = irq_of_parse_and_map(np, 0); |
241 | 241 | ||
242 | status = request_irq(cf->irq, electra_cf_irq, IRQF_SHARED, | 242 | status = request_irq(cf->irq, electra_cf_irq, IRQF_SHARED, |
243 | driver_name, cf); | 243 | driver_name, cf); |
244 | if (status < 0) { | 244 | if (status < 0) { |
245 | dev_err(device, "request_irq failed\n"); | 245 | dev_err(device, "request_irq failed\n"); |
246 | goto fail1; | 246 | goto fail1; |
247 | } | 247 | } |
248 | 248 | ||
249 | cf->socket.pci_irq = cf->irq; | 249 | cf->socket.pci_irq = cf->irq; |
250 | 250 | ||
251 | prop = of_get_property(np, "card-detect-gpio", NULL); | 251 | prop = of_get_property(np, "card-detect-gpio", NULL); |
252 | if (!prop) | 252 | if (!prop) |
253 | goto fail1; | 253 | goto fail1; |
254 | cf->gpio_detect = *prop; | 254 | cf->gpio_detect = *prop; |
255 | 255 | ||
256 | prop = of_get_property(np, "card-vsense-gpio", NULL); | 256 | prop = of_get_property(np, "card-vsense-gpio", NULL); |
257 | if (!prop) | 257 | if (!prop) |
258 | goto fail1; | 258 | goto fail1; |
259 | cf->gpio_vsense = *prop; | 259 | cf->gpio_vsense = *prop; |
260 | 260 | ||
261 | prop = of_get_property(np, "card-3v-gpio", NULL); | 261 | prop = of_get_property(np, "card-3v-gpio", NULL); |
262 | if (!prop) | 262 | if (!prop) |
263 | goto fail1; | 263 | goto fail1; |
264 | cf->gpio_3v = *prop; | 264 | cf->gpio_3v = *prop; |
265 | 265 | ||
266 | prop = of_get_property(np, "card-5v-gpio", NULL); | 266 | prop = of_get_property(np, "card-5v-gpio", NULL); |
267 | if (!prop) | 267 | if (!prop) |
268 | goto fail1; | 268 | goto fail1; |
269 | cf->gpio_5v = *prop; | 269 | cf->gpio_5v = *prop; |
270 | 270 | ||
271 | cf->socket.io_offset = cf->io_base; | 271 | cf->socket.io_offset = cf->io_base; |
272 | 272 | ||
273 | /* reserve chip-select regions */ | 273 | /* reserve chip-select regions */ |
274 | if (!request_mem_region(cf->mem_phys, cf->mem_size, driver_name)) { | 274 | if (!request_mem_region(cf->mem_phys, cf->mem_size, driver_name)) { |
275 | status = -ENXIO; | 275 | status = -ENXIO; |
276 | dev_err(device, "Can't claim memory region\n"); | 276 | dev_err(device, "Can't claim memory region\n"); |
277 | goto fail1; | 277 | goto fail1; |
278 | } | 278 | } |
279 | 279 | ||
280 | if (!request_region(cf->io_base, cf->io_size, driver_name)) { | 280 | if (!request_region(cf->io_base, cf->io_size, driver_name)) { |
281 | status = -ENXIO; | 281 | status = -ENXIO; |
282 | dev_err(device, "Can't claim I/O region\n"); | 282 | dev_err(device, "Can't claim I/O region\n"); |
283 | goto fail2; | 283 | goto fail2; |
284 | } | 284 | } |
285 | 285 | ||
286 | cf->socket.owner = THIS_MODULE; | 286 | cf->socket.owner = THIS_MODULE; |
287 | cf->socket.dev.parent = &ofdev->dev; | 287 | cf->socket.dev.parent = &ofdev->dev; |
288 | cf->socket.ops = &electra_cf_ops; | 288 | cf->socket.ops = &electra_cf_ops; |
289 | cf->socket.resource_ops = &pccard_static_ops; | 289 | cf->socket.resource_ops = &pccard_static_ops; |
290 | cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP | | 290 | cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP | |
291 | SS_CAP_MEM_ALIGN; | 291 | SS_CAP_MEM_ALIGN; |
292 | cf->socket.map_size = 0x800; | 292 | cf->socket.map_size = 0x800; |
293 | 293 | ||
294 | status = pcmcia_register_socket(&cf->socket); | 294 | status = pcmcia_register_socket(&cf->socket); |
295 | if (status < 0) { | 295 | if (status < 0) { |
296 | dev_err(device, "pcmcia_register_socket failed\n"); | 296 | dev_err(device, "pcmcia_register_socket failed\n"); |
297 | goto fail3; | 297 | goto fail3; |
298 | } | 298 | } |
299 | 299 | ||
300 | dev_info(device, "at mem 0x%lx io 0x%llx irq %d\n", | 300 | dev_info(device, "at mem 0x%lx io 0x%llx irq %d\n", |
301 | cf->mem_phys, io.start, cf->irq); | 301 | cf->mem_phys, io.start, cf->irq); |
302 | 302 | ||
303 | cf->active = 1; | 303 | cf->active = 1; |
304 | electra_cf_timer((unsigned long)cf); | 304 | electra_cf_timer((unsigned long)cf); |
305 | return 0; | 305 | return 0; |
306 | 306 | ||
307 | fail3: | 307 | fail3: |
308 | release_region(cf->io_base, cf->io_size); | 308 | release_region(cf->io_base, cf->io_size); |
309 | fail2: | 309 | fail2: |
310 | release_mem_region(cf->mem_phys, cf->mem_size); | 310 | release_mem_region(cf->mem_phys, cf->mem_size); |
311 | fail1: | 311 | fail1: |
312 | if (cf->irq != NO_IRQ) | 312 | if (cf->irq != NO_IRQ) |
313 | free_irq(cf->irq, cf); | 313 | free_irq(cf->irq, cf); |
314 | 314 | ||
315 | if (cf->io_virt) | 315 | if (cf->io_virt) |
316 | __iounmap_at(cf->io_virt, cf->io_size); | 316 | __iounmap_at(cf->io_virt, cf->io_size); |
317 | if (cf->mem_base) | 317 | if (cf->mem_base) |
318 | iounmap(cf->mem_base); | 318 | iounmap(cf->mem_base); |
319 | if (cf->gpio_base) | 319 | if (cf->gpio_base) |
320 | iounmap(cf->gpio_base); | 320 | iounmap(cf->gpio_base); |
321 | device_init_wakeup(&ofdev->dev, 0); | 321 | device_init_wakeup(&ofdev->dev, 0); |
322 | kfree(cf); | 322 | kfree(cf); |
323 | return status; | 323 | return status; |
324 | 324 | ||
325 | } | 325 | } |
326 | 326 | ||
327 | static int __devexit electra_cf_remove(struct platform_device *ofdev) | 327 | static int __devexit electra_cf_remove(struct platform_device *ofdev) |
328 | { | 328 | { |
329 | struct device *device = &ofdev->dev; | 329 | struct device *device = &ofdev->dev; |
330 | struct electra_cf_socket *cf; | 330 | struct electra_cf_socket *cf; |
331 | 331 | ||
332 | cf = dev_get_drvdata(device); | 332 | cf = dev_get_drvdata(device); |
333 | 333 | ||
334 | cf->active = 0; | 334 | cf->active = 0; |
335 | pcmcia_unregister_socket(&cf->socket); | 335 | pcmcia_unregister_socket(&cf->socket); |
336 | free_irq(cf->irq, cf); | 336 | free_irq(cf->irq, cf); |
337 | del_timer_sync(&cf->timer); | 337 | del_timer_sync(&cf->timer); |
338 | 338 | ||
339 | __iounmap_at(cf->io_virt, cf->io_size); | 339 | __iounmap_at(cf->io_virt, cf->io_size); |
340 | iounmap(cf->mem_base); | 340 | iounmap(cf->mem_base); |
341 | iounmap(cf->gpio_base); | 341 | iounmap(cf->gpio_base); |
342 | release_mem_region(cf->mem_phys, cf->mem_size); | 342 | release_mem_region(cf->mem_phys, cf->mem_size); |
343 | release_region(cf->io_base, cf->io_size); | 343 | release_region(cf->io_base, cf->io_size); |
344 | 344 | ||
345 | kfree(cf); | 345 | kfree(cf); |
346 | 346 | ||
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||
350 | static const struct of_device_id electra_cf_match[] = { | 350 | static const struct of_device_id electra_cf_match[] = { |
351 | { | 351 | { |
352 | .compatible = "electra-cf", | 352 | .compatible = "electra-cf", |
353 | }, | 353 | }, |
354 | {}, | 354 | {}, |
355 | }; | 355 | }; |
356 | MODULE_DEVICE_TABLE(of, electra_cf_match); | 356 | MODULE_DEVICE_TABLE(of, electra_cf_match); |
357 | 357 | ||
358 | static struct platform_driver electra_cf_driver = { | 358 | static struct platform_driver electra_cf_driver = { |
359 | .driver = { | 359 | .driver = { |
360 | .name = (char *)driver_name, | 360 | .name = (char *)driver_name, |
361 | .owner = THIS_MODULE, | 361 | .owner = THIS_MODULE, |
362 | .of_match_table = electra_cf_match, | 362 | .of_match_table = electra_cf_match, |
363 | }, | 363 | }, |
364 | .probe = electra_cf_probe, | 364 | .probe = electra_cf_probe, |
365 | .remove = electra_cf_remove, | 365 | .remove = electra_cf_remove, |
366 | }; | 366 | }; |
367 | 367 | ||
368 | static int __init electra_cf_init(void) | 368 | module_platform_driver(electra_cf_driver); |
369 | { | ||
370 | return platform_driver_register(&electra_cf_driver); | ||
371 | } | ||
372 | module_init(electra_cf_init); | ||
373 | |||
374 | static void __exit electra_cf_exit(void) | ||
375 | { | ||
376 | platform_driver_unregister(&electra_cf_driver); | ||
377 | } | ||
378 | module_exit(electra_cf_exit); | ||
379 | 369 | ||
380 | MODULE_LICENSE("GPL"); | 370 | MODULE_LICENSE("GPL"); |
381 | MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>"); | 371 | MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>"); |
382 | MODULE_DESCRIPTION("PA Semi Electra CF driver"); | 372 | MODULE_DESCRIPTION("PA Semi Electra CF driver"); |
383 | 373 |
drivers/pcmcia/m8xx_pcmcia.c
1 | /* | 1 | /* |
2 | * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series. | 2 | * m8xx_pcmcia.c - Linux PCMCIA socket driver for the mpc8xx series. |
3 | * | 3 | * |
4 | * (C) 1999-2000 Magnus Damm <damm@opensource.se> | 4 | * (C) 1999-2000 Magnus Damm <damm@opensource.se> |
5 | * (C) 2001-2002 Montavista Software, Inc. | 5 | * (C) 2001-2002 Montavista Software, Inc. |
6 | * <mlocke@mvista.com> | 6 | * <mlocke@mvista.com> |
7 | * | 7 | * |
8 | * Support for two slots by Cyclades Corporation | 8 | * Support for two slots by Cyclades Corporation |
9 | * <oliver.kurth@cyclades.de> | 9 | * <oliver.kurth@cyclades.de> |
10 | * Further fixes, v2.6 kernel port | 10 | * Further fixes, v2.6 kernel port |
11 | * <marcelo.tosatti@cyclades.com> | 11 | * <marcelo.tosatti@cyclades.com> |
12 | * | 12 | * |
13 | * Some fixes, additions (C) 2005-2007 Montavista Software, Inc. | 13 | * Some fixes, additions (C) 2005-2007 Montavista Software, Inc. |
14 | * <vbordug@ru.mvista.com> | 14 | * <vbordug@ru.mvista.com> |
15 | * | 15 | * |
16 | * "The ExCA standard specifies that socket controllers should provide | 16 | * "The ExCA standard specifies that socket controllers should provide |
17 | * two IO and five memory windows per socket, which can be independently | 17 | * two IO and five memory windows per socket, which can be independently |
18 | * configured and positioned in the host address space and mapped to | 18 | * configured and positioned in the host address space and mapped to |
19 | * arbitrary segments of card address space. " - David A Hinds. 1999 | 19 | * arbitrary segments of card address space. " - David A Hinds. 1999 |
20 | * | 20 | * |
21 | * This controller does _not_ meet the ExCA standard. | 21 | * This controller does _not_ meet the ExCA standard. |
22 | * | 22 | * |
23 | * m8xx pcmcia controller brief info: | 23 | * m8xx pcmcia controller brief info: |
24 | * + 8 windows (attrib, mem, i/o) | 24 | * + 8 windows (attrib, mem, i/o) |
25 | * + up to two slots (SLOT_A and SLOT_B) | 25 | * + up to two slots (SLOT_A and SLOT_B) |
26 | * + inputpins, outputpins, event and mask registers. | 26 | * + inputpins, outputpins, event and mask registers. |
27 | * - no offset register. sigh. | 27 | * - no offset register. sigh. |
28 | * | 28 | * |
29 | * Because of the lacking offset register we must map the whole card. | 29 | * Because of the lacking offset register we must map the whole card. |
30 | * We assign each memory window PCMCIA_MEM_WIN_SIZE address space. | 30 | * We assign each memory window PCMCIA_MEM_WIN_SIZE address space. |
31 | * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO | 31 | * Make sure there is (PCMCIA_MEM_WIN_SIZE * PCMCIA_MEM_WIN_NO |
32 | * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE. | 32 | * * PCMCIA_SOCKETS_NO) bytes at PCMCIA_MEM_WIN_BASE. |
33 | * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE. | 33 | * The i/o windows are dynamically allocated at PCMCIA_IO_WIN_BASE. |
34 | * They are maximum 64KByte each... | 34 | * They are maximum 64KByte each... |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include <linux/module.h> | 37 | #include <linux/module.h> |
38 | #include <linux/init.h> | 38 | #include <linux/init.h> |
39 | #include <linux/types.h> | 39 | #include <linux/types.h> |
40 | #include <linux/fcntl.h> | 40 | #include <linux/fcntl.h> |
41 | #include <linux/string.h> | 41 | #include <linux/string.h> |
42 | 42 | ||
43 | #include <linux/kernel.h> | 43 | #include <linux/kernel.h> |
44 | #include <linux/errno.h> | 44 | #include <linux/errno.h> |
45 | #include <linux/timer.h> | 45 | #include <linux/timer.h> |
46 | #include <linux/ioport.h> | 46 | #include <linux/ioport.h> |
47 | #include <linux/delay.h> | 47 | #include <linux/delay.h> |
48 | #include <linux/interrupt.h> | 48 | #include <linux/interrupt.h> |
49 | #include <linux/fsl_devices.h> | 49 | #include <linux/fsl_devices.h> |
50 | #include <linux/bitops.h> | 50 | #include <linux/bitops.h> |
51 | #include <linux/of_device.h> | 51 | #include <linux/of_device.h> |
52 | #include <linux/of_platform.h> | 52 | #include <linux/of_platform.h> |
53 | 53 | ||
54 | #include <asm/io.h> | 54 | #include <asm/io.h> |
55 | #include <asm/system.h> | 55 | #include <asm/system.h> |
56 | #include <asm/time.h> | 56 | #include <asm/time.h> |
57 | #include <asm/mpc8xx.h> | 57 | #include <asm/mpc8xx.h> |
58 | #include <asm/8xx_immap.h> | 58 | #include <asm/8xx_immap.h> |
59 | #include <asm/irq.h> | 59 | #include <asm/irq.h> |
60 | #include <asm/fs_pd.h> | 60 | #include <asm/fs_pd.h> |
61 | 61 | ||
62 | #include <pcmcia/ss.h> | 62 | #include <pcmcia/ss.h> |
63 | 63 | ||
64 | #define pcmcia_info(args...) printk(KERN_INFO "m8xx_pcmcia: "args) | 64 | #define pcmcia_info(args...) printk(KERN_INFO "m8xx_pcmcia: "args) |
65 | #define pcmcia_error(args...) printk(KERN_ERR "m8xx_pcmcia: "args) | 65 | #define pcmcia_error(args...) printk(KERN_ERR "m8xx_pcmcia: "args) |
66 | 66 | ||
67 | static const char *version = "Version 0.06, Aug 2005"; | 67 | static const char *version = "Version 0.06, Aug 2005"; |
68 | MODULE_LICENSE("Dual MPL/GPL"); | 68 | MODULE_LICENSE("Dual MPL/GPL"); |
69 | 69 | ||
70 | #if !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B) | 70 | #if !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B) |
71 | 71 | ||
72 | /* The RPX series use SLOT_B */ | 72 | /* The RPX series use SLOT_B */ |
73 | #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE) | 73 | #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE) |
74 | #define CONFIG_PCMCIA_SLOT_B | 74 | #define CONFIG_PCMCIA_SLOT_B |
75 | #define CONFIG_BD_IS_MHZ | 75 | #define CONFIG_BD_IS_MHZ |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | /* The ADS board use SLOT_A */ | 78 | /* The ADS board use SLOT_A */ |
79 | #ifdef CONFIG_ADS | 79 | #ifdef CONFIG_ADS |
80 | #define CONFIG_PCMCIA_SLOT_A | 80 | #define CONFIG_PCMCIA_SLOT_A |
81 | #define CONFIG_BD_IS_MHZ | 81 | #define CONFIG_BD_IS_MHZ |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | /* The FADS series are a mess */ | 84 | /* The FADS series are a mess */ |
85 | #ifdef CONFIG_FADS | 85 | #ifdef CONFIG_FADS |
86 | #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC860) || defined(CONFIG_MPC821) | 86 | #if defined(CONFIG_MPC860T) || defined(CONFIG_MPC860) || defined(CONFIG_MPC821) |
87 | #define CONFIG_PCMCIA_SLOT_A | 87 | #define CONFIG_PCMCIA_SLOT_A |
88 | #else | 88 | #else |
89 | #define CONFIG_PCMCIA_SLOT_B | 89 | #define CONFIG_PCMCIA_SLOT_B |
90 | #endif | 90 | #endif |
91 | #endif | 91 | #endif |
92 | 92 | ||
93 | #if defined(CONFIG_MPC885ADS) | 93 | #if defined(CONFIG_MPC885ADS) |
94 | #define CONFIG_PCMCIA_SLOT_A | 94 | #define CONFIG_PCMCIA_SLOT_A |
95 | #define PCMCIA_GLITCHY_CD | 95 | #define PCMCIA_GLITCHY_CD |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | /* Cyclades ACS uses both slots */ | 98 | /* Cyclades ACS uses both slots */ |
99 | #ifdef CONFIG_PRxK | 99 | #ifdef CONFIG_PRxK |
100 | #define CONFIG_PCMCIA_SLOT_A | 100 | #define CONFIG_PCMCIA_SLOT_A |
101 | #define CONFIG_PCMCIA_SLOT_B | 101 | #define CONFIG_PCMCIA_SLOT_B |
102 | #endif | 102 | #endif |
103 | 103 | ||
104 | #endif /* !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B) */ | 104 | #endif /* !defined(CONFIG_PCMCIA_SLOT_A) && !defined(CONFIG_PCMCIA_SLOT_B) */ |
105 | 105 | ||
106 | #if defined(CONFIG_PCMCIA_SLOT_A) && defined(CONFIG_PCMCIA_SLOT_B) | 106 | #if defined(CONFIG_PCMCIA_SLOT_A) && defined(CONFIG_PCMCIA_SLOT_B) |
107 | 107 | ||
108 | #define PCMCIA_SOCKETS_NO 2 | 108 | #define PCMCIA_SOCKETS_NO 2 |
109 | /* We have only 8 windows, dualsocket support will be limited. */ | 109 | /* We have only 8 windows, dualsocket support will be limited. */ |
110 | #define PCMCIA_MEM_WIN_NO 2 | 110 | #define PCMCIA_MEM_WIN_NO 2 |
111 | #define PCMCIA_IO_WIN_NO 2 | 111 | #define PCMCIA_IO_WIN_NO 2 |
112 | #define PCMCIA_SLOT_MSG "SLOT_A and SLOT_B" | 112 | #define PCMCIA_SLOT_MSG "SLOT_A and SLOT_B" |
113 | 113 | ||
114 | #elif defined(CONFIG_PCMCIA_SLOT_A) || defined(CONFIG_PCMCIA_SLOT_B) | 114 | #elif defined(CONFIG_PCMCIA_SLOT_A) || defined(CONFIG_PCMCIA_SLOT_B) |
115 | 115 | ||
116 | #define PCMCIA_SOCKETS_NO 1 | 116 | #define PCMCIA_SOCKETS_NO 1 |
117 | /* full support for one slot */ | 117 | /* full support for one slot */ |
118 | #define PCMCIA_MEM_WIN_NO 5 | 118 | #define PCMCIA_MEM_WIN_NO 5 |
119 | #define PCMCIA_IO_WIN_NO 2 | 119 | #define PCMCIA_IO_WIN_NO 2 |
120 | 120 | ||
121 | /* define _slot_ to be able to optimize macros */ | 121 | /* define _slot_ to be able to optimize macros */ |
122 | 122 | ||
123 | #ifdef CONFIG_PCMCIA_SLOT_A | 123 | #ifdef CONFIG_PCMCIA_SLOT_A |
124 | #define _slot_ 0 | 124 | #define _slot_ 0 |
125 | #define PCMCIA_SLOT_MSG "SLOT_A" | 125 | #define PCMCIA_SLOT_MSG "SLOT_A" |
126 | #else | 126 | #else |
127 | #define _slot_ 1 | 127 | #define _slot_ 1 |
128 | #define PCMCIA_SLOT_MSG "SLOT_B" | 128 | #define PCMCIA_SLOT_MSG "SLOT_B" |
129 | #endif | 129 | #endif |
130 | 130 | ||
131 | #else | 131 | #else |
132 | #error m8xx_pcmcia: Bad configuration! | 132 | #error m8xx_pcmcia: Bad configuration! |
133 | #endif | 133 | #endif |
134 | 134 | ||
135 | /* ------------------------------------------------------------------------- */ | 135 | /* ------------------------------------------------------------------------- */ |
136 | 136 | ||
137 | #define PCMCIA_MEM_WIN_BASE 0xe0000000 /* base address for memory window 0 */ | 137 | #define PCMCIA_MEM_WIN_BASE 0xe0000000 /* base address for memory window 0 */ |
138 | #define PCMCIA_MEM_WIN_SIZE 0x04000000 /* each memory window is 64 MByte */ | 138 | #define PCMCIA_MEM_WIN_SIZE 0x04000000 /* each memory window is 64 MByte */ |
139 | #define PCMCIA_IO_WIN_BASE _IO_BASE /* base address for io window 0 */ | 139 | #define PCMCIA_IO_WIN_BASE _IO_BASE /* base address for io window 0 */ |
140 | /* ------------------------------------------------------------------------- */ | 140 | /* ------------------------------------------------------------------------- */ |
141 | 141 | ||
142 | static int pcmcia_schlvl; | 142 | static int pcmcia_schlvl; |
143 | 143 | ||
144 | static DEFINE_SPINLOCK(events_lock); | 144 | static DEFINE_SPINLOCK(events_lock); |
145 | 145 | ||
146 | #define PCMCIA_SOCKET_KEY_5V 1 | 146 | #define PCMCIA_SOCKET_KEY_5V 1 |
147 | #define PCMCIA_SOCKET_KEY_LV 2 | 147 | #define PCMCIA_SOCKET_KEY_LV 2 |
148 | 148 | ||
149 | /* look up table for pgcrx registers */ | 149 | /* look up table for pgcrx registers */ |
150 | static u32 *m8xx_pgcrx[2]; | 150 | static u32 *m8xx_pgcrx[2]; |
151 | 151 | ||
152 | /* | 152 | /* |
153 | * This structure is used to address each window in the PCMCIA controller. | 153 | * This structure is used to address each window in the PCMCIA controller. |
154 | * | 154 | * |
155 | * Keep in mind that we assume that pcmcia_win[n+1] is mapped directly | 155 | * Keep in mind that we assume that pcmcia_win[n+1] is mapped directly |
156 | * after pcmcia_win[n]... | 156 | * after pcmcia_win[n]... |
157 | */ | 157 | */ |
158 | 158 | ||
159 | struct pcmcia_win { | 159 | struct pcmcia_win { |
160 | u32 br; | 160 | u32 br; |
161 | u32 or; | 161 | u32 or; |
162 | }; | 162 | }; |
163 | 163 | ||
164 | /* | 164 | /* |
165 | * For some reason the hardware guys decided to make both slots share | 165 | * For some reason the hardware guys decided to make both slots share |
166 | * some registers. | 166 | * some registers. |
167 | * | 167 | * |
168 | * Could someone invent object oriented hardware ? | 168 | * Could someone invent object oriented hardware ? |
169 | * | 169 | * |
170 | * The macros are used to get the right bit from the registers. | 170 | * The macros are used to get the right bit from the registers. |
171 | * SLOT_A : slot = 0 | 171 | * SLOT_A : slot = 0 |
172 | * SLOT_B : slot = 1 | 172 | * SLOT_B : slot = 1 |
173 | */ | 173 | */ |
174 | 174 | ||
175 | #define M8XX_PCMCIA_VS1(slot) (0x80000000 >> (slot << 4)) | 175 | #define M8XX_PCMCIA_VS1(slot) (0x80000000 >> (slot << 4)) |
176 | #define M8XX_PCMCIA_VS2(slot) (0x40000000 >> (slot << 4)) | 176 | #define M8XX_PCMCIA_VS2(slot) (0x40000000 >> (slot << 4)) |
177 | #define M8XX_PCMCIA_VS_MASK(slot) (0xc0000000 >> (slot << 4)) | 177 | #define M8XX_PCMCIA_VS_MASK(slot) (0xc0000000 >> (slot << 4)) |
178 | #define M8XX_PCMCIA_VS_SHIFT(slot) (30 - (slot << 4)) | 178 | #define M8XX_PCMCIA_VS_SHIFT(slot) (30 - (slot << 4)) |
179 | 179 | ||
180 | #define M8XX_PCMCIA_WP(slot) (0x20000000 >> (slot << 4)) | 180 | #define M8XX_PCMCIA_WP(slot) (0x20000000 >> (slot << 4)) |
181 | #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4)) | 181 | #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4)) |
182 | #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4)) | 182 | #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4)) |
183 | #define M8XX_PCMCIA_BVD2(slot) (0x04000000 >> (slot << 4)) | 183 | #define M8XX_PCMCIA_BVD2(slot) (0x04000000 >> (slot << 4)) |
184 | #define M8XX_PCMCIA_BVD1(slot) (0x02000000 >> (slot << 4)) | 184 | #define M8XX_PCMCIA_BVD1(slot) (0x02000000 >> (slot << 4)) |
185 | #define M8XX_PCMCIA_RDY(slot) (0x01000000 >> (slot << 4)) | 185 | #define M8XX_PCMCIA_RDY(slot) (0x01000000 >> (slot << 4)) |
186 | #define M8XX_PCMCIA_RDY_L(slot) (0x00800000 >> (slot << 4)) | 186 | #define M8XX_PCMCIA_RDY_L(slot) (0x00800000 >> (slot << 4)) |
187 | #define M8XX_PCMCIA_RDY_H(slot) (0x00400000 >> (slot << 4)) | 187 | #define M8XX_PCMCIA_RDY_H(slot) (0x00400000 >> (slot << 4)) |
188 | #define M8XX_PCMCIA_RDY_R(slot) (0x00200000 >> (slot << 4)) | 188 | #define M8XX_PCMCIA_RDY_R(slot) (0x00200000 >> (slot << 4)) |
189 | #define M8XX_PCMCIA_RDY_F(slot) (0x00100000 >> (slot << 4)) | 189 | #define M8XX_PCMCIA_RDY_F(slot) (0x00100000 >> (slot << 4)) |
190 | #define M8XX_PCMCIA_MASK(slot) (0xFFFF0000 >> (slot << 4)) | 190 | #define M8XX_PCMCIA_MASK(slot) (0xFFFF0000 >> (slot << 4)) |
191 | 191 | ||
192 | #define M8XX_PCMCIA_POR_VALID 0x00000001 | 192 | #define M8XX_PCMCIA_POR_VALID 0x00000001 |
193 | #define M8XX_PCMCIA_POR_WRPROT 0x00000002 | 193 | #define M8XX_PCMCIA_POR_WRPROT 0x00000002 |
194 | #define M8XX_PCMCIA_POR_ATTRMEM 0x00000010 | 194 | #define M8XX_PCMCIA_POR_ATTRMEM 0x00000010 |
195 | #define M8XX_PCMCIA_POR_IO 0x00000018 | 195 | #define M8XX_PCMCIA_POR_IO 0x00000018 |
196 | #define M8XX_PCMCIA_POR_16BIT 0x00000040 | 196 | #define M8XX_PCMCIA_POR_16BIT 0x00000040 |
197 | 197 | ||
198 | #define M8XX_PGCRX(slot) m8xx_pgcrx[slot] | 198 | #define M8XX_PGCRX(slot) m8xx_pgcrx[slot] |
199 | 199 | ||
200 | #define M8XX_PGCRX_CXOE 0x00000080 | 200 | #define M8XX_PGCRX_CXOE 0x00000080 |
201 | #define M8XX_PGCRX_CXRESET 0x00000040 | 201 | #define M8XX_PGCRX_CXRESET 0x00000040 |
202 | 202 | ||
203 | /* we keep one lookup table per socket to check flags */ | 203 | /* we keep one lookup table per socket to check flags */ |
204 | 204 | ||
205 | #define PCMCIA_EVENTS_MAX 5 /* 4 max at a time + termination */ | 205 | #define PCMCIA_EVENTS_MAX 5 /* 4 max at a time + termination */ |
206 | 206 | ||
207 | struct event_table { | 207 | struct event_table { |
208 | u32 regbit; | 208 | u32 regbit; |
209 | u32 eventbit; | 209 | u32 eventbit; |
210 | }; | 210 | }; |
211 | 211 | ||
212 | static const char driver_name[] = "m8xx-pcmcia"; | 212 | static const char driver_name[] = "m8xx-pcmcia"; |
213 | 213 | ||
214 | struct socket_info { | 214 | struct socket_info { |
215 | void (*handler) (void *info, u32 events); | 215 | void (*handler) (void *info, u32 events); |
216 | void *info; | 216 | void *info; |
217 | 217 | ||
218 | u32 slot; | 218 | u32 slot; |
219 | pcmconf8xx_t *pcmcia; | 219 | pcmconf8xx_t *pcmcia; |
220 | u32 bus_freq; | 220 | u32 bus_freq; |
221 | int hwirq; | 221 | int hwirq; |
222 | 222 | ||
223 | socket_state_t state; | 223 | socket_state_t state; |
224 | struct pccard_mem_map mem_win[PCMCIA_MEM_WIN_NO]; | 224 | struct pccard_mem_map mem_win[PCMCIA_MEM_WIN_NO]; |
225 | struct pccard_io_map io_win[PCMCIA_IO_WIN_NO]; | 225 | struct pccard_io_map io_win[PCMCIA_IO_WIN_NO]; |
226 | struct event_table events[PCMCIA_EVENTS_MAX]; | 226 | struct event_table events[PCMCIA_EVENTS_MAX]; |
227 | struct pcmcia_socket socket; | 227 | struct pcmcia_socket socket; |
228 | }; | 228 | }; |
229 | 229 | ||
230 | static struct socket_info socket[PCMCIA_SOCKETS_NO]; | 230 | static struct socket_info socket[PCMCIA_SOCKETS_NO]; |
231 | 231 | ||
232 | /* | 232 | /* |
233 | * Search this table to see if the windowsize is | 233 | * Search this table to see if the windowsize is |
234 | * supported... | 234 | * supported... |
235 | */ | 235 | */ |
236 | 236 | ||
237 | #define M8XX_SIZES_NO 32 | 237 | #define M8XX_SIZES_NO 32 |
238 | 238 | ||
239 | static const u32 m8xx_size_to_gray[M8XX_SIZES_NO] = { | 239 | static const u32 m8xx_size_to_gray[M8XX_SIZES_NO] = { |
240 | 0x00000001, 0x00000002, 0x00000008, 0x00000004, | 240 | 0x00000001, 0x00000002, 0x00000008, 0x00000004, |
241 | 0x00000080, 0x00000040, 0x00000010, 0x00000020, | 241 | 0x00000080, 0x00000040, 0x00000010, 0x00000020, |
242 | 0x00008000, 0x00004000, 0x00001000, 0x00002000, | 242 | 0x00008000, 0x00004000, 0x00001000, 0x00002000, |
243 | 0x00000100, 0x00000200, 0x00000800, 0x00000400, | 243 | 0x00000100, 0x00000200, 0x00000800, 0x00000400, |
244 | 244 | ||
245 | 0x0fffffff, 0xffffffff, 0xffffffff, 0xffffffff, | 245 | 0x0fffffff, 0xffffffff, 0xffffffff, 0xffffffff, |
246 | 0x01000000, 0x02000000, 0xffffffff, 0x04000000, | 246 | 0x01000000, 0x02000000, 0xffffffff, 0x04000000, |
247 | 0x00010000, 0x00020000, 0x00080000, 0x00040000, | 247 | 0x00010000, 0x00020000, 0x00080000, 0x00040000, |
248 | 0x00800000, 0x00400000, 0x00100000, 0x00200000 | 248 | 0x00800000, 0x00400000, 0x00100000, 0x00200000 |
249 | }; | 249 | }; |
250 | 250 | ||
251 | /* ------------------------------------------------------------------------- */ | 251 | /* ------------------------------------------------------------------------- */ |
252 | 252 | ||
253 | static irqreturn_t m8xx_interrupt(int irq, void *dev); | 253 | static irqreturn_t m8xx_interrupt(int irq, void *dev); |
254 | 254 | ||
255 | #define PCMCIA_BMT_LIMIT (15*4) /* Bus Monitor Timeout value */ | 255 | #define PCMCIA_BMT_LIMIT (15*4) /* Bus Monitor Timeout value */ |
256 | 256 | ||
257 | /* ------------------------------------------------------------------------- */ | 257 | /* ------------------------------------------------------------------------- */ |
258 | /* board specific stuff: */ | 258 | /* board specific stuff: */ |
259 | /* voltage_set(), hardware_enable() and hardware_disable() */ | 259 | /* voltage_set(), hardware_enable() and hardware_disable() */ |
260 | /* ------------------------------------------------------------------------- */ | 260 | /* ------------------------------------------------------------------------- */ |
261 | /* RPX Boards from Embedded Planet */ | 261 | /* RPX Boards from Embedded Planet */ |
262 | 262 | ||
263 | #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE) | 263 | #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_RPXLITE) |
264 | 264 | ||
265 | /* The RPX boards seems to have it's bus monitor timeout set to 6*8 clocks. | 265 | /* The RPX boards seems to have it's bus monitor timeout set to 6*8 clocks. |
266 | * SYPCR is write once only, therefore must the slowest memory be faster | 266 | * SYPCR is write once only, therefore must the slowest memory be faster |
267 | * than the bus monitor or we will get a machine check due to the bus timeout. | 267 | * than the bus monitor or we will get a machine check due to the bus timeout. |
268 | */ | 268 | */ |
269 | 269 | ||
270 | #define PCMCIA_BOARD_MSG "RPX CLASSIC or RPX LITE" | 270 | #define PCMCIA_BOARD_MSG "RPX CLASSIC or RPX LITE" |
271 | 271 | ||
272 | #undef PCMCIA_BMT_LIMIT | 272 | #undef PCMCIA_BMT_LIMIT |
273 | #define PCMCIA_BMT_LIMIT (6*8) | 273 | #define PCMCIA_BMT_LIMIT (6*8) |
274 | 274 | ||
275 | static int voltage_set(int slot, int vcc, int vpp) | 275 | static int voltage_set(int slot, int vcc, int vpp) |
276 | { | 276 | { |
277 | u32 reg = 0; | 277 | u32 reg = 0; |
278 | 278 | ||
279 | switch (vcc) { | 279 | switch (vcc) { |
280 | case 0: | 280 | case 0: |
281 | break; | 281 | break; |
282 | case 33: | 282 | case 33: |
283 | reg |= BCSR1_PCVCTL4; | 283 | reg |= BCSR1_PCVCTL4; |
284 | break; | 284 | break; |
285 | case 50: | 285 | case 50: |
286 | reg |= BCSR1_PCVCTL5; | 286 | reg |= BCSR1_PCVCTL5; |
287 | break; | 287 | break; |
288 | default: | 288 | default: |
289 | return 1; | 289 | return 1; |
290 | } | 290 | } |
291 | 291 | ||
292 | switch (vpp) { | 292 | switch (vpp) { |
293 | case 0: | 293 | case 0: |
294 | break; | 294 | break; |
295 | case 33: | 295 | case 33: |
296 | case 50: | 296 | case 50: |
297 | if (vcc == vpp) | 297 | if (vcc == vpp) |
298 | reg |= BCSR1_PCVCTL6; | 298 | reg |= BCSR1_PCVCTL6; |
299 | else | 299 | else |
300 | return 1; | 300 | return 1; |
301 | break; | 301 | break; |
302 | case 120: | 302 | case 120: |
303 | reg |= BCSR1_PCVCTL7; | 303 | reg |= BCSR1_PCVCTL7; |
304 | default: | 304 | default: |
305 | return 1; | 305 | return 1; |
306 | } | 306 | } |
307 | 307 | ||
308 | if (!((vcc == 50) || (vcc == 0))) | 308 | if (!((vcc == 50) || (vcc == 0))) |
309 | return 1; | 309 | return 1; |
310 | 310 | ||
311 | /* first, turn off all power */ | 311 | /* first, turn off all power */ |
312 | 312 | ||
313 | out_be32(((u32 *) RPX_CSR_ADDR), | 313 | out_be32(((u32 *) RPX_CSR_ADDR), |
314 | in_be32(((u32 *) RPX_CSR_ADDR)) & ~(BCSR1_PCVCTL4 | | 314 | in_be32(((u32 *) RPX_CSR_ADDR)) & ~(BCSR1_PCVCTL4 | |
315 | BCSR1_PCVCTL5 | | 315 | BCSR1_PCVCTL5 | |
316 | BCSR1_PCVCTL6 | | 316 | BCSR1_PCVCTL6 | |
317 | BCSR1_PCVCTL7)); | 317 | BCSR1_PCVCTL7)); |
318 | 318 | ||
319 | /* enable new powersettings */ | 319 | /* enable new powersettings */ |
320 | 320 | ||
321 | out_be32(((u32 *) RPX_CSR_ADDR), in_be32(((u32 *) RPX_CSR_ADDR)) | reg); | 321 | out_be32(((u32 *) RPX_CSR_ADDR), in_be32(((u32 *) RPX_CSR_ADDR)) | reg); |
322 | 322 | ||
323 | return 0; | 323 | return 0; |
324 | } | 324 | } |
325 | 325 | ||
326 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V | 326 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V |
327 | #define hardware_enable(_slot_) /* No hardware to enable */ | 327 | #define hardware_enable(_slot_) /* No hardware to enable */ |
328 | #define hardware_disable(_slot_) /* No hardware to disable */ | 328 | #define hardware_disable(_slot_) /* No hardware to disable */ |
329 | 329 | ||
330 | #endif /* CONFIG_RPXCLASSIC */ | 330 | #endif /* CONFIG_RPXCLASSIC */ |
331 | 331 | ||
332 | /* FADS Boards from Motorola */ | 332 | /* FADS Boards from Motorola */ |
333 | 333 | ||
334 | #if defined(CONFIG_FADS) | 334 | #if defined(CONFIG_FADS) |
335 | 335 | ||
336 | #define PCMCIA_BOARD_MSG "FADS" | 336 | #define PCMCIA_BOARD_MSG "FADS" |
337 | 337 | ||
338 | static int voltage_set(int slot, int vcc, int vpp) | 338 | static int voltage_set(int slot, int vcc, int vpp) |
339 | { | 339 | { |
340 | u32 reg = 0; | 340 | u32 reg = 0; |
341 | 341 | ||
342 | switch (vcc) { | 342 | switch (vcc) { |
343 | case 0: | 343 | case 0: |
344 | break; | 344 | break; |
345 | case 33: | 345 | case 33: |
346 | reg |= BCSR1_PCCVCC0; | 346 | reg |= BCSR1_PCCVCC0; |
347 | break; | 347 | break; |
348 | case 50: | 348 | case 50: |
349 | reg |= BCSR1_PCCVCC1; | 349 | reg |= BCSR1_PCCVCC1; |
350 | break; | 350 | break; |
351 | default: | 351 | default: |
352 | return 1; | 352 | return 1; |
353 | } | 353 | } |
354 | 354 | ||
355 | switch (vpp) { | 355 | switch (vpp) { |
356 | case 0: | 356 | case 0: |
357 | break; | 357 | break; |
358 | case 33: | 358 | case 33: |
359 | case 50: | 359 | case 50: |
360 | if (vcc == vpp) | 360 | if (vcc == vpp) |
361 | reg |= BCSR1_PCCVPP1; | 361 | reg |= BCSR1_PCCVPP1; |
362 | else | 362 | else |
363 | return 1; | 363 | return 1; |
364 | break; | 364 | break; |
365 | case 120: | 365 | case 120: |
366 | if ((vcc == 33) || (vcc == 50)) | 366 | if ((vcc == 33) || (vcc == 50)) |
367 | reg |= BCSR1_PCCVPP0; | 367 | reg |= BCSR1_PCCVPP0; |
368 | else | 368 | else |
369 | return 1; | 369 | return 1; |
370 | default: | 370 | default: |
371 | return 1; | 371 | return 1; |
372 | } | 372 | } |
373 | 373 | ||
374 | /* first, turn off all power */ | 374 | /* first, turn off all power */ |
375 | out_be32((u32 *) BCSR1, | 375 | out_be32((u32 *) BCSR1, |
376 | in_be32((u32 *) BCSR1) & ~(BCSR1_PCCVCC_MASK | | 376 | in_be32((u32 *) BCSR1) & ~(BCSR1_PCCVCC_MASK | |
377 | BCSR1_PCCVPP_MASK)); | 377 | BCSR1_PCCVPP_MASK)); |
378 | 378 | ||
379 | /* enable new powersettings */ | 379 | /* enable new powersettings */ |
380 | out_be32((u32 *) BCSR1, in_be32((u32 *) BCSR1) | reg); | 380 | out_be32((u32 *) BCSR1, in_be32((u32 *) BCSR1) | reg); |
381 | 381 | ||
382 | return 0; | 382 | return 0; |
383 | } | 383 | } |
384 | 384 | ||
385 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V | 385 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V |
386 | 386 | ||
387 | static void hardware_enable(int slot) | 387 | static void hardware_enable(int slot) |
388 | { | 388 | { |
389 | out_be32((u32 *) BCSR1, in_be32((u32 *) BCSR1) & ~BCSR1_PCCEN); | 389 | out_be32((u32 *) BCSR1, in_be32((u32 *) BCSR1) & ~BCSR1_PCCEN); |
390 | } | 390 | } |
391 | 391 | ||
392 | static void hardware_disable(int slot) | 392 | static void hardware_disable(int slot) |
393 | { | 393 | { |
394 | out_be32((u32 *) BCSR1, in_be32((u32 *) BCSR1) | BCSR1_PCCEN); | 394 | out_be32((u32 *) BCSR1, in_be32((u32 *) BCSR1) | BCSR1_PCCEN); |
395 | } | 395 | } |
396 | 396 | ||
397 | #endif | 397 | #endif |
398 | 398 | ||
399 | /* MPC885ADS Boards */ | 399 | /* MPC885ADS Boards */ |
400 | 400 | ||
401 | #if defined(CONFIG_MPC885ADS) | 401 | #if defined(CONFIG_MPC885ADS) |
402 | 402 | ||
403 | #define PCMCIA_BOARD_MSG "MPC885ADS" | 403 | #define PCMCIA_BOARD_MSG "MPC885ADS" |
404 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V | 404 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V |
405 | 405 | ||
406 | static inline void hardware_enable(int slot) | 406 | static inline void hardware_enable(int slot) |
407 | { | 407 | { |
408 | m8xx_pcmcia_ops.hw_ctrl(slot, 1); | 408 | m8xx_pcmcia_ops.hw_ctrl(slot, 1); |
409 | } | 409 | } |
410 | 410 | ||
411 | static inline void hardware_disable(int slot) | 411 | static inline void hardware_disable(int slot) |
412 | { | 412 | { |
413 | m8xx_pcmcia_ops.hw_ctrl(slot, 0); | 413 | m8xx_pcmcia_ops.hw_ctrl(slot, 0); |
414 | } | 414 | } |
415 | 415 | ||
416 | static inline int voltage_set(int slot, int vcc, int vpp) | 416 | static inline int voltage_set(int slot, int vcc, int vpp) |
417 | { | 417 | { |
418 | return m8xx_pcmcia_ops.voltage_set(slot, vcc, vpp); | 418 | return m8xx_pcmcia_ops.voltage_set(slot, vcc, vpp); |
419 | } | 419 | } |
420 | 420 | ||
421 | #endif | 421 | #endif |
422 | 422 | ||
423 | /* ------------------------------------------------------------------------- */ | 423 | /* ------------------------------------------------------------------------- */ |
424 | /* Motorola MBX860 */ | 424 | /* Motorola MBX860 */ |
425 | 425 | ||
426 | #if defined(CONFIG_MBX) | 426 | #if defined(CONFIG_MBX) |
427 | 427 | ||
428 | #define PCMCIA_BOARD_MSG "MBX" | 428 | #define PCMCIA_BOARD_MSG "MBX" |
429 | 429 | ||
430 | static int voltage_set(int slot, int vcc, int vpp) | 430 | static int voltage_set(int slot, int vcc, int vpp) |
431 | { | 431 | { |
432 | u8 reg = 0; | 432 | u8 reg = 0; |
433 | 433 | ||
434 | switch (vcc) { | 434 | switch (vcc) { |
435 | case 0: | 435 | case 0: |
436 | break; | 436 | break; |
437 | case 33: | 437 | case 33: |
438 | reg |= CSR2_VCC_33; | 438 | reg |= CSR2_VCC_33; |
439 | break; | 439 | break; |
440 | case 50: | 440 | case 50: |
441 | reg |= CSR2_VCC_50; | 441 | reg |= CSR2_VCC_50; |
442 | break; | 442 | break; |
443 | default: | 443 | default: |
444 | return 1; | 444 | return 1; |
445 | } | 445 | } |
446 | 446 | ||
447 | switch (vpp) { | 447 | switch (vpp) { |
448 | case 0: | 448 | case 0: |
449 | break; | 449 | break; |
450 | case 33: | 450 | case 33: |
451 | case 50: | 451 | case 50: |
452 | if (vcc == vpp) | 452 | if (vcc == vpp) |
453 | reg |= CSR2_VPP_VCC; | 453 | reg |= CSR2_VPP_VCC; |
454 | else | 454 | else |
455 | return 1; | 455 | return 1; |
456 | break; | 456 | break; |
457 | case 120: | 457 | case 120: |
458 | if ((vcc == 33) || (vcc == 50)) | 458 | if ((vcc == 33) || (vcc == 50)) |
459 | reg |= CSR2_VPP_12; | 459 | reg |= CSR2_VPP_12; |
460 | else | 460 | else |
461 | return 1; | 461 | return 1; |
462 | default: | 462 | default: |
463 | return 1; | 463 | return 1; |
464 | } | 464 | } |
465 | 465 | ||
466 | /* first, turn off all power */ | 466 | /* first, turn off all power */ |
467 | out_8((u8 *) MBX_CSR2_ADDR, | 467 | out_8((u8 *) MBX_CSR2_ADDR, |
468 | in_8((u8 *) MBX_CSR2_ADDR) & ~(CSR2_VCC_MASK | CSR2_VPP_MASK)); | 468 | in_8((u8 *) MBX_CSR2_ADDR) & ~(CSR2_VCC_MASK | CSR2_VPP_MASK)); |
469 | 469 | ||
470 | /* enable new powersettings */ | 470 | /* enable new powersettings */ |
471 | out_8((u8 *) MBX_CSR2_ADDR, in_8((u8 *) MBX_CSR2_ADDR) | reg); | 471 | out_8((u8 *) MBX_CSR2_ADDR, in_8((u8 *) MBX_CSR2_ADDR) | reg); |
472 | 472 | ||
473 | return 0; | 473 | return 0; |
474 | } | 474 | } |
475 | 475 | ||
476 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V | 476 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_5V |
477 | #define hardware_enable(_slot_) /* No hardware to enable */ | 477 | #define hardware_enable(_slot_) /* No hardware to enable */ |
478 | #define hardware_disable(_slot_) /* No hardware to disable */ | 478 | #define hardware_disable(_slot_) /* No hardware to disable */ |
479 | 479 | ||
480 | #endif /* CONFIG_MBX */ | 480 | #endif /* CONFIG_MBX */ |
481 | 481 | ||
482 | #if defined(CONFIG_PRxK) | 482 | #if defined(CONFIG_PRxK) |
483 | #include <asm/cpld.h> | 483 | #include <asm/cpld.h> |
484 | extern volatile fpga_pc_regs *fpga_pc; | 484 | extern volatile fpga_pc_regs *fpga_pc; |
485 | 485 | ||
486 | #define PCMCIA_BOARD_MSG "MPC855T" | 486 | #define PCMCIA_BOARD_MSG "MPC855T" |
487 | 487 | ||
488 | static int voltage_set(int slot, int vcc, int vpp) | 488 | static int voltage_set(int slot, int vcc, int vpp) |
489 | { | 489 | { |
490 | u8 reg = 0; | 490 | u8 reg = 0; |
491 | u8 regread; | 491 | u8 regread; |
492 | cpld_regs *ccpld = get_cpld(); | 492 | cpld_regs *ccpld = get_cpld(); |
493 | 493 | ||
494 | switch (vcc) { | 494 | switch (vcc) { |
495 | case 0: | 495 | case 0: |
496 | break; | 496 | break; |
497 | case 33: | 497 | case 33: |
498 | reg |= PCMCIA_VCC_33; | 498 | reg |= PCMCIA_VCC_33; |
499 | break; | 499 | break; |
500 | case 50: | 500 | case 50: |
501 | reg |= PCMCIA_VCC_50; | 501 | reg |= PCMCIA_VCC_50; |
502 | break; | 502 | break; |
503 | default: | 503 | default: |
504 | return 1; | 504 | return 1; |
505 | } | 505 | } |
506 | 506 | ||
507 | switch (vpp) { | 507 | switch (vpp) { |
508 | case 0: | 508 | case 0: |
509 | break; | 509 | break; |
510 | case 33: | 510 | case 33: |
511 | case 50: | 511 | case 50: |
512 | if (vcc == vpp) | 512 | if (vcc == vpp) |
513 | reg |= PCMCIA_VPP_VCC; | 513 | reg |= PCMCIA_VPP_VCC; |
514 | else | 514 | else |
515 | return 1; | 515 | return 1; |
516 | break; | 516 | break; |
517 | case 120: | 517 | case 120: |
518 | if ((vcc == 33) || (vcc == 50)) | 518 | if ((vcc == 33) || (vcc == 50)) |
519 | reg |= PCMCIA_VPP_12; | 519 | reg |= PCMCIA_VPP_12; |
520 | else | 520 | else |
521 | return 1; | 521 | return 1; |
522 | default: | 522 | default: |
523 | return 1; | 523 | return 1; |
524 | } | 524 | } |
525 | 525 | ||
526 | reg = reg >> (slot << 2); | 526 | reg = reg >> (slot << 2); |
527 | regread = in_8(&ccpld->fpga_pc_ctl); | 527 | regread = in_8(&ccpld->fpga_pc_ctl); |
528 | if (reg != | 528 | if (reg != |
529 | (regread & ((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> (slot << 2)))) { | 529 | (regread & ((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> (slot << 2)))) { |
530 | /* enable new powersettings */ | 530 | /* enable new powersettings */ |
531 | regread = | 531 | regread = |
532 | regread & ~((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> | 532 | regread & ~((PCMCIA_VCC_MASK | PCMCIA_VPP_MASK) >> |
533 | (slot << 2)); | 533 | (slot << 2)); |
534 | out_8(&ccpld->fpga_pc_ctl, reg | regread); | 534 | out_8(&ccpld->fpga_pc_ctl, reg | regread); |
535 | msleep(100); | 535 | msleep(100); |
536 | } | 536 | } |
537 | 537 | ||
538 | return 0; | 538 | return 0; |
539 | } | 539 | } |
540 | 540 | ||
541 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_LV | 541 | #define socket_get(_slot_) PCMCIA_SOCKET_KEY_LV |
542 | #define hardware_enable(_slot_) /* No hardware to enable */ | 542 | #define hardware_enable(_slot_) /* No hardware to enable */ |
543 | #define hardware_disable(_slot_) /* No hardware to disable */ | 543 | #define hardware_disable(_slot_) /* No hardware to disable */ |
544 | 544 | ||
545 | #endif /* CONFIG_PRxK */ | 545 | #endif /* CONFIG_PRxK */ |
546 | 546 | ||
547 | static u32 pending_events[PCMCIA_SOCKETS_NO]; | 547 | static u32 pending_events[PCMCIA_SOCKETS_NO]; |
548 | static DEFINE_SPINLOCK(pending_event_lock); | 548 | static DEFINE_SPINLOCK(pending_event_lock); |
549 | 549 | ||
550 | static irqreturn_t m8xx_interrupt(int irq, void *dev) | 550 | static irqreturn_t m8xx_interrupt(int irq, void *dev) |
551 | { | 551 | { |
552 | struct socket_info *s; | 552 | struct socket_info *s; |
553 | struct event_table *e; | 553 | struct event_table *e; |
554 | unsigned int i, events, pscr, pipr, per; | 554 | unsigned int i, events, pscr, pipr, per; |
555 | pcmconf8xx_t *pcmcia = socket[0].pcmcia; | 555 | pcmconf8xx_t *pcmcia = socket[0].pcmcia; |
556 | 556 | ||
557 | pr_debug("m8xx_pcmcia: Interrupt!\n"); | 557 | pr_debug("m8xx_pcmcia: Interrupt!\n"); |
558 | /* get interrupt sources */ | 558 | /* get interrupt sources */ |
559 | 559 | ||
560 | pscr = in_be32(&pcmcia->pcmc_pscr); | 560 | pscr = in_be32(&pcmcia->pcmc_pscr); |
561 | pipr = in_be32(&pcmcia->pcmc_pipr); | 561 | pipr = in_be32(&pcmcia->pcmc_pipr); |
562 | per = in_be32(&pcmcia->pcmc_per); | 562 | per = in_be32(&pcmcia->pcmc_per); |
563 | 563 | ||
564 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { | 564 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { |
565 | s = &socket[i]; | 565 | s = &socket[i]; |
566 | e = &s->events[0]; | 566 | e = &s->events[0]; |
567 | events = 0; | 567 | events = 0; |
568 | 568 | ||
569 | while (e->regbit) { | 569 | while (e->regbit) { |
570 | if (pscr & e->regbit) | 570 | if (pscr & e->regbit) |
571 | events |= e->eventbit; | 571 | events |= e->eventbit; |
572 | 572 | ||
573 | e++; | 573 | e++; |
574 | } | 574 | } |
575 | 575 | ||
576 | /* | 576 | /* |
577 | * report only if both card detect signals are the same | 577 | * report only if both card detect signals are the same |
578 | * not too nice done, | 578 | * not too nice done, |
579 | * we depend on that CD2 is the bit to the left of CD1... | 579 | * we depend on that CD2 is the bit to the left of CD1... |
580 | */ | 580 | */ |
581 | if (events & SS_DETECT) | 581 | if (events & SS_DETECT) |
582 | if (((pipr & M8XX_PCMCIA_CD2(i)) >> 1) ^ | 582 | if (((pipr & M8XX_PCMCIA_CD2(i)) >> 1) ^ |
583 | (pipr & M8XX_PCMCIA_CD1(i))) { | 583 | (pipr & M8XX_PCMCIA_CD1(i))) { |
584 | events &= ~SS_DETECT; | 584 | events &= ~SS_DETECT; |
585 | } | 585 | } |
586 | #ifdef PCMCIA_GLITCHY_CD | 586 | #ifdef PCMCIA_GLITCHY_CD |
587 | /* | 587 | /* |
588 | * I've experienced CD problems with my ADS board. | 588 | * I've experienced CD problems with my ADS board. |
589 | * We make an extra check to see if there was a | 589 | * We make an extra check to see if there was a |
590 | * real change of Card detection. | 590 | * real change of Card detection. |
591 | */ | 591 | */ |
592 | 592 | ||
593 | if ((events & SS_DETECT) && | 593 | if ((events & SS_DETECT) && |
594 | ((pipr & | 594 | ((pipr & |
595 | (M8XX_PCMCIA_CD2(i) | M8XX_PCMCIA_CD1(i))) == 0) && | 595 | (M8XX_PCMCIA_CD2(i) | M8XX_PCMCIA_CD1(i))) == 0) && |
596 | (s->state.Vcc | s->state.Vpp)) { | 596 | (s->state.Vcc | s->state.Vpp)) { |
597 | events &= ~SS_DETECT; | 597 | events &= ~SS_DETECT; |
598 | /*printk( "CD glitch workaround - CD = 0x%08x!\n", | 598 | /*printk( "CD glitch workaround - CD = 0x%08x!\n", |
599 | (pipr & (M8XX_PCMCIA_CD2(i) | 599 | (pipr & (M8XX_PCMCIA_CD2(i) |
600 | | M8XX_PCMCIA_CD1(i)))); */ | 600 | | M8XX_PCMCIA_CD1(i)))); */ |
601 | } | 601 | } |
602 | #endif | 602 | #endif |
603 | 603 | ||
604 | /* call the handler */ | 604 | /* call the handler */ |
605 | 605 | ||
606 | pr_debug("m8xx_pcmcia: slot %u: events = 0x%02x, pscr = 0x%08x, " | 606 | pr_debug("m8xx_pcmcia: slot %u: events = 0x%02x, pscr = 0x%08x, " |
607 | "pipr = 0x%08x\n", i, events, pscr, pipr); | 607 | "pipr = 0x%08x\n", i, events, pscr, pipr); |
608 | 608 | ||
609 | if (events) { | 609 | if (events) { |
610 | spin_lock(&pending_event_lock); | 610 | spin_lock(&pending_event_lock); |
611 | pending_events[i] |= events; | 611 | pending_events[i] |= events; |
612 | spin_unlock(&pending_event_lock); | 612 | spin_unlock(&pending_event_lock); |
613 | /* | 613 | /* |
614 | * Turn off RDY_L bits in the PER mask on | 614 | * Turn off RDY_L bits in the PER mask on |
615 | * CD interrupt receival. | 615 | * CD interrupt receival. |
616 | * | 616 | * |
617 | * They can generate bad interrupts on the | 617 | * They can generate bad interrupts on the |
618 | * ACS4,8,16,32. - marcelo | 618 | * ACS4,8,16,32. - marcelo |
619 | */ | 619 | */ |
620 | per &= ~M8XX_PCMCIA_RDY_L(0); | 620 | per &= ~M8XX_PCMCIA_RDY_L(0); |
621 | per &= ~M8XX_PCMCIA_RDY_L(1); | 621 | per &= ~M8XX_PCMCIA_RDY_L(1); |
622 | 622 | ||
623 | out_be32(&pcmcia->pcmc_per, per); | 623 | out_be32(&pcmcia->pcmc_per, per); |
624 | 624 | ||
625 | if (events) | 625 | if (events) |
626 | pcmcia_parse_events(&socket[i].socket, events); | 626 | pcmcia_parse_events(&socket[i].socket, events); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | 629 | ||
630 | /* clear the interrupt sources */ | 630 | /* clear the interrupt sources */ |
631 | out_be32(&pcmcia->pcmc_pscr, pscr); | 631 | out_be32(&pcmcia->pcmc_pscr, pscr); |
632 | 632 | ||
633 | pr_debug("m8xx_pcmcia: Interrupt done.\n"); | 633 | pr_debug("m8xx_pcmcia: Interrupt done.\n"); |
634 | 634 | ||
635 | return IRQ_HANDLED; | 635 | return IRQ_HANDLED; |
636 | } | 636 | } |
637 | 637 | ||
638 | static u32 m8xx_get_graycode(u32 size) | 638 | static u32 m8xx_get_graycode(u32 size) |
639 | { | 639 | { |
640 | u32 k; | 640 | u32 k; |
641 | 641 | ||
642 | for (k = 0; k < M8XX_SIZES_NO; k++) | 642 | for (k = 0; k < M8XX_SIZES_NO; k++) |
643 | if (m8xx_size_to_gray[k] == size) | 643 | if (m8xx_size_to_gray[k] == size) |
644 | break; | 644 | break; |
645 | 645 | ||
646 | if ((k == M8XX_SIZES_NO) || (m8xx_size_to_gray[k] == -1)) | 646 | if ((k == M8XX_SIZES_NO) || (m8xx_size_to_gray[k] == -1)) |
647 | k = -1; | 647 | k = -1; |
648 | 648 | ||
649 | return k; | 649 | return k; |
650 | } | 650 | } |
651 | 651 | ||
652 | static u32 m8xx_get_speed(u32 ns, u32 is_io, u32 bus_freq) | 652 | static u32 m8xx_get_speed(u32 ns, u32 is_io, u32 bus_freq) |
653 | { | 653 | { |
654 | u32 reg, clocks, psst, psl, psht; | 654 | u32 reg, clocks, psst, psl, psht; |
655 | 655 | ||
656 | if (!ns) { | 656 | if (!ns) { |
657 | 657 | ||
658 | /* | 658 | /* |
659 | * We get called with IO maps setup to 0ns | 659 | * We get called with IO maps setup to 0ns |
660 | * if not specified by the user. | 660 | * if not specified by the user. |
661 | * They should be 255ns. | 661 | * They should be 255ns. |
662 | */ | 662 | */ |
663 | 663 | ||
664 | if (is_io) | 664 | if (is_io) |
665 | ns = 255; | 665 | ns = 255; |
666 | else | 666 | else |
667 | ns = 100; /* fast memory if 0 */ | 667 | ns = 100; /* fast memory if 0 */ |
668 | } | 668 | } |
669 | 669 | ||
670 | /* | 670 | /* |
671 | * In PSST, PSL, PSHT fields we tell the controller | 671 | * In PSST, PSL, PSHT fields we tell the controller |
672 | * timing parameters in CLKOUT clock cycles. | 672 | * timing parameters in CLKOUT clock cycles. |
673 | * CLKOUT is the same as GCLK2_50. | 673 | * CLKOUT is the same as GCLK2_50. |
674 | */ | 674 | */ |
675 | 675 | ||
676 | /* how we want to adjust the timing - in percent */ | 676 | /* how we want to adjust the timing - in percent */ |
677 | 677 | ||
678 | #define ADJ 180 /* 80 % longer accesstime - to be sure */ | 678 | #define ADJ 180 /* 80 % longer accesstime - to be sure */ |
679 | 679 | ||
680 | clocks = ((bus_freq / 1000) * ns) / 1000; | 680 | clocks = ((bus_freq / 1000) * ns) / 1000; |
681 | clocks = (clocks * ADJ) / (100 * 1000); | 681 | clocks = (clocks * ADJ) / (100 * 1000); |
682 | if (clocks >= PCMCIA_BMT_LIMIT) { | 682 | if (clocks >= PCMCIA_BMT_LIMIT) { |
683 | printk("Max access time limit reached\n"); | 683 | printk("Max access time limit reached\n"); |
684 | clocks = PCMCIA_BMT_LIMIT - 1; | 684 | clocks = PCMCIA_BMT_LIMIT - 1; |
685 | } | 685 | } |
686 | 686 | ||
687 | psst = clocks / 7; /* setup time */ | 687 | psst = clocks / 7; /* setup time */ |
688 | psht = clocks / 7; /* hold time */ | 688 | psht = clocks / 7; /* hold time */ |
689 | psl = (clocks * 5) / 7; /* strobe length */ | 689 | psl = (clocks * 5) / 7; /* strobe length */ |
690 | 690 | ||
691 | psst += clocks - (psst + psht + psl); | 691 | psst += clocks - (psst + psht + psl); |
692 | 692 | ||
693 | reg = psst << 12; | 693 | reg = psst << 12; |
694 | reg |= psl << 7; | 694 | reg |= psl << 7; |
695 | reg |= psht << 16; | 695 | reg |= psht << 16; |
696 | 696 | ||
697 | return reg; | 697 | return reg; |
698 | } | 698 | } |
699 | 699 | ||
700 | static int m8xx_get_status(struct pcmcia_socket *sock, unsigned int *value) | 700 | static int m8xx_get_status(struct pcmcia_socket *sock, unsigned int *value) |
701 | { | 701 | { |
702 | int lsock = container_of(sock, struct socket_info, socket)->slot; | 702 | int lsock = container_of(sock, struct socket_info, socket)->slot; |
703 | struct socket_info *s = &socket[lsock]; | 703 | struct socket_info *s = &socket[lsock]; |
704 | unsigned int pipr, reg; | 704 | unsigned int pipr, reg; |
705 | pcmconf8xx_t *pcmcia = s->pcmcia; | 705 | pcmconf8xx_t *pcmcia = s->pcmcia; |
706 | 706 | ||
707 | pipr = in_be32(&pcmcia->pcmc_pipr); | 707 | pipr = in_be32(&pcmcia->pcmc_pipr); |
708 | 708 | ||
709 | *value = ((pipr & (M8XX_PCMCIA_CD1(lsock) | 709 | *value = ((pipr & (M8XX_PCMCIA_CD1(lsock) |
710 | | M8XX_PCMCIA_CD2(lsock))) == 0) ? SS_DETECT : 0; | 710 | | M8XX_PCMCIA_CD2(lsock))) == 0) ? SS_DETECT : 0; |
711 | *value |= (pipr & M8XX_PCMCIA_WP(lsock)) ? SS_WRPROT : 0; | 711 | *value |= (pipr & M8XX_PCMCIA_WP(lsock)) ? SS_WRPROT : 0; |
712 | 712 | ||
713 | if (s->state.flags & SS_IOCARD) | 713 | if (s->state.flags & SS_IOCARD) |
714 | *value |= (pipr & M8XX_PCMCIA_BVD1(lsock)) ? SS_STSCHG : 0; | 714 | *value |= (pipr & M8XX_PCMCIA_BVD1(lsock)) ? SS_STSCHG : 0; |
715 | else { | 715 | else { |
716 | *value |= (pipr & M8XX_PCMCIA_RDY(lsock)) ? SS_READY : 0; | 716 | *value |= (pipr & M8XX_PCMCIA_RDY(lsock)) ? SS_READY : 0; |
717 | *value |= (pipr & M8XX_PCMCIA_BVD1(lsock)) ? SS_BATDEAD : 0; | 717 | *value |= (pipr & M8XX_PCMCIA_BVD1(lsock)) ? SS_BATDEAD : 0; |
718 | *value |= (pipr & M8XX_PCMCIA_BVD2(lsock)) ? SS_BATWARN : 0; | 718 | *value |= (pipr & M8XX_PCMCIA_BVD2(lsock)) ? SS_BATWARN : 0; |
719 | } | 719 | } |
720 | 720 | ||
721 | if (s->state.Vcc | s->state.Vpp) | 721 | if (s->state.Vcc | s->state.Vpp) |
722 | *value |= SS_POWERON; | 722 | *value |= SS_POWERON; |
723 | 723 | ||
724 | /* | 724 | /* |
725 | * Voltage detection: | 725 | * Voltage detection: |
726 | * This driver only supports 16-Bit pc-cards. | 726 | * This driver only supports 16-Bit pc-cards. |
727 | * Cardbus is not handled here. | 727 | * Cardbus is not handled here. |
728 | * | 728 | * |
729 | * To determine what voltage to use we must read the VS1 and VS2 pin. | 729 | * To determine what voltage to use we must read the VS1 and VS2 pin. |
730 | * Depending on what socket type is present, | 730 | * Depending on what socket type is present, |
731 | * different combinations mean different things. | 731 | * different combinations mean different things. |
732 | * | 732 | * |
733 | * Card Key Socket Key VS1 VS2 Card Vcc for CIS parse | 733 | * Card Key Socket Key VS1 VS2 Card Vcc for CIS parse |
734 | * | 734 | * |
735 | * 5V 5V, LV* NC NC 5V only 5V (if available) | 735 | * 5V 5V, LV* NC NC 5V only 5V (if available) |
736 | * | 736 | * |
737 | * 5V 5V, LV* GND NC 5 or 3.3V as low as possible | 737 | * 5V 5V, LV* GND NC 5 or 3.3V as low as possible |
738 | * | 738 | * |
739 | * 5V 5V, LV* GND GND 5, 3.3, x.xV as low as possible | 739 | * 5V 5V, LV* GND GND 5, 3.3, x.xV as low as possible |
740 | * | 740 | * |
741 | * LV* 5V - - shall not fit into socket | 741 | * LV* 5V - - shall not fit into socket |
742 | * | 742 | * |
743 | * LV* LV* GND NC 3.3V only 3.3V | 743 | * LV* LV* GND NC 3.3V only 3.3V |
744 | * | 744 | * |
745 | * LV* LV* NC GND x.xV x.xV (if avail.) | 745 | * LV* LV* NC GND x.xV x.xV (if avail.) |
746 | * | 746 | * |
747 | * LV* LV* GND GND 3.3 or x.xV as low as possible | 747 | * LV* LV* GND GND 3.3 or x.xV as low as possible |
748 | * | 748 | * |
749 | * *LV means Low Voltage | 749 | * *LV means Low Voltage |
750 | * | 750 | * |
751 | * | 751 | * |
752 | * That gives us the following table: | 752 | * That gives us the following table: |
753 | * | 753 | * |
754 | * Socket VS1 VS2 Voltage | 754 | * Socket VS1 VS2 Voltage |
755 | * | 755 | * |
756 | * 5V NC NC 5V | 756 | * 5V NC NC 5V |
757 | * 5V NC GND none (should not be possible) | 757 | * 5V NC GND none (should not be possible) |
758 | * 5V GND NC >= 3.3V | 758 | * 5V GND NC >= 3.3V |
759 | * 5V GND GND >= x.xV | 759 | * 5V GND GND >= x.xV |
760 | * | 760 | * |
761 | * LV NC NC 5V (if available) | 761 | * LV NC NC 5V (if available) |
762 | * LV NC GND x.xV (if available) | 762 | * LV NC GND x.xV (if available) |
763 | * LV GND NC 3.3V | 763 | * LV GND NC 3.3V |
764 | * LV GND GND >= x.xV | 764 | * LV GND GND >= x.xV |
765 | * | 765 | * |
766 | * So, how do I determine if I have a 5V or a LV | 766 | * So, how do I determine if I have a 5V or a LV |
767 | * socket on my board? Look at the socket! | 767 | * socket on my board? Look at the socket! |
768 | * | 768 | * |
769 | * | 769 | * |
770 | * Socket with 5V key: | 770 | * Socket with 5V key: |
771 | * ++--------------------------------------------+ | 771 | * ++--------------------------------------------+ |
772 | * || | | 772 | * || | |
773 | * || || | 773 | * || || |
774 | * || || | 774 | * || || |
775 | * | | | 775 | * | | |
776 | * +---------------------------------------------+ | 776 | * +---------------------------------------------+ |
777 | * | 777 | * |
778 | * Socket with LV key: | 778 | * Socket with LV key: |
779 | * ++--------------------------------------------+ | 779 | * ++--------------------------------------------+ |
780 | * || | | 780 | * || | |
781 | * | || | 781 | * | || |
782 | * | || | 782 | * | || |
783 | * | | | 783 | * | | |
784 | * +---------------------------------------------+ | 784 | * +---------------------------------------------+ |
785 | * | 785 | * |
786 | * | 786 | * |
787 | * With other words - LV only cards does not fit | 787 | * With other words - LV only cards does not fit |
788 | * into the 5V socket! | 788 | * into the 5V socket! |
789 | */ | 789 | */ |
790 | 790 | ||
791 | /* read out VS1 and VS2 */ | 791 | /* read out VS1 and VS2 */ |
792 | 792 | ||
793 | reg = (pipr & M8XX_PCMCIA_VS_MASK(lsock)) | 793 | reg = (pipr & M8XX_PCMCIA_VS_MASK(lsock)) |
794 | >> M8XX_PCMCIA_VS_SHIFT(lsock); | 794 | >> M8XX_PCMCIA_VS_SHIFT(lsock); |
795 | 795 | ||
796 | if (socket_get(lsock) == PCMCIA_SOCKET_KEY_LV) { | 796 | if (socket_get(lsock) == PCMCIA_SOCKET_KEY_LV) { |
797 | switch (reg) { | 797 | switch (reg) { |
798 | case 1: | 798 | case 1: |
799 | *value |= SS_3VCARD; | 799 | *value |= SS_3VCARD; |
800 | break; /* GND, NC - 3.3V only */ | 800 | break; /* GND, NC - 3.3V only */ |
801 | case 2: | 801 | case 2: |
802 | *value |= SS_XVCARD; | 802 | *value |= SS_XVCARD; |
803 | break; /* NC. GND - x.xV only */ | 803 | break; /* NC. GND - x.xV only */ |
804 | }; | 804 | }; |
805 | } | 805 | } |
806 | 806 | ||
807 | pr_debug("m8xx_pcmcia: GetStatus(%d) = %#2.2x\n", lsock, *value); | 807 | pr_debug("m8xx_pcmcia: GetStatus(%d) = %#2.2x\n", lsock, *value); |
808 | return 0; | 808 | return 0; |
809 | } | 809 | } |
810 | 810 | ||
811 | static int m8xx_set_socket(struct pcmcia_socket *sock, socket_state_t * state) | 811 | static int m8xx_set_socket(struct pcmcia_socket *sock, socket_state_t * state) |
812 | { | 812 | { |
813 | int lsock = container_of(sock, struct socket_info, socket)->slot; | 813 | int lsock = container_of(sock, struct socket_info, socket)->slot; |
814 | struct socket_info *s = &socket[lsock]; | 814 | struct socket_info *s = &socket[lsock]; |
815 | struct event_table *e; | 815 | struct event_table *e; |
816 | unsigned int reg; | 816 | unsigned int reg; |
817 | unsigned long flags; | 817 | unsigned long flags; |
818 | pcmconf8xx_t *pcmcia = socket[0].pcmcia; | 818 | pcmconf8xx_t *pcmcia = socket[0].pcmcia; |
819 | 819 | ||
820 | pr_debug("m8xx_pcmcia: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, " | 820 | pr_debug("m8xx_pcmcia: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, " |
821 | "io_irq %d, csc_mask %#2.2x)\n", lsock, state->flags, | 821 | "io_irq %d, csc_mask %#2.2x)\n", lsock, state->flags, |
822 | state->Vcc, state->Vpp, state->io_irq, state->csc_mask); | 822 | state->Vcc, state->Vpp, state->io_irq, state->csc_mask); |
823 | 823 | ||
824 | /* First, set voltage - bail out if invalid */ | 824 | /* First, set voltage - bail out if invalid */ |
825 | if (voltage_set(lsock, state->Vcc, state->Vpp)) | 825 | if (voltage_set(lsock, state->Vcc, state->Vpp)) |
826 | return -EINVAL; | 826 | return -EINVAL; |
827 | 827 | ||
828 | /* Take care of reset... */ | 828 | /* Take care of reset... */ |
829 | if (state->flags & SS_RESET) | 829 | if (state->flags & SS_RESET) |
830 | out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) | M8XX_PGCRX_CXRESET); /* active high */ | 830 | out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) | M8XX_PGCRX_CXRESET); /* active high */ |
831 | else | 831 | else |
832 | out_be32(M8XX_PGCRX(lsock), | 832 | out_be32(M8XX_PGCRX(lsock), |
833 | in_be32(M8XX_PGCRX(lsock)) & ~M8XX_PGCRX_CXRESET); | 833 | in_be32(M8XX_PGCRX(lsock)) & ~M8XX_PGCRX_CXRESET); |
834 | 834 | ||
835 | /* ... and output enable. */ | 835 | /* ... and output enable. */ |
836 | 836 | ||
837 | /* The CxOE signal is connected to a 74541 on the ADS. | 837 | /* The CxOE signal is connected to a 74541 on the ADS. |
838 | I guess most other boards used the ADS as a reference. | 838 | I guess most other boards used the ADS as a reference. |
839 | I tried to control the CxOE signal with SS_OUTPUT_ENA, | 839 | I tried to control the CxOE signal with SS_OUTPUT_ENA, |
840 | but the reset signal seems connected via the 541. | 840 | but the reset signal seems connected via the 541. |
841 | If the CxOE is left high are some signals tristated and | 841 | If the CxOE is left high are some signals tristated and |
842 | no pullups are present -> the cards act weird. | 842 | no pullups are present -> the cards act weird. |
843 | So right now the buffers are enabled if the power is on. */ | 843 | So right now the buffers are enabled if the power is on. */ |
844 | 844 | ||
845 | if (state->Vcc || state->Vpp) | 845 | if (state->Vcc || state->Vpp) |
846 | out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) & ~M8XX_PGCRX_CXOE); /* active low */ | 846 | out_be32(M8XX_PGCRX(lsock), in_be32(M8XX_PGCRX(lsock)) & ~M8XX_PGCRX_CXOE); /* active low */ |
847 | else | 847 | else |
848 | out_be32(M8XX_PGCRX(lsock), | 848 | out_be32(M8XX_PGCRX(lsock), |
849 | in_be32(M8XX_PGCRX(lsock)) | M8XX_PGCRX_CXOE); | 849 | in_be32(M8XX_PGCRX(lsock)) | M8XX_PGCRX_CXOE); |
850 | 850 | ||
851 | /* | 851 | /* |
852 | * We'd better turn off interrupts before | 852 | * We'd better turn off interrupts before |
853 | * we mess with the events-table.. | 853 | * we mess with the events-table.. |
854 | */ | 854 | */ |
855 | 855 | ||
856 | spin_lock_irqsave(&events_lock, flags); | 856 | spin_lock_irqsave(&events_lock, flags); |
857 | 857 | ||
858 | /* | 858 | /* |
859 | * Play around with the interrupt mask to be able to | 859 | * Play around with the interrupt mask to be able to |
860 | * give the events the generic pcmcia driver wants us to. | 860 | * give the events the generic pcmcia driver wants us to. |
861 | */ | 861 | */ |
862 | 862 | ||
863 | e = &s->events[0]; | 863 | e = &s->events[0]; |
864 | reg = 0; | 864 | reg = 0; |
865 | 865 | ||
866 | if (state->csc_mask & SS_DETECT) { | 866 | if (state->csc_mask & SS_DETECT) { |
867 | e->eventbit = SS_DETECT; | 867 | e->eventbit = SS_DETECT; |
868 | reg |= e->regbit = (M8XX_PCMCIA_CD2(lsock) | 868 | reg |= e->regbit = (M8XX_PCMCIA_CD2(lsock) |
869 | | M8XX_PCMCIA_CD1(lsock)); | 869 | | M8XX_PCMCIA_CD1(lsock)); |
870 | e++; | 870 | e++; |
871 | } | 871 | } |
872 | if (state->flags & SS_IOCARD) { | 872 | if (state->flags & SS_IOCARD) { |
873 | /* | 873 | /* |
874 | * I/O card | 874 | * I/O card |
875 | */ | 875 | */ |
876 | if (state->csc_mask & SS_STSCHG) { | 876 | if (state->csc_mask & SS_STSCHG) { |
877 | e->eventbit = SS_STSCHG; | 877 | e->eventbit = SS_STSCHG; |
878 | reg |= e->regbit = M8XX_PCMCIA_BVD1(lsock); | 878 | reg |= e->regbit = M8XX_PCMCIA_BVD1(lsock); |
879 | e++; | 879 | e++; |
880 | } | 880 | } |
881 | /* | 881 | /* |
882 | * If io_irq is non-zero we should enable irq. | 882 | * If io_irq is non-zero we should enable irq. |
883 | */ | 883 | */ |
884 | if (state->io_irq) { | 884 | if (state->io_irq) { |
885 | out_be32(M8XX_PGCRX(lsock), | 885 | out_be32(M8XX_PGCRX(lsock), |
886 | in_be32(M8XX_PGCRX(lsock)) | | 886 | in_be32(M8XX_PGCRX(lsock)) | |
887 | mk_int_int_mask(s->hwirq) << 24); | 887 | mk_int_int_mask(s->hwirq) << 24); |
888 | /* | 888 | /* |
889 | * Strange thing here: | 889 | * Strange thing here: |
890 | * The manual does not tell us which interrupt | 890 | * The manual does not tell us which interrupt |
891 | * the sources generate. | 891 | * the sources generate. |
892 | * Anyhow, I found out that RDY_L generates IREQLVL. | 892 | * Anyhow, I found out that RDY_L generates IREQLVL. |
893 | * | 893 | * |
894 | * We use level triggerd interrupts, and they don't | 894 | * We use level triggerd interrupts, and they don't |
895 | * have to be cleared in PSCR in the interrupt handler. | 895 | * have to be cleared in PSCR in the interrupt handler. |
896 | */ | 896 | */ |
897 | reg |= M8XX_PCMCIA_RDY_L(lsock); | 897 | reg |= M8XX_PCMCIA_RDY_L(lsock); |
898 | } else | 898 | } else |
899 | out_be32(M8XX_PGCRX(lsock), | 899 | out_be32(M8XX_PGCRX(lsock), |
900 | in_be32(M8XX_PGCRX(lsock)) & 0x00ffffff); | 900 | in_be32(M8XX_PGCRX(lsock)) & 0x00ffffff); |
901 | } else { | 901 | } else { |
902 | /* | 902 | /* |
903 | * Memory card | 903 | * Memory card |
904 | */ | 904 | */ |
905 | if (state->csc_mask & SS_BATDEAD) { | 905 | if (state->csc_mask & SS_BATDEAD) { |
906 | e->eventbit = SS_BATDEAD; | 906 | e->eventbit = SS_BATDEAD; |
907 | reg |= e->regbit = M8XX_PCMCIA_BVD1(lsock); | 907 | reg |= e->regbit = M8XX_PCMCIA_BVD1(lsock); |
908 | e++; | 908 | e++; |
909 | } | 909 | } |
910 | if (state->csc_mask & SS_BATWARN) { | 910 | if (state->csc_mask & SS_BATWARN) { |
911 | e->eventbit = SS_BATWARN; | 911 | e->eventbit = SS_BATWARN; |
912 | reg |= e->regbit = M8XX_PCMCIA_BVD2(lsock); | 912 | reg |= e->regbit = M8XX_PCMCIA_BVD2(lsock); |
913 | e++; | 913 | e++; |
914 | } | 914 | } |
915 | /* What should I trigger on - low/high,raise,fall? */ | 915 | /* What should I trigger on - low/high,raise,fall? */ |
916 | if (state->csc_mask & SS_READY) { | 916 | if (state->csc_mask & SS_READY) { |
917 | e->eventbit = SS_READY; | 917 | e->eventbit = SS_READY; |
918 | reg |= e->regbit = 0; //?? | 918 | reg |= e->regbit = 0; //?? |
919 | e++; | 919 | e++; |
920 | } | 920 | } |
921 | } | 921 | } |
922 | 922 | ||
923 | e->regbit = 0; /* terminate list */ | 923 | e->regbit = 0; /* terminate list */ |
924 | 924 | ||
925 | /* | 925 | /* |
926 | * Clear the status changed . | 926 | * Clear the status changed . |
927 | * Port A and Port B share the same port. | 927 | * Port A and Port B share the same port. |
928 | * Writing ones will clear the bits. | 928 | * Writing ones will clear the bits. |
929 | */ | 929 | */ |
930 | 930 | ||
931 | out_be32(&pcmcia->pcmc_pscr, reg); | 931 | out_be32(&pcmcia->pcmc_pscr, reg); |
932 | 932 | ||
933 | /* | 933 | /* |
934 | * Write the mask. | 934 | * Write the mask. |
935 | * Port A and Port B share the same port. | 935 | * Port A and Port B share the same port. |
936 | * Need for read-modify-write. | 936 | * Need for read-modify-write. |
937 | * Ones will enable the interrupt. | 937 | * Ones will enable the interrupt. |
938 | */ | 938 | */ |
939 | 939 | ||
940 | reg |= | 940 | reg |= |
941 | in_be32(&pcmcia-> | 941 | in_be32(&pcmcia-> |
942 | pcmc_per) & (M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1)); | 942 | pcmc_per) & (M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1)); |
943 | out_be32(&pcmcia->pcmc_per, reg); | 943 | out_be32(&pcmcia->pcmc_per, reg); |
944 | 944 | ||
945 | spin_unlock_irqrestore(&events_lock, flags); | 945 | spin_unlock_irqrestore(&events_lock, flags); |
946 | 946 | ||
947 | /* copy the struct and modify the copy */ | 947 | /* copy the struct and modify the copy */ |
948 | 948 | ||
949 | s->state = *state; | 949 | s->state = *state; |
950 | 950 | ||
951 | return 0; | 951 | return 0; |
952 | } | 952 | } |
953 | 953 | ||
954 | static int m8xx_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io) | 954 | static int m8xx_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *io) |
955 | { | 955 | { |
956 | int lsock = container_of(sock, struct socket_info, socket)->slot; | 956 | int lsock = container_of(sock, struct socket_info, socket)->slot; |
957 | 957 | ||
958 | struct socket_info *s = &socket[lsock]; | 958 | struct socket_info *s = &socket[lsock]; |
959 | struct pcmcia_win *w; | 959 | struct pcmcia_win *w; |
960 | unsigned int reg, winnr; | 960 | unsigned int reg, winnr; |
961 | pcmconf8xx_t *pcmcia = s->pcmcia; | 961 | pcmconf8xx_t *pcmcia = s->pcmcia; |
962 | 962 | ||
963 | #define M8XX_SIZE (io->stop - io->start + 1) | 963 | #define M8XX_SIZE (io->stop - io->start + 1) |
964 | #define M8XX_BASE (PCMCIA_IO_WIN_BASE + io->start) | 964 | #define M8XX_BASE (PCMCIA_IO_WIN_BASE + io->start) |
965 | 965 | ||
966 | pr_debug("m8xx_pcmcia: SetIOMap(%d, %d, %#2.2x, %d ns, " | 966 | pr_debug("m8xx_pcmcia: SetIOMap(%d, %d, %#2.2x, %d ns, " |
967 | "%#4.4llx-%#4.4llx)\n", lsock, io->map, io->flags, | 967 | "%#4.4llx-%#4.4llx)\n", lsock, io->map, io->flags, |
968 | io->speed, (unsigned long long)io->start, | 968 | io->speed, (unsigned long long)io->start, |
969 | (unsigned long long)io->stop); | 969 | (unsigned long long)io->stop); |
970 | 970 | ||
971 | if ((io->map >= PCMCIA_IO_WIN_NO) || (io->start > 0xffff) | 971 | if ((io->map >= PCMCIA_IO_WIN_NO) || (io->start > 0xffff) |
972 | || (io->stop > 0xffff) || (io->stop < io->start)) | 972 | || (io->stop > 0xffff) || (io->stop < io->start)) |
973 | return -EINVAL; | 973 | return -EINVAL; |
974 | 974 | ||
975 | if ((reg = m8xx_get_graycode(M8XX_SIZE)) == -1) | 975 | if ((reg = m8xx_get_graycode(M8XX_SIZE)) == -1) |
976 | return -EINVAL; | 976 | return -EINVAL; |
977 | 977 | ||
978 | if (io->flags & MAP_ACTIVE) { | 978 | if (io->flags & MAP_ACTIVE) { |
979 | 979 | ||
980 | pr_debug("m8xx_pcmcia: io->flags & MAP_ACTIVE\n"); | 980 | pr_debug("m8xx_pcmcia: io->flags & MAP_ACTIVE\n"); |
981 | 981 | ||
982 | winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO) | 982 | winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO) |
983 | + (lsock * PCMCIA_IO_WIN_NO) + io->map; | 983 | + (lsock * PCMCIA_IO_WIN_NO) + io->map; |
984 | 984 | ||
985 | /* setup registers */ | 985 | /* setup registers */ |
986 | 986 | ||
987 | w = (void *)&pcmcia->pcmc_pbr0; | 987 | w = (void *)&pcmcia->pcmc_pbr0; |
988 | w += winnr; | 988 | w += winnr; |
989 | 989 | ||
990 | out_be32(&w->or, 0); /* turn off window first */ | 990 | out_be32(&w->or, 0); /* turn off window first */ |
991 | out_be32(&w->br, M8XX_BASE); | 991 | out_be32(&w->br, M8XX_BASE); |
992 | 992 | ||
993 | reg <<= 27; | 993 | reg <<= 27; |
994 | reg |= M8XX_PCMCIA_POR_IO | (lsock << 2); | 994 | reg |= M8XX_PCMCIA_POR_IO | (lsock << 2); |
995 | 995 | ||
996 | reg |= m8xx_get_speed(io->speed, 1, s->bus_freq); | 996 | reg |= m8xx_get_speed(io->speed, 1, s->bus_freq); |
997 | 997 | ||
998 | if (io->flags & MAP_WRPROT) | 998 | if (io->flags & MAP_WRPROT) |
999 | reg |= M8XX_PCMCIA_POR_WRPROT; | 999 | reg |= M8XX_PCMCIA_POR_WRPROT; |
1000 | 1000 | ||
1001 | /*if(io->flags & (MAP_16BIT | MAP_AUTOSZ)) */ | 1001 | /*if(io->flags & (MAP_16BIT | MAP_AUTOSZ)) */ |
1002 | if (io->flags & MAP_16BIT) | 1002 | if (io->flags & MAP_16BIT) |
1003 | reg |= M8XX_PCMCIA_POR_16BIT; | 1003 | reg |= M8XX_PCMCIA_POR_16BIT; |
1004 | 1004 | ||
1005 | if (io->flags & MAP_ACTIVE) | 1005 | if (io->flags & MAP_ACTIVE) |
1006 | reg |= M8XX_PCMCIA_POR_VALID; | 1006 | reg |= M8XX_PCMCIA_POR_VALID; |
1007 | 1007 | ||
1008 | out_be32(&w->or, reg); | 1008 | out_be32(&w->or, reg); |
1009 | 1009 | ||
1010 | pr_debug("m8xx_pcmcia: Socket %u: Mapped io window %u at " | 1010 | pr_debug("m8xx_pcmcia: Socket %u: Mapped io window %u at " |
1011 | "%#8.8x, OR = %#8.8x.\n", lsock, io->map, w->br, w->or); | 1011 | "%#8.8x, OR = %#8.8x.\n", lsock, io->map, w->br, w->or); |
1012 | } else { | 1012 | } else { |
1013 | /* shutdown IO window */ | 1013 | /* shutdown IO window */ |
1014 | winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO) | 1014 | winnr = (PCMCIA_MEM_WIN_NO * PCMCIA_SOCKETS_NO) |
1015 | + (lsock * PCMCIA_IO_WIN_NO) + io->map; | 1015 | + (lsock * PCMCIA_IO_WIN_NO) + io->map; |
1016 | 1016 | ||
1017 | /* setup registers */ | 1017 | /* setup registers */ |
1018 | 1018 | ||
1019 | w = (void *)&pcmcia->pcmc_pbr0; | 1019 | w = (void *)&pcmcia->pcmc_pbr0; |
1020 | w += winnr; | 1020 | w += winnr; |
1021 | 1021 | ||
1022 | out_be32(&w->or, 0); /* turn off window */ | 1022 | out_be32(&w->or, 0); /* turn off window */ |
1023 | out_be32(&w->br, 0); /* turn off base address */ | 1023 | out_be32(&w->br, 0); /* turn off base address */ |
1024 | 1024 | ||
1025 | pr_debug("m8xx_pcmcia: Socket %u: Unmapped io window %u at " | 1025 | pr_debug("m8xx_pcmcia: Socket %u: Unmapped io window %u at " |
1026 | "%#8.8x, OR = %#8.8x.\n", lsock, io->map, w->br, w->or); | 1026 | "%#8.8x, OR = %#8.8x.\n", lsock, io->map, w->br, w->or); |
1027 | } | 1027 | } |
1028 | 1028 | ||
1029 | /* copy the struct and modify the copy */ | 1029 | /* copy the struct and modify the copy */ |
1030 | s->io_win[io->map] = *io; | 1030 | s->io_win[io->map] = *io; |
1031 | s->io_win[io->map].flags &= (MAP_WRPROT | MAP_16BIT | MAP_ACTIVE); | 1031 | s->io_win[io->map].flags &= (MAP_WRPROT | MAP_16BIT | MAP_ACTIVE); |
1032 | pr_debug("m8xx_pcmcia: SetIOMap exit\n"); | 1032 | pr_debug("m8xx_pcmcia: SetIOMap exit\n"); |
1033 | 1033 | ||
1034 | return 0; | 1034 | return 0; |
1035 | } | 1035 | } |
1036 | 1036 | ||
1037 | static int m8xx_set_mem_map(struct pcmcia_socket *sock, | 1037 | static int m8xx_set_mem_map(struct pcmcia_socket *sock, |
1038 | struct pccard_mem_map *mem) | 1038 | struct pccard_mem_map *mem) |
1039 | { | 1039 | { |
1040 | int lsock = container_of(sock, struct socket_info, socket)->slot; | 1040 | int lsock = container_of(sock, struct socket_info, socket)->slot; |
1041 | struct socket_info *s = &socket[lsock]; | 1041 | struct socket_info *s = &socket[lsock]; |
1042 | struct pcmcia_win *w; | 1042 | struct pcmcia_win *w; |
1043 | struct pccard_mem_map *old; | 1043 | struct pccard_mem_map *old; |
1044 | unsigned int reg, winnr; | 1044 | unsigned int reg, winnr; |
1045 | pcmconf8xx_t *pcmcia = s->pcmcia; | 1045 | pcmconf8xx_t *pcmcia = s->pcmcia; |
1046 | 1046 | ||
1047 | pr_debug("m8xx_pcmcia: SetMemMap(%d, %d, %#2.2x, %d ns, " | 1047 | pr_debug("m8xx_pcmcia: SetMemMap(%d, %d, %#2.2x, %d ns, " |
1048 | "%#5.5llx, %#5.5x)\n", lsock, mem->map, mem->flags, | 1048 | "%#5.5llx, %#5.5x)\n", lsock, mem->map, mem->flags, |
1049 | mem->speed, (unsigned long long)mem->static_start, | 1049 | mem->speed, (unsigned long long)mem->static_start, |
1050 | mem->card_start); | 1050 | mem->card_start); |
1051 | 1051 | ||
1052 | if ((mem->map >= PCMCIA_MEM_WIN_NO) | 1052 | if ((mem->map >= PCMCIA_MEM_WIN_NO) |
1053 | // || ((mem->s) >= PCMCIA_MEM_WIN_SIZE) | 1053 | // || ((mem->s) >= PCMCIA_MEM_WIN_SIZE) |
1054 | || (mem->card_start >= 0x04000000) | 1054 | || (mem->card_start >= 0x04000000) |
1055 | || (mem->static_start & 0xfff) /* 4KByte resolution */ | 1055 | || (mem->static_start & 0xfff) /* 4KByte resolution */ |
1056 | ||(mem->card_start & 0xfff)) | 1056 | ||(mem->card_start & 0xfff)) |
1057 | return -EINVAL; | 1057 | return -EINVAL; |
1058 | 1058 | ||
1059 | if ((reg = m8xx_get_graycode(PCMCIA_MEM_WIN_SIZE)) == -1) { | 1059 | if ((reg = m8xx_get_graycode(PCMCIA_MEM_WIN_SIZE)) == -1) { |
1060 | printk("Cannot set size to 0x%08x.\n", PCMCIA_MEM_WIN_SIZE); | 1060 | printk("Cannot set size to 0x%08x.\n", PCMCIA_MEM_WIN_SIZE); |
1061 | return -EINVAL; | 1061 | return -EINVAL; |
1062 | } | 1062 | } |
1063 | reg <<= 27; | 1063 | reg <<= 27; |
1064 | 1064 | ||
1065 | winnr = (lsock * PCMCIA_MEM_WIN_NO) + mem->map; | 1065 | winnr = (lsock * PCMCIA_MEM_WIN_NO) + mem->map; |
1066 | 1066 | ||
1067 | /* Setup the window in the pcmcia controller */ | 1067 | /* Setup the window in the pcmcia controller */ |
1068 | 1068 | ||
1069 | w = (void *)&pcmcia->pcmc_pbr0; | 1069 | w = (void *)&pcmcia->pcmc_pbr0; |
1070 | w += winnr; | 1070 | w += winnr; |
1071 | 1071 | ||
1072 | reg |= lsock << 2; | 1072 | reg |= lsock << 2; |
1073 | 1073 | ||
1074 | reg |= m8xx_get_speed(mem->speed, 0, s->bus_freq); | 1074 | reg |= m8xx_get_speed(mem->speed, 0, s->bus_freq); |
1075 | 1075 | ||
1076 | if (mem->flags & MAP_ATTRIB) | 1076 | if (mem->flags & MAP_ATTRIB) |
1077 | reg |= M8XX_PCMCIA_POR_ATTRMEM; | 1077 | reg |= M8XX_PCMCIA_POR_ATTRMEM; |
1078 | 1078 | ||
1079 | if (mem->flags & MAP_WRPROT) | 1079 | if (mem->flags & MAP_WRPROT) |
1080 | reg |= M8XX_PCMCIA_POR_WRPROT; | 1080 | reg |= M8XX_PCMCIA_POR_WRPROT; |
1081 | 1081 | ||
1082 | if (mem->flags & MAP_16BIT) | 1082 | if (mem->flags & MAP_16BIT) |
1083 | reg |= M8XX_PCMCIA_POR_16BIT; | 1083 | reg |= M8XX_PCMCIA_POR_16BIT; |
1084 | 1084 | ||
1085 | if (mem->flags & MAP_ACTIVE) | 1085 | if (mem->flags & MAP_ACTIVE) |
1086 | reg |= M8XX_PCMCIA_POR_VALID; | 1086 | reg |= M8XX_PCMCIA_POR_VALID; |
1087 | 1087 | ||
1088 | out_be32(&w->or, reg); | 1088 | out_be32(&w->or, reg); |
1089 | 1089 | ||
1090 | pr_debug("m8xx_pcmcia: Socket %u: Mapped memory window %u at %#8.8x, " | 1090 | pr_debug("m8xx_pcmcia: Socket %u: Mapped memory window %u at %#8.8x, " |
1091 | "OR = %#8.8x.\n", lsock, mem->map, w->br, w->or); | 1091 | "OR = %#8.8x.\n", lsock, mem->map, w->br, w->or); |
1092 | 1092 | ||
1093 | if (mem->flags & MAP_ACTIVE) { | 1093 | if (mem->flags & MAP_ACTIVE) { |
1094 | /* get the new base address */ | 1094 | /* get the new base address */ |
1095 | mem->static_start = PCMCIA_MEM_WIN_BASE + | 1095 | mem->static_start = PCMCIA_MEM_WIN_BASE + |
1096 | (PCMCIA_MEM_WIN_SIZE * winnr) | 1096 | (PCMCIA_MEM_WIN_SIZE * winnr) |
1097 | + mem->card_start; | 1097 | + mem->card_start; |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | pr_debug("m8xx_pcmcia: SetMemMap(%d, %d, %#2.2x, %d ns, " | 1100 | pr_debug("m8xx_pcmcia: SetMemMap(%d, %d, %#2.2x, %d ns, " |
1101 | "%#5.5llx, %#5.5x)\n", lsock, mem->map, mem->flags, | 1101 | "%#5.5llx, %#5.5x)\n", lsock, mem->map, mem->flags, |
1102 | mem->speed, (unsigned long long)mem->static_start, | 1102 | mem->speed, (unsigned long long)mem->static_start, |
1103 | mem->card_start); | 1103 | mem->card_start); |
1104 | 1104 | ||
1105 | /* copy the struct and modify the copy */ | 1105 | /* copy the struct and modify the copy */ |
1106 | 1106 | ||
1107 | old = &s->mem_win[mem->map]; | 1107 | old = &s->mem_win[mem->map]; |
1108 | 1108 | ||
1109 | *old = *mem; | 1109 | *old = *mem; |
1110 | old->flags &= (MAP_ATTRIB | MAP_WRPROT | MAP_16BIT | MAP_ACTIVE); | 1110 | old->flags &= (MAP_ATTRIB | MAP_WRPROT | MAP_16BIT | MAP_ACTIVE); |
1111 | 1111 | ||
1112 | return 0; | 1112 | return 0; |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | static int m8xx_sock_init(struct pcmcia_socket *sock) | 1115 | static int m8xx_sock_init(struct pcmcia_socket *sock) |
1116 | { | 1116 | { |
1117 | int i; | 1117 | int i; |
1118 | pccard_io_map io = { 0, 0, 0, 0, 1 }; | 1118 | pccard_io_map io = { 0, 0, 0, 0, 1 }; |
1119 | pccard_mem_map mem = { 0, 0, 0, 0, 0, 0 }; | 1119 | pccard_mem_map mem = { 0, 0, 0, 0, 0, 0 }; |
1120 | 1120 | ||
1121 | pr_debug("m8xx_pcmcia: sock_init(%d)\n", s); | 1121 | pr_debug("m8xx_pcmcia: sock_init(%d)\n", s); |
1122 | 1122 | ||
1123 | m8xx_set_socket(sock, &dead_socket); | 1123 | m8xx_set_socket(sock, &dead_socket); |
1124 | for (i = 0; i < PCMCIA_IO_WIN_NO; i++) { | 1124 | for (i = 0; i < PCMCIA_IO_WIN_NO; i++) { |
1125 | io.map = i; | 1125 | io.map = i; |
1126 | m8xx_set_io_map(sock, &io); | 1126 | m8xx_set_io_map(sock, &io); |
1127 | } | 1127 | } |
1128 | for (i = 0; i < PCMCIA_MEM_WIN_NO; i++) { | 1128 | for (i = 0; i < PCMCIA_MEM_WIN_NO; i++) { |
1129 | mem.map = i; | 1129 | mem.map = i; |
1130 | m8xx_set_mem_map(sock, &mem); | 1130 | m8xx_set_mem_map(sock, &mem); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | return 0; | 1133 | return 0; |
1134 | 1134 | ||
1135 | } | 1135 | } |
1136 | 1136 | ||
1137 | static int m8xx_sock_suspend(struct pcmcia_socket *sock) | 1137 | static int m8xx_sock_suspend(struct pcmcia_socket *sock) |
1138 | { | 1138 | { |
1139 | return m8xx_set_socket(sock, &dead_socket); | 1139 | return m8xx_set_socket(sock, &dead_socket); |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | static struct pccard_operations m8xx_services = { | 1142 | static struct pccard_operations m8xx_services = { |
1143 | .init = m8xx_sock_init, | 1143 | .init = m8xx_sock_init, |
1144 | .suspend = m8xx_sock_suspend, | 1144 | .suspend = m8xx_sock_suspend, |
1145 | .get_status = m8xx_get_status, | 1145 | .get_status = m8xx_get_status, |
1146 | .set_socket = m8xx_set_socket, | 1146 | .set_socket = m8xx_set_socket, |
1147 | .set_io_map = m8xx_set_io_map, | 1147 | .set_io_map = m8xx_set_io_map, |
1148 | .set_mem_map = m8xx_set_mem_map, | 1148 | .set_mem_map = m8xx_set_mem_map, |
1149 | }; | 1149 | }; |
1150 | 1150 | ||
1151 | static int __init m8xx_probe(struct platform_device *ofdev) | 1151 | static int __init m8xx_probe(struct platform_device *ofdev) |
1152 | { | 1152 | { |
1153 | struct pcmcia_win *w; | 1153 | struct pcmcia_win *w; |
1154 | unsigned int i, m, hwirq; | 1154 | unsigned int i, m, hwirq; |
1155 | pcmconf8xx_t *pcmcia; | 1155 | pcmconf8xx_t *pcmcia; |
1156 | int status; | 1156 | int status; |
1157 | struct device_node *np = ofdev->dev.of_node; | 1157 | struct device_node *np = ofdev->dev.of_node; |
1158 | 1158 | ||
1159 | pcmcia_info("%s\n", version); | 1159 | pcmcia_info("%s\n", version); |
1160 | 1160 | ||
1161 | pcmcia = of_iomap(np, 0); | 1161 | pcmcia = of_iomap(np, 0); |
1162 | if (pcmcia == NULL) | 1162 | if (pcmcia == NULL) |
1163 | return -EINVAL; | 1163 | return -EINVAL; |
1164 | 1164 | ||
1165 | pcmcia_schlvl = irq_of_parse_and_map(np, 0); | 1165 | pcmcia_schlvl = irq_of_parse_and_map(np, 0); |
1166 | hwirq = irq_map[pcmcia_schlvl].hwirq; | 1166 | hwirq = irq_map[pcmcia_schlvl].hwirq; |
1167 | if (pcmcia_schlvl < 0) { | 1167 | if (pcmcia_schlvl < 0) { |
1168 | iounmap(pcmcia); | 1168 | iounmap(pcmcia); |
1169 | return -EINVAL; | 1169 | return -EINVAL; |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | m8xx_pgcrx[0] = &pcmcia->pcmc_pgcra; | 1172 | m8xx_pgcrx[0] = &pcmcia->pcmc_pgcra; |
1173 | m8xx_pgcrx[1] = &pcmcia->pcmc_pgcrb; | 1173 | m8xx_pgcrx[1] = &pcmcia->pcmc_pgcrb; |
1174 | 1174 | ||
1175 | pcmcia_info(PCMCIA_BOARD_MSG " using " PCMCIA_SLOT_MSG | 1175 | pcmcia_info(PCMCIA_BOARD_MSG " using " PCMCIA_SLOT_MSG |
1176 | " with IRQ %u (%d). \n", pcmcia_schlvl, hwirq); | 1176 | " with IRQ %u (%d). \n", pcmcia_schlvl, hwirq); |
1177 | 1177 | ||
1178 | /* Configure Status change interrupt */ | 1178 | /* Configure Status change interrupt */ |
1179 | 1179 | ||
1180 | if (request_irq(pcmcia_schlvl, m8xx_interrupt, IRQF_SHARED, | 1180 | if (request_irq(pcmcia_schlvl, m8xx_interrupt, IRQF_SHARED, |
1181 | driver_name, socket)) { | 1181 | driver_name, socket)) { |
1182 | pcmcia_error("Cannot allocate IRQ %u for SCHLVL!\n", | 1182 | pcmcia_error("Cannot allocate IRQ %u for SCHLVL!\n", |
1183 | pcmcia_schlvl); | 1183 | pcmcia_schlvl); |
1184 | iounmap(pcmcia); | 1184 | iounmap(pcmcia); |
1185 | return -1; | 1185 | return -1; |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | w = (void *)&pcmcia->pcmc_pbr0; | 1188 | w = (void *)&pcmcia->pcmc_pbr0; |
1189 | 1189 | ||
1190 | out_be32(&pcmcia->pcmc_pscr, M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1)); | 1190 | out_be32(&pcmcia->pcmc_pscr, M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1)); |
1191 | clrbits32(&pcmcia->pcmc_per, M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1)); | 1191 | clrbits32(&pcmcia->pcmc_per, M8XX_PCMCIA_MASK(0) | M8XX_PCMCIA_MASK(1)); |
1192 | 1192 | ||
1193 | /* connect interrupt and disable CxOE */ | 1193 | /* connect interrupt and disable CxOE */ |
1194 | 1194 | ||
1195 | out_be32(M8XX_PGCRX(0), | 1195 | out_be32(M8XX_PGCRX(0), |
1196 | M8XX_PGCRX_CXOE | (mk_int_int_mask(hwirq) << 16)); | 1196 | M8XX_PGCRX_CXOE | (mk_int_int_mask(hwirq) << 16)); |
1197 | out_be32(M8XX_PGCRX(1), | 1197 | out_be32(M8XX_PGCRX(1), |
1198 | M8XX_PGCRX_CXOE | (mk_int_int_mask(hwirq) << 16)); | 1198 | M8XX_PGCRX_CXOE | (mk_int_int_mask(hwirq) << 16)); |
1199 | 1199 | ||
1200 | /* initialize the fixed memory windows */ | 1200 | /* initialize the fixed memory windows */ |
1201 | 1201 | ||
1202 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { | 1202 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { |
1203 | for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) { | 1203 | for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) { |
1204 | out_be32(&w->br, PCMCIA_MEM_WIN_BASE + | 1204 | out_be32(&w->br, PCMCIA_MEM_WIN_BASE + |
1205 | (PCMCIA_MEM_WIN_SIZE | 1205 | (PCMCIA_MEM_WIN_SIZE |
1206 | * (m + i * PCMCIA_MEM_WIN_NO))); | 1206 | * (m + i * PCMCIA_MEM_WIN_NO))); |
1207 | 1207 | ||
1208 | out_be32(&w->or, 0); /* set to not valid */ | 1208 | out_be32(&w->or, 0); /* set to not valid */ |
1209 | 1209 | ||
1210 | w++; | 1210 | w++; |
1211 | } | 1211 | } |
1212 | } | 1212 | } |
1213 | 1213 | ||
1214 | /* turn off voltage */ | 1214 | /* turn off voltage */ |
1215 | voltage_set(0, 0, 0); | 1215 | voltage_set(0, 0, 0); |
1216 | voltage_set(1, 0, 0); | 1216 | voltage_set(1, 0, 0); |
1217 | 1217 | ||
1218 | /* Enable external hardware */ | 1218 | /* Enable external hardware */ |
1219 | hardware_enable(0); | 1219 | hardware_enable(0); |
1220 | hardware_enable(1); | 1220 | hardware_enable(1); |
1221 | 1221 | ||
1222 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { | 1222 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { |
1223 | socket[i].slot = i; | 1223 | socket[i].slot = i; |
1224 | socket[i].socket.owner = THIS_MODULE; | 1224 | socket[i].socket.owner = THIS_MODULE; |
1225 | socket[i].socket.features = | 1225 | socket[i].socket.features = |
1226 | SS_CAP_PCCARD | SS_CAP_MEM_ALIGN | SS_CAP_STATIC_MAP; | 1226 | SS_CAP_PCCARD | SS_CAP_MEM_ALIGN | SS_CAP_STATIC_MAP; |
1227 | socket[i].socket.irq_mask = 0x000; | 1227 | socket[i].socket.irq_mask = 0x000; |
1228 | socket[i].socket.map_size = 0x1000; | 1228 | socket[i].socket.map_size = 0x1000; |
1229 | socket[i].socket.io_offset = 0; | 1229 | socket[i].socket.io_offset = 0; |
1230 | socket[i].socket.pci_irq = pcmcia_schlvl; | 1230 | socket[i].socket.pci_irq = pcmcia_schlvl; |
1231 | socket[i].socket.ops = &m8xx_services; | 1231 | socket[i].socket.ops = &m8xx_services; |
1232 | socket[i].socket.resource_ops = &pccard_iodyn_ops; | 1232 | socket[i].socket.resource_ops = &pccard_iodyn_ops; |
1233 | socket[i].socket.cb_dev = NULL; | 1233 | socket[i].socket.cb_dev = NULL; |
1234 | socket[i].socket.dev.parent = &ofdev->dev; | 1234 | socket[i].socket.dev.parent = &ofdev->dev; |
1235 | socket[i].pcmcia = pcmcia; | 1235 | socket[i].pcmcia = pcmcia; |
1236 | socket[i].bus_freq = ppc_proc_freq; | 1236 | socket[i].bus_freq = ppc_proc_freq; |
1237 | socket[i].hwirq = hwirq; | 1237 | socket[i].hwirq = hwirq; |
1238 | 1238 | ||
1239 | } | 1239 | } |
1240 | 1240 | ||
1241 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { | 1241 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { |
1242 | status = pcmcia_register_socket(&socket[i].socket); | 1242 | status = pcmcia_register_socket(&socket[i].socket); |
1243 | if (status < 0) | 1243 | if (status < 0) |
1244 | pcmcia_error("Socket register failed\n"); | 1244 | pcmcia_error("Socket register failed\n"); |
1245 | } | 1245 | } |
1246 | 1246 | ||
1247 | return 0; | 1247 | return 0; |
1248 | } | 1248 | } |
1249 | 1249 | ||
1250 | static int m8xx_remove(struct platform_device *ofdev) | 1250 | static int m8xx_remove(struct platform_device *ofdev) |
1251 | { | 1251 | { |
1252 | u32 m, i; | 1252 | u32 m, i; |
1253 | struct pcmcia_win *w; | 1253 | struct pcmcia_win *w; |
1254 | pcmconf8xx_t *pcmcia = socket[0].pcmcia; | 1254 | pcmconf8xx_t *pcmcia = socket[0].pcmcia; |
1255 | 1255 | ||
1256 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { | 1256 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) { |
1257 | w = (void *)&pcmcia->pcmc_pbr0; | 1257 | w = (void *)&pcmcia->pcmc_pbr0; |
1258 | 1258 | ||
1259 | out_be32(&pcmcia->pcmc_pscr, M8XX_PCMCIA_MASK(i)); | 1259 | out_be32(&pcmcia->pcmc_pscr, M8XX_PCMCIA_MASK(i)); |
1260 | out_be32(&pcmcia->pcmc_per, | 1260 | out_be32(&pcmcia->pcmc_per, |
1261 | in_be32(&pcmcia->pcmc_per) & ~M8XX_PCMCIA_MASK(i)); | 1261 | in_be32(&pcmcia->pcmc_per) & ~M8XX_PCMCIA_MASK(i)); |
1262 | 1262 | ||
1263 | /* turn off interrupt and disable CxOE */ | 1263 | /* turn off interrupt and disable CxOE */ |
1264 | out_be32(M8XX_PGCRX(i), M8XX_PGCRX_CXOE); | 1264 | out_be32(M8XX_PGCRX(i), M8XX_PGCRX_CXOE); |
1265 | 1265 | ||
1266 | /* turn off memory windows */ | 1266 | /* turn off memory windows */ |
1267 | for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) { | 1267 | for (m = 0; m < PCMCIA_MEM_WIN_NO; m++) { |
1268 | out_be32(&w->or, 0); /* set to not valid */ | 1268 | out_be32(&w->or, 0); /* set to not valid */ |
1269 | w++; | 1269 | w++; |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | /* turn off voltage */ | 1272 | /* turn off voltage */ |
1273 | voltage_set(i, 0, 0); | 1273 | voltage_set(i, 0, 0); |
1274 | 1274 | ||
1275 | /* disable external hardware */ | 1275 | /* disable external hardware */ |
1276 | hardware_disable(i); | 1276 | hardware_disable(i); |
1277 | } | 1277 | } |
1278 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) | 1278 | for (i = 0; i < PCMCIA_SOCKETS_NO; i++) |
1279 | pcmcia_unregister_socket(&socket[i].socket); | 1279 | pcmcia_unregister_socket(&socket[i].socket); |
1280 | iounmap(pcmcia); | 1280 | iounmap(pcmcia); |
1281 | 1281 | ||
1282 | free_irq(pcmcia_schlvl, NULL); | 1282 | free_irq(pcmcia_schlvl, NULL); |
1283 | 1283 | ||
1284 | return 0; | 1284 | return 0; |
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | static const struct of_device_id m8xx_pcmcia_match[] = { | 1287 | static const struct of_device_id m8xx_pcmcia_match[] = { |
1288 | { | 1288 | { |
1289 | .type = "pcmcia", | 1289 | .type = "pcmcia", |
1290 | .compatible = "fsl,pq-pcmcia", | 1290 | .compatible = "fsl,pq-pcmcia", |
1291 | }, | 1291 | }, |
1292 | {}, | 1292 | {}, |
1293 | }; | 1293 | }; |
1294 | 1294 | ||
1295 | MODULE_DEVICE_TABLE(of, m8xx_pcmcia_match); | 1295 | MODULE_DEVICE_TABLE(of, m8xx_pcmcia_match); |
1296 | 1296 | ||
1297 | static struct platform_driver m8xx_pcmcia_driver = { | 1297 | static struct platform_driver m8xx_pcmcia_driver = { |
1298 | .driver = { | 1298 | .driver = { |
1299 | .name = driver_name, | 1299 | .name = driver_name, |
1300 | .owner = THIS_MODULE, | 1300 | .owner = THIS_MODULE, |
1301 | .of_match_table = m8xx_pcmcia_match, | 1301 | .of_match_table = m8xx_pcmcia_match, |
1302 | }, | 1302 | }, |
1303 | .probe = m8xx_probe, | 1303 | .probe = m8xx_probe, |
1304 | .remove = m8xx_remove, | 1304 | .remove = m8xx_remove, |
1305 | }; | 1305 | }; |
1306 | 1306 | ||
1307 | static int __init m8xx_init(void) | 1307 | module_platform_driver(m8xx_pcmcia_driver); |
1308 | { | ||
1309 | return platform_driver_register(&m8xx_pcmcia_driver); | ||
1310 | } | ||
1311 | |||
1312 | static void __exit m8xx_exit(void) | ||
1313 | { | ||
1314 | platform_driver_unregister(&m8xx_pcmcia_driver); | ||
1315 | } | ||
1316 | |||
1317 | module_init(m8xx_init); | ||
1318 | module_exit(m8xx_exit); | ||
1319 | 1308 |
drivers/pcmcia/pxa2xx_viper.c
1 | /* | 1 | /* |
2 | * Viper/Zeus PCMCIA support | 2 | * Viper/Zeus PCMCIA support |
3 | * Copyright 2004 Arcom Control Systems | 3 | * Copyright 2004 Arcom Control Systems |
4 | * | 4 | * |
5 | * Maintained by Marc Zyngier <maz@misterjones.org> | 5 | * Maintained by Marc Zyngier <maz@misterjones.org> |
6 | * | 6 | * |
7 | * Based on: | 7 | * Based on: |
8 | * iPAQ h2200 PCMCIA support | 8 | * iPAQ h2200 PCMCIA support |
9 | * Copyright 2004 Koen Kooi <koen@vestingbar.nl> | 9 | * Copyright 2004 Koen Kooi <koen@vestingbar.nl> |
10 | * | 10 | * |
11 | * This file is subject to the terms and conditions of the GNU General Public | 11 | * This file is subject to the terms and conditions of the GNU General Public |
12 | * License. See the file COPYING in the main directory of this archive for | 12 | * License. See the file COPYING in the main directory of this archive for |
13 | * more details. | 13 | * more details. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/interrupt.h> | 20 | #include <linux/interrupt.h> |
21 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/gpio.h> | 22 | #include <linux/gpio.h> |
23 | 23 | ||
24 | #include <pcmcia/ss.h> | 24 | #include <pcmcia/ss.h> |
25 | 25 | ||
26 | #include <asm/irq.h> | 26 | #include <asm/irq.h> |
27 | 27 | ||
28 | #include <mach/arcom-pcmcia.h> | 28 | #include <mach/arcom-pcmcia.h> |
29 | 29 | ||
30 | #include "soc_common.h" | 30 | #include "soc_common.h" |
31 | #include "pxa2xx_base.h" | 31 | #include "pxa2xx_base.h" |
32 | 32 | ||
33 | static struct platform_device *arcom_pcmcia_dev; | 33 | static struct platform_device *arcom_pcmcia_dev; |
34 | 34 | ||
35 | static struct pcmcia_irqs irqs[] = { | 35 | static struct pcmcia_irqs irqs[] = { |
36 | { | 36 | { |
37 | .sock = 0, | 37 | .sock = 0, |
38 | .str = "PCMCIA_CD", | 38 | .str = "PCMCIA_CD", |
39 | }, | 39 | }, |
40 | }; | 40 | }; |
41 | 41 | ||
42 | static inline struct arcom_pcmcia_pdata *viper_get_pdata(void) | 42 | static inline struct arcom_pcmcia_pdata *viper_get_pdata(void) |
43 | { | 43 | { |
44 | return arcom_pcmcia_dev->dev.platform_data; | 44 | return arcom_pcmcia_dev->dev.platform_data; |
45 | } | 45 | } |
46 | 46 | ||
47 | static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt) | 47 | static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
48 | { | 48 | { |
49 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); | 49 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
50 | unsigned long flags; | 50 | unsigned long flags; |
51 | 51 | ||
52 | skt->socket.pci_irq = gpio_to_irq(pdata->rdy_gpio); | 52 | skt->socket.pci_irq = gpio_to_irq(pdata->rdy_gpio); |
53 | irqs[0].irq = gpio_to_irq(pdata->cd_gpio); | 53 | irqs[0].irq = gpio_to_irq(pdata->cd_gpio); |
54 | 54 | ||
55 | if (gpio_request(pdata->cd_gpio, "CF detect")) | 55 | if (gpio_request(pdata->cd_gpio, "CF detect")) |
56 | goto err_request_cd; | 56 | goto err_request_cd; |
57 | 57 | ||
58 | if (gpio_request(pdata->rdy_gpio, "CF ready")) | 58 | if (gpio_request(pdata->rdy_gpio, "CF ready")) |
59 | goto err_request_rdy; | 59 | goto err_request_rdy; |
60 | 60 | ||
61 | if (gpio_request(pdata->pwr_gpio, "CF power")) | 61 | if (gpio_request(pdata->pwr_gpio, "CF power")) |
62 | goto err_request_pwr; | 62 | goto err_request_pwr; |
63 | 63 | ||
64 | local_irq_save(flags); | 64 | local_irq_save(flags); |
65 | 65 | ||
66 | if (gpio_direction_output(pdata->pwr_gpio, 0) || | 66 | if (gpio_direction_output(pdata->pwr_gpio, 0) || |
67 | gpio_direction_input(pdata->cd_gpio) || | 67 | gpio_direction_input(pdata->cd_gpio) || |
68 | gpio_direction_input(pdata->rdy_gpio)) { | 68 | gpio_direction_input(pdata->rdy_gpio)) { |
69 | local_irq_restore(flags); | 69 | local_irq_restore(flags); |
70 | goto err_dir; | 70 | goto err_dir; |
71 | } | 71 | } |
72 | 72 | ||
73 | local_irq_restore(flags); | 73 | local_irq_restore(flags); |
74 | 74 | ||
75 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); | 75 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
76 | 76 | ||
77 | err_dir: | 77 | err_dir: |
78 | gpio_free(pdata->pwr_gpio); | 78 | gpio_free(pdata->pwr_gpio); |
79 | err_request_pwr: | 79 | err_request_pwr: |
80 | gpio_free(pdata->rdy_gpio); | 80 | gpio_free(pdata->rdy_gpio); |
81 | err_request_rdy: | 81 | err_request_rdy: |
82 | gpio_free(pdata->cd_gpio); | 82 | gpio_free(pdata->cd_gpio); |
83 | err_request_cd: | 83 | err_request_cd: |
84 | dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n"); | 84 | dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n"); |
85 | return -1; | 85 | return -1; |
86 | } | 86 | } |
87 | 87 | ||
88 | /* | 88 | /* |
89 | * Release all resources. | 89 | * Release all resources. |
90 | */ | 90 | */ |
91 | static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) | 91 | static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
92 | { | 92 | { |
93 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); | 93 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
94 | 94 | ||
95 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); | 95 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
96 | gpio_free(pdata->pwr_gpio); | 96 | gpio_free(pdata->pwr_gpio); |
97 | gpio_free(pdata->rdy_gpio); | 97 | gpio_free(pdata->rdy_gpio); |
98 | gpio_free(pdata->cd_gpio); | 98 | gpio_free(pdata->cd_gpio); |
99 | } | 99 | } |
100 | 100 | ||
101 | static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt, | 101 | static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
102 | struct pcmcia_state *state) | 102 | struct pcmcia_state *state) |
103 | { | 103 | { |
104 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); | 104 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
105 | 105 | ||
106 | state->detect = !gpio_get_value(pdata->cd_gpio); | 106 | state->detect = !gpio_get_value(pdata->cd_gpio); |
107 | state->ready = !!gpio_get_value(pdata->rdy_gpio); | 107 | state->ready = !!gpio_get_value(pdata->rdy_gpio); |
108 | state->bvd1 = 1; | 108 | state->bvd1 = 1; |
109 | state->bvd2 = 1; | 109 | state->bvd2 = 1; |
110 | state->wrprot = 0; | 110 | state->wrprot = 0; |
111 | state->vs_3v = 1; /* Can only apply 3.3V */ | 111 | state->vs_3v = 1; /* Can only apply 3.3V */ |
112 | state->vs_Xv = 0; | 112 | state->vs_Xv = 0; |
113 | } | 113 | } |
114 | 114 | ||
115 | static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, | 115 | static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
116 | const socket_state_t *state) | 116 | const socket_state_t *state) |
117 | { | 117 | { |
118 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); | 118 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
119 | 119 | ||
120 | /* Silently ignore Vpp, output enable, speaker enable. */ | 120 | /* Silently ignore Vpp, output enable, speaker enable. */ |
121 | pdata->reset(state->flags & SS_RESET); | 121 | pdata->reset(state->flags & SS_RESET); |
122 | 122 | ||
123 | /* Apply socket voltage */ | 123 | /* Apply socket voltage */ |
124 | switch (state->Vcc) { | 124 | switch (state->Vcc) { |
125 | case 0: | 125 | case 0: |
126 | gpio_set_value(pdata->pwr_gpio, 0); | 126 | gpio_set_value(pdata->pwr_gpio, 0); |
127 | break; | 127 | break; |
128 | case 33: | 128 | case 33: |
129 | gpio_set_value(pdata->pwr_gpio, 1); | 129 | gpio_set_value(pdata->pwr_gpio, 1); |
130 | break; | 130 | break; |
131 | default: | 131 | default: |
132 | dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc); | 132 | dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc); |
133 | return -1; | 133 | return -1; |
134 | } | 134 | } |
135 | 135 | ||
136 | return 0; | 136 | return 0; |
137 | } | 137 | } |
138 | 138 | ||
139 | static struct pcmcia_low_level viper_pcmcia_ops = { | 139 | static struct pcmcia_low_level viper_pcmcia_ops = { |
140 | .owner = THIS_MODULE, | 140 | .owner = THIS_MODULE, |
141 | .hw_init = viper_pcmcia_hw_init, | 141 | .hw_init = viper_pcmcia_hw_init, |
142 | .hw_shutdown = viper_pcmcia_hw_shutdown, | 142 | .hw_shutdown = viper_pcmcia_hw_shutdown, |
143 | .socket_state = viper_pcmcia_socket_state, | 143 | .socket_state = viper_pcmcia_socket_state, |
144 | .configure_socket = viper_pcmcia_configure_socket, | 144 | .configure_socket = viper_pcmcia_configure_socket, |
145 | .nr = 1, | 145 | .nr = 1, |
146 | }; | 146 | }; |
147 | 147 | ||
148 | static struct platform_device *viper_pcmcia_device; | 148 | static struct platform_device *viper_pcmcia_device; |
149 | 149 | ||
150 | static int viper_pcmcia_probe(struct platform_device *pdev) | 150 | static int viper_pcmcia_probe(struct platform_device *pdev) |
151 | { | 151 | { |
152 | int ret; | 152 | int ret; |
153 | 153 | ||
154 | /* I can't imagine more than one device, but you never know... */ | 154 | /* I can't imagine more than one device, but you never know... */ |
155 | if (arcom_pcmcia_dev) | 155 | if (arcom_pcmcia_dev) |
156 | return -EEXIST; | 156 | return -EEXIST; |
157 | 157 | ||
158 | if (!pdev->dev.platform_data) | 158 | if (!pdev->dev.platform_data) |
159 | return -EINVAL; | 159 | return -EINVAL; |
160 | 160 | ||
161 | viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); | 161 | viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
162 | if (!viper_pcmcia_device) | 162 | if (!viper_pcmcia_device) |
163 | return -ENOMEM; | 163 | return -ENOMEM; |
164 | 164 | ||
165 | arcom_pcmcia_dev = pdev; | 165 | arcom_pcmcia_dev = pdev; |
166 | 166 | ||
167 | viper_pcmcia_device->dev.parent = &pdev->dev; | 167 | viper_pcmcia_device->dev.parent = &pdev->dev; |
168 | 168 | ||
169 | ret = platform_device_add_data(viper_pcmcia_device, | 169 | ret = platform_device_add_data(viper_pcmcia_device, |
170 | &viper_pcmcia_ops, | 170 | &viper_pcmcia_ops, |
171 | sizeof(viper_pcmcia_ops)); | 171 | sizeof(viper_pcmcia_ops)); |
172 | 172 | ||
173 | if (!ret) | 173 | if (!ret) |
174 | ret = platform_device_add(viper_pcmcia_device); | 174 | ret = platform_device_add(viper_pcmcia_device); |
175 | 175 | ||
176 | if (ret) { | 176 | if (ret) { |
177 | platform_device_put(viper_pcmcia_device); | 177 | platform_device_put(viper_pcmcia_device); |
178 | arcom_pcmcia_dev = NULL; | 178 | arcom_pcmcia_dev = NULL; |
179 | } | 179 | } |
180 | 180 | ||
181 | return ret; | 181 | return ret; |
182 | } | 182 | } |
183 | 183 | ||
184 | static int viper_pcmcia_remove(struct platform_device *pdev) | 184 | static int viper_pcmcia_remove(struct platform_device *pdev) |
185 | { | 185 | { |
186 | platform_device_unregister(viper_pcmcia_device); | 186 | platform_device_unregister(viper_pcmcia_device); |
187 | arcom_pcmcia_dev = NULL; | 187 | arcom_pcmcia_dev = NULL; |
188 | return 0; | 188 | return 0; |
189 | } | 189 | } |
190 | 190 | ||
191 | static struct platform_device_id viper_pcmcia_id_table[] = { | 191 | static struct platform_device_id viper_pcmcia_id_table[] = { |
192 | { .name = "viper-pcmcia", }, | 192 | { .name = "viper-pcmcia", }, |
193 | { .name = "zeus-pcmcia", }, | 193 | { .name = "zeus-pcmcia", }, |
194 | { }, | 194 | { }, |
195 | }; | 195 | }; |
196 | 196 | ||
197 | static struct platform_driver viper_pcmcia_driver = { | 197 | static struct platform_driver viper_pcmcia_driver = { |
198 | .probe = viper_pcmcia_probe, | 198 | .probe = viper_pcmcia_probe, |
199 | .remove = viper_pcmcia_remove, | 199 | .remove = viper_pcmcia_remove, |
200 | .driver = { | 200 | .driver = { |
201 | .name = "arcom-pcmcia", | 201 | .name = "arcom-pcmcia", |
202 | .owner = THIS_MODULE, | 202 | .owner = THIS_MODULE, |
203 | }, | 203 | }, |
204 | .id_table = viper_pcmcia_id_table, | 204 | .id_table = viper_pcmcia_id_table, |
205 | }; | 205 | }; |
206 | 206 | ||
207 | static int __init viper_pcmcia_init(void) | 207 | module_platform_driver(viper_pcmcia_driver); |
208 | { | ||
209 | return platform_driver_register(&viper_pcmcia_driver); | ||
210 | } | ||
211 | |||
212 | static void __exit viper_pcmcia_exit(void) | ||
213 | { | ||
214 | return platform_driver_unregister(&viper_pcmcia_driver); | ||
215 | } | ||
216 | |||
217 | module_init(viper_pcmcia_init); | ||
218 | module_exit(viper_pcmcia_exit); | ||
219 | 208 | ||
220 | MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table); | 209 | MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table); |
221 | MODULE_LICENSE("GPL"); | 210 | MODULE_LICENSE("GPL"); |
222 | 211 |
drivers/pcmcia/xxs1500_ss.c
1 | /* | 1 | /* |
2 | * PCMCIA socket code for the MyCable XXS1500 system. | 2 | * PCMCIA socket code for the MyCable XXS1500 system. |
3 | * | 3 | * |
4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> | 4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> |
5 | * | 5 | * |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/delay.h> | 8 | #include <linux/delay.h> |
9 | #include <linux/gpio.h> | 9 | #include <linux/gpio.h> |
10 | #include <linux/interrupt.h> | 10 | #include <linux/interrupt.h> |
11 | #include <linux/io.h> | 11 | #include <linux/io.h> |
12 | #include <linux/ioport.h> | 12 | #include <linux/ioport.h> |
13 | #include <linux/mm.h> | 13 | #include <linux/mm.h> |
14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
15 | #include <linux/pm.h> | 15 | #include <linux/pm.h> |
16 | #include <linux/resource.h> | 16 | #include <linux/resource.h> |
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | #include <linux/spinlock.h> | 18 | #include <linux/spinlock.h> |
19 | 19 | ||
20 | #include <pcmcia/ss.h> | 20 | #include <pcmcia/ss.h> |
21 | #include <pcmcia/cistpl.h> | 21 | #include <pcmcia/cistpl.h> |
22 | 22 | ||
23 | #include <asm/irq.h> | 23 | #include <asm/irq.h> |
24 | #include <asm/system.h> | 24 | #include <asm/system.h> |
25 | #include <asm/mach-au1x00/au1000.h> | 25 | #include <asm/mach-au1x00/au1000.h> |
26 | 26 | ||
27 | #define MEM_MAP_SIZE 0x400000 | 27 | #define MEM_MAP_SIZE 0x400000 |
28 | #define IO_MAP_SIZE 0x1000 | 28 | #define IO_MAP_SIZE 0x1000 |
29 | 29 | ||
30 | 30 | ||
31 | /* | 31 | /* |
32 | * 3.3V cards only; all interfacing is done via gpios: | 32 | * 3.3V cards only; all interfacing is done via gpios: |
33 | * | 33 | * |
34 | * 0/1: carddetect (00 = card present, xx = huh) | 34 | * 0/1: carddetect (00 = card present, xx = huh) |
35 | * 4: card irq | 35 | * 4: card irq |
36 | * 204: reset (high-act) | 36 | * 204: reset (high-act) |
37 | * 205: buffer enable (low-act) | 37 | * 205: buffer enable (low-act) |
38 | * 208/209: card voltage key (00,01,10,11) | 38 | * 208/209: card voltage key (00,01,10,11) |
39 | * 210: battwarn | 39 | * 210: battwarn |
40 | * 211: batdead | 40 | * 211: batdead |
41 | * 214: power (low-act) | 41 | * 214: power (low-act) |
42 | */ | 42 | */ |
43 | #define GPIO_CDA 0 | 43 | #define GPIO_CDA 0 |
44 | #define GPIO_CDB 1 | 44 | #define GPIO_CDB 1 |
45 | #define GPIO_CARDIRQ 4 | 45 | #define GPIO_CARDIRQ 4 |
46 | #define GPIO_RESET 204 | 46 | #define GPIO_RESET 204 |
47 | #define GPIO_OUTEN 205 | 47 | #define GPIO_OUTEN 205 |
48 | #define GPIO_VSL 208 | 48 | #define GPIO_VSL 208 |
49 | #define GPIO_VSH 209 | 49 | #define GPIO_VSH 209 |
50 | #define GPIO_BATTDEAD 210 | 50 | #define GPIO_BATTDEAD 210 |
51 | #define GPIO_BATTWARN 211 | 51 | #define GPIO_BATTWARN 211 |
52 | #define GPIO_POWER 214 | 52 | #define GPIO_POWER 214 |
53 | 53 | ||
54 | struct xxs1500_pcmcia_sock { | 54 | struct xxs1500_pcmcia_sock { |
55 | struct pcmcia_socket socket; | 55 | struct pcmcia_socket socket; |
56 | void *virt_io; | 56 | void *virt_io; |
57 | 57 | ||
58 | phys_addr_t phys_io; | 58 | phys_addr_t phys_io; |
59 | phys_addr_t phys_attr; | 59 | phys_addr_t phys_attr; |
60 | phys_addr_t phys_mem; | 60 | phys_addr_t phys_mem; |
61 | 61 | ||
62 | /* previous flags for set_socket() */ | 62 | /* previous flags for set_socket() */ |
63 | unsigned int old_flags; | 63 | unsigned int old_flags; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | #define to_xxs_socket(x) container_of(x, struct xxs1500_pcmcia_sock, socket) | 66 | #define to_xxs_socket(x) container_of(x, struct xxs1500_pcmcia_sock, socket) |
67 | 67 | ||
68 | static irqreturn_t cdirq(int irq, void *data) | 68 | static irqreturn_t cdirq(int irq, void *data) |
69 | { | 69 | { |
70 | struct xxs1500_pcmcia_sock *sock = data; | 70 | struct xxs1500_pcmcia_sock *sock = data; |
71 | 71 | ||
72 | pcmcia_parse_events(&sock->socket, SS_DETECT); | 72 | pcmcia_parse_events(&sock->socket, SS_DETECT); |
73 | 73 | ||
74 | return IRQ_HANDLED; | 74 | return IRQ_HANDLED; |
75 | } | 75 | } |
76 | 76 | ||
77 | static int xxs1500_pcmcia_configure(struct pcmcia_socket *skt, | 77 | static int xxs1500_pcmcia_configure(struct pcmcia_socket *skt, |
78 | struct socket_state_t *state) | 78 | struct socket_state_t *state) |
79 | { | 79 | { |
80 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | 80 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); |
81 | unsigned int changed; | 81 | unsigned int changed; |
82 | 82 | ||
83 | /* power control */ | 83 | /* power control */ |
84 | switch (state->Vcc) { | 84 | switch (state->Vcc) { |
85 | case 0: | 85 | case 0: |
86 | gpio_set_value(GPIO_POWER, 1); /* power off */ | 86 | gpio_set_value(GPIO_POWER, 1); /* power off */ |
87 | break; | 87 | break; |
88 | case 33: | 88 | case 33: |
89 | gpio_set_value(GPIO_POWER, 0); /* power on */ | 89 | gpio_set_value(GPIO_POWER, 0); /* power on */ |
90 | break; | 90 | break; |
91 | case 50: | 91 | case 50: |
92 | default: | 92 | default: |
93 | return -EINVAL; | 93 | return -EINVAL; |
94 | } | 94 | } |
95 | 95 | ||
96 | changed = state->flags ^ sock->old_flags; | 96 | changed = state->flags ^ sock->old_flags; |
97 | 97 | ||
98 | if (changed & SS_RESET) { | 98 | if (changed & SS_RESET) { |
99 | if (state->flags & SS_RESET) { | 99 | if (state->flags & SS_RESET) { |
100 | gpio_set_value(GPIO_RESET, 1); /* assert reset */ | 100 | gpio_set_value(GPIO_RESET, 1); /* assert reset */ |
101 | gpio_set_value(GPIO_OUTEN, 1); /* buffers off */ | 101 | gpio_set_value(GPIO_OUTEN, 1); /* buffers off */ |
102 | } else { | 102 | } else { |
103 | gpio_set_value(GPIO_RESET, 0); /* deassert reset */ | 103 | gpio_set_value(GPIO_RESET, 0); /* deassert reset */ |
104 | gpio_set_value(GPIO_OUTEN, 0); /* buffers on */ | 104 | gpio_set_value(GPIO_OUTEN, 0); /* buffers on */ |
105 | msleep(500); | 105 | msleep(500); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | sock->old_flags = state->flags; | 109 | sock->old_flags = state->flags; |
110 | 110 | ||
111 | return 0; | 111 | return 0; |
112 | } | 112 | } |
113 | 113 | ||
114 | static int xxs1500_pcmcia_get_status(struct pcmcia_socket *skt, | 114 | static int xxs1500_pcmcia_get_status(struct pcmcia_socket *skt, |
115 | unsigned int *value) | 115 | unsigned int *value) |
116 | { | 116 | { |
117 | unsigned int status; | 117 | unsigned int status; |
118 | int i; | 118 | int i; |
119 | 119 | ||
120 | status = 0; | 120 | status = 0; |
121 | 121 | ||
122 | /* check carddetects: GPIO[0:1] must both be low */ | 122 | /* check carddetects: GPIO[0:1] must both be low */ |
123 | if (!gpio_get_value(GPIO_CDA) && !gpio_get_value(GPIO_CDB)) | 123 | if (!gpio_get_value(GPIO_CDA) && !gpio_get_value(GPIO_CDB)) |
124 | status |= SS_DETECT; | 124 | status |= SS_DETECT; |
125 | 125 | ||
126 | /* determine card voltage: GPIO[208:209] binary value */ | 126 | /* determine card voltage: GPIO[208:209] binary value */ |
127 | i = (!!gpio_get_value(GPIO_VSL)) | ((!!gpio_get_value(GPIO_VSH)) << 1); | 127 | i = (!!gpio_get_value(GPIO_VSL)) | ((!!gpio_get_value(GPIO_VSH)) << 1); |
128 | 128 | ||
129 | switch (i) { | 129 | switch (i) { |
130 | case 0: | 130 | case 0: |
131 | case 1: | 131 | case 1: |
132 | case 2: | 132 | case 2: |
133 | status |= SS_3VCARD; /* 3V card */ | 133 | status |= SS_3VCARD; /* 3V card */ |
134 | break; | 134 | break; |
135 | case 3: /* 5V card, unsupported */ | 135 | case 3: /* 5V card, unsupported */ |
136 | default: | 136 | default: |
137 | status |= SS_XVCARD; /* treated as unsupported in core */ | 137 | status |= SS_XVCARD; /* treated as unsupported in core */ |
138 | } | 138 | } |
139 | 139 | ||
140 | /* GPIO214: low active power switch */ | 140 | /* GPIO214: low active power switch */ |
141 | status |= gpio_get_value(GPIO_POWER) ? 0 : SS_POWERON; | 141 | status |= gpio_get_value(GPIO_POWER) ? 0 : SS_POWERON; |
142 | 142 | ||
143 | /* GPIO204: high-active reset line */ | 143 | /* GPIO204: high-active reset line */ |
144 | status |= gpio_get_value(GPIO_RESET) ? SS_RESET : SS_READY; | 144 | status |= gpio_get_value(GPIO_RESET) ? SS_RESET : SS_READY; |
145 | 145 | ||
146 | /* other stuff */ | 146 | /* other stuff */ |
147 | status |= gpio_get_value(GPIO_BATTDEAD) ? 0 : SS_BATDEAD; | 147 | status |= gpio_get_value(GPIO_BATTDEAD) ? 0 : SS_BATDEAD; |
148 | status |= gpio_get_value(GPIO_BATTWARN) ? 0 : SS_BATWARN; | 148 | status |= gpio_get_value(GPIO_BATTWARN) ? 0 : SS_BATWARN; |
149 | 149 | ||
150 | *value = status; | 150 | *value = status; |
151 | 151 | ||
152 | return 0; | 152 | return 0; |
153 | } | 153 | } |
154 | 154 | ||
155 | static int xxs1500_pcmcia_sock_init(struct pcmcia_socket *skt) | 155 | static int xxs1500_pcmcia_sock_init(struct pcmcia_socket *skt) |
156 | { | 156 | { |
157 | gpio_direction_input(GPIO_CDA); | 157 | gpio_direction_input(GPIO_CDA); |
158 | gpio_direction_input(GPIO_CDB); | 158 | gpio_direction_input(GPIO_CDB); |
159 | gpio_direction_input(GPIO_VSL); | 159 | gpio_direction_input(GPIO_VSL); |
160 | gpio_direction_input(GPIO_VSH); | 160 | gpio_direction_input(GPIO_VSH); |
161 | gpio_direction_input(GPIO_BATTDEAD); | 161 | gpio_direction_input(GPIO_BATTDEAD); |
162 | gpio_direction_input(GPIO_BATTWARN); | 162 | gpio_direction_input(GPIO_BATTWARN); |
163 | gpio_direction_output(GPIO_RESET, 1); /* assert reset */ | 163 | gpio_direction_output(GPIO_RESET, 1); /* assert reset */ |
164 | gpio_direction_output(GPIO_OUTEN, 1); /* disable buffers */ | 164 | gpio_direction_output(GPIO_OUTEN, 1); /* disable buffers */ |
165 | gpio_direction_output(GPIO_POWER, 1); /* power off */ | 165 | gpio_direction_output(GPIO_POWER, 1); /* power off */ |
166 | 166 | ||
167 | return 0; | 167 | return 0; |
168 | } | 168 | } |
169 | 169 | ||
170 | static int xxs1500_pcmcia_sock_suspend(struct pcmcia_socket *skt) | 170 | static int xxs1500_pcmcia_sock_suspend(struct pcmcia_socket *skt) |
171 | { | 171 | { |
172 | return 0; | 172 | return 0; |
173 | } | 173 | } |
174 | 174 | ||
175 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, | 175 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, |
176 | struct pccard_io_map *map) | 176 | struct pccard_io_map *map) |
177 | { | 177 | { |
178 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | 178 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); |
179 | 179 | ||
180 | map->start = (u32)sock->virt_io; | 180 | map->start = (u32)sock->virt_io; |
181 | map->stop = map->start + IO_MAP_SIZE; | 181 | map->stop = map->start + IO_MAP_SIZE; |
182 | 182 | ||
183 | return 0; | 183 | return 0; |
184 | } | 184 | } |
185 | 185 | ||
186 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, | 186 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, |
187 | struct pccard_mem_map *map) | 187 | struct pccard_mem_map *map) |
188 | { | 188 | { |
189 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | 189 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); |
190 | 190 | ||
191 | if (map->flags & MAP_ATTRIB) | 191 | if (map->flags & MAP_ATTRIB) |
192 | map->static_start = sock->phys_attr + map->card_start; | 192 | map->static_start = sock->phys_attr + map->card_start; |
193 | else | 193 | else |
194 | map->static_start = sock->phys_mem + map->card_start; | 194 | map->static_start = sock->phys_mem + map->card_start; |
195 | 195 | ||
196 | return 0; | 196 | return 0; |
197 | } | 197 | } |
198 | 198 | ||
199 | static struct pccard_operations xxs1500_pcmcia_operations = { | 199 | static struct pccard_operations xxs1500_pcmcia_operations = { |
200 | .init = xxs1500_pcmcia_sock_init, | 200 | .init = xxs1500_pcmcia_sock_init, |
201 | .suspend = xxs1500_pcmcia_sock_suspend, | 201 | .suspend = xxs1500_pcmcia_sock_suspend, |
202 | .get_status = xxs1500_pcmcia_get_status, | 202 | .get_status = xxs1500_pcmcia_get_status, |
203 | .set_socket = xxs1500_pcmcia_configure, | 203 | .set_socket = xxs1500_pcmcia_configure, |
204 | .set_io_map = au1x00_pcmcia_set_io_map, | 204 | .set_io_map = au1x00_pcmcia_set_io_map, |
205 | .set_mem_map = au1x00_pcmcia_set_mem_map, | 205 | .set_mem_map = au1x00_pcmcia_set_mem_map, |
206 | }; | 206 | }; |
207 | 207 | ||
208 | static int __devinit xxs1500_pcmcia_probe(struct platform_device *pdev) | 208 | static int __devinit xxs1500_pcmcia_probe(struct platform_device *pdev) |
209 | { | 209 | { |
210 | struct xxs1500_pcmcia_sock *sock; | 210 | struct xxs1500_pcmcia_sock *sock; |
211 | struct resource *r; | 211 | struct resource *r; |
212 | int ret, irq; | 212 | int ret, irq; |
213 | 213 | ||
214 | sock = kzalloc(sizeof(struct xxs1500_pcmcia_sock), GFP_KERNEL); | 214 | sock = kzalloc(sizeof(struct xxs1500_pcmcia_sock), GFP_KERNEL); |
215 | if (!sock) | 215 | if (!sock) |
216 | return -ENOMEM; | 216 | return -ENOMEM; |
217 | 217 | ||
218 | ret = -ENODEV; | 218 | ret = -ENODEV; |
219 | 219 | ||
220 | /* 36bit PCMCIA Attribute area address */ | 220 | /* 36bit PCMCIA Attribute area address */ |
221 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); | 221 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr"); |
222 | if (!r) { | 222 | if (!r) { |
223 | dev_err(&pdev->dev, "missing 'pcmcia-attr' resource!\n"); | 223 | dev_err(&pdev->dev, "missing 'pcmcia-attr' resource!\n"); |
224 | goto out0; | 224 | goto out0; |
225 | } | 225 | } |
226 | sock->phys_attr = r->start; | 226 | sock->phys_attr = r->start; |
227 | 227 | ||
228 | /* 36bit PCMCIA Memory area address */ | 228 | /* 36bit PCMCIA Memory area address */ |
229 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); | 229 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem"); |
230 | if (!r) { | 230 | if (!r) { |
231 | dev_err(&pdev->dev, "missing 'pcmcia-mem' resource!\n"); | 231 | dev_err(&pdev->dev, "missing 'pcmcia-mem' resource!\n"); |
232 | goto out0; | 232 | goto out0; |
233 | } | 233 | } |
234 | sock->phys_mem = r->start; | 234 | sock->phys_mem = r->start; |
235 | 235 | ||
236 | /* 36bit PCMCIA IO area address */ | 236 | /* 36bit PCMCIA IO area address */ |
237 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); | 237 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io"); |
238 | if (!r) { | 238 | if (!r) { |
239 | dev_err(&pdev->dev, "missing 'pcmcia-io' resource!\n"); | 239 | dev_err(&pdev->dev, "missing 'pcmcia-io' resource!\n"); |
240 | goto out0; | 240 | goto out0; |
241 | } | 241 | } |
242 | sock->phys_io = r->start; | 242 | sock->phys_io = r->start; |
243 | 243 | ||
244 | 244 | ||
245 | /* | 245 | /* |
246 | * PCMCIA client drivers use the inb/outb macros to access | 246 | * PCMCIA client drivers use the inb/outb macros to access |
247 | * the IO registers. Since mips_io_port_base is added | 247 | * the IO registers. Since mips_io_port_base is added |
248 | * to the access address of the mips implementation of | 248 | * to the access address of the mips implementation of |
249 | * inb/outb, we need to subtract it here because we want | 249 | * inb/outb, we need to subtract it here because we want |
250 | * to access the I/O or MEM address directly, without | 250 | * to access the I/O or MEM address directly, without |
251 | * going through this "mips_io_port_base" mechanism. | 251 | * going through this "mips_io_port_base" mechanism. |
252 | */ | 252 | */ |
253 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - | 253 | sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) - |
254 | mips_io_port_base); | 254 | mips_io_port_base); |
255 | 255 | ||
256 | if (!sock->virt_io) { | 256 | if (!sock->virt_io) { |
257 | dev_err(&pdev->dev, "cannot remap IO area\n"); | 257 | dev_err(&pdev->dev, "cannot remap IO area\n"); |
258 | ret = -ENOMEM; | 258 | ret = -ENOMEM; |
259 | goto out0; | 259 | goto out0; |
260 | } | 260 | } |
261 | 261 | ||
262 | sock->socket.ops = &xxs1500_pcmcia_operations; | 262 | sock->socket.ops = &xxs1500_pcmcia_operations; |
263 | sock->socket.owner = THIS_MODULE; | 263 | sock->socket.owner = THIS_MODULE; |
264 | sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ); | 264 | sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ); |
265 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | 265 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; |
266 | sock->socket.map_size = MEM_MAP_SIZE; | 266 | sock->socket.map_size = MEM_MAP_SIZE; |
267 | sock->socket.io_offset = (unsigned long)sock->virt_io; | 267 | sock->socket.io_offset = (unsigned long)sock->virt_io; |
268 | sock->socket.dev.parent = &pdev->dev; | 268 | sock->socket.dev.parent = &pdev->dev; |
269 | sock->socket.resource_ops = &pccard_static_ops; | 269 | sock->socket.resource_ops = &pccard_static_ops; |
270 | 270 | ||
271 | platform_set_drvdata(pdev, sock); | 271 | platform_set_drvdata(pdev, sock); |
272 | 272 | ||
273 | /* setup carddetect irq: use one of the 2 GPIOs as an | 273 | /* setup carddetect irq: use one of the 2 GPIOs as an |
274 | * edge detector. | 274 | * edge detector. |
275 | */ | 275 | */ |
276 | irq = gpio_to_irq(GPIO_CDA); | 276 | irq = gpio_to_irq(GPIO_CDA); |
277 | irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); | 277 | irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); |
278 | ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock); | 278 | ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock); |
279 | if (ret) { | 279 | if (ret) { |
280 | dev_err(&pdev->dev, "cannot setup cd irq\n"); | 280 | dev_err(&pdev->dev, "cannot setup cd irq\n"); |
281 | goto out1; | 281 | goto out1; |
282 | } | 282 | } |
283 | 283 | ||
284 | ret = pcmcia_register_socket(&sock->socket); | 284 | ret = pcmcia_register_socket(&sock->socket); |
285 | if (ret) { | 285 | if (ret) { |
286 | dev_err(&pdev->dev, "failed to register\n"); | 286 | dev_err(&pdev->dev, "failed to register\n"); |
287 | goto out2; | 287 | goto out2; |
288 | } | 288 | } |
289 | 289 | ||
290 | printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n"); | 290 | printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n"); |
291 | 291 | ||
292 | return 0; | 292 | return 0; |
293 | 293 | ||
294 | out2: | 294 | out2: |
295 | free_irq(gpio_to_irq(GPIO_CDA), sock); | 295 | free_irq(gpio_to_irq(GPIO_CDA), sock); |
296 | out1: | 296 | out1: |
297 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | 297 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); |
298 | out0: | 298 | out0: |
299 | kfree(sock); | 299 | kfree(sock); |
300 | return ret; | 300 | return ret; |
301 | } | 301 | } |
302 | 302 | ||
303 | static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev) | 303 | static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev) |
304 | { | 304 | { |
305 | struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev); | 305 | struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev); |
306 | 306 | ||
307 | pcmcia_unregister_socket(&sock->socket); | 307 | pcmcia_unregister_socket(&sock->socket); |
308 | free_irq(gpio_to_irq(GPIO_CDA), sock); | 308 | free_irq(gpio_to_irq(GPIO_CDA), sock); |
309 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | 309 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); |
310 | kfree(sock); | 310 | kfree(sock); |
311 | 311 | ||
312 | return 0; | 312 | return 0; |
313 | } | 313 | } |
314 | 314 | ||
315 | static struct platform_driver xxs1500_pcmcia_socket_driver = { | 315 | static struct platform_driver xxs1500_pcmcia_socket_driver = { |
316 | .driver = { | 316 | .driver = { |
317 | .name = "xxs1500_pcmcia", | 317 | .name = "xxs1500_pcmcia", |
318 | .owner = THIS_MODULE, | 318 | .owner = THIS_MODULE, |
319 | }, | 319 | }, |
320 | .probe = xxs1500_pcmcia_probe, | 320 | .probe = xxs1500_pcmcia_probe, |
321 | .remove = __devexit_p(xxs1500_pcmcia_remove), | 321 | .remove = __devexit_p(xxs1500_pcmcia_remove), |
322 | }; | 322 | }; |
323 | 323 | ||
324 | int __init xxs1500_pcmcia_socket_load(void) | 324 | module_platform_driver(xxs1500_pcmcia_socket_driver); |
325 | { | ||
326 | return platform_driver_register(&xxs1500_pcmcia_socket_driver); | ||
327 | } | ||
328 | |||
329 | void __exit xxs1500_pcmcia_socket_unload(void) | ||
330 | { | ||
331 | platform_driver_unregister(&xxs1500_pcmcia_socket_driver); | ||
332 | } | ||
333 | |||
334 | module_init(xxs1500_pcmcia_socket_load); | ||
335 | module_exit(xxs1500_pcmcia_socket_unload); | ||
336 | 325 | ||
337 | MODULE_LICENSE("GPL"); | 326 | MODULE_LICENSE("GPL"); |
338 | MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems"); | 327 | MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems"); |
339 | MODULE_AUTHOR("Manuel Lauss"); | 328 | MODULE_AUTHOR("Manuel Lauss"); |
340 | 329 |