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/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/sched.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/device.h>
42 #include <linux/init.h>
45 #include <asm/ecard.h>
46 #include <asm/hardware.h>
49 #include <asm/mmu_context.h>
50 #include <asm/mach/irq.h>
51 #include <asm/tlbflush.h>
53 #ifndef CONFIG_ARCH_RPC
57 struct ecard_request {
58 void (*fn)(struct ecard_request *);
62 unsigned int use_loader;
64 struct completion *complete;
67 struct expcard_blacklist {
68 unsigned short manufacturer;
69 unsigned short product;
73 static ecard_t *cards;
74 static ecard_t *slot_to_expcard[MAX_ECARDS];
75 static unsigned int ectcr;
77 static unsigned int have_expmask;
80 /* List of descriptions of cards which don't have an extended
81 * identification, or chunk directories containing a description.
83 static struct expcard_blacklist __initdata blacklist[] = {
84 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
88 ecard_loader_reset(volatile unsigned char *pa, loader_t loader);
90 ecard_loader_read(int off, volatile unsigned char *pa, loader_t loader);
92 static const struct ecard_id *
93 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec);
95 static inline unsigned short
96 ecard_getu16(unsigned char *v)
98 return v[0] | v[1] << 8;
101 static inline signed long
102 ecard_gets24(unsigned char *v)
104 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
107 static inline ecard_t *
108 slot_to_ecard(unsigned int slot)
110 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
113 /* ===================== Expansion card daemon ======================== */
115 * Since the loader programs on the expansion cards need to be run
116 * in a specific environment, create a separate task with this
117 * environment up, and pass requests to this task as and when we
120 * This should allow 99% of loaders to be called from Linux.
122 * From a security standpoint, we trust the card vendors. This
123 * may be a misplaced trust.
125 #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
126 #define POD_INT_ADDR(x) ((volatile unsigned char *)\
127 ((BUS_ADDR((x)) - IO_BASE) + IO_START))
129 static void ecard_task_reset(struct ecard_request *req)
131 struct expansion_card *ec = req->ec;
133 ecard_loader_reset(POD_INT_ADDR(ec->podaddr), ec->loader);
136 static void ecard_task_readbytes(struct ecard_request *req)
138 unsigned char *buf = (unsigned char *)req->buffer;
139 volatile unsigned char *base_addr =
140 (volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);
141 unsigned int len = req->length;
142 unsigned int off = req->address;
144 if (req->ec->slot_no == 8) {
146 * The card maintains an index which increments the address
147 * into a 4096-byte page on each access. We need to keep
148 * track of the counter.
150 static unsigned int index;
153 page = (off >> 12) * 4;
160 * If we are reading offset 0, or our current index is
161 * greater than the offset, reset the hardware index counter.
163 if (off == 0 || index > off) {
169 * Increment the hardware index counter until we get to the
170 * required offset. The read bytes are discarded.
172 while (index < off) {
174 byte = base_addr[page];
179 *buf++ = base_addr[page];
184 if (!req->use_loader || !req->ec->loader) {
187 *buf++ = base_addr[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_addr,
205 static DECLARE_WAIT_QUEUE_HEAD(ecard_wait);
206 static struct ecard_request *ecard_req;
207 static DECLARE_MUTEX(ecard_sem);
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, 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, EASI_BASE);
235 dst_pgd = pgd_offset(mm, EASI_START);
237 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
241 flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
242 flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
245 static int ecard_init_mm(void)
247 struct mm_struct * mm = mm_alloc();
248 struct mm_struct *active_mm = current->active_mm;
254 current->active_mm = mm;
255 activate_mm(active_mm, mm);
257 ecard_init_pgtables(mm);
262 ecard_task(void * unused)
264 daemonize("kecardd");
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(completion);
298 req->complete = &completion;
302 wake_up(&ecard_wait);
305 * Now wait for kecardd to run.
307 wait_for_completion(&completion);
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 = (loader_t)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)
390 if (irqnr < 4 && have_expmask) {
391 have_expmask |= 1 << irqnr;
392 __raw_writeb(have_expmask, EXPMASK_ENABLE);
397 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
400 if (irqnr < 4 && have_expmask) {
401 have_expmask &= ~(1 << irqnr);
402 __raw_writeb(have_expmask, EXPMASK_ENABLE);
407 static int ecard_def_irq_pending(ecard_t *ec)
409 return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;
412 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
414 panic("ecard_def_fiq_enable called - impossible");
417 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
419 panic("ecard_def_fiq_disable called - impossible");
422 static int ecard_def_fiq_pending(ecard_t *ec)
424 return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;
427 static expansioncard_ops_t ecard_default_ops = {
428 ecard_def_irq_enable,
429 ecard_def_irq_disable,
430 ecard_def_irq_pending,
431 ecard_def_fiq_enable,
432 ecard_def_fiq_disable,
433 ecard_def_fiq_pending
437 * Enable and disable interrupts from expansion cards.
438 * (interrupts are disabled for these functions).
440 * They are not meant to be called directly, but via enable/disable_irq.
442 static void ecard_irq_unmask(unsigned int irqnr)
444 ecard_t *ec = slot_to_ecard(irqnr - 32);
448 ec->ops = &ecard_default_ops;
450 if (ec->claimed && ec->ops->irqenable)
451 ec->ops->irqenable(ec, irqnr);
453 printk(KERN_ERR "ecard: rejecting request to "
454 "enable IRQs for %d\n", irqnr);
458 static void ecard_irq_mask(unsigned int irqnr)
460 ecard_t *ec = slot_to_ecard(irqnr - 32);
464 ec->ops = &ecard_default_ops;
466 if (ec->ops && ec->ops->irqdisable)
467 ec->ops->irqdisable(ec, irqnr);
471 static struct irqchip ecard_chip = {
472 .ack = ecard_irq_mask,
473 .mask = ecard_irq_mask,
474 .unmask = ecard_irq_unmask,
477 void ecard_enablefiq(unsigned int fiqnr)
479 ecard_t *ec = slot_to_ecard(fiqnr);
483 ec->ops = &ecard_default_ops;
485 if (ec->claimed && ec->ops->fiqenable)
486 ec->ops->fiqenable(ec, fiqnr);
488 printk(KERN_ERR "ecard: rejecting request to "
489 "enable FIQs for %d\n", fiqnr);
493 void ecard_disablefiq(unsigned int fiqnr)
495 ecard_t *ec = slot_to_ecard(fiqnr);
499 ec->ops = &ecard_default_ops;
501 if (ec->ops->fiqdisable)
502 ec->ops->fiqdisable(ec, fiqnr);
507 ecard_dump_irq_state(ecard_t *ec)
509 printk(" %d: %sclaimed, ",
511 ec->claimed ? "" : "not ");
513 if (ec->ops && ec->ops->irqpending &&
514 ec->ops != &ecard_default_ops)
515 printk("irq %spending\n",
516 ec->ops->irqpending(ec) ? "" : "not ");
518 printk("irqaddr %p, mask = %02X, status = %02X\n",
519 ec->irqaddr, ec->irqmask, *ec->irqaddr);
522 static void ecard_check_lockup(struct irqdesc *desc)
524 static unsigned long last;
529 * If the timer interrupt has not run since the last million
530 * unrecognised expansion card interrupts, then there is
531 * something seriously wrong. Disable the expansion card
532 * interrupts so at least we can continue.
534 * Maybe we ought to start a timer to re-enable them some time
537 if (last == jiffies) {
539 if (lockup > 1000000) {
540 printk(KERN_ERR "\nInterrupt lockup detected - "
541 "disabling all expansion card interrupts\n");
543 desc->chip->mask(IRQ_EXPANSIONCARD);
545 printk("Expansion card IRQ state:\n");
547 for (ec = cards; ec; ec = ec->next)
548 ecard_dump_irq_state(ec);
554 * If we did not recognise the source of this interrupt,
555 * warn the user, but don't flood the user with these messages.
557 if (!last || time_after(jiffies, last + 5*HZ)) {
559 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
564 ecard_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
569 desc->chip->mask(irq);
570 for (ec = cards; ec; ec = ec->next) {
573 if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)
576 if (ec->ops && ec->ops->irqpending)
577 pending = ec->ops->irqpending(ec);
579 pending = ecard_default_ops.irqpending(ec);
582 struct irqdesc *d = irq_desc + ec->irq;
583 d->handle(ec->irq, d, regs);
587 desc->chip->unmask(irq);
590 ecard_check_lockup(desc);
594 static unsigned char priority_masks[] =
596 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
599 static unsigned char first_set[] =
601 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
602 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
606 ecard_irqexp_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
608 const unsigned int statusmask = 15;
611 status = __raw_readb(EXPMASK_STATUS) & statusmask;
613 unsigned int slot = first_set[status];
614 ecard_t *ec = slot_to_ecard(slot);
617 struct irqdesc *d = irqdesc + ec->irq;
619 * this ugly code is so that we can operate a
620 * prioritorising system:
622 * Card 0 highest priority
625 * Card 3 lowest priority
627 * Serial cards should go in 0/1, ethernet/scsi in 2/3
628 * otherwise you will lose serial data at high speeds!
630 d->handle(ec->irq, d, regs);
632 printk(KERN_WARNING "card%d: interrupt from unclaimed "
634 have_expmask &= ~(1 << slot);
635 __raw_writeb(have_expmask, EXPMASK_ENABLE);
638 printk(KERN_WARNING "Wild interrupt from backplane (masks)\n");
641 static int __init ecard_probeirqhw(void)
646 __raw_writeb(0x00, EXPMASK_ENABLE);
647 __raw_writeb(0xff, EXPMASK_STATUS);
648 found = (__raw_readb(EXPMASK_STATUS) & 15) == 0;
649 __raw_writeb(0xff, EXPMASK_ENABLE);
652 printk(KERN_DEBUG "Expansion card interrupt "
653 "management hardware found\n");
655 /* for each card present, set a bit to '1' */
656 have_expmask = 0x80000000;
658 for (ec = cards; ec; ec = ec->next)
659 have_expmask |= 1 << ec->slot_no;
661 __raw_writeb(have_expmask, EXPMASK_ENABLE);
667 #define ecard_irqexp_handler NULL
668 #define ecard_probeirqhw() (0)
671 #ifndef IO_EC_MEMC8_BASE
672 #define IO_EC_MEMC8_BASE 0
675 unsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
677 unsigned long address = 0;
678 int slot = ec->slot_no;
680 if (ec->slot_no == 8)
681 return IO_EC_MEMC8_BASE;
683 ectcr &= ~(1 << slot);
688 address = IO_EC_MEMC_BASE + (slot << 12);
693 address = IO_EC_IOC_BASE + (slot << 12);
694 #ifdef IO_EC_IOC4_BASE
696 address = IO_EC_IOC4_BASE + ((slot - 4) << 12);
699 address += speed << 17;
702 #ifdef IO_EC_EASI_BASE
704 address = IO_EC_EASI_BASE + (slot << 22);
705 if (speed == ECARD_FAST)
714 iomd_writeb(ectcr, IOMD_ECTCR);
719 static int ecard_prints(char *buffer, ecard_t *ec)
721 char *start = buffer;
723 buffer += sprintf(buffer, " %d: %s ", ec->slot_no,
724 ec->type == ECARD_EASI ? "EASI" : " ");
726 if (ec->cid.id == 0) {
727 struct in_chunk_dir incd;
729 buffer += sprintf(buffer, "[%04X:%04X] ",
730 ec->cid.manufacturer, ec->cid.product);
732 if (!ec->card_desc && ec->cid.cd &&
733 ecard_readchunk(&incd, ec, 0xf5, 0)) {
734 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
737 strcpy((char *)ec->card_desc, incd.d.string);
740 buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
742 buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
744 return buffer - start;
747 static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
754 while (ec && count > cnt) {
755 len = ecard_prints(buf, ec);
759 *start = buf + (pos - (at - len));
767 return (count > cnt) ? cnt : count;
770 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
772 static void ecard_proc_init(void)
774 proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
775 create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
779 #define ec_set_resource(ec,nr,st,sz,flg) \
781 (ec)->resource[nr].name = ec->dev.bus_id; \
782 (ec)->resource[nr].start = st; \
783 (ec)->resource[nr].end = (st) + (sz) - 1; \
784 (ec)->resource[nr].flags = flg; \
787 static void __init ecard_init_resources(struct expansion_card *ec)
789 unsigned long base = PODSLOT_IOC4_BASE;
790 unsigned int slot = ec->slot_no;
794 ec_set_resource(ec, ECARD_RES_MEMC,
795 PODSLOT_MEMC_BASE + (slot << 14),
796 PODSLOT_MEMC_SIZE, IORESOURCE_MEM);
797 base = PODSLOT_IOC0_BASE;
800 #ifdef CONFIG_ARCH_RPC
802 ec_set_resource(ec, ECARD_RES_EASI,
803 PODSLOT_EASI_BASE + (slot << 24),
804 PODSLOT_EASI_SIZE, IORESOURCE_MEM);
808 ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE,
809 NETSLOT_SIZE, IORESOURCE_MEM);
813 for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++) {
814 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
815 base + (slot << 14) + (i << 19),
816 PODSLOT_IOC_SIZE, IORESOURCE_MEM);
819 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
820 if (ec->resource[i].start &&
821 request_resource(&iomem_resource, &ec->resource[i])) {
822 printk(KERN_ERR "%s: resource(s) not available\n",
824 ec->resource[i].end -= ec->resource[i].start;
825 ec->resource[i].start = 0;
830 static ssize_t ecard_show_irq(struct device *dev, char *buf)
832 struct expansion_card *ec = ECARD_DEV(dev);
833 return sprintf(buf, "%u\n", ec->irq);
836 static DEVICE_ATTR(irq, S_IRUGO, ecard_show_irq, NULL);
838 static ssize_t ecard_show_dma(struct device *dev, char *buf)
840 struct expansion_card *ec = ECARD_DEV(dev);
841 return sprintf(buf, "%u\n", ec->dma);
844 static DEVICE_ATTR(dma, S_IRUGO, ecard_show_dma, NULL);
846 static ssize_t ecard_show_resources(struct device *dev, char *buf)
848 struct expansion_card *ec = ECARD_DEV(dev);
852 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
853 str += sprintf(str, "%08lx %08lx %08lx\n",
854 ec->resource[i].start,
856 ec->resource[i].flags);
861 static DEVICE_ATTR(resource, S_IRUGO, ecard_show_resources, NULL);
863 static ssize_t ecard_show_vendor(struct device *dev, char *buf)
865 struct expansion_card *ec = ECARD_DEV(dev);
866 return sprintf(buf, "%u\n", ec->cid.manufacturer);
869 static DEVICE_ATTR(vendor, S_IRUGO, ecard_show_vendor, NULL);
871 static ssize_t ecard_show_device(struct device *dev, char *buf)
873 struct expansion_card *ec = ECARD_DEV(dev);
874 return sprintf(buf, "%u\n", ec->cid.product);
877 static DEVICE_ATTR(device, S_IRUGO, ecard_show_device, NULL);
880 int ecard_request_resources(struct expansion_card *ec)
884 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
885 if (ecard_resource_end(ec, i) &&
886 !request_mem_region(ecard_resource_start(ec, i),
887 ecard_resource_len(ec, i),
888 ec->dev.driver->name)) {
896 if (ecard_resource_end(ec, i))
897 release_mem_region(ecard_resource_start(ec, i),
898 ecard_resource_len(ec, i));
902 EXPORT_SYMBOL(ecard_request_resources);
904 void ecard_release_resources(struct expansion_card *ec)
908 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
909 if (ecard_resource_end(ec, i))
910 release_mem_region(ecard_resource_start(ec, i),
911 ecard_resource_len(ec, i));
913 EXPORT_SYMBOL(ecard_release_resources);
916 * Probe for an expansion card.
918 * If bit 1 of the first byte of the card is set, then the
919 * card does not exist.
922 ecard_probe(int slot, card_type_t type)
929 ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);
933 memset(ec, 0, sizeof(ecard_t));
940 ec->card_desc = NULL;
941 ec->ops = &ecard_default_ops;
944 if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
948 ecard_readbytes(&cid, ec, 0, 16, 0);
952 ec->cid.id = cid.r_id;
953 ec->cid.cd = cid.r_cd;
954 ec->cid.is = cid.r_is;
956 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
957 ec->cid.product = ecard_getu16(cid.r_prod);
958 ec->cid.country = cid.r_country;
959 ec->cid.irqmask = cid.r_irqmask;
960 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
961 ec->cid.fiqmask = cid.r_fiqmask;
962 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
964 ec->irqaddr = (unsigned char *)ioaddr(ec->podaddr);
967 ec->irqmask = ec->cid.irqmask;
968 ec->irqaddr += ec->cid.irqoff;
969 ec->fiqmask = ec->cid.fiqmask;
970 ec->fiqaddr += ec->cid.fiqoff;
976 for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
977 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
978 blacklist[i].product == ec->cid.product) {
979 ec->card_desc = blacklist[i].type;
983 snprintf(ec->dev.bus_id, sizeof(ec->dev.bus_id), "ecard%d", slot);
984 ec->dev.parent = NULL;
985 ec->dev.bus = &ecard_bus_type;
986 ec->dev.dma_mask = &ec->dma_mask;
987 ec->dma_mask = (u64)0xffffffff;
989 ecard_init_resources(ec);
992 * hook the interrupt handlers
996 set_irq_chip(ec->irq, &ecard_chip);
997 set_irq_handler(ec->irq, do_level_IRQ);
998 set_irq_flags(ec->irq, IRQF_VALID);
1001 #ifdef IO_EC_MEMC8_BASE
1005 #ifdef CONFIG_ARCH_RPC
1006 /* On RiscPC, only first two slots have DMA capability */
1011 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
1014 slot_to_expcard[slot] = ec;
1016 device_register(&ec->dev);
1017 device_create_file(&ec->dev, &dev_attr_dma);
1018 device_create_file(&ec->dev, &dev_attr_irq);
1019 device_create_file(&ec->dev, &dev_attr_resource);
1020 device_create_file(&ec->dev, &dev_attr_vendor);
1021 device_create_file(&ec->dev, &dev_attr_device);
1032 * Initialise the expansion card system.
1033 * Locate all hardware - interrupt management and
1036 static int __init ecard_init(void)
1038 int slot, irqhw, ret;
1040 ret = kernel_thread(ecard_task, NULL, CLONE_KERNEL);
1042 printk(KERN_ERR "Ecard: unable to create kernel thread: %d\n",
1047 printk("Probing expansion cards\n");
1049 for (slot = 0; slot < 8; slot ++) {
1050 if (ecard_probe(slot, ECARD_EASI) == -ENODEV)
1051 ecard_probe(slot, ECARD_IOC);
1054 #ifdef IO_EC_MEMC8_BASE
1055 ecard_probe(8, ECARD_IOC);
1058 irqhw = ecard_probeirqhw();
1060 set_irq_chained_handler(IRQ_EXPANSIONCARD,
1061 irqhw ? ecard_irqexp_handler : ecard_irq_handler);
1068 subsys_initcall(ecard_init);
1073 static const struct ecard_id *
1074 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
1078 for (i = 0; ids[i].manufacturer != 65535; i++)
1079 if (ec->cid.manufacturer == ids[i].manufacturer &&
1080 ec->cid.product == ids[i].product)
1086 static int ecard_drv_probe(struct device *dev)
1088 struct expansion_card *ec = ECARD_DEV(dev);
1089 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1090 const struct ecard_id *id;
1093 id = ecard_match_device(drv->id_table, ec);
1096 ret = drv->probe(ec, id);
1102 static int ecard_drv_remove(struct device *dev)
1104 struct expansion_card *ec = ECARD_DEV(dev);
1105 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1114 * Before rebooting, we must make sure that the expansion card is in a
1115 * sensible state, so it can be re-detected. This means that the first
1116 * page of the ROM must be visible. We call the expansion cards reset
1119 static void ecard_drv_shutdown(struct device *dev)
1121 struct expansion_card *ec = ECARD_DEV(dev);
1122 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1123 struct ecard_request req;
1128 req.fn = ecard_task_reset;
1133 int ecard_register_driver(struct ecard_driver *drv)
1135 drv->drv.bus = &ecard_bus_type;
1136 drv->drv.probe = ecard_drv_probe;
1137 drv->drv.remove = ecard_drv_remove;
1138 drv->drv.shutdown = ecard_drv_shutdown;
1140 return driver_register(&drv->drv);
1143 void ecard_remove_driver(struct ecard_driver *drv)
1145 driver_unregister(&drv->drv);
1148 static int ecard_match(struct device *_dev, struct device_driver *_drv)
1150 struct expansion_card *ec = ECARD_DEV(_dev);
1151 struct ecard_driver *drv = ECARD_DRV(_drv);
1154 if (drv->id_table) {
1155 ret = ecard_match_device(drv->id_table, ec) != NULL;
1157 ret = ec->cid.id == drv->id;
1163 struct bus_type ecard_bus_type = {
1165 .match = ecard_match,
1168 static int ecard_bus_init(void)
1170 return bus_register(&ecard_bus_type);
1173 postcore_initcall(ecard_bus_init);
1175 EXPORT_SYMBOL(ecard_readchunk);
1176 EXPORT_SYMBOL(ecard_address);
1177 EXPORT_SYMBOL(ecard_register_driver);
1178 EXPORT_SYMBOL(ecard_remove_driver);
1179 EXPORT_SYMBOL(ecard_bus_type);