2 * include/linux/mfd/rt5025.h
3 * Include header file for Richtek RT5025 Core file
5 * Copyright (C) 2013 Richtek Electronics
6 * cy_huang <cy_huang@richtek.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #ifndef __LINUX_MFD_RT5025_H
14 #define __LINUX_MFD_RT5025_H
16 #include <linux/power_supply.h>
18 #define RT5025_DEVICE_NAME "RT5025"
21 RT5025_RSTDELAY1_100MS,
22 RT5025_RSTDELAY1_500MS,
28 RT5025_RSTDELAY2_100MS,
29 RT5025_RSTDELAY2_500MS,
46 RT5025_STARTIME_100MS,
160 RT5025_MAX_REGULATOR,
163 struct rt5025_power_data {
166 unsigned char Resv1:1;
167 unsigned char CHGBC_EN:1;
169 unsigned char Resv2:1;
170 unsigned char CCCHG_TIMEOUT:2;
171 unsigned char PRECHG_TIMEOUT:2;
177 unsigned char Resv:2;
178 unsigned char VOREG:6;
184 unsigned char Resv:1;
185 unsigned char AICR:2;
187 unsigned char CHG_RST:1;
193 unsigned char Resv1:4;
195 unsigned char Resv2:2;
201 unsigned char IPREC:1;
202 unsigned char IEOC:1;
203 unsigned char VPREC:3;
204 unsigned char Resv:3;
210 unsigned char Resv1:4;
211 unsigned char CHGC_EN:1;
212 unsigned char CHG_DCDC_MODE:1;
213 unsigned char BATD_EN:1;
214 unsigned char Resv2:1;
220 struct rt5025_gpio_data {
225 struct rt5025_misc_data {
228 unsigned char Action:2;
229 unsigned char Delayed1:2;
230 unsigned char Delayed2:2;
231 unsigned char Resv:2;
237 unsigned char Resv:5;
238 unsigned char VOFF:3;
244 unsigned char PG_DLY:2;
245 unsigned char SHDN_PRESS:2;
246 unsigned char LPRESS_TIME:2;
247 unsigned char START_TIME:2;
253 unsigned char Resv:4;
254 unsigned char SHDN_DLYTIME:2;
255 unsigned char SHDN_TIMING:1;
256 unsigned char SHDN_CTRL:1;
262 unsigned char Resv:2;
263 unsigned char OT_ENSHDN:1;
264 unsigned char PWRON_ENSHDN:1;
265 unsigned char DCDC3LV_ENSHDN:1;
266 unsigned char DCDC2LV_ENSHDN:1;
267 unsigned char DCDC1LV_ENSHDN:1;
268 unsigned char SYSLV_ENSHDN:1;
274 struct rt5025_irq_data {
277 unsigned char BATABS:1;
278 unsigned char Resv1:2;
279 unsigned char INUSB_PLUGIN:1;
280 unsigned char INUSBOVP:1;
281 unsigned char Resv2:1;
282 unsigned char INAC_PLUGIN:1;
283 unsigned char INACOVP:1;
289 unsigned char CHTERMI:1;
290 unsigned char CHBATOVI:1;
291 unsigned char CHGOODI_INUSB:1;
292 unsigned char CHBADI_INUSB:1;
293 unsigned char CHSLPI_INUSB:1;
294 unsigned char CHGOODI_INAC:1;
295 unsigned char CHBADI_INAC:1;
296 unsigned char CHSLPI_INAC:1;
302 unsigned char TIMEOUT_CC:1;
303 unsigned char TIMEOUT_PC:1;
304 unsigned char Resv:3;
305 unsigned char CHVSREGI:1;
306 unsigned char CHTREGI:1;
307 unsigned char CHRCHGI:1;
313 unsigned char SYSLV:1;
314 unsigned char DCDC4LVHV:1;
315 unsigned char PWRONLP:1;
316 unsigned char PWRONSP:1;
317 unsigned char DCDC3LV:1;
318 unsigned char DCDC2LV:1;
319 unsigned char DCDC1LV:1;
326 unsigned char Resv:1;
327 unsigned char GPIO0_IE:1;
328 unsigned char GPIO1_IE:1;
329 unsigned char GPIO2_IE:1;
330 unsigned char RESETB:1;
331 unsigned char PWRONF:1;
332 unsigned char PWRONR:1;
333 unsigned char KPSHDN:1;
339 #define CHG_EVENT_INACOVP (0x80<<16)
340 #define CHG_EVENT_INAC_PLUGIN (0x40<<16)
341 #define CHG_EVENT_INUSBOVP (0x10<<16)
342 #define CHG_EVENT_INUSB_PLUGIN (0x08<<16)
343 #define CHG_EVENT_BAT_ABS (0x01<<16)
345 #define CHG_EVENT_CHSLPI_INAC (0x80<<8)
346 #define CHG_EVENT_CHBADI_INAC (0x40<<8)
347 #define CHG_EVENT_CHGOODI_INAC (0x20<<8)
348 #define CHG_EVENT_CHSLPI_INUSB (0x10<<8)
349 #define CHG_EVENT_CHBADI_INUSB (0x08<<8)
350 #define CHG_EVENT_CHGOODI_INUSB (0x04<<8)
351 #define CHG_EVENT_CHBATOVI (0x02<<8)
352 #define CHG_EVENT_CHTERMI (0x01<<8)
354 #define CHG_EVENT_CHRCHGI (0x80<<0)
355 #define CHG_EVENT_CHTREGI (0x40<<0)
356 #define CHG_EVENT_CHVSREGI (0x20<<0)
357 #define CHG_EVENT_TIMEOUTPC (0x02<<0)
358 #define CHG_EVENT_TIMEOUTCC (0x01<<0)
360 #define CHARGER_DETECT_MASK (CHG_EVENT_INAC_PLUGIN | CHG_EVENT_INUSB_PLUGIN | \
361 CHG_EVENT_CHSLPI_INAC | CHG_EVENT_CHSLPI_INUSB | \
362 CHG_EVENT_CHBADI_INAC | CHG_EVENT_CHBADI_INUSB)
364 #define PWR_EVENT_OTIQ (0x80<<8)
365 #define PWR_EVENT_DCDC1LV (0x40<<8)
366 #define PWR_EVENT_DCDC2LV (0x20<<8)
367 #define PWR_EVENT_DCDC3LV (0x10<<8)
368 #define PWR_EVENT_PWRONSP (0x08<<8)
369 #define PWR_EVENT_PWRONLP (0x04<<8)
370 #define PWR_EVENT_DCDC4LVHV (0x02<<8)
371 #define PWR_EVENT_SYSLV (0x01<<8)
373 #define PWR_EVENT_KPSHDN (0x80<<0)
374 #define PWR_EVNET_PWRONR (0x40<<0)
375 #define PWR_EVENT_PWRONF (0x20<<0)
376 #define PWR_EVENT_RESETB (0x10<<0)
377 #define PWR_EVENT_GPIO2IE (0x08<<0)
378 #define PWR_EVENT_GPIO1IE (0x04<<0)
379 #define PWR_EVENT_GPIO0IE (0x02<<0)
381 struct rt5025_event_callback {
383 void (*charger_event_callback)(uint32_t detected);
384 void (*power_event_callkback)(uint32_t detected);
386 void (*over_temperature_callback)(uint8_t detected);
387 void (*charging_complete_callback)(void);
388 void (*over_voltage_callback)(uint8_t detected);
389 void (*under_voltage_callback)(uint8_t detected);
390 void (*charge_fault_callback)(uint8_t detected);
391 void (*charge_warning_callback)(uint8_t detected);
395 struct rt5025_power_info {
396 struct i2c_client *i2c;
398 struct rt5025_gauge_callbacks *event_callback;
399 struct power_supply ac;
400 struct power_supply usb;
401 unsigned ac_online:1;
402 unsigned usb_online:1;
407 struct i2c_client *i2c;
408 struct workqueue_struct *wq;
410 struct rt5025_power_info *power_info;
413 struct delayed_work delayed_work;
414 struct mutex io_lock;
417 struct rt5025_platform_data {
418 struct regulator_init_data* regulator[RT5025_MAX_REGULATOR];
419 struct rt5025_power_data* power_data;
420 struct rt5025_gpio_data* gpio_data;
421 struct rt5025_misc_data* misc_data;
422 struct rt5025_irq_data* irq_data;
423 struct rt5025_event_callback *cb;
424 int (*pre_init)(struct rt5025_chip *rt5025_chip);
425 /** Called after subdevices are set up */
426 int (*post_init)(void);
430 #ifdef CONFIG_MFD_RT5025_MISC
431 extern void rt5025_power_off(void);
432 #endif /* CONFIG_MFD_RT5025_MISC */
434 #ifdef CONFIG_POWER_RT5025
435 extern int rt5025_gauge_init(struct rt5025_power_info *);
436 extern int rt5025_power_passirq_to_gauge(struct rt5025_power_info *);
437 extern int rt5025_power_charge_detect(struct rt5025_power_info *);
438 #endif /* CONFIG_POEWR_RT5025 */
440 extern int rt5025_reg_block_read(struct i2c_client *, int, int, void *);
441 extern int rt5025_reg_read(struct i2c_client *, int);
442 extern int rt5025_reg_write(struct i2c_client *, int, unsigned char);
443 extern int rt5025_assign_bits(struct i2c_client *, int, unsigned char, unsigned char);
444 extern int rt5025_set_bits(struct i2c_client *, int, unsigned char);
445 extern int rt5025_clr_bits(struct i2c_client *, int, unsigned char);
447 extern int rt5025_core_init(struct rt5025_chip *, struct rt5025_platform_data *);
448 extern int rt5025_core_deinit(struct rt5025_chip *);
450 #ifdef CONFIG_MFD_RT_SHOW_INFO
451 #define RTINFO(format, args...) \
452 printk(KERN_INFO "%s:%s() line-%d: " format, RT5025_DEVICE_NAME,__FUNCTION__,__LINE__, ##args)
454 #define RTINFO(format,args...)
455 #endif /* CONFIG_MFD_RT_SHOW_INFO */
457 #endif /* __LINUX_MFD_RT5025_H */