Lines Matching +full:time +full:- +full:slot
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic GPIO card-detect helper
13 #include <linux/mmc/slot-gpio.h>
17 #include "slot-gpio.h"
33 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpio_cd_irqt()
35 host->trigger_card_event = true; in mmc_gpio_cd_irqt()
36 mmc_detect_change(host, msecs_to_jiffies(ctx->cd_debounce_delay_ms)); in mmc_gpio_cd_irqt()
43 const char *devname = dev_name(host->parent); in mmc_gpio_alloc()
46 ctx = devm_kzalloc(host->parent, sizeof(*ctx), GFP_KERNEL); in mmc_gpio_alloc()
48 return -ENOMEM; in mmc_gpio_alloc()
50 ctx->cd_debounce_delay_ms = 200; in mmc_gpio_alloc()
51 ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL, "%s cd", devname); in mmc_gpio_alloc()
52 if (!ctx->cd_label) in mmc_gpio_alloc()
53 return -ENOMEM; in mmc_gpio_alloc()
54 ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL, "%s ro", devname); in mmc_gpio_alloc()
55 if (!ctx->ro_label) in mmc_gpio_alloc()
56 return -ENOMEM; in mmc_gpio_alloc()
57 ctx->cd_irq = -EINVAL; in mmc_gpio_alloc()
58 host->slot.handler_priv = ctx; in mmc_gpio_alloc()
59 host->slot.cd_irq = -EINVAL; in mmc_gpio_alloc()
66 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpio_set_cd_irq()
71 ctx->cd_irq = irq; in mmc_gpio_set_cd_irq()
77 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpio_get_ro()
80 if (!ctx || !ctx->ro_gpio) in mmc_gpio_get_ro()
81 return -ENOSYS; in mmc_gpio_get_ro()
83 cansleep = gpiod_cansleep(ctx->ro_gpio); in mmc_gpio_get_ro()
85 gpiod_get_value_cansleep(ctx->ro_gpio) : in mmc_gpio_get_ro()
86 gpiod_get_value(ctx->ro_gpio); in mmc_gpio_get_ro()
92 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpio_get_cd()
95 if (!ctx || !ctx->cd_gpio) in mmc_gpio_get_cd()
96 return -ENOSYS; in mmc_gpio_get_cd()
98 cansleep = gpiod_cansleep(ctx->cd_gpio); in mmc_gpio_get_cd()
100 gpiod_get_value_cansleep(ctx->cd_gpio) : in mmc_gpio_get_cd()
101 gpiod_get_value(ctx->cd_gpio); in mmc_gpio_get_cd()
107 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpiod_request_cd_irq()
108 int irq = -EINVAL; in mmc_gpiod_request_cd_irq()
111 if (host->slot.cd_irq >= 0 || !ctx || !ctx->cd_gpio) in mmc_gpiod_request_cd_irq()
118 if (ctx->cd_irq >= 0) in mmc_gpiod_request_cd_irq()
119 irq = ctx->cd_irq; in mmc_gpiod_request_cd_irq()
120 else if (!(host->caps & MMC_CAP_NEEDS_POLL)) in mmc_gpiod_request_cd_irq()
121 irq = gpiod_to_irq(ctx->cd_gpio); in mmc_gpiod_request_cd_irq()
124 if (!ctx->cd_gpio_isr) in mmc_gpiod_request_cd_irq()
125 ctx->cd_gpio_isr = mmc_gpio_cd_irqt; in mmc_gpiod_request_cd_irq()
126 ret = devm_request_threaded_irq(host->parent, irq, in mmc_gpiod_request_cd_irq()
127 NULL, ctx->cd_gpio_isr, in mmc_gpiod_request_cd_irq()
129 ctx->cd_label, host); in mmc_gpiod_request_cd_irq()
134 host->slot.cd_irq = irq; in mmc_gpiod_request_cd_irq()
137 host->caps |= MMC_CAP_NEEDS_POLL; in mmc_gpiod_request_cd_irq()
145 if (!(host->caps & MMC_CAP_CD_WAKE) || in mmc_gpio_set_cd_wake()
146 host->slot.cd_irq < 0 || in mmc_gpio_set_cd_wake()
147 on == host->slot.cd_wake_enabled) in mmc_gpio_set_cd_wake()
151 ret = enable_irq_wake(host->slot.cd_irq); in mmc_gpio_set_cd_wake()
152 host->slot.cd_wake_enabled = !ret; in mmc_gpio_set_cd_wake()
154 disable_irq_wake(host->slot.cd_irq); in mmc_gpio_set_cd_wake()
155 host->slot.cd_wake_enabled = false; in mmc_gpio_set_cd_wake()
163 * the card-detect GPIO.
167 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpio_set_cd_isr()
169 WARN_ON(ctx->cd_gpio_isr); in mmc_gpio_set_cd_isr()
170 ctx->cd_gpio_isr = isr; in mmc_gpio_set_cd_isr()
175 * mmc_gpiod_request_cd - request a gpio descriptor for card-detection
180 * @debounce: debounce time in microseconds
191 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpiod_request_cd()
195 desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); in mmc_gpiod_request_cd()
201 gpiod_set_consumer_name(desc, ctx->cd_label); in mmc_gpiod_request_cd()
206 ctx->cd_debounce_delay_ms = debounce / 1000; in mmc_gpiod_request_cd()
209 /* override forces default (active-low) polarity ... */ in mmc_gpiod_request_cd()
213 /* ... or active-high */ in mmc_gpiod_request_cd()
214 if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) in mmc_gpiod_request_cd()
217 ctx->cd_gpio = desc; in mmc_gpiod_request_cd()
224 * mmc_gpiod_set_cd_config - set config for card-detection GPIO
228 * This can be used by mmc host drivers to fixup a card-detection GPIO's config
237 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpiod_set_cd_config()
239 return gpiod_set_config(ctx->cd_gpio, config); in mmc_gpiod_set_cd_config()
245 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_can_gpio_cd()
247 return ctx->cd_gpio ? true : false; in mmc_can_gpio_cd()
252 * mmc_gpiod_request_ro - request a gpio descriptor for write protection
256 * @debounce: debounce time in microseconds
263 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_gpiod_request_ro()
267 desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); in mmc_gpiod_request_ro()
273 gpiod_set_consumer_name(desc, ctx->ro_label); in mmc_gpiod_request_ro()
281 if (host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH) in mmc_gpiod_request_ro()
284 ctx->ro_gpio = desc; in mmc_gpiod_request_ro()
292 struct mmc_gpio *ctx = host->slot.handler_priv; in mmc_can_gpio_ro()
294 return ctx->ro_gpio ? true : false; in mmc_can_gpio_ro()