int snfc_i2c_open (void) { mm_segment_t old_fs = get_fs(); int i; SNFC_DEBUG_MSG_LOW("[snfc_i2c] snfc_i2c_open\n"); for(i=0; i<I2C_STATUS_LOOP_MAX_CNT; i++) { if(__snfc_i2c_control_get_status() != I2C_STATUS_FOR_FELICA) break; usleep(100); } // // __snfc_i2c_control_set_status(I2C_STATUS_FOR_NFC); set_fs(KERNEL_DS); fd = sys_open("/dev/i2c-0", O_RDWR|O_NONBLOCK, 0); // if (fd < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_open (/dev/snfc_i2c): %d \n", fd); __snfc_i2c_control_set_status(I2C_STATUS_READY); return fd; } set_fs(old_fs); return 0; }
int snfc_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(); SNFC_DEBUG_MSG_LOW("[snfc_i2c] snfc_i2c_write\n"); set_fs(KERNEL_DS); /* */ rc = snfc_i2c_open(); if (rc) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_open : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ rc = snfc_i2c_set_slave_address(I2C_SNFC_SLAVE_ADDRESS); if (rc) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_set_slave_address : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ memset(write_buf,0x00,2*sizeof(unsigned char)); write_buf[0] = reg; write_buf[1] = *buf; SNFC_DEBUG_MSG_LOW("[snfc_i2c] write_buf[0][1] : 0x%02x 0x%02x \n",write_buf[0],write_buf[1]); /* */ rc = sys_write(fd, write_buf, 2); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - sys_write : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ rc = snfc_i2c_release(); if (rc) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_release : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } set_fs(old_fs); return 0; }
/* * Description : * Input : None * Output : */ void set_felica_i2c_status(_e_snfc_i2c_status i2c_status) { #if defined(CONFIG_LGE_FELICA_NFC) FELICA_DEBUG_MSG_MED("[FELICA_COMMON] set_felica_i2c_status : %d \n", i2c_status); __snfc_i2c_control_set_status(i2c_status); #endif }
/* * Description : * Input : None * Output : */ void set_felica_i2c_status(_e_snfc_i2c_status i2c_status) { #if defined(CONFIG_LGE_FELICA_NFC)&& defined(FELICA_NFC_INTERFACE) #ifdef FEATURE_DEBUG_MED FELICA_DEBUG_MSG("[FELICA_COMMON] set_felica_i2c_status : %d \n", i2c_status); #endif __snfc_i2c_control_set_status(i2c_status); #endif }
int snfc_i2c_release (void) { int rc = 0; mm_segment_t old_fs = get_fs(); SNFC_DEBUG_MSG_LOW("[snfc_i2c] snfc_i2c_release\n"); set_fs(KERNEL_DS); rc = sys_close(fd); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_release : %d \n", rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } set_fs(old_fs); __snfc_i2c_control_set_status(I2C_STATUS_READY); return 0; }
/* * Description : * Input : * Output : */ int snfc_i2c_read(unsigned char reg, unsigned char *buf, size_t count, struct i2c_client *client) { // struct i2c_client *client; // struct snfc_i2c_dev snfc_i2c_dev; ssize_t rc = 0; // int retry; // snfc_i2c_dev = (snfc_i2c_dev*) private_data->client; __snfc_i2c_control_set_status(I2C_STATUS_FOR_NFC); SNFC_DEBUG_MSG_LOW("[snfc_i2c] snfc_i2c_read\n"); // client = (struct snfc_i2c_dev*) private_data->client; //client->addr = I2C_SNFC_SLAVE_ADDRESS; //client->flags &= ~I2C_CLIENT_TEN; rc = i2c_master_send(client, ®, 1); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c_read] ERROR - send address : %ld \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } rc = i2c_master_recv(client, buf, count); SNFC_DEBUG_MSG_LOW("[snfc_i2c_read] read data : 0x%02x \n",*buf); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c_read] ERROR - i2c_master_recv : %ld \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } __snfc_i2c_control_set_status(I2C_STATUS_READY); return 0; }
int snfc_i2c_set_slave_address (unsigned char slave_address) { int rc = -1; rc = sys_ioctl(fd, I2C_SLAVE, slave_address>>1); // if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - sys_ioctl : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } SNFC_DEBUG_MSG_LOW("[snfc_i2c] slave address : 0x%02x\n",slave_address>>1); return 0; }
/* * Description : * Input : * Output : */ int snfc_i2c_write(unsigned char reg, unsigned char *buf, size_t count, struct i2c_client *client) { // struct i2c_client *client; //struct snfc_i2c_dev snfc_i2c_dev; ssize_t rc = 0; ssize_t err_ret = 0; unsigned char write_buf[2]; //snfc_i2c_dev = (snfc_i2c_dev*) private_data; SNFC_DEBUG_MSG_LOW("[snfc_i2c] snfc_i2c_write\n"); // client = (struct snfc_i2c_dev*) private_data->client; /* set register */ memset(write_buf,0x00,2*sizeof(unsigned char)); write_buf[0] = reg; write_buf[1] = *buf; SNFC_DEBUG_MSG_LOW("[snfc_i2c] write_buf[0][1] : 0x%02x 0x%02x \n",write_buf[0],write_buf[1]); /* write data */ rc = i2c_master_send(client, write_buf, count+1); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - i2c_master_send : %ld \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); err_ret = 1; goto write_exit; } write_exit: if(err_ret) return rc; else return 0; }
int snfc_i2c_read(unsigned char reg, unsigned char *buf, size_t count) { ssize_t rc = 0; mm_segment_t old_fs = get_fs(); int retry; SNFC_DEBUG_MSG_LOW("[snfc_i2c] snfc_i2c_read\n"); set_fs(KERNEL_DS); /* */ for(retry=0;retry<100000;retry++) { rc = snfc_i2c_open(); if(rc == 0) break; else usleep(100); } if (rc) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_open : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ rc = snfc_i2c_set_slave_address(I2C_SNFC_SLAVE_ADDRESS); if (rc) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - snfc_i2c_set_slave_address : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ rc = sys_write(fd, ®, 1); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - sys_write : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ rc = sys_read(fd, buf, count); SNFC_DEBUG_MSG_LOW("[snfc_i2c] read data : 0x%02x \n",*buf); if (rc < 0) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - sys_read : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } /* */ rc = snfc_i2c_release(); if (rc) { SNFC_DEBUG_MSG("[snfc_i2c] ERROR - felica_i2c_release : %d \n",rc); __snfc_i2c_control_set_status(I2C_STATUS_READY); return rc; } set_fs(old_fs); return 0; }