Re: [PATCH 2/2] drm/tiny: add support for tft displays based on ilitek, ili9488

2022-10-24 Thread Thomas Zimmermann

Hi,

thanks for your driver submission.

Am 18.10.22 um 18:45 schrieb Tommaso Merciai:

This adds support for ilitek,ili9488 based displays with shift register
in front of controller. Waveshare,pico-restouch-lcd-3.5 are such displays

Signed-off-by: Tommaso Merciai 
---
  drivers/gpu/drm/tiny/Kconfig   |  13 +
  drivers/gpu/drm/tiny/Makefile  |   1 +
  drivers/gpu/drm/tiny/ili9488.c | 440 +
  3 files changed, 454 insertions(+)
  create mode 100644 drivers/gpu/drm/tiny/ili9488.c

diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig
index 027cd87c3d0d7..6e708e8414806 100644
--- a/drivers/gpu/drm/tiny/Kconfig
+++ b/drivers/gpu/drm/tiny/Kconfig
@@ -148,6 +148,19 @@ config TINYDRM_ILI9486
  
  	  If M is selected the module will be called ili9486.
  
+config TINYDRM_ILI9488

+   tristate "DRM support for ILI9488 display panels"
+   depends on DRM && SPI
+   select DRM_KMS_HELPER
+   select DRM_GEM_CMA_HELPER


This is now called DRM_GEM_DMA_HELPER and all _cma_ infixes have been 
renamed to _dma_. Please rebase onto drm-tip or drm-misc-next and you'll 
notice.


BUT I think this driver should use GEM SHMEM helpers instead (see 
DRM_GEM_SHMEM_HELPER). Nothing here needs DMA memory AFAICT.




+   select DRM_MIPI_DBI
+   select BACKLIGHT_CLASS_DEVICE
+   help
+ DRM driver for the following Ilitek ILI9488 panels:
+ * LCD 3.5" 320x480 TFT (Waveshare Pico-ResTouch-LCD-3.5")
+
+ If M is selected the module will be called ili9486.
+
  config TINYDRM_MI0283QT
tristate "DRM support for MI0283QT"
depends on DRM && SPI
diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile
index 1d9d6227e7ab7..aad6683b2ac40 100644
--- a/drivers/gpu/drm/tiny/Makefile
+++ b/drivers/gpu/drm/tiny/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_TINYDRM_ILI9163) += ili9163.o
  obj-$(CONFIG_TINYDRM_ILI9225) += ili9225.o
  obj-$(CONFIG_TINYDRM_ILI9341) += ili9341.o
  obj-$(CONFIG_TINYDRM_ILI9486) += ili9486.o
+obj-$(CONFIG_TINYDRM_ILI9488)  += ili9488.o
  obj-$(CONFIG_TINYDRM_MI0283QT)+= mi0283qt.o
  obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o
  obj-$(CONFIG_TINYDRM_ST7586)  += st7586.o
diff --git a/drivers/gpu/drm/tiny/ili9488.c b/drivers/gpu/drm/tiny/ili9488.c
new file mode 100644
index 0..b94d9d4ff4544
--- /dev/null
+++ b/drivers/gpu/drm/tiny/ili9488.c
@@ -0,0 +1,440 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * DRM driver for Ilitek ILI9488 panels
+ *
+ * Copyright 2020 Kamlesh Gurudasani 


He's also in CC. Shouldn't he have signed off the patch?


+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 


empty line here


+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 


This block has to be order alphabetically.


+
+#define ILI9488_VCOM_CONTROL_1 0xC5
+#define ILI9488_COLUMN_ADDRESS_SET 0x2A
+#define ILI9488_PAGE_ADDRESS_SET   0x2B
+#define ILI9488_MEMORY_WRITE   0x2C
+#define ILI9488_POSITIVE_GAMMA_CORRECTION  0xE0
+#define ILI9488_NEGATIVE_GAMMA_CORRECTION  0xE1
+#define ILI9488_POWER_CONTROL_10xC0
+#define ILI9488_POWER_CONTROL_20xC1
+#define ILI9488_POWER_CONTROL_30xC2
+#define ILI9488_MEM_ACCESS_CONTROL 0x36
+#define ILI9488_COLMOD_PIXEL_FORMAT_SET0x3A
+#define ILI9488_INTERFACE_MODE_CONTROL 0xB0
+#define ILI9488_FRAME_RATE_CONTROL_PARTIAL 0xB3
+#define ILI9488_DISPLAY_INVERSION_ON   0x21
+#define ILI9488_DISPLAY_INVERSION_CONTROL  0xB4
+#define ILI9488_DISPLAY_FUNCTION_CONTROL   0xB6
+#define ILI9488_ENTRY_MODE_SET 0xB7
+#define ILI9488_HS_LANES_CONTROL   0xBE
+#define ILI9488_SET_IMAGE_FUNCTION 0xE9
+#define ILI9488_ADJUST_CONTROL_3   0xF7
+#define ILI9488_DISPLAY_ON 0x29
+#define ILI9488_DISPLAY_OFF0x28
+#define ILI9488_ENTER_SLEEP_MODE   0x10
+#define ILI9488_DBI_BPP18  0x06
+#define ILI9488_DBI_BPP16  0x05
+#define ILI9488_DPI_BPP24  0x70
+#define ILI9488_DPI_BPP18  0x60
+#define ILI9488_DPI_BPP16  0x50
+#define ILI9488_FRAME_RATE_CONTROL_NORMAL  0xB1
+#define ILI9488_SLEEP_OUT  0x11
+
+#define ILI9488_MADCTL_RGB BIT(2)
+#define ILI9488_MADCTL_BGR BIT(3)
+#define ILI9488_MADCTL_MV  BIT(5)
+#define ILI9488_MADCTL_MX  BIT(6)
+#define ILI9488_MADCTL_MY  BIT(7)
+
+static void ili9488_rgb565_to_rgb666_line(u8 *dst, u16 *sbuf,
+ unsigned int pixels)
+{
+   unsigned int x;
+
+   for (x = 0; x < pixels; x++) {
+   

Re: [PATCH 2/2] drm/tiny: add support for tft displays based on ilitek, ili9488

2022-10-19 Thread Javier Martinez Canillas
Hello Tommaso,

On 10/18/22 18:45, Tommaso Merciai wrote:

[...]

> +config TINYDRM_ILI9488
> + tristate "DRM support for ILI9488 display panels"
> + depends on DRM && SPI
> + select DRM_KMS_HELPER
> + select DRM_GEM_CMA_HELPER
> + select DRM_MIPI_DBI
> + select BACKLIGHT_CLASS_DEVICE
> + help
> +   DRM driver for the following Ilitek ILI9488 panels:
> +   * LCD 3.5" 320x480 TFT (Waveshare Pico-ResTouch-LCD-3.5")
> +
> +   If M is selected the module will be called ili9486.
> +

Typo here, should be ili9488.

[...]

> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +

Please sort these alphabetically

> +
> +static void ili9488_rgb565_to_rgb666_line(u8 *dst, u16 *sbuf,
> +   unsigned int pixels)
> +{
> + unsigned int x;
> +
> + for (x = 0; x < pixels; x++) {
> + *dst++ = ((*sbuf & 0xF800) >> 8);
> + *dst++ = ((*sbuf & 0x07E0) >> 3);
> + *dst++ = ((*sbuf & 0x001F) << 3);
> + sbuf++;
> + }
> +}
> +

If these format conversions helpers are really needed, they need to be
added as helpers to drivers/gpu/drm/drm_format_helper.c instead.

> +static void ili9488_rgb565_to_rgb666(u8 *dst, void *vaddr,
> +  struct drm_framebuffer *fb,
> +  struct drm_rect *rect)
> +{
> + unsigned long linepixels = drm_rect_width(rect);
> + unsigned long lines = drm_rect_height(rect);
> + size_t dst_len = linepixels * 3;
> + size_t src_len = linepixels * fb->format->cpp[0];
> + unsigned int y;
> + u16 *sbuf;
> +
> + /*
> +  * The cma memory is write-combined so reads are uncached.
> +  * Speed up by fetching one line at a time.
> +  */
> + sbuf = kmalloc(src_len, GFP_KERNEL);
> + if (!sbuf)
> + return;

This will cause an extra copy even when CMA isn't used. Please take a look
how the format helpers do this. You should pass a struct iosys_map param
and internally use the drm_fb_xfrm() helper that would handle both the I/O
mem and system memory cases.

> +static int ili9488_buf_copy(void *dst, struct drm_framebuffer *fb,
> + struct drm_rect *rect)
> +{
> + struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
> + void *src = cma_obj->vaddr;
> + int ret = 0;
> +
> + ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
> + if (ret)
> + return ret;
> +

If you rebase on top of the "[PATCH 0/5] drm: Add new plane helpers to
begin/end FB access" series then an explicit CPU access to GEM BOs sync
isn't needed anymore:

https://lore.kernel.org/dri-devel/20221017111510.20818-1-tzimmerm...@suse.de/


> + switch (fb->format->format) {
> + case DRM_FORMAT_RGB565:
> + ili9488_rgb565_to_rgb666(dst, src, fb, rect);

This is the biggest issue I see with this driver. The exported format is
RGB565 but RGB666 is used. I believe the policy is for the driver to expose
the native format to user-space.

I know that there isn't a DRM_FORMAT_RGB666 in neither DRM nor mesa, but
still I think that adding it should be part of this series. If you also
want to expose DRM_FORMAT_RGB565 for compatibility reasons, then I guess
that's OK but as mentioned the format helpers need to be in the DRM core.

[...]

> +static void ili9488_fb_dirty(struct drm_framebuffer *fb, struct drm_rect 
> *rect)
> +{

This looks very similar, if not the same than the mipi_dbi_fb_dirty() helper.

[...]

> +static void ili9488_pipe_update(struct drm_simple_display_pipe *pipe,
> +struct drm_plane_state *old_state)
> +{

And same for this, it's basically mipi_dbi_pipe_update() if you end using the
mipi_dbi_fb_dirty() helper instead of a custom ili9488_fb_dirty() handler.

> + struct drm_plane_state *state = pipe->plane.state;
> + struct drm_rect rect;
> +
> + if (!pipe->crtc.state->active)
> + return;
> +
> + if (drm_atomic_helper_damage_merged(old_state, state, ))
> + ili9488_fb_dirty(state->fb, );

I see that most MIPI DBI drivers use this function to merge all the damage clips
into a big rectangle. Is there a reason why this is done in this way rather than
just iterating over all the damage areas and update them one by one?

Since for example there are multiple damage clips that aren't close to each 
other,
the resulting rectangle could be quite big.

[...]

> +DEFINE_DRM_GEM_CMA_FOPS(ili9488_fops);
> +

Do you really need CMA for this? Can't you just use DEFINE_DRM_GEM_FOPS() 
instead?

> +static struct drm_driver ili9488_driver = {
> + .driver_features= DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
> + .fops   = _fops,
> + DRM_GEM_CMA_DRIVER_OPS_VMAP,

DRM_GEM_SHMEM_DRIVER_OPS, ?

> + .debugfs_init   = 

Re: [PATCH 2/2] drm/tiny: add support for tft displays based on ilitek,ili9488

2022-10-19 Thread Tommaso Merciai
On Tue, Oct 18, 2022 at 08:31:22PM +0200, Michael Nazzareno Trimarchi wrote:

Hi Michael,

> Hi
> 
> On Tue, Oct 18, 2022 at 6:46 PM Tommaso Merciai
>  wrote:
> >
> > This adds support for ilitek,ili9488 based displays with shift register
> > in front of controller. Waveshare,pico-restouch-lcd-3.5 are such displays
> >
> > Signed-off-by: Tommaso Merciai 
> > ---
> 
> Because I start to make it working this driver, I think that my
> signed-off is missing here

Yes, right. :)
I upload in v2, my bad

> 
> >  drivers/gpu/drm/tiny/Kconfig   |  13 +
> >  drivers/gpu/drm/tiny/Makefile  |   1 +
> >  drivers/gpu/drm/tiny/ili9488.c | 440 +
> >  3 files changed, 454 insertions(+)
> >  create mode 100644 drivers/gpu/drm/tiny/ili9488.c
> >
> > diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig
> > index 027cd87c3d0d7..6e708e8414806 100644
> > --- a/drivers/gpu/drm/tiny/Kconfig
> > +++ b/drivers/gpu/drm/tiny/Kconfig
> > @@ -148,6 +148,19 @@ config TINYDRM_ILI9486
> >
> >   If M is selected the module will be called ili9486.
> >
> > +config TINYDRM_ILI9488
> > +   tristate "DRM support for ILI9488 display panels"
> > +   depends on DRM && SPI
> > +   select DRM_KMS_HELPER
> > +   select DRM_GEM_CMA_HELPER
> > +   select DRM_MIPI_DBI
> > +   select BACKLIGHT_CLASS_DEVICE
> > +   help
> > + DRM driver for the following Ilitek ILI9488 panels:
> > + * LCD 3.5" 320x480 TFT (Waveshare Pico-ResTouch-LCD-3.5")
> > +
> > + If M is selected the module will be called ili9486.
> > +
> >  config TINYDRM_MI0283QT
> > tristate "DRM support for MI0283QT"
> > depends on DRM && SPI
> > diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile
> > index 1d9d6227e7ab7..aad6683b2ac40 100644
> > --- a/drivers/gpu/drm/tiny/Makefile
> > +++ b/drivers/gpu/drm/tiny/Makefile
> > @@ -11,6 +11,7 @@ obj-$(CONFIG_TINYDRM_ILI9163) += ili9163.o
> >  obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
> >  obj-$(CONFIG_TINYDRM_ILI9341)  += ili9341.o
> >  obj-$(CONFIG_TINYDRM_ILI9486)  += ili9486.o
> > +obj-$(CONFIG_TINYDRM_ILI9488)  += ili9488.o
> >  obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o
> >  obj-$(CONFIG_TINYDRM_REPAPER)  += repaper.o
> >  obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
> > diff --git a/drivers/gpu/drm/tiny/ili9488.c b/drivers/gpu/drm/tiny/ili9488.c
> > new file mode 100644
> > index 0..b94d9d4ff4544
> > --- /dev/null
> > +++ b/drivers/gpu/drm/tiny/ili9488.c
> > @@ -0,0 +1,440 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * DRM driver for Ilitek ILI9488 panels
> > + *
> > + * Copyright 2020 Kamlesh Gurudasani 
> > + */
> 
> Code was changed a bit so please add copyright of me and you

Agree, thanks.

> 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define ILI9488_VCOM_CONTROL_1 0xC5
> > +#define ILI9488_COLUMN_ADDRESS_SET 0x2A
> > +#define ILI9488_PAGE_ADDRESS_SET   0x2B
> > +#define ILI9488_MEMORY_WRITE   0x2C
> > +#define ILI9488_POSITIVE_GAMMA_CORRECTION  0xE0
> > +#define ILI9488_NEGATIVE_GAMMA_CORRECTION  0xE1
> > +#define ILI9488_POWER_CONTROL_10xC0
> > +#define ILI9488_POWER_CONTROL_20xC1
> > +#define ILI9488_POWER_CONTROL_30xC2
> > +#define ILI9488_MEM_ACCESS_CONTROL 0x36
> > +#define ILI9488_COLMOD_PIXEL_FORMAT_SET0x3A
> > +#define ILI9488_INTERFACE_MODE_CONTROL 0xB0
> > +#define ILI9488_FRAME_RATE_CONTROL_PARTIAL 0xB3
> > +#define ILI9488_DISPLAY_INVERSION_ON   0x21
> > +#define ILI9488_DISPLAY_INVERSION_CONTROL  0xB4
> > +#define ILI9488_DISPLAY_FUNCTION_CONTROL   0xB6
> > +#define ILI9488_ENTRY_MODE_SET 0xB7
> > +#define ILI9488_HS_LANES_CONTROL   0xBE
> > +#define ILI9488_SET_IMAGE_FUNCTION 0xE9
> > +#define ILI9488_ADJUST_CONTROL_3   0xF7
> > +#define ILI9488_DISPLAY_ON 0x29
> > +#define ILI9488_DISPLAY_OFF0x28
> > +#define ILI9488_ENTER_SLEEP_MODE   0x10
> > +#define ILI9488_DBI_BPP18  0x06
> > +#define ILI9488_DBI_BPP16  0x05
> > +#define ILI9488_DPI_BPP24  0x70
> > +#define ILI9488_DPI_BPP18  0x60
> > +#define ILI9488_DPI_BPP16  0x50
> > +#define ILI9488_FRAME_RATE_CONTROL_NORMAL  0xB1
> > +#define ILI9488_SLEEP_OUT  0x11
> > +
> > +#define ILI9488_MADCTL_RGB BIT(2)
> > +#define ILI9488_MADCTL_BGR BIT(3)
> > 

Re: [PATCH 2/2] drm/tiny: add support for tft displays based on ilitek, ili9488

2022-10-18 Thread Michael Nazzareno Trimarchi
Hi

On Tue, Oct 18, 2022 at 6:46 PM Tommaso Merciai
 wrote:
>
> This adds support for ilitek,ili9488 based displays with shift register
> in front of controller. Waveshare,pico-restouch-lcd-3.5 are such displays
>
> Signed-off-by: Tommaso Merciai 
> ---

Because I start to make it working this driver, I think that my
signed-off is missing here

>  drivers/gpu/drm/tiny/Kconfig   |  13 +
>  drivers/gpu/drm/tiny/Makefile  |   1 +
>  drivers/gpu/drm/tiny/ili9488.c | 440 +
>  3 files changed, 454 insertions(+)
>  create mode 100644 drivers/gpu/drm/tiny/ili9488.c
>
> diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig
> index 027cd87c3d0d7..6e708e8414806 100644
> --- a/drivers/gpu/drm/tiny/Kconfig
> +++ b/drivers/gpu/drm/tiny/Kconfig
> @@ -148,6 +148,19 @@ config TINYDRM_ILI9486
>
>   If M is selected the module will be called ili9486.
>
> +config TINYDRM_ILI9488
> +   tristate "DRM support for ILI9488 display panels"
> +   depends on DRM && SPI
> +   select DRM_KMS_HELPER
> +   select DRM_GEM_CMA_HELPER
> +   select DRM_MIPI_DBI
> +   select BACKLIGHT_CLASS_DEVICE
> +   help
> + DRM driver for the following Ilitek ILI9488 panels:
> + * LCD 3.5" 320x480 TFT (Waveshare Pico-ResTouch-LCD-3.5")
> +
> + If M is selected the module will be called ili9486.
> +
>  config TINYDRM_MI0283QT
> tristate "DRM support for MI0283QT"
> depends on DRM && SPI
> diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile
> index 1d9d6227e7ab7..aad6683b2ac40 100644
> --- a/drivers/gpu/drm/tiny/Makefile
> +++ b/drivers/gpu/drm/tiny/Makefile
> @@ -11,6 +11,7 @@ obj-$(CONFIG_TINYDRM_ILI9163) += ili9163.o
>  obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
>  obj-$(CONFIG_TINYDRM_ILI9341)  += ili9341.o
>  obj-$(CONFIG_TINYDRM_ILI9486)  += ili9486.o
> +obj-$(CONFIG_TINYDRM_ILI9488)  += ili9488.o
>  obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o
>  obj-$(CONFIG_TINYDRM_REPAPER)  += repaper.o
>  obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
> diff --git a/drivers/gpu/drm/tiny/ili9488.c b/drivers/gpu/drm/tiny/ili9488.c
> new file mode 100644
> index 0..b94d9d4ff4544
> --- /dev/null
> +++ b/drivers/gpu/drm/tiny/ili9488.c
> @@ -0,0 +1,440 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * DRM driver for Ilitek ILI9488 panels
> + *
> + * Copyright 2020 Kamlesh Gurudasani 
> + */

Code was changed a bit so please add copyright of me and you

> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define ILI9488_VCOM_CONTROL_1 0xC5
> +#define ILI9488_COLUMN_ADDRESS_SET 0x2A
> +#define ILI9488_PAGE_ADDRESS_SET   0x2B
> +#define ILI9488_MEMORY_WRITE   0x2C
> +#define ILI9488_POSITIVE_GAMMA_CORRECTION  0xE0
> +#define ILI9488_NEGATIVE_GAMMA_CORRECTION  0xE1
> +#define ILI9488_POWER_CONTROL_10xC0
> +#define ILI9488_POWER_CONTROL_20xC1
> +#define ILI9488_POWER_CONTROL_30xC2
> +#define ILI9488_MEM_ACCESS_CONTROL 0x36
> +#define ILI9488_COLMOD_PIXEL_FORMAT_SET0x3A
> +#define ILI9488_INTERFACE_MODE_CONTROL 0xB0
> +#define ILI9488_FRAME_RATE_CONTROL_PARTIAL 0xB3
> +#define ILI9488_DISPLAY_INVERSION_ON   0x21
> +#define ILI9488_DISPLAY_INVERSION_CONTROL  0xB4
> +#define ILI9488_DISPLAY_FUNCTION_CONTROL   0xB6
> +#define ILI9488_ENTRY_MODE_SET 0xB7
> +#define ILI9488_HS_LANES_CONTROL   0xBE
> +#define ILI9488_SET_IMAGE_FUNCTION 0xE9
> +#define ILI9488_ADJUST_CONTROL_3   0xF7
> +#define ILI9488_DISPLAY_ON 0x29
> +#define ILI9488_DISPLAY_OFF0x28
> +#define ILI9488_ENTER_SLEEP_MODE   0x10
> +#define ILI9488_DBI_BPP18  0x06
> +#define ILI9488_DBI_BPP16  0x05
> +#define ILI9488_DPI_BPP24  0x70
> +#define ILI9488_DPI_BPP18  0x60
> +#define ILI9488_DPI_BPP16  0x50
> +#define ILI9488_FRAME_RATE_CONTROL_NORMAL  0xB1
> +#define ILI9488_SLEEP_OUT  0x11
> +
> +#define ILI9488_MADCTL_RGB BIT(2)
> +#define ILI9488_MADCTL_BGR BIT(3)
> +#define ILI9488_MADCTL_MV  BIT(5)
> +#define ILI9488_MADCTL_MX  BIT(6)
> +#define ILI9488_MADCTL_MY  BIT(7)
> +
> +static void ili9488_rgb565_to_rgb666_line(u8 *dst, u16 *sbuf,
> + unsigned int pixels)
> +{
> +   unsigned int x;
> +
> +   for (x = 0; x < pixels; x++) {
> +   *dst++ = ((*sbuf & 0xF800) >> 8);
> +   *dst++ = 

[PATCH 2/2] drm/tiny: add support for tft displays based on ilitek, ili9488

2022-10-18 Thread Tommaso Merciai
This adds support for ilitek,ili9488 based displays with shift register
in front of controller. Waveshare,pico-restouch-lcd-3.5 are such displays

Signed-off-by: Tommaso Merciai 
---
 drivers/gpu/drm/tiny/Kconfig   |  13 +
 drivers/gpu/drm/tiny/Makefile  |   1 +
 drivers/gpu/drm/tiny/ili9488.c | 440 +
 3 files changed, 454 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/ili9488.c

diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig
index 027cd87c3d0d7..6e708e8414806 100644
--- a/drivers/gpu/drm/tiny/Kconfig
+++ b/drivers/gpu/drm/tiny/Kconfig
@@ -148,6 +148,19 @@ config TINYDRM_ILI9486
 
  If M is selected the module will be called ili9486.
 
+config TINYDRM_ILI9488
+   tristate "DRM support for ILI9488 display panels"
+   depends on DRM && SPI
+   select DRM_KMS_HELPER
+   select DRM_GEM_CMA_HELPER
+   select DRM_MIPI_DBI
+   select BACKLIGHT_CLASS_DEVICE
+   help
+ DRM driver for the following Ilitek ILI9488 panels:
+ * LCD 3.5" 320x480 TFT (Waveshare Pico-ResTouch-LCD-3.5")
+
+ If M is selected the module will be called ili9486.
+
 config TINYDRM_MI0283QT
tristate "DRM support for MI0283QT"
depends on DRM && SPI
diff --git a/drivers/gpu/drm/tiny/Makefile b/drivers/gpu/drm/tiny/Makefile
index 1d9d6227e7ab7..aad6683b2ac40 100644
--- a/drivers/gpu/drm/tiny/Makefile
+++ b/drivers/gpu/drm/tiny/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_TINYDRM_ILI9163) += ili9163.o
 obj-$(CONFIG_TINYDRM_ILI9225)  += ili9225.o
 obj-$(CONFIG_TINYDRM_ILI9341)  += ili9341.o
 obj-$(CONFIG_TINYDRM_ILI9486)  += ili9486.o
+obj-$(CONFIG_TINYDRM_ILI9488)  += ili9488.o
 obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o
 obj-$(CONFIG_TINYDRM_REPAPER)  += repaper.o
 obj-$(CONFIG_TINYDRM_ST7586)   += st7586.o
diff --git a/drivers/gpu/drm/tiny/ili9488.c b/drivers/gpu/drm/tiny/ili9488.c
new file mode 100644
index 0..b94d9d4ff4544
--- /dev/null
+++ b/drivers/gpu/drm/tiny/ili9488.c
@@ -0,0 +1,440 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * DRM driver for Ilitek ILI9488 panels
+ *
+ * Copyright 2020 Kamlesh Gurudasani 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ILI9488_VCOM_CONTROL_1 0xC5
+#define ILI9488_COLUMN_ADDRESS_SET 0x2A
+#define ILI9488_PAGE_ADDRESS_SET   0x2B
+#define ILI9488_MEMORY_WRITE   0x2C
+#define ILI9488_POSITIVE_GAMMA_CORRECTION  0xE0
+#define ILI9488_NEGATIVE_GAMMA_CORRECTION  0xE1
+#define ILI9488_POWER_CONTROL_10xC0
+#define ILI9488_POWER_CONTROL_20xC1
+#define ILI9488_POWER_CONTROL_30xC2
+#define ILI9488_MEM_ACCESS_CONTROL 0x36
+#define ILI9488_COLMOD_PIXEL_FORMAT_SET0x3A
+#define ILI9488_INTERFACE_MODE_CONTROL 0xB0
+#define ILI9488_FRAME_RATE_CONTROL_PARTIAL 0xB3
+#define ILI9488_DISPLAY_INVERSION_ON   0x21
+#define ILI9488_DISPLAY_INVERSION_CONTROL  0xB4
+#define ILI9488_DISPLAY_FUNCTION_CONTROL   0xB6
+#define ILI9488_ENTRY_MODE_SET 0xB7
+#define ILI9488_HS_LANES_CONTROL   0xBE
+#define ILI9488_SET_IMAGE_FUNCTION 0xE9
+#define ILI9488_ADJUST_CONTROL_3   0xF7
+#define ILI9488_DISPLAY_ON 0x29
+#define ILI9488_DISPLAY_OFF0x28
+#define ILI9488_ENTER_SLEEP_MODE   0x10
+#define ILI9488_DBI_BPP18  0x06
+#define ILI9488_DBI_BPP16  0x05
+#define ILI9488_DPI_BPP24  0x70
+#define ILI9488_DPI_BPP18  0x60
+#define ILI9488_DPI_BPP16  0x50
+#define ILI9488_FRAME_RATE_CONTROL_NORMAL  0xB1
+#define ILI9488_SLEEP_OUT  0x11
+
+#define ILI9488_MADCTL_RGB BIT(2)
+#define ILI9488_MADCTL_BGR BIT(3)
+#define ILI9488_MADCTL_MV  BIT(5)
+#define ILI9488_MADCTL_MX  BIT(6)
+#define ILI9488_MADCTL_MY  BIT(7)
+
+static void ili9488_rgb565_to_rgb666_line(u8 *dst, u16 *sbuf,
+ unsigned int pixels)
+{
+   unsigned int x;
+
+   for (x = 0; x < pixels; x++) {
+   *dst++ = ((*sbuf & 0xF800) >> 8);
+   *dst++ = ((*sbuf & 0x07E0) >> 3);
+   *dst++ = ((*sbuf & 0x001F) << 3);
+   sbuf++;
+   }
+}
+
+static void ili9488_rgb565_to_rgb666(u8 *dst, void *vaddr,
+struct drm_framebuffer *fb,
+struct drm_rect *rect)
+{
+   unsigned long linepixels = drm_rect_width(rect);
+   unsigned long lines = drm_rect_height(rect);
+   size_t dst_len = linepixels * 3;
+