linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
@ 2023-01-20 20:10 Umang Jain
  2023-01-20 20:10 ` [PATCH v6 1/6] staging: vc04_services: Drop __VCCOREVER__ remnants Umang Jain
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:10 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

This series just introduces five extra patches for dropping include
directives from Makefiles (suggested by Greg KH) and rebased.

The main patch (6/6) removes platform device/driver abuse and moves
things to standard device/driver model using a custom_bus. Specific
details are elaborated in the commit message.

The patch series is based on top of d514392f17fd (tag: next-20230120)
of linux-next.

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/20221222191500.515795-1-umang.jain@ideasonboard.com/

-v1:
https://lore.kernel.org/all/20221220084404.19280-1-umang.jain@ideasonboard.com/

Umang Jain (6):
  staging: vc04_services: Drop __VCCOREVER__ remnants
  staging: vc04_services: bcm2835-audio: Drop include Makefile directive
  staging: vc04_services: bcm2835-camera: Drop include Makefile
    directive
  staging: vc04_services: vchiq-mmal: Drop include Makefile directive
  staging: vc04_services: interface: Drop include Makefile directive
  staging: vc04_services: vchiq: Register devices with a custom bus_type

 drivers/staging/vc04_services/Makefile        |   3 +-
 .../vc04_services/bcm2835-audio/Makefile      |   2 -
 .../vc04_services/bcm2835-audio/bcm2835.c     |  27 +++--
 .../vc04_services/bcm2835-audio/bcm2835.h     |   3 +-
 .../vc04_services/bcm2835-camera/Makefile     |   5 -
 .../bcm2835-camera/bcm2835-camera.c           |  35 +++---
 .../vc04_services/bcm2835-camera/controls.c   |   6 +-
 .../interface/vchiq_arm/vchiq_arm.c           |  52 +++++----
 .../interface/vchiq_arm/vchiq_core.h          |   2 +-
 .../interface/vchiq_arm/vchiq_device.c        | 102 ++++++++++++++++++
 .../interface/vchiq_arm/vchiq_device.h        |  39 +++++++
 .../interface/vchiq_arm/vchiq_ioctl.h         |   3 +-
 .../staging/vc04_services/vchiq-mmal/Makefile |   5 -
 .../vc04_services/vchiq-mmal/mmal-vchiq.c     |   2 +-
 14 files changed, 206 insertions(+), 80 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.0


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v6 1/6] staging: vc04_services: Drop __VCCOREVER__ remnants
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
@ 2023-01-20 20:10 ` Umang Jain
  2023-01-20 20:11 ` [PATCH v6 2/6] staging: vc04_services: bcm2835-audio: Drop include Makefile directive Umang Jain
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:10 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

Commit 8ba5f91bab63 ("staging: vc04_services: remove __VCCOREVER__")
was meant to remove all of __VCCOREVER__ definitions but missed to
remove a few. Hence, drop them now.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/vc04_services/bcm2835-audio/Makefile  | 2 +-
 drivers/staging/vc04_services/bcm2835-camera/Makefile | 3 +--
 drivers/staging/vc04_services/vchiq-mmal/Makefile     | 3 +--
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-audio/Makefile b/drivers/staging/vc04_services/bcm2835-audio/Makefile
index d59fe4dde615..fc7ac6112a3e 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/Makefile
+++ b/drivers/staging/vc04_services/bcm2835-audio/Makefile
@@ -2,4 +2,4 @@
 obj-$(CONFIG_SND_BCM2835)	+= snd-bcm2835.o
 snd-bcm2835-objs		:= bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
 
-ccflags-y += -I $(srctree)/$(src)/../include -D__VCCOREVER__=0x04000000
+ccflags-y += -I $(srctree)/$(src)/../include
diff --git a/drivers/staging/vc04_services/bcm2835-camera/Makefile b/drivers/staging/vc04_services/bcm2835-camera/Makefile
index 3a76d6ade428..3494c82b271a 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/Makefile
+++ b/drivers/staging/vc04_services/bcm2835-camera/Makefile
@@ -7,5 +7,4 @@ obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-v4l2.o
 
 ccflags-y += \
 	-I $(srctree)/$(src)/.. \
-	-I $(srctree)/$(src)/../vchiq-mmal/ \
-	-D__VCCOREVER__=0x04000000
+	-I $(srctree)/$(src)/../vchiq-mmal/
diff --git a/drivers/staging/vc04_services/vchiq-mmal/Makefile b/drivers/staging/vc04_services/vchiq-mmal/Makefile
index b2a830f48acc..c7d3b06e17ce 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/Makefile
+++ b/drivers/staging/vc04_services/vchiq-mmal/Makefile
@@ -5,5 +5,4 @@ obj-$(CONFIG_BCM2835_VCHIQ_MMAL) += bcm2835-mmal-vchiq.o
 
 ccflags-y += \
 	-I$(srctree)/$(src)/.. \
-	-I$(srctree)/$(src)/../include \
-	-D__VCCOREVER__=0x04000000
+	-I$(srctree)/$(src)/../include
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v6 2/6] staging: vc04_services: bcm2835-audio: Drop include Makefile directive
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
  2023-01-20 20:10 ` [PATCH v6 1/6] staging: vc04_services: Drop __VCCOREVER__ remnants Umang Jain
@ 2023-01-20 20:11 ` Umang Jain
  2023-01-20 20:11 ` [PATCH v6 3/6] staging: vc04_services: bcm2835-camera: " Umang Jain
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:11 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

Drop the include directive. They can break the build, when one only
wants to build a subdirectory. Replace with "../" for the includes,
in the bcm2835.h instead.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/bcm2835-audio/Makefile  | 2 --
 drivers/staging/vc04_services/bcm2835-audio/bcm2835.h | 3 ++-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-audio/Makefile b/drivers/staging/vc04_services/bcm2835-audio/Makefile
index fc7ac6112a3e..01ceebdf88e7 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/Makefile
+++ b/drivers/staging/vc04_services/bcm2835-audio/Makefile
@@ -1,5 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_SND_BCM2835)	+= snd-bcm2835.o
 snd-bcm2835-objs		:= bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
-
-ccflags-y += -I $(srctree)/$(src)/../include
diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
index 38b7451d77b2..0a81383c475a 100644
--- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
+++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.h
@@ -6,11 +6,12 @@
 
 #include <linux/device.h>
 #include <linux/wait.h>
-#include <linux/raspberrypi/vchiq.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm-indirect.h>
 
+#include "../include/linux/raspberrypi/vchiq.h"
+
 #define MAX_SUBSTREAMS   (8)
 #define AVAIL_SUBSTREAMS_MASK  (0xff)
 
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v6 3/6] staging: vc04_services: bcm2835-camera: Drop include Makefile directive
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
  2023-01-20 20:10 ` [PATCH v6 1/6] staging: vc04_services: Drop __VCCOREVER__ remnants Umang Jain
  2023-01-20 20:11 ` [PATCH v6 2/6] staging: vc04_services: bcm2835-audio: Drop include Makefile directive Umang Jain
@ 2023-01-20 20:11 ` Umang Jain
  2023-01-20 20:11 ` [PATCH v6 4/6] staging: vc04_services: vchiq-mmal: " Umang Jain
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:11 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

Drop the include directive. They can break the build, when one only
wants to build a subdirectory. Replace with "../" for the includes,
in the bcm2835-camera files instead.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/staging/vc04_services/bcm2835-camera/Makefile  |  4 ----
 .../vc04_services/bcm2835-camera/bcm2835-camera.c      | 10 +++++-----
 .../staging/vc04_services/bcm2835-camera/controls.c    |  6 +++---
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/Makefile b/drivers/staging/vc04_services/bcm2835-camera/Makefile
index 3494c82b271a..203b93899b20 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/Makefile
+++ b/drivers/staging/vc04_services/bcm2835-camera/Makefile
@@ -4,7 +4,3 @@ bcm2835-v4l2-$(CONFIG_VIDEO_BCM2835) := \
 	controls.o
 
 obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-v4l2.o
-
-ccflags-y += \
-	-I $(srctree)/$(src)/.. \
-	-I $(srctree)/$(src)/../vchiq-mmal/
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 797ebe2a973a..4f81765912ea 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -26,11 +26,11 @@
 #include <linux/delay.h>
 #include <linux/platform_device.h>
 
-#include "mmal-common.h"
-#include "mmal-encodings.h"
-#include "mmal-vchiq.h"
-#include "mmal-msg.h"
-#include "mmal-parameters.h"
+#include "../vchiq-mmal/mmal-common.h"
+#include "../vchiq-mmal/mmal-encodings.h"
+#include "../vchiq-mmal/mmal-vchiq.h"
+#include "../vchiq-mmal/mmal-msg.h"
+#include "../vchiq-mmal/mmal-parameters.h"
 #include "bcm2835-camera.h"
 
 #define MIN_WIDTH 32
diff --git a/drivers/staging/vc04_services/bcm2835-camera/controls.c b/drivers/staging/vc04_services/bcm2835-camera/controls.c
index 5644d1d457b9..6bce45925bf1 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/controls.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/controls.c
@@ -23,9 +23,9 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-common.h>
 
