Re: [PATCH v5 10/13] power: supply: mt6370: Add MediaTek MT6370 charger driver
From: Andy Shevchenko <hidden>
Date: 2022-07-15 16:52:11
Also in:
dri-devel, linux-arm-kernel, linux-devicetree, linux-iio, linux-leds, linux-mediatek, linux-pm, linux-usb, lkml
On Fri, Jul 15, 2022 at 1:29 PM ChiaEn Wu [off-list ref] wrote:
From: ChiaEn Wu <redacted> MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards. This adds MediaTek MT6370 Charger driver support. The charger module of MT6370 supports High-Accuracy Voltage/Current Regulation, Average Input Current Regulation, Battery Temperature Sensing, Over-Temperature Protection, DPDM Detection for BC1.2.
...
+static int mt6370_chg_probe(struct platform_device *pdev)
+{
+ int ret;
+ struct mt6370_priv *priv;
+
+ priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->dev = &pdev->dev;
+
+ priv->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+ if (!priv->regmap)
+ return dev_err_probe(&pdev->dev, -ENODEV,
+ "Failed to get regmap\n");
+
+ ret = mt6370_chg_init_rmap_fields(priv);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to init regmap fields\n");
+
+ platform_set_drvdata(pdev, priv);
+
+ priv->iio_adcs = devm_iio_channel_get_all(priv->dev);
+ if (IS_ERR(priv->iio_adcs))
+ return dev_err_probe(&pdev->dev, PTR_ERR(priv->iio_adcs),
+ "Failed to get iio adc\n");
+
+ ret = mt6370_chg_init_otg_regulator(priv);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret,
+ "Failed to init otg regulator\n");
+
+ ret = mt6370_chg_init_psy(priv);
+ if (ret)
+ return dev_err_probe(&pdev->dev, ret, "Failed to init psy\n");
+
+ mutex_init(&priv->attach_lock);
+ priv->attach = MT6370_ATTACH_STAT_DETACH;
+
+ priv->wq = create_singlethread_workqueue(dev_name(priv->dev));
+ if (IS_ERR(priv->wq))+ return dev_err_probe(priv->dev, PTR_ERR(priv->wq), + "Failed to create workqueue\n");
You need either wrap mutex to be deallocated by devm or don't use dev_err_probe() here.
+ INIT_WORK(&priv->bc12_work, mt6370_chg_bc12_work_func);
+ INIT_DELAYED_WORK(&priv->mivr_dwork, mt6370_chg_mivr_dwork_func);
+
+ ret = mt6370_chg_init_setting(priv);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to init mt6370 charger setting\n");
+ goto probe_out;
+ }
+
+ ret = mt6370_chg_init_irq(priv);
+ if (ret)
+ goto probe_out;
+
+ mt6370_chg_pwr_rdy_check(priv);
+
+ return 0;
+
+probe_out:
+ cancel_delayed_work_sync(&priv->mivr_dwork);
+ flush_workqueue(priv->wq);
+ destroy_workqueue(priv->wq);
+ mutex_destroy(&priv->attach_lock);
+
+ return ret;
+}
+
+static int mt6370_chg_remove(struct platform_device *pdev)
+{
+ struct mt6370_priv *priv = platform_get_drvdata(pdev);
+
+ cancel_delayed_work_sync(&priv->mivr_dwork);
+ flush_workqueue(priv->wq);
+ destroy_workqueue(priv->wq);
+ mutex_destroy(&priv->attach_lock);
+
+ return 0;
+}-- With Best Regards, Andy Shevchenko