mbox series

[0/6] drm/sun4i: Support color dithering for LCD panels

Message ID 20180419093225.614-1-wens@csie.org
Headers show
Series drm/sun4i: Support color dithering for LCD panels | expand

Message

Chen-Yu Tsai April 19, 2018, 9:32 a.m. UTC
Dithering is a method of approximating a color from a mixture of other
colors when the required color isn't available. It reduces color
banding artifacts that can be observed when displaying gradients
(e.g. grayscale gradients). This may occur when the image that needs
to be displayed is 24-bit but the LCD panel is a lower bit depth and
does not perform dithering on its own.

The TCON (LCD controller) found in Allwinner SoCs has hardware support
for dithering on channel 0, the channel used to feed LCD panels. This
series adds support for it.

Patch 1 reworks the mode set function for the CPU interface to pass
the encoder object, so it can be passed to other helper functions.

Patch 2 renames the dithering related register macros to reflect the
fact that dithering is only supported on channel 0.

Patch 3 adds support for dithering on all LCD panel output types.

Patch 4 adds support for Banana Pi's 7" DPI LCD panel.

Patch 5 adds a pinmux setting for RGB888 for the Allwinner A20 SoC.
This change has been sent by others before.

Patch 6 provides an example for enabling the Banana Pi 7" DPI LCD panel
on the Banana Pi M1+. This should not be merged. I will likely rework
this into an overlay in the future.

Note that I was only able to test dithering with DPI, as I do not have
other panel types. However the underlying concept and core code is the
same, as are the drm objects accessed. Nevertheless I'm hoping Jonathan
can test LVDS and Maxime can test MIPI DSI.

Also it seems pwm-backlight hardware is unusable at the moment. I'm not
sure whether the pwm-backlight or sun4i-pwm driver is to blame. I had to
manually poke the pwm registers so the LCD backlight wouldn't be
completely black.


Regards
ChenYu

Chen-Yu Tsai (5):
  drm/sun4i: tcon: Pass drm_encoder * into sun4i_tcon0_mode_set_cpu
  drm/sun4i: tcon: Rename Dithering related register macros
  drm/panel: simple: Add support for Banana Pi 7" S070WV20-CT16 panel
  ARM: dts: sun7i: add pinmux setting for RGB888 output for LCD0
  [DO NOT MERGE] ARM: dts: sun7i: bananapi-m1-plus: Enable Bananapi 7"
    800x480 RGB LCD panel

Jonathan Liu (1):
  drm/sun4i: tcon: Add dithering support for RGB565/RGB666 LCD panels

 .../display/panel/bananapi,s070wv20-ct16.txt  |  7 ++
 .../boot/dts/sun7i-a20-bananapi-m1-plus.dts   | 61 +++++++++++++++
 arch/arm/boot/dts/sun7i-a20.dtsi              | 11 +++
 drivers/gpu/drm/panel/panel-simple.c          | 25 ++++++
 drivers/gpu/drm/sun4i/sun4i_tcon.c            | 76 ++++++++++++++++---
 drivers/gpu/drm/sun4i/sun4i_tcon.h            | 27 ++++---
 6 files changed, 186 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/display/panel/bananapi,s070wv20-ct16.txt

Comments

Maxime Ripard April 19, 2018, 1:31 p.m. UTC | #1
Hi,

On Thu, Apr 19, 2018 at 05:32:22PM +0800, Chen-Yu Tsai wrote:
> From: Jonathan Liu <net147@gmail.com>
> 
> The hardware supports dithering on TCON channel 0 which is used for LCD
> panels.
> 
> Dithering is a method of approximating a color from a mixture of other
> colors when the required color isn't available. It reduces color
> banding artifacts that can be observed when displaying gradients
> (e.g. grayscale gradients). This may occur when the image that needs
> to be displayed is 24-bit but the LCD panel is a lower bit depth and
> does not perform dithering on its own.
> 
> Signed-off-by: Jonathan Liu <net147@gmail.com>
> [wens@csie.org: check display_info.bpc first; handle LVDS and MIPI DSI]
> Signed-off-by: Chen-Yu Tsai <wens@csie.org>
> ---
> 
> Hi Maxime,
> 
> The dithering parameters used here are different from the ones you used
> in your MIPI DSI series. You might want to check if it still works for
> you.
> 
> ---
>  drivers/gpu/drm/sun4i/sun4i_tcon.c | 63 +++++++++++++++++++++++++++++-
>  1 file changed, 62 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c
> index 2bd53ef7d4b8..827518f4790e 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c
> @@ -12,6 +12,7 @@
>  
>  #include <drm/drmP.h>
>  #include <drm/drm_atomic_helper.h>
> +#include <drm/drm_connector.h>
>  #include <drm/drm_crtc.h>
>  #include <drm/drm_crtc_helper.h>
>  #include <drm/drm_encoder.h>
> @@ -276,8 +277,59 @@ static void sun4i_tcon0_mode_set_common(struct sun4i_tcon *tcon,
>  		     SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
>  }
>  
> +static void sun4i_tcon0_mode_set_dithering(struct sun4i_tcon *tcon,
> +					   const struct drm_connector *connector)
> +{
> +	u32 bus_format = 0;
> +	u32 val = 0;
> +
> +	/* XXX Would this ever happen? */
> +	if (!connector)
> +		return;
> +
> +	/*
> +	 * FIXME: Undocumented bits
> +	 *
> +	 * The whole dithering process and these parameters are not
> +	 * explained in the vendor documents or BSP kernel code.
> +	 */
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PR_REG, 0x11111111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PG_REG, 0x11111111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PB_REG, 0x11111111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LR_REG, 0x11111111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LG_REG, 0x11111111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LB_REG, 0x11111111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL0_REG, 0x01010000);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL1_REG, 0x15151111);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL2_REG, 0x57575555);
> +	regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL3_REG, 0x7f7f7777);
> +
> +	/* Do dithering if panel only supports 6 bits per color */
> +	if (connector->display_info.bpc == 6)
> +		val |= SUN4I_TCON0_FRM_CTL_EN;
> +
> +	if (connector->display_info.num_bus_formats == 1)
> +		bus_format = connector->display_info.bus_formats[0];
> +
> +	/* Check the connection format */
> +	switch (bus_format) {
> +	case MEDIA_BUS_FMT_RGB565_1X16:
> +		/* R and B components are only 5 bits deep */
> +		val |= SUN4I_TCON0_FRM_CTL_MODE_R;
> +		val |= SUN4I_TCON0_FRM_CTL_MODE_B;
> +	case MEDIA_BUS_FMT_RGB666_1X18:
> +	case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
> +		/* Fall through: enable dithering */
> +		val |= SUN4I_TCON0_FRM_CTL_EN;
> +		break;
> +	}
> +
> +	/* Write dithering settings */
> +	regmap_write(tcon->regs, SUN4I_TCON_FRM_CTL_REG, val);
> +}
> +
>  static void sun4i_tcon0_mode_set_cpu(struct sun4i_tcon *tcon,
> -				     struct drm_encoder *encoder,
> +				     const struct drm_encoder *encoder,

The whole serie looks good, but that should probbaly be part of the
first patch?

Maxime
Jagan Teki Sept. 5, 2018, 1:24 p.m. UTC | #2
On Thu, Apr 19, 2018 at 3:02 PM, Chen-Yu Tsai <wens@csie.org> wrote:
> Dithering is a method of approximating a color from a mixture of other
> colors when the required color isn't available. It reduces color
> banding artifacts that can be observed when displaying gradients
> (e.g. grayscale gradients). This may occur when the image that needs
> to be displayed is 24-bit but the LCD panel is a lower bit depth and
> does not perform dithering on its own.
>
> The TCON (LCD controller) found in Allwinner SoCs has hardware support
> for dithering on channel 0, the channel used to feed LCD panels. This
> series adds support for it.
>
> Patch 1 reworks the mode set function for the CPU interface to pass
> the encoder object, so it can be passed to other helper functions.
>
> Patch 2 renames the dithering related register macros to reflect the
> fact that dithering is only supported on channel 0.
>
> Patch 3 adds support for dithering on all LCD panel output types.
>
> Patch 4 adds support for Banana Pi's 7" DPI LCD panel.
>
> Patch 5 adds a pinmux setting for RGB888 for the Allwinner A20 SoC.
> This change has been sent by others before.
>
> Patch 6 provides an example for enabling the Banana Pi 7" DPI LCD panel
> on the Banana Pi M1+. This should not be merged. I will likely rework
> this into an overlay in the future.
>
> Note that I was only able to test dithering with DPI, as I do not have
> other panel types. However the underlying concept and core code is the
> same, as are the drm objects accessed. Nevertheless I'm hoping Jonathan
> can test LVDS and Maxime can test MIPI DSI.
>
> Also it seems pwm-backlight hardware is unusable at the moment. I'm not
> sure whether the pwm-backlight or sun4i-pwm driver is to blame. I had to
> manually poke the pwm registers so the LCD backlight wouldn't be
> completely black.
>
>
> Regards
> ChenYu
>
> Chen-Yu Tsai (5):
>   drm/sun4i: tcon: Pass drm_encoder * into sun4i_tcon0_mode_set_cpu
>   drm/sun4i: tcon: Rename Dithering related register macros
>   drm/panel: simple: Add support for Banana Pi 7" S070WV20-CT16 panel
>   ARM: dts: sun7i: add pinmux setting for RGB888 output for LCD0
>   [DO NOT MERGE] ARM: dts: sun7i: bananapi-m1-plus: Enable Bananapi 7"
>     800x480 RGB LCD panel
>
> Jonathan Liu (1):
>   drm/sun4i: tcon: Add dithering support for RGB565/RGB666 LCD panels

Do you have any working branch to test this, I can't see drm probing
on linux-next, I even enabled de on dts which is missing.

Jagan.