[U-Boot] [PATCH V2 1/2] usb: ohci: ohci-da8xx: Enable da850-ohci driver with DM support

Marek Vasut marex at denx.de
Tue Apr 30 11:39:20 UTC 2019


On 4/30/19 12:21 PM, Adam Ford wrote:
[..]

> +#if CONFIG_IS_ENABLED(DM_USB)
> +static int ohci_da8xx_probe(struct udevice *dev)
> +{
> +	struct ohci_regs *regs = (struct ohci_regs *)devfdt_get_addr(dev);
> +	struct da8xx_ohci *priv = dev_get_priv(dev);
> +	int i, err, ret, clock_nb;
> +
> +	err = 0;
> +	priv->clock_count = 0;
> +	clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells");
> +	if (clock_nb > 0) {

What happens if clock_nb == -ENOENT ?

I think what you want here is

if (clock_nb < 0) {
	...
	return clock_nb;
}

if (clock_nb > 0) {
	...
}

> +		priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
> +					    GFP_KERNEL);
> +		if (!priv->clocks)
> +			return -ENOMEM;
> +
> +		for (i = 0; i < clock_nb; i++) {
> +			err = clk_get_by_index(dev, i, &priv->clocks[i]);
> +			if (err < 0)
> +				break;
> +
> +			err = clk_enable(&priv->clocks[i]);
> +			if (err) {
> +				dev_err(dev, "failed to enable clock %d\n", i);
> +				clk_free(&priv->clocks[i]);
> +				goto clk_err;
> +			}
> +			priv->clock_count++;
> +		}
> +	} else if (clock_nb != -ENOENT) {
> +		dev_err(dev, "failed to get clock phandle(%d)\n", clock_nb);
> +		return clock_nb;
> +	}
> +
> +	err = usb_cpu_init();
> +
> +	if (err)
> +		goto clk_err;
> +
> +	err = ohci_register(dev, regs);
> +	if (err)
> +		goto phy_err;
> +
> +	return 0;
> +
> +phy_err:
> +	ret = usb_cpu_stop();
> +	if (ret)
> +		dev_err(dev, "failed to shutdown usb phy\n");
> +
> +clk_err:
> +	ret = clk_release_all(priv->clocks, priv->clock_count);
> +	if (ret)
> +		dev_err(dev, "failed to disable all clocks\n");
> +
> +	return err;
> +}
> +
> +static int ohci_da8xx_remove(struct udevice *dev)
> +{
> +	struct da8xx_ohci *priv = dev_get_priv(dev);
> +	int ret;
> +
> +	ret = ohci_deregister(dev);
> +	if (ret)
> +		return ret;
> +
> +	ret = usb_cpu_stop();
> +	if (ret)
> +		return ret;
> +
> +	return clk_release_all(priv->clocks, priv->clock_count);
> +}
> +
> +static const struct udevice_id da8xx_ohci_ids[] = {
> +	{ .compatible = "ti,da830-ohci" },
> +	{ }
> +};
> +
> +U_BOOT_DRIVER(ohci_generic) = {
> +	.name	= "ohci-da8xx",
> +	.id	= UCLASS_USB,
> +	.of_match = da8xx_ohci_ids,
> +	.probe = ohci_da8xx_probe,
> +	.remove = ohci_da8xx_remove,

Add DM_FLAG_OS_PREPARE for this to work IIRC.

> +	.ops	= &ohci_usb_ops,
> +	.priv_auto_alloc_size = sizeof(struct da8xx_ohci),
> +	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
> +};
> +#endif
> 


-- 
Best regards,
Marek Vasut


More information about the U-Boot mailing list