regulator: tps65090: Allow setting the overcurrent wait time
[cascardo/linux.git] / include / linux / mfd / tps65090.h
1 /*
2  * Core driver interface for TI TPS65090 PMIC family
3  *
4  * Copyright (C) 2012 NVIDIA Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  *
20  */
21
22 #ifndef __LINUX_MFD_TPS65090_H
23 #define __LINUX_MFD_TPS65090_H
24
25 #include <linux/irq.h>
26 #include <linux/regmap.h>
27
28 /* TPS65090 IRQs */
29 enum {
30         TPS65090_IRQ_INTERRUPT,
31         TPS65090_IRQ_VAC_STATUS_CHANGE,
32         TPS65090_IRQ_VSYS_STATUS_CHANGE,
33         TPS65090_IRQ_BAT_STATUS_CHANGE,
34         TPS65090_IRQ_CHARGING_STATUS_CHANGE,
35         TPS65090_IRQ_CHARGING_COMPLETE,
36         TPS65090_IRQ_OVERLOAD_DCDC1,
37         TPS65090_IRQ_OVERLOAD_DCDC2,
38         TPS65090_IRQ_OVERLOAD_DCDC3,
39         TPS65090_IRQ_OVERLOAD_FET1,
40         TPS65090_IRQ_OVERLOAD_FET2,
41         TPS65090_IRQ_OVERLOAD_FET3,
42         TPS65090_IRQ_OVERLOAD_FET4,
43         TPS65090_IRQ_OVERLOAD_FET5,
44         TPS65090_IRQ_OVERLOAD_FET6,
45         TPS65090_IRQ_OVERLOAD_FET7,
46 };
47
48 /* TPS65090 Regulator ID */
49 enum {
50         TPS65090_REGULATOR_DCDC1,
51         TPS65090_REGULATOR_DCDC2,
52         TPS65090_REGULATOR_DCDC3,
53         TPS65090_REGULATOR_FET1,
54         TPS65090_REGULATOR_FET2,
55         TPS65090_REGULATOR_FET3,
56         TPS65090_REGULATOR_FET4,
57         TPS65090_REGULATOR_FET5,
58         TPS65090_REGULATOR_FET6,
59         TPS65090_REGULATOR_FET7,
60         TPS65090_REGULATOR_LDO1,
61         TPS65090_REGULATOR_LDO2,
62
63         /* Last entry for maximum ID */
64         TPS65090_REGULATOR_MAX,
65 };
66
67 struct tps65090 {
68         struct device           *dev;
69         struct regmap           *rmap;
70         struct regmap_irq_chip_data *irq_data;
71 };
72
73 /*
74  * struct tps65090_regulator_plat_data
75  *
76  * @reg_init_data: The regulator init data.
77  * @enable_ext_control: Enable extrenal control or not. Only available for
78  *     DCDC1, DCDC2 and DCDC3.
79  * @gpio: Gpio number if external control is enabled and controlled through
80  *     gpio.
81  * @overcurrent_wait_valid: True if the overcurrent_wait should be applied.
82  * @overcurrent_wait: Value to set as the overcurrent wait time.  This is the
83  *     actual bitfield value, not a time in ms (valid value are 0 - 3).
84  */
85 struct tps65090_regulator_plat_data {
86         struct regulator_init_data *reg_init_data;
87         bool enable_ext_control;
88         int gpio;
89         bool overcurrent_wait_valid;
90         int overcurrent_wait;
91 };
92
93 struct tps65090_platform_data {
94         int irq_base;
95
96         char **supplied_to;
97         size_t num_supplicants;
98         int enable_low_current_chrg;
99
100         struct tps65090_regulator_plat_data *reg_pdata[TPS65090_REGULATOR_MAX];
101 };
102
103 /*
104  * NOTE: the functions below are not intended for use outside
105  * of the TPS65090 sub-device drivers
106  */
107 static inline int tps65090_write(struct device *dev, int reg, uint8_t val)
108 {
109         struct tps65090 *tps = dev_get_drvdata(dev);
110
111         return regmap_write(tps->rmap, reg, val);
112 }
113
114 static inline int tps65090_read(struct device *dev, int reg, uint8_t *val)
115 {
116         struct tps65090 *tps = dev_get_drvdata(dev);
117         unsigned int temp_val;
118         int ret;
119
120         ret = regmap_read(tps->rmap, reg, &temp_val);
121         if (!ret)
122                 *val = temp_val;
123         return ret;
124 }
125
126 static inline int tps65090_set_bits(struct device *dev, int reg,
127                 uint8_t bit_num)
128 {
129         struct tps65090 *tps = dev_get_drvdata(dev);
130
131         return regmap_update_bits(tps->rmap, reg, BIT(bit_num), ~0u);
132 }
133
134 static inline int tps65090_clr_bits(struct device *dev, int reg,
135                 uint8_t bit_num)
136 {
137         struct tps65090 *tps = dev_get_drvdata(dev);
138
139         return regmap_update_bits(tps->rmap, reg, BIT(bit_num), 0u);
140 }
141
142 #endif /*__LINUX_MFD_TPS65090_H */