diff mbox series

[2/2] leds: pca9532: use mask and shift helper macros

Message ID 517672dc62754eafb8e57ec731402236@de.pepperl-fuchs.com
State New
Headers show
Series None | expand

Commit Message

Moll Markus Sept. 15, 2020, 7:12 p.m. UTC
Each led setting occupies two bits in a corresponding led register.
Accessing these bits requires shifting and masking. The new helper
macros concentrate the computation of those masks in one place.

Signed-off-by: Markus Moll <mmoll@de.pepperl-fuchs.com>
---

 drivers/leds/leds-pca9532.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

--
2.25.1


i.A. Dr. Markus Moll
Pepperl+Fuchs SE
Geschäftsbereich VT-IVC
Lilienthalstraße 200
68307 Mannheim
Telefon: +49 621 776 - 4282




Pepperl+Fuchs SE, Mannheim
Vorstände/Board members: Dr.-Ing. Gunther Kegel (Vors.), Werner Guthier (stellv. Vors.), Mehmet Hatiboglu
Vorsitzender des Aufsichtsrats/Chairman of the supervisory board: Michael Fuchs sen.
Registergericht/Register Court: AG Mannheim HRB 737016 - UST-ID Nr. DE 143877372


Wichtiger Hinweis:
Diese E-Mail einschliesslich ihrer Anhaenge enthaelt vertrauliche und rechtlich geschuetzte Informationen, die nur fuer den Adressaten bestimmt sind. Sollten Sie nicht der bezeichnete Adressat sein, so teilen Sie dies bitte dem Absender umgehend mit und loeschen Sie diese Nachricht und ihre Anhaenge. Die unbefugte Weitergabe, das Anfertigen von Kopien und jede Veraenderung der E-Mail ist untersagt. Der Absender haftet nicht fuer die Inhalte von veraenderten E-Mails.

Important Information:
This e-mail message including its attachments contains confidential and legally protected information solely intended for the addressee. If you are not the intended addressee of this message, please contact the addresser immediately and delete this message including its attachments. The unauthorized dissemination, copying and change of this e-mail are strictly forbidden. The addresser shall not be liable for the content of such changed e-mails.
diff mbox series

Patch

diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index d822ffcdbae..890f19d3c62 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -27,6 +27,8 @@ 
 #define PCA9532_REG_PWM(m, i)(PCA9532_REG_OFFSET(m) + 0x2 + (i) * 2)
 #define LED_REG(m, led)(PCA9532_REG_OFFSET(m) + 0x5 + (led >> 2))
 #define LED_NUM(led)(led & 0x3)
+#define LED_SHIFT(led)(LED_NUM(led) * 2)
+#define LED_MASK(led)(0x3 << LED_SHIFT(led))

 #define ldev_to_led(c)       container_of(c, struct pca9532_led, ldev)

@@ -162,9 +164,9 @@  static void pca9532_setled(struct pca9532_led *led)
 mutex_lock(&data->update_lock);
 reg = i2c_smbus_read_byte_data(client, LED_REG(maxleds, led->id));
 /* zero led bits */
-reg = reg & ~(0x3<<LED_NUM(led->id)*2);
+reg = reg & ~LED_MASK(led->id);
 /* set the new value */
-reg = reg | (led->state << LED_NUM(led->id)*2);
+reg = reg | (led->state << LED_SHIFT(led->id));
 i2c_smbus_write_byte_data(client, LED_REG(maxleds, led->id), reg);
 mutex_unlock(&data->update_lock);
 }
@@ -260,7 +262,7 @@  static enum pca9532_state pca9532_getled(struct pca9532_led *led)

 mutex_lock(&data->update_lock);
 reg = i2c_smbus_read_byte_data(client, LED_REG(maxleds, led->id));
-ret = (reg >> LED_NUM(led->id) * 2)&0x3;
+ret = (reg & LED_MASK(led->id)) >> LED_SHIFT(led->id);
 mutex_unlock(&data->update_lock);
 return ret;
 }