Hey,

due line wrapping issues with kmail I'm sending these patches attachment. The 
main goal is to send an uevent whenever something changes that might changed 
the battery charging state. So the good thing is we do send out changes, the 
bad thing is when someone in userspace will go to /sys/class/power/foo/state 
it will not say charging. So either the battery takes time to report to us or 
we cached the HDQ state of the battery and need to flush it?

Anyway here is the patchset:

Holger Freyther (5):
      [bq27000] Make the checkpatch.pl happy
      [janitor] Make checkpatch happy on the header files
      [janitor] make checkpatch.pl happy
      [battery] Make the bq27000 send an uevent when the charging state 
possible changed
      [pcf50633] Report more events to userspace using the default callback


 arch/arm/mach-s3c2440/mach-gta02.c |   36 
+++++++++++++++++++-----------------
 drivers/i2c/chips/pcf50606.c       |   25 ++++++++++++++-----------
 drivers/i2c/chips/pcf50633.c       |   24 +++++++++++++++---------
 drivers/power/bq27000_battery.c    |   18 ++++++++++++++++--
 include/linux/bq27000_battery.h    |    2 ++
 include/linux/pcf50606.h           |    2 +-
 include/linux/pcf50633.h           |    2 +-
 include/linux/pcf506xx.h           |    3 ++-
 8 files changed, 70 insertions(+), 42 deletions(-)

From ae3f72fc608fcd0a98a980a335ac4dc7ad95b221 Mon Sep 17 00:00:00 2001
From: Holger Freyther <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 12:12:20 +0200
Subject: [PATCH] [bq27000] Make the checkpatch.pl happy

---
 drivers/power/bq27000_battery.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/power/bq27000_battery.c b/drivers/power/bq27000_battery.c
index 4511e9c..c87e26d 100644
--- a/drivers/power/bq27000_battery.c
+++ b/drivers/power/bq27000_battery.c
@@ -179,7 +179,9 @@ static int bq27000_battery_get_property(struct power_supply *psy,
 		v = hdq_read16(di, BQ27000_AI_L);
 		if (v < 0)
 			return v;
-		if (v < 2) { /* no real activity on the battery */
+
+		/* no real activity on the battery */
+		if (v < 2) {
 			if (!hdq_read16(di, BQ27000_TTF_L))
 				val->intval = POWER_SUPPLY_STATUS_FULL;
 			else
@@ -199,7 +201,8 @@ static int bq27000_battery_get_property(struct power_supply *psy,
 		v = hdq_read16(di, BQ27000_VOLT_L);
 		if (v < 0)
 			return v;
-		val->intval = v * 1000; /* mV -> uV */
+		/* mV -> uV */
+		val->intval = v * 1000;
 		break;
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		v = (di->hdq_read)(BQ27000_FLAGS);
-- 
1.5.4.3

From 5718bde77ed1a75e0fd2cdf5e099e66121d10c0a Mon Sep 17 00:00:00 2001
From: Holger Freyther <[EMAIL PROTECTED]>
Date: Wed, 4 Jun 2008 18:00:41 +0200
Subject: [PATCH] [battery] Make the bq27000 send an uevent when the charging state possible changed
     Remove the todo entries from the pcf50633, make the mach-gta02
     call the bq27000 driver from the pmu callback.

---
 arch/arm/mach-s3c2440/mach-gta02.c |   36 +++++++++++++++++++-----------------
 drivers/i2c/chips/pcf50633.c       |    4 ----
 drivers/power/bq27000_battery.c    |   11 +++++++++++
 include/linux/bq27000_battery.h    |    2 ++
 4 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
index 1eaa0c1..827f68f 100644
--- a/arch/arm/mach-s3c2440/mach-gta02.c
+++ b/arch/arm/mach-s3c2440/mach-gta02.c
@@ -456,6 +456,24 @@ static struct s3c2410_uartcfg gta02_uartcfgs[] = {
 
 };
 
+/* BQ27000 Battery */
+
+struct bq27000_platform_data bq27000_pdata = {
+	.name = "bat",
+	.rsense_mohms = 20,
+	.hdq_read = gta02hdq_read,
+	.hdq_write = gta02hdq_write,
+	.hdq_initialized = gta02hdq_initialized,
+};
+
+struct platform_device bq27000_battery_device = {
+	.name 		= "bq27000-battery",
+	.dev = {
+		.platform_data = &bq27000_pdata,
+	},
+};
+
+
 /* PMU driver info */
 
 static int pmu_callback(struct device *dev, unsigned int feature,
@@ -488,6 +506,7 @@ static int pmu_callback(struct device *dev, unsigned int feature,
 		break;
 	}
 
+	bq27000_charging_state_change(&bq27000_battery_device);
 	return 0;
 }
 
@@ -746,23 +765,6 @@ struct platform_device gta02_hdq_device = {
 };
 #endif
 
-/* BQ27000 Battery */
-
-struct bq27000_platform_data bq27000_pdata = {
-	.name = "bat",
-	.rsense_mohms = 20,
-	.hdq_read = gta02hdq_read,
-	.hdq_write = gta02hdq_write,
-	.hdq_initialized = gta02hdq_initialized,
-};
-
-struct platform_device bq27000_battery_device = {
-	.name 		= "bq27000-battery",
-	.dev = {
-		.platform_data = &bq27000_pdata,
-	},
-};
-
 
 /* NOR Flash */
 
diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
index 4d19dae..8a27925 100644
--- a/drivers/i2c/chips/pcf50633.c
+++ b/drivers/i2c/chips/pcf50633.c
@@ -888,8 +888,6 @@ static void pcf50633_work(struct work_struct *work)
 		if (pcf->pdata->cb)
 			pcf->pdata->cb(&pcf->client.dev,
 				       PCF50633_FEAT_MBC, PMU_EVT_INSERT);
-		/* FIXME: signal this to userspace */
-		//kobject_uevent( ,KOBJ_ADD);
 	}
 	if (pcfirq[0] & PCF50633_INT1_ADPREM) {
 		/* Charger removed */
@@ -900,8 +898,6 @@ static void pcf50633_work(struct work_struct *work)
 		if (pcf->pdata->cb)
 			pcf->pdata->cb(&pcf->client.dev,
 				       PCF50633_FEAT_MBC, PMU_EVT_REMOVE);
-		/* FIXME: signal this to userspace */
-		//kobject_uevent( ,KOBJ_ADD);
 	}
 	if (pcfirq[0] & PCF50633_INT1_USBINS) {
 		DEBUGPC("USBINS ");
diff --git a/drivers/power/bq27000_battery.c b/drivers/power/bq27000_battery.c
index c87e26d..4855d5a 100644
--- a/drivers/power/bq27000_battery.c
+++ b/drivers/power/bq27000_battery.c
@@ -330,6 +330,17 @@ static int bq27000_battery_remove(struct platform_device *pdev)
 	return 0;
 }
 
+void bq27000_charging_state_change(struct platform_device *pdev)
+{
+	struct bq27000_device_info *di = platform_get_drvdata(pdev);
+
+	if (!di)
+	    return;
+
+	power_supply_changed(&di->bat);
+}
+EXPORT_SYMBOL_GPL(bq27000_charging_state_change);
+
 #ifdef CONFIG_PM
 
 static int bq27000_battery_suspend(struct platform_device *pdev,
diff --git a/include/linux/bq27000_battery.h b/include/linux/bq27000_battery.h
index 36b4f20..fed4287 100644
--- a/include/linux/bq27000_battery.h
+++ b/include/linux/bq27000_battery.h
@@ -1,6 +1,8 @@
 #ifndef __BQ27000_BATTERY_H__
 #define __BQ27000_BATTERY_H__
 
+void bq27000_charging_state_change(struct platform_device *pdev);
+
 struct bq27000_platform_data {
 	const char 	*name;
 	int		rsense_mohms;
-- 
1.5.4.3

From 683ef8067815f6ba0ede73fa71973823726213a3 Mon Sep 17 00:00:00 2001
From: Holger Freyther <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 12:27:36 +0200
Subject: [PATCH] [janitor] Make checkpatch happy on the header files

---
 include/linux/pcf50606.h |    2 +-
 include/linux/pcf50633.h |    2 +-
 include/linux/pcf506xx.h |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/pcf50606.h b/include/linux/pcf50606.h
index 167328f..b17d35b 100644
--- a/include/linux/pcf50606.h
+++ b/include/linux/pcf50606.h
@@ -85,7 +85,7 @@ struct pcf50606_platform_data {
 	struct {
 		u_int8_t mbcc3; /* charger voltage / current */
 	} charger;
-	pmu_cb *cb;
+	pmu_cb cb;
 };
 
 #endif
diff --git a/include/linux/pcf50633.h b/include/linux/pcf50633.h
index 4653285..b4d65dc 100644
--- a/include/linux/pcf50633.h
+++ b/include/linux/pcf50633.h
@@ -176,7 +176,7 @@ struct pcf50633_platform_data {
 	struct {
 		u_int8_t mbcc3; /* charger voltage / current */
 	} charger;
-	pmu_cb *cb;
+	pmu_cb cb;
 
 	/* post-resume backlight bringup */
 	int defer_resume_backlight;
diff --git a/include/linux/pcf506xx.h b/include/linux/pcf506xx.h
index 9069bd4..a1365e0 100644
--- a/include/linux/pcf506xx.h
+++ b/include/linux/pcf506xx.h
@@ -26,7 +26,7 @@ enum pmu_event {
 	__NUM_PMU_EVTS
 };
 
-typedef int pmu_cb(struct device *dev, unsigned int feature,
+typedef int (*pmu_cb)(struct device *dev, unsigned int feature,
 		   enum pmu_event event);
 
 
-- 
1.5.4.3

From 000450f1ad2c713d2345a872fdf44f5dd3702e1b Mon Sep 17 00:00:00 2001
From: Holger Freyther <[EMAIL PROTECTED]>
Date: Thu, 29 May 2008 14:53:58 +0200
Subject: [PATCH] [janitor] make checkpatch.pl happy

---
 drivers/i2c/chips/pcf50606.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/chips/pcf50606.c b/drivers/i2c/chips/pcf50606.c
index aa841e3..ddba1c7 100644
--- a/drivers/i2c/chips/pcf50606.c
+++ b/drivers/i2c/chips/pcf50606.c
@@ -79,12 +79,12 @@ I2C_CLIENT_INSMOD_1(pcf50606);
 #define PCF50606_B_CHG_PROT	4	/* Charger Protection */
 #define PCF50606_B_CHG_READY	5	/* Charging completed */
 
-#define PCF50606_F_CHG_FAST	(1<<PCF50606_B_CHG_FAST)	/* Charger Fast allowed */
-#define PCF50606_F_CHG_PRESENT	(1<<PCF50606_B_CHG_PRESENT)	/* Charger present */
-#define PCF50606_F_CHG_FOK	(1<<PCF50606_B_CHG_FOK)	/* Fast OK for battery */
-#define PCF50606_F_CHG_ERR	(1<<PCF50606_B_CHG_ERR)	/* Charger Error */
-#define PCF50606_F_CHG_PROT	(1<<PCF50606_B_CHG_PROT)	/* Charger Protection */
-#define PCF50606_F_CHG_READY	(1<<PCF50606_B_CHG_READY)	/* Charging completed */
+#define PCF50606_F_CHG_FAST	(1<<PCF50606_B_CHG_FAST)
+#define PCF50606_F_CHG_PRESENT	(1<<PCF50606_B_CHG_PRESENT)
+#define PCF50606_F_CHG_FOK	(1<<PCF50606_B_CHG_FOK)
+#define PCF50606_F_CHG_ERR	(1<<PCF50606_B_CHG_ERR)
+#define PCF50606_F_CHG_PROT	(1<<PCF50606_B_CHG_PROT)
+#define PCF50606_F_CHG_READY	(1<<PCF50606_B_CHG_READY)
 #define PCF50606_F_CHG_MASK	0x000000fc
 
 #define PCF50606_F_PWR_PRESSED	0x00000100
@@ -598,7 +598,8 @@ static void pcf50606_work(struct work_struct *work)
 			pcf->flags |= PCF50606_F_CHG_PRESENT;
 			if (pcf->pdata->cb)
 				pcf->pdata->cb(&pcf->client.dev,
-					PCF50606_FEAT_MBC, PMU_EVT_INSERT);
+						PCF50606_FEAT_MBC,
+						PMU_EVT_INSERT);
 		}
 
 		pcf->coldplug_done = 1;
@@ -988,7 +989,8 @@ EXPORT_SYMBOL_GPL(pcf50606_charge_fast);
 
 static inline u_int16_t adc_to_rntc(struct pcf50606_data *pcf, u_int16_t adc)
 {
-	u_int32_t r_ntc = (adc * (u_int32_t)pcf->pdata->r_fix_batt) / (1023 - adc);
+	u_int32_t r_ntc = (adc * (u_int32_t)pcf->pdata->r_fix_batt)
+		/ (1023 - adc);
 
 	return r_ntc;
 }
@@ -1290,8 +1292,9 @@ static int pcf50606_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
 	struct pcf50606_time pcf_tm;
 
 	mutex_lock(&pcf->lock);
-	alrm->enabled = 
-             __reg_read(pcf, PCF50606_REG_INT1M) & PCF50606_INT1_ALARM ? 0 : 1;
+	alrm->enabled =
+		__reg_read(pcf, PCF50606_REG_INT1M) & PCF50606_INT1_ALARM
+		? 0 : 1;
 	pcf_tm.sec = __reg_read(pcf, PCF50606_REG_RTCSCA);
 	pcf_tm.min = __reg_read(pcf, PCF50606_REG_RTCMNA);
 	pcf_tm.hour = __reg_read(pcf, PCF50606_REG_RTCHRA);
@@ -1665,7 +1668,7 @@ static int pcf50606_detect(struct i2c_adapter *adapter, int address, int kind)
 		return -ENOMEM;
 
 	mutex_init(&data->lock);
- 	mutex_init(&data->working_lock);
+	mutex_init(&data->working_lock);
 	INIT_WORK(&data->work, pcf50606_work);
 	data->irq = irq;
 	data->working = 0;
-- 
1.5.4.3

From c221bb27c8e22daa451e26353140777223d397d2 Mon Sep 17 00:00:00 2001
From: Holger Freyther <[EMAIL PROTECTED]>
Date: Tue, 1 Jul 2008 20:11:20 +0200
Subject: [PATCH] [pcf50633] Report more events to userspace using the default callback

Signed-Off-By: Holger Freyther <[EMAIL PROTECTED]>
---
 drivers/i2c/chips/pcf50633.c |   20 +++++++++++++++-----
 include/linux/pcf506xx.h     |    1 +
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
index 8a27925..10934f7 100644
--- a/drivers/i2c/chips/pcf50633.c
+++ b/drivers/i2c/chips/pcf50633.c
@@ -1037,25 +1037,35 @@ static void pcf50633_work(struct work_struct *work)
 		 * this is really "battery not pulling current" -- it can
 		 * appear with no battery attached
 		 */
-		/* FIXME: signal this to userspace */
+		if (pcf->pdata->cb)
+			pcf->pdata->cb(&pcf->client.dev,
+				       PCF50633_FEAT_MBC, PMU_EVT_CHARGER_CHANGE);
 	}
 	if (pcfirq[2] & PCF50633_INT3_THLIMON) {
 		DEBUGPC("THLIMON ");
 		pcf->flags |= PCF50633_F_CHG_PROT;
-		/* FIXME: signal this to userspace */
+		if (pcf->pdata->cb)
+			pcf->pdata->cb(&pcf->client.dev,
+				       PCF50633_FEAT_MBC, PMU_EVT_CHARGER_CHANGE);
 	}
 	if (pcfirq[2] & PCF50633_INT3_THLIMOFF) {
 		DEBUGPC("THLIMOFF ");
 		pcf->flags &= ~PCF50633_F_CHG_PROT;
-		/* FIXME: signal this to userspace */
+		if (pcf->pdata->cb)
+			pcf->pdata->cb(&pcf->client.dev,
+				       PCF50633_FEAT_MBC, PMU_EVT_CHARGER_CHANGE);
 	}
 	if (pcfirq[2] & PCF50633_INT3_USBLIMON) {
 		DEBUGPC("USBLIMON ");
-		/* FIXME: signal this to userspace */
+		if (pcf->pdata->cb)
+			pcf->pdata->cb(&pcf->client.dev,
+				       PCF50633_FEAT_MBC, PMU_EVT_CHARGER_CHANGE);
 	}
 	if (pcfirq[2] & PCF50633_INT3_USBLIMOFF) {
 		DEBUGPC("USBLIMOFF ");
-		/* FIXME: signal this to userspace */
+		if (pcf->pdata->cb)
+			pcf->pdata->cb(&pcf->client.dev,
+				       PCF50633_FEAT_MBC, PMU_EVT_CHARGER_CHANGE);
 	}
 	if (pcfirq[2] & PCF50633_INT3_ADCRDY) {
 		/* ADC result ready */
diff --git a/include/linux/pcf506xx.h b/include/linux/pcf506xx.h
index a1365e0..459b160 100644
--- a/include/linux/pcf506xx.h
+++ b/include/linux/pcf506xx.h
@@ -23,6 +23,7 @@ enum pmu_event {
 #endif
 	PMU_EVT_CHARGER_ACTIVE,
 	PMU_EVT_CHARGER_IDLE,
+	PMU_EVT_CHARGER_CHANGE,
 	__NUM_PMU_EVTS
 };
 
-- 
1.5.4.3

Reply via email to