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/reboot.h>
38 #include <linux/slab.h>
39 #include <linux/proc_fs.h>
40 #include <linux/device.h>
41 #include <linux/init.h>
44 #include <asm/ecard.h>
45 #include <asm/hardware.h>
48 #include <asm/mmu_context.h>
49 #include <asm/mach/irq.h>
50 #include <asm/tlbflush.h>
52 #ifndef CONFIG_ARCH_RPC
61 struct ecard_request {
66 unsigned int use_loader;
70 struct expcard_blacklist {
71 unsigned short manufacturer;
72 unsigned short product;
76 static ecard_t *cards;
77 static ecard_t *slot_to_expcard[MAX_ECARDS];
78 static unsigned int ectcr;
80 static unsigned int have_expmask;
83 /* List of descriptions of cards which don't have an extended
84 * identification, or chunk directories containing a description.
86 static struct expcard_blacklist __initdata blacklist[] = {
87 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
91 ecard_loader_reset(volatile unsigned char *pa, loader_t loader);
93 ecard_loader_read(int off, volatile unsigned char *pa, loader_t loader);
95 static const struct ecard_id *
96 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec);
98 static inline unsigned short
99 ecard_getu16(unsigned char *v)
101 return v[0] | v[1] << 8;
104 static inline signed long
105 ecard_gets24(unsigned char *v)
107 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
110 static inline ecard_t *
111 slot_to_ecard(unsigned int slot)
113 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
116 /* ===================== Expansion card daemon ======================== */
118 * Since the loader programs on the expansion cards need to be run
119 * in a specific environment, create a separate task with this
120 * environment up, and pass requests to this task as and when we
123 * This should allow 99% of loaders to be called from Linux.
125 * From a security standpoint, we trust the card vendors. This
126 * may be a misplaced trust.
128 #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
129 #define POD_INT_ADDR(x) ((volatile unsigned char *)\
130 ((BUS_ADDR((x)) - IO_BASE) + IO_START))
132 static inline void ecard_task_reset(struct ecard_request *req)
134 struct expansion_card *ec = req->ec;
136 ecard_loader_reset(POD_INT_ADDR(ec->podaddr), ec->loader);
140 ecard_task_readbytes(struct ecard_request *req)
142 unsigned char *buf = (unsigned char *)req->buffer;
143 volatile unsigned char *base_addr =
144 (volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);
145 unsigned int len = req->length;
146 unsigned int off = req->address;
148 if (req->ec->slot_no == 8) {
150 * The card maintains an index which increments the address
151 * into a 4096-byte page on each access. We need to keep
152 * track of the counter.
154 static unsigned int index;
157 page = (off >> 12) * 4;
164 * If we are reading offset 0, or our current index is
165 * greater than the offset, reset the hardware index counter.
167 if (off == 0 || index > off) {
173 * Increment the hardware index counter until we get to the
174 * required offset. The read bytes are discarded.
176 while (index < off) {
178 byte = base_addr[page];
183 *buf++ = base_addr[page];
188 if (!req->use_loader || !req->ec->loader) {
191 *buf++ = base_addr[off];
197 * The following is required by some
198 * expansion card loader programs.
200 *(unsigned long *)0x108 = 0;
201 *buf++ = ecard_loader_read(off++, base_addr,
209 static void ecard_do_request(struct ecard_request *req)
213 ecard_task_readbytes(req);
217 ecard_task_reset(req);
222 #include <linux/completion.h>
224 static pid_t ecard_pid;
225 static wait_queue_head_t ecard_wait;
226 static struct ecard_request *ecard_req;
228 static DECLARE_COMPLETION(ecard_completion);
231 * Set up the expansion card daemon's page tables.
233 static void ecard_init_pgtables(struct mm_struct *mm)
235 struct vm_area_struct vma;
237 /* We want to set up the page tables for the following mapping:
239 * 0x03000000 0x03000000
240 * 0x03010000 unmapped
241 * 0x03210000 0x03210000
242 * 0x03400000 unmapped
243 * 0x08000000 0x08000000
244 * 0x10000000 unmapped
246 * FIXME: we don't follow this 100% yet.
248 pgd_t *src_pgd, *dst_pgd;
250 src_pgd = pgd_offset(mm, IO_BASE);
251 dst_pgd = pgd_offset(mm, IO_START);
253 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (IO_SIZE / PGDIR_SIZE));
255 src_pgd = pgd_offset(mm, EASI_BASE);
256 dst_pgd = pgd_offset(mm, EASI_START);
258 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
262 flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
263 flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
266 static int ecard_init_mm(void)
268 struct mm_struct * mm = mm_alloc();
269 struct mm_struct *active_mm = current->active_mm;
275 current->active_mm = mm;
276 activate_mm(active_mm, mm);
278 ecard_init_pgtables(mm);
283 ecard_task(void * unused)
285 struct task_struct *tsk = current;
287 daemonize("kecardd");
290 * Allocate a mm. We're not a lazy-TLB kernel task since we need
291 * to set page table entries where the user space would be. Note
292 * that this also creates the page tables. Failure is not an
296 panic("kecardd: unable to alloc mm\n");
299 struct ecard_request *req;
302 req = xchg(&ecard_req, NULL);
305 sigemptyset(&tsk->pending.signal);
306 interruptible_sleep_on(&ecard_wait);
308 } while (req == NULL);
310 ecard_do_request(req);
311 complete(&ecard_completion);
316 * Wake the expansion card daemon to action our request.
318 * FIXME: The test here is not sufficient to detect if the
322 ecard_call(struct ecard_request *req)
325 * Make sure we have a context that is able to sleep.
327 if (current == &init_task || in_interrupt())
331 ecard_pid = kernel_thread(ecard_task, NULL, CLONE_KERNEL);
334 wake_up(&ecard_wait);
337 * Now wait for kecardd to run.
339 wait_for_completion(&ecard_completion);
342 /* ======================= Mid-level card control ===================== */
345 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
347 struct ecard_request req;
349 req.req = req_readbytes;
353 req.use_loader = useld;
359 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
361 struct ex_chunk_dir excd;
369 ecard_readbytes(&excd, ec, index, 8, useld);
371 if (c_id(&excd) == 0) {
372 if (!useld && ec->loader) {
379 if (c_id(&excd) == 0xf0) { /* link */
380 index = c_start(&excd);
383 if (c_id(&excd) == 0x80) { /* loader */
385 ec->loader = (loader_t)kmalloc(c_len(&excd),
388 ecard_readbytes(ec->loader, ec,
390 c_len(&excd), useld);
396 if (c_id(&excd) == id && num-- == 0)
400 if (c_id(&excd) & 0x80) {
401 switch (c_id(&excd) & 0x70) {
403 ecard_readbytes((unsigned char *)excd.d.string, ec,
404 (int)c_start(&excd), c_len(&excd),
411 cd->start_offset = c_start(&excd);
412 memcpy(cd->d.string, excd.d.string, 256);
416 /* ======================= Interrupt control ============================ */
418 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
421 if (irqnr < 4 && have_expmask) {
422 have_expmask |= 1 << irqnr;
423 __raw_writeb(have_expmask, EXPMASK_ENABLE);
428 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
431 if (irqnr < 4 && have_expmask) {
432 have_expmask &= ~(1 << irqnr);
433 __raw_writeb(have_expmask, EXPMASK_ENABLE);
438 static int ecard_def_irq_pending(ecard_t *ec)
440 return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;
443 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
445 panic("ecard_def_fiq_enable called - impossible");
448 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
450 panic("ecard_def_fiq_disable called - impossible");
453 static int ecard_def_fiq_pending(ecard_t *ec)
455 return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;
458 static expansioncard_ops_t ecard_default_ops = {
459 ecard_def_irq_enable,
460 ecard_def_irq_disable,
461 ecard_def_irq_pending,
462 ecard_def_fiq_enable,
463 ecard_def_fiq_disable,
464 ecard_def_fiq_pending
468 * Enable and disable interrupts from expansion cards.
469 * (interrupts are disabled for these functions).
471 * They are not meant to be called directly, but via enable/disable_irq.
473 static void ecard_irq_unmask(unsigned int irqnr)
475 ecard_t *ec = slot_to_ecard(irqnr - 32);
479 ec->ops = &ecard_default_ops;
481 if (ec->claimed && ec->ops->irqenable)
482 ec->ops->irqenable(ec, irqnr);
484 printk(KERN_ERR "ecard: rejecting request to "
485 "enable IRQs for %d\n", irqnr);
489 static void ecard_irq_mask(unsigned int irqnr)
491 ecard_t *ec = slot_to_ecard(irqnr - 32);
495 ec->ops = &ecard_default_ops;
497 if (ec->ops && ec->ops->irqdisable)
498 ec->ops->irqdisable(ec, irqnr);
502 static struct irqchip ecard_chip = {
503 .ack = ecard_irq_mask,
504 .mask = ecard_irq_mask,
505 .unmask = ecard_irq_unmask,
508 void ecard_enablefiq(unsigned int fiqnr)
510 ecard_t *ec = slot_to_ecard(fiqnr);
514 ec->ops = &ecard_default_ops;
516 if (ec->claimed && ec->ops->fiqenable)
517 ec->ops->fiqenable(ec, fiqnr);
519 printk(KERN_ERR "ecard: rejecting request to "
520 "enable FIQs for %d\n", fiqnr);
524 void ecard_disablefiq(unsigned int fiqnr)
526 ecard_t *ec = slot_to_ecard(fiqnr);
530 ec->ops = &ecard_default_ops;
532 if (ec->ops->fiqdisable)
533 ec->ops->fiqdisable(ec, fiqnr);
538 ecard_dump_irq_state(ecard_t *ec)
540 printk(" %d: %sclaimed, ",
542 ec->claimed ? "" : "not ");
544 if (ec->ops && ec->ops->irqpending &&
545 ec->ops != &ecard_default_ops)
546 printk("irq %spending\n",
547 ec->ops->irqpending(ec) ? "" : "not ");
549 printk("irqaddr %p, mask = %02X, status = %02X\n",
550 ec->irqaddr, ec->irqmask, *ec->irqaddr);
553 static void ecard_check_lockup(struct irqdesc *desc)
555 static unsigned long last;
560 * If the timer interrupt has not run since the last million
561 * unrecognised expansion card interrupts, then there is
562 * something seriously wrong. Disable the expansion card
563 * interrupts so at least we can continue.
565 * Maybe we ought to start a timer to re-enable them some time
568 if (last == jiffies) {
570 if (lockup > 1000000) {
571 printk(KERN_ERR "\nInterrupt lockup detected - "
572 "disabling all expansion card interrupts\n");
574 desc->chip->mask(IRQ_EXPANSIONCARD);
576 printk("Expansion card IRQ state:\n");
578 for (ec = cards; ec; ec = ec->next)
579 ecard_dump_irq_state(ec);
585 * If we did not recognise the source of this interrupt,
586 * warn the user, but don't flood the user with these messages.
588 if (!last || time_after(jiffies, last + 5*HZ)) {
590 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
595 ecard_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
600 desc->chip->mask(irq);
601 for (ec = cards; ec; ec = ec->next) {
604 if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)
607 if (ec->ops && ec->ops->irqpending)
608 pending = ec->ops->irqpending(ec);
610 pending = ecard_default_ops.irqpending(ec);
613 struct irqdesc *d = irq_desc + ec->irq;
614 d->handle(ec->irq, d, regs);
618 desc->chip->unmask(irq);
621 ecard_check_lockup(desc);
625 static unsigned char priority_masks[] =
627 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
630 static unsigned char first_set[] =
632 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
633 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
637 ecard_irqexp_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
639 const unsigned int statusmask = 15;
642 status = __raw_readb(EXPMASK_STATUS) & statusmask;
644 unsigned int slot = first_set[status];
645 ecard_t *ec = slot_to_ecard(slot);
648 struct irqdesc *d = irqdesc + ec->irq;
650 * this ugly code is so that we can operate a
651 * prioritorising system:
653 * Card 0 highest priority
656 * Card 3 lowest priority
658 * Serial cards should go in 0/1, ethernet/scsi in 2/3
659 * otherwise you will lose serial data at high speeds!
661 d->handle(ec->irq, d, regs);
663 printk(KERN_WARNING "card%d: interrupt from unclaimed "
665 have_expmask &= ~(1 << slot);
666 __raw_writeb(have_expmask, EXPMASK_ENABLE);
669 printk(KERN_WARNING "Wild interrupt from backplane (masks)\n");
672 static int __init ecard_probeirqhw(void)
677 __raw_writeb(0x00, EXPMASK_ENABLE);
678 __raw_writeb(0xff, EXPMASK_STATUS);
679 found = (__raw_readb(EXPMASK_STATUS) & 15) == 0;
680 __raw_writeb(0xff, EXPMASK_ENABLE);
683 printk(KERN_DEBUG "Expansion card interrupt "
684 "management hardware found\n");
686 /* for each card present, set a bit to '1' */
687 have_expmask = 0x80000000;
689 for (ec = cards; ec; ec = ec->next)
690 have_expmask |= 1 << ec->slot_no;
692 __raw_writeb(have_expmask, EXPMASK_ENABLE);
698 #define ecard_irqexp_handler NULL
699 #define ecard_probeirqhw() (0)
702 #ifndef IO_EC_MEMC8_BASE
703 #define IO_EC_MEMC8_BASE 0
706 unsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
708 unsigned long address = 0;
709 int slot = ec->slot_no;
711 if (ec->slot_no == 8)
712 return IO_EC_MEMC8_BASE;
714 ectcr &= ~(1 << slot);
719 address = IO_EC_MEMC_BASE + (slot << 12);
724 address = IO_EC_IOC_BASE + (slot << 12);
725 #ifdef IO_EC_IOC4_BASE
727 address = IO_EC_IOC4_BASE + ((slot - 4) << 12);
730 address += speed << 17;
733 #ifdef IO_EC_EASI_BASE
735 address = IO_EC_EASI_BASE + (slot << 22);
736 if (speed == ECARD_FAST)
745 iomd_writeb(ectcr, IOMD_ECTCR);
750 static int ecard_prints(char *buffer, ecard_t *ec)
752 char *start = buffer;
754 buffer += sprintf(buffer, " %d: %s ", ec->slot_no,
755 ec->type == ECARD_EASI ? "EASI" : " ");
757 if (ec->cid.id == 0) {
758 struct in_chunk_dir incd;
760 buffer += sprintf(buffer, "[%04X:%04X] ",
761 ec->cid.manufacturer, ec->cid.product);
763 if (!ec->card_desc && ec->cid.cd &&
764 ecard_readchunk(&incd, ec, 0xf5, 0)) {
765 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
768 strcpy((char *)ec->card_desc, incd.d.string);
771 buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
773 buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
775 return buffer - start;
778 static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
785 while (ec && count > cnt) {
786 len = ecard_prints(buf, ec);
790 *start = buf + (pos - (at - len));
798 return (count > cnt) ? cnt : count;
801 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
803 static void ecard_proc_init(void)
805 proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
806 create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
810 #define ec_set_resource(ec,nr,st,sz,flg) \
812 (ec)->resource[nr].name = ec->dev.bus_id; \
813 (ec)->resource[nr].start = st; \
814 (ec)->resource[nr].end = (st) + (sz) - 1; \
815 (ec)->resource[nr].flags = flg; \
818 static void __init ecard_init_resources(struct expansion_card *ec)
820 unsigned long base = PODSLOT_IOC4_BASE;
821 unsigned int slot = ec->slot_no;
825 ec_set_resource(ec, ECARD_RES_MEMC,
826 PODSLOT_MEMC_BASE + (slot << 14),
827 PODSLOT_MEMC_SIZE, IORESOURCE_MEM);
828 base = PODSLOT_IOC0_BASE;
831 #ifdef CONFIG_ARCH_RPC
833 ec_set_resource(ec, ECARD_RES_EASI,
834 PODSLOT_EASI_BASE + (slot << 24),
835 PODSLOT_EASI_SIZE, IORESOURCE_MEM);
839 ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE,
840 NETSLOT_SIZE, IORESOURCE_MEM);
844 for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++) {
845 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
846 base + (slot << 14) + (i << 19),
847 PODSLOT_IOC_SIZE, IORESOURCE_MEM);
850 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
851 if (ec->resource[i].start &&
852 request_resource(&iomem_resource, &ec->resource[i])) {
853 printk(KERN_ERR "%s: resource(s) not available\n",
855 ec->resource[i].end -= ec->resource[i].start;
856 ec->resource[i].start = 0;
861 static ssize_t ecard_show_irq(struct device *dev, char *buf)
863 struct expansion_card *ec = ECARD_DEV(dev);
864 return sprintf(buf, "%u\n", ec->irq);
867 static DEVICE_ATTR(irq, S_IRUGO, ecard_show_irq, NULL);
869 static ssize_t ecard_show_dma(struct device *dev, char *buf)
871 struct expansion_card *ec = ECARD_DEV(dev);
872 return sprintf(buf, "%u\n", ec->dma);
875 static DEVICE_ATTR(dma, S_IRUGO, ecard_show_dma, NULL);
877 static ssize_t ecard_show_resources(struct device *dev, char *buf)
879 struct expansion_card *ec = ECARD_DEV(dev);
883 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
884 str += sprintf(str, "%08lx %08lx %08lx\n",
885 ec->resource[i].start,
887 ec->resource[i].flags);
892 static DEVICE_ATTR(resource, S_IRUGO, ecard_show_resources, NULL);
894 static ssize_t ecard_show_vendor(struct device *dev, char *buf)
896 struct expansion_card *ec = ECARD_DEV(dev);
897 return sprintf(buf, "%u\n", ec->cid.manufacturer);
900 static DEVICE_ATTR(vendor, S_IRUGO, ecard_show_vendor, NULL);
902 static ssize_t ecard_show_device(struct device *dev, char *buf)
904 struct expansion_card *ec = ECARD_DEV(dev);
905 return sprintf(buf, "%u\n", ec->cid.product);
908 static DEVICE_ATTR(device, S_IRUGO, ecard_show_device, NULL);
911 int ecard_request_resources(struct expansion_card *ec)
915 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
916 if (ecard_resource_end(ec, i) &&
917 !request_mem_region(ecard_resource_start(ec, i),
918 ecard_resource_len(ec, i),
919 ec->dev.driver->name)) {
927 if (ecard_resource_end(ec, i))
928 release_mem_region(ecard_resource_start(ec, i),
929 ecard_resource_len(ec, i));
933 EXPORT_SYMBOL(ecard_request_resources);
935 void ecard_release_resources(struct expansion_card *ec)
939 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
940 if (ecard_resource_end(ec, i))
941 release_mem_region(ecard_resource_start(ec, i),
942 ecard_resource_len(ec, i));
944 EXPORT_SYMBOL(ecard_release_resources);
947 * Probe for an expansion card.
949 * If bit 1 of the first byte of the card is set, then the
950 * card does not exist.
953 ecard_probe(int slot, card_type_t type)
960 ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);
964 memset(ec, 0, sizeof(ecard_t));
971 ec->card_desc = NULL;
972 ec->ops = &ecard_default_ops;
975 if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
979 ecard_readbytes(&cid, ec, 0, 16, 0);
983 ec->cid.id = cid.r_id;
984 ec->cid.cd = cid.r_cd;
985 ec->cid.is = cid.r_is;
987 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
988 ec->cid.product = ecard_getu16(cid.r_prod);
989 ec->cid.country = cid.r_country;
990 ec->cid.irqmask = cid.r_irqmask;
991 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
992 ec->cid.fiqmask = cid.r_fiqmask;
993 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
995 ec->irqaddr = (unsigned char *)ioaddr(ec->podaddr);
998 ec->irqmask = ec->cid.irqmask;
999 ec->irqaddr += ec->cid.irqoff;
1000 ec->fiqmask = ec->cid.fiqmask;
1001 ec->fiqaddr += ec->cid.fiqoff;
1007 for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
1008 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
1009 blacklist[i].product == ec->cid.product) {
1010 ec->card_desc = blacklist[i].type;
1014 snprintf(ec->dev.bus_id, sizeof(ec->dev.bus_id), "ecard%d", slot);
1015 ec->dev.parent = NULL;
1016 ec->dev.bus = &ecard_bus_type;
1017 ec->dev.dma_mask = &ec->dma_mask;
1018 ec->dma_mask = (u64)0xffffffff;
1020 ecard_init_resources(ec);
1023 * hook the interrupt handlers
1026 ec->irq = 32 + slot;
1027 set_irq_chip(ec->irq, &ecard_chip);
1028 set_irq_handler(ec->irq, do_level_IRQ);
1029 set_irq_flags(ec->irq, IRQF_VALID);
1032 #ifdef IO_EC_MEMC8_BASE
1036 #ifdef CONFIG_ARCH_RPC
1037 /* On RiscPC, only first two slots have DMA capability */
1042 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
1045 slot_to_expcard[slot] = ec;
1047 device_register(&ec->dev);
1048 device_create_file(&ec->dev, &dev_attr_dma);
1049 device_create_file(&ec->dev, &dev_attr_irq);
1050 device_create_file(&ec->dev, &dev_attr_resource);
1051 device_create_file(&ec->dev, &dev_attr_vendor);
1052 device_create_file(&ec->dev, &dev_attr_device);
1063 * Initialise the expansion card system.
1064 * Locate all hardware - interrupt management and
1067 static int __init ecard_init(void)
1071 init_waitqueue_head(&ecard_wait);
1073 printk("Probing expansion cards\n");
1075 for (slot = 0; slot < 8; slot ++) {
1076 if (ecard_probe(slot, ECARD_EASI) == -ENODEV)
1077 ecard_probe(slot, ECARD_IOC);
1080 #ifdef IO_EC_MEMC8_BASE
1081 ecard_probe(8, ECARD_IOC);
1084 irqhw = ecard_probeirqhw();
1086 set_irq_chained_handler(IRQ_EXPANSIONCARD,
1087 irqhw ? ecard_irqexp_handler : ecard_irq_handler);
1094 subsys_initcall(ecard_init);
1099 static const struct ecard_id *
1100 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
1104 for (i = 0; ids[i].manufacturer != 65535; i++)
1105 if (ec->cid.manufacturer == ids[i].manufacturer &&
1106 ec->cid.product == ids[i].product)
1112 static int ecard_drv_probe(struct device *dev)
1114 struct expansion_card *ec = ECARD_DEV(dev);
1115 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1116 const struct ecard_id *id;
1119 id = ecard_match_device(drv->id_table, ec);
1122 ret = drv->probe(ec, id);
1128 static int ecard_drv_remove(struct device *dev)
1130 struct expansion_card *ec = ECARD_DEV(dev);
1131 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1140 * Before rebooting, we must make sure that the expansion card is in a
1141 * sensible state, so it can be re-detected. This means that the first
1142 * page of the ROM must be visible. We call the expansion cards reset
1145 static void ecard_drv_shutdown(struct device *dev)
1147 struct expansion_card *ec = ECARD_DEV(dev);
1148 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1149 struct ecard_request req;
1154 req.req = req_reset;
1159 int ecard_register_driver(struct ecard_driver *drv)
1161 drv->drv.bus = &ecard_bus_type;
1162 drv->drv.probe = ecard_drv_probe;
1163 drv->drv.remove = ecard_drv_remove;
1164 drv->drv.shutdown = ecard_drv_shutdown;
1166 return driver_register(&drv->drv);
1169 void ecard_remove_driver(struct ecard_driver *drv)
1171 driver_unregister(&drv->drv);
1174 static int ecard_match(struct device *_dev, struct device_driver *_drv)
1176 struct expansion_card *ec = ECARD_DEV(_dev);
1177 struct ecard_driver *drv = ECARD_DRV(_drv);
1180 if (drv->id_table) {
1181 ret = ecard_match_device(drv->id_table, ec) != NULL;
1183 ret = ec->cid.id == drv->id;
1189 struct bus_type ecard_bus_type = {
1191 .match = ecard_match,
1194 static int ecard_bus_init(void)
1196 return bus_register(&ecard_bus_type);
1199 postcore_initcall(ecard_bus_init);
1201 EXPORT_SYMBOL(ecard_readchunk);
1202 EXPORT_SYMBOL(ecard_address);
1203 EXPORT_SYMBOL(ecard_register_driver);
1204 EXPORT_SYMBOL(ecard_remove_driver);
1205 EXPORT_SYMBOL(ecard_bus_type);