Skip to content

Commit a0d15cc

Browse files
tlebWolfram Sang
authored andcommitted
i2c: nomadik: switch from of_device_is_compatible() to of_match_device()
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. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 5420210 commit a0d15cc

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

drivers/i2c/busses/i2c-nomadik.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/mfd/syscon.h>
2727
#include <linux/module.h>
2828
#include <linux/of.h>
29+
#include <linux/of_device.h>
2930
#include <linux/pinctrl/consumer.h>
3031
#include <linux/pm_runtime.h>
3132
#include <linux/regmap.h>
@@ -1046,8 +1047,6 @@ static int nmk_i2c_eyeq5_probe(struct nmk_i2c_dev *priv)
10461047
struct regmap *olb;
10471048
unsigned int id;
10481049

1049-
priv->has_32b_bus = true;
1050-
10511050
olb = syscon_regmap_lookup_by_phandle_args(np, "mobileye,olb", 1, &id);
10521051
if (IS_ERR(olb))
10531052
return PTR_ERR(olb);
@@ -1068,26 +1067,46 @@ static int nmk_i2c_eyeq5_probe(struct nmk_i2c_dev *priv)
10681067
return 0;
10691068
}
10701069

1070+
#define NMK_I2C_EYEQ_FLAG_32B_BUS BIT(0)
1071+
#define NMK_I2C_EYEQ_FLAG_IS_EYEQ5 BIT(1)
1072+
1073+
static const struct of_device_id nmk_i2c_eyeq_match_table[] = {
1074+
{
1075+
.compatible = "mobileye,eyeq5-i2c",
1076+
.data = (void *)(NMK_I2C_EYEQ_FLAG_32B_BUS | NMK_I2C_EYEQ_FLAG_IS_EYEQ5),
1077+
},
1078+
};
1079+
10711080
static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
10721081
{
1073-
int ret = 0;
1074-
struct nmk_i2c_dev *priv;
1082+
struct i2c_vendor_data *vendor = id->data;
1083+
u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1;
10751084
struct device_node *np = adev->dev.of_node;
1085+
const struct of_device_id *match;
10761086
struct device *dev = &adev->dev;
1087+
unsigned long match_flags = 0;
1088+
struct nmk_i2c_dev *priv;
10771089
struct i2c_adapter *adap;
1078-
struct i2c_vendor_data *vendor = id->data;
1079-
u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1;
1090+
int ret = 0;
1091+
1092+
/*
1093+
* We do not want to attach a .of_match_table to our amba driver.
1094+
* Do not convert to device_get_match_data().
1095+
*/
1096+
match = of_match_device(nmk_i2c_eyeq_match_table, dev);
1097+
if (match)
1098+
match_flags = (unsigned long)match->data;
10801099

10811100
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
10821101
if (!priv)
10831102
return -ENOMEM;
10841103

10851104
priv->vendor = vendor;
10861105
priv->adev = adev;
1087-
priv->has_32b_bus = false;
1106+
priv->has_32b_bus = match_flags & NMK_I2C_EYEQ_FLAG_32B_BUS;
10881107
nmk_i2c_of_probe(np, priv);
10891108

1090-
if (of_device_is_compatible(np, "mobileye,eyeq5-i2c")) {
1109+
if (match_flags & NMK_I2C_EYEQ_FLAG_IS_EYEQ5) {
10911110
ret = nmk_i2c_eyeq5_probe(priv);
10921111
if (ret)
10931112
return dev_err_probe(dev, ret, "failed OLB lookup\n");

0 commit comments

Comments
 (0)