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>
48 #include <asm/ecard.h>
49 #include <mach/hardware.h>
51 #include <asm/mmu_context.h>
52 #include <asm/mach/irq.h>
53 #include <asm/tlbflush.h>
57 #ifndef CONFIG_ARCH_RPC
61 struct ecard_request
{
62 void (*fn
)(struct ecard_request
*);
66 unsigned int use_loader
;
68 struct completion
*complete
;
71 struct expcard_blacklist
{
72 unsigned short manufacturer
;
73 unsigned short product
;
77 static ecard_t
*cards
;
78 static ecard_t
*slot_to_expcard
[MAX_ECARDS
];
79 static unsigned int ectcr
;
81 static unsigned int have_expmask
;
84 /* List of descriptions of cards which don't have an extended
85 * identification, or chunk directories containing a description.
87 static struct expcard_blacklist __initdata blacklist
[] = {
88 { MANU_ACORN
, PROD_ACORN_ETHER1
, "Acorn Ether1" }
92 ecard_loader_reset(unsigned long base
, loader_t loader
);
94 ecard_loader_read(int off
, unsigned long base
, loader_t loader
);
96 static inline unsigned short ecard_getu16(unsigned char *v
)
98 return v
[0] | v
[1] << 8;
101 static inline signed long ecard_gets24(unsigned char *v
)
103 return v
[0] | v
[1] << 8 | v
[2] << 16 | ((v
[2] & 0x80) ? 0xff000000 : 0);
106 static inline ecard_t
*slot_to_ecard(unsigned int slot
)
108 return slot
< MAX_ECARDS
? slot_to_expcard
[slot
] : NULL
;
111 /* ===================== Expansion card daemon ======================== */
113 * Since the loader programs on the expansion cards need to be run
114 * in a specific environment, create a separate task with this
115 * environment up, and pass requests to this task as and when we
118 * This should allow 99% of loaders to be called from Linux.
120 * From a security standpoint, we trust the card vendors. This
121 * may be a misplaced trust.
123 static void ecard_task_reset(struct ecard_request
*req
)
125 struct expansion_card
*ec
= req
->ec
;
126 struct resource
*res
;
128 res
= ec
->slot_no
== 8
129 ? &ec
->resource
[ECARD_RES_MEMC
]
131 ? &ec
->resource
[ECARD_RES_EASI
]
132 : &ec
->resource
[ECARD_RES_IOCSYNC
];
134 ecard_loader_reset(res
->start
, ec
->loader
);
137 static void ecard_task_readbytes(struct ecard_request
*req
)
139 struct expansion_card
*ec
= req
->ec
;
140 unsigned char *buf
= req
->buffer
;
141 unsigned int len
= req
->length
;
142 unsigned int off
= req
->address
;
144 if (ec
->slot_no
== 8) {
145 void __iomem
*base
= (void __iomem
*)
146 ec
->resource
[ECARD_RES_MEMC
].start
;
149 * The card maintains an index which increments the address
150 * into a 4096-byte page on each access. We need to keep
151 * track of the counter.
153 static unsigned int index
;
156 page
= (off
>> 12) * 4;
163 * If we are reading offset 0, or our current index is
164 * greater than the offset, reset the hardware index counter.
166 if (off
== 0 || index
> off
) {
172 * Increment the hardware index counter until we get to the
173 * required offset. The read bytes are discarded.
175 while (index
< off
) {
181 *buf
++ = readb(base
+ page
);
185 unsigned long base
= (ec
->easi
186 ? &ec
->resource
[ECARD_RES_EASI
]
187 : &ec
->resource
[ECARD_RES_IOCSYNC
])->start
;
188 void __iomem
*pbase
= (void __iomem
*)base
;
190 if (!req
->use_loader
|| !ec
->loader
) {
193 *buf
++ = readb(pbase
+ off
);
199 * The following is required by some
200 * expansion card loader programs.
202 *(unsigned long *)0x108 = 0;
203 *buf
++ = ecard_loader_read(off
++, base
,
211 static DECLARE_WAIT_QUEUE_HEAD(ecard_wait
);
212 static struct ecard_request
*ecard_req
;
213 static DEFINE_MUTEX(ecard_mutex
);
216 * Set up the expansion card daemon's page tables.
218 static void ecard_init_pgtables(struct mm_struct
*mm
)
220 struct vm_area_struct vma
;
222 /* We want to set up the page tables for the following mapping:
224 * 0x03000000 0x03000000
225 * 0x03010000 unmapped
226 * 0x03210000 0x03210000
227 * 0x03400000 unmapped
228 * 0x08000000 0x08000000
229 * 0x10000000 unmapped
231 * FIXME: we don't follow this 100% yet.
233 pgd_t
*src_pgd
, *dst_pgd
;
235 src_pgd
= pgd_offset(mm
, (unsigned long)IO_BASE
);
236 dst_pgd
= pgd_offset(mm
, IO_START
);
238 memcpy(dst_pgd
, src_pgd
, sizeof(pgd_t
) * (IO_SIZE
/ PGDIR_SIZE
));
240 src_pgd
= pgd_offset(mm
, EASI_BASE
);
241 dst_pgd
= pgd_offset(mm
, EASI_START
);
243 memcpy(dst_pgd
, src_pgd
, sizeof(pgd_t
) * (EASI_SIZE
/ PGDIR_SIZE
));
247 flush_tlb_range(&vma
, IO_START
, IO_START
+ IO_SIZE
);
248 flush_tlb_range(&vma
, EASI_START
, EASI_START
+ EASI_SIZE
);
251 static int ecard_init_mm(void)
253 struct mm_struct
* mm
= mm_alloc();
254 struct mm_struct
*active_mm
= current
->active_mm
;
260 current
->active_mm
= mm
;
261 activate_mm(active_mm
, mm
);
263 ecard_init_pgtables(mm
);
268 ecard_task(void * unused
)
271 * Allocate a mm. We're not a lazy-TLB kernel task since we need
272 * to set page table entries where the user space would be. Note
273 * that this also creates the page tables. Failure is not an
277 panic("kecardd: unable to alloc mm\n");
280 struct ecard_request
*req
;
282 wait_event_interruptible(ecard_wait
, ecard_req
!= NULL
);
284 req
= xchg(&ecard_req
, NULL
);
287 complete(req
->complete
);
293 * Wake the expansion card daemon to action our request.
295 * FIXME: The test here is not sufficient to detect if the
298 static void ecard_call(struct ecard_request
*req
)
300 DECLARE_COMPLETION_ONSTACK(completion
);
302 req
->complete
= &completion
;
304 mutex_lock(&ecard_mutex
);
306 wake_up(&ecard_wait
);
309 * Now wait for kecardd to run.
311 wait_for_completion(&completion
);
312 mutex_unlock(&ecard_mutex
);
315 /* ======================= Mid-level card control ===================== */
318 ecard_readbytes(void *addr
, ecard_t
*ec
, int off
, int len
, int useld
)
320 struct ecard_request req
;
322 req
.fn
= ecard_task_readbytes
;
326 req
.use_loader
= useld
;
332 int ecard_readchunk(struct in_chunk_dir
*cd
, ecard_t
*ec
, int id
, int num
)
334 struct ex_chunk_dir excd
;
342 ecard_readbytes(&excd
, ec
, index
, 8, useld
);
344 if (c_id(&excd
) == 0) {
345 if (!useld
&& ec
->loader
) {
352 if (c_id(&excd
) == 0xf0) { /* link */
353 index
= c_start(&excd
);
356 if (c_id(&excd
) == 0x80) { /* loader */
358 ec
->loader
= kmalloc(c_len(&excd
),
361 ecard_readbytes(ec
->loader
, ec
,
363 c_len(&excd
), useld
);
369 if (c_id(&excd
) == id
&& num
-- == 0)
373 if (c_id(&excd
) & 0x80) {
374 switch (c_id(&excd
) & 0x70) {
376 ecard_readbytes((unsigned char *)excd
.d
.string
, ec
,
377 (int)c_start(&excd
), c_len(&excd
),
384 cd
->start_offset
= c_start(&excd
);
385 memcpy(cd
->d
.string
, excd
.d
.string
, 256);
389 /* ======================= Interrupt control ============================ */
391 static void ecard_def_irq_enable(ecard_t
*ec
, int irqnr
)
394 if (irqnr
< 4 && have_expmask
) {
395 have_expmask
|= 1 << irqnr
;
396 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
401 static void ecard_def_irq_disable(ecard_t
*ec
, int irqnr
)
404 if (irqnr
< 4 && have_expmask
) {
405 have_expmask
&= ~(1 << irqnr
);
406 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
411 static int ecard_def_irq_pending(ecard_t
*ec
)
413 return !ec
->irqmask
|| readb(ec
->irqaddr
) & ec
->irqmask
;
416 static void ecard_def_fiq_enable(ecard_t
*ec
, int fiqnr
)
418 panic("ecard_def_fiq_enable called - impossible");
421 static void ecard_def_fiq_disable(ecard_t
*ec
, int fiqnr
)
423 panic("ecard_def_fiq_disable called - impossible");
426 static int ecard_def_fiq_pending(ecard_t
*ec
)
428 return !ec
->fiqmask
|| readb(ec
->fiqaddr
) & ec
->fiqmask
;
431 static expansioncard_ops_t ecard_default_ops
= {
432 ecard_def_irq_enable
,
433 ecard_def_irq_disable
,
434 ecard_def_irq_pending
,
435 ecard_def_fiq_enable
,
436 ecard_def_fiq_disable
,
437 ecard_def_fiq_pending
441 * Enable and disable interrupts from expansion cards.
442 * (interrupts are disabled for these functions).
444 * They are not meant to be called directly, but via enable/disable_irq.
446 static void ecard_irq_unmask(struct irq_data
*d
)
448 ecard_t
*ec
= slot_to_ecard(d
->irq
- 32);
452 ec
->ops
= &ecard_default_ops
;
454 if (ec
->claimed
&& ec
->ops
->irqenable
)
455 ec
->ops
->irqenable(ec
, d
->irq
);
457 printk(KERN_ERR
"ecard: rejecting request to "
458 "enable IRQs for %d\n", d
->irq
);
462 static void ecard_irq_mask(struct irq_data
*d
)
464 ecard_t
*ec
= slot_to_ecard(d
->irq
- 32);
468 ec
->ops
= &ecard_default_ops
;
470 if (ec
->ops
&& ec
->ops
->irqdisable
)
471 ec
->ops
->irqdisable(ec
, d
->irq
);
475 static struct irq_chip ecard_chip
= {
477 .irq_ack
= ecard_irq_mask
,
478 .irq_mask
= ecard_irq_mask
,
479 .irq_unmask
= ecard_irq_unmask
,
482 void ecard_enablefiq(unsigned int fiqnr
)
484 ecard_t
*ec
= slot_to_ecard(fiqnr
);
488 ec
->ops
= &ecard_default_ops
;
490 if (ec
->claimed
&& ec
->ops
->fiqenable
)
491 ec
->ops
->fiqenable(ec
, fiqnr
);
493 printk(KERN_ERR
"ecard: rejecting request to "
494 "enable FIQs for %d\n", fiqnr
);
498 void ecard_disablefiq(unsigned int fiqnr
)
500 ecard_t
*ec
= slot_to_ecard(fiqnr
);
504 ec
->ops
= &ecard_default_ops
;
506 if (ec
->ops
->fiqdisable
)
507 ec
->ops
->fiqdisable(ec
, fiqnr
);
511 static void ecard_dump_irq_state(void)
515 printk("Expansion card IRQ state:\n");
517 for (ec
= cards
; ec
; ec
= ec
->next
) {
518 if (ec
->slot_no
== 8)
521 printk(" %d: %sclaimed, ",
522 ec
->slot_no
, ec
->claimed
? "" : "not ");
524 if (ec
->ops
&& ec
->ops
->irqpending
&&
525 ec
->ops
!= &ecard_default_ops
)
526 printk("irq %spending\n",
527 ec
->ops
->irqpending(ec
) ? "" : "not ");
529 printk("irqaddr %p, mask = %02X, status = %02X\n",
530 ec
->irqaddr
, ec
->irqmask
, readb(ec
->irqaddr
));
534 static void ecard_check_lockup(struct irq_desc
*desc
)
536 static unsigned long last
;
540 * If the timer interrupt has not run since the last million
541 * unrecognised expansion card interrupts, then there is
542 * something seriously wrong. Disable the expansion card
543 * interrupts so at least we can continue.
545 * Maybe we ought to start a timer to re-enable them some time
548 if (last
== jiffies
) {
550 if (lockup
> 1000000) {
551 printk(KERN_ERR
"\nInterrupt lockup detected - "
552 "disabling all expansion card interrupts\n");
554 desc
->irq_data
.chip
->irq_mask(&desc
->irq_data
);
555 ecard_dump_irq_state();
561 * If we did not recognise the source of this interrupt,
562 * warn the user, but don't flood the user with these messages.
564 if (!last
|| time_after(jiffies
, last
+ 5*HZ
)) {
566 printk(KERN_WARNING
"Unrecognised interrupt from backplane\n");
567 ecard_dump_irq_state();
572 ecard_irq_handler(unsigned int irq
, struct irq_desc
*desc
)
577 desc
->irq_data
.chip
->irq_mask(&desc
->irq_data
);
578 for (ec
= cards
; ec
; ec
= ec
->next
) {
581 if (!ec
->claimed
|| ec
->irq
== NO_IRQ
|| ec
->slot_no
== 8)
584 if (ec
->ops
&& ec
->ops
->irqpending
)
585 pending
= ec
->ops
->irqpending(ec
);
587 pending
= ecard_default_ops
.irqpending(ec
);
590 generic_handle_irq(ec
->irq
);
594 desc
->irq_data
.chip
->irq_unmask(&desc
->irq_data
);
597 ecard_check_lockup(desc
);
601 static unsigned char priority_masks
[] =
603 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
606 static unsigned char first_set
[] =
608 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
609 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
613 ecard_irqexp_handler(unsigned int irq
, struct irq_desc
*desc
)
615 const unsigned int statusmask
= 15;
618 status
= __raw_readb(EXPMASK_STATUS
) & statusmask
;
620 unsigned int slot
= first_set
[status
];
621 ecard_t
*ec
= slot_to_ecard(slot
);
625 * this ugly code is so that we can operate a
626 * prioritorising system:
628 * Card 0 highest priority
631 * Card 3 lowest priority
633 * Serial cards should go in 0/1, ethernet/scsi in 2/3
634 * otherwise you will lose serial data at high speeds!
636 generic_handle_irq(ec
->irq
);
638 printk(KERN_WARNING
"card%d: interrupt from unclaimed "
640 have_expmask
&= ~(1 << slot
);
641 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
644 printk(KERN_WARNING
"Wild interrupt from backplane (masks)\n");
647 static int __init
ecard_probeirqhw(void)
652 __raw_writeb(0x00, EXPMASK_ENABLE
);
653 __raw_writeb(0xff, EXPMASK_STATUS
);
654 found
= (__raw_readb(EXPMASK_STATUS
) & 15) == 0;
655 __raw_writeb(0xff, EXPMASK_ENABLE
);
658 printk(KERN_DEBUG
"Expansion card interrupt "
659 "management hardware found\n");
661 /* for each card present, set a bit to '1' */
662 have_expmask
= 0x80000000;
664 for (ec
= cards
; ec
; ec
= ec
->next
)
665 have_expmask
|= 1 << ec
->slot_no
;
667 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
673 #define ecard_irqexp_handler NULL
674 #define ecard_probeirqhw() (0)
677 #ifndef IO_EC_MEMC8_BASE
678 #define IO_EC_MEMC8_BASE 0
681 static unsigned int __ecard_address(ecard_t
*ec
, card_type_t type
, card_speed_t speed
)
683 unsigned long address
= 0;
684 int slot
= ec
->slot_no
;
686 if (ec
->slot_no
== 8)
687 return IO_EC_MEMC8_BASE
;
689 ectcr
&= ~(1 << slot
);
694 address
= IO_EC_MEMC_BASE
+ (slot
<< 12);
699 address
= IO_EC_IOC_BASE
+ (slot
<< 12);
700 #ifdef IO_EC_IOC4_BASE
702 address
= IO_EC_IOC4_BASE
+ ((slot
- 4) << 12);
705 address
+= speed
<< 17;
708 #ifdef IO_EC_EASI_BASE
710 address
= IO_EC_EASI_BASE
+ (slot
<< 22);
711 if (speed
== ECARD_FAST
)
720 iomd_writeb(ectcr
, IOMD_ECTCR
);
725 static int ecard_prints(struct seq_file
*m
, ecard_t
*ec
)
727 seq_printf(m
, " %d: %s ", ec
->slot_no
, ec
->easi
? "EASI" : " ");
729 if (ec
->cid
.id
== 0) {
730 struct in_chunk_dir incd
;
732 seq_printf(m
, "[%04X:%04X] ",
733 ec
->cid
.manufacturer
, ec
->cid
.product
);
735 if (!ec
->card_desc
&& ec
->cid
.cd
&&
736 ecard_readchunk(&incd
, ec
, 0xf5, 0)) {
737 ec
->card_desc
= kmalloc(strlen(incd
.d
.string
)+1, GFP_KERNEL
);
740 strcpy((char *)ec
->card_desc
, incd
.d
.string
);
743 seq_printf(m
, "%s\n", ec
->card_desc
? ec
->card_desc
: "*unknown*");
745 seq_printf(m
, "Simple card %d\n", ec
->cid
.id
);
750 static int ecard_devices_proc_show(struct seq_file
*m
, void *v
)
761 static int ecard_devices_proc_open(struct inode
*inode
, struct file
*file
)
763 return single_open(file
, ecard_devices_proc_show
, NULL
);
766 static const struct file_operations bus_ecard_proc_fops
= {
767 .owner
= THIS_MODULE
,
768 .open
= ecard_devices_proc_open
,
771 .release
= single_release
,
774 static struct proc_dir_entry
*proc_bus_ecard_dir
= NULL
;
776 static void ecard_proc_init(void)
778 proc_bus_ecard_dir
= proc_mkdir("bus/ecard", NULL
);
779 proc_create("devices", 0, proc_bus_ecard_dir
, &bus_ecard_proc_fops
);
782 #define ec_set_resource(ec,nr,st,sz) \
784 (ec)->resource[nr].name = dev_name(&ec->dev); \
785 (ec)->resource[nr].start = st; \
786 (ec)->resource[nr].end = (st) + (sz) - 1; \
787 (ec)->resource[nr].flags = IORESOURCE_MEM; \
790 static void __init
ecard_free_card(struct expansion_card
*ec
)
794 for (i
= 0; i
< ECARD_NUM_RESOURCES
; i
++)
795 if (ec
->resource
[i
].flags
)
796 release_resource(&ec
->resource
[i
]);
801 static struct expansion_card
*__init
ecard_alloc_card(int type
, int slot
)
803 struct expansion_card
*ec
;
807 ec
= kzalloc(sizeof(ecard_t
), GFP_KERNEL
);
809 ec
= ERR_PTR(-ENOMEM
);
814 ec
->easi
= type
== ECARD_EASI
;
818 ec
->ops
= &ecard_default_ops
;
820 dev_set_name(&ec
->dev
, "ecard%d", slot
);
821 ec
->dev
.parent
= NULL
;
822 ec
->dev
.bus
= &ecard_bus_type
;
823 ec
->dev
.dma_mask
= &ec
->dma_mask
;
824 ec
->dma_mask
= (u64
)0xffffffff;
825 ec
->dev
.coherent_dma_mask
= ec
->dma_mask
;
828 ec_set_resource(ec
, ECARD_RES_MEMC
,
829 PODSLOT_MEMC_BASE
+ (slot
<< 14),
831 base
= PODSLOT_IOC0_BASE
+ (slot
<< 14);
833 base
= PODSLOT_IOC4_BASE
+ ((slot
- 4) << 14);
835 #ifdef CONFIG_ARCH_RPC
837 ec_set_resource(ec
, ECARD_RES_EASI
,
838 PODSLOT_EASI_BASE
+ (slot
<< 24),
843 ec_set_resource(ec
, ECARD_RES_MEMC
, NETSLOT_BASE
, NETSLOT_SIZE
);
847 for (i
= 0; i
<= ECARD_RES_IOCSYNC
- ECARD_RES_IOCSLOW
; i
++)
848 ec_set_resource(ec
, i
+ ECARD_RES_IOCSLOW
,
849 base
+ (i
<< 19), PODSLOT_IOC_SIZE
);
851 for (i
= 0; i
< ECARD_NUM_RESOURCES
; i
++) {
852 if (ec
->resource
[i
].flags
&&
853 request_resource(&iomem_resource
, &ec
->resource
[i
])) {
854 dev_err(&ec
->dev
, "resource(s) not available\n");
855 ec
->resource
[i
].end
-= ec
->resource
[i
].start
;
856 ec
->resource
[i
].start
= 0;
857 ec
->resource
[i
].flags
= 0;
865 static ssize_t
ecard_show_irq(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
867 struct expansion_card
*ec
= ECARD_DEV(dev
);
868 return sprintf(buf
, "%u\n", ec
->irq
);
871 static ssize_t
ecard_show_dma(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
873 struct expansion_card
*ec
= ECARD_DEV(dev
);
874 return sprintf(buf
, "%u\n", ec
->dma
);
877 static ssize_t
ecard_show_resources(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
879 struct expansion_card
*ec
= ECARD_DEV(dev
);
883 for (i
= 0; i
< ECARD_NUM_RESOURCES
; i
++)
884 str
+= sprintf(str
, "%08x %08x %08lx\n",
885 ec
->resource
[i
].start
,
887 ec
->resource
[i
].flags
);
892 static ssize_t
ecard_show_vendor(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
894 struct expansion_card
*ec
= ECARD_DEV(dev
);
895 return sprintf(buf
, "%u\n", ec
->cid
.manufacturer
);
898 static ssize_t
ecard_show_device(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
900 struct expansion_card
*ec
= ECARD_DEV(dev
);
901 return sprintf(buf
, "%u\n", ec
->cid
.product
);
904 static ssize_t
ecard_show_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
906 struct expansion_card
*ec
= ECARD_DEV(dev
);
907 return sprintf(buf
, "%s\n", ec
->easi
? "EASI" : "IOC");
910 static struct device_attribute ecard_dev_attrs
[] = {
911 __ATTR(device
, S_IRUGO
, ecard_show_device
, NULL
),
912 __ATTR(dma
, S_IRUGO
, ecard_show_dma
, NULL
),
913 __ATTR(irq
, S_IRUGO
, ecard_show_irq
, NULL
),
914 __ATTR(resource
, S_IRUGO
, ecard_show_resources
, NULL
),
915 __ATTR(type
, S_IRUGO
, ecard_show_type
, NULL
),
916 __ATTR(vendor
, S_IRUGO
, ecard_show_vendor
, NULL
),
921 int ecard_request_resources(struct expansion_card
*ec
)
925 for (i
= 0; i
< ECARD_NUM_RESOURCES
; i
++) {
926 if (ecard_resource_end(ec
, i
) &&
927 !request_mem_region(ecard_resource_start(ec
, i
),
928 ecard_resource_len(ec
, i
),
929 ec
->dev
.driver
->name
)) {
937 if (ecard_resource_end(ec
, i
))
938 release_mem_region(ecard_resource_start(ec
, i
),
939 ecard_resource_len(ec
, i
));
943 EXPORT_SYMBOL(ecard_request_resources
);
945 void ecard_release_resources(struct expansion_card
*ec
)
949 for (i
= 0; i
< ECARD_NUM_RESOURCES
; i
++)
950 if (ecard_resource_end(ec
, i
))
951 release_mem_region(ecard_resource_start(ec
, i
),
952 ecard_resource_len(ec
, i
));
954 EXPORT_SYMBOL(ecard_release_resources
);
956 void ecard_setirq(struct expansion_card
*ec
, const struct expansion_card_ops
*ops
, void *irq_data
)
958 ec
->irq_data
= irq_data
;
962 EXPORT_SYMBOL(ecard_setirq
);
964 void __iomem
*ecardm_iomap(struct expansion_card
*ec
, unsigned int res
,
965 unsigned long offset
, unsigned long maxsize
)
967 unsigned long start
= ecard_resource_start(ec
, res
);
968 unsigned long end
= ecard_resource_end(ec
, res
);
970 if (offset
> (end
- start
))
974 if (maxsize
&& end
- start
> maxsize
)
975 end
= start
+ maxsize
;
977 return devm_ioremap(&ec
->dev
, start
, end
- start
);
979 EXPORT_SYMBOL(ecardm_iomap
);
982 * Probe for an expansion card.
984 * If bit 1 of the first byte of the card is set, then the
985 * card does not exist.
988 ecard_probe(int slot
, card_type_t type
)
995 ec
= ecard_alloc_card(type
, slot
);
1002 if ((ec
->podaddr
= __ecard_address(ec
, type
, ECARD_SYNC
)) == 0)
1006 ecard_readbytes(&cid
, ec
, 0, 16, 0);
1010 ec
->cid
.id
= cid
.r_id
;
1011 ec
->cid
.cd
= cid
.r_cd
;
1012 ec
->cid
.is
= cid
.r_is
;
1013 ec
->cid
.w
= cid
.r_w
;
1014 ec
->cid
.manufacturer
= ecard_getu16(cid
.r_manu
);
1015 ec
->cid
.product
= ecard_getu16(cid
.r_prod
);
1016 ec
->cid
.country
= cid
.r_country
;
1017 ec
->cid
.irqmask
= cid
.r_irqmask
;
1018 ec
->cid
.irqoff
= ecard_gets24(cid
.r_irqoff
);
1019 ec
->cid
.fiqmask
= cid
.r_fiqmask
;
1020 ec
->cid
.fiqoff
= ecard_gets24(cid
.r_fiqoff
);
1022 ec
->irqaddr
= (void __iomem
*)ioaddr(ec
->podaddr
);
1025 ec
->irqmask
= ec
->cid
.irqmask
;
1026 ec
->irqaddr
+= ec
->cid
.irqoff
;
1027 ec
->fiqmask
= ec
->cid
.fiqmask
;
1028 ec
->fiqaddr
+= ec
->cid
.fiqoff
;
1034 for (i
= 0; i
< ARRAY_SIZE(blacklist
); i
++)
1035 if (blacklist
[i
].manufacturer
== ec
->cid
.manufacturer
&&
1036 blacklist
[i
].product
== ec
->cid
.product
) {
1037 ec
->card_desc
= blacklist
[i
].type
;
1042 * hook the interrupt handlers
1045 ec
->irq
= 32 + slot
;
1046 irq_set_chip_and_handler(ec
->irq
, &ecard_chip
,
1048 set_irq_flags(ec
->irq
, IRQF_VALID
);
1051 #ifdef IO_EC_MEMC8_BASE
1055 #ifdef CONFIG_ARCH_RPC
1056 /* On RiscPC, only first two slots have DMA capability */
1061 for (ecp
= &cards
; *ecp
; ecp
= &(*ecp
)->next
);
1064 slot_to_expcard
[slot
] = ec
;
1066 device_register(&ec
->dev
);
1071 ecard_free_card(ec
);
1077 * Initialise the expansion card system.
1078 * Locate all hardware - interrupt management and
1081 static int __init
ecard_init(void)
1083 struct task_struct
*task
;
1086 task
= kthread_run(ecard_task
, NULL
, "kecardd");
1088 printk(KERN_ERR
"Ecard: unable to create kernel thread: %ld\n",
1090 return PTR_ERR(task
);
1093 printk("Probing expansion cards\n");
1095 for (slot
= 0; slot
< 8; slot
++) {
1096 if (ecard_probe(slot
, ECARD_EASI
) == -ENODEV
)
1097 ecard_probe(slot
, ECARD_IOC
);
1100 #ifdef IO_EC_MEMC8_BASE
1101 ecard_probe(8, ECARD_IOC
);
1104 irqhw
= ecard_probeirqhw();
1106 irq_set_chained_handler(IRQ_EXPANSIONCARD
,
1107 irqhw
? ecard_irqexp_handler
: ecard_irq_handler
);
1114 subsys_initcall(ecard_init
);
1119 static const struct ecard_id
*
1120 ecard_match_device(const struct ecard_id
*ids
, struct expansion_card
*ec
)
1124 for (i
= 0; ids
[i
].manufacturer
!= 65535; i
++)
1125 if (ec
->cid
.manufacturer
== ids
[i
].manufacturer
&&
1126 ec
->cid
.product
== ids
[i
].product
)
1132 static int ecard_drv_probe(struct device
*dev
)
1134 struct expansion_card
*ec
= ECARD_DEV(dev
);
1135 struct ecard_driver
*drv
= ECARD_DRV(dev
->driver
);
1136 const struct ecard_id
*id
;
1139 id
= ecard_match_device(drv
->id_table
, ec
);
1142 ret
= drv
->probe(ec
, id
);
1148 static int ecard_drv_remove(struct device
*dev
)
1150 struct expansion_card
*ec
= ECARD_DEV(dev
);
1151 struct ecard_driver
*drv
= ECARD_DRV(dev
->driver
);
1157 * Restore the default operations. We ensure that the
1158 * ops are set before we change the data.
1160 ec
->ops
= &ecard_default_ops
;
1162 ec
->irq_data
= NULL
;
1168 * Before rebooting, we must make sure that the expansion card is in a
1169 * sensible state, so it can be re-detected. This means that the first
1170 * page of the ROM must be visible. We call the expansion cards reset
1173 static void ecard_drv_shutdown(struct device
*dev
)
1175 struct expansion_card
*ec
= ECARD_DEV(dev
);
1176 struct ecard_driver
*drv
= ECARD_DRV(dev
->driver
);
1177 struct ecard_request req
;
1186 * If this card has a loader, call the reset handler.
1189 req
.fn
= ecard_task_reset
;
1195 int ecard_register_driver(struct ecard_driver
*drv
)
1197 drv
->drv
.bus
= &ecard_bus_type
;
1199 return driver_register(&drv
->drv
);
1202 void ecard_remove_driver(struct ecard_driver
*drv
)
1204 driver_unregister(&drv
->drv
);
1207 static int ecard_match(struct device
*_dev
, struct device_driver
*_drv
)
1209 struct expansion_card
*ec
= ECARD_DEV(_dev
);
1210 struct ecard_driver
*drv
= ECARD_DRV(_drv
);
1213 if (drv
->id_table
) {
1214 ret
= ecard_match_device(drv
->id_table
, ec
) != NULL
;
1216 ret
= ec
->cid
.id
== drv
->id
;
1222 struct bus_type ecard_bus_type
= {
1224 .dev_attrs
= ecard_dev_attrs
,
1225 .match
= ecard_match
,
1226 .probe
= ecard_drv_probe
,
1227 .remove
= ecard_drv_remove
,
1228 .shutdown
= ecard_drv_shutdown
,
1231 static int ecard_bus_init(void)
1233 return bus_register(&ecard_bus_type
);
1236 postcore_initcall(ecard_bus_init
);
1238 EXPORT_SYMBOL(ecard_readchunk
);
1239 EXPORT_SYMBOL(ecard_register_driver
);
1240 EXPORT_SYMBOL(ecard_remove_driver
);
1241 EXPORT_SYMBOL(ecard_bus_type
);