Skip to contentSkip to conversation

usb: typec: anx7688: Add driver for ANX7688 USB-C HDMI bridge

PATCH In review Pavel Machek 3 participants 6 messages Feb 1, 2024 – Feb 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: typec: anx7688: Add driver for ANX7688 USB-C HDMI bridge

From: Ondrej Jirman <[email protected]>

This is driver for ANX7688 USB-C HDMI, with flashing and debugging features removed. ANX7688 is rather criticial piece on PinePhone, there's no display and no battery charging without it.

There's likely more work to be done here, but having basic support in mainline is needed to be able to work on the other stuff (networking, cameras, power management).

drivers/usb/typec/Kconfig +11 -0
index 2f80c2792dbd..982b7c444a1f 100644
@@ -64,6 +65,17 @@ config TYPEC_ANX7411
 	  If you choose to build this driver as a dynamically linked module, the
 	  module will be called anx7411.ko.
 
+config TYPEC_ANX7688
+	tristate "Analogix ANX7688 Type-C DRP Port controller and mux driver"
+	depends on I2C
+	depends on USB_ROLE_SWITCH
+	help
+	  Say Y or M here if your system has Analogix ANX7688 Type-C Bridge
+	  controller driver.
+
+	  If you choose to build this driver as a dynamically linked module, the
+	  module will be called anx7688.ko.
+
 config TYPEC_RT1719
 	tristate "Richtek RT1719 Sink Only Type-C controller driver"
 	depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH
drivers/usb/typec/Makefile +1 -0
index 7a368fea61bc..3f8ff94ad294 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_TYPEC_TCPM)	+= tcpm/
 obj-$(CONFIG_TYPEC_UCSI)	+= ucsi/
 obj-$(CONFIG_TYPEC_TPS6598X)	+= tipd/
 obj-$(CONFIG_TYPEC_ANX7411)	+= anx7411.o
+obj-$(CONFIG_TYPEC_ANX7688)	+= anx7688.o
 obj-$(CONFIG_TYPEC_HD3SS3220)	+= hd3ss3220.o
 obj-$(CONFIG_TYPEC_STUSB160X) 	+= stusb160x.o
 obj-$(CONFIG_TYPEC_RT1719)	+= rt1719.o
drivers/usb/typec/anx7688.c new file +1866 -0

1,866 lines not on this page · raw message

maintainer
#1 lore raw

drivers/usb/typec/anx7688.c line 3

Quoted 6 lines · Pavel Machek
drivers/usb/typec/anx7688.c new file +3 -0
@@ -0,0 +1,1866 @@
+/*
+ * ANX7688 USB-C HDMI bridge/PD driver
+ *

<snip>

Did this pass checkpatch? I need a spdx line for new files please, don't force us to go back and guess in the future, that isn't nice.

thanks,

greg k-h

#2 lore raw

Hi!

Quoted 11 lines

drivers/usb/typec/anx7688.c line 3

Quoted 6 lines
drivers/usb/typec/anx7688.c new file +3 -0
@@ -0,0 +1,1866 @@
+/*
+ * ANX7688 USB-C HDMI bridge/PD driver
+ *

<snip>

Did this pass checkpatch? I need a spdx line for new files please, don't force us to go back and guess in the future, that isn't nice.

Thanks for the review. Fixing checkpatch issues is easy, but it looks like closer look will be needed at the devicetree probing.

Also, what are the authors preferences about the license? I'd prefer GPLv2+.

Best regards,
Pavel

maintainer
#3 lore raw
In reply to Pavel Machek
Quoted 1 line · Pavel Machek

+#define DEBUG

Please don't. This is dynamic, use the dynamic debugging and set it from userspace if you want to debug the driver.

Quoted 18 lines
drivers/usb/typec/anx7688.c new file +18 -0
+
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/extcon-provider.h>
+#include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/irqreturn.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_irq.h>
+#include <linux/power_supply.h>
+#include <linux/regulator/consumer.h>
+#include <linux/usb/pd.h>
+#include <linux/usb/role.h>
+#include <linux/usb/typec.h>
+

drivers/usb/typec/anx7688.c line 73

Quoted 10 lines
drivers/usb/typec/anx7688.c new file +10 -0
+/* firmware regs */
+
+#define ANX7688_REG_VBUS_OFF_DELAY_TIME 0x22
+#define ANX7688_REG_FEATURE_CTRL        0x27
+#define ANX7688_REG_EEPROM_LOAD_STATUS1 0x11
+#define ANX7688_REG_EEPROM_LOAD_STATUS0 0x12
+#define ANX7688_REG_FW_VERSION1         0x15
+#define ANX7688_REG_FW_VERSION0         0x16
+
+#define ANX7688_EEPROM_FW_LOADED	0x01

Mix of tabs and spaces, please just use tabs.

drivers/usb/typec/anx7688.c line 168

Quoted 12 lines
drivers/usb/typec/anx7688.c new file +12 -0
+static const char * const anx7688_supply_names[] = {
+        "avdd33",
+        "avdd18",
+        "dvdd18",
+        "avdd10",
+        "dvdd10",
+	"i2c",
+        "hdmi_vt",
+
+        "vconn", // power for VCONN1/VCONN2 switches
+        "vbus", // vbus power
+};

Again, tabs vs. spaces, please use checkpatch.

Quoted 16 lines
drivers/usb/typec/anx7688.c new file +16 -0
+#define ANX7688_NUM_SUPPLIES ARRAY_SIZE(anx7688_supply_names)
+#define ANX7688_NUM_ALWAYS_ON_SUPPLIES (ANX7688_NUM_SUPPLIES - 1)
+
+#define ANX7688_I2C_INDEX (ANX7688_NUM_SUPPLIES - 4)
+#define ANX7688_VCONN_INDEX (ANX7688_NUM_SUPPLIES - 2)
+#define ANX7688_VBUS_INDEX (ANX7688_NUM_SUPPLIES - 1)
+
+enum {
+	ANX7688_F_POWERED,
+	ANX7688_F_CONNECTED,
+	ANX7688_F_FW_FAILED,
+	ANX7688_F_PWRSUPPLY_CHANGE,
+	ANX7688_F_CURRENT_UPDATE,
+};
+
+struct anx7688 {

drivers/usb/typec/anx7688.c line 195

Quoted 10 lines
drivers/usb/typec/anx7688.c new file +10 -0
+        struct device *dev;
+        struct i2c_client *client;
+        struct i2c_client *client_tcpc;
+        struct regulator_bulk_data supplies[ANX7688_NUM_SUPPLIES];
+	struct power_supply *vbus_in_supply;
+	struct notifier_block vbus_in_nb;
+	int input_current_limit; // mA
+        struct gpio_desc *gpio_enable;
+        struct gpio_desc *gpio_reset;
+        struct gpio_desc *gpio_cabledet;

I'm stopping here, again, tabs, you know this :(

greg k-h

#4 lore raw
In reply to Pavel Machek

Hi Pavel,

Quoted 5 lines · Pavel Machek

From: Ondrej Jirman <[email protected]>

This is driver for ANX7688 USB-C HDMI, with flashing and debugging features removed. ANX7688 is rather criticial piece on PinePhone, there's no display and no battery charging without it.

Don't remove the flashing part. Some Pinephones come without the firmware in the past. Even recently, I've seen some people in the Pine chat asking how to flash the firmware on some old PinePhone.

It's a safe operation that can be done at any time and can only be done from the kernel driver.

Quoted 5 lines

There's likely more work to be done here, but having basic support in mainline is needed to be able to work on the other stuff (networking, cameras, power management).

I should be second in order of sign-offs. Martijn wrote a non-working skeleton
https://megous.com/git/linux/commit/?h=pp-5.7&id=30e33cefd7956a2b49fb27008b4af9d868974e58
driver. Then I picked it up and developed it over years to a working thing. Almost none of the skeleton remains.

License is GPLv2.

Quoted 32 lines

[...]

drivers/usb/typec/anx7688.c new file +26 -0
+static int anx7688_i2c_probe(struct i2c_client *client)
+{
+        struct anx7688 *anx7688;
+        struct device *dev = &client->dev;
+        struct typec_capability typec_cap = { };
+        int i, vid_h, vid_l;
+        int irq_cabledet;
+        int ret = 0;
+
+        anx7688 = devm_kzalloc(dev, sizeof(*anx7688), GFP_KERNEL);
+        if (!anx7688)
+                return -ENOMEM;
+
+        i2c_set_clientdata(client, anx7688);
+        anx7688->client = client;
+        anx7688->dev = &client->dev;
+        mutex_init(&anx7688->lock);
+        INIT_DELAYED_WORK(&anx7688->work, anx7688_work);
+	anx7688->last_extcon_state = -1;
+
+	ret = of_property_read_variable_u32_array(dev->of_node, "source-caps",
+						  anx7688->src_caps,
+						  1, ARRAY_SIZE(anx7688->src_caps));
+	if (ret < 0) {
+		dev_err(dev, "failed to get source-caps from DT\n");
+		return ret;

drivers/usb/typec/anx7688.c line 1606

Quoted 10 lines
drivers/usb/typec/anx7688.c new file +10 -0
+	}
+	anx7688->n_src_caps = ret;
+
+	ret = of_property_read_variable_u32_array(dev->of_node, "sink-caps",
+						  anx7688->snk_caps,
+						  1, ARRAY_SIZE(anx7688->snk_caps));
+	if (ret < 0) {
+		dev_err(dev, "failed to get sink-caps from DT\n");
+		return ret;
+	}

^^^ The driver will need to follow usb-c-connector bindings and it will need a bindings documentation for itself.

That's one of the missing things that I did not implement, yet.

Kind regards,

	o.
#5 lore raw

Hi!

Quoted 6 lines
Quoted 5 lines

From: Ondrej Jirman <[email protected]>

This is driver for ANX7688 USB-C HDMI, with flashing and debugging features removed. ANX7688 is rather criticial piece on PinePhone, there's no display and no battery charging without it.

Quoted 6 lines

Don't remove the flashing part. Some Pinephones come without the firmware in the past. Even recently, I've seen some people in the Pine chat asking how to flash the firmware on some old PinePhone.

It's a safe operation that can be done at any time and can only be done from the kernel driver.

I can re-add it later, but initial merge will be tricky enough as-is.

Quoted 10 lines
Quoted 5 lines

There's likely more work to be done here, but having basic support in mainline is needed to be able to work on the other stuff (networking, cameras, power management).

I should be second in order of sign-offs. Martijn wrote a non-working skeleton
https://megous.com/git/linux/commit/?h=pp-5.7&id=30e33cefd7956a2b49fb27008b4af9d868974e58
driver. Then I picked it up and developed it over years to a working thing. Almost none of the skeleton remains.

I believe From: should match First signed-off. I guess Martijn should be marked as co-developed-by or something like that?

Quoted 1 line

License is GPLv2.

Ok.

Quoted 11 lines

drivers/usb/typec/anx7688.c line 1606

Quoted 7 lines
drivers/usb/typec/anx7688.c new file +7 -0
+	ret = of_property_read_variable_u32_array(dev->of_node, "sink-caps",
+						  anx7688->snk_caps,
+						  1, ARRAY_SIZE(anx7688->snk_caps));
+	if (ret < 0) {
+		dev_err(dev, "failed to get sink-caps from DT\n");
+		return ret;
+	}

^^^ The driver will need to follow usb-c-connector bindings and it will need a bindings documentation for itself.

Quoted 1 line

That's one of the missing things that I did not implement, yet.

Yep, I fought with device trees for few days. I should have yaml ready.

Best regards,
Pavel

Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.