summaryrefslogtreecommitdiff
path: root/drivers/power/wmt_battery/gauge/vt1603
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/wmt_battery/gauge/vt1603')
-rwxr-xr-xdrivers/power/wmt_battery/gauge/vt1603/Makefile5
-rwxr-xr-xdrivers/power/wmt_battery/gauge/vt1603/batt_leds.c189
-rwxr-xr-xdrivers/power/wmt_battery/gauge/vt1603/batt_leds.h12
-rwxr-xr-xdrivers/power/wmt_battery/gauge/vt1603/vt1603.c513
-rwxr-xr-xdrivers/power/wmt_battery/gauge/vt1603/vt1603.h124
5 files changed, 843 insertions, 0 deletions
diff --git a/drivers/power/wmt_battery/gauge/vt1603/Makefile b/drivers/power/wmt_battery/gauge/vt1603/Makefile
new file mode 100755
index 00000000..c30df937
--- /dev/null
+++ b/drivers/power/wmt_battery/gauge/vt1603/Makefile
@@ -0,0 +1,5 @@
+
+s_wmt_batt_vt1603-objs += vt1603.o batt_leds.o
+
+obj-m += s_wmt_batt_vt1603.o
+
diff --git a/drivers/power/wmt_battery/gauge/vt1603/batt_leds.c b/drivers/power/wmt_battery/gauge/vt1603/batt_leds.c
new file mode 100755
index 00000000..108f40f9
--- /dev/null
+++ b/drivers/power/wmt_battery/gauge/vt1603/batt_leds.c
@@ -0,0 +1,189 @@
+/*
+ * batt_leds.c - WonderMedia Battery LED Driver.
+ *
+ * Copyright (C) 2013 WonderMedia Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * 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.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/leds.h>
+#include <linux/rtc.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+#include <linux/gpio.h>
+#include <mach/wmt_iomux.h>
+#include <mach/wmt_env.h>
+
+enum {
+ LED_GREEN = 0,
+ LED_RED,
+};
+
+struct batt_led_trigger {
+ char *name;
+ struct led_trigger *trigger;
+};
+
+#define RTC_NAME "rtc0"
+static struct rtc_device *rtc_dev = NULL;
+static bool battery_led_registered = false;
+
+static struct batt_led_trigger batt_led_triggers[] = {
+ [LED_GREEN] = {
+ .name = "bat-green",
+ },
+ [LED_RED] = {
+ .name = "bat-red",
+ }
+};
+
+static struct gpio_led batt_leds[] = {
+ [LED_GREEN] = {
+ .name = "bat-green",
+ .default_trigger = "bat-green",
+ .retain_state_suspended = 1,
+ .active_low = 0,
+ },
+ [LED_RED] = {
+ .name = "bat-red",
+ .default_trigger = "bat-red",
+ .retain_state_suspended = 1,
+ .active_low = 0,
+ },
+};
+
+static struct gpio_led_platform_data batt_leds_data = {
+ .leds = batt_leds,
+ .num_leds = ARRAY_SIZE(batt_leds),
+};
+
+static struct platform_device batt_leds_dev = {
+ .name = "leds-gpio",
+ .id = -1,
+ .dev = {
+ .platform_data = &batt_leds_data,
+ },
+};
+
+static int parse_battery_led_param(void)
+{
+ char env[] = "wmt.charger.led";
+ char s[64];
+ size_t l = sizeof(s);
+ int id, r, g;
+
+ if (wmt_getsyspara(env, s, &l))
+ return -EINVAL;
+
+ if (sscanf(s, "%d:%d:%d", &id, &r, &g) != 3)
+ return -EINVAL;
+
+ if (id != 1 || !gpio_is_valid(r) || !gpio_is_valid(g))
+ return -EINVAL;
+
+ batt_leds[LED_GREEN].gpio = g;
+ batt_leds[LED_RED].gpio = r;
+
+ pr_info("charger-led: charging (gpio%d), full (gpio%d)\n", r, g);
+ return 0;
+}
+
+int batt_leds_update(int status)
+{
+ struct led_trigger *r = batt_led_triggers[LED_RED].trigger;
+ struct led_trigger *g = batt_led_triggers[LED_GREEN].trigger;
+
+ if (battery_led_registered == false)
+ return 0;
+
+ switch (status) {
+ case POWER_SUPPLY_STATUS_CHARGING:
+ led_trigger_event(r, LED_FULL);
+ led_trigger_event(g, LED_OFF);
+ gpio_direction_input(batt_leds[LED_GREEN].gpio);
+ break;
+ case POWER_SUPPLY_STATUS_FULL:
+ led_trigger_event(r, LED_OFF);
+ led_trigger_event(g, LED_FULL);
+ break;
+ case POWER_SUPPLY_STATUS_DISCHARGING:
+ default:
+ led_trigger_event(r, LED_OFF);
+ led_trigger_event(g, LED_OFF);
+ gpio_direction_input(batt_leds[LED_GREEN].gpio);
+ break;
+ }
+ return 0;
+}
+
+void batt_leds_suspend_prepare(void)
+{
+ struct rtc_wkalrm tmp;
+ unsigned long time, now;
+ //unsigned long add = 30; /* seconds */
+ unsigned long add = 120; /* seconds */
+
+ if (battery_led_registered == false)
+ return;
+
+ if (!rtc_dev) {
+ rtc_dev = rtc_class_open(RTC_NAME);
+ if (IS_ERR_OR_NULL(rtc_dev)) {
+ rtc_dev = NULL;
+ pr_err("Cannot get RTC %s, %ld.\n", RTC_NAME, PTR_ERR(rtc_dev));
+ return;
+ }
+ }
+
+ tmp.enabled = 1;
+ rtc_read_time(rtc_dev, &tmp.time);
+ rtc_tm_to_time(&tmp.time, &now);
+ time = now + add;
+
+ rtc_time_to_tm(time, &tmp.time);
+ rtc_set_alarm(rtc_dev, &tmp);
+
+}
+
+void batt_leds_resume_complete(void)
+{
+ if (rtc_dev) {
+ rtc_class_close(rtc_dev);
+ rtc_dev = NULL;
+ }
+}
+
+int batt_leds_setup(void)
+{
+ int i;
+
+ if (parse_battery_led_param())
+ return -EINVAL;
+
+ platform_device_register(&batt_leds_dev);
+
+ for (i = 0; i < ARRAY_SIZE(batt_led_triggers); ++i)
+ led_trigger_register_simple(batt_led_triggers[i].name,
+ &batt_led_triggers[i].trigger);
+ battery_led_registered = true;
+ return 0;
+}
+
+void batt_leds_cleanup(void)
+{
+ int i;
+
+ if (battery_led_registered == true) {
+ platform_device_unregister(&batt_leds_dev);
+ for (i = 0; i < ARRAY_SIZE(batt_led_triggers); ++i)
+ led_trigger_unregister_simple(batt_led_triggers[i].trigger);
+ battery_led_registered = false;
+ }
+}
diff --git a/drivers/power/wmt_battery/gauge/vt1603/batt_leds.h b/drivers/power/wmt_battery/gauge/vt1603/batt_leds.h
new file mode 100755
index 00000000..dbcaa657
--- /dev/null
+++ b/drivers/power/wmt_battery/gauge/vt1603/batt_leds.h
@@ -0,0 +1,12 @@
+#ifndef _BATT_LEDS_H_
+#define _BATT_LEDS_H_
+
+extern int batt_leds_setup(void);
+extern void batt_leds_cleanup(void);
+extern void batt_leds_suspend_prepare(void);
+extern void batt_leds_resume_complete(void);
+extern int batt_leds_update(int status);
+
+#endif /* #ifndef _BATT_LEDS_H_ */
+
+
diff --git a/drivers/power/wmt_battery/gauge/vt1603/vt1603.c b/drivers/power/wmt_battery/gauge/vt1603/vt1603.c
new file mode 100755
index 00000000..e75a99e8
--- /dev/null
+++ b/drivers/power/wmt_battery/gauge/vt1603/vt1603.c
@@ -0,0 +1,513 @@
+/*
+ * vt1603.c - WonderMedia VT1603 Adc Battery Driver.
+ *
+ * Copyright (C) 2013 WonderMedia Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * 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.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/power_supply.h>
+#include <linux/platform_device.h>
+#include <linux/power/wmt_battery.h>
+#include <mach/wmt_env.h>
+
+#include "vt1603.h"
+#include "batt_leds.h"
+
+enum {
+ COMPENSATION_VOLUME = 0,
+ COMPENSATION_BRIGHTNESS,
+ COMPENSATION_WIFI,
+ COMPENSATION_VIDEO,
+ COMPENSATION_USB,
+ COMPENSATION_HDMI,
+ COMPENSATION_COUNT
+};
+
+static const char *compensation_strings[] = {
+ "volume",
+ "brightness",
+ "wifi",
+ "video",
+ "usb",
+ "hdmi"
+};
+
+struct vt1603_device_info {
+ struct vt1603 *vt1603;
+ struct device *dev;
+ struct power_supply ps_bat;
+ struct mutex mutex;
+ int compensation[COMPENSATION_COUNT];
+
+ int capacity;
+ int sleeping;
+ int debug;
+};
+
+static struct vt1603_device_info *vt1603_dev_info = NULL;
+
+static int vt1603_set_reg8(struct vt1603 *vt1603, u8 reg, u8 val)
+{
+ int ret = vt1603->reg_write(vt1603, reg, val);
+ if (ret)
+ pr_err("vt1603 battery write error, errno%d\n", ret);
+ return ret;
+}
+
+static u8 vt1603_get_reg8(struct vt1603 *vt1603, u8 reg)
+{
+ u8 val = 0;
+ int ret = 0;
+
+ ret = vt1603->reg_read(vt1603, reg, &val);
+ if (ret < 0){
+ pr_err("vt1603 battery read error, errno%d\n", ret);
+ return 0;
+ }
+
+ return val;
+}
+
+static int vt1603_read8(struct vt1603 *vt1603, u8 reg, u8 *data)
+{
+ int ret = vt1603->reg_read(vt1603, reg, data);
+ if (ret)
+ pr_err("vt1603 battery read error, errno%d\n", ret);
+ return ret;
+}
+
+static void vt1603_setbits(struct vt1603 *vt1603, u8 reg, u8 mask)
+{
+ u8 tmp = vt1603_get_reg8(vt1603, reg) | mask;
+ vt1603_set_reg8(vt1603, reg, tmp);
+}
+
+static void vt1603_clrbits(struct vt1603 *vt1603, u8 reg, u8 mask)
+{
+ u8 tmp = vt1603_get_reg8(vt1603, reg) & (~mask);
+ vt1603_set_reg8(vt1603, reg, tmp);
+}
+
+#define ADC_DATA(low, high) ((((high) & 0x0F) << 8) + (low))
+
+static int vt1603_get_bat_data(struct vt1603 *vt1603,int *data)
+{
+ int ret = 0;
+ u8 data_l, data_h;
+
+ ret |= vt1603_read8(vt1603, VT1603_DATL_REG, &data_l);
+ ret |= vt1603_read8(vt1603, VT1603_DATH_REG, &data_h);
+
+ *data = ADC_DATA(data_l, data_h);
+ return ret;
+}
+
+static void vt1603_switch_to_bat_mode(struct vt1603 *vt1603)
+{
+ vt1603_set_reg8(vt1603, VT1603_CR_REG, 0x00);
+ vt1603_set_reg8(vt1603, 0xc6, 0x00);
+ vt1603_set_reg8(vt1603, VT1603_AMCR_REG, BIT0);
+}
+
+static inline void vt1603_bat_pen_manual(struct vt1603 *vt1603)
+{
+ vt1603_setbits(vt1603, VT1603_INTCR_REG, BIT7);
+}
+
+static void vt1603_bat_power_up(struct vt1603 *vt1603)
+{
+ if (vt1603_get_reg8(vt1603, VT1603_PWC_REG) != 0x08)
+ vt1603_set_reg8(vt1603, VT1603_PWC_REG, 0x08);
+}
+
+static int vt1603_read_volt(struct vt1603 *vt1603)
+{
+ int timeout = 2000;
+ int ret = 0;
+ int value;
+
+ // wait for interrupt that adc converted completed.
+ do {
+ if (vt1603_get_reg8(vt1603, VT1603_INTS_REG) & BIT0)
+ break;
+ } while (timeout--);
+
+ if (!timeout) {
+ pr_err("wait adc end timeout ?!\n");
+ return -ETIMEDOUT;
+ }
+
+ ret = vt1603_get_bat_data(vt1603, &value);
+ if (ret < 0) {
+ pr_err("vt1603 get bat adc data Failed!\n");
+ return ret;
+ }
+
+ return value;
+}
+
+static int vt1603_manual_read_adc(struct vt1603 *vt1603)
+{
+ int i;
+ int ret = 0;
+ uint32_t sum = 0;
+
+ /* enable sar-adc power and clock */
+ vt1603_bat_power_up(vt1603);
+ /* enable pen down/up to avoid miss irq */
+ vt1603_bat_pen_manual(vt1603);
+ /* switch vt1603 to battery detect mode */
+ vt1603_switch_to_bat_mode(vt1603);
+ /* do conversion use battery manual mode */
+ vt1603_setbits(vt1603, VT1603_INTS_REG, BIT0);
+ vt1603_set_reg8(vt1603, VT1603_CR_REG, BIT4);
+
+ for (i = 0; i < 4; i++) {
+ ret = vt1603_read_volt(vt1603);
+ if (ret < 0)
+ break;
+ sum += ret;
+
+ vt1603_setbits(vt1603, VT1603_INTS_REG, BIT0);
+ vt1603_set_reg8(vt1603, VT1603_CR_REG, BIT4); //start manual ADC mode
+ }
+ vt1603_clrbits(vt1603, VT1603_INTCR_REG, BIT7);
+ vt1603_setbits(vt1603, VT1603_INTS_REG, BIT0 | BIT3);
+ vt1603_set_reg8(vt1603, VT1603_CR_REG, BIT1);
+
+ return (ret < 0) ? ret : (sum >> 2);
+}
+
+static inline int volt_reg_to_mV(int value)
+{
+ return ((value * 1047) / 1000);
+}
+
+static int vt1603_bat_read_voltage(struct vt1603_device_info *di, int *intval)
+{
+ int ret = vt1603_manual_read_adc(di->vt1603);
+ if (ret < 0)
+ return ret;
+
+ *intval = volt_reg_to_mV(ret);
+ return 0;
+}
+
+static int vt1603_bat_read_status(struct vt1603_device_info *di, int *intval)
+{
+ int status;
+
+ status = charger_get_status();
+ if (status < 0)
+ return status;
+
+ if (status == POWER_SUPPLY_STATUS_CHARGING && di->capacity == 100)
+ status = POWER_SUPPLY_STATUS_FULL;
+
+ batt_leds_update(status);
+ *intval = status;
+ return 0;
+}
+
+static int vt1603_proc_read(char *buf, char **start, off_t offset, int len,
+ int *eof, void *data)
+{
+ int l = 0, i;
+ int ret, status, dcin, voltage, full;
+ struct vt1603_device_info *di = vt1603_dev_info;
+
+ mutex_lock(&di->mutex);
+
+ ret = vt1603_bat_read_status(di, &status);
+ if (ret) {
+ pr_err("vt1603_bat_read_status failed\n");
+ goto out;
+ }
+ voltage = vt1603_manual_read_adc(di->vt1603);
+ if (voltage < 0) {
+ pr_err("vt1603_manual_read_adc failed\n");
+ goto out;
+ }
+
+ dcin = power_supply_is_system_supplied();
+ full = charger_is_full();
+
+ l += sprintf(buf + l, "status : %d\n", status);
+ l += sprintf(buf + l, "dcin : %d\n", dcin);
+ l += sprintf(buf + l, "voltage : %d\n", voltage);
+ l += sprintf(buf + l, "full : %d\n", full);
+ l += sprintf(buf + l, "sleeping : %d\n", di->sleeping);
+ l += sprintf(buf + l, "debug : %d\n", di->debug);
+
+ for (i = 0; i < COMPENSATION_COUNT; i++) {
+ l += sprintf(buf +l, "compensation %10s : %d\n",
+ compensation_strings[i], di->compensation[i]);
+ }
+
+ /* clear after read */
+ di->sleeping = 0;
+out:
+ mutex_unlock(&di->mutex);
+ return l;
+}
+
+static int vt1603_proc_write(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ int bm, usage;
+ struct vt1603_device_info *di = vt1603_dev_info;
+ int capacity;
+
+ if (sscanf(buffer, "capacity=%d", &capacity)) {
+ di->capacity = capacity;
+ power_supply_changed(&di->ps_bat);
+ return count;
+ }
+
+ if (sscanf(buffer, "debug=%d", &di->debug))
+ return count;
+
+ if (sscanf(buffer, "MODULE_CHANGE:%d-%d", &bm, &usage) < 2)
+ return 0;
+
+ if (bm < 0 || bm >= COMPENSATION_COUNT) {
+ pr_err("bm %d error, [0, %d)\n", bm, COMPENSATION_COUNT);
+ return 0;
+ }
+
+ if (usage > 100 || usage < 0) {
+ pr_err("usage %d error\n", usage);
+ return 0;
+ }
+
+ mutex_lock(&di->mutex);
+ di->compensation[bm] = usage;
+ mutex_unlock(&di->mutex);
+ return count;
+}
+
+#define VT1603_PROC_NAME "battery_calibration"
+
+static void vt1603_proc_init(void)
+{
+ struct proc_dir_entry *entry;
+
+ entry = create_proc_entry(VT1603_PROC_NAME, 0666, NULL);
+ if (entry) {
+ entry->read_proc = vt1603_proc_read;
+ entry->write_proc = vt1603_proc_write;
+ }
+}
+
+static void vt1603_proc_cleanup(void)
+{
+ remove_proc_entry(VT1603_PROC_NAME, NULL);
+}
+
+#define to_vt1603_device_info(x) container_of((x), \
+ struct vt1603_device_info, ps_bat);
+
+static int vt1603_battery_get_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ union power_supply_propval *val)
+{
+ int ret = 0;
+ struct vt1603_device_info *di = to_vt1603_device_info(psy);
+
+ mutex_lock(&di->mutex);
+ switch (psp) {
+ case POWER_SUPPLY_PROP_STATUS:
+ ret = vt1603_bat_read_status(di, &val->intval);
+ break;
+ case POWER_SUPPLY_PROP_CAPACITY:
+ val->intval = di->capacity;
+ break;
+ case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+ ret = vt1603_bat_read_voltage(di, &val->intval);
+ break;
+ case POWER_SUPPLY_PROP_TECHNOLOGY:
+ val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
+ break;
+ case POWER_SUPPLY_PROP_PRESENT:
+ val->intval = 1;
+ break;
+ case POWER_SUPPLY_PROP_HEALTH:
+ val->intval = POWER_SUPPLY_HEALTH_GOOD;
+ break;
+ case POWER_SUPPLY_PROP_TEMP:
+ val->intval = 250;
+ break;
+ case POWER_SUPPLY_PROP_ONLINE:
+ val->intval = 1;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ mutex_unlock(&di->mutex);
+ return ret;
+}
+
+static void vt1603_external_power_changed(struct power_supply *psy)
+{
+ power_supply_changed(psy);
+}
+
+static enum power_supply_property vt1603_battery_props[] = {
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_HEALTH,
+ POWER_SUPPLY_PROP_PRESENT,
+ POWER_SUPPLY_PROP_TEMP,
+ POWER_SUPPLY_PROP_ONLINE,
+ POWER_SUPPLY_PROP_CAPACITY,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_TECHNOLOGY,
+};
+
+static int __devinit vt1603_batt_probe(struct platform_device *pdev)
+{
+ struct vt1603_device_info *di;
+ int ret;
+
+ di = kzalloc(sizeof(*di), GFP_KERNEL);
+ if (!di) {
+ dev_err(&pdev->dev, "no memery\n");
+ return -ENOMEM;
+ }
+
+ di->dev = &pdev->dev;
+ di->vt1603 = dev_get_platdata(&pdev->dev);
+ di->capacity = 50;
+
+ mutex_init(&di->mutex);
+
+ di->ps_bat.name = "battery";
+ di->ps_bat.type = POWER_SUPPLY_TYPE_BATTERY;
+ di->ps_bat.properties = vt1603_battery_props;
+ di->ps_bat.num_properties = ARRAY_SIZE(vt1603_battery_props);
+ di->ps_bat.get_property = vt1603_battery_get_property;
+ di->ps_bat.external_power_changed = vt1603_external_power_changed;
+
+ ret = power_supply_register(di->dev, &di->ps_bat);
+ if (ret) {
+ dev_err(di->dev, "failed to register battery: %d\n", ret);
+ kfree(di);
+ return ret;
+ }
+
+ platform_set_drvdata(pdev, di);
+ vt1603_dev_info = di;
+
+ vt1603_proc_init();
+
+ pr_info("VT1603 Battery Driver Installed!\n");
+ return 0;
+}
+
+static int __devexit vt1603_batt_remove(struct platform_device *pdev)
+{
+ struct vt1603_device_info *di = platform_get_drvdata(pdev);
+ vt1603_proc_cleanup();
+ power_supply_unregister(&di->ps_bat);
+ kfree(di);
+ vt1603_dev_info = NULL;
+ pr_info("VT1603 Battery Driver Removed!\n");
+ return 0;
+}
+
+static int vt1603_batt_suspend_prepare(struct device *dev)
+{
+ struct vt1603_device_info *di = dev_get_drvdata(dev);
+ int status, ret;
+
+ ret = vt1603_bat_read_status(di, &status);
+ if (ret) {
+ pr_err("vt1603_bat_read_status failed\n");
+ return 0;
+ }
+
+ if (status == POWER_SUPPLY_STATUS_CHARGING)
+ batt_leds_suspend_prepare();
+
+ return 0;
+}
+
+static int vt1603_batt_suspend(struct device *dev)
+{
+ return 0;
+}
+
+static int vt1603_batt_resume(struct device *dev)
+{
+ struct vt1603_device_info *di = dev_get_drvdata(dev);
+ di->sleeping = 1;
+ return 0;
+}
+
+static void vt1603_batt_resume_complete(struct device *dev)
+{
+ return batt_leds_resume_complete();
+}
+
+static const struct dev_pm_ops vt1603_batt_manager_pm = {
+ .prepare = vt1603_batt_suspend_prepare,
+ .suspend = vt1603_batt_suspend,
+ .resume = vt1603_batt_resume,
+ .complete = vt1603_batt_resume_complete,
+};
+
+static struct platform_driver vt1603_batt_driver = {
+ .driver = {
+ .name = "vt1603-batt",
+ .owner = THIS_MODULE,
+ .pm = &vt1603_batt_manager_pm,
+ },
+ .probe = vt1603_batt_probe,
+ .remove = __devexit_p(vt1603_batt_remove),
+};
+
+static int parse_battery_param(void)
+{
+ char env[] = "wmt.battery.param";
+ char buf[64];
+ size_t l = sizeof(buf);
+
+ if (wmt_getsyspara(env, buf, &l))
+ return -EINVAL;
+
+ return prefixcmp(buf, "vt1603") ? -ENODEV : 0;
+}
+
+static int __init vt1603_batt_init(void)
+{
+ if (parse_battery_param())
+ return -EINVAL;
+
+ batt_leds_setup();
+ return platform_driver_register(&vt1603_batt_driver);
+}
+
+static void __exit vt1603_batt_exit(void)
+{
+ platform_driver_unregister(&vt1603_batt_driver);
+ batt_leds_cleanup();
+}
+
+module_init(vt1603_batt_init);
+module_exit(vt1603_batt_exit);
+
+MODULE_AUTHOR("WonderMedia");
+MODULE_DESCRIPTION("WonderMedia VT1603 Adc Battery Driver");
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/power/wmt_battery/gauge/vt1603/vt1603.h b/drivers/power/wmt_battery/gauge/vt1603/vt1603.h
new file mode 100755
index 00000000..24471226
--- /dev/null
+++ b/drivers/power/wmt_battery/gauge/vt1603/vt1603.h
@@ -0,0 +1,124 @@
+/*++
+ Copyright (c) 2008 WonderMedia Technologies, Inc.
+
+ This program is free software: you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software Foundation,
+ either version 2 of the License, or (at your option) any later version.
+
+ 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, see <http://www.gnu.org/licenses/>.
+
+ WonderMedia Technologies, Inc.
+ 10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
+--*/
+
+#ifndef __VT1603_BAT_H__
+#define __VT1603_BAT_H__
+#include <linux/mfd/vt1603/core.h>
+
+#define BIT0 0x00000001
+#define BIT1 0x00000002
+#define BIT2 0x00000004
+#define BIT3 0x00000008
+#define BIT4 0x00000010
+#define BIT5 0x00000020
+#define BIT6 0x00000040
+#define BIT7 0x00000080
+#define BIT8 0x00000100
+
+/* VT1603 touch panel state */
+#define TS_PENDOWN_STATE 0x00
+#define TS_PENUP_STATE 0x01
+
+/* vt1603 bus type config */
+#define VT1603_MAX_SPI_CLK (20*1000*1000)
+#define SPI_DEFAULT_CLK (12*1000*1000)
+#define IDLE_DATA_NUM 5
+#define VT1603_SPI_FIX_CS 0x00
+#define VT1603_SPI_FAKE_CS 3 //(0x7F - 1)
+#define VT1603_SPI_BUS_0 0x00
+#define VT1603_SPI_BUS_1 0x01
+#define VT1603_REG_OP_R 0x00
+#define VT1603_REG_OP_W 0x01
+
+
+#define VT1603_I2C_FIX_ADDR 0x1A
+#define VT1603_I2C_FAKE_ADDR 0xEE
+#define VT1603_I2C_WCMD 0x00
+#define VT1603_I2C_RCMD 0x01
+#define VT1603_I2C_RWCMD 0x02
+#define VT1603_I2C_BUS_0 0x00
+#define VT1603_I2C_BUS_1 0x01
+
+
+#define BA_WAKEUP_SRC_0 BIT0
+#define BA_WAKEUP_SRC_1 BIT1
+#define BA_WAKEUP_SRC_2 BIT2
+#define BA_WAKEUP_SRC_3 BIT3
+
+#define I2C_BUS 0
+#define SPI_BUS 1
+#define VT1603_FIFO_LEN 3
+
+/* VT1603 Register address */
+#define VT1603_BTHD_REG 0x78
+#define VT1603_BCLK_REG 0x88
+#define VT1603_BAEN_REG 0x04
+
+#define VT1603_PWC_REG 0xC0
+#define VT1603_CR_REG 0xC1
+#define VT1603_CCCR_REG 0xC2
+#define VT1603_CDPR_REG 0xC3
+#define VT1603_TSPC_REG 0xC4
+#define VT1603_AMCR_REG 0xC7
+#define VT1603_INTCR_REG 0xC8
+#define VT1603_INTEN_REG 0xC9
+#define VT1603_INTS_REG 0xCA
+#define VT1603_DCR_REG 0xCB
+
+#define VT1603_TODCL_REG 0xCC
+#define VT1603_TODCH_REG 0xCD
+
+#define VT1603_DATL_REG 0xCE
+#define VT1603_DATH_REG 0xCF
+
+#define VT1603_XPL_REG 0xD0
+#define VT1603_XPH_REG 0xD1
+#define VT1603_YPL_REG 0xD2
+#define VT1603_YPH_REG 0xD3
+
+#define VT1603_BATL_REG 0xD4
+#define VT1603_BATH_REG 0xD5
+
+#define VT1603_TEMPL_REG 0xD6
+#define VT1603_TEMPH_REG 0xD7
+
+#define VT1603_ERR8_REG 0xD8
+#define VT1603_ERR7_REG 0xD9
+#define VT1603_ERR6_REG 0xDA
+#define VT1603_ERR5_REG 0xDB
+#define VT1603_ERR4_REG 0xDC
+#define VT1603_ERR3_REG 0xDD
+#define VT1603_ERR2_REG 0xDE
+#define VT1603_ERR1_REG 0xDF
+
+#define VT1603_DBG8_REG 0xE0
+#define VT1603_DBG7_REG 0xE1
+#define VT1603_DBG6_REG 0xE2
+#define VT1603_DBG5_REG 0xE3
+#define VT1603_DBG4_REG 0xE4
+#define VT1603_DBG3_REG 0xE5
+#define VT1603_DBG2_REG 0xE6
+#define VT1603_DBG1_REG 0xE7
+
+/* for VT1603 GPIO1 interrupt setting */
+#define VT1603_IMASK_REG27 27
+#define VT1603_IMASK_REG28 28
+#define VT1603_IMASK_REG29 29
+#define VT1603_IPOL_REG33 33
+#define VT1603_ISEL_REG36 36
+
+#endif /* __VT1603_TS_H__ */