blob: eb874e923fab4e33a9064e7a41502d39a1ca94b4 [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 PM8xxx Battery Alarm driver
14 *
15 */
16#ifndef __MFD_PM8XXX_BATT_ALARM_H__
17#define __MFD_PM8XXX_BATT_ALARM_H__
18
19#include <linux/bitops.h>
20#include <linux/errno.h>
21
22#define PM8XXX_BATT_ALARM_DEV_NAME "pm8xxx-batt-alarm"
23
24/**
25 * enum pm8xxx_batt_alarm_core_data - PMIC core specific core passed into the
26 * batter alarm driver as platform data
27 * @irq_name:
28 * @reg_addr_batt_alarm_threshold: PMIC threshold register address
29 * @reg_addr_batt_alarm_ctrl1: PMIC control 1 register address
30 * @reg_addr_batt_alarm_ctrl2: PMIC control 2 register address
31 * @reg_addr_batt_alarm_pwm_ctrl: PMIC PWM control register address
32 */
33struct pm8xxx_batt_alarm_core_data {
34 char *irq_name;
35 u16 reg_addr_threshold;
36 u16 reg_addr_ctrl1;
37 u16 reg_addr_ctrl2;
38 u16 reg_addr_pwm_ctrl;
39};
40
41/**
42 * enum pm8xxx_batt_alarm_comparator - battery alarm comparator ID values
43 */
44enum pm8xxx_batt_alarm_comparator {
45 PM8XXX_BATT_ALARM_LOWER_COMPARATOR,
46 PM8XXX_BATT_ALARM_UPPER_COMPARATOR,
47};
48
49/**
50 * enum pm8xxx_batt_alarm_hold_time - hold time required for out of range
51 * battery voltage needed to trigger a status change. Enum names denote
52 * hold time in milliseconds.
53 */
54enum pm8xxx_batt_alarm_hold_time {
55 PM8XXX_BATT_ALARM_HOLD_TIME_0p125_MS = 0,
56 PM8XXX_BATT_ALARM_HOLD_TIME_0p25_MS,
57 PM8XXX_BATT_ALARM_HOLD_TIME_0p5_MS,
58 PM8XXX_BATT_ALARM_HOLD_TIME_1_MS,
59 PM8XXX_BATT_ALARM_HOLD_TIME_2_MS,
60 PM8XXX_BATT_ALARM_HOLD_TIME_4_MS,
61 PM8XXX_BATT_ALARM_HOLD_TIME_8_MS,
62 PM8XXX_BATT_ALARM_HOLD_TIME_16_MS,
63};
64
65/*
66 * Bits that are set in the return value of pm8xxx_batt_alarm_status_read
67 * to indicate crossing of the upper or lower threshold.
68 */
69#define PM8XXX_BATT_ALARM_STATUS_BELOW_LOWER BIT(0)
70#define PM8XXX_BATT_ALARM_STATUS_ABOVE_UPPER BIT(1)
71
72#if defined(CONFIG_MFD_PM8XXX_BATT_ALARM) \
73 || defined(CONFIG_MFD_PM8XXX_BATT_ALARM_MODULE)
74
75/**
76 * pm8xxx_batt_alarm_enable - enable one of the battery voltage threshold
77 * comparators
78 * @comparator: selects which comparator to enable
79 *
80 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
81 */
82int pm8xxx_batt_alarm_enable(enum pm8xxx_batt_alarm_comparator comparator);
83
84/**
85 * pm8xxx_batt_alarm_disable - disable one of the battery voltage threshold
86 * comparators
87 * @comparator: selects which comparator to disable
88 *
89 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
90 */
91int pm8xxx_batt_alarm_disable(enum pm8xxx_batt_alarm_comparator comparator);
92
93
94/**
95 * pm8xxx_batt_alarm_threshold_set - set the lower and upper alarm thresholds
96 * @comparator: selects which comparator to set the threshold of
97 * @threshold_mV: battery voltage threshold in millivolts
98 * set points = 2500-5675 mV in 25 mV steps
99 *
100 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
101 */
102int pm8xxx_batt_alarm_threshold_set(
103 enum pm8xxx_batt_alarm_comparator comparator, int threshold_mV);
104
105/**
106 * pm8xxx_batt_alarm_status_read - get status of both threshold comparators
107 *
108 * RETURNS: < 0 = error
109 * 0 = battery voltage ok
110 * BIT(0) set = battery voltage below lower threshold
111 * BIT(1) set = battery voltage above upper threshold
112 */
113int pm8xxx_batt_alarm_status_read(void);
114
115/**
116 * pm8xxx_batt_alarm_register_notifier - register a notifier to run when a
117 * battery voltage change interrupt fires
118 * @nb: notifier block containing callback function to register
119 *
120 * nb->notifier_call must point to a function of this form -
121 * int (*notifier_call)(struct notifier_block *nb, unsigned long status,
122 * void *unused);
123 * "status" will receive the battery alarm status; "unused" will be NULL.
124 *
125 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
126 */
127int pm8xxx_batt_alarm_register_notifier(struct notifier_block *nb);
128
129/**
130 * pm8xxx_batt_alarm_unregister_notifier - unregister a notifier that is run
131 * when a battery voltage change interrupt fires
132 * @nb: notifier block containing callback function to unregister
133 *
134 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
135 */
136int pm8xxx_batt_alarm_unregister_notifier(struct notifier_block *nb);
137
138/**
139 * pm8xxx_batt_alarm_hold_time_set - set hold time of interrupt output *
140 * @hold_time: amount of time that battery voltage must remain outside of the
141 * threshold range before the battery alarm interrupt triggers
142 *
143 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
144 */
145int pm8xxx_batt_alarm_hold_time_set(enum pm8xxx_batt_alarm_hold_time hold_time);
146
147/**
148 * pm8xxx_batt_alarm_pwm_rate_set - set battery alarm update rate *
149 * @use_pwm: 1 = use PWM update rate, 0 = comparators always active
150 * @clock_scaler: PWM clock scaler = 2 to 9
151 * @clock_divider: PWM clock divider = 2 to 8
152 *
153 * This function sets the rate at which the battery alarm module enables
154 * the threshold comparators. The rate is determined by the following equation:
155 *
156 * f_update = (1024 Hz) / (clock_divider * (2 ^ clock_scaler))
157 *
158 * Thus, the update rate can range from 0.25 Hz to 128 Hz.
159 *
160 * RETURNS: an appropriate -ERRNO error value on error, or zero for success.
161 */
162int pm8xxx_batt_alarm_pwm_rate_set(int use_pwm, int clock_scaler,
163 int clock_divider);
164#else
165
166static inline int
167pm8xxx_batt_alarm_enable(enum pm8xxx_batt_alarm_comparator comparator)
168{ return -ENODEV; }
169
170static inline int
171pm8xxx_batt_alarm_disable(enum pm8xxx_batt_alarm_comparator comparator)
172{ return -ENODEV; }
173
174static inline int
175pm8xxx_batt_alarm_threshold_set(enum pm8xxx_batt_alarm_comparator comparator,
176 int threshold_mV)
177{ return -ENODEV; }
178
179static inline int pm8xxx_batt_alarm_status_read(void)
180{ return -ENODEV; }
181
182static inline int pm8xxx_batt_alarm_register_notifier(struct notifier_block *nb)
183{ return -ENODEV; }
184
185static inline int
186pm8xxx_batt_alarm_unregister_notifier(struct notifier_block *nb)
187{ return -ENODEV; }
188
189static inline int
190pm8xxx_batt_alarm_hold_time_set(enum pm8xxx_batt_alarm_hold_time hold_time)
191{ return -ENODEV; }
192
193static inline int
194pm8xxx_batt_alarm_pwm_rate_set(int use_pwm, int clock_scaler, int clock_divider)
195{ return -ENODEV; }
196
197#endif
198
199
200#endif /* __MFD_PM8XXX_BATT_ALARM_H__ */