From patchwork Wed Feb 1 10:16:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihail Atanassov X-Patchwork-Id: 9549663 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 85CFF60415 for ; Wed, 1 Feb 2017 12:50:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72E281FE95 for ; Wed, 1 Feb 2017 12:50:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67A822843B; Wed, 1 Feb 2017 12:50:46 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, 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 93E6728438 for ; Wed, 1 Feb 2017 12:50:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA2E56E7AB; Wed, 1 Feb 2017 12:50:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0086.outbound.protection.outlook.com [104.47.2.86]) by gabe.freedesktop.org (Postfix) with ESMTPS id 769DC6E7AB for ; Wed, 1 Feb 2017 12:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=878u7UoHL96kKaO0I1T4bbo6+IxrF8v5yBvvHrPOOSE=; b=SpKa9urszgFprUv/Q8+yXl7a+76hlH76iJV4BpXYpkgUyzGIhdSY/iZ/0JKIkkKJa8DmzfiWbfbCaZYtuCxntfkq72+dOHGHcPH7Em0Wp7Kt/ONG4SfKVt05WJ6YyQ3Gy24bOdNZBuSHdlNe2K9elAy9JGoD3406WjQo7+JBT2M= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Mihail.Atanassov@arm.com; Received: from e110433-lin.cambridge.arm.com (217.140.96.140) by AM4PR08MB0881.eurprd08.prod.outlook.com (10.164.83.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.874.12; Wed, 1 Feb 2017 10:17:06 +0000 From: Mihail Atanassov To: Subject: [PATCH 2/2] drm: mali-dp: enable gamma support Date: Wed, 1 Feb 2017 10:16:58 +0000 Message-ID: <1485944218-14354-2-git-send-email-mihail.atanassov@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485944218-14354-1-git-send-email-mihail.atanassov@arm.com> References: <1485944218-14354-1-git-send-email-mihail.atanassov@arm.com> MIME-Version: 1.0 X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: HE1PR0202CA0044.eurprd02.prod.outlook.com (10.171.89.158) To AM4PR08MB0881.eurprd08.prod.outlook.com (10.164.83.27) X-MS-Office365-Filtering-Correlation-Id: 643ee61d-048d-4004-5f5b-08d44a8b7a03 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:AM4PR08MB0881; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0881; 3:5yzHzefZLa4yh9w1NW73T4Q4+hk8NmGfdLjgLQMezfuKJRwwCuH9aQQm3C0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N/8WyvA/7TZYbQa4WJZd0ouPolU4ehSiWCL1iPc5o4hBqfQ5r0/PjLudar6mty57g1bsOzh4XDhBufiU0RI9i1ZQ0jxUGa8Ob/Bg3gzHUIfZBwP/V4N6Qlni5qSf8wOGbS+kRycsUQh/IDLAYHHXSJX+V3kKFHBE3ykYoFZg9jjsLDNlmJhUTSgOn9qBiK0QPaLy9OGHQm2iegRYprweJceHsBuFrj9PkWP2qqPjn8c5cHxEcy; 20:uK08h9MDoEyzmJrzaxUJVOE6lfFSAU24b7XXuyKbNwLDSPha2U/GWr1MWEKpiE4++1sjYRqUeE5nyqI/a9yeyqCZ29DRQBIdNDtjnjKuk3pyX/UZPVFurIEFFzvuPeu6wvW2X51fPgQRiABRNTCtCYomWtD6hfqCtd3dBWccQSs= NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123558025)(20161123564025)(20161123562025)(20161123555025)(20161123560025)(6072148); SRVR:AM4PR08MB0881; BCL:0; PCL:0; RULEID:; SRVR:AM4PR08MB0881; X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0881; 4:D3nrKDfFJU0mnpIfAeqO/jCdt4g6EnGuaGgUG9mEzVkP7k3K6VJkzYOIX/4j8yYe96GtmZK1XzEYI30pEWkTs3UxY/uginvlaiAI/O3nUh6zt0nGWxUBhDZyW6fm3j2wQZ7/C1ggesOoU9DXBhZnrCbLSYmMvDljKLuD37GWIgvi2XS34hgmo+YneTG0DpXtQBMmVFzVDuDvwDLW3Q9SH8qnAlKyg+BNQuepqV0AGgIKwcE3izSbLkQ226o7epRxOeg1E3XiIJ6hG4Lv/DbeAWb3b2JhQeq35R1vCGxBQYKPJxZPWYoO9VLLjlnKH1QOw5LN/L+sbnRGAsu7EnLdW/Yum9aFSJ+iso+m+7okSKreKPtVEQ6eLj9nrZe9Cf+6hIGOMUuY9gP9hYv/vo8oJKEgDYwOrcuoucTKEuwWbfWO19vGcJoWpw+W+QeWATWM+4TQK03PD2xDbHYOWtVviUTCZWdeL/Qpvbv0sUob3TAt2zDNBZwcpIHZ9u2l02mbw/1n7q+MYad3Euz7qRbjjXmVlHAZyMST4q2M0NbnzXX944kJLP8x1m4BYgl2Ny4JMlgEGXmP667yXE5M42E3eU4tzilOhP7IGffbeYEraPwm6oCmmLJm1hHaJT1fd0NfrvXmBrrwlAvnyX1f4qVxCxa/x/EiPE4SjrDP65f5IiQ= X-Forefront-PRVS: 0205EDCD76 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(7916002)(39850400002)(39450400003)(39840400002)(39410400002)(199003)(189002)(54906002)(42186005)(6916009)(53936002)(105586002)(38730400001)(4326007)(5660300001)(110136003)(6666003)(2950100002)(76176999)(106356001)(575784001)(86362001)(50986999)(33646002)(6486002)(47776003)(68736007)(92566002)(2351001)(25786008)(5003940100001)(101416001)(6116002)(66066001)(36756003)(97736004)(189998001)(81156014)(305945005)(50466002)(81166006)(7736002)(3846002)(2906002)(50226002)(48376002)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB0881; H:e110433-lin.cambridge.arm.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM4PR08MB0881; 23:rG0eA8kvb7fPRijpZ2RRGg+RtHqaE7A72P8ogZUJn?= =?us-ascii?Q?OpgAyglvZLfjs8KlUdwBHS1hoN2AJuueHN0A9c4TV7ALJb3a8fBWri3Y+P5U?= =?us-ascii?Q?S12A+y/9nyqSt0hIEJZLlqT9xI/6R9mGWC8HPk9kPCySR4Ze7cjDXKDPmK5f?= =?us-ascii?Q?xbo00fCe9Sr1Z18r5JV4uF/+Z65wkrQfZPj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VgIje9SNqnHIXxfPMK5pFwmO6tdNpTlzsdt7lDSI2vKguPJ/Jt4d/Dgk1Xl?= =?us-ascii?Q?PvB+gC5Jhj9zF6PBy2MgAYz10OhCogdS0gihABfekJK8RM8cAoJOlLRZhsuz?= =?us-ascii?Q?lIGBVMut0UmH04gbphQXJBR9eil1dlC+Rlm?= X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0881; 6:hn7cwrY+lV4Xu41ZBNPpRlDGLdpSM1jgALxqKC2KaeDCwWMkB7RIJsSZFekkOvxhI9fU76giKem5zunw2utZnJz0hmnZqUR1uPxrYh39F2cSnObBbTxw1rR1Bfp6Ckj66Y2s3ISf55iVoeOrM4nu/MWBHBfp1qIiOxjtPaS+Znyj+m7Wovduc+2jAawQP3KwNN/5+4stf1BqbCu0YTqiOpKO35bP3BDEYUE8gXurZ8AQOh6xNlqR/CDoiMmEY6biJNUqPEleBxyex5qEcss14eBx6hhjCfspCszxBqjypk4Qbm7DM1TTdfmfGFGvVBpJwLU/IpWyJXxJhIPq77fmJOei2liEWNY2k1eyemk8HUK1w7rMXH/aU6oIjXiCtZR/0/6bAf85nhko9ePVHS/guGI3/CTSn45Kpl0+edR18ENtZQ9/E12QTypw/nBES1VG; 5:ftpKfQ+rjA5WPqzcl3O57dKEZvnl9CBDhVH40jA4CDDd2Zgvcm6y7xw7Bgq90GLmaMK7fTGPyK2SmsTQnBwuzcz+fNuVQM5gDBVK9pIkhm6BX1o2fsmnrWblVacgwvvcgLRhA26uwE3sQ+GUJ0r50w==; 24:tXL4WXk+OQ4xXZwFlUWZ6Xv5A6tLi/FoNuvF638pGCqDHShnkGf1QVFeRNJKQExjk6n1nNfIv/NeXVQBvPYClD/6TzqUvL9oguE1+HY8mBc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM4PR08MB0881; 7:OTd+vrwm/+km77ZH0Rxia8dBDBYctMwGHozSOQ3ZXnTZZlGWlPIu+zDbH0Ww74VsDBKS9kfO089BR6ddkv6OP0jVsxXAiu+UnN7Ub1Xu9GRZNzO2Zk58ld75qa5JFb5DJW0iklmvd+lfEcuhg1dyHA/gOGLOEAhdtSaD5VPcuhBDiZMhFOZAaqnW3Vfd0kzhJkWiIhctVmKHBk1+35+2oW1EAAAh6zMwwogeR86VzoMUBuCVuuDHEXRv2M9bar6D1DXCLwkz9v/weWxLtzZTeV+aOTHjqZzvaCfVj8D+gdHZpZrBiVkV+38qmyybSOf7pCTHm6HtQfmj1KaXwiZ+IICj8WEqUGQLJYrHfm2gM8htosZ+4gT82W2/dIdywdI0jPy7axDKWjbAD8K1GYBHsOWLkTFJxCYckj/cBHVN5QNQV+NGb96n6Qij1ASsTrin5MKi73x8uN6PKr5fsShNywpKlMJm2o90qapbcKAMOIK0qXtN3G8YZAUI/MtSpBR+t8R9GLLHouv7H1pgcTdzkmw1/W1FsjhnXRMrgLiYuba8H0dexHf0ctN/6i6xdHQ/ X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2017 10:17:06.6533 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB0881 Cc: Liviu Dudau , linux-kernel@vger.kernel.org, Mali DP Maintainers , nd@arm.com 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add gamma via the DRM GAMMA_LUT/GAMMA_LUT_SIZE CRTC properties. The expected LUT size is 4096 in order to produce as accurate a set of segments as possible. This version uses only the green channel's gamma curve to set the hardware curve on DP550/650. For the sake of simplicity, it uses the same table of coefficients for all 3 curves on DP500. Signed-off-by: Mihail Atanassov --- drivers/gpu/drm/arm/malidp_crtc.c | 130 ++++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/arm/malidp_drv.c | 52 +++++++++++++++ drivers/gpu/drm/arm/malidp_drv.h | 1 + drivers/gpu/drm/arm/malidp_hw.c | 3 + drivers/gpu/drm/arm/malidp_hw.h | 2 + drivers/gpu/drm/arm/malidp_regs.h | 19 ++++-- 6 files changed, 197 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_crtc.c b/drivers/gpu/drm/arm/malidp_crtc.c index d1cd0e7..10f79b6 100644 --- a/drivers/gpu/drm/arm/malidp_crtc.c +++ b/drivers/gpu/drm/arm/malidp_crtc.c @@ -82,6 +82,114 @@ static void malidp_crtc_disable(struct drm_crtc *crtc) clk_disable_unprepare(hwdev->pxlclk); } +static const struct gamma_curve_segment { + u16 start; + u16 end; +} segments[MALIDP_COEFFTAB_NUM_COEFFS] = { + /* sector 0 */ + { 0, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 }, + { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, + { 8, 8 }, { 9, 9 }, { 10, 10 }, { 11, 11 }, + { 12, 12 }, { 13, 13 }, { 14, 14 }, { 15, 15 }, + /* sector 1 */ + { 16, 19 }, { 20, 23 }, { 24, 27 }, { 28, 31 }, + /* sector 2 */ + { 32, 39 }, { 40, 47 }, { 48, 55 }, { 56, 63 }, + /* sector 3 */ + { 64, 79 }, { 80, 95 }, { 96, 111 }, { 112, 127 }, + /* sector 4 */ + { 128, 159 }, { 160, 191 }, { 192, 223 }, { 224, 255 }, + /* sector 5 */ + { 256, 319 }, { 320, 383 }, { 384, 447 }, { 448, 511 }, + /* sector 6 */ + { 512, 639 }, { 640, 767 }, { 768, 895 }, { 896, 1023 }, + { 1024, 1151 }, { 1152, 1279 }, { 1280, 1407 }, { 1408, 1535 }, + { 1536, 1663 }, { 1664, 1791 }, { 1792, 1919 }, { 1920, 2047 }, + { 2048, 2175 }, { 2176, 2303 }, { 2304, 2431 }, { 2432, 2559 }, + { 2560, 2687 }, { 2688, 2815 }, { 2816, 2943 }, { 2944, 3071 }, + { 3072, 3199 }, { 3200, 3327 }, { 3328, 3455 }, { 3456, 3583 }, + { 3584, 3711 }, { 3712, 3839 }, { 3840, 3967 }, { 3968, 4095 }, +}; + +#define DE_COEFTAB_DATA(a, b) ((((a) & 0xfff) << 16) | (((b) & 0xfff))) + +static void malidp_generate_gamma_table(struct drm_property_blob *lut_blob, + u32 coeffs[MALIDP_COEFFTAB_NUM_COEFFS]) +{ + struct drm_color_lut *lut = (struct drm_color_lut *)lut_blob->data; + int i; + + for (i = 0; i < MALIDP_COEFFTAB_NUM_COEFFS; ++i) { + u32 a, b; + u32 delta_in; + u32 out_start, out_end; + + delta_in = segments[i].end - segments[i].start; + /* DP has 12-bit internal precision for its LUTs. */ + out_start = drm_color_lut_extract(lut[segments[i].start].green, + 12); + out_end = drm_color_lut_extract(lut[segments[i].end].green, 12); + a = (delta_in == 0) ? + 0 : ((out_end - out_start) * 256) / delta_in; + b = out_start; + coeffs[i] = DE_COEFTAB_DATA(a, b); + } +} + +/* + * Check if there is a new gamma LUT and if it is of an acceptable size. Also, + * reject any LUTs that use distinct red, green, and blue curves. + */ +static int malidp_crtc_atomic_check_gamma(struct drm_crtc *crtc, + struct drm_crtc_state *state) +{ + struct malidp_crtc_state *mc = to_malidp_crtc_state(state); + struct drm_color_lut *lut; + size_t lut_size; + int i; + + if (!state->color_mgmt_changed) + return 0; + + if (!state->gamma_lut) + return 0; + + if (crtc->state->gamma_lut && (crtc->state->gamma_lut->base.id == + state->gamma_lut->base.id)) + return 0; + + if (state->gamma_lut->length % sizeof(struct drm_color_lut)) + return -EINVAL; + + lut_size = state->gamma_lut->length / sizeof(struct drm_color_lut); + if (lut_size != 4096) + return -EINVAL; + + lut = (struct drm_color_lut *)state->gamma_lut->data; + for (i = 0; i < lut_size; ++i) + if (!((lut[i].red == lut[i].green) && + (lut[i].red == lut[i].blue))) + return -EINVAL; + + if (!state->mode_changed) { + int ret; + + state->mode_changed = true; + /* + * Kerneldoc for drm_atomic_helper_check_modeset mandates that + * it be invoked when the driver sets ->mode_changed. Since + * changing the gamma LUT Doesn't depend on any external + * resources, it is safe to call it only once. + */ + ret = drm_atomic_helper_check_modeset(crtc->dev, state->state); + if (ret) + return ret; + } + + malidp_generate_gamma_table(state->gamma_lut, mc->gamma_coeffs); + return 0; +} + static int malidp_crtc_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state) { @@ -91,6 +199,7 @@ static int malidp_crtc_atomic_check(struct drm_crtc *crtc, const struct drm_plane_state *pstate; u32 rot_mem_free, rot_mem_usable; int rotated_planes = 0; + int ret; /* * check if there is enough rotation memory available for planes @@ -157,6 +266,10 @@ static int malidp_crtc_atomic_check(struct drm_crtc *crtc, } } + ret = malidp_crtc_atomic_check_gamma(crtc, state); + if (ret) + return ret; + return 0; } @@ -174,6 +287,8 @@ static struct drm_crtc_state *malidp_crtc_duplicate_state(struct drm_crtc *crtc) return NULL; __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base); + memcpy(state->gamma_coeffs, cs->gamma_coeffs, + sizeof(state->gamma_coeffs)); return &state->base; } @@ -203,6 +318,7 @@ static void malidp_crtc_reset(struct drm_crtc *crtc) }; static const struct drm_crtc_funcs malidp_crtc_funcs = { + .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, @@ -238,11 +354,17 @@ int malidp_crtc_init(struct drm_device *drm) ret = drm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL, &malidp_crtc_funcs, NULL); + if (ret) + goto crtc_cleanup_planes; - if (!ret) { - drm_crtc_helper_add(&malidp->crtc, &malidp_crtc_helper_funcs); - return 0; - } + drm_crtc_helper_add(&malidp->crtc, &malidp_crtc_helper_funcs); + drm_mode_crtc_set_gamma_size(&malidp->crtc, 4096); + /* No inverse-gamma and color adjustments yet. */ + drm_crtc_enable_color_mgmt(&malidp->crtc, + 0, + false, + 4096); + return 0; crtc_cleanup_planes: malidp_de_planes_destroy(drm); diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 32f746e..a9f787d 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -33,6 +33,51 @@ #define MALIDP_CONF_VALID_TIMEOUT 250 +static void malidp_write_gamma_table(struct malidp_hw_device *hwdev, + u32 data[MALIDP_COEFFTAB_NUM_COEFFS]) +{ + int i; + /* Update all channels with a single gamma curve. */ + const u32 gamma_write_mask = GENMASK(18, 16); + /* + * Always write an entire table, so the address field in + * DE_COEFFTAB_ADDR is 0 and we can use the gamma_write_mask bitmask + * directly. + */ + malidp_hw_write(hwdev, gamma_write_mask, + hwdev->map.coeffs_base + MALIDP_COEF_TABLE_ADDR); + for (i = 0; i < MALIDP_COEFFTAB_NUM_COEFFS; ++i) + malidp_hw_write(hwdev, data[i], + hwdev->map.coeffs_base + + MALIDP_COEF_TABLE_DATA); +} + +static void malidp_atomic_commit_update_gamma(struct drm_crtc *crtc, + struct drm_crtc_state *old_state) +{ + struct malidp_drm *malidp = crtc_to_malidp_device(crtc); + struct malidp_hw_device *hwdev = malidp->dev; + + if (!crtc->state->color_mgmt_changed) + return; + + if (!crtc->state->gamma_lut) { + malidp_hw_clearbits(hwdev, + MALIDP_DISP_FUNC_GAM, + MALIDP_DE_DISPLAY_FUNC); + } else { + struct malidp_crtc_state *mc = + to_malidp_crtc_state(crtc->state); + + if (!old_state->gamma_lut || (crtc->state->gamma_lut->base.id != + old_state->gamma_lut->base.id)) + malidp_write_gamma_table(hwdev, mc->gamma_coeffs); + + malidp_hw_setbits(hwdev, MALIDP_DISP_FUNC_GAM, + MALIDP_DE_DISPLAY_FUNC); + } +} + /* * set the "config valid" bit and wait until the hardware acts on it */ @@ -89,8 +134,15 @@ static void malidp_atomic_commit_hw_done(struct drm_atomic_state *state) static void malidp_atomic_commit_tail(struct drm_atomic_state *state) { struct drm_device *drm = state->dev; + struct drm_crtc *crtc; + struct drm_crtc_state *old_crtc_state; + int i; drm_atomic_helper_commit_modeset_disables(drm, state); + + for_each_crtc_in_state(state, crtc, old_crtc_state, i) + malidp_atomic_commit_update_gamma(crtc, old_crtc_state); + drm_atomic_helper_commit_modeset_enables(drm, state); drm_atomic_helper_commit_planes(drm, state, 0); diff --git a/drivers/gpu/drm/arm/malidp_drv.h b/drivers/gpu/drm/arm/malidp_drv.h index c7a69ae..374d43e 100644 --- a/drivers/gpu/drm/arm/malidp_drv.h +++ b/drivers/gpu/drm/arm/malidp_drv.h @@ -49,6 +49,7 @@ struct malidp_plane_state { struct malidp_crtc_state { struct drm_crtc_state base; + u32 gamma_coeffs[MALIDP_COEFFTAB_NUM_COEFFS]; }; #define to_malidp_crtc_state(x) container_of(x, struct malidp_crtc_state, base) diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_hw.c index 4bdf531..5ceca17 100644 --- a/drivers/gpu/drm/arm/malidp_hw.c +++ b/drivers/gpu/drm/arm/malidp_hw.c @@ -415,6 +415,7 @@ static int malidp650_query_hw(struct malidp_hw_device *hwdev) const struct malidp_hw_device malidp_device[MALIDP_MAX_DEVICES] = { [MALIDP_500] = { .map = { + .coeffs_base = MALIDP500_COEFFS_BASE, .se_base = MALIDP500_SE_BASE, .dc_base = MALIDP500_DC_BASE, .out_depth_base = MALIDP500_OUTPUT_DEPTH, @@ -450,6 +451,7 @@ static int malidp650_query_hw(struct malidp_hw_device *hwdev) }, [MALIDP_550] = { .map = { + .coeffs_base = MALIDP550_COEFFS_BASE, .se_base = MALIDP550_SE_BASE, .dc_base = MALIDP550_DC_BASE, .out_depth_base = MALIDP550_DE_OUTPUT_DEPTH, @@ -483,6 +485,7 @@ static int malidp650_query_hw(struct malidp_hw_device *hwdev) }, [MALIDP_650] = { .map = { + .coeffs_base = MALIDP550_COEFFS_BASE, .se_base = MALIDP550_SE_BASE, .dc_base = MALIDP550_DC_BASE, .out_depth_base = MALIDP550_DE_OUTPUT_DEPTH, diff --git a/drivers/gpu/drm/arm/malidp_hw.h b/drivers/gpu/drm/arm/malidp_hw.h index 087e1202..ecff7d4 100644 --- a/drivers/gpu/drm/arm/malidp_hw.h +++ b/drivers/gpu/drm/arm/malidp_hw.h @@ -66,6 +66,8 @@ struct malidp_layer { struct malidp_hw_regmap { /* address offset of the DE register bank */ /* is always 0x0000 */ + /* address offset of the DE coefficients registers */ + const u16 coeffs_base; /* address offset of the SE registers bank */ const u16 se_base; /* address offset of the DC registers bank */ diff --git a/drivers/gpu/drm/arm/malidp_regs.h b/drivers/gpu/drm/arm/malidp_regs.h index 73fecb3..2e213c3 100644 --- a/drivers/gpu/drm/arm/malidp_regs.h +++ b/drivers/gpu/drm/arm/malidp_regs.h @@ -63,6 +63,7 @@ /* bit masks that are common between products */ #define MALIDP_CFG_VALID (1 << 0) +#define MALIDP_DISP_FUNC_GAM (1 << 0) #define MALIDP_DISP_FUNC_ILACED (1 << 8) /* register offsets for IRQ management */ @@ -92,6 +93,12 @@ #define MALIDP_DE_H_ACTIVE(x) (((x) & 0x1fff) << 0) #define MALIDP_DE_V_ACTIVE(x) (((x) & 0x1fff) << 16) +#define MALIDP_COEFFTAB_NUM_COEFFS 64 +/* register offsets relative to MALIDP5x0_COEFFS_BASE */ +#define MALIDP_COLOR_ADJ_COEF 0x00000 +#define MALIDP_COEF_TABLE_ADDR 0x00030 +#define MALIDP_COEF_TABLE_DATA 0x00034 + /* register offsets and bits specific to DP500 */ #define MALIDP500_DC_BASE 0x00000 #define MALIDP500_DC_CONTROL 0x0000c @@ -109,9 +116,11 @@ #define MALIDP500_BGND_COLOR 0x0003c #define MALIDP500_OUTPUT_DEPTH 0x00044 #define MALIDP500_YUV_RGB_COEF 0x00048 -#define MALIDP500_COLOR_ADJ_COEF 0x00078 -#define MALIDP500_COEF_TABLE_ADDR 0x000a8 -#define MALIDP500_COEF_TABLE_DATA 0x000ac +/* + * To match DP550/650, the start of the coeffs registers is + * at COLORADJ_COEFF0 instead of at YUV_RGB_COEF1. + */ +#define MALIDP500_COEFFS_BASE 0x00078 #define MALIDP500_DE_LV_BASE 0x00100 #define MALIDP500_DE_LV_PTR_BASE 0x00124 #define MALIDP500_DE_LG1_BASE 0x00200 @@ -136,9 +145,7 @@ #define MALIDP550_DE_DISP_SIDEBAND 0x00040 #define MALIDP550_DE_BGND_COLOR 0x00044 #define MALIDP550_DE_OUTPUT_DEPTH 0x0004c -#define MALIDP550_DE_COLOR_COEF 0x00050 -#define MALIDP550_DE_COEF_TABLE_ADDR 0x00080 -#define MALIDP550_DE_COEF_TABLE_DATA 0x00084 +#define MALIDP550_COEFFS_BASE 0x00050 #define MALIDP550_DE_LV1_BASE 0x00100 #define MALIDP550_DE_LV1_PTR_BASE 0x00124 #define MALIDP550_DE_LV2_BASE 0x00200