[PATCH v5 08/13] usb: typec: tcpci_mt6370: Add MediaTek MT6370 tcpci driver
ChiYuan Huang
u0084500 at gmail.com
Mon Jul 18 01:08:35 PDT 2022
On Fri, Jul 15, 2022 at 03:10:42PM +0200, Andy Shevchenko wrote:
> On Fri, Jul 15, 2022 at 1:28 PM ChiaEn Wu <peterwu.pub at gmail.com> wrote:
>
> > The MT6370 is a highly-integrated smart power management IC, which
> > includes a single cell Li-Ion/Li-Polymer switching battery charger,
> > a USB Type-C & Power Delivery (PD) controller, dual Flash LED current
> > sources, a RGB LED driver, a backlight WLED driver, a display bias
> > driver and a general LDO for portable devices.
> >
> > This commit add support for the Type-C & Power Delivery controller in
>
> This commit add -> Add
>
Upper case? Or rewrite it as 'This commit is to add .....'?
>
> > MediaTek MT6370 IC.
>
>
> > +static int mt6370_tcpc_probe(struct platform_device *pdev)
> > +{
> > + struct mt6370_priv *priv;
> > + struct device *dev = &pdev->dev;
> > + int ret;
> > +
> > + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> > + if (!priv)
> > + return -ENOMEM;
> > +
> > + priv->dev = dev;
> > + platform_set_drvdata(pdev, priv);
> > +
> > + priv->tcpci_data.regmap = dev_get_regmap(dev->parent, NULL);
> > + if (!priv->tcpci_data.regmap)
> > + return dev_err_probe(dev, -ENODEV, "Failed to init regmap\n");
> > +
> > + ret = mt6370_check_vendor_info(priv);
> > + if (ret)
> > + return ret;
> > +
> > + priv->irq = platform_get_irq(pdev, 0);
> > + if (priv->irq < 0)
> > + return priv->irq;
> > +
> > + /* Assign TCPCI feature and ops */
> > + priv->tcpci_data.auto_discharge_disconnect = 1;
> > + priv->tcpci_data.init = mt6370_tcpc_init;
> > + priv->tcpci_data.set_vconn = mt6370_tcpc_set_vconn;
> > +
> > + priv->vbus = devm_regulator_get_optional(dev, "vbus");
> > + if (!IS_ERR(priv->vbus))
> > + priv->tcpci_data.set_vbus = mt6370_tcpc_set_vbus;
> > +
> > + priv->tcpci = tcpci_register_port(dev, &priv->tcpci_data);
> > + if (IS_ERR(priv->tcpci))
> > + return dev_err_probe(dev, PTR_ERR(priv->tcpci),
> > + "Failed to register tcpci port\n");
> > +
> > + ret = devm_request_threaded_irq(dev, priv->irq, NULL,
> > + mt6370_irq_handler, IRQF_ONESHOT,
> > + dev_name(dev), priv);
> > + if (ret) {
>
> > + tcpci_unregister_port(priv->tcpci);
>
> This is wrong.
> You mixed devm_ with non-devm. Either drop devm_ *after* the first
> non-devm_ call, or convert everything to be managed.
>
How about to add 'devm_add_action_or_reset' for tcpci_unregister_port?
This will convert all as 'devm_' version.
> > + return dev_err_probe(dev, ret, "Failed to allocate irq\n");
> > + }
> > +
> > + device_init_wakeup(dev, true);
> > + dev_pm_set_wake_irq(dev, priv->irq);
> > +
> > + return 0;
> > +}
> > +
> > +static int mt6370_tcpc_remove(struct platform_device *pdev)
> > +{
> > + struct mt6370_priv *priv = platform_get_drvdata(pdev);
>
> > + disable_irq(priv->irq);
>
> Why?
> An ugly workaround due to ordering issues in ->probe()?
>
Yes, due to the ordering in probe.
'bus remove' will be called before device resource releases.
Like as you said, another way is to convert all as non-devm
version after 'tcpci_unregister_port'.
If to keep the original order, 'disable_irq' before
'tcpci_unregister_port' can make the flow more safe.
Or you can think one case if irq triggers after
'tcpci_unregister_port'. Null pointer occurs.
Anyway, in next revision, I'll convert all to be 'devm_' version.
For this remove callback, only 'dev_pm_clear_wake_irq' and
'device_init_wakeup' will be kept.
Is this better?
> > + tcpci_unregister_port(priv->tcpci);
> > + dev_pm_clear_wake_irq(&pdev->dev);
> > + device_init_wakeup(&pdev->dev, false);
> > +
> > + return 0;
> > +}
>
> --
> With Best Regards,
> Andy Shevchenko
More information about the Linux-mediatek
mailing list