1 /*
2 * drivers/pcmcia/sa1100_simpad.c
3 *
4 * PCMCIA implementation routines for simpad
5 *
6 */
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9
10 #include <asm/hardware.h>
11 #include <asm/irq.h>
12 #include "sa1100_generic.h"
13
14 extern long get_cs3_shadow(void);
15 extern void set_cs3_bit(int value);
16 extern void clear_cs3_bit(int value);
17
18
simpad_pcmcia_init(struct pcmcia_init * init)19 static int simpad_pcmcia_init(struct pcmcia_init *init){
20 int irq, res;
21
22 set_cs3_bit(PCMCIA_RESET);
23 clear_cs3_bit(PCMCIA_BUFF_DIS);
24 clear_cs3_bit(PCMCIA_RESET);
25
26 clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
27
28 /* Set transition detect */
29 set_GPIO_IRQ_edge( GPIO_CF_CD, GPIO_NO_EDGES );
30 set_GPIO_IRQ_edge( GPIO_CF_IRQ, GPIO_FALLING_EDGE );
31
32 /* Register interrupts */
33 irq = IRQ_GPIO_CF_CD;
34 res = request_irq( irq, init->handler, SA_INTERRUPT, "CF_CD", NULL );
35 if( res < 0 ) goto irq_err;
36
37 /* There's only one slot, but it's "Slot 1": */
38 return 2;
39
40 irq_err:
41 printk( KERN_ERR "%s: Request for IRQ %lu failed\n", __FUNCTION__, irq );
42 return -1;
43 }
44
simpad_pcmcia_shutdown(void)45 static int simpad_pcmcia_shutdown(void)
46 {
47 /* disable IRQs */
48 free_irq( IRQ_GPIO_CF_CD, NULL );
49
50 /* Disable CF bus: */
51
52 //set_cs3_bit(PCMCIA_BUFF_DIS);
53 clear_cs3_bit(PCMCIA_RESET);
54
55 return 0;
56 }
57
simpad_pcmcia_socket_state(struct pcmcia_state_array * state_array)58 static int simpad_pcmcia_socket_state(struct pcmcia_state_array
59 *state_array)
60 {
61 unsigned long levels;
62 unsigned long *cs3reg = CS3_BASE;
63
64 if(state_array->size<2) return -1;
65
66 memset(state_array->state, 0,
67 (state_array->size)*sizeof(struct pcmcia_state));
68
69 levels=GPLR;
70
71 state_array->state[1].detect=((levels & GPIO_CF_CD)==0)?1:0;
72
73 state_array->state[1].ready=(levels & GPIO_CF_IRQ)?1:0;
74
75 state_array->state[1].bvd1=1; /* Not available on Simpad. */
76
77 state_array->state[1].bvd2=1; /* Not available on Simpad. */
78
79 state_array->state[1].wrprot=0; /* Not available on Simpad. */
80
81
82 if((*cs3reg & 0x0c) == 0x0c) {
83 state_array->state[1].vs_3v=0;
84 state_array->state[1].vs_Xv=0;
85 } else
86 {
87 state_array->state[1].vs_3v=1;
88 state_array->state[1].vs_Xv=0;
89 }
90 return 1;
91 }
92
simpad_pcmcia_get_irq_info(struct pcmcia_irq_info * info)93 static int simpad_pcmcia_get_irq_info(struct pcmcia_irq_info *info){
94
95 if(info->sock>1) return -1;
96
97 if(info->sock==1)
98 info->irq=IRQ_GPIO_CF_IRQ;
99
100 return 0;
101 }
102
simpad_pcmcia_configure_socket(const struct pcmcia_configure * configure)103 static int simpad_pcmcia_configure_socket(const struct pcmcia_configure
104 *configure)
105 {
106 unsigned long value, flags;
107
108 if(configure->sock>1) return -1;
109
110 if(configure->sock==0) return 0;
111
112 save_flags_cli(flags);
113
114 /* Murphy: see table of MIC2562a-1 */
115
116 switch(configure->vcc){
117 case 0:
118 clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
119 break;
120
121 case 33:
122 clear_cs3_bit(VCC_3V_EN|EN0);
123 set_cs3_bit(VCC_5V_EN|EN1);
124 break;
125
126 case 50:
127 clear_cs3_bit(VCC_5V_EN|EN1);
128 set_cs3_bit(VCC_3V_EN|EN0);
129 break;
130
131 default:
132 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", __FUNCTION__,
133 configure->vcc);
134 clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
135 restore_flags(flags);
136 return -1;
137 }
138
139 /* Silently ignore Vpp, output enable, speaker enable. */
140
141 restore_flags(flags);
142
143 return 0;
144 }
145
simpad_pcmcia_socket_init(int sock)146 static int simpad_pcmcia_socket_init(int sock)
147 {
148 set_GPIO_IRQ_edge(GPIO_CF_CD, GPIO_BOTH_EDGES);
149 return 0;
150 }
151
simpad_pcmcia_socket_suspend(int sock)152 static int simpad_pcmcia_socket_suspend(int sock)
153 {
154 set_GPIO_IRQ_edge(GPIO_CF_CD, GPIO_NO_EDGES);
155 return 0;
156 }
157
158 struct pcmcia_low_level simpad_pcmcia_ops = {
159 init: simpad_pcmcia_init,
160 shutdown: simpad_pcmcia_shutdown,
161 socket_state: simpad_pcmcia_socket_state,
162 get_irq_info: simpad_pcmcia_get_irq_info,
163 configure_socket: simpad_pcmcia_configure_socket,
164
165 socket_init: simpad_pcmcia_socket_init,
166 socket_suspend: simpad_pcmcia_socket_suspend,
167 };
168
169