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 | ||
19 | #include <linux/highmem.h> | |
cba179ae | 20 | #include <linux/mmc/tmio.h> |
b6147490 | 21 | #include <linux/pagemap.h> |
df3ef2d3 | 22 | #include <linux/spinlock.h> |
b6147490 | 23 | |
b6147490 | 24 | /* Definitions for values the CTRL_SDIO_STATUS register can take. */ |
cba179ae | 25 | #define TMIO_SDIO_STAT_IOIRQ 0x0001 |
b6147490 | 26 | #define TMIO_SDIO_STAT_EXPUB52 0x4000 |
cba179ae SH |
27 | #define TMIO_SDIO_STAT_EXWT 0x8000 |
28 | #define TMIO_SDIO_MASK_ALL 0xc007 | |
b6147490 GL |
29 | |
30 | /* Define some IRQ masks */ | |
31 | /* This is the mask used at reset by the chip */ | |
32 | #define TMIO_MASK_ALL 0x837f031d | |
33 | #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND) | |
34 | #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND) | |
35 | #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \ | |
36 | TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT) | |
37 | #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD) | |
38 | ||
39 | struct tmio_mmc_data; | |
40 | ||
41 | struct tmio_mmc_host { | |
42 | void __iomem *ctl; | |
43 | unsigned long bus_shift; | |
44 | struct mmc_command *cmd; | |
45 | struct mmc_request *mrq; | |
46 | struct mmc_data *data; | |
47 | struct mmc_host *mmc; | |
b6147490 GL |
48 | unsigned int sdio_irq_enabled; |
49 | ||
50 | /* Callbacks for clock / power control */ | |
51 | void (*set_pwr)(struct platform_device *host, int state); | |
52 | void (*set_clk_div)(struct platform_device *host, int state); | |
53 | ||
e6ee7182 GL |
54 | int pm_error; |
55 | ||
b6147490 GL |
56 | /* pio related stuff */ |
57 | struct scatterlist *sg_ptr; | |
58 | struct scatterlist *sg_orig; | |
59 | unsigned int sg_len; | |
60 | unsigned int sg_off; | |
61 | ||
62 | struct platform_device *pdev; | |
63 | struct tmio_mmc_data *pdata; | |
64 | ||
65 | /* DMA support */ | |
66 | bool force_pio; | |
67 | struct dma_chan *chan_rx; | |
68 | struct dma_chan *chan_tx; | |
69 | struct tasklet_struct dma_complete; | |
70 | struct tasklet_struct dma_issue; | |
71 | struct scatterlist bounce_sg; | |
72 | u8 *bounce_buf; | |
73 | ||
74 | /* Track lost interrupts */ | |
75 | struct delayed_work delayed_reset_work; | |
76 | spinlock_t lock; | |
77 | unsigned long last_req_ts; | |
78 | }; | |
79 | ||
80 | int tmio_mmc_host_probe(struct tmio_mmc_host **host, | |
81 | struct platform_device *pdev, | |
82 | struct tmio_mmc_data *pdata); | |
83 | void tmio_mmc_host_remove(struct tmio_mmc_host *host); | |
84 | void tmio_mmc_do_data_irq(struct tmio_mmc_host *host); | |
85 | ||
86 | void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i); | |
87 | void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i); | |
8e7bfdb3 | 88 | irqreturn_t tmio_mmc_irq(int irq, void *devid); |
b6147490 GL |
89 | |
90 | static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg, | |
91 | unsigned long *flags) | |
92 | { | |
93 | local_irq_save(*flags); | |
94 | return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; | |
95 | } | |
96 | ||
97 | static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg, | |
98 | unsigned long *flags, void *virt) | |
99 | { | |
100 | kunmap_atomic(virt - sg->offset, KM_BIO_SRC_IRQ); | |
101 | local_irq_restore(*flags); | |
102 | } | |
103 | ||
42051e8a | 104 | #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE) |
b6147490 GL |
105 | void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data); |
106 | void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata); | |
107 | void tmio_mmc_release_dma(struct tmio_mmc_host *host); | |
108 | #else | |
109 | static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host, | |
110 | struct mmc_data *data) | |
111 | { | |
112 | } | |
113 | ||
114 | static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host, | |
115 | struct tmio_mmc_data *pdata) | |
116 | { | |
117 | host->chan_tx = NULL; | |
118 | host->chan_rx = NULL; | |
119 | } | |
120 | ||
121 | static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host) | |
122 | { | |
123 | } | |
124 | #endif | |
125 | ||
e6ee7182 GL |
126 | #ifdef CONFIG_PM |
127 | int tmio_mmc_host_suspend(struct device *dev); | |
128 | int tmio_mmc_host_resume(struct device *dev); | |
129 | #else | |
130 | #define tmio_mmc_host_suspend NULL | |
131 | #define tmio_mmc_host_resume NULL | |
132 | #endif | |
133 | ||
7311bef0 GL |
134 | int tmio_mmc_host_runtime_suspend(struct device *dev); |
135 | int tmio_mmc_host_runtime_resume(struct device *dev); | |
136 | ||
a11862d3 SH |
137 | static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr) |
138 | { | |
139 | return readw(host->ctl + (addr << host->bus_shift)); | |
140 | } | |
141 | ||
142 | static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr, | |
143 | u16 *buf, int count) | |
144 | { | |
145 | readsw(host->ctl + (addr << host->bus_shift), buf, count); | |
146 | } | |
147 | ||
148 | static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr) | |
149 | { | |
150 | return readw(host->ctl + (addr << host->bus_shift)) | | |
151 | readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16; | |
152 | } | |
153 | ||
154 | static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val) | |
155 | { | |
973ed3af SH |
156 | /* If there is a hook and it returns non-zero then there |
157 | * is an error and the write should be skipped | |
158 | */ | |
159 | if (host->pdata->write16_hook && host->pdata->write16_hook(host, addr)) | |
160 | return; | |
a11862d3 SH |
161 | writew(val, host->ctl + (addr << host->bus_shift)); |
162 | } | |
163 | ||
164 | static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr, | |
165 | u16 *buf, int count) | |
166 | { | |
167 | writesw(host->ctl + (addr << host->bus_shift), buf, count); | |
168 | } | |
169 | ||
170 | static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val) | |
171 | { | |
172 | writew(val, host->ctl + (addr << host->bus_shift)); | |
173 | writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift)); | |
174 | } | |
175 | ||
176 | ||
b6147490 | 177 | #endif |