{"id":817921,"url":"http://patchwork.ozlabs.org/api/patches/817921/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20170924145622.4031-5-linus.walleij@linaro.org/","project":{"id":42,"url":"http://patchwork.ozlabs.org/api/projects/42/?format=json","name":"Linux GPIO development","link_name":"linux-gpio","list_id":"linux-gpio.vger.kernel.org","list_email":"linux-gpio@vger.kernel.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170924145622.4031-5-linus.walleij@linaro.org>","list_archive_url":null,"date":"2017-09-24T14:56:18","name":"[4/8] extcon: gpio: Convert to fully use GPIO descriptor","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"e1b749a95133cf553d5795072330a76028761317","submitter":{"id":7055,"url":"http://patchwork.ozlabs.org/api/people/7055/?format=json","name":"Linus Walleij","email":"linus.walleij@linaro.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-gpio/patch/20170924145622.4031-5-linus.walleij@linaro.org/mbox/","series":[{"id":4818,"url":"http://patchwork.ozlabs.org/api/series/4818/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-gpio/list/?series=4818","date":"2017-09-24T14:56:14","name":"GPIO extcon modernization","version":1,"mbox":"http://patchwork.ozlabs.org/series/4818/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/817921/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/817921/checks/","tags":{},"related":[],"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>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"h6CObgrT\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0Vkr1VCNz9sRV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 25 Sep 2017 01:00:20 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752594AbdIXPAD (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tSun, 24 Sep 2017 11:00:03 -0400","from mail-pf0-f169.google.com ([209.85.192.169]:49369 \"EHLO\n\tmail-pf0-f169.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752475AbdIXPAC (ORCPT\n\t<rfc822; linux-gpio@vger.kernel.org>); Sun, 24 Sep 2017 11:00:02 -0400","by mail-pf0-f169.google.com with SMTP id l188so2608653pfc.6\n\tfor <linux-gpio@vger.kernel.org>;\n\tSun, 24 Sep 2017 08:00:02 -0700 (PDT)","from genomnajs.saswifi.com ([104.153.224.168])\n\tby smtp.gmail.com with ESMTPSA id\n\tn83sm7386805pfi.163.2017.09.24.07.59.24\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 24 Sep 2017 08:00:01 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=9EoT4D03TXTHT89pkomvmDIwfs/ypqXeVk5hZO8RL1E=;\n\tb=h6CObgrTcPZkdCAZ/ct51BJ9g/Sc+SyyI8QsgYXVjwweu63cKkYzoFIiCwZatHg/w/\n\tx/1PrysEf5xwZ/wmfqjFGMgWXDEJsCr71VsL/xzA+to2DX7HG+ekmaWEOzXIoxTPVdTy\n\tHOV8l0jbFIDCGrwZBT6WazKpQTGFafpQPS1gc=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=9EoT4D03TXTHT89pkomvmDIwfs/ypqXeVk5hZO8RL1E=;\n\tb=pNzPu/js6HRnZ7qyBPBjSJMKfn+79mN7g50R0MZ9RRbqWrj6FkHCr7Bsq9AV8iGbLO\n\tDkSIN2oHBi3MEjuposxL2A8iWEkSBFWSbg891/HBF4U1T9uktPhGjt6GH9hxWlV0XgCB\n\tmKowHw9mEBi+avzivkzcxPEP26qspq8WaX50B1NpdNvgTk7jhSA+kbPZNbJ0CY0HMRhN\n\tOO1I3gJ0T3CWXXIRU2qb+zz6CFLCgbSw0kgqDXuKLZNKzgRMF6nFnGNVuZ2/Vwr4f5jo\n\tRIL79R3Kr8GYlZUciOGy+15GpBC0i7iuB0yjm0iQ8RcGhubjr+yZbbPZK7y0sldJxhJc\n\tMcRA==","X-Gm-Message-State":"AHPjjUgH3VdALWui+qCd/KqBBSPdOYJ0FEP+feHJknMXYD+TPfAB9+wm\n\t7tXfjp4tvQmmDX3J8tCqipzkSg==","X-Google-Smtp-Source":"AOwi7QDThN7DPSh4jq4dQGnzZXDT+pqUvSJe3tfRlstyuqnHgE+2JRdLz+w3VG71kPXvU+jlLuiBcQ==","X-Received":"by 10.84.212.2 with SMTP id d2mr4876051pli.412.1506265201913;\n\tSun, 24 Sep 2017 08:00:01 -0700 (PDT)","From":"Linus Walleij <linus.walleij@linaro.org>","To":"MyungJoo Ham <myungjoo.ham@samsung.com>,\n\tChanwoo Choi <cw00.choi@samsung.com>","Cc":"linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,\n\tJohn Stultz <john.stultz@linaro.org>,\n\tMike Lockwood <lockwood@google.com>, Guenter Roeck <linux@roeck-us.net>,\n\tLinus Walleij <linus.walleij@linaro.org>","Subject":"[PATCH 4/8] extcon: gpio: Convert to fully use GPIO descriptor","Date":"Sun, 24 Sep 2017 16:56:18 +0200","Message-Id":"<20170924145622.4031-5-linus.walleij@linaro.org>","X-Mailer":"git-send-email 2.13.5","In-Reply-To":"<20170924145622.4031-1-linus.walleij@linaro.org>","References":"<20170924145622.4031-1-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"},"content":"Since we are not getting the GPIO from any platform data and global\nGPIO numberspace, we simply get the named \"extcon\" GPIO directly from\nthe device. Cut away \"active low\" since GPIO descriptors already know\nif the line is active high or low. Simplify a bit with a\nstruct device *dev helper variable in probe() and cut the complex\ninit() function.\n\nSigned-off-by: Linus Walleij <linus.walleij@linaro.org>\n---\n drivers/extcon/extcon-gpio.c | 66 ++++++++++----------------------------------\n 1 file changed, 15 insertions(+), 51 deletions(-)","diff":"diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c\nindex 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+\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","prefixes":["4/8"]}