lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201215212228.185517-4-clemens.gruber@pqgruber.com>
Date:   Tue, 15 Dec 2020 22:22:25 +0100
From:   Clemens Gruber <clemens.gruber@...ruber.com>
To:     linux-pwm@...r.kernel.org
Cc:     Thierry Reding <thierry.reding@...il.com>,
        u.kleine-koenig@...gutronix.de,
        Sven Van Asbroeck <TheSven73@...il.com>,
        Lee Jones <lee.jones@...aro.org>, linux-kernel@...r.kernel.org,
        Mika Westerberg <mika.westerberg@...ux.intel.com>,
        David Jander <david@...tonic.nl>,
        Clemens Gruber <clemens.gruber@...ruber.com>
Subject: [PATCH v5 4/7] pwm: pca9685: Reset registers to POR state in probe

Reset the prescale and ON/OFF registers to their POR default state in
the probe function. Otherwise, the PWMs could still be active after a
watchdog reset and reboot, etc.

Signed-off-by: Clemens Gruber <clemens.gruber@...ruber.com>
---
 drivers/pwm/pwm-pca9685.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c
index 7b14447f3c05..38aadaf50996 100644
--- a/drivers/pwm/pwm-pca9685.c
+++ b/drivers/pwm/pwm-pca9685.c
@@ -47,6 +47,7 @@
 #define PCA9685_ALL_LED_OFF_H	0xFD
 #define PCA9685_PRESCALE	0xFE
 
+#define PCA9685_PRESCALE_DEF	0x1E	/* => default frequency of ~200 Hz */
 #define PCA9685_PRESCALE_MIN	0x03	/* => max. frequency of 1526 Hz */
 #define PCA9685_PRESCALE_MAX	0xFF	/* => min. frequency of 24 Hz */
 
@@ -446,9 +447,11 @@ static int pca9685_pwm_probe(struct i2c_client *client,
 	reg &= ~(MODE1_ALLCALL | MODE1_SUB1 | MODE1_SUB2 | MODE1_SUB3);
 	regmap_write(pca->regmap, PCA9685_MODE1, reg);
 
-	/* Clear all "full off" bits */
+	/* Reset ON/OFF registers to HW defaults (only full OFF bit is set) */
+	regmap_write(pca->regmap, PCA9685_ALL_LED_ON_L, 0);
+	regmap_write(pca->regmap, PCA9685_ALL_LED_ON_H, 0);
 	regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_L, 0);
-	regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_H, 0);
+	regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_H, LED_FULL);
 
 	pca->chip.ops = &pca9685_pwm_ops;
 	/* Add an extra channel for ALL_LED */
@@ -470,8 +473,10 @@ static int pca9685_pwm_probe(struct i2c_client *client,
 	/*
 	 * The chip comes out of power-up in the sleep state,
 	 * but force it to sleep in case it was woken up before
+	 * and set the default prescale value
 	 */
 	pca9685_set_sleep_mode(pca, true);
+	regmap_write(pca->regmap, PCA9685_PRESCALE, PCA9685_PRESCALE_DEF);
 	pm_runtime_set_suspended(&client->dev);
 	pm_runtime_enable(&client->dev);
 
-- 
2.29.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