more debug output
[linux-2.4.git] / drivers / pcmcia / sa1100_graphicsclient.c
1 /*
2  * drivers/pcmcia/sa1100_graphicsclient.c
3  *
4  * PCMCIA implementation routines for Graphics Client Plus
5  *
6  * 9/12/01   Woojung
7  *    Turn power OFF at startup
8  * 1/31/2001 Woojung Huh
9  *    Fix for GC Plus PCMCIA Reset Problem
10  * 2/27/2001 Woojung Huh [whuh@applieddata.net]
11  *    Fix
12  *
13  */
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/delay.h>
17
18 #include <asm/hardware.h>
19 #include <asm/irq.h>
20 #include "sa1100_generic.h"
21
22 #error This is broken!
23
24 #define S0_CD_IRQ               60                              // Socket 0 Card Detect IRQ
25 #define S0_STS_IRQ              55                              // Socket 0 PCMCIA IRQ
26
27 static volatile unsigned long *PCMCIA_Status = 
28                 ((volatile unsigned long *) ADS_p2v(_ADS_CS_STATUS));
29
30 static volatile unsigned long *PCMCIA_Power = 
31                 ((volatile unsigned long *) ADS_p2v(_ADS_CS_PR));
32
33 static int gcplus_pcmcia_init(struct pcmcia_init *init)
34 {
35   int irq, res;
36
37   // Reset PCMCIA
38   // Reset Timing for CPLD(U2) version 8001E or later
39   *PCMCIA_Power &= ~ ADS_CS_PR_A_RESET;
40   udelay(12);                   // 12 uSec
41
42   *PCMCIA_Power |= ADS_CS_PR_A_RESET;
43   mdelay(30);                   // 30 mSec
44
45   // Turn off 5V
46   *PCMCIA_Power &= ~0x03;
47
48   /* Register interrupts */
49   irq = S0_CD_IRQ;
50   res = request_irq(irq, init->handler, SA_INTERRUPT, "PCMCIA 0 CD", NULL);
51   if (res < 0) {
52           printk(KERN_ERR "%s: Request for IRQ %lu failed\n", __FUNCTION__, irq);
53           return        -1;
54   }
55
56   return 1;                     // 1 PCMCIA Slot
57 }
58
59 static int gcplus_pcmcia_shutdown(void)
60 {
61   /* disable IRQs */
62   free_irq( S0_CD_IRQ, NULL);
63   
64   /* Shutdown PCMCIA power */
65   mdelay(2);                                            // 2msec
66   *PCMCIA_Power &= ~0x03;
67
68   return 0;
69 }
70
71 static int gcplus_pcmcia_socket_state(struct pcmcia_state_array
72                                        *state_array){
73   unsigned long levels;
74
75   if(state_array->size<1) return -1;
76
77   memset(state_array->state, 0, 
78          (state_array->size)*sizeof(struct pcmcia_state));
79
80   levels=*PCMCIA_Status;
81
82   state_array->state[0].detect=(levels & ADS_CS_ST_A_CD)?1:0;
83   state_array->state[0].ready=(levels & ADS_CS_ST_A_READY)?1:0;
84   state_array->state[0].bvd1= 0;
85   state_array->state[0].bvd2= 0;
86   state_array->state[0].wrprot=0;
87   state_array->state[0].vs_3v=0;
88   state_array->state[0].vs_Xv=0;
89
90   return 1;
91 }
92
93 static int gcplus_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
94 {
95         if (info->sock > 1)
96                 return -1;
97
98         if (info->sock == 0)
99                 info->irq = S0_STS_IRQ;
100
101         return 0;
102 }
103
104 static int gcplus_pcmcia_configure_socket(const struct pcmcia_configure
105                                            *configure)
106 {
107   unsigned long flags;
108
109   if(configure->sock>1) return -1;
110
111   save_flags_cli(flags);
112
113   switch (configure->vcc) {
114   case 0:
115           *PCMCIA_Power &= ~(ADS_CS_PR_A_3V_POWER | ADS_CS_PR_A_5V_POWER);
116     break;
117
118   case 50:
119           *PCMCIA_Power &= ~(ADS_CS_PR_A_3V_POWER | ADS_CS_PR_A_5V_POWER);
120           *PCMCIA_Power |= ADS_CS_PR_A_5V_POWER;
121         break;
122
123   case 33:
124           *PCMCIA_Power &= ~(ADS_CS_PR_A_3V_POWER | ADS_CS_PR_A_5V_POWER);
125           *PCMCIA_Power |= ADS_CS_PR_A_3V_POWER;
126     break;
127
128   default:
129     printk(KERN_ERR "%s(): unrecognized Vcc %u\n", __FUNCTION__,
130            configure->vcc);
131     restore_flags(flags);
132     return -1;
133   }
134
135   /* Silently ignore Vpp, output enable, speaker enable. */
136
137   // Reset PCMCIA
138   *PCMCIA_Power &= ~ ADS_CS_PR_A_RESET;
139   udelay(12);
140
141   *PCMCIA_Power |= ADS_CS_PR_A_RESET;
142   mdelay(30);
143
144   restore_flags(flags);
145
146   return 0;
147 }
148
149 static int gcplus_pcmcia_socket_init(int sock)
150 {
151   return 0;
152 }
153
154 static int gcplus_pcmcia_socket_suspend(int sock)
155 {
156   return 0;
157 }
158
159 struct pcmcia_low_level gcplus_pcmcia_ops = { 
160   init:                 gcplus_pcmcia_init,
161   shutdown:             gcplus_pcmcia_shutdown,
162   socket_state:         gcplus_pcmcia_socket_state,
163   get_irq_info:         gcplus_pcmcia_get_irq_info,
164   configure_socket:     gcplus_pcmcia_configure_socket,
165
166   socket_init:          gcplus_pcmcia_socket_init,
167   socket_suspend:       gcplus_pcmcia_socket_suspend,
168 };
169