Re: [NEW DRIVER V3 7/8] DA9058 HWMON driver
On Wed, Aug 15, 2012 at 04:05:24PM +0100, Anthony Olech wrote: > This is the HWMON component driver of the Dialog DA9058 PMIC. > This driver is just one component of the whole DA9058 PMIC driver. > It depends on the CORE and ADC component drivers of the DA9058 MFD. > If so, please state as dependencies in Kconfig. Also see below. > Signed-off-by: Anthony Olech > Signed-off-by: David Dajun Chen > --- > Documentation/hwmon/da9058 | 30 +++ > drivers/hwmon/Kconfig| 10 + > drivers/hwmon/Makefile |1 + > drivers/hwmon/da9058-hwmon.c | 425 > ++ > 4 files changed, 466 insertions(+), 0 deletions(-) > create mode 100644 Documentation/hwmon/da9058 > create mode 100644 drivers/hwmon/da9058-hwmon.c > The patch neither applies on top of 3.6-rc1 nor my -next tree. What is its parent ? > diff --git a/Documentation/hwmon/da9058 b/Documentation/hwmon/da9058 > new file mode 100644 > index 000..60634c5 > --- /dev/null > +++ b/Documentation/hwmon/da9058 > @@ -0,0 +1,30 @@ > +Kernel driver da9058-hwmon > +== > + > +Supported chips: > + * Dialog Semiconductor DA9058 PMIC > +Prefix: 'da9058' > +Datasheet: > + http://www.dialog-semiconductor.com/products/power-management/da9058 > + > +Authors: Opensource [Anthony Olech] > + > +Description > +--- > + > +The DA9058 PMIC contains a 5 channel ADC which can be used to monitor a > +range of system operating parameters, including the battery voltage and > +temperature. The ADC measures voltage, but two of the ADC channels can > +be configured to supply a current, so that if an NTC termister is connected > +then the voltage reading can be converted to a temperature. Currently the > +driver provides reporting of all the input values but does not provide any > +alarms. > + > +Voltage Monitoring > +-- > + > +Voltages are sampled in either 'automatic' or 'manual' mode, which is an > +initialization parameter set in the platform data by the machine driver. > +In manual mode the ADC conversion is 12 bit and in automatic mode it is > +10 bit. However all the raw readings are reported as 12 bit numbers. > + This results in a whitespace error (no blank line at EOF). > diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig > index 6f1d167..0986f43 100644 > --- a/drivers/hwmon/Kconfig > +++ b/drivers/hwmon/Kconfig > @@ -294,6 +294,16 @@ config SENSORS_ATXP1 > This driver can also be built as a module. If so, the module > will be called atxp1. > > +config SENSORS_DA9058 > + tristate "Dialog Semiconductor DA9058 ADC" > + depends on I2C Presumably also depends on the MFD driver and possibly EXPERIMENTAL. The one thing it does not depend on, at least not directly, is I2C, since it does not perform any I2C function calls. > + help > + If you say yes here you get support for ADC on the Dialog > + Semiconductor DA9058 PMIC. > + > + This driver can also be built as a module. If so, the module > + will be called da9058-hwmon. > + > config SENSORS_DS620 > tristate "Dallas Semiconductor DS620" > depends on I2C > diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile > index e1eeac1..be99572 100644 > --- a/drivers/hwmon/Makefile > +++ b/drivers/hwmon/Makefile > @@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o > obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o > obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o > obj-$(CONFIG_SENSORS_DME1737)+= dme1737.o > +obj-$(CONFIG_SENSORS_DA9058) += da9058-hwmon.o In alphabetical order, please > obj-$(CONFIG_SENSORS_DS620) += ds620.o > obj-$(CONFIG_SENSORS_DS1621) += ds1621.o > obj-$(CONFIG_SENSORS_EMC1403)+= emc1403.o > diff --git a/drivers/hwmon/da9058-hwmon.c b/drivers/hwmon/da9058-hwmon.c > new file mode 100644 > index 000..8953170 > --- /dev/null > +++ b/drivers/hwmon/da9058-hwmon.c > @@ -0,0 +1,425 @@ > +/* > + * Copyright (C) 2012 Dialog Semiconductor Ltd. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +static ssize_t da9058_vbat_show_txt(struct device *dev, > + struct device_attribute *devattr, char *buf) Please align second lines of function declarations and function calls with the opening (. You don't need separate functions for all the label show functions. One function plus index is good enough. Look into the da902 driver for an example. _label instead of _txt might be a better function name. > +{ > + return sprintf(buf, "vbat\n"); > +} > + > +static ssize_t da9058_vbat_show_min(struc
[NEW DRIVER V3 7/8] DA9058 HWMON driver
This is the HWMON component driver of the Dialog DA9058 PMIC. This driver is just one component of the whole DA9058 PMIC driver. It depends on the CORE and ADC component drivers of the DA9058 MFD. Signed-off-by: Anthony Olech Signed-off-by: David Dajun Chen --- Documentation/hwmon/da9058 | 30 +++ drivers/hwmon/Kconfig| 10 + drivers/hwmon/Makefile |1 + drivers/hwmon/da9058-hwmon.c | 425 ++ 4 files changed, 466 insertions(+), 0 deletions(-) create mode 100644 Documentation/hwmon/da9058 create mode 100644 drivers/hwmon/da9058-hwmon.c diff --git a/Documentation/hwmon/da9058 b/Documentation/hwmon/da9058 new file mode 100644 index 000..60634c5 --- /dev/null +++ b/Documentation/hwmon/da9058 @@ -0,0 +1,30 @@ +Kernel driver da9058-hwmon +== + +Supported chips: + * Dialog Semiconductor DA9058 PMIC +Prefix: 'da9058' +Datasheet: + http://www.dialog-semiconductor.com/products/power-management/da9058 + +Authors: Opensource [Anthony Olech] + +Description +--- + +The DA9058 PMIC contains a 5 channel ADC which can be used to monitor a +range of system operating parameters, including the battery voltage and +temperature. The ADC measures voltage, but two of the ADC channels can +be configured to supply a current, so that if an NTC termister is connected +then the voltage reading can be converted to a temperature. Currently the +driver provides reporting of all the input values but does not provide any +alarms. + +Voltage Monitoring +-- + +Voltages are sampled in either 'automatic' or 'manual' mode, which is an +initialization parameter set in the platform data by the machine driver. +In manual mode the ADC conversion is 12 bit and in automatic mode it is +10 bit. However all the raw readings are reported as 12 bit numbers. + diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 6f1d167..0986f43 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -294,6 +294,16 @@ config SENSORS_ATXP1 This driver can also be built as a module. If so, the module will be called atxp1. +config SENSORS_DA9058 + tristate "Dialog Semiconductor DA9058 ADC" + depends on I2C + help + If you say yes here you get support for ADC on the Dialog + Semiconductor DA9058 PMIC. + + This driver can also be built as a module. If so, the module + will be called da9058-hwmon. + config SENSORS_DS620 tristate "Dallas Semiconductor DS620" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index e1eeac1..be99572 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o obj-$(CONFIG_SENSORS_ATXP1)+= atxp1.o obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o obj-$(CONFIG_SENSORS_DME1737) += dme1737.o +obj-$(CONFIG_SENSORS_DA9058) += da9058-hwmon.o obj-$(CONFIG_SENSORS_DS620)+= ds620.o obj-$(CONFIG_SENSORS_DS1621) += ds1621.o obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o diff --git a/drivers/hwmon/da9058-hwmon.c b/drivers/hwmon/da9058-hwmon.c new file mode 100644 index 000..8953170 --- /dev/null +++ b/drivers/hwmon/da9058-hwmon.c @@ -0,0 +1,425 @@ +/* + * Copyright (C) 2012 Dialog Semiconductor Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +static ssize_t da9058_vbat_show_txt(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + return sprintf(buf, "vbat\n"); +} + +static ssize_t da9058_vbat_show_min(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + return sprintf(buf, "2500\n"); +} + +static ssize_t da9058_vbat_show_max(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + return sprintf(buf, "4500\n"); +} + +static ssize_t da9058_vbat_show_adc(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + struct da9058_hwmon *hwmon = dev_get_drvdata(dev); + int voltage; /* x000 .. xFFF = 2500 .. 4500 mV */ + int ret; + + ret = da9058_adc_read(hwmon->da9058, DA9058_ADCMAN_MUXSEL_VBAT, + hwmon->use_automatic_adc, &voltage); + if (ret) + return ret; + + return sprintf(buf, "%d\n", 2500 + voltage * 2000 / 0xFFF); +} + +static ssize_t da9058_tbat_show_txt(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + return sprintf(buf,