fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / pcmcia / m32r_cfc.c
index 836058d..3c22ac4 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
 #include <linux/string.h>
 #include <linux/delay.h>
 #include <linux/workqueue.h>
 #include <linux/interrupt.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/bitops.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <asm/bitops.h>
 #include <asm/system.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
@@ -61,7 +59,7 @@ typedef struct pcc_socket {
        u_short                 type, flags;
        struct pcmcia_socket    socket;
        unsigned int            number;
-       ioaddr_t                ioaddr;
+       kio_addr_t              ioaddr;
        u_long                  mapaddr;
        u_long                  base;   /* PCC register base */
        u_char                  cs_irq1, cs_irq2, intr;
@@ -86,7 +84,7 @@ static pcc_socket_t socket[M32R_MAX_PCC] = {
 static unsigned int pcc_get(u_short, unsigned int);
 static void pcc_set(u_short, unsigned int , unsigned int );
 
-static spinlock_t pcc_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(pcc_lock);
 
 #if !defined(CONFIG_PLAT_USRV)
 static inline u_long pcc_port2addr(unsigned long port, int size) {
@@ -239,6 +237,7 @@ void pcc_iowrite_word(int sock, unsigned long port, void *buf, size_t size,
 
 /*====================================================================*/
 
+#define IS_REGISTERED          0x2000
 #define IS_ALIVE               0x8000
 
 typedef struct pcc_t {
@@ -255,7 +254,7 @@ static pcc_t pcc[] = {
 #endif /* CONFIG_PLAT_USRV */
 };
 
-static irqreturn_t pcc_interrupt(int, void *, struct pt_regs *);
+static irqreturn_t pcc_interrupt(int, void *);
 
 /*====================================================================*/
 
@@ -300,7 +299,7 @@ static int __init is_alive(u_short sock)
        return 0;
 }
 
-static void add_pcc_socket(ulong base, int irq, ulong mapaddr, ioaddr_t ioaddr)
+static void add_pcc_socket(ulong base, int irq, ulong mapaddr, kio_addr_t ioaddr)
 {
        pcc_socket_t *t = &socket[pcc_sockets];
 
@@ -355,9 +354,10 @@ static void add_pcc_socket(ulong base, int irq, ulong mapaddr, ioaddr_t ioaddr)
 #ifndef CONFIG_PLAT_USRV
        /* insert interrupt */
        request_irq(irq, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt);
+#ifndef CONFIG_PLAT_MAPPI3
        /* eject interrupt */
        request_irq(irq+1, pcc_interrupt, 0, "m32r_cfc", pcc_interrupt);
-
+#endif
        debug(3, "m32r_cfc: enable CFMSK, RDYSEL\n");
        pcc_set(pcc_sockets, (unsigned int)PLD_CFIMASK, 0x01);
 #endif /* CONFIG_PLAT_USRV */
@@ -372,14 +372,13 @@ static void add_pcc_socket(ulong base, int irq, ulong mapaddr, ioaddr_t ioaddr)
 
 /*====================================================================*/
 
-static irqreturn_t pcc_interrupt(int irq, void *dev, struct pt_regs *regs)
+static irqreturn_t pcc_interrupt(int irq, void *dev)
 {
        int i;
        u_int events = 0;
        int handled = 0;
 
-       debug(3, "m32r_cfc: pcc_interrupt: irq=%d, dev=%p, regs=%p\n",
-               irq, dev, regs);
+       debug(3, "m32r_cfc: pcc_interrupt: irq=%d, dev=%p\n", irq, dev);
        for (i = 0; i < pcc_sockets; i++) {
                if (socket[i].cs_irq1 != irq && socket[i].cs_irq2 != irq)
                        continue;
@@ -399,7 +398,7 @@ static irqreturn_t pcc_interrupt(int irq, void *dev, struct pt_regs *regs)
 static void pcc_interrupt_wrapper(u_long data)
 {
        debug(3, "m32r_cfc: pcc_interrupt_wrapper:\n");
-       pcc_interrupt(0, NULL, NULL);
+       pcc_interrupt(0, NULL);
        init_timer(&poll_timer);
        poll_timer.expires = jiffies + poll_interval;
        add_timer(&poll_timer);
@@ -443,7 +442,7 @@ static int _pcc_get_status(u_short sock, u_int *value)
                debug(3, "m32r_cfc: _pcc_get_status: "
                         "power off (CPCR=0x%08x)\n", status);
        }
-#elif defined(CONFIG_PLAT_MAPPI2)
+#elif defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
        if ( status ) {
                status = pcc_get(sock, (unsigned int)PLD_CPCR);
                if (status == 0) { /* power off */
@@ -451,18 +450,23 @@ static int _pcc_get_status(u_short sock, u_int *value)
                        pcc_set(sock, (unsigned int)PLD_CFBUFCR,0); /* force buffer off for ZA-36 */
                        udelay(50);
                }
-               status = pcc_get(sock, (unsigned int)PLD_CFBUFCR);
-               if (status != 0) { /* buffer off */
-                       pcc_set(sock, (unsigned int)PLD_CFBUFCR,0);
-                       udelay(50);
-                       pcc_set(sock, (unsigned int)PLD_CFRSTCR, 0x0101);
-                       udelay(25); /* for IDE reset */
-                       pcc_set(sock, (unsigned int)PLD_CFRSTCR, 0x0100);
-                       mdelay(2);  /* for IDE reset */
-               } else {
-                       *value |= SS_POWERON;
-                       *value |= SS_READY;
-               }
+               *value |= SS_POWERON;
+
+               pcc_set(sock, (unsigned int)PLD_CFBUFCR,0);
+               udelay(50);
+               pcc_set(sock, (unsigned int)PLD_CFRSTCR, 0x0101);
+               udelay(25); /* for IDE reset */
+               pcc_set(sock, (unsigned int)PLD_CFRSTCR, 0x0100);
+               mdelay(2);  /* for IDE reset */
+
+               *value |= SS_READY;
+               *value |= SS_3VCARD;
+       } else {
+               /* disable CF power */
+               pcc_set(sock, (unsigned int)PLD_CPCR, 0);
+               udelay(100);
+               debug(3, "m32r_cfc: _pcc_get_status: "
+                        "power off (CPCR=0x%08x)\n", status);
        }
 #else
 #error no platform configuration
@@ -474,54 +478,19 @@ static int _pcc_get_status(u_short sock, u_int *value)
 
 /*====================================================================*/
 
-static int _pcc_get_socket(u_short sock, socket_state_t *state)
-{
-//     pcc_socket_t *t = &socket[sock];
-
-#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
-       state->flags = 0;
-       state->csc_mask = SS_DETECT;
-       state->csc_mask |= SS_READY;
-       state->io_irq = 0;
-       state->Vcc = 33;        /* 3.3V fixed */
-       state->Vpp = 33;
-#endif
-       debug(3, "m32r_cfc: GetSocket(%d) = flags %#3.3x, Vcc %d, Vpp %d, "
-                 "io_irq %d, csc_mask %#2.2x\n", sock, state->flags,
-                 state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
-       return 0;
-} /* _get_socket */
-
-/*====================================================================*/
-
 static int _pcc_set_socket(u_short sock, socket_state_t *state)
 {
-#if defined(CONFIG_PLAT_MAPPI2)
-       u_long reg = 0;
-#endif
        debug(3, "m32r_cfc: SetSocket(%d, flags %#3.3x, Vcc %d, Vpp %d, "
                  "io_irq %d, csc_mask %#2.2x)\n", sock, state->flags,
                  state->Vcc, state->Vpp, state->io_irq, state->csc_mask);
 
-#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT)
+#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_USRV) || defined(CONFIG_PLAT_OPSPUT) || defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
        if (state->Vcc) {
                if ((state->Vcc != 50) && (state->Vcc != 33))
                        return -EINVAL;
                /* accept 5V and 3.3V */
        }
-#elif defined(CONFIG_PLAT_MAPPI2)
-       if (state->Vcc) {
-               /*
-                * 5V only
-                */
-               if (state->Vcc == 50) {
-                       reg |= PCCSIGCR_VEN;
-               } else {
-                       return -EINVAL;
-               }
-       }
 #endif
-
        if (state->flags & SS_RESET) {
                debug(3, ":RESET\n");
                pcc_set(sock,(unsigned int)PLD_CFRSTCR,0x101);
@@ -568,7 +537,7 @@ static int _pcc_set_io_map(u_short sock, struct pccard_io_map *io)
        u_char map;
 
        debug(3, "m32r_cfc: SetIOMap(%d, %d, %#2.2x, %d ns, "
-                 "%#4.4x-%#4.4x)\n", sock, io->map, io->flags,
+                 "%#lx-%#lx)\n", sock, io->map, io->flags,
                  io->speed, io->start, io->stop);
        map = io->map;
 
@@ -585,7 +554,7 @@ static int _pcc_set_mem_map(u_short sock, struct pccard_mem_map *mem)
        pcc_socket_t *t = &socket[sock];
 
        debug(3, "m32r_cfc: SetMemMap(%d, %d, %#2.2x, %d ns, "
-                "%#5.5lx, %#5.5x)\n", sock, map, mem->flags,
+                "%#lx, %#x)\n", sock, map, mem->flags,
                 mem->speed, mem->static_start, mem->card_start);
 
        /*
@@ -677,18 +646,6 @@ static int pcc_get_status(struct pcmcia_socket *s, u_int *value)
        LOCKED(_pcc_get_status(sock, value));
 }
 
-static int pcc_get_socket(struct pcmcia_socket *s, socket_state_t *state)
-{
-       unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
-
-       if (socket[sock].flags & IS_ALIVE) {
-               debug(3, "m32r_cfc: pcc_get_socket: sock(%d) -EINVAL\n", sock);
-               return -EINVAL;
-       }
-       debug(3, "m32r_cfc: pcc_get_socket: sock(%d)\n", sock);
-       LOCKED(_pcc_get_socket(sock, state));
-}
-
 static int pcc_set_socket(struct pcmcia_socket *s, socket_state_t *state)
 {
        unsigned int sock = container_of(s, struct pcc_socket, socket)->number;
@@ -731,17 +688,9 @@ static int pcc_init(struct pcmcia_socket *s)
        return 0;
 }
 
-static int pcc_suspend(struct pcmcia_socket *sock)
-{
-       debug(3, "m32r_cfc: pcc_suspend()\n");
-       return pcc_set_socket(sock, &dead_socket);
-}
-
 static struct pccard_operations pcc_operations = {
        .init                   = pcc_init,
-       .suspend                = pcc_suspend,
        .get_status             = pcc_get_status,
-       .get_socket             = pcc_get_socket,
        .set_socket             = pcc_set_socket,
        .set_io_map             = pcc_set_io_map,
        .set_mem_map            = pcc_set_mem_map,
@@ -749,28 +698,11 @@ static struct pccard_operations pcc_operations = {
 
 /*====================================================================*/
 
-static int m32r_pcc_suspend(struct device *dev, u32 state, u32 level)
-{
-       int ret = 0;
-       if (level == SUSPEND_SAVE_STATE)
-               ret = pcmcia_socket_dev_suspend(dev, state);
-       return ret;
-}
-
-static int m32r_pcc_resume(struct device *dev, u32 level)
-{
-       int ret = 0;
-       if (level == RESUME_RESTORE_STATE)
-               ret = pcmcia_socket_dev_resume(dev);
-       return ret;
-}
-
-
 static struct device_driver pcc_driver = {
        .name = "cfc",
        .bus = &platform_bus_type,
-       .suspend = m32r_pcc_suspend,
-       .resume = m32r_pcc_resume,
+       .suspend = pcmcia_socket_dev_suspend,
+       .resume = pcmcia_socket_dev_resume,
 };
 
 static struct platform_device pcc_device = {
@@ -794,7 +726,7 @@ static int __init init_m32r_pcc(void)
                return ret;
        }
 
-#if defined(CONFIG_PLAT_MAPPI2)
+#if defined(CONFIG_PLAT_MAPPI2) || defined(CONFIG_PLAT_MAPPI3)
        pcc_set(0, (unsigned int)PLD_CFCR0, 0x0f0f);
        pcc_set(0, (unsigned int)PLD_CFCR1, 0x0200);
 #endif
@@ -807,7 +739,7 @@ static int __init init_m32r_pcc(void)
 #else  /* CONFIG_PLAT_USRV */
        {
                ulong base, mapaddr;
-               ioaddr_t ioaddr;
+               kio_addr_t ioaddr;
 
                for (i = 0 ; i < M32R_MAX_PCC ; i++) {
                        base = (ulong)PLD_CFRSTCR;
@@ -831,14 +763,13 @@ static int __init init_m32r_pcc(void)
        for (i = 0 ; i < pcc_sockets ; i++) {
                socket[i].socket.dev.dev = &pcc_device.dev;
                socket[i].socket.ops = &pcc_operations;
+               socket[i].socket.resource_ops = &pccard_nonstatic_ops;
                socket[i].socket.owner = THIS_MODULE;
                socket[i].number = i;
                ret = pcmcia_register_socket(&socket[i].socket);
-               if (ret && i--) {
-                       for (; i>= 0; i--)
-                               pcmcia_unregister_socket(&socket[i].socket);
-                       break;
-               }
+               if (!ret)
+                       socket[i].flags |= IS_REGISTERED;
+
 #if 0  /* driver model ordering issue */
                class_device_create_file(&socket[i].socket.dev,
                                         &class_device_attr_info);
@@ -864,7 +795,8 @@ static void __exit exit_m32r_pcc(void)
        int i;
 
        for (i = 0; i < pcc_sockets; i++)
-               pcmcia_unregister_socket(&socket[i].socket);
+               if (socket[i].flags & IS_REGISTERED)
+                       pcmcia_unregister_socket(&socket[i].socket);
 
        platform_device_unregister(&pcc_device);
        if (poll_interval != 0)