[PATCH 2/4] usb: typec: stusb4500: add USB PD fixed supply driver
Sascha Hauer
s.hauer at pengutronix.de
Tue Nov 17 03:27:56 PST 2026
Hi Giandomenico,
On 2026-11-14 17:19, Giandomenico Rossi wrote:
> +
> +#include <common.h>
> +#include <init.h>
> +#include <driver.h>
> +#include <i2c/i2c.h>
> +#include <of.h>
> +#include <linux/err.h>
> +#include <linux/regmap.h>
> +#include <linux/bitfield.h>
> +#include <dt-bindings/usb/pd.h>
> +#include <asm/unaligned.h>
> +#include <linux/usb/typec.h>
> +#include <linux/usb/typec_altmode.h>
> +#include <linux/mutex.h>
> +#include <command.h>
> +#include <getopt.h>
> +#include <usb/stusb4500.h>
Please trim the inclusions. At least common.h, command.h and getopt.h
shouldn't be needed here.
> +
> +static int stusb4500_typec_register(struct stusb4500 *stusb,
> + struct device_node *connector)
> +{
> + stusb->cap.driver_data = stusb;
> + stusb->cap.ops = &stusb4500_typec_ops;
> + stusb->cap.of_node = connector;
> +
> + stusb->port = typec_register_port(stusb->dev, &stusb->cap);
We don't have typec_unregister_port() in barebox. This means you will
have a dangling port registered when you error out from probe after this
point.
Either add typec_unregister_port() and call it if you error out with a
registered port, or re-order the probe order to call
typec_register_port() as last step.
> +
> +static int stusb4500_probe(struct device *dev)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + struct regmap_config config = {
> + .reg_bits = STUSB4500_REGSIZE,
> + .val_bits = STUSB4500_REGSIZE,
> + .max_register = STUSB4500_RDO_REG_STATUS + 3,
> + };
Should be const.
> + struct stusb4500_contract contract = {};
> + struct stusb4500 *stusb;
> + int ret;
> +
> + stusb = xzalloc(sizeof(*stusb));
> + stusb->dev = dev;
> +
> + ret = stusb4500_register(stusb);
> + if (ret)
> + goto err_free;
The probe order is strange, you register with the framework before
initializing the register map. Should be the other way round.
> +
> + stusb->map = regmap_init_i2c(client, &config);
> + if (IS_ERR(stusb->map)) {
> + ret = PTR_ERR(stusb->map);
> + goto err_free;
> + }
> +
> + ret = stusb4500_init(stusb);
> + if (ret)
> + goto err_regmap;
> +
> + dev->priv = stusb;
> +
> + ret = stusb4500_update_sink_pdos(stusb);
> + if (ret)
> + goto err_regmap;
> +
> + if (of_property_read_bool(dev->of_node, "st,renegotiate-on-probe")) {
> + ret = stusb4500_renegotiate(stusb);
> + if (ret < 0)
> + goto err_regmap;
> + }
> +
> + ret = stusb4500_read_contract(stusb, &contract);
> + if (ret)
> + goto err_regmap;
The data returned in &contract is not used. What is this call good for?
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list