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: 10011721 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 6C7EF600CC for ; Tue, 17 Oct 2017 11:09:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DDB0205D6 for ; Tue, 17 Oct 2017 11:09:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 516F828856; Tue, 17 Oct 2017 11:09:42 +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.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B4553205D6 for ; Tue, 17 Oct 2017 11:09:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=wkM5rtT2Iuls/jVCWBrWyFBg2uYseDRZhfPOHEsKQPw=; b=XBF 3W/4yA/QmB0QRC5Fp3miyAwZmyoIEU/bS7CCYJTmmOOuVuQ65GdwyTvgRYnZokQ0eB+XchCWtivfX ODo81bOE6jwZZ45O8jgAPBdgBVaUnU7X+//zlvnLkLCx6aDu4NfVMBHnzyUg8vTmO07Wk2cL5SuEW 7VRLPi4K3ljai+XrNxqCSn5HjLq4sUMFsQGH6BDPfXJ5bCd7QBH6dLq5U5azxQxMNpORXiLvo/1qC rmOD4retxVBliCc0PNOdIQ1qhPe54PIxycUv7ZRDWGRxnoMfIC+0VXEMr4lpQAtLM34XMQCUV/jjw qWewWKHlrFW7jRHPoh4D0mu9oYe7JjA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e4Pkj-0001GG-BD; Tue, 17 Oct 2017 11:09:41 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e4Pke-0001CE-Ut for linux-arm-kernel@lists.infradead.org; Tue, 17 Oct 2017 11:09:39 +0000 Received: by mail-pf0-x242.google.com with SMTP id b79so1102814pfk.5 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=gaWAxEjC2lXNDMK3pUcpstLjnZeD9awwYA9aEdf7GtqqqN879TcAidYN4dyDQjrmhI yQLxYQTRwtuuhsdl5aXtTgLZz/R7Yu4rZy6/xT2YyyyAH1CqvPd55dz0qnAenyOSVifb naMu593MXGvpJ0yHa75UiPOMx5UzISfXWwNPpgIrLLP8Jm3+yFm9PF9AvhOloC70S2rh 3a9ck0+0pBFO3MyhbnU4+NzG+YFrjU4/6tRt0sWJs8p5VXbJihE9O/8OLrQ5rh81ARud fuIHmS2ypewpNvSeM2Lc67E2TLx+/teaCb2bwllKkxrc3n0XVuWjIPUVSwtVnXOvEJIn cpYA== X-Gm-Message-State: AMCzsaWtfulsac847GmrTFP52QdbQF8+z+gjM07CNT2Q6y87F3y0MY3t ZvHmpgFAEgOVRxqTul36jb8= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171017_040937_036093_746DD9B5 X-CRM114-Status: GOOD ( 13.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-sunxi@googlegroups.com, Jonathan Liu , linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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)