aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-03-10 09:02:39 -0400
committerChris Ball <chris@printf.net>2014-03-17 09:11:46 -0400
commit842f4bdd37c7a0984e22aa919ad1f043137ac5c8 (patch)
tree7daefc2aac4422411ca9809ff00735db303e9df6
parent2b5cc85135279c3504c72ab51bd089d102a2f8e9 (diff)
mmc: slot-gpio: Record GPIO descriptors instead of GPIO numbers
In preparation for adding a descriptor-based CD GPIO API, switch from recording GPIO numbers to recording GPIO descriptors. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Tested-by: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Chris Ball <chris@printf.net>
-rw-r--r--drivers/mmc/core/slot-gpio.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 46596b71a32f..86547a2a82c6 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/gpio.h> 12#include <linux/gpio.h>
13#include <linux/gpio/consumer.h>
13#include <linux/interrupt.h> 14#include <linux/interrupt.h>
14#include <linux/jiffies.h> 15#include <linux/jiffies.h>
15#include <linux/mmc/host.h> 16#include <linux/mmc/host.h>
@@ -18,8 +19,10 @@
18#include <linux/slab.h> 19#include <linux/slab.h>
19 20
20struct mmc_gpio { 21struct mmc_gpio {
21 int ro_gpio; 22 struct gpio_desc *ro_gpio;
22 int cd_gpio; 23 struct gpio_desc *cd_gpio;
24 bool override_ro_active_level;
25 bool override_cd_active_level;
23 char *ro_label; 26 char *ro_label;
24 char cd_label[0]; 27 char cd_label[0];
25}; 28};
@@ -57,8 +60,6 @@ static int mmc_gpio_alloc(struct mmc_host *host)
57 ctx->ro_label = ctx->cd_label + len; 60 ctx->ro_label = ctx->cd_label + len;
58 snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent)); 61 snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
59 snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent)); 62 snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
60 ctx->cd_gpio = -EINVAL;
61 ctx->ro_gpio = -EINVAL;
62 host->slot.handler_priv = ctx; 63 host->slot.handler_priv = ctx;
63 } 64 }
64 } 65 }
@@ -72,11 +73,14 @@ int mmc_gpio_get_ro(struct mmc_host *host)
72{ 73{
73 struct mmc_gpio *ctx = host->slot.handler_priv; 74 struct mmc_gpio *ctx = host->slot.handler_priv;
74 75
75 if (!ctx || !gpio_is_valid(ctx->ro_gpio)) 76 if (!ctx || !ctx->ro_gpio)
76 return -ENOSYS; 77 return -ENOSYS;
77 78
78 return !gpio_get_value_cansleep(ctx->ro_gpio) ^ 79 if (ctx->override_ro_active_level)
79 !!(host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH); 80 return !gpiod_get_raw_value_cansleep(ctx->ro_gpio) ^
81 !!(host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH);
82
83 return gpiod_get_value_cansleep(ctx->ro_gpio);
80} 84}
81EXPORT_SYMBOL(mmc_gpio_get_ro); 85EXPORT_SYMBOL(mmc_gpio_get_ro);
82 86
@@ -84,11 +88,14 @@ int mmc_gpio_get_cd(struct mmc_host *host)
84{ 88{
85 struct mmc_gpio *ctx = host->slot.handler_priv; 89 struct mmc_gpio *ctx = host->slot.handler_priv;
86 90
87 if (!ctx || !gpio_is_valid(ctx->cd_gpio)) 91 if (!ctx || !ctx->cd_gpio)
88 return -ENOSYS; 92 return -ENOSYS;
89 93
90 return !gpio_get_value_cansleep(ctx->cd_gpio) ^ 94 if (ctx->override_cd_active_level)
91 !!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH); 95 return !gpiod_get_raw_value_cansleep(ctx->cd_gpio) ^
96 !!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH);
97
98 return gpiod_get_value_cansleep(ctx->cd_gpio);
92} 99}
93EXPORT_SYMBOL(mmc_gpio_get_cd); 100EXPORT_SYMBOL(mmc_gpio_get_cd);
94 101
@@ -125,7 +132,8 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
125 if (ret < 0) 132 if (ret < 0)
126 return ret; 133 return ret;
127 134
128 ctx->ro_gpio = gpio; 135 ctx->override_ro_active_level = true;
136 ctx->ro_gpio = gpio_to_desc(gpio);
129 137
130 return 0; 138 return 0;
131} 139}
@@ -201,7 +209,8 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio,
201 if (irq < 0) 209 if (irq < 0)
202 host->caps |= MMC_CAP_NEEDS_POLL; 210 host->caps |= MMC_CAP_NEEDS_POLL;
203 211
204 ctx->cd_gpio = gpio; 212 ctx->override_cd_active_level = true;
213 ctx->cd_gpio = gpio_to_desc(gpio);
205 214
206 return 0; 215 return 0;
207} 216}
@@ -219,11 +228,11 @@ void mmc_gpio_free_ro(struct mmc_host *host)
219 struct mmc_gpio *ctx = host->slot.handler_priv; 228 struct mmc_gpio *ctx = host->slot.handler_priv;
220 int gpio; 229 int gpio;
221 230
222 if (!ctx || !gpio_is_valid(ctx->ro_gpio)) 231 if (!ctx || !ctx->ro_gpio)
223 return; 232 return;
224 233
225 gpio = ctx->ro_gpio; 234 gpio = desc_to_gpio(ctx->ro_gpio);
226 ctx->ro_gpio = -EINVAL; 235 ctx->ro_gpio = NULL;
227 236
228 devm_gpio_free(&host->class_dev, gpio); 237 devm_gpio_free(&host->class_dev, gpio);
229} 238}
@@ -241,7 +250,7 @@ void mmc_gpio_free_cd(struct mmc_host *host)
241 struct mmc_gpio *ctx = host->slot.handler_priv; 250 struct mmc_gpio *ctx = host->slot.handler_priv;
242 int gpio; 251 int gpio;
243 252
244 if (!ctx || !gpio_is_valid(ctx->cd_gpio)) 253 if (!ctx || !ctx->cd_gpio)
245 return; 254 return;
246 255
247 if (host->slot.cd_irq >= 0) { 256 if (host->slot.cd_irq >= 0) {
@@ -249,8 +258,8 @@ void mmc_gpio_free_cd(struct mmc_host *host)
249 host->slot.cd_irq = -EINVAL; 258 host->slot.cd_irq = -EINVAL;
250 } 259 }
251 260
252 gpio = ctx->cd_gpio; 261 gpio = desc_to_gpio(ctx->cd_gpio);
253 ctx->cd_gpio = -EINVAL; 262 ctx->cd_gpio = NULL;
254 263
255 devm_gpio_free(&host->class_dev, gpio); 264 devm_gpio_free(&host->class_dev, gpio);
256} 265}