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/notifier.h>
41 #include <linux/device.h>
42 #include <linux/init.h>
45 #include <asm/ecard.h>
46 #include <asm/hardware.h>
49 #include <asm/pgalloc.h>
50 #include <asm/mmu_context.h>
51 #include <asm/mach/irq.h>
52 #include <asm/tlbflush.h>
54 #ifndef CONFIG_ARCH_RPC
63 struct ecard_request
{
68 unsigned int use_loader
;
72 struct expcard_blacklist
{
73 unsigned short manufacturer
;
74 unsigned short product
;
78 static ecard_t
*cards
;
79 static ecard_t
*slot_to_expcard
[MAX_ECARDS
];
80 static unsigned int ectcr
;
82 static unsigned int have_expmask
;
85 /* List of descriptions of cards which don't have an extended
86 * identification, or chunk directories containing a description.
88 static struct expcard_blacklist __initdata blacklist
[] = {
89 { MANU_ACORN
, PROD_ACORN_ETHER1
, "Acorn Ether1" }
93 ecard_loader_reset(volatile unsigned char *pa
, loader_t loader
);
95 ecard_loader_read(int off
, volatile unsigned char *pa
, loader_t loader
);
97 static const struct ecard_id
*
98 ecard_match_device(const struct ecard_id
*ids
, struct expansion_card
*ec
);
100 static inline unsigned short
101 ecard_getu16(unsigned char *v
)
103 return v
[0] | v
[1] << 8;
106 static inline signed long
107 ecard_gets24(unsigned char *v
)
109 return v
[0] | v
[1] << 8 | v
[2] << 16 | ((v
[2] & 0x80) ? 0xff000000 : 0);
112 static inline ecard_t
*
113 slot_to_ecard(unsigned int slot
)
115 return slot
< MAX_ECARDS
? slot_to_expcard
[slot
] : NULL
;
118 /* ===================== Expansion card daemon ======================== */
120 * Since the loader programs on the expansion cards need to be run
121 * in a specific environment, create a separate task with this
122 * environment up, and pass requests to this task as and when we
125 * This should allow 99% of loaders to be called from Linux.
127 * From a security standpoint, we trust the card vendors. This
128 * may be a misplaced trust.
130 #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
131 #define POD_INT_ADDR(x) ((volatile unsigned char *)\
132 ((BUS_ADDR((x)) - IO_BASE) + IO_START))
134 static inline void ecard_task_reset(void)
138 for (ec
= cards
; ec
; ec
= ec
->next
)
140 ecard_loader_reset(POD_INT_ADDR(ec
->podaddr
),
145 ecard_task_readbytes(struct ecard_request
*req
)
147 unsigned char *buf
= (unsigned char *)req
->buffer
;
148 volatile unsigned char *base_addr
=
149 (volatile unsigned char *)POD_INT_ADDR(req
->ec
->podaddr
);
150 unsigned int len
= req
->length
;
151 unsigned int off
= req
->address
;
153 if (req
->ec
->slot_no
== 8) {
155 * The card maintains an index which increments the address
156 * into a 4096-byte page on each access. We need to keep
157 * track of the counter.
159 static unsigned int index
;
162 page
= (off
>> 12) * 4;
169 * If we are reading offset 0, or our current index is
170 * greater than the offset, reset the hardware index counter.
172 if (off
== 0 || index
> off
) {
178 * Increment the hardware index counter until we get to the
179 * required offset. The read bytes are discarded.
181 while (index
< off
) {
183 byte
= base_addr
[page
];
188 *buf
++ = base_addr
[page
];
193 if (!req
->use_loader
|| !req
->ec
->loader
) {
196 *buf
++ = base_addr
[off
];
202 * The following is required by some
203 * expansion card loader programs.
205 *(unsigned long *)0x108 = 0;
206 *buf
++ = ecard_loader_read(off
++, base_addr
,
214 static void ecard_do_request(struct ecard_request
*req
)
218 ecard_task_readbytes(req
);
228 #include <linux/completion.h>
230 static pid_t ecard_pid
;
231 static wait_queue_head_t ecard_wait
;
232 static struct ecard_request
*ecard_req
;
234 static DECLARE_COMPLETION(ecard_completion
);
237 * Set up the expansion card daemon's page tables.
239 static void ecard_init_pgtables(struct mm_struct
*mm
)
241 struct vm_area_struct vma
;
243 /* We want to set up the page tables for the following mapping:
245 * 0x03000000 0x03000000
246 * 0x03010000 unmapped
247 * 0x03210000 0x03210000
248 * 0x03400000 unmapped
249 * 0x08000000 0x08000000
250 * 0x10000000 unmapped
252 * FIXME: we don't follow this 100% yet.
254 pgd_t
*src_pgd
, *dst_pgd
;
256 src_pgd
= pgd_offset(mm
, IO_BASE
);
257 dst_pgd
= pgd_offset(mm
, IO_START
);
259 memcpy(dst_pgd
, src_pgd
, sizeof(pgd_t
) * (IO_SIZE
/ PGDIR_SIZE
));
261 src_pgd
= pgd_offset(mm
, EASI_BASE
);
262 dst_pgd
= pgd_offset(mm
, EASI_START
);
264 memcpy(dst_pgd
, src_pgd
, sizeof(pgd_t
) * (EASI_SIZE
/ PGDIR_SIZE
));
268 flush_tlb_range(&vma
, IO_START
, IO_START
+ IO_SIZE
);
269 flush_tlb_range(&vma
, EASI_START
, EASI_START
+ EASI_SIZE
);
272 static int ecard_init_mm(void)
274 struct mm_struct
* mm
= mm_alloc();
275 struct mm_struct
*active_mm
= current
->active_mm
;
281 current
->active_mm
= mm
;
282 activate_mm(active_mm
, mm
);
284 ecard_init_pgtables(mm
);
289 ecard_task(void * unused
)
291 struct task_struct
*tsk
= current
;
294 * We don't want /any/ signals, not even SIGKILL
296 sigfillset(&tsk
->blocked
);
297 sigemptyset(&tsk
->pending
.signal
);
299 strcpy(tsk
->comm
, "kecardd");
303 * Allocate a mm. We're not a lazy-TLB kernel task since we need
304 * to set page table entries where the user space would be. Note
305 * that this also creates the page tables. Failure is not an
309 panic("kecardd: unable to alloc mm\n");
312 struct ecard_request
*req
;
315 req
= xchg(&ecard_req
, NULL
);
318 sigemptyset(&tsk
->pending
.signal
);
319 interruptible_sleep_on(&ecard_wait
);
321 } while (req
== NULL
);
323 ecard_do_request(req
);
324 complete(&ecard_completion
);
329 * Wake the expansion card daemon to action our request.
331 * FIXME: The test here is not sufficient to detect if the
335 ecard_call(struct ecard_request
*req
)
338 * Make sure we have a context that is able to sleep.
340 if (current
== &init_task
|| in_interrupt())
344 ecard_pid
= kernel_thread(ecard_task
, NULL
,
345 CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
348 wake_up(&ecard_wait
);
351 * Now wait for kecardd to run.
353 wait_for_completion(&ecard_completion
);
357 * On 26-bit processors, we don't need the kcardd thread to access the
358 * expansion card loaders. We do it directly.
360 #define ecard_call(req) ecard_do_request(req)
363 /* ======================= Mid-level card control ===================== */
366 * This function is responsible for resetting the expansion cards to a
367 * sensible state immediately prior to rebooting the system. This function
368 * has process state (keventd), so we can sleep.
370 * Possible "val" values here:
371 * SYS_RESTART - restarting system
372 * SYS_HALT - halting system
373 * SYS_POWER_OFF - powering down system
375 * We ignore all calls, unless it is a SYS_RESTART call - power down/halts
376 * will be followed by a SYS_RESTART if ctrl-alt-del is pressed again.
378 static int ecard_reboot(struct notifier_block
*me
, unsigned long val
, void *v
)
380 struct ecard_request req
;
382 if (val
!= SYS_RESTART
)
386 * Disable the expansion card interrupt
388 disable_irq(IRQ_EXPANSIONCARD
);
391 * If we have any expansion card loader code which will handle
392 * the reset for us, call it now.
394 req
.req
= req_reset_all
;
398 * Disable the expansion card interrupt again, just to be sure.
400 disable_irq(IRQ_EXPANSIONCARD
);
403 * Finally, reset the expansion card interrupt mask to
404 * all enable (RISC OS doesn't set this)
408 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
413 static struct notifier_block ecard_reboot_notifier
= {
414 .notifier_call
= ecard_reboot
,
420 ecard_readbytes(void *addr
, ecard_t
*ec
, int off
, int len
, int useld
)
422 struct ecard_request req
;
424 req
.req
= req_readbytes
;
428 req
.use_loader
= useld
;
434 int ecard_readchunk(struct in_chunk_dir
*cd
, ecard_t
*ec
, int id
, int num
)
436 struct ex_chunk_dir excd
;
444 ecard_readbytes(&excd
, ec
, index
, 8, useld
);
446 if (c_id(&excd
) == 0) {
447 if (!useld
&& ec
->loader
) {
454 if (c_id(&excd
) == 0xf0) { /* link */
455 index
= c_start(&excd
);
458 if (c_id(&excd
) == 0x80) { /* loader */
460 ec
->loader
= (loader_t
)kmalloc(c_len(&excd
),
463 ecard_readbytes(ec
->loader
, ec
,
465 c_len(&excd
), useld
);
471 if (c_id(&excd
) == id
&& num
-- == 0)
475 if (c_id(&excd
) & 0x80) {
476 switch (c_id(&excd
) & 0x70) {
478 ecard_readbytes((unsigned char *)excd
.d
.string
, ec
,
479 (int)c_start(&excd
), c_len(&excd
),
486 cd
->start_offset
= c_start(&excd
);
487 memcpy(cd
->d
.string
, excd
.d
.string
, 256);
491 /* ======================= Interrupt control ============================ */
493 static void ecard_def_irq_enable(ecard_t
*ec
, int irqnr
)
496 if (irqnr
< 4 && have_expmask
) {
497 have_expmask
|= 1 << irqnr
;
498 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
503 static void ecard_def_irq_disable(ecard_t
*ec
, int irqnr
)
506 if (irqnr
< 4 && have_expmask
) {
507 have_expmask
&= ~(1 << irqnr
);
508 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
513 static int ecard_def_irq_pending(ecard_t
*ec
)
515 return !ec
->irqmask
|| ec
->irqaddr
[0] & ec
->irqmask
;
518 static void ecard_def_fiq_enable(ecard_t
*ec
, int fiqnr
)
520 panic("ecard_def_fiq_enable called - impossible");
523 static void ecard_def_fiq_disable(ecard_t
*ec
, int fiqnr
)
525 panic("ecard_def_fiq_disable called - impossible");
528 static int ecard_def_fiq_pending(ecard_t
*ec
)
530 return !ec
->fiqmask
|| ec
->fiqaddr
[0] & ec
->fiqmask
;
533 static expansioncard_ops_t ecard_default_ops
= {
534 ecard_def_irq_enable
,
535 ecard_def_irq_disable
,
536 ecard_def_irq_pending
,
537 ecard_def_fiq_enable
,
538 ecard_def_fiq_disable
,
539 ecard_def_fiq_pending
543 * Enable and disable interrupts from expansion cards.
544 * (interrupts are disabled for these functions).
546 * They are not meant to be called directly, but via enable/disable_irq.
548 static void ecard_irq_unmask(unsigned int irqnr
)
550 ecard_t
*ec
= slot_to_ecard(irqnr
- 32);
554 ec
->ops
= &ecard_default_ops
;
556 if (ec
->claimed
&& ec
->ops
->irqenable
)
557 ec
->ops
->irqenable(ec
, irqnr
);
559 printk(KERN_ERR
"ecard: rejecting request to "
560 "enable IRQs for %d\n", irqnr
);
564 static void ecard_irq_mask(unsigned int irqnr
)
566 ecard_t
*ec
= slot_to_ecard(irqnr
- 32);
570 ec
->ops
= &ecard_default_ops
;
572 if (ec
->ops
&& ec
->ops
->irqdisable
)
573 ec
->ops
->irqdisable(ec
, irqnr
);
577 static struct irqchip ecard_chip
= {
578 .ack
= ecard_irq_mask
,
579 .mask
= ecard_irq_mask
,
580 .unmask
= ecard_irq_unmask
,
583 void ecard_enablefiq(unsigned int fiqnr
)
585 ecard_t
*ec
= slot_to_ecard(fiqnr
);
589 ec
->ops
= &ecard_default_ops
;
591 if (ec
->claimed
&& ec
->ops
->fiqenable
)
592 ec
->ops
->fiqenable(ec
, fiqnr
);
594 printk(KERN_ERR
"ecard: rejecting request to "
595 "enable FIQs for %d\n", fiqnr
);
599 void ecard_disablefiq(unsigned int fiqnr
)
601 ecard_t
*ec
= slot_to_ecard(fiqnr
);
605 ec
->ops
= &ecard_default_ops
;
607 if (ec
->ops
->fiqdisable
)
608 ec
->ops
->fiqdisable(ec
, fiqnr
);
613 ecard_dump_irq_state(ecard_t
*ec
)
615 printk(" %d: %sclaimed, ",
617 ec
->claimed
? "" : "not ");
619 if (ec
->ops
&& ec
->ops
->irqpending
&&
620 ec
->ops
!= &ecard_default_ops
)
621 printk("irq %spending\n",
622 ec
->ops
->irqpending(ec
) ? "" : "not ");
624 printk("irqaddr %p, mask = %02X, status = %02X\n",
625 ec
->irqaddr
, ec
->irqmask
, *ec
->irqaddr
);
628 static void ecard_check_lockup(struct irqdesc
*desc
)
630 static int last
, lockup
;
634 * If the timer interrupt has not run since the last million
635 * unrecognised expansion card interrupts, then there is
636 * something seriously wrong. Disable the expansion card
637 * interrupts so at least we can continue.
639 * Maybe we ought to start a timer to re-enable them some time
642 if (last
== jiffies
) {
644 if (lockup
> 1000000) {
645 printk(KERN_ERR
"\nInterrupt lockup detected - "
646 "disabling all expansion card interrupts\n");
648 desc
->chip
->mask(IRQ_EXPANSIONCARD
);
650 printk("Expansion card IRQ state:\n");
652 for (ec
= cards
; ec
; ec
= ec
->next
)
653 ecard_dump_irq_state(ec
);
659 * If we did not recognise the source of this interrupt,
660 * warn the user, but don't flood the user with these messages.
662 if (!last
|| time_after(jiffies
, last
+ 5*HZ
)) {
664 printk(KERN_WARNING
"Unrecognised interrupt from backplane\n");
669 ecard_irq_handler(unsigned int irq
, struct irqdesc
*desc
, struct pt_regs
*regs
)
674 desc
->chip
->mask(irq
);
675 for (ec
= cards
; ec
; ec
= ec
->next
) {
678 if (!ec
->claimed
|| ec
->irq
== NO_IRQ
|| ec
->slot_no
== 8)
681 if (ec
->ops
&& ec
->ops
->irqpending
)
682 pending
= ec
->ops
->irqpending(ec
);
684 pending
= ecard_default_ops
.irqpending(ec
);
687 struct irqdesc
*d
= irq_desc
+ ec
->irq
;
688 d
->handle(ec
->irq
, d
, regs
);
692 desc
->chip
->unmask(irq
);
695 ecard_check_lockup(desc
);
699 static unsigned char priority_masks
[] =
701 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
704 static unsigned char first_set
[] =
706 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
707 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
711 ecard_irqexp_handler(unsigned int irq
, struct irqdesc
*desc
, struct pt_regs
*regs
)
713 const unsigned int statusmask
= 15;
716 status
= __raw_readb(EXPMASK_STATUS
) & statusmask
;
718 unsigned int slot
= first_set
[status
];
719 ecard_t
*ec
= slot_to_ecard(slot
);
722 struct irqdesc
*d
= irqdesc
+ ec
->irq
;
724 * this ugly code is so that we can operate a
725 * prioritorising system:
727 * Card 0 highest priority
730 * Card 3 lowest priority
732 * Serial cards should go in 0/1, ethernet/scsi in 2/3
733 * otherwise you will lose serial data at high speeds!
735 d
->handle(ec
->irq
, d
, regs
);
737 printk(KERN_WARNING
"card%d: interrupt from unclaimed "
739 have_expmask
&= ~(1 << slot
);
740 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
743 printk(KERN_WARNING
"Wild interrupt from backplane (masks)\n");
746 static int __init
ecard_probeirqhw(void)
751 __raw_writeb(0x00, EXPMASK_ENABLE
);
752 __raw_writeb(0xff, EXPMASK_STATUS
);
753 found
= (__raw_readb(EXPMASK_STATUS
) & 15) == 0;
754 __raw_writeb(0xff, EXPMASK_ENABLE
);
757 printk(KERN_DEBUG
"Expansion card interrupt "
758 "management hardware found\n");
760 /* for each card present, set a bit to '1' */
761 have_expmask
= 0x80000000;
763 for (ec
= cards
; ec
; ec
= ec
->next
)
764 have_expmask
|= 1 << ec
->slot_no
;
766 __raw_writeb(have_expmask
, EXPMASK_ENABLE
);
772 #define ecard_irqexp_handler NULL
773 #define ecard_probeirqhw() (0)
776 #ifndef IO_EC_MEMC8_BASE
777 #define IO_EC_MEMC8_BASE 0
780 unsigned int ecard_address(ecard_t
*ec
, card_type_t type
, card_speed_t speed
)
782 unsigned long address
= 0;
783 int slot
= ec
->slot_no
;
785 if (ec
->slot_no
== 8)
786 return IO_EC_MEMC8_BASE
;
788 ectcr
&= ~(1 << slot
);
793 address
= IO_EC_MEMC_BASE
+ (slot
<< 12);
798 address
= IO_EC_IOC_BASE
+ (slot
<< 12);
799 #ifdef IO_EC_IOC4_BASE
801 address
= IO_EC_IOC4_BASE
+ ((slot
- 4) << 12);
804 address
+= speed
<< 17;
807 #ifdef IO_EC_EASI_BASE
809 address
= IO_EC_EASI_BASE
+ (slot
<< 22);
810 if (speed
== ECARD_FAST
)
819 iomd_writeb(ectcr
, IOMD_ECTCR
);
824 static int ecard_prints(char *buffer
, ecard_t
*ec
)
826 char *start
= buffer
;
828 buffer
+= sprintf(buffer
, " %d: %s ", ec
->slot_no
,
829 ec
->type
== ECARD_EASI
? "EASI" : " ");
831 if (ec
->cid
.id
== 0) {
832 struct in_chunk_dir incd
;
834 buffer
+= sprintf(buffer
, "[%04X:%04X] ",
835 ec
->cid
.manufacturer
, ec
->cid
.product
);
837 if (!ec
->card_desc
&& ec
->cid
.cd
&&
838 ecard_readchunk(&incd
, ec
, 0xf5, 0)) {
839 ec
->card_desc
= kmalloc(strlen(incd
.d
.string
)+1, GFP_KERNEL
);
842 strcpy((char *)ec
->card_desc
, incd
.d
.string
);
845 buffer
+= sprintf(buffer
, "%s\n", ec
->card_desc
? ec
->card_desc
: "*unknown*");
847 buffer
+= sprintf(buffer
, "Simple card %d\n", ec
->cid
.id
);
849 return buffer
- start
;
852 static int get_ecard_dev_info(char *buf
, char **start
, off_t pos
, int count
)
859 while (ec
&& count
> cnt
) {
860 len
= ecard_prints(buf
, ec
);
864 *start
= buf
+ (pos
- (at
- len
));
872 return (count
> cnt
) ? cnt
: count
;
875 static struct proc_dir_entry
*proc_bus_ecard_dir
= NULL
;
877 static void ecard_proc_init(void)
879 proc_bus_ecard_dir
= proc_mkdir("ecard", proc_bus
);
880 create_proc_info_entry("devices", 0, proc_bus_ecard_dir
,
885 * Probe for an expansion card.
887 * If bit 1 of the first byte of the card is set, then the
888 * card does not exist.
891 ecard_probe(int slot
, card_type_t type
)
898 ec
= kmalloc(sizeof(ecard_t
), GFP_KERNEL
);
902 memset(ec
, 0, sizeof(ecard_t
));
909 ec
->card_desc
= NULL
;
910 ec
->ops
= &ecard_default_ops
;
913 if ((ec
->podaddr
= ecard_address(ec
, type
, ECARD_SYNC
)) == 0)
917 ecard_readbytes(&cid
, ec
, 0, 16, 0);
921 ec
->cid
.id
= cid
.r_id
;
922 ec
->cid
.cd
= cid
.r_cd
;
923 ec
->cid
.is
= cid
.r_is
;
925 ec
->cid
.manufacturer
= ecard_getu16(cid
.r_manu
);
926 ec
->cid
.product
= ecard_getu16(cid
.r_prod
);
927 ec
->cid
.country
= cid
.r_country
;
928 ec
->cid
.irqmask
= cid
.r_irqmask
;
929 ec
->cid
.irqoff
= ecard_gets24(cid
.r_irqoff
);
930 ec
->cid
.fiqmask
= cid
.r_fiqmask
;
931 ec
->cid
.fiqoff
= ecard_gets24(cid
.r_fiqoff
);
933 ec
->irqaddr
= (unsigned char *)ioaddr(ec
->podaddr
);
936 ec
->irqmask
= ec
->cid
.irqmask
;
937 ec
->irqaddr
+= ec
->cid
.irqoff
;
938 ec
->fiqmask
= ec
->cid
.fiqmask
;
939 ec
->fiqaddr
+= ec
->cid
.fiqoff
;
945 for (i
= 0; i
< sizeof(blacklist
) / sizeof(*blacklist
); i
++)
946 if (blacklist
[i
].manufacturer
== ec
->cid
.manufacturer
&&
947 blacklist
[i
].product
== ec
->cid
.product
) {
948 ec
->card_desc
= blacklist
[i
].type
;
953 * hook the interrupt handlers
957 set_irq_chip(ec
->irq
, &ecard_chip
);
958 set_irq_handler(ec
->irq
, do_level_IRQ
);
959 set_irq_flags(ec
->irq
, IRQF_VALID
);
962 #ifdef IO_EC_MEMC8_BASE
966 #ifdef CONFIG_ARCH_RPC
967 /* On RiscPC, only first two slots have DMA capability */
972 for (ecp
= &cards
; *ecp
; ecp
= &(*ecp
)->next
);
975 slot_to_expcard
[slot
] = ec
;
977 snprintf(ec
->dev
.bus_id
, sizeof(ec
->dev
.bus_id
), "ecard%d", slot
);
978 strcpy(ec
->dev
.name
, "fixme!");
979 ec
->dev
.parent
= NULL
;
980 ec
->dev
.bus
= &ecard_bus_type
;
982 device_register(&ec
->dev
);
993 * Initialise the expansion card system.
994 * Locate all hardware - interrupt management and
997 static int __init
ecard_init(void)
1002 * Register our reboot notifier
1004 register_reboot_notifier(&ecard_reboot_notifier
);
1006 #ifdef CONFIG_CPU_32
1007 init_waitqueue_head(&ecard_wait
);
1010 printk("Probing expansion cards\n");
1012 for (slot
= 0; slot
< 8; slot
++) {
1013 if (ecard_probe(slot
, ECARD_EASI
) == -ENODEV
)
1014 ecard_probe(slot
, ECARD_IOC
);
1017 #ifdef IO_EC_MEMC8_BASE
1018 ecard_probe(8, ECARD_IOC
);
1021 irqhw
= ecard_probeirqhw();
1023 set_irq_chained_handler(IRQ_EXPANSIONCARD
,
1024 irqhw
? ecard_irqexp_handler
: ecard_irq_handler
);
1031 subsys_initcall(ecard_init
);
1036 static const struct ecard_id
*
1037 ecard_match_device(const struct ecard_id
*ids
, struct expansion_card
*ec
)
1041 for (i
= 0; ids
[i
].manufacturer
!= 65535; i
++)
1042 if (ec
->cid
.manufacturer
== ids
[i
].manufacturer
&&
1043 ec
->cid
.product
== ids
[i
].product
)
1049 static int ecard_drv_probe(struct device
*dev
)
1051 struct expansion_card
*ec
= ECARD_DEV(dev
);
1052 struct ecard_driver
*drv
= ECARD_DRV(dev
->driver
);
1053 const struct ecard_id
*id
;
1056 id
= ecard_match_device(drv
->id_table
, ec
);
1059 ret
= drv
->probe(ec
, id
);
1065 static int ecard_drv_remove(struct device
*dev
)
1067 struct expansion_card
*ec
= ECARD_DEV(dev
);
1068 struct ecard_driver
*drv
= ECARD_DRV(dev
->driver
);
1076 int ecard_register_driver(struct ecard_driver
*drv
)
1078 drv
->drv
.bus
= &ecard_bus_type
;
1079 drv
->drv
.probe
= ecard_drv_probe
;
1080 drv
->drv
.remove
= ecard_drv_remove
;
1082 return driver_register(&drv
->drv
);
1085 void ecard_remove_driver(struct ecard_driver
*drv
)
1087 driver_unregister(&drv
->drv
);
1090 static int ecard_match(struct device
*_dev
, struct device_driver
*_drv
)
1092 struct expansion_card
*ec
= ECARD_DEV(_dev
);
1093 struct ecard_driver
*drv
= ECARD_DRV(_drv
);
1096 if (drv
->id_table
) {
1097 ret
= ecard_match_device(drv
->id_table
, ec
) != NULL
;
1099 ret
= ec
->cid
.id
== drv
->id
;
1105 struct bus_type ecard_bus_type
= {
1107 .match
= ecard_match
,
1110 static int ecard_bus_init(void)
1112 return bus_register(&ecard_bus_type
);
1115 postcore_initcall(ecard_bus_init
);
1117 EXPORT_SYMBOL(ecard_readchunk
);
1118 EXPORT_SYMBOL(ecard_address
);
1119 EXPORT_SYMBOL(ecard_register_driver
);
1120 EXPORT_SYMBOL(ecard_remove_driver
);
1121 EXPORT_SYMBOL(ecard_bus_type
);