Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5468706imm; Tue, 16 Oct 2018 10:41:31 -0700 (PDT) X-Google-Smtp-Source: ACcGV6208dP9Cfwkm+H9Hu+hs5RbeHVDjbSui9rQQA11AYDZ/wEnk7A/jfF5NjL1apL1WPkjaees X-Received: by 2002:a63:4e4e:: with SMTP id o14-v6mr21579552pgl.181.1539711691049; Tue, 16 Oct 2018 10:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539711691; cv=none; d=google.com; s=arc-20160816; b=Gjw2VoAKLpRpO/ANBYA0SvioRyrsmk/OZ1Jj0RjS0Emm16aLbXUcQrjgBH7NB5XiUN lSr0V5IhBkfNPSp4YEK6aTtFNPoMWuG5Ywb7vH9+QGVDVuubsWbOtQzrPk0vnGhx88M8 ffS2S3iK23brqQemUulzvlpQ2gmgPazF9zS16GNleojGzzGxCA0mfJ3Ym7cdlK58NZAO VYFKbxM1gKmoFexXyrriq1jHuXLGs29Er22qURC73QiVKcVnpOXKl2ieEoI6wgx1v+SU bQScPrU8Bojpq0c+zL7dm8PlneunF/axpXV0RdJ+7gYxFB845ZLOnfjukEI0uW8Z7B9q 5FDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pkuHJt+fSq9QL8V1hOpl+hs5fE2TEWjgqL5N0xigV74=; b=FKhQUjQLznHqKNFyUAUd++GvfktxLpSDZOwjShCisTqkZ7lxtSPNKaJ5/PefEOZUsw 8XD5IMWXrCbeEaKbcMcKl9lc7Cjc947G7AwC2SrbjIg8R8hvK2fa7UyjCOwWVNJWLSpC UNmU0TzLg0qFUsX2AGpwSsgN/+72Iqp6Cf5Ceb5kDGNfD1Vqd82bZncZh8yeWck1nrmx 1coU7ObSXpdarEpU923St5ZyrFtMzmLe7xj9qvLQpGgTG7Fep1VhpcsFI3KBhow32TG9 HbDfGRiiIHio639h0T7/7zVb3OwvCyIq6vw6SCLsCR4lIGjhQ/vRajt4oTGShI50YAsZ 319w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RkUgJd4X; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5-v6si15338868plm.320.2018.10.16.10.41.14; Tue, 16 Oct 2018 10:41:31 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RkUgJd4X; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727433AbeJQBbH (ORCPT + 99 others); Tue, 16 Oct 2018 21:31:07 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38538 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727032AbeJQBbG (ORCPT ); Tue, 16 Oct 2018 21:31:06 -0400 Received: by mail-pl1-f195.google.com with SMTP id q19-v6so8279731pll.5; Tue, 16 Oct 2018 10:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=pkuHJt+fSq9QL8V1hOpl+hs5fE2TEWjgqL5N0xigV74=; b=RkUgJd4XJg+fbzsJ3jcdB+ijVFYunUPqcKyQv18x5R/P0z2thvw0IJK0bnC4ysHOYH ukQ7aGyvvhqvwFcijfyWLq/c0SurAuqz/HSFyZAaR7zE4a+unlXOzUtQkPJyrwqiog59 quiBfqB0a7Cu7VRo6KSLl+4gIhIz7cvr45LlS/lVF+TTxwfPwYa15GLUmpL1cTn6ZZP6 /fr9u44B1pCnZxI7CZAn/ErXcDRJCElNdTCoI9GydGZO++ka5UnhQYPbZfIMK2Ylhhms R+s6yfih+LR1PLZwqHxubqXaLuX0LRSfDZ1339nxQfHULntdt9YMKITP4+vEYm2BfDRP 5S8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=pkuHJt+fSq9QL8V1hOpl+hs5fE2TEWjgqL5N0xigV74=; b=B+HwoAlpr6M/ifiTuRTOJvxnkT2cHdq/5KiDTYJIEuHyvpvQep5F00U7QUkfcHbaB/ WnHmLCJpVd/FuOp3UGSWXXIihQtKdX67PPhAAYlG6QBxFYGx8G8Kt4ge7txco3gP2pH5 7ujSSCPYq98YRcNCQnOsYzbvSpmFVuizUmnReptLspHjK6A7hFQLYN97WJWgS+jsqJON cJwl3h0ibJX96+L4N30myP/urBwHdxF0B69NSsf5Z0mwRfq4wGSvWteVmuSJ1oHgpaMe Y1gNrnASVUPCxClKfppKOiZ3FoadLceCwMtA4QzVaHuSsYv+G3ZzfRNtQ8Ifg6FjVnQe BKuw== X-Gm-Message-State: ABuFfoizjRKYZc9Fxg3P8d6CZ7QRSybXdD/ssTaI7rmExJDo7pXarPdp BLu12U4/CXF8XJtH6IM/cUg= X-Received: by 2002:a17:902:5602:: with SMTP id h2-v6mr22195065pli.220.1539711575330; Tue, 16 Oct 2018 10:39:35 -0700 (PDT) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id a5-v6sm17084663pfo.53.2018.10.16.10.39.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Oct 2018 10:39:34 -0700 (PDT) Date: Tue, 16 Oct 2018 10:39:31 -0700 From: Dmitry Torokhov To: Richard Leitner Cc: robh+dt@kernel.org, mark.rutland@arm.com, linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] Input: sx8654 - add reset-gpio support Message-ID: <20181016173931.GC230131@dtor-ws> References: <20181016091653.26896-1-richard.leitner@skidata.com> <20181016091653.26896-3-richard.leitner@skidata.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181016091653.26896-3-richard.leitner@skidata.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Richard, On Tue, Oct 16, 2018 at 11:16:48AM +0200, Richard Leitner wrote: > 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; Have this in an "else" branch? > + > + 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; > + } There is no need to wrap this into CONFIG_OF or test "node". Just use devm_gpiod_get_optional() and it will work equally well on DT, ACPI, and static board systems. > + > + 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); I'd do: if (err != -EPROBE_DEFER) dev_err(...) here instead of separate branch. > + dev_err(dev, "unable to request GPIO reset pin (%d)\n", err); > + return err; > + } > + dev_dbg(dev, "got GPIO reset pin\n"); Also, I'd move all this code directly into probe() since all this #ifdefery is not needed. > + > + return 0; > +} > + > +static const struct of_device_id sx8654_of_match[] = { > + { .compatible = "semtech,sx8654", }, > + { }, > +}; Please keep the device table wehere it was. > +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; > - Why do we need to move this? > 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 > Thanks. -- Dmitry