From patchwork Mon Feb 12 08:53:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 871923 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Q5Qahqpv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zfzwg4l4Cz9sNw for ; Mon, 12 Feb 2018 19:53:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933196AbeBLIxa (ORCPT ); Mon, 12 Feb 2018 03:53:30 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:38919 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933174AbeBLIxY (ORCPT ); Mon, 12 Feb 2018 03:53:24 -0500 Received: by mail-lf0-f65.google.com with SMTP id h78so12201586lfg.6 for ; Mon, 12 Feb 2018 00:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SrThppyoR5yvdc+QSoNVD0b61E4l4nWzJ+WH3IuT1u0=; b=Q5QahqpvAIGvA87hygpPNpMmVJL9qIpJdmFWkEco+8uvPfw7zSAYfDMfSkVbzxxpY2 R+bqZzzs6JRwn+bI/dQDUuB4NRkA+gXgB5Kh8LiIkVwUMkssR8EUeuLr4C+LU6Re8qQV 5+DwB1zXMAkgbZ7pHj42IGIcK2kDCTGX8pyiU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SrThppyoR5yvdc+QSoNVD0b61E4l4nWzJ+WH3IuT1u0=; b=IJ4ukAuWuzLR3MIXCeHXSvXnp2YFcLCHPW3uyjQXgdtl8qjRyeFrSm20mL/9NtzWhA JS4cu/2I+WUbZRTpSAYLgUjaOOhYfkTQ76ofANDmicedNfIf4ArmF50sD9JJB/DFk+0c BCnlxyZqoxWgSXTVQjjfxcJ/3Vhr+JrRst/+PyM2itv3QLYzP+K7jYLFX6h6woZYBtF0 3+7HeuJZuwmdNA5sH5fHZ5rJb/+hlQDMj0OcASEZRNGWbr2NvLDdple0BtAgQLmpMuGP Aq+9evaVl94SYebp31S4H5P6mVGuw5i0Fo3SlJHqx+Kx5oinaULr1n53EaA9CrmmwMJ8 tHTw== X-Gm-Message-State: APf1xPC0aPRKzLOM2icmQpGmR1SlvBCsfbS8VMymXNcl41oUD2jbmON5 yAxwZK49JZFI5EmQ9aa4L0OwuQ== X-Google-Smtp-Source: AH8x225wxUdhcUV+rVSBgJDUFvjkg+VGFoXt8VTAIjWuTNJ5U8+Imdyf8dydTWAWjAnrTgDvJQYuLA== X-Received: by 10.25.23.129 with SMTP id 1mr7078936lfx.143.1518425603070; Mon, 12 Feb 2018 00:53:23 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id r13sm1590461lfr.19.2018.02.12.00.53.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 00:53:22 -0800 (PST) From: Linus Walleij To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Mike Lockwood , Guenter Roeck , Linus Walleij Subject: [PATCH 3/3] extcon: gpio: Convert to fully use GPIO descriptor Date: Mon, 12 Feb 2018 09:53:14 +0100 Message-Id: <20180212085314.23014-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180212085314.23014-1-linus.walleij@linaro.org> References: <20180212085314.23014-1-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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 --- 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 1d180f717fdf..9491e3d0645d 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include @@ -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) + 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)