Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1031663imm; Mon, 9 Jul 2018 15:46:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdzjHZCxvPBRy87mv0YzdpSJ5PXTi6FcEktA4vul6S6mRqaXjlbi6zbVNeb/4i/vFwulf9N X-Received: by 2002:a63:8449:: with SMTP id k70-v6mr13997650pgd.309.1531176359992; Mon, 09 Jul 2018 15:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531176359; cv=none; d=google.com; s=arc-20160816; b=As7LM5gcCANEV/iYehWmAaLMqf5SoNCqHwbaYOeY/wmDuNUUfFoD52Y9dQgLPXa0Ae KCcftDyhTCfR/+dTq+M58kyHZNr5DIaj9Y7hfuqa1r2kQz22gONbcEOTJ/dD5YAnpuqP 1/y3mTXQYrrxDKyqSh88HnlQf0XtgHQcu0aUtEhnGgzUgXKjRC3OTFlzzAcjQT3egQAk tfQgZmIM/lxM039V9TBCfTePgMXBi7d/FJduVM74/XQaebuBKP3LxfFAbu8z1gbBo67a Cl2aH2OlyUm41HtO8d+Q2r5MZBClyMHlQdxJ4UXzWok5ScnShyHmmNXq+e2wIZDT5PXF N7+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=w0bcY2PyJkSTb9lDqIgTQ12xU/cABmv33pZVXJ39g4A=; b=alG40gWW3qdJASII+hYotNmxGnOEnT32f89bjFEq1n2mZr2evy9w8fjyVqeFkcKXGd URhO6VsJAEXOdqq2UGQIqa8H+wIlqB92EKGSr14DIvRlzK3nqRNw01Gisfz39L0nLuYX dxSYKCY5qQWVCyRcWEoCm+aC2S50ZTonvs3feb4HGAvvWBn+bqwgrM1cTP2ePYHqNoi5 VEvv2x5FHXPHeGJjR/hUmjrLcSJuIDpgprAxNFVO9fMznHS6/qa0rLQYDtzAnSl5REia Ywtcco82M3C4oYWpWJuutqE+7YYxyE+pWBY27GT+wlqhhRV9qUPOD1Evpnr5FpeeTtvA zVcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MzDo26rV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si15155128plh.492.2018.07.09.15.45.45; Mon, 09 Jul 2018 15:45:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MzDo26rV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933353AbeGIWjo (ORCPT + 99 others); Mon, 9 Jul 2018 18:39:44 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:43691 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932798AbeGIWjl (ORCPT ); Mon, 9 Jul 2018 18:39:41 -0400 Received: by mail-pl0-f68.google.com with SMTP id c41-v6so6676457plj.10; Mon, 09 Jul 2018 15:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=w0bcY2PyJkSTb9lDqIgTQ12xU/cABmv33pZVXJ39g4A=; b=MzDo26rVkParcgS7BVEKmz2fXXnMijcqEVr9YHyPBOVgcR8qOVqXkNqq7g7p27cdJ0 im5v6B1rJQtr1NTo85PnwHQBFzSvNW9rx46/FrQD2LquDr4lXhuLdvxPtLSDlhQnuLn9 tFn6TLeL+xUZD2qRXh+7ambxRyjgsrbflQtZ3cAZJSh+5DsapIqmGMksdPAdTucJdUju 5BXx7ou1TjDLwrNonoIEZuJSAvamWs6JicaFvevKi5RCbWVEaHT93l3SFqSyjoNXspDY mWaqMGRabqZrrXRWhci0Rfy1G2zmasugudGWp2vlqceSMaHG7HXEkRp2eTXKZPVJqvvH JR9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=w0bcY2PyJkSTb9lDqIgTQ12xU/cABmv33pZVXJ39g4A=; b=RjkpET+fhInFBMVPSn4XDZN3hQ/NkcB1PPQBcxC2TXR3gZysIkJl0hGH/76xWTBRf/ uppsKH+x5uEwhFWi50g21As/le808Y8WyvMLSAmB8U3GXOqmB373ostI7AJ5gkopAr1Q maAroP+yUvmXl0/G0NO0Pt8m5oNoz14v+POE9GF0euWzxJjYFMMfcaUIld7Es+e6qJuk JGx6CsCl49pXFntQSj1sm6K6tsmm+ERwjzVwvO54C2HxBPc3l9sycPa0ZaW2YaORaPJ9 99SErXPfPIqJQG12xBo/qsb7G0LnIgm7O4ygPC8YL08QM/ikDD7c35XBAms9HaUOq1DM twCw== X-Gm-Message-State: APt69E31Em1dk4Gn8LceIZmhq4yNYxkR4RStr7XL4/SIu5263B4rxbwQ dSxOOYDhN3OPDQ0GygDUeS1YLA== X-Received: by 2002:a17:902:b589:: with SMTP id a9-v6mr22369869pls.140.1531175980669; Mon, 09 Jul 2018 15:39:40 -0700 (PDT) Received: from majic.sklembedded.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.googlemail.com with ESMTPSA id r16-v6sm30143804pfe.173.2018.07.09.15.39.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Jul 2018 15:39:39 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Mauro Carvalho Chehab , =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Sakari Ailus , Sebastian Reichel , Hans Verkuil , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v6 04/17] media: v4l2: async: Add convenience functions to allocate and add asd's Date: Mon, 9 Jul 2018 15:39:04 -0700 Message-Id: <1531175957-1973-5-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531175957-1973-1-git-send-email-steve_longerbeam@mentor.com> References: <1531175957-1973-1-git-send-email-steve_longerbeam@mentor.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add these convenience functions, which allocate an asd of match type fwnode, i2c, or device-name, of size asd_struct_size, and then adds them to the notifier asd_list. Signed-off-by: Steve Longerbeam --- drivers/media/v4l2-core/v4l2-async.c | 76 ++++++++++++++++++++++++++++++++++++ include/media/v4l2-async.h | 62 +++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 8e52df2..e60a82a 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -646,6 +646,82 @@ int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, } EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_subdev); +struct v4l2_async_subdev * +v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, + struct fwnode_handle *fwnode, + unsigned int asd_struct_size) +{ + struct v4l2_async_subdev *asd; + int ret; + + asd = kzalloc(asd_struct_size, GFP_KERNEL); + if (!asd) + return ERR_PTR(-ENOMEM); + + asd->match_type = V4L2_ASYNC_MATCH_FWNODE; + asd->match.fwnode = fwnode; + + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret) { + kfree(asd); + return ERR_PTR(ret); + } + + return asd; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_fwnode_subdev); + +struct v4l2_async_subdev * +v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier, + int adapter_id, unsigned short address, + unsigned int asd_struct_size) +{ + struct v4l2_async_subdev *asd; + int ret; + + asd = kzalloc(asd_struct_size, GFP_KERNEL); + if (!asd) + return ERR_PTR(-ENOMEM); + + asd->match_type = V4L2_ASYNC_MATCH_I2C; + asd->match.i2c.adapter_id = adapter_id; + asd->match.i2c.address = address; + + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret) { + kfree(asd); + return ERR_PTR(ret); + } + + return asd; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_i2c_subdev); + +struct v4l2_async_subdev * +v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier, + const char *device_name, + unsigned int asd_struct_size) +{ + struct v4l2_async_subdev *asd; + int ret; + + asd = kzalloc(asd_struct_size, GFP_KERNEL); + if (!asd) + return ERR_PTR(-ENOMEM); + + asd->match_type = V4L2_ASYNC_MATCH_DEVNAME; + asd->match.device_name = device_name; + + ret = v4l2_async_notifier_add_subdev(notifier, asd); + if (ret) { + kfree(asd); + return ERR_PTR(ret); + } + + return asd; +} +EXPORT_SYMBOL_GPL(v4l2_async_notifier_add_devname_subdev); + int v4l2_async_register_subdev(struct v4l2_subdev *sd) { struct v4l2_async_notifier *subdev_notifier; diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h index ab4d7ac..3489e4c 100644 --- a/include/media/v4l2-async.h +++ b/include/media/v4l2-async.h @@ -175,6 +175,68 @@ int v4l2_async_notifier_add_subdev(struct v4l2_async_notifier *notifier, struct v4l2_async_subdev *asd); /** + * v4l2_async_notifier_add_fwnode_subdev - Allocate and add a fwnode async + * subdev to the notifier's master asd_list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @fwnode: fwnode handle of the sub-device to be matched + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * + * This can be used before registering a notifier to add a + * fwnode-matched asd to the notifiers master asd_list. If the caller + * uses this method to compose an asd list, it must never allocate + * or place asd's in the @subdevs array. + */ +struct v4l2_async_subdev * +v4l2_async_notifier_add_fwnode_subdev(struct v4l2_async_notifier *notifier, + struct fwnode_handle *fwnode, + unsigned int asd_struct_size); + +/** + * v4l2_async_notifier_add_i2c_subdev - Allocate and add an i2c async + * subdev to the notifier's master asd_list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @adapter_id: I2C adapter ID to be matched + * @address: I2C address of sub-device to be matched + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * + * Same as above but for I2C matched sub-devices. + */ +struct v4l2_async_subdev * +v4l2_async_notifier_add_i2c_subdev(struct v4l2_async_notifier *notifier, + int adapter_id, unsigned short address, + unsigned int asd_struct_size); + +/** + * v4l2_async_notifier_add_devname_subdev - Allocate and add a device-name + * async subdev to the notifier's master asd_list. + * + * @notifier: pointer to &struct v4l2_async_notifier + * @device_name: device name string to be matched + * @asd_struct_size: size of the driver's async sub-device struct, including + * sizeof(struct v4l2_async_subdev). The &struct + * v4l2_async_subdev shall be the first member of + * the driver's async sub-device struct, i.e. both + * begin at the same memory address. + * + * Same as above but for device-name matched sub-devices. + */ +struct v4l2_async_subdev * +v4l2_async_notifier_add_devname_subdev(struct v4l2_async_notifier *notifier, + const char *device_name, + unsigned int asd_struct_size); + + +/** * v4l2_async_notifier_register - registers a subdevice asynchronous notifier * * @v4l2_dev: pointer to &struct v4l2_device -- 2.7.4