#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <dlfcn.h>

#include "gsw_hwpin_interface.h"
#include "gsw_hal_errcode.h"
#include "gsw_log_interface.h"


#define GSW_GPIO "[HAL][GSW_GPIO]"


#define wakeout 117

typedef enum{
  GSW_HAL_PINDIR_IN,
  GSW_HAL_PINDIR_OUT,
}gsw_hal_pinDirection;

typedef enum{
  GSW_HAL_LEVEL_LOW,
  GSW_HAL_LEVEL_HIGH,
}gsw_hal_pinLevel;

typedef enum{
  GSW_HAL_PULL_NULL,
  GSW_HAL_PULL_DOWN,
  GSW_HAL_PULL_UP,
}gsw_hal_pinPullSel;

typedef enum{
  GSW_HAL_USB_DISCONNECTED,
  GSW_HAL_USB_CONNECTED,
}gsw_hal_usbStatus;
//typedef void (*mbtk_log)(int level, const char *format,...);
//static mbtk_log fun_ptr_log = NULL;


int gpio_check(int gpio)
{
    char buffer[128];
    memset(buffer,0,128);
    sprintf(buffer,"/sys/class/gpio/gpio%d/direction", gpio);
    return access(buffer , F_OK);
}


static int gpio_export(int gpio)
{
    int file=-1;
    int result =-1;
    char pin_index_buffer[5]= {0};

    if (gpio_check(gpio) == 0)
    {
        LOGE(GSW_GPIO, "export has been add\n");
        return 0;
    }

    file = open("/sys/class/gpio/export",O_WRONLY);
    if(file == -1)
    {
        LOGE(GSW_GPIO, "Open gpio export file fail.");
        return -1;
    }

    sprintf(pin_index_buffer,"%d", gpio);
    result = write(file,pin_index_buffer,strlen(pin_index_buffer));
    if(result < 0)
    {
        LOGE(GSW_GPIO, "Gpio[%d] export fail.", gpio);
        close(file);
        return -1;
    }
    close(file);

    return 0;
}

static int gpio_unexport(int gpio)
{
    int file=-1;
    int result =-1;
    char pin_index_buffer[5]= {0};
    if (gpio_check(gpio) == -1)
    {
        LOGE(GSW_GPIO, "export has been not add\n");
        return -1;
    }

    file = open("/sys/class/gpio/unexport",O_WRONLY);
    if(file == -1)
    {
        LOGE(GSW_GPIO, "Open gpio unexport file fail.");
        return -1;
    }

    sprintf(pin_index_buffer,"%d", gpio);
    result=write(file,pin_index_buffer,strlen(pin_index_buffer));
    if(result < 0)
    {
        close(file);
        LOGE(GSW_GPIO, "Gpio[%d] unexport fail.", gpio);
        return -1;
    }
    close(file);

    return 0;
}

int32_t gsw_gpio_SetDirection(uint32_t gpioNum, gsw_hal_pinDirection dir)
{
    char buffer[128]= {0};
    int file =-1;
    int result =-1;
    char direction[10] = {0};
    memset(buffer,0,128);

    if (gpio_check(gpioNum) == -1)
    {
        LOGD(GSW_GPIO, "in dir export has been not add\n");
        gpio_export(gpioNum);
    }


    sprintf(buffer,"/sys/class/gpio/gpio%u/direction", gpioNum);
    file = open(buffer, O_WRONLY);
    if(file == -1)
    {
        LOGE(GSW_GPIO, "Open gpio[%d] direct fail.", gpioNum);
        return -1;
    }
    if (dir == GSW_HAL_PINDIR_IN)
        sprintf(direction,"in");
    else if (dir == GSW_HAL_PINDIR_OUT)
        sprintf(direction,"out");
    
    result = write(file,direction,strlen(direction));
    if(result != strlen(direction))
    {
        LOGE(GSW_GPIO, "Set gpio[%d] direct fail.", gpioNum);
        close(file);
        gpio_unexport(gpioNum);
        return GSW_HAL_NORMAL_FAIL;
    }
    close(file);
    gpio_unexport(gpioNum);
    return GSW_HAL_SUCCESS;
}

gsw_hal_pinLevel gsw_gpio_GetLevel(uint32_t gpioNum)
{
    char buffer[50];
    char path[128];
    int file =-1;
    int result =-1;
    memset(path,0,sizeof(path));
    memset(buffer,0,sizeof(buffer));

    if (gpio_check(gpioNum) == -1)
    {
        LOGD(GSW_GPIO, "in get value export has been not add\n");
        gpio_export(gpioNum);
    }
    sprintf(path,"/sys/class/gpio/gpio%u/value", gpioNum);
    file = open(path,O_RDONLY);
    if(file == -1)
    {
        LOGE(GSW_GPIO, "Open gpio[%d] fail.", gpioNum);
        return -1;
    }
    result = read(file,buffer,50);
    if(result <= 0)
    {
        LOGE(GSW_GPIO, "Get gpio[%d] value fail", gpioNum);
        close(file);
        gpio_unexport(gpioNum);
        return GSW_HAL_NORMAL_FAIL;
    }
    close(file);
    gpio_unexport(gpioNum);
    return atoi(buffer);
}

int32_t gsw_gpio_SetLevel(uint32_t gpioNum, gsw_hal_pinLevel level)
{
    char buffer[128]= {0};
    int file =-1;
    int result =-1;
    memset(buffer,0,50);

    if (gpio_check(gpioNum) == -1)
    {
        LOGD(GSW_GPIO, "in set value export has been not add\n");
        gpio_export(gpioNum);
    }

    sprintf(buffer,"/sys/class/gpio/gpio%u/value", gpioNum);
    file = open(buffer,O_WRONLY);
    if(file == -1)
    {
        LOGE(GSW_GPIO, "Open gpio[%d] value fail.", gpioNum);
        return -1;
    }
    if(level == GSW_HAL_LEVEL_LOW) {
        result = write(file,"0",1);
    } else {
        result = write(file,"1",1);
    }
    if(result != 1)
    {
        LOGE(GSW_GPIO, "Set gpio[%d] value fail err =%d.", gpioNum, errno);
        close(file);
        gpio_unexport(gpioNum);
        return GSW_HAL_NORMAL_FAIL;
    }
    close(file);
    gpio_unexport(gpioNum);
    return GSW_HAL_SUCCESS;
}


int32_t gsw_gpio_Init(uint32_t gpioNum, gsw_hal_pinDirection dir, gsw_hal_pinLevel level, gsw_hal_pinPullSel pullsel)
{
    if (dir != 1 && dir != 0)
    {
        LOGE(GSW_GPIO, "[lynq_gpio_init] direction fail.");
        return -1;
    }

    if (level != 1 && level != 0)
    {
        LOGE(GSW_GPIO, "[lynq_gpio_init] value fail.");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(gpio_export(gpioNum))
    {
        LOGE(GSW_GPIO, "[lynq_gpio_init]gpio_export fail.");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(gsw_gpio_SetDirection(gpioNum, dir))
    {
        LOGE(GSW_GPIO, "[lynq_gpio_init]gpio_direct_set fail.");
        return GSW_HAL_NORMAL_FAIL;
    }

    if(dir == 1 && (gsw_gpio_SetLevel(gpioNum, level) != 0))
    {
        LOGE(GSW_GPIO, "[lynq_gpio_init]gpio_value_set fail.");
        return GSW_HAL_NORMAL_FAIL;
    }
    return GSW_HAL_SUCCESS;
}
int gsw_hwpin_is_usb_connected(void)
{
    FILE *fp;
    char cmd[128] = {0};
    char tmp_rsp[20] = {0};
    //char *CONNECTED = "configured";
    char *DISCONNECTED = "not attached";

    sprintf(cmd,"cat /sys/devices/platform/soc/d4200000.axi/c0000000.usb/udc/c0000000.usb/state");
    fp=popen(cmd, "r");
    if (fgets(tmp_rsp,sizeof(tmp_rsp),fp) == NULL)
        LOGE(GSW_GPIO, "gsw_hwpin_is_usb_connected fail.");
    pclose(fp);
    if (strncmp(tmp_rsp,DISCONNECTED,strlen(DISCONNECTED)) == 0)
        return GSW_HAL_USB_DISCONNECTED;
    else
        return GSW_HAL_USB_CONNECTED;
}

int32_t gsw_setWakeupLevel(gsw_hal_pinLevel level)
{
    if (gsw_gpio_SetLevel(wakeout, level) == GSW_HAL_NORMAL_FAIL)
    {
        return GSW_HAL_NORMAL_FAIL;
    }
    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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "[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(GSW_GPIO, "[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(GSW_GPIO, "[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(GSW_GPIO, "[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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "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(GSW_GPIO, "[hwpin] factory test ctrl led entry");
    if (false == g_aging_flag)
    {
        if (false == aging_flag)
        {
            LOGI(GSW_GPIO, "[hwpin] factory test ctrl led aging_flag = %d", aging_flag);
            return GSW_HAL_SUCCESS;
        }
        g_aging_flag = aging_flag;
        LOGI(GSW_GPIO, "g_aging_flag 1 value %d", g_aging_flag);
    }
    else if (false == aging_flag)
    {
        g_aging_flag = aging_flag;
        LOGI(GSW_GPIO, "g_aging_flag 2 value %d", g_aging_flag);
    }

    gsw_hwpin_led_green_blink(delay_on, delay_off);

    LOGI(GSW_GPIO, "[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)
{
    char cmd[256] = {0};
    int ret = 0;

    if(!emmc_path || access(emmc_path, F_OK) != 0) 
    {
        LOGE(GSW_GPIO, "Invalid path : %s", emmc_path);
        return ret;
    }

    sprintf(cmd, "fstrim -v %s", emmc_path);
    ret = system(cmd);

    LOGI(GSW_GPIO, "command %s, ret : %d", cmd, ret);

    return GSW_HAL_SUCCESS;
}