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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
|
/*
* PCMCIA socket code for the Alchemy Db1xxx/Pb1xxx boards.
*
* Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com>
*
*/
/* This is a fairly generic PCMCIA socket driver suitable for the
* following Alchemy Development boards:
* Db1000, Db/Pb1500, Db/Pb1100, Db/Pb1550, Db/Pb1200, Db1300
*
* The Db1000 is used as a reference: Per-socket card-, carddetect- and
* statuschange IRQs connected to SoC GPIOs, control and status register
* bits arranged in per-socket groups in an external PLD. All boards
* listed here use this layout, including bit positions and meanings.
* Of course there are exceptions in later boards:
*
* - Pb1100/Pb1500: single socket only; voltage key bits VS are
* at STATUS[5:4] (instead of STATUS[1:0]).
* - Au1200-based: additional card-eject irqs, irqs not gpios!
* - Db1300: Db1200-like, no pwr ctrl, single socket (#1).
*/
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/pm.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/resource.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <pcmcia/ss.h>
#include <asm/mach-au1x00/au1000.h>
#include <asm/mach-db1x00/bcsr.h>
#define MEM_MAP_SIZE 0x400000
#define IO_MAP_SIZE 0x1000
struct db1x_pcmcia_sock {
struct pcmcia_socket socket;
int nr; /* socket number */
void *virt_io;
phys_addr_t phys_io;
phys_addr_t phys_attr;
phys_addr_t phys_mem;
/* previous flags for set_socket() */
unsigned int old_flags;
/* interrupt sources: linux irq numbers! */
int insert_irq; /* default carddetect irq */
int stschg_irq; /* card-status-change irq */
int card_irq; /* card irq */
int eject_irq; /* db1200/pb1200 have these */
#define BOARD_TYPE_DEFAULT 0 /* most boards */
#define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */
#define BOARD_TYPE_PB1100 2 /* VS bits slightly different */
#define BOARD_TYPE_DB1300 3 /* no power control */
int board_type;
};
#define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket)
static int db1300_card_inserted(struct db1x_pcmcia_sock *sock)
{
return bcsr_read(BCSR_SIGSTAT) & (1 << 8);
}
/* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */
static int db1200_card_inserted(struct db1x_pcmcia_sock *sock)
{
unsigned short sigstat;
sigstat = bcsr_read(BCSR_SIGSTAT);
return sigstat & 1 << (8 + 2 * sock->nr);
}
/* carddetect gpio: low-active */
static int db1000_card_inserted(struct db1x_pcmcia_sock *sock)
{
return !gpio_get_value(irq_to_gpio(sock->insert_irq));
}
static int db1x_card_inserted(struct db1x_pcmcia_sock *sock)
{
switch (sock->board_type) {
case BOARD_TYPE_DB1200:
return db1200_card_inserted(sock);
case BOARD_TYPE_DB1300:
return db1300_card_inserted(sock);
default:
return db1000_card_inserted(sock);
}
}
/* STSCHG tends to bounce heavily when cards are inserted/ejected.
* To avoid this, the interrupt is normally disabled and only enabled
* after reset to a card has been de-asserted.
*/
static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en)
{
if (sock->stschg_irq != -1) {
if (en)
enable_irq(sock->stschg_irq);
else
disable_irq(sock->stschg_irq);
}
}
static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data)
{
struct db1x_pcmcia_sock *sock = data;
pcmcia_parse_events(&sock->socket, SS_DETECT);
return IRQ_HANDLED;
}
static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data)
{
struct db1x_pcmcia_sock *sock = data;
pcmcia_parse_events(&sock->socket, SS_STSCHG);
return IRQ_HANDLED;
}
static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data)
{
struct db1x_pcmcia_sock *sock = data;
/* Db/Pb1200 have separate per-socket insertion and ejection
* interrupts which stay asserted as long as the card is
* inserted/missing. The one which caused us to be called
* needs to be disabled and the other one enabled.
*/
if (irq == sock->insert_irq) {
disable_irq_nosync(sock->insert_irq);
enable_irq(sock->eject_irq);
} else {
disable_irq_nosync(sock->eject_irq);
enable_irq(sock->insert_irq);
}
pcmcia_parse_events(&sock->socket, SS_DETECT);
return IRQ_HANDLED;
}
static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock)
{
int ret;
if (sock->stschg_irq != -1) {
ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq,
0, "pcmcia_stschg", sock);
if (ret)
return ret;
}
/* Db/Pb1200 have separate per-socket insertion and ejection
* interrupts, which should show edge behaviour but don't.
* So interrupts are disabled until both insertion and
* ejection handler have been registered and the currently
* active one disabled.
*/
if ((sock->board_type == BOARD_TYPE_DB1200) ||
(sock->board_type == BOARD_TYPE_DB1300)) {
ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq,
0, "pcmcia_insert", sock);
if (ret)
goto out1;
ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq,
0, "pcmcia_eject", sock);
if (ret) {
free_irq(sock->insert_irq, sock);
goto out1;
}
/* enable the currently silent one */
if (db1x_card_inserted(sock))
enable_irq(sock->eject_irq);
else
enable_irq(sock->insert_irq);
} else {
/* all other (older) Db1x00 boards use a GPIO to show
* card detection status: use both-edge triggers.
*/
irq_set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH);
ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq,
0, "pcmcia_carddetect", sock);
if (ret)
goto out1;
}
return 0; /* all done */
out1:
if (sock->stschg_irq != -1)
free_irq(sock->stschg_irq, sock);
return ret;
}
static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock)
{
if (sock->stschg_irq != -1)
free_irq(sock->stschg_irq, sock);
free_irq(sock->insert_irq, sock);
if (sock->eject_irq != -1)
free_irq(sock->eject_irq, sock);
}
/*
* configure a PCMCIA socket on the Db1x00 series of boards (and
* compatibles).
*
* 2 external registers are involved:
* pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id
* pcmcia_control(offset 0x10):
* bits[0:1] set vcc for card
* bits[2:3] set vpp for card
* bit 4: enable data buffers
* bit 7: reset# for card
* add 8 for second socket.
*/
static int db1x_pcmcia_configure(struct pcmcia_socket *skt,
struct socket_state_t *state)
{
struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
unsigned short cr_clr, cr_set;
unsigned int changed;
int v, p, ret;
/* card voltage setup */
cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */
cr_set = 0;
v = p = ret = 0;
switch (state->Vcc) {
case 50:
++v;
case 33:
++v;
case 0:
break;
default:
printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n",
sock->nr, state->Vcc);
}
switch (state->Vpp) {
case 12:
++p;
case 33:
case 50:
++p;
case 0:
break;
default:
printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n",
sock->nr, state->Vpp);
}
/* sanity check: Vpp must be 0, 12, or Vcc */
if (((state->Vcc == 33) && (state->Vpp == 50)) ||
((state->Vcc == 50) && (state->Vpp == 33))) {
printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n",
sock->nr, state->Vcc, state->Vpp);
v = p =
|