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

leds: lm3697: cosmetic change: use helper variable, reverse christmas tree

Use helper variable dev instead of always writing &client->dev, or
&priv->client->dev, or even &led->priv->client->dev.

With one more line moved reverse christmas tree is also achieved.
Signed-off-by: default avatarMarek Behún <marek.behun@nic.cz>
Reviewed-by: default avatarDan Murphy <dmurphy@ti.com>
Signed-off-by: default avatarPavel Machek <pavel@ucw.cz>
parent 3a953dc3
...@@ -115,6 +115,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev, ...@@ -115,6 +115,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
struct lm3697_led *led = container_of(led_cdev, struct lm3697_led, struct lm3697_led *led = container_of(led_cdev, struct lm3697_led,
led_dev); led_dev);
int ctrl_en_val = (1 << led->control_bank); int ctrl_en_val = (1 << led->control_bank);
struct device *dev = led->priv->dev;
int ret; int ret;
mutex_lock(&led->priv->lock); mutex_lock(&led->priv->lock);
...@@ -123,7 +124,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev, ...@@ -123,7 +124,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
ret = regmap_update_bits(led->priv->regmap, LM3697_CTRL_ENABLE, ret = regmap_update_bits(led->priv->regmap, LM3697_CTRL_ENABLE,
ctrl_en_val, ~ctrl_en_val); ctrl_en_val, ~ctrl_en_val);
if (ret) { if (ret) {
dev_err(&led->priv->client->dev, "Cannot write ctrl register\n"); dev_err(dev, "Cannot write ctrl register\n");
goto brightness_out; goto brightness_out;
} }
...@@ -131,8 +132,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev, ...@@ -131,8 +132,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
} else { } else {
ret = ti_lmu_common_set_brightness(&led->lmu_data, brt_val); ret = ti_lmu_common_set_brightness(&led->lmu_data, brt_val);
if (ret) { if (ret) {
dev_err(&led->priv->client->dev, dev_err(dev, "Cannot write brightness\n");
"Cannot write brightness\n");
goto brightness_out; goto brightness_out;
} }
...@@ -141,8 +141,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev, ...@@ -141,8 +141,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
LM3697_CTRL_ENABLE, LM3697_CTRL_ENABLE,
ctrl_en_val, ctrl_en_val); ctrl_en_val, ctrl_en_val);
if (ret) { if (ret) {
dev_err(&led->priv->client->dev, dev_err(dev, "Cannot enable the device\n");
"Cannot enable the device\n");
goto brightness_out; goto brightness_out;
} }
...@@ -157,6 +156,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev, ...@@ -157,6 +156,7 @@ static int lm3697_brightness_set(struct led_classdev *led_cdev,
static int lm3697_init(struct lm3697 *priv) static int lm3697_init(struct lm3697 *priv)
{ {
struct device *dev = priv->dev;
struct lm3697_led *led; struct lm3697_led *led;
int i, ret; int i, ret;
...@@ -165,26 +165,26 @@ static int lm3697_init(struct lm3697 *priv) ...@@ -165,26 +165,26 @@ static int lm3697_init(struct lm3697 *priv)
} else { } else {
ret = regmap_write(priv->regmap, LM3697_RESET, LM3697_SW_RESET); ret = regmap_write(priv->regmap, LM3697_RESET, LM3697_SW_RESET);
if (ret) { if (ret) {
dev_err(&priv->client->dev, "Cannot reset the device\n"); dev_err(dev, "Cannot reset the device\n");
goto out; goto out;
} }
} }
ret = regmap_write(priv->regmap, LM3697_CTRL_ENABLE, 0x0); ret = regmap_write(priv->regmap, LM3697_CTRL_ENABLE, 0x0);
if (ret) { if (ret) {
dev_err(&priv->client->dev, "Cannot write ctrl enable\n"); dev_err(dev, "Cannot write ctrl enable\n");
goto out; goto out;
} }
ret = regmap_write(priv->regmap, LM3697_OUTPUT_CONFIG, priv->bank_cfg); ret = regmap_write(priv->regmap, LM3697_OUTPUT_CONFIG, priv->bank_cfg);
if (ret) if (ret)
dev_err(&priv->client->dev, "Cannot write OUTPUT config\n"); dev_err(dev, "Cannot write OUTPUT config\n");
for (i = 0; i < LM3697_MAX_CONTROL_BANKS; i++) { for (i = 0; i < LM3697_MAX_CONTROL_BANKS; i++) {
led = &priv->leds[i]; led = &priv->leds[i];
ret = ti_lmu_common_set_ramp(&led->lmu_data); ret = ti_lmu_common_set_ramp(&led->lmu_data);
if (ret) if (ret)
dev_err(&priv->client->dev, "Setting the ramp rate failed\n"); dev_err(dev, "Setting the ramp rate failed\n");
} }
out: out:
return ret; return ret;
...@@ -193,37 +193,37 @@ static int lm3697_init(struct lm3697 *priv) ...@@ -193,37 +193,37 @@ static int lm3697_init(struct lm3697 *priv)
static int lm3697_probe_dt(struct lm3697 *priv) static int lm3697_probe_dt(struct lm3697 *priv)
{ {
struct fwnode_handle *child = NULL; struct fwnode_handle *child = NULL;
struct device *dev = priv->dev;
struct lm3697_led *led; struct lm3697_led *led;
int ret = -EINVAL;
int control_bank; int control_bank;
size_t i = 0; size_t i = 0;
int ret = -EINVAL;
int j; int j;
priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev, priv->enable_gpio = devm_gpiod_get_optional(dev, "enable",
"enable", GPIOD_OUT_LOW); GPIOD_OUT_LOW);
if (IS_ERR(priv->enable_gpio)) { if (IS_ERR(priv->enable_gpio)) {
ret = PTR_ERR(priv->enable_gpio); ret = PTR_ERR(priv->enable_gpio);
dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n", dev_err(dev, "Failed to get enable gpio: %d\n", ret);
ret);
return ret; return ret;
} }
priv->regulator = devm_regulator_get(&priv->client->dev, "vled"); priv->regulator = devm_regulator_get(dev, "vled");
if (IS_ERR(priv->regulator)) if (IS_ERR(priv->regulator))
priv->regulator = NULL; priv->regulator = NULL;
device_for_each_child_node(priv->dev, child) { device_for_each_child_node(dev, child) {
struct led_init_data init_data = {}; struct led_init_data init_data = {};
ret = fwnode_property_read_u32(child, "reg", &control_bank); ret = fwnode_property_read_u32(child, "reg", &control_bank);
if (ret) { if (ret) {
dev_err(&priv->client->dev, "reg property missing\n"); dev_err(dev, "reg property missing\n");
fwnode_handle_put(child); fwnode_handle_put(child);
goto child_out; goto child_out;
} }
if (control_bank > LM3697_CONTROL_B) { if (control_bank > LM3697_CONTROL_B) {
dev_err(&priv->client->dev, "reg property is invalid\n"); dev_err(dev, "reg property is invalid\n");
ret = -EINVAL; ret = -EINVAL;
fwnode_handle_put(child); fwnode_handle_put(child);
goto child_out; goto child_out;
...@@ -231,10 +231,10 @@ static int lm3697_probe_dt(struct lm3697 *priv) ...@@ -231,10 +231,10 @@ static int lm3697_probe_dt(struct lm3697 *priv)
led = &priv->leds[i]; led = &priv->leds[i];
ret = ti_lmu_common_get_brt_res(&priv->client->dev, ret = ti_lmu_common_get_brt_res(dev, child, &led->lmu_data);
child, &led->lmu_data);
if (ret) if (ret)
dev_warn(&priv->client->dev, "brightness resolution property missing\n"); dev_warn(dev,
"brightness resolution property missing\n");
led->control_bank = control_bank; led->control_bank = control_bank;
led->lmu_data.regmap = priv->regmap; led->lmu_data.regmap = priv->regmap;
...@@ -247,7 +247,7 @@ static int lm3697_probe_dt(struct lm3697 *priv) ...@@ -247,7 +247,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)
led->num_leds = fwnode_property_count_u32(child, "led-sources"); led->num_leds = fwnode_property_count_u32(child, "led-sources");
if (led->num_leds > LM3697_MAX_LED_STRINGS) { if (led->num_leds > LM3697_MAX_LED_STRINGS) {
dev_err(&priv->client->dev, "Too many LED strings defined\n"); dev_err(dev, "Too many LED strings defined\n");
continue; continue;
} }
...@@ -255,7 +255,7 @@ static int lm3697_probe_dt(struct lm3697 *priv) ...@@ -255,7 +255,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)
led->hvled_strings, led->hvled_strings,
led->num_leds); led->num_leds);
if (ret) { if (ret) {
dev_err(&priv->client->dev, "led-sources property missing\n"); dev_err(dev, "led-sources property missing\n");
fwnode_handle_put(child); fwnode_handle_put(child);
goto child_out; goto child_out;
} }
...@@ -264,10 +264,9 @@ static int lm3697_probe_dt(struct lm3697 *priv) ...@@ -264,10 +264,9 @@ static int lm3697_probe_dt(struct lm3697 *priv)
priv->bank_cfg |= priv->bank_cfg |=
(led->control_bank << led->hvled_strings[j]); (led->control_bank << led->hvled_strings[j]);
ret = ti_lmu_common_get_ramp_params(&priv->client->dev, ret = ti_lmu_common_get_ramp_params(dev, child, &led->lmu_data);
child, &led->lmu_data);
if (ret) if (ret)
dev_warn(&priv->client->dev, "runtime-ramp properties missing\n"); dev_warn(dev, "runtime-ramp properties missing\n");
fwnode_property_read_string(child, "linux,default-trigger", fwnode_property_read_string(child, "linux,default-trigger",
&led->led_dev.default_trigger); &led->led_dev.default_trigger);
...@@ -281,11 +280,10 @@ static int lm3697_probe_dt(struct lm3697 *priv) ...@@ -281,11 +280,10 @@ static int lm3697_probe_dt(struct lm3697 *priv)
led->led_dev.max_brightness = led->lmu_data.max_brightness; led->led_dev.max_brightness = led->lmu_data.max_brightness;
led->led_dev.brightness_set_blocking = lm3697_brightness_set; led->led_dev.brightness_set_blocking = lm3697_brightness_set;
ret = devm_led_classdev_register_ext(priv->dev, &led->led_dev, ret = devm_led_classdev_register_ext(dev, &led->led_dev,
&init_data); &init_data);
if (ret) { if (ret) {
dev_err(&priv->client->dev, "led register err: %d\n", dev_err(dev, "led register err: %d\n", ret);
ret);
fwnode_handle_put(child); fwnode_handle_put(child);
goto child_out; goto child_out;
} }
...@@ -300,18 +298,18 @@ static int lm3697_probe_dt(struct lm3697 *priv) ...@@ -300,18 +298,18 @@ static int lm3697_probe_dt(struct lm3697 *priv)
static int lm3697_probe(struct i2c_client *client, static int lm3697_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct lm3697 *led; struct lm3697 *led;
int count; int count;
int ret; int ret;
count = device_get_child_node_count(&client->dev); count = device_get_child_node_count(dev);
if (!count) { if (!count) {
dev_err(&client->dev, "LEDs are not defined in device tree!"); dev_err(dev, "LEDs are not defined in device tree!");
return -ENODEV; return -ENODEV;
} }
led = devm_kzalloc(&client->dev, struct_size(led, leds, count), led = devm_kzalloc(dev, struct_size(led, leds, count), GFP_KERNEL);
GFP_KERNEL);
if (!led) if (!led)
return -ENOMEM; return -ENOMEM;
...@@ -319,12 +317,11 @@ static int lm3697_probe(struct i2c_client *client, ...@@ -319,12 +317,11 @@ static int lm3697_probe(struct i2c_client *client,
i2c_set_clientdata(client, led); i2c_set_clientdata(client, led);
led->client = client; led->client = client;
led->dev = &client->dev; led->dev = dev;
led->regmap = devm_regmap_init_i2c(client, &lm3697_regmap_config); led->regmap = devm_regmap_init_i2c(client, &lm3697_regmap_config);
if (IS_ERR(led->regmap)) { if (IS_ERR(led->regmap)) {
ret = PTR_ERR(led->regmap); ret = PTR_ERR(led->regmap);
dev_err(&client->dev, "Failed to allocate register map: %d\n", dev_err(dev, "Failed to allocate register map: %d\n", ret);
ret);
return ret; return ret;
} }
...@@ -338,12 +335,13 @@ static int lm3697_probe(struct i2c_client *client, ...@@ -338,12 +335,13 @@ static int lm3697_probe(struct i2c_client *client,
static int lm3697_remove(struct i2c_client *client) static int lm3697_remove(struct i2c_client *client)
{ {
struct lm3697 *led = i2c_get_clientdata(client); struct lm3697 *led = i2c_get_clientdata(client);
struct device *dev = &led->client->dev;
int ret; int ret;
ret = regmap_update_bits(led->regmap, LM3697_CTRL_ENABLE, ret = regmap_update_bits(led->regmap, LM3697_CTRL_ENABLE,
LM3697_CTRL_A_B_EN, 0); LM3697_CTRL_A_B_EN, 0);
if (ret) { if (ret) {
dev_err(&led->client->dev, "Failed to disable the device\n"); dev_err(dev, "Failed to disable the device\n");
return ret; return ret;
} }
...@@ -353,8 +351,7 @@ static int lm3697_remove(struct i2c_client *client) ...@@ -353,8 +351,7 @@ static int lm3697_remove(struct i2c_client *client)
if (led->regulator) { if (led->regulator) {
ret = regulator_disable(led->regulator); ret = regulator_disable(led->regulator);
if (ret) if (ret)
dev_err(&led->client->dev, dev_err(dev, "Failed to disable regulator\n");
"Failed to disable regulator\n");
} }
mutex_destroy(&led->lock); mutex_destroy(&led->lock);
......
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