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