All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/4] megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28 ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart

The video processing pipeline on the second output on the GE B850v3:

  Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output

Each bridge has a dedicated flash containing firmware for supporting the
custom design. The result is that in this design neither the STDP4028
nor the STDP2690 behave as the stock bridges would. The compatible
strings include the suffix "-ge-b850v3-fw" to make it clear that the
driver is for the bridges with the firmware which is specific for the GE
B850v3.

The driver is powerless to control the video processing pipeline, as the
two bridges behaves as a single one. The driver is only needed for
telling the host about EDID / HPD, and for giving the host powers to ack
interrupts.

Changes from V1:
 - Fix bindings documentation
 - Fix white space issues on the driver
 - Improved ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid

Changes from V7(was GE B850v3 LVDS/DP++ Bridge):
 - New devicetree binding with one node per bridge, and two ports per bridge
 - Two i2c_devices, one per bridge
 - Removed uneeded mutexes
 - Moved documentation to bindings/display/bridge
 - Included test for EDID extension blocks
 - Renamed bridge pointer to ge_b850v3_lvds_ptr
 - Removed the call to drm_helper_hpd_irq_event()
 - Removed assignments to bridge.driver_private

Changes from V6:
 - Removed check for pixel clock as the bridge supports up to 330Mhz while the
   host is limited to 264 MHz in very specific conditions.
 - Added a second mutex to avoid concurrency issues while acking interrupts
   from threaded interrupt handlers.
 - Renamed the edid mutex to be more descriptive.
 - Added a .detach() function that disables the interrupts.
 - Adopted i2c_new_secondary_device() and updated the dts and documentation to
   match the new method.
 - Removed useless test to drm_bridge_add()
 - Did some refactoring around devm_request_threaded_irq()
 - Added a missing call to i2c_unregister_device() on the i2c_driver.remove()
   function.

Changes from V5:
 - Change to MAINTAINERS in a separate patch
 - Reworked interrupt handler initialization
 - Removed useless calls to: drm_connector_register(),
   drm_helper_hpd_irq_event(), and drm_bridge_enable()

Changes from V4:
 - Renamed the i2c_driver.name from "ge,b850v3-lvds-dp" to "b850v3-lvds-dp" to
   remove the comma from the driver name

Changes from V3:
 - Removed the patch that was configuring the mapping between IPUs and external
   displays on the dts file

Peter Senna Tschudin (4):
  dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
  MAINTAINERS: Add entry for megachips-stdpxxxx-ge-b850v3-fw
  drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  dts/imx6q-b850v3: Use megachips-stdpxxxx-ge-b850v3-fw bridges
    (LVDS-DP++)

 .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     |  94 +++++
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 MAINTAINERS                                        |   8 +
 arch/arm/boot/dts/imx6q-b850v3.dts                 |  68 ++++
 drivers/gpu/drm/bridge/Kconfig                     |  11 +
 drivers/gpu/drm/bridge/Makefile                    |   1 +
 .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
 7 files changed, 594 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
 create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c

-- 
2.9.3

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

* [PATCH V2 0/4] megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28 ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: linux-arm-kernel

The video processing pipeline on the second output on the GE B850v3:

  Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output

Each bridge has a dedicated flash containing firmware for supporting the
custom design. The result is that in this design neither the STDP4028
nor the STDP2690 behave as the stock bridges would. The compatible
strings include the suffix "-ge-b850v3-fw" to make it clear that the
driver is for the bridges with the firmware which is specific for the GE
B850v3.

The driver is powerless to control the video processing pipeline, as the
two bridges behaves as a single one. The driver is only needed for
telling the host about EDID / HPD, and for giving the host powers to ack
interrupts.

Changes from V1:
 - Fix bindings documentation
 - Fix white space issues on the driver
 - Improved ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid

Changes from V7(was GE B850v3 LVDS/DP++ Bridge):
 - New devicetree binding with one node per bridge, and two ports per bridge
 - Two i2c_devices, one per bridge
 - Removed uneeded mutexes
 - Moved documentation to bindings/display/bridge
 - Included test for EDID extension blocks
 - Renamed bridge pointer to ge_b850v3_lvds_ptr
 - Removed the call to drm_helper_hpd_irq_event()
 - Removed assignments to bridge.driver_private

Changes from V6:
 - Removed check for pixel clock as the bridge supports up to 330Mhz while the
   host is limited to 264 MHz in very specific conditions.
 - Added a second mutex to avoid concurrency issues while acking interrupts
   from threaded interrupt handlers.
 - Renamed the edid mutex to be more descriptive.
 - Added a .detach() function that disables the interrupts.
 - Adopted i2c_new_secondary_device() and updated the dts and documentation to
   match the new method.
 - Removed useless test to drm_bridge_add()
 - Did some refactoring around devm_request_threaded_irq()
 - Added a missing call to i2c_unregister_device() on the i2c_driver.remove()
   function.

Changes from V5:
 - Change to MAINTAINERS in a separate patch
 - Reworked interrupt handler initialization
 - Removed useless calls to: drm_connector_register(),
   drm_helper_hpd_irq_event(), and drm_bridge_enable()

Changes from V4:
 - Renamed the i2c_driver.name from "ge,b850v3-lvds-dp" to "b850v3-lvds-dp" to
   remove the comma from the driver name

Changes from V3:
 - Removed the patch that was configuring the mapping between IPUs and external
   displays on the dts file

Peter Senna Tschudin (4):
  dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
  MAINTAINERS: Add entry for megachips-stdpxxxx-ge-b850v3-fw
  drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  dts/imx6q-b850v3: Use megachips-stdpxxxx-ge-b850v3-fw bridges
    (LVDS-DP++)

 .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     |  94 +++++
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 MAINTAINERS                                        |   8 +
 arch/arm/boot/dts/imx6q-b850v3.dts                 |  68 ++++
 drivers/gpu/drm/bridge/Kconfig                     |  11 +
 drivers/gpu/drm/bridge/Makefile                    |   1 +
 .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
 7 files changed, 594 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
 create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c

-- 
2.9.3

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

* [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
  2017-02-28 14:28 ` Peter Senna Tschudin
  (?)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  -1 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Rob Herring, Fabio Estevam, Rask Ingemann Lambertsen

Devicetree binding documentation for the second video output
of the GE B850v3:
   STDP4028-ge-b850v3-fw bridges (LVDS-DP)
   STDP2690-ge-b850v3-fw bridges (DP-DP++)

Added entry for MegaChips at:
 Documentation/devicetree/bindings/vendor-prefixes.txt

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Javier Martinez Canillas <javier@dowhile0.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Changes from V1:
 - New subject
 - Moved binding documentation from bindings/video/ to bindings/display/bridge/
 - Reworded to describe hardware instead of the driver
 - Reformated the bindings to have one set of required properties per device
 - Updated reg description
 - Defined number of ports and what they are for

 .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     | 94 ++++++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 2 files changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt

diff --git a/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt b/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
new file mode 100644
index 0000000..7baa658
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
@@ -0,0 +1,94 @@
+Drivers for the second video output of the GE B850v3:
+   STDP4028-ge-b850v3-fw bridges (LVDS-DP)
+   STDP2690-ge-b850v3-fw bridges (DP-DP++)
+
+The video processing pipeline on the second output on the GE B850v3:
+
+   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+
+Each bridge has a dedicated flash containing firmware for supporting the custom
+design. The result is that, in this design, neither the STDP4028 nor the
+STDP2690 behave as the stock bridges would. The compatible strings include the
+suffix "-ge-b850v3-fw" to make it clear that the driver is for the bridges with
+the firmware specific for the GE B850v3.
+
+The hardware do not provide control over the video processing pipeline, as the
+two bridges behaves as a single one. The only interfaces exposed by the
+hardware are EDID, HPD, and interrupts.
+
+stdp4028-ge-b850v3-fw required properties:
+  - compatible : "megachips,stdp4028-ge-b850v3-fw"
+  - reg : I2C bus address
+  - interrupt-parent : phandle of the interrupt controller that services
+    interrupts to the device
+  - interrupts : one interrupt should be described here, as in
+    <0 IRQ_TYPE_LEVEL_HIGH>
+  - ports : One input port(reg = <0>) and one output port(reg = <1>)
+
+stdp2690-ge-b850v3-fw required properties:
+    compatible : "megachips,stdp2690-ge-b850v3-fw"
+  - reg : I2C bus address
+  - ports : One input port(reg = <0>) and one output port(reg = <1>)
+
+Example:
+
+&mux2_i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+
+	stdp4028@73 {
+		compatible = "megachips,stdp4028-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x73>;
+
+		interrupt-parent = <&gpio2>;
+		interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp4028_in: endpoint {
+					remote-endpoint = <&lvds0_out>;
+				};
+			};
+			port@1 {
+				reg = <1>;
+				stdp4028_out: endpoint {
+					remote-endpoint = <&stdp2690_in>;
+				};
+			};
+		};
+	};
+
+	stdp2690@72 {
+		compatible = "megachips,stdp2690-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x72>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp2690_in: endpoint {
+					remote-endpoint = <&stdp4028_out>;
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				stdp2690_out: endpoint {
+					/* Connector for external display */
+				};
+			};
+		};
+	};
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index ec0bfb9..4686f4b 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -178,6 +178,7 @@ maxim	Maxim Integrated Products
 mcube	mCube
 meas	Measurement Specialties
 mediatek	MediaTek Inc.
+megachips	MegaChips
 melexis	Melexis N.V.
 melfas	MELFAS Inc.
 memsic	MEMSIC Inc.
-- 
2.9.3

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

* [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Fabio Estevam, Rob Herring, Rask Ingemann Lambertsen

Devicetree binding documentation for the second video output
of the GE B850v3:
   STDP4028-ge-b850v3-fw bridges (LVDS-DP)
   STDP2690-ge-b850v3-fw bridges (DP-DP++)

Added entry for MegaChips at:
 Documentation/devicetree/bindings/vendor-prefixes.txt

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Javier Martinez Canillas <javier@dowhile0.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Changes from V1:
 - New subject
 - Moved binding documentation from bindings/video/ to bindings/display/bridge/
 - Reworded to describe hardware instead of the driver
 - Reformated the bindings to have one set of required properties per device
 - Updated reg description
 - Defined number of ports and what they are for

 .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     | 94 ++++++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 2 files changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt

diff --git a/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt b/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
new file mode 100644
index 0000000..7baa658
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
@@ -0,0 +1,94 @@
+Drivers for the second video output of the GE B850v3:
+   STDP4028-ge-b850v3-fw bridges (LVDS-DP)
+   STDP2690-ge-b850v3-fw bridges (DP-DP++)
+
+The video processing pipeline on the second output on the GE B850v3:
+
+   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+
+Each bridge has a dedicated flash containing firmware for supporting the custom
+design. The result is that, in this design, neither the STDP4028 nor the
+STDP2690 behave as the stock bridges would. The compatible strings include the
+suffix "-ge-b850v3-fw" to make it clear that the driver is for the bridges with
+the firmware specific for the GE B850v3.
+
+The hardware do not provide control over the video processing pipeline, as the
+two bridges behaves as a single one. The only interfaces exposed by the
+hardware are EDID, HPD, and interrupts.
+
+stdp4028-ge-b850v3-fw required properties:
+  - compatible : "megachips,stdp4028-ge-b850v3-fw"
+  - reg : I2C bus address
+  - interrupt-parent : phandle of the interrupt controller that services
+    interrupts to the device
+  - interrupts : one interrupt should be described here, as in
+    <0 IRQ_TYPE_LEVEL_HIGH>
+  - ports : One input port(reg = <0>) and one output port(reg = <1>)
+
+stdp2690-ge-b850v3-fw required properties:
+    compatible : "megachips,stdp2690-ge-b850v3-fw"
+  - reg : I2C bus address
+  - ports : One input port(reg = <0>) and one output port(reg = <1>)
+
+Example:
+
+&mux2_i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+
+	stdp4028@73 {
+		compatible = "megachips,stdp4028-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x73>;
+
+		interrupt-parent = <&gpio2>;
+		interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp4028_in: endpoint {
+					remote-endpoint = <&lvds0_out>;
+				};
+			};
+			port@1 {
+				reg = <1>;
+				stdp4028_out: endpoint {
+					remote-endpoint = <&stdp2690_in>;
+				};
+			};
+		};
+	};
+
+	stdp2690@72 {
+		compatible = "megachips,stdp2690-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x72>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp2690_in: endpoint {
+					remote-endpoint = <&stdp4028_out>;
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				stdp2690_out: endpoint {
+					/* Connector for external display */
+				};
+			};
+		};
+	};
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index ec0bfb9..4686f4b 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -178,6 +178,7 @@ maxim	Maxim Integrated Products
 mcube	mCube
 meas	Measurement Specialties
 mediatek	MediaTek Inc.
+megachips	MegaChips
 melexis	Melexis N.V.
 melfas	MELFAS Inc.
 memsic	MEMSIC Inc.
-- 
2.9.3

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

* [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: linux-arm-kernel

Devicetree binding documentation for the second video output
of the GE B850v3:
   STDP4028-ge-b850v3-fw bridges (LVDS-DP)
   STDP2690-ge-b850v3-fw bridges (DP-DP++)

Added entry for MegaChips at:
 Documentation/devicetree/bindings/vendor-prefixes.txt

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Javier Martinez Canillas <javier@dowhile0.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Changes from V1:
 - New subject
 - Moved binding documentation from bindings/video/ to bindings/display/bridge/
 - Reworded to describe hardware instead of the driver
 - Reformated the bindings to have one set of required properties per device
 - Updated reg description
 - Defined number of ports and what they are for

 .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     | 94 ++++++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 2 files changed, 95 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt

diff --git a/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt b/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
new file mode 100644
index 0000000..7baa658
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
@@ -0,0 +1,94 @@
+Drivers for the second video output of the GE B850v3:
+   STDP4028-ge-b850v3-fw bridges (LVDS-DP)
+   STDP2690-ge-b850v3-fw bridges (DP-DP++)
+
+The video processing pipeline on the second output on the GE B850v3:
+
+   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+
+Each bridge has a dedicated flash containing firmware for supporting the custom
+design. The result is that, in this design, neither the STDP4028 nor the
+STDP2690 behave as the stock bridges would. The compatible strings include the
+suffix "-ge-b850v3-fw" to make it clear that the driver is for the bridges with
+the firmware specific for the GE B850v3.
+
+The hardware do not provide control over the video processing pipeline, as the
+two bridges behaves as a single one. The only interfaces exposed by the
+hardware are EDID, HPD, and interrupts.
+
+stdp4028-ge-b850v3-fw required properties:
+  - compatible : "megachips,stdp4028-ge-b850v3-fw"
+  - reg : I2C bus address
+  - interrupt-parent : phandle of the interrupt controller that services
+    interrupts to the device
+  - interrupts : one interrupt should be described here, as in
+    <0 IRQ_TYPE_LEVEL_HIGH>
+  - ports : One input port(reg = <0>) and one output port(reg = <1>)
+
+stdp2690-ge-b850v3-fw required properties:
+    compatible : "megachips,stdp2690-ge-b850v3-fw"
+  - reg : I2C bus address
+  - ports : One input port(reg = <0>) and one output port(reg = <1>)
+
+Example:
+
+&mux2_i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+
+	stdp4028 at 73 {
+		compatible = "megachips,stdp4028-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x73>;
+
+		interrupt-parent = <&gpio2>;
+		interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port at 0 {
+				reg = <0>;
+				stdp4028_in: endpoint {
+					remote-endpoint = <&lvds0_out>;
+				};
+			};
+			port at 1 {
+				reg = <1>;
+				stdp4028_out: endpoint {
+					remote-endpoint = <&stdp2690_in>;
+				};
+			};
+		};
+	};
+
+	stdp2690 at 72 {
+		compatible = "megachips,stdp2690-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x72>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port at 0 {
+				reg = <0>;
+				stdp2690_in: endpoint {
+					remote-endpoint = <&stdp4028_out>;
+				};
+			};
+
+			port at 1 {
+				reg = <1>;
+				stdp2690_out: endpoint {
+					/* Connector for external display */
+				};
+			};
+		};
+	};
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index ec0bfb9..4686f4b 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -178,6 +178,7 @@ maxim	Maxim Integrated Products
 mcube	mCube
 meas	Measurement Specialties
 mediatek	MediaTek Inc.
+megachips	MegaChips
 melexis	Melexis N.V.
 melfas	MELFAS Inc.
 memsic	MEMSIC Inc.
-- 
2.9.3

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

* [PATCH V2 2/4] MAINTAINERS: Add entry for megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Rob Herring, Fabio Estevam

Add MAINTAINERS entry for the second video output of the GE B850v3:
       STDP4028-ge-b850v3-fw bridges (LVDS-DP)
       STDP2690-ge-b850v3-fw bridges (DP-DP++)

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
CC: David Airlie <airlied@linux.ie>
CC: Thierry Reding <treding@nvidia.com>
CC: Thierry Reding <thierry.reding@gmail.com>
CC: Archit Taneja <architt@codeaurora.org>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Unchanged from V1

 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8d97b1d..5f30b17 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8129,6 +8129,14 @@ L:	linux-wireless@vger.kernel.org
 S:	Maintained
 F:	drivers/net/wireless/mediatek/mt7601u/
 
+MEGACHIPS STDPXXXX-GE-B850V3-FW LVDS/DP++ BRIDGES
+M:	Peter Senna Tschudin <peter.senna@collabora.com>
+M:	Martin Donnelly <martin.donnelly@ge.com>
+M:	Martyn Welch <martyn.welch@collabora.co.uk>
+S:	Maintained
+F:	drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
+F:	Documentation/devicetree/bindings/video/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
+
 MEGARAID SCSI/SAS DRIVERS
 M:	Kashyap Desai <kashyap.desai@broadcom.com>
 M:	Sumit Saxena <sumit.saxena@broadcom.com>
-- 
2.9.3

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

* [PATCH V2 2/4] MAINTAINERS: Add entry for megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied-cv59FeDIM0c, architt-sgV2jX0FEOL9JmXXK+q4OQ,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, daniel.vetter-/w4YWyX8dFk,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q, devicetree-u79uwXL29TY76Z2rM5mHXA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ,
	eballetbo-Re5JQEeQqe8AvxtiuMwx3w, galak-sgV2jX0FEOL9JmXXK+q4OQ,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	heiko-4mtYJXux2i+zQB+pC5nmwQ,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	javier-0uQlZySMnqxg9hUCZPvPmw, jslaby-AlSwsSmVLrQ,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-I+IVW8TIWO2tmTQ+vhA3Yw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-0h96xk9xTtrk1uMJSBkQmQ, mark.rutland-5wv7dgnIgG8,
	martin.donnelly-JJi787mZWgc, martyn.welch-ZGY8ohtN/8pPYcu2f3hruQ,
	mchehab-JPH+aEBZ4P+UEJcrhfAQsw, pawel.moll-5wv7dgnIgG8,
	peter.senna-ZGY8ohtN/8qB+jHODAdFcQ,
	peter.senna-Re5JQEeQqe8AvxtiuMwx3w,
	p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ,
	thierry.reding-Re5JQEeQqe8AvxtiuMwx3w,
	rmk+kernel-I+IVW8TIWO2tmTQ+vhA3Yw,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, shawnguo-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Rob Herring, Fabio Estevam

Add MAINTAINERS entry for the second video output of the GE B850v3:
       STDP4028-ge-b850v3-fw bridges (LVDS-DP)
       STDP2690-ge-b850v3-fw bridges (DP-DP++)

Cc: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
Cc: Martyn Welch <martyn.welch-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org>
Cc: Martin Donnelly <martin.donnelly-JJi787mZWgc@public.gmane.org>
Cc: Daniel Vetter <daniel.vetter-/w4YWyX8dFk@public.gmane.org>
Cc: Enric Balletbo i Serra <enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
Cc: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Fabio Estevam <fabio.estevam-3arQi8VN3Tc@public.gmane.org>
CC: David Airlie <airlied-cv59FeDIM0c@public.gmane.org>
CC: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
CC: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
CC: Archit Taneja <architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Signed-off-by: Peter Senna Tschudin <peter.senna-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
Unchanged from V1

 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8d97b1d..5f30b17 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8129,6 +8129,14 @@ L:	linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
 S:	Maintained
 F:	drivers/net/wireless/mediatek/mt7601u/
 
+MEGACHIPS STDPXXXX-GE-B850V3-FW LVDS/DP++ BRIDGES
+M:	Peter Senna Tschudin <peter.senna-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
+M:	Martin Donnelly <martin.donnelly-JJi787mZWgc@public.gmane.org>
+M:	Martyn Welch <martyn.welch-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org>
+S:	Maintained
+F:	drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
+F:	Documentation/devicetree/bindings/video/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
+
 MEGARAID SCSI/SAS DRIVERS
 M:	Kashyap Desai <kashyap.desai-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
 M:	Sumit Saxena <sumit.saxena-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH V2 2/4] MAINTAINERS: Add entry for megachips-stdpxxxx-ge-b850v3-fw
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: linux-arm-kernel

Add MAINTAINERS entry for the second video output of the GE B850v3:
       STDP4028-ge-b850v3-fw bridges (LVDS-DP)
       STDP2690-ge-b850v3-fw bridges (DP-DP++)

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
CC: David Airlie <airlied@linux.ie>
CC: Thierry Reding <treding@nvidia.com>
CC: Thierry Reding <thierry.reding@gmail.com>
CC: Archit Taneja <architt@codeaurora.org>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Unchanged from V1

 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8d97b1d..5f30b17 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8129,6 +8129,14 @@ L:	linux-wireless at vger.kernel.org
 S:	Maintained
 F:	drivers/net/wireless/mediatek/mt7601u/
 
+MEGACHIPS STDPXXXX-GE-B850V3-FW LVDS/DP++ BRIDGES
+M:	Peter Senna Tschudin <peter.senna@collabora.com>
+M:	Martin Donnelly <martin.donnelly@ge.com>
+M:	Martyn Welch <martyn.welch@collabora.co.uk>
+S:	Maintained
+F:	drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
+F:	Documentation/devicetree/bindings/video/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt
+
 MEGARAID SCSI/SAS DRIVERS
 M:	Kashyap Desai <kashyap.desai@broadcom.com>
 M:	Sumit Saxena <sumit.saxena@broadcom.com>
-- 
2.9.3

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  2017-02-28 14:28 ` Peter Senna Tschudin
  (?)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  -1 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Rob Herring, Fabio Estevam

The video processing pipeline on the second output on the GE B850v3:

  Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output

Each bridge has a dedicated flash containing firmware for supporting the
custom design. The result is that in this design neither the STDP4028
nor the STDP2690 behave as the stock bridges would. The compatible
strings include the suffix "-ge-b850v3-fw" to make it clear that the
driver is for the bridges with the firmware which is specific for the GE
B850v3.

The driver is powerless to control the video processing pipeline, as the
two bridges behaves as a single one. The driver is only needed for
telling the host about EDID / HPD, and for giving the host powers to ack
interrupts.

This driver adds one i2c_device for each bridge, but only one
drm_bridge. This design allows the creation of a functional connector
that is capable of reading EDID from the STDP2690 while handling
interrupts on the STDP4028.

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Archit Taneja <architt@codeaurora.org>
Cc: Enric Balletbo <enric.balletbo@collabora.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Changes from V1:
 - Updated copyright year
 - Fixed blank line issues
 - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
   added a comment to explain the test.
 - Fixed checkpatch strict warnings about continuation lines. In one case
   fixing the warning would cause the continuation line to be over 80 chars and
   that strict warning remains.

 drivers/gpu/drm/bridge/Kconfig                     |  11 +
 drivers/gpu/drm/bridge/Makefile                    |   1 +
 .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index eb8688e..4a937f1 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
 	  Support the I2S Audio interface which is part of the Synopsis
 	  Designware HDMI block.
 
+config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
+	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_PANEL
+	---help---
+          This is a driver for the display bridges of
+          GE B850v3 that convert dual channel LVDS
+          to DP++. This is used with the i.MX6 imx-ldb
+          driver. You are likely to say N here.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2e83a785..af0b7cc 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
new file mode 100644
index 0000000..6f82a44
--- /dev/null
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -0,0 +1,411 @@
+/*
+ * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
+ * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
+
+ * Copyright (c) 2017, Collabora Ltd.
+ * Copyright (c) 2017, General Electric Company
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
+ * display bridge of the GE B850v3. There are two physical bridges on the video
+ * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
+ * physical bridges are automatically configured by the input video signal, and
+ * the driver has no access to the video processing pipeline. The driver is
+ * only needed to read EDID from the STDP2690 and to handle HPD events from the
+ * STDP4028. The driver communicates with both bridges over i2c. The video
+ * signal pipeline is as follows:
+ *
+ *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drmP.h>
+
+#define EDID_EXT_BLOCK_CNT 0x7E
+
+#define STDP4028_IRQ_OUT_CONF_REG 0x02
+#define STDP4028_DPTX_IRQ_EN_REG 0x3C
+#define STDP4028_DPTX_IRQ_STS_REG 0x3D
+#define STDP4028_DPTX_STS_REG 0x3E
+
+#define STDP4028_DPTX_DP_IRQ_EN 0x1000
+
+#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
+#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
+#define STDP4028_DPTX_IRQ_CONFIG \
+		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
+
+#define STDP4028_DPTX_HOTPLUG_STS 0x0200
+#define STDP4028_DPTX_LINK_STS 0x1000
+#define STDP4028_CON_STATE_CONNECTED \
+		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
+
+#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
+#define STDP4028_DPTX_LINK_CH_STS 0x2000
+#define STDP4028_DPTX_IRQ_CLEAR \
+		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
+
+static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
+
+struct ge_b850v3_lvds {
+	struct drm_connector connector;
+	struct drm_bridge bridge;
+	struct i2c_client *stdp4028_i2c;
+	struct i2c_client *stdp2690_i2c;
+	struct edid *edid;
+};
+
+static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
+
+u8 *stdp2690_get_edid(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	unsigned char start = 0x00;
+	unsigned int total_size;
+	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= client->addr,
+			.flags	= 0,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= client->addr,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+			.buf	= block,
+		}
+	};
+
+	if (!block)
+		return NULL;
+
+	if (i2c_transfer(adapter, msgs, 2) != 2) {
+		DRM_ERROR("Unable to read EDID.\n");
+		goto err;
+	}
+
+	if (!drm_edid_block_valid(block, 0, false, NULL)) {
+		DRM_ERROR("Invalid EDID data\n");
+		goto err;
+	}
+
+	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
+	if (total_size > EDID_LENGTH) {
+		kfree(block);
+		block = kmalloc(total_size, GFP_KERNEL);
+		if (!block)
+			return NULL;
+
+		/* Yes, read the entire buffer, and do not skip the first
+		 * EDID_LENGTH bytes.
+		 */
+		start = 0x00;
+		msgs[1].len = total_size;
+		msgs[1].buf = block;
+
+		if (i2c_transfer(adapter, msgs, 2) != 2) {
+			DRM_ERROR("Unable to read EDID extension blocks.\n");
+			goto err;
+		}
+		if (!drm_edid_block_valid(block, 1, false, NULL)) {
+			DRM_ERROR("Invalid EDID data\n");
+			goto err;
+		}
+	}
+
+	return block;
+
+err:
+	kfree(block);
+	return NULL;
+}
+
+static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
+{
+	struct i2c_client *client;
+	int num_modes = 0;
+
+	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
+
+	if (ge_b850v3_lvds_ptr->edid) {
+		drm_mode_connector_update_edid_property(connector,
+						      ge_b850v3_lvds_ptr->edid);
+		num_modes = drm_add_edid_modes(connector,
+					       ge_b850v3_lvds_ptr->edid);
+	}
+
+	return num_modes;
+}
+
+static enum drm_mode_status ge_b850v3_lvds_mode_valid(
+		struct drm_connector *connector, struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static const struct
+drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
+	.get_modes = ge_b850v3_lvds_get_modes,
+	.mode_valid = ge_b850v3_lvds_mode_valid,
+};
+
+static enum drm_connector_status ge_b850v3_lvds_detect(
+		struct drm_connector *connector, bool force)
+{
+	struct i2c_client *stdp4028_i2c =
+			ge_b850v3_lvds_ptr->stdp4028_i2c;
+	s32 link_state;
+
+	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
+					      STDP4028_DPTX_STS_REG);
+
+	if (link_state == STDP4028_CON_STATE_CONNECTED)
+		return connector_status_connected;
+
+	if (link_state == 0)
+		return connector_status_disconnected;
+
+	return connector_status_unknown;
+}
+
+static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = ge_b850v3_lvds_detect,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
+{
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (ge_b850v3_lvds_ptr->connector.dev)
+		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
+
+	return IRQ_HANDLED;
+}
+
+static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
+{
+	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+	int ret;
+
+	if (!bridge->encoder) {
+		DRM_ERROR("Parent encoder object not found");
+		return -ENODEV;
+	}
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(connector,
+				 &ge_b850v3_lvds_connector_helper_funcs);
+
+	ret = drm_connector_init(bridge->dev, connector,
+				 &ge_b850v3_lvds_connector_funcs,
+				 DRM_MODE_CONNECTOR_DisplayPort);
+	if (ret) {
+		DRM_ERROR("Failed to initialize connector with drm\n");
+		return ret;
+	}
+
+	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
+	if (ret)
+		return ret;
+
+	/* Configures the bridge to re-enable interrupts after each ack. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_IRQ_OUT_CONF_REG,
+				  STDP4028_DPTX_DP_IRQ_EN);
+
+	/* Enable interrupts */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_EN_REG,
+				  STDP4028_DPTX_IRQ_CONFIG);
+
+	return 0;
+}
+
+static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
+	.attach = ge_b850v3_lvds_attach,
+};
+
+static int ge_b850v3_lvds_init(struct device *dev)
+{
+	mutex_lock(&ge_b850v3_lvds_dev_mutex);
+
+	if (ge_b850v3_lvds_ptr)
+		goto success;
+
+	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
+					  sizeof(*ge_b850v3_lvds_ptr),
+					  GFP_KERNEL);
+
+	if (!ge_b850v3_lvds_ptr) {
+		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+		return -ENOMEM;
+	}
+
+	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
+	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
+	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
+
+success:
+	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+	return 0;
+}
+
+static void ge_b850v3_lvds_remove(void)
+{
+	mutex_lock(&ge_b850v3_lvds_dev_mutex);
+	/*
+	 * This check is to avoid both the drivers
+	 * removing the bridge in their remove() function
+	 */
+	if (!ge_b850v3_lvds_ptr)
+		goto out;
+
+	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+
+	ge_b850v3_lvds_ptr = NULL;
+out:
+	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+}
+
+static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp4028_i2c->dev;
+
+	ge_b850v3_lvds_init(dev);
+
+	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
+	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
+
+	/* Clear pending interrupts since power up. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (!stdp4028_i2c->irq)
+		return 0;
+
+	return devm_request_threaded_irq(&stdp4028_i2c->dev,
+			stdp4028_i2c->irq, NULL,
+			ge_b850v3_lvds_irq_handler,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
+}
+
+static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
+{
+	ge_b850v3_lvds_remove();
+
+	return 0;
+}
+
+static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
+	{"stdp4028_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
+	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
+	.probe		= stdp4028_ge_b850v3_fw_probe,
+	.remove		= stdp4028_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp4028-ge-b850v3-fw",
+		.of_match_table = stdp4028_ge_b850v3_fw_match,
+	},
+};
+module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
+
+static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp2690_i2c->dev;
+
+	ge_b850v3_lvds_init(dev);
+
+	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
+	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
+
+	return 0;
+}
+
+static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
+{
+	ge_b850v3_lvds_remove();
+
+	return 0;
+}
+
+static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
+	{"stdp2690_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
+	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
+	.probe		= stdp2690_ge_b850v3_fw_probe,
+	.remove		= stdp2690_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp2690-ge-b850v3-fw",
+		.of_match_table = stdp2690_ge_b850v3_fw_match,
+	},
+};
+module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
+
+MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
+MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
+MODULE_LICENSE("GPL v2");
-- 
2.9.3

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Fabio Estevam, Rob Herring

The video processing pipeline on the second output on the GE B850v3:

  Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output

Each bridge has a dedicated flash containing firmware for supporting the
custom design. The result is that in this design neither the STDP4028
nor the STDP2690 behave as the stock bridges would. The compatible
strings include the suffix "-ge-b850v3-fw" to make it clear that the
driver is for the bridges with the firmware which is specific for the GE
B850v3.

The driver is powerless to control the video processing pipeline, as the
two bridges behaves as a single one. The driver is only needed for
telling the host about EDID / HPD, and for giving the host powers to ack
interrupts.

This driver adds one i2c_device for each bridge, but only one
drm_bridge. This design allows the creation of a functional connector
that is capable of reading EDID from the STDP2690 while handling
interrupts on the STDP4028.

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Archit Taneja <architt@codeaurora.org>
Cc: Enric Balletbo <enric.balletbo@collabora.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Changes from V1:
 - Updated copyright year
 - Fixed blank line issues
 - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
   added a comment to explain the test.
 - Fixed checkpatch strict warnings about continuation lines. In one case
   fixing the warning would cause the continuation line to be over 80 chars and
   that strict warning remains.

 drivers/gpu/drm/bridge/Kconfig                     |  11 +
 drivers/gpu/drm/bridge/Makefile                    |   1 +
 .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index eb8688e..4a937f1 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
 	  Support the I2S Audio interface which is part of the Synopsis
 	  Designware HDMI block.
 
+config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
+	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_PANEL
+	---help---
+          This is a driver for the display bridges of
+          GE B850v3 that convert dual channel LVDS
+          to DP++. This is used with the i.MX6 imx-ldb
+          driver. You are likely to say N here.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2e83a785..af0b7cc 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
new file mode 100644
index 0000000..6f82a44
--- /dev/null
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -0,0 +1,411 @@
+/*
+ * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
+ * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
+
+ * Copyright (c) 2017, Collabora Ltd.
+ * Copyright (c) 2017, General Electric Company
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
+ * display bridge of the GE B850v3. There are two physical bridges on the video
+ * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
+ * physical bridges are automatically configured by the input video signal, and
+ * the driver has no access to the video processing pipeline. The driver is
+ * only needed to read EDID from the STDP2690 and to handle HPD events from the
+ * STDP4028. The driver communicates with both bridges over i2c. The video
+ * signal pipeline is as follows:
+ *
+ *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drmP.h>
+
+#define EDID_EXT_BLOCK_CNT 0x7E
+
+#define STDP4028_IRQ_OUT_CONF_REG 0x02
+#define STDP4028_DPTX_IRQ_EN_REG 0x3C
+#define STDP4028_DPTX_IRQ_STS_REG 0x3D
+#define STDP4028_DPTX_STS_REG 0x3E
+
+#define STDP4028_DPTX_DP_IRQ_EN 0x1000
+
+#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
+#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
+#define STDP4028_DPTX_IRQ_CONFIG \
+		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
+
+#define STDP4028_DPTX_HOTPLUG_STS 0x0200
+#define STDP4028_DPTX_LINK_STS 0x1000
+#define STDP4028_CON_STATE_CONNECTED \
+		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
+
+#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
+#define STDP4028_DPTX_LINK_CH_STS 0x2000
+#define STDP4028_DPTX_IRQ_CLEAR \
+		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
+
+static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
+
+struct ge_b850v3_lvds {
+	struct drm_connector connector;
+	struct drm_bridge bridge;
+	struct i2c_client *stdp4028_i2c;
+	struct i2c_client *stdp2690_i2c;
+	struct edid *edid;
+};
+
+static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
+
+u8 *stdp2690_get_edid(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	unsigned char start = 0x00;
+	unsigned int total_size;
+	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= client->addr,
+			.flags	= 0,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= client->addr,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+			.buf	= block,
+		}
+	};
+
+	if (!block)
+		return NULL;
+
+	if (i2c_transfer(adapter, msgs, 2) != 2) {
+		DRM_ERROR("Unable to read EDID.\n");
+		goto err;
+	}
+
+	if (!drm_edid_block_valid(block, 0, false, NULL)) {
+		DRM_ERROR("Invalid EDID data\n");
+		goto err;
+	}
+
+	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
+	if (total_size > EDID_LENGTH) {
+		kfree(block);
+		block = kmalloc(total_size, GFP_KERNEL);
+		if (!block)
+			return NULL;
+
+		/* Yes, read the entire buffer, and do not skip the first
+		 * EDID_LENGTH bytes.
+		 */
+		start = 0x00;
+		msgs[1].len = total_size;
+		msgs[1].buf = block;
+
+		if (i2c_transfer(adapter, msgs, 2) != 2) {
+			DRM_ERROR("Unable to read EDID extension blocks.\n");
+			goto err;
+		}
+		if (!drm_edid_block_valid(block, 1, false, NULL)) {
+			DRM_ERROR("Invalid EDID data\n");
+			goto err;
+		}
+	}
+
+	return block;
+
+err:
+	kfree(block);
+	return NULL;
+}
+
+static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
+{
+	struct i2c_client *client;
+	int num_modes = 0;
+
+	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
+
+	if (ge_b850v3_lvds_ptr->edid) {
+		drm_mode_connector_update_edid_property(connector,
+						      ge_b850v3_lvds_ptr->edid);
+		num_modes = drm_add_edid_modes(connector,
+					       ge_b850v3_lvds_ptr->edid);
+	}
+
+	return num_modes;
+}
+
+static enum drm_mode_status ge_b850v3_lvds_mode_valid(
+		struct drm_connector *connector, struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static const struct
+drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
+	.get_modes = ge_b850v3_lvds_get_modes,
+	.mode_valid = ge_b850v3_lvds_mode_valid,
+};
+
+static enum drm_connector_status ge_b850v3_lvds_detect(
+		struct drm_connector *connector, bool force)
+{
+	struct i2c_client *stdp4028_i2c =
+			ge_b850v3_lvds_ptr->stdp4028_i2c;
+	s32 link_state;
+
+	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
+					      STDP4028_DPTX_STS_REG);
+
+	if (link_state == STDP4028_CON_STATE_CONNECTED)
+		return connector_status_connected;
+
+	if (link_state == 0)
+		return connector_status_disconnected;
+
+	return connector_status_unknown;
+}
+
+static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = ge_b850v3_lvds_detect,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
+{
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (ge_b850v3_lvds_ptr->connector.dev)
+		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
+
+	return IRQ_HANDLED;
+}
+
+static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
+{
+	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+	int ret;
+
+	if (!bridge->encoder) {
+		DRM_ERROR("Parent encoder object not found");
+		return -ENODEV;
+	}
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(connector,
+				 &ge_b850v3_lvds_connector_helper_funcs);
+
+	ret = drm_connector_init(bridge->dev, connector,
+				 &ge_b850v3_lvds_connector_funcs,
+				 DRM_MODE_CONNECTOR_DisplayPort);
+	if (ret) {
+		DRM_ERROR("Failed to initialize connector with drm\n");
+		return ret;
+	}
+
+	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
+	if (ret)
+		return ret;
+
+	/* Configures the bridge to re-enable interrupts after each ack. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_IRQ_OUT_CONF_REG,
+				  STDP4028_DPTX_DP_IRQ_EN);
+
+	/* Enable interrupts */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_EN_REG,
+				  STDP4028_DPTX_IRQ_CONFIG);
+
+	return 0;
+}
+
+static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
+	.attach = ge_b850v3_lvds_attach,
+};
+
+static int ge_b850v3_lvds_init(struct device *dev)
+{
+	mutex_lock(&ge_b850v3_lvds_dev_mutex);
+
+	if (ge_b850v3_lvds_ptr)
+		goto success;
+
+	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
+					  sizeof(*ge_b850v3_lvds_ptr),
+					  GFP_KERNEL);
+
+	if (!ge_b850v3_lvds_ptr) {
+		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+		return -ENOMEM;
+	}
+
+	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
+	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
+	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
+
+success:
+	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+	return 0;
+}
+
+static void ge_b850v3_lvds_remove(void)
+{
+	mutex_lock(&ge_b850v3_lvds_dev_mutex);
+	/*
+	 * This check is to avoid both the drivers
+	 * removing the bridge in their remove() function
+	 */
+	if (!ge_b850v3_lvds_ptr)
+		goto out;
+
+	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+
+	ge_b850v3_lvds_ptr = NULL;
+out:
+	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+}
+
+static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp4028_i2c->dev;
+
+	ge_b850v3_lvds_init(dev);
+
+	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
+	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
+
+	/* Clear pending interrupts since power up. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (!stdp4028_i2c->irq)
+		return 0;
+
+	return devm_request_threaded_irq(&stdp4028_i2c->dev,
+			stdp4028_i2c->irq, NULL,
+			ge_b850v3_lvds_irq_handler,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
+}
+
+static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
+{
+	ge_b850v3_lvds_remove();
+
+	return 0;
+}
+
+static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
+	{"stdp4028_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
+	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
+	.probe		= stdp4028_ge_b850v3_fw_probe,
+	.remove		= stdp4028_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp4028-ge-b850v3-fw",
+		.of_match_table = stdp4028_ge_b850v3_fw_match,
+	},
+};
+module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
+
+static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp2690_i2c->dev;
+
+	ge_b850v3_lvds_init(dev);
+
+	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
+	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
+
+	return 0;
+}
+
+static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
+{
+	ge_b850v3_lvds_remove();
+
+	return 0;
+}
+
+static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
+	{"stdp2690_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
+	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
+	.probe		= stdp2690_ge_b850v3_fw_probe,
+	.remove		= stdp2690_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp2690-ge-b850v3-fw",
+		.of_match_table = stdp2690_ge_b850v3_fw_match,
+	},
+};
+module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
+
+MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
+MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
+MODULE_LICENSE("GPL v2");
-- 
2.9.3

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: linux-arm-kernel

The video processing pipeline on the second output on the GE B850v3:

  Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output

Each bridge has a dedicated flash containing firmware for supporting the
custom design. The result is that in this design neither the STDP4028
nor the STDP2690 behave as the stock bridges would. The compatible
strings include the suffix "-ge-b850v3-fw" to make it clear that the
driver is for the bridges with the firmware which is specific for the GE
B850v3.

The driver is powerless to control the video processing pipeline, as the
two bridges behaves as a single one. The driver is only needed for
telling the host about EDID / HPD, and for giving the host powers to ack
interrupts.

This driver adds one i2c_device for each bridge, but only one
drm_bridge. This design allows the creation of a functional connector
that is capable of reading EDID from the STDP2690 while handling
interrupts on the STDP4028.

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Archit Taneja <architt@codeaurora.org>
Cc: Enric Balletbo <enric.balletbo@collabora.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Changes from V1:
 - Updated copyright year
 - Fixed blank line issues
 - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
   added a comment to explain the test.
 - Fixed checkpatch strict warnings about continuation lines. In one case
   fixing the warning would cause the continuation line to be over 80 chars and
   that strict warning remains.

 drivers/gpu/drm/bridge/Kconfig                     |  11 +
 drivers/gpu/drm/bridge/Makefile                    |   1 +
 .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
 3 files changed, 423 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index eb8688e..4a937f1 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
 	  Support the I2S Audio interface which is part of the Synopsis
 	  Designware HDMI block.
 
+config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
+	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_PANEL
+	---help---
+          This is a driver for the display bridges of
+          GE B850v3 that convert dual channel LVDS
+          to DP++. This is used with the i.MX6 imx-ldb
+          driver. You are likely to say N here.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2e83a785..af0b7cc 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
new file mode 100644
index 0000000..6f82a44
--- /dev/null
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -0,0 +1,411 @@
+/*
+ * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
+ * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
+
+ * Copyright (c) 2017, Collabora Ltd.
+ * Copyright (c) 2017, General Electric Company
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
+ * display bridge of the GE B850v3. There are two physical bridges on the video
+ * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
+ * physical bridges are automatically configured by the input video signal, and
+ * the driver has no access to the video processing pipeline. The driver is
+ * only needed to read EDID from the STDP2690 and to handle HPD events from the
+ * STDP4028. The driver communicates with both bridges over i2c. The video
+ * signal pipeline is as follows:
+ *
+ *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drmP.h>
+
+#define EDID_EXT_BLOCK_CNT 0x7E
+
+#define STDP4028_IRQ_OUT_CONF_REG 0x02
+#define STDP4028_DPTX_IRQ_EN_REG 0x3C
+#define STDP4028_DPTX_IRQ_STS_REG 0x3D
+#define STDP4028_DPTX_STS_REG 0x3E
+
+#define STDP4028_DPTX_DP_IRQ_EN 0x1000
+
+#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
+#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
+#define STDP4028_DPTX_IRQ_CONFIG \
+		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
+
+#define STDP4028_DPTX_HOTPLUG_STS 0x0200
+#define STDP4028_DPTX_LINK_STS 0x1000
+#define STDP4028_CON_STATE_CONNECTED \
+		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
+
+#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
+#define STDP4028_DPTX_LINK_CH_STS 0x2000
+#define STDP4028_DPTX_IRQ_CLEAR \
+		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
+
+static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
+
+struct ge_b850v3_lvds {
+	struct drm_connector connector;
+	struct drm_bridge bridge;
+	struct i2c_client *stdp4028_i2c;
+	struct i2c_client *stdp2690_i2c;
+	struct edid *edid;
+};
+
+static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
+
+u8 *stdp2690_get_edid(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	unsigned char start = 0x00;
+	unsigned int total_size;
+	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= client->addr,
+			.flags	= 0,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= client->addr,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+			.buf	= block,
+		}
+	};
+
+	if (!block)
+		return NULL;
+
+	if (i2c_transfer(adapter, msgs, 2) != 2) {
+		DRM_ERROR("Unable to read EDID.\n");
+		goto err;
+	}
+
+	if (!drm_edid_block_valid(block, 0, false, NULL)) {
+		DRM_ERROR("Invalid EDID data\n");
+		goto err;
+	}
+
+	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
+	if (total_size > EDID_LENGTH) {
+		kfree(block);
+		block = kmalloc(total_size, GFP_KERNEL);
+		if (!block)
+			return NULL;
+
+		/* Yes, read the entire buffer, and do not skip the first
+		 * EDID_LENGTH bytes.
+		 */
+		start = 0x00;
+		msgs[1].len = total_size;
+		msgs[1].buf = block;
+
+		if (i2c_transfer(adapter, msgs, 2) != 2) {
+			DRM_ERROR("Unable to read EDID extension blocks.\n");
+			goto err;
+		}
+		if (!drm_edid_block_valid(block, 1, false, NULL)) {
+			DRM_ERROR("Invalid EDID data\n");
+			goto err;
+		}
+	}
+
+	return block;
+
+err:
+	kfree(block);
+	return NULL;
+}
+
+static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
+{
+	struct i2c_client *client;
+	int num_modes = 0;
+
+	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
+
+	if (ge_b850v3_lvds_ptr->edid) {
+		drm_mode_connector_update_edid_property(connector,
+						      ge_b850v3_lvds_ptr->edid);
+		num_modes = drm_add_edid_modes(connector,
+					       ge_b850v3_lvds_ptr->edid);
+	}
+
+	return num_modes;
+}
+
+static enum drm_mode_status ge_b850v3_lvds_mode_valid(
+		struct drm_connector *connector, struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static const struct
+drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
+	.get_modes = ge_b850v3_lvds_get_modes,
+	.mode_valid = ge_b850v3_lvds_mode_valid,
+};
+
+static enum drm_connector_status ge_b850v3_lvds_detect(
+		struct drm_connector *connector, bool force)
+{
+	struct i2c_client *stdp4028_i2c =
+			ge_b850v3_lvds_ptr->stdp4028_i2c;
+	s32 link_state;
+
+	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
+					      STDP4028_DPTX_STS_REG);
+
+	if (link_state == STDP4028_CON_STATE_CONNECTED)
+		return connector_status_connected;
+
+	if (link_state == 0)
+		return connector_status_disconnected;
+
+	return connector_status_unknown;
+}
+
+static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = ge_b850v3_lvds_detect,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
+{
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (ge_b850v3_lvds_ptr->connector.dev)
+		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
+
+	return IRQ_HANDLED;
+}
+
+static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
+{
+	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+	int ret;
+
+	if (!bridge->encoder) {
+		DRM_ERROR("Parent encoder object not found");
+		return -ENODEV;
+	}
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(connector,
+				 &ge_b850v3_lvds_connector_helper_funcs);
+
+	ret = drm_connector_init(bridge->dev, connector,
+				 &ge_b850v3_lvds_connector_funcs,
+				 DRM_MODE_CONNECTOR_DisplayPort);
+	if (ret) {
+		DRM_ERROR("Failed to initialize connector with drm\n");
+		return ret;
+	}
+
+	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
+	if (ret)
+		return ret;
+
+	/* Configures the bridge to re-enable interrupts after each ack. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_IRQ_OUT_CONF_REG,
+				  STDP4028_DPTX_DP_IRQ_EN);
+
+	/* Enable interrupts */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_EN_REG,
+				  STDP4028_DPTX_IRQ_CONFIG);
+
+	return 0;
+}
+
+static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
+	.attach = ge_b850v3_lvds_attach,
+};
+
+static int ge_b850v3_lvds_init(struct device *dev)
+{
+	mutex_lock(&ge_b850v3_lvds_dev_mutex);
+
+	if (ge_b850v3_lvds_ptr)
+		goto success;
+
+	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
+					  sizeof(*ge_b850v3_lvds_ptr),
+					  GFP_KERNEL);
+
+	if (!ge_b850v3_lvds_ptr) {
+		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+		return -ENOMEM;
+	}
+
+	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
+	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
+	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
+
+success:
+	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+	return 0;
+}
+
+static void ge_b850v3_lvds_remove(void)
+{
+	mutex_lock(&ge_b850v3_lvds_dev_mutex);
+	/*
+	 * This check is to avoid both the drivers
+	 * removing the bridge in their remove() function
+	 */
+	if (!ge_b850v3_lvds_ptr)
+		goto out;
+
+	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+
+	ge_b850v3_lvds_ptr = NULL;
+out:
+	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
+}
+
+static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp4028_i2c->dev;
+
+	ge_b850v3_lvds_init(dev);
+
+	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
+	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
+
+	/* Clear pending interrupts since power up. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (!stdp4028_i2c->irq)
+		return 0;
+
+	return devm_request_threaded_irq(&stdp4028_i2c->dev,
+			stdp4028_i2c->irq, NULL,
+			ge_b850v3_lvds_irq_handler,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
+}
+
+static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
+{
+	ge_b850v3_lvds_remove();
+
+	return 0;
+}
+
+static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
+	{"stdp4028_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
+	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
+	.probe		= stdp4028_ge_b850v3_fw_probe,
+	.remove		= stdp4028_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp4028-ge-b850v3-fw",
+		.of_match_table = stdp4028_ge_b850v3_fw_match,
+	},
+};
+module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
+
+static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp2690_i2c->dev;
+
+	ge_b850v3_lvds_init(dev);
+
+	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
+	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
+
+	return 0;
+}
+
+static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
+{
+	ge_b850v3_lvds_remove();
+
+	return 0;
+}
+
+static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
+	{"stdp2690_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
+	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
+	.probe		= stdp2690_ge_b850v3_fw_probe,
+	.remove		= stdp2690_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp2690-ge-b850v3-fw",
+		.of_match_table = stdp2690_ge_b850v3_fw_match,
+	},
+};
+module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
+
+MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
+MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
+MODULE_LICENSE("GPL v2");
-- 
2.9.3

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

* [PATCH V2 4/4] dts/imx6q-b850v3: Use megachips-stdpxxxx-ge-b850v3-fw bridges (LVDS-DP++)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Rob Herring, Fabio Estevam

Configures the megachips-stdpxxxx-ge-b850v3-fw bridges on the GE
B850v3 dts file.

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Javier Martinez Canillas <javier@dowhile0.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Unchanged from V1.

 arch/arm/boot/dts/imx6q-b850v3.dts | 68 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/arch/arm/boot/dts/imx6q-b850v3.dts b/arch/arm/boot/dts/imx6q-b850v3.dts
index b237429..3ec54da 100644
--- a/arch/arm/boot/dts/imx6q-b850v3.dts
+++ b/arch/arm/boot/dts/imx6q-b850v3.dts
@@ -72,6 +72,13 @@
 		fsl,data-mapping = "spwg";
 		fsl,data-width = <24>;
 		status = "okay";
+
+		port@4 {
+			reg = <4>;
+			lvds0_out: endpoint {
+				remote-endpoint = <&stdp4028_in>;
+			};
+		};
 	};
 };
 
@@ -146,3 +153,64 @@
 &usdhc2 {
 	status = "disabled";
 };
+
+&mux2_i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+
+	stdp4028@73 {
+		compatible = "megachips,stdp4028-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x73>;
+
+		interrupt-parent = <&gpio2>;
+		interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp4028_in: endpoint {
+					remote-endpoint = <&lvds0_out>;
+				};
+			};
+			port@1 {
+				reg = <1>;
+				stdp4028_out: endpoint {
+					remote-endpoint = <&stdp2690_in>;
+				};
+			};
+		};
+	};
+
+	stdp2690@72 {
+		compatible = "megachips,stdp2690-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x72>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp2690_in: endpoint {
+					remote-endpoint = <&stdp4028_out>;
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				stdp2690_out: endpoint {
+					/* Connector for external display */
+				};
+			};
+		};
+	};
+};
-- 
2.9.3

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

