18a6df5ca374fdf522381ae6188e0f59d569546c
[sfrench/cifs-2.6.git] / drivers / pcmcia / soc_common.h
1 /*
2  * linux/drivers/pcmcia/soc_common.h
3  *
4  * Copyright (C) 2000 John G Dorsey <john+@cs.cmu.edu>
5  *
6  * This file contains definitions for the PCMCIA support code common to
7  * integrated SOCs like the SA-11x0 and PXA2xx microprocessors.
8  */
9 #ifndef _ASM_ARCH_PCMCIA
10 #define _ASM_ARCH_PCMCIA
11
12 /* include the world */
13 #include <linux/clk.h>
14 #include <linux/cpufreq.h>
15 #include <pcmcia/ss.h>
16 #include <pcmcia/cistpl.h>
17
18
19 struct device;
20 struct gpio_desc;
21 struct pcmcia_low_level;
22 struct regulator;
23
24 struct soc_pcmcia_regulator {
25         struct regulator        *reg;
26         bool                    on;
27 };
28
29 /*
30  * This structure encapsulates per-socket state which we might need to
31  * use when responding to a Card Services query of some kind.
32  */
33 struct soc_pcmcia_socket {
34         struct pcmcia_socket    socket;
35
36         /*
37          * Info from low level handler
38          */
39         unsigned int            nr;
40         struct clk              *clk;
41
42         /*
43          * Core PCMCIA state
44          */
45         const struct pcmcia_low_level *ops;
46
47         unsigned int            status;
48         socket_state_t          cs_state;
49
50         unsigned short          spd_io[MAX_IO_WIN];
51         unsigned short          spd_mem[MAX_WIN];
52         unsigned short          spd_attr[MAX_WIN];
53
54         struct resource         res_skt;
55         struct resource         res_io;
56         struct resource         res_mem;
57         struct resource         res_attr;
58         void __iomem            *virt_io;
59
60         struct {
61                 int             gpio;
62                 struct gpio_desc *desc;
63                 unsigned int    irq;
64                 const char      *name;
65         } stat[4];
66 #define SOC_STAT_CD             0       /* Card detect */
67 #define SOC_STAT_BVD1           1       /* BATDEAD / IOSTSCHG */
68 #define SOC_STAT_BVD2           2       /* BATWARN / IOSPKR */
69 #define SOC_STAT_RDY            3       /* Ready / Interrupt */
70
71         struct gpio_desc        *gpio_reset;
72         struct gpio_desc        *gpio_bus_enable;
73         struct soc_pcmcia_regulator vcc;
74         struct soc_pcmcia_regulator vpp;
75
76         unsigned int            irq_state;
77
78         struct timer_list       poll_timer;
79         struct list_head        node;
80 };
81
82 struct skt_dev_info {
83         int nskt;
84         struct soc_pcmcia_socket skt[0];
85 };
86
87 struct pcmcia_state {
88   unsigned detect: 1,
89             ready: 1,
90              bvd1: 1,
91              bvd2: 1,
92            wrprot: 1,
93             vs_3v: 1,
94             vs_Xv: 1;
95 };
96
97 struct pcmcia_low_level {
98         struct module *owner;
99
100         /* first socket in system */
101         int first;
102         /* nr of sockets */
103         int nr;
104
105         int (*hw_init)(struct soc_pcmcia_socket *);
106         void (*hw_shutdown)(struct soc_pcmcia_socket *);
107
108         void (*socket_state)(struct soc_pcmcia_socket *, struct pcmcia_state *);
109         int (*configure_socket)(struct soc_pcmcia_socket *, const socket_state_t *);
110
111         /*
112          * Enable card status IRQs on (re-)initialisation.  This can
113          * be called at initialisation, power management event, or
114          * pcmcia event.
115          */
116         void (*socket_init)(struct soc_pcmcia_socket *);
117
118         /*
119          * Disable card status IRQs and PCMCIA bus on suspend.
120          */
121         void (*socket_suspend)(struct soc_pcmcia_socket *);
122
123         /*
124          * Hardware specific timing routines.
125          * If provided, the get_timing routine overrides the SOC default.
126          */
127         unsigned int (*get_timing)(struct soc_pcmcia_socket *, unsigned int, unsigned int);
128         int (*set_timing)(struct soc_pcmcia_socket *);
129         int (*show_timing)(struct soc_pcmcia_socket *, char *);
130
131 #ifdef CONFIG_CPU_FREQ
132         /*
133          * CPUFREQ support.
134          */
135         int (*frequency_change)(struct soc_pcmcia_socket *, unsigned long, struct cpufreq_freqs *);
136 #endif
137 };
138
139
140 struct soc_pcmcia_timing {
141         unsigned short io;
142         unsigned short mem;
143         unsigned short attr;
144 };
145
146 extern void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *, struct soc_pcmcia_timing *);
147
148 void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt,
149         struct pcmcia_low_level *ops, struct device *dev);
150 void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt);
151 int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt);
152 int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt);
153
154 void soc_common_cf_socket_state(struct soc_pcmcia_socket *skt,
155         struct pcmcia_state *state);
156
157 int soc_pcmcia_regulator_set(struct soc_pcmcia_socket *skt,
158         struct soc_pcmcia_regulator *r, int v);
159
160 #ifdef CONFIG_PCMCIA_DEBUG
161
162 extern void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
163                              int lvl, const char *fmt, ...);
164
165 #define debug(skt, lvl, fmt, arg...) \
166         soc_pcmcia_debug(skt, __func__, lvl, fmt , ## arg)
167
168 #else
169 #define debug(skt, lvl, fmt, arg...) do { } while (0)
170 #endif
171
172
173 /*
174  * The PC Card Standard, Release 7, section 4.13.4, says that twIORD
175  * has a minimum value of 165ns. Section 4.13.5 says that twIOWR has
176  * a minimum value of 165ns, as well. Section 4.7.2 (describing
177  * common and attribute memory write timing) says that twWE has a
178  * minimum value of 150ns for a 250ns cycle time (for 5V operation;
179  * see section 4.7.4), or 300ns for a 600ns cycle time (for 3.3V
180  * operation, also section 4.7.4). Section 4.7.3 says that taOE
181  * has a maximum value of 150ns for a 300ns cycle time (for 5V
182  * operation), or 300ns for a 600ns cycle time (for 3.3V operation).
183  *
184  * When configuring memory maps, Card Services appears to adopt the policy
185  * that a memory access time of "0" means "use the default." The default
186  * PCMCIA I/O command width time is 165ns. The default PCMCIA 5V attribute
187  * and memory command width time is 150ns; the PCMCIA 3.3V attribute and
188  * memory command width time is 300ns.
189  */
190 #define SOC_PCMCIA_IO_ACCESS            (165)
191 #define SOC_PCMCIA_5V_MEM_ACCESS        (150)
192 #define SOC_PCMCIA_3V_MEM_ACCESS        (300)
193 #define SOC_PCMCIA_ATTR_MEM_ACCESS      (300)
194
195 /*
196  * The socket driver actually works nicely in interrupt-driven form,
197  * so the (relatively infrequent) polling is "just to be sure."
198  */
199 #define SOC_PCMCIA_POLL_PERIOD    (2*HZ)
200
201
202 /* I/O pins replacing memory pins
203  * (PCMCIA System Architecture, 2nd ed., by Don Anderson, p.75)
204  *
205  * These signals change meaning when going from memory-only to
206  * memory-or-I/O interface:
207  */
208 #define iostschg bvd1
209 #define iospkr   bvd2
210
211 #endif