1 // SPDX-License-Identifier: GPL-2.0+
3 * AD5671R, AD5675R, AD5691R, AD5692R, AD5693, AD5693R,
4 * AD5694, AD5694R, AD5695R, AD5696, AD5696R
5 * Digital to analog converters driver
7 * Copyright 2018 Analog Devices Inc.
12 #include <linux/module.h>
13 #include <linux/i2c.h>
15 static int ad5686_i2c_read(struct ad5686_state
*st
, u8 addr
)
17 struct i2c_client
*i2c
= to_i2c_client(st
->dev
);
18 struct i2c_msg msg
[2] = {
23 .buf
= &st
->data
[0].d8
[1],
27 .flags
= i2c
->flags
| I2C_M_RD
,
29 .buf
= (char *)&st
->data
[0].d16
,
34 st
->data
[0].d32
= cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP
) |
38 ret
= i2c_transfer(i2c
->adapter
, msg
, 2);
42 return be16_to_cpu(st
->data
[0].d16
);
45 static int ad5686_i2c_write(struct ad5686_state
*st
,
46 u8 cmd
, u8 addr
, u16 val
)
48 struct i2c_client
*i2c
= to_i2c_client(st
->dev
);
51 st
->data
[0].d32
= cpu_to_be32(AD5686_CMD(cmd
) | AD5686_ADDR(addr
)
54 ret
= i2c_master_send(i2c
, &st
->data
[0].d8
[1], 3);
58 return (ret
!= 3) ? -EIO
: 0;
61 static int ad5686_i2c_probe(struct i2c_client
*i2c
,
62 const struct i2c_device_id
*id
)
64 return ad5686_probe(&i2c
->dev
, id
->driver_data
, id
->name
,
65 ad5686_i2c_write
, ad5686_i2c_read
);
68 static int ad5686_i2c_remove(struct i2c_client
*i2c
)
70 return ad5686_remove(&i2c
->dev
);
73 static const struct i2c_device_id ad5686_i2c_id
[] = {
74 {"ad5311r", ID_AD5311R
},
75 {"ad5671r", ID_AD5671R
},
76 {"ad5675r", ID_AD5675R
},
77 {"ad5691r", ID_AD5691R
},
78 {"ad5692r", ID_AD5692R
},
79 {"ad5693", ID_AD5693
},
80 {"ad5693r", ID_AD5693R
},
81 {"ad5694", ID_AD5694
},
82 {"ad5694r", ID_AD5694R
},
83 {"ad5695r", ID_AD5695R
},
84 {"ad5696", ID_AD5696
},
85 {"ad5696r", ID_AD5696R
},
88 MODULE_DEVICE_TABLE(i2c
, ad5686_i2c_id
);
90 static struct i2c_driver ad5686_i2c_driver
= {
94 .probe
= ad5686_i2c_probe
,
95 .remove
= ad5686_i2c_remove
,
96 .id_table
= ad5686_i2c_id
,
99 module_i2c_driver(ad5686_i2c_driver
);
101 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
102 MODULE_DESCRIPTION("Analog Devices AD5686 and similar multi-channel DACs");
103 MODULE_LICENSE("GPL v2");