Re: [PATCH v6 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-25 Thread Oleksandr Kozaruk
On Sat, Jul 20, 2013 at 11:43:42AM +0100, Jonathan Cameron wrote:
 On 07/19/2013 10:27 AM, Oleksandr Kozaruk wrote:
  The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
  known also as Phoenix and PhoenixLite.
 
  The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
  respectively. Some channels have current source and are used for
  measuring voltage drop on resistive load for detecting battery ID
  resistance, or measuring voltage drop on NTC resistors for external
  temperature measurements. Some channels measure voltage, (i.e. battery
  voltage), and have voltage dividers, thus, capable to scale voltage.
  Some channels are dedicated for measuring die temperature.
 
  Some channels are calibrated in 2 points, having offsets from ideal
  values kept in trim registers. This is used to correct measurements.
 
  The differences between GPADC in TWL6030 and TWL6032:
  - 10 bit vs 12 bit ADC;
  - 17 vs 19 channels;
  - channels have different purpose(i.e. battery voltage
channel 8 vs channel 18);
  - trim values are interpreted differently.
 
  Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
  Girish S Ghongdemath.
 
  Signed-off-by: Balaji T K balaj...@ti.com
  Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
  Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
 A few little bits and bobs inline.
 
 My only major query is about the lack of info for the temperature
 channels.  How do you convert these to useful real world units?

On blaze tablet platform(OMAP 4) temperature channels were used by
thermal framework and battery driver.
Thermal was using channel 4 [1]

Here is the comment from the driver:

* NTC termistor (NCP15WB473F) schematic connection for OMAP4460 board:
*
*  [Vref]
*|
*$ (Rpu)
*|
*++---[Vin]
*||
*   [Rt]  $ (Rpd)
*||
*    (ground)
*
* NTC termistor resistanse (Rt, k) calculated from following formula:
*
* Rt = Rpd * Rpu * Vin / (Rpd * (Vref - Vin) - Rpu * Vin)
*
* where   Vref (GPADC_VREF4) - reference voltage, Vref = 1250 mV;
* Vin (GPADC_IN4) - measuring voltage, Vin = 0...1250 mV;
* Rpu (R1041) - pullup resistor, Rpu = 10 k;
* Rpd (R1043) - pulldown resistor, Rpd = 220 k;
*
* Pcb temp sensor temperature (t, C) calculated from following formula:
*
* t = 1 / (ln(Rt / Rt0) / B + 1 / T0) - 273
*
* where   Rt0 - NTC termistor resistance at 25 C, Rt0 = 47 k;
* B - specific constant, B = 4131 K;
* T0 - temperature, T0 = 298 K
[..]

And then there is a table for conversion:
/*
 * Temperature values in degrees celsius,
 * voltage values from 156 to 1191 milli volts
*/
static s8 mvolt_to_temp[] = {
   125, 125, 125, 124, 124, 124, 124, 123, 123, 123, 122, 122,
   122, 122, 121, 121, 121, 121, 120, 120, 120, 120, 119, 119,
[..]

The battery driver was using channel 1, dedicated for measuring battery
temperature.
static void twl6030_bci_battery_work(struct work_struct *work)
{
[..]
for (temp = 0; temp  di-platform_data-tblsize; temp++) {
if (adc_code = di-platform_data-
battery_tmp_tbl[temp])
break;
}

/* first 2 values are for negative temperature */
di-temp_C = (temp - 2) * 10; * /* in tenths of degree Celsius */
[..]
}
static int omap4_batt_table[] = {
/* adc code for temperature in degree C */
929, 925, /* -2 ,-1 */
920, 917, 912, 908, 904, 899, 895, 890, 885, 880, /* 00 - 09 */
875, 869, 864, 858, 853, 847, 841, 835, 829, 823, /* 10 - 19 */
[..]
591, 583, 575, 567, 559, 551, 543, 535, 527, 519, /* 50 - 59 */
511, 504, 496 /* 60 - 62 */
};

So, one driver was using millivolts and the other ADC code,
Though converting to millivolts and the to temperature, seems,
to be redundant, as code can be converted to temperature.
If I recollect correctly the previous driver version was using just
ADC code.

Regards,
Sasha.

[1] 
http://git.omapzoom.org/?p=kernel/omap.git;a=blob;f=drivers/staging/thermal_framework/sensor/thermistor_sensor.c;h=828d8010579b55ec4a122c49a2e5b547b1e41e63;hb=decb3fd3ddf207e0118d0d558459acc7094e

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-25 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1027 +++
 3 files changed, 1042 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 93129ec..f8f9f18 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -160,6 +160,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 8f475d3..db430bd 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -17,4 +17,5 @@ obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..2b63083
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1027 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+/*
+ * twl6030 per TRM has 17 channels, and twl6032 has 19 channels
+ * 2 test network channels are not used,
+ * 2 die temperature channels are not used either, as it is not
+ * defined how to convert ADC value to temperature
+ */
+#define TWL6030_GPADC_USED_CHANNELS13
+#define TWL6030_GPADC_MAX_CHANNELS 15
+#define TWL6032_GPADC_USED_CHANNELS15
+#define TWL6032_GPADC_MAX_CHANNELS 19
+#define TWL6030_GPADC_NUM_TRIM_REGS16
+
+#define TWL6030_GPADC_CTRL_P1

[PATCH v8 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-25 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..b78e1d5 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   adc {
+   compatible = ti,twl6030-gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 0/2] TWL6030, TWL6032 GPADC driver

2013-07-25 Thread Oleksandr Kozaruk
Hello,

v8 - removed unused test channels completely, removed die
 temperature channels, as it is not known how to convert ADC code
 to temperature. There if formula for twl6030, but no formula
 for twl6032.
v7 - addressed clean up comments, removed test channels
v6 - addressed comments about trim bits, checkpatch clean up
v5 - gpadc DT node renamed from gpadc to generic adc, added
 temperature channels; raw code is corracted with calibration
 data.
v4 - addressed comments: fixed style violation, bug in freeing memory,
 added comments explaining calibration method, removed test network
 channels from exposing to userspace, error handling for 
 wait_for_complition
v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.11-rc2


Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |6 +
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1027 +++
 4 files changed, 1048 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-22 Thread Oleksandr Kozaruk
Hi Jonathan,

On Sat, Jul 20, 2013 at 1:43 PM, Jonathan Cameron ji...@kernel.org wrote:
 On 07/19/2013 10:27 AM, Oleksandr Kozaruk wrote:
 The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
 known also as Phoenix and PhoenixLite.

 The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
 respectively. Some channels have current source and are used for
 measuring voltage drop on resistive load for detecting battery ID
 resistance, or measuring voltage drop on NTC resistors for external
 temperature measurements. Some channels measure voltage, (i.e. battery
 voltage), and have voltage dividers, thus, capable to scale voltage.
 Some channels are dedicated for measuring die temperature.

 Some channels are calibrated in 2 points, having offsets from ideal
 values kept in trim registers. This is used to correct measurements.

 The differences between GPADC in TWL6030 and TWL6032:
 - 10 bit vs 12 bit ADC;
 - 17 vs 19 channels;
 - channels have different purpose(i.e. battery voltage
   channel 8 vs channel 18);
 - trim values are interpreted differently.

 Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
 Girish S Ghongdemath.

 Signed-off-by: Balaji T K balaj...@ti.com
 Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
 Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
 A few little bits and bobs inline.

 My only major query is about the lack of info for the temperature
 channels.  How do you convert these to useful real world units?

If I get your question right: the ADC channels 1, 4 are dedicated for
measuring resistive value.
The temperature measurement will depend on:
1) the ADC code(provided by the driver);
2) value of the NTC resistor, its characteristics, the way it is
plugged in the circuit,
and may be some calibration data(platform dependent); How the driver can the
drive take care of these?
[...]

 +static int twl6030_gpadc_read_raw(struct iio_dev *indio_dev,
 +  const struct iio_chan_spec *chan,
 +  int *val, int *val2, long mask)
 +{
 + struct twl6030_gpadc_data *gpadc = iio_priv(indio_dev);
 + int ret = -EINVAL;
 I'm suprised you didn't get a warning about the assigment above
 being pointless as you overwrite ret just below.
Indeed, ret is overwritten, though, there is no warning from make C=2
and checkpatch is silent.
I'll remove the initialization.
[...]

 +
 +#define TWL6030_GPADC_CHAN(chn, _type, chan_info) {  \
 + .type = _type,  \
 + .channel = chn, \
 + .info_mask_separate = BIT(chan_info),   \
 + .indexed = 1,   \
 +}
 +


 Why list these at all?  I see they are no longer visible from
 userspace, but they are still taking up memory etc without I
 think ever being used?
I've kept it because for twl6032 there is a gap if I drop channels 15, 16,
as channels 17, 18 are used.

 +/* internal test network channel */
 +#define TWL6030_GPADC_TEST_CHAN(chn, chan_info) {\
 + .type = IIO_VOLTAGE,\
 + .channel = chn, \
 + .indexed = 1,   \
 +}
 +
 +static const struct iio_chan_spec twl6030_gpadc_iio_channels[] = {
 + TWL6030_GPADC_CHAN(0, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED),
 + TWL6030_GPADC_CHAN(1, IIO_TEMP, IIO_CHAN_INFO_RAW),
 So we have no other information about the temp channels other than
 raw adc counts?  If so, how are these useful?  I guess you might
 be intending to use iio-hwmon to get these into hwmon the use
 lm-sensors config files to convert to something useful.
 Otherwise, you probably want to get the board specific info on
 the calibration of these in here to make the data available to userspace
 in a useful format...

Hmm, it seems that info on the NTC type is board specific. And we
should get it from device tree?
I thought the driver just gives the ADC code, and consumer will know
what to do with the ADC data.
So, calculation for converting to temperature should be done in this driver?
I don't know how yet.
[...]

 +MODULE_AUTHOR(Texas Instruments Inc.);

 I would normally expect an actual person for
 the module author.  Is this TI policy or simply a case of no clear single
 author?  Note I believe there is no problem with having multiple
 MODULE_AUTHOR lines so that everyone who made a major contribution is
 included.

Yes, this is because of having multiple authors. I will change it for
Balaji, Graeme and myself.

Regards,
OK.
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-22 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..b78e1d5 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   adc {
+   compatible = ti,twl6030-gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-22 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |  14 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/twl6030-gpadc.c | 981 
 3 files changed, 996 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 93129ec..f8f9f18 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -160,6 +160,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 8f475d3..db430bd 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -17,4 +17,5 @@ obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..1b1962e
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,981 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 15
+#define TWL6032_GPADC_MAX_CHANNELS 19
+#define TWL6030_GPADC_NUM_TRIM_REGS16
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define TWL6030_GPADC_CTRL_P1_SP1  BIT(3)
+
+#define TWL6030_GPADC_GPCH0_LSB

[PATCH v7 0/2] TWL6030, TWL6032 GPADC driver

2013-07-22 Thread Oleksandr Kozaruk
Hello,

v7 - addressed clean up comments, removed test channels
v6 - addressed comments about trim bits, checkpatch clean up
v5 - gpadc DT node renamed from gpadc to generic adc, added
 temperature channels; raw code is corracted with calibration
 data.
v4 - addressed comments: fixed style violation, bug in freeing memory,
 added comments explaining calibration method, removed test network
 channels from exposing to userspace, error handling for 
 wait_for_complition
v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.11-rc2

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |   6 +
 drivers/iio/adc/Kconfig |  14 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/twl6030-gpadc.c | 981 
 4 files changed, 1002 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-20 Thread Oleksandr Kozaruk
Hi Sergei,

On Fri, Jul 19, 2013 at 1:18 PM, Sergei Shtylyov
sergei.shtyl...@cogentembedded.com wrote:
 Hello.


 On 07/19/2013 07:40 PM, Grygorii Strashko wrote:

 GPADC is the general purpose ADC present on twl6030.
 The dt data is interrupt used to trigger end of ADC
 conversion.


 Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
 ---
   arch/arm/boot/dts/twl6030.dtsi | 6 ++
   1 file changed, 6 insertions(+)


 diff --git a/arch/arm/boot/dts/twl6030.dtsi
 b/arch/arm/boot/dts/twl6030.dtsi
 index 2e3bd31..d7d4c28 100644
 --- a/arch/arm/boot/dts/twl6030.dtsi
 +++ b/arch/arm/boot/dts/twl6030.dtsi
 @@ -103,4 +103,10 @@
   compatible = ti,twl6030-pwmled;
   #pwm-cells = 2;
   };
 +
 +adc: gpadc {


 Read my lips: the node should be called just adc, not gpadc.

 Are you sure?


I didn't know how to express my disappointment from Oleksandr's inability
 to understand what I wanted to convey to him from 2 attempts... first,
How would you comment the following code, v3.10-rc7:

arch/arm/boot/dts/dbx5x0.dtsi, line 375
375  ab8500-gpadc {
376  compatible =
stericsson,ab8500-gpadc;
377  interrupts = 32
IRQ_TYPE_LEVEL_HIGH
arch/arm/boot/dts/dbx5x0.dtsi:  ab8500-gpadc {
arch/arm/boot/dts/dbx5x0.dtsi:
compatible = stericsson,ab8500-gpadc;
arch/arm/boot/dts/dbx5x0.dtsi:
vddadc-supply = ab8500_ldo_tvout_reg;


arch/arm/boot/dts/sama5d3.dtsi: tsadcc: tsadcc@f8018000 {
arch/arm/boot/dts/sama5d3.dtsi: compatible =
atmel,at91sam9x5-tsadcc;
arch/arm/boot/dts/sama5d3.dtsi:
atmel,tsadcc_clock = 30;

arch/arm/boot/dts/am33xx.dtsi:  tscadc: tscadc@44e0d000 {
arch/arm/boot/dts/am33xx.dtsi:  compatible = ti,am3359-tscadc;
arch/arm/boot/dts/am33xx.dtsi:  ti,hwmods = adc_tsc;
arch/arm/boot/dts/am33xx.dtsi:  am335x_adc: adc {
arch/arm/boot/dts/am33xx.dtsi:  compatible =
ti,am3359-adc;

Regards,
Sasha.

 changed the label instead of the node name, then he only dropped twl6030_
 prefix from the name. I should probably have been even more specific before.


 Why? The name was selected according to the documentation on device
 General
 purpose analog-to-digital converter (GPADC).


Sigh, we simply don't care whether this ADC is general-purpose or not.
 The main thing it is ADC.


 PS. Following your logic - GPIO need to renamed to IO everywhere ;P


GPIO is well known and established abbreviation, contrasted to GPADC.
 Moreover, ePAPR spec lists gpio as a generic node name.


 WBR, Sergei

 --
 To unsubscribe from this list: send the line unsubscribe linux-omap in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-19 Thread Oleksandr Kozaruk
Hello Lars,

On Thu, Jul 18, 2013 at 12:48 PM, Lars-Peter Clausen l...@metafoo.de wrote:
 On 07/18/2013 10:36 AM, Oleksandr Kozaruk wrote:
 Hello Lars,

 On Wed, Jul 17, 2013 at 9:04 PM, Lars-Peter Clausen l...@metafoo.de wrote:
 +static int twl6032_calibration(struct twl6030_gpadc_data *gpadc)
 +{
 + int chn, d1 = 0, d2 = 0, temp;
 + u8 trim_regs[17];
 + int ret;
 +
 + ret = twl_i2c_read(TWL6030_MODULE_ID2, trim_regs + 1,
 + TWL6030_GPADC_TRIM1, 16);
 + if (ret  0) {
 + dev_err(gpadc-dev, calibration failed\n);
 + return ret;
 + }
 +
 + /*
 +  * Loop to calculate the value needed for returning voltages from
 +  * GPADC not values.
 +  *
 +  * gain is calculated to 3 decimal places fixed point.
 +  */
 + for (chn = 0; chn  TWL6032_GPADC_MAX_CHANNELS; chn++) {
 +
 + switch (chn) {
 + case 0:
 + case 1:
 + case 2:
 + case 3:
 + case 4:
 + case 5:
 + case 6:
 + case 11:
 + case 12:
 + case 13:
 + case 14:
 + /* D1 */
 + d1 = (trim_regs[3]  0x1F)  2;
 + d1 |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + d1 = -d1;
 +
 + /* D2 */
 + d2 = (trim_regs[4]  0x3F)  2;
 + d2 |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + d2 = -d2;
 + break;
 + case 8:
 + /* D1 */
 + temp = (trim_regs[3]  0x1F)  2;
 + temp |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + temp = -temp;
 +
 + d1 = (trim_regs[8]  0x18)  1;
 + d1 |= (trim_regs[7]  0x1E)  1;
 + if (trim_regs[7]  0x01)
 + d1 = -d1;
 +
 + d1 += temp;
 +
 + /* D2 */
 + temp = (trim_regs[4]  0x3F)  2;
 + temp |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + temp = -temp;
 +
 + d2 = (trim_regs[10]  0x1F)  2;
 + d2 |= (trim_regs[8]  0x06)  1;
 + if (trim_regs[8]  0x01)
 + d2 = -d2;
 +
 + d2 += temp;
 + break;
 + case 9:
 + /* D1 */
 + temp = (trim_regs[3]  0x1F)  2;
 + temp |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + temp = -temp;
 +
 + d1 = (trim_regs[14]  0x18)  1;
 + d1 |= (trim_regs[12]  0x1E)  1;
 + if (trim_regs[12]  0x01)
 + d1 = -d1;
 +
 + d1 += temp;
 +
 + /* D2 */
 + temp = (trim_regs[4]  0x3F)  2;
 + temp |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + temp = -temp;
 +
 + d2 = (trim_regs[16]  0x1F)  2;
 + d2 |= (trim_regs[14]  0x06)  1;
 + if (trim_regs[14]  0x01)
 + d2 = -d2;
 +
 + d2 += temp;
 + case 10:
 + /* D1 */
 + d1 = (trim_regs[11]  0x0F)  3;
 + d1 |= (trim_regs[9]  0x0E)  1;
 + if (trim_regs[9]  0x01)
 + d1 = -d1;
 +
 + /* D2 */
 + d2 = (trim_regs[15]  0x0F)  3;
 + d2 |= (trim_regs[13]  0x0E)  1;
 + if (trim_regs[13]  0x01)
 + d2 = -d2;
 + break;
 + case 7:
 + case 18:
 + /* D1 */
 + temp = (trim_regs[3]  0x1F)  2;
 + temp |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + temp = -temp;
 +
 + d1 = (trim_regs[5]  0x7E)  1;
 + if (trim_regs[5]  0x01)
 + d1 = -d1;
 +.
 + d1 += temp;
 +
 + /* D2 */
 + temp = (trim_regs[4]  0x3F)  2;
 + temp |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + temp = -temp;
 +
 + d2 = (trim_regs[6]  0xFE)  1;
 + if (trim_regs[6]  0x01)
 + d2 = -d2

[PATCH v6 0/2] TWL6030, TWL6032 GPADC driver

2013-07-19 Thread Oleksandr Kozaruk
Hello,

v6 - addressed comments about trim bits, checkpatch clean up
v5 - gpadc DT node renamed from gpadc to generic adc, added
 temperature channels; raw code is corracted with calibration
 data.
v4 - addressed comments: fixed style violation, bug in freeing memory,
 added comments explaining calibration method, removed test network
 channels from exposing to userspace, error handling for 
 wait_for_complition
v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |   6 +
 drivers/iio/adc/Kconfig |  14 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/twl6030-gpadc.c | 991 
 4 files changed, 1012 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-19 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |  14 +
 drivers/iio/adc/Makefile|   1 +
 drivers/iio/adc/twl6030-gpadc.c | 991 
 3 files changed, 1006 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..3172461 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -150,6 +150,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..996ba09 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -16,4 +16,5 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..b42cfd6
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,991 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define TWL6030_GPADC_CTRL_P1_SP1  BIT(3)
+
+#define TWL6030_GPADC_GPCH0_LSB(0x29)
+
+#define TWL6030_GPADC_RT_SW1_EOC_MASK

[PATCH v6 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-19 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..d7d4c28 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   adc: gpadc {
+   compatible = ti,twl6030-gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-18 Thread Oleksandr Kozaruk
Hello Lars,

On Wed, Jul 17, 2013 at 9:04 PM, Lars-Peter Clausen l...@metafoo.de wrote:
 +static int twl6032_calibration(struct twl6030_gpadc_data *gpadc)
 +{
 + int chn, d1 = 0, d2 = 0, temp;
 + u8 trim_regs[17];
 + int ret;
 +
 + ret = twl_i2c_read(TWL6030_MODULE_ID2, trim_regs + 1,
 + TWL6030_GPADC_TRIM1, 16);
 + if (ret  0) {
 + dev_err(gpadc-dev, calibration failed\n);
 + return ret;
 + }
 +
 + /*
 +  * Loop to calculate the value needed for returning voltages from
 +  * GPADC not values.
 +  *
 +  * gain is calculated to 3 decimal places fixed point.
 +  */
 + for (chn = 0; chn  TWL6032_GPADC_MAX_CHANNELS; chn++) {
 +
 + switch (chn) {
 + case 0:
 + case 1:
 + case 2:
 + case 3:
 + case 4:
 + case 5:
 + case 6:
 + case 11:
 + case 12:
 + case 13:
 + case 14:
 + /* D1 */
 + d1 = (trim_regs[3]  0x1F)  2;
 + d1 |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + d1 = -d1;
 +
 + /* D2 */
 + d2 = (trim_regs[4]  0x3F)  2;
 + d2 |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + d2 = -d2;
 + break;
 + case 8:
 + /* D1 */
 + temp = (trim_regs[3]  0x1F)  2;
 + temp |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + temp = -temp;
 +
 + d1 = (trim_regs[8]  0x18)  1;
 + d1 |= (trim_regs[7]  0x1E)  1;
 + if (trim_regs[7]  0x01)
 + d1 = -d1;
 +
 + d1 += temp;
 +
 + /* D2 */
 + temp = (trim_regs[4]  0x3F)  2;
 + temp |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + temp = -temp;
 +
 + d2 = (trim_regs[10]  0x1F)  2;
 + d2 |= (trim_regs[8]  0x06)  1;
 + if (trim_regs[8]  0x01)
 + d2 = -d2;
 +
 + d2 += temp;
 + break;
 + case 9:
 + /* D1 */
 + temp = (trim_regs[3]  0x1F)  2;
 + temp |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + temp = -temp;
 +
 + d1 = (trim_regs[14]  0x18)  1;
 + d1 |= (trim_regs[12]  0x1E)  1;
 + if (trim_regs[12]  0x01)
 + d1 = -d1;
 +
 + d1 += temp;
 +
 + /* D2 */
 + temp = (trim_regs[4]  0x3F)  2;
 + temp |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + temp = -temp;
 +
 + d2 = (trim_regs[16]  0x1F)  2;
 + d2 |= (trim_regs[14]  0x06)  1;
 + if (trim_regs[14]  0x01)
 + d2 = -d2;
 +
 + d2 += temp;
 + case 10:
 + /* D1 */
 + d1 = (trim_regs[11]  0x0F)  3;
 + d1 |= (trim_regs[9]  0x0E)  1;
 + if (trim_regs[9]  0x01)
 + d1 = -d1;
 +
 + /* D2 */
 + d2 = (trim_regs[15]  0x0F)  3;
 + d2 |= (trim_regs[13]  0x0E)  1;
 + if (trim_regs[13]  0x01)
 + d2 = -d2;
 + break;
 + case 7:
 + case 18:
 + /* D1 */
 + temp = (trim_regs[3]  0x1F)  2;
 + temp |= (trim_regs[1]  0x06)  1;
 + if (trim_regs[1]  0x01)
 + temp = -temp;
 +
 + d1 = (trim_regs[5]  0x7E)  1;
 + if (trim_regs[5]  0x01)
 + d1 = -d1;
 +.
 + d1 += temp;
 +
 + /* D2 */
 + temp = (trim_regs[4]  0x3F)  2;
 + temp |= (trim_regs[2]  0x06)  1;
 + if (trim_regs[2]  0x01)
 + temp = -temp;
 +
 + d2 = (trim_regs[6]  0xFE)  1;
 + if (trim_regs[6]  0x01)
 + d2 = -d2;
 +
 + d2 += temp;
 + break;


 There is quite a bit of copy paste in here. Putting the bit swizziling into
 a helper 

Re: [PATCH 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-17 Thread Oleksandr Kozaruk

Hello Jonathan,

Two very quick comments based on quick glance as it may be a while 
before I can do a full review.


We still have channels that are only usable for temperature being 
output to user space as voltage channels? Is the conversion so very hard?


Can you please clarify what should return temperature channel for 
in_tempX_input (processed)? Is it voltage or Celsius degree?

in_tempX_raw should return ADC code? Right?

Regards,
OK.
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 0/2] TWL6030, TWL6032 GPADC driver

2013-07-17 Thread Oleksandr Kozaruk
Hello,

v5 - gpadc DT node renamed from gpadc to generic adc, added
 temperature channels; raw code is corracted with calibration
 data.
v4 - addressed comments: fixed style violation, bug in freeing memory,
 added comments explaining calibration method, removed test network
 channels from exposing to userspace, error handling for 
 wait_for_complition
v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |6 +
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1026 +++
 4 files changed, 1047 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-17 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1026 +++
 3 files changed, 1041 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..3172461 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -150,6 +150,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..996ba09 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -16,4 +16,5 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..97fad5b
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1026 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define TWL6030_GPADC_CTRL_P1_SP1  BIT(3)
+
+#define TWL6030_GPADC_GPCH0_LSB(0x29)
+
+#define TWL6030_GPADC_RT_SW1_EOC_MASK

[PATCH v5 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-17 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..322aa8e 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   adc: twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-17 Thread Oleksandr Kozaruk

On Mon, Jul 15, 2013 at 01:33:53PM +0200, Lars-Peter Clausen wrote:
 On 07/15/2013 01:09 PM, Kozaruk, Oleksandr wrote:
 [...]
 
  + ret = devm_request_threaded_irq(dev, irq, NULL,
  + twl6030_gpadc_irq_handler,
  + IRQF_ONESHOT, twl6030_gpadc, gpadc);
 
  You access memory in the interrupt handler which is freed before 
the interrupt

  handler is freed.
  Thanks for pointing this. devm_* will free memory for irq after the 
driver
  is removed and memory for the device is freed. I took me awhile to 
understand
  this. Is there going to be something like devm_iio_device_alloc? 
whould it be helpfull?

 

 Yes, I think it certainly makes sense to add a 
devm_iio_device_alloc(), care

 to send a patch?

Anything like this? (of course it's not a patch)

struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
{
struct iio_dev *indio_dev;
size_t alloc_size;

alloc_size = sizeof(struct iio_dev);
if (sizeof_priv) {
alloc_size = ALIGN(alloc_size, IIO_ALIGN);
alloc_size += sizeof_priv;
}
/* ensure 32-byte alignment of whole construct ? */
alloc_size += IIO_ALIGN - 1;

indio_dev = devm_kzalloc(dev, alloc_size, GFP_KERNEL);
if (indio_dev) {
indio_dev-dev.groups = indio_dev-groups;
indio_dev-dev.type = iio_device_type;
indio_dev-dev.bus = iio_bus_type;
device_initialize(indio_dev-dev);
dev_set_drvdata(indio_dev-dev, (void *)indio_dev);
mutex_init(indio_dev-mlock);
mutex_init(indio_dev-info_exist_lock);
INIT_LIST_HEAD(indio_dev-channel_attr_list);

indio_dev-id = ida_simple_get(iio_ida, 0, 0, GFP_KERNEL);
if (indio_dev-id  0) {
/* cannot use a dev_err as the name isn't available */
printk(KERN_ERR Failed to get id\n);
kfree(dev);
return NULL;
}
dev_set_name(indio_dev-dev, iio:device%d, indio_dev-id);
INIT_LIST_HEAD(indio_dev-buffer_list);
}

return indio_dev;
}
EXPORT_SYMBOL(devm_iio_device_alloc);

Regards,
OK
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-16 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..434842c 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   gpadc: twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-16 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1008 +++
 3 files changed, 1023 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..3172461 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -150,6 +150,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..996ba09 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -16,4 +16,5 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..658f35b
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1008 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define TWL6030_GPADC_CTRL_P1_SP1  BIT(3)
+
+#define TWL6030_GPADC_GPCH0_LSB(0x29)
+
+#define TWL6030_GPADC_RT_SW1_EOC_MASK

[PATCH v4 0/2] TWL6030, TWL6032 GPADC driver

2013-07-16 Thread Oleksandr Kozaruk
Hello,

v4 - addressed comments: fixed style violation, bug in freeing memory,
 added comments explaining calibration method, removed test network
 channels from exposing to userspace, error handling for 
 wait_for_complition
v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |6 +
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1008 +++
 4 files changed, 1029 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-16 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..434842c 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   gpadc: twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-16 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1008 +++
 3 files changed, 1023 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..3172461 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -150,6 +150,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..996ba09 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -16,4 +16,5 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..658f35b
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1008 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define TWL6030_GPADC_CTRL_P1_SP1  BIT(3)
+
+#define TWL6030_GPADC_GPCH0_LSB(0x29)
+
+#define TWL6030_GPADC_RT_SW1_EOC_MASK

[PATCH v4 0/2] TWL6030, TWL6032 GPADC driver

2013-07-16 Thread Oleksandr Kozaruk
Hello,

v4 - addressed comments: fixed style violation, bug in freeing memory,
 added comments explaining calibration method, removed test network
 channels from exposing to userspace, error handling for 
 wait_for_complition
v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |6 +
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1008 +++
 4 files changed, 1029 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-16 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..434842c 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   gpadc: twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-16 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030, and TWL6032 PMIC,
known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19 channels
respectively. Some channels have current source and are used for
measuring voltage drop on resistive load for detecting battery ID
resistance, or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage, (i.e. battery
voltage), and have voltage dividers, thus, capable to scale voltage.
Some channels are dedicated for measuring die temperature.

Some channels are calibrated in 2 points, having offsets from ideal
values kept in trim registers. This is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i.e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |   14 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1008 +++
 3 files changed, 1023 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..3172461 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -150,6 +150,20 @@ config TI_AM335X_ADC
  Say yes here to build support for Texas Instruments ADC
  driver which is also a MFD client.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Converter) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030/TWL6032 General
+ Purpose A/D Converter. This will add support for battery type
+ detection, battery voltage and temperature measurement, die
+ temperature measurement, system supply voltage, audio accessory,
+ USB ID detection.
+
+ This driver can also be built as a module. If so, the module will be
+ called twl6030-gpadc.
+
 config VIPERBOARD_ADC
tristate Viperboard ADC support
depends on MFD_VIPERBOARD  USB
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..996ba09 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -16,4 +16,5 @@ obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..658f35b
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1008 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define TWL6030_GPADC_CTRL_P1_SP1  BIT(3)
+
+#define TWL6030_GPADC_GPCH0_LSB(0x29)
+
+#define TWL6030_GPADC_RT_SW1_EOC_MASK

[PATCH v3 0/2] TWL6030, TWL6032 GPADC driver

2013-07-12 Thread Oleksandr Kozaruk
Hello,

v3 - fixed compiler warning
v2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver exports function returning converted value for
requested channels.

Sysfs entries are added to start and read conversion result
in millivolts for chosen channel.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |6 +
 drivers/iio/adc/Kconfig |8 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1019 +++
 4 files changed, 1034 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-12 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi |6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..434842c 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   gpadc: twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-12 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030,
and TWL6032 PMIC, known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage,
(i.e. battery voltage), and have voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels are calibrated in 2 points, having
offsets from ideal values kept in trim registers. This
is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver exports function returning converted value for
requested channels.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |8 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1019 +++
 3 files changed, 1028 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..87d699e 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -157,4 +157,12 @@ config VIPERBOARD_ADC
  Say yes here to access the ADC part of the Nano River
  Technologies Viperboard.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Convertor) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030 General Purpose
+ A/D Convertor.
+
 endmenu
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..8b05633 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -17,3 +17,4 @@ obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..6ceb789
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1019 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+/* Define this as the biggest of all chips using this driver */
+#define GPADC_MAX_CHANNELS TWL6032_GPADC_MAX_CHANNELS
+
+#define TWL6030_GPADC_CTRL 0x00/* 0x2e */
+#define TWL6030_GPADC_CTRL20x01/* 0x2f */
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+#define TWL6030_GPADC_CTRL_P2  0x06
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_RTCH0_LSB0x09
+#define TWL6032_GPADC_RTCH0_MSB0x0a
+#define TWL6032_GPADC_RTCH1_LSB0x0b
+#define TWL6032_GPADC_RTCH1_MSB0x0c
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define

[PATCH v2 0/2] TWL6030, TWL6032 GPADC driver

2013-07-10 Thread Oleksandr Kozaruk
Hello,

This is version 2 - the driver put in drivers/iio, and
converted using iio facilities as suggested by Graeme.

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030/TWL6032 is a PMIC that has a GPADC with 17/19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements, other channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver exports function returning converted value for
requested channels.

Sysfs entries are added to start and read conversion result
in millivolts for chosen channel.

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- iio framework is used

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 arch/arm/boot/dts/twl6030.dtsi  |6 +
 drivers/iio/adc/Kconfig |8 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1019 +++
 4 files changed, 1034 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-07-10 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi |6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..434842c 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,10 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   gpadc: twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   #io-channel-cells = 1;
+   };
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/2] iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-07-10 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030,
and TWL6032 PMIC, known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage,
(i.e. battery voltage), and have voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels are calibrated in 2 points, having
offsets from ideal values kept in trim registers. This
is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver exports function returning converted value for
requested channels.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 drivers/iio/adc/Kconfig |8 +
 drivers/iio/adc/Makefile|1 +
 drivers/iio/adc/twl6030-gpadc.c | 1019 +++
 3 files changed, 1028 insertions(+)
 create mode 100644 drivers/iio/adc/twl6030-gpadc.c

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index ab0767e6..87d699e 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -157,4 +157,12 @@ config VIPERBOARD_ADC
  Say yes here to access the ADC part of the Nano River
  Technologies Viperboard.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Convertor) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030 General Purpose
+ A/D Convertor.
+
 endmenu
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index 0a825be..8b05633 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -17,3 +17,4 @@ obj-$(CONFIG_MAX1363) += max1363.o
 obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
 obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
 obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
+obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
new file mode 100644
index 000..d9529a9
--- /dev/null
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -0,0 +1,1019 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/of_platform.h
+#include linux/i2c/twl.h
+#include linux/iio/iio.h
+#include linux/iio/sysfs.h
+
+#define DRIVER_NAMEtwl6030_gpadc
+
+#define TWL6030_GPADC_MAX_CHANNELS 17
+#define TWL6032_GPADC_MAX_CHANNELS 19
+/* Define this as the biggest of all chips using this driver */
+#define GPADC_MAX_CHANNELS TWL6032_GPADC_MAX_CHANNELS
+
+#define TWL6030_GPADC_CTRL 0x00/* 0x2e */
+#define TWL6030_GPADC_CTRL20x01/* 0x2f */
+
+#define TWL6030_GPADC_CTRL_P1  0x05
+#define TWL6030_GPADC_CTRL_P2  0x06
+
+#define TWL6032_GPADC_GPSELECT_ISB 0x07
+#define TWL6032_GPADC_CTRL_P1  0x08
+
+#define TWL6032_GPADC_RTCH0_LSB0x09
+#define TWL6032_GPADC_RTCH0_MSB0x0a
+#define TWL6032_GPADC_RTCH1_LSB0x0b
+#define TWL6032_GPADC_RTCH1_MSB0x0c
+#define TWL6032_GPADC_GPCH0_LSB0x0d
+#define TWL6032_GPADC_GPCH0_MSB0x0e
+
+#define

[PATCH v1 0/2] TWL6030, TWL6032 GPADC driver

2013-06-27 Thread Oleksandr Kozaruk
Hello

TWL603[02] GPADC is used to measure battery voltage,
battery temperature, battery presence ID, and could
be used to measure twl603[02] die temperature.
This is used on TI blaze, blaze tablet platforms.

The TWL6030 and TWL6032 have GPADC with 17 and 19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage,
(i.e. battery voltage), and have inbuilt voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels could be calibrated in 2 points, having
offsets from ideal values in trim registers.

The difference between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver exports function returning converted value for
requested channels: raw code, corrected code, and converted
to mV result.

Sysfs entries are added to start and read conversion result
in millivolts for channel if it has calibration data, or
ADC code(for temperature and test network channels).

The driver is derived from git://git.omapzoom.org/kernel/omap.git
The original driver's authors and contributors are Balaji T K,
Graeme Gregory, Ambresh K, Girish S Ghongdemath.

The changes to the original driver:
- device tree adaptation;
- drop ioctl support - never been used;
- unified measurement method for both devices;
- get rid of if (device == X) code style to data driven;
- drop polling end of conversion and use interrupt instead;
- simplified (hopefully) exported external function interface to the driver.

Tested with on blaze tablet 2 with OMAP4430(twl6030), and
OMAP4470(twl6032) SOMs.

The patches were tested against 3.10-rc7

Oleksandr Kozaruk (2):
  ARM: dts: twl: Add GPADC data to device tree
  mfd: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

 .../testing/sysfs-devices-platform-twl6030_gpadc   |5 +
 arch/arm/boot/dts/twl6030.dtsi |5 +
 drivers/mfd/Kconfig|8 +
 drivers/mfd/Makefile   |1 +
 drivers/mfd/twl6030-gpadc.c| 1053 
 include/linux/i2c/twl6030-gpadc.h  |   51 +
 6 files changed, 1123 insertions(+)
 create mode 100644 
Documentation/ABI/testing/sysfs-devices-platform-twl6030_gpadc
 create mode 100644 drivers/mfd/twl6030-gpadc.c
 create mode 100644 include/linux/i2c/twl6030-gpadc.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 2/2] mfd: twl6030-gpadc: TWL6030, TWL6032 GPADC driver

2013-06-27 Thread Oleksandr Kozaruk
The GPADC is general purpose ADC found on TWL6030,
and TWL6032 PMIC, known also as Phoenix and PhoenixLite.

The TWL6030 and TWL6032 have GPADC with 17 and 19
channels respectively. Some channels have current
source and are used for measuring voltage drop
on resistive load for detecting battery ID resistance,
or measuring voltage drop on NTC resistors for external
temperature measurements. Some channels measure voltage,
(i.e. battery voltage), and have voltage dividers,
thus, capable to scale voltage. Some channels are dedicated
for measuring die temperature.

Some channels are calibrated in 2 points, having
offsets from ideal values kept in trim registers. This
is used to correct measurements.

The differences between GPADC in TWL6030 and TWL6032:
- 10 bit vs 12 bit ADC;
- 17 vs 19 channels;
- channels have different purpose(i. e. battery voltage
  channel 8 vs channel 18);
- trim values are interpreted differently.

The driver exports function returning converted value for
requested channels.

Based on the driver patched from Balaji TK, Graeme Gregory, Ambresh K,
Girish S Ghongdemath.

Signed-off-by: Balaji T K balaj...@ti.com
Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 .../testing/sysfs-devices-platform-twl6030_gpadc   |5 +
 drivers/mfd/Kconfig|8 +
 drivers/mfd/Makefile   |1 +
 drivers/mfd/twl6030-gpadc.c| 1053 
 include/linux/i2c/twl6030-gpadc.h  |   51 +
 5 files changed, 1118 insertions(+)
 create mode 100644 
Documentation/ABI/testing/sysfs-devices-platform-twl6030_gpadc
 create mode 100644 drivers/mfd/twl6030-gpadc.c
 create mode 100644 include/linux/i2c/twl6030-gpadc.h

diff --git a/Documentation/ABI/testing/sysfs-devices-platform-twl6030_gpadc 
b/Documentation/ABI/testing/sysfs-devices-platform-twl6030_gpadc
new file mode 100644
index 000..e9c5812
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-platform-twl6030_gpadc
@@ -0,0 +1,5 @@
+What:  /sys/bus/platform/devices/twl603X_gpadc.26/inX_channel
+Date:  June 2013
+Contact:   Oleksandr Kozaruk oleksandr.koza...@ti.com
+Description:   Start GPADC conversion for chosen channel X and report the 
result.
+   The result is returned in millivolts.
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index d54e985..8eb7494 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -970,6 +970,14 @@ config MFD_TC3589X
  additional drivers must be enabled in order to use the
  functionality of the device.
 
+config TWL6030_GPADC
+   tristate TWL6030 GPADC (General Purpose A/D Convertor) Support
+   depends on TWL4030_CORE
+   default n
+   help
+ Say yes here if you want support for the TWL6030 General Purpose
+ A/D Convertor.
+
 config MFD_TMIO
bool
default n
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 718e94a..59f504f 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_MENELAUS)+= menelaus.o
 obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o
 obj-$(CONFIG_TWL4030_MADC)  += twl4030-madc.o
 obj-$(CONFIG_TWL4030_POWER)+= twl4030-power.o
+obj-$(CONFIG_TWL6030_GPADC)+= twl6030-gpadc.o
 obj-$(CONFIG_MFD_TWL4030_AUDIO)+= twl4030-audio.o
 obj-$(CONFIG_TWL6040_CORE) += twl6040.o
 
diff --git a/drivers/mfd/twl6030-gpadc.c b/drivers/mfd/twl6030-gpadc.c
new file mode 100644
index 000..1868bc0
--- /dev/null
+++ b/drivers/mfd/twl6030-gpadc.c
@@ -0,0 +1,1053 @@
+/*
+ * TWL6030 GPADC module driver
+ *
+ * Copyright (C) 2009-2013 Texas Instruments Inc.
+ * Nishant Kamat nska...@ti.com
+ * Balaji T K balaj...@ti.com
+ * Graeme Gregory g...@slimlogic.co.uk
+ * Girish S Ghongdemath giris...@ti.com
+ * Ambresh K ambr...@ti.com
+ * Oleksandr Kozaruk oleksandr.koza...@ti.com
+ *
+ * Based on twl4030-madc.c
+ * Copyright (C) 2008 Nokia Corporation
+ * Mikko Ylinen mikko.k.yli...@nokia.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/types.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/slab.h
+#include linux/hwmon

[PATCH v1 1/2] ARM: dts: twl: Add GPADC data to device tree

2013-06-27 Thread Oleksandr Kozaruk
GPADC is the general purpose ADC present on twl6030.
The dt data is interrupt used to trigger end of ADC
conversion.

Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---
 arch/arm/boot/dts/twl6030.dtsi |5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/boot/dts/twl6030.dtsi b/arch/arm/boot/dts/twl6030.dtsi
index 2e3bd31..189872c 100644
--- a/arch/arm/boot/dts/twl6030.dtsi
+++ b/arch/arm/boot/dts/twl6030.dtsi
@@ -103,4 +103,9 @@
compatible = ti,twl6030-pwmled;
#pwm-cells = 2;
};
+
+   twl6030_gpadc {
+   compatible = ti,twl6030_gpadc;
+   interrupts = 3;
+   };
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] MFD: Change TWL6025 references to TWL6032

2013-06-19 Thread Oleksandr Kozaruk
From: Graeme Gregory g...@slimlogic.co.uk

The TWL6025 was never released beyond sample form and was replaced by
the PhoenixLite range of chips - TWL6032. Change the references to
reference the TWL6032 class and name the registers to twl6032 in line with
an actual released chip name to avoid confusion.

Currently there are no users of TWL6025 in the code.

Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
Acked-by: Lee Jones lee.jo...@linaro.org

---

There are non-mainline branches that use twl6032 by its name (for example
git://git.omapzoom.org/kernel/omap.git). There is intention to add support
of twl6032 device in mainline, but we'd like to know if we can use twl6032
instead of twl6025 in our new patches, that we are going to provide.
Related discussion: https://patchwork.kernel.org/patch/2686331/

 .../bindings/regulator/twl-regulator.txt   |   26 +++
 .../devicetree/bindings/usb/twl-usb.txt|2 +-
 drivers/mfd/twl-core.c |   46 ++--
 drivers/regulator/twl-regulator.c  |   76 ++--
 drivers/usb/phy/phy-twl6030-usb.c  |2 +-
 include/linux/i2c/twl.h|   30 
 6 files changed, 91 insertions(+), 91 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/twl-regulator.txt 
b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
index 658749b..75b0c16 100644
--- a/Documentation/devicetree/bindings/regulator/twl-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/twl-regulator.txt
@@ -18,20 +18,20 @@ For twl6030 regulators/LDOs
   - ti,twl6030-vdd1 for VDD1 SMPS
   - ti,twl6030-vdd2 for VDD2 SMPS
   - ti,twl6030-vdd3 for VDD3 SMPS
-For twl6025 regulators/LDOs
+For twl6032 regulators/LDOs
 - compatible:
-  - ti,twl6025-ldo1 for LDO1 LDO
-  - ti,twl6025-ldo2 for LDO2 LDO
-  - ti,twl6025-ldo3 for LDO3 LDO
-  - ti,twl6025-ldo4 for LDO4 LDO
-  - ti,twl6025-ldo5 for LDO5 LDO
-  - ti,twl6025-ldo6 for LDO6 LDO
-  - ti,twl6025-ldo7 for LDO7 LDO
-  - ti,twl6025-ldoln for LDOLN LDO
-  - ti,twl6025-ldousb for LDOUSB LDO
-  - ti,twl6025-smps3 for SMPS3 SMPS
-  - ti,twl6025-smps4 for SMPS4 SMPS
-  - ti,twl6025-vio for VIO SMPS
+  - ti,twl6032-ldo1 for LDO1 LDO
+  - ti,twl6032-ldo2 for LDO2 LDO
+  - ti,twl6032-ldo3 for LDO3 LDO
+  - ti,twl6032-ldo4 for LDO4 LDO
+  - ti,twl6032-ldo5 for LDO5 LDO
+  - ti,twl6032-ldo6 for LDO6 LDO
+  - ti,twl6032-ldo7 for LDO7 LDO
+  - ti,twl6032-ldoln for LDOLN LDO
+  - ti,twl6032-ldousb for LDOUSB LDO
+  - ti,twl6032-smps3 for SMPS3 SMPS
+  - ti,twl6032-smps4 for SMPS4 SMPS
+  - ti,twl6032-vio for VIO SMPS
 For twl4030 regulators/LDOs
 - compatible:
   - ti,twl4030-vaux1 for VAUX1 LDO
diff --git a/Documentation/devicetree/bindings/usb/twl-usb.txt 
b/Documentation/devicetree/bindings/usb/twl-usb.txt
index 36b9aed..0aee0ad 100644
--- a/Documentation/devicetree/bindings/usb/twl-usb.txt
+++ b/Documentation/devicetree/bindings/usb/twl-usb.txt
@@ -8,7 +8,7 @@ TWL6030 USB COMPARATOR
usb interrupt number that raises VBUS interrupts when the controller has to
act as device
  - usb-supply : phandle to the regulator device tree node. It should be vusb
-   if it is twl6030 or ldousb if it is twl6025 subclass.
+   if it is twl6030 or ldousb if it is twl6032 subclass.
 
 twl6030-usb {
compatible = ti,twl6030-usb;
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 89ab4d9..f39bceb 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -118,7 +118,7 @@
 #define TWL6030_BASEADD_GASGAUGE   0x00C0
 #define TWL6030_BASEADD_PIH0x00D0
 #define TWL6030_BASEADD_CHARGER0x00E0
-#define TWL6025_BASEADD_CHARGER0x00DA
+#define TWL6032_BASEADD_CHARGER0x00DA
 #define TWL6030_BASEADD_LED0x00F4
 
 /* subchip/slave 2 0x4A - DFT */
@@ -718,9 +718,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned 
irq_base,
| REGULATOR_CHANGE_STATUS,
};
 
-   if (features  TWL6025_SUBCLASS) {
+   if (features  TWL6032_SUBCLASS) {
usb3v3.supply = ldousb;
-   regulator = TWL6025_REG_LDOUSB;
+   regulator = TWL6032_REG_LDOUSB;
} else {
usb3v3.supply = vusb;
regulator = TWL6030_REG_VUSB;
@@ -747,8 +747,8 @@ add_children(struct twl4030_platform_data *pdata, unsigned 
irq_base,
usb3v3.dev_name = dev_name(child);
} else if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) 
   twl_class_is_6030()) {
-   if (features  TWL6025_SUBCLASS)
-   child = add_regulator(TWL6025_REG_LDOUSB,
+   if (features

Re: [RFC v1] MFD: Change TWL6025 references to TWL6032

2013-06-13 Thread Oleksandr Kozaruk

On 06/07/2013 05:44 PM, g...@slimlogic.co.uk wrote:

On 2013-06-07 15:36, Mark Brown wrote:

On Fri, Jun 07, 2013 at 01:53:10PM +0300, Oleksandr Kozaruk wrote:

From: Graeme Gregory g...@slimlogic.co.uk

The TWL6025 was never released beyond sample form and was replaced by
the PhoenixLite range of chips - TWL6032. Change the references to
reference the TWL6032 class and name the registers to twl6032 in 
line with

an actual released chip name to avoid confusion.

Currently there is no users of TWL6025 in the code.


Given that the chip exists even if not widely distributed it seems as
well to keep the twl6025 references in there at least in the device ID
table - it won't do any harm to people using the twl6032 name and might
help someone who happens to pick up an old board for whatever reason.


I do not think any old boards exist, it really was a limited run!

Graeme


Hello Mark, Graeme

So, what is your opinion? Could we move forward with this?

In addition, If twl6032 will be added on top of twl6025 there will be no 
guarantee

that twl6025 will work because:
- there is no HW to verify
- there is no documentation on twl6025 available, so, in case if current 
implementation is

  different from what is needed for twl6032 - it can't be handled properly
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v1] MFD: Change TWL6025 references to TWL6032

2013-06-13 Thread Oleksandr Kozaruk

On 06/07/2013 05:44 PM, g...@slimlogic.co.uk wrote:

On 2013-06-07 15:36, Mark Brown wrote:

On Fri, Jun 07, 2013 at 01:53:10PM +0300, Oleksandr Kozaruk wrote:

From: Graeme Gregory g...@slimlogic.co.uk

The TWL6025 was never released beyond sample form and was replaced by
the PhoenixLite range of chips - TWL6032. Change the references to
reference the TWL6032 class and name the registers to twl6032 in 
line with

an actual released chip name to avoid confusion.

Currently there is no users of TWL6025 in the code.


Given that the chip exists even if not widely distributed it seems as
well to keep the twl6025 references in there at least in the device ID
table - it won't do any harm to people using the twl6032 name and might
help someone who happens to pick up an old board for whatever reason.


I do not think any old boards exist, it really was a limited run!

Graeme


Hello Mark, Graeme,

Taking in account that:
- there is no hardware to test twl6025, testing is not possible;
- there is no documentation for twl6025, and if there are any changes to 
twl6032 is not known;
- twl6032 is available, and in production, twl6025 is not even found on 
ti.com http://ti.com


So, what do you think, can this change be accepted?

// I apologize for sending personal e-mails, not to the mail list
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v1] MFD: Change TWL6025 references to TWL6032

2013-06-13 Thread Oleksandr Kozaruk

On 06/07/2013 05:44 PM, g...@slimlogic.co.uk wrote:

On 2013-06-07 15:36, Mark Brown wrote:

On Fri, Jun 07, 2013 at 01:53:10PM +0300, Oleksandr Kozaruk wrote:

From: Graeme Gregory g...@slimlogic.co.uk

The TWL6025 was never released beyond sample form and was replaced by
the PhoenixLite range of chips - TWL6032. Change the references to
reference the TWL6032 class and name the registers to twl6032 in 
line with

an actual released chip name to avoid confusion.

Currently there is no users of TWL6025 in the code.


Given that the chip exists even if not widely distributed it seems as
well to keep the twl6025 references in there at least in the device ID
table - it won't do any harm to people using the twl6032 name and might
help someone who happens to pick up an old board for whatever reason.


I do not think any old boards exist, it really was a limited run!

Graeme


Hello Mark, Graeme,

Taking in account that:
- there is no hardware to test twl6025, testing is not possible;
- there is no documentation for twl6025, and if there are any changes to 
twl6032 is not known;
- twl6032 is available, and in production, twl6025 is not even found on 
ti.com 
https://emea.mail.ti.com/owa/redir.aspx?C=Lmz99OgekUScv9U89hUFHXTz_mebO9AIdxDOPBzqDKKuqB_Dr5dpU_Sl2criZoxOeMxW4IqmDOA.URL=http%3a%2f%2fti.com


So, what do you think, can this change be accepted?

// I apologize for sending previous email as personal, not to mail list.
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v1] MFD: Change TWL6025 references to TWL6032

2013-06-13 Thread Oleksandr Kozaruk

On 06/13/2013 11:17 AM, Oleksandr Kozaruk wrote:
On Fri, Jun 7, 2013 at 5:44 PM, g...@slimlogic.co.uk 
mailto:g...@slimlogic.co.uk wrote:


 On 2013-06-07 15:36, Mark Brown wrote:

 On Fri, Jun 07, 2013 at 01:53:10PM +0300, Oleksandr Kozaruk wrote:

 From: Graeme Gregory g...@slimlogic.co.uk mailto:g...@slimlogic.co.uk

 The TWL6025 was never released beyond sample form and was replaced by
 the PhoenixLite range of chips - TWL6032. Change the references to
 reference the TWL6032 class and name the registers to twl6032 in 
line with

 an actual released chip name to avoid confusion.

 Currently there is no users of TWL6025 in the code.


 Given that the chip exists even if not widely distributed it seems as
 well to keep the twl6025 references in there at least in the device ID
 table - it won't do any harm to people using the twl6032 name and might
 help someone who happens to pick up an old board for whatever reason.


 I do not think any old boards exist, it really was a limited run!

 Graeme

Hello Mark, Graeme,

Taking in account that:
- there is no hardware to test twl6025, testing is not possible;
- there is no documentation for twl6025, and if there are any changes 
to twl6032 is not known;
- twl6032 is available, and in production, twl6025 is not even found 
on ti.com http://ti.com


So, what do you think, can this change be accepted?
http://www.globallogic.com/email_disclaimer.txt

Sorry for spamming - had problems with mail server.
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v1] MFD: Change TWL6025 references to TWL6032

2013-06-07 Thread Oleksandr Kozaruk
From: Graeme Gregory g...@slimlogic.co.uk

The TWL6025 was never released beyond sample form and was replaced by
the PhoenixLite range of chips - TWL6032. Change the references to
reference the TWL6032 class and name the registers to twl6032 in line with
an actual released chip name to avoid confusion.

Currently there is no users of TWL6025 in the code. 

Signed-off-by: Graeme Gregory g...@slimlogic.co.uk
Signed-off-by: Oleksandr Kozaruk oleksandr.koza...@ti.com
---

There are non-mainline branches that use twl6032 by its name (for example
git://git.omapzoom.org/kernel/omap.git). There is intention to add support
of twl6032 device in mainline, but we'd like to know if we can use twl6032
instead of twl6025 in our new patches, that we are going to provide.

 drivers/mfd/twl-core.c|   46 +++---
 drivers/regulator/twl-regulator.c |   76 ++---
 drivers/usb/phy/phy-twl6030-usb.c |2 +-
 include/linux/i2c/twl.h   |   30 +++
 4 files changed, 77 insertions(+), 77 deletions(-)

diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 89ab4d9..f39bceb 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -118,7 +118,7 @@
 #define TWL6030_BASEADD_GASGAUGE   0x00C0
 #define TWL6030_BASEADD_PIH0x00D0
 #define TWL6030_BASEADD_CHARGER0x00E0
-#define TWL6025_BASEADD_CHARGER0x00DA
+#define TWL6032_BASEADD_CHARGER0x00DA
 #define TWL6030_BASEADD_LED0x00F4
 
 /* subchip/slave 2 0x4A - DFT */
@@ -718,9 +718,9 @@ add_children(struct twl4030_platform_data *pdata, unsigned 
irq_base,
| REGULATOR_CHANGE_STATUS,
};
 
-   if (features  TWL6025_SUBCLASS) {
+   if (features  TWL6032_SUBCLASS) {
usb3v3.supply = ldousb;
-   regulator = TWL6025_REG_LDOUSB;
+   regulator = TWL6032_REG_LDOUSB;
} else {
usb3v3.supply = vusb;
regulator = TWL6030_REG_VUSB;
@@ -747,8 +747,8 @@ add_children(struct twl4030_platform_data *pdata, unsigned 
irq_base,
usb3v3.dev_name = dev_name(child);
} else if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) 
   twl_class_is_6030()) {
-   if (features  TWL6025_SUBCLASS)
-   child = add_regulator(TWL6025_REG_LDOUSB,
+   if (features  TWL6032_SUBCLASS)
+   child = add_regulator(TWL6032_REG_LDOUSB,
pdata-ldousb, features);
else
child = add_regulator(TWL6030_REG_VUSB,
@@ -872,7 +872,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned 
irq_base,
 
/* twl6030 regulators */
if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)  twl_class_is_6030() 
-   !(features  TWL6025_SUBCLASS)) {
+   !(features  TWL6032_SUBCLASS)) {
child = add_regulator(TWL6030_REG_VDD1, pdata-vdd1,
features);
if (IS_ERR(child))
@@ -952,60 +952,60 @@ add_children(struct twl4030_platform_data *pdata, 
unsigned irq_base,
return PTR_ERR(child);
}
 
-   /* twl6025 regulators */
+   /* twl6032 regulators */
if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)  twl_class_is_6030() 
-   (features  TWL6025_SUBCLASS)) {
-   child = add_regulator(TWL6025_REG_LDO5, pdata-ldo5,
+   (features  TWL6032_SUBCLASS)) {
+   child = add_regulator(TWL6032_REG_LDO5, pdata-ldo5,
features);
if (IS_ERR(child))
return PTR_ERR(child);
 
-   child = add_regulator(TWL6025_REG_LDO1, pdata-ldo1,
+   child = add_regulator(TWL6032_REG_LDO1, pdata-ldo1,
features);
if (IS_ERR(child))
return PTR_ERR(child);
 
-   child = add_regulator(TWL6025_REG_LDO7, pdata-ldo7,
+   child = add_regulator(TWL6032_REG_LDO7, pdata-ldo7,
features);
if (IS_ERR(child))
return PTR_ERR(child);
 
-   child = add_regulator(TWL6025_REG_LDO6, pdata-ldo6,
+   child = add_regulator(TWL6032_REG_LDO6, pdata-ldo6,
features);
if (IS_ERR(child))
return PTR_ERR(child);
 
-   child = add_regulator(TWL6025_REG_LDOLN, pdata-ldoln,
+   child = add_regulator(TWL6032_REG_LDOLN, pdata-ldoln,
features