Failure to detect card ins/rem with pd6729
Komuro
komurojun at mbn.nifty.com
Mon Sep 20 06:55:10 EDT 2004
>Is is safer to reset the bits 3,4 when irq_mode != 1 ?
OK.
I also add irq_mask,irq_list,irq_list_count,poll_interval parameter.
irq_mode default is now 0.
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-20 19:36:24.284568072 +0900
@@ -39,8 +39,20 @@
*/
#define to_cycles(ns) ((ns)/120)
+static int irq_mode = 0; /* 1 = PCI interrupt, 0 = ISA interrupt */
+/* Bit map or list of interrupts to choose from */
+static u_int irq_mask = 0xffff;
+static int irq_list[16];
+static int irq_list_count;
+static int poll_interval = HZ;
+
static spinlock_t port_lock = SPIN_LOCK_UNLOCKED;
+module_param(irq_mode, int, 0444);
+module_param(irq_mask, int, 0444);
+module_param_array(irq_list, int, irq_list_count, 0444);
+module_param(poll_interval, int, 0444);
+
/* basic value read/write functions */
static unsigned char indirect_read(struct pd6729_socket *socket, unsigned sho
rt reg)
@@ -204,14 +216,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)
@@ -274,10 +285,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 +310,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 +319,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 +345,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 +420,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 +446,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 */
@@ -604,9 +616,54 @@
.set_mem_map = pd6729_set_mem_map,
};
+static irqreturn_t i365_count_irq(int irq, void *dev, struct pt_regs *regs)
+{
+ dprintk("-> hit on irq %d\n", irq);
+ return IRQ_HANDLED;
+}
+
+static int _check_irq(int irq, int flags)
+{
+ if (request_irq(irq, i365_count_irq, flags, "x", i365_count_irq) != 0)
+ return -1;
+ free_irq(irq, i365_count_irq);
+ return 0;
+}
+
+static u_int __init isa_scan(void)
+{
+ u_int mask0, mask = 0;
+ int i;
+
+ if (irq_list_count == 0)
+ mask0 = irq_mask;
+ 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)) && (_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!");
+
+ 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 +678,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.
*/
@@ -639,12 +695,23 @@
printk(KERN_INFO "pd6729: pci request region failed.\n");
goto err_out_disable;
}
+
+ if (irq_mode == 1) {
+ printk(KERN_INFO "pd6729: PCI card interrupts, PCI status changes\n");
+ mask = 0;
+ } else {
+ mask = isa_scan();
+ if (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 +724,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 +752,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 +771,21 @@
int i;
struct pd6729_socket *socket = pci_get_drvdata(dev);
+ /* Turn off all interrupt sources */
+ indirect_write(socket, I365_CSCINT, 0);
+
+ if (irq_mode == 1) {
+ indirect_write(socket, PD67_EXT_INDEX, PD67_EXT_CTL_1);
+ indirect_write(socket, PD67_EXT_DATA, 0);
+ }
+
for (i = 0; i < MAX_SOCKETS; i++)
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-20 19:36:27.211123168 +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