sdk-hwV1.3/lichee/xr806/appos/include/driver/component/axp/axp_common.h

275 lines
8.0 KiB
C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file axp.h
* @author XRADIO IOT WLAN Team
*/
/*
* Copyright (C) 2017 XRADIO TECHNOLOGY CO., LTD. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of XRADIO TECHNOLOGY CO., LTD. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __AXP_COMMON_H__
#define __AXP_COMMON_H__
#include "driver/chip/hal_gpio.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#define axp_err(fmt...) printf("[axp_bmu][err]: " fmt)
#define axp_info(fmt...) printf("[axp_bmu][info]: " fmt)
#define axp_warn(fmt...) printf("[axp_bmu][warn]: " fmt)
#ifndef u32
typedef unsigned int u32;
#endif
enum power_supply_property;
union power_supply_propval;
enum axp_boot_source {
AXP_BOOT_SOURCE_BUTTON = 0,
AXP_BOOT_SOURCE_IRQ_LOW = 1,
AXP_BOOT_SOURCE_VBUS_USB = 2,
AXP_BOOT_SOURCE_CHARGER = 3,
AXP_BOOT_SOURCE_BATTERY = 4,
AXP_BOOT_SOURCE_UNKOWN = 5,
};
enum power_key_status{
POWER_KEY_PRESS = 0,
POWER_KEY_RELEASE,
POWER_KEY_UNKNOW,
};
struct axp_gpio_attribute{
GPIO_Port power_on_sys_port;
GPIO_Pin power_on_sys_pin;
GPIO_Port irq_port;
GPIO_Pin irq_pin;
GPIO_Port power_ok_port;
GPIO_Pin power_ok_pin;
};
/* enum system_state_t {
* SYSTEM_STATUS_NORMAL,
* SYSTEM_STATUS_RESUME,
* SYSTEM_STATUS_SUSPEND,
* SYSTEM_STATUS_UNKNOW,
* }; */
struct axp2101_model_data;
struct axp_config_info{
u32 pmu_id;
u32 pmu_battery_rdc;
u32 pmu_battery_cap;
u32 pmu_bat_det;
u32 pmu_chg_ic_temp;
u32 pmu_pre_chg;
u32 pmu_iterm_limit;
u32 pmu_runtime_chgcur;
u32 pmu_suspend_chgcur;
u32 pmu_shutdown_chgcur;
u32 pmu_init_chgvol;
u32 pmu_init_chgend_rate;
u32 pmu_init_chg_enabled;
u32 pmu_init_bc_en;
u32 pmu_init_adc_freq;
u32 pmu_init_adcts_freq;
u32 pmu_init_chg_pretime;
u32 pmu_init_chg_csttime;
u32 pmu_batt_cap_correct;
u32 pmu_chg_end_on_en;
u32 ocv_coulumb_100;
u32 pmu_btn_chg_en;
u32 pmu_btn_chg_cfg;
u32 pmu_ac_vol;
u32 pmu_ac_cur;
u32 pmu_usbpc_vol;
u32 pmu_usbpc_cur;
u32 pmu_usbad_vol;
u32 pmu_usbad_cur;
u32 pmu_pwroff_vol;
u32 pmu_pwron_vol;
u32 pmu_powkey_off_time;
u32 pmu_powkey_off_en;
u32 pmu_powkey_off_delay_time;
u32 pmu_powkey_off_func;
u32 pmu_powkey_long_time;
u32 pmu_powkey_on_time;
u32 pmu_powkey_wakeup_irq;
u32 pmu_pwrok_time;
u32 pmu_pwrnoe_time;
u32 pmu_reset_shutdown_en;
u32 pmu_battery_warning_level1;
u32 pmu_battery_warning_level2;
u32 pmu_restvol_adjust_time;
u32 pmu_ocv_cou_adjust_time;
u32 pmu_chgled_func;
u32 pmu_chgled_enable;
u32 pmu_chgled_type;
u32 pmu_vbusen_func;
u32 pmu_reset;
u32 pmu_irq_wakeup;
u32 pmu_hot_shutdown;
u32 pmu_inshort;
u32 power_start;
u32 pmu_as_slave;
u32 pmu_bat_unused;
u32 pmu_ocv_en;
u32 pmu_cou_en;
u32 pmu_update_min_time;
u32 pmu_bat_temp_enable;
u32 pmu_bat_ts_current;
u32 pmu_bat_charge_ltf;
u32 pmu_bat_charge_htf;
/* 设置电池过温关机值 */
u32 pmu_bat_shutdown_ltf;
/* 设置电池欠温关机值 */
u32 pmu_bat_shutdown_htf;
u32 pmu_bat_temp_para1;
u32 pmu_bat_temp_para2;
u32 pmu_bat_temp_para3;
u32 pmu_bat_temp_para4;
u32 pmu_bat_temp_para5;
u32 pmu_bat_temp_para6;
u32 pmu_bat_temp_para7;
u32 pmu_bat_temp_para8;
u32 pmu_bat_temp_para9;
u32 pmu_bat_temp_para10;
u32 pmu_bat_temp_para11;
u32 pmu_bat_temp_para12;
u32 pmu_bat_temp_para13;
u32 pmu_bat_temp_para14;
u32 pmu_bat_temp_para15;
u32 pmu_bat_temp_para16;
/* 设置电池过压关机机值不设置默认超过5V关机 */
u32 pmu_bat_over_vol;
/* u32 wakeup_usb_in;
* u32 wakeup_usb_out;
* u32 wakeup_bat_in;
* u32 wakeup_bat_out;
* u32 wakeup_bat_charging;
* u32 wakeup_bat_charge_over;
* u32 wakeup_low_warning1;
* u32 wakeup_low_warning2; */
/* 打开电池欠温关机功能,默认打开 */
u32 bat_untemp_work_shut_down;
/* 打开电池过温关机功能,默认打开 */
u32 bat_ovtemp_work_shut_down;
/* u32 wakeup_untemp_chg;
* u32 wakeup_ovtemp_chg; */
/* 使能芯片过温检测功能,默认打开,可不配置 */
u32 pmu_die_ovtemp_detect;
/* 设置pmu芯片过温过机115/125/135度 only three value
* 默认配置i125度过温关机*/
u32 pmu_die_ovtemp_shut_down;
u32 pmu_powerkey_irq_enable;
struct axp2101_model_data *data;
};
extern struct sunxi_pmu_dev_t pmu_axp2101_driver;
extern struct sunxi_bmu_dev_t bmu_axp2101_driver;
extern struct axp_irq_dev_t axp2101_irq_driver;
struct sunxi_pmu_dev_t {
const char *pmu_name;
int (*probe)(struct axp_gpio_attribute *gpio_attribute); /* matches chipid*/
int (*deinit)(void);
int (*get_info)(char *name, unsigned char *chipid); /*get axp info*/
int (*set_voltage)(char *name, unsigned int vol_value, unsigned int onoff); /*Set a certain power, voltage value. */
int (*get_voltage)(char *name, int *voltage); /*Read a certain power, voltage value */
int (*set_power_on)(bool restart); /*Set poweron*/
int (*set_power_off)(void); /*Set shutdown*/
enum axp_boot_source (*get_poweron_source)(void); /* Get the reason for triggering the boot, (button to power on, power on)*/
int (*set_sys_mode)(int status); /*Sets the state of the next mode */
int (*set_dcdc_mode)(const char *name, int mode); /*force dcdc mode in pwm or not */
int (*get_sys_mode)(void); /*Get the current state*/
int (*get_key_irq)(void); /*Get the button length interrupt*/
int (*set_bus_vol_limit)(int voltage); /*Set limit total voltage*/
int (*get_bus_vol_limit)(int *voltage); /*Get limit total voltage*/
int (*get_reg_value)(uint8_t reg, uint8_t *data);/*get register value*/
int (*set_reg_value)(uint8_t reg, uint8_t data);/*set register value*/
void (*dump_whole_reg)(void);
};
struct sunxi_bmu_dev_t {
const char *bmu_name;
int (*probe)(void); /* matches chipid*/
int (*set_charge_current_limit)(int current); /*Set the current charge size*/
int (*get_charge_current_limit)(void); /* get the current charge */
int (*get_bmu_version)(void); /* get bmu chipid */
int (*set_battery_param)(struct axp_config_info *param_info);
int (*get_battery_property)(enum power_supply_property psp, union power_supply_propval *val);
};
struct axp_irq_dev_t {
int (*probe)(void);
int (*init)(struct axp_gpio_attribute *gpio_attribute);
int (*deinit)(struct axp_gpio_attribute *gpio_attribute);
enum power_key_status (*get_powerkey_status)(void);
};
typedef struct sunxi_pmu_dev_list {
char *name; // pmu name
struct sunxi_pmu_dev_t *pmu_driver;
struct sunxi_bmu_dev_t *bmu_driver;
struct axp_irq_dev_t *irq_driver;
} sunxi_pmu_dev_list;
static sunxi_pmu_dev_list axp_table[] = {
{
"pmu",
&pmu_axp2101_driver,
&bmu_axp2101_driver,
&axp2101_irq_driver,
},
};
static const unsigned int SIZE_OF_AXP_TABLE = sizeof(axp_table) / sizeof(sunxi_pmu_dev_list);
#ifdef __cplusplus
}
#endif
#endif /* __AXP_COMMON_H__ */