diff options
author | Angelo Compagnucci <angelo.compagnucci@gmail.com> | 2014-08-03 18:22:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-03-16 14:00:34 -0400 |
commit | 2816ac64ac46c4017355a49331250e5c016dc2c0 (patch) | |
tree | 9d1c2c22cd48f95a7182ce070a829ec366a52a6a /drivers/iio/adc | |
parent | bd75afaa314b2743c5379df3ccc84fab03126b71 (diff) |
Add support for Microchip Technology's MCP3426/7/8 ADC
This patch extends previous mcp3422 driver to support
missing members of the family, mcp3426/7/8.
Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r-- | drivers/iio/adc/Kconfig | 7 | ||||
-rw-r--r-- | drivers/iio/adc/mcp3422.c | 33 |
2 files changed, 32 insertions, 8 deletions
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig index a0368119c275..1dffa2d56262 100644 --- a/drivers/iio/adc/Kconfig +++ b/drivers/iio/adc/Kconfig | |||
@@ -157,11 +157,12 @@ config MCP320X | |||
157 | called mcp320x. | 157 | called mcp320x. |
158 | 158 | ||
159 | config MCP3422 | 159 | config MCP3422 |
160 | tristate "Microchip Technology MCP3422/3/4 driver" | 160 | tristate "Microchip Technology MCP3422/3/4/6/7/8 driver" |
161 | depends on I2C | 161 | depends on I2C |
162 | help | 162 | help |
163 | Say yes here to build support for Microchip Technology's MCP3422, | 163 | Say yes here to build support for Microchip Technology's |
164 | MCP3423 or MCP3424 analog to digital converters. | 164 | MCP3422, MCP3423, MCP3424, MCP3426, MCP3427 or MCP3428 |
165 | analog to digital converters. | ||
165 | 166 | ||
166 | This driver can also be built as a module. If so, the module will be | 167 | This driver can also be built as a module. If so, the module will be |
167 | called mcp3422. | 168 | called mcp3422. |
diff --git a/drivers/iio/adc/mcp3422.c b/drivers/iio/adc/mcp3422.c index 47dcb34ff44c..51672256072b 100644 --- a/drivers/iio/adc/mcp3422.c +++ b/drivers/iio/adc/mcp3422.c | |||
@@ -1,10 +1,11 @@ | |||
1 | /* | 1 | /* |
2 | * mcp3422.c - driver for the Microchip mcp3422/3/4 chip family | 2 | * mcp3422.c - driver for the Microchip mcp3422/3/4/6/7/8 chip family |
3 | * | 3 | * |
4 | * Copyright (C) 2013, Angelo Compagnucci | 4 | * Copyright (C) 2013, Angelo Compagnucci |
5 | * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com> | 5 | * Author: Angelo Compagnucci <angelo.compagnucci@gmail.com> |
6 | * | 6 | * |
7 | * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf | 7 | * Datasheet: http://ww1.microchip.com/downloads/en/devicedoc/22088b.pdf |
8 | * http://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdf | ||
8 | * | 9 | * |
9 | * This driver exports the value of analog input voltage to sysfs, the | 10 | * This driver exports the value of analog input voltage to sysfs, the |
10 | * voltage unit is nV. | 11 | * voltage unit is nV. |
@@ -96,6 +97,7 @@ static const int mcp3422_sign_extend[4] = { | |||
96 | /* Client data (each client gets its own) */ | 97 | /* Client data (each client gets its own) */ |
97 | struct mcp3422 { | 98 | struct mcp3422 { |
98 | struct i2c_client *i2c; | 99 | struct i2c_client *i2c; |
100 | u8 id; | ||
99 | u8 config; | 101 | u8 config; |
100 | u8 pga[4]; | 102 | u8 pga[4]; |
101 | struct mutex lock; | 103 | struct mutex lock; |
@@ -238,6 +240,8 @@ static int mcp3422_write_raw(struct iio_dev *iio, | |||
238 | temp = MCP3422_SRATE_15; | 240 | temp = MCP3422_SRATE_15; |
239 | break; | 241 | break; |
240 | case 3: | 242 | case 3: |
243 | if (adc->id > 4) | ||
244 | return -EINVAL; | ||
241 | temp = MCP3422_SRATE_3; | 245 | temp = MCP3422_SRATE_3; |
242 | break; | 246 | break; |
243 | default: | 247 | default: |
@@ -271,6 +275,17 @@ static int mcp3422_write_raw_get_fmt(struct iio_dev *indio_dev, | |||
271 | } | 275 | } |
272 | } | 276 | } |
273 | 277 | ||
278 | static ssize_t mcp3422_show_samp_freqs(struct device *dev, | ||
279 | struct device_attribute *attr, char *buf) | ||
280 | { | ||
281 | struct mcp3422 *adc = iio_priv(dev_to_iio_dev(dev)); | ||
282 | |||
283 | if (adc->id > 4) | ||
284 | return sprintf(buf, "240 60 15\n"); | ||
285 | |||
286 | return sprintf(buf, "240 60 15 3\n"); | ||
287 | } | ||
288 | |||
274 | static ssize_t mcp3422_show_scales(struct device *dev, | 289 | static ssize_t mcp3422_show_scales(struct device *dev, |
275 | struct device_attribute *attr, char *buf) | 290 | struct device_attribute *attr, char *buf) |
276 | { | 291 | { |
@@ -284,12 +299,13 @@ static ssize_t mcp3422_show_scales(struct device *dev, | |||
284 | mcp3422_scales[sample_rate][3]); | 299 | mcp3422_scales[sample_rate][3]); |
285 | } | 300 | } |
286 | 301 | ||
287 | static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("240 60 15 3"); | 302 | static IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, |
303 | mcp3422_show_samp_freqs, NULL, 0); | ||
288 | static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, | 304 | static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, |
289 | mcp3422_show_scales, NULL, 0); | 305 | mcp3422_show_scales, NULL, 0); |
290 | 306 | ||
291 | static struct attribute *mcp3422_attributes[] = { | 307 | static struct attribute *mcp3422_attributes[] = { |
292 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, | 308 | &iio_dev_attr_sampling_frequency_available.dev_attr.attr, |
293 | &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, | 309 | &iio_dev_attr_in_voltage_scale_available.dev_attr.attr, |
294 | NULL, | 310 | NULL, |
295 | }; | 311 | }; |
@@ -335,6 +351,7 @@ static int mcp3422_probe(struct i2c_client *client, | |||
335 | 351 | ||
336 | adc = iio_priv(indio_dev); | 352 | adc = iio_priv(indio_dev); |
337 | adc->i2c = client; | 353 | adc->i2c = client; |
354 | adc->id = (u8)(id->driver_data); | ||
338 | 355 | ||
339 | mutex_init(&adc->lock); | 356 | mutex_init(&adc->lock); |
340 | 357 | ||
@@ -343,13 +360,16 @@ static int mcp3422_probe(struct i2c_client *client, | |||
343 | indio_dev->modes = INDIO_DIRECT_MODE; | 360 | indio_dev->modes = INDIO_DIRECT_MODE; |
344 | indio_dev->info = &mcp3422_info; | 361 | indio_dev->info = &mcp3422_info; |
345 | 362 | ||
346 | switch ((unsigned int)(id->driver_data)) { | 363 | switch (adc->id) { |
347 | case 2: | 364 | case 2: |
348 | case 3: | 365 | case 3: |
366 | case 6: | ||
367 | case 7: | ||
349 | indio_dev->channels = mcp3422_channels; | 368 | indio_dev->channels = mcp3422_channels; |
350 | indio_dev->num_channels = ARRAY_SIZE(mcp3422_channels); | 369 | indio_dev->num_channels = ARRAY_SIZE(mcp3422_channels); |
351 | break; | 370 | break; |
352 | case 4: | 371 | case 4: |
372 | case 8: | ||
353 | indio_dev->channels = mcp3424_channels; | 373 | indio_dev->channels = mcp3424_channels; |
354 | indio_dev->num_channels = ARRAY_SIZE(mcp3424_channels); | 374 | indio_dev->num_channels = ARRAY_SIZE(mcp3424_channels); |
355 | break; | 375 | break; |
@@ -375,6 +395,9 @@ static const struct i2c_device_id mcp3422_id[] = { | |||
375 | { "mcp3422", 2 }, | 395 | { "mcp3422", 2 }, |
376 | { "mcp3423", 3 }, | 396 | { "mcp3423", 3 }, |
377 | { "mcp3424", 4 }, | 397 | { "mcp3424", 4 }, |
398 | { "mcp3426", 6 }, | ||
399 | { "mcp3427", 7 }, | ||
400 | { "mcp3428", 8 }, | ||
378 | { } | 401 | { } |
379 | }; | 402 | }; |
380 | MODULE_DEVICE_TABLE(i2c, mcp3422_id); | 403 | MODULE_DEVICE_TABLE(i2c, mcp3422_id); |
@@ -399,5 +422,5 @@ static struct i2c_driver mcp3422_driver = { | |||
399 | module_i2c_driver(mcp3422_driver); | 422 | module_i2c_driver(mcp3422_driver); |
400 | 423 | ||
401 | MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>"); | 424 | MODULE_AUTHOR("Angelo Compagnucci <angelo.compagnucci@gmail.com>"); |
402 | MODULE_DESCRIPTION("Microchip mcp3422/3/4 driver"); | 425 | MODULE_DESCRIPTION("Microchip mcp3422/3/4/6/7/8 driver"); |
403 | MODULE_LICENSE("GPL v2"); | 426 | MODULE_LICENSE("GPL v2"); |