From 0bb3ca6c980e8e25f8f4957920d3be3e47e7ac3e Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 16 Jun 2023 23:36:50 +0100 Subject: [PATCH] v6.3: use simple i2c probe commit a00f6d3723f5617222ab8df228228c3c2c84e3ec Author: Stephen Kitt Date: Wed Oct 12 18:36:47 2022 +0200 drivers/i2c: use simple i2c probe All these drivers have an i2c probe function which doesn't use the "struct i2c_device_id *id" parameter, so they can trivially be converted to the "probe_new" style of probe with a single argument. This is part of an ongoing transition to single-argument i2c probe functions. Old-style probe functions involve a call to i2c_match_id: in drivers/i2c/i2c-core-base.c, /* * When there are no more users of probe(), * rename probe_new to probe. */ if (driver->probe_new) status = driver->probe_new(client); else if (driver->probe) status = driver->probe(client, i2c_match_id(driver->id_table, client)); else status = -EINVAL; Drivers which don't need the second parameter can be declared using probe_new instead, avoiding the call to i2c_match_id. Drivers which do can still be converted to probe_new-style, calling i2c_match_id themselves (as is done currently for of_match_id). This change was done using the following Coccinelle script, and fixed up for whitespace changes: @ rule1 @ identifier fn; identifier client, id; @@ - static int fn(struct i2c_client *client, const struct i2c_device_id *id) + static int fn(struct i2c_client *client) { ...when != id } @ rule2 depends on rule1 @ identifier rule1.fn; identifier driver; @@ struct i2c_driver driver = { - .probe + .probe_new = ( fn | - &fn + fn ) , }; Signed-off-by: Stephen Kitt Signed-off-by: Wolfram Sang --- ac108.c | 22 +++++++++++----------- wm8960.c | 3 +-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ac108.c b/ac108.c index 9709cb8..18c987f 100644 --- a/ac108.c +++ b/ac108.c @@ -1410,7 +1410,15 @@ static const struct regmap_config ac108_regmap = { .max_register = 0xDF, .cache_type = REGCACHE_FLAT, }; -static int ac108_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i2c_id) { +static const struct i2c_device_id ac108_i2c_id[] = { + { "ac108_0", 0 }, + { "ac108_1", 1 }, + { "ac108_2", 2 }, + { "ac108_3", 3 }, + { "ac101", AC101_I2C_ID }, + { } +}; +static int ac108_i2c_probe(struct i2c_client *i2c) { struct device_node *np = i2c->dev.of_node; unsigned int val = 0; int ret = 0, index; @@ -1423,11 +1431,11 @@ static int ac108_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *i } } - index = (int)i2c_id->driver_data; + index = (int)i2c_match_id(ac108_i2c_id, i2c)->driver_data; if (index == AC101_I2C_ID) { ac10x->i2c101 = i2c; i2c_set_clientdata(i2c, ac10x); - ret = ac101_probe(i2c, i2c_id); + ret = ac101_probe(i2c, i2c_match_id(ac108_i2c_id, i2c)); if (ret) { ac10x->i2c101 = NULL; return ret; @@ -1520,14 +1528,6 @@ __ret: } } -static const struct i2c_device_id ac108_i2c_id[] = { - { "ac108_0", 0 }, - { "ac108_1", 1 }, - { "ac108_2", 2 }, - { "ac108_3", 3 }, - { "ac101", AC101_I2C_ID }, - { } -}; MODULE_DEVICE_TABLE(i2c, ac108_i2c_id); static const struct of_device_id ac108_of_match[] = { diff --git a/wm8960.c b/wm8960.c index 28ade11..187df65 100644 --- a/wm8960.c +++ b/wm8960.c @@ -1318,8 +1318,7 @@ static void wm8960_set_pdata_from_of(struct i2c_client *i2c, pdata->shared_lrclk = true; } -static int wm8960_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static int wm8960_i2c_probe(struct i2c_client *i2c) { struct wm8960_data *pdata = dev_get_platdata(&i2c->dev); struct wm8960_priv *wm8960;