public inbox for linux-doc@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kaustabh Chakraborty" <kauschluss@disroot.org>
To: "André Draszik" <andre.draszik@linaro.org>,
	"Kaustabh Chakraborty" <kauschluss@disroot.org>,
	"Lee Jones" <lee@kernel.org>, "Pavel Machek" <pavel@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"MyungJoo Ham" <myungjoo.ham@samsung.com>,
	"Chanwoo Choi" <cw00.choi@samsung.com>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>
Cc: <linux-leds@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-samsung-soc@vger.kernel.org>, <linux-rtc@vger.kernel.org>,
	<linux-doc@vger.kernel.org>
Subject: Re: [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device
Date: Thu, 05 Feb 2026 21:46:34 +0530	[thread overview]
Message-ID: <DG75VP6IIUXD.1VA6YSMNTPJQ6@disroot.org> (raw)
In-Reply-To: <e34d429e27392eba894b9592724a77fa82fc8009.camel@linaro.org>

On 2026-02-04 16:55 +00:00, André Draszik wrote:
> Hi,
>
> On Mon, 2026-01-26 at 00:37 +0530, Kaustabh Chakraborty wrote:
>> Add support for flash LEDs found in certain Samsung S2M series PMICs.
>> The device has two channels for LEDs, typically for the back and front
>> cameras in mobile devices. Both channels can be independently
>> controlled, and can be operated in torch or flash modes.
>> 
>> The driver includes initial support for the S2MU005 PMIC flash LEDs.
>> 
>> Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
>> ---
>>  drivers/leds/flash/Kconfig          |  12 ++
>>  drivers/leds/flash/Makefile         |   1 +
>>  drivers/leds/flash/leds-s2m-flash.c | 410 ++++++++++++++++++++++++++++++++++++
>>  3 files changed, 423 insertions(+)
>> 
>> diff --git a/drivers/leds/flash/Kconfig b/drivers/leds/flash/Kconfig
>> index 5e08102a67841..be62e05277429 100644
>> --- a/drivers/leds/flash/Kconfig
>> +++ b/drivers/leds/flash/Kconfig
>> @@ -114,6 +114,18 @@ config LEDS_RT8515
>>  	  To compile this driver as a module, choose M here: the module
>>  	  will be called leds-rt8515.
>>  
>> +config LEDS_S2M_FLASH
>> +	tristate "Samsung S2M series PMICs flash/torch LED support"
>> +	depends on LEDS_CLASS
>> +	depends on MFD_SEC_CORE
>> +	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
>> +	select REGMAP_IRQ
>> +	help
>> +	  This option enables support for the flash/torch LEDs found in
>> +	  certain Samsung S2M series PMICs, such as the S2MU005. It has
>> +	  a LED channel dedicated for every physical LED. The LEDs can
>> +	  be controlled in flash and torch modes.
>> +
>>  config LEDS_SGM3140
>>  	tristate "LED support for the SGM3140"
>>  	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
>> diff --git a/drivers/leds/flash/Makefile b/drivers/leds/flash/Makefile
>> index 712fb737a428e..44e6c1b4beb37 100644
>> --- a/drivers/leds/flash/Makefile
>> +++ b/drivers/leds/flash/Makefile
>> @@ -10,6 +10,7 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o
>>  obj-$(CONFIG_LEDS_QCOM_FLASH)	+= leds-qcom-flash.o
>>  obj-$(CONFIG_LEDS_RT4505)	+= leds-rt4505.o
>>  obj-$(CONFIG_LEDS_RT8515)	+= leds-rt8515.o
>> +obj-$(CONFIG_LEDS_S2M_FLASH)	+= leds-s2m-flash.o
>>  obj-$(CONFIG_LEDS_SGM3140)	+= leds-sgm3140.o
>>  obj-$(CONFIG_LEDS_SY7802)	+= leds-sy7802.o
>>  obj-$(CONFIG_LEDS_TPS6131X)	+= leds-tps6131x.o
>> diff --git a/drivers/leds/flash/leds-s2m-flash.c b/drivers/leds/flash/leds-s2m-flash.c
>> new file mode 100644
>> index 0000000000000..1be2745c475bf
>> --- /dev/null
>> +++ b/drivers/leds/flash/leds-s2m-flash.c
>> @@ -0,0 +1,410 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Flash and Torch LED Driver for Samsung S2M series PMICs.
>> + *
>> + * Copyright (c) 2015 Samsung Electronics Co., Ltd
>> + * Copyright (c) 2025 Kaustabh Chakraborty <kauschluss@disroot.org>
>> + */
>> +
>> +#include <linux/container_of.h>
>> +#include <linux/led-class-flash.h>
>> +#include <linux/mfd/samsung/core.h>
>> +#include <linux/mfd/samsung/s2mu005.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/regmap.h>
>> +#include <media/v4l2-flash-led-class.h>
>> +
>> +#define MAX_CHANNELS	2
>> +
>> +struct s2m_fled {
>> +	struct device *dev;
>> +	struct regmap *regmap;
>> +	struct led_classdev_flash cdev;
>> +	struct v4l2_flash *v4l2_flash;
>> +	struct mutex lock;
>
> Please add a (brief) comment describing what the mutex protects.

The mutex object prevents the concurrent access of flash control
registers by the LED and V4L2 subsystems. -- will add this.

>> +
>> +	/*
>> +	 * Get the LED enable register address. Revision EVT0 has the
>> +	 * register at CTRL4, while EVT1 and higher have it at CTRL6.
>> +	 */
>> +	if (priv->pmic_revision == 0)
>> +		reg_enable = S2MU005_REG_FLED_CTRL4;
>> +	else
>> +		reg_enable = S2MU005_REG_FLED_CTRL6;
>
> You could REG_FIELD() and friends for this and everywhere else with
> similar if / else.
>

REG_FIELD(), from what I understood, is for selecting a bit field inside
a single register. However this code chooses between two separate
registers. I believe your interpretation was incorrect? Please clarify.

>> +static int s2m_fled_init_channel(struct device *dev, struct fwnode_handle *fwnp,
>> +				 struct s2m_fled *priv)
>> +{
>> +	struct led_classdev *led = &priv->cdev.led_cdev;
>> +	struct led_init_data init_data = {};
>> +	struct v4l2_flash_config v4l2_cfg = {};
>> +	int ret;
>> +
>> +	led->max_brightness = priv->spec->torch_max_brightness;
>> +	led->brightness_set_blocking = priv->spec->torch_brightness_set_blocking;
>> +	led->flags |= LED_DEV_CAP_FLASH;
>> +
>> +	priv->cdev.timeout.min = priv->spec->flash_min_timeout_us;
>> +	priv->cdev.timeout.step = priv->spec->flash_min_timeout_us;
>> +	priv->cdev.timeout.max = priv->spec->flash_max_timeout_us;
>> +	priv->cdev.timeout.val = priv->spec->flash_max_timeout_us;
>> +
>> +	priv->cdev.brightness.min = priv->spec->flash_min_current_ua;
>> +	priv->cdev.brightness.step = priv->spec->flash_min_current_ua;
>> +	priv->cdev.brightness.max = priv->spec->flash_max_current_ua;
>> +	priv->cdev.brightness.val = priv->spec->flash_max_current_ua;
>> +
>> +	s2m_fled_flash_timeout_set(&priv->cdev, priv->cdev.timeout.val);
>> +	s2m_fled_flash_brightness_set(&priv->cdev, priv->cdev.brightness.val);
>> +
>> +	priv->cdev.ops = priv->spec->flash_ops;
>> +
>> +	init_data.fwnode = fwnp;
>> +	ret = devm_led_classdev_flash_register_ext(dev, &priv->cdev, &init_data);
>> +	if (ret < 0) {
>> +		dev_err(dev, "failed to create LED flash device\n");
>> +		return ret;
>
> dev_err_probe()?
>
>> +	}
>> +
>> +	v4l2_cfg.intensity.min = priv->spec->flash_min_current_ua;
>> +	v4l2_cfg.intensity.step = priv->spec->flash_min_current_ua;
>> +	v4l2_cfg.intensity.max = priv->spec->flash_max_current_ua;
>> +	v4l2_cfg.intensity.val = priv->spec->flash_max_current_ua;
>> +
>> +	v4l2_cfg.has_external_strobe = true;
>> +
>> +	priv->v4l2_flash = v4l2_flash_init(dev, fwnp, &priv->cdev,
>> +					   &s2m_fled_v4l2_flash_ops, &v4l2_cfg);
>> +	if (IS_ERR(priv->v4l2_flash)) {
>> +		dev_err(dev, "failed to create V4L2 flash device\n");
>> +		v4l2_flash_release(priv->v4l2_flash);
>> +		return PTR_ERR(priv->v4l2_flash);
>
> dev_err_probe()?
>
>> +	}
>> +
>> +	return devm_add_action_or_reset(dev, (void *)v4l2_flash_release,
>> +					priv->v4l2_flash);
>
> maybe add dev_err_probe() here, and drop the extra message in s2m_fled_probe().
>
>> +}
>> +
>> +static int s2m_fled_probe(struct platform_device *pdev)
>> +{
>> +	struct device *dev = &pdev->dev;
>> +	struct sec_pmic_dev *pmic_drvdata = dev_get_drvdata(dev->parent);
>> +	struct s2m_fled *priv;
>> +	struct fwnode_handle *child;
>> +	struct regmap *regmap;
>> +	const struct s2m_fled_spec *spec;
>> +	int ret;
>> +
>> +	priv = devm_kzalloc(dev, sizeof(*priv) * MAX_CHANNELS, GFP_KERNEL);
>> +	if (!priv)
>> +		return dev_err_probe(dev, -ENOMEM, "failed to allocate driver private\n");
>> +
>> +	platform_set_drvdata(pdev, priv);
>> +	regmap = pmic_drvdata->regmap_pmic;
>> +
>> +	switch (platform_get_device_id(pdev)->driver_data) {
>> +	case S2MU005:
>> +		spec = &s2mu005_fled_spec;
>> +		/* Enable the LED channels. */
>> +		ret = regmap_set_bits(regmap, S2MU005_REG_FLED_CTRL1,
>> +				      S2MU005_FLED_CH_EN);
>> +		if (ret < 0)
>> +			return dev_err_probe(dev, ret, "failed to enable LED channels\n");
>> +		break;
>> +	default:
>> +		return dev_err_probe(dev, -ENODEV,
>> +				     "device type %d is not supported by driver\n",
>> +				     pmic_drvdata->device_type);
>> +	}
>> +
>> +	device_for_each_child_node(dev, child) {
>> +		u32 reg;
>> +
>> +		if (fwnode_property_read_u32(child, "reg", &reg))
>> +			goto next_child;
>> +
>> +		if (reg >= spec->num_channels) {
>> +			dev_warn(dev, "channel %d is non-existent\n", reg);
>> +			goto next_child;
>> +		}
>> +
>> +		if (priv[reg].dev) {
>> +			dev_warn(dev, "duplicate node for channel %d\n", reg);
>> +			goto next_child;
>> +		}
>> +
>> +		priv[reg].dev = dev;
>> +		priv[reg].regmap = regmap;
>> +		priv[reg].channel = (u8)reg;
>> +		priv[reg].spec = spec;
>> +		priv[reg].pmic_revision = pmic_drvdata->revision;
>> +
>> +		ret = devm_mutex_init(dev, &priv[reg].lock);
>> +		if (ret)
>> +			return dev_err_probe(dev, ret, "failed to create mutex lock\n");
>> +
>> +		ret = s2m_fled_init_channel(dev, child, &priv[reg]);
>> +		if (ret < 0)
>> +			dev_warn(dev, "channel init failed (%d)\n", ret);
>
> s2m_fled_init_channel() already prints a message on (most) errors, and then
> there's another one here. Also, is it really OK to continue ignoring the
> error?
>

The LED channels are supposed to be independent, so if one fails, the
others may still work. 

But errors in s2m_fled_init_channel() is not-hardware related, so this
reasoning doesn't make sense. So I shall implement your changes.

  reply	other threads:[~2026-02-05 16:16 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-25 19:07 [PATCH v2 00/12] Support for Samsung S2MU005 PMIC and its sub-devices Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 01/12] dt-bindings: leds: document Samsung S2M series PMIC flash LED device Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 02/12] dt-bindings: leds: document Samsung S2M series PMIC RGB " Kaustabh Chakraborty
2026-02-06 13:38   ` Rob Herring
2026-02-06 13:56     ` Kaustabh Chakraborty
2026-02-06 14:03       ` Kaustabh Chakraborty
2026-02-08 13:05       ` Jacek Anaszewski
2026-01-25 19:07 ` [PATCH v2 03/12] dt-bindings: extcon: document Samsung S2M series PMIC extcon device Kaustabh Chakraborty
2026-02-06 13:49   ` Rob Herring
2026-02-06 13:52     ` Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 04/12] dt-bindings: power: supply: document Samsung S2M series PMIC charger device Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 05/12] dt-bindings: mfd: s2mps11: add documentation for S2MU005 PMIC Kaustabh Chakraborty
2026-01-25 20:59   ` Rob Herring (Arm)
2026-01-25 19:07 ` [PATCH v2 06/12] mfd: sec: add support " Kaustabh Chakraborty
2026-01-26 19:41   ` kernel test robot
2026-02-04 15:23   ` André Draszik
2026-02-05 15:32     ` Kaustabh Chakraborty
2026-02-10  9:55       ` André Draszik
2026-02-20 16:56       ` Sander Vanheule
2026-02-23 13:56         ` Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 07/12] mfd: sec: store hardware revision in sec_pmic_dev and add S2MU005 support Kaustabh Chakraborty
2026-02-04 14:17   ` André Draszik
2026-02-04 15:05     ` Kaustabh Chakraborty
2026-02-05 16:26       ` Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 08/12] leds: flash: add support for Samsung S2M series PMIC flash LED device Kaustabh Chakraborty
2026-02-04 16:55   ` André Draszik
2026-02-05 16:16     ` Kaustabh Chakraborty [this message]
2026-02-10 10:03       ` André Draszik
2026-02-10 18:37         ` Kaustabh Chakraborty
2026-02-05 10:54   ` André Draszik
2026-01-25 19:07 ` [PATCH v2 09/12] leds: rgb: add support for Samsung S2M series PMIC RGB " Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 10/12] Documentation: leds: document pattern behavior of Samsung S2M series PMIC RGB LEDs Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 11/12] extcon: add support for Samsung S2M series PMIC extcon devices Kaustabh Chakraborty
2026-01-25 19:07 ` [PATCH v2 12/12] power: supply: add support for Samsung S2M series PMIC charger device Kaustabh Chakraborty

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=DG75VP6IIUXD.1VA6YSMNTPJQ6@disroot.org \
    --to=kauschluss@disroot.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andre.draszik@linaro.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=krzk@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=pavel@kernel.org \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=sre@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