Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1236907 > unrolled thread

[PATCH 0/5] extcon: gpio: Clean-up code and use the gpiod_* API

Started byChanwoo Choi <cw00.choi@samsung.com>
First post2015-10-01 04:30 +0200
Last post2015-10-01 04:30 +0200
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/5] extcon: gpio: Clean-up code and use the gpiod_* API Chanwoo Choi <cw00.choi@samsung.com> - 2015-10-01 04:30 +0200
    [PATCH 4/5] extcon: gpio: Fix minor coding style and remove the unused  fields. Chanwoo Choi <cw00.choi@samsung.com> - 2015-10-01 04:30 +0200
    [PATCH 5/5] extcon: gpio: Use descriptor-based GPIO interface instead  of legacy gpio_* API Chanwoo Choi <cw00.choi@samsung.com> - 2015-10-01 04:30 +0200

#1236907 — [PATCH 0/5] extcon: gpio: Clean-up code and use the gpiod_* API

FromChanwoo Choi <cw00.choi@samsung.com>
Date2015-10-01 04:30 +0200
Subject[PATCH 0/5] extcon: gpio: Clean-up code and use the gpiod_* API
Message-ID<qeBN8-6ZF-3@gated-at.bofh.it>
This patch-set clean up the extcon-gpio driver before supporting the device
tree bindings.

Chanwoo Choi (5):
  extcon: gpio: Use resource managed function for request_irq
  extcon: gpio: Remove duplicate data from struct gpio_extcon_data
  extcon: gpio: Add the missing supported_cable parameter to devm_extcon_dev_allocate()
  extcon: gpio: Fix minor coding style and remove the unused fields.
  extcon: gpio: Use descriptor-based GPIO interface instead of legacy gpio_* API

 drivers/extcon/extcon-gpio.c       | 130 ++++++++++++++++++++-----------------
 include/linux/extcon/extcon-gpio.h |  24 ++-----
 2 files changed, 76 insertions(+), 78 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1236908 — [PATCH 4/5] extcon: gpio: Fix minor coding style and remove the unused fields.

FromChanwoo Choi <cw00.choi@samsung.com>
Date2015-10-01 04:30 +0200
Subject[PATCH 4/5] extcon: gpio: Fix minor coding style and remove the unused fields.
Message-ID<qeBN8-6ZF-11@gated-at.bofh.it>
In reply to#1236907
This patch fixes the minor coding style about indentation and removes the
unused fields from struct gpio_extcon_platform_data.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-gpio.c       | 11 ++++-------
 include/linux/extcon/extcon-gpio.h | 22 ++++------------------
 2 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index ba927df2fb91..27de6aee890f 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -1,7 +1,5 @@
 /*
- *  drivers/extcon/extcon_gpio.c
- *
- *  Single-state GPIO extcon driver based on extcon class
+ * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
  *
  * Copyright (C) 2008 Google, Inc.
  * Author: Mike Lockwood <lockwood@android.com>
@@ -17,8 +15,7 @@
  * 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/extcon.h>
 #include <linux/extcon/extcon-gpio.h>
@@ -37,7 +34,7 @@ struct gpio_extcon_data {
 	struct delayed_work work;
 	unsigned long debounce_jiffies;
 
-	struct gpio_extcon_platform_data *pdata;
+	struct gpio_extcon_pdata *pdata;
 };
 
 static void gpio_extcon_work(struct work_struct *work)
@@ -64,7 +61,7 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
-	struct gpio_extcon_platform_data *pdata = dev_get_platdata(&pdev->dev);
+	struct gpio_extcon_pdata *pdata = dev_get_platdata(&pdev->dev);
 	struct gpio_extcon_data *data;
 	int ret;
 
diff --git a/include/linux/extcon/extcon-gpio.h b/include/linux/extcon/extcon-gpio.h
index 232bb8f80b51..7cacafb78b09 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/extcon-gpio.h
@@ -1,5 +1,5 @@
 /*
- *  External connector (extcon) class generic GPIO driver
+ * Single-state GPIO extcon driver based on extcon class
  *
  * Copyright (C) 2012 Samsung Electronics
  * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
@@ -16,16 +16,14 @@
  * 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.
- *
-*/
+ */
 #ifndef __EXTCON_GPIO_H__
 #define __EXTCON_GPIO_H__ __FILE__
 
 #include <linux/extcon.h>
 
 /**
- * struct gpio_extcon_platform_data - A simple GPIO-controlled extcon device.
- * @name:		The name of this GPIO extcon device.
+ * struct gpio_extcon_pdata - A simple GPIO-controlled extcon device.
  * @extcon_id:		The unique id of specific external connector.
  * @gpio:		Corresponding GPIO.
  * @gpio_active_low:	Boolean describing whether gpio active state is 1 or 0
@@ -33,28 +31,16 @@
  *			If false, high state of gpio means active.
  * @debounce:		Debounce time for GPIO IRQ in ms.
  * @irq_flags:		IRQ Flags (e.g., IRQF_TRIGGER_LOW).
- * @state_on:		print_state is overriden with state_on if attached.
- *			If NULL, default method of extcon class is used.
- * @state_off:		print_state is overriden with state_off if detached.
- *			If NUll, default method of extcon class is used.
  * @check_on_resume:	Boolean describing whether to check the state of gpio
  *			while resuming from sleep.
- *
- * Note that in order for state_on or state_off to be valid, both state_on
- * and state_off should be not NULL. If at least one of them is NULL,
- * the print_state is not overriden.
  */
-struct gpio_extcon_platform_data {
-	const char *name;
+struct gpio_extcon_pdata {
 	unsigned int extcon_id;
 	unsigned gpio;
 	bool gpio_active_low;
 	unsigned long debounce;
 	unsigned long irq_flags;
 
-	/* if NULL, "0" or "1" will be printed */
-	const char *state_on;
-	const char *state_off;
 	bool check_on_resume;
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1236909 — [PATCH 5/5] extcon: gpio: Use descriptor-based GPIO interface instead of legacy gpio_* API

FromChanwoo Choi <cw00.choi@samsung.com>
Date2015-10-01 04:30 +0200
Subject[PATCH 5/5] extcon: gpio: Use descriptor-based GPIO interface instead of legacy gpio_* API
Message-ID<qeBN8-6ZF-13@gated-at.bofh.it>
In reply to#1236907
This patch uses the descriptor-based GPIO interface (gpiod_* API) instead of
legacy gpio_* API and add the internal gpio_extcon_init() to handle
all gpio-related tasks.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-gpio.c | 62 ++++++++++++++++++++++++++++++--------------
 1 file changed, 43 insertions(+), 19 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 27de6aee890f..279ff8f6637d 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -20,6 +20,7 @@
 #include <linux/extcon.h>
 #include <linux/extcon/extcon-gpio.h>
 #include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
@@ -34,6 +35,7 @@ struct gpio_extcon_data {
 	struct delayed_work work;
 	unsigned long debounce_jiffies;
 
+	struct gpio_desc *id_gpiod;
 	struct gpio_extcon_pdata *pdata;
 };
 
@@ -44,7 +46,7 @@ static void gpio_extcon_work(struct work_struct *work)
 		container_of(to_delayed_work(work), struct gpio_extcon_data,
 			     work);
 
-	state = gpio_get_value(data->pdata->gpio);
+	state = gpiod_get_value_cansleep(data->id_gpiod);
 	if (data->pdata->gpio_active_low)
 		state = !state;
 	extcon_set_state(data->edev, state);
@@ -59,6 +61,35 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data)
+{
+	struct gpio_extcon_pdata *pdata = data->pdata;
+	int ret;
+
+	ret = devm_gpio_request_one(dev, pdata->gpio, GPIOF_DIR_IN,
+				dev_name(dev));
+	if (ret < 0)
+		return ret;
+
+	data->id_gpiod = gpio_to_desc(pdata->gpio);
+	if (!data->id_gpiod)
+		return -EINVAL;
+
+	if (pdata->debounce) {
+		ret = gpiod_set_debounce(data->id_gpiod,
+					pdata->debounce * 1000);
+		if (ret < 0)
+			data->debounce_jiffies =
+				msecs_to_jiffies(pdata->debounce);
+	}
+
+	data->irq = gpiod_to_irq(data->id_gpiod);
+	if (data->irq < 0)
+		return data->irq;
+
+	return 0;
+}
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
 	struct gpio_extcon_pdata *pdata = dev_get_platdata(&pdev->dev);
@@ -74,25 +105,18 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 				   GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
-
-	data->edev = devm_extcon_dev_allocate(&pdev->dev, &pdata->extcon_id);
-	if (IS_ERR(data->edev)) {
-		dev_err(&pdev->dev, "failed to allocate extcon device\n");
-		return -ENOMEM;
-	}
 	data->pdata = pdata;
 
-	ret = devm_gpio_request_one(&pdev->dev, data->pdata->gpio, GPIOF_DIR_IN,
-				    pdev->name);
+	/* Initialize the gpio */
+	ret = gpio_extcon_init(&pdev->dev, data);
 	if (ret < 0)
 		return ret;
 
-	if (pdata->debounce) {
-		ret = gpio_set_debounce(data->pdata->gpio,
-					pdata->debounce * 1000);
-		if (ret < 0)
-			data->debounce_jiffies =
-				msecs_to_jiffies(pdata->debounce);
+	/* Allocate the memory of extcon devie and register extcon device */
+	data->edev = devm_extcon_dev_allocate(&pdev->dev, &pdata->extcon_id);
+	if (IS_ERR(data->edev)) {
+		dev_err(&pdev->dev, "failed to allocate extcon device\n");
+		return -ENOMEM;
 	}
 
 	ret = devm_extcon_dev_register(&pdev->dev, data->edev);
@@ -101,10 +125,10 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 
 	INIT_DELAYED_WORK(&data->work, gpio_extcon_work);
 
-	data->irq = gpio_to_irq(data->pdata->gpio);
-	if (data->irq < 0)
-		return data->irq;
-
+	/*
+	 * Request the interrput of gpio to detect whether external connector
+	 * is attached or detached.
+	 */
 	ret = devm_request_any_context_irq(&pdev->dev, data->irq,
 					gpio_irq_handler, pdata->irq_flags,
 					pdev->name, data);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web