From patchwork Sat Jun 17 21:12:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 41959 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dML1R-0002XO-ME; Sat, 17 Jun 2017 21:12:45 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.89/mailfrontend-8) with esmtp id 1dML1P-0003Cn-mG; Sat, 17 Jun 2017 23:12:45 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752529AbdFQVMj (ORCPT + 1 other); Sat, 17 Jun 2017 17:12:39 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:50197 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752448AbdFQVMi (ORCPT ); Sat, 17 Jun 2017 17:12:38 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 7D24E824DE; Sat, 17 Jun 2017 23:12:35 +0200 (CEST) Date: Sat, 17 Jun 2017 23:12:35 +0200 From: Pavel Machek To: Sakari Ailus 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 Message-ID: <20170617211234.GA30157@amd> References: <1497433639-13101-1-git-send-email-sakari.ailus@linux.intel.com> <1497433639-13101-8-git-send-email-sakari.ailus@linux.intel.com> <20170616124242.GA8145@amd> <20170616124526.GM15419@paasikivi.fi.intel.com> <20170617125919.GB13133@amd> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170617125919.GB13133@amd> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2017.6.17.210316 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' BODY_PARA_IS_SENTENCE_URL 0.1, MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, KNOWN_FREEWEB_URI 0.05, MSGID_ADDED_BY_MTA 0.05, BODY_SIZE_5000_5999 0, BODY_SIZE_7000_LESS 0, INVALID_MSGID_NO_FQDN 0, IN_REP_TO 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, URI_ENDS_IN_HTML 0, URI_WITH_PATH_ONLY 0, __ANY_URI 0, __ATTACHMENT_SIZE_0_10K 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CD 0, __CP_URI_IN_BODY 0, __CT 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0, __FORWARDED_MSG 0, __HAS_ATTACHMENT 0, __HAS_ATTACHMENT1 0, __HAS_ATTACHMENT2 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_LIST_ID 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __KNOWN_FREEWEB_URI2 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_TEXT_P2 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __MULTIPLE_URI_TEXT 0, __NO_HTML_TAG_RAW 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __TO_MALFORMED_2 0, __TO_NAME 0, __TO_NAME_DIFF_FROM_ACC 0, __TO_REAL_NAMES 0, __URI_IN_BODY 0, __URI_NOT_IMG 0, __URI_NS , __URI_WITH_PATH 0, __USER_AGENT 0' 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? And here's tested version that actually works for me. Wants moving to common code, perhaps renaming functions. Signed-off-by: Pavel Machek Best regards, Pavel diff --git a/drivers/media/i2c/et8ek8/et8ek8_driver.c b/drivers/media/i2c/et8ek8/et8ek8_driver.c index 05b9bd9..4674939 100644 --- a/drivers/media/i2c/et8ek8/et8ek8_driver.c +++ b/drivers/media/i2c/et8ek8/et8ek8_driver.c @@ -32,13 +32,92 @@ #include #include #include -#include +#include +#include #include #include #include #include +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" }; + 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 +146,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) @@ -1509,8 +1590,9 @@ et8ek8_registered(struct v4l2_subdev *subdev) dev_err(&client->dev, "controls initialization failed\n"); goto err_file; } - + __et8ek8_get_pad_format(sensor, NULL, 0, V4L2_SUBDEV_FORMAT_ACTIVE); + v4l2_simple_subnotifier_register(subdev, &sensor->notifier_s); return 0; @@ -1663,7 +1745,13 @@ static int et8ek8_probe(struct i2c_client *client, return ret; } + sensor->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR; + mutex_init(&sensor->power_lock); + + ret = simple_subdev_probe(dev, &sensor->notifier_s.notifier); + if (ret < 0) + printk("Simple subdev probe failed\n"); v4l2_i2c_subdev_init(&sensor->subdev, client, &et8ek8_ops); sensor->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; @@ -1703,6 +1791,7 @@ static int __exit et8ek8_remove(struct i2c_client *client) } v4l2_device_unregister_subdev(&sensor->subdev); + /* FIXME: v4l2_async_subnotifier_unregister(&sensor->notifier_s.notifier); */ device_remove_file(&client->dev, &dev_attr_priv_mem); v4l2_ctrl_handler_free(&sensor->ctrl_handler); v4l2_async_unregister_subdev(&sensor->subdev); 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 *