* [PATCH V2 4/4] dts/imx6q-b850v3: Use megachips-stdpxxxx-ge-b850v3-fw bridges (LVDS-DP++)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: airlied-cv59FeDIM0c, architt-sgV2jX0FEOL9JmXXK+q4OQ,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, daniel.vetter-/w4YWyX8dFk,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q, devicetree-u79uwXL29TY76Z2rM5mHXA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ,
	eballetbo-Re5JQEeQqe8AvxtiuMwx3w, galak-sgV2jX0FEOL9JmXXK+q4OQ,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	heiko-4mtYJXux2i+zQB+pC5nmwQ,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
	javier-0uQlZySMnqxg9hUCZPvPmw, jslaby-AlSwsSmVLrQ,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-I+IVW8TIWO2tmTQ+vhA3Yw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-0h96xk9xTtrk1uMJSBkQmQ, mark.rutland-5wv7dgnIgG8,
	martin.donnelly-JJi787mZWgc, martyn.welch-ZGY8ohtN/8pPYcu2f3hruQ,
	mchehab-JPH+aEBZ4P+UEJcrhfAQsw, pawel.moll-5wv7dgnIgG8,
	peter.senna-ZGY8ohtN/8qB+jHODAdFcQ,
	peter.senna-Re5JQEeQqe8AvxtiuMwx3w,
	p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ,
	thierry.reding-Re5JQEeQqe8AvxtiuMwx3w,
	rmk+kernel-I+IVW8TIWO2tmTQ+vhA3Yw,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, shawnguo-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Rob Herring, Fabio Estevam

Configures the megachips-stdpxxxx-ge-b850v3-fw bridges on the GE
B850v3 dts file.

Cc: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
Cc: Martyn Welch <martyn.welch-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org>
Cc: Martin Donnelly <martin.donnelly-JJi787mZWgc@public.gmane.org>
Cc: Javier Martinez Canillas <javier-0uQlZySMnqxg9hUCZPvPmw@public.gmane.org>
Cc: Enric Balletbo i Serra <enric.balletbo-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
Cc: Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Fabio Estevam <fabio.estevam-3arQi8VN3Tc@public.gmane.org>
Signed-off-by: Peter Senna Tschudin <peter.senna-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
---
Unchanged from V1.

 arch/arm/boot/dts/imx6q-b850v3.dts | 68 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/arch/arm/boot/dts/imx6q-b850v3.dts b/arch/arm/boot/dts/imx6q-b850v3.dts
index b237429..3ec54da 100644
--- a/arch/arm/boot/dts/imx6q-b850v3.dts
+++ b/arch/arm/boot/dts/imx6q-b850v3.dts
@@ -72,6 +72,13 @@
 		fsl,data-mapping = "spwg";
 		fsl,data-width = <24>;
 		status = "okay";
+
+		port@4 {
+			reg = <4>;
+			lvds0_out: endpoint {
+				remote-endpoint = <&stdp4028_in>;
+			};
+		};
 	};
 };
 
@@ -146,3 +153,64 @@
 &usdhc2 {
 	status = "disabled";
 };
+
+&mux2_i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+
+	stdp4028@73 {
+		compatible = "megachips,stdp4028-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x73>;
+
+		interrupt-parent = <&gpio2>;
+		interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp4028_in: endpoint {
+					remote-endpoint = <&lvds0_out>;
+				};
+			};
+			port@1 {
+				reg = <1>;
+				stdp4028_out: endpoint {
+					remote-endpoint = <&stdp2690_in>;
+				};
+			};
+		};
+	};
+
+	stdp2690@72 {
+		compatible = "megachips,stdp2690-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x72>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port@0 {
+				reg = <0>;
+				stdp2690_in: endpoint {
+					remote-endpoint = <&stdp4028_out>;
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				stdp2690_out: endpoint {
+					/* Connector for external display */
+				};
+			};
+		};
+	};
+};
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH V2 4/4] dts/imx6q-b850v3: Use megachips-stdpxxxx-ge-b850v3-fw bridges (LVDS-DP++)
@ 2017-02-28 14:28   ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-02-28 14:28 UTC (permalink / raw)
  To: linux-arm-kernel

Configures the megachips-stdpxxxx-ge-b850v3-fw bridges on the GE
B850v3 dts file.

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Martyn Welch <martyn.welch@collabora.co.uk>
Cc: Martin Donnelly <martin.donnelly@ge.com>
Cc: Javier Martinez Canillas <javier@dowhile0.org>
Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
---
Unchanged from V1.

 arch/arm/boot/dts/imx6q-b850v3.dts | 68 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/arch/arm/boot/dts/imx6q-b850v3.dts b/arch/arm/boot/dts/imx6q-b850v3.dts
index b237429..3ec54da 100644
--- a/arch/arm/boot/dts/imx6q-b850v3.dts
+++ b/arch/arm/boot/dts/imx6q-b850v3.dts
@@ -72,6 +72,13 @@
 		fsl,data-mapping = "spwg";
 		fsl,data-width = <24>;
 		status = "okay";
+
+		port at 4 {
+			reg = <4>;
+			lvds0_out: endpoint {
+				remote-endpoint = <&stdp4028_in>;
+			};
+		};
 	};
 };
 
@@ -146,3 +153,64 @@
 &usdhc2 {
 	status = "disabled";
 };
+
+&mux2_i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+
+	stdp4028 at 73 {
+		compatible = "megachips,stdp4028-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x73>;
+
+		interrupt-parent = <&gpio2>;
+		interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port at 0 {
+				reg = <0>;
+				stdp4028_in: endpoint {
+					remote-endpoint = <&lvds0_out>;
+				};
+			};
+			port at 1 {
+				reg = <1>;
+				stdp4028_out: endpoint {
+					remote-endpoint = <&stdp2690_in>;
+				};
+			};
+		};
+	};
+
+	stdp2690 at 72 {
+		compatible = "megachips,stdp2690-ge-b850v3-fw";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		reg = <0x72>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			port at 0 {
+				reg = <0>;
+				stdp2690_in: endpoint {
+					remote-endpoint = <&stdp4028_out>;
+				};
+			};
+
+			port at 1 {
+				reg = <1>;
+				stdp2690_out: endpoint {
+					/* Connector for external display */
+				};
+			};
+		};
+	};
+};
-- 
2.9.3

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  2017-02-28 14:28   ` Peter Senna Tschudin
  (?)
@ 2017-03-01  4:08     ` Archit Taneja
  -1 siblings, 0 replies; 29+ messages in thread
From: Archit Taneja @ 2017-03-01  4:08 UTC (permalink / raw)
  To: Peter Senna Tschudin, airlied, akpm, daniel.vetter, davem,
	devicetree, dri-devel, enric.balletbo, eballetbo, galak, gregkh,
	heiko, ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel,
	linux, linux-kernel, linux, mark.rutland, martin.donnelly,
	martyn.welch, mchehab, pawel.moll, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Rob Herring, Fabio Estevam



On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
> The video processing pipeline on the second output on the GE B850v3:
>
>   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>
> Each bridge has a dedicated flash containing firmware for supporting the
> custom design. The result is that in this design neither the STDP4028
> nor the STDP2690 behave as the stock bridges would. The compatible
> strings include the suffix "-ge-b850v3-fw" to make it clear that the
> driver is for the bridges with the firmware which is specific for the GE
> B850v3.
>
> The driver is powerless to control the video processing pipeline, as the
> two bridges behaves as a single one. The driver is only needed for
> telling the host about EDID / HPD, and for giving the host powers to ack
> interrupts.
>
> This driver adds one i2c_device for each bridge, but only one
> drm_bridge. This design allows the creation of a functional connector
> that is capable of reading EDID from the STDP2690 while handling
> interrupts on the STDP4028.
>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Martin Donnelly <martin.donnelly@ge.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Thierry Reding <treding@nvidia.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: Archit Taneja <architt@codeaurora.org>
> Cc: Enric Balletbo <enric.balletbo@collabora.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> ---
> Changes from V1:
>  - Updated copyright year
>  - Fixed blank line issues
>  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
>    added a comment to explain the test.
>  - Fixed checkpatch strict warnings about continuation lines. In one case
>    fixing the warning would cause the continuation line to be over 80 chars and
>    that strict warning remains.
>
>  drivers/gpu/drm/bridge/Kconfig                     |  11 +
>  drivers/gpu/drm/bridge/Makefile                    |   1 +
>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
>  3 files changed, 423 insertions(+)
>  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>
> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> index eb8688e..4a937f1 100644
> --- a/drivers/gpu/drm/bridge/Kconfig
> +++ b/drivers/gpu/drm/bridge/Kconfig
> @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
>  	  Support the I2S Audio interface which is part of the Synopsis
>  	  Designware HDMI block.
>
> +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
> +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
> +	depends on OF
> +	select DRM_KMS_HELPER
> +	select DRM_PANEL
> +	---help---
> +          This is a driver for the display bridges of
> +          GE B850v3 that convert dual channel LVDS
> +          to DP++. This is used with the i.MX6 imx-ldb
> +          driver. You are likely to say N here.
> +
>  config DRM_NXP_PTN3460
>  	tristate "NXP PTN3460 DP/LVDS bridge"
>  	depends on OF
> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> index 2e83a785..af0b7cc 100644
> --- a/drivers/gpu/drm/bridge/Makefile
> +++ b/drivers/gpu/drm/bridge/Makefile
> @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
>  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
>  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
>  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
> +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
>  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
>  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
>  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> new file mode 100644
> index 0000000..6f82a44
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -0,0 +1,411 @@
> +/*
> + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
> + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
> +
> + * Copyright (c) 2017, Collabora Ltd.
> + * Copyright (c) 2017, General Electric Company
> +
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> +
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> +
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
> + * display bridge of the GE B850v3. There are two physical bridges on the video
> + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
> + * physical bridges are automatically configured by the input video signal, and
> + * the driver has no access to the video processing pipeline. The driver is
> + * only needed to read EDID from the STDP2690 and to handle HPD events from the
> + * STDP4028. The driver communicates with both bridges over i2c. The video
> + * signal pipeline is as follows:
> + *
> + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> + *
> + */
> +
> +#include <linux/gpio.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <drm/drm_atomic.h>
> +#include <drm/drm_atomic_helper.h>
> +#include <drm/drm_crtc_helper.h>
> +#include <drm/drm_edid.h>
> +#include <drm/drmP.h>
> +
> +#define EDID_EXT_BLOCK_CNT 0x7E
> +
> +#define STDP4028_IRQ_OUT_CONF_REG 0x02
> +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
> +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
> +#define STDP4028_DPTX_STS_REG 0x3E
> +
> +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
> +
> +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
> +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
> +#define STDP4028_DPTX_IRQ_CONFIG \
> +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
> +
> +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
> +#define STDP4028_DPTX_LINK_STS 0x1000
> +#define STDP4028_CON_STATE_CONNECTED \
> +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
> +
> +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
> +#define STDP4028_DPTX_LINK_CH_STS 0x2000
> +#define STDP4028_DPTX_IRQ_CLEAR \
> +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
> +
> +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
> +
> +struct ge_b850v3_lvds {
> +	struct drm_connector connector;
> +	struct drm_bridge bridge;
> +	struct i2c_client *stdp4028_i2c;
> +	struct i2c_client *stdp2690_i2c;
> +	struct edid *edid;
> +};
> +
> +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
> +
> +u8 *stdp2690_get_edid(struct i2c_client *client)
> +{
> +	struct i2c_adapter *adapter = client->adapter;
> +	unsigned char start = 0x00;
> +	unsigned int total_size;
> +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> +
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr	= client->addr,
> +			.flags	= 0,
> +			.len	= 1,
> +			.buf	= &start,
> +		}, {
> +			.addr	= client->addr,
> +			.flags	= I2C_M_RD,
> +			.len	= EDID_LENGTH,
> +			.buf	= block,
> +		}
> +	};
> +
> +	if (!block)
> +		return NULL;
> +
> +	if (i2c_transfer(adapter, msgs, 2) != 2) {
> +		DRM_ERROR("Unable to read EDID.\n");
> +		goto err;
> +	}
> +
> +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
> +		DRM_ERROR("Invalid EDID data\n");
> +		goto err;
> +	}
> +
> +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> +	if (total_size > EDID_LENGTH) {
> +		kfree(block);
> +		block = kmalloc(total_size, GFP_KERNEL);
> +		if (!block)
> +			return NULL;
> +
> +		/* Yes, read the entire buffer, and do not skip the first
> +		 * EDID_LENGTH bytes.
> +		 */
> +		start = 0x00;
> +		msgs[1].len = total_size;
> +		msgs[1].buf = block;
> +
> +		if (i2c_transfer(adapter, msgs, 2) != 2) {
> +			DRM_ERROR("Unable to read EDID extension blocks.\n");
> +			goto err;
> +		}
> +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
> +			DRM_ERROR("Invalid EDID data\n");
> +			goto err;
> +		}
> +	}
> +
> +	return block;
> +
> +err:
> +	kfree(block);
> +	return NULL;
> +}
> +
> +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
> +{
> +	struct i2c_client *client;
> +	int num_modes = 0;
> +
> +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
> +
> +	kfree(ge_b850v3_lvds_ptr->edid);
> +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
> +
> +	if (ge_b850v3_lvds_ptr->edid) {
> +		drm_mode_connector_update_edid_property(connector,
> +						      ge_b850v3_lvds_ptr->edid);
> +		num_modes = drm_add_edid_modes(connector,
> +					       ge_b850v3_lvds_ptr->edid);
> +	}
> +
> +	return num_modes;
> +}
> +
> +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
> +		struct drm_connector *connector, struct drm_display_mode *mode)
> +{
> +	return MODE_OK;
> +}
> +
> +static const struct
> +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
> +	.get_modes = ge_b850v3_lvds_get_modes,
> +	.mode_valid = ge_b850v3_lvds_mode_valid,
> +};
> +
> +static enum drm_connector_status ge_b850v3_lvds_detect(
> +		struct drm_connector *connector, bool force)
> +{
> +	struct i2c_client *stdp4028_i2c =
> +			ge_b850v3_lvds_ptr->stdp4028_i2c;
> +	s32 link_state;
> +
> +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
> +					      STDP4028_DPTX_STS_REG);
> +
> +	if (link_state == STDP4028_CON_STATE_CONNECTED)
> +		return connector_status_connected;
> +
> +	if (link_state == 0)
> +		return connector_status_disconnected;
> +
> +	return connector_status_unknown;
> +}
> +
> +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
> +	.dpms = drm_atomic_helper_connector_dpms,
> +	.fill_modes = drm_helper_probe_single_connector_modes,
> +	.detect = ge_b850v3_lvds_detect,
> +	.destroy = drm_connector_cleanup,
> +	.reset = drm_atomic_helper_connector_reset,
> +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> +};
> +
> +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
> +{
> +	struct i2c_client *stdp4028_i2c
> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> +
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_STS_REG,
> +				  STDP4028_DPTX_IRQ_CLEAR);
> +
> +	if (ge_b850v3_lvds_ptr->connector.dev)
> +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
> +{
> +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
> +	struct i2c_client *stdp4028_i2c
> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> +	int ret;
> +
> +	if (!bridge->encoder) {
> +		DRM_ERROR("Parent encoder object not found");
> +		return -ENODEV;
> +	}
> +
> +	connector->polled = DRM_CONNECTOR_POLL_HPD;
> +
> +	drm_connector_helper_add(connector,
> +				 &ge_b850v3_lvds_connector_helper_funcs);
> +
> +	ret = drm_connector_init(bridge->dev, connector,
> +				 &ge_b850v3_lvds_connector_funcs,
> +				 DRM_MODE_CONNECTOR_DisplayPort);
> +	if (ret) {
> +		DRM_ERROR("Failed to initialize connector with drm\n");
> +		return ret;
> +	}
> +
> +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
> +	if (ret)
> +		return ret;
> +
> +	/* Configures the bridge to re-enable interrupts after each ack. */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_IRQ_OUT_CONF_REG,
> +				  STDP4028_DPTX_DP_IRQ_EN);
> +
> +	/* Enable interrupts */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_EN_REG,
> +				  STDP4028_DPTX_IRQ_CONFIG);
> +
> +	return 0;
> +}
> +
> +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
> +	.attach = ge_b850v3_lvds_attach,
> +};
> +
> +static int ge_b850v3_lvds_init(struct device *dev)
> +{
> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> +
> +	if (ge_b850v3_lvds_ptr)
> +		goto success;
> +
> +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
> +					  sizeof(*ge_b850v3_lvds_ptr),
> +					  GFP_KERNEL);
> +
> +	if (!ge_b850v3_lvds_ptr) {
> +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +		return -ENOMEM;
> +	}
> +
> +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
> +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
> +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
> +
> +success:
> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +	return 0;
> +}
> +
> +static void ge_b850v3_lvds_remove(void)
> +{
> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> +	/*
> +	 * This check is to avoid both the drivers
> +	 * removing the bridge in their remove() function
> +	 */
> +	if (!ge_b850v3_lvds_ptr)
> +		goto out;
> +
> +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> +
> +	kfree(ge_b850v3_lvds_ptr->edid);
> +
> +	ge_b850v3_lvds_ptr = NULL;
> +out:
> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +}
> +
> +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
> +				       const struct i2c_device_id *id)
> +{
> +	struct device *dev = &stdp4028_i2c->dev;
> +
> +	ge_b850v3_lvds_init(dev);
> +
> +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
> +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
> +
> +	/* Clear pending interrupts since power up. */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_STS_REG,
> +				  STDP4028_DPTX_IRQ_CLEAR);
> +
> +	if (!stdp4028_i2c->irq)
> +		return 0;
> +
> +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
> +			stdp4028_i2c->irq, NULL,
> +			ge_b850v3_lvds_irq_handler,
> +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
> +}
> +
> +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
> +{
> +	ge_b850v3_lvds_remove();
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
> +	{"stdp4028_ge_fw", 0},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
> +
> +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
> +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
> +
> +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
> +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
> +	.probe		= stdp4028_ge_b850v3_fw_probe,
> +	.remove		= stdp4028_ge_b850v3_fw_remove,
> +	.driver		= {
> +		.name		= "stdp4028-ge-b850v3-fw",
> +		.of_match_table = stdp4028_ge_b850v3_fw_match,
> +	},
> +};
> +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
> +
> +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
> +				       const struct i2c_device_id *id)
> +{
> +	struct device *dev = &stdp2690_i2c->dev;
> +
> +	ge_b850v3_lvds_init(dev);
> +
> +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
> +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
> +
> +	return 0;
> +}
> +
> +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
> +{
> +	ge_b850v3_lvds_remove();
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> +	{"stdp2690_ge_fw", 0},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> +
> +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> +
> +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> +	.probe		= stdp2690_ge_b850v3_fw_probe,
> +	.remove		= stdp2690_ge_b850v3_fw_remove,
> +	.driver		= {
> +		.name		= "stdp2690-ge-b850v3-fw",
> +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> +	},
> +};
> +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);

Didn't catch this in the last series, but there can only be one
module_init call per module. This breaks compilation when the
driver is built as a module.

You could do something like:

static int __init stdpxxxx_ge_b850v3_init(void)
{
	int ret;

	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
	if (ret)
		return ret;

	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
}
module_init(stdpxxxx_ge_b850v3_init);

static void __exit stdpxxxx_ge_b850v3_exit(void)
{
	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
}
module_exit(stdpxxxx_ge_b850v3_exit);

Thanks,
Archit

> +
> +MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
> +MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
> +MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
> +MODULE_LICENSE("GPL v2");
>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-01  4:08     ` Archit Taneja
  0 siblings, 0 replies; 29+ messages in thread
From: Archit Taneja @ 2017-03-01  4:08 UTC (permalink / raw)
  To: Peter Senna Tschudin, airlied, akpm, daniel.vetter, davem,
	devicetree, dri-devel, enric.balletbo, eballetbo, galak, gregkh,
	heiko, ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel,
	linux, linux-kernel, linux, mark.rutland, martin.donnelly,
	martyn.welch, mchehab, pawel.moll, peter.senna, p.zabel,
	thierry.reding, rmk+kernel, robh+dt, shawnguo, tiwai, treding,
	ykk, laurent.pinchart
  Cc: Fabio Estevam, Rob Herring



On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
> The video processing pipeline on the second output on the GE B850v3:
>
>   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>
> Each bridge has a dedicated flash containing firmware for supporting the
> custom design. The result is that in this design neither the STDP4028
> nor the STDP2690 behave as the stock bridges would. The compatible
> strings include the suffix "-ge-b850v3-fw" to make it clear that the
> driver is for the bridges with the firmware which is specific for the GE
> B850v3.
>
> The driver is powerless to control the video processing pipeline, as the
> two bridges behaves as a single one. The driver is only needed for
> telling the host about EDID / HPD, and for giving the host powers to ack
> interrupts.
>
> This driver adds one i2c_device for each bridge, but only one
> drm_bridge. This design allows the creation of a functional connector
> that is capable of reading EDID from the STDP2690 while handling
> interrupts on the STDP4028.
>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Martin Donnelly <martin.donnelly@ge.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Thierry Reding <treding@nvidia.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: Archit Taneja <architt@codeaurora.org>
> Cc: Enric Balletbo <enric.balletbo@collabora.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> ---
> Changes from V1:
>  - Updated copyright year
>  - Fixed blank line issues
>  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
>    added a comment to explain the test.
>  - Fixed checkpatch strict warnings about continuation lines. In one case
>    fixing the warning would cause the continuation line to be over 80 chars and
>    that strict warning remains.
>
>  drivers/gpu/drm/bridge/Kconfig                     |  11 +
>  drivers/gpu/drm/bridge/Makefile                    |   1 +
>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
>  3 files changed, 423 insertions(+)
>  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>
> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> index eb8688e..4a937f1 100644
> --- a/drivers/gpu/drm/bridge/Kconfig
> +++ b/drivers/gpu/drm/bridge/Kconfig
> @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
>  	  Support the I2S Audio interface which is part of the Synopsis
>  	  Designware HDMI block.
>
> +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
> +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
> +	depends on OF
> +	select DRM_KMS_HELPER
> +	select DRM_PANEL
> +	---help---
> +          This is a driver for the display bridges of
> +          GE B850v3 that convert dual channel LVDS
> +          to DP++. This is used with the i.MX6 imx-ldb
> +          driver. You are likely to say N here.
> +
>  config DRM_NXP_PTN3460
>  	tristate "NXP PTN3460 DP/LVDS bridge"
>  	depends on OF
> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> index 2e83a785..af0b7cc 100644
> --- a/drivers/gpu/drm/bridge/Makefile
> +++ b/drivers/gpu/drm/bridge/Makefile
> @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
>  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
>  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
>  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
> +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
>  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
>  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
>  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> new file mode 100644
> index 0000000..6f82a44
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -0,0 +1,411 @@
> +/*
> + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
> + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
> +
> + * Copyright (c) 2017, Collabora Ltd.
> + * Copyright (c) 2017, General Electric Company
> +
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> +
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> +
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
> + * display bridge of the GE B850v3. There are two physical bridges on the video
> + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
> + * physical bridges are automatically configured by the input video signal, and
> + * the driver has no access to the video processing pipeline. The driver is
> + * only needed to read EDID from the STDP2690 and to handle HPD events from the
> + * STDP4028. The driver communicates with both bridges over i2c. The video
> + * signal pipeline is as follows:
> + *
> + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> + *
> + */
> +
> +#include <linux/gpio.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <drm/drm_atomic.h>
> +#include <drm/drm_atomic_helper.h>
> +#include <drm/drm_crtc_helper.h>
> +#include <drm/drm_edid.h>
> +#include <drm/drmP.h>
> +
> +#define EDID_EXT_BLOCK_CNT 0x7E
> +
> +#define STDP4028_IRQ_OUT_CONF_REG 0x02
> +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
> +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
> +#define STDP4028_DPTX_STS_REG 0x3E
> +
> +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
> +
> +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
> +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
> +#define STDP4028_DPTX_IRQ_CONFIG \
> +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
> +
> +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
> +#define STDP4028_DPTX_LINK_STS 0x1000
> +#define STDP4028_CON_STATE_CONNECTED \
> +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
> +
> +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
> +#define STDP4028_DPTX_LINK_CH_STS 0x2000
> +#define STDP4028_DPTX_IRQ_CLEAR \
> +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
> +
> +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
> +
> +struct ge_b850v3_lvds {
> +	struct drm_connector connector;
> +	struct drm_bridge bridge;
> +	struct i2c_client *stdp4028_i2c;
> +	struct i2c_client *stdp2690_i2c;
> +	struct edid *edid;
> +};
> +
> +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
> +
> +u8 *stdp2690_get_edid(struct i2c_client *client)
> +{
> +	struct i2c_adapter *adapter = client->adapter;
> +	unsigned char start = 0x00;
> +	unsigned int total_size;
> +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> +
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr	= client->addr,
> +			.flags	= 0,
> +			.len	= 1,
> +			.buf	= &start,
> +		}, {
> +			.addr	= client->addr,
> +			.flags	= I2C_M_RD,
> +			.len	= EDID_LENGTH,
> +			.buf	= block,
> +		}
> +	};
> +
> +	if (!block)
> +		return NULL;
> +
> +	if (i2c_transfer(adapter, msgs, 2) != 2) {
> +		DRM_ERROR("Unable to read EDID.\n");
> +		goto err;
> +	}
> +
> +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
> +		DRM_ERROR("Invalid EDID data\n");
> +		goto err;
> +	}
> +
> +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> +	if (total_size > EDID_LENGTH) {
> +		kfree(block);
> +		block = kmalloc(total_size, GFP_KERNEL);
> +		if (!block)
> +			return NULL;
> +
> +		/* Yes, read the entire buffer, and do not skip the first
> +		 * EDID_LENGTH bytes.
> +		 */
> +		start = 0x00;
> +		msgs[1].len = total_size;
> +		msgs[1].buf = block;
> +
> +		if (i2c_transfer(adapter, msgs, 2) != 2) {
> +			DRM_ERROR("Unable to read EDID extension blocks.\n");
> +			goto err;
> +		}
> +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
> +			DRM_ERROR("Invalid EDID data\n");
> +			goto err;
> +		}
> +	}
> +
> +	return block;
> +
> +err:
> +	kfree(block);
> +	return NULL;
> +}
> +
> +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
> +{
> +	struct i2c_client *client;
> +	int num_modes = 0;
> +
> +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
> +
> +	kfree(ge_b850v3_lvds_ptr->edid);
> +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
> +
> +	if (ge_b850v3_lvds_ptr->edid) {
> +		drm_mode_connector_update_edid_property(connector,
> +						      ge_b850v3_lvds_ptr->edid);
> +		num_modes = drm_add_edid_modes(connector,
> +					       ge_b850v3_lvds_ptr->edid);
> +	}
> +
> +	return num_modes;
> +}
> +
> +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
> +		struct drm_connector *connector, struct drm_display_mode *mode)
> +{
> +	return MODE_OK;
> +}
> +
> +static const struct
> +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
> +	.get_modes = ge_b850v3_lvds_get_modes,
> +	.mode_valid = ge_b850v3_lvds_mode_valid,
> +};
> +
> +static enum drm_connector_status ge_b850v3_lvds_detect(
> +		struct drm_connector *connector, bool force)
> +{
> +	struct i2c_client *stdp4028_i2c =
> +			ge_b850v3_lvds_ptr->stdp4028_i2c;
> +	s32 link_state;
> +
> +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
> +					      STDP4028_DPTX_STS_REG);
> +
> +	if (link_state == STDP4028_CON_STATE_CONNECTED)
> +		return connector_status_connected;
> +
> +	if (link_state == 0)
> +		return connector_status_disconnected;
> +
> +	return connector_status_unknown;
> +}
> +
> +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
> +	.dpms = drm_atomic_helper_connector_dpms,
> +	.fill_modes = drm_helper_probe_single_connector_modes,
> +	.detect = ge_b850v3_lvds_detect,
> +	.destroy = drm_connector_cleanup,
> +	.reset = drm_atomic_helper_connector_reset,
> +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> +};
> +
> +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
> +{
> +	struct i2c_client *stdp4028_i2c
> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> +
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_STS_REG,
> +				  STDP4028_DPTX_IRQ_CLEAR);
> +
> +	if (ge_b850v3_lvds_ptr->connector.dev)
> +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
> +{
> +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
> +	struct i2c_client *stdp4028_i2c
> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> +	int ret;
> +
> +	if (!bridge->encoder) {
> +		DRM_ERROR("Parent encoder object not found");
> +		return -ENODEV;
> +	}
> +
> +	connector->polled = DRM_CONNECTOR_POLL_HPD;
> +
> +	drm_connector_helper_add(connector,
> +				 &ge_b850v3_lvds_connector_helper_funcs);
> +
> +	ret = drm_connector_init(bridge->dev, connector,
> +				 &ge_b850v3_lvds_connector_funcs,
> +				 DRM_MODE_CONNECTOR_DisplayPort);
> +	if (ret) {
> +		DRM_ERROR("Failed to initialize connector with drm\n");
> +		return ret;
> +	}
> +
> +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
> +	if (ret)
> +		return ret;
> +
> +	/* Configures the bridge to re-enable interrupts after each ack. */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_IRQ_OUT_CONF_REG,
> +				  STDP4028_DPTX_DP_IRQ_EN);
> +
> +	/* Enable interrupts */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_EN_REG,
> +				  STDP4028_DPTX_IRQ_CONFIG);
> +
> +	return 0;
> +}
> +
> +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
> +	.attach = ge_b850v3_lvds_attach,
> +};
> +
> +static int ge_b850v3_lvds_init(struct device *dev)
> +{
> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> +
> +	if (ge_b850v3_lvds_ptr)
> +		goto success;
> +
> +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
> +					  sizeof(*ge_b850v3_lvds_ptr),
> +					  GFP_KERNEL);
> +
> +	if (!ge_b850v3_lvds_ptr) {
> +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +		return -ENOMEM;
> +	}
> +
> +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
> +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
> +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
> +
> +success:
> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +	return 0;
> +}
> +
> +static void ge_b850v3_lvds_remove(void)
> +{
> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> +	/*
> +	 * This check is to avoid both the drivers
> +	 * removing the bridge in their remove() function
> +	 */
> +	if (!ge_b850v3_lvds_ptr)
> +		goto out;
> +
> +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> +
> +	kfree(ge_b850v3_lvds_ptr->edid);
> +
> +	ge_b850v3_lvds_ptr = NULL;
> +out:
> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +}
> +
> +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
> +				       const struct i2c_device_id *id)
> +{
> +	struct device *dev = &stdp4028_i2c->dev;
> +
> +	ge_b850v3_lvds_init(dev);
> +
> +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
> +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
> +
> +	/* Clear pending interrupts since power up. */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_STS_REG,
> +				  STDP4028_DPTX_IRQ_CLEAR);
> +
> +	if (!stdp4028_i2c->irq)
> +		return 0;
> +
> +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
> +			stdp4028_i2c->irq, NULL,
> +			ge_b850v3_lvds_irq_handler,
> +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
> +}
> +
> +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
> +{
> +	ge_b850v3_lvds_remove();
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
> +	{"stdp4028_ge_fw", 0},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
> +
> +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
> +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
> +
> +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
> +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
> +	.probe		= stdp4028_ge_b850v3_fw_probe,
> +	.remove		= stdp4028_ge_b850v3_fw_remove,
> +	.driver		= {
> +		.name		= "stdp4028-ge-b850v3-fw",
> +		.of_match_table = stdp4028_ge_b850v3_fw_match,
> +	},
> +};
> +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
> +
> +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
> +				       const struct i2c_device_id *id)
> +{
> +	struct device *dev = &stdp2690_i2c->dev;
> +
> +	ge_b850v3_lvds_init(dev);
> +
> +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
> +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
> +
> +	return 0;
> +}
> +
> +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
> +{
> +	ge_b850v3_lvds_remove();
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> +	{"stdp2690_ge_fw", 0},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> +
> +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> +
> +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> +	.probe		= stdp2690_ge_b850v3_fw_probe,
> +	.remove		= stdp2690_ge_b850v3_fw_remove,
> +	.driver		= {
> +		.name		= "stdp2690-ge-b850v3-fw",
> +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> +	},
> +};
> +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);

Didn't catch this in the last series, but there can only be one
module_init call per module. This breaks compilation when the
driver is built as a module.

You could do something like:

static int __init stdpxxxx_ge_b850v3_init(void)
{
	int ret;

	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
	if (ret)
		return ret;

	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
}
module_init(stdpxxxx_ge_b850v3_init);

static void __exit stdpxxxx_ge_b850v3_exit(void)
{
	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
}
module_exit(stdpxxxx_ge_b850v3_exit);

Thanks,
Archit

> +
> +MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
> +MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
> +MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
> +MODULE_LICENSE("GPL v2");
>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-01  4:08     ` Archit Taneja
  0 siblings, 0 replies; 29+ messages in thread
From: Archit Taneja @ 2017-03-01  4:08 UTC (permalink / raw)
  To: linux-arm-kernel



