From nobody Wed Nov 27 16:55:52 2024 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 2664918E764; Wed, 9 Oct 2024 10:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728469425; cv=none; b=lNf8kXyZvfu3J4EzxmaxwTVCfX94ZeuCr5lxjHYHseHTtAhTb8sWO0+th+zenRwKP4MUHOuVtSjDhIcIQeaFMm+KRsHsGKh4NgbqPU1d/S/ELHMDPNyMU5WQjW8Lgcg1EhbGTQbp15KwTimXsp0Ogy/i5+4hRaTF3cMiW5tdXzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728469425; c=relaxed/simple; bh=QMCIUPpXqgRCwrZH7410pZ8JrhRNP9EubqVL/sVI/CI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Iy+Q9IrjO6l1GzI/KO2Don4dyQ/oXl55ZX+6GtNEDDMzpaBO1RkvRf8haSwvTIPfcPwTrKTCK0FF5N2Yf/8hvYeEFuGtqkzich6APYgnJT83L2nyJemClFGyIWsKwJhNt1OYMWW4f8cyn1f/7X06hdXKkzFBksRUFGdB/YnIF98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=CPK8keeX; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="CPK8keeX" Received: by mail.gandi.net (Postfix) with ESMTPSA id E3964C0002; Wed, 9 Oct 2024 10:23:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1728469411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0RkPb/ZmhIYMKGdFcEhqFg5pBv1BW4T9WKx57Ml1gvk=; b=CPK8keeXpLYeRc5B4XVCc9+5LgzrWTEVrhI0PvfIa/eFGmxVo4iKx89i9vd6RXM5x8xL6M tgwYN+SH9n7NCVl+0NI3tcOnQ4gO2ZOLp/jf7yiNaPFgrbIMvJ9CjRe9D29F9smL59d4Rd mIMbJG0XZmRGJH1Nc4AyOKD9NrTvYBp4/fFmj+9vFd0wqCIUN023lDdT+HjC5Fkfq78M9a Ex1K6FrwMEWxSiTGZzeVWXbSAJo2IHrpxvaDdS0tTA+Fv4Ho/OPT6o3ZBCWPunbiFUVJnW rRVbu4l48DOSU3ou2k5qjLpNZVfo810k/EcT0Ay6utwfAbWvN8dAe3yUPPo7yA== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Wed, 09 Oct 2024 12:23:29 +0200 Subject: [PATCH v2 3/6] i2c: nomadik: switch from of_device_is_compatible() to of_match_device() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241009-mbly-i2c-v2-3-ac9230a8dac5@bootlin.com> References: <20241009-mbly-i2c-v2-0-ac9230a8dac5@bootlin.com> In-Reply-To: <20241009-mbly-i2c-v2-0-ac9230a8dac5@bootlin.com> To: Linus Walleij , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Vladimir Kondratiev , =?utf-8?q?Gr=C3=A9gory_Clement?= , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.14.2 X-GND-Sasl: theo.lebrun@bootlin.com Compatible-specific behavior is implemented using a if-condition on the return value from of_device_is_compatible(), from probe. It does not scale well when compatible number increases. Switch to using a match table and a call to of_match_device(). We DO NOT attach a .of_match_table field to our amba driver, as we do not use the table to match our driver to devices. Sort probe variable declarations in reverse christmas tree to try and introduce some logic into the ordering. Signed-off-by: Th=C3=A9o Lebrun Reviewed-by: Linus Walleij --- drivers/i2c/busses/i2c-nomadik.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-noma= dik.c index ad0f02acdb1215a1c04729f97bb14a4d93f88456..c40328d1bca6cdefc61906cf916= 0f8411e37922a 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -1046,8 +1047,6 @@ static int nmk_i2c_eyeq5_probe(struct nmk_i2c_dev *pr= iv) struct regmap *olb; unsigned int id; =20 - priv->has_32b_bus =3D true; - olb =3D syscon_regmap_lookup_by_phandle_args(np, "mobileye,olb", 1, &id); if (IS_ERR(olb)) return PTR_ERR(olb); @@ -1068,15 +1067,35 @@ static int nmk_i2c_eyeq5_probe(struct nmk_i2c_dev *= priv) return 0; } =20 +#define NMK_I2C_EYEQ_FLAG_32B_BUS BIT(0) +#define NMK_I2C_EYEQ_FLAG_IS_EYEQ5 BIT(1) + +static const struct of_device_id nmk_i2c_eyeq_match_table[] =3D { + { + .compatible =3D "mobileye,eyeq5-i2c", + .data =3D (void *)(NMK_I2C_EYEQ_FLAG_32B_BUS | NMK_I2C_EYEQ_FLAG_IS_EYEQ= 5), + }, +}; + static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *i= d) { - int ret =3D 0; - struct nmk_i2c_dev *priv; - struct device_node *np =3D adev->dev.of_node; - struct device *dev =3D &adev->dev; - struct i2c_adapter *adap; struct i2c_vendor_data *vendor =3D id->data; u32 max_fifo_threshold =3D (vendor->fifodepth / 2) - 1; + struct device_node *np =3D adev->dev.of_node; + const struct of_device_id *match; + struct device *dev =3D &adev->dev; + unsigned long match_flags =3D 0; + struct nmk_i2c_dev *priv; + struct i2c_adapter *adap; + int ret =3D 0; + + /* + * We do not want to attach a .of_match_table to our amba driver. + * Do not convert to device_get_match_data(). + */ + match =3D of_match_device(nmk_i2c_eyeq_match_table, dev); + if (match) + match_flags =3D (unsigned long)match->data; =20 priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -1084,10 +1103,10 @@ static int nmk_i2c_probe(struct amba_device *adev, = const struct amba_id *id) =20 priv->vendor =3D vendor; priv->adev =3D adev; - priv->has_32b_bus =3D false; + priv->has_32b_bus =3D match_flags & NMK_I2C_EYEQ_FLAG_32B_BUS; nmk_i2c_of_probe(np, priv); =20 - if (of_device_is_compatible(np, "mobileye,eyeq5-i2c")) { + if (match_flags & NMK_I2C_EYEQ_FLAG_IS_EYEQ5) { ret =3D nmk_i2c_eyeq5_probe(priv); if (ret) return dev_err_probe(dev, ret, "failed OLB lookup\n"); --=20 2.46.2