mirror of
https://github.com/team-infusion-developers/android_kernel_samsung_msm8976.git
synced 2024-10-31 18:09:19 +00:00
0171e31d02
Add a new BCL framework driver which provides interface to configure and interact with the battery current limit hardware. This framework driver also provides a generic interface for the hardware drivers to register with function pointers, thus abstracting the underlying hardware from the upper level kernel modules. The BCL peripheral driver exposes the below read-only sysfs nodes for user debugging. -/sys/class/msm_bcl/voltage/value - Latest battery voltage value (uV) -/sys/class/msm_bcl/voltage/high_trip - Active maximum battery voltage threshold (uV) -/sys/class/msm_bcl/voltage/low_trip - Active minimum battery voltage threshold (uV) -/sys/class/msm_bcl/current/value - Latest battery current value (uA) -/sys/class/msm_bcl/current/high_trip - Active maximum battery current threshold (uA) -/sys/class/msm_bcl/current/low_trip - Active minimum battery current threshold (uA) The bcl framework driver provides a data-structure to input the trip threshold, trip type, trip notification, and its associated data to be passed along the notification. The kernel drivers can use this data-structure to pass the high and low trip threshold information for battery voltage and current. struct bcl_threshold { int trip_value; enum bcl_trip_type type; void (*trip_notify)(enum bcl_trip_type, int, void *); void *trip_data; }; - int msm_bcl_enable(void); - int msm_bcl_disable(void); Kernel driver should use these interfaces to enable and disable the BCL monitoring feature respectively. The msm_bcl_enable(void) call will set the thresholds for BCL monitoring and will enable hardware BCL monitoring. - int msm_bcl_set_threshold(enum bcl_param, enum bcl_trip_type, struct bcl_threshold *); Kernel drivers should use this interface to program the high trip and low trip thresholds along with their notification callbacks for battery voltage and current. - int msm_bcl_read(enum bcl_param, int *); Kernel driver can use this interface to read the last hardware sampled voltage and current reading in micro-volts and micro-ampere respectively. - struct bcl_param_data *msm_bcl_register_param(enum bcl_param, struct bcl_driver_ops *, char *); - int msm_bcl_unregister_param(struct bcl_param_data *); BCL hardware drivers should use this interface to register with the BCL framework. The BCL hardware drivers should define the ops functions required by the framework driver and provide that as input using the struct bcl_driver_ops parameter. The register function returns a struct bcl_param_data pointer on success, which can be used as input for unregistering the same from BCL framework driver. struct bcl_driver_ops { int (*read) (int *); int (*set_high_trip) (int); int (*get_high_trip) (int *); int (*set_low_trip) (int); int (*get_low_trip) (int *); int (*disable) (void); int (*enable) (void); int (*notify) (struct bcl_param_data *, int, enum bcl_trip_type); }; This BCL frmaework requires the BCL hardware drivers to have interfaces implementing the above functionalities. - read This function should read the last hardware sampled value. - set_high_trip - get_high_trip - set_low_trip - get_low_trip These functions should set and get the high trip and low trip. - disable - enable These functions should enable or disable the voltage or current param monitoring. -notify BCL framework populates this function pointer with a generic threshold handler interface. On reaching high/low trip, the BCL hardware driver should call this notification handler with appropriate input parameters. Change-Id: I5ee544bdf0bce7114f8251799ea32b121bb4464c Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
104 lines
2.7 KiB
C
104 lines
2.7 KiB
C
/*
|
|
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
* only version 2 as published by the Free Software Foundation.
|
|
*
|
|
* 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 __MSM_BCL_H
|
|
#define __MSM_BCL_H
|
|
|
|
#define BCL_NAME_MAX_LEN 20
|
|
|
|
enum bcl_trip_type {
|
|
BCL_HIGH_TRIP,
|
|
BCL_LOW_TRIP,
|
|
BCL_TRIP_MAX,
|
|
};
|
|
|
|
enum bcl_param {
|
|
BCL_PARAM_VOLTAGE,
|
|
BCL_PARAM_CURRENT,
|
|
BCL_PARAM_MAX,
|
|
};
|
|
|
|
struct bcl_threshold {
|
|
int trip_value;
|
|
enum bcl_trip_type type;
|
|
void *trip_data;
|
|
void (*trip_notify) (enum bcl_trip_type, int, void *);
|
|
};
|
|
struct bcl_param_data;
|
|
struct bcl_driver_ops {
|
|
int (*read) (int *);
|
|
int (*set_high_trip) (int);
|
|
int (*get_high_trip) (int *);
|
|
int (*set_low_trip) (int);
|
|
int (*get_low_trip) (int *);
|
|
int (*disable) (void);
|
|
int (*enable) (void);
|
|
int (*notify) (struct bcl_param_data *, int,
|
|
enum bcl_trip_type);
|
|
};
|
|
|
|
struct bcl_param_data {
|
|
char name[BCL_NAME_MAX_LEN];
|
|
struct device device;
|
|
struct bcl_driver_ops *ops;
|
|
int high_trip;
|
|
int low_trip;
|
|
int last_read_val;
|
|
bool registered;
|
|
struct kobj_attribute val_attr;
|
|
struct kobj_attribute high_trip_attr;
|
|
struct kobj_attribute low_trip_attr;
|
|
struct attribute_group bcl_attr_gp;
|
|
struct bcl_threshold *thresh[BCL_TRIP_MAX];
|
|
};
|
|
|
|
#ifdef CONFIG_MSM_BCL_CTL
|
|
struct bcl_param_data *msm_bcl_register_param(enum bcl_param,
|
|
struct bcl_driver_ops *, char *);
|
|
int msm_bcl_unregister_param(struct bcl_param_data *);
|
|
int msm_bcl_enable(void);
|
|
int msm_bcl_disable(void);
|
|
int msm_bcl_set_threshold(enum bcl_param, enum bcl_trip_type,
|
|
struct bcl_threshold *);
|
|
int msm_bcl_read(enum bcl_param, int *);
|
|
#else
|
|
static inline struct bcl_param_data *msm_bcl_register_param(
|
|
enum bcl_param param_type, struct bcl_driver_ops *ops, char *name)
|
|
{
|
|
return NULL;
|
|
}
|
|
static inline int msm_bcl_unregister_param(struct bcl_param_data *data)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
static inline int msm_bcl_enable(void)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
static inline int msm_bcl_disable(void)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
static inline int msm_bcl_set_threshold(enum bcl_param param_type,
|
|
enum bcl_trip_type type,
|
|
struct bcl_threshold *inp_thresh)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
static inline int msm_bcl_read(enum bcl_param param_type, int *vbat_value)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
#endif
|
|
|
|
#endif /*__MSM_BCL_H*/
|