static ssize_t psensor_status_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ static int init = 0; int psensor_status = 0; if(off > 0){ *eof = 1; return 0; } if(!init){ mt_set_gpio_mode(GPIO38, GPIO_MODE_00); mt_set_gpio_dir(GPIO38, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIO38, GPIO_PULL_DISABLE); msleep(100); init = 1; } psensor_status = mt_get_gpio_in(GPIO38); if(psensor_status) sprintf(nvs->psensor_status, "%s", "1"); else sprintf(nvs->psensor_status, "%s", "0"); nvs_write(); return sprintf(page, "%s\n", nvs->psensor_status) + 1; }
static ssize_t gps_sku_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ static int init = 0; int gps_sku = 0; if(off > 0){ *eof = 1; return 0; } if(!init){ mt_set_gpio_mode(GPIO74, GPIO_MODE_00); mt_set_gpio_dir(GPIO74, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIO74, GPIO_PULL_DISABLE); msleep(100); init = 1; } gps_sku = mt_get_gpio_in(GPIO74); if(gps_sku) sprintf(nvs->gps_sku, "%s", "520T+MT3332"); else sprintf(nvs->gps_sku, "%s", "NH520"); nvs_write(); return sprintf(page, "%s\n", nvs->gps_sku) + 1; }
static ssize_t rf_version_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ char messages[RF_VER_SIZE] = {0}; int rf_ver0 = 1; //gpioExt27 int rf_ver1 = 1; //gpioExt28 static int init = 0; if(!init){ mt_set_gpio_mode(GPIOEXT27, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT27, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT27, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT27, GPIO_PULL_UP); mt_set_gpio_mode(GPIOEXT28, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT28, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT28, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT28, GPIO_PULL_UP); msleep(100); init = 1; } rf_ver0 = mt_get_gpio_in(GPIOEXT27); rf_ver1 = mt_get_gpio_in(GPIOEXT28); if(rf_ver0 == 0 && rf_ver1 == 0){ sprintf(messages, "%s", "3G"); } else if(rf_ver0 == 1 && rf_ver1 == 0){ sprintf(messages, "%s", "LTE"); } else if(rf_ver0 == 0 && rf_ver1 == 1){ sprintf(messages, "%s", "WIFI"); } else if(rf_ver0 == 1 && rf_ver1 == 1){ sprintf(messages, "%s", "MV"); } else sprintf(messages, "%s", "N/A"); messages[RF_VER_SIZE-1] = 0x0; nvs_read(); sprintf(nvs->rf_version, "%s", messages); nvs_write(); if(off > 0){ *eof = 1; return 0; } return sprintf(page, "%s\n", messages) + 1; }
static ssize_t acer_code_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { char messages[ACER_CODE_SIZE] = {0}; if(len != ACER_CODE_REAL_SIZE+1) return -EFAULT; if (copy_from_user(messages, buff, ACER_CODE_REAL_SIZE)) return -EFAULT; messages[ACER_CODE_REAL_SIZE] = 0x0; sprintf(nvs->acer_code, "%s", messages); nvs_write(); return strlen(buff); }
static ssize_t bt_mac_addr_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { char messages[BT_MAC_ADDR_SIZE] = {0}; if(len != MAC_ADDR_SIZE+1) return -EFAULT; if (copy_from_user(messages, buff, MAC_ADDR_SIZE)) return -EFAULT; messages[MAC_ADDR_SIZE] = 0x0; sprintf(nvs->bt_mac_addr, "%s", messages); nvs_write(); return strlen(buff); }
/** * Save non-volatile stored options back to non-volatile storage device * * @v nvo Non-volatile options block * @ret rc Return status code */ static int nvo_save ( struct nvo_block *nvo ) { uint8_t *checksum = nvo->data; int rc; /* Recalculate checksum, if applicable */ if ( nvo->len > 0 ) *checksum -= nvo_checksum ( nvo ); /* Write data */ if ( ( rc = nvs_write ( nvo->nvs, nvo->address, nvo->data, nvo->len ) ) != 0 ) { DBGC ( nvo, "NVO %p could not write %zd bytes at %#04x: %s\n", nvo, nvo->len, nvo->address, strerror ( rc ) ); return rc; } DBGC ( nvo, "NVO %p saved to non-volatile storage\n", nvo ); return 0; }
static ssize_t wifi_country_code_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { if(len < sizeof("5545")) return -EFAULT; else if(len < sizeof("0x5545")) goto fourdig; if(!strncmp(buff, "0x5545", sizeof("0x5545")-1)){ nvs->wifi_country_code[0] = 0x45; nvs->wifi_country_code[1] = 0x55; } else if(!strncmp(buff, "0x5355", sizeof("0x5355")-1)){ nvs->wifi_country_code[0] = 0x55; nvs->wifi_country_code[1] = 0x53; } else{ printk(KERN_ERR, "===> Error country code! Country code should be 0x5545/0x5355\n"); return -EFAULT; } goto done; fourdig: if(!strncmp(buff, "5545", sizeof("5545")-1)){ nvs->wifi_country_code[0] = 0x45; nvs->wifi_country_code[1] = 0x55; } else if(!strncmp(buff, "5355", sizeof("5355")-1)){ nvs->wifi_country_code[0] = 0x55; nvs->wifi_country_code[1] = 0x53; } else{ printk(KERN_ERR, "===> Error country code! Country code should be 0x5545/0x5355\n"); return -EFAULT; } done: nvs_write(); return strlen(buff); }
static ssize_t imei_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { char messages[IMEI_SIZE] = {0}; if(len >= (IMEI_SIZE - 1)) len = IMEI_SIZE -1; else len -=1; //ignore "\n" if (copy_from_user(messages, buff, len)) return -EFAULT; messages[IMEI_SIZE-1] = 0x0; sprintf(nvs->imei, "%s", messages); nvs_write(); nvs_read(); return strlen(buff); }
/** * Save non-volatile stored options back to non-volatile storage device * * @v nvo Non-volatile options block * @ret rc Return status code */ static int nvo_save ( struct nvo_block *nvo ) { void *data = nvo->data; uint8_t *checksum = data; struct nvo_fragment *frag; int rc; /* Recalculate checksum */ *checksum -= nvo_checksum ( nvo ); /* Write data a fragment at a time */ for ( frag = nvo->fragments ; frag->len ; frag++ ) { if ( ( rc = nvs_write ( nvo->nvs, frag->address, data, frag->len ) ) != 0 ) { DBGC ( nvo, "NVO %p could not write %zd bytes at " "%#04x\n", nvo, frag->len, frag->address ); return rc; } data += frag->len; } DBGC ( nvo, "NVO %p saved to non-volatile storage\n", nvo ); return 0; }
static ssize_t pcb_version_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ char messages[PCB_VER_SIZE] = {0}; int pcb_ver0 = 1; //gpioExt29 // SB/SC int pcb_ver1 = 1; //gpioExt30 // SB/SC int pcb_ver2 = 0; //gpioExt40 // SC only static int init = 0; if(!init){ mt_set_gpio_mode(GPIOEXT29, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT29, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT29, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT29, GPIO_PULL_UP); mt_set_gpio_mode(GPIOEXT30, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT30, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT30, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT30, GPIO_PULL_UP); mt_set_gpio_mode(GPIOEXT40, GPIO_MODE_00); mt_set_gpio_dir(GPIOEXT40, GPIO_DIR_IN); mt_set_gpio_pull_enable(GPIOEXT40, GPIO_PULL_DISABLE); //mt_set_gpio_pull_select(GPIOEXT40, GPIO_PULL_UP); msleep(100); init = 1; } pcb_ver0 = mt_get_gpio_in(GPIOEXT29); pcb_ver1 = mt_get_gpio_in(GPIOEXT30); pcb_ver2 = mt_get_gpio_in(GPIOEXT40); if(pcb_ver0 == 0 && pcb_ver1 == 0 && pcb_ver2 == 0){ sprintf(messages, "%s", "SA"); } else if(pcb_ver0 == 1 && pcb_ver1 == 0 && pcb_ver2 == 0){ sprintf(messages, "%s", "-2"); } else if(pcb_ver0 == 0 && pcb_ver1 == 1 && pcb_ver2 == 0){ sprintf(messages, "%s", "-1M"); } else if(pcb_ver0 == 1 && pcb_ver1 == 1 && pcb_ver2 == 0){ sprintf(messages, "%s", "SD"); } else if(pcb_ver0 == 0 && pcb_ver1 == 0 && pcb_ver2 == 1){ sprintf(messages, "%s", "SC"); } else if(pcb_ver0 == 1 && pcb_ver1 == 0 && pcb_ver2 == 1){ sprintf(messages, "%s", "-3"); } else if(pcb_ver0 == 0 && pcb_ver1 == 1 && pcb_ver2 == 1){ sprintf(messages, "%s", "-4"); } else if(pcb_ver0 == 1 && pcb_ver1 == 1 && pcb_ver2 == 1){ sprintf(messages, "%s", "-5"); } else sprintf(messages, "%s", "N/A"); messages[PCB_VER_SIZE-1] = 0x0; nvs_read(); sprintf(nvs->pcb_version, "%s", messages); nvs_write(); if(off > 0){ *eof = 1; return 0; } return sprintf(page, "%s\n", messages) + 1; }