This source file includes following definitions.
- db1300_card_inserted
- db1200_card_inserted
- db1000_card_inserted
- db1x_card_inserted
- set_stschg
- db1000_pcmcia_cdirq
- db1000_pcmcia_stschgirq
- db1200_pcmcia_cdirq
- db1200_pcmcia_cdirq_fn
- db1x_pcmcia_setup_irqs
- db1x_pcmcia_free_irqs
- db1x_pcmcia_configure
- db1x_pcmcia_get_status
- db1x_pcmcia_sock_init
- db1x_pcmcia_sock_suspend
- au1x00_pcmcia_set_io_map
- au1x00_pcmcia_set_mem_map
- db1x_pcmcia_socket_probe
- db1x_pcmcia_socket_remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include <linux/delay.h>
26 #include <linux/gpio.h>
27 #include <linux/interrupt.h>
28 #include <linux/pm.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <linux/resource.h>
32 #include <linux/slab.h>
33 #include <linux/spinlock.h>
34
35 #include <pcmcia/ss.h>
36
37 #include <asm/mach-au1x00/au1000.h>
38 #include <asm/mach-db1x00/bcsr.h>
39
40 #define MEM_MAP_SIZE 0x400000
41 #define IO_MAP_SIZE 0x1000
42
43 struct db1x_pcmcia_sock {
44 struct pcmcia_socket socket;
45 int nr;
46 void *virt_io;
47
48 phys_addr_t phys_io;
49 phys_addr_t phys_attr;
50 phys_addr_t phys_mem;
51
52
53 unsigned int old_flags;
54
55
56 int insert_irq;
57 int stschg_irq;
58 int card_irq;
59 int eject_irq;
60 int insert_gpio;
61
62 #define BOARD_TYPE_DEFAULT 0
63 #define BOARD_TYPE_DB1200 1
64 #define BOARD_TYPE_PB1100 2
65 #define BOARD_TYPE_DB1300 3
66 int board_type;
67 };
68
69 #define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket)
70
71 static int db1300_card_inserted(struct db1x_pcmcia_sock *sock)
72 {
73 return bcsr_read(BCSR_SIGSTAT) & (1 << 8);
74 }
75
76
77 static int db1200_card_inserted(struct db1x_pcmcia_sock *sock)
78 {
79 unsigned short sigstat;
80
81 sigstat = bcsr_read(BCSR_SIGSTAT);
82 return sigstat & 1 << (8 + 2 * sock->nr);
83 }
84
85
86 static int db1000_card_inserted(struct db1x_pcmcia_sock *sock)
87 {
88 return !gpio_get_value(sock->insert_gpio);
89 }
90
91 static int db1x_card_inserted(struct db1x_pcmcia_sock *sock)
92 {
93 switch (sock->board_type) {
94 case BOARD_TYPE_DB1200:
95 return db1200_card_inserted(sock);
96 case BOARD_TYPE_DB1300:
97 return db1300_card_inserted(sock);
98 default:
99 return db1000_card_inserted(sock);
100 }
101 }
102
103
104
105
106
107 static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en)
108 {
109 if (sock->stschg_irq != -1) {
110 if (en)
111 enable_irq(sock->stschg_irq);
112 else
113 disable_irq(sock->stschg_irq);
114 }
115 }
116
117 static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data)
118 {
119 struct db1x_pcmcia_sock *sock = data;
120
121 pcmcia_parse_events(&sock->socket, SS_DETECT);
122
123 return IRQ_HANDLED;
124 }
125
126 static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data)
127 {
128 struct db1x_pcmcia_sock *sock = data;
129
130 pcmcia_parse_events(&sock->socket, SS_STSCHG);
131
132 return IRQ_HANDLED;
133 }
134
135
136
137
138
139
140 static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data)
141 {
142 disable_irq_nosync(irq);
143 return IRQ_WAKE_THREAD;
144 }
145
146 static irqreturn_t db1200_pcmcia_cdirq_fn(int irq, void *data)
147 {
148 struct db1x_pcmcia_sock *sock = data;
149
150
151 msleep(100);
152 if (irq == sock->insert_irq)
153 enable_irq(sock->eject_irq);
154 else
155 enable_irq(sock->insert_irq);
156
157 pcmcia_parse_events(&sock->socket, SS_DETECT);
158
159 return IRQ_HANDLED;
160 }
161
162 static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock)
163 {
164 int ret;
165
166 if (sock->stschg_irq != -1) {
167 ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq,
168 0, "pcmcia_stschg", sock);
169 if (ret)
170 return ret;
171 }
172
173
174
175
176
177
178
179 if ((sock->board_type == BOARD_TYPE_DB1200) ||
180 (sock->board_type == BOARD_TYPE_DB1300)) {
181 ret = request_threaded_irq(sock->insert_irq, db1200_pcmcia_cdirq,
182 db1200_pcmcia_cdirq_fn, 0, "pcmcia_insert", sock);
183 if (ret)
184 goto out1;
185
186 ret = request_threaded_irq(sock->eject_irq, db1200_pcmcia_cdirq,
187 db1200_pcmcia_cdirq_fn, 0, "pcmcia_eject", sock);
188 if (ret) {
189 free_irq(sock->insert_irq, sock);
190 goto out1;
191 }
192
193
194 if (db1x_card_inserted(sock))
195 enable_irq(sock->eject_irq);
196 else
197 enable_irq(sock->insert_irq);
198 } else {
199
200
201
202 irq_set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH);
203 ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq,
204 0, "pcmcia_carddetect", sock);
205
206 if (ret)
207 goto out1;
208 }
209
210 return 0;
211
212 out1:
213 if (sock->stschg_irq != -1)
214 free_irq(sock->stschg_irq, sock);
215
216 return ret;
217 }
218
219 static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock)
220 {
221 if (sock->stschg_irq != -1)
222 free_irq(sock->stschg_irq, sock);
223
224 free_irq(sock->insert_irq, sock);
225 if (sock->eject_irq != -1)
226 free_irq(sock->eject_irq, sock);
227 }
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242 static int db1x_pcmcia_configure(struct pcmcia_socket *skt,
243 struct socket_state_t *state)
244 {
245 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
246 unsigned short cr_clr, cr_set;
247 unsigned int changed;
248 int v, p, ret;
249
250
251 cr_clr = (0xf << (sock->nr * 8));
252 cr_set = 0;
253 v = p = ret = 0;
254
255 switch (state->Vcc) {
256 case 50:
257 ++v;
258
259 case 33:
260 ++v;
261
262 case 0:
263 break;
264 default:
265 printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n",
266 sock->nr, state->Vcc);
267 }
268
269 switch (state->Vpp) {
270 case 12:
271 ++p;
272
273 case 33:
274 case 50:
275 ++p;
276
277 case 0:
278 break;
279 default:
280 printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n",
281 sock->nr, state->Vpp);
282 }
283
284
285 if (((state->Vcc == 33) && (state->Vpp == 50)) ||
286 ((state->Vcc == 50) && (state->Vpp == 33))) {
287 printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n",
288 sock->nr, state->Vcc, state->Vpp);
289 v = p = 0;
290 ret = -EINVAL;
291 }
292
293
294 if (sock->board_type != BOARD_TYPE_DB1300)
295 cr_set |= ((v << 2) | p) << (sock->nr * 8);
296
297 changed = state->flags ^ sock->old_flags;
298
299 if (changed & SS_RESET) {
300 if (state->flags & SS_RESET) {
301 set_stschg(sock, 0);
302
303 cr_clr |= (1 << (7 + (sock->nr * 8)));
304 cr_clr |= (1 << (4 + (sock->nr * 8)));
305 } else {
306
307 cr_set |= 1 << (7 + (sock->nr * 8));
308 cr_set |= 1 << (4 + (sock->nr * 8));
309 }
310 }
311
312
313 bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set);
314
315 sock->old_flags = state->flags;
316
317
318 if ((changed & SS_RESET) && !(state->flags & SS_RESET)) {
319 msleep(500);
320 set_stschg(sock, 1);
321 }
322
323 return ret;
324 }
325
326
327 #define GET_VCC(cr, socknr) \
328 ((((cr) >> 2) >> ((socknr) * 8)) & 3)
329
330
331 #define GET_VS(sr, socknr) \
332 (((sr) >> (2 * (socknr))) & 3)
333
334
335 #define GET_RESET(cr, socknr) \
336 ((cr) & (1 << (7 + (8 * (socknr)))))
337
338 static int db1x_pcmcia_get_status(struct pcmcia_socket *skt,
339 unsigned int *value)
340 {
341 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
342 unsigned short cr, sr;
343 unsigned int status;
344
345 status = db1x_card_inserted(sock) ? SS_DETECT : 0;
346
347 cr = bcsr_read(BCSR_PCMCIA);
348 sr = bcsr_read(BCSR_STATUS);
349
350
351 if (sock->board_type == BOARD_TYPE_PB1100)
352 sr >>= 4;
353
354
355 switch (GET_VS(sr, sock->nr)) {
356 case 0:
357 case 2:
358 status |= SS_3VCARD;
359 case 3:
360 break;
361 default:
362 status |= SS_XVCARD;
363 }
364
365
366 status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0;
367
368
369 if ((sock->board_type == BOARD_TYPE_DB1300) && (status & SS_DETECT))
370 status = SS_POWERON | SS_3VCARD | SS_DETECT;
371
372
373 status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET;
374
375 *value = status;
376
377 return 0;
378 }
379
380 static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt)
381 {
382 return 0;
383 }
384
385 static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt)
386 {
387 return 0;
388 }
389
390 static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt,
391 struct pccard_io_map *map)
392 {
393 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
394
395 map->start = (u32)sock->virt_io;
396 map->stop = map->start + IO_MAP_SIZE;
397
398 return 0;
399 }
400
401 static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt,
402 struct pccard_mem_map *map)
403 {
404 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
405
406 if (map->flags & MAP_ATTRIB)
407 map->static_start = sock->phys_attr + map->card_start;
408 else
409 map->static_start = sock->phys_mem + map->card_start;
410
411 return 0;
412 }
413
414 static struct pccard_operations db1x_pcmcia_operations = {
415 .init = db1x_pcmcia_sock_init,
416 .suspend = db1x_pcmcia_sock_suspend,
417 .get_status = db1x_pcmcia_get_status,
418 .set_socket = db1x_pcmcia_configure,
419 .set_io_map = au1x00_pcmcia_set_io_map,
420 .set_mem_map = au1x00_pcmcia_set_mem_map,
421 };
422
423 static int db1x_pcmcia_socket_probe(struct platform_device *pdev)
424 {
425 struct db1x_pcmcia_sock *sock;
426 struct resource *r;
427 int ret, bid;
428
429 sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL);
430 if (!sock)
431 return -ENOMEM;
432
433 sock->nr = pdev->id;
434
435 bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
436 switch (bid) {
437 case BCSR_WHOAMI_PB1500:
438 case BCSR_WHOAMI_PB1500R2:
439 case BCSR_WHOAMI_PB1100:
440 sock->board_type = BOARD_TYPE_PB1100;
441 break;
442 case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR:
443 sock->board_type = BOARD_TYPE_DEFAULT;
444 break;
445 case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200:
446 sock->board_type = BOARD_TYPE_DB1200;
447 break;
448 case BCSR_WHOAMI_DB1300:
449 sock->board_type = BOARD_TYPE_DB1300;
450 break;
451 default:
452 printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid);
453 ret = -ENODEV;
454 goto out0;
455 };
456
457
458
459
460
461
462
463
464
465
466
467
468 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card");
469 sock->card_irq = r ? r->start : 0;
470
471
472
473
474 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert");
475 sock->insert_irq = r ? r->start : -1;
476 if (sock->board_type == BOARD_TYPE_DEFAULT) {
477 sock->insert_gpio = r ? r->start : -1;
478 sock->insert_irq = r ? gpio_to_irq(r->start) : -1;
479 }
480
481
482 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg");
483 sock->stschg_irq = r ? r->start : -1;
484
485
486 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject");
487 sock->eject_irq = r ? r->start : -1;
488
489 ret = -ENODEV;
490
491
492 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr");
493 if (!r) {
494 printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n",
495 sock->nr);
496 goto out0;
497 }
498 sock->phys_attr = r->start;
499
500
501 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem");
502 if (!r) {
503 printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n",
504 sock->nr);
505 goto out0;
506 }
507 sock->phys_mem = r->start;
508
509
510 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io");
511 if (!r) {
512 printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n",
513 sock->nr);
514 goto out0;
515 }
516 sock->phys_io = r->start;
517
518
519
520
521
522
523
524
525
526 sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) -
527 mips_io_port_base);
528
529 if (!sock->virt_io) {
530 printk(KERN_ERR "pcmcia%d: cannot remap IO area\n",
531 sock->nr);
532 ret = -ENOMEM;
533 goto out0;
534 }
535
536 sock->socket.ops = &db1x_pcmcia_operations;
537 sock->socket.owner = THIS_MODULE;
538 sock->socket.pci_irq = sock->card_irq;
539 sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD;
540 sock->socket.map_size = MEM_MAP_SIZE;
541 sock->socket.io_offset = (unsigned long)sock->virt_io;
542 sock->socket.dev.parent = &pdev->dev;
543 sock->socket.resource_ops = &pccard_static_ops;
544
545 platform_set_drvdata(pdev, sock);
546
547 ret = db1x_pcmcia_setup_irqs(sock);
548 if (ret) {
549 printk(KERN_ERR "pcmcia%d cannot setup interrupts\n",
550 sock->nr);
551 goto out1;
552 }
553
554 set_stschg(sock, 0);
555
556 ret = pcmcia_register_socket(&sock->socket);
557 if (ret) {
558 printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr);
559 goto out2;
560 }
561
562 printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx"
563 "(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d "
564 "%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io,
565 sock->phys_attr, sock->phys_mem, sock->card_irq,
566 sock->insert_irq, sock->stschg_irq, sock->eject_irq);
567
568 return 0;
569
570 out2:
571 db1x_pcmcia_free_irqs(sock);
572 out1:
573 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
574 out0:
575 kfree(sock);
576 return ret;
577 }
578
579 static int db1x_pcmcia_socket_remove(struct platform_device *pdev)
580 {
581 struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev);
582
583 db1x_pcmcia_free_irqs(sock);
584 pcmcia_unregister_socket(&sock->socket);
585 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
586 kfree(sock);
587
588 return 0;
589 }
590
591 static struct platform_driver db1x_pcmcia_socket_driver = {
592 .driver = {
593 .name = "db1xxx_pcmcia",
594 },
595 .probe = db1x_pcmcia_socket_probe,
596 .remove = db1x_pcmcia_socket_remove,
597 };
598
599 module_platform_driver(db1x_pcmcia_socket_driver);
600
601 MODULE_LICENSE("GPL");
602 MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards");
603 MODULE_AUTHOR("Manuel Lauss");