iio: gyro: bmg160: wait full startup time after mode change at probe
PATCH 1/1 iio: gyro: bmg160: wait full startup time after mode change at probe
bmg160_chip_init() calls bmg160_set_mode(BMG160_MODE_NORMAL) and then waits only 500-1000 us. Per the BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013), the start-up and wake-up times (tsu, twusm) are 30 ms.
The same file already waits BMG160_MAX_STARTUP_TIME_MS (80 ms) in bmg160_runtime_resume() after the same set_mode(NORMAL) operation. The 500 us value at probe was likely a unit mix-up; the old comment said "500 ms" while the code used microseconds.
Reuse the same constant via msleep_interruptible() to match the runtime resume path. Without this, register writes that follow the mode change can hit the chip before it is ready.
--- drivers/iio/gyro/bmg160_core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/gyro/bmg160_core.c +1 -2
@@ -258,8 +258,7 @@ static int bmg160_chip_init(struct bmg160_data *data)if (ret <0 )return ret; -/* Wait upto 500 ms to be ready after changing mode */ -usleep_range (500 ,1000 ); +msleep_interruptible (BMG160_MAX_STARTUP_TIME_MS );/* Set Bandwidth */ ret =bmg160_set_bw (data,BMG160_DEF_BW );
Signature · 1 line
2.43.0
Quoted 13 lines · Stepan Ionichev
bmg160_chip_init()callsbmg160_set_mode(BMG160_MODE_NORMAL)and then waits only 500-1000 us. Per the BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013), the start-up and wake-up times (tsu, twusm) are 30 ms.The same file already waits
BMG160_MAX_STARTUP_TIME_MS(80 ms) inbmg160_runtime_resume()after the sameset_mode(NORMAL)operation. The 500 us value at probe was likely a unit mix-up; the old comment said "500 ms" while the code used microseconds.Reuse the same constant via
msleep_interruptible()to match the runtime resume path. Without this, register writes that follow the mode change can hit the chip before it is ready.
...
drivers/iio/gyro/bmg160_core.c static int bmg160_chip_init(struct bmg160_data *data) · line 261
Quoted 1 line
drivers/iio/gyro/bmg160_core.c +0
-1-/* Wait upto 500 ms to be ready after changing mode */
First of all, the same comment, put better description on "why?" based on the datasheet explanation.
drivers/iio/gyro/bmg160_core.c static int bmg160_chip_init(struct bmg160_data *data) · line 261
Quoted 2 lines
drivers/iio/gyro/bmg160_core.c +1
-1-usleep_range (500 ,1000 ); +msleep_interruptible (BMG160_MAX_STARTUP_TIME_MS );
Hmm... This returns an error in case it's aborted by a signal or other means. What are you supposed to do with that?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 1/1 iio: gyro: bmg160: wait full startup time after mode change at probe
In reply to Stepan Ionichevbmg160_chip_init() calls bmg160_set_mode(BMG160_MODE_NORMAL) and then waits only 500-1000 us. Per the BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013), the start-up and wake-up times (tsu, twusm) are 30 ms.
The same file already waits BMG160_MAX_STARTUP_TIME_MS (80 ms) in bmg160_runtime_resume() after the same set_mode(NORMAL) operation. The 500 us value at probe was likely a unit mix-up; the old comment said "500 ms" while the code used microseconds.
Reuse the same constant via msleep() and add a code comment explaining the datasheet basis for the wait. Without this, register writes that follow the mode change can hit the chip before it is ready.
---
v2:
- Use msleep() instead of msleep_interruptible() so the wait is not cut short by signals during probe (per Andy)
- Add a code comment with the datasheet basis for the 80 ms wait (per Andy)
drivers/iio/gyro/bmg160_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/gyro/bmg160_core.c +8 -2
@@ -258,8 +258,14 @@ static int bmg160_chip_init(struct bmg160_data *data)if (ret <0 )return ret; -/* Wait upto 500 ms to be ready after changing mode */ -usleep_range (500 ,1000 ); +/* +* Wait for the chip to be ready after switching to normal mode. +* The BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013) +* specifies a start-up / wake-up time (tsu, twusm) of 30 ms; use +* BMG160_MAX_STARTUP_TIME_MS (80 ms) as a safety margin, matching +* what bmg160_runtime_resume() already does. +*/ +msleep (BMG160_MAX_STARTUP_TIME_MS );/* Set Bandwidth */ ret =bmg160_set_bw (data,BMG160_DEF_BW );
Signature · 1 line
2.43.0
Jonathan Cameron
maintainerQuoted 10 lines · On Mon, 11 May 2026 11:40:20 +0500 Stepan Ionichev <[email protected]> wrote:
bmg160_chip_init()callsbmg160_set_mode(BMG160_MODE_NORMAL)and then waits only 500-1000 us. Per the BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013), the start-up and wake-up times (tsu, twusm) are 30 ms.The same file already waits
BMG160_MAX_STARTUP_TIME_MS(80 ms) inbmg160_runtime_resume()after the sameset_mode(NORMAL)operation. The 500 us value at probe was likely a unit mix-up; the old comment said "500 ms" while the code used microseconds.
Quoted 7 lines
Reuse the same constant via
msleep()and add a code comment explaining the datasheet basis for the wait. Without this, register writes that follow the mode change can hit the chip before it is ready.Fixes 22b46c45fb9b ("iio:gyro:bmg160 Gyro Sensor driver")Signed-off-by Stepan Ionichev <[email protected]>
Some process stuff.
Never send a new version in reply to the older one. Always a fresh thread - the reason is mainly that the threads become unreadable if you got to more than one or two versions.
Also, don't send a new version for a reasonable period of time. Something small like this maybe a few days, a bigger patch 1 week.
That lets multiple reviewers have time to take a look. If you have a lot on list already then slow down in general and spend some time helping to review patches coming from others. The biggest bottleneck in IIO is reviewer time.
Anyhow, I'm going ignore this for a little while at least...
Jonathan
Quoted 31 lines
---
v2:
- Usemsleep()instead ofmsleep_interruptible()so the wait is not cut short by signals during probe (per Andy)
- Add a code comment with the datasheet basis for the 80 ms wait (per Andy)drivers/iio/gyro/bmg160_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/iio/gyro/bmg160_core.c +8
-2@@ -258,8 +258,14 @@ static int bmg160_chip_init(struct bmg160_data *data)if (ret <0 )return ret; -/* Wait upto 500 ms to be ready after changing mode */ -usleep_range (500 ,1000 ); +/* +* Wait for the chip to be ready after switching to normal mode. +* The BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013) +* specifies a start-up / wake-up time (tsu, twusm) of 30 ms; use +* BMG160_MAX_STARTUP_TIME_MS (80 ms) as a safety margin, matching +* what bmg160_runtime_resume() already does. +*/ +msleep (BMG160_MAX_STARTUP_TIME_MS );/* Set Bandwidth */ ret =bmg160_set_bw (data,BMG160_DEF_BW );
Quoted 29 lines · On Mon, 11 May 2026 15:47:04 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 10 lines · On Mon, 11 May 2026 11:40:20 +0500 Stepan Ionichev <[email protected]> wrote:
bmg160_chip_init()callsbmg160_set_mode(BMG160_MODE_NORMAL)and then waits only 500-1000 us. Per the BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013), the start-up and wake-up times (tsu, twusm) are 30 ms.The same file already waits
BMG160_MAX_STARTUP_TIME_MS(80 ms) inbmg160_runtime_resume()after the sameset_mode(NORMAL)operation. The 500 us value at probe was likely a unit mix-up; the old comment said "500 ms" while the code used microseconds.Quoted 7 lines
Reuse the same constant via
msleep()and add a code comment explaining the datasheet basis for the wait. Without this, register writes that follow the mode change can hit the chip before it is ready.Fixes 22b46c45fb9b ("iio:gyro:bmg160 Gyro Sensor driver")Signed-off-by Stepan Ionichev <[email protected]>Some process stuff.
Never send a new version in reply to the older one. Always a fresh thread - the reason is mainly that the threads become unreadable if you got to more than one or two versions.
Also, don't send a new version for a reasonable period of time. Something small like this maybe a few days, a bigger patch 1 week.
Quoted 6 lines
That lets multiple reviewers have time to take a look. If you have a lot on list already then slow down in general and spend some time helping to review patches coming from others. The biggest bottleneck in IIO is reviewer time.
Anyhow, I'm going ignore this for a little while at least...
Applied to the fixes-togreg branch of iio.git and marked for stable.
As fixes go it's pretty safe given it just extends a sleep, so I'll grab it now rather than waiting longer.
Jonathan
Quoted 36 lines
Jonathan
Quoted 31 lines
---
v2:
- Usemsleep()instead ofmsleep_interruptible()so the wait is not cut short by signals during probe (per Andy)
- Add a code comment with the datasheet basis for the 80 ms wait (per Andy)drivers/iio/gyro/bmg160_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/iio/gyro/bmg160_core.c +8
-2@@ -258,8 +258,14 @@ static int bmg160_chip_init(struct bmg160_data *data)if (ret <0 )return ret; -/* Wait upto 500 ms to be ready after changing mode */ -usleep_range (500 ,1000 ); +/* +* Wait for the chip to be ready after switching to normal mode. +* The BMG160 datasheet (BST-BMG160-DS000-07 Rev. 1.0, May 2013) +* specifies a start-up / wake-up time (tsu, twusm) of 30 ms; use +* BMG160_MAX_STARTUP_TIME_MS (80 ms) as a safety margin, matching +* what bmg160_runtime_resume() already does. +*/ +msleep (BMG160_MAX_STARTUP_TIME_MS );/* Set Bandwidth */ ret =bmg160_set_bw (data,BMG160_DEF_BW );