@@ -56,20 +56,6 @@ static const unsigned int sd_au_size[] = {
5656 SZ_16M / 512 , (SZ_16M + SZ_8M ) / 512 , SZ_32M / 512 , SZ_64M / 512 ,
5757};
5858
59- #define UNSTUFF_BITS (resp ,start ,size ) \
60- ({ \
61- const int __size = size; \
62- const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
63- const int __off = 3 - ((start) / 32); \
64- const int __shft = (start) & 31; \
65- u32 __res; \
66- \
67- __res = resp[__off] >> __shft; \
68- if (__size + __shft > 32) \
69- __res |= resp[__off-1] << ((32 - __shft) % 32); \
70- __res & __mask; \
71- })
72-
7359#define SD_POWEROFF_NOTIFY_TIMEOUT_MS 1000
7460#define SD_WRITE_EXTR_SINGLE_TIMEOUT_MS 1000
7561
@@ -95,18 +81,18 @@ void mmc_decode_cid(struct mmc_card *card)
9581 * SD doesn't currently have a version field so we will
9682 * have to assume we can parse this.
9783 */
98- card -> cid .manfid = UNSTUFF_BITS (resp , 120 , 8 );
99- card -> cid .oemid = UNSTUFF_BITS (resp , 104 , 16 );
100- card -> cid .prod_name [0 ] = UNSTUFF_BITS (resp , 96 , 8 );
101- card -> cid .prod_name [1 ] = UNSTUFF_BITS (resp , 88 , 8 );
102- card -> cid .prod_name [2 ] = UNSTUFF_BITS (resp , 80 , 8 );
103- card -> cid .prod_name [3 ] = UNSTUFF_BITS (resp , 72 , 8 );
104- card -> cid .prod_name [4 ] = UNSTUFF_BITS (resp , 64 , 8 );
105- card -> cid .hwrev = UNSTUFF_BITS (resp , 60 , 4 );
106- card -> cid .fwrev = UNSTUFF_BITS (resp , 56 , 4 );
107- card -> cid .serial = UNSTUFF_BITS (resp , 24 , 32 );
108- card -> cid .year = UNSTUFF_BITS (resp , 12 , 8 );
109- card -> cid .month = UNSTUFF_BITS (resp , 8 , 4 );
84+ card -> cid .manfid = unstuff_bits (resp , 120 , 8 );
85+ card -> cid .oemid = unstuff_bits (resp , 104 , 16 );
86+ card -> cid .prod_name [0 ] = unstuff_bits (resp , 96 , 8 );
87+ card -> cid .prod_name [1 ] = unstuff_bits (resp , 88 , 8 );
88+ card -> cid .prod_name [2 ] = unstuff_bits (resp , 80 , 8 );
89+ card -> cid .prod_name [3 ] = unstuff_bits (resp , 72 , 8 );
90+ card -> cid .prod_name [4 ] = unstuff_bits (resp , 64 , 8 );
91+ card -> cid .hwrev = unstuff_bits (resp , 60 , 4 );
92+ card -> cid .fwrev = unstuff_bits (resp , 56 , 4 );
93+ card -> cid .serial = unstuff_bits (resp , 24 , 32 );
94+ card -> cid .year = unstuff_bits (resp , 12 , 8 );
95+ card -> cid .month = unstuff_bits (resp , 8 , 4 );
11096
11197 card -> cid .year += 2000 ; /* SD cards year offset */
11298}
@@ -120,41 +106,41 @@ static int mmc_decode_csd(struct mmc_card *card)
120106 unsigned int e , m , csd_struct ;
121107 u32 * resp = card -> raw_csd ;
122108
123- csd_struct = UNSTUFF_BITS (resp , 126 , 2 );
109+ csd_struct = unstuff_bits (resp , 126 , 2 );
124110
125111 switch (csd_struct ) {
126112 case 0 :
127- m = UNSTUFF_BITS (resp , 115 , 4 );
128- e = UNSTUFF_BITS (resp , 112 , 3 );
113+ m = unstuff_bits (resp , 115 , 4 );
114+ e = unstuff_bits (resp , 112 , 3 );
129115 csd -> taac_ns = (taac_exp [e ] * taac_mant [m ] + 9 ) / 10 ;
130- csd -> taac_clks = UNSTUFF_BITS (resp , 104 , 8 ) * 100 ;
116+ csd -> taac_clks = unstuff_bits (resp , 104 , 8 ) * 100 ;
131117
132- m = UNSTUFF_BITS (resp , 99 , 4 );
133- e = UNSTUFF_BITS (resp , 96 , 3 );
118+ m = unstuff_bits (resp , 99 , 4 );
119+ e = unstuff_bits (resp , 96 , 3 );
134120 csd -> max_dtr = tran_exp [e ] * tran_mant [m ];
135- csd -> cmdclass = UNSTUFF_BITS (resp , 84 , 12 );
121+ csd -> cmdclass = unstuff_bits (resp , 84 , 12 );
136122
137- e = UNSTUFF_BITS (resp , 47 , 3 );
138- m = UNSTUFF_BITS (resp , 62 , 12 );
123+ e = unstuff_bits (resp , 47 , 3 );
124+ m = unstuff_bits (resp , 62 , 12 );
139125 csd -> capacity = (1 + m ) << (e + 2 );
140126
141- csd -> read_blkbits = UNSTUFF_BITS (resp , 80 , 4 );
142- csd -> read_partial = UNSTUFF_BITS (resp , 79 , 1 );
143- csd -> write_misalign = UNSTUFF_BITS (resp , 78 , 1 );
144- csd -> read_misalign = UNSTUFF_BITS (resp , 77 , 1 );
145- csd -> dsr_imp = UNSTUFF_BITS (resp , 76 , 1 );
146- csd -> r2w_factor = UNSTUFF_BITS (resp , 26 , 3 );
147- csd -> write_blkbits = UNSTUFF_BITS (resp , 22 , 4 );
148- csd -> write_partial = UNSTUFF_BITS (resp , 21 , 1 );
127+ csd -> read_blkbits = unstuff_bits (resp , 80 , 4 );
128+ csd -> read_partial = unstuff_bits (resp , 79 , 1 );
129+ csd -> write_misalign = unstuff_bits (resp , 78 , 1 );
130+ csd -> read_misalign = unstuff_bits (resp , 77 , 1 );
131+ csd -> dsr_imp = unstuff_bits (resp , 76 , 1 );
132+ csd -> r2w_factor = unstuff_bits (resp , 26 , 3 );
133+ csd -> write_blkbits = unstuff_bits (resp , 22 , 4 );
134+ csd -> write_partial = unstuff_bits (resp , 21 , 1 );
149135
150- if (UNSTUFF_BITS (resp , 46 , 1 )) {
136+ if (unstuff_bits (resp , 46 , 1 )) {
151137 csd -> erase_size = 1 ;
152138 } else if (csd -> write_blkbits >= 9 ) {
153- csd -> erase_size = UNSTUFF_BITS (resp , 39 , 7 ) + 1 ;
139+ csd -> erase_size = unstuff_bits (resp , 39 , 7 ) + 1 ;
154140 csd -> erase_size <<= csd -> write_blkbits - 9 ;
155141 }
156142
157- if (UNSTUFF_BITS (resp , 13 , 1 ))
143+ if (unstuff_bits (resp , 13 , 1 ))
158144 mmc_card_set_readonly (card );
159145 break ;
160146 case 1 :
@@ -169,17 +155,17 @@ static int mmc_decode_csd(struct mmc_card *card)
169155 csd -> taac_ns = 0 ; /* Unused */
170156 csd -> taac_clks = 0 ; /* Unused */
171157
172- m = UNSTUFF_BITS (resp , 99 , 4 );
173- e = UNSTUFF_BITS (resp , 96 , 3 );
158+ m = unstuff_bits (resp , 99 , 4 );
159+ e = unstuff_bits (resp , 96 , 3 );
174160 csd -> max_dtr = tran_exp [e ] * tran_mant [m ];
175- csd -> cmdclass = UNSTUFF_BITS (resp , 84 , 12 );
176- csd -> c_size = UNSTUFF_BITS (resp , 48 , 22 );
161+ csd -> cmdclass = unstuff_bits (resp , 84 , 12 );
162+ csd -> c_size = unstuff_bits (resp , 48 , 22 );
177163
178164 /* SDXC cards have a minimum C_SIZE of 0x00FFFF */
179165 if (csd -> c_size >= 0xFFFF )
180166 mmc_card_set_ext_capacity (card );
181167
182- m = UNSTUFF_BITS (resp , 48 , 22 );
168+ m = unstuff_bits (resp , 48 , 22 );
183169 csd -> capacity = (1 + m ) << 10 ;
184170
185171 csd -> read_blkbits = 9 ;
@@ -191,7 +177,7 @@ static int mmc_decode_csd(struct mmc_card *card)
191177 csd -> write_partial = 0 ;
192178 csd -> erase_size = 1 ;
193179
194- if (UNSTUFF_BITS (resp , 13 , 1 ))
180+ if (unstuff_bits (resp , 13 , 1 ))
195181 mmc_card_set_readonly (card );
196182 break ;
197183 default :
@@ -217,33 +203,33 @@ static int mmc_decode_scr(struct mmc_card *card)
217203 resp [3 ] = card -> raw_scr [1 ];
218204 resp [2 ] = card -> raw_scr [0 ];
219205
220- scr_struct = UNSTUFF_BITS (resp , 60 , 4 );
206+ scr_struct = unstuff_bits (resp , 60 , 4 );
221207 if (scr_struct != 0 ) {
222208 pr_err ("%s: unrecognised SCR structure version %d\n" ,
223209 mmc_hostname (card -> host ), scr_struct );
224210 return - EINVAL ;
225211 }
226212
227- scr -> sda_vsn = UNSTUFF_BITS (resp , 56 , 4 );
228- scr -> bus_widths = UNSTUFF_BITS (resp , 48 , 4 );
213+ scr -> sda_vsn = unstuff_bits (resp , 56 , 4 );
214+ scr -> bus_widths = unstuff_bits (resp , 48 , 4 );
229215 if (scr -> sda_vsn == SCR_SPEC_VER_2 )
230216 /* Check if Physical Layer Spec v3.0 is supported */
231- scr -> sda_spec3 = UNSTUFF_BITS (resp , 47 , 1 );
217+ scr -> sda_spec3 = unstuff_bits (resp , 47 , 1 );
232218
233219 if (scr -> sda_spec3 ) {
234- scr -> sda_spec4 = UNSTUFF_BITS (resp , 42 , 1 );
235- scr -> sda_specx = UNSTUFF_BITS (resp , 38 , 4 );
220+ scr -> sda_spec4 = unstuff_bits (resp , 42 , 1 );
221+ scr -> sda_specx = unstuff_bits (resp , 38 , 4 );
236222 }
237223
238- if (UNSTUFF_BITS (resp , 55 , 1 ))
224+ if (unstuff_bits (resp , 55 , 1 ))
239225 card -> erased_byte = 0xFF ;
240226 else
241227 card -> erased_byte = 0x0 ;
242228
243229 if (scr -> sda_spec4 )
244- scr -> cmds = UNSTUFF_BITS (resp , 32 , 4 );
230+ scr -> cmds = unstuff_bits (resp , 32 , 4 );
245231 else if (scr -> sda_spec3 )
246- scr -> cmds = UNSTUFF_BITS (resp , 32 , 2 );
232+ scr -> cmds = unstuff_bits (resp , 32 , 2 );
247233
248234 /* SD Spec says: any SD Card shall set at least bits 0 and 2 */
249235 if (!(scr -> bus_widths & SD_SCR_BUS_WIDTH_1 ) ||
@@ -289,17 +275,17 @@ static int mmc_read_ssr(struct mmc_card *card)
289275 kfree (raw_ssr );
290276
291277 /*
292- * UNSTUFF_BITS only works with four u32s so we have to offset the
278+ * unstuff_bits only works with four u32s so we have to offset the
293279 * bitfield positions accordingly.
294280 */
295- au = UNSTUFF_BITS (card -> raw_ssr , 428 - 384 , 4 );
281+ au = unstuff_bits (card -> raw_ssr , 428 - 384 , 4 );
296282 if (au ) {
297283 if (au <= 9 || card -> scr .sda_spec3 ) {
298284 card -> ssr .au = sd_au_size [au ];
299- es = UNSTUFF_BITS (card -> raw_ssr , 408 - 384 , 16 );
300- et = UNSTUFF_BITS (card -> raw_ssr , 402 - 384 , 6 );
285+ es = unstuff_bits (card -> raw_ssr , 408 - 384 , 16 );
286+ et = unstuff_bits (card -> raw_ssr , 402 - 384 , 6 );
301287 if (es && et ) {
302- eo = UNSTUFF_BITS (card -> raw_ssr , 400 - 384 , 2 );
288+ eo = unstuff_bits (card -> raw_ssr , 400 - 384 , 2 );
303289 card -> ssr .erase_timeout = (et * 1000 ) / es ;
304290 card -> ssr .erase_offset = eo * 1000 ;
305291 }
@@ -313,7 +299,7 @@ static int mmc_read_ssr(struct mmc_card *card)
313299 * starting SD5.1 discard is supported if DISCARD_SUPPORT (b313) is set
314300 */
315301 resp [3 ] = card -> raw_ssr [6 ];
316- discard_support = UNSTUFF_BITS (resp , 313 - 288 , 1 );
302+ discard_support = unstuff_bits (resp , 313 - 288 , 1 );
317303 card -> erase_arg = (card -> scr .sda_specx && discard_support ) ?
318304 SD_DISCARD_ARG : SD_ERASE_ARG ;
319305
0 commit comments