Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/ioport.h> |
| 32 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/timer.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/types.h> |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <pcmcia/cs_types.h> |
| 39 | #include <pcmcia/cs.h> |
| 40 | #include <pcmcia/ss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <pcmcia/cistpl.h> |
| 42 | #include <pcmcia/bus_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Yoichi Yuasa | b5446b5 | 2007-10-16 01:23:51 -0700 | [diff] [blame] | 50 | |
| 51 | #define PCMCIA_MAX_SOCK 0 |
| 52 | #define PCMCIA_NUM_SOCKS (PCMCIA_MAX_SOCK + 1) |
| 53 | #define PCMCIA_IRQ AU1000_GPIO_4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #if 0 |
Harvey Harrison | 2e11cb4 | 2008-05-01 04:34:54 -0700 | [diff] [blame] | 56 | #define DEBUG(x, args...) printk(__func__ ": " x, ##args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | }; |