[PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY

Vinod Koul vkoul at kernel.org
Thu Jan 15 04:05:48 PST 2026


On 15-01-26, 14:42, Jiayu Du wrote:

> +static struct phy *k230_usb_phy_xlate(struct device *dev,
> +				      const struct of_phandle_args *args)
> +{
> +	struct k230_usb_phy_global *global = dev_get_drvdata(dev);
> +	struct k230_usb_phy_instance *phy_inst;
> +	struct phy *phy;
> +
> +	if (args->args[0] >= MAX_PHYS)
> +		return ERR_PTR(-EINVAL);
> +
> +	phy_inst = devm_kzalloc(dev, sizeof(*phy_inst), GFP_KERNEL);
> +	if (!phy_inst)
> +		return ERR_PTR(-ENOMEM);
> +
> +	phy_inst->global = global;
> +	phy_inst->index = args->args[0];
> +
> +	phy = devm_phy_create(dev, NULL, &k230_usb_phy_ops);
> +	if (IS_ERR(phy))
> +		return ERR_PTR(PTR_ERR(phy));
> +
> +	phy_set_drvdata(phy, phy_inst);

This seems wrong place, why is this not done in the driver probe?

> +
> +	return phy;
> +}
> +
> +static int k230_usb_phy_probe(struct platform_device *pdev)
> +{
> +	struct k230_usb_phy_global *global;
> +	struct device *dev = &pdev->dev;
> +	struct phy_provider *provider;
> +
> +	global = devm_kzalloc(dev, sizeof(*global), GFP_KERNEL);
> +	if (!global)
> +		return -ENOMEM;
> +	dev_set_drvdata(dev, global);
> +
> +	global->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(global->base))
> +		return dev_err_probe(dev, PTR_ERR(global->base),
> +				     "ioremap failed\n");
> +
> +	global->reg_test_offset[0] = 0x70;
> +	global->reg_ctl_offset[0] = 0xb0;
> +	global->reg_test_offset[1] = 0x90;
> +	global->reg_ctl_offset[1] = 0xb8;

Where are these magic values coming from?

-- 
~Vinod



More information about the linux-riscv mailing list