-#include "mmal-common.h"
-#include "mmal-vchiq.h"
-#include "mmal-parameters.h"
+#include "../vchiq-mmal/mmal-common.h"
+#include "../vchiq-mmal/mmal-vchiq.h"
+#include "../vchiq-mmal/mmal-parameters.h"
 #include "bcm2835-camera.h"
 
 /* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v6 4/6] staging: vc04_services: vchiq-mmal: Drop include Makefile directive
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
                   ` (2 preceding siblings ...)
  2023-01-20 20:11 ` [PATCH v6 3/6] staging: vc04_services: bcm2835-camera: " Umang Jain
@ 2023-01-20 20:11 ` Umang Jain
  2023-01-20 20:11 ` [PATCH v6 5/6] staging: vc04_services: interface: " Umang Jain
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:11 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

Drop the include directive. They can break the build, when one only
wants to build a subdirectory. Replace with "../" for the includes,
in the mmal-vchiq.c instead.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/vchiq-mmal/Makefile     | 4 ----
 drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c | 2 +-
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/vc04_services/vchiq-mmal/Makefile b/drivers/staging/vc04_services/vchiq-mmal/Makefile
index c7d3b06e17ce..6937f6534c26 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/Makefile
+++ b/drivers/staging/vc04_services/vchiq-mmal/Makefile
@@ -2,7 +2,3 @@
 bcm2835-mmal-vchiq-objs := mmal-vchiq.o
 
 obj-$(CONFIG_BCM2835_VCHIQ_MMAL) += bcm2835-mmal-vchiq.o
-
-ccflags-y += \
-	-I$(srctree)/$(src)/.. \
-	-I$(srctree)/$(src)/../include
diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
index 6b5879a33780..234e3764db64 100644
--- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
@@ -23,9 +23,9 @@
 #include <linux/slab.h>
 #include <linux/completion.h>
 #include <linux/vmalloc.h>
-#include <linux/raspberrypi/vchiq.h>
 #include <media/videobuf2-vmalloc.h>
 
+#include "../include/linux/raspberrypi/vchiq.h"
 #include "mmal-common.h"
 #include "mmal-vchiq.h"
 #include "mmal-msg.h"
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v6 5/6] staging: vc04_services: interface: Drop include Makefile directive
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
                   ` (3 preceding siblings ...)
  2023-01-20 20:11 ` [PATCH v6 4/6] staging: vc04_services: vchiq-mmal: " Umang Jain
@ 2023-01-20 20:11 ` Umang Jain
  2023-01-20 20:11 ` [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
  2023-01-22 23:34 ` [PATCH v6 0/6] " Stefan Wahren
  6 siblings, 0 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:11 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

Drop the include directive. They can break the build, when one only
wants to build a subdirectory. Replace with "../" for the includes,
in the interface/ files instead.

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/Makefile                         | 2 --
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h | 2 +-
 .../staging/vc04_services/interface/vchiq_arm/vchiq_ioctl.h    | 3 ++-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
index 1fd191e2e2a5..44794bdf6173 100644
--- a/drivers/staging/vc04_services/Makefile
+++ b/drivers/staging/vc04_services/Makefile
@@ -15,5 +15,3 @@ obj-$(CONFIG_SND_BCM2835)		+= bcm2835-audio/
 obj-$(CONFIG_VIDEO_BCM2835)		+= bcm2835-camera/
 obj-$(CONFIG_BCM2835_VCHIQ_MMAL)	+= vchiq-mmal/
 
-ccflags-y += -I $(srctree)/$(src)/include
-
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
index 3c198eb1c77a..ec1a3caefaea 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
@@ -10,8 +10,8 @@
 #include <linux/kref.h>
 #include <linux/rcupdate.h>
 #include <linux/wait.h>
-#include <linux/raspberrypi/vchiq.h>
 
+#include "../../include/linux/raspberrypi/vchiq.h"
 #include "vchiq_cfg.h"
 
 /* Do this so that we can test-build the code on non-rpi systems */
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_ioctl.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
index 96f50beace44..17550831f86c 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
@@ -5,7 +5,8 @@
 #define VCHIQ_IOCTLS_H
 
 #include <linux/ioctl.h>
-#include <linux/raspberrypi/vchiq.h>
+
+#include "../../include/linux/raspberrypi/vchiq.h"
 
 #define VCHIQ_IOC_MAGIC 0xc4
 #define VCHIQ_INVALID_HANDLE (~0)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
                   ` (4 preceding siblings ...)
  2023-01-20 20:11 ` [PATCH v6 5/6] staging: vc04_services: interface: " Umang Jain
@ 2023-01-20 20:11 ` Umang Jain
  2023-01-22 23:50   ` Stefan Wahren
  2023-01-23 18:11   ` Greg Kroah-Hartman
  2023-01-22 23:34 ` [PATCH v6 0/6] " Stefan Wahren
  6 siblings, 2 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-20 20:11 UTC (permalink / raw)
  To: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel
  Cc: Stefan Wahren, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Laurent Pinchart, Paul Elder, Umang Jain

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.

Replace the platform device/driver model with a standard device driver
model. A custom bus_type, vchiq_bus_type, is created in the vchiq
interface which matches the devices to their specific device drivers
thereby, establishing driver binding. A struct vchiq_device wraps the
struct device for each device being registered on the bus by the vchiq
interface. On the other hand, struct vchiq_driver wraps the struct
device_driver and the module_vchiq_driver() macro is provided for the
driver registration.

Each device registered will expose a 'name' read-only device attribute
in sysfs (/sys/bus/vchiq-bus/devices). New devices and drivers can be
added by registering on vchiq_bus_type and adding a corresponding
device name entry in the static list of devices, vchiq_devices. There
is currently no way to enumerate the VCHIQ devices that are available
from the firmware.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 drivers/staging/vc04_services/Makefile        |   1 +
 .../vc04_services/bcm2835-audio/bcm2835.c     |  27 +++--
 .../bcm2835-camera/bcm2835-camera.c           |  25 ++---
 .../interface/vchiq_arm/vchiq_arm.c           |  52 +++++----
 .../interface/vchiq_arm/vchiq_device.c        | 102 ++++++++++++++++++
 .../interface/vchiq_arm/vchiq_device.h        |  39 +++++++
 6 files changed, 192 insertions(+), 54 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

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/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
index 00bc898b0189..05118dafe62d 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,8 @@ 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 device *dev)
 {
-	struct device *dev = &pdev->dev;
 	int err;
 
 	if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
@@ -292,32 +291,32 @@ 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 device *pdev,
 				    pm_message_t state)
 {
 	return 0;
 }
 
-static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
+static int snd_bcm2835_alsa_resume(struct device *pdev)
 {
 	return 0;
 }
 
 #endif
 
-static struct platform_driver bcm2835_alsa_driver = {
-	.probe = snd_bcm2835_alsa_probe,
+static struct vchiq_driver bcm2835_alsa_driver = {
+	.driver	= {
+		.probe = snd_bcm2835_alsa_probe,
 #ifdef CONFIG_PM
-	.suspend = snd_bcm2835_alsa_suspend,
-	.resume = snd_bcm2835_alsa_resume,
+		.suspend = snd_bcm2835_alsa_suspend,
+		.resume = snd_bcm2835_alsa_resume,
 #endif
-	.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");
+MODULE_ALIAS("bcm2835_audio");
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index 4f81765912ea..57f053de53b9 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 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, "%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 int bcm2835_mmal_remove(struct platform_device *pdev)
+static int bcm2835_mmal_remove(struct device *device)
 {
 	int camera;
 	struct vchiq_mmal_instance *instance = gdev[0]->instance;
@@ -1990,17 +1991,17 @@ static int bcm2835_mmal_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static struct platform_driver bcm2835_camera_driver = {
-	.probe		= bcm2835_mmal_probe,
-	.remove		= bcm2835_mmal_remove,
-	.driver		= {
-		.name	= "bcm2835-camera",
-	},
+static struct vchiq_driver bcm2835_camera_driver = {
+	.driver = {
+		.name		= "bcm2835-camera",
+		.probe          = bcm2835_mmal_probe,
+		.remove         = bcm2835_mmal_remove,
+	}
 };
 
-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");
+MODULE_ALIAS("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 22de23f3af02..4a57ff760106 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,8 @@
 #include <linux/cdev.h>
 #include <linux/fs.h>
 #include <linux/device.h>
+#include <linux/device/bus.h>
+#include <linux/string.h>
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/pagemap.h>
@@ -34,6 +36,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"
 
@@ -65,9 +68,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 {
 	const unsigned int cache_line_size;
 	struct rpi_firmware *fw;
@@ -132,6 +132,11 @@ struct vchiq_pagelist_info {
 	unsigned int scatterlist_mapped;
 };
 
+static const char *const vchiq_devices[] = {
+	"bcm2835_audio",
+	"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
@@ -1763,33 +1768,13 @@ 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;
 	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);
@@ -1832,8 +1817,12 @@ 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;
 
@@ -1845,8 +1834,8 @@ static int vchiq_probe(struct platform_device *pdev)
 
 static int 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();
 
@@ -1866,6 +1855,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");
@@ -1876,6 +1871,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);
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..ec542d6bc68a
--- /dev/null
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * 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);
+
+static ssize_t vchiq_dev_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct vchiq_device *device = container_of(dev, struct vchiq_device, dev);
+
+	return sprintf(buf, "%s", device->name);
+}
+
+static DEVICE_ATTR_RO(vchiq_dev);
+
+static struct attribute *vchiq_dev_attrs[] = {
+	&dev_attr_vchiq_dev.attr,
+	NULL
+};
+
+ATTRIBUTE_GROUPS(vchiq_dev);
+
+static const struct device_type vchiq_device_type = {
+	.groups         = vchiq_dev_groups
+};
+
+struct bus_type vchiq_bus_type = {
+	.name   = "vchiq-bus",
+	.match  = vchiq_bus_type_match,
+};
+EXPORT_SYMBOL_GPL(vchiq_bus_type);
+
+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->name = name;
+	device->dev.init_name = name;
+	device->dev.parent = parent;
+	device->dev.bus = &vchiq_bus_type;
+	device->dev.type = &vchiq_device_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..0848c1b353f8
--- /dev/null
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+/*
+ * 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;
+	const char *name;
+};
+
+struct vchiq_driver {
+	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.0


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
                   ` (5 preceding siblings ...)
  2023-01-20 20:11 ` [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
@ 2023-01-22 23:34 ` Stefan Wahren
  2023-01-23  7:48   ` Umang Jain
  6 siblings, 1 reply; 23+ messages in thread
From: Stefan Wahren @ 2023-01-22 23:34 UTC (permalink / raw)
  To: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Umang,

Am 20.01.23 um 21:10 schrieb Umang Jain:
> This series just introduces five extra patches for dropping include
> directives from Makefiles (suggested by Greg KH) and rebased.
>
> The main patch (6/6) removes platform device/driver abuse and moves
> things to standard device/driver model using a custom_bus. Specific
> details are elaborated in the commit message.
>
> The patch series is based on top of d514392f17fd (tag: next-20230120)
> of linux-next.

applied this series on top of linux-next and build it with 
arm/multi_v7_defconfig plus the following:

CONFIG_BCM_VIDEOCORE=y
CONFIG_BCM2835_VCHIQ=m
CONFIG_VCHIQ_CDEV=y
CONFIG_SND_BCM2835=m
CONFIG_VIDEO_BCM2835=m
CONFIG_BCM2835_VCHIQ_MMAL=m

and the devices doesn't register on Raspberry Pi 3 B Plus:

[   25.523337] vchiq: module is from the staging directory, the quality 
is unknown, you have been warned.
[   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
bcm2835_audio vchiq device
[   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
bcm2835-camera vchiq device


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-20 20:11 ` [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
@ 2023-01-22 23:50   ` Stefan Wahren
  2023-01-23 18:11   ` Greg Kroah-Hartman
  1 sibling, 0 replies; 23+ messages in thread
From: Stefan Wahren @ 2023-01-22 23:50 UTC (permalink / raw)
  To: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Umang,

Am 20.01.23 um 21:11 schrieb Umang Jain:
> 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.
>
> Replace the platform device/driver model with a standard device driver
> model. A custom bus_type, vchiq_bus_type, is created in the vchiq
> interface which matches the devices to their specific device drivers
> thereby, establishing driver binding. A struct vchiq_device wraps the
> struct device for each device being registered on the bus by the vchiq
> interface. On the other hand, struct vchiq_driver wraps the struct
> device_driver and the module_vchiq_driver() macro is provided for the
> driver registration.
>
> Each device registered will expose a 'name' read-only device attribute
> in sysfs (/sys/bus/vchiq-bus/devices). New devices and drivers can be
> added by registering on vchiq_bus_type and adding a corresponding
> device name entry in the static list of devices, vchiq_devices. There
> is currently no way to enumerate the VCHIQ devices that are available
> from the firmware.
>
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   drivers/staging/vc04_services/Makefile        |   1 +
>   .../vc04_services/bcm2835-audio/bcm2835.c     |  27 +++--
>   .../bcm2835-camera/bcm2835-camera.c           |  25 ++---
>   .../interface/vchiq_arm/vchiq_arm.c           |  52 +++++----
>   .../interface/vchiq_arm/vchiq_device.c        | 102 ++++++++++++++++++
>   .../interface/vchiq_arm/vchiq_device.h        |  39 +++++++
>   6 files changed, 192 insertions(+), 54 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
>
> 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/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
> index 00bc898b0189..05118dafe62d 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,8 @@ 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 device *dev)
>   {
> -	struct device *dev = &pdev->dev;
>   	int err;
>   
>   	if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
> @@ -292,32 +291,32 @@ 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 device *pdev,
>   				    pm_message_t state)
>   {
>   	return 0;
>   }
>   
> -static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
> +static int snd_bcm2835_alsa_resume(struct device *pdev)
>   {
>   	return 0;
>   }
>   
>   #endif
>   
> -static struct platform_driver bcm2835_alsa_driver = {
> -	.probe = snd_bcm2835_alsa_probe,
> +static struct vchiq_driver bcm2835_alsa_driver = {
> +	.driver	= {
> +		.probe = snd_bcm2835_alsa_probe,
>   #ifdef CONFIG_PM
> -	.suspend = snd_bcm2835_alsa_suspend,
> -	.resume = snd_bcm2835_alsa_resume,
> +		.suspend = snd_bcm2835_alsa_suspend,
> +		.resume = snd_bcm2835_alsa_resume,
>   #endif
> -	.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");
> +MODULE_ALIAS("bcm2835_audio");
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> index 4f81765912ea..57f053de53b9 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 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, "%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 int bcm2835_mmal_remove(struct platform_device *pdev)
> +static int bcm2835_mmal_remove(struct device *device)
>   {
>   	int camera;
>   	struct vchiq_mmal_instance *instance = gdev[0]->instance;
> @@ -1990,17 +1991,17 @@ static int bcm2835_mmal_remove(struct platform_device *pdev)
>   	return 0;
>   }
>   
> -static struct platform_driver bcm2835_camera_driver = {
> -	.probe		= bcm2835_mmal_probe,
> -	.remove		= bcm2835_mmal_remove,
> -	.driver		= {
> -		.name	= "bcm2835-camera",
> -	},
> +static struct vchiq_driver bcm2835_camera_driver = {
> +	.driver = {
> +		.name		= "bcm2835-camera",
> +		.probe          = bcm2835_mmal_probe,
> +		.remove         = bcm2835_mmal_remove,
> +	}
>   };
>   
> -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");
> +MODULE_ALIAS("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 22de23f3af02..4a57ff760106 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,8 @@
>   #include <linux/cdev.h>
>   #include <linux/fs.h>
>   #include <linux/device.h>
> +#include <linux/device/bus.h>
> +#include <linux/string.h>
>   #include <linux/mm.h>
>   #include <linux/highmem.h>
>   #include <linux/pagemap.h>
> @@ -34,6 +36,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"
>   
> @@ -65,9 +68,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 {
>   	const unsigned int cache_line_size;
>   	struct rpi_firmware *fw;
> @@ -132,6 +132,11 @@ struct vchiq_pagelist_info {
>   	unsigned int scatterlist_mapped;
>   };
>   
> +static const char *const vchiq_devices[] = {
> +	"bcm2835_audio",
> +	"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
> @@ -1763,33 +1768,13 @@ 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;
>   	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);
> @@ -1832,8 +1817,12 @@ 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]);
I think it's helpful to log "err" here.
> +	}
>   
>   	return 0;
>   
> @@ -1845,8 +1834,8 @@ static int vchiq_probe(struct platform_device *pdev)
>   
>   static int 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();
>   
> @@ -1866,6 +1855,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");
Shouldn't we unregister the bus in this error case?
> @@ -1876,6 +1871,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);
> 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..ec542d6bc68a
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
> +/*
> + * 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);
> +
> +static ssize_t vchiq_dev_show(struct device *dev,
> +			      struct device_attribute *attr, char *buf)
> +{
> +	struct vchiq_device *device = container_of(dev, struct vchiq_device, dev);
> +
> +	return sprintf(buf, "%s", device->name);
> +}
> +
> +static DEVICE_ATTR_RO(vchiq_dev);
> +
> +static struct attribute *vchiq_dev_attrs[] = {
> +	&dev_attr_vchiq_dev.attr,
> +	NULL
> +};
> +
> +ATTRIBUTE_GROUPS(vchiq_dev);
> +
> +static const struct device_type vchiq_device_type = {
> +	.groups         = vchiq_dev_groups
> +};
> +
> +struct bus_type vchiq_bus_type = {
> +	.name   = "vchiq-bus",
> +	.match  = vchiq_bus_type_match,
> +};
> +EXPORT_SYMBOL_GPL(vchiq_bus_type);
> +
> +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;
Please add a empty line here.
> +	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->name = name;
> +	device->dev.init_name = name;
> +	device->dev.parent = parent;
> +	device->dev.bus = &vchiq_bus_type;
> +	device->dev.type = &vchiq_device_type;
> +	device->dev.release = vchiq_device_release;
> +
> +	ret = device_register(&device->dev);
> +	if (ret) {
> +		put_device(&device->dev);
> +		return -EINVAL;
Why not returning "ret" here?
> +	}
> +
> +	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..0848c1b353f8
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
> +/*
> + * 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;
> +	const char *name;
> +};
> +
> +struct vchiq_driver {
> +	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 */

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-22 23:34 ` [PATCH v6 0/6] " Stefan Wahren
@ 2023-01-23  7:48   ` Umang Jain
  2023-01-23  8:58     ` Laurent Pinchart
                       ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-23  7:48 UTC (permalink / raw)
  To: Stefan Wahren, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Stefan,

Thank for the testing.

On 1/23/23 5:04 AM, Stefan Wahren wrote:
> Hi Umang,
>
> Am 20.01.23 um 21:10 schrieb Umang Jain:
>> This series just introduces five extra patches for dropping include
>> directives from Makefiles (suggested by Greg KH) and rebased.
>>
>> The main patch (6/6) removes platform device/driver abuse and moves
>> things to standard device/driver model using a custom_bus. Specific
>> details are elaborated in the commit message.
>>
>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>> of linux-next.
>
> applied this series on top of linux-next and build it with 
> arm/multi_v7_defconfig plus the following:
>
> CONFIG_BCM_VIDEOCORE=y
> CONFIG_BCM2835_VCHIQ=m
> CONFIG_VCHIQ_CDEV=y
> CONFIG_SND_BCM2835=m
> CONFIG_VIDEO_BCM2835=m
> CONFIG_BCM2835_VCHIQ_MMAL=m
>
> and the devices doesn't register on Raspberry Pi 3 B Plus:
>
> [   25.523337] vchiq: module is from the staging directory, the 
> quality is unknown, you have been warned.
> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
> bcm2835_audio vchiq device
> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
> bcm2835-camera vchiq device

I was able to reproduce and it seems the issue here is the change 
mentioned in the cover

- drop dma_set_mask_and_coherent

in V6.

(I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp applied 
so my branch has the DMA hunk included while I was testing V6)

Below is the hunk which should resolve the issue.

--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
@@ -6,6 +6,7 @@
   */

  #include <linux/device/bus.h>
+#include <linux/dma-mapping.h>
  #include <linux/slab.h>
  #include <linux/string.h>

@@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
const char *name)
         device->dev.type = &vchiq_device_type;
         device->dev.release = vchiq_device_release;

+       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
+       if (ret < 0) {
+               vchiq_device_release(&device->dev);
+               return ret;
+       }
+
         ret = device_register(&device->dev);
         if (ret) {
                 put_device(&device->dev);

It seems we need to include the dma_set_mask_and_coherent() even if 
bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look into 
why is that/

  Laurent, any thoughts on this please?

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23  7:48   ` Umang Jain
@ 2023-01-23  8:58     ` Laurent Pinchart
  2023-01-24  8:41       ` Stefan Wahren
  2023-01-23 11:46     ` Stefan Wahren
  2023-01-23 17:28     ` Stefan Wahren
  2 siblings, 1 reply; 23+ messages in thread
From: Laurent Pinchart @ 2023-01-23  8:58 UTC (permalink / raw)
  To: Umang Jain
  Cc: Stefan Wahren, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Paul Elder

On Mon, Jan 23, 2023 at 01:18:30PM +0530, Umang Jain wrote:
> Hi Stefan,
> 
> Thank for the testing.
> 
> On 1/23/23 5:04 AM, Stefan Wahren wrote:
> > Hi Umang,
> >
> > Am 20.01.23 um 21:10 schrieb Umang Jain:
> >> This series just introduces five extra patches for dropping include
> >> directives from Makefiles (suggested by Greg KH) and rebased.
> >>
> >> The main patch (6/6) removes platform device/driver abuse and moves
> >> things to standard device/driver model using a custom_bus. Specific
> >> details are elaborated in the commit message.
> >>
> >> The patch series is based on top of d514392f17fd (tag: next-20230120)
> >> of linux-next.
> >
> > applied this series on top of linux-next and build it with 
> > arm/multi_v7_defconfig plus the following:
> >
> > CONFIG_BCM_VIDEOCORE=y
> > CONFIG_BCM2835_VCHIQ=m
> > CONFIG_VCHIQ_CDEV=y
> > CONFIG_SND_BCM2835=m
> > CONFIG_VIDEO_BCM2835=m
> > CONFIG_BCM2835_VCHIQ_MMAL=m
> >
> > and the devices doesn't register on Raspberry Pi 3 B Plus:
> >
> > [   25.523337] vchiq: module is from the staging directory, the quality is unknown, you have been warned.
> > [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register bcm2835_audio vchiq device
> > [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register bcm2835-camera vchiq device
> 
> I was able to reproduce and it seems the issue here is the change 
> mentioned in the cover
> 
> - drop dma_set_mask_and_coherent
> 
> in V6.
> 
> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp applied 
> so my branch has the DMA hunk included while I was testing V6)
> 
> Below is the hunk which should resolve the issue.
> 
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -6,6 +6,7 @@
>    */
> 
>   #include <linux/device/bus.h>
> +#include <linux/dma-mapping.h>
>   #include <linux/slab.h>
>   #include <linux/string.h>
> 
> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
> const char *name)
>          device->dev.type = &vchiq_device_type;
>          device->dev.release = vchiq_device_release;
> 
> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
> +       if (ret < 0) {
> +               vchiq_device_release(&device->dev);
> +               return ret;
> +       }
> +
>          ret = device_register(&device->dev);
>          if (ret) {
>                  put_device(&device->dev);
> 
> It seems we need to include the dma_set_mask_and_coherent() even if 
> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look into 
> why is that/
> 
>   Laurent, any thoughts on this please?

Nothing that immediately springs to my mind. Can you investigate ?

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23  7:48   ` Umang Jain
  2023-01-23  8:58     ` Laurent Pinchart
@ 2023-01-23 11:46     ` Stefan Wahren
  2023-01-23 14:12       ` Umang Jain
  2023-01-23 17:28     ` Stefan Wahren
  2 siblings, 1 reply; 23+ messages in thread
From: Stefan Wahren @ 2023-01-23 11:46 UTC (permalink / raw)
  To: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Umang,

Am 23.01.23 um 08:48 schrieb Umang Jain:
> Hi Stefan,
>
> Thank for the testing.
>
> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>> Hi Umang,
>>
>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>> This series just introduces five extra patches for dropping include
>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>
>>> The main patch (6/6) removes platform device/driver abuse and moves
>>> things to standard device/driver model using a custom_bus. Specific
>>> details are elaborated in the commit message.
>>>
>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>> of linux-next.
>>
>> applied this series on top of linux-next and build it with 
>> arm/multi_v7_defconfig plus the following:
>>
>> CONFIG_BCM_VIDEOCORE=y
>> CONFIG_BCM2835_VCHIQ=m
>> CONFIG_VCHIQ_CDEV=y
>> CONFIG_SND_BCM2835=m
>> CONFIG_VIDEO_BCM2835=m
>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>
>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>
>> [   25.523337] vchiq: module is from the staging directory, the 
>> quality is unknown, you have been warned.
>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>> bcm2835_audio vchiq device
>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>> bcm2835-camera vchiq device
>
> I was able to reproduce and it seems the issue here is the change 
> mentioned in the cover
>
> - drop dma_set_mask_and_coherent
>
> in V6.
>
> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
> applied so my branch has the DMA hunk included while I was testing V6)

just to avoid misunderstandings, did you read 
drivers/staging/vc04_services/interface/TESTING ?

The Raspberry Pi 4 is currently not fully supported for VCHIQ in 
mainline. From my limited understanding the DMA controller driver needs 
40 bit support, so VCHIQ on BCM2711 can use it. This part is currently 
only available in the vendor tree. The reason why the driver is 
unexpectedly probing is a historical issue in the devicetree :-(

Raspberry Pi 4 support is not considered as necessary for moving out of 
staging.

>
> Below is the hunk which should resolve the issue.
>
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -6,6 +6,7 @@
>   */
>
>  #include <linux/device/bus.h>
> +#include <linux/dma-mapping.h>
>  #include <linux/slab.h>
>  #include <linux/string.h>
>
> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
> const char *name)
>         device->dev.type = &vchiq_device_type;
>         device->dev.release = vchiq_device_release;
>
> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
> +       if (ret < 0) {
> +               vchiq_device_release(&device->dev);
> +               return ret;
> +       }
> +
>         ret = device_register(&device->dev);
>         if (ret) {
>                 put_device(&device->dev);
>
> It seems we need to include the dma_set_mask_and_coherent() even if 
> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
> into why is that/
>
>  Laurent, any thoughts on this please?

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23 11:46     ` Stefan Wahren
@ 2023-01-23 14:12       ` Umang Jain
  2023-01-23 15:28         ` Stefan Wahren
  0 siblings, 1 reply; 23+ messages in thread
From: Umang Jain @ 2023-01-23 14:12 UTC (permalink / raw)
  To: Stefan Wahren, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Stefan

On 1/23/23 5:16 PM, Stefan Wahren wrote:
> Hi Umang,
>
> Am 23.01.23 um 08:48 schrieb Umang Jain:
>> Hi Stefan,
>>
>> Thank for the testing.
>>
>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>> Hi Umang,
>>>
>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>> This series just introduces five extra patches for dropping include
>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>
>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>> things to standard device/driver model using a custom_bus. Specific
>>>> details are elaborated in the commit message.
>>>>
>>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>>> of linux-next.
>>>
>>> applied this series on top of linux-next and build it with 
>>> arm/multi_v7_defconfig plus the following:
>>>
>>> CONFIG_BCM_VIDEOCORE=y
>>> CONFIG_BCM2835_VCHIQ=m
>>> CONFIG_VCHIQ_CDEV=y
>>> CONFIG_SND_BCM2835=m
>>> CONFIG_VIDEO_BCM2835=m
>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>
>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>
>>> [   25.523337] vchiq: module is from the staging directory, the 
>>> quality is unknown, you have been warned.
>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>> bcm2835_audio vchiq device
>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>> bcm2835-camera vchiq device
>>
>> I was able to reproduce and it seems the issue here is the change 
>> mentioned in the cover
>>
>> - drop dma_set_mask_and_coherent
>>
>> in V6.
>>
>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
>> applied so my branch has the DMA hunk included while I was testing V6)
>
> just to avoid misunderstandings, did you read 
> drivers/staging/vc04_services/interface/TESTING ?

Yes, but it's not geared towards the hardware I have (Rpi Model 4B)
>
> The Raspberry Pi 4 is currently not fully supported for VCHIQ in 
> mainline. From my limited understanding the DMA controller driver 
> needs 40 bit support, so VCHIQ on BCM2711 can use it. This part is 
> currently only available in the vendor tree. The reason why the driver 
> is unexpectedly probing is a historical issue in the devicetree :-(
>
> Raspberry Pi 4 support is not considered as necessary for moving out 
> of staging.
>

While I am looking into what's the reason behind the hunk, without which 
the devices cannot get registered... This is not related to the 40bit 
support for DMA. I remember that it worked without it during the 
bcm2835-isp development.

Are you implying that I should not use RPi Model 4B for testing ? 
Because that's the only RPi hardware I own.
>>
>> Below is the hunk which should resolve the issue.
>>
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> @@ -6,6 +6,7 @@
>>   */
>>
>>  #include <linux/device/bus.h>
>> +#include <linux/dma-mapping.h>
>>  #include <linux/slab.h>
>>  #include <linux/string.h>
>>
>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
>> const char *name)
>>         device->dev.type = &vchiq_device_type;
>>         device->dev.release = vchiq_device_release;
>>
>> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
>> +       if (ret < 0) {
>> +               vchiq_device_release(&device->dev);
>> +               return ret;
>> +       }
>> +
>>         ret = device_register(&device->dev);
>>         if (ret) {
>>                 put_device(&device->dev);
>>
>> It seems we need to include the dma_set_mask_and_coherent() even if 
>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
>> into why is that/
>>
>>  Laurent, any thoughts on this please?


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23 14:12       ` Umang Jain
@ 2023-01-23 15:28         ` Stefan Wahren
  0 siblings, 0 replies; 23+ messages in thread
From: Stefan Wahren @ 2023-01-23 15:28 UTC (permalink / raw)
  To: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Umang,

Am 23.01.23 um 15:12 schrieb Umang Jain:
> Hi Stefan
>
> On 1/23/23 5:16 PM, Stefan Wahren wrote:
>> Hi Umang,
>>
>> Am 23.01.23 um 08:48 schrieb Umang Jain:
>>> Hi Stefan,
>>>
>>> Thank for the testing.
>>>
>>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>>> Hi Umang,
>>>>
>>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>>> This series just introduces five extra patches for dropping include
>>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>>
>>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>>> things to standard device/driver model using a custom_bus. Specific
>>>>> details are elaborated in the commit message.
>>>>>
>>>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>>>> of linux-next.
>>>>
>>>> applied this series on top of linux-next and build it with 
>>>> arm/multi_v7_defconfig plus the following:
>>>>
>>>> CONFIG_BCM_VIDEOCORE=y
>>>> CONFIG_BCM2835_VCHIQ=m
>>>> CONFIG_VCHIQ_CDEV=y
>>>> CONFIG_SND_BCM2835=m
>>>> CONFIG_VIDEO_BCM2835=m
>>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>>
>>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>>
>>>> [   25.523337] vchiq: module is from the staging directory, the 
>>>> quality is unknown, you have been warned.
>>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>>> bcm2835_audio vchiq device
>>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>>> bcm2835-camera vchiq device
>>>
>>> I was able to reproduce and it seems the issue here is the change 
>>> mentioned in the cover
>>>
>>> - drop dma_set_mask_and_coherent
>>>
>>> in V6.
>>>
>>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
>>> applied so my branch has the DMA hunk included while I was testing V6)
>>
>> just to avoid misunderstandings, did you read 
>> drivers/staging/vc04_services/interface/TESTING ?
>
> Yes, but it's not geared towards the hardware I have (Rpi Model 4B)
>>
>> The Raspberry Pi 4 is currently not fully supported for VCHIQ in 
>> mainline. From my limited understanding the DMA controller driver 
>> needs 40 bit support, so VCHIQ on BCM2711 can use it. This part is 
>> currently only available in the vendor tree. The reason why the 
>> driver is unexpectedly probing is a historical issue in the 
>> devicetree :-(
>>
>> Raspberry Pi 4 support is not considered as necessary for moving out 
>> of staging.
>>
>
> While I am looking into what's the reason behind the hunk, without 
> which the devices cannot get registered... This is not related to the 
> 40bit support for DMA. I remember that it worked without it during the 
> bcm2835-isp development.
>
> Are you implying that I should not use RPi Model 4B for testing ? 
> Because that's the only RPi hardware I own.

No, i didn't want to imply this. It's just a warning that's currently 
not the best platform for testing. But i also understand that nowadays 
users have a BCM2711 based Raspberry Pi.

This leads to another question which device tree do you use for testing, 
since the mainline one doesn't have the right compatible for BCM2711?

>>>
>>> Below is the hunk which should resolve the issue.
>>>
>>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>> @@ -6,6 +6,7 @@
>>>   */
>>>
>>>  #include <linux/device/bus.h>
>>> +#include <linux/dma-mapping.h>
>>>  #include <linux/slab.h>
>>>  #include <linux/string.h>
>>>
>>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
>>> const char *name)
>>>         device->dev.type = &vchiq_device_type;
>>>         device->dev.release = vchiq_device_release;
>>>
>>> +       ret = dma_set_mask_and_coherent(&device->dev, 
>>> DMA_BIT_MASK(32));
>>> +       if (ret < 0) {
>>> +               vchiq_device_release(&device->dev);
>>> +               return ret;
>>> +       }
>>> +
>>>         ret = device_register(&device->dev);
>>>         if (ret) {
>>>                 put_device(&device->dev);
>>>
>>> It seems we need to include the dma_set_mask_and_coherent() even if 
>>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
>>> into why is that/
>>>
>>>  Laurent, any thoughts on this please?
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23  7:48   ` Umang Jain
  2023-01-23  8:58     ` Laurent Pinchart
  2023-01-23 11:46     ` Stefan Wahren
@ 2023-01-23 17:28     ` Stefan Wahren
  2023-01-24  5:39       ` Umang Jain
  2 siblings, 1 reply; 23+ messages in thread
From: Stefan Wahren @ 2023-01-23 17:28 UTC (permalink / raw)
  To: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Umang,

Am 23.01.23 um 08:48 schrieb Umang Jain:
> Hi Stefan,
>
> Thank for the testing.
>
> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>> Hi Umang,
>>
>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>> This series just introduces five extra patches for dropping include
>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>
>>> The main patch (6/6) removes platform device/driver abuse and moves
>>> things to standard device/driver model using a custom_bus. Specific
>>> details are elaborated in the commit message.
>>>
>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>> of linux-next.
>>
>> applied this series on top of linux-next and build it with 
>> arm/multi_v7_defconfig plus the following:
>>
>> CONFIG_BCM_VIDEOCORE=y
>> CONFIG_BCM2835_VCHIQ=m
>> CONFIG_VCHIQ_CDEV=y
>> CONFIG_SND_BCM2835=m
>> CONFIG_VIDEO_BCM2835=m
>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>
>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>
>> [   25.523337] vchiq: module is from the staging directory, the 
>> quality is unknown, you have been warned.
>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>> bcm2835_audio vchiq device
>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>> bcm2835-camera vchiq device
>
> I was able to reproduce and it seems the issue here is the change 
> mentioned in the cover
>
> - drop dma_set_mask_and_coherent
>
> in V6.
>
> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
> applied so my branch has the DMA hunk included while I was testing V6)
>
> Below is the hunk which should resolve the issue.
>
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> @@ -6,6 +6,7 @@
>   */
>
>  #include <linux/device/bus.h>
> +#include <linux/dma-mapping.h>
>  #include <linux/slab.h>
>  #include <linux/string.h>
>
> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
> const char *name)
>         device->dev.type = &vchiq_device_type;
>         device->dev.release = vchiq_device_release;
>
> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
> +       if (ret < 0) {
> +               vchiq_device_release(&device->dev);
> +               return ret;
> +       }
> +
>         ret = device_register(&device->dev);
>         if (ret) {
>                 put_device(&device->dev);
Yes, this patch fixes the errors above. But i noticed that the series 
also break autoprobing of bcm2835-audio and bcm2835-camera.
>
> It seems we need to include the dma_set_mask_and_coherent() even if 
> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
> into why is that/
>
>  Laurent, any thoughts on this please?
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-20 20:11 ` [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
  2023-01-22 23:50   ` Stefan Wahren
@ 2023-01-23 18:11   ` Greg Kroah-Hartman
  2023-01-23 18:22     ` Laurent Pinchart
  1 sibling, 1 reply; 23+ messages in thread
From: Greg Kroah-Hartman @ 2023-01-23 18:11 UTC (permalink / raw)
  To: Umang Jain
  Cc: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel, Stefan Wahren, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

On Sat, Jan 21, 2023 at 01:41:04AM +0530, 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.
> 
> Replace the platform device/driver model with a standard device driver
> model. A custom bus_type, vchiq_bus_type, is created in the vchiq
> interface which matches the devices to their specific device drivers
> thereby, establishing driver binding. A struct vchiq_device wraps the
> struct device for each device being registered on the bus by the vchiq
> interface. On the other hand, struct vchiq_driver wraps the struct
> device_driver and the module_vchiq_driver() macro is provided for the
> driver registration.
> 
> Each device registered will expose a 'name' read-only device attribute
> in sysfs (/sys/bus/vchiq-bus/devices). New devices and drivers can be
> added by registering on vchiq_bus_type and adding a corresponding
> device name entry in the static list of devices, vchiq_devices. There
> is currently no way to enumerate the VCHIQ devices that are available
> from the firmware.

I took the first 5 patches in this series, but stopped here.

This one needs to be broken up into much smaller pieces.  I suggest
creating the bus, and then move the existing code over to the new
interfaces instead of doing it all at once.  This way is much harder to
review and problems do not stand out very well.

Some minor questions:

> -static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
> +static int snd_bcm2835_alsa_probe(struct device *dev)

probe functions (and all bus functions) should take your new device
type, not a generic device type, as that's not what they are working
with here at all.


>  {
> -	struct device *dev = &pdev->dev;
>  	int err;
>  
>  	if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
> @@ -292,32 +291,32 @@ 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 device *pdev,
>  				    pm_message_t state)

Same here, use your real device type.

> -static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
> +static int snd_bcm2835_alsa_resume(struct device *pdev)

And here, a real device type please.

>  MODULE_AUTHOR("Dom Cobley");
>  MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
>  MODULE_LICENSE("GPL");
> -MODULE_ALIAS("platform:bcm2835_audio");
> +MODULE_ALIAS("bcm2835_audio");

Why do you need this module alias now?  Are you sure it still works?  If
so, why is it created by hand like this?

> +static const char *const vchiq_devices[] = {
> +	"bcm2835_audio",
> +	"bcm2835-camera",
> +};

A list of device names?  That's really odd, so please really really
document it.

> +static ssize_t vchiq_dev_show(struct device *dev,
> +			      struct device_attribute *attr, char *buf)
> +{
> +	struct vchiq_device *device = container_of(dev, struct vchiq_device, dev);
> +
> +	return sprintf(buf, "%s", device->name);

sysfs_emit() please.

But why do you have the device name as a sysfs file?  It's the name of
the directory in sysfs already, why have it repeated?

> +}
> +
> +static DEVICE_ATTR_RO(vchiq_dev);
> +
> +static struct attribute *vchiq_dev_attrs[] = {
> +	&dev_attr_vchiq_dev.attr,
> +	NULL
> +};
> +
> +ATTRIBUTE_GROUPS(vchiq_dev);
> +
> +static const struct device_type vchiq_device_type = {
> +	.groups         = vchiq_dev_groups
> +};
> +
> +struct bus_type vchiq_bus_type = {
> +	.name   = "vchiq-bus",
> +	.match  = vchiq_bus_type_match,
> +};
> +EXPORT_SYMBOL_GPL(vchiq_bus_type);

Why is this exported?

> +
> +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->name = name;
> +	device->dev.init_name = name;
> +	device->dev.parent = parent;
> +	device->dev.bus = &vchiq_bus_type;
> +	device->dev.type = &vchiq_device_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..0848c1b353f8
> --- /dev/null
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
> +/*
> + * 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;
> +	const char *name;

Why do you need another name for your device?  What's wrong with the
name field in struct device?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23 18:11   ` Greg Kroah-Hartman
@ 2023-01-23 18:22     ` Laurent Pinchart
  0 siblings, 0 replies; 23+ messages in thread
From: Laurent Pinchart @ 2023-01-23 18:22 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel, Stefan Wahren, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Paul Elder

Hi Greg,

On Mon, Jan 23, 2023 at 07:11:06PM +0100, Greg Kroah-Hartman wrote:
> On Sat, Jan 21, 2023 at 01:41:04AM +0530, 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.
> > 
> > Replace the platform device/driver model with a standard device driver
> > model. A custom bus_type, vchiq_bus_type, is created in the vchiq
> > interface which matches the devices to their specific device drivers
> > thereby, establishing driver binding. A struct vchiq_device wraps the
> > struct device for each device being registered on the bus by the vchiq
> > interface. On the other hand, struct vchiq_driver wraps the struct
> > device_driver and the module_vchiq_driver() macro is provided for the
> > driver registration.
> > 
> > Each device registered will expose a 'name' read-only device attribute
> > in sysfs (/sys/bus/vchiq-bus/devices). New devices and drivers can be
> > added by registering on vchiq_bus_type and adding a corresponding
> > device name entry in the static list of devices, vchiq_devices. There
> > is currently no way to enumerate the VCHIQ devices that are available
> > from the firmware.
> 
> I took the first 5 patches in this series, but stopped here.
> 
> This one needs to be broken up into much smaller pieces.  I suggest
> creating the bus, and then move the existing code over to the new
> interfaces instead of doing it all at once.  This way is much harder to
> review and problems do not stand out very well.
> 
> Some minor questions:
> 
> > -static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
> > +static int snd_bcm2835_alsa_probe(struct device *dev)
> 
> probe functions (and all bus functions) should take your new device
> type, not a generic device type, as that's not what they are working
> with here at all.
> 
> >  {
> > -	struct device *dev = &pdev->dev;
> >  	int err;
> >  
> >  	if (num_channels <= 0 || num_channels > MAX_SUBSTREAMS) {
> > @@ -292,32 +291,32 @@ 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 device *pdev,
> >  				    pm_message_t state)
> 
> Same here, use your real device type.
> 
> > -static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
> > +static int snd_bcm2835_alsa_resume(struct device *pdev)
> 
> And here, a real device type please.
> 
> >  MODULE_AUTHOR("Dom Cobley");
> >  MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
> >  MODULE_LICENSE("GPL");
> > -MODULE_ALIAS("platform:bcm2835_audio");
> > +MODULE_ALIAS("bcm2835_audio");
> 
> Why do you need this module alias now?  Are you sure it still works?  If
> so, why is it created by hand like this?

I like when you beat me to review a series, and point out all the things
I would have pointed out too :-)

> > +static const char *const vchiq_devices[] = {
> > +	"bcm2835_audio",
> > +	"bcm2835-camera",
> > +};
> 
> A list of device names?  That's really odd, so please really really
> document it.

As discussed previously, the devices implemented in the firmware are not
discoverable, so we need to hardcode them here. A comment is indeed
needed.

> > +static ssize_t vchiq_dev_show(struct device *dev,
> > +			      struct device_attribute *attr, char *buf)
> > +{
> > +	struct vchiq_device *device = container_of(dev, struct vchiq_device, dev);
> > +
> > +	return sprintf(buf, "%s", device->name);
> 
> sysfs_emit() please.
> 
> But why do you have the device name as a sysfs file?  It's the name of
> the directory in sysfs already, why have it repeated?
> 
> > +}
> > +
> > +static DEVICE_ATTR_RO(vchiq_dev);
> > +
> > +static struct attribute *vchiq_dev_attrs[] = {
> > +	&dev_attr_vchiq_dev.attr,
> > +	NULL
> > +};
> > +
> > +ATTRIBUTE_GROUPS(vchiq_dev);
> > +
> > +static const struct device_type vchiq_device_type = {
> > +	.groups         = vchiq_dev_groups
> > +};
> > +
> > +struct bus_type vchiq_bus_type = {
> > +	.name   = "vchiq-bus",
> > +	.match  = vchiq_bus_type_match,
> > +};
> > +EXPORT_SYMBOL_GPL(vchiq_bus_type);
> 
> Why is this exported?
> 
> > +
> > +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->name = name;
> > +	device->dev.init_name = name;
> > +	device->dev.parent = parent;
> > +	device->dev.bus = &vchiq_bus_type;
> > +	device->dev.type = &vchiq_device_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..0848c1b353f8
> > --- /dev/null
> > +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.h
> > @@ -0,0 +1,39 @@
> > +/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
> > +/*
> > + * 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;
> > +	const char *name;
> 
> Why do you need another name for your device?  What's wrong with the
> name field in struct device?
> 
> thanks,
> 
> greg k-h

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23 17:28     ` Stefan Wahren
@ 2023-01-24  5:39       ` Umang Jain
  2023-01-24  8:26         ` Laurent Pinchart
  2023-01-24  8:39         ` Stefan Wahren
  0 siblings, 2 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-24  5:39 UTC (permalink / raw)
  To: Stefan Wahren, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Stefan

On 1/23/23 10:58 PM, Stefan Wahren wrote:
> Hi Umang,
>
> Am 23.01.23 um 08:48 schrieb Umang Jain:
>> Hi Stefan,
>>
>> Thank for the testing.
>>
>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>> Hi Umang,
>>>
>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>> This series just introduces five extra patches for dropping include
>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>
>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>> things to standard device/driver model using a custom_bus. Specific
>>>> details are elaborated in the commit message.
>>>>
>>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>>> of linux-next.
>>>
>>> applied this series on top of linux-next and build it with 
>>> arm/multi_v7_defconfig plus the following:
>>>
>>> CONFIG_BCM_VIDEOCORE=y
>>> CONFIG_BCM2835_VCHIQ=m
>>> CONFIG_VCHIQ_CDEV=y
>>> CONFIG_SND_BCM2835=m
>>> CONFIG_VIDEO_BCM2835=m
>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>
>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>
>>> [   25.523337] vchiq: module is from the staging directory, the 
>>> quality is unknown, you have been warned.
>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>> bcm2835_audio vchiq device
>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>> bcm2835-camera vchiq device
>>
>> I was able to reproduce and it seems the issue here is the change 
>> mentioned in the cover
>>
>> - drop dma_set_mask_and_coherent
>>
>> in V6.
>>
>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
>> applied so my branch has the DMA hunk included while I was testing V6)
>>
>> Below is the hunk which should resolve the issue.
>>
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> @@ -6,6 +6,7 @@
>>   */
>>
>>  #include <linux/device/bus.h>
>> +#include <linux/dma-mapping.h>
>>  #include <linux/slab.h>
>>  #include <linux/string.h>
>>
>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
>> const char *name)
>>         device->dev.type = &vchiq_device_type;
>>         device->dev.release = vchiq_device_release;
>>
>> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
>> +       if (ret < 0) {
>> +               vchiq_device_release(&device->dev);
>> +               return ret;
>> +       }
>> +
>>         ret = device_register(&device->dev);
>>         if (ret) {
>>                 put_device(&device->dev);
> Yes, this patch fixes the errors above. But i noticed that the series 
> also break autoprobing of bcm2835-audio and bcm2835-camera.

For the diff concerned, I am still looking into why is this needed.

Regarding the autoprobing, I have noticed that as well. It seems the 
probing is automatic for platform driver/devices and we are moving away 
from the platform driver/devices. So, this is expected I suppose?

Reading from Documentation/driver-api/driver-model/platform.rst

"""
Driver binding is performed automatically by the driver core, invoking 
driver probe() after finding a match between device and driver. If the 
probe() succeeds, the driver and device are bound as usual
"""

Should we retain this behavior ?
>>
>> It seems we need to include the dma_set_mask_and_coherent() even if 
>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
>> into why is that/
>>
>>  Laurent, any thoughts on this please?
>>
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-24  5:39       ` Umang Jain
@ 2023-01-24  8:26         ` Laurent Pinchart
  2023-01-24  8:39         ` Stefan Wahren
  1 sibling, 0 replies; 23+ messages in thread
From: Laurent Pinchart @ 2023-01-24  8:26 UTC (permalink / raw)
  To: Umang Jain
  Cc: Stefan Wahren, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Paul Elder

Hi Umang,

On Tue, Jan 24, 2023 at 11:09:31AM +0530, Umang Jain wrote:
> On 1/23/23 10:58 PM, Stefan Wahren wrote:
> > Am 23.01.23 um 08:48 schrieb Umang Jain:
> >> On 1/23/23 5:04 AM, Stefan Wahren wrote:
> >>> Am 20.01.23 um 21:10 schrieb Umang Jain:
> >>>> This series just introduces five extra patches for dropping include
> >>>> directives from Makefiles (suggested by Greg KH) and rebased.
> >>>>
> >>>> The main patch (6/6) removes platform device/driver abuse and moves
> >>>> things to standard device/driver model using a custom_bus. Specific
> >>>> details are elaborated in the commit message.
> >>>>
> >>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
> >>>> of linux-next.
> >>>
> >>> applied this series on top of linux-next and build it with 
> >>> arm/multi_v7_defconfig plus the following:
> >>>
> >>> CONFIG_BCM_VIDEOCORE=y
> >>> CONFIG_BCM2835_VCHIQ=m
> >>> CONFIG_VCHIQ_CDEV=y
> >>> CONFIG_SND_BCM2835=m
> >>> CONFIG_VIDEO_BCM2835=m
> >>> CONFIG_BCM2835_VCHIQ_MMAL=m
> >>>
> >>> and the devices doesn't register on Raspberry Pi 3 B Plus:
> >>>
> >>> [   25.523337] vchiq: module is from the staging directory, the 
> >>> quality is unknown, you have been warned.
> >>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
> >>> bcm2835_audio vchiq device
> >>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
> >>> bcm2835-camera vchiq device
> >>
> >> I was able to reproduce and it seems the issue here is the change 
> >> mentioned in the cover
> >>
> >> - drop dma_set_mask_and_coherent
> >>
> >> in V6.
> >>
> >> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
> >> applied so my branch has the DMA hunk included while I was testing V6)
> >>
> >> Below is the hunk which should resolve the issue.
> >>
> >> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> >> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
> >> @@ -6,6 +6,7 @@
> >>   */
> >>
> >>  #include <linux/device/bus.h>
> >> +#include <linux/dma-mapping.h>
> >>  #include <linux/slab.h>
> >>  #include <linux/string.h>
> >>
> >> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
> >> const char *name)
> >>         device->dev.type = &vchiq_device_type;
> >>         device->dev.release = vchiq_device_release;
> >>
> >> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
> >> +       if (ret < 0) {
> >> +               vchiq_device_release(&device->dev);
> >> +               return ret;
> >> +       }
> >> +
> >>         ret = device_register(&device->dev);
> >>         if (ret) {
> >>                 put_device(&device->dev);
> >
> > Yes, this patch fixes the errors above. But i noticed that the series 
> > also break autoprobing of bcm2835-audio and bcm2835-camera.
> 
> For the diff concerned, I am still looking into why is this needed.
> 
> Regarding the autoprobing, I have noticed that as well. It seems the 
> probing is automatic for platform driver/devices and we are moving away 
> from the platform driver/devices. So, this is expected I suppose?
> 
> Reading from Documentation/driver-api/driver-model/platform.rst
> 
> """
> Driver binding is performed automatically by the driver core, invoking 
> driver probe() after finding a match between device and driver. If the 
> probe() succeeds, the driver and device are bound as usual
> """
> 
> Should we retain this behavior ?

Why shouldn't we ? :-)

> >> It seems we need to include the dma_set_mask_and_coherent() even if 
> >> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
> >> into why is that/
> >>
> >>  Laurent, any thoughts on this please?

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-24  5:39       ` Umang Jain
  2023-01-24  8:26         ` Laurent Pinchart
@ 2023-01-24  8:39         ` Stefan Wahren
  1 sibling, 0 replies; 23+ messages in thread
From: Stefan Wahren @ 2023-01-24  8:39 UTC (permalink / raw)
  To: Umang Jain, linux-staging, linux-rpi-kernel, linux-arm-kernel,
	linux-media, linux-kernel
  Cc: Greg Kroah-Hartman, Florian Fainelli, Adrien Thierry,
	Dan Carpenter, Dave Stevenson, Kieran Bingham, Laurent Pinchart,
	Paul Elder

Hi Umang,

Am 24.01.23 um 06:39 schrieb Umang Jain:
> Hi Stefan
>
> On 1/23/23 10:58 PM, Stefan Wahren wrote:
>> Hi Umang,
>>
>> Am 23.01.23 um 08:48 schrieb Umang Jain:
>>> Hi Stefan,
>>>
>>> Thank for the testing.
>>>
>>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>>> Hi Umang,
>>>>
>>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>>> This series just introduces five extra patches for dropping include
>>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>>
>>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>>> things to standard device/driver model using a custom_bus. Specific
>>>>> details are elaborated in the commit message.
>>>>>
>>>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>>>> of linux-next.
>>>>
>>>> applied this series on top of linux-next and build it with 
>>>> arm/multi_v7_defconfig plus the following:
>>>>
>>>> CONFIG_BCM_VIDEOCORE=y
>>>> CONFIG_BCM2835_VCHIQ=m
>>>> CONFIG_VCHIQ_CDEV=y
>>>> CONFIG_SND_BCM2835=m
>>>> CONFIG_VIDEO_BCM2835=m
>>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>>
>>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>>
>>>> [   25.523337] vchiq: module is from the staging directory, the 
>>>> quality is unknown, you have been warned.
>>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>>> bcm2835_audio vchiq device
>>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>>> bcm2835-camera vchiq device
>>>
>>> I was able to reproduce and it seems the issue here is the change 
>>> mentioned in the cover
>>>
>>> - drop dma_set_mask_and_coherent
>>>
>>> in V6.
>>>
>>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
>>> applied so my branch has the DMA hunk included while I was testing V6)
>>>
>>> Below is the hunk which should resolve the issue.
>>>
>>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>> @@ -6,6 +6,7 @@
>>>   */
>>>
>>>  #include <linux/device/bus.h>
>>> +#include <linux/dma-mapping.h>
>>>  #include <linux/slab.h>
>>>  #include <linux/string.h>
>>>
>>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent, 
>>> const char *name)
>>>         device->dev.type = &vchiq_device_type;
>>>         device->dev.release = vchiq_device_release;
>>>
>>> +       ret = dma_set_mask_and_coherent(&device->dev, 
>>> DMA_BIT_MASK(32));
>>> +       if (ret < 0) {
>>> +               vchiq_device_release(&device->dev);
>>> +               return ret;
>>> +       }
>>> +
>>>         ret = device_register(&device->dev);
>>>         if (ret) {
>>>                 put_device(&device->dev);
>> Yes, this patch fixes the errors above. But i noticed that the series 
>> also break autoprobing of bcm2835-audio and bcm2835-camera.
>
> For the diff concerned, I am still looking into why is this needed.
>
> Regarding the autoprobing, I have noticed that as well. It seems the 
> probing is automatic for platform driver/devices and we are moving 
> away from the platform driver/devices. So, this is expected I suppose?
>
> Reading from Documentation/driver-api/driver-model/platform.rst
>
> """
> Driver binding is performed automatically by the driver core, invoking 
> driver probe() after finding a match between device and driver. If the 
> probe() succeeds, the driver and device are bound as usual
> """
>
> Should we retain this behavior ?
 From user perspective this behavior change is a regression. So we need 
automatic probing to convince user to use the mainline kernel.
>>>
>>> It seems we need to include the dma_set_mask_and_coherent() even if 
>>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
>>> into why is that/
>>>
>>>  Laurent, any thoughts on this please?
>>>
>>> _______________________________________________
>>> linux-arm-kernel mailing list
>>> linux-arm-kernel@lists.infradead.org
>>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-23  8:58     ` Laurent Pinchart
@ 2023-01-24  8:41       ` Stefan Wahren
  2023-01-24 19:47         ` Phil Elwell
  0 siblings, 1 reply; 23+ messages in thread
From: Stefan Wahren @ 2023-01-24  8:41 UTC (permalink / raw)
  To: Laurent Pinchart, Umang Jain, Phil Elwell
  Cc: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Paul Elder

Hi Phil,

Am 23.01.23 um 09:58 schrieb Laurent Pinchart:
> On Mon, Jan 23, 2023 at 01:18:30PM +0530, Umang Jain wrote:
>> Hi Stefan,
>>
>> Thank for the testing.
>>
>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>> Hi Umang,
>>>
>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>> This series just introduces five extra patches for dropping include
>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>
>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>> things to standard device/driver model using a custom_bus. Specific
>>>> details are elaborated in the commit message.
>>>>
>>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>>> of linux-next.
>>> applied this series on top of linux-next and build it with
>>> arm/multi_v7_defconfig plus the following:
>>>
>>> CONFIG_BCM_VIDEOCORE=y
>>> CONFIG_BCM2835_VCHIQ=m
>>> CONFIG_VCHIQ_CDEV=y
>>> CONFIG_SND_BCM2835=m
>>> CONFIG_VIDEO_BCM2835=m
>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>
>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>
>>> [   25.523337] vchiq: module is from the staging directory, the quality is unknown, you have been warned.
>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register bcm2835_audio vchiq device
>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register bcm2835-camera vchiq device
>> I was able to reproduce and it seems the issue here is the change
>> mentioned in the cover
>>
>> - drop dma_set_mask_and_coherent
>>
>> in V6.
>>
>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp applied
>> so my branch has the DMA hunk included while I was testing V6)
>>
>> Below is the hunk which should resolve the issue.
>>
>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>> @@ -6,6 +6,7 @@
>>     */
>>
>>    #include <linux/device/bus.h>
>> +#include <linux/dma-mapping.h>
>>    #include <linux/slab.h>
>>    #include <linux/string.h>
>>
>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent,
>> const char *name)
>>           device->dev.type = &vchiq_device_type;
>>           device->dev.release = vchiq_device_release;
>>
>> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
>> +       if (ret < 0) {
>> +               vchiq_device_release(&device->dev);
>> +               return ret;
>> +       }
>> +
>>           ret = device_register(&device->dev);
>>           if (ret) {
>>                   put_device(&device->dev);
>>
>> It seems we need to include the dma_set_mask_and_coherent() even if
>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look into
>> why is that/

Do you have an answer for this?

Thanks

>>
>>    Laurent, any thoughts on this please?
> Nothing that immediately springs to my mind. Can you investigate ?
>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-24  8:41       ` Stefan Wahren
@ 2023-01-24 19:47         ` Phil Elwell
  2023-01-26 13:33           ` Umang Jain
  0 siblings, 1 reply; 23+ messages in thread
From: Phil Elwell @ 2023-01-24 19:47 UTC (permalink / raw)
  To: Stefan Wahren, Laurent Pinchart, Umang Jain
  Cc: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Paul Elder

On 24/01/2023 8:41, Stefan Wahren wrote:
> Hi Phil,
> 
> Am 23.01.23 um 09:58 schrieb Laurent Pinchart:
>> On Mon, Jan 23, 2023 at 01:18:30PM +0530, Umang Jain wrote:
>>> Hi Stefan,
>>>
>>> Thank for the testing.
>>>
>>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>>> Hi Umang,
>>>>
>>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>>> This series just introduces five extra patches for dropping include
>>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>>
>>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>>> things to standard device/driver model using a custom_bus. Specific
>>>>> details are elaborated in the commit message.
>>>>>
>>>>> The patch series is based on top of d514392f17fd (tag: next-20230120)
>>>>> of linux-next.
>>>> applied this series on top of linux-next and build it with
>>>> arm/multi_v7_defconfig plus the following:
>>>>
>>>> CONFIG_BCM_VIDEOCORE=y
>>>> CONFIG_BCM2835_VCHIQ=m
>>>> CONFIG_VCHIQ_CDEV=y
>>>> CONFIG_SND_BCM2835=m
>>>> CONFIG_VIDEO_BCM2835=m
>>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>>
>>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>>
>>>> [   25.523337] vchiq: module is from the staging directory, the quality is unknown, you have been warned.
>>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register bcm2835_audio vchiq device
>>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register bcm2835-camera vchiq device
>>> I was able to reproduce and it seems the issue here is the change
>>> mentioned in the cover
>>>
>>> - drop dma_set_mask_and_coherent
>>>
>>> in V6.
>>>
>>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp applied
>>> so my branch has the DMA hunk included while I was testing V6)
>>>
>>> Below is the hunk which should resolve the issue.
>>>
>>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>> @@ -6,6 +6,7 @@
>>>     */
>>>
>>>    #include <linux/device/bus.h>
>>> +#include <linux/dma-mapping.h>
>>>    #include <linux/slab.h>
>>>    #include <linux/string.h>
>>>
>>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent,
>>> const char *name)
>>>           device->dev.type = &vchiq_device_type;
>>>           device->dev.release = vchiq_device_release;
>>>
>>> +       ret = dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32));
>>> +       if (ret < 0) {
>>> +               vchiq_device_release(&device->dev);
>>> +               return ret;
>>> +       }
>>> +
>>>           ret = device_register(&device->dev);
>>>           if (ret) {
>>>                   put_device(&device->dev);
>>>
>>> It seems we need to include the dma_set_mask_and_coherent() even if
>>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look into
>>> why is that/
> 
> Do you have an answer for this?

That's because vchiq does use DMA for bulk transfers, it's just that the DMA hardware
is driven from the VPU side. And even though the VPU can only address 1GB, it uses the
upper address bits to determine cacheability of accesses, hence the need for 32-bit
DMA addresses.

Phil


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type
  2023-01-24 19:47         ` Phil Elwell
@ 2023-01-26 13:33           ` Umang Jain
  0 siblings, 0 replies; 23+ messages in thread
From: Umang Jain @ 2023-01-26 13:33 UTC (permalink / raw)
  To: Phil Elwell, Stefan Wahren, Laurent Pinchart
  Cc: linux-staging, linux-rpi-kernel, linux-arm-kernel, linux-media,
	linux-kernel, Greg Kroah-Hartman, Florian Fainelli,
	Adrien Thierry, Dan Carpenter, Dave Stevenson, Kieran Bingham,
	Paul Elder

Hi Phil,

Thank you for the response

On 1/25/23 1:17 AM, Phil Elwell wrote:
> On 24/01/2023 8:41, Stefan Wahren wrote:
>> Hi Phil,
>>
>> Am 23.01.23 um 09:58 schrieb Laurent Pinchart:
>>> On Mon, Jan 23, 2023 at 01:18:30PM +0530, Umang Jain wrote:
>>>> Hi Stefan,
>>>>
>>>> Thank for the testing.
>>>>
>>>> On 1/23/23 5:04 AM, Stefan Wahren wrote:
>>>>> Hi Umang,
>>>>>
>>>>> Am 20.01.23 um 21:10 schrieb Umang Jain:
>>>>>> This series just introduces five extra patches for dropping include
>>>>>> directives from Makefiles (suggested by Greg KH) and rebased.
>>>>>>
>>>>>> The main patch (6/6) removes platform device/driver abuse and moves
>>>>>> things to standard device/driver model using a custom_bus. Specific
>>>>>> details are elaborated in the commit message.
>>>>>>
>>>>>> The patch series is based on top of d514392f17fd (tag: 
>>>>>> next-20230120)
>>>>>> of linux-next.
>>>>> applied this series on top of linux-next and build it with
>>>>> arm/multi_v7_defconfig plus the following:
>>>>>
>>>>> CONFIG_BCM_VIDEOCORE=y
>>>>> CONFIG_BCM2835_VCHIQ=m
>>>>> CONFIG_VCHIQ_CDEV=y
>>>>> CONFIG_SND_BCM2835=m
>>>>> CONFIG_VIDEO_BCM2835=m
>>>>> CONFIG_BCM2835_VCHIQ_MMAL=m
>>>>>
>>>>> and the devices doesn't register on Raspberry Pi 3 B Plus:
>>>>>
>>>>> [   25.523337] vchiq: module is from the staging directory, the 
>>>>> quality is unknown, you have been warned.
>>>>> [   25.541647] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>>>> bcm2835_audio vchiq device
>>>>> [   25.553692] bcm2835_vchiq 3f00b840.mailbox: Failed to register 
>>>>> bcm2835-camera vchiq device
>>>> I was able to reproduce and it seems the issue here is the change
>>>> mentioned in the cover
>>>>
>>>> - drop dma_set_mask_and_coherent
>>>>
>>>> in V6.
>>>>
>>>> (I usually test patches on RPi 4B with vcsm-cma and bcm2835-isp 
>>>> applied
>>>> so my branch has the DMA hunk included while I was testing V6)
>>>>
>>>> Below is the hunk which should resolve the issue.
>>>>
>>>> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>>> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_device.c
>>>> @@ -6,6 +6,7 @@
>>>>     */
>>>>
>>>>    #include <linux/device/bus.h>
>>>> +#include <linux/dma-mapping.h>
>>>>    #include <linux/slab.h>
>>>>    #include <linux/string.h>
>>>>
>>>> @@ -72,6 +73,12 @@ int vchiq_device_register(struct device *parent,
>>>> const char *name)
>>>>           device->dev.type = &vchiq_device_type;
>>>>           device->dev.release = vchiq_device_release;
>>>>
>>>> +       ret = dma_set_mask_and_coherent(&device->dev, 
>>>> DMA_BIT_MASK(32));
>>>> +       if (ret < 0) {
>>>> +               vchiq_device_release(&device->dev);
>>>> +               return ret;
>>>> +       }
>>>> +
>>>>           ret = device_register(&device->dev);
>>>>           if (ret) {
>>>>                   put_device(&device->dev);
>>>>
>>>> It seems we need to include the dma_set_mask_and_coherent() even if
>>>> bcm2835-audio, bcm2835-camera device doesn't do DMA? I need to look 
>>>> into
>>>> why is that/
>>
>> Do you have an answer for this?
>
> That's because vchiq does use DMA for bulk transfers, it's just that 
> the DMA hardware
> is driven from the VPU side. And even though the VPU can only address 
> 1GB, it uses the
> upper address bits to determine cacheability of accesses, hence the 
> need for 32-bit
> DMA addresses.

Is it worth recording this as a comment  in the patch?
>
> Phil
>


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2023-01-26 13:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-20 20:10 [PATCH v6 0/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
2023-01-20 20:10 ` [PATCH v6 1/6] staging: vc04_services: Drop __VCCOREVER__ remnants Umang Jain
2023-01-20 20:11 ` [PATCH v6 2/6] staging: vc04_services: bcm2835-audio: Drop include Makefile directive Umang Jain
2023-01-20 20:11 ` [PATCH v6 3/6] staging: vc04_services: bcm2835-camera: " Umang Jain
2023-01-20 20:11 ` [PATCH v6 4/6] staging: vc04_services: vchiq-mmal: " Umang Jain
2023-01-20 20:11 ` [PATCH v6 5/6] staging: vc04_services: interface: " Umang Jain
2023-01-20 20:11 ` [PATCH v6 6/6] staging: vc04_services: vchiq: Register devices with a custom bus_type Umang Jain
2023-01-22 23:50   ` Stefan Wahren
2023-01-23 18:11   ` Greg Kroah-Hartman
2023-01-23 18:22     ` Laurent Pinchart
2023-01-22 23:34 ` [PATCH v6 0/6] " Stefan Wahren
2023-01-23  7:48   ` Umang Jain
2023-01-23  8:58     ` Laurent Pinchart
2023-01-24  8:41       ` Stefan Wahren
2023-01-24 19:47         ` Phil Elwell
2023-01-26 13:33           ` Umang Jain
2023-01-23 11:46     ` Stefan Wahren
2023-01-23 14:12       ` Umang Jain
2023-01-23 15:28         ` Stefan Wahren
2023-01-23 17:28     ` Stefan Wahren
2023-01-24  5:39       ` Umang Jain
2023-01-24  8:26         ` Laurent Pinchart
2023-01-24  8:39         ` Stefan Wahren

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).