Skip to contentSkip to conversation

iio: ltc2983: add support for optional reset gpio

PATCH Superseded Nuno Sá 4 participants 12 messages Aug 20, 2021 – Aug 25, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

PATCH 1/2 iio: ltc2983: add support for optional reset gpio

Check if an optional reset gpio is present and if so, make sure to reset the device.

---
 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/iio/temperature/ltc2983.c +11 -0
index 3b4a0e60e605..37903e9fb90f 100644
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct spi_device *spi)
 {
 	struct ltc2983_data *st;
 	struct iio_dev *indio_dev;
+	struct gpio_desc *gpio;
 	const char *name = spi_get_device_id(spi)->name;
 	int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpio))
+		return PTR_ERR(gpio);
+
+	if (gpio) {
+		/* bring device out of reset */
+		usleep_range(1000, 1005);
+		gpiod_set_value_cansleep(gpio, 0);
+	}
+
 	ret = ltc2983_setup(st, true);
 	if (ret)
 		return ret;
Signature · 1 line
2.33.0
author maintainer
#1 lore raw

PATCH 2/2 iio: ltc2983: fail probe if no channels are given

If there are no channels defined in the devicetree, there's no point in probing the device. We were actually requesting a zero sized 'kmalloc' array but since we were not touching the ZERO_SIZE_PTR afterwards, nothing bad was actually happening. Hence this is not really a fix but rather an improvement.

---
 drivers/iio/temperature/ltc2983.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iio/temperature/ltc2983.c +5 -0
index 37903e9fb90f..7dd2f1dd3685 100644
@@ -1275,6 +1275,11 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
 			     &st->filter_notch_freq);
 
 	st->num_channels = of_get_available_child_count(dev->of_node);
+	if (!st->num_channels) {
+		dev_err(&st->spi->dev, "At least one channel must be given!");
+		return -EINVAL;
+	}
+
 	st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors),
 				   GFP_KERNEL);
 	if (!st->sensors)
Signature · 1 line
2.33.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] iio: ltc2983: fail probe if no channels are given

Quoted 7 lines · Nuno Sá

If there are no channels defined in the devicetree, there's no point in probing the device. We were actually requesting a zero sized 'kmalloc' array but since we were not touching the ZERO_SIZE_PTR afterwards, nothing bad was actually happening. Hence this is not really a fix but rather an improvement.

Quoted 24 lines
---
 drivers/iio/temperature/ltc2983.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iio/temperature/ltc2983.c +5 -1
index 37903e9fb90f..7dd2f1dd3685 100644
@@ -1275,6 +1275,11 @@ static int ltc2983_parse_dt(struct ltc2983_data *st)
                             &st->filter_notch_freq);
 
        st->num_channels = of_get_available_child_count(dev->of_node);
+       if (!st->num_channels) {
+               dev_err(&st->spi->dev, "At least one channel must be given!");
+               return -EINVAL;
+       }
+
        st->sensors = devm_kcalloc(dev, st->num_channels, sizeof(*st->sensors),
                                   GFP_KERNEL);
        if (!st->sensors)
--

2.33.0

#3 lore raw
In reply to Nuno Sá
Quoted 4 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to reset the device.

Just one note/question inline.

Quoted 19 lines
---
 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/iio/temperature/ltc2983.c +1 -0
index 3b4a0e60e605..37903e9fb90f 100644
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct spi_device *spi)
 {
        struct ltc2983_data *st;
        struct iio_dev *indio_dev;
+       struct gpio_desc *gpio;
        const char *name = spi_get_device_id(spi)->name;
        int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct spi_device *spi)
        if (ret)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi) · line 1505

Quoted 10 lines
drivers/iio/temperature/ltc2983.c +8 -0
                return ret;
 
+       gpio = devm_gpiod_get_optional(&st->spi->dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(gpio))
+               return PTR_ERR(gpio);
+
+       if (gpio) {
+               /* bring device out of reset */
+               usleep_range(1000, 1005);
+               gpiod_set_value_cansleep(gpio, 0);

Datasheet mentions that it takes up to 100 ms for the device to fully start-up. It also mentions that the (command) status register will be unavailable to the user before this point.
Page 16, Conversion State Details section, second paragraph.

I think there should probably be a sleep here of 100 ms.

Other than that change looks good.

Quoted 8 lines
drivers/iio/temperature/ltc2983.c +2 -1
+       }
+
        ret = ltc2983_setup(st, true);
        if (ret)
                return ret;
--

2.33.0

author maintainer
#4 lore raw
Quoted 64 lines

-----Original Message-----
From: Alexandru Ardelean <[email protected]>
Sent: Friday, August 20, 2021 10:21 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Drew Fustini <[email protected]>
Subject: Re: [PATCH 1/2] iio: ltc2983: add support for optional reset gpio

[External]

Quoted 2 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to

reset

Quoted 2 lines

the device.

Just one note/question inline.

Review

Quoted 6 lines
---
 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
(quoted diff) +0 -0

b/drivers/iio/temperature/ltc2983.c

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device

Quoted 4 lines

index 3b4a0e60e605..37903e9fb90f 100644

drivers/iio/temperature/ltc2983.c +0 -0
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct spi_device

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device

Quoted 8 lines
drivers/iio/temperature/ltc2983.c +1 -0
 {
        struct ltc2983_data *st;
        struct iio_dev *indio_dev;
+       struct gpio_desc *gpio;
        const char *name = spi_get_device_id(spi)->name;
        int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct spi_device

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi)

Quoted 4 lines
drivers/iio/temperature/ltc2983.c +1 -0
        if (ret)
                return ret;
 
+       gpio = devm_gpiod_get_optional(&st->spi->dev, "reset",

GPIOD_OUT_HIGH);

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi) · line 1505

Quoted 7 lines
drivers/iio/temperature/ltc2983.c +7 -0
+       if (IS_ERR(gpio))
+               return PTR_ERR(gpio);
+
+       if (gpio) {
+               /* bring device out of reset */
+               usleep_range(1000, 1005);
+               gpiod_set_value_cansleep(gpio, 0);

Datasheet mentions that it takes up to 100 ms for the device to fully start-up.
It also mentions that the (command) status register will be unavailable to the user before this point.
Page 16, Conversion State Details section, second paragraph.

Quoted 4 lines

I think there should probably be a sleep here of 100 ms.

Other than that change looks good.

In the setup function we do a polled read on the status register until we get the indication we are up. This was actually a fix sent recently [1].

[1]: https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/
- Nuno Sá

Quoted 8 lines
Quoted 8 lines
drivers/iio/temperature/ltc2983.c +2 -1
+       }
+
        ret = ltc2983_setup(st, true);
        if (ret)
                return ret;
--

2.33.0

#5 lore raw
Quoted 65 lines · Nuno
Quoted 65 lines

-----Original Message-----
From: Alexandru Ardelean <[email protected]>
Sent: Friday, August 20, 2021 10:21 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Drew Fustini <[email protected]>
Subject: Re: [PATCH 1/2] iio: ltc2983: add support for optional reset gpio

[External]

Quoted 2 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to

reset

Quoted 2 lines

the device.

Just one note/question inline.

Review

Quoted 6 lines
---
 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
(quoted diff) +0 -0

b/drivers/iio/temperature/ltc2983.c

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device

Quoted 4 lines

index 3b4a0e60e605..37903e9fb90f 100644

drivers/iio/temperature/ltc2983.c +0 -0
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct spi_device

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device

Quoted 8 lines
drivers/iio/temperature/ltc2983.c +1 -0
 {
        struct ltc2983_data *st;
        struct iio_dev *indio_dev;
+       struct gpio_desc *gpio;
        const char *name = spi_get_device_id(spi)->name;
        int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct spi_device

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi)

Quoted 4 lines
drivers/iio/temperature/ltc2983.c +1 -0
        if (ret)
                return ret;
 
+       gpio = devm_gpiod_get_optional(&st->spi->dev, "reset",

GPIOD_OUT_HIGH);

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi) · line 1505

