static ssize_t uart_sel_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int state; if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1)) return -EINVAL; /* prevents the system from entering suspend */ wake_lock(&sec_misc_wake_lock); if (state == 1) { printk("[denis]Set UART path to AP state : %d\n" , state); gpio_set_value(GPIO_UART_SEL, 1); /* Set UART path to AP */ klogi("Set UART path to AP\n"); sec_set_param(param_index_uartsel, &state); } else if (state == 0) { printk("[denis]Set UART path to CP state : %d\n", state); gpio_set_value(GPIO_UART_SEL, 0); /* Set UART path to CP */ klogi("Set UART path to CP\n"); sec_set_param(param_index_uartsel, &state); } else klogi("Enter 1(AP uart) or 0(CP uart)...\n"); wake_unlock(&sec_misc_wake_lock); return size; }
static ssize_t usb_sel_store(struct device *dev, struct device_attribute *attr,const char *buf, size_t size) { int state; if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 2)) return -EINVAL; // prevents the system from entering suspend wake_lock(&sec_misc_wake_lock); if(state == 2) { p3_set_usb_path(USB_SEL_ADC); // Set USB path to CP klogi("Set USB path to ADC\n"); } else if(state == 1) { p3_set_usb_path(USB_SEL_AP_USB); // Set USB path to AP klogi("Set USB path to AP\n"); } else if(state == 0) { p3_set_usb_path(USB_SEL_CP_USB); // Set USB path to CP klogi("Set USB path to CP\n"); } else klogi("Enter 2(ADC usb) or 1(AP usb) or 0(CP usb)...\n"); if (state >= 0 && state <= 2) sec_set_param(param_index_usbsel, &state); wake_unlock(&sec_misc_wake_lock); return size; }
static void sec_switch_init_work(struct work_struct *work) { struct delayed_work *dw = container_of(work, struct delayed_work, work); struct sec_switch_wq *wq = container_of(dw, struct sec_switch_wq, work_q); struct sec_switch_struct *secsw = wq->sdata; int usb_sel = 0; int uart_sel = 0; cancel_delayed_work(&wq->work_q); sec_get_param(param_index_uartsel, &secsw->switch_sel); if ( secsw->switch_sel == 0 ) { secsw->switch_sel = 0x4; // UART_SEL default to MDM9K & USB_SEL default to APQ8K : 0100 sec_set_param(param_index_uartsel, &secsw->switch_sel); } pr_err("sec_switch_probe enter %s value = 0x%X \n", __func__, secsw->switch_sel); usb_sel = secsw->switch_sel & USB_SEL_MASK; uart_sel = secsw->switch_sel & UART_SEL_MASK; if (uart_sel) uart_switch_mode(secsw, SWITCH_APQ8K); else uart_switch_mode(secsw, SWITCH_MDM9K); }
static ssize_t usb_sel_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sec_switch_struct *secsw = dev_get_drvdata(dev); int usb_sel = 0; usb_sel = secsw->switch_sel & USB_SEL_MASK; #ifdef CONFIG_SEC_MISC sec_get_param(param_index_uartsel, &secsw->switch_sel); #endif if (strncmp(buf, "PDA", 3) == 0 || strncmp(buf, "pda", 3) == 0) { if (usb_sel!=SWITCH_PDA) { usb_switch_mode(secsw, SWITCH_PDA); secsw->switch_sel |= USB_SEL_MASK; } } if (strncmp(buf, "MODEM", 5) == 0 || strncmp(buf, "modem", 5) == 0) { if (usb_sel!=SWITCH_MODEM) { usb_switch_mode(secsw, SWITCH_MODEM); secsw->switch_sel &= ~USB_SEL_MASK; } } #ifdef CONFIG_SEC_MISC sec_set_param(param_index_uartsel, &secsw->switch_sel); #endif return size; }
static ssize_t usb_sel_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sec_switch_struct *secsw = dev_get_drvdata(dev); int usb_sel = 0; usb_sel = secsw->switch_sel & USB_SEL_MASK; sec_get_param(param_index_uartsel, &secsw->switch_sel); secsw->is_manualset=1; if (strncmp(buf, "PDA", 3) == 0 || strncmp(buf, "pda", 3) == 0) { if (usb_sel!=SWITCH_APQ8K) { usb_switch_mode(secsw, SWITCH_APQ8K); secsw->switch_sel |= USB_SEL_MASK; } } if (strncmp(buf, "MODEM", 5) == 0 || strncmp(buf, "modem", 5) == 0) { if (usb_sel!=SWITCH_MDM9K) { usb_switch_mode(secsw, SWITCH_MDM9K); secsw->switch_sel &= ~USB_SEL_MASK; } } sec_set_param(param_index_uartsel, &secsw->switch_sel); return size; }
static ssize_t uart_sel_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sec_switch_struct *secsw = dev_get_drvdata(dev); #ifdef CONFIG_SEC_MISC sec_get_param(param_index_uartsel, &secsw->switch_sel); #endif if (strncmp(buf, "PDA", 3) == 0 || strncmp(buf, "pda", 3) == 0) { uart_switch_mode(secsw, SWITCH_PDA); secsw->switch_sel |= UART_SEL_MASK; pr_err("[UART Switch] Path : PDA\n"); } if (strncmp(buf, "MODEM", 5) == 0 || strncmp(buf, "modem", 5) == 0) { uart_switch_mode(secsw, SWITCH_MODEM); secsw->switch_sel &= ~UART_SEL_MASK; pr_err("[UART Switch] Path : MODEM\n"); } pr_err("end %s value = 0x%X \n", __func__, secsw->switch_sel); #ifdef CONFIG_SEC_MISC sec_set_param(param_index_uartsel, &secsw->switch_sel); #endif return size; }
static ssize_t power_off_reason_store (struct device *dev, struct device_attribute *attr,\ const char *buf, size_t size) { int power_off_reason; sscanf(buf, "%i", &power_off_reason); sec_set_param(param_power_off_reason, &power_off_reason); return size; }
static ssize_t update_cp_bin_store (struct device *dev, struct device_attribute *attr,\ const char *buf, size_t size) { int update = 0; sscanf(buf, "%i", &update); sec_set_param(param_update_cp_bin, &update); return size; }
static ssize_t slideCount_store (struct device *dev, struct device_attribute *attr,\ const char *buf, size_t size) { int slideCount; sscanf(buf, "%i", &slideCount); sec_set_param(param_slideCount, &slideCount); return size; }
static ssize_t rory_control_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int rory_control; sscanf(buf, "%i", &rory_control); pr_info("rory control store ..... %d\n", rory_control); /* write to param */ sec_set_param(param_rory_control, &rory_control); return size; }
static ssize_t uart_sel_store(struct device *dev, struct device_attribute *attr,const char *buf, size_t size) { int state; if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1)) return -EINVAL; #if defined(CONFIG_SEC_KEYBOARD_DOCK) if (g_keyboard) { pr_err("%s - the keyboard is connected.\n", __func__); return size; } #endif // prevents the system from entering suspend wake_lock(&sec_misc_wake_lock); if(state == 1) { printk("[denis]Set UART path to AP state : %d\n" ,state); gpio_set_value(GPIO_UART_SEL, 1); // Set UART path to AP klogi("Set UART path to AP\n"); sec_set_param(param_index_uartsel, &state); } else if(state == 0) { printk("[denis]Set UART path to CP state : %d\n",state); gpio_set_value(GPIO_UART_SEL, 0); // Set UART path to CP klogi("Set UART path to CP\n"); sec_set_param(param_index_uartsel, &state); } else klogi("Enter 1(AP uart) or 0(CP uart)...\n"); wake_unlock(&sec_misc_wake_lock); return size; }
static ssize_t sales_code_store (struct device *dev, struct device_attribute *attr,\ const char *buf, size_t size) { int sales_code; sscanf(buf, "%i", &sales_code); pr_info("sales_code store ..... %d\n", sales_code); /* write to param */ sec_set_param(param_sales_code, &sales_code); return size; }
int kernel_sec_get_debug_level(void) { sec_get_param(param_index_debuglevel, &sec_dbg_level); if (!(sec_dbg_level == KERNEL_SEC_DEBUG_LEVEL_LOW || sec_dbg_level == KERNEL_SEC_DEBUG_LEVEL_MID || sec_dbg_level == KERNEL_SEC_DEBUG_LEVEL_HIGH)) { /*In case of invalid debug level, default (debug level low)*/ pr_notice(KERN_NOTICE "(%s) The debug value is"\ "invalid(0x%x)!! Set default level(LOW)\n", __func__, sec_dbg_level); sec_dbg_level = KERNEL_SEC_DEBUG_LEVEL_LOW; sec_set_param(param_index_debuglevel, &sec_dbg_level); } return sec_dbg_level; }
bool kernel_sec_set_debug_level(int level) { #if 0 //FIXME if (!(level == KERNEL_SEC_DEBUG_LEVEL_LOW || level == KERNEL_SEC_DEBUG_LEVEL_MID || level == KERNEL_SEC_DEBUG_LEVEL_HIGH)) { pr_notice(KERN_NOTICE "(kernel_sec_set_debug_level) The debug"\ "value is invalid(0x%x)!! Set default"\ "level(LOW)\n", level); sec_dbg_level = KERNEL_SEC_DEBUG_LEVEL_LOW; return -EINVAL; } sec_dbg_level = level; switch (level) { case KERNEL_SEC_DEBUG_LEVEL_LOW: enable = 0; enable_user = 0; break; case KERNEL_SEC_DEBUG_LEVEL_MID: enable = 1; enable_user = 0; break; case KERNEL_SEC_DEBUG_LEVEL_HIGH: enable = 1; enable_user = 1; break; default: enable = 1; enable_user = 1; } /* write to param */ sec_set_param(param_index_debuglevel, &sec_dbg_level); pr_notice(KERN_NOTICE "(kernel_sec_set_debug_level)"\ "The debug value is 0x%x !!\n", level); #endif return 1; }
static ssize_t uart_sel_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct sec_switch_struct *secsw = dev_get_drvdata(dev); sec_get_param(param_index_uartsel, &secsw->switch_sel); if (strncmp(buf, "PDA", 3) == 0 || strncmp(buf, "pda", 3) == 0) { uart_switch_mode(secsw, SWITCH_APQ8K); secsw->switch_sel |= UART_SEL_MASK; pr_debug("[UART Switch] Path : PDA\n"); } if (strncmp(buf, "MODEM", 5) == 0 || strncmp(buf, "modem", 5) == 0) { uart_switch_mode(secsw, SWITCH_MDM9K); secsw->switch_sel &= ~UART_SEL_MASK; pr_debug("[UART Switch] Path : MODEM\n"); } sec_set_param(param_index_uartsel, &secsw->switch_sel); return size; }
static int write_bootloader_message(char *cmd, int mode) { struct file *filp; mm_segment_t oldfs; int ret = 0; loff_t pos = 2048L; /* bootloader message offset in MISC.*/ #ifdef CONFIG_KERNEL_DEBUG_SEC int state; #endif struct bootloader_message bootmsg; memset(&bootmsg, 0, sizeof(struct bootloader_message)); if (mode == REBOOT_MODE_RECOVERY) { strcpy(bootmsg.command, "boot-recovery"); #ifdef CONFIG_KERNEL_DEBUG_SEC reboot_mode = REBOOT_MODE_RECOVERY; kernel_sec_set_debug_level(KERNEL_SEC_DEBUG_LEVEL_LOW); state = 1; /* Set USB path to AP */ sec_set_param(param_index_usbsel, &state); #endif } else if (mode == REBOOT_MODE_FASTBOOT) strcpy(bootmsg.command, "boot-fastboot"); else if (mode == REBOOT_MODE_NORMAL) strcpy(bootmsg.command, "boot-reboot"); else if (mode == REBOOT_MODE_FOTA) strcpy(bootmsg.command, "boot-fota"); else if (mode == REBOOT_MODE_NONE) strcpy(bootmsg.command, "boot-normal"); else strcpy(bootmsg.command, cmd); bootmsg.status[0] = (char) mode; filp = filp_open(MISC_DEVICE, O_WRONLY, 0); if (IS_ERR(filp)) { pr_info("failed to open MISC : '%s'.\n", MISC_DEVICE); return 0; } oldfs = get_fs(); set_fs(KERNEL_DS); ret = vfs_write(filp, (const char *)&bootmsg, sizeof(struct bootloader_message), &pos); set_fs(oldfs); if (ret < 0) pr_info("failed to write on MISC\n"); else pr_info("command : %s written on MISC\n", bootmsg.command); fput(filp); filp_close(filp, NULL); return ret; }
void sec_param_restart_reason(const char *cmd) { unsigned long value = 0; unsigned int param_restart_reason = 0; if (cmd != NULL) { printk(KERN_NOTICE " Reboot cmd=%s\n",cmd); if (!strncmp(cmd, "bootloader", 10)) { param_restart_reason = 0x77665500; } else if (!strncmp(cmd, "recovery", 8)) { param_restart_reason = 0x77665502; } else if (!strcmp(cmd, "rtc")) { param_restart_reason = 0x77665503; } else if (!strncmp(cmd, "oem-", 4)) { unsigned long code; int ret; ret = kstrtoul(cmd + 4, 16, &code); if (!ret) param_restart_reason = (0x6f656d00 | (code & 0xff)); #ifdef CONFIG_SEC_DEBUG } else if (!strncmp(cmd, "sec_debug_hw_reset", 18)) { param_restart_reason = SECDEBUG_MODE; #endif } else if (!strncmp(cmd, "download", 8)) { param_restart_reason = 0x12345671; } else if (!strncmp(cmd, "nvbackup", 8)) { param_restart_reason = 0x77665511; } else if (!strncmp(cmd, "nvrestore", 9)) { param_restart_reason = 0x77665512; } else if (!strncmp(cmd, "nverase", 7)) { param_restart_reason = 0x77665514; } else if (!strncmp(cmd, "nvrecovery", 10)) { param_restart_reason = 0x77665515; } else if (!strncmp(cmd, "sud", 3)) { if (strlen(cmd) == 5) param_restart_reason = (0xabcf0000 | (((cmd[3] - '0') * 10) + (cmd[4] - '0'))); else param_restart_reason = (0xabcf0000 | (cmd[3] - '0')); } else if (!strncmp(cmd, "debug", 5) && !kstrtoul(cmd + 5, 0, &value)) { param_restart_reason =(0xabcd0000 | value); } else if (!strncmp(cmd, "cpdebug", 7) /* set cp debug level */ && !kstrtoul(cmd + 7, 0, &value)) { param_restart_reason = (0xfedc0000 | value); #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF) } else if (!strncmp(cmd, "swsel", 5) /* set switch value */ && !kstrtoul(cmd + 5, 0, &value)) { param_restart_reason = (0xabce0000 | value); #endif } else if (!strncmp(cmd, "edl", 3)) { param_restart_reason = 0x0; // Hack. Fix it later } else if (!strncmp(cmd, "lpm", 3)) { param_restart_reason = 0x12345678; // Need to do normal reboot from lpm mode }else if (strlen(cmd) == 0) { printk(KERN_NOTICE "%s : value of cmd is NULL.\n", __func__); param_restart_reason = 0x12345678; } else { param_restart_reason = 0x77665501; } } #ifdef CONFIG_SEC_DEBUG else { param_restart_reason = 0x0; // Hack. Fix it later } #endif printk(KERN_NOTICE "%s : param_restart_reason = 0x%x\n", __func__,param_restart_reason); /* In case of Hard reset IMEM contents are lost, hence writing param_restart_reason to param partition */ printk(KERN_NOTICE "%s: Write PARAM_RESTART_REASON 0x%x to param \n",__func__,param_restart_reason); sec_set_param(param_index_restart_reason, ¶m_restart_reason); }