blob: bdb5ec1cf5600ccfff616cdba51d62ca9c61a092 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/kernel/ecard.c
3 *
4 * Copyright 1995-2001 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Find all installed expansion cards, and handle interrupts from them.
11 *
12 * Created from information from Acorns RiscOS3 PRMs
13 *
14 * 08-Dec-1996 RMK Added code for the 9'th expansion card - the ether
15 * podule slot.
16 * 06-May-1997 RMK Added blacklist for cards whose loader doesn't work.
17 * 12-Sep-1997 RMK Created new handling of interrupt enables/disables
18 * - cards can now register their own routine to control
19 * interrupts (recommended).
20 * 29-Sep-1997 RMK Expansion card interrupt hardware not being re-enabled
21 * on reset from Linux. (Caused cards not to respond
22 * under RiscOS without hard reset).
23 * 15-Feb-1998 RMK Added DMA support
24 * 12-Sep-1998 RMK Added EASI support
25 * 10-Jan-1999 RMK Run loaders in a simulated RISC OS environment.
26 * 17-Apr-1999 RMK Support for EASI Type C cycles.
27 */
28#define ECARD_C
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/types.h>
33#include <linux/sched.h>
Ingo Molnar6e84f312017-02-08 18:51:29 +010034#include <linux/sched/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/interrupt.h>
36#include <linux/completion.h>
37#include <linux/reboot.h>
38#include <linux/mm.h>
39#include <linux/slab.h>
40#include <linux/proc_fs.h>
Alexey Dobriyan9b001212008-04-29 01:01:49 -070041#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/device.h>
43#include <linux/init.h>
Arjan van de Ven00431702006-01-12 18:42:23 +000044#include <linux/mutex.h>
Eric W. Biederman134c99e2007-04-26 00:04:40 -070045#include <linux/kthread.h>
Russell Kingb4ac0842012-03-01 17:50:33 +000046#include <linux/irq.h>
Russell King10bdaaa2007-05-10 18:40:51 +010047#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#include <asm/dma.h>
50#include <asm/ecard.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010051#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <asm/irq.h>
53#include <asm/mmu_context.h>
54#include <asm/mach/irq.h>
55#include <asm/tlbflush.h>
56
Russell Kingc0b04d12007-05-03 10:20:47 +010057#include "ecard.h"
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059struct ecard_request {
60 void (*fn)(struct ecard_request *);
61 ecard_t *ec;
62 unsigned int address;
63 unsigned int length;
64 unsigned int use_loader;
65 void *buffer;
66 struct completion *complete;
67};
68
69struct expcard_blacklist {
70 unsigned short manufacturer;
71 unsigned short product;
72 const char *type;
73};
74
75static ecard_t *cards;
76static ecard_t *slot_to_expcard[MAX_ECARDS];
77static unsigned int ectcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/* List of descriptions of cards which don't have an extended
80 * identification, or chunk directories containing a description.
81 */
82static struct expcard_blacklist __initdata blacklist[] = {
83 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
84};
85
86asmlinkage extern int
87ecard_loader_reset(unsigned long base, loader_t loader);
88asmlinkage extern int
89ecard_loader_read(int off, unsigned long base, loader_t loader);
90
91static inline unsigned short ecard_getu16(unsigned char *v)
92{
93 return v[0] | v[1] << 8;
94}
95
96static inline signed long ecard_gets24(unsigned char *v)
97{
98 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
99}
100
101static inline ecard_t *slot_to_ecard(unsigned int slot)
102{
103 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
104}
105
106/* ===================== Expansion card daemon ======================== */
107/*
108 * Since the loader programs on the expansion cards need to be run
109 * in a specific environment, create a separate task with this
110 * environment up, and pass requests to this task as and when we
111 * need to.
112 *
113 * This should allow 99% of loaders to be called from Linux.
114 *
115 * From a security standpoint, we trust the card vendors. This
116 * may be a misplaced trust.
117 */
118static void ecard_task_reset(struct ecard_request *req)
119{
120 struct expansion_card *ec = req->ec;
121 struct resource *res;
122
123 res = ec->slot_no == 8
124 ? &ec->resource[ECARD_RES_MEMC]
Russell King5559bca2007-05-03 10:47:37 +0100125 : ec->easi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 ? &ec->resource[ECARD_RES_EASI]
127 : &ec->resource[ECARD_RES_IOCSYNC];
128
129 ecard_loader_reset(res->start, ec->loader);
130}
131
132static void ecard_task_readbytes(struct ecard_request *req)
133{
134 struct expansion_card *ec = req->ec;
135 unsigned char *buf = req->buffer;
136 unsigned int len = req->length;
137 unsigned int off = req->address;
138
139 if (ec->slot_no == 8) {
140 void __iomem *base = (void __iomem *)
141 ec->resource[ECARD_RES_MEMC].start;
142
143 /*
144 * The card maintains an index which increments the address
145 * into a 4096-byte page on each access. We need to keep
146 * track of the counter.
147 */
148 static unsigned int index;
149 unsigned int page;
150
151 page = (off >> 12) * 4;
152 if (page > 256 * 4)
153 return;
154
155 off &= 4095;
156
157 /*
158 * If we are reading offset 0, or our current index is
159 * greater than the offset, reset the hardware index counter.
160 */
161 if (off == 0 || index > off) {
162 writeb(0, base);
163 index = 0;
164 }
165
166 /*
167 * Increment the hardware index counter until we get to the
168 * required offset. The read bytes are discarded.
169 */
170 while (index < off) {
171 readb(base + page);
172 index += 1;
173 }
174
175 while (len--) {
176 *buf++ = readb(base + page);
177 index += 1;
178 }
179 } else {
Russell King5559bca2007-05-03 10:47:37 +0100180 unsigned long base = (ec->easi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 ? &ec->resource[ECARD_RES_EASI]
182 : &ec->resource[ECARD_RES_IOCSYNC])->start;
183 void __iomem *pbase = (void __iomem *)base;
184
185 if (!req->use_loader || !ec->loader) {
186 off *= 4;
187 while (len--) {
188 *buf++ = readb(pbase + off);
189 off += 4;
190 }
191 } else {
192 while(len--) {
193 /*
194 * The following is required by some
195 * expansion card loader programs.
196 */
197 *(unsigned long *)0x108 = 0;
198 *buf++ = ecard_loader_read(off++, base,
199 ec->loader);
200 }
201 }
202 }
203
204}
205
206static DECLARE_WAIT_QUEUE_HEAD(ecard_wait);
207static struct ecard_request *ecard_req;
Arjan van de Ven00431702006-01-12 18:42:23 +0000208static DEFINE_MUTEX(ecard_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/*
211 * Set up the expansion card daemon's page tables.
212 */
213static void ecard_init_pgtables(struct mm_struct *mm)
214{
215 struct vm_area_struct vma;
216
217 /* We want to set up the page tables for the following mapping:
218 * Virtual Physical
219 * 0x03000000 0x03000000
220 * 0x03010000 unmapped
221 * 0x03210000 0x03210000
222 * 0x03400000 unmapped
223 * 0x08000000 0x08000000
224 * 0x10000000 unmapped
225 *
226 * FIXME: we don't follow this 100% yet.
227 */
228 pgd_t *src_pgd, *dst_pgd;
229
230 src_pgd = pgd_offset(mm, (unsigned long)IO_BASE);
231 dst_pgd = pgd_offset(mm, IO_START);
232
233 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (IO_SIZE / PGDIR_SIZE));
234
Russell King5e4cdb82011-07-07 11:40:52 +0100235 src_pgd = pgd_offset(mm, (unsigned long)EASI_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 dst_pgd = pgd_offset(mm, EASI_START);
237
238 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
239
Russell King81caaf22012-03-05 23:29:51 +0000240 vma.vm_flags = VM_EXEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 vma.vm_mm = mm;
242
243 flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
244 flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
245}
246
247static int ecard_init_mm(void)
248{
249 struct mm_struct * mm = mm_alloc();
250 struct mm_struct *active_mm = current->active_mm;
251
252 if (!mm)
253 return -ENOMEM;
254
255 current->mm = mm;
256 current->active_mm = mm;
257 activate_mm(active_mm, mm);
258 mmdrop(active_mm);
259 ecard_init_pgtables(mm);
260 return 0;
261}
262
263static int
264ecard_task(void * unused)
265{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 /*
267 * Allocate a mm. We're not a lazy-TLB kernel task since we need
268 * to set page table entries where the user space would be. Note
269 * that this also creates the page tables. Failure is not an
270 * option here.
271 */
272 if (ecard_init_mm())
273 panic("kecardd: unable to alloc mm\n");
274
275 while (1) {
276 struct ecard_request *req;
277
278 wait_event_interruptible(ecard_wait, ecard_req != NULL);
279
280 req = xchg(&ecard_req, NULL);
281 if (req != NULL) {
282 req->fn(req);
283 complete(req->complete);
284 }
285 }
286}
287
288/*
289 * Wake the expansion card daemon to action our request.
290 *
291 * FIXME: The test here is not sufficient to detect if the
292 * kcardd is running.
293 */
294static void ecard_call(struct ecard_request *req)
295{
Peter Zijlstra6e9a4732006-09-30 23:28:10 -0700296 DECLARE_COMPLETION_ONSTACK(completion);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 req->complete = &completion;
299
Arjan van de Ven00431702006-01-12 18:42:23 +0000300 mutex_lock(&ecard_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 ecard_req = req;
302 wake_up(&ecard_wait);
303
304 /*
305 * Now wait for kecardd to run.
306 */
307 wait_for_completion(&completion);
Arjan van de Ven00431702006-01-12 18:42:23 +0000308 mutex_unlock(&ecard_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
311/* ======================= Mid-level card control ===================== */
312
313static void
314ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
315{
316 struct ecard_request req;
317
318 req.fn = ecard_task_readbytes;
319 req.ec = ec;
320 req.address = off;
321 req.length = len;
322 req.use_loader = useld;
323 req.buffer = addr;
324
325 ecard_call(&req);
326}
327
328int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
329{
330 struct ex_chunk_dir excd;
331 int index = 16;
332 int useld = 0;
333
334 if (!ec->cid.cd)
335 return 0;
336
337 while(1) {
338 ecard_readbytes(&excd, ec, index, 8, useld);
339 index += 8;
340 if (c_id(&excd) == 0) {
341 if (!useld && ec->loader) {
342 useld = 1;
343 index = 0;
344 continue;
345 }
346 return 0;
347 }
348 if (c_id(&excd) == 0xf0) { /* link */
349 index = c_start(&excd);
350 continue;
351 }
352 if (c_id(&excd) == 0x80) { /* loader */
353 if (!ec->loader) {
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800354 ec->loader = kmalloc(c_len(&excd),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 GFP_KERNEL);
356 if (ec->loader)
357 ecard_readbytes(ec->loader, ec,
358 (int)c_start(&excd),
359 c_len(&excd), useld);
360 else
361 return 0;
362 }
363 continue;
364 }
365 if (c_id(&excd) == id && num-- == 0)
366 break;
367 }
368
369 if (c_id(&excd) & 0x80) {
370 switch (c_id(&excd) & 0x70) {
371 case 0x70:
372 ecard_readbytes((unsigned char *)excd.d.string, ec,
373 (int)c_start(&excd), c_len(&excd),
374 useld);
375 break;
376 case 0x00:
377 break;
378 }
379 }
380 cd->start_offset = c_start(&excd);
381 memcpy(cd->d.string, excd.d.string, 256);
382 return 1;
383}
384
385/* ======================= Interrupt control ============================ */
386
387static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
388{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
391static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
392{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
395static int ecard_def_irq_pending(ecard_t *ec)
396{
397 return !ec->irqmask || readb(ec->irqaddr) & ec->irqmask;
398}
399
400static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
401{
402 panic("ecard_def_fiq_enable called - impossible");
403}
404
405static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
406{
407 panic("ecard_def_fiq_disable called - impossible");
408}
409
410static int ecard_def_fiq_pending(ecard_t *ec)
411{
412 return !ec->fiqmask || readb(ec->fiqaddr) & ec->fiqmask;
413}
414
415static expansioncard_ops_t ecard_default_ops = {
416 ecard_def_irq_enable,
417 ecard_def_irq_disable,
418 ecard_def_irq_pending,
419 ecard_def_fiq_enable,
420 ecard_def_fiq_disable,
421 ecard_def_fiq_pending
422};
423
424/*
425 * Enable and disable interrupts from expansion cards.
426 * (interrupts are disabled for these functions).
427 *
428 * They are not meant to be called directly, but via enable/disable_irq.
429 */
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100430static void ecard_irq_unmask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Russell Kingc402c112012-03-01 17:54:11 +0000432 ecard_t *ec = irq_data_get_irq_chip_data(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 if (ec) {
435 if (!ec->ops)
436 ec->ops = &ecard_default_ops;
437
438 if (ec->claimed && ec->ops->irqenable)
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100439 ec->ops->irqenable(ec, d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 else
441 printk(KERN_ERR "ecard: rejecting request to "
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100442 "enable IRQs for %d\n", d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444}
445
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100446static void ecard_irq_mask(struct irq_data *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Russell Kingc402c112012-03-01 17:54:11 +0000448 ecard_t *ec = irq_data_get_irq_chip_data(d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (ec) {
451 if (!ec->ops)
452 ec->ops = &ecard_default_ops;
453
454 if (ec->ops && ec->ops->irqdisable)
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100455 ec->ops->irqdisable(ec, d->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457}
458
David Brownell38c677c2006-08-01 22:26:25 +0100459static struct irq_chip ecard_chip = {
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100460 .name = "ECARD",
461 .irq_ack = ecard_irq_mask,
462 .irq_mask = ecard_irq_mask,
463 .irq_unmask = ecard_irq_unmask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464};
465
466void ecard_enablefiq(unsigned int fiqnr)
467{
468 ecard_t *ec = slot_to_ecard(fiqnr);
469
470 if (ec) {
471 if (!ec->ops)
472 ec->ops = &ecard_default_ops;
473
474 if (ec->claimed && ec->ops->fiqenable)
475 ec->ops->fiqenable(ec, fiqnr);
476 else
477 printk(KERN_ERR "ecard: rejecting request to "
478 "enable FIQs for %d\n", fiqnr);
479 }
480}
481
482void ecard_disablefiq(unsigned int fiqnr)
483{
484 ecard_t *ec = slot_to_ecard(fiqnr);
485
486 if (ec) {
487 if (!ec->ops)
488 ec->ops = &ecard_default_ops;
489
490 if (ec->ops->fiqdisable)
491 ec->ops->fiqdisable(ec, fiqnr);
492 }
493}
494
495static void ecard_dump_irq_state(void)
496{
497 ecard_t *ec;
498
499 printk("Expansion card IRQ state:\n");
500
501 for (ec = cards; ec; ec = ec->next) {
502 if (ec->slot_no == 8)
503 continue;
504
505 printk(" %d: %sclaimed, ",
506 ec->slot_no, ec->claimed ? "" : "not ");
507
508 if (ec->ops && ec->ops->irqpending &&
509 ec->ops != &ecard_default_ops)
510 printk("irq %spending\n",
511 ec->ops->irqpending(ec) ? "" : "not ");
512 else
513 printk("irqaddr %p, mask = %02X, status = %02X\n",
514 ec->irqaddr, ec->irqmask, readb(ec->irqaddr));
515 }
516}
517
Russell King10dd5ce2006-11-23 11:41:32 +0000518static void ecard_check_lockup(struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
520 static unsigned long last;
521 static int lockup;
522
523 /*
524 * If the timer interrupt has not run since the last million
525 * unrecognised expansion card interrupts, then there is
526 * something seriously wrong. Disable the expansion card
527 * interrupts so at least we can continue.
528 *
529 * Maybe we ought to start a timer to re-enable them some time
530 * later?
531 */
532 if (last == jiffies) {
533 lockup += 1;
534 if (lockup > 1000000) {
535 printk(KERN_ERR "\nInterrupt lockup detected - "
536 "disabling all expansion card interrupts\n");
537
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100538 desc->irq_data.chip->irq_mask(&desc->irq_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 ecard_dump_irq_state();
540 }
541 } else
542 lockup = 0;
543
544 /*
545 * If we did not recognise the source of this interrupt,
546 * warn the user, but don't flood the user with these messages.
547 */
548 if (!last || time_after(jiffies, last + 5*HZ)) {
549 last = jiffies;
550 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
551 ecard_dump_irq_state();
552 }
553}
554
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200555static void ecard_irq_handler(struct irq_desc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 ecard_t *ec;
558 int called = 0;
559
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100560 desc->irq_data.chip->irq_mask(&desc->irq_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 for (ec = cards; ec; ec = ec->next) {
562 int pending;
563
Russell King41569e32012-01-18 15:41:44 +0000564 if (!ec->claimed || !ec->irq || ec->slot_no == 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 continue;
566
567 if (ec->ops && ec->ops->irqpending)
568 pending = ec->ops->irqpending(ec);
569 else
570 pending = ecard_default_ops.irqpending(ec);
571
572 if (pending) {
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100573 generic_handle_irq(ec->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 called ++;
575 }
576 }
Lennert Buytenhek4a87bac2010-11-29 10:21:01 +0100577 desc->irq_data.chip->irq_unmask(&desc->irq_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 if (called == 0)
580 ecard_check_lockup(desc);
581}
582
Russell King1ace7562011-07-07 10:56:41 +0100583static void __iomem *__ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Russell King06cf0b52011-07-07 11:07:36 +0100585 void __iomem *address = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 int slot = ec->slot_no;
587
588 if (ec->slot_no == 8)
Russell King06cf0b52011-07-07 11:07:36 +0100589 return ECARD_MEMC8_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 ectcr &= ~(1 << slot);
592
593 switch (type) {
594 case ECARD_MEMC:
595 if (slot < 4)
Russell King06cf0b52011-07-07 11:07:36 +0100596 address = ECARD_MEMC_BASE + (slot << 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 break;
598
599 case ECARD_IOC:
600 if (slot < 4)
Russell King06cf0b52011-07-07 11:07:36 +0100601 address = ECARD_IOC_BASE + (slot << 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 else
Russell King06cf0b52011-07-07 11:07:36 +0100603 address = ECARD_IOC4_BASE + ((slot - 4) << 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 if (address)
Russell King06cf0b52011-07-07 11:07:36 +0100605 address += speed << 19;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 break;
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 case ECARD_EASI:
Russell King06cf0b52011-07-07 11:07:36 +0100609 address = ECARD_EASI_BASE + (slot << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 if (speed == ECARD_FAST)
611 ectcr |= 1 << slot;
612 break;
Russell King06cf0b52011-07-07 11:07:36 +0100613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 default:
615 break;
616 }
617
618#ifdef IOMD_ECTCR
619 iomd_writeb(ectcr, IOMD_ECTCR);
620#endif
Russell King06cf0b52011-07-07 11:07:36 +0100621 return address;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700624static int ecard_prints(struct seq_file *m, ecard_t *ec)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700626 seq_printf(m, " %d: %s ", ec->slot_no, ec->easi ? "EASI" : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 if (ec->cid.id == 0) {
629 struct in_chunk_dir incd;
630
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700631 seq_printf(m, "[%04X:%04X] ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 ec->cid.manufacturer, ec->cid.product);
633
634 if (!ec->card_desc && ec->cid.cd &&
635 ecard_readchunk(&incd, ec, 0xf5, 0)) {
636 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
637
638 if (ec->card_desc)
639 strcpy((char *)ec->card_desc, incd.d.string);
640 }
641
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700642 seq_printf(m, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 } else
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700644 seq_printf(m, "Simple card %d\n", ec->cid.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647}
648
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700649static int ecard_devices_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 ecard_t *ec = cards;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700653 while (ec) {
654 ecard_prints(m, ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 ec = ec->next;
656 }
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700657 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
659
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700660static int ecard_devices_proc_open(struct inode *inode, struct file *file)
661{
662 return single_open(file, ecard_devices_proc_show, NULL);
663}
664
665static const struct file_operations bus_ecard_proc_fops = {
666 .owner = THIS_MODULE,
667 .open = ecard_devices_proc_open,
668 .read = seq_read,
669 .llseek = seq_lseek,
670 .release = single_release,
671};
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
674
675static void ecard_proc_init(void)
676{
Alexey Dobriyan9c370662008-04-29 01:01:41 -0700677 proc_bus_ecard_dir = proc_mkdir("bus/ecard", NULL);
Alexey Dobriyan9b001212008-04-29 01:01:49 -0700678 proc_create("devices", 0, proc_bus_ecard_dir, &bus_ecard_proc_fops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
681#define ec_set_resource(ec,nr,st,sz) \
682 do { \
Kay Sievers3f978702008-05-30 17:42:11 +0200683 (ec)->resource[nr].name = dev_name(&ec->dev); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 (ec)->resource[nr].start = st; \
685 (ec)->resource[nr].end = (st) + (sz) - 1; \
686 (ec)->resource[nr].flags = IORESOURCE_MEM; \
687 } while (0)
688
689static void __init ecard_free_card(struct expansion_card *ec)
690{
691 int i;
692
693 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
694 if (ec->resource[i].flags)
695 release_resource(&ec->resource[i]);
696
697 kfree(ec);
698}
699
700static struct expansion_card *__init ecard_alloc_card(int type, int slot)
701{
702 struct expansion_card *ec;
703 unsigned long base;
704 int i;
705
Russell Kingd2a02b92006-03-20 19:46:41 +0000706 ec = kzalloc(sizeof(ecard_t), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if (!ec) {
708 ec = ERR_PTR(-ENOMEM);
709 goto nomem;
710 }
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 ec->slot_no = slot;
Russell King5559bca2007-05-03 10:47:37 +0100713 ec->easi = type == ECARD_EASI;
Russell King41569e32012-01-18 15:41:44 +0000714 ec->irq = 0;
715 ec->fiq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 ec->dma = NO_DMA;
717 ec->ops = &ecard_default_ops;
718
Kay Sievers1d559e22009-01-06 10:44:43 -0800719 dev_set_name(&ec->dev, "ecard%d", slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 ec->dev.parent = NULL;
721 ec->dev.bus = &ecard_bus_type;
722 ec->dev.dma_mask = &ec->dma_mask;
723 ec->dma_mask = (u64)0xffffffff;
Russell King69f4f332007-04-02 13:53:15 +0100724 ec->dev.coherent_dma_mask = ec->dma_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 if (slot < 4) {
727 ec_set_resource(ec, ECARD_RES_MEMC,
728 PODSLOT_MEMC_BASE + (slot << 14),
729 PODSLOT_MEMC_SIZE);
730 base = PODSLOT_IOC0_BASE + (slot << 14);
731 } else
732 base = PODSLOT_IOC4_BASE + ((slot - 4) << 14);
733
734#ifdef CONFIG_ARCH_RPC
735 if (slot < 8) {
736 ec_set_resource(ec, ECARD_RES_EASI,
737 PODSLOT_EASI_BASE + (slot << 24),
738 PODSLOT_EASI_SIZE);
739 }
740
741 if (slot == 8) {
742 ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE, NETSLOT_SIZE);
743 } else
744#endif
745
746 for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++)
747 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
748 base + (i << 19), PODSLOT_IOC_SIZE);
749
750 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
751 if (ec->resource[i].flags &&
752 request_resource(&iomem_resource, &ec->resource[i])) {
Greg Kroah-Hartmanfc3a8822008-05-02 06:02:41 +0200753 dev_err(&ec->dev, "resource(s) not available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 ec->resource[i].end -= ec->resource[i].start;
755 ec->resource[i].start = 0;
756 ec->resource[i].flags = 0;
757 }
758 }
759
760 nomem:
761 return ec;
762}
763
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200764static ssize_t irq_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
766 struct expansion_card *ec = ECARD_DEV(dev);
767 return sprintf(buf, "%u\n", ec->irq);
768}
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200769static DEVICE_ATTR_RO(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200771static ssize_t dma_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 struct expansion_card *ec = ECARD_DEV(dev);
774 return sprintf(buf, "%u\n", ec->dma);
775}
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200776static DEVICE_ATTR_RO(dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200778static ssize_t resource_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 struct expansion_card *ec = ECARD_DEV(dev);
781 char *str = buf;
782 int i;
783
784 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
Russell Kingc9e41432006-07-03 13:29:03 +0100785 str += sprintf(str, "%08x %08x %08lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 ec->resource[i].start,
787 ec->resource[i].end,
788 ec->resource[i].flags);
789
790 return str - buf;
791}
Greg Kroah-Hartmand565ed382017-06-14 11:54:29 +0200792static DEVICE_ATTR_RO(resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200794static ssize_t vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
796 struct expansion_card *ec = ECARD_DEV(dev);
797 return sprintf(buf, "%u\n", ec->cid.manufacturer);
798}
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200799static DEVICE_ATTR_RO(vendor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200801static ssize_t device_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
803 struct expansion_card *ec = ECARD_DEV(dev);
804 return sprintf(buf, "%u\n", ec->cid.product);
805}
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200806static DEVICE_ATTR_RO(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200808static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809{
810 struct expansion_card *ec = ECARD_DEV(dev);
Russell King5559bca2007-05-03 10:47:37 +0100811 return sprintf(buf, "%s\n", ec->easi ? "EASI" : "IOC");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200813static DEVICE_ATTR_RO(type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200815static struct attribute *ecard_dev_attrs[] = {
816 &dev_attr_device.attr,
817 &dev_attr_dma.attr,
818 &dev_attr_irq.attr,
819 &dev_attr_resource.attr,
820 &dev_attr_type.attr,
821 &dev_attr_vendor.attr,
822 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823};
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +0200824ATTRIBUTE_GROUPS(ecard_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826int ecard_request_resources(struct expansion_card *ec)
827{
828 int i, err = 0;
829
830 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
831 if (ecard_resource_end(ec, i) &&
832 !request_mem_region(ecard_resource_start(ec, i),
833 ecard_resource_len(ec, i),
834 ec->dev.driver->name)) {
835 err = -EBUSY;
836 break;
837 }
838 }
839
840 if (err) {
841 while (i--)
842 if (ecard_resource_end(ec, i))
843 release_mem_region(ecard_resource_start(ec, i),
844 ecard_resource_len(ec, i));
845 }
846 return err;
847}
848EXPORT_SYMBOL(ecard_request_resources);
849
850void ecard_release_resources(struct expansion_card *ec)
851{
852 int i;
853
854 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
855 if (ecard_resource_end(ec, i))
856 release_mem_region(ecard_resource_start(ec, i),
857 ecard_resource_len(ec, i));
858}
859EXPORT_SYMBOL(ecard_release_resources);
860
Russell Kingc7b87f32007-05-10 16:46:13 +0100861void ecard_setirq(struct expansion_card *ec, const struct expansion_card_ops *ops, void *irq_data)
862{
863 ec->irq_data = irq_data;
864 barrier();
865 ec->ops = ops;
866}
867EXPORT_SYMBOL(ecard_setirq);
868
Russell King10bdaaa2007-05-10 18:40:51 +0100869void __iomem *ecardm_iomap(struct expansion_card *ec, unsigned int res,
870 unsigned long offset, unsigned long maxsize)
871{
872 unsigned long start = ecard_resource_start(ec, res);
873 unsigned long end = ecard_resource_end(ec, res);
874
875 if (offset > (end - start))
876 return NULL;
877
878 start += offset;
879 if (maxsize && end - start > maxsize)
880 end = start + maxsize;
881
882 return devm_ioremap(&ec->dev, start, end - start);
883}
884EXPORT_SYMBOL(ecardm_iomap);
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886/*
887 * Probe for an expansion card.
888 *
889 * If bit 1 of the first byte of the card is set, then the
890 * card does not exist.
891 */
Russell Kingb4ac0842012-03-01 17:50:33 +0000892static int __init ecard_probe(int slot, unsigned irq, card_type_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
894 ecard_t **ecp;
895 ecard_t *ec;
896 struct ex_ecid cid;
Russell King1ace7562011-07-07 10:56:41 +0100897 void __iomem *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 int i, rc;
899
900 ec = ecard_alloc_card(type, slot);
901 if (IS_ERR(ec)) {
902 rc = PTR_ERR(ec);
903 goto nomem;
904 }
905
906 rc = -ENODEV;
Russell King1ace7562011-07-07 10:56:41 +0100907 if ((addr = __ecard_address(ec, type, ECARD_SYNC)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 goto nodev;
909
910 cid.r_zero = 1;
911 ecard_readbytes(&cid, ec, 0, 16, 0);
912 if (cid.r_zero)
913 goto nodev;
914
915 ec->cid.id = cid.r_id;
916 ec->cid.cd = cid.r_cd;
917 ec->cid.is = cid.r_is;
918 ec->cid.w = cid.r_w;
919 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
920 ec->cid.product = ecard_getu16(cid.r_prod);
921 ec->cid.country = cid.r_country;
922 ec->cid.irqmask = cid.r_irqmask;
923 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
924 ec->cid.fiqmask = cid.r_fiqmask;
925 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
926 ec->fiqaddr =
Russell King1ace7562011-07-07 10:56:41 +0100927 ec->irqaddr = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 if (ec->cid.is) {
930 ec->irqmask = ec->cid.irqmask;
931 ec->irqaddr += ec->cid.irqoff;
932 ec->fiqmask = ec->cid.fiqmask;
933 ec->fiqaddr += ec->cid.fiqoff;
934 } else {
935 ec->irqmask = 1;
936 ec->fiqmask = 4;
937 }
938
Ahmed S. Darwisheeea82f2007-02-05 16:10:25 -0800939 for (i = 0; i < ARRAY_SIZE(blacklist); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
941 blacklist[i].product == ec->cid.product) {
942 ec->card_desc = blacklist[i].type;
943 break;
944 }
945
Russell Kingb4ac0842012-03-01 17:50:33 +0000946 ec->irq = irq;
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 /*
949 * hook the interrupt handlers
950 */
951 if (slot < 8) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100952 irq_set_chip_and_handler(ec->irq, &ecard_chip,
953 handle_level_irq);
Russell Kingc402c112012-03-01 17:54:11 +0000954 irq_set_chip_data(ec->irq, ec);
Rob Herringe8d36d52015-07-27 15:55:13 -0500955 irq_clear_status_flags(ec->irq, IRQ_NOREQUEST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958#ifdef CONFIG_ARCH_RPC
959 /* On RiscPC, only first two slots have DMA capability */
960 if (slot < 2)
961 ec->dma = 2 + slot;
962#endif
963
964 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
965
966 *ecp = ec;
967 slot_to_expcard[slot] = ec;
968
Arnd Bergmann5f078092012-04-30 16:26:01 +0000969 rc = device_register(&ec->dev);
970 if (rc)
971 goto nodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 return 0;
974
975 nodev:
976 ecard_free_card(ec);
977 nomem:
978 return rc;
979}
980
981/*
982 * Initialise the expansion card system.
983 * Locate all hardware - interrupt management and
984 * actual cards.
985 */
986static int __init ecard_init(void)
987{
Eric W. Biederman134c99e2007-04-26 00:04:40 -0700988 struct task_struct *task;
Russell King530c2ea2012-03-01 18:46:46 +0000989 int slot, irqbase;
Russell Kingb4ac0842012-03-01 17:50:33 +0000990
991 irqbase = irq_alloc_descs(-1, 0, 8, -1);
992 if (irqbase < 0)
993 return irqbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Eric W. Biederman134c99e2007-04-26 00:04:40 -0700995 task = kthread_run(ecard_task, NULL, "kecardd");
996 if (IS_ERR(task)) {
Russell Kinge6aeb472007-05-03 10:55:46 +0100997 printk(KERN_ERR "Ecard: unable to create kernel thread: %ld\n",
Eric W. Biederman134c99e2007-04-26 00:04:40 -0700998 PTR_ERR(task));
Russell Kingb4ac0842012-03-01 17:50:33 +0000999 irq_free_descs(irqbase, 8);
Eric W. Biederman134c99e2007-04-26 00:04:40 -07001000 return PTR_ERR(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002
1003 printk("Probing expansion cards\n");
1004
1005 for (slot = 0; slot < 8; slot ++) {
Russell Kingb4ac0842012-03-01 17:50:33 +00001006 if (ecard_probe(slot, irqbase + slot, ECARD_EASI) == -ENODEV)
1007 ecard_probe(slot, irqbase + slot, ECARD_IOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 }
1009
Russell Kingb4ac0842012-03-01 17:50:33 +00001010 ecard_probe(8, 11, ECARD_IOC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Russell King530c2ea2012-03-01 18:46:46 +00001012 irq_set_chained_handler(IRQ_EXPANSIONCARD, ecard_irq_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 ecard_proc_init();
1015
1016 return 0;
1017}
1018
1019subsys_initcall(ecard_init);
1020
1021/*
1022 * ECARD "bus"
1023 */
1024static const struct ecard_id *
1025ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
1026{
1027 int i;
1028
1029 for (i = 0; ids[i].manufacturer != 65535; i++)
1030 if (ec->cid.manufacturer == ids[i].manufacturer &&
1031 ec->cid.product == ids[i].product)
1032 return ids + i;
1033
1034 return NULL;
1035}
1036
1037static int ecard_drv_probe(struct device *dev)
1038{
1039 struct expansion_card *ec = ECARD_DEV(dev);
1040 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1041 const struct ecard_id *id;
1042 int ret;
1043
1044 id = ecard_match_device(drv->id_table, ec);
1045
Russell King9ecba1f2008-04-19 16:01:38 +01001046 ec->claimed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 ret = drv->probe(ec, id);
1048 if (ret)
Russell King9ecba1f2008-04-19 16:01:38 +01001049 ec->claimed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 return ret;
1051}
1052
1053static int ecard_drv_remove(struct device *dev)
1054{
1055 struct expansion_card *ec = ECARD_DEV(dev);
1056 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1057
1058 drv->remove(ec);
Russell King9ecba1f2008-04-19 16:01:38 +01001059 ec->claimed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Russell Kingc7b87f32007-05-10 16:46:13 +01001061 /*
1062 * Restore the default operations. We ensure that the
1063 * ops are set before we change the data.
1064 */
1065 ec->ops = &ecard_default_ops;
1066 barrier();
1067 ec->irq_data = NULL;
1068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return 0;
1070}
1071
1072/*
1073 * Before rebooting, we must make sure that the expansion card is in a
1074 * sensible state, so it can be re-detected. This means that the first
1075 * page of the ROM must be visible. We call the expansion cards reset
1076 * handler, if any.
1077 */
1078static void ecard_drv_shutdown(struct device *dev)
1079{
1080 struct expansion_card *ec = ECARD_DEV(dev);
1081 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1082 struct ecard_request req;
1083
Russell Kinge08b7542006-01-05 14:30:57 +00001084 if (dev->driver) {
1085 if (drv->shutdown)
1086 drv->shutdown(ec);
Russell King9ecba1f2008-04-19 16:01:38 +01001087 ec->claimed = 0;
Russell Kinge08b7542006-01-05 14:30:57 +00001088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 /*
1091 * If this card has a loader, call the reset handler.
1092 */
1093 if (ec->loader) {
1094 req.fn = ecard_task_reset;
1095 req.ec = ec;
1096 ecard_call(&req);
1097 }
1098}
1099
1100int ecard_register_driver(struct ecard_driver *drv)
1101{
1102 drv->drv.bus = &ecard_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 return driver_register(&drv->drv);
1105}
1106
1107void ecard_remove_driver(struct ecard_driver *drv)
1108{
1109 driver_unregister(&drv->drv);
1110}
1111
1112static int ecard_match(struct device *_dev, struct device_driver *_drv)
1113{
1114 struct expansion_card *ec = ECARD_DEV(_dev);
1115 struct ecard_driver *drv = ECARD_DRV(_drv);
1116 int ret;
1117
1118 if (drv->id_table) {
1119 ret = ecard_match_device(drv->id_table, ec) != NULL;
1120 } else {
1121 ret = ec->cid.id == drv->id;
1122 }
1123
1124 return ret;
1125}
1126
1127struct bus_type ecard_bus_type = {
1128 .name = "ecard",
Greg Kroah-Hartman71d1e5d2017-06-06 14:14:16 +02001129 .dev_groups = ecard_dev_groups,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 .match = ecard_match,
Russell Kinge08b7542006-01-05 14:30:57 +00001131 .probe = ecard_drv_probe,
1132 .remove = ecard_drv_remove,
1133 .shutdown = ecard_drv_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134};
1135
1136static int ecard_bus_init(void)
1137{
1138 return bus_register(&ecard_bus_type);
1139}
1140
1141postcore_initcall(ecard_bus_init);
1142
1143EXPORT_SYMBOL(ecard_readchunk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144EXPORT_SYMBOL(ecard_register_driver);
1145EXPORT_SYMBOL(ecard_remove_driver);
1146EXPORT_SYMBOL(ecard_bus_type);