Commit Graph

1 Commits

Author SHA1 Message Date
Ram Chandrasekar 0171e31d02 bcl: Add BCL framework driver
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>
2014-08-01 18:26:55 -06:00