Commit 39118499 authored by Marek Behún's avatar Marek Behún Committed by Pavel Machek

leds: pca963x: cosmetic: use helper variables, better indentation

Use helper variables: instead of writing &client->dev at many places,
write only dev. The same with pca963x->chip->chipdef,
pca963x->chip->client).

Use helper variable u8 val for i2c_smbus_write_byte_data, for better
indentation.

Indent better on various places.
Signed-off-by: default avatarMarek Behún <marek.behun@nic.cz>
Cc: Peter Meerwald <p.meerwald@bct-electronic.com>
Cc: Ricardo Ribalda <ribalda@kernel.org>
Cc: Zahari Petkov <zahari@balena.io>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent a2380982
...@@ -118,33 +118,36 @@ struct pca963x_led { ...@@ -118,33 +118,36 @@ struct pca963x_led {
static int pca963x_brightness(struct pca963x_led *pca963x, static int pca963x_brightness(struct pca963x_led *pca963x,
enum led_brightness brightness) enum led_brightness brightness)
{ {
u8 ledout_addr = pca963x->chip->chipdef->ledout_base struct i2c_client *client = pca963x->chip->client;
+ (pca963x->led_num / 4); struct pca963x_chipdef *chipdef = pca963x->chip->chipdef;
u8 ledout; u8 ledout_addr, ledout, mask, val;
int shift = 2 * (pca963x->led_num % 4); int shift;
u8 mask = 0x3 << shift;
int ret; int ret;
ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr); ledout_addr = chipdef->ledout_base + (pca963x->led_num / 4);
shift = 2 * (pca963x->led_num % 4);
mask = 0x3 << shift;
ledout = i2c_smbus_read_byte_data(client, ledout_addr);
switch (brightness) { switch (brightness) {
case LED_FULL: case LED_FULL:
ret = i2c_smbus_write_byte_data(pca963x->chip->client, val = (ledout & ~mask) | (PCA963X_LED_ON << shift);
ledout_addr, ret = i2c_smbus_write_byte_data(client, ledout_addr, val);
(ledout & ~mask) | (PCA963X_LED_ON << shift));
break; break;
case LED_OFF: case LED_OFF:
ret = i2c_smbus_write_byte_data(pca963x->chip->client, val = ledout & ~mask;
ledout_addr, ledout & ~mask); ret = i2c_smbus_write_byte_data(client, ledout_addr, val);
break; break;
default: default:
ret = i2c_smbus_write_byte_data(pca963x->chip->client, ret = i2c_smbus_write_byte_data(client,
PCA963X_PWM_BASE + pca963x->led_num, PCA963X_PWM_BASE +
pca963x->led_num,
brightness); brightness);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = i2c_smbus_write_byte_data(pca963x->chip->client,
ledout_addr, val = (ledout & ~mask) | (PCA963X_LED_PWM << shift);
(ledout & ~mask) | (PCA963X_LED_PWM << shift)); ret = i2c_smbus_write_byte_data(client, ledout_addr, val);
break; break;
} }
...@@ -153,36 +156,40 @@ static int pca963x_brightness(struct pca963x_led *pca963x, ...@@ -153,36 +156,40 @@ static int pca963x_brightness(struct pca963x_led *pca963x,
static void pca963x_blink(struct pca963x_led *pca963x) static void pca963x_blink(struct pca963x_led *pca963x)
{ {
u8 ledout_addr = pca963x->chip->chipdef->ledout_base + struct i2c_client *client = pca963x->chip->client;
(pca963x->led_num / 4); struct pca963x_chipdef *chipdef = pca963x->chip->chipdef;
u8 ledout; u8 ledout_addr, ledout, mask, val, mode2;
u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client, int shift;
PCA963X_MODE2);
int shift = 2 * (pca963x->led_num % 4); ledout_addr = chipdef->ledout_base + (pca963x->led_num / 4);
u8 mask = 0x3 << shift; shift = 2 * (pca963x->led_num % 4);
mask = 0x3 << shift;
mode2 = i2c_smbus_read_byte_data(client, PCA963X_MODE2);
i2c_smbus_write_byte_data(pca963x->chip->client, i2c_smbus_write_byte_data(client, chipdef->grppwm, pca963x->gdc);
pca963x->chip->chipdef->grppwm, pca963x->gdc);
i2c_smbus_write_byte_data(pca963x->chip->client, i2c_smbus_write_byte_data(client, chipdef->grpfreq, pca963x->gfrq);
pca963x->chip->chipdef->grpfreq, pca963x->gfrq);
if (!(mode2 & PCA963X_MODE2_DMBLNK)) if (!(mode2 & PCA963X_MODE2_DMBLNK))
i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2, i2c_smbus_write_byte_data(client, PCA963X_MODE2,
mode2 | PCA963X_MODE2_DMBLNK); mode2 | PCA963X_MODE2_DMBLNK);
mutex_lock(&pca963x->chip->mutex); mutex_lock(&pca963x->chip->mutex);
ledout = i2c_smbus_read_byte_data(pca963x->chip->client, ledout_addr);
if ((ledout & mask) != (PCA963X_LED_GRP_PWM << shift)) ledout = i2c_smbus_read_byte_data(client, ledout_addr);
i2c_smbus_write_byte_data(pca963x->chip->client, ledout_addr, if ((ledout & mask) != (PCA963X_LED_GRP_PWM << shift)) {
(ledout & ~mask) | (PCA963X_LED_GRP_PWM << shift)); val = (ledout & ~mask) | (PCA963X_LED_GRP_PWM << shift);
i2c_smbus_write_byte_data(client, ledout_addr, val);
}
mutex_unlock(&pca963x->chip->mutex); mutex_unlock(&pca963x->chip->mutex);
} }
static int pca963x_power_state(struct pca963x_led *pca963x) static int pca963x_power_state(struct pca963x_led *pca963x)
{ {
struct i2c_client *client = pca963x->chip->client;
unsigned long *leds_on = &pca963x->chip->leds_on; unsigned long *leds_on = &pca963x->chip->leds_on;
unsigned long cached_leds = pca963x->chip->leds_on; unsigned long cached_leds = *leds_on;
if (pca963x->led_cdev.brightness) if (pca963x->led_cdev.brightness)
set_bit(pca963x->led_num, leds_on); set_bit(pca963x->led_num, leds_on);
...@@ -190,8 +197,8 @@ static int pca963x_power_state(struct pca963x_led *pca963x) ...@@ -190,8 +197,8 @@ static int pca963x_power_state(struct pca963x_led *pca963x)
clear_bit(pca963x->led_num, leds_on); clear_bit(pca963x->led_num, leds_on);
if (!(*leds_on) != !cached_leds) if (!(*leds_on) != !cached_leds)
return i2c_smbus_write_byte_data(pca963x->chip->client, return i2c_smbus_write_byte_data(client, PCA963X_MODE1,
PCA963X_MODE1, *leds_on ? 0 : BIT(4)); *leds_on ? 0 : BIT(4));
return 0; return 0;
} }
...@@ -278,23 +285,23 @@ static int pca963x_blink_set(struct led_classdev *led_cdev, ...@@ -278,23 +285,23 @@ static int pca963x_blink_set(struct led_classdev *led_cdev,
} }
static struct pca963x_platform_data * static struct pca963x_platform_data *
pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip) pca963x_get_pdata(struct device *dev, struct pca963x_chipdef *chip)
{ {
struct pca963x_platform_data *pdata; struct pca963x_platform_data *pdata;
struct led_info *pca963x_leds; struct led_info *pca963x_leds;
struct fwnode_handle *child; struct fwnode_handle *child;
int count; int count;
count = device_get_child_node_count(&client->dev); count = device_get_child_node_count(dev);
if (!count || count > chip->n_leds) if (!count || count > chip->n_leds)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
pca963x_leds = devm_kcalloc(&client->dev, pca963x_leds = devm_kcalloc(dev, chip->n_leds, sizeof(struct led_info),
chip->n_leds, sizeof(struct led_info), GFP_KERNEL); GFP_KERNEL);
if (!pca963x_leds) if (!pca963x_leds)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
device_for_each_child_node(&client->dev, child) { device_for_each_child_node(dev, child) {
struct led_info led = {}; struct led_info led = {};
u32 reg; u32 reg;
int res; int res;
...@@ -312,8 +319,8 @@ pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip) ...@@ -312,8 +319,8 @@ pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip)
pca963x_leds[reg] = led; pca963x_leds[reg] = led;
} }
pdata = devm_kzalloc(&client->dev, pdata = devm_kzalloc(dev, sizeof(struct pca963x_platform_data),
sizeof(struct pca963x_platform_data), GFP_KERNEL); GFP_KERNEL);
if (!pdata) if (!pdata)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -321,23 +328,23 @@ pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip) ...@@ -321,23 +328,23 @@ pca963x_get_pdata(struct i2c_client *client, struct pca963x_chipdef *chip)
pdata->leds.num_leds = chip->n_leds; pdata->leds.num_leds = chip->n_leds;
/* default to open-drain unless totem pole (push-pull) is specified */ /* default to open-drain unless totem pole (push-pull) is specified */
if (device_property_read_bool(&client->dev, "nxp,totem-pole")) if (device_property_read_bool(dev, "nxp,totem-pole"))
pdata->outdrv = PCA963X_TOTEM_POLE; pdata->outdrv = PCA963X_TOTEM_POLE;
else else
pdata->outdrv = PCA963X_OPEN_DRAIN; pdata->outdrv = PCA963X_OPEN_DRAIN;
/* default to software blinking unless hardware blinking is specified */ /* default to software blinking unless hardware blinking is specified */
if (device_property_read_bool(&client->dev, "nxp,hw-blink")) if (device_property_read_bool(dev, "nxp,hw-blink"))
pdata->blink_type = PCA963X_HW_BLINK; pdata->blink_type = PCA963X_HW_BLINK;
else else
pdata->blink_type = PCA963X_SW_BLINK; pdata->blink_type = PCA963X_SW_BLINK;
if (device_property_read_u32(&client->dev, "nxp,period-scale", if (device_property_read_u32(dev, "nxp,period-scale",
&chip->scaling)) &chip->scaling))
chip->scaling = 1000; chip->scaling = 1000;
/* default to non-inverted output, unless inverted is specified */ /* default to non-inverted output, unless inverted is specified */
if (device_property_read_bool(&client->dev, "nxp,inverted-out")) if (device_property_read_bool(dev, "nxp,inverted-out"))
pdata->dir = PCA963X_INVERTED; pdata->dir = PCA963X_INVERTED;
else else
pdata->dir = PCA963X_NORMAL; pdata->dir = PCA963X_NORMAL;
...@@ -357,6 +364,7 @@ MODULE_DEVICE_TABLE(of, of_pca963x_match); ...@@ -357,6 +364,7 @@ MODULE_DEVICE_TABLE(of, of_pca963x_match);
static int pca963x_probe(struct i2c_client *client, static int pca963x_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct pca963x *pca963x_chip; struct pca963x *pca963x_chip;
struct pca963x_led *pca963x; struct pca963x_led *pca963x;
struct pca963x_platform_data *pdata; struct pca963x_platform_data *pdata;
...@@ -364,29 +372,26 @@ static int pca963x_probe(struct i2c_client *client, ...@@ -364,29 +372,26 @@ static int pca963x_probe(struct i2c_client *client,
int i, err; int i, err;
chip = &pca963x_chipdefs[id->driver_data]; chip = &pca963x_chipdefs[id->driver_data];
pdata = dev_get_platdata(&client->dev); pdata = dev_get_platdata(dev);
if (!pdata) { if (!pdata) {
pdata = pca963x_get_pdata(client, chip); pdata = pca963x_get_pdata(dev, chip);
if (IS_ERR(pdata)) { if (IS_ERR(pdata)) {
dev_warn(&client->dev, "could not parse configuration\n"); dev_warn(dev, "could not parse configuration\n");
pdata = NULL; pdata = NULL;
} }
} }
if (pdata && (pdata->leds.num_leds < 1 || if (pdata && (pdata->leds.num_leds < 1 ||
pdata->leds.num_leds > chip->n_leds)) { pdata->leds.num_leds > chip->n_leds)) {
dev_err(&client->dev, "board info must claim 1-%d LEDs", dev_err(dev, "board info must claim 1-%d LEDs", chip->n_leds);
chip->n_leds);
return -EINVAL; return -EINVAL;
} }
pca963x_chip = devm_kzalloc(&client->dev, sizeof(*pca963x_chip), pca963x_chip = devm_kzalloc(dev, sizeof(*pca963x_chip), GFP_KERNEL);
GFP_KERNEL);
if (!pca963x_chip) if (!pca963x_chip)
return -ENOMEM; return -ENOMEM;
pca963x = devm_kcalloc(&client->dev, chip->n_leds, sizeof(*pca963x), pca963x = devm_kcalloc(dev, chip->n_leds, sizeof(*pca963x), GFP_KERNEL);
GFP_KERNEL);
if (!pca963x) if (!pca963x)
return -ENOMEM; return -ENOMEM;
...@@ -427,7 +432,7 @@ static int pca963x_probe(struct i2c_client *client, ...@@ -427,7 +432,7 @@ static int pca963x_probe(struct i2c_client *client,
if (pdata && pdata->blink_type == PCA963X_HW_BLINK) if (pdata && pdata->blink_type == PCA963X_HW_BLINK)
pca963x[i].led_cdev.blink_set = pca963x_blink_set; pca963x[i].led_cdev.blink_set = pca963x_blink_set;
err = led_classdev_register(&client->dev, &pca963x[i].led_cdev); err = led_classdev_register(dev, &pca963x[i].led_cdev);
if (err < 0) if (err < 0)
goto exit; goto exit;
} }
...@@ -436,8 +441,7 @@ static int pca963x_probe(struct i2c_client *client, ...@@ -436,8 +441,7 @@ static int pca963x_probe(struct i2c_client *client,
i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4)); i2c_smbus_write_byte_data(client, PCA963X_MODE1, BIT(4));
if (pdata) { if (pdata) {
u8 mode2 = i2c_smbus_read_byte_data(pca963x->chip->client, u8 mode2 = i2c_smbus_read_byte_data(client, PCA963X_MODE2);
PCA963X_MODE2);
/* Configure output: open-drain or totem pole (push-pull) */ /* Configure output: open-drain or totem pole (push-pull) */
if (pdata->outdrv == PCA963X_OPEN_DRAIN) if (pdata->outdrv == PCA963X_OPEN_DRAIN)
mode2 &= ~PCA963X_MODE2_OUTDRV; mode2 &= ~PCA963X_MODE2_OUTDRV;
...@@ -446,8 +450,7 @@ static int pca963x_probe(struct i2c_client *client, ...@@ -446,8 +450,7 @@ static int pca963x_probe(struct i2c_client *client,
/* Configure direction: normal or inverted */ /* Configure direction: normal or inverted */
if (pdata->dir == PCA963X_INVERTED) if (pdata->dir == PCA963X_INVERTED)
mode2 |= PCA963X_MODE2_INVRT; mode2 |= PCA963X_MODE2_INVRT;
i2c_smbus_write_byte_data(pca963x->chip->client, PCA963X_MODE2, i2c_smbus_write_byte_data(client, PCA963X_MODE2, mode2);
mode2);
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment