162 lines
4.7 KiB
C
162 lines
4.7 KiB
C
#ifndef __DRV_PM_PMC_H__
|
||
#define __DRV_PM_PMC_H__
|
||
|
||
#include "xmedia_type.h"
|
||
|
||
//#define PM_WAKEUP1_SUPPORT
|
||
|
||
#define WAKEUP_EXT_GPIO_NUM 1
|
||
|
||
#define PWR_BASE_ADDR 0x120f0000
|
||
#define PMR_STATUS_OFFSET 0x4
|
||
#define PWR_STATUS_WAKEUP_SOURCE GENMASK(6, 2)
|
||
#define PWR_PD_SEL_OFFSET 0x8
|
||
#define PWR_CTRL0_OFFSET 0x10
|
||
#define PWR_POWER_UNMASK (BIT(1) | BIT(0))
|
||
#define PWR_WAKEUP_POLARITY (BIT(3) | BIT(4))
|
||
#define PWR_RTC_MASK BIT(5)
|
||
#define PWR_WAKEUP_MASK BIT(6)
|
||
#define PWR_STARTUP_MASK BIT(16)
|
||
#define PWR_BUTTON_ADJ_MASK BIT(28)
|
||
#define PWR_BUTTON_ADJ_MASK_SHIFT 28
|
||
#define PWR_BUTTON_ADJ_TIME_MASK GENMASK(27,20)
|
||
#define PWR_BUTTON_ADJ_TIME_SHIFT 20
|
||
#define PWR_CTRL1_OFFSET 0x14
|
||
#define PWM_BUTTON_CTRL_OFFSET 0x18
|
||
#define PWR_STARTUP_CRTL_OFFSET 0x20
|
||
#define PWR_RSTN_CRTL_OFFSET 0x24
|
||
#define PWR_SEQ_CRTL_OFFSET 0x28
|
||
#define PWR_WAKEUP_CRTL_OFFSET 0x30
|
||
#define PWR_WAKEUPN_IOSHARE BIT(8)
|
||
#define PWR_WAKEUP_PD BIT(3)
|
||
#define PWR_WAKEUP_PU BIT(2)
|
||
#define PWR_WAKEUP_DS_MASK (0x3)
|
||
#define PWR_WAKEUP_DS_1 0x0
|
||
#define PWR_WAKEUP_DS_2 0x1
|
||
#define PWR_WAKEUP_DS_3 0x2
|
||
#define PWR_WAKEUP_DS_4 0x3
|
||
#define PWR_EN_CRTL_OFFSET 0x34
|
||
#define PWR_WAKEUP1_CRTL_OFFSET 0x38
|
||
|
||
#define PWR_BUTTON_ADJ_TIME_MAX 255 //<=25.5s
|
||
|
||
/*
|
||
* 0x120f0050 在待机的时候保存linux唤醒入口地址,
|
||
* 跳转内核之前保存唤醒状态,
|
||
* 刚进入aux读取PMR_STATUS_OFFSET到aux的中保存
|
||
*/
|
||
#define PWR_STATUS_BACKUP_OFFSET 0x50
|
||
#define WAKEUP_STATUS_GPIO0_MASK 0x100
|
||
#define WAKEUP_STATUS_GPIO1_MASK 0x400
|
||
|
||
typedef enum {
|
||
PMC_SRC_WAKEUP = 0,
|
||
PMC_SRC_STARTUP,
|
||
PMC_SRC_BUTTON,
|
||
PMC_SRC_RTC,
|
||
PMC_SRC_MAX,
|
||
} lotus_pmc_wakeup_type;
|
||
|
||
#ifdef PM_WAKEUP1_SUPPORT
|
||
/*
|
||
* 当type为PM_WKMODE_WAKEUP(gpio唤醒时),detail为唤醒gpio号,唤醒gpio号与xmedia_pm_attr中的唤醒gpio号对应
|
||
* 当type为PM_WKMODE_STARTUP, detail无意义
|
||
* 当type为PM_WKMODE_BUTTON,detail无意义
|
||
* 当type为PM_WKMODE_RTC,detail无意义
|
||
*/
|
||
typedef struct {
|
||
lotus_pmc_wakeup_type type;
|
||
xmedia_u32 detail;
|
||
} lotus_pm_wakeup_info;
|
||
#endif
|
||
|
||
typedef enum {
|
||
PMC_PWR_RISING_EDGE = 0,
|
||
PMC_PWR_FALLING_EDGE,
|
||
PMC_PWR_HIGH_LEVEL,
|
||
PMC_PWR_LOW_LEVEL,
|
||
PMC_PWR_MAX,
|
||
} lotus_pmc_wakeup_polarity;
|
||
|
||
typedef struct {
|
||
xmedia_bool rtc_enable; // 1:表示使能
|
||
xmedia_u32 rtc_timeout; // 单位为10ms
|
||
} lotus_pmc_rtc_attr;
|
||
|
||
typedef struct {
|
||
xmedia_bool wakeup_enable; // 1:表示使能
|
||
lotus_pmc_wakeup_polarity wakeup_polarity; //上升沿、下降沿、高电平和低电平触发
|
||
} lotus_pmc_wakeup_attr;
|
||
|
||
typedef struct {
|
||
xmedia_bool button_adj_enable; //1:表示使能
|
||
xmedia_u32 button_adj_time; //button触发时间,精度100ms
|
||
}lotus_pmc_button_attr;
|
||
|
||
/*
|
||
* wakeup_attr: 对应唤醒gpio0的配置
|
||
* wakeup_ext_attr_arry[0] 对应唤醒gpio1开始的其他唤醒gpio的配置
|
||
* 如果唤醒gpio0和唤醒gpio1同时使用,只支持高电平唤醒,同时高电平持续时间必须大于xxms
|
||
*/
|
||
typedef struct {
|
||
lotus_pmc_wakeup_attr wakeup_attr;
|
||
xmedia_bool startup_enable;
|
||
xmedia_bool button_enable;
|
||
lotus_pmc_button_attr button_attr;
|
||
lotus_pmc_rtc_attr rtc_attr;
|
||
#ifdef PM_WAKEUP1_SUPPORT
|
||
lotus_pmc_wakeup_attr wakeup_ext_attr_arry[WAKEUP_EXT_GPIO_NUM];
|
||
#endif
|
||
} lotus_pmc_all_attr;
|
||
|
||
typedef struct {
|
||
xmedia_u64 rtc_delta_time; // 单位为1ms
|
||
xmedia_u64 rtc_current_time;
|
||
xmedia_u64 rtc_last_suspend_time;
|
||
} lotus_pm_rtc_info;
|
||
|
||
typedef enum {
|
||
CMD_PM_INIT = 0,
|
||
CMD_PM_DEINIT,
|
||
CMD_PM_SET_ALL_ATTR,
|
||
CMD_PM_GET_ALL_ATTR,
|
||
CMD_PM_GET_RTC_ATTR,
|
||
CMD_PM_SET_RTC_ATTR,
|
||
CMD_PM_GET_WK_ATTR,
|
||
CMD_PM_SET_WK_ATTR,
|
||
CMD_PM_GET_WK_SOURCE,
|
||
CMD_PM_SET_AUX,
|
||
CMD_PM_GET_DDR_PARAM,
|
||
CMD_PM_GET_RTC_INFO,
|
||
#ifdef PM_WAKEUP1_SUPPORT
|
||
CMD_PM_GET_WK_INFO,
|
||
#endif
|
||
CMD_PM_GET_RTC_TIMER,
|
||
CMD_PM_END = 0xFFFF,
|
||
} pm_ioctl_cmd;
|
||
|
||
struct aux_mem {
|
||
xmedia_u64 phy_addr;
|
||
xmedia_u32 size;
|
||
};
|
||
|
||
xmedia_s32 lotus_pmc_init(xmedia_void);
|
||
xmedia_void lotus_pmc_deinit(xmedia_void);
|
||
xmedia_s32 lotus_get_wakeup_type(lotus_pmc_wakeup_type *type);
|
||
#ifdef PM_WAKEUP1_SUPPORT
|
||
xmedia_s32 lotus_pm_get_wakeup_info(lotus_pm_wakeup_info *info);
|
||
#endif
|
||
xmedia_s32 lotus_set_all_attr(lotus_pmc_all_attr *attr);
|
||
xmedia_s32 lotus_get_all_attr(lotus_pmc_all_attr *attr);
|
||
xmedia_s32 lotus_set_wakeup_attr(lotus_pmc_wakeup_attr *attr);
|
||
xmedia_s32 lotus_get_wakeup_attr(lotus_pmc_wakeup_attr *attr);
|
||
xmedia_s32 lotus_set_button_attr(lotus_pmc_button_attr *attr);
|
||
xmedia_s32 lotus_get_button_attr(lotus_pmc_button_attr *attr);
|
||
xmedia_s32 lotus_set_rtc_attr(lotus_pmc_rtc_attr *attr);
|
||
xmedia_s32 lotus_get_rtc_attr(lotus_pmc_rtc_attr *attr);
|
||
xmedia_void lotus_get_rtc_timer(xmedia_void);
|
||
xmedia_s32 lotus_pmc_set_aux(struct aux_mem *aux);
|
||
xmedia_s32 lotus_pm_get_rtc_info(lotus_pm_rtc_info *info);
|
||
|
||
#endif
|