.. | .. |
---|
10 | 10 | #include <linux/init.h> |
---|
11 | 11 | #include <linux/mutex.h> |
---|
12 | 12 | #include <linux/err.h> |
---|
| 13 | +#include <linux/of.h> |
---|
| 14 | +#include <linux/of_device.h> |
---|
13 | 15 | #include <linux/spi/spi.h> |
---|
14 | 16 | #include <linux/iio/iio.h> |
---|
| 17 | +#include <linux/iio/sysfs.h> |
---|
15 | 18 | #include <linux/iio/trigger.h> |
---|
16 | 19 | #include <linux/iio/buffer.h> |
---|
17 | 20 | #include <linux/iio/triggered_buffer.h> |
---|
.. | .. |
---|
22 | 25 | enum { |
---|
23 | 26 | MAX6675, |
---|
24 | 27 | 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' |
---|
25 | 39 | }; |
---|
26 | 40 | |
---|
27 | 41 | static const struct iio_chan_spec max6675_channels[] = { |
---|
28 | 42 | { /* thermocouple temperature */ |
---|
29 | 43 | .type = IIO_TEMP, |
---|
30 | 44 | .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), |
---|
32 | 47 | .scan_index = 0, |
---|
33 | 48 | .scan_type = { |
---|
34 | 49 | .sign = 's', |
---|
.. | .. |
---|
46 | 61 | .type = IIO_TEMP, |
---|
47 | 62 | .address = 2, |
---|
48 | 63 | .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), |
---|
50 | 66 | .scan_index = 0, |
---|
51 | 67 | .scan_type = { |
---|
52 | 68 | .sign = 's', |
---|
.. | .. |
---|
108 | 124 | const struct maxim_thermocouple_chip *chip; |
---|
109 | 125 | |
---|
110 | 126 | u8 buffer[16] ____cacheline_aligned; |
---|
| 127 | + char tc_type; |
---|
111 | 128 | }; |
---|
112 | 129 | |
---|
113 | 130 | static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, |
---|
.. | .. |
---|
192 | 209 | default: |
---|
193 | 210 | *val = 250; /* 1000 * 0.25 */ |
---|
194 | 211 | 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; |
---|
196 | 217 | break; |
---|
197 | 218 | } |
---|
198 | 219 | |
---|
.. | .. |
---|
208 | 229 | const struct spi_device_id *id = spi_get_device_id(spi); |
---|
209 | 230 | struct iio_dev *indio_dev; |
---|
210 | 231 | struct maxim_thermocouple_data *data; |
---|
| 232 | + const int chip_type = (id->driver_data == MAX6675) ? MAX6675 : MAX31855; |
---|
211 | 233 | const struct maxim_thermocouple_chip *chip = |
---|
212 | | - &maxim_thermocouple_chips[id->driver_data]; |
---|
| 234 | + &maxim_thermocouple_chips[chip_type]; |
---|
213 | 235 | int ret; |
---|
214 | 236 | |
---|
215 | 237 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data)); |
---|
.. | .. |
---|
222 | 244 | indio_dev->available_scan_masks = chip->scan_masks; |
---|
223 | 245 | indio_dev->num_channels = chip->num_channels; |
---|
224 | 246 | indio_dev->modes = INDIO_DIRECT_MODE; |
---|
225 | | - indio_dev->dev.parent = &spi->dev; |
---|
226 | 247 | |
---|
227 | 248 | data = iio_priv(indio_dev); |
---|
228 | 249 | data->spi = spi; |
---|
229 | 250 | data->chip = chip; |
---|
| 251 | + data->tc_type = maxim_tc_types[id->driver_data]; |
---|
230 | 252 | |
---|
231 | | - ret = iio_triggered_buffer_setup(indio_dev, NULL, |
---|
| 253 | + ret = devm_iio_triggered_buffer_setup(&spi->dev, |
---|
| 254 | + indio_dev, NULL, |
---|
232 | 255 | maxim_thermocouple_trigger_handler, NULL); |
---|
233 | 256 | if (ret) |
---|
234 | 257 | return ret; |
---|
235 | 258 | |
---|
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"); |
---|
239 | 261 | |
---|
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); |
---|
256 | 263 | } |
---|
257 | 264 | |
---|
258 | 265 | static const struct spi_device_id maxim_thermocouple_id[] = { |
---|
259 | 266 | {"max6675", MAX6675}, |
---|
260 | 267 | {"max31855", MAX31855}, |
---|
| 268 | + {"max31855k", MAX31855K}, |
---|
| 269 | + {"max31855j", MAX31855J}, |
---|
| 270 | + {"max31855n", MAX31855N}, |
---|
| 271 | + {"max31855s", MAX31855S}, |
---|
| 272 | + {"max31855t", MAX31855T}, |
---|
| 273 | + {"max31855e", MAX31855E}, |
---|
| 274 | + {"max31855r", MAX31855R}, |
---|
261 | 275 | {}, |
---|
262 | 276 | }; |
---|
263 | 277 | MODULE_DEVICE_TABLE(spi, maxim_thermocouple_id); |
---|
264 | 278 | |
---|
| 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 | + |
---|
265 | 293 | static struct spi_driver maxim_thermocouple_driver = { |
---|
266 | 294 | .driver = { |
---|
267 | 295 | .name = MAXIM_THERMOCOUPLE_DRV_NAME, |
---|
| 296 | + .of_match_table = maxim_thermocouple_of_match, |
---|
268 | 297 | }, |
---|
269 | 298 | .probe = maxim_thermocouple_probe, |
---|
270 | | - .remove = maxim_thermocouple_remove, |
---|
271 | 299 | .id_table = maxim_thermocouple_id, |
---|
272 | 300 | }; |
---|
273 | 301 | module_spi_driver(maxim_thermocouple_driver); |
---|