linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Daniel Mack <daniel.mack@holoplot.com>
Cc: linux-leds@vger.kernel.org, Daniel Mack <daniel@zonque.org>
Subject: Re: [PATCH v3 3/3] leds: is31f132xx: add support for is31fl3293
Date: Wed, 26 Nov 2025 15:14:04 +0000	[thread overview]
Message-ID: <20251126151404.GG3070764@google.com> (raw)
In-Reply-To: <20251121113557.77418-4-daniel.mack@holoplot.com>

On Fri, 21 Nov 2025, Daniel Mack wrote:

> From: Daniel Mack <daniel@zonque.org>
> 
> This chip supports 3 LED channels with 4096 possible PWM values.
> 
> Extend the driver to support this variant:
> 
>  * Make brightness steps configurable per device type
>  * Handle dual-register brightness updates
>  * Allow to specify values to write into the PWM update register
>  * Add custom init and shutdown function for 3293 variant
>  * Init registers after parsing DT properties
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>
> ---
> v1 -> v2: address styling issues
> 
>  drivers/leds/leds-is31fl32xx.c | 137 +++++++++++++++++++++++++++++++--
>  1 file changed, 129 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/leds/leds-is31fl32xx.c b/drivers/leds/leds-is31fl32xx.c
> index 388d6a0b6932..05e28257ca4b 100644
> --- a/drivers/leds/leds-is31fl32xx.c
> +++ b/drivers/leds/leds-is31fl32xx.c
> @@ -32,10 +32,25 @@
>  #define IS31FL3216_CONFIG_SSD_ENABLE  BIT(7)
>  #define IS31FL3216_CONFIG_SSD_DISABLE 0
>  
> +/* Registers for IS31FL3293 */
> +#define IS31FL3293_SHUTDOWN_REG 0x01
> +#define IS31FL3293_SHUTDOWN_SSD_DISABLE  BIT(0)
> +#define IS31FL3293_SHUTDOWN_EN1 BIT(4)
> +#define IS31FL3293_SHUTDOWN_EN2 BIT(5)
> +#define IS31FL3293_SHUTDOWN_EN3 BIT(6)
> +#define IS31FL3293_GCC_REG 0x03
> +#define IS31FL3293_GCC_LEVEL_MAX 0x3f
> +#define IS31FL3293_CL_REG 0x10
> +#define IS31FL3293_COLOR_UPDATE_REG 0x27
> +#define IS31FL3293_COLOR_UPDATE_MAGIC 0xc5
> +#define IS31FL3293_RESET_REG 0x3c
> +#define IS31FL3293_RESET_MAGIC 0xc5
> +
>  struct is31fl32xx_priv;
>  struct is31fl32xx_led_data {
>  	struct led_classdev cdev;
>  	u8 channel; /* 1-based, max priv->cdef->channels */
> +	u32 max_microamp;
>  	struct is31fl32xx_priv *priv;
>  };
>  
> @@ -51,12 +66,14 @@ struct is31fl32xx_priv {
>   * @channels            : Number of LED channels
>   * @shutdown_reg        : address of Shutdown register (optional)
>   * @pwm_update_reg      : address of PWM Update register
> + * @pwm_update_value    : value to write to PWM Update register
>   * @global_control_reg  : address of Global Control register (optional)
>   * @reset_reg           : address of Reset register (optional)
>   * @pwm_register_base   : address of first PWM register
>   * @pwm_registers_reversed: : true if PWM registers count down instead of up
>   * @led_control_register_base : address of first LED control register (optional)
>   * @enable_bits_per_led_control_register: number of LEDs enable bits in each
> + * @brightness_steps    : number of brightness steps supported by the chip
>   * @reset_func          : pointer to reset function
>   * @sw_shutdown_func    : pointer to software shutdown function
>   *
> @@ -74,12 +91,14 @@ struct is31fl32xx_chipdef {
>  	u8	channels;
>  	u8	shutdown_reg;
>  	u8	pwm_update_reg;
> +	u8	pwm_update_value;
>  	u8	global_control_reg;
>  	u8	reset_reg;
>  	u8	pwm_register_base;
>  	bool	pwm_registers_reversed;
>  	u8	led_control_register_base;
>  	u8	enable_bits_per_led_control_register;
> +	u16	brightness_steps;
>  	int (*reset_func)(struct is31fl32xx_priv *priv);
>  	int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable);
>  };
> @@ -148,6 +167,62 @@ static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv,
>  	return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value);
>  }
>  
> +/*
> + * Custom Reset function for IS31FL3293. We need to set the global current limit
> + * and write to the color update register once.
> + */
> +static int is31fl3293_reset(struct is31fl32xx_priv *priv)
> +{
> +	int i, ret;
> +
> +	ret = is31fl32xx_write(priv, IS31FL3293_RESET_REG,
> +			       IS31FL3293_RESET_MAGIC);
> +	if (ret)
> +		return ret;
> +
> +	/* Set the global current limit to maximum */
> +	ret = is31fl32xx_write(priv, IS31FL3293_GCC_REG,
> +			       IS31FL3293_GCC_LEVEL_MAX);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0; i < priv->num_leds; i++) {
> +		struct is31fl32xx_led_data *led_data = &priv->leds[i];
> +		int current_level_reg = IS31FL3293_CL_REG + led_data->channel - 1;
> +		int microamp = max(led_data->max_microamp, 20000);
> +		int current_level = (microamp * 0xff) / 20000;

Nit: Why 20000?  Please define it instead of using magic numbers for things.

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2025-11-26 15:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-21 11:35 [PATCH v3 0/3] leds: is31f132xx: add support for is31fl3293 Daniel Mack
2025-11-21 11:35 ` [PATCH v3 1/3] dt-bindings: leds: add issi,is31fl3293 to leds-is31fl32xx Daniel Mack
2025-11-21 11:35 ` [PATCH v3 2/3] leds: is31f132xx: re-order code to remove forward declarations Daniel Mack
2025-11-21 11:35 ` [PATCH v3 3/3] leds: is31f132xx: add support for is31fl3293 Daniel Mack
2025-11-26 15:14   ` Lee Jones [this message]
2025-11-26 15:13 ` [PATCH v3 0/3] " Lee Jones

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=20251126151404.GG3070764@google.com \
    --to=lee@kernel.org \
    --cc=daniel.mack@holoplot.com \
    --cc=daniel@zonque.org \
    --cc=linux-leds@vger.kernel.org \
    /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).