power: pm8921-charger: Add HTC variants of pm8921-charger, pm8921-bms

HTC kernel version: villeu-jb-crc-3.4.10-ae8b65e

Change-Id: I2a0f9fc8b80bbf4fee5bd2d840fcb86a59b0ab68
diff --git a/include/linux/mfd/pm8xxx/pm8921-bms-htc.h b/include/linux/mfd/pm8xxx/pm8921-bms-htc.h
new file mode 100644
index 0000000..d38ecbe
--- /dev/null
+++ b/include/linux/mfd/pm8xxx/pm8921-bms-htc.h
@@ -0,0 +1,186 @@
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#ifndef __PM8XXX_BMS_H
+#define __PM8XXX_BMS_H
+
+#include <linux/errno.h>
+
+#define PM8921_BMS_DEV_NAME	"pm8921-bms"
+
+#define FCC_CC_COLS		5
+#define FCC_TEMP_COLS		8
+
+#define PC_CC_ROWS             29
+#define PC_CC_COLS             13
+
+#define PC_TEMP_ROWS		29
+#define PC_TEMP_COLS		8
+
+#define MAX_SINGLE_LUT_COLS	20
+
+struct single_row_lut {
+	int x[MAX_SINGLE_LUT_COLS];
+	int y[MAX_SINGLE_LUT_COLS];
+	int cols;
+};
+
+struct sf_lut {
+	int rows;
+	int cols;
+	int row_entries[PC_CC_COLS];
+	int percent[PC_CC_ROWS];
+	int sf[PC_CC_ROWS][PC_CC_COLS];
+};
+
+struct pc_temp_ocv_lut {
+	int rows;
+	int cols;
+	int temp[PC_TEMP_COLS];
+	int percent[PC_TEMP_ROWS];
+	int ocv[PC_TEMP_ROWS][PC_TEMP_COLS];
+};
+
+struct pm8921_bms_battery_data {
+	unsigned int		fcc;
+	struct single_row_lut	*fcc_temp_lut;
+	struct single_row_lut	*fcc_sf_lut;
+	struct pc_temp_ocv_lut	*pc_temp_ocv_lut;
+	struct sf_lut		*pc_sf_lut;
+	struct sf_lut		*rbatt_sf_lut;
+	int			default_rbatt_mohm;
+	int			delta_rbatt_mohm;
+};
+
+struct pm8xxx_bms_core_data {
+	unsigned int	batt_temp_channel;
+	unsigned int	vbat_channel;
+	unsigned int	ref625mv_channel;
+	unsigned int	ref1p25v_channel;
+	unsigned int	batt_id_channel;
+};
+
+enum battery_type {
+	BATT_UNKNOWN = 0,
+	BATT_PALLADIUM,
+	BATT_DESAY,
+};
+
+struct pm8921_bms_platform_data {
+	struct pm8xxx_bms_core_data	bms_cdata;
+	enum battery_type		battery_type;
+	unsigned int			r_sense;
+	unsigned int			i_test;
+	unsigned int			v_failure;
+	unsigned int			max_voltage_uv;
+	unsigned int			rconn_mohm;
+	int				enable_fcc_learning;
+};
+
+#if defined(CONFIG_PM8921_BMS) || defined(CONFIG_PM8921_BMS_MODULE)
+extern struct pm8921_bms_battery_data  palladium_1500_data;
+extern struct pm8921_bms_battery_data  desay_5200_data;
+int pm8921_bms_get_vsense_avg(int *result);
+
+int pm8921_bms_get_battery_current(int *result);
+
+int pm8921_bms_get_percent_charge(void);
+
+int pm8921_bms_get_fcc(void);
+
+int pm8921_bms_charging_began(void);
+void pm8921_bms_charging_end(int is_battery_full);
+
+void pm8921_bms_calibrate_hkadc(void);
+int pm8921_bms_stop_ocv_updates(void);
+int pm8921_bms_start_ocv_updates(void);
+int pm8921_bms_get_simultaneous_battery_voltage_and_current(int *ibat_ua,
+								int *vbat_uv);
+int pm8921_bms_get_rbatt(void);
+void pm8921_bms_invalidate_shutdown_soc(void);
+int pm8921_bms_dump_all(void);
+#ifdef CONFIG_HTC_BATT_8960
+int pm8921_bms_get_batt_current(int *result);
+
+int pm8921_bms_get_batt_soc(int *result);
+int pm8921_bms_get_batt_cc(int *result);
+int pm8921_bms_get_attr_text(char *buf, int size);
+#endif 
+#else
+static inline int pm8921_bms_get_vsense_avg(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_battery_current(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_percent_charge(void)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_fcc(void)
+{
+	return -ENXIO;
+}
+static inline void pm8921_bms_charging_began(void)
+{
+}
+static inline void pm8921_bms_charging_end(int is_battery_full)
+{
+}
+static inline void pm8921_bms_calibrate_hkadc(void)
+{
+}
+static inline void pm8921_bms_stop_ocv_updates(void)
+{
+}
+static inline void pm8921_bms_start_ocv_updates(void)
+{
+}
+static inline int pm8921_bms_get_simultaneous_battery_voltage_and_current(
+						int *ibat_ua, int *vbat_uv)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_rbatt(void)
+{
+	return -EINVAL;
+}
+static inline void pm8921_bms_invalidate_shutdown_soc(void)
+{
+}
+static inline int pm8921_bms_dump_all(void)
+{
+	return -ENXIO;
+}
+#ifdef CONFIG_HTC_BATT_8960
+static inline int pm8921_bms_get_batt_current(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_batt_soc(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_batt_cc(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_bms_get_attr_text(char *buf, int size)
+{
+	return 0;
+}
+#endif 
+#endif
+
+#endif
diff --git a/include/linux/mfd/pm8xxx/pm8921-charger-htc.h b/include/linux/mfd/pm8xxx/pm8921-charger-htc.h
new file mode 100644
index 0000000..f4151cb
--- /dev/null
+++ b/include/linux/mfd/pm8xxx/pm8921-charger-htc.h
@@ -0,0 +1,354 @@
+/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ */
+
+#ifndef __PM8XXX_CHARGER_H
+#define __PM8XXX_CHARGER_H
+
+#include <linux/errno.h>
+#include <linux/power_supply.h>
+#ifdef CONFIG_HTC_BATT_8960
+#include <mach/htc_charger.h>
+#endif
+
+#define PM8921_CHARGER_DEV_NAME	"pm8921-charger"
+
+struct pm8xxx_charger_core_data {
+	unsigned int	vbat_channel;
+	unsigned int	batt_temp_channel;
+	unsigned int	batt_id_channel;
+};
+
+enum pm8921_chg_cold_thr {
+	PM_SMBC_BATT_TEMP_COLD_THR__LOW,
+	PM_SMBC_BATT_TEMP_COLD_THR__HIGH
+};
+
+enum pm8921_chg_hot_thr	{
+	PM_SMBC_BATT_TEMP_HOT_THR__LOW,
+	PM_SMBC_BATT_TEMP_HOT_THR__HIGH
+};
+
+enum pm8921_usb_ov_threshold {
+	PM_USB_OV_5P5V,
+	PM_USB_OV_6V,
+	PM_USB_OV_6P5V,
+	PM_USB_OV_7V,
+};
+
+enum pm8921_usb_debounce_time {
+	PM_USB_BYPASS_DEBOUNCER,
+	PM_USB_DEBOUNCE_20P5MS,
+	PM_USB_DEBOUNCE_40P5MS,
+	PM_USB_DEBOUNCE_80P5MS,
+};
+
+enum pm8921_chg_led_src_config {
+	LED_SRC_GND,
+	LED_SRC_VPH_PWR,
+	LED_SRC_5V,
+	LED_SRC_MIN_VPH_5V,
+	LED_SRC_BYPASS,
+};
+
+
+struct ext_usb_chg_pm8921 {
+	const char	*name;
+	void		*ctx;
+	int		(*start_charging) (void *ctx);
+	int		(*stop_charging) (void *ctx);
+	bool		(*is_trickle) (void *ctx);
+	struct htc_charger	*ichg;
+};
+
+
+struct pm8921_charger_platform_data {
+	struct pm8xxx_charger_core_data	charger_cdata;
+	unsigned int			safety_time;
+	unsigned int			ttrkl_time;
+	unsigned int			update_time;
+	unsigned int			max_voltage;
+	unsigned int			min_voltage;
+	unsigned int			resume_voltage_delta;
+	unsigned int			term_current;
+	int				cool_temp;
+	int				warm_temp;
+	unsigned int			temp_check_period;
+	unsigned int			max_bat_chg_current;
+	unsigned int			cool_bat_chg_current;
+	unsigned int			warm_bat_chg_current;
+	unsigned int			cool_bat_voltage;
+	unsigned int			warm_bat_voltage;
+	unsigned int			(*get_batt_capacity_percent) (void);
+	int64_t				batt_id_min;
+	int64_t				batt_id_max;
+	bool				keep_btm_on_suspend;
+	bool				dc_unplug_check;
+	int				trkl_voltage;
+	int				weak_voltage;
+	int				trkl_current;
+	int				weak_current;
+	int				vin_min;
+	int				*thermal_mitigation;
+	int				thermal_levels;
+	int				mbat_in_gpio;
+	int				is_embeded_batt;
+	enum pm8921_chg_cold_thr	cold_thr;
+	enum pm8921_chg_hot_thr		hot_thr;
+	int				rconn_mohm;
+	enum pm8921_chg_led_src_config	led_src_config;
+	struct ext_usb_chg_pm8921	*ext_usb;
+};
+
+enum pm8921_charger_source {
+	PM8921_CHG_SRC_NONE,
+	PM8921_CHG_SRC_USB,
+	PM8921_CHG_SRC_DC,
+};
+
+struct ext_chg_pm8921 {
+	const char	*name;
+	void		*ctx;
+	int		(*start_charging) (void *ctx);
+	int		(*stop_charging) (void *ctx);
+	bool		(*is_trickle) (void *ctx);
+};
+
+#ifdef CONFIG_HTC_BATT_8960
+struct pm8921_charger_batt_param {
+	unsigned int max_voltage;
+	unsigned int cool_bat_voltage;
+	unsigned int warm_bat_voltage;
+};
+#endif 
+
+#if defined(CONFIG_PM8921_CHARGER) || defined(CONFIG_PM8921_CHARGER_MODULE)
+void pm8921_charger_vbus_draw(unsigned int mA);
+int pm8921_charger_register_vbus_sn(void (*callback)(int));
+void pm8921_charger_unregister_vbus_sn(void (*callback)(int));
+int pm8921_charger_enable(bool enable);
+
+int pm8921_is_usb_chg_plugged_in(void);
+
+int pm8921_is_dc_chg_plugged_in(void);
+
+int pm8921_is_pwr_src_plugged_in(void);
+
+int pm8921_is_battery_present(void);
+
+int pm8921_set_max_battery_charge_current(int ma);
+
+int pm8921_disable_input_current_limit(bool disable);
+
+
+int pm8921_set_usb_power_supply_type(enum power_supply_type type);
+
+int pm8921_disable_source_current(bool disable);
+
+int pm8921_regulate_input_voltage(int voltage);
+bool pm8921_is_battery_charging(int *source);
+
+int pm8921_batt_temperature(void);
+int register_external_dc_charger(struct ext_chg_pm8921 *ext);
+
+void unregister_external_dc_charger(struct ext_chg_pm8921 *ext);
+
+int pm8921_usb_ovp_set_threshold(enum pm8921_usb_ov_threshold ov);
+
+int pm8921_usb_ovp_set_hystersis(enum pm8921_usb_debounce_time ms);
+
+int pm8921_usb_ovp_disable(int disable);
+
+#ifdef CONFIG_HTC_BATT_8960
+int pm8921_get_batt_voltage(int *result);
+
+int pm8921_get_batt_temperature(int *result);
+
+int pm8921_get_batt_id(int *result);
+
+int pm8921_is_batt_temperature_fault(int *result);
+
+int pm8921_is_batt_temp_fault_disable_chg(int *result);
+
+int pm8921_is_batt_full(int *result);
+
+int pm8921_get_charging_source(int *result);
+
+int pm8921_get_charging_enabled(int *result);
+
+int pm8921_pwrsrc_enable(bool enable);
+
+int pm8921_set_pwrsrc_and_charger_enable(enum htc_power_source_type src,
+		bool chg_enable, bool pwrsrc_enable);
+
+int pm8921_limit_charge_enable(bool enable);
+
+int pm8921_is_charger_ovp(int *result);
+
+int pm8921_dump_all(void);
+
+int pm8921_charger_get_attr_text(char *buf, int size);
+
+int pm8921_charger_get_attr_text_with_ext_charger(char *buf, int size);
+
+int pm8921_gauge_get_attr_text(char *buf, int size);
+#endif 
+void pm8921_chg_disable_usbin_valid_irq(void);
+void pm8921_chg_enable_usbin_valid_irq(void);
+#else
+static inline void pm8921_charger_vbus_draw(unsigned int mA)
+{
+}
+static inline int pm8921_charger_register_vbus_sn(void (*callback)(int))
+{
+	return -ENXIO;
+}
+static inline void pm8921_charger_unregister_vbus_sn(void (*callback)(int))
+{
+}
+static inline int pm8921_charger_enable(bool enable)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_usb_chg_plugged_in(void)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_dc_chg_plugged_in(void)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_pwr_src_plugged_in(void)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_battery_present(void)
+{
+	return -ENXIO;
+}
+static inline int pm8921_disable_input_current_limit(bool disable)
+{
+	return -ENXIO;
+}
+static inline int pm8921_set_usb_power_supply_type(enum power_supply_type type)
+{
+	return -ENXIO;
+}
+static inline int pm8921_set_max_battery_charge_current(int ma)
+{
+	return -ENXIO;
+}
+static inline int pm8921_disable_source_current(bool disable)
+{
+	return -ENXIO;
+}
+static inline int pm8921_regulate_input_voltage(int voltage)
+{
+	return -ENXIO;
+}
+static inline bool pm8921_is_battery_charging(int *source)
+{
+	*source = PM8921_CHG_SRC_NONE;
+	return 0;
+}
+static inline int pm8921_batt_temperature(void)
+{
+	return -ENXIO;
+}
+static inline int register_external_dc_charger(struct ext_chg_pm8921 *ext)
+{
+	pr_err("%s.not implemented.\n", __func__);
+	return -ENODEV;
+}
+static inline void unregister_external_dc_charger(struct ext_chg_pm8921 *ext)
+{
+	pr_err("%s.not implemented.\n", __func__);
+}
+static inline int pm8921_usb_ovp_set_threshold(enum pm8921_usb_ov_threshold ov)
+{
+	return -ENXIO;
+}
+static inline int pm8921_usb_ovp_set_hystersis(enum pm8921_usb_debounce_time ms)
+{
+	return -ENXIO;
+}
+static inline int pm8921_usb_ovp_disable(int disable)
+{
+	return -ENXIO;
+}
+#ifdef CONFIG_HTC_BATT_8960
+static inline int pm8921_get_batt_voltage(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_get_batt_temperature(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_get_batt_id(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_batt_temperature_fault(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_batt_temp_fault_disable_chg(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_batt_full(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_get_charging_source(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_get_charging_enabled(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_pwrsrc_enable(bool enable)
+{
+	return -ENXIO;
+}
+static inline int pm8921_set_pwrsrc_and_charger_enable(enum htc_power_source_type src,
+		bool chg_enable, bool pwrsrc_enable)
+{
+	return -ENXIO;
+}
+static inline int pm8921_limit_charge_enable(bool enable)
+{
+	return -ENXIO;
+}
+static inline int pm8921_is_charger_ovp(int *result)
+{
+	return -ENXIO;
+}
+static inline int pm8921_charger_get_attr_text(char *buf, int size)
+{
+	return -ENXIO;
+}
+static inline int pm8921_gauge_get_attr_text(char *buf, int size)
+{
+	return -ENXIO;
+}
+#endif 
+static inline void pm8921_chg_disable_usbin_valid_irq(void)
+{
+}
+static inline void pm8921_chg_enable_usbin_valid_irq(void)
+{
+}
+#endif
+
+#endif
diff --git a/include/linux/mfd/pm8xxx/pm8921.h b/include/linux/mfd/pm8xxx/pm8921.h
index aabbb21..d9710ca 100644
--- a/include/linux/mfd/pm8xxx/pm8921.h
+++ b/include/linux/mfd/pm8xxx/pm8921.h
@@ -29,10 +29,16 @@
 #include <linux/input/pmic8xxx-pwrkey.h>
 #include <linux/input/pmic8xxx-keypad.h>
 #include <linux/regulator/pm8xxx-regulator.h>
-#include <linux/mfd/pm8xxx/pm8921-charger.h>
 #include <linux/mfd/pm8xxx/pm8xxx-adc.h>
+#ifdef CONFIG_HTC_BATT_8960
+#include <linux/mfd/pm8xxx/pm8921-charger-htc.h>
+#include <linux/mfd/pm8xxx/pm8921-bms-htc.h>
+#include <linux/leds-pm8xxx-htc.h>
+#else
+#include <linux/mfd/pm8xxx/pm8921-charger.h>
 #include <linux/mfd/pm8xxx/pm8921-bms.h>
 #include <linux/leds-pm8xxx.h>
+#endif
 #include <linux/mfd/pm8xxx/vibrator.h>
 #include <linux/mfd/pm8xxx/ccadc.h>
 
diff --git a/include/linux/smb349.h b/include/linux/smb349.h
new file mode 100644
index 0000000..9189358
--- /dev/null
+++ b/include/linux/smb349.h
@@ -0,0 +1,377 @@
+/* Copyright (c) 2012 Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only 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.
+ *
+ */
+#ifndef __SMB349_H__
+#define __SMB349_H__
+
+#ifdef CONFIG_HTC_BATT_8960
+#include <mach/htc_charger.h>
+#endif
+
+#define SMB_CHG_CURR_REG			0x00
+#define CHG_OTHER_CURRENT_REG		0x01
+#define VAR_FUNC_REG			0x02
+#define FLOAT_VOLTAGE_REG		0x03
+#define CHG_CTRL_REG			0x04
+#define STAT_TIMER_REG			0x05
+#define PIN_ENABLE_CTRL_REG		0x06
+#define THERM_CTRL_A_REG		0x07
+#define SYSOK_USB3_SEL_REG		0x08
+#define CTRL_FUNC_REG		0x09
+#define OTG_TLIM_THERM_CNTRL_REG	0x0A
+#define LIMIT_CELL_TEMP_MONI_REG 0x0B
+#define FAULT_IRQ_REG				0x0C
+#define STATUS_IRQ_REG				0x0D
+#define SYSOK_REG				0x0E
+#define AUTO_INPUT_VOL_DET_REG		0x10
+#define I2C_BUS_REG				0x12
+#define CMD_A_REG				0x30
+#define CMD_B_REG				0x31
+#define CMD_C_REG				0x33
+#define IRQ_A_REG				0x35
+#define IRQ_B_REG				0x36
+#define IRQ_C_REG				0x37
+#define IRQ_D_REG				0x38
+#define IRQ_E_REG				0x39
+#define IRQ_F_REG				0x3A
+#define STATUS_A_REG				0x3B
+#define STATUS_B_REG				0x3C
+#define STATUS_C_REG				0x3D
+#define STATUS_D_REG				0x3E
+#define STATUS_E_REG				0x3F
+
+#define CHG_STATUS_MASK		SMB349_MASK(2, 1)
+#define CHG_ENABLE_STATUS_BIT		BIT(0)
+
+#define FAST_CHG_CURRENT_MASK			SMB349_MASK(4, 4)
+
+
+#define SUSPEND_MODE_MASK				SMB349_MASK(1, 2)
+
+#define CHARGING_ENABLE_MASK				SMB349_MASK(1, 1)
+#define VOLIATILE_WRITE_PERMISSIOIN_MASK		SMB349_MASK(1, 7)
+#define CURRENT_TERMINATION_MASK			SMB349_MASK(1, 6)
+
+#define OTG_ENABLE_MASK				SMB349_MASK(1, 4)
+#define AICL_MASK				SMB349_MASK(1, 4)
+#define USBCS_MASK				SMB349_MASK(1, 4)
+
+#define AC_INPUT_CURRENT_LIMIT_MASK		SMB349_MASK(4, 0)
+#define DC_INPUT_CURRENT_LIMIT_MASK		SMB349_MASK(4, 0)
+
+#define PRE_CHG_CURRENT_MASK			SMB349_MASK(3, 5)
+
+#define USB_HC_MODE_MASK			SMB349_MASK(1, 0)
+#define TERMINATION_CURRENT_MASK		SMB349_MASK(3, 2)
+
+#define USB_1_5_MODE_MASK			SMB349_MASK(1, 1)
+
+#define IS_SUSPEND_MODE_MASK			SMB349_MASK(1, 7)
+
+#define OTG_CURRENT_MASK			SMB349_MASK(2, 2)
+
+
+#define PIN_CONTROL_ACTIVE_MASK			SMB349_MASK(2, 5)
+
+#define PRE_CHG_TO_FAST_CHG_THRESH_MASK		SMB349_MASK(2, 6)
+#define SWITCH_FREQ_MASK			SMB349_MASK(2, 6)
+#define OTG_I2C_PIN_MASK			SMB349_MASK(2, 6)
+
+#define PRE_CHG_TO_FAST_CHG_ENABLE_MASK		SMB349_MASK(1, 1)
+#define FLOAT_VOLTAGE_MASK			SMB349_MASK(6, 0)
+
+
+#define SUSPEND_MODE_BIT			BIT(2)
+#define CHG_ENABLE_BIT				BIT(1)
+#define VOLATILE_W_PERM_BIT			BIT(7)
+#define USB_SELECTION_BIT			BIT(1)
+#define SYSTEM_FET_ENABLE_BIT			BIT(7)
+#define AICL_COMPLETE_STATUS_BIT		BIT(4)
+#define AUTOMATIC_INPUT_CURR_LIMIT_BIT		BIT(4)
+#define I2C_CONTROL_CHARGER_BIT			BIT(5)
+#define AUTOMATIC_POWER_SOURCE_DETECTION_BIT	BIT(2)
+#define BATT_OV_END_CHG_BIT			BIT(1)
+#define VCHG_FUNCTION				BIT(0)
+#define USB_1_5_MODE				BIT(1)
+#define USB_HC_MODE				BIT(0)
+#define POWER_OK_STATUS				BIT(0)
+#define USBCS_PIN_MODE				BIT(4)
+#define USBCS_REGISTER_MODE			0
+#define CURR_TERM_END_CHG_BIT			BIT(6)
+
+#define SMB349_HOT_TEMPERATURE_HARD_LIMIT_IRQ			7
+#define SMB349_HOT_TEMPERATURE_HARD_LIMIT_STATUS                6
+#define SMB349_COLD_TEMPERATURE_HARD_LIMIT_IRQ                  5
+#define SMB349_COLD_TEMPERATURE_HARD_LIMIT_STATUS               4
+#define SMB349_HOT_TEMPERATURE_SOFT_LIMIT_IRQ                   3
+#define SMB349_HOT_TEMPERATURE_SOFT_LIMIT_STATUS                2
+#define SMB349_COLD_TEMPERATURE_SOFT_LIMIT_IRQ                  1
+#define SMB349_COLD_TEMPERATURE_SOFT_LIMIT_STATUS               0
+
+#define SMB349_BATTERY_OVER_VOLTAGE_CONDITION_IRQ		7
+#define SMB349_BATTERY_OVER_VOLTAGE_STATUS			6
+#define SMB349_MISSING_BATTER_IRQ                               5
+#define SMB349_MISSING_BATTERY_STATUS                           4
+#define SMB349_LOW_BATTERY_VOLTAGE_IRQ                          3
+#define SMB349_LOW_BATTERY_VOLTAGE_STATUS                       2
+#define SMB349_PRE_TO_FAST_CHARGE_BATTERY_VOLTAGE_IRQ           1
+#define SMB349_PRE_TO_FAST_CHARGE_BATTERY_VOLTAGE_STATUS        0
+
+#define SMB349_INTERNAL_TEMPERATURE_LIMIT_IRQ			7
+#define SMB349_INTERNAL_TEMPERATURE_LIMIT_STATUS                6
+#define SMB349_RE_CHARGE_BATTERY_THRESHOLD_IRQ                  5
+#define SMB349_RE_CHARGE_BATTERY_THRESHOLD_STATUS               4
+#define SMB349_TAPER_CHARGING_MODE_IRQ                          3
+#define SMB349_TAPER_CHARGING_MODE_STATUS                       2
+#define SMB349_TERMINATION_CHARGING_CURRENT_HIT_IRQ             1
+#define SMB349_TERMINATION_CHARGING_CURRENT_HIT_STATUS          0
+
+#define SMB349_APSD_COMPLETED_IRQ				7
+#define SMB349_APSD_COMPLETED_STATUS                            6
+#define SMB349_AICL_COMPLETE_IRQ                                5
+#define SMB349_AICL_COMPLETE_STATUS                             4
+#define SMB349_RESERVED_3                                         3
+#define SMB349_RESERVED_2                                         2
+#define SMB349_CHARGE_TIMEOUT_IRQ                               1
+#define SMB349_CHARGE_TIMEOUT_STATUS                            0
+
+
+#define SMB349_CIN_OVER_VOLTAGE_IRQ				7
+#define SMB349_DCIN_OVER_VOLTAGE_STATUS				6
+#define SMB349_DCIN_UNDER_VOLTAGE_IRQ				5
+#define SMB349_DCIN_UNDER_VOLTAGE_STATUS			4
+#define SMB349_AFVC_ACTIVE_IRQ					3
+#define SMB349_AFVC_ACTIVE_STATUS				2
+
+#define SMB349_OTG_OVER_CURRENT_LIMIT_IRQ			7
+#define SMB349_OTG_OVER_CURRENT_LIMIT_STATUS            	6
+#define SMB349_OTG_BATTERY_UNDER_VOLTAGE_IRQ            	5
+#define SMB349_OTG_BATTERY_UNDER_VOLTAGE_STATUS         	4
+#define SMB349_OTG_DETECTION_IRQ                        	3
+#define SMB349_OTG_DETECTION_STATUS                     	2
+#define SMB349_POWER_OK_IRQ					1
+#define SMB349_POWER_OK_STATUS					0
+
+
+#define SMB349_FAST_CHG_MIN_MA	1000
+#define SMB349_FAST_CHG_STEP_MA	200
+#define SMB349_FAST_CHG_MAX_MA	4000
+#define SMB349_FAST_CHG_SHIFT	4
+#define SMB349_PRE_CHG_SHIFT	5
+
+#define SMB349_OTG_I2C_PIN_SHIFT	6
+
+#define SMB349_OTG_I2C_CONTROL		0x0
+#define SMB349_OTG_PIN_CONTROL		0x1
+
+#define SMB34X_OTG_CURR_LIMIT_SHIFT	2
+#define SMB349_SWITCH_FREQ_SHIFT	6
+
+#define SMB349_PIN_CONTROL_SHIFT	5
+#define SMB349_USBCS_REGISTER_CTRL	0
+#define SMB349_USBCS_PIN_CTRL		1
+
+#define SMB349_NO_CHARGING				0
+#define SMB349_PRE_CHARGING				1
+#define SMB349_FAST_CHARGING				2
+#define SMB349_TAPER_CHARGING				3
+
+
+
+#define	SMB349_FLOAT_VOL_4000_MV	0x1B
+#define	SMB349_FLOAT_VOL_4200_MV	0x25
+#define	SMB349_FLOAT_VOL_4220_MV	0x26
+#define	SMB349_FLOAT_VOL_4240_MV	0x27
+#define	SMB349_FLOAT_VOL_4260_MV	0x28
+#define	SMB349_FLOAT_VOL_4280_MV	0x29
+#define	SMB349_FLOAT_VOL_4300_MV	0x2A
+#define	SMB349_FLOAT_VOL_4320_MV	0x2B
+#define	SMB349_FLOAT_VOL_4340_MV	0x2C
+#define	SMB349_FLOAT_VOL_4350_MV	0x2D
+
+
+#define SMB_OTG_CURR_LIMIT_250MA		0x0
+#define SMB_OTG_CURR_LIMIT_500MA		0x1
+#define SMB_OTG_CURR_LIMIT_750MA		0x2
+#define SMB_OTG_CURR_LIMIT_1000MA		0x3
+
+
+#define SMB349_I2C_CONTROL_ACTIVE_HIGH		0x0
+#define SMB349_I2C_CONTROL_ACTIVE_LOW		0x1
+#define SMB349_PIN_CONTROL_ACTIVE_HIGH		0x2
+#define SMB349_PIN_CONTROL_ACTIVE_LOW		0x3
+
+#define		AICL_RESULT_500MA	0x0
+#define		AICL_RESULT_900MA       0x1
+#define		AICL_RESULT_1000MA      0x2
+#define		AICL_RESULT_1100MA      0x3
+#define		AICL_RESULT_1200MA      0x4
+#define		AICL_RESULT_1300MA      0x5
+#define		AICL_RESULT_1500MA      0x6
+#define		AICL_RESULT_1600MA      0x7
+#define		AICL_RESULT_1700MA      0x8
+#define		AICL_RESULT_1800MA      0x9
+#define		AICL_RESULT_2000MA      0xa
+#define		AICL_RESULT_2200MA      0xb
+#define		AICL_RESULT_2400MA      0xc
+#define		AICL_RESULT_2500MA      0xd
+#define		AICL_RESULT_3000MA      0xe
+#define		AICL_RESULT_3500MA      0xf
+
+#define		SWITCH_FREQ_750KHZ	0x0
+#define		SWITCH_FREQ_1MHZ       	0x1
+#define		SWITCH_FREQ_1D5MHZ     	0x2
+#define		SWITCH_FREQ_3MHZ       	0x3
+
+#define SMB349_USB_MODE		0
+#define SMB349_HC_MODE		1
+
+#define		FAST_CHARGE_500MA	0x0
+#define		FAST_CHARGE_600MA       0x1
+#define		FAST_CHARGE_700MA       0x2
+#define		FAST_CHARGE_800MA       0x3
+#define		FAST_CHARGE_900MA       0x4
+#define		FAST_CHARGE_1000MA      0x5
+#define		FAST_CHARGE_1100MA      0x6
+#define		FAST_CHARGE_1200MA      0x7
+#define		FAST_CHARGE_1300MA      0x8
+#define		FAST_CHARGE_1400MA      0x9
+#define		FAST_CHARGE_1500MA      0xa
+#define		FAST_CHARGE_1600MA      0xb
+#define		FAST_CHARGE_1700MA      0xc
+#define		FAST_CHARGE_1800MA      0xd
+#define		FAST_CHARGE_1900MA      0xe
+#define		FAST_CHARGE_2000MA      0xf
+
+
+#define         SMB340_FASTCHG_1000MA      0x0
+#define         SMB340_FASTCHG_1200MA      0x1
+#define         SMB340_FASTCHG_1400MA      0x2
+#define         SMB340_FASTCHG_1600MA      0x3
+#define         SMB340_FASTCHG_1800MA      0x4
+#define         SMB340_FASTCHG_2000MA      0x5
+#define         SMB340_FASTCHG_2200MA      0x6
+#define         SMB340_FASTCHG_2400MA      0x7
+#define         SMB340_FASTCHG_2600MA      0x8
+#define         SMB340_FASTCHG_2800MA      0x9
+#define         SMB340_FASTCHG_3000MA      0xa
+#define         SMB340_FASTCHG_3200MA      0xb
+#define         SMB340_FASTCHG_3400MA      0xc
+#define         SMB340_FASTCHG_3600MA      0xd
+#define         SMB340_FASTCHG_3800MA      0xe
+#define         SMB340_FASTCHG_4000MA      0xf
+
+
+
+#define		DC_INPUT_500MA		0x0
+#define		DC_INPUT_900MA		0x1
+#define		DC_INPUT_1000MA		0x2
+#define		DC_INPUT_1100MA		0x3
+#define		DC_INPUT_1200MA		0x4
+#define		DC_INPUT_1300MA		0x5
+#define		DC_INPUT_1500MA		0x6
+#define		DC_INPUT_1600MA		0x7
+#define		DC_INPUT_1700MA		0x8
+#define		DC_INPUT_1800MA		0x9
+#define		DC_INPUT_2000MA		0xa
+#define		DC_INPUT_2200MA		0xb
+#define		DC_INPUT_2400MA		0xc
+#define		DC_INPUT_2500MA		0xd
+#define		DC_INPUT_3000MA		0xe
+#define		DC_INPUT_3500MA		0xf
+
+#define		PRECHG_CURR_100MA		0x0
+#define		PRECHG_CURR_150MA		0x1
+#define		PRECHG_CURR_200MA		0x2
+#define		PRECHG_CURR_250MA		0x3
+#define		PRECHG_CURR_300MA		0x4
+#define		PRECHG_CURR_350MA		0x5
+#define		PRECHG_CURR_50MA		0x6
+
+#define         SMB340_PRECHG_CURR_200MA	0x0
+#define         SMB340_PRECHG_CURR_300MA	0x1
+#define         SMB340_PRECHG_CURR_400MA	0x2
+#define         SMB340_PRECHG_CURR_500MA	0x3
+#define         SMB340_PRECHG_CURR_600MA	0x4
+#define         SMB340_PRECHG_CURR_700MA	0x5
+#define         SMB340_PRECHG_CURR_100MA	0x6
+
+
+#define		SMB_349		1
+#define		SMB_340		2
+
+enum smb349_thermal_state {
+	STATE_HI_V_SCRN_ON = 1,
+	STATE_LO_V_SCRN_ON,
+	STATE_HI_V_SCRN_OFF,
+	STATE_LO_V_SCRN_OFF,
+};
+
+struct smb349_chg_int_notifier {
+	struct list_head notifier_link;
+	const char *name;
+	void (*func)(int int_reg, int value);
+};
+
+struct smb349_platform_data {
+	int chg_susp_gpio;
+	int chg_current_ma;
+	int chip_rev;
+#ifdef CONFIG_SUPPORT_DQ_BATTERY
+	int dq_result;
+#endif
+	int aicl_result_threshold;
+	int dc_input_max;
+};
+
+struct smb349_charger_batt_param {
+	int max_voltage;
+	int cool_bat_voltage;
+};
+int smb349_set_AICL_mode(unsigned int enable);
+int smb349_allow_fast_charging_setting(void);
+int smb349_allow_volatile_wrtting(void);
+int smb349_enable_charging(bool enable);
+int smb349_eoc_notify(enum htc_extchg_event_type main_event);
+int smb349_event_notify(enum htc_extchg_event_type extchg_event);
+int smb349_temp_notify(enum htc_extchg_event_type main_event);
+int smb349_enable_5v_output(bool mhl_in);
+int smb349_config(void);
+void smb349_dbg(void);
+int  smb349_dump_reg(u8 reg);
+void smb349_partial_reg_dump(void);
+int smb349_dump_all(void);
+int smb349_is_AICL_complete(void);
+int smb349_is_AICL_enabled(void);
+int smb349_is_charger_bit_low_active(void);
+int smb349_is_charger_error(void);
+int smb349_reset_max_chg_vol(enum htc_extchg_event_type main_event);
+int smb349_is_charging_enabled(void);
+int smb349_is_batt_temp_fault_disable_chg(int *result);
+int smb349_get_i2c_slave_id(void);
+int smb349_is_hc_mode(void);
+int smb349_is_usbcs_register_mode(void);
+int smb349_masked_write(int reg, u8 mask, u8 val);
+int smb349_not_allow_charging_cycle_end(void);
+int smb349_enable_pwrsrc(bool enable);
+int smb349_set_pwrsrc_and_charger_enable(enum htc_power_source_type src, bool chg_enable, bool pwrsrc_enable);
+int smb349_set_hc_mode(unsigned int enable);
+int smb349_switch_usbcs_mode(int mode);
+int smb349_limit_charge_enable(bool enable);
+int smb349_get_charging_src(int *result);
+int smb349_get_charging_enabled(int *result);
+int smb349_is_charger_overvoltage(int* result);
+int smb349_charger_get_attr_text(char *buf, int size);
+int smb349_start_charging(void *ctx);
+int smb349_stop_charging(void *ctx);
+bool smb349_is_trickle_charging(void *ctx);
+#endif