From patchwork Sun Sep 24 14:56:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114128 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1642813qgf; Sun, 24 Sep 2017 07:59:26 -0700 (PDT) X-Received: by 10.159.249.69 with SMTP id h5mr4949380pls.208.1506265166549; Sun, 24 Sep 2017 07:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506265166; cv=none; d=google.com; s=arc-20160816; b=RiKzXpZHikHdVbS8V/yFq0aDXzZ/I81ayz6eIxZaA69MreBsZRExTCqPQSuoVOPCz2 u0AgLTj3P5gQNl58gUrM81VS1AVFFRJTPjrUmPsi21/Jpy3BDEaBdNKrSJHCAsZCRUI4 WY0jST3h2/QBtlgibJ782fp5mzBb64EGSMmN+b9B8WQVBG0OHCJ85uqeP4yDYRQTiUSL /V4ozDMM8geMj5z0kI9vAnr5f8asJJC3ehkFILYe4NlKt6OGgHSHTpnJDZ7KBFygDdZ9 rmpV+TNQ3AiDxS+cS497CR+eGfpCxReeIp891nPXNOUISFbNfgMUYMxjVT5GT+P7AQhO blyQ== 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=M9XDYYz0gZs1pQCax0DPKAB1f/KOsg+vKI8BIsSW1d0=; b=ZR3STNEF9ofCdmEKcEqkIb4Ct/aRmcljFNJgcTSTs8i+bM1Anp4USbK1NzLFdK++Ec qfskl1WqCV5ezSwio9VsbXcMJRuh7OnUnTIFoPjtOYDh9k43iKQQrW7PdAMZdssKT+HZ lIZbbPi5dAb+KEKjYuSGY6DfSWl3lwH536f2TOPoS0/1W1npGQAzm0CGbLimFsKCpcjF fIaH7mGO78s+kvyZyyzCqF41GjIT4hXSHfzHoEJKtkycOVeE6eGW6pHhkwf1WMp424vH CoMoSoLmIlptr88uFhqtv14+SzcPWa1RbQsJ0d7boqZ/BI832QJihR9qp/6l4VZL0wyv JqyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=irUfUJ2M; 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 z2si2728151pgo.334.2017.09.24.07.59.26; Sun, 24 Sep 2017 07:59:26 -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=irUfUJ2M; 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 S1752639AbdIXO7Y (ORCPT + 26 others); Sun, 24 Sep 2017 10:59:24 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:55571 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752392AbdIXO7W (ORCPT ); Sun, 24 Sep 2017 10:59:22 -0400 Received: by mail-pg0-f42.google.com with SMTP id b11so2721490pgn.12 for ; Sun, 24 Sep 2017 07:59:22 -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=M9XDYYz0gZs1pQCax0DPKAB1f/KOsg+vKI8BIsSW1d0=; b=irUfUJ2MH2rJmZTNqx6+vL2SbpYjKjMLRMUmuMohRvJsS7NBU67KggDbzLFZVgz2AD vaFuaUxroMlE+yEjRHQpGDWdtgxwqJnJcsrIbIbQABEFbyg7DisyY98hc63AJbBrpHqE tvJds2cKRivU6z0q7TSQU9vjXuRz2mjHgqU40= 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=M9XDYYz0gZs1pQCax0DPKAB1f/KOsg+vKI8BIsSW1d0=; b=IqPBZp6U0r1gXj/oowBkrWqyd9/4/bbZr/7P3VcUh/HRzyZZZl/iiYWstQeGQHZ5B5 EqDDpyboLEd4PxRz2R2G/EiMvRe54SHKwvsLOg6ND151UaBZUSSKnzMR6yGgrXvZk/S/ YQmZDYCwQqcEjxO7oBYlNOquChaLNBIgKOHozgg4mZTcN6kvZhBQEzPQNj/BUYLJssWk 1Iv3aDk9msNSaTyEgYydagsqcUMz542xtMg9GHNmlDvKWzHuVcH2CGjWljiG5r0/CH+m MNbNpjUB1M4RJmHNK3kzw56RurMeheXOdsnQ4+bZCVDW1RCup3Gnzs0bSNSakflS47jE tgVA== X-Gm-Message-State: AHPjjUhU7MG0ncfZnBX35EIMm8nbxW2e0Lylb4b1FNJWvF+2FFlVJdZP 39boPGiJLZfNqwZKPJQDDfqubg== X-Google-Smtp-Source: AOwi7QDiw4q5JwFL9AxHZKPO/60rcqAYZn7JXQHbvhyY1Vo+rfyp8zRK9kPGuzt6AzX7iGdKkQj2zQ== X-Received: by 10.84.171.193 with SMTP id l59mr4792507plb.133.1506265161898; Sun, 24 Sep 2017 07:59:21 -0700 (PDT) Received: from genomnajs.saswifi.com ([104.153.224.168]) by smtp.gmail.com with ESMTPSA id n83sm7386805pfi.163.2017.09.24.07.58.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 07:59:21 -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 3/8] extcon: gpio: Move platform data into state container Date: Sun, 24 Sep 2017 16:56:17 +0200 Message-Id: <20170924145622.4031-4-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 This moves the platform data settings from the platform data struct and into the state container, saving some unnecessary references and simplifying things a bit. Signed-off-by: Linus Walleij --- drivers/extcon/extcon-gpio.c | 56 ++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) -- 2.13.5 Acked-by: Chanwoo Choi diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index 6abf5f70fdbf..9c4094edd123 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -29,7 +29,13 @@ #include /** - * struct gpio_extcon_pdata - A simple GPIO-controlled extcon device. + * struct gpio_extcon_data - A simple GPIO-controlled extcon device state container. + * @edev: Extcon device. + * @irq: Interrupt line for the external connector. + * @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. * @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 @@ -40,23 +46,18 @@ * @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; struct delayed_work work; unsigned long debounce_jiffies; - struct gpio_desc *id_gpiod; - struct gpio_extcon_pdata *pdata; + unsigned int extcon_id; + unsigned gpio; + bool gpio_active_low; + unsigned long debounce; + unsigned long irq_flags; + bool check_on_resume; }; static void gpio_extcon_work(struct work_struct *work) @@ -67,10 +68,10 @@ static void gpio_extcon_work(struct work_struct *work) work); state = gpiod_get_value_cansleep(data->id_gpiod); - if (data->pdata->gpio_active_low) + if (data->gpio_active_low) state = !state; - extcon_set_state_sync(data->edev, data->pdata->extcon_id, state); + extcon_set_state_sync(data->edev, data->extcon_id, state); } static irqreturn_t gpio_irq_handler(int irq, void *dev_id) @@ -84,24 +85,23 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id) static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data) { - struct gpio_extcon_pdata *pdata = data->pdata; int ret; - ret = devm_gpio_request_one(dev, pdata->gpio, GPIOF_DIR_IN, + 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(pdata->gpio); + data->id_gpiod = gpio_to_desc(data->gpio); if (!data->id_gpiod) return -EINVAL; - if (pdata->debounce) { + if (data->debounce) { ret = gpiod_set_debounce(data->id_gpiod, - pdata->debounce * 1000); + data->debounce * 1000); if (ret < 0) data->debounce_jiffies = - msecs_to_jiffies(pdata->debounce); + msecs_to_jiffies(data->debounce); } data->irq = gpiod_to_irq(data->id_gpiod); @@ -113,20 +113,16 @@ static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data) static int gpio_extcon_probe(struct platform_device *pdev) { - struct gpio_extcon_pdata *pdata = dev_get_platdata(&pdev->dev); struct gpio_extcon_data *data; int ret; - if (!pdata) - return -EBUSY; - if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE) - return -EINVAL; - data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data), GFP_KERNEL); if (!data) return -ENOMEM; - data->pdata = pdata; + + if (!data->irq_flags || data->extcon_id > EXTCON_NONE) + return -EINVAL; /* Initialize the gpio */ ret = gpio_extcon_init(&pdev->dev, data); @@ -134,7 +130,7 @@ static int gpio_extcon_probe(struct platform_device *pdev) return ret; /* Allocate the memory of extcon devie and register extcon device */ - data->edev = devm_extcon_dev_allocate(&pdev->dev, &pdata->extcon_id); + data->edev = devm_extcon_dev_allocate(&pdev->dev, &data->extcon_id); if (IS_ERR(data->edev)) { dev_err(&pdev->dev, "failed to allocate extcon device\n"); return -ENOMEM; @@ -151,7 +147,7 @@ static int gpio_extcon_probe(struct platform_device *pdev) * is attached or detached. */ ret = devm_request_any_context_irq(&pdev->dev, data->irq, - gpio_irq_handler, pdata->irq_flags, + gpio_irq_handler, data->irq_flags, pdev->name, data); if (ret < 0) return ret; @@ -178,7 +174,7 @@ static int gpio_extcon_resume(struct device *dev) struct gpio_extcon_data *data; data = dev_get_drvdata(dev); - if (data->pdata->check_on_resume) + if (data->check_on_resume) queue_delayed_work(system_power_efficient_wq, &data->work, data->debounce_jiffies);