From patchwork Tue Dec 31 02:05:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Heiny X-Patchwork-Id: 3421281 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2D8349F295 for ; Tue, 31 Dec 2013 02:05:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E7D220107 for ; Tue, 31 Dec 2013 02:05:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB298200EC for ; Tue, 31 Dec 2013 02:05:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752559Ab3LaCFj (ORCPT ); Mon, 30 Dec 2013 21:05:39 -0500 Received: from us-mx2.synaptics.com ([192.147.44.131]:55784 "EHLO us-mx2.synaptics.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752516Ab3LaCFi (ORCPT ); Mon, 30 Dec 2013 21:05:38 -0500 Received: from unknown (HELO securemail.synaptics.com) ([172.20.21.135]) by us-mx2.synaptics.com with ESMTP; 30 Dec 2013 18:05:37 -0800 Received: from USW-OWA1.synaptics-inc.local ([10.20.24.16]) by securemail.synaptics.com (PGP Universal service); Mon, 30 Dec 2013 17:55:35 -0800 X-PGP-Universal: processed; by securemail.synaptics.com on Mon, 30 Dec 2013 17:55:35 -0800 Received: from brontomerus.synaptics.com (10.3.20.103) by USW-OWA1.synaptics-inc.local (10.20.24.15) with Microsoft SMTP Server (TLS) id 14.3.123.3; Mon, 30 Dec 2013 18:05:37 -0800 From: Christopher Heiny To: Dmitry Torokhov CC: Linux Input , Christopher Heiny , Andrew Duggan , Vincent Huang , Vivian Ly , Daniel Rosenberg , Jean Delvare , Joerie de Gram , Linus Walleij , Benjamin Tissoires Subject: [PATCH V5] input synaptics-rmi4: Bug fixes to ATTN GPIO handling. Date: Mon, 30 Dec 2013 18:05:25 -0800 Message-ID: <1388455525-30610-1-git-send-email-cheiny@synaptics.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.3.20.103] X-Brightmail-Tracker: AAAAAQAAAWE= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes some bugs in handling of the RMI4 attention line GPIO. 1) in enable_sensor(), eliminate the complicated check on ATTN and just call process_interrupt_requests(). This will have minimal overhead if ATTN is not asserted, and clears the state of the RMI4 device in any case. 2) Correctly free the GPIO in rmi_driver_remove(). 3) in rmi_driver_probe() - declare the name of the attention gpio (GPIO_LABEL) - use gpio_request_one() to get the gpio and export it. - simplify (somewhat) conditional gpio acquisition logic and combine with interrupt setup 4) use gpio_is_valid() instead of comparing to 0. Signed-off-by: Christopher Heiny Cc: Dmitry Torokhov Cc: Benjamin Tissoires --- drivers/input/rmi4/rmi_driver.c | 66 ++++++++++++++++++++++++----------------- drivers/input/rmi4/rmi_driver.h | 1 + 2 files changed, 40 insertions(+), 27 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-input" 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/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 2ae9af9..420ef56 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -140,7 +140,6 @@ static int enable_sensor(struct rmi_device *rmi_dev) struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); struct rmi_transport_dev *xport; int retval = 0; - struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev); if (data->enabled) return 0; @@ -169,11 +168,7 @@ static int enable_sensor(struct rmi_device *rmi_dev) data->enabled = true; - if (!pdata->level_triggered && - gpio_get_value(pdata->attn_gpio) == pdata->attn_polarity) - retval = process_interrupt_requests(rmi_dev); - - return retval; + return process_interrupt_requests(rmi_dev); } static void rmi_free_function_list(struct rmi_device *rmi_dev) @@ -800,10 +795,16 @@ static SIMPLE_DEV_PM_OPS(rmi_driver_pm, rmi_driver_suspend, rmi_driver_resume); static int rmi_driver_remove(struct device *dev) { struct rmi_device *rmi_dev = to_rmi_device(dev); + const struct rmi_device_platform_data *pdata = + to_rmi_platform_data(rmi_dev); + const struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev); disable_sensor(rmi_dev); rmi_free_function_list(rmi_dev); + if (data->gpio_held) + gpio_free(pdata->attn_gpio); + return 0; } @@ -815,6 +816,7 @@ static int rmi_driver_probe(struct device *dev) struct rmi_device_platform_data *pdata; int retval = 0; struct rmi_device *rmi_dev; + static const char GPIO_LABEL[] = "attn"; dev_dbg(dev, "%s: Starting probe.\n", __func__); @@ -937,7 +939,9 @@ static int rmi_driver_probe(struct device *dev) mutex_init(&data->suspend_mutex); } - if (pdata->attn_gpio) { + if (gpio_is_valid(pdata->attn_gpio)) { + ulong gpio_flags = GPIOF_DIR_IN; + data->irq = gpio_to_irq(pdata->attn_gpio); if (pdata->level_triggered) { data->irq_flags = IRQF_ONESHOT | @@ -948,33 +952,41 @@ static int rmi_driver_probe(struct device *dev) (pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH) ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; } - } else - data->poll_interval = ktime_set(0, - (pdata->poll_interval_ms ? pdata->poll_interval_ms : - DEFAULT_POLL_INTERVAL_MS) * 1000 * 1000); - - if (data->f01_container->dev.driver) { - /* Driver already bound, so enable ATTN now. */ - enable_sensor(rmi_dev); - } - if (IS_ENABLED(CONFIG_RMI4_DEV) && pdata->attn_gpio) { - retval = gpio_export(pdata->attn_gpio, false); + if (IS_ENABLED(CONFIG_RMI4_DEV)) + gpio_flags |= GPIOF_EXPORT; + retval = gpio_request_one(pdata->attn_gpio, gpio_flags, + GPIO_LABEL); if (retval) { - dev_warn(dev, "WARNING: Failed to export ATTN gpio!\n"); + dev_warn(dev, "WARNING: Failed to request ATTN gpio %d, code=%d.\n", + pdata->attn_gpio, retval); retval = 0; } else { - retval = gpio_export_link(dev, - "attn", pdata->attn_gpio); - if (retval) { - dev_warn(dev, - "WARNING: Failed to symlink ATTN gpio!\n"); - retval = 0; - } else { - dev_info(dev, "Exported ATTN GPIO %d.", + dev_info(dev, "Obtained ATTN gpio %d.\n", pdata->attn_gpio); + data->gpio_held = true; + if (IS_ENABLED(CONFIG_RMI4_DEV)) { + retval = gpio_export_link(dev, + GPIO_LABEL, pdata->attn_gpio); + if (retval) { + dev_warn(dev, + "WARNING: Failed to symlink ATTN gpio!\n"); + retval = 0; + } else { + dev_info(dev, "Exported ATTN gpio %d.", + pdata->attn_gpio); + } } } + } else { + data->poll_interval = ktime_set(0, + (pdata->poll_interval_ms ? pdata->poll_interval_ms : + DEFAULT_POLL_INTERVAL_MS) * 1000 * 1000); + } + + if (data->f01_container->dev.driver) { + /* Driver already bound, so enable ATTN now. */ + enable_sensor(rmi_dev); } return 0; diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index 0d57700..df9ddd8 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -41,6 +41,7 @@ struct rmi_driver_data { u32 attn_count; u32 irq_debug; /* Should be bool, but debugfs wants u32 */ + bool gpio_held; int irq; int irq_flags; int num_of_irq_regs;