Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: pca963x: Add support for suspend and resume

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

Signed-off-by: Amitesh Singh <singh.amitesh@gmail.com>
Link: https://lore.kernel.org/r/20240203162524.343936-1-singh.amitesh@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Amitesh Singh and committed by
Lee Jones
46f02b68 9225333e

+28
+28
drivers/leds/leds-pca963x.c
··· 39 39 #define PCA963X_LED_PWM 0x2 /* Controlled through PWM */ 40 40 #define PCA963X_LED_GRP_PWM 0x3 /* Controlled through PWM/GRPPWM */ 41 41 42 + #define PCA963X_MODE1_SLEEP 0x04 /* Normal mode or Low Power mode, oscillator off */ 42 43 #define PCA963X_MODE2_OUTDRV 0x04 /* Open-drain or totem pole */ 43 44 #define PCA963X_MODE2_INVRT 0x10 /* Normal or inverted direction */ 44 45 #define PCA963X_MODE2_DMBLNK 0x20 /* Enable blinking */ ··· 381 380 return ret; 382 381 } 383 382 383 + static int pca963x_suspend(struct device *dev) 384 + { 385 + struct pca963x *chip = dev_get_drvdata(dev); 386 + u8 reg; 387 + 388 + reg = i2c_smbus_read_byte_data(chip->client, PCA963X_MODE1); 389 + reg = reg | BIT(PCA963X_MODE1_SLEEP); 390 + i2c_smbus_write_byte_data(chip->client, PCA963X_MODE1, reg); 391 + 392 + return 0; 393 + } 394 + 395 + static int pca963x_resume(struct device *dev) 396 + { 397 + struct pca963x *chip = dev_get_drvdata(dev); 398 + u8 reg; 399 + 400 + reg = i2c_smbus_read_byte_data(chip->client, PCA963X_MODE1); 401 + reg = reg & ~BIT(PCA963X_MODE1_SLEEP); 402 + i2c_smbus_write_byte_data(chip->client, PCA963X_MODE1, reg); 403 + 404 + return 0; 405 + } 406 + 407 + static DEFINE_SIMPLE_DEV_PM_OPS(pca963x_pm, pca963x_suspend, pca963x_resume); 408 + 384 409 static const struct of_device_id of_pca963x_match[] = { 385 410 { .compatible = "nxp,pca9632", }, 386 411 { .compatible = "nxp,pca9633", }, ··· 457 430 .driver = { 458 431 .name = "leds-pca963x", 459 432 .of_match_table = of_pca963x_match, 433 + .pm = pm_sleep_ptr(&pca963x_pm) 460 434 }, 461 435 .probe = pca963x_probe, 462 436 .id_table = pca963x_id,