From patchwork Wed Jun 19 09:26:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lowry Li (Arm Technology China)" X-Patchwork-Id: 11003747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B65C1112C for ; Wed, 19 Jun 2019 09:26:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A438928B5F for ; Wed, 19 Jun 2019 09:26:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9887728B67; Wed, 19 Jun 2019 09:26:40 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 7412228B90 for ; Wed, 19 Jun 2019 09:26:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C27E46E32E; Wed, 19 Jun 2019 09:26:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70074.outbound.protection.outlook.com [40.107.7.74]) by gabe.freedesktop.org (Postfix) with ESMTPS id 245266E348 for ; Wed, 19 Jun 2019 09:26:36 +0000 (UTC) Received: from VI1PR08MB5488.eurprd08.prod.outlook.com (52.133.246.150) by VI1PR08MB3261.eurprd08.prod.outlook.com (52.134.30.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1987.12; Wed, 19 Jun 2019 09:26:32 +0000 Received: from VI1PR08MB5488.eurprd08.prod.outlook.com ([fe80::e9f4:59c8:9be1:910b]) by VI1PR08MB5488.eurprd08.prod.outlook.com ([fe80::e9f4:59c8:9be1:910b%4]) with mapi id 15.20.1987.014; Wed, 19 Jun 2019 09:26:32 +0000 From: "Lowry Li (Arm Technology China)" To: Liviu Dudau , "james qian wang (Arm Technology China)" , "maarten.lankhorst@linux.intel.com" , "seanpaul@chromium.org" , "airlied@linux.ie" , Brian Starkey Subject: [PATCH] drm/komeda: Adds output-color format/depth support Thread-Topic: [PATCH] drm/komeda: Adds output-color format/depth support Thread-Index: AQHVJoEVPYjDhuWz6UWhEkSkCc30oA== Date: Wed, 19 Jun 2019 09:26:32 +0000 Message-ID: <1560936357-21876-1-git-send-email-lowry.li@arm.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: SLXP216CA0072.KORP216.PROD.OUTLOOK.COM (2603:1096:100:5::34) To VI1PR08MB5488.eurprd08.prod.outlook.com (2603:10a6:803:137::22) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.9.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ed61cbcc-7779-4384-7da2-08d6f4983798 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:VI1PR08MB3261; x-ms-traffictypediagnostic: VI1PR08MB3261: nodisclaimer: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 0073BFEF03 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(366004)(396003)(39860400002)(346002)(136003)(189003)(199004)(64756008)(2906002)(66946007)(66476007)(66556008)(66446008)(6512007)(8676002)(316002)(73956011)(6486002)(6116002)(2501003)(186003)(102836004)(68736007)(6636002)(6436002)(50226002)(81156014)(110136005)(7736002)(54906003)(3846002)(305945005)(53936002)(26005)(81166006)(36756003)(256004)(14454004)(2616005)(66066001)(55236004)(5660300002)(14444005)(4326008)(476003)(2201001)(6506007)(386003)(25786009)(8936002)(86362001)(478600001)(486006)(99286004)(72206003)(71190400001)(71200400001)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB3261; H:VI1PR08MB5488.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ECqGo7Gyep3rAUTt44njZypUwa/w++j5OFzTXqmYL7DTEqhKscp3tUzhR7OnDsodsVieeZq762W7/E1bniKBLYxuFfxQFEKiWVCqXTxMd1Jy6OrOf5qYkpdwpDrRL71LCbjz7FMwf6GL7iD/291QFJacOm/QTimshHAazrMefh/6CxX2rRounerzUmli1hnhdd9wA5kMfe3HAbWjFI2xv6LR7U9knHK2wu3zvrUrZwflHvi9NzFvgeAsaeFs5qKtaJAgvzIPdC7wGVHMlJQfNaQE6EcMCa3s428UiE+bodCLjQHntO3YkohrATdun7dNCjSK+kArnu1kDgzrLV28f9sdD4NYzbFNryyu6h98LbNYVy6nl2XQ1YaQSwuqEaZPc1VQm5ze/AFHGpIhDpzKhbXaG/6alvje822/70TEB9c= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed61cbcc-7779-4384-7da2-08d6f4983798 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jun 2019 09:26:32.7593 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Lowry.Li@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3261 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aFWKzl+lbkb2ueUNcj99pcIf5u2xDqcc7UBWYcXz1Uw=; b=zIgPZI9+KzgXtKfuB0+seZO6a9zTgdn7U3/E82B9D+GacZJwUsKOsraflhptnO0h2xLwYXdYn0mSHVXVSm/+q2c5NPfPcFAJuvTqhCl0XnExeYfTqUcdeihm7O7mNVzwAFI92g/uykCTkJBeExn75USzHjJnqriIxX3Vupuhlps= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Lowry.Li@arm.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , "Jonathan Chai \(Arm Technology China\)" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin \(Arm Technology China\)" , nd Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Sets color_depth according to connector->bpc. Adds a new optional DT attribute "color-format" to represent a preferred color formats for a specific pipeline, and the select order is: YCRCB420 > YCRCB422 > YCRCB444 > RGB444 The color-format can be anyone of these 4 format, one color-format not only represent one format, but also include the lower formats, like color-format preferred_color_formats YCRCB420 YCRCB420 > YCRCB422 > YCRCB444 > RGB444 YCRCB422 YCRCB422 > YCRCB444 > RGB444 YCRCB444 YCRCB444 > RGB444 RGB444 RGB444 Then the final color_format is calculated by 3 steps: 1. calculate HW available formats. avail_formats = connector_color_formats & improc->color_formats; 2. filter out un-preferred format. avail_formats &= preferred_color_formats; 3. select the final format according to the preferred order. color_format = BIT(__fls(aval_formats)); Signed-off-by: Lowry Li (Arm Technology China) --- .../gpu/drm/arm/display/komeda/d71/d71_component.c | 14 ++++++++-- drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 27 ++++++++++++++++++ drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 32 +++++++++++++++++++++- drivers/gpu/drm/arm/display/komeda/komeda_kms.h | 2 ++ .../gpu/drm/arm/display/komeda/komeda_pipeline.h | 3 ++ .../drm/arm/display/komeda/komeda_pipeline_state.c | 31 +++++++++++++++++++++ .../drm/arm/display/komeda/komeda_wb_connector.c | 5 ++++ 7 files changed, 111 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c index 01dd426..5135577 100644 --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c @@ -955,6 +955,7 @@ static void d71_improc_update(struct komeda_component *c, to_d71_input_id(state, index)); malidp_write32(reg, BLK_SIZE, HV_SIZE(st->hsize, st->vsize)); + malidp_write32(reg, IPS_DEPTH, st->color_depth); if (crtc_st->color_mgmt_changed) { mask |= IPS_CTRL_FT | IPS_CTRL_RGB; @@ -974,8 +975,17 @@ static void d71_improc_update(struct komeda_component *c, } } - if (mask) - malidp_write32_mask(reg, BLK_CONTROL, mask, ctrl); + mask |= IPS_CTRL_YUV | IPS_CTRL_CHD422 | IPS_CTRL_CHD420; + + /* config color format */ + if (st->color_format == DRM_COLOR_FORMAT_YCRCB420) + ctrl |= IPS_CTRL_YUV | IPS_CTRL_CHD422 | IPS_CTRL_CHD420; + else if (st->color_format == DRM_COLOR_FORMAT_YCRCB422) + ctrl |= IPS_CTRL_YUV | IPS_CTRL_CHD422; + else if (st->color_format == DRM_COLOR_FORMAT_YCRCB444) + ctrl |= IPS_CTRL_YUV; + + malidp_write32_mask(reg, BLK_CONTROL, mask, ctrl); } static void d71_improc_dump(struct komeda_component *c, struct seq_file *sf) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c index cc6582f..ae67894 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c @@ -18,6 +18,33 @@ #include "komeda_dev.h" #include "komeda_kms.h" +void komeda_crtc_get_color_config(struct drm_crtc_state *crtc_st, + u32 *color_depths, u32 *color_formats) +{ + struct drm_connector *conn; + struct drm_connector_state *conn_st; + u32 conn_color_formats = ~0u; + int i, min_bpc = 31, conn_bpc = 0; + + for_each_new_connector_in_state(crtc_st->state, conn, conn_st, i) { + if (conn_st->crtc != crtc_st->crtc) + continue; + + conn_bpc = conn->display_info.bpc ? conn->display_info.bpc : 8; + conn_color_formats &= conn->display_info.color_formats; + + if (conn_bpc < min_bpc) + min_bpc = conn_bpc; + } + + /* connector doesn't config any color_format, use RGB444 as default */ + if (conn_color_formats == 0) + conn_color_formats = DRM_COLOR_FORMAT_RGB444; + + *color_depths = GENMASK(conn_bpc, 0); + *color_formats = conn_color_formats; +} + static void komeda_crtc_update_clock_ratio(struct komeda_crtc_state *kcrtc_st) { u64 pxlclk, aclk; diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c index 591da1e..a09de45 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c @@ -102,12 +102,34 @@ static void komeda_debugfs_init(struct komeda_dev *mdev) .attrs = komeda_sysfs_entries, }; +static int to_color_format(const char *str) +{ + int format; + + if (!strncmp(str, "RGB444", 7)) { + format = DRM_COLOR_FORMAT_RGB444; + } else if (!strncmp(str, "YCRCB444", 9)) { + format = DRM_COLOR_FORMAT_YCRCB444; + } else if (!strncmp(str, "YCRCB422", 9)) { + format = DRM_COLOR_FORMAT_YCRCB422; + } else if (!strncmp(str, "YCRCB420", 9)) { + format = DRM_COLOR_FORMAT_YCRCB420; + } else { + DRM_WARN("invalid color_format: %s, please set it to RGB444, YCRCB444, YCRCB422 or YCRCB420\n", + str); + format = DRM_COLOR_FORMAT_RGB444; + } + + return format; +} + static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_node *np) { struct komeda_pipeline *pipe; struct clk *clk; u32 pipe_id; - int ret = 0; + int ret = 0, color_format; + const char *str; ret = of_property_read_u32(np, "reg", &pipe_id); if (ret != 0 || pipe_id >= mdev->n_pipelines) @@ -122,6 +144,14 @@ static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_node *np) } pipe->pxlclk = clk; + /* fetch DT configured color-format, if not set, use RGB444 */ + if (!of_property_read_string(np, "color-format", &str)) + color_format = to_color_format(str); + else + color_format = DRM_COLOR_FORMAT_RGB444; + + pipe->improc->preferred_color_formats = (color_format << 1) - 1; + /* enum ports */ pipe->of_output_links[0] = of_graph_get_remote_node(np, KOMEDA_OF_PORT_OUTPUT, 0); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h b/drivers/gpu/drm/arm/display/komeda/komeda_kms.h index cf2122b..dc1d436 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_kms.h @@ -180,6 +180,8 @@ static inline bool has_flip_h(u32 rot) return !!(rotation & DRM_MODE_REFLECT_X); } +void komeda_crtc_get_color_config(struct drm_crtc_state *crtc_st, + u32 *color_depths, u32 *color_formats); unsigned long komeda_crtc_get_aclk(struct komeda_crtc_state *kcrtc_st); int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h index 9a5fc35..9e84232 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h @@ -317,6 +317,8 @@ struct komeda_splitter_state { struct komeda_improc { struct komeda_component base; u32 supported_color_formats; /* DRM_RGB/YUV444/YUV420*/ + /* the preferred order is from MSB to LSB YUV420 --> RGB444 */ + u32 preferred_color_formats; u32 supported_color_depths; /* BIT(8) | BIT(10)*/ u8 supports_degamma : 1; u8 supports_csc : 1; @@ -325,6 +327,7 @@ struct komeda_improc { struct komeda_improc_state { struct komeda_component_state base; + u8 color_format, color_depth; u16 hsize, vsize; u32 fgamma_coeffs[KOMEDA_N_GAMMA_COEFFS]; u32 ctm_coeffs[KOMEDA_N_CTM_COEFFS]; diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c index 796cae6..4523d28 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c @@ -743,6 +743,7 @@ void pipeline_composition_size(struct komeda_crtc_state *kcrtc_st, struct komeda_data_flow_cfg *dflow) { struct drm_crtc *crtc = kcrtc_st->base.crtc; + struct drm_crtc_state *crtc_st = &kcrtc_st->base; struct komeda_component_state *c_st; struct komeda_improc_state *st; @@ -756,6 +757,36 @@ void pipeline_composition_size(struct komeda_crtc_state *kcrtc_st, st->hsize = dflow->in_w; st->vsize = dflow->in_h; + if (drm_atomic_crtc_needs_modeset(crtc_st)) { + u32 output_depths, output_formats; + u32 avail_depths, avail_formats; + + komeda_crtc_get_color_config(crtc_st, &output_depths, + &output_formats); + + avail_depths = output_depths & improc->supported_color_depths; + if (avail_depths == 0) { + DRM_DEBUG_ATOMIC("No available color depths, conn depths: 0x%x & display: 0x%x\n", + output_depths, + improc->supported_color_depths); + return -EINVAL; + } + + avail_formats = output_formats & + improc->supported_color_formats & + improc->preferred_color_formats; + if (avail_formats == 0) { + DRM_DEBUG_ATOMIC("No available color_formats, conn formats 0x%x & display: 0x%x & preferred: 0x%x\n", + output_formats, + improc->supported_color_formats, + improc->preferred_color_formats); + return -EINVAL; + } + + st->color_depth = __fls(avail_depths); + st->color_format = BIT(__fls(avail_formats)); + } + if (kcrtc_st->base.color_mgmt_changed) { drm_lut_to_fgamma_coeffs(kcrtc_st->base.gamma_lut, st->fgamma_coeffs); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c index 4e26b27..6c43462 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c @@ -149,6 +149,7 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms, struct komeda_dev *mdev = kms->base.dev_private; struct komeda_wb_connector *kwb_conn; struct drm_writeback_connector *wb_conn; + struct drm_display_info *info; u32 *formats, n_formats = 0; int err; @@ -178,6 +179,10 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms, drm_connector_helper_add(&wb_conn->base, &komeda_wb_conn_helper_funcs); + info = &kwb_conn->base.base.display_info; + info->bpc = __fls(kcrtc->master->improc->supported_color_depths); + info->color_formats = kcrtc->master->improc->supported_color_formats; + kcrtc->wb_conn = kwb_conn; return 0;