Re: [PATCH 2/2] mmc: add a generic GPIO card-detect helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Fri, Dec 23 2011, Guennadi Liakhovetski wrote:
> This patch adds a primitive helper to support card hotplug detection on
> platforms, where a GPIO, capable of producing interrupts, is used for
> detection of card-insertion and -removal events.
>
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@xxxxxx>
> ---
>  drivers/mmc/core/Makefile   |    2 +-
>  drivers/mmc/core/cd-gpio.c  |   74 +++++++++++++++++++++++++++++++++++++++++++
>  include/linux/mmc/cd-gpio.h |   19 +++++++++++
>  3 files changed, 94 insertions(+), 1 deletions(-)
>  create mode 100644 drivers/mmc/core/cd-gpio.c
>  create mode 100644 include/linux/mmc/cd-gpio.h
>
> diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
> index 6395019..dca4428 100644
> --- a/drivers/mmc/core/Makefile
> +++ b/drivers/mmc/core/Makefile
> @@ -7,6 +7,6 @@ mmc_core-y			:= core.o bus.o host.o \
>  				   mmc.o mmc_ops.o sd.o sd_ops.o \
>  				   sdio.o sdio_ops.o sdio_bus.o \
>  				   sdio_cis.o sdio_io.o sdio_irq.o \
> -				   quirks.o
> +				   quirks.o cd-gpio.o
>  
>  mmc_core-$(CONFIG_DEBUG_FS)	+= debugfs.o
> diff --git a/drivers/mmc/core/cd-gpio.c b/drivers/mmc/core/cd-gpio.c
> new file mode 100644
> index 0000000..4c79f0c
> --- /dev/null
> +++ b/drivers/mmc/core/cd-gpio.c
> @@ -0,0 +1,74 @@
> +/*
> + * Generic GPIO card-detect helper
> + *
> + * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@xxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/gpio.h>
> +#include <linux/interrupt.h>
> +#include <linux/jiffies.h>
> +#include <linux/mmc/host.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +
> +struct mmc_cd_gpio {
> +	unsigned int gpio;
> +	char label[0];
> +};
> +
> +static irqreturn_t mmc_cd_gpio_irqt(int irq, void *dev_id)
> +{
> +	/* Schedule a card detection after a debounce timeout */
> +	mmc_detect_change(dev_id, msecs_to_jiffies(100));
> +	return IRQ_HANDLED;
> +}
> +
> +int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio,
> +			unsigned int irq, unsigned long flags)
> +{
> +	size_t len = strlen(dev_name(host->parent)) + 4;
> +	struct mmc_cd_gpio *cd = kmalloc(sizeof(*cd) + len, GFP_KERNEL);
> +	int ret;
> +
> +	if (!cd)
> +		return -ENOMEM;
> +
> +	sprintf(cd->label, "%s cd", dev_name(host->parent));

Mind using snprintf() instead?  I prefer it for new uses, it leaves
fewer uses of sprintf to audit for correctness.

Thanks,

- Chris.
-- 
Chris Ball   <cjb@xxxxxxxxxx>   <http://printf.net/>
One Laptop Per Child
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux