blob: 0a0ac78e6fab006d1a4ed7d530d5ebddd1bfc485 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12/*
13 * Qualcomm PMIC 8058 Battery Alarm Device driver
14 *
15 */
16#ifndef __PMIC8058_BATT_ALARM_H__
17#define __PMIC8058_BATT_ALARM_H__
18
19#include <linux/bitops.h>
20
21/**
22 * enum pm8058_batt_alarm_hold_time - hold time required for out of range
23 * battery voltage needed to trigger a status change. Enum names denote
24 * hold time in milliseconds.
25 */
26enum pm8058_batt_alarm_hold_time {
27 PM8058_BATT_ALARM_HOLD_TIME_0p125_MS = 0,
28 PM8058_BATT_ALARM_HOLD_TIME_0p25_MS,
29 PM8058_BATT_ALARM_HOLD_TIME_0p5_MS,
30 PM8058_BATT_ALARM_HOLD_TIME_1_MS,
31 PM8058_BATT_ALARM_HOLD_TIME_2_MS,
32 PM8058_BATT_ALARM_HOLD_TIME_4_MS,
33 PM8058_BATT_ALARM_HOLD_TIME_8_MS,
34 PM8058_BATT_ALARM_HOLD_TIME_16_MS,
35};
36
37/*
38 * Bits that are set in the return value of pm8058_batt_alarm_status_read
39 * to indicate crossing of the upper or lower threshold.
40 */
41#define PM8058_BATT_ALARM_STATUS_BELOW_LOWER BIT(0)
42#define PM8058_BATT_ALARM_STATUS_ABOVE_UPPER BIT(1)
43
44/**
45 * pm8058_batt_alarm_state_set - enable or disable the threshold comparators
46 * @enable_lower_comparator: 1 = enable comparator, 0 = disable comparator
47 * @enable_upper_comparator: 1 = enable comparator, 0 = disable comparator
48 *
49 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
50 */
51int pm8058_batt_alarm_state_set(int enable_lower_comparator,
52 int enable_upper_comparator);
53
54/**
55 * pm8058_batt_alarm_threshold_set - set the lower and upper alarm thresholds
56 * @lower_threshold_mV: battery undervoltage threshold in millivolts
57 * @upper_threshold_mV: battery overvoltage threshold in millivolts
58 *
59 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
60 */
61int pm8058_batt_alarm_threshold_set(int lower_threshold_mV,
62 int upper_threshold_mV);
63
64/**
65 * pm8058_batt_alarm_status_read - get status of both threshold comparators
66 *
67 * RETURNS: < 0 = error
68 * 0 = battery voltage ok
69 * BIT(0) set = battery voltage below lower threshold
70 * BIT(1) set = battery voltage above upper threshold
71 */
72int pm8058_batt_alarm_status_read(void);
73
74/**
75 * pm8058_batt_alarm_register_notifier - register a notifier to run when a
76 * battery voltage change interrupt fires
77 * @nb: notifier block containing callback function to register
78 *
79 * nb->notifier_call must point to a function of this form -
80 * int (*notifier_call)(struct notifier_block *nb, unsigned long status,
81 * void *unused);
82 * "status" will receive the battery alarm status; "unused" will be NULL.
83 *
84 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
85 */
86int pm8058_batt_alarm_register_notifier(struct notifier_block *nb);
87
88/**
89 * pm8058_batt_alarm_unregister_notifier - unregister a notifier that is run
90 * when a battery voltage change interrupt fires
91 * @nb: notifier block containing callback function to unregister
92 *
93 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
94 */
95int pm8058_batt_alarm_unregister_notifier(struct notifier_block *nb);
96
97/**
98 * pm8058_batt_alarm_hold_time_set - set hold time of interrupt output *
99 * @hold_time: amount of time that battery voltage must remain outside of the
100 * threshold range before the battery alarm interrupt triggers
101 *
102 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
103 */
104int pm8058_batt_alarm_hold_time_set(enum pm8058_batt_alarm_hold_time hold_time);
105
106/**
107 * pm8058_batt_alarm_pwm_rate_set - set battery alarm update rate *
108 * @use_pwm: 1 = use PWM update rate, 0 = comparators always active
109 * @clock_scaler: PWM clock scaler = 2 to 9
110 * @clock_divider: PWM clock divider = 2 to 8
111 *
112 * This function sets the rate at which the battery alarm module enables
113 * the threshold comparators. The rate is determined by the following equation:
114 *
115 * f_update = (1024 Hz) / (clock_divider * (2 ^ clock_scaler))
116 *
117 * Thus, the update rate can range from 0.25 Hz to 128 Hz.
118 *
119 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
120 */
121int pm8058_batt_alarm_pwm_rate_set(int use_pwm, int clock_scaler,
122 int clock_divider);
123
124#endif /* __PMIC8058_BATT_ALARM_H__ */