diff options
author | Pierre Ossman <drzeus@drzeus.cx> | 2007-05-27 06:57:15 -0400 |
---|---|---|
committer | Pierre Ossman <drzeus@drzeus.cx> | 2007-09-23 13:57:03 -0400 |
commit | 46f555f2731a14545a09ec06d27bd18e8e07069f (patch) | |
tree | 49b7050322d21b39a81bd383f4b697fb6268d454 | |
parent | f76c85154d320497bf1a939a98d6c432edcbd4a9 (diff) |
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>
-rw-r--r-- | drivers/mmc/core/Makefile | 3 | ||||
-rw-r--r-- | drivers/mmc/core/sdio_io.c | 105 | ||||
-rw-r--r-- | include/linux/mmc/sdio_func.h | 12 |
3 files changed, 119 insertions, 1 deletions
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index 71ab3d1e1eb2..bf7a00248039 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile | |||
@@ -9,5 +9,6 @@ endif | |||
9 | obj-$(CONFIG_MMC) += mmc_core.o | 9 | obj-$(CONFIG_MMC) += mmc_core.o |
10 | mmc_core-y := core.o sysfs.o bus.o host.o \ | 10 | mmc_core-y := core.o sysfs.o bus.o host.o \ |
11 | mmc.o mmc_ops.o sd.o sd_ops.o \ | 11 | 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 | ||
13 | 14 | ||
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c new file mode 100644 index 000000000000..4ad06e575634 --- /dev/null +++ b/drivers/mmc/core/sdio_io.c | |||
@@ -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 | |||
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h index 13a1a9ca4b66..5c56df196287 100644 --- a/include/linux/mmc/sdio_func.h +++ b/include/linux/mmc/sdio_func.h | |||
@@ -49,5 +49,17 @@ struct sdio_driver { | |||
49 | extern int sdio_register_driver(struct sdio_driver *); | 49 | extern int sdio_register_driver(struct sdio_driver *); |
50 | extern void sdio_unregister_driver(struct sdio_driver *); | 50 | extern void sdio_unregister_driver(struct sdio_driver *); |
51 | 51 | ||
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 | |||
52 | #endif | 64 | #endif |
53 | 65 | ||