2 * linux/arch/arm/kernel/ecard.c
4 * Copyright 1995-2001 Russell King
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.
10 * Find all installed expansion cards, and handle interrupts from them.
12 * Created from information from Acorns RiscOS3 PRMs
14 * 08-Dec-1996 RMK Added code for the 9'th expansion card - the ether
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.
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/sched.h>
34 #include <linux/interrupt.h>
35 #include <linux/completion.h>
36 #include <linux/reboot.h>
38 #include <linux/slab.h>
39 #include <linux/proc_fs.h>
40 #include <linux/seq_file.h>
41 #include <linux/device.h>
42 #include <linux/init.h>
43 #include <linux/mutex.h>
44 #include <linux/kthread.h>
45 #include <linux/irq.h>
49 #include <asm/ecard.h>
50 #include <mach/hardware.h>
52 #include <asm/mmu_context.h>
53 #include <asm/mach/irq.h>
54 #include <asm/tlbflush.h>
58 struct ecard_request {
59 void (*fn)(struct ecard_request *);
63 unsigned int use_loader;
65 struct completion *complete;
68 struct expcard_blacklist {
69 unsigned short manufacturer;
70 unsigned short product;
74 static ecard_t *cards;
75 static ecard_t *slot_to_expcard[MAX_ECARDS];
76 static unsigned int ectcr;
78 /* List of descriptions of cards which don't have an extended
79 * identification, or chunk directories containing a description.
81 static struct expcard_blacklist __initdata blacklist[] = {
82 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
86 ecard_loader_reset(unsigned long base, loader_t loader);
88 ecard_loader_read(int off, unsigned long base, loader_t loader);
90 static inline unsigned short ecard_getu16(unsigned char *v)
92 return v[0] | v[1] << 8;
95 static inline signed long ecard_gets24(unsigned char *v)
97 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
100 static inline ecard_t *slot_to_ecard(unsigned int slot)
102 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
105 /* ===================== Expansion card daemon ======================== */
107 * Since the loader programs on the expansion cards need to be run
108 * in a specific environment, create a separate task with this
109 * environment up, and pass requests to this task as and when we
112 * This should allow 99% of loaders to be called from Linux.
114 * From a security standpoint, we trust the card vendors. This
115 * may be a misplaced trust.
117 static void ecard_task_reset(struct ecard_request *req)
119 struct expansion_card *ec = req->ec;
120 struct resource *res;
122 res = ec->slot_no == 8
123 ? &ec->resource[ECARD_RES_MEMC]
125 ? &ec->resource[ECARD_RES_EASI]
126 : &ec->resource[ECARD_RES_IOCSYNC];
128 ecard_loader_reset(res->start, ec->loader);
131 static void ecard_task_readbytes(struct ecard_request *req)
133 struct expansion_card *ec = req->ec;
134 unsigned char *buf = req->buffer;
135 unsigned int len = req->length;
136 unsigned int off = req->address;
138 if (ec->slot_no == 8) {
139 void __iomem *base = (void __iomem *)
140 ec->resource[ECARD_RES_MEMC].start;
143 * The card maintains an index which increments the address
144 * into a 4096-byte page on each access. We need to keep
145 * track of the counter.
147 static unsigned int index;
150 page = (off >> 12) * 4;
157 * If we are reading offset 0, or our current index is
158 * greater than the offset, reset the hardware index counter.
160 if (off == 0 || index > off) {
166 * Increment the hardware index counter until we get to the
167 * required offset. The read bytes are discarded.
169 while (index < off) {
175 *buf++ = readb(base + page);
179 unsigned long base = (ec->easi
180 ? &ec->resource[ECARD_RES_EASI]
181 : &ec->resource[ECARD_RES_IOCSYNC])->start;
182 void __iomem *pbase = (void __iomem *)base;
184 if (!req->use_loader || !ec->loader) {
187 *buf++ = readb(pbase + off);
193 * The following is required by some
194 * expansion card loader programs.
196 *(unsigned long *)0x108 = 0;
197 *buf++ = ecard_loader_read(off++, base,
205 static DECLARE_WAIT_QUEUE_HEAD(ecard_wait);
206 static struct ecard_request *ecard_req;
207 static DEFINE_MUTEX(ecard_mutex);
210 * Set up the expansion card daemon's page tables.
212 static void ecard_init_pgtables(struct mm_struct *mm)
214 struct vm_area_struct vma;
216 /* We want to set up the page tables for the following mapping:
218 * 0x03000000 0x03000000
219 * 0x03010000 unmapped
220 * 0x03210000 0x03210000
221 * 0x03400000 unmapped
222 * 0x08000000 0x08000000
223 * 0x10000000 unmapped
225 * FIXME: we don't follow this 100% yet.
227 pgd_t *src_pgd, *dst_pgd;
229 src_pgd = pgd_offset(mm, (unsigned long)IO_BASE);
230 dst_pgd = pgd_offset(mm, IO_START);
232 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (IO_SIZE / PGDIR_SIZE));
234 src_pgd = pgd_offset(mm, (unsigned long)EASI_BASE);
235 dst_pgd = pgd_offset(mm, EASI_START);
237 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
239 vma.vm_flags = VM_EXEC;
242 flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
243 flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
246 static int ecard_init_mm(void)
248 struct mm_struct * mm = mm_alloc();
249 struct mm_struct *active_mm = current->active_mm;
255 current->active_mm = mm;
256 activate_mm(active_mm, mm);
258 ecard_init_pgtables(mm);
263 ecard_task(void * unused)
266 * Allocate a mm. We're not a lazy-TLB kernel task since we need
267 * to set page table entries where the user space would be. Note
268 * that this also creates the page tables. Failure is not an
272 panic("kecardd: unable to alloc mm\n");
275 struct ecard_request *req;
277 wait_event_interruptible(ecard_wait, ecard_req != NULL);
279 req = xchg(&ecard_req, NULL);
282 complete(req->complete);
288 * Wake the expansion card daemon to action our request.
290 * FIXME: The test here is not sufficient to detect if the
293 static void ecard_call(struct ecard_request *req)
295 DECLARE_COMPLETION_ONSTACK(completion);
297 req->complete = &completion;
299 mutex_lock(&ecard_mutex);
301 wake_up(&ecard_wait);
304 * Now wait for kecardd to run.
306 wait_for_completion(&completion);
307 mutex_unlock(&ecard_mutex);
310 /* ======================= Mid-level card control ===================== */
313 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
315 struct ecard_request req;
317 req.fn = ecard_task_readbytes;
321 req.use_loader = useld;
327 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
329 struct ex_chunk_dir excd;
337 ecard_readbytes(&excd, ec, index, 8, useld);
339 if (c_id(&excd) == 0) {
340 if (!useld && ec->loader) {
347 if (c_id(&excd) == 0xf0) { /* link */
348 index = c_start(&excd);
351 if (c_id(&excd) == 0x80) { /* loader */
353 ec->loader = kmalloc(c_len(&excd),
356 ecard_readbytes(ec->loader, ec,
358 c_len(&excd), useld);
364 if (c_id(&excd) == id && num-- == 0)
368 if (c_id(&excd) & 0x80) {
369 switch (c_id(&excd) & 0x70) {
371 ecard_readbytes((unsigned char *)excd.d.string, ec,
372 (int)c_start(&excd), c_len(&excd),
379 cd->start_offset = c_start(&excd);
380 memcpy(cd->d.string, excd.d.string, 256);
384 /* ======================= Interrupt control ============================ */
386 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
390 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
394 static int ecard_def_irq_pending(ecard_t *ec)
396 return !ec->irqmask || readb(ec->irqaddr) & ec->irqmask;
399 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
401 panic("ecard_def_fiq_enable called - impossible");
404 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
406 panic("ecard_def_fiq_disable called - impossible");
409 static int ecard_def_fiq_pending(ecard_t *ec)
411 return !ec->fiqmask || readb(ec->fiqaddr) & ec->fiqmask;
414 static expansioncard_ops_t ecard_default_ops = {
415 ecard_def_irq_enable,
416 ecard_def_irq_disable,
417 ecard_def_irq_pending,
418 ecard_def_fiq_enable,
419 ecard_def_fiq_disable,
420 ecard_def_fiq_pending
424 * Enable and disable interrupts from expansion cards.
425 * (interrupts are disabled for these functions).
427 * They are not meant to be called directly, but via enable/disable_irq.
429 static void ecard_irq_unmask(struct irq_data *d)
431 ecard_t *ec = irq_data_get_irq_chip_data(d);
435 ec->ops = &ecard_default_ops;
437 if (ec->claimed && ec->ops->irqenable)
438 ec->ops->irqenable(ec, d->irq);
440 printk(KERN_ERR "ecard: rejecting request to "
441 "enable IRQs for %d\n", d->irq);
445 static void ecard_irq_mask(struct irq_data *d)
447 ecard_t *ec = irq_data_get_irq_chip_data(d);
451 ec->ops = &ecard_default_ops;
453 if (ec->ops && ec->ops->irqdisable)
454 ec->ops->irqdisable(ec, d->irq);
458 static struct irq_chip ecard_chip = {
460 .irq_ack = ecard_irq_mask,
461 .irq_mask = ecard_irq_mask,
462 .irq_unmask = ecard_irq_unmask,
465 void ecard_enablefiq(unsigned int fiqnr)
467 ecard_t *ec = slot_to_ecard(fiqnr);
471 ec->ops = &ecard_default_ops;
473 if (ec->claimed && ec->ops->fiqenable)
474 ec->ops->fiqenable(ec, fiqnr);
476 printk(KERN_ERR "ecard: rejecting request to "
477 "enable FIQs for %d\n", fiqnr);
481 void ecard_disablefiq(unsigned int fiqnr)
483 ecard_t *ec = slot_to_ecard(fiqnr);
487 ec->ops = &ecard_default_ops;
489 if (ec->ops->fiqdisable)
490 ec->ops->fiqdisable(ec, fiqnr);
494 static void ecard_dump_irq_state(void)
498 printk("Expansion card IRQ state:\n");
500 for (ec = cards; ec; ec = ec->next) {
501 if (ec->slot_no == 8)
504 printk(" %d: %sclaimed, ",
505 ec->slot_no, ec->claimed ? "" : "not ");
507 if (ec->ops && ec->ops->irqpending &&
508 ec->ops != &ecard_default_ops)
509 printk("irq %spending\n",
510 ec->ops->irqpending(ec) ? "" : "not ");
512 printk("irqaddr %p, mask = %02X, status = %02X\n",
513 ec->irqaddr, ec->irqmask, readb(ec->irqaddr));
517 static void ecard_check_lockup(struct irq_desc *desc)
519 static unsigned long last;
523 * If the timer interrupt has not run since the last million
524 * unrecognised expansion card interrupts, then there is
525 * something seriously wrong. Disable the expansion card
526 * interrupts so at least we can continue.
528 * Maybe we ought to start a timer to re-enable them some time
531 if (last == jiffies) {
533 if (lockup > 1000000) {
534 printk(KERN_ERR "\nInterrupt lockup detected - "
535 "disabling all expansion card interrupts\n");
537 desc->irq_data.chip->irq_mask(&desc->irq_data);
538 ecard_dump_irq_state();
544 * If we did not recognise the source of this interrupt,
545 * warn the user, but don't flood the user with these messages.
547 if (!last || time_after(jiffies, last + 5*HZ)) {
549 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
550 ecard_dump_irq_state();
554 static void ecard_irq_handler(struct irq_desc *desc)
559 desc->irq_data.chip->irq_mask(&desc->irq_data);
560 for (ec = cards; ec; ec = ec->next) {
563 if (!ec->claimed || !ec->irq || ec->slot_no == 8)
566 if (ec->ops && ec->ops->irqpending)
567 pending = ec->ops->irqpending(ec);
569 pending = ecard_default_ops.irqpending(ec);
572 generic_handle_irq(ec->irq);
576 desc->irq_data.chip->irq_unmask(&desc->irq_data);
579 ecard_check_lockup(desc);
582 static void __iomem *__ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
584 void __iomem *address = NULL;
585 int slot = ec->slot_no;
587 if (ec->slot_no == 8)
588 return ECARD_MEMC8_BASE;
590 ectcr &= ~(1 << slot);
595 address = ECARD_MEMC_BASE + (slot << 14);
600 address = ECARD_IOC_BASE + (slot << 14);
602 address = ECARD_IOC4_BASE + ((slot - 4) << 14);
604 address += speed << 19;
608 address = ECARD_EASI_BASE + (slot << 24);
609 if (speed == ECARD_FAST)
618 iomd_writeb(ectcr, IOMD_ECTCR);
623 static int ecard_prints(struct seq_file *m, ecard_t *ec)
625 seq_printf(m, " %d: %s ", ec->slot_no, ec->easi ? "EASI" : " ");
627 if (ec->cid.id == 0) {
628 struct in_chunk_dir incd;
630 seq_printf(m, "[%04X:%04X] ",
631 ec->cid.manufacturer, ec->cid.product);
633 if (!ec->card_desc && ec->cid.cd &&
634 ecard_readchunk(&incd, ec, 0xf5, 0)) {
635 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
638 strcpy((char *)ec->card_desc, incd.d.string);
641 seq_printf(m, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
643 seq_printf(m, "Simple card %d\n", ec->cid.id);
648 static int ecard_devices_proc_show(struct seq_file *m, void *v)
659 static int ecard_devices_proc_open(struct inode *inode, struct file *file)
661 return single_open(file, ecard_devices_proc_show, NULL);
664 static const struct file_operations bus_ecard_proc_fops = {
665 .owner = THIS_MODULE,
666 .open = ecard_devices_proc_open,
669 .release = single_release,
672 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
674 static void ecard_proc_init(void)
676 proc_bus_ecard_dir = proc_mkdir("bus/ecard", NULL);
677 proc_create("devices", 0, proc_bus_ecard_dir, &bus_ecard_proc_fops);
680 #define ec_set_resource(ec,nr,st,sz) \
682 (ec)->resource[nr].name = dev_name(&ec->dev); \
683 (ec)->resource[nr].start = st; \
684 (ec)->resource[nr].end = (st) + (sz) - 1; \
685 (ec)->resource[nr].flags = IORESOURCE_MEM; \
688 static void __init ecard_free_card(struct expansion_card *ec)
692 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
693 if (ec->resource[i].flags)
694 release_resource(&ec->resource[i]);
699 static struct expansion_card *__init ecard_alloc_card(int type, int slot)
701 struct expansion_card *ec;
705 ec = kzalloc(sizeof(ecard_t), GFP_KERNEL);
707 ec = ERR_PTR(-ENOMEM);
712 ec->easi = type == ECARD_EASI;
716 ec->ops = &ecard_default_ops;
718 dev_set_name(&ec->dev, "ecard%d", slot);
719 ec->dev.parent = NULL;
720 ec->dev.bus = &ecard_bus_type;
721 ec->dev.dma_mask = &ec->dma_mask;
722 ec->dma_mask = (u64)0xffffffff;
723 ec->dev.coherent_dma_mask = ec->dma_mask;
726 ec_set_resource(ec, ECARD_RES_MEMC,
727 PODSLOT_MEMC_BASE + (slot << 14),
729 base = PODSLOT_IOC0_BASE + (slot << 14);
731 base = PODSLOT_IOC4_BASE + ((slot - 4) << 14);
733 #ifdef CONFIG_ARCH_RPC
735 ec_set_resource(ec, ECARD_RES_EASI,
736 PODSLOT_EASI_BASE + (slot << 24),
741 ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE, NETSLOT_SIZE);
745 for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++)
746 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
747 base + (i << 19), PODSLOT_IOC_SIZE);
749 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
750 if (ec->resource[i].flags &&
751 request_resource(&iomem_resource, &ec->resource[i])) {
752 dev_err(&ec->dev, "resource(s) not available\n");
753 ec->resource[i].end -= ec->resource[i].start;
754 ec->resource[i].start = 0;
755 ec->resource[i].flags = 0;
763 static ssize_t ecard_show_irq(struct device *dev, struct device_attribute *attr, char *buf)
765 struct expansion_card *ec = ECARD_DEV(dev);
766 return sprintf(buf, "%u\n", ec->irq);
769 static ssize_t ecard_show_dma(struct device *dev, struct device_attribute *attr, char *buf)
771 struct expansion_card *ec = ECARD_DEV(dev);
772 return sprintf(buf, "%u\n", ec->dma);
775 static ssize_t ecard_show_resources(struct device *dev, struct device_attribute *attr, char *buf)
777 struct expansion_card *ec = ECARD_DEV(dev);
781 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
782 str += sprintf(str, "%08x %08x %08lx\n",
783 ec->resource[i].start,
785 ec->resource[i].flags);
790 static ssize_t ecard_show_vendor(struct device *dev, struct device_attribute *attr, char *buf)
792 struct expansion_card *ec = ECARD_DEV(dev);
793 return sprintf(buf, "%u\n", ec->cid.manufacturer);
796 static ssize_t ecard_show_device(struct device *dev, struct device_attribute *attr, char *buf)
798 struct expansion_card *ec = ECARD_DEV(dev);
799 return sprintf(buf, "%u\n", ec->cid.product);
802 static ssize_t ecard_show_type(struct device *dev, struct device_attribute *attr, char *buf)
804 struct expansion_card *ec = ECARD_DEV(dev);
805 return sprintf(buf, "%s\n", ec->easi ? "EASI" : "IOC");
808 static struct device_attribute ecard_dev_attrs[] = {
809 __ATTR(device, S_IRUGO, ecard_show_device, NULL),
810 __ATTR(dma, S_IRUGO, ecard_show_dma, NULL),
811 __ATTR(irq, S_IRUGO, ecard_show_irq, NULL),
812 __ATTR(resource, S_IRUGO, ecard_show_resources, NULL),
813 __ATTR(type, S_IRUGO, ecard_show_type, NULL),
814 __ATTR(vendor, S_IRUGO, ecard_show_vendor, NULL),
819 int ecard_request_resources(struct expansion_card *ec)
823 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
824 if (ecard_resource_end(ec, i) &&
825 !request_mem_region(ecard_resource_start(ec, i),
826 ecard_resource_len(ec, i),
827 ec->dev.driver->name)) {
835 if (ecard_resource_end(ec, i))
836 release_mem_region(ecard_resource_start(ec, i),
837 ecard_resource_len(ec, i));
841 EXPORT_SYMBOL(ecard_request_resources);
843 void ecard_release_resources(struct expansion_card *ec)
847 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
848 if (ecard_resource_end(ec, i))
849 release_mem_region(ecard_resource_start(ec, i),
850 ecard_resource_len(ec, i));
852 EXPORT_SYMBOL(ecard_release_resources);
854 void ecard_setirq(struct expansion_card *ec, const struct expansion_card_ops *ops, void *irq_data)
856 ec->irq_data = irq_data;
860 EXPORT_SYMBOL(ecard_setirq);
862 void __iomem *ecardm_iomap(struct expansion_card *ec, unsigned int res,
863 unsigned long offset, unsigned long maxsize)
865 unsigned long start = ecard_resource_start(ec, res);
866 unsigned long end = ecard_resource_end(ec, res);
868 if (offset > (end - start))
872 if (maxsize && end - start > maxsize)
873 end = start + maxsize;
875 return devm_ioremap(&ec->dev, start, end - start);
877 EXPORT_SYMBOL(ecardm_iomap);
880 * Probe for an expansion card.
882 * If bit 1 of the first byte of the card is set, then the
883 * card does not exist.
885 static int __init ecard_probe(int slot, unsigned irq, card_type_t type)
893 ec = ecard_alloc_card(type, slot);
900 if ((addr = __ecard_address(ec, type, ECARD_SYNC)) == NULL)
904 ecard_readbytes(&cid, ec, 0, 16, 0);
908 ec->cid.id = cid.r_id;
909 ec->cid.cd = cid.r_cd;
910 ec->cid.is = cid.r_is;
912 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
913 ec->cid.product = ecard_getu16(cid.r_prod);
914 ec->cid.country = cid.r_country;
915 ec->cid.irqmask = cid.r_irqmask;
916 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
917 ec->cid.fiqmask = cid.r_fiqmask;
918 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
923 ec->irqmask = ec->cid.irqmask;
924 ec->irqaddr += ec->cid.irqoff;
925 ec->fiqmask = ec->cid.fiqmask;
926 ec->fiqaddr += ec->cid.fiqoff;
932 for (i = 0; i < ARRAY_SIZE(blacklist); i++)
933 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
934 blacklist[i].product == ec->cid.product) {
935 ec->card_desc = blacklist[i].type;
942 * hook the interrupt handlers
945 irq_set_chip_and_handler(ec->irq, &ecard_chip,
947 irq_set_chip_data(ec->irq, ec);
948 irq_clear_status_flags(ec->irq, IRQ_NOREQUEST);
951 #ifdef CONFIG_ARCH_RPC
952 /* On RiscPC, only first two slots have DMA capability */
957 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
960 slot_to_expcard[slot] = ec;
962 rc = device_register(&ec->dev);
975 * Initialise the expansion card system.
976 * Locate all hardware - interrupt management and
979 static int __init ecard_init(void)
981 struct task_struct *task;
984 irqbase = irq_alloc_descs(-1, 0, 8, -1);
988 task = kthread_run(ecard_task, NULL, "kecardd");
990 printk(KERN_ERR "Ecard: unable to create kernel thread: %ld\n",
992 irq_free_descs(irqbase, 8);
993 return PTR_ERR(task);
996 printk("Probing expansion cards\n");
998 for (slot = 0; slot < 8; slot ++) {
999 if (ecard_probe(slot, irqbase + slot, ECARD_EASI) == -ENODEV)
1000 ecard_probe(slot, irqbase + slot, ECARD_IOC);
1003 ecard_probe(8, 11, ECARD_IOC);
1005 irq_set_chained_handler(IRQ_EXPANSIONCARD, ecard_irq_handler);
1012 subsys_initcall(ecard_init);
1017 static const struct ecard_id *
1018 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
1022 for (i = 0; ids[i].manufacturer != 65535; i++)
1023 if (ec->cid.manufacturer == ids[i].manufacturer &&
1024 ec->cid.product == ids[i].product)
1030 static int ecard_drv_probe(struct device *dev)
1032 struct expansion_card *ec = ECARD_DEV(dev);
1033 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1034 const struct ecard_id *id;
1037 id = ecard_match_device(drv->id_table, ec);
1040 ret = drv->probe(ec, id);
1046 static int ecard_drv_remove(struct device *dev)
1048 struct expansion_card *ec = ECARD_DEV(dev);
1049 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1055 * Restore the default operations. We ensure that the
1056 * ops are set before we change the data.
1058 ec->ops = &ecard_default_ops;
1060 ec->irq_data = NULL;
1066 * Before rebooting, we must make sure that the expansion card is in a
1067 * sensible state, so it can be re-detected. This means that the first
1068 * page of the ROM must be visible. We call the expansion cards reset
1071 static void ecard_drv_shutdown(struct device *dev)
1073 struct expansion_card *ec = ECARD_DEV(dev);
1074 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1075 struct ecard_request req;
1084 * If this card has a loader, call the reset handler.
1087 req.fn = ecard_task_reset;
1093 int ecard_register_driver(struct ecard_driver *drv)
1095 drv->drv.bus = &ecard_bus_type;
1097 return driver_register(&drv->drv);
1100 void ecard_remove_driver(struct ecard_driver *drv)
1102 driver_unregister(&drv->drv);
1105 static int ecard_match(struct device *_dev, struct device_driver *_drv)
1107 struct expansion_card *ec = ECARD_DEV(_dev);
1108 struct ecard_driver *drv = ECARD_DRV(_drv);
1111 if (drv->id_table) {
1112 ret = ecard_match_device(drv->id_table, ec) != NULL;
1114 ret = ec->cid.id == drv->id;
1120 struct bus_type ecard_bus_type = {
1122 .dev_attrs = ecard_dev_attrs,
1123 .match = ecard_match,
1124 .probe = ecard_drv_probe,
1125 .remove = ecard_drv_remove,
1126 .shutdown = ecard_drv_shutdown,
1129 static int ecard_bus_init(void)
1131 return bus_register(&ecard_bus_type);
1134 postcore_initcall(ecard_bus_init);
1136 EXPORT_SYMBOL(ecard_readchunk);
1137 EXPORT_SYMBOL(ecard_register_driver);
1138 EXPORT_SYMBOL(ecard_remove_driver);
1139 EXPORT_SYMBOL(ecard_bus_type);