On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
> The video processing pipeline on the second output on the GE B850v3:
>
>   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>
> Each bridge has a dedicated flash containing firmware for supporting the
> custom design. The result is that in this design neither the STDP4028
> nor the STDP2690 behave as the stock bridges would. The compatible
> strings include the suffix "-ge-b850v3-fw" to make it clear that the
> driver is for the bridges with the firmware which is specific for the GE
> B850v3.
>
> The driver is powerless to control the video processing pipeline, as the
> two bridges behaves as a single one. The driver is only needed for
> telling the host about EDID / HPD, and for giving the host powers to ack
> interrupts.
>
> This driver adds one i2c_device for each bridge, but only one
> drm_bridge. This design allows the creation of a functional connector
> that is capable of reading EDID from the STDP2690 while handling
> interrupts on the STDP4028.
>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Martin Donnelly <martin.donnelly@ge.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Cc: David Airlie <airlied@linux.ie>
> Cc: Thierry Reding <treding@nvidia.com>
> Cc: Thierry Reding <thierry.reding@gmail.com>
> Cc: Archit Taneja <architt@codeaurora.org>
> Cc: Enric Balletbo <enric.balletbo@collabora.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> ---
> Changes from V1:
>  - Updated copyright year
>  - Fixed blank line issues
>  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
>    added a comment to explain the test.
>  - Fixed checkpatch strict warnings about continuation lines. In one case
>    fixing the warning would cause the continuation line to be over 80 chars and
>    that strict warning remains.
>
>  drivers/gpu/drm/bridge/Kconfig                     |  11 +
>  drivers/gpu/drm/bridge/Makefile                    |   1 +
>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
>  3 files changed, 423 insertions(+)
>  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>
> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> index eb8688e..4a937f1 100644
> --- a/drivers/gpu/drm/bridge/Kconfig
> +++ b/drivers/gpu/drm/bridge/Kconfig
> @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
>  	  Support the I2S Audio interface which is part of the Synopsis
>  	  Designware HDMI block.
>
> +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
> +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
> +	depends on OF
> +	select DRM_KMS_HELPER
> +	select DRM_PANEL
> +	---help---
> +          This is a driver for the display bridges of
> +          GE B850v3 that convert dual channel LVDS
> +          to DP++. This is used with the i.MX6 imx-ldb
> +          driver. You are likely to say N here.
> +
>  config DRM_NXP_PTN3460
>  	tristate "NXP PTN3460 DP/LVDS bridge"
>  	depends on OF
> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> index 2e83a785..af0b7cc 100644
> --- a/drivers/gpu/drm/bridge/Makefile
> +++ b/drivers/gpu/drm/bridge/Makefile
> @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
>  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
>  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
>  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
> +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
>  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
>  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
>  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> new file mode 100644
> index 0000000..6f82a44
> --- /dev/null
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -0,0 +1,411 @@
> +/*
> + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
> + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
> +
> + * Copyright (c) 2017, Collabora Ltd.
> + * Copyright (c) 2017, General Electric Company
> +
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> +
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> +
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
> + * display bridge of the GE B850v3. There are two physical bridges on the video
> + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
> + * physical bridges are automatically configured by the input video signal, and
> + * the driver has no access to the video processing pipeline. The driver is
> + * only needed to read EDID from the STDP2690 and to handle HPD events from the
> + * STDP4028. The driver communicates with both bridges over i2c. The video
> + * signal pipeline is as follows:
> + *
> + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> + *
> + */
> +
> +#include <linux/gpio.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <drm/drm_atomic.h>
> +#include <drm/drm_atomic_helper.h>
> +#include <drm/drm_crtc_helper.h>
> +#include <drm/drm_edid.h>
> +#include <drm/drmP.h>
> +
> +#define EDID_EXT_BLOCK_CNT 0x7E
> +
> +#define STDP4028_IRQ_OUT_CONF_REG 0x02
> +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
> +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
> +#define STDP4028_DPTX_STS_REG 0x3E
> +
> +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
> +
> +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
> +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
> +#define STDP4028_DPTX_IRQ_CONFIG \
> +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
> +
> +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
> +#define STDP4028_DPTX_LINK_STS 0x1000
> +#define STDP4028_CON_STATE_CONNECTED \
> +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
> +
> +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
> +#define STDP4028_DPTX_LINK_CH_STS 0x2000
> +#define STDP4028_DPTX_IRQ_CLEAR \
> +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
> +
> +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
> +
> +struct ge_b850v3_lvds {
> +	struct drm_connector connector;
> +	struct drm_bridge bridge;
> +	struct i2c_client *stdp4028_i2c;
> +	struct i2c_client *stdp2690_i2c;
> +	struct edid *edid;
> +};
> +
> +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
> +
> +u8 *stdp2690_get_edid(struct i2c_client *client)
> +{
> +	struct i2c_adapter *adapter = client->adapter;
> +	unsigned char start = 0x00;
> +	unsigned int total_size;
> +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> +
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr	= client->addr,
> +			.flags	= 0,
> +			.len	= 1,
> +			.buf	= &start,
> +		}, {
> +			.addr	= client->addr,
> +			.flags	= I2C_M_RD,
> +			.len	= EDID_LENGTH,
> +			.buf	= block,
> +		}
> +	};
> +
> +	if (!block)
> +		return NULL;
> +
> +	if (i2c_transfer(adapter, msgs, 2) != 2) {
> +		DRM_ERROR("Unable to read EDID.\n");
> +		goto err;
> +	}
> +
> +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
> +		DRM_ERROR("Invalid EDID data\n");
> +		goto err;
> +	}
> +
> +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> +	if (total_size > EDID_LENGTH) {
> +		kfree(block);
> +		block = kmalloc(total_size, GFP_KERNEL);
> +		if (!block)
> +			return NULL;
> +
> +		/* Yes, read the entire buffer, and do not skip the first
> +		 * EDID_LENGTH bytes.
> +		 */
> +		start = 0x00;
> +		msgs[1].len = total_size;
> +		msgs[1].buf = block;
> +
> +		if (i2c_transfer(adapter, msgs, 2) != 2) {
> +			DRM_ERROR("Unable to read EDID extension blocks.\n");
> +			goto err;
> +		}
> +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
> +			DRM_ERROR("Invalid EDID data\n");
> +			goto err;
> +		}
> +	}
> +
> +	return block;
> +
> +err:
> +	kfree(block);
> +	return NULL;
> +}
> +
> +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
> +{
> +	struct i2c_client *client;
> +	int num_modes = 0;
> +
> +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
> +
> +	kfree(ge_b850v3_lvds_ptr->edid);
> +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
> +
> +	if (ge_b850v3_lvds_ptr->edid) {
> +		drm_mode_connector_update_edid_property(connector,
> +						      ge_b850v3_lvds_ptr->edid);
> +		num_modes = drm_add_edid_modes(connector,
> +					       ge_b850v3_lvds_ptr->edid);
> +	}
> +
> +	return num_modes;
> +}
> +
> +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
> +		struct drm_connector *connector, struct drm_display_mode *mode)
> +{
> +	return MODE_OK;
> +}
> +
> +static const struct
> +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
> +	.get_modes = ge_b850v3_lvds_get_modes,
> +	.mode_valid = ge_b850v3_lvds_mode_valid,
> +};
> +
> +static enum drm_connector_status ge_b850v3_lvds_detect(
> +		struct drm_connector *connector, bool force)
> +{
> +	struct i2c_client *stdp4028_i2c =
> +			ge_b850v3_lvds_ptr->stdp4028_i2c;
> +	s32 link_state;
> +
> +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
> +					      STDP4028_DPTX_STS_REG);
> +
> +	if (link_state == STDP4028_CON_STATE_CONNECTED)
> +		return connector_status_connected;
> +
> +	if (link_state == 0)
> +		return connector_status_disconnected;
> +
> +	return connector_status_unknown;
> +}
> +
> +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
> +	.dpms = drm_atomic_helper_connector_dpms,
> +	.fill_modes = drm_helper_probe_single_connector_modes,
> +	.detect = ge_b850v3_lvds_detect,
> +	.destroy = drm_connector_cleanup,
> +	.reset = drm_atomic_helper_connector_reset,
> +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> +};
> +
> +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
> +{
> +	struct i2c_client *stdp4028_i2c
> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> +
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_STS_REG,
> +				  STDP4028_DPTX_IRQ_CLEAR);
> +
> +	if (ge_b850v3_lvds_ptr->connector.dev)
> +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
> +{
> +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
> +	struct i2c_client *stdp4028_i2c
> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> +	int ret;
> +
> +	if (!bridge->encoder) {
> +		DRM_ERROR("Parent encoder object not found");
> +		return -ENODEV;
> +	}
> +
> +	connector->polled = DRM_CONNECTOR_POLL_HPD;
> +
> +	drm_connector_helper_add(connector,
> +				 &ge_b850v3_lvds_connector_helper_funcs);
> +
> +	ret = drm_connector_init(bridge->dev, connector,
> +				 &ge_b850v3_lvds_connector_funcs,
> +				 DRM_MODE_CONNECTOR_DisplayPort);
> +	if (ret) {
> +		DRM_ERROR("Failed to initialize connector with drm\n");
> +		return ret;
> +	}
> +
> +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
> +	if (ret)
> +		return ret;
> +
> +	/* Configures the bridge to re-enable interrupts after each ack. */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_IRQ_OUT_CONF_REG,
> +				  STDP4028_DPTX_DP_IRQ_EN);
> +
> +	/* Enable interrupts */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_EN_REG,
> +				  STDP4028_DPTX_IRQ_CONFIG);
> +
> +	return 0;
> +}
> +
> +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
> +	.attach = ge_b850v3_lvds_attach,
> +};
> +
> +static int ge_b850v3_lvds_init(struct device *dev)
> +{
> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> +
> +	if (ge_b850v3_lvds_ptr)
> +		goto success;
> +
> +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
> +					  sizeof(*ge_b850v3_lvds_ptr),
> +					  GFP_KERNEL);
> +
> +	if (!ge_b850v3_lvds_ptr) {
> +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +		return -ENOMEM;
> +	}
> +
> +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
> +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
> +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
> +
> +success:
> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +	return 0;
> +}
> +
> +static void ge_b850v3_lvds_remove(void)
> +{
> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> +	/*
> +	 * This check is to avoid both the drivers
> +	 * removing the bridge in their remove() function
> +	 */
> +	if (!ge_b850v3_lvds_ptr)
> +		goto out;
> +
> +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> +
> +	kfree(ge_b850v3_lvds_ptr->edid);
> +
> +	ge_b850v3_lvds_ptr = NULL;
> +out:
> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> +}
> +
> +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
> +				       const struct i2c_device_id *id)
> +{
> +	struct device *dev = &stdp4028_i2c->dev;
> +
> +	ge_b850v3_lvds_init(dev);
> +
> +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
> +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
> +
> +	/* Clear pending interrupts since power up. */
> +	i2c_smbus_write_word_data(stdp4028_i2c,
> +				  STDP4028_DPTX_IRQ_STS_REG,
> +				  STDP4028_DPTX_IRQ_CLEAR);
> +
> +	if (!stdp4028_i2c->irq)
> +		return 0;
> +
> +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
> +			stdp4028_i2c->irq, NULL,
> +			ge_b850v3_lvds_irq_handler,
> +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
> +}
> +
> +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
> +{
> +	ge_b850v3_lvds_remove();
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
> +	{"stdp4028_ge_fw", 0},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
> +
> +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
> +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
> +
> +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
> +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
> +	.probe		= stdp4028_ge_b850v3_fw_probe,
> +	.remove		= stdp4028_ge_b850v3_fw_remove,
> +	.driver		= {
> +		.name		= "stdp4028-ge-b850v3-fw",
> +		.of_match_table = stdp4028_ge_b850v3_fw_match,
> +	},
> +};
> +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
> +
> +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
> +				       const struct i2c_device_id *id)
> +{
> +	struct device *dev = &stdp2690_i2c->dev;
> +
> +	ge_b850v3_lvds_init(dev);
> +
> +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
> +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
> +
> +	return 0;
> +}
> +
> +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
> +{
> +	ge_b850v3_lvds_remove();
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> +	{"stdp2690_ge_fw", 0},
> +	{},
> +};
> +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> +
> +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> +
> +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> +	.probe		= stdp2690_ge_b850v3_fw_probe,
> +	.remove		= stdp2690_ge_b850v3_fw_remove,
> +	.driver		= {
> +		.name		= "stdp2690-ge-b850v3-fw",
> +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> +	},
> +};
> +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);

Didn't catch this in the last series, but there can only be one
module_init call per module. This breaks compilation when the
driver is built as a module.

You could do something like:

static int __init stdpxxxx_ge_b850v3_init(void)
{
	int ret;

	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
	if (ret)
		return ret;

	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
}
module_init(stdpxxxx_ge_b850v3_init);

static void __exit stdpxxxx_ge_b850v3_exit(void)
{
	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
}
module_exit(stdpxxxx_ge_b850v3_exit);

Thanks,
Archit

> +
> +MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
> +MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
> +MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
> +MODULE_LICENSE("GPL v2");
>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  2017-03-01  4:08     ` Archit Taneja
  (?)
@ 2017-03-01 10:38       ` Peter Senna Tschudin
  -1 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-03-01 10:38 UTC (permalink / raw)
  To: Archit Taneja
  Cc: airlied, akpm, daniel.vetter, davem, devicetree, dri-devel,
	enric.balletbo, eballetbo, galak, gregkh, heiko, ijc+devicetree,
	javier, jslaby, kernel, linux-arm-kernel, linux, linux-kernel,
	linux, mark.rutland, martin.donnelly, martyn.welch, mchehab,
	pawel.moll, peter.senna, p.zabel, thierry.reding, rmk+kernel,
	robh+dt, shawnguo, tiwai, treding, ykk, laurent.pinchart,
	Rob Herring, Fabio Estevam

Hi Archit,

Thank you for the review!

On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
> 
> 
> On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
> > The video processing pipeline on the second output on the GE B850v3:
> > 
> >   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> > 
> > Each bridge has a dedicated flash containing firmware for supporting the
> > custom design. The result is that in this design neither the STDP4028
> > nor the STDP2690 behave as the stock bridges would. The compatible
> > strings include the suffix "-ge-b850v3-fw" to make it clear that the
> > driver is for the bridges with the firmware which is specific for the GE
> > B850v3.
> > 
> > The driver is powerless to control the video processing pipeline, as the
> > two bridges behaves as a single one. The driver is only needed for
> > telling the host about EDID / HPD, and for giving the host powers to ack
> > interrupts.
> > 
> > This driver adds one i2c_device for each bridge, but only one
> > drm_bridge. This design allows the creation of a functional connector
> > that is capable of reading EDID from the STDP2690 while handling
> > interrupts on the STDP4028.
> > 
> > Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> > Cc: Martin Donnelly <martin.donnelly@ge.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> > Cc: Philipp Zabel <p.zabel@pengutronix.de>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Fabio Estevam <fabio.estevam@nxp.com>
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Thierry Reding <treding@nvidia.com>
> > Cc: Thierry Reding <thierry.reding@gmail.com>
> > Cc: Archit Taneja <architt@codeaurora.org>
> > Cc: Enric Balletbo <enric.balletbo@collabora.com>
> > Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> > ---
> > Changes from V1:
> >  - Updated copyright year
> >  - Fixed blank line issues
> >  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
> >    added a comment to explain the test.
> >  - Fixed checkpatch strict warnings about continuation lines. In one case
> >    fixing the warning would cause the continuation line to be over 80 chars and
> >    that strict warning remains.
> > 
> >  drivers/gpu/drm/bridge/Kconfig                     |  11 +
> >  drivers/gpu/drm/bridge/Makefile                    |   1 +
> >  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
> >  3 files changed, 423 insertions(+)
> >  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > 
> > diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> > index eb8688e..4a937f1 100644
> > --- a/drivers/gpu/drm/bridge/Kconfig
> > +++ b/drivers/gpu/drm/bridge/Kconfig
> > @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
> >  	  Support the I2S Audio interface which is part of the Synopsis
> >  	  Designware HDMI block.
> > 
> > +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
> > +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
> > +	depends on OF
> > +	select DRM_KMS_HELPER
> > +	select DRM_PANEL
> > +	---help---
> > +          This is a driver for the display bridges of
> > +          GE B850v3 that convert dual channel LVDS
> > +          to DP++. This is used with the i.MX6 imx-ldb
> > +          driver. You are likely to say N here.
> > +
> >  config DRM_NXP_PTN3460
> >  	tristate "NXP PTN3460 DP/LVDS bridge"
> >  	depends on OF
> > diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> > index 2e83a785..af0b7cc 100644
> > --- a/drivers/gpu/drm/bridge/Makefile
> > +++ b/drivers/gpu/drm/bridge/Makefile
> > @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
> >  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
> >  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
> >  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
> > +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
> >  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
> >  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
> >  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
> > diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > new file mode 100644
> > index 0000000..6f82a44
> > --- /dev/null
> > +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > @@ -0,0 +1,411 @@
> > +/*
> > + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
> > + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
> > +
> > + * Copyright (c) 2017, Collabora Ltd.
> > + * Copyright (c) 2017, General Electric Company
> > +
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms and conditions of the GNU General Public License,
> > + * version 2, as published by the Free Software Foundation.
> > +
> > + * This program is distributed in the hope it will be useful, but WITHOUT
> > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > + * more details.
> > +
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > +
> > + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
> > + * display bridge of the GE B850v3. There are two physical bridges on the video
> > + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
> > + * physical bridges are automatically configured by the input video signal, and
> > + * the driver has no access to the video processing pipeline. The driver is
> > + * only needed to read EDID from the STDP2690 and to handle HPD events from the
> > + * STDP4028. The driver communicates with both bridges over i2c. The video
> > + * signal pipeline is as follows:
> > + *
> > + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> > + *
> > + */
> > +
> > +#include <linux/gpio.h>
> > +#include <linux/i2c.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <drm/drm_atomic.h>
> > +#include <drm/drm_atomic_helper.h>
> > +#include <drm/drm_crtc_helper.h>
> > +#include <drm/drm_edid.h>
> > +#include <drm/drmP.h>
> > +
> > +#define EDID_EXT_BLOCK_CNT 0x7E
> > +
> > +#define STDP4028_IRQ_OUT_CONF_REG 0x02
> > +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
> > +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
> > +#define STDP4028_DPTX_STS_REG 0x3E
> > +
> > +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
> > +
> > +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
> > +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
> > +#define STDP4028_DPTX_IRQ_CONFIG \
> > +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
> > +
> > +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
> > +#define STDP4028_DPTX_LINK_STS 0x1000
> > +#define STDP4028_CON_STATE_CONNECTED \
> > +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
> > +
> > +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
> > +#define STDP4028_DPTX_LINK_CH_STS 0x2000
> > +#define STDP4028_DPTX_IRQ_CLEAR \
> > +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
> > +
> > +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
> > +
> > +struct ge_b850v3_lvds {
> > +	struct drm_connector connector;
> > +	struct drm_bridge bridge;
> > +	struct i2c_client *stdp4028_i2c;
> > +	struct i2c_client *stdp2690_i2c;
> > +	struct edid *edid;
> > +};
> > +
> > +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
> > +
> > +u8 *stdp2690_get_edid(struct i2c_client *client)
> > +{
> > +	struct i2c_adapter *adapter = client->adapter;
> > +	unsigned char start = 0x00;
> > +	unsigned int total_size;
> > +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> > +
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr	= client->addr,
> > +			.flags	= 0,
> > +			.len	= 1,
> > +			.buf	= &start,
> > +		}, {
> > +			.addr	= client->addr,
> > +			.flags	= I2C_M_RD,
> > +			.len	= EDID_LENGTH,
> > +			.buf	= block,
> > +		}
> > +	};
> > +
> > +	if (!block)
> > +		return NULL;
> > +
> > +	if (i2c_transfer(adapter, msgs, 2) != 2) {
> > +		DRM_ERROR("Unable to read EDID.\n");
> > +		goto err;
> > +	}
> > +
> > +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
> > +		DRM_ERROR("Invalid EDID data\n");
> > +		goto err;
> > +	}
> > +
> > +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> > +	if (total_size > EDID_LENGTH) {
> > +		kfree(block);
> > +		block = kmalloc(total_size, GFP_KERNEL);
> > +		if (!block)
> > +			return NULL;
> > +
> > +		/* Yes, read the entire buffer, and do not skip the first
> > +		 * EDID_LENGTH bytes.
> > +		 */
> > +		start = 0x00;
> > +		msgs[1].len = total_size;
> > +		msgs[1].buf = block;
> > +
> > +		if (i2c_transfer(adapter, msgs, 2) != 2) {
> > +			DRM_ERROR("Unable to read EDID extension blocks.\n");
> > +			goto err;
> > +		}
> > +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
> > +			DRM_ERROR("Invalid EDID data\n");
> > +			goto err;
> > +		}
> > +	}
> > +
> > +	return block;
> > +
> > +err:
> > +	kfree(block);
> > +	return NULL;
> > +}
> > +
> > +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
> > +{
> > +	struct i2c_client *client;
> > +	int num_modes = 0;
> > +
> > +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
> > +
> > +	kfree(ge_b850v3_lvds_ptr->edid);
> > +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
> > +
> > +	if (ge_b850v3_lvds_ptr->edid) {
> > +		drm_mode_connector_update_edid_property(connector,
> > +						      ge_b850v3_lvds_ptr->edid);
> > +		num_modes = drm_add_edid_modes(connector,
> > +					       ge_b850v3_lvds_ptr->edid);
> > +	}
> > +
> > +	return num_modes;
> > +}
> > +
> > +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
> > +		struct drm_connector *connector, struct drm_display_mode *mode)
> > +{
> > +	return MODE_OK;
> > +}
> > +
> > +static const struct
> > +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
> > +	.get_modes = ge_b850v3_lvds_get_modes,
> > +	.mode_valid = ge_b850v3_lvds_mode_valid,
> > +};
> > +
> > +static enum drm_connector_status ge_b850v3_lvds_detect(
> > +		struct drm_connector *connector, bool force)
> > +{
> > +	struct i2c_client *stdp4028_i2c =
> > +			ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +	s32 link_state;
> > +
> > +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
> > +					      STDP4028_DPTX_STS_REG);
> > +
> > +	if (link_state == STDP4028_CON_STATE_CONNECTED)
> > +		return connector_status_connected;
> > +
> > +	if (link_state == 0)
> > +		return connector_status_disconnected;
> > +
> > +	return connector_status_unknown;
> > +}
> > +
> > +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
> > +	.dpms = drm_atomic_helper_connector_dpms,
> > +	.fill_modes = drm_helper_probe_single_connector_modes,
> > +	.detect = ge_b850v3_lvds_detect,
> > +	.destroy = drm_connector_cleanup,
> > +	.reset = drm_atomic_helper_connector_reset,
> > +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> > +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> > +};
> > +
> > +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
> > +{
> > +	struct i2c_client *stdp4028_i2c
> > +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_STS_REG,
> > +				  STDP4028_DPTX_IRQ_CLEAR);
> > +
> > +	if (ge_b850v3_lvds_ptr->connector.dev)
> > +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> > +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
> > +{
> > +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
> > +	struct i2c_client *stdp4028_i2c
> > +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +	int ret;
> > +
> > +	if (!bridge->encoder) {
> > +		DRM_ERROR("Parent encoder object not found");
> > +		return -ENODEV;
> > +	}
> > +
> > +	connector->polled = DRM_CONNECTOR_POLL_HPD;
> > +
> > +	drm_connector_helper_add(connector,
> > +				 &ge_b850v3_lvds_connector_helper_funcs);
> > +
> > +	ret = drm_connector_init(bridge->dev, connector,
> > +				 &ge_b850v3_lvds_connector_funcs,
> > +				 DRM_MODE_CONNECTOR_DisplayPort);
> > +	if (ret) {
> > +		DRM_ERROR("Failed to initialize connector with drm\n");
> > +		return ret;
> > +	}
> > +
> > +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* Configures the bridge to re-enable interrupts after each ack. */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_IRQ_OUT_CONF_REG,
> > +				  STDP4028_DPTX_DP_IRQ_EN);
> > +
> > +	/* Enable interrupts */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_EN_REG,
> > +				  STDP4028_DPTX_IRQ_CONFIG);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
> > +	.attach = ge_b850v3_lvds_attach,
> > +};
> > +
> > +static int ge_b850v3_lvds_init(struct device *dev)
> > +{
> > +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> > +
> > +	if (ge_b850v3_lvds_ptr)
> > +		goto success;
> > +
> > +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
> > +					  sizeof(*ge_b850v3_lvds_ptr),
> > +					  GFP_KERNEL);
> > +
> > +	if (!ge_b850v3_lvds_ptr) {
> > +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
> > +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
> > +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
> > +
> > +success:
> > +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +	return 0;
> > +}
> > +
> > +static void ge_b850v3_lvds_remove(void)
> > +{
> > +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> > +	/*
> > +	 * This check is to avoid both the drivers
> > +	 * removing the bridge in their remove() function
> > +	 */
> > +	if (!ge_b850v3_lvds_ptr)
> > +		goto out;
> > +
> > +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> > +
> > +	kfree(ge_b850v3_lvds_ptr->edid);
> > +
> > +	ge_b850v3_lvds_ptr = NULL;
> > +out:
> > +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +}
> > +
> > +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
> > +				       const struct i2c_device_id *id)
> > +{
> > +	struct device *dev = &stdp4028_i2c->dev;
> > +
> > +	ge_b850v3_lvds_init(dev);
> > +
> > +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
> > +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
> > +
> > +	/* Clear pending interrupts since power up. */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_STS_REG,
> > +				  STDP4028_DPTX_IRQ_CLEAR);
> > +
> > +	if (!stdp4028_i2c->irq)
> > +		return 0;
> > +
> > +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
> > +			stdp4028_i2c->irq, NULL,
> > +			ge_b850v3_lvds_irq_handler,
> > +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> > +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
> > +}
> > +
> > +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
> > +{
> > +	ge_b850v3_lvds_remove();
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp4028_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp4028_ge_b850v3_fw_probe,
> > +	.remove		= stdp4028_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp4028-ge-b850v3-fw",
> > +		.of_match_table = stdp4028_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
> > +
> > +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
> > +				       const struct i2c_device_id *id)
> > +{
> > +	struct device *dev = &stdp2690_i2c->dev;
> > +
> > +	ge_b850v3_lvds_init(dev);
> > +
> > +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
> > +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
> > +
> > +	return 0;
> > +}
> > +
> > +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
> > +{
> > +	ge_b850v3_lvds_remove();
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp2690_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp2690_ge_b850v3_fw_probe,
> > +	.remove		= stdp2690_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp2690-ge-b850v3-fw",
> > +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
> 
> Didn't catch this in the last series, but there can only be one
> module_init call per module. This breaks compilation when the
> driver is built as a module.

Unfortunately yes. Got loads of errors when trying to compile as a
module.

> 
> You could do something like:
> 
> static int __init stdpxxxx_ge_b850v3_init(void)
> {
> 	int ret;
> 
> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
> 	if (ret)
> 		return ret;
> 
> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> }
> module_init(stdpxxxx_ge_b850v3_init);
> 
> static void __exit stdpxxxx_ge_b850v3_exit(void)
> {
> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> }
> module_exit(stdpxxxx_ge_b850v3_exit);

Thank you! I was wondering if merging ge_b850v3_lvds_init() with
stdpxxxx_ge_b850v3_init() and ge_b850v3_lvds_remove() with
stdpxxxx_ge_b850v3_exit() make sense as it can probably eliminate the
need for the mutex.

> 
> Thanks,
> Archit
> 
> > +
> > +MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
> > +MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
> > +MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
> > +MODULE_LICENSE("GPL v2");
> > 
> 
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-01 10:38       ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-03-01 10:38 UTC (permalink / raw)
  To: Archit Taneja
  Cc: mark.rutland, heiko, airlied, daniel.vetter, peter.senna,
	dri-devel, tiwai, thierry.reding, laurent.pinchart, ykk, jslaby,
	martyn.welch, Rob Herring, mchehab, linux, javier, treding,
	linux, martin.donnelly, devicetree, p.zabel, pawel.moll,
	ijc+devicetree, eballetbo, Fabio Estevam, rmk+kernel, robh+dt,
	linux-arm-kernel, gregkh, linux-kernel, kernel, galak,
	enric.balletbo, akpm, shawnguo, davem

Hi Archit,

Thank you for the review!

On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
> 
> 
> On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
> > The video processing pipeline on the second output on the GE B850v3:
> > 
> >   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> > 
> > Each bridge has a dedicated flash containing firmware for supporting the
> > custom design. The result is that in this design neither the STDP4028
> > nor the STDP2690 behave as the stock bridges would. The compatible
> > strings include the suffix "-ge-b850v3-fw" to make it clear that the
> > driver is for the bridges with the firmware which is specific for the GE
> > B850v3.
> > 
> > The driver is powerless to control the video processing pipeline, as the
> > two bridges behaves as a single one. The driver is only needed for
> > telling the host about EDID / HPD, and for giving the host powers to ack
> > interrupts.
> > 
> > This driver adds one i2c_device for each bridge, but only one
> > drm_bridge. This design allows the creation of a functional connector
> > that is capable of reading EDID from the STDP2690 while handling
> > interrupts on the STDP4028.
> > 
> > Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> > Cc: Martin Donnelly <martin.donnelly@ge.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> > Cc: Philipp Zabel <p.zabel@pengutronix.de>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Fabio Estevam <fabio.estevam@nxp.com>
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Thierry Reding <treding@nvidia.com>
> > Cc: Thierry Reding <thierry.reding@gmail.com>
> > Cc: Archit Taneja <architt@codeaurora.org>
> > Cc: Enric Balletbo <enric.balletbo@collabora.com>
> > Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> > ---
> > Changes from V1:
> >  - Updated copyright year
> >  - Fixed blank line issues
> >  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
> >    added a comment to explain the test.
> >  - Fixed checkpatch strict warnings about continuation lines. In one case
> >    fixing the warning would cause the continuation line to be over 80 chars and
> >    that strict warning remains.
> > 
> >  drivers/gpu/drm/bridge/Kconfig                     |  11 +
> >  drivers/gpu/drm/bridge/Makefile                    |   1 +
> >  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
> >  3 files changed, 423 insertions(+)
> >  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > 
> > diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> > index eb8688e..4a937f1 100644
> > --- a/drivers/gpu/drm/bridge/Kconfig
> > +++ b/drivers/gpu/drm/bridge/Kconfig
> > @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
> >  	  Support the I2S Audio interface which is part of the Synopsis
> >  	  Designware HDMI block.
> > 
> > +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
> > +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
> > +	depends on OF
> > +	select DRM_KMS_HELPER
> > +	select DRM_PANEL
> > +	---help---
> > +          This is a driver for the display bridges of
> > +          GE B850v3 that convert dual channel LVDS
> > +          to DP++. This is used with the i.MX6 imx-ldb
> > +          driver. You are likely to say N here.
> > +
> >  config DRM_NXP_PTN3460
> >  	tristate "NXP PTN3460 DP/LVDS bridge"
> >  	depends on OF
> > diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> > index 2e83a785..af0b7cc 100644
> > --- a/drivers/gpu/drm/bridge/Makefile
> > +++ b/drivers/gpu/drm/bridge/Makefile
> > @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
> >  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
> >  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
> >  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
> > +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
> >  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
> >  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
> >  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
> > diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > new file mode 100644
> > index 0000000..6f82a44
> > --- /dev/null
> > +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > @@ -0,0 +1,411 @@
> > +/*
> > + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
> > + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
> > +
> > + * Copyright (c) 2017, Collabora Ltd.
> > + * Copyright (c) 2017, General Electric Company
> > +
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms and conditions of the GNU General Public License,
> > + * version 2, as published by the Free Software Foundation.
> > +
> > + * This program is distributed in the hope it will be useful, but WITHOUT
> > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > + * more details.
> > +
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > +
> > + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
> > + * display bridge of the GE B850v3. There are two physical bridges on the video
> > + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
> > + * physical bridges are automatically configured by the input video signal, and
> > + * the driver has no access to the video processing pipeline. The driver is
> > + * only needed to read EDID from the STDP2690 and to handle HPD events from the
> > + * STDP4028. The driver communicates with both bridges over i2c. The video
> > + * signal pipeline is as follows:
> > + *
> > + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> > + *
> > + */
> > +
> > +#include <linux/gpio.h>
> > +#include <linux/i2c.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <drm/drm_atomic.h>
> > +#include <drm/drm_atomic_helper.h>
> > +#include <drm/drm_crtc_helper.h>
> > +#include <drm/drm_edid.h>
> > +#include <drm/drmP.h>
> > +
> > +#define EDID_EXT_BLOCK_CNT 0x7E
> > +
> > +#define STDP4028_IRQ_OUT_CONF_REG 0x02
> > +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
> > +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
> > +#define STDP4028_DPTX_STS_REG 0x3E
> > +
> > +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
> > +
> > +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
> > +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
> > +#define STDP4028_DPTX_IRQ_CONFIG \
> > +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
> > +
> > +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
> > +#define STDP4028_DPTX_LINK_STS 0x1000
> > +#define STDP4028_CON_STATE_CONNECTED \
> > +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
> > +
> > +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
> > +#define STDP4028_DPTX_LINK_CH_STS 0x2000
> > +#define STDP4028_DPTX_IRQ_CLEAR \
> > +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
> > +
> > +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
> > +
> > +struct ge_b850v3_lvds {
> > +	struct drm_connector connector;
> > +	struct drm_bridge bridge;
> > +	struct i2c_client *stdp4028_i2c;
> > +	struct i2c_client *stdp2690_i2c;
> > +	struct edid *edid;
> > +};
> > +
> > +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
> > +
> > +u8 *stdp2690_get_edid(struct i2c_client *client)
> > +{
> > +	struct i2c_adapter *adapter = client->adapter;
> > +	unsigned char start = 0x00;
> > +	unsigned int total_size;
> > +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> > +
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr	= client->addr,
> > +			.flags	= 0,
> > +			.len	= 1,
> > +			.buf	= &start,
> > +		}, {
> > +			.addr	= client->addr,
> > +			.flags	= I2C_M_RD,
> > +			.len	= EDID_LENGTH,
> > +			.buf	= block,
> > +		}
> > +	};
> > +
> > +	if (!block)
> > +		return NULL;
> > +
> > +	if (i2c_transfer(adapter, msgs, 2) != 2) {
> > +		DRM_ERROR("Unable to read EDID.\n");
> > +		goto err;
> > +	}
> > +
> > +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
> > +		DRM_ERROR("Invalid EDID data\n");
> > +		goto err;
> > +	}
> > +
> > +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> > +	if (total_size > EDID_LENGTH) {
> > +		kfree(block);
> > +		block = kmalloc(total_size, GFP_KERNEL);
> > +		if (!block)
> > +			return NULL;
> > +
> > +		/* Yes, read the entire buffer, and do not skip the first
> > +		 * EDID_LENGTH bytes.
> > +		 */
> > +		start = 0x00;
> > +		msgs[1].len = total_size;
> > +		msgs[1].buf = block;
> > +
> > +		if (i2c_transfer(adapter, msgs, 2) != 2) {
> > +			DRM_ERROR("Unable to read EDID extension blocks.\n");
> > +			goto err;
> > +		}
> > +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
> > +			DRM_ERROR("Invalid EDID data\n");
> > +			goto err;
> > +		}
> > +	}
> > +
> > +	return block;
> > +
> > +err:
> > +	kfree(block);
> > +	return NULL;
> > +}
> > +
> > +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
> > +{
> > +	struct i2c_client *client;
> > +	int num_modes = 0;
> > +
> > +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
> > +
> > +	kfree(ge_b850v3_lvds_ptr->edid);
> > +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
> > +
> > +	if (ge_b850v3_lvds_ptr->edid) {
> > +		drm_mode_connector_update_edid_property(connector,
> > +						      ge_b850v3_lvds_ptr->edid);
> > +		num_modes = drm_add_edid_modes(connector,
> > +					       ge_b850v3_lvds_ptr->edid);
> > +	}
> > +
> > +	return num_modes;
> > +}
> > +
> > +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
> > +		struct drm_connector *connector, struct drm_display_mode *mode)
> > +{
> > +	return MODE_OK;
> > +}
> > +
> > +static const struct
> > +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
> > +	.get_modes = ge_b850v3_lvds_get_modes,
> > +	.mode_valid = ge_b850v3_lvds_mode_valid,
> > +};
> > +
> > +static enum drm_connector_status ge_b850v3_lvds_detect(
> > +		struct drm_connector *connector, bool force)
> > +{
> > +	struct i2c_client *stdp4028_i2c =
> > +			ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +	s32 link_state;
> > +
> > +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
> > +					      STDP4028_DPTX_STS_REG);
> > +
> > +	if (link_state == STDP4028_CON_STATE_CONNECTED)
> > +		return connector_status_connected;
> > +
> > +	if (link_state == 0)
> > +		return connector_status_disconnected;
> > +
> > +	return connector_status_unknown;
> > +}
> > +
> > +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
> > +	.dpms = drm_atomic_helper_connector_dpms,
> > +	.fill_modes = drm_helper_probe_single_connector_modes,
> > +	.detect = ge_b850v3_lvds_detect,
> > +	.destroy = drm_connector_cleanup,
> > +	.reset = drm_atomic_helper_connector_reset,
> > +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> > +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> > +};
> > +
> > +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
> > +{
> > +	struct i2c_client *stdp4028_i2c
> > +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_STS_REG,
> > +				  STDP4028_DPTX_IRQ_CLEAR);
> > +
> > +	if (ge_b850v3_lvds_ptr->connector.dev)
> > +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> > +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
> > +{
> > +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
> > +	struct i2c_client *stdp4028_i2c
> > +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +	int ret;
> > +
> > +	if (!bridge->encoder) {
> > +		DRM_ERROR("Parent encoder object not found");
> > +		return -ENODEV;
> > +	}
> > +
> > +	connector->polled = DRM_CONNECTOR_POLL_HPD;
> > +
> > +	drm_connector_helper_add(connector,
> > +				 &ge_b850v3_lvds_connector_helper_funcs);
> > +
> > +	ret = drm_connector_init(bridge->dev, connector,
> > +				 &ge_b850v3_lvds_connector_funcs,
> > +				 DRM_MODE_CONNECTOR_DisplayPort);
> > +	if (ret) {
> > +		DRM_ERROR("Failed to initialize connector with drm\n");
> > +		return ret;
> > +	}
> > +
> > +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* Configures the bridge to re-enable interrupts after each ack. */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_IRQ_OUT_CONF_REG,
> > +				  STDP4028_DPTX_DP_IRQ_EN);
> > +
> > +	/* Enable interrupts */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_EN_REG,
> > +				  STDP4028_DPTX_IRQ_CONFIG);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
> > +	.attach = ge_b850v3_lvds_attach,
> > +};
> > +
> > +static int ge_b850v3_lvds_init(struct device *dev)
> > +{
> > +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> > +
> > +	if (ge_b850v3_lvds_ptr)
> > +		goto success;
> > +
> > +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
> > +					  sizeof(*ge_b850v3_lvds_ptr),
> > +					  GFP_KERNEL);
> > +
> > +	if (!ge_b850v3_lvds_ptr) {
> > +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
> > +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
> > +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
> > +
> > +success:
> > +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +	return 0;
> > +}
> > +
> > +static void ge_b850v3_lvds_remove(void)
> > +{
> > +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> > +	/*
> > +	 * This check is to avoid both the drivers
> > +	 * removing the bridge in their remove() function
> > +	 */
> > +	if (!ge_b850v3_lvds_ptr)
> > +		goto out;
> > +
> > +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> > +
> > +	kfree(ge_b850v3_lvds_ptr->edid);
> > +
> > +	ge_b850v3_lvds_ptr = NULL;
> > +out:
> > +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +}
> > +
> > +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
> > +				       const struct i2c_device_id *id)
> > +{
> > +	struct device *dev = &stdp4028_i2c->dev;
> > +
> > +	ge_b850v3_lvds_init(dev);
> > +
> > +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
> > +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
> > +
> > +	/* Clear pending interrupts since power up. */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_STS_REG,
> > +				  STDP4028_DPTX_IRQ_CLEAR);
> > +
> > +	if (!stdp4028_i2c->irq)
> > +		return 0;
> > +
> > +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
> > +			stdp4028_i2c->irq, NULL,
> > +			ge_b850v3_lvds_irq_handler,
> > +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> > +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
> > +}
> > +
> > +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
> > +{
> > +	ge_b850v3_lvds_remove();
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp4028_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp4028_ge_b850v3_fw_probe,
> > +	.remove		= stdp4028_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp4028-ge-b850v3-fw",
> > +		.of_match_table = stdp4028_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
> > +
> > +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
> > +				       const struct i2c_device_id *id)
> > +{
> > +	struct device *dev = &stdp2690_i2c->dev;
> > +
> > +	ge_b850v3_lvds_init(dev);
> > +
> > +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
> > +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
> > +
> > +	return 0;
> > +}
> > +
> > +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
> > +{
> > +	ge_b850v3_lvds_remove();
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp2690_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp2690_ge_b850v3_fw_probe,
> > +	.remove		= stdp2690_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp2690-ge-b850v3-fw",
> > +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
> 
> Didn't catch this in the last series, but there can only be one
> module_init call per module. This breaks compilation when the
> driver is built as a module.

Unfortunately yes. Got loads of errors when trying to compile as a
module.

> 
> You could do something like:
> 
> static int __init stdpxxxx_ge_b850v3_init(void)
> {
> 	int ret;
> 
> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
> 	if (ret)
> 		return ret;
> 
> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> }
> module_init(stdpxxxx_ge_b850v3_init);
> 
> static void __exit stdpxxxx_ge_b850v3_exit(void)
> {
> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> }
> module_exit(stdpxxxx_ge_b850v3_exit);

Thank you! I was wondering if merging ge_b850v3_lvds_init() with
stdpxxxx_ge_b850v3_init() and ge_b850v3_lvds_remove() with
stdpxxxx_ge_b850v3_exit() make sense as it can probably eliminate the
need for the mutex.

> 
> Thanks,
> Archit
> 
> > +
> > +MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
> > +MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
> > +MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
> > +MODULE_LICENSE("GPL v2");
> > 
> 
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-01 10:38       ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-03-01 10:38 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Archit,

Thank you for the review!

On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
> 
> 
> On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
> > The video processing pipeline on the second output on the GE B850v3:
> > 
> >   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> > 
> > Each bridge has a dedicated flash containing firmware for supporting the
> > custom design. The result is that in this design neither the STDP4028
> > nor the STDP2690 behave as the stock bridges would. The compatible
> > strings include the suffix "-ge-b850v3-fw" to make it clear that the
> > driver is for the bridges with the firmware which is specific for the GE
> > B850v3.
> > 
> > The driver is powerless to control the video processing pipeline, as the
> > two bridges behaves as a single one. The driver is only needed for
> > telling the host about EDID / HPD, and for giving the host powers to ack
> > interrupts.
> > 
> > This driver adds one i2c_device for each bridge, but only one
> > drm_bridge. This design allows the creation of a functional connector
> > that is capable of reading EDID from the STDP2690 while handling
> > interrupts on the STDP4028.
> > 
> > Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> > Cc: Martin Donnelly <martin.donnelly@ge.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> > Cc: Philipp Zabel <p.zabel@pengutronix.de>
> > Cc: Rob Herring <robh@kernel.org>
> > Cc: Fabio Estevam <fabio.estevam@nxp.com>
> > Cc: David Airlie <airlied@linux.ie>
> > Cc: Thierry Reding <treding@nvidia.com>
> > Cc: Thierry Reding <thierry.reding@gmail.com>
> > Cc: Archit Taneja <architt@codeaurora.org>
> > Cc: Enric Balletbo <enric.balletbo@collabora.com>
> > Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> > ---
> > Changes from V1:
> >  - Updated copyright year
> >  - Fixed blank line issues
> >  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
> >    added a comment to explain the test.
> >  - Fixed checkpatch strict warnings about continuation lines. In one case
> >    fixing the warning would cause the continuation line to be over 80 chars and
> >    that strict warning remains.
> > 
> >  drivers/gpu/drm/bridge/Kconfig                     |  11 +
> >  drivers/gpu/drm/bridge/Makefile                    |   1 +
> >  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
> >  3 files changed, 423 insertions(+)
> >  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > 
> > diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
> > index eb8688e..4a937f1 100644
> > --- a/drivers/gpu/drm/bridge/Kconfig
> > +++ b/drivers/gpu/drm/bridge/Kconfig
> > @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
> >  	  Support the I2S Audio interface which is part of the Synopsis
> >  	  Designware HDMI block.
> > 
> > +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
> > +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
> > +	depends on OF
> > +	select DRM_KMS_HELPER
> > +	select DRM_PANEL
> > +	---help---
> > +          This is a driver for the display bridges of
> > +          GE B850v3 that convert dual channel LVDS
> > +          to DP++. This is used with the i.MX6 imx-ldb
> > +          driver. You are likely to say N here.
> > +
> >  config DRM_NXP_PTN3460
> >  	tristate "NXP PTN3460 DP/LVDS bridge"
> >  	depends on OF
> > diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
> > index 2e83a785..af0b7cc 100644
> > --- a/drivers/gpu/drm/bridge/Makefile
> > +++ b/drivers/gpu/drm/bridge/Makefile
> > @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
> >  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
> >  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
> >  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
> > +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
> >  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
> >  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
> >  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
> > diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > new file mode 100644
> > index 0000000..6f82a44
> > --- /dev/null
> > +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > @@ -0,0 +1,411 @@
> > +/*
> > + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
> > + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
> > +
> > + * Copyright (c) 2017, Collabora Ltd.
> > + * Copyright (c) 2017, General Electric Company
> > +
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms and conditions of the GNU General Public License,
> > + * version 2, as published by the Free Software Foundation.
> > +
> > + * This program is distributed in the hope it will be useful, but WITHOUT
> > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > + * more details.
> > +
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > +
> > + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
> > + * display bridge of the GE B850v3. There are two physical bridges on the video
> > + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
> > + * physical bridges are automatically configured by the input video signal, and
> > + * the driver has no access to the video processing pipeline. The driver is
> > + * only needed to read EDID from the STDP2690 and to handle HPD events from the
> > + * STDP4028. The driver communicates with both bridges over i2c. The video
> > + * signal pipeline is as follows:
> > + *
> > + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
> > + *
> > + */
> > +
> > +#include <linux/gpio.h>
> > +#include <linux/i2c.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <drm/drm_atomic.h>
> > +#include <drm/drm_atomic_helper.h>
> > +#include <drm/drm_crtc_helper.h>
> > +#include <drm/drm_edid.h>
> > +#include <drm/drmP.h>
> > +
> > +#define EDID_EXT_BLOCK_CNT 0x7E
> > +
> > +#define STDP4028_IRQ_OUT_CONF_REG 0x02
> > +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
> > +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
> > +#define STDP4028_DPTX_STS_REG 0x3E
> > +
> > +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
> > +
> > +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
> > +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
> > +#define STDP4028_DPTX_IRQ_CONFIG \
> > +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
> > +
> > +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
> > +#define STDP4028_DPTX_LINK_STS 0x1000
> > +#define STDP4028_CON_STATE_CONNECTED \
> > +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
> > +
> > +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
> > +#define STDP4028_DPTX_LINK_CH_STS 0x2000
> > +#define STDP4028_DPTX_IRQ_CLEAR \
> > +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
> > +
> > +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
> > +
> > +struct ge_b850v3_lvds {
> > +	struct drm_connector connector;
> > +	struct drm_bridge bridge;
> > +	struct i2c_client *stdp4028_i2c;
> > +	struct i2c_client *stdp2690_i2c;
> > +	struct edid *edid;
> > +};
> > +
> > +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
> > +
> > +u8 *stdp2690_get_edid(struct i2c_client *client)
> > +{
> > +	struct i2c_adapter *adapter = client->adapter;
> > +	unsigned char start = 0x00;
> > +	unsigned int total_size;
> > +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> > +
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr	= client->addr,
> > +			.flags	= 0,
> > +			.len	= 1,
> > +			.buf	= &start,
> > +		}, {
> > +			.addr	= client->addr,
> > +			.flags	= I2C_M_RD,
> > +			.len	= EDID_LENGTH,
> > +			.buf	= block,
> > +		}
> > +	};
> > +
> > +	if (!block)
> > +		return NULL;
> > +
> > +	if (i2c_transfer(adapter, msgs, 2) != 2) {
> > +		DRM_ERROR("Unable to read EDID.\n");
> > +		goto err;
> > +	}
> > +
> > +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
> > +		DRM_ERROR("Invalid EDID data\n");
> > +		goto err;
> > +	}
> > +
> > +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> > +	if (total_size > EDID_LENGTH) {
> > +		kfree(block);
> > +		block = kmalloc(total_size, GFP_KERNEL);
> > +		if (!block)
> > +			return NULL;
> > +
> > +		/* Yes, read the entire buffer, and do not skip the first
> > +		 * EDID_LENGTH bytes.
> > +		 */
> > +		start = 0x00;
> > +		msgs[1].len = total_size;
> > +		msgs[1].buf = block;
> > +
> > +		if (i2c_transfer(adapter, msgs, 2) != 2) {
> > +			DRM_ERROR("Unable to read EDID extension blocks.\n");
> > +			goto err;
> > +		}
> > +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
> > +			DRM_ERROR("Invalid EDID data\n");
> > +			goto err;
> > +		}
> > +	}
> > +
> > +	return block;
> > +
> > +err:
> > +	kfree(block);
> > +	return NULL;
> > +}
> > +
> > +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
> > +{
> > +	struct i2c_client *client;
> > +	int num_modes = 0;
> > +
> > +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
> > +
> > +	kfree(ge_b850v3_lvds_ptr->edid);
> > +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
> > +
> > +	if (ge_b850v3_lvds_ptr->edid) {
> > +		drm_mode_connector_update_edid_property(connector,
> > +						      ge_b850v3_lvds_ptr->edid);
> > +		num_modes = drm_add_edid_modes(connector,
> > +					       ge_b850v3_lvds_ptr->edid);
> > +	}
> > +
> > +	return num_modes;
> > +}
> > +
> > +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
> > +		struct drm_connector *connector, struct drm_display_mode *mode)
> > +{
> > +	return MODE_OK;
> > +}
> > +
> > +static const struct
> > +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
> > +	.get_modes = ge_b850v3_lvds_get_modes,
> > +	.mode_valid = ge_b850v3_lvds_mode_valid,
> > +};
> > +
> > +static enum drm_connector_status ge_b850v3_lvds_detect(
> > +		struct drm_connector *connector, bool force)
> > +{
> > +	struct i2c_client *stdp4028_i2c =
> > +			ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +	s32 link_state;
> > +
> > +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
> > +					      STDP4028_DPTX_STS_REG);
> > +
> > +	if (link_state == STDP4028_CON_STATE_CONNECTED)
> > +		return connector_status_connected;
> > +
> > +	if (link_state == 0)
> > +		return connector_status_disconnected;
> > +
> > +	return connector_status_unknown;
> > +}
> > +
> > +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
> > +	.dpms = drm_atomic_helper_connector_dpms,
> > +	.fill_modes = drm_helper_probe_single_connector_modes,
> > +	.detect = ge_b850v3_lvds_detect,
> > +	.destroy = drm_connector_cleanup,
> > +	.reset = drm_atomic_helper_connector_reset,
> > +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> > +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> > +};
> > +
> > +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
> > +{
> > +	struct i2c_client *stdp4028_i2c
> > +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_STS_REG,
> > +				  STDP4028_DPTX_IRQ_CLEAR);
> > +
> > +	if (ge_b850v3_lvds_ptr->connector.dev)
> > +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> > +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
> > +{
> > +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
> > +	struct i2c_client *stdp4028_i2c
> > +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
> > +	int ret;
> > +
> > +	if (!bridge->encoder) {
> > +		DRM_ERROR("Parent encoder object not found");
> > +		return -ENODEV;
> > +	}
> > +
> > +	connector->polled = DRM_CONNECTOR_POLL_HPD;
> > +
> > +	drm_connector_helper_add(connector,
> > +				 &ge_b850v3_lvds_connector_helper_funcs);
> > +
> > +	ret = drm_connector_init(bridge->dev, connector,
> > +				 &ge_b850v3_lvds_connector_funcs,
> > +				 DRM_MODE_CONNECTOR_DisplayPort);
> > +	if (ret) {
> > +		DRM_ERROR("Failed to initialize connector with drm\n");
> > +		return ret;
> > +	}
> > +
> > +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* Configures the bridge to re-enable interrupts after each ack. */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_IRQ_OUT_CONF_REG,
> > +				  STDP4028_DPTX_DP_IRQ_EN);
> > +
> > +	/* Enable interrupts */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_EN_REG,
> > +				  STDP4028_DPTX_IRQ_CONFIG);
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
> > +	.attach = ge_b850v3_lvds_attach,
> > +};
> > +
> > +static int ge_b850v3_lvds_init(struct device *dev)
> > +{
> > +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> > +
> > +	if (ge_b850v3_lvds_ptr)
> > +		goto success;
> > +
> > +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
> > +					  sizeof(*ge_b850v3_lvds_ptr),
> > +					  GFP_KERNEL);
> > +
> > +	if (!ge_b850v3_lvds_ptr) {
> > +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
> > +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
> > +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
> > +
> > +success:
> > +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +	return 0;
> > +}
> > +
> > +static void ge_b850v3_lvds_remove(void)
> > +{
> > +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
> > +	/*
> > +	 * This check is to avoid both the drivers
> > +	 * removing the bridge in their remove() function
> > +	 */
> > +	if (!ge_b850v3_lvds_ptr)
> > +		goto out;
> > +
> > +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> > +
> > +	kfree(ge_b850v3_lvds_ptr->edid);
> > +
> > +	ge_b850v3_lvds_ptr = NULL;
> > +out:
> > +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
> > +}
> > +
> > +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
> > +				       const struct i2c_device_id *id)
> > +{
> > +	struct device *dev = &stdp4028_i2c->dev;
> > +
> > +	ge_b850v3_lvds_init(dev);
> > +
> > +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
> > +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
> > +
> > +	/* Clear pending interrupts since power up. */
> > +	i2c_smbus_write_word_data(stdp4028_i2c,
> > +				  STDP4028_DPTX_IRQ_STS_REG,
> > +				  STDP4028_DPTX_IRQ_CLEAR);
> > +
> > +	if (!stdp4028_i2c->irq)
> > +		return 0;
> > +
> > +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
> > +			stdp4028_i2c->irq, NULL,
> > +			ge_b850v3_lvds_irq_handler,
> > +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> > +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
> > +}
> > +
> > +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
> > +{
> > +	ge_b850v3_lvds_remove();
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp4028_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp4028_ge_b850v3_fw_probe,
> > +	.remove		= stdp4028_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp4028-ge-b850v3-fw",
> > +		.of_match_table = stdp4028_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
> > +
> > +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
> > +				       const struct i2c_device_id *id)
> > +{
> > +	struct device *dev = &stdp2690_i2c->dev;
> > +
> > +	ge_b850v3_lvds_init(dev);
> > +
> > +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
> > +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
> > +
> > +	return 0;
> > +}
> > +
> > +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
> > +{
> > +	ge_b850v3_lvds_remove();
> > +
> > +	return 0;
> > +}
> > +
> > +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp2690_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp2690_ge_b850v3_fw_probe,
> > +	.remove		= stdp2690_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp2690-ge-b850v3-fw",
> > +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
> 
> Didn't catch this in the last series, but there can only be one
> module_init call per module. This breaks compilation when the
> driver is built as a module.

Unfortunately yes. Got loads of errors when trying to compile as a
module.

> 
> You could do something like:
> 
> static int __init stdpxxxx_ge_b850v3_init(void)
> {
> 	int ret;
> 
> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
> 	if (ret)
> 		return ret;
> 
> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> }
> module_init(stdpxxxx_ge_b850v3_init);
> 
> static void __exit stdpxxxx_ge_b850v3_exit(void)
> {
> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> }
> module_exit(stdpxxxx_ge_b850v3_exit);

Thank you! I was wondering if merging ge_b850v3_lvds_init() with
stdpxxxx_ge_b850v3_init() and ge_b850v3_lvds_remove() with
stdpxxxx_ge_b850v3_exit() make sense as it can probably eliminate the
need for the mutex.

> 
> Thanks,
> Archit
> 
> > +
> > +MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
> > +MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
> > +MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
> > +MODULE_LICENSE("GPL v2");
> > 
> 
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  2017-03-01  4:08     ` Archit Taneja
  (?)
@ 2017-03-01 16:16       ` Peter Senna Tschudin
  -1 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-03-01 16:16 UTC (permalink / raw)
  To: Archit Taneja
  Cc: airlied, akpm, daniel.vetter, davem, devicetree, dri-devel,
	enric.balletbo, eballetbo, galak, gregkh, heiko, ijc+devicetree,
	javier, jslaby, kernel, linux-arm-kernel, linux, linux-kernel,
	linux, mark.rutland, martin.donnelly, martyn.welch, mchehab,
	pawel.moll, peter.senna, p.zabel, thierry.reding, rmk+kernel,
	robh+dt, shawnguo, tiwai, treding, ykk, laurent.pinchart,
	Rob Herring, Fabio Estevam

On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
[...]
> > +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp2690_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp2690_ge_b850v3_fw_probe,
> > +	.remove		= stdp2690_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp2690-ge-b850v3-fw",
> > +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
> 
> Didn't catch this in the last series, but there can only be one
> module_init call per module. This breaks compilation when the
> driver is built as a module.
> 
> You could do something like:
> 
> static int __init stdpxxxx_ge_b850v3_init(void)
> {
> 	int ret;
> 
> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
> 	if (ret)
> 		return ret;
> 
> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> }
> module_init(stdpxxxx_ge_b850v3_init);
> 
> static void __exit stdpxxxx_ge_b850v3_exit(void)
> {
> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> }
> module_exit(stdpxxxx_ge_b850v3_exit);
> 
> Thanks,
> Archit

This has the init and exit functions merged and no need for the mutex
anymore. Compiled and run as a module and works fine. What do you think?

commit 15f8bf1b50d69454adeb32b5ff86c953124279fd
Author: Peter Senna Tschudin <peter.senna@collabora.com>
Date:   Wed May 25 00:59:17 2016 +0200

    drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
    
    The video processing pipeline on the second output on the GE B850v3:
    
      Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
    
    Each bridge has a dedicated flash containing firmware for supporting the
    custom design. The result is that in this design neither the STDP4028
    nor the STDP2690 behave as the stock bridges would. The compatible
    strings include the suffix "-ge-b850v3-fw" to make it clear that the
    driver is for the bridges with the firmware which is specific for the GE
    B850v3.
    
    The driver is powerless to control the video processing pipeline, as the
    two bridges behaves as a single one. The driver is only needed for
    telling the host about EDID / HPD, and for giving the host powers to ack
    interrupts.
    
    This driver adds one i2c_device for each bridge, but only one
    drm_bridge. This design allows the creation of a functional connector
    that is capable of reading EDID from the STDP2690 while handling
    interrupts on the STDP4028.
    
    Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Cc: Martyn Welch <martyn.welch@collabora.co.uk>
    Cc: Martin Donnelly <martin.donnelly@ge.com>
    Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
    Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
    Cc: Philipp Zabel <p.zabel@pengutronix.de>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Fabio Estevam <fabio.estevam@nxp.com>
    Cc: David Airlie <airlied@linux.ie>
    Cc: Thierry Reding <treding@nvidia.com>
    Cc: Thierry Reding <thierry.reding@gmail.com>
    Cc: Archit Taneja <architt@codeaurora.org>
    Cc: Enric Balletbo <enric.balletbo@collabora.com>
    Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index eb8688e..4a937f1 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
 	  Support the I2S Audio interface which is part of the Synopsis
 	  Designware HDMI block.
 
+config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
+	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_PANEL
+	---help---
+          This is a driver for the display bridges of
+          GE B850v3 that convert dual channel LVDS
+          to DP++. This is used with the i.MX6 imx-ldb
+          driver. You are likely to say N here.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2e83a785..af0b7cc 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
new file mode 100644
index 0000000..c1d93aa
--- /dev/null
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -0,0 +1,396 @@
+/*
+ * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
+ * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
+
+ * Copyright (c) 2017, Collabora Ltd.
+ * Copyright (c) 2017, General Electric Company
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
+ * display bridge of the GE B850v3. There are two physical bridges on the video
+ * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
+ * physical bridges are automatically configured by the input video signal, and
+ * the driver has no access to the video processing pipeline. The driver is
+ * only needed to read EDID from the STDP2690 and to handle HPD events from the
+ * STDP4028. The driver communicates with both bridges over i2c. The video
+ * signal pipeline is as follows:
+ *
+ *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drmP.h>
+
+#define EDID_EXT_BLOCK_CNT 0x7E
+
+#define STDP4028_IRQ_OUT_CONF_REG 0x02
+#define STDP4028_DPTX_IRQ_EN_REG 0x3C
+#define STDP4028_DPTX_IRQ_STS_REG 0x3D
+#define STDP4028_DPTX_STS_REG 0x3E
+
+#define STDP4028_DPTX_DP_IRQ_EN 0x1000
+
+#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
+#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
+#define STDP4028_DPTX_IRQ_CONFIG \
+		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
+
+#define STDP4028_DPTX_HOTPLUG_STS 0x0200
+#define STDP4028_DPTX_LINK_STS 0x1000
+#define STDP4028_CON_STATE_CONNECTED \
+		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
+
+#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
+#define STDP4028_DPTX_LINK_CH_STS 0x2000
+#define STDP4028_DPTX_IRQ_CLEAR \
+		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
+
+struct ge_b850v3_lvds {
+	struct drm_connector connector;
+	struct drm_bridge bridge;
+	struct i2c_client *stdp4028_i2c;
+	struct i2c_client *stdp2690_i2c;
+	struct edid *edid;
+};
+
+static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
+
+u8 *stdp2690_get_edid(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	unsigned char start = 0x00;
+	unsigned int total_size;
+	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= client->addr,
+			.flags	= 0,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= client->addr,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+			.buf	= block,
+		}
+	};
+
+	if (!block)
+		return NULL;
+
+	if (i2c_transfer(adapter, msgs, 2) != 2) {
+		DRM_ERROR("Unable to read EDID.\n");
+		goto err;
+	}
+
+	if (!drm_edid_block_valid(block, 0, false, NULL)) {
+		DRM_ERROR("Invalid EDID data\n");
+		goto err;
+	}
+
+	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
+	if (total_size > EDID_LENGTH) {
+		kfree(block);
+		block = kmalloc(total_size, GFP_KERNEL);
+		if (!block)
+			return NULL;
+
+		/* Yes, read the entire buffer, and do not skip the first
+		 * EDID_LENGTH bytes.
+		 */
+		start = 0x00;
+		msgs[1].len = total_size;
+		msgs[1].buf = block;
+
+		if (i2c_transfer(adapter, msgs, 2) != 2) {
+			DRM_ERROR("Unable to read EDID extension blocks.\n");
+			goto err;
+		}
+		if (!drm_edid_block_valid(block, 1, false, NULL)) {
+			DRM_ERROR("Invalid EDID data\n");
+			goto err;
+		}
+	}
+
+	return block;
+
+err:
+	kfree(block);
+	return NULL;
+}
+
+static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
+{
+	struct i2c_client *client;
+	int num_modes = 0;
+
+	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
+
+	if (ge_b850v3_lvds_ptr->edid) {
+		drm_mode_connector_update_edid_property(connector,
+						      ge_b850v3_lvds_ptr->edid);
+		num_modes = drm_add_edid_modes(connector,
+					       ge_b850v3_lvds_ptr->edid);
+	}
+
+	return num_modes;
+}
+
+static enum drm_mode_status ge_b850v3_lvds_mode_valid(
+		struct drm_connector *connector, struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static const struct
+drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
+	.get_modes = ge_b850v3_lvds_get_modes,
+	.mode_valid = ge_b850v3_lvds_mode_valid,
+};
+
+static enum drm_connector_status ge_b850v3_lvds_detect(
+		struct drm_connector *connector, bool force)
+{
+	struct i2c_client *stdp4028_i2c =
+			ge_b850v3_lvds_ptr->stdp4028_i2c;
+	s32 link_state;
+
+	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
+					      STDP4028_DPTX_STS_REG);
+
+	if (link_state == STDP4028_CON_STATE_CONNECTED)
+		return connector_status_connected;
+
+	if (link_state == 0)
+		return connector_status_disconnected;
+
+	return connector_status_unknown;
+}
+
+static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = ge_b850v3_lvds_detect,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
+{
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (ge_b850v3_lvds_ptr->connector.dev)
+		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
+
+	return IRQ_HANDLED;
+}
+
+static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
+{
+	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+	int ret;
+
+	if (!bridge->encoder) {
+		DRM_ERROR("Parent encoder object not found");
+		return -ENODEV;
+	}
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(connector,
+				 &ge_b850v3_lvds_connector_helper_funcs);
+
+	ret = drm_connector_init(bridge->dev, connector,
+				 &ge_b850v3_lvds_connector_funcs,
+				 DRM_MODE_CONNECTOR_DisplayPort);
+	if (ret) {
+		DRM_ERROR("Failed to initialize connector with drm\n");
+		return ret;
+	}
+
+	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
+	if (ret)
+		return ret;
+
+	/* Configures the bridge to re-enable interrupts after each ack. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_IRQ_OUT_CONF_REG,
+				  STDP4028_DPTX_DP_IRQ_EN);
+
+	/* Enable interrupts */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_EN_REG,
+				  STDP4028_DPTX_IRQ_CONFIG);
+
+	return 0;
+}
+
+static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
+	.attach = ge_b850v3_lvds_attach,
+};
+
+static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp4028_i2c->dev;
+
+	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
+
+	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
+	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
+
+	/* Clear pending interrupts since power up. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (!stdp4028_i2c->irq)
+		return 0;
+
+	return devm_request_threaded_irq(&stdp4028_i2c->dev,
+			stdp4028_i2c->irq, NULL,
+			ge_b850v3_lvds_irq_handler,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
+}
+
+static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
+{
+	return 0;
+}
+
+static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
+	{"stdp4028_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
+	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
+	.probe		= stdp4028_ge_b850v3_fw_probe,
+	.remove		= stdp4028_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp4028-ge-b850v3-fw",
+		.of_match_table = stdp4028_ge_b850v3_fw_match,
+	},
+};
+
+static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
+				       const struct i2c_device_id *id)
+{
+	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
+	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
+
+	return 0;
+}
+
+static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
+{
+	return 0;
+}
+
+static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
+	{"stdp2690_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
+	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
+	.probe		= stdp2690_ge_b850v3_fw_probe,
+	.remove		= stdp2690_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp2690-ge-b850v3-fw",
+		.of_match_table = stdp2690_ge_b850v3_fw_match,
+	},
+};
+
+static int __init stdpxxxx_ge_b850v3_init(void)
+{
+	int ret;
+
+	ge_b850v3_lvds_ptr = kzalloc(sizeof(*ge_b850v3_lvds_ptr), GFP_KERNEL);
+
+	if (!ge_b850v3_lvds_ptr)
+		return -ENOMEM;
+
+	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
+	if (ret) {
+		kfree(ge_b850v3_lvds_ptr);
+		return ret;
+	}
+
+	ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
+	if (ret) {
+	        i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
+		kfree(ge_b850v3_lvds_ptr);
+		return ret;
+	}
+
+	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
+	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
+
+	return 0;
+}
+module_init(stdpxxxx_ge_b850v3_init);
+
+static void __exit stdpxxxx_ge_b850v3_exit(void)
+{
+	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
+	kfree(ge_b850v3_lvds_ptr->edid);
+
+	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
+	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
+
+	kfree(ge_b850v3_lvds_ptr);
+}
+module_exit(stdpxxxx_ge_b850v3_exit);
+
+MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
+MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
+MODULE_LICENSE("GPL v2");

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-01 16:16       ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-03-01 16:16 UTC (permalink / raw)
  To: Archit Taneja
  Cc: mark.rutland, heiko, airlied, daniel.vetter, peter.senna,
	dri-devel, tiwai, thierry.reding, laurent.pinchart, ykk, jslaby,
	martyn.welch, Rob Herring, mchehab, linux, javier, treding,
	linux, martin.donnelly, devicetree, p.zabel, pawel.moll,
	ijc+devicetree, eballetbo, Fabio Estevam, rmk+kernel, robh+dt,
	linux-arm-kernel, gregkh, linux-kernel, kernel, galak,
	enric.balletbo, akpm, shawnguo, davem

On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
[...]
> > +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp2690_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp2690_ge_b850v3_fw_probe,
> > +	.remove		= stdp2690_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp2690-ge-b850v3-fw",
> > +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
> 
> Didn't catch this in the last series, but there can only be one
> module_init call per module. This breaks compilation when the
> driver is built as a module.
> 
> You could do something like:
> 
> static int __init stdpxxxx_ge_b850v3_init(void)
> {
> 	int ret;
> 
> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
> 	if (ret)
> 		return ret;
> 
> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> }
> module_init(stdpxxxx_ge_b850v3_init);
> 
> static void __exit stdpxxxx_ge_b850v3_exit(void)
> {
> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> }
> module_exit(stdpxxxx_ge_b850v3_exit);
> 
> Thanks,
> Archit

This has the init and exit functions merged and no need for the mutex
anymore. Compiled and run as a module and works fine. What do you think?

commit 15f8bf1b50d69454adeb32b5ff86c953124279fd
Author: Peter Senna Tschudin <peter.senna@collabora.com>
Date:   Wed May 25 00:59:17 2016 +0200

    drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
    
    The video processing pipeline on the second output on the GE B850v3:
    
      Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
    
    Each bridge has a dedicated flash containing firmware for supporting the
    custom design. The result is that in this design neither the STDP4028
    nor the STDP2690 behave as the stock bridges would. The compatible
    strings include the suffix "-ge-b850v3-fw" to make it clear that the
    driver is for the bridges with the firmware which is specific for the GE
    B850v3.
    
    The driver is powerless to control the video processing pipeline, as the
    two bridges behaves as a single one. The driver is only needed for
    telling the host about EDID / HPD, and for giving the host powers to ack
    interrupts.
    
    This driver adds one i2c_device for each bridge, but only one
    drm_bridge. This design allows the creation of a functional connector
    that is capable of reading EDID from the STDP2690 while handling
    interrupts on the STDP4028.
    
    Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Cc: Martyn Welch <martyn.welch@collabora.co.uk>
    Cc: Martin Donnelly <martin.donnelly@ge.com>
    Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
    Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
    Cc: Philipp Zabel <p.zabel@pengutronix.de>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Fabio Estevam <fabio.estevam@nxp.com>
    Cc: David Airlie <airlied@linux.ie>
    Cc: Thierry Reding <treding@nvidia.com>
    Cc: Thierry Reding <thierry.reding@gmail.com>
    Cc: Archit Taneja <architt@codeaurora.org>
    Cc: Enric Balletbo <enric.balletbo@collabora.com>
    Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index eb8688e..4a937f1 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
 	  Support the I2S Audio interface which is part of the Synopsis
 	  Designware HDMI block.
 
+config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
+	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_PANEL
+	---help---
+          This is a driver for the display bridges of
+          GE B850v3 that convert dual channel LVDS
+          to DP++. This is used with the i.MX6 imx-ldb
+          driver. You are likely to say N here.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2e83a785..af0b7cc 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
new file mode 100644
index 0000000..c1d93aa
--- /dev/null
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -0,0 +1,396 @@
+/*
+ * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
+ * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
+
+ * Copyright (c) 2017, Collabora Ltd.
+ * Copyright (c) 2017, General Electric Company
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
+ * display bridge of the GE B850v3. There are two physical bridges on the video
+ * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
+ * physical bridges are automatically configured by the input video signal, and
+ * the driver has no access to the video processing pipeline. The driver is
+ * only needed to read EDID from the STDP2690 and to handle HPD events from the
+ * STDP4028. The driver communicates with both bridges over i2c. The video
+ * signal pipeline is as follows:
+ *
+ *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drmP.h>
+
+#define EDID_EXT_BLOCK_CNT 0x7E
+
+#define STDP4028_IRQ_OUT_CONF_REG 0x02
+#define STDP4028_DPTX_IRQ_EN_REG 0x3C
+#define STDP4028_DPTX_IRQ_STS_REG 0x3D
+#define STDP4028_DPTX_STS_REG 0x3E
+
+#define STDP4028_DPTX_DP_IRQ_EN 0x1000
+
+#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
+#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
+#define STDP4028_DPTX_IRQ_CONFIG \
+		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
+
+#define STDP4028_DPTX_HOTPLUG_STS 0x0200
+#define STDP4028_DPTX_LINK_STS 0x1000
+#define STDP4028_CON_STATE_CONNECTED \
+		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
+
+#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
+#define STDP4028_DPTX_LINK_CH_STS 0x2000
+#define STDP4028_DPTX_IRQ_CLEAR \
+		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
+
+struct ge_b850v3_lvds {
+	struct drm_connector connector;
+	struct drm_bridge bridge;
+	struct i2c_client *stdp4028_i2c;
+	struct i2c_client *stdp2690_i2c;
+	struct edid *edid;
+};
+
+static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
+
+u8 *stdp2690_get_edid(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	unsigned char start = 0x00;
+	unsigned int total_size;
+	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= client->addr,
+			.flags	= 0,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= client->addr,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+			.buf	= block,
+		}
+	};
+
+	if (!block)
+		return NULL;
+
+	if (i2c_transfer(adapter, msgs, 2) != 2) {
+		DRM_ERROR("Unable to read EDID.\n");
+		goto err;
+	}
+
+	if (!drm_edid_block_valid(block, 0, false, NULL)) {
+		DRM_ERROR("Invalid EDID data\n");
+		goto err;
+	}
+
+	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
+	if (total_size > EDID_LENGTH) {
+		kfree(block);
+		block = kmalloc(total_size, GFP_KERNEL);
+		if (!block)
+			return NULL;
+
+		/* Yes, read the entire buffer, and do not skip the first
+		 * EDID_LENGTH bytes.
+		 */
+		start = 0x00;
+		msgs[1].len = total_size;
+		msgs[1].buf = block;
+
+		if (i2c_transfer(adapter, msgs, 2) != 2) {
+			DRM_ERROR("Unable to read EDID extension blocks.\n");
+			goto err;
+		}
+		if (!drm_edid_block_valid(block, 1, false, NULL)) {
+			DRM_ERROR("Invalid EDID data\n");
+			goto err;
+		}
+	}
+
+	return block;
+
+err:
+	kfree(block);
+	return NULL;
+}
+
+static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
+{
+	struct i2c_client *client;
+	int num_modes = 0;
+
+	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
+
+	if (ge_b850v3_lvds_ptr->edid) {
+		drm_mode_connector_update_edid_property(connector,
+						      ge_b850v3_lvds_ptr->edid);
+		num_modes = drm_add_edid_modes(connector,
+					       ge_b850v3_lvds_ptr->edid);
+	}
+
+	return num_modes;
+}
+
+static enum drm_mode_status ge_b850v3_lvds_mode_valid(
+		struct drm_connector *connector, struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static const struct
+drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
+	.get_modes = ge_b850v3_lvds_get_modes,
+	.mode_valid = ge_b850v3_lvds_mode_valid,
+};
+
+static enum drm_connector_status ge_b850v3_lvds_detect(
+		struct drm_connector *connector, bool force)
+{
+	struct i2c_client *stdp4028_i2c =
+			ge_b850v3_lvds_ptr->stdp4028_i2c;
+	s32 link_state;
+
+	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
+					      STDP4028_DPTX_STS_REG);
+
+	if (link_state == STDP4028_CON_STATE_CONNECTED)
+		return connector_status_connected;
+
+	if (link_state == 0)
+		return connector_status_disconnected;
+
+	return connector_status_unknown;
+}
+
+static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = ge_b850v3_lvds_detect,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
+{
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (ge_b850v3_lvds_ptr->connector.dev)
+		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
+
+	return IRQ_HANDLED;
+}
+
+static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
+{
+	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+	int ret;
+
+	if (!bridge->encoder) {
+		DRM_ERROR("Parent encoder object not found");
+		return -ENODEV;
+	}
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(connector,
+				 &ge_b850v3_lvds_connector_helper_funcs);
+
+	ret = drm_connector_init(bridge->dev, connector,
+				 &ge_b850v3_lvds_connector_funcs,
+				 DRM_MODE_CONNECTOR_DisplayPort);
+	if (ret) {
+		DRM_ERROR("Failed to initialize connector with drm\n");
+		return ret;
+	}
+
+	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
+	if (ret)
+		return ret;
+
+	/* Configures the bridge to re-enable interrupts after each ack. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_IRQ_OUT_CONF_REG,
+				  STDP4028_DPTX_DP_IRQ_EN);
+
+	/* Enable interrupts */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_EN_REG,
+				  STDP4028_DPTX_IRQ_CONFIG);
+
+	return 0;
+}
+
+static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
+	.attach = ge_b850v3_lvds_attach,
+};
+
+static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp4028_i2c->dev;
+
+	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
+
+	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
+	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
+
+	/* Clear pending interrupts since power up. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (!stdp4028_i2c->irq)
+		return 0;
+
+	return devm_request_threaded_irq(&stdp4028_i2c->dev,
+			stdp4028_i2c->irq, NULL,
+			ge_b850v3_lvds_irq_handler,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
+}
+
+static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
+{
+	return 0;
+}
+
+static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
+	{"stdp4028_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
+	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
+	.probe		= stdp4028_ge_b850v3_fw_probe,
+	.remove		= stdp4028_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp4028-ge-b850v3-fw",
+		.of_match_table = stdp4028_ge_b850v3_fw_match,
+	},
+};
+
+static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
+				       const struct i2c_device_id *id)
+{
+	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
+	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
+
+	return 0;
+}
+
+static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
+{
+	return 0;
+}
+
+static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
+	{"stdp2690_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
+	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
+	.probe		= stdp2690_ge_b850v3_fw_probe,
+	.remove		= stdp2690_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp2690-ge-b850v3-fw",
+		.of_match_table = stdp2690_ge_b850v3_fw_match,
+	},
+};
+
+static int __init stdpxxxx_ge_b850v3_init(void)
+{
+	int ret;
+
+	ge_b850v3_lvds_ptr = kzalloc(sizeof(*ge_b850v3_lvds_ptr), GFP_KERNEL);
+
+	if (!ge_b850v3_lvds_ptr)
+		return -ENOMEM;
+
+	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
+	if (ret) {
+		kfree(ge_b850v3_lvds_ptr);
+		return ret;
+	}
+
+	ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
+	if (ret) {
+	        i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
+		kfree(ge_b850v3_lvds_ptr);
+		return ret;
+	}
+
+	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
+	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
+
+	return 0;
+}
+module_init(stdpxxxx_ge_b850v3_init);
+
+static void __exit stdpxxxx_ge_b850v3_exit(void)
+{
+	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
+	kfree(ge_b850v3_lvds_ptr->edid);
+
+	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
+	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
+
+	kfree(ge_b850v3_lvds_ptr);
+}
+module_exit(stdpxxxx_ge_b850v3_exit);
+
+MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
+MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
+MODULE_LICENSE("GPL v2");

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-01 16:16       ` Peter Senna Tschudin
  0 siblings, 0 replies; 29+ messages in thread
From: Peter Senna Tschudin @ 2017-03-01 16:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
[...]
> > +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
> > +	{"stdp2690_ge_fw", 0},
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
> > +
> > +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
> > +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
> > +
> > +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
> > +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
> > +	.probe		= stdp2690_ge_b850v3_fw_probe,
> > +	.remove		= stdp2690_ge_b850v3_fw_remove,
> > +	.driver		= {
> > +		.name		= "stdp2690-ge-b850v3-fw",
> > +		.of_match_table = stdp2690_ge_b850v3_fw_match,
> > +	},
> > +};
> > +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
> 
> Didn't catch this in the last series, but there can only be one
> module_init call per module. This breaks compilation when the
> driver is built as a module.
> 
> You could do something like:
> 
> static int __init stdpxxxx_ge_b850v3_init(void)
> {
> 	int ret;
> 
> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
> 	if (ret)
> 		return ret;
> 
> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> }
> module_init(stdpxxxx_ge_b850v3_init);
> 
> static void __exit stdpxxxx_ge_b850v3_exit(void)
> {
> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> }
> module_exit(stdpxxxx_ge_b850v3_exit);
> 
> Thanks,
> Archit

This has the init and exit functions merged and no need for the mutex
anymore. Compiled and run as a module and works fine. What do you think?

commit 15f8bf1b50d69454adeb32b5ff86c953124279fd
Author: Peter Senna Tschudin <peter.senna@collabora.com>
Date:   Wed May 25 00:59:17 2016 +0200

    drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
    
    The video processing pipeline on the second output on the GE B850v3:
    
      Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
    
    Each bridge has a dedicated flash containing firmware for supporting the
    custom design. The result is that in this design neither the STDP4028
    nor the STDP2690 behave as the stock bridges would. The compatible
    strings include the suffix "-ge-b850v3-fw" to make it clear that the
    driver is for the bridges with the firmware which is specific for the GE
    B850v3.
    
    The driver is powerless to control the video processing pipeline, as the
    two bridges behaves as a single one. The driver is only needed for
    telling the host about EDID / HPD, and for giving the host powers to ack
    interrupts.
    
    This driver adds one i2c_device for each bridge, but only one
    drm_bridge. This design allows the creation of a functional connector
    that is capable of reading EDID from the STDP2690 while handling
    interrupts on the STDP4028.
    
    Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
    Cc: Martyn Welch <martyn.welch@collabora.co.uk>
    Cc: Martin Donnelly <martin.donnelly@ge.com>
    Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
    Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
    Cc: Philipp Zabel <p.zabel@pengutronix.de>
    Cc: Rob Herring <robh@kernel.org>
    Cc: Fabio Estevam <fabio.estevam@nxp.com>
    Cc: David Airlie <airlied@linux.ie>
    Cc: Thierry Reding <treding@nvidia.com>
    Cc: Thierry Reding <thierry.reding@gmail.com>
    Cc: Archit Taneja <architt@codeaurora.org>
    Cc: Enric Balletbo <enric.balletbo@collabora.com>
    Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index eb8688e..4a937f1 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
 	  Support the I2S Audio interface which is part of the Synopsis
 	  Designware HDMI block.
 
+config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
+	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
+	depends on OF
+	select DRM_KMS_HELPER
+	select DRM_PANEL
+	---help---
+          This is a driver for the display bridges of
+          GE B850v3 that convert dual channel LVDS
+          to DP++. This is used with the i.MX6 imx-ldb
+          driver. You are likely to say N here.
+
 config DRM_NXP_PTN3460
 	tristate "NXP PTN3460 DP/LVDS bridge"
 	depends on OF
diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
index 2e83a785..af0b7cc 100644
--- a/drivers/gpu/drm/bridge/Makefile
+++ b/drivers/gpu/drm/bridge/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
 obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
 obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
 obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
new file mode 100644
index 0000000..c1d93aa
--- /dev/null
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -0,0 +1,396 @@
+/*
+ * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
+ * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
+
+ * Copyright (c) 2017, Collabora Ltd.
+ * Copyright (c) 2017, General Electric Company
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
+ * display bridge of the GE B850v3. There are two physical bridges on the video
+ * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
+ * physical bridges are automatically configured by the input video signal, and
+ * the driver has no access to the video processing pipeline. The driver is
+ * only needed to read EDID from the STDP2690 and to handle HPD events from the
+ * STDP4028. The driver communicates with both bridges over i2c. The video
+ * signal pipeline is as follows:
+ *
+ *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
+ *
+ */
+
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+#include <drm/drmP.h>
+
+#define EDID_EXT_BLOCK_CNT 0x7E
+
+#define STDP4028_IRQ_OUT_CONF_REG 0x02
+#define STDP4028_DPTX_IRQ_EN_REG 0x3C
+#define STDP4028_DPTX_IRQ_STS_REG 0x3D
+#define STDP4028_DPTX_STS_REG 0x3E
+
+#define STDP4028_DPTX_DP_IRQ_EN 0x1000
+
+#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
+#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
+#define STDP4028_DPTX_IRQ_CONFIG \
+		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
+
+#define STDP4028_DPTX_HOTPLUG_STS 0x0200
+#define STDP4028_DPTX_LINK_STS 0x1000
+#define STDP4028_CON_STATE_CONNECTED \
+		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
+
+#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
+#define STDP4028_DPTX_LINK_CH_STS 0x2000
+#define STDP4028_DPTX_IRQ_CLEAR \
+		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
+
+struct ge_b850v3_lvds {
+	struct drm_connector connector;
+	struct drm_bridge bridge;
+	struct i2c_client *stdp4028_i2c;
+	struct i2c_client *stdp2690_i2c;
+	struct edid *edid;
+};
+
+static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
+
+u8 *stdp2690_get_edid(struct i2c_client *client)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	unsigned char start = 0x00;
+	unsigned int total_size;
+	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= client->addr,
+			.flags	= 0,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= client->addr,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+			.buf	= block,
+		}
+	};
+
+	if (!block)
+		return NULL;
+
+	if (i2c_transfer(adapter, msgs, 2) != 2) {
+		DRM_ERROR("Unable to read EDID.\n");
+		goto err;
+	}
+
+	if (!drm_edid_block_valid(block, 0, false, NULL)) {
+		DRM_ERROR("Invalid EDID data\n");
+		goto err;
+	}
+
+	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
+	if (total_size > EDID_LENGTH) {
+		kfree(block);
+		block = kmalloc(total_size, GFP_KERNEL);
+		if (!block)
+			return NULL;
+
+		/* Yes, read the entire buffer, and do not skip the first
+		 * EDID_LENGTH bytes.
+		 */
+		start = 0x00;
+		msgs[1].len = total_size;
+		msgs[1].buf = block;
+
+		if (i2c_transfer(adapter, msgs, 2) != 2) {
+			DRM_ERROR("Unable to read EDID extension blocks.\n");
+			goto err;
+		}
+		if (!drm_edid_block_valid(block, 1, false, NULL)) {
+			DRM_ERROR("Invalid EDID data\n");
+			goto err;
+		}
+	}
+
+	return block;
+
+err:
+	kfree(block);
+	return NULL;
+}
+
+static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
+{
+	struct i2c_client *client;
+	int num_modes = 0;
+
+	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
+
+	kfree(ge_b850v3_lvds_ptr->edid);
+	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
+
+	if (ge_b850v3_lvds_ptr->edid) {
+		drm_mode_connector_update_edid_property(connector,
+						      ge_b850v3_lvds_ptr->edid);
+		num_modes = drm_add_edid_modes(connector,
+					       ge_b850v3_lvds_ptr->edid);
+	}
+
+	return num_modes;
+}
+
+static enum drm_mode_status ge_b850v3_lvds_mode_valid(
+		struct drm_connector *connector, struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static const struct
+drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
+	.get_modes = ge_b850v3_lvds_get_modes,
+	.mode_valid = ge_b850v3_lvds_mode_valid,
+};
+
+static enum drm_connector_status ge_b850v3_lvds_detect(
+		struct drm_connector *connector, bool force)
+{
+	struct i2c_client *stdp4028_i2c =
+			ge_b850v3_lvds_ptr->stdp4028_i2c;
+	s32 link_state;
+
+	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
+					      STDP4028_DPTX_STS_REG);
+
+	if (link_state == STDP4028_CON_STATE_CONNECTED)
+		return connector_status_connected;
+
+	if (link_state == 0)
+		return connector_status_disconnected;
+
+	return connector_status_unknown;
+}
+
+static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = ge_b850v3_lvds_detect,
+	.destroy = drm_connector_cleanup,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
+{
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (ge_b850v3_lvds_ptr->connector.dev)
+		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
+
+	return IRQ_HANDLED;
+}
+
+static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
+{
+	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
+	struct i2c_client *stdp4028_i2c
+			= ge_b850v3_lvds_ptr->stdp4028_i2c;
+	int ret;
+
+	if (!bridge->encoder) {
+		DRM_ERROR("Parent encoder object not found");
+		return -ENODEV;
+	}
+
+	connector->polled = DRM_CONNECTOR_POLL_HPD;
+
+	drm_connector_helper_add(connector,
+				 &ge_b850v3_lvds_connector_helper_funcs);
+
+	ret = drm_connector_init(bridge->dev, connector,
+				 &ge_b850v3_lvds_connector_funcs,
+				 DRM_MODE_CONNECTOR_DisplayPort);
+	if (ret) {
+		DRM_ERROR("Failed to initialize connector with drm\n");
+		return ret;
+	}
+
+	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
+	if (ret)
+		return ret;
+
+	/* Configures the bridge to re-enable interrupts after each ack. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_IRQ_OUT_CONF_REG,
+				  STDP4028_DPTX_DP_IRQ_EN);
+
+	/* Enable interrupts */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_EN_REG,
+				  STDP4028_DPTX_IRQ_CONFIG);
+
+	return 0;
+}
+
+static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
+	.attach = ge_b850v3_lvds_attach,
+};
+
+static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
+				       const struct i2c_device_id *id)
+{
+	struct device *dev = &stdp4028_i2c->dev;
+
+	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
+
+	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
+	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
+
+	/* Clear pending interrupts since power up. */
+	i2c_smbus_write_word_data(stdp4028_i2c,
+				  STDP4028_DPTX_IRQ_STS_REG,
+				  STDP4028_DPTX_IRQ_CLEAR);
+
+	if (!stdp4028_i2c->irq)
+		return 0;
+
+	return devm_request_threaded_irq(&stdp4028_i2c->dev,
+			stdp4028_i2c->irq, NULL,
+			ge_b850v3_lvds_irq_handler,
+			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
+}
+
+static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
+{
+	return 0;
+}
+
+static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
+	{"stdp4028_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
+	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
+	.probe		= stdp4028_ge_b850v3_fw_probe,
+	.remove		= stdp4028_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp4028-ge-b850v3-fw",
+		.of_match_table = stdp4028_ge_b850v3_fw_match,
+	},
+};
+
+static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
+				       const struct i2c_device_id *id)
+{
+	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
+	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
+
+	return 0;
+}
+
+static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
+{
+	return 0;
+}
+
+static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
+	{"stdp2690_ge_fw", 0},
+	{},
+};
+MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
+
+static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
+	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
+
+static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
+	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
+	.probe		= stdp2690_ge_b850v3_fw_probe,
+	.remove		= stdp2690_ge_b850v3_fw_remove,
+	.driver		= {
+		.name		= "stdp2690-ge-b850v3-fw",
+		.of_match_table = stdp2690_ge_b850v3_fw_match,
+	},
+};
+
+static int __init stdpxxxx_ge_b850v3_init(void)
+{
+	int ret;
+
+	ge_b850v3_lvds_ptr = kzalloc(sizeof(*ge_b850v3_lvds_ptr), GFP_KERNEL);
+
+	if (!ge_b850v3_lvds_ptr)
+		return -ENOMEM;
+
+	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
+	if (ret) {
+		kfree(ge_b850v3_lvds_ptr);
+		return ret;
+	}
+
+	ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
+	if (ret) {
+	        i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
+		kfree(ge_b850v3_lvds_ptr);
+		return ret;
+	}
+
+	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
+	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
+
+	return 0;
+}
+module_init(stdpxxxx_ge_b850v3_init);
+
+static void __exit stdpxxxx_ge_b850v3_exit(void)
+{
+	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
+	kfree(ge_b850v3_lvds_ptr->edid);
+
+	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
+	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
+
+	kfree(ge_b850v3_lvds_ptr);
+}
+module_exit(stdpxxxx_ge_b850v3_exit);
+
+MODULE_AUTHOR("Peter Senna Tschudin <peter.senna@collabora.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@collabora.co.uk>");
+MODULE_DESCRIPTION("GE LVDS to DP++ display bridge)");
+MODULE_LICENSE("GPL v2");

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
  2017-03-01 10:38       ` Peter Senna Tschudin
  (?)
@ 2017-03-02  9:29         ` Archit Taneja
  -1 siblings, 0 replies; 29+ messages in thread
From: Archit Taneja @ 2017-03-02  9:29 UTC (permalink / raw)
  To: Peter Senna Tschudin
  Cc: airlied, akpm, daniel.vetter, davem, devicetree, dri-devel,
	enric.balletbo, eballetbo, galak, gregkh, heiko, ijc+devicetree,
	javier, jslaby, kernel, linux-arm-kernel, linux, linux-kernel,
	linux, mark.rutland, martin.donnelly, martyn.welch, mchehab,
	pawel.moll, peter.senna, p.zabel, thierry.reding, rmk+kernel,
	robh+dt, shawnguo, tiwai, treding, ykk, laurent.pinchart,
	Rob Herring, Fabio Estevam

Hi Peter,

On 3/1/2017 4:08 PM, Peter Senna Tschudin wrote:
> Hi Archit,
>
> Thank you for the review!
>
> On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
>>
>>
>> On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
>>> The video processing pipeline on the second output on the GE B850v3:
>>>
>>>   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>>>
>>> Each bridge has a dedicated flash containing firmware for supporting the
>>> custom design. The result is that in this design neither the STDP4028
>>> nor the STDP2690 behave as the stock bridges would. The compatible
>>> strings include the suffix "-ge-b850v3-fw" to make it clear that the
>>> driver is for the bridges with the firmware which is specific for the GE
>>> B850v3.
>>>
>>> The driver is powerless to control the video processing pipeline, as the
>>> two bridges behaves as a single one. The driver is only needed for
>>> telling the host about EDID / HPD, and for giving the host powers to ack
>>> interrupts.
>>>
>>> This driver adds one i2c_device for each bridge, but only one
>>> drm_bridge. This design allows the creation of a functional connector
>>> that is capable of reading EDID from the STDP2690 while handling
>>> interrupts on the STDP4028.
>>>
>>> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
>>> Cc: Martin Donnelly <martin.donnelly@ge.com>
>>> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
>>> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
>>> Cc: Philipp Zabel <p.zabel@pengutronix.de>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Fabio Estevam <fabio.estevam@nxp.com>
>>> Cc: David Airlie <airlied@linux.ie>
>>> Cc: Thierry Reding <treding@nvidia.com>
>>> Cc: Thierry Reding <thierry.reding@gmail.com>
>>> Cc: Archit Taneja <architt@codeaurora.org>
>>> Cc: Enric Balletbo <enric.balletbo@collabora.com>
>>> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
>>> ---
>>> Changes from V1:
>>>  - Updated copyright year
>>>  - Fixed blank line issues
>>>  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
>>>    added a comment to explain the test.
>>>  - Fixed checkpatch strict warnings about continuation lines. In one case
>>>    fixing the warning would cause the continuation line to be over 80 chars and
>>>    that strict warning remains.
>>>
>>>  drivers/gpu/drm/bridge/Kconfig                     |  11 +
>>>  drivers/gpu/drm/bridge/Makefile                    |   1 +
>>>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
>>>  3 files changed, 423 insertions(+)
>>>  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>>
>>> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
>>> index eb8688e..4a937f1 100644
>>> --- a/drivers/gpu/drm/bridge/Kconfig
>>> +++ b/drivers/gpu/drm/bridge/Kconfig
>>> @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
>>>  	  Support the I2S Audio interface which is part of the Synopsis
>>>  	  Designware HDMI block.
>>>
>>> +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
>>> +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
>>> +	depends on OF
>>> +	select DRM_KMS_HELPER
>>> +	select DRM_PANEL
>>> +	---help---
>>> +          This is a driver for the display bridges of
>>> +          GE B850v3 that convert dual channel LVDS
>>> +          to DP++. This is used with the i.MX6 imx-ldb
>>> +          driver. You are likely to say N here.
>>> +
>>>  config DRM_NXP_PTN3460
>>>  	tristate "NXP PTN3460 DP/LVDS bridge"
>>>  	depends on OF
>>> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
>>> index 2e83a785..af0b7cc 100644
>>> --- a/drivers/gpu/drm/bridge/Makefile
>>> +++ b/drivers/gpu/drm/bridge/Makefile
>>> @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
>>>  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
>>>  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
>>>  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
>>> +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
>>>  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
>>>  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
>>>  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
>>> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>> new file mode 100644
>>> index 0000000..6f82a44
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>> @@ -0,0 +1,411 @@
>>> +/*
>>> + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
>>> + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
>>> +
>>> + * Copyright (c) 2017, Collabora Ltd.
>>> + * Copyright (c) 2017, General Electric Company
>>> +
>>> + * This program is free software; you can redistribute it and/or modify it
>>> + * under the terms and conditions of the GNU General Public License,
>>> + * version 2, as published by the Free Software Foundation.
>>> +
>>> + * This program is distributed in the hope it will be useful, but WITHOUT
>>> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>>> + * more details.
>>> +
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
>>> +
>>> + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
>>> + * display bridge of the GE B850v3. There are two physical bridges on the video
>>> + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
>>> + * physical bridges are automatically configured by the input video signal, and
>>> + * the driver has no access to the video processing pipeline. The driver is
>>> + * only needed to read EDID from the STDP2690 and to handle HPD events from the
>>> + * STDP4028. The driver communicates with both bridges over i2c. The video
>>> + * signal pipeline is as follows:
>>> + *
>>> + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>>> + *
>>> + */
>>> +
>>> +#include <linux/gpio.h>
>>> +#include <linux/i2c.h>
>>> +#include <linux/module.h>
>>> +#include <linux/of.h>
>>> +#include <drm/drm_atomic.h>
>>> +#include <drm/drm_atomic_helper.h>
>>> +#include <drm/drm_crtc_helper.h>
>>> +#include <drm/drm_edid.h>
>>> +#include <drm/drmP.h>
>>> +
>>> +#define EDID_EXT_BLOCK_CNT 0x7E
>>> +
>>> +#define STDP4028_IRQ_OUT_CONF_REG 0x02
>>> +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
>>> +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
>>> +#define STDP4028_DPTX_STS_REG 0x3E
>>> +
>>> +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
>>> +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
>>> +#define STDP4028_DPTX_IRQ_CONFIG \
>>> +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
>>> +#define STDP4028_DPTX_LINK_STS 0x1000
>>> +#define STDP4028_CON_STATE_CONNECTED \
>>> +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
>>> +#define STDP4028_DPTX_LINK_CH_STS 0x2000
>>> +#define STDP4028_DPTX_IRQ_CLEAR \
>>> +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
>>> +
>>> +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
>>> +
>>> +struct ge_b850v3_lvds {
>>> +	struct drm_connector connector;
>>> +	struct drm_bridge bridge;
>>> +	struct i2c_client *stdp4028_i2c;
>>> +	struct i2c_client *stdp2690_i2c;
>>> +	struct edid *edid;
>>> +};
>>> +
>>> +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
>>> +
>>> +u8 *stdp2690_get_edid(struct i2c_client *client)
>>> +{
>>> +	struct i2c_adapter *adapter = client->adapter;
>>> +	unsigned char start = 0x00;
>>> +	unsigned int total_size;
>>> +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
>>> +
>>> +	struct i2c_msg msgs[] = {
>>> +		{
>>> +			.addr	= client->addr,
>>> +			.flags	= 0,
>>> +			.len	= 1,
>>> +			.buf	= &start,
>>> +		}, {
>>> +			.addr	= client->addr,
>>> +			.flags	= I2C_M_RD,
>>> +			.len	= EDID_LENGTH,
>>> +			.buf	= block,
>>> +		}
>>> +	};
>>> +
>>> +	if (!block)
>>> +		return NULL;
>>> +
>>> +	if (i2c_transfer(adapter, msgs, 2) != 2) {
>>> +		DRM_ERROR("Unable to read EDID.\n");
>>> +		goto err;
>>> +	}
>>> +
>>> +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
>>> +		DRM_ERROR("Invalid EDID data\n");
>>> +		goto err;
>>> +	}
>>> +
>>> +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
>>> +	if (total_size > EDID_LENGTH) {
>>> +		kfree(block);
>>> +		block = kmalloc(total_size, GFP_KERNEL);
>>> +		if (!block)
>>> +			return NULL;
>>> +
>>> +		/* Yes, read the entire buffer, and do not skip the first
>>> +		 * EDID_LENGTH bytes.
>>> +		 */
>>> +		start = 0x00;
>>> +		msgs[1].len = total_size;
>>> +		msgs[1].buf = block;
>>> +
>>> +		if (i2c_transfer(adapter, msgs, 2) != 2) {
>>> +			DRM_ERROR("Unable to read EDID extension blocks.\n");
>>> +			goto err;
>>> +		}
>>> +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
>>> +			DRM_ERROR("Invalid EDID data\n");
>>> +			goto err;
>>> +		}
>>> +	}
>>> +
>>> +	return block;
>>> +
>>> +err:
>>> +	kfree(block);
>>> +	return NULL;
>>> +}
>>> +
>>> +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
>>> +{
>>> +	struct i2c_client *client;
>>> +	int num_modes = 0;
>>> +
>>> +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
>>> +
>>> +	kfree(ge_b850v3_lvds_ptr->edid);
>>> +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
>>> +
>>> +	if (ge_b850v3_lvds_ptr->edid) {
>>> +		drm_mode_connector_update_edid_property(connector,
>>> +						      ge_b850v3_lvds_ptr->edid);
>>> +		num_modes = drm_add_edid_modes(connector,
>>> +					       ge_b850v3_lvds_ptr->edid);
>>> +	}
>>> +
>>> +	return num_modes;
>>> +}
>>> +
>>> +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
>>> +		struct drm_connector *connector, struct drm_display_mode *mode)
>>> +{
>>> +	return MODE_OK;
>>> +}
>>> +
>>> +static const struct
>>> +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
>>> +	.get_modes = ge_b850v3_lvds_get_modes,
>>> +	.mode_valid = ge_b850v3_lvds_mode_valid,
>>> +};
>>> +
>>> +static enum drm_connector_status ge_b850v3_lvds_detect(
>>> +		struct drm_connector *connector, bool force)
>>> +{
>>> +	struct i2c_client *stdp4028_i2c =
>>> +			ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +	s32 link_state;
>>> +
>>> +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
>>> +					      STDP4028_DPTX_STS_REG);
>>> +
>>> +	if (link_state == STDP4028_CON_STATE_CONNECTED)
>>> +		return connector_status_connected;
>>> +
>>> +	if (link_state == 0)
>>> +		return connector_status_disconnected;
>>> +
>>> +	return connector_status_unknown;
>>> +}
>>> +
>>> +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
>>> +	.dpms = drm_atomic_helper_connector_dpms,
>>> +	.fill_modes = drm_helper_probe_single_connector_modes,
>>> +	.detect = ge_b850v3_lvds_detect,
>>> +	.destroy = drm_connector_cleanup,
>>> +	.reset = drm_atomic_helper_connector_reset,
>>> +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
>>> +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>>> +};
>>> +
>>> +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
>>> +{
>>> +	struct i2c_client *stdp4028_i2c
>>> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_STS_REG,
>>> +				  STDP4028_DPTX_IRQ_CLEAR);
>>> +
>>> +	if (ge_b850v3_lvds_ptr->connector.dev)
>>> +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
>>> +
>>> +	return IRQ_HANDLED;
>>> +}
>>> +
>>> +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
>>> +{
>>> +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
>>> +	struct i2c_client *stdp4028_i2c
>>> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +	int ret;
>>> +
>>> +	if (!bridge->encoder) {
>>> +		DRM_ERROR("Parent encoder object not found");
>>> +		return -ENODEV;
>>> +	}
>>> +
>>> +	connector->polled = DRM_CONNECTOR_POLL_HPD;
>>> +
>>> +	drm_connector_helper_add(connector,
>>> +				 &ge_b850v3_lvds_connector_helper_funcs);
>>> +
>>> +	ret = drm_connector_init(bridge->dev, connector,
>>> +				 &ge_b850v3_lvds_connector_funcs,
>>> +				 DRM_MODE_CONNECTOR_DisplayPort);
>>> +	if (ret) {
>>> +		DRM_ERROR("Failed to initialize connector with drm\n");
>>> +		return ret;
>>> +	}
>>> +
>>> +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
>>> +	if (ret)
>>> +		return ret;
>>> +
>>> +	/* Configures the bridge to re-enable interrupts after each ack. */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_IRQ_OUT_CONF_REG,
>>> +				  STDP4028_DPTX_DP_IRQ_EN);
>>> +
>>> +	/* Enable interrupts */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_EN_REG,
>>> +				  STDP4028_DPTX_IRQ_CONFIG);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
>>> +	.attach = ge_b850v3_lvds_attach,
>>> +};
>>> +
>>> +static int ge_b850v3_lvds_init(struct device *dev)
>>> +{
>>> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
>>> +
>>> +	if (ge_b850v3_lvds_ptr)
>>> +		goto success;
>>> +
>>> +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
>>> +					  sizeof(*ge_b850v3_lvds_ptr),
>>> +					  GFP_KERNEL);
>>> +
>>> +	if (!ge_b850v3_lvds_ptr) {
>>> +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +		return -ENOMEM;
>>> +	}
>>> +
>>> +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
>>> +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
>>> +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
>>> +
>>> +success:
>>> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +	return 0;
>>> +}
>>> +
>>> +static void ge_b850v3_lvds_remove(void)
>>> +{
>>> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
>>> +	/*
>>> +	 * This check is to avoid both the drivers
>>> +	 * removing the bridge in their remove() function
>>> +	 */
>>> +	if (!ge_b850v3_lvds_ptr)
>>> +		goto out;
>>> +
>>> +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
>>> +
>>> +	kfree(ge_b850v3_lvds_ptr->edid);
>>> +
>>> +	ge_b850v3_lvds_ptr = NULL;
>>> +out:
>>> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +}
>>> +
>>> +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
>>> +				       const struct i2c_device_id *id)
>>> +{
>>> +	struct device *dev = &stdp4028_i2c->dev;
>>> +
>>> +	ge_b850v3_lvds_init(dev);
>>> +
>>> +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
>>> +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
>>> +
>>> +	/* Clear pending interrupts since power up. */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_STS_REG,
>>> +				  STDP4028_DPTX_IRQ_CLEAR);
>>> +
>>> +	if (!stdp4028_i2c->irq)
>>> +		return 0;
>>> +
>>> +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
>>> +			stdp4028_i2c->irq, NULL,
>>> +			ge_b850v3_lvds_irq_handler,
>>> +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
>>> +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
>>> +}
>>> +
>>> +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
>>> +{
>>> +	ge_b850v3_lvds_remove();
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
>>> +	{"stdp4028_ge_fw", 0},
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
>>> +
>>> +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
>>> +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
>>> +
>>> +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
>>> +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
>>> +	.probe		= stdp4028_ge_b850v3_fw_probe,
>>> +	.remove		= stdp4028_ge_b850v3_fw_remove,
>>> +	.driver		= {
>>> +		.name		= "stdp4028-ge-b850v3-fw",
>>> +		.of_match_table = stdp4028_ge_b850v3_fw_match,
>>> +	},
>>> +};
>>> +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
>>> +
>>> +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
>>> +				       const struct i2c_device_id *id)
>>> +{
>>> +	struct device *dev = &stdp2690_i2c->dev;
>>> +
>>> +	ge_b850v3_lvds_init(dev);
>>> +
>>> +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
>>> +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
>>> +{
>>> +	ge_b850v3_lvds_remove();
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
>>> +	{"stdp2690_ge_fw", 0},
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
>>> +
>>> +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
>>> +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
>>> +
>>> +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
>>> +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
>>> +	.probe		= stdp2690_ge_b850v3_fw_probe,
>>> +	.remove		= stdp2690_ge_b850v3_fw_remove,
>>> +	.driver		= {
>>> +		.name		= "stdp2690-ge-b850v3-fw",
>>> +		.of_match_table = stdp2690_ge_b850v3_fw_match,
>>> +	},
>>> +};
>>> +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
>>
>> Didn't catch this in the last series, but there can only be one
>> module_init call per module. This breaks compilation when the
>> driver is built as a module.
>
> Unfortunately yes. Got loads of errors when trying to compile as a
> module.
>
>>
>> You could do something like:
>>
>> static int __init stdpxxxx_ge_b850v3_init(void)
>> {
>> 	int ret;
>>
>> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
>> 	if (ret)
>> 		return ret;
>>
>> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
>> }
>> module_init(stdpxxxx_ge_b850v3_init);
>>
>> static void __exit stdpxxxx_ge_b850v3_exit(void)
>> {
>> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
>> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
>> }
>> module_exit(stdpxxxx_ge_b850v3_exit);
>
> Thank you! I was wondering if merging ge_b850v3_lvds_init() with
> stdpxxxx_ge_b850v3_init() and ge_b850v3_lvds_remove() with
> stdpxxxx_ge_b850v3_exit() make sense as it can probably eliminate the
> need for the mutex.

Doing anything apart from the driver registration/unregistration
in the module_init/exit calls is frowned upon. Nothing specific
to the device should ideally be added in them.

It would be nice to eventually get rid of the lvds_dev_mutex, but
I think we can live with it for now.

Regards,
Archit


-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

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

* Re: [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-02  9:29         ` Archit Taneja
  0 siblings, 0 replies; 29+ messages in thread
From: Archit Taneja @ 2017-03-02  9:29 UTC (permalink / raw)
  To: Peter Senna Tschudin
  Cc: mark.rutland, heiko, airlied, daniel.vetter, peter.senna,
	dri-devel, tiwai, thierry.reding, laurent.pinchart, ykk, jslaby,
	martyn.welch, Rob Herring, mchehab, linux, javier, treding,
	linux, martin.donnelly, devicetree, p.zabel, pawel.moll,
	ijc+devicetree, eballetbo, Fabio Estevam, rmk+kernel, robh+dt,
	linux-arm-kernel, gregkh, linux-kernel, kernel, galak,
	enric.balletbo, akpm, shawnguo, davem

Hi Peter,

On 3/1/2017 4:08 PM, Peter Senna Tschudin wrote:
> Hi Archit,
>
> Thank you for the review!
>
> On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
>>
>>
>> On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
>>> The video processing pipeline on the second output on the GE B850v3:
>>>
>>>   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>>>
>>> Each bridge has a dedicated flash containing firmware for supporting the
>>> custom design. The result is that in this design neither the STDP4028
>>> nor the STDP2690 behave as the stock bridges would. The compatible
>>> strings include the suffix "-ge-b850v3-fw" to make it clear that the
>>> driver is for the bridges with the firmware which is specific for the GE
>>> B850v3.
>>>
>>> The driver is powerless to control the video processing pipeline, as the
>>> two bridges behaves as a single one. The driver is only needed for
>>> telling the host about EDID / HPD, and for giving the host powers to ack
>>> interrupts.
>>>
>>> This driver adds one i2c_device for each bridge, but only one
>>> drm_bridge. This design allows the creation of a functional connector
>>> that is capable of reading EDID from the STDP2690 while handling
>>> interrupts on the STDP4028.
>>>
>>> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
>>> Cc: Martin Donnelly <martin.donnelly@ge.com>
>>> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
>>> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
>>> Cc: Philipp Zabel <p.zabel@pengutronix.de>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Fabio Estevam <fabio.estevam@nxp.com>
>>> Cc: David Airlie <airlied@linux.ie>
>>> Cc: Thierry Reding <treding@nvidia.com>
>>> Cc: Thierry Reding <thierry.reding@gmail.com>
>>> Cc: Archit Taneja <architt@codeaurora.org>
>>> Cc: Enric Balletbo <enric.balletbo@collabora.com>
>>> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
>>> ---
>>> Changes from V1:
>>>  - Updated copyright year
>>>  - Fixed blank line issues
>>>  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
>>>    added a comment to explain the test.
>>>  - Fixed checkpatch strict warnings about continuation lines. In one case
>>>    fixing the warning would cause the continuation line to be over 80 chars and
>>>    that strict warning remains.
>>>
>>>  drivers/gpu/drm/bridge/Kconfig                     |  11 +
>>>  drivers/gpu/drm/bridge/Makefile                    |   1 +
>>>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
>>>  3 files changed, 423 insertions(+)
>>>  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>>
>>> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
>>> index eb8688e..4a937f1 100644
>>> --- a/drivers/gpu/drm/bridge/Kconfig
>>> +++ b/drivers/gpu/drm/bridge/Kconfig
>>> @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
>>>  	  Support the I2S Audio interface which is part of the Synopsis
>>>  	  Designware HDMI block.
>>>
>>> +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
>>> +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
>>> +	depends on OF
>>> +	select DRM_KMS_HELPER
>>> +	select DRM_PANEL
>>> +	---help---
>>> +          This is a driver for the display bridges of
>>> +          GE B850v3 that convert dual channel LVDS
>>> +          to DP++. This is used with the i.MX6 imx-ldb
>>> +          driver. You are likely to say N here.
>>> +
>>>  config DRM_NXP_PTN3460
>>>  	tristate "NXP PTN3460 DP/LVDS bridge"
>>>  	depends on OF
>>> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
>>> index 2e83a785..af0b7cc 100644
>>> --- a/drivers/gpu/drm/bridge/Makefile
>>> +++ b/drivers/gpu/drm/bridge/Makefile
>>> @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
>>>  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
>>>  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
>>>  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
>>> +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
>>>  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
>>>  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
>>>  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
>>> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>> new file mode 100644
>>> index 0000000..6f82a44
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>> @@ -0,0 +1,411 @@
>>> +/*
>>> + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
>>> + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
>>> +
>>> + * Copyright (c) 2017, Collabora Ltd.
>>> + * Copyright (c) 2017, General Electric Company
>>> +
>>> + * This program is free software; you can redistribute it and/or modify it
>>> + * under the terms and conditions of the GNU General Public License,
>>> + * version 2, as published by the Free Software Foundation.
>>> +
>>> + * This program is distributed in the hope it will be useful, but WITHOUT
>>> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>>> + * more details.
>>> +
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
>>> +
>>> + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
>>> + * display bridge of the GE B850v3. There are two physical bridges on the video
>>> + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
>>> + * physical bridges are automatically configured by the input video signal, and
>>> + * the driver has no access to the video processing pipeline. The driver is
>>> + * only needed to read EDID from the STDP2690 and to handle HPD events from the
>>> + * STDP4028. The driver communicates with both bridges over i2c. The video
>>> + * signal pipeline is as follows:
>>> + *
>>> + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>>> + *
>>> + */
>>> +
>>> +#include <linux/gpio.h>
>>> +#include <linux/i2c.h>
>>> +#include <linux/module.h>
>>> +#include <linux/of.h>
>>> +#include <drm/drm_atomic.h>
>>> +#include <drm/drm_atomic_helper.h>
>>> +#include <drm/drm_crtc_helper.h>
>>> +#include <drm/drm_edid.h>
>>> +#include <drm/drmP.h>
>>> +
>>> +#define EDID_EXT_BLOCK_CNT 0x7E
>>> +
>>> +#define STDP4028_IRQ_OUT_CONF_REG 0x02
>>> +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
>>> +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
>>> +#define STDP4028_DPTX_STS_REG 0x3E
>>> +
>>> +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
>>> +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
>>> +#define STDP4028_DPTX_IRQ_CONFIG \
>>> +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
>>> +#define STDP4028_DPTX_LINK_STS 0x1000
>>> +#define STDP4028_CON_STATE_CONNECTED \
>>> +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
>>> +#define STDP4028_DPTX_LINK_CH_STS 0x2000
>>> +#define STDP4028_DPTX_IRQ_CLEAR \
>>> +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
>>> +
>>> +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
>>> +
>>> +struct ge_b850v3_lvds {
>>> +	struct drm_connector connector;
>>> +	struct drm_bridge bridge;
>>> +	struct i2c_client *stdp4028_i2c;
>>> +	struct i2c_client *stdp2690_i2c;
>>> +	struct edid *edid;
>>> +};
>>> +
>>> +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
>>> +
>>> +u8 *stdp2690_get_edid(struct i2c_client *client)
>>> +{
>>> +	struct i2c_adapter *adapter = client->adapter;
>>> +	unsigned char start = 0x00;
>>> +	unsigned int total_size;
>>> +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
>>> +
>>> +	struct i2c_msg msgs[] = {
>>> +		{
>>> +			.addr	= client->addr,
>>> +			.flags	= 0,
>>> +			.len	= 1,
>>> +			.buf	= &start,
>>> +		}, {
>>> +			.addr	= client->addr,
>>> +			.flags	= I2C_M_RD,
>>> +			.len	= EDID_LENGTH,
>>> +			.buf	= block,
>>> +		}
>>> +	};
>>> +
>>> +	if (!block)
>>> +		return NULL;
>>> +
>>> +	if (i2c_transfer(adapter, msgs, 2) != 2) {
>>> +		DRM_ERROR("Unable to read EDID.\n");
>>> +		goto err;
>>> +	}
>>> +
>>> +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
>>> +		DRM_ERROR("Invalid EDID data\n");
>>> +		goto err;
>>> +	}
>>> +
>>> +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
>>> +	if (total_size > EDID_LENGTH) {
>>> +		kfree(block);
>>> +		block = kmalloc(total_size, GFP_KERNEL);
>>> +		if (!block)
>>> +			return NULL;
>>> +
>>> +		/* Yes, read the entire buffer, and do not skip the first
>>> +		 * EDID_LENGTH bytes.
>>> +		 */
>>> +		start = 0x00;
>>> +		msgs[1].len = total_size;
>>> +		msgs[1].buf = block;
>>> +
>>> +		if (i2c_transfer(adapter, msgs, 2) != 2) {
>>> +			DRM_ERROR("Unable to read EDID extension blocks.\n");
>>> +			goto err;
>>> +		}
>>> +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
>>> +			DRM_ERROR("Invalid EDID data\n");
>>> +			goto err;
>>> +		}
>>> +	}
>>> +
>>> +	return block;
>>> +
>>> +err:
>>> +	kfree(block);
>>> +	return NULL;
>>> +}
>>> +
>>> +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
>>> +{
>>> +	struct i2c_client *client;
>>> +	int num_modes = 0;
>>> +
>>> +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
>>> +
>>> +	kfree(ge_b850v3_lvds_ptr->edid);
>>> +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
>>> +
>>> +	if (ge_b850v3_lvds_ptr->edid) {
>>> +		drm_mode_connector_update_edid_property(connector,
>>> +						      ge_b850v3_lvds_ptr->edid);
>>> +		num_modes = drm_add_edid_modes(connector,
>>> +					       ge_b850v3_lvds_ptr->edid);
>>> +	}
>>> +
>>> +	return num_modes;
>>> +}
>>> +
>>> +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
>>> +		struct drm_connector *connector, struct drm_display_mode *mode)
>>> +{
>>> +	return MODE_OK;
>>> +}
>>> +
>>> +static const struct
>>> +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
>>> +	.get_modes = ge_b850v3_lvds_get_modes,
>>> +	.mode_valid = ge_b850v3_lvds_mode_valid,
>>> +};
>>> +
>>> +static enum drm_connector_status ge_b850v3_lvds_detect(
>>> +		struct drm_connector *connector, bool force)
>>> +{
>>> +	struct i2c_client *stdp4028_i2c =
>>> +			ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +	s32 link_state;
>>> +
>>> +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
>>> +					      STDP4028_DPTX_STS_REG);
>>> +
>>> +	if (link_state == STDP4028_CON_STATE_CONNECTED)
>>> +		return connector_status_connected;
>>> +
>>> +	if (link_state == 0)
>>> +		return connector_status_disconnected;
>>> +
>>> +	return connector_status_unknown;
>>> +}
>>> +
>>> +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
>>> +	.dpms = drm_atomic_helper_connector_dpms,
>>> +	.fill_modes = drm_helper_probe_single_connector_modes,
>>> +	.detect = ge_b850v3_lvds_detect,
>>> +	.destroy = drm_connector_cleanup,
>>> +	.reset = drm_atomic_helper_connector_reset,
>>> +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
>>> +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>>> +};
>>> +
>>> +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
>>> +{
>>> +	struct i2c_client *stdp4028_i2c
>>> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_STS_REG,
>>> +				  STDP4028_DPTX_IRQ_CLEAR);
>>> +
>>> +	if (ge_b850v3_lvds_ptr->connector.dev)
>>> +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
>>> +
>>> +	return IRQ_HANDLED;
>>> +}
>>> +
>>> +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
>>> +{
>>> +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
>>> +	struct i2c_client *stdp4028_i2c
>>> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +	int ret;
>>> +
>>> +	if (!bridge->encoder) {
>>> +		DRM_ERROR("Parent encoder object not found");
>>> +		return -ENODEV;
>>> +	}
>>> +
>>> +	connector->polled = DRM_CONNECTOR_POLL_HPD;
>>> +
>>> +	drm_connector_helper_add(connector,
>>> +				 &ge_b850v3_lvds_connector_helper_funcs);
>>> +
>>> +	ret = drm_connector_init(bridge->dev, connector,
>>> +				 &ge_b850v3_lvds_connector_funcs,
>>> +				 DRM_MODE_CONNECTOR_DisplayPort);
>>> +	if (ret) {
>>> +		DRM_ERROR("Failed to initialize connector with drm\n");
>>> +		return ret;
>>> +	}
>>> +
>>> +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
>>> +	if (ret)
>>> +		return ret;
>>> +
>>> +	/* Configures the bridge to re-enable interrupts after each ack. */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_IRQ_OUT_CONF_REG,
>>> +				  STDP4028_DPTX_DP_IRQ_EN);
>>> +
>>> +	/* Enable interrupts */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_EN_REG,
>>> +				  STDP4028_DPTX_IRQ_CONFIG);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
>>> +	.attach = ge_b850v3_lvds_attach,
>>> +};
>>> +
>>> +static int ge_b850v3_lvds_init(struct device *dev)
>>> +{
>>> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
>>> +
>>> +	if (ge_b850v3_lvds_ptr)
>>> +		goto success;
>>> +
>>> +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
>>> +					  sizeof(*ge_b850v3_lvds_ptr),
>>> +					  GFP_KERNEL);
>>> +
>>> +	if (!ge_b850v3_lvds_ptr) {
>>> +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +		return -ENOMEM;
>>> +	}
>>> +
>>> +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
>>> +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
>>> +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
>>> +
>>> +success:
>>> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +	return 0;
>>> +}
>>> +
>>> +static void ge_b850v3_lvds_remove(void)
>>> +{
>>> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
>>> +	/*
>>> +	 * This check is to avoid both the drivers
>>> +	 * removing the bridge in their remove() function
>>> +	 */
>>> +	if (!ge_b850v3_lvds_ptr)
>>> +		goto out;
>>> +
>>> +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
>>> +
>>> +	kfree(ge_b850v3_lvds_ptr->edid);
>>> +
>>> +	ge_b850v3_lvds_ptr = NULL;
>>> +out:
>>> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +}
>>> +
>>> +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
>>> +				       const struct i2c_device_id *id)
>>> +{
>>> +	struct device *dev = &stdp4028_i2c->dev;
>>> +
>>> +	ge_b850v3_lvds_init(dev);
>>> +
>>> +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
>>> +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
>>> +
>>> +	/* Clear pending interrupts since power up. */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_STS_REG,
>>> +				  STDP4028_DPTX_IRQ_CLEAR);
>>> +
>>> +	if (!stdp4028_i2c->irq)
>>> +		return 0;
>>> +
>>> +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
>>> +			stdp4028_i2c->irq, NULL,
>>> +			ge_b850v3_lvds_irq_handler,
>>> +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
>>> +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
>>> +}
>>> +
>>> +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
>>> +{
>>> +	ge_b850v3_lvds_remove();
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
>>> +	{"stdp4028_ge_fw", 0},
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
>>> +
>>> +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
>>> +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
>>> +
>>> +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
>>> +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
>>> +	.probe		= stdp4028_ge_b850v3_fw_probe,
>>> +	.remove		= stdp4028_ge_b850v3_fw_remove,
>>> +	.driver		= {
>>> +		.name		= "stdp4028-ge-b850v3-fw",
>>> +		.of_match_table = stdp4028_ge_b850v3_fw_match,
>>> +	},
>>> +};
>>> +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
>>> +
>>> +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
>>> +				       const struct i2c_device_id *id)
>>> +{
>>> +	struct device *dev = &stdp2690_i2c->dev;
>>> +
>>> +	ge_b850v3_lvds_init(dev);
>>> +
>>> +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
>>> +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
>>> +{
>>> +	ge_b850v3_lvds_remove();
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
>>> +	{"stdp2690_ge_fw", 0},
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
>>> +
>>> +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
>>> +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
>>> +
>>> +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
>>> +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
>>> +	.probe		= stdp2690_ge_b850v3_fw_probe,
>>> +	.remove		= stdp2690_ge_b850v3_fw_remove,
>>> +	.driver		= {
>>> +		.name		= "stdp2690-ge-b850v3-fw",
>>> +		.of_match_table = stdp2690_ge_b850v3_fw_match,
>>> +	},
>>> +};
>>> +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
>>
>> Didn't catch this in the last series, but there can only be one
>> module_init call per module. This breaks compilation when the
>> driver is built as a module.
>
> Unfortunately yes. Got loads of errors when trying to compile as a
> module.
>
>>
>> You could do something like:
>>
>> static int __init stdpxxxx_ge_b850v3_init(void)
>> {
>> 	int ret;
>>
>> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
>> 	if (ret)
>> 		return ret;
>>
>> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
>> }
>> module_init(stdpxxxx_ge_b850v3_init);
>>
>> static void __exit stdpxxxx_ge_b850v3_exit(void)
>> {
>> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
>> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
>> }
>> module_exit(stdpxxxx_ge_b850v3_exit);
>
> Thank you! I was wondering if merging ge_b850v3_lvds_init() with
> stdpxxxx_ge_b850v3_init() and ge_b850v3_lvds_remove() with
> stdpxxxx_ge_b850v3_exit() make sense as it can probably eliminate the
> need for the mutex.

Doing anything apart from the driver registration/unregistration
in the module_init/exit calls is frowned upon. Nothing specific
to the device should ideally be added in them.

It would be nice to eventually get rid of the lvds_dev_mutex, but
I think we can live with it for now.

Regards,
Archit


-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

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

* [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)
@ 2017-03-02  9:29         ` Archit Taneja
  0 siblings, 0 replies; 29+ messages in thread
From: Archit Taneja @ 2017-03-02  9:29 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Peter,

On 3/1/2017 4:08 PM, Peter Senna Tschudin wrote:
> Hi Archit,
>
> Thank you for the review!
>
> On Wed, Mar 01, 2017 at 09:38:48AM +0530, Archit Taneja wrote:
>>
>>
>> On 02/28/2017 07:58 PM, Peter Senna Tschudin wrote:
>>> The video processing pipeline on the second output on the GE B850v3:
>>>
>>>   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>>>
>>> Each bridge has a dedicated flash containing firmware for supporting the
>>> custom design. The result is that in this design neither the STDP4028
>>> nor the STDP2690 behave as the stock bridges would. The compatible
>>> strings include the suffix "-ge-b850v3-fw" to make it clear that the
>>> driver is for the bridges with the firmware which is specific for the GE
>>> B850v3.
>>>
>>> The driver is powerless to control the video processing pipeline, as the
>>> two bridges behaves as a single one. The driver is only needed for
>>> telling the host about EDID / HPD, and for giving the host powers to ack
>>> interrupts.
>>>
>>> This driver adds one i2c_device for each bridge, but only one
>>> drm_bridge. This design allows the creation of a functional connector
>>> that is capable of reading EDID from the STDP2690 while handling
>>> interrupts on the STDP4028.
>>>
>>> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
>>> Cc: Martin Donnelly <martin.donnelly@ge.com>
>>> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
>>> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
>>> Cc: Philipp Zabel <p.zabel@pengutronix.de>
>>> Cc: Rob Herring <robh@kernel.org>
>>> Cc: Fabio Estevam <fabio.estevam@nxp.com>
>>> Cc: David Airlie <airlied@linux.ie>
>>> Cc: Thierry Reding <treding@nvidia.com>
>>> Cc: Thierry Reding <thierry.reding@gmail.com>
>>> Cc: Archit Taneja <architt@codeaurora.org>
>>> Cc: Enric Balletbo <enric.balletbo@collabora.com>
>>> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
>>> ---
>>> Changes from V1:
>>>  - Updated copyright year
>>>  - Fixed blank line issues
>>>  - Updated ge_b850v3_lvds_remove() to not rely on ge_b850v3_lvds_ptr->edid and
>>>    added a comment to explain the test.
>>>  - Fixed checkpatch strict warnings about continuation lines. In one case
>>>    fixing the warning would cause the continuation line to be over 80 chars and
>>>    that strict warning remains.
>>>
>>>  drivers/gpu/drm/bridge/Kconfig                     |  11 +
>>>  drivers/gpu/drm/bridge/Makefile                    |   1 +
>>>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 411 +++++++++++++++++++++
>>>  3 files changed, 423 insertions(+)
>>>  create mode 100644 drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>>
>>> diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
>>> index eb8688e..4a937f1 100644
>>> --- a/drivers/gpu/drm/bridge/Kconfig
>>> +++ b/drivers/gpu/drm/bridge/Kconfig
>>> @@ -48,6 +48,17 @@ config DRM_DW_HDMI_I2S_AUDIO
>>>  	  Support the I2S Audio interface which is part of the Synopsis
>>>  	  Designware HDMI block.
>>>
>>> +config DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW
>>> +	tristate "MegaChips stdp4028-ge-b850v3-fw and stdp2690-ge-b850v3-fw"
>>> +	depends on OF
>>> +	select DRM_KMS_HELPER
>>> +	select DRM_PANEL
>>> +	---help---
>>> +          This is a driver for the display bridges of
>>> +          GE B850v3 that convert dual channel LVDS
>>> +          to DP++. This is used with the i.MX6 imx-ldb
>>> +          driver. You are likely to say N here.
>>> +
>>>  config DRM_NXP_PTN3460
>>>  	tristate "NXP PTN3460 DP/LVDS bridge"
>>>  	depends on OF
>>> diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile
>>> index 2e83a785..af0b7cc 100644
>>> --- a/drivers/gpu/drm/bridge/Makefile
>>> +++ b/drivers/gpu/drm/bridge/Makefile
>>> @@ -5,6 +5,7 @@ obj-$(CONFIG_DRM_DUMB_VGA_DAC) += dumb-vga-dac.o
>>>  obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
>>>  obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
>>>  obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
>>> +obj-$(CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW) += megachips-stdpxxxx-ge-b850v3-fw.o
>>>  obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o
>>>  obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o
>>>  obj-$(CONFIG_DRM_SIL_SII8620) += sil-sii8620.o
>>> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>> new file mode 100644
>>> index 0000000..6f82a44
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
>>> @@ -0,0 +1,411 @@
>>> +/*
>>> + * Driver for MegaChips STDP4028 with GE B850v3 firmware (LVDS-DP)
>>> + * Driver for MegaChips STDP2690 with GE B850v3 firmware (DP-DP++)
>>> +
>>> + * Copyright (c) 2017, Collabora Ltd.
>>> + * Copyright (c) 2017, General Electric Company
>>> +
>>> + * This program is free software; you can redistribute it and/or modify it
>>> + * under the terms and conditions of the GNU General Public License,
>>> + * version 2, as published by the Free Software Foundation.
>>> +
>>> + * This program is distributed in the hope it will be useful, but WITHOUT
>>> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
>>> + * more details.
>>> +
>>> + * You should have received a copy of the GNU General Public License
>>> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
>>> +
>>> + * This driver creates a drm_bridge and a drm_connector for the LVDS to DP++
>>> + * display bridge of the GE B850v3. There are two physical bridges on the video
>>> + * signal pipeline: a STDP4028(LVDS to DP) and a STDP2690(DP to DP++). The
>>> + * physical bridges are automatically configured by the input video signal, and
>>> + * the driver has no access to the video processing pipeline. The driver is
>>> + * only needed to read EDID from the STDP2690 and to handle HPD events from the
>>> + * STDP4028. The driver communicates with both bridges over i2c. The video
>>> + * signal pipeline is as follows:
>>> + *
>>> + *   Host -> LVDS|--(STDP4028)--|DP -> DP|--(STDP2690)--|DP++ -> Video output
>>> + *
>>> + */
>>> +
>>> +#include <linux/gpio.h>
>>> +#include <linux/i2c.h>
>>> +#include <linux/module.h>
>>> +#include <linux/of.h>
>>> +#include <drm/drm_atomic.h>
>>> +#include <drm/drm_atomic_helper.h>
>>> +#include <drm/drm_crtc_helper.h>
>>> +#include <drm/drm_edid.h>
>>> +#include <drm/drmP.h>
>>> +
>>> +#define EDID_EXT_BLOCK_CNT 0x7E
>>> +
>>> +#define STDP4028_IRQ_OUT_CONF_REG 0x02
>>> +#define STDP4028_DPTX_IRQ_EN_REG 0x3C
>>> +#define STDP4028_DPTX_IRQ_STS_REG 0x3D
>>> +#define STDP4028_DPTX_STS_REG 0x3E
>>> +
>>> +#define STDP4028_DPTX_DP_IRQ_EN 0x1000
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_IRQ_EN 0x0400
>>> +#define STDP4028_DPTX_LINK_CH_IRQ_EN 0x2000
>>> +#define STDP4028_DPTX_IRQ_CONFIG \
>>> +		(STDP4028_DPTX_LINK_CH_IRQ_EN | STDP4028_DPTX_HOTPLUG_IRQ_EN)
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_STS 0x0200
>>> +#define STDP4028_DPTX_LINK_STS 0x1000
>>> +#define STDP4028_CON_STATE_CONNECTED \
>>> +		(STDP4028_DPTX_HOTPLUG_STS | STDP4028_DPTX_LINK_STS)
>>> +
>>> +#define STDP4028_DPTX_HOTPLUG_CH_STS 0x0400
>>> +#define STDP4028_DPTX_LINK_CH_STS 0x2000
>>> +#define STDP4028_DPTX_IRQ_CLEAR \
>>> +		(STDP4028_DPTX_LINK_CH_STS | STDP4028_DPTX_HOTPLUG_CH_STS)
>>> +
>>> +static DEFINE_MUTEX(ge_b850v3_lvds_dev_mutex);
>>> +
>>> +struct ge_b850v3_lvds {
>>> +	struct drm_connector connector;
>>> +	struct drm_bridge bridge;
>>> +	struct i2c_client *stdp4028_i2c;
>>> +	struct i2c_client *stdp2690_i2c;
>>> +	struct edid *edid;
>>> +};
>>> +
>>> +static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
>>> +
>>> +u8 *stdp2690_get_edid(struct i2c_client *client)
>>> +{
>>> +	struct i2c_adapter *adapter = client->adapter;
>>> +	unsigned char start = 0x00;
>>> +	unsigned int total_size;
>>> +	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
>>> +
>>> +	struct i2c_msg msgs[] = {
>>> +		{
>>> +			.addr	= client->addr,
>>> +			.flags	= 0,
>>> +			.len	= 1,
>>> +			.buf	= &start,
>>> +		}, {
>>> +			.addr	= client->addr,
>>> +			.flags	= I2C_M_RD,
>>> +			.len	= EDID_LENGTH,
>>> +			.buf	= block,
>>> +		}
>>> +	};
>>> +
>>> +	if (!block)
>>> +		return NULL;
>>> +
>>> +	if (i2c_transfer(adapter, msgs, 2) != 2) {
>>> +		DRM_ERROR("Unable to read EDID.\n");
>>> +		goto err;
>>> +	}
>>> +
>>> +	if (!drm_edid_block_valid(block, 0, false, NULL)) {
>>> +		DRM_ERROR("Invalid EDID data\n");
>>> +		goto err;
>>> +	}
>>> +
>>> +	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
>>> +	if (total_size > EDID_LENGTH) {
>>> +		kfree(block);
>>> +		block = kmalloc(total_size, GFP_KERNEL);
>>> +		if (!block)
>>> +			return NULL;
>>> +
>>> +		/* Yes, read the entire buffer, and do not skip the first
>>> +		 * EDID_LENGTH bytes.
>>> +		 */
>>> +		start = 0x00;
>>> +		msgs[1].len = total_size;
>>> +		msgs[1].buf = block;
>>> +
>>> +		if (i2c_transfer(adapter, msgs, 2) != 2) {
>>> +			DRM_ERROR("Unable to read EDID extension blocks.\n");
>>> +			goto err;
>>> +		}
>>> +		if (!drm_edid_block_valid(block, 1, false, NULL)) {
>>> +			DRM_ERROR("Invalid EDID data\n");
>>> +			goto err;
>>> +		}
>>> +	}
>>> +
>>> +	return block;
>>> +
>>> +err:
>>> +	kfree(block);
>>> +	return NULL;
>>> +}
>>> +
>>> +static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)
>>> +{
>>> +	struct i2c_client *client;
>>> +	int num_modes = 0;
>>> +
>>> +	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
>>> +
>>> +	kfree(ge_b850v3_lvds_ptr->edid);
>>> +	ge_b850v3_lvds_ptr->edid = (struct edid *)stdp2690_get_edid(client);
>>> +
>>> +	if (ge_b850v3_lvds_ptr->edid) {
>>> +		drm_mode_connector_update_edid_property(connector,
>>> +						      ge_b850v3_lvds_ptr->edid);
>>> +		num_modes = drm_add_edid_modes(connector,
>>> +					       ge_b850v3_lvds_ptr->edid);
>>> +	}
>>> +
>>> +	return num_modes;
>>> +}
>>> +
>>> +static enum drm_mode_status ge_b850v3_lvds_mode_valid(
>>> +		struct drm_connector *connector, struct drm_display_mode *mode)
>>> +{
>>> +	return MODE_OK;
>>> +}
>>> +
>>> +static const struct
>>> +drm_connector_helper_funcs ge_b850v3_lvds_connector_helper_funcs = {
>>> +	.get_modes = ge_b850v3_lvds_get_modes,
>>> +	.mode_valid = ge_b850v3_lvds_mode_valid,
>>> +};
>>> +
>>> +static enum drm_connector_status ge_b850v3_lvds_detect(
>>> +		struct drm_connector *connector, bool force)
>>> +{
>>> +	struct i2c_client *stdp4028_i2c =
>>> +			ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +	s32 link_state;
>>> +
>>> +	link_state = i2c_smbus_read_word_data(stdp4028_i2c,
>>> +					      STDP4028_DPTX_STS_REG);
>>> +
>>> +	if (link_state == STDP4028_CON_STATE_CONNECTED)
>>> +		return connector_status_connected;
>>> +
>>> +	if (link_state == 0)
>>> +		return connector_status_disconnected;
>>> +
>>> +	return connector_status_unknown;
>>> +}
>>> +
>>> +static const struct drm_connector_funcs ge_b850v3_lvds_connector_funcs = {
>>> +	.dpms = drm_atomic_helper_connector_dpms,
>>> +	.fill_modes = drm_helper_probe_single_connector_modes,
>>> +	.detect = ge_b850v3_lvds_detect,
>>> +	.destroy = drm_connector_cleanup,
>>> +	.reset = drm_atomic_helper_connector_reset,
>>> +	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
>>> +	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
>>> +};
>>> +
>>> +static irqreturn_t ge_b850v3_lvds_irq_handler(int irq, void *dev_id)
>>> +{
>>> +	struct i2c_client *stdp4028_i2c
>>> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_STS_REG,
>>> +				  STDP4028_DPTX_IRQ_CLEAR);
>>> +
>>> +	if (ge_b850v3_lvds_ptr->connector.dev)
>>> +		drm_kms_helper_hotplug_event(ge_b850v3_lvds_ptr->connector.dev);
>>> +
>>> +	return IRQ_HANDLED;
>>> +}
>>> +
>>> +static int ge_b850v3_lvds_attach(struct drm_bridge *bridge)
>>> +{
>>> +	struct drm_connector *connector = &ge_b850v3_lvds_ptr->connector;
>>> +	struct i2c_client *stdp4028_i2c
>>> +			= ge_b850v3_lvds_ptr->stdp4028_i2c;
>>> +	int ret;
>>> +
>>> +	if (!bridge->encoder) {
>>> +		DRM_ERROR("Parent encoder object not found");
>>> +		return -ENODEV;
>>> +	}
>>> +
>>> +	connector->polled = DRM_CONNECTOR_POLL_HPD;
>>> +
>>> +	drm_connector_helper_add(connector,
>>> +				 &ge_b850v3_lvds_connector_helper_funcs);
>>> +
>>> +	ret = drm_connector_init(bridge->dev, connector,
>>> +				 &ge_b850v3_lvds_connector_funcs,
>>> +				 DRM_MODE_CONNECTOR_DisplayPort);
>>> +	if (ret) {
>>> +		DRM_ERROR("Failed to initialize connector with drm\n");
>>> +		return ret;
>>> +	}
>>> +
>>> +	ret = drm_mode_connector_attach_encoder(connector, bridge->encoder);
>>> +	if (ret)
>>> +		return ret;
>>> +
>>> +	/* Configures the bridge to re-enable interrupts after each ack. */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_IRQ_OUT_CONF_REG,
>>> +				  STDP4028_DPTX_DP_IRQ_EN);
>>> +
>>> +	/* Enable interrupts */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_EN_REG,
>>> +				  STDP4028_DPTX_IRQ_CONFIG);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct drm_bridge_funcs ge_b850v3_lvds_funcs = {
>>> +	.attach = ge_b850v3_lvds_attach,
>>> +};
>>> +
>>> +static int ge_b850v3_lvds_init(struct device *dev)
>>> +{
>>> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
>>> +
>>> +	if (ge_b850v3_lvds_ptr)
>>> +		goto success;
>>> +
>>> +	ge_b850v3_lvds_ptr = devm_kzalloc(dev,
>>> +					  sizeof(*ge_b850v3_lvds_ptr),
>>> +					  GFP_KERNEL);
>>> +
>>> +	if (!ge_b850v3_lvds_ptr) {
>>> +		mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +		return -ENOMEM;
>>> +	}
>>> +
>>> +	ge_b850v3_lvds_ptr->bridge.funcs = &ge_b850v3_lvds_funcs;
>>> +	ge_b850v3_lvds_ptr->bridge.of_node = dev->of_node;
>>> +	drm_bridge_add(&ge_b850v3_lvds_ptr->bridge);
>>> +
>>> +success:
>>> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +	return 0;
>>> +}
>>> +
>>> +static void ge_b850v3_lvds_remove(void)
>>> +{
>>> +	mutex_lock(&ge_b850v3_lvds_dev_mutex);
>>> +	/*
>>> +	 * This check is to avoid both the drivers
>>> +	 * removing the bridge in their remove() function
>>> +	 */
>>> +	if (!ge_b850v3_lvds_ptr)
>>> +		goto out;
>>> +
>>> +	drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
>>> +
>>> +	kfree(ge_b850v3_lvds_ptr->edid);
>>> +
>>> +	ge_b850v3_lvds_ptr = NULL;
>>> +out:
>>> +	mutex_unlock(&ge_b850v3_lvds_dev_mutex);
>>> +}
>>> +
>>> +static int stdp4028_ge_b850v3_fw_probe(struct i2c_client *stdp4028_i2c,
>>> +				       const struct i2c_device_id *id)
>>> +{
>>> +	struct device *dev = &stdp4028_i2c->dev;
>>> +
>>> +	ge_b850v3_lvds_init(dev);
>>> +
>>> +	ge_b850v3_lvds_ptr->stdp4028_i2c = stdp4028_i2c;
>>> +	i2c_set_clientdata(stdp4028_i2c, ge_b850v3_lvds_ptr);
>>> +
>>> +	/* Clear pending interrupts since power up. */
>>> +	i2c_smbus_write_word_data(stdp4028_i2c,
>>> +				  STDP4028_DPTX_IRQ_STS_REG,
>>> +				  STDP4028_DPTX_IRQ_CLEAR);
>>> +
>>> +	if (!stdp4028_i2c->irq)
>>> +		return 0;
>>> +
>>> +	return devm_request_threaded_irq(&stdp4028_i2c->dev,
>>> +			stdp4028_i2c->irq, NULL,
>>> +			ge_b850v3_lvds_irq_handler,
>>> +			IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
>>> +			"ge-b850v3-lvds-dp", ge_b850v3_lvds_ptr);
>>> +}
>>> +
>>> +static int stdp4028_ge_b850v3_fw_remove(struct i2c_client *stdp4028_i2c)
>>> +{
>>> +	ge_b850v3_lvds_remove();
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct i2c_device_id stdp4028_ge_b850v3_fw_i2c_table[] = {
>>> +	{"stdp4028_ge_fw", 0},
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, stdp4028_ge_b850v3_fw_i2c_table);
>>> +
>>> +static const struct of_device_id stdp4028_ge_b850v3_fw_match[] = {
>>> +	{ .compatible = "megachips,stdp4028-ge-b850v3-fw" },
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(of, stdp4028_ge_b850v3_fw_match);
>>> +
>>> +static struct i2c_driver stdp4028_ge_b850v3_fw_driver = {
>>> +	.id_table	= stdp4028_ge_b850v3_fw_i2c_table,
>>> +	.probe		= stdp4028_ge_b850v3_fw_probe,
>>> +	.remove		= stdp4028_ge_b850v3_fw_remove,
>>> +	.driver		= {
>>> +		.name		= "stdp4028-ge-b850v3-fw",
>>> +		.of_match_table = stdp4028_ge_b850v3_fw_match,
>>> +	},
>>> +};
>>> +module_i2c_driver(stdp4028_ge_b850v3_fw_driver);
>>> +
>>> +static int stdp2690_ge_b850v3_fw_probe(struct i2c_client *stdp2690_i2c,
>>> +				       const struct i2c_device_id *id)
>>> +{
>>> +	struct device *dev = &stdp2690_i2c->dev;
>>> +
>>> +	ge_b850v3_lvds_init(dev);
>>> +
>>> +	ge_b850v3_lvds_ptr->stdp2690_i2c = stdp2690_i2c;
>>> +	i2c_set_clientdata(stdp2690_i2c, ge_b850v3_lvds_ptr);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static int stdp2690_ge_b850v3_fw_remove(struct i2c_client *stdp2690_i2c)
>>> +{
>>> +	ge_b850v3_lvds_remove();
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static const struct i2c_device_id stdp2690_ge_b850v3_fw_i2c_table[] = {
>>> +	{"stdp2690_ge_fw", 0},
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(i2c, stdp2690_ge_b850v3_fw_i2c_table);
>>> +
>>> +static const struct of_device_id stdp2690_ge_b850v3_fw_match[] = {
>>> +	{ .compatible = "megachips,stdp2690-ge-b850v3-fw" },
>>> +	{},
>>> +};
>>> +MODULE_DEVICE_TABLE(of, stdp2690_ge_b850v3_fw_match);
>>> +
>>> +static struct i2c_driver stdp2690_ge_b850v3_fw_driver = {
>>> +	.id_table	= stdp2690_ge_b850v3_fw_i2c_table,
>>> +	.probe		= stdp2690_ge_b850v3_fw_probe,
>>> +	.remove		= stdp2690_ge_b850v3_fw_remove,
>>> +	.driver		= {
>>> +		.name		= "stdp2690-ge-b850v3-fw",
>>> +		.of_match_table = stdp2690_ge_b850v3_fw_match,
>>> +	},
>>> +};
>>> +module_i2c_driver(stdp2690_ge_b850v3_fw_driver);
>>
>> Didn't catch this in the last series, but there can only be one
>> module_init call per module. This breaks compilation when the
>> driver is built as a module.
>
> Unfortunately yes. Got loads of errors when trying to compile as a
> module.
>
>>
>> You could do something like:
>>
>> static int __init stdpxxxx_ge_b850v3_init(void)
>> {
>> 	int ret;
>>
>> 	ret = i2c_add_driver(&stdp4028_ge_b850v3_fw_driver);
>> 	if (ret)
>> 		return ret;
>>
>> 	return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
>> }
>> module_init(stdpxxxx_ge_b850v3_init);
>>
>> static void __exit stdpxxxx_ge_b850v3_exit(void)
>> {
>> 	i2c_del_driver(&stdp2690_ge_b850v3_fw_driver);
>> 	i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
>> }
>> module_exit(stdpxxxx_ge_b850v3_exit);
>
> Thank you! I was wondering if merging ge_b850v3_lvds_init() with
> stdpxxxx_ge_b850v3_init() and ge_b850v3_lvds_remove() with
> stdpxxxx_ge_b850v3_exit() make sense as it can probably eliminate the
> need for the mutex.

Doing anything apart from the driver registration/unregistration
in the module_init/exit calls is frowned upon. Nothing specific
to the device should ideally be added in them.

It would be nice to eventually get rid of the lvds_dev_mutex, but
I think we can live with it for now.

Regards,
Archit


-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

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

* Re: [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
  2017-02-28 14:28   ` Peter Senna Tschudin
  (?)
@ 2017-03-03  6:21     ` Rob Herring
  -1 siblings, 0 replies; 29+ messages in thread
From: Rob Herring @ 2017-03-03  6:21 UTC (permalink / raw)
  To: Peter Senna Tschudin
  Cc: airlied, architt, akpm, daniel.vetter, davem, devicetree,
	dri-devel, enric.balletbo, eballetbo, galak, gregkh, heiko,
	ijc+devicetree, javier, jslaby, kernel, linux-arm-kernel, linux,
	linux-kernel, linux, mark.rutland, martin.donnelly, martyn.welch,
	mchehab, pawel.moll, peter.senna, p.zabel, thierry.reding,
	rmk+kernel, shawnguo, tiwai, treding, ykk, laurent.pinchart,
	Fabio Estevam, Rask Ingemann Lambertsen

On Tue, Feb 28, 2017 at 03:28:10PM +0100, Peter Senna Tschudin wrote:
> Devicetree binding documentation for the second video output
> of the GE B850v3:
>    STDP4028-ge-b850v3-fw bridges (LVDS-DP)
>    STDP2690-ge-b850v3-fw bridges (DP-DP++)
> 
> Added entry for MegaChips at:
>  Documentation/devicetree/bindings/vendor-prefixes.txt
> 
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Martin Donnelly <martin.donnelly@ge.com>
> Cc: Javier Martinez Canillas <javier@dowhile0.org>
> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> ---
> Changes from V1:
>  - New subject
>  - Moved binding documentation from bindings/video/ to bindings/display/bridge/
>  - Reworded to describe hardware instead of the driver
>  - Reformated the bindings to have one set of required properties per device
>  - Updated reg description
>  - Defined number of ports and what they are for
> 
>  .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     | 94 ++++++++++++++++++++++
>  .../devicetree/bindings/vendor-prefixes.txt        |  1 +
>  2 files changed, 95 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
@ 2017-03-03  6:21     ` Rob Herring
  0 siblings, 0 replies; 29+ messages in thread
From: Rob Herring @ 2017-03-03  6:21 UTC (permalink / raw)
  To: Peter Senna Tschudin
  Cc: mark.rutland, heiko, airlied, daniel.vetter, peter.senna,
	dri-devel, tiwai, thierry.reding, laurent.pinchart, ykk, jslaby,
	martyn.welch, architt, mchehab, linux, javier, treding,
	Rask Ingemann Lambertsen, linux, martin.donnelly, devicetree,
	p.zabel, pawel.moll, ijc+devicetree, eballetbo, Fabio Estevam,
	rmk+kernel, linux-arm-kernel, gregkh, linux-kernel, kernel,
	galak, enric.balletbo, akpm, shaw

On Tue, Feb 28, 2017 at 03:28:10PM +0100, Peter Senna Tschudin wrote:
> Devicetree binding documentation for the second video output
> of the GE B850v3:
>    STDP4028-ge-b850v3-fw bridges (LVDS-DP)
>    STDP2690-ge-b850v3-fw bridges (DP-DP++)
> 
> Added entry for MegaChips at:
>  Documentation/devicetree/bindings/vendor-prefixes.txt
> 
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Martin Donnelly <martin.donnelly@ge.com>
> Cc: Javier Martinez Canillas <javier@dowhile0.org>
> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> ---
> Changes from V1:
>  - New subject
>  - Moved binding documentation from bindings/video/ to bindings/display/bridge/
>  - Reworded to describe hardware instead of the driver
>  - Reformated the bindings to have one set of required properties per device
>  - Updated reg description
>  - Defined number of ports and what they are for
> 
>  .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     | 94 ++++++++++++++++++++++
>  .../devicetree/bindings/vendor-prefixes.txt        |  1 +
>  2 files changed, 95 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt

Acked-by: Rob Herring <robh@kernel.org>

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

* [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw
@ 2017-03-03  6:21     ` Rob Herring
  0 siblings, 0 replies; 29+ messages in thread
From: Rob Herring @ 2017-03-03  6:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Feb 28, 2017 at 03:28:10PM +0100, Peter Senna Tschudin wrote:
> Devicetree binding documentation for the second video output
> of the GE B850v3:
>    STDP4028-ge-b850v3-fw bridges (LVDS-DP)
>    STDP2690-ge-b850v3-fw bridges (DP-DP++)
> 
> Added entry for MegaChips at:
>  Documentation/devicetree/bindings/vendor-prefixes.txt
> 
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Martyn Welch <martyn.welch@collabora.co.uk>
> Cc: Martin Donnelly <martin.donnelly@ge.com>
> Cc: Javier Martinez Canillas <javier@dowhile0.org>
> Cc: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Signed-off-by: Peter Senna Tschudin <peter.senna@collabora.com>
> ---
> Changes from V1:
>  - New subject
>  - Moved binding documentation from bindings/video/ to bindings/display/bridge/
>  - Reworded to describe hardware instead of the driver
>  - Reformated the bindings to have one set of required properties per device
>  - Updated reg description
>  - Defined number of ports and what they are for
> 
>  .../bridge/megachips-stdpxxxx-ge-b850v3-fw.txt     | 94 ++++++++++++++++++++++
>  .../devicetree/bindings/vendor-prefixes.txt        |  1 +
>  2 files changed, 95 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/display/bridge/megachips-stdpxxxx-ge-b850v3-fw.txt

Acked-by: Rob Herring <robh@kernel.org>

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

end of thread, other threads:[~2017-03-03  6:53 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28 14:28 [PATCH V2 0/4] megachips-stdpxxxx-ge-b850v3-fw Peter Senna Tschudin
2017-02-28 14:28 ` Peter Senna Tschudin
2017-02-28 14:28 ` [PATCH V2 1/4] dt-bindings: display: megachips-stdpxxxx-ge-b850v3-fw Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-03-03  6:21   ` Rob Herring
2017-03-03  6:21     ` Rob Herring
2017-03-03  6:21     ` Rob Herring
2017-02-28 14:28 ` [PATCH V2 2/4] MAINTAINERS: Add entry for megachips-stdpxxxx-ge-b850v3-fw Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-02-28 14:28 ` [PATCH V2 3/4] drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++) Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-03-01  4:08   ` Archit Taneja
2017-03-01  4:08     ` Archit Taneja
2017-03-01  4:08     ` Archit Taneja
2017-03-01 10:38     ` Peter Senna Tschudin
2017-03-01 10:38       ` Peter Senna Tschudin
2017-03-01 10:38       ` Peter Senna Tschudin
2017-03-02  9:29       ` Archit Taneja
2017-03-02  9:29         ` Archit Taneja
2017-03-02  9:29         ` Archit Taneja
2017-03-01 16:16     ` Peter Senna Tschudin
2017-03-01 16:16       ` Peter Senna Tschudin
2017-03-01 16:16       ` Peter Senna Tschudin
2017-02-28 14:28 ` [PATCH V2 4/4] dts/imx6q-b850v3: Use megachips-stdpxxxx-ge-b850v3-fw bridges (LVDS-DP++) Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin
2017-02-28 14:28   ` Peter Senna Tschudin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.