public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] iio: light: stk3310: Fix PS interrupt after suspend and clean up code style
@ 2026-05-04  3:04 Miao Li
  2026-05-04  3:04 ` [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM Miao Li
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Miao Li @ 2026-05-04  3:04 UTC (permalink / raw)
  To: jic23
  Cc: dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19, linux-iio,
	linux-kernel, limiao870622, Miao Li

From: Miao Li <limiao@kylinos.cn>

This patch series addresses an interrupt issue and does two code cleanups
for the stk3310 driver.

Patch 1 fixes a PS interrupt issue where the interrupt cannot be triggered
normally after waking from suspend/hibernation, discovered on the Inspur
HS326 laptop with HiSilicon M900 processor.

Patch 2 replaces uint32_t with u32 and reorders members of struct
stk3310_data to eliminate memory padding holes, improving code
consistency and efficiency.

Patch 3 replaces hardcoded count parameters with sizeof(buf) in
regmap_bulk_read/write calls to improve code maintainability.

Miao Li (3):
  iio: light: stk3310: Deal with the ps interrupt issue in PM
  iio: light: stk3310: Replace uint32_t with u32 and reorder members to
    eliminate padding
  iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count
    parameter

 drivers/iio/light/stk3310.c | 84 ++++++++++++++++++++++++++++++++-----
 1 file changed, 73 insertions(+), 11 deletions(-)

Best regards.
-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM
  2026-05-04  3:04 [PATCH v4 0/3] iio: light: stk3310: Fix PS interrupt after suspend and clean up code style Miao Li
@ 2026-05-04  3:04 ` Miao Li
  2026-05-04 15:34   ` Jonathan Cameron
  2026-05-05  6:53   ` Andy Shevchenko
  2026-05-04  3:04 ` [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding Miao Li
  2026-05-04  3:04 ` [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter Miao Li
  2 siblings, 2 replies; 11+ messages in thread
From: Miao Li @ 2026-05-04  3:04 UTC (permalink / raw)
  To: jic23
  Cc: dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19, linux-iio,
	linux-kernel, limiao870622, Miao Li

From: Miao Li <limiao@kylinos.cn>

On the Inspur HS326 laptop(which integrated with HiSilicon M900
processor), if the STK3311-X chip's PS interrupt is configured
in "Recommended interrupt mode", the interrupt cannot be triggered
normally after waking from suspend or hibernation.

In this case, neither disabling and re-enabling the interrupt nor
resetting the PS threshold register can restore the interrupt to
normal operation.

If the interrupt is disabled in suspend() then reset the PS threshold
register and enable the interrupt in resume(). This resolves the issue.

Signed-off-by: Miao Li <limiao@kylinos.cn>
---
 drivers/iio/light/stk3310.c | 72 ++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index a75a83594..86cc6e8ec 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -117,6 +117,9 @@ struct stk3310_data {
 	struct mutex lock;
 	bool als_enabled;
 	bool ps_enabled;
+	bool ps_int_enabled;
+	uint32_t ps_thdl;
+	uint32_t ps_thdh;
 	uint32_t ps_near_level;
 	u64 timestamp;
 	struct regmap *regmap;
@@ -296,8 +299,15 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
 
 	buf = cpu_to_be16(val);
 	ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&client->dev, "failed to set PS threshold!\n");
+		return ret;
+	}
+
+	if (reg == STK3310_REG_THDH_PS)
+		data->ps_thdh = val;
+	else
+		data->ps_thdl = val;
 
 	return ret;
 }
@@ -331,8 +341,14 @@ static int stk3310_write_event_config(struct iio_dev *indio_dev,
 	/* Set INT_PS value */
 	mutex_lock(&data->lock);
 	ret = regmap_field_write(data->reg_int_ps, state);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&client->dev, "failed to set interrupt mode\n");
+		mutex_unlock(&data->lock);
+		return ret;
+	}
+
+	data->ps_int_enabled = state;
+
 	mutex_unlock(&data->lock);
 
 	return ret;
