Commit | Line | Data |
---|---|---|
b6147490 GL |
1 | /* |
2 | * linux/drivers/mmc/host/tmio_mmc.h | |
3 | * | |
4 | * Copyright (C) 2007 Ian Molton | |
5 | * Copyright (C) 2004 Ian Molton | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * Driver for the MMC / SD / SDIO cell found in: | |
12 | * | |
13 | * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3 | |
14 | */ | |
15 | ||
16 | #ifndef TMIO_MMC_H | |
17 | #define TMIO_MMC_H | |
18 | ||
361936ef | 19 | #include <linux/dmaengine.h> |
b6147490 | 20 | #include <linux/highmem.h> |
cba179ae | 21 | #include <linux/mmc/tmio.h> |
b9269fdd | 22 | #include <linux/mutex.h> |
b6147490 | 23 | #include <linux/pagemap.h> |
6c0cbef6 | 24 | #include <linux/scatterlist.h> |
e3de2be7 | 25 | #include <linux/spinlock.h> |
b6147490 | 26 | |
b6147490 | 27 | /* Definitions for values the CTRL_SDIO_STATUS register can take. */ |
cba179ae | 28 | #define TMIO_SDIO_STAT_IOIRQ 0x0001 |
b6147490 | 29 | #define TMIO_SDIO_STAT_EXPUB52 0x4000 |
cba179ae SH |
30 | #define TMIO_SDIO_STAT_EXWT 0x8000 |
31 | #define TMIO_SDIO_MASK_ALL 0xc007 | |
b6147490 GL |
32 | |
33 | /* Define some IRQ masks */ | |
34 | /* This is the mask used at reset by the chip */ | |
35 | #define TMIO_MASK_ALL 0x837f031d | |
36 | #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND) | |
37 | #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND) | |
38 | #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \ | |
39 | TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT) | |
40 | #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD) | |
41 | ||
42 | struct tmio_mmc_data; | |
5add2aca | 43 | struct tmio_mmc_host; |
b6147490 | 44 | |
7ecc09ba | 45 | struct tmio_mmc_dma { |
361936ef | 46 | enum dma_slave_buswidth dma_buswidth; |
7ecc09ba | 47 | bool (*filter)(struct dma_chan *chan, void *arg); |
5add2aca | 48 | void (*enable)(struct tmio_mmc_host *host, bool enable); |
7ecc09ba KM |
49 | }; |
50 | ||
b6147490 GL |
51 | struct tmio_mmc_host { |
52 | void __iomem *ctl; | |
b6147490 GL |
53 | struct mmc_command *cmd; |
54 | struct mmc_request *mrq; | |
55 | struct mmc_data *data; | |
56 | struct mmc_host *mmc; | |
b6147490 GL |
57 | |
58 | /* Callbacks for clock / power control */ | |
59 | void (*set_pwr)(struct platform_device *host, int state); | |
60 | void (*set_clk_div)(struct platform_device *host, int state); | |
61 | ||
62 | /* pio related stuff */ | |
63 | struct scatterlist *sg_ptr; | |
64 | struct scatterlist *sg_orig; | |
65 | unsigned int sg_len; | |
66 | unsigned int sg_off; | |
7445bf9e | 67 | unsigned long bus_shift; |
b6147490 GL |
68 | |
69 | struct platform_device *pdev; | |
70 | struct tmio_mmc_data *pdata; | |
7ecc09ba | 71 | struct tmio_mmc_dma *dma; |
b6147490 GL |
72 | |
73 | /* DMA support */ | |
74 | bool force_pio; | |
75 | struct dma_chan *chan_rx; | |
76 | struct dma_chan *chan_tx; | |
77 | struct tasklet_struct dma_complete; | |
78 | struct tasklet_struct dma_issue; | |
79 | struct scatterlist bounce_sg; | |
80 | u8 *bounce_buf; | |
81 | ||
82 | /* Track lost interrupts */ | |
83 | struct delayed_work delayed_reset_work; | |
b9269fdd GL |
84 | struct work_struct done; |
85 | ||
ae12d250 | 86 | /* Cache */ |
54680fe7 SH |
87 | u32 sdcard_irq_mask; |
88 | u32 sdio_irq_mask; | |
ae12d250 | 89 | unsigned int clk_cache; |
54680fe7 | 90 | |
b9269fdd | 91 | spinlock_t lock; /* protect host private data */ |
b6147490 | 92 | unsigned long last_req_ts; |
b9269fdd | 93 | struct mutex ios_lock; /* protect set_ios() context */ |
2b1ac5c2 | 94 | bool native_hotplug; |
7501c431 | 95 | bool sdio_irq_enabled; |
dfe9a229 KM |
96 | |
97 | int (*write16_hook)(struct tmio_mmc_host *host, int addr); | |
0ea28210 | 98 | int (*clk_enable)(struct tmio_mmc_host *host); |
2fb55956 BH |
99 | unsigned int (*clk_update)(struct tmio_mmc_host *host, |
100 | unsigned int new_clock); | |
0ea28210 | 101 | void (*clk_disable)(struct tmio_mmc_host *host); |
85c02ddd KM |
102 | int (*multi_io_quirk)(struct mmc_card *card, |
103 | unsigned int direction, int blk_size); | |
b6147490 GL |
104 | }; |
105 | ||
94b110af KM |
106 | struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev); |
107 | void tmio_mmc_host_free(struct tmio_mmc_host *host); | |
108 | int tmio_mmc_host_probe(struct tmio_mmc_host *host, | |
b6147490 GL |
109 | struct tmio_mmc_data *pdata); |
110 | void tmio_mmc_host_remove(struct tmio_mmc_host *host); | |
111 | void tmio_mmc_do_data_irq(struct tmio_mmc_host *host); | |
112 | ||
113 | void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i); | |
114 | void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i); | |
8e7bfdb3 | 115 | irqreturn_t tmio_mmc_irq(int irq, void *devid); |
7729c7a2 SH |
116 | irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid); |
117 | irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid); | |
118 | irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid); | |
b6147490 GL |
119 | |
120 | static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg, | |
121 | unsigned long *flags) | |
122 | { | |
123 | local_irq_save(*flags); | |
482fce99 | 124 | return kmap_atomic(sg_page(sg)) + sg->offset; |
b6147490 GL |
125 | } |
126 | ||
127 | static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg, | |
128 | unsigned long *flags, void *virt) | |
129 | { | |
482fce99 | 130 | kunmap_atomic(virt - sg->offset); |
b6147490 GL |
131 | local_irq_restore(*flags); |
132 | } | |
133 | ||
42051e8a | 134 | #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE) |
b6147490 | 135 | void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data); |
162f43e3 | 136 | void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable); |
b6147490 GL |
137 | void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata); |
138 | void tmio_mmc_release_dma(struct tmio_mmc_host *host); | |
e3de2be7 | 139 | void tmio_mmc_abort_dma(struct tmio_mmc_host *host); |
b6147490 GL |
140 | #else |
141 | static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host, | |
142 | struct mmc_data *data) | |
143 | { | |
144 | } | |
145 | ||
162f43e3 GL |
146 | static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable) |
147 | { | |
148 | } | |
149 | ||
b6147490 GL |
150 | static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host, |
151 | struct tmio_mmc_data *pdata) | |
152 | { | |
153 | host->chan_tx = NULL; | |
154 | host->chan_rx = NULL; | |
155 | } | |
156 | ||
157 | static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host) | |
158 | { | |
159 | } | |
e3de2be7 GL |
160 | |
161 | static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host) | |
162 | { | |
163 | } | |
b6147490 GL |
164 | #endif |
165 | ||
9ade7dbf | 166 | #ifdef CONFIG_PM |
7311bef0 GL |
167 | int tmio_mmc_host_runtime_suspend(struct device *dev); |
168 | int tmio_mmc_host_runtime_resume(struct device *dev); | |
710dec95 | 169 | #endif |
7311bef0 | 170 | |
a11862d3 SH |
171 | static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr) |
172 | { | |
7445bf9e | 173 | return readw(host->ctl + (addr << host->bus_shift)); |
a11862d3 SH |
174 | } |
175 | ||
176 | static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr, | |
177 | u16 *buf, int count) | |
178 | { | |
7445bf9e | 179 | readsw(host->ctl + (addr << host->bus_shift), buf, count); |
a11862d3 SH |
180 | } |
181 | ||
182 | static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr) | |
183 | { | |
7445bf9e KM |
184 | return readw(host->ctl + (addr << host->bus_shift)) | |
185 | readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16; | |
a11862d3 SH |
186 | } |
187 | ||
188 | static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val) | |
189 | { | |
973ed3af SH |
190 | /* If there is a hook and it returns non-zero then there |
191 | * is an error and the write should be skipped | |
192 | */ | |
dfe9a229 | 193 | if (host->write16_hook && host->write16_hook(host, addr)) |
973ed3af | 194 | return; |
7445bf9e | 195 | writew(val, host->ctl + (addr << host->bus_shift)); |
a11862d3 SH |
196 | } |
197 | ||
198 | static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr, | |
199 | u16 *buf, int count) | |
200 | { | |
7445bf9e | 201 | writesw(host->ctl + (addr << host->bus_shift), buf, count); |
a11862d3 SH |
202 | } |
203 | ||
204 | static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val) | |
205 | { | |
7445bf9e KM |
206 | writew(val, host->ctl + (addr << host->bus_shift)); |
207 | writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift)); | |
a11862d3 SH |
208 | } |
209 | ||
210 | ||
b6147490 | 211 | #endif |