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/sched/mm.h>
35 #include <linux/interrupt.h>
36 #include <linux/completion.h>
37 #include <linux/reboot.h>
39 #include <linux/slab.h>
40 #include <linux/proc_fs.h>
41 #include <linux/seq_file.h>
42 #include <linux/device.h>
43 #include <linux/init.h>
44 #include <linux/mutex.h>
45 #include <linux/kthread.h>
46 #include <linux/irq.h>
50 #include <asm/ecard.h>
51 #include <mach/hardware.h>
53 #include <asm/mmu_context.h>
54 #include <asm/mach/irq.h>
55 #include <asm/tlbflush.h>
59 struct ecard_request {
60 void (*fn)(struct ecard_request *);
64 unsigned int use_loader;
66 struct completion *complete;
69 struct expcard_blacklist {
70 unsigned short manufacturer;
71 unsigned short product;
75 static ecard_t *cards;
76 static ecard_t *slot_to_expcard[MAX_ECARDS];
77 static unsigned int ectcr;
79 /* List of descriptions of cards which don't have an extended
80 * identification, or chunk directories containing a description.
82 static struct expcard_blacklist __initdata blacklist[] = {
83 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
87 ecard_loader_reset(unsigned long base, loader_t loader);
89 ecard_loader_read(int off, unsigned long base, loader_t loader);
91 static inline unsigned short ecard_getu16(unsigned char *v)
93 return v[0] | v[1] << 8;
96 static inline signed long ecard_gets24(unsigned char *v)
98 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
101 static inline ecard_t *slot_to_ecard(unsigned int slot)
103 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
106 /* ===================== Expansion card daemon ======================== */
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
113 * This should allow 99% of loaders to be called from Linux.
115 * From a security standpoint, we trust the card vendors. This
116 * may be a misplaced trust.
118 static void ecard_task_reset(struct ecard_request *req)
120 struct expansion_card *ec = req->ec;
121 struct resource *res;
123 res = ec->slot_no == 8
124 ? &ec->resource[ECARD_RES_MEMC]
126 ? &ec->resource[ECARD_RES_EASI]
127 : &ec->resource[ECARD_RES_IOCSYNC];
129 ecard_loader_reset(res->start, ec->loader);
132 static void ecard_task_readbytes(struct ecard_request *req)
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;
139 if (ec->slot_no == 8) {
140 void __iomem *base = (void __iomem *)
141 ec->resource[ECARD_RES_MEMC].start;
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.
148 static unsigned int index;
151 page = (off >> 12) * 4;
158 * If we are reading offset 0, or our current index is
159 * greater than the offset, reset the hardware index counter.
161 if (off == 0 || index > off) {
167 * Increment the hardware index counter until we get to the
168 * required offset. The read bytes are discarded.
170 while (index < off) {
176 *buf++ = readb(base + page);
180 unsigned long base = (ec->easi
181 ? &ec->resource[ECARD_RES_EASI]
182 : &ec->resource[ECARD_RES_IOCSYNC])->start;
183 void __iomem *pbase = (void __iomem *)base;
185 if (!req->use_loader || !ec->loader) {
188 *buf++ = readb(pbase + off);
194 * The following is required by some
195 * expansion card loader programs.
197 *(unsigned long *)0x108 = 0;
198 *buf++ = ecard_loader_read(off++, base,
206 static DECLARE_WAIT_QUEUE_HEAD(ecard_wait);
207 static struct ecard_request *ecard_req;
208 static DEFINE_MUTEX(ecard_mutex);
211 * Set up the expansion card daemon's page tables.
213 static void ecard_init_pgtables(struct mm_struct *mm)
215 struct vm_area_struct vma;
217 /* We want to set up the page tables for the following mapping:
219 * 0x03000000 0x03000000
220 * 0x03010000 unmapped
221 * 0x03210000 0x03210000
222 * 0x03400000 unmapped
223 * 0x08000000 0x08000000
224 * 0x10000000 unmapped
226 * FIXME: we don't follow this 100% yet.
228 pgd_t *src_pgd, *dst_pgd;
230 src_pgd = pgd_offset(mm, (unsigned long)IO_BASE);
231 dst_pgd = pgd_offset(mm, IO_START);
233 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (IO_SIZE / PGDIR_SIZE));
235 src_pgd = pgd_offset(mm, (unsigned long)EASI_BASE);
236 dst_pgd = pgd_offset(mm, EASI_START);
238 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
240 vma.vm_flags = VM_EXEC;
243 flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
244 flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
247 static int ecard_init_mm(void)
249 struct mm_struct * mm = mm_alloc();
250 struct mm_struct *active_mm = current->active_mm;
256 current->active_mm = mm;
257 activate_mm(active_mm, mm);
259 ecard_init_pgtables(mm);
264 ecard_task(void * unused)
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
273 panic("kecardd: unable to alloc mm\n");
276 struct ecard_request *req;
278 wait_event_interruptible(ecard_wait, ecard_req != NULL);
280 req = xchg(&ecard_req, NULL);
283 complete(req->complete);
289 * Wake the expansion card daemon to action our request.
291 * FIXME: The test here is not sufficient to detect if the
294 static void ecard_call(struct ecard_request *req)
296 DECLARE_COMPLETION_ONSTACK(completion);
298 req->complete = &completion;
300 mutex_lock(&ecard_mutex);
302 wake_up(&ecard_wait);
305 * Now wait for kecardd to run.
307 wait_for_completion(&completion);
308 mutex_unlock(&ecard_mutex);
311 /* ======================= Mid-level card control ===================== */
314 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
316 struct ecard_request req;
318 req.fn = ecard_task_readbytes;
322 req.use_loader = useld;
328 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
330 struct ex_chunk_dir excd;
338 ecard_readbytes(&excd, ec, index, 8, useld);
340 if (c_id(&excd) == 0) {
341 if (!useld && ec->loader) {
348 if (c_id(&excd) == 0xf0) { /* link */
349 index = c_start(&excd);
352 if (c_id(&excd) == 0x80) { /* loader */
354 ec->loader = kmalloc(c_len(&excd),
357 ecard_readbytes(ec->loader, ec,
359 c_len(&excd), useld);
365 if (c_id(&excd) == id && num-- == 0)
369 if (c_id(&excd) & 0x80) {
370 switch (c_id(&excd) & 0x70) {
372 ecard_readbytes((unsigned char *)excd.d.string, ec,
373 (int)c_start(&excd), c_len(&excd),
380 cd->start_offset = c_start(&excd);
381 memcpy(cd->d.string, excd.d.string, 256);
385 /* ======================= Interrupt control ============================ */
387 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
391 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
395 static int ecard_def_irq_pending(ecard_t *ec)
397 return !ec->irqmask || readb(ec->irqaddr) & ec->irqmask;
400 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
402 panic("ecard_def_fiq_enable called - impossible");
405 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
407 panic("ecard_def_fiq_disable called - impossible");
410 static int ecard_def_fiq_pending(ecard_t *ec)
412 return !ec->fiqmask || readb(ec->fiqaddr) & ec->fiqmask;
415 static 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
425 * Enable and disable interrupts from expansion cards.
426 * (interrupts are disabled for these functions).
428 * They are not meant to be called directly, but via enable/disable_irq.
430 static void ecard_irq_unmask(struct irq_data *d)
432 ecard_t *ec = irq_data_get_irq_chip_data(d);
436 ec->ops = &ecard_default_ops;
438 if (ec->claimed && ec->ops->irqenable)
439 ec->ops->irqenable(ec, d->irq);
441 printk(KERN_ERR "ecard: rejecting request to "
442 "enable IRQs for %d\n", d->irq);
446 static void ecard_irq_mask(struct irq_data *d)
448 ecard_t *ec = irq_data_get_irq_chip_data(d);
452 ec->ops = &ecard_default_ops;
454 if (ec->ops && ec->ops->irqdisable)
455 ec->ops->irqdisable(ec, d->irq);
459 static struct irq_chip ecard_chip = {
461 .irq_ack = ecard_irq_mask,
462 .irq_mask = ecard_irq_mask,
463 .irq_unmask = ecard_irq_unmask,
466 void ecard_enablefiq(unsigned int fiqnr)
468 ecard_t *ec = slot_to_ecard(fiqnr);
472 ec->ops = &ecard_default_ops;
474 if (ec->claimed && ec->ops->fiqenable)
475 ec->ops->fiqenable(ec, fiqnr);
477 printk(KERN_ERR "ecard: rejecting request to "
478 "enable FIQs for %d\n", fiqnr);
482 void ecard_disablefiq(unsigned int fiqnr)
484 ecard_t *ec = slot_to_ecard(fiqnr);
488 ec->ops = &ecard_default_ops;
490 if (ec->ops->fiqdisable)
491 ec->ops->fiqdisable(ec, fiqnr);
495 static void ecard_dump_irq_state(void)
499 printk("Expansion card IRQ state:\n");
501 for (ec = cards; ec; ec = ec->next) {
502 if (ec->slot_no == 8)
505 printk(" %d: %sclaimed, ",
506 ec->slot_no, ec->claimed ? "" : "not ");
508 if (ec->ops && ec->ops->irqpending &&
509 ec->ops != &ecard_default_ops)
510 printk("irq %spending\n",
511 ec->ops->irqpending(ec) ? "" : "not ");
513 printk("irqaddr %p, mask = %02X, status = %02X\n",
514 ec->irqaddr, ec->irqmask, readb(ec->irqaddr));
518 static void ecard_check_lockup(struct irq_desc *desc)
520 static unsigned long last;
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.
529 * Maybe we ought to start a timer to re-enable them some time
532 if (last == jiffies) {
534 if (lockup > 1000000) {
535 printk(KERN_ERR "\nInterrupt lockup detected - "
536 "disabling all expansion card interrupts\n");
538 desc->irq_data.chip->irq_mask(&desc->irq_data);
539 ecard_dump_irq_state();
545 * If we did not recognise the source of this interrupt,
546 * warn the user, but don't flood the user with these messages.
548 if (!last || time_after(jiffies, last + 5*HZ)) {
550 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
551 ecard_dump_irq_state();
555 static void ecard_irq_handler(struct irq_desc *desc)
560 desc->irq_data.chip->irq_mask(&desc->irq_data);
561 for (ec = cards; ec; ec = ec->next) {
564 if (!ec->claimed || !ec->irq || ec->slot_no == 8)
567 if (ec->ops && ec->ops->irqpending)
568 pending = ec->ops->irqpending(ec);
570 pending = ecard_default_ops.irqpending(ec);
573 generic_handle_irq(ec->irq);
577 desc->irq_data.chip->irq_unmask(&desc->irq_data);
580 ecard_check_lockup(desc);
583 static void __iomem *__ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
585 void __iomem *address = NULL;
586 int slot = ec->slot_no;
588 if (ec->slot_no == 8)
589 return ECARD_MEMC8_BASE;
591 ectcr &= ~(1 << slot);
596 address = ECARD_MEMC_BASE + (slot << 14);
601 address = ECARD_IOC_BASE + (slot << 14);
603 address = ECARD_IOC4_BASE + ((slot - 4) << 14);
605 address += speed << 19;
609 address = ECARD_EASI_BASE + (slot << 24);
610 if (speed == ECARD_FAST)
619 iomd_writeb(ectcr, IOMD_ECTCR);
624 static int ecard_prints(struct seq_file *m, ecard_t *ec)
626 seq_printf(m, " %d: %s ", ec->slot_no, ec->easi ? "EASI" : " ");
628 if (ec->cid.id == 0) {
629 struct in_chunk_dir incd;
631 seq_printf(m, "[%04X:%04X] ",
632 ec->cid.manufacturer, ec->cid.product);
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);
639 strcpy((char *)ec->card_desc, incd.d.string);
642 seq_printf(m, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
644 seq_printf(m, "Simple card %d\n", ec->cid.id);
649 static int ecard_devices_proc_show(struct seq_file *m, void *v)
660 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
662 static void ecard_proc_init(void)
664 proc_bus_ecard_dir = proc_mkdir("bus/ecard", NULL);
665 proc_create_single("devices", 0, proc_bus_ecard_dir,
666 ecard_devices_proc_show);
669 #define ec_set_resource(ec,nr,st,sz) \
671 (ec)->resource[nr].name = dev_name(&ec->dev); \
672 (ec)->resource[nr].start = st; \
673 (ec)->resource[nr].end = (st) + (sz) - 1; \
674 (ec)->resource[nr].flags = IORESOURCE_MEM; \
677 static void __init ecard_free_card(struct expansion_card *ec)
681 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
682 if (ec->resource[i].flags)
683 release_resource(&ec->resource[i]);
688 static struct expansion_card *__init ecard_alloc_card(int type, int slot)
690 struct expansion_card *ec;
694 ec = kzalloc(sizeof(ecard_t), GFP_KERNEL);
696 ec = ERR_PTR(-ENOMEM);
701 ec->easi = type == ECARD_EASI;
705 ec->ops = &ecard_default_ops;
707 dev_set_name(&ec->dev, "ecard%d", slot);
708 ec->dev.parent = NULL;
709 ec->dev.bus = &ecard_bus_type;
710 ec->dev.dma_mask = &ec->dma_mask;
711 ec->dma_mask = (u64)0xffffffff;
712 ec->dev.coherent_dma_mask = ec->dma_mask;
715 ec_set_resource(ec, ECARD_RES_MEMC,
716 PODSLOT_MEMC_BASE + (slot << 14),
718 base = PODSLOT_IOC0_BASE + (slot << 14);
720 base = PODSLOT_IOC4_BASE + ((slot - 4) << 14);
722 #ifdef CONFIG_ARCH_RPC
724 ec_set_resource(ec, ECARD_RES_EASI,
725 PODSLOT_EASI_BASE + (slot << 24),
730 ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE, NETSLOT_SIZE);
734 for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++)
735 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
736 base + (i << 19), PODSLOT_IOC_SIZE);
738 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
739 if (ec->resource[i].flags &&
740 request_resource(&iomem_resource, &ec->resource[i])) {
741 dev_err(&ec->dev, "resource(s) not available\n");
742 ec->resource[i].end -= ec->resource[i].start;
743 ec->resource[i].start = 0;
744 ec->resource[i].flags = 0;
752 static ssize_t irq_show(struct device *dev, struct device_attribute *attr, char *buf)
754 struct expansion_card *ec = ECARD_DEV(dev);
755 return sprintf(buf, "%u\n", ec->irq);
757 static DEVICE_ATTR_RO(irq);
759 static ssize_t dma_show(struct device *dev, struct device_attribute *attr, char *buf)
761 struct expansion_card *ec = ECARD_DEV(dev);
762 return sprintf(buf, "%u\n", ec->dma);
764 static DEVICE_ATTR_RO(dma);
766 static ssize_t resource_show(struct device *dev, struct device_attribute *attr, char *buf)
768 struct expansion_card *ec = ECARD_DEV(dev);
772 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
773 str += sprintf(str, "%08x %08x %08lx\n",
774 ec->resource[i].start,
776 ec->resource[i].flags);
780 static DEVICE_ATTR_RO(resource);
782 static ssize_t vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
784 struct expansion_card *ec = ECARD_DEV(dev);
785 return sprintf(buf, "%u\n", ec->cid.manufacturer);
787 static DEVICE_ATTR_RO(vendor);
789 static ssize_t device_show(struct device *dev, struct device_attribute *attr, char *buf)
791 struct expansion_card *ec = ECARD_DEV(dev);
792 return sprintf(buf, "%u\n", ec->cid.product);
794 static DEVICE_ATTR_RO(device);
796 static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf)
798 struct expansion_card *ec = ECARD_DEV(dev);
799 return sprintf(buf, "%s\n", ec->easi ? "EASI" : "IOC");
801 static DEVICE_ATTR_RO(type);
803 static struct attribute *ecard_dev_attrs[] = {
804 &dev_attr_device.attr,
807 &dev_attr_resource.attr,
809 &dev_attr_vendor.attr,
812 ATTRIBUTE_GROUPS(ecard_dev);
814 int ecard_request_resources(struct expansion_card *ec)
818 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
819 if (ecard_resource_end(ec, i) &&
820 !request_mem_region(ecard_resource_start(ec, i),
821 ecard_resource_len(ec, i),
822 ec->dev.driver->name)) {
830 if (ecard_resource_end(ec, i))
831 release_mem_region(ecard_resource_start(ec, i),
832 ecard_resource_len(ec, i));
836 EXPORT_SYMBOL(ecard_request_resources);
838 void ecard_release_resources(struct expansion_card *ec)
842 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
843 if (ecard_resource_end(ec, i))
844 release_mem_region(ecard_resource_start(ec, i),
845 ecard_resource_len(ec, i));
847 EXPORT_SYMBOL(ecard_release_resources);
849 void ecard_setirq(struct expansion_card *ec, const struct expansion_card_ops *ops, void *irq_data)
851 ec->irq_data = irq_data;
855 EXPORT_SYMBOL(ecard_setirq);
857 void __iomem *ecardm_iomap(struct expansion_card *ec, unsigned int res,
858 unsigned long offset, unsigned long maxsize)
860 unsigned long start = ecard_resource_start(ec, res);
861 unsigned long end = ecard_resource_end(ec, res);
863 if (offset > (end - start))
867 if (maxsize && end - start > maxsize)
868 end = start + maxsize;
870 return devm_ioremap(&ec->dev, start, end - start);
872 EXPORT_SYMBOL(ecardm_iomap);
875 * Probe for an expansion card.
877 * If bit 1 of the first byte of the card is set, then the
878 * card does not exist.
880 static int __init ecard_probe(int slot, unsigned irq, card_type_t type)
888 ec = ecard_alloc_card(type, slot);
895 if ((addr = __ecard_address(ec, type, ECARD_SYNC)) == NULL)
899 ecard_readbytes(&cid, ec, 0, 16, 0);
903 ec->cid.id = cid.r_id;
904 ec->cid.cd = cid.r_cd;
905 ec->cid.is = cid.r_is;
907 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
908 ec->cid.product = ecard_getu16(cid.r_prod);
909 ec->cid.country = cid.r_country;
910 ec->cid.irqmask = cid.r_irqmask;
911 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
912 ec->cid.fiqmask = cid.r_fiqmask;
913 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
918 ec->irqmask = ec->cid.irqmask;
919 ec->irqaddr += ec->cid.irqoff;
920 ec->fiqmask = ec->cid.fiqmask;
921 ec->fiqaddr += ec->cid.fiqoff;
927 for (i = 0; i < ARRAY_SIZE(blacklist); i++)
928 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
929 blacklist[i].product == ec->cid.product) {
930 ec->card_desc = blacklist[i].type;
937 * hook the interrupt handlers
940 irq_set_chip_and_handler(ec->irq, &ecard_chip,
942 irq_set_chip_data(ec->irq, ec);
943 irq_clear_status_flags(ec->irq, IRQ_NOREQUEST);
946 #ifdef CONFIG_ARCH_RPC
947 /* On RiscPC, only first two slots have DMA capability */
952 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
955 slot_to_expcard[slot] = ec;
957 rc = device_register(&ec->dev);
970 * Initialise the expansion card system.
971 * Locate all hardware - interrupt management and
974 static int __init ecard_init(void)
976 struct task_struct *task;
979 irqbase = irq_alloc_descs(-1, 0, 8, -1);
983 task = kthread_run(ecard_task, NULL, "kecardd");
985 printk(KERN_ERR "Ecard: unable to create kernel thread: %ld\n",
987 irq_free_descs(irqbase, 8);
988 return PTR_ERR(task);
991 printk("Probing expansion cards\n");
993 for (slot = 0; slot < 8; slot ++) {
994 if (ecard_probe(slot, irqbase + slot, ECARD_EASI) == -ENODEV)
995 ecard_probe(slot, irqbase + slot, ECARD_IOC);
998 ecard_probe(8, 11, ECARD_IOC);
1000 irq_set_chained_handler(IRQ_EXPANSIONCARD, ecard_irq_handler);
1007 subsys_initcall(ecard_init);
1012 static const struct ecard_id *
1013 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
1017 for (i = 0; ids[i].manufacturer != 65535; i++)
1018 if (ec->cid.manufacturer == ids[i].manufacturer &&
1019 ec->cid.product == ids[i].product)
1025 static int ecard_drv_probe(struct device *dev)
1027 struct expansion_card *ec = ECARD_DEV(dev);
1028 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1029 const struct ecard_id *id;
1032 id = ecard_match_device(drv->id_table, ec);
1035 ret = drv->probe(ec, id);
1041 static int ecard_drv_remove(struct device *dev)
1043 struct expansion_card *ec = ECARD_DEV(dev);
1044 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1050 * Restore the default operations. We ensure that the
1051 * ops are set before we change the data.
1053 ec->ops = &ecard_default_ops;
1055 ec->irq_data = NULL;
1061 * Before rebooting, we must make sure that the expansion card is in a
1062 * sensible state, so it can be re-detected. This means that the first
1063 * page of the ROM must be visible. We call the expansion cards reset
1066 static void ecard_drv_shutdown(struct device *dev)
1068 struct expansion_card *ec = ECARD_DEV(dev);
1069 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1070 struct ecard_request req;
1079 * If this card has a loader, call the reset handler.
1082 req.fn = ecard_task_reset;
1088 int ecard_register_driver(struct ecard_driver *drv)
1090 drv->drv.bus = &ecard_bus_type;
1092 return driver_register(&drv->drv);
1095 void ecard_remove_driver(struct ecard_driver *drv)
1097 driver_unregister(&drv->drv);
1100 static int ecard_match(struct device *_dev, struct device_driver *_drv)
1102 struct expansion_card *ec = ECARD_DEV(_dev);
1103 struct ecard_driver *drv = ECARD_DRV(_drv);
1106 if (drv->id_table) {
1107 ret = ecard_match_device(drv->id_table, ec) != NULL;
1109 ret = ec->cid.id == drv->id;
1115 struct bus_type ecard_bus_type = {
1117 .dev_groups = ecard_dev_groups,
1118 .match = ecard_match,
1119 .probe = ecard_drv_probe,
1120 .remove = ecard_drv_remove,
1121 .shutdown = ecard_drv_shutdown,
1124 static int ecard_bus_init(void)
1126 return bus_register(&ecard_bus_type);
1129 postcore_initcall(ecard_bus_init);
1131 EXPORT_SYMBOL(ecard_readchunk);
1132 EXPORT_SYMBOL(ecard_register_driver);
1133 EXPORT_SYMBOL(ecard_remove_driver);
1134 EXPORT_SYMBOL(ecard_bus_type);