Failure to detect card ins/rem with pd6729
Komuro
komurojun at mbn.nifty.com
Sat Sep 25 19:20:28 EDT 2004
>Sorry I mean using: MODULE_PARM_DESC(param1, "Description of param1") >functi
on/macro
>in the module code, so that the description can be seen by using modinfo >com
mand also.
OK.I added MODULE_PARAM_DESC.
default value of "irq_mode" parameter is now 1.
Best Regards
Komuro
diff -ruN linux/drivers/pcmcia.orig/pd6729.c linux/drivers/pcmcia/pd6729.c
--- linux/drivers/pcmcia.orig/pd6729.c 2004-08-14 19:56:01.000000000 +0900
+++ linux/drivers/pcmcia/pd6729.c 2004-09-26 08:03:36.549224304 +0900
@@ -39,6 +39,38 @@
*/
#define to_cycles(ns) ((ns)/120)
+/*
+ * PARAMETERS
+ * irq_mode=n
+ * Specifies the interrupt delivery mode. The default (1) is to use PCI
+ * interrupts; a value of 0 selects ISA interrupts. This must be set for
+ * correct operation of PCI card readers.
+ *
+ * irq_list=i,j,...
+ * This list limits the set of interrupts that can be used by PCMCIA
+ * cards.
+ * The default list is 3,4,5,7,9,10,11.
+ * (irq_list parameter is not used, if irq_mode = 1)
+ *
+ * poll_interval=n
+ * Sets the card status polling delay, in 1/1000 second increments.
+ * Polling only affects detection of card insert and eject events.
+ * The default is 1000.
+ * (poll_interval parameter is not used, if irq_mode = 1)
+ */
+
+static int irq_mode = 1; /* 0 = ISA interrupt, 1 = PCI interrupt */
+static int irq_list[16];
+static int irq_list_count = 0;
+static int poll_interval = HZ;
+
+module_param(irq_mode, int, 0444);
+module_param_array(irq_list, int, irq_list_count, 0444);
+module_param(poll_interval, int, 0444);
+MODULE_PARM_DESC(irq_mode, "interrupt delivery mode. 0 = ISA, 1 = PCI. defaul
t is 1");
+MODULE_PARM_DESC(irq_list, "interrupts that can be used by PCMCIA cards");
+MODULE_PARM_DESC(poll_interval, "card status polling delay. default is 1000")
;
+
static spinlock_t port_lock = SPIN_LOCK_UNLOCKED;
/* basic value read/write functions */
@@ -204,14 +236,13 @@
return IRQ_RETVAL(handled);
}
-/* socket functions */
-
-static void set_bridge_state(struct pd6729_socket *socket)
+static void pd6729_interrupt_wrapper(unsigned long data)
{
- indirect_write(socket, I365_GBLCTL, 0x00);
- indirect_write(socket, I365_GENCTL, 0x00);
+ struct pd6729_socket *socket = (struct pd6729_socket *) data;
- indirect_setbit(socket, I365_INTCTL, 0x08);
+ pd6729_interrupt(0, (void *)socket, NULL);
+ socket->poll_timer.expires = jiffies + poll_interval;
+ add_timer(&socket->poll_timer);
}
static int pd6729_get_status(struct pcmcia_socket *sock, u_int *value)
@@ -262,7 +293,6 @@
return 0;
}
-
static int pd6729_get_socket(struct pcmcia_socket *sock, socket_state_t *stat
e)
{
struct pd6729_socket *socket = container_of(sock, struct pd6729_socket, sock
et);
@@ -274,10 +304,7 @@
state->io_irq = 0;
state->csc_mask = 0;
- /*
- * First the power status of the socket
- * PCTRL - Power Control Register
- */
+ /* First the power status of the socket */
reg = indirect_read(socket, I365_POWER);
if (reg & I365_PWR_AUTO)
@@ -302,10 +329,7 @@
state->Vpp = 120;
}
- /*
- * Now the IO card, RESET flags and IO interrupt
- * IGENC, Interrupt and General Control
- */
+ /* Now the IO card, RESET flags and IO interrupt */
reg = indirect_read(socket, I365_INTCTL);
if ((reg & I365_PC_RESET) == 0)
@@ -314,12 +338,9 @@
state->flags |= SS_IOCARD; /* This is an IO card */
/* Set the IRQ number */
- state->io_irq = socket->socket.pci_irq;
+ state->io_irq = socket->card_irq;
- /*
- * Card status change
- * CSCICR, Card Status Change Interrupt Configuration
- */
+ /* Card status change */
reg = indirect_read(socket, I365_CSCINT);
if (reg & I365_CSC_DETECT)
@@ -343,22 +364,22 @@
static int pd6729_set_socket(struct pcmcia_socket *sock, socket_state_t *stat
e)
{
struct pd6729_socket *socket = container_of(sock, struct pd6729_socket, sock
et);
- unsigned char reg;
+ unsigned char reg, data;
/* First, set the global controller options */
+ indirect_write(socket, I365_GBLCTL, 0x00);
+ indirect_write(socket, I365_GENCTL, 0x00);
- set_bridge_state(socket);
-
- /* Values for the IGENC register */
+ socket->card_irq = state->io_irq;
reg = 0;
/* The reset bit has "inverse" logic */
if (!(state->flags & SS_RESET))
- reg = reg | I365_PC_RESET;
+ reg |= I365_PC_RESET;
if (state->flags & SS_IOCARD)
- reg = reg | I365_PC_IOCARD;
+ reg |= I365_PC_IOCARD;
- /* IGENC, Interrupt and General Control Register */
+ /* Interrupt and General Control Register */
indirect_write(socket, I365_INTCTL, reg);
/* Power registers */
@@ -418,9 +439,14 @@
if (reg != indirect_read(socket, I365_POWER))
indirect_write(socket, I365_POWER, reg);
- /* Now, specifiy that all interrupts are to be done as PCI interrupts */
+ if (irq_mode == 1) {
+ /* all interrupts are to be done as PCI interrupts */
+ data = PD67_EC1_INV_MGMT_IRQ | PD67_EC1_INV_CARD_IRQ;
+ } else
+ data = 0;
+
indirect_write(socket, PD67_EXT_INDEX, PD67_EXT_CTL_1);
- indirect_write(socket, PD67_EXT_DATA, PD67_EC1_INV_MGMT_IRQ | PD67_EC1_INV_C
ARD_IRQ);
+ indirect_write(socket, PD67_EXT_DATA, data);
/* Enable specific interrupt events */
@@ -439,11 +465,16 @@
if (state->csc_mask & SS_READY)
reg |= I365_CSC_READY;
}
- reg |= 0x30; /* management IRQ: PCI INTA# = "irq 3" */
+ if (irq_mode == 1)
+ reg |= 0x30; /* management IRQ: PCI INTA# = "irq 3" */
indirect_write(socket, I365_CSCINT, reg);
reg = indirect_read(socket, I365_INTCTL);
- reg |= 0x03; /* card IRQ: PCI INTA# = "irq 3" */
+ if (irq_mode == 1)
+ reg |= 0x03; /* card IRQ: PCI INTA# = "irq 3" */
+ else
+ reg |= socket->card_irq;
+
indirect_write(socket, I365_INTCTL, reg);
/* now clear the (probably bogus) pending stuff by doing a dummy read */
@@ -592,7 +623,6 @@
return 0;
}
-
/* the pccard structure and its functions */
static struct pccard_operations pd6729_operations = {
.init = pd6729_init,
@@ -604,9 +634,61 @@
.set_mem_map = pd6729_set_mem_map,
};
+static irqreturn_t pd6729_test(int irq, void *dev, struct pt_regs *regs)
+{
+ dprintk("-> hit on irq %d\n", irq);
+ return IRQ_HANDLED;
+}
+
+static int pd6729_check_irq(int irq, int flags)
+{
+ if (request_irq(irq, pd6729_test, flags, "x", pd6729_test) != 0)
+ return -1;
+ free_irq(irq, pd6729_test);
+ return 0;
+}
+
+static u_int __init pd6729_isa_scan(void)
+{
+ u_int mask0, mask = 0;
+ int i;
+
+ if (irq_mode == 1) {
+ printk(KERN_INFO "pd6729: PCI card interrupts, PCI status changes\n");
+ return 0;
+ }
+
+ if (irq_list_count == 0)
+ mask0 = 0xffff;
+ else
+ for (i = mask0 = 0; i < irq_list_count; i++)
+ mask0 |= (1<<irq_list[i]);
+
+ mask0 &= PD67_MASK;
+
+ /* just find interrupts that aren't in use */
+ for (i = 0; i < 16; i++)
+ if ((mask0 & (1 << i)) && (pd6729_check_irq(i, 0) == 0))
+ mask |= (1 << i);
+
+ printk(KERN_INFO "pd6729: ISA irqs = ");
+ for (i = 0; i < 16; i++)
+ if (mask & (1<<i))
+ printk("%s%d", ((mask & ((1<<i)-1)) ? "," : ""), i);
+
+ if (mask == 0) printk("none!");
+
+ if (poll_interval == 0)
+ poll_interval = HZ;
+ printk(" polling interval = %d ms\n", poll_interval * 1000 / HZ);
+
+ return mask;
+}
+
static int __devinit pd6729_pci_probe(struct pci_dev *dev, const struct pci_d
evice_id *id)
{
int i, j, ret;
+ u_int mask;
char configbyte;
struct pd6729_socket *socket;
@@ -621,9 +703,8 @@
printk(KERN_INFO "pd6729: Cirrus PD6729 PCI to PCMCIA Bridge at 0x%lx on irq
%d\n",
pci_resource_start(dev, 0), dev->irq);
- printk(KERN_INFO "pd6729: configured as a %d socket device.\n", MAX_SOCKETS)
;
/*
- * Since we have no memory BARs some firmware we may not
+ * Since we have no memory BARs some firmware may not
* have had PCI_COMMAND_MEM enabled, yet the device needs
* it.
*/
@@ -640,11 +721,20 @@
goto err_out_disable;
}
+ if (dev->irq == 0)
+ irq_mode = 0; /* fall back to ISA interrupt mode */
+
+ mask = pd6729_isa_scan();
+ if (irq_mode == 0 && mask == 0) {
+ printk(KERN_INFO "pd6729: no ISA interrupt is available.\n");
+ goto err_out_free_res;
+ }
+
for (i = 0; i < MAX_SOCKETS; i++) {
socket[i].io_base = pci_resource_start(dev, 0);
socket[i].socket.features |= SS_CAP_PCCARD;
socket[i].socket.map_size = 0x1000;
- socket[i].socket.irq_mask = 0;
+ socket[i].socket.irq_mask = mask;
socket[i].socket.pci_irq = dev->irq;
socket[i].socket.owner = THIS_MODULE;
@@ -657,10 +747,19 @@
pci_set_drvdata(dev, socket);
- /* Register the interrupt handler */
- if ((ret = request_irq(dev->irq, pd6729_interrupt, SA_SHIRQ, "pd6729", socke
t))) {
- printk(KERN_ERR "pd6729: Failed to register irq %d, aborting\n", dev->irq);
- goto err_out_free_res;
+ if (irq_mode == 1) {
+ /* Register the interrupt handler */
+ if ((ret = request_irq(dev->irq, pd6729_interrupt, SA_SHIRQ, "pd6729", sock
et))) {
+ printk(KERN_ERR "pd6729: Failed to register irq %d, aborting\n", dev->irq)
;
+ goto err_out_free_res;
+ }
+ } else {
+ /* poll Card status change */
+ init_timer(&socket->poll_timer);
+ socket->poll_timer.function = pd6729_interrupt_wrapper;
+ socket->poll_timer.data = (unsigned long)socket;
+ socket->poll_timer.expires = jiffies + poll_interval;
+ add_timer(&socket->poll_timer);
}
for (i = 0; i < MAX_SOCKETS; i++) {
@@ -676,7 +775,10 @@
return 0;
err_out_free_res2:
- free_irq(dev->irq, socket);
+ if (irq_mode == 1)
+ free_irq(dev->irq, socket);
+ else
+ del_timer_sync(&socket->poll_timer);
err_out_free_res:
pci_release_regions(dev);
err_out_disable:
@@ -692,10 +794,18 @@
int i;
struct pd6729_socket *socket = pci_get_drvdata(dev);
- for (i = 0; i < MAX_SOCKETS; i++)
+ for (i = 0; i < MAX_SOCKETS; i++) {
+ /* Turn off all interrupt sources */
+ indirect_write(&socket[i], I365_CSCINT, 0);
+ indirect_write(&socket[i], I365_INTCTL, 0);
+
pcmcia_unregister_socket(&socket[i].socket);
+ }
- free_irq(dev->irq, socket);
+ if (irq_mode == 1)
+ free_irq(dev->irq, socket);
+ else
+ del_timer_sync(&socket->poll_timer);
pci_release_regions(dev);
pci_disable_device(dev);
diff -ruN linux/drivers/pcmcia.orig/pd6729.h linux/drivers/pcmcia/pd6729.h
--- linux/drivers/pcmcia.orig/pd6729.h 2004-08-14 19:54:47.000000000 +0900
+++ linux/drivers/pcmcia/pd6729.h 2004-09-26 07:59:53.880075160 +0900
@@ -16,13 +16,15 @@
#define PD67_EXD_VS1(s) (0x01 << ((s) << 1))
#define PD67_EXD_VS2(s) (0x02 << ((s) << 1))
-
-
+/* Default ISA interrupt mask */
+#define PD67_MASK 0x0eb8 /* irq 11,10,9,7,5,4,3 */
struct pd6729_socket {
int number;
+ int card_irq;
unsigned long io_base; /* base io address of the socket */
struct pcmcia_socket socket;
+ struct timer_list poll_timer;
};
#endif
More information about the linux-pcmcia
mailing list