Merge tag 'timer' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[deliverable/linux.git] / include / linux / mmc / sh_mmcif.h
CommitLineData
fdc50a94
YG
1/*
2 * include/linux/mmc/sh_mmcif.h
3 *
4 * platform data for eMMC driver
5 *
6 * Copyright (C) 2010 Renesas Solutions Corp.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License.
11 *
12 */
13
100e9186
RD
14#ifndef LINUX_MMC_SH_MMCIF_H
15#define LINUX_MMC_SH_MMCIF_H
fdc50a94 16
487d9fc5 17#include <linux/io.h>
a782d688
GL
18#include <linux/platform_device.h>
19#include <linux/sh_dma.h>
487d9fc5 20
fdc50a94
YG
21/*
22 * MMCIF : CE_CLK_CTRL [19:16]
23 * 1000 : Peripheral clock / 512
24 * 0111 : Peripheral clock / 256
25 * 0110 : Peripheral clock / 128
26 * 0101 : Peripheral clock / 64
27 * 0100 : Peripheral clock / 32
28 * 0011 : Peripheral clock / 16
29 * 0010 : Peripheral clock / 8
30 * 0001 : Peripheral clock / 4
31 * 0000 : Peripheral clock / 2
32 * 1111 : Peripheral clock (sup_pclk set '1')
33 */
34
a782d688
GL
35struct sh_mmcif_dma {
36 struct sh_dmae_slave chan_priv_tx;
37 struct sh_dmae_slave chan_priv_rx;
38};
39
fdc50a94
YG
40struct sh_mmcif_plat_data {
41 void (*set_pwr)(struct platform_device *pdev, int state);
42 void (*down_pwr)(struct platform_device *pdev);
777271d0 43 int (*get_cd)(struct platform_device *pdef);
714c4a6e
GL
44 struct sh_mmcif_dma *dma; /* Deprecated. Instead */
45 unsigned int slave_id_tx; /* use embedded slave_id_[tr]x */
46 unsigned int slave_id_rx;
e480606a
GL
47 bool use_cd_gpio : 1;
48 unsigned int cd_gpio;
a782d688
GL
49 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */
50 unsigned long caps;
51 u32 ocr;
fdc50a94
YG
52};
53
487d9fc5
MD
54#define MMCIF_CE_CMD_SET 0x00000000
55#define MMCIF_CE_ARG 0x00000008
56#define MMCIF_CE_ARG_CMD12 0x0000000C
57#define MMCIF_CE_CMD_CTRL 0x00000010
58#define MMCIF_CE_BLOCK_SET 0x00000014
59#define MMCIF_CE_CLK_CTRL 0x00000018
60#define MMCIF_CE_BUF_ACC 0x0000001C
61#define MMCIF_CE_RESP3 0x00000020
62#define MMCIF_CE_RESP2 0x00000024
63#define MMCIF_CE_RESP1 0x00000028
64#define MMCIF_CE_RESP0 0x0000002C
65#define MMCIF_CE_RESP_CMD12 0x00000030
66#define MMCIF_CE_DATA 0x00000034
67#define MMCIF_CE_INT 0x00000040
68#define MMCIF_CE_INT_MASK 0x00000044
69#define MMCIF_CE_HOST_STS1 0x00000048
70#define MMCIF_CE_HOST_STS2 0x0000004C
71#define MMCIF_CE_VERSION 0x0000007C
72
da1d39e3
SH
73/* CE_BUF_ACC */
74#define BUF_ACC_DMAWEN (1 << 25)
75#define BUF_ACC_DMAREN (1 << 24)
76#define BUF_ACC_BUSW_32 (0 << 17)
77#define BUF_ACC_BUSW_16 (1 << 17)
78#define BUF_ACC_ATYP (1 << 16)
79
80/* CE_CLK_CTRL */
81#define CLK_ENABLE (1 << 24) /* 1: output mmc clock */
135111cc
GL
82#define CLK_CLEAR (0xf << 16)
83#define CLK_SUP_PCLK (0xf << 16)
84#define CLKDIV_4 (1 << 16) /* mmc clock frequency.
85 * n: bus clock/(2^(n+1)) */
86#define CLKDIV_256 (7 << 16) /* mmc clock frequency. (see above) */
87#define SRSPTO_256 (2 << 12) /* resp timeout */
88#define SRBSYTO_29 (0xf << 8) /* resp busy timeout */
89#define SRWDTO_29 (0xf << 4) /* read/write timeout */
90#define SCCSTO_29 (0xf << 0) /* ccs timeout */
da1d39e3
SH
91
92/* CE_VERSION */
93#define SOFT_RST_ON (1 << 31)
1ae0affe 94#define SOFT_RST_OFF 0
da1d39e3 95
2f6ba579 96static inline u32 sh_mmcif_readl(void __iomem *addr, int reg)
487d9fc5 97{
bba95878 98 return __raw_readl(addr + reg);
487d9fc5
MD
99}
100
2f6ba579 101static inline void sh_mmcif_writel(void __iomem *addr, int reg, u32 val)
487d9fc5 102{
bba95878 103 __raw_writel(val, addr + reg);
487d9fc5
MD
104}
105
8a768952
MD
106#define SH_MMCIF_BBS 512 /* boot block size */
107
2f6ba579 108static inline void sh_mmcif_boot_cmd_send(void __iomem *base,
8a768952
MD
109 unsigned long cmd, unsigned long arg)
110{
111 sh_mmcif_writel(base, MMCIF_CE_INT, 0);
112 sh_mmcif_writel(base, MMCIF_CE_ARG, arg);
113 sh_mmcif_writel(base, MMCIF_CE_CMD_SET, cmd);
114}
115
2f6ba579 116static inline int sh_mmcif_boot_cmd_poll(void __iomem *base, unsigned long mask)
8a768952
MD
117{
118 unsigned long tmp;
119 int cnt;
120
121 for (cnt = 0; cnt < 1000000; cnt++) {
122 tmp = sh_mmcif_readl(base, MMCIF_CE_INT);
123 if (tmp & mask) {
124 sh_mmcif_writel(base, MMCIF_CE_INT, tmp & ~mask);
125 return 0;
126 }
127 }
128
129 return -1;
130}
131
2f6ba579 132static inline int sh_mmcif_boot_cmd(void __iomem *base,
8a768952
MD
133 unsigned long cmd, unsigned long arg)
134{
135 sh_mmcif_boot_cmd_send(base, cmd, arg);
136 return sh_mmcif_boot_cmd_poll(base, 0x00010000);
137}
138
2f6ba579 139static inline int sh_mmcif_boot_do_read_single(void __iomem *base,
8a768952
MD
140 unsigned int block_nr,
141 unsigned long *buf)
142{
143 int k;
144
145 /* CMD13 - Status */
146 sh_mmcif_boot_cmd(base, 0x0d400000, 0x00010000);
147
148 if (sh_mmcif_readl(base, MMCIF_CE_RESP0) != 0x0900)
149 return -1;
150
151 /* CMD17 - Read */
152 sh_mmcif_boot_cmd(base, 0x11480000, block_nr * SH_MMCIF_BBS);
153 if (sh_mmcif_boot_cmd_poll(base, 0x00100000) < 0)
154 return -1;
155
156 for (k = 0; k < (SH_MMCIF_BBS / 4); k++)
157 buf[k] = sh_mmcif_readl(base, MMCIF_CE_DATA);
158
159 return 0;
160}
161
2f6ba579 162static inline int sh_mmcif_boot_do_read(void __iomem *base,
8a768952
MD
163 unsigned long first_block,
164 unsigned long nr_blocks,
165 void *buf)
166{
167 unsigned long k;
168 int ret = 0;
169
54b38463
SH
170 /* In data transfer mode: Set clock to Bus clock/4 (about 20Mhz) */
171 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
172 CLK_ENABLE | CLKDIV_4 | SRSPTO_256 |
173 SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
174
175 /* CMD9 - Get CSD */
176 sh_mmcif_boot_cmd(base, 0x09806000, 0x00010000);
177
178 /* CMD7 - Select the card */
179 sh_mmcif_boot_cmd(base, 0x07400000, 0x00010000);
180
8a768952
MD
181 /* CMD16 - Set the block size */
182 sh_mmcif_boot_cmd(base, 0x10400000, SH_MMCIF_BBS);
183
184 for (k = 0; !ret && k < nr_blocks; k++)
185 ret = sh_mmcif_boot_do_read_single(base, first_block + k,
186 buf + (k * SH_MMCIF_BBS));
187
188 return ret;
189}
190
2f6ba579 191static inline void sh_mmcif_boot_init(void __iomem *base)
8a768952 192{
8a768952 193 /* reset */
1ae0affe
SH
194 sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_ON);
195 sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_OFF);
8a768952
MD
196
197 /* byte swap */
da1d39e3 198 sh_mmcif_writel(base, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
8a768952
MD
199
200 /* Set block size in MMCIF hardware */
201 sh_mmcif_writel(base, MMCIF_CE_BLOCK_SET, SH_MMCIF_BBS);
202
22efa0fe 203 /* Enable the clock, set it to Bus clock/256 (about 325Khz). */
da1d39e3 204 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
22efa0fe
SH
205 CLK_ENABLE | CLKDIV_256 | SRSPTO_256 |
206 SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
8a768952
MD
207
208 /* CMD0 */
209 sh_mmcif_boot_cmd(base, 0x00000040, 0);
210
211 /* CMD1 - Get OCR */
212 do {
213 sh_mmcif_boot_cmd(base, 0x01405040, 0x40300000); /* CMD1 */
214 } while ((sh_mmcif_readl(base, MMCIF_CE_RESP0) & 0x80000000)
215 != 0x80000000);
216
217 /* CMD2 - Get CID */
218 sh_mmcif_boot_cmd(base, 0x02806040, 0);
219
220 /* CMD3 - Set card relative address */
221 sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000);
222}
223
100e9186 224#endif /* LINUX_MMC_SH_MMCIF_H */
This page took 0.227482 seconds and 5 git commands to generate.