blob: f2078aecb9149ca05259473994bdcffe8e83bbc8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Eric Miao2a125dd2010-11-22 22:48:49 +080013#include <linux/clk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/cpufreq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <pcmcia/ss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <pcmcia/cistpl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18
19struct device;
Russell King45ca7532016-08-31 08:49:45 +010020struct gpio_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021struct pcmcia_low_level;
Russell Kingac61b602016-08-31 08:49:46 +010022struct regulator;
23
24struct soc_pcmcia_regulator {
25 struct regulator *reg;
26 bool on;
27};
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
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 */
33struct soc_pcmcia_socket {
34 struct pcmcia_socket socket;
35
36 /*
37 * Info from low level handler
38 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 unsigned int nr;
Eric Miao2a125dd2010-11-22 22:48:49 +080040 struct clk *clk;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42 /*
43 * Core PCMCIA state
44 */
Russell King - ARM Linuxb62d99b2009-03-29 22:14:32 +010045 const struct pcmcia_low_level *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
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
Russell Kingd9dc8782011-12-19 22:00:22 +000060 struct {
61 int gpio;
Russell King45ca7532016-08-31 08:49:45 +010062 struct gpio_desc *desc;
Russell Kingd9dc8782011-12-19 22:00:22 +000063 unsigned int irq;
64 const char *name;
Russell King58052712016-08-31 11:28:19 +010065 } stat[6];
Russell Kingd9dc8782011-12-19 22:00:22 +000066#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 */
Russell King58052712016-08-31 11:28:19 +010070#define SOC_STAT_VS1 4 /* Voltage sense 1 */
71#define SOC_STAT_VS2 5 /* Voltage sense 2 */
Russell Kingd9dc8782011-12-19 22:00:22 +000072
Russell King535e0ab2016-08-31 08:49:45 +010073 struct gpio_desc *gpio_reset;
74 struct gpio_desc *gpio_bus_enable;
Russell Kingac61b602016-08-31 08:49:46 +010075 struct soc_pcmcia_regulator vcc;
76 struct soc_pcmcia_regulator vpp;
Russell King535e0ab2016-08-31 08:49:45 +010077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 unsigned int irq_state;
79
Russell Kingfb8c9952016-08-31 08:49:46 +010080#ifdef CONFIG_CPU_FREQ
81 struct notifier_block cpufreq_nb;
82#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 struct timer_list poll_timer;
84 struct list_head node;
85};
86
Eric Miaob393c692009-01-19 17:34:27 +080087struct skt_dev_info {
88 int nskt;
89 struct soc_pcmcia_socket skt[0];
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092struct pcmcia_state {
93 unsigned detect: 1,
94 ready: 1,
95 bvd1: 1,
96 bvd2: 1,
97 wrprot: 1,
98 vs_3v: 1,
99 vs_Xv: 1;
100};
101
102struct pcmcia_low_level {
103 struct module *owner;
104
105 /* first socket in system */
106 int first;
107 /* nr of sockets */
108 int nr;
109
110 int (*hw_init)(struct soc_pcmcia_socket *);
111 void (*hw_shutdown)(struct soc_pcmcia_socket *);
112
113 void (*socket_state)(struct soc_pcmcia_socket *, struct pcmcia_state *);
114 int (*configure_socket)(struct soc_pcmcia_socket *, const socket_state_t *);
115
116 /*
117 * Enable card status IRQs on (re-)initialisation. This can
118 * be called at initialisation, power management event, or
119 * pcmcia event.
120 */
121 void (*socket_init)(struct soc_pcmcia_socket *);
122
123 /*
124 * Disable card status IRQs and PCMCIA bus on suspend.
125 */
126 void (*socket_suspend)(struct soc_pcmcia_socket *);
127
128 /*
129 * Hardware specific timing routines.
130 * If provided, the get_timing routine overrides the SOC default.
131 */
132 unsigned int (*get_timing)(struct soc_pcmcia_socket *, unsigned int, unsigned int);
133 int (*set_timing)(struct soc_pcmcia_socket *);
134 int (*show_timing)(struct soc_pcmcia_socket *, char *);
135
136#ifdef CONFIG_CPU_FREQ
137 /*
138 * CPUFREQ support.
139 */
140 int (*frequency_change)(struct soc_pcmcia_socket *, unsigned long, struct cpufreq_freqs *);
141#endif
142};
143
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145struct soc_pcmcia_timing {
146 unsigned short io;
147 unsigned short mem;
148 unsigned short attr;
149};
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151extern void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *, struct soc_pcmcia_timing *);
152
Russell Kinge0d21172011-12-19 14:07:31 +0000153void soc_pcmcia_init_one(struct soc_pcmcia_socket *skt,
Russell Kingc8f9ce52016-08-31 08:49:46 +0100154 const struct pcmcia_low_level *ops, struct device *dev);
Russell King - ARM Linux097e2962009-03-26 21:45:05 +0000155void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt);
156int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt);
Russell King45ca7532016-08-31 08:49:45 +0100157int soc_pcmcia_request_gpiods(struct soc_pcmcia_socket *skt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Russell Kinga1d05002016-08-31 08:49:46 +0100159void soc_common_cf_socket_state(struct soc_pcmcia_socket *skt,
160 struct pcmcia_state *state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Russell Kingac61b602016-08-31 08:49:46 +0100162int soc_pcmcia_regulator_set(struct soc_pcmcia_socket *skt,
163 struct soc_pcmcia_regulator *r, int v);
164
Dominik Brodowski7d16b652008-08-02 21:02:01 +0200165#ifdef CONFIG_PCMCIA_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167extern void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
168 int lvl, const char *fmt, ...);
169
170#define debug(skt, lvl, fmt, arg...) \
171 soc_pcmcia_debug(skt, __func__, lvl, fmt , ## arg)
172
173#else
174#define debug(skt, lvl, fmt, arg...) do { } while (0)
175#endif
176
177
178/*
179 * The PC Card Standard, Release 7, section 4.13.4, says that twIORD
180 * has a minimum value of 165ns. Section 4.13.5 says that twIOWR has
181 * a minimum value of 165ns, as well. Section 4.7.2 (describing
182 * common and attribute memory write timing) says that twWE has a
183 * minimum value of 150ns for a 250ns cycle time (for 5V operation;
184 * see section 4.7.4), or 300ns for a 600ns cycle time (for 3.3V
185 * operation, also section 4.7.4). Section 4.7.3 says that taOE
186 * has a maximum value of 150ns for a 300ns cycle time (for 5V
187 * operation), or 300ns for a 600ns cycle time (for 3.3V operation).
188 *
189 * When configuring memory maps, Card Services appears to adopt the policy
190 * that a memory access time of "0" means "use the default." The default
191 * PCMCIA I/O command width time is 165ns. The default PCMCIA 5V attribute
192 * and memory command width time is 150ns; the PCMCIA 3.3V attribute and
193 * memory command width time is 300ns.
194 */
195#define SOC_PCMCIA_IO_ACCESS (165)
196#define SOC_PCMCIA_5V_MEM_ACCESS (150)
197#define SOC_PCMCIA_3V_MEM_ACCESS (300)
198#define SOC_PCMCIA_ATTR_MEM_ACCESS (300)
199
200/*
201 * The socket driver actually works nicely in interrupt-driven form,
202 * so the (relatively infrequent) polling is "just to be sure."
203 */
204#define SOC_PCMCIA_POLL_PERIOD (2*HZ)
205
206
207/* I/O pins replacing memory pins
208 * (PCMCIA System Architecture, 2nd ed., by Don Anderson, p.75)
209 *
210 * These signals change meaning when going from memory-only to
211 * memory-or-I/O interface:
212 */
213#define iostschg bvd1
214#define iospkr bvd2
215
216#endif