blob: 04ff452bf5c3e5eebd7251be8c8fd6c4d5861d0c [file] [log] [blame]
Yusuke Godafdc50a92010-05-26 14:41:59 -07001/*
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
Robert P. J. Day100e9182011-05-27 16:04:03 -040014#ifndef LINUX_MMC_SH_MMCIF_H
15#define LINUX_MMC_SH_MMCIF_H
Yusuke Godafdc50a92010-05-26 14:41:59 -070016
Magnus Damm487d9fc2010-05-18 14:42:51 +000017#include <linux/io.h>
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +000018#include <linux/platform_device.h>
19#include <linux/sh_dma.h>
Magnus Damm487d9fc2010-05-18 14:42:51 +000020
Yusuke Godafdc50a92010-05-26 14:41:59 -070021/*
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
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +000035struct sh_mmcif_dma {
36 struct sh_dmae_slave chan_priv_tx;
37 struct sh_dmae_slave chan_priv_rx;
38};
39
Yusuke Godafdc50a92010-05-26 14:41:59 -070040struct sh_mmcif_plat_data {
41 void (*set_pwr)(struct platform_device *pdev, int state);
42 void (*down_pwr)(struct platform_device *pdev);
Arnd Hannemann777271d2010-08-24 17:27:01 +020043 int (*get_cd)(struct platform_device *pdef);
Guennadi Liakhovetski714c4a62011-08-30 18:26:39 +020044 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;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +000047 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */
48 unsigned long caps;
49 u32 ocr;
Yusuke Godafdc50a92010-05-26 14:41:59 -070050};
51
Magnus Damm487d9fc2010-05-18 14:42:51 +000052#define MMCIF_CE_CMD_SET 0x00000000
53#define MMCIF_CE_ARG 0x00000008
54#define MMCIF_CE_ARG_CMD12 0x0000000C
55#define MMCIF_CE_CMD_CTRL 0x00000010
56#define MMCIF_CE_BLOCK_SET 0x00000014
57#define MMCIF_CE_CLK_CTRL 0x00000018
58#define MMCIF_CE_BUF_ACC 0x0000001C
59#define MMCIF_CE_RESP3 0x00000020
60#define MMCIF_CE_RESP2 0x00000024
61#define MMCIF_CE_RESP1 0x00000028
62#define MMCIF_CE_RESP0 0x0000002C
63#define MMCIF_CE_RESP_CMD12 0x00000030
64#define MMCIF_CE_DATA 0x00000034
65#define MMCIF_CE_INT 0x00000040
66#define MMCIF_CE_INT_MASK 0x00000044
67#define MMCIF_CE_HOST_STS1 0x00000048
68#define MMCIF_CE_HOST_STS2 0x0000004C
69#define MMCIF_CE_VERSION 0x0000007C
70
Simon Hormanda1d39e2010-11-09 17:47:02 +090071/* CE_BUF_ACC */
72#define BUF_ACC_DMAWEN (1 << 25)
73#define BUF_ACC_DMAREN (1 << 24)
74#define BUF_ACC_BUSW_32 (0 << 17)
75#define BUF_ACC_BUSW_16 (1 << 17)
76#define BUF_ACC_ATYP (1 << 16)
77
78/* CE_CLK_CTRL */
79#define CLK_ENABLE (1 << 24) /* 1: output mmc clock */
80#define CLK_CLEAR ((1 << 19) | (1 << 18) | (1 << 17) | (1 << 16))
81#define CLK_SUP_PCLK ((1 << 19) | (1 << 18) | (1 << 17) | (1 << 16))
Simon Horman22efa0f2010-11-27 00:11:55 +000082#define CLKDIV_4 (1<<16) /* mmc clock frequency.
83 * n: bus clock/(2^(n+1)) */
84#define CLKDIV_256 (7<<16) /* mmc clock frequency. (see above) */
Simon Hormanda1d39e2010-11-09 17:47:02 +090085#define SRSPTO_256 ((1 << 13) | (0 << 12)) /* resp timeout */
86#define SRBSYTO_29 ((1 << 11) | (1 << 10) | \
87 (1 << 9) | (1 << 8)) /* resp busy timeout */
88#define SRWDTO_29 ((1 << 7) | (1 << 6) | \
89 (1 << 5) | (1 << 4)) /* read/write timeout */
90#define SCCSTO_29 ((1 << 3) | (1 << 2) | \
91 (1 << 1) | (1 << 0)) /* ccs timeout */
92
93/* CE_VERSION */
94#define SOFT_RST_ON (1 << 31)
Simon Horman1ae0aff2010-11-26 23:02:58 +000095#define SOFT_RST_OFF 0
Simon Hormanda1d39e2010-11-09 17:47:02 +090096
Paul Mundt2f6ba572010-11-04 12:21:25 +090097static inline u32 sh_mmcif_readl(void __iomem *addr, int reg)
Magnus Damm487d9fc2010-05-18 14:42:51 +000098{
Paul Mundtbba95872011-01-14 15:57:47 +090099 return __raw_readl(addr + reg);
Magnus Damm487d9fc2010-05-18 14:42:51 +0000100}
101
Paul Mundt2f6ba572010-11-04 12:21:25 +0900102static inline void sh_mmcif_writel(void __iomem *addr, int reg, u32 val)
Magnus Damm487d9fc2010-05-18 14:42:51 +0000103{
Paul Mundtbba95872011-01-14 15:57:47 +0900104 __raw_writel(val, addr + reg);
Magnus Damm487d9fc2010-05-18 14:42:51 +0000105}
106
Magnus Damm8a768952010-05-18 14:43:04 +0000107#define SH_MMCIF_BBS 512 /* boot block size */
108
Paul Mundt2f6ba572010-11-04 12:21:25 +0900109static inline void sh_mmcif_boot_cmd_send(void __iomem *base,
Magnus Damm8a768952010-05-18 14:43:04 +0000110 unsigned long cmd, unsigned long arg)
111{
112 sh_mmcif_writel(base, MMCIF_CE_INT, 0);
113 sh_mmcif_writel(base, MMCIF_CE_ARG, arg);
114 sh_mmcif_writel(base, MMCIF_CE_CMD_SET, cmd);
115}
116
Paul Mundt2f6ba572010-11-04 12:21:25 +0900117static inline int sh_mmcif_boot_cmd_poll(void __iomem *base, unsigned long mask)
Magnus Damm8a768952010-05-18 14:43:04 +0000118{
119 unsigned long tmp;
120 int cnt;
121
122 for (cnt = 0; cnt < 1000000; cnt++) {
123 tmp = sh_mmcif_readl(base, MMCIF_CE_INT);
124 if (tmp & mask) {
125 sh_mmcif_writel(base, MMCIF_CE_INT, tmp & ~mask);
126 return 0;
127 }
128 }
129
130 return -1;
131}
132
Paul Mundt2f6ba572010-11-04 12:21:25 +0900133static inline int sh_mmcif_boot_cmd(void __iomem *base,
Magnus Damm8a768952010-05-18 14:43:04 +0000134 unsigned long cmd, unsigned long arg)
135{
136 sh_mmcif_boot_cmd_send(base, cmd, arg);
137 return sh_mmcif_boot_cmd_poll(base, 0x00010000);
138}
139
Paul Mundt2f6ba572010-11-04 12:21:25 +0900140static inline int sh_mmcif_boot_do_read_single(void __iomem *base,
Magnus Damm8a768952010-05-18 14:43:04 +0000141 unsigned int block_nr,
142 unsigned long *buf)
143{
144 int k;
145
146 /* CMD13 - Status */
147 sh_mmcif_boot_cmd(base, 0x0d400000, 0x00010000);
148
149 if (sh_mmcif_readl(base, MMCIF_CE_RESP0) != 0x0900)
150 return -1;
151
152 /* CMD17 - Read */
153 sh_mmcif_boot_cmd(base, 0x11480000, block_nr * SH_MMCIF_BBS);
154 if (sh_mmcif_boot_cmd_poll(base, 0x00100000) < 0)
155 return -1;
156
157 for (k = 0; k < (SH_MMCIF_BBS / 4); k++)
158 buf[k] = sh_mmcif_readl(base, MMCIF_CE_DATA);
159
160 return 0;
161}
162
Paul Mundt2f6ba572010-11-04 12:21:25 +0900163static inline int sh_mmcif_boot_do_read(void __iomem *base,
Magnus Damm8a768952010-05-18 14:43:04 +0000164 unsigned long first_block,
165 unsigned long nr_blocks,
166 void *buf)
167{
168 unsigned long k;
169 int ret = 0;
170
Simon Horman54b38462010-12-06 00:12:45 +0000171 /* In data transfer mode: Set clock to Bus clock/4 (about 20Mhz) */
172 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
173 CLK_ENABLE | CLKDIV_4 | SRSPTO_256 |
174 SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
175
176 /* CMD9 - Get CSD */
177 sh_mmcif_boot_cmd(base, 0x09806000, 0x00010000);
178
179 /* CMD7 - Select the card */
180 sh_mmcif_boot_cmd(base, 0x07400000, 0x00010000);
181
Magnus Damm8a768952010-05-18 14:43:04 +0000182 /* CMD16 - Set the block size */
183 sh_mmcif_boot_cmd(base, 0x10400000, SH_MMCIF_BBS);
184
185 for (k = 0; !ret && k < nr_blocks; k++)
186 ret = sh_mmcif_boot_do_read_single(base, first_block + k,
187 buf + (k * SH_MMCIF_BBS));
188
189 return ret;
190}
191
Paul Mundt2f6ba572010-11-04 12:21:25 +0900192static inline void sh_mmcif_boot_init(void __iomem *base)
Magnus Damm8a768952010-05-18 14:43:04 +0000193{
Magnus Damm8a768952010-05-18 14:43:04 +0000194 /* reset */
Simon Horman1ae0aff2010-11-26 23:02:58 +0000195 sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_ON);
196 sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_OFF);
Magnus Damm8a768952010-05-18 14:43:04 +0000197
198 /* byte swap */
Simon Hormanda1d39e2010-11-09 17:47:02 +0900199 sh_mmcif_writel(base, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
Magnus Damm8a768952010-05-18 14:43:04 +0000200
201 /* Set block size in MMCIF hardware */
202 sh_mmcif_writel(base, MMCIF_CE_BLOCK_SET, SH_MMCIF_BBS);
203
Simon Horman22efa0f2010-11-27 00:11:55 +0000204 /* Enable the clock, set it to Bus clock/256 (about 325Khz). */
Simon Hormanda1d39e2010-11-09 17:47:02 +0900205 sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
Simon Horman22efa0f2010-11-27 00:11:55 +0000206 CLK_ENABLE | CLKDIV_256 | SRSPTO_256 |
207 SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
Magnus Damm8a768952010-05-18 14:43:04 +0000208
209 /* CMD0 */
210 sh_mmcif_boot_cmd(base, 0x00000040, 0);
211
212 /* CMD1 - Get OCR */
213 do {
214 sh_mmcif_boot_cmd(base, 0x01405040, 0x40300000); /* CMD1 */
215 } while ((sh_mmcif_readl(base, MMCIF_CE_RESP0) & 0x80000000)
216 != 0x80000000);
217
218 /* CMD2 - Get CID */
219 sh_mmcif_boot_cmd(base, 0x02806040, 0);
220
221 /* CMD3 - Set card relative address */
222 sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000);
223}
224
Robert P. J. Day100e9182011-05-27 16:04:03 -0400225#endif /* LINUX_MMC_SH_MMCIF_H */