ricoh619:ricoh619 pmu modify set mode and init reg
[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 #define RICOH_DC1_SLOT 0x16
131 #define RICOH_DC2_SLOT 0x17
132 #define RICOH_DC3_SLOT 0x18
133 #define RICOH_DC4_SLOT 0x19
134 #define RICOH_DC5_SLOT 0x1a
135
136 #define RICOH_LDO1_SLOT 0x1b
137 #define RICOH_LDO2_SLOT 0x1c
138 #define RICOH_LDO3_SLOT 0x1d
139 #define RICOH_LDO4_SLOT 0x1e
140 #define RICOH_LDO5_SLOT 0x1f
141 #define RICOH_LDO6_SLOT 0x20
142 #define RICOH_LDO7_SLOT 0x21
143 #define RICOH_LDO8_SLOT 0x22
144 #define RICOH_LDO9_SLOT 0x23
145 #define RICOH_LDO10_SLOT 0x24
146
147
148
149 /* RICOH619 IRQ definitions */
150 enum {
151         RICOH619_IRQ_POWER_ON,
152         RICOH619_IRQ_EXTIN,
153         RICOH619_IRQ_PRE_VINDT,
154         RICOH619_IRQ_PREOT,
155         RICOH619_IRQ_POWER_OFF,
156         RICOH619_IRQ_NOE_OFF,
157         RICOH619_IRQ_WD,
158         RICOH619_IRQ_CLK_STP,
159
160         RICOH619_IRQ_DC1LIM,
161         RICOH619_IRQ_DC2LIM,
162         RICOH619_IRQ_DC3LIM,
163         RICOH619_IRQ_DC4LIM,
164         RICOH619_IRQ_DC5LIM,
165
166         RICOH619_IRQ_ILIMLIR,
167         RICOH619_IRQ_VBATLIR,
168         RICOH619_IRQ_VADPLIR,
169         RICOH619_IRQ_VUSBLIR,
170         RICOH619_IRQ_VSYSLIR,
171         RICOH619_IRQ_VTHMLIR,
172         RICOH619_IRQ_AIN1LIR,
173         RICOH619_IRQ_AIN0LIR,
174         
175         RICOH619_IRQ_ILIMHIR,
176         RICOH619_IRQ_VBATHIR,
177         RICOH619_IRQ_VADPHIR,
178         RICOH619_IRQ_VUSBHIR,
179         RICOH619_IRQ_VSYSHIR,
180         RICOH619_IRQ_VTHMHIR,
181         RICOH619_IRQ_AIN1HIR,
182         RICOH619_IRQ_AIN0HIR,
183
184         RICOH619_IRQ_ADC_ENDIR,
185
186         RICOH619_IRQ_GPIO0,
187         RICOH619_IRQ_GPIO1,
188         RICOH619_IRQ_GPIO2,
189         RICOH619_IRQ_GPIO3,
190         RICOH619_IRQ_GPIO4,
191
192         RICOH619_IRQ_CTC,
193         RICOH619_IRQ_DALE,
194
195         RICOH619_IRQ_FVADPDETSINT,
196         RICOH619_IRQ_FVUSBDETSINT,
197         RICOH619_IRQ_FVADPLVSINT,
198         RICOH619_IRQ_FVUSBLVSINT,
199         RICOH619_IRQ_FWVADPSINT,
200         RICOH619_IRQ_FWVUSBSINT,
201
202         RICOH619_IRQ_FONCHGINT,
203         RICOH619_IRQ_FCHGCMPINT,
204         RICOH619_IRQ_FBATOPENINT,
205         RICOH619_IRQ_FSLPMODEINT,
206         RICOH619_IRQ_FBTEMPJTA1INT,
207         RICOH619_IRQ_FBTEMPJTA2INT,
208         RICOH619_IRQ_FBTEMPJTA3INT,
209         RICOH619_IRQ_FBTEMPJTA4INT,
210
211         RICOH619_IRQ_FCURTERMINT,
212         RICOH619_IRQ_FVOLTERMINT,
213         RICOH619_IRQ_FICRVSINT,
214         RICOH619_IRQ_FPOOR_CHGCURINT,
215         RICOH619_IRQ_FOSCFDETINT1,
216         RICOH619_IRQ_FOSCFDETINT2,
217         RICOH619_IRQ_FOSCFDETINT3,
218         RICOH619_IRQ_FOSCMDETINT,
219
220         RICOH619_IRQ_FDIEOFFINT,
221         RICOH619_IRQ_FDIEERRINT,
222         RICOH619_IRQ_FBTEMPERRINT,
223         RICOH619_IRQ_FVBATOVINT,
224         RICOH619_IRQ_FTTIMOVINT,
225         RICOH619_IRQ_FRTIMOVINT,
226         RICOH619_IRQ_FVADPOVSINT,
227         RICOH619_IRQ_FVUSBOVSINT,
228
229         RICOH619_IRQ_FGCDET,
230         RICOH619_IRQ_FPCDET,
231         RICOH619_IRQ_FWARN_ADP,
232
233         /* Should be last entry */
234         RICOH619_NR_IRQS,
235 };
236
237 /* Ricoh619 gpio definitions */
238 enum {
239         RICOH619_GPIO0,
240         RICOH619_GPIO1,
241         RICOH619_GPIO2,
242         RICOH619_GPIO3,
243         RICOH619_GPIO4,
244
245         RICOH619_NR_GPIO,
246 };
247
248 enum ricoh619_sleep_control_id {
249         RICOH619_DS_DC1,
250         RICOH619_DS_DC2,
251         RICOH619_DS_DC3,
252         RICOH619_DS_DC4,
253         RICOH619_DS_DC5,
254         RICOH619_DS_LDO1,
255         RICOH619_DS_LDO2,
256         RICOH619_DS_LDO3,
257         RICOH619_DS_LDO4,
258         RICOH619_DS_LDO5,
259         RICOH619_DS_LDO6,
260         RICOH619_DS_LDO7,
261         RICOH619_DS_LDO8,
262         RICOH619_DS_LDO9,
263         RICOH619_DS_LDO10,
264         RICOH619_DS_LDORTC1,
265         RICOH619_DS_LDORTC2,
266         RICOH619_DS_PSO0,
267         RICOH619_DS_PSO1,
268         RICOH619_DS_PSO2,
269         RICOH619_DS_PSO3,
270         RICOH619_DS_PSO4,
271 };
272
273
274 struct ricoh619_subdev_info {
275         int             id;
276         const char      *name;
277         void            *platform_data;
278 };
279
280 /*
281 struct ricoh619_rtc_platform_data {
282         int irq;
283         struct rtc_time time;
284 };
285 */
286
287 struct ricoh619_gpio_init_data {
288         unsigned output_mode_en:1;      /* Enable output mode during init */
289         unsigned output_val:1;          /* Output value if it is in output mode */
290         unsigned init_apply:1;          /* Apply init data on configuring gpios*/
291         unsigned led_mode:1;            /* Select LED mode during init */
292         unsigned led_func:1;            /* Set LED function if LED mode is 1 */
293 };
294
295 struct ricoh619 {
296         struct device           *dev;
297         struct i2c_client       *client;
298         struct mutex            io_lock;
299         int                     gpio_base;
300         struct gpio_chip        gpio_chip;
301         int                     irq_base;
302 //      struct irq_chip         irq_chip;
303         int                     chip_irq;
304         struct mutex            irq_lock;
305         unsigned long           group_irq_en[MAX_MAIN_INTERRUPT];
306
307         /* For main interrupt bits in INTC */
308         u8                      intc_inten_cache;
309         u8                      intc_inten_reg;
310
311         /* For group interrupt bits and address */
312         u8                      irq_en_cache[MAX_INTERRUPT_MASKS];
313         u8                      irq_en_reg[MAX_INTERRUPT_MASKS];
314
315         /* For gpio edge */
316         u8                      gpedge_cache[MAX_GPEDGE_REG];
317         u8                      gpedge_reg[MAX_GPEDGE_REG];
318
319         int                     bank_num;
320 };
321
322 struct ricoh619_platform_data {
323         int             num_subdevs;
324         struct  ricoh619_subdev_info *subdevs;
325         int (*init_port)(int irq_num); // Init GPIO for IRQ pin
326         int             gpio_base;
327         int             irq_base;
328         struct ricoh619_gpio_init_data *gpio_init_data;
329         int num_gpioinit_data;
330         bool enable_shutdown_pin;
331         int (*pre_init)(struct ricoh619 *ricoh619);
332         int (*post_init)(struct ricoh619 *ricoh619);
333 };
334
335 /* ==================================== */
336 /* RICOH619 Power_Key device data       */
337 /* ==================================== */
338 struct ricoh619_pwrkey_platform_data {
339         int irq;
340         unsigned long delay_ms;
341 };
342 extern int pwrkey_wakeup;
343 extern struct ricoh619 *g_ricoh619;
344 /* ==================================== */
345 /* RICOH619 battery device data */
346 /* ==================================== */
347 extern int g_soc;
348 extern int g_fg_on_mode;
349
350 extern int ricoh619_read(struct device *dev, uint8_t reg, uint8_t *val);
351 extern int ricoh619_read_bank1(struct device *dev, uint8_t reg, uint8_t *val);
352 extern int ricoh619_bulk_reads(struct device *dev, u8 reg, u8 count,
353                                                                 uint8_t *val);
354 extern int ricoh619_bulk_reads_bank1(struct device *dev, u8 reg, u8 count,
355                                                                 uint8_t *val);
356 extern int ricoh619_write(struct device *dev, u8 reg, uint8_t val);
357 extern int ricoh619_write_bank1(struct device *dev, u8 reg, uint8_t val);
358 extern int ricoh619_bulk_writes(struct device *dev, u8 reg, u8 count,
359                                                                 uint8_t *val);
360 extern int ricoh619_bulk_writes_bank1(struct device *dev, u8 reg, u8 count,
361                                                                 uint8_t *val);
362 extern int ricoh619_set_bits(struct device *dev, u8 reg, uint8_t bit_mask);
363 extern int ricoh619_clr_bits(struct device *dev, u8 reg, uint8_t bit_mask);
364 extern int ricoh619_update(struct device *dev, u8 reg, uint8_t val,
365                                                                 uint8_t mask);
366 extern int ricoh619_update_bank1(struct device *dev, u8 reg, uint8_t val,
367                                                                 uint8_t mask);
368 extern int ricoh619_power_off(void);
369 extern int ricoh619_irq_init(struct ricoh619 *ricoh619, int irq, int irq_base);
370 extern int ricoh619_irq_exit(struct ricoh619 *ricoh619);
371 extern int ricoh619_power_off(void);
372
373 #endif