Re: [PATCH] usb: typec: anx7688: Add driver for ANX7688 USB-C HDMI bridge

From: Ondřej Jirman
Date: Sat Feb 03 2024 - 13:18:34 EST


Hi Pavel,

On Thu, Feb 01, 2024 at 11:41:56AM +0100, Pavel Machek wrote:
> From: Ondrej Jirman <megi@xxxxxx>
>
> 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.

> 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).
>
> Signed-off-by: Ondrej Jirman <megi@xxxxxx>

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.

> Signed-off-by: Martijn Braam <martijn@xxxxxxxxx>
> Signed-off-by: Samuel Holland <samuel@xxxxxxxxxxxx>
> Signed-off-by: Pavel Machek <pavel@xxxxxx>
>
> [...]
>
> +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;
> + }
> + 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.