Re: [PATCH v2 2/3] drm/stm: dsi: add support of an optional regulator

From: Philippe CORNU
Date: Mon May 13 2019 - 07:23:37 EST


Hi Yannick,


On 5/10/19 6:16 PM, Philippe Cornu wrote:
> Dear Yannick,
> Thank you for your patch,
>
> I like better the new shorter commit heading, thank you.
>
>
> On 5/10/19 4:20 PM, Yannick Fertrà wrote:
>> Add support of an optional regulator for the phy part of the DSI
>> controller.
>>
>> Signed-off-by: Yannick Fertrà <yannick.fertre@xxxxxx>
>> ---
>> Â drivers/gpu/drm/stm/dw_mipi_dsi-stm.c | 45
>> ++++++++++++++++++++++++++++++-----
>> Â 1 file changed, 39 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
>> b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
>> index 1bef73e..22bd095 100644
>> --- a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
>> +++ b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
>> @@ -9,6 +9,7 @@
>> Â #include <linux/clk.h>
>> Â #include <linux/iopoll.h>
>> Â #include <linux/module.h>
>> +#include <linux/regulator/consumer.h>
>> Â #include <drm/drmP.h>
>> Â #include <drm/drm_mipi_dsi.h>
>> Â #include <drm/bridge/dw_mipi_dsi.h>
>> @@ -76,6 +77,7 @@ struct dw_mipi_dsi_stm {
>> ÂÂÂÂÂ u32 hw_version;
>> ÂÂÂÂÂ int lane_min_kbps;
>> ÂÂÂÂÂ int lane_max_kbps;
>> +ÂÂÂ struct regulator *vdd_supply;
>> Â };
>> Â static inline void dsi_write(struct dw_mipi_dsi_stm *dsi, u32 reg,
>> u32 val)
>> @@ -318,17 +320,31 @@ static int dw_mipi_dsi_stm_probe(struct
>> platform_device *pdev)
>> ÂÂÂÂÂÂÂÂÂ return PTR_ERR(dsi->base);
>> ÂÂÂÂÂ }
>> +ÂÂÂ dsi->vdd_supply = devm_regulator_get_optional(dev, "phy-dsi");
>> +ÂÂÂ if (IS_ERR(dsi->vdd_supply)) {
>> +ÂÂÂÂÂÂÂ ret = PTR_ERR(dsi->vdd_supply);
>> +ÂÂÂÂÂÂÂ if (ret != -EPROBE_DEFER)
>> +ÂÂÂÂÂÂÂÂÂÂÂ DRM_ERROR("failed to request regulator: %d\n", ret);
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }


I did more tests on a stm32f469 disco board and this above code does not
work (the ret value is -ENODEV)

Two possibilities then:
1) remove the _optional (but we have the "using dummy regulator"
message, I am fine with it)

or
2) handle -ENODEV but do not forget to check vdd_supply!=NULL before
calling all regulator_(enable/disable)

if (ret != -ENODEV) {
if (ret != -EPROBE_DEFER)
DRM_ERROR("failed to request regulator: %d\n",
ret);
return ret;
}
dsi->vdd_supply = NULL;
}

if (dsi->vdd_supply) {
ret = regulator_enable(dsi->vdd_supply);
...


if (dsi->vdd_supply)
regulator_disable(dsi->vdd_supply);


I let you choose your favorite one.

Thank you,
Philippe

>> +
>> +ÂÂÂ ret = regulator_enable(dsi->vdd_supply);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ DRM_ERROR("failed to enable regulator: %d\n", ret);
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> ÂÂÂÂÂ dsi->pllref_clk = devm_clk_get(dev, "ref");
>> ÂÂÂÂÂ if (IS_ERR(dsi->pllref_clk)) {
>> ÂÂÂÂÂÂÂÂÂ ret = PTR_ERR(dsi->pllref_clk);
>> -ÂÂÂÂÂÂÂ dev_err(dev, "Unable to get pll reference clock: %d\n", ret);
>> -ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ DRM_ERROR("Unable to get pll reference clock: %d\n", ret);
>> +ÂÂÂÂÂÂÂ goto err_clk_get;
>> ÂÂÂÂÂ }
>> ÂÂÂÂÂ ret = clk_prepare_enable(dsi->pllref_clk);
>> ÂÂÂÂÂ if (ret) {
>> -ÂÂÂÂÂÂÂ dev_err(dev, "%s: Failed to enable pllref_clk\n", __func__);
>> -ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂÂÂÂÂ DRM_ERROR("%s: Failed to enable pllref_clk\n", __func__);
>> +ÂÂÂÂÂÂÂ goto err_clk_get;
>> ÂÂÂÂÂ }
>> ÂÂÂÂÂ dw_mipi_dsi_stm_plat_data.base = dsi->base;
>> @@ -339,11 +355,19 @@ static int dw_mipi_dsi_stm_probe(struct
>> platform_device *pdev)
>> ÂÂÂÂÂ dsi->dsi = dw_mipi_dsi_probe(pdev, &dw_mipi_dsi_stm_plat_data);
>> ÂÂÂÂÂ if (IS_ERR(dsi->dsi)) {
>> ÂÂÂÂÂÂÂÂÂ DRM_ERROR("Failed to initialize mipi dsi host\n");
>> -ÂÂÂÂÂÂÂ clk_disable_unprepare(dsi->pllref_clk);
>> -ÂÂÂÂÂÂÂ return PTR_ERR(dsi->dsi);
>> +ÂÂÂÂÂÂÂ ret = PTR_ERR(dsi->dsi);
>> +ÂÂÂÂÂÂÂ goto err_dsi_probe;
>> ÂÂÂÂÂ }
>> ÂÂÂÂÂ return 0;
>> +
>> +err_dsi_probe:
>> +ÂÂÂ clk_disable_unprepare(dsi->pllref_clk);
>> +err_clk_get:
>> +ÂÂÂ regulator_disable(dsi->vdd_supply);
>> +
>> +ÂÂÂ return ret;
>> +
>> Â }
>> Â static int dw_mipi_dsi_stm_remove(struct platform_device *pdev)
>> @@ -351,6 +375,7 @@ static int dw_mipi_dsi_stm_remove(struct
>> platform_device *pdev)
>> ÂÂÂÂÂ struct dw_mipi_dsi_stm *dsi = platform_get_drvdata(pdev);
>> ÂÂÂÂÂ clk_disable_unprepare(dsi->pllref_clk);
>> +ÂÂÂ regulator_disable(dsi->vdd_supply);
>> ÂÂÂÂÂ dw_mipi_dsi_remove(dsi->dsi);
>
> for a future patch: we may have a different order
> ÂÂÂÂdw_mipi_dsi_remove(dsi->dsi);
> ÂÂÂÂclk_disable_unprepare(dsi->pllref_clk);
> ÂÂÂÂregulator_disable(dsi->vdd_supply);
>
>> ÂÂÂÂÂ return 0;
>> @@ -363,6 +388,7 @@ static int __maybe_unused
>> dw_mipi_dsi_stm_suspend(struct device *dev)
>> ÂÂÂÂÂ DRM_DEBUG_DRIVER("\n");
>> ÂÂÂÂÂ clk_disable_unprepare(dsi->pllref_clk);
>> +ÂÂÂ regulator_disable(dsi->vdd_supply);
>> ÂÂÂÂÂ return 0;
>> Â }
>> @@ -370,9 +396,16 @@ static int __maybe_unused
>> dw_mipi_dsi_stm_suspend(struct device *dev)
>> Â static int __maybe_unudw_mipi_dsi_remove(dsi->dsi);sed
>> dw_mipi_dsi_stm_resume(struct device *dev)
>> Â {
>> ÂÂÂÂÂ struct dw_mipi_dsi_stm *dsi = dw_mipi_dsi_stm_plat_data.priv_data;
>> +ÂÂÂ int ret;
>> ÂÂÂÂÂ DRM_DEBUG_DRIVER("\n");
>> +ÂÂÂ ret = regulator_enable(dsi->vdd_supply);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ DRM_ERROR("failed to enable regulator: %d\n", ret);
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> ÂÂÂÂÂ clk_prepare_enable(dsi->pllref_clk);
>
> for a future patch: we may check clk_prepare_enable return value.
>
>> ÂÂÂÂÂ return 0;
>>
>
>
> Acked-by: Philippe Cornu <philippe.cornu@xxxxxx>
>
> Philippe :)
>