From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl
Subject: [PATCH v3 3/5] mc: Provide a helper for setting bus_info field
Date: Wed, 9 Mar 2022 18:31:10 +0200 [thread overview]
Message-ID: <20220309163112.11708-4-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20220309163112.11708-1-sakari.ailus@linux.intel.com>
The bus_info or a similar field exists in a lot of structs, yet drivers
tend to set the value of that field by themselves in a determinable way.
Thus provide a helper for doing this. To be used in subsequent patches.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
include/media/media-device.h | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/include/media/media-device.h b/include/media/media-device.h
index bc015d2cf541..2122d15bde4e 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -13,12 +13,13 @@
#include <linux/list.h>
#include <linux/mutex.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
#include <media/media-devnode.h>
#include <media/media-entity.h>
struct ida;
-struct device;
struct media_device;
/**
@@ -181,8 +182,7 @@ struct media_device {
atomic_t request_id;
};
-/* We don't need to include pci.h or usb.h here */
-struct pci_dev;
+/* We don't need to include usb.h here */
struct usb_device;
#ifdef CONFIG_MEDIA_CONTROLLER
@@ -502,4 +502,28 @@ static inline void __media_device_usb_init(struct media_device *mdev,
#define media_device_usb_init(mdev, udev, name) \
__media_device_usb_init(mdev, udev, name, KBUILD_MODNAME)
+
+/**
+ * media_set_bus_info() - Set bus_info field
+ *
+ * @bus_info: Variable where to write the bus info (char array)
+ * @bus_info_size: Length of the bus_info
+ * @dev: Related struct device
+ *
+ * Sets bus information based on &dev. This is currently done for PCI and
+ * platform devices. dev is required to be non-NULL for this to happen.
+ *
+ * This function is not meant to be called from drivers.
+ */
+static inline void
+media_set_bus_info(char *bus_info, size_t bus_info_size, struct device *dev)
+{
+ if (!dev)
+ strscpy(bus_info, "no bus info", bus_info_size);
+ else if (dev_is_platform(dev))
+ snprintf(bus_info, bus_info_size, "platform:%s", dev_name(dev));
+ else if (dev_is_pci(dev))
+ snprintf(bus_info, bus_info_size, "PCI:%s", dev_name(dev));
+}
+
#endif
--
2.30.2
next prev parent reply other threads:[~2022-03-09 16:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-09 16:31 [PATCH v3 0/5] Set bus_info field in framework Sakari Ailus
2022-03-09 16:31 ` [PATCH v3 1/5] mc: Remove redundant documentation Sakari Ailus
2022-03-09 16:31 ` [PATCH v3 2/5] mc: media_device_init() initialises a media_device, not media_entity Sakari Ailus
2022-03-16 9:15 ` Laurent Pinchart
2022-03-09 16:31 ` Sakari Ailus [this message]
2022-03-16 9:18 ` [PATCH v3 3/5] mc: Provide a helper for setting bus_info field Laurent Pinchart
2022-03-16 9:24 ` Laurent Pinchart
2022-03-16 9:50 ` Sakari Ailus
2022-03-09 16:31 ` [PATCH v3 4/5] mc: Set bus_info in media_device_init() Sakari Ailus
2022-03-16 9:22 ` Laurent Pinchart
2022-03-09 16:31 ` [PATCH v3 5/5] v4l: ioctl: Set bus_info in v4l_querycap() Sakari Ailus
2022-04-14 11:07 ` [PATCH v4 " 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=20220309163112.11708-4-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.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