From patchwork Tue Oct 17 11:09:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Liu X-Patchwork-Id: 10014061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9364C60215 for ; Wed, 18 Oct 2017 08:20:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 832EA28A1D for ; Wed, 18 Oct 2017 08:20:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7815E28AF1; Wed, 18 Oct 2017 08:20:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 264AE28A1D for ; Wed, 18 Oct 2017 08:20:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 460536E854; Wed, 18 Oct 2017 08:17:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C9D86E61D for ; Tue, 17 Oct 2017 11:09:16 +0000 (UTC) Received: by mail-pf0-x242.google.com with SMTP id b6so1100056pfh.7 for ; Tue, 17 Oct 2017 04:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=hR6GCKANYHyasWUp8dEp8g4zawDcMuidJsoRYh3Vt9k=; b=lCN7u2Xcz6dQ6Aij7438DxiIaSTXHtvzm2J4cuHwlQ2jp20Hah2ONieWWUg/9fXcR4 fYZ5rSqdgcI1+xOIdbSRDSxkKcoQlHNhiuljrRnGIAOaIT/iLUCPbVwJvktSiT6r51Hg 6pQIOuT8hmlfHs9n8cqGsunMj5aNFzHiSXIjtoMWlHlH13kp3VpjZD3cnULhxH5v2kEa ZHBW/gP5PXUngqgb2DoYKcEryB6nlkteIV26UClcC4BHROQ5nhw4Da8ULcVieaQscKuk G/XaUqTLmSUqey802kLrD2WKbPpG4O+mnTKG6huEHTOqc7o9vVBzDGoKWsLyhPEZQuG1 B2ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hR6GCKANYHyasWUp8dEp8g4zawDcMuidJsoRYh3Vt9k=; b=OfSRpwGFljFmVfh1xOFPOXOOeo/spOptdz0R8WE0zi4iihnzQ5g1ltF2/8Qmcz2YLb daDmsB7Tv5w4fWblVqmrK796hTgTxVapZWDnTruIu5yJQ6Zc/USsZmY4Vo+IwIFuk4F+ SeLaZX6uFt92QkUHSKzXBGUIPXvogCoxfiwgkX63Il2fGwhSf2E3iTPQuYWnD0J3i8VL qyA3H9C7Wou+hvl0Nz64cKw9m2iU9YihV6h4jZ8GUNpyG9+2nicg3lYDO6KNXAnNOzoq osbo4mEVv1vIABK9M1aQH/vY1/ys8HGPmMKYY9Bfg9w8PvlOrQGocDknDvgtqoPb/NnL RlIA== X-Gm-Message-State: AMCzsaWPwJsHJ0SOPr7O0HeHpuUmbuarrjnaqDCs2rQfe9DJ8WDxoYEq +dDlak61T0lwUrp8SzF/xz8= X-Google-Smtp-Source: AOwi7QC0jzfcIUCyELK3j7abR0e8R2G/p3Lq3SGHpraIGXtnretAJ6dQKkdaOvFeBBOQQHzpMVJBuQ== X-Received: by 10.98.64.207 with SMTP id f76mr11348723pfd.279.1508238555626; Tue, 17 Oct 2017 04:09:15 -0700 (PDT) Received: from 60-242-179-244.static.tpgi.com.au (60-242-179-244.static.tpgi.com.au. [60.242.179.244]) by smtp.gmail.com with ESMTPSA id v14sm18547198pfd.153.2017.10.17.04.09.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Oct 2017 04:09:14 -0700 (PDT) From: Jonathan Liu To: Maxime Ripard , David Airlie , Chen-Yu Tsai Subject: [PATCH] drm/sun4i: tcon: Add dithering support for RGB565/RGB666 LCD panels Date: Tue, 17 Oct 2017 22:09:46 +1100 Message-Id: <20171017110946.18961-1-net147@gmail.com> X-Mailer: git-send-email 2.14.2 X-Mailman-Approved-At: Wed, 18 Oct 2017 08:17:10 +0000 Cc: linux-sunxi@googlegroups.com, Jonathan Liu , linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Dithering is supported on TCON channel 0 which is used for LCD panels. Signed-off-by: Jonathan Liu --- drivers/gpu/drm/sun4i/sun4i_tcon.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/sun4i/sun4i_tcon.h | 18 +++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index 68751b999877..cf313ca858b3 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -12,11 +12,13 @@ #include #include +#include #include #include #include #include #include +#include #include @@ -168,7 +170,9 @@ void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon, struct drm_display_mode *mode) { unsigned int bp, hsync, vsync; + u32 bus_format = 0; u8 clk_delay; + struct drm_connector *connector = tcon->panel->connector; u32 val = 0; /* Configure the dot clock */ @@ -230,6 +234,39 @@ void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon, SUN4I_TCON0_IO_POL_HSYNC_POSITIVE | SUN4I_TCON0_IO_POL_VSYNC_POSITIVE, val); + if (connector->display_info.num_bus_formats) + bus_format = connector->display_info.bus_formats[0]; + + switch (bus_format) { + case MEDIA_BUS_FMT_RGB565_1X16: + case MEDIA_BUS_FMT_RGB666_1X18: + /* Enable dithering */ + /* FIXME: Undocumented bits */ + regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED0_REG, 0x11111111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED1_REG, 0x11111111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED2_REG, 0x11111111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED3_REG, 0x11111111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED4_REG, 0x11111111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED5_REG, 0x11111111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_TAB0_REG, 0x01010000); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_TAB1_REG, 0x15151111); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_TAB2_REG, 0x57575555); + regmap_write(tcon->regs, SUN4I_TCON0_FRM_TAB3_REG, 0x7f7f7777); + val = SUN4I_TCON0_FRM_CTL_ENABLE; + + if (bus_format == MEDIA_BUS_FMT_RGB565_1X16) { + val |= SUN4I_TCON0_FRM_CTL_MODE_R; + val |= SUN4I_TCON0_FRM_CTL_MODE_B; + } + + regmap_write(tcon->regs, SUN4I_TCON0_FRM_CTL_REG, val); + break; + default: + /* Disable dithering */ + regmap_write(tcon->regs, SUN4I_TCON0_FRM_CTL_REG, 0); + break; + } + /* Map output pins to channel 0 */ regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, SUN4I_TCON_GCTL_IOMAP_MASK, diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.h b/drivers/gpu/drm/sun4i/sun4i_tcon.h index d9e1357cc8ae..d64d45144c91 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.h +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.h @@ -31,7 +31,23 @@ #define SUN4I_TCON_GINT0_VBLANK_INT(pipe) BIT(15 - (pipe)) #define SUN4I_TCON_GINT1_REG 0x8 -#define SUN4I_TCON_FRM_CTL_REG 0x10 + +#define SUN4I_TCON0_FRM_CTL_REG 0x10 +#define SUN4I_TCON0_FRM_CTL_ENABLE BIT(31) +#define SUN4I_TCON0_FRM_CTL_MODE_R BIT(6) +#define SUN4I_TCON0_FRM_CTL_MODE_G BIT(5) +#define SUN4I_TCON0_FRM_CTL_MODE_B BIT(4) + +#define SUN4I_TCON0_FRM_SEED0_REG 0x14 +#define SUN4I_TCON0_FRM_SEED1_REG 0x18 +#define SUN4I_TCON0_FRM_SEED2_REG 0x1c +#define SUN4I_TCON0_FRM_SEED3_REG 0x20 +#define SUN4I_TCON0_FRM_SEED4_REG 0x24 +#define SUN4I_TCON0_FRM_SEED5_REG 0x28 +#define SUN4I_TCON0_FRM_TAB0_REG 0x2c +#define SUN4I_TCON0_FRM_TAB1_REG 0x30 +#define SUN4I_TCON0_FRM_TAB2_REG 0x34 +#define SUN4I_TCON0_FRM_TAB3_REG 0x38 #define SUN4I_TCON0_CTL_REG 0x40 #define SUN4I_TCON0_CTL_TCON_ENABLE BIT(31)