From patchwork Wed Jan 11 17:28:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Bisson X-Patchwork-Id: 9510785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C79E7601E7 for ; Wed, 11 Jan 2017 17:29:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAE6F28626 for ; Wed, 11 Jan 2017 17:29:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFB112862E; Wed, 11 Jan 2017 17:29:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89C1E28626 for ; Wed, 11 Jan 2017 17:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937770AbdAKR2v (ORCPT ); Wed, 11 Jan 2017 12:28:51 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:33792 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965257AbdAKR2u (ORCPT ); Wed, 11 Jan 2017 12:28:50 -0500 Received: by mail-wm0-f51.google.com with SMTP id f73so28126805wmf.1 for ; Wed, 11 Jan 2017 09:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=boundarydevices-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=+XYFnsdwJofh2TCSlo6KcyYGvAtTghXR5tAahAV4Fso=; b=0iz/tLCnoWKhYTStHuBurRGJpUU51lazsjt1/RZ7dVmovkLa7Ghf7pTNsAB3Va9J9Q SLc8zU4yvFAZCt8RL1YJKM3d4lCkpLowKoPeTx7+1ar8pHz2B9Z58gSZHgmYu0Pxm5pO EAhx7JQ+kNp8eeKLswxfs38RYW8PCkEZPt2xjpNpxl3Ht0Iz0GA2AzlHy0z3cBDcr7Ys C60iORG4JQwy7aXgy4VyFg/4L30dsPB1ic/ndwS7mcKlxGzF5mDNXDXwYVHfJ/nJlkrx 9POu1BCR+2ZKT9IQRFtAAmbZzDJolVxQlRJPllb94Ch7NVvC9kvr9bUw2NPxuDdZiYvn 5mYg== 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=+XYFnsdwJofh2TCSlo6KcyYGvAtTghXR5tAahAV4Fso=; b=frKfFTBW3zpZPGWBnQ07GCzaA43rhk/RDmX4yQ7gn+RKppHSbCDE2SyTU5YWrQngNI 5EeyZxg9JIQ50dIzyVzGwNBqkO7/53SU0aB6PtMhA3zmVR1hfejtMCLwCQR3NOPf7d17 B+1bEAvVVRzXbxsJBtjrA4zNrTL7zgxRQGDyXq/ko5zKwHzPVlUJCLQvcmc6oRQexKR5 4qy5ve6u4vEkRQ0l78+hvgshNVeCSD5pXJPcEvKNak3Wp7Uz9ILOKpv6GqgQyEQA01wR k25z+Mv87mnxV8+j+VxYSccSLWQLLH3pKhuX4C5gLVeAH1yuh22s2b2S0uuweL0JKxrq V/FA== X-Gm-Message-State: AIkVDXK/JB0emmEC09TGGOWMiZDpGC6Qwtgl0mVUBP7I5JSe3ys9am35pXN9gKN5TXp06g== X-Received: by 10.223.167.130 with SMTP id j2mr5248110wrc.154.1484155728185; Wed, 11 Jan 2017 09:28:48 -0800 (PST) Received: from localhost.localdomain (LMontsouris-657-1-10-89.w90-63.abo.wanadoo.fr. [90.63.251.89]) by smtp.googlemail.com with ESMTPSA id x7sm9560013wjp.18.2017.01.11.09.28.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 09:28:47 -0800 (PST) From: Gary Bisson To: linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org, Gary Bisson Subject: [PATCH] Input: egalax_ts - do not release gpio if probe successful Date: Wed, 11 Jan 2017 18:28:41 +0100 Message-Id: <20170111172841.9825-1-gary.bisson@boundarydevices.com> X-Mailer: git-send-email 2.11.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Thus preventing anyone to later modify the interrupt GPIO direction and/or state without the driver knowing. Also checking if device is present before allocating the input device. Signed-off-by: Gary Bisson --- drivers/input/touchscreen/egalax_ts.c | 56 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/drivers/input/touchscreen/egalax_ts.c b/drivers/input/touchscreen/egalax_ts.c index 1afc08b08155..f6b94bb19bd8 100644 --- a/drivers/input/touchscreen/egalax_ts.c +++ b/drivers/input/touchscreen/egalax_ts.c @@ -62,6 +62,7 @@ struct egalax_ts { struct i2c_client *client; struct input_dev *input_dev; + struct gpio_desc *wakeup_gpio; }; static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id) @@ -120,36 +121,21 @@ static irqreturn_t egalax_ts_interrupt(int irq, void *dev_id) } /* wake up controller by an falling edge of interrupt gpio. */ -static int egalax_wake_up_device(struct i2c_client *client) +static int egalax_wake_up_device(struct gpio_desc *wakeup_gpio) { - struct device_node *np = client->dev.of_node; - int gpio; int ret; - if (!np) - return -ENODEV; - - gpio = of_get_named_gpio(np, "wakeup-gpios", 0); - if (!gpio_is_valid(gpio)) - return -ENODEV; - - ret = gpio_request(gpio, "egalax_irq"); - if (ret < 0) { - dev_err(&client->dev, - "request gpio failed, cannot wake up controller: %d\n", - ret); + /* wake up controller via an falling edge on IRQ gpio. */ + ret = gpiod_direction_output(wakeup_gpio, 0); + if (ret < 0) return ret; - } - /* wake up controller via an falling edge on IRQ gpio. */ - gpio_direction_output(gpio, 0); - gpio_set_value(gpio, 1); + gpiod_set_value(wakeup_gpio, 1); /* controller should be waken up, return irq. */ - gpio_direction_input(gpio); - gpio_free(gpio); + ret = gpiod_direction_input(wakeup_gpio); - return 0; + return ret; } static int egalax_firmware_version(struct i2c_client *client) @@ -177,17 +163,15 @@ static int egalax_ts_probe(struct i2c_client *client, return -ENOMEM; } - input_dev = devm_input_allocate_device(&client->dev); - if (!input_dev) { - dev_err(&client->dev, "Failed to allocate memory\n"); - return -ENOMEM; + ts->wakeup_gpio = devm_gpiod_get_index(&client->dev, "wakeup", + 0, GPIOD_ASIS); + if (IS_ERR(ts->wakeup_gpio)) { + dev_err(&client->dev, "Failed to get wakeup gpio"); + return -ENODEV; } - ts->client = client; - ts->input_dev = input_dev; - /* controller may be in sleep, wake it up. */ - error = egalax_wake_up_device(client); + error = egalax_wake_up_device(ts->wakeup_gpio); if (error) { dev_err(&client->dev, "Failed to wake up the controller\n"); return error; @@ -199,6 +183,15 @@ static int egalax_ts_probe(struct i2c_client *client, return error; } + input_dev = devm_input_allocate_device(&client->dev); + if (!input_dev) { + dev_err(&client->dev, "Failed to allocate memory\n"); + return -ENOMEM; + } + + ts->client = client; + ts->input_dev = input_dev; + input_dev->name = "EETI eGalax Touch Screen"; input_dev->id.bustype = BUS_I2C; @@ -254,8 +247,9 @@ static int __maybe_unused egalax_ts_suspend(struct device *dev) static int __maybe_unused egalax_ts_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); + struct egalax_ts *ts = i2c_get_clientdata(client); - return egalax_wake_up_device(client); + return egalax_wake_up_device(ts->wakeup_gpio); } static SIMPLE_DEV_PM_OPS(egalax_ts_pm_ops, egalax_ts_suspend, egalax_ts_resume);