Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Generic GPIO card-detect helper |
| 3 | * |
| 4 | * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
| 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/gpio.h> |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 13 | #include <linux/gpio/consumer.h> |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/jiffies.h> |
| 16 | #include <linux/mmc/host.h> |
| 17 | #include <linux/mmc/slot-gpio.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/slab.h> |
| 20 | |
| 21 | struct mmc_gpio { |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 22 | struct gpio_desc *ro_gpio; |
| 23 | struct gpio_desc *cd_gpio; |
| 24 | bool override_ro_active_level; |
| 25 | bool override_cd_active_level; |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 26 | char *ro_label; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 27 | char cd_label[0]; |
| 28 | }; |
| 29 | |
| 30 | static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id) |
| 31 | { |
| 32 | /* Schedule a card detection after a debounce timeout */ |
Guennadi Liakhovetski | 451c895 | 2012-12-04 16:51:36 +0100 | [diff] [blame] | 33 | struct mmc_host *host = dev_id; |
| 34 | |
| 35 | if (host->ops->card_event) |
| 36 | host->ops->card_event(host); |
| 37 | |
| 38 | mmc_detect_change(host, msecs_to_jiffies(200)); |
| 39 | |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 40 | return IRQ_HANDLED; |
| 41 | } |
| 42 | |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 43 | static int mmc_gpio_alloc(struct mmc_host *host) |
| 44 | { |
| 45 | size_t len = strlen(dev_name(host->parent)) + 4; |
| 46 | struct mmc_gpio *ctx; |
| 47 | |
| 48 | mutex_lock(&host->slot.lock); |
| 49 | |
| 50 | ctx = host->slot.handler_priv; |
| 51 | if (!ctx) { |
| 52 | /* |
| 53 | * devm_kzalloc() can be called after device_initialize(), even |
| 54 | * before device_add(), i.e., between mmc_alloc_host() and |
| 55 | * mmc_add_host() |
| 56 | */ |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 57 | ctx = devm_kzalloc(&host->class_dev, sizeof(*ctx) + 2 * len, |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 58 | GFP_KERNEL); |
| 59 | if (ctx) { |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 60 | ctx->ro_label = ctx->cd_label + len; |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 61 | snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent)); |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 62 | snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent)); |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 63 | host->slot.handler_priv = ctx; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | mutex_unlock(&host->slot.lock); |
| 68 | |
| 69 | return ctx ? 0 : -ENOMEM; |
| 70 | } |
| 71 | |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 72 | int mmc_gpio_get_ro(struct mmc_host *host) |
| 73 | { |
| 74 | struct mmc_gpio *ctx = host->slot.handler_priv; |
| 75 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 76 | if (!ctx || !ctx->ro_gpio) |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 77 | return -ENOSYS; |
| 78 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 79 | if (ctx->override_ro_active_level) |
| 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); |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 84 | } |
| 85 | EXPORT_SYMBOL(mmc_gpio_get_ro); |
| 86 | |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 87 | int mmc_gpio_get_cd(struct mmc_host *host) |
| 88 | { |
| 89 | struct mmc_gpio *ctx = host->slot.handler_priv; |
| 90 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 91 | if (!ctx || !ctx->cd_gpio) |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 92 | return -ENOSYS; |
| 93 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 94 | if (ctx->override_cd_active_level) |
| 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); |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 99 | } |
| 100 | EXPORT_SYMBOL(mmc_gpio_get_cd); |
| 101 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 102 | /** |
| 103 | * mmc_gpio_request_ro - request a gpio for write-protection |
| 104 | * @host: mmc host |
| 105 | * @gpio: gpio number requested |
| 106 | * |
| 107 | * As devm_* managed functions are used in mmc_gpio_request_ro(), client |
| 108 | * drivers do not need to explicitly call mmc_gpio_free_ro() for freeing up, |
| 109 | * if the requesting and freeing are only needed at probing and unbinding time |
| 110 | * for once. However, if client drivers do something special like runtime |
| 111 | * switching for write-protection, they are responsible for calling |
| 112 | * mmc_gpio_request_ro() and mmc_gpio_free_ro() as a pair on their own. |
| 113 | * |
| 114 | * Returns zero on success, else an error. |
| 115 | */ |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 116 | int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) |
| 117 | { |
| 118 | struct mmc_gpio *ctx; |
| 119 | int ret; |
| 120 | |
| 121 | if (!gpio_is_valid(gpio)) |
| 122 | return -EINVAL; |
| 123 | |
| 124 | ret = mmc_gpio_alloc(host); |
| 125 | if (ret < 0) |
| 126 | return ret; |
| 127 | |
| 128 | ctx = host->slot.handler_priv; |
| 129 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 130 | ret = devm_gpio_request_one(&host->class_dev, gpio, GPIOF_DIR_IN, |
| 131 | ctx->ro_label); |
Chris Ball | 15e8a8e | 2012-09-09 22:56:48 -0400 | [diff] [blame] | 132 | if (ret < 0) |
| 133 | return ret; |
| 134 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 135 | ctx->override_ro_active_level = true; |
| 136 | ctx->ro_gpio = gpio_to_desc(gpio); |
Chris Ball | 15e8a8e | 2012-09-09 22:56:48 -0400 | [diff] [blame] | 137 | |
| 138 | return 0; |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 139 | } |
| 140 | EXPORT_SYMBOL(mmc_gpio_request_ro); |
| 141 | |
Adrian Hunter | 740a221 | 2014-03-10 15:02:41 +0200 | [diff] [blame^] | 142 | void mmc_gpiod_request_cd_irq(struct mmc_host *host) |
Adrian Hunter | 2665267 | 2014-03-10 15:02:40 +0200 | [diff] [blame] | 143 | { |
| 144 | struct mmc_gpio *ctx = host->slot.handler_priv; |
| 145 | int ret, irq; |
| 146 | |
| 147 | if (host->slot.cd_irq >= 0 || !ctx || !ctx->cd_gpio) |
| 148 | return; |
| 149 | |
| 150 | irq = gpiod_to_irq(ctx->cd_gpio); |
| 151 | |
| 152 | /* |
| 153 | * Even if gpiod_to_irq() returns a valid IRQ number, the platform might |
| 154 | * still prefer to poll, e.g., because that IRQ number is already used |
| 155 | * by another unit and cannot be shared. |
| 156 | */ |
| 157 | if (irq >= 0 && host->caps & MMC_CAP_NEEDS_POLL) |
| 158 | irq = -EINVAL; |
| 159 | |
| 160 | if (irq >= 0) { |
| 161 | ret = devm_request_threaded_irq(&host->class_dev, irq, |
| 162 | NULL, mmc_gpio_cd_irqt, |
| 163 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
| 164 | ctx->cd_label, host); |
| 165 | if (ret < 0) |
| 166 | irq = ret; |
| 167 | } |
| 168 | |
| 169 | host->slot.cd_irq = irq; |
| 170 | |
| 171 | if (irq < 0) |
| 172 | host->caps |= MMC_CAP_NEEDS_POLL; |
| 173 | } |
Adrian Hunter | 740a221 | 2014-03-10 15:02:41 +0200 | [diff] [blame^] | 174 | EXPORT_SYMBOL(mmc_gpiod_request_cd_irq); |
Adrian Hunter | 2665267 | 2014-03-10 15:02:40 +0200 | [diff] [blame] | 175 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 176 | /** |
| 177 | * mmc_gpio_request_cd - request a gpio for card-detection |
| 178 | * @host: mmc host |
| 179 | * @gpio: gpio number requested |
Laurent Pinchart | 214fc30 | 2013-08-08 12:38:31 +0200 | [diff] [blame] | 180 | * @debounce: debounce time in microseconds |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 181 | * |
| 182 | * As devm_* managed functions are used in mmc_gpio_request_cd(), client |
| 183 | * drivers do not need to explicitly call mmc_gpio_free_cd() for freeing up, |
| 184 | * if the requesting and freeing are only needed at probing and unbinding time |
| 185 | * for once. However, if client drivers do something special like runtime |
| 186 | * switching for card-detection, they are responsible for calling |
| 187 | * mmc_gpio_request_cd() and mmc_gpio_free_cd() as a pair on their own. |
| 188 | * |
Laurent Pinchart | 214fc30 | 2013-08-08 12:38:31 +0200 | [diff] [blame] | 189 | * If GPIO debouncing is desired, set the debounce parameter to a non-zero |
| 190 | * value. The caller is responsible for ensuring that the GPIO driver associated |
| 191 | * with the GPIO supports debouncing, otherwise an error will be returned. |
| 192 | * |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 193 | * Returns zero on success, else an error. |
| 194 | */ |
Laurent Pinchart | 214fc30 | 2013-08-08 12:38:31 +0200 | [diff] [blame] | 195 | int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio, |
| 196 | unsigned int debounce) |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 197 | { |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 198 | struct mmc_gpio *ctx; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 199 | int ret; |
| 200 | |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 201 | ret = mmc_gpio_alloc(host); |
| 202 | if (ret < 0) |
| 203 | return ret; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 204 | |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 205 | ctx = host->slot.handler_priv; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 206 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 207 | ret = devm_gpio_request_one(&host->class_dev, gpio, GPIOF_DIR_IN, |
| 208 | ctx->cd_label); |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 209 | if (ret < 0) |
Guennadi Liakhovetski | a7d1a1e | 2012-05-01 16:51:38 +0200 | [diff] [blame] | 210 | /* |
| 211 | * don't bother freeing memory. It might still get used by other |
| 212 | * slot functions, in any case it will be freed, when the device |
| 213 | * is destroyed. |
| 214 | */ |
| 215 | return ret; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 216 | |
Laurent Pinchart | 214fc30 | 2013-08-08 12:38:31 +0200 | [diff] [blame] | 217 | if (debounce) { |
| 218 | ret = gpio_set_debounce(gpio, debounce); |
| 219 | if (ret < 0) |
| 220 | return ret; |
| 221 | } |
| 222 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 223 | ctx->override_cd_active_level = true; |
| 224 | ctx->cd_gpio = gpio_to_desc(gpio); |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 225 | |
Adrian Hunter | 2665267 | 2014-03-10 15:02:40 +0200 | [diff] [blame] | 226 | mmc_gpiod_request_cd_irq(host); |
| 227 | |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 228 | return 0; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 229 | } |
| 230 | EXPORT_SYMBOL(mmc_gpio_request_cd); |
| 231 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 232 | /** |
| 233 | * mmc_gpio_free_ro - free the write-protection gpio |
| 234 | * @host: mmc host |
| 235 | * |
| 236 | * It's provided only for cases that client drivers need to manually free |
| 237 | * up the write-protection gpio requested by mmc_gpio_request_ro(). |
| 238 | */ |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 239 | void mmc_gpio_free_ro(struct mmc_host *host) |
| 240 | { |
| 241 | struct mmc_gpio *ctx = host->slot.handler_priv; |
| 242 | int gpio; |
| 243 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 244 | if (!ctx || !ctx->ro_gpio) |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 245 | return; |
| 246 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 247 | gpio = desc_to_gpio(ctx->ro_gpio); |
| 248 | ctx->ro_gpio = NULL; |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 249 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 250 | devm_gpio_free(&host->class_dev, gpio); |
Guennadi Liakhovetski | 5aa7dad | 2012-05-01 16:59:38 +0200 | [diff] [blame] | 251 | } |
| 252 | EXPORT_SYMBOL(mmc_gpio_free_ro); |
| 253 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 254 | /** |
| 255 | * mmc_gpio_free_cd - free the card-detection gpio |
| 256 | * @host: mmc host |
| 257 | * |
| 258 | * It's provided only for cases that client drivers need to manually free |
| 259 | * up the card-detection gpio requested by mmc_gpio_request_cd(). |
| 260 | */ |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 261 | void mmc_gpio_free_cd(struct mmc_host *host) |
| 262 | { |
Guennadi Liakhovetski | 27410ee | 2012-05-01 15:40:15 +0200 | [diff] [blame] | 263 | struct mmc_gpio *ctx = host->slot.handler_priv; |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 264 | int gpio; |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 265 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 266 | if (!ctx || !ctx->cd_gpio) |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 267 | return; |
| 268 | |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 269 | if (host->slot.cd_irq >= 0) { |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 270 | devm_free_irq(&host->class_dev, host->slot.cd_irq, host); |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 271 | host->slot.cd_irq = -EINVAL; |
| 272 | } |
| 273 | |
Adrian Hunter | 842f4bd | 2014-03-10 15:02:39 +0200 | [diff] [blame] | 274 | gpio = desc_to_gpio(ctx->cd_gpio); |
| 275 | ctx->cd_gpio = NULL; |
Guennadi Liakhovetski | befe404 | 2012-05-01 16:27:25 +0200 | [diff] [blame] | 276 | |
Shawn Guo | d65b5ae | 2012-12-11 22:32:18 +0800 | [diff] [blame] | 277 | devm_gpio_free(&host->class_dev, gpio); |
Guennadi Liakhovetski | fd0ea65 | 2012-04-30 23:31:57 +0200 | [diff] [blame] | 278 | } |
| 279 | EXPORT_SYMBOL(mmc_gpio_free_cd); |
Adrian Hunter | 740a221 | 2014-03-10 15:02:41 +0200 | [diff] [blame^] | 280 | |
| 281 | /** |
| 282 | * mmc_gpiod_request_cd - request a gpio descriptor for card-detection |
| 283 | * @host: mmc host |
| 284 | * @con_id: function within the GPIO consumer |
| 285 | * @idx: index of the GPIO to obtain in the consumer |
| 286 | * @override_active_level: ignore %GPIO_ACTIVE_LOW flag |
| 287 | * @debounce: debounce time in microseconds |
| 288 | * |
| 289 | * Use this function in place of mmc_gpio_request_cd() to use the GPIO |
| 290 | * descriptor API. Note that it is paired with mmc_gpiod_free_cd() not |
| 291 | * mmc_gpio_free_cd(). Note also that it must be called prior to mmc_add_host() |
| 292 | * otherwise the caller must also call mmc_gpiod_request_cd_irq(). |
| 293 | * |
| 294 | * Returns zero on success, else an error. |
| 295 | */ |
| 296 | int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, |
| 297 | unsigned int idx, bool override_active_level, |
| 298 | unsigned int debounce) |
| 299 | { |
| 300 | struct mmc_gpio *ctx; |
| 301 | struct gpio_desc *desc; |
| 302 | int ret; |
| 303 | |
| 304 | ret = mmc_gpio_alloc(host); |
| 305 | if (ret < 0) |
| 306 | return ret; |
| 307 | |
| 308 | ctx = host->slot.handler_priv; |
| 309 | |
| 310 | if (!con_id) |
| 311 | con_id = ctx->cd_label; |
| 312 | |
| 313 | desc = devm_gpiod_get_index(host->parent, con_id, idx); |
| 314 | if (IS_ERR(desc)) |
| 315 | return PTR_ERR(desc); |
| 316 | |
| 317 | ret = gpiod_direction_input(desc); |
| 318 | if (ret < 0) |
| 319 | return ret; |
| 320 | |
| 321 | if (debounce) { |
| 322 | ret = gpiod_set_debounce(desc, debounce); |
| 323 | if (ret < 0) |
| 324 | return ret; |
| 325 | } |
| 326 | |
| 327 | ctx->override_cd_active_level = override_active_level; |
| 328 | ctx->cd_gpio = desc; |
| 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | EXPORT_SYMBOL(mmc_gpiod_request_cd); |
| 333 | |
| 334 | /** |
| 335 | * mmc_gpiod_free_cd - free the card-detection gpio descriptor |
| 336 | * @host: mmc host |
| 337 | * |
| 338 | * It's provided only for cases that client drivers need to manually free |
| 339 | * up the card-detection gpio requested by mmc_gpiod_request_cd(). |
| 340 | */ |
| 341 | void mmc_gpiod_free_cd(struct mmc_host *host) |
| 342 | { |
| 343 | struct mmc_gpio *ctx = host->slot.handler_priv; |
| 344 | |
| 345 | if (!ctx || !ctx->cd_gpio) |
| 346 | return; |
| 347 | |
| 348 | if (host->slot.cd_irq >= 0) { |
| 349 | devm_free_irq(&host->class_dev, host->slot.cd_irq, host); |
| 350 | host->slot.cd_irq = -EINVAL; |
| 351 | } |
| 352 | |
| 353 | devm_gpiod_put(&host->class_dev, ctx->cd_gpio); |
| 354 | |
| 355 | ctx->cd_gpio = NULL; |
| 356 | } |
| 357 | EXPORT_SYMBOL(mmc_gpiod_free_cd); |