/* * Description : read data from uart * Input : buf : data count : data length * Output : success : data length fail : 0 */ int felica_uart_read(char *buf, size_t count) { mm_segment_t old_fs = get_fs(); int n; int retry = 5; FELICA_DEBUG_MSG_LOW("[FELICA_UART] read_hs_uart - start \n"); if (uart_f == NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] felica_uart is not opened\n"); return 0; } set_fs(KERNEL_DS); while ((n = vfs_read(uart_f, buf, count, &uart_f->f_pos)) == -EAGAIN && retry > 0) { mdelay(10); FELICA_DEBUG_MSG_MED("[FELICA_UART] felica_uart_read - delay : %d \n", retry); retry--; } FELICA_DEBUG_MSG_MED("[FELICA_UART] read_hs_uart - count(%d), num of read data(%d) \n",(int)count ,n); set_fs(old_fs); FELICA_DEBUG_MSG_LOW("[FELICA_UART] read_hs_uart - end \n"); return n; }
/* * Description: MFC calls this function using close method(int close()) of FileInputStream class * Input: None * Output: RFS low : 1 RFS high : 0 */ static int felica_rfs_release (struct inode *inode, struct file *fp) { if(0 == isopen) { FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_release - not open \n"); return -1; } else { FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_release - start \n"); isopen = 0; } #ifdef FELICA_LED_SUPPORT isFelicaUsed = 0; #endif FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_release - end \n"); #ifdef FELICA_FN_DEVICE_TEST FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_release - result(%d) \n",result_close_rfs); return result_close_rfs; #else return 0; #endif }
/* * Description: MFC calls this function using open method of FileInputStream class * Input: None * Output: Success : 0 Fail : Others */ static int felica_rfs_open (struct inode *inode, struct file *fp) { int rc = 0; if(1 == isopen) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] felica_rfs_open - already open \n"); return -1; } else { FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_open - start \n"); isopen = 1; } #ifdef FELICA_LED_SUPPORT rc = felica_gpio_open(felica_get_rfs_gpio_num(), GPIO_DIRECTION_IN, GPIO_HIGH_VALUE); #else rc = felica_gpio_open(felica_get_rfs_gpio_num(), GPIO_DIRECTION_IN, GPIO_LOW_VALUE); #endif FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_open - end \n"); #ifdef FELICA_FN_DEVICE_TEST FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_open - result(%d) \n",result_open_rfs); return result_open_rfs; #else return rc; #endif }
/* * Description : write data to uart * Input : buf : data count : data length * Output : success : data length fail : 0 */ int felica_uart_write(char *buf, size_t count) { mm_segment_t old_fs = get_fs(); int n; FELICA_DEBUG_MSG_LOW("[FELICA_UART] write_hs_uart - start \n"); if (uart_f == NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] felica_uart is not opened\n"); return 0; } set_fs(KERNEL_DS); n = vfs_write(uart_f, buf, count, &uart_f->f_pos); FELICA_DEBUG_MSG_LOW("[FELICA_UART] write_hs_uart - write (%d)\n", n); set_fs(old_fs); FELICA_DEBUG_MSG_LOW("[FELICA_UART] write_hs_uart - end \n"); return n; }
static void felica_rfs_open_after_boot_work(struct work_struct *data) { int rc = 0; FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_open_after_boot_work - start"); rc = felica_gpio_open(felica_get_rfs_gpio_num(), GPIO_DIRECTION_IN, GPIO_HIGH_VALUE); FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_open_after_boot_work - end"); }
/* * Description : open uart * Input : None * Output : success : 0 fail : others */ int felica_uart_open(void) { struct termios newtio; mm_segment_t old_fs = get_fs(); FELICA_DEBUG_MSG_LOW("[FELICA_UART] open_hs_uart - start \n"); if(FELICA_UART_NOTAVAILABLE == get_felica_uart_status()) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] collision!! uart is used by other device \n"); return -1; } if (uart_f != NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] felica_uart is already opened\n"); return 0; } set_fs(KERNEL_DS); uart_f = filp_open(FELICA_UART_NAME, O_RDWR | O_NOCTTY | O_NONBLOCK, 0); FELICA_DEBUG_MSG_LOW("[FELICA_UART] open UART\n"); if (uart_f == NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] ERROR - can not sys_open \n"); set_fs(old_fs); return -1; } set_felica_uart_status(UART_STATUS_FOR_FELICA); memset(&newtio, 0, sizeof(newtio)); newtio.c_cflag = B460800 | CS8 | CLOCAL | CREAD; newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 5; do_vfs_ioctl(uart_f, -1, TCFLSH, TCIOFLUSH); do_vfs_ioctl(uart_f, -1, TCSETSF, (unsigned long)&newtio); set_fs(old_fs); FELICA_DEBUG_MSG_LOW("[FELICA_UART] open_hs_uart - end \n"); return 0; }
static void felica_rfs_exit(void) { FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_exit - start \n"); #ifdef FELICA_LED_SUPPORT free_irq(gpio_to_irq(felica_get_rfs_gpio_num()), NULL); destroy_felica_rfs_wake_lock(); #endif /* deregister the device file */ misc_deregister(&felica_rfs_device); FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_exit - end \n"); }
/* * Description : * Input : * Output : */ int felica_get_rfs_gpio_num(void) { /* If it has different GPIO number each HW version, please use this route. */ int gpionum = GPIO_FELICA_RFS; pr_info("CBAL current rev -> %d \n",lge_get_board_revno()); if (lge_get_board_revno() < HW_REV_B) { pr_info("CBAL RFS-CDET gpio rev old -> %d \n",GPIO_FELICA_RFS_REV_A); gpionum = GPIO_FELICA_RFS_REV_A; } else { pr_info("CBAL RFS-CDET gpio rev -> %d \n",GPIO_FELICA_RFS); gpionum = GPIO_FELICA_RFS; } FELICA_DEBUG_MSG_LOW("[FELICA_GPIO] felica_get_rfs_gpio_num(%d) \n",gpionum); return gpionum; return GPIO_FELICA_RFS; }
/* * Description: * Input: * Output: */ void disable_write_pon(bool val) { if(val) result_write_pon = -1; else result_write_pon = 1; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_pon_write - val(%d), result_write_pon(%d) \n",val,result_write_pon); }
/* * Description: * Input: * Output: */ void disable_close_rfs(bool val) { if(val) result_close_rfs = -1; else result_close_rfs = 0; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_rfs_close - val(%d), result_close_rfs(%d) \n",val,result_close_rfs); }
/* * Description: * Input: * Output: */ void disable_read_rws(bool val) { if(val) result_read_rws = -1; else result_read_rws = 0; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_rws_read - val(%d), result_read_rws(%d) \n",val,result_read_rws); }
/* * Description: * Input: * Output: */ void disable_close_cen(bool val) { if(val) result_close_cen = -1; else result_close_cen = 0; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_cen_close - val(%d), result_close_cen(%d) \n",val,result_close_cen); }
/* * Description: * Input: * Output: */ void disable_open_pon(bool val) { if(val) result_open_pon = -1; else result_open_pon = 0; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_pon_open - val(%d), result_open_pon(%d) \n",val,result_open_pon); }
/* * Description: * Input: * Output: */ void disable_read_cen(bool val) { if(val) result_read_cen = -1; else result_read_cen = 1; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_cen_read - val(%d), result_read_cen(%d) \n",val,result_read_cen); }
/* * Description: * Input: * Output: */ void disable_write_uart(bool val) { if(val) result_write_uart = -1; else result_write_uart = 0; FELICA_DEBUG_MSG_LOW("[FELICA] disable_felica_uart_write - val(%d), result_write_uart(%d) \n",val,result_write_uart); }
/* * Description: * Input: * Output: */ void disable_open_uart(bool val) { if(val) result_open_uart = -1; else result_open_uart = 0; FELICA_DEBUG_MSG_LOW("[FELICA] felica_uart_open_failed - val(%d), result_open_uart(%d) \n",val,result_open_uart); }
static int invoke_led_service(void) { int rc = 0; int getvalue; char *argv_on[] = { "/system/bin/sh", "/system/bin/am", "startservice", "--es", "rfs", "on", "-n", FELICA_LED_INTENT, NULL }; char *argv_off[] = { "/system/bin/sh", "/system/bin/am", "startservice", "--es", "rfs", "off", "-n", FELICA_LED_INTENT, NULL }; static char *envp[] = {FELICA_LD_LIBRARY_PATH,FELICA_BOOTCLASSPATH,FELICA_PATH,NULL}; FELICA_DEBUG_MSG_LOW("[FELICA_RFS] invoke led service ... \n"); getvalue = felica_gpio_read(felica_get_rfs_gpio_num()); if( isFelicaUsed ==0 && getvalue == GPIO_LOW_VALUE) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] Felica LED On ... \n"); lock_felica_rfs_wake_lock(); rc = call_usermodehelper( argv_on[0], argv_on, envp, UMH_WAIT_PROC ); isFelicaUsed = 1; } else if( isFelicaUsed ==1 && getvalue == GPIO_HIGH_VALUE) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] Felica LED Off ... \n"); unlock_felica_rfs_wake_lock(); rc = call_usermodehelper( argv_off[0], argv_off, envp, UMH_WAIT_PROC ); isFelicaUsed =0; } else { FELICA_DEBUG_MSG_MED("[FELICA_RFS] Felica LED exception case ... do nothing \n"); FELICA_DEBUG_MSG_MED("[FELICA_RFS] felica_gpio_read = %d , isFelicaUsed =%d \n",getvalue,isFelicaUsed); unlock_felica_rfs_wake_lock(); #if defined(CONFIG_LGE_FELICA_ONLY) FELICA_DEBUG_MSG_MED("[FELICA_RFS] Felica LED ERROR case so LED Off ... \n"); rc = call_usermodehelper( argv_off[0], argv_off, envp, UMH_WAIT_PROC ); isFelicaUsed =0; #endif } FELICA_DEBUG_MSG_LOW("[FELICA_RFS] invoke_led_service: %d \n", rc); return rc; }
static void felica_rfs_interrupt_work(struct work_struct *data) { int rc = 0; disable_irq_nosync(gpio_to_irq(felica_get_rfs_gpio_num())); usermodehelper_enable(); FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_interrupt_work - start \n"); rc = invoke_led_service(); if(rc) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] Error - invoke app \n"); unlock_felica_rfs_wake_lock(); isFelicaUsed =0; } FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_interrupt_work - end \n"); enable_irq(gpio_to_irq(felica_get_rfs_gpio_num())); }
static int felica_rfs_init(void) { int rc; FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_init - start \n"); /* register the device file */ rc = misc_register(&felica_rfs_device); if (rc < 0) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] FAIL!! can not register felica_rfs \n"); return rc; } #ifdef FELICA_LED_SUPPORT FELICA_DEBUG_MSG_LOW("[FELICA_RFS] FELICA LED NEW SUPPORT !!\n"); rc= request_irq(gpio_to_irq(felica_get_rfs_gpio_num()), felica_rfs_detect_interrupt, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING|IRQF_NO_SUSPEND , FELICA_RFS_NAME, NULL); if (rc) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] FAIL!! can not request_irq rc =%d\n",(int)rc); return rc; } irq_set_irq_wake(gpio_to_irq(felica_get_rfs_gpio_num()),1); init_felica_rfs_wake_lock(); #else FELICA_DEBUG_MSG_LOW("[FELICA_RFS] FELICA LED NOT SUPPORT !! \n"); #endif FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_init - end \n"); #if defined(FELICA_LED_SUPPORT) && defined(CONFIG_LGE_FELICA_DCM) schedule_delayed_work(&felica_rfs_open_after_boot, 3000); #endif return 0; }
/* * Description : get size of remaing data * Input : none * Output : success : data length fail : 0 */ int felica_uart_ioctrl(int *count) { mm_segment_t old_fs = get_fs(); int n; FELICA_DEBUG_MSG_LOW("[FELICA_UART] felica_uart_ioctrl - start \n"); if (uart_f == NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] felica_uart is not opened\n"); return 0; } set_fs(KERNEL_DS); n = do_vfs_ioctl(uart_f, -1, TIOCINQ, (unsigned long)count); FELICA_DEBUG_MSG_MED("[FELICA_UART] do_vfs_ioctl return(%d), count(%d) \n", n, *count); set_fs(old_fs); FELICA_DEBUG_MSG_LOW("[FELICA_UART] felica_uart_ioctrl - end \n"); return n; }
/* * Description : close uart * Input : None * Output : success : 0 */ int felica_uart_close(void) { mm_segment_t old_fs = get_fs(); FELICA_DEBUG_MSG_LOW("[FELICA_UART] close_hs_uart - start \n"); if (uart_f == NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] felica_uart is not opened \n"); return 0; } set_felica_uart_status(UART_STATUS_READY); set_fs(KERNEL_DS); filp_close(uart_f, NULL); uart_f = NULL; set_fs(old_fs); FELICA_DEBUG_MSG_LOW("[FELICA_UART] close_hs_uart - end \n"); return 0; }
/* * Description : * Input : * Output : */ int felica_get_int_gpio_num(void) { /* If it has different GPIO number each HW version, please use this route. */ #ifdef CONFIG_LGE_FELICA_NFC_DCM int gpionum = GPIO_FELICA_INT; if (lge_get_board_revno() < HW_REV_D) { gpionum = GPIO_FELICA_INT; } else { gpionum = GPIO_FELICA_INT_REV_D; } FELICA_DEBUG_MSG_LOW("[FELICA_GPIO] felica_get_rws_gpio_num(%d) \n",gpionum); return gpionum; #else return GPIO_FELICA_INT; #endif }
/* * Description: * Input: * Output: */ static ssize_t felica_test_write(struct file *fp, const char *buf, size_t count, loff_t *pos) { unsigned char case_buf[3] = {0,}; int rc = -1; /* Check error */ if(NULL == buf) { FELICA_DEBUG_MSG_HIGH("[FELICA_TEST] ERROR - start \n"); return -1; } /* copy from user data */ rc = copy_from_user(case_buf, buf, count); if(rc) { FELICA_DEBUG_MSG_HIGH("[FELICA_TEST] ERROR - copy_from_user \n"); return -1; } FELICA_DEBUG_MSG_LOW("[FELICA_TEST] copy_from_user[%d][%d][%d] \n",case_buf[0],case_buf[1],case_buf[2]); switch(case_buf[0]) { case FFI: switch(case_buf[1]) { case FN_DEVICE_FT_DISABLE_OPEN_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_open_uart(ON); else disable_open_uart(OFF); break; case FN_DEVICE_FT_DISABLE_CLOSE_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_close_uart(ON); else disable_close_uart(OFF); break; case FN_DEVICE_FT_DISABLE_AVAILABLE_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_available_uart(ON); else disable_available_uart(OFF); break; case FN_DEVICE_FT_DISABLE_READ_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_read_uart(ON); else disable_read_uart(OFF); break; } break; case FFO: switch(case_buf[1]) { case FN_DEVICE_FT_DISABLE_OPEN_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_open_uart(ON); else disable_open_uart(OFF); break; case FN_DEVICE_FT_DISABLE_CLOSE_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_close_uart(ON); else disable_close_uart(OFF); break; case FN_DEVICE_FT_DISABLE_READ_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_read_uart(ON); else disable_read_uart(OFF); break; case FN_DEVICE_FT_DISABLE_WRITE_UART: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_write_uart(ON); else disable_write_uart(OFF); break; } break; case PFO: switch(case_buf[1]) { case FN_DEVICE_FT_DISABLE_OPEN_PON: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_open_pon(ON); else disable_open_pon(OFF); break; case FN_DEVICE_FT_DISABLE_CLOSE_PON: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_close_pon(ON); else disable_close_pon(OFF); break; case FN_DEVICE_FT_DISABLE_WRITE_PON: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_write_pon(ON); else disable_write_pon(OFF); break; } break; case CFI: switch(case_buf[1]) { case FN_DEVICE_FT_DISABLE_OPEN_CEN: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_open_cen(ON); else disable_open_cen(OFF); break; case FN_DEVICE_FT_DISABLE_CLOSE_CEN: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_close_cen(ON); else disable_close_cen(OFF); break; case FN_DEVICE_FT_DISABLE_READ_CEN: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_read_cen(ON); else disable_read_cen(OFF); break; } break; case RFI: switch(case_buf[1]) { case FN_DEVICE_FT_DISABLE_OPEN_RFS: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_open_rfs(ON); else disable_open_rfs(OFF); break; case FN_DEVICE_FT_DISABLE_CLOSE_RFS: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_close_rfs(ON); else disable_close_rfs(OFF); break; case FN_DEVICE_FT_DISABLE_READ_RFS: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_read_rfs(ON); else disable_read_rfs(OFF); break; } break; case RWFI: switch(case_buf[1]) { case FN_DEVICE_FT_DISABLE_OPEN_RWS: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_open_rws(ON); else disable_open_rws(OFF); break; case FN_DEVICE_FT_DISABLE_CLOSE_RWS: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_close_rws(ON); else disable_close_rws(OFF); break; case FN_DEVICE_FT_DISABLE_READ_RWS: if(case_buf[2] == FN_DEVICE_TEST_ON) disable_read_rws(ON); else disable_read_rws(OFF); break; } break; } return 1; }
/* * Description: MFC calls this function using read method(int read()) of FileInputStream class * Input: None * Output: RFS low : 1 RFS high : 0 */ static ssize_t felica_rfs_read(struct file *fp, char *buf, size_t count, loff_t *pos) { int rc = 0; int getvalue = GPIO_LOW_VALUE; FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_read - start \n"); /* Check error */ if(NULL == fp) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] ERROR fp is NULL \n"); return -1; } if(NULL == buf) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] ERROR buf is NULL \n"); return -1; } if(1 != count) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] ERROR count(%d) \n",(int)count); return -1; } if(NULL == pos) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] ERROR pos is NULL \n"); return -1; } /* Get GPIO value */ getvalue = felica_gpio_read(felica_get_rfs_gpio_num()); FELICA_DEBUG_MSG_MED("[FELICA_RFS] RFS GPIO status : %d \n", getvalue); if((GPIO_LOW_VALUE != getvalue)&&(GPIO_HIGH_VALUE != getvalue)) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] ERROR - getvalue is out of range \n"); return -1; } /* Copy value to user memory */ getvalue = getvalue ? GPIO_LOW_VALUE: GPIO_HIGH_VALUE; FELICA_DEBUG_MSG_MED("[FELICA_RFS] RFS status : %d \n", getvalue); rc = copy_to_user((void*)buf, (void*)&getvalue, count); if(rc) { FELICA_DEBUG_MSG_HIGH("[FELICA_RFS] ERROR - copy_to_user \n"); return rc; } FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_read - end \n"); #ifdef FELICA_FN_DEVICE_TEST FELICA_DEBUG_MSG_LOW("[FELICA_RFS] felica_rfs_read - result(%d) \n",result_read_rfs); if(result_read_rfs != -1) result_read_rfs = count; return result_read_rfs; #else return count; #endif }