* [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display @ 2017-08-07 17:39 David Lechner 2017-08-07 17:39 ` [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() David Lechner ` (5 more replies) 0 siblings, 6 replies; 11+ messages in thread From: David Lechner @ 2017-08-07 17:39 UTC (permalink / raw) To: dri-devel, devicetree Cc: David Lechner, Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel The goal of this series is to get the built-in LCD of the LEGO MINDSTORMS EV3 working. v2 changes: * Wrote a new driver for ST7586 instead of combining it with existing drivers * Don't touch MIPI DBI code (other than the patch suggested by Noralf) * New defconfig patch v3 changes: * New patch to generalize tinydrm_xrgb8888_to_gray8() so that it can be reused. * Device tree bindings in separate patch. * Fixed incorrect device tree binding pin descriptions. * Added MAINTAINERS entry for drivers/gpu/drm/tinydrm/st7586.c. * Removed "mipi_dbi_" from function names in st7586.c. * Moved init and fini to pipe_enable and pipe_disable ops. * Dropped RGB565 format. * Made adjustments for the fact the controller cannot be read via SPI. * Dropped st7586.h - values moved into st7586.c. v4 changes: * Dropped patch "drm/tinydrm: remove call to mipi_dbi_init() from mipi_dbi_spi_init()" since it has been applied. * correct order for MAINTAINERS entry * Drop code/dt bindings not used by LEGO EV3 (regulator, backlight, etc) * Make gpios required * Use lookup table for pixel packing algorithm * Don't modify clip when used as function parameter * Rename dc to a0 since that is what is on the datasheet/LEGO schematic. David Lechner (5): drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() dt-bindings: add binding for Sitronix ST7586 display panels drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD ARM: dts: da850-lego-ev3: Add node for LCD display ARM: davinci_all_defconfig: enable tinydrm and ST7586 .../bindings/display/sitronix,st7586.txt | 22 ++ MAINTAINERS | 6 + arch/arm/boot/dts/da850-lego-ev3.dts | 24 ++ arch/arm/configs/davinci_all_defconfig | 2 + drivers/gpu/drm/tinydrm/Kconfig | 10 + drivers/gpu/drm/tinydrm/Makefile | 1 + drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 42 +- drivers/gpu/drm/tinydrm/repaper.c | 28 +- drivers/gpu/drm/tinydrm/st7586.c | 428 +++++++++++++++++++++ include/drm/tinydrm/tinydrm-helpers.h | 3 +- 10 files changed, 534 insertions(+), 32 deletions(-) create mode 100644 Documentation/devicetree/bindings/display/sitronix,st7586.txt create mode 100644 drivers/gpu/drm/tinydrm/st7586.c -- 2.7.4 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner @ 2017-08-07 17:39 ` David Lechner 2017-08-09 15:56 ` Noralf Trønnes 2017-08-07 17:39 ` [PATCH v4 2/5] dt-bindings: add binding for Sitronix ST7586 display panels David Lechner ` (4 subsequent siblings) 5 siblings, 1 reply; 11+ messages in thread From: David Lechner @ 2017-08-07 17:39 UTC (permalink / raw) To: dri-devel, devicetree Cc: David Lechner, Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel This adds parameters for vaddr and clip to tinydrm_xrgb8888_to_gray8() to make it more generic. dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver. Return type is change to void to simplify error handling by callers. Signed-off-by: David Lechner <david@lechnology.com> --- v4 changes: * Change return type to void. drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 42 +++++++++----------------- drivers/gpu/drm/tinydrm/repaper.c | 28 +++++++++++++++-- include/drm/tinydrm/tinydrm-helpers.h | 3 +- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index 75808bb..bd6cce0 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c @@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565); /** * tinydrm_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale * @dst: 8-bit grayscale destination buffer + * @vaddr: XRGB8888 source buffer * @fb: DRM framebuffer + * @clip: Clip rectangle area to copy * * Drm doesn't have native monochrome or grayscale support. * Such drivers can announce the commonly supported XR24 format to userspace @@ -195,41 +197,31 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565); * where 1 means foreground color and 0 background color. * * ITU BT.601 is used for the RGB -> luma (brightness) conversion. - * - * Returns: - * Zero on success, negative error code on failure. */ -int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb) +void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, + struct drm_clip_rect *clip) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); - struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; - unsigned int x, y, pitch = fb->pitches[0]; - int ret = 0; + unsigned int len = (clip->x2 - clip->x1) * sizeof(u32); + unsigned int x, y; void *buf; u32 *src; if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888)) - return -EINVAL; + return; /* * The cma memory is write-combined so reads are uncached. * Speed up by fetching one line at a time. */ - buf = kmalloc(pitch, GFP_KERNEL); + buf = kmalloc(len, GFP_KERNEL); if (!buf) - return -ENOMEM; - - if (import_attach) { - ret = dma_buf_begin_cpu_access(import_attach->dmabuf, - DMA_FROM_DEVICE); - if (ret) - goto err_free; - } + return; - for (y = 0; y < fb->height; y++) { - src = cma_obj->vaddr + (y * pitch); - memcpy(buf, src, pitch); + for (y = clip->y1; y < clip->y2; y++) { + src = vaddr + (y * fb->pitches[0]); + src += clip->x1; + memcpy(buf, src, len); src = buf; - for (x = 0; x < fb->width; x++) { + for (x = clip->x1; x < clip->x2; x++) { u8 r = (*src & 0x00ff0000) >> 16; u8 g = (*src & 0x0000ff00) >> 8; u8 b = *src & 0x000000ff; @@ -240,13 +232,7 @@ int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb) } } - if (import_attach) - ret = dma_buf_end_cpu_access(import_attach->dmabuf, - DMA_FROM_DEVICE); -err_free: kfree(buf); - - return ret; } EXPORT_SYMBOL(tinydrm_xrgb8888_to_gray8); diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c index 3343d3f..30dc97b 100644 --- a/drivers/gpu/drm/tinydrm/repaper.c +++ b/drivers/gpu/drm/tinydrm/repaper.c @@ -18,6 +18,7 @@ */ #include <linux/delay.h> +#include <linux/dma-buf.h> #include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/of_device.h> @@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, struct drm_clip_rect *clips, unsigned int num_clips) { + struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); + struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; struct tinydrm_device *tdev = fb->dev->dev_private; struct repaper_epd *epd = epd_from_tinydrm(tdev); + struct drm_clip_rect clip; u8 *buf = NULL; int ret = 0; + /* repaper can't do partial updates */ + clip.x1 = 0; + clip.x2 = fb->width; + clip.y1 = 0; + clip.y2 = fb->height; + mutex_lock(&tdev->dirty_lock); if (!epd->enabled) @@ -550,9 +560,21 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, goto out_unlock; } - ret = tinydrm_xrgb8888_to_gray8(buf, fb); - if (ret) - goto out_unlock; + if (import_attach) { + ret = dma_buf_begin_cpu_access(import_attach->dmabuf, + DMA_FROM_DEVICE); + if (ret) + goto out_unlock; + } + + tinydrm_xrgb8888_to_gray8(buf, cma_obj->vaddr, fb, &clip); + + if (import_attach) { + ret = dma_buf_end_cpu_access(import_attach->dmabuf, + DMA_FROM_DEVICE); + if (ret) + goto out_unlock; + } repaper_gray8_to_mono_reversed(buf, fb->width, fb->height); diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h index a6c387f..d554ded 100644 --- a/include/drm/tinydrm/tinydrm-helpers.h +++ b/include/drm/tinydrm/tinydrm-helpers.h @@ -43,7 +43,8 @@ void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb, void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr, struct drm_framebuffer *fb, struct drm_clip_rect *clip, bool swap); -int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb); +void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, + struct drm_clip_rect *clip); struct backlight_device *tinydrm_of_find_backlight(struct device *dev); int tinydrm_enable_backlight(struct backlight_device *backlight); -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() 2017-08-07 17:39 ` [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() David Lechner @ 2017-08-09 15:56 ` Noralf Trønnes 0 siblings, 0 replies; 11+ messages in thread From: Noralf Trønnes @ 2017-08-09 15:56 UTC (permalink / raw) To: David Lechner, dri-devel, devicetree Cc: Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel Den 07.08.2017 19.39, skrev David Lechner: > This adds parameters for vaddr and clip to tinydrm_xrgb8888_to_gray8() to > make it more generic. > > dma_buf_{begin,end}_cpu_access() are moved out to the repaper driver. > > Return type is change to void to simplify error handling by callers. > > Signed-off-by: David Lechner <david@lechnology.com> > --- Thanks for doing this, applied to drm-misc. Noralf. > v4 changes: > * Change return type to void. > > > drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 42 +++++++++----------------- > drivers/gpu/drm/tinydrm/repaper.c | 28 +++++++++++++++-- > include/drm/tinydrm/tinydrm-helpers.h | 3 +- > 3 files changed, 41 insertions(+), 32 deletions(-) > > diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c > index 75808bb..bd6cce0 100644 > --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c > +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c > @@ -185,7 +185,9 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565); > /** > * tinydrm_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale > * @dst: 8-bit grayscale destination buffer > + * @vaddr: XRGB8888 source buffer > * @fb: DRM framebuffer > + * @clip: Clip rectangle area to copy > * > * Drm doesn't have native monochrome or grayscale support. > * Such drivers can announce the commonly supported XR24 format to userspace > @@ -195,41 +197,31 @@ EXPORT_SYMBOL(tinydrm_xrgb8888_to_rgb565); > * where 1 means foreground color and 0 background color. > * > * ITU BT.601 is used for the RGB -> luma (brightness) conversion. > - * > - * Returns: > - * Zero on success, negative error code on failure. > */ > -int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb) > +void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, > + struct drm_clip_rect *clip) > { > - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); > - struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; > - unsigned int x, y, pitch = fb->pitches[0]; > - int ret = 0; > + unsigned int len = (clip->x2 - clip->x1) * sizeof(u32); > + unsigned int x, y; > void *buf; > u32 *src; > > if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888)) > - return -EINVAL; > + return; > /* > * The cma memory is write-combined so reads are uncached. > * Speed up by fetching one line at a time. > */ > - buf = kmalloc(pitch, GFP_KERNEL); > + buf = kmalloc(len, GFP_KERNEL); > if (!buf) > - return -ENOMEM; > - > - if (import_attach) { > - ret = dma_buf_begin_cpu_access(import_attach->dmabuf, > - DMA_FROM_DEVICE); > - if (ret) > - goto err_free; > - } > + return; > > - for (y = 0; y < fb->height; y++) { > - src = cma_obj->vaddr + (y * pitch); > - memcpy(buf, src, pitch); > + for (y = clip->y1; y < clip->y2; y++) { > + src = vaddr + (y * fb->pitches[0]); > + src += clip->x1; > + memcpy(buf, src, len); > src = buf; > - for (x = 0; x < fb->width; x++) { > + for (x = clip->x1; x < clip->x2; x++) { > u8 r = (*src & 0x00ff0000) >> 16; > u8 g = (*src & 0x0000ff00) >> 8; > u8 b = *src & 0x000000ff; > @@ -240,13 +232,7 @@ int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb) > } > } > > - if (import_attach) > - ret = dma_buf_end_cpu_access(import_attach->dmabuf, > - DMA_FROM_DEVICE); > -err_free: > kfree(buf); > - > - return ret; > } > EXPORT_SYMBOL(tinydrm_xrgb8888_to_gray8); > > diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c > index 3343d3f..30dc97b 100644 > --- a/drivers/gpu/drm/tinydrm/repaper.c > +++ b/drivers/gpu/drm/tinydrm/repaper.c > @@ -18,6 +18,7 @@ > */ > > #include <linux/delay.h> > +#include <linux/dma-buf.h> > #include <linux/gpio/consumer.h> > #include <linux/module.h> > #include <linux/of_device.h> > @@ -525,11 +526,20 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, > struct drm_clip_rect *clips, > unsigned int num_clips) > { > + struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); > + struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; > struct tinydrm_device *tdev = fb->dev->dev_private; > struct repaper_epd *epd = epd_from_tinydrm(tdev); > + struct drm_clip_rect clip; > u8 *buf = NULL; > int ret = 0; > > + /* repaper can't do partial updates */ > + clip.x1 = 0; > + clip.x2 = fb->width; > + clip.y1 = 0; > + clip.y2 = fb->height; > + > mutex_lock(&tdev->dirty_lock); > > if (!epd->enabled) > @@ -550,9 +560,21 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, > goto out_unlock; > } > > - ret = tinydrm_xrgb8888_to_gray8(buf, fb); > - if (ret) > - goto out_unlock; > + if (import_attach) { > + ret = dma_buf_begin_cpu_access(import_attach->dmabuf, > + DMA_FROM_DEVICE); > + if (ret) > + goto out_unlock; > + } > + > + tinydrm_xrgb8888_to_gray8(buf, cma_obj->vaddr, fb, &clip); > + > + if (import_attach) { > + ret = dma_buf_end_cpu_access(import_attach->dmabuf, > + DMA_FROM_DEVICE); > + if (ret) > + goto out_unlock; > + } > > repaper_gray8_to_mono_reversed(buf, fb->width, fb->height); > > diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h > index a6c387f..d554ded 100644 > --- a/include/drm/tinydrm/tinydrm-helpers.h > +++ b/include/drm/tinydrm/tinydrm-helpers.h > @@ -43,7 +43,8 @@ void tinydrm_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb, > void tinydrm_xrgb8888_to_rgb565(u16 *dst, void *vaddr, > struct drm_framebuffer *fb, > struct drm_clip_rect *clip, bool swap); > -int tinydrm_xrgb8888_to_gray8(u8 *dst, struct drm_framebuffer *fb); > +void tinydrm_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb, > + struct drm_clip_rect *clip); > > struct backlight_device *tinydrm_of_find_backlight(struct device *dev); > int tinydrm_enable_backlight(struct backlight_device *backlight); ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 2/5] dt-bindings: add binding for Sitronix ST7586 display panels 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner 2017-08-07 17:39 ` [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() David Lechner @ 2017-08-07 17:39 ` David Lechner 2017-08-10 21:00 ` Rob Herring 2017-08-07 17:39 ` [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD David Lechner ` (3 subsequent siblings) 5 siblings, 1 reply; 11+ messages in thread From: David Lechner @ 2017-08-07 17:39 UTC (permalink / raw) To: dri-devel, devicetree Cc: David Lechner, Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel This adds a new binding for Sitronix ST7586 display panels. Using lego as the vendor prefix in the compatible string because the display panel I am working with is an integral part of the LEGO MINDSTORMS EV3. Signed-off-by: David Lechner <david@lechnology.com> --- v4 changes: * Dropped optional properties and only use pins actually used on LEGO EV3. * Rename dc to a0 since that is what is on the datasheet/LEGO schematic. .../bindings/display/sitronix,st7586.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/sitronix,st7586.txt diff --git a/Documentation/devicetree/bindings/display/sitronix,st7586.txt b/Documentation/devicetree/bindings/display/sitronix,st7586.txt new file mode 100644 index 0000000..1d0dad1 --- /dev/null +++ b/Documentation/devicetree/bindings/display/sitronix,st7586.txt @@ -0,0 +1,22 @@ +Sitronix ST7586 display panel + +Required properties: +- compatible: "lego,ev3-lcd". +- a0-gpios: The A0 signal (since this binding is for serial mode, this is + the pin labeled D1 on the controller, not the pin labeled A0) +- reset-gpios: Reset pin + +The node for this driver must be a child node of a SPI controller, hence +all mandatory properties described in ../spi/spi-bus.txt must be specified. + +Optional properties: +- rotation: panel rotation in degrees counter clockwise (0,90,180,270) + +Example: + display@0{ + compatible = "lego,ev3-lcd"; + reg = <0>; + spi-max-frequency = <10000000>; + a0-gpios = <&gpio 43 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio 80 GPIO_ACTIVE_HIGH>; + }; -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v4 2/5] dt-bindings: add binding for Sitronix ST7586 display panels 2017-08-07 17:39 ` [PATCH v4 2/5] dt-bindings: add binding for Sitronix ST7586 display panels David Lechner @ 2017-08-10 21:00 ` Rob Herring 0 siblings, 0 replies; 11+ messages in thread From: Rob Herring @ 2017-08-10 21:00 UTC (permalink / raw) To: David Lechner Cc: dri-devel, devicetree, Noralf Trønnes, Daniel Vetter, David Airlie, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel On Mon, Aug 07, 2017 at 12:39:38PM -0500, David Lechner wrote: > This adds a new binding for Sitronix ST7586 display panels. > > Using lego as the vendor prefix in the compatible string because the display > panel I am working with is an integral part of the LEGO MINDSTORMS EV3. > > Signed-off-by: David Lechner <david@lechnology.com> > --- > > v4 changes: > * Dropped optional properties and only use pins actually used on LEGO EV3. > * Rename dc to a0 since that is what is on the datasheet/LEGO schematic. > > > .../bindings/display/sitronix,st7586.txt | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > create mode 100644 Documentation/devicetree/bindings/display/sitronix,st7586.txt Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner 2017-08-07 17:39 ` [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() David Lechner 2017-08-07 17:39 ` [PATCH v4 2/5] dt-bindings: add binding for Sitronix ST7586 display panels David Lechner @ 2017-08-07 17:39 ` David Lechner 2017-08-09 17:59 ` Noralf Trønnes 2017-08-07 17:39 ` [PATCH v4 4/5] ARM: dts: da850-lego-ev3: Add node for LCD display David Lechner ` (2 subsequent siblings) 5 siblings, 1 reply; 11+ messages in thread From: David Lechner @ 2017-08-07 17:39 UTC (permalink / raw) To: dri-devel, devicetree Cc: David Lechner, Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new module for the ST7586 controller with parameters for the LEGO MINDSTORMS EV3 LCD display. Signed-off-by: David Lechner <david@lechnology.com> --- v4 changes: * correct order for MAINTAINERS entry * Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume) * Make gpios required * Use lookup table for pixel packing algorithm * Don't modify clip when used as function parameter * Use roundup/rounddown macros MAINTAINERS | 6 + drivers/gpu/drm/tinydrm/Kconfig | 10 + drivers/gpu/drm/tinydrm/Makefile | 1 + drivers/gpu/drm/tinydrm/st7586.c | 428 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 445 insertions(+) create mode 100644 drivers/gpu/drm/tinydrm/st7586.c diff --git a/MAINTAINERS b/MAINTAINERS index a1e772e..19ca3e6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4380,6 +4380,12 @@ S: Orphan / Obsolete F: drivers/gpu/drm/sis/ F: include/uapi/drm/sis_drm.h +DRM DRIVER FOR SITRONIX ST7586 PANELS +M: David Lechner <david@lechnology.com> +S: Maintained +F: drivers/gpu/drm/tinydrm/st7586.c +F: Documentation/devicetree/bindings/display/st7586.txt + DRM DRIVER FOR TDFX VIDEO CARDS S: Orphan / Obsolete F: drivers/gpu/drm/tdfx/ diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig index f17c3ca..2e790e7 100644 --- a/drivers/gpu/drm/tinydrm/Kconfig +++ b/drivers/gpu/drm/tinydrm/Kconfig @@ -32,3 +32,13 @@ config TINYDRM_REPAPER 2.71" TFT EPD Panel (E2271CS021) If M is selected the module will be called repaper. + +config TINYDRM_ST7586 + tristate "DRM support for Sitronix ST7586 display panels" + depends on DRM_TINYDRM && SPI + select TINYDRM_MIPI_DBI + help + DRM driver for the following Sitronix ST7586 panels: + * LEGO MINDSTORMS EV3 + + If M is selected the module will be called st7586. diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile index 95bb4d4..0c184bd 100644 --- a/drivers/gpu/drm/tinydrm/Makefile +++ b/drivers/gpu/drm/tinydrm/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI) += mipi-dbi.o # Displays obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o +obj-$(CONFIG_TINYDRM_ST7586) += st7586.o diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c new file mode 100644 index 0000000..1b39d3f --- /dev/null +++ b/drivers/gpu/drm/tinydrm/st7586.c @@ -0,0 +1,428 @@ +/* + * DRM driver for Sitronix ST7586 panels + * + * Copyright 2017 David Lechner <david@lechnology.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <linux/delay.h> +#include <linux/dma-buf.h> +#include <linux/gpio/consumer.h> +#include <linux/module.h> +#include <linux/property.h> +#include <linux/spi/spi.h> +#include <video/mipi_display.h> + +#include <drm/tinydrm/mipi-dbi.h> +#include <drm/tinydrm/tinydrm-helpers.h> + +/* controller-specific commands */ +#define ST7586_DISP_MODE_GRAY 0x38 +#define ST7586_DISP_MODE_MONO 0x39 +#define ST7586_ENABLE_DDRAM 0x3a +#define ST7586_SET_DISP_DUTY 0xb0 +#define ST7586_SET_PART_DISP 0xb4 +#define ST7586_SET_NLINE_INV 0xb5 +#define ST7586_SET_VOP 0xc0 +#define ST7586_SET_BIAS_SYSTEM 0xc3 +#define ST7586_SET_BOOST_LEVEL 0xc4 +#define ST7586_SET_VOP_OFFSET 0xc7 +#define ST7586_ENABLE_ANALOG 0xd0 +#define ST7586_AUTO_READ_CTRL 0xd7 +#define ST7586_OTP_RW_CTRL 0xe0 +#define ST7586_OTP_CTRL_OUT 0xe1 +#define ST7586_OTP_READ 0xe3 + +#define ST7586_DISP_CTRL_MX BIT(6) +#define ST7586_DISP_CTRL_MY BIT(7) + +/* + * The ST7586 controller has an unusual pixel format where 2bpp grayscale is + * packed 3 pixels per byte with the first two pixels using 3 bits and the 3rd + * pixel using only 2 bits. + * + * | D7 | D6 | D5 || | || 2bpp | + * | (D4) | (D3) | (D2) || D1 | D0 || GRAY | + * +------+------+------++------+------++------+ + * | 1 | 1 | 1 || 1 | 1 || 0 0 | black + * | 1 | 0 | 0 || 1 | 0 || 0 1 | dark gray + * | 0 | 1 | 0 || 0 | 1 || 1 0 | light gray + * | 0 | 0 | 0 || 0 | 0 || 1 1 | white + */ + +static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 }; + +static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr, + struct drm_framebuffer *fb, + struct drm_clip_rect *clip) +{ + size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1); + unsigned int x, y; + u8 *src, *buf, val; + + buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return; + + tinydrm_xrgb8888_to_gray8(buf, vaddr, fb, clip); + src = buf; + + for (y = clip->y1; y < clip->y2; y++) { + for (x = clip->x1; x < clip->x2; x += 3) { + val = st7586_lookup[*src++ >> 6] << 5; + val |= st7586_lookup[*src++ >> 6] << 2; + val |= st7586_lookup[*src++ >> 6] >> 1; + *dst++ = val; + } + } + + kfree(buf); +} + +static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb, + struct drm_clip_rect *clip) +{ + struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); + struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; + void *src = cma_obj->vaddr; + int ret = 0; + + if (import_attach) { + ret = dma_buf_begin_cpu_access(import_attach->dmabuf, + DMA_FROM_DEVICE); + if (ret) + return ret; + } + + st7586_xrgb8888_to_gray332(dst, src, fb, clip); + + if (import_attach) + ret = dma_buf_end_cpu_access(import_attach->dmabuf, + DMA_FROM_DEVICE); + + return ret; +} + +static int st7586_fb_dirty(struct drm_framebuffer *fb, + struct drm_file *file_priv, unsigned int flags, + unsigned int color, struct drm_clip_rect *clips, + unsigned int num_clips) +{ + struct tinydrm_device *tdev = fb->dev->dev_private; + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); + struct drm_clip_rect clip; + int start, end; + int ret = 0; + + mutex_lock(&tdev->dirty_lock); + + if (!mipi->enabled) + goto out_unlock; + + /* fbdev can flush even when we're not interested */ + if (tdev->pipe.plane.fb != fb) + goto out_unlock; + + tinydrm_merge_clips(&clip, clips, num_clips, flags, fb->width, + fb->height); + + /* 3 pixels per byte, so grow clip to nearest multiple of 3 */ + clip.x1 = rounddown(clip.x1, 3); + clip.x2 = roundup(clip.x2, 3); + + DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id, + clip.x1, clip.x2, clip.y1, clip.y2); + + ret = st7586_buf_copy(mipi->tx_buf, fb, &clip); + if (ret) + goto out_unlock; + + /* Pixels are packed 3 per byte */ + start = clip.x1 / 3; + end = clip.x2 / 3; + + mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, + (start >> 8) & 0xFF, start & 0xFF, + (end >> 8) & 0xFF, (end - 1) & 0xFF); + mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS, + (clip.y1 >> 8) & 0xFF, clip.y1 & 0xFF, + (clip.y2 >> 8) & 0xFF, (clip.y2 - 1) & 0xFF); + + ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START, + (u8 *)mipi->tx_buf, + (end - start) * (clip.y2 - clip.y1)); + +out_unlock: + mutex_unlock(&tdev->dirty_lock); + + if (ret) + dev_err_once(fb->dev->dev, "Failed to update display %d\n", + ret); + + return ret; +} + +static const struct drm_framebuffer_funcs st7586_fb_funcs = { + .destroy = drm_fb_cma_destroy, + .create_handle = drm_fb_cma_create_handle, + .dirty = st7586_fb_dirty, +}; + +void st7586_pipe_enable(struct drm_simple_display_pipe *pipe, + struct drm_crtc_state *crtc_state) +{ + struct tinydrm_device *tdev = pipe_to_tinydrm(pipe); + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); + struct drm_framebuffer *fb = pipe->plane.fb; + struct device *dev = tdev->drm->dev; + int ret; + u8 addr_mode; + + DRM_DEBUG_KMS("\n"); + + mipi_dbi_hw_reset(mipi); + ret = mipi_dbi_command(mipi, ST7586_AUTO_READ_CTRL, 0x9f); + if (ret) { + dev_err(dev, "Error sending command %d\n", ret); + return; + } + + mipi_dbi_command(mipi, ST7586_OTP_RW_CTRL, 0x00); + + msleep(10); + + mipi_dbi_command(mipi, ST7586_OTP_READ); + + msleep(20); + + mipi_dbi_command(mipi, ST7586_OTP_CTRL_OUT); + mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE); + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); + + msleep(50); + + mipi_dbi_command(mipi, ST7586_SET_VOP_OFFSET, 0x00); + mipi_dbi_command(mipi, ST7586_SET_VOP, 0xe3, 0x00); + mipi_dbi_command(mipi, ST7586_SET_BIAS_SYSTEM, 0x02); + mipi_dbi_command(mipi, ST7586_SET_BOOST_LEVEL, 0x04); + mipi_dbi_command(mipi, ST7586_ENABLE_ANALOG, 0x1d); + mipi_dbi_command(mipi, ST7586_SET_NLINE_INV, 0x00); + mipi_dbi_command(mipi, ST7586_DISP_MODE_GRAY); + mipi_dbi_command(mipi, ST7586_ENABLE_DDRAM, 0x02); + + switch (mipi->rotation) { + default: + addr_mode = 0x00; + break; + case 90: + addr_mode = ST7586_DISP_CTRL_MY; + break; + case 180: + addr_mode = ST7586_DISP_CTRL_MX | ST7586_DISP_CTRL_MY; + break; + case 270: + addr_mode = ST7586_DISP_CTRL_MX; + break; + } + mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode); + + mipi_dbi_command(mipi, ST7586_SET_DISP_DUTY, 0x7f); + mipi_dbi_command(mipi, ST7586_SET_PART_DISP, 0xa0); + mipi_dbi_command(mipi, MIPI_DCS_SET_PARTIAL_AREA, 0x00, 0x00, 0x00, 0x77); + mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE); + + msleep(100); + + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON); + + mipi->enabled = true; + + if (fb) + fb->funcs->dirty(fb, NULL, 0, 0, NULL, 0); +} + +static void st7586_pipe_disable(struct drm_simple_display_pipe *pipe) +{ + struct tinydrm_device *tdev = pipe_to_tinydrm(pipe); + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); + + DRM_DEBUG_KMS("\n"); + + if (!mipi->enabled) + return; + + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); + mipi->enabled = false; +} + +static const u32 st7586_formats[] = { + DRM_FORMAT_XRGB8888, +}; + +static int st7586_init(struct device *dev, struct mipi_dbi *mipi, + const struct drm_simple_display_pipe_funcs *pipe_funcs, + struct drm_driver *driver, const struct drm_display_mode *mode, + unsigned int rotation) +{ + size_t bufsize = (mode->vdisplay + 2) / 3 * mode->hdisplay; + struct tinydrm_device *tdev = &mipi->tinydrm; + int ret; + + mutex_init(&mipi->cmdlock); + + mipi->tx_buf = devm_kmalloc(dev, bufsize, GFP_KERNEL); + if (!mipi->tx_buf) + return -ENOMEM; + + ret = devm_tinydrm_init(dev, tdev, &st7586_fb_funcs, driver); + if (ret) + return ret; + + ret = tinydrm_display_pipe_init(tdev, pipe_funcs, + DRM_MODE_CONNECTOR_VIRTUAL, + st7586_formats, + ARRAY_SIZE(st7586_formats), + mode, rotation); + if (ret) + return ret; + + tdev->drm->mode_config.preferred_depth = 32; + mipi->rotation = rotation; + + drm_mode_config_reset(tdev->drm); + + DRM_DEBUG_KMS("preferred_depth=%u, rotation = %u\n", + tdev->drm->mode_config.preferred_depth, rotation); + + return 0; +} + +static const struct drm_simple_display_pipe_funcs st7586_pipe_funcs = { + .enable = st7586_pipe_enable, + .disable = st7586_pipe_disable, + .update = tinydrm_display_pipe_update, + .prepare_fb = tinydrm_display_pipe_prepare_fb, +}; + +static const struct drm_display_mode st7586_mode = { + TINYDRM_MODE(178, 128, 37, 27), +}; + +DEFINE_DRM_GEM_CMA_FOPS(st7586_fops); + +static struct drm_driver st7586_driver = { + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | + DRIVER_ATOMIC, + .fops = &st7586_fops, + TINYDRM_GEM_DRIVER_OPS, + .lastclose = tinydrm_lastclose, + .debugfs_init = mipi_dbi_debugfs_init, + .name = "st7586", + .desc = "Sitronix ST7586", + .date = "20170801", + .major = 1, + .minor = 0, +}; + +static const struct of_device_id st7586_of_match[] = { + { .compatible = "lego,ev3-lcd" }, + {}, +}; +MODULE_DEVICE_TABLE(of, st7586_of_match); + +static const struct spi_device_id st7586_id[] = { + { "ev3-lcd", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(spi, st7586_id); + +static int st7586_probe(struct spi_device *spi) +{ + struct device *dev = &spi->dev; + struct tinydrm_device *tdev; + struct mipi_dbi *mipi; + struct gpio_desc *a0; + u32 rotation = 0; + int ret; + + mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL); + if (!mipi) + return -ENOMEM; + + mipi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(mipi->reset)) { + dev_err(dev, "Failed to get gpio 'reset'\n"); + return PTR_ERR(mipi->reset); + } + + a0 = devm_gpiod_get(dev, "a0", GPIOD_OUT_LOW); + if (IS_ERR(a0)) { + dev_err(dev, "Failed to get gpio 'a0'\n"); + return PTR_ERR(a0); + } + + device_property_read_u32(dev, "rotation", &rotation); + + ret = mipi_dbi_spi_init(spi, mipi, a0); + if (ret) + return ret; + + /* Cannot read from this controller via SPI */ + mipi->read_commands = NULL; + + /* + * we are using 8-bit data, so we are not actually swapping anything, + * but setting mipi->swap_bytes makes mipi_dbi_typec3_command() do the + * right thing and not use 16-bit transfers (which results in swapped + * bytes on little-endian systems and causes out of order data to be + * sent to the display). + */ + mipi->swap_bytes = true; + + ret = st7586_init(&spi->dev, mipi, &st7586_pipe_funcs, &st7586_driver, + &st7586_mode, rotation); + if (ret) + return ret; + + tdev = &mipi->tinydrm; + + ret = devm_tinydrm_register(tdev); + if (ret) + return ret; + + spi_set_drvdata(spi, mipi); + + DRM_DEBUG_DRIVER("Initialized %s:%s @%uMHz on minor %d\n", + tdev->drm->driver->name, dev_name(dev), + spi->max_speed_hz / 1000000, + tdev->drm->primary->index); + + return 0; +} + +static void st7586_shutdown(struct spi_device *spi) +{ + struct mipi_dbi *mipi = spi_get_drvdata(spi); + + tinydrm_shutdown(&mipi->tinydrm); +} + +static struct spi_driver st7586_spi_driver = { + .driver = { + .name = "st7586", + .owner = THIS_MODULE, + .of_match_table = st7586_of_match, + }, + .id_table = st7586_id, + .probe = st7586_probe, + .shutdown = st7586_shutdown, +}; +module_spi_driver(st7586_spi_driver); + +MODULE_DESCRIPTION("Sitronix ST7586 DRM driver"); +MODULE_AUTHOR("David Lechner <david@lechnology.com>"); +MODULE_LICENSE("GPL"); -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD 2017-08-07 17:39 ` [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD David Lechner @ 2017-08-09 17:59 ` Noralf Trønnes 2017-08-11 16:40 ` Noralf Trønnes 0 siblings, 1 reply; 11+ messages in thread From: Noralf Trønnes @ 2017-08-09 17:59 UTC (permalink / raw) To: David Lechner, dri-devel, devicetree Cc: Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel Den 07.08.2017 19.39, skrev David Lechner: > LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new > module for the ST7586 controller with parameters for the LEGO MINDSTORMS > EV3 LCD display. > > Signed-off-by: David Lechner <david@lechnology.com> > --- This looks good, even I understand the pixel packing now :-) Now we wait for the DT maintainers to have their say. Reviewed-by: Noralf Trønnes <noralf@tronnes.org> > v4 changes: > * correct order for MAINTAINERS entry > * Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume) > * Make gpios required > * Use lookup table for pixel packing algorithm > * Don't modify clip when used as function parameter > * Use roundup/rounddown macros > > > MAINTAINERS | 6 + > drivers/gpu/drm/tinydrm/Kconfig | 10 + > drivers/gpu/drm/tinydrm/Makefile | 1 + > drivers/gpu/drm/tinydrm/st7586.c | 428 +++++++++++++++++++++++++++++++++++++++ > 4 files changed, 445 insertions(+) > create mode 100644 drivers/gpu/drm/tinydrm/st7586.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index a1e772e..19ca3e6 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -4380,6 +4380,12 @@ S: Orphan / Obsolete > F: drivers/gpu/drm/sis/ > F: include/uapi/drm/sis_drm.h > > +DRM DRIVER FOR SITRONIX ST7586 PANELS > +M: David Lechner <david@lechnology.com> > +S: Maintained > +F: drivers/gpu/drm/tinydrm/st7586.c > +F: Documentation/devicetree/bindings/display/st7586.txt > + > DRM DRIVER FOR TDFX VIDEO CARDS > S: Orphan / Obsolete > F: drivers/gpu/drm/tdfx/ > diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig > index f17c3ca..2e790e7 100644 > --- a/drivers/gpu/drm/tinydrm/Kconfig > +++ b/drivers/gpu/drm/tinydrm/Kconfig > @@ -32,3 +32,13 @@ config TINYDRM_REPAPER > 2.71" TFT EPD Panel (E2271CS021) > > If M is selected the module will be called repaper. > + > +config TINYDRM_ST7586 > + tristate "DRM support for Sitronix ST7586 display panels" > + depends on DRM_TINYDRM && SPI > + select TINYDRM_MIPI_DBI > + help > + DRM driver for the following Sitronix ST7586 panels: > + * LEGO MINDSTORMS EV3 > + > + If M is selected the module will be called st7586. > diff --git a/drivers/gpu/drm/tinydrm/Makefile b/drivers/gpu/drm/tinydrm/Makefile > index 95bb4d4..0c184bd 100644 > --- a/drivers/gpu/drm/tinydrm/Makefile > +++ b/drivers/gpu/drm/tinydrm/Makefile > @@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI) += mipi-dbi.o > # Displays > obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o > obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o > +obj-$(CONFIG_TINYDRM_ST7586) += st7586.o > diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c > new file mode 100644 > index 0000000..1b39d3f > --- /dev/null > +++ b/drivers/gpu/drm/tinydrm/st7586.c > @@ -0,0 +1,428 @@ > +/* > + * DRM driver for Sitronix ST7586 panels > + * > + * Copyright 2017 David Lechner <david@lechnology.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + */ > + > +#include <linux/delay.h> > +#include <linux/dma-buf.h> > +#include <linux/gpio/consumer.h> > +#include <linux/module.h> > +#include <linux/property.h> > +#include <linux/spi/spi.h> > +#include <video/mipi_display.h> > + > +#include <drm/tinydrm/mipi-dbi.h> > +#include <drm/tinydrm/tinydrm-helpers.h> > + > +/* controller-specific commands */ > +#define ST7586_DISP_MODE_GRAY 0x38 > +#define ST7586_DISP_MODE_MONO 0x39 > +#define ST7586_ENABLE_DDRAM 0x3a > +#define ST7586_SET_DISP_DUTY 0xb0 > +#define ST7586_SET_PART_DISP 0xb4 > +#define ST7586_SET_NLINE_INV 0xb5 > +#define ST7586_SET_VOP 0xc0 > +#define ST7586_SET_BIAS_SYSTEM 0xc3 > +#define ST7586_SET_BOOST_LEVEL 0xc4 > +#define ST7586_SET_VOP_OFFSET 0xc7 > +#define ST7586_ENABLE_ANALOG 0xd0 > +#define ST7586_AUTO_READ_CTRL 0xd7 > +#define ST7586_OTP_RW_CTRL 0xe0 > +#define ST7586_OTP_CTRL_OUT 0xe1 > +#define ST7586_OTP_READ 0xe3 > + > +#define ST7586_DISP_CTRL_MX BIT(6) > +#define ST7586_DISP_CTRL_MY BIT(7) > + > +/* > + * The ST7586 controller has an unusual pixel format where 2bpp grayscale is > + * packed 3 pixels per byte with the first two pixels using 3 bits and the 3rd > + * pixel using only 2 bits. > + * > + * | D7 | D6 | D5 || | || 2bpp | > + * | (D4) | (D3) | (D2) || D1 | D0 || GRAY | > + * +------+------+------++------+------++------+ > + * | 1 | 1 | 1 || 1 | 1 || 0 0 | black > + * | 1 | 0 | 0 || 1 | 0 || 0 1 | dark gray > + * | 0 | 1 | 0 || 0 | 1 || 1 0 | light gray > + * | 0 | 0 | 0 || 0 | 0 || 1 1 | white > + */ > + > +static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 }; > + > +static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr, > + struct drm_framebuffer *fb, > + struct drm_clip_rect *clip) > +{ > + size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1); > + unsigned int x, y; > + u8 *src, *buf, val; > + > + buf = kmalloc(len, GFP_KERNEL); > + if (!buf) > + return; > + > + tinydrm_xrgb8888_to_gray8(buf, vaddr, fb, clip); > + src = buf; > + > + for (y = clip->y1; y < clip->y2; y++) { > + for (x = clip->x1; x < clip->x2; x += 3) { > + val = st7586_lookup[*src++ >> 6] << 5; > + val |= st7586_lookup[*src++ >> 6] << 2; > + val |= st7586_lookup[*src++ >> 6] >> 1; > + *dst++ = val; > + } > + } > + > + kfree(buf); > +} > + > +static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb, > + struct drm_clip_rect *clip) > +{ > + struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); > + struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; > + void *src = cma_obj->vaddr; > + int ret = 0; > + > + if (import_attach) { > + ret = dma_buf_begin_cpu_access(import_attach->dmabuf, > + DMA_FROM_DEVICE); > + if (ret) > + return ret; > + } > + > + st7586_xrgb8888_to_gray332(dst, src, fb, clip); > + > + if (import_attach) > + ret = dma_buf_end_cpu_access(import_attach->dmabuf, > + DMA_FROM_DEVICE); > + > + return ret; > +} > + > +static int st7586_fb_dirty(struct drm_framebuffer *fb, > + struct drm_file *file_priv, unsigned int flags, > + unsigned int color, struct drm_clip_rect *clips, > + unsigned int num_clips) > +{ > + struct tinydrm_device *tdev = fb->dev->dev_private; > + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); > + struct drm_clip_rect clip; > + int start, end; > + int ret = 0; > + > + mutex_lock(&tdev->dirty_lock); > + > + if (!mipi->enabled) > + goto out_unlock; > + > + /* fbdev can flush even when we're not interested */ > + if (tdev->pipe.plane.fb != fb) > + goto out_unlock; > + > + tinydrm_merge_clips(&clip, clips, num_clips, flags, fb->width, > + fb->height); > + > + /* 3 pixels per byte, so grow clip to nearest multiple of 3 */ > + clip.x1 = rounddown(clip.x1, 3); > + clip.x2 = roundup(clip.x2, 3); > + > + DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", fb->base.id, > + clip.x1, clip.x2, clip.y1, clip.y2); > + > + ret = st7586_buf_copy(mipi->tx_buf, fb, &clip); > + if (ret) > + goto out_unlock; > + > + /* Pixels are packed 3 per byte */ > + start = clip.x1 / 3; > + end = clip.x2 / 3; > + > + mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, > + (start >> 8) & 0xFF, start & 0xFF, > + (end >> 8) & 0xFF, (end - 1) & 0xFF); > + mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS, > + (clip.y1 >> 8) & 0xFF, clip.y1 & 0xFF, > + (clip.y2 >> 8) & 0xFF, (clip.y2 - 1) & 0xFF); > + > + ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START, > + (u8 *)mipi->tx_buf, > + (end - start) * (clip.y2 - clip.y1)); > + > +out_unlock: > + mutex_unlock(&tdev->dirty_lock); > + > + if (ret) > + dev_err_once(fb->dev->dev, "Failed to update display %d\n", > + ret); > + > + return ret; > +} > + > +static const struct drm_framebuffer_funcs st7586_fb_funcs = { > + .destroy = drm_fb_cma_destroy, > + .create_handle = drm_fb_cma_create_handle, > + .dirty = st7586_fb_dirty, > +}; > + > +void st7586_pipe_enable(struct drm_simple_display_pipe *pipe, > + struct drm_crtc_state *crtc_state) > +{ > + struct tinydrm_device *tdev = pipe_to_tinydrm(pipe); > + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); > + struct drm_framebuffer *fb = pipe->plane.fb; > + struct device *dev = tdev->drm->dev; > + int ret; > + u8 addr_mode; > + > + DRM_DEBUG_KMS("\n"); > + > + mipi_dbi_hw_reset(mipi); > + ret = mipi_dbi_command(mipi, ST7586_AUTO_READ_CTRL, 0x9f); > + if (ret) { > + dev_err(dev, "Error sending command %d\n", ret); > + return; > + } > + > + mipi_dbi_command(mipi, ST7586_OTP_RW_CTRL, 0x00); > + > + msleep(10); > + > + mipi_dbi_command(mipi, ST7586_OTP_READ); > + > + msleep(20); > + > + mipi_dbi_command(mipi, ST7586_OTP_CTRL_OUT); > + mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE); > + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); > + > + msleep(50); > + > + mipi_dbi_command(mipi, ST7586_SET_VOP_OFFSET, 0x00); > + mipi_dbi_command(mipi, ST7586_SET_VOP, 0xe3, 0x00); > + mipi_dbi_command(mipi, ST7586_SET_BIAS_SYSTEM, 0x02); > + mipi_dbi_command(mipi, ST7586_SET_BOOST_LEVEL, 0x04); > + mipi_dbi_command(mipi, ST7586_ENABLE_ANALOG, 0x1d); > + mipi_dbi_command(mipi, ST7586_SET_NLINE_INV, 0x00); > + mipi_dbi_command(mipi, ST7586_DISP_MODE_GRAY); > + mipi_dbi_command(mipi, ST7586_ENABLE_DDRAM, 0x02); > + > + switch (mipi->rotation) { > + default: > + addr_mode = 0x00; > + break; > + case 90: > + addr_mode = ST7586_DISP_CTRL_MY; > + break; > + case 180: > + addr_mode = ST7586_DISP_CTRL_MX | ST7586_DISP_CTRL_MY; > + break; > + case 270: > + addr_mode = ST7586_DISP_CTRL_MX; > + break; > + } > + mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode); > + > + mipi_dbi_command(mipi, ST7586_SET_DISP_DUTY, 0x7f); > + mipi_dbi_command(mipi, ST7586_SET_PART_DISP, 0xa0); > + mipi_dbi_command(mipi, MIPI_DCS_SET_PARTIAL_AREA, 0x00, 0x00, 0x00, 0x77); > + mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE); > + > + msleep(100); > + > + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON); > + > + mipi->enabled = true; > + > + if (fb) > + fb->funcs->dirty(fb, NULL, 0, 0, NULL, 0); > +} > + > +static void st7586_pipe_disable(struct drm_simple_display_pipe *pipe) > +{ > + struct tinydrm_device *tdev = pipe_to_tinydrm(pipe); > + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); > + > + DRM_DEBUG_KMS("\n"); > + > + if (!mipi->enabled) > + return; > + > + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); > + mipi->enabled = false; > +} > + > +static const u32 st7586_formats[] = { > + DRM_FORMAT_XRGB8888, > +}; > + > +static int st7586_init(struct device *dev, struct mipi_dbi *mipi, > + const struct drm_simple_display_pipe_funcs *pipe_funcs, > + struct drm_driver *driver, const struct drm_display_mode *mode, > + unsigned int rotation) > +{ > + size_t bufsize = (mode->vdisplay + 2) / 3 * mode->hdisplay; > + struct tinydrm_device *tdev = &mipi->tinydrm; > + int ret; > + > + mutex_init(&mipi->cmdlock); > + > + mipi->tx_buf = devm_kmalloc(dev, bufsize, GFP_KERNEL); > + if (!mipi->tx_buf) > + return -ENOMEM; > + > + ret = devm_tinydrm_init(dev, tdev, &st7586_fb_funcs, driver); > + if (ret) > + return ret; > + > + ret = tinydrm_display_pipe_init(tdev, pipe_funcs, > + DRM_MODE_CONNECTOR_VIRTUAL, > + st7586_formats, > + ARRAY_SIZE(st7586_formats), > + mode, rotation); > + if (ret) > + return ret; > + > + tdev->drm->mode_config.preferred_depth = 32; > + mipi->rotation = rotation; > + > + drm_mode_config_reset(tdev->drm); > + > + DRM_DEBUG_KMS("preferred_depth=%u, rotation = %u\n", > + tdev->drm->mode_config.preferred_depth, rotation); > + > + return 0; > +} > + > +static const struct drm_simple_display_pipe_funcs st7586_pipe_funcs = { > + .enable = st7586_pipe_enable, > + .disable = st7586_pipe_disable, > + .update = tinydrm_display_pipe_update, > + .prepare_fb = tinydrm_display_pipe_prepare_fb, > +}; > + > +static const struct drm_display_mode st7586_mode = { > + TINYDRM_MODE(178, 128, 37, 27), > +}; > + > +DEFINE_DRM_GEM_CMA_FOPS(st7586_fops); > + > +static struct drm_driver st7586_driver = { > + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | > + DRIVER_ATOMIC, > + .fops = &st7586_fops, > + TINYDRM_GEM_DRIVER_OPS, > + .lastclose = tinydrm_lastclose, > + .debugfs_init = mipi_dbi_debugfs_init, > + .name = "st7586", > + .desc = "Sitronix ST7586", > + .date = "20170801", > + .major = 1, > + .minor = 0, > +}; > + > +static const struct of_device_id st7586_of_match[] = { > + { .compatible = "lego,ev3-lcd" }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, st7586_of_match); > + > +static const struct spi_device_id st7586_id[] = { > + { "ev3-lcd", 0 }, > + { }, > +}; > +MODULE_DEVICE_TABLE(spi, st7586_id); > + > +static int st7586_probe(struct spi_device *spi) > +{ > + struct device *dev = &spi->dev; > + struct tinydrm_device *tdev; > + struct mipi_dbi *mipi; > + struct gpio_desc *a0; > + u32 rotation = 0; > + int ret; > + > + mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL); > + if (!mipi) > + return -ENOMEM; > + > + mipi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); > + if (IS_ERR(mipi->reset)) { > + dev_err(dev, "Failed to get gpio 'reset'\n"); > + return PTR_ERR(mipi->reset); > + } > + > + a0 = devm_gpiod_get(dev, "a0", GPIOD_OUT_LOW); > + if (IS_ERR(a0)) { > + dev_err(dev, "Failed to get gpio 'a0'\n"); > + return PTR_ERR(a0); > + } > + > + device_property_read_u32(dev, "rotation", &rotation); > + > + ret = mipi_dbi_spi_init(spi, mipi, a0); > + if (ret) > + return ret; > + > + /* Cannot read from this controller via SPI */ > + mipi->read_commands = NULL; > + > + /* > + * we are using 8-bit data, so we are not actually swapping anything, > + * but setting mipi->swap_bytes makes mipi_dbi_typec3_command() do the > + * right thing and not use 16-bit transfers (which results in swapped > + * bytes on little-endian systems and causes out of order data to be > + * sent to the display). > + */ > + mipi->swap_bytes = true; > + > + ret = st7586_init(&spi->dev, mipi, &st7586_pipe_funcs, &st7586_driver, > + &st7586_mode, rotation); > + if (ret) > + return ret; > + > + tdev = &mipi->tinydrm; > + > + ret = devm_tinydrm_register(tdev); > + if (ret) > + return ret; > + > + spi_set_drvdata(spi, mipi); > + > + DRM_DEBUG_DRIVER("Initialized %s:%s @%uMHz on minor %d\n", > + tdev->drm->driver->name, dev_name(dev), > + spi->max_speed_hz / 1000000, > + tdev->drm->primary->index); > + > + return 0; > +} > + > +static void st7586_shutdown(struct spi_device *spi) > +{ > + struct mipi_dbi *mipi = spi_get_drvdata(spi); > + > + tinydrm_shutdown(&mipi->tinydrm); > +} > + > +static struct spi_driver st7586_spi_driver = { > + .driver = { > + .name = "st7586", > + .owner = THIS_MODULE, > + .of_match_table = st7586_of_match, > + }, > + .id_table = st7586_id, > + .probe = st7586_probe, > + .shutdown = st7586_shutdown, > +}; > +module_spi_driver(st7586_spi_driver); > + > +MODULE_DESCRIPTION("Sitronix ST7586 DRM driver"); > +MODULE_AUTHOR("David Lechner <david@lechnology.com>"); > +MODULE_LICENSE("GPL"); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD 2017-08-09 17:59 ` Noralf Trønnes @ 2017-08-11 16:40 ` Noralf Trønnes 0 siblings, 0 replies; 11+ messages in thread From: Noralf Trønnes @ 2017-08-11 16:40 UTC (permalink / raw) To: David Lechner, dri-devel, devicetree Cc: Mark Rutland, Kevin Hilman, Sekhar Nori, linux-kernel, Rob Herring, Laurent Pinchart, linux-arm-kernel Den 09.08.2017 19.59, skrev Noralf Trønnes: > > Den 07.08.2017 19.39, skrev David Lechner: >> LEGO MINDSTORMS EV3 has an LCD with a ST7586 controller. This adds a new >> module for the ST7586 controller with parameters for the LEGO MINDSTORMS >> EV3 LCD display. >> >> Signed-off-by: David Lechner <david@lechnology.com> >> --- > > This looks good, even I understand the pixel packing now :-) > Now we wait for the DT maintainers to have their say. > > Reviewed-by: Noralf Trønnes <noralf@tronnes.org> > Thanks, applied to drm-misc together with dt binding. Noralf. >> v4 changes: >> * correct order for MAINTAINERS entry >> * Drop code not used by LEGO EV3 (regulator, backlight, suspend/resume) >> * Make gpios required >> * Use lookup table for pixel packing algorithm >> * Don't modify clip when used as function parameter >> * Use roundup/rounddown macros >> >> >> MAINTAINERS | 6 + >> drivers/gpu/drm/tinydrm/Kconfig | 10 + >> drivers/gpu/drm/tinydrm/Makefile | 1 + >> drivers/gpu/drm/tinydrm/st7586.c | 428 >> +++++++++++++++++++++++++++++++++++++++ >> 4 files changed, 445 insertions(+) >> create mode 100644 drivers/gpu/drm/tinydrm/st7586.c >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index a1e772e..19ca3e6 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -4380,6 +4380,12 @@ S: Orphan / Obsolete >> F: drivers/gpu/drm/sis/ >> F: include/uapi/drm/sis_drm.h >> +DRM DRIVER FOR SITRONIX ST7586 PANELS >> +M: David Lechner <david@lechnology.com> >> +S: Maintained >> +F: drivers/gpu/drm/tinydrm/st7586.c >> +F: Documentation/devicetree/bindings/display/st7586.txt >> + >> DRM DRIVER FOR TDFX VIDEO CARDS >> S: Orphan / Obsolete >> F: drivers/gpu/drm/tdfx/ >> diff --git a/drivers/gpu/drm/tinydrm/Kconfig >> b/drivers/gpu/drm/tinydrm/Kconfig >> index f17c3ca..2e790e7 100644 >> --- a/drivers/gpu/drm/tinydrm/Kconfig >> +++ b/drivers/gpu/drm/tinydrm/Kconfig >> @@ -32,3 +32,13 @@ config TINYDRM_REPAPER >> 2.71" TFT EPD Panel (E2271CS021) >> If M is selected the module will be called repaper. >> + >> +config TINYDRM_ST7586 >> + tristate "DRM support for Sitronix ST7586 display panels" >> + depends on DRM_TINYDRM && SPI >> + select TINYDRM_MIPI_DBI >> + help >> + DRM driver for the following Sitronix ST7586 panels: >> + * LEGO MINDSTORMS EV3 >> + >> + If M is selected the module will be called st7586. >> diff --git a/drivers/gpu/drm/tinydrm/Makefile >> b/drivers/gpu/drm/tinydrm/Makefile >> index 95bb4d4..0c184bd 100644 >> --- a/drivers/gpu/drm/tinydrm/Makefile >> +++ b/drivers/gpu/drm/tinydrm/Makefile >> @@ -6,3 +6,4 @@ obj-$(CONFIG_TINYDRM_MIPI_DBI) += mipi-dbi.o >> # Displays >> obj-$(CONFIG_TINYDRM_MI0283QT) += mi0283qt.o >> obj-$(CONFIG_TINYDRM_REPAPER) += repaper.o >> +obj-$(CONFIG_TINYDRM_ST7586) += st7586.o >> diff --git a/drivers/gpu/drm/tinydrm/st7586.c >> b/drivers/gpu/drm/tinydrm/st7586.c >> new file mode 100644 >> index 0000000..1b39d3f >> --- /dev/null >> +++ b/drivers/gpu/drm/tinydrm/st7586.c >> @@ -0,0 +1,428 @@ >> +/* >> + * DRM driver for Sitronix ST7586 panels >> + * >> + * Copyright 2017 David Lechner <david@lechnology.com> >> + * >> + * This program is free software; you can redistribute it and/or modify >> + * it under the terms of the GNU General Public License as published by >> + * the Free Software Foundation; either version 2 of the License, or >> + * (at your option) any later version. >> + */ >> + >> +#include <linux/delay.h> >> +#include <linux/dma-buf.h> >> +#include <linux/gpio/consumer.h> >> +#include <linux/module.h> >> +#include <linux/property.h> >> +#include <linux/spi/spi.h> >> +#include <video/mipi_display.h> >> + >> +#include <drm/tinydrm/mipi-dbi.h> >> +#include <drm/tinydrm/tinydrm-helpers.h> >> + >> +/* controller-specific commands */ >> +#define ST7586_DISP_MODE_GRAY 0x38 >> +#define ST7586_DISP_MODE_MONO 0x39 >> +#define ST7586_ENABLE_DDRAM 0x3a >> +#define ST7586_SET_DISP_DUTY 0xb0 >> +#define ST7586_SET_PART_DISP 0xb4 >> +#define ST7586_SET_NLINE_INV 0xb5 >> +#define ST7586_SET_VOP 0xc0 >> +#define ST7586_SET_BIAS_SYSTEM 0xc3 >> +#define ST7586_SET_BOOST_LEVEL 0xc4 >> +#define ST7586_SET_VOP_OFFSET 0xc7 >> +#define ST7586_ENABLE_ANALOG 0xd0 >> +#define ST7586_AUTO_READ_CTRL 0xd7 >> +#define ST7586_OTP_RW_CTRL 0xe0 >> +#define ST7586_OTP_CTRL_OUT 0xe1 >> +#define ST7586_OTP_READ 0xe3 >> + >> +#define ST7586_DISP_CTRL_MX BIT(6) >> +#define ST7586_DISP_CTRL_MY BIT(7) >> + >> +/* >> + * The ST7586 controller has an unusual pixel format where 2bpp >> grayscale is >> + * packed 3 pixels per byte with the first two pixels using 3 bits >> and the 3rd >> + * pixel using only 2 bits. >> + * >> + * | D7 | D6 | D5 || | || 2bpp | >> + * | (D4) | (D3) | (D2) || D1 | D0 || GRAY | >> + * +------+------+------++------+------++------+ >> + * | 1 | 1 | 1 || 1 | 1 || 0 0 | black >> + * | 1 | 0 | 0 || 1 | 0 || 0 1 | dark gray >> + * | 0 | 1 | 0 || 0 | 1 || 1 0 | light gray >> + * | 0 | 0 | 0 || 0 | 0 || 1 1 | white >> + */ >> + >> +static const u8 st7586_lookup[] = { 0x7, 0x4, 0x2, 0x0 }; >> + >> +static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr, >> + struct drm_framebuffer *fb, >> + struct drm_clip_rect *clip) >> +{ >> + size_t len = (clip->x2 - clip->x1) * (clip->y2 - clip->y1); >> + unsigned int x, y; >> + u8 *src, *buf, val; >> + >> + buf = kmalloc(len, GFP_KERNEL); >> + if (!buf) >> + return; >> + >> + tinydrm_xrgb8888_to_gray8(buf, vaddr, fb, clip); >> + src = buf; >> + >> + for (y = clip->y1; y < clip->y2; y++) { >> + for (x = clip->x1; x < clip->x2; x += 3) { >> + val = st7586_lookup[*src++ >> 6] << 5; >> + val |= st7586_lookup[*src++ >> 6] << 2; >> + val |= st7586_lookup[*src++ >> 6] >> 1; >> + *dst++ = val; >> + } >> + } >> + >> + kfree(buf); >> +} >> + >> +static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb, >> + struct drm_clip_rect *clip) >> +{ >> + struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); >> + struct dma_buf_attachment *import_attach = >> cma_obj->base.import_attach; >> + void *src = cma_obj->vaddr; >> + int ret = 0; >> + >> + if (import_attach) { >> + ret = dma_buf_begin_cpu_access(import_attach->dmabuf, >> + DMA_FROM_DEVICE); >> + if (ret) >> + return ret; >> + } >> + >> + st7586_xrgb8888_to_gray332(dst, src, fb, clip); >> + >> + if (import_attach) >> + ret = dma_buf_end_cpu_access(import_attach->dmabuf, >> + DMA_FROM_DEVICE); >> + >> + return ret; >> +} >> + >> +static int st7586_fb_dirty(struct drm_framebuffer *fb, >> + struct drm_file *file_priv, unsigned int flags, >> + unsigned int color, struct drm_clip_rect *clips, >> + unsigned int num_clips) >> +{ >> + struct tinydrm_device *tdev = fb->dev->dev_private; >> + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); >> + struct drm_clip_rect clip; >> + int start, end; >> + int ret = 0; >> + >> + mutex_lock(&tdev->dirty_lock); >> + >> + if (!mipi->enabled) >> + goto out_unlock; >> + >> + /* fbdev can flush even when we're not interested */ >> + if (tdev->pipe.plane.fb != fb) >> + goto out_unlock; >> + >> + tinydrm_merge_clips(&clip, clips, num_clips, flags, fb->width, >> + fb->height); >> + >> + /* 3 pixels per byte, so grow clip to nearest multiple of 3 */ >> + clip.x1 = rounddown(clip.x1, 3); >> + clip.x2 = roundup(clip.x2, 3); >> + >> + DRM_DEBUG("Flushing [FB:%d] x1=%u, x2=%u, y1=%u, y2=%u\n", >> fb->base.id, >> + clip.x1, clip.x2, clip.y1, clip.y2); >> + >> + ret = st7586_buf_copy(mipi->tx_buf, fb, &clip); >> + if (ret) >> + goto out_unlock; >> + >> + /* Pixels are packed 3 per byte */ >> + start = clip.x1 / 3; >> + end = clip.x2 / 3; >> + >> + mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, >> + (start >> 8) & 0xFF, start & 0xFF, >> + (end >> 8) & 0xFF, (end - 1) & 0xFF); >> + mipi_dbi_command(mipi, MIPI_DCS_SET_PAGE_ADDRESS, >> + (clip.y1 >> 8) & 0xFF, clip.y1 & 0xFF, >> + (clip.y2 >> 8) & 0xFF, (clip.y2 - 1) & 0xFF); >> + >> + ret = mipi_dbi_command_buf(mipi, MIPI_DCS_WRITE_MEMORY_START, >> + (u8 *)mipi->tx_buf, >> + (end - start) * (clip.y2 - clip.y1)); >> + >> +out_unlock: >> + mutex_unlock(&tdev->dirty_lock); >> + >> + if (ret) >> + dev_err_once(fb->dev->dev, "Failed to update display %d\n", >> + ret); >> + >> + return ret; >> +} >> + >> +static const struct drm_framebuffer_funcs st7586_fb_funcs = { >> + .destroy = drm_fb_cma_destroy, >> + .create_handle = drm_fb_cma_create_handle, >> + .dirty = st7586_fb_dirty, >> +}; >> + >> +void st7586_pipe_enable(struct drm_simple_display_pipe *pipe, >> + struct drm_crtc_state *crtc_state) >> +{ >> + struct tinydrm_device *tdev = pipe_to_tinydrm(pipe); >> + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); >> + struct drm_framebuffer *fb = pipe->plane.fb; >> + struct device *dev = tdev->drm->dev; >> + int ret; >> + u8 addr_mode; >> + >> + DRM_DEBUG_KMS("\n"); >> + >> + mipi_dbi_hw_reset(mipi); >> + ret = mipi_dbi_command(mipi, ST7586_AUTO_READ_CTRL, 0x9f); >> + if (ret) { >> + dev_err(dev, "Error sending command %d\n", ret); >> + return; >> + } >> + >> + mipi_dbi_command(mipi, ST7586_OTP_RW_CTRL, 0x00); >> + >> + msleep(10); >> + >> + mipi_dbi_command(mipi, ST7586_OTP_READ); >> + >> + msleep(20); >> + >> + mipi_dbi_command(mipi, ST7586_OTP_CTRL_OUT); >> + mipi_dbi_command(mipi, MIPI_DCS_EXIT_SLEEP_MODE); >> + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); >> + >> + msleep(50); >> + >> + mipi_dbi_command(mipi, ST7586_SET_VOP_OFFSET, 0x00); >> + mipi_dbi_command(mipi, ST7586_SET_VOP, 0xe3, 0x00); >> + mipi_dbi_command(mipi, ST7586_SET_BIAS_SYSTEM, 0x02); >> + mipi_dbi_command(mipi, ST7586_SET_BOOST_LEVEL, 0x04); >> + mipi_dbi_command(mipi, ST7586_ENABLE_ANALOG, 0x1d); >> + mipi_dbi_command(mipi, ST7586_SET_NLINE_INV, 0x00); >> + mipi_dbi_command(mipi, ST7586_DISP_MODE_GRAY); >> + mipi_dbi_command(mipi, ST7586_ENABLE_DDRAM, 0x02); >> + >> + switch (mipi->rotation) { >> + default: >> + addr_mode = 0x00; >> + break; >> + case 90: >> + addr_mode = ST7586_DISP_CTRL_MY; >> + break; >> + case 180: >> + addr_mode = ST7586_DISP_CTRL_MX | ST7586_DISP_CTRL_MY; >> + break; >> + case 270: >> + addr_mode = ST7586_DISP_CTRL_MX; >> + break; >> + } >> + mipi_dbi_command(mipi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode); >> + >> + mipi_dbi_command(mipi, ST7586_SET_DISP_DUTY, 0x7f); >> + mipi_dbi_command(mipi, ST7586_SET_PART_DISP, 0xa0); >> + mipi_dbi_command(mipi, MIPI_DCS_SET_PARTIAL_AREA, 0x00, 0x00, >> 0x00, 0x77); >> + mipi_dbi_command(mipi, MIPI_DCS_EXIT_INVERT_MODE); >> + >> + msleep(100); >> + >> + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_ON); >> + >> + mipi->enabled = true; >> + >> + if (fb) >> + fb->funcs->dirty(fb, NULL, 0, 0, NULL, 0); >> +} >> + >> +static void st7586_pipe_disable(struct drm_simple_display_pipe *pipe) >> +{ >> + struct tinydrm_device *tdev = pipe_to_tinydrm(pipe); >> + struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); >> + >> + DRM_DEBUG_KMS("\n"); >> + >> + if (!mipi->enabled) >> + return; >> + >> + mipi_dbi_command(mipi, MIPI_DCS_SET_DISPLAY_OFF); >> + mipi->enabled = false; >> +} >> + >> +static const u32 st7586_formats[] = { >> + DRM_FORMAT_XRGB8888, >> +}; >> + >> +static int st7586_init(struct device *dev, struct mipi_dbi *mipi, >> + const struct drm_simple_display_pipe_funcs *pipe_funcs, >> + struct drm_driver *driver, const struct drm_display_mode *mode, >> + unsigned int rotation) >> +{ >> + size_t bufsize = (mode->vdisplay + 2) / 3 * mode->hdisplay; >> + struct tinydrm_device *tdev = &mipi->tinydrm; >> + int ret; >> + >> + mutex_init(&mipi->cmdlock); >> + >> + mipi->tx_buf = devm_kmalloc(dev, bufsize, GFP_KERNEL); >> + if (!mipi->tx_buf) >> + return -ENOMEM; >> + >> + ret = devm_tinydrm_init(dev, tdev, &st7586_fb_funcs, driver); >> + if (ret) >> + return ret; >> + >> + ret = tinydrm_display_pipe_init(tdev, pipe_funcs, >> + DRM_MODE_CONNECTOR_VIRTUAL, >> + st7586_formats, >> + ARRAY_SIZE(st7586_formats), >> + mode, rotation); >> + if (ret) >> + return ret; >> + >> + tdev->drm->mode_config.preferred_depth = 32; >> + mipi->rotation = rotation; >> + >> + drm_mode_config_reset(tdev->drm); >> + >> + DRM_DEBUG_KMS("preferred_depth=%u, rotation = %u\n", >> + tdev->drm->mode_config.preferred_depth, rotation); >> + >> + return 0; >> +} >> + >> +static const struct drm_simple_display_pipe_funcs st7586_pipe_funcs = { >> + .enable = st7586_pipe_enable, >> + .disable = st7586_pipe_disable, >> + .update = tinydrm_display_pipe_update, >> + .prepare_fb = tinydrm_display_pipe_prepare_fb, >> +}; >> + >> +static const struct drm_display_mode st7586_mode = { >> + TINYDRM_MODE(178, 128, 37, 27), >> +}; >> + >> +DEFINE_DRM_GEM_CMA_FOPS(st7586_fops); >> + >> +static struct drm_driver st7586_driver = { >> + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | >> + DRIVER_ATOMIC, >> + .fops = &st7586_fops, >> + TINYDRM_GEM_DRIVER_OPS, >> + .lastclose = tinydrm_lastclose, >> + .debugfs_init = mipi_dbi_debugfs_init, >> + .name = "st7586", >> + .desc = "Sitronix ST7586", >> + .date = "20170801", >> + .major = 1, >> + .minor = 0, >> +}; >> + >> +static const struct of_device_id st7586_of_match[] = { >> + { .compatible = "lego,ev3-lcd" }, >> + {}, >> +}; >> +MODULE_DEVICE_TABLE(of, st7586_of_match); >> + >> +static const struct spi_device_id st7586_id[] = { >> + { "ev3-lcd", 0 }, >> + { }, >> +}; >> +MODULE_DEVICE_TABLE(spi, st7586_id); >> + >> +static int st7586_probe(struct spi_device *spi) >> +{ >> + struct device *dev = &spi->dev; >> + struct tinydrm_device *tdev; >> + struct mipi_dbi *mipi; >> + struct gpio_desc *a0; >> + u32 rotation = 0; >> + int ret; >> + >> + mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL); >> + if (!mipi) >> + return -ENOMEM; >> + >> + mipi->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); >> + if (IS_ERR(mipi->reset)) { >> + dev_err(dev, "Failed to get gpio 'reset'\n"); >> + return PTR_ERR(mipi->reset); >> + } >> + >> + a0 = devm_gpiod_get(dev, "a0", GPIOD_OUT_LOW); >> + if (IS_ERR(a0)) { >> + dev_err(dev, "Failed to get gpio 'a0'\n"); >> + return PTR_ERR(a0); >> + } >> + >> + device_property_read_u32(dev, "rotation", &rotation); >> + >> + ret = mipi_dbi_spi_init(spi, mipi, a0); >> + if (ret) >> + return ret; >> + >> + /* Cannot read from this controller via SPI */ >> + mipi->read_commands = NULL; >> + >> + /* >> + * we are using 8-bit data, so we are not actually swapping >> anything, >> + * but setting mipi->swap_bytes makes mipi_dbi_typec3_command() >> do the >> + * right thing and not use 16-bit transfers (which results in >> swapped >> + * bytes on little-endian systems and causes out of order data >> to be >> + * sent to the display). >> + */ >> + mipi->swap_bytes = true; >> + >> + ret = st7586_init(&spi->dev, mipi, &st7586_pipe_funcs, >> &st7586_driver, >> + &st7586_mode, rotation); >> + if (ret) >> + return ret; >> + >> + tdev = &mipi->tinydrm; >> + >> + ret = devm_tinydrm_register(tdev); >> + if (ret) >> + return ret; >> + >> + spi_set_drvdata(spi, mipi); >> + >> + DRM_DEBUG_DRIVER("Initialized %s:%s @%uMHz on minor %d\n", >> + tdev->drm->driver->name, dev_name(dev), >> + spi->max_speed_hz / 1000000, >> + tdev->drm->primary->index); >> + >> + return 0; >> +} >> + >> +static void st7586_shutdown(struct spi_device *spi) >> +{ >> + struct mipi_dbi *mipi = spi_get_drvdata(spi); >> + >> + tinydrm_shutdown(&mipi->tinydrm); >> +} >> + >> +static struct spi_driver st7586_spi_driver = { >> + .driver = { >> + .name = "st7586", >> + .owner = THIS_MODULE, >> + .of_match_table = st7586_of_match, >> + }, >> + .id_table = st7586_id, >> + .probe = st7586_probe, >> + .shutdown = st7586_shutdown, >> +}; >> +module_spi_driver(st7586_spi_driver); >> + >> +MODULE_DESCRIPTION("Sitronix ST7586 DRM driver"); >> +MODULE_AUTHOR("David Lechner <david@lechnology.com>"); >> +MODULE_LICENSE("GPL"); > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel > ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v4 4/5] ARM: dts: da850-lego-ev3: Add node for LCD display 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner ` (2 preceding siblings ...) 2017-08-07 17:39 ` [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD David Lechner @ 2017-08-07 17:39 ` David Lechner 2017-08-07 17:39 ` [PATCH v4 5/5] ARM: davinci_all_defconfig: enable tinydrm and ST7586 David Lechner 2017-08-22 14:02 ` [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display Sekhar Nori 5 siblings, 0 replies; 11+ messages in thread From: David Lechner @ 2017-08-07 17:39 UTC (permalink / raw) To: dri-devel, devicetree Cc: David Lechner, Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel This adds a new node for the LEGO MINDSTORMS EV3 LCD display. Signed-off-by: David Lechner <david@lechnology.com> --- v4 changes: * changed dc to a0 arch/arm/boot/dts/da850-lego-ev3.dts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm/boot/dts/da850-lego-ev3.dts b/arch/arm/boot/dts/da850-lego-ev3.dts index 45983c0..413dbd5 100644 --- a/arch/arm/boot/dts/da850-lego-ev3.dts +++ b/arch/arm/boot/dts/da850-lego-ev3.dts @@ -249,6 +249,15 @@ 0x4c 0x00000080 0x000000f0 >; }; + + ev3_lcd_pins: pinmux_lcd { + pinctrl-single,bits = < + /* SIMO, GP2[11], GP2[12], CLK */ + 0x14 0x00188100 0x00ffff00 + /* GP5[0] */ + 0x30 0x80000000 0xf0000000 + >; + }; }; &pinconf { @@ -357,6 +366,21 @@ }; }; +&spi1 { + status = "okay"; + pinctrl-0 = <&ev3_lcd_pins>; + pinctrl-names = "default"; + cs-gpios = <&gpio 44 GPIO_ACTIVE_LOW>; + + display@0{ + compatible = "lego,ev3-lcd"; + reg = <0>; + spi-max-frequency = <10000000>; + a0-gpios = <&gpio 43 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio 80 GPIO_ACTIVE_HIGH>; + }; +}; + &ehrpwm0 { status = "okay"; }; -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v4 5/5] ARM: davinci_all_defconfig: enable tinydrm and ST7586 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner ` (3 preceding siblings ...) 2017-08-07 17:39 ` [PATCH v4 4/5] ARM: dts: da850-lego-ev3: Add node for LCD display David Lechner @ 2017-08-07 17:39 ` David Lechner 2017-08-22 14:02 ` [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display Sekhar Nori 5 siblings, 0 replies; 11+ messages in thread From: David Lechner @ 2017-08-07 17:39 UTC (permalink / raw) To: dri-devel, devicetree Cc: David Lechner, Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Sekhar Nori, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel This enables the tinydrm and ST7586 panel modules used by the display on LEGO MINDSTORMS EV3. Signed-off-by: David Lechner <david@lechnology.com> --- arch/arm/configs/davinci_all_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/configs/davinci_all_defconfig b/arch/arm/configs/davinci_all_defconfig index 06e2e2a..27d9720 100644 --- a/arch/arm/configs/davinci_all_defconfig +++ b/arch/arm/configs/davinci_all_defconfig @@ -143,6 +143,8 @@ CONFIG_VIDEO_ADV7343=m CONFIG_DRM=m CONFIG_DRM_TILCDC=m CONFIG_DRM_DUMB_VGA_DAC=m +CONFIG_DRM_TINYDRM=m +CONFIG_TINYDRM_ST7586=m CONFIG_FB=y CONFIG_FIRMWARE_EDID=y CONFIG_FB_DA8XX=y -- 2.7.4 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner ` (4 preceding siblings ...) 2017-08-07 17:39 ` [PATCH v4 5/5] ARM: davinci_all_defconfig: enable tinydrm and ST7586 David Lechner @ 2017-08-22 14:02 ` Sekhar Nori 5 siblings, 0 replies; 11+ messages in thread From: Sekhar Nori @ 2017-08-22 14:02 UTC (permalink / raw) To: David Lechner, dri-devel, devicetree Cc: Noralf Trønnes, Daniel Vetter, David Airlie, Rob Herring, Mark Rutland, Kevin Hilman, Laurent Pinchart, linux-arm-kernel, linux-kernel On Monday 07 August 2017 11:09 PM, David Lechner wrote: > ARM: dts: da850-lego-ev3: Add node for LCD display > ARM: davinci_all_defconfig: enable tinydrm and ST7586 Queuing these two patches (4/5 and 5/5) through davinci tree. Thanks, Sekhar ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-08-22 14:05 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-08-07 17:39 [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display David Lechner 2017-08-07 17:39 ` [PATCH v4 1/5] drm/tinydrm: Generalize tinydrm_xrgb8888_to_gray8() David Lechner 2017-08-09 15:56 ` Noralf Trønnes 2017-08-07 17:39 ` [PATCH v4 2/5] dt-bindings: add binding for Sitronix ST7586 display panels David Lechner 2017-08-10 21:00 ` Rob Herring 2017-08-07 17:39 ` [PATCH v4 3/5] drm/tinydrm: add support for LEGO MINDSTORMS EV3 LCD David Lechner 2017-08-09 17:59 ` Noralf Trønnes 2017-08-11 16:40 ` Noralf Trønnes 2017-08-07 17:39 ` [PATCH v4 4/5] ARM: dts: da850-lego-ev3: Add node for LCD display David Lechner 2017-08-07 17:39 ` [PATCH v4 5/5] ARM: davinci_all_defconfig: enable tinydrm and ST7586 David Lechner 2017-08-22 14:02 ` [PATCH v4 0/5] Support for LEGO MINDSTORMS EV3 LCD display Sekhar Nori
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).