lkml.org 
[lkml]   [2016]   [Apr]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4/6] leds: pca963x: Reduce magic values
Date
This patch uses the newly introduced defines to further reduce magic
values and magic shifts. These changes have a slightly bigger impact as
they do introduce binary changes. There should be no logical changes
however.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
---
drivers/leds/leds-pca963x.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index e4e668d..14690f2 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -199,33 +199,32 @@ static int pca963x_brightness(struct pca963x_led *pca963x,
u8 ledout_addr = pca963x->chip->chipdef->ledout_base
+ (pca963x->led_num / 4);
u8 ledout;
- int shift = 2 * (pca963x->led_num % 4);
- u8 mask = 0x3 << shift;
int ret;

mutex_lock(&pca963x->chip->mutex);
ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr);
+ ledout &= ~PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_MASK, pca963x->led_num);
switch (brightness) {
case LED_FULL:
- ret = i2c_smbus_write_byte_data(pca963x->chip->client,
- ledout_addr,
- (ledout & ~mask) | (PCA963X_LEDOUT_LED_ON << shift));
+ ledout |= PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_LED_ON,
+ pca963x->led_num);
break;
case LED_OFF:
- ret = i2c_smbus_write_byte_data(pca963x->chip->client,
- ledout_addr, ledout & ~mask);
+ ledout |= PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_LED_OFF,
+ pca963x->led_num);
break;
default:
ret = i2c_smbus_write_byte_data(pca963x->chip->client,
- PCA963X_PWM_BASE + pca963x->led_num,
+ PCA963X_PWM_ADDR(pca963x->led_num),
brightness);
if (ret < 0)
goto unlock;
- ret = i2c_smbus_write_byte_data(pca963x->chip->client,
- ledout_addr,
- (ledout & ~mask) | (PCA963X_LEDOUT_LED_PWM << shift));
+ ledout |= PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_LED_PWM,
+ pca963x->led_num);
break;
}
+ ret = i2c_smbus_write_byte_data(pca963x->chip->client, ledout_addr,
+ ledout);
unlock:
mutex_unlock(&pca963x->chip->mutex);
return ret;
@@ -237,8 +236,6 @@ static void pca963x_blink(struct pca963x_led *pca963x)
(pca963x->led_num / 4);
u8 ledout;
u8 mode2;
- int shift = 2 * (pca963x->led_num % 4);
- u8 mask = 0x3 << shift;

mutex_lock(&pca963x->chip->mutex);
i2c_smbus_write_byte_data(pca963x->chip->client,
@@ -253,9 +250,14 @@ static void pca963x_blink(struct pca963x_led *pca963x)
mode2 | PCA963X_MODE2_DMBLNK);

ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr);
- if ((ledout & mask) != (PCA963X_LEDOUT_LED_GRP_PWM << shift))
+ if ((ledout &
+ PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_MASK, pca963x->led_num)) !=
+ PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_LED_GRP_PWM, pca963x->led_num)) {
+ ledout |= PCA963X_LEDOUT_LDR(PCA963X_LEDOUT_LED_GRP_PWM,
+ pca963x->led_num);
i2c_smbus_write_byte_data(pca963x->chip->client, ledout_addr,
- (ledout & ~mask) | (PCA963X_LEDOUT_LED_GRP_PWM << shift));
+ ledout);
+ }
mutex_unlock(&pca963x->chip->mutex);
}

--
2.8.0.rc3
\
 
 \ /
  Last update: 2016-04-19 10:01    [W:0.169 / U:60.940 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site