blob: 7d79b14d56aa55ba1a661882445a720ce6956566 [file] [log] [blame]
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +01001/*
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>
20#include <linux/pagemap.h>
21
22/* Definitions for values the CTRL_STATUS register can take. */
23#define TMIO_STAT_CMDRESPEND 0x00000001
24#define TMIO_STAT_DATAEND 0x00000004
25#define TMIO_STAT_CARD_REMOVE 0x00000008
26#define TMIO_STAT_CARD_INSERT 0x00000010
27#define TMIO_STAT_SIGSTATE 0x00000020
28#define TMIO_STAT_WRPROTECT 0x00000080
29#define TMIO_STAT_CARD_REMOVE_A 0x00000100
30#define TMIO_STAT_CARD_INSERT_A 0x00000200
31#define TMIO_STAT_SIGSTATE_A 0x00000400
32#define TMIO_STAT_CMD_IDX_ERR 0x00010000
33#define TMIO_STAT_CRCFAIL 0x00020000
34#define TMIO_STAT_STOPBIT_ERR 0x00040000
35#define TMIO_STAT_DATATIMEOUT 0x00080000
36#define TMIO_STAT_RXOVERFLOW 0x00100000
37#define TMIO_STAT_TXUNDERRUN 0x00200000
38#define TMIO_STAT_CMDTIMEOUT 0x00400000
39#define TMIO_STAT_RXRDY 0x01000000
40#define TMIO_STAT_TXRQ 0x02000000
41#define TMIO_STAT_ILL_FUNC 0x20000000
42#define TMIO_STAT_CMD_BUSY 0x40000000
43#define TMIO_STAT_ILL_ACCESS 0x80000000
44
45/* Definitions for values the CTRL_SDIO_STATUS register can take. */
46#define TMIO_SDIO_STAT_IOIRQ 0x0001
47#define TMIO_SDIO_STAT_EXPUB52 0x4000
48#define TMIO_SDIO_STAT_EXWT 0x8000
49#define TMIO_SDIO_MASK_ALL 0xc007
50
51/* Define some IRQ masks */
52/* This is the mask used at reset by the chip */
53#define TMIO_MASK_ALL 0x837f031d
54#define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
55#define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
56#define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
57 TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
58#define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
59
60struct tmio_mmc_data;
61
62struct tmio_mmc_host {
63 void __iomem *ctl;
64 unsigned long bus_shift;
65 struct mmc_command *cmd;
66 struct mmc_request *mrq;
67 struct mmc_data *data;
68 struct mmc_host *mmc;
69 int irq;
70 unsigned int sdio_irq_enabled;
71
72 /* Callbacks for clock / power control */
73 void (*set_pwr)(struct platform_device *host, int state);
74 void (*set_clk_div)(struct platform_device *host, int state);
75
76 /* pio related stuff */
77 struct scatterlist *sg_ptr;
78 struct scatterlist *sg_orig;
79 unsigned int sg_len;
80 unsigned int sg_off;
81
82 struct platform_device *pdev;
83 struct tmio_mmc_data *pdata;
84
85 /* DMA support */
86 bool force_pio;
87 struct dma_chan *chan_rx;
88 struct dma_chan *chan_tx;
89 struct tasklet_struct dma_complete;
90 struct tasklet_struct dma_issue;
91 struct scatterlist bounce_sg;
92 u8 *bounce_buf;
93
94 /* Track lost interrupts */
95 struct delayed_work delayed_reset_work;
96 spinlock_t lock;
97 unsigned long last_req_ts;
98};
99
100int tmio_mmc_host_probe(struct tmio_mmc_host **host,
101 struct platform_device *pdev,
102 struct tmio_mmc_data *pdata);
103void tmio_mmc_host_remove(struct tmio_mmc_host *host);
104void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
105
106void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
107void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
108
109static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
110 unsigned long *flags)
111{
112 local_irq_save(*flags);
113 return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
114}
115
116static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg,
117 unsigned long *flags, void *virt)
118{
119 kunmap_atomic(virt - sg->offset, KM_BIO_SRC_IRQ);
120 local_irq_restore(*flags);
121}
122
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100123#if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
Guennadi Liakhovetskib6147492011-03-23 12:42:44 +0100124void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data);
125void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata);
126void tmio_mmc_release_dma(struct tmio_mmc_host *host);
127#else
128static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
129 struct mmc_data *data)
130{
131}
132
133static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host,
134 struct tmio_mmc_data *pdata)
135{
136 host->chan_tx = NULL;
137 host->chan_rx = NULL;
138}
139
140static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
141{
142}
143#endif
144
145#endif