#ifndef _AXP210X_H_ #define _AXP210X_H_ #include "linux/types.h" #define AXP210X_MANUFACTURER "X-POWERS" /* AXP210X params */ #define AXP2101_VERSION (0x18) #define AXP2101_INVALID_REGADDR (0x22) #define AXP2101_DEBUG 1 typedef union { uint8_t byte; struct { unsigned sleep: 1; unsigned r1: 3; unsigned por: 1; unsigned reset: 1; unsigned r2: 2; }; } reg_mode_t; typedef union { uint8_t byte; struct { unsigned bromupen: 1; unsigned r0: 3; unsigned update_mark: 1; unsigned enwdt: 1; unsigned r1: 2; }; } reg_config_t; typedef union { uint8_t byte; struct { unsigned lowsoc: 1; unsigned newsoc: 1; unsigned ot: 1; unsigned wdt: 1; unsigned r : 4; }; } reg_irq_t; typedef union { uint8_t byte; struct { unsigned lowsoc: 1; unsigned newsoc: 1; unsigned ot: 1; unsigned wdt: 1; unsigned r : 4; }; } reg_irqmask_t; struct axp210x_reg_t { uint8_t brom; reg_mode_t mode; reg_config_t config; uint16_t vbat; uint8_t temp; uint8_t soc; uint16_t t2e; uint16_t t2f; uint8_t lowsocth; reg_irq_t irq; reg_irqmask_t irqmask; }; enum axp210x_regaddr_index { AXP210X_REG_ID = 0, AXP210X_REG_BROM, AXP210X_REG_MODE, AXP210X_REG_CONFIG, AXP210X_REG_VBAT, AXP210X_REG_COMSTAT0, AXP210X_REG_TM, AXP210X_REG_SOC, AXP210X_REG_T2E, AXP210X_REG_T2F, AXP210X_REG_LOWSOC, AXP210X_REG_IRQ, AXP210X_REG_IRQMASK, AXP210X_REG_MAX, AXP210X_REG_IIN_LIM, AXP210X_REG_ICC_CFG, AXP210X_COMM_STAT1, AXP210X_COMM_STAT0, AXP210X_CHGLED_CFG, AXP210X_MODULE_EN, }; enum axp210x_chip { AXP2101 = 0, }; struct axp210x_model_data { uint8_t *model; size_t model_size; }; enum axp210x_irq { AXP210x_IRQ_WDT = 0x08, AXP210X_IRQ_OT = 0x04, AXP210X_IRQ_NEWSOC = 0x02, AXP210X_IRQ_LOWSOC = 0x01, AXP210X_IRQ_ALL = 0x0F, }; struct axp210x_state { int bat_stat; int bat_full; int bat_read; }; struct axp210x_device_info { char *name; struct device *dev; uint8_t batnum; enum axp210x_chip chip; struct axp_config_info dts_info; uint8_t *regaddrs; struct axp210x_reg_t regcache; struct axp210x_model_data data; struct task_struct *poll_read; struct gpio_desc *gpiod; struct axp_regmap *regmap; int virq; int version; struct power_supply *bat; struct power_supply *usb; struct power_supply *ac; struct delayed_work bat_chk; struct axp210x_state stat; int (*read)(uint8_t regaddr, uint8_t *regdata, uint8_t bytenum); int (*write)(uint8_t regaddr, uint8_t *regdata, uint8_t bytenum); }; /*****************Debug************************/ #if (AXP2101_DEBUG) extern u32 debug_level; /* Message always need to be present even in release version. */ #define XPOWER_DBG_ALWY 1 /* Error message to report an error, it can hardly works. */ #define XPOWER_DBG_ERROR 2 /* Warning message to inform us of something unnormal or * something very important, but it still work. */ #define XPOWER_DBG_WARN 3 /* Important message we need to know in unstable version. */ #define XPOWER_DBG_INFO 4 /* Normal message just for debug in developing stage. */ #define XPOWER_DBG_DEBUG 5 #define XPOWER_DBG_DEFAULT XPOWER_DBG_WARN #define axp210x_alway(...) \ printk(KERN_ERR "[AXP210X]" __VA_ARGS__); #define axp210x_err(...) \ do { \ if (debug_level >= XPOWER_DBG_ERROR) \ printk(KERN_ERR "[AXP210X_ERR]" __VA_ARGS__); \ } while (0) #define axp210x_warn(...) \ do { \ if (debug_level >= XPOWER_DBG_WARN) \ printk(KERN_ERR "[AXP210X_WARN]" __VA_ARGS__); \ } while (0) #define axp210x_info(...) \ do { \ if (debug_level >= XPOWER_DBG_INFO) \ printk(KERN_ERR "[AXP210X_INFO]" __VA_ARGS__); \ } while (0) #define axp210x_debug(...) \ do { \ if (debug_level >= XPOWER_DBG_DEBUG) \ printk(KERN_ERR "[AXP210X_DBG]" __VA_ARGS__); \ } while (0) #else #define axp210x_alway(...) #define axp210x_err(...) #define axp210x_warn(...) #define axp210x_info(...) #define axp210x_debug(...) #endif #endif