]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/mmc/host/tmio_mmc.h
mmc: tmio: add .enable_dma on tmio_mmc_dma
[mirror_ubuntu-hirsute-kernel.git] / drivers / mmc / host / tmio_mmc.h
CommitLineData
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>
b9269fdd 21#include <linux/mutex.h>
b6147490 22#include <linux/pagemap.h>
6c0cbef6 23#include <linux/scatterlist.h>
e3de2be7 24#include <linux/spinlock.h>
b6147490 25
b6147490 26/* Definitions for values the CTRL_SDIO_STATUS register can take. */
cba179ae 27#define TMIO_SDIO_STAT_IOIRQ 0x0001
b6147490 28#define TMIO_SDIO_STAT_EXPUB52 0x4000
cba179ae
SH
29#define TMIO_SDIO_STAT_EXWT 0x8000
30#define TMIO_SDIO_MASK_ALL 0xc007
b6147490
GL
31
32/* Define some IRQ masks */
33/* This is the mask used at reset by the chip */
34#define TMIO_MASK_ALL 0x837f031d
35#define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
36#define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
37#define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
38 TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
39#define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
40
41struct tmio_mmc_data;
5add2aca 42struct tmio_mmc_host;
b6147490 43
7ecc09ba
KM
44struct tmio_mmc_dma {
45 void *chan_priv_tx;
46 void *chan_priv_rx;
47 int slave_id_tx;
48 int slave_id_rx;
7ecc09ba 49 bool (*filter)(struct dma_chan *chan, void *arg);
5add2aca 50 void (*enable)(struct tmio_mmc_host *host, bool enable);
7ecc09ba
KM
51};
52
b6147490
GL
53struct tmio_mmc_host {
54 void __iomem *ctl;
b6147490
GL
55 struct mmc_command *cmd;
56 struct mmc_request *mrq;
57 struct mmc_data *data;
58 struct mmc_host *mmc;
b6147490
GL
59
60 /* Callbacks for clock / power control */
61 void (*set_pwr)(struct platform_device *host, int state);
62 void (*set_clk_div)(struct platform_device *host, int state);
63
64 /* pio related stuff */
65 struct scatterlist *sg_ptr;
66 struct scatterlist *sg_orig;
67 unsigned int sg_len;
68 unsigned int sg_off;
7445bf9e 69 unsigned long bus_shift;
b6147490
GL
70
71 struct platform_device *pdev;
72 struct tmio_mmc_data *pdata;
7ecc09ba 73 struct tmio_mmc_dma *dma;
b6147490
GL
74
75 /* DMA support */
76 bool force_pio;
77 struct dma_chan *chan_rx;
78 struct dma_chan *chan_tx;
79 struct tasklet_struct dma_complete;
80 struct tasklet_struct dma_issue;
81 struct scatterlist bounce_sg;
82 u8 *bounce_buf;
83
84 /* Track lost interrupts */
85 struct delayed_work delayed_reset_work;
b9269fdd
GL
86 struct work_struct done;
87
ae12d250 88 /* Cache */
54680fe7
SH
89 u32 sdcard_irq_mask;
90 u32 sdio_irq_mask;
ae12d250 91 unsigned int clk_cache;
54680fe7 92
b9269fdd 93 spinlock_t lock; /* protect host private data */
b6147490 94 unsigned long last_req_ts;
b9269fdd 95 struct mutex ios_lock; /* protect set_ios() context */
2b1ac5c2 96 bool native_hotplug;
7501c431 97 bool sdio_irq_enabled;
dfe9a229
KM
98
99 int (*write16_hook)(struct tmio_mmc_host *host, int addr);
4fe2ec57 100 int (*clk_enable)(struct platform_device *pdev, unsigned int *f);
00452c11 101 void (*clk_disable)(struct platform_device *pdev);
85c02ddd
KM
102 int (*multi_io_quirk)(struct mmc_card *card,
103 unsigned int direction, int blk_size);
b6147490
GL
104};
105
94b110af
KM
106struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev);
107void tmio_mmc_host_free(struct tmio_mmc_host *host);
108int tmio_mmc_host_probe(struct tmio_mmc_host *host,
b6147490
GL
109 struct tmio_mmc_data *pdata);
110void tmio_mmc_host_remove(struct tmio_mmc_host *host);
111void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
112
113void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
114void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
8e7bfdb3 115irqreturn_t tmio_mmc_irq(int irq, void *devid);
7729c7a2
SH
116irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
117irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
118irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
b6147490
GL
119
120static 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
127static 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 135void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data);
162f43e3 136void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable);
b6147490
GL
137void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata);
138void tmio_mmc_release_dma(struct tmio_mmc_host *host);
e3de2be7 139void tmio_mmc_abort_dma(struct tmio_mmc_host *host);
b6147490
GL
140#else
141static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
142 struct mmc_data *data)
143{
144}
145
162f43e3
GL
146static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
147{
148}
149
b6147490
GL
150static 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
157static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
158{
159}
e3de2be7
GL
160
161static 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
167int tmio_mmc_host_runtime_suspend(struct device *dev);
168int tmio_mmc_host_runtime_resume(struct device *dev);
710dec95 169#endif
7311bef0 170
a11862d3
SH
171static 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
176static 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
182static 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
188static 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
198static 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
204static 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