On 07/23/2014 09:51 AM, Thierry Reding wrote: > On Tue, Jul 22, 2014 at 11:33:11AM +0200, Andrzej Hajda wrote: >> On 07/22/2014 10:12 AM, Thierry Reding wrote: >>> On Tue, Jul 22, 2014 at 09:32:58AM +0200, Andrzej Hajda wrote: >>>> On 07/22/2014 09:12 AM, Thierry Reding wrote: >>>>> From: Thierry Reding <treding at nvidia.com> >>>>> >>>>> Currently the mipi_dsi_dcs_write() function requires the DCS command >>>>> byte to be embedded within the write buffer whereas mipi_dsi_dcs_read() >>>>> has a separate parameter. Make them more symmetrical by adding an extra >>>>> command parameter to mipi_dsi_dcs_write(). >>>>> >>>>> Also update the S6E8AA0 panel driver (the only user of this API) to >>>>> adapt to this new API. >>>> I do not agree with that. DCS read and write are not symmetrical by design: >>>> - write just sends data, >>>> - read sends data then reads response. >>>> >>>> Forcing API to be symmetrical complicates the implementation without real >>>> gain. >>> Why does it complicate anything? >> >> Why? Lets see: >> >> drivers/gpu/drm/drm_mipi_dsi.c | 45 >> ++++++++++++++++++++++++----------- >> drivers/gpu/drm/panel/panel-s6e8aa0.c | 4 ++-- >> include/drm/drm_mipi_dsi.h | 4 ++-- >> 3 files changed, 35 insertions(+), 18 deletions(-) >> >> >> Original function has two vars, one 'if', one 'switch' and one operation >> call, nothing more. >> You proposes to add new vars, kmalloc with no memory handling, memcpy, >> playing with indices, conditional kfree. Isn't it enough to call it more >> complicated? :) > > It certainly makes the implementation of mipi_dsi_dcs_write() slightly > more complicated, but the point is that it makes it easier for users of > the API. So the complexity moves into one central location rather than > each call site. Ultimately that will reduce overall complexity.
I guess it will increase complexity. If you look at the s6e8aa0 or any other driver using DCS commands you will see the most DCS commands have constant arguments, so driver uses small static arrays without copying them to temporary variables. With your approach every time you will have to allocate tiny memory bufs, memcpy to them and deallocate them later. I terms of drivers code simplicity, current version with proposed macros do better job. > >>> Granted we need to dynamically allocate >>> a buffer for each transfer, but it's all hidden away in a common helper >>> function. The big advantage in using a separate parameter for the >>> command is that it makes it trivial to implement the majority of DCS >>> commands, like this: >>> >>> const u8 format = 0x77; >>> const u8 mode = 0x00; >>> >>> mipi_dsi_dcs_write(dsi, MIPI_DCS_SOFT_RESET, NULL, 0); >>> mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, &format, 1); >>> mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, &mode, 1); >>> mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON, NULL, 0); >> >> For this I have proposed once more universal macro, sth like this: >> >> #define mipi_dsi_dcs_write_seq(dsi, seq...) \ >> ({\ >> const u8 d[] = { seq };\ >> BUILD_BUG_ON_MSG(ARRAY_SIZE(d) > 64, "DCS sequence too big for stack");\ >> mipi_dsi_dcs_write(dsi, d, ARRAY_SIZE(d));\ >> }) >> >> It makes trivial to implement ALL DCS commands in much more readable manner. >> Please compare with your examples above: >> mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_SOFT_RESET); >> mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_PIXEL_FORMAT, 0x77); >> mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_TEAR_ON, 0); >> mipi_dsi_dcs_write(dsi, MIPI_DCS_SET_DISPLAY_ON); >> >> It could be also accompanied by static version, for memory optimization: >> >> #define mipi_dsi_dcs_write_seq_static(dsi, seq...) \ >> ({\ >> static const u8 d[] = { seq };\ >> mipi_dsi_dcs_write(dsi, d, ARRAY_SIZE(d));\ >> }) > > I've said before why I dislike these macros. One alternative for the > above would be to add something like a mipi_dsi_dcs_writev() function > that takes a variable list of arguments, Few greps in sources shows kernel prefers variadic macros over variadic functions. Few examples: #define or51132_writebytes(state, data...) #define sn9c102_write_const_regs(sn9c102_device, data...) #define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...) #define media_entity_call(entity, operation, args...) #define call_memop(vb, op, args...) #define __pcpu_size_call(stem, variable, ...) #define rsnd_platform_call(priv, dai, func, param...) #define send_seq(priv, data...) > somewhat like this: > > ssize_t mipi_dsi_dcs_writev(struct mipi_dsi_device *dsi, u8 command, > unsigned int count, ...) > { > ... > } > > And the above would become: > > mipi_dsi_dcs_writev(dsi, MIPI_DCS_SOFT_RESET, 0); > mipi_dsi_dcs_writev(dsi, MIPI_DCS_SET_PIXEL_FORMAT, 1, 0x77); > ... > > That's still one argument more, but at least it isn't a macro. > > Thierry > >> >> >>> >>> Without the extra parameter, the above becomes: >>> >>> const u8 data[1] = { MIPI_DCS_SOFT_RESET }; >>> mipi_dsi_dcs_write(dsi, data, sizeof(data)); >>> >>> const u8 data[2] = { MIPI_DCS_SET_PIXEL_FORMAT, 0x77 }; >>> mipi_dsi_dcs_write(dsi, data, sizeof(data)); >>> >>> const u8 data[2] = { MIPI_DCS_SET_TEAR_ON, 0x00 }; >>> mipi_dsi_dcs_write(dsi, data, sizeof(data)); >>> >>> const u8 data[1] = { MIPI_DCS_SET_DISPLAY_ON }; >>> mipi_dsi_dcs_write(dsi, data, sizeof(data)); >>> >>> In this form it looks still rather readable, but if you need to do this >>> within an initialization function, it become fairly cluttered: >>> >>> const u8 soft_reset[1] = { MIPI_DCS_SOFT_RESET }; >>> const u8 set_pixel_format[2] = { MIPI_DCS_SET_PIXEL_FORMAT, 0x77 }; >>> const u8 set_tear_on[2] = { MIPI_DCS_SET_TEAR_ON, 0x00 }; >>> const u8 set_display_on[1] = { MIPI_DCS_SET_DISPLAY_ON }; >>> >>> mipi_dsi_dcs_write(dsi, soft_reset, sizeof(soft_reset)); >>> >>> mipi_dsi_dcs_write(dsi, set_pixel_format, sizeof(set_pixel_format)); >>> >>> mipi_dsi_dcs_write(dsi, set_tear_on, sizeof(set_tear_on)); >>> >>> mipi_dsi_dcs_write(dsi, set_display_on, sizeof(set_display_on)); >>> >>> I find that really hard to read because it has a potentially large gap >>> between the place where the commands are defined and where they're used. >> >> You will have the same gap issue with your approach in case of DCS >> commands with arguments. > > But it's at least reduced to only the payload. The actual command will > still be there on the same line as the function call. You don't have to > search for some array and inspect the array to find out which command is > being sent. > >> With 'my' approach it is still readable. > > Until you mess up the arguments and have to deal with the not-so- > readable errors from the compiler. This is simple macro, it is rather hard to mess with arguments, additionally both arguments are type checked directly(seq) on indirectly(dsi). > >>> Some of this could possibly be alleviated by adding separate functions >>> for standard commands. But either way, I think having this kind of >>> symmetry within an API is always good (it's consistent). By the law of >>> least surprise people will actually expect mipi_dsi_dcs_write() to take >>> a command as a second parameter. >> >> As I wrote earlier I do not see symmetry here: dcs-read is in fact write >> and read, >> dcs-write is just write. Hiding this fact in API does not seems to me >> good, but I guess >> it is rather matter of taste. > > The symmetry isn't about the physical transfers. It's a logical > symmetry. Each DCS command is identified by a command, whether it's a > read or a write. If you insist on it maybe it will be better to leave my version of mipi_dsi_dcs_write, maybe renamed to mipi_dsi_dcs_write_buf or sth similar and add your version using internally my version. This way you will have your symmetry and I will keep my simplicity :) > > There's a similar dissymmetry in how the payload length is handled. > Currently peripheral drivers need to encode that within the payload > buffer, and DSI host drivers need to parse it out of that depending on > the type of write. That makes it needlessly difficult for host drivers > and I think the interface would be much easier to use if peripheral > drivers specified the payload (and its length) only and let drivers > obtain the length of writes from the .tx_len field. I am not sure if I understand correctly. Where the peripherals encodes payload length in payload buffer? > > Thierry > > > > _______________________________________________ > dri-devel mailing list > dri-devel at lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/dri-devel >