@@ -504,10 +520,15 @@ static int stk3310_init(struct iio_dev *indio_dev)
 
 	/* Enable PS interrupts */
 	ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&client->dev, "failed to enable interrupts!\n");
+		return ret;
+	}
 
-	return ret;
+	data->ps_int_enabled = true;
+	data->ps_thdh = STK3310_PS_MAX_VAL;
+
+	return 0;
 }
 
 static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg)
@@ -671,9 +692,18 @@ static void stk3310_remove(struct i2c_client *client)
 static int stk3310_suspend(struct device *dev)
 {
 	struct stk3310_data *data;
+	int ret;
 
 	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
 
+	if (data->ps_int_enabled) {
+		ret = regmap_field_write(data->reg_int_ps, 0x0);
+		if (ret < 0) {
+			dev_err(dev, "failed to disable ps int at suspend.\n");
+			return ret;
+		}
+	}
+
 	return stk3310_set_state(data, STK3310_STATE_STANDBY);
 }
 
@@ -681,6 +711,8 @@ static int stk3310_resume(struct device *dev)
 {
 	u8 state = 0;
 	struct stk3310_data *data;
+	__be16 buf;
+	int ret;
 
 	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
 	if (data->ps_enabled)
@@ -688,7 +720,37 @@ static int stk3310_resume(struct device *dev)
 	if (data->als_enabled)
 		state |= STK3310_STATE_EN_ALS;
 
-	return stk3310_set_state(data, state);
+	ret = stk3310_set_state(data, state);
+	if (ret < 0)
+		return ret;
+
+	if (data->ps_thdl != 0x0) {
+		buf = cpu_to_be16(data->ps_thdl);
+		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDL_PS, &buf, 2);
+		if (ret < 0) {
+			dev_err(dev, "failed to set reg THDL_PS at resume.\n");
+			return ret;
+		}
+	}
+
+	if (data->ps_thdh != STK3310_PS_MAX_VAL) {
+		buf = cpu_to_be16(data->ps_thdh);
+		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDH_PS, &buf, 2);
+		if (ret < 0) {
+			dev_err(dev, "failed to set reg THDH_PS at resume.\n");
+			return ret;
+		}
+	}
+
+	if (data->ps_int_enabled) {
+		ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN);
+		if (ret < 0) {
+			dev_err(dev, "failed to enable ps int at resume.\n");
+			return ret;
+		}
+	}
+
+	return 0;
 }
 
 static DEFINE_SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding
  2026-05-04  3:04 [PATCH v4 0/3] iio: light: stk3310: Fix PS interrupt after suspend and clean up code style Miao Li
  2026-05-04  3:04 ` [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM Miao Li
@ 2026-05-04  3:04 ` Miao Li
  2026-05-04  8:19   ` Joshua Crofts
  2026-05-05  6:51   ` Andy Shevchenko
  2026-05-04  3:04 ` [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter Miao Li
  2 siblings, 2 replies; 11+ messages in thread
From: Miao Li @ 2026-05-04  3:04 UTC (permalink / raw)
  To: jic23
  Cc: dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19, linux-iio,
	linux-kernel, limiao870622, Miao Li, Andy Shevchenko

From: Miao Li <limiao@kylinos.cn>

Replace the uint32_t type members in the stk3310_data structure with u32
to adhere to the unified kernel coding style, and reorder the member
variables to eliminate memory padding holes.

Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Miao Li <limiao@kylinos.cn>
---
 drivers/iio/light/stk3310.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index 86cc6e8ec..0447fbf1b 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -115,12 +115,6 @@ static const int stk3310_it_table[][2] = {
 struct stk3310_data {
 	struct i2c_client *client;
 	struct mutex lock;
-	bool als_enabled;
-	bool ps_enabled;
-	bool ps_int_enabled;
-	uint32_t ps_thdl;
-	uint32_t ps_thdh;
-	uint32_t ps_near_level;
 	u64 timestamp;
 	struct regmap *regmap;
 	struct regmap_field *reg_state;
@@ -131,6 +125,12 @@ struct stk3310_data {
 	struct regmap_field *reg_int_ps;
 	struct regmap_field *reg_flag_psint;
 	struct regmap_field *reg_flag_nf;
+	u32 ps_thdl;
+	u32 ps_thdh;
+	u32 ps_near_level;
+	bool als_enabled;
+	bool ps_enabled;
+	bool ps_int_enabled;
 };
 
 static const struct iio_event_spec stk3310_events[] = {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter
  2026-05-04  3:04 [PATCH v4 0/3] iio: light: stk3310: Fix PS interrupt after suspend and clean up code style Miao Li
  2026-05-04  3:04 ` [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM Miao Li
  2026-05-04  3:04 ` [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding Miao Li
@ 2026-05-04  3:04 ` Miao Li
  2026-05-04  7:11   ` Joshua Crofts
  2026-05-05  6:49   ` Andy Shevchenko
  2 siblings, 2 replies; 11+ messages in thread
From: Miao Li @ 2026-05-04  3:04 UTC (permalink / raw)
  To: jic23
  Cc: dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19, linux-iio,
	linux-kernel, limiao870622, Miao Li

From: Miao Li <limiao@kylinos.cn>

Convert the hardcoded count parameter to sizeof(buf) for all
regmap_bulk_write() and regmap_bulk_read() calls in this driver
to improve code maintainability. For details, see [1].

[1] https://lore.kernel.org/all/20260428192213.7c5c80e5@jic23-huawei/

Signed-off-by: Miao Li <limiao@kylinos.cn>
---
 drivers/iio/light/stk3310.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
index 0447fbf1b..74ee75721 100644
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -258,7 +258,7 @@ static int stk3310_read_event(struct iio_dev *indio_dev,
 		return -EINVAL;
 
 	mutex_lock(&data->lock);
-	ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
+	ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf));
 	mutex_unlock(&data->lock);
 	if (ret < 0) {
 		dev_err(&data->client->dev, "register read failed\n");
@@ -298,7 +298,7 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
 		return -EINVAL;
 
 	buf = cpu_to_be16(val);
-	ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
+	ret = regmap_bulk_write(data->regmap, reg, &buf, sizeof(buf));
 	if (ret < 0) {
 		dev_err(&client->dev, "failed to set PS threshold!\n");
 		return ret;
@@ -376,7 +376,7 @@ static int stk3310_read_raw(struct iio_dev *indio_dev,
 			reg = STK3310_REG_PS_DATA_MSB;
 
 		mutex_lock(&data->lock);
-		ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
+		ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf));
 		if (ret < 0) {
 			dev_err(&client->dev, "register read failed\n");
 			mutex_unlock(&data->lock);
@@ -726,7 +726,7 @@ static int stk3310_resume(struct device *dev)
 
 	if (data->ps_thdl != 0x0) {
 		buf = cpu_to_be16(data->ps_thdl);
-		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDL_PS, &buf, 2);
+		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDL_PS, &buf, sizeof(buf));
 		if (ret < 0) {
 			dev_err(dev, "failed to set reg THDL_PS at resume.\n");
 			return ret;
@@ -735,7 +735,7 @@ static int stk3310_resume(struct device *dev)
 
 	if (data->ps_thdh != STK3310_PS_MAX_VAL) {
 		buf = cpu_to_be16(data->ps_thdh);
-		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDH_PS, &buf, 2);
+		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDH_PS, &buf, sizeof(buf));
 		if (ret < 0) {
 			dev_err(dev, "failed to set reg THDH_PS at resume.\n");
 			return ret;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter
  2026-05-04  3:04 ` [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter Miao Li
@ 2026-05-04  7:11   ` Joshua Crofts
  2026-05-05  6:49   ` Andy Shevchenko
  1 sibling, 0 replies; 11+ messages in thread
From: Joshua Crofts @ 2026-05-04  7:11 UTC (permalink / raw)
  To: Miao Li
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19,
	linux-iio, linux-kernel, Miao Li

On Mon, 4 May 2026 at 05:05, Miao Li <limiao870622@163.com> wrote:
>
> From: Miao Li <limiao@kylinos.cn>
>
> Convert the hardcoded count parameter to sizeof(buf) for all
> regmap_bulk_write() and regmap_bulk_read() calls in this driver
> to improve code maintainability. For details, see [1].
>
> [1] https://lore.kernel.org/all/20260428192213.7c5c80e5@jic23-huawei/
>
> Signed-off-by: Miao Li <limiao@kylinos.cn>
> ---
>  drivers/iio/light/stk3310.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
> index 0447fbf1b..74ee75721 100644
> --- a/drivers/iio/light/stk3310.c
> +++ b/drivers/iio/light/stk3310.c
> @@ -258,7 +258,7 @@ static int stk3310_read_event(struct iio_dev *indio_dev,
>                 return -EINVAL;
>
>         mutex_lock(&data->lock);
> -       ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
> +       ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf));
>         mutex_unlock(&data->lock);
>         if (ret < 0) {
>                 dev_err(&data->client->dev, "register read failed\n");
> @@ -298,7 +298,7 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
>                 return -EINVAL;
>
>         buf = cpu_to_be16(val);
> -       ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
> +       ret = regmap_bulk_write(data->regmap, reg, &buf, sizeof(buf));
>         if (ret < 0) {
>                 dev_err(&client->dev, "failed to set PS threshold!\n");
>                 return ret;
> @@ -376,7 +376,7 @@ static int stk3310_read_raw(struct iio_dev *indio_dev,
>                         reg = STK3310_REG_PS_DATA_MSB;
>
>                 mutex_lock(&data->lock);
> -               ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
> +               ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf));
>                 if (ret < 0) {
>                         dev_err(&client->dev, "register read failed\n");
>                         mutex_unlock(&data->lock);
> @@ -726,7 +726,7 @@ static int stk3310_resume(struct device *dev)
>
>         if (data->ps_thdl != 0x0) {
>                 buf = cpu_to_be16(data->ps_thdl);
> -               ret = regmap_bulk_write(data->regmap, STK3310_REG_THDL_PS, &buf, 2);
> +               ret = regmap_bulk_write(data->regmap, STK3310_REG_THDL_PS, &buf, sizeof(buf));
>                 if (ret < 0) {
>                         dev_err(dev, "failed to set reg THDL_PS at resume.\n");
>                         return ret;
> @@ -735,7 +735,7 @@ static int stk3310_resume(struct device *dev)
>
>         if (data->ps_thdh != STK3310_PS_MAX_VAL) {
>                 buf = cpu_to_be16(data->ps_thdh);
> -               ret = regmap_bulk_write(data->regmap, STK3310_REG_THDH_PS, &buf, 2);
> +               ret = regmap_bulk_write(data->regmap, STK3310_REG_THDH_PS, &buf, sizeof(buf));
>                 if (ret < 0) {
>                         dev_err(dev, "failed to set reg THDH_PS at resume.\n");
>                         return ret;
> --
> 2.25.1
>
>

LGTM.

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards

CJD

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding
  2026-05-04  3:04 ` [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding Miao Li
@ 2026-05-04  8:19   ` Joshua Crofts
  2026-05-05  6:51   ` Andy Shevchenko
  1 sibling, 0 replies; 11+ messages in thread
From: Joshua Crofts @ 2026-05-04  8:19 UTC (permalink / raw)
  To: Miao Li
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19,
	linux-iio, linux-kernel, Miao Li, Andy Shevchenko

On Mon, 4 May 2026 at 05:05, Miao Li <limiao870622@163.com> wrote:
>
> From: Miao Li <limiao@kylinos.cn>
>
> Replace the uint32_t type members in the stk3310_data structure with u32
> to adhere to the unified kernel coding style, and reorder the member
> variables to eliminate memory padding holes.
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Miao Li <limiao@kylinos.cn>
> ---
>  drivers/iio/light/stk3310.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
> index 86cc6e8ec..0447fbf1b 100644
> --- a/drivers/iio/light/stk3310.c
> +++ b/drivers/iio/light/stk3310.c
> @@ -115,12 +115,6 @@ static const int stk3310_it_table[][2] = {
>  struct stk3310_data {
>         struct i2c_client *client;
>         struct mutex lock;
> -       bool als_enabled;
> -       bool ps_enabled;
> -       bool ps_int_enabled;
> -       uint32_t ps_thdl;
> -       uint32_t ps_thdh;
> -       uint32_t ps_near_level;
>         u64 timestamp;
>         struct regmap *regmap;
>         struct regmap_field *reg_state;
> @@ -131,6 +125,12 @@ struct stk3310_data {
>         struct regmap_field *reg_int_ps;
>         struct regmap_field *reg_flag_psint;
>         struct regmap_field *reg_flag_nf;
> +       u32 ps_thdl;
> +       u32 ps_thdh;
> +       u32 ps_near_level;
> +       bool als_enabled;
> +       bool ps_enabled;
> +       bool ps_int_enabled;
>  };
>
>  static const struct iio_event_spec stk3310_events[] = {
> --
> 2.25.1
>
>

Reviewed-by: Joshua Crofts <joshua.crofts1@gmail.com>

-- 
Kind regards

CJD

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM
  2026-05-04  3:04 ` [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM Miao Li
@ 2026-05-04 15:34   ` Jonathan Cameron
  2026-05-05  6:53   ` Andy Shevchenko
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2026-05-04 15:34 UTC (permalink / raw)
  To: Miao Li
  Cc: dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19, linux-iio,
	linux-kernel, Miao Li

On Mon,  4 May 2026 11:04:06 +0800
Miao Li <limiao870622@163.com> wrote:

> From: Miao Li <limiao@kylinos.cn>
> 
> On the Inspur HS326 laptop(which integrated with HiSilicon M900
> processor), if the STK3311-X chip's PS interrupt is configured
> in "Recommended interrupt mode", the interrupt cannot be triggered
> normally after waking from suspend or hibernation.
> 
> In this case, neither disabling and re-enabling the interrupt nor
> resetting the PS threshold register can restore the interrupt to
> normal operation.
> 
> If the interrupt is disabled in suspend() then reset the PS threshold
> register and enable the interrupt in resume(). This resolves the issue.
> 
> Signed-off-by: Miao Li <limiao@kylinos.cn>

Hi Miao Li,

This to me feels like something we should backport and is
sort of a fix.  For now I'm going to queue it via the slow path (for next
merge window) but you want me to drag it into the fixes branch to hit
sooner please reply with a Fixes tag to indicate when this code was
added.  I'd guess the second ever patch to the driver that added
threshold support, but I haven't checked.

So for now series applied to the testing branch of iio.git.

Note I made two tweaks - see below.


> ---
>  drivers/iio/light/stk3310.c | 72 ++++++++++++++++++++++++++++++++++---
>  1 file changed, 67 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c
> index a75a83594..86cc6e8ec 100644
> --- a/drivers/iio/light/stk3310.c
> +++ b/drivers/iio/light/stk3310.c
> @@ -117,6 +117,9 @@ struct stk3310_data {
>  	struct mutex lock;
>  	bool als_enabled;
>  	bool ps_enabled;
> +	bool ps_int_enabled;
> +	uint32_t ps_thdl;
> +	uint32_t ps_thdh;
>  	uint32_t ps_near_level;
>  	u64 timestamp;
>  	struct regmap *regmap;
> @@ -296,8 +299,15 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
>  
>  	buf = cpu_to_be16(val);
>  	ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(&client->dev, "failed to set PS threshold!\n");
> +		return ret;
> +	}
> +
> +	if (reg == STK3310_REG_THDH_PS)
> +		data->ps_thdh = val;
> +	else
> +		data->ps_thdl = val;
>  
>  	return ret;

return 0;

>  }
> @@ -331,8 +341,14 @@ static int stk3310_write_event_config(struct iio_dev *indio_dev,
>  	/* Set INT_PS value */
>  	mutex_lock(&data->lock);
>  	ret = regmap_field_write(data->reg_int_ps, state);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(&client->dev, "failed to set interrupt mode\n");
> +		mutex_unlock(&data->lock);
> +		return ret;
> +	}
> +
> +	data->ps_int_enabled = state;
> +
>  	mutex_unlock(&data->lock);
>  
>  	return ret;

return 0;

> @@ -504,10 +520,15 @@ static int stk3310_init(struct iio_dev *indio_dev)
>  
>  	/* Enable PS interrupts */
>  	ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(&client->dev, "failed to enable interrupts!\n");
> +		return ret;
> +	}
>  
> -	return ret;
> +	data->ps_int_enabled = true;
> +	data->ps_thdh = STK3310_PS_MAX_VAL;
> +
> +	return 0;
>  }
>  
>  static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg)
> @@ -671,9 +692,18 @@ static void stk3310_remove(struct i2c_client *client)
>  static int stk3310_suspend(struct device *dev)
>  {
>  	struct stk3310_data *data;
> +	int ret;
>  
>  	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
>  
> +	if (data->ps_int_enabled) {
> +		ret = regmap_field_write(data->reg_int_ps, 0x0);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to disable ps int at suspend.\n");
> +			return ret;
> +		}
> +	}
> +
>  	return stk3310_set_state(data, STK3310_STATE_STANDBY);
>  }
>  
> @@ -681,6 +711,8 @@ static int stk3310_resume(struct device *dev)
>  {
>  	u8 state = 0;
>  	struct stk3310_data *data;
> +	__be16 buf;
> +	int ret;
>  
>  	data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
>  	if (data->ps_enabled)
> @@ -688,7 +720,37 @@ static int stk3310_resume(struct device *dev)
>  	if (data->als_enabled)
>  		state |= STK3310_STATE_EN_ALS;
>  
> -	return stk3310_set_state(data, state);
> +	ret = stk3310_set_state(data, state);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (data->ps_thdl != 0x0) {
> +		buf = cpu_to_be16(data->ps_thdl);
> +		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDL_PS, &buf, 2);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to set reg THDL_PS at resume.\n");
> +			return ret;
> +		}
> +	}
> +
> +	if (data->ps_thdh != STK3310_PS_MAX_VAL) {
> +		buf = cpu_to_be16(data->ps_thdh);
> +		ret = regmap_bulk_write(data->regmap, STK3310_REG_THDH_PS, &buf, 2);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to set reg THDH_PS at resume.\n");
> +			return ret;
> +		}
> +	}
> +
> +	if (data->ps_int_enabled) {
> +		ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN);
> +		if (ret < 0) {
> +			dev_err(dev, "failed to enable ps int at resume.\n");
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
>  }
>  
>  static DEFINE_SIMPLE_DEV_PM_OPS(stk3310_pm_ops, stk3310_suspend,


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter
  2026-05-04  3:04 ` [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter Miao Li
  2026-05-04  7:11   ` Joshua Crofts
@ 2026-05-05  6:49   ` Andy Shevchenko
  2026-05-05  9:29     ` Jonathan Cameron
  1 sibling, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2026-05-05  6:49 UTC (permalink / raw)
  To: Miao Li
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19,
	linux-iio, linux-kernel, Miao Li

On Mon, May 04, 2026 at 11:04:08AM +0800, Miao Li wrote:

> Convert the hardcoded count parameter to sizeof(buf) for all
> regmap_bulk_write() and regmap_bulk_read() calls in this driver
> to improve code maintainability. For details, see [1].

> [1] https://lore.kernel.org/all/20260428192213.7c5c80e5@jic23-huawei/
> 

Make these two lines a formal Link tag,

Link: $URL [1]

Perhaps even Suggested-by tag is also good to add.

> Signed-off-by: Miao Li <limiao@kylinos.cn>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding
  2026-05-04  3:04 ` [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding Miao Li
  2026-05-04  8:19   ` Joshua Crofts
@ 2026-05-05  6:51   ` Andy Shevchenko
  1 sibling, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2026-05-05  6:51 UTC (permalink / raw)
  To: Miao Li
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19,
	linux-iio, linux-kernel, Miao Li

On Mon, May 04, 2026 at 11:04:07AM +0800, Miao Li wrote:

> Replace the uint32_t type members in the stk3310_data structure with u32

stk3310_data structure --> struct stk3310_data

> to adhere to the unified kernel coding style, and reorder the member
> variables to eliminate memory padding holes.

Might be good to add `pahole` summary before and after the change.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM
  2026-05-04  3:04 ` [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM Miao Li
  2026-05-04 15:34   ` Jonathan Cameron
@ 2026-05-05  6:53   ` Andy Shevchenko
  1 sibling, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2026-05-05  6:53 UTC (permalink / raw)
  To: Miao Li
  Cc: jic23, dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19,
	linux-iio, linux-kernel, Miao Li

On Mon, May 04, 2026 at 11:04:06AM +0800, Miao Li wrote:

> On the Inspur HS326 laptop(which integrated with HiSilicon M900
> processor), if the STK3311-X chip's PS interrupt is configured
> in "Recommended interrupt mode", the interrupt cannot be triggered
> normally after waking from suspend or hibernation.
> 
> In this case, neither disabling and re-enabling the interrupt nor
> resetting the PS threshold register can restore the interrupt to
> normal operation.
> 
> If the interrupt is disabled in suspend() then reset the PS threshold
> register and enable the interrupt in resume(). This resolves the issue.

Like Jonathan said, this should be a fix, otherwise the ordering
of the patches in the series is wrong (and this should be actually
the last one in the series).

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter
  2026-05-05  6:49   ` Andy Shevchenko
@ 2026-05-05  9:29     ` Jonathan Cameron
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2026-05-05  9:29 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Miao Li, dlechner, nuno.sa, andy, waqar.hameed, dixitparmar19,
	linux-iio, linux-kernel, Miao Li

On Tue, 5 May 2026 09:49:41 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Mon, May 04, 2026 at 11:04:08AM +0800, Miao Li wrote:
> 
> > Convert the hardcoded count parameter to sizeof(buf) for all
> > regmap_bulk_write() and regmap_bulk_read() calls in this driver
> > to improve code maintainability. For details, see [1].  
> 
> > [1] https://lore.kernel.org/all/20260428192213.7c5c80e5@jic23-huawei/
> >   
> 
> Make these two lines a formal Link tag,
> 
> Link: $URL [1]
> 
> Perhaps even Suggested-by tag is also good to add.
Tweaked this and the previous as suggested + added tag to previous.

Thanks,

J
> 
> > Signed-off-by: Miao Li <limiao@kylinos.cn>  
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-05-05  9:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04  3:04 [PATCH v4 0/3] iio: light: stk3310: Fix PS interrupt after suspend and clean up code style Miao Li
2026-05-04  3:04 ` [PATCH v4 1/3] iio: light: stk3310: Deal with the ps interrupt issue in PM Miao Li
2026-05-04 15:34   ` Jonathan Cameron
2026-05-05  6:53   ` Andy Shevchenko
2026-05-04  3:04 ` [PATCH v4 2/3] iio: light: stk3310: Replace uint32_t with u32 and reorder members to eliminate padding Miao Li
2026-05-04  8:19   ` Joshua Crofts
2026-05-05  6:51   ` Andy Shevchenko
2026-05-04  3:04 ` [PATCH v4 3/3] iio: light: stk3310: Use sizeof() for regmap_bulk_read/write count parameter Miao Li
2026-05-04  7:11   ` Joshua Crofts
2026-05-05  6:49   ` Andy Shevchenko
2026-05-05  9:29     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox