drm/mipi-dsi: Add a mipi_dual_dsi_dcs_write_seq() macro
Subsystems (2)
PATCH 1/1 drm/mipi-dsi: Add a mipi_dual_dsi_dcs_write_seq() macro
The panels with two dsi connected (sync dual dsi mode) need to transmit dcs command to the two dsi host simultaneously, let's add mipi_dual_dsi_dcs_write_seq() macro for this kind of panels.
--- include/drm/drm_mipi_dsi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
include/drm/drm_mipi_dsi.h +15 -0
@@ -336,6 +336,21 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, } \ }while (0 ) +/** +* mipi_dsi_dcs_write_seq - transmit a DCS command with payload +* @dsi: array of 2 DSI peripheral devices +* @cmd: Command +* @seq: buffer containing data to be transmitted +*/ +#define mipi_dual_dsi_dcs_write_seq(dsi, cmd, seq...) \ +do { \ +if (ARRAY_SIZE (dsi) >2 ) \ +return -EINVAL ; \ +int i; \ +for (i =0 ; i <ARRAY_SIZE (dsi); i++) \ +mipi_dsi_dcs_write_seq (dsi[i], cmd, seq); \ + }while (0 ) +/** * struct mipi_dsi_driver - DSI driver * @driver: device driver model driver
Signature · 1 line
2.39.2
Quoted 3 lines · Jianhua Lu
The panels with two dsi connected (sync dual dsi mode) need to transmit dcs command to the two dsi host simultaneously, let's add
mipi_dual_dsi_dcs_write_seq()macro for this kind of panels.
If we were to add a helper for this case, it should be a proper function and not a macro like this.
We'd also need to see a user for this upstream.
Quoted 11 lines
Signed-off-by Jianhua Lu <[email protected]>--- include/drm/drm_mipi_dsi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)include/drm/drm_mipi_dsi.h +0
-0
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 341
Quoted 6 lines
include/drm/drm_mipi_dsi.h +3
-0@@ -336,6 +336,21 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, } \ }while (0 ) +/** +* mipi_dsi_dcs_write_seq - transmit a DCS command with payload +* @dsi: array of 2 DSI peripheral devices
This makes the assumption the devices are stored in an array. What if drivers want to store them differently, for whatever reason? Maybe they have an array of some container structs that have the devices? Maybe they just have two struct mipi_dsi_device pointers?
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 349
Quoted 8 lines
include/drm/drm_mipi_dsi.h +8
-0+* @cmd: Command +* @seq: buffer containing data to be transmitted +*/ +#define mipi_dual_dsi_dcs_write_seq(dsi, cmd, seq...) \ + do { \ + if (ARRAY_SIZE(dsi) > 2) \ + return -EINVAL; \ + int i; \
I believe this should lead to a warning for mixing code and declarations.
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 351
Quoted 2 lines
include/drm/drm_mipi_dsi.h +2
-0+for (i =0 ; i <ARRAY_SIZE (dsi); i++) \ +mipi_dsi_dcs_write_seq (dsi[i], cmd, seq); \
This ignores errors.
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 353
Quoted 2 lines
include/drm/drm_mipi_dsi.h +2
-0+ }while (0 ) +
Without an example user, I'm not yet convinced about the usefulness of the helper, but I'd imagine something like this would be a more generic approach, not enforcing the array, and handling errors properly:
ssize_t mipi_dsi_dual_dcs_write(struct mipi_dsi_device *dsi0,
struct mipi_dsi_device *dsi1, u8 cmd, const void *data, size_t len)
{
ssize_t err = 0;
if (dsi0)
err = mipi_dsi_dcs_write(dsi0, cmd, data, len);
if (dsi1 && !err)
err = mipi_dsi_dcs_write(dsi1, cmd, data, len);
return err;
}But even that begs the question where does it end? There are a lot of mipi_dsi_dcs_*() functions as well as mipi_dsi_generic_write(). Dual wrappers for all of them? :o
BR,
Jani.
Quoted 3 lines
include/drm/drm_mipi_dsi.h +0
-0/** * struct mipi_dsi_driver - DSI driver * @driver: device driver model driver
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Quoted 24 lines · Jani Nikula
Quoted 3 lines · Jianhua Lu
The panels with two dsi connected (sync dual dsi mode) need to transmit dcs command to the two dsi host simultaneously, let's add
mipi_dual_dsi_dcs_write_seq()macro for this kind of panels.If we were to add a helper for this case, it should be a proper function and not a macro like this.
We'd also need to see a user for this upstream.
Quoted 14 lines
Signed-off-by Jianhua Lu <[email protected]>--- include/drm/drm_mipi_dsi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)include/drm/drm_mipi_dsi.h +0
-0@@ -336,6 +336,21 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, } \ }while (0 )
Quoted 8 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 341
Quoted 3 lines
include/drm/drm_mipi_dsi.h +3
-0+/** +* mipi_dsi_dcs_write_seq - transmit a DCS command with payload +* @dsi: array of 2 DSI peripheral devices This makes the assumption the devices are stored in an array. What if drivers want to store them differently, for whatever reason? Maybe they have an array of some container structs that have the devices? Maybe they just have two struct
mipi_dsi_devicepointers?
This array just store two struct mipi_dsi_device pointers
Quoted 13 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 349
Quoted 9 lines
include/drm/drm_mipi_dsi.h +8
-0+* @cmd: Command +* @seq: buffer containing data to be transmitted +*/ +#define mipi_dual_dsi_dcs_write_seq(dsi, cmd, seq...) \ + do { \ + if (ARRAY_SIZE(dsi) > 2) \ + return -EINVAL; \ + int i; \I believe this should lead to a warning for mixing code and declarations.
Quoted 4 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 351
Quoted 2 lines
include/drm/drm_mipi_dsi.h +2
-0+for (i =0 ; i <ARRAY_SIZE (dsi); i++) \ +mipi_dsi_dcs_write_seq (dsi[i], cmd, seq); \This ignores errors.
mipi_dsi_dcs_write_seq is also a macro, contains error checks in the body block.
Quoted 11 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 353
Quoted 3 lines
include/drm/drm_mipi_dsi.h +2
-0+ }while (0 ) +Without an example user, I'm not yet convinced about the usefulness of the helper, but I'd imagine something like this would be a more generic approach, not enforcing the array, and handling errors properly:
ssize_tmipi_dsi_dual_dcs_write(structmipi_dsi_device*dsi0,
structmipi_dsi_device*dsi1, u8 cmd, const void *data,size_tlen)
Quoted 11 lines
{
ssize_t err = 0;
if (dsi0)
err = mipi_dsi_dcs_write(dsi0, cmd, data, len);
if (dsi1 && !err)
err = mipi_dsi_dcs_write(dsi1, cmd, data, len);
return err;
}Thanks for your explanation and this looks more reasonable.
Quoted 4 lines
But even that begs the question where does it end? There are a lot of mipi_dsi_dcs_*() functions as well as
mipi_dsi_generic_write(). Dual wrappers for all of them? :o
It's definitly useless to wrap all of them. Please ignore this patch.
Quoted 12 lines
BR,
Jani.Quoted 3 lines
include/drm/drm_mipi_dsi.h +0
-0/** * struct mipi_dsi_driver - DSI driver * @driver: device driver model driver Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Quoted 47 lines · Jianhua Lu
Quoted 24 lines · Jani Nikula
Quoted 3 lines · Jianhua Lu
The panels with two dsi connected (sync dual dsi mode) need to transmit dcs command to the two dsi host simultaneously, let's add
mipi_dual_dsi_dcs_write_seq()macro for this kind of panels.If we were to add a helper for this case, it should be a proper function and not a macro like this.
We'd also need to see a user for this upstream.
Quoted 14 lines
Signed-off-by Jianhua Lu <[email protected]>--- include/drm/drm_mipi_dsi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)include/drm/drm_mipi_dsi.h +0
-0@@ -336,6 +336,21 @@ int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, } \ }while (0 )Quoted 8 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 341
Quoted 3 lines
include/drm/drm_mipi_dsi.h +3
-0+/** +* mipi_dsi_dcs_write_seq - transmit a DCS command with payload +* @dsi: array of 2 DSI peripheral devices This makes the assumption the devices are stored in an array. What if drivers want to store them differently, for whatever reason? Maybe they have an array of some container structs that have the devices? Maybe they just have two struct
mipi_dsi_devicepointers?This array just store two struct
mipi_dsi_devicepointersQuoted 13 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 349
Quoted 9 lines
include/drm/drm_mipi_dsi.h +8
-0+* @cmd: Command +* @seq: buffer containing data to be transmitted +*/ +#define mipi_dual_dsi_dcs_write_seq(dsi, cmd, seq...) \ + do { \ + if (ARRAY_SIZE(dsi) > 2) \ + return -EINVAL; \ + int i; \I believe this should lead to a warning for mixing code and declarations.
Quoted 5 lines
Quoted 4 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 351
Quoted 2 lines
include/drm/drm_mipi_dsi.h +2
-0+for (i =0 ; i <ARRAY_SIZE (dsi); i++) \ +mipi_dsi_dcs_write_seq (dsi[i], cmd, seq); \This ignores errors.
mipi_dsi_dcs_write_seqis also a macro, contains error checks in the body block.
Ugh, I think it's pretty scary to hide control flow like return statements in macros like this.
IMO the the main user of mipi_dsi_dcs_write_seq()
i.e. panel_nv3051d_init_sequence() in drivers/gpu/drm/panel/panel-newvision-nv3051d.c should be written to do the writes from an array in a loop instead.
BR,
Jani.
Quoted 40 lines
Quoted 11 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 353
Quoted 3 lines
include/drm/drm_mipi_dsi.h +2
-0+ }while (0 ) +Without an example user, I'm not yet convinced about the usefulness of the helper, but I'd imagine something like this would be a more generic approach, not enforcing the array, and handling errors properly:
ssize_tmipi_dsi_dual_dcs_write(structmipi_dsi_device*dsi0,
structmipi_dsi_device*dsi1, u8 cmd, const void *data,size_tlen)Quoted 11 lines
{ ssize_t err = 0; if (dsi0) err = mipi_dsi_dcs_write(dsi0, cmd, data, len); if (dsi1 && !err) err = mipi_dsi_dcs_write(dsi1, cmd, data, len); return err; }Thanks for your explanation and this looks more reasonable.
Quoted 4 lines
But even that begs the question where does it end? There are a lot of mipi_dsi_dcs_*() functions as well as
mipi_dsi_generic_write(). Dual wrappers for all of them? :oIt's definitly useless to wrap all of them. Please ignore this patch.
Quoted 12 lines
BR,
Jani.Quoted 3 lines
include/drm/drm_mipi_dsi.h +0
-0/** * struct mipi_dsi_driver - DSI driver * @driver: device driver model driver Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
(CC Javier)
Quoted 8 lines · Jani Nikula
Quoted 5 lines
Quoted 4 lines
include/drm/drm_mipi_dsi.h int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi, · line 351
Quoted 2 lines
include/drm/drm_mipi_dsi.h +2
-0+for (i =0 ; i <ARRAY_SIZE (dsi); i++) \ +mipi_dsi_dcs_write_seq (dsi[i], cmd, seq); \This ignores errors.
mipi_dsi_dcs_write_seqis also a macro, contains error checks in the body block.Ugh, I think it's pretty scary to hide control flow like return statements in macros like this.
The macros are written like this because:
#define mipi_dsi_generic_write_seq(dsi, seq...)
(...)
static const u8 d[] = { seq };Array of bytes
ret = mipi_dsi_generic_write(dsi, d, ARRAY_SIZE(d));
So we can use use ARRAY_SIZE() in the macro and pass in any arbitrary sequence, e.g.
mipi_dsi_generic_write_seq(dsi, 0xfb, 0x01);
Any function-esque definitions will (as in your example) require a length to be passed in so it would become:
mipi_dsi_generic_write_seq(dsi, 0xfb, 0x01, 2);
And if you grep mipi_dsi_generic_write_seq | wc -l you find all the 245 opportunities to get that last len wrong and cause an out-of-bounds bug.
I think this macro is the lesser evil for this reason, also it saves code that you otherwise have to do manually, and one should never put a person to do a machine's job.
Any suggestions to rewrite the macro using varargs welcome. I think it is not very easy to do without the preprocessor.
Yours,
Linus Walleij