The patch series added a new bus type vchiq_bus_type and registers
child devices in order to move them away from using platform
device/driver.
Patch 1/5 and 2/5 adds a new bus_type and registers them to vchiq
interface
Patch 3/5 and 4/5 moves the bcm2835-camera and bcm2835-audio
to the new bus respectively
Patch 5/5 removes a platform registeration helper which is no
longer required.
Changes in v8:
- Drop dual licensing. Instead use GPL-2.0 only for patch 1/5
Changes in v7:
(5 out of 6 patches from v6 merged)
- Split the main patch (6/6) as requested.
- Use struct vchiq_device * instead of struct device * in
all bus functions.
- Drop additional name attribute displayed in sysfs (redundant info)
- Document vchiq_interface doesn't enumerate device discovery
- remove EXPORT_SYMBOL_GPL(vchiq_bus_type)
Changes in v6:
- Split struct device and struct driver wrappers in vchiq_device.[ch]
- Move vchiq_bus_type definition to vchiq_device.[ch] as well
- return error on bus_register() failure
- drop dma_set_mask_and_coherent
- trivial variable name change
Changes in v5:
- Fixup missing "staging: " in commits' subject line
- No code changes from v4
Changes in v4:
- Introduce patches to drop include directives from Makefile
Changes in v3:
- Rework entirely to replace platform devices/driver model
-v2:
https://lore.kernel.org/all/[email protected]/
-v1:
https://lore.kernel.org/all/[email protected]/
Umang Jain (5):
staging: vc04_services: vchiq_arm: Add new bus type and device type
staging: vc04_services: vchiq_arm: Register vchiq_bus_type
staging: bcm2835-camera: Register bcm2835-camera with vchiq_bus_type
staging: bcm2835-audio: Register bcm2835-audio with vchiq_bus_type
staging: vc04_services: vchiq_arm: Remove vchiq_register_child()
drivers/staging/vc04_services/Makefile | 1 +
.../vc04_services/bcm2835-audio/bcm2835.c | 17 ++--
.../bcm2835-camera/bcm2835-camera.c | 16 ++--
.../interface/vchiq_arm/vchiq_arm.c | 56 +++++++------
.../interface/vchiq_arm/vchiq_device.c | 78 +++++++++++++++++++
.../interface/vchiq_arm/vchiq_device.h | 43 ++++++++++
6 files changed, 165 insertions(+), 46 deletions(-)
create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
--
2.39.1
vchiq_register_child() is used to registered child devices as platform
devices. Now that the child devices are migrated to use the
vchiq_bus_type instead, they will be registered to that. Hence, drop
vchiq_register_child() as it is no more required.
Signed-off-by: Umang Jain <[email protected]>
---
.../interface/vchiq_arm/vchiq_arm.c | 22 -------------------
1 file changed, 22 deletions(-)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 75da37fa6372..3c52b09c49ea 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1778,28 +1778,6 @@ static const struct of_device_id vchiq_of_match[] = {
};
MODULE_DEVICE_TABLE(of, vchiq_of_match);
-static struct platform_device *
-vchiq_register_child(struct platform_device *pdev, const char *name)
-{
- struct platform_device_info pdevinfo;
- struct platform_device *child;
-
- memset(&pdevinfo, 0, sizeof(pdevinfo));
-
- pdevinfo.parent = &pdev->dev;
- pdevinfo.name = name;
- pdevinfo.id = PLATFORM_DEVID_NONE;
- pdevinfo.dma_mask = DMA_BIT_MASK(32);
-
- child = platform_device_register_full(&pdevinfo);
- if (IS_ERR(child)) {
- dev_warn(&pdev->dev, "%s not registered\n", name);
- child = NULL;
- }
-
- return child;
-}
-
static int vchiq_probe(struct platform_device *pdev)
{
struct device_node *fw_node;
--
2.39.1
Register the vchiq_bus_type bus with the vchiq interface.
The bcm2835-camera nad bcm2835_audio will be registered to this bus type
going ahead.
Signed-off-by: Umang Jain <[email protected]>
---
.../vc04_services/interface/vchiq_arm/vchiq_arm.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index aa2313f3bcab..e8d40f891449 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -12,6 +12,7 @@
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/device.h>
+#include <linux/device/bus.h>
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
@@ -34,6 +35,7 @@
#include "vchiq_ioctl.h"
#include "vchiq_arm.h"
#include "vchiq_debugfs.h"
+#include "vchiq_device.h"
#include "vchiq_connected.h"
#include "vchiq_pagelist.h"
@@ -1870,6 +1872,12 @@ static int __init vchiq_driver_init(void)
{
int ret;
+ ret = bus_register(&vchiq_bus_type);
+ if (ret) {
+ pr_err("Failed to register %s\n", vchiq_bus_type.name);
+ return ret;
+ }
+
ret = platform_driver_register(&vchiq_driver);
if (ret)
pr_err("Failed to register vchiq driver\n");
@@ -1880,6 +1888,7 @@ module_init(vchiq_driver_init);
static void __exit vchiq_driver_exit(void)
{
+ bus_unregister(&vchiq_bus_type);
platform_driver_unregister(&vchiq_driver);
}
module_exit(vchiq_driver_exit);
--
2.39.1
Similar to how bcm2385-camera device is registered, register the
bcm2835-audio with vchiq_bus_type as well.
Signed-off-by: Umang Jain <[email protected]>
---
.../vc04_services/bcm2835-audio/bcm2835.c | 17 ++++++++---------
.../interface/vchiq_arm/vchiq_arm.c | 6 +-----
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 00bc898b0189..f81a9a4fbd5d 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2011 Broadcom Corporation. All rights reserved. */
-#include <linux/platform_device.h>
-
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
+#include "../interface/vchiq_arm/vchiq_arm.h"
+#include "../interface/vchiq_arm/vchiq_device.h"
#include "bcm2835.h"
static bool enable_hdmi;
@@ -268,9 +268,9 @@ static int snd_add_child_devices(struct device *device, u32 numchans)
return 0;
}
-static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
+static int snd_bcm2835_alsa_probe(struct vchiq_device *device)
{
- struct device *dev = &pdev->dev;
+ struct device *dev = &device->dev;
int err;
if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
@@ -292,20 +292,20 @@ static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
#ifdef CONFIG_PM
-static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
+static int snd_bcm2835_alsa_suspend(struct vchiq_device *device,
pm_message_t state)
{
return 0;
}
-static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
+static int snd_bcm2835_alsa_resume(struct vchiq_device *device)
{
return 0;
}
#endif
-static struct platform_driver bcm2835_alsa_driver = {
+static struct vchiq_driver bcm2835_alsa_driver = {
.probe = snd_bcm2835_alsa_probe,
#ifdef CONFIG_PM
.suspend = snd_bcm2835_alsa_suspend,
@@ -315,9 +315,8 @@ static struct platform_driver bcm2835_alsa_driver = {
.name = "bcm2835_audio",
},
};
-module_platform_driver(bcm2835_alsa_driver);
+module_vchiq_driver(bcm2835_alsa_driver);
MODULE_AUTHOR("Dom Cobley");
MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:bcm2835_audio");
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 79d4d0eeb5fb..75da37fa6372 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -67,8 +67,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
DEFINE_SPINLOCK(msg_queue_spinlock);
struct vchiq_state g_state;
-static struct platform_device *bcm2835_audio;
-
struct vchiq_drvdata {
const unsigned int cache_line_size;
struct rpi_firmware *fw;
@@ -139,6 +137,7 @@ struct vchiq_pagelist_info {
* the interface.
*/
static const char *const vchiq_devices[] = {
+ "bcm2835_audio",
"bcm2835-camera",
};
@@ -1849,8 +1848,6 @@ static int vchiq_probe(struct platform_device *pdev)
goto error_exit;
}
- bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
-
for (i = 0; i < ARRAY_SIZE(vchiq_devices); i++) {
err = vchiq_device_register(&pdev->dev, vchiq_devices[i]);
if (err)
@@ -1868,7 +1865,6 @@ static int vchiq_probe(struct platform_device *pdev)
static void vchiq_remove(struct platform_device *pdev)
{
- platform_device_unregister(bcm2835_audio);
bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
vchiq_debugfs_deinit();
vchiq_deregister_chrdev();
--
2.39.1
The devices that the vchiq interface registers (bcm2835-audio,
bcm2835-camera) are implemented and exposed by the VC04 firmware.
The device tree describes the VC04 itself with the resources required
to communicate with it through a mailbox interface. However, the
vchiq interface registers these devices as platform devices. This
also means the specific drivers for these devices are getting
registered as platform drivers. This is not correct and a blatant
abuse of platform device/driver.
Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
which will be used to migrate child devices that the vchiq interfaces
creates/registers from the platform device/driver.
Signed-off-by: Umang Jain <[email protected]>
---
drivers/staging/vc04_services/Makefile | 1 +
.../interface/vchiq_arm/vchiq_device.c | 78 +++++++++++++++++++
.../interface/vchiq_arm/vchiq_device.h | 43 ++++++++++
3 files changed, 122 insertions(+)
create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
index 44794bdf6173..2d071e55e175 100644
--- a/drivers/staging/vc04_services/Makefile
+++ b/drivers/staging/vc04_services/Makefile
@@ -5,6 +5,7 @@ vchiq-objs := \
interface/vchiq_arm/vchiq_core.o \
interface/vchiq_arm/vchiq_arm.o \
interface/vchiq_arm/vchiq_debugfs.o \
+ interface/vchiq_arm/vchiq_device.o \
interface/vchiq_arm/vchiq_connected.o \
ifdef CONFIG_VCHIQ_CDEV
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
new file mode 100644
index 000000000000..dff312e9735c
--- /dev/null
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * vchiq_device.c - VCHIQ generic device and bus-type
+ *
+ * Copyright (c) 2023 Ideas On Board Oy
+ */
+
+#include <linux/device/bus.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "vchiq_device.h"
+
+static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv);
+
+struct bus_type vchiq_bus_type = {
+ .name = "vchiq-bus",
+ .match = vchiq_bus_type_match,
+};
+
+static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
+{
+ if (dev->bus == &vchiq_bus_type &&
+ strcmp(dev_name(dev), drv->name) == 0)
+ return 1;
+ return 0;
+}
+
+static void vchiq_device_release(struct device *dev)
+{
+ struct vchiq_device *device;
+
+ device = container_of(dev, struct vchiq_device, dev);
+ kfree(device);
+}
+
+int vchiq_device_register(struct device *parent, const char *name)
+{
+ struct vchiq_device *device = NULL;
+ int ret;
+
+ device = kzalloc(sizeof(*device), GFP_KERNEL);
+ if (!device)
+ return -ENOMEM;
+
+ device->dev.init_name = name;
+ device->dev.parent = parent;
+ device->dev.bus = &vchiq_bus_type;
+ device->dev.release = vchiq_device_release;
+
+ ret = device_register(&device->dev);
+ if (ret) {
+ put_device(&device->dev);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int vchiq_device_unregister(struct device *dev, void *data)
+{
+ device_unregister(dev);
+ return 0;
+}
+
+int vchiq_driver_register(struct vchiq_driver *vchiq_drv)
+{
+ vchiq_drv->driver.bus = &vchiq_bus_type;
+
+ return driver_register(&vchiq_drv->driver);
+}
+EXPORT_SYMBOL_GPL(vchiq_driver_register);
+
+void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv)
+{
+ driver_unregister(&vchiq_drv->driver);
+}
+EXPORT_SYMBOL_GPL(vchiq_driver_unregister);
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
new file mode 100644
index 000000000000..dcd8a3d9eebe
--- /dev/null
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 Ideas On Board Oy
+ */
+
+#ifndef _VCHIQ_DEVICE_H
+#define _VCHIQ_DEVICE_H
+
+#include <linux/device.h>
+
+struct vchiq_device {
+ struct device dev;
+};
+
+struct vchiq_driver {
+ int (*probe)(struct vchiq_device *device);
+ void (*remove)(struct vchiq_device *device);
+ int (*resume)(struct vchiq_device *device);
+ int (*suspend)(struct vchiq_device *device,
+ pm_message_t state);
+ struct device_driver driver;
+};
+
+extern struct bus_type vchiq_bus_type;
+
+int vchiq_device_register(struct device *parent, const char *name);
+int vchiq_device_unregister(struct device *dev, void *data);
+
+int vchiq_driver_register(struct vchiq_driver *vchiq_drv);
+void vchiq_driver_unregister(struct vchiq_driver *vchiq_drv);
+
+/**
+ * module_vchiq_driver() - Helper macro for registering a vchiq driver
+ * @__vchiq_driver: vchiq driver struct
+ *
+ * Helper macro for vchiq drivers which do not do anything special in
+ * module init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_vchiq_driver(__vchiq_driver) \
+ module_driver(__vchiq_driver, vchiq_driver_register, vchiq_driver_unregister)
+
+#endif /* _VCHIQ_DEVICE_H */
--
2.39.1
Register the bcm2835-camera with the vchiq_bus_type instead of using
platform driver/device.
Also the VCHIQ firmware doesn't support device enumeration, hence
one has to maintain a list of devices to be registered in the interface.
Signed-off-by: Umang Jain <[email protected]>
---
.../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
.../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 346d00df815a..f37b2a881d92 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -24,8 +24,9 @@
#include <media/v4l2-event.h>
#include <media/v4l2-common.h>
#include <linux/delay.h>
-#include <linux/platform_device.h>
+#include "../interface/vchiq_arm/vchiq_arm.h"
+#include "../interface/vchiq_arm/vchiq_device.h"
#include "../vchiq-mmal/mmal-common.h"
#include "../vchiq-mmal/mmal-encodings.h"
#include "../vchiq-mmal/mmal-vchiq.h"
@@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
.fmt.pix.sizeimage = 1024 * 768,
};
-static int bcm2835_mmal_probe(struct platform_device *pdev)
+static int bcm2835_mmal_probe(struct vchiq_device *device)
{
int ret;
struct bcm2835_mmal_dev *dev;
@@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
&camera_instance);
ret = v4l2_device_register(NULL, &dev->v4l2_dev);
if (ret) {
- dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
+ dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
__func__, ret);
goto free_dev;
}
@@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
return ret;
}
-static void bcm2835_mmal_remove(struct platform_device *pdev)
+static void bcm2835_mmal_remove(struct vchiq_device *device)
{
int camera;
struct vchiq_mmal_instance *instance = gdev[0]->instance;
@@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
vchiq_mmal_finalise(instance);
}
-static struct platform_driver bcm2835_camera_driver = {
+static struct vchiq_driver bcm2835_camera_driver = {
.probe = bcm2835_mmal_probe,
- .remove_new = bcm2835_mmal_remove,
+ .remove = bcm2835_mmal_remove,
.driver = {
.name = "bcm2835-camera",
},
};
-module_platform_driver(bcm2835_camera_driver)
+module_vchiq_driver(bcm2835_camera_driver)
MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
MODULE_AUTHOR("Vincent Sanders");
MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:bcm2835-camera");
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index e8d40f891449..79d4d0eeb5fb 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -67,7 +67,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
DEFINE_SPINLOCK(msg_queue_spinlock);
struct vchiq_state g_state;
-static struct platform_device *bcm2835_camera;
static struct platform_device *bcm2835_audio;
struct vchiq_drvdata {
@@ -134,6 +133,15 @@ struct vchiq_pagelist_info {
unsigned int scatterlist_mapped;
};
+/*
+ * The devices implemented in the VCHIQ firmware are not discoverable,
+ * so we need to maintain a list of them in order to register them with
+ * the interface.
+ */
+static const char *const vchiq_devices[] = {
+ "bcm2835-camera",
+};
+
static void __iomem *g_regs;
/* This value is the size of the L2 cache lines as understood by the
* VPU firmware, which determines the required alignment of the
@@ -1798,6 +1806,7 @@ static int vchiq_probe(struct platform_device *pdev)
struct device_node *fw_node;
const struct of_device_id *of_id;
struct vchiq_drvdata *drvdata;
+ unsigned int i;
int err;
of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
@@ -1840,9 +1849,15 @@ static int vchiq_probe(struct platform_device *pdev)
goto error_exit;
}
- bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera");
bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
+ for (i = 0; i < ARRAY_SIZE(vchiq_devices); i++) {
+ err = vchiq_device_register(&pdev->dev, vchiq_devices[i]);
+ if (err)
+ dev_err(&pdev->dev, "Failed to register %s vchiq device\n",
+ vchiq_devices[i]);
+ }
+
return 0;
failed_platform_init:
@@ -1854,7 +1869,7 @@ static int vchiq_probe(struct platform_device *pdev)
static void vchiq_remove(struct platform_device *pdev)
{
platform_device_unregister(bcm2835_audio);
- platform_device_unregister(bcm2835_camera);
+ bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
vchiq_debugfs_deinit();
vchiq_deregister_chrdev();
}
--
2.39.1
Quoting Umang Jain (2023-06-27 21:16:25)
> Register the vchiq_bus_type bus with the vchiq interface.
> The bcm2835-camera nad bcm2835_audio will be registered to this bus type
s/nad/and/
Is it possible to rename bcm2835_audio to bcm2835-audio for consistency?
Or is that baked into existing usage/abi already?
If it can be changed, I think it's probably something to do in an
independent patch at the end of the series anyway.
I suspect this patch could be merged with 1/5 but I think it's ok
separate too.
Reviewed-by: Kieran Bingham <[email protected]>
> going ahead.
>
> Signed-off-by: Umang Jain <[email protected]>
> ---
> .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index aa2313f3bcab..e8d40f891449 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -12,6 +12,7 @@
> #include <linux/cdev.h>
> #include <linux/fs.h>
> #include <linux/device.h>
> +#include <linux/device/bus.h>
> #include <linux/mm.h>
> #include <linux/highmem.h>
> #include <linux/pagemap.h>
> @@ -34,6 +35,7 @@
> #include "vchiq_ioctl.h"
> #include "vchiq_arm.h"
> #include "vchiq_debugfs.h"
> +#include "vchiq_device.h"
> #include "vchiq_connected.h"
> #include "vchiq_pagelist.h"
>
> @@ -1870,6 +1872,12 @@ static int __init vchiq_driver_init(void)
> {
> int ret;
>
> + ret = bus_register(&vchiq_bus_type);
> + if (ret) {
> + pr_err("Failed to register %s\n", vchiq_bus_type.name);
> + return ret;
> + }
> +
> ret = platform_driver_register(&vchiq_driver);
> if (ret)
> pr_err("Failed to register vchiq driver\n");
> @@ -1880,6 +1888,7 @@ module_init(vchiq_driver_init);
>
> static void __exit vchiq_driver_exit(void)
> {
> + bus_unregister(&vchiq_bus_type);
> platform_driver_unregister(&vchiq_driver);
> }
> module_exit(vchiq_driver_exit);
> --
> 2.39.1
>
Hi Kieran,
On 6/28/23 1:21 PM, Kieran Bingham wrote:
> Quoting Umang Jain (2023-06-27 21:16:25)
>> Register the vchiq_bus_type bus with the vchiq interface.
>> The bcm2835-camera nad bcm2835_audio will be registered to this bus type
> s/nad/and/
Oops, v9 probably?
>
> Is it possible to rename bcm2835_audio to bcm2835-audio for consistency?
> Or is that baked into existing usage/abi already?
well, there are more (bcm2835_hdmi, bcm2835_headphones) so, I don't
think I will address in this series.
>
> If it can be changed, I think it's probably something to do in an
> independent patch at the end of the series anyway.
>
> I suspect this patch could be merged with 1/5 but I think it's ok
> separate too.
>
>
> Reviewed-by: Kieran Bingham <[email protected]>
>
>> going ahead.
>>
>> Signed-off-by: Umang Jain <[email protected]>
>> ---
>> .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> index aa2313f3bcab..e8d40f891449 100644
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> @@ -12,6 +12,7 @@
>> #include <linux/cdev.h>
>> #include <linux/fs.h>
>> #include <linux/device.h>
>> +#include <linux/device/bus.h>
>> #include <linux/mm.h>
>> #include <linux/highmem.h>
>> #include <linux/pagemap.h>
>> @@ -34,6 +35,7 @@
>> #include "vchiq_ioctl.h"
>> #include "vchiq_arm.h"
>> #include "vchiq_debugfs.h"
>> +#include "vchiq_device.h"
>> #include "vchiq_connected.h"
>> #include "vchiq_pagelist.h"
>>
>> @@ -1870,6 +1872,12 @@ static int __init vchiq_driver_init(void)
>> {
>> int ret;
>>
>> + ret = bus_register(&vchiq_bus_type);
>> + if (ret) {
>> + pr_err("Failed to register %s\n", vchiq_bus_type.name);
>> + return ret;
>> + }
>> +
>> ret = platform_driver_register(&vchiq_driver);
>> if (ret)
>> pr_err("Failed to register vchiq driver\n");
>> @@ -1880,6 +1888,7 @@ module_init(vchiq_driver_init);
>>
>> static void __exit vchiq_driver_exit(void)
>> {
>> + bus_unregister(&vchiq_bus_type);
>> platform_driver_unregister(&vchiq_driver);
>> }
>> module_exit(vchiq_driver_exit);
>> --
>> 2.39.1
>>
Quoting Umang Jain (2023-06-27 21:16:26)
> Register the bcm2835-camera with the vchiq_bus_type instead of using
> platform driver/device.
>
> Also the VCHIQ firmware doesn't support device enumeration, hence
> one has to maintain a list of devices to be registered in the interface.
>
> Signed-off-by: Umang Jain <[email protected]>
> ---
> .../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
> .../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
> 2 files changed, 26 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> index 346d00df815a..f37b2a881d92 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> @@ -24,8 +24,9 @@
> #include <media/v4l2-event.h>
> #include <media/v4l2-common.h>
> #include <linux/delay.h>
> -#include <linux/platform_device.h>
>
> +#include "../interface/vchiq_arm/vchiq_arm.h"
> +#include "../interface/vchiq_arm/vchiq_device.h"
> #include "../vchiq-mmal/mmal-common.h"
> #include "../vchiq-mmal/mmal-encodings.h"
> #include "../vchiq-mmal/mmal-vchiq.h"
> @@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
> .fmt.pix.sizeimage = 1024 * 768,
> };
>
> -static int bcm2835_mmal_probe(struct platform_device *pdev)
> +static int bcm2835_mmal_probe(struct vchiq_device *device)
> {
> int ret;
> struct bcm2835_mmal_dev *dev;
> @@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> &camera_instance);
> ret = v4l2_device_register(NULL, &dev->v4l2_dev);
> if (ret) {
> - dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
> + dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
> __func__, ret);
> goto free_dev;
> }
> @@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> return ret;
> }
>
> -static void bcm2835_mmal_remove(struct platform_device *pdev)
> +static void bcm2835_mmal_remove(struct vchiq_device *device)
> {
> int camera;
> struct vchiq_mmal_instance *instance = gdev[0]->instance;
> @@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
> vchiq_mmal_finalise(instance);
> }
>
> -static struct platform_driver bcm2835_camera_driver = {
> +static struct vchiq_driver bcm2835_camera_driver = {
> .probe = bcm2835_mmal_probe,
> - .remove_new = bcm2835_mmal_remove,
> + .remove = bcm2835_mmal_remove,
> .driver = {
> .name = "bcm2835-camera",
> },
> };
>
> -module_platform_driver(bcm2835_camera_driver)
> +module_vchiq_driver(bcm2835_camera_driver)
>
> MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
> MODULE_AUTHOR("Vincent Sanders");
> MODULE_LICENSE("GPL");
> -MODULE_ALIAS("platform:bcm2835-camera");
This bit worries me. I think that's how module autoloading is handled.
Can you check into the details of MODULE_ALIAS and follow the rabbit
hole for a bit? It's a few years since I last went down there so I can't
remember the specifics right now.
Except for that, I think this looks good.
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index e8d40f891449..79d4d0eeb5fb 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -67,7 +67,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
> DEFINE_SPINLOCK(msg_queue_spinlock);
> struct vchiq_state g_state;
>
> -static struct platform_device *bcm2835_camera;
> static struct platform_device *bcm2835_audio;
>
> struct vchiq_drvdata {
> @@ -134,6 +133,15 @@ struct vchiq_pagelist_info {
> unsigned int scatterlist_mapped;
> };
>
> +/*
> + * The devices implemented in the VCHIQ firmware are not discoverable,
> + * so we need to maintain a list of them in order to register them with
> + * the interface.
> + */
> +static const char *const vchiq_devices[] = {
> + "bcm2835-camera",
> +};
> +
> static void __iomem *g_regs;
> /* This value is the size of the L2 cache lines as understood by the
> * VPU firmware, which determines the required alignment of the
> @@ -1798,6 +1806,7 @@ static int vchiq_probe(struct platform_device *pdev)
> struct device_node *fw_node;
> const struct of_device_id *of_id;
> struct vchiq_drvdata *drvdata;
> + unsigned int i;
> int err;
>
> of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
> @@ -1840,9 +1849,15 @@ static int vchiq_probe(struct platform_device *pdev)
> goto error_exit;
> }
>
> - bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera");
> bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
>
> + for (i = 0; i < ARRAY_SIZE(vchiq_devices); i++) {
> + err = vchiq_device_register(&pdev->dev, vchiq_devices[i]);
> + if (err)
> + dev_err(&pdev->dev, "Failed to register %s vchiq device\n",
> + vchiq_devices[i]);
> + }
> +
> return 0;
>
> failed_platform_init:
> @@ -1854,7 +1869,7 @@ static int vchiq_probe(struct platform_device *pdev)
> static void vchiq_remove(struct platform_device *pdev)
> {
> platform_device_unregister(bcm2835_audio);
> - platform_device_unregister(bcm2835_camera);
> + bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
> vchiq_debugfs_deinit();
> vchiq_deregister_chrdev();
> }
> --
> 2.39.1
>
Quoting Umang Jain (2023-06-27 21:16:27)
> Similar to how bcm2385-camera device is registered, register the
> bcm2835-audio with vchiq_bus_type as well.
bcm2835-audio here and in the dir name, but registered as
bcm2835_audio... Personally I prefer bcm2835-audio ... but this is
already discussed earlier in the series.
>
> Signed-off-by: Umang Jain <[email protected]>
> ---
> .../vc04_services/bcm2835-audio/bcm2835.c | 17 ++++++++---------
> .../interface/vchiq_arm/vchiq_arm.c | 6 +-----
> 2 files changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
> index 00bc898b0189..f81a9a4fbd5d 100644
> --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
> +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
> @@ -1,12 +1,12 @@
> // SPDX-License-Identifier: GPL-2.0
> /* Copyright 2011 Broadcom Corporation. All rights reserved. */
>
> -#include <linux/platform_device.h>
> -
> #include <linux/init.h>
> #include <linux/slab.h>
> #include <linux/module.h>
>
> +#include "../interface/vchiq_arm/vchiq_arm.h"
> +#include "../interface/vchiq_arm/vchiq_device.h"
> #include "bcm2835.h"
>
> static bool enable_hdmi;
> @@ -268,9 +268,9 @@ static int snd_add_child_devices(struct device *device, u32 numchans)
> return 0;
> }
>
> -static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
> +static int snd_bcm2835_alsa_probe(struct vchiq_device *device)
> {
> - struct device *dev = &pdev->dev;
> + struct device *dev = &device->dev;
> int err;
>
> if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
> @@ -292,20 +292,20 @@ static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
>
> #ifdef CONFIG_PM
>
> -static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
> +static int snd_bcm2835_alsa_suspend(struct vchiq_device *device,
> pm_message_t state)
> {
> return 0;
> }
>
> -static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
> +static int snd_bcm2835_alsa_resume(struct vchiq_device *device)
> {
> return 0;
> }
>
> #endif
>
> -static struct platform_driver bcm2835_alsa_driver = {
> +static struct vchiq_driver bcm2835_alsa_driver = {
> .probe = snd_bcm2835_alsa_probe,
> #ifdef CONFIG_PM
> .suspend = snd_bcm2835_alsa_suspend,
> @@ -315,9 +315,8 @@ static struct platform_driver bcm2835_alsa_driver = {
> .name = "bcm2835_audio",
> },
> };
> -module_platform_driver(bcm2835_alsa_driver);
> +module_vchiq_driver(bcm2835_alsa_driver);
>
> MODULE_AUTHOR("Dom Cobley");
> MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
> MODULE_LICENSE("GPL");
> -MODULE_ALIAS("platform:bcm2835_audio");
And same as with the bcm2385-camera ... I expect this might be required
in some form to support module autoloading?
But with that resolved:
Reviewed-by: Kieran Bingham <[email protected]>
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index 79d4d0eeb5fb..75da37fa6372 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -67,8 +67,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
> DEFINE_SPINLOCK(msg_queue_spinlock);
> struct vchiq_state g_state;
>
> -static struct platform_device *bcm2835_audio;
> -
> struct vchiq_drvdata {
> const unsigned int cache_line_size;
> struct rpi_firmware *fw;
> @@ -139,6 +137,7 @@ struct vchiq_pagelist_info {
> * the interface.
> */
> static const char *const vchiq_devices[] = {
> + "bcm2835_audio",
> "bcm2835-camera",
> };
>
> @@ -1849,8 +1848,6 @@ static int vchiq_probe(struct platform_device *pdev)
> goto error_exit;
> }
>
> - bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
> -
> for (i = 0; i < ARRAY_SIZE(vchiq_devices); i++) {
> err = vchiq_device_register(&pdev->dev, vchiq_devices[i]);
> if (err)
> @@ -1868,7 +1865,6 @@ static int vchiq_probe(struct platform_device *pdev)
>
> static void vchiq_remove(struct platform_device *pdev)
> {
> - platform_device_unregister(bcm2835_audio);
> bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
> vchiq_debugfs_deinit();
> vchiq_deregister_chrdev();
> --
> 2.39.1
>
Quoting Umang Jain (2023-06-27 21:16:28)
> vchiq_register_child() is used to registered child devices as platform
s/registered/register/
> devices. Now that the child devices are migrated to use the
> vchiq_bus_type instead, they will be registered to that. Hence, drop
> vchiq_register_child() as it is no more required.
>
Reviewed-by: Kieran Bingham <[email protected]>
> Signed-off-by: Umang Jain <[email protected]>
> ---
> .../interface/vchiq_arm/vchiq_arm.c | 22 -------------------
> 1 file changed, 22 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index 75da37fa6372..3c52b09c49ea 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -1778,28 +1778,6 @@ static const struct of_device_id vchiq_of_match[] = {
> };
> MODULE_DEVICE_TABLE(of, vchiq_of_match);
>
> -static struct platform_device *
> -vchiq_register_child(struct platform_device *pdev, const char *name)
> -{
> - struct platform_device_info pdevinfo;
> - struct platform_device *child;
> -
> - memset(&pdevinfo, 0, sizeof(pdevinfo));
> -
> - pdevinfo.parent = &pdev->dev;
> - pdevinfo.name = name;
> - pdevinfo.id = PLATFORM_DEVID_NONE;
> - pdevinfo.dma_mask = DMA_BIT_MASK(32);
> -
> - child = platform_device_register_full(&pdevinfo);
> - if (IS_ERR(child)) {
> - dev_warn(&pdev->dev, "%s not registered\n", name);
> - child = NULL;
> - }
> -
> - return child;
> -}
> -
> static int vchiq_probe(struct platform_device *pdev)
> {
> struct device_node *fw_node;
> --
> 2.39.1
>
Hi Kieran,
On 6/29/23 12:44 AM, Kieran Bingham wrote:
> Quoting Umang Jain (2023-06-27 21:16:26)
>> Register the bcm2835-camera with the vchiq_bus_type instead of using
>> platform driver/device.
>>
>> Also the VCHIQ firmware doesn't support device enumeration, hence
>> one has to maintain a list of devices to be registered in the interface.
>>
>> Signed-off-by: Umang Jain <[email protected]>
>> ---
>> .../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
>> .../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
>> 2 files changed, 26 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
>> index 346d00df815a..f37b2a881d92 100644
>> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
>> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
>> @@ -24,8 +24,9 @@
>> #include <media/v4l2-event.h>
>> #include <media/v4l2-common.h>
>> #include <linux/delay.h>
>> -#include <linux/platform_device.h>
>>
>> +#include "../interface/vchiq_arm/vchiq_arm.h"
>> +#include "../interface/vchiq_arm/vchiq_device.h"
>> #include "../vchiq-mmal/mmal-common.h"
>> #include "../vchiq-mmal/mmal-encodings.h"
>> #include "../vchiq-mmal/mmal-vchiq.h"
>> @@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
>> .fmt.pix.sizeimage = 1024 * 768,
>> };
>>
>> -static int bcm2835_mmal_probe(struct platform_device *pdev)
>> +static int bcm2835_mmal_probe(struct vchiq_device *device)
>> {
>> int ret;
>> struct bcm2835_mmal_dev *dev;
>> @@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
>> &camera_instance);
>> ret = v4l2_device_register(NULL, &dev->v4l2_dev);
>> if (ret) {
>> - dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
>> + dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
>> __func__, ret);
>> goto free_dev;
>> }
>> @@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
>> return ret;
>> }
>>
>> -static void bcm2835_mmal_remove(struct platform_device *pdev)
>> +static void bcm2835_mmal_remove(struct vchiq_device *device)
>> {
>> int camera;
>> struct vchiq_mmal_instance *instance = gdev[0]->instance;
>> @@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
>> vchiq_mmal_finalise(instance);
>> }
>>
>> -static struct platform_driver bcm2835_camera_driver = {
>> +static struct vchiq_driver bcm2835_camera_driver = {
>> .probe = bcm2835_mmal_probe,
>> - .remove_new = bcm2835_mmal_remove,
>> + .remove = bcm2835_mmal_remove,
>> .driver = {
>> .name = "bcm2835-camera",
>> },
>> };
>>
>> -module_platform_driver(bcm2835_camera_driver)
>> +module_vchiq_driver(bcm2835_camera_driver)
>>
>> MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
>> MODULE_AUTHOR("Vincent Sanders");
>> MODULE_LICENSE("GPL");
>> -MODULE_ALIAS("platform:bcm2835-camera");
> This bit worries me. I think that's how module autoloading is handled.
>
> Can you check into the details of MODULE_ALIAS and follow the rabbit
> hole for a bit? It's a few years since I last went down there so I can't
> remember the specifics right now.
vchiq_probe() will register both the bcm2385_audio and bcm2835-camera
hence, we don't need MODULE_ALIAS for those two.
So what I also tested is that, when bcm2835_vchiq loads, it will
auto-load both audio and camera with it (since these are child devices
of vchiq). I think that's the correct way.
>
> Except for that, I think this looks good.
>
>
>> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> index e8d40f891449..79d4d0eeb5fb 100644
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
>> @@ -67,7 +67,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
>> DEFINE_SPINLOCK(msg_queue_spinlock);
>> struct vchiq_state g_state;
>>
>> -static struct platform_device *bcm2835_camera;
>> static struct platform_device *bcm2835_audio;
>>
>> struct vchiq_drvdata {
>> @@ -134,6 +133,15 @@ struct vchiq_pagelist_info {
>> unsigned int scatterlist_mapped;
>> };
>>
>> +/*
>> + * The devices implemented in the VCHIQ firmware are not discoverable,
>> + * so we need to maintain a list of them in order to register them with
>> + * the interface.
>> + */
>> +static const char *const vchiq_devices[] = {
>> + "bcm2835-camera",
>> +};
>> +
>> static void __iomem *g_regs;
>> /* This value is the size of the L2 cache lines as understood by the
>> * VPU firmware, which determines the required alignment of the
>> @@ -1798,6 +1806,7 @@ static int vchiq_probe(struct platform_device *pdev)
>> struct device_node *fw_node;
>> const struct of_device_id *of_id;
>> struct vchiq_drvdata *drvdata;
>> + unsigned int i;
>> int err;
>>
>> of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
>> @@ -1840,9 +1849,15 @@ static int vchiq_probe(struct platform_device *pdev)
>> goto error_exit;
>> }
>>
>> - bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera");
>> bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
>>
>> + for (i = 0; i < ARRAY_SIZE(vchiq_devices); i++) {
>> + err = vchiq_device_register(&pdev->dev, vchiq_devices[i]);
>> + if (err)
>> + dev_err(&pdev->dev, "Failed to register %s vchiq device\n",
>> + vchiq_devices[i]);
>> + }
>> +
>> return 0;
>>
>> failed_platform_init:
>> @@ -1854,7 +1869,7 @@ static int vchiq_probe(struct platform_device *pdev)
>> static void vchiq_remove(struct platform_device *pdev)
>> {
>> platform_device_unregister(bcm2835_audio);
>> - platform_device_unregister(bcm2835_camera);
>> + bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
>> vchiq_debugfs_deinit();
>> vchiq_deregister_chrdev();
>> }
>> --
>> 2.39.1
>>
Quoting Umang Jain (2023-06-29 12:49:17)
> Hi Kieran,
>
> On 6/29/23 12:44 AM, Kieran Bingham wrote:
> > Quoting Umang Jain (2023-06-27 21:16:26)
> >> Register the bcm2835-camera with the vchiq_bus_type instead of using
> >> platform driver/device.
> >>
> >> Also the VCHIQ firmware doesn't support device enumeration, hence
> >> one has to maintain a list of devices to be registered in the interface.
> >>
> >> Signed-off-by: Umang Jain <[email protected]>
> >> ---
> >> .../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
> >> .../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
> >> 2 files changed, 26 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> >> index 346d00df815a..f37b2a881d92 100644
> >> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> >> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> >> @@ -24,8 +24,9 @@
> >> #include <media/v4l2-event.h>
> >> #include <media/v4l2-common.h>
> >> #include <linux/delay.h>
> >> -#include <linux/platform_device.h>
> >>
> >> +#include "../interface/vchiq_arm/vchiq_arm.h"
> >> +#include "../interface/vchiq_arm/vchiq_device.h"
> >> #include "../vchiq-mmal/mmal-common.h"
> >> #include "../vchiq-mmal/mmal-encodings.h"
> >> #include "../vchiq-mmal/mmal-vchiq.h"
> >> @@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
> >> .fmt.pix.sizeimage = 1024 * 768,
> >> };
> >>
> >> -static int bcm2835_mmal_probe(struct platform_device *pdev)
> >> +static int bcm2835_mmal_probe(struct vchiq_device *device)
> >> {
> >> int ret;
> >> struct bcm2835_mmal_dev *dev;
> >> @@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> >> &camera_instance);
> >> ret = v4l2_device_register(NULL, &dev->v4l2_dev);
> >> if (ret) {
> >> - dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
> >> + dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
> >> __func__, ret);
> >> goto free_dev;
> >> }
> >> @@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> >> return ret;
> >> }
> >>
> >> -static void bcm2835_mmal_remove(struct platform_device *pdev)
> >> +static void bcm2835_mmal_remove(struct vchiq_device *device)
> >> {
> >> int camera;
> >> struct vchiq_mmal_instance *instance = gdev[0]->instance;
> >> @@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
> >> vchiq_mmal_finalise(instance);
> >> }
> >>
> >> -static struct platform_driver bcm2835_camera_driver = {
> >> +static struct vchiq_driver bcm2835_camera_driver = {
> >> .probe = bcm2835_mmal_probe,
> >> - .remove_new = bcm2835_mmal_remove,
> >> + .remove = bcm2835_mmal_remove,
> >> .driver = {
> >> .name = "bcm2835-camera",
> >> },
> >> };
> >>
> >> -module_platform_driver(bcm2835_camera_driver)
> >> +module_vchiq_driver(bcm2835_camera_driver)
> >>
> >> MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
> >> MODULE_AUTHOR("Vincent Sanders");
> >> MODULE_LICENSE("GPL");
> >> -MODULE_ALIAS("platform:bcm2835-camera");
> > This bit worries me. I think that's how module autoloading is handled.
> >
> > Can you check into the details of MODULE_ALIAS and follow the rabbit
> > hole for a bit? It's a few years since I last went down there so I can't
> > remember the specifics right now.
>
> vchiq_probe() will register both the bcm2385_audio and bcm2835-camera
> hence, we don't need MODULE_ALIAS for those two.
It registers the devices, but I thought MODULE_ALIAS was how that gets
tied to which module to load (when drivers are built as modules).
> So what I also tested is that, when bcm2835_vchiq loads, it will
> auto-load both audio and camera with it (since these are child devices
> of vchiq). I think that's the correct way.
Could you test a build with the following (two) configurations please?
1)
CONFIG_BCM2835_VCHIQ=y
CONFIG_VIDEO_BCM2835=m
CONFIG_SND_BCM2835=m
2)
CONFIG_BCM2835_VCHIQ=m
CONFIG_VIDEO_BCM2835=m
CONFIG_SND_BCM2835=m
> >
> > Except for that, I think this looks good.
> >
> >
> >> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> >> index e8d40f891449..79d4d0eeb5fb 100644
> >> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> >> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> >> @@ -67,7 +67,6 @@ int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
> >> DEFINE_SPINLOCK(msg_queue_spinlock);
> >> struct vchiq_state g_state;
> >>
> >> -static struct platform_device *bcm2835_camera;
> >> static struct platform_device *bcm2835_audio;
> >>
> >> struct vchiq_drvdata {
> >> @@ -134,6 +133,15 @@ struct vchiq_pagelist_info {
> >> unsigned int scatterlist_mapped;
> >> };
> >>
> >> +/*
> >> + * The devices implemented in the VCHIQ firmware are not discoverable,
> >> + * so we need to maintain a list of them in order to register them with
> >> + * the interface.
> >> + */
> >> +static const char *const vchiq_devices[] = {
> >> + "bcm2835-camera",
> >> +};
> >> +
> >> static void __iomem *g_regs;
> >> /* This value is the size of the L2 cache lines as understood by the
> >> * VPU firmware, which determines the required alignment of the
> >> @@ -1798,6 +1806,7 @@ static int vchiq_probe(struct platform_device *pdev)
> >> struct device_node *fw_node;
> >> const struct of_device_id *of_id;
> >> struct vchiq_drvdata *drvdata;
> >> + unsigned int i;
> >> int err;
> >>
> >> of_id = of_match_node(vchiq_of_match, pdev->dev.of_node);
> >> @@ -1840,9 +1849,15 @@ static int vchiq_probe(struct platform_device *pdev)
> >> goto error_exit;
> >> }
> >>
> >> - bcm2835_camera = vchiq_register_child(pdev, "bcm2835-camera");
> >> bcm2835_audio = vchiq_register_child(pdev, "bcm2835_audio");
> >>
> >> + for (i = 0; i < ARRAY_SIZE(vchiq_devices); i++) {
> >> + err = vchiq_device_register(&pdev->dev, vchiq_devices[i]);
> >> + if (err)
> >> + dev_err(&pdev->dev, "Failed to register %s vchiq device\n",
> >> + vchiq_devices[i]);
> >> + }
> >> +
> >> return 0;
> >>
> >> failed_platform_init:
> >> @@ -1854,7 +1869,7 @@ static int vchiq_probe(struct platform_device *pdev)
> >> static void vchiq_remove(struct platform_device *pdev)
> >> {
> >> platform_device_unregister(bcm2835_audio);
> >> - platform_device_unregister(bcm2835_camera);
> >> + bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
> >> vchiq_debugfs_deinit();
> >> vchiq_deregister_chrdev();
> >> }
> >> --
> >> 2.39.1
> >>
>
On Tue, Jun 27, 2023 at 10:16:24PM +0200, Umang Jain wrote:
> The devices that the vchiq interface registers (bcm2835-audio,
> bcm2835-camera) are implemented and exposed by the VC04 firmware.
> The device tree describes the VC04 itself with the resources required
> to communicate with it through a mailbox interface. However, the
> vchiq interface registers these devices as platform devices. This
> also means the specific drivers for these devices are getting
> registered as platform drivers. This is not correct and a blatant
> abuse of platform device/driver.
>
> Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
> which will be used to migrate child devices that the vchiq interfaces
> creates/registers from the platform device/driver.
>
> Signed-off-by: Umang Jain <[email protected]>
> ---
> drivers/staging/vc04_services/Makefile | 1 +
> .../interface/vchiq_arm/vchiq_device.c | 78 +++++++++++++++++++
> .../interface/vchiq_arm/vchiq_device.h | 43 ++++++++++
> 3 files changed, 122 insertions(+)
> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>
> diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
> index 44794bdf6173..2d071e55e175 100644
> --- a/drivers/staging/vc04_services/Makefile
> +++ b/drivers/staging/vc04_services/Makefile
> @@ -5,6 +5,7 @@ vchiq-objs := \
> interface/vchiq_arm/vchiq_core.o \
> interface/vchiq_arm/vchiq_arm.o \
> interface/vchiq_arm/vchiq_debugfs.o \
> + interface/vchiq_arm/vchiq_device.o \
> interface/vchiq_arm/vchiq_connected.o \
>
> ifdef CONFIG_VCHIQ_CDEV
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> new file mode 100644
> index 000000000000..dff312e9735c
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -0,0 +1,78 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * vchiq_device.c - VCHIQ generic device and bus-type
> + *
> + * Copyright (c) 2023 Ideas On Board Oy
> + */
> +
> +#include <linux/device/bus.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +
> +#include "vchiq_device.h"
> +
> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv);
> +
> +struct bus_type vchiq_bus_type = {
> + .name = "vchiq-bus",
> + .match = vchiq_bus_type_match,
> +};
> +
> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
> +{
> + if (dev->bus == &vchiq_bus_type &&
> + strcmp(dev_name(dev), drv->name) == 0)
> + return 1;
> + return 0;
> +}
> +
> +static void vchiq_device_release(struct device *dev)
> +{
> + struct vchiq_device *device;
> +
> + device = container_of(dev, struct vchiq_device, dev);
> + kfree(device);
> +}
> +
> +int vchiq_device_register(struct device *parent, const char *name)
> +{
> + struct vchiq_device *device = NULL;
No need to set this to NULL.
> + int ret;
> +
> + device = kzalloc(sizeof(*device), GFP_KERNEL);
> + if (!device)
> + return -ENOMEM;
> +
> + device->dev.init_name = name;
> + device->dev.parent = parent;
> + device->dev.bus = &vchiq_bus_type;
> + device->dev.release = vchiq_device_release;
> +
> + ret = device_register(&device->dev);
> + if (ret) {
> + put_device(&device->dev);
> + return -EINVAL;
Why not return the error given to you?
> + }
> +
> + return 0;
You create a new device, shouldn't you return it? How is it going to be
looked up again?
> +}
> +
> +int vchiq_device_unregister(struct device *dev, void *data)
You should be passing in a sruct vchiq_device *device here, right?
And why the void pointer you do nothing with?
> +{
> + device_unregister(dev);
> + return 0;
> +}
No need to export this?
thanks,
greg k-h
On Tue, Jun 27, 2023 at 10:16:26PM +0200, Umang Jain wrote:
> Register the bcm2835-camera with the vchiq_bus_type instead of using
> platform driver/device.
>
> Also the VCHIQ firmware doesn't support device enumeration, hence
> one has to maintain a list of devices to be registered in the interface.
>
> Signed-off-by: Umang Jain <[email protected]>
> ---
> .../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
> .../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
> 2 files changed, 26 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> index 346d00df815a..f37b2a881d92 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> @@ -24,8 +24,9 @@
> #include <media/v4l2-event.h>
> #include <media/v4l2-common.h>
> #include <linux/delay.h>
> -#include <linux/platform_device.h>
>
> +#include "../interface/vchiq_arm/vchiq_arm.h"
> +#include "../interface/vchiq_arm/vchiq_device.h"
> #include "../vchiq-mmal/mmal-common.h"
> #include "../vchiq-mmal/mmal-encodings.h"
> #include "../vchiq-mmal/mmal-vchiq.h"
> @@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
> .fmt.pix.sizeimage = 1024 * 768,
> };
>
> -static int bcm2835_mmal_probe(struct platform_device *pdev)
> +static int bcm2835_mmal_probe(struct vchiq_device *device)
> {
> int ret;
> struct bcm2835_mmal_dev *dev;
> @@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> &camera_instance);
> ret = v4l2_device_register(NULL, &dev->v4l2_dev);
> if (ret) {
> - dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
> + dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
> __func__, ret);
> goto free_dev;
> }
> @@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> return ret;
> }
>
> -static void bcm2835_mmal_remove(struct platform_device *pdev)
> +static void bcm2835_mmal_remove(struct vchiq_device *device)
> {
> int camera;
> struct vchiq_mmal_instance *instance = gdev[0]->instance;
> @@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
> vchiq_mmal_finalise(instance);
> }
>
> -static struct platform_driver bcm2835_camera_driver = {
> +static struct vchiq_driver bcm2835_camera_driver = {
> .probe = bcm2835_mmal_probe,
> - .remove_new = bcm2835_mmal_remove,
> + .remove = bcm2835_mmal_remove,
No need to change this here, right? That's independant of this patch
series.
thanks,
greg k-h
Hi Greg,
On 7/3/23 3:29 PM, Greg KH wrote:
> On Tue, Jun 27, 2023 at 10:16:26PM +0200, Umang Jain wrote:
>> Register the bcm2835-camera with the vchiq_bus_type instead of using
>> platform driver/device.
>>
>> Also the VCHIQ firmware doesn't support device enumeration, hence
>> one has to maintain a list of devices to be registered in the interface.
>>
>> Signed-off-by: Umang Jain <[email protected]>
>> ---
>> .../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
>> .../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
>> 2 files changed, 26 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
>> index 346d00df815a..f37b2a881d92 100644
>> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
>> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
>> @@ -24,8 +24,9 @@
>> #include <media/v4l2-event.h>
>> #include <media/v4l2-common.h>
>> #include <linux/delay.h>
>> -#include <linux/platform_device.h>
>>
>> +#include "../interface/vchiq_arm/vchiq_arm.h"
>> +#include "../interface/vchiq_arm/vchiq_device.h"
>> #include "../vchiq-mmal/mmal-common.h"
>> #include "../vchiq-mmal/mmal-encodings.h"
>> #include "../vchiq-mmal/mmal-vchiq.h"
>> @@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
>> .fmt.pix.sizeimage = 1024 * 768,
>> };
>>
>> -static int bcm2835_mmal_probe(struct platform_device *pdev)
>> +static int bcm2835_mmal_probe(struct vchiq_device *device)
>> {
>> int ret;
>> struct bcm2835_mmal_dev *dev;
>> @@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
>> &camera_instance);
>> ret = v4l2_device_register(NULL, &dev->v4l2_dev);
>> if (ret) {
>> - dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
>> + dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
>> __func__, ret);
>> goto free_dev;
>> }
>> @@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
>> return ret;
>> }
>>
>> -static void bcm2835_mmal_remove(struct platform_device *pdev)
>> +static void bcm2835_mmal_remove(struct vchiq_device *device)
>> {
>> int camera;
>> struct vchiq_mmal_instance *instance = gdev[0]->instance;
>> @@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
>> vchiq_mmal_finalise(instance);
>> }
>>
>> -static struct platform_driver bcm2835_camera_driver = {
>> +static struct vchiq_driver bcm2835_camera_driver = {
>> .probe = bcm2835_mmal_probe,
>> - .remove_new = bcm2835_mmal_remove,
>> + .remove = bcm2835_mmal_remove,
> No need to change this here, right? That's independant of this patch
> series.
Why not ?
Should I have "remove_new()" in the struct vchiq_driver {..} [Patch
1/5] instead of "remove()" - match up with platform_driver virtual
interface ?
>
> thanks,
>
> greg k-h
On Mon, Jul 03, 2023 at 04:44:39PM +0200, Umang Jain wrote:
> Hi Greg,
>
> On 7/3/23 3:29 PM, Greg KH wrote:
> > On Tue, Jun 27, 2023 at 10:16:26PM +0200, Umang Jain wrote:
> > > Register the bcm2835-camera with the vchiq_bus_type instead of using
> > > platform driver/device.
> > >
> > > Also the VCHIQ firmware doesn't support device enumeration, hence
> > > one has to maintain a list of devices to be registered in the interface.
> > >
> > > Signed-off-by: Umang Jain <[email protected]>
> > > ---
> > > .../bcm2835-camera/bcm2835-camera.c | 16 +++++++-------
> > > .../interface/vchiq_arm/vchiq_arm.c | 21 ++++++++++++++++---
> > > 2 files changed, 26 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> > > index 346d00df815a..f37b2a881d92 100644
> > > --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> > > +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> > > @@ -24,8 +24,9 @@
> > > #include <media/v4l2-event.h>
> > > #include <media/v4l2-common.h>
> > > #include <linux/delay.h>
> > > -#include <linux/platform_device.h>
> > > +#include "../interface/vchiq_arm/vchiq_arm.h"
> > > +#include "../interface/vchiq_arm/vchiq_device.h"
> > > #include "../vchiq-mmal/mmal-common.h"
> > > #include "../vchiq-mmal/mmal-encodings.h"
> > > #include "../vchiq-mmal/mmal-vchiq.h"
> > > @@ -1841,7 +1842,7 @@ static struct v4l2_format default_v4l2_format = {
> > > .fmt.pix.sizeimage = 1024 * 768,
> > > };
> > > -static int bcm2835_mmal_probe(struct platform_device *pdev)
> > > +static int bcm2835_mmal_probe(struct vchiq_device *device)
> > > {
> > > int ret;
> > > struct bcm2835_mmal_dev *dev;
> > > @@ -1896,7 +1897,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> > > &camera_instance);
> > > ret = v4l2_device_register(NULL, &dev->v4l2_dev);
> > > if (ret) {
> > > - dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n",
> > > + dev_err(&device->dev, "%s: could not register V4L2 device: %d\n",
> > > __func__, ret);
> > > goto free_dev;
> > > }
> > > @@ -1976,7 +1977,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
> > > return ret;
> > > }
> > > -static void bcm2835_mmal_remove(struct platform_device *pdev)
> > > +static void bcm2835_mmal_remove(struct vchiq_device *device)
> > > {
> > > int camera;
> > > struct vchiq_mmal_instance *instance = gdev[0]->instance;
> > > @@ -1988,17 +1989,16 @@ static void bcm2835_mmal_remove(struct platform_device *pdev)
> > > vchiq_mmal_finalise(instance);
> > > }
> > > -static struct platform_driver bcm2835_camera_driver = {
> > > +static struct vchiq_driver bcm2835_camera_driver = {
> > > .probe = bcm2835_mmal_probe,
> > > - .remove_new = bcm2835_mmal_remove,
> > > + .remove = bcm2835_mmal_remove,
> > No need to change this here, right? That's independant of this patch
> > series.
>
> Why not ?
>
> Should I have "remove_new()"? in the struct vchiq_driver {..} [Patch 1/5]
> instead of "remove()"? -? match up with platform_driver virtual interface ?
Ah, sorry, my fault, I thought this was just a platform driver change.
This is fine.
greg k-h
Hi Greg,
(resending because it got bounced off a few lists due a line a copied
with HTML tag..)
On 7/3/23 3:28 PM, Greg KH wrote:
> On Tue, Jun 27, 2023 at 10:16:24PM +0200, Umang Jain wrote:
>> The devices that the vchiq interface registers (bcm2835-audio,
>> bcm2835-camera) are implemented and exposed by the VC04 firmware.
>> The device tree describes the VC04 itself with the resources required
>> to communicate with it through a mailbox interface. However, the
>> vchiq interface registers these devices as platform devices. This
>> also means the specific drivers for these devices are getting
>> registered as platform drivers. This is not correct and a blatant
>> abuse of platform device/driver.
>>
>> Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
>> which will be used to migrate child devices that the vchiq interfaces
>> creates/registers from the platform device/driver.
>>
>> Signed-off-by: Umang Jain <[email protected]>
>> ---
>> drivers/staging/vc04_services/Makefile | 1 +
>> .../interface/vchiq_arm/vchiq_device.c | 78 +++++++++++++++++++
>> .../interface/vchiq_arm/vchiq_device.h | 43 ++++++++++
>> 3 files changed, 122 insertions(+)
>> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
>>
>> diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
>> index 44794bdf6173..2d071e55e175 100644
>> --- a/drivers/staging/vc04_services/Makefile
>> +++ b/drivers/staging/vc04_services/Makefile
>> @@ -5,6 +5,7 @@ vchiq-objs := \
>> interface/vchiq_arm/vchiq_core.o \
>> interface/vchiq_arm/vchiq_arm.o \
>> interface/vchiq_arm/vchiq_debugfs.o \
>> + interface/vchiq_arm/vchiq_device.o \
>> interface/vchiq_arm/vchiq_connected.o \
>>
>> ifdef CONFIG_VCHIQ_CDEV
>> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> new file mode 100644
>> index 000000000000..dff312e9735c
>> --- /dev/null
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> @@ -0,0 +1,78 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * vchiq_device.c - VCHIQ generic device and bus-type
>> + *
>> + * Copyright (c) 2023 Ideas On Board Oy
>> + */
>> +
>> +#include <linux/device/bus.h>
>> +#include <linux/slab.h>
>> +#include <linux/string.h>
>> +
>> +#include "vchiq_device.h"
>> +
>> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv);
>> +
>> +struct bus_type vchiq_bus_type = {
>> + .name = "vchiq-bus",
>> + .match = vchiq_bus_type_match,
>> +};
>> +
>> +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
>> +{
>> + if (dev->bus == &vchiq_bus_type &&
>> + strcmp(dev_name(dev), drv->name) == 0)
>> + return 1;
>> + return 0;
>> +}
>> +
>> +static void vchiq_device_release(struct device *dev)
>> +{
>> + struct vchiq_device *device;
>> +
>> + device = container_of(dev, struct vchiq_device, dev);
>> + kfree(device);
>> +}
>> +
>> +int vchiq_device_register(struct device *parent, const char *name)
>> +{
>> + struct vchiq_device *device = NULL;
> No need to set this to NULL.
>
>> + int ret;
>> +
>> + device = kzalloc(sizeof(*device), GFP_KERNEL);
>> + if (!device)
>> + return -ENOMEM;
>> +
>> + device->dev.init_name = name;
>> + device->dev.parent = parent;
>> + device->dev.bus = &vchiq_bus_type;
>> + device->dev.release = vchiq_device_release;
>> +
>> + ret = device_register(&device->dev);
>> + if (ret) {
>> + put_device(&device->dev);
>> + return -EINVAL;
> Why not return the error given to you?
>
>> + }
>> +
>> + return 0;
> You create a new device, shouldn't you return it? How is it going to be
> looked up again?
So I haven't come across usage of the device other than unregistered
right now. If you look at the platform_device static instances of
bcm2835_camera, bcm2835-audio, they are also just used for unregistering
the devices only.
So for unregistering devices on vchiq_bus - I am using the
bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
in patch 3/5.
So basically I can return the instances right now, but there would be no
user of those instances.
>
>> +}
>> +
>> +int vchiq_device_unregister(struct device *dev, void *data)
> You should be passing in a sruct vchiq_device *device here, right?
>
> And why the void pointer you do nothing with?
ack
>
>
>> +{
>> + device_unregister(dev);
>> + return 0;
>> +}
> No need to export this?
In the previous reviews you mentioned not to export it. The
vchiq_bus_type is internal to the vchiq_driver to register it's child
devices. I don't think any other module will be using this bus directly?
Maybe I'm mistaken?
>
> thanks,
>
> greg k-h
On Mon, Jul 03, 2023 at 06:15:25PM +0200, Umang Jain wrote:
> Hi Greg,
>
> (resending because it got bounced off a few lists due a line a copied with
> HTML tag..)
>
> On 7/3/23 3:28 PM, Greg KH wrote:
> > On Tue, Jun 27, 2023 at 10:16:24PM +0200, Umang Jain wrote:
> > > The devices that the vchiq interface registers (bcm2835-audio,
> > > bcm2835-camera) are implemented and exposed by the VC04 firmware.
> > > The device tree describes the VC04 itself with the resources required
> > > to communicate with it through a mailbox interface. However, the
> > > vchiq interface registers these devices as platform devices. This
> > > also means the specific drivers for these devices are getting
> > > registered as platform drivers. This is not correct and a blatant
> > > abuse of platform device/driver.
> > >
> > > Add a new bus type, vchiq_bus_type and device type (struct vchiq_device)
> > > which will be used to migrate child devices that the vchiq interfaces
> > > creates/registers from the platform device/driver.
> > >
> > > Signed-off-by: Umang Jain <[email protected]>
> > > ---
> > > drivers/staging/vc04_services/Makefile | 1 +
> > > .../interface/vchiq_arm/vchiq_device.c | 78 +++++++++++++++++++
> > > .../interface/vchiq_arm/vchiq_device.h | 43 ++++++++++
> > > 3 files changed, 122 insertions(+)
> > > create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> > > create mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
> > >
> > > diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
> > > index 44794bdf6173..2d071e55e175 100644
> > > --- a/drivers/staging/vc04_services/Makefile
> > > +++ b/drivers/staging/vc04_services/Makefile
> > > @@ -5,6 +5,7 @@ vchiq-objs := \
> > > interface/vchiq_arm/vchiq_core.o \
> > > interface/vchiq_arm/vchiq_arm.o \
> > > interface/vchiq_arm/vchiq_debugfs.o \
> > > + interface/vchiq_arm/vchiq_device.o \
> > > interface/vchiq_arm/vchiq_connected.o \
> > > ifdef CONFIG_VCHIQ_CDEV
> > > diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> > > new file mode 100644
> > > index 000000000000..dff312e9735c
> > > --- /dev/null
> > > +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> > > @@ -0,0 +1,78 @@
> > > +// SPDX-License-Identifier: GPL-2.0
> > > +/*
> > > + * vchiq_device.c - VCHIQ generic device and bus-type
> > > + *
> > > + * Copyright (c) 2023 Ideas On Board Oy
> > > + */
> > > +
> > > +#include <linux/device/bus.h>
> > > +#include <linux/slab.h>
> > > +#include <linux/string.h>
> > > +
> > > +#include "vchiq_device.h"
> > > +
> > > +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv);
> > > +
> > > +struct bus_type vchiq_bus_type = {
> > > + .name = "vchiq-bus",
> > > + .match = vchiq_bus_type_match,
> > > +};
> > > +
> > > +static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv)
> > > +{
> > > + if (dev->bus == &vchiq_bus_type &&
> > > + strcmp(dev_name(dev), drv->name) == 0)
> > > + return 1;
> > > + return 0;
> > > +}
> > > +
> > > +static void vchiq_device_release(struct device *dev)
> > > +{
> > > + struct vchiq_device *device;
> > > +
> > > + device = container_of(dev, struct vchiq_device, dev);
> > > + kfree(device);
> > > +}
> > > +
> > > +int vchiq_device_register(struct device *parent, const char *name)
> > > +{
> > > + struct vchiq_device *device = NULL;
> > No need to set this to NULL.
> >
> > > + int ret;
> > > +
> > > + device = kzalloc(sizeof(*device), GFP_KERNEL);
> > > + if (!device)
> > > + return -ENOMEM;
> > > +
> > > + device->dev.init_name = name;
> > > + device->dev.parent = parent;
> > > + device->dev.bus = &vchiq_bus_type;
> > > + device->dev.release = vchiq_device_release;
> > > +
> > > + ret = device_register(&device->dev);
> > > + if (ret) {
> > > + put_device(&device->dev);
> > > + return -EINVAL;
> > Why not return the error given to you?
> >
> > > + }
> > > +
> > > + return 0;
> > You create a new device, shouldn't you return it? How is it going to be
> > looked up again?
>
> So I haven't come across usage of the device other than unregistered right
> now. If you look at the platform_device static instances of bcm2835_camera,
> bcm2835-audio, they are also just used for unregistering the devices only.
That feels odd, you need to register a device, use it, and then
unregister it when finished. Otherwise why have it?
> So for unregistering devices on vchiq_bus - I am using the
>
> ??? bus_for_each_dev(&vchiq_bus_type, NULL, NULL, vchiq_device_unregister);
Ick, no, that is horrid, unregister the device that was created, that's
how all other busses work.
> So basically I can return the instances right now, but there would be no
> user of those instances.
You should save it :)
> >
> > > +}
> > > +
> > > +int vchiq_device_unregister(struct device *dev, void *data)
> > You should be passing in a sruct vchiq_device *device here, right?
> >
> > And why the void pointer you do nothing with?
>
> ack
> >
> >
> > > +{
> > > + device_unregister(dev);
> > > + return 0;
> > > +}
> > No need to export this?
>
> In the previous reviews you mentioned not to export it. The vchiq_bus_type
> is internal to the vchiq_driver to register it's child devices. I don't
> think any other module will be using this bus directly? Maybe I'm mistaken?
Ok, just didn't match up with the register function export.
thanks,
greg k-h