From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com, jacopo.mondi@ideasonboard.com,
Bingbu Cao <bingbu.cao@intel.com>,
Tianshu Qiu <tian.shu.qiu@intel.com>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>
Subject: [PATCH 1/4] media: v4l: Add a helper for setting up link-frequencies control
Date: Mon, 11 Dec 2023 16:06:55 +0200 [thread overview]
Message-ID: <20231211140658.366268-2-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20231211140658.366268-1-sakari.ailus@linux.intel.com>
Add a helper for obtaining supported link frequencies in form most drivers
need them. The result is a bitmap of supported controls.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/v4l2-core/v4l2-common.c | 48 +++++++++++++++++++++++++++
include/media/v4l2-common.h | 27 +++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index e9e7e70fa24e..63302009db5f 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -585,3 +585,51 @@ u32 v4l2_fraction_to_interval(u32 numerator, u32 denominator)
return denominator ? numerator * multiplier / denominator : 0;
}
EXPORT_SYMBOL_GPL(v4l2_fraction_to_interval);
+
+int v4l2_link_frequencies_to_bitmap(struct device *dev,
+ const u64 *fw_link_freqs,
+ unsigned int num_of_fw_link_freqs,
+ const s64 *driver_link_freqs,
+ unsigned int num_of_driver_link_freqs,
+ unsigned long *bitmap)
+{
+ unsigned int i;
+
+ *bitmap = 0;
+
+ if (!num_of_fw_link_freqs) {
+ dev_err(dev, "no link frequencies in firmware\n");
+ return -ENODATA;
+ }
+
+ for (i = 0; i < num_of_fw_link_freqs; i++) {
+ unsigned int j;
+
+ for (j = 0; j < num_of_driver_link_freqs; j++) {
+ if (fw_link_freqs[i] != driver_link_freqs[j])
+ continue;
+
+ dev_dbg(dev, "enabling link frequency %lld Hz\n",
+ driver_link_freqs[j]);
+ *bitmap |= BIT(j);
+ break;
+ }
+ }
+
+ if (!*bitmap) {
+ dev_err(dev, "no matching link frequencies found\n");
+
+ dev_dbg(dev, "specified in firmware:\n");
+ for (i = 0; i < num_of_fw_link_freqs; i++)
+ dev_dbg(dev, "\t%llu Hz\n", fw_link_freqs[i]);
+
+ dev_dbg(dev, "driver supported:\n");
+ for (i = 0; i < num_of_driver_link_freqs; i++)
+ dev_dbg(dev, "\t%lld Hz\n", driver_link_freqs[i]);
+
+ return -ENOENT;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_link_frequencies_to_bitmap);
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index d278836fd9cb..adf997baf659 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -547,6 +547,33 @@ void v4l2_simplify_fraction(u32 *numerator, u32 *denominator,
unsigned int n_terms, unsigned int threshold);
u32 v4l2_fraction_to_interval(u32 numerator, u32 denominator);
+/**
+ * v4l2_link_frequencies_to_bitmap - Figure out platform-supported link
+ * frequencies
+ * @dev: The struct device
+ * @fw_link_freqs: Array of link frequencies from firmware
+ * @num_of_fw_link_freqs: Number of entries in @fw_link_freqs
+ * @driver_link_freqs: Array of link frequencies supported by the driver
+ * @num_of_driver_link_freqs: Number of entries in @driver_link_freqs
+ * @bitmap: Bitmap of driver-supported link frequencies found in @fw_link_freqs
+ *
+ * This function checks which driver-supported link frequencies are enabled in
+ * system firmware and sets the corresponding bits in @bitmap (after first
+ * zeroing it).
+ *
+ * Return values:
+ * 0: Success
+ * -ENOENT: No match found between driver-supported link frequencies and
+ * those available in firmware.
+ * -ENODATA: No link frequencies were specified in firmware.
+ */
+int v4l2_link_frequencies_to_bitmap(struct device *dev,
+ const u64 *fw_link_freqs,
+ unsigned int num_of_fw_link_freqs,
+ const s64 *driver_link_freqs,
+ unsigned int num_of_driver_link_freqs,
+ unsigned long *bitmap);
+
static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf)
{
/*
--
2.39.2
next prev parent reply other threads:[~2023-12-11 14:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 14:06 [PATCH 0/4] Add link frequency to bitmap helper Sakari Ailus
2023-12-11 14:06 ` Sakari Ailus [this message]
2023-12-12 16:07 ` [PATCH 1/4] media: v4l: Add a helper for setting up link-frequencies control kernel test robot
2023-12-11 14:06 ` [PATCH 2/4] media: imx334: Use v4l2_link_frequencies_to_bitmap helper Sakari Ailus
2023-12-11 20:37 ` kernel test robot
2023-12-11 14:06 ` [PATCH 3/4] media: imx319: " Sakari Ailus
2023-12-13 2:16 ` Cao, Bingbu
2023-12-13 9:51 ` Sakari Ailus
2023-12-11 14:06 ` [PATCH 4/4] media: imx355: " 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=20231211140658.366268-2-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=bingbu.cao@intel.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=tian.shu.qiu@intel.com \
/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