net: fsl: Fix error checking for platform_get_irq()
[linux-2.6-block.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
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
42struct tmio_mmc_data;
5add2aca 43struct tmio_mmc_host;
b6147490 44
7ecc09ba 45struct 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
51struct 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);
4fe2ec57 98 int (*clk_enable)(struct platform_device *pdev, unsigned int *f);
00452c11 99 void (*clk_disable)(struct platform_device *pdev);
85c02ddd
KM
100 int (*multi_io_quirk)(struct mmc_card *card,
101 unsigned int direction, int blk_size);
b6147490
GL
102};
103
94b110af
KM
104struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev);
105void tmio_mmc_host_free(struct tmio_mmc_host *host);
106int tmio_mmc_host_probe(struct tmio_mmc_host *host,
b6147490
GL
107 struct tmio_mmc_data *pdata);
108void tmio_mmc_host_remove(struct tmio_mmc_host *host);
109void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
110
111void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
112void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
8e7bfdb3 113irqreturn_t tmio_mmc_irq(int irq, void *devid);
7729c7a2
SH
114irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
115irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
116irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
b6147490
GL
117
118static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
119 unsigned long *flags)
120{
121 local_irq_save(*flags);
482fce99 122 return kmap_atomic(sg_page(sg)) + sg->offset;
b6147490
GL
123}
124
125static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg,
126 unsigned long *flags, void *virt)
127{
482fce99 128 kunmap_atomic(virt - sg->offset);
b6147490
GL
129 local_irq_restore(*flags);
130}
131
42051e8a 132#if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
b6147490 133void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data);
162f43e3 134void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable);
b6147490
GL
135void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata);
136void tmio_mmc_release_dma(struct tmio_mmc_host *host);
e3de2be7 137void tmio_mmc_abort_dma(struct tmio_mmc_host *host);
b6147490
GL
138#else
139static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
140 struct mmc_data *data)
141{
142}
143
162f43e3
GL
144static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
145{
146}
147
b6147490
GL
148static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host,
149 struct tmio_mmc_data *pdata)
150{
151 host->chan_tx = NULL;
152 host->chan_rx = NULL;
153}
154
155static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
156{
157}
e3de2be7
GL
158
159static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
160{
161}
b6147490
GL
162#endif
163
9ade7dbf 164#ifdef CONFIG_PM
7311bef0
GL
165int tmio_mmc_host_runtime_suspend(struct device *dev);
166int tmio_mmc_host_runtime_resume(struct device *dev);
710dec95 167#endif
7311bef0 168
a11862d3
SH
169static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
170{
7445bf9e 171 return readw(host->ctl + (addr << host->bus_shift));
a11862d3
SH
172}
173
174static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
175 u16 *buf, int count)
176{
7445bf9e 177 readsw(host->ctl + (addr << host->bus_shift), buf, count);
a11862d3
SH
178}
179
180static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
181{
7445bf9e
KM
182 return readw(host->ctl + (addr << host->bus_shift)) |
183 readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
a11862d3
SH
184}
185
186static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val)
187{
973ed3af
SH
188 /* If there is a hook and it returns non-zero then there
189 * is an error and the write should be skipped
190 */
dfe9a229 191 if (host->write16_hook && host->write16_hook(host, addr))
973ed3af 192 return;
7445bf9e 193 writew(val, host->ctl + (addr << host->bus_shift));
a11862d3
SH
194}
195
196static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
197 u16 *buf, int count)
198{
7445bf9e 199 writesw(host->ctl + (addr << host->bus_shift), buf, count);
a11862d3
SH
200}
201
202static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
203{
7445bf9e
KM
204 writew(val, host->ctl + (addr << host->bus_shift));
205 writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
a11862d3
SH
206}
207
208
b6147490 209#endif