linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Leitner <richard.leitner@skidata.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: <robh+dt@kernel.org>, <mark.rutland@arm.com>,
	<linux-input@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Richard Leitner <richard.leitner@skidata.com>
Subject: Re: [PATCH 2/7] Input: sx8654 - add reset-gpio support
Date: Tue, 16 Oct 2018 21:32:41 +0200	[thread overview]
Message-ID: <8d5ea869-0d92-aef0-1d27-bb5ecf5ba0af@skidata.com> (raw)
In-Reply-To: <20181016173931.GC230131@dtor-ws>

Hi Dimitry,
thanks for the quick reply!

On 10/16/18 7:39 PM, Dmitry Torokhov wrote:
> 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.
>>

...

>> +
>> +	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?

If that's the preferred way... of course.

> 
>> +
>> +	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.

Ok. Thank you for that information!
I haven't been aware of this before :-)

> 
>> +
>> +	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.

Indeed... Looks like a more sexy solution. Thanks.

> 
>> +		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.

Without the #ifdef'ery and node checking this sounds reasonable.

> 
>> +
>> +	return 0;
>> +}
>> +
>> +static const struct of_device_id sx8654_of_match[] = {
>> +	{ .compatible = "semtech,sx8654", },
>> +	{ },
>> +};
> 
> Please keep the device table wehere it was.

OK.

>> @@ -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?

This was because sx8654_get_ofdata needed ts->client->dev.
But as I will integrate the reset gpio getting in the probe function 
I'll move it back.

...

> 
> Thanks.
> 

I'll send a v2 of the series as soon as I have fixed the other patches.

regards;Richard.L

  reply	other threads:[~2018-10-16 19:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16  9:16 [PATCH 0/7] Input: sx8654 - reset-gpio, sx865[056] support, etc Richard Leitner
2018-10-16  9:16 ` [PATCH 1/7] dt-bindings: input: touchscreen: sx8654: add reset-gpio property Richard Leitner
2018-10-16  9:16 ` [PATCH 2/7] Input: sx8654 - add reset-gpio support Richard Leitner
2018-10-16 17:39   ` Dmitry Torokhov
2018-10-16 19:32     ` Richard Leitner [this message]
2018-10-16  9:16 ` [PATCH 3/7] dt-bindings: input: touchscreen: sx8654: add compatible models Richard Leitner
2018-10-16  9:16 ` [PATCH 4/7] Input: sx8654 - add sx8655 and sx8656 to compatibles Richard Leitner
2018-10-16  9:22 ` [PATCH 5/7] dt-bindings: input: touchscreen: sx8654: add sx8650 to comatibles Richard Leitner
2018-10-16  9:22 ` [PATCH 6/7] Input: sx8654 - add sx8650 support Richard Leitner
2018-10-16 17:48   ` Dmitry Torokhov
2018-10-16 19:34     ` Richard Leitner
2018-10-16 20:18       ` Dmitry Torokhov
2018-10-16  9:23 ` [PATCH 7/7] Input: sx8654 - use common of_touchscreen functions Richard Leitner
2018-10-16 17:52   ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d5ea869-0d92-aef0-1d27-bb5ecf5ba0af@skidata.com \
    --to=richard.leitner@skidata.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).