25 #include <linux/module.h>
27 #include <linux/slab.h>
29 #include <linux/i2c.h>
45 static const unsigned int fullscale_table[8] = {
46 6144, 4096, 2048, 1024, 512, 256, 256, 256 };
49 static const unsigned int data_rate_table[8] = {
50 128, 250, 490, 920, 1600, 2400, 3300, 3300 };
52 #define ADS1015_DEFAULT_CHANNELS 0xff
53 #define ADS1015_DEFAULT_PGA 2
54 #define ADS1015_DEFAULT_DATA_RATE 4
68 unsigned int conversion_time_ms;
78 conversion_time_ms =
DIV_ROUND_UP(1000, data_rate_table[data_rate]);
82 config |= (1 << 15) | (1 << 8);
83 config |= (channel & 0x0007) << 12;
84 config |= (pga & 0x0007) << 9;
85 config |= (data_rate & 0x0007) << 5;
87 res = i2c_smbus_write_word_swapped(client,
ADS1015_CONFIG, config);
92 msleep(conversion_time_ms);
97 if (!(config & (1 << 15))) {
110 static int ads1015_reg_to_mv(
struct i2c_client *client,
unsigned int channel,
115 int fullscale = fullscale_table[pga];
129 res = ads1015_read_adc(client, index);
133 return sprintf(buf,
"%d\n", ads1015_reg_to_mv(client, index, res));
151 static int ads1015_remove(
struct i2c_client *client)
163 static int ads1015_get_channels_config_of(
struct i2c_client *client)
168 if (!client->
dev.of_node
180 if (!property || len !=
sizeof(
int)) {
187 if (channel > ADS1015_CHANNELS) {
189 "invalid channel index %d on %s\n",
195 if (property && len ==
sizeof(
int)) {
199 "invalid gain on %s\n",
205 if (property && len ==
sizeof(
int)) {
209 "invalid data_rate on %s\n",
223 static void ads1015_get_channels_config(
struct i2c_client *client)
237 if (!ads1015_get_channels_config_of(client))
249 static int ads1015_probe(
struct i2c_client *client,
261 i2c_set_clientdata(client, data);
265 ads1015_get_channels_config(client);
298 .probe = ads1015_probe,
299 .remove = ads1015_remove,
300 .id_table = ads1015_id,