]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/mmc/host/sdhci.h
c0ee766bec5c6981a76db819a3715c2e9c93a918
[sojka/nv-tegra/linux-3.10.git] / drivers / mmc / host / sdhci.h
1 /*
2  *  linux/drivers/mmc/host/sdhci.h - Secure Digital Host Controller Interface driver
3  *
4  * Header file for Host Controller registers and I/O accessors.
5  *
6  *  Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
7  *  Copyright (c) 2011-2015, NVIDIA CORPORATION. All Rights Reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or (at
12  * your option) any later version.
13  */
14 #ifndef __SDHCI_HW_H
15 #define __SDHCI_HW_H
16
17 #include <linux/scatterlist.h>
18 #include <linux/compiler.h>
19 #include <linux/types.h>
20 #include <linux/io.h>
21
22 #include <linux/mmc/sdhci.h>
23
24 /*
25  * Controller registers
26  */
27
28 #define SDHCI_DMA_ADDRESS       0x00
29 #define SDHCI_ARGUMENT2         SDHCI_DMA_ADDRESS
30
31 #define SDHCI_BLOCK_SIZE        0x04
32 #define  SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz & 0xFFF))
33
34 #define SDHCI_BLOCK_COUNT       0x06
35
36 #define SDHCI_ARGUMENT          0x08
37
38 #define SDHCI_TRANSFER_MODE     0x0C
39 #define  SDHCI_TRNS_DMA         0x01
40 #define  SDHCI_TRNS_BLK_CNT_EN  0x02
41 #define  SDHCI_TRNS_AUTO_CMD12  0x04
42 #define  SDHCI_TRNS_AUTO_CMD23  0x08
43 #define  SDHCI_TRNS_READ        0x10
44 #define  SDHCI_TRNS_MULTI       0x20
45 #define  SDHCI_TRNS_RESP_TYPE   0x40
46 #define  SDHCI_TRNS_ERR_CHECK   0x80
47 #define  SDHCI_TRNS_RES_INT_DIS 0x100
48
49 #define SDHCI_COMMAND           0x0E
50 #define  SDHCI_CMD_RESP_MASK    0x03
51 #define  SDHCI_CMD_CRC          0x08
52 #define  SDHCI_CMD_INDEX        0x10
53 #define  SDHCI_CMD_DATA         0x20
54 #define  SDHCI_CMD_ABORTCMD     0xC0
55
56 #define  SDHCI_CMD_RESP_NONE    0x00
57 #define  SDHCI_CMD_RESP_LONG    0x01
58 #define  SDHCI_CMD_RESP_SHORT   0x02
59 #define  SDHCI_CMD_RESP_SHORT_BUSY 0x03
60
61 #define SDHCI_MAKE_CMD(c, f) (((c & 0xff) << 8) | (f & 0xff))
62 #define SDHCI_GET_CMD(c) ((c>>8) & 0x3f)
63
64 #define SDHCI_RESPONSE          0x10
65
66 #define SDHCI_BUFFER            0x20
67
68 #define SDHCI_PRESENT_STATE     0x24
69 #define  SDHCI_CMD_INHIBIT      0x00000001
70 #define  SDHCI_DATA_INHIBIT     0x00000002
71 #define  SDHCI_RETUNING_REQUIRED        0x00000008
72 #define  SDHCI_DATA_7_4_LVL     0x00000010
73 #define   SDHCI_DATA_7_4_LVL_SHIFT      4
74 #define  SDHCI_DOING_WRITE      0x00000100
75 #define  SDHCI_DOING_READ       0x00000200
76 #define  SDHCI_SPACE_AVAILABLE  0x00000400
77 #define  SDHCI_DATA_AVAILABLE   0x00000800
78 #define  SDHCI_CARD_PRESENT     0x00010000
79 #define  SDHCI_WRITE_PROTECT    0x00080000
80 #define  SDHCI_DATA_LVL_MASK    0x00F00000
81 #define   SDHCI_DATA_LVL_SHIFT  20
82 #define  SDHCI_IN_DORMANT_STATE 0x20000000
83 #define  SDHCI_UHS2_LANE_SYNC_PHY_INITIALIZED   0x40000000
84 #define  SDHCI_UHS2_IF_DETECTED 0x80000000
85
86
87 #define SDHCI_HOST_CONTROL      0x28
88 #define  SDHCI_CTRL_LED         0x01
89 #define  SDHCI_CTRL_4BITBUS     0x02
90 #define  SDHCI_CTRL_HISPD       0x04
91 #define  SDHCI_CTRL_DMA_MASK    0x18
92 #define   SDHCI_CTRL_SDMA       0x00
93 #define   SDHCI_CTRL_RSVD       0x08
94 #define   SDHCI_CTRL_ADMA2      0x10
95 #define   SDHCI_CTRL_ADMA3      0x18
96 #define   SDHCI_CTRL_8BITBUS    0x20
97 #define   SDHCI_CTRL_SD_BUS_POWER_ON    0x00000100
98 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_SELECT_SHIFT        9
99 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_SELECT_MASK 0x00000E00
100 #define   SDHCI_CTRL_SD_BUS_POWER_ON_VDD2       0x00001000
101 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_SELECT_VDD2_SHIFT   13
102 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_SELECT_VDD2_MASK    0x0000E000
103 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_V1_8        5
104 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_V3_0        6
105 #define   SDHCI_CTRL_SD_BUS_VOLTAGE_V3_3        7
106
107 #define SDHCI_POWER_CONTROL     0x29
108 #define  SDHCI_POWER_ON         0x01
109 #define  SDHCI_POWER_180        0x0A
110 #define  SDHCI_POWER_300        0x0C
111 #define  SDHCI_POWER_330        0x0E
112
113 #define SDHCI_BLOCK_GAP_CONTROL 0x2A
114
115 #define SDHCI_WAKE_UP_CONTROL   0x2B
116 #define  SDHCI_WAKE_ON_INT      0x01
117 #define  SDHCI_WAKE_ON_INSERT   0x02
118 #define  SDHCI_WAKE_ON_REMOVE   0x04
119
120 #define SDHCI_CLOCK_CONTROL     0x2C
121 #define  SDHCI_DIVIDER_SHIFT    8
122 #define  SDHCI_DIVIDER_HI_SHIFT 6
123 #define  SDHCI_DIV_MASK 0xFF
124 #define  SDHCI_DIV_MASK_LEN     8
125 #define  SDHCI_DIV_HI_MASK      0x300
126 #define  SDHCI_UPPER_SDCLK_FREQUENCYSELECT_MASK 0x00C0
127 #define  SDHCI_PROG_CLOCK_MODE  0x0020
128 #define  SDHCI_CLOCK_CARD_EN    0x0004
129 #define  SDHCI_CLOCK_INT_STABLE 0x0002
130 #define  SDHCI_CLOCK_INT_EN     0x0001
131
132 #define SDHCI_TIMEOUT_CONTROL   0x2E
133
134 #define SDHCI_SOFTWARE_RESET    0x2F
135 #define  SDHCI_RESET_ALL        0x01
136 #define  SDHCI_RESET_CMD        0x02
137 #define  SDHCI_RESET_DATA       0x04
138
139 #define SDHCI_INT_STATUS        0x30
140 #define SDHCI_INT_ENABLE        0x34
141 #define SDHCI_SIGNAL_ENABLE     0x38
142 #define  SDHCI_INT_RESPONSE     0x00000001
143 #define  SDHCI_INT_DATA_END     0x00000002
144 #define  SDHCI_INT_BLK_GAP      0x00000004
145 #define  SDHCI_INT_DMA_END      0x00000008
146 #define  SDHCI_INT_SPACE_AVAIL  0x00000010
147 #define  SDHCI_INT_DATA_AVAIL   0x00000020
148 #define  SDHCI_INT_CARD_INSERT  0x00000040
149 #define  SDHCI_INT_CARD_REMOVE  0x00000080
150 #define  SDHCI_INT_RETUNING_EVENT       0x00001000
151 #define  SDHCI_INT_CARD_INT     0x00000100
152 #define  SDHCI_INT_ERROR        0x00008000
153 #define  SDHCI_INT_TIMEOUT      0x00010000
154 #define  SDHCI_INT_CRC          0x00020000
155 #define  SDHCI_INT_END_BIT      0x00040000
156 #define  SDHCI_INT_INDEX        0x00080000
157 #define  SDHCI_INT_DATA_TIMEOUT 0x00100000
158 #define  SDHCI_INT_DATA_CRC     0x00200000
159 #define  SDHCI_INT_DATA_END_BIT 0x00400000
160 #define  SDHCI_INT_BUS_POWER    0x00800000
161 #define  SDHCI_INT_ACMD12ERR    0x01000000
162 #define  SDHCI_INT_ADMA_ERROR   0x02000000
163 #define  SDHCI_INT_TUNING_ERROR 0x04000000
164 #define  SDHCI_INT_RESP_ERROR   0x08000000
165 #define  SDHCI_INT_SPI_ERROR    0x20000000
166
167 #define  SDHCI_INT_NORMAL_MASK  0x00007FFF
168 #define  SDHCI_INT_ERROR_MASK   0xFFFF8000
169
170 #define  SDHCI_INT_CMD_MASK     (SDHCI_INT_RESPONSE | SDHCI_INT_TIMEOUT | \
171                 SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX)
172 #define  SDHCI_INT_DATA_MASK    (SDHCI_INT_DATA_END | SDHCI_INT_DMA_END | \
173                 SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | \
174                 SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | \
175                 SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | \
176                 SDHCI_INT_BLK_GAP)
177 #define SDHCI_INT_ALL_MASK      ((unsigned int)-1)
178
179 #define SDHCI_ACMD12_ERR        0x3C
180 #define  SDHCI_NOT_EXECUTED     0x00000001
181 #define  SDHCI_TIMEOUT_ERR      0x00000002
182 #define  SDHCI_CRC_ERR  0x00000004
183 #define  SDHCI_END_BIT_ERR      0x00000008
184 #define  SDHCI_INDEX_ERR        0x00000010
185 #define  SDHCI_COMMAND_NOT_ISSUED       0x0080
186 #define  SDHCI_UHS_MODE_SEL_SHIFT       16
187 #define  SDHCI_UHS_MODE_SEL_MASK        000x0700
188 #define  SDHCI_UHS_SDR12        0
189 #define  SDHCI_UHS_SDR25        1
190 #define  SDHCI_UHS_SDR50        2
191 #define  SDHCI_UHS_SDR104       3
192 #define  SDHCI_UHS_DDR50        4
193 #define  SDHCI_UHS2     7
194 #define  SDHCI_VOLT_18_EN       0x00080000
195 #define  SDHCI_EXECUTE_TUNING   0x00400000
196 #define  SDHCI_SAMPLING_CLK_TUNED       0x00800000
197 #define  SDHCI_UHS2_IF_EN       0x01000000
198 #define  SDHCI_HOST_VERSION_4_EN        0x10000000
199 #define  SDHCI_ADDRESSING_64BIT_EN      0x20000000
200 #define  SDHCI_ASYNC_INTR_EN    0x40000000
201 #define  SDHCI_PRESET_VALUE_SW_SEL      0x80000000
202
203 #define SDHCI_HOST_CONTROL2             0x3E
204 #define  SDHCI_CTRL_UHS_MASK            0x0007
205 #define   SDHCI_CTRL_UHS_SDR12          0x0000
206 #define   SDHCI_CTRL_UHS_SDR25          0x0001
207 #define   SDHCI_CTRL_UHS_SDR50          0x0002
208 #define   SDHCI_CTRL_UHS_SDR104         0x0003
209 #define   SDHCI_CTRL_UHS_DDR50          0x0004
210 #define   SDHCI_CTRL_UHS_HS400          0x0005
211 #define   SDHCI_CTRL_HS_SDR200          0x0006 /* reserved value in SDIO spec */
212 #define  SDHCI_CTRL_VDD_180             0x0008
213 #define  SDHCI_CTRL_DRV_TYPE_MASK       0x0030
214 #define   SDHCI_CTRL_DRV_TYPE_B         0x0000
215 #define   SDHCI_CTRL_DRV_TYPE_A         0x0010
216 #define   SDHCI_CTRL_DRV_TYPE_C         0x0020
217 #define   SDHCI_CTRL_DRV_TYPE_D         0x0030
218 #define  SDHCI_CTRL_EXEC_TUNING         0x0040
219 #define  SDHCI_CTRL_TUNED_CLK           0x0080
220 #define  SDHCI_CTRL_PRESET_VAL_ENABLE   0x8000
221
222 #define SDHCI_CAPABILITIES      0x40
223 #define  SDHCI_TIMEOUT_CLK_MASK 0x0000003F
224 #define  SDHCI_TIMEOUT_CLK_SHIFT 0
225 #define  SDHCI_TIMEOUT_CLK_UNIT 0x00000080
226 #define  SDHCI_CLOCK_BASE_MASK  0x0000FF00
227 #define  SDHCI_CLOCK_V3_BASE_MASK       0x0000FF00
228 #define  SDHCI_CLOCK_BASE_SHIFT 8
229 #define  SDHCI_MAX_BLOCK_MASK   0x00030000
230 #define  SDHCI_MAX_BLOCK_SHIFT  16
231 #define  SDHCI_CAN_DO_8BIT      0x00040000
232 #define  SDHCI_CAN_DO_ADMA2     0x00080000
233 #define  SDHCI_CAN_DO_HISPD     0x00200000
234 #define  SDHCI_CAN_DO_SDMA      0x00400000
235 #define  SDHCI_CAN_VDD_330      0x01000000
236 #define  SDHCI_CAN_VDD_300      0x02000000
237 #define  SDHCI_CAN_VDD_180      0x04000000
238 #define  SDHCI_CAN_64BIT        0x10000000
239 #define  SDHCI_CAN_ASYNC_INTR   0x20000000
240 #define  SDHCI_CAN_SLOT_TYPE    0x40000000
241
242 #define SDHCI_CAPABILITIES_1    0x44
243 #define  SDHCI_SUPPORT_SDR50    0x00000001
244 #define  SDHCI_SUPPORT_SDR104   0x00000002
245 #define  SDHCI_SUPPORT_DDR50    0x00000004
246 #define  SDHCI_SUPPORT_UHS2     0x00000008
247 #define  SDHCI_DRIVER_TYPE_A    0x00000010
248 #define  SDHCI_DRIVER_TYPE_C    0x00000020
249 #define  SDHCI_DRIVER_TYPE_D    0x00000040
250 #define  SDHCI_RETUNING_TIMER_COUNT_MASK        0x00000F00
251 #define  SDHCI_RETUNING_TIMER_COUNT_SHIFT       8
252 #define  SDHCI_USE_SDR50_TUNING                 0x00002000
253 #define  SDHCI_RETUNING_MODE_MASK               0x0000C000
254 #define  SDHCI_RETUNING_MODE_SHIFT              14
255 #define  SDHCI_CLOCK_MUL_MASK   0x00FF0000
256 #define  SDHCI_CLOCK_MUL_SHIFT  16
257 #define  SDHCI_SUPPORT_ADMA3    0x08000000
258 #define  SDHCI_SUPPORT_VDD2_1_8V        0x10000000
259
260 #define SDHCI_MAX_CURRENT               0x48
261 #define  SDHCI_MAX_CURRENT_LIMIT        0xFF
262 #define  SDHCI_MAX_CURRENT_330_MASK     0x0000FF
263 #define  SDHCI_MAX_CURRENT_330_SHIFT    0
264 #define  SDHCI_MAX_CURRENT_300_MASK     0x00FF00
265 #define  SDHCI_MAX_CURRENT_300_SHIFT    8
266 #define  SDHCI_MAX_CURRENT_180_MASK     0xFF0000
267 #define  SDHCI_MAX_CURRENT_180_SHIFT    16
268 #define   SDHCI_MAX_CURRENT_MULTIPLIER  4
269
270 /* 4C-4F reserved for more max current */
271
272 #define SDHCI_SET_ACMD12_ERROR  0x50
273 #define SDHCI_SET_INT_ERROR     0x52
274
275 #define SDHCI_ADMA_ERROR        0x54
276
277 /* 55-57 reserved */
278
279 #define SDHCI_ADMA_ADDRESS      0x58
280 #define SDHCI_UPPER_ADMA_ADDRESS        0x5C
281
282 #define SDHCI_PRESET_DEFAULT_AND_INIT   0x60
283 #define SDHCI_PRESET_SDR12_AND_HIGH     0x64
284 #define SDHCI_PRESET_SDR50_AND_SDR25    0x68
285 #define SDHCI_PRESET_DDR50_AND_SDR104   0x6C
286 #define SDHCI_PRESET_DDR50_AND_SDR104   0x6C
287 #define  SDHCI_SDCLK_FREQ_VAL_LOW_SHIFT 0
288 #define  SDHCI_SDCLK_FREQ_VAL_LOW_MASK  0x000003FF
289 #define  SDHCI_SDCLK_FREQ_VAL_HIGH_SHIFT        16
290 #define  SDHCI_SDCLK_FREQ_VAL_HIGH_MASK 0x03FF0000
291 #define  SDHCI_CLK_GEN_VAL_LOW_SHIFT    10
292 #define  SDHCI_CLK_GEN_VAL_LOW_MASK     0x00000400
293 #define  SDHCI_CLK_GEN_VAL_HIGH_SHIFT   26
294 #define  SDHCI_CLK_GEN_VAL_HIGH_MASK    0x04000000
295 #define  SDHCI_DRIVE_STRENGTH_VAL_LOW_SHIFT     14
296 #define  SDHCI_DRIVE_STRENGTH_VAL_LOW_MASK      0x0000C000
297 #define  SDHCI_DRIVE_STRENGTH_VAL_HIGH_SHIFT    30
298 #define  SDHCI_DRIVE_STRENGTH_VAL_HIGH_MASK     0xC0000000
299
300 #define SDHCI_PRESET_FOR_SDR12 0x66
301 #define SDHCI_PRESET_FOR_SDR25 0x68
302 #define SDHCI_PRESET_FOR_SDR50 0x6A
303 #define SDHCI_PRESET_FOR_SDR104        0x6C
304 #define SDHCI_PRESET_FOR_DDR50 0x6E
305 #define SDHCI_PRESET_DRV_MASK  0xC000
306 #define SDHCI_PRESET_DRV_SHIFT  14
307 #define SDHCI_PRESET_CLKGEN_SEL_MASK   0x400
308 #define SDHCI_PRESET_CLKGEN_SEL_SHIFT   10
309 #define SDHCI_PRESET_SDCLK_FREQ_MASK   0x3FF
310 #define SDHCI_PRESET_SDCLK_FREQ_SHIFT   0
311
312 #define SDHCI_SLOT_INT_STATUS   0xFC
313
314 #define SDHCI_HOST_VERSION      0xFE
315 #define  SDHCI_VENDOR_VER_MASK  0xFF00
316 #define  SDHCI_VENDOR_VER_SHIFT 8
317 #define  SDHCI_SPEC_VER_MASK    0x00FF
318 #define  SDHCI_SPEC_VER_SHIFT   0
319 #define   SDHCI_SPEC_100        0
320 #define   SDHCI_SPEC_200        1
321 #define   SDHCI_SPEC_300        2
322 #define   SDHCI_SPEC_400        3
323
324 /*
325  * End of controller registers.
326  */
327
328 #define SDHCI_MAX_DIV_SPEC_200  256
329 #define SDHCI_MAX_DIV_SPEC_300  2046
330
331 /* Time (in milli sec) interval to run auto calibration */
332 #define SDHCI_PERIODIC_CALIB_TIMEOUT    100
333
334 /*
335  * Host SDMA buffer boundary. Valid values from 4K to 512K in powers of 2.
336  */
337 #define SDHCI_DEFAULT_BOUNDARY_SIZE  (512 * 1024)
338 #define SDHCI_DEFAULT_BOUNDARY_ARG   (ilog2(SDHCI_DEFAULT_BOUNDARY_SIZE) - 12)
339
340 struct sdhci_ops {
341 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
342         u32             (*read_l)(struct sdhci_host *host, int reg);
343         u16             (*read_w)(struct sdhci_host *host, int reg);
344         u8              (*read_b)(struct sdhci_host *host, int reg);
345         void            (*write_l)(struct sdhci_host *host, u32 val, int reg);
346         void            (*write_w)(struct sdhci_host *host, u16 val, int reg);
347         void            (*write_b)(struct sdhci_host *host, u8 val, int reg);
348 #endif
349
350         void    (*set_clock)(struct sdhci_host *host, unsigned int clock);
351
352         int             (*enable_dma)(struct sdhci_host *host);
353         unsigned int    (*get_max_clock)(struct sdhci_host *host);
354         unsigned int    (*get_min_clock)(struct sdhci_host *host);
355         unsigned int    (*get_timeout_clock)(struct sdhci_host *host);
356         int             (*platform_bus_width)(struct sdhci_host *host,
357                                                int width);
358         void (*platform_send_init_74_clocks)(struct sdhci_host *host,
359                                              u8 power_mode);
360         unsigned int    (*get_ro)(struct sdhci_host *host);
361         unsigned int    (*get_cd)(struct sdhci_host *host);
362         void    (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
363         void    (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
364         int     (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
365         void    (*hw_reset)(struct sdhci_host *host);
366         void    (*platform_suspend)(struct sdhci_host *host);
367         void    (*platform_resume)(struct sdhci_host *host);
368         void    (*adma_workaround)(struct sdhci_host *host, u32 intmask);
369         void    (*platform_init)(struct sdhci_host *host);
370         void    (*platform_get_bus)(struct sdhci_host *host);
371         void    (*platform_ios_config_enter)(struct sdhci_host *host,
372                 struct mmc_ios *ios);
373         void    (*platform_ios_config_exit)(struct sdhci_host *host,
374                 struct mmc_ios *ios);
375         int     (*switch_signal_voltage)(struct sdhci_host *host,
376                                 unsigned int signal_voltage);
377         void    (*switch_signal_voltage_exit)(struct sdhci_host *host,
378                                 unsigned char signal_voltage);
379         int     (*suspend)(struct sdhci_host *host);
380         int     (*resume)(struct sdhci_host *host);
381         int     (*execute_freq_tuning)(struct sdhci_host *sdhci, u32 opcode);
382         int     (*get_tuning_counter)(struct sdhci_host *sdhci);
383         int     (*sd_error_stats)(struct sdhci_host *host, u32 int_status);
384         int     (*dfs_gov_init)(struct sdhci_host *host);
385         void    (*dfs_gov_exit)(struct sdhci_host *host);
386         unsigned long   (*dfs_gov_get_target_freq)(struct sdhci_host *host,
387                 struct devfreq_dev_status *dev_status);
388         int     (*get_drive_strength)(struct sdhci_host *host,
389                 unsigned int max_dtr, int host_drv, int card_drv);
390         void    (*post_init)(struct sdhci_host *host);
391         void    (*dump_host_cust_regs)(struct sdhci_host *host);
392         int     (*get_max_tuning_loop_counter)(struct sdhci_host *sdhci);
393         void    (*config_tap_delay)(struct sdhci_host *host, u8 option);
394         bool    (*is_tuning_done)(struct sdhci_host *sdhci);
395         int     (*validate_sd2_0)(struct sdhci_host *sdhci);
396         void    (*get_max_pio_transfer_limits)(struct sdhci_host *sdhci);
397 };
398
399 static inline void sdhci_check_host_clock(struct sdhci_host *host)
400 {
401         if (!host->is_clk_on) {
402                 if (host->ops->set_clock) {
403                         if (host->mmc->ios.clock) {
404                                 host->ops->set_clock(host,
405                                         host->mmc->ios.clock);
406                         } else {
407                                 host->ops->set_clock(host, 400000);
408                         }
409                 }
410         }
411 }
412
413 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
414
415 static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
416 {
417         sdhci_check_host_clock(host);
418         if (unlikely(host->ops->write_l))
419                 host->ops->write_l(host, val, reg);
420         else
421                 writel(val, host->ioaddr + reg);
422 }
423
424 static inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg)
425 {
426         sdhci_check_host_clock(host);
427         if (unlikely(host->ops->write_w))
428                 host->ops->write_w(host, val, reg);
429         else
430                 writew(val, host->ioaddr + reg);
431 }
432
433 static inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
434 {
435         sdhci_check_host_clock(host);
436         if (unlikely(host->ops->write_b))
437                 host->ops->write_b(host, val, reg);
438         else
439                 writeb(val, host->ioaddr + reg);
440 }
441
442 static inline u32 sdhci_readl(struct sdhci_host *host, int reg)
443 {
444         sdhci_check_host_clock(host);
445         if (unlikely(host->ops->read_l))
446                 return host->ops->read_l(host, reg);
447         else
448                 return readl(host->ioaddr + reg);
449 }
450
451 static inline u16 sdhci_readw(struct sdhci_host *host, int reg)
452 {
453         sdhci_check_host_clock(host);
454         if (unlikely(host->ops->read_w))
455                 return host->ops->read_w(host, reg);
456         else
457                 return readw(host->ioaddr + reg);
458 }
459
460 static inline u8 sdhci_readb(struct sdhci_host *host, int reg)
461 {
462         sdhci_check_host_clock(host);
463         if (unlikely(host->ops->read_b))
464                 return host->ops->read_b(host, reg);
465         else
466                 return readb(host->ioaddr + reg);
467 }
468
469 #else
470
471 static inline void sdhci_writel(struct sdhci_host *host, u32 val, int reg)
472 {
473         sdhci_check_host_clock(host);
474         writel(val, host->ioaddr + reg);
475 }
476
477 static inline void sdhci_writew(struct sdhci_host *host, u16 val, int reg)
478 {
479         sdhci_check_host_clock(host);
480         writew(val, host->ioaddr + reg);
481 }
482
483 static inline void sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
484 {
485         sdhci_check_host_clock(host);
486         writeb(val, host->ioaddr + reg);
487 }
488
489 static inline u32 sdhci_readl(struct sdhci_host *host, int reg)
490 {
491         sdhci_check_host_clock(host);
492         return readl(host->ioaddr + reg);
493 }
494
495 static inline u16 sdhci_readw(struct sdhci_host *host, int reg)
496 {
497         sdhci_check_host_clock(host);
498         return readw(host->ioaddr + reg);
499 }
500
501 static inline u8 sdhci_readb(struct sdhci_host *host, int reg)
502 {
503         sdhci_check_host_clock(host);
504         return readb(host->ioaddr + reg);
505 }
506
507 #endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */
508
509 extern struct sdhci_host *sdhci_alloc_host(struct device *dev,
510         size_t priv_size);
511 extern void sdhci_free_host(struct sdhci_host *host);
512
513 static inline void *sdhci_priv(struct sdhci_host *host)
514 {
515         return (void *)host->private;
516 }
517
518 extern void sdhci_card_detect(struct sdhci_host *host);
519 extern int sdhci_add_host(struct sdhci_host *host);
520 extern void sdhci_runtime_forbid(struct sdhci_host *host);
521 extern void sdhci_remove_host(struct sdhci_host *host, int dead);
522
523 #ifdef CONFIG_PM
524 extern int sdhci_suspend_host(struct sdhci_host *host);
525 extern int sdhci_resume_host(struct sdhci_host *host);
526 extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
527 #endif
528
529 #ifdef CONFIG_PM_RUNTIME
530 extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
531 extern int sdhci_runtime_resume_host(struct sdhci_host *host);
532 #endif
533 extern struct task_struct *suspend_task;
534
535 #endif /* __SDHCI_HW_H */