diff options
author | Shawn Guo <shawn.guo@linaro.org> | 2012-12-11 09:32:18 -0500 |
---|---|---|
committer | Chris Ball <cjb@laptop.org> | 2013-02-11 12:51:23 -0500 |
commit | d65b5ae8dabf48d8e7811a5319ec581e41b04d62 (patch) | |
tree | 327c78f03aaa1ea5b580908ef61ae01c3701ec0c /drivers/mmc | |
parent | 505a8680b78f580245cfb83f37971c7b62bcf991 (diff) |
mmc: slot-gpio: use devm_* managed functions to ease users
Use devm_* managed functions, so that slot-gpio users do not have to
call mmc_gpio_free_ro/cd to free up resources requested in
mmc_gpio_request_ro/cd.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/core/slot-gpio.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c index 16a1c0b6f264..324235105519 100644 --- a/drivers/mmc/core/slot-gpio.c +++ b/drivers/mmc/core/slot-gpio.c | |||
@@ -92,6 +92,20 @@ int mmc_gpio_get_cd(struct mmc_host *host) | |||
92 | } | 92 | } |
93 | EXPORT_SYMBOL(mmc_gpio_get_cd); | 93 | EXPORT_SYMBOL(mmc_gpio_get_cd); |
94 | 94 | ||
95 | /** | ||
96 | * mmc_gpio_request_ro - request a gpio for write-protection | ||
97 | * @host: mmc host | ||
98 | * @gpio: gpio number requested | ||
99 | * | ||
100 | * As devm_* managed functions are used in mmc_gpio_request_ro(), client | ||
101 | * drivers do not need to explicitly call mmc_gpio_free_ro() for freeing up, | ||
102 | * if the requesting and freeing are only needed at probing and unbinding time | ||
103 | * for once. However, if client drivers do something special like runtime | ||
104 | * switching for write-protection, they are responsible for calling | ||
105 | * mmc_gpio_request_ro() and mmc_gpio_free_ro() as a pair on their own. | ||
106 | * | ||
107 | * Returns zero on success, else an error. | ||
108 | */ | ||
95 | int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) | 109 | int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) |
96 | { | 110 | { |
97 | struct mmc_gpio *ctx; | 111 | struct mmc_gpio *ctx; |
@@ -106,7 +120,8 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) | |||
106 | 120 | ||
107 | ctx = host->slot.handler_priv; | 121 | ctx = host->slot.handler_priv; |
108 | 122 | ||
109 | ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label); | 123 | ret = devm_gpio_request_one(&host->class_dev, gpio, GPIOF_DIR_IN, |
124 | ctx->ro_label); | ||
110 | if (ret < 0) | 125 | if (ret < 0) |
111 | return ret; | 126 | return ret; |
112 | 127 | ||
@@ -116,6 +131,20 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) | |||
116 | } | 131 | } |
117 | EXPORT_SYMBOL(mmc_gpio_request_ro); | 132 | EXPORT_SYMBOL(mmc_gpio_request_ro); |
118 | 133 | ||
134 | /** | ||
135 | * mmc_gpio_request_cd - request a gpio for card-detection | ||
136 | * @host: mmc host | ||
137 | * @gpio: gpio number requested | ||
138 | * | ||
139 | * As devm_* managed functions are used in mmc_gpio_request_cd(), client | ||
140 | * drivers do not need to explicitly call mmc_gpio_free_cd() for freeing up, | ||
141 | * if the requesting and freeing are only needed at probing and unbinding time | ||
142 | * for once. However, if client drivers do something special like runtime | ||
143 | * switching for card-detection, they are responsible for calling | ||
144 | * mmc_gpio_request_cd() and mmc_gpio_free_cd() as a pair on their own. | ||
145 | * | ||
146 | * Returns zero on success, else an error. | ||
147 | */ | ||
119 | int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) | 148 | int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) |
120 | { | 149 | { |
121 | struct mmc_gpio *ctx; | 150 | struct mmc_gpio *ctx; |
@@ -128,7 +157,8 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) | |||
128 | 157 | ||
129 | ctx = host->slot.handler_priv; | 158 | ctx = host->slot.handler_priv; |
130 | 159 | ||
131 | ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->cd_label); | 160 | ret = devm_gpio_request_one(&host->class_dev, gpio, GPIOF_DIR_IN, |
161 | ctx->cd_label); | ||
132 | if (ret < 0) | 162 | if (ret < 0) |
133 | /* | 163 | /* |
134 | * don't bother freeing memory. It might still get used by other | 164 | * don't bother freeing memory. It might still get used by other |
@@ -146,7 +176,8 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) | |||
146 | irq = -EINVAL; | 176 | irq = -EINVAL; |
147 | 177 | ||
148 | if (irq >= 0) { | 178 | if (irq >= 0) { |
149 | ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt, | 179 | ret = devm_request_threaded_irq(&host->class_dev, irq, |
180 | NULL, mmc_gpio_cd_irqt, | ||
150 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | 181 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
151 | ctx->cd_label, host); | 182 | ctx->cd_label, host); |
152 | if (ret < 0) | 183 | if (ret < 0) |
@@ -164,6 +195,13 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) | |||
164 | } | 195 | } |
165 | EXPORT_SYMBOL(mmc_gpio_request_cd); | 196 | EXPORT_SYMBOL(mmc_gpio_request_cd); |
166 | 197 | ||
198 | /** | ||
199 | * mmc_gpio_free_ro - free the write-protection gpio | ||
200 | * @host: mmc host | ||
201 | * | ||
202 | * It's provided only for cases that client drivers need to manually free | ||
203 | * up the write-protection gpio requested by mmc_gpio_request_ro(). | ||
204 | */ | ||
167 | void mmc_gpio_free_ro(struct mmc_host *host) | 205 | void mmc_gpio_free_ro(struct mmc_host *host) |
168 | { | 206 | { |
169 | struct mmc_gpio *ctx = host->slot.handler_priv; | 207 | struct mmc_gpio *ctx = host->slot.handler_priv; |
@@ -175,10 +213,17 @@ void mmc_gpio_free_ro(struct mmc_host *host) | |||
175 | gpio = ctx->ro_gpio; | 213 | gpio = ctx->ro_gpio; |
176 | ctx->ro_gpio = -EINVAL; | 214 | ctx->ro_gpio = -EINVAL; |
177 | 215 | ||
178 | gpio_free(gpio); | 216 | devm_gpio_free(&host->class_dev, gpio); |
179 | } | 217 | } |
180 | EXPORT_SYMBOL(mmc_gpio_free_ro); | 218 | EXPORT_SYMBOL(mmc_gpio_free_ro); |
181 | 219 | ||
220 | /** | ||
221 | * mmc_gpio_free_cd - free the card-detection gpio | ||
222 | * @host: mmc host | ||
223 | * | ||
224 | * It's provided only for cases that client drivers need to manually free | ||
225 | * up the card-detection gpio requested by mmc_gpio_request_cd(). | ||
226 | */ | ||
182 | void mmc_gpio_free_cd(struct mmc_host *host) | 227 | void mmc_gpio_free_cd(struct mmc_host *host) |
183 | { | 228 | { |
184 | struct mmc_gpio *ctx = host->slot.handler_priv; | 229 | struct mmc_gpio *ctx = host->slot.handler_priv; |
@@ -188,13 +233,13 @@ void mmc_gpio_free_cd(struct mmc_host *host) | |||
188 | return; | 233 | return; |
189 | 234 | ||
190 | if (host->slot.cd_irq >= 0) { | 235 | if (host->slot.cd_irq >= 0) { |
191 | free_irq(host->slot.cd_irq, host); | 236 | devm_free_irq(&host->class_dev, host->slot.cd_irq, host); |
192 | host->slot.cd_irq = -EINVAL; | 237 | host->slot.cd_irq = -EINVAL; |
193 | } | 238 | } |
194 | 239 | ||
195 | gpio = ctx->cd_gpio; | 240 | gpio = ctx->cd_gpio; |
196 | ctx->cd_gpio = -EINVAL; | 241 | ctx->cd_gpio = -EINVAL; |
197 | 242 | ||
198 | gpio_free(gpio); | 243 | devm_gpio_free(&host->class_dev, gpio); |
199 | } | 244 | } |
200 | EXPORT_SYMBOL(mmc_gpio_free_cd); | 245 | EXPORT_SYMBOL(mmc_gpio_free_cd); |