Skip to contentSkip to conversation

GMSL Refresh (would be v6)

PATCH In review Jacopo Mondi 5 participants 29 messages Nov 16, 2019 – Dec 11, 2019

Subsystems (4)
lore
Share & tools
lore

Jacopo Mondi

author maintainer
#0 lore raw

cover GMSL Refresh (would be v6)

Hello this is refersh of our GMSL work.

Current situation is the following:
- Kieran sent a full v4 with multiplexed stream support and has a v5 branch in his repository with v4 review comment fixes on top

I rebased the multiplexed stream's series on latest media-master
https://jmondi.org/cgit/linux/log/?h=v4l2-mux/media-master/v6

On top of that I took Kieran's v5 and re-applied on top:
https://jmondi.org/cgit/linux/log/?h=jmondi/gmsl/kieran/v6

- Niklas sent a v1 (which sould have been a v5) which removes multiplexed streams and only support one camera and was meant for inclusion but is still floating around in linux-media, mostly because some of the comments on Kieran's v4 still applied there, if I'm not mistaken.

I took Niklas' single stream max9286 and replaced the original bindings with a json-schema version
https://jmondi.org/cgit/linux/log/?h=jmondi/gmsl/niklas/v6

I bumped all versions to v6 to avoid further confusion.

Not having a working GMSL setup I would ask to Kieran or Niklas to test this version so that we can try re-send the single stream max9286 version with new yaml bindings for inclusion.

(I kept linux-media e devicetree out as I would like to test the patches before expanding the receivers list)

Thanks
j

Jacopo Mondi (2):
arm64: dts: renesas: Add Maxim GMSL expansion board
arm64: dts: renesas: r8a7796=salvator-x: Include GMSL

Laurent Pinchart (1):
dt-bindings: media: i2c: Add bindings for Maxim Integrated MAX9286

Niklas Söderlund (1):
max9286: Add MAX9286 driver

 .../bindings/media/i2c/maxim,max9286.yaml     |  286 +++++
 MAINTAINERS                                   |   10 +
 .../boot/dts/renesas/r8a7795-salvator-x.dts   |    1 +
 .../boot/dts/renesas/salvator-x-max9286.dtsi  |  394 ++++++
 drivers/media/i2c/Kconfig                     |   11 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/max9286.c                   | 1081 +++++++++++++++++
 7 files changed, 1784 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
 create mode 100644 arch/arm64/boot/dts/renesas/salvator-x-max9286.dtsi
 create mode 100644 drivers/media/i2c/max9286.c

--
2.23.0

author maintainer
#1 lore raw

PATCH 1/4 dt-bindings: media: i2c: Add bindings for Maxim Integrated MAX9286

From: Laurent Pinchart <[email protected]>

The MAX9286 deserializes video data received on up to 4 Gigabit Multimedia Serial Links (GMSL) and outputs them on a CSI-2 port using up to 4 data lanes.

---
 .../bindings/media/i2c/maxim,max9286.yaml     | 286 ++++++++++++++++++
 1 file changed, 286 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml new file +286 -0
new file mode 100644
index 000000000000..731e317ef4ce
@@ -0,0 +1,286 @@
+# SPDX-License-Identifier: GPL-2.0-only
+# Copyright (C) 2019 Renesas Electronics Corp.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/i2c/maxim,max9286.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim Integrated Quad GMSL Deserializer
+
+maintainers:
+  - Jacopo Mondi <[email protected]>
+  - Kieran Bingham <[email protected]>
+  - Laurent Pinchart <[email protected]>
+  - Niklas Söderlund <[email protected]>
+
+description: -|
+  The MAX9286 deserializer receives video data on up to 4 Gigabit Multimedia
+  Serial Links (GMSL) and outputs them on a CSI-2 D-PHY port using up to 4 data
+  lanes.
+
+  In addition to video data, the GMSL links carry a bidirectional control
+  channel that encapsulates I2C messages. The MAX9286 forwards all I2C traffic
+  not addressed to itself to the other side of the links, where a GMSL
+  serializer will output it on a local I2C bus. In the other direction all I2C
+  traffic received over GMSL by the MAX9286 is output on the local I2C bus.
+
+properties:
+  '#address-cells':
+    const: 1
+
+  '#size-cells':
+    const: 0
+
+  compatible:
+    const: maxim,max9286
+
+  reg:
+    description: I2C device address
+    maxItems: 1
+
+  poc-supply:
+    description: Regulator providing Power over Coax to the cameras
+    maxItems: 1
+
+  enable-gpios:
+    description: GPIO connected to the \#PWDN pin with inverted polarity
+    maxItems: 1
+
+  ports:
+    type: object
+    description: -|
+      The connections to the MAX9286 GMSL and its endpoint nodes are modelled
+      using the OF graph bindings in accordance with the video interface
+      bindings defined in
+      Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+      The following table lists the port number corresponding to each device
+      port.
+
+        Port            Description
+        ----------------------------------------
+        Port 0          GMSL Input 0
+        Port 1          GMSL Input 1
+        Port 2          GMSL Input 2
+        Port 3          GMSL Input 3
+        Port 4          CSI-2 Output
+
+    properties:
+      '#address-cells':
+        const: 1
+
+      '#size-cells':
+        const: 0
+
+      port@[0-3]:
+        properties:
+          reg:
+            enum: [ 0, 1, 2, 3 ]
+
+          endpoint:
+            type: object
+
+            properties:
+              remote-endpoint:
+                description: -|
+                 phandle to the remote GMSL source endpoint subnode in the
+                 remote node port.
+                maxItems: 1
+
+            required:
+              - remote-endpoint
+
+        required:
+          - reg
+          - endpoint
+
+        additionalProperties: false
+
+      port@4:
+        properties:
+          reg:
+            const: 4
+
+          endpoint:
+            type: object
+
+            properties:
+              remote-endpoint:
+                description: phandle to the remote CSI-2 sink endpoint.
+                maxItems: 1
+
+              data-lanes:
+                description: array of physical CSI-2 data lane indexes.
+
+            required:
+              - remote-endpoint
+              - data-lanes
+
+        required:
+          - reg
+          - endpoint
+
+        additionalProperties: false
+
+    required:
+      - port@4
+
+  i2c-mux:
+    description: -|
+      Each GMSL link is modelled as a child bus of an i2c bus
+      multiplexer/switch, in accordance with bindings described in
+      Documentation/devicetree/bindings/i2c/i2c-mux.txt. The serializer
+      device on the remote end of the GMSL link shall be modelled as a child
+      node of the corresponding I2C bus.
+
+    properties:
+      '#address-cells':
+        const: 1
+
+      '#size-cells':
+        const: 0
+
+  additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - ports
+  - i2c-mux
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    i2c@e66d8000 {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      reg = <0 0xe66d8000 0 0x40>;
+
+      gmsl-deserializer@2c {
+        compatible = "maxim,max9286";
+        reg = <0x2c>;
+        poc-supply = <&camera_poc_12v>;
+        enable-gpios = <&gpio 13 GPIO_ACTIVE_HIGH>;
+
+        ports {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          port@0 {
+            reg = <0>;
+
+            max9286_in0: endpoint {
+              remote-endpoint = <&rdacm20_out0>;
+            };
+          };
+
+          port@1 {
+            reg = <1>;
+
+            max9286_in1: endpoint {
+              remote-endpoint = <&rdacm20_out1>;
+            };
+          };
+
+          port@2 {
+            reg = <2>;
+
+            max9286_in2: endpoint {
+              remote-endpoint = <&rdacm20_out2>;
+            };
+          };
+
+          port@3 {
+            reg = <3>;
+
+            max9286_in3: endpoint {
+              remote-endpoint = <&rdacm20_out3>;
+            };
+          };
+
+          port@4 {
+            reg = <4>;
+
+            max9286_out: endpoint {
+              data-lanes = <1 2 3 4>;
+              remote-endpoint = <&csi40_in>;
+            };
+          };
+        };
+
+        i2c-mux {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          i2c@0 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reg = <0>;
+
+            camera@51 {
+              reg = <0x51>;
+
+              port {
+                rdacm20_out0: endpoint {
+                  remote-endpoint = <&max9286_in0>;
+                };
+              };
+
+            };
+          };
+
+          i2c@1 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <1>;
+
+            camera@52 {
+              reg = <0x52>;
+
+              port {
+                rdacm20_out1: endpoint {
+                  remote-endpoint = <&max9286_in1>;
+                };
+              };
+            };
+          };
+
+          i2c@2 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <2>;
+
+            camera@53 {
+              reg = <0x53>;
+
+              port {
+                rdacm20_out2: endpoint {
+                  remote-endpoint = <&max9286_in2>;
+                };
+              };
+            };
+          };
+
+          i2c@3 {
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <3>;
+
+            camera@54 {
+              reg = <0x54>;
+
+              port {
+                rdacm20_out3: endpoint {
+                  remote-endpoint = <&max9286_in3>;
+                };
+              };
+            };
+          };
+        };
+      };
+    };
Signature · 1 line
2.23.0
author maintainer
#2 lore raw

PATCH 2/4 max9286: Add MAX9286 driver

In reply to Jacopo Mondi

From: Niklas Söderlund <[email protected]>

The MAX9286 is a 4-channel GMSL deserializer with coax or STP input and CSI-2 output. The device supports multicamera streaming applications, and features the ability to synchronise the attached cameras. The driver however limits the number of cameras to one as there are no way to express in V4L2 today that multiple video streams are transmitted over one CSI-2 bus.

CSI-2 output can be configured with 1 to 4 lanes, and a control channel is supported over I2C, which implements an I2C mux to facilitate communications with connected cameras across the reverse control channel.

---
 MAINTAINERS                 |   10 +
 drivers/media/i2c/Kconfig   |   11 +
 drivers/media/i2c/Makefile  |    1 +
 drivers/media/i2c/max9286.c | 1081 +++++++++++++++++++++++++++++++++++
 4 files changed, 1103 insertions(+)
 create mode 100644 drivers/media/i2c/max9286.c
MAINTAINERS +10 -0
index 37a977cbac6f..f463d00d25c2 100644
@@ -9900,6 +9900,16 @@ F:	Documentation/devicetree/bindings/hwmon/max6697.txt
 F:	drivers/hwmon/max6697.c
 F:	include/linux/platform_data/max6697.h
 
+MAX9286 QUAD GMSL DESERIALIZER DRIVER
+M:	Jacopo Mondi <[email protected]>
+M:	Kieran Bingham <[email protected]>
+M:	Laurent Pinchart <[email protected]>
+M:	Niklas Söderlund <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/media/i2c/maxim,max9286.txt
+F:	drivers/media/i2c/max9286.c
+
 MAX9860 MONO AUDIO VOICE CODEC DRIVER
 M:	Peter Rosin <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
drivers/media/i2c/Kconfig +11 -0
index c68e002d26ea..32a4deb90617 100644
@@ -442,6 +442,17 @@ config VIDEO_VPX3220
 	  To compile this driver as a module, choose M here: the
 	  module will be called vpx3220.
 
+config VIDEO_MAX9286
+	tristate "Maxim MAX9286 GMSL deserializer support"
+	depends on I2C && I2C_MUX
+	depends on VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
+	select V4L2_FWNODE
+	help
+	  This driver supports the Maxim MAX9286 GMSL deserializer.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called max9286.
+
 comment "Video and audio decoders"
 
 config VIDEO_SAA717X
drivers/media/i2c/Makefile +1 -0
index c147bb9d28db..8896cf8bfc4f 100644
@@ -117,5 +117,6 @@ obj-$(CONFIG_VIDEO_IMX290)	+= imx290.o
 obj-$(CONFIG_VIDEO_IMX319)	+= imx319.o
 obj-$(CONFIG_VIDEO_IMX355)	+= imx355.o
 obj-$(CONFIG_VIDEO_ST_MIPID02) += st-mipid02.o
+obj-$(CONFIG_VIDEO_MAX9286)	+= max9286.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
drivers/media/i2c/max9286.c new file +1081 -0

1,081 lines not on this page · raw message

Signature · 1 line
2.23.0
author maintainer
#3 lore raw

PATCH 3/4 arm64: dts: renesas: Add Maxim GMSL expansion board

In reply to Jacopo Mondi

Add Maxim MAX9286 expansion board for Salvator-X Renesas board.

This patch updates the salvator-x-max9286.dtsi to comply with the newly defined yaml bindings and its based on Kieran's
"arm64: dts: renesas: salvator-x: Add MAX9286 expansion board" from
git://git.kernel.org/pub/scm/linux/kernel/git/kbingham/rcar.git#gmsl-v5

---
 .../boot/dts/renesas/salvator-x-max9286.dtsi  | 394 ++++++++++++++++++
 1 file changed, 394 insertions(+)
 create mode 100644 arch/arm64/boot/dts/renesas/salvator-x-max9286.dtsi
