hwmon: Add MCP3021 ADC driver
Subsystems (2)
PATCH v5 1/1 hwmon: Add MCP3021 ADC driver
Add I2C driver for MCP3021 that is an ADC chip from Microchip. The MCP3021 is a successive approximation A/D converter (ADC) with 10-bit resolution.
The driver export the value of Vin to sysfs, the voltage unit is mV. Through the sysfs interface, lm-sensors tool can also display Vin voltage.
---
The patch V5 fixed two issues based on Jean's comments.
Documentation/hwmon/mcp3021 | 22 ++++++ drivers/hwmon/Kconfig | 10 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/mcp3021.c | 176 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+), 0 deletions(-) create mode 100644 Documentation/hwmon/mcp3021 create mode 100644 drivers/hwmon/mcp3021.c
Documentation/hwmon/mcp3021 new file +22 -0
@@ -0,0 +1,22 @@ +Kernel driver MCP3021 +=========== + +Supported chips: + * Microchip Technology MCP3021 + Prefix: 'mcp3021' + Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21805a.pdf + +Author: Mingkai Hu + +Description +----------- + +This driver implements support for the Microchip Technology MCP3021 chip. + +The Microchip Technology Inc. MCP3021 is a successive approximation A/D +converter (ADC) with 10-bit resolution. +This device provides one single-ended input with very low power consumption. +Communication to the MCP3021 is performed using a 2-wire I2C compatible +interface. Standard (100 kHz) and Fast (400 kHz) I2C modes are available. +The default I2C device address is 0x4d (contact the Microchip factory for +additional address options).
drivers/hwmon/Kconfig +10 -0
@@ -812,6 +812,16 @@ config SENSORS_MAX6650 This driver can also be built as a module. If so, the module will be called max6650. +config SENSORS_MCP3021 + tristate "Microchip MCP3021" + depends on I2C && EXPERIMENTAL + help + If you say yes here you get support for the MCP3021 chip + that is a A/D converter (ADC) with 10-bit resolution. + + This driver can also be built as a module. If so, the module + will be called mcp3021. + config SENSORS_NTC_THERMISTOR tristate "NTC thermistor support" depends on EXPERIMENTAL
drivers/hwmon/Makefile +1 -0
@@ -95,6 +95,7 @@ obj-$(CONFIG_SENSORS_MAX6639) += max6639.o obj-$(CONFIG_SENSORS_MAX6642) += max6642.o obj-$(CONFIG_SENSORS_MAX6650) += max6650.o obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o +obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o obj-$(CONFIG_SENSORS_PC87360) += pc87360.o obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
drivers/hwmon/mcp3021.c new file +176 -0
176 lines not on this page · raw message
Signature · 8 lines
1.7.5.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 9 lines · Xie Xiaobo
Add I2C driver for MCP3021 that is an ADC chip from Microchip. The MCP3021 is a successive approximation A/D converter (ADC) with 10-bit resolution.
The driver export the value of Vin to sysfs, the voltage unit is mV. Through the sysfs interface, lm-sensors tool can also display Vin voltage.Signed-off-by Mingkai Hu <[email protected]>Signed-off-by Xie Xiaobo <[email protected]>
[ ... ]
drivers/hwmon/mcp3021.c line 90
Quoted 3 lines
drivers/hwmon/mcp3021.c new file +3
-0+ +if (reg <0 ) { +printk (KERN_ERR "%s encountered error %d\n" , __func__, reg);
You should use dev_err() here.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 11 lines · Guenter Roeck
Quoted 9 lines · Xie Xiaobo
Add I2C driver for MCP3021 that is an ADC chip from Microchip. The MCP3021 is a successive approximation A/D converter (ADC) with 10-bit resolution.
The driver export the value of Vin to sysfs, the voltage unit is mV. Through the sysfs interface, lm-sensors tool can also display Vin voltage.Signed-off-by Mingkai Hu <[email protected]>Signed-off-by Xie Xiaobo <[email protected]>
Quoted 7 lines
[ ... ]
drivers/hwmon/mcp3021.c line 90
Quoted 3 lines
drivers/hwmon/mcp3021.c new file +3
-0+ +if (reg <0 ) { +printk (KERN_ERR "%s encountered error %d\n" , __func__, reg);You should use
dev_err()here.
I don't think there's any point in printing an error message in the first place. I/O errors over I2C can happen, and the caller will get an error when it happens. "sensors" will display an error message and other monitoring applications would do too. Logging an error message is redundant IMHO.
If Xie agrees, I'll just remove the message, no need to resent. We've gone through 4 reviews, it's probably enough for such a small driver, it's about time to accept it for the next merge window. Patch applied (with minor changes), thanks.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 26 lines · Jean Delvare
Quoted 11 lines · Guenter Roeck
Quoted 9 lines · Xie Xiaobo
Add I2C driver for MCP3021 that is an ADC chip from Microchip. The MCP3021 is a successive approximation A/D converter (ADC) with 10-bit resolution.
The driver export the value of Vin to sysfs, the voltage unit is mV. Through the sysfs interface, lm-sensors tool can also display Vin voltage.Signed-off-by Mingkai Hu <[email protected]>Signed-off-by Xie Xiaobo <[email protected]>Quoted 7 lines
[ ... ]
drivers/hwmon/mcp3021.c line 90
Quoted 3 lines
drivers/hwmon/mcp3021.c new file +3
-0+ +if (reg <0 ) { +printk (KERN_ERR "%s encountered error %d\n" , __func__, reg);You should use
dev_err()here.I don't think there's any point in printing an error message in the first place. I/O errors over I2C can happen, and the caller will get an error when it happens. "sensors" will display an error message and other monitoring applications would do too. Logging an error message is redundant IMHO.
Quoted 5 lines
If Xie agrees, I'll just remove the message, no need to resent. We've gone through 4 reviews, it's probably enough for such a small driver, it's about time to accept it for the next merge window. Patch applied (with minor changes), thanks.
Ok with me. I am not a friend of such error messages.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
SGkgSmVhbiwNCg0KUmVtb3ZpbmcgdGhlIHByaW50ayBpcyBPSyBmb3IgbWUuIFRoYW5rIHlvdSB2 ZXJ5IG11Y2guDQoNCkJScw0KWGllIFhpYW9ibw0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0t LS0tDQo+IEZyb206IEplYW4gRGVsdmFyZSBbbWFpbHRvOmtoYWx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