Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  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/tqueue.h>
 34 #include <linux/timer.h>
 35 #include <linux/mm.h>
 36 #include <linux/proc_fs.h>
 37 #include <linux/types.h>
 38 
 39 #include <pcmcia/cs_types.h>
 40 #include <pcmcia/cs.h>
 41 #include <pcmcia/ss.h>
 42 #include <pcmcia/cistpl.h>
 43 #include <pcmcia/bus_ops.h>
 44 
 45 #include <asm/io.h>
 46 #include <asm/irq.h>
 47 #include <asm/system.h>
 48 
 49 #include <asm/au1000.h>
 50 #include <asm/au1000_pcmcia.h>
 51 
 52 #define PCMCIA_MAX_SOCK         0
 53 #define PCMCIA_NUM_SOCKS        (PCMCIA_MAX_SOCK + 1)
 54 #define PCMCIA_IRQ              AU1000_GPIO_4
 55 
 56 #if 0
 57 #define DEBUG(x, args...)       printk(__func__ ": " x, ##args)
 58 #else
 59 #define DEBUG(x,args...)
 60 #endif
 61 
 62 static int xxs1500_pcmcia_init(struct pcmcia_init *init)
 63 {
 64         return PCMCIA_NUM_SOCKS;
 65 }
 66 
 67 static int xxs1500_pcmcia_shutdown(void)
 68 {
 69         /* turn off power */
 70         au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30),
 71                         GPIO2_OUTPUT);
 72         au_sync_delay(100);
 73 
 74         /* assert reset */
 75         au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20),
 76                         GPIO2_OUTPUT);
 77         au_sync_delay(100);
 78         return 0;
 79 }
 80 
 81 
 82 static int
 83 xxs1500_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
 84 {
 85         u32 inserted; u32 vs;
 86         unsigned long gpio, gpio2;
 87 
 88         if(sock > PCMCIA_MAX_SOCK) return -1;
 89 
 90         gpio = au_readl(SYS_PINSTATERD);
 91         gpio2 = au_readl(GPIO2_PINSTATE);
 92 
 93         vs = gpio2 & ((1<<8) | (1<<9));
 94         inserted = (!(gpio & 0x1) && !(gpio & 0x2));
 95 
 96         state->ready = 0;
 97         state->vs_Xv = 0;
 98         state->vs_3v = 0;
 99         state->detect = 0;
100 
101         if (inserted) {
102                 switch (vs) {
103                         case 0:
104                         case 1:
105                         case 2:
106                                 state->vs_3v=1;
107                                 break;
108                         case 3: /* 5V */
109                         default:
110                                 /* return without setting 'detect' */
111                                 printk(KERN_ERR "au1x00_cs: unsupported VS\n",
112                                                 vs);
113                                 return;
114                 }
115                 state->detect = 1;
116         }
117 
118         if (state->detect) {
119                 state->ready = 1;
120         }
121 
122         state->bvd1= gpio2 & (1<<10);
123         state->bvd2 = gpio2 & (1<<11);
124         state->wrprot=0;
125         return 1;
126 }
127 
128 
129 static int xxs1500_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
130 {
131 
132         if(info->sock > PCMCIA_MAX_SOCK) return -1;
133         info->irq = PCMCIA_IRQ;
134         return 0;
135 }
136 
137 
138 static int
139 xxs1500_pcmcia_configure_socket(const struct pcmcia_configure *configure)
140 {
141 
142         if(configure->sock > PCMCIA_MAX_SOCK) return -1;
143 
144         DEBUG("Vcc %dV Vpp %dV, reset %d\n",
145                         configure->vcc, configure->vpp, configure->reset);
146 
147         switch(configure->vcc){
148                 case 33: /* Vcc 3.3V */
149                         /* turn on power */
150                         DEBUG("turn on power\n");
151                         au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<14))|(1<<30),
152                                         GPIO2_OUTPUT);
153                         au_sync_delay(100);
154                         break;
155                 case 50: /* Vcc 5V */
156                 default: /* what's this ? */
157                         printk(KERN_ERR "au1x00_cs: unsupported VCC\n");
158                 case 0:  /* Vcc 0 */
159                         /* turn off power */
160                         au_sync_delay(100);
161                         au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30),
162                                         GPIO2_OUTPUT);
163                         break;
164         }
165 
166         if (!configure->reset) {
167                 DEBUG("deassert reset\n");
168                 au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<4))|(1<<20),
169                                 GPIO2_OUTPUT);
170                 au_sync_delay(100);
171                 au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<5))|(1<<21),
172                                 GPIO2_OUTPUT);
173         }
174         else {
175                 DEBUG("assert reset\n");
176                 au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20),
177                                 GPIO2_OUTPUT);
178         }
179         au_sync_delay(100);
180         return 0;
181 }
182 
183 struct pcmcia_low_level xxs1500_pcmcia_ops = {
184         xxs1500_pcmcia_init,
185         xxs1500_pcmcia_shutdown,
186         xxs1500_pcmcia_socket_state,
187         xxs1500_pcmcia_get_irq_info,
188         xxs1500_pcmcia_configure_socket
189 };
190 
  This page was automatically generated by the LXR engine.