forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/iio/temperature/maxim_thermocouple.c
....@@ -10,8 +10,11 @@
1010 #include <linux/init.h>
1111 #include <linux/mutex.h>
1212 #include <linux/err.h>
13
+#include <linux/of.h>
14
+#include <linux/of_device.h>
1315 #include <linux/spi/spi.h>
1416 #include <linux/iio/iio.h>
17
+#include <linux/iio/sysfs.h>
1518 #include <linux/iio/trigger.h>
1619 #include <linux/iio/buffer.h>
1720 #include <linux/iio/triggered_buffer.h>
....@@ -22,13 +25,25 @@
2225 enum {
2326 MAX6675,
2427 MAX31855,
28
+ MAX31855K,
29
+ MAX31855J,
30
+ MAX31855N,
31
+ MAX31855S,
32
+ MAX31855T,
33
+ MAX31855E,
34
+ MAX31855R,
35
+};
36
+
37
+static const char maxim_tc_types[] = {
38
+ 'K', '?', 'K', 'J', 'N', 'S', 'T', 'E', 'R'
2539 };
2640
2741 static const struct iio_chan_spec max6675_channels[] = {
2842 { /* thermocouple temperature */
2943 .type = IIO_TEMP,
3044 .info_mask_separate =
31
- BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
45
+ BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) |
46
+ BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE),
3247 .scan_index = 0,
3348 .scan_type = {
3449 .sign = 's',
....@@ -46,7 +61,8 @@
4661 .type = IIO_TEMP,
4762 .address = 2,
4863 .info_mask_separate =
49
- BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
64
+ BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) |
65
+ BIT(IIO_CHAN_INFO_THERMOCOUPLE_TYPE),
5066 .scan_index = 0,
5167 .scan_type = {
5268 .sign = 's',
....@@ -108,6 +124,7 @@
108124 const struct maxim_thermocouple_chip *chip;
109125
110126 u8 buffer[16] ____cacheline_aligned;
127
+ char tc_type;
111128 };
112129
113130 static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
....@@ -192,7 +209,11 @@
192209 default:
193210 *val = 250; /* 1000 * 0.25 */
194211 ret = IIO_VAL_INT;
195
- };
212
+ }
213
+ break;
214
+ case IIO_CHAN_INFO_THERMOCOUPLE_TYPE:
215
+ *val = data->tc_type;
216
+ ret = IIO_VAL_CHAR;
196217 break;
197218 }
198219
....@@ -208,8 +229,9 @@
208229 const struct spi_device_id *id = spi_get_device_id(spi);
209230 struct iio_dev *indio_dev;
210231 struct maxim_thermocouple_data *data;
232
+ const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855;
211233 const struct maxim_thermocouple_chip *chip =
212
- &maxim_thermocouple_chips[id->driver_data];
234
+ &maxim_thermocouple_chips[chip_type];
213235 int ret;
214236
215237 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
....@@ -222,52 +244,58 @@
222244 indio_dev->available_scan_masks = chip->scan_masks;
223245 indio_dev->num_channels = chip->num_channels;
224246 indio_dev->modes = INDIO_DIRECT_MODE;
225
- indio_dev->dev.parent = &spi->dev;
226247
227248 data = iio_priv(indio_dev);
228249 data->spi = spi;
229250 data->chip = chip;
251
+ data->tc_type = maxim_tc_types[id->driver_data];
230252
231
- ret = iio_triggered_buffer_setup(indio_dev, NULL,
253
+ ret = devm_iio_triggered_buffer_setup(&spi->dev,
254
+ indio_dev, NULL,
232255 maxim_thermocouple_trigger_handler, NULL);
233256 if (ret)
234257 return ret;
235258
236
- ret = iio_device_register(indio_dev);
237
- if (ret)
238
- goto error_unreg_buffer;
259
+ if (id->driver_data == MAX31855)
260
+ dev_warn(&spi->dev, "generic max31855 ID is deprecated\nplease use more specific part type");
239261
240
- return 0;
241
-
242
-error_unreg_buffer:
243
- iio_triggered_buffer_cleanup(indio_dev);
244
-
245
- return ret;
246
-}
247
-
248
-static int maxim_thermocouple_remove(struct spi_device *spi)
249
-{
250
- struct iio_dev *indio_dev = spi_get_drvdata(spi);
251
-
252
- iio_device_unregister(indio_dev);
253
- iio_triggered_buffer_cleanup(indio_dev);
254
-
255
- return 0;
262
+ return devm_iio_device_register(&spi->dev, indio_dev);
256263 }
257264
258265 static const struct spi_device_id maxim_thermocouple_id[] = {
259266 {"max6675", MAX6675},
260267 {"max31855", MAX31855},
268
+ {"max31855k", MAX31855K},
269
+ {"max31855j", MAX31855J},
270
+ {"max31855n", MAX31855N},
271
+ {"max31855s", MAX31855S},
272
+ {"max31855t", MAX31855T},
273
+ {"max31855e", MAX31855E},
274
+ {"max31855r", MAX31855R},
261275 {},
262276 };
263277 MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id);
264278
279
+static const struct of_device_id maxim_thermocouple_of_match[] = {
280
+ { .compatible = "maxim,max6675" },
281
+ { .compatible = "maxim,max31855" },
282
+ { .compatible = "maxim,max31855k" },
283
+ { .compatible = "maxim,max31855j" },
284
+ { .compatible = "maxim,max31855n" },
285
+ { .compatible = "maxim,max31855s" },
286
+ { .compatible = "maxim,max31855t" },
287
+ { .compatible = "maxim,max31855e" },
288
+ { .compatible = "maxim,max31855r" },
289
+ { },
290
+};
291
+MODULE_DEVICE_TABLE(of, maxim_thermocouple_of_match);
292
+
265293 static struct spi_driver maxim_thermocouple_driver = {
266294 .driver = {
267295 .name = MAXIM_THERMOCOUPLE_DRV_NAME,
296
+ .of_match_table = maxim_thermocouple_of_match,
268297 },
269298 .probe = maxim_thermocouple_probe,
270
- .remove = maxim_thermocouple_remove,
271299 .id_table = maxim_thermocouple_id,
272300 };
273301 module_spi_driver(maxim_thermocouple_driver);