arch/arm64/boot/dts/renesas/salvator-x-max9286.dtsi new file +394 -0
new file mode 100644
index 000000000000..d9b3edb4ed80
@@ -0,0 +1,394 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Device Tree Source for the Salvator-X MAX9286 expansion board
+ *
+ * Copyright (C) 2017 Ideas on Board <[email protected]>
+ */
+
+#include <dt-bindings/gpio/gpio.h>
+
+/*
+ * MAX9286 A
+ */
+#define MAXIM_CAMERA0 "imi,rdacm20"
+#define MAXIM_CAMERA1 "imi,rdacm20"
+#define MAXIM_CAMERA2 "imi,rdacm20"
+#define MAXIM_CAMERA3 "imi,rdacm20"
+
+/*
+ * MAX9286 B
+ */
+//#define MAXIM_CAMERA4 "imi,rdacm20"
+//#define MAXIM_CAMERA5 "imi,rdacm20"
+//#define MAXIM_CAMERA6 "imi,rdacm20"
+//#define MAXIM_CAMERA7 "imi,rdacm20"
+
+/ {
+/*
+ * Powered MCU IMI cameras need delay between power-on and R-Car access
+ * to avoid I2C bus conflicts since the R-Car I2C does not support I2C
+ * multi-master. The I2C bus conflict would result in R-Car I2C IP stall.
+ */
+#define IMI_MCU_V0_DELAY	8000000	/* delay for powered MCU firmware v0 */
+#define IMI_MCU_V1_DELAY	3000000	/* delay for powered MCU firmware v1 */
+#define IMI_MCU_NO_DELAY	0	/* delay for unpowered MCU  */
+#define IMI_MCU_DELAY		IMI_MCU_V0_DELAY
+
+	poc_12v: regulator-vcc-poc-12v {
+		compatible = "regulator-fixed";
+
+		regulator-name = "Camera PoC 12V";
+		regulator-min-microvolt = <12000000>;
+		regulator-max-microvolt = <12000000>;
+		startup-delay-us = <(250000 + IMI_MCU_DELAY)>;
+
+		gpio = <&gpio6 30 GPIO_ACTIVE_HIGH>;
+		enable-active-high;
+	};
+};
+
+&vin0 {
+	status = "okay";
+};
+
+&vin1 {
+	status = "okay";
+};
+
+&vin2 {
+	status = "okay";
+};
+
+&vin3 {
+	status = "okay";
+};
+
+&vin4 {
+	status = "okay";
+};
+
+&vin5 {
+	status = "okay";
+};
+
+&vin6 {
+	status = "okay";
+};
+
+&vin7 {
+	status = "okay";
+};
+
+/* Disconnect the csi40 endpoint from the ADV748x TXA (HDMI) */
+&adv7482_txa {
+	/delete-property/ remote-endpoint;
+	status = "disabled";
+};
+
+&csi40 {
+	status = "okay";
+
+	ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		port@0 {
+			reg = <0>;
+
+			csi40_in: endpoint {
+				clock-lanes = <0>;
+				data-lanes = <1 2 3 4>;
+				remote-endpoint = <&max9286_out0>;
+			};
+		};
+	};
+};
+
+&csi41 {
+	status = "okay";
+
+	ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		port@0 {
+			reg = <0>;
+
+			csi41_in: endpoint {
+				clock-lanes = <0>;
+				data-lanes = <1 2 3 4>;
+				remote-endpoint = <&max9286_out1>;
+			};
+		};
+	};
+};
+
+&i2c4 {
+	gmsl-deserializer@4c {
+		compatible = "maxim,max9286";
+		reg = <0x4c>;
+		poc-supply = <&poc_12v>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				max9286_in0: endpoint {
+#ifdef MAXIM_CAMERA0
+					remote-endpoint = <&rdacm20_out0>;
+#endif
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				max9286_in1: endpoint {
+#ifdef MAXIM_CAMERA1
+					remote-endpoint = <&rdacm20_out1>;
+#endif
+				};
+			};
+
+			port@2 {
+				reg = <2>;
+				max9286_in2: endpoint {
+#ifdef MAXIM_CAMERA2
+					remote-endpoint = <&rdacm20_out2>;
+#endif
+				};
+			};
+
+			port@3 {
+				reg = <3>;
+				max9286_in3: endpoint {
+#ifdef MAXIM_CAMERA3
+					remote-endpoint = <&rdacm20_out3>;
+#endif
+				};
+			};
+
+			port@4 {
+				reg = <4>;
+				max9286_out0: endpoint {
+					clock-lanes = <0>;
+					data-lanes = <1 2 3 4>;
+					remote-endpoint = <&csi40_in>;
+				};
+			};
+		};
+
+		i2c-mux {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			i2c@0 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0>;
+
+#ifdef MAXIM_CAMERA0
+				camera@31 {
+					compatible = MAXIM_CAMERA0;
+					reg = <0x31 0x41 0x51>;
+
+					port {
+						rdacm20_out0: endpoint {
+							remote-endpoint = <&max9286_in0>;
+						};
+					};
+
+				};
+#endif
+			};
+
+			i2c@1 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <1>;
+
+#ifdef MAXIM_CAMERA1
+				camera@32 {
+					compatible = MAXIM_CAMERA1;
+					reg = <0x32 0x42 0x52>;
+					port {
+						rdacm20_out1: endpoint {
+							remote-endpoint = <&max9286_in1>;
+						};
+					};
+				};
+#endif
+			};
+
+			i2c@2 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <2>;
+
+#ifdef MAXIM_CAMERA2
+				camera@33 {
+					compatible = MAXIM_CAMERA2;
+					reg = <0x33 0x43 0x53>;
+					port {
+						rdacm20_out2: endpoint {
+							remote-endpoint = <&max9286_in2>;
+						};
+					};
+				};
+#endif
+			};
+
+			i2c@3 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <3>;
+
+#ifdef MAXIM_CAMERA3
+				camera@34 {
+					compatible = MAXIM_CAMERA3;
+					reg = <0x34 0x44 0x54>;
+					port {
+						rdacm20_out3: endpoint {
+							remote-endpoint = <&max9286_in3>;
+						};
+					};
+				};
+#endif
+			};
+		};
+	};
+
+	gmsl-deserializer@6c {
+		compatible = "maxim,max9286";
+		reg = <0x6c>;
+		poc-supply = <&poc_12v>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				max9286_in4: endpoint {
+#ifdef MAXIM_CAMERA4
+					remote-endpoint = <&rdacm20_out4>;
+#endif
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				max9286_in5: endpoint {
+#ifdef MAXIM_CAMERA5
+					remote-endpoint = <&rdacm20_out5>;
+#endif
+				};
+			};
+
+			port@2 {
+				reg = <2>;
+				max9286_in6: endpoint {
+#ifdef MAXIM_CAMERA6
+					remote-endpoint = <&rdacm20_out6>;
+#endif
+				};
+			};
+
+			port@3 {
+				reg = <3>;
+				max9286_in7: endpoint {
+#ifdef MAXIM_CAMERA7
+					remote-endpoint = <&rdacm20_out7>;
+#endif
+				};
+			};
+
+			port@4 {
+				reg = <4>;
+				max9286_out1: endpoint {
+					clock-lanes = <0>;
+					data-lanes = <1 2 3 4>;
+					remote-endpoint = <&csi41_in>;
+				};
+			};
+		};
+
+		i2c-mux {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			i2c@0 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0>;
+
+#ifdef MAXIM_CAMERA4
+				camera@35 {
+					compatible = MAXIM_CAMERA4;
+					reg = <0x35 0x45 0x55>;
+					port {
+						rdacm20_out4: endpoint {
+							remote-endpoint = <&max9286_in4>;
+						};
+					};
+				};
+#endif
+			};
+
+			i2c@1 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <1>;
+
+#ifdef MAXIM_CAMERA5
+				camera@36 {
+					compatible = MAXIM_CAMERA5;
+					reg = <0x36 0x46 0x56>;
+					port {
+						rdacm20_out5: endpoint {
+							remote-endpoint = <&max9286_in5>;
+						};
+					};
+				};
+#endif
+			};
+
+			i2c@2 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <2>;
+
+#ifdef MAXIM_CAMERA6
+				camera@37 {
+					compatible = MAXIM_CAMERA6;
+					reg = <0x37 0x47 0x57>;
+					port {
+						rdacm20_out6: endpoint {
+							remote-endpoint = <&max9286_in6>;
+						};
+					};
+				};
+#endif
+			};
+
+			i2c@3 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <3>;
+
+#ifdef MAXIM_CAMERA7
+				camera@38 {
+					compatible = MAXIM_CAMERA7;
+					reg = <0x38 0x48 0x58>;
+					port {
+						rdacm20_out7: endpoint {
+							remote-endpoint = <&max9286_in7>;
+						};
+					};
+				};
+#endif
+			};
+		};
+	};
+};
Signature · 1 line
2.23.0
author maintainer
#4 lore raw

PATCH 4/4 arm64: dts: renesas: r8a7796=salvator-x: Include GMSL

In reply to Jacopo Mondi

Include the Maxim GMSL expansion board DTSi for M3-W Salvator-x board.

---
 arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts +1 -0
index 72874f675359..3f523c52c2b8 100644
@@ -155,3 +155,4 @@
 
 	status = "okay";
 };
+#include "salvator-x-max9286.dtsi"
Signature · 1 line
2.23.0
#5 lore raw

Re: [RFT 4/4] arm64: dts: renesas: r8a7796=salvator-x: Include GMSL

Hi Jacopo,

Quoted 1 line · Jacopo Mondi

Include the Maxim GMSL expansion board DTSi for M3-W Salvator-x board.

This and subject says M3-W...

Quoted 3 lines
---
 arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts | 1 +

... but this is for the (rare) combination of Salvator-X and H3 ES2.0?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
maintainer
#6 lore raw
In reply to Jacopo Mondi

Hi Jacopo,

Thanks for this refresh. The key part here is the refresh of the V4L2-Mux series, which is what had previously blocked the GMSL series.

Will you post/publish the vl42-mux series on the linux-media mailinglist?

I know there are other interested parties who are looking at such topics
- so highlighting the latest version might be beneficial to promoting discussions.

Quoted 21 lines · Jacopo Mondi

Hello this is refersh of our GMSL work.

Current situation is the following:
- Kieran sent a full v4 with multiplexed stream support and has a v5 branch in his repository with v4 review comment fixes on top

I rebased the multiplexed stream's series on latest media-master
https://jmondi.org/cgit/linux/log/?h=v4l2-mux/media-master/v6

On top of that I took Kieran's v5 and re-applied on top:
https://jmondi.org/cgit/linux/log/?h=jmondi/gmsl/kieran/v6

- Niklas sent a v1 (which sould have been a v5) which removes multiplexed streams and only support one camera and was meant for inclusion but is still floating around in linux-media, mostly because some of the comments on Kieran's v4 still applied there, if I'm not mistaken.

I took Niklas' single stream max9286 and replaced the original bindings with a json-schema version
https://jmondi.org/cgit/linux/log/?h=jmondi/gmsl/niklas/v6

Quoted 5 lines

I bumped all versions to v6 to avoid further confusion.

Not having a working GMSL setup I would ask to Kieran or Niklas to test this version so that we can try re-send the single stream max9286 version with new yaml bindings for inclusion.

Thanks, I can confirm that the rebase to current master was successful (based on your branch with the version of patches based on my gmsl/v5)

As we now have two forks of the GMSL I'm going to rebase these such that the separation between current topics is clear:

- MAX9286 with support for a single camera (and only a single MAX9286)
- This we could/should hope to get upstream
- MAX9286 VC support
- (requires the V4L2-Mux support of course)
- MAX9286 dual device workaround (not suitable for upstream currently)
- Required to function on the Salvator-XS GMSL board.

Once I've done (and tested this) I'll make a new posting (should we call this v6? or v6.1?)

In the meantime, I will not be making changes to the RDACM20, so if you wish to get started investigating the separation topic here - then I don't think you are blocked on me.

--
Regards

Kieran

Quoted 31 lines

(I kept linux-media e devicetree out as I would like to test the patches before expanding the receivers list)

Thanks
j

Jacopo Mondi (2):
arm64: dts: renesas: Add Maxim GMSL expansion board
arm64: dts: renesas: r8a7796=salvator-x: Include GMSL

Laurent Pinchart (1):
dt-bindings: media: i2c: Add bindings for Maxim Integrated MAX9286

Niklas Söderlund (1):
max9286: Add MAX9286 driver

 .../bindings/media/i2c/maxim,max9286.yaml     |  286 +++++
 MAINTAINERS                                   |   10 +
 .../boot/dts/renesas/r8a7795-salvator-x.dts   |    1 +
 .../boot/dts/renesas/salvator-x-max9286.dtsi  |  394 ++++++
 drivers/media/i2c/Kconfig                     |   11 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/max9286.c                   | 1081 +++++++++++++++++
 7 files changed, 1784 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
 create mode 100644 arch/arm64/boot/dts/renesas/salvator-x-max9286.dtsi
 create mode 100644 drivers/media/i2c/max9286.c

--
2.23.0

#7 lore raw

Hi Kieran,

Quoted 6 lines · Kieran Bingham

Hi Jacopo,

Thanks for this refresh. The key part here is the refresh of the V4L2-Mux series, which is what had previously blocked the GMSL series.

Will you post/publish the vl42-mux series on the linux-media mailinglist?

I considered that, but we already know that series is not meant to go far, so I could just as reference...

Quoted 5 lines

I know there are other interested parties who are looking at such topics
- so highlighting the latest version might be beneficial to promoting discussions.

Might be, yes...

Quoted 23 lines · Jacopo Mondi
Quoted 21 lines

Hello this is refersh of our GMSL work.

Current situation is the following:
- Kieran sent a full v4 with multiplexed stream support and has a v5 branch in his repository with v4 review comment fixes on top

I rebased the multiplexed stream's series on latest media-master
https://jmondi.org/cgit/linux/log/?h=v4l2-mux/media-master/v6

On top of that I took Kieran's v5 and re-applied on top:
https://jmondi.org/cgit/linux/log/?h=jmondi/gmsl/kieran/v6

- Niklas sent a v1 (which sould have been a v5) which removes multiplexed streams and only support one camera and was meant for inclusion but is still floating around in linux-media, mostly because some of the comments on Kieran's v4 still applied there, if I'm not mistaken.

I took Niklas' single stream max9286 and replaced the original bindings with a json-schema version
https://jmondi.org/cgit/linux/log/?h=jmondi/gmsl/niklas/v6

Quoted 9 lines
Quoted 5 lines

I bumped all versions to v6 to avoid further confusion.

Not having a working GMSL setup I would ask to Kieran or Niklas to test this version so that we can try re-send the single stream max9286 version with new yaml bindings for inclusion.

Thanks, I can confirm that the rebase to current master was successful (based on your branch with the version of patches based on my gmsl/v5)

Great! Thanks for testing!

Quoted 11 lines

As we now have two forks of the GMSL I'm going to rebase these such that the separation between current topics is clear:

- MAX9286 with support for a single camera (and only a single MAX9286)
- This we could/should hope to get upstream
- MAX9286 VC support
- (requires the V4L2-Mux support of course)
- MAX9286 dual device workaround (not suitable for upstream currently)
- Required to function on the Salvator-XS GMSL board.

Quoted 2 lines

Once I've done (and tested this) I'll make a new posting (should we call this v6? or v6.1?)

I think you can keep v6, as this one is RFT..

Quoted 6 lines

In the meantime, I will not be making changes to the RDACM20, so if you wish to get started investigating the separation topic here - then I don't think you are blocked on me.

I think this will need a bit more thoughts... Separating max9271 and ov10653 might be trivial, as the only action the current rdacm20 driver does on the sensor is an initial configuration with a set of register-value entries. It's a bit more work to properly define the data connection in DT and setting up a sub-notifier in the serializer driver, but that's totally feasible...

Although, as Laurent pointed out we have a uController in the camera module, regulators (iirc) etc, and so it makes sense to keep a single rdacm20 driver, breaking out the serializer driver code into a re-usable library instead of making a proper driver out of it.

What's your opinion on this ?

Thanks
j

Quoted 40 lines

--
Regards

Kieran

Quoted 31 lines

(I kept linux-media e devicetree out as I would like to test the patches before expanding the receivers list)

Thanks
j

Jacopo Mondi (2):
arm64: dts: renesas: Add Maxim GMSL expansion board
arm64: dts: renesas: r8a7796=salvator-x: Include GMSL

Laurent Pinchart (1):
dt-bindings: media: i2c: Add bindings for Maxim Integrated MAX9286

Niklas Söderlund (1):
max9286: Add MAX9286 driver

 .../bindings/media/i2c/maxim,max9286.yaml     |  286 +++++
 MAINTAINERS                                   |   10 +
 .../boot/dts/renesas/r8a7795-salvator-x.dts   |    1 +
 .../boot/dts/renesas/salvator-x-max9286.dtsi  |  394 ++++++
 drivers/media/i2c/Kconfig                     |   11 +
 drivers/media/i2c/Makefile                    |    1 +
 drivers/media/i2c/max9286.c                   | 1081 +++++++++++++++++
 7 files changed, 1784 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml
 create mode 100644 arch/arm64/boot/dts/renesas/salvator-x-max9286.dtsi
 create mode 100644 drivers/media/i2c/max9286.c

--
2.23.0

#8 lore raw

PATCH 1/1 max9286: simplify i2c-mux parsing

In reply to Jacopo Mondi

- Identify each enabled i2c-mux channel in a single pass

The parse_dt function iterates each node in the i2c-mux for each endpoint looking for a match. The only purpose of these iterations is to determine if the corresponding i2c-channel is enabled. (status = 'okay').

Iterate the i2c-mux nodes in a single pass storing the enable state in a local i2c_mux_mask for use when parsing the endpoints.

---
 drivers/media/i2c/max9286.c | 84 +++++++++++++++----------------------
 1 file changed, 34 insertions(+), 50 deletions(-)
drivers/media/i2c/max9286.c +34 -50
index 34cb6f3b40c2..a36132becdc7 100644
@@ -1097,55 +1097,6 @@ static int max9286_is_bound(struct device *dev, void *data)
 	return 0;
 }
 
-static struct device_node *max9286_get_i2c_by_id(struct device_node *parent,
-						 u32 id)
-{
-	struct device_node *i2c_mux;
-	struct device_node *child;
-
-	/* Balance the of_node_put() performed by of_find_node_by_name() */
-	of_node_get(parent);
-
-	i2c_mux = of_find_node_by_name(parent, "i2c-mux");
-	if (!i2c_mux) {
-		printk("max9286: Failed to find i2c-mux node\n");
-		return NULL;
-	}
-
-	for_each_child_of_node(i2c_mux, child) {
-		u32 i2c_id = 0;
-
-		if (of_node_cmp(child->name, "i2c") != 0)
-			continue;
-		of_property_read_u32(child, "reg", &i2c_id);
-		if (id == i2c_id)
-			return child;
-	}
-
-	return NULL;
-}
-
-static int max9286_check_i2c_bus_by_id(struct device *dev, int id)
-{
-	struct device_node *i2c_np;
-
-	i2c_np = max9286_get_i2c_by_id(dev->of_node, id);
-	if (!i2c_np) {
-		dev_err(dev, "Failed to find corresponding i2c@%u\n", id);
-		return -ENODEV;
-	}
-
-	if (!of_device_is_available(i2c_np)) {
-		dev_dbg(dev, "Skipping port %u with disabled I2C bus\n", id);
-		of_node_put(i2c_np);
-		return -ENODEV;
-	}
-
-	of_node_put(i2c_np);
-
-	return 0;
-}
-
 static void max9286_cleanup_dt(struct max9286_priv *priv)
 {
 	struct max9286_source *source;
@@ -1167,11 +1118,44 @@ static void max9286_cleanup_dt(struct max9286_priv *priv)
 static int max9286_parse_dt(struct max9286_priv *priv)
 {
 	struct device *dev = &priv->client->dev;
+	struct device_node *i2c_mux;
+	struct device_node *child = NULL;
 	struct device_node *ep_np = NULL;
+	unsigned int i2c_mux_mask = 0;
 	int ret;
 
+	/* Balance the of_node_put() performed by of_find_node_by_name() */
+	of_node_get(dev->of_node);
+	i2c_mux = of_find_node_by_name(dev->of_node, "i2c-mux");
+	if (!i2c_mux) {
+		dev_err(dev, "Failed to find i2c-mux node\n");
+		return -EINVAL;
+	}
+
+	/* Identify which i2c-mux channels are enabled */
+	for_each_child_of_node(i2c_mux, child) {
+		u32 id = 0;
+
+		if (of_node_cmp(child->name, "i2c") != 0)
+			continue;
+
+		of_property_read_u32(child, "reg", &id);
+		if (id >= MAX9286_NUM_GMSL)
+			continue;
+
+		if (!of_device_is_available(child)) {
+			dev_dbg(dev, "Skipping port %u with disabled I2C bus\n", id);
+			continue;
+		}
+
+		i2c_mux_mask |= BIT(id);
+	}
+	of_node_put(child);
+	of_node_put(i2c_mux);
+
 	v4l2_async_notifier_init(&priv->notifier);
 
+	/* Parse the endpoints */
 	for_each_endpoint_of_node(dev->of_node, ep_np) {
 		struct max9286_source *source;
 		struct of_endpoint ep;
@@ -1214,7 +1198,7 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 		}
 
 		/* Skip if the corresponding GMSL link is unavailable. */
-		if (max9286_check_i2c_bus_by_id(dev, ep.port))
+		if (!(i2c_mux_mask & BIT(ep.port)))
 			continue;
 
 		if (priv->sources[ep.port].fwnode) {
Signature · 1 line
2.20.1
#9 lore raw

Re: [PATCH] max9286: simplify i2c-mux parsing

Hi Kieran,

Quoted 9 lines · Kieran Bingham

- Identify each enabled i2c-mux channel in a single pass

The parse_dt function iterates each node in the i2c-mux for each endpoint looking for a match. The only purpose of these iterations is to determine if the corresponding i2c-channel is enabled. (status = 'okay').

Iterate the i2c-mux nodes in a single pass storing the enable state in a local i2c_mux_mask for use when parsing the endpoints.

I very much agree with this :)

Quoted 66 lines
---
 drivers/media/i2c/max9286.c | 84 +++++++++++++++----------------------
 1 file changed, 34 insertions(+), 50 deletions(-)
drivers/media/i2c/max9286.c +0 -49
index 34cb6f3b40c2..a36132becdc7 100644
@@ -1097,55 +1097,6 @@ static int max9286_is_bound(struct device *dev, void *data)
 	return 0;
 }
 
-static struct device_node *max9286_get_i2c_by_id(struct device_node *parent,
-						 u32 id)
-{
-	struct device_node *i2c_mux;
-	struct device_node *child;
-
-	/* Balance the of_node_put() performed by of_find_node_by_name() */
-	of_node_get(parent);
-
-	i2c_mux = of_find_node_by_name(parent, "i2c-mux");
-	if (!i2c_mux) {
-		printk("max9286: Failed to find i2c-mux node\n");
-		return NULL;
-	}
-
-	for_each_child_of_node(i2c_mux, child) {
-		u32 i2c_id = 0;
-
-		if (of_node_cmp(child->name, "i2c") != 0)
-			continue;
-		of_property_read_u32(child, "reg", &i2c_id);
-		if (id == i2c_id)
-			return child;
-	}
-
-	return NULL;
-}
-
-static int max9286_check_i2c_bus_by_id(struct device *dev, int id)
-{
-	struct device_node *i2c_np;
-
-	i2c_np = max9286_get_i2c_by_id(dev->of_node, id);
-	if (!i2c_np) {
-		dev_err(dev, "Failed to find corresponding i2c@%u\n", id);
-		return -ENODEV;
-	}
-
-	if (!of_device_is_available(i2c_np)) {
-		dev_dbg(dev, "Skipping port %u with disabled I2C bus\n", id);
-		of_node_put(i2c_np);
-		return -ENODEV;
-	}
-
-	of_node_put(i2c_np);
-
-	return 0;
-}
-
 static void max9286_cleanup_dt(struct max9286_priv *priv)
 {
 	struct max9286_source *source;

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1123

Quoted 6 lines
drivers/media/i2c/max9286.c +2 -0
@@ -1167,11 +1118,44 @@ static void max9286_cleanup_dt(struct max9286_priv *priv)
 static int max9286_parse_dt(struct max9286_priv *priv)
 {
 	struct device *dev = &priv->client->dev;
+	struct device_node *i2c_mux;
+	struct device_node *child = NULL;
 	struct device_node *ep_np = NULL;

Nit: could you re-use child or ep_np ?

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1127

Quoted 4 lines
drivers/media/i2c/max9286.c +2 -0
+	unsigned int i2c_mux_mask = 0;
 	int ret;
 
+	/* Balance the of_node_put() performed by of_find_node_by_name() */

Do you need this comment ?

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1140

Quoted 13 lines
drivers/media/i2c/max9286.c +13 -0
+	of_node_get(dev->of_node);
+	i2c_mux = of_find_node_by_name(dev->of_node, "i2c-mux");
+	if (!i2c_mux) {
+		dev_err(dev, "Failed to find i2c-mux node\n");
+		return -EINVAL;
+	}
+
+	/* Identify which i2c-mux channels are enabled */
+	for_each_child_of_node(i2c_mux, child) {
+		u32 id = 0;
+
+		if (of_node_cmp(child->name, "i2c") != 0)
+			continue;

With the new bindings in yaml format and the associated verification, this should not happen.

Quoted 9 lines
drivers/media/i2c/max9286.c +9 -0
+
+		of_property_read_u32(child, "reg", &id);
+		if (id >= MAX9286_NUM_GMSL)
+			continue;
+
+		if (!of_device_is_available(child)) {
+			dev_dbg(dev, "Skipping port %u with disabled I2C bus\n", id);
+			continue;
+		}

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1159

Quoted 10 lines
drivers/media/i2c/max9286.c +7 -0
+
+		i2c_mux_mask |= BIT(id);
+	}
+	of_node_put(child);
+	of_node_put(i2c_mux);
+
 	v4l2_async_notifier_init(&priv->notifier);
 
+	/* Parse the endpoints */
 	for_each_endpoint_of_node(dev->of_node, ep_np) {

dev->of_node is reused here, do you need to get it again ?

All minors though, squash this on the next max9286 submission if you feel to.

Thanks
j

Quoted 14 lines
drivers/media/i2c/max9286.c +1 -2
 		struct max9286_source *source;
 		struct of_endpoint ep;
@@ -1214,7 +1198,7 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 		}
 
 		/* Skip if the corresponding GMSL link is unavailable. */
-		if (max9286_check_i2c_bus_by_id(dev, ep.port))
+		if (!(i2c_mux_mask & BIT(ep.port)))
 			continue;
 
 		if (priv->sources[ep.port].fwnode) {
--

2.20.1

#10 lore raw

Re: [PATCH] max9286: simplify i2c-mux parsing

Hi Jacopo,

Quoted 9 lines · Jacopo Mondi

Hi Kieran,

Quoted 6 lines · Kieran Bingham

- Identify each enabled i2c-mux channel in a single pass

The parse_dt function iterates each node in the i2c-mux for each endpoint looking for a match. The only purpose of these iterations is to determine if the corresponding i2c-channel is enabled. (status = 'okay').

Quoted 5 lines
Quoted 3 lines

Iterate the i2c-mux nodes in a single pass storing the enable state in a local i2c_mux_mask for use when parsing the endpoints.

I very much agree with this :)

Great,

Quoted 67 lines
Quoted 67 lines
---
 drivers/media/i2c/max9286.c | 84 +++++++++++++++----------------------
 1 file changed, 34 insertions(+), 50 deletions(-)
drivers/media/i2c/max9286.c +0 -49
index 34cb6f3b40c2..a36132becdc7 100644
@@ -1097,55 +1097,6 @@ static int max9286_is_bound(struct device *dev, void *data)
 	return 0;
 }
 
-static struct device_node *max9286_get_i2c_by_id(struct device_node *parent,
-						 u32 id)
-{
-	struct device_node *i2c_mux;
-	struct device_node *child;
-
-	/* Balance the of_node_put() performed by of_find_node_by_name() */
-	of_node_get(parent);
-
-	i2c_mux = of_find_node_by_name(parent, "i2c-mux");
-	if (!i2c_mux) {
-		printk("max9286: Failed to find i2c-mux node\n");
-		return NULL;
-	}
-
-	for_each_child_of_node(i2c_mux, child) {
-		u32 i2c_id = 0;
-
-		if (of_node_cmp(child->name, "i2c") != 0)
-			continue;
-		of_property_read_u32(child, "reg", &i2c_id);
-		if (id == i2c_id)
-			return child;
-	}
-
-	return NULL;
-}
-
-static int max9286_check_i2c_bus_by_id(struct device *dev, int id)
-{
-	struct device_node *i2c_np;
-
-	i2c_np = max9286_get_i2c_by_id(dev->of_node, id);
-	if (!i2c_np) {
-		dev_err(dev, "Failed to find corresponding i2c@%u\n", id);
-		return -ENODEV;
-	}
-
-	if (!of_device_is_available(i2c_np)) {
-		dev_dbg(dev, "Skipping port %u with disabled I2C bus\n", id);
-		of_node_put(i2c_np);
-		return -ENODEV;
-	}
-
-	of_node_put(i2c_np);
-
-	return 0;
-}
-
 static void max9286_cleanup_dt(struct max9286_priv *priv)
 {
 	struct max9286_source *source;
@@ -1167,11 +1118,44 @@ static void max9286_cleanup_dt(struct max9286_priv *priv)
Quoted 8 lines

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1123

Quoted 6 lines
drivers/media/i2c/max9286.c +2 -0
 static int max9286_parse_dt(struct max9286_priv *priv)
 {
 	struct device *dev = &priv->client->dev;
+	struct device_node *i2c_mux;
+	struct device_node *child = NULL;
 	struct device_node *ep_np = NULL;

Nit: could you re-use child or ep_np ?

Yes, that would reduce local vars. I'll do this now.

Quoted 7 lines

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1127

Quoted 5 lines
drivers/media/i2c/max9286.c +2 -0
+	unsigned int i2c_mux_mask = 0;
 	int ret;
 
+	/* Balance the of_node_put() performed by of_find_node_by_name() */

Do you need this comment ?

It was non-obvious to me at least when I added it /why/ I had to get it. But perhaps now I've got further along, it's more clear why.

DT references are a pain :-D
Lots of places where they are implicitly reduced in loops etc..

Quoted 8 lines
Quoted 8 lines
drivers/media/i2c/max9286.c +8 -0
+	of_node_get(dev->of_node);
+	i2c_mux = of_find_node_by_name(dev->of_node, "i2c-mux");
+	if (!i2c_mux) {
+		dev_err(dev, "Failed to find i2c-mux node\n");
+		return -EINVAL;
+	}
+
+	/* Identify which i2c-mux channels are enabled */
Quoted 8 lines

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1140

Quoted 5 lines
drivers/media/i2c/max9286.c +5 -0
+	for_each_child_of_node(i2c_mux, child) {
+		u32 id = 0;
+
+		if (of_node_cmp(child->name, "i2c") != 0)
+			continue;

With the new bindings in yaml format and the associated verification, this should not happen.

Aha, yes I think you're right - well in that case I'm happy to drop it, and simplify the code.

Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/max9286.c +15 -0
+
+		of_property_read_u32(child, "reg", &id);
+		if (id >= MAX9286_NUM_GMSL)
+			continue;
+
+		if (!of_device_is_available(child)) {
+			dev_dbg(dev, "Skipping port %u with disabled I2C bus\n", id);
+			continue;
+		}
+
+		i2c_mux_mask |= BIT(id);
+	}
+	of_node_put(child);
+	of_node_put(i2c_mux);
+
 	v4l2_async_notifier_init(&priv->notifier);
 
Quoted 4 lines

drivers/media/i2c/max9286.c static void max9286_cleanup_dt(struct max9286_priv *priv) · line 1159

Quoted 2 lines
drivers/media/i2c/max9286.c +1 -0
+	/* Parse the endpoints */
 	for_each_endpoint_of_node(dev->of_node, ep_np) {

dev->of_node is reused here, do you need to get it again ?

Urggh, no idea ... I'll investigate.
The earlier one crashed on me, this one did not ... but better to get it 'right'.

Quoted 2 lines

All minors though, squash this on the next max9286 submission if you feel to.

Thanks.

--
Kieran

Quoted 18 lines

Thanks
j

Quoted 14 lines
drivers/media/i2c/max9286.c +1 -2
 		struct max9286_source *source;
 		struct of_endpoint ep;
@@ -1214,7 +1198,7 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 		}
 
 		/* Skip if the corresponding GMSL link is unavailable. */
-		if (max9286_check_i2c_bus_by_id(dev, ep.port))
+		if (!(i2c_mux_mask & BIT(ep.port)))
 			continue;
 
 		if (priv->sources[ep.port].fwnode) {
--

2.20.1

Signature · 3 lines
Regards
--
Kieran
#11 lore raw

PATCH 1/1 max9286: Improve mux-state readbility

In reply to Jacopo Mondi

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted ith a FIXME and is difficult to interpret the meaning of the values 0, 1, 2.

Introduce an enum to declare the intent of each state, and comment the states accordingly.

This state transition is only needed for the multi-channel support, and will not be included in the single-channel max9286 posting.

---
 drivers/media/i2c/max9286.c | 63 +++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)
drivers/media/i2c/max9286.c +40 -23
index eed00ff1dee4..a9c3e7411bda 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,16 +221,39 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
+enum max9286_i2c_mux_state {
+	/*
+	 * The I2C Mux will enable only a single channel (both forward, and
+	 * reverse) at a time, and to reduce I2C bus bandwidth, it will only
+	 * reconfigure the channel when a write is requested to a different
+	 * channel.
+	 */
+	MAX9286_I2C_MUX_STATE_CHANNEL = 0,
+
+	/*
+	 * The I2C mux will be configured with all ports open. All I2C writes
+	 * will be transmitted to all remote I2C devices, and where multiple
+	 * devices have the same address, the write will be received by all of
+	 * them.
+	 */
+	MAX9286_I2C_MUX_STATE_OPEN,
+
+	/*
+	 * The I2C mux is configured with all ports open.
+	 *
+	 * No reconfiguration of the I2C mux channel select is required.
+	 */
+	MAX9286_I2C_MUX_STATE_DISABLE_SELECT,
+};
+
 static int max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
-	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * mux, and that the channel state and ID is invalidated to ensure we
+	 * reconfigure on the next max9286_i2c_mux_select() call.
 	 */
+	priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;
 	priv->mux_channel = -1;
 	max9286_write(priv, 0x0a, 0x00);
 	usleep_range(3000, 5000);
@@ -242,23 +265,19 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
+	/* channel select is disabled when configured in the opened state. */
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_DISABLE_SELECT)
 		return 0;
-	} else if (priv->streaming == 2) {
+
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_OPEN) {
+		/* Open all channels on the MAX9286 */
+		max9286_write(priv, 0x0a, 0xff);
+		priv->mux_state = MAX9286_I2C_MUX_STATE_DISABLE_SELECT;
 		return 0;
 	}
 
+	/* Handling for MAX9286_I2C_MUX_STATE_CHANNEL */
+
 	if (priv->mux_channel == chan)
 		return 0;
 
@@ -441,8 +460,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_OPEN;
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +508,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;
 	}
 
 	return 0;
Signature · 1 line
2.20.1
#12 lore raw

Re: [PATCH] max9286: Improve mux-state readbility

Hi Kieran,

Quoted 6 lines · Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted ith a FIXME and is difficult to interpret the meaning of the

s/ith/with

Quoted 27 lines

values 0, 1, 2.

Introduce an enum to declare the intent of each state, and comment the states accordingly.

This state transition is only needed for the multi-channel support, and will not be included in the single-channel max9286 posting.

---
 drivers/media/i2c/max9286.c | 63 +++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)
drivers/media/i2c/max9286.c +1 -1
index eed00ff1dee4..a9c3e7411bda 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 224

Quoted 4 lines
drivers/media/i2c/max9286.c +1 -0
@@ -221,16 +221,39 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
+enum max9286_i2c_mux_state {

Let the bikeshedding begin here

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 226

Quoted 2 lines
drivers/media/i2c/max9286.c +2 -0
+	/*
+	 * The I2C Mux will enable only a single channel (both forward, and

s/Mux/mux

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 229

Quoted 3 lines
drivers/media/i2c/max9286.c +3 -0
+	 * reverse) at a time, and to reduce I2C bus bandwidth, it will only
+	 * reconfigure the channel when a write is requested to a different
+	 * channel.

I won't here explain what a mux channel select does

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 231

Quoted 2 lines
drivers/media/i2c/max9286.c +2 -0
+	 */
+	MAX9286_I2C_MUX_STATE_CHANNEL = 0,

To me, this should be the initial state of the mux, where all channels are closed.

The state machine to me should look like:

        init() -> i2c_mux_close() -> mux_state = CLOSED;
        all transaction selects/deselect a single channel

        s_stream(1) -> mux_state = REQUEST_OPEN
        first transaction opens all channels -> mux_state = OPEN
        all successive transactions with (mux_state = OPEN) are nop

        s_stream(0) -> i2c_mux_close() -> mux_state = CLOSED
        all transaction selects/deselect a single channel until next s_stream(1)

For this state I propose MAX9286_I2C_MUX_STATE_CLOSED

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 239

Quoted 8 lines
drivers/media/i2c/max9286.c +8 -0
+
+	/*
+	 * The I2C mux will be configured with all ports open. All I2C writes
+	 * will be transmitted to all remote I2C devices, and where multiple
+	 * devices have the same address, the write will be received by all of
+	 * them.
+	 */
+	MAX9286_I2C_MUX_STATE_OPEN,

I propose MAX9286_I2C_MUX_STATE_REQUEST_OPEN

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 246

Quoted 7 lines
drivers/media/i2c/max9286.c +7 -0
+
+	/*
+	 * The I2C mux is configured with all ports open.
+	 *
+	 * No reconfiguration of the I2C mux channel select is required.
+	 */
+	MAX9286_I2C_MUX_STATE_DISABLE_SELECT,

I propose MAX9286_I2C_MUX_STATE_OPEN

Could all these be shorten to MAX9286_MUX_.... ?

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 228

Quoted 7 lines
drivers/media/i2c/max9286.c +2 -3
+};
+
 static int max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;

I don't get why we had this one here. Do you agree it was not necessary ? I guess so, since you dropped it...

Quoted 18 lines
drivers/media/i2c/max9286.c +3 -5
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
-	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * mux, and that the channel state and ID is invalidated to ensure we
+	 * reconfigure on the next max9286_i2c_mux_select() call.
 	 */
+	priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;
 	priv->mux_channel = -1;
 	max9286_write(priv, 0x0a, 0x00);
 	usleep_range(3000, 5000);
@@ -242,23 +265,19 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 268

Quoted 10 lines
drivers/media/i2c/max9286.c +1 -9
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
+	/* channel select is disabled when configured in the opened state. */

Channel

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 275

Quoted 8 lines
drivers/media/i2c/max9286.c +6 -1
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_DISABLE_SELECT)
 		return 0;
-	} else if (priv->streaming == 2) {
+
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_OPEN) {
+		/* Open all channels on the MAX9286 */
+		max9286_write(priv, 0x0a, 0xff);
+		priv->mux_state = MAX9286_I2C_MUX_STATE_DISABLE_SELECT;

Shouldn't we sleep 3-5ms when changing the forward/reverse channel configuration ?

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 280

Quoted 5 lines
drivers/media/i2c/max9286.c +2 -0
 		return 0;
 	}
 
+	/* Handling for MAX9286_I2C_MUX_STATE_CHANNEL */
+

Empty line
Do you need this comment ?

Quoted 14 lines
drivers/media/i2c/max9286.c +1 -2
 	if (priv->mux_channel == chan)
 		return 0;
 
@@ -441,8 +460,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_OPEN;
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {

drivers/media/i2c/max9286.c static int max9286_s_stream(struct v4l2_subdev *sd, int enable) · line 511

Quoted 6 lines
drivers/media/i2c/max9286.c +1 -2
@@ -490,8 +508,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Shouldn't we call i2c_mux_close() here, and let it close all channels and reset the mux state ? If the mux is not closed by writing 0x0a = 0x00 but the state is here reset to STATE_CHANNEL all successive i2c_mux_select() call will re-open channel-by-channel a mux that is already open, won't they ?

Overall, I very much agree we need this patch, so thanks for having addressed it!

Thanks
j

Quoted 6 lines
drivers/media/i2c/max9286.c +0 -1
 	}
 
 	return 0;
--

2.20.1

#13 lore raw

Re: [PATCH] max9286: Improve mux-state readbility

Hi Jacopo,

Thanks for reviewing this :D

Quoted 11 lines · Jacopo Mondi

Hi Kieran,

Quoted 6 lines · Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted ith a FIXME and is difficult to interpret the meaning of the

s/ith/with

ack.

Quoted 31 lines
Quoted 31 lines

values 0, 1, 2.

Introduce an enum to declare the intent of each state, and comment the states accordingly.

This state transition is only needed for the multi-channel support, and will not be included in the single-channel max9286 posting.

---
 drivers/media/i2c/max9286.c | 63 +++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)
drivers/media/i2c/max9286.c +1 -1
index eed00ff1dee4..a9c3e7411bda 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,16 +221,39 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
Quoted 8 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 224

Quoted 1 line
drivers/media/i2c/max9286.c +1 -0
+enum max9286_i2c_mux_state {

Let the bikeshedding begin here

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 226

Quoted 2 lines
drivers/media/i2c/max9286.c +2 -0
+	/*
+	 * The I2C Mux will enable only a single channel (both forward, and

s/Mux/mux

Ack.

Quoted 6 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 229

Quoted 4 lines
drivers/media/i2c/max9286.c +3 -0
+	 * reverse) at a time, and to reduce I2C bus bandwidth, it will only
+	 * reconfigure the channel when a write is requested to a different
+	 * channel.

I won't here explain what a mux channel select does

I was trying to explain what /this state/ does ... I can streamline this.

Quoted 7 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 231

Quoted 3 lines
drivers/media/i2c/max9286.c +2 -0
+	 */
+	MAX9286_I2C_MUX_STATE_CHANNEL = 0,

To me, this should be the initial state of the mux, where all channels are closed.

I actually started with a _CLOSED here, but I determined that _CLOSED was redundant, as _CLOSED is simply _CHANNEL with a channel id of -1.

And when in _CLOSED, the next 'write' should be of type _CHANNEL, as in it should configure only a single channel, and open only that channel.

Quoted 5 lines

The state machine to me should look like:

        init() -> i2c_mux_close() -> mux_state = CLOSED;
        all transaction selects/deselect a single channel>
        s_stream(1) -> mux_state = REQUEST_OPEN

I also had a REQUEST_OPEN, but I deemed it also to be a bit redundant, as the external (not mux components) which adapt the mux_state should only care about two states - Either it's open or on channel.

I almost wonder if I should put in a helper function to make mux_state private to the i2c_mux functions ... but I think that's overkill.

Quoted 19 lines

first transaction opens all channels -> mux_state = OPEN all successive transactions with (mux_state = OPEN) are nop

s_stream(0) -> i2c_mux_close() -> mux_state = CLOSED
all transaction selects/deselect a single channel until next s_stream(1)

For this state I propose MAX9286_I2C_MUX_STATE_CLOSED

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 239

Quoted 8 lines
drivers/media/i2c/max9286.c +8 -0
+
+	/*
+	 * The I2C mux will be configured with all ports open. All I2C writes
+	 * will be transmitted to all remote I2C devices, and where multiple
+	 * devices have the same address, the write will be received by all of
+	 * them.
+	 */
+	MAX9286_I2C_MUX_STATE_OPEN,

I propose MAX9286_I2C_MUX_STATE_REQUEST_OPEN

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 246

Quoted 7 lines
drivers/media/i2c/max9286.c +7 -0
+
+	/*
+	 * The I2C mux is configured with all ports open.
+	 *
+	 * No reconfiguration of the I2C mux channel select is required.
+	 */
+	MAX9286_I2C_MUX_STATE_DISABLE_SELECT,

I propose MAX9286_I2C_MUX_STATE_OPEN

I had this as 'MUX_STATE_OPENED', but it felt like what it was really doing was just 'disabling select' operations, hence I renamed it.

It's also 'internal' and I wouldn't expect the no nmax9286_i2c_mux_ functions to reference this enum value.

My further reasoning to keep this as DISABLE_SELECT is that ifsomeone set this state (not that anyone ever should), when the mux was closed - it would remain closed.

Quoted 1 line

Could all these be shorten to MAX9286_MUX_.... ?

I think so, I was just following the function naming.

Quoted 10 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 228

Quoted 7 lines
drivers/media/i2c/max9286.c +2 -3
+};
+
 static int max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;

I don't get why we had this one here. Do you agree it was not necessary ? I guess so, since you dropped it...

Exactly, I couldn't see any reason for this to be here, and I also couldn't see it being used, as _close It doesn't get called after an s_stream operation as far as I can tell. It's only currently closed during _probe and _init.

However, if at some other point, someone wanted to call _close, I would expect it to close all of the channels.

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 256

Quoted 9 lines
drivers/media/i2c/max9286.c +3 -2
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
-	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * mux, and that the channel state and ID is invalidated to ensure we
+	 * reconfigure on the next max9286_i2c_mux_select() call.
 	 */
+	priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Note here that we set the mux_channel to -1, and thus the state is set to _CHANNEL as discussed above, because on the next operation - we expect either the write to go to the specific channel, /or/ if someone has set MAX9286_I2C_MUX_STATE_OPEN explicitly the select call will send it to all channels.

Those are the only two options as far as I can tell, so adding extra states of '_CLOSED' seems redundant, and adds unecessary complexity to me.

Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/max9286.c +0 -0
 	priv->mux_channel = -1;
 	max9286_write(priv, 0x0a, 0x00);
 	usleep_range(3000, 5000);
@@ -242,23 +265,19 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
Quoted 15 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 268

Quoted 13 lines
drivers/media/i2c/max9286.c +1 -12
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
+	/* channel select is disabled when configured in the opened state. */

Channel

Ack.

Quoted 12 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 275

Quoted 9 lines
drivers/media/i2c/max9286.c +6 -1
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_DISABLE_SELECT)
 		return 0;
-	} else if (priv->streaming == 2) {
+
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_OPEN) {
+		/* Open all channels on the MAX9286 */
+		max9286_write(priv, 0x0a, 0xff);
+		priv->mux_state = MAX9286_I2C_MUX_STATE_DISABLE_SELECT;

Shouldn't we sleep 3-5ms when changing the forward/reverse channel configuration ?

Based on the comments below, we probably do - and this has been missing.

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 280

Quoted 6 lines
drivers/media/i2c/max9286.c +2 -0
 		return 0;
 	}
 
+	/* Handling for MAX9286_I2C_MUX_STATE_CHANNEL */
+

Empty line
Do you need this comment ?

I wanted to clarify that of the 3 states, the lines above explicitly handle the MAX9286_I2C_MUX_STATE_DISABLE_SELECT, and the MAX9286_I2C_MUX_STATE_OPEN states, so it's left 'implicit' that the code below is MAX9286_I2C_MUX_STATE_CHANNEL.

I added the comment to make it more explicit.

I didn't want to move all the code into a switch statement which would be my only alternative otherwise I think.

Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/max9286.c +1 -2
 	if (priv->mux_channel == chan)
 		return 0;
 
@@ -441,8 +460,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_OPEN;
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +508,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_s_stream(struct v4l2_subdev *sd, int enable) · line 511

Quoted 3 lines
drivers/media/i2c/max9286.c +1 -2
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Shouldn't we call i2c_mux_close() here, and let it close all channels and reset the mux state ? If the mux is not closed by writing 0x0a = 0x00 but the state is here reset to STATE_CHANNEL all successive i2c_mux_select() call will re-open channel-by-channel a mux that is already open, won't they ?

I have not modified the actual state transitions from your original implementation, so I think you're the expert here. This is your code, just renamed.

(Ok perhaps that's not true, I removed the state check at max9286_i2c_mux_close above)

So - thinking it through ... Yes, you are right - this will leave all the channels open. This is the behaviour we had before this patch though so I wonder if this could explain any of the issues we've had.

I don't /think/ so - because
A) we probably reset the board a lot,
B) I don't think we've had issues starting and stopping streams, but we haven't done enough testing there.

Quoted 2 lines

Overall, I very much agree we need this patch, so thanks for having addressed it!

No problem, I needed to go through to understand what the three states (0, 1, 2) were, so this is what I came up with.

Thanks for your comments, I'll await any further comments to the above then do a respin before collapsing it into the multi-stream support patch.

Or do you think we should keep things as separate patches on top of the 'single' camera support? I don't want to end up in a GMSL==100 patches to track case again if we can avoid it .., So I'd like to keep it down to three managable topics :

Patch 1) A single camera support, (should apply and run on linux-media) Patch 2) Support for multiple streams (requires v4l2-mux) Patch 3) Support for 2 MAX9286 on one bus (not upstreamable currently)

--
Kieran

Quoted 9 lines

Thanks
j

Quoted 6 lines
drivers/media/i2c/max9286.c +0 -1
 	}
 
 	return 0;
--

2.20.1

#14 lore raw

Re: [PATCH] max9286: Improve mux-state readbility

Hi Kieran,

Quoted 132 lines · Kieran Bingham

Hi Jacopo,

Thanks for reviewing this :D

Quoted 11 lines · Jacopo Mondi

Hi Kieran,

Quoted 6 lines · Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted ith a FIXME and is difficult to interpret the meaning of the

s/ith/with

ack.

Quoted 31 lines
Quoted 31 lines

values 0, 1, 2.

Introduce an enum to declare the intent of each state, and comment the states accordingly.

This state transition is only needed for the multi-channel support, and will not be included in the single-channel max9286 posting.

---
 drivers/media/i2c/max9286.c | 63 +++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)
drivers/media/i2c/max9286.c +1 -1
index eed00ff1dee4..a9c3e7411bda 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,16 +221,39 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
Quoted 8 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 224

Quoted 1 line
drivers/media/i2c/max9286.c +1 -0
+enum max9286_i2c_mux_state {

Let the bikeshedding begin here

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 226

Quoted 2 lines
drivers/media/i2c/max9286.c +2 -0
+	/*
+	 * The I2C Mux will enable only a single channel (both forward, and

s/Mux/mux

Ack.

Quoted 6 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 229

Quoted 4 lines
drivers/media/i2c/max9286.c +3 -0
+	 * reverse) at a time, and to reduce I2C bus bandwidth, it will only
+	 * reconfigure the channel when a write is requested to a different
+	 * channel.

I won't here explain what a mux channel select does

I was trying to explain what /this state/ does ... I can streamline this.

Quoted 7 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 231

Quoted 3 lines
drivers/media/i2c/max9286.c +2 -0
+	 */
+	MAX9286_I2C_MUX_STATE_CHANNEL = 0,

To me, this should be the initial state of the mux, where all channels are closed.

I actually started with a _CLOSED here, but I determined that _CLOSED was redundant, as _CLOSED is simply _CHANNEL with a channel id of -1.

And when in _CLOSED, the next 'write' should be of type _CHANNEL, as in it should configure only a single channel, and open only that channel.

Quoted 5 lines

The state machine to me should look like:

        init() -> i2c_mux_close() -> mux_state = CLOSED;
        all transaction selects/deselect a single channel>
        s_stream(1) -> mux_state = REQUEST_OPEN

I also had a REQUEST_OPEN, but I deemed it also to be a bit redundant, as the external (not mux components) which adapt the mux_state should only care about two states - Either it's open or on channel.

I almost wonder if I should put in a helper function to make mux_state private to the i2c_mux functions ... but I think that's overkill.

Quoted 19 lines

first transaction opens all channels -> mux_state = OPEN all successive transactions with (mux_state = OPEN) are nop

s_stream(0) -> i2c_mux_close() -> mux_state = CLOSED
all transaction selects/deselect a single channel until next s_stream(1)

For this state I propose MAX9286_I2C_MUX_STATE_CLOSED

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 239

Quoted 8 lines
drivers/media/i2c/max9286.c +8 -0
+
+	/*
+	 * The I2C mux will be configured with all ports open. All I2C writes
+	 * will be transmitted to all remote I2C devices, and where multiple
+	 * devices have the same address, the write will be received by all of
+	 * them.
+	 */
+	MAX9286_I2C_MUX_STATE_OPEN,

I propose MAX9286_I2C_MUX_STATE_REQUEST_OPEN

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 246

Quoted 7 lines
drivers/media/i2c/max9286.c +7 -0
+
+	/*
+	 * The I2C mux is configured with all ports open.
+	 *
+	 * No reconfiguration of the I2C mux channel select is required.
+	 */
+	MAX9286_I2C_MUX_STATE_DISABLE_SELECT,

I propose MAX9286_I2C_MUX_STATE_OPEN

I had this as 'MUX_STATE_OPENED', but it felt like what it was really doing was just 'disabling select' operations, hence I renamed it.

Quoted 7 lines

It's also 'internal' and I wouldn't expect the no nmax9286_i2c_mux_ functions to reference this enum value.

My further reasoning to keep this as DISABLE_SELECT is that ifsomeone set this state (not that anyone ever should), when the mux was closed - it would remain closed.

Ok, let's see what other thinks... anyway, that's your code so if you feel strong about this, I'm fine with what you have

Quoted 42 lines
Quoted 2 lines

Could all these be shorten to MAX9286_MUX_.... ?

I think so, I was just following the function naming.

Quoted 10 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 228

Quoted 7 lines
drivers/media/i2c/max9286.c +2 -3
+};
+
 static int max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;

I don't get why we had this one here. Do you agree it was not necessary ? I guess so, since you dropped it...

Exactly, I couldn't see any reason for this to be here, and I also couldn't see it being used, as _close It doesn't get called after an s_stream operation as far as I can tell. It's only currently closed during _probe and _init.

However, if at some other point, someone wanted to call _close, I would expect it to close all of the channels.

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 256

Quoted 9 lines
drivers/media/i2c/max9286.c +3 -2
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
-	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * mux, and that the channel state and ID is invalidated to ensure we
+	 * reconfigure on the next max9286_i2c_mux_select() call.
 	 */
+	priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Note here that we set the mux_channel to -1, and thus the state is set to _CHANNEL as discussed above, because on the next operation - we expect either the write to go to the specific channel, /or/ if someone has set MAX9286_I2C_MUX_STATE_OPEN explicitly the select call will send it to all channels.

Quoted 2 lines

Those are the only two options as far as I can tell, so adding extra states of '_CLOSED' seems redundant, and adds unecessary complexity to me.

_CLOSED was meant to replace _CHANNEL in my proposal. No worries though

Quoted 40 lines
Quoted 8 lines
Quoted 8 lines
drivers/media/i2c/max9286.c +0 -0
 	priv->mux_channel = -1;
 	max9286_write(priv, 0x0a, 0x00);
 	usleep_range(3000, 5000);
@@ -242,23 +265,19 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
Quoted 15 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 268

Quoted 13 lines
drivers/media/i2c/max9286.c +1 -12
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
+	/* channel select is disabled when configured in the opened state. */

Channel

Ack.

Quoted 12 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 275

Quoted 9 lines
drivers/media/i2c/max9286.c +6 -1
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_DISABLE_SELECT)
 		return 0;
-	} else if (priv->streaming == 2) {
+
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_OPEN) {
+		/* Open all channels on the MAX9286 */
+		max9286_write(priv, 0x0a, 0xff);
+		priv->mux_state = MAX9286_I2C_MUX_STATE_DISABLE_SELECT;

Shouldn't we sleep 3-5ms when changing the forward/reverse channel configuration ?

Quoted 2 lines

Based on the comments below, we probably do - and this has been missing.

Yes, was not there in first place

Quoted 50 lines
Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 280

Quoted 6 lines
drivers/media/i2c/max9286.c +2 -0
 		return 0;
 	}
 
+	/* Handling for MAX9286_I2C_MUX_STATE_CHANNEL */
+

Empty line
Do you need this comment ?

I wanted to clarify that of the 3 states, the lines above explicitly handle the MAX9286_I2C_MUX_STATE_DISABLE_SELECT, and the MAX9286_I2C_MUX_STATE_OPEN states, so it's left 'implicit' that the code below is MAX9286_I2C_MUX_STATE_CHANNEL.

I added the comment to make it more explicit.

I didn't want to move all the code into a switch statement which would be my only alternative otherwise I think.

Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/max9286.c +1 -2
 	if (priv->mux_channel == chan)
 		return 0;
 
@@ -441,8 +460,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_OPEN;
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +508,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_s_stream(struct v4l2_subdev *sd, int enable) · line 511

Quoted 3 lines
drivers/media/i2c/max9286.c +1 -2
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Shouldn't we call i2c_mux_close() here, and let it close all channels and reset the mux state ? If the mux is not closed by writing 0x0a = 0x00 but the state is here reset to STATE_CHANNEL all successive i2c_mux_select() call will re-open channel-by-channel a mux that is already open, won't they ?

Quoted 3 lines

I have not modified the actual state transitions from your original implementation, so I think you're the expert here. This is your code, just renamed.

I know, this was a question not strictly related to your changes

Quoted 4 lines

(Ok perhaps that's not true, I removed the state check at max9286_i2c_mux_close above)

Quoted 8 lines

So - thinking it through ... Yes, you are right - this will leave all the channels open. This is the behaviour we had before this patch though so I wonder if this could explain any of the issues we've had.

I don't /think/ so - because
A) we probably reset the board a lot,
B) I don't think we've had issues starting and stopping streams, but we haven't done enough testing there.

Also, it won't hurt to have the mux open all the time after we have configured addresses properly. It just does not feel 'right'

Quoted 12 lines
Quoted 5 lines

Overall, I very much agree we need this patch, so thanks for having addressed it!

No problem, I needed to go through to understand what the three states (0, 1, 2) were, so this is what I came up with.

Thanks for your comments, I'll await any further comments to the above then do a respin before collapsing it into the multi-stream support patch.

Quoted 8 lines

Or do you think we should keep things as separate patches on top of the 'single' camera support? I don't want to end up in a GMSL==100 patches to track case again if we can avoid it .., So I'd like to keep it down to three managable topics :

Patch 1) A single camera support, (should apply and run on linux-media) Patch 2) Support for multiple streams (requires v4l2-mux) Patch 3) Support for 2 MAX9286 on one bus (not upstreamable currently)

I very much agree with this plan!

Thanks
j

Quoted 14 lines

--
Kieran

Quoted 9 lines

Thanks
j

Quoted 6 lines
drivers/media/i2c/max9286.c +0 -1
 	}
 
 	return 0;
--

2.20.1

#15 lore raw

Re: [PATCH] max9286: Improve mux-state readbility

Hi Jacopo,

Quoted 138 lines · Jacopo Mondi

Hi Kieran,

Quoted 135 lines · Kieran Bingham

Hi Jacopo,

Thanks for reviewing this :D

Quoted 11 lines · Jacopo Mondi

Hi Kieran,

Quoted 6 lines · Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted ith a FIXME and is difficult to interpret the meaning of the

s/ith/with

ack.

Quoted 31 lines
Quoted 31 lines

values 0, 1, 2.

Introduce an enum to declare the intent of each state, and comment the states accordingly.

This state transition is only needed for the multi-channel support, and will not be included in the single-channel max9286 posting.

---
 drivers/media/i2c/max9286.c | 63 +++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)
drivers/media/i2c/max9286.c +1 -1
index eed00ff1dee4..a9c3e7411bda 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,16 +221,39 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
Quoted 8 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 224

Quoted 1 line
drivers/media/i2c/max9286.c +1 -0
+enum max9286_i2c_mux_state {

Let the bikeshedding begin here

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 226

Quoted 2 lines
drivers/media/i2c/max9286.c +2 -0
+	/*
+	 * The I2C Mux will enable only a single channel (both forward, and

s/Mux/mux

Ack.

Quoted 6 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 229

Quoted 4 lines
drivers/media/i2c/max9286.c +3 -0
+	 * reverse) at a time, and to reduce I2C bus bandwidth, it will only
+	 * reconfigure the channel when a write is requested to a different
+	 * channel.

I won't here explain what a mux channel select does

I was trying to explain what /this state/ does ... I can streamline this.

Quoted 7 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 231

Quoted 3 lines
drivers/media/i2c/max9286.c +2 -0
+	 */
+	MAX9286_I2C_MUX_STATE_CHANNEL = 0,

To me, this should be the initial state of the mux, where all channels are closed.

I actually started with a _CLOSED here, but I determined that _CLOSED was redundant, as _CLOSED is simply _CHANNEL with a channel id of -1.

And when in _CLOSED, the next 'write' should be of type _CHANNEL, as in it should configure only a single channel, and open only that channel.

Quoted 5 lines

The state machine to me should look like:

        init() -> i2c_mux_close() -> mux_state = CLOSED;
        all transaction selects/deselect a single channel>
        s_stream(1) -> mux_state = REQUEST_OPEN

I also had a REQUEST_OPEN, but I deemed it also to be a bit redundant, as the external (not mux components) which adapt the mux_state should only care about two states - Either it's open or on channel.

I almost wonder if I should put in a helper function to make mux_state private to the i2c_mux functions ... but I think that's overkill.

Quoted 19 lines

first transaction opens all channels -> mux_state = OPEN all successive transactions with (mux_state = OPEN) are nop

s_stream(0) -> i2c_mux_close() -> mux_state = CLOSED
all transaction selects/deselect a single channel until next s_stream(1)

For this state I propose MAX9286_I2C_MUX_STATE_CLOSED

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 239

Quoted 8 lines
drivers/media/i2c/max9286.c +8 -0
+
+	/*
+	 * The I2C mux will be configured with all ports open. All I2C writes
+	 * will be transmitted to all remote I2C devices, and where multiple
+	 * devices have the same address, the write will be received by all of
+	 * them.
+	 */
+	MAX9286_I2C_MUX_STATE_OPEN,

I propose MAX9286_I2C_MUX_STATE_REQUEST_OPEN

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 246

Quoted 7 lines
drivers/media/i2c/max9286.c +7 -0
+
+	/*
+	 * The I2C mux is configured with all ports open.
+	 *
+	 * No reconfiguration of the I2C mux channel select is required.
+	 */
+	MAX9286_I2C_MUX_STATE_DISABLE_SELECT,

I propose MAX9286_I2C_MUX_STATE_OPEN

I had this as 'MUX_STATE_OPENED', but it felt like what it was really doing was just 'disabling select' operations, hence I renamed it.

It's also 'internal' and I wouldn't expect the no nmax9286_i2c_mux_ functions to reference this enum value.

Quoted 7 lines
Quoted 4 lines

My further reasoning to keep this as DISABLE_SELECT is that ifsomeone set this state (not that anyone ever should), when the mux was closed - it would remain closed.

Ok, let's see what other thinks... anyway, that's your code so if you feel strong about this, I'm fine with what you have

Ok,

Quoted 41 lines
Quoted 41 lines
Quoted 1 line

Could all these be shorten to MAX9286_MUX_.... ?

I think so, I was just following the function naming.

Quoted 10 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 228

Quoted 7 lines
drivers/media/i2c/max9286.c +2 -3
+};
+
 static int max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;

I don't get why we had this one here. Do you agree it was not necessary ? I guess so, since you dropped it...

Exactly, I couldn't see any reason for this to be here, and I also couldn't see it being used, as _close It doesn't get called after an s_stream operation as far as I can tell. It's only currently closed during _probe and _init.

However, if at some other point, someone wanted to call _close, I would expect it to close all of the channels.

Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 256

Quoted 9 lines
drivers/media/i2c/max9286.c +3 -2
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
-	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * mux, and that the channel state and ID is invalidated to ensure we
+	 * reconfigure on the next max9286_i2c_mux_select() call.
 	 */
+	priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Note here that we set the mux_channel to -1, and thus the state is set to _CHANNEL as discussed above, because on the next operation - we expect either the write to go to the specific channel, /or/ if someone has set MAX9286_I2C_MUX_STATE_OPEN explicitly the select call will send it to all channels.

Quoted 5 lines
Quoted 2 lines

Those are the only two options as far as I can tell, so adding extra states of '_CLOSED' seems redundant, and adds unecessary complexity to me.

_CLOSED was meant to replace _CHANNEL in my proposal. No worries though

Ah I see, as in just a different name. My concern with _CLOSED though is that we do not close the channel after each write, and _CLOSED could potentially give the impression that we do ...

Quoted 108 lines
Quoted 39 lines
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/max9286.c +0 -0
 	priv->mux_channel = -1;
 	max9286_write(priv, 0x0a, 0x00);
 	usleep_range(3000, 5000);
@@ -242,23 +265,19 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
Quoted 15 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 268

Quoted 13 lines
drivers/media/i2c/max9286.c +1 -12
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
+	/* channel select is disabled when configured in the opened state. */

Channel

Ack.

Quoted 12 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 275

Quoted 9 lines
drivers/media/i2c/max9286.c +6 -1
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_DISABLE_SELECT)
 		return 0;
-	} else if (priv->streaming == 2) {
+
+	if (priv->mux_state == MAX9286_I2C_MUX_STATE_OPEN) {
+		/* Open all channels on the MAX9286 */
+		max9286_write(priv, 0x0a, 0xff);
+		priv->mux_state = MAX9286_I2C_MUX_STATE_DISABLE_SELECT;

Shouldn't we sleep 3-5ms when changing the forward/reverse channel configuration ?

Quoted 2 lines

Based on the comments below, we probably do - and this has been missing.

Yes, was not there in first place

Quoted 50 lines
Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan) · line 280

Quoted 6 lines
drivers/media/i2c/max9286.c +2 -0
 		return 0;
 	}
 
+	/* Handling for MAX9286_I2C_MUX_STATE_CHANNEL */
+

Empty line
Do you need this comment ?

I wanted to clarify that of the 3 states, the lines above explicitly handle the MAX9286_I2C_MUX_STATE_DISABLE_SELECT, and the MAX9286_I2C_MUX_STATE_OPEN states, so it's left 'implicit' that the code below is MAX9286_I2C_MUX_STATE_CHANNEL.

I added the comment to make it more explicit.

I didn't want to move all the code into a switch statement which would be my only alternative otherwise I think.

Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/max9286.c +1 -2
 	if (priv->mux_channel == chan)
 		return 0;
 
@@ -441,8 +460,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_OPEN;
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +508,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
Quoted 9 lines

drivers/media/i2c/max9286.c static int max9286_s_stream(struct v4l2_subdev *sd, int enable) · line 511

Quoted 3 lines
drivers/media/i2c/max9286.c +1 -2
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;

Shouldn't we call i2c_mux_close() here, and let it close all channels and reset the mux state ? If the mux is not closed by writing 0x0a = 0x00 but the state is here reset to STATE_CHANNEL all successive i2c_mux_select() call will re-open channel-by-channel a mux that is already open, won't they ?

Quoted 3 lines

I have not modified the actual state transitions from your original implementation, so I think you're the expert here. This is your code, just renamed.

I know, this was a question not strictly related to your changes

Quoted 8 lines

(Ok perhaps that's not true, I removed the state check at max9286_i2c_mux_close above)

So - thinking it through ... Yes, you are right - this will leave all the channels open. This is the behaviour we had before this patch though so I wonder if this could explain any of the issues we've had.

Quoted 7 lines
Quoted 4 lines

I don't /think/ so - because
A) we probably reset the board a lot,
B) I don't think we've had issues starting and stopping streams, but we haven't done enough testing there.

Also, it won't hurt to have the mux open all the time after we have configured addresses properly. It just does not feel 'right'

Indeed, and while it may not hurt, it leads to a point where we get the following conditions :

(O=Open, _=Closed)

1 2 3 4
O _ _ _ // Write to 1
_ O _ _ // Write to 2
_ _ O _ // Write to 3
_ _ _ O // Write to 4

O O O O // StreamOn // MAX9286_I2C_MUX_STATE_OPEN
O O O O // StreamOff // MAX9286_I2C_MUX_STATE_CHANNEL

O O O O // Write to 1
_ O O O // Write to 2
_ _ O O // Write to 3
_ _ _ O // Write to 4

O _ _ _ // Write to 1

O O O O // StreamOn // MAX9286_I2C_MUX_STATE_OPEN
O O O O // StreamOff // MAX9286_I2C_MUX_STATE_CHANNEL

... Continues

I will indeed fix this by calling mux_close when we stop streaming. At least then we will have a consistent state as we expect.

In fact from all that I think that means we would likely be better to have:

/* Opens all channels on the MUX and disables individual select lines */ static int max9286_i2c_mux_open(struct max9286_priv *priv)

{
	/* Open all channels on the MAX9286 */
	max9286_write(priv, 0x0a, 0xff);
	usleep_range(3000, 5000);

	priv->mux_state = MAX9286_I2C_MUX_STATE_DISABLE_SELECT;

	return 0;
}

static int max9286_i2c_mux_close(struct max9286_priv *priv)

{
	priv->mux_state = MAX9286_I2C_MUX_STATE_CHANNEL;
	priv->mux_channel = -1;
	max9286_write(priv, 0x0a, 0x00);
	usleep_range(3000, 5000);
	return 0;
}

static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)

{
	struct max9286_priv *priv = i2c_mux_priv(muxc);

	/* channel select is disabled when configured in the opend state. */
	if (priv->mux_state == MAX9286_I2C_MUX_STATE_DISABLE_SELECT)
		return 0;

	/* Handling for MAX9286_I2C_MUX_STATE_CHANNEL */

	if (priv->mux_channel == chan)
		return 0;

	...
}

Which makes the intentions much clearer, and stops other sections of the driver from directly modifying the 'private' mux_state.

Quoted 14 lines
Quoted 14 lines
Quoted 2 lines

Overall, I very much agree we need this patch, so thanks for having addressed it!

No problem, I needed to go through to understand what the three states (0, 1, 2) were, so this is what I came up with.

Thanks for your comments, I'll await any further comments to the above then do a respin before collapsing it into the multi-stream support patch.

Or do you think we should keep things as separate patches on top of the 'single' camera support? I don't want to end up in a GMSL==100 patches to track case again if we can avoid it .., So I'd like to keep it down to three managable topics :

Quoted 5 lines
Quoted 3 lines

Patch 1) A single camera support, (should apply and run on linux-media) Patch 2) Support for multiple streams (requires v4l2-mux) Patch 3) Support for 2 MAX9286 on one bus (not upstreamable currently)

I very much agree with this plan!

Great, I'm on the right track then.

Quoted 3 lines

Thanks
j

Signature · 3 lines
Regards
--
Kieran
#16 lore raw

PATCH 1/1 max9286: Improve mux-state readbility [v2]

In reply to Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted with a FIXME and is difficult to interpret the meaning of the values 0, 1, 2.

Introduce a new function call max9286_i2c_mux_open() to make it clear when a component opens all the mux channels, and update the usage in s_stream() to max9286_i2c_mux_close() the mux on stop stream.

We previously had missed an occasion to sleep after an update to the I2C Fwd/Rev channels, so all writes to this configuration register are moved to a helper: max9286_i2c_mux_configure() which guarantees the delay.

---
 drivers/media/i2c/max9286.c | 74 ++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/media/i2c/max9286.c +37 -37
index 5b8dfa652d50..b34fb31c6db5 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,57 +221,59 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
-static int max9286_i2c_mux_close(struct max9286_priv *priv)
+enum max9286_i2c_mux_state {
+	MAX9286_MUX_CLOSED = 0,
+	MAX9286_MUX_OPEN,
+};
+
+static void max9286_i2c_mux_configure(struct max9286_priv *priv, u8 conf)
+{
+	max9286_write(priv, 0x0a, conf);
+
+	/*
+	 * We must sleep after any change to the forward or reverse channel
+	 * configuration.
+	 */
+	usleep_range(3000, 5000);
+}
+
+static void max9286_i2c_mux_open(struct max9286_priv *priv)
+{
+	/* Open all channels on the MAX9286 */
+	max9286_i2c_mux_configure(priv, 0xff);
+
+	priv->mux_state = MAX9286_MUX_OPEN;
+}
+
+static void max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
 	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * on the next max9286_i2c_mux_select() call.
 	 */
-	priv->mux_channel = -1;
-	max9286_write(priv, 0x0a, 0x00);
-	usleep_range(3000, 5000);
+	max9286_i2c_mux_configure(priv, 0x00);
 
-	return 0;
+	priv->mux_state = MAX9286_MUX_CLOSED;
+	priv->mux_channel = -1;
 }
 
 static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
-		return 0;
-	} else if (priv->streaming == 2) {
+	/* channel select is disabled when configured in the opened state. */
+	if (priv->mux_state == MAX9286_MUX_OPEN)
 		return 0;
-	}
 
 	if (priv->mux_channel == chan)
 		return 0;
 
 	priv->mux_channel = chan;
 
-	max9286_write(priv, 0x0a,
-		      MAX9286_FWDCCEN(chan) | MAX9286_REVCCEN(chan));
-
-	/*
-	 * We must sleep after any change to the forward or reverse channel
-	 * configuration.
-	 */
-	usleep_range(3000, 5000);
+	max9286_i2c_mux_configure(priv,
+				  MAX9286_FWDCCEN(chan) |
+				  MAX9286_REVCCEN(chan));
 
 	return 0;
 }
@@ -441,8 +443,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		max9286_i2c_mux_open(priv);
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +491,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		max9286_i2c_mux_close(priv);
 	}
 
 	return 0;
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#17 lore raw

Re: [PATCH] max9286: Improve mux-state readbility [v2]

Hi Kieran,
only a really minor nit, you could fix when squashing this patch

Quoted 93 lines · Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted with a FIXME and is difficult to interpret the meaning of the values 0, 1, 2.

Introduce a new function call max9286_i2c_mux_open() to make it clear when a component opens all the mux channels, and update the usage in s_stream() to max9286_i2c_mux_close() the mux on stop stream.

We previously had missed an occasion to sleep after an update to the I2C Fwd/Rev channels, so all writes to this configuration register are moved to a helper: max9286_i2c_mux_configure() which guarantees the delay.

---
 drivers/media/i2c/max9286.c | 74 ++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/media/i2c/max9286.c +30 -15
index 5b8dfa652d50..b34fb31c6db5 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,57 +221,59 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
-static int max9286_i2c_mux_close(struct max9286_priv *priv)
+enum max9286_i2c_mux_state {
+	MAX9286_MUX_CLOSED = 0,
+	MAX9286_MUX_OPEN,
+};
+
+static void max9286_i2c_mux_configure(struct max9286_priv *priv, u8 conf)
+{
+	max9286_write(priv, 0x0a, conf);
+
+	/*
+	 * We must sleep after any change to the forward or reverse channel
+	 * configuration.
+	 */
+	usleep_range(3000, 5000);
+}
+
+static void max9286_i2c_mux_open(struct max9286_priv *priv)
+{
+	/* Open all channels on the MAX9286 */
+	max9286_i2c_mux_configure(priv, 0xff);
+
+	priv->mux_state = MAX9286_MUX_OPEN;
+}
+
+static void max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
 	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * on the next max9286_i2c_mux_select() call.
 	 */
-	priv->mux_channel = -1;
-	max9286_write(priv, 0x0a, 0x00);
-	usleep_range(3000, 5000);
+	max9286_i2c_mux_configure(priv, 0x00);
 
-	return 0;
+	priv->mux_state = MAX9286_MUX_CLOSED;
+	priv->mux_channel = -1;
 }
 
 static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 265

Quoted 10 lines
drivers/media/i2c/max9286.c +1 -9
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
-		return 0;
-	} else if (priv->streaming == 2) {
+	/* channel select is disabled when configured in the opened state. */

All other comments in this driver start with a capital letter.

Otherwise, I really like this patch! thanks!

Thanks
j

Quoted 46 lines
drivers/media/i2c/max9286.c +6 -14
+	if (priv->mux_state == MAX9286_MUX_OPEN)
 		return 0;
-	}
 
 	if (priv->mux_channel == chan)
 		return 0;
 
 	priv->mux_channel = chan;
 
-	max9286_write(priv, 0x0a,
-		      MAX9286_FWDCCEN(chan) | MAX9286_REVCCEN(chan));
-
-	/*
-	 * We must sleep after any change to the forward or reverse channel
-	 * configuration.
-	 */
-	usleep_range(3000, 5000);
+	max9286_i2c_mux_configure(priv,
+				  MAX9286_FWDCCEN(chan) |
+				  MAX9286_REVCCEN(chan));
 
 	return 0;
 }
@@ -441,8 +443,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		max9286_i2c_mux_open(priv);
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +491,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		max9286_i2c_mux_close(priv);
 	}
 
 	return 0;
--

2.20.1

#18 lore raw

Re: [PATCH] max9286: Improve mux-state readbility [v2]

Hi Jacopo,

Quoted 42 lines · Jacopo Mondi

Hi Kieran,
only a really minor nit, you could fix when squashing this patch

Quoted 38 lines · Kieran Bingham

The MAX9286 implements an I2C mux which we maintain in an open state while we are streaming from the cameras.

The development code for the MAX9286 uses an integer value with arbitrary state values to control these state transitions. This is highlighted with a FIXME and is difficult to interpret the meaning of the values 0, 1, 2.

Introduce a new function call max9286_i2c_mux_open() to make it clear when a component opens all the mux channels, and update the usage in s_stream() to max9286_i2c_mux_close() the mux on stop stream.

We previously had missed an occasion to sleep after an update to the I2C Fwd/Rev channels, so all writes to this configuration register are moved to a helper: max9286_i2c_mux_configure() which guarantees the delay.

---
 drivers/media/i2c/max9286.c | 74 ++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 37 deletions(-)
drivers/media/i2c/max9286.c +1 -1
index 5b8dfa652d50..b34fb31c6db5 100644
@@ -144,7 +144,7 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int streaming;
+	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
@@ -221,57 +221,59 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
Quoted 5 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 227

Quoted 5 lines
drivers/media/i2c/max9286.c +4 -1
-static int max9286_i2c_mux_close(struct max9286_priv *priv)
+enum max9286_i2c_mux_state {
+	MAX9286_MUX_CLOSED = 0,
+	MAX9286_MUX_OPEN,
+};

This is now down to just two states, so I think this probably warrants being changed to a bool mux_open;

I've already folded /this/ patch into the main max9286 driver, so I'll make this small fix and post it here along with the next two fixes I have.

Quoted 54 lines
Quoted 54 lines
drivers/media/i2c/max9286.c +25 -17
+
+static void max9286_i2c_mux_configure(struct max9286_priv *priv, u8 conf)
+{
+	max9286_write(priv, 0x0a, conf);
+
+	/*
+	 * We must sleep after any change to the forward or reverse channel
+	 * configuration.
+	 */
+	usleep_range(3000, 5000);
+}
+
+static void max9286_i2c_mux_open(struct max9286_priv *priv)
+{
+	/* Open all channels on the MAX9286 */
+	max9286_i2c_mux_configure(priv, 0xff);
+
+	priv->mux_state = MAX9286_MUX_OPEN;
+}
+
+static void max9286_i2c_mux_close(struct max9286_priv *priv)
 {
-	/* FIXME: See note in max9286_i2c_mux_select() */
-	if (priv->streaming)
-		return 0;
 	/*
 	 * Ensure that both the forward and reverse channel are disabled on the
 	 * mux, and that the channel ID is invalidated to ensure we reconfigure
-	 * on the next select call.
+	 * on the next max9286_i2c_mux_select() call.
 	 */
-	priv->mux_channel = -1;
-	max9286_write(priv, 0x0a, 0x00);
-	usleep_range(3000, 5000);
+	max9286_i2c_mux_configure(priv, 0x00);
 
-	return 0;
+	priv->mux_state = MAX9286_MUX_CLOSED;
+	priv->mux_channel = -1;
 }
 
 static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
-	/*
-	 * FIXME: This state keeping is a hack and do the job. It should
-	 * be should be reworked. One option to consider is that once all
-	 * cameras are programmed the mux selection logic should be disabled
-	 * and all all reverse and forward channels enable all the time.
-	 *
-	 * In any case this logic with a int that have two states should be
-	 * reworked!
-	 */
Quoted 8 lines

drivers/media/i2c/max9286.c static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val) · line 265

Quoted 6 lines
drivers/media/i2c/max9286.c +1 -5
-	if (priv->streaming == 1) {
-		max9286_write(priv, 0x0a, 0xff);
-		priv->streaming = 2;
-		return 0;
-	} else if (priv->streaming == 2) {
+	/* channel select is disabled when configured in the opened state. */

All other comments in this driver start with a capital letter.

Thanks, this is fixed up.

Quoted 53 lines

Otherwise, I really like this patch! thanks!

Thanks
j

Quoted 46 lines
drivers/media/i2c/max9286.c +6 -14
+	if (priv->mux_state == MAX9286_MUX_OPEN)
 		return 0;
-	}
 
 	if (priv->mux_channel == chan)
 		return 0;
 
 	priv->mux_channel = chan;
 
-	max9286_write(priv, 0x0a,
-		      MAX9286_FWDCCEN(chan) | MAX9286_REVCCEN(chan));
-
-	/*
-	 * We must sleep after any change to the forward or reverse channel
-	 * configuration.
-	 */
-	usleep_range(3000, 5000);
+	max9286_i2c_mux_configure(priv,
+				  MAX9286_FWDCCEN(chan) |
+				  MAX9286_REVCCEN(chan));
 
 	return 0;
 }
@@ -441,8 +443,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 	int ret;
 
 	if (enable) {
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 1;
+		max9286_i2c_mux_open(priv);
 
 		/* Start all cameras. */
 		for_each_source(priv, source) {
@@ -490,8 +491,7 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
 		for_each_source(priv, source)
 			v4l2_subdev_call(source->sd, video, s_stream, 0);
 
-		/* FIXME: See note in max9286_i2c_mux_select() */
-		priv->streaming = 0;
+		max9286_i2c_mux_close(priv);
 	}
 
 	return 0;
--

2.20.1

Signature · 3 lines
Regards
--
Kieran
#19 lore raw

PATCH 1/3 media: i2c: max9286: Remove redundant max9286_i2c_mux_state

In reply to Jacopo Mondi

While simplifying the i2c-mux state, the states were stored in an enum (initially there were three).

This has now simplified down to 2 states, open and closed - and can be represented easily in a bool.

It 'could' also be represented within the mux_channel, but I don't want to pollute that further than the '-1' value which is already stored in there to represent no channel selected.

Remove the max9286_i2c_mux_state and replace with a bool mux_open flag, and move the location within the private struct to be more appropriate.

---
 drivers/media/i2c/max9286.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/media/i2c/max9286.c +4 -9
index e5b3f78318db..6ea08fd87811 100644
@@ -144,10 +144,10 @@ struct max9286_priv {
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
 	bool poc_enabled;
-	int mux_state;
 
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
+	bool mux_open;
 
 	struct v4l2_ctrl_handler ctrls;
 
@@ -221,11 +221,6 @@ static int max9286_write(struct max9286_priv *priv, u8 reg, u8 val)
  * I2C Multiplexer
  */
 
-enum max9286_i2c_mux_state {
-	MAX9286_MUX_CLOSED = 0,
-	MAX9286_MUX_OPEN,
-};
-
 static void max9286_i2c_mux_configure(struct max9286_priv *priv, u8 conf)
 {
 	max9286_write(priv, 0x0a, conf);
@@ -242,7 +237,7 @@ static void max9286_i2c_mux_open(struct max9286_priv *priv)
 	/* Open all channels on the MAX9286 */
 	max9286_i2c_mux_configure(priv, 0xff);
 
-	priv->mux_state = MAX9286_MUX_OPEN;
+	priv->mux_open = true;
 }
 
 static void max9286_i2c_mux_close(struct max9286_priv *priv)
@@ -254,7 +249,7 @@ static void max9286_i2c_mux_close(struct max9286_priv *priv)
 	 */
 	max9286_i2c_mux_configure(priv, 0x00);
 
-	priv->mux_state = MAX9286_MUX_CLOSED;
+	priv->mux_open = false;
 	priv->mux_channel = -1;
 }
 
@@ -263,7 +258,7 @@ static int max9286_i2c_mux_select(struct i2c_mux_core *muxc, u32 chan)
 	struct max9286_priv *priv = i2c_mux_priv(muxc);
 
 	/* Channel select is disabled when configured in the opened state. */
-	if (priv->mux_state == MAX9286_MUX_OPEN)
+	if (priv->mux_open)
 		return 0;
 
 	if (priv->mux_channel == chan)
Signature · 1 line
2.20.1
#20 lore raw

PATCH 2/3 media: i2c: max9286: Add GPIO chip controller

Provide a GPIO chip to control the two output lines available on the MAX9286.

---
 drivers/media/i2c/max9286.c | 68 +++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
drivers/media/i2c/max9286.c +68 -0
index 6ea08fd87811..c34e7b5c7447 100644
@@ -13,6 +13,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/fwnode.h>
+#include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
 #include <linux/module.h>
@@ -58,6 +59,8 @@
 #define MAX9286_HVSRC_D0		(2 << 0)
 #define MAX9286_HVSRC_D14		(1 << 0)
 #define MAX9286_HVSRC_D18		(0 << 0)
+/* Register 0x0f */
+#define MAX9286_0X0F_RESERVED		BIT(3)
 /* Register 0x12 */
 #define MAX9286_CSILANECNT(n)		(((n) - 1) << 6)
 #define MAX9286_CSIDBL			BIT(5)
@@ -145,6 +148,9 @@ struct max9286_priv {
 	struct regulator *regulator;
 	bool poc_enabled;
 
+	struct gpio_chip gpio;
+	u8 gpio_state;
+
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
 	bool mux_open;
@@ -712,6 +718,60 @@ static const struct of_device_id max9286_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, max9286_dt_ids);
 
+static void max9286_gpio_set(struct gpio_chip *chip,
+			     unsigned int offset, int value)
+{
+	struct max9286_priv *priv = gpiochip_get_data(chip);
+
+	if (value)
+		priv->gpio_state |= BIT(offset);
+	else
+		priv->gpio_state &= ~BIT(offset);
+
+	max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | priv->gpio_state);
+}
+
+static int max9286_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+	struct max9286_priv *priv = gpiochip_get_data(chip);
+
+	return priv->gpio_state & BIT(offset);
+}
+
+static int max9286_gpio(struct max9286_priv *priv)
+{
+	struct device *dev = &priv->client->dev;
+	struct gpio_chip *gpio = &priv->gpio;
+	int ret;
+
+	static const char * const names[] = {
+		"GPIO0OUT",
+		"GPIO1OUT",
+	};
+
+	/* Configure the GPIO */
+	gpio->label = dev_name(dev);
+	gpio->parent = dev;
+	gpio->owner = THIS_MODULE;
+	gpio->of_node = dev->of_node;
+	gpio->ngpio = 2;
+	gpio->set = max9286_gpio_set;
+	gpio->get = max9286_gpio_get;
+	gpio->can_sleep = true;
+	gpio->names = names;
+
+	/* GPIO values default to high */
+	priv->gpio_state = BIT(0) | BIT(1);
+
+	ret = devm_gpiochip_add_data(dev, gpio, priv);
+	if (ret)
+		dev_err(dev, "Unable to create gpio_chip\n");
+
+	dev_err(dev, "Created gpio_chip for MAX9286\n");
+
+	return ret;
+}
+
 static int max9286_init(struct device *dev)
 {
 	struct max9286_priv *priv;
@@ -984,6 +1044,14 @@ static int max9286_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
+	/*
+	 * It is possible to set up the power regulator from the GPIO lines,
+	 * so it needs to be set up early.
+	 */
+	ret = max9286_gpio(priv);
+	if (ret)
+		return ret;
+
 	priv->regulator = regulator_get(&client->dev, "poc");
 	if (IS_ERR(priv->regulator)) {
 		if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
Signature · 1 line
2.20.1
#21 lore raw

Re: [PATCH 2/3] media: i2c: max9286: Add GPIO chip controller

Hello me,

Quoted 83 lines · Kieran Bingham

Provide a GPIO chip to control the two output lines available on the MAX9286.

---
 drivers/media/i2c/max9286.c | 68 +++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
drivers/media/i2c/max9286.c +46 -0
index 6ea08fd87811..c34e7b5c7447 100644
@@ -13,6 +13,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/fwnode.h>
+#include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
 #include <linux/module.h>
@@ -58,6 +59,8 @@
 #define MAX9286_HVSRC_D0		(2 << 0)
 #define MAX9286_HVSRC_D14		(1 << 0)
 #define MAX9286_HVSRC_D18		(0 << 0)
+/* Register 0x0f */
+#define MAX9286_0X0F_RESERVED		BIT(3)
 /* Register 0x12 */
 #define MAX9286_CSILANECNT(n)		(((n) - 1) << 6)
 #define MAX9286_CSIDBL			BIT(5)
@@ -145,6 +148,9 @@ struct max9286_priv {
 	struct regulator *regulator;
 	bool poc_enabled;
 
+	struct gpio_chip gpio;
+	u8 gpio_state;
+
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
 	bool mux_open;
@@ -712,6 +718,60 @@ static const struct of_device_id max9286_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, max9286_dt_ids);
 
+static void max9286_gpio_set(struct gpio_chip *chip,
+			     unsigned int offset, int value)
+{
+	struct max9286_priv *priv = gpiochip_get_data(chip);
+
+	if (value)
+		priv->gpio_state |= BIT(offset);
+	else
+		priv->gpio_state &= ~BIT(offset);
+
+	max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | priv->gpio_state);
+}
+
+static int max9286_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+	struct max9286_priv *priv = gpiochip_get_data(chip);
+
+	return priv->gpio_state & BIT(offset);
+}
+
+static int max9286_gpio(struct max9286_priv *priv)
+{
+	struct device *dev = &priv->client->dev;
+	struct gpio_chip *gpio = &priv->gpio;
+	int ret;
+
+	static const char * const names[] = {
+		"GPIO0OUT",
+		"GPIO1OUT",
+	};
+
+	/* Configure the GPIO */
+	gpio->label = dev_name(dev);
+	gpio->parent = dev;
+	gpio->owner = THIS_MODULE;
+	gpio->of_node = dev->of_node;
+	gpio->ngpio = 2;
+	gpio->set = max9286_gpio_set;
+	gpio->get = max9286_gpio_get;
+	gpio->can_sleep = true;

drivers/media/i2c/max9286.c static const struct of_device_id max9286_dt_ids[] = { · line 770

Quoted 10 lines
drivers/media/i2c/max9286.c +10 -0
+	gpio->names = names;
+
+	/* GPIO values default to high */
+	priv->gpio_state = BIT(0) | BIT(1);
+
+	ret = devm_gpiochip_add_data(dev, gpio, priv);
+	if (ret)
+		dev_err(dev, "Unable to create gpio_chip\n");
+
+	dev_err(dev, "Created gpio_chip for MAX9286\n");

This debug line should be removed of course.

Now removed.

Quoted 23 lines
drivers/media/i2c/max9286.c +12 -0
+
+	return ret;
+}
+
 static int max9286_init(struct device *dev)
 {
 	struct max9286_priv *priv;
@@ -984,6 +1044,14 @@ static int max9286_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
+	/*
+	 * It is possible to set up the power regulator from the GPIO lines,
+	 * so it needs to be set up early.
+	 */
+	ret = max9286_gpio(priv);
+	if (ret)
+		return ret;
+
 	priv->regulator = regulator_get(&client->dev, "poc");
 	if (IS_ERR(priv->regulator)) {
 		if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
Signature · 3 lines
Regards
--
Kieran
#22 lore raw

Re: [PATCH 2/3] media: i2c: max9286: Add GPIO chip controller

Hi All,

Quoted 5 lines · Kieran Bingham

Hello me,

Quoted 2 lines · Kieran Bingham

Provide a GPIO chip to control the two output lines available on the MAX9286.

A separate mail thread to Mark Brown regarding the regulator topic [0] has suggested that this should be implemented as an MFD.

Does anyone have any comments on this approach? I know we've discussed the use of the MFD framework on this driver before ... thus perhaps it might be a bit contentious ...

Due to this, I am not yet going to fold this patch into the max9286 driver.

[0] Regulator probe on demand (or circular dependencies)
https://lore.kernel.org/linux-renesas-soc/[email protected]/T/#t

--
Regards

Kieran

Quoted 119 lines
Quoted 80 lines
---
 drivers/media/i2c/max9286.c | 68 +++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
drivers/media/i2c/max9286.c +46 -0
index 6ea08fd87811..c34e7b5c7447 100644
@@ -13,6 +13,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/fwnode.h>
+#include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
 #include <linux/module.h>
@@ -58,6 +59,8 @@
 #define MAX9286_HVSRC_D0		(2 << 0)
 #define MAX9286_HVSRC_D14		(1 << 0)
 #define MAX9286_HVSRC_D18		(0 << 0)
+/* Register 0x0f */
+#define MAX9286_0X0F_RESERVED		BIT(3)
 /* Register 0x12 */
 #define MAX9286_CSILANECNT(n)		(((n) - 1) << 6)
 #define MAX9286_CSIDBL			BIT(5)
@@ -145,6 +148,9 @@ struct max9286_priv {
 	struct regulator *regulator;
 	bool poc_enabled;
 
+	struct gpio_chip gpio;
+	u8 gpio_state;
+
 	struct i2c_mux_core *mux;
 	unsigned int mux_channel;
 	bool mux_open;
@@ -712,6 +718,60 @@ static const struct of_device_id max9286_dt_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, max9286_dt_ids);
 
+static void max9286_gpio_set(struct gpio_chip *chip,
+			     unsigned int offset, int value)
+{
+	struct max9286_priv *priv = gpiochip_get_data(chip);
+
+	if (value)
+		priv->gpio_state |= BIT(offset);
+	else
+		priv->gpio_state &= ~BIT(offset);
+
+	max9286_write(priv, 0x0f, MAX9286_0X0F_RESERVED | priv->gpio_state);
+}
+
+static int max9286_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+	struct max9286_priv *priv = gpiochip_get_data(chip);
+
+	return priv->gpio_state & BIT(offset);
+}
+
+static int max9286_gpio(struct max9286_priv *priv)
+{
+	struct device *dev = &priv->client->dev;
+	struct gpio_chip *gpio = &priv->gpio;
+	int ret;
+
+	static const char * const names[] = {
+		"GPIO0OUT",
+		"GPIO1OUT",
+	};
+
+	/* Configure the GPIO */
+	gpio->label = dev_name(dev);
+	gpio->parent = dev;
+	gpio->owner = THIS_MODULE;
+	gpio->of_node = dev->of_node;
+	gpio->ngpio = 2;
+	gpio->set = max9286_gpio_set;
+	gpio->get = max9286_gpio_get;
+	gpio->can_sleep = true;

drivers/media/i2c/max9286.c static const struct of_device_id max9286_dt_ids[] = { · line 770

Quoted 10 lines
drivers/media/i2c/max9286.c +10 -0
+	gpio->names = names;
+
+	/* GPIO values default to high */
+	priv->gpio_state = BIT(0) | BIT(1);
+
+	ret = devm_gpiochip_add_data(dev, gpio, priv);
+	if (ret)
+		dev_err(dev, "Unable to create gpio_chip\n");
+
+	dev_err(dev, "Created gpio_chip for MAX9286\n");

This debug line should be removed of course.

Now removed.

Quoted 23 lines
drivers/media/i2c/max9286.c +12 -0
+
+	return ret;
+}
+
 static int max9286_init(struct device *dev)
 {
 	struct max9286_priv *priv;
@@ -984,6 +1044,14 @@ static int max9286_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
+	/*
+	 * It is possible to set up the power regulator from the GPIO lines,
+	 * so it needs to be set up early.
+	 */
+	ret = max9286_gpio(priv);
+	if (ret)
+		return ret;
+
 	priv->regulator = regulator_get(&client->dev, "poc");
 	if (IS_ERR(priv->regulator)) {
 		if (PTR_ERR(priv->regulator) != -EPROBE_DEFER)
Signature · 3 lines
Regards
--
Kieran
#23 lore raw

PATCH 3/3 media: i2c: max9286: Provide optional enable-gpio

In reply to Kieran Bingham

The MAX9286 has a negated PWDN line which must be raised to enable the device. On the Eagle-V3M this pin is connected to a GPIO on the io_expander.

Provide an enable-gpio dt property to specify the link, and ensure that the line is handled in the driver accordingly.

This can also provide the abiltiy to manage low power states and runtime-pm at a later date by fully powering down the chip.

---
 drivers/media/i2c/max9286.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/media/i2c/max9286.c +13 -0
index c34e7b5c7447..67065cd99d8d 100644
@@ -13,6 +13,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/fwnode.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
@@ -143,6 +144,7 @@ struct max9286_source {
 
 struct max9286_priv {
 	struct i2c_client *client;
+	struct gpio_desc *gpiod_pwdn;
 	struct v4l2_subdev sd;
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
@@ -1044,6 +1046,14 @@ static int max9286_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
+	priv->gpiod_pwdn = devm_gpiod_get_optional(&client->dev, "enable",
+						   GPIOD_OUT_HIGH);
+	if (IS_ERR(priv->gpiod_pwdn))
+		return PTR_ERR(priv->gpiod_pwdn);
+
+	gpiod_set_consumer_name(priv->gpiod_pwdn, "max9286-pwdn");
+	gpiod_set_value_cansleep(priv->gpiod_pwdn, 1);
+
 	/*
 	 * It is possible to set up the power regulator from the GPIO lines,
 	 * so it needs to be set up early.
@@ -1117,6 +1127,9 @@ static int max9286_remove(struct i2c_client *client)
 	regulator_put(priv->regulator);
 
 	max9286_cleanup_dt(priv);
+
+	gpiod_set_value_cansleep(priv->gpiod_pwdn, 0);
+
 	kfree(priv);
 
 	return 0;
Signature · 1 line
2.20.1
#24 lore raw

Re: [PATCH 3/3] media: i2c: max9286: Provide optional enable-gpio

Hi all,

Quoted 11 lines · Kieran Bingham

The MAX9286 has a negated PWDN line which must be raised to enable the device. On the Eagle-V3M this pin is connected to a GPIO on the io_expander.

Provide an enable-gpio dt property to specify the link, and ensure that the line is handled in the driver accordingly.

This can also provide the abiltiy to manage low power states and runtime-pm at a later date by fully powering down the chip.

I'm happy that this one isn't going to cause any contention, and I'm going to fold this one into the driver.

--
Kieran

Quoted 50 lines
---
 drivers/media/i2c/max9286.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/media/i2c/max9286.c +13 -0
index c34e7b5c7447..67065cd99d8d 100644
@@ -13,6 +13,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/fwnode.h>
+#include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/i2c.h>
 #include <linux/i2c-mux.h>
@@ -143,6 +144,7 @@ struct max9286_source {
 
 struct max9286_priv {
 	struct i2c_client *client;
+	struct gpio_desc *gpiod_pwdn;
 	struct v4l2_subdev sd;
 	struct media_pad pads[MAX9286_N_PADS];
 	struct regulator *regulator;
@@ -1044,6 +1046,14 @@ static int max9286_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
+	priv->gpiod_pwdn = devm_gpiod_get_optional(&client->dev, "enable",
+						   GPIOD_OUT_HIGH);
+	if (IS_ERR(priv->gpiod_pwdn))
+		return PTR_ERR(priv->gpiod_pwdn);
+
+	gpiod_set_consumer_name(priv->gpiod_pwdn, "max9286-pwdn");
+	gpiod_set_value_cansleep(priv->gpiod_pwdn, 1);
+
 	/*
 	 * It is possible to set up the power regulator from the GPIO lines,
 	 * so it needs to be set up early.
@@ -1117,6 +1127,9 @@ static int max9286_remove(struct i2c_client *client)
 	regulator_put(priv->regulator);
 
 	max9286_cleanup_dt(priv);
+
+	gpiod_set_value_cansleep(priv->gpiod_pwdn, 0);
+
 	kfree(priv);
 
 	return 0;
Signature · 3 lines
Regards
--
Kieran
#25 lore raw

Re: [PATCH 1/3] media: i2c: max9286: Remove redundant max9286_i2c_mux_state

In reply to Kieran Bingham

Hi Kieran,

Quoted 6 lines · Kieran Bingham

While simplifying the i2c-mux state, the states were stored in an enum (initially there were three).

This has now simplified down to 2 states, open and closed - and can be represented easily in a bool.

Quoted 8 lines

It 'could' also be represented within the mux_channel, but I don't want to pollute that further than the '-1' value which is already stored in there to represent no channel selected.

Remove the max9286_i2c_mux_state and replace with a bool mux_open flag, and move the location within the private struct to be more appropriate.

Thanks for your patch!

drivers/media/i2c/max9286.c struct max9286_priv { · line 150

Quoted 11 lines
drivers/media/i2c/max9286.c +1 -1
@@ -144,10 +144,10 @@ struct max9286_priv {
        struct media_pad pads[MAX9286_N_PADS];
        struct regulator *regulator;
        bool poc_enabled;
-       int mux_state;
 
        struct i2c_mux_core *mux;
        unsigned int mux_channel;
+       bool mux_open;

Please keep all booleans together, to fill up holes due to alignment restrictions.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#26 lore raw

Re: [PATCH 1/3] media: i2c: max9286: Remove redundant max9286_i2c_mux_state

Hi Geert,

Quoted 29 lines · Geert Uytterhoeven

Hi Kieran,

Quoted 6 lines · Kieran Bingham

While simplifying the i2c-mux state, the states were stored in an enum (initially there were three).

This has now simplified down to 2 states, open and closed - and can be represented easily in a bool.

Quoted 8 lines

It 'could' also be represented within the mux_channel, but I don't want to pollute that further than the '-1' value which is already stored in there to represent no channel selected.

Remove the max9286_i2c_mux_state and replace with a bool mux_open flag, and move the location within the private struct to be more appropriate.

Thanks for your patch!

Quoted 8 lines
drivers/media/i2c/max9286.c +0 -1
@@ -144,10 +144,10 @@ struct max9286_priv {
        struct media_pad pads[MAX9286_N_PADS];
        struct regulator *regulator;
        bool poc_enabled;
-       int mux_state;
 
Quoted 6 lines

drivers/media/i2c/max9286.c struct max9286_priv { · line 150

Quoted 3 lines
drivers/media/i2c/max9286.c +1 -0
        struct i2c_mux_core *mux;
        unsigned int mux_channel;
+       bool mux_open;

Please keep all booleans together, to fill up holes due to alignment restrictions.

I was trying to group related i2c_mux items, but I do indeed see a strong argument there...

/me digs out pahole just to have a look :-D (but I know what the answer is)

struct max9286_priv {

struct i2c_client *        client;               /*     0     8 */
struct gpio_desc *         gpiod_pwdn;           /*     8     8 */
struct v4l2_subdev         sd;                   /*    16   320 */
/* --- cacheline 5 boundary (320 bytes) was 16 bytes ago --- */
struct media_pad           pads[5];              /*   336   280 */
/* --- cacheline 9 boundary (576 bytes) was 40 bytes ago --- */
struct regulator *         regulator;            /*   616     8 */
struct dentry *            dbgroot;              /*   624     8 */
bool                       poc_enabled;          /*   632     1 */

/* XXX 7 bytes hole, try to pack */
/* --- cacheline 10 boundary (640 bytes) --- */

struct gpio_chip gpio; /* 640 600 */
/* --- cacheline 19 boundary (1216 bytes) was 24 bytes ago --- */

u8 gpio_state; /* 1240 1 */
/* XXX 7 bytes hole, try to pack */

struct i2c_mux_core *      mux;                  /*  1248     8 /
unsigned int               mux_channel;          /*  1256     4 */
bool                       mux_open;             /*  1260     1 */

/* XXX 3 bytes hole, try to pack */

struct v4l2_ctrl_handler ctrls; /* 1264 296 */
/* --- cacheline 24 boundary (1536 bytes) was 24 bytes ago --- */
struct v4l2_mbus_framefmt fmt[4]; /* 1560 192 */
/* --- cacheline 27 boundary (1728 bytes) was 24 bytes ago --- */

unsigned int               nsources;             /*  1752     4 */
unsigned int               source_mask;          /*  1756     4 */
unsigned int               route_mask;           /*  1760     4 */
unsigned int               csi2_data_lanes;      /*  1764     4 */
struct max9286_source      sources[4];           /*  1768   288 */

/* --- cacheline 32 boundary (2048 bytes) was 8 bytes ago --- */
struct v4l2_async_notifier notifier; /* 2056 96 */

/* size: 2152, cachelines: 34, members: 20 */
/* sum members: 2135, holes: 3, sum holes: 17 */
/* last cacheline: 40 bytes */
};

Hrm ... this one really pulls me in both directions ... Which is the lesser evil - memory holes or ungrouped variables?

--
Kieran

Quoted 4 lines

Gr{oetje,eeting}s,

Geert

#27 lore raw

Re: [PATCH 1/3] media: i2c: max9286: Remove redundant max9286_i2c_mux_state

Hi All,

Quoted 21 lines · Kieran Bingham

Hi Geert,

Quoted 18 lines · Geert Uytterhoeven

Hi Kieran,

Quoted 14 lines · Kieran Bingham

While simplifying the i2c-mux state, the states were stored in an enum (initially there were three).

This has now simplified down to 2 states, open and closed - and can be represented easily in a bool.

It 'could' also be represented within the mux_channel, but I don't want to pollute that further than the '-1' value which is already stored in there to represent no channel selected.

Remove the max9286_i2c_mux_state and replace with a bool mux_open flag, and move the location within the private struct to be more appropriate.

Folding this patch into the max9286 driver without correcting for holes, as I believe it's better to group the associated variables together, and accept the small loss, as the structure is very large so it's a small proportion.

--
Kieran

Quoted 79 lines
Quoted 11 lines

Thanks for your patch!

Quoted 8 lines
drivers/media/i2c/max9286.c +0 -1
@@ -144,10 +144,10 @@ struct max9286_priv {
        struct media_pad pads[MAX9286_N_PADS];
        struct regulator *regulator;
        bool poc_enabled;
-       int mux_state;
 
Quoted 6 lines

drivers/media/i2c/max9286.c struct max9286_priv { · line 150

Quoted 3 lines
drivers/media/i2c/max9286.c +1 -0
        struct i2c_mux_core *mux;
        unsigned int mux_channel;
+       bool mux_open;

Please keep all booleans together, to fill up holes due to alignment restrictions.

I was trying to group related i2c_mux items, but I do indeed see a strong argument there...

/me digs out pahole just to have a look :-D (but I know what the answer is)

struct max9286_priv {

struct i2c_client *        client;               /*     0     8 */
struct gpio_desc *         gpiod_pwdn;           /*     8     8 */
struct v4l2_subdev         sd;                   /*    16   320 */
/* --- cacheline 5 boundary (320 bytes) was 16 bytes ago --- */
struct media_pad           pads[5];              /*   336   280 */
/* --- cacheline 9 boundary (576 bytes) was 40 bytes ago --- */
struct regulator *         regulator;            /*   616     8 */
struct dentry *            dbgroot;              /*   624     8 */
bool                       poc_enabled;          /*   632     1 */

/* XXX 7 bytes hole, try to pack */
/* --- cacheline 10 boundary (640 bytes) --- */

struct gpio_chip gpio; /* 640 600 */
/* --- cacheline 19 boundary (1216 bytes) was 24 bytes ago --- */

u8 gpio_state; /* 1240 1 */
/* XXX 7 bytes hole, try to pack */

struct i2c_mux_core *      mux;                  /*  1248     8 /
unsigned int               mux_channel;          /*  1256     4 */
bool                       mux_open;             /*  1260     1 */

/* XXX 3 bytes hole, try to pack */

struct v4l2_ctrl_handler ctrls; /* 1264 296 */
/* --- cacheline 24 boundary (1536 bytes) was 24 bytes ago --- */
struct v4l2_mbus_framefmt fmt[4]; /* 1560 192 */
/* --- cacheline 27 boundary (1728 bytes) was 24 bytes ago --- */

unsigned int               nsources;             /*  1752     4 */
unsigned int               source_mask;          /*  1756     4 */
unsigned int               route_mask;           /*  1760     4 */
unsigned int               csi2_data_lanes;      /*  1764     4 */
struct max9286_source      sources[4];           /*  1768   288 */

/* --- cacheline 32 boundary (2048 bytes) was 8 bytes ago --- */
struct v4l2_async_notifier notifier; /* 2056 96 */

/* size: 2152, cachelines: 34, members: 20 */
/* sum members: 2135, holes: 3, sum holes: 17 */
/* last cacheline: 40 bytes */
};

Hrm ... this one really pulls me in both directions ... Which is the lesser evil - memory holes or ungrouped variables?

--
Kieran

Quoted 4 lines

Gr{oetje,eeting}s,

Geert

Signature · 3 lines
Regards
--
Kieran
author maintainer
#28 lore raw

PATCH 1/1 dt-bindings: media: i2c: max9286: Specify 'type'

In reply to Jacopo Mondi

Add the 'type' tag to a few entries to fix the warning reported by the most recent dtschema validator

Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml:
properties:i2c-mux: 'type' is a dependency of 'properties'

---
Hi Kieran,
I know you're collecting patches to re-submit max9286 support.

Please squash this on top of the dt bindings documentation patch to fix an issue reported by recent version of the dtschema validator.

Thanks
j

---
 Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/media/i2c/maxim,max9286.yaml +3 -0
index 731e317ef4ce..d37ea2c432f6 100644
@@ -73,6 +73,7 @@ properties:
         const: 0
 
       port@[0-3]:
+        type: object
         properties:
           reg:
             enum: [ 0, 1, 2, 3 ]
@@ -97,6 +98,7 @@ properties:
         additionalProperties: false
 
       port@4:
+        type: object
         properties:
           reg:
             const: 4
@@ -126,6 +128,7 @@ properties:
       - port@4
 
   i2c-mux:
+    type: object
     description: -|
       Each GMSL link is modelled as a child bus of an i2c bus
       multiplexer/switch, in accordance with bindings described in

--
2.24.0