1
2
3
4
5
6
7
8
9
10#ifndef LINUX_MMC_HOST_H
11#define LINUX_MMC_HOST_H
12
13#include <linux/leds.h>
14#include <linux/sched.h>
15
16#include <linux/mmc/core.h>
17#include <linux/mmc/pm.h>
18
19struct mmc_ios {
20 unsigned int clock;
21 unsigned short vdd;
22
23
24
25 unsigned char bus_mode;
26
27#define MMC_BUSMODE_OPENDRAIN 1
28#define MMC_BUSMODE_PUSHPULL 2
29
30 unsigned char chip_select;
31
32#define MMC_CS_DONTCARE 0
33#define MMC_CS_HIGH 1
34#define MMC_CS_LOW 2
35
36 unsigned char power_mode;
37
38#define MMC_POWER_OFF 0
39#define MMC_POWER_UP 1
40#define MMC_POWER_ON 2
41
42 unsigned char bus_width;
43
44#define MMC_BUS_WIDTH_1 0
45#define MMC_BUS_WIDTH_4 2
46#define MMC_BUS_WIDTH_8 3
47
48 unsigned char timing;
49
50#define MMC_TIMING_LEGACY 0
51#define MMC_TIMING_MMC_HS 1
52#define MMC_TIMING_SD_HS 2
53#define MMC_TIMING_UHS_SDR12 MMC_TIMING_LEGACY
54#define MMC_TIMING_UHS_SDR25 MMC_TIMING_SD_HS
55#define MMC_TIMING_UHS_SDR50 3
56#define MMC_TIMING_UHS_SDR104 4
57#define MMC_TIMING_UHS_DDR50 5
58
59#define MMC_SDR_MODE 0
60#define MMC_1_2V_DDR_MODE 1
61#define MMC_1_8V_DDR_MODE 2
62
63 unsigned char signal_voltage;
64
65#define MMC_SIGNAL_VOLTAGE_330 0
66#define MMC_SIGNAL_VOLTAGE_180 1
67#define MMC_SIGNAL_VOLTAGE_120 2
68
69 unsigned char drv_type;
70
71#define MMC_SET_DRIVER_TYPE_B 0
72#define MMC_SET_DRIVER_TYPE_A 1
73#define MMC_SET_DRIVER_TYPE_C 2
74#define MMC_SET_DRIVER_TYPE_D 3
75};
76
77struct mmc_host_ops {
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 int (*enable)(struct mmc_host *host);
106 int (*disable)(struct mmc_host *host, int lazy);
107
108
109
110
111
112 void (*post_req)(struct mmc_host *host, struct mmc_request *req,
113 int err);
114 void (*pre_req)(struct mmc_host *host, struct mmc_request *req,
115 bool is_first_req);
116 void (*request)(struct mmc_host *host, struct mmc_request *req);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
138 int (*get_ro)(struct mmc_host *host);
139 int (*get_cd)(struct mmc_host *host);
140
141 void (*enable_sdio_irq)(struct mmc_host *host, int enable);
142
143
144 void (*init_card)(struct mmc_host *host, struct mmc_card *card);
145
146 int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios);
147 int (*execute_tuning)(struct mmc_host *host);
148 void (*enable_preset_value)(struct mmc_host *host, bool enable);
149 int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
150};
151
152struct mmc_card;
153struct device;
154
155struct mmc_async_req {
156
157 struct mmc_request *mrq;
158
159
160
161
162 int (*err_check) (struct mmc_card *, struct mmc_async_req *);
163};
164
165struct mmc_host {
166 struct device *parent;
167 struct device class_dev;
168 int index;
169 const struct mmc_host_ops *ops;
170 unsigned int f_min;
171 unsigned int f_max;
172 unsigned int f_init;
173 u32 ocr_avail;
174 u32 ocr_avail_sdio;
175 u32 ocr_avail_sd;
176 u32 ocr_avail_mmc;
177 struct notifier_block pm_notify;
178
179#define MMC_VDD_165_195 0x00000080
180#define MMC_VDD_20_21 0x00000100
181#define MMC_VDD_21_22 0x00000200
182#define MMC_VDD_22_23 0x00000400
183#define MMC_VDD_23_24 0x00000800
184#define MMC_VDD_24_25 0x00001000
185#define MMC_VDD_25_26 0x00002000
186#define MMC_VDD_26_27 0x00004000
187#define MMC_VDD_27_28 0x00008000
188#define MMC_VDD_28_29 0x00010000
189#define MMC_VDD_29_30 0x00020000
190#define MMC_VDD_30_31 0x00040000
191#define MMC_VDD_31_32 0x00080000
192#define MMC_VDD_32_33 0x00100000
193#define MMC_VDD_33_34 0x00200000
194#define MMC_VDD_34_35 0x00400000
195#define MMC_VDD_35_36 0x00800000
196
197 unsigned long caps;
198
199#define MMC_CAP_4_BIT_DATA (1 << 0)
200#define MMC_CAP_MMC_HIGHSPEED (1 << 1)
201#define MMC_CAP_SD_HIGHSPEED (1 << 2)
202#define MMC_CAP_SDIO_IRQ (1 << 3)
203#define MMC_CAP_SPI (1 << 4)
204#define MMC_CAP_NEEDS_POLL (1 << 5)
205#define MMC_CAP_8_BIT_DATA (1 << 6)
206#define MMC_CAP_DISABLE (1 << 7)
207#define MMC_CAP_NONREMOVABLE (1 << 8)
208#define MMC_CAP_WAIT_WHILE_BUSY (1 << 9)
209#define MMC_CAP_ERASE (1 << 10)
210#define MMC_CAP_1_8V_DDR (1 << 11)
211
212#define MMC_CAP_1_2V_DDR (1 << 12)
213
214#define MMC_CAP_POWER_OFF_CARD (1 << 13)
215#define MMC_CAP_BUS_WIDTH_TEST (1 << 14)
216#define MMC_CAP_UHS_SDR12 (1 << 15)
217#define MMC_CAP_UHS_SDR25 (1 << 16)
218#define MMC_CAP_UHS_SDR50 (1 << 17)
219#define MMC_CAP_UHS_SDR104 (1 << 18)
220#define MMC_CAP_UHS_DDR50 (1 << 19)
221#define MMC_CAP_SET_XPC_330 (1 << 20)
222#define MMC_CAP_SET_XPC_300 (1 << 21)
223#define MMC_CAP_SET_XPC_180 (1 << 22)
224#define MMC_CAP_DRIVER_TYPE_A (1 << 23)
225#define MMC_CAP_DRIVER_TYPE_C (1 << 24)
226#define MMC_CAP_DRIVER_TYPE_D (1 << 25)
227#define MMC_CAP_MAX_CURRENT_200 (1 << 26)
228#define MMC_CAP_MAX_CURRENT_400 (1 << 27)
229#define MMC_CAP_MAX_CURRENT_600 (1 << 28)
230#define MMC_CAP_MAX_CURRENT_800 (1 << 29)
231#define MMC_CAP_CMD23 (1 << 30)
232
233 mmc_pm_flag_t pm_caps;
234
235#ifdef CONFIG_MMC_CLKGATE
236 int clk_requests;
237 unsigned int clk_delay;
238 bool clk_gated;
239 struct work_struct clk_gate_work;
240 unsigned int clk_old;
241 spinlock_t clk_lock;
242 struct mutex clk_gate_mutex;
243#endif
244
245
246 unsigned int max_seg_size;
247 unsigned short max_segs;
248 unsigned short unused;
249 unsigned int max_req_size;
250 unsigned int max_blk_size;
251 unsigned int max_blk_count;
252 unsigned int max_discard_to;
253
254
255 spinlock_t lock;
256
257 struct mmc_ios ios;
258 u32 ocr;
259
260
261 unsigned int use_spi_crc:1;
262 unsigned int claimed:1;
263 unsigned int bus_dead:1;
264#ifdef CONFIG_MMC_DEBUG
265 unsigned int removed:1;
266#endif
267
268
269 int enabled;
270 int rescan_disable;
271 int nesting_cnt;
272 int en_dis_recurs;
273 unsigned int disable_delay;
274 struct delayed_work disable;
275
276 struct mmc_card *card;
277
278 wait_queue_head_t wq;
279 struct task_struct *claimer;
280 int claim_cnt;
281
282 struct delayed_work detect;
283
284 const struct mmc_bus_ops *bus_ops;
285 unsigned int bus_refs;
286
287 unsigned int sdio_irqs;
288 struct task_struct *sdio_irq_thread;
289 atomic_t sdio_irq_thread_abort;
290
291 mmc_pm_flag_t pm_flags;
292
293#ifdef CONFIG_LEDS_TRIGGERS
294 struct led_trigger *led;
295#endif
296
297#ifdef CONFIG_REGULATOR
298 bool regulator_enabled;
299#endif
300
301 struct dentry *debugfs_root;
302
303 struct mmc_async_req *areq;
304
305 unsigned long private[0] ____cacheline_aligned;
306};
307
308extern struct mmc_host *mmc_alloc_host(int extra, struct device *);
309extern int mmc_add_host(struct mmc_host *);
310extern void mmc_remove_host(struct mmc_host *);
311extern void mmc_free_host(struct mmc_host *);
312
313static inline void *mmc_priv(struct mmc_host *host)
314{
315 return (void *)host->private;
316}
317
318#define mmc_host_is_spi(host) ((host)->caps & MMC_CAP_SPI)
319
320#define mmc_dev(x) ((x)->parent)
321#define mmc_classdev(x) (&(x)->class_dev)
322#define mmc_hostname(x) (dev_name(&(x)->class_dev))
323
324extern int mmc_suspend_host(struct mmc_host *);
325extern int mmc_resume_host(struct mmc_host *);
326
327extern int mmc_power_save_host(struct mmc_host *host);
328extern int mmc_power_restore_host(struct mmc_host *host);
329
330extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
331extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
332
333static inline void mmc_signal_sdio_irq(struct mmc_host *host)
334{
335 host->ops->enable_sdio_irq(host, 0);
336 wake_up_process(host->sdio_irq_thread);
337}
338
339struct regulator;
340
341#ifdef CONFIG_REGULATOR
342int mmc_regulator_get_ocrmask(struct regulator *supply);
343int mmc_regulator_set_ocr(struct mmc_host *mmc,
344 struct regulator *supply,
345 unsigned short vdd_bit);
346#else
347static inline int mmc_regulator_get_ocrmask(struct regulator *supply)
348{
349 return 0;
350}
351
352static inline int mmc_regulator_set_ocr(struct mmc_host *mmc,
353 struct regulator *supply,
354 unsigned short vdd_bit)
355{
356 return 0;
357}
358#endif
359
360int mmc_card_awake(struct mmc_host *host);
361int mmc_card_sleep(struct mmc_host *host);
362int mmc_card_can_sleep(struct mmc_host *host);
363
364int mmc_host_enable(struct mmc_host *host);
365int mmc_host_disable(struct mmc_host *host);
366int mmc_host_lazy_disable(struct mmc_host *host);
367int mmc_pm_notify(struct notifier_block *notify_block, unsigned long, void *);
368
369static inline void mmc_set_disable_delay(struct mmc_host *host,
370 unsigned int disable_delay)
371{
372 host->disable_delay = disable_delay;
373}
374
375
376extern int mmc_assume_removable;
377
378static inline int mmc_card_is_removable(struct mmc_host *host)
379{
380 return !(host->caps & MMC_CAP_NONREMOVABLE) && mmc_assume_removable;
381}
382
383static inline int mmc_card_keep_power(struct mmc_host *host)
384{
385 return host->pm_flags & MMC_PM_KEEP_POWER;
386}
387
388static inline int mmc_card_wake_sdio_irq(struct mmc_host *host)
389{
390 return host->pm_flags & MMC_PM_WAKE_SDIO_IRQ;
391}
392
393static inline int mmc_host_cmd23(struct mmc_host *host)
394{
395 return host->caps & MMC_CAP_CMD23;
396}
397#endif
398