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