aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mmc/sh_mmcif.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/mmc/sh_mmcif.h')
-rw-r--r--include/linux/mmc/sh_mmcif.h91
1 files changed, 58 insertions, 33 deletions
diff --git a/include/linux/mmc/sh_mmcif.h b/include/linux/mmc/sh_mmcif.h
index 5c99da1078aa..bf173502d744 100644
--- a/include/linux/mmc/sh_mmcif.h
+++ b/include/linux/mmc/sh_mmcif.h
@@ -14,8 +14,9 @@
14#ifndef __SH_MMCIF_H__ 14#ifndef __SH_MMCIF_H__
15#define __SH_MMCIF_H__ 15#define __SH_MMCIF_H__
16 16
17#include <linux/platform_device.h>
18#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/platform_device.h>
19#include <linux/sh_dma.h>
19 20
20/* 21/*
21 * MMCIF : CE_CLK_CTRL [19:16] 22 * MMCIF : CE_CLK_CTRL [19:16]
@@ -31,13 +32,19 @@
31 * 1111 : Peripheral clock (sup_pclk set '1') 32 * 1111 : Peripheral clock (sup_pclk set '1')
32 */ 33 */
33 34
35struct sh_mmcif_dma {
36 struct sh_dmae_slave chan_priv_tx;
37 struct sh_dmae_slave chan_priv_rx;
38};
39
34struct sh_mmcif_plat_data { 40struct sh_mmcif_plat_data {
35 void (*set_pwr)(struct platform_device *pdev, int state); 41 void (*set_pwr)(struct platform_device *pdev, int state);
36 void (*down_pwr)(struct platform_device *pdev); 42 void (*down_pwr)(struct platform_device *pdev);
37 int (*get_cd)(struct platform_device *pdef); 43 int (*get_cd)(struct platform_device *pdef);
38 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */ 44 struct sh_mmcif_dma *dma;
39 unsigned long caps; 45 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */
40 u32 ocr; 46 unsigned long caps;
47 u32 ocr;
41}; 48};
42 49
43#define MMCIF_CE_CMD_SET 0x00000000 50#define MMCIF_CE_CMD_SET 0x00000000
@@ -59,6 +66,32 @@ struct sh_mmcif_plat_data {
59#define MMCIF_CE_HOST_STS2 0x0000004C 66#define MMCIF_CE_HOST_STS2 0x0000004C
60#define MMCIF_CE_VERSION 0x0000007C 67#define MMCIF_CE_VERSION 0x0000007C
61 68
69/* CE_BUF_ACC */
70#define BUF_ACC_DMAWEN (1 << 25)
71#define BUF_ACC_DMAREN (1 << 24)
72#define BUF_ACC_BUSW_32 (0 << 17)
73#define BUF_ACC_BUSW_16 (1 << 17)
74#define BUF_ACC_ATYP (1 << 16)
75
76/* CE_CLK_CTRL */
77#define CLK_ENABLE (1 << 24) /* 1: output mmc clock */
78#define CLK_CLEAR ((1 << 19) | (1 << 18) | (1 << 17) | (1 << 16))
79#define CLK_SUP_PCLK ((1 << 19) | (1 << 18) | (1 << 17) | (1 << 16))
80#define CLKDIV_4 (1<<16) /* mmc clock frequency.
81 * n: bus clock/(2^(n+1)) */
82#define CLKDIV_256 (7<<16) /* mmc clock frequency. (see above) */
83#define SRSPTO_256 ((1 << 13) | (0 << 12)) /* resp timeout */
84#define SRBSYTO_29 ((1 << 11) | (1 << 10) | \
85 (1 << 9) | (1 << 8)) /* resp busy timeout */
86#define SRWDTO_29 ((1 << 7) | (1 << 6) | \
87 (1 << 5) | (1 << 4)) /* read/write timeout */
88#define SCCSTO_29 ((1 << 3) | (1 << 2) | \
89 (1 << 1) | (1 << 0)) /* ccs timeout */
90
91/* CE_VERSION */
92#define SOFT_RST_ON (1 << 31)
93#define SOFT_RST_OFF 0
94
62static inline u32 sh_mmcif_readl(void __iomem *addr, int reg) 95static inline u32 sh_mmcif_readl(void __iomem *addr, int reg)
63{ 96{
64 return readl(addr + reg); 97 return readl(addr + reg);
@@ -71,6 +104,9 @@ static inline void sh_mmcif_writel(void __iomem *addr, int reg, u32 val)
71 104
72#define SH_MMCIF_BBS 512 /* boot block size */ 105#define SH_MMCIF_BBS 512 /* boot block size */
73 106
107enum { MMCIF_PROGRESS_ENTER, MMCIF_PROGRESS_INIT,
108 MMCIF_PROGRESS_LOAD, MMCIF_PROGRESS_DONE };
109
74static inline void sh_mmcif_boot_cmd_send(void __iomem *base, 110static inline void sh_mmcif_boot_cmd_send(void __iomem *base,
75 unsigned long cmd, unsigned long arg) 111 unsigned long cmd, unsigned long arg)
76{ 112{
@@ -133,6 +169,17 @@ static inline int sh_mmcif_boot_do_read(void __iomem *base,
133 unsigned long k; 169 unsigned long k;
134 int ret = 0; 170 int ret = 0;
135 171
172 /* In data transfer mode: Set clock to Bus clock/4 (about 20Mhz) */
173 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
174 CLK_ENABLE | CLKDIV_4 | SRSPTO_256 |
175 SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
176
177 /* CMD9 - Get CSD */
178 sh_mmcif_boot_cmd(base, 0x09806000, 0x00010000);
179
180 /* CMD7 - Select the card */
181 sh_mmcif_boot_cmd(base, 0x07400000, 0x00010000);
182
136 /* CMD16 - Set the block size */ 183 /* CMD16 - Set the block size */
137 sh_mmcif_boot_cmd(base, 0x10400000, SH_MMCIF_BBS); 184 sh_mmcif_boot_cmd(base, 0x10400000, SH_MMCIF_BBS);
138 185
@@ -145,21 +192,20 @@ static inline int sh_mmcif_boot_do_read(void __iomem *base,
145 192
146static inline void sh_mmcif_boot_init(void __iomem *base) 193static inline void sh_mmcif_boot_init(void __iomem *base)
147{ 194{
148 unsigned long tmp;
149
150 /* reset */ 195 /* reset */
151 tmp = sh_mmcif_readl(base, MMCIF_CE_VERSION); 196 sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_ON);
152 sh_mmcif_writel(base, MMCIF_CE_VERSION, tmp | 0x80000000); 197 sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_OFF);
153 sh_mmcif_writel(base, MMCIF_CE_VERSION, tmp & ~0x80000000);
154 198
155 /* byte swap */ 199 /* byte swap */
156 sh_mmcif_writel(base, MMCIF_CE_BUF_ACC, 0x00010000); 200 sh_mmcif_writel(base, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
157 201
158 /* Set block size in MMCIF hardware */ 202 /* Set block size in MMCIF hardware */
159 sh_mmcif_writel(base, MMCIF_CE_BLOCK_SET, SH_MMCIF_BBS); 203 sh_mmcif_writel(base, MMCIF_CE_BLOCK_SET, SH_MMCIF_BBS);
160 204
161 /* Enable the clock, set it to Bus clock/256 (about 325Khz)*/ 205 /* Enable the clock, set it to Bus clock/256 (about 325Khz). */
162 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL, 0x01072fff); 206 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
207 CLK_ENABLE | CLKDIV_256 | SRSPTO_256 |
208 SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
163 209
164 /* CMD0 */ 210 /* CMD0 */
165 sh_mmcif_boot_cmd(base, 0x00000040, 0); 211 sh_mmcif_boot_cmd(base, 0x00000040, 0);
@@ -177,25 +223,4 @@ static inline void sh_mmcif_boot_init(void __iomem *base)
177 sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000); 223 sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000);
178} 224}
179 225
180static inline void sh_mmcif_boot_slurp(void __iomem *base,
181 unsigned char *buf,
182 unsigned long no_bytes)
183{
184 unsigned long tmp;
185
186 /* In data transfer mode: Set clock to Bus clock/4 (about 20Mhz) */
187 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL, 0x01012fff);
188
189 /* CMD9 - Get CSD */
190 sh_mmcif_boot_cmd(base, 0x09806000, 0x00010000);
191
192 /* CMD7 - Select the card */
193 sh_mmcif_boot_cmd(base, 0x07400000, 0x00010000);
194
195 tmp = no_bytes / SH_MMCIF_BBS;
196 tmp += (no_bytes % SH_MMCIF_BBS) ? 1 : 0;
197
198 sh_mmcif_boot_do_read(base, 512, tmp, buf);
199}
200
201#endif /* __SH_MMCIF_H__ */ 226#endif /* __SH_MMCIF_H__ */