Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: temperature: tmp117: Convert enum->pointer for data in the match tables

Convert enum->pointer for data in the match tables, so that
device_get_match_data() can do match against OF/ACPI/I2C tables, once i2c
bus type match support added to it.

Add struct tmp11x_info and replace enum->struct *tmp11x_info for data in
the match table. Drop tmp117_identify() and simplify tmp117_probe() by
replacing device_get_match_data() and id lookup for retrieving data by
i2c_get_match_data().

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
Link: https://lore.kernel.org/r/20230812161154.196555-1-biju.das.jz@bp.renesas.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Biju Das and committed by
Jonathan Cameron
fc1d297b 5a4ef20a

+44 -50
+44 -50
drivers/iio/temperature/tmp117.c
··· 42 42 s16 calibbias; 43 43 }; 44 44 45 + struct tmp11x_info { 46 + const char *name; 47 + struct iio_chan_spec const *channels; 48 + int num_channels; 49 + }; 50 + 45 51 static int tmp117_read_raw(struct iio_dev *indio_dev, 46 52 struct iio_chan_spec const *channel, int *val, 47 53 int *val2, long mask) ··· 125 119 }, 126 120 }; 127 121 122 + static const struct tmp11x_info tmp116_channels_info = { 123 + .name = "tmp116", 124 + .channels = tmp116_channels, 125 + .num_channels = ARRAY_SIZE(tmp116_channels) 126 + }; 127 + 128 + static const struct tmp11x_info tmp117_channels_info = { 129 + .name = "tmp117", 130 + .channels = tmp117_channels, 131 + .num_channels = ARRAY_SIZE(tmp117_channels) 132 + }; 133 + 128 134 static const struct iio_info tmp117_info = { 129 135 .read_raw = tmp117_read_raw, 130 136 .write_raw = tmp117_write_raw, 131 137 }; 132 138 133 - static int tmp117_identify(struct i2c_client *client) 139 + static int tmp117_probe(struct i2c_client *client) 134 140 { 135 - const struct i2c_device_id *id; 136 - unsigned long match_data; 141 + const struct tmp11x_info *match_data; 142 + struct tmp117_data *data; 143 + struct iio_dev *indio_dev; 137 144 int dev_id; 145 + 146 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 147 + return -EOPNOTSUPP; 138 148 139 149 dev_id = i2c_smbus_read_word_swapped(client, TMP117_REG_DEVICE_ID); 140 150 if (dev_id < 0) ··· 158 136 159 137 switch (dev_id) { 160 138 case TMP116_DEVICE_ID: 139 + match_data = &tmp116_channels_info; 140 + break; 161 141 case TMP117_DEVICE_ID: 162 - return dev_id; 142 + match_data = &tmp117_channels_info; 143 + break; 144 + default: 145 + dev_info(&client->dev, 146 + "Unknown device id (0x%x), use fallback compatible\n", 147 + dev_id); 148 + match_data = i2c_get_match_data(client); 163 149 } 164 150 165 - dev_info(&client->dev, "Unknown device id (0x%x), use fallback compatible\n", 166 - dev_id); 167 - 168 - match_data = (uintptr_t)device_get_match_data(&client->dev); 169 - if (match_data) 170 - return match_data; 171 - 172 - id = i2c_client_get_device_id(client); 173 - if (id) 174 - return id->driver_data; 175 - 176 - dev_err(&client->dev, "Failed to identify unsupported device\n"); 177 - 178 - return -ENODEV; 179 - } 180 - 181 - static int tmp117_probe(struct i2c_client *client) 182 - { 183 - struct tmp117_data *data; 184 - struct iio_dev *indio_dev; 185 - int ret, dev_id; 186 - 187 - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) 188 - return -EOPNOTSUPP; 189 - 190 - ret = tmp117_identify(client); 191 - if (ret < 0) 192 - return ret; 193 - 194 - dev_id = ret; 151 + if (!match_data) 152 + return dev_err_probe(&client->dev, -ENODEV, 153 + "Failed to identify unsupported device\n"); 195 154 196 155 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 197 156 if (!indio_dev) ··· 184 181 185 182 indio_dev->modes = INDIO_DIRECT_MODE; 186 183 indio_dev->info = &tmp117_info; 184 + indio_dev->channels = match_data->channels; 185 + indio_dev->num_channels = match_data->num_channels; 186 + indio_dev->name = match_data->name; 187 187 188 - switch (dev_id) { 189 - case TMP116_DEVICE_ID: 190 - indio_dev->channels = tmp116_channels; 191 - indio_dev->num_channels = ARRAY_SIZE(tmp116_channels); 192 - indio_dev->name = "tmp116"; 193 - break; 194 - case TMP117_DEVICE_ID: 195 - indio_dev->channels = tmp117_channels; 196 - indio_dev->num_channels = ARRAY_SIZE(tmp117_channels); 197 - indio_dev->name = "tmp117"; 198 - break; 199 - } 200 188 201 189 return devm_iio_device_register(&client->dev, indio_dev); 202 190 } 203 191 204 192 static const struct of_device_id tmp117_of_match[] = { 205 - { .compatible = "ti,tmp116", .data = (void *)TMP116_DEVICE_ID }, 206 - { .compatible = "ti,tmp117", .data = (void *)TMP117_DEVICE_ID }, 193 + { .compatible = "ti,tmp116", .data = &tmp116_channels_info }, 194 + { .compatible = "ti,tmp117", .data = &tmp117_channels_info }, 207 195 { } 208 196 }; 209 197 MODULE_DEVICE_TABLE(of, tmp117_of_match); 210 198 211 199 static const struct i2c_device_id tmp117_id[] = { 212 - { "tmp116", TMP116_DEVICE_ID }, 213 - { "tmp117", TMP117_DEVICE_ID }, 200 + { "tmp116", (kernel_ulong_t)&tmp116_channels_info }, 201 + { "tmp117", (kernel_ulong_t)&tmp117_channels_info }, 214 202 { } 215 203 }; 216 204 MODULE_DEVICE_TABLE(i2c, tmp117_id);