From patchwork Mon Feb 12 08:53:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 127951 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3006159ljc; Mon, 12 Feb 2018 00:53:25 -0800 (PST) X-Google-Smtp-Source: AH8x226aIbWWeWMtbMaz//DnJEKOi3Vss83ZaqBakdHEB/NBCr46jIcTG93DTNGG4zQs71i1Jyhf X-Received: by 10.98.25.207 with SMTP id 198mr11068908pfz.83.1518425605674; Mon, 12 Feb 2018 00:53:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518425605; cv=none; d=google.com; s=arc-20160816; b=duKUJzOg9WHDDteRcdb2Ke62ILZZMHEWoODyxXdxfm1WvYJ8/9eSPVGyIPaj0rJh8m izUTnaIeYXv47rlh+/APOWE+rQPscUfJYYDhbfF6BOrO2NpzeuRAkgCq82DyzwOFWGnU k4Y3RWxzNRGpTtYKGmAbuY8oVNOsRPJNTJ18lvJjtHsrril7Slb+2SlP915JavXaPTTP 0fZEvCSq5RNVajqAzwLo27Ius719756aFNIPnmXo7nvzjUmY181lkvKoK3RW97w9+SF1 TMIRKL7hp44YfTO2Jx6nJck+jSjcqm3Q0UntK1snY6X5Ay/9AjNFi24IUk2eJ4JSGdPF /kCw== 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=+17faZWieeDrmqi48lrd4XyIVXQ/lEgqXuvKe1aHXjU=; b=BYj+rKF41M1DhVZeVZDjCNF6x3qkeCLnPZQ8jJ2sX0FixqeOI4JoLMH96amauKwh6s 2YKmMvPmr5JfsyDCC4aR82Eil3SB79GyhQLfHT5+dXXsvbxRlKbHmnRoXjidi4AcGdQY 6M2NpzgNawtVGeAhlHVJoSsAXJwvXcnZHDt5wSbsR0PfGY0mpbOQdmTpQ/Y5wpxl11W/ 84mY7zUR46q9xv9L2L8s9cirIBV4pIERqTSLPkLAUScjqUmUb5dO51tkzOfQWH3BzQGK 3CC9htEVjUZxusfNtDUBCodK6W+kC498PHWjDPiZup32OUV2oAtjxzHIhNAcAwURjOJR xgaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=BxCRuSST; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (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.25; Mon, 12 Feb 2018 00:53:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=BxCRuSST; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933185AbeBLIxY (ORCPT + 5 others); Mon, 12 Feb 2018 03:53:24 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:37257 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933172AbeBLIxW (ORCPT ); Mon, 12 Feb 2018 03:53:22 -0500 Received: by mail-lf0-f68.google.com with SMTP id f137so19396918lfe.4 for ; Mon, 12 Feb 2018 00:53:21 -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=TDBMEjTD2jKIoe3OD4AeXA0tD9KdOXZ90+7ZdX/yrMM=; b=BxCRuSSTbDhxqbxZbPXleT+YAihN5NeinqwYdicGPc2sye3IH5jlAE/OR5vdzz0WOb fbZf2MqnMSy7Xme5XfPXhAc9XhyPN0SDRdTKDWcgTbg44Fk3/z8u+z95/enbXC1FHZda 2hoA+ujHuuLewxCZJdMLGXGdUdaNA0iGarexc= 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=TDBMEjTD2jKIoe3OD4AeXA0tD9KdOXZ90+7ZdX/yrMM=; b=K5QeLwHNBvDoG991dU36GeII0QofcmnUmHzLeONkmpxgjGY4ReY/6rrUp9L8K7zcA4 dekACqr88Bb3ecmlQoPxvHm4yjb1GU7fqjYID42HlAPYPbmaeAXNFVP1uKZ1+KluSzRb 8/znw5+7Wnbx28TPyUbC/q9+8NVi4yR9MQxZ2tT3SFtQGJxOBwuyQf15PJCS5ZIsB8ER JFSxsRL5+xJyvWcUOg8l3fGAOV/mGFOjxILC+Y8WF878fBiXNS1IGqsUCx5uB7nA83Gk f5R/Fteh1wUd6+daGw74fuO/T2usuyMNuZnUSE0DhZxPb/9AUitVzJbUpfnAWHFiZEbs AtcQ== X-Gm-Message-State: APf1xPAIANTnruC2C7aOVVNhmgPn7y4Q7PxAFuawNnmhhwzwF9IwU/vr wlhq801Wwt5G2RvfzwqGN38N5A== X-Received: by 10.46.117.3 with SMTP id q3mr7422961ljc.65.1518425600638; Mon, 12 Feb 2018 00:53:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 00:53:19 -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 2/3] extcon: gpio: Move platform data into state container Date: Mon, 12 Feb 2018 09:53:13 +0100 Message-Id: <20180212085314.23014-2-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 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.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index 5f88f36cc54e..1d180f717fdf 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);