Skip to contentSkip to conversation

power_supply : Introduce battery identification framework

PATCH In review Jenny TC 1 participant 2 messages Oct 12, 2012 – Oct 18, 2012 Power supply

lore
Share & tools
lore

Jenny TC

author
#0 lore raw

PATCH v2 1/1 power_supply : Introduce battery identification framework

This patch introduces generic battid framework. Different battid drivers sitting on different linux kernel subsystem (1wire, I2C, SFI etc) can interface with the power supply susbsytem using the APIs exposed in the power supply usbsystem. The consumers (charger driver/battery driver/power management drivers) can register for notification from the battery id drivers using the APIs from this framework

---
V1: Submitted the initialcode
V2:
Added file headers

 drivers/power/Kconfig            |    8 ++++
 drivers/power/Makefile           |    1 +
 drivers/power/battery_id.c       |   94 ++++++++++++++++++++++++++++++++++++++
 include/linux/power/battery_id.h |   50 ++++++++++++++++++++
 4 files changed, 153 insertions(+)
 create mode 100644 drivers/power/battery_id.c
 create mode 100644 include/linux/power/battery_id.h
drivers/power/Kconfig +8 -0
index 49a8939..74b297d 100644
@@ -8,6 +8,14 @@ menuconfig POWER_SUPPLY
 
 if POWER_SUPPLY
 
+config POWER_SUPPLY_BATTID
+	bool "Power Supply Battery Identification Framework"
+	help
+	 Say Y here to enable the power supply battery idnetification
+	 framework. The framework would allow different battery identification
+	 drivers to interface with power supply subsystem. Also it allows consumer
+	 drivers to register for notification from the power_supply subsystem.
+
 config POWER_SUPPLY_DEBUG
 	bool "Power supply debug"
 	help
drivers/power/Makefile +1 -0
index b949cf8..6a63f45 100644
@@ -3,6 +3,7 @@ ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG
 power_supply-y				:= power_supply_core.o
 power_supply-$(CONFIG_SYSFS)		+= power_supply_sysfs.o
 power_supply-$(CONFIG_LEDS_TRIGGERS)	+= power_supply_leds.o
+power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o
 
 obj-$(CONFIG_POWER_SUPPLY)	+= power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)	+= generic-adc-battery.o
drivers/power/battery_id.c new file +94 -0

94 lines not on this page · raw message

include/linux/power/battery_id.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#1 lore raw

Anton,

Please ignore this patch. I submitted this as part of charging framework.

-jtc

Quoted 248 lines

-----Original Message-----
From: [email protected] [mailto:linux-kernel- [email protected]] On Behalf Of Jenny TC
Sent: Friday, October 12, 2012 10:13 PM
To: Anton Vorontsov; Anton Vorontsov; [email protected]; linux- [email protected]
Cc: Tc, Jenny; David Rajamanickam, Ajay Thomas; Pallala, Ramakrishna
Subject: [PATCH V2] power_supply : Introduce battery identification framework

This patch introduces generic battid framework. Different battid drivers sitting on different linux kernel subsystem (1wire, I2C, SFI etc) can interface with the power supply susbsytem using the APIs exposed in the power supply usbsystem. The consumers (charger driver/battery driver/power management drivers) can register for notification from the battery id drivers using the APIs from this framework

---
V1: Submitted the initialcode
V2:
Added file headers

 drivers/power/Kconfig            |    8 ++++
 drivers/power/Makefile           |    1 +
 drivers/power/battery_id.c       |   94
++++++++++++++++++++++++++++++++++++++
 include/linux/power/battery_id.h |   50 ++++++++++++++++++++
 4 files changed, 153 insertions(+)
 create mode 100644 drivers/power/battery_id.c  create mode 100644

include/linux/power/battery_id.h

drivers/power/Kconfig index renamed from drivers/power/Kconfig +0 -0

49a8939..74b297d 100644

drivers/power/Kconfig +5 -0
@@ -8,6 +8,14 @@ menuconfig POWER_SUPPLY
 
 if POWER_SUPPLY
 
+config POWER_SUPPLY_BATTID
+	bool "Power Supply Battery Identification Framework"
+	help
+	 Say Y here to enable the power supply battery idnetification
+	 framework. The framework would allow different battery

identification

drivers/power/Kconfig +1 -0
+	 drivers to interface with power supply subsystem. Also it allows

consumer

drivers/power/Kconfig +1 -0
+	 drivers to register for notification from the power_supply

subsystem.

drivers/power/Kconfig +1 -0
+
 config POWER_SUPPLY_DEBUG
 	bool "Power supply debug"
 	help
drivers/power/Makefile index renamed from drivers/power/Makefile +0 -0

b949cf8..6a63f45 100644

drivers/power/Makefile +1 -0
@@ -3,6 +3,7 @@ ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG
 power_supply-y				:= power_supply_core.o
 power_supply-$(CONFIG_SYSFS)		+= power_supply_sysfs.o
 power_supply-$(CONFIG_LEDS_TRIGGERS)	+= power_supply_leds.o
