mfd: twl4030: Driver for twl4030 madc module
Subsystems (2)
PATCH v4 2/2 mfd: twl4030: Driver for twl4030 madc module
Introducing a driver for MADC on TWL4030 powerIC. MADC stands for monitoring ADC. This driver monitors the real time conversion of analog signals like battery temperature, battery cuurent etc.
---
V4:
Removed unwanted else from twl4030_madc_read_channels functions.
V3:
Added for_each_set_bit for efficient bit checking
and locking the mutex earlier in the threaded irq
handler.
V2:
Added functions to convert raw voltages to current and temperature.
V1:
http://www.mail-archive.com/[email protected]/msg44543.html
drivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/twl4030-madc.c | 812 ++++++++++++++++++++++++++++++++++++++ include/linux/i2c/twl4030-madc.h | 142 +++++++ 4 files changed, 965 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/twl4030-madc.c create mode 100644 include/linux/i2c/twl4030-madc.h
drivers/mfd/Kconfig +10 -0
@@ -167,6 +167,16 @@ config TWL4030_CORE high speed USB OTG transceiver, an audio codec (on most versions) and many other features. +config TWL4030_MADC + tristate "Texas Instruments TWL4030 MADC" + depends on TWL4030_CORE + help + This driver provides support for triton TWL4030-MADC. The + driver supports both RT and SW conversion methods. + + This driver can be built as a module. If so it will be + named twl4030-madc + config TWL4030_POWER bool "Support power resources on TWL4030 family chips" depends on TWL4030_CORE && ARM
drivers/mfd/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_TPS6507X) += tps6507x.o 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_TWL4030_CODEC) += twl4030-codec.o obj-$(CONFIG_TWL6030_PWM) += twl6030-pwm.o
drivers/mfd/twl4030-madc.c new file +812 -0
812 lines not on this page · raw message
include/linux/i2c/twl4030-madc.h new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Quoted 10 lines · Keerthy
drivers/mfd/twl4030-madc.c new file +10
-0+static int twl4030_madc_read_channels (struct twl4030_madc_data *madc, + u8 reg_base, unsigned + long channels, int *buf) +{ + int count = 0, count_req = 0, i; + u8 reg; + + for_each_set_bit(i, &channels, TWL4030_MADC_MAX_CHANNELS) { + reg = reg_base + 2 * i; + buf[i] = twl4030_madc_channel_raw_read(madc, reg);
drivers/mfd/twl4030-madc.c line 234
Quoted 10 lines
drivers/mfd/twl4030-madc.c new file +10
-0+ if (buf[i] < 0) { + dev_err(madc->dev, + "Unable to read register 0x%X\n", reg); + count_req++; + continue; + } + switch (i) { + case 10: + buf[i] = + twl4030battery_current(buf[i]);
Possibly fix these breaks in statements where applicable.
Quoted 45 lines
+ if (buf[i] < 0) {
+ dev_err(madc->dev,
+ "error reading current");
+ count_req++;
+ } else {
+ count++;
+ buf[i] = buf[i] - 750;
+ }
+ break;
+ case 1:
+ buf[i] =
+twl4030battery_temperature(buf[i]);
+ if (buf[i] < 0) {
+ dev_err(madc->dev,
+ "error reading temperature");
+ count_req++;
+ } else {
+ count++;
+ }
+ break;
+ default:
+ count++;
+ /* Analog Input (V) =conv_result*
+ * step_size / R
+ *conv_result= decimal value
+ * of 10-bit conversion
+ * result
+ * step size = 1.5 / (2 ^ 10 -1)
+ * R = Prescaler ratio for input
+ * channels
+ * Result given in mV hence multiplied
+ * by 1000
+ */
+ buf[i] = (buf[i] * 3 * 1000 *
+ twl4030_divider_ratios[i].denominator)
+ / (2 * 1023 *
+ twl4030_divider_ratios[i].numerator);
+ }
+ }
+ if (count_req)
+dev_dbg(madc->dev, "%d channel conversion failed\n", count_req);drivers/mfd/twl4030-madc.c new file +4
-0+ + return count; +} +
Quoted 96 lines · Keerthy
Introducing a driver for MADC on TWL4030 powerIC. MADC stands for monitoring ADC. This driver monitors the real time conversion of analog signals like battery temperature, battery cuurent etc.
Signed-off-by Keerthy <[email protected]>---
V4:
Removed unwanted else fromtwl4030_madc_read_channelsfunctions.V3:
Addedfor_each_set_bitfor efficient bit checking
and locking the mutex earlier in the threaded irq
handler.V2:
Added functions to convert raw voltages to current and temperature.V1:
http://www.mail-archive.com/[email protected]/msg44543.htmldrivers/mfd/Kconfig | 10 + drivers/mfd/Makefile | 1 + drivers/mfd/twl4030-madc.c | 812 ++++++++++++++++++++++++++++++++++++++ include/linux/i2c/twl4030-madc.h | 142 +++++++ 4 files changed, 965 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/twl4030-madc.c create mode 100644 include/linux/i2c/twl4030-madc.hdrivers/mfd/Kconfig +10
-0@@ -167,6 +167,16 @@ config TWL4030_CORE high speed USB OTG transceiver, an audio codec (on most versions) and many other features. +config TWL4030_MADC + tristate "Texas Instruments TWL4030 MADC" + depends on TWL4030_CORE + help + This driver provides support for triton TWL4030-MADC. The + driver supports both RT and SW conversion methods. + + This driver can be built as a module. If so it will be + named twl4030-madc + config TWL4030_POWER bool "Support power resources on TWL4030 family chips" depends on TWL4030_CORE && ARMdrivers/mfd/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_TPS6507X) += tps6507x.o 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_TWL4030_CODEC) += twl4030-codec.o obj-$(CONFIG_TWL6030_PWM) += twl6030-pwm.odrivers/mfd/twl4030-madc.c new file +28
-0@@ -0,0 +1,812 @@ +/* +* +* TWL4030 MADC module driver-This driver monitors the real time +* conversion of analog signals like battery temperature, +* battery type, battery level etc. +* +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ +* J Keerthy <[email protected]> +* +* Based on twl4030-madc.c +* Copyright (C) 2008 Nokia Corporation +* Mikko Ylinen <[email protected]> +* +* Amit Kucheria <[email protected]> +* +* 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
drivers/mfd/twl4030-madc.c line 38
Quoted 10 lines
drivers/mfd/twl4030-madc.c new file +10
-0+* +*/ + +#include <linux/interrupt.h> +#include <linux/delay.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/i2c/twl.h> +#include <linux/i2c/twl4030-madc.h> +
I didn't have a close look, but I suspect that several includes are missing here. See Documentation/SubmitChecklist, item #1.
Quoted 26 lines
drivers/mfd/twl4030-madc.c new file +26
-0+/* +* struct twl4030_madc_data - a container for madc info +* @dev - pointer to device structure for madc +* @lock - mutex protecting this data structire +* @requests - Array of request struct corresponding to SW1, SW2 and RT +* @imr - Interrupt mask register of MADC +* @isr - Interrupt status register of MADC +*/ +struct twl4030_madc_data { +struct device *dev; +struct mutex lock;/* mutex protecting this data structire */ +struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS ]; +int imr; +int isr; +}; + +static struct twl4030_madc_data *twl4030_madc; + +struct twl4030_prescale_divider_ratios { +s16 numerator; +s16 denominator; +}; + +static const struct twl4030_prescale_divider_ratios +twl4030_divider_ratios[16 ] = { + {1 ,1 },/* CHANNEL 0 No Prescaler */
drivers/mfd/twl4030-madc.c line 74
Quoted 10 lines
drivers/mfd/twl4030-madc.c new file +10
-0+ {1, 1}, /* CHANNEL 1 No Prescaler */ + {6, 10}, /* CHANNEL 2 */ + {6, 10}, /* CHANNEL 3 */ + {6, 10}, /* CHANNEL 4 */ + {6, 10}, /* CHANNEL 5 */ + {6, 10}, /* CHANNEL 6 */ + {6, 10}, /* CHANNEL 7 */ + {3, 14}, /* CHANNEL 8 */ + {1, 3}, /* CHANNEL 9 */ + {1, 1}, /* CHANNEL 10 NA */
Something else but NA might be helpful here, to distinguish the entry form 13/14.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors