blob: c2239a7e383a969221ccdf2e65c0a27e06446da7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/pcmcia/m32r_pcc.c
3 *
4 * Device driver for the PCMCIA functionality of M32R.
5 *
6 * Copyright (c) 2001, 2002, 2003, 2004
7 * Hiroyuki Kondo, Naoto Sugai, Hayato Fujiwara
8 */
9
10#include <linux/module.h>
11#include <linux/moduleparam.h>
12#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/types.h>
14#include <linux/fcntl.h>
15#include <linux/string.h>
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/ioport.h>
20#include <linux/delay.h>
21#include <linux/workqueue.h>
22#include <linux/interrupt.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010023#include <linux/platform_device.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070024#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/irq.h>
26#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/addrspace.h>
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <pcmcia/ss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* XXX: should be moved into asm/irq.h */
32#define PCC0_IRQ 24
33#define PCC1_IRQ 25
34
35#include "m32r_pcc.h"
36
37#define CHAOS_PCC_DEBUG
38#ifdef CHAOS_PCC_DEBUG
39 static volatile u_short dummy_readbuf;
40#endif
41
42#define PCC_DEBUG_DBEX
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/* Poll status interval -- 0 means default to interrupt */
46static int poll_interval = 0;
47
48typedef enum pcc_space { as_none = 0, as_comm, as_attr, as_io } pcc_as_t;
49
50typedef struct pcc_socket {
51 u_short type, flags;
52 struct pcmcia_socket socket;
53 unsigned int number;
Olof Johansson906da802008-02-04 22:27:35 -080054 unsigned int ioaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 u_long mapaddr;
56 u_long base; /* PCC register base */
57 u_char cs_irq, intr;
58 pccard_io_map io_map[MAX_IO_WIN];
59 pccard_mem_map mem_map[MAX_WIN];
60 u_char io_win;
61 u_char mem_win;
62 pcc_as_t current_space;
63 u_char last_iodbex;
64#ifdef CHAOS_PCC_DEBUG
65 u_char last_iosize;
66#endif
67#ifdef CONFIG_PROC_FS
68 struct proc_dir_entry *proc;
69#endif
70} pcc_socket_t;
71
72static int pcc_sockets = 0;
73static pcc_socket_t socket[M32R_MAX_PCC] = {
74 { 0, }, /* ... */
75};
76
77/*====================================================================*/
78
79static unsigned int pcc_get(u_short, unsigned int);
80static void pcc_set(u_short, unsigned int , unsigned int );
81
82static DEFINE_SPINLOCK(pcc_lock);
83
84void pcc_iorw(int sock, unsigned long port, void *buf, size_t size, size_t nmemb, int wr, int flag)
85{
86 u_long addr;
87 u_long flags;
88 int need_ex;
89#ifdef PCC_DEBUG_DBEX
90 int _dbex;
91#endif
92 pcc_socket_t *t = &socket[sock];
93#ifdef CHAOS_PCC_DEBUG
94 int map_changed = 0;
95#endif
96
97 /* Need lock ? */
98 spin_lock_irqsave(&pcc_lock, flags);
99
100 /*
101 * Check if need dbex
102 */
103 need_ex = (size > 1 && flag == 0) ? PCMOD_DBEX : 0;
104#ifdef PCC_DEBUG_DBEX
105 _dbex = need_ex;
106 need_ex = 0;
107#endif
108
109 /*
110 * calculate access address
111 */
112 addr = t->mapaddr + port - t->ioaddr + KSEG1; /* XXX */
113
114 /*
115 * Check current mapping
116 */
117 if (t->current_space != as_io || t->last_iodbex != need_ex) {
118
119 u_long cbsz;
120
121 /*
122 * Disable first
123 */
124 pcc_set(sock, PCCR, 0);
125
126 /*
127 * Set mode and io address
128 */
129 cbsz = (t->flags & MAP_16BIT) ? 0 : PCMOD_CBSZ;
130 pcc_set(sock, PCMOD, PCMOD_AS_IO | cbsz | need_ex);
131 pcc_set(sock, PCADR, addr & 0x1ff00000);
132
133 /*
134 * Enable and read it
135 */
136 pcc_set(sock, PCCR, 1);
137
138#ifdef CHAOS_PCC_DEBUG
139#if 0
140 map_changed = (t->current_space == as_attr && size == 2); /* XXX */
141#else
142 map_changed = 1;
143#endif
144#endif
145 t->current_space = as_io;
146 }
147
148 /*
149 * access to IO space
150 */
151 if (size == 1) {
152 /* Byte */
153 unsigned char *bp = (unsigned char *)buf;
154
155#ifdef CHAOS_DEBUG
156 if (map_changed) {
157 dummy_readbuf = readb(addr);
158 }
159#endif
160 if (wr) {
161 /* write Byte */
162 while (nmemb--) {
163 writeb(*bp++, addr);
164 }
165 } else {
166 /* read Byte */
167 while (nmemb--) {
168 *bp++ = readb(addr);
169 }
170 }
171 } else {
172 /* Word */
173 unsigned short *bp = (unsigned short *)buf;
174
175#ifdef CHAOS_PCC_DEBUG
176 if (map_changed) {
177 dummy_readbuf = readw(addr);
178 }
179#endif
180 if (wr) {
181 /* write Word */
182 while (nmemb--) {
183#ifdef PCC_DEBUG_DBEX
184 if (_dbex) {
185 unsigned char *cp = (unsigned char *)bp;
186 unsigned short tmp;
187 tmp = cp[1] << 8 | cp[0];
188 writew(tmp, addr);
189 bp++;
190 } else
191#endif
192 writew(*bp++, addr);
193 }
194 } else {
195 /* read Word */
196 while (nmemb--) {
197#ifdef PCC_DEBUG_DBEX
198 if (_dbex) {
199 unsigned char *cp = (unsigned char *)bp;
200 unsigned short tmp;
201 tmp = readw(addr);
202 cp[0] = tmp & 0xff;
203 cp[1] = (tmp >> 8) & 0xff;
204 bp++;
205 } else
206#endif
207 *bp++ = readw(addr);
208 }
209 }
210 }
211
212#if 1
213 /* addr is no longer used */
214 if ((addr = pcc_get(sock, PCIRC)) & PCIRC_BWERR) {
215 printk("m32r_pcc: BWERR detected : port 0x%04lx : iosize %dbit\n",
216 port, size * 8);
217 pcc_set(sock, PCIRC, addr);
218 }
219#endif
220 /*
221 * save state
222 */
223 t->last_iosize = size;
224 t->last_iodbex = need_ex;
225
226 /* Need lock ? */
227
228 spin_unlock_irqrestore(&pcc_lock,flags);
229
230 return;
231}
232
233void pcc_ioread(int sock, unsigned long port, void *buf, size_t size, size_t nmemb, int flag) {
234 pcc_iorw(sock, port, buf, size, nmemb, 0, flag);
235}
236
237void pcc_iowrite(int sock, unsigned long port, void *buf, size_t size, size_t nmemb, int flag) {
238 pcc_iorw(sock, port, buf, size, nmemb, 1, flag);
239}
240
241/*====================================================================*/
242
243#define IS_REGISTERED 0x2000
244#define IS_ALIVE 0x8000
245
246typedef struct pcc_t {
247 char *name;
248 u_short flags;
249} pcc_t;
250
251static pcc_t pcc[] = {
252 { "xnux2", 0 }, { "xnux2", 0 },
253};
254
David Howells7d12e782006-10-05 14:55:46 +0100255static irqreturn_t pcc_interrupt(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257/*====================================================================*/
258
259static struct timer_list poll_timer;
260
261static unsigned int pcc_get(u_short sock, unsigned int reg)
262{
263 return inl(socket[sock].base + reg);
264}
265
266
267static void pcc_set(u_short sock, unsigned int reg, unsigned int data)
268{
269 outl(data, socket[sock].base + reg);
270}
271
272/*======================================================================
273
274 See if a card is present, powered up, in IO mode, and already
275 bound to a (non PC Card) Linux driver. We leave these alone.
276
277 We make an exception for cards that seem to be serial devices.
278
279======================================================================*/
280
281static int __init is_alive(u_short sock)
282{
283 unsigned int stat;
284 unsigned int f;
285
286 stat = pcc_get(sock, PCIRC);
287 f = (stat & (PCIRC_CDIN1 | PCIRC_CDIN2)) >> 16;
288 if(!f){
289 printk("m32r_pcc: No Card is detected at socket %d : stat = 0x%08x\n",stat,sock);
290 return 0;
291 }
292 if(f!=3)
293 printk("m32r_pcc: Insertion fail (%.8x) at socket %d\n",stat,sock);
294 else
295 printk("m32r_pcc: Card is Inserted at socket %d(%.8x)\n",sock,stat);
296 return 0;
297}
298
Sudip Mukherjee4170a202016-12-12 16:40:59 -0800299static int add_pcc_socket(ulong base, int irq, ulong mapaddr,
300 unsigned int ioaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 pcc_socket_t *t = &socket[pcc_sockets];
Sudip Mukherjee4170a202016-12-12 16:40:59 -0800303 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* add sockets */
306 t->ioaddr = ioaddr;
307 t->mapaddr = mapaddr;
308 t->base = base;
309#ifdef CHAOS_PCC_DEBUG
310 t->flags = MAP_16BIT;
311#else
312 t->flags = 0;
313#endif
314 if (is_alive(pcc_sockets))
315 t->flags |= IS_ALIVE;
316
317 /* add pcc */
318 if (t->base > 0) {
319 request_region(t->base, 0x20, "m32r-pcc");
320 }
321
322 printk(KERN_INFO " %s ", pcc[pcc_sockets].name);
323 printk("pcc at 0x%08lx\n", t->base);
324
325 /* Update socket interrupt information, capabilities */
326 t->socket.features |= (SS_CAP_PCCARD | SS_CAP_STATIC_MAP);
327 t->socket.map_size = M32R_PCC_MAPSIZE;
328 t->socket.io_offset = ioaddr; /* use for io access offset */
329 t->socket.irq_mask = 0;
330 t->socket.pci_irq = 2 + pcc_sockets; /* XXX */
331
Sudip Mukherjee4170a202016-12-12 16:40:59 -0800332 err = request_irq(irq, pcc_interrupt, 0, "m32r-pcc", pcc_interrupt);
333 if (err) {
334 if (t->base > 0)
335 release_region(t->base, 0x20);
336 return err;
337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 pcc_sockets++;
340
Sudip Mukherjee4170a202016-12-12 16:40:59 -0800341 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344
345/*====================================================================*/
346
David Howells7d12e782006-10-05 14:55:46 +0100347static irqreturn_t pcc_interrupt(int irq, void *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 int i, j, irc;
350 u_int events, active;
351 int handled = 0;
352
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200353 pr_debug("m32r_pcc: pcc_interrupt(%d)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 for (j = 0; j < 20; j++) {
356 active = 0;
357 for (i = 0; i < pcc_sockets; i++) {
358 if ((socket[i].cs_irq != irq) &&
359 (socket[i].socket.pci_irq != irq))
360 continue;
361 handled = 1;
362 irc = pcc_get(i, PCIRC);
363 irc >>=16;
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200364 pr_debug("m32r_pcc: interrupt: socket %d pcirc 0x%02x ",
365 i, irc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 if (!irc)
367 continue;
368
369 events = (irc) ? SS_DETECT : 0;
370 events |= (pcc_get(i,PCCR) & PCCR_PCEN) ? SS_READY : 0;
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200371 pr_debug("m32r_pcc: event 0x%02x\n", events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 if (events)
374 pcmcia_parse_events(&socket[i].socket, events);
375
376 active |= events;
377 active = 0;
378 }
379 if (!active) break;
380 }
381 if (j == 20)
382 printk(KERN_NOTICE "m32r-pcc: infinite loop in interrupt handler\n");
383
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200384 pr_debug("m32r_pcc: interrupt done\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 return IRQ_RETVAL(handled);
387} /* pcc_interrupt */
388
Kees Cook35c3f852017-10-16 16:27:53 -0700389static void pcc_interrupt_wrapper(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Al Viro9c8e7f52006-10-07 16:29:18 +0100391 pcc_interrupt(0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 poll_timer.expires = jiffies + poll_interval;
393 add_timer(&poll_timer);
394}
395
396/*====================================================================*/
397
398static int _pcc_get_status(u_short sock, u_int *value)
399{
400 u_int status;
401
402 status = pcc_get(sock,PCIRC);
403 *value = ((status & PCIRC_CDIN1) && (status & PCIRC_CDIN2))
404 ? SS_DETECT : 0;
405
406 status = pcc_get(sock,PCCR);
407
408#if 0
409 *value |= (status & PCCR_PCEN) ? SS_READY : 0;
410#else
411 *value |= SS_READY; /* XXX: always */
412#endif
413
414 status = pcc_get(sock,PCCSIGCR);
415 *value |= (status & PCCSIGCR_VEN) ? SS_POWERON : 0;
416
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200417 pr_debug("m32r_pcc: GetStatus(%d) = %#4.4x\n", sock, *value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return 0;
419} /* _get_status */
420
421/*====================================================================*/
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423static int _pcc_set_socket(u_short sock, socket_state_t *state)
424{
425 u_long reg = 0;
426
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200427 pr_debug("m32r_pcc: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 "io_irq %d, csc_mask %#2.2x)", sock, state->flags,
429 state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
430
431 if (state->Vcc) {
432 /*
433 * 5V only
434 */
435 if (state->Vcc == 50) {
436 reg |= PCCSIGCR_VEN;
437 } else {
438 return -EINVAL;
439 }
440 }
441
442 if (state->flags & SS_RESET) {
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200443 pr_debug("m32r_pcc: :RESET\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 reg |= PCCSIGCR_CRST;
445 }
446 if (state->flags & SS_OUTPUT_ENA){
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200447 pr_debug("m32r_pcc: :OUTPUT_ENA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /* bit clear */
449 } else {
450 reg |= PCCSIGCR_SEN;
451 }
452
453 pcc_set(sock,PCCSIGCR,reg);
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if(state->flags & SS_IOCARD){
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200456 pr_debug("m32r_pcc: :IOCARD");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458 if (state->flags & SS_PWR_AUTO) {
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200459 pr_debug("m32r_pcc: :PWR_AUTO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461 if (state->csc_mask & SS_DETECT)
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200462 pr_debug("m32r_pcc: :csc-SS_DETECT");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (state->flags & SS_IOCARD) {
464 if (state->csc_mask & SS_STSCHG)
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200465 pr_debug("m32r_pcc: :STSCHG");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 } else {
467 if (state->csc_mask & SS_BATDEAD)
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200468 pr_debug("m32r_pcc: :BATDEAD");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (state->csc_mask & SS_BATWARN)
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200470 pr_debug("m32r_pcc: :BATWARN");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (state->csc_mask & SS_READY)
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200472 pr_debug("m32r_pcc: :READY");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200474 pr_debug("m32r_pcc: \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return 0;
476} /* _set_socket */
477
478/*====================================================================*/
479
480static int _pcc_set_io_map(u_short sock, struct pccard_io_map *io)
481{
482 u_char map;
483
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200484 pr_debug("m32r_pcc: SetIOMap(%d, %d, %#2.2x, %d ns, "
Wolfram Sang5f784332009-10-19 11:42:13 +0200485 "%#llx-%#llx)\n", sock, io->map, io->flags,
486 io->speed, (unsigned long long)io->start,
487 (unsigned long long)io->stop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 map = io->map;
489
490 return 0;
491} /* _set_io_map */
492
493/*====================================================================*/
494
495static int _pcc_set_mem_map(u_short sock, struct pccard_mem_map *mem)
496{
497
498 u_char map = mem->map;
499 u_long mode;
500 u_long addr;
501 pcc_socket_t *t = &socket[sock];
502#ifdef CHAOS_PCC_DEBUG
503#if 0
504 pcc_as_t last = t->current_space;
505#endif
506#endif
507
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200508 pr_debug("m32r_pcc: SetMemMap(%d, %d, %#2.2x, %d ns, "
Wolfram Sang5f784332009-10-19 11:42:13 +0200509 "%#llx, %#x)\n", sock, map, mem->flags,
510 mem->speed, (unsigned long long)mem->static_start,
511 mem->card_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 /*
514 * sanity check
515 */
516 if ((map > MAX_WIN) || (mem->card_start > 0x3ffffff)){
517 return -EINVAL;
518 }
519
520 /*
521 * de-activate
522 */
523 if ((mem->flags & MAP_ACTIVE) == 0) {
524 t->current_space = as_none;
525 return 0;
526 }
527
528 /*
529 * Disable first
530 */
531 pcc_set(sock, PCCR, 0);
532
533 /*
534 * Set mode
535 */
536 if (mem->flags & MAP_ATTRIB) {
537 mode = PCMOD_AS_ATTRIB | PCMOD_CBSZ;
538 t->current_space = as_attr;
539 } else {
540 mode = 0; /* common memory */
541 t->current_space = as_comm;
542 }
543 pcc_set(sock, PCMOD, mode);
544
545 /*
546 * Set address
547 */
548 addr = t->mapaddr + (mem->card_start & M32R_PCC_MAPMASK);
549 pcc_set(sock, PCADR, addr);
550
551 mem->static_start = addr + mem->card_start;
552
553 /*
554 * Enable again
555 */
556 pcc_set(sock, PCCR, 1);
557
558#ifdef CHAOS_PCC_DEBUG
559#if 0
560 if (last != as_attr) {
561#else
562 if (1) {
563#endif
564 dummy_readbuf = *(u_char *)(addr + KSEG1);
565 }
566#endif
567
568 return 0;
569
570} /* _set_mem_map */
571
572#if 0 /* driver model ordering issue */
573/*======================================================================
574
575 Routines for accessing socket information and register dumps via
576 /proc/bus/pccard/...
577
578======================================================================*/
579
580static ssize_t show_info(struct class_device *class_dev, char *buf)
581{
582 pcc_socket_t *s = container_of(class_dev, struct pcc_socket,
583 socket.dev);
584
585 return sprintf(buf, "type: %s\nbase addr: 0x%08lx\n",
586 pcc[s->type].name, s->base);
587}
588
589static ssize_t show_exca(struct class_device *class_dev, char *buf)
590{
591 /* FIXME */
592
593 return 0;
594}
595
596static CLASS_DEVICE_ATTR(info, S_IRUGO, show_info, NULL);
597static CLASS_DEVICE_ATTR(exca, S_IRUGO, show_exca, NULL);
598#endif
599
600/*====================================================================*/
601
602/* this is horribly ugly... proper locking needs to be done here at
603 * some time... */
604#define LOCKED(x) do { \
605 int retval; \
606 unsigned long flags; \
607 spin_lock_irqsave(&pcc_lock, flags); \
608 retval = x; \
609 spin_unlock_irqrestore(&pcc_lock, flags); \
610 return retval; \
611} while (0)
612
613
614static int pcc_get_status(struct pcmcia_socket *s, u_int *value)
615{
616 unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
617
618 if (socket[sock].flags & IS_ALIVE) {
619 *value = 0;
620 return -EINVAL;
621 }
622 LOCKED(_pcc_get_status(sock, value));
623}
624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625static int pcc_set_socket(struct pcmcia_socket *s, socket_state_t *state)
626{
627 unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
628
629 if (socket[sock].flags & IS_ALIVE)
630 return -EINVAL;
631
632 LOCKED(_pcc_set_socket(sock, state));
633}
634
635static int pcc_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
636{
637 unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
638
639 if (socket[sock].flags & IS_ALIVE)
640 return -EINVAL;
641 LOCKED(_pcc_set_io_map(sock, io));
642}
643
644static int pcc_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *mem)
645{
646 unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
647
648 if (socket[sock].flags & IS_ALIVE)
649 return -EINVAL;
650 LOCKED(_pcc_set_mem_map(sock, mem));
651}
652
653static int pcc_init(struct pcmcia_socket *s)
654{
Dominik Brodowskic9f50dd2009-10-23 12:56:46 +0200655 pr_debug("m32r_pcc: init call\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 return 0;
657}
658
659static struct pccard_operations pcc_operations = {
660 .init = pcc_init,
661 .get_status = pcc_get_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .set_socket = pcc_set_socket,
663 .set_io_map = pcc_set_io_map,
664 .set_mem_map = pcc_set_mem_map,
665};
666
667/*====================================================================*/
668
Ming Lei7a192ec2009-02-06 23:40:12 +0800669static struct platform_driver pcc_driver = {
670 .driver = {
671 .name = "pcc",
Ming Lei7a192ec2009-02-06 23:40:12 +0800672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673};
674
675static struct platform_device pcc_device = {
676 .name = "pcc",
677 .id = 0,
678};
679
680/*====================================================================*/
681
682static int __init init_m32r_pcc(void)
683{
684 int i, ret;
685
Ming Lei7a192ec2009-02-06 23:40:12 +0800686 ret = platform_driver_register(&pcc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 if (ret)
688 return ret;
689
690 ret = platform_device_register(&pcc_device);
Sudip Mukherjeec795cf42016-12-12 16:41:02 -0800691 if (ret)
692 goto unreg_driv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
694 printk(KERN_INFO "m32r PCC probe:\n");
695
696 pcc_sockets = 0;
697
Sudip Mukherjee3da82062016-12-12 16:41:05 -0800698 ret = add_pcc_socket(M32R_PCC0_BASE, PCC0_IRQ, M32R_PCC0_MAPBASE,
699 0x1000);
700 if (ret)
701 goto unreg_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703#ifdef CONFIG_M32RPCC_SLOT2
Sudip Mukherjee3da82062016-12-12 16:41:05 -0800704 ret = add_pcc_socket(M32R_PCC1_BASE, PCC1_IRQ, M32R_PCC1_MAPBASE,
705 0x2000);
706 if (ret)
707 goto unreg_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#endif
709
710 if (pcc_sockets == 0) {
711 printk("socket is not found.\n");
Sudip Mukherjeec795cf42016-12-12 16:41:02 -0800712 ret = -ENODEV;
713 goto unreg_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715
716 /* Set up interrupt handler(s) */
717
718 for (i = 0 ; i < pcc_sockets ; i++) {
Al Viroccbe48f2007-02-09 16:05:37 +0000719 socket[i].socket.dev.parent = &pcc_device.dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 socket[i].socket.ops = &pcc_operations;
721 socket[i].socket.resource_ops = &pccard_static_ops;
722 socket[i].socket.owner = THIS_MODULE;
723 socket[i].number = i;
724 ret = pcmcia_register_socket(&socket[i].socket);
725 if (!ret)
726 socket[i].flags |= IS_REGISTERED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
729 /* Finally, schedule a polling interrupt */
730 if (poll_interval != 0) {
Kees Cook35c3f852017-10-16 16:27:53 -0700731 timer_setup(&poll_timer, pcc_interrupt_wrapper, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 poll_timer.expires = jiffies + poll_interval;
733 add_timer(&poll_timer);
734 }
735
736 return 0;
Sudip Mukherjeec795cf42016-12-12 16:41:02 -0800737
738unreg_dev:
739 platform_device_unregister(&pcc_device);
740unreg_driv:
741 platform_driver_unregister(&pcc_driver);
742 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743} /* init_m32r_pcc */
744
745static void __exit exit_m32r_pcc(void)
746{
747 int i;
748
749 for (i = 0; i < pcc_sockets; i++)
750 if (socket[i].flags & IS_REGISTERED)
751 pcmcia_unregister_socket(&socket[i].socket);
752
753 platform_device_unregister(&pcc_device);
754 if (poll_interval != 0)
755 del_timer_sync(&poll_timer);
756
Ming Lei7a192ec2009-02-06 23:40:12 +0800757 platform_driver_unregister(&pcc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758} /* exit_m32r_pcc */
759
760module_init(init_m32r_pcc);
761module_exit(exit_m32r_pcc);
762MODULE_LICENSE("Dual MPL/GPL");
763/*====================================================================*/