[PATCH v7 11/13] leds: rgb: mt6370: Add MediaTek MT6370 current sink type LED Indicator support

Andy Shevchenko andy.shevchenko at gmail.com
Fri Aug 5 11:07:18 UTC 2022


On Fri, Aug 5, 2022 at 9:07 AM ChiaEn Wu <peterwu.pub at gmail.com> wrote:
>
> From: ChiYuan Huang <cy_huang at richtek.com>
>
> The MediaTek MT6370 is a highly-integrated smart power management IC,
> which includes a single cell Li-Ion/Li-Polymer switching battery
> charger, a USB Type-C & Power Delivery (PD) controller, dual
> Flash LED current sources, a RGB LED driver, a backlight WLED driver,
> a display bias driver and a general LDO for portable devices.
>
> Add a support for the MediaTek MT6370 Current Sink Type LED Indicator

Add support

(This is also for all other commit messages)

> driver. It can control four channels current-sink RGB LEDs with 3 modes,

3 modes:

> constant current, PWM, and breath mode.

...

> +static int mt6370_gen_breath_pattern(struct mt6370_priv *priv,
> +                                    struct led_pattern *pattern, u32 len,
> +                                    u8 *pattern_val, u32 val_len)
> +{
> +       enum mt6370_led_ranges sel_range;
> +       struct led_pattern *curr;
> +       unsigned int sel;
> +       u32 val = 0;
> +       int i;
> +
> +       if (len < P_MAX_PATTERNS && val_len < P_MAX_PATTERNS / 2)
> +               return -EINVAL;
> +
> +       /*
> +        * Pattern list
> +        * tr1:  byte 0, b'[7: 4]
> +        * tr2:  byte 0, b'[3: 0]
> +        * tf1:  byte 1, b'[7: 4]
> +        * tf2:  byte 1, b'[3: 0]
> +        * ton:  byte 2, b'[7: 4]
> +        * toff: byte 2, b'[3: 0]
> +        */
> +       for (i = 0; i < P_MAX_PATTERNS; i++) {
> +               curr = pattern + i;
> +
> +               sel_range = i == P_LED_TOFF ? R_LED_TOFF : R_LED_TRFON;
> +
> +               linear_range_get_selector_within(priv->ranges + sel_range,
> +                                                curr->delta_t, &sel);
> +
> +               val <<= i % 2 == 0 ? 8 : 0;
> +               val |= sel << (i % 2 == 0 ? 4 : 0);

It's too cryptic, why not simply:

  if (i % 2) {
    val |= sel;
  } else {
    val <<= 8;
    val |= sel << 4;
  }

?

> +       }
> +
> +       put_unaligned_be24(val, pattern_val);
> +
> +       return 0;
> +}

...

> +       const char * const states[] = { "off", "keep", "on" };

> +       ret = fwnode_property_read_string(init_data->fwnode, "default-state",
> +                                         &stat_str);
> +       if (!ret) {
> +               ret = match_string(states, ARRAY_SIZE(states), stat_str);
> +               if (ret < 0)
> +                       ret = STATE_OFF;
> +
> +               led->default_state = ret;
> +       }

Replace this by using led_init_default_state_get().

-- 
With Best Regards,
Andy Shevchenko


More information about the dri-devel mailing list