[Feature][T108][system][task-view-1692]Merged gsw hal code
Only Configure: No
Affected branch: GSW_V1453
Affected module: libgsw
Is it affected on IC: only ASR
Self-test: yes
Doc Update: no
Change-Id: I7fb669b6afc6e2f92a1e86ec8543498eb73120b4
diff --git a/mbtk/libgsw_lib/gsw_hwpin_interface.c b/mbtk/libgsw_lib/gsw_hwpin_interface.c
index 9837b97..d132b01 100755
--- a/mbtk/libgsw_lib/gsw_hwpin_interface.c
+++ b/mbtk/libgsw_lib/gsw_hwpin_interface.c
@@ -8,6 +8,7 @@
#include <dlfcn.h>
#include "gsw_hwpin_interface.h"
+#include "gsw_hal_errcode.h"
#ifndef LOG_ERR_LEVEL
#define LOG_ERR_LEVEL 3 /* error conditions */
@@ -96,9 +97,7 @@
} \
fun_ptr_log(LOG_ERR_LEVEL, "%s#%s: "GSW_GPIO"" fmt, ptr_1001 + 1, line_1001, ##args); \
} while(0)
-
-#define GSW_HAL_MEM_INVAILD -2 //表示入参地址为NULL
#define wakeout 117
typedef enum{
@@ -167,7 +166,6 @@
return -1;
}
- memset(pin_index_buffer,0,5);
sprintf(pin_index_buffer,"%d", gpio);
result = write(file,pin_index_buffer,strlen(pin_index_buffer));
if(result < 0)
@@ -199,7 +197,6 @@
return -1;
}
- memset(pin_index_buffer,0,5);
sprintf(pin_index_buffer,"%d", gpio);
result=write(file,pin_index_buffer,strlen(pin_index_buffer));
if(result < 0)
@@ -261,8 +258,8 @@
char path[128];
int file =-1;
int result =-1;
- memset(path,0,128);
- memset(buffer,0,50);
+ memset(path,0,sizeof(path));
+ memset(buffer,0,sizeof(buffer));
if (handle())
return GSW_HAL_NORMAL_FAIL;
@@ -396,3 +393,382 @@
}
return GSW_HAL_SUCCESS;
}
+
+#define SYS_LED_DEV_TRIGGER_NODE "/sys/class/leds/red/trigger"
+#define SYS_LED_DEV_BRIGHTNES_NODE "/sys/class/leds/red/brightness"
+#define SYS_LED_DEV_DELAY_OFF_NODE "/sys/class/leds/red/delay_off"
+#define SYS_LED_DEV_DELAY_ON_NODE "/sys/class/leds/red/delay_on"
+#define EMMC_HEALTH_FILE "/sys/kernel/debug/mmc0/mmc0:0001/health"
+#define MDM_RESET_MCU 19
+#define MDM_BOOT_MCU_CTRL 31
+#define MDM_PWRMDM_EN 116
+#define MDM_WAKEUP_MCU 117
+
+int gsw_hwpin_mcu_reset(void)
+{
+ if (0 != gsw_gpio_Init(MDM_RESET_MCU, GSW_HAL_PINDIR_OUT, GSW_HAL_LEVEL_LOW, GSW_HAL_PULL_DOWN))
+ {
+ LOGE("init GPIO %d fail!", MDM_RESET_MCU);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(1000);
+ if (0 != gsw_gpio_SetLevel(MDM_RESET_MCU, GSW_HAL_LEVEL_HIGH))
+ {
+ LOGE("set GPIO %d : %d fail!", MDM_RESET_MCU, GSW_HAL_LEVEL_HIGH);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(100000);
+ if (0 != gsw_gpio_SetLevel(MDM_RESET_MCU, GSW_HAL_LEVEL_LOW))
+ {
+ LOGE("set GPIO %d : %d fail!", MDM_RESET_MCU, GSW_HAL_LEVEL_LOW);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(100000);
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_mcu_enter_bootmode(void)
+{
+ if (0 != gsw_gpio_Init(MDM_BOOT_MCU_CTRL, GSW_HAL_PINDIR_OUT, GSW_HAL_LEVEL_LOW, GSW_HAL_PULL_DOWN))
+ {
+ LOGE("init GPIO %d fail!", MDM_BOOT_MCU_CTRL);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(1000);
+ if (0 != gsw_gpio_SetLevel(MDM_BOOT_MCU_CTRL, GSW_HAL_LEVEL_HIGH))
+ {
+ LOGE("set GPIO %d : %d fail!", MDM_BOOT_MCU_CTRL, GSW_HAL_LEVEL_HIGH);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(100000);
+ return gsw_hwpin_mcu_reset();
+}
+
+int gsw_hwpin_mcu_exit_bootmode(void)
+{
+ if (0 != gsw_gpio_Init(MDM_BOOT_MCU_CTRL, GSW_HAL_PINDIR_OUT, GSW_HAL_LEVEL_LOW, GSW_HAL_PULL_DOWN))
+ {
+ LOGE("init GPIO %d fail!", MDM_BOOT_MCU_CTRL);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(1000);
+ if (0 != gsw_gpio_SetLevel(MDM_BOOT_MCU_CTRL, GSW_HAL_LEVEL_LOW))
+ {
+ LOGE("set GPIO %d : %d fail!", MDM_BOOT_MCU_CTRL, GSW_HAL_LEVEL_LOW);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(100000);
+ return gsw_hwpin_mcu_reset();
+}
+
+int gsw_hwpin_soc_power_keep(void)
+{
+ return 0;
+}
+
+int gsw_hwpin_soc_power_release(void)
+{
+ return 0;
+}
+
+static int _gsw_hwpin_soc_power_down(void)
+{
+ if (0 != gsw_gpio_Init(MDM_PWRMDM_EN, GSW_HAL_PINDIR_OUT, GSW_HAL_LEVEL_LOW, GSW_HAL_PULL_DOWN))
+ {
+ LOGE("init GPIO %d fail!", MDM_BOOT_MCU_CTRL);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ usleep(1000);
+ if (0 != gsw_gpio_SetLevel(MDM_PWRMDM_EN, GSW_HAL_LEVEL_HIGH))
+ {
+ LOGE("set GPIO %d : %d fail!", MDM_PWRMDM_EN, GSW_HAL_LEVEL_HIGH);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_tcam_reset(void)
+{
+ if (gsw_hwpin_mcu_reset() < 0)
+ return GSW_HAL_NORMAL_FAIL;
+ usleep(10000);
+ return _gsw_hwpin_soc_power_down();
+}
+
+int gsw_hwpin_soc_wakeup_mcu(void)
+{
+ if (0 != gsw_setWakeupLevel(GSW_HAL_LEVEL_HIGH))
+ {
+ LOGE("wakeup mcu fail!");
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_soc_wakeup_mcu_gpio_set_low(void)
+{
+ if (0 != gsw_setWakeupLevel(GSW_HAL_LEVEL_LOW))
+ {
+ LOGE("wakeup mcu set low fail!");
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ return GSW_HAL_SUCCESS;
+}
+
+static int _file_read(const char *file, char *value, unsigned int len)
+{
+ int fd = 0;
+ int ret = 0;
+ fd = open(file, O_RDONLY);
+ if(fd <= 0) {
+ LOGE("[hwpin] open file error %d,%s", fd, file);
+ return GSW_HAL_ERROR_FILE_OPEN;
+ }
+ if(value && len > 0) {
+ ret = read(fd, value, len);
+ }
+ close(fd);
+ if(ret < 0) {
+ LOGE("[hwpin] read file error %d,%s",ret, file);
+ }
+ return ret;
+}
+
+static int _file_write(const char *file, char *value)
+{
+ int fd = 0;
+ int ret = 0;
+ fd = open(file, O_WRONLY);
+ if(fd <= 0) {
+ LOGE("[hwpin] open file error %d,%s", fd, file);
+ return GSW_HAL_ERROR_FILE_OPEN;
+ }
+ if(value) {
+ ret = write(fd, value, strlen(value));
+ }
+ close(fd);
+ if(ret < 0) {
+ LOGE("[hwpin] write file error %d,%s",ret, file);
+ }
+ return ret;
+}
+
+int gsw_hwpin_led_red_on(void)
+{
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_led_red_off(void)
+{
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_led_red_blink(int delay_on, int delay_off)
+{
+ return GSW_HAL_SUCCESS;
+}
+
+static bool g_aging_flag = false;
+int gsw_hwpin_led_green_on(void)
+{
+ if (true == g_aging_flag)
+ {
+ LOGI("green on LED file fail g_aging_flag = %d", g_aging_flag);
+ return GSW_HAL_SUCCESS;
+ }
+
+ if (access(SYS_LED_DEV_TRIGGER_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_TRIGGER_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (_file_write(SYS_LED_DEV_TRIGGER_NODE, "none") <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_TRIGGER_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (access(SYS_LED_DEV_BRIGHTNES_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_BRIGHTNES_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (_file_write(SYS_LED_DEV_BRIGHTNES_NODE, "1") <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_BRIGHTNES_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_led_green_off(void)
+{
+ if (true == g_aging_flag)
+ {
+ LOGI("green off LED file fail g_aging_flag = %d", g_aging_flag);
+ return GSW_HAL_SUCCESS;
+ }
+
+ if (access(SYS_LED_DEV_TRIGGER_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_TRIGGER_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (_file_write(SYS_LED_DEV_TRIGGER_NODE, "none") <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_TRIGGER_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (access(SYS_LED_DEV_BRIGHTNES_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_BRIGHTNES_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (_file_write(SYS_LED_DEV_BRIGHTNES_NODE, "0") <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_BRIGHTNES_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_led_green_blink(int delay_on, int delay_off)
+{
+ char buf[32] = {0};
+
+ if (true == g_aging_flag)
+ {
+ LOGI("green blink LED file fail g_aging_flag = %d", g_aging_flag);
+ return GSW_HAL_SUCCESS;
+ }
+
+ if (access(SYS_LED_DEV_TRIGGER_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_TRIGGER_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (_file_write(SYS_LED_DEV_TRIGGER_NODE, "timer") <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_TRIGGER_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (access(SYS_LED_DEV_DELAY_OFF_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_DELAY_OFF_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ sprintf(buf, "%d", delay_off);
+ if (_file_write(SYS_LED_DEV_DELAY_OFF_NODE, buf) <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_DELAY_OFF_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ if (access(SYS_LED_DEV_DELAY_ON_NODE, W_OK) != 0)
+ {
+ LOGE("green_on LED file fail %s", SYS_LED_DEV_DELAY_ON_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ sprintf(buf, "%d", delay_on);
+ if (_file_write(SYS_LED_DEV_DELAY_ON_NODE, buf) <= 0)
+ {
+ LOGE("green_on LED write fail %s", SYS_LED_DEV_DELAY_ON_NODE);
+ return GSW_HAL_NORMAL_FAIL;
+ }
+
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_get_emmc_health(int *written_mbytes, int *health)
+{
+ char buffer[32] = {0};
+ char *p = buffer;
+ char *written_str = buffer;
+ char *health_str = NULL;
+
+ if (!written_mbytes && !health)
+ return GSW_HAL_NORMAL_FAIL;
+
+ if (_file_read(EMMC_HEALTH_FILE, buffer, sizeof(buffer)) <= 0)
+ return -1;
+
+ /* [0000017500-003], all 17500MB has be writtend, 003 is health value(smaller is better) */
+ while (*p != '\0')
+ {
+ if ('-' == *p)
+ {
+ health_str = p + 1;
+ *p = '\0';
+ break;
+ }
+ p++;
+ }
+
+ if (written_mbytes)
+ sscanf(written_str, "%10d", written_mbytes);
+ if (health)
+ sscanf(health_str, "%10d", health);
+
+ return GSW_HAL_SUCCESS;
+}
+
+bool gsw_hwpin_check_emmc_readonly(void)
+{
+ return false;//defualt return normal
+}
+
+int gsw_hwpin_factorytest_ctrl_led(bool aging_flag, int delay_on, int delay_off)
+{
+ LOGI("[hwpin] factory test ctrl led entry");
+ if (false == g_aging_flag)
+ {
+ if (false == aging_flag)
+ {
+ LOGI("[hwpin] factory test ctrl led aging_flag = %d", aging_flag);
+ return GSW_HAL_SUCCESS;
+ }
+ g_aging_flag = aging_flag;
+ LOGI("g_aging_flag 1 value %d", g_aging_flag);
+ }
+ else if (false == aging_flag)
+ {
+ g_aging_flag = aging_flag;
+ LOGI("g_aging_flag 2 value %d", g_aging_flag);
+ }
+
+ gsw_hwpin_led_green_blink(delay_on, delay_off);
+
+ LOGI("[hwpin] factory test ctrl led exit");
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_mute_test(int value)
+{
+ return GSW_HAL_SUCCESS;
+}
+
+int gsw_hwpin_fstrim_emmc(const char *emmc_path)
+{
+ return GSW_HAL_SUCCESS;
+}
\ No newline at end of file