[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <539E79A1.50208@roeck-us.net>
Date: Sun, 15 Jun 2014 21:59:13 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: George Cherian <george.cherian@...com>, cw00.choi@...sung.com,
myungjoo.ham@...sung.com, grant.likely@...aro.org,
rdunlap@...radead.org, galak@...eaurora.org, mark.rutland@....com,
ijc+devicetree@...lion.org.uk, robh+dt@...nel.org,
pawel.moll@....com
CC: linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
devicetree@...r.kernel.org
Subject: Re: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx
On 06/15/2014 07:42 PM, George Cherian wrote:
> This is the driver for the USB ID pin detection. This driver
> handles only the USB ID pin changes generated by cable
> insertion/removal.
>
> Signed-off-by: George Cherian <george.cherian@...com>
Hi George,
Curious: Why can't you use extcon-gpio ?
Also, I thought that Linux specific bindings would be unacceptable.
"ti,dra7xx-extcon" looks very linux specific to me. Did the rules change ?
Thanks,
Guenter
> ---
> .../devicetree/bindings/extcon/extcon-dra7xx.txt | 15 ++
> drivers/extcon/Kconfig | 5 +
> drivers/extcon/Makefile | 1 +
> drivers/extcon/extcon-dra7xx.c | 164 +++++++++++++++++++++
> 4 files changed, 185 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/extcon/extcon-dra7xx.txt
> create mode 100644 drivers/extcon/extcon-dra7xx.c
>
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-dra7xx.txt b/Documentation/devicetree/bindings/extcon/extcon-dra7xx.txt
> new file mode 100644
> index 0000000..69c3804
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-dra7xx.txt
> @@ -0,0 +1,15 @@
> +EXTCON FOR DRA7xx USB
> +
> +Required Properties:
> + - compatible : Should be "ti,dra7xx-extcon"
> + - gpios : specifies the gpio pin used for ID pin detection.
> +
> +
> +Please refer to ../gpio/gpio.txt for details of the common GPIO bindings
> +
> +Example:
> +
> + dra7xx_extcon {
> + compatible = "ti,dra7xx-extcon";
> + gpios = <&gpio21 1 0>;
> + };
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index aebde48..1481b7f 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -70,4 +70,9 @@ config EXTCON_PALMAS
> Say Y here to enable support for USB peripheral and USB host
> detection by palmas usb.
>
> +config EXTCON_DRA7XX
> + tristate "DRA7xx USB ID detection EXTCON support"
> + help
> + Say Y here to enable support for USB ID detection for DRA7xx.
> +
> endif # MULTISTATE_SWITCH
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index bf7861e..b5f7cac 100644
> --- a/drivers/extcon/Makefile
> +++ b/drivers/extcon/Makefile
> @@ -10,3 +10,4 @@ obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o
> obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o
> obj-$(CONFIG_EXTCON_ARIZONA) += extcon-arizona.o
> obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o
> +obj-$(CONFIG_EXTCON_DRA7XX) += extcon-dra7xx.o
> diff --git a/drivers/extcon/extcon-dra7xx.c b/drivers/extcon/extcon-dra7xx.c
> new file mode 100644
> index 0000000..2f80509
> --- /dev/null
> +++ b/drivers/extcon/extcon-dra7xx.c
> @@ -0,0 +1,164 @@
> +/*
> + * DRA7xx-Extcon USB ID pin detection driver
> + *
> + * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * Author: George Cherian <george.cherian@...com>
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/extcon.h>
> +#include <linux/gpio.h>
> +#include <linux/interrupt.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_gpio.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>
> +
> +struct dra7xx_extcon {
> + struct device *dev;
> + struct extcon_dev edev;
> +
> + int id_gpio;
> + int id_irq;
> +};
> +
> +static const char *dra7xx_extcon_cable[] = {
> + [1] = "USB-HOST",
> + NULL,
> +};
> +
> +#define ID_GND 0
> +
> +static irqreturn_t id_irq_handler(int irq, void *data)
> +{
> + struct dra7xx_extcon *dra7xx_extcon = (struct dra7xx_extcon *)data;
> + int id_current;
> +
> + id_current = gpio_get_value_cansleep(dra7xx_extcon->id_gpio);
> + if (id_current == ID_GND)
> + extcon_set_cable_state(&dra7xx_extcon->edev, "USB-HOST", true);
> + else
> + extcon_set_cable_state(&dra7xx_extcon->edev, "USB-HOST", false);
> +
> + return IRQ_HANDLED;
> +}
> +
> +static void dra7xx_extcon_set_initial_state(struct dra7xx_extcon *dra7xx_extcon)
> +{
> + int id_current;
> +
> + id_current = gpio_get_value_cansleep(dra7xx_extcon->id_gpio);
> + if (id_current == ID_GND)
> + extcon_set_cable_state(&dra7xx_extcon->edev,
> + "USB-HOST", true);
> + else
> + extcon_set_cable_state(&dra7xx_extcon->edev,
> + "USB-HOST", false);
> +}
> +
> +static int dra7xx_extcon_request_irq(struct dra7xx_extcon *dra7xx_extcon)
> +{
> + int ret;
> +
> + ret = devm_request_threaded_irq(dra7xx_extcon->dev,
> + dra7xx_extcon->id_irq,
> + NULL, id_irq_handler,
> + IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
> + dev_name(dra7xx_extcon->dev),
> + (void *)dra7xx_extcon);
> + if (ret) {
> + dev_err(dra7xx_extcon->dev, "failed to request id irq #%d\n",
> + dra7xx_extcon->id_irq);
> + return ret;
> + }
> + return ret;
> +}
> +
> +static int dra7xx_extcon_probe(struct platform_device *pdev)
> +{
> + struct device_node *node = pdev->dev.of_node;
> + struct dra7xx_extcon *dra7xx_extcon;
> + int ret, gpio;
> +
> + dra7xx_extcon = devm_kzalloc(&pdev->dev, sizeof(*dra7xx_extcon),
> + GFP_KERNEL);
> + if (!dra7xx_extcon)
> + return -ENOMEM;
> +
> + dra7xx_extcon->dev = &pdev->dev;
> +
> + platform_set_drvdata(pdev, dra7xx_extcon);
> +
> + dra7xx_extcon->edev.supported_cable = dra7xx_extcon_cable;
> +
> + gpio = of_get_gpio(node, 0);
> + if (gpio_is_valid(gpio)) {
> + dra7xx_extcon->id_gpio = gpio;
> + ret = devm_gpio_request(&pdev->dev, dra7xx_extcon->id_gpio,
> + "id_gpio");
> + if (ret)
> + return ret;
> +
> + dra7xx_extcon->id_irq = gpio_to_irq(dra7xx_extcon->id_gpio);
> + } else {
> + dev_err(&pdev->dev, "failed to get id gpio\n");
> + return -EPROBE_DEFER;
> + }
> +
> + ret = dra7xx_extcon_request_irq(dra7xx_extcon);
> + if (ret)
> + return ret;
> +
> + ret = extcon_dev_register(&dra7xx_extcon->edev);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to register extcon device\n");
> + return ret;
> + }
> +
> + dra7xx_extcon_set_initial_state(dra7xx_extcon);
> +
> + return 0;
> +}
> +
> +static int dra7xx_extcon_remove(struct platform_device *pdev)
> +{
> + struct dra7xx_extcon *dra7xx_extcon = platform_get_drvdata(pdev);
> +
> + extcon_dev_unregister(&dra7xx_extcon->edev);
> + return 0;
> +}
> +
> +static struct of_device_id of_dra7xx_extcon_match_tbl[] = {
> + { .compatible = "ti,dra7xx-extcon", },
> + { /* end */ }
> +};
> +
> +static struct platform_driver dra7xx_extcon_driver = {
> + .probe = dra7xx_extcon_probe,
> + .remove = dra7xx_extcon_remove,
> + .driver = {
> + .name = "dra7xx-extcon",
> + .of_match_table = of_dra7xx_extcon_match_tbl,
> + .owner = THIS_MODULE,
> + },
> +};
> +
> +module_platform_driver(dra7xx_extcon_driver);
> +
> +MODULE_ALIAS("platform:extcon-dra7xx");
> +MODULE_AUTHOR("George Cherian <george.cherian@...com>");
> +MODULE_DESCRIPTION("USB ID pin detection driver for DRA7xx");
> +MODULE_LICENSE("GPL");
> +MODULE_DEVICE_TABLE(of, of_dra7xx_extcon_match_tbl);
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists