Skip to content

Commit 7806cdb

Browse files
David VrabelPierre Ossman
authored andcommitted
sdio: add sdio_f0_readb() and sdio_f0_writeb()
Add sdio_f0_readb() and sdio_f0_writeb() functions to reading and writing function 0 registers. Writes outside the vendor specific CCCR registers (0xF0 - 0xFF) are not permitted. Signed-off-by: David Vrabel <david.vrabel@csr.com> Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
1 parent d84075c commit 7806cdb

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

drivers/mmc/core/sdio_io.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,67 @@ void sdio_writel(struct sdio_func *func, unsigned long b, unsigned int addr,
482482
}
483483
EXPORT_SYMBOL_GPL(sdio_writel);
484484

485+
/**
486+
* sdio_f0_readb - read a single byte from SDIO function 0
487+
* @func: an SDIO function of the card
488+
* @addr: address to read
489+
* @err_ret: optional status value from transfer
490+
*
491+
* Reads a single byte from the address space of SDIO function 0.
492+
* If there is a problem reading the address, 0xff is returned
493+
* and @err_ret will contain the error code.
494+
*/
495+
unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
496+
int *err_ret)
497+
{
498+
int ret;
499+
unsigned char val;
500+
501+
BUG_ON(!func);
502+
503+
if (err_ret)
504+
*err_ret = 0;
505+
506+
ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
507+
if (ret) {
508+
if (err_ret)
509+
*err_ret = ret;
510+
return 0xFF;
511+
}
512+
513+
return val;
514+
}
515+
EXPORT_SYMBOL_GPL(sdio_f0_readb);
516+
517+
/**
518+
* sdio_f0_writeb - write a single byte to SDIO function 0
519+
* @func: an SDIO function of the card
520+
* @b: byte to write
521+
* @addr: address to write to
522+
* @err_ret: optional status value from transfer
523+
*
524+
* Writes a single byte to the address space of SDIO function 0.
525+
* @err_ret will contain the status of the actual transfer.
526+
*
527+
* Only writes to the vendor specific CCCR registers (0xF0 -
528+
* 0xFF) are permiited; @err_ret will be set to -EINVAL for *
529+
* writes outside this range.
530+
*/
531+
void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
532+
int *err_ret)
533+
{
534+
int ret;
535+
536+
BUG_ON(!func);
537+
538+
if (addr < 0xF0 || addr > 0xFF) {
539+
if (err_ret)
540+
*err_ret = -EINVAL;
541+
return;
542+
}
543+
544+
ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
545+
if (err_ret)
546+
*err_ret = ret;
547+
}
548+
EXPORT_SYMBOL_GPL(sdio_f0_writeb);

include/linux/mmc/sdio_func.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,10 @@ extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
141141
extern int sdio_writesb(struct sdio_func *func, unsigned int addr,
142142
void *src, int count);
143143

144+
extern unsigned char sdio_f0_readb(struct sdio_func *func,
145+
unsigned int addr, int *err_ret);
146+
extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,
147+
unsigned int addr, int *err_ret);
148+
144149
#endif
145150

0 commit comments

Comments
 (0)