logbuffer: move logbuffer and gvotables to kernel

logbuffers are used from the GBMS and TCPCI code to record internal
state and debug information that don't need (or cannot) be routed
to the standard syslog.

votables are used to arbitrate the access and manage the state of a
shared resource. Also make PMIC voter compat a compile time option

Bug: 166510851
Bug: 166528086
Bug: 164260419
Test: recompile
Signed-off-by: AleX Pelosi <[email protected]>
Change-Id: Idd8752bbd4b5fe7a1145cf2892884050926107dd
diff --git a/Kconfig b/Kconfig
index 3fea8f2..f95e40a 100644
--- a/Kconfig
+++ b/Kconfig
@@ -43,16 +43,8 @@
 	help
 	  Say Y here to enable Google USB overheat mitigation
 
-config GOOGLE_LOGBUFFER
-	tristate "debugfs logbuffer"
-	help
-	  Say Y here to enable logbuffer.
-	  This option enables a module that exposes an API to maintain driver
-	  specific logs in an exclusive ring buffer and exposes it through
-	  debugfs.
-
-config GOOGLE_VOTABLE
-	tristate "Voter compatibility shim"
+config PMIC_VOTER_COMPAT
+	tristate "QC Pmic Voter compatibility shim"
 	help
 	  Say Y here to enable voter compatibility shim layer.
 	  This option enables a call interface between the legacy voter
diff --git a/Makefile b/Makefile
index 59c2f63..c31e7a9 100644
--- a/Makefile
+++ b/Makefile
@@ -6,9 +6,6 @@
 obj-$(CONFIG_GOOGLE_BATTERY)	+= google-battery.o
 google-battery-objs += google_battery.o google_ttf.o
 obj-$(CONFIG_USB_OVERHEAT_MITIGATION)	+= overheat_mitigation.o
-obj-$(CONFIG_GOOGLE_LOGBUFFER)	+= logbuffer.o
-obj-$(CONFIG_GOOGLE_VOTABLE)	+= google-votable.o
-google-votable-objs += gvotable.o pmic-voter-compat.o
 obj-$(CONFIG_CHARGER_P9221)	+= p9221_charger.o
 obj-$(CONFIG_CHARGER_MAX77729)	+= max77729_charger.o
 obj-$(CONFIG_CHARGER_MAX77759)	+= max77759_charger.o
@@ -19,6 +16,7 @@
 max1720x-battery-objs += max1720x_battery.o max_m5.o
 obj-$(CONFIG_PCA9468)	+= pca9468_charger.o
 obj-$(CONFIG_MAX20339)		+= max20339.o
+obj-$(CONFIG_PMIC_VOTER_COMPAT)	+= pmic-voter-compat.o
 
 KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
 M ?= $(shell pwd)
@@ -29,8 +27,7 @@
 		  CONFIG_GOOGLE_BATTERY=m \
 		  CONFIG_GOOGLE_BEE=m \
 		  CONFIG_USB_OVERHEAT_MITIGATION=m \
-		  CONFIG_GOOGLE_LOGBUFFER=m \
-		  CONFIG_GOOGLE_VOTABLE=m \
+		  CONFIG_PMIC_VOTER_COMPAT=m \
 		  CONFIG_CHARGER_P9221=m \
 		  CONFIG_CHARGER_MAX77729=m \
 		  CONFIG_CHARGER_MAX77759=m \
diff --git a/google_battery.c b/google_battery.c
index b7424e7..76bf374 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -32,7 +32,7 @@
 #include "google_bms.h"
 #include "google_psy.h"
 #include "qmath.h"
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 #include <crypto/hash.h>
 
 #include <linux/debugfs.h>
@@ -3858,7 +3858,7 @@
 			"Couldn't register as power supply, ret=%d\n", ret);
 	}
 
-	batt_drv->ssoc_log = debugfs_logbuffer_register("ssoc");
+	batt_drv->ssoc_log = logbuffer_register("ssoc");
 	if (IS_ERR(batt_drv->ssoc_log)) {
 		ret = PTR_ERR(batt_drv->ssoc_log);
 		dev_err(batt_drv->device,
@@ -3866,7 +3866,7 @@
 		batt_drv->ssoc_log = NULL;
 	}
 
-	batt_drv->ttf_log = debugfs_logbuffer_register("ttf");
+	batt_drv->ttf_log = logbuffer_register("ttf");
 	if (IS_ERR(batt_drv->ttf_log)) {
 		ret = PTR_ERR(batt_drv->ttf_log);
 		dev_err(batt_drv->device,
@@ -3920,9 +3920,9 @@
 		return 0;
 
 	if (batt_drv->ssoc_log)
-		debugfs_logbuffer_unregister(batt_drv->ssoc_log);
+		logbuffer_unregister(batt_drv->ssoc_log);
 	if (batt_drv->ttf_log)
-		debugfs_logbuffer_unregister(batt_drv->ttf_log);
+		logbuffer_unregister(batt_drv->ttf_log);
 	if (batt_drv->tz_dev)
 		thermal_zone_of_sensor_unregister(batt_drv->device,
 				batt_drv->tz_dev);
diff --git a/google_charger.c b/google_charger.c
index 86061c2..5d4d937 100644
--- a/google_charger.c
+++ b/google_charger.c
@@ -35,7 +35,7 @@
 #include "google_bms.h"
 #include "google_dc_pps.h"
 #include "google_psy.h"
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 
 #ifdef CONFIG_DEBUG_FS
 #include <linux/debugfs.h>
@@ -2522,7 +2522,7 @@
 		alarm_try_to_cancel(&chg_drv->chg_wakeup_alarm);
 
 		if (chg_drv->pps_data.log)
-			debugfs_logbuffer_unregister(chg_drv->pps_data.log);
+			logbuffer_unregister(chg_drv->pps_data.log);
 	}
 
 	return 0;
diff --git a/google_cpm.c b/google_cpm.c
index 8589eba..16d712b 100644
--- a/google_cpm.c
+++ b/google_cpm.c
@@ -29,11 +29,12 @@
 #include <linux/pm_wakeup.h>
 #include <linux/thermal.h>
 #include <linux/slab.h>
-#include "gvotable.h"
+#include <misc/gvotable.h>
+#include "gbms_power_supply.h"
 #include "google_bms.h"
 #include "google_dc_pps.h"
 #include "google_psy.h"
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 
 #include <linux/debugfs.h>
 
diff --git a/google_dc_pps.c b/google_dc_pps.c
index 7b39247..fb9dd3c 100644
--- a/google_dc_pps.c
+++ b/google_dc_pps.c
@@ -22,10 +22,10 @@
 #include <linux/usb/pd.h>
 #include <linux/usb/tcpm.h>
 #include <linux/alarmtimer.h>
+#include <misc/logbuffer.h>
 #include "google_bms.h"
 #include "google_psy.h"
 #include "google_dc_pps.h"
-#include "logbuffer.h"
 
 #ifdef CONFIG_DEBUG_FS
 #include <linux/debugfs.h>
@@ -521,7 +521,7 @@
 		}
 	}
 
-	pps_data->log = debugfs_logbuffer_register("pps");
+	pps_data->log = logbuffer_register("pps");
 	if (IS_ERR(pps_data->log))
 		pps_data->log = NULL;
 
diff --git a/google_dc_pps.h b/google_dc_pps.h
index 01c5442..9edd1e8 100644
--- a/google_dc_pps.h
+++ b/google_dc_pps.h
@@ -18,7 +18,7 @@
 
 #include <linux/usb/pd.h>
 #include <linux/pm_wakeup.h>
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 
 #define PD_T_PPS_TIMEOUT		9000	/* Maximum of 10 seconds */
 #define PD_T_PPS_DEADLINE_S		7
diff --git a/google_ttf.c b/google_ttf.c
index da8f68d..98b7113 100644
--- a/google_ttf.c
+++ b/google_ttf.c
@@ -20,10 +20,10 @@
 #include <linux/platform_device.h>
 #include <linux/pm_wakeup.h>
 #include <linux/thermal.h>
+#include <misc/logbuffer.h>
 #include "google_bms.h"
 #include "google_psy.h"
 #include "qmath.h"
-#include "logbuffer.h"
 
 #ifdef CONFIG_DEBUG_FS
 #include <linux/debugfs.h>
diff --git a/gvotable.c b/gvotable.c
deleted file mode 100644
index eb86c7a..0000000
--- a/gvotable.c
+++ /dev/null
@@ -1,1486 +0,0 @@
-/*
- * Copyright 2019 Google, Inc
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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.
- */
-
-#include "gvotable.h"
-
-#include <linux/init.h>
-#include <linux/list.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/string.h>
-#include <linux/stringhash.h>
-
-#ifdef CONFIG_DEBUG_FS
-# include <linux/debugfs.h>
-# include <linux/seq_file.h>
-#endif
-
-#define VOTES_HISTORY_DEPTH  1
-#define MAX_NAME_LEN        16
-#define MAX_VOTE2STR_LEN    16
-
-
-#define DEBUGFS_CAST_VOTE_REASON "DEBUGFS"
-#define DEBUGFS_FORCE_VOTE_REASON "DEBUGFS_FORCE"
-
-static const char default_reason[] = "Default";
-#ifdef CONFIG_DEBUG_FS
-static struct dentry *debugfs_root;
-#endif
-
-static DEFINE_MUTEX(gvotable_lock);
-static LIST_HEAD(gvotables);
-
-/* a ballot is associated to a reason */
-struct ballot {
-	bool enabled;
-	uint32_t reason_hash;
-	char reason[GVOTABLE_MAX_REASON_LEN];
-
-	uint32_t idx;
-	void *vote[VOTES_HISTORY_DEPTH];
-	int vote_size;	/* !=0 when copy is requested */
-
-	uint32_t num_votes;
-
-	struct list_head list;
-};
-
-struct gvotable_election {
-	uint32_t hash;
-
-	int	vote_size;	/* actual vote size */
-	bool	use_alloc;	/* if true, use kalloc() for result and votes */
-
-	char name[MAX_NAME_LEN];
-	bool	has_name;	/* only elections with names are visible */
-
-	struct mutex cb_lock;	/* see lock_result(), lock_election() */
-	struct mutex re_lock;	/* see lock_result(), lock_election() */
-	void	*owner;
-
-	void	*result;	/* current result and reason */
-	char	reason[GVOTABLE_MAX_REASON_LEN];
-	bool	result_is_valid;
-
-	void	*data;		/* _get_data() */
-
-	gvotable_callback_fn callback;
-	int (*cmp)(void *, void *);
-
-	bool	auto_callback;	/* allow disabling callbacks (internal) */
-	void	*default_vote;
-	int	has_default_vote;	/* -1 no, 1 yes */
-
-	void	*force_result;
-	bool	force_result_is_enabled;
-
-	struct list_head votes; /* actual ballots */
-	uint32_t num_voters;	/* number of ballots */
-
-	uint32_t num_votes;	/* number of votes */
-
-	gvotable_v2sfn_t vote2str;
-	bool	is_int_type;	/* int-type debugfs entries */
-	bool	is_bool_type;
-};
-
-#define gvotable_lock_result(el) mutex_lock(&(el)->re_lock)
-#define gvotable_unlock_result(el) mutex_unlock(&(el)->re_lock);
-
-#define CONFIG_DEBUG_GVOTABLE_LOCKS
-#ifdef CONFIG_DEBUG_GVOTABLE_LOCKS
-void gvotable_lock_election(struct gvotable_election *el)
-{
-	int ret;
-
-	ret = mutex_trylock(&el->cb_lock);
-	if (WARN(ret == 0 && el->owner == get_current(),
-		 "%s cannot call this function from the callback\n",
-		 el->has_name ? el->name : "<>"))
-		mutex_lock(&el->cb_lock);
-
-	el->owner = get_current();
-	gvotable_lock_result(el);
-}
-#else
-#define gvotable_lock_election(el) do { \
-	mutex_lock(&(el)->cb_lock); \
-	mutex_lock(&(el)->re_lock); \
-} while (0)
-
-#endif
-
-#define gvotable_unlock_callback(el) mutex_unlock(&(el)->cb_lock);
-#define gvotable_unlock_election(el) do { \
-	mutex_unlock(&(el)->re_lock); \
-	mutex_unlock(&(el)->cb_lock); \
-} while (0)
-
-
-struct election_slot {
-	struct gvotable_election *el;
-	struct list_head list;
-	struct dentry *de;
-};
-
-int gvotable_comparator_uint_max(void *l, void *r)
-{
-	unsigned int a = *((unsigned int *) &l);
-	unsigned int b = *((unsigned int *) &r);
-
-	if (a > b)
-		return 1;
-	else if (a < b)
-		return (-1);
-	else
-		return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_comparator_uint_max);
-
-int gvotable_comparator_int(void *l, void *r)
-{
-	int a = *((int *) &l);
-	int b = *((int *) &r);
-
-	if (a > b)
-		return 1;
-	else if (a < b)
-		return (-1);
-	else
-		return 0;
-}
-
-/* compares l and r as integers */
-int gvotable_comparator_int_max(void *a, void *b)
-{
-	return -gvotable_comparator_int(a, b);
-}
-EXPORT_SYMBOL_GPL(gvotable_comparator_int_max);
-
-/* compares l and r as integers */
-int gvotable_comparator_int_min(void *a, void *b)
-{
-	return gvotable_comparator_int(a, b);
-}
-EXPORT_SYMBOL_GPL(gvotable_comparator_int_min);
-
-/* compares l and r as integers */
-int gvotable_comparator_uint_min(void *a, void *b)
-{
-	return -gvotable_comparator_uint_max(a, b);
-}
-EXPORT_SYMBOL_GPL(gvotable_comparator_uint_min);
-
-/* Always add new elements on head of the list */
-int gvotable_comparator_most_recent(void *a, void *b)
-{
-	return (-1);
-}
-EXPORT_SYMBOL_GPL(gvotable_comparator_most_recent);
-
-/* Always add new element on tail of the list */
-int gvotable_comparator_least_recent(void *a, void *b)
-{
-	return 1;
-}
-EXPORT_SYMBOL_GPL(gvotable_comparator_least_recent);
-
-/*
- * Here we use the cheapest choice, i.e. list head. bool elections return
- * 0 when there are NO votes active and a 1 value when there is at least
- * one vote.
- */
-static int gvotable_comparator_bool(void *a, void *b)
-{
-	return 1;
-}
-
-/* NONE add to the head of the list */
-static int gvotable_comparator_none(void *a, void *b)
-{
-	return (-1);
-}
-
-int gvotable_v2s_int(char *str,  size_t len, const void *vote)
-{
-	return scnprintf(str, len, "%ld", (unsigned long)vote);
-}
-EXPORT_SYMBOL_GPL(gvotable_v2s_int);
-
-int gvotable_v2s_uint(char *str, size_t len, const void *vote)
-{
-	return scnprintf(str, len, "%lu", (unsigned long)vote);
-}
-EXPORT_SYMBOL_GPL(gvotable_v2s_uint);
-
-int gvotable_v2s_uint_hex(char *str, size_t len, const void *vote)
-{
-	return scnprintf(str, len, "0x%lx", (unsigned long)vote);
-}
-EXPORT_SYMBOL_GPL(gvotable_v2s_uint_hex);
-
-/* GVotable internal hashing function */
-static uint32_t gvotable_internal_hash(const char *str)
-{
-	return full_name_hash(NULL, str, strlen(str));
-}
-
-static void gvotable_internal_update_reason(struct gvotable_election *el,
-					    const char *new_reason)
-{
-	strlcpy(el->reason, new_reason, GVOTABLE_MAX_REASON_LEN);
-}
-
-static void gvotable_internal_copy_result(struct gvotable_election *el,
-					  void **result,
-					  void *new_result)
-{
-	if (el->use_alloc)
-		memcpy(*result, new_result, el->vote_size);
-	else
-		*result = new_result;
-}
-
-static void gvotable_internal_update_result(struct gvotable_election *el,
-					    void *new_result)
-{
-	gvotable_internal_copy_result(el, &el->result, new_result);
-	el->result_is_valid = true;
-}
-
-#define GVOTABLE_BOOL_TRUE_VALUE	((void *)1)
-#define GVOTABLE_BOOL_FALSE_VALUE	((void *)0)
-
-/*
- * Determine the new result for the election, return true if the el->callback
- * needs to be called for the election false otherwise. MUST return false if
- * the el->callback is invalid (NULL).
- * requires &->re_lock and &->cb_lock
- */
-static bool gvotable_internal_run_election(struct gvotable_election *el)
-{
-	struct ballot *ballot;
-	bool callback_required = false;
-
-	if (el->force_result_is_enabled)
-		return false;
-	/* TODO: FIX this hack */
-	if (el->cmp == gvotable_comparator_none)
-		return true;
-
-	list_for_each_entry(ballot, &el->votes, list) {
-		if (!ballot->enabled)
-			continue;
-
-		/* Update reason if needed TODO: call *_set_result() */
-		if (!el->result_is_valid ||
-		    strncmp(el->reason, ballot->reason,
-			    GVOTABLE_MAX_REASON_LEN)) {
-
-			gvotable_internal_update_reason(el, ballot->reason);
-			callback_required = el->auto_callback;
-		}
-
-		/* Update result if needed TODO: call *_set_result() */
-		if (callback_required ||
-		    el->cmp(el->result, ballot->vote[ballot->idx]) != 0) {
-			void *new_result;
-
-			/* any-type elections have a default int-type value */
-			if (el->is_bool_type)
-				new_result = GVOTABLE_BOOL_TRUE_VALUE;
-			else
-				new_result = ballot->vote[ballot->idx];
-
-			gvotable_internal_update_result(el, new_result);
-			callback_required = el->auto_callback;
-		}
-
-		/* updated also in gvotable_internal_update_result() */
-		el->result_is_valid = true;
-		goto exit_done;
-	}
-
-	/*
-	 * Could not find a vote: use default if when set.
-	 * bool-type elections always have a default int-type default vote.
-	 */
-	if (el->has_default_vote == 1) {
-
-		/* TODO: call *_set_result() */
-		if (!el->result_is_valid ||
-		    strncmp(el->reason, default_reason,
-			    GVOTABLE_MAX_REASON_LEN)) {
-
-			gvotable_internal_update_reason(el, default_reason);
-			callback_required = el->auto_callback;
-		}
-
-		/* TODO: call *_set_result() */
-		if (callback_required ||
-		    el->cmp(el->result, el->default_vote) != 0) {
-
-			gvotable_internal_update_result(el, el->default_vote);
-			callback_required = el->auto_callback;
-		}
-
-		/* updated also in gvotable_internal_update_result() */
-		el->result_is_valid = true;
-	} else {
-		callback_required = el->result_is_valid && el->auto_callback;
-		el->result_is_valid = false;
-		el->reason[0] = 0; /* default to null reason */
-	}
-
-exit_done:
-	return callback_required && el->callback;
-}
-
-/* requires &gvotable_lock */
-static struct election_slot *gvotable_find_internal(const char *name)
-{
-	struct election_slot *slot;
-	struct gvotable_election *el;
-	unsigned int hash;
-
-	if (!name)
-		return NULL;
-
-	hash = gvotable_internal_hash(name);
-
-	list_for_each_entry(slot, &gvotables, list) {
-		el = slot->el;
-		if ((hash == el->hash) && el->has_name &&
-		    (strncmp(el->name, name, MAX_NAME_LEN) == 0))
-			return slot;
-	}
-
-	return NULL;
-}
-
-/* requires &gvotable_lock */
-static struct election_slot *gvotable_find_internal_ptr(struct gvotable_election *el)
-{
-	struct election_slot *slot;
-
-	list_for_each_entry(slot, &gvotables, list)
-		if (slot->el == el)
-			return slot;
-
-	return NULL;
-}
-
-/* requires &gvotable_lock */
-static void gvotable_add_internal(struct election_slot *slot)
-{
-	list_add(&slot->list, &gvotables);
-}
-
-/* requires &gvotable_lock */
-static void gvotable_delete_internal(struct election_slot *slot)
-{
-	list_del(&slot->list);
-	kfree(slot);
-}
-
-/* reader lock on election */
-static struct ballot *gvotable_ballot_find_internal(struct gvotable_election *el,
-						    const char *reason)
-{
-	struct ballot *ballot;
-	uint32_t reason_hash;
-
-	reason_hash = gvotable_internal_hash(reason);
-
-	list_for_each_entry(ballot, &el->votes, list) {
-
-		if ((reason_hash == ballot->reason_hash) &&
-		    (strncmp(ballot->reason, reason,
-			     GVOTABLE_MAX_REASON_LEN) == 0))
-			return ballot;
-	}
-	return NULL;
-}
-
-void gvotable_election_for_each(struct gvotable_election *el,
-				gvotable_foreach_callback_fn callback_fn,
-				void *cb_data)
-{
-	struct ballot *ballot;
-	int ret;
-
-	if (el->force_result_is_enabled) {
-		callback_fn(cb_data, DEBUGFS_FORCE_VOTE_REASON,
-				 el->force_result);
-		return;
-	}
-
-	/* TODO: LOCK list? */
-	list_for_each_entry(ballot, &el->votes, list) {
-		if (!ballot->enabled)
-			continue;
-
-		ret = callback_fn(cb_data, ballot->reason,
-				  ballot->vote[ballot->idx]);
-		if (ret < 0)
-			break;
-	}
-}
-EXPORT_SYMBOL_GPL(gvotable_election_for_each);
-
-
-#ifdef CONFIG_DEBUG_FS
-static int gvotable_debugfs_create_el_int(struct election_slot *slot);
-static void gvotable_debugfs_create_el(struct election_slot *slot);
-static void gvotable_debugfs_delete_el(struct election_slot *slot);
-#else
-static int gvotable_debugfs_create_el_int(struct election_slot *slot)
-{
-}
-static void gvotable_debugfs_create_el(struct election_slot *slot)
-{
-}
-static void gvotable_debugfs_delete_el(struct election_slot *slot)
-{
-}
-#endif
-
-/* Allow redefining the allocator: required for testing */
-#ifndef gvotable_kzalloc
-#define gvotable_kzalloc(p, f) kzalloc(sizeof(*p), f)
-#endif
-
-/* Allow redefining the allocator: required for testing */
-#ifndef gvotable_needs_alloc
-#define gvotable_needs_alloc(vote_size) \
-	((vote_size) > sizeof(((struct ballot *)0)->vote[0]))
-#endif
-
-struct gvotable_election *gvotable_create_election(const char *name,
-					int vote_size,
-					int (*cmp_fn)(void *, void *),
-					gvotable_callback_fn callback_fn,
-					void *data)
-{
-	struct gvotable_election *el = NULL;
-	struct election_slot *slot;
-
-	if (!cmp_fn)
-		cmp_fn = gvotable_comparator_none;
-
-	mutex_lock(&gvotable_lock);
-
-	if (name && gvotable_find_internal(name))
-		goto done_exit;
-
-	slot = gvotable_kzalloc(slot, GFP_KERNEL);
-	if (!slot)
-		goto done_exit;
-
-	slot->el = gvotable_kzalloc(slot->el, GFP_KERNEL);
-	if (!slot->el) {
-		kfree(slot);
-		goto done_exit;
-	}
-
-	mutex_init(&(slot->el->re_lock));
-	mutex_init(&(slot->el->cb_lock));
-	INIT_LIST_HEAD(&slot->el->votes);
-	slot->el->callback	= callback_fn;
-	slot->el->auto_callback	= true;
-	slot->el->cmp		= cmp_fn;
-	slot->el->data		= data;
-	slot->el->has_default_vote = -1;
-	slot->el->vote_size	= vote_size;
-	slot->el->use_alloc 	= gvotable_needs_alloc(vote_size);
-
-	/* preallocate result */
-	if (slot->el->use_alloc) {
-		slot->el->result = kzalloc(vote_size, GFP_KERNEL);
-		if (!slot->el->result) {
-			kfree(slot->el);
-			kfree(slot);
-			goto done_exit;
-		}
-	}
-
-	if (name) {
-		slot->el->has_name = true;
-		slot->el->hash     = gvotable_internal_hash(name);
-		strlcpy(slot->el->name, name, MAX_NAME_LEN);
-
-		gvotable_debugfs_create_el(slot);
-	}
-
-	gvotable_add_internal(slot);
-	el = slot->el;
-
-done_exit:
-	mutex_unlock(&gvotable_lock);
-	return el;
-}
-EXPORT_SYMBOL_GPL(gvotable_create_election);
-
-struct gvotable_election *gvotable_create_int_election(const char *name,
-					int (*cmp_fn)(void *, void *),
-					gvotable_callback_fn cb_fn,
-					void *data)
-{
-	struct gvotable_election *el;
-
-	el =  gvotable_create_election(name, sizeof(int), cmp_fn, cb_fn, data);
-	if (!el)
-		return NULL;
-
-	el->is_int_type = true;
-	if (name) {
-		struct election_slot *slot;
-
-		slot = gvotable_find_internal(name);
-		if (slot)
-			gvotable_debugfs_create_el_int(slot);
-	}
-
-	return el;
-}
-EXPORT_SYMBOL_GPL(gvotable_create_int_election);
-
-/*
- * "bool" elections return 1 when there is at least one vote active and 0
- * otherwise. Actual votes are ignored and the result is always the state
- * of the votes.
- */
-struct gvotable_election *gvotable_create_bool_election(const char *name,
-					gvotable_callback_fn cb_fn,
-					void *data)
-{
-	struct gvotable_election *el;
-
-	el =  gvotable_create_election(name, sizeof(int),
-				       gvotable_comparator_bool, cb_fn, data);
-	if (!el)
-		return NULL;
-
-	/* the fist call to set_default doesn't run election */
-	gvotable_set_default(el, GVOTABLE_BOOL_FALSE_VALUE);
-	/* run the election to update the actual vote */
-	gvotable_internal_run_election(el);
-	el->is_bool_type = true;
-	return el;
-}
-EXPORT_SYMBOL_GPL(gvotable_create_bool_election);
-
-/*
- * Destroying an election involves removing all ballots and removing the
- * election (and all its links) from the election slot.
- * TODO: calls to the election API should validate the *el pointer with
- * find_internal before accessing the election.
- */
-int gvotable_destroy_election(struct gvotable_election *el)
-{
-	struct ballot *tmp, *ballot;
-	struct election_slot *slot;
-
-	if (!el)
-		return -EINVAL;
-
-	gvotable_lock_result(el);
-
-	/* TODO: mark el as pending deletion and fail all operations */
-	list_for_each_entry_safe(ballot, tmp, &el->votes, list) {
-
-		if (ballot->vote_size) {
-			int i;
-
-			for (i = 0; i < VOTES_HISTORY_DEPTH; i++) {
-				if (ballot->vote[i]) {
-					kfree(ballot->vote[i]);
-					ballot->vote[i] = NULL;
-				}
-			}
-		}
-
-		kfree(ballot);
-	}
-
-	gvotable_unlock_result(el);
-
-	/* Find slots associated with this handle and remove them */
-	mutex_lock(&gvotable_lock);
-	slot = gvotable_find_internal_ptr(el);
-	while (slot) {
-		gvotable_debugfs_delete_el(slot);
-		gvotable_delete_internal(slot);
-		slot = gvotable_find_internal_ptr(el);
-	}
-	mutex_unlock(&gvotable_lock);
-
-	if (el->use_alloc)
-		kfree(el->result);
-	kfree(el);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_destroy_election);
-
-
-/*
- * Get a public election
- * TODO: the election can be destroyed while in use so SW needs to mark the
- * election as invalid somehow. One way to do this is to use find_internal()
- * to validate the election before accessing the fields (must make an
- * exception with nameless elections)
- */
-struct gvotable_election *gvotable_election_get_handle(const char *name)
-{
-	struct election_slot *slot;
-
-	if (!name)
-		return NULL;
-
-	mutex_lock(&gvotable_lock);
-	slot = gvotable_find_internal(name);
-	mutex_unlock(&gvotable_lock);
-
-	return (slot) ? slot->el : NULL;
-}
-EXPORT_SYMBOL_GPL(gvotable_election_get_handle);
-
-/* Set name of an election (makes election available for lookup) */
-int gvotable_election_set_name(struct gvotable_election *el, const char *name)
-{
-	struct election_slot *slot;
-
-	if (!el || !name)
-		return -EINVAL;
-
-	mutex_lock(&gvotable_lock);
-	if (el->has_name || gvotable_find_internal(name)) {
-		mutex_unlock(&gvotable_lock);
-		return -EEXIST;
-	}
-
-	el->has_name = true;
-	el->hash = gvotable_internal_hash(name);
-	strlcpy(el->name, name, MAX_NAME_LEN);
-
-	/* el->has_name ==> find internal will now find the election */
-	slot = gvotable_find_internal(name);
-	if (slot) {
-		gvotable_debugfs_create_el(slot);
-		if (slot->el->is_int_type)
-			gvotable_debugfs_create_el_int(slot);
-	}
-
-	mutex_unlock(&gvotable_lock);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_election_set_name);
-
-void gvotable_set_vote2str(struct gvotable_election *el,
-			   gvotable_v2sfn_t vote2str)
-{
-	el->vote2str = vote2str;
-}
-EXPORT_SYMBOL_GPL(gvotable_set_vote2str);
-
-static void gvotable_run_callback(struct gvotable_election *el)
-{
-	if (el->result_is_valid)
-		el->callback(el, el->reason, el->result);
-	else
-		el->callback(el, NULL, NULL);
-}
-
-/* Set the default value, rerun the election when the value changes */
-int gvotable_set_default(struct gvotable_election *el, void *default_val)
-{
-	bool changed;
-
-	/* boolean elections don't allow changing the default value */
-	if (!el || el->is_bool_type)
-		return -EINVAL;
-
-	gvotable_lock_election(el);
-
-	changed = el->has_default_vote == 1 && el->default_vote != default_val;
-	el->default_vote = default_val;
-
-	if (changed) {
-		if (gvotable_internal_run_election(el)) {
-			gvotable_unlock_result(el);
-			gvotable_run_callback(el);
-		}
-	} else {
-		gvotable_unlock_result(el);
-	}
-
-	el->has_default_vote = 1;
-	gvotable_unlock_callback(el);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_set_default);
-
-int gvotable_get_default(struct gvotable_election *el, void **result)
-{
-	int ret;
-
-	if (!el)
-		return -EINVAL;
-
-	gvotable_lock_election(el);
-	if (el->has_default_vote) {
-		gvotable_internal_copy_result(el, result, el->default_vote);
-		ret = 0;
-	} else {
-		ret = -EINVAL;
-	}
-
-	gvotable_unlock_election(el);
-	return ret;
-}
-
-/* Enable or disable usage of a default value for a given election */
-int gvotable_use_default(struct gvotable_election *el, bool default_is_enabled)
-{
-
-	/* boolean elections don't allow changing the default value */
-	if (!el || el->is_bool_type)
-		return -EINVAL;
-
-	gvotable_lock_election(el);
-
-	el->has_default_vote = default_is_enabled;
-	if (gvotable_internal_run_election(el)) {
-		gvotable_unlock_result(el);
-		gvotable_run_callback(el);
-	} else {
-		gvotable_unlock_result(el);
-	}
-
-	gvotable_unlock_callback(el);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_use_default);
-
-/* Retrieve data for an election */
-void* gvotable_get_data(struct gvotable_election *el)
-{
-	return el ? el->data: NULL;
-}
-EXPORT_SYMBOL_GPL(gvotable_get_data);
-
-/* NULL (0) is  a valid value when votes are integers */
-static int gvotable_get_current_result_unlocked(struct gvotable_election *el,
-					        const void **result)
-{
-	if (el->force_result_is_enabled)
-		*result = el->force_result;
-	else if (el->result_is_valid)
-		*result = el->result;
-	else
-		return -EAGAIN;
-
-	return 0;
-}
-
-int gvotable_get_current_vote(struct gvotable_election *el, const void **vote)
-{
-	int ret;
-
-	if (!el || !vote)
-		return -EINVAL;
-
-	gvotable_lock_result(el);
-	ret = gvotable_get_current_result_unlocked(el, vote);
-	gvotable_unlock_result(el);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_get_current_vote);
-
-int gvotable_get_current_int_vote(struct gvotable_election *el)
-{
-	const void *ptr;
-	int ret;
-
-	ret = gvotable_get_current_vote(el, &ptr);
-	return (ret) ? ret : (uintptr_t)ptr;
-}
-EXPORT_SYMBOL_GPL(gvotable_get_current_int_vote);
-
-/* copy the actual current vote */
-int gvotable_copy_current_result(struct gvotable_election *el, void *vote,
-			         int vote_size)
-{
-	const void *tmp;
-	int ret;
-
-	if (!el || !vote)
-		return -EINVAL;
-	if (vote_size != el->vote_size)
-		return -ERANGE;
-
-	gvotable_lock_result(el);
-	ret = gvotable_get_current_result_unlocked(el, &tmp);
-	if (ret == 0)
-		memcpy(vote, tmp, vote_size);
-	gvotable_unlock_result(el);
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_copy_current_result);
-
-static int gvotable_get_current_reason_unlocked(struct gvotable_election *el,
-						char *reason, int max_len)
-{
-	char *r = NULL;
-
-	if (el->force_result_is_enabled)
-		r = DEBUGFS_FORCE_VOTE_REASON;
-	else if (el->result_is_valid)
-		r = el->reason;
-
-	return r ? strlcpy(reason, r, max_len) : -EAGAIN;
-}
-
-
-/* Retrieve current reason for election result. */
-int gvotable_get_current_reason(struct gvotable_election *el, char *reason,
-				int max_len)
-{
-	int len;
-
-	if (!el || !reason)
-		return -EINVAL;
-
-	gvotable_lock_result(el);
-	len = gvotable_get_current_reason_unlocked(el, reason, max_len);
-	gvotable_unlock_result(el);
-	return len;
-}
-EXPORT_SYMBOL_GPL(gvotable_get_current_reason);
-
-/* Get vote associated with a specific reason */
-int gvotable_get_vote(struct gvotable_election *el, const char *reason,
-		      void **vote)
-{
-	struct ballot *ballot;
-
-	if (!el || !reason || !vote)
-		return -EINVAL;
-
-	gvotable_lock_result(el);
-	ballot = gvotable_ballot_find_internal(el, reason);
-	if (!ballot) {
-		gvotable_unlock_result(el);
-		return -ENODEV;
-	}
-
-	*vote = ballot->vote[ballot->idx];
-	gvotable_unlock_result(el);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_get_vote);
-
-/* Determine the reason is enabled */
-int gvotable_is_enabled(struct gvotable_election *el, const char *reason,
-			bool *enabled)
-{
-	struct ballot *ballot;
-
-	if (!el || !reason || !enabled)
-		return -EINVAL;
-
-	gvotable_lock_result(el);
-	ballot = gvotable_ballot_find_internal(el, reason);
-	if (!ballot) {
-		gvotable_unlock_result(el);
-		return -ENODEV;
-	}
-
-	*enabled = ballot->enabled;
-	gvotable_unlock_result(el);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_is_enabled);
-
-/* requires &el->re_lock */
-static int gvotable_update_ballot(struct ballot *ballot, void *vote,
-				  bool enabled)
-{
-	const int idx = (ballot->idx + 1) % VOTES_HISTORY_DEPTH;
-
-	ballot->enabled = enabled;
-
-	if (ballot->vote_size == 0) {
-		ballot->vote[idx] = vote;
-		goto exit_done;
-	}
-
-	if (!ballot->vote[idx]) {
-		ballot->vote[idx] = kzalloc(ballot->vote_size, GFP_KERNEL);
-		if (!ballot->vote[idx])
-			return -ENOMEM;
-	}
-
-	memcpy(ballot->vote[idx], vote, ballot->vote_size);
-
-exit_done:
-	ballot->idx = idx;
-	ballot->num_votes++;
-	return 0;
-}
-
-/* requires &el->re_lock */
-static void gvotable_add_ballot(struct gvotable_election *el,
-				struct ballot *ballot)
-{
-	struct ballot *last, *tmp;
-	void *vote = ballot->vote[ballot->idx];
-
-	/* If this is the only element, just add */
-	if (list_empty(&el->votes)) {
-		list_add(&ballot->list, &el->votes);
-		return;
-	}
-
-	/* strcmp() behavior, most recent (-1), least recent (1), min */
-	list_for_each_entry(tmp, &el->votes, list) {
-		if (el->cmp(vote, tmp->vote[tmp->idx]) < 0) {
-			/* Add new element before current one */
-			list_add_tail(&ballot->list, &tmp->list);
-			return;
-		}
-	}
-
-	/* Add new element after the last one */
-	last = list_last_entry(&el->votes, struct ballot, list);
-	list_add(&ballot->list, &last->list);
-
-	el->num_votes++;
-}
-
-static int gvotable_recast_ballot(struct gvotable_election *el,
-				  const char *reason,
-				  bool enabled)
-{
-	struct ballot *ballot;
-	int ret;
-
-	gvotable_lock_election(el);
-
-	ballot = gvotable_ballot_find_internal(el, reason);
-	if (!ballot) {
-		gvotable_unlock_election(el);
-		return -EINVAL;
-	}
-
-	list_del(&ballot->list);
-	ret = gvotable_update_ballot(ballot, ballot->vote[ballot->idx],
-				     enabled);
-	if (ret < 0) {
-		gvotable_unlock_election(el);
-		return ret;
-	}
-
-	gvotable_add_ballot(el, ballot);
-
-	if (gvotable_internal_run_election(el)) {
-		gvotable_unlock_result(el);
-		gvotable_run_callback(el);
-	} else {
-		gvotable_unlock_result(el);
-	}
-
-	gvotable_unlock_callback(el);
-	return 0;
-}
-
-#define gvotable_ballot_size_ok(size) ((size) <= sizeof(void *))
-
-/* This is generally used for shortcute so doesn't belong to the API */
-void gvotable_run_election(struct gvotable_election *el)
-{
-	bool callback;
-
-	gvotable_lock_election(el);
-	callback = gvotable_internal_run_election(el);
-	gvotable_unlock_result(el);
-	if (callback)
-		gvotable_run_callback(el);
-	gvotable_unlock_callback(el);
-}
-
-/* This can only be called while in the callback: the API here is not great */
-int gvotable_election_set_result(struct gvotable_election *el,
-				 const char *reason, void *result)
-{
-	if (!el || !reason || reason[0] == 0)
-		return -EINVAL;
-	/* a NULL vote is ok when we are not using copy */
-	if (el->use_alloc && !result)
-		return -EINVAL;
-	if (el->cmp != gvotable_comparator_none) {
-		WARN_ONCE(1, "Setting the result is not supported for a votable of this type");
-		return -EINVAL;
-	}
-
-	gvotable_internal_update_reason(el, reason);
-	gvotable_internal_update_result(el, result);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_election_set_result);
-
-int gvotable_cast_vote(struct gvotable_election *el, const char *reason,
-		       void *vote, bool enabled)
-{
-	struct ballot *ballot;
-	int ret;
-
-	if (!el || !reason || reason[0] == 0)
-		return -EINVAL;
-	/* a NULL vote is ok when we are not using copy */
-	if (el->use_alloc && !vote)
-		return -EINVAL;
-
-	gvotable_lock_election(el);
-
-	ballot = gvotable_ballot_find_internal(el, reason);
-	if (ballot) {
-		list_del(&ballot->list);
-	} else {
-		ballot = gvotable_kzalloc(ballot, GFP_KERNEL);
-		if (!ballot) {
-			gvotable_unlock_election(el);
-			return -ENOMEM;
-		}
-
-		ballot->reason_hash = gvotable_internal_hash(reason);
-		strlcpy(ballot->reason, reason, GVOTABLE_MAX_REASON_LEN);
-		if (el->use_alloc)
-			ballot->vote_size = el->vote_size;
-		el->num_voters++;
-	}
-
-	ret = gvotable_update_ballot(ballot, vote, enabled);
-	if (ret < 0) {
-		/* TODO: free the first vote on failure */
-		gvotable_unlock_election(el);
-		return ret;
-	}
-
-	gvotable_add_ballot(el, ballot);
-
-	if (gvotable_internal_run_election(el)) {
-		gvotable_unlock_result(el);
-		gvotable_run_callback(el);
-	} else {
-		gvotable_unlock_result(el);
-	}
-
-	gvotable_unlock_callback(el);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(gvotable_cast_vote);
-
-#ifdef CONFIG_DEBUG_FS
-
-#define GVOTABLE_DEBUG_ATTRIBUTE(name, fn_read, fn_write) \
-static const struct file_operations name = {	\
-	.open	= simple_open,			\
-	.llseek	= no_llseek,			\
-	.read	= fn_read,			\
-	.write	= fn_write,			\
-}
-
-/* requires lock on election */
-static int gvotable_dump_election(char *buf, size_t len,
-				  struct gvotable_election *el)
-{
-	gvotable_v2sfn_t vote2str = el->vote2str;
-	char reason[GVOTABLE_MAX_REASON_LEN];
-	int rc, count = 0;
-	const void *vote;
-
-	count += scnprintf(&buf[count], len - count, "%s:",
-			   el->has_name ? el->name : " :");
-
-	rc = gvotable_get_current_reason_unlocked(el, reason, sizeof(reason));
-	if (rc < 0)
-		count += scnprintf(&buf[count], len - count, " <%d>", rc);
-	else
-		count += scnprintf(&buf[count], len - count, " current=%s",
-				   reason);
-
-	rc = gvotable_get_current_result_unlocked(el, &vote);
-	if (rc < 0) {
-		count += scnprintf(&buf[count], len - count, " <%d>", rc);
-	} else {
-		count += scnprintf(&buf[count], len - count, " v=");
-		if (vote2str)
-			count += vote2str(&buf[count], len - count, vote);
-		else
-			count += scnprintf(&buf[count], len - count, "<>");
-	}
-
-	/* bool elections always have a default (0) vote */
-	if (!el->is_bool_type && el->has_default_vote == 1) {
-		count += scnprintf(&buf[count], len - count, " d=");
-		if (vote2str)
-			count += vote2str(&buf[count], len - count,
-					  el->default_vote);
-		else
-			count += scnprintf(&buf[count], len - count, "<>");
-	}
-
-	count += scnprintf(&buf[count], len - count, "\n");
-	return count;
-}
-
-/* requires &gvotable_lock */
-static int gvotable_list_elections(char *buf, size_t len)
-{
-	struct election_slot *slot;
-	int count = 0;
-
-	if (list_empty(&gvotables))
-		return 0;
-
-	list_for_each_entry(slot, &gvotables, list) {
-		gvotable_lock_result(slot->el);
-
-		count += gvotable_dump_election(&buf[count], len - count,
-					     slot->el);
-
-		gvotable_unlock_result(slot->el);
-	}
-
-	return count;
-}
-
-static ssize_t debugfs_list_elections(struct file *filp,
-				      char __user *user_buf,
-				      size_t count, loff_t *ppos)
-{
-	const int buf_size = 4096;
-	char *buf;
-	int len;
-
-	buf = kzalloc(buf_size, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	mutex_lock(&gvotable_lock);
-	len = gvotable_list_elections(buf, buf_size);
-	if (!len)
-		len = scnprintf(buf, buf_size, "data not available\n");
-	mutex_unlock(&gvotable_lock);
-
-	count = simple_read_from_buffer(user_buf, count, ppos, buf, len);
-
-	kfree(buf);
-	return count;
-}
-
-GVOTABLE_DEBUG_ATTRIBUTE(debugfs_elections_fops, debugfs_list_elections, NULL);
-
-
-/* requires lock on election */
-static int gvotable_dump_ballot(char *buf, size_t len, struct ballot *ballot,
-				gvotable_v2sfn_t vote2str)
-{
-	int count = 0;
-
-	count += scnprintf(&buf[count], len - count, " %s", ballot->reason);
-	count += scnprintf(&buf[count], len - count, " en=%d val=",
-			   ballot->enabled);
-	count += vote2str(&buf[count], len - count, ballot->vote[ballot->idx]);
-	count += scnprintf(&buf[count], len - count, " #votes=%d",
-			   ballot->num_votes);
-
-	return count;
-}
-
-/* requires lock on election */
-static int gvotable_list_ballots(char *buf, size_t len,
-				 struct gvotable_election *el,
-				 gvotable_v2sfn_t vote2str)
-{
-	struct ballot *ballot;
-	int count = 0;
-
-	if (!vote2str)
-		vote2str = el->vote2str;
-	if (!el || !vote2str)
-		return -EINVAL;
-
-	list_for_each_entry(ballot, &el->votes, list) {
-
-		count += scnprintf(&buf[count], len - count, "%s:",
-				   el->has_name ? el->name : " :");
-		count += gvotable_dump_ballot(&buf[count], len - count, ballot,
-					      vote2str);
-		count += scnprintf(&buf[count], len - count, "\n");
-	}
-
-	return count;
-}
-
-static ssize_t debugfs_list_ballots(struct file *filp,
-				    char __user *user_buf,
-				    size_t count, loff_t *ppos)
-{
-	struct election_slot *slot = filp->private_data;
-	const int buf_size = 4096;
-	char *buf;
-	int len;
-
-	buf = kzalloc(buf_size, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	gvotable_lock_result(slot->el);
-
-	len = gvotable_list_ballots(buf, buf_size, slot->el, NULL);
-	if (len < 0) {
-		len = scnprintf(buf, buf_size, "data not available (%d)\n",
-				len);
-	} else {
-		len += gvotable_dump_election(&buf[len], buf_size - len,
-					      slot->el);
-	}
-
-	gvotable_unlock_result(slot->el);
-
-	count = simple_read_from_buffer(user_buf, count, ppos, buf, len);
-
-	kfree(buf);
-
-	return count;
-}
-
-GVOTABLE_DEBUG_ATTRIBUTE(debugfs_ballots_fops, debugfs_list_ballots, NULL);
-
-static ssize_t debugfs_enable_vote(struct file *filp,
-				   const char __user *user_buf,
-				   size_t count, loff_t *ppos)
-{
-	struct election_slot *slot = filp->private_data;
-	char reason[GVOTABLE_MAX_REASON_LEN] = { 0 };
-	int ret;
-
-	ret = simple_write_to_buffer(reason, sizeof(reason), ppos, user_buf,
-				     count);
-	if (ret < 0)
-		return -EFAULT;
-
-	ret = gvotable_recast_ballot(slot->el, reason, true);
-	if (ret < 0) {
-		pr_err("cannot recast %s (%d)\n", reason, ret);
-		return ret;
-	}
-
-	return count;
-}
-
-GVOTABLE_DEBUG_ATTRIBUTE(debugs_enable_vote_fops, NULL, debugfs_enable_vote);
-
-
-static ssize_t debugfs_disable_vote(struct file *filp,
-				   const char __user *user_buf,
-				   size_t count, loff_t *ppos)
-{
-	struct election_slot *slot = filp->private_data;
-	char reason[GVOTABLE_MAX_REASON_LEN] = { 0 };
-	int ret;
-
-	ret = simple_write_to_buffer(reason, sizeof(reason), ppos, user_buf,
-				     count);
-	if (ret < 0)
-		return -EFAULT;
-
-	ret = gvotable_recast_ballot(slot->el, reason, false);
-	if (ret < 0) {
-		pr_err("cannot recast %s (%d)\n", reason, ret);
-		return ret;
-	}
-
-	return count;
-}
-
-GVOTABLE_DEBUG_ATTRIBUTE(debugs_disable_vote_fops, NULL, debugfs_disable_vote);
-
-/* TODO: only enable for int votes */
-static int debugfs_cast_int_vote(void *data, u64 val)
-{
-	struct election_slot *slot = data;
-	bool enabled = false;
-	int ret;
-
-	ret = gvotable_is_enabled(slot->el, DEBUGFS_CAST_VOTE_REASON,
-				  &enabled);
-	if (ret < 0)
-		pr_debug("vote not present\n");
-
-	return gvotable_cast_vote(slot->el, DEBUGFS_CAST_VOTE_REASON,
-				  (void*)val, enabled);
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(debugfs_cast_int_vote_fops,
-				NULL,
-				debugfs_cast_int_vote, "%llu\n");
-
-/* TODO: only enable for int votes */
-static int debugfs_force_int_value(void *data, u64 val)
-{
-	struct election_slot *slot = data;
-
-	slot->el->force_result = (void*)val;
-	return 0;
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(debugfs_force_int_value_fops,
-			NULL,
-			debugfs_force_int_value, "%llu\n");
-
-static int debugfs_force_int_active(void *data, u64 val)
-{
-	struct election_slot *slot = data;
-
-
-	gvotable_lock_election(slot->el);
-
-	slot->el->force_result_is_enabled = !!val;
-	gvotable_unlock_result(slot->el);
-
-	if (!slot->el->callback)
-		goto exit_done;
-
-	if (slot->el->force_result_is_enabled) {
-		slot->el->callback(slot->el, DEBUGFS_FORCE_VOTE_REASON,
-				   slot->el->force_result);
-	} else {
-		gvotable_run_callback(slot->el);
-	}
-
-exit_done:
-	gvotable_unlock_callback(slot->el);
-	return 0;
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(debugfs_force_int_active_fops,
-			NULL,
-			debugfs_force_int_active, "%llu\n");
-
-static void gvotable_debugfs_cleanup(void)
-{
-	if (debugfs_root)
-		debugfs_remove_recursive(debugfs_root);
-	debugfs_root = NULL;
-}
-
-static int gvotable_debugfs_create_el_int(struct election_slot *slot)
-{
-	if (!slot->de)
-		return -ENOENT;
-
-	debugfs_create_file("cast_int_vote", 0200, slot->de, slot,
-			&debugfs_cast_int_vote_fops);
-	debugfs_create_file("force_int_value", 0200, slot->de, slot,
-			&debugfs_force_int_value_fops);
-	debugfs_create_file("force_int_active", 0200, slot->de, slot,
-			&debugfs_force_int_active_fops);
-
-	return 0;
-}
-
-static void gvotable_debugfs_create_el(struct election_slot *slot)
-{
-	/* TODO: add anon to a special directory */
-	if (!slot->el->has_name)
-		return;
-
-	if (!debugfs_root) {
-		debugfs_root = debugfs_create_dir("gvotables", 0);
-		if (!debugfs_root) {
-			pr_err("cannot create gvotables debug directory\n");
-			return;
-		}
-
-		/* add: list all the elections including the anon ones */
-		debugfs_create_file("elections", 0444, debugfs_root, NULL,
-				    &debugfs_elections_fops);
-
-		pr_err("gvotables debug directory OK\n");
-	}
-
-	slot->de = debugfs_create_dir(slot->el->name, debugfs_root);
-	if (!slot->de) {
-		pr_err("cannot create debugfs entry for slot=%p\n", slot);
-		return;
-	}
-
-	debugfs_create_file("status", 0444, slot->de, slot,
-			    &debugfs_ballots_fops);
-	debugfs_create_file("enable_vote", 0200, slot->de, slot,
-			    &debugs_enable_vote_fops);
-	debugfs_create_file("disable_vote", 0200, slot->de, slot,
-			    &debugs_disable_vote_fops);
-}
-
-static void gvotable_debugfs_delete_el(struct election_slot *slot)
-{
-	if (!slot->de)
-		return;
-
-	debugfs_remove_recursive(slot->de);
-	slot->de = NULL;
-}
-
-
-#else /* CONFIG_DEBUG_FS */
-static inline void gvotable_debugfs_cleanup(void)
-{
-
-}
-#endif
-
-
-static int __init gvotable_init(void)
-{
-	return 0;
-}
-
-static void __exit gvotable_exit(void)
-{
-	struct election_slot *slot, *tmp;
-
-	gvotable_debugfs_cleanup();
-	list_for_each_entry_safe(slot, tmp, &gvotables, list) {
-		pr_debug("Destroying %p\n", slot->el);
-		gvotable_destroy_election(slot->el);
-	}
-	pr_info("Deinit completed\n\n");
-	return;
-}
-
-module_init(gvotable_init);
-module_exit(gvotable_exit);
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Luigi Zevola <[email protected]>");
-MODULE_DESCRIPTION("Election library for shared resources");
-MODULE_VERSION("0.01");
diff --git a/gvotable.h b/gvotable.h
deleted file mode 100644
index ca89e5f..0000000
--- a/gvotable.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2019 Google, Inc
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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 __GOOGLE_GVOTABLE_H_
-#define __GOOGLE_GVOTABLE_H_
-
-#include <linux/types.h>
-#include <linux/mutex.h>
-
-#define GVOTABLE_MAX_REASON_LEN      16
-
-struct gvotable_election;
-
-typedef int (*gvotable_cmp_fn)(void *a, void *b);
-typedef void (*gvotable_callback_fn)(struct gvotable_election *el,
-				     const char *reason,
-				     void *vote);
-
-struct gvotable_election *gvotable_create_election(const char *name,
-					int vote_size,
-					int  (*cmp_fn)(void *, void *),
-					gvotable_callback_fn callback_fn,
-					void *data);
-
-#define _GVOTABLE_EPC(a, ...) a ## __VA_ARGS__
-#define GVOTABLE__ELECTION_HELPER(t) \
-	_GVOTABLE_EPC(_GVOTABLE_EPC(gvotable_create_,t)_election)(name, cmp_fn, cb_fn, data)
-
-/* NOTE: cannot change the data after init to avoid adding a lock for it */
-struct gvotable_election *gvotable_create_int_election(const char *name,
-					gvotable_cmp_fn cmp_fn,
-					gvotable_callback_fn callback_fn,
-					void *data);
-
-struct gvotable_election *gvotable_create_bool_election(const char *name,
-					gvotable_callback_fn callback_fn,
-					void *data);
-
-
-int gvotable_destroy_election(struct gvotable_election *el);
-
-struct gvotable_election *gvotable_election_get_handle(const char *name);
-
-/* TODO: redesign this API  */
-typedef int (*gvotable_foreach_callback_fn)(void *data, const char *reason,
-					    void *vote);
-void gvotable_election_for_each(struct gvotable_election *el,
-				gvotable_foreach_callback_fn callback_fn,
-				void *callback_data);
-int gvotable_election_set_result(struct gvotable_election *el,
-				 const char *reason, void *vote);
-
-
-void *gvotable_get_data(struct gvotable_election *el);
-
-int gvotable_get_current_reason(struct gvotable_election *el,
-				char *reason,
-				int max_reason_len);
-
-int gvotable_set_default(struct gvotable_election *el, void *default_val);
-int gvotable_get_default(struct gvotable_election *el, void **default_val);
-
-int gvotable_election_set_name(struct gvotable_election *el,
-			       const char *name);
-
-int gvotable_use_default(struct gvotable_election *el,
-			 bool default_is_enabled);
-
-int gvotable_cast_vote(struct gvotable_election *el,
-		       const char *reason,
-		       void *vote,
-		       bool enabled);
-
-int gvotable_get_vote(struct gvotable_election *el,
-		      const char *reason,
-		      void **vote);
-
-int gvotable_is_enabled(struct gvotable_election *el,
-		        const char *reason,
-		        bool *enabled);
-
-int gvotable_get_current_int_vote(struct gvotable_election *el);
-int gvotable_get_current_vote(struct gvotable_election *el, const void **vote);
-int gvotable_copy_current_result(struct gvotable_election *el, void *vote,
-				 int vote_size);
-
-int gvotable_comparator_uint_max(void *a, void *b);
-int gvotable_comparator_uint_min(void *a, void *b);
-int gvotable_comparator_int_max(void *a, void *b);
-int gvotable_comparator_int_min(void *a, void *b);
-int gvotable_comparator_most_recent(void *a, void *b);
-int gvotable_comparator_least_recent(void *a, void *b);
-
-/* dump, debug */
-typedef int (*gvotable_v2sfn_t)(char *str, size_t len, const void *);
-int gvotable_v2s_int(char *str,  size_t len, const void *vote);
-int gvotable_v2s_uint(char *str, size_t len, const void *vote);
-int gvotable_v2s_uint_hex(char *str, size_t len, const void *vote);
-void gvotable_set_vote2str(struct gvotable_election *el,
-			   gvotable_v2sfn_t vote2str);
-
-#endif /* __GOOGLE_GVOTABLE_H_*/
diff --git a/logbuffer.c b/logbuffer.c
deleted file mode 100644
index da26c1f..0000000
--- a/logbuffer.c
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright 2019 Google, Inc
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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.
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/debugfs.h>
-#include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/rtc.h>
-#include <linux/sched/clock.h>
-#include <linux/seq_file.h>
-#include <linux/suspend.h>
-#include <linux/slab.h>
-#include <linux/syscore_ops.h>
-#include <linux/vmalloc.h>
-
-#define LOG_BUFFER_ENTRIES      1024
-#define LOG_BUFFER_ENTRY_SIZE   256
-#define ID_LENGTH		50
-
-struct logbuffer {
-	int logbuffer_head;
-	int logbuffer_tail;
-	// protects buffer
-	spinlock_t logbuffer_lock;
-	u8 *buffer;
-	struct dentry *file;
-	char id[ID_LENGTH];
-	struct list_head entry;
-};
-
-/*
- * Rootdir for the log files.
- */
-struct dentry *rootdir;
-
-/*
- * Device suspended since last logged.
- */
-bool suspend_since_last_logged;
-
-/*
- * List to maintain logbuffer intance.
- */
-static LIST_HEAD(instances);
-
-/*
- * Protects instances list.
- */
-static spinlock_t instances_lock;
-
-static void __logbuffer_log(struct logbuffer *instance,
-			    const char *tmpbuffer, bool record_utc)
-{
-	u64 ts_nsec = local_clock();
-	unsigned long rem_nsec = do_div(ts_nsec, 1000000000);
-
-	if (record_utc) {
-		struct timespec ts;
-		struct rtc_time tm;
-
-		getnstimeofday(&ts);
-		rtc_time_to_tm(ts.tv_sec, &tm);
-		scnprintf(instance->buffer + (instance->logbuffer_head *
-			  LOG_BUFFER_ENTRY_SIZE),
-			  LOG_BUFFER_ENTRY_SIZE,
-			  "[%5lu.%06lu] %d-%02d-%02d %02d:%02d:%02d.%09lu UTC",
-			  (unsigned long)ts_nsec, rem_nsec / 1000,
-			  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
-			  tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec);
-	} else {
-		scnprintf(instance->buffer + (instance->logbuffer_head *
-			  LOG_BUFFER_ENTRY_SIZE),
-			  LOG_BUFFER_ENTRY_SIZE, "[%5lu.%06lu] %s",
-			  (unsigned long)ts_nsec, rem_nsec / 1000,
-			  tmpbuffer);
-	}
-
-	instance->logbuffer_head = (instance->logbuffer_head + 1)
-			% LOG_BUFFER_ENTRIES;
-	if (instance->logbuffer_head == instance->logbuffer_tail) {
-		instance->logbuffer_tail = (instance->logbuffer_tail + 1)
-				      % LOG_BUFFER_ENTRIES;
-	}
-}
-
-void logbuffer_vlog(struct logbuffer *instance, const char *fmt,
-		    va_list args)
-{
-	char tmpbuffer[LOG_BUFFER_ENTRY_SIZE];
-	unsigned long flags;
-
-	if (!instance)
-		return;
-
-	/* Empty log msgs are passed from TCPM to log RTC.
-	 * The RTC is printed if thats the first message
-	 * printed after resume.
-	 */
-	if (fmt)
-		vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args);
-
-	spin_lock_irqsave(&instance->logbuffer_lock, flags);
-	if (instance->logbuffer_head < 0 ||
-	    instance->logbuffer_head >= LOG_BUFFER_ENTRIES) {
-		pr_warn("Bad log buffer index %d\n", instance->logbuffer_head);
-		goto abort;
-	}
-
-	/* Print UTC at the start of the buffer */
-	if ((instance->logbuffer_head == instance->logbuffer_tail) ||
-	    (instance->logbuffer_head == LOG_BUFFER_ENTRIES - 1)) {
-		__logbuffer_log(instance, tmpbuffer, true);
-	/* Print UTC when logging after suspend */
-	} else if (suspend_since_last_logged) {
-		__logbuffer_log(instance, tmpbuffer, true);
-		suspend_since_last_logged = false;
-	} else if (!fmt) {
-		goto abort;
-	}
-
-	__logbuffer_log(instance, tmpbuffer, false);
-
-abort:
-	spin_unlock_irqrestore(&instance->logbuffer_lock, flags);
-}
-EXPORT_SYMBOL_GPL(logbuffer_vlog);
-
-void logbuffer_log(struct logbuffer *instance, const char *fmt, ...)
-{
-	va_list args;
-
-	va_start(args, fmt);
-	logbuffer_vlog(instance, fmt, args);
-	va_end(args);
-}
-EXPORT_SYMBOL_GPL(logbuffer_log);
-
-static int logbuffer_seq_show(struct seq_file *s, void *v)
-{
-	struct logbuffer *instance = (struct logbuffer *)s->private;
-	int tail;
-
-	spin_lock(&instance->logbuffer_lock);
-	tail = instance->logbuffer_tail;
-	while (tail != instance->logbuffer_head) {
-		seq_printf(s, "%s\n", instance->buffer +
-			   (tail * LOG_BUFFER_ENTRY_SIZE));
-		tail = (tail + 1) % LOG_BUFFER_ENTRIES;
-	}
-
-	spin_unlock(&instance->logbuffer_lock);
-
-	return 0;
-}
-
-static int logbuffer_debug_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, logbuffer_seq_show, inode->i_private);
-}
-
-static const struct file_operations logbuffer_debug_operations = {
-	.open           = logbuffer_debug_open,
-	.llseek         = seq_lseek,
-	.read           = seq_read,
-	.release        = single_release,
-};
-
-struct logbuffer *debugfs_logbuffer_register(char *name)
-{
-	struct logbuffer *instance;
-	unsigned long flags;
-
-	if (IS_ERR_OR_NULL(rootdir)) {
-		pr_err("rootdir not found\n");
-		return ERR_PTR(-EINVAL);
-	}
-
-	instance = kzalloc(sizeof(struct logbuffer), GFP_KERNEL);
-	if (!instance) {
-		pr_err("fialed to create instance %s\n", name);
-		return ERR_PTR(-ENOMEM);
-	}
-
-	instance->buffer = vzalloc(LOG_BUFFER_ENTRIES * LOG_BUFFER_ENTRY_SIZE);
-	if (!instance->buffer) {
-		pr_err("failed to create buffer %s\n", name);
-		instance = ERR_PTR(-ENOMEM);
-		goto free_instance;
-	}
-
-	instance->file = debugfs_create_file(name,
-				0444, rootdir, instance,
-				&logbuffer_debug_operations);
-	if (IS_ERR_OR_NULL(instance->file)) {
-		pr_err("Failed to create debugfs file:%s err:%ld\n", name,
-		       PTR_ERR(instance->file));
-		goto free_buffer;
-	}
-
-	strlcpy(instance->id, name, sizeof(instance->id));
-
-	spin_lock_init(&instance->logbuffer_lock);
-
-	spin_lock_irqsave(&instances_lock, flags);
-	list_add(&instance->entry, &instances);
-	spin_unlock_irqrestore(&instances_lock, flags);
-
-	pr_info(" id:%s registered\n", name);
-	return instance;
-
-free_buffer:
-	vfree(instance->buffer);
-free_instance:
-	kfree(instance);
-
-	return ERR_PTR(-ENOMEM);
-}
-EXPORT_SYMBOL_GPL(debugfs_logbuffer_register);
-
-void debugfs_logbuffer_unregister(struct logbuffer *instance)
-{
-	unsigned long flags;
-
-	if (!instance) {
-		pr_err("Instance ptr null\n");
-		return;
-	}
-
-	debugfs_remove(instance->file);
-	vfree(instance->buffer);
-	spin_lock_irqsave(&instances_lock, flags);
-	list_del(&instance->entry);
-	spin_unlock_irqrestore(&instances_lock, flags);
-	pr_info(" id:%s unregistered\n", instance->id);
-	kfree(instance);
-}
-EXPORT_SYMBOL_GPL(debugfs_logbuffer_unregister);
-
-int logbuffer_suspend(void)
-{
-	suspend_since_last_logged = true;
-	return 0;
-}
-
-static struct syscore_ops logbuffer_ops = {
-	.suspend        = logbuffer_suspend,
-};
-
-static int __init logbuffer_debugfs_init(void)
-{
-	spin_lock_init(&instances_lock);
-
-	rootdir = debugfs_create_dir("logbuffer", NULL);
-	if (IS_ERR_OR_NULL(rootdir)) {
-		pr_err("Unable to create rootdir %ld\n", PTR_ERR(rootdir));
-		return PTR_ERR(rootdir);
-	}
-
-	register_syscore_ops(&logbuffer_ops);
-
-	return 0;
-}
-
-static void logbuffer_debugfs_exit(void)
-{
-	struct logbuffer *instance, *next;
-	unsigned long flags;
-
-	spin_lock_irqsave(&instances_lock, flags);
-	list_for_each_entry_safe(instance, next, &instances, entry) {
-		debugfs_remove(instance->file);
-		vfree(instance->buffer);
-		list_del(&instance->entry);
-		pr_info(" id:%s unregistered\n", instance->id);
-		kfree(instance);
-	}
-	spin_unlock_irqrestore(&instances_lock, flags);
-	debugfs_remove(rootdir);
-}
-early_initcall(logbuffer_debugfs_init);
-module_exit(logbuffer_debugfs_exit);
-MODULE_LICENSE("GPL");
diff --git a/logbuffer.h b/logbuffer.h
deleted file mode 100644
index 2c99495..0000000
--- a/logbuffer.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2019 Google, Inc
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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 __GOOGLE_LOGBUFFER_H_
-#define __GOOGLE_LOGBUFFER_H_
-
-#include <stdarg.h>
-
-struct logbuffer;
-void logbuffer_log(struct logbuffer *instance, const char *fmt, ...);
-void logbuffer_vlog(struct logbuffer *instance, const char *fmt,
-		    va_list args);
-/*
- * Registers a new log buffer entry.
- * param name: name of the file in the /d/logbuffer/ directory.
- * returns the pointer to the logbuffer metadata.
- */
-struct logbuffer *debugfs_logbuffer_register(char *name);
-
-void debugfs_logbuffer_unregister(struct logbuffer *instance);
-#endif /* __GOOGLE_LOGBUFFER_H_ */
-
diff --git a/max1720x_battery.c b/max1720x_battery.c
index 714f542..ac96358 100644
--- a/max1720x_battery.c
+++ b/max1720x_battery.c
@@ -35,7 +35,7 @@
 
 #include "gbms_power_supply.h"
 #include "google_bms.h"
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 #include "max1720x_battery.h"
 
 #include <linux/debugfs.h>
@@ -4070,7 +4070,7 @@
 				ret);
 	}
 
-	chip->ce_log = debugfs_logbuffer_register("batt_ce");
+	chip->ce_log = logbuffer_register("batt_ce");
 	if (IS_ERR(chip->ce_log)) {
 		ret = PTR_ERR(chip->ce_log);
 		dev_err(dev, "failed to obtain logbuffer, ret=%d\n", ret);
@@ -4105,7 +4105,7 @@
 	struct max1720x_chip *chip = i2c_get_clientdata(client);
 
 	if (chip->ce_log) {
-		debugfs_logbuffer_unregister(chip->ce_log);
+		logbuffer_unregister(chip->ce_log);
 		chip->ce_log = NULL;
 	}
 
diff --git a/max77729_charger.c b/max77729_charger.c
index 75ecde1..8d95f36 100644
--- a/max77729_charger.c
+++ b/max77729_charger.c
@@ -21,9 +21,9 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_gpio.h>
-#include <linux/power_supply.h>
 #include <linux/regmap.h>
-#include "gvotable.h"
+#include <misc/gvotable.h>
+#include "gbms_power_supply.h"
 
 #ifdef CONFIG_DEBUG_FS
 # include <linux/debugfs.h>
diff --git a/max77759_charger.c b/max77759_charger.c
index 19a2633..fb8b34d 100644
--- a/max77759_charger.c
+++ b/max77759_charger.c
@@ -26,10 +26,11 @@
 #include <linux/regmap.h>
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
+#include <misc/gvotable.h>
+#include "gbms_power_supply.h"
 #include "google_bms.h"
 #include "max_m5.h"
 #include "max77759.h"
-#include "gvotable.h"
 
 /* CHG_DETAILS_01:CHG_DTLS */
 #define CHGR_DTLS_DEAD_BATTERY_MODE			0x00
diff --git a/max77759_maxq.c b/max77759_maxq.c
index 2dfd58c..55ca8d1 100644
--- a/max77759_maxq.c
+++ b/max77759_maxq.c
@@ -17,7 +17,7 @@
 #include <linux/of_gpio.h>
 #include <linux/regmap.h>
 
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 #include "max77759_regs.h"
 
 #define PAYLOAD_REQUEST_LENGTH_BYTES		33
@@ -272,7 +272,7 @@
 	if (IS_ERR_OR_NULL(maxq))
 		return ERR_PTR(-ENOMEM);
 
-	maxq->log = debugfs_logbuffer_register("maxq");
+	maxq->log = logbuffer_register("maxq");
 	if (IS_ERR_OR_NULL(maxq->log)) {
 		dev_err(dev, "MAXQ logbuffer register failed\n");
 		return (struct max77759_maxq *)maxq->log;
@@ -294,7 +294,7 @@
 void maxq_remove(struct max77759_maxq *maxq)
 {
 	maxq->init_done = false;
-	debugfs_logbuffer_unregister(maxq->log);
+	logbuffer_unregister(maxq->log);
 }
 EXPORT_SYMBOL_GPL(maxq_remove);
 MODULE_AUTHOR("Badhri Jagan Sridharan <[email protected]>");
diff --git a/max_m5.c b/max_m5.c
index 9d5a5f0..1f094d9 100644
--- a/max_m5.c
+++ b/max_m5.c
@@ -25,7 +25,7 @@
 #include <linux/regmap.h>
 #include "google_bms.h"
 #include "google_psy.h"
-#include "logbuffer.h"
+#include <misc/logbuffer.h>
 
 #include "max_m5_reg.h"
 #include "max_m5.h"
diff --git a/p9221_charger.c b/p9221_charger.c
index ed730c9..df274b7 100644
--- a/p9221_charger.c
+++ b/p9221_charger.c
@@ -28,8 +28,9 @@
 #include <linux/delay.h>
 #include <linux/power_supply.h>
 #include <linux/alarmtimer.h>
+#include <misc/logbuffer.h>
+#include "gbms_power_supply.h"
 #include "pmic-voter.h" /* TODO(b/163679860): use gvotables */
-#include "logbuffer.h"
 #include "p9221_charger.h"
 
 #define P9221_TX_TIMEOUT_MS		(20 * 1000)
@@ -4226,7 +4227,7 @@
 		return ret;
 	}
 
-	charger->log = debugfs_logbuffer_register("wireless");
+	charger->log = logbuffer_register("wireless");
 	if (IS_ERR(charger->log)) {
 		ret = PTR_ERR(charger->log);
 		dev_err(charger->dev,
@@ -4234,7 +4235,7 @@
 		charger->log = NULL;
 	}
 
-	charger->rtx_log = debugfs_logbuffer_register("rtx");
+	charger->rtx_log = logbuffer_register("rtx");
 	if (IS_ERR(charger->rtx_log)) {
 		ret = PTR_ERR(charger->rtx_log);
 		dev_err(charger->dev,
@@ -4274,9 +4275,9 @@
 	power_supply_unreg_notifier(&charger->nb);
 	mutex_destroy(&charger->io_lock);
 	if (charger->log)
-		debugfs_logbuffer_unregister(charger->log);
+		logbuffer_unregister(charger->log);
 	if (charger->rtx_log)
-		debugfs_logbuffer_unregister(charger->rtx_log);
+		logbuffer_unregister(charger->rtx_log);
 	return 0;
 }
 
diff --git a/pmic-voter-compat.c b/pmic-voter-compat.c
index 39fb7f5..93a73a4 100644
--- a/pmic-voter-compat.c
+++ b/pmic-voter-compat.c
@@ -11,14 +11,13 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
+
+#include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include "linux/slab.h"
-/* TODO: make PMIC_VOTER_COMPAT a build configuration and use
- * #include <linux/pmic-voter.h>
- */
+#include <misc/gvotable.h>
 #include "pmic-voter.h"
-#include "gvotable.h"
 
 #define V2EL(x) ((struct gvotable_election *)(v))
 
@@ -211,3 +210,8 @@
 	gvotable_destroy_election(V2EL(v));
 }
 EXPORT_SYMBOL_GPL(destroy_votable);
+
+MODULE_AUTHOR("Jim Wylder <[email protected]>");
+MODULE_AUTHOR("AleX Pelosi <[email protected]>");
+MODULE_DESCRIPTION("QC PMIC Votable compatibility");
+MODULE_LICENSE("GPL");
\ No newline at end of file