15 #include <linux/module.h>
17 #include <linux/i2c.h>
23 #include <linux/slab.h>
27 #define DRV_VERSION "0.4"
32 #define AD7418_REG_TEMP_IN 0x00
33 #define AD7418_REG_CONF 0x01
34 #define AD7418_REG_TEMP_HYST 0x02
35 #define AD7418_REG_TEMP_OS 0x03
36 #define AD7418_REG_ADC 0x04
37 #define AD7418_REG_CONF2 0x05
39 #define AD7418_REG_ADC_CH(x) ((x) << 5)
40 #define AD7418_CH_TEMP AD7418_REG_ADC_CH(0)
74 .probe = ad7418_probe,
75 .remove = ad7418_remove,
76 .id_table = ad7418_id,
85 dev_err(&client->
dev,
"cannot read configuration register\n");
99 struct ad7418_data *data = i2c_get_clientdata(client);
116 for (i = 0; i < 3; i++) {
118 i2c_smbus_read_word_swapped(client,
122 for (i = 0, ch = 4; i < data->
adc_max; i++, ch--) {
129 i2c_smbus_read_word_swapped(client,
149 struct ad7418_data *data = ad7418_update_device(dev);
151 LM75_TEMP_FROM_REG(data->
temp[attr->
index]));
158 struct ad7418_data *data = ad7418_update_device(dev);
161 ((data->
in[attr->
index] >> 6) * 2500 + 512) / 1024);
165 const char *buf,
size_t count)
169 struct ad7418_data *data = i2c_get_clientdata(client);
171 int ret = kstrtol(buf, 10, &temp);
177 data->
temp[attr->
index] = LM75_TEMP_TO_REG(temp);
178 i2c_smbus_write_word_swapped(client,
179 AD7418_REG_TEMP[attr->
index],
196 static struct attribute *ad7416_attributes[] = {
197 &sensor_dev_attr_temp1_max.dev_attr.attr,
198 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
199 &sensor_dev_attr_temp1_input.dev_attr.attr,
203 static struct attribute *ad7417_attributes[] = {
204 &sensor_dev_attr_temp1_max.dev_attr.attr,
205 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
206 &sensor_dev_attr_temp1_input.dev_attr.attr,
207 &sensor_dev_attr_in1_input.dev_attr.attr,
208 &sensor_dev_attr_in2_input.dev_attr.attr,
209 &sensor_dev_attr_in3_input.dev_attr.attr,
210 &sensor_dev_attr_in4_input.dev_attr.attr,
214 static struct attribute *ad7418_attributes[] = {
215 &sensor_dev_attr_temp1_max.dev_attr.attr,
216 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
217 &sensor_dev_attr_temp1_input.dev_attr.attr,
218 &sensor_dev_attr_in1_input.dev_attr.attr,
222 static int ad7418_probe(
struct i2c_client *client,
238 i2c_set_clientdata(client, data);
241 data->
type =
id->driver_data;
243 switch (data->
type) {
246 data->
attrs.attrs = ad7416_attributes;
251 data->
attrs.attrs = ad7417_attributes;
256 data->
attrs.attrs = ad7418_attributes;
263 ad7418_init_client(client);
283 static int ad7418_remove(
struct i2c_client *client)
285 struct ad7418_data *data = i2c_get_clientdata(client);