linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: ChiYuan Huang <cy_huang@richtek.com>
Cc: ChiaEn Wu <chiaen_wu@richtek.com>,
	corbet@lwn.net, pavel@ucw.cz, matthias.bgg@gmail.com,
	andriy.shevchenko@linux.intel.com, jacek.anaszewski@gmail.com,
	angelogioacchino.delregno@collabora.com,
	linux-doc@vger.kernel.org, peterwu.pub@gmail.com,
	linux-leds@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	szunichen@gmail.com
Subject: Re: [PATCH v17 RESEND 2/3] leds: flash: mt6370: Add MediaTek MT6370 flashlight support
Date: Thu, 9 Mar 2023 17:24:48 +0000	[thread overview]
Message-ID: <20230309172448.GU9667@google.com> (raw)
In-Reply-To: <20230309014927.GA12537@linuxcarl2.richtek.com>

On Thu, 09 Mar 2023, ChiYuan Huang wrote:

> On Wed, Mar 08, 2023 at 01:54:33PM +0000, Lee Jones wrote:
> Hi, Lee:
> > On Tue, 07 Mar 2023, ChiYuan Huang wrote:
> >
> > > Hi, Lee:
> > >    Reply below the comments.
> > >
> > > On Sun, Mar 05, 2023 at 10:06:08AM +0000, Lee Jones wrote:
> > > > On Thu, 23 Feb 2023, ChiaEn Wu wrote:
> > > >
> > > > > From: ChiYuan Huang <cy_huang@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 support for the MT6370 Flash LED driver. Flash LED in MT6370
> > > > > has 2 channels and support torch/strobe mode.
> > > > >
> > > > > Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> > > > > Co-developed-by: Alice Chen <alice_chen@richtek.com>
> > > > > Signed-off-by: Alice Chen <alice_chen@richtek.com>
> > > > > Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
> > > > > Signed-off-by: ChiaEn Wu <chiaen_wu@richtek.com>
> > > > > ---
> > > > > v17
> > > > > - Update the year of Copyright from 2022 to 2023
> > > > >
> > > > > ---
> > > > >  drivers/leds/flash/Kconfig             |  13 +
> > > > >  drivers/leds/flash/Makefile            |   1 +
> > > > >  drivers/leds/flash/leds-mt6370-flash.c | 596 +++++++++++++++++++++++++++++++++
> > > > >  3 files changed, 610 insertions(+)
> > > > >  create mode 100644 drivers/leds/flash/leds-mt6370-flash.c
> >
> > [...]
> >
> > > > > +static int _mt6370_flash_brightness_set(struct led_classdev_flash *fl_cdev,
> > > > > +					u32 brightness)
> > > > > +{
> > > > > +	struct mt6370_led *led = to_mt6370_led(fl_cdev, flash);
> > > > > +	struct mt6370_priv *priv = led->priv;
> > > > > +	struct led_flash_setting *setting = &fl_cdev->brightness;
> > > > > +	u32 val = (brightness - setting->min) / setting->step;
> > > > > +	int ret, i;
> > > > > +
> > > > > +	if (led->led_no == MT6370_LED_JOINT) {
> > > >
> > > > What is a "JOINT"?
> > > >
> > > Since MT6370 has two flash led channels. Per channel can drive the current up to 1.5A.
> > > 'JOINT' case is used if 1.5A driving current is not enough, like as flash current 2A.
> > > They can use two channels to drive 'one' flash led by the HW application.
> > > This will make the driving current larger than the capability of one channel.
> >
> > Is "joint" the term used in the datasheet?
> >
> Nope, this term is not clearly defined in the datasheet. but this kind of HW application is
> allowed.
> > Please make this definition clear in the code.
> >
> > If I'm asking, others are likely to too.
> >
> Thanks, I'll add more comments to clearly describe what the 'JOINT' code did.
> > [...]
> >
> > > > > +static int mt6370_init_flash_properties(struct device *dev,
> > > > > +					struct mt6370_led *led,
> > > > > +					struct fwnode_handle *fwnode)
> > > > > +{
> > > > > +	struct led_classdev_flash *flash = &led->flash;
> > > > > +	struct led_classdev *lcdev = &flash->led_cdev;
> > > > > +	struct mt6370_priv *priv = led->priv;
> > > > > +	struct led_flash_setting *s;
> > > > > +	u32 sources[MT6370_MAX_LEDS];
> > > > > +	u32 max_ua, val;
> > > > > +	int i, ret, num;
> > > > > +
> > > > > +	num = fwnode_property_count_u32(fwnode, "led-sources");
> > > > > +	if (num < 1)
> > > > > +		return dev_err_probe(dev, -EINVAL,
> > > > > +				     "Not specified or wrong number of led-sources\n");
> > > > > +
> > > > > +	ret = fwnode_property_read_u32_array(fwnode, "led-sources", sources, num);
> > > > > +	if (ret)
> > > > > +		return ret;
> > > > > +
> > > > > +	for (i = 0; i < num; i++) {
> > > > > +		if (sources[i] >= MT6370_MAX_LEDS)
> > > > > +			return -EINVAL;
> > > > > +		if (priv->leds_active & BIT(sources[i]))
> > > > > +			return -EINVAL;
> > > > > +		priv->leds_active |= BIT(sources[i]);
> > > > > +	}
> > > > > +
> > > > > +	led->led_no = num == 2 ? MT6370_LED_JOINT : sources[0];
> > > > > +
> > > > > +	max_ua = num == 2 ? MT6370_ITORCH_DOUBLE_MAX_uA : MT6370_ITORCH_MAX_uA;
> > > > > +	val = MT6370_ITORCH_MIN_uA;
> > > >
> > > > In what scenario does this not get overwritten?
> > > >
> > > Only if the property is missing. This will make the value keep in minimum.
> >
> > If the property is missing, fwnode_property_read_u32() returns an errno, no?
> >
> > If that's the case, val will be over-written in the if() clause?
> >
> In this funciton, three properties needs to be paresed from DT. Each one need to clamp the value.
> There're two ways to write the code.
>
> [Option 1]
> ret = fwnode_property_read_u32(...)
> if (ret)
>     val = MIM_uA;
>
> val = mt6370_clamp(val, MIN, MAX);
>
> [Option 2]
> val = MIN_uA;
> if (!ret)
>     val = mt6370_clamp(val, MIN, MAX);
>
>
> From the above, the sencond one can save more LOC, no?
> But it seems the first one is more preferable by you, right?

I see now that 'val' is used in clamp() before being overwritten now.

--
Lee Jones [李琼斯]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-03-09 17:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 11:23 [PATCH v17 RESEND 0/3] Add MediaTek MT6370 PMIC support ChiaEn Wu
2023-02-23 11:23 ` [PATCH v17 RESEND 1/3] leds: rgb: mt6370: Add MediaTek MT6370 current sink type LED Indicator support ChiaEn Wu
2023-02-23 13:14   ` AngeloGioacchino Del Regno
2023-03-05  8:55   ` Lee Jones
2023-03-07  2:23     ` ChiYuan Huang
2023-03-08 14:02       ` Lee Jones
2023-02-23 11:23 ` [PATCH v17 RESEND 2/3] leds: flash: mt6370: Add MediaTek MT6370 flashlight support ChiaEn Wu
2023-03-05 10:06   ` Lee Jones
2023-03-07  3:44     ` ChiYuan Huang
2023-03-08 13:54       ` Lee Jones
2023-03-09  1:49         ` ChiYuan Huang
2023-03-09 17:24           ` Lee Jones [this message]
2023-02-23 11:23 ` [PATCH v17 RESEND 3/3] docs: leds: Add MT6370 RGB LED pattern document ChiaEn Wu
2023-03-05 10:18   ` Lee Jones
2023-03-07  4:08     ` ChiYuan Huang
2023-03-08 13:42       ` 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=20230309172448.GU9667@google.com \
    --to=lee@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chiaen_wu@richtek.com \
    --cc=corbet@lwn.net \
    --cc=cy_huang@richtek.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=peterwu.pub@gmail.com \
    --cc=szunichen@gmail.com \
    /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).