+power_supply-$(CONFIG_POWER_SUPPLY_BATTID) += battery_id.o
 
 obj-$(CONFIG_POWER_SUPPLY)	+= power_supply.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)	+= generic-adc-battery.o
drivers/power/battery_id.c new file renamed from drivers/power/battery_id.c +0 -0

mode 100644 index 0000000..f6160b6

drivers/power/battery_id.c new file +7 -0
@@ -0,0 +1,94 @@
+/*
+ * battery_id.c - Power supply battery identification framework
+ *
+ * Copyright (C) 2012 Intel Corporation
+ *
+ *
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~
+~~~
+ *
+ * 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; version 2 of the License.
+ *
+ * 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

drivers/power/battery_id.c new file +7 -0
+along
+ * with this program; if not, write to the Free Software Foundation,
+Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ *
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~
+~~~
+ * Author: Jenny TC <[email protected]>
+ * Author: David Rajamanickam, Ajay Thomas
+ * <[email protected]>
+ */

drivers/power/battery_id.c new file +23 -0
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/notifier.h>
+#include <linux/power/battery_id.h>
+
+ATOMIC_NOTIFIER_HEAD(batt_id_notifier);
+
+static struct ps_batt_chg_prof *batt_property; static int batt_status;
+
+int batt_id_reg_notifier(struct notifier_block *nb) {
+	return atomic_notifier_chain_register(&batt_id_notifier, nb); }
+EXPORT_SYMBOL_GPL(batt_id_reg_notifier);
+
+void batt_id_unreg_notifier(struct notifier_block *nb) {
+	atomic_notifier_chain_unregister(&batt_id_notifier, nb); }
+EXPORT_SYMBOL_GPL(batt_id_unreg_notifier);
+
+
+/**
+ * battery_prop_changed - Update properties when  battery connection

status
+ * changes
+ * @battery_conn_stat : The current connection status of battery
+ * @batt_prop : Address of the ps_batt_chg_prof structure with the updated
+ * values passed from the calling function
+ *
+ * Whenever the battery connection status changes this function will be

drivers/power/battery_id.c new file +10 -0
+called
+ * to indicate a change in the status and to update the status and
+value of
+ * properties
+ */
+void battery_prop_changed(int battery_conn_stat,
+			struct ps_batt_chg_prof *batt_prop)
+{
+	if (batt_status != battery_conn_stat) {
+		if (battery_conn_stat ==

POWER_SUPPLY_BATTERY_INSERTED)

drivers/power/battery_id.c new file +26 -0
+			batt_property = batt_prop;
+		else
+			batt_property = NULL;
+
+		batt_status = battery_conn_stat;
+	}
+
+	atomic_notifier_call_chain(&batt_id_notifier,
+			0, &(batt_property));
+
+}
+EXPORT_SYMBOL_GPL(battery_prop_changed);
+
+/**
+ * get_batt_prop - Get the battery connection status and updated
+properties
+ * @batt_prop : battery properties structure copied to this address  */
+int get_batt_prop(struct ps_batt_chg_prof *batt_prop) {
+	if (batt_property)
+		memcpy(batt_prop, batt_property,
+			sizeof(struct ps_batt_chg_prof));
+	else
+		return -ENOMEM;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(get_batt_prop);
include/linux/power/battery_id.h new file +8 -0
new file mode 100644
index 0000000..9a4832e
@@ -0,0 +1,50 @@
+/*
+ * battery_id.h - Power supply battery identification framework header
+file
+ *
+ * Copyright (C) 2012 Intel Corporation
+ *
+ *
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~
+~~~
+ *
+ * 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; version 2 of the License.
+ *
+ * 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

include/linux/power/battery_id.h new file +7 -0
+along
+ * with this program; if not, write to the Free Software Foundation,
+Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ *
+ *
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~
+~~~
+ * Author: Jenny TC <[email protected]>
+ * Author: David Rajamanickam, Ajay Thomas
+ * <[email protected]>
+ */

include/linux/power/battery_id.h new file +20 -0
+
+#ifndef __BATTERY_ID_H__
+
+#define __BATTERY_ID_H__
+
+enum {
+	POWER_SUPPLY_BATTERY_REMOVED = 0,
+	POWER_SUPPLY_BATTERY_INSERTED,
+};
+
+/* charging profile structure definition */ struct ps_batt_chg_prof {
+	enum batt_chrg_prof_type chrg_prof_type;
+	void *batt_prof;
+};
+
+/*For notification during battery change event*/
+extern struct atomic_notifier_head    batt_id_notifier;
+
+extern void battery_prop_changed(int battery_conn_stat,
+				struct ps_batt_chg_prof *batt_prop); extern

int

include/linux/power/battery_id.h new file +3 -1
+get_batt_prop(struct ps_batt_chg_prof *batt_prop); extern int
+batt_id_reg_notifier(struct notifier_block *nb); extern void
+batt_id_unreg_notifier(struct notifier_block *nb); #endif
--

1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/