2 * include/linux/mfd/ricoh619.h
4 * Core driver interface to access RICOH RC5T619 power management chip.
6 * Copyright (C) 2012-2013 RICOH COMPANY,LTD
9 * Copyright (C) 2011 NVIDIA Corporation
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.
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
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.
27 #ifndef __LINUX_MFD_RICOH619_H
28 #define __LINUX_MFD_RICOH619_H
30 #include <linux/mutex.h>
31 #include <linux/types.h>
32 #include <linux/gpio.h>
33 #include <linux/i2c.h>
35 /* Maximum number of main interrupts */
36 #define MAX_INTERRUPT_MASKS 13
37 #define MAX_MAIN_INTERRUPT 7
38 #define MAX_GPEDGE_REG 2
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
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
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
74 /* interrupt status registers (monitor regs)*/
75 #define RICOH619_INTC_INTPOL 0x9C
76 #define RICOH619_INTC_INTEN 0x9D
77 #define RICOH619_INTC_INTMON 0x9E
79 #define RICOH619_INT_MON_SYS 0x14
80 #define RICOH619_INT_MON_DCDC 0x42
81 #define RICOH619_INT_MON_RTC 0xAF
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
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
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
115 #define RICOH619_REG_BANKSEL 0xFF
117 /* Charger Control register */
118 #define RICOH619_CHG_CTL1 0xB3
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
127 #define RICOH619_FG_CTRL 0xE0
128 #define RICOH619_PSWR 0x07
130 /* RICOH619 IRQ definitions */
132 RICOH619_IRQ_POWER_ON,
134 RICOH619_IRQ_PRE_VINDT,
136 RICOH619_IRQ_POWER_OFF,
137 RICOH619_IRQ_NOE_OFF,
139 RICOH619_IRQ_CLK_STP,
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,
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,
165 RICOH619_IRQ_ADC_ENDIR,
176 RICOH619_IRQ_FVADPDETSINT,
177 RICOH619_IRQ_FVUSBDETSINT,
178 RICOH619_IRQ_FVADPLVSINT,
179 RICOH619_IRQ_FVUSBLVSINT,
180 RICOH619_IRQ_FWVADPSINT,
181 RICOH619_IRQ_FWVUSBSINT,
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,
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,
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,
212 RICOH619_IRQ_FWARN_ADP,
214 /* Should be last entry */
218 /* Ricoh619 gpio definitions */
229 enum ricoh619_sleep_control_id {
255 struct ricoh619_subdev_info {
262 struct ricoh619_rtc_platform_data {
264 struct rtc_time time;
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 */
278 struct i2c_client *client;
279 struct mutex io_lock;
281 struct gpio_chip gpio_chip;
283 // struct irq_chip irq_chip;
285 struct mutex irq_lock;
286 unsigned long group_irq_en[MAX_MAIN_INTERRUPT];
288 /* For main interrupt bits in INTC */
292 /* For group interrupt bits and address */
293 u8 irq_en_cache[MAX_INTERRUPT_MASKS];
294 u8 irq_en_reg[MAX_INTERRUPT_MASKS];
297 u8 gpedge_cache[MAX_GPEDGE_REG];
298 u8 gpedge_reg[MAX_GPEDGE_REG];
303 struct ricoh619_platform_data {
305 struct ricoh619_subdev_info *subdevs;
306 int (*init_port)(int irq_num); // Init GPIO for IRQ pin
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);
316 /* ==================================== */
317 /* RICOH619 Power_Key device data */
318 /* ==================================== */
319 struct ricoh619_pwrkey_platform_data {
321 unsigned long delay_ms;
323 extern int pwrkey_wakeup;
324 extern struct ricoh619 *g_ricoh619;
325 /* ==================================== */
326 /* RICOH619 battery device data */
327 /* ==================================== */
329 extern int g_fg_on_mode;
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,
335 extern int ricoh619_bulk_reads_bank1(struct device *dev, u8 reg, u8 count,
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,
341 extern int ricoh619_bulk_writes_bank1(struct device *dev, u8 reg, u8 count,
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,
347 extern int ricoh619_update_bank1(struct device *dev, u8 reg, uint8_t val,
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);