Message ID | 20220314141643.22184-9-u.kleine-koenig@pengutronix.de (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | clk: provide new devm helpers for prepared and enabled clocks | expand |
On 14/03/2022 15:16, Uwe Kleine-König wrote: > devm_clk_get_enabled() returns a clock prepared and enabled and already > registers a devm exit handler to disable (and unprepare) the clock. > > There is slight change in behavior as a failure to enable the clock > now results in an error message, too. Also the actual error code is added > to the message. > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> > --- > drivers/gpu/drm/meson/meson_dw_hdmi.c | 48 +++++++++------------------ > 1 file changed, 16 insertions(+), 32 deletions(-) > > diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c b/drivers/gpu/drm/meson/meson_dw_hdmi.c > index 5cd2b2ebbbd3..6034e80c5b2e 100644 > --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c > +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c > @@ -670,29 +670,6 @@ static void meson_disable_regulator(void *data) > regulator_disable(data); > } > > -static void meson_disable_clk(void *data) > -{ > - clk_disable_unprepare(data); > -} > - > -static int meson_enable_clk(struct device *dev, char *name) > -{ > - struct clk *clk; > - int ret; > - > - clk = devm_clk_get(dev, name); > - if (IS_ERR(clk)) { > - dev_err(dev, "Unable to get %s pclk\n", name); > - return PTR_ERR(clk); > - } > - > - ret = clk_prepare_enable(clk); > - if (!ret) > - ret = devm_add_action_or_reset(dev, meson_disable_clk, clk); > - > - return ret; > -} > - > static int meson_dw_hdmi_bind(struct device *dev, struct device *master, > void *data) > { > @@ -702,6 +679,7 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, > struct drm_device *drm = data; > struct meson_drm *priv = drm->dev_private; > struct dw_hdmi_plat_data *dw_plat_data; > + struct clk *clk; > int irq; > int ret; > > @@ -763,17 +741,23 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, > if (IS_ERR(meson_dw_hdmi->hdmitx)) > return PTR_ERR(meson_dw_hdmi->hdmitx); > > - ret = meson_enable_clk(dev, "isfr"); > - if (ret) > - return ret; > + clk = devm_clk_get_enabled(dev, "isfr"); > + if (IS_ERR(clk)) { > + dev_err(dev, "Failed to get enabled isfr pclk (%pe)\n", clk); > + return PTR_ERR(clk); > + } > > - ret = meson_enable_clk(dev, "iahb"); > - if (ret) > - return ret; > + clk = devm_clk_get_enabled(dev, "iahb"); > + if (IS_ERR(clk)) { > + dev_err(dev, "Failed to get enabled iahb pclk (%pe)\n", clk); > + return PTR_ERR(clk); > + } > > - ret = meson_enable_clk(dev, "venci"); > - if (ret) > - return ret; > + clk = devm_clk_get_enabled(dev, "venci"); > + if (IS_ERR(clk)) { > + dev_err(dev, "Failed to get enabled venci pclk (%pe)\n", clk); > + return PTR_ERR(clk); > + } > > dw_plat_data->regm = devm_regmap_init(dev, NULL, meson_dw_hdmi, > &meson_dw_hdmi_regmap_config); Acked-by: Neil Armstrong <narmstrong@baylibre.com>
diff --git a/drivers/gpu/drm/meson/meson_dw_hdmi.c b/drivers/gpu/drm/meson/meson_dw_hdmi.c index 5cd2b2ebbbd3..6034e80c5b2e 100644 --- a/drivers/gpu/drm/meson/meson_dw_hdmi.c +++ b/drivers/gpu/drm/meson/meson_dw_hdmi.c @@ -670,29 +670,6 @@ static void meson_disable_regulator(void *data) regulator_disable(data); } -static void meson_disable_clk(void *data) -{ - clk_disable_unprepare(data); -} - -static int meson_enable_clk(struct device *dev, char *name) -{ - struct clk *clk; - int ret; - - clk = devm_clk_get(dev, name); - if (IS_ERR(clk)) { - dev_err(dev, "Unable to get %s pclk\n", name); - return PTR_ERR(clk); - } - - ret = clk_prepare_enable(clk); - if (!ret) - ret = devm_add_action_or_reset(dev, meson_disable_clk, clk); - - return ret; -} - static int meson_dw_hdmi_bind(struct device *dev, struct device *master, void *data) { @@ -702,6 +679,7 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, struct drm_device *drm = data; struct meson_drm *priv = drm->dev_private; struct dw_hdmi_plat_data *dw_plat_data; + struct clk *clk; int irq; int ret; @@ -763,17 +741,23 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master, if (IS_ERR(meson_dw_hdmi->hdmitx)) return PTR_ERR(meson_dw_hdmi->hdmitx); - ret = meson_enable_clk(dev, "isfr"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "isfr"); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get enabled isfr pclk (%pe)\n", clk); + return PTR_ERR(clk); + } - ret = meson_enable_clk(dev, "iahb"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "iahb"); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get enabled iahb pclk (%pe)\n", clk); + return PTR_ERR(clk); + } - ret = meson_enable_clk(dev, "venci"); - if (ret) - return ret; + clk = devm_clk_get_enabled(dev, "venci"); + if (IS_ERR(clk)) { + dev_err(dev, "Failed to get enabled venci pclk (%pe)\n", clk); + return PTR_ERR(clk); + } dw_plat_data->regm = devm_regmap_init(dev, NULL, meson_dw_hdmi, &meson_dw_hdmi_regmap_config);
devm_clk_get_enabled() returns a clock prepared and enabled and already registers a devm exit handler to disable (and unprepare) the clock. There is slight change in behavior as a failure to enable the clock now results in an error message, too. Also the actual error code is added to the message. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/gpu/drm/meson/meson_dw_hdmi.c | 48 +++++++++------------------ 1 file changed, 16 insertions(+), 32 deletions(-)