diff options
author | Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> | 2012-10-03 16:54:08 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2012-12-05 13:55:54 -0500 |
commit | 0962e0f1a5634b63953db2c12edcff938f9d811d (patch) | |
tree | 698edc816261f42f0acd810f8f15a9fa70234e6f | |
parent | 46d784629202c5da9be8d727988e7083fb455bf8 (diff) |
hwmon: (ads7828) add support for ADS7830
The ADS7830 device is almost the same as the ADS7828,
except that it does 8-bit sampling, instead of 12-bit.
This patch extends the ads7828 driver to support this chip.
Signed-off-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | Documentation/hwmon/ads7828 | 11 | ||||
-rw-r--r-- | drivers/hwmon/Kconfig | 7 | ||||
-rw-r--r-- | drivers/hwmon/ads7828.c | 25 |
3 files changed, 32 insertions, 11 deletions
diff --git a/Documentation/hwmon/ads7828 b/Documentation/hwmon/ads7828 index a987c94a88e5..f6e263e0f607 100644 --- a/Documentation/hwmon/ads7828 +++ b/Documentation/hwmon/ads7828 | |||
@@ -7,9 +7,15 @@ Supported chips: | |||
7 | Datasheet: Publicly available at the Texas Instruments website: | 7 | Datasheet: Publicly available at the Texas Instruments website: |
8 | http://focus.ti.com/lit/ds/symlink/ads7828.pdf | 8 | http://focus.ti.com/lit/ds/symlink/ads7828.pdf |
9 | 9 | ||
10 | * Texas Instruments ADS7830 | ||
11 | Prefix: 'ads7830' | ||
12 | Datasheet: Publicly available at the Texas Instruments website: | ||
13 | http://focus.ti.com/lit/ds/symlink/ads7830.pdf | ||
14 | |||
10 | Authors: | 15 | Authors: |
11 | Steve Hardy <shardy@redhat.com> | 16 | Steve Hardy <shardy@redhat.com> |
12 | Vivien Didelot <vivien.didelot@savoirfairelinux.com> | 17 | Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
18 | Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> | ||
13 | 19 | ||
14 | Platform data | 20 | Platform data |
15 | ------------- | 21 | ------------- |
@@ -35,9 +41,10 @@ in include/linux/platform_data/ads7828.h). The structure fields are: | |||
35 | Description | 41 | Description |
36 | ----------- | 42 | ----------- |
37 | 43 | ||
38 | This driver implements support for the Texas Instruments ADS7828. | 44 | This driver implements support for the Texas Instruments ADS7828 and ADS7830. |
39 | 45 | ||
40 | This device is a 12-bit 8-channel A-D converter. | 46 | The ADS7828 device is a 12-bit 8-channel A/D converter, while the ADS7830 does |
47 | 8-bit sampling. | ||
41 | 48 | ||
42 | It can operate in single ended mode (8 +ve inputs) or in differential mode, | 49 | It can operate in single ended mode (8 +ve inputs) or in differential mode, |
43 | where 4 differential pairs can be measured. | 50 | where 4 differential pairs can be measured. |
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index c4633de64465..9e3d977c106b 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -1106,11 +1106,12 @@ config SENSORS_ADS1015 | |||
1106 | will be called ads1015. | 1106 | will be called ads1015. |
1107 | 1107 | ||
1108 | config SENSORS_ADS7828 | 1108 | config SENSORS_ADS7828 |
1109 | tristate "Texas Instruments ADS7828" | 1109 | tristate "Texas Instruments ADS7828 and compatibles" |
1110 | depends on I2C | 1110 | depends on I2C |
1111 | help | 1111 | help |
1112 | If you say yes here you get support for Texas Instruments ADS7828 | 1112 | If you say yes here you get support for Texas Instruments ADS7828 and |
1113 | 12-bit 8-channel ADC device. | 1113 | ADS7830 8-channel A/D converters. ADS7828 resolution is 12-bit, while |
1114 | it is 8-bit on ADS7830. | ||
1114 | 1115 | ||
1115 | This driver can also be built as a module. If so, the module | 1116 | This driver can also be built as a module. If so, the module |
1116 | will be called ads7828. | 1117 | will be called ads7828. |
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c index 42914fc1436d..409b5c16defb 100644 --- a/drivers/hwmon/ads7828.c +++ b/drivers/hwmon/ads7828.c | |||
@@ -1,11 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | * ads7828.c - lm_sensors driver for ads7828 12-bit 8-channel ADC | 2 | * ads7828.c - driver for TI ADS7828 8-channel A/D converter and compatibles |
3 | * (C) 2007 EADS Astrium | 3 | * (C) 2007 EADS Astrium |
4 | * | 4 | * |
5 | * This driver is based on the lm75 and other lm_sensors/hwmon drivers | 5 | * This driver is based on the lm75 and other lm_sensors/hwmon drivers |
6 | * | 6 | * |
7 | * Written by Steve Hardy <shardy@redhat.com> | 7 | * Written by Steve Hardy <shardy@redhat.com> |
8 | * | 8 | * |
9 | * ADS7830 support, by Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> | ||
10 | * | ||
9 | * For further information, see the Documentation/hwmon/ads7828 file. | 11 | * For further information, see the Documentation/hwmon/ads7828 file. |
10 | * | 12 | * |
11 | * This program is free software; you can redistribute it and/or modify | 13 | * This program is free software; you can redistribute it and/or modify |
@@ -43,6 +45,9 @@ | |||
43 | #define ADS7828_EXT_VREF_MV_MIN 50 /* External vref min value 0.05V */ | 45 | #define ADS7828_EXT_VREF_MV_MIN 50 /* External vref min value 0.05V */ |
44 | #define ADS7828_EXT_VREF_MV_MAX 5250 /* External vref max value 5.25V */ | 46 | #define ADS7828_EXT_VREF_MV_MAX 5250 /* External vref max value 5.25V */ |
45 | 47 | ||
48 | /* List of supported devices */ | ||
49 | enum ads7828_chips { ads7828, ads7830 }; | ||
50 | |||
46 | /* Client specific data */ | 51 | /* Client specific data */ |
47 | struct ads7828_data { | 52 | struct ads7828_data { |
48 | struct device *hwmon_dev; | 53 | struct device *hwmon_dev; |
@@ -55,6 +60,7 @@ struct ads7828_data { | |||
55 | unsigned int vref_mv; /* voltage reference value */ | 60 | unsigned int vref_mv; /* voltage reference value */ |
56 | u8 cmd_byte; /* Command byte without channel bits */ | 61 | u8 cmd_byte; /* Command byte without channel bits */ |
57 | unsigned int lsb_resol; /* Resolution of the ADC sample LSB */ | 62 | unsigned int lsb_resol; /* Resolution of the ADC sample LSB */ |
63 | s32 (*read_channel)(const struct i2c_client *client, u8 command); | ||
58 | }; | 64 | }; |
59 | 65 | ||
60 | /* Command byte C2,C1,C0 - see datasheet */ | 66 | /* Command byte C2,C1,C0 - see datasheet */ |
@@ -78,8 +84,7 @@ static struct ads7828_data *ads7828_update_device(struct device *dev) | |||
78 | 84 | ||
79 | for (ch = 0; ch < ADS7828_NCH; ch++) { | 85 | for (ch = 0; ch < ADS7828_NCH; ch++) { |
80 | u8 cmd = ads7828_cmd_byte(data->cmd_byte, ch); | 86 | u8 cmd = ads7828_cmd_byte(data->cmd_byte, ch); |
81 | data->adc_input[ch] = | 87 | data->adc_input[ch] = data->read_channel(client, cmd); |
82 | i2c_smbus_read_word_swapped(client, cmd); | ||
83 | } | 88 | } |
84 | data->last_updated = jiffies; | 89 | data->last_updated = jiffies; |
85 | data->valid = true; | 90 | data->valid = true; |
@@ -164,7 +169,14 @@ static int ads7828_probe(struct i2c_client *client, | |||
164 | else | 169 | else |
165 | data->vref_mv = ADS7828_INT_VREF_MV; | 170 | data->vref_mv = ADS7828_INT_VREF_MV; |
166 | 171 | ||
167 | data->lsb_resol = DIV_ROUND_CLOSEST(data->vref_mv * 1000, 4096); | 172 | /* ADS7828 uses 12-bit samples, while ADS7830 is 8-bit */ |
173 | if (id->driver_data == ads7828) { | ||
174 | data->lsb_resol = DIV_ROUND_CLOSEST(data->vref_mv * 1000, 4096); | ||
175 | data->read_channel = i2c_smbus_read_word_swapped; | ||
176 | } else { | ||
177 | data->lsb_resol = DIV_ROUND_CLOSEST(data->vref_mv * 1000, 256); | ||
178 | data->read_channel = i2c_smbus_read_byte_data; | ||
179 | } | ||
168 | 180 | ||
169 | data->cmd_byte = data->ext_vref ? ADS7828_CMD_PD1 : ADS7828_CMD_PD3; | 181 | data->cmd_byte = data->ext_vref ? ADS7828_CMD_PD1 : ADS7828_CMD_PD3; |
170 | if (!data->diff_input) | 182 | if (!data->diff_input) |
@@ -191,7 +203,8 @@ error: | |||
191 | } | 203 | } |
192 | 204 | ||
193 | static const struct i2c_device_id ads7828_device_ids[] = { | 205 | static const struct i2c_device_id ads7828_device_ids[] = { |
194 | { "ads7828", 0 }, | 206 | { "ads7828", ads7828 }, |
207 | { "ads7830", ads7830 }, | ||
195 | { } | 208 | { } |
196 | }; | 209 | }; |
197 | MODULE_DEVICE_TABLE(i2c, ads7828_device_ids); | 210 | MODULE_DEVICE_TABLE(i2c, ads7828_device_ids); |
@@ -210,4 +223,4 @@ module_i2c_driver(ads7828_driver); | |||
210 | 223 | ||
211 | MODULE_LICENSE("GPL"); | 224 | MODULE_LICENSE("GPL"); |
212 | MODULE_AUTHOR("Steve Hardy <shardy@redhat.com>"); | 225 | MODULE_AUTHOR("Steve Hardy <shardy@redhat.com>"); |
213 | MODULE_DESCRIPTION("Driver for TI ADS7828 A/D converter"); | 226 | MODULE_DESCRIPTION("Driver for TI ADS7828 A/D converter and compatibles"); |