Skip to content

feat(kernel/pca963x): implement power management #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: cp-release/lf-5.15.y
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions drivers/leds/leds-pca963x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -362,6 +363,45 @@ static int pca963x_register_leds(struct i2c_client *client,
return ret;
}

#ifdef CONFIG_PM
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;
}

static const struct dev_pm_ops pca963x_pmops = {
SET_SYSTEM_SLEEP_PM_OPS(pca963x_suspend, pca963x_resume)
};

#define PCA963X_SMBUS_PMOPS (&pca963x_pmops)

#else
#define PCA963X_SMBUS_PMOPS NULL
#endif

static const struct of_device_id of_pca963x_match[] = {
{ .compatible = "nxp,pca9632", },
{ .compatible = "nxp,pca9633", },
Expand Down Expand Up @@ -412,6 +452,7 @@ static struct i2c_driver pca963x_driver = {
.driver = {
.name = "leds-pca963x",
.of_match_table = of_pca963x_match,
.pm = PCA963X_SMBUS_PMOPS
},
.probe = pca963x_probe,
.id_table = pca963x_id,
Expand Down