From patchwork Mon Feb 12 08:53:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 127952 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3006202ljc; Mon, 12 Feb 2018 00:53:30 -0800 (PST) X-Google-Smtp-Source: AH8x226Hym5mmIC8JNQn73fsoZwgZiDrNs3iVJjyCXqzh8sYpVB4FM6IFVPEVjE6EbXw5hw7EPcp X-Received: by 10.101.78.12 with SMTP id r12mr8880509pgt.33.1518425610484; Mon, 12 Feb 2018 00:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518425610; cv=none; d=google.com; s=arc-20160816; b=f19r1CJ/ikMt1DeFNVGPugCs6BMdmve1eiVvXv/p3Ge4v1X6eITcTcRe795E+FDBZC pIgDmgHiVpN8Hr3BHVlhdU6ChAJKkTSIvSOl1/lurry3F/dr8VjEjwqqfSORcrqCZrbd ABw/ZGUC06QytChRQrzgWY6arICf7Hs3CrTrBaKb3P2Anp3JYaNnYisZoRpZWGqFvBNT Or0H0HsmWpfI5hdxmsPZX/GbBq5Rlu3hiLIjoaTw6fs3mCQ3xspb/WIkzelxnW4blVlg 2xVwCgAk0bX/4zYAVRJXUaL9NpXfgWmAaKF82EBpuKMZdzbYgdqiE6+iR33edGQz6dCO pLxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=AL7k3LkSauFZ5NqInZPTH8DHbfgPKqOXFFIN0CyzZGk=; b=Px7/pX3CS9aBPoXTmlGm4s2W2O4EGJF9z+w41r467VYqu+G2MKiLYZT3rTDVdlrC8z vOCgiIt+IF/bTQo7l9v0FDObJO0nJ4A9/bpSAJIrh30WEuQZMRVXTuNrvcAYxDHjqtIt fU3C4pcTMA6Wb1zSBHFokK85Jz14iA+En/jMAxFwnguDzj5zgRSPr749lKxM0lV17Kls b+aEjVc3Hcwd01atvnjdykSkZf4QKxymmf/RfEV2514ToHyzjnCiLvXaXPECMIpumiG6 GCRY2xLAHxtlexGB+DaQwA9r7gIoubAVoQ1emLRwbjq9XxGcmEB7mwvzIIH3wsF8IKr/ rYFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=js4oR5BX; 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 a15-v6si5618753pll.304.2018.02.12.00.53.30; Mon, 12 Feb 2018 00:53:30 -0800 (PST) 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=js4oR5BX; 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 S933188AbeBLIxZ (ORCPT + 12 others); Mon, 12 Feb 2018 03:53:25 -0500 Received: from mail-lf0-f65.google.com ([209.85.215.65]:46354 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932946AbeBLIxU (ORCPT ); Mon, 12 Feb 2018 03:53:20 -0500 Received: by mail-lf0-f65.google.com with SMTP id q194so19361317lfe.13 for ; Mon, 12 Feb 2018 00:53:19 -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; bh=AL7k3LkSauFZ5NqInZPTH8DHbfgPKqOXFFIN0CyzZGk=; b=js4oR5BXWzpNk6OAGPmnmEpikiszcFkdCfuAidawDmo4VYMfEMu4to757OP3+mHIm+ I2DzuYEbb5XNp6pv/w9iAoPSowyWTfQp5A/TTeippN8fmfdw6OUg7q0K8TgrOWWOtHo/ fxakOaHvTJL+8jN34mIOMV4UlxAm0i5GDXx+8= 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; bh=AL7k3LkSauFZ5NqInZPTH8DHbfgPKqOXFFIN0CyzZGk=; b=RTSYjK/y4akUB19+G2arG+Lq2VUzOxrs7OJOSshyXAoiaiWzBmXY3P1hphBCsaM7aY tkEIkSarzPbfFTCFhB6yVwdqtrR73ZEGBbCpVWeJqcAaHe3C2oqv+bmhH+Y6I3PeR8w4 SyUdxUDgXuTdZsfYo4KcL5f061730BHpDXjunSPjipPhovkD57IN6XsSBdqRO3yxok8J mqqrjIWy/I0WtYRQr6JsA+K8OG1REo8f3DYY7WLop/YTbwiEw/44/AkgaHmgQyWk7p89 5C8qIRbcxnJFNKgQ68vIXNxGb/uBIaExjf2bJeM0PZlXfCDxe7NgDRHOlWGG0VwGXBRD Cfvg== X-Gm-Message-State: APf1xPAuC9VN7AHOgCJ5twARcEBSBSv+u+45vCgSnGWQfz+d+8WRHf3m eywwGziYsPYDa665ABBRhoRUgw== X-Received: by 10.46.118.4 with SMTP id r4mr7496447ljc.123.1518425598485; Mon, 12 Feb 2018 00:53:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 00:53:17 -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 1/3] extcon: gpio: Localize platform data Date: Mon, 12 Feb 2018 09:53:12 +0100 Message-Id: <20180212085314.23014-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nothing in the entire kernel #includes so move the platform data declaration inside of the driver. Signed-off-by: Linus Walleij --- drivers/extcon/extcon-gpio.c | 22 +++++++++++++++++- include/linux/extcon/extcon-gpio.h | 47 -------------------------------------- 2 files changed, 21 insertions(+), 48 deletions(-) delete mode 100644 include/linux/extcon/extcon-gpio.h -- 2.14.3 diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index ab770adcca7e..5f88f36cc54e 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -18,7 +18,6 @@ */ #include -#include #include #include #include @@ -29,6 +28,27 @@ #include #include +/** + * struct gpio_extcon_pdata - A simple GPIO-controlled extcon device. + * @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 + * while resuming from sleep. + */ +struct gpio_extcon_pdata { + unsigned int extcon_id; + unsigned gpio; + bool gpio_active_low; + unsigned long debounce; + unsigned long irq_flags; + bool check_on_resume; +}; + struct gpio_extcon_data { struct extcon_dev *edev; int irq; diff --git a/include/linux/extcon/extcon-gpio.h b/include/linux/extcon/extcon-gpio.h deleted file mode 100644 index 7cacafb78b09..000000000000 --- a/include/linux/extcon/extcon-gpio.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Single-state GPIO extcon driver based on extcon class - * - * Copyright (C) 2012 Samsung Electronics - * Author: MyungJoo Ham - * - * based on switch class driver - * Copyright (C) 2008 Google, Inc. - * Author: Mike Lockwood - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ -#ifndef __EXTCON_GPIO_H__ -#define __EXTCON_GPIO_H__ __FILE__ - -#include - -/** - * struct gpio_extcon_pdata - A simple GPIO-controlled extcon device. - * @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 - * while resuming from sleep. - */ -struct gpio_extcon_pdata { - unsigned int extcon_id; - unsigned gpio; - bool gpio_active_low; - unsigned long debounce; - unsigned long irq_flags; - - bool check_on_resume; -}; - -#endif /* __EXTCON_GPIO_H__ */ 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: 127953 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3006259ljc; Mon, 12 Feb 2018 00:53:35 -0800 (PST) X-Google-Smtp-Source: AH8x226drXevRZLGs60hiQMhKGG3Cc+SoSzapatT6oNIb9bl2rTCVvXILuj8xRU3PFrbk4iBsjyS X-Received: by 2002:a17:902:f:: with SMTP id 15-v6mr10099064pla.419.1518425615758; Mon, 12 Feb 2018 00:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518425615; cv=none; d=google.com; s=arc-20160816; b=ls3F2ZWYWj2a5t/XgIvMLtRQxn69zRyzLK8ZsLV+g9T1uynnjo4qhS4uc8JN9NQxGL fpiWT1iUOIWOeOWwCkyXqwtkUrQrbn9phpbKhk9RW8DbDIIEoGnjDAyhWOf8vdoZj16b Z8wuSIILfOO7grbORVMz3CwUybUBi6yaZPzt+8K5D7QE/tn2P3zMCWw4tE1A6XUjTrcG wFrcpjWe++T3Azg+w5EPaihJNN71J+Qxyd2rqUyVD7vPxs1HLqpfkLI5YnJAHI0/2ncV /gwsbsSej/ef0zA9jPnB4lT6Y6llxcgOuS6lnSs0QjZzTGbVc5p9LbpDc48YDGAXNw2r yasw== 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=SrThppyoR5yvdc+QSoNVD0b61E4l4nWzJ+WH3IuT1u0=; b=DxUP1U3lOG7p6A4BTeuwNpj8HTGYR8YaB7nC6MzMTkcWRWkfl31uc9DvYoqhkhF5/J OT1KOjPFpGeE4BQMq5Qy0TH5vsyr9tqjqOPFlYcYTzVQALwsppmMEMfY9MuACFbh8hmS z/kVor5sid0NWPsLv7lDuJ5LHzT+L+sHNbkTScETWYINR6wt3RabvWlYkPxiRua9RhVr 9FwVAsodeznsmRu1Fl3skVeGD8ktGqRUhKoEwBpyJEWC3+3viqffhh3F1rr+86biDb1e tQlMBNFFVNhSxcCnXEiOsMEJkt1rUMZTRm/rycnoto+TEHUZAeEcmmxbDQvmERp5AtEp 0IpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q5Qahqpv; 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 a15-v6si5618753pll.304.2018.02.12.00.53.35; Mon, 12 Feb 2018 00:53:35 -0800 (PST) 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=Q5Qahqpv; 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 S933202AbeBLIxa (ORCPT + 12 others); Mon, 12 Feb 2018 03:53:30 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:46361 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933173AbeBLIxY (ORCPT ); Mon, 12 Feb 2018 03:53:24 -0500 Received: by mail-lf0-f67.google.com with SMTP id q194so19361535lfe.13 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=eJnMFkMjWXfcMIF2Hi7swTNAPm2fHgjhhBmzU2OWlazeB9mnB3LOfBkroJ3ICZI9ij JLpyF+0v9m6KOWTklgZYZkNtj4sd6vOfmbk6TurjZ76ABo8YPbrA30MV67PukKe5Y5MU zj86D/UioymTfSi/EWVRNwwhsPp74AAR4s+q+wNMG1SobcnpamhFQe48kNnRCWcuO6/g zz6vKmgPc3o37K3kEYoyjOTk8HqFN2ySuArlCGQ1pN3Cv3eInw66ocMFWUl2XBNGMiWa M8lo8R9rDuOdLiCbxdnVR0VWO78T7rDBhhMZhCD785tGuqkYMy3X+Ws6XA83SvaNkM7H VOYQ== X-Gm-Message-State: APf1xPDWaqOhAgkqpFjeBK0l8Kc3BMueVQ1MmFsklwMn/XJ2laQK7yM3 rlkyLfzh3ZJRmvJai1FzjjUv7g== 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-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.14.3 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)