Quoted 7 lines
drivers/iio/temperature/ltc2983.c +7 -0
+       if (IS_ERR(gpio))
+               return PTR_ERR(gpio);
+
+       if (gpio) {
+               /* bring device out of reset */
+               usleep_range(1000, 1005);
+               gpiod_set_value_cansleep(gpio, 0);

Datasheet mentions that it takes up to 100 ms for the device to fully start-up.
It also mentions that the (command) status register will be unavailable to the user before this point.
Page 16, Conversion State Details section, second paragraph.

Quoted 9 lines
Quoted 4 lines

I think there should probably be a sleep here of 100 ms.

Other than that change looks good.

In the setup function we do a polled read on the status register until we get the indication we are up. This was actually a fix sent recently [1].

Yes, I saw that.
But I did not have energy to look at it too in-depth [at that moment in time]. Apologies.

But the question is: is the statement on page 16 valid?
i.e. do we need to wait 100ms after the reset pin goes low? because it states:

In the first phase of the start-up state all critical analog circuits are powered up.
This includes the LDO, reference, charge pump and ADCs. ***During this first phase, the com-mand status register will be inaccessible to the user.***
***This phase takes a maximum of 100mS to complete. *** Once this phase completes, the command status register will be accessible and return
a value of 0x80 until the LTC2983 is completely initialized.

Quoted 11 lines

[1]: https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/
- Nuno Sá

Quoted 8 lines
Quoted 8 lines
drivers/iio/temperature/ltc2983.c +2 -1
+       }
+
        ret = ltc2983_setup(st, true);
        if (ret)
                return ret;
--

2.33.0

author maintainer
#6 lore raw
Quoted 101 lines

-----Original Message-----
From: Alexandru Ardelean <[email protected]>
Sent: Friday, August 20, 2021 8:59 PM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Drew Fustini <[email protected]>
Subject: Re: [PATCH 1/2] iio: ltc2983: add support for optional reset gpio

Quoted 30 lines · Nuno
Quoted 30 lines

-----Original Message-----
From: Alexandru Ardelean <[email protected]>
Sent: Friday, August 20, 2021 10:21 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Drew Fustini <[email protected]>
Subject: Re: [PATCH 1/2] iio: ltc2983: add support for optional reset gpio

[External]

Quoted 2 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to

reset

Quoted 2 lines

the device.

Just one note/question inline.

Quoted 5 lines
---
 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/iio/temperature/ltc2983.c

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct

Quoted 4 lines

index 3b4a0e60e605..37903e9fb90f 100644

drivers/iio/temperature/ltc2983.c +0 -0
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct

spi_device

Quoted 9 lines
Quoted 9 lines

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct

Quoted 8 lines
drivers/iio/temperature/ltc2983.c +1 -0
 {
        struct ltc2983_data *st;
        struct iio_dev *indio_dev;
+       struct gpio_desc *gpio;
        const char *name = spi_get_device_id(spi)->name;
        int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct

spi_device

Quoted 14 lines
Quoted 14 lines

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi)

Quoted 4 lines
drivers/iio/temperature/ltc2983.c +1 -0
        if (ret)
                return ret;
 
+       gpio = devm_gpiod_get_optional(&st->spi->dev, "reset",

GPIOD_OUT_HIGH);

Quoted 7 lines
drivers/iio/temperature/ltc2983.c +7 -0
+       if (IS_ERR(gpio))
+               return PTR_ERR(gpio);
+
+       if (gpio) {
+               /* bring device out of reset */
+               usleep_range(1000, 1005);
+               gpiod_set_value_cansleep(gpio, 0);
Quoted 1 line
Quoted 1 line

Datasheet mentions that it takes up to 100 ms for the device to

fully

Quoted 5 lines
Quoted 5 lines

start-up.
It also mentions that the (command) status register will be unavailable to the user before this point.
Page 16, Conversion State Details section, second paragraph.

Quoted 9 lines
Quoted 4 lines

I think there should probably be a sleep here of 100 ms.

Other than that change looks good.

In the setup function we do a polled read on the status register until we get the indication we are up. This was actually a fix sent recently [1].

Yes, I saw that.
But I did not have energy to look at it too in-depth [at that moment in time].
Apologies.

But the question is: is the statement on page 16 valid? i.e. do we need to wait 100ms after the reset pin goes low? because it states:

Quoted 9 lines

In the first phase of the start-up state all critical analog circuits are powered up.
This includes the LDO, reference, charge pump and ADCs. ***During this first phase, the com-mand status register will be inaccessible to the user.***
***This phase takes a maximum of 100mS to complete. *** Once this phase completes, the command status register will be accessible and return
a value of 0x80 until the LTC2983 is completely initialized.

Yes, I saw that on the datasheet. My interpretation is that the status register is just not available so we just get 0x00 or 0xff (whatever the default state of the SDO line). In my tests, it took 3 iterations to acknowledge the device as up. Reading 0x00, 0x80 and 0x40...

Being this said, let's see if someone else has something to say about this. I'm more than fine in adding the 100ms as I also wondered about this to be honest.

- Nuno Sá

author maintainer
#7 lore raw
Quoted 133 lines

From: Sa, Nuno <[email protected]>
Sent: Monday, August 23, 2021 9:05 AM
To: Alexandru Ardelean <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Drew Fustini <[email protected]>
Subject: RE: [PATCH 1/2] iio: ltc2983: add support for optional reset gpio

[External]

Quoted 10 lines

-----Original Message-----
From: Alexandru Ardelean <[email protected]>
Sent: Friday, August 20, 2021 8:59 PM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>; Drew Fustini <[email protected]>
Subject: Re: [PATCH 1/2] iio: ltc2983: add support for optional reset gpio

Quoted 11 lines
Quoted 9 lines · Nuno
Quoted 9 lines

-----Original Message-----
From: Alexandru Ardelean <[email protected]>
Sent: Friday, August 20, 2021 10:21 AM
To: Sa, Nuno <[email protected]>
Cc: linux-iio <[email protected]>; Jonathan Cameron <[email protected]>; Lars-Peter Clausen <[email protected]>;

Drew

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Fustini <[email protected]>
Subject: Re: [PATCH 1/2] iio: ltc2983: add support for optional

reset

Quoted 50 lines
Quoted 19 lines
Quoted 19 lines

gpio

[External]

Quoted 2 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to

reset

Quoted 2 lines

the device.

Just one note/question inline.

Quoted 5 lines
---
 drivers/iio/temperature/ltc2983.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/iio/temperature/ltc2983.c

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct

Quoted 4 lines

index 3b4a0e60e605..37903e9fb90f 100644

drivers/iio/temperature/ltc2983.c +0 -0
@@ -1470,6 +1470,7 @@ static int ltc2983_probe(struct

spi_device

Quoted 9 lines
Quoted 9 lines

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct

Quoted 8 lines
drivers/iio/temperature/ltc2983.c +1 -0
 {
        struct ltc2983_data *st;
        struct iio_dev *indio_dev;
+       struct gpio_desc *gpio;
        const char *name = spi_get_device_id(spi)->name;
        int ret;
 
@@ -1494,6 +1495,16 @@ static int ltc2983_probe(struct

spi_device

Quoted 14 lines
Quoted 14 lines

*spi)

drivers/iio/temperature/ltc2983.c static int ltc2983_probe(struct spi_device *spi)

Quoted 4 lines
drivers/iio/temperature/ltc2983.c +1 -0
        if (ret)
                return ret;
 
+       gpio = devm_gpiod_get_optional(&st->spi->dev, "reset",

GPIOD_OUT_HIGH);

Quoted 7 lines
drivers/iio/temperature/ltc2983.c +7 -0
+       if (IS_ERR(gpio))
+               return PTR_ERR(gpio);
+
+       if (gpio) {
+               /* bring device out of reset */
+               usleep_range(1000, 1005);
+               gpiod_set_value_cansleep(gpio, 0);
Quoted 13 lines
Quoted 1 line
Quoted 1 line

Datasheet mentions that it takes up to 100 ms for the device to

fully

Quoted 11 lines
Quoted 9 lines

start-up.
It also mentions that the (command) status register will be unavailable to the user before this point.
Page 16, Conversion State Details section, second paragraph.

I think there should probably be a sleep here of 100 ms.

Other than that change looks good.

In the setup function we do a polled read on the status register

until

Quoted 6 lines
Quoted 3 lines

we get the indication we are up. This was actually a fix sent recently [1].

Yes, I saw that.
But I did not have energy to look at it too in-depth [at that moment

in

Quoted 5 lines

time].
Apologies.

But the question is: is the statement on page 16 valid? i.e. do we need to wait 100ms after the reset pin goes low? because

it

Quoted 11 lines

states:

In the first phase of the start-up state all critical analog circuits are powered up.
This includes the LDO, reference, charge pump and ADCs. ***During this first phase, the com-mand status register will be inaccessible to the user.***
***This phase takes a maximum of 100mS to complete. *** Once this phase completes, the command status register will be accessible and return
a value of 0x80 until the LTC2983 is completely initialized.

Yes, I saw that on the datasheet. My interpretation is that the status register is just not available so we just get 0x00 or 0xff (whatever the default state of the SDO line). In my tests, it took 3 iterations to acknowledge
the device as up. Reading 0x00, 0x80 and 0x40...

Quoted 5 lines

Being this said, let's see if someone else has something to say about this.
I'm more than fine in adding the 100ms as I also wondered about this to
be honest.

So, I did consulted internally about this and the status register is 0 initialized during the initial powert-up state which means we don't really have to wait 100ms here....

Anyways, I will still send a v2 with a improved range for 'usleep_range()'.

- Nuno Sá

#8 lore raw
In reply to Nuno Sá
Quoted 3 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to reset the device.

...

Quoted 1 line

+ usleep_range(1000, 1005);

The delta should be at least 20%, otherwise I'm not sure why such a strict range?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to reset
the device.

Quoted 7 lines

...

Quoted 1 line

+ usleep_range(1000, 1005);

The delta should be at least 20%, otherwise I'm not sure why such a strict range?

No special reason... I just had no hard requirement for delta so I just gave something small. Is 20% documented anywhere? I did a quick look on the API's and I could not find nothing related. Anyways, if that is a best practise for being more power friendly I'm happy to change it... (well, we might end up just having 100ms here which means 'msleep()').

- Nuno Sá

#10 lore raw
Quoted 8 lines · Nuno Sá
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to reset
the device.

...

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

+ usleep_range(1000, 1005);

The delta should be at least 20%, otherwise I'm not sure why such a strict range?

No special reason... I just had no hard requirement for delta so I just gave something small. Is 20% documented anywhere?

Quick search shows nothing, but I remember I saw it somewhere. So, the explanation is empirical, because the idea behind is to allow less HRT interrupts. When you do a tough margin, you may generate too many interrupts from the timer. So, 20% seems like a good balance for most of the values.

The parameters to take into account are:
- minimum (or maybe rather median?) CPU frequency the code will be run on
- minimal sleep (for small sleeps even better to have udelay() as I
believe documented in timers.rst, for bigger sleeps, like 10ms the margin can be 10% or so)
- NO_HZ kernel configuration
- etc (if anything I forgot)

Quoted 4 lines

I did a quick look on
the API's and I could not find nothing related. Anyways, if that is a best practise for being more power friendly I'm happy to change it... (well, we might end up just having 100ms here which means 'msleep()').

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw
Quoted 23 lines · Andy Shevchenko
Quoted 12 lines · Nuno Sá
Quoted 11 lines · Andy Shevchenko
Quoted 4 lines · Nuno Sá

Check if an optional reset gpio is present and if so, make sure to
reset
the device.

...

Quoted 1 line

+ usleep_range(1000, 1005);

Quoted 8 lines
Quoted 4 lines

The delta should be at least 20%, otherwise I'm not sure why such a
strict range?

No special reason... I just had no hard requirement for delta so I just
gave something small. Is 20% documented anywhere?

Quoted 6 lines

Quick search shows nothing, but I remember I saw it somewhere. So, the explanation is empirical, because the idea behind is to allow less HRT interrupts. When you do a tough margin, you may generate too many interrupts from the timer. So, 20% seems like a good balance for most of the values.

I see, that makes sense to me.

Quoted 6 lines

The parameters to take into account are:
- minimum (or maybe rather median?) CPU frequency the code will be
run on
- minimal sleep (for small sleeps even better to have udelay() as I
believe documented in timers.rst, for bigger sleeps, like 10ms the margin can be 10% or so)

udelay() would be for sleeps < 10us

- Nuno Sá