/* * Description : * Input : * Output : */ int felica_i2c_read(unsigned char reg, unsigned char *buf, size_t count) { ssize_t rc = 0; mm_segment_t old_fs = get_fs(); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] felica_i2c_read\n"); #endif set_fs(KERNEL_DS); /* dev/i2c-0 device file open */ rc = felica_i2c_open(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_open : %d \n",rc); return rc; } /* Set slave address */ rc = felica_i2c_set_slave_address(I2C_FELICA_SLAVE_ADDRESS); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_set_slave_address : %d \n",rc); return rc; } /* set register address */ rc = sys_write(fd, ®, 1); if (rc < 0) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - sys_write : %d \n",rc); return rc; } /* read register data */ rc = sys_read(fd, buf, count); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] read data : 0x%02x \n",*buf); #endif if (rc < 0) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - sys_read : %d \n",rc); return rc; } /* release i2c */ rc = felica_i2c_release(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_release : %d \n",rc); return rc; } set_fs(old_fs); return 0; }
/* * Description : * Input : * Output : */ int felica_i2c_write(unsigned char reg, unsigned char *buf, size_t count) { ssize_t rc = 0; unsigned char write_buf[2]; mm_segment_t old_fs = get_fs(); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] felica_i2c_write\n"); #endif set_fs(KERNEL_DS); /* dev/i2c-0 device file open */ rc = felica_i2c_open(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_open : %d \n",rc); return rc; } /* set slave address */ rc = felica_i2c_set_slave_address(I2C_FELICA_SLAVE_ADDRESS); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_set_slave_address : %d \n",rc); return rc; } /* set register */ memset(write_buf,0x00,2*sizeof(unsigned char)); write_buf[0] = reg; write_buf[1] = *buf; #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] write_buf[0][1] : 0x%02x 0x%02x \n",write_buf[0],write_buf[1]); #endif /* write data */ rc = sys_write(fd, write_buf, 2); if (rc < 0) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - sys_write : %d \n",rc); return rc; } /* release i2c */ rc = felica_i2c_release(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_release : %d \n",rc); return rc; } set_fs(old_fs); return 0; }
/* * Description : * Input : * Output : */ int felica_i2c_write(unsigned char reg, unsigned char *buf, size_t count) { ssize_t rc = 0; unsigned char write_buf[2]; mm_segment_t old_fs = get_fs(); int retry = 10; #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] felica_i2c_write\n"); #endif // while((I2C_STATUS_NO_USE != get_felica_i2c_status())&&(retry > 0)) while((I2C_STATUS_FOR_NFC == get_felica_i2c_status())&&(retry > 0)) { usleep(100); retry--; } // if(I2C_STATUS_NO_USE != get_felica_i2c_status()) if(I2C_STATUS_FOR_NFC == get_felica_i2c_status()) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - other device(NFC) use i2c abnormally \n"); goto ERROR; } set_felica_i2c_status(I2C_STATUS_FOR_FELICA); set_fs(KERNEL_DS); /* dev/i2c-0 device file open */ rc = felica_i2c_open(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_open : %d \n",rc); goto ERROR; } /* set slave address */ rc = felica_i2c_set_slave_address(I2C_FELICA_SLAVE_ADDRESS); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_set_slave_address : %d \n",rc); goto ERROR; } /* set register */ memset(write_buf,0x00,2*sizeof(unsigned char)); write_buf[0] = reg; write_buf[1] = *buf; #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] write_buf[0][1] : 0x%02x 0x%02x \n",write_buf[0],write_buf[1]); #endif /* write data */ rc = sys_write(fd, write_buf, 2); if (rc < 0) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - sys_write : %d \n",rc); goto ERROR; } /* release i2c */ rc = felica_i2c_release(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_release : %d \n",rc); goto ERROR; } set_fs(old_fs); // set_felica_i2c_status(I2C_STATUS_NO_USE); set_felica_i2c_status(I2C_STATUS_READY); return 0; ERROR: // set_felica_i2c_status(I2C_STATUS_NO_USE); set_felica_i2c_status(I2C_STATUS_READY); return rc; }
/* * Description : * Input : * Output : */ int felica_i2c_read(unsigned char reg, unsigned char *buf, size_t count) { ssize_t rc = 0; mm_segment_t old_fs = get_fs(); int retry = 10; #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] felica_i2c_read\n"); #endif // while((I2C_STATUS_NO_USE != get_felica_i2c_status())&&(retry > 0)) while((I2C_STATUS_FOR_NFC == get_felica_i2c_status())&&(retry > 0)) { usleep(100); retry--; } // if(I2C_STATUS_NO_USE != get_felica_i2c_status()) if(I2C_STATUS_FOR_NFC == get_felica_i2c_status()) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - other device(NFC) use i2c abnormally \n"); goto ERROR; } set_felica_i2c_status(I2C_STATUS_FOR_FELICA); set_fs(KERNEL_DS); /* dev/i2c-0 device file open */ rc = felica_i2c_open(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_open : %d \n",rc); goto ERROR; } /* Set slave address */ rc = felica_i2c_set_slave_address(I2C_FELICA_SLAVE_ADDRESS); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_set_slave_address : %d \n",rc); goto ERROR; } /* set register address */ rc = sys_write(fd, ®, 1); if (rc < 0) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - sys_write : %d \n",rc); goto ERROR; } /* read register data */ rc = sys_read(fd, buf, count); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_I2C] read data : 0x%02x \n",*buf); #endif if (rc < 0) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - sys_read : %d \n",rc); goto ERROR; } /* release i2c */ rc = felica_i2c_release(); if (rc) { FELICA_DEBUG_MSG("[FELICA_I2C] ERROR - felica_i2c_release : %d \n",rc); goto ERROR; } set_fs(old_fs); // set_felica_i2c_status(I2C_STATUS_NO_USE); set_felica_i2c_status(I2C_STATUS_READY); return 0; ERROR: // set_felica_i2c_status(I2C_STATUS_NO_USE); set_felica_i2c_status(I2C_STATUS_READY); return rc; }