initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / arm26 / kernel / ecard.c
blob8434f0f0c2dd1921e5164c2dcade93ca0d617536
1 /*
2 * linux/arch/arm26/kernel/ecard.c
4 * Copyright 1995-2001 Russell King
5 * Copyright 2003 Ian Molton
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Find all installed expansion cards, and handle interrupts from them.
13 * Created from information from Acorns RiscOS3 PRMs
14 * 15-Jun-2003 IM Modified from ARM32 (RiscPC capable) version
15 * 10-Jan-1999 RMK Run loaders in a simulated RISC OS environment.
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).
25 #define ECARD_C
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/sched.h>
32 #include <linux/interrupt.h>
33 #include <linux/reboot.h>
34 #include <linux/mm.h>
35 #include <linux/slab.h>
36 #include <linux/proc_fs.h>
37 #include <linux/device.h>
38 #include <linux/init.h>
40 #include <asm/dma.h>
41 #include <asm/ecard.h>
42 #include <asm/hardware.h>
43 #include <asm/io.h>
44 #include <asm/irq.h>
45 #include <asm/pgalloc.h>
46 #include <asm/mmu_context.h>
47 #include <asm/irq.h>
48 #include <asm/irqchip.h>
49 #include <asm/tlbflush.h>
51 enum req {
52 req_readbytes,
53 req_reset
56 struct ecard_request {
57 enum req req;
58 ecard_t *ec;
59 unsigned int address;
60 unsigned int length;
61 unsigned int use_loader;
62 void *buffer;
65 struct expcard_blacklist {
66 unsigned short manufacturer;
67 unsigned short product;
68 const char *type;
71 static ecard_t *cards;
72 static ecard_t *slot_to_expcard[MAX_ECARDS];
73 static unsigned int ectcr;
75 /* List of descriptions of cards which don't have an extended
76 * identification, or chunk directories containing a description.
78 static struct expcard_blacklist __initdata blacklist[] = {
79 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
82 asmlinkage extern int
83 ecard_loader_reset(volatile unsigned char *pa, loader_t loader);
84 asmlinkage extern int
85 ecard_loader_read(int off, volatile unsigned char *pa, loader_t loader);
87 static const struct ecard_id *
88 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec);
90 static inline unsigned short
91 ecard_getu16(unsigned char *v)
93 return v[0] | v[1] << 8;
96 static inline signed long
97 ecard_gets24(unsigned char *v)
99 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
102 static inline ecard_t *
103 slot_to_ecard(unsigned int slot)
105 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
108 /* ===================== Expansion card daemon ======================== */
110 * Since the loader programs on the expansion cards need to be run
111 * in a specific environment, create a separate task with this
112 * environment up, and pass requests to this task as and when we
113 * need to.
115 * This should allow 99% of loaders to be called from Linux.
117 * From a security standpoint, we trust the card vendors. This
118 * may be a misplaced trust.
120 #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
121 #define POD_INT_ADDR(x) ((volatile unsigned char *)\
122 ((BUS_ADDR((x)) - IO_BASE) + IO_START))
124 static inline void ecard_task_reset(struct ecard_request *req)
126 struct expansion_card *ec = req->ec;
127 if (ec->loader)
128 ecard_loader_reset(POD_INT_ADDR(ec->podaddr), ec->loader);
131 static void
132 ecard_task_readbytes(struct ecard_request *req)
134 unsigned char *buf = (unsigned char *)req->buffer;
135 volatile unsigned char *base_addr =
136 (volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);
137 unsigned int len = req->length;
138 unsigned int off = req->address;
140 if (req->ec->slot_no == 8) {
142 * The card maintains an index which increments the address
143 * into a 4096-byte page on each access. We need to keep
144 * track of the counter.
146 static unsigned int index;
147 unsigned int page;
149 page = (off >> 12) * 4;
150 if (page > 256 * 4)
151 return;
153 off &= 4095;
156 * If we are reading offset 0, or our current index is
157 * greater than the offset, reset the hardware index counter.
159 if (off == 0 || index > off) {
160 *base_addr = 0;
161 index = 0;
165 * Increment the hardware index counter until we get to the
166 * required offset. The read bytes are discarded.
168 while (index < off) {
169 unsigned char byte;
170 byte = base_addr[page];
171 index += 1;
174 while (len--) {
175 *buf++ = base_addr[page];
176 index += 1;
178 } else {
180 if (!req->use_loader || !req->ec->loader) {
181 off *= 4;
182 while (len--) {
183 *buf++ = base_addr[off];
184 off += 4;
186 } else {
187 while(len--) {
189 * The following is required by some
190 * expansion card loader programs.
192 *(unsigned long *)0x108 = 0;
193 *buf++ = ecard_loader_read(off++, base_addr,
194 req->ec->loader);
201 static void ecard_do_request(struct ecard_request *req)
203 switch (req->req) {
204 case req_readbytes:
205 ecard_task_readbytes(req);
206 break;
208 case req_reset:
209 ecard_task_reset(req);
210 break;
215 * On 26-bit processors, we don't need the kcardd thread to access the
216 * expansion card loaders. We do it directly.
218 #define ecard_call(req) ecard_do_request(req)
220 /* ======================= Mid-level card control ===================== */
222 static void
223 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
225 struct ecard_request req;
227 req.req = req_readbytes;
228 req.ec = ec;
229 req.address = off;
230 req.length = len;
231 req.use_loader = useld;
232 req.buffer = addr;
234 ecard_call(&req);
237 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
239 struct ex_chunk_dir excd;
240 int index = 16;
241 int useld = 0;
243 if (!ec->cid.cd)
244 return 0;
246 while(1) {
247 ecard_readbytes(&excd, ec, index, 8, useld);
248 index += 8;
249 if (c_id(&excd) == 0) {
250 if (!useld && ec->loader) {
251 useld = 1;
252 index = 0;
253 continue;
255 return 0;
257 if (c_id(&excd) == 0xf0) { /* link */
258 index = c_start(&excd);
259 continue;
261 if (c_id(&excd) == 0x80) { /* loader */
262 if (!ec->loader) {
263 ec->loader = (loader_t)kmalloc(c_len(&excd),
264 GFP_KERNEL);
265 if (ec->loader)
266 ecard_readbytes(ec->loader, ec,
267 (int)c_start(&excd),
268 c_len(&excd), useld);
269 else
270 return 0;
272 continue;
274 if (c_id(&excd) == id && num-- == 0)
275 break;
278 if (c_id(&excd) & 0x80) {
279 switch (c_id(&excd) & 0x70) {
280 case 0x70:
281 ecard_readbytes((unsigned char *)excd.d.string, ec,
282 (int)c_start(&excd), c_len(&excd),
283 useld);
284 break;
285 case 0x00:
286 break;
289 cd->start_offset = c_start(&excd);
290 memcpy(cd->d.string, excd.d.string, 256);
291 return 1;
294 /* ======================= Interrupt control ============================ */
296 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
300 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
304 static int ecard_def_irq_pending(ecard_t *ec)
306 return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;
309 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
311 panic("ecard_def_fiq_enable called - impossible");
314 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
316 panic("ecard_def_fiq_disable called - impossible");
319 static int ecard_def_fiq_pending(ecard_t *ec)
321 return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;
324 static expansioncard_ops_t ecard_default_ops = {
325 ecard_def_irq_enable,
326 ecard_def_irq_disable,
327 ecard_def_irq_pending,
328 ecard_def_fiq_enable,
329 ecard_def_fiq_disable,
330 ecard_def_fiq_pending
334 * Enable and disable interrupts from expansion cards.
335 * (interrupts are disabled for these functions).
337 * They are not meant to be called directly, but via enable/disable_irq.
339 static void ecard_irq_unmask(unsigned int irqnr)
341 ecard_t *ec = slot_to_ecard(irqnr - 32);
343 if (ec) {
344 if (!ec->ops)
345 ec->ops = &ecard_default_ops;
347 if (ec->claimed && ec->ops->irqenable)
348 ec->ops->irqenable(ec, irqnr);
349 else
350 printk(KERN_ERR "ecard: rejecting request to "
351 "enable IRQs for %d\n", irqnr);
355 static void ecard_irq_mask(unsigned int irqnr)
357 ecard_t *ec = slot_to_ecard(irqnr - 32);
359 if (ec) {
360 if (!ec->ops)
361 ec->ops = &ecard_default_ops;
363 if (ec->ops && ec->ops->irqdisable)
364 ec->ops->irqdisable(ec, irqnr);
368 static struct irqchip ecard_chip = {
369 .ack = ecard_irq_mask,
370 .mask = ecard_irq_mask,
371 .unmask = ecard_irq_unmask,
374 void ecard_enablefiq(unsigned int fiqnr)
376 ecard_t *ec = slot_to_ecard(fiqnr);
378 if (ec) {
379 if (!ec->ops)
380 ec->ops = &ecard_default_ops;
382 if (ec->claimed && ec->ops->fiqenable)
383 ec->ops->fiqenable(ec, fiqnr);
384 else
385 printk(KERN_ERR "ecard: rejecting request to "
386 "enable FIQs for %d\n", fiqnr);
390 void ecard_disablefiq(unsigned int fiqnr)
392 ecard_t *ec = slot_to_ecard(fiqnr);
394 if (ec) {
395 if (!ec->ops)
396 ec->ops = &ecard_default_ops;
398 if (ec->ops->fiqdisable)
399 ec->ops->fiqdisable(ec, fiqnr);
403 static void
404 ecard_dump_irq_state(ecard_t *ec)
406 printk(" %d: %sclaimed, ",
407 ec->slot_no,
408 ec->claimed ? "" : "not ");
410 if (ec->ops && ec->ops->irqpending &&
411 ec->ops != &ecard_default_ops)
412 printk("irq %spending\n",
413 ec->ops->irqpending(ec) ? "" : "not ");
414 else
415 printk("irqaddr %p, mask = %02X, status = %02X\n",
416 ec->irqaddr, ec->irqmask, *ec->irqaddr);
419 static void ecard_check_lockup(struct irqdesc *desc)
421 static int last, lockup;
422 ecard_t *ec;
425 * If the timer interrupt has not run since the last million
426 * unrecognised expansion card interrupts, then there is
427 * something seriously wrong. Disable the expansion card
428 * interrupts so at least we can continue.
430 * Maybe we ought to start a timer to re-enable them some time
431 * later?
433 if (last == jiffies) {
434 lockup += 1;
435 if (lockup > 1000000) {
436 printk(KERN_ERR "\nInterrupt lockup detected - "
437 "disabling all expansion card interrupts\n");
439 desc->chip->mask(IRQ_EXPANSIONCARD);
441 printk("Expansion card IRQ state:\n");
443 for (ec = cards; ec; ec = ec->next)
444 ecard_dump_irq_state(ec);
446 } else
447 lockup = 0;
450 * If we did not recognise the source of this interrupt,
451 * warn the user, but don't flood the user with these messages.
453 if (!last || time_after(jiffies, (unsigned long)(last + 5*HZ))) {
454 last = jiffies;
455 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
459 static void
460 ecard_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
462 ecard_t *ec;
463 int called = 0;
465 desc->chip->mask(irq);
466 for (ec = cards; ec; ec = ec->next) {
467 int pending;
469 if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)
470 continue;
472 if (ec->ops && ec->ops->irqpending)
473 pending = ec->ops->irqpending(ec);
474 else
475 pending = ecard_default_ops.irqpending(ec);
477 if (pending) {
478 struct irqdesc *d = irq_desc + ec->irq;
479 d->handle(ec->irq, d, regs);
480 called ++;
483 desc->chip->unmask(irq);
485 if (called == 0)
486 ecard_check_lockup(desc);
489 #define ecard_irqexp_handler NULL
490 #define ecard_probeirqhw() (0)
492 unsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
494 unsigned long address = 0;
495 int slot = ec->slot_no;
497 if (ec->slot_no == 8)
498 return 0;
500 ectcr &= ~(1 << slot);
502 switch (type) {
503 case ECARD_MEMC:
504 if (slot < 4)
505 address = IO_EC_MEMC_BASE + (slot << 12);
506 break;
508 case ECARD_IOC:
509 if (slot < 4)
510 address = IO_EC_IOC_BASE + (slot << 12);
511 if (address)
512 address += speed << 17;
513 break;
515 default:
516 break;
519 return address;
522 static int ecard_prints(char *buffer, ecard_t *ec)
524 char *start = buffer;
526 buffer += sprintf(buffer, " %d: ", ec->slot_no);
528 if (ec->cid.id == 0) {
529 struct in_chunk_dir incd;
531 buffer += sprintf(buffer, "[%04X:%04X] ",
532 ec->cid.manufacturer, ec->cid.product);
534 if (!ec->card_desc && ec->cid.cd &&
535 ecard_readchunk(&incd, ec, 0xf5, 0)) {
536 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
538 if (ec->card_desc)
539 strcpy((char *)ec->card_desc, incd.d.string);
542 buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
543 } else
544 buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
546 return buffer - start;
549 static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
551 ecard_t *ec = cards;
552 off_t at = 0;
553 int len, cnt;
555 cnt = 0;
556 while (ec && count > cnt) {
557 len = ecard_prints(buf, ec);
558 at += len;
559 if (at >= pos) {
560 if (!*start) {
561 *start = buf + (pos - (at - len));
562 cnt = at - pos;
563 } else
564 cnt += len;
565 buf += len;
567 ec = ec->next;
569 return (count > cnt) ? cnt : count;
572 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
574 static void ecard_proc_init(void)
576 proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
577 create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
578 get_ecard_dev_info);
581 #define ec_set_resource(ec,nr,st,sz,flg) \
582 do { \
583 (ec)->resource[nr].name = ec->dev.bus_id; \
584 (ec)->resource[nr].start = st; \
585 (ec)->resource[nr].end = (st) + (sz) - 1; \
586 (ec)->resource[nr].flags = flg; \
587 } while (0)
589 static void __init ecard_init_resources(struct expansion_card *ec)
591 unsigned long base = PODSLOT_IOC0_BASE;
592 unsigned int slot = ec->slot_no;
593 int i;
595 if (slot < 4) {
596 ec_set_resource(ec, ECARD_RES_MEMC,
597 PODSLOT_MEMC_BASE + (slot << 14),
598 PODSLOT_MEMC_SIZE, IORESOURCE_MEM);
601 for (i = 0; i < ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++) {
602 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
603 base + (slot << 14) + (i << 19),
604 PODSLOT_IOC_SIZE, IORESOURCE_MEM);
607 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
608 if (ec->resource[i].start &&
609 request_resource(&iomem_resource, &ec->resource[i])) {
610 printk(KERN_ERR "%s: resource(s) not available\n",
611 ec->dev.bus_id);
612 ec->resource[i].end -= ec->resource[i].start;
613 ec->resource[i].start = 0;
618 static ssize_t ecard_show_irq(struct device *dev, char *buf)
620 struct expansion_card *ec = ECARD_DEV(dev);
621 return sprintf(buf, "%u\n", ec->irq);
624 static ssize_t ecard_show_vendor(struct device *dev, char *buf)
626 struct expansion_card *ec = ECARD_DEV(dev);
627 return sprintf(buf, "%u\n", ec->cid.manufacturer);
630 static ssize_t ecard_show_device(struct device *dev, char *buf)
632 struct expansion_card *ec = ECARD_DEV(dev);
633 return sprintf(buf, "%u\n", ec->cid.product);
636 static ssize_t ecard_show_dma(struct device *dev, char *buf)
638 struct expansion_card *ec = ECARD_DEV(dev);
639 return sprintf(buf, "%u\n", ec->dma);
642 static ssize_t ecard_show_resources(struct device *dev, char *buf)
644 struct expansion_card *ec = ECARD_DEV(dev);
645 char *str = buf;
646 int i;
648 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
649 str += sprintf(str, "%08lx %08lx %08lx\n",
650 ec->resource[i].start,
651 ec->resource[i].end,
652 ec->resource[i].flags);
654 return str - buf;
657 static DEVICE_ATTR(irq, S_IRUGO, ecard_show_irq, NULL);
658 static DEVICE_ATTR(vendor, S_IRUGO, ecard_show_vendor, NULL);
659 static DEVICE_ATTR(device, S_IRUGO, ecard_show_device, NULL);
660 static DEVICE_ATTR(dma, S_IRUGO, ecard_show_dma, NULL);
661 static DEVICE_ATTR(resource, S_IRUGO, ecard_show_resources, NULL);
664 * Probe for an expansion card.
666 * If bit 1 of the first byte of the card is set, then the
667 * card does not exist.
669 static int __init
670 ecard_probe(int slot, card_type_t type)
672 ecard_t **ecp;
673 ecard_t *ec;
674 struct ex_ecid cid;
675 int i, rc = -ENOMEM;
677 ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);
678 if (!ec)
679 goto nomem;
681 memset(ec, 0, sizeof(ecard_t));
683 ec->slot_no = slot;
684 ec->type = type;
685 ec->irq = NO_IRQ;
686 ec->fiq = NO_IRQ;
687 ec->dma = NO_DMA;
688 ec->card_desc = NULL;
689 ec->ops = &ecard_default_ops;
691 rc = -ENODEV;
692 if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
693 goto nodev;
695 cid.r_zero = 1;
696 ecard_readbytes(&cid, ec, 0, 16, 0);
697 if (cid.r_zero)
698 goto nodev;
700 ec->cid.id = cid.r_id;
701 ec->cid.cd = cid.r_cd;
702 ec->cid.is = cid.r_is;
703 ec->cid.w = cid.r_w;
704 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
705 ec->cid.product = ecard_getu16(cid.r_prod);
706 ec->cid.country = cid.r_country;
707 ec->cid.irqmask = cid.r_irqmask;
708 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
709 ec->cid.fiqmask = cid.r_fiqmask;
710 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
711 ec->fiqaddr =
712 ec->irqaddr = (unsigned char *)ioaddr(ec->podaddr);
714 if (ec->cid.is) {
715 ec->irqmask = ec->cid.irqmask;
716 ec->irqaddr += ec->cid.irqoff;
717 ec->fiqmask = ec->cid.fiqmask;
718 ec->fiqaddr += ec->cid.fiqoff;
719 } else {
720 ec->irqmask = 1;
721 ec->fiqmask = 4;
724 for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
725 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
726 blacklist[i].product == ec->cid.product) {
727 ec->card_desc = blacklist[i].type;
728 break;
731 snprintf(ec->dev.bus_id, sizeof(ec->dev.bus_id), "ecard%d", slot);
732 ec->dev.parent = NULL;
733 ec->dev.bus = &ecard_bus_type;
734 ec->dev.dma_mask = &ec->dma_mask;
735 ec->dma_mask = (u64)0xffffffff;
737 ecard_init_resources(ec);
740 * hook the interrupt handlers
742 if (slot < 8) {
743 ec->irq = 32 + slot;
744 set_irq_chip(ec->irq, &ecard_chip);
745 set_irq_handler(ec->irq, do_level_IRQ);
746 set_irq_flags(ec->irq, IRQF_VALID);
749 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
751 *ecp = ec;
752 slot_to_expcard[slot] = ec;
754 device_register(&ec->dev);
755 device_create_file(&ec->dev, &dev_attr_dma);
756 device_create_file(&ec->dev, &dev_attr_irq);
757 device_create_file(&ec->dev, &dev_attr_resource);
758 device_create_file(&ec->dev, &dev_attr_vendor);
759 device_create_file(&ec->dev, &dev_attr_device);
761 return 0;
763 nodev:
764 kfree(ec);
765 nomem:
766 return rc;
770 * Initialise the expansion card system.
771 * Locate all hardware - interrupt management and
772 * actual cards.
774 static int __init ecard_init(void)
776 int slot, irqhw;
778 printk("Probing expansion cards\n");
780 for (slot = 0; slot < 4; slot ++) {
781 ecard_probe(slot, ECARD_IOC);
784 irqhw = ecard_probeirqhw();
786 set_irq_chained_handler(IRQ_EXPANSIONCARD,
787 irqhw ? ecard_irqexp_handler : ecard_irq_handler);
789 ecard_proc_init();
791 return 0;
794 subsys_initcall(ecard_init);
797 * ECARD "bus"
799 static const struct ecard_id *
800 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
802 int i;
804 for (i = 0; ids[i].manufacturer != 65535; i++)
805 if (ec->cid.manufacturer == ids[i].manufacturer &&
806 ec->cid.product == ids[i].product)
807 return ids + i;
809 return NULL;
812 static int ecard_drv_probe(struct device *dev)
814 struct expansion_card *ec = ECARD_DEV(dev);
815 struct ecard_driver *drv = ECARD_DRV(dev->driver);
816 const struct ecard_id *id;
817 int ret;
819 id = ecard_match_device(drv->id_table, ec);
821 ecard_claim(ec);
822 ret = drv->probe(ec, id);
823 if (ret)
824 ecard_release(ec);
825 return ret;
828 static int ecard_drv_remove(struct device *dev)
830 struct expansion_card *ec = ECARD_DEV(dev);
831 struct ecard_driver *drv = ECARD_DRV(dev->driver);
833 drv->remove(ec);
834 ecard_release(ec);
836 return 0;
840 * Before rebooting, we must make sure that the expansion card is in a
841 * sensible state, so it can be re-detected. This means that the first
842 * page of the ROM must be visible. We call the expansion cards reset
843 * handler, if any.
845 static void ecard_drv_shutdown(struct device *dev)
847 struct expansion_card *ec = ECARD_DEV(dev);
848 struct ecard_driver *drv = ECARD_DRV(dev->driver);
849 struct ecard_request req;
851 if (drv->shutdown)
852 drv->shutdown(ec);
853 ecard_release(ec);
854 req.req = req_reset;
855 req.ec = ec;
856 ecard_call(&req);
859 int ecard_register_driver(struct ecard_driver *drv)
861 drv->drv.bus = &ecard_bus_type;
862 drv->drv.probe = ecard_drv_probe;
863 drv->drv.remove = ecard_drv_remove;
864 drv->drv.shutdown = ecard_drv_shutdown;
866 return driver_register(&drv->drv);
869 void ecard_remove_driver(struct ecard_driver *drv)
871 driver_unregister(&drv->drv);
874 static int ecard_match(struct device *_dev, struct device_driver *_drv)
876 struct expansion_card *ec = ECARD_DEV(_dev);
877 struct ecard_driver *drv = ECARD_DRV(_drv);
878 int ret;
880 if (drv->id_table) {
881 ret = ecard_match_device(drv->id_table, ec) != NULL;
882 } else {
883 ret = ec->cid.id == drv->id;
886 return ret;
889 struct bus_type ecard_bus_type = {
890 .name = "ecard",
891 .match = ecard_match,
894 static int ecard_bus_init(void)
896 return bus_register(&ecard_bus_type);
899 postcore_initcall(ecard_bus_init);
901 EXPORT_SYMBOL(ecard_readchunk);
902 EXPORT_SYMBOL(ecard_address);
903 EXPORT_SYMBOL(ecard_register_driver);
904 EXPORT_SYMBOL(ecard_remove_driver);
905 EXPORT_SYMBOL(ecard_bus_type);