ricoh619:support pmic ricoh619
[firefly-linux-kernel-4.4.55.git] / include / linux / mfd / ricoh619.h
1 /* 
2  * include/linux/mfd/ricoh619.h
3  *
4  * Core driver interface to access RICOH RC5T619 power management chip.
5  *
6  * Copyright (C) 2012-2013 RICOH COMPANY,LTD
7  *
8  * Based on code
9  *      Copyright (C) 2011 NVIDIA Corporation
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19  * more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24  *
25  */
26
27 #ifndef __LINUX_MFD_RICOH619_H
28 #define __LINUX_MFD_RICOH619_H
29
30 #include <linux/mutex.h>
31 #include <linux/types.h>
32 #include <linux/gpio.h>
33 #include <linux/i2c.h>
34
35 /* Maximum number of main interrupts */
36 #define MAX_INTERRUPT_MASKS     13
37 #define MAX_MAIN_INTERRUPT      7
38 #define MAX_GPEDGE_REG          2
39
40 /* Power control register */
41 #define RICOH619_PWR_WD                 0x0B
42 #define RICOH619_PWR_WD_COUNT           0x0C
43 #define RICOH619_PWR_FUNC               0x0D
44 #define RICOH619_PWR_SLP_CNT            0x0E
45 #define RICOH619_PWR_REP_CNT            0x0F
46 #define RICOH619_PWR_ON_TIMSET          0x10
47 #define RICOH619_PWR_NOE_TIMSET         0x11
48 #define RICOH619_PWR_IRSEL              0x15
49
50 /* Interrupt enable register */
51 #define RICOH619_INT_EN_SYS             0x12
52 #define RICOH619_INT_EN_DCDC            0x40
53 #define RICOH619_INT_EN_RTC             0xAE
54 #define RICOH619_INT_EN_ADC1            0x88
55 #define RICOH619_INT_EN_ADC2            0x89
56 #define RICOH619_INT_EN_ADC3            0x8A
57 #define RICOH619_INT_EN_GPIO            0x94
58 #define RICOH619_INT_EN_GPIO2           0x94 // dummy
59 #define RICOH619_INT_MSK_CHGCTR         0xBE
60 #define RICOH619_INT_MSK_CHGSTS1        0xBF
61 #define RICOH619_INT_MSK_CHGSTS2        0xC0
62 #define RICOH619_INT_MSK_CHGERR         0xC1
63 #define RICOH619_INT_MSK_CHGEXTIF       0xD1
64
65 /* Interrupt select register */
66 #define RICOH619_PWR_IRSEL                      0x15
67 #define RICOH619_CHG_CTRL_DETMOD1       0xCA
68 #define RICOH619_CHG_CTRL_DETMOD2       0xCB
69 #define RICOH619_CHG_STAT_DETMOD1       0xCC
70 #define RICOH619_CHG_STAT_DETMOD2       0xCD
71 #define RICOH619_CHG_STAT_DETMOD3       0xCE
72
73
74 /* interrupt status registers (monitor regs)*/
75 #define RICOH619_INTC_INTPOL            0x9C
76 #define RICOH619_INTC_INTEN             0x9D
77 #define RICOH619_INTC_INTMON            0x9E
78
79 #define RICOH619_INT_MON_SYS            0x14
80 #define RICOH619_INT_MON_DCDC           0x42
81 #define RICOH619_INT_MON_RTC            0xAF
82
83 #define RICOH619_INT_MON_CHGCTR         0xC6
84 #define RICOH619_INT_MON_CHGSTS1        0xC7
85 #define RICOH619_INT_MON_CHGSTS2        0xC8
86 #define RICOH619_INT_MON_CHGERR         0xC9
87 #define RICOH619_INT_MON_CHGEXTIF       0xD3
88
89 /* interrupt clearing registers */
90 #define RICOH619_INT_IR_SYS             0x13
91 #define RICOH619_INT_IR_DCDC            0x41
92 #define RICOH619_INT_IR_RTC             0xAF
93 #define RICOH619_INT_IR_ADCL            0x8C
94 #define RICOH619_INT_IR_ADCH            0x8D
95 #define RICOH619_INT_IR_ADCEND          0x8E
96 #define RICOH619_INT_IR_GPIOR           0x95
97 #define RICOH619_INT_IR_GPIOF           0x96
98 #define RICOH619_INT_IR_CHGCTR          0xC2
99 #define RICOH619_INT_IR_CHGSTS1         0xC3
100 #define RICOH619_INT_IR_CHGSTS2         0xC4
101 #define RICOH619_INT_IR_CHGERR          0xC5
102 #define RICOH619_INT_IR_CHGEXTIF        0xD2
103
104 /* GPIO register base address */
105 #define RICOH619_GPIO_IOSEL             0x90
106 #define RICOH619_GPIO_IOOUT             0x91
107 #define RICOH619_GPIO_GPEDGE1           0x92
108 #define RICOH619_GPIO_GPEDGE2           0x93
109 //#define RICOH619_GPIO_EN_GPIR         0x94
110 //#define RICOH619_GPIO_IR_GPR          0x95
111 //#define RICOH619_GPIO_IR_GPF          0x96
112 #define RICOH619_GPIO_MON_IOIN          0x97
113 #define RICOH619_GPIO_LED_FUNC          0x98
114
115 #define RICOH619_REG_BANKSEL            0xFF
116
117 /* Charger Control register */
118 #define RICOH619_CHG_CTL1               0xB3
119
120 /* ADC Control register */
121 #define RICOH619_ADC_CNT1               0x64
122 #define RICOH619_ADC_CNT2               0x65
123 #define RICOH619_ADC_CNT3               0x66
124 #define RICOH619_ADC_VADP_THL           0x7C
125 #define RICOH619_ADC_VSYS_THL           0x80
126
127 #define RICOH619_FG_CTRL                0xE0
128 #define RICOH619_PSWR                   0x07
129
130 /* RICOH619 IRQ definitions */
131 enum {
132         RICOH619_IRQ_POWER_ON,
133         RICOH619_IRQ_EXTIN,
134         RICOH619_IRQ_PRE_VINDT,
135         RICOH619_IRQ_PREOT,
136         RICOH619_IRQ_POWER_OFF,
137         RICOH619_IRQ_NOE_OFF,
138         RICOH619_IRQ_WD,
139         RICOH619_IRQ_CLK_STP,
140
141         RICOH619_IRQ_DC1LIM,
142         RICOH619_IRQ_DC2LIM,
143         RICOH619_IRQ_DC3LIM,
144         RICOH619_IRQ_DC4LIM,
145         RICOH619_IRQ_DC5LIM,
146
147         RICOH619_IRQ_ILIMLIR,
148         RICOH619_IRQ_VBATLIR,
149         RICOH619_IRQ_VADPLIR,
150         RICOH619_IRQ_VUSBLIR,
151         RICOH619_IRQ_VSYSLIR,
152         RICOH619_IRQ_VTHMLIR,
153         RICOH619_IRQ_AIN1LIR,
154         RICOH619_IRQ_AIN0LIR,
155         
156         RICOH619_IRQ_ILIMHIR,
157         RICOH619_IRQ_VBATHIR,
158         RICOH619_IRQ_VADPHIR,
159         RICOH619_IRQ_VUSBHIR,
160         RICOH619_IRQ_VSYSHIR,
161         RICOH619_IRQ_VTHMHIR,
162         RICOH619_IRQ_AIN1HIR,
163         RICOH619_IRQ_AIN0HIR,
164
165         RICOH619_IRQ_ADC_ENDIR,
166
167         RICOH619_IRQ_GPIO0,
168         RICOH619_IRQ_GPIO1,
169         RICOH619_IRQ_GPIO2,
170         RICOH619_IRQ_GPIO3,
171         RICOH619_IRQ_GPIO4,
172
173         RICOH619_IRQ_CTC,
174         RICOH619_IRQ_DALE,
175
176         RICOH619_IRQ_FVADPDETSINT,
177         RICOH619_IRQ_FVUSBDETSINT,
178         RICOH619_IRQ_FVADPLVSINT,
179         RICOH619_IRQ_FVUSBLVSINT,
180         RICOH619_IRQ_FWVADPSINT,
181         RICOH619_IRQ_FWVUSBSINT,
182
183         RICOH619_IRQ_FONCHGINT,
184         RICOH619_IRQ_FCHGCMPINT,
185         RICOH619_IRQ_FBATOPENINT,
186         RICOH619_IRQ_FSLPMODEINT,
187         RICOH619_IRQ_FBTEMPJTA1INT,
188         RICOH619_IRQ_FBTEMPJTA2INT,
189         RICOH619_IRQ_FBTEMPJTA3INT,
190         RICOH619_IRQ_FBTEMPJTA4INT,
191
192         RICOH619_IRQ_FCURTERMINT,
193         RICOH619_IRQ_FVOLTERMINT,
194         RICOH619_IRQ_FICRVSINT,
195         RICOH619_IRQ_FPOOR_CHGCURINT,
196         RICOH619_IRQ_FOSCFDETINT1,
197         RICOH619_IRQ_FOSCFDETINT2,
198         RICOH619_IRQ_FOSCFDETINT3,
199         RICOH619_IRQ_FOSCMDETINT,
200
201         RICOH619_IRQ_FDIEOFFINT,
202         RICOH619_IRQ_FDIEERRINT,
203         RICOH619_IRQ_FBTEMPERRINT,
204         RICOH619_IRQ_FVBATOVINT,
205         RICOH619_IRQ_FTTIMOVINT,
206         RICOH619_IRQ_FRTIMOVINT,
207         RICOH619_IRQ_FVADPOVSINT,
208         RICOH619_IRQ_FVUSBOVSINT,
209
210         RICOH619_IRQ_FGCDET,
211         RICOH619_IRQ_FPCDET,
212         RICOH619_IRQ_FWARN_ADP,
213
214         /* Should be last entry */
215         RICOH619_NR_IRQS,
216 };
217
218 /* Ricoh619 gpio definitions */
219 enum {
220         RICOH619_GPIO0,
221         RICOH619_GPIO1,
222         RICOH619_GPIO2,
223         RICOH619_GPIO3,
224         RICOH619_GPIO4,
225
226         RICOH619_NR_GPIO,
227 };
228
229 enum ricoh619_sleep_control_id {
230         RICOH619_DS_DC1,
231         RICOH619_DS_DC2,
232         RICOH619_DS_DC3,
233         RICOH619_DS_DC4,
234         RICOH619_DS_DC5,
235         RICOH619_DS_LDO1,
236         RICOH619_DS_LDO2,
237         RICOH619_DS_LDO3,
238         RICOH619_DS_LDO4,
239         RICOH619_DS_LDO5,
240         RICOH619_DS_LDO6,
241         RICOH619_DS_LDO7,
242         RICOH619_DS_LDO8,
243         RICOH619_DS_LDO9,
244         RICOH619_DS_LDO10,
245         RICOH619_DS_LDORTC1,
246         RICOH619_DS_LDORTC2,
247         RICOH619_DS_PSO0,
248         RICOH619_DS_PSO1,
249         RICOH619_DS_PSO2,
250         RICOH619_DS_PSO3,
251         RICOH619_DS_PSO4,
252 };
253
254
255 struct ricoh619_subdev_info {
256         int             id;
257         const char      *name;
258         void            *platform_data;
259 };
260
261 /*
262 struct ricoh619_rtc_platform_data {
263         int irq;
264         struct rtc_time time;
265 };
266 */
267
268 struct ricoh619_gpio_init_data {
269         unsigned output_mode_en:1;      /* Enable output mode during init */
270         unsigned output_val:1;          /* Output value if it is in output mode */
271         unsigned init_apply:1;          /* Apply init data on configuring gpios*/
272         unsigned led_mode:1;            /* Select LED mode during init */
273         unsigned led_func:1;            /* Set LED function if LED mode is 1 */
274 };
275
276 struct ricoh619 {
277         struct device           *dev;
278         struct i2c_client       *client;
279         struct mutex            io_lock;
280         int                     gpio_base;
281         struct gpio_chip        gpio_chip;
282         int                     irq_base;
283 //      struct irq_chip         irq_chip;
284         int                     chip_irq;
285         struct mutex            irq_lock;
286         unsigned long           group_irq_en[MAX_MAIN_INTERRUPT];
287
288         /* For main interrupt bits in INTC */
289         u8                      intc_inten_cache;
290         u8                      intc_inten_reg;
291
292         /* For group interrupt bits and address */
293         u8                      irq_en_cache[MAX_INTERRUPT_MASKS];
294         u8                      irq_en_reg[MAX_INTERRUPT_MASKS];
295
296         /* For gpio edge */
297         u8                      gpedge_cache[MAX_GPEDGE_REG];
298         u8                      gpedge_reg[MAX_GPEDGE_REG];
299
300         int                     bank_num;
301 };
302
303 struct ricoh619_platform_data {
304         int             num_subdevs;
305         struct  ricoh619_subdev_info *subdevs;
306         int (*init_port)(int irq_num); // Init GPIO for IRQ pin
307         int             gpio_base;
308         int             irq_base;
309         struct ricoh619_gpio_init_data *gpio_init_data;
310         int num_gpioinit_data;
311         bool enable_shutdown_pin;
312         int (*pre_init)(struct ricoh619 *ricoh619);
313         int (*post_init)(struct ricoh619 *ricoh619);
314 };
315
316 /* ==================================== */
317 /* RICOH619 Power_Key device data       */
318 /* ==================================== */
319 struct ricoh619_pwrkey_platform_data {
320         int irq;
321         unsigned long delay_ms;
322 };
323 extern int pwrkey_wakeup;
324 extern struct ricoh619 *g_ricoh619;
325 /* ==================================== */
326 /* RICOH619 battery device data */
327 /* ==================================== */
328 extern int g_soc;
329 extern int g_fg_on_mode;
330
331 extern int ricoh619_read(struct device *dev, uint8_t reg, uint8_t *val);
332 extern int ricoh619_read_bank1(struct device *dev, uint8_t reg, uint8_t *val);
333 extern int ricoh619_bulk_reads(struct device *dev, u8 reg, u8 count,
334                                                                 uint8_t *val);
335 extern int ricoh619_bulk_reads_bank1(struct device *dev, u8 reg, u8 count,
336                                                                 uint8_t *val);
337 extern int ricoh619_write(struct device *dev, u8 reg, uint8_t val);
338 extern int ricoh619_write_bank1(struct device *dev, u8 reg, uint8_t val);
339 extern int ricoh619_bulk_writes(struct device *dev, u8 reg, u8 count,
340                                                                 uint8_t *val);
341 extern int ricoh619_bulk_writes_bank1(struct device *dev, u8 reg, u8 count,
342                                                                 uint8_t *val);
343 extern int ricoh619_set_bits(struct device *dev, u8 reg, uint8_t bit_mask);
344 extern int ricoh619_clr_bits(struct device *dev, u8 reg, uint8_t bit_mask);
345 extern int ricoh619_update(struct device *dev, u8 reg, uint8_t val,
346                                                                 uint8_t mask);
347 extern int ricoh619_update_bank1(struct device *dev, u8 reg, uint8_t val,
348                                                                 uint8_t mask);
349 extern int ricoh619_power_off(void);
350 extern int ricoh619_irq_init(struct ricoh619 *ricoh619, int irq, int irq_base);
351 extern int ricoh619_irq_exit(struct ricoh619 *ricoh619);
352 extern int ricoh619_power_off(void);
353
354 #endif