ext4: fix undefined behavior in ext4_fill_flex_info()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mmc / host / tmio_mmc.h
blobee8fa89b2b57b2b194e8ae442eee12d8716e3141
1 /* Definitons for use with the tmio_mmc.c
3 * (c) 2004 Ian Molton <spyro@f2s.com>
4 * (c) 2007 Ian Molton <spyro@f2s.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/highmem.h>
14 #define CNF_CMD 0x04
15 #define CNF_CTL_BASE 0x10
16 #define CNF_INT_PIN 0x3d
17 #define CNF_STOP_CLK_CTL 0x40
18 #define CNF_GCLK_CTL 0x41
19 #define CNF_SD_CLK_MODE 0x42
20 #define CNF_PIN_STATUS 0x44
21 #define CNF_PWR_CTL_1 0x48
22 #define CNF_PWR_CTL_2 0x49
23 #define CNF_PWR_CTL_3 0x4a
24 #define CNF_CARD_DETECT_MODE 0x4c
25 #define CNF_SD_SLOT 0x50
26 #define CNF_EXT_GCLK_CTL_1 0xf0
27 #define CNF_EXT_GCLK_CTL_2 0xf1
28 #define CNF_EXT_GCLK_CTL_3 0xf9
29 #define CNF_SD_LED_EN_1 0xfa
30 #define CNF_SD_LED_EN_2 0xfe
32 #define SDCREN 0x2 /* Enable access to MMC CTL regs. (flag in COMMAND_REG)*/
34 #define CTL_SD_CMD 0x00
35 #define CTL_ARG_REG 0x04
36 #define CTL_STOP_INTERNAL_ACTION 0x08
37 #define CTL_XFER_BLK_COUNT 0xa
38 #define CTL_RESPONSE 0x0c
39 #define CTL_STATUS 0x1c
40 #define CTL_IRQ_MASK 0x20
41 #define CTL_SD_CARD_CLK_CTL 0x24
42 #define CTL_SD_XFER_LEN 0x26
43 #define CTL_SD_MEM_CARD_OPT 0x28
44 #define CTL_SD_ERROR_DETAIL_STATUS 0x2c
45 #define CTL_SD_DATA_PORT 0x30
46 #define CTL_TRANSACTION_CTL 0x34
47 #define CTL_RESET_SD 0xe0
48 #define CTL_SDIO_REGS 0x100
49 #define CTL_CLK_AND_WAIT_CTL 0x138
50 #define CTL_RESET_SDIO 0x1e0
52 /* Definitions for values the CTRL_STATUS register can take. */
53 #define TMIO_STAT_CMDRESPEND 0x00000001
54 #define TMIO_STAT_DATAEND 0x00000004
55 #define TMIO_STAT_CARD_REMOVE 0x00000008
56 #define TMIO_STAT_CARD_INSERT 0x00000010
57 #define TMIO_STAT_SIGSTATE 0x00000020
58 #define TMIO_STAT_WRPROTECT 0x00000080
59 #define TMIO_STAT_CARD_REMOVE_A 0x00000100
60 #define TMIO_STAT_CARD_INSERT_A 0x00000200
61 #define TMIO_STAT_SIGSTATE_A 0x00000400
62 #define TMIO_STAT_CMD_IDX_ERR 0x00010000
63 #define TMIO_STAT_CRCFAIL 0x00020000
64 #define TMIO_STAT_STOPBIT_ERR 0x00040000
65 #define TMIO_STAT_DATATIMEOUT 0x00080000
66 #define TMIO_STAT_RXOVERFLOW 0x00100000
67 #define TMIO_STAT_TXUNDERRUN 0x00200000
68 #define TMIO_STAT_CMDTIMEOUT 0x00400000
69 #define TMIO_STAT_RXRDY 0x01000000
70 #define TMIO_STAT_TXRQ 0x02000000
71 #define TMIO_STAT_ILL_FUNC 0x20000000
72 #define TMIO_STAT_CMD_BUSY 0x40000000
73 #define TMIO_STAT_ILL_ACCESS 0x80000000
75 /* Define some IRQ masks */
76 /* This is the mask used at reset by the chip */
77 #define TMIO_MASK_ALL 0x837f031d
78 #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND | \
79 TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
80 #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND | \
81 TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
82 #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
83 TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
84 #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
87 #define enable_mmc_irqs(host, i) \
88 do { \
89 u32 mask;\
90 mask = sd_ctrl_read32((host), CTL_IRQ_MASK); \
91 mask &= ~((i) & TMIO_MASK_IRQ); \
92 sd_ctrl_write32((host), CTL_IRQ_MASK, mask); \
93 } while (0)
95 #define disable_mmc_irqs(host, i) \
96 do { \
97 u32 mask;\
98 mask = sd_ctrl_read32((host), CTL_IRQ_MASK); \
99 mask |= ((i) & TMIO_MASK_IRQ); \
100 sd_ctrl_write32((host), CTL_IRQ_MASK, mask); \
101 } while (0)
103 #define ack_mmc_irqs(host, i) \
104 do { \
105 sd_ctrl_write32((host), CTL_STATUS, ~(i)); \
106 } while (0)
109 struct tmio_mmc_host {
110 void __iomem *cnf;
111 void __iomem *ctl;
112 unsigned long bus_shift;
113 struct mmc_command *cmd;
114 struct mmc_request *mrq;
115 struct mmc_data *data;
116 struct mmc_host *mmc;
117 int irq;
119 /* pio related stuff */
120 struct scatterlist *sg_ptr;
121 unsigned int sg_len;
122 unsigned int sg_off;
125 #include <linux/io.h>
127 static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
129 return readw(host->ctl + (addr << host->bus_shift));
132 static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
133 u16 *buf, int count)
135 readsw(host->ctl + (addr << host->bus_shift), buf, count);
138 static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
140 return readw(host->ctl + (addr << host->bus_shift)) |
141 readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
144 static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr,
145 u16 val)
147 writew(val, host->ctl + (addr << host->bus_shift));
150 static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
151 u16 *buf, int count)
153 writesw(host->ctl + (addr << host->bus_shift), buf, count);
156 static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr,
157 u32 val)
159 writew(val, host->ctl + (addr << host->bus_shift));
160 writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
163 static inline void sd_config_write8(struct tmio_mmc_host *host, int addr,
164 u8 val)
166 writeb(val, host->cnf + (addr << host->bus_shift));
169 static inline void sd_config_write16(struct tmio_mmc_host *host, int addr,
170 u16 val)
172 writew(val, host->cnf + (addr << host->bus_shift));
175 static inline void sd_config_write32(struct tmio_mmc_host *host, int addr,
176 u32 val)
178 writew(val, host->cnf + (addr << host->bus_shift));
179 writew(val >> 16, host->cnf + ((addr + 2) << host->bus_shift));
182 #include <linux/scatterlist.h>
183 #include <linux/blkdev.h>
185 static inline void tmio_mmc_init_sg(struct tmio_mmc_host *host,
186 struct mmc_data *data)
188 host->sg_len = data->sg_len;
189 host->sg_ptr = data->sg;
190 host->sg_off = 0;
193 static inline int tmio_mmc_next_sg(struct tmio_mmc_host *host)
195 host->sg_ptr = sg_next(host->sg_ptr);
196 host->sg_off = 0;
197 return --host->sg_len;
200 static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
201 unsigned long *flags)
203 local_irq_save(*flags);
204 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
207 static inline void tmio_mmc_kunmap_atomic(void *virt,
208 unsigned long *flags)
210 kunmap_atomic(virt, KM_BIO_SRC_IRQ);
211 local_irq_restore(*flags);
214 #ifdef CONFIG_MMC_DEBUG
216 #define STATUS_TO_TEXT(a) \
217 do { \
218 if (status & TMIO_STAT_##a) \
219 printk(#a); \
220 } while (0)
222 void pr_debug_status(u32 status)
224 printk(KERN_DEBUG "status: %08x = ", status);
225 STATUS_TO_TEXT(CARD_REMOVE);
226 STATUS_TO_TEXT(CARD_INSERT);
227 STATUS_TO_TEXT(SIGSTATE);
228 STATUS_TO_TEXT(WRPROTECT);
229 STATUS_TO_TEXT(CARD_REMOVE_A);
230 STATUS_TO_TEXT(CARD_INSERT_A);
231 STATUS_TO_TEXT(SIGSTATE_A);
232 STATUS_TO_TEXT(CMD_IDX_ERR);
233 STATUS_TO_TEXT(STOPBIT_ERR);
234 STATUS_TO_TEXT(ILL_FUNC);
235 STATUS_TO_TEXT(CMD_BUSY);
236 STATUS_TO_TEXT(CMDRESPEND);
237 STATUS_TO_TEXT(DATAEND);
238 STATUS_TO_TEXT(CRCFAIL);
239 STATUS_TO_TEXT(DATATIMEOUT);
240 STATUS_TO_TEXT(CMDTIMEOUT);
241 STATUS_TO_TEXT(RXOVERFLOW);
242 STATUS_TO_TEXT(TXUNDERRUN);
243 STATUS_TO_TEXT(RXRDY);
244 STATUS_TO_TEXT(TXRQ);
245 STATUS_TO_TEXT(ILL_ACCESS);
246 printk("\n");
249 #else
250 #define pr_debug_status(s) do { } while (0)
251 #endif