HWMON: DA9052 hwmon driver v1
Subsystems (3)
PATCH 6/11 HWMON: DA9052 hwmon driver v1
The DA9052 PMIC provides an Analogue to Digital Converter with 10 bits resolution and 10 channels.
This patch montiors the DA9052 PMIC's ADC channels mostly for battery parameters like battery temperature, junction temperature, battery current etc.
--- Documentation/hwmon/da9052 | 58 ++++++++ drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/da9052-hwmon.c | 332 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 401 insertions(+), 0 deletions(-) create mode 100755 Documentation/hwmon/da9052 create mode 100755 drivers/hwmon/da9052-hwmon.c
Documentation/hwmon/da9052 new file +58 -0
@@ -0,0 +1,58 @@ +Kernel driver da9052-hwmon +========================== + +Supported chips: + * Dialog Semiconductors DA9052 PMICs + Prefix: 'da9052' + Datasheet: Kindly visit www.dialog-semiconductor.com and request for the + official datasheet. + +Authors: David Dajun Chen <[email protected]> + +Description +----------- + +The DA9052 provides an Analogue to Digital Converter (ADC) with 10 bits +resolution and track and hold circuitry combined with an analogue input +multiplexer. The analogue input multiplexer will allow conversion of up to 10 +different inputs. The track and hold circuit ensures stable input voltages at +the input of the ADC during the conversion. + +The ADC is used to measure the following inputs: +Channel 0: VDDOUT - measurement of the system voltage +Channel 1: ICH - internal battery charger current measurement +Channel 2: TBAT - output from the battery NTC +Channel 3: VBAT - measurement of the battery voltage +Channel 4: ADC_IN4 - high impedance input (0 - 2.5V) +Channel 5: ADC_IN5 - high impedance input (0 - 2.5V) +Channel 6: ADC_IN6 - high impedance input (0 - 2.5V) +Channel 7: XY - TSI interface to measure the X and Y voltage of the touch +screen resistive potentiometers +Channel 8: Internal Tjunc. - sense (internal temp. sensor) +Channel 9: VBBAT - measurement of the backup battery voltage + +By using sysfs attributes we can measure the system voltage VDDOUT, the battery +charging current ICH, battery temperature TBAT, battery junction temperature +TJUNC, battery voltage VBAT and the back up battery voltage VBBAT. + +Voltage Monitoring +------------------ + +Voltages are sampled by a 10 bit ADC. Voltages in millivolts are 1.465 +times the ADC value. + +Temperature Monitoring +---------------------- + +Temperatures are sampled by a 10 bit ADC. Junction and battery temperatures +are monitored by the ADC channels. + +The junction temperature is calculated: + Degrees celsius = 1.708 * (TJUNC_RES - T_OFFSET) - 108.8 +The junction temperature attribute is supported by the driver. + +The battery temperature is calculated: + Degree Celcius = 1 / (t1 + 1/298)- 273 +where t1 = (1/B)* ln(( ADCval * 2.5)/(R25*ITBAT*255)) +Default values of R25, B, ITBAT are 10e3, 3380 and 50e-6 respectively. +
drivers/hwmon/Kconfig +10 -0
@@ -303,6 +303,16 @@ config SENSORS_DS1621 This driver can also be built as a module. If so, the module will be called ds1621. +config SENSORS_DA9052_ADC + tristate "Dialog DA9052 HWMON" + depends on PMIC_DA9052 + help + Say y here to support the ADC found on + Dialog Semiconductor DA9052 PMIC. + + This driver can also be built as module. If so, the module + will be called da9052-hwmon. + config SENSORS_I5K_AMB tristate "FB-DIMM AMB temperature sensor on Intel 5000 series chipsets" depends on PCI && EXPERIMENTAL
drivers/hwmon/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o obj-$(CONFIG_SENSORS_PKGTEMP) += pkgtemp.o +obj-$(CONFIG_SENSORS_DA9052_ADC) += da9052-hwmon.o obj-$(CONFIG_SENSORS_DME1737) += dme1737.o obj-$(CONFIG_SENSORS_DS620) += ds620.o obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
drivers/hwmon/da9052-hwmon.c new file +332 -0
332 lines not on this page · raw message
Quoted 8 lines · On Tue, 2011-06-28 at 10:24 -0400, ashishj3 wrote:
The DA9052 PMIC provides an Analogue to Digital Converter with 10 bits resolution and 10 channels.
This patch montiors the DA9052 PMIC's ADC channels mostly for battery parameters like battery temperature, junction temperature, battery current etc.
Signed-off-by David Dajun Chen <[email protected]>Signed-off-by Ashish Jangam <[email protected]>
[ ... ]
Quoted 21 lines
drivers/hwmon/da9052-hwmon.c new file +21
-0+static ssize_t da9052_read_vddout (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +struct da9052_hwmon *hwmon =dev_get_drvdata (dev); +int ret, vdd =-1 ; + +mutex_lock (&hwmon->hwmon_lock); + + ret =da9052_enable_vddout_channel (hwmon->da9052); +if (ret <0 ) + goto hwmon_err; + + ret =da9052_reg_read (hwmon->da9052,DA9052_VDD_RES_REG ); +if (ret <0 ) +pr_err ("failed to read VDD_RES_REG\n" ); +else + vdd = ret; + + ret =da9052_disable_vddout_channel (hwmon->da9052); +if (ret <0 ) + goto hwmon_err;
drivers/hwmon/da9052-hwmon.c line 101
Quoted 10 lines
drivers/hwmon/da9052-hwmon.c new file +10
-0+ +if (vdd >=0 ) { +mutex_unlock (&hwmon->hwmon_lock); +return sprintf (buf,"%d\n" , vdd); + } + +hwmon_err: +mutex_unlock (&hwmon->hwmon_lock); +return ret; +}
This function still produces a bad result if the call to da9052_reg_read() fails and the call to da9052_disable_vddout_channel() doesn't.
I would suggest to replace pr_err() with "goto hwmon_err". If you do that, you don't need to initialize vdd, you don't need the else case for its assignment, and you don't need "if (vdd >= 0)" either.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 28 lines · Guenter Roeck
Quoted 27 lines · ashish jangam
drivers/hwmon/da9052-hwmon.c new file +27
-0+static ssize_t da9052_read_vddout (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +struct da9052_hwmon *hwmon =dev_get_drvdata (dev); +int ret, vdd =-1 ; + +mutex_lock (&hwmon->hwmon_lock); + + ret =da9052_enable_vddout_channel (hwmon->da9052); +if (ret <0 ) + goto hwmon_err; + + ret =da9052_reg_read (hwmon->da9052,DA9052_VDD_RES_REG ); +if (ret <0 ) +pr_err ("failed to read VDD_RES_REG\n" ); +else + vdd = ret; + + ret =da9052_disable_vddout_channel (hwmon->da9052); +if (ret <0 ) + goto hwmon_err; + +if (vdd >=0 ) { +mutex_unlock (&hwmon->hwmon_lock); +return sprintf (buf,"%d\n" , vdd); + } +
Quoted 8 lines
drivers/hwmon/da9052-hwmon.c line 101
Quoted 4 lines
drivers/hwmon/da9052-hwmon.c new file +4
-0+hwmon_err: +mutex_unlock (&hwmon->hwmon_lock); +return ret; +}This function still produces a bad result if the call to
da9052_reg_read()fails and the call toda9052_disable_vddout_channel()doesn't.
Thanks much for comments and patience. When vddout channel is enabled and then read from this channel fails then, in this case should vddout channel get disabled? Is this correct understanding.
Quoted 4 lines
I would suggest to replace
pr_err()with "gotohwmon_err". If you do that, you don't need to initialize vdd, you don't need the else case for its assignment, and you don't need "if (vdd >= 0)" either.
Will take care of this. Thanks...Ashish
Quoted 5 lines
Guenter
Quoted 37 lines · Ashish Jangam
Quoted 28 lines · Guenter Roeck
Quoted 27 lines · ashish jangam
drivers/hwmon/da9052-hwmon.c new file +27
-0+static ssize_t da9052_read_vddout (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +struct da9052_hwmon *hwmon =dev_get_drvdata (dev); +int ret, vdd =-1 ; + +mutex_lock (&hwmon->hwmon_lock); + + ret =da9052_enable_vddout_channel (hwmon->da9052); +if (ret <0 ) + goto hwmon_err; + + ret =da9052_reg_read (hwmon->da9052,DA9052_VDD_RES_REG ); +if (ret <0 ) +pr_err ("failed to read VDD_RES_REG\n" ); +else + vdd = ret; + + ret =da9052_disable_vddout_channel (hwmon->da9052); +if (ret <0 ) + goto hwmon_err; + +if (vdd >=0 ) { +mutex_unlock (&hwmon->hwmon_lock); +return sprintf (buf,"%d\n" , vdd); + } +Quoted 8 lines
drivers/hwmon/da9052-hwmon.c line 101
Quoted 4 lines
drivers/hwmon/da9052-hwmon.c new file +4
-0+hwmon_err: +mutex_unlock (&hwmon->hwmon_lock); +return ret; +}This function still produces a bad result if the call to
da9052_reg_read()fails and the call toda9052_disable_vddout_channel()doesn't.
Quoted 3 lines
Thanks much for comments and patience. When vddout channel is enabled and then read from this channel fails then, in this case should vddout channel get disabled? Is this correct understanding.
Hmm, yes, you are right there. You should try to disable it. But you would have to do that such that you don't override the original error. One possibility would be to add an unconditional call to da9052_disable_vddout_channel() into the error path.
ret = da9052_reg_read(hwmon->da9052, DA9052_VDD_RES_REG); if (ret < 0) goto hwmon_err_release; ... hwmon_err_release: da9052_disable_vddout_channel(hwmon->da9052); hwmon_err: ...
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors