All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip
@ 2020-03-18  7:07 Enric Balletbo i Serra
  2020-03-18  7:07 ` [PATCH v4 2/4] mfd: anx7688: Add driver for " Enric Balletbo i Serra
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-03-18  7:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Collabora Kernel ML, Andrzej Hajda, icenowy, anarsoul,
	Neil Armstrong, matthias.bgg, drinkcat, hsinyi, megous,
	Lee Jones, Mark Rutland, Rob Herring, devicetree

The ANX7688 chip is a Type-C Port Controller, HDMI to DP converter and
USB-C mux between USB 3.0 lanes and the DP output.

For our use case a big part of the chip, like power supplies, control
gpios and the usb-c part is managed by an Embedded Controller, hence,
this is its simplest form of the binding. We'd prefer introduce these
properties for someone with a different use case so they can test
on their hardware.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v4: None
Changes in v3:
- Add binding for ANX7688 multi-function device.

Changes in v2: None

 .../bindings/mfd/analogix,anx7688.yaml        | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml

diff --git a/Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml b/Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml
new file mode 100644
index 000000000000..bb95a4e87188
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mfd/analogix,anx7688.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analogix ANX7688 HDMI to USB Type-C Bridge (Port Controller with MUX)
+
+maintainers:
+  - Nicolas Boichat <drinkcat@chromium.org>
+  - Enric Balletbo i Serra <enric.balletbo@collabora.com>
+
+description: |
+  ANX7688 converts HDMI 2.0 to DisplayPort 1.3 Ultra-HDi (4096x2160p60)
+  including an intelligent crosspoint switch to support USB Type-C (USB-C).
+  The integrated crosspoint switch supports USB 3.1 data transfer along with
+  the DisplayPort Alternate Mode signaling over USB Type-C. Additionally,
+  an on-chip microcontroller (OCM) is available to manage the signal switching,
+  Channel Configuration (CC) detection, USB Power Delivery (USB-PD), Vendor
+  Defined Message (VDM) protocol support and other functions as defined in the
+  USB TypeC and USB Power Delivery specifications.
+
+  As a result, a multi-function device is exposed as parent of the video
+  bridge, TCPC and MUX blocks.
+
+properties:
+  compatible:
+    const: analogix,anx7688
+
+  reg:
+    maxItems: 1
+    description: I2C address of the device
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        anx7688: anx7688@2c {
+            compatible = "analogix,anx7688";
+            reg = <0x2c>;
+        };
+    };
-- 
2.25.1


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

* [PATCH v4 2/4] mfd: anx7688: Add driver for Analogix ANX7688 chip
  2020-03-18  7:07 [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip Enric Balletbo i Serra
@ 2020-03-18  7:07 ` Enric Balletbo i Serra
  2020-03-26  9:30   ` Lee Jones
  2020-03-18  7:07   ` Enric Balletbo i Serra
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-03-18  7:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Collabora Kernel ML, Andrzej Hajda, icenowy, anarsoul,
	Neil Armstrong, matthias.bgg, drinkcat, hsinyi, megous,
	Lee Jones

The ANX7688 chip is a Type-C Port Controller, HDMI to DP converter and
USB-C mux between USB 3.0 lanes and the DP output.

For our use case a big part of the chip, like power supplies, control
gpios and usb-c parts are managed by an Embedded Controller, hence,
this is its simplest form of it. Other users of this chip might
introduce new functionalities as per their requirements.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/mfd/Kconfig         | 11 +++++
 drivers/mfd/Makefile        |  1 +
 drivers/mfd/anx7688.c       | 87 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/anx7688.h | 39 +++++++++++++++++
 4 files changed, 138 insertions(+)
 create mode 100644 drivers/mfd/anx7688.c
 create mode 100644 include/linux/mfd/anx7688.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 2b203290e7b9..ac4ef4f20518 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -51,6 +51,17 @@ config MFD_ACT8945A
 	  linear regulators, along with a complete ActivePath battery
 	  charger.
 
+config MFD_ANX7688
+	tristate "Analogix ANX7688"
+	select MFD_CORE
+	select REGMAP_I2C
+	depends on I2C && OF
+	help
+	  Support the ANX7688 from Analogix. This device features a USB
+	  Type-C Port Controller (TCPC), and HDMI to DP converter, and
+	  USB-C mux between USB 3.0 lanes and the DP output of the
+	  embedded converter.
+
 config MFD_SUN4I_GPADC
 	tristate "Allwinner sunxi platforms' GPADC MFD driver"
 	select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index b83f172545e1..4c6ca8a7d260 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MFD_88PM800)	+= 88pm800.o 88pm80x.o
 obj-$(CONFIG_MFD_88PM805)	+= 88pm805.o 88pm80x.o
 obj-$(CONFIG_MFD_ACT8945A)	+= act8945a.o
 obj-$(CONFIG_MFD_SM501)		+= sm501.o
+obj-$(CONFIG_MFD_ANX7688)	+= anx7688.o
 obj-$(CONFIG_MFD_ASIC3)		+= asic3.o tmio_core.o
 obj-$(CONFIG_ARCH_BCM2835)	+= bcm2835-pm.o
 obj-$(CONFIG_MFD_BCM590XX)	+= bcm590xx.o
diff --git a/drivers/mfd/anx7688.c b/drivers/mfd/anx7688.c
new file mode 100644
index 000000000000..fab7ed410c46
--- /dev/null
+++ b/drivers/mfd/anx7688.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * HDMI to USB Type-C Bridge and Port Controller with MUX
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include <linux/i2c.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mfd/anx7688.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/regulator/consumer.h>
+#include <linux/regmap.h>
+
+static const struct regmap_config anx7688_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+};
+
+static int anx7688_i2c_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct anx7688 *anx7688;
+	u16 vendor, device;
+	u8 buffer[4];
+	int ret;
+
+	anx7688 = devm_kzalloc(dev, sizeof(*anx7688), GFP_KERNEL);
+	if (!anx7688)
+		return -ENOMEM;
+
+	anx7688->client = client;
+	i2c_set_clientdata(client, anx7688);
+
+	anx7688->regmap = devm_regmap_init_i2c(client, &anx7688_regmap_config);
+
+	/* Read both vendor and device id (4 bytes). */
+	ret = regmap_bulk_read(anx7688->regmap, ANX7688_VENDOR_ID_REG,
+			       buffer, 4);
+	if (ret) {
+		dev_err(dev, "Failed to read chip vendor/device id\n");
+		return ret;
+	}
+
+	vendor = (u16)buffer[1] << 8 | buffer[0];
+	device = (u16)buffer[3] << 8 | buffer[2];
+	if (vendor != ANX7688_VENDOR_ID || device != ANX7688_DEVICE_ID) {
+		dev_err(dev, "Invalid vendor/device id %04x/%04x\n",
+			vendor, device);
+		return -ENODEV;
+	}
+
+	ret = regmap_bulk_read(anx7688->regmap, ANX7688_FW_VERSION_REG,
+			       buffer, 2);
+	if (ret) {
+		dev_err(&client->dev, "Failed to read firmware version\n");
+		return ret;
+	}
+
+	anx7688->fw_version = (u16)buffer[0] << 8 | buffer[1];
+	dev_info(dev, "ANX7688 firwmare version 0x%04x\n",
+		 anx7688->fw_version);
+
+	return devm_of_platform_populate(dev);
+}
+
+static const struct of_device_id anx7688_match_table[] = {
+	{ .compatible = "analogix,anx7688", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, anx7688_match_table);
+
+static struct i2c_driver anx7688_driver = {
+	.probe_new = anx7688_i2c_probe,
+	.driver = {
+		.name = "anx7688",
+		.of_match_table = anx7688_match_table,
+	},
+};
+
+module_i2c_driver(anx7688_driver);
+
+MODULE_DESCRIPTION("HDMI to USB Type-C Bridge and Port Controller with MUX driver");
+MODULE_AUTHOR("Nicolas Boichat <drinkcat@chromium.org>");
+MODULE_AUTHOR("Enric Balletbo i Serra <enric.balletbo@collabora.com>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/anx7688.h b/include/linux/mfd/anx7688.h
new file mode 100644
index 000000000000..f2760856f045
--- /dev/null
+++ b/include/linux/mfd/anx7688.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * HDMI to USB Type-C Bridge and Port Controller with MUX
+ *
+ * Copyright 2020 Google LLC
+ */
+#ifndef __LINUX_MFD_ANX7688_H
+#define __LINUX_MFD_ANX7688_H
+
+#include <linux/types.h>
+
+/* Register addresses */
+#define ANX7688_VENDOR_ID_REG		0x00
+#define ANX7688_DEVICE_ID_REG		0x02
+
+#define ANX7688_FW_VERSION_REG		0x80
+
+#define ANX7688_DP_BANDWIDTH_REG	0x85
+#define ANX7688_DP_LANE_COUNT_REG	0x86
+
+#define ANX7688_VENDOR_ID		0x1f29
+#define ANX7688_DEVICE_ID		0x7688
+
+/* First supported firmware version (0.85) */
+#define ANX7688_MINIMUM_FW_VERSION	0x0085
+
+struct gpio_desc;
+struct i2c_client;
+struct regulator;
+struct regmap;
+
+struct anx7688 {
+	struct i2c_client *client;
+	struct regmap *regmap;
+
+	u16 fw_version;
+};
+
+#endif /* __LINUX_MFD_ANX7688_H */
-- 
2.25.1


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

* [PATCH v4 3/4] dt-bindings: Add ANX7688 HDMI to DP bridge binding
  2020-03-18  7:07 [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip Enric Balletbo i Serra
@ 2020-03-18  7:07   ` Enric Balletbo i Serra
  2020-03-18  7:07   ` Enric Balletbo i Serra
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-03-18  7:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Collabora Kernel ML, Andrzej Hajda, icenowy, anarsoul,
	Neil Armstrong, matthias.bgg, drinkcat, hsinyi, megous,
	Daniel Vetter, David Airlie, Mark Rutland, Rob Herring,
	devicetree, dri-devel

From: Nicolas Boichat <drinkcat@chromium.org>

Add documentation for DT properties supported by the ANX7688 HDMI-DP
converter.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v4: None
Changes in v3:
- Adapt the bridge bindings for the multi-function device.

Changes in v2:
- Improve a bit the descriptions using the info from the datasheet.
- Convert binding to yaml.
- Use dual licensing.

 .../bridge/analogix,anx7688-bridge.yaml       | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml

diff --git a/Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml b/Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml
new file mode 100644
index 000000000000..c56da3f39dd8
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml
@@ -0,0 +1,80 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/bridge/analogix,anx7688-bridge.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analogix ANX7688 HDMI to DisplayPort Bridge
+
+maintainers:
+  - Nicolas Boichat <drinkcat@chromium.org>
+  - Enric Balletbo i Serra <enric.balletbo@collabora.com>
+
+description: |
+  The ANX7688 bridge describes the HDMI 2.0 to DisplayPort 1.3 bridge block
+  included in the ANX7688 chip controller. These are meant to be used for
+  controlling display-related signals.
+
+  The node of this device should be under an analogix,anx7866 node. Please refer
+  to Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml for the ANX7688
+  core bindings.
+
+properties:
+  compatible:
+    const: analogix,anx7688-bridge
+
+  ports:
+    type: object
+
+    properties:
+      port@0:
+        type: object
+        description: |
+          Video port for HDMI input
+
+      port@1:
+        type: object
+        description: |
+          Video port for DP output
+
+    required:
+      - port@0
+
+required:
+  - compatible
+  - ports
+
+examples:
+  - |
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        anx7688: anx7688@2c {
+            compatible = "analogix,anx7688";
+            reg = <0x2c>;
+
+            bridge {
+                compatible = "analogix,anx7688-bridge";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        anx7688_in: endpoint {
+                            remote-endpoint = <&hdmi0_out>;
+                        };
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        anx7688_out: endpoint {
+                            remote-endpoint = <&typec0_connector>;
+                       };
+                    };
+                };
+            };
+        };
+    };
-- 
2.25.1


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

* [PATCH v4 3/4] dt-bindings: Add ANX7688 HDMI to DP bridge binding
@ 2020-03-18  7:07   ` Enric Balletbo i Serra
  0 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-03-18  7:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: megous, Mark Rutland, drinkcat, Neil Armstrong, David Airlie,
	dri-devel, anarsoul, Andrzej Hajda, devicetree, Rob Herring,
	hsinyi, matthias.bgg, Collabora Kernel ML, icenowy

From: Nicolas Boichat <drinkcat@chromium.org>

Add documentation for DT properties supported by the ANX7688 HDMI-DP
converter.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v4: None
Changes in v3:
- Adapt the bridge bindings for the multi-function device.

Changes in v2:
- Improve a bit the descriptions using the info from the datasheet.
- Convert binding to yaml.
- Use dual licensing.

 .../bridge/analogix,anx7688-bridge.yaml       | 80 +++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml

diff --git a/Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml b/Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml
new file mode 100644
index 000000000000..c56da3f39dd8
--- /dev/null
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7688-bridge.yaml
@@ -0,0 +1,80 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/display/bridge/analogix,anx7688-bridge.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analogix ANX7688 HDMI to DisplayPort Bridge
+
+maintainers:
+  - Nicolas Boichat <drinkcat@chromium.org>
+  - Enric Balletbo i Serra <enric.balletbo@collabora.com>
+
+description: |
+  The ANX7688 bridge describes the HDMI 2.0 to DisplayPort 1.3 bridge block
+  included in the ANX7688 chip controller. These are meant to be used for
+  controlling display-related signals.
+
+  The node of this device should be under an analogix,anx7866 node. Please refer
+  to Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml for the ANX7688
+  core bindings.
+
+properties:
+  compatible:
+    const: analogix,anx7688-bridge
+
+  ports:
+    type: object
+
+    properties:
+      port@0:
+        type: object
+        description: |
+          Video port for HDMI input
+
+      port@1:
+        type: object
+        description: |
+          Video port for DP output
+
+    required:
+      - port@0
+
+required:
+  - compatible
+  - ports
+
+examples:
+  - |
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        anx7688: anx7688@2c {
+            compatible = "analogix,anx7688";
+            reg = <0x2c>;
+
+            bridge {
+                compatible = "analogix,anx7688-bridge";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        anx7688_in: endpoint {
+                            remote-endpoint = <&hdmi0_out>;
+                        };
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        anx7688_out: endpoint {
+                            remote-endpoint = <&typec0_connector>;
+                       };
+                    };
+                };
+            };
+        };
+    };
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* [PATCH v4 4/4] drm/bridge: anx7688: Add ANX7688 bridge driver support
  2020-03-18  7:07 [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip Enric Balletbo i Serra
@ 2020-03-18  7:07   ` Enric Balletbo i Serra
  2020-03-18  7:07   ` Enric Balletbo i Serra
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-03-18  7:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Collabora Kernel ML, Andrzej Hajda, icenowy, anarsoul,
	Neil Armstrong, matthias.bgg, drinkcat, hsinyi, megous,
	kbuild test robot, Daniel Vetter, David Airlie, Jernej Skrabec,
	Jonas Karlman, Laurent Pinchart, Maxime Ripard, Thomas Gleixner,
	Torsten Duwe, dri-devel

From: Nicolas Boichat <drinkcat@chromium.org>

This driver adds support for the ANX7688 HDMI to DP converter block of the
ANX7688 multi-function device.

For our use case, the only reason the Linux kernel driver is necessary is
to reject resolutions that require more bandwidth than what is available
on the DP side. DP bandwidth and lane count are reported by the bridge via
2 registers and, as far as we know, only for chips that have a firmware
version greather than 0.85 supports these two registers.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
[The driver is OF only so should depends on CONFIG_OF]
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v4:
- Fix build issue reported by kbuild test robot

Changes in v3:
- Convert to a child of ANX7688 multi-function device.

Changes in v2:
- Move driver to drivers/gpu/drm/bridge/analogix.
- Make the driver OF only so we can reduce the ifdefs.
- Update the Copyright to 2020.
- Use probe_new so we can get rid of the i2c_device_id table.

 drivers/gpu/drm/bridge/analogix/Kconfig       |  10 ++
 drivers/gpu/drm/bridge/analogix/Makefile      |   1 +
 .../drm/bridge/analogix/analogix-anx7688.c    | 135 ++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/analogix/analogix-anx7688.c

diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig b/drivers/gpu/drm/bridge/analogix/Kconfig
index e1fa7d820373..1f096055c036 100644
--- a/drivers/gpu/drm/bridge/analogix/Kconfig
+++ b/drivers/gpu/drm/bridge/analogix/Kconfig
@@ -11,6 +11,16 @@ config DRM_ANALOGIX_ANX6345
 	  ANX6345 transforms the LVTTL RGB output of an
 	  application processor to eDP or DisplayPort.
 
+config DRM_ANALOGIX_ANX7688
+	tristate "Analogix ANX7688 bridge"
+	depends on OF
+	select DRM_KMS_HELPER
+	select MFD_ANX7688
+	help
+	  ANX7688 is an ultra-low power 4k Ultra-HD (4096x2160p60)
+	  mobile HD transmitter designed for portable devices. The
+	  ANX7688 converts HDMI 2.0 to DisplayPort 1.3 Ultra-HD.
+
 config DRM_ANALOGIX_ANX78XX
 	tristate "Analogix ANX78XX bridge"
 	select DRM_ANALOGIX_DP
diff --git a/drivers/gpu/drm/bridge/analogix/Makefile b/drivers/gpu/drm/bridge/analogix/Makefile
index 97669b374098..27cd73635c8c 100644
--- a/drivers/gpu/drm/bridge/analogix/Makefile
+++ b/drivers/gpu/drm/bridge/analogix/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 analogix_dp-objs := analogix_dp_core.o analogix_dp_reg.o analogix-i2c-dptx.o
 obj-$(CONFIG_DRM_ANALOGIX_ANX6345) += analogix-anx6345.o
+obj-$(CONFIG_DRM_ANALOGIX_ANX7688) += analogix-anx7688.o
 obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o
 obj-$(CONFIG_DRM_ANALOGIX_DP) += analogix_dp.o
diff --git a/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c
new file mode 100644
index 000000000000..81b950ecde27
--- /dev/null
+++ b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ANX7688 HDMI->DP bridge driver
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include <linux/mfd/anx7688.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <drm/drm_bridge.h>
+#include <drm/drm_print.h>
+
+struct anx7688_bridge_data {
+	struct drm_bridge bridge;
+	struct regmap *regmap;
+
+	bool filter;
+};
+
+static inline struct anx7688_bridge_data *
+bridge_to_anx7688(struct drm_bridge *bridge)
+{
+	return container_of(bridge, struct anx7688_bridge_data, bridge);
+}
+
+static bool anx7688_bridge_mode_fixup(struct drm_bridge *bridge,
+				      const struct drm_display_mode *mode,
+				      struct drm_display_mode *adjusted_mode)
+{
+	struct anx7688_bridge_data *data = bridge_to_anx7688(bridge);
+	int totalbw, requiredbw;
+	u8 dpbw, lanecount;
+	u8 regs[2];
+	int ret;
+
+	if (!data->filter)
+		return true;
+
+	/* Read both regs 0x85 (bandwidth) and 0x86 (lane count). */
+	ret = regmap_bulk_read(data->regmap, ANX7688_DP_BANDWIDTH_REG, regs,
+			       2);
+	if (ret < 0) {
+		DRM_ERROR("Failed to read bandwidth/lane count\n");
+		return false;
+	}
+	dpbw = regs[0];
+	lanecount = regs[1];
+
+	/* Maximum 0x19 bandwidth (6.75 Gbps Turbo mode), 2 lanes */
+	if (dpbw > 0x19 || lanecount > 2) {
+		DRM_ERROR("Invalid bandwidth/lane count (%02x/%d)\n", dpbw,
+			  lanecount);
+		return false;
+	}
+
+	/* Compute available bandwidth (kHz) */
+	totalbw = dpbw * lanecount * 270000 * 8 / 10;
+
+	/* Required bandwidth (8 bpc, kHz) */
+	requiredbw = mode->clock * 8 * 3;
+
+	DRM_DEBUG_KMS("DP bandwidth: %d kHz (%02x/%d); mode requires %d Khz\n",
+		      totalbw, dpbw, lanecount, requiredbw);
+
+	if (totalbw == 0) {
+		DRM_ERROR("Bandwidth/lane count are 0, not rejecting modes\n");
+		return true;
+	}
+
+	return totalbw >= requiredbw;
+}
+
+static const struct drm_bridge_funcs anx7688_bridge_funcs = {
+	.mode_fixup = anx7688_bridge_mode_fixup,
+};
+
+static int anx7688_bridge_probe(struct platform_device *pdev)
+{
+	struct anx7688 *anx7688 = dev_get_drvdata(pdev->dev.parent);
+	struct anx7688_bridge_data *data;
+	struct device *dev = &pdev->dev;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->bridge.of_node = dev->of_node;
+	data->regmap = anx7688->regmap;
+
+	/* FW version >= 0.85 supports bandwidth/lane count registers */
+	if (anx7688->fw_version >= ANX7688_MINIMUM_FW_VERSION)
+		data->filter = true;
+	else
+		/* Warn, but not fail, for backwards compatibility */
+		DRM_WARN("Old ANX7688 FW version (0x%04x), not filtering\n",
+			 anx7688->fw_version);
+
+	data->bridge.funcs = &anx7688_bridge_funcs;
+	drm_bridge_add(&data->bridge);
+
+	return 0;
+}
+
+static int anx7688_bridge_remove(struct platform_device *pdev)
+{
+	struct anx7688_bridge_data *data = dev_get_drvdata(&pdev->dev);
+
+	drm_bridge_remove(&data->bridge);
+
+	return 0;
+}
+
+static const struct of_device_id anx7688_bridge_match_table[] = {
+	{ .compatible = "analogix,anx7688-bridge", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, anx7688_bridge_match_table);
+
+static struct platform_driver anx7688_bridge_driver = {
+	.probe = anx7688_bridge_probe,
+	.remove = anx7688_bridge_remove,
+	.driver = {
+		.name = "anx7688-bridge",
+		.of_match_table = anx7688_bridge_match_table,
+	},
+};
+
+module_platform_driver(anx7688_bridge_driver);
+
+MODULE_DESCRIPTION("ANX7688 HDMI->DP bridge driver");
+MODULE_AUTHOR("Nicolas Boichat <drinkcat@chromium.org>");
+MODULE_AUTHOR("Enric Balletbo i Serra <enric.balletbo@collabora.com>");
+MODULE_LICENSE("GPL");
-- 
2.25.1


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

* [PATCH v4 4/4] drm/bridge: anx7688: Add ANX7688 bridge driver support
@ 2020-03-18  7:07   ` Enric Balletbo i Serra
  0 siblings, 0 replies; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-03-18  7:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: megous, Jernej Skrabec, drinkcat, kbuild test robot,
	Maxime Ripard, Neil Armstrong, David Airlie, Torsten Duwe,
	Jonas Karlman, dri-devel, anarsoul, Andrzej Hajda,
	Laurent Pinchart, hsinyi, matthias.bgg, Thomas Gleixner,
	Collabora Kernel ML, icenowy

From: Nicolas Boichat <drinkcat@chromium.org>

This driver adds support for the ANX7688 HDMI to DP converter block of the
ANX7688 multi-function device.

For our use case, the only reason the Linux kernel driver is necessary is
to reject resolutions that require more bandwidth than what is available
on the DP side. DP bandwidth and lane count are reported by the bridge via
2 registers and, as far as we know, only for chips that have a firmware
version greather than 0.85 supports these two registers.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
[The driver is OF only so should depends on CONFIG_OF]
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

Changes in v4:
- Fix build issue reported by kbuild test robot

Changes in v3:
- Convert to a child of ANX7688 multi-function device.

Changes in v2:
- Move driver to drivers/gpu/drm/bridge/analogix.
- Make the driver OF only so we can reduce the ifdefs.
- Update the Copyright to 2020.
- Use probe_new so we can get rid of the i2c_device_id table.

 drivers/gpu/drm/bridge/analogix/Kconfig       |  10 ++
 drivers/gpu/drm/bridge/analogix/Makefile      |   1 +
 .../drm/bridge/analogix/analogix-anx7688.c    | 135 ++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/analogix/analogix-anx7688.c

diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig b/drivers/gpu/drm/bridge/analogix/Kconfig
index e1fa7d820373..1f096055c036 100644
--- a/drivers/gpu/drm/bridge/analogix/Kconfig
+++ b/drivers/gpu/drm/bridge/analogix/Kconfig
@@ -11,6 +11,16 @@ config DRM_ANALOGIX_ANX6345
 	  ANX6345 transforms the LVTTL RGB output of an
 	  application processor to eDP or DisplayPort.
 
+config DRM_ANALOGIX_ANX7688
+	tristate "Analogix ANX7688 bridge"
+	depends on OF
+	select DRM_KMS_HELPER
+	select MFD_ANX7688
+	help
+	  ANX7688 is an ultra-low power 4k Ultra-HD (4096x2160p60)
+	  mobile HD transmitter designed for portable devices. The
+	  ANX7688 converts HDMI 2.0 to DisplayPort 1.3 Ultra-HD.
+
 config DRM_ANALOGIX_ANX78XX
 	tristate "Analogix ANX78XX bridge"
 	select DRM_ANALOGIX_DP
diff --git a/drivers/gpu/drm/bridge/analogix/Makefile b/drivers/gpu/drm/bridge/analogix/Makefile
index 97669b374098..27cd73635c8c 100644
--- a/drivers/gpu/drm/bridge/analogix/Makefile
+++ b/drivers/gpu/drm/bridge/analogix/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 analogix_dp-objs := analogix_dp_core.o analogix_dp_reg.o analogix-i2c-dptx.o
 obj-$(CONFIG_DRM_ANALOGIX_ANX6345) += analogix-anx6345.o
+obj-$(CONFIG_DRM_ANALOGIX_ANX7688) += analogix-anx7688.o
 obj-$(CONFIG_DRM_ANALOGIX_ANX78XX) += analogix-anx78xx.o
 obj-$(CONFIG_DRM_ANALOGIX_DP) += analogix_dp.o
diff --git a/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c
new file mode 100644
index 000000000000..81b950ecde27
--- /dev/null
+++ b/drivers/gpu/drm/bridge/analogix/analogix-anx7688.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ANX7688 HDMI->DP bridge driver
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include <linux/mfd/anx7688.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <drm/drm_bridge.h>
+#include <drm/drm_print.h>
+
+struct anx7688_bridge_data {
+	struct drm_bridge bridge;
+	struct regmap *regmap;
+
+	bool filter;
+};
+
+static inline struct anx7688_bridge_data *
+bridge_to_anx7688(struct drm_bridge *bridge)
+{
+	return container_of(bridge, struct anx7688_bridge_data, bridge);
+}
+
+static bool anx7688_bridge_mode_fixup(struct drm_bridge *bridge,
+				      const struct drm_display_mode *mode,
+				      struct drm_display_mode *adjusted_mode)
+{
+	struct anx7688_bridge_data *data = bridge_to_anx7688(bridge);
+	int totalbw, requiredbw;
+	u8 dpbw, lanecount;
+	u8 regs[2];
+	int ret;
+
+	if (!data->filter)
+		return true;
+
+	/* Read both regs 0x85 (bandwidth) and 0x86 (lane count). */
+	ret = regmap_bulk_read(data->regmap, ANX7688_DP_BANDWIDTH_REG, regs,
+			       2);
+	if (ret < 0) {
+		DRM_ERROR("Failed to read bandwidth/lane count\n");
+		return false;
+	}
+	dpbw = regs[0];
+	lanecount = regs[1];
+
+	/* Maximum 0x19 bandwidth (6.75 Gbps Turbo mode), 2 lanes */
+	if (dpbw > 0x19 || lanecount > 2) {
+		DRM_ERROR("Invalid bandwidth/lane count (%02x/%d)\n", dpbw,
+			  lanecount);
+		return false;
+	}
+
+	/* Compute available bandwidth (kHz) */
+	totalbw = dpbw * lanecount * 270000 * 8 / 10;
+
+	/* Required bandwidth (8 bpc, kHz) */
+	requiredbw = mode->clock * 8 * 3;
+
+	DRM_DEBUG_KMS("DP bandwidth: %d kHz (%02x/%d); mode requires %d Khz\n",
+		      totalbw, dpbw, lanecount, requiredbw);
+
+	if (totalbw == 0) {
+		DRM_ERROR("Bandwidth/lane count are 0, not rejecting modes\n");
+		return true;
+	}
+
+	return totalbw >= requiredbw;
+}
+
+static const struct drm_bridge_funcs anx7688_bridge_funcs = {
+	.mode_fixup = anx7688_bridge_mode_fixup,
+};
+
+static int anx7688_bridge_probe(struct platform_device *pdev)
+{
+	struct anx7688 *anx7688 = dev_get_drvdata(pdev->dev.parent);
+	struct anx7688_bridge_data *data;
+	struct device *dev = &pdev->dev;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->bridge.of_node = dev->of_node;
+	data->regmap = anx7688->regmap;
+
+	/* FW version >= 0.85 supports bandwidth/lane count registers */
+	if (anx7688->fw_version >= ANX7688_MINIMUM_FW_VERSION)
+		data->filter = true;
+	else
+		/* Warn, but not fail, for backwards compatibility */
+		DRM_WARN("Old ANX7688 FW version (0x%04x), not filtering\n",
+			 anx7688->fw_version);
+
+	data->bridge.funcs = &anx7688_bridge_funcs;
+	drm_bridge_add(&data->bridge);
+
+	return 0;
+}
+
+static int anx7688_bridge_remove(struct platform_device *pdev)
+{
+	struct anx7688_bridge_data *data = dev_get_drvdata(&pdev->dev);
+
+	drm_bridge_remove(&data->bridge);
+
+	return 0;
+}
+
+static const struct of_device_id anx7688_bridge_match_table[] = {
+	{ .compatible = "analogix,anx7688-bridge", },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, anx7688_bridge_match_table);
+
+static struct platform_driver anx7688_bridge_driver = {
+	.probe = anx7688_bridge_probe,
+	.remove = anx7688_bridge_remove,
+	.driver = {
+		.name = "anx7688-bridge",
+		.of_match_table = anx7688_bridge_match_table,
+	},
+};
+
+module_platform_driver(anx7688_bridge_driver);
+
+MODULE_DESCRIPTION("ANX7688 HDMI->DP bridge driver");
+MODULE_AUTHOR("Nicolas Boichat <drinkcat@chromium.org>");
+MODULE_AUTHOR("Enric Balletbo i Serra <enric.balletbo@collabora.com>");
+MODULE_LICENSE("GPL");
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH v4 2/4] mfd: anx7688: Add driver for Analogix ANX7688 chip
  2020-03-18  7:07 ` [PATCH v4 2/4] mfd: anx7688: Add driver for " Enric Balletbo i Serra
@ 2020-03-26  9:30   ` Lee Jones
  0 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2020-03-26  9:30 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: linux-kernel, Collabora Kernel ML, Andrzej Hajda, icenowy,
	anarsoul, Neil Armstrong, matthias.bgg, drinkcat, hsinyi, megous

On Wed, 18 Mar 2020, Enric Balletbo i Serra wrote:

> The ANX7688 chip is a Type-C Port Controller, HDMI to DP converter and
> USB-C mux between USB 3.0 lanes and the DP output.
> 
> For our use case a big part of the chip, like power supplies, control
> gpios and usb-c parts are managed by an Embedded Controller, hence,
> this is its simplest form of it. Other users of this chip might
> introduce new functionalities as per their requirements.

Hmm... So first impressions is that this 'driver' doesn't really do
anything useful other than checking the running model.  I think you're
better off using "simple-mfd" and doing the ID check inside the
useful/functional child device driver(s).

> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> ---
> 
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
> 
>  drivers/mfd/Kconfig         | 11 +++++
>  drivers/mfd/Makefile        |  1 +
>  drivers/mfd/anx7688.c       | 87 +++++++++++++++++++++++++++++++++++++
>  include/linux/mfd/anx7688.h | 39 +++++++++++++++++
>  4 files changed, 138 insertions(+)
>  create mode 100644 drivers/mfd/anx7688.c
>  create mode 100644 include/linux/mfd/anx7688.h

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip
  2020-03-18  7:07 [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip Enric Balletbo i Serra
                   ` (2 preceding siblings ...)
  2020-03-18  7:07   ` Enric Balletbo i Serra
@ 2020-03-30 22:58 ` Rob Herring
  3 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2020-03-30 22:58 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: linux-kernel, Collabora Kernel ML, Andrzej Hajda, icenowy,
	anarsoul, Neil Armstrong, matthias.bgg, drinkcat, hsinyi, megous,
	Lee Jones, Mark Rutland, devicetree

On Wed, Mar 18, 2020 at 08:07:27AM +0100, Enric Balletbo i Serra wrote:
> The ANX7688 chip is a Type-C Port Controller, HDMI to DP converter and
> USB-C mux between USB 3.0 lanes and the DP output.
> 
> For our use case a big part of the chip, like power supplies, control
> gpios and the usb-c part is managed by an Embedded Controller, hence,
> this is its simplest form of the binding. We'd prefer introduce these
> properties for someone with a different use case so they can test
> on their hardware.

I'm not sure this is a move in the right direction from the prior 
version. Just because you have multiple functions that doesn't mean 
the DT has multiple child nodes. What's a 'function' exactly may vary 
by OS (or in time). Are the USB-C functions separate h/w? Are there 
separate resources for each sub-function that need to be defined in DT?

We do need to be able to construct a graph with this device, HDMI 
output, USB host, and USB connector. That may dictate what does or 
doesn't work here.

> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
> ---
> 
> Changes in v4: None
> Changes in v3:
> - Add binding for ANX7688 multi-function device.
> 
> Changes in v2: None
> 
>  .../bindings/mfd/analogix,anx7688.yaml        | 48 +++++++++++++++++++
>  1 file changed, 48 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml
> 
> diff --git a/Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml b/Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml
> new file mode 100644
> index 000000000000..bb95a4e87188
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/mfd/analogix,anx7688.yaml
> @@ -0,0 +1,48 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/mfd/analogix,anx7688.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Analogix ANX7688 HDMI to USB Type-C Bridge (Port Controller with MUX)
> +
> +maintainers:
> +  - Nicolas Boichat <drinkcat@chromium.org>
> +  - Enric Balletbo i Serra <enric.balletbo@collabora.com>
> +
> +description: |
> +  ANX7688 converts HDMI 2.0 to DisplayPort 1.3 Ultra-HDi (4096x2160p60)
> +  including an intelligent crosspoint switch to support USB Type-C (USB-C).
> +  The integrated crosspoint switch supports USB 3.1 data transfer along with
> +  the DisplayPort Alternate Mode signaling over USB Type-C. Additionally,
> +  an on-chip microcontroller (OCM) is available to manage the signal switching,
> +  Channel Configuration (CC) detection, USB Power Delivery (USB-PD), Vendor
> +  Defined Message (VDM) protocol support and other functions as defined in the
> +  USB TypeC and USB Power Delivery specifications.
> +
> +  As a result, a multi-function device is exposed as parent of the video
> +  bridge, TCPC and MUX blocks.
> +
> +properties:
> +  compatible:
> +    const: analogix,anx7688
> +
> +  reg:
> +    maxItems: 1
> +    description: I2C address of the device
> +
> +required:
> +  - compatible
> +  - reg

If this does stay like this, then you need to define the child node(s) 
here and reference their bindings.

> +
> +examples:
> +  - |
> +    i2c0 {
> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +
> +        anx7688: anx7688@2c {
> +            compatible = "analogix,anx7688";
> +            reg = <0x2c>;
> +        };
> +    };
> -- 
> 2.25.1
> 

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

end of thread, other threads:[~2020-03-30 22:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18  7:07 [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip Enric Balletbo i Serra
2020-03-18  7:07 ` [PATCH v4 2/4] mfd: anx7688: Add driver for " Enric Balletbo i Serra
2020-03-26  9:30   ` Lee Jones
2020-03-18  7:07 ` [PATCH v4 3/4] dt-bindings: Add ANX7688 HDMI to DP bridge binding Enric Balletbo i Serra
2020-03-18  7:07   ` Enric Balletbo i Serra
2020-03-18  7:07 ` [PATCH v4 4/4] drm/bridge: anx7688: Add ANX7688 bridge driver support Enric Balletbo i Serra
2020-03-18  7:07   ` Enric Balletbo i Serra
2020-03-30 22:58 ` [PATCH v4 1/4] dt-bindings: Add binding for the Analogix ANX7688 chip Rob Herring

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.