Commit 9b67cdfdb8174ba0a6789a24b45f7837e8eff992
1 parent
d3f297b0c4
Exists in
smarc-ti-linux-3.12.y
Upgrade eMMC from 4GB to 8GB
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
drivers/mmc/core/mmc.c
1 | /* | 1 | /* |
2 | * linux/drivers/mmc/core/mmc.c | 2 | * linux/drivers/mmc/core/mmc.c |
3 | * | 3 | * |
4 | * Copyright (C) 2003-2004 Russell King, All Rights Reserved. | 4 | * Copyright (C) 2003-2004 Russell King, All Rights Reserved. |
5 | * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. | 5 | * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. |
6 | * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. | 6 | * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify | 8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License version 2 as | 9 | * it under the terms of the GNU General Public License version 2 as |
10 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/err.h> | 13 | #include <linux/err.h> |
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/stat.h> | 15 | #include <linux/stat.h> |
16 | 16 | ||
17 | #include <linux/mmc/host.h> | 17 | #include <linux/mmc/host.h> |
18 | #include <linux/mmc/card.h> | 18 | #include <linux/mmc/card.h> |
19 | #include <linux/mmc/mmc.h> | 19 | #include <linux/mmc/mmc.h> |
20 | 20 | ||
21 | #include "core.h" | 21 | #include "core.h" |
22 | #include "bus.h" | 22 | #include "bus.h" |
23 | #include "mmc_ops.h" | 23 | #include "mmc_ops.h" |
24 | #include "sd_ops.h" | 24 | #include "sd_ops.h" |
25 | 25 | ||
26 | static const unsigned int tran_exp[] = { | 26 | static const unsigned int tran_exp[] = { |
27 | 10000, 100000, 1000000, 10000000, | 27 | 10000, 100000, 1000000, 10000000, |
28 | 0, 0, 0, 0 | 28 | 0, 0, 0, 0 |
29 | }; | 29 | }; |
30 | 30 | ||
31 | static const unsigned char tran_mant[] = { | 31 | static const unsigned char tran_mant[] = { |
32 | 0, 10, 12, 13, 15, 20, 25, 30, | 32 | 0, 10, 12, 13, 15, 20, 25, 30, |
33 | 35, 40, 45, 50, 55, 60, 70, 80, | 33 | 35, 40, 45, 50, 55, 60, 70, 80, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | static const unsigned int tacc_exp[] = { | 36 | static const unsigned int tacc_exp[] = { |
37 | 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, | 37 | 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, |
38 | }; | 38 | }; |
39 | 39 | ||
40 | static const unsigned int tacc_mant[] = { | 40 | static const unsigned int tacc_mant[] = { |
41 | 0, 10, 12, 13, 15, 20, 25, 30, | 41 | 0, 10, 12, 13, 15, 20, 25, 30, |
42 | 35, 40, 45, 50, 55, 60, 70, 80, | 42 | 35, 40, 45, 50, 55, 60, 70, 80, |
43 | }; | 43 | }; |
44 | 44 | ||
45 | #define UNSTUFF_BITS(resp,start,size) \ | 45 | #define UNSTUFF_BITS(resp,start,size) \ |
46 | ({ \ | 46 | ({ \ |
47 | const int __size = size; \ | 47 | const int __size = size; \ |
48 | const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ | 48 | const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ |
49 | const int __off = 3 - ((start) / 32); \ | 49 | const int __off = 3 - ((start) / 32); \ |
50 | const int __shft = (start) & 31; \ | 50 | const int __shft = (start) & 31; \ |
51 | u32 __res; \ | 51 | u32 __res; \ |
52 | \ | 52 | \ |
53 | __res = resp[__off] >> __shft; \ | 53 | __res = resp[__off] >> __shft; \ |
54 | if (__size + __shft > 32) \ | 54 | if (__size + __shft > 32) \ |
55 | __res |= resp[__off-1] << ((32 - __shft) % 32); \ | 55 | __res |= resp[__off-1] << ((32 - __shft) % 32); \ |
56 | __res & __mask; \ | 56 | __res & __mask; \ |
57 | }) | 57 | }) |
58 | 58 | ||
59 | /* | 59 | /* |
60 | * Given the decoded CSD structure, decode the raw CID to our CID structure. | 60 | * Given the decoded CSD structure, decode the raw CID to our CID structure. |
61 | */ | 61 | */ |
62 | static int mmc_decode_cid(struct mmc_card *card) | 62 | static int mmc_decode_cid(struct mmc_card *card) |
63 | { | 63 | { |
64 | u32 *resp = card->raw_cid; | 64 | u32 *resp = card->raw_cid; |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * The selection of the format here is based upon published | 67 | * The selection of the format here is based upon published |
68 | * specs from sandisk and from what people have reported. | 68 | * specs from sandisk and from what people have reported. |
69 | */ | 69 | */ |
70 | switch (card->csd.mmca_vsn) { | 70 | switch (card->csd.mmca_vsn) { |
71 | case 0: /* MMC v1.0 - v1.2 */ | 71 | case 0: /* MMC v1.0 - v1.2 */ |
72 | case 1: /* MMC v1.4 */ | 72 | case 1: /* MMC v1.4 */ |
73 | card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); | 73 | card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); |
74 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); | 74 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); |
75 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); | 75 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); |
76 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); | 76 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); |
77 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); | 77 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); |
78 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); | 78 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); |
79 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); | 79 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); |
80 | card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); | 80 | card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); |
81 | card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); | 81 | card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); |
82 | card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); | 82 | card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); |
83 | card->cid.serial = UNSTUFF_BITS(resp, 16, 24); | 83 | card->cid.serial = UNSTUFF_BITS(resp, 16, 24); |
84 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); | 84 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); |
85 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; | 85 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; |
86 | break; | 86 | break; |
87 | 87 | ||
88 | case 2: /* MMC v2.0 - v2.2 */ | 88 | case 2: /* MMC v2.0 - v2.2 */ |
89 | case 3: /* MMC v3.1 - v3.3 */ | 89 | case 3: /* MMC v3.1 - v3.3 */ |
90 | case 4: /* MMC v4 */ | 90 | case 4: /* MMC v4 */ |
91 | card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); | 91 | card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); |
92 | card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); | 92 | card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); |
93 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); | 93 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); |
94 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); | 94 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); |
95 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); | 95 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); |
96 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); | 96 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); |
97 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); | 97 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); |
98 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); | 98 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); |
99 | card->cid.prv = UNSTUFF_BITS(resp, 48, 8); | 99 | card->cid.prv = UNSTUFF_BITS(resp, 48, 8); |
100 | card->cid.serial = UNSTUFF_BITS(resp, 16, 32); | 100 | card->cid.serial = UNSTUFF_BITS(resp, 16, 32); |
101 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); | 101 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); |
102 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; | 102 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; |
103 | break; | 103 | break; |
104 | 104 | ||
105 | default: | 105 | default: |
106 | pr_err("%s: card has unknown MMCA version %d\n", | 106 | pr_err("%s: card has unknown MMCA version %d\n", |
107 | mmc_hostname(card->host), card->csd.mmca_vsn); | 107 | mmc_hostname(card->host), card->csd.mmca_vsn); |
108 | return -EINVAL; | 108 | return -EINVAL; |
109 | } | 109 | } |
110 | 110 | ||
111 | return 0; | 111 | return 0; |
112 | } | 112 | } |
113 | 113 | ||
114 | static void mmc_set_erase_size(struct mmc_card *card) | 114 | static void mmc_set_erase_size(struct mmc_card *card) |
115 | { | 115 | { |
116 | if (card->ext_csd.erase_group_def & 1) | 116 | if (card->ext_csd.erase_group_def & 1) |
117 | card->erase_size = card->ext_csd.hc_erase_size; | 117 | card->erase_size = card->ext_csd.hc_erase_size; |
118 | else | 118 | else |
119 | card->erase_size = card->csd.erase_size; | 119 | card->erase_size = card->csd.erase_size; |
120 | 120 | ||
121 | mmc_init_erase(card); | 121 | mmc_init_erase(card); |
122 | } | 122 | } |
123 | 123 | ||
124 | /* | 124 | /* |
125 | * Given a 128-bit response, decode to our card CSD structure. | 125 | * Given a 128-bit response, decode to our card CSD structure. |
126 | */ | 126 | */ |
127 | static int mmc_decode_csd(struct mmc_card *card) | 127 | static int mmc_decode_csd(struct mmc_card *card) |
128 | { | 128 | { |
129 | struct mmc_csd *csd = &card->csd; | 129 | struct mmc_csd *csd = &card->csd; |
130 | unsigned int e, m, a, b; | 130 | unsigned int e, m, a, b; |
131 | u32 *resp = card->raw_csd; | 131 | u32 *resp = card->raw_csd; |
132 | 132 | ||
133 | /* | 133 | /* |
134 | * We only understand CSD structure v1.1 and v1.2. | 134 | * We only understand CSD structure v1.1 and v1.2. |
135 | * v1.2 has extra information in bits 15, 11 and 10. | 135 | * v1.2 has extra information in bits 15, 11 and 10. |
136 | * We also support eMMC v4.4 & v4.41. | 136 | * We also support eMMC v4.4 & v4.41. |
137 | */ | 137 | */ |
138 | csd->structure = UNSTUFF_BITS(resp, 126, 2); | 138 | csd->structure = UNSTUFF_BITS(resp, 126, 2); |
139 | if (csd->structure == 0) { | 139 | if (csd->structure == 0) { |
140 | pr_err("%s: unrecognised CSD structure version %d\n", | 140 | pr_err("%s: unrecognised CSD structure version %d\n", |
141 | mmc_hostname(card->host), csd->structure); | 141 | mmc_hostname(card->host), csd->structure); |
142 | return -EINVAL; | 142 | return -EINVAL; |
143 | } | 143 | } |
144 | 144 | ||
145 | csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); | 145 | csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); |
146 | m = UNSTUFF_BITS(resp, 115, 4); | 146 | m = UNSTUFF_BITS(resp, 115, 4); |
147 | e = UNSTUFF_BITS(resp, 112, 3); | 147 | e = UNSTUFF_BITS(resp, 112, 3); |
148 | csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; | 148 | csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; |
149 | csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; | 149 | csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; |
150 | 150 | ||
151 | m = UNSTUFF_BITS(resp, 99, 4); | 151 | m = UNSTUFF_BITS(resp, 99, 4); |
152 | e = UNSTUFF_BITS(resp, 96, 3); | 152 | e = UNSTUFF_BITS(resp, 96, 3); |
153 | csd->max_dtr = tran_exp[e] * tran_mant[m]; | 153 | csd->max_dtr = tran_exp[e] * tran_mant[m]; |
154 | csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); | 154 | csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); |
155 | 155 | ||
156 | e = UNSTUFF_BITS(resp, 47, 3); | 156 | e = UNSTUFF_BITS(resp, 47, 3); |
157 | m = UNSTUFF_BITS(resp, 62, 12); | 157 | m = UNSTUFF_BITS(resp, 62, 12); |
158 | csd->capacity = (1 + m) << (e + 2); | 158 | csd->capacity = (1 + m) << (e + 2); |
159 | 159 | ||
160 | csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); | 160 | csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); |
161 | csd->read_partial = UNSTUFF_BITS(resp, 79, 1); | 161 | csd->read_partial = UNSTUFF_BITS(resp, 79, 1); |
162 | csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); | 162 | csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); |
163 | csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); | 163 | csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); |
164 | csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); | 164 | csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); |
165 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); | 165 | csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); |
166 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); | 166 | csd->write_partial = UNSTUFF_BITS(resp, 21, 1); |
167 | 167 | ||
168 | if (csd->write_blkbits >= 9) { | 168 | if (csd->write_blkbits >= 9) { |
169 | a = UNSTUFF_BITS(resp, 42, 5); | 169 | a = UNSTUFF_BITS(resp, 42, 5); |
170 | b = UNSTUFF_BITS(resp, 37, 5); | 170 | b = UNSTUFF_BITS(resp, 37, 5); |
171 | csd->erase_size = (a + 1) * (b + 1); | 171 | csd->erase_size = (a + 1) * (b + 1); |
172 | csd->erase_size <<= csd->write_blkbits - 9; | 172 | csd->erase_size <<= csd->write_blkbits - 9; |
173 | } | 173 | } |
174 | 174 | ||
175 | return 0; | 175 | return 0; |
176 | } | 176 | } |
177 | 177 | ||
178 | /* | 178 | /* |
179 | * Read extended CSD. | 179 | * Read extended CSD. |
180 | */ | 180 | */ |
181 | static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) | 181 | static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) |
182 | { | 182 | { |
183 | int err; | 183 | int err; |
184 | u8 *ext_csd; | 184 | u8 *ext_csd; |
185 | 185 | ||
186 | BUG_ON(!card); | 186 | BUG_ON(!card); |
187 | BUG_ON(!new_ext_csd); | 187 | BUG_ON(!new_ext_csd); |
188 | 188 | ||
189 | *new_ext_csd = NULL; | 189 | *new_ext_csd = NULL; |
190 | 190 | ||
191 | if (card->csd.mmca_vsn < CSD_SPEC_VER_4) | 191 | if (card->csd.mmca_vsn < CSD_SPEC_VER_4) |
192 | return 0; | 192 | return 0; |
193 | 193 | ||
194 | /* | 194 | /* |
195 | * As the ext_csd is so large and mostly unused, we don't store the | 195 | * As the ext_csd is so large and mostly unused, we don't store the |
196 | * raw block in mmc_card. | 196 | * raw block in mmc_card. |
197 | */ | 197 | */ |
198 | ext_csd = kmalloc(512, GFP_KERNEL); | 198 | ext_csd = kmalloc(512, GFP_KERNEL); |
199 | if (!ext_csd) { | 199 | if (!ext_csd) { |
200 | pr_err("%s: could not allocate a buffer to " | 200 | pr_err("%s: could not allocate a buffer to " |
201 | "receive the ext_csd.\n", mmc_hostname(card->host)); | 201 | "receive the ext_csd.\n", mmc_hostname(card->host)); |
202 | return -ENOMEM; | 202 | return -ENOMEM; |
203 | } | 203 | } |
204 | 204 | ||
205 | err = mmc_send_ext_csd(card, ext_csd); | 205 | err = mmc_send_ext_csd(card, ext_csd); |
206 | if (err) { | 206 | if (err) { |
207 | kfree(ext_csd); | 207 | kfree(ext_csd); |
208 | *new_ext_csd = NULL; | 208 | *new_ext_csd = NULL; |
209 | 209 | ||
210 | /* If the host or the card can't do the switch, | 210 | /* If the host or the card can't do the switch, |
211 | * fail more gracefully. */ | 211 | * fail more gracefully. */ |
212 | if ((err != -EINVAL) | 212 | if ((err != -EINVAL) |
213 | && (err != -ENOSYS) | 213 | && (err != -ENOSYS) |
214 | && (err != -EFAULT)) | 214 | && (err != -EFAULT)) |
215 | return err; | 215 | return err; |
216 | 216 | ||
217 | /* | 217 | /* |
218 | * High capacity cards should have this "magic" size | 218 | * High capacity cards should have this "magic" size |
219 | * stored in their CSD. | 219 | * stored in their CSD. |
220 | */ | 220 | */ |
221 | if (card->csd.capacity == (4096 * 512)) { | 221 | if (card->csd.capacity == (4096 * 512)) { |
222 | pr_err("%s: unable to read EXT_CSD " | 222 | pr_err("%s: unable to read EXT_CSD " |
223 | "on a possible high capacity card. " | 223 | "on a possible high capacity card. " |
224 | "Card will be ignored.\n", | 224 | "Card will be ignored.\n", |
225 | mmc_hostname(card->host)); | 225 | mmc_hostname(card->host)); |
226 | } else { | 226 | } else { |
227 | pr_warning("%s: unable to read " | 227 | pr_warning("%s: unable to read " |
228 | "EXT_CSD, performance might " | 228 | "EXT_CSD, performance might " |
229 | "suffer.\n", | 229 | "suffer.\n", |
230 | mmc_hostname(card->host)); | 230 | mmc_hostname(card->host)); |
231 | err = 0; | 231 | err = 0; |
232 | } | 232 | } |
233 | } else | 233 | } else |
234 | *new_ext_csd = ext_csd; | 234 | *new_ext_csd = ext_csd; |
235 | 235 | ||
236 | return err; | 236 | return err; |
237 | } | 237 | } |
238 | 238 | ||
239 | static void mmc_select_card_type(struct mmc_card *card) | 239 | static void mmc_select_card_type(struct mmc_card *card) |
240 | { | 240 | { |
241 | struct mmc_host *host = card->host; | 241 | struct mmc_host *host = card->host; |
242 | u8 card_type = card->ext_csd.raw_card_type & EXT_CSD_CARD_TYPE_MASK; | 242 | u8 card_type = card->ext_csd.raw_card_type & EXT_CSD_CARD_TYPE_MASK; |
243 | u32 caps = host->caps, caps2 = host->caps2; | 243 | u32 caps = host->caps, caps2 = host->caps2; |
244 | unsigned int hs_max_dtr = 0; | 244 | unsigned int hs_max_dtr = 0; |
245 | 245 | ||
246 | if (card_type & EXT_CSD_CARD_TYPE_26) | 246 | if (card_type & EXT_CSD_CARD_TYPE_26) |
247 | hs_max_dtr = MMC_HIGH_26_MAX_DTR; | 247 | hs_max_dtr = MMC_HIGH_26_MAX_DTR; |
248 | 248 | ||
249 | if (caps & MMC_CAP_MMC_HIGHSPEED && | 249 | if (caps & MMC_CAP_MMC_HIGHSPEED && |
250 | card_type & EXT_CSD_CARD_TYPE_52) | 250 | card_type & EXT_CSD_CARD_TYPE_52) |
251 | hs_max_dtr = MMC_HIGH_52_MAX_DTR; | 251 | hs_max_dtr = MMC_HIGH_52_MAX_DTR; |
252 | 252 | ||
253 | if ((caps & MMC_CAP_1_8V_DDR && | 253 | if ((caps & MMC_CAP_1_8V_DDR && |
254 | card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) || | 254 | card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) || |
255 | (caps & MMC_CAP_1_2V_DDR && | 255 | (caps & MMC_CAP_1_2V_DDR && |
256 | card_type & EXT_CSD_CARD_TYPE_DDR_1_2V)) | 256 | card_type & EXT_CSD_CARD_TYPE_DDR_1_2V)) |
257 | hs_max_dtr = MMC_HIGH_DDR_MAX_DTR; | 257 | hs_max_dtr = MMC_HIGH_DDR_MAX_DTR; |
258 | 258 | ||
259 | if ((caps2 & MMC_CAP2_HS200_1_8V_SDR && | 259 | if ((caps2 & MMC_CAP2_HS200_1_8V_SDR && |
260 | card_type & EXT_CSD_CARD_TYPE_SDR_1_8V) || | 260 | card_type & EXT_CSD_CARD_TYPE_SDR_1_8V) || |
261 | (caps2 & MMC_CAP2_HS200_1_2V_SDR && | 261 | (caps2 & MMC_CAP2_HS200_1_2V_SDR && |
262 | card_type & EXT_CSD_CARD_TYPE_SDR_1_2V)) | 262 | card_type & EXT_CSD_CARD_TYPE_SDR_1_2V)) |
263 | hs_max_dtr = MMC_HS200_MAX_DTR; | 263 | hs_max_dtr = MMC_HS200_MAX_DTR; |
264 | 264 | ||
265 | card->ext_csd.hs_max_dtr = hs_max_dtr; | 265 | card->ext_csd.hs_max_dtr = hs_max_dtr; |
266 | card->ext_csd.card_type = card_type; | 266 | card->ext_csd.card_type = card_type; |
267 | } | 267 | } |
268 | 268 | ||
269 | /* | 269 | /* |
270 | * Decode extended CSD. | 270 | * Decode extended CSD. |
271 | */ | 271 | */ |
272 | static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) | 272 | static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) |
273 | { | 273 | { |
274 | int err = 0, idx; | 274 | int err = 0, idx; |
275 | unsigned int part_size; | 275 | unsigned int part_size; |
276 | u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0; | 276 | u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0; |
277 | 277 | ||
278 | BUG_ON(!card); | 278 | BUG_ON(!card); |
279 | 279 | ||
280 | if (!ext_csd) | 280 | if (!ext_csd) |
281 | return 0; | 281 | return 0; |
282 | 282 | ||
283 | /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ | 283 | /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ |
284 | card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; | 284 | card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; |
285 | if (card->csd.structure == 3) { | 285 | if (card->csd.structure == 3) { |
286 | if (card->ext_csd.raw_ext_csd_structure > 2) { | 286 | if (card->ext_csd.raw_ext_csd_structure > 2) { |
287 | pr_err("%s: unrecognised EXT_CSD structure " | 287 | pr_err("%s: unrecognised EXT_CSD structure " |
288 | "version %d\n", mmc_hostname(card->host), | 288 | "version %d\n", mmc_hostname(card->host), |
289 | card->ext_csd.raw_ext_csd_structure); | 289 | card->ext_csd.raw_ext_csd_structure); |
290 | err = -EINVAL; | 290 | err = -EINVAL; |
291 | goto out; | 291 | goto out; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | card->ext_csd.rev = ext_csd[EXT_CSD_REV]; | 295 | card->ext_csd.rev = ext_csd[EXT_CSD_REV]; |
296 | if (card->ext_csd.rev > 7) { | 296 | if (card->ext_csd.rev > 8) { |
297 | pr_err("%s: unrecognised EXT_CSD revision %d\n", | 297 | pr_err("%s: unrecognised EXT_CSD revision %d\n", |
298 | mmc_hostname(card->host), card->ext_csd.rev); | 298 | mmc_hostname(card->host), card->ext_csd.rev); |
299 | err = -EINVAL; | 299 | err = -EINVAL; |
300 | goto out; | 300 | goto out; |
301 | } | 301 | } |
302 | 302 | ||
303 | card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; | 303 | card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; |
304 | card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; | 304 | card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; |
305 | card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; | 305 | card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; |
306 | card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; | 306 | card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; |
307 | if (card->ext_csd.rev >= 2) { | 307 | if (card->ext_csd.rev >= 2) { |
308 | card->ext_csd.sectors = | 308 | card->ext_csd.sectors = |
309 | ext_csd[EXT_CSD_SEC_CNT + 0] << 0 | | 309 | ext_csd[EXT_CSD_SEC_CNT + 0] << 0 | |
310 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | | 310 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | |
311 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | | 311 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | |
312 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; | 312 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; |
313 | 313 | ||
314 | /* Cards with density > 2GiB are sector addressed */ | 314 | /* Cards with density > 2GiB are sector addressed */ |
315 | if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) | 315 | if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) |
316 | mmc_card_set_blockaddr(card); | 316 | mmc_card_set_blockaddr(card); |
317 | } | 317 | } |
318 | 318 | ||
319 | card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; | 319 | card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; |
320 | mmc_select_card_type(card); | 320 | mmc_select_card_type(card); |
321 | 321 | ||
322 | card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; | 322 | card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; |
323 | card->ext_csd.raw_erase_timeout_mult = | 323 | card->ext_csd.raw_erase_timeout_mult = |
324 | ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; | 324 | ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; |
325 | card->ext_csd.raw_hc_erase_grp_size = | 325 | card->ext_csd.raw_hc_erase_grp_size = |
326 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; | 326 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; |
327 | if (card->ext_csd.rev >= 3) { | 327 | if (card->ext_csd.rev >= 3) { |
328 | u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; | 328 | u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; |
329 | card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; | 329 | card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; |
330 | 330 | ||
331 | /* EXT_CSD value is in units of 10ms, but we store in ms */ | 331 | /* EXT_CSD value is in units of 10ms, but we store in ms */ |
332 | card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; | 332 | card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; |
333 | 333 | ||
334 | /* Sleep / awake timeout in 100ns units */ | 334 | /* Sleep / awake timeout in 100ns units */ |
335 | if (sa_shift > 0 && sa_shift <= 0x17) | 335 | if (sa_shift > 0 && sa_shift <= 0x17) |
336 | card->ext_csd.sa_timeout = | 336 | card->ext_csd.sa_timeout = |
337 | 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; | 337 | 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; |
338 | card->ext_csd.erase_group_def = | 338 | card->ext_csd.erase_group_def = |
339 | ext_csd[EXT_CSD_ERASE_GROUP_DEF]; | 339 | ext_csd[EXT_CSD_ERASE_GROUP_DEF]; |
340 | card->ext_csd.hc_erase_timeout = 300 * | 340 | card->ext_csd.hc_erase_timeout = 300 * |
341 | ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; | 341 | ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; |
342 | card->ext_csd.hc_erase_size = | 342 | card->ext_csd.hc_erase_size = |
343 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; | 343 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; |
344 | 344 | ||
345 | card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; | 345 | card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; |
346 | 346 | ||
347 | /* | 347 | /* |
348 | * There are two boot regions of equal size, defined in | 348 | * There are two boot regions of equal size, defined in |
349 | * multiples of 128K. | 349 | * multiples of 128K. |
350 | */ | 350 | */ |
351 | if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { | 351 | if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { |
352 | for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { | 352 | for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { |
353 | part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; | 353 | part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; |
354 | mmc_part_add(card, part_size, | 354 | mmc_part_add(card, part_size, |
355 | EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, | 355 | EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, |
356 | "boot%d", idx, true, | 356 | "boot%d", idx, true, |
357 | MMC_BLK_DATA_AREA_BOOT); | 357 | MMC_BLK_DATA_AREA_BOOT); |
358 | } | 358 | } |
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | card->ext_csd.raw_hc_erase_gap_size = | 362 | card->ext_csd.raw_hc_erase_gap_size = |
363 | ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; | 363 | ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; |
364 | card->ext_csd.raw_sec_trim_mult = | 364 | card->ext_csd.raw_sec_trim_mult = |
365 | ext_csd[EXT_CSD_SEC_TRIM_MULT]; | 365 | ext_csd[EXT_CSD_SEC_TRIM_MULT]; |
366 | card->ext_csd.raw_sec_erase_mult = | 366 | card->ext_csd.raw_sec_erase_mult = |
367 | ext_csd[EXT_CSD_SEC_ERASE_MULT]; | 367 | ext_csd[EXT_CSD_SEC_ERASE_MULT]; |
368 | card->ext_csd.raw_sec_feature_support = | 368 | card->ext_csd.raw_sec_feature_support = |
369 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; | 369 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; |
370 | card->ext_csd.raw_trim_mult = | 370 | card->ext_csd.raw_trim_mult = |
371 | ext_csd[EXT_CSD_TRIM_MULT]; | 371 | ext_csd[EXT_CSD_TRIM_MULT]; |
372 | card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; | 372 | card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; |
373 | if (card->ext_csd.rev >= 4) { | 373 | if (card->ext_csd.rev >= 4) { |
374 | /* | 374 | /* |
375 | * Enhanced area feature support -- check whether the eMMC | 375 | * Enhanced area feature support -- check whether the eMMC |
376 | * card has the Enhanced area enabled. If so, export enhanced | 376 | * card has the Enhanced area enabled. If so, export enhanced |
377 | * area offset and size to user by adding sysfs interface. | 377 | * area offset and size to user by adding sysfs interface. |
378 | */ | 378 | */ |
379 | if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && | 379 | if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && |
380 | (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { | 380 | (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { |
381 | hc_erase_grp_sz = | 381 | hc_erase_grp_sz = |
382 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; | 382 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; |
383 | hc_wp_grp_sz = | 383 | hc_wp_grp_sz = |
384 | ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; | 384 | ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; |
385 | 385 | ||
386 | card->ext_csd.enhanced_area_en = 1; | 386 | card->ext_csd.enhanced_area_en = 1; |
387 | /* | 387 | /* |
388 | * calculate the enhanced data area offset, in bytes | 388 | * calculate the enhanced data area offset, in bytes |
389 | */ | 389 | */ |
390 | card->ext_csd.enhanced_area_offset = | 390 | card->ext_csd.enhanced_area_offset = |
391 | (ext_csd[139] << 24) + (ext_csd[138] << 16) + | 391 | (ext_csd[139] << 24) + (ext_csd[138] << 16) + |
392 | (ext_csd[137] << 8) + ext_csd[136]; | 392 | (ext_csd[137] << 8) + ext_csd[136]; |
393 | if (mmc_card_blockaddr(card)) | 393 | if (mmc_card_blockaddr(card)) |
394 | card->ext_csd.enhanced_area_offset <<= 9; | 394 | card->ext_csd.enhanced_area_offset <<= 9; |
395 | /* | 395 | /* |
396 | * calculate the enhanced data area size, in kilobytes | 396 | * calculate the enhanced data area size, in kilobytes |
397 | */ | 397 | */ |
398 | card->ext_csd.enhanced_area_size = | 398 | card->ext_csd.enhanced_area_size = |
399 | (ext_csd[142] << 16) + (ext_csd[141] << 8) + | 399 | (ext_csd[142] << 16) + (ext_csd[141] << 8) + |
400 | ext_csd[140]; | 400 | ext_csd[140]; |
401 | card->ext_csd.enhanced_area_size *= | 401 | card->ext_csd.enhanced_area_size *= |
402 | (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); | 402 | (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); |
403 | card->ext_csd.enhanced_area_size <<= 9; | 403 | card->ext_csd.enhanced_area_size <<= 9; |
404 | } else { | 404 | } else { |
405 | /* | 405 | /* |
406 | * If the enhanced area is not enabled, disable these | 406 | * If the enhanced area is not enabled, disable these |
407 | * device attributes. | 407 | * device attributes. |
408 | */ | 408 | */ |
409 | card->ext_csd.enhanced_area_offset = -EINVAL; | 409 | card->ext_csd.enhanced_area_offset = -EINVAL; |
410 | card->ext_csd.enhanced_area_size = -EINVAL; | 410 | card->ext_csd.enhanced_area_size = -EINVAL; |
411 | } | 411 | } |
412 | 412 | ||
413 | /* | 413 | /* |
414 | * General purpose partition feature support -- | 414 | * General purpose partition feature support -- |
415 | * If ext_csd has the size of general purpose partitions, | 415 | * If ext_csd has the size of general purpose partitions, |
416 | * set size, part_cfg, partition name in mmc_part. | 416 | * set size, part_cfg, partition name in mmc_part. |
417 | */ | 417 | */ |
418 | if (ext_csd[EXT_CSD_PARTITION_SUPPORT] & | 418 | if (ext_csd[EXT_CSD_PARTITION_SUPPORT] & |
419 | EXT_CSD_PART_SUPPORT_PART_EN) { | 419 | EXT_CSD_PART_SUPPORT_PART_EN) { |
420 | if (card->ext_csd.enhanced_area_en != 1) { | 420 | if (card->ext_csd.enhanced_area_en != 1) { |
421 | hc_erase_grp_sz = | 421 | hc_erase_grp_sz = |
422 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; | 422 | ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; |
423 | hc_wp_grp_sz = | 423 | hc_wp_grp_sz = |
424 | ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; | 424 | ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; |
425 | 425 | ||
426 | card->ext_csd.enhanced_area_en = 1; | 426 | card->ext_csd.enhanced_area_en = 1; |
427 | } | 427 | } |
428 | 428 | ||
429 | for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) { | 429 | for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) { |
430 | if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] && | 430 | if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] && |
431 | !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] && | 431 | !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] && |
432 | !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]) | 432 | !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]) |
433 | continue; | 433 | continue; |
434 | part_size = | 434 | part_size = |
435 | (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2] | 435 | (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2] |
436 | << 16) + | 436 | << 16) + |
437 | (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] | 437 | (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] |
438 | << 8) + | 438 | << 8) + |
439 | ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3]; | 439 | ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3]; |
440 | part_size *= (size_t)(hc_erase_grp_sz * | 440 | part_size *= (size_t)(hc_erase_grp_sz * |
441 | hc_wp_grp_sz); | 441 | hc_wp_grp_sz); |
442 | mmc_part_add(card, part_size << 19, | 442 | mmc_part_add(card, part_size << 19, |
443 | EXT_CSD_PART_CONFIG_ACC_GP0 + idx, | 443 | EXT_CSD_PART_CONFIG_ACC_GP0 + idx, |
444 | "gp%d", idx, false, | 444 | "gp%d", idx, false, |
445 | MMC_BLK_DATA_AREA_GP); | 445 | MMC_BLK_DATA_AREA_GP); |
446 | } | 446 | } |
447 | } | 447 | } |
448 | card->ext_csd.sec_trim_mult = | 448 | card->ext_csd.sec_trim_mult = |
449 | ext_csd[EXT_CSD_SEC_TRIM_MULT]; | 449 | ext_csd[EXT_CSD_SEC_TRIM_MULT]; |
450 | card->ext_csd.sec_erase_mult = | 450 | card->ext_csd.sec_erase_mult = |
451 | ext_csd[EXT_CSD_SEC_ERASE_MULT]; | 451 | ext_csd[EXT_CSD_SEC_ERASE_MULT]; |
452 | card->ext_csd.sec_feature_support = | 452 | card->ext_csd.sec_feature_support = |
453 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; | 453 | ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; |
454 | card->ext_csd.trim_timeout = 300 * | 454 | card->ext_csd.trim_timeout = 300 * |
455 | ext_csd[EXT_CSD_TRIM_MULT]; | 455 | ext_csd[EXT_CSD_TRIM_MULT]; |
456 | 456 | ||
457 | /* | 457 | /* |
458 | * Note that the call to mmc_part_add above defaults to read | 458 | * Note that the call to mmc_part_add above defaults to read |
459 | * only. If this default assumption is changed, the call must | 459 | * only. If this default assumption is changed, the call must |
460 | * take into account the value of boot_locked below. | 460 | * take into account the value of boot_locked below. |
461 | */ | 461 | */ |
462 | card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; | 462 | card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; |
463 | card->ext_csd.boot_ro_lockable = true; | 463 | card->ext_csd.boot_ro_lockable = true; |
464 | 464 | ||
465 | /* Save power class values */ | 465 | /* Save power class values */ |
466 | card->ext_csd.raw_pwr_cl_52_195 = | 466 | card->ext_csd.raw_pwr_cl_52_195 = |
467 | ext_csd[EXT_CSD_PWR_CL_52_195]; | 467 | ext_csd[EXT_CSD_PWR_CL_52_195]; |
468 | card->ext_csd.raw_pwr_cl_26_195 = | 468 | card->ext_csd.raw_pwr_cl_26_195 = |
469 | ext_csd[EXT_CSD_PWR_CL_26_195]; | 469 | ext_csd[EXT_CSD_PWR_CL_26_195]; |
470 | card->ext_csd.raw_pwr_cl_52_360 = | 470 | card->ext_csd.raw_pwr_cl_52_360 = |
471 | ext_csd[EXT_CSD_PWR_CL_52_360]; | 471 | ext_csd[EXT_CSD_PWR_CL_52_360]; |
472 | card->ext_csd.raw_pwr_cl_26_360 = | 472 | card->ext_csd.raw_pwr_cl_26_360 = |
473 | ext_csd[EXT_CSD_PWR_CL_26_360]; | 473 | ext_csd[EXT_CSD_PWR_CL_26_360]; |
474 | card->ext_csd.raw_pwr_cl_200_195 = | 474 | card->ext_csd.raw_pwr_cl_200_195 = |
475 | ext_csd[EXT_CSD_PWR_CL_200_195]; | 475 | ext_csd[EXT_CSD_PWR_CL_200_195]; |
476 | card->ext_csd.raw_pwr_cl_200_360 = | 476 | card->ext_csd.raw_pwr_cl_200_360 = |
477 | ext_csd[EXT_CSD_PWR_CL_200_360]; | 477 | ext_csd[EXT_CSD_PWR_CL_200_360]; |
478 | card->ext_csd.raw_pwr_cl_ddr_52_195 = | 478 | card->ext_csd.raw_pwr_cl_ddr_52_195 = |
479 | ext_csd[EXT_CSD_PWR_CL_DDR_52_195]; | 479 | ext_csd[EXT_CSD_PWR_CL_DDR_52_195]; |
480 | card->ext_csd.raw_pwr_cl_ddr_52_360 = | 480 | card->ext_csd.raw_pwr_cl_ddr_52_360 = |
481 | ext_csd[EXT_CSD_PWR_CL_DDR_52_360]; | 481 | ext_csd[EXT_CSD_PWR_CL_DDR_52_360]; |
482 | } | 482 | } |
483 | 483 | ||
484 | if (card->ext_csd.rev >= 5) { | 484 | if (card->ext_csd.rev >= 5) { |
485 | /* Adjust production date as per JEDEC JESD84-B451 */ | 485 | /* Adjust production date as per JEDEC JESD84-B451 */ |
486 | if (card->cid.year < 2010) | 486 | if (card->cid.year < 2010) |
487 | card->cid.year += 16; | 487 | card->cid.year += 16; |
488 | 488 | ||
489 | /* check whether the eMMC card supports BKOPS */ | 489 | /* check whether the eMMC card supports BKOPS */ |
490 | if (ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1) { | 490 | if (ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1) { |
491 | card->ext_csd.bkops = 1; | 491 | card->ext_csd.bkops = 1; |
492 | card->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN]; | 492 | card->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN]; |
493 | card->ext_csd.raw_bkops_status = | 493 | card->ext_csd.raw_bkops_status = |
494 | ext_csd[EXT_CSD_BKOPS_STATUS]; | 494 | ext_csd[EXT_CSD_BKOPS_STATUS]; |
495 | if (!card->ext_csd.bkops_en) | 495 | if (!card->ext_csd.bkops_en) |
496 | pr_info("%s: BKOPS_EN bit is not set\n", | 496 | pr_info("%s: BKOPS_EN bit is not set\n", |
497 | mmc_hostname(card->host)); | 497 | mmc_hostname(card->host)); |
498 | } | 498 | } |
499 | 499 | ||
500 | /* check whether the eMMC card supports HPI */ | 500 | /* check whether the eMMC card supports HPI */ |
501 | if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { | 501 | if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { |
502 | card->ext_csd.hpi = 1; | 502 | card->ext_csd.hpi = 1; |
503 | if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) | 503 | if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) |
504 | card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; | 504 | card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; |
505 | else | 505 | else |
506 | card->ext_csd.hpi_cmd = MMC_SEND_STATUS; | 506 | card->ext_csd.hpi_cmd = MMC_SEND_STATUS; |
507 | /* | 507 | /* |
508 | * Indicate the maximum timeout to close | 508 | * Indicate the maximum timeout to close |
509 | * a command interrupted by HPI | 509 | * a command interrupted by HPI |
510 | */ | 510 | */ |
511 | card->ext_csd.out_of_int_time = | 511 | card->ext_csd.out_of_int_time = |
512 | ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; | 512 | ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; |
513 | } | 513 | } |
514 | 514 | ||
515 | card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; | 515 | card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; |
516 | card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; | 516 | card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; |
517 | 517 | ||
518 | /* | 518 | /* |
519 | * RPMB regions are defined in multiples of 128K. | 519 | * RPMB regions are defined in multiples of 128K. |
520 | */ | 520 | */ |
521 | card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; | 521 | card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; |
522 | if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { | 522 | if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { |
523 | mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, | 523 | mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, |
524 | EXT_CSD_PART_CONFIG_ACC_RPMB, | 524 | EXT_CSD_PART_CONFIG_ACC_RPMB, |
525 | "rpmb", 0, false, | 525 | "rpmb", 0, false, |
526 | MMC_BLK_DATA_AREA_RPMB); | 526 | MMC_BLK_DATA_AREA_RPMB); |
527 | } | 527 | } |
528 | } | 528 | } |
529 | 529 | ||
530 | card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; | 530 | card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; |
531 | if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) | 531 | if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) |
532 | card->erased_byte = 0xFF; | 532 | card->erased_byte = 0xFF; |
533 | else | 533 | else |
534 | card->erased_byte = 0x0; | 534 | card->erased_byte = 0x0; |
535 | 535 | ||
536 | /* eMMC v4.5 or later */ | 536 | /* eMMC v4.5 or later */ |
537 | if (card->ext_csd.rev >= 6) { | 537 | if (card->ext_csd.rev >= 6) { |
538 | card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; | 538 | card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; |
539 | 539 | ||
540 | card->ext_csd.generic_cmd6_time = 10 * | 540 | card->ext_csd.generic_cmd6_time = 10 * |
541 | ext_csd[EXT_CSD_GENERIC_CMD6_TIME]; | 541 | ext_csd[EXT_CSD_GENERIC_CMD6_TIME]; |
542 | card->ext_csd.power_off_longtime = 10 * | 542 | card->ext_csd.power_off_longtime = 10 * |
543 | ext_csd[EXT_CSD_POWER_OFF_LONG_TIME]; | 543 | ext_csd[EXT_CSD_POWER_OFF_LONG_TIME]; |
544 | 544 | ||
545 | card->ext_csd.cache_size = | 545 | card->ext_csd.cache_size = |
546 | ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 | | 546 | ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 | |
547 | ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 | | 547 | ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 | |
548 | ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 | | 548 | ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 | |
549 | ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24; | 549 | ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24; |
550 | 550 | ||
551 | if (ext_csd[EXT_CSD_DATA_SECTOR_SIZE] == 1) | 551 | if (ext_csd[EXT_CSD_DATA_SECTOR_SIZE] == 1) |
552 | card->ext_csd.data_sector_size = 4096; | 552 | card->ext_csd.data_sector_size = 4096; |
553 | else | 553 | else |
554 | card->ext_csd.data_sector_size = 512; | 554 | card->ext_csd.data_sector_size = 512; |
555 | 555 | ||
556 | if ((ext_csd[EXT_CSD_DATA_TAG_SUPPORT] & 1) && | 556 | if ((ext_csd[EXT_CSD_DATA_TAG_SUPPORT] & 1) && |
557 | (ext_csd[EXT_CSD_TAG_UNIT_SIZE] <= 8)) { | 557 | (ext_csd[EXT_CSD_TAG_UNIT_SIZE] <= 8)) { |
558 | card->ext_csd.data_tag_unit_size = | 558 | card->ext_csd.data_tag_unit_size = |
559 | ((unsigned int) 1 << ext_csd[EXT_CSD_TAG_UNIT_SIZE]) * | 559 | ((unsigned int) 1 << ext_csd[EXT_CSD_TAG_UNIT_SIZE]) * |
560 | (card->ext_csd.data_sector_size); | 560 | (card->ext_csd.data_sector_size); |
561 | } else { | 561 | } else { |
562 | card->ext_csd.data_tag_unit_size = 0; | 562 | card->ext_csd.data_tag_unit_size = 0; |
563 | } | 563 | } |
564 | 564 | ||
565 | card->ext_csd.max_packed_writes = | 565 | card->ext_csd.max_packed_writes = |
566 | ext_csd[EXT_CSD_MAX_PACKED_WRITES]; | 566 | ext_csd[EXT_CSD_MAX_PACKED_WRITES]; |
567 | card->ext_csd.max_packed_reads = | 567 | card->ext_csd.max_packed_reads = |
568 | ext_csd[EXT_CSD_MAX_PACKED_READS]; | 568 | ext_csd[EXT_CSD_MAX_PACKED_READS]; |
569 | } else { | 569 | } else { |
570 | card->ext_csd.data_sector_size = 512; | 570 | card->ext_csd.data_sector_size = 512; |
571 | } | 571 | } |
572 | 572 | ||
573 | out: | 573 | out: |
574 | return err; | 574 | return err; |
575 | } | 575 | } |
576 | 576 | ||
577 | static inline void mmc_free_ext_csd(u8 *ext_csd) | 577 | static inline void mmc_free_ext_csd(u8 *ext_csd) |
578 | { | 578 | { |
579 | kfree(ext_csd); | 579 | kfree(ext_csd); |
580 | } | 580 | } |
581 | 581 | ||
582 | 582 | ||
583 | static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) | 583 | static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) |
584 | { | 584 | { |
585 | u8 *bw_ext_csd; | 585 | u8 *bw_ext_csd; |
586 | int err; | 586 | int err; |
587 | 587 | ||
588 | if (bus_width == MMC_BUS_WIDTH_1) | 588 | if (bus_width == MMC_BUS_WIDTH_1) |
589 | return 0; | 589 | return 0; |
590 | 590 | ||
591 | err = mmc_get_ext_csd(card, &bw_ext_csd); | 591 | err = mmc_get_ext_csd(card, &bw_ext_csd); |
592 | 592 | ||
593 | if (err || bw_ext_csd == NULL) { | 593 | if (err || bw_ext_csd == NULL) { |
594 | err = -EINVAL; | 594 | err = -EINVAL; |
595 | goto out; | 595 | goto out; |
596 | } | 596 | } |
597 | 597 | ||
598 | /* only compare read only fields */ | 598 | /* only compare read only fields */ |
599 | err = !((card->ext_csd.raw_partition_support == | 599 | err = !((card->ext_csd.raw_partition_support == |
600 | bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) && | 600 | bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) && |
601 | (card->ext_csd.raw_erased_mem_count == | 601 | (card->ext_csd.raw_erased_mem_count == |
602 | bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) && | 602 | bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) && |
603 | (card->ext_csd.rev == | 603 | (card->ext_csd.rev == |
604 | bw_ext_csd[EXT_CSD_REV]) && | 604 | bw_ext_csd[EXT_CSD_REV]) && |
605 | (card->ext_csd.raw_ext_csd_structure == | 605 | (card->ext_csd.raw_ext_csd_structure == |
606 | bw_ext_csd[EXT_CSD_STRUCTURE]) && | 606 | bw_ext_csd[EXT_CSD_STRUCTURE]) && |
607 | (card->ext_csd.raw_card_type == | 607 | (card->ext_csd.raw_card_type == |
608 | bw_ext_csd[EXT_CSD_CARD_TYPE]) && | 608 | bw_ext_csd[EXT_CSD_CARD_TYPE]) && |
609 | (card->ext_csd.raw_s_a_timeout == | 609 | (card->ext_csd.raw_s_a_timeout == |
610 | bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) && | 610 | bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) && |
611 | (card->ext_csd.raw_hc_erase_gap_size == | 611 | (card->ext_csd.raw_hc_erase_gap_size == |
612 | bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) && | 612 | bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) && |
613 | (card->ext_csd.raw_erase_timeout_mult == | 613 | (card->ext_csd.raw_erase_timeout_mult == |
614 | bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) && | 614 | bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) && |
615 | (card->ext_csd.raw_hc_erase_grp_size == | 615 | (card->ext_csd.raw_hc_erase_grp_size == |
616 | bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) && | 616 | bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) && |
617 | (card->ext_csd.raw_sec_trim_mult == | 617 | (card->ext_csd.raw_sec_trim_mult == |
618 | bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) && | 618 | bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) && |
619 | (card->ext_csd.raw_sec_erase_mult == | 619 | (card->ext_csd.raw_sec_erase_mult == |
620 | bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) && | 620 | bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) && |
621 | (card->ext_csd.raw_sec_feature_support == | 621 | (card->ext_csd.raw_sec_feature_support == |
622 | bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) && | 622 | bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) && |
623 | (card->ext_csd.raw_trim_mult == | 623 | (card->ext_csd.raw_trim_mult == |
624 | bw_ext_csd[EXT_CSD_TRIM_MULT]) && | 624 | bw_ext_csd[EXT_CSD_TRIM_MULT]) && |
625 | (card->ext_csd.raw_sectors[0] == | 625 | (card->ext_csd.raw_sectors[0] == |
626 | bw_ext_csd[EXT_CSD_SEC_CNT + 0]) && | 626 | bw_ext_csd[EXT_CSD_SEC_CNT + 0]) && |
627 | (card->ext_csd.raw_sectors[1] == | 627 | (card->ext_csd.raw_sectors[1] == |
628 | bw_ext_csd[EXT_CSD_SEC_CNT + 1]) && | 628 | bw_ext_csd[EXT_CSD_SEC_CNT + 1]) && |
629 | (card->ext_csd.raw_sectors[2] == | 629 | (card->ext_csd.raw_sectors[2] == |
630 | bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && | 630 | bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && |
631 | (card->ext_csd.raw_sectors[3] == | 631 | (card->ext_csd.raw_sectors[3] == |
632 | bw_ext_csd[EXT_CSD_SEC_CNT + 3]) && | 632 | bw_ext_csd[EXT_CSD_SEC_CNT + 3]) && |
633 | (card->ext_csd.raw_pwr_cl_52_195 == | 633 | (card->ext_csd.raw_pwr_cl_52_195 == |
634 | bw_ext_csd[EXT_CSD_PWR_CL_52_195]) && | 634 | bw_ext_csd[EXT_CSD_PWR_CL_52_195]) && |
635 | (card->ext_csd.raw_pwr_cl_26_195 == | 635 | (card->ext_csd.raw_pwr_cl_26_195 == |
636 | bw_ext_csd[EXT_CSD_PWR_CL_26_195]) && | 636 | bw_ext_csd[EXT_CSD_PWR_CL_26_195]) && |
637 | (card->ext_csd.raw_pwr_cl_52_360 == | 637 | (card->ext_csd.raw_pwr_cl_52_360 == |
638 | bw_ext_csd[EXT_CSD_PWR_CL_52_360]) && | 638 | bw_ext_csd[EXT_CSD_PWR_CL_52_360]) && |
639 | (card->ext_csd.raw_pwr_cl_26_360 == | 639 | (card->ext_csd.raw_pwr_cl_26_360 == |
640 | bw_ext_csd[EXT_CSD_PWR_CL_26_360]) && | 640 | bw_ext_csd[EXT_CSD_PWR_CL_26_360]) && |
641 | (card->ext_csd.raw_pwr_cl_200_195 == | 641 | (card->ext_csd.raw_pwr_cl_200_195 == |
642 | bw_ext_csd[EXT_CSD_PWR_CL_200_195]) && | 642 | bw_ext_csd[EXT_CSD_PWR_CL_200_195]) && |
643 | (card->ext_csd.raw_pwr_cl_200_360 == | 643 | (card->ext_csd.raw_pwr_cl_200_360 == |
644 | bw_ext_csd[EXT_CSD_PWR_CL_200_360]) && | 644 | bw_ext_csd[EXT_CSD_PWR_CL_200_360]) && |
645 | (card->ext_csd.raw_pwr_cl_ddr_52_195 == | 645 | (card->ext_csd.raw_pwr_cl_ddr_52_195 == |
646 | bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_195]) && | 646 | bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_195]) && |
647 | (card->ext_csd.raw_pwr_cl_ddr_52_360 == | 647 | (card->ext_csd.raw_pwr_cl_ddr_52_360 == |
648 | bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_360])); | 648 | bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_360])); |
649 | if (err) | 649 | if (err) |
650 | err = -EINVAL; | 650 | err = -EINVAL; |
651 | 651 | ||
652 | out: | 652 | out: |
653 | mmc_free_ext_csd(bw_ext_csd); | 653 | mmc_free_ext_csd(bw_ext_csd); |
654 | return err; | 654 | return err; |
655 | } | 655 | } |
656 | 656 | ||
657 | MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], | 657 | MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], |
658 | card->raw_cid[2], card->raw_cid[3]); | 658 | card->raw_cid[2], card->raw_cid[3]); |
659 | MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], | 659 | MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], |
660 | card->raw_csd[2], card->raw_csd[3]); | 660 | card->raw_csd[2], card->raw_csd[3]); |
661 | MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); | 661 | MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); |
662 | MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); | 662 | MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); |
663 | MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); | 663 | MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); |
664 | MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); | 664 | MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); |
665 | MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); | 665 | MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); |
666 | MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); | 666 | MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); |
667 | MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); | 667 | MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); |
668 | MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); | 668 | MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); |
669 | MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv); | 669 | MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv); |
670 | MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); | 670 | MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); |
671 | MMC_DEV_ATTR(enhanced_area_offset, "%llu\n", | 671 | MMC_DEV_ATTR(enhanced_area_offset, "%llu\n", |
672 | card->ext_csd.enhanced_area_offset); | 672 | card->ext_csd.enhanced_area_offset); |
673 | MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size); | 673 | MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size); |
674 | MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult); | 674 | MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult); |
675 | MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors); | 675 | MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors); |
676 | 676 | ||
677 | static struct attribute *mmc_std_attrs[] = { | 677 | static struct attribute *mmc_std_attrs[] = { |
678 | &dev_attr_cid.attr, | 678 | &dev_attr_cid.attr, |
679 | &dev_attr_csd.attr, | 679 | &dev_attr_csd.attr, |
680 | &dev_attr_date.attr, | 680 | &dev_attr_date.attr, |
681 | &dev_attr_erase_size.attr, | 681 | &dev_attr_erase_size.attr, |
682 | &dev_attr_preferred_erase_size.attr, | 682 | &dev_attr_preferred_erase_size.attr, |
683 | &dev_attr_fwrev.attr, | 683 | &dev_attr_fwrev.attr, |
684 | &dev_attr_hwrev.attr, | 684 | &dev_attr_hwrev.attr, |
685 | &dev_attr_manfid.attr, | 685 | &dev_attr_manfid.attr, |
686 | &dev_attr_name.attr, | 686 | &dev_attr_name.attr, |
687 | &dev_attr_oemid.attr, | 687 | &dev_attr_oemid.attr, |
688 | &dev_attr_prv.attr, | 688 | &dev_attr_prv.attr, |
689 | &dev_attr_serial.attr, | 689 | &dev_attr_serial.attr, |
690 | &dev_attr_enhanced_area_offset.attr, | 690 | &dev_attr_enhanced_area_offset.attr, |
691 | &dev_attr_enhanced_area_size.attr, | 691 | &dev_attr_enhanced_area_size.attr, |
692 | &dev_attr_raw_rpmb_size_mult.attr, | 692 | &dev_attr_raw_rpmb_size_mult.attr, |
693 | &dev_attr_rel_sectors.attr, | 693 | &dev_attr_rel_sectors.attr, |
694 | NULL, | 694 | NULL, |
695 | }; | 695 | }; |
696 | 696 | ||
697 | static struct attribute_group mmc_std_attr_group = { | 697 | static struct attribute_group mmc_std_attr_group = { |
698 | .attrs = mmc_std_attrs, | 698 | .attrs = mmc_std_attrs, |
699 | }; | 699 | }; |
700 | 700 | ||
701 | static const struct attribute_group *mmc_attr_groups[] = { | 701 | static const struct attribute_group *mmc_attr_groups[] = { |
702 | &mmc_std_attr_group, | 702 | &mmc_std_attr_group, |
703 | NULL, | 703 | NULL, |
704 | }; | 704 | }; |
705 | 705 | ||
706 | static struct device_type mmc_type = { | 706 | static struct device_type mmc_type = { |
707 | .groups = mmc_attr_groups, | 707 | .groups = mmc_attr_groups, |
708 | }; | 708 | }; |
709 | 709 | ||
710 | /* | 710 | /* |
711 | * Select the PowerClass for the current bus width | 711 | * Select the PowerClass for the current bus width |
712 | * If power class is defined for 4/8 bit bus in the | 712 | * If power class is defined for 4/8 bit bus in the |
713 | * extended CSD register, select it by executing the | 713 | * extended CSD register, select it by executing the |
714 | * mmc_switch command. | 714 | * mmc_switch command. |
715 | */ | 715 | */ |
716 | static int mmc_select_powerclass(struct mmc_card *card, | 716 | static int mmc_select_powerclass(struct mmc_card *card, |
717 | unsigned int bus_width) | 717 | unsigned int bus_width) |
718 | { | 718 | { |
719 | int err = 0; | 719 | int err = 0; |
720 | unsigned int pwrclass_val = 0; | 720 | unsigned int pwrclass_val = 0; |
721 | struct mmc_host *host; | 721 | struct mmc_host *host; |
722 | 722 | ||
723 | BUG_ON(!card); | 723 | BUG_ON(!card); |
724 | 724 | ||
725 | host = card->host; | 725 | host = card->host; |
726 | BUG_ON(!host); | 726 | BUG_ON(!host); |
727 | 727 | ||
728 | /* Power class selection is supported for versions >= 4.0 */ | 728 | /* Power class selection is supported for versions >= 4.0 */ |
729 | if (card->csd.mmca_vsn < CSD_SPEC_VER_4) | 729 | if (card->csd.mmca_vsn < CSD_SPEC_VER_4) |
730 | return 0; | 730 | return 0; |
731 | 731 | ||
732 | /* Power class values are defined only for 4/8 bit bus */ | 732 | /* Power class values are defined only for 4/8 bit bus */ |
733 | if (bus_width == EXT_CSD_BUS_WIDTH_1) | 733 | if (bus_width == EXT_CSD_BUS_WIDTH_1) |
734 | return 0; | 734 | return 0; |
735 | 735 | ||
736 | switch (1 << host->ios.vdd) { | 736 | switch (1 << host->ios.vdd) { |
737 | case MMC_VDD_165_195: | 737 | case MMC_VDD_165_195: |
738 | if (host->ios.clock <= 26000000) | 738 | if (host->ios.clock <= 26000000) |
739 | pwrclass_val = card->ext_csd.raw_pwr_cl_26_195; | 739 | pwrclass_val = card->ext_csd.raw_pwr_cl_26_195; |
740 | else if (host->ios.clock <= 52000000) | 740 | else if (host->ios.clock <= 52000000) |
741 | pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? | 741 | pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? |
742 | card->ext_csd.raw_pwr_cl_52_195 : | 742 | card->ext_csd.raw_pwr_cl_52_195 : |
743 | card->ext_csd.raw_pwr_cl_ddr_52_195; | 743 | card->ext_csd.raw_pwr_cl_ddr_52_195; |
744 | else if (host->ios.clock <= 200000000) | 744 | else if (host->ios.clock <= 200000000) |
745 | pwrclass_val = card->ext_csd.raw_pwr_cl_200_195; | 745 | pwrclass_val = card->ext_csd.raw_pwr_cl_200_195; |
746 | break; | 746 | break; |
747 | case MMC_VDD_27_28: | 747 | case MMC_VDD_27_28: |
748 | case MMC_VDD_28_29: | 748 | case MMC_VDD_28_29: |
749 | case MMC_VDD_29_30: | 749 | case MMC_VDD_29_30: |
750 | case MMC_VDD_30_31: | 750 | case MMC_VDD_30_31: |
751 | case MMC_VDD_31_32: | 751 | case MMC_VDD_31_32: |
752 | case MMC_VDD_32_33: | 752 | case MMC_VDD_32_33: |
753 | case MMC_VDD_33_34: | 753 | case MMC_VDD_33_34: |
754 | case MMC_VDD_34_35: | 754 | case MMC_VDD_34_35: |
755 | case MMC_VDD_35_36: | 755 | case MMC_VDD_35_36: |
756 | if (host->ios.clock <= 26000000) | 756 | if (host->ios.clock <= 26000000) |
757 | pwrclass_val = card->ext_csd.raw_pwr_cl_26_360; | 757 | pwrclass_val = card->ext_csd.raw_pwr_cl_26_360; |
758 | else if (host->ios.clock <= 52000000) | 758 | else if (host->ios.clock <= 52000000) |
759 | pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? | 759 | pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? |
760 | card->ext_csd.raw_pwr_cl_52_360 : | 760 | card->ext_csd.raw_pwr_cl_52_360 : |
761 | card->ext_csd.raw_pwr_cl_ddr_52_360; | 761 | card->ext_csd.raw_pwr_cl_ddr_52_360; |
762 | else if (host->ios.clock <= 200000000) | 762 | else if (host->ios.clock <= 200000000) |
763 | pwrclass_val = card->ext_csd.raw_pwr_cl_200_360; | 763 | pwrclass_val = card->ext_csd.raw_pwr_cl_200_360; |
764 | break; | 764 | break; |
765 | default: | 765 | default: |
766 | pr_warning("%s: Voltage range not supported " | 766 | pr_warning("%s: Voltage range not supported " |
767 | "for power class.\n", mmc_hostname(host)); | 767 | "for power class.\n", mmc_hostname(host)); |
768 | return -EINVAL; | 768 | return -EINVAL; |
769 | } | 769 | } |
770 | 770 | ||
771 | if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8)) | 771 | if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8)) |
772 | pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >> | 772 | pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >> |
773 | EXT_CSD_PWR_CL_8BIT_SHIFT; | 773 | EXT_CSD_PWR_CL_8BIT_SHIFT; |
774 | else | 774 | else |
775 | pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >> | 775 | pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >> |
776 | EXT_CSD_PWR_CL_4BIT_SHIFT; | 776 | EXT_CSD_PWR_CL_4BIT_SHIFT; |
777 | 777 | ||
778 | /* If the power class is different from the default value */ | 778 | /* If the power class is different from the default value */ |
779 | if (pwrclass_val > 0) { | 779 | if (pwrclass_val > 0) { |
780 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 780 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
781 | EXT_CSD_POWER_CLASS, | 781 | EXT_CSD_POWER_CLASS, |
782 | pwrclass_val, | 782 | pwrclass_val, |
783 | card->ext_csd.generic_cmd6_time); | 783 | card->ext_csd.generic_cmd6_time); |
784 | } | 784 | } |
785 | 785 | ||
786 | return err; | 786 | return err; |
787 | } | 787 | } |
788 | 788 | ||
789 | /* | 789 | /* |
790 | * Selects the desired buswidth and switch to the HS200 mode | 790 | * Selects the desired buswidth and switch to the HS200 mode |
791 | * if bus width set without error | 791 | * if bus width set without error |
792 | */ | 792 | */ |
793 | static int mmc_select_hs200(struct mmc_card *card) | 793 | static int mmc_select_hs200(struct mmc_card *card) |
794 | { | 794 | { |
795 | int idx, err = -EINVAL; | 795 | int idx, err = -EINVAL; |
796 | struct mmc_host *host; | 796 | struct mmc_host *host; |
797 | static unsigned ext_csd_bits[] = { | 797 | static unsigned ext_csd_bits[] = { |
798 | EXT_CSD_BUS_WIDTH_4, | 798 | EXT_CSD_BUS_WIDTH_4, |
799 | EXT_CSD_BUS_WIDTH_8, | 799 | EXT_CSD_BUS_WIDTH_8, |
800 | }; | 800 | }; |
801 | static unsigned bus_widths[] = { | 801 | static unsigned bus_widths[] = { |
802 | MMC_BUS_WIDTH_4, | 802 | MMC_BUS_WIDTH_4, |
803 | MMC_BUS_WIDTH_8, | 803 | MMC_BUS_WIDTH_8, |
804 | }; | 804 | }; |
805 | 805 | ||
806 | BUG_ON(!card); | 806 | BUG_ON(!card); |
807 | 807 | ||
808 | host = card->host; | 808 | host = card->host; |
809 | 809 | ||
810 | if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V && | 810 | if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V && |
811 | host->caps2 & MMC_CAP2_HS200_1_2V_SDR) | 811 | host->caps2 & MMC_CAP2_HS200_1_2V_SDR) |
812 | err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120); | 812 | err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120); |
813 | 813 | ||
814 | if (err && card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_8V && | 814 | if (err && card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_8V && |
815 | host->caps2 & MMC_CAP2_HS200_1_8V_SDR) | 815 | host->caps2 & MMC_CAP2_HS200_1_8V_SDR) |
816 | err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); | 816 | err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); |
817 | 817 | ||
818 | /* If fails try again during next card power cycle */ | 818 | /* If fails try again during next card power cycle */ |
819 | if (err) | 819 | if (err) |
820 | goto err; | 820 | goto err; |
821 | 821 | ||
822 | idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0; | 822 | idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 1 : 0; |
823 | 823 | ||
824 | /* | 824 | /* |
825 | * Unlike SD, MMC cards dont have a configuration register to notify | 825 | * Unlike SD, MMC cards dont have a configuration register to notify |
826 | * supported bus width. So bus test command should be run to identify | 826 | * supported bus width. So bus test command should be run to identify |
827 | * the supported bus width or compare the ext csd values of current | 827 | * the supported bus width or compare the ext csd values of current |
828 | * bus width and ext csd values of 1 bit mode read earlier. | 828 | * bus width and ext csd values of 1 bit mode read earlier. |
829 | */ | 829 | */ |
830 | for (; idx >= 0; idx--) { | 830 | for (; idx >= 0; idx--) { |
831 | 831 | ||
832 | /* | 832 | /* |
833 | * Host is capable of 8bit transfer, then switch | 833 | * Host is capable of 8bit transfer, then switch |
834 | * the device to work in 8bit transfer mode. If the | 834 | * the device to work in 8bit transfer mode. If the |
835 | * mmc switch command returns error then switch to | 835 | * mmc switch command returns error then switch to |
836 | * 4bit transfer mode. On success set the corresponding | 836 | * 4bit transfer mode. On success set the corresponding |
837 | * bus width on the host. | 837 | * bus width on the host. |
838 | */ | 838 | */ |
839 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 839 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
840 | EXT_CSD_BUS_WIDTH, | 840 | EXT_CSD_BUS_WIDTH, |
841 | ext_csd_bits[idx], | 841 | ext_csd_bits[idx], |
842 | card->ext_csd.generic_cmd6_time); | 842 | card->ext_csd.generic_cmd6_time); |
843 | if (err) | 843 | if (err) |
844 | continue; | 844 | continue; |
845 | 845 | ||
846 | mmc_set_bus_width(card->host, bus_widths[idx]); | 846 | mmc_set_bus_width(card->host, bus_widths[idx]); |
847 | 847 | ||
848 | if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) | 848 | if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) |
849 | err = mmc_compare_ext_csds(card, bus_widths[idx]); | 849 | err = mmc_compare_ext_csds(card, bus_widths[idx]); |
850 | else | 850 | else |
851 | err = mmc_bus_test(card, bus_widths[idx]); | 851 | err = mmc_bus_test(card, bus_widths[idx]); |
852 | if (!err) | 852 | if (!err) |
853 | break; | 853 | break; |
854 | } | 854 | } |
855 | 855 | ||
856 | /* switch to HS200 mode if bus width set successfully */ | 856 | /* switch to HS200 mode if bus width set successfully */ |
857 | if (!err) | 857 | if (!err) |
858 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 858 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
859 | EXT_CSD_HS_TIMING, 2, 0); | 859 | EXT_CSD_HS_TIMING, 2, 0); |
860 | err: | 860 | err: |
861 | return err; | 861 | return err; |
862 | } | 862 | } |
863 | 863 | ||
864 | /* | 864 | /* |
865 | * Handle the detection and initialisation of a card. | 865 | * Handle the detection and initialisation of a card. |
866 | * | 866 | * |
867 | * In the case of a resume, "oldcard" will contain the card | 867 | * In the case of a resume, "oldcard" will contain the card |
868 | * we're trying to reinitialise. | 868 | * we're trying to reinitialise. |
869 | */ | 869 | */ |
870 | static int mmc_init_card(struct mmc_host *host, u32 ocr, | 870 | static int mmc_init_card(struct mmc_host *host, u32 ocr, |
871 | struct mmc_card *oldcard) | 871 | struct mmc_card *oldcard) |
872 | { | 872 | { |
873 | struct mmc_card *card; | 873 | struct mmc_card *card; |
874 | int err, ddr = 0; | 874 | int err, ddr = 0; |
875 | u32 cid[4]; | 875 | u32 cid[4]; |
876 | unsigned int max_dtr; | 876 | unsigned int max_dtr; |
877 | u32 rocr; | 877 | u32 rocr; |
878 | u8 *ext_csd = NULL; | 878 | u8 *ext_csd = NULL; |
879 | 879 | ||
880 | BUG_ON(!host); | 880 | BUG_ON(!host); |
881 | WARN_ON(!host->claimed); | 881 | WARN_ON(!host->claimed); |
882 | 882 | ||
883 | /* Set correct bus mode for MMC before attempting init */ | 883 | /* Set correct bus mode for MMC before attempting init */ |
884 | if (!mmc_host_is_spi(host)) | 884 | if (!mmc_host_is_spi(host)) |
885 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); | 885 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); |
886 | 886 | ||
887 | /* | 887 | /* |
888 | * Since we're changing the OCR value, we seem to | 888 | * Since we're changing the OCR value, we seem to |
889 | * need to tell some cards to go back to the idle | 889 | * need to tell some cards to go back to the idle |
890 | * state. We wait 1ms to give cards time to | 890 | * state. We wait 1ms to give cards time to |
891 | * respond. | 891 | * respond. |
892 | * mmc_go_idle is needed for eMMC that are asleep | 892 | * mmc_go_idle is needed for eMMC that are asleep |
893 | */ | 893 | */ |
894 | mmc_go_idle(host); | 894 | mmc_go_idle(host); |
895 | 895 | ||
896 | /* The extra bit indicates that we support high capacity */ | 896 | /* The extra bit indicates that we support high capacity */ |
897 | err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); | 897 | err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); |
898 | if (err) | 898 | if (err) |
899 | goto err; | 899 | goto err; |
900 | 900 | ||
901 | /* | 901 | /* |
902 | * For SPI, enable CRC as appropriate. | 902 | * For SPI, enable CRC as appropriate. |
903 | */ | 903 | */ |
904 | if (mmc_host_is_spi(host)) { | 904 | if (mmc_host_is_spi(host)) { |
905 | err = mmc_spi_set_crc(host, use_spi_crc); | 905 | err = mmc_spi_set_crc(host, use_spi_crc); |
906 | if (err) | 906 | if (err) |
907 | goto err; | 907 | goto err; |
908 | } | 908 | } |
909 | 909 | ||
910 | /* | 910 | /* |
911 | * Fetch CID from card. | 911 | * Fetch CID from card. |
912 | */ | 912 | */ |
913 | if (mmc_host_is_spi(host)) | 913 | if (mmc_host_is_spi(host)) |
914 | err = mmc_send_cid(host, cid); | 914 | err = mmc_send_cid(host, cid); |
915 | else | 915 | else |
916 | err = mmc_all_send_cid(host, cid); | 916 | err = mmc_all_send_cid(host, cid); |
917 | if (err) | 917 | if (err) |
918 | goto err; | 918 | goto err; |
919 | 919 | ||
920 | if (oldcard) { | 920 | if (oldcard) { |
921 | if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { | 921 | if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { |
922 | err = -ENOENT; | 922 | err = -ENOENT; |
923 | goto err; | 923 | goto err; |
924 | } | 924 | } |
925 | 925 | ||
926 | card = oldcard; | 926 | card = oldcard; |
927 | } else { | 927 | } else { |
928 | /* | 928 | /* |
929 | * Allocate card structure. | 929 | * Allocate card structure. |
930 | */ | 930 | */ |
931 | card = mmc_alloc_card(host, &mmc_type); | 931 | card = mmc_alloc_card(host, &mmc_type); |
932 | if (IS_ERR(card)) { | 932 | if (IS_ERR(card)) { |
933 | err = PTR_ERR(card); | 933 | err = PTR_ERR(card); |
934 | goto err; | 934 | goto err; |
935 | } | 935 | } |
936 | 936 | ||
937 | card->type = MMC_TYPE_MMC; | 937 | card->type = MMC_TYPE_MMC; |
938 | card->rca = 1; | 938 | card->rca = 1; |
939 | memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); | 939 | memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); |
940 | } | 940 | } |
941 | 941 | ||
942 | /* | 942 | /* |
943 | * For native busses: set card RCA and quit open drain mode. | 943 | * For native busses: set card RCA and quit open drain mode. |
944 | */ | 944 | */ |
945 | if (!mmc_host_is_spi(host)) { | 945 | if (!mmc_host_is_spi(host)) { |
946 | err = mmc_set_relative_addr(card); | 946 | err = mmc_set_relative_addr(card); |
947 | if (err) | 947 | if (err) |
948 | goto free_card; | 948 | goto free_card; |
949 | 949 | ||
950 | mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); | 950 | mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); |
951 | } | 951 | } |
952 | 952 | ||
953 | if (!oldcard) { | 953 | if (!oldcard) { |
954 | /* | 954 | /* |
955 | * Fetch CSD from card. | 955 | * Fetch CSD from card. |
956 | */ | 956 | */ |
957 | err = mmc_send_csd(card, card->raw_csd); | 957 | err = mmc_send_csd(card, card->raw_csd); |
958 | if (err) | 958 | if (err) |
959 | goto free_card; | 959 | goto free_card; |
960 | 960 | ||
961 | err = mmc_decode_csd(card); | 961 | err = mmc_decode_csd(card); |
962 | if (err) | 962 | if (err) |
963 | goto free_card; | 963 | goto free_card; |
964 | err = mmc_decode_cid(card); | 964 | err = mmc_decode_cid(card); |
965 | if (err) | 965 | if (err) |
966 | goto free_card; | 966 | goto free_card; |
967 | } | 967 | } |
968 | 968 | ||
969 | /* | 969 | /* |
970 | * Select card, as all following commands rely on that. | 970 | * Select card, as all following commands rely on that. |
971 | */ | 971 | */ |
972 | if (!mmc_host_is_spi(host)) { | 972 | if (!mmc_host_is_spi(host)) { |
973 | err = mmc_select_card(card); | 973 | err = mmc_select_card(card); |
974 | if (err) | 974 | if (err) |
975 | goto free_card; | 975 | goto free_card; |
976 | } | 976 | } |
977 | 977 | ||
978 | if (!oldcard) { | 978 | if (!oldcard) { |
979 | /* | 979 | /* |
980 | * Fetch and process extended CSD. | 980 | * Fetch and process extended CSD. |
981 | */ | 981 | */ |
982 | 982 | ||
983 | err = mmc_get_ext_csd(card, &ext_csd); | 983 | err = mmc_get_ext_csd(card, &ext_csd); |
984 | if (err) | 984 | if (err) |
985 | goto free_card; | 985 | goto free_card; |
986 | err = mmc_read_ext_csd(card, ext_csd); | 986 | err = mmc_read_ext_csd(card, ext_csd); |
987 | if (err) | 987 | if (err) |
988 | goto free_card; | 988 | goto free_card; |
989 | 989 | ||
990 | /* If doing byte addressing, check if required to do sector | 990 | /* If doing byte addressing, check if required to do sector |
991 | * addressing. Handle the case of <2GB cards needing sector | 991 | * addressing. Handle the case of <2GB cards needing sector |
992 | * addressing. See section 8.1 JEDEC Standard JED84-A441; | 992 | * addressing. See section 8.1 JEDEC Standard JED84-A441; |
993 | * ocr register has bit 30 set for sector addressing. | 993 | * ocr register has bit 30 set for sector addressing. |
994 | */ | 994 | */ |
995 | if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) | 995 | if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) |
996 | mmc_card_set_blockaddr(card); | 996 | mmc_card_set_blockaddr(card); |
997 | 997 | ||
998 | /* Erase size depends on CSD and Extended CSD */ | 998 | /* Erase size depends on CSD and Extended CSD */ |
999 | mmc_set_erase_size(card); | 999 | mmc_set_erase_size(card); |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | /* | 1002 | /* |
1003 | * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF | 1003 | * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF |
1004 | * bit. This bit will be lost every time after a reset or power off. | 1004 | * bit. This bit will be lost every time after a reset or power off. |
1005 | */ | 1005 | */ |
1006 | if (card->ext_csd.enhanced_area_en || | 1006 | if (card->ext_csd.enhanced_area_en || |
1007 | (card->ext_csd.rev >= 3 && (host->caps2 & MMC_CAP2_HC_ERASE_SZ))) { | 1007 | (card->ext_csd.rev >= 3 && (host->caps2 & MMC_CAP2_HC_ERASE_SZ))) { |
1008 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1008 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1009 | EXT_CSD_ERASE_GROUP_DEF, 1, | 1009 | EXT_CSD_ERASE_GROUP_DEF, 1, |
1010 | card->ext_csd.generic_cmd6_time); | 1010 | card->ext_csd.generic_cmd6_time); |
1011 | 1011 | ||
1012 | if (err && err != -EBADMSG) | 1012 | if (err && err != -EBADMSG) |
1013 | goto free_card; | 1013 | goto free_card; |
1014 | 1014 | ||
1015 | if (err) { | 1015 | if (err) { |
1016 | err = 0; | 1016 | err = 0; |
1017 | /* | 1017 | /* |
1018 | * Just disable enhanced area off & sz | 1018 | * Just disable enhanced area off & sz |
1019 | * will try to enable ERASE_GROUP_DEF | 1019 | * will try to enable ERASE_GROUP_DEF |
1020 | * during next time reinit | 1020 | * during next time reinit |
1021 | */ | 1021 | */ |
1022 | card->ext_csd.enhanced_area_offset = -EINVAL; | 1022 | card->ext_csd.enhanced_area_offset = -EINVAL; |
1023 | card->ext_csd.enhanced_area_size = -EINVAL; | 1023 | card->ext_csd.enhanced_area_size = -EINVAL; |
1024 | } else { | 1024 | } else { |
1025 | card->ext_csd.erase_group_def = 1; | 1025 | card->ext_csd.erase_group_def = 1; |
1026 | /* | 1026 | /* |
1027 | * enable ERASE_GRP_DEF successfully. | 1027 | * enable ERASE_GRP_DEF successfully. |
1028 | * This will affect the erase size, so | 1028 | * This will affect the erase size, so |
1029 | * here need to reset erase size | 1029 | * here need to reset erase size |
1030 | */ | 1030 | */ |
1031 | mmc_set_erase_size(card); | 1031 | mmc_set_erase_size(card); |
1032 | } | 1032 | } |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | /* | 1035 | /* |
1036 | * Ensure eMMC user default partition is enabled | 1036 | * Ensure eMMC user default partition is enabled |
1037 | */ | 1037 | */ |
1038 | if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { | 1038 | if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { |
1039 | card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; | 1039 | card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; |
1040 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, | 1040 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, |
1041 | card->ext_csd.part_config, | 1041 | card->ext_csd.part_config, |
1042 | card->ext_csd.part_time); | 1042 | card->ext_csd.part_time); |
1043 | if (err && err != -EBADMSG) | 1043 | if (err && err != -EBADMSG) |
1044 | goto free_card; | 1044 | goto free_card; |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | /* | 1047 | /* |
1048 | * Enable power_off_notification byte in the ext_csd register | 1048 | * Enable power_off_notification byte in the ext_csd register |
1049 | */ | 1049 | */ |
1050 | if (card->ext_csd.rev >= 6) { | 1050 | if (card->ext_csd.rev >= 6) { |
1051 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1051 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1052 | EXT_CSD_POWER_OFF_NOTIFICATION, | 1052 | EXT_CSD_POWER_OFF_NOTIFICATION, |
1053 | EXT_CSD_POWER_ON, | 1053 | EXT_CSD_POWER_ON, |
1054 | card->ext_csd.generic_cmd6_time); | 1054 | card->ext_csd.generic_cmd6_time); |
1055 | if (err && err != -EBADMSG) | 1055 | if (err && err != -EBADMSG) |
1056 | goto free_card; | 1056 | goto free_card; |
1057 | 1057 | ||
1058 | /* | 1058 | /* |
1059 | * The err can be -EBADMSG or 0, | 1059 | * The err can be -EBADMSG or 0, |
1060 | * so check for success and update the flag | 1060 | * so check for success and update the flag |
1061 | */ | 1061 | */ |
1062 | if (!err) | 1062 | if (!err) |
1063 | card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; | 1063 | card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | /* | 1066 | /* |
1067 | * Activate high speed (if supported) | 1067 | * Activate high speed (if supported) |
1068 | */ | 1068 | */ |
1069 | if (card->ext_csd.hs_max_dtr != 0) { | 1069 | if (card->ext_csd.hs_max_dtr != 0) { |
1070 | err = 0; | 1070 | err = 0; |
1071 | if (card->ext_csd.hs_max_dtr > 52000000 && | 1071 | if (card->ext_csd.hs_max_dtr > 52000000 && |
1072 | host->caps2 & MMC_CAP2_HS200) | 1072 | host->caps2 & MMC_CAP2_HS200) |
1073 | err = mmc_select_hs200(card); | 1073 | err = mmc_select_hs200(card); |
1074 | else if (host->caps & MMC_CAP_MMC_HIGHSPEED) | 1074 | else if (host->caps & MMC_CAP_MMC_HIGHSPEED) |
1075 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1075 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1076 | EXT_CSD_HS_TIMING, 1, | 1076 | EXT_CSD_HS_TIMING, 1, |
1077 | card->ext_csd.generic_cmd6_time); | 1077 | card->ext_csd.generic_cmd6_time); |
1078 | 1078 | ||
1079 | if (err && err != -EBADMSG) | 1079 | if (err && err != -EBADMSG) |
1080 | goto free_card; | 1080 | goto free_card; |
1081 | 1081 | ||
1082 | if (err) { | 1082 | if (err) { |
1083 | pr_warning("%s: switch to highspeed failed\n", | 1083 | pr_warning("%s: switch to highspeed failed\n", |
1084 | mmc_hostname(card->host)); | 1084 | mmc_hostname(card->host)); |
1085 | err = 0; | 1085 | err = 0; |
1086 | } else { | 1086 | } else { |
1087 | if (card->ext_csd.hs_max_dtr > 52000000 && | 1087 | if (card->ext_csd.hs_max_dtr > 52000000 && |
1088 | host->caps2 & MMC_CAP2_HS200) { | 1088 | host->caps2 & MMC_CAP2_HS200) { |
1089 | mmc_card_set_hs200(card); | 1089 | mmc_card_set_hs200(card); |
1090 | mmc_set_timing(card->host, | 1090 | mmc_set_timing(card->host, |
1091 | MMC_TIMING_MMC_HS200); | 1091 | MMC_TIMING_MMC_HS200); |
1092 | } else { | 1092 | } else { |
1093 | mmc_card_set_highspeed(card); | 1093 | mmc_card_set_highspeed(card); |
1094 | mmc_set_timing(card->host, MMC_TIMING_MMC_HS); | 1094 | mmc_set_timing(card->host, MMC_TIMING_MMC_HS); |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | /* | 1099 | /* |
1100 | * Compute bus speed. | 1100 | * Compute bus speed. |
1101 | */ | 1101 | */ |
1102 | max_dtr = (unsigned int)-1; | 1102 | max_dtr = (unsigned int)-1; |
1103 | 1103 | ||
1104 | if (mmc_card_highspeed(card) || mmc_card_hs200(card)) { | 1104 | if (mmc_card_highspeed(card) || mmc_card_hs200(card)) { |
1105 | if (max_dtr > card->ext_csd.hs_max_dtr) | 1105 | if (max_dtr > card->ext_csd.hs_max_dtr) |
1106 | max_dtr = card->ext_csd.hs_max_dtr; | 1106 | max_dtr = card->ext_csd.hs_max_dtr; |
1107 | if (mmc_card_highspeed(card) && (max_dtr > 52000000)) | 1107 | if (mmc_card_highspeed(card) && (max_dtr > 52000000)) |
1108 | max_dtr = 52000000; | 1108 | max_dtr = 52000000; |
1109 | } else if (max_dtr > card->csd.max_dtr) { | 1109 | } else if (max_dtr > card->csd.max_dtr) { |
1110 | max_dtr = card->csd.max_dtr; | 1110 | max_dtr = card->csd.max_dtr; |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | mmc_set_clock(host, max_dtr); | 1113 | mmc_set_clock(host, max_dtr); |
1114 | 1114 | ||
1115 | /* | 1115 | /* |
1116 | * Indicate DDR mode (if supported). | 1116 | * Indicate DDR mode (if supported). |
1117 | */ | 1117 | */ |
1118 | if (mmc_card_highspeed(card)) { | 1118 | if (mmc_card_highspeed(card)) { |
1119 | if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) && | 1119 | if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) && |
1120 | (host->caps & MMC_CAP_1_8V_DDR)) | 1120 | (host->caps & MMC_CAP_1_8V_DDR)) |
1121 | ddr = MMC_1_8V_DDR_MODE; | 1121 | ddr = MMC_1_8V_DDR_MODE; |
1122 | else if ((card->ext_csd.card_type & | 1122 | else if ((card->ext_csd.card_type & |
1123 | EXT_CSD_CARD_TYPE_DDR_1_2V) && | 1123 | EXT_CSD_CARD_TYPE_DDR_1_2V) && |
1124 | (host->caps & MMC_CAP_1_2V_DDR)) | 1124 | (host->caps & MMC_CAP_1_2V_DDR)) |
1125 | ddr = MMC_1_2V_DDR_MODE; | 1125 | ddr = MMC_1_2V_DDR_MODE; |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | /* | 1128 | /* |
1129 | * Indicate HS200 SDR mode (if supported). | 1129 | * Indicate HS200 SDR mode (if supported). |
1130 | */ | 1130 | */ |
1131 | if (mmc_card_hs200(card)) { | 1131 | if (mmc_card_hs200(card)) { |
1132 | u32 ext_csd_bits; | 1132 | u32 ext_csd_bits; |
1133 | u32 bus_width = card->host->ios.bus_width; | 1133 | u32 bus_width = card->host->ios.bus_width; |
1134 | 1134 | ||
1135 | /* | 1135 | /* |
1136 | * For devices supporting HS200 mode, the bus width has | 1136 | * For devices supporting HS200 mode, the bus width has |
1137 | * to be set before executing the tuning function. If | 1137 | * to be set before executing the tuning function. If |
1138 | * set before tuning, then device will respond with CRC | 1138 | * set before tuning, then device will respond with CRC |
1139 | * errors for responses on CMD line. So for HS200 the | 1139 | * errors for responses on CMD line. So for HS200 the |
1140 | * sequence will be | 1140 | * sequence will be |
1141 | * 1. set bus width 4bit / 8 bit (1 bit not supported) | 1141 | * 1. set bus width 4bit / 8 bit (1 bit not supported) |
1142 | * 2. switch to HS200 mode | 1142 | * 2. switch to HS200 mode |
1143 | * 3. set the clock to > 52Mhz <=200MHz and | 1143 | * 3. set the clock to > 52Mhz <=200MHz and |
1144 | * 4. execute tuning for HS200 | 1144 | * 4. execute tuning for HS200 |
1145 | */ | 1145 | */ |
1146 | if ((host->caps2 & MMC_CAP2_HS200) && | 1146 | if ((host->caps2 & MMC_CAP2_HS200) && |
1147 | card->host->ops->execute_tuning) { | 1147 | card->host->ops->execute_tuning) { |
1148 | mmc_host_clk_hold(card->host); | 1148 | mmc_host_clk_hold(card->host); |
1149 | err = card->host->ops->execute_tuning(card->host, | 1149 | err = card->host->ops->execute_tuning(card->host, |
1150 | MMC_SEND_TUNING_BLOCK_HS200); | 1150 | MMC_SEND_TUNING_BLOCK_HS200); |
1151 | mmc_host_clk_release(card->host); | 1151 | mmc_host_clk_release(card->host); |
1152 | } | 1152 | } |
1153 | if (err) { | 1153 | if (err) { |
1154 | pr_warning("%s: tuning execution failed\n", | 1154 | pr_warning("%s: tuning execution failed\n", |
1155 | mmc_hostname(card->host)); | 1155 | mmc_hostname(card->host)); |
1156 | goto err; | 1156 | goto err; |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? | 1159 | ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? |
1160 | EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; | 1160 | EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; |
1161 | err = mmc_select_powerclass(card, ext_csd_bits); | 1161 | err = mmc_select_powerclass(card, ext_csd_bits); |
1162 | if (err) | 1162 | if (err) |
1163 | pr_warning("%s: power class selection to bus width %d" | 1163 | pr_warning("%s: power class selection to bus width %d" |
1164 | " failed\n", mmc_hostname(card->host), | 1164 | " failed\n", mmc_hostname(card->host), |
1165 | 1 << bus_width); | 1165 | 1 << bus_width); |
1166 | } | 1166 | } |
1167 | 1167 | ||
1168 | /* | 1168 | /* |
1169 | * Activate wide bus and DDR (if supported). | 1169 | * Activate wide bus and DDR (if supported). |
1170 | */ | 1170 | */ |
1171 | if (!mmc_card_hs200(card) && | 1171 | if (!mmc_card_hs200(card) && |
1172 | (card->csd.mmca_vsn >= CSD_SPEC_VER_4) && | 1172 | (card->csd.mmca_vsn >= CSD_SPEC_VER_4) && |
1173 | (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { | 1173 | (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { |
1174 | static unsigned ext_csd_bits[][2] = { | 1174 | static unsigned ext_csd_bits[][2] = { |
1175 | { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, | 1175 | { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, |
1176 | { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 }, | 1176 | { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 }, |
1177 | { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 }, | 1177 | { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 }, |
1178 | }; | 1178 | }; |
1179 | static unsigned bus_widths[] = { | 1179 | static unsigned bus_widths[] = { |
1180 | MMC_BUS_WIDTH_8, | 1180 | MMC_BUS_WIDTH_8, |
1181 | MMC_BUS_WIDTH_4, | 1181 | MMC_BUS_WIDTH_4, |
1182 | MMC_BUS_WIDTH_1 | 1182 | MMC_BUS_WIDTH_1 |
1183 | }; | 1183 | }; |
1184 | unsigned idx, bus_width = 0; | 1184 | unsigned idx, bus_width = 0; |
1185 | 1185 | ||
1186 | if (host->caps & MMC_CAP_8_BIT_DATA) | 1186 | if (host->caps & MMC_CAP_8_BIT_DATA) |
1187 | idx = 0; | 1187 | idx = 0; |
1188 | else | 1188 | else |
1189 | idx = 1; | 1189 | idx = 1; |
1190 | for (; idx < ARRAY_SIZE(bus_widths); idx++) { | 1190 | for (; idx < ARRAY_SIZE(bus_widths); idx++) { |
1191 | bus_width = bus_widths[idx]; | 1191 | bus_width = bus_widths[idx]; |
1192 | if (bus_width == MMC_BUS_WIDTH_1) | 1192 | if (bus_width == MMC_BUS_WIDTH_1) |
1193 | ddr = 0; /* no DDR for 1-bit width */ | 1193 | ddr = 0; /* no DDR for 1-bit width */ |
1194 | err = mmc_select_powerclass(card, ext_csd_bits[idx][0]); | 1194 | err = mmc_select_powerclass(card, ext_csd_bits[idx][0]); |
1195 | if (err) | 1195 | if (err) |
1196 | pr_warning("%s: power class selection to " | 1196 | pr_warning("%s: power class selection to " |
1197 | "bus width %d failed\n", | 1197 | "bus width %d failed\n", |
1198 | mmc_hostname(card->host), | 1198 | mmc_hostname(card->host), |
1199 | 1 << bus_width); | 1199 | 1 << bus_width); |
1200 | 1200 | ||
1201 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1201 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1202 | EXT_CSD_BUS_WIDTH, | 1202 | EXT_CSD_BUS_WIDTH, |
1203 | ext_csd_bits[idx][0], | 1203 | ext_csd_bits[idx][0], |
1204 | card->ext_csd.generic_cmd6_time); | 1204 | card->ext_csd.generic_cmd6_time); |
1205 | if (!err) { | 1205 | if (!err) { |
1206 | mmc_set_bus_width(card->host, bus_width); | 1206 | mmc_set_bus_width(card->host, bus_width); |
1207 | 1207 | ||
1208 | /* | 1208 | /* |
1209 | * If controller can't handle bus width test, | 1209 | * If controller can't handle bus width test, |
1210 | * compare ext_csd previously read in 1 bit mode | 1210 | * compare ext_csd previously read in 1 bit mode |
1211 | * against ext_csd at new bus width | 1211 | * against ext_csd at new bus width |
1212 | */ | 1212 | */ |
1213 | if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) | 1213 | if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) |
1214 | err = mmc_compare_ext_csds(card, | 1214 | err = mmc_compare_ext_csds(card, |
1215 | bus_width); | 1215 | bus_width); |
1216 | else | 1216 | else |
1217 | err = mmc_bus_test(card, bus_width); | 1217 | err = mmc_bus_test(card, bus_width); |
1218 | if (!err) | 1218 | if (!err) |
1219 | break; | 1219 | break; |
1220 | } | 1220 | } |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | if (!err && ddr) { | 1223 | if (!err && ddr) { |
1224 | err = mmc_select_powerclass(card, ext_csd_bits[idx][1]); | 1224 | err = mmc_select_powerclass(card, ext_csd_bits[idx][1]); |
1225 | if (err) | 1225 | if (err) |
1226 | pr_warning("%s: power class selection to " | 1226 | pr_warning("%s: power class selection to " |
1227 | "bus width %d ddr %d failed\n", | 1227 | "bus width %d ddr %d failed\n", |
1228 | mmc_hostname(card->host), | 1228 | mmc_hostname(card->host), |
1229 | 1 << bus_width, ddr); | 1229 | 1 << bus_width, ddr); |
1230 | 1230 | ||
1231 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1231 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1232 | EXT_CSD_BUS_WIDTH, | 1232 | EXT_CSD_BUS_WIDTH, |
1233 | ext_csd_bits[idx][1], | 1233 | ext_csd_bits[idx][1], |
1234 | card->ext_csd.generic_cmd6_time); | 1234 | card->ext_csd.generic_cmd6_time); |
1235 | } | 1235 | } |
1236 | if (err) { | 1236 | if (err) { |
1237 | pr_warning("%s: switch to bus width %d ddr %d " | 1237 | pr_warning("%s: switch to bus width %d ddr %d " |
1238 | "failed\n", mmc_hostname(card->host), | 1238 | "failed\n", mmc_hostname(card->host), |
1239 | 1 << bus_width, ddr); | 1239 | 1 << bus_width, ddr); |
1240 | goto free_card; | 1240 | goto free_card; |
1241 | } else if (ddr) { | 1241 | } else if (ddr) { |
1242 | /* | 1242 | /* |
1243 | * eMMC cards can support 3.3V to 1.2V i/o (vccq) | 1243 | * eMMC cards can support 3.3V to 1.2V i/o (vccq) |
1244 | * signaling. | 1244 | * signaling. |
1245 | * | 1245 | * |
1246 | * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq. | 1246 | * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq. |
1247 | * | 1247 | * |
1248 | * 1.8V vccq at 3.3V core voltage (vcc) is not required | 1248 | * 1.8V vccq at 3.3V core voltage (vcc) is not required |
1249 | * in the JEDEC spec for DDR. | 1249 | * in the JEDEC spec for DDR. |
1250 | * | 1250 | * |
1251 | * Do not force change in vccq since we are obviously | 1251 | * Do not force change in vccq since we are obviously |
1252 | * working and no change to vccq is needed. | 1252 | * working and no change to vccq is needed. |
1253 | * | 1253 | * |
1254 | * WARNING: eMMC rules are NOT the same as SD DDR | 1254 | * WARNING: eMMC rules are NOT the same as SD DDR |
1255 | */ | 1255 | */ |
1256 | if (ddr == MMC_1_2V_DDR_MODE) { | 1256 | if (ddr == MMC_1_2V_DDR_MODE) { |
1257 | err = __mmc_set_signal_voltage(host, | 1257 | err = __mmc_set_signal_voltage(host, |
1258 | MMC_SIGNAL_VOLTAGE_120); | 1258 | MMC_SIGNAL_VOLTAGE_120); |
1259 | if (err) | 1259 | if (err) |
1260 | goto err; | 1260 | goto err; |
1261 | } | 1261 | } |
1262 | mmc_card_set_ddr_mode(card); | 1262 | mmc_card_set_ddr_mode(card); |
1263 | mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50); | 1263 | mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50); |
1264 | mmc_set_bus_width(card->host, bus_width); | 1264 | mmc_set_bus_width(card->host, bus_width); |
1265 | } | 1265 | } |
1266 | } | 1266 | } |
1267 | 1267 | ||
1268 | /* | 1268 | /* |
1269 | * Enable HPI feature (if supported) | 1269 | * Enable HPI feature (if supported) |
1270 | */ | 1270 | */ |
1271 | if (card->ext_csd.hpi) { | 1271 | if (card->ext_csd.hpi) { |
1272 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1272 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1273 | EXT_CSD_HPI_MGMT, 1, | 1273 | EXT_CSD_HPI_MGMT, 1, |
1274 | card->ext_csd.generic_cmd6_time); | 1274 | card->ext_csd.generic_cmd6_time); |
1275 | if (err && err != -EBADMSG) | 1275 | if (err && err != -EBADMSG) |
1276 | goto free_card; | 1276 | goto free_card; |
1277 | if (err) { | 1277 | if (err) { |
1278 | pr_warning("%s: Enabling HPI failed\n", | 1278 | pr_warning("%s: Enabling HPI failed\n", |
1279 | mmc_hostname(card->host)); | 1279 | mmc_hostname(card->host)); |
1280 | err = 0; | 1280 | err = 0; |
1281 | } else | 1281 | } else |
1282 | card->ext_csd.hpi_en = 1; | 1282 | card->ext_csd.hpi_en = 1; |
1283 | } | 1283 | } |
1284 | 1284 | ||
1285 | /* | 1285 | /* |
1286 | * If cache size is higher than 0, this indicates | 1286 | * If cache size is higher than 0, this indicates |
1287 | * the existence of cache and it can be turned on. | 1287 | * the existence of cache and it can be turned on. |
1288 | */ | 1288 | */ |
1289 | if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && | 1289 | if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && |
1290 | card->ext_csd.cache_size > 0) { | 1290 | card->ext_csd.cache_size > 0) { |
1291 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1291 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1292 | EXT_CSD_CACHE_CTRL, 1, | 1292 | EXT_CSD_CACHE_CTRL, 1, |
1293 | card->ext_csd.generic_cmd6_time); | 1293 | card->ext_csd.generic_cmd6_time); |
1294 | if (err && err != -EBADMSG) | 1294 | if (err && err != -EBADMSG) |
1295 | goto free_card; | 1295 | goto free_card; |
1296 | 1296 | ||
1297 | /* | 1297 | /* |
1298 | * Only if no error, cache is turned on successfully. | 1298 | * Only if no error, cache is turned on successfully. |
1299 | */ | 1299 | */ |
1300 | if (err) { | 1300 | if (err) { |
1301 | pr_warning("%s: Cache is supported, " | 1301 | pr_warning("%s: Cache is supported, " |
1302 | "but failed to turn on (%d)\n", | 1302 | "but failed to turn on (%d)\n", |
1303 | mmc_hostname(card->host), err); | 1303 | mmc_hostname(card->host), err); |
1304 | card->ext_csd.cache_ctrl = 0; | 1304 | card->ext_csd.cache_ctrl = 0; |
1305 | err = 0; | 1305 | err = 0; |
1306 | } else { | 1306 | } else { |
1307 | card->ext_csd.cache_ctrl = 1; | 1307 | card->ext_csd.cache_ctrl = 1; |
1308 | } | 1308 | } |
1309 | } | 1309 | } |
1310 | 1310 | ||
1311 | /* | 1311 | /* |
1312 | * The mandatory minimum values are defined for packed command. | 1312 | * The mandatory minimum values are defined for packed command. |
1313 | * read: 5, write: 3 | 1313 | * read: 5, write: 3 |
1314 | */ | 1314 | */ |
1315 | if (card->ext_csd.max_packed_writes >= 3 && | 1315 | if (card->ext_csd.max_packed_writes >= 3 && |
1316 | card->ext_csd.max_packed_reads >= 5 && | 1316 | card->ext_csd.max_packed_reads >= 5 && |
1317 | host->caps2 & MMC_CAP2_PACKED_CMD) { | 1317 | host->caps2 & MMC_CAP2_PACKED_CMD) { |
1318 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1318 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1319 | EXT_CSD_EXP_EVENTS_CTRL, | 1319 | EXT_CSD_EXP_EVENTS_CTRL, |
1320 | EXT_CSD_PACKED_EVENT_EN, | 1320 | EXT_CSD_PACKED_EVENT_EN, |
1321 | card->ext_csd.generic_cmd6_time); | 1321 | card->ext_csd.generic_cmd6_time); |
1322 | if (err && err != -EBADMSG) | 1322 | if (err && err != -EBADMSG) |
1323 | goto free_card; | 1323 | goto free_card; |
1324 | if (err) { | 1324 | if (err) { |
1325 | pr_warn("%s: Enabling packed event failed\n", | 1325 | pr_warn("%s: Enabling packed event failed\n", |
1326 | mmc_hostname(card->host)); | 1326 | mmc_hostname(card->host)); |
1327 | card->ext_csd.packed_event_en = 0; | 1327 | card->ext_csd.packed_event_en = 0; |
1328 | err = 0; | 1328 | err = 0; |
1329 | } else { | 1329 | } else { |
1330 | card->ext_csd.packed_event_en = 1; | 1330 | card->ext_csd.packed_event_en = 1; |
1331 | } | 1331 | } |
1332 | } | 1332 | } |
1333 | 1333 | ||
1334 | if (!oldcard) | 1334 | if (!oldcard) |
1335 | host->card = card; | 1335 | host->card = card; |
1336 | 1336 | ||
1337 | mmc_free_ext_csd(ext_csd); | 1337 | mmc_free_ext_csd(ext_csd); |
1338 | return 0; | 1338 | return 0; |
1339 | 1339 | ||
1340 | free_card: | 1340 | free_card: |
1341 | if (!oldcard) | 1341 | if (!oldcard) |
1342 | mmc_remove_card(card); | 1342 | mmc_remove_card(card); |
1343 | err: | 1343 | err: |
1344 | mmc_free_ext_csd(ext_csd); | 1344 | mmc_free_ext_csd(ext_csd); |
1345 | 1345 | ||
1346 | return err; | 1346 | return err; |
1347 | } | 1347 | } |
1348 | 1348 | ||
1349 | static int mmc_can_sleep(struct mmc_card *card) | 1349 | static int mmc_can_sleep(struct mmc_card *card) |
1350 | { | 1350 | { |
1351 | return (card && card->ext_csd.rev >= 3); | 1351 | return (card && card->ext_csd.rev >= 3); |
1352 | } | 1352 | } |
1353 | 1353 | ||
1354 | static int mmc_sleep(struct mmc_host *host) | 1354 | static int mmc_sleep(struct mmc_host *host) |
1355 | { | 1355 | { |
1356 | struct mmc_command cmd = {0}; | 1356 | struct mmc_command cmd = {0}; |
1357 | struct mmc_card *card = host->card; | 1357 | struct mmc_card *card = host->card; |
1358 | int err; | 1358 | int err; |
1359 | 1359 | ||
1360 | if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) | 1360 | if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) |
1361 | return 0; | 1361 | return 0; |
1362 | 1362 | ||
1363 | err = mmc_deselect_cards(host); | 1363 | err = mmc_deselect_cards(host); |
1364 | if (err) | 1364 | if (err) |
1365 | return err; | 1365 | return err; |
1366 | 1366 | ||
1367 | cmd.opcode = MMC_SLEEP_AWAKE; | 1367 | cmd.opcode = MMC_SLEEP_AWAKE; |
1368 | cmd.arg = card->rca << 16; | 1368 | cmd.arg = card->rca << 16; |
1369 | cmd.arg |= 1 << 15; | 1369 | cmd.arg |= 1 << 15; |
1370 | 1370 | ||
1371 | cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; | 1371 | cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; |
1372 | err = mmc_wait_for_cmd(host, &cmd, 0); | 1372 | err = mmc_wait_for_cmd(host, &cmd, 0); |
1373 | if (err) | 1373 | if (err) |
1374 | return err; | 1374 | return err; |
1375 | 1375 | ||
1376 | /* | 1376 | /* |
1377 | * If the host does not wait while the card signals busy, then we will | 1377 | * If the host does not wait while the card signals busy, then we will |
1378 | * will have to wait the sleep/awake timeout. Note, we cannot use the | 1378 | * will have to wait the sleep/awake timeout. Note, we cannot use the |
1379 | * SEND_STATUS command to poll the status because that command (and most | 1379 | * SEND_STATUS command to poll the status because that command (and most |
1380 | * others) is invalid while the card sleeps. | 1380 | * others) is invalid while the card sleeps. |
1381 | */ | 1381 | */ |
1382 | if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) | 1382 | if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) |
1383 | mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); | 1383 | mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); |
1384 | 1384 | ||
1385 | return err; | 1385 | return err; |
1386 | } | 1386 | } |
1387 | 1387 | ||
1388 | static int mmc_can_poweroff_notify(const struct mmc_card *card) | 1388 | static int mmc_can_poweroff_notify(const struct mmc_card *card) |
1389 | { | 1389 | { |
1390 | return card && | 1390 | return card && |
1391 | mmc_card_mmc(card) && | 1391 | mmc_card_mmc(card) && |
1392 | (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); | 1392 | (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); |
1393 | } | 1393 | } |
1394 | 1394 | ||
1395 | static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) | 1395 | static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) |
1396 | { | 1396 | { |
1397 | unsigned int timeout = card->ext_csd.generic_cmd6_time; | 1397 | unsigned int timeout = card->ext_csd.generic_cmd6_time; |
1398 | int err; | 1398 | int err; |
1399 | 1399 | ||
1400 | /* Use EXT_CSD_POWER_OFF_SHORT as default notification type. */ | 1400 | /* Use EXT_CSD_POWER_OFF_SHORT as default notification type. */ |
1401 | if (notify_type == EXT_CSD_POWER_OFF_LONG) | 1401 | if (notify_type == EXT_CSD_POWER_OFF_LONG) |
1402 | timeout = card->ext_csd.power_off_longtime; | 1402 | timeout = card->ext_csd.power_off_longtime; |
1403 | 1403 | ||
1404 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1404 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
1405 | EXT_CSD_POWER_OFF_NOTIFICATION, | 1405 | EXT_CSD_POWER_OFF_NOTIFICATION, |
1406 | notify_type, timeout); | 1406 | notify_type, timeout); |
1407 | if (err) | 1407 | if (err) |
1408 | pr_err("%s: Power Off Notification timed out, %u\n", | 1408 | pr_err("%s: Power Off Notification timed out, %u\n", |
1409 | mmc_hostname(card->host), timeout); | 1409 | mmc_hostname(card->host), timeout); |
1410 | 1410 | ||
1411 | /* Disable the power off notification after the switch operation. */ | 1411 | /* Disable the power off notification after the switch operation. */ |
1412 | card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; | 1412 | card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; |
1413 | 1413 | ||
1414 | return err; | 1414 | return err; |
1415 | } | 1415 | } |
1416 | 1416 | ||
1417 | /* | 1417 | /* |
1418 | * Host is being removed. Free up the current card. | 1418 | * Host is being removed. Free up the current card. |
1419 | */ | 1419 | */ |
1420 | static void mmc_remove(struct mmc_host *host) | 1420 | static void mmc_remove(struct mmc_host *host) |
1421 | { | 1421 | { |
1422 | BUG_ON(!host); | 1422 | BUG_ON(!host); |
1423 | BUG_ON(!host->card); | 1423 | BUG_ON(!host->card); |
1424 | 1424 | ||
1425 | mmc_remove_card(host->card); | 1425 | mmc_remove_card(host->card); |
1426 | host->card = NULL; | 1426 | host->card = NULL; |
1427 | } | 1427 | } |
1428 | 1428 | ||
1429 | /* | 1429 | /* |
1430 | * Card detection - card is alive. | 1430 | * Card detection - card is alive. |
1431 | */ | 1431 | */ |
1432 | static int mmc_alive(struct mmc_host *host) | 1432 | static int mmc_alive(struct mmc_host *host) |
1433 | { | 1433 | { |
1434 | return mmc_send_status(host->card, NULL); | 1434 | return mmc_send_status(host->card, NULL); |
1435 | } | 1435 | } |
1436 | 1436 | ||
1437 | /* | 1437 | /* |
1438 | * Card detection callback from host. | 1438 | * Card detection callback from host. |
1439 | */ | 1439 | */ |
1440 | static void mmc_detect(struct mmc_host *host) | 1440 | static void mmc_detect(struct mmc_host *host) |
1441 | { | 1441 | { |
1442 | int err; | 1442 | int err; |
1443 | 1443 | ||
1444 | BUG_ON(!host); | 1444 | BUG_ON(!host); |
1445 | BUG_ON(!host->card); | 1445 | BUG_ON(!host->card); |
1446 | 1446 | ||
1447 | mmc_get_card(host->card); | 1447 | mmc_get_card(host->card); |
1448 | 1448 | ||
1449 | /* | 1449 | /* |
1450 | * Just check if our card has been removed. | 1450 | * Just check if our card has been removed. |
1451 | */ | 1451 | */ |
1452 | err = _mmc_detect_card_removed(host); | 1452 | err = _mmc_detect_card_removed(host); |
1453 | 1453 | ||
1454 | mmc_put_card(host->card); | 1454 | mmc_put_card(host->card); |
1455 | 1455 | ||
1456 | if (err) { | 1456 | if (err) { |
1457 | mmc_remove(host); | 1457 | mmc_remove(host); |
1458 | 1458 | ||
1459 | mmc_claim_host(host); | 1459 | mmc_claim_host(host); |
1460 | mmc_detach_bus(host); | 1460 | mmc_detach_bus(host); |
1461 | mmc_power_off(host); | 1461 | mmc_power_off(host); |
1462 | mmc_release_host(host); | 1462 | mmc_release_host(host); |
1463 | } | 1463 | } |
1464 | } | 1464 | } |
1465 | 1465 | ||
1466 | static int _mmc_suspend(struct mmc_host *host, bool is_suspend) | 1466 | static int _mmc_suspend(struct mmc_host *host, bool is_suspend) |
1467 | { | 1467 | { |
1468 | int err = 0; | 1468 | int err = 0; |
1469 | unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT : | 1469 | unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT : |
1470 | EXT_CSD_POWER_OFF_LONG; | 1470 | EXT_CSD_POWER_OFF_LONG; |
1471 | 1471 | ||
1472 | BUG_ON(!host); | 1472 | BUG_ON(!host); |
1473 | BUG_ON(!host->card); | 1473 | BUG_ON(!host->card); |
1474 | 1474 | ||
1475 | mmc_claim_host(host); | 1475 | mmc_claim_host(host); |
1476 | 1476 | ||
1477 | if (mmc_card_doing_bkops(host->card)) { | 1477 | if (mmc_card_doing_bkops(host->card)) { |
1478 | err = mmc_stop_bkops(host->card); | 1478 | err = mmc_stop_bkops(host->card); |
1479 | if (err) | 1479 | if (err) |
1480 | goto out; | 1480 | goto out; |
1481 | } | 1481 | } |
1482 | 1482 | ||
1483 | err = mmc_cache_ctrl(host, 0); | 1483 | err = mmc_cache_ctrl(host, 0); |
1484 | if (err) | 1484 | if (err) |
1485 | goto out; | 1485 | goto out; |
1486 | 1486 | ||
1487 | if (mmc_can_poweroff_notify(host->card) && | 1487 | if (mmc_can_poweroff_notify(host->card) && |
1488 | ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend)) | 1488 | ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend)) |
1489 | err = mmc_poweroff_notify(host->card, notify_type); | 1489 | err = mmc_poweroff_notify(host->card, notify_type); |
1490 | else if (mmc_can_sleep(host->card)) | 1490 | else if (mmc_can_sleep(host->card)) |
1491 | err = mmc_sleep(host); | 1491 | err = mmc_sleep(host); |
1492 | else if (!mmc_host_is_spi(host)) | 1492 | else if (!mmc_host_is_spi(host)) |
1493 | err = mmc_deselect_cards(host); | 1493 | err = mmc_deselect_cards(host); |
1494 | host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); | 1494 | host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); |
1495 | 1495 | ||
1496 | if (!err) | 1496 | if (!err) |
1497 | mmc_power_off(host); | 1497 | mmc_power_off(host); |
1498 | out: | 1498 | out: |
1499 | mmc_release_host(host); | 1499 | mmc_release_host(host); |
1500 | return err; | 1500 | return err; |
1501 | } | 1501 | } |
1502 | 1502 | ||
1503 | /* | 1503 | /* |
1504 | * Suspend callback from host. | 1504 | * Suspend callback from host. |
1505 | */ | 1505 | */ |
1506 | static int mmc_suspend(struct mmc_host *host) | 1506 | static int mmc_suspend(struct mmc_host *host) |
1507 | { | 1507 | { |
1508 | return _mmc_suspend(host, true); | 1508 | return _mmc_suspend(host, true); |
1509 | } | 1509 | } |
1510 | 1510 | ||
1511 | /* | 1511 | /* |
1512 | * Resume callback from host. | 1512 | * Resume callback from host. |
1513 | * | 1513 | * |
1514 | * This function tries to determine if the same card is still present | 1514 | * This function tries to determine if the same card is still present |
1515 | * and, if so, restore all state to it. | 1515 | * and, if so, restore all state to it. |
1516 | */ | 1516 | */ |
1517 | static int mmc_resume(struct mmc_host *host) | 1517 | static int mmc_resume(struct mmc_host *host) |
1518 | { | 1518 | { |
1519 | int err; | 1519 | int err; |
1520 | 1520 | ||
1521 | BUG_ON(!host); | 1521 | BUG_ON(!host); |
1522 | BUG_ON(!host->card); | 1522 | BUG_ON(!host->card); |
1523 | 1523 | ||
1524 | mmc_claim_host(host); | 1524 | mmc_claim_host(host); |
1525 | mmc_power_up(host); | 1525 | mmc_power_up(host); |
1526 | mmc_select_voltage(host, host->ocr); | 1526 | mmc_select_voltage(host, host->ocr); |
1527 | err = mmc_init_card(host, host->ocr, host->card); | 1527 | err = mmc_init_card(host, host->ocr, host->card); |
1528 | mmc_release_host(host); | 1528 | mmc_release_host(host); |
1529 | 1529 | ||
1530 | return err; | 1530 | return err; |
1531 | } | 1531 | } |
1532 | 1532 | ||
1533 | 1533 | ||
1534 | /* | 1534 | /* |
1535 | * Callback for runtime_suspend. | 1535 | * Callback for runtime_suspend. |
1536 | */ | 1536 | */ |
1537 | static int mmc_runtime_suspend(struct mmc_host *host) | 1537 | static int mmc_runtime_suspend(struct mmc_host *host) |
1538 | { | 1538 | { |
1539 | int err; | 1539 | int err; |
1540 | 1540 | ||
1541 | if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) | 1541 | if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) |
1542 | return 0; | 1542 | return 0; |
1543 | 1543 | ||
1544 | mmc_claim_host(host); | 1544 | mmc_claim_host(host); |
1545 | 1545 | ||
1546 | err = mmc_suspend(host); | 1546 | err = mmc_suspend(host); |
1547 | if (err) { | 1547 | if (err) { |
1548 | pr_err("%s: error %d doing aggessive suspend\n", | 1548 | pr_err("%s: error %d doing aggessive suspend\n", |
1549 | mmc_hostname(host), err); | 1549 | mmc_hostname(host), err); |
1550 | goto out; | 1550 | goto out; |
1551 | } | 1551 | } |
1552 | mmc_power_off(host); | 1552 | mmc_power_off(host); |
1553 | 1553 | ||
1554 | out: | 1554 | out: |
1555 | mmc_release_host(host); | 1555 | mmc_release_host(host); |
1556 | return err; | 1556 | return err; |
1557 | } | 1557 | } |
1558 | 1558 | ||
1559 | /* | 1559 | /* |
1560 | * Callback for runtime_resume. | 1560 | * Callback for runtime_resume. |
1561 | */ | 1561 | */ |
1562 | static int mmc_runtime_resume(struct mmc_host *host) | 1562 | static int mmc_runtime_resume(struct mmc_host *host) |
1563 | { | 1563 | { |
1564 | int err; | 1564 | int err; |
1565 | 1565 | ||
1566 | if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) | 1566 | if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) |
1567 | return 0; | 1567 | return 0; |
1568 | 1568 | ||
1569 | mmc_claim_host(host); | 1569 | mmc_claim_host(host); |
1570 | 1570 | ||
1571 | mmc_power_up(host); | 1571 | mmc_power_up(host); |
1572 | err = mmc_resume(host); | 1572 | err = mmc_resume(host); |
1573 | if (err) | 1573 | if (err) |
1574 | pr_err("%s: error %d doing aggessive resume\n", | 1574 | pr_err("%s: error %d doing aggessive resume\n", |
1575 | mmc_hostname(host), err); | 1575 | mmc_hostname(host), err); |
1576 | 1576 | ||
1577 | mmc_release_host(host); | 1577 | mmc_release_host(host); |
1578 | return 0; | 1578 | return 0; |
1579 | } | 1579 | } |
1580 | 1580 | ||
1581 | static int mmc_power_restore(struct mmc_host *host) | 1581 | static int mmc_power_restore(struct mmc_host *host) |
1582 | { | 1582 | { |
1583 | int ret; | 1583 | int ret; |
1584 | 1584 | ||
1585 | host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); | 1585 | host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); |
1586 | mmc_claim_host(host); | 1586 | mmc_claim_host(host); |
1587 | ret = mmc_init_card(host, host->ocr, host->card); | 1587 | ret = mmc_init_card(host, host->ocr, host->card); |
1588 | mmc_release_host(host); | 1588 | mmc_release_host(host); |
1589 | 1589 | ||
1590 | return ret; | 1590 | return ret; |
1591 | } | 1591 | } |
1592 | 1592 | ||
1593 | static const struct mmc_bus_ops mmc_ops = { | 1593 | static const struct mmc_bus_ops mmc_ops = { |
1594 | .remove = mmc_remove, | 1594 | .remove = mmc_remove, |
1595 | .detect = mmc_detect, | 1595 | .detect = mmc_detect, |
1596 | .suspend = NULL, | 1596 | .suspend = NULL, |
1597 | .resume = NULL, | 1597 | .resume = NULL, |
1598 | .power_restore = mmc_power_restore, | 1598 | .power_restore = mmc_power_restore, |
1599 | .alive = mmc_alive, | 1599 | .alive = mmc_alive, |
1600 | }; | 1600 | }; |
1601 | 1601 | ||
1602 | static const struct mmc_bus_ops mmc_ops_unsafe = { | 1602 | static const struct mmc_bus_ops mmc_ops_unsafe = { |
1603 | .remove = mmc_remove, | 1603 | .remove = mmc_remove, |
1604 | .detect = mmc_detect, | 1604 | .detect = mmc_detect, |
1605 | .suspend = mmc_suspend, | 1605 | .suspend = mmc_suspend, |
1606 | .resume = mmc_resume, | 1606 | .resume = mmc_resume, |
1607 | .runtime_suspend = mmc_runtime_suspend, | 1607 | .runtime_suspend = mmc_runtime_suspend, |
1608 | .runtime_resume = mmc_runtime_resume, | 1608 | .runtime_resume = mmc_runtime_resume, |
1609 | .power_restore = mmc_power_restore, | 1609 | .power_restore = mmc_power_restore, |
1610 | .alive = mmc_alive, | 1610 | .alive = mmc_alive, |
1611 | }; | 1611 | }; |
1612 | 1612 | ||
1613 | static void mmc_attach_bus_ops(struct mmc_host *host) | 1613 | static void mmc_attach_bus_ops(struct mmc_host *host) |
1614 | { | 1614 | { |
1615 | const struct mmc_bus_ops *bus_ops; | 1615 | const struct mmc_bus_ops *bus_ops; |
1616 | 1616 | ||
1617 | if (!mmc_card_is_removable(host)) | 1617 | if (!mmc_card_is_removable(host)) |
1618 | bus_ops = &mmc_ops_unsafe; | 1618 | bus_ops = &mmc_ops_unsafe; |
1619 | else | 1619 | else |
1620 | bus_ops = &mmc_ops; | 1620 | bus_ops = &mmc_ops; |
1621 | mmc_attach_bus(host, bus_ops); | 1621 | mmc_attach_bus(host, bus_ops); |
1622 | } | 1622 | } |
1623 | 1623 | ||
1624 | /* | 1624 | /* |
1625 | * Starting point for MMC card init. | 1625 | * Starting point for MMC card init. |
1626 | */ | 1626 | */ |
1627 | int mmc_attach_mmc(struct mmc_host *host) | 1627 | int mmc_attach_mmc(struct mmc_host *host) |
1628 | { | 1628 | { |
1629 | int err; | 1629 | int err; |
1630 | u32 ocr; | 1630 | u32 ocr; |
1631 | 1631 | ||
1632 | BUG_ON(!host); | 1632 | BUG_ON(!host); |
1633 | WARN_ON(!host->claimed); | 1633 | WARN_ON(!host->claimed); |
1634 | 1634 | ||
1635 | /* Set correct bus mode for MMC before attempting attach */ | 1635 | /* Set correct bus mode for MMC before attempting attach */ |
1636 | if (!mmc_host_is_spi(host)) | 1636 | if (!mmc_host_is_spi(host)) |
1637 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); | 1637 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); |
1638 | 1638 | ||
1639 | err = mmc_send_op_cond(host, 0, &ocr); | 1639 | err = mmc_send_op_cond(host, 0, &ocr); |
1640 | if (err) | 1640 | if (err) |
1641 | return err; | 1641 | return err; |
1642 | 1642 | ||
1643 | mmc_attach_bus_ops(host); | 1643 | mmc_attach_bus_ops(host); |
1644 | if (host->ocr_avail_mmc) | 1644 | if (host->ocr_avail_mmc) |
1645 | host->ocr_avail = host->ocr_avail_mmc; | 1645 | host->ocr_avail = host->ocr_avail_mmc; |
1646 | 1646 | ||
1647 | /* | 1647 | /* |
1648 | * We need to get OCR a different way for SPI. | 1648 | * We need to get OCR a different way for SPI. |
1649 | */ | 1649 | */ |
1650 | if (mmc_host_is_spi(host)) { | 1650 | if (mmc_host_is_spi(host)) { |
1651 | err = mmc_spi_read_ocr(host, 1, &ocr); | 1651 | err = mmc_spi_read_ocr(host, 1, &ocr); |
1652 | if (err) | 1652 | if (err) |
1653 | goto err; | 1653 | goto err; |
1654 | } | 1654 | } |
1655 | 1655 | ||
1656 | /* | 1656 | /* |
1657 | * Sanity check the voltages that the card claims to | 1657 | * Sanity check the voltages that the card claims to |
1658 | * support. | 1658 | * support. |
1659 | */ | 1659 | */ |
1660 | if (ocr & 0x7F) { | 1660 | if (ocr & 0x7F) { |
1661 | pr_warning("%s: card claims to support voltages " | 1661 | pr_warning("%s: card claims to support voltages " |
1662 | "below the defined range. These will be ignored.\n", | 1662 | "below the defined range. These will be ignored.\n", |
1663 | mmc_hostname(host)); | 1663 | mmc_hostname(host)); |
1664 | ocr &= ~0x7F; | 1664 | ocr &= ~0x7F; |
1665 | } | 1665 | } |
1666 | 1666 | ||
1667 | host->ocr = mmc_select_voltage(host, ocr); | 1667 | host->ocr = mmc_select_voltage(host, ocr); |
1668 | 1668 | ||
1669 | /* | 1669 | /* |
1670 | * Can we support the voltage of the card? | 1670 | * Can we support the voltage of the card? |
1671 | */ | 1671 | */ |
1672 | if (!host->ocr) { | 1672 | if (!host->ocr) { |
1673 | err = -EINVAL; | 1673 | err = -EINVAL; |
1674 | goto err; | 1674 | goto err; |
1675 | } | 1675 | } |
1676 | 1676 | ||
1677 | /* | 1677 | /* |
1678 | * Detect and init the card. | 1678 | * Detect and init the card. |
1679 | */ | 1679 | */ |
1680 | err = mmc_init_card(host, host->ocr, NULL); | 1680 | err = mmc_init_card(host, host->ocr, NULL); |
1681 | if (err) | 1681 | if (err) |
1682 | goto err; | 1682 | goto err; |
1683 | 1683 | ||
1684 | mmc_release_host(host); | 1684 | mmc_release_host(host); |
1685 | err = mmc_add_card(host->card); | 1685 | err = mmc_add_card(host->card); |
1686 | mmc_claim_host(host); | 1686 | mmc_claim_host(host); |
1687 | if (err) | 1687 | if (err) |
1688 | goto remove_card; | 1688 | goto remove_card; |
1689 | 1689 | ||
1690 | return 0; | 1690 | return 0; |
1691 | 1691 | ||
1692 | remove_card: | 1692 | remove_card: |
1693 | mmc_release_host(host); | 1693 | mmc_release_host(host); |
1694 | mmc_remove_card(host->card); | 1694 | mmc_remove_card(host->card); |
1695 | mmc_claim_host(host); | 1695 | mmc_claim_host(host); |
1696 | host->card = NULL; | 1696 | host->card = NULL; |
1697 | err: | 1697 | err: |
1698 | mmc_detach_bus(host); | 1698 | mmc_detach_bus(host); |
1699 | 1699 | ||
1700 | pr_err("%s: error %d whilst initialising MMC card\n", | 1700 | pr_err("%s: error %d whilst initialising MMC card\n", |
1701 | mmc_hostname(host), err); | 1701 | mmc_hostname(host), err); |
1702 | 1702 | ||
1703 | return err; | 1703 | return err; |
1704 | } | 1704 | } |
1705 | 1705 |