hwmon: ADC124S501 generic driver
RFC PATCH 1/1 hwmon: ADC124S501 generic driver
SPI driver for analog to digital converters national semiconductor ADC081S101, ADC124S501, ...
Hi all!
patch against 2.6.26, tested on a custom arm board and only compil-tested on x86.
This driver add support for National Semiconductor ADC<bb><c>S<sss> chip family, where:
* bb is the resolution in number of bits (8, 10, 12)
* c is the number of channels (1, 2, 4)
* sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500 kSPS and 101 for 1 MSPS)
Some remarks:
* The chip type (-> the number of inputs) are determined by the module alias, is it a good idea? it could be implemented using platform data.
* The Makefile seems ordered alphabetically, what order should be used for the Konfig file?
Best regards
Marc
drivers/hwmon/Kconfig +16 -0
@@ -390,6 +390,22 @@ config SENSORS_LM70 This driver can also be built as a module. If so, the module will be called lm70. +config SENSORS_ADCXX + tristate "National Semiconductor ADCxxxSxxx" + depends on SPI_MASTER && EXPERIMENTAL + help + If you say yes here you get support for the National Semiconductor + ADC<bb><c>S<sss> chip family, where + * bb is the resolution in number of bits (8, 10, 12) + * c is the number of channels (1, 2, 4) + * sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500 + kSPS and 101 for 1 MSPS) + + Examples : ADC081S101, ADC124S501, ... + + This driver can also be built as a module. If so, the module + will be called adcxx. + config SENSORS_LM75 tristate "National Semiconductor LM75 and compatibles" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SENSORS_W83791D) += w83791d.o obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o obj-$(CONFIG_SENSORS_AD7418) += ad7418.o +obj-$(CONFIG_SENSORS_ADCXX) += adcxx.o obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
drivers/hwmon/adcxx.c new file +292 -0
292 lines not on this page · raw message
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 17 lines · On Wed, 23 Jul 2008 13:07:54 +0200 Marc Pignat <[email protected]> wrote:
SPI driver for analog to digital converters national semiconductor ADC081S101, ADC124S501, ...
Signed-off-by Marc Pignat <[email protected]>Hi all!
patch against 2.6.26, tested on a custom arm board and only compil-tested on x86.
This driver add support for National Semiconductor ADC<bb><c>S<sss> chip family, where:
* bb is the resolution in number of bits (8, 10, 12)
* c is the number of channels (1, 2, 4)
* sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500 kSPS and 101 for 1 MSPS)
Quoted 7 lines
Some remarks:
* The chip type (-> the number of inputs) are determined by the module alias, is it a good idea? it could be implemented using platform data.* The
Makefileseems ordered alphabetically, what order should be used for the Konfig file?
That changelog is a bit of a mess. I cleaned up up as:
SPI driver for analog to digital converters national semiconductor ADC081S101, ADC124S501, ...
This driver adds support for National Semiconductor ADC<bb><c>S<sss> chip family, where:
* bb is the resolution in number of bits (8, 10, 12)
* c is the number of channels (1, 2, 4)
* sss is the maximum conversion speed (021 for 200 kSPS, 051 for 500 kSPS and 101 for 1 MSPS)
Some remarks:
* The chip type (-> the number of inputs) are determined by the module alias, is it a good idea? it could be implemented using platform data.
but then didn't apply the patch.
Quoted 5 lines
...
drivers/hwmon/adcxx.c new file +2
-0+/* sysfs hook function */ +static ssize_t adcxx_read(struct device *dev,
drivers/hwmon/adcxx.c line 68
Quoted 10 lines
drivers/hwmon/adcxx.c new file +10
-0+ struct device_attribute *devattr, char *buf) +{ + struct spi_device *spi = to_spi_device(dev); +struct sensor_device_attribute *attr =to_sensor_dev_attr (devattr); +struct adcxx *adc =dev_get_drvdata (&spi->dev); + +u8 tx_buf[2 ] = { attr->index <<3 };/* other bits are don't care */ +u8 rx_buf[2 ]; +int status; +int value;
The driver has rather a lot of inexplicable blank lines in the middle of the automatic variable definitions. The preferred style is no blank lines within the definitions and a single blank line after them all, thanks.
Quoted 36 lines
...
drivers/hwmon/adcxx.c new file +33
-0+static int __devinit adcxx_probe (struct spi_device *spi,int channels) +{ +struct adcxx *adc; +int status; +int i; + + adc =kzalloc (sizeof *adc,GFP_KERNEL ); +if (!adc) +return -ENOMEM ; + +/* set a default value for the reference */ + adc->reference =3300 ; + + adc->channels = channels; + +mutex_init (&adc->lock); + +dev_set_drvdata (&spi->dev, adc); + +for (i =0 ; i <3 + adc->channels; i++) { + status =device_create_file (&spi->dev, &ad_input[i].dev_attr); +if (status) + goto out_dev_create_file_failed; + } + + adc->hwmon_dev =hwmon_device_register (&spi->dev); +if (IS_ERR (adc->hwmon_dev)) { +dev_dbg (&spi->dev,"hwmon_device_register failed.\n" ); + status =PTR_ERR (adc->hwmon_dev); + goto out_dev_reg_failed; + } + +return 0 ;
drivers/hwmon/adcxx.c line 204
Quoted 10 lines
drivers/hwmon/adcxx.c new file +10
-0+ +out_dev_create_file_failed: +hwmon_device_unregister (adc->hwmon_dev); +for (i =0 ; i <3 + adc->channels; i++) +device_remove_file (&spi->dev, &ad_input[i].dev_attr); +out_dev_reg_failed: +dev_set_drvdata (&spi->dev,NULL ); +kfree (adc); +return status; +}
The error recovery here is messed up. The targets of the `goto's are reversed. But even if that is fixed, we can end up doing device_remove_file() of objects which weren't successfully created. That might work, or it might generate runtime warnings or it might crash. I don't know. It'd be best to just avoid doing it?
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors