linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
To: linux-media@vger.kernel.org
Cc: dafna.hirschfeld@collabora.com,
	laurent.pinchart@ideasonboard.com, helen.koike@collabora.com,
	ezequiel@collabora.com, andre.almeida@collabora.com,
	skhan@linuxfoundation.org, hverkuil@xs4all.nl,
	kernel@collabora.com, dafna3@gmail.com
Subject: [PATCH 5/5] media: vimc: Add device index to the bus_info
Date: Thu, 19 Sep 2019 23:32:08 +0300	[thread overview]
Message-ID: <20190919203208.12515-6-dafna.hirschfeld@collabora.com> (raw)
In-Reply-To: <20190919203208.12515-1-dafna.hirschfeld@collabora.com>

Use a bitmask to get the next available device index
to be used for the bus_info field in the v4l2_capability
struct in the VIDIOC_QUERYCAP ioctl

Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
---
 drivers/media/platform/vimc/vimc-capture.c |  8 ++++++--
 drivers/media/platform/vimc/vimc-common.h  |  2 ++
 drivers/media/platform/vimc/vimc-core.c    | 24 +++++++++++++++++++++-
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c
index 6ccf879c0b75..408bacb7c77e 100644
--- a/drivers/media/platform/vimc/vimc-capture.c
+++ b/drivers/media/platform/vimc/vimc-capture.c
@@ -31,6 +31,7 @@ struct vimc_cap_device {
 	struct mutex lock;
 	u32 sequence;
 	struct vimc_stream stream;
+	char bus_info[32];
 };
 
 static const struct v4l2_pix_format fmt_default = {
@@ -55,10 +56,12 @@ struct vimc_cap_buffer {
 static int vimc_cap_querycap(struct file *file, void *priv,
 			     struct v4l2_capability *cap)
 {
+	struct vimc_cap_device *vcap = video_drvdata(file);
+
 	strscpy(cap->driver, VIMC_PDEV_NAME, sizeof(cap->driver));
 	strscpy(cap->card, KBUILD_MODNAME, sizeof(cap->card));
-	snprintf(cap->bus_info, sizeof(cap->bus_info),
-		 "platform:%s", VIMC_PDEV_NAME);
+	strscpy(cap->bus_info, vcap->bus_info, sizeof(cap->bus_info));
+
 
 	return 0;
 }
@@ -456,6 +459,7 @@ struct vimc_ent_device *vimc_cap_add(struct vimc_device *vimc,
 	vcap->ved.vdev_get_format = vimc_cap_get_format;
 
 	vcap->dev = vimc->mdev.dev;
+	strscpy(vcap->bus_info, vimc->mdev.bus_info, sizeof(vcap->bus_info));
 
 	/* Initialize the video_device struct */
 	vdev = &vcap->vdev;
diff --git a/drivers/media/platform/vimc/vimc-common.h b/drivers/media/platform/vimc/vimc-common.h
index 5c7f451a7bf0..489b32f79b23 100644
--- a/drivers/media/platform/vimc/vimc-common.h
+++ b/drivers/media/platform/vimc/vimc-common.h
@@ -143,12 +143,14 @@ struct vimc_link {
  * struct vimc_device - main device for vimc driver
  *
  * @mdev	the associated media_device parent
+ * @idx		the index of the device, used for info_bus
  * @v4l2_dev	Internal v4l2 parent device
  * @ents	list of vimc_ent_device objects
  */
 struct vimc_device {
 	struct media_device mdev;
 	struct v4l2_device v4l2_dev;
+	unsigned int idx;
 
 	struct list_head ents;
 };
diff --git a/drivers/media/platform/vimc/vimc-core.c b/drivers/media/platform/vimc/vimc-core.c
index 06a36cc1f00c..6065dd51438a 100644
--- a/drivers/media/platform/vimc/vimc-core.c
+++ b/drivers/media/platform/vimc/vimc-core.c
@@ -17,6 +17,11 @@
 
 #include "vimc-configfs.h"
 
+#define VIMC_MAX_DEVS 64
+
+
+static DECLARE_BITMAP(used, VIMC_MAX_DEVS);
+static DEFINE_MUTEX(vimc_dev_idx_lock);
 
 static struct vimc_ent_type ent_types[] = {
 	{
@@ -201,9 +206,20 @@ static int vimc_probe(struct platform_device *pdev)
 	const struct vimc_platform_data_core *pdata = pdev->dev.platform_data;
 	struct vimc_device *vimc;
 	int ret;
+	unsigned int idx;
 
 	dev_dbg(&pdev->dev, "probe\n");
 
+	mutex_lock(&vimc_dev_idx_lock);
+	idx = find_first_zero_bit(used, VIMC_MAX_DEVS);
+	if (idx == VIMC_MAX_DEVS) {
+		mutex_unlock(&vimc_dev_idx_lock);
+		dev_err(&pdev->dev, "there are already %u devs which is the max allowed\n",
+			VIMC_MAX_DEVS);
+		return -EBUSY;
+	}
+	set_bit(idx, used);
+	mutex_unlock(&vimc_dev_idx_lock);
 	vimc = devm_kzalloc(&pdev->dev, sizeof(*vimc),
 			GFP_KERNEL);
 	if (!vimc)
@@ -211,6 +227,7 @@ static int vimc_probe(struct platform_device *pdev)
 
 	memset(&vimc->mdev, 0, sizeof(vimc->mdev));
 	INIT_LIST_HEAD(&vimc->ents);
+	vimc->idx = idx;
 
 	/* Link the media device within the v4l2_device */
 	vimc->v4l2_dev.mdev = &vimc->mdev;
@@ -219,7 +236,8 @@ static int vimc_probe(struct platform_device *pdev)
 	strscpy(vimc->mdev.model, VIMC_MDEV_MODEL_NAME,
 		sizeof(vimc->mdev.model));
 	snprintf(vimc->mdev.bus_info, sizeof(vimc->mdev.bus_info),
-		 "platform:%s", VIMC_PDEV_NAME);
+		 "platform:%s-%03u", VIMC_PDEV_NAME, idx);
+
 	vimc->mdev.dev = &pdev->dev;
 	media_device_init(&vimc->mdev);
 
@@ -234,6 +252,7 @@ static int vimc_remove(struct platform_device *pdev)
 {
 	struct vimc_device *vimc = platform_get_drvdata(pdev);
 	struct vimc_platform_data_core *pdata = pdev->dev.platform_data;
+	unsigned long idx = vimc->idx;
 
 	dev_dbg(&pdev->dev, "remove\n");
 
@@ -242,6 +261,9 @@ static int vimc_remove(struct platform_device *pdev)
 	vimc_rm_subdevs(vimc, pdata);
 	v4l2_device_unregister(&vimc->v4l2_dev);
 
+	mutex_lock(&vimc_dev_idx_lock);
+	clear_bit(idx, used);
+	mutex_unlock(&vimc_dev_idx_lock);
 	return 0;
 }
 
-- 
2.20.1


  parent reply	other threads:[~2019-09-19 20:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 20:32 [PATCH 0/5] media: vimc: use configfs in order to configure devices topologies Dafna Hirschfeld
2019-09-19 20:32 ` [PATCH 1/5] media: vimc: upon streaming, check that the pipeline starts with a source entity Dafna Hirschfeld
2019-09-26 14:32   ` Shuah Khan
2019-10-08 13:34     ` Dafna Hirschfeld
2019-09-19 20:32 ` [PATCH 2/5] docs: media: vimc: Documenting vimc topology configuration using configfs Dafna Hirschfeld
2019-09-20 13:39   ` Hans Verkuil
2019-09-23  9:29     ` Dafna Hirschfeld
2019-09-23  9:50       ` Hans Verkuil
2019-09-27  5:56         ` Andrzej Pietrasiewicz
2019-09-26 18:59   ` Shuah Khan
2019-09-19 20:32 ` [PATCH 3/5] media: vimc: Add the implementation for the configfs api Dafna Hirschfeld
2019-09-26 19:25   ` Shuah Khan
2019-11-04 15:28     ` Dafna Hirschfeld
2019-09-27  7:55   ` Andrzej Pietrasiewicz
2019-09-19 20:32 ` [PATCH 4/5] media: vimc: use configfs instead of having hardcoded configuration Dafna Hirschfeld
2019-09-26 19:41   ` Shuah Khan
2019-09-19 20:32 ` Dafna Hirschfeld [this message]
2019-09-20 13:17 ` [PATCH 0/5] media: vimc: use configfs in order to configure devices topologies Hans Verkuil
2019-09-20 15:07   ` Dafna Hirschfeld
2019-09-20 15:10     ` 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=20190919203208.12515-6-dafna.hirschfeld@collabora.com \
    --to=dafna.hirschfeld@collabora.com \
    --cc=andre.almeida@collabora.com \
    --cc=dafna3@gmail.com \
    --cc=ezequiel@collabora.com \
    --cc=helen.koike@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@collabora.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=skhan@linuxfoundation.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;
as well as URLs for NNTP newsgroup(s).