As part of the ongoing i2c transition to the simple probe
("probe_new"), this patch uses i2c_match_id to retrieve the
driver_data for the probed device. The id parameter is thus no longer
necessary and the simple probe can be used instead.
In the context of an i2c probe, i2c_match_id with the module id table
and the probed client never returns null, so removing the null check
on the i2c_device_id pointer is safe.
The i2c id tables are moved up before the probe function, as
suggested by Wolfram Sang.
Signed-off-by: Stephen Kitt <steve@sk2.org>
Link: https://lore.kernel.org/r/20220415160613.148882-4-steve@sk2.org
Signed-off-by: Mark Brown <broonie@kernel.org>
        .non_legacy_dai_naming  = 1,
 };
 
-static int max98088_i2c_probe(struct i2c_client *i2c,
-                             const struct i2c_device_id *id)
+static const struct i2c_device_id max98088_i2c_id[] = {
+       { "max98088", MAX98088 },
+       { "max98089", MAX98089 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, max98088_i2c_id);
+
+static int max98088_i2c_probe(struct i2c_client *i2c)
 {
        struct max98088_priv *max98088;
        int ret;
+       const struct i2c_device_id *id;
 
        max98088 = devm_kzalloc(&i2c->dev, sizeof(struct max98088_priv),
                               GFP_KERNEL);
                if (PTR_ERR(max98088->mclk) == -EPROBE_DEFER)
                        return PTR_ERR(max98088->mclk);
 
+       id = i2c_match_id(max98088_i2c_id, i2c);
        max98088->devtype = id->driver_data;
 
        i2c_set_clientdata(i2c, max98088);
        return ret;
 }
 
-static const struct i2c_device_id max98088_i2c_id[] = {
-       { "max98088", MAX98088 },
-       { "max98089", MAX98089 },
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, max98088_i2c_id);
-
 #if defined(CONFIG_OF)
 static const struct of_device_id max98088_of_match[] = {
        { .compatible = "maxim,max98088" },
                .name = "max98088",
                .of_match_table = of_match_ptr(max98088_of_match),
        },
-       .probe  = max98088_i2c_probe,
+       .probe_new = max98088_i2c_probe,
        .id_table = max98088_i2c_id,
 };
 
 
        .cache_type = REGCACHE_RBTREE,
 };
 
-static int max98090_i2c_probe(struct i2c_client *i2c,
-                                const struct i2c_device_id *i2c_id)
+static const struct i2c_device_id max98090_i2c_id[] = {
+       { "max98090", MAX98090 },
+       { "max98091", MAX98091 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, max98090_i2c_id);
+
+static int max98090_i2c_probe(struct i2c_client *i2c)
 {
        struct max98090_priv *max98090;
        const struct acpi_device_id *acpi_id;
                        return -EINVAL;
                }
                driver_data = acpi_id->driver_data;
-       } else if (i2c_id) {
+       } else {
+               const struct i2c_device_id *i2c_id =
+                       i2c_match_id(max98090_i2c_id, i2c);
                driver_data = i2c_id->driver_data;
        }
 
        SET_SYSTEM_SLEEP_PM_OPS(NULL, max98090_resume)
 };
 
-static const struct i2c_device_id max98090_i2c_id[] = {
-       { "max98090", MAX98090 },
-       { "max98091", MAX98091 },
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, max98090_i2c_id);
-
 #ifdef CONFIG_OF
 static const struct of_device_id max98090_of_match[] = {
        { .compatible = "maxim,max98090", },
                .of_match_table = of_match_ptr(max98090_of_match),
                .acpi_match_table = ACPI_PTR(max98090_acpi_match),
        },
-       .probe  = max98090_i2c_probe,
+       .probe_new = max98090_i2c_probe,
        .shutdown = max98090_i2c_shutdown,
        .remove = max98090_i2c_remove,
        .id_table = max98090_i2c_id,
 
        .non_legacy_dai_naming  = 1,
 };
 
-static int max98095_i2c_probe(struct i2c_client *i2c,
-                            const struct i2c_device_id *id)
+static const struct i2c_device_id max98095_i2c_id[] = {
+       { "max98095", MAX98095 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, max98095_i2c_id);
+
+static int max98095_i2c_probe(struct i2c_client *i2c)
 {
        struct max98095_priv *max98095;
        int ret;
+       const struct i2c_device_id *id;
 
        max98095 = devm_kzalloc(&i2c->dev, sizeof(struct max98095_priv),
                                GFP_KERNEL);
                return ret;
        }
 
+       id = i2c_match_id(max98095_i2c_id, i2c);
        max98095->devtype = id->driver_data;
        i2c_set_clientdata(i2c, max98095);
        max98095->pdata = i2c->dev.platform_data;
        return ret;
 }
 
-static const struct i2c_device_id max98095_i2c_id[] = {
-       { "max98095", MAX98095 },
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, max98095_i2c_id);
-
 #ifdef CONFIG_OF
 static const struct of_device_id max98095_of_match[] = {
        { .compatible = "maxim,max98095", },
                .name = "max98095",
                .of_match_table = of_match_ptr(max98095_of_match),
        },
-       .probe  = max98095_i2c_probe,
+       .probe_new = max98095_i2c_probe,
        .id_table = max98095_i2c_id,
 };