1 // SPDX-License-Identifier: GPL-2.0-only
3 * ltc2497.c - Driver for Analog Devices/Linear Technology LTC2497 ADC
5 * Copyright (C) 2017 Analog Devices Inc.
7 * Datasheet: http://cds.linear.com/docs/en/datasheet/2497fd.pdf
10 #include <linux/i2c.h>
11 #include <linux/iio/iio.h>
12 #include <linux/iio/driver.h>
13 #include <linux/module.h>
14 #include <linux/mod_devicetable.h>
18 struct ltc2497_driverdata
{
19 /* this must be the first member */
20 struct ltc2497core_driverdata common_ddata
;
21 struct i2c_client
*client
;
23 * DMA (thus cache coherency maintenance) requires the
24 * transfer buffers to live in their own cache lines.
26 __be32 buf ____cacheline_aligned
;
29 static int ltc2497_result_and_measure(struct ltc2497core_driverdata
*ddata
,
32 struct ltc2497_driverdata
*st
=
33 container_of(ddata
, struct ltc2497_driverdata
, common_ddata
);
37 ret
= i2c_master_recv(st
->client
, (char *)&st
->buf
, 3);
39 dev_err(&st
->client
->dev
, "i2c_master_recv failed\n");
43 *val
= (be32_to_cpu(st
->buf
) >> 14) - (1 << 17);
46 ret
= i2c_smbus_write_byte(st
->client
,
47 LTC2497_ENABLE
| address
);
49 dev_err(&st
->client
->dev
, "i2c transfer failed: %pe\n",
54 static int ltc2497_probe(struct i2c_client
*client
,
55 const struct i2c_device_id
*id
)
57 struct iio_dev
*indio_dev
;
58 struct ltc2497_driverdata
*st
;
59 struct device
*dev
= &client
->dev
;
61 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_I2C
|
62 I2C_FUNC_SMBUS_WRITE_BYTE
))
65 indio_dev
= devm_iio_device_alloc(dev
, sizeof(*st
));
69 st
= iio_priv(indio_dev
);
70 i2c_set_clientdata(client
, indio_dev
);
72 st
->common_ddata
.result_and_measure
= ltc2497_result_and_measure
;
74 return ltc2497core_probe(dev
, indio_dev
);
77 static int ltc2497_remove(struct i2c_client
*client
)
79 struct iio_dev
*indio_dev
= i2c_get_clientdata(client
);
81 ltc2497core_remove(indio_dev
);
86 static const struct i2c_device_id ltc2497_id
[] = {
90 MODULE_DEVICE_TABLE(i2c
, ltc2497_id
);
92 static const struct of_device_id ltc2497_of_match
[] = {
93 { .compatible
= "lltc,ltc2497", },
96 MODULE_DEVICE_TABLE(of
, ltc2497_of_match
);
98 static struct i2c_driver ltc2497_driver
= {
101 .of_match_table
= ltc2497_of_match
,
103 .probe
= ltc2497_probe
,
104 .remove
= ltc2497_remove
,
105 .id_table
= ltc2497_id
,
107 module_i2c_driver(ltc2497_driver
);
109 MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
110 MODULE_DESCRIPTION("Linear Technology LTC2497 ADC driver");
111 MODULE_LICENSE("GPL v2");