diff options
author | Evgeniy Dushistov <dushistov@mail.ru> | 2013-08-01 15:23:48 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-08-12 01:10:40 -0400 |
commit | 60c1f31fc5dfdbef388f47739e14c3cd85ad17e2 (patch) | |
tree | e6ef15e9bc3be1a3cb9e264e350261ec5a472525 /drivers/hwmon | |
parent | e3b20b3f586604cde718a609b39577086351ed49 (diff) |
hwmon: (ads1015) Add support for ADS1115
This patch adds support for ads1115 device to ads1015 driver.
Based on work of Emiliano Carnati <carnatiatebneuro.com>.
Tested on ARM CPU based board.
Signed-off-by: Evgeniy A. Dushistov <dushistov@mail.ru>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/Kconfig | 4 | ||||
-rw-r--r-- | drivers/hwmon/ads1015.c | 27 |
2 files changed, 23 insertions, 8 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e989f7fd645b..47b3e5821cb8 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -1202,8 +1202,8 @@ config SENSORS_ADS1015 | |||
1202 | tristate "Texas Instruments ADS1015" | 1202 | tristate "Texas Instruments ADS1015" |
1203 | depends on I2C | 1203 | depends on I2C |
1204 | help | 1204 | help |
1205 | If you say yes here you get support for Texas Instruments ADS1015 | 1205 | If you say yes here you get support for Texas Instruments |
1206 | 12-bit 4-input ADC device. | 1206 | ADS1015/ADS1115 12/16-bit 4-input ADC device. |
1207 | 1207 | ||
1208 | This driver can also be built as a module. If so, the module | 1208 | This driver can also be built as a module. If so, the module |
1209 | will be called ads1015. | 1209 | will be called ads1015. |
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c index 2798246ad814..7f9dc2f86b63 100644 --- a/drivers/hwmon/ads1015.c +++ b/drivers/hwmon/ads1015.c | |||
@@ -46,17 +46,28 @@ static const unsigned int fullscale_table[8] = { | |||
46 | 6144, 4096, 2048, 1024, 512, 256, 256, 256 }; | 46 | 6144, 4096, 2048, 1024, 512, 256, 256, 256 }; |
47 | 47 | ||
48 | /* Data rates in samples per second */ | 48 | /* Data rates in samples per second */ |
49 | static const unsigned int data_rate_table[8] = { | 49 | static const unsigned int data_rate_table_1015[8] = { |
50 | 128, 250, 490, 920, 1600, 2400, 3300, 3300 }; | 50 | 128, 250, 490, 920, 1600, 2400, 3300, 3300 |
51 | }; | ||
52 | |||
53 | static const unsigned int data_rate_table_1115[8] = { | ||
54 | 8, 16, 32, 64, 128, 250, 475, 860 | ||
55 | }; | ||
51 | 56 | ||
52 | #define ADS1015_DEFAULT_CHANNELS 0xff | 57 | #define ADS1015_DEFAULT_CHANNELS 0xff |
53 | #define ADS1015_DEFAULT_PGA 2 | 58 | #define ADS1015_DEFAULT_PGA 2 |
54 | #define ADS1015_DEFAULT_DATA_RATE 4 | 59 | #define ADS1015_DEFAULT_DATA_RATE 4 |
55 | 60 | ||
61 | enum ads1015_chips { | ||
62 | ads1015, | ||
63 | ads1115, | ||
64 | }; | ||
65 | |||
56 | struct ads1015_data { | 66 | struct ads1015_data { |
57 | struct device *hwmon_dev; | 67 | struct device *hwmon_dev; |
58 | struct mutex update_lock; /* mutex protect updates */ | 68 | struct mutex update_lock; /* mutex protect updates */ |
59 | struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; | 69 | struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; |
70 | enum ads1015_chips id; | ||
60 | }; | 71 | }; |
61 | 72 | ||
62 | static int ads1015_read_adc(struct i2c_client *client, unsigned int channel) | 73 | static int ads1015_read_adc(struct i2c_client *client, unsigned int channel) |
@@ -66,6 +77,8 @@ static int ads1015_read_adc(struct i2c_client *client, unsigned int channel) | |||
66 | unsigned int pga = data->channel_data[channel].pga; | 77 | unsigned int pga = data->channel_data[channel].pga; |
67 | unsigned int data_rate = data->channel_data[channel].data_rate; | 78 | unsigned int data_rate = data->channel_data[channel].data_rate; |
68 | unsigned int conversion_time_ms; | 79 | unsigned int conversion_time_ms; |
80 | const unsigned int * const rate_table = data->id == ads1115 ? | ||
81 | data_rate_table_1115 : data_rate_table_1015; | ||
69 | int res; | 82 | int res; |
70 | 83 | ||
71 | mutex_lock(&data->update_lock); | 84 | mutex_lock(&data->update_lock); |
@@ -75,7 +88,7 @@ static int ads1015_read_adc(struct i2c_client *client, unsigned int channel) | |||
75 | if (res < 0) | 88 | if (res < 0) |
76 | goto err_unlock; | 89 | goto err_unlock; |
77 | config = res; | 90 | config = res; |
78 | conversion_time_ms = DIV_ROUND_UP(1000, data_rate_table[data_rate]); | 91 | conversion_time_ms = DIV_ROUND_UP(1000, rate_table[data_rate]); |
79 | 92 | ||
80 | /* setup and start single conversion */ | 93 | /* setup and start single conversion */ |
81 | config &= 0x001f; | 94 | config &= 0x001f; |
@@ -113,8 +126,9 @@ static int ads1015_reg_to_mv(struct i2c_client *client, unsigned int channel, | |||
113 | struct ads1015_data *data = i2c_get_clientdata(client); | 126 | struct ads1015_data *data = i2c_get_clientdata(client); |
114 | unsigned int pga = data->channel_data[channel].pga; | 127 | unsigned int pga = data->channel_data[channel].pga; |
115 | int fullscale = fullscale_table[pga]; | 128 | int fullscale = fullscale_table[pga]; |
129 | const unsigned mask = data->id == ads1115 ? 0x7fff : 0x7ff0; | ||
116 | 130 | ||
117 | return DIV_ROUND_CLOSEST(reg * fullscale, 0x7ff0); | 131 | return DIV_ROUND_CLOSEST(reg * fullscale, mask); |
118 | } | 132 | } |
119 | 133 | ||
120 | /* sysfs callback function */ | 134 | /* sysfs callback function */ |
@@ -257,7 +271,7 @@ static int ads1015_probe(struct i2c_client *client, | |||
257 | GFP_KERNEL); | 271 | GFP_KERNEL); |
258 | if (!data) | 272 | if (!data) |
259 | return -ENOMEM; | 273 | return -ENOMEM; |
260 | 274 | data->id = id->driver_data; | |
261 | i2c_set_clientdata(client, data); | 275 | i2c_set_clientdata(client, data); |
262 | mutex_init(&data->update_lock); | 276 | mutex_init(&data->update_lock); |
263 | 277 | ||
@@ -286,7 +300,8 @@ exit_remove: | |||
286 | } | 300 | } |
287 | 301 | ||
288 | static const struct i2c_device_id ads1015_id[] = { | 302 | static const struct i2c_device_id ads1015_id[] = { |
289 | { "ads1015", 0 }, | 303 | { "ads1015", ads1015}, |
304 | { "ads1115", ads1115}, | ||
290 | { } | 305 | { } |
291 | }; | 306 | }; |
292 | MODULE_DEVICE_TABLE(i2c, ads1015_id); | 307 | MODULE_DEVICE_TABLE(i2c, ads1015_id); |