Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4936966imm; Tue, 16 Oct 2018 02:30:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV60Q7hWgOj9NIU4YYIDXIXaQMiHt7eYHL3zc8bLoEi0Y4ik5VyWkSWrlzvihogLsfJuhPvmr X-Received: by 2002:a62:52cc:: with SMTP id g195-v6mr21778930pfb.241.1539682203579; Tue, 16 Oct 2018 02:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539682203; cv=none; d=google.com; s=arc-20160816; b=SGFDeTy0ZSsPFvB/uMJAz1WRceUOZIOpWxjhULk/GJz/xRmxOsRCuHFaGObrTjnY8l SwtcLN+5qu4Tuy8GFCFw1DpqLZvxyL7r5p5eEZuLgZXUNSeSin/E7Ywn0HaT/0hoF3DB ONzZ4oSkAFkyr+1sk844uz/gwD+3wfIXksA6q3BNgz2H8Yt9/hp0SqoS6A54DJtanUR7 U0No+RIo91rBIoTuXxtXXOgwxFVCF+6eVg9D7Q+34slR5wljE+U376NrVCR1h6/WbY3x mD9X47TT1lMb6SPMlD4eWFXhDyqZvb4nwZ8Ccrld6MmXB2sGIEtVZv7ajY2lL9S8kH82 LBkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NAIk/Lq0AWirLlKXr5FZ6dPz0hITLjFQudLRan8m0IY=; b=AumRYGRH9mHI1OupLvDQwTv+IlxQ6hpXUEuY0GHmcDaMA5j59Tca7MTfjXbikT8Qpz uubd9+bYc90aHR+mzQSeesl13Y8Yt3E+InrYzfwNBG+5+T0MavyLHxEOXI92O619W8G9 8bhIFuuDES01uwx7E8FomuRGqAznsBgnkm1aUTR2DVxSOmvXmbLMfxQR0YzkLjU0WkJZ yz/RGQdIiE6fFybJ9EZc8CWpr9ZKGHk7pPbjWrmLz64VcmdTkEEm0F1OLtvxcZp7W171 lNPs/kOjHrD9VEiaWt0FzbxpDBYqcVWb7/RntftG5U4KTibNl9Iyi4PrXFriBnR0q1y0 YNgw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h32-v6si13347573pgm.126.2018.10.16.02.29.48; Tue, 16 Oct 2018 02:30:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbeJPRRv (ORCPT + 99 others); Tue, 16 Oct 2018 13:17:51 -0400 Received: from mail1.skidata.com ([91.230.2.99]:21997 "EHLO mail1.skidata.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeJPRRv (ORCPT ); Tue, 16 Oct 2018 13:17:51 -0400 X-IronPort-AV: E=Sophos;i="5.54,388,1534802400"; d="scan'208";a="12887974" From: Richard Leitner To: , , CC: , , , Richard Leitner Subject: [PATCH 2/7] Input: sx8654 - add reset-gpio support Date: Tue, 16 Oct 2018 11:16:48 +0200 Message-ID: <20181016091653.26896-3-richard.leitner@skidata.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181016091653.26896-1-richard.leitner@skidata.com> References: <20181016091653.26896-1-richard.leitner@skidata.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [192.168.111.252] X-ClientProxiedBy: sdex4srv.skidata.net (192.168.111.82) To sdex5srv.skidata.net (192.168.111.83) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sx8654 features a NRST input which may be connected to a GPIO. Therefore add support for hard-resetting the sx8654 via this NRST. If the reset-gpio property is provided the sx8654 is resetted via NRST instead of the soft-reset via I2C. Signed-off-by: Richard Leitner --- drivers/input/touchscreen/sx8654.c | 88 ++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/sx8654.c b/drivers/input/touchscreen/sx8654.c index ed29db3ec731..059127490c8d 100644 --- a/drivers/input/touchscreen/sx8654.c +++ b/drivers/input/touchscreen/sx8654.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include /* register addresses */ #define I2C_REG_TOUCH0 0x00 @@ -74,6 +76,7 @@ struct sx8654 { struct input_dev *input; struct i2c_client *client; + struct gpio_desc *gpio_reset; }; static irqreturn_t sx8654_irq(int irq, void *handle) @@ -124,6 +127,27 @@ static irqreturn_t sx8654_irq(int irq, void *handle) return IRQ_HANDLED; } +static int sx8654_reset(struct sx8654 *ts) +{ + int err; + + if (ts->gpio_reset) { + gpiod_set_value_cansleep(ts->gpio_reset, 1); + udelay(2); /* Tpulse > 1µs */ + gpiod_set_value_cansleep(ts->gpio_reset, 0); + + return 0; + } + + dev_dbg(&ts->client->dev, "NRST unavailable, try softreset\n"); + err = i2c_smbus_write_byte_data(ts->client, I2C_REG_SOFTRESET, + SOFTRESET_VALUE); + if (err) + return err; + + return 0; +} + static int sx8654_open(struct input_dev *dev) { struct sx8654 *sx8654 = input_get_drvdata(dev); @@ -171,6 +195,44 @@ static void sx8654_close(struct input_dev *dev) } } +#ifdef CONFIG_OF +static int sx8654_get_ofdata(struct sx8654 *ts) +{ + struct device *dev = &ts->client->dev; + struct device_node *node = dev->of_node; + int err; + + if (!node) { + ts->gpio_reset = NULL; + return 0; + } + + ts->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (PTR_ERR(ts->gpio_reset) == -EPROBE_DEFER) { + return -EPROBE_DEFER; + } else if (IS_ERR(ts->gpio_reset)) { + err = PTR_ERR(ts->gpio_reset); + dev_err(dev, "unable to request GPIO reset pin (%d)\n", err); + return err; + } + dev_dbg(dev, "got GPIO reset pin\n"); + + return 0; +} + +static const struct of_device_id sx8654_of_match[] = { + { .compatible = "semtech,sx8654", }, + { }, +}; +MODULE_DEVICE_TABLE(of, sx8654_of_match); +#else /* CONFIG_OF */ +static int sx8654_get_ofdata(struct sx8654 *ts) +{ + ts->gpio_reset = NULL; + return 0; +} +#endif /* CONFIG_OF */ + static int sx8654_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -186,10 +248,20 @@ static int sx8654_probe(struct i2c_client *client, if (!sx8654) return -ENOMEM; + sx8654->client = client; + + error = sx8654_get_ofdata(sx8654); + if (error) { + dev_err(&client->dev, "get_ofdata failed: %d\n", error); + return error; + } + input = devm_input_allocate_device(&client->dev); if (!input) return -ENOMEM; + sx8654->input = input; + input->name = "SX8654 I2C Touchscreen"; input->id.bustype = BUS_I2C; input->dev.parent = &client->dev; @@ -201,15 +273,11 @@ static int sx8654_probe(struct i2c_client *client, input_set_abs_params(input, ABS_X, 0, MAX_12BIT, 0, 0); input_set_abs_params(input, ABS_Y, 0, MAX_12BIT, 0, 0); - sx8654->client = client; - sx8654->input = input; - input_set_drvdata(sx8654->input, sx8654); - error = i2c_smbus_write_byte_data(client, I2C_REG_SOFTRESET, - SOFTRESET_VALUE); + error = sx8654_reset(sx8654); if (error) { - dev_err(&client->dev, "writing softreset value failed"); + dev_err(&client->dev, "reset failed"); return error; } @@ -256,14 +324,6 @@ static int sx8654_probe(struct i2c_client *client, return 0; } -#ifdef CONFIG_OF -static const struct of_device_id sx8654_of_match[] = { - { .compatible = "semtech,sx8654", }, - { }, -}; -MODULE_DEVICE_TABLE(of, sx8654_of_match); -#endif - static const struct i2c_device_id sx8654_id_table[] = { { "semtech_sx8654", 0 }, { }, -- 2.11.0