hwmon: (max16065) Remove use of i2c_match_id()
authorAndrew Davis <afd@ti.com>
Wed, 3 Apr 2024 20:36:21 +0000 (15:36 -0500)
committerGuenter Roeck <linux@roeck-us.net>
Sat, 8 Jun 2024 23:07:33 +0000 (16:07 -0700)
The function i2c_match_id() is used to fetch the matching ID from
the i2c_device_id table. This is often used to then retrieve the
matching driver_data. This can be done in one step with the helper
i2c_get_match_data().

This helper has a couple other benefits:
 * It doesn't need the i2c_device_id passed in so we do not need
   to have that forward declared, allowing us to remove those or
   move the i2c_device_id table down to its more natural spot
   with the other module info.
 * It also checks for device match data, which allows for OF and
   ACPI based probing. That means we do not have to manually check
   those first and can remove those checks.

Signed-off-by: Andrew Davis <afd@ti.com>
Link: https://lore.kernel.org/r/20240403203633.914389-20-afd@ti.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/max16065.c

index aa38c45adc09e22122634697aab58506f29b00ae..7ce9a89f93a0d93cc09479182a940b9443b9e9fe 100644 (file)
@@ -493,8 +493,6 @@ static const struct attribute_group max16065_max_group = {
        .is_visible = max16065_secondary_is_visible,
 };
 
-static const struct i2c_device_id max16065_id[];
-
 static int max16065_probe(struct i2c_client *client)
 {
        struct i2c_adapter *adapter = client->adapter;
@@ -505,7 +503,7 @@ static int max16065_probe(struct i2c_client *client)
        bool have_secondary;            /* true if chip has secondary limits */
        bool secondary_is_max = false;  /* secondary limits reflect max */
        int groups = 0;
-       const struct i2c_device_id *id = i2c_match_id(max16065_id, client);
+       enum chips chip = (uintptr_t)i2c_get_match_data(client);
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
                                     | I2C_FUNC_SMBUS_READ_WORD_DATA))
@@ -518,9 +516,9 @@ static int max16065_probe(struct i2c_client *client)
        data->client = client;
        mutex_init(&data->update_lock);
 
-       data->num_adc = max16065_num_adc[id->driver_data];
-       data->have_current = max16065_have_current[id->driver_data];
-       have_secondary = max16065_have_secondary[id->driver_data];
+       data->num_adc = max16065_num_adc[chip];
+       data->have_current = max16065_have_current[chip];
+       have_secondary = max16065_have_secondary[chip];
 
        if (have_secondary) {
                val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE);