From patchwork Sun Sep 24 14:56:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114129 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1643313qgf; Sun, 24 Sep 2017 08:00:06 -0700 (PDT) X-Received: by 10.98.129.6 with SMTP id t6mr4822700pfd.225.1506265206551; Sun, 24 Sep 2017 08:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506265206; cv=none; d=google.com; s=arc-20160816; b=Qv0A418q1yESDAshpxukOvsef3y/khsRFh6v1LQkx4bF1p+GK87oBFCRWQUFIfVUWB fb3ITsRK5NMY9A9fs6jz5a2l2eV5ktLpv10O1n8sHuoZogVeCQKNx/l0jFanR42si4ML MknigTx2coMMM5DnBwufVDc7CUzAOBfJNyFDR7k0ca+yHF8Ni1Mthur6+J65zVZFcLmk z4ITsfNNqzeXT1XcCs9ITiyYbuPrDeS1ltz78iAeWLE403p6kFpeGa7+HwkMkwJrfFMr Vakxr/fAcTQwI4brMIhB64X2XS9IzxaPcKvb6Oo5U1d2u1t4oLyeGL9K0CZceSNIWYiG 4foA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=9EoT4D03TXTHT89pkomvmDIwfs/ypqXeVk5hZO8RL1E=; b=CCIyxwVJ19tpENkMMzwN4BzCycu9d1yFjU3YbTQ4LU0XbNrEhlYhtiMhMqa4Lzvr6f skvPx9u+6E59nFAg+//uokO+ACCIzSDIgTuXYI2L+OCByrsV6dsdn9gY2MXcEFauDTyG Ddja3DIxO9tQJiPXEMbAVXpRZpRqTvzTQu/sh//LVpnoiFXXvFKIdaRtvWaciIEOb2IQ YZcJRb74P0h1WiEDa47XyvzXO7KFmQLam5D4bt2yhFZkfBBXhTq8DSElgljSmlqkC1uQ 4YjqW4n/5fFQrwPzlZzN+56bmgXAh3PfsT++3fZ7OYkytwKciulWsN0Py9yG/32O51zh QGeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h6CObgrT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f18si2725636pgn.355.2017.09.24.08.00.06; Sun, 24 Sep 2017 08:00:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h6CObgrT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbdIXPAE (ORCPT + 26 others); Sun, 24 Sep 2017 11:00:04 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:52166 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752461AbdIXPAC (ORCPT ); Sun, 24 Sep 2017 11:00:02 -0400 Received: by mail-pf0-f169.google.com with SMTP id b70so2605498pfl.8 for ; Sun, 24 Sep 2017 08:00:02 -0700 (PDT) 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=9EoT4D03TXTHT89pkomvmDIwfs/ypqXeVk5hZO8RL1E=; b=h6CObgrTcPZkdCAZ/ct51BJ9g/Sc+SyyI8QsgYXVjwweu63cKkYzoFIiCwZatHg/w/ x/1PrysEf5xwZ/wmfqjFGMgWXDEJsCr71VsL/xzA+to2DX7HG+ekmaWEOzXIoxTPVdTy HOV8l0jbFIDCGrwZBT6WazKpQTGFafpQPS1gc= 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=9EoT4D03TXTHT89pkomvmDIwfs/ypqXeVk5hZO8RL1E=; b=RsUHP0+zIqDGvNsLPMyGi3bk4Buh7xQR8ki8SvCltRl1jOhCDOCIm6Ejk5fjBO0NUx OC46zBr8hi/5uVP4kOj+fSYC7BQ278C078uIQO27F86dX5JUZUqLe0AVIJZeyJ2J9W3u 3sHfxc6xuN3i70XHaeadxSRzDVeSk/PVkCZa2WisSzh9rmht4y5Rb8cElMuFzg+21ZAs CFKe3XMEHqRO294V7nIFT1cVSFQHxpbdX0NDN8Bkmyz2p7X27v8CB2UL++LOzkKriLpT xvmzcQkxEoKde24cf2+MJNd3XYEUVR60QUrXkngIEtTfTC0TGP3R7zCkNiFiZu6z8P/X psvA== X-Gm-Message-State: AHPjjUgxDIxdWge/wjq1LOXiVx8UyqF9DfAJ2gd1z8hZ0gQuy9XwhAnK rJfmY1NzUs3LZdE2FSkbmEnwTQ== X-Google-Smtp-Source: AOwi7QDThN7DPSh4jq4dQGnzZXDT+pqUvSJe3tfRlstyuqnHgE+2JRdLz+w3VG71kPXvU+jlLuiBcQ== X-Received: by 10.84.212.2 with SMTP id d2mr4876051pli.412.1506265201913; Sun, 24 Sep 2017 08:00:01 -0700 (PDT) Received: from genomnajs.saswifi.com ([104.153.224.168]) by smtp.gmail.com with ESMTPSA id n83sm7386805pfi.163.2017.09.24.07.59.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 08:00:01 -0700 (PDT) From: Linus Walleij To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, John Stultz , Mike Lockwood , Guenter Roeck , Linus Walleij 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) -- 2.13.5 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 -#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)