Received: by 2002:ac8:6d01:0:b0:423:7e07:f8e4 with SMTP id o1csp6631889qtt; Mon, 18 Dec 2023 02:06:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfEb6I2aALnKpXdJ0T0f33ikkohXI+/3QMG5GbvP8BKeuBzPomYx/ESamWmWSspfDTz/Yv X-Received: by 2002:a17:90a:5301:b0:28b:8734:885f with SMTP id x1-20020a17090a530100b0028b8734885fmr293136pjh.55.1702894010643; Mon, 18 Dec 2023 02:06:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702894010; cv=none; d=google.com; s=arc-20160816; b=VdoRCq37D8W5bV66vB1xbS86dasjEi2Ub+9flNH0v2ILFRcHMcn8DsWp8LjYdO6KwP e5r2DfFeOH//ZPnuTi2Ztwfg5sjarKWeGVdyY10XdtgkBlOoIn4HJhwDszn83lKjybpj jdqAYObx397YCyY7H8Jub0byup4XMztQ7/9vPR9t67LnvGa3dsAZ7oXJgrTV2SaNEXLV adskLPahvzMe8q5UFA7sbtmIPYtYdnoB1Ur+HxBydl07A0D/gemNTi5Tz74HET5TxIzK oUtXN2gq42gApIL3S+E2B+pILn5y/E6AIfUgH3SmGIseYrNyDiSTTluXi2D4JEFndpEf 1j+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ctfs7TTmgrfBBB+Gyga6B3Q8xc7HzrE3I3aO8/QApsQ=; fh=jejk4hcq7/BxBx++uS6mNE2629zToLBrV5YsK7QQT38=; b=Bhx4BYMwChrydYNMMM6TLWJy149OZlzOaQsUdVySOANmMcverWkIO543kwwSw+CNm8 3i5LLnd+uWspNQZsgyPVaZZBReFSN8dlQPyrjK73FqBCfQBYQjxfeuEUcezPUFiA6Amw eyYgh8ju/9UgR79pWLGEee+xtKLFWf4SexuxWWWWCSgMbqVkoKBAclMxrpTmDBlPmceC yhH+lU0rMUhzSQ+icBioSkjzCkpdx2Z4F02P2UgVh/3zKH8kQ+7b4PUiqMc2uf0N7TSU MLeaustwZyInThZXLRnwgOUv1Yy71DO5MlzgH0rIVxKULZbsExKgIK6cJZHTfOcw7lwA +iig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JIjgKonP; spf=pass (google.com: domain of linux-kernel+bounces-3295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o11-20020a170902d4cb00b001d3ce203f74si215269plg.6.2023.12.18.02.06.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 02:06:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JIjgKonP; spf=pass (google.com: domain of linux-kernel+bounces-3295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 625E32818F2 for ; Mon, 18 Dec 2023 10:06:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7185B12B9B; Mon, 18 Dec 2023 10:06:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JIjgKonP" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4A9D14A99; Mon, 18 Dec 2023 10:06:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A9E9C433C7; Mon, 18 Dec 2023 10:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702894003; bh=AwkgUvmIIlJRw6wjNIJtQ8AvdNLkhMFC6d/fk8gMjrg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JIjgKonPzMclEyKuNHco7lMvBubuPnpljdHzARGSMzyAU/Y3QrM9WAK6UHc0beTod XAItiK9jQmcXA/kxrT6nfsofZkyxVqsBfvjD1bsHKkj8kkUdavPyfuXdSajnszuI9y emEqal23SmNKd8XvZlsNLHsOSH/8gf55GZptxKODZvyiHpOi8FnFI+FqLKiSu298Od V57+fD7DlS8SqRxHQM2ZevCl76nw5gsgOu38Ov6oCThXEMvOSdz4ybt/nyBwBIG9I6 Lu/eI/HB0pj/JlXOkRoTG+1McuQ9KHDefdAnBBByckN8pqE2U/pWGCXZeKToYCqmHY EW4wEutjQYSXw== Date: Mon, 18 Dec 2023 11:06:40 +0100 From: Maxime Ripard To: Alex Bee Cc: Sandy Huang , Heiko =?utf-8?Q?St=C3=BCbner?= , Andy Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 19/27] drm/rockchip: inno_hdmi: Move tmds rate to connector state subclass Message-ID: References: <20231216162639.125215-1-knaerzche@gmail.com> <20231216162639.125215-20-knaerzche@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ktn4oocwkdhkmjca" Content-Disposition: inline In-Reply-To: <20231216162639.125215-20-knaerzche@gmail.com> --ktn4oocwkdhkmjca Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Sat, Dec 16, 2023 at 05:26:30PM +0100, Alex Bee wrote: > Similar to the othter members of inno_hdmi_connector_state the tmds_rate = is > not a property of the device, but of the connector state. Move it to > inno_hdmi_connector_state and make it a long to comply with the clock > framework. To get arround the issue of not having the connector state when > inno_hdmi_i2c_init is called in the bind path, getting the tmds rate is > wrapped in function which returns the fallback rate if the connector > doesn't have a state yet. >=20 > Signed-off-by: Alex Bee > --- > changes in v2: > - new patch >=20 > drivers/gpu/drm/rockchip/inno_hdmi.c | 36 +++++++++++++++++++--------- > 1 file changed, 25 insertions(+), 11 deletions(-) >=20 > diff --git a/drivers/gpu/drm/rockchip/inno_hdmi.c b/drivers/gpu/drm/rockc= hip/inno_hdmi.c > index f9bfae1e97a2..6799d24501b8 100644 > --- a/drivers/gpu/drm/rockchip/inno_hdmi.c > +++ b/drivers/gpu/drm/rockchip/inno_hdmi.c > @@ -47,14 +47,13 @@ struct inno_hdmi { > =20 > struct inno_hdmi_i2c *i2c; > struct i2c_adapter *ddc; > - > - unsigned int tmds_rate; > }; > =20 > struct inno_hdmi_connector_state { > struct drm_connector_state base; > unsigned int enc_out_format; > unsigned int colorimetry; > + unsigned long tmds_rate; > }; > =20 > static struct inno_hdmi *encoder_to_inno_hdmi(struct drm_encoder *encode= r) > @@ -133,11 +132,33 @@ static inline void hdmi_modb(struct inno_hdmi *hdmi= , u16 offset, > hdmi_writeb(hdmi, offset, temp); > } > =20 > +static unsigned long inno_hdmi_tmds_rate(struct inno_hdmi *hdmi) > +{ > + struct drm_connector *connector =3D &hdmi->connector; > + struct drm_connector_state *conn_state =3D connector->state; > + struct inno_hdmi_connector_state *inno_conn_state; > + > + if (conn_state) { > + inno_conn_state =3D to_inno_hdmi_conn_state(conn_state); > + return inno_conn_state->tmds_rate; > + } > + > + /* > + * When IP controller haven't configured to an accurate video > + * timing, then the TMDS clock source would be switched to > + * PCLK_HDMI, so we need to init the TMDS rate to PCLK rate, > + * and reconfigure the DDC clock. > + */ > + > + return clk_get_rate(hdmi->pclk); > +} > + > static void inno_hdmi_i2c_init(struct inno_hdmi *hdmi) > { > int ddc_bus_freq; > + unsigned long tmds_rate =3D inno_hdmi_tmds_rate(hdmi); > =20 > - ddc_bus_freq =3D (hdmi->tmds_rate >> 2) / HDMI_SCL_RATE; > + ddc_bus_freq =3D (tmds_rate >> 2) / HDMI_SCL_RATE; > =20 > hdmi_writeb(hdmi, DDC_BUS_FREQ_L, ddc_bus_freq & 0xFF); > hdmi_writeb(hdmi, DDC_BUS_FREQ_H, (ddc_bus_freq >> 8) & 0xFF); > @@ -431,7 +452,7 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi, > * DCLK_LCDC, so we need to init the TMDS rate to mode pixel > * clock rate, and reconfigure the DDC clock. > */ > - hdmi->tmds_rate =3D mode->clock * 1000; > + inno_conn_state->tmds_rate =3D mode->clock * 1000; > inno_hdmi_i2c_init(hdmi); > =20 > /* Unmute video and audio output */ > @@ -823,13 +844,6 @@ static int inno_hdmi_bind(struct device *dev, struct= device *master, > goto err_disable_clk; > } > =20 > - /* > - * When IP controller haven't configured to an accurate video > - * timing, then the TMDS clock source would be switched to > - * PCLK_HDMI, so we need to init the TMDS rate to PCLK rate, > - * and reconfigure the DDC clock. > - */ > - hdmi->tmds_rate =3D clk_get_rate(hdmi->pclk); > inno_hdmi_i2c_init(hdmi); I still think my patch is better there. There's two places that use the inno_hdmi.tmds_rate field: the two callers of inno_hdmi_i2c_init(). One is at bind time and needs to initialise it with a sane default since we don't have a mode set yet, the other is to update the internal clock rate while we have a mode set. Since there's a single "modeset" user, there's no need to store it in the state structure at all: it can be a local variable. And in the bind function, you're not going to use the state structure either since there's no state, and it's just a default that has no relation to the modeset code at all. Your function on the other end tries to reconcile and handle the two. But there's no reason to, it just makes the code harder to follow. Just pass the parent rate you want to init with as an argument and it's easy to read and maintain. Maxime --ktn4oocwkdhkmjca Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCZYAZsAAKCRDj7w1vZxhR xeeqAP9jWaSu4gtrIA1SHbjksa/UTSfOXdNX566r/ULPL2MxMgD/Sy+flPKM3KE5 PyZ9MW6Ch2GTdiZgVVTIWW2RsnmW9wA= =+y1P -----END PGP SIGNATURE----- --ktn4oocwkdhkmjca--