Commit ea901300cd8b809285fa5cbced18124f127e0ac6

Authored by Tomas Winkler
Committed by Pierre Ossman
1 parent 62a7573ee9

sdio: sdio_io.c Fix sparse warnings

Unfold nested macros it creates not readable code and
sparse warnings
sdio_io.c:190:9: warning: symbol '_min1' shadows an earlier one

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>

Showing 1 changed file with 4 additions and 5 deletions Inline Diff

drivers/mmc/core/sdio_io.c
1 /* 1 /*
2 * linux/drivers/mmc/core/sdio_io.c 2 * linux/drivers/mmc/core/sdio_io.c
3 * 3 *
4 * Copyright 2007-2008 Pierre Ossman 4 * Copyright 2007-2008 Pierre Ossman
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at 8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version. 9 * your option) any later version.
10 */ 10 */
11 11
12 #include <linux/mmc/host.h> 12 #include <linux/mmc/host.h>
13 #include <linux/mmc/card.h> 13 #include <linux/mmc/card.h>
14 #include <linux/mmc/sdio.h> 14 #include <linux/mmc/sdio.h>
15 #include <linux/mmc/sdio_func.h> 15 #include <linux/mmc/sdio_func.h>
16 16
17 #include "sdio_ops.h" 17 #include "sdio_ops.h"
18 18
19 /** 19 /**
20 * sdio_claim_host - exclusively claim a bus for a certain SDIO function 20 * sdio_claim_host - exclusively claim a bus for a certain SDIO function
21 * @func: SDIO function that will be accessed 21 * @func: SDIO function that will be accessed
22 * 22 *
23 * Claim a bus for a set of operations. The SDIO function given 23 * Claim a bus for a set of operations. The SDIO function given
24 * is used to figure out which bus is relevant. 24 * is used to figure out which bus is relevant.
25 */ 25 */
26 void sdio_claim_host(struct sdio_func *func) 26 void sdio_claim_host(struct sdio_func *func)
27 { 27 {
28 BUG_ON(!func); 28 BUG_ON(!func);
29 BUG_ON(!func->card); 29 BUG_ON(!func->card);
30 30
31 mmc_claim_host(func->card->host); 31 mmc_claim_host(func->card->host);
32 } 32 }
33 EXPORT_SYMBOL_GPL(sdio_claim_host); 33 EXPORT_SYMBOL_GPL(sdio_claim_host);
34 34
35 /** 35 /**
36 * sdio_release_host - release a bus for a certain SDIO function 36 * sdio_release_host - release a bus for a certain SDIO function
37 * @func: SDIO function that was accessed 37 * @func: SDIO function that was accessed
38 * 38 *
39 * Release a bus, allowing others to claim the bus for their 39 * Release a bus, allowing others to claim the bus for their
40 * operations. 40 * operations.
41 */ 41 */
42 void sdio_release_host(struct sdio_func *func) 42 void sdio_release_host(struct sdio_func *func)
43 { 43 {
44 BUG_ON(!func); 44 BUG_ON(!func);
45 BUG_ON(!func->card); 45 BUG_ON(!func->card);
46 46
47 mmc_release_host(func->card->host); 47 mmc_release_host(func->card->host);
48 } 48 }
49 EXPORT_SYMBOL_GPL(sdio_release_host); 49 EXPORT_SYMBOL_GPL(sdio_release_host);
50 50
51 /** 51 /**
52 * sdio_enable_func - enables a SDIO function for usage 52 * sdio_enable_func - enables a SDIO function for usage
53 * @func: SDIO function to enable 53 * @func: SDIO function to enable
54 * 54 *
55 * Powers up and activates a SDIO function so that register 55 * Powers up and activates a SDIO function so that register
56 * access is possible. 56 * access is possible.
57 */ 57 */
58 int sdio_enable_func(struct sdio_func *func) 58 int sdio_enable_func(struct sdio_func *func)
59 { 59 {
60 int ret; 60 int ret;
61 unsigned char reg; 61 unsigned char reg;
62 unsigned long timeout; 62 unsigned long timeout;
63 63
64 BUG_ON(!func); 64 BUG_ON(!func);
65 BUG_ON(!func->card); 65 BUG_ON(!func->card);
66 66
67 pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func)); 67 pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func));
68 68
69 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg); 69 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
70 if (ret) 70 if (ret)
71 goto err; 71 goto err;
72 72
73 reg |= 1 << func->num; 73 reg |= 1 << func->num;
74 74
75 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); 75 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
76 if (ret) 76 if (ret)
77 goto err; 77 goto err;
78 78
79 timeout = jiffies + msecs_to_jiffies(func->enable_timeout); 79 timeout = jiffies + msecs_to_jiffies(func->enable_timeout);
80 80
81 while (1) { 81 while (1) {
82 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg); 82 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg);
83 if (ret) 83 if (ret)
84 goto err; 84 goto err;
85 if (reg & (1 << func->num)) 85 if (reg & (1 << func->num))
86 break; 86 break;
87 ret = -ETIME; 87 ret = -ETIME;
88 if (time_after(jiffies, timeout)) 88 if (time_after(jiffies, timeout))
89 goto err; 89 goto err;
90 } 90 }
91 91
92 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func)); 92 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
93 93
94 return 0; 94 return 0;
95 95
96 err: 96 err:
97 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func)); 97 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
98 return ret; 98 return ret;
99 } 99 }
100 EXPORT_SYMBOL_GPL(sdio_enable_func); 100 EXPORT_SYMBOL_GPL(sdio_enable_func);
101 101
102 /** 102 /**
103 * sdio_disable_func - disable a SDIO function 103 * sdio_disable_func - disable a SDIO function
104 * @func: SDIO function to disable 104 * @func: SDIO function to disable
105 * 105 *
106 * Powers down and deactivates a SDIO function. Register access 106 * Powers down and deactivates a SDIO function. Register access
107 * to this function will fail until the function is reenabled. 107 * to this function will fail until the function is reenabled.
108 */ 108 */
109 int sdio_disable_func(struct sdio_func *func) 109 int sdio_disable_func(struct sdio_func *func)
110 { 110 {
111 int ret; 111 int ret;
112 unsigned char reg; 112 unsigned char reg;
113 113
114 BUG_ON(!func); 114 BUG_ON(!func);
115 BUG_ON(!func->card); 115 BUG_ON(!func->card);
116 116
117 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func)); 117 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
118 118
119 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg); 119 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
120 if (ret) 120 if (ret)
121 goto err; 121 goto err;
122 122
123 reg &= ~(1 << func->num); 123 reg &= ~(1 << func->num);
124 124
125 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); 125 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
126 if (ret) 126 if (ret)
127 goto err; 127 goto err;
128 128
129 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func)); 129 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
130 130
131 return 0; 131 return 0;
132 132
133 err: 133 err:
134 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func)); 134 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
135 return -EIO; 135 return -EIO;
136 } 136 }
137 EXPORT_SYMBOL_GPL(sdio_disable_func); 137 EXPORT_SYMBOL_GPL(sdio_disable_func);
138 138
139 /** 139 /**
140 * sdio_set_block_size - set the block size of an SDIO function 140 * sdio_set_block_size - set the block size of an SDIO function
141 * @func: SDIO function to change 141 * @func: SDIO function to change
142 * @blksz: new block size or 0 to use the default. 142 * @blksz: new block size or 0 to use the default.
143 * 143 *
144 * The default block size is the largest supported by both the function 144 * The default block size is the largest supported by both the function
145 * and the host, with a maximum of 512 to ensure that arbitrarily sized 145 * and the host, with a maximum of 512 to ensure that arbitrarily sized
146 * data transfer use the optimal (least) number of commands. 146 * data transfer use the optimal (least) number of commands.
147 * 147 *
148 * A driver may call this to override the default block size set by the 148 * A driver may call this to override the default block size set by the
149 * core. This can be used to set a block size greater than the maximum 149 * core. This can be used to set a block size greater than the maximum
150 * that reported by the card; it is the driver's responsibility to ensure 150 * that reported by the card; it is the driver's responsibility to ensure
151 * it uses a value that the card supports. 151 * it uses a value that the card supports.
152 * 152 *
153 * Returns 0 on success, -EINVAL if the host does not support the 153 * Returns 0 on success, -EINVAL if the host does not support the
154 * requested block size, or -EIO (etc.) if one of the resultant FBR block 154 * requested block size, or -EIO (etc.) if one of the resultant FBR block
155 * size register writes failed. 155 * size register writes failed.
156 * 156 *
157 */ 157 */
158 int sdio_set_block_size(struct sdio_func *func, unsigned blksz) 158 int sdio_set_block_size(struct sdio_func *func, unsigned blksz)
159 { 159 {
160 int ret; 160 int ret;
161 161
162 if (blksz > func->card->host->max_blk_size) 162 if (blksz > func->card->host->max_blk_size)
163 return -EINVAL; 163 return -EINVAL;
164 164
165 if (blksz == 0) { 165 if (blksz == 0) {
166 blksz = min(func->max_blksize, func->card->host->max_blk_size); 166 blksz = min(func->max_blksize, func->card->host->max_blk_size);
167 blksz = min(blksz, 512u); 167 blksz = min(blksz, 512u);
168 } 168 }
169 169
170 ret = mmc_io_rw_direct(func->card, 1, 0, 170 ret = mmc_io_rw_direct(func->card, 1, 0,
171 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE, 171 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE,
172 blksz & 0xff, NULL); 172 blksz & 0xff, NULL);
173 if (ret) 173 if (ret)
174 return ret; 174 return ret;
175 ret = mmc_io_rw_direct(func->card, 1, 0, 175 ret = mmc_io_rw_direct(func->card, 1, 0,
176 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1, 176 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1,
177 (blksz >> 8) & 0xff, NULL); 177 (blksz >> 8) & 0xff, NULL);
178 if (ret) 178 if (ret)
179 return ret; 179 return ret;
180 func->cur_blksize = blksz; 180 func->cur_blksize = blksz;
181 return 0; 181 return 0;
182 } 182 }
183 EXPORT_SYMBOL_GPL(sdio_set_block_size); 183 EXPORT_SYMBOL_GPL(sdio_set_block_size);
184 184
185 /* 185 /*
186 * Calculate the maximum byte mode transfer size 186 * Calculate the maximum byte mode transfer size
187 */ 187 */
188 static inline unsigned int sdio_max_byte_size(struct sdio_func *func) 188 static inline unsigned int sdio_max_byte_size(struct sdio_func *func)
189 { 189 {
190 return min(min(min( 190 unsigned mval = min(func->card->host->max_seg_size,
191 func->card->host->max_seg_size, 191 func->card->host->max_blk_size);
192 func->card->host->max_blk_size), 192 mval = min(mval, func->max_blksize);
193 func->max_blksize), 193 return min(mval, 512u); /* maximum size for byte mode */
194 512u); /* maximum size for byte mode */
195 } 194 }
196 195
197 /** 196 /**
198 * sdio_align_size - pads a transfer size to a more optimal value 197 * sdio_align_size - pads a transfer size to a more optimal value
199 * @func: SDIO function 198 * @func: SDIO function
200 * @sz: original transfer size 199 * @sz: original transfer size
201 * 200 *
202 * Pads the original data size with a number of extra bytes in 201 * Pads the original data size with a number of extra bytes in
203 * order to avoid controller bugs and/or performance hits 202 * order to avoid controller bugs and/or performance hits
204 * (e.g. some controllers revert to PIO for certain sizes). 203 * (e.g. some controllers revert to PIO for certain sizes).
205 * 204 *
206 * If possible, it will also adjust the size so that it can be 205 * If possible, it will also adjust the size so that it can be
207 * handled in just a single request. 206 * handled in just a single request.
208 * 207 *
209 * Returns the improved size, which might be unmodified. 208 * Returns the improved size, which might be unmodified.
210 */ 209 */
211 unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) 210 unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz)
212 { 211 {
213 unsigned int orig_sz; 212 unsigned int orig_sz;
214 unsigned int blk_sz, byte_sz; 213 unsigned int blk_sz, byte_sz;
215 unsigned chunk_sz; 214 unsigned chunk_sz;
216 215
217 orig_sz = sz; 216 orig_sz = sz;
218 217
219 /* 218 /*
220 * Do a first check with the controller, in case it 219 * Do a first check with the controller, in case it
221 * wants to increase the size up to a point where it 220 * wants to increase the size up to a point where it
222 * might need more than one block. 221 * might need more than one block.
223 */ 222 */
224 sz = mmc_align_data_size(func->card, sz); 223 sz = mmc_align_data_size(func->card, sz);
225 224
226 /* 225 /*
227 * If we can still do this with just a byte transfer, then 226 * If we can still do this with just a byte transfer, then
228 * we're done. 227 * we're done.
229 */ 228 */
230 if (sz <= sdio_max_byte_size(func)) 229 if (sz <= sdio_max_byte_size(func))
231 return sz; 230 return sz;
232 231
233 if (func->card->cccr.multi_block) { 232 if (func->card->cccr.multi_block) {
234 /* 233 /*
235 * Check if the transfer is already block aligned 234 * Check if the transfer is already block aligned
236 */ 235 */
237 if ((sz % func->cur_blksize) == 0) 236 if ((sz % func->cur_blksize) == 0)
238 return sz; 237 return sz;
239 238
240 /* 239 /*
241 * Realign it so that it can be done with one request, 240 * Realign it so that it can be done with one request,
242 * and recheck if the controller still likes it. 241 * and recheck if the controller still likes it.
243 */ 242 */
244 blk_sz = ((sz + func->cur_blksize - 1) / 243 blk_sz = ((sz + func->cur_blksize - 1) /
245 func->cur_blksize) * func->cur_blksize; 244 func->cur_blksize) * func->cur_blksize;
246 blk_sz = mmc_align_data_size(func->card, blk_sz); 245 blk_sz = mmc_align_data_size(func->card, blk_sz);
247 246
248 /* 247 /*
249 * This value is only good if it is still just 248 * This value is only good if it is still just
250 * one request. 249 * one request.
251 */ 250 */
252 if ((blk_sz % func->cur_blksize) == 0) 251 if ((blk_sz % func->cur_blksize) == 0)
253 return blk_sz; 252 return blk_sz;
254 253
255 /* 254 /*
256 * We failed to do one request, but at least try to 255 * We failed to do one request, but at least try to
257 * pad the remainder properly. 256 * pad the remainder properly.
258 */ 257 */
259 byte_sz = mmc_align_data_size(func->card, 258 byte_sz = mmc_align_data_size(func->card,
260 sz % func->cur_blksize); 259 sz % func->cur_blksize);
261 if (byte_sz <= sdio_max_byte_size(func)) { 260 if (byte_sz <= sdio_max_byte_size(func)) {
262 blk_sz = sz / func->cur_blksize; 261 blk_sz = sz / func->cur_blksize;
263 return blk_sz * func->cur_blksize + byte_sz; 262 return blk_sz * func->cur_blksize + byte_sz;
264 } 263 }
265 } else { 264 } else {
266 /* 265 /*
267 * We need multiple requests, so first check that the 266 * We need multiple requests, so first check that the
268 * controller can handle the chunk size; 267 * controller can handle the chunk size;
269 */ 268 */
270 chunk_sz = mmc_align_data_size(func->card, 269 chunk_sz = mmc_align_data_size(func->card,
271 sdio_max_byte_size(func)); 270 sdio_max_byte_size(func));
272 if (chunk_sz == sdio_max_byte_size(func)) { 271 if (chunk_sz == sdio_max_byte_size(func)) {
273 /* 272 /*
274 * Fix up the size of the remainder (if any) 273 * Fix up the size of the remainder (if any)
275 */ 274 */
276 byte_sz = orig_sz % chunk_sz; 275 byte_sz = orig_sz % chunk_sz;
277 if (byte_sz) { 276 if (byte_sz) {
278 byte_sz = mmc_align_data_size(func->card, 277 byte_sz = mmc_align_data_size(func->card,
279 byte_sz); 278 byte_sz);
280 } 279 }
281 280
282 return (orig_sz / chunk_sz) * chunk_sz + byte_sz; 281 return (orig_sz / chunk_sz) * chunk_sz + byte_sz;
283 } 282 }
284 } 283 }
285 284
286 /* 285 /*
287 * The controller is simply incapable of transferring the size 286 * The controller is simply incapable of transferring the size
288 * we want in decent manner, so just return the original size. 287 * we want in decent manner, so just return the original size.
289 */ 288 */
290 return orig_sz; 289 return orig_sz;
291 } 290 }
292 EXPORT_SYMBOL_GPL(sdio_align_size); 291 EXPORT_SYMBOL_GPL(sdio_align_size);
293 292
294 /* Split an arbitrarily sized data transfer into several 293 /* Split an arbitrarily sized data transfer into several
295 * IO_RW_EXTENDED commands. */ 294 * IO_RW_EXTENDED commands. */
296 static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, 295 static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
297 unsigned addr, int incr_addr, u8 *buf, unsigned size) 296 unsigned addr, int incr_addr, u8 *buf, unsigned size)
298 { 297 {
299 unsigned remainder = size; 298 unsigned remainder = size;
300 unsigned max_blocks; 299 unsigned max_blocks;
301 int ret; 300 int ret;
302 301
303 /* Do the bulk of the transfer using block mode (if supported). */ 302 /* Do the bulk of the transfer using block mode (if supported). */
304 if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) { 303 if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) {
305 /* Blocks per command is limited by host count, host transfer 304 /* Blocks per command is limited by host count, host transfer
306 * size (we only use a single sg entry) and the maximum for 305 * size (we only use a single sg entry) and the maximum for
307 * IO_RW_EXTENDED of 511 blocks. */ 306 * IO_RW_EXTENDED of 511 blocks. */
308 max_blocks = min(func->card->host->max_blk_count, 307 max_blocks = min(func->card->host->max_blk_count,
309 func->card->host->max_seg_size / func->cur_blksize); 308 func->card->host->max_seg_size / func->cur_blksize);
310 max_blocks = min(max_blocks, 511u); 309 max_blocks = min(max_blocks, 511u);
311 310
312 while (remainder > func->cur_blksize) { 311 while (remainder > func->cur_blksize) {
313 unsigned blocks; 312 unsigned blocks;
314 313
315 blocks = remainder / func->cur_blksize; 314 blocks = remainder / func->cur_blksize;
316 if (blocks > max_blocks) 315 if (blocks > max_blocks)
317 blocks = max_blocks; 316 blocks = max_blocks;
318 size = blocks * func->cur_blksize; 317 size = blocks * func->cur_blksize;
319 318
320 ret = mmc_io_rw_extended(func->card, write, 319 ret = mmc_io_rw_extended(func->card, write,
321 func->num, addr, incr_addr, buf, 320 func->num, addr, incr_addr, buf,
322 blocks, func->cur_blksize); 321 blocks, func->cur_blksize);
323 if (ret) 322 if (ret)
324 return ret; 323 return ret;
325 324
326 remainder -= size; 325 remainder -= size;
327 buf += size; 326 buf += size;
328 if (incr_addr) 327 if (incr_addr)
329 addr += size; 328 addr += size;
330 } 329 }
331 } 330 }
332 331
333 /* Write the remainder using byte mode. */ 332 /* Write the remainder using byte mode. */
334 while (remainder > 0) { 333 while (remainder > 0) {
335 size = min(remainder, sdio_max_byte_size(func)); 334 size = min(remainder, sdio_max_byte_size(func));
336 335
337 ret = mmc_io_rw_extended(func->card, write, func->num, addr, 336 ret = mmc_io_rw_extended(func->card, write, func->num, addr,
338 incr_addr, buf, 1, size); 337 incr_addr, buf, 1, size);
339 if (ret) 338 if (ret)
340 return ret; 339 return ret;
341 340
342 remainder -= size; 341 remainder -= size;
343 buf += size; 342 buf += size;
344 if (incr_addr) 343 if (incr_addr)
345 addr += size; 344 addr += size;
346 } 345 }
347 return 0; 346 return 0;
348 } 347 }
349 348
350 /** 349 /**
351 * sdio_readb - read a single byte from a SDIO function 350 * sdio_readb - read a single byte from a SDIO function
352 * @func: SDIO function to access 351 * @func: SDIO function to access
353 * @addr: address to read 352 * @addr: address to read
354 * @err_ret: optional status value from transfer 353 * @err_ret: optional status value from transfer
355 * 354 *
356 * Reads a single byte from the address space of a given SDIO 355 * Reads a single byte from the address space of a given SDIO
357 * function. If there is a problem reading the address, 0xff 356 * function. If there is a problem reading the address, 0xff
358 * is returned and @err_ret will contain the error code. 357 * is returned and @err_ret will contain the error code.
359 */ 358 */
360 u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret) 359 u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret)
361 { 360 {
362 int ret; 361 int ret;
363 u8 val; 362 u8 val;
364 363
365 BUG_ON(!func); 364 BUG_ON(!func);
366 365
367 if (err_ret) 366 if (err_ret)
368 *err_ret = 0; 367 *err_ret = 0;
369 368
370 ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val); 369 ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
371 if (ret) { 370 if (ret) {
372 if (err_ret) 371 if (err_ret)
373 *err_ret = ret; 372 *err_ret = ret;
374 return 0xFF; 373 return 0xFF;
375 } 374 }
376 375
377 return val; 376 return val;
378 } 377 }
379 EXPORT_SYMBOL_GPL(sdio_readb); 378 EXPORT_SYMBOL_GPL(sdio_readb);
380 379
381 /** 380 /**
382 * sdio_writeb - write a single byte to a SDIO function 381 * sdio_writeb - write a single byte to a SDIO function
383 * @func: SDIO function to access 382 * @func: SDIO function to access
384 * @b: byte to write 383 * @b: byte to write
385 * @addr: address to write to 384 * @addr: address to write to
386 * @err_ret: optional status value from transfer 385 * @err_ret: optional status value from transfer
387 * 386 *
388 * Writes a single byte to the address space of a given SDIO 387 * Writes a single byte to the address space of a given SDIO
389 * function. @err_ret will contain the status of the actual 388 * function. @err_ret will contain the status of the actual
390 * transfer. 389 * transfer.
391 */ 390 */
392 void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret) 391 void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret)
393 { 392 {
394 int ret; 393 int ret;
395 394
396 BUG_ON(!func); 395 BUG_ON(!func);
397 396
398 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL); 397 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
399 if (err_ret) 398 if (err_ret)
400 *err_ret = ret; 399 *err_ret = ret;
401 } 400 }
402 EXPORT_SYMBOL_GPL(sdio_writeb); 401 EXPORT_SYMBOL_GPL(sdio_writeb);
403 402
404 /** 403 /**
405 * sdio_memcpy_fromio - read a chunk of memory from a SDIO function 404 * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
406 * @func: SDIO function to access 405 * @func: SDIO function to access
407 * @dst: buffer to store the data 406 * @dst: buffer to store the data
408 * @addr: address to begin reading from 407 * @addr: address to begin reading from
409 * @count: number of bytes to read 408 * @count: number of bytes to read
410 * 409 *
411 * Reads from the address space of a given SDIO function. Return 410 * Reads from the address space of a given SDIO function. Return
412 * value indicates if the transfer succeeded or not. 411 * value indicates if the transfer succeeded or not.
413 */ 412 */
414 int sdio_memcpy_fromio(struct sdio_func *func, void *dst, 413 int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
415 unsigned int addr, int count) 414 unsigned int addr, int count)
416 { 415 {
417 return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count); 416 return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
418 } 417 }
419 EXPORT_SYMBOL_GPL(sdio_memcpy_fromio); 418 EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
420 419
421 /** 420 /**
422 * sdio_memcpy_toio - write a chunk of memory to a SDIO function 421 * sdio_memcpy_toio - write a chunk of memory to a SDIO function
423 * @func: SDIO function to access 422 * @func: SDIO function to access
424 * @addr: address to start writing to 423 * @addr: address to start writing to
425 * @src: buffer that contains the data to write 424 * @src: buffer that contains the data to write
426 * @count: number of bytes to write 425 * @count: number of bytes to write
427 * 426 *
428 * Writes to the address space of a given SDIO function. Return 427 * Writes to the address space of a given SDIO function. Return
429 * value indicates if the transfer succeeded or not. 428 * value indicates if the transfer succeeded or not.
430 */ 429 */
431 int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr, 430 int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
432 void *src, int count) 431 void *src, int count)
433 { 432 {
434 return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count); 433 return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
435 } 434 }
436 EXPORT_SYMBOL_GPL(sdio_memcpy_toio); 435 EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
437 436
438 /** 437 /**
439 * sdio_readsb - read from a FIFO on a SDIO function 438 * sdio_readsb - read from a FIFO on a SDIO function
440 * @func: SDIO function to access 439 * @func: SDIO function to access
441 * @dst: buffer to store the data 440 * @dst: buffer to store the data
442 * @addr: address of (single byte) FIFO 441 * @addr: address of (single byte) FIFO
443 * @count: number of bytes to read 442 * @count: number of bytes to read
444 * 443 *
445 * Reads from the specified FIFO of a given SDIO function. Return 444 * Reads from the specified FIFO of a given SDIO function. Return
446 * value indicates if the transfer succeeded or not. 445 * value indicates if the transfer succeeded or not.
447 */ 446 */
448 int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr, 447 int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
449 int count) 448 int count)
450 { 449 {
451 return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count); 450 return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
452 } 451 }
453 EXPORT_SYMBOL_GPL(sdio_readsb); 452 EXPORT_SYMBOL_GPL(sdio_readsb);
454 453
455 /** 454 /**
456 * sdio_writesb - write to a FIFO of a SDIO function 455 * sdio_writesb - write to a FIFO of a SDIO function
457 * @func: SDIO function to access 456 * @func: SDIO function to access
458 * @addr: address of (single byte) FIFO 457 * @addr: address of (single byte) FIFO
459 * @src: buffer that contains the data to write 458 * @src: buffer that contains the data to write
460 * @count: number of bytes to write 459 * @count: number of bytes to write
461 * 460 *
462 * Writes to the specified FIFO of a given SDIO function. Return 461 * Writes to the specified FIFO of a given SDIO function. Return
463 * value indicates if the transfer succeeded or not. 462 * value indicates if the transfer succeeded or not.
464 */ 463 */
465 int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src, 464 int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
466 int count) 465 int count)
467 { 466 {
468 return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count); 467 return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
469 } 468 }
470 EXPORT_SYMBOL_GPL(sdio_writesb); 469 EXPORT_SYMBOL_GPL(sdio_writesb);
471 470
472 /** 471 /**
473 * sdio_readw - read a 16 bit integer from a SDIO function 472 * sdio_readw - read a 16 bit integer from a SDIO function
474 * @func: SDIO function to access 473 * @func: SDIO function to access
475 * @addr: address to read 474 * @addr: address to read
476 * @err_ret: optional status value from transfer 475 * @err_ret: optional status value from transfer
477 * 476 *
478 * Reads a 16 bit integer from the address space of a given SDIO 477 * Reads a 16 bit integer from the address space of a given SDIO
479 * function. If there is a problem reading the address, 0xffff 478 * function. If there is a problem reading the address, 0xffff
480 * is returned and @err_ret will contain the error code. 479 * is returned and @err_ret will contain the error code.
481 */ 480 */
482 u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret) 481 u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret)
483 { 482 {
484 int ret; 483 int ret;
485 484
486 if (err_ret) 485 if (err_ret)
487 *err_ret = 0; 486 *err_ret = 0;
488 487
489 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2); 488 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
490 if (ret) { 489 if (ret) {
491 if (err_ret) 490 if (err_ret)
492 *err_ret = ret; 491 *err_ret = ret;
493 return 0xFFFF; 492 return 0xFFFF;
494 } 493 }
495 494
496 return le16_to_cpup((__le16 *)func->tmpbuf); 495 return le16_to_cpup((__le16 *)func->tmpbuf);
497 } 496 }
498 EXPORT_SYMBOL_GPL(sdio_readw); 497 EXPORT_SYMBOL_GPL(sdio_readw);
499 498
500 /** 499 /**
501 * sdio_writew - write a 16 bit integer to a SDIO function 500 * sdio_writew - write a 16 bit integer to a SDIO function
502 * @func: SDIO function to access 501 * @func: SDIO function to access
503 * @b: integer to write 502 * @b: integer to write
504 * @addr: address to write to 503 * @addr: address to write to
505 * @err_ret: optional status value from transfer 504 * @err_ret: optional status value from transfer
506 * 505 *
507 * Writes a 16 bit integer to the address space of a given SDIO 506 * Writes a 16 bit integer to the address space of a given SDIO
508 * function. @err_ret will contain the status of the actual 507 * function. @err_ret will contain the status of the actual
509 * transfer. 508 * transfer.
510 */ 509 */
511 void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret) 510 void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret)
512 { 511 {
513 int ret; 512 int ret;
514 513
515 *(__le16 *)func->tmpbuf = cpu_to_le16(b); 514 *(__le16 *)func->tmpbuf = cpu_to_le16(b);
516 515
517 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2); 516 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
518 if (err_ret) 517 if (err_ret)
519 *err_ret = ret; 518 *err_ret = ret;
520 } 519 }
521 EXPORT_SYMBOL_GPL(sdio_writew); 520 EXPORT_SYMBOL_GPL(sdio_writew);
522 521
523 /** 522 /**
524 * sdio_readl - read a 32 bit integer from a SDIO function 523 * sdio_readl - read a 32 bit integer from a SDIO function
525 * @func: SDIO function to access 524 * @func: SDIO function to access
526 * @addr: address to read 525 * @addr: address to read
527 * @err_ret: optional status value from transfer 526 * @err_ret: optional status value from transfer
528 * 527 *
529 * Reads a 32 bit integer from the address space of a given SDIO 528 * Reads a 32 bit integer from the address space of a given SDIO
530 * function. If there is a problem reading the address, 529 * function. If there is a problem reading the address,
531 * 0xffffffff is returned and @err_ret will contain the error 530 * 0xffffffff is returned and @err_ret will contain the error
532 * code. 531 * code.
533 */ 532 */
534 u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret) 533 u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret)
535 { 534 {
536 int ret; 535 int ret;
537 536
538 if (err_ret) 537 if (err_ret)
539 *err_ret = 0; 538 *err_ret = 0;
540 539
541 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4); 540 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
542 if (ret) { 541 if (ret) {
543 if (err_ret) 542 if (err_ret)
544 *err_ret = ret; 543 *err_ret = ret;
545 return 0xFFFFFFFF; 544 return 0xFFFFFFFF;
546 } 545 }
547 546
548 return le32_to_cpup((__le32 *)func->tmpbuf); 547 return le32_to_cpup((__le32 *)func->tmpbuf);
549 } 548 }
550 EXPORT_SYMBOL_GPL(sdio_readl); 549 EXPORT_SYMBOL_GPL(sdio_readl);
551 550
552 /** 551 /**
553 * sdio_writel - write a 32 bit integer to a SDIO function 552 * sdio_writel - write a 32 bit integer to a SDIO function
554 * @func: SDIO function to access 553 * @func: SDIO function to access
555 * @b: integer to write 554 * @b: integer to write
556 * @addr: address to write to 555 * @addr: address to write to
557 * @err_ret: optional status value from transfer 556 * @err_ret: optional status value from transfer
558 * 557 *
559 * Writes a 32 bit integer to the address space of a given SDIO 558 * Writes a 32 bit integer to the address space of a given SDIO
560 * function. @err_ret will contain the status of the actual 559 * function. @err_ret will contain the status of the actual
561 * transfer. 560 * transfer.
562 */ 561 */
563 void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret) 562 void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret)
564 { 563 {
565 int ret; 564 int ret;
566 565
567 *(__le32 *)func->tmpbuf = cpu_to_le32(b); 566 *(__le32 *)func->tmpbuf = cpu_to_le32(b);
568 567
569 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4); 568 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
570 if (err_ret) 569 if (err_ret)
571 *err_ret = ret; 570 *err_ret = ret;
572 } 571 }
573 EXPORT_SYMBOL_GPL(sdio_writel); 572 EXPORT_SYMBOL_GPL(sdio_writel);
574 573
575 /** 574 /**
576 * sdio_f0_readb - read a single byte from SDIO function 0 575 * sdio_f0_readb - read a single byte from SDIO function 0
577 * @func: an SDIO function of the card 576 * @func: an SDIO function of the card
578 * @addr: address to read 577 * @addr: address to read
579 * @err_ret: optional status value from transfer 578 * @err_ret: optional status value from transfer
580 * 579 *
581 * Reads a single byte from the address space of SDIO function 0. 580 * Reads a single byte from the address space of SDIO function 0.
582 * If there is a problem reading the address, 0xff is returned 581 * If there is a problem reading the address, 0xff is returned
583 * and @err_ret will contain the error code. 582 * and @err_ret will contain the error code.
584 */ 583 */
585 unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr, 584 unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
586 int *err_ret) 585 int *err_ret)
587 { 586 {
588 int ret; 587 int ret;
589 unsigned char val; 588 unsigned char val;
590 589
591 BUG_ON(!func); 590 BUG_ON(!func);
592 591
593 if (err_ret) 592 if (err_ret)
594 *err_ret = 0; 593 *err_ret = 0;
595 594
596 ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val); 595 ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
597 if (ret) { 596 if (ret) {
598 if (err_ret) 597 if (err_ret)
599 *err_ret = ret; 598 *err_ret = ret;
600 return 0xFF; 599 return 0xFF;
601 } 600 }
602 601
603 return val; 602 return val;
604 } 603 }
605 EXPORT_SYMBOL_GPL(sdio_f0_readb); 604 EXPORT_SYMBOL_GPL(sdio_f0_readb);
606 605
607 /** 606 /**
608 * sdio_f0_writeb - write a single byte to SDIO function 0 607 * sdio_f0_writeb - write a single byte to SDIO function 0
609 * @func: an SDIO function of the card 608 * @func: an SDIO function of the card
610 * @b: byte to write 609 * @b: byte to write
611 * @addr: address to write to 610 * @addr: address to write to
612 * @err_ret: optional status value from transfer 611 * @err_ret: optional status value from transfer
613 * 612 *
614 * Writes a single byte to the address space of SDIO function 0. 613 * Writes a single byte to the address space of SDIO function 0.
615 * @err_ret will contain the status of the actual transfer. 614 * @err_ret will contain the status of the actual transfer.
616 * 615 *
617 * Only writes to the vendor specific CCCR registers (0xF0 - 616 * Only writes to the vendor specific CCCR registers (0xF0 -
618 * 0xFF) are permiited; @err_ret will be set to -EINVAL for * 617 * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
619 * writes outside this range. 618 * writes outside this range.
620 */ 619 */
621 void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr, 620 void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
622 int *err_ret) 621 int *err_ret)
623 { 622 {
624 int ret; 623 int ret;
625 624
626 BUG_ON(!func); 625 BUG_ON(!func);
627 626
628 if (addr < 0xF0 || addr > 0xFF) { 627 if (addr < 0xF0 || addr > 0xFF) {
629 if (err_ret) 628 if (err_ret)
630 *err_ret = -EINVAL; 629 *err_ret = -EINVAL;
631 return; 630 return;
632 } 631 }
633 632
634 ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL); 633 ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
635 if (err_ret) 634 if (err_ret)
636 *err_ret = ret; 635 *err_ret = ret;
637 } 636 }
638 EXPORT_SYMBOL_GPL(sdio_f0_writeb); 637 EXPORT_SYMBOL_GPL(sdio_f0_writeb);
639 638