26 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <linux/i2c.h>
38 #define ADS7828_CMD_SD_SE 0x80
39 #define ADS7828_CMD_SD_DIFF 0x00
40 #define ADS7828_CMD_PD0 0x0
41 #define ADS7828_CMD_PD1 0x04
42 #define ADS7828_CMD_PD2 0x08
43 #define ADS7828_CMD_PD3 0x0C
44 #define ADS7828_INT_VREF_MV 2500
47 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
51 static bool se_input = 1;
52 static bool int_vref = 1;
59 static u8 ads7828_cmd_byte;
60 static unsigned int ads7828_lsb_resol;
77 static inline u8 channel_cmd_byte(
int ch)
80 u8 cmd = (((ch>>1) | (ch&0x01)<<2)<<4);
81 cmd |= ads7828_cmd_byte;
96 dev_dbg(&client->
dev,
"Starting ads7828 update\n");
99 u8 cmd = channel_cmd_byte(ch);
101 i2c_smbus_read_word_swapped(client, cmd);
120 ads7828_lsb_resol)/1000);
123 #define in_reg(offset)\
124 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in,\
136 static struct attribute *ads7828_attributes[] = {
137 &sensor_dev_attr_in0_input.dev_attr.attr,
138 &sensor_dev_attr_in1_input.dev_attr.attr,
139 &sensor_dev_attr_in2_input.dev_attr.attr,
140 &sensor_dev_attr_in3_input.dev_attr.attr,
141 &sensor_dev_attr_in4_input.dev_attr.attr,
142 &sensor_dev_attr_in5_input.dev_attr.attr,
143 &sensor_dev_attr_in6_input.dev_attr.attr,
144 &sensor_dev_attr_in7_input.dev_attr.attr,
149 .attrs = ads7828_attributes,
152 static int ads7828_remove(
struct i2c_client *client)
172 .probe = ads7828_probe,
173 .remove = ads7828_remove,
174 .id_table = ads7828_id,
175 .detect = ads7828_detect,
176 .address_list = normal_i2c,
180 static int ads7828_detect(
struct i2c_client *client,
199 u8 cmd = channel_cmd_byte(ch);
200 in_data = i2c_smbus_read_word_swapped(client, cmd);
201 if (in_data & 0xF000) {
202 pr_debug(
"%s : Doesn't look like an ads7828 device\n",
213 static int ads7828_probe(
struct i2c_client *client,
224 i2c_set_clientdata(client, data);
245 static int __init sensors_ads7828_init(
void)
248 ads7828_cmd_byte = se_input ?
250 ads7828_cmd_byte |= int_vref ?
254 ads7828_lsb_resol = (vref_mv*1000)/4096;
256 return i2c_add_driver(&ads7828_driver);
259 static void __exit sensors_ads7828_exit(
void)