diff options
author | Pierre Ossman <drzeus@drzeus.cx> | 2007-05-27 08:22:37 -0400 |
---|---|---|
committer | Pierre Ossman <drzeus@drzeus.cx> | 2007-09-23 14:10:56 -0400 |
commit | fa64efa1f2a0672767ad0753a6e4bfa4bcc77b87 (patch) | |
tree | 9d85f00c23c5e7c922becb639d3dfec9d08f4e89 /drivers/mmc | |
parent | 46f555f2731a14545a09ec06d27bd18e8e07069f (diff) |
mmc: enable/disable functions for SDIO
Like many other buses, the devices (functions) on the SDIO bus
must be enabled before they can be used. Add functions that allow
drivers to do so.
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/core/sdio_io.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c index 4ad06e575634..eb6c20935cef 100644 --- a/drivers/mmc/core/sdio_io.c +++ b/drivers/mmc/core/sdio_io.c | |||
@@ -11,6 +11,7 @@ | |||
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_func.h> | 15 | #include <linux/mmc/sdio_func.h> |
15 | 16 | ||
16 | #include "sdio_ops.h" | 17 | #include "sdio_ops.h" |
@@ -48,6 +49,98 @@ void sdio_release_host(struct sdio_func *func) | |||
48 | EXPORT_SYMBOL_GPL(sdio_release_host); | 49 | EXPORT_SYMBOL_GPL(sdio_release_host); |
49 | 50 | ||
50 | /** | 51 | /** |
52 | * 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 | */ | ||
58 | int 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, ®); | ||
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 | |||
79 | /* | ||
80 | * FIXME: This should timeout based on information in the CIS, | ||
81 | * but we don't have card to parse that yet. | ||
82 | */ | ||
83 | timeout = jiffies + HZ; | ||
84 | |||
85 | while (1) { | ||
86 | ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, ®); | ||
87 | if (ret) | ||
88 | goto err; | ||
89 | if (reg & (1 << func->num)) | ||
90 | break; | ||
91 | ret = -ETIME; | ||
92 | if (time_after(jiffies, timeout)) | ||
93 | goto err; | ||
94 | } | ||
95 | |||
96 | pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func)); | ||
97 | |||
98 | return 0; | ||
99 | |||
100 | err: | ||
101 | pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func)); | ||
102 | return ret; | ||
103 | } | ||
104 | EXPORT_SYMBOL_GPL(sdio_enable_func); | ||
105 | |||
106 | /** | ||
107 | * sdio_disable_func - disable a SDIO function | ||
108 | * @func: SDIO function to disable | ||
109 | * | ||
110 | * Powers down and deactivates a SDIO function. Register access | ||
111 | * to this function will fail until the function is reenabled. | ||
112 | */ | ||
113 | int sdio_disable_func(struct sdio_func *func) | ||
114 | { | ||
115 | int ret; | ||
116 | unsigned char reg; | ||
117 | |||
118 | BUG_ON(!func); | ||
119 | BUG_ON(!func->card); | ||
120 | |||
121 | pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func)); | ||
122 | |||
123 | ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®); | ||
124 | if (ret) | ||
125 | goto err; | ||
126 | |||
127 | reg &= ~(1 << func->num); | ||
128 | |||
129 | ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL); | ||
130 | if (ret) | ||
131 | goto err; | ||
132 | |||
133 | pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func)); | ||
134 | |||
135 | return 0; | ||
136 | |||
137 | err: | ||
138 | pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func)); | ||
139 | return -EIO; | ||
140 | } | ||
141 | EXPORT_SYMBOL_GPL(sdio_disable_func); | ||
142 | |||
143 | /** | ||
51 | * sdio_readb - read a single byte from a SDIO function | 144 | * sdio_readb - read a single byte from a SDIO function |
52 | * @func: SDIO function to access | 145 | * @func: SDIO function to access |
53 | * @addr: address to read | 146 | * @addr: address to read |