Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp6851491ybn; Mon, 30 Sep 2019 04:58:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqziCRW66pO2q/kA9c8P1uzY67DJ/RzZWRoYQ5C+WSWHDZm6a26JWLQfbZpNMWPky86FKsCb X-Received: by 2002:a50:a8a2:: with SMTP id k31mr18871907edc.79.1569844694711; Mon, 30 Sep 2019 04:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569844694; cv=none; d=google.com; s=arc-20160816; b=oF9oy3tdZAUm3ZvD+e0bOBJWWqQqQMyiI+1/xlfutPMBiMWAKidMPcTBKIdsLxn+V2 5R/1mFf3EMWEgZRJshOaW0wbxuQv7FvuQ8Top1NX2fBBdLwUrh3tJZF4xfCI8MOZOwzG McTOnxMDhiItGwarV+Z4T7UErGLyqxxLdElxzeeDGJpHf1SNc3bY071yE0l1C4UWlcq3 X1cDTZ6xN5jMnvRKmT2ypRJB4bYxg1y09W31wjeVXtdNuLOTpc3W+s08Dh0EBOWmEBTJ sT+p0o2e4DDvrLezcMwcCCTBLpBnz03AARbr9/3RRqeGHloT91OblJevbdDv0iIzD18q jBrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=XK+Pj//CAf98OmvrIc+Zkz8mL+/Q71gw+jEEwWOAJHE=; b=lirkxTPdQikzwWf9aNmBTIs6D5Aaim4l+yGE7Jnq+nYccMoB8NHRnIVOIdy3sM+k8P oMdaz++GwF1DX5uWAfLzvbAWYJJTp97sbr39Rf4groXlphw/wDDAZ/VolAZzCdowW0lK 9wCrEDNHx7c1pRvNe1lGnAvt3m+Qy4i4pCEoKyQB8kHS/Fv/O7GPm6WX8SEtMn10gC3l T2RvV569iZt9yUV4bf007eMzJrUrjtD6XsXn8QOOQgg3jQMhVrLmSkDxbYzOFN5/1Sfw 5cKUsyUupjr2mX5A9hjpvuCi5tGPzaq02H8gF1/ohj1urU3VyUX7qSgifO1f0a9cjei3 EkEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gz11si6898102ejb.341.2019.09.30.04.57.50; Mon, 30 Sep 2019 04:58:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730184AbfI3L40 (ORCPT + 99 others); Mon, 30 Sep 2019 07:56:26 -0400 Received: from mail-vk1-f196.google.com ([209.85.221.196]:39291 "EHLO mail-vk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727885AbfI3L40 (ORCPT ); Mon, 30 Sep 2019 07:56:26 -0400 Received: by mail-vk1-f196.google.com with SMTP id u4so2586443vkl.6 for ; Mon, 30 Sep 2019 04:56:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XK+Pj//CAf98OmvrIc+Zkz8mL+/Q71gw+jEEwWOAJHE=; b=eSInWx7WCUV6tRFSEM+Mm5SA43u6NL7pTbAwxfddk54eQzWBKylfsgrhgOziQsdOXm IOQ21HBWtwfZJjebGZM3A8zY3tA8PXQjF117U8YkiuqO6rj0XzJkd2x+/060sSoHz04t KIZsxIMH68Sln7KFDklRLcCo5pGWfN5vlF9pCVXv7P4EpSSrLmSpLSGczqDk5lVMxCLy /PO0ouSQQznA0MvOWv7cXrPwDUkgjrjIPU7qLgEcdZO92qODpCSkfcNL6dMyiHv77AMM Zw/8o84MhYkb/QcSlt3OfEf23vJd9DObaWjXCTmwUEA2uHc0nMjFkaadtF83131pcKPK 5YWA== X-Gm-Message-State: APjAAAUrMpy+5nQBl3v1Y9vuTlj1avDEMnB69Eks/Gyy5kTtzI7DFiTh q2MVRoGjZIJ2tDBZnWz7N8W/dhbZq8BLmMV3kY0= X-Received: by 2002:a1f:e387:: with SMTP id a129mr11405vkh.14.1569844585010; Mon, 30 Sep 2019 04:56:25 -0700 (PDT) MIME-Version: 1.0 References: <20190930045408.8053-1-james.qian.wang@arm.com> <20190930045408.8053-3-james.qian.wang@arm.com> <20190930110438.6w7jtw2e5s2ykwnd@DESKTOP-E1NTVVP.localdomain> In-Reply-To: <20190930110438.6w7jtw2e5s2ykwnd@DESKTOP-E1NTVVP.localdomain> From: Ilia Mirkin Date: Mon, 30 Sep 2019 07:56:13 -0400 Message-ID: Subject: Re: [PATCH 2/3] drm/komeda: Add drm_ctm_to_coeffs() To: Brian Starkey Cc: "james qian wang (Arm Technology China)" , nd , Ayan Halder , "Oscar Zhang (Arm Technology China)" , "Tiannan Zhu (Arm Technology China)" , Mihail Atanassov , "airlied@linux.ie" , Liviu Dudau , "Jonathan Chai (Arm Technology China)" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin (Arm Technology China)" , "Channing Chen (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , "Thomas Sun (Arm Technology China)" , "Lowry Li (Arm Technology China)" , "sean@poorly.run" , Ben Davis Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 30, 2019 at 7:05 AM Brian Starkey wrote: > > Hi James, > > On Mon, Sep 30, 2019 at 04:54:41AM +0000, james qian wang (Arm Technology China) wrote: > > This function is used to convert drm_color_ctm S31.32 sign-magnitude > > value to komeda required Q2.12 2's complement > > > > Signed-off-by: james qian wang (Arm Technology China) > > --- > > .../arm/display/komeda/komeda_color_mgmt.c | 27 +++++++++++++++++++ > > .../arm/display/komeda/komeda_color_mgmt.h | 1 + > > 2 files changed, 28 insertions(+) > > > > diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c > > index c180ce70c26c..c92c82eebddb 100644 > > --- a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c > > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c > > @@ -117,3 +117,30 @@ void drm_lut_to_fgamma_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs) > > { > > drm_lut_to_coeffs(lut_blob, coeffs, sector_tbl, ARRAY_SIZE(sector_tbl)); > > } > > + > > +/* Convert from S31.32 sign-magnitude to HW Q2.12 2's complement */ > > +static s32 drm_ctm_s31_32_to_q2_12(u64 input) > > +{ > > + u64 mag = (input & ~BIT_ULL(63)) >> 20; > > + bool negative = !!(input & BIT_ULL(63)); > > + u32 val; > > + > > + /* the range of signed 2s complement is [-2^n, 2^n - 1] */ > > + val = clamp_val(mag, 0, negative ? BIT(14) : BIT(14) - 1); > > + > > + return negative ? 0 - val : val; > > +} > > This function looks generally useful. Should it be in DRM core > (assuming there isn't already one there)? > > You can use a parameter to determine the number of bits desired in the > output. I suspect every driver needs to do something similar. You can see what I did for nouveau here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=88b703527ba70659365d989f29579f1292ebf9c3 (look for csc_drm_to_base) Would be great to have a common helper which correctly accounts for all the variability. Cheers, -ilia