[PATCH 2/3] PMU and Battery interaction in regard to kobject uevent

Holger Freyther zecke at openmoko.org
Tue Jun 3 11:23:31 CEST 2008


From a93cc5dd0796c9d6d7b57b4896a6e44b2cbdb917 Mon Sep 17 00:00:00 2001
From: Holger Freyther <zecke at openmoko.org>
Date: Thu, 29 May 2008 01:25:44 +0200
Subject: [PATCH] [pmu] Only use the pmu_cb, kill the _event_handler

---
 arch/arm/mach-s3c2410/mach-gta01.c |    2 +-
 arch/arm/mach-s3c2440/mach-gta02.c |    2 +-
 drivers/i2c/chips/pcf50606.c       |   10 ++++----
 drivers/i2c/chips/pcf50633.c       |   38 +++++++++++++----------------------
 drivers/power/bq27000_battery.c    |    5 ++-
 include/linux/pcf50633.h           |   12 +---------
 include/linux/pcf506xx.h           |    2 +-
 7 files changed, 27 insertions(+), 44 deletions(-)

diff --git a/arch/arm/mach-s3c2410/mach-gta01.c 
b/arch/arm/mach-s3c2410/mach-gta01.c
index a77ed3d..5027dd9 100644
--- a/arch/arm/mach-s3c2410/mach-gta01.c
+++ b/arch/arm/mach-s3c2410/mach-gta01.c
@@ -108,7 +108,7 @@ static struct s3c2410_uartcfg gta01_uartcfgs[] = {
 /* PMU driver info */
 
 static int pmu_callback(struct device *dev, unsigned int feature,
-			enum pmu_event event)
+			enum pmu_event event, void *data)
 {
 	switch (feature) {
 	case PCF50606_FEAT_ACD:
diff --git a/arch/arm/mach-s3c2440/mach-gta02.c 
b/arch/arm/mach-s3c2440/mach-gta02.c
index 601f7bc..e7bc38f 100644
--- a/arch/arm/mach-s3c2440/mach-gta02.c
+++ b/arch/arm/mach-s3c2440/mach-gta02.c
@@ -424,7 +424,7 @@ static struct s3c2410_uartcfg gta02_uartcfgs[] = {
 /* PMU driver info */
 
 static int pmu_callback(struct device *dev, unsigned int feature,
-			enum pmu_event event)
+			enum pmu_event event, void *data)
 {
 	switch (feature) {
 	case PCF50633_FEAT_MBC:
diff --git a/drivers/i2c/chips/pcf50606.c b/drivers/i2c/chips/pcf50606.c
index aa841e3..6d48111 100644
--- a/drivers/i2c/chips/pcf50606.c
+++ b/drivers/i2c/chips/pcf50606.c
@@ -598,7 +598,7 @@ 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, NULL);
 		}
 
 		pcf->coldplug_done = 1;
@@ -695,7 +695,7 @@ 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, NULL);
 		/* FIXME: how to signal this to userspace */
 	}
 	if (pcfirq[1] & PCF50606_INT2_CHGRM) {
@@ -706,7 +706,7 @@ static void pcf50606_work(struct work_struct *work)
 		pcf->flags &= ~(PCF50606_F_CHG_MASK|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, NULL);
 		/* FIXME: how signal this to userspace */
 	}
 	if (pcfirq[1] & PCF50606_INT2_CHGFOK) {
@@ -757,14 +757,14 @@ static void pcf50606_work(struct work_struct *work)
 		DEBUGPC("ACDINS ");
 		if (pcf->pdata->cb)
 			pcf->pdata->cb(&pcf->client.dev,
-				       PCF50606_FEAT_ACD, PMU_EVT_INSERT);
+				       PCF50606_FEAT_ACD, PMU_EVT_INSERT, NULL);
 	}
 	if (pcfirq[2] & PCF50606_INT3_ACDREM) {
 		/* Accessory removal detected */
 		DEBUGPC("ACDREM ");
 		if (pcf->pdata->cb)
 			pcf->pdata->cb(&pcf->client.dev,
-				       PCF50606_FEAT_ACD, PMU_EVT_REMOVE);
+				       PCF50606_FEAT_ACD, PMU_EVT_REMOVE, NULL);
 	}
 	/* FIXME: TSCPRES */
 	if (pcfirq[2] & PCF50606_INT3_LOWBAT) {
diff --git a/drivers/i2c/chips/pcf50633.c b/drivers/i2c/chips/pcf50633.c
index 2e5d3ff..ce476a4 100644
--- a/drivers/i2c/chips/pcf50633.c
+++ b/drivers/i2c/chips/pcf50633.c
@@ -157,7 +157,7 @@ struct pcf50633_data {
 };
 
 struct pcf50633_event_handler_data {
-	pcf50633_event_handler handler;
+	pmu_cb *handler;
 	void *data;
 	struct list_head entry;
 };
@@ -472,18 +472,22 @@ void pcf50633_go_standby(void)
 }
 EXPORT_SYMBOL_GPL(pcf50633_go_standby);
 
-static void pcf50633_report_event(struct pcf50633_data *pcf, enum 
pcf50633_plug_event event, int plug)
+static void pcf50633_report_event(struct pcf50633_data *pcf, unsigned int 
feature,
+			enum pmu_event event)
 {
 	struct list_head *element;
 
+	if (pcf->pdata->cb)
+		pcf->pdata->cb(&pcf->client.dev, feature, event, NULL);
+
 	list_for_each(element, &pcf->event_handler) {
 	    struct pcf50633_event_handler_data *event_data = 
 				container_of(element, struct pcf50633_event_handler_data, entry);
-	    (*event_data->handler)(pcf, event, plug, event_data->data);
+	    (*event_data->handler)(&pcf->client.dev, feature, event, 
event_data->data);
 	}
 }
 
-void pcf50633_add_event_handler(struct pcf50633_data *pcf, 
pcf50633_event_handler handler, void *token)
+void pcf50633_add_event_handler(struct pcf50633_data *pcf, pmu_cb *handler, 
void *token)
 {
 	struct pcf50633_event_handler_data *data;
 
@@ -498,7 +502,7 @@ void pcf50633_add_event_handler(struct pcf50633_data *pcf, 
pcf50633_event_handle
 }
 EXPORT_SYMBOL_GPL(pcf50633_add_event_handler);
 
-void pcf50633_remove_event_handler(struct pcf50633_data *pcf, 
pcf50633_event_handler _handler)
+void pcf50633_remove_event_handler(struct pcf50633_data *pcf, pmu_cb 
*_handler)
 {
 	struct list_head *element;
 
@@ -678,9 +682,7 @@ static void pcf50633_work(struct work_struct *work)
 			input_report_key(pcf->input_dev, KEY_POWER2, 1);
 			apm_queue_event(APM_POWER_STATUS_CHANGE);
 			pcf->flags |= PCF50633_F_USB_PRESENT;
-			if (pcf->pdata->cb)
-				pcf->pdata->cb(&pcf->client.dev,
-					PCF50633_FEAT_MBC, PMU_EVT_USB_INSERT);
+			pcf50633_report_event(pcf, PCF50633_FEAT_MBC, PMU_EVT_USB_INSERT);
 		}
 
 		/* figure out our initial charging stance */
@@ -699,10 +701,7 @@ static void pcf50633_work(struct work_struct *work)
 		input_report_key(pcf->input_dev, KEY_BATTERY, 1);
 		apm_queue_event(APM_POWER_STATUS_CHANGE);
 		pcf->flags |= PCF50633_F_CHG_PRESENT;
-		if (pcf->pdata->cb)
-			pcf->pdata->cb(&pcf->client.dev,
-				       PCF50633_FEAT_MBC, PMU_EVT_INSERT);
-		pcf50633_report_event(pcf, PCF50633_PLUG_EVENT_CHARGER, 1);
+		pcf50633_report_event(pcf, PCF50633_FEAT_MBC, PMU_EVT_INSERT);
 	}
 	if (pcfirq[0] & PCF50633_INT1_ADPREM) {
 		/* Charger removed */
@@ -710,23 +709,17 @@ static void pcf50633_work(struct work_struct *work)
 		input_report_key(pcf->input_dev, KEY_BATTERY, 0);
 		apm_queue_event(APM_POWER_STATUS_CHANGE);
 		pcf->flags &= ~PCF50633_F_CHG_PRESENT;
-		if (pcf->pdata->cb)
-			pcf->pdata->cb(&pcf->client.dev,
-				       PCF50633_FEAT_MBC, PMU_EVT_REMOVE);
-		pcf50633_report_event(pcf, PCF50633_PLUG_EVENT_CHARGER, 0);
+		pcf50633_report_event(pcf, PCF50633_FEAT_MBC, PMU_EVT_REMOVE);
 	}
 	if (pcfirq[0] & PCF50633_INT1_USBINS) {
 		DEBUGPC("USBINS ");
 		input_report_key(pcf->input_dev, KEY_POWER2, 1);
 		apm_queue_event(APM_POWER_STATUS_CHANGE);
 		pcf->flags |= PCF50633_F_USB_PRESENT;
-		if (pcf->pdata->cb)
-			pcf->pdata->cb(&pcf->client.dev,
-				       PCF50633_FEAT_MBC, PMU_EVT_USB_INSERT);
+		pcf50633_report_event(pcf, PCF50633_FEAT_MBC, PMU_EVT_USB_INSERT);
 		/* completion irq will figure out our charging stance */
 		add_request_to_adc_queue(pcf, PCF50633_ADCC1_MUX_ADCIN1,
 				     PCF50633_ADCC1_AVERAGE_16);
-		pcf50633_report_event(pcf, PCF50633_PLUG_EVENT_USB, 1);
 	}
 	if (pcfirq[0] & PCF50633_INT1_USBREM) {
 		DEBUGPC("USBREM ");
@@ -735,13 +728,10 @@ static void pcf50633_work(struct work_struct *work)
 			input_report_key(pcf->input_dev, KEY_POWER2, 0);
 			apm_queue_event(APM_POWER_STATUS_CHANGE);
 			pcf->flags &= ~PCF50633_F_USB_PRESENT;
-			if (pcf->pdata->cb)
-				pcf->pdata->cb(&pcf->client.dev,
-					PCF50633_FEAT_MBC, PMU_EVT_USB_REMOVE);
+			pcf50633_report_event(pcf, PCF50633_FEAT_MBC, PMU_EVT_USB_REMOVE);
 			/* completion irq will figure out our charging stance */
 			add_request_to_adc_queue(pcf, PCF50633_ADCC1_MUX_ADCIN1,
 					PCF50633_ADCC1_AVERAGE_16);
-			pcf50633_report_event(pcf, PCF50633_PLUG_EVENT_USB, 0);
 		}
 	}
 	if (pcfirq[0] & PCF50633_INT1_ALARM) {
diff --git a/drivers/power/bq27000_battery.c b/drivers/power/bq27000_battery.c
index 8b7f81c..8f81f2b 100644
--- a/drivers/power/bq27000_battery.c
+++ b/drivers/power/bq27000_battery.c
@@ -122,12 +122,13 @@ struct bq27000_device_info {
 	int (*hdq_write)(int, u8); /* from platform */
 };
 
-static void bq2700_battery_event_handler(struct pcf50633_data *data,
-	    enum pcf50633_plug_event event, int insert, void *di)
+static int bq2700_battery_event_handler(struct device *dev,
+	    unsigned int feature, enum pmu_event event, void *di)
 {
 	struct bq27000_device_info *device = (struct bq27000_device_info *)di;
 
 	kobject_uevent(&device->bat.dev->kobj, KOBJ_CHANGE);
+	return 0;
 }
 
 /*
diff --git a/include/linux/pcf50633.h b/include/linux/pcf50633.h
index cc551c1..c35a18e 100644
--- a/include/linux/pcf50633.h
+++ b/include/linux/pcf50633.h
@@ -20,11 +20,6 @@ enum pcf50633_regulator_id {
 	__NUM_PCF50633_REGULATORS
 };
 
-enum pcf50633_plug_event {
-	PCF50633_PLUG_EVENT_CHARGER,
-	PCF50633_PLUG_EVENT_USB
-};
-
 enum pcf50633_reg_int1 {
 	PCF50633_INT1_ADPINS	= 0x01,	/* Adapter inserted */
 	PCF50633_INT1_ADPREM	= 0x02,	/* Adapter removed */
@@ -82,9 +77,6 @@ enum pcf50633_reg_int5 {
 struct pcf50633_data;
 extern struct pcf50633_data *pcf50633_global;
 
-typedef void (*pcf50633_event_handler)(struct pcf50633_data *data,
-		enum pcf50633_plug_event event, int insert, void *token);
-
 extern void
 pcf50633_go_standby(void);
 
@@ -133,10 +125,10 @@ extern int
 pcf50633_report_resumers(struct pcf50633_data *pcf, char *buf);
 
 extern void
-pcf50633_add_event_handler(struct pcf50633_data *pcf, pcf50633_event_handler 
handler, void *data);
+pcf50633_add_event_handler(struct pcf50633_data *pcf, pmu_cb* cb, void 
*data);
 
 extern void
-pcf50633_remove_event_handler(struct pcf50633_data *pcf, 
pcf50633_event_handler handler);
+pcf50633_remove_event_handler(struct pcf50633_data *pcf, pmu_cb* cbr);
 
 
 #define PCF50633_FEAT_EXTON	0x00000001	/* not yet supported */
diff --git a/include/linux/pcf506xx.h b/include/linux/pcf506xx.h
index 33be73e..d31bd14 100644
--- a/include/linux/pcf506xx.h
+++ b/include/linux/pcf506xx.h
@@ -25,7 +25,7 @@ enum pmu_event {
 };
 
 typedef int pmu_cb(struct device *dev, unsigned int feature,
-		   enum pmu_event event);
+		   enum pmu_event event, void *data);
 
 
 #endif /* !_LINUX_PCF506XX_H */
-- 
1.5.4.3





More information about the openmoko-kernel mailing list