Skip to content

Commit 46f555f

Browse files
author
Pierre Ossman
committed
mmc: add basic SDIO I/O operations
Add command wrappers that simplify register access from SDIO function drivers. Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
1 parent f76c851 commit 46f555f

3 files changed

Lines changed: 119 additions & 1 deletion

File tree

‎drivers/mmc/core/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ endif
99
obj-$(CONFIG_MMC) += mmc_core.o
1010
mmc_core-y := core.o sysfs.o bus.o host.o \
1111
mmc.o mmc_ops.o sd.o sd_ops.o \
12-
sdio.o sdio_ops.o sdio_bus.o
12+
sdio.o sdio_ops.o sdio_bus.o \
13+
sdio_io.o
1314

‎drivers/mmc/core/sdio_io.c‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* linux/drivers/mmc/core/sdio_io.c
3+
*
4+
* Copyright 2007 Pierre Ossman
5+
*
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>
14+
#include <linux/mmc/sdio_func.h>
15+
16+
#include "sdio_ops.h"
17+
18+
/**
19+
* sdio_claim_host - exclusively claim a bus for a certain SDIO function
20+
* @func: SDIO function that will be accessed
21+
*
22+
* Claim a bus for a set of operations. The SDIO function given
23+
* is used to figure out which bus is relevant.
24+
*/
25+
void sdio_claim_host(struct sdio_func *func)
26+
{
27+
BUG_ON(!func);
28+
BUG_ON(!func->card);
29+
30+
mmc_claim_host(func->card->host);
31+
}
32+
EXPORT_SYMBOL_GPL(sdio_claim_host);
33+
34+
/**
35+
* sdio_release_host - release a bus for a certain SDIO function
36+
* @func: SDIO function that was accessed
37+
*
38+
* Release a bus, allowing others to claim the bus for their
39+
* operations.
40+
*/
41+
void sdio_release_host(struct sdio_func *func)
42+
{
43+
BUG_ON(!func);
44+
BUG_ON(!func->card);
45+
46+
mmc_release_host(func->card->host);
47+
}
48+
EXPORT_SYMBOL_GPL(sdio_release_host);
49+
50+
/**
51+
* sdio_readb - read a single byte from a SDIO function
52+
* @func: SDIO function to access
53+
* @addr: address to read
54+
* @err_ret: optional status value from transfer
55+
*
56+
* Reads a single byte from the address space of a given SDIO
57+
* function. If there is a problem reading the address, 0xff
58+
* is returned and @err_ret will contain the error code.
59+
*/
60+
unsigned char sdio_readb(struct sdio_func *func, unsigned int addr,
61+
int *err_ret)
62+
{
63+
int ret;
64+
unsigned char val;
65+
66+
BUG_ON(!func);
67+
68+
if (err_ret)
69+
*err_ret = 0;
70+
71+
ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
72+
if (ret) {
73+
if (err_ret)
74+
*err_ret = ret;
75+
return 0xFF;
76+
}
77+
78+
return val;
79+
}
80+
EXPORT_SYMBOL_GPL(sdio_readb);
81+
82+
/**
83+
* sdio_writeb - write a single byte to a SDIO function
84+
* @func: SDIO function to access
85+
* @b: byte to write
86+
* @addr: address to write to
87+
* @err_ret: optional status value from transfer
88+
*
89+
* Writes a single byte to the address space of a given SDIO
90+
* function. @err_ret will contain the status of the actual
91+
* transfer.
92+
*/
93+
void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
94+
int *err_ret)
95+
{
96+
int ret;
97+
98+
BUG_ON(!func);
99+
100+
ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
101+
if (err_ret)
102+
*err_ret = ret;
103+
}
104+
EXPORT_SYMBOL_GPL(sdio_writeb);
105+

‎include/linux/mmc/sdio_func.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,17 @@ struct sdio_driver {
4949
extern int sdio_register_driver(struct sdio_driver *);
5050
extern void sdio_unregister_driver(struct sdio_driver *);
5151

52+
/*
53+
* SDIO I/O operations
54+
*/
55+
extern void sdio_claim_host(struct sdio_func *func);
56+
extern void sdio_release_host(struct sdio_func *func);
57+
58+
extern unsigned char sdio_readb(struct sdio_func *func,
59+
unsigned int addr, int *err_ret);
60+
61+
extern void sdio_writeb(struct sdio_func *func, unsigned char b,
62+
unsigned int addr, int *err_ret);
63+
5264
#endif
5365

0 commit comments

Comments
 (0)