Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Evgeniy Dushistov and committed by
Guenter Roeck
60c1f31f e3b20b3f

+29 -10
+6 -2
Documentation/hwmon/ads1015
··· 6 6 Prefix: 'ads1015' 7 7 Datasheet: Publicly available at the Texas Instruments website : 8 8 http://focus.ti.com/lit/ds/symlink/ads1015.pdf 9 + * Texas Instruments ADS1115 10 + Prefix: 'ads1115' 11 + Datasheet: Publicly available at the Texas Instruments website : 12 + http://focus.ti.com/lit/ds/symlink/ads1115.pdf 9 13 10 14 Authors: 11 15 Dirk Eibach, Guntermann & Drunck GmbH <eibach@gdsys.de> ··· 17 13 Description 18 14 ----------- 19 15 20 - This driver implements support for the Texas Instruments ADS1015. 16 + This driver implements support for the Texas Instruments ADS1015/ADS1115. 21 17 22 - This device is a 12-bit A-D converter with 4 inputs. 18 + This device is a 12/16-bit A-D converter with 4 inputs. 23 19 24 20 The inputs can be used single ended or in certain differential combinations. 25 21
+2 -2
drivers/hwmon/Kconfig
··· 1202 1202 tristate "Texas Instruments ADS1015" 1203 1203 depends on I2C 1204 1204 help 1205 - If you say yes here you get support for Texas Instruments ADS1015 1206 - 12-bit 4-input ADC device. 1205 + If you say yes here you get support for Texas Instruments 1206 + ADS1015/ADS1115 12/16-bit 4-input ADC device. 1207 1207 1208 1208 This driver can also be built as a module. If so, the module 1209 1209 will be called ads1015.
+21 -6
drivers/hwmon/ads1015.c
··· 46 46 6144, 4096, 2048, 1024, 512, 256, 256, 256 }; 47 47 48 48 /* Data rates in samples per second */ 49 - static const unsigned int data_rate_table[8] = { 50 - 128, 250, 490, 920, 1600, 2400, 3300, 3300 }; 49 + static const unsigned int data_rate_table_1015[8] = { 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 57 #define ADS1015_DEFAULT_CHANNELS 0xff 53 58 #define ADS1015_DEFAULT_PGA 2 54 59 #define ADS1015_DEFAULT_DATA_RATE 4 55 60 61 + enum ads1015_chips { 62 + ads1015, 63 + ads1115, 64 + }; 65 + 56 66 struct ads1015_data { 57 67 struct device *hwmon_dev; 58 68 struct mutex update_lock; /* mutex protect updates */ 59 69 struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 70 + enum ads1015_chips id; 60 71 }; 61 72 62 73 static int ads1015_read_adc(struct i2c_client *client, unsigned int channel) ··· 77 66 unsigned int pga = data->channel_data[channel].pga; 78 67 unsigned int data_rate = data->channel_data[channel].data_rate; 79 68 unsigned int conversion_time_ms; 69 + const unsigned int * const rate_table = data->id == ads1115 ? 70 + data_rate_table_1115 : data_rate_table_1015; 80 71 int res; 81 72 82 73 mutex_lock(&data->update_lock); ··· 88 75 if (res < 0) 89 76 goto err_unlock; 90 77 config = res; 91 - conversion_time_ms = DIV_ROUND_UP(1000, data_rate_table[data_rate]); 78 + conversion_time_ms = DIV_ROUND_UP(1000, rate_table[data_rate]); 92 79 93 80 /* setup and start single conversion */ 94 81 config &= 0x001f; ··· 126 113 struct ads1015_data *data = i2c_get_clientdata(client); 127 114 unsigned int pga = data->channel_data[channel].pga; 128 115 int fullscale = fullscale_table[pga]; 116 + const unsigned mask = data->id == ads1115 ? 0x7fff : 0x7ff0; 129 117 130 - return DIV_ROUND_CLOSEST(reg * fullscale, 0x7ff0); 118 + return DIV_ROUND_CLOSEST(reg * fullscale, mask); 131 119 } 132 120 133 121 /* sysfs callback function */ ··· 271 257 GFP_KERNEL); 272 258 if (!data) 273 259 return -ENOMEM; 274 - 260 + data->id = id->driver_data; 275 261 i2c_set_clientdata(client, data); 276 262 mutex_init(&data->update_lock); 277 263 ··· 300 286 } 301 287 302 288 static const struct i2c_device_id ads1015_id[] = { 303 - { "ads1015", 0 }, 289 + { "ads1015", ads1015}, 290 + { "ads1115", ads1115}, 304 291 { } 305 292 }; 306 293 MODULE_DEVICE_TABLE(i2c, ads1015_id);