void mmc_gpiod_request_cd_irq(struct mmc_host *host)
{ struct mmc_gpio *ctx = host->slot.handler_priv; int irq = -EINVAL; int ret;
if (host->slot.cd_irq >= 0 || !ctx || !ctx->cd_gpio) return;
/* * Do not use IRQ if the platform prefers to poll, e.g., because that * IRQ number is already used by another unit and cannot be shared.
*/ if (ctx->cd_irq >= 0)
irq = ctx->cd_irq; elseif (!(host->caps & MMC_CAP_NEEDS_POLL))
irq = gpiod_to_irq(ctx->cd_gpio);
if (irq >= 0) { if (!ctx->cd_gpio_isr)
ctx->cd_gpio_isr = mmc_gpio_cd_irqt;
ret = devm_request_threaded_irq(host->parent, irq,
NULL, ctx->cd_gpio_isr,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
ctx->cd_label, host); if (ret < 0)
irq = ret;
}
host->slot.cd_irq = irq;
if (irq < 0)
host->caps |= MMC_CAP_NEEDS_POLL;
}
EXPORT_SYMBOL(mmc_gpiod_request_cd_irq);
int mmc_gpio_set_cd_wake(struct mmc_host *host, bool on)
{ int ret = 0;
if (!(host->caps & MMC_CAP_CD_WAKE) ||
host->slot.cd_irq < 0 ||
on == host->slot.cd_wake_enabled) return 0;
if (on) {
ret = enable_irq_wake(host->slot.cd_irq);
host->slot.cd_wake_enabled = !ret;
} else {
disable_irq_wake(host->slot.cd_irq);
host->slot.cd_wake_enabled = false;
}
/** * mmc_gpiod_request_cd - request a gpio descriptor for card-detection * @host: mmc host * @con_id: function within the GPIO consumer * @idx: index of the GPIO to obtain in the consumer * @override_active_level: ignore %GPIO_ACTIVE_LOW flag * @debounce: debounce time in microseconds * * Note that this must be called prior to mmc_add_host() * otherwise the caller must also call mmc_gpiod_request_cd_irq(). * * Returns zero on success, else an error.
*/ int mmc_gpiod_request_cd(struct mmc_host *host, constchar *con_id, unsignedint idx, bool override_active_level, unsignedint debounce)
{ struct mmc_gpio *ctx = host->slot.handler_priv; struct gpio_desc *desc; int ret;
desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); if (IS_ERR(desc)) return PTR_ERR(desc);
/* Update default label if no con_id provided */ if (!con_id)
gpiod_set_consumer_name(desc, ctx->cd_label);
if (debounce) {
ret = gpiod_set_debounce(desc, debounce); if (ret < 0)
ctx->cd_debounce_delay_ms = debounce / 1000;
}
/* ... or active-high */ if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH)
gpiod_toggle_active_low(desc);
ctx->cd_gpio = desc;
return 0;
}
EXPORT_SYMBOL(mmc_gpiod_request_cd);
/** * mmc_gpiod_set_cd_config - set config for card-detection GPIO * @host: mmc host * @config: Generic pinconf config (from pinconf_to_config_packed()) * * This can be used by mmc host drivers to fixup a card-detection GPIO's config * (e.g. set PIN_CONFIG_BIAS_PULL_UP) after acquiring the GPIO descriptor * through mmc_gpiod_request_cd(). * * Returns: * 0 on success, or a negative errno value on error.
*/ int mmc_gpiod_set_cd_config(struct mmc_host *host, unsignedlong config)
{ struct mmc_gpio *ctx = host->slot.handler_priv;
/** * mmc_gpiod_request_ro - request a gpio descriptor for write protection * @host: mmc host * @con_id: function within the GPIO consumer * @idx: index of the GPIO to obtain in the consumer * @debounce: debounce time in microseconds * * Returns zero on success, else an error.
*/ int mmc_gpiod_request_ro(struct mmc_host *host, constchar *con_id, unsignedint idx, unsignedint debounce)
{ struct mmc_gpio *ctx = host->slot.handler_priv; struct gpio_desc *desc; int ret;
desc = devm_gpiod_get_index(host->parent, con_id, idx, GPIOD_IN); if (IS_ERR(desc)) return PTR_ERR(desc);
/* Update default label if no con_id provided */ if (!con_id)
gpiod_set_consumer_name(desc, ctx->ro_label);
if (debounce) {
ret = gpiod_set_debounce(desc, debounce); if (ret < 0) return ret;
}
if (host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH)
gpiod_toggle_active_low(desc);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.