diff mbox series

drm/panel: db7430: Improve error reporting

Message ID 20210630191301.3664478-1-linus.walleij@linaro.org
State New
Headers show
Series drm/panel: db7430: Improve error reporting | expand

Commit Message

Linus Walleij June 30, 2021, 7:13 p.m. UTC
This creates a macro wrapping mipi_dbi_command() such that we get
some explicit error reporting if something goes wrong.

Cc: Noralf Trønnes <noralf@tronnes.org>
Suggested-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/gpu/drm/panel/panel-samsung-db7430.c | 66 +++++++++++---------
 1 file changed, 36 insertions(+), 30 deletions(-)

-- 
2.31.1

Comments

Noralf Trønnes June 30, 2021, 7:46 p.m. UTC | #1
Den 30.06.2021 21.13, skrev Linus Walleij:
> This creates a macro wrapping mipi_dbi_command() such that we get

> some explicit error reporting if something goes wrong.

> 

> Cc: Noralf Trønnes <noralf@tronnes.org>

> Suggested-by: Douglas Anderson <dianders@chromium.org>

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

> ---

>  drivers/gpu/drm/panel/panel-samsung-db7430.c | 66 +++++++++++---------

>  1 file changed, 36 insertions(+), 30 deletions(-)

> 

> diff --git a/drivers/gpu/drm/panel/panel-samsung-db7430.c b/drivers/gpu/drm/panel/panel-samsung-db7430.c

> index fe58263bd9cd..c42d43ab6a4f 100644

> --- a/drivers/gpu/drm/panel/panel-samsung-db7430.c

> +++ b/drivers/gpu/drm/panel/panel-samsung-db7430.c

> @@ -90,9 +90,17 @@ static inline struct db7430 *to_db7430(struct drm_panel *panel)

>  	return container_of(panel, struct db7430, panel);

>  }

>  

> +#define db7430_command(db, cmd, seq...) \

> +({ \

> +	struct mipi_dbi *dbi = &db->dbi;	\

> +	int ret;				\

> +	ret = mipi_dbi_command(dbi, cmd, seq);  \

> +	if (ret)							\

> +		dev_err(db->dev, "failure in writing command %#02x\n", cmd); \

> +})

> +


I did a grep and there's only one mipi_dbi_command() caller that checks
the return code: mipi_dbi_poweron_reset_conditional().

Can you add the error reporting to mipi_dbi_command() instead? Instead
of drivers adding their own similar macros.

In that case I think you need to add a plain 'ret' at the end of the
macro for it to return the error code.

Noralf.
Noralf Trønnes June 30, 2021, 7:58 p.m. UTC | #2
Den 30.06.2021 21.46, skrev Noralf Trønnes:
> 

> 

> Den 30.06.2021 21.13, skrev Linus Walleij:

>> This creates a macro wrapping mipi_dbi_command() such that we get

>> some explicit error reporting if something goes wrong.

>>

>> Cc: Noralf Trønnes <noralf@tronnes.org>

>> Suggested-by: Douglas Anderson <dianders@chromium.org>

>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

>> ---

>>  drivers/gpu/drm/panel/panel-samsung-db7430.c | 66 +++++++++++---------

>>  1 file changed, 36 insertions(+), 30 deletions(-)

>>

>> diff --git a/drivers/gpu/drm/panel/panel-samsung-db7430.c b/drivers/gpu/drm/panel/panel-samsung-db7430.c

>> index fe58263bd9cd..c42d43ab6a4f 100644

>> --- a/drivers/gpu/drm/panel/panel-samsung-db7430.c

>> +++ b/drivers/gpu/drm/panel/panel-samsung-db7430.c

>> @@ -90,9 +90,17 @@ static inline struct db7430 *to_db7430(struct drm_panel *panel)

>>  	return container_of(panel, struct db7430, panel);

>>  }

>>  

>> +#define db7430_command(db, cmd, seq...) \

>> +({ \

>> +	struct mipi_dbi *dbi = &db->dbi;	\

>> +	int ret;				\

>> +	ret = mipi_dbi_command(dbi, cmd, seq);  \

>> +	if (ret)							\

>> +		dev_err(db->dev, "failure in writing command %#02x\n", cmd); \

>> +})

>> +

> 

> I did a grep and there's only one mipi_dbi_command() caller that checks

> the return code: mipi_dbi_poweron_reset_conditional().

> 

> Can you add the error reporting to mipi_dbi_command() instead? Instead

> of drivers adding their own similar macros.

> 

> In that case I think you need to add a plain 'ret' at the end of the

> macro for it to return the error code.

> 


I think the error reporting needs to ratelimited if added to
mipi_dbi_command() because worst case a blinking fbcon cursor will
trigger 10 errors a second for the framebuffer drivers.

Noralf.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/panel/panel-samsung-db7430.c b/drivers/gpu/drm/panel/panel-samsung-db7430.c
index fe58263bd9cd..c42d43ab6a4f 100644
--- a/drivers/gpu/drm/panel/panel-samsung-db7430.c
+++ b/drivers/gpu/drm/panel/panel-samsung-db7430.c
@@ -90,9 +90,17 @@  static inline struct db7430 *to_db7430(struct drm_panel *panel)
 	return container_of(panel, struct db7430, panel);
 }
 
+#define db7430_command(db, cmd, seq...) \
+({ \
+	struct mipi_dbi *dbi = &db->dbi;	\
+	int ret;				\
+	ret = mipi_dbi_command(dbi, cmd, seq);  \
+	if (ret)							\
+		dev_err(db->dev, "failure in writing command %#02x\n", cmd); \
+})
+
 static int db7430_power_on(struct db7430 *db)
 {
-	struct mipi_dbi *dbi = &db->dbi;
 	int ret;
 
 	/* Power up */
@@ -119,48 +127,48 @@  static int db7430_power_on(struct db7430 *db)
 	 * normal output behaviour is horizontally flipped and BGR ordered. Do
 	 * it twice because the first message doesn't always "take".
 	 */
-	mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, 0x0a);
-	mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, 0x0a);
-	mipi_dbi_command(dbi, DB7430_ACCESS_PROT_OFF, 0x00);
-	mipi_dbi_command(dbi, DB7430_PANEL_DRIVING, 0x28, 0x08);
-	mipi_dbi_command(dbi, DB7430_SOURCE_CONTROL,
+	db7430_command(db, MIPI_DCS_SET_ADDRESS_MODE, 0x0a);
+	db7430_command(db, MIPI_DCS_SET_ADDRESS_MODE, 0x0a);
+	db7430_command(db, DB7430_ACCESS_PROT_OFF, 0x00);
+	db7430_command(db, DB7430_PANEL_DRIVING, 0x28, 0x08);
+	db7430_command(db, DB7430_SOURCE_CONTROL,
 			 0x01, 0x30, 0x15, 0x05, 0x22);
-	mipi_dbi_command(dbi, DB7430_GATE_INTERFACE,
+	db7430_command(db, DB7430_GATE_INTERFACE,
 			 0x10, 0x01, 0x00);
-	mipi_dbi_command(dbi, DB7430_DISPLAY_H_TIMING,
+	db7430_command(db, DB7430_DISPLAY_H_TIMING,
 			 0x06, 0x55, 0x03, 0x07, 0x0b,
 			 0x33, 0x00, 0x01, 0x03);
 	/*
 	 * 0x00 in datasheet 0x01 in vendor code 0x00, it seems 0x01 means
 	 * DE active high and 0x00 means DE active low.
 	 */
-	mipi_dbi_command(dbi, DB7430_RGB_SYNC_OPTION, 0x01);
-	mipi_dbi_command(dbi, DB7430_GAMMA_SET_RED,
+	db7430_command(db, DB7430_RGB_SYNC_OPTION, 0x01);
+	db7430_command(db, DB7430_GAMMA_SET_RED,
 		/* R positive gamma */ 0x00,
 		0x0A, 0x31, 0x3B, 0x4E, 0x58, 0x59, 0x5B, 0x58, 0x5E, 0x62,
 		0x60, 0x61, 0x5E, 0x62, 0x55, 0x55, 0x7F, 0x08,
 		/* R negative gamma */ 0x00,
 		0x0A, 0x31, 0x3B, 0x4E, 0x58, 0x59, 0x5B, 0x58, 0x5E, 0x62,
 		0x60, 0x61, 0x5E, 0x62, 0x55, 0x55, 0x7F, 0x08);
-	mipi_dbi_command(dbi, DB7430_GAMMA_SET_GREEN,
+	db7430_command(db, DB7430_GAMMA_SET_GREEN,
 		/* G positive gamma */ 0x00,
 		0x25, 0x15, 0x28, 0x3D, 0x4A, 0x48, 0x4C, 0x4A, 0x52, 0x59,
 		0x59, 0x5B, 0x56, 0x60, 0x5D, 0x55, 0x7F, 0x0A,
 		/* G negative gamma */ 0x00,
 		0x25, 0x15, 0x28, 0x3D, 0x4A, 0x48, 0x4C, 0x4A, 0x52, 0x59,
 		0x59, 0x5B, 0x56, 0x60, 0x5D, 0x55, 0x7F, 0x0A);
-	mipi_dbi_command(dbi, DB7430_GAMMA_SET_BLUE,
+	db7430_command(db, DB7430_GAMMA_SET_BLUE,
 		/* B positive gamma */ 0x00,
 		0x48, 0x10, 0x1F, 0x2F, 0x35, 0x38, 0x3D, 0x3C, 0x45, 0x4D,
 		0x4E, 0x52, 0x51, 0x60, 0x7F, 0x7E, 0x7F, 0x0C,
 		/* B negative gamma */ 0x00,
 		0x48, 0x10, 0x1F, 0x2F, 0x35, 0x38, 0x3D, 0x3C, 0x45, 0x4D,
 		0x4E, 0x52, 0x51, 0x60, 0x7F, 0x7E, 0x7F, 0x0C);
-	mipi_dbi_command(dbi, DB7430_BIAS_CURRENT_CTRL, 0x33, 0x13);
-	mipi_dbi_command(dbi, DB7430_DDV_CTRL, 0x11, 0x00, 0x00);
-	mipi_dbi_command(dbi, DB7430_GAMMA_CTRL_REF, 0x50, 0x50);
-	mipi_dbi_command(dbi, DB7430_DCDC_CTRL, 0x2f, 0x11, 0x1e, 0x46);
-	mipi_dbi_command(dbi, DB7430_VCL_CTRL, 0x11, 0x0a);
+	db7430_command(db, DB7430_BIAS_CURRENT_CTRL, 0x33, 0x13);
+	db7430_command(db, DB7430_DDV_CTRL, 0x11, 0x00, 0x00);
+	db7430_command(db, DB7430_GAMMA_CTRL_REF, 0x50, 0x50);
+	db7430_command(db, DB7430_DCDC_CTRL, 0x2f, 0x11, 0x1e, 0x46);
+	db7430_command(db, DB7430_VCL_CTRL, 0x11, 0x0a);
 
 	return 0;
 }
@@ -181,11 +189,10 @@  static int db7430_unprepare(struct drm_panel *panel)
 static int db7430_disable(struct drm_panel *panel)
 {
 	struct db7430 *db = to_db7430(panel);
-	struct mipi_dbi *dbi = &db->dbi;
 
-	mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_OFF);
+	db7430_command(db, MIPI_DCS_SET_DISPLAY_OFF);
 	msleep(25);
-	mipi_dbi_command(dbi, MIPI_DCS_ENTER_SLEEP_MODE);
+	db7430_command(db, MIPI_DCS_ENTER_SLEEP_MODE);
 	msleep(120);
 
 	return 0;
@@ -199,26 +206,25 @@  static int db7430_prepare(struct drm_panel *panel)
 static int db7430_enable(struct drm_panel *panel)
 {
 	struct db7430 *db = to_db7430(panel);
-	struct mipi_dbi *dbi = &db->dbi;
 
 	/* Exit sleep mode */
-	mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE);
+	db7430_command(db, MIPI_DCS_EXIT_SLEEP_MODE);
 	msleep(20);
 
 	/* NVM (non-volatile memory) load sequence */
-	mipi_dbi_command(dbi, DB7430_UNKNOWN_D4, 0x52, 0x5e);
-	mipi_dbi_command(dbi, DB7430_UNKNOWN_F8, 0x01, 0xf5, 0xf2, 0x71, 0x44);
-	mipi_dbi_command(dbi, DB7430_UNKNOWN_FC, 0x00, 0x08);
+	db7430_command(db, DB7430_UNKNOWN_D4, 0x52, 0x5e);
+	db7430_command(db, DB7430_UNKNOWN_F8, 0x01, 0xf5, 0xf2, 0x71, 0x44);
+	db7430_command(db, DB7430_UNKNOWN_FC, 0x00, 0x08);
 	msleep(150);
 
 	/* CABC turn on sequence (BC = backlight control) */
-	mipi_dbi_command(dbi, DB7430_UNKNOWN_B4, 0x0f, 0x00, 0x50);
-	mipi_dbi_command(dbi, DB7430_USER_SELECT, 0x80);
-	mipi_dbi_command(dbi, DB7430_UNKNOWN_B7, 0x24);
-	mipi_dbi_command(dbi, DB7430_UNKNOWN_B8, 0x01);
+	db7430_command(db, DB7430_UNKNOWN_B4, 0x0f, 0x00, 0x50);
+	db7430_command(db, DB7430_USER_SELECT, 0x80);
+	db7430_command(db, DB7430_UNKNOWN_B7, 0x24);
+	db7430_command(db, DB7430_UNKNOWN_B8, 0x01);
 
 	/* Turn on display */
-	mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
+	db7430_command(db, MIPI_DCS_SET_DISPLAY_ON);
 
 	return 0;
 }