diff options
| author | Manuel Lauss <manuel.lauss@googlemail.com> | 2009-10-04 08:55:29 -0400 |
|---|---|---|
| committer | Ralf Baechle <ralf@linux-mips.org> | 2010-02-27 06:52:51 -0500 |
| commit | 0273b4efccd3bc2b2ef5ea9778e71d8efbbb7ac7 (patch) | |
| tree | c67c6fb5ff0aa4a0201676374b252ea60475235c | |
| parent | 27dd65ac9afabc8e67ab73f7c2f575eddbb47167 (diff) | |
MIPS: Alchemy: XXS1500 PCMCIA driver rewrite
Rewritten XXS1500 PCMCIA socket driver, standalone (doesn't depend on
au1000_generic.c) and added carddetect IRQ support.
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
Cc: Florian Fainelli <florian@openwrt.org>
Cc: Linux-PCMCIA <linux-pcmcia@lists.infradead.org>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
| -rw-r--r-- | arch/mips/alchemy/xxs1500/Makefile | 2 | ||||
| -rw-r--r-- | arch/mips/alchemy/xxs1500/board_setup.c | 16 | ||||
| -rw-r--r-- | arch/mips/alchemy/xxs1500/platform.c | 63 | ||||
| -rw-r--r-- | drivers/pcmcia/Kconfig | 10 | ||||
| -rw-r--r-- | drivers/pcmcia/Makefile | 3 | ||||
| -rw-r--r-- | drivers/pcmcia/au1000_xxs1500.c | 188 | ||||
| -rw-r--r-- | drivers/pcmcia/xxs1500_ss.c | 357 |
7 files changed, 433 insertions, 206 deletions
diff --git a/arch/mips/alchemy/xxs1500/Makefile b/arch/mips/alchemy/xxs1500/Makefile index 545d8f5496e5..68671c2f372c 100644 --- a/arch/mips/alchemy/xxs1500/Makefile +++ b/arch/mips/alchemy/xxs1500/Makefile | |||
| @@ -5,4 +5,4 @@ | |||
| 5 | # Makefile for MyCable XXS1500 board. | 5 | # Makefile for MyCable XXS1500 board. |
| 6 | # | 6 | # |
| 7 | 7 | ||
| 8 | lib-y := init.o board_setup.o | 8 | lib-y := init.o board_setup.o platform.o |
diff --git a/arch/mips/alchemy/xxs1500/board_setup.c b/arch/mips/alchemy/xxs1500/board_setup.c index cad14f8a7c2a..eb31350d9772 100644 --- a/arch/mips/alchemy/xxs1500/board_setup.c +++ b/arch/mips/alchemy/xxs1500/board_setup.c | |||
| @@ -69,22 +69,6 @@ void __init board_setup(void) | |||
| 69 | /* Enable DTR = USB power up */ | 69 | /* Enable DTR = USB power up */ |
| 70 | au_writel(0x01, UART3_ADDR + UART_MCR); /* UART_MCR_DTR is 0x01??? */ | 70 | au_writel(0x01, UART3_ADDR + UART_MCR); /* UART_MCR_DTR is 0x01??? */ |
| 71 | 71 | ||
| 72 | #ifdef CONFIG_PCMCIA_XXS1500 | ||
| 73 | /* GPIO 0, 1, and 4 are inputs */ | ||
| 74 | alchemy_gpio_direction_input(0); | ||
| 75 | alchemy_gpio_direction_input(1); | ||
| 76 | alchemy_gpio_direction_input(4); | ||
| 77 | |||
| 78 | /* GPIO2 208/9/10/11 are inputs */ | ||
| 79 | alchemy_gpio_direction_input(208); | ||
| 80 | alchemy_gpio_direction_input(209); | ||
| 81 | alchemy_gpio_direction_input(210); | ||
| 82 | alchemy_gpio_direction_input(211); | ||
| 83 | |||
| 84 | /* Turn off power */ | ||
| 85 | alchemy_gpio_direction_output(214, 0); | ||
| 86 | #endif | ||
| 87 | |||
| 88 | #ifdef CONFIG_PCI | 72 | #ifdef CONFIG_PCI |
| 89 | #if defined(__MIPSEB__) | 73 | #if defined(__MIPSEB__) |
| 90 | au_writel(0xf | (2 << 6) | (1 << 4), Au1500_PCI_CFG); | 74 | au_writel(0xf | (2 << 6) | (1 << 4), Au1500_PCI_CFG); |
diff --git a/arch/mips/alchemy/xxs1500/platform.c b/arch/mips/alchemy/xxs1500/platform.c new file mode 100644 index 000000000000..c14dcaa95311 --- /dev/null +++ b/arch/mips/alchemy/xxs1500/platform.c | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /* | ||
| 2 | * XXS1500 board platform device registration | ||
| 3 | * | ||
| 4 | * Copyright (C) 2009 Manuel Lauss | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/init.h> | ||
| 22 | #include <linux/platform_device.h> | ||
| 23 | |||
| 24 | #include <asm/mach-au1x00/au1000.h> | ||
| 25 | |||
| 26 | static struct resource xxs1500_pcmcia_res[] = { | ||
| 27 | { | ||
| 28 | .name = "pseudo-io", | ||
| 29 | .flags = IORESOURCE_MEM, | ||
| 30 | .start = PCMCIA_IO_PSEUDO_PHYS, | ||
| 31 | .end = PCMCIA_IO_PSEUDO_PHYS + 0x00040000 - 1, | ||
| 32 | }, | ||
| 33 | { | ||
| 34 | .name = "pseudo-attr", | ||
| 35 | .flags = IORESOURCE_MEM, | ||
| 36 | .start = PCMCIA_ATTR_PSEUDO_PHYS, | ||
| 37 | .end = PCMCIA_ATTR_PSEUDO_PHYS + 0x00040000 - 1, | ||
| 38 | }, | ||
| 39 | { | ||
| 40 | .name = "pseudo-mem", | ||
| 41 | .flags = IORESOURCE_MEM, | ||
| 42 | .start = PCMCIA_IO_PSEUDO_PHYS, | ||
| 43 | .end = PCMCIA_IO_PSEUDO_PHYS + 0x00040000 - 1, | ||
| 44 | }, | ||
| 45 | }; | ||
| 46 | |||
| 47 | static struct platform_device xxs1500_pcmcia_dev = { | ||
| 48 | .name = "xxs1500_pcmcia", | ||
| 49 | .id = -1, | ||
| 50 | .num_resources = ARRAY_SIZE(xxs1500_pcmcia_res), | ||
| 51 | .resource = xxs1500_pcmcia_res, | ||
| 52 | }; | ||
| 53 | |||
| 54 | static struct platform_device *xxs1500_devs[] __initdata = { | ||
| 55 | &xxs1500_pcmcia_dev, | ||
| 56 | }; | ||
| 57 | |||
| 58 | static int __init xxs1500_dev_init(void) | ||
| 59 | { | ||
| 60 | return platform_add_devices(xxs1500_devs, | ||
| 61 | ARRAY_SIZE(xxs1500_devs)); | ||
| 62 | } | ||
| 63 | device_initcall(xxs1500_dev_init); | ||
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index 7c16d35679a6..1e01578a0a77 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig | |||
| @@ -185,6 +185,16 @@ config PCMCIA_ALCHEMY_DEVBOARD | |||
| 185 | 185 | ||
| 186 | This driver is also available as a module called db1xxx_ss.ko | 186 | This driver is also available as a module called db1xxx_ss.ko |
| 187 | 187 | ||
| 188 | config PCMCIA_XXS1500 | ||
| 189 | tristate "MyCable XXS1500 PCMCIA socket support" | ||
| 190 | depends on PCMCIA && MIPS_XXS1500 | ||
| 191 | select 64BIT_PHYS_ADDR | ||
| 192 | help | ||
| 193 | Support for the PCMCIA/CF socket interface on MyCable XXS1500 | ||
| 194 | systems. | ||
| 195 | |||
| 196 | This driver is also available as a module called xxs1500_ss.ko | ||
| 197 | |||
| 188 | config PCMCIA_BCM63XX | 198 | config PCMCIA_BCM63XX |
| 189 | tristate "bcm63xx pcmcia support" | 199 | tristate "bcm63xx pcmcia support" |
| 190 | depends on BCM63XX && PCMCIA | 200 | depends on BCM63XX && PCMCIA |
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile index f128d71c74c2..21ee96448b1e 100644 --- a/drivers/pcmcia/Makefile +++ b/drivers/pcmcia/Makefile | |||
| @@ -39,7 +39,6 @@ obj-$(CONFIG_PCMCIA_ALCHEMY_DEVBOARD) += db1xxx_ss.o | |||
| 39 | 39 | ||
| 40 | au1x00_ss-y += au1000_generic.o | 40 | au1x00_ss-y += au1000_generic.o |
| 41 | au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o | 41 | au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o |
| 42 | au1x00_ss-$(CONFIG_MIPS_XXS1500) += au1000_xxs1500.o | ||
| 43 | 42 | ||
| 44 | sa1111_cs-y += sa1111_generic.o | 43 | sa1111_cs-y += sa1111_generic.o |
| 45 | sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1100_neponset.o | 44 | sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1100_neponset.o |
| @@ -69,3 +68,5 @@ pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o | |||
| 69 | pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o | 68 | pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o |
| 70 | 69 | ||
| 71 | obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) | 70 | obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) |
| 71 | |||
| 72 | obj-$(CONFIG_PCMCIA_XXS1500) += xxs1500_ss.o | ||
diff --git a/drivers/pcmcia/au1000_xxs1500.c b/drivers/pcmcia/au1000_xxs1500.c deleted file mode 100644 index b43d47b50819..000000000000 --- a/drivers/pcmcia/au1000_xxs1500.c +++ /dev/null | |||
| @@ -1,188 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * MyCable board specific pcmcia routines. | ||
| 4 | * | ||
| 5 | * Copyright 2003 MontaVista Software Inc. | ||
| 6 | * Author: Pete Popov, MontaVista Software, Inc. | ||
| 7 | * ppopov@mvista.com or source@mvista.com | ||
| 8 | * | ||
| 9 | * ######################################################################## | ||
| 10 | * | ||
| 11 | * This program is free software; you can distribute it and/or modify it | ||
| 12 | * under the terms of the GNU General Public License (Version 2) as | ||
| 13 | * published by the Free Software Foundation. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 18 | * for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU General Public License along | ||
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
| 22 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
| 23 | * | ||
| 24 | * ######################################################################## | ||
| 25 | * | ||
| 26 | * | ||
| 27 | */ | ||
| 28 | #include <linux/module.h> | ||
| 29 | #include <linux/init.h> | ||
| 30 | #include <linux/delay.h> | ||
| 31 | #include <linux/ioport.h> | ||
| 32 | #include <linux/kernel.h> | ||
| 33 | #include <linux/timer.h> | ||
| 34 | #include <linux/mm.h> | ||
| 35 | #include <linux/proc_fs.h> | ||
| 36 | #include <linux/types.h> | ||
| 37 | |||
| 38 | #include <pcmcia/cs_types.h> | ||
| 39 | #include <pcmcia/cs.h> | ||
| 40 | #include <pcmcia/ss.h> | ||
| 41 | #include <pcmcia/cistpl.h> | ||
| 42 | #include <pcmcia/bus_ops.h> | ||
| 43 | |||
| 44 | #include <asm/io.h> | ||
| 45 | #include <asm/irq.h> | ||
| 46 | #include <asm/system.h> | ||
| 47 | |||
| 48 | #include <asm/au1000.h> | ||
| 49 | #include <asm/au1000_pcmcia.h> | ||
| 50 | |||
| 51 | #define PCMCIA_MAX_SOCK 0 | ||
| 52 | #define PCMCIA_NUM_SOCKS (PCMCIA_MAX_SOCK + 1) | ||
| 53 | #define PCMCIA_IRQ AU1000_GPIO_4 | ||
| 54 | |||
| 55 | #if 0 | ||
| 56 | #define DEBUG(x, args...) printk(__func__ ": " x, ##args) | ||
| 57 | #else | ||
| 58 | #define DEBUG(x,args...) | ||
| 59 | #endif | ||
| 60 | |||
| 61 | static int xxs1500_pcmcia_init(struct pcmcia_init *init) | ||
| 62 | { | ||
| 63 | return PCMCIA_NUM_SOCKS; | ||
| 64 | } | ||
| 65 | |||
| 66 | static int xxs1500_pcmcia_shutdown(void) | ||
| 67 | { | ||
| 68 | /* turn off power */ | ||
| 69 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30), | ||
| 70 | GPIO2_OUTPUT); | ||
| 71 | au_sync_delay(100); | ||
| 72 | |||
| 73 | /* assert reset */ | ||
| 74 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20), | ||
| 75 | GPIO2_OUTPUT); | ||
| 76 | au_sync_delay(100); | ||
| 77 | return 0; | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | static int | ||
| 82 | xxs1500_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state) | ||
| 83 | { | ||
| 84 | u32 inserted; u32 vs; | ||
| 85 | unsigned long gpio, gpio2; | ||
| 86 | |||
| 87 | if(sock > PCMCIA_MAX_SOCK) return -1; | ||
| 88 | |||
| 89 | gpio = au_readl(SYS_PINSTATERD); | ||
| 90 | gpio2 = au_readl(GPIO2_PINSTATE); | ||
| 91 | |||
| 92 | vs = gpio2 & ((1<<8) | (1<<9)); | ||
| 93 | inserted = (!(gpio & 0x1) && !(gpio & 0x2)); | ||
| 94 | |||
| 95 | state->ready = 0; | ||
| 96 | state->vs_Xv = 0; | ||
| 97 | state->vs_3v = 0; | ||
| 98 | state->detect = 0; | ||
| 99 | |||
| 100 | if (inserted) { | ||
| 101 | switch (vs) { | ||
| 102 | case 0: | ||
| 103 | case 1: | ||
| 104 | case 2: | ||
| 105 | state->vs_3v=1; | ||
| 106 | break; | ||
| 107 | case 3: /* 5V */ | ||
| 108 | default: | ||
| 109 | /* return without setting 'detect' */ | ||
| 110 | printk(KERN_ERR "au1x00_cs: unsupported VS\n", | ||
| 111 | vs); | ||
| 112 | return; | ||
| 113 | } | ||
| 114 | state->detect = 1; | ||
| 115 | } | ||
| 116 | |||
| 117 | if (state->detect) { | ||
| 118 | state->ready = 1; | ||
| 119 | } | ||
| 120 | |||
| 121 | state->bvd1= gpio2 & (1<<10); | ||
| 122 | state->bvd2 = gpio2 & (1<<11); | ||
| 123 | state->wrprot=0; | ||
| 124 | return 1; | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | static int xxs1500_pcmcia_get_irq_info(struct pcmcia_irq_info *info) | ||
| 129 | { | ||
| 130 | |||
| 131 | if(info->sock > PCMCIA_MAX_SOCK) return -1; | ||
| 132 | info->irq = PCMCIA_IRQ; | ||
| 133 | return 0; | ||
| 134 | } | ||
| 135 | |||
| 136 | |||
| 137 | static int | ||
| 138 | xxs1500_pcmcia_configure_socket(const struct pcmcia_configure *configure) | ||
| 139 | { | ||
| 140 | |||
| 141 | if(configure->sock > PCMCIA_MAX_SOCK) return -1; | ||
| 142 | |||
| 143 | DEBUG("Vcc %dV Vpp %dV, reset %d\n", | ||
| 144 | configure->vcc, configure->vpp, configure->reset); | ||
| 145 | |||
| 146 | switch(configure->vcc){ | ||
| 147 | case 33: /* Vcc 3.3V */ | ||
| 148 | /* turn on power */ | ||
| 149 | DEBUG("turn on power\n"); | ||
| 150 | au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<14))|(1<<30), | ||
| 151 | GPIO2_OUTPUT); | ||
| 152 | au_sync_delay(100); | ||
| 153 | break; | ||
| 154 | case 50: /* Vcc 5V */ | ||
| 155 | default: /* what's this ? */ | ||
| 156 | printk(KERN_ERR "au1x00_cs: unsupported VCC\n"); | ||
| 157 | case 0: /* Vcc 0 */ | ||
| 158 | /* turn off power */ | ||
| 159 | au_sync_delay(100); | ||
| 160 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30), | ||
| 161 | GPIO2_OUTPUT); | ||
| 162 | break; | ||
| 163 | } | ||
| 164 | |||
| 165 | if (!configure->reset) { | ||
| 166 | DEBUG("deassert reset\n"); | ||
| 167 | au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<4))|(1<<20), | ||
| 168 | GPIO2_OUTPUT); | ||
| 169 | au_sync_delay(100); | ||
| 170 | au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<5))|(1<<21), | ||
| 171 | GPIO2_OUTPUT); | ||
| 172 | } | ||
| 173 | else { | ||
| 174 | DEBUG("assert reset\n"); | ||
| 175 | au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20), | ||
| 176 | GPIO2_OUTPUT); | ||
| 177 | } | ||
| 178 | au_sync_delay(100); | ||
| 179 | return 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | struct pcmcia_low_level xxs1500_pcmcia_ops = { | ||
| 183 | xxs1500_pcmcia_init, | ||
| 184 | xxs1500_pcmcia_shutdown, | ||
| 185 | xxs1500_pcmcia_socket_state, | ||
| 186 | xxs1500_pcmcia_get_irq_info, | ||
| 187 | xxs1500_pcmcia_configure_socket | ||
| 188 | }; | ||
diff --git a/drivers/pcmcia/xxs1500_ss.c b/drivers/pcmcia/xxs1500_ss.c new file mode 100644 index 000000000000..4e36930b51ce --- /dev/null +++ b/drivers/pcmcia/xxs1500_ss.c | |||
| @@ -0,0 +1,357 @@ | |||
| 1 | /* | ||
| 2 | * PCMCIA socket code for the MyCable XXS1500 system. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com> | ||
| 5 | * | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <linux/delay.h> | ||
| 9 | #include <linux/gpio.h> | ||
| 10 | #include <linux/interrupt.h> | ||
| 11 | #include <linux/io.h> | ||
| 12 | #include <linux/ioport.h> | ||
| 13 | #include <linux/mm.h> | ||
| 14 | #include <linux/platform_device.h> | ||
| 15 | #include <linux/pm.h> | ||
| 16 | #include <linux/resource.h> | ||
| 17 | #include <linux/spinlock.h> | ||
| 18 | |||
| 19 | #include <pcmcia/cs_types.h> | ||
| 20 | #include <pcmcia/cs.h> | ||
| 21 | #include <pcmcia/ss.h> | ||
| 22 | #include <pcmcia/cistpl.h> | ||
| 23 | |||
| 24 | #include <asm/irq.h> | ||
| 25 | #include <asm/system.h> | ||
| 26 | #include <asm/mach-au1x00/au1000.h> | ||
| 27 | |||
| 28 | #define MEM_MAP_SIZE 0x400000 | ||
| 29 | #define IO_MAP_SIZE 0x1000 | ||
| 30 | |||
| 31 | |||
| 32 | /* | ||
| 33 | * 3.3V cards only; all interfacing is done via gpios: | ||
| 34 | * | ||
| 35 | * 0/1: carddetect (00 = card present, xx = huh) | ||
| 36 | * 4: card irq | ||
| 37 | * 204: reset (high-act) | ||
| 38 | * 205: buffer enable (low-act) | ||
| 39 | * 208/209: card voltage key (00,01,10,11) | ||
| 40 | * 210: battwarn | ||
| 41 | * 211: batdead | ||
| 42 | * 214: power (low-act) | ||
| 43 | */ | ||
| 44 | #define GPIO_CDA 0 | ||
| 45 | #define GPIO_CDB 1 | ||
| 46 | #define GPIO_CARDIRQ 4 | ||
| 47 | #define GPIO_RESET 204 | ||
| 48 | #define GPIO_OUTEN 205 | ||
| 49 | #define GPIO_VSL 208 | ||
| 50 | #define GPIO_VSH 209 | ||
| 51 | #define GPIO_BATTDEAD 210 | ||
| 52 | #define GPIO_BATTWARN 211 | ||
| 53 | #define GPIO_POWER 214 | ||
| 54 | |||
| 55 | struct xxs1500_pcmcia_sock { | ||
| 56 | struct pcmcia_socket socket; | ||
| 57 | void *virt_io; | ||
| 58 | |||
| 59 | /* the "pseudo" addresses of the PCMCIA space. */ | ||
| 60 | unsigned long phys_io; | ||
| 61 | unsigned long phys_attr; | ||
| 62 | unsigned long phys_mem; | ||
| 63 | |||
| 64 | /* previous flags for set_socket() */ | ||
| 65 | unsigned int old_flags; | ||
| 66 | }; | ||
| 67 | |||
| 68 | #define to_xxs_socket(x) container_of(x, struct xxs1500_pcmcia_sock, socket) | ||
| 69 | |||
| 70 | static irqreturn_t cdirq(int irq, void *data) | ||
| 71 | { | ||
| 72 | struct xxs1500_pcmcia_sock *sock = data; | ||
| 73 | |||
| 74 | pcmcia_parse_events(&sock->socket, SS_DETECT); | ||
| 75 | |||
| 76 | return IRQ_HANDLED; | ||
| 77 | } | ||
| 78 | |||
| 79 | static int xxs1500_pcmcia_configure(struct pcmcia_socket *skt, | ||
| 80 | struct socket_state_t *state) | ||
| 81 | { | ||
| 82 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | ||
| 83 | unsigned int changed; | ||
| 84 | |||
| 85 | /* power control */ | ||
| 86 | switch (state->Vcc) { | ||
| 87 | case 0: | ||
| 88 | gpio_set_value(GPIO_POWER, 1); /* power off */ | ||
| 89 | break; | ||
| 90 | case 33: | ||
| 91 | gpio_set_value(GPIO_POWER, 0); /* power on */ | ||
| 92 | break; | ||
| 93 | case 50: | ||
| 94 | default: | ||
| 95 | return -EINVAL; | ||
| 96 | } | ||
| 97 | |||
| 98 | changed = state->flags ^ sock->old_flags; | ||
| 99 | |||
| 100 | if (changed & SS_RESET) { | ||
| 101 | if (state->flags & SS_RESET) { | ||
| 102 | gpio_set_value(GPIO_RESET, 1); /* assert reset */ | ||
| 103 | gpio_set_value(GPIO_OUTEN, 1); /* buffers off */ | ||
| 104 | } else { | ||
| 105 | gpio_set_value(GPIO_RESET, 0); /* deassert reset */ | ||
| 106 | gpio_set_value(GPIO_OUTEN, 0); /* buffers on */ | ||
| 107 | msleep(500); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | sock->old_flags = state->flags; | ||
| 112 | |||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | static int xxs1500_pcmcia_get_status(struct pcmcia_socket *skt, | ||
| 117 | unsigned int *value) | ||
| 118 | { | ||
| 119 | unsigned int status; | ||
| 120 | int i; | ||
| 121 | |||
| 122 | status = 0; | ||
| 123 | |||
| 124 | /* check carddetects: GPIO[0:1] must both be low */ | ||
| 125 | if (!gpio_get_value(GPIO_CDA) && !gpio_get_value(GPIO_CDB)) | ||
| 126 | status |= SS_DETECT; | ||
| 127 | |||
| 128 | /* determine card voltage: GPIO[208:209] binary value */ | ||
| 129 | i = (!!gpio_get_value(GPIO_VSL)) | ((!!gpio_get_value(GPIO_VSH)) << 1); | ||
| 130 | |||
| 131 | switch (i) { | ||
| 132 | case 0: | ||
| 133 | case 1: | ||
| 134 | case 2: | ||
| 135 | status |= SS_3VCARD; /* 3V card */ | ||
| 136 | break; | ||
| 137 | case 3: /* 5V card, unsupported */ | ||
| 138 | default: | ||
| 139 | status |= SS_XVCARD; /* treated as unsupported in core */ | ||
| 140 | } | ||
| 141 | |||
| 142 | /* GPIO214: low active power switch */ | ||
| 143 | status |= gpio_get_value(GPIO_POWER) ? 0 : SS_POWERON; | ||
| 144 | |||
| 145 | /* GPIO204: high-active reset line */ | ||
| 146 | status |= gpio_get_value(GPIO_RESET) ? SS_RESET : SS_READY; | ||
| 147 | |||
| 148 | /* other stuff */ | ||
| 149 | status |= gpio_get_value(GPIO_BATTDEAD) ? 0 : SS_BATDEAD; | ||
| 150 | status |= gpio_get_value(GPIO_BATTWARN) ? 0 : SS_BATWARN; | ||
| 151 | |||
| 152 | *value = status; | ||
| 153 | |||
| 154 | return 0; | ||
| 155 | } | ||
| 156 | |||
| 157 | static int xxs1500_pcmcia_sock_init(struct pcmcia_socket *skt) | ||
| 158 | { | ||
| 159 | gpio_direction_input(GPIO_CDA); | ||
| 160 | gpio_direction_input(GPIO_CDB); | ||
| 161 | gpio_direction_input(GPIO_VSL); | ||
| 162 | gpio_direction_input(GPIO_VSH); | ||
| 163 | gpio_direction_input(GPIO_BATTDEAD); | ||
| 164 | gpio_direction_input(GPIO_BATTWARN); | ||
| 165 | gpio_direction_output(GPIO_RESET, 1); /* assert reset */ | ||
| 166 | gpio_direction_output(GPIO_OUTEN, 1); /* disable buffers */ | ||
| 167 | gpio_direction_output(GPIO_POWER, 1); /* power off */ | ||
| 168 | |||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | |||
| 172 | static int xxs1500_pcmcia_sock_suspend(struct pcmcia_socket *skt) | ||
| 173 | { | ||
| 174 | return 0; | ||
| 175 | } | ||
| 176 | |||
| 177 | static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt, | ||
| 178 | struct pccard_io_map *map) | ||
| 179 | { | ||
| 180 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | ||
| 181 | |||
| 182 | map->start = (u32)sock->virt_io; | ||
| 183 | map->stop = map->start + IO_MAP_SIZE; | ||
| 184 | |||
| 185 | return 0; | ||
| 186 | } | ||
| 187 | |||
| 188 | static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt, | ||
| 189 | struct pccard_mem_map *map) | ||
| 190 | { | ||
| 191 | struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt); | ||
| 192 | |||
| 193 | if (map->flags & MAP_ATTRIB) | ||
| 194 | map->static_start = sock->phys_attr + map->card_start; | ||
| 195 | else | ||
| 196 | map->static_start = sock->phys_mem + map->card_start; | ||
| 197 | |||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | |||
| 201 | static struct pccard_operations xxs1500_pcmcia_operations = { | ||
| 202 | .init = xxs1500_pcmcia_sock_init, | ||
| 203 | .suspend = xxs1500_pcmcia_sock_suspend, | ||
| 204 | .get_status = xxs1500_pcmcia_get_status, | ||
| 205 | .set_socket = xxs1500_pcmcia_configure, | ||
| 206 | .set_io_map = au1x00_pcmcia_set_io_map, | ||
| 207 | .set_mem_map = au1x00_pcmcia_set_mem_map, | ||
| 208 | }; | ||
| 209 | |||
| 210 | static int __devinit xxs1500_pcmcia_probe(struct platform_device *pdev) | ||
| 211 | { | ||
| 212 | struct xxs1500_pcmcia_sock *sock; | ||
| 213 | struct resource *r; | ||
| 214 | phys_t physio; | ||
| 215 | int ret, irq; | ||
| 216 | |||
| 217 | sock = kzalloc(sizeof(struct xxs1500_pcmcia_sock), GFP_KERNEL); | ||
| 218 | if (!sock) | ||
| 219 | return -ENOMEM; | ||
| 220 | |||
| 221 | ret = -ENODEV; | ||
| 222 | |||
| 223 | /* | ||
| 224 | * pseudo-attr: The 32bit address of the PCMCIA attribute space | ||
| 225 | * for this socket (usually the 36bit address shifted 4 to the | ||
| 226 | * right). | ||
| 227 | */ | ||
| 228 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pseudo-attr"); | ||
| 229 | if (!r) { | ||
| 230 | dev_err(&pdev->dev, "missing 'pseudo-attr' resource!\n"); | ||
| 231 | goto out0; | ||
| 232 | } | ||
| 233 | sock->phys_attr = r->start; | ||
| 234 | |||
| 235 | /* | ||
| 236 | * pseudo-mem: The 32bit address of the PCMCIA memory space for | ||
| 237 | * this socket (usually the 36bit address shifted 4 to the right) | ||
| 238 | */ | ||
| 239 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pseudo-mem"); | ||
| 240 | if (!r) { | ||
| 241 | dev_err(&pdev->dev, "missing 'pseudo-mem' resource!\n"); | ||
| 242 | goto out0; | ||
| 243 | } | ||
| 244 | sock->phys_mem = r->start; | ||
| 245 | |||
| 246 | /* | ||
| 247 | * pseudo-io: The 32bit address of the PCMCIA IO space for this | ||
| 248 | * socket (usually the 36bit address shifted 4 to the right). | ||
| 249 | */ | ||
| 250 | r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pseudo-io"); | ||
| 251 | if (!r) { | ||
| 252 | dev_err(&pdev->dev, "missing 'pseudo-io' resource!\n"); | ||
| 253 | goto out0; | ||
| 254 | } | ||
| 255 | sock->phys_io = r->start; | ||
| 256 | |||
| 257 | |||
| 258 | /* for io must remap the full 36bit address (for reference see | ||
| 259 | * alchemy/common/setup.c::__fixup_bigphys_addr) | ||
| 260 | */ | ||
| 261 | physio = ((phys_t)sock->phys_io) << 4; | ||
| 262 | |||
| 263 | /* | ||
| 264 | * PCMCIA client drivers use the inb/outb macros to access | ||
| 265 | * the IO registers. Since mips_io_port_base is added | ||
| 266 | * to the access address of the mips implementation of | ||
| 267 | * inb/outb, we need to subtract it here because we want | ||
| 268 | * to access the I/O or MEM address directly, without | ||
| 269 | * going through this "mips_io_port_base" mechanism. | ||
| 270 | */ | ||
| 271 | sock->virt_io = (void *)(ioremap(physio, IO_MAP_SIZE) - | ||
| 272 | mips_io_port_base); | ||
| 273 | |||
| 274 | if (!sock->virt_io) { | ||
| 275 | dev_err(&pdev->dev, "cannot remap IO area\n"); | ||
| 276 | ret = -ENOMEM; | ||
| 277 | goto out0; | ||
| 278 | } | ||
| 279 | |||
| 280 | sock->socket.ops = &xxs1500_pcmcia_operations; | ||
| 281 | sock->socket.owner = THIS_MODULE; | ||
| 282 | sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ); | ||
| 283 | sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD; | ||
| 284 | sock->socket.map_size = MEM_MAP_SIZE; | ||
| 285 | sock->socket.io_offset = (unsigned long)sock->virt_io; | ||
| 286 | sock->socket.dev.parent = &pdev->dev; | ||
| 287 | sock->socket.resource_ops = &pccard_static_ops; | ||
| 288 | |||
| 289 | platform_set_drvdata(pdev, sock); | ||
| 290 | |||
| 291 | /* setup carddetect irq: use one of the 2 GPIOs as an | ||
| 292 | * edge detector. | ||
| 293 | */ | ||
| 294 | irq = gpio_to_irq(GPIO_CDA); | ||
| 295 | set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); | ||
| 296 | ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock); | ||
| 297 | if (ret) { | ||
| 298 | dev_err(&pdev->dev, "cannot setup cd irq\n"); | ||
| 299 | goto out1; | ||
| 300 | } | ||
| 301 | |||
| 302 | ret = pcmcia_register_socket(&sock->socket); | ||
| 303 | if (ret) { | ||
| 304 | dev_err(&pdev->dev, "failed to register\n"); | ||
| 305 | goto out2; | ||
| 306 | } | ||
| 307 | |||
| 308 | printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n"); | ||
| 309 | |||
| 310 | return 0; | ||
| 311 | |||
| 312 | out2: | ||
| 313 | free_irq(gpio_to_irq(GPIO_CDA), sock); | ||
| 314 | out1: | ||
| 315 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
| 316 | out0: | ||
| 317 | kfree(sock); | ||
| 318 | return ret; | ||
| 319 | } | ||
| 320 | |||
| 321 | static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev) | ||
| 322 | { | ||
| 323 | struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev); | ||
| 324 | |||
| 325 | pcmcia_unregister_socket(&sock->socket); | ||
| 326 | free_irq(gpio_to_irq(GPIO_CDA), sock); | ||
| 327 | iounmap((void *)(sock->virt_io + (u32)mips_io_port_base)); | ||
| 328 | kfree(sock); | ||
| 329 | |||
| 330 | return 0; | ||
| 331 | } | ||
| 332 | |||
| 333 | static struct platform_driver xxs1500_pcmcia_socket_driver = { | ||
| 334 | .driver = { | ||
| 335 | .name = "xxs1500_pcmcia", | ||
| 336 | .owner = THIS_MODULE, | ||
| 337 | }, | ||
| 338 | .probe = xxs1500_pcmcia_probe, | ||
| 339 | .remove = __devexit_p(xxs1500_pcmcia_remove), | ||
| 340 | }; | ||
| 341 | |||
| 342 | int __init xxs1500_pcmcia_socket_load(void) | ||
| 343 | { | ||
| 344 | return platform_driver_register(&xxs1500_pcmcia_socket_driver); | ||
| 345 | } | ||
| 346 | |||
| 347 | void __exit xxs1500_pcmcia_socket_unload(void) | ||
| 348 | { | ||
| 349 | platform_driver_unregister(&xxs1500_pcmcia_socket_driver); | ||
| 350 | } | ||
| 351 | |||
| 352 | module_init(xxs1500_pcmcia_socket_load); | ||
| 353 | module_exit(xxs1500_pcmcia_socket_unload); | ||
| 354 | |||
| 355 | MODULE_LICENSE("GPL"); | ||
| 356 | MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems"); | ||
| 357 | MODULE_AUTHOR("Manuel Lauss"); | ||
