aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core
diff options
context:
space:
mode:
authorUlf Hansson <ulf.hansson@linaro.org>2014-12-18 09:44:36 -0500
committerUlf Hansson <ulf.hansson@linaro.org>2015-01-19 03:56:18 -0500
commitdf8aca162e5ff2b20c7a4de3e64e5b96ff838ab0 (patch)
tree10fd8c7a3d6892525e89916044e0b8b728b61e2d /drivers/mmc/core
parente2d1926bad0d0cf7e4b8bf11a8efd1b5fe48893e (diff)
mmc: slot-gpio: Rework how to handle allocation of slot-gpio data
By moving the allocation of the slot-gpio data into mmc_alloc_host(), we can remove the slot-gpio internal calls to mmc_gpio_alloc(). This means mmc_gpio_alloc() has now only one caller left, which consequence allow us to simplify and remove some of the slot-gpio code. Additionally, this makes the slot-gpio mutex redundant, so let's remove it. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r--drivers/mmc/core/host.c20
-rw-r--r--drivers/mmc/core/slot-gpio.c62
2 files changed, 23 insertions, 59 deletions
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index fcb7f06373cf..07636449b4de 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -29,6 +29,7 @@
29 29
30#include "core.h" 30#include "core.h"
31#include "host.h" 31#include "host.h"
32#include "slot-gpio.h"
32 33
33#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev) 34#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
34 35
@@ -38,7 +39,6 @@ static DEFINE_SPINLOCK(mmc_host_lock);
38static void mmc_host_classdev_release(struct device *dev) 39static void mmc_host_classdev_release(struct device *dev)
39{ 40{
40 struct mmc_host *host = cls_dev_to_mmc_host(dev); 41 struct mmc_host *host = cls_dev_to_mmc_host(dev);
41 mutex_destroy(&host->slot.lock);
42 spin_lock(&mmc_host_lock); 42 spin_lock(&mmc_host_lock);
43 idr_remove(&mmc_host_idr, host->index); 43 idr_remove(&mmc_host_idr, host->index);
44 spin_unlock(&mmc_host_lock); 44 spin_unlock(&mmc_host_lock);
@@ -478,8 +478,10 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
478 host->index = err; 478 host->index = err;
479 spin_unlock(&mmc_host_lock); 479 spin_unlock(&mmc_host_lock);
480 idr_preload_end(); 480 idr_preload_end();
481 if (err < 0) 481 if (err < 0) {
482 goto free; 482 kfree(host);
483 return NULL;
484 }
483 485
484 dev_set_name(&host->class_dev, "mmc%d", host->index); 486 dev_set_name(&host->class_dev, "mmc%d", host->index);
485 487
@@ -488,10 +490,12 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
488 host->class_dev.class = &mmc_host_class; 490 host->class_dev.class = &mmc_host_class;
489 device_initialize(&host->class_dev); 491 device_initialize(&host->class_dev);
490 492
491 mmc_host_clk_init(host); 493 if (mmc_gpio_alloc(host)) {
494 put_device(&host->class_dev);
495 return NULL;
496 }
492 497
493 mutex_init(&host->slot.lock); 498 mmc_host_clk_init(host);
494 host->slot.cd_irq = -EINVAL;
495 499
496 spin_lock_init(&host->lock); 500 spin_lock_init(&host->lock);
497 init_waitqueue_head(&host->wq); 501 init_waitqueue_head(&host->wq);
@@ -512,10 +516,6 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
512 host->max_blk_count = PAGE_CACHE_SIZE / 512; 516 host->max_blk_count = PAGE_CACHE_SIZE / 512;
513 517
514 return host; 518 return host;
515
516free:
517 kfree(host);
518 return NULL;
519} 519}
520 520
521EXPORT_SYMBOL(mmc_alloc_host); 521EXPORT_SYMBOL(mmc_alloc_host);
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index ec918c27e77f..1a3edbd47719 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -43,29 +43,17 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
43int mmc_gpio_alloc(struct mmc_host *host) 43int mmc_gpio_alloc(struct mmc_host *host)
44{ 44{
45 size_t len = strlen(dev_name(host->parent)) + 4; 45 size_t len = strlen(dev_name(host->parent)) + 4;
46 struct mmc_gpio *ctx; 46 struct mmc_gpio *ctx = devm_kzalloc(host->parent,
47 47 sizeof(*ctx) + 2 * len, GFP_KERNEL);
48 mutex_lock(&host->slot.lock); 48
49 49 if (ctx) {
50 ctx = host->slot.handler_priv; 50 ctx->ro_label = ctx->cd_label + len;
51 if (!ctx) { 51 snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
52 /* 52 snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
53 * devm_kzalloc() can be called after device_initialize(), even 53 host->slot.handler_priv = ctx;
54 * before device_add(), i.e., between mmc_alloc_host() and 54 host->slot.cd_irq = -EINVAL;
55 * mmc_add_host()
56 */
57 ctx = devm_kzalloc(host->parent, sizeof(*ctx) + 2 * len,
58 GFP_KERNEL);
59 if (ctx) {
60 ctx->ro_label = ctx->cd_label + len;
61 snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
62 snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
63 host->slot.handler_priv = ctx;
64 }
65 } 55 }
66 56
67 mutex_unlock(&host->slot.lock);
68
69 return ctx ? 0 : -ENOMEM; 57 return ctx ? 0 : -ENOMEM;
70} 58}
71 59
@@ -111,18 +99,12 @@ EXPORT_SYMBOL(mmc_gpio_get_cd);
111 */ 99 */
112int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) 100int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
113{ 101{
114 struct mmc_gpio *ctx; 102 struct mmc_gpio *ctx = host->slot.handler_priv;
115 int ret; 103 int ret;
116 104
117 if (!gpio_is_valid(gpio)) 105 if (!gpio_is_valid(gpio))
118 return -EINVAL; 106 return -EINVAL;
119 107
120 ret = mmc_gpio_alloc(host);
121 if (ret < 0)
122 return ret;
123
124 ctx = host->slot.handler_priv;
125
126 ret = devm_gpio_request_one(host->parent, gpio, GPIOF_DIR_IN, 108 ret = devm_gpio_request_one(host->parent, gpio, GPIOF_DIR_IN,
127 ctx->ro_label); 109 ctx->ro_label);
128 if (ret < 0) 110 if (ret < 0)
@@ -187,15 +169,9 @@ EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
187int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio, 169int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio,
188 unsigned int debounce) 170 unsigned int debounce)
189{ 171{
190 struct mmc_gpio *ctx; 172 struct mmc_gpio *ctx = host->slot.handler_priv;
191 int ret; 173 int ret;
192 174
193 ret = mmc_gpio_alloc(host);
194 if (ret < 0)
195 return ret;
196
197 ctx = host->slot.handler_priv;
198
199 ret = devm_gpio_request_one(host->parent, gpio, GPIOF_DIR_IN, 175 ret = devm_gpio_request_one(host->parent, gpio, GPIOF_DIR_IN,
200 ctx->cd_label); 176 ctx->cd_label);
201 if (ret < 0) 177 if (ret < 0)
@@ -239,16 +215,10 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id,
239 unsigned int idx, bool override_active_level, 215 unsigned int idx, bool override_active_level,
240 unsigned int debounce, bool *gpio_invert) 216 unsigned int debounce, bool *gpio_invert)
241{ 217{
242 struct mmc_gpio *ctx; 218 struct mmc_gpio *ctx = host->slot.handler_priv;
243 struct gpio_desc *desc; 219 struct gpio_desc *desc;
244 int ret; 220 int ret;
245 221
246 ret = mmc_gpio_alloc(host);
247 if (ret < 0)
248 return ret;
249
250 ctx = host->slot.handler_priv;
251
252 if (!con_id) 222 if (!con_id)
253 con_id = ctx->cd_label; 223 con_id = ctx->cd_label;
254 224
@@ -291,16 +261,10 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id,
291 unsigned int idx, bool override_active_level, 261 unsigned int idx, bool override_active_level,
292 unsigned int debounce, bool *gpio_invert) 262 unsigned int debounce, bool *gpio_invert)
293{ 263{
294 struct mmc_gpio *ctx; 264 struct mmc_gpio *ctx = host->slot.handler_priv;
295 struct gpio_desc *desc; 265 struct gpio_desc *desc;
296 int ret; 266 int ret;
297 267
298 ret = mmc_gpio_alloc(host);
299 if (ret < 0)
300 return ret;
301
302 ctx = host->slot.handler_priv;
303
304 if (!con_id) 268 if (!con_id)
305 con_id = ctx->ro_label; 269 con_id = ctx->ro_label;
306 270