[PATCH v5 08/13] usb: typec: tcpci_mt6370: Add MediaTek MT6370 tcpci driver
Andy Shevchenko
andy.shevchenko at gmail.com
Fri Jul 15 06:10:42 PDT 2022
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
> 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.
> + 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()?
> + 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