Skip to contentSkip to conversation

leds/pca963x: implement power management

PATCH In review Amitesh Singh 2 participants 2 messages Jan 16, 2024 – Jan 25, 2024 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds/pca963x: implement power management

This implements power management in upstream driver for pca9633 which enables device sleep and resume on system-wide sleep/hibernation

---
 drivers/leds/leds-pca963x.c | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/leds/leds-pca963x.c +38 -0
index 47223c850e4b..2474e40d8479 100644
@@ -39,6 +39,7 @@
 #define PCA963X_LED_PWM		0x2	/* Controlled through PWM */
 #define PCA963X_LED_GRP_PWM	0x3	/* Controlled through PWM/GRPPWM */
 
+#define PCA963X_MODE1_SLEEP     0x04    /* Normal mode or Low Power mode, oscillator off */
 #define PCA963X_MODE2_OUTDRV	0x04	/* Open-drain or totem pole */
 #define PCA963X_MODE2_INVRT	0x10	/* Normal or inverted direction */
 #define PCA963X_MODE2_DMBLNK	0x20	/* Enable blinking */
@@ -380,6 +381,42 @@ static int pca963x_register_leds(struct i2c_client *client,
 	return ret;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int pca963x_suspend(struct device *dev)
+{
+	struct pca963x *chip;
+	u8 reg;
+
+	chip = dev_get_drvdata(dev);
+
+	reg = i2c_smbus_read_byte_data(chip->client, PCA963X_MODE1);
+	reg = reg | (1 << PCA963X_MODE1_SLEEP);
+	i2c_smbus_write_byte_data(chip->client, PCA963X_MODE1, reg);
+
+	return 0;
+}
+
+static int pca963x_resume(struct device *dev)
+{
+	struct pca963x *chip;
+	u8 reg;
+
+	chip = dev_get_drvdata(dev);
+
+	reg = i2c_smbus_read_byte_data(chip->client, PCA963X_MODE1);
+	reg = reg & ~(1 << PCA963X_MODE1_SLEEP);
+	i2c_smbus_write_byte_data(chip->client, PCA963X_MODE1, reg);
+
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops pca963x_pmops = {
+	SET_SYSTEM_SLEEP_PM_OPS(pca963x_suspend, pca963x_resume)
+};
+
+static SIMPLE_DEV_PM_OPS(pca963x_pm, pca963x_suspend, pca963x_resume);
+
 static const struct of_device_id of_pca963x_match[] = {
 	{ .compatible = "nxp,pca9632", },
 	{ .compatible = "nxp,pca9633", },
@@ -430,6 +467,7 @@ static struct i2c_driver pca963x_driver = {
 	.driver = {
 		.name	= "leds-pca963x",
 		.of_match_table = of_pca963x_match,
+		.pm = &pca963x_pmops
 	},
 	.probe = pca963x_probe,
 	.id_table = pca963x_id,
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 1 line · Amitesh Singh

This implements power management in upstream driver

This *is* the upstream driver. No need to mention that.

Quoted 21 lines

for pca9633 which enables device sleep and resume
on system-wide sleep/hibernation

---
 drivers/leds/leds-pca963x.c | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/leds/leds-pca963x.c +1 -0
index 47223c850e4b..2474e40d8479 100644
@@ -39,6 +39,7 @@
 #define PCA963X_LED_PWM		0x2	/* Controlled through PWM */
 #define PCA963X_LED_GRP_PWM	0x3	/* Controlled through PWM/GRPPWM */
 
+#define PCA963X_MODE1_SLEEP     0x04    /* Normal mode or Low Power mode, oscillator off */
 #define PCA963X_MODE2_OUTDRV	0x04	/* Open-drain or totem pole */
 #define PCA963X_MODE2_INVRT	0x10	/* Normal or inverted direction */
 #define PCA963X_MODE2_DMBLNK	0x20	/* Enable blinking */

drivers/leds/leds-pca963x.c static int pca963x_register_leds(struct i2c_client *client, · line 390

Quoted 10 lines
drivers/leds/leds-pca963x.c +7 -0
@@ -380,6 +381,42 @@ static int pca963x_register_leds(struct i2c_client *client,
 	return ret;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int pca963x_suspend(struct device *dev)
+{
+	struct pca963x *chip;
+	u8 reg;
+
+	chip = dev_get_drvdata(dev);

Do the assignment during declaration.

drivers/leds/leds-pca963x.c static int pca963x_register_leds(struct i2c_client *client, · line 393

Quoted 2 lines
drivers/leds/leds-pca963x.c +2 -0
+	reg = i2c_smbus_read_byte_data(chip->client, PCA963X_MODE1);
+	reg = reg | (1 << PCA963X_MODE1_SLEEP);

BIT()

drivers/leds/leds-pca963x.c static int pca963x_register_leds(struct i2c_client *client, · line 404

Quoted 11 lines
drivers/leds/leds-pca963x.c +11 -0
+	i2c_smbus_write_byte_data(chip->client, PCA963X_MODE1, reg);
+
+	return 0;
+}
+
+static int pca963x_resume(struct device *dev)
+{
+	struct pca963x *chip;
+	u8 reg;
+
+	chip = dev_get_drvdata(dev);

As above.

drivers/leds/leds-pca963x.c static int pca963x_register_leds(struct i2c_client *client, · line 405

Quoted 2 lines
drivers/leds/leds-pca963x.c +2 -0
+	reg = i2c_smbus_read_byte_data(chip->client, PCA963X_MODE1);
+	reg = reg & ~(1 << PCA963X_MODE1_SLEEP);

As above.

drivers/leds/leds-pca963x.c static int pca963x_register_leds(struct i2c_client *client, · line 417

Quoted 10 lines
drivers/leds/leds-pca963x.c +10 -0
+	i2c_smbus_write_byte_data(chip->client, PCA963X_MODE1, reg);
+
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops pca963x_pmops = {
+	SET_SYSTEM_SLEEP_PM_OPS(pca963x_suspend, pca963x_resume)
+};
+

Remove this line.

Quoted 16 lines
drivers/leds/leds-pca963x.c +3 -0
+static SIMPLE_DEV_PM_OPS(pca963x_pm, pca963x_suspend, pca963x_resume);
+
 static const struct of_device_id of_pca963x_match[] = {
 	{ .compatible = "nxp,pca9632", },
 	{ .compatible = "nxp,pca9633", },
@@ -430,6 +467,7 @@ static struct i2c_driver pca963x_driver = {
 	.driver = {
 		.name	= "leds-pca963x",
 		.of_match_table = of_pca963x_match,
+		.pm = &pca963x_pmops
 	},
 	.probe = pca963x_probe,
 	.id_table = pca963x_id,
Signature · 1 line
2.43.0
Signature · 1 line
Lee Jones [李琼斯]