[{"id":1775092,"web_url":"http://patchwork.ozlabs.org/comment/1775092/","msgid":"<59C9B8D9.6050203@samsung.com>","list_archive_url":null,"date":"2017-09-26T02:18:01","subject":"Re: [PATCH 4/8] extcon: gpio: Convert to fully use GPIO descriptor","submitter":{"id":46832,"url":"http://patchwork.ozlabs.org/api/people/46832/","name":"Chanwoo Choi","email":"cw00.choi@samsung.com"},"content":"Hi Linus,\n\nLooks good to me. But, there is one comment\nof gpiod_to_irq()'s return value.\n\nIf you modify it, feel free to add my tag:\nAcked-by: Chanwoo Choi <cw00.choi@samsung.com>\n\nOn 2017년 09월 24일 23:56, Linus Walleij wrote:\n> Since we are not getting the GPIO from any platform data and global\n> GPIO numberspace, we simply get the named \"extcon\" GPIO directly from\n> the device. Cut away \"active low\" since GPIO descriptors already know\n> if the line is active high or low. Simplify a bit with a\n> struct device *dev helper variable in probe() and cut the complex\n> init() function.\n> \n> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>\n> ---\n>  drivers/extcon/extcon-gpio.c | 66 ++++++++++----------------------------------\n>  1 file changed, 15 insertions(+), 51 deletions(-)\n> \n> diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c\n> index 9c4094edd123..86f3ec6d6014 100644\n> --- a/drivers/extcon/extcon-gpio.c\n> +++ b/drivers/extcon/extcon-gpio.c\n> @@ -18,7 +18,6 @@\n>   */\n>  \n>  #include <linux/extcon.h>\n> -#include <linux/gpio.h>\n>  #include <linux/gpio/consumer.h>\n>  #include <linux/init.h>\n>  #include <linux/interrupt.h>\n> @@ -35,12 +34,8 @@\n>   * @work:\t\tWork fired by the interrupt.\n>   * @debounce_jiffies:\tNumber of jiffies to wait for the GPIO to stabilize, from the debounce\n>   *\t\t\tvalue.\n> - * @id_gpiod:\t\tGPIO descriptor for this external connector.\n> + * @gpiod:\t\tGPIO descriptor for this external connector.\n>   * @extcon_id:\t\tThe unique id of specific external connector.\n> - * @gpio:\t\tCorresponding GPIO.\n> - * @gpio_active_low:\tBoolean describing whether gpio active state is 1 or 0\n> - *\t\t\tIf true, low state of gpio means active.\n> - *\t\t\tIf false, high state of gpio means active.\n>   * @debounce:\t\tDebounce time for GPIO IRQ in ms.\n>   * @irq_flags:\t\tIRQ Flags (e.g., IRQF_TRIGGER_LOW).\n>   * @check_on_resume:\tBoolean describing whether to check the state of gpio\n> @@ -51,10 +46,8 @@ struct gpio_extcon_data {\n>  \tint irq;\n>  \tstruct delayed_work work;\n>  \tunsigned long debounce_jiffies;\n> -\tstruct gpio_desc *id_gpiod;\n> +\tstruct gpio_desc *gpiod;\n>  \tunsigned int extcon_id;\n> -\tunsigned gpio;\n> -\tbool gpio_active_low;\n>  \tunsigned long debounce;\n>  \tunsigned long irq_flags;\n>  \tbool check_on_resume;\n> @@ -67,10 +60,7 @@ static void gpio_extcon_work(struct work_struct *work)\n>  \t\tcontainer_of(to_delayed_work(work), struct gpio_extcon_data,\n>  \t\t\t     work);\n>  \n> -\tstate = gpiod_get_value_cansleep(data->id_gpiod);\n> -\tif (data->gpio_active_low)\n> -\t\tstate = !state;\n> -\n> +\tstate = gpiod_get_value_cansleep(data->gpiod);\n>  \textcon_set_state_sync(data->edev, data->extcon_id, state);\n>  }\n>  \n> @@ -83,60 +73,34 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)\n>  \treturn IRQ_HANDLED;\n>  }\n>  \n> -static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data)\n> -{\n> -\tint ret;\n> -\n> -\tret = devm_gpio_request_one(dev, data->gpio, GPIOF_DIR_IN,\n> -\t\t\t\tdev_name(dev));\n> -\tif (ret < 0)\n> -\t\treturn ret;\n> -\n> -\tdata->id_gpiod = gpio_to_desc(data->gpio);\n> -\tif (!data->id_gpiod)\n> -\t\treturn -EINVAL;\n> -\n> -\tif (data->debounce) {\n> -\t\tret = gpiod_set_debounce(data->id_gpiod,\n> -\t\t\t\t\t data->debounce * 1000);\n> -\t\tif (ret < 0)\n> -\t\t\tdata->debounce_jiffies =\n> -\t\t\t\tmsecs_to_jiffies(data->debounce);\n> -\t}\n> -\n> -\tdata->irq = gpiod_to_irq(data->id_gpiod);\n> -\tif (data->irq < 0)\n> -\t\treturn data->irq;\n> -\n> -\treturn 0;\n> -}\n> -\n>  static int gpio_extcon_probe(struct platform_device *pdev)\n>  {\n>  \tstruct gpio_extcon_data *data;\n> +\tstruct device *dev = &pdev->dev;\n>  \tint ret;\n>  \n> -\tdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data),\n> -\t\t\t\t   GFP_KERNEL);\n> +\tdata = devm_kzalloc(dev, sizeof(struct gpio_extcon_data), GFP_KERNEL);\n>  \tif (!data)\n>  \t\treturn -ENOMEM;\n>  \n>  \tif (!data->irq_flags || data->extcon_id > EXTCON_NONE)\n>  \t\treturn -EINVAL;\n>  \n> -\t/* Initialize the gpio */\n> -\tret = gpio_extcon_init(&pdev->dev, data);\n> -\tif (ret < 0)\n> -\t\treturn ret;\n> +\tdata->gpiod = devm_gpiod_get(dev, \"extcon\", GPIOD_IN);\n> +\tif (IS_ERR(data->gpiod))\n> +\t\treturn PTR_ERR(data->gpiod);\n> +\tdata->irq = gpiod_to_irq(data->gpiod);\n> +\tif (data->irq <= 0)\n\n\"if (data->irq < 0)\" is enough. If irq is zero, gpiod_to_irq()\nreturns the -ENXIO.\n\n> +\t\treturn data->irq;\n>  \n>  \t/* Allocate the memory of extcon devie and register extcon device */\n> -\tdata->edev = devm_extcon_dev_allocate(&pdev->dev, &data->extcon_id);\n> +\tdata->edev = devm_extcon_dev_allocate(dev, &data->extcon_id);\n>  \tif (IS_ERR(data->edev)) {\n> -\t\tdev_err(&pdev->dev, \"failed to allocate extcon device\\n\");\n> +\t\tdev_err(dev, \"failed to allocate extcon device\\n\");\n>  \t\treturn -ENOMEM;\n>  \t}\n>  \n> -\tret = devm_extcon_dev_register(&pdev->dev, data->edev);\n> +\tret = devm_extcon_dev_register(dev, data->edev);\n>  \tif (ret < 0)\n>  \t\treturn ret;\n>  \n> @@ -146,7 +110,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)\n>  \t * Request the interrupt of gpio to detect whether external connector\n>  \t * is attached or detached.\n>  \t */\n> -\tret = devm_request_any_context_irq(&pdev->dev, data->irq,\n> +\tret = devm_request_any_context_irq(dev, data->irq,\n>  \t\t\t\t\tgpio_irq_handler, data->irq_flags,\n>  \t\t\t\t\tpdev->name, data);\n>  \tif (ret < 0)\n>","headers":{"Return-Path":"<linux-gpio-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-gpio-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y1PkR5YQLz9t3F\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 12:18:07 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S936111AbdIZCSG (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tMon, 25 Sep 2017 22:18:06 -0400","from mailout4.samsung.com ([203.254.224.34]:61760 \"EHLO\n\tmailout4.samsung.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S934681AbdIZCSE (ORCPT\n\t<rfc822; linux-gpio@vger.kernel.org>); Mon, 25 Sep 2017 22:18:04 -0400","from epcas1p1.samsung.com (unknown [182.195.41.45])\n\tby mailout4.samsung.com (KnoxPortal) with ESMTP id\n\t20170926021800epoutp041f3620f262c04f569db6f70640625bc5~nx8xhMSsU2912429124epoutp04f;\n\tTue, 26 Sep 2017 02:18:00 +0000 (GMT)","from epsmges1p1.samsung.com (unknown [182.195.40.67]) by\n\tepcas1p3.samsung.com (KnoxPortal) with ESMTP id\n\t20170926021800epcas1p3fce10db2c86716c6608f02079e8e0080~nx8xMcfPp1564815648epcas1p3w;\n\tTue, 26 Sep 2017 02:18:00 +0000 (GMT)","from epcas1p4.samsung.com ( [182.195.41.48]) by\n\tepsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id\n\t0D.84.04439.8D8B9C95; Tue, 26 Sep 2017 11:18:00 +0900 (KST)","from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by\n\tepcas1p4.samsung.com (KnoxPortal) with ESMTP id\n\t20170926021800epcas1p48fcab9a034e7eea797476b2e1fdd4b6e~nx8xA7mzh1519315193epcas1p4r;\n\tTue, 26 Sep 2017 02:18:00 +0000 (GMT)","from epmmp2 ( [203.254.227.17]) by epsmgms2p1new.samsung.com\n\t(Symantec Messaging Gateway) with SMTP id 08.85.06995.8D8B9C95;\n\tTue, 26 Sep 2017 11:18:00 +0900 (KST)","from [10.113.62.212] by mmp2.samsung.com (Oracle Communications\n\tMessaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id\n\t<0OWV0060J7Q0DA40@mmp2.samsung.com>;\n\tTue, 26 Sep 2017 11:18:00 +0900 (KST)"],"X-AuditID":"b6c32a35-d60af9c000001157-08-59c9b8d81a45","MIME-version":"1.0","Content-transfer-encoding":"8BIT","Content-type":"text/plain; charset=\"UTF-8\"","Message-id":"<59C9B8D9.6050203@samsung.com>","Date":"Tue, 26 Sep 2017 11:18:01 +0900","From":"Chanwoo Choi <cw00.choi@samsung.com>","Organization":"Samsung Electronics","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101\n\tThunderbird/31.6.0","To":"Linus Walleij <linus.walleij@linaro.org>,\n\tMyungJoo Ham <myungjoo.ham@samsung.com>","Cc":"linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,\n\tJohn Stultz <john.stultz@linaro.org>, Guenter Roeck <linux@roeck-us.net>","Subject":"Re: [PATCH 4/8] extcon: gpio: Convert to fully use GP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XRmb3JtIExhYihTL1c=?=\n\t=?utf-8?b?7IS87YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?=","X-Global-Sender":"=?utf-8?q?Chanwoo_Choi=1BTizen_Platform_Lab=2E=1BSamsung?=\n\t=?utf-8?q?_Electronics=1BSenior_Engineer?=","X-Sender-Code":"=?utf-8?q?C10=1BTELE=1BC10V8111?=","CMS-TYPE":"101P","DLP-Filter":"Pass","X-CFilter-Loop":"Reflected","X-CMS-RootMailID":"20170924150004epcas4p3217d627df09c3292114f93ec0a66e3b4","X-RootMTR":"20170924150004epcas4p3217d627df09c3292114f93ec0a66e3b4","References":"<20170924145622.4031-1-linus.walleij@linaro.org>\n\t<CGME20170924150004epcas4p3217d627df09c3292114f93ec0a66e3b4@epcas4p3.samsung.com>\n\t<20170924145622.4031-5-linus.walleij@linaro.org>","Sender":"linux-gpio-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-gpio.vger.kernel.org>","X-Mailing-List":"linux-gpio@vger.kernel.org"}}]