19 #include <linux/module.h>
21 #include <linux/i2c.h>
29 #define MCP4725_DRV_NAME "mcp4725"
37 #ifdef CONFIG_PM_SLEEP
38 static int mcp4725_suspend(
struct device *
dev)
48 static int mcp4725_resume(
struct device *
dev)
50 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
62 #define MCP4725_PM_OPS (&mcp4725_pm_ops)
64 #define MCP4725_PM_OPS NULL
74 .scan_type =
IIO_ST(
'u', 12, 16, 0),
77 static int mcp4725_set_value(
struct iio_dev *indio_dev,
int val)
83 if (val >= (1 << 12) || val < 0)
86 outbuf[0] = (val >> 8) & 0xf;
87 outbuf[1] = val & 0xff;
98 static int mcp4725_read_raw(
struct iio_dev *indio_dev,
100 int *val,
int *val2,
long mask)
103 unsigned long scale_uv;
110 scale_uv = (data->
vref_mv * 1000) >> 12;
111 *val = scale_uv / 1000000;
112 *val2 = scale_uv % 1000000;
118 static int mcp4725_write_raw(
struct iio_dev *indio_dev,
120 int val,
int val2,
long mask)
127 ret = mcp4725_set_value(indio_dev, val);
138 static const struct iio_info mcp4725_info = {
139 .read_raw = mcp4725_read_raw,
140 .write_raw = mcp4725_write_raw,
153 if (!platform_data || !platform_data->
vref_mv) {
154 dev_err(&client->
dev,
"invalid platform data");
160 if (indio_dev ==
NULL) {
164 data = iio_priv(indio_dev);
165 i2c_set_clientdata(client, indio_dev);
168 indio_dev->
dev.parent = &client->
dev;
169 indio_dev->
info = &mcp4725_info;
170 indio_dev->
channels = &mcp4725_channel;
179 dev_err(&client->
dev,
"failed to read DAC value");
180 goto exit_free_device;
182 data->
dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
186 goto exit_free_device;
188 dev_info(&client->
dev,
"MCP4725 DAC registered\n");
200 struct iio_dev *indio_dev = i2c_get_clientdata(client);
219 .probe = mcp4725_probe,
221 .id_table = mcp4725_id,