2014-06-16 02:45:24

by George Cherian

[permalink] [raw]
Subject: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx

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 <[email protected]>
---
.../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 <[email protected]>
+ *
+ * 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 <[email protected]>");
+MODULE_DESCRIPTION("USB ID pin detection driver for DRA7xx");
+MODULE_LICENSE("GPL");
+MODULE_DEVICE_TABLE(of, of_dra7xx_extcon_match_tbl);
--
1.8.3.1


2014-06-16 04:59:25

by Guenter Roeck

[permalink] [raw]
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 <[email protected]>

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 <[email protected]>
> + *
> + * 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 <[email protected]>");
> +MODULE_DESCRIPTION("USB ID pin detection driver for DRA7xx");
> +MODULE_LICENSE("GPL");
> +MODULE_DEVICE_TABLE(of, of_dra7xx_extcon_match_tbl);
>

2014-06-16 05:42:37

by George Cherian

[permalink] [raw]
Subject: Re: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx

On 6/16/2014 10:29 AM, Guenter Roeck wrote:
> 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 <[email protected]>
>
> Hi George,
>
> Curious: Why can't you use extcon-gpio ?
Main reason being missing dt support.
>
> Also, I thought that Linux specific bindings would be unacceptable.
> "ti,dra7xx-extcon" looks very linux specific to me. Did the rules
> change ?
>
Then how about "ti,extcon-usbid" ?
> 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 <[email protected]>
>> + *
>> + * 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 <[email protected]>");
>> +MODULE_DESCRIPTION("USB ID pin detection driver for DRA7xx");
>> +MODULE_LICENSE("GPL");
>> +MODULE_DEVICE_TABLE(of, of_dra7xx_extcon_match_tbl);
>>
>


--
-George

2014-06-16 05:48:39

by Chanwoo Choi

[permalink] [raw]
Subject: Re: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx

Hi George,

On 06/16/2014 02:41 PM, George Cherian wrote:
> On 6/16/2014 10:29 AM, Guenter Roeck wrote:
>> 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 <[email protected]>
>>
>> Hi George,
>>
>> Curious: Why can't you use extcon-gpio ?
> Main reason being missing dt support.

I'd like you to use extcon-gpio for DRA7xx driver.
This patch has just one gpio control to wheter USB-HOST is attached or detached.

Thanks,
Chanwoo Choi

2014-06-16 14:16:00

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx

On 06/15/2014 10:41 PM, George Cherian wrote:
> On 6/16/2014 10:29 AM, Guenter Roeck wrote:
>> 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 <[email protected]>
>>
>> Hi George,
>>
>> Curious: Why can't you use extcon-gpio ?
> Main reason being missing dt support.

Then why not add dt support to it ?

>>
>> Also, I thought that Linux specific bindings would be unacceptable.
>> "ti,dra7xx-extcon" looks very linux specific to me. Did the rules change ?
>>
> Then how about "ti,extcon-usbid" ?

"extcon" seems very linux specific to me.

Anyway, not arguing, just asking, since I wondered. If the extcon maintainer
and the dt folks are happy with your driver, so am I.

Guenter

2014-06-17 12:27:02

by George Cherian

[permalink] [raw]
Subject: Re: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx

On 6/16/2014 11:18 AM, Chanwoo Choi wrote:
> Hi George,
>
> On 06/16/2014 02:41 PM, George Cherian wrote:
>> On 6/16/2014 10:29 AM, Guenter Roeck wrote:
>>> 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 <[email protected]>
>>> Hi George,
>>>
>>> Curious: Why can't you use extcon-gpio ?
>> Main reason being missing dt support.
> I'd like you to use extcon-gpio for DRA7xx driver.
> This patch has just one gpio control to wheter USB-HOST is attached or detached.
Okay I will do that.

>
> Thanks,
> Chanwoo Choi
>


--
-George

2014-06-17 12:29:31

by George Cherian

[permalink] [raw]
Subject: Re: [PATCH] extcon: extcon-dra7xx: Add Extcon driver for DRA7xx

On 6/16/2014 7:45 PM, Guenter Roeck wrote:
> On 06/15/2014 10:41 PM, George Cherian wrote:
>> On 6/16/2014 10:29 AM, Guenter Roeck wrote:
>>> 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 <[email protected]>
>>>
>>> Hi George,
>>>
>>> Curious: Why can't you use extcon-gpio ?
>> Main reason being missing dt support.
>
> Then why not add dt support to it ?
Yes, I did sent a patch for the same.
http://marc.info/?l=linux-kernel&m=140297766828100&w=2
http://marc.info/?l=linux-kernel&m=140297771028124&w=2
http://marc.info/?l=linux-kernel&m=140297768828109&w=2
>
>>>
>>> Also, I thought that Linux specific bindings would be unacceptable.
>>> "ti,dra7xx-extcon" looks very linux specific to me. Did the rules
>>> change ?
>>>
>> Then how about "ti,extcon-usbid" ?
>
> "extcon" seems very linux specific to me.
>
> Anyway, not arguing, just asking, since I wondered. If the extcon
> maintainer
> and the dt folks are happy with your driver, so am I.
>
> Guenter
>


--
-George