linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Murphy <dmurphy@ti.com>
To: Jacek Anaszewski <jacek.anaszewski@gmail.com>, <pavel@ucw.cz>
Cc: <linux-leds@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v9 07/15] leds: lp50xx: Add the LP50XX family of the RGB LED driver
Date: Thu, 26 Sep 2019 06:59:34 -0500	[thread overview]
Message-ID: <d4126720-25ea-7c15-2424-b7f16b25c3b4@ti.com> (raw)
In-Reply-To: <4293530f-70ae-0796-e7a7-0c6564e71132@gmail.com>

Jacek

On 9/25/19 4:27 PM, Jacek Anaszewski wrote:
> Dan,
>
> On 9/25/19 7:46 PM, Dan Murphy wrote:

<big_snip>

>> +
>> +static int lp50xx_brightness_set(struct led_classdev *cdev,
>> +			     enum led_brightness brightness)
>> +{
>> +	struct lp50xx_led *led = container_of(cdev, struct lp50xx_led, led_dev);
>> +	const struct lp50xx_chip_info *led_chip = led->priv->chip_info;
>> +	struct led_mc_color_entry *color_data;
>> +	u8 led_offset, reg_val, reg_color_offset;
>> +	int ret = 0;
>> +
>> +	mutex_lock(&led->priv->lock);
>> +
>> +	if (led->ctrl_bank_enabled)
>> +		reg_val = led_chip->bank_brt_reg;
>> +	else
>> +		reg_val = led_chip->led_brightness0_reg +
>> +			  led->led_number;
>> +
>> +	ret = regmap_write(led->priv->regmap, reg_val, brightness);
>> +	if (ret) {
>> +		dev_err(&led->priv->client->dev,
>> +			"Cannot write brightness value %d\n", ret);
>> +		goto out;
>> +	}
>> +
>> +	list_for_each_entry(color_data, &led->mc_cdev.color_list, list) {
>> +		if (color_data->led_color_id == LED_COLOR_ID_RED)
>> +			reg_color_offset = 0;
>> +		else if (color_data->led_color_id == LED_COLOR_ID_GREEN)
>> +			reg_color_offset = 1;
>> +		else if (color_data->led_color_id == LED_COLOR_ID_BLUE)
>> +			reg_color_offset = 2;
>> +		else
>> +			continue;
> This else case is quite erroneous. Sheer continue is just ignoring
> serious problem. I'd log the problem and return -EINVAL.
Ack.
>
> Also, you could have a macro for mapping color_id to offset.
If the code needed to do this more then once I could justify a macro.  
But this is the only instance of this check.
>
>> +
>> +		if (led->ctrl_bank_enabled) {
>> +			reg_val = led_chip->bank_mix_reg + reg_color_offset;
>> +		} else {
>> +			led_offset = (led->led_number * 3)  + reg_color_offset;
>> +			reg_val = led_chip->mix_out0_reg + led_offset;
>> +		}
>> +
>> +		ret = regmap_write(led->priv->regmap, reg_val,
>> +				   color_data->intensity);
>> +		if (ret) {
>> +			dev_err(&led->priv->client->dev,
>> +				"Cannot write intensity value %d\n", ret);
>> +			goto out;
>> +		}
>> +	}
>> +out:
>> +	mutex_unlock(&led->priv->lock);
>> +	return ret;
>> +}
>> +
>> +static enum led_brightness lp50xx_brightness_get(struct led_classdev *cdev)
>> +{
>> +	struct lp50xx_led *led = container_of(cdev, struct lp50xx_led, led_dev);
>> +	const struct lp50xx_chip_info *led_chip = led->priv->chip_info;
>> +	unsigned int brt_val;
>> +	u8 reg_val;
>> +	int ret;
>> +
>> +	mutex_lock(&led->priv->lock);
>> +
>> +	if (led->ctrl_bank_enabled)
>> +		reg_val = led_chip->bank_brt_reg;
>> +	else
>> +		reg_val = led_chip->led_brightness0_reg + led->led_number;
>> +
>> +	ret = regmap_read(led->priv->regmap, reg_val, &brt_val);
>> +
>> +	mutex_unlock(&led->priv->lock);
>> +
>> +	return brt_val;
>> +}
>> +
>> +static int lp50xx_set_banks(struct lp50xx *priv, u32 led_banks[])
>> +{
>> +	u8 led_config_lo, led_config_hi;
>> +	u32 bank_enable_mask = 0;
>> +	int ret;
>> +	int i;
>> +
>> +	for (i = 0; i < priv->chip_info->num_leds; i++)
>> +		bank_enable_mask |= (1 << led_banks[i]);
>> +
>> +	led_config_lo = (u8)(bank_enable_mask & 0xff);
>> +	led_config_hi = (u8)(bank_enable_mask >> 8) & 0xff;
>> +
>> +	ret = regmap_write(priv->regmap, LP50XX_LED_CFG0, led_config_lo);
>> +	if (ret)
>> +		return ret;
>> +
>> +	if (led_config_hi)
> Now I think that less questionable would be writing led_config_hi always
> for devices that have CFG1 register. IOW write led_config_hi also
> when it equals 0.

Ack.  I will have to modify the check to only write this for LP5030/36 
as those are the only 2 that have the CFG1 register.

>
>> +		ret = regmap_write(priv->regmap, LP5036_LED_CFG1,
>> +				   led_config_hi);
>> +
>> +	return ret;
>> +}
>> +
>> +static int lp50xx_reset(struct lp50xx *priv)
>> +{
>> +	if (priv->enable_gpio)
>> +		return gpiod_direction_output(priv->enable_gpio, 1);
>> +	else
>> +		return regmap_write(priv->regmap, priv->chip_info->reset_reg,
>> +				    LP50XX_SW_RESET);
>> +}
>> +
>> +static int lp50xx_enable_disable(struct lp50xx *priv, u8 enable_disable)
>> +{
>> +	return regmap_write(priv->regmap, LP50XX_DEV_CFG0, enable_disable);
>> +}
>> +
>> +static int lp50xx_probe_dt(struct lp50xx *priv)
>> +{
>> +	u32 led_banks[LP5036_MAX_LED_MODULES];
>> +	struct fwnode_handle *child = NULL;
>> +	struct fwnode_handle *led_node = NULL;
>> +	struct led_init_data init_data;
>> +	struct lp50xx_led *led;
>> +	int num_colors;
>> +	u32 color_id;
>> +	int led_number;
>> +	size_t i = 0;
>> +	int ret;
>> +
>> +	priv->enable_gpio = devm_gpiod_get_optional(&priv->client->dev,
>> +						   "enable", GPIOD_OUT_LOW);
>> +	if (IS_ERR(priv->enable_gpio)) {
>> +		ret = PTR_ERR(priv->enable_gpio);
>> +		dev_err(&priv->client->dev, "Failed to get enable gpio: %d\n",
>> +			ret);
>> +		return ret;
>> +	}
>> +
>> +	priv->regulator = devm_regulator_get(&priv->client->dev, "vled");
>> +	if (IS_ERR(priv->regulator))
>> +		priv->regulator = NULL;
>> +
>> +	device_for_each_child_node(&priv->client->dev, child) {
>> +		led = &priv->leds[i];
>> +		if (fwnode_property_present(child, "ti,led-bank")) {
>> +			ret = fwnode_property_read_u32_array(child,
>> +							     "ti,led-bank",
>> +							     NULL, 0);
>> +			ret = fwnode_property_read_u32_array(child,
>> +							     "ti,led-bank",
>> +							     led_banks,
>> +							     ret);
>> +
>> +			priv->num_of_banked_leds = ARRAY_SIZE(led_banks);
>> +
>> +			ret = lp50xx_set_banks(priv, led_banks);
>> +			if (ret) {
>> +				dev_err(&priv->client->dev,
>> +					"Cannot setup banked LEDs\n");
>> +				fwnode_handle_put(child);
>> +				goto child_out;
>> +			}
>> +			led->ctrl_bank_enabled = 1;
>> +
>> +		} else {
>> +			ret = fwnode_property_read_u32(child, "reg",
>> +					       &led_number);
> Not checking ret val?
Yes it is after the else case.  But I should probably check return for 
the led-bank
>
>> +
>> +			led->led_number = led_number;
>> +		}
>> +		if (ret) {
>> +			dev_err(&priv->client->dev,
>> +				"led sourcing property missing\n");
>> +			fwnode_handle_put(child);
>> +			goto child_out;
>> +		}
>> +

Dan

[...]


  reply	other threads:[~2019-09-26 11:54 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 17:46 [PATCH v9 00/15] Multicolor Framework Dan Murphy
2019-09-25 17:46 ` [PATCH v9 01/15] leds: multicolor: Add sysfs interface definition Dan Murphy
2019-09-25 20:58   ` Jacek Anaszewski
2019-09-26 11:10   ` Pavel Machek
2019-09-26 12:08     ` Dan Murphy
2019-09-25 17:46 ` [PATCH v9 02/15] dt: bindings: Add multicolor class dt bindings documention Dan Murphy
2019-09-25 17:46 ` [PATCH v9 03/15] dt-bindings: leds: Add multicolor ID to the color ID list Dan Murphy
2019-09-25 17:46 ` [PATCH v9 04/15] " Dan Murphy
2019-09-25 17:46 ` [PATCH v9 05/15] leds: multicolor: Introduce a multicolor class definition Dan Murphy
2019-09-25 21:12   ` Jacek Anaszewski
2019-09-26 11:52     ` Dan Murphy
2019-09-28 10:09       ` Jacek Anaszewski
2019-09-28 18:31         ` Jacek Anaszewski
2019-09-25 17:46 ` [PATCH v9 06/15] dt: bindings: lp50xx: Introduce the lp50xx family of RGB drivers Dan Murphy
2019-09-25 17:46 ` [PATCH v9 07/15] leds: lp50xx: Add the LP50XX family of the RGB LED driver Dan Murphy
2019-09-25 21:27   ` Jacek Anaszewski
2019-09-26 11:59     ` Dan Murphy [this message]
2019-09-28 10:29       ` Jacek Anaszewski
2019-09-25 17:46 ` [PATCH v9 08/15] dt: bindings: lp55xx: Be consistent in the document with LED Dan Murphy
2019-09-25 21:31   ` Jacek Anaszewski
2019-09-26 12:00     ` Dan Murphy
2019-09-25 17:46 ` [PATCH v9 09/15] dt: bindings: lp55xx: Update binding for Multicolor Framework Dan Murphy
2019-09-25 21:34   ` Jacek Anaszewski
2019-09-26 12:00     ` Dan Murphy
2019-09-25 17:46 ` [PATCH v9 10/15] ARM: dts: n900: Add reg property to the LP5523 channel node Dan Murphy
2019-09-25 17:46 ` [PATCH v9 11/15] ARM: dts: imx6dl-yapp4: Add reg property to the lp5562 " Dan Murphy
2019-09-25 18:00   ` Fabio Estevam
2019-09-25 18:16     ` Dan Murphy
2019-09-25 17:46 ` [PATCH v9 12/15] ARM: dts: ste-href: Add reg property to the LP5521 channel nodes Dan Murphy
2019-10-04 21:30   ` Linus Walleij
2019-09-25 17:46 ` [PATCH v9 13/15] leds: lp55xx: Update the lp55xx to use the multi color framework Dan Murphy
2019-09-25 22:00   ` Jacek Anaszewski
2019-09-26 12:02     ` Dan Murphy
2019-09-29 13:01       ` Jacek Anaszewski
2019-09-30 16:31         ` Dan Murphy
2019-09-30 20:34           ` Dan Murphy
2019-09-25 17:46 ` [PATCH v9 14/15] leds: lp55xx: Fix checkpatch file permissions issues Dan Murphy
2019-09-25 17:46 ` [PATCH v9 15/15] leds: lp5523: Fix checkpatch issues in the code Dan Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d4126720-25ea-7c15-2424-b7f16b25c3b4@ti.com \
    --to=dmurphy@ti.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).