public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: linux-leds@vger.kernel.org, laurent.pinchart@ideasonboard.com,
	niklas.soderlund@ragnatech.se, hverkuil@xs4all.nl
Subject: [RFC 06/19] leds: as3645a: Separate flash and indicator LED sub-devices
Date: Tue, 18 Jul 2017 22:03:48 +0300	[thread overview]
Message-ID: <20170718190401.14797-7-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20170718190401.14797-1-sakari.ailus@linux.intel.com>

To be merged to the as3645a driver patch.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/leds/leds-as3645a.c | 64 +++++++++++++++++++++++++++++----------------
 1 file changed, 42 insertions(+), 22 deletions(-)

diff --git a/drivers/leds/leds-as3645a.c b/drivers/leds/leds-as3645a.c
index b1dc32a3c620..9df480cea160 100644
--- a/drivers/leds/leds-as3645a.c
+++ b/drivers/leds/leds-as3645a.c
@@ -138,6 +138,10 @@ struct as3645a {
 	struct led_classdev iled_cdev;
 
 	struct v4l2_flash *vf;
+	struct v4l2_flash *vfind;
+
+	struct device_node *flash_node;
+	struct device_node *indicator_node;
 
 	struct as3645a_config cfg;
 
@@ -508,16 +512,15 @@ static int as3645a_parse_node(struct as3645a *flash,
 			      struct device_node *node)
 {
 	struct as3645a_config *cfg = &flash->cfg;
-	struct device_node *child;
 	int rval;
 
-	child = of_get_child_by_name(node, "flash");
-	if (!child) {
+	flash->flash_node = of_get_child_by_name(node, "flash");
+	if (!flash->flash_node) {
 		dev_err(&flash->client->dev, "can't find flash node\n");
 		return -ENODEV;
 	}
 
-	rval = of_property_read_u32(child, "flash-timeout-us",
+	rval = of_property_read_u32(flash->flash_node, "flash-timeout-us",
 				   &cfg->flash_timeout_us);
 	if (rval < 0) {
 		dev_err(&flash->client->dev,
@@ -525,7 +528,7 @@ static int as3645a_parse_node(struct as3645a *flash,
 		goto out_err;
 	}
 
-	rval = of_property_read_u32(child, "flash-max-microamp",
+	rval = of_property_read_u32(flash->flash_node, "flash-max-microamp",
 				   &cfg->flash_max_ua);
 	if (rval < 0) {
 		dev_err(&flash->client->dev,
@@ -533,7 +536,7 @@ static int as3645a_parse_node(struct as3645a *flash,
 		goto out_err;
 	}
 
-	rval = of_property_read_u32(child, "led-max-microamp",
+	rval = of_property_read_u32(flash->flash_node, "led-max-microamp",
 				   &cfg->assist_max_ua);
 	if (rval < 0) {
 		dev_err(&flash->client->dev,
@@ -541,22 +544,21 @@ static int as3645a_parse_node(struct as3645a *flash,
 		goto out_err;
 	}
 
-	of_property_read_u32(child, "voltage-reference",
+	of_property_read_u32(flash->flash_node, "voltage-reference",
 			     &cfg->voltage_reference);
 
-	of_property_read_u32(child, "peak-current-limit", &cfg->peak);
+	of_property_read_u32(flash->flash_node, "peak-current-limit",
+			     &cfg->peak);
 	cfg->peak = AS_PEAK_mA_TO_REG(cfg->peak);
 
-	of_node_put(child);
-
-	child = of_get_child_by_name(node, "indicator");
-	if (!child) {
+	flash->indicator_node = of_get_child_by_name(node, "indicator");
+	if (!flash->indicator_node) {
 		dev_warn(&flash->client->dev,
 			 "can't find indicator node\n");
-		return 0;
+		goto out_err;
 	}
 
-	rval = of_property_read_u32(child, "led-max-microamp",
+	rval = of_property_read_u32(flash->indicator_node, "led-max-microamp",
 				   &cfg->indicator_max_ua);
 	if (rval < 0) {
 		dev_err(&flash->client->dev,
@@ -564,12 +566,11 @@ static int as3645a_parse_node(struct as3645a *flash,
 		goto out_err;
 	}
 
-	of_node_put(child);
-
 	return 0;
 
 out_err:
-	of_node_put(child);
+	of_node_put(flash->flash_node);
+	of_node_put(flash->indicator_node);
 
 	return rval;
 }
@@ -628,13 +629,15 @@ static int as3645a_v4l2_setup(struct as3645a *flash)
 	struct led_classdev_flash *fled = &flash->fled;
 	struct led_classdev *led = &fled->led_cdev;
 	struct v4l2_flash_config cfg = {
-		.torch_intensity = {
+		.intensity = {
 			.min = AS_TORCH_INTENSITY_MIN,
 			.max = flash->cfg.assist_max_ua,
 			.step = AS_TORCH_INTENSITY_STEP,
 			.val = flash->cfg.assist_max_ua,
 		},
-		.indicator_intensity = {
+	};
+	struct v4l2_flash_config cfgind = {
+		.intensity = {
 			.min = AS_INDICATOR_INTENSITY_MIN,
 			.max = flash->cfg.indicator_max_ua,
 			.step = AS_INDICATOR_INTENSITY_STEP,
@@ -643,12 +646,22 @@ static int as3645a_v4l2_setup(struct as3645a *flash)
 	};
 
 	strlcpy(cfg.dev_name, led->name, sizeof(cfg.dev_name));
+	strlcpy(cfgind.dev_name, flash->iled_cdev.name, sizeof(cfg.dev_name));
 
-	flash->vf = v4l2_flash_init(&flash->client->dev, NULL, &flash->fled,
-				    &flash->iled_cdev, NULL, &cfg);
+	flash->vf = v4l2_flash_init(
+		&flash->client->dev, of_fwnode_handle(flash->flash_node),
+		&flash->fled, NULL, &cfg);
 	if (IS_ERR(flash->vf))
 		return PTR_ERR(flash->vf);
 
+	flash->vfind = v4l2_flash_indicator_init(
+		&flash->client->dev, of_fwnode_handle(flash->indicator_node),
+		&flash->iled_cdev, &cfgind);
+	if (IS_ERR(flash->vfind)) {
+		v4l2_flash_release(flash->vf);
+		return PTR_ERR(flash->vfind);
+	}
+
 	return 0;
 }
 
@@ -672,7 +685,7 @@ static int as3645a_probe(struct i2c_client *client)
 
 	rval = as3645a_detect(flash);
 	if (rval < 0)
-		return rval;
+		goto out_put_nodes;
 
 	mutex_init(&flash->mutex);
 	i2c_set_clientdata(client, flash);
@@ -697,6 +710,10 @@ static int as3645a_probe(struct i2c_client *client)
 out_mutex_destroy:
 	mutex_destroy(&flash->mutex);
 
+out_put_nodes:
+	of_node_put(flash->flash_node);
+	of_node_put(flash->indicator_node);
+
 	return rval;
 }
 
@@ -713,6 +730,9 @@ static int as3645a_remove(struct i2c_client *client)
 
 	mutex_destroy(&flash->mutex);
 
+	of_node_put(flash->flash_node);
+	of_node_put(flash->indicator_node);
+
 	return 0;
 }
 
-- 
2.11.0

  parent reply	other threads:[~2017-07-18 19:04 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 19:03 [RFC 00/19] Async sub-notifiers and how to use them Sakari Ailus
2017-07-18 19:03 ` [RFC 01/19] device property: Introduce fwnode_property_get_reference_args Sakari Ailus
2017-07-18 19:03 ` [RFC 02/19] v4l: async: add subnotifier registration for subdevices Sakari Ailus
2017-07-18 21:28   ` Niklas Söderlund
2017-07-18 19:03 ` [RFC 03/19] dt: bindings: Add a binding for flash devices associated to a sensor Sakari Ailus
2017-07-18 19:03 ` [RFC 04/19] dt: bindings: Add lens-focus binding for image sensors Sakari Ailus
2017-07-28  8:53   ` Hans Verkuil
2017-07-28 12:45     ` Pavel Machek
2017-08-15 11:24     ` Sakari Ailus
2017-07-18 19:03 ` [RFC 05/19] leds: as3645a: Add LED flash class driver Sakari Ailus
2017-07-19 20:17   ` Jacek Anaszewski
2017-07-19 21:21     ` Sakari Ailus
2017-07-18 19:03 ` Sakari Ailus [this message]
2017-07-18 19:03 ` [RFC 07/19] v4l: fwnode: Support generic parsing of graph endpoints in V4L2 Sakari Ailus
2017-07-18 19:03 ` [RFC 08/19] arm: dts: omap3: N9/N950: Add AS3645A camera flash Sakari Ailus
2017-07-18 19:16   ` Sakari Ailus
2017-07-22  9:40   ` Pavel Machek
2017-07-18 19:03 ` [RFC 09/19] v4l2-fwnode: Add conveniences function for parsing generic references Sakari Ailus
2017-07-18 19:03 ` [RFC 10/19] v4l2-fwnode: Add convenience function for parsing common external refs Sakari Ailus
2017-07-18 19:03 ` [RFC 11/19] v4l2-async: Register sub-devices before calling bound callback Sakari Ailus
2017-07-19 11:24   ` Hans Verkuil
2017-07-20 16:09     ` Sakari Ailus
2017-07-20 16:23       ` Hans Verkuil
2017-07-20 19:23         ` Sakari Ailus
2017-07-21  7:14           ` Hans Verkuil
2017-07-20 23:53         ` Kieran Bingham
2017-07-18 19:03 ` [RFC 12/19] v4l2-subdev: Support registering V4L2 sub-device nodes one by one Sakari Ailus
2017-07-18 19:03 ` [RFC 13/19] v4l2-device: Register sub-device nodes at sub-device registration time Sakari Ailus
2017-07-18 19:03 ` [RFC 14/19] omap3isp: Move sub-device link creation to notifier bound callback Sakari Ailus
2017-07-18 19:03 ` [RFC 15/19] omap3isp: Initialise "crashed" media entity enum in probe Sakari Ailus
2017-07-18 19:03 ` [RFC 16/19] omap3isp: Move media device registration to probe Sakari Ailus
2017-07-18 19:03 ` [RFC 17/19] omap3isp: Drop the async notifier callback Sakari Ailus
2017-07-18 19:04 ` [RFC 18/19] v4l2-fwnode: Add abstracted sub-device notifiers Sakari Ailus
2017-07-18 21:19   ` Niklas Söderlund
2017-07-19 22:20     ` Sakari Ailus
2017-07-19 22:33     ` [RFC 1/1] v4l2-subdev: Add a function to set sub-device notifier callbacks Sakari Ailus
2017-07-26 17:48       ` Mauro Carvalho Chehab
2017-07-18 19:04 ` [RFC 19/19] smiapp: Add support for flash and lens devices Sakari Ailus
2017-07-19 11:42 ` [RFC 00/19] Async sub-notifiers and how to use them Hans Verkuil
2017-07-20 16:14   ` Sakari Ailus
2017-07-21  6:57     ` Niklas Söderlund
2017-08-04 18:25       ` Sakari Ailus
2017-08-23  9:09         ` Hans Verkuil
2017-08-23 11:34           ` Pavel Machek
2017-08-23 12:02             ` Hans Verkuil
2017-08-23 12:29           ` Laurent Pinchart
2017-08-23 15:40             ` Hans Verkuil
2017-08-23 12:59           ` Niklas Söderlund
2017-08-23 13:32             ` Laurent Pinchart
2017-08-23 15:23               ` Hans Verkuil

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=20170718190401.14797-7-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    /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