From: Pavel Machek <pavel@ucw.cz>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: linux-media@vger.kernel.org, linux-leds@vger.kernel.org,
devicetree@vger.kernel.org, sebastian.reichel@collabora.co.uk,
robh@kernel.org
Subject: Re: [PATCH 7/8] smiapp: Add support for flash, lens and EEPROM devices
Date: Sat, 17 Jun 2017 14:59:19 +0200 [thread overview]
Message-ID: <20170617125919.GB13133@amd> (raw)
In-Reply-To: <20170616124526.GM15419@paasikivi.fi.intel.com>
[-- Attachment #1: Type: text/plain, Size: 4964 bytes --]
Hi!
> > This is quite a lot of boilerplate for that. Would it make sense to
> > provide helper function at least for this?
>
> Yes. I've been thinking of having helper functions for notifiers and
> sub-notifiers. Most of the receiver drivers are implementing exactly the
> same thing but with different twists (read: bugs).
Perhaps something like this is a starting point?
Pavel
commit 22d722b7ee7cb437ae2013fa83a215f91151621c
Author: Pavel <pavel@ucw.cz>
Date: Sat Jun 17 14:14:08 2017 +0200
Subdev support for et8ek8.
Subdev code is ready for moving to some other place -- this is really
common code.
Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff --git a/drivers/media/i2c/et8ek8/et8ek8_driver.c b/drivers/media/i2c/et8ek8/et8ek8_driver.c
index 05b9bd9..a6899fc 100644
--- a/drivers/media/i2c/et8ek8/et8ek8_driver.c
+++ b/drivers/media/i2c/et8ek8/et8ek8_driver.c
@@ -32,13 +32,90 @@
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/sort.h>
-#include <linux/v4l2-mediabus.h>
+#include <media/v4l2-async.h>
+#include <linux/v4l2-mediabus.h>
#include <media/media-entity.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-subdev.h>
+static int simple_subdev_notifier_bound(struct v4l2_async_notifier *notifier,
+ struct v4l2_subdev *sd,
+ struct v4l2_async_subdev *asd)
+{
+ return 0;
+}
+
+static int simple_subdev_notifier_complete(
+ struct v4l2_async_notifier *notifier)
+{
+ struct v4l2_async_notifier_simple *notifier_s =
+ container_of(notifier, struct v4l2_async_notifier_simple, notifier);
+
+ return v4l2_device_register_subdev_nodes(notifier_s->v4l2_dev);
+}
+
+static inline int v4l2_simple_subnotifier_register(struct v4l2_subdev *subdev,
+ struct v4l2_async_notifier_simple *notifier_s)
+{
+ struct v4l2_async_notifier *notifier = ¬ifier_s->notifier;
+ int rval;
+ if (!notifier->num_subdevs)
+ return 0;
+
+ notifier_s->v4l2_dev = subdev->v4l2_dev;
+ notifier->bound = simple_subdev_notifier_bound;
+ notifier->complete = simple_subdev_notifier_complete;
+ rval = v4l2_async_subnotifier_register(subdev, notifier);
+ return rval;
+}
+
+static inline int simple_subdev_probe(struct device *dev,
+ struct v4l2_async_notifier *notifier)
+{
+ static const char *props[] = { "flash", "lens", "eeprom" };
+ unsigned int i;
+ const int max_subdevs = 3;
+
+ notifier->subdevs =
+ devm_kcalloc(dev, max_subdevs,
+ sizeof(struct v4l2_async_subdev *), GFP_KERNEL);
+ if (!notifier->subdevs)
+ return -ENOMEM;
+
+ for (i = 0; i < ARRAY_SIZE(props); i++) {
+ struct device_node *node;
+ unsigned int j = 0;
+
+ while ((node = of_parse_phandle(dev->of_node, props[i], j++))) {
+ struct v4l2_async_subdev **asd =
+ ¬ifier->subdevs[
+ notifier->num_subdevs];
+
+ if (WARN_ON(notifier->num_subdevs >= max_subdevs)) {
+ of_node_put(node);
+ return 0;
+ }
+
+ *asd = devm_kzalloc(
+ dev, sizeof(struct v4l2_async_subdev),
+ GFP_KERNEL);
+ if (!*asd) {
+ of_node_put(node);
+ return 0;
+ }
+
+ (*asd)->match.fwnode.fwnode = of_fwnode_handle(node);
+ (*asd)->match_type = V4L2_ASYNC_MATCH_FWNODE;
+ notifier->num_subdevs++;
+
+ of_node_put(node);
+ }
+ }
+ return 0;
+}
+
#include "et8ek8_reg.h"
#define ET8EK8_NAME "et8ek8"
@@ -67,6 +144,8 @@ struct et8ek8_sensor {
struct mutex power_lock;
int power_count;
+
+ struct v4l2_async_notifier_simple notifier_s;
};
#define to_et8ek8_sensor(sd) container_of(sd, struct et8ek8_sensor, subdev)
@@ -1510,6 +1589,8 @@ et8ek8_registered(struct v4l2_subdev *subdev)
goto err_file;
}
+ v4l2_simple_subnotifier_register(subdev, &sensor->notifier_s);
+
__et8ek8_get_pad_format(sensor, NULL, 0, V4L2_SUBDEV_FORMAT_ACTIVE);
return 0;
@@ -1680,6 +1761,8 @@ static int et8ek8_probe(struct i2c_client *client,
if (ret < 0)
goto err_entity;
+ simple_subdev_probe(dev, &sensor->notifier_s.notifier);
+
dev_dbg(dev, "initialized!\n");
return 0;
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
index f7e2a1a..63bcf80 100644
--- a/include/media/v4l2-async.h
+++ b/include/media/v4l2-async.h
@@ -104,6 +104,11 @@ struct v4l2_async_notifier {
struct v4l2_async_subdev *asd);
};
+struct v4l2_async_notifier_simple {
+ struct v4l2_async_notifier notifier;
+ struct v4l2_device * v4l2_dev;
+};
+
/**
* v4l2_async_notifier_register - registers a subdevice asynchronous subnotifier
*
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2017-06-17 12:59 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-14 9:47 [PATCH 0/8] Support registering lens, flash and EEPROM devices Sakari Ailus
2017-06-14 9:47 ` [PATCH 1/8] dt: bindings: Add a binding for flash devices associated to a sensor Sakari Ailus
2017-06-14 15:19 ` Rob Herring
[not found] ` <1497433639-13101-2-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-15 9:11 ` Pavel Machek
2017-06-15 9:11 ` Pavel Machek
2017-06-15 9:21 ` Sebastian Reichel
2017-06-14 9:47 ` [PATCH 2/8] dt: bindings: Add lens-focus binding for image sensors Sakari Ailus
2017-06-14 15:20 ` Rob Herring
2017-06-14 9:47 ` [PATCH 3/8] dt: bindings: Add a binding for referencing EEPROM from camera sensors Sakari Ailus
2017-06-18 14:05 ` Rob Herring
[not found] ` <1497433639-13101-4-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-07-19 7:52 ` Maxime Ripard
2017-07-19 7:52 ` Maxime Ripard
2017-07-19 9:21 ` Sakari Ailus
2017-07-19 11:18 ` Maxime Ripard
2017-07-21 11:14 ` Sakari Ailus
2017-07-21 11:14 ` Sakari Ailus
[not found] ` <1497433639-13101-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-14 9:47 ` [PATCH 4/8] v4l2-flash: Use led_classdev instead of led_classdev_flash for indicator Sakari Ailus
2017-06-14 9:47 ` Sakari Ailus
2017-06-14 21:13 ` Jacek Anaszewski
2017-06-15 6:31 ` kbuild test robot
2017-06-15 10:45 ` Sebastian Reichel
2017-06-14 9:47 ` [PATCH 5/8] v4l2-flash: Flash ops aren't mandatory Sakari Ailus
2017-06-14 9:47 ` Sakari Ailus
2017-06-14 21:14 ` Jacek Anaszewski
[not found] ` <3e0a8823-a8b4-3f78-25e0-22d8cb8ad090-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14 21:19 ` Sakari Ailus
2017-06-14 21:19 ` Sakari Ailus
[not found] ` <20170614211939.GR12407-S+BSfZ9RZZmRSg0ZkenSGLdO1Tsj/99ntUK59QYPAWc@public.gmane.org>
2017-06-15 12:08 ` Jacek Anaszewski
2017-06-15 12:08 ` Jacek Anaszewski
2017-06-15 9:24 ` Sebastian Reichel
2017-06-15 12:32 ` Sakari Ailus
2017-06-15 12:32 ` Sakari Ailus
[not found] ` <20170615123209.GD12407-S+BSfZ9RZZmRSg0ZkenSGLdO1Tsj/99ntUK59QYPAWc@public.gmane.org>
2017-06-15 12:51 ` Sebastian Reichel
2017-06-15 12:51 ` Sebastian Reichel
2017-07-18 17:36 ` [PATCH v1.1 1/1] " Sakari Ailus
2017-07-19 11:53 ` Pavel Machek
2017-06-14 9:47 ` [PATCH 6/8] leds: as3645a: Add LED flash class driver Sakari Ailus
2017-06-14 9:47 ` Sakari Ailus
2017-06-14 21:15 ` Jacek Anaszewski
2017-06-14 22:10 ` Sakari Ailus
[not found] ` <20170614221028.GS12407-S+BSfZ9RZZmRSg0ZkenSGLdO1Tsj/99ntUK59QYPAWc@public.gmane.org>
2017-06-15 13:01 ` Jacek Anaszewski
2017-06-15 13:01 ` Jacek Anaszewski
2017-06-15 13:34 ` Sakari Ailus
[not found] ` <20170615133404.GF12407-S+BSfZ9RZZmRSg0ZkenSGLdO1Tsj/99ntUK59QYPAWc@public.gmane.org>
2017-06-15 13:47 ` Jacek Anaszewski
2017-06-15 13:47 ` Jacek Anaszewski
2017-06-14 21:39 ` Pavel Machek
2017-06-14 22:21 ` Sakari Ailus
2017-06-14 22:28 ` Pavel Machek
2017-06-14 22:43 ` Sakari Ailus
2017-06-15 10:43 ` Pavel Machek
2017-06-14 9:47 ` [PATCH 7/8] smiapp: Add support for flash, lens and EEPROM devices Sakari Ailus
2017-06-15 1:50 ` kbuild test robot
2017-06-16 12:07 ` Pavel Machek
2017-06-16 12:26 ` Sakari Ailus
[not found] ` <20170616122629.GL15419-z7MJbOB4PBP+e+fPlCVrcFDQ4js95KgL@public.gmane.org>
2017-06-16 13:10 ` Pavel Machek
2017-06-16 13:10 ` Pavel Machek
2017-06-16 12:42 ` Pavel Machek
2017-06-16 12:45 ` Sakari Ailus
[not found] ` <20170616124526.GM15419-z7MJbOB4PBP+e+fPlCVrcFDQ4js95KgL@public.gmane.org>
2017-06-17 9:19 ` Pavel Machek
2017-06-17 9:19 ` Pavel Machek
2017-06-17 12:59 ` Pavel Machek [this message]
2017-06-17 21:12 ` Pavel Machek
[not found] ` <1497433639-13101-8-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-06-17 12:17 ` Pavel Machek
2017-06-17 12:17 ` Pavel Machek
2017-06-14 9:47 ` [PATCH 8/8] arm: dts: omap3: N9/N950: Add AS3645A camera flash Sakari Ailus
2017-06-15 10:15 ` Sebastian Reichel
2017-06-14 9:53 ` [PATCH 0/8] Support registering lens, flash and EEPROM devices Sakari Ailus
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=20170617125919.GB13133@amd \
--to=pavel@ucw.cz \
--cc=devicetree@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=sebastian.reichel@collabora.co.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.