From: Chanwoo Choi <cw00.choi@samsung.com>
To: Linus Walleij <linus.walleij@linaro.org>,
MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
John Stultz <john.stultz@linaro.org>,
Guenter Roeck <linux@roeck-us.net>
Subject: Re: [PATCH 4/8] extcon: gpio: Convert to fully use GPIO descriptor
Date: Tue, 26 Sep 2017 11:18:01 +0900 [thread overview]
Message-ID: <59C9B8D9.6050203@samsung.com> (raw)
In-Reply-To: <20170924145622.4031-5-linus.walleij@linaro.org>
Hi Linus,
Looks good to me. But, there is one comment
of gpiod_to_irq()'s return value.
If you modify it, feel free to add my tag:
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>
On 2017년 09월 24일 23:56, Linus Walleij wrote:
> Since we are not getting the GPIO from any platform data and global
> GPIO numberspace, we simply get the named "extcon" GPIO directly from
> the device. Cut away "active low" since GPIO descriptors already know
> if the line is active high or low. Simplify a bit with a
> struct device *dev helper variable in probe() and cut the complex
> init() function.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> drivers/extcon/extcon-gpio.c | 66 ++++++++++----------------------------------
> 1 file changed, 15 insertions(+), 51 deletions(-)
>
> diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
> index 9c4094edd123..86f3ec6d6014 100644
> --- a/drivers/extcon/extcon-gpio.c
> +++ b/drivers/extcon/extcon-gpio.c
> @@ -18,7 +18,6 @@
> */
>
> #include <linux/extcon.h>
> -#include <linux/gpio.h>
> #include <linux/gpio/consumer.h>
> #include <linux/init.h>
> #include <linux/interrupt.h>
> @@ -35,12 +34,8 @@
> * @work: Work fired by the interrupt.
> * @debounce_jiffies: Number of jiffies to wait for the GPIO to stabilize, from the debounce
> * value.
> - * @id_gpiod: GPIO descriptor for this external connector.
> + * @gpiod: GPIO descriptor for this external connector.
> * @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
> - * If true, low state of gpio means active.
> - * 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).
> * @check_on_resume: Boolean describing whether to check the state of gpio
> @@ -51,10 +46,8 @@ struct gpio_extcon_data {
> int irq;
> struct delayed_work work;
> unsigned long debounce_jiffies;
> - struct gpio_desc *id_gpiod;
> + struct gpio_desc *gpiod;
> unsigned int extcon_id;
> - unsigned gpio;
> - bool gpio_active_low;
> unsigned long debounce;
> unsigned long irq_flags;
> bool check_on_resume;
> @@ -67,10 +60,7 @@ static void gpio_extcon_work(struct work_struct *work)
> container_of(to_delayed_work(work), struct gpio_extcon_data,
> work);
>
> - state = gpiod_get_value_cansleep(data->id_gpiod);
> - if (data->gpio_active_low)
> - state = !state;
> -
> + state = gpiod_get_value_cansleep(data->gpiod);
> extcon_set_state_sync(data->edev, data->extcon_id, state);
> }
>
> @@ -83,60 +73,34 @@ 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)
> -{
> - int ret;
> -
> - ret = devm_gpio_request_one(dev, data->gpio, GPIOF_DIR_IN,
> - dev_name(dev));
> - if (ret < 0)
> - return ret;
> -
> - data->id_gpiod = gpio_to_desc(data->gpio);
> - if (!data->id_gpiod)
> - return -EINVAL;
> -
> - if (data->debounce) {
> - ret = gpiod_set_debounce(data->id_gpiod,
> - data->debounce * 1000);
> - if (ret < 0)
> - data->debounce_jiffies =
> - msecs_to_jiffies(data->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_data *data;
> + struct device *dev = &pdev->dev;
> int ret;
>
> - data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data),
> - GFP_KERNEL);
> + data = devm_kzalloc(dev, sizeof(struct gpio_extcon_data), GFP_KERNEL);
> if (!data)
> return -ENOMEM;
>
> if (!data->irq_flags || data->extcon_id > EXTCON_NONE)
> return -EINVAL;
>
> - /* Initialize the gpio */
> - ret = gpio_extcon_init(&pdev->dev, data);
> - if (ret < 0)
> - return ret;
> + data->gpiod = devm_gpiod_get(dev, "extcon", GPIOD_IN);
> + if (IS_ERR(data->gpiod))
> + return PTR_ERR(data->gpiod);
> + data->irq = gpiod_to_irq(data->gpiod);
> + if (data->irq <= 0)
"if (data->irq < 0)" is enough. If irq is zero, gpiod_to_irq()
returns the -ENXIO.
> + return data->irq;
>
> /* Allocate the memory of extcon devie and register extcon device */
> - data->edev = devm_extcon_dev_allocate(&pdev->dev, &data->extcon_id);
> + data->edev = devm_extcon_dev_allocate(dev, &data->extcon_id);
> if (IS_ERR(data->edev)) {
> - dev_err(&pdev->dev, "failed to allocate extcon device\n");
> + dev_err(dev, "failed to allocate extcon device\n");
> return -ENOMEM;
> }
>
> - ret = devm_extcon_dev_register(&pdev->dev, data->edev);
> + ret = devm_extcon_dev_register(dev, data->edev);
> if (ret < 0)
> return ret;
>
> @@ -146,7 +110,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
> * Request the interrupt of gpio to detect whether external connector
> * is attached or detached.
> */
> - ret = devm_request_any_context_irq(&pdev->dev, data->irq,
> + ret = devm_request_any_context_irq(dev, data->irq,
> gpio_irq_handler, data->irq_flags,
> pdev->name, data);
> if (ret < 0)
>
--
Best Regards,
Chanwoo Choi
Samsung Electronics
next prev parent reply other threads:[~2017-09-26 2:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-24 14:56 [PATCH 0/8] GPIO extcon modernization Linus Walleij
2017-09-24 14:56 ` [PATCH 1/8] extcon: gpio: Add DT bindings Linus Walleij
2017-09-24 19:56 ` Rob Herring
2017-09-26 0:39 ` Linus Walleij
2017-09-26 2:02 ` Chanwoo Choi
2017-10-19 10:47 ` Chanwoo Choi
2017-09-24 14:56 ` [PATCH 2/8] extcon: gpio: Localize platform data Linus Walleij
2017-09-26 2:04 ` Chanwoo Choi
2017-09-24 14:56 ` [PATCH 3/8] extcon: gpio: Move platform data into state container Linus Walleij
2017-09-26 2:04 ` Chanwoo Choi
2017-09-24 14:56 ` [PATCH 4/8] extcon: gpio: Convert to fully use GPIO descriptor Linus Walleij
2017-09-26 2:18 ` Chanwoo Choi [this message]
2017-09-24 14:56 ` [PATCH 5/8] extcon: gpio: Request reasonable interrupts Linus Walleij
2017-09-26 2:19 ` Chanwoo Choi
2017-09-24 14:56 ` [PATCH 6/8] extcon: gpio: Get debounce setting from device property Linus Walleij
2017-09-26 2:23 ` Chanwoo Choi
2017-09-24 14:56 ` [PATCH 7/8] extcon: gpio: Get connector type " Linus Walleij
2017-09-24 14:56 ` [PATCH 8/8] extcon: gpio: Always check state on resume Linus Walleij
2017-09-26 2:25 ` Chanwoo Choi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=59C9B8D9.6050203@samsung.com \
--to=cw00.choi@samsung.com \
--cc=john.stultz@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=myungjoo.ham@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox