Add debugfs to check coulomb counter value which reads from PMIC by IPC command.
(Bug 7312 - battery charge status shows abnormally)

Signed-off-by: Major Lee <major_lee@wistron.com>
---

--- linux-2.6.37.bak/drivers/power/intel_mid_battery.c	2011-05-12 11:57:59.840232580 +0800
+++ linux-2.6.37/drivers/power/intel_mid_battery.c	2011-05-16 11:52:04.898702000 +0800
@@ -34,6 +34,9 @@
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
 #include <linux/gpio.h>
+#ifdef CONFIG_DEBUG_FS
+#include <linux/debugfs.h>
+#endif
 
 #include <asm/intel_scu_ipc.h>
 
@@ -105,6 +108,12 @@ struct pmic_power_module_info {
 	struct delayed_work monitor_battery;
 	struct work_struct handler;
 	struct work_struct adap_handler;
+
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs_battery_root;
+	struct dentry *debugfs_ccval;
+	u32 ccval;
+#endif
 };
 
 static unsigned int delay_time = 2000;	/* in ms */
@@ -152,6 +161,10 @@ struct battery_property {
 /* PMIC_GPIO_0 for adapter detection */
 #define PMIC_GPIO_0			64
 
+#ifdef CONFIG_DEBUG_FS
+static struct dentry *debugfs_root;
+#endif
+
 /**
  *	pmic_scu_ipc_battery_cc_read	-	read battery cc
  *	@value: battery coulomb counter read
@@ -262,6 +275,10 @@ static void pmic_battery_read_status(str
 		return;
 	}
 
+#ifdef CONFIG_DEBUG_FS
+	pbi->ccval = ccval;
+#endif
+
 	if (intel_scu_ipc_ioread8(PMIC_BATT_CHR_SCHRGINT_ADDR, &r8)) {
 		dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
 								__func__);
@@ -597,6 +614,59 @@ static void pmic_battery_handle_intrpt(s
 	}
 }
 
+#ifdef CONFIG_DEBUG_FS
+static int ccval_open_file(struct inode *inode, struct file *file)
+{
+	file->private_data = inode->i_private;
+
+	return 0;
+}
+
+static ssize_t ccval_read_file(struct file *file, char __user *user_buf,
+									size_t count, loff_t *ppos)
+{
+	ssize_t ret;
+	struct pmic_power_module_info *pbi = file->private_data;
+	char buf[10];
+
+	ret = sprintf(buf, "%08x\n", pbi->ccval);
+	if (ret >= 0)
+		ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+
+	return ret;
+}
+
+static const struct file_operations ccval_fops = {
+	.open = ccval_open_file,
+	.read = ccval_read_file,
+	.write = NULL,
+	.llseek = default_llseek,
+};
+
+static void init_battery_debugfs(struct pmic_power_module_info *pbi)
+{
+	pbi->debugfs_battery_root = debugfs_create_dir(DRIVER_NAME,
+									debugfs_root);
+	if (!pbi->debugfs_battery_root) {
+		dev_err(pbi->dev, "%s(): Failed to create debugfs directory\n",
+					__func__);
+		return;
+	}
+
+	pbi->debugfs_ccval = debugfs_create_file("ccval", 0400,
+							pbi->debugfs_battery_root,
+							pbi, &ccval_fops);
+	if (!pbi->debugfs_ccval)
+		dev_err(pbi->dev, "%s(): Failed to create ccval debugfs file\n",
+					__func__);
+}
+
+static void cleanup_battery_debugfs(struct pmic_power_module_info *pbi)
+{
+	debugfs_remove_recursive(pbi->debugfs_battery_root);
+}
+#endif
+
 /**
  * pmic_battery_probe - pmic battery initialize
  * @irq: pmic battery device irq
@@ -709,6 +779,10 @@ static __devinit int probe(int irq, stru
 			"registration with power supply subsystem successful\n",
 			__func__);
 
+#ifdef CONFIG_DEBUG_FS
+	init_battery_debugfs(pbi);
+#endif
+
 	return retval;
 
 power_reg_failed_1:
@@ -747,6 +821,10 @@ static int __devexit platform_pmic_batte
 {
 	struct pmic_power_module_info *pbi = dev_get_drvdata(&pdev->dev);
 
+#ifdef CONFIG_DEBUG_FS
+	cleanup_battery_debugfs(pbi);
+#endif
+
 	free_irq(pbi->irq, pbi);
 	free_irq(pbi->adap_irq, pbi);
 	cancel_rearming_delayed_workqueue(pbi->monitor_wqueue,
