From patchwork Mon May 4 17:37:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 207885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4254FC3A5A9 for ; Mon, 4 May 2020 17:37:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22572206A4 for ; Mon, 4 May 2020 17:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730049AbgEDRh4 (ORCPT ); Mon, 4 May 2020 13:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730039AbgEDRhz (ORCPT ); Mon, 4 May 2020 13:37:55 -0400 X-Greylist: delayed 27966 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 04 May 2020 10:37:55 PDT Received: from mail.bugwerft.de (mail.bugwerft.de [IPv6:2a03:6000:1011::59]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7C622C061A0E for ; Mon, 4 May 2020 10:37:55 -0700 (PDT) Received: from zenbar.fritz.box (pD95EF30E.dip0.t-ipconnect.de [217.94.243.14]) by mail.bugwerft.de (Postfix) with ESMTPSA id 9809F403F4C; Mon, 4 May 2020 17:35:14 +0000 (UTC) From: Daniel Mack To: linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, m.felsch@pengutronix.de, Daniel Mack Subject: [PATCH v2 1/3] input: touch: ads7846: add short-hand for spi->dev in probe() function Date: Mon, 4 May 2020 19:37:43 +0200 Message-Id: <20200504173745.1246505-1-daniel@zonque.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This will make the code a bit more terse. No functional change intended. Signed-off-by: Daniel Mack --- drivers/input/touchscreen/ads7846.c | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 8fd7fc39c4fd..a1033b06f031 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -1265,20 +1265,21 @@ static int ads7846_probe(struct spi_device *spi) { const struct ads7846_platform_data *pdata; struct ads7846 *ts; + struct device *dev = &spi->dev; struct ads7846_packet *packet; struct input_dev *input_dev; unsigned long irq_flags; int err; if (!spi->irq) { - dev_dbg(&spi->dev, "no IRQ?\n"); + dev_dbg(dev, "no IRQ?\n"); return -EINVAL; } /* don't exceed max specified sample rate */ if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { - dev_err(&spi->dev, "f(sample) %d KHz?\n", - (spi->max_speed_hz/SAMPLE_BITS)/1000); + dev_err(dev, "f(sample) %d KHz?\n", + (spi->max_speed_hz/SAMPLE_BITS)/1000); return -EINVAL; } @@ -1310,9 +1311,9 @@ static int ads7846_probe(struct spi_device *spi) mutex_init(&ts->lock); init_waitqueue_head(&ts->wait); - pdata = dev_get_platdata(&spi->dev); + pdata = dev_get_platdata(dev); if (!pdata) { - pdata = ads7846_probe_dt(&spi->dev); + pdata = ads7846_probe_dt(dev); if (IS_ERR(pdata)) { err = PTR_ERR(pdata); goto err_free_mem; @@ -1354,12 +1355,12 @@ static int ads7846_probe(struct spi_device *spi) ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; - snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); + snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); input_dev->name = ts->name; input_dev->phys = ts->phys; - input_dev->dev.parent = &spi->dev; + input_dev->dev.parent = dev; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); @@ -1393,16 +1394,16 @@ static int ads7846_probe(struct spi_device *spi) ads7846_setup_spi_msg(ts, pdata); - ts->reg = regulator_get(&spi->dev, "vcc"); + ts->reg = regulator_get(dev, "vcc"); if (IS_ERR(ts->reg)) { err = PTR_ERR(ts->reg); - dev_err(&spi->dev, "unable to get regulator: %d\n", err); + dev_err(dev, "unable to get regulator: %d\n", err); goto err_free_gpio; } err = regulator_enable(ts->reg); if (err) { - dev_err(&spi->dev, "unable to enable regulator: %d\n", err); + dev_err(dev, "unable to enable regulator: %d\n", err); goto err_put_regulator; } @@ -1410,18 +1411,18 @@ static int ads7846_probe(struct spi_device *spi) irq_flags |= IRQF_ONESHOT; err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, - irq_flags, spi->dev.driver->name, ts); + irq_flags, dev->driver->name, ts); if (err && !pdata->irq_flags) { - dev_info(&spi->dev, + dev_info(dev, "trying pin change workaround on irq %d\n", spi->irq); irq_flags |= IRQF_TRIGGER_RISING; err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, - irq_flags, spi->dev.driver->name, ts); + irq_flags, dev->driver->name, ts); } if (err) { - dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); + dev_dbg(dev, "irq %d busy?\n", spi->irq); goto err_disable_regulator; } @@ -1429,18 +1430,18 @@ static int ads7846_probe(struct spi_device *spi) if (err) goto err_free_irq; - dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); + dev_info(dev, "touchscreen, irq %d\n", spi->irq); /* * Take a first sample, leaving nPENIRQ active and vREF off; avoid * the touchscreen, in case it's not connected. */ if (ts->model == 7845) - ads7845_read12_ser(&spi->dev, PWRDOWN); + ads7845_read12_ser(dev, PWRDOWN); else - (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux)); + (void) ads7846_read12_ser(dev, READ_12BIT_SER(vaux)); - err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); + err = sysfs_create_group(&dev->kobj, &ads784x_attr_group); if (err) goto err_remove_hwmon; @@ -1448,19 +1449,19 @@ static int ads7846_probe(struct spi_device *spi) if (err) goto err_remove_attr_group; - device_init_wakeup(&spi->dev, pdata->wakeup); + device_init_wakeup(dev, pdata->wakeup); /* * If device does not carry platform data we must have allocated it * when parsing DT data. */ - if (!dev_get_platdata(&spi->dev)) - devm_kfree(&spi->dev, (void *)pdata); + if (!dev_get_platdata(dev)) + devm_kfree(dev, (void *)pdata); return 0; err_remove_attr_group: - sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); + sysfs_remove_group(&dev->kobj, &ads784x_attr_group); err_remove_hwmon: ads784x_hwmon_unregister(spi, ts); err_free_irq: From patchwork Mon May 4 17:37:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 207884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABC2CC47258 for ; Mon, 4 May 2020 17:37:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 965B22068E for ; Mon, 4 May 2020 17:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729386AbgEDRh6 (ORCPT ); Mon, 4 May 2020 13:37:58 -0400 Received: from mail.bugwerft.de ([46.23.86.59]:37962 "EHLO mail.bugwerft.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730039AbgEDRh5 (ORCPT ); Mon, 4 May 2020 13:37:57 -0400 Received: from zenbar.fritz.box (pD95EF30E.dip0.t-ipconnect.de [217.94.243.14]) by mail.bugwerft.de (Postfix) with ESMTPSA id 29A4A403F58; Mon, 4 May 2020 17:35:17 +0000 (UTC) From: Daniel Mack To: linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, m.felsch@pengutronix.de, Daniel Mack Subject: [PATCH v2 3/3] input: touchscreen: ads7846: switch to gpiod API Date: Mon, 4 May 2020 19:37:45 +0200 Message-Id: <20200504173745.1246505-3-daniel@zonque.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200504173745.1246505-1-daniel@zonque.org> References: <20200504173745.1246505-1-daniel@zonque.org> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Use gpiod_* function to access the pendown GPIO line. Signed-off-by: Daniel Mack --- drivers/input/touchscreen/ads7846.c | 53 ++++++++++++++++------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 7f4ead542a73..b3e17ee4e499 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -137,7 +137,7 @@ struct ads7846 { void *filter_data; void (*filter_cleanup)(void *data); int (*get_pendown_state)(void); - int gpio_pendown; + struct gpio_desc *gpio_pendown; void (*wait_for_sync)(void); }; @@ -598,7 +598,7 @@ static int get_pendown_state(struct ads7846 *ts) if (ts->get_pendown_state) return ts->get_pendown_state(); - return !gpio_get_value(ts->gpio_pendown); + return !gpiod_get_value(ts->gpio_pendown); } static void null_wait_for_sync(void) @@ -919,6 +919,7 @@ static int ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts, const struct ads7846_platform_data *pdata) { + struct device *dev = &spi->dev; int err; /* @@ -929,27 +930,33 @@ static int ads7846_setup_pendown(struct spi_device *spi, if (pdata->get_pendown_state) { ts->get_pendown_state = pdata->get_pendown_state; - } else if (gpio_is_valid(pdata->gpio_pendown)) { - - err = devm_gpio_request_one(&spi->dev, pdata->gpio_pendown, - GPIOF_IN, "ads7846_pendown"); - if (err) { - dev_err(&spi->dev, - "failed to request/setup pendown GPIO%d: %d\n", - pdata->gpio_pendown, err); - return err; - } + return 0; + } - ts->gpio_pendown = pdata->gpio_pendown; + ts->gpio_pendown = devm_gpiod_get(dev, "pendown", GPIOD_IN); + if (IS_ERR(ts->gpio_pendown)) { + err = PTR_ERR(ts->gpio_pendown); - if (pdata->gpio_pendown_debounce) - gpio_set_debounce(pdata->gpio_pendown, - pdata->gpio_pendown_debounce); - } else { - dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); - return -EINVAL; + if (gpio_is_valid(pdata->gpio_pendown)) { + err = devm_gpio_request_one(dev, pdata->gpio_pendown, + GPIOF_IN, + "ads7846_pendown"); + if (err < 0) + return err; + + ts->gpio_pendown = gpio_to_desc(pdata->gpio_pendown); + if (!ts->gpio_pendown) + return -EINVAL; + } + + if (err < 0) + return err; } + if (pdata->gpio_pendown_debounce) + gpiod_set_debounce(ts->gpio_pendown, + pdata->gpio_pendown_debounce); + return 0; } @@ -1236,8 +1243,6 @@ static const struct ads7846_platform_data *ads7846_probe_dt(struct device *dev) pdata->wakeup = of_property_read_bool(node, "wakeup-source") || of_property_read_bool(node, "linux,wakeup"); - pdata->gpio_pendown = of_get_named_gpio(dev->of_node, "pendown-gpio", 0); - return pdata; } #else @@ -1340,8 +1345,10 @@ static int ads7846_probe(struct spi_device *spi) } err = ads7846_setup_pendown(spi, ts, pdata); - if (err) + if (err) { + dev_err(dev, "Unable to request pendown GPIO: %d", err); goto err_cleanup_filter; + } if (pdata->penirq_recheck_delay_usecs) ts->penirq_recheck_delay_usecs =