Some dsi panels require the dsi lanes keeping low before panel power
on. So seperate the panel power control and the communication with panel.
And put the power control in drm_panel_prepare_power and
drm_panel_unprepare_power. Put the communication with panel in
drm_panel_prepare and drm_panel_unprepare.
Signed-off-by: Jitao Shi <[email protected]>
---
drivers/gpu/drm/bridge/panel.c | 17 +++++++++++++++
drivers/gpu/drm/drm_panel.c | 38 ++++++++++++++++++++++++++++++++++
include/drm/drm_bridge.h | 2 ++
include/drm/drm_panel.h | 17 +++++++++++++++
4 files changed, 74 insertions(+)
diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c
index 0ddc37551194..a19c96e710fc 100644
--- a/drivers/gpu/drm/bridge/panel.c
+++ b/drivers/gpu/drm/bridge/panel.c
@@ -125,6 +125,23 @@ static int panel_bridge_get_modes(struct drm_bridge *bridge,
return drm_panel_get_modes(panel_bridge->panel, connector);
}
+int panel_bridge_prepare_power(struct drm_bridge *bridge)
+{
+ struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
+
+ return drm_panel_prepare_power(panel_bridge->panel);
+}
+EXPORT_SYMBOL(panel_bridge_prepare_power);
+
+int panel_bridge_unprepare_power(struct drm_bridge *bridge)
+{
+ struct panel_bridge *panel_bridge = drm_bridge_to_panel_bridge(bridge);
+
+ return drm_panel_unprepare_power(panel_bridge->panel);
+}
+EXPORT_SYMBOL(panel_bridge_unprepare_power);
+
+
static const struct drm_bridge_funcs panel_bridge_bridge_funcs = {
.attach = panel_bridge_attach,
.detach = panel_bridge_detach,
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index f634371c717a..7bb5185db17d 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -115,6 +115,24 @@ int drm_panel_prepare(struct drm_panel *panel)
}
EXPORT_SYMBOL(drm_panel_prepare);
+/**
+ * drm_panel_prepare_power - power on a panel's power
+ * @panel: DRM panel
+ *
+ * Calling this function will enable power and deassert any reset signals to
+ * the panel.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int drm_panel_prepare_power(struct drm_panel *panel)
+{
+ if (panel && panel->funcs && panel->funcs->prepare_power)
+ return panel->funcs->prepare_power(panel);
+
+ return panel ? -ENOSYS : -EINVAL;
+}
+EXPORT_SYMBOL(drm_panel_prepare_power);
+
/**
* drm_panel_unprepare - power off a panel
* @panel: DRM panel
@@ -138,6 +156,26 @@ int drm_panel_unprepare(struct drm_panel *panel)
}
EXPORT_SYMBOL(drm_panel_unprepare);
+/**
+ * drm_panel_unprepare_power - power off a panel
+ * @panel: DRM panel
+ *
+ * Calling this function will completely power off a panel (assert the panel's
+ * reset, turn off power supplies, ...). After this function has completed, it
+ * is usually no longer possible to communicate with the panel until another
+ * call to drm_panel_prepare_power and drm_panel_prepare().
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int drm_panel_unprepare_power(struct drm_panel *panel)
+{
+ if (panel && panel->funcs && panel->funcs->unprepare_power)
+ return panel->funcs->unprepare_power(panel);
+
+ return panel ? -ENOSYS : -EINVAL;
+}
+EXPORT_SYMBOL(drm_panel_unprepare_power);
+
/**
* drm_panel_enable - enable a panel
* @panel: DRM panel
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index 2195daa289d2..cc94c9da47d8 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -892,6 +892,8 @@ struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
struct drm_panel *panel,
u32 connector_type);
struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
+int panel_bridge_prepare_power(struct drm_bridge *bridge);
+int panel_bridge_unprepare_power(struct drm_bridge *bridge);
#endif
#endif
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index 33605c3f0eba..48e83712ad44 100644
--- a/include/drm/drm_panel.h
+++ b/include/drm/drm_panel.h
@@ -68,6 +68,13 @@ enum drm_panel_orientation;
* functionality to enable/disable backlight.
*/
struct drm_panel_funcs {
+ /**
+ * @prepare_power:
+ *
+ * Turn on panel power.
+ */
+ int (*prepare_power)(struct drm_panel *panel);
+
/**
* @prepare:
*
@@ -115,6 +122,13 @@ struct drm_panel_funcs {
int (*get_modes)(struct drm_panel *panel,
struct drm_connector *connector);
+ /**
+ * @unprepare_power:
+ *
+ * Turn off panel_power.
+ */
+ int (*unprepare_power)(struct drm_panel *panel);
+
/**
* @get_timings:
*
@@ -180,6 +194,9 @@ void drm_panel_init(struct drm_panel *panel, struct device *dev,
void drm_panel_add(struct drm_panel *panel);
void drm_panel_remove(struct drm_panel *panel);
+int drm_panel_prepare_power(struct drm_panel *panel);
+int drm_panel_unprepare_power(struct drm_panel *panel);
+
int drm_panel_prepare(struct drm_panel *panel);
int drm_panel_unprepare(struct drm_panel *panel);
--
2.25.1
Add the drm_panel_prepare_power and drm_panel_unprepare_power control.
Turn on panel power(drm_panel_prepare_power) and control before dsi
enable. And then dsi enable, send dcs cmd in drm_panel_prepare, last
turn on backlight.
Signed-off-by: Jitao Shi <[email protected]>
---
drivers/gpu/drm/mediatek/mtk_dsi.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
index a1ff152ef468..455fe582c6b5 100644
--- a/drivers/gpu/drm/mediatek/mtk_dsi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
@@ -615,10 +615,13 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
dsi->data_rate = DIV_ROUND_UP_ULL(dsi->vm.pixelclock * bit_per_pixel,
dsi->lanes);
+ if (panel_bridge_prepare_power(dsi->next_bridge))
+ DRM_INFO("can't prepare power the panel\n");
+
ret = clk_set_rate(dsi->hs_clk, dsi->data_rate);
if (ret < 0) {
dev_err(dev, "Failed to set data rate: %d\n", ret);
- goto err_refcount;
+ goto err_prepare_power;
}
phy_power_on(dsi->phy);
@@ -661,7 +664,9 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
clk_disable_unprepare(dsi->engine_clk);
err_phy_power_off:
phy_power_off(dsi->phy);
-err_refcount:
+err_prepare_power:
+ if (panel_bridge_unprepare_power(dsi->next_bridge))
+ DRM_INFO("Can't unprepare power the panel\n");
dsi->refcount--;
return ret;
}
@@ -694,6 +699,9 @@ static void mtk_dsi_poweroff(struct mtk_dsi *dsi)
clk_disable_unprepare(dsi->digital_clk);
phy_power_off(dsi->phy);
+
+ if (panel_bridge_unprepare_power(dsi->next_bridge))
+ DRM_INFO("Can't unprepare power the panel\n");
}
static void mtk_output_dsi_enable(struct mtk_dsi *dsi)
--
2.25.1
Hi, Jitao:
Jitao Shi <[email protected]> 於 2021年4月20日 週二 下午9:26寫道:
>
> Add the drm_panel_prepare_power and drm_panel_unprepare_power control.
> Turn on panel power(drm_panel_prepare_power) and control before dsi
> enable. And then dsi enable, send dcs cmd in drm_panel_prepare, last
> turn on backlight.
Please describe WHY do you need this patch? Fix any bug?
>
> Signed-off-by: Jitao Shi <[email protected]>
> ---
> drivers/gpu/drm/mediatek/mtk_dsi.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index a1ff152ef468..455fe582c6b5 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> @@ -615,10 +615,13 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
> dsi->data_rate = DIV_ROUND_UP_ULL(dsi->vm.pixelclock * bit_per_pixel,
> dsi->lanes);
>
> + if (panel_bridge_prepare_power(dsi->next_bridge))
ret = panel_bridge_prepare_power(dsi->next_bridge);
if (ret)
> + DRM_INFO("can't prepare power the panel\n");
I think you should goto err_refcount;
> +
> ret = clk_set_rate(dsi->hs_clk, dsi->data_rate);
> if (ret < 0) {
> dev_err(dev, "Failed to set data rate: %d\n", ret);
> - goto err_refcount;
> + goto err_prepare_power;
> }
>
> phy_power_on(dsi->phy);
> @@ -661,7 +664,9 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
> clk_disable_unprepare(dsi->engine_clk);
> err_phy_power_off:
> phy_power_off(dsi->phy);
> -err_refcount:
> +err_prepare_power:
> + if (panel_bridge_unprepare_power(dsi->next_bridge))
ret = panel_bridge_unprepare_power(dsi->next_bridge);
> + DRM_INFO("Can't unprepare power the panel\n");
> dsi->refcount--;
> return ret;
> }
> @@ -694,6 +699,9 @@ static void mtk_dsi_poweroff(struct mtk_dsi *dsi)
> clk_disable_unprepare(dsi->digital_clk);
>
> phy_power_off(dsi->phy);
> +
> + if (panel_bridge_unprepare_power(dsi->next_bridge))
ret = panel_bridge_unprepare_power(dsi->next_bridge);
> + DRM_INFO("Can't unprepare power the panel\n");
> }
>
> static void mtk_output_dsi_enable(struct mtk_dsi *dsi)
> --
> 2.25.1
> _______________________________________________
> dri-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
On Sat, 2021-04-24 at 00:36 +0800, Chun-Kuang Hu wrote:
> Hi, Jitao:
>
> Jitao Shi <[email protected]> 於 2021年4月20日 週二 下午9:26寫道:
> >
> > Add the drm_panel_prepare_power and drm_panel_unprepare_power control.
> > Turn on panel power(drm_panel_prepare_power) and control before dsi
> > enable. And then dsi enable, send dcs cmd in drm_panel_prepare, last
> > turn on backlight.
>
> Please describe WHY do you need this patch? Fix any bug?
Most panels, have five steps when poweron.
1. turn on dsi signal to LP11 --> dsi host's action
2. turn on the power supplies, --> panel's action
3. send the DCS cmd to panel --> panel's action
4. start send video stream --> dsi host's action
5. turn on backlight. --> panel's action
we put "turn on the power supplies" and "send the DCS cmd to panel" in
panel_prepare. And "turn on backlight" in panel_enable.
But some other panels has a special poweron sequence as the following.
1. turn on the power supplies, --> panel's action
2. turn on dsi signal to LP11 --> dsi host's action
3. send the DCS cmd to panel --> panel's action
4. start send video stream --> dsi host's action
5. turn on backlight. --> panel's action
panel's actions are divided into three parts.
So I add a new api "drm_panel_prepare_power/rm_panel_unprepare_power" to
control the sequence.
Best Regards
Jitao
>
> >
> > Signed-off-by: Jitao Shi <[email protected]>
> > ---
> > drivers/gpu/drm/mediatek/mtk_dsi.c | 12 ++++++++++--
> > 1 file changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> > index a1ff152ef468..455fe582c6b5 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> > @@ -615,10 +615,13 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
> > dsi->data_rate = DIV_ROUND_UP_ULL(dsi->vm.pixelclock * bit_per_pixel,
> > dsi->lanes);
> >
> > + if (panel_bridge_prepare_power(dsi->next_bridge))
>
> ret = panel_bridge_prepare_power(dsi->next_bridge);
> if (ret)
>
> > + DRM_INFO("can't prepare power the panel\n");
>
> I think you should goto err_refcount;
Thanks for your review. I'll fix it next patch.
>
> > +
> > ret = clk_set_rate(dsi->hs_clk, dsi->data_rate);
> > if (ret < 0) {
> > dev_err(dev, "Failed to set data rate: %d\n", ret);
> > - goto err_refcount;
> > + goto err_prepare_power;
> > }
> >
> > phy_power_on(dsi->phy);
> > @@ -661,7 +664,9 @@ static int mtk_dsi_poweron(struct mtk_dsi *dsi)
> > clk_disable_unprepare(dsi->engine_clk);
> > err_phy_power_off:
> > phy_power_off(dsi->phy);
> > -err_refcount:
> > +err_prepare_power:
> > + if (panel_bridge_unprepare_power(dsi->next_bridge))
>
> ret = panel_bridge_unprepare_power(dsi->next_bridge);
>
> > + DRM_INFO("Can't unprepare power the panel\n");
> > dsi->refcount--;
> > return ret;
> > }
> > @@ -694,6 +699,9 @@ static void mtk_dsi_poweroff(struct mtk_dsi *dsi)
> > clk_disable_unprepare(dsi->digital_clk);
> >
> > phy_power_off(dsi->phy);
> > +
> > + if (panel_bridge_unprepare_power(dsi->next_bridge))
>
> ret = panel_bridge_unprepare_power(dsi->next_bridge);
>
> > + DRM_INFO("Can't unprepare power the panel\n");
> > }
> >
> > static void mtk_output_dsi_enable(struct mtk_dsi *dsi)
> > --
> > 2.25.1
> > _______________________________________________
> > dri-devel mailing list
> > [email protected]
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel