static int AMI304_ReadSensorData(char *buf, int bufsize) { char cmd; int mode = 0; unsigned char databuf[10] = {0,}; int res = 0; if ((!buf)||(bufsize<=80)) return -1; if (!ami304_i2c_client) { *buf = 0; return -2; } read_lock(&ami304_data.lock); mode = ami304_data.mode; read_unlock(&ami304_data.lock); databuf[0] = AMI304_REG_CTRL3; databuf[1] = AMI304_CTRL3_FORCE_BIT; res = i2c_master_send(ami304_i2c_client, databuf, 2); if (res <= 0) goto exit_AMI304_ReadSensorData; //udelay(700); msleep(1); // We can read all measured data in once cmd = AMI304_REG_DATAXH; res = i2c_master_send(ami304_i2c_client, &cmd, 1); if (res <= 0) goto exit_AMI304_ReadSensorData; // udelay(20); res = i2c_master_recv(ami304_i2c_client, &(databuf[0]), 6); if (res <= 0) goto exit_AMI304_ReadSensorData; sprintf(buf, "%02x %02x %02x %02x %02x %02x", databuf[0], databuf[1], databuf[2], databuf[3], databuf[4], databuf[5]); if (AMI304_DEBUG_DEV_STATUS & ami304_debug_mask) { int mx, my, mz; mx = my = mz = 0; mx = (int)(databuf[0] | (databuf[1] << 8)); my = (int)(databuf[2] | (databuf[3] << 8)); mz = (int)(databuf[4] | (databuf[5] << 8)); if (mx>32768) mx = mx-65536; if (my>32768) my = my-65536; if (mz>32768) mz = mz-65536; AMID("Magnetic Raw Data: X=%d, Y=%d, Z=%d\n", mx, my, mz); } exit_AMI304_ReadSensorData: if (res <= 0) { if (printk_ratelimit()) { AMIE("I2C error: ret value=%d\n", res); } return -3; } return 0; }
static ssize_t pn547_dev_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct pn547_dev *pn547_dev = filp->private_data; static char tmp[MAX_BUFFER_SIZE]; int ret; static bool isFinalPacket = true; unsigned long flags; if (count > MAX_BUFFER_SIZE) count = MAX_BUFFER_SIZE; //pr_err("%s : reading %zu bytes.\n", __func__, count); // for debug wait: if (isFinalPacket == true) { ret = wait_event_interruptible_timeout(pn547_dev->read_wq, gpio_get_value(pn547_dev->irq_gpio), msecs_to_jiffies(NFC_TIMEOUT_MS)); if (ret == 0) { pr_err("%s: event_interruptible!\n", __func__); // NFC_TIMEOUT_MS for debug spin_lock_irqsave(&pn547_dev->irq_enabled_lock, flags); if (sIsWakeLocked == true) { wake_unlock(&nfc_wake_lock); sIsWakeLocked = false; } spin_unlock_irqrestore(&pn547_dev->irq_enabled_lock, flags); //pr_err("%s: wake_unlock\n", __func__); // for debug isFinalPacket = false; goto wait; } } else { ret = wait_event_interruptible(pn547_dev->read_wq, gpio_get_value(pn547_dev->irq_gpio)); isFinalPacket = true; } if (ret == -ERESTARTSYS) { //pr_err("%s: pass wait_event_interruptible by signal. Skip!\n", __func__); // for debug return -0xFF; } else { //pr_err("%s: pass wait_event_interruptible by condition (%d)\n", __func__, gpio_get_value(pn547_dev->irq_gpio)); // for debug } /* Read data */ mutex_lock(&pn547_dev->read_mutex); memset(tmp, 0x00, MAX_BUFFER_SIZE); ret = i2c_master_recv(pn547_dev->client, tmp, count); mutex_unlock(&pn547_dev->read_mutex); if (count == 0) { pr_err("%s: reading 0 bytes! skip! (%d)\n", __func__, ret); return ret; } if (ret < 0) { pr_err("%s: i2c_master_recv returned %d\n", __func__, ret); return ret; } if (ret > count) { pr_err("%s: received too many bytes from i2c (%d)\n", __func__, ret); return -EIO; } if (copy_to_user(buf, tmp, ret)) { pr_warning("%s : failed to copy to user space\n", __func__); return -EFAULT; } //pr_err("%s: i2c_master_recv success (%d)\n", __func__, ret); // for debug return ret; }
static int check_bootloader(struct i2c_client *client, unsigned int uState) { u8 uVal; u8 uTemp; recheck: if (i2c_master_recv(client, &uVal, 1) != 1) return -EIO; if (uVal & 0x20) { if (i2c_master_recv(client, &uTemp, 1) != 1) { pr_err("[SSP]: %s - i2c recv fail\n", __func__); return -EIO; } if (i2c_master_recv(client, &uTemp, 1) != 1) { pr_err("[SSP]: %s - i2c recv fail\n", __func__); return -EIO; } uVal &= ~0x20; } if ((uVal & 0xF0) == BL_APP_CRC_FAIL) { pr_info("[SSP] SSP_APP_CRC_FAIL - There is no bootloader.\n"); if (i2c_master_recv(client, &uVal, 1) != 1) { pr_err("[SSP]: %s - i2c recv fail\n", __func__); return -EIO; } if (uVal & 0x20) { if (i2c_master_recv(client, &uTemp, 1) != 1) { pr_err("[SSP]: %s - i2c recv fail\n", __func__); return -EIO; } if (i2c_master_recv(client, &uTemp, 1) != 1) { pr_err("[SSP]: %s - i2c recv fail\n", __func__); return -EIO; } uVal &= ~0x20; } } switch (uState) { case BL_WAITING_BOOTLOAD_CMD: case BL_WAITING_FRAME_DATA: uVal &= ~BL_BOOT_STATUS_MASK; break; case BL_FRAME_CRC_PASS: if (uVal == BL_FRAME_CRC_CHECK) goto recheck; break; default: return -EINVAL; } if (uVal != uState) { pr_err("[SSP]: %s - Unvalid bootloader mode state\n", __func__); return -EINVAL; } return 0; }
static ssize_t bcm2079x_dev_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct bcm2079x_dev *bcm2079x_dev = filp->private_data; unsigned char tmp[MAX_BUFFER_SIZE]; int total, len, ret; total = 0; len = 0; if (bcm2079x_dev->count_irq > 0) bcm2079x_dev->count_irq--; bcm2079x_dev->count_read++; if (count > MAX_BUFFER_SIZE) count = MAX_BUFFER_SIZE; mutex_lock(&bcm2079x_dev->read_mutex); /** Read the first 4 bytes to include the length of the NCI or HCI. **/ ret = i2c_master_recv(bcm2079x_dev->client, tmp, 4); if (ret == 4) { total = ret; /** First byte is the packet type **/ switch (tmp[0]) { case PACKET_TYPE_NCI: len = tmp[PACKET_HEADER_SIZE_NCI-1]; break; case PACKET_TYPE_HCIEV: len = tmp[PACKET_HEADER_SIZE_HCI-1]; if (len == 0) /* Since payload is 0, decrement total size (from 4 to 3) */ total--; else /*First byte of payload is in tmp[3] already */ len--; break; default: /*Unknown packet byte */ len = 0; break; } /* switch*/ /** make sure full packet fits in the buffer **/ if (len > 0 && (len + total) <= count) { /** read the remainder of the packet. **/ ret = i2c_master_recv(bcm2079x_dev->client, tmp+total, len); if (ret == len) total += len; } /* if */ } /* if */ mutex_unlock(&bcm2079x_dev->read_mutex); if (total > count || copy_to_user(buf, tmp, total)) { dev_err(&bcm2079x_dev->client->dev, "failed to copy to user space, total = %d\n", total); total = -EFAULT; bcm2079x_dev->error_read++; } return total; }
/* ------------------------------------------------------------------------- */ static ssize_t pn544_dev_read (struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct pn544_dev *pn544 = (struct pn544_dev *)filp->private_data; struct i2c_client *client = (struct i2c_client *)pn544->client; char *tmp; int ret; // int irq_gpio = irq_to_gpio(client->irq); int irq_gpio = INT_TO_MSM_GPIO(client->irq); if (count > MAX_BUFFER_SIZE) { count = MAX_BUFFER_SIZE; } tmp = kmalloc(count,GFP_KERNEL); if (tmp == NULL) { return -ENOMEM; } #ifdef ZTE_NFC_DEBUG printk("pn544-dev: reading %zu bytes.\n", count); #else pr_debug("pn544-dev: reading %zu bytes.\n", count); #endif /* Lock semaphore */ if (down_interruptible(&pn544->sem)) { return -ERESTARTSYS; } /* Wait for IRQ if not already pending */ if(pn544_dev->int_active_low==1) { while (gpio_get_value(irq_gpio)) { /* Not ready to read data, release semaphore */ up(&pn544->sem); /* Handle non-blocking calls */ if (filp->f_flags & O_NONBLOCK) { return -EAGAIN; } #ifdef ZTE_NFC_DEBUG printk("pn544-dev: wait for incoming data1.\n"); #else pr_debug("pn544-dev: wait for incoming data1.\n"); #endif #if 0 /* Sleep until the IRQ comes */ /*这个函数睡眠之后不会被调度,需要在中断或定时器中wake_up_interruptible() 之后才会被调度去判决gpio_get_value(irq_gpio)!=0 */ if (wait_event_interruptible(pn544->read_queue, (gpio_get_value(irq_gpio)==0))) { printk(KERN_ERR"pn544-dev: wait for interrupt error1.\n"); return -ERESTARTSYS; /* signal: tell the fs layer to handle it */ } #else if(wait_event_interruptible_timeout(pn544->read_queue, (gpio_get_value(irq_gpio)==0), msecs_to_jiffies(5000))<=0){ printk(KERN_ERR"pn544-dev: wait for interrupt error1.\n"); return -ERESTARTSYS; /* signal: tell the fs layer to handle it */ } #endif /* Loop, but first reacquire the lock (to avoid multiple read concurrency) */ if (down_interruptible(&pn544->sem)) { printk(KERN_ERR"pn544-dev: wait for interrupt sem error1.\n"); return -ERESTARTSYS; } } } else { while (!gpio_get_value(irq_gpio)) { /* Not ready to read data, release semaphore */ up(&pn544->sem); /* Handle non-blocking calls */ if (filp->f_flags & O_NONBLOCK) { return -EAGAIN; } #ifdef ZTE_NFC_DEBUG printk("pn544-dev: wait for incoming data2.\n"); #else pr_debug("pn544-dev: wait for incoming data2.\n"); #endif #if 1 //NXP CODE /* Sleep until the IRQ comes */ /*这个函数睡眠之后不会被调度,需要在中断或定时器中wake_up_interruptible() 之后才会被调度去判决gpio_get_value(irq_gpio)!=0 */ if (wait_event_interruptible(pn544->read_queue, (gpio_get_value(irq_gpio)!=0))) { printk(KERN_ERR"pn544-dev: wait for interrupt error2.\n"); return -ERESTARTSYS; /* signal: tell the fs layer to handle it */ } #else if(wait_event_interruptible_timeout(pn544->read_queue, (gpio_get_value(irq_gpio)!=0), msecs_to_jiffies(5000))<=0){ printk(KERN_ERR"pn544-dev: wait for interrupt error2.\n"); return -ERESTARTSYS; /* signal: tell the fs layer to handle it */ } #endif /* Loop, but first reacquire the lock (to avoid multiple read concurrency) */ if (down_interruptible(&pn544->sem)) { printk(KERN_ERR"pn544-dev: wait for interrupt sem error2.\n"); return -ERESTARTSYS; } } } /* Read data */ ret = i2c_master_recv(client, tmp, count); if (ret >= 0) { ret = copy_to_user(buf, tmp, count)?-EFAULT:ret; #ifdef ZTE_NFC_DEBUG printk("pn544_dev_read: received "); printk_buffer(tmp, count); printk("\n"); #else pr_debug("pn544_dev_read: received "); pr_debug_buffer(tmp, count); pr_debug("\n"); #endif } else if (ret < 0) { printk(KERN_WARNING "pn544_dev: failed to read from i2c (error code %d)\n", ret); } /* Release semaphore */ up (&pn544->sem); kfree(tmp); return ret; }
static void epen_checksum_read_atBoot(struct wacom_i2c *wac_i2c) { int ret; int val; int i,j; int retry = 3; unsigned char data[6] = {0,}; { disable_irq(wac_i2c->client->irq); data[0] = COM_CHECKSUM; while( retry-- ) { ret = i2c_master_send(wac_i2c->client, &data[0], 1); if( ret < 0 ){ printk(KERN_DEBUG "[E-PEN] i2c fail, retry, %d\n", __LINE__); continue; } msleep(200); ret = i2c_master_recv(wac_i2c->client, data, 5); if( ret < 0 ){ printk(KERN_DEBUG "[E-PEN] i2c fail, retry, %d\n", __LINE__); continue; } else if( data[0] == 0x1f ) break; printk(KERN_DEBUG "[E-PEN] checksum retry\n"); } if (ret >= 0) { printk(KERN_DEBUG "[E-PEN] received checksum %x, %x, %x, %x, %x\n", data[0], data[1], data[2], data[3], data[4]); for( j = 0 ; j < 5; j++ ){ Firmware_checksum_backup[j] = data[j]; } } for( i = 0 ; i < 5; ++i ) { if( data[i] != Firmware_checksum[i] ){ printk(KERN_DEBUG "[E-PEN] checksum fail %dth %d %d\n", i, data[i], Firmware_checksum[i]); break; } } if( i == 5 ) epen_checksum_result = true; else epen_checksum_result = false; enable_irq(wac_i2c->client->irq); printk(KERN_DEBUG "[E-PEN] %s, result %d\n", __func__, epen_checksum_result); } }
static ssize_t pn544_dev_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct pn544_dev *pn544_dev = filp->private_data; static char tmp[MAX_BUFFER_SIZE]; int ret; int irq_gpio_val = 0; if (count > MAX_BUFFER_SIZE) count = MAX_BUFFER_SIZE; pr_debug("%s : reading %zu bytes.\n", __func__, count); mutex_lock(&pn544_dev->read_mutex); if (!stReadIntFlag) { irq_gpio_val = gpio_get_value(pn544_dev->irq_gpio); dprintk(PN544_DRV_NAME ":IRQ GPIO = %d\n", irq_gpio_val); if (irq_gpio_val == 0) { if (filp->f_flags & O_NONBLOCK) { pr_err(PN544_DRV_NAME ":f_falg has O_NONBLOCK. EAGAIN!\n"); ret = -EAGAIN; goto fail; } pn544_dev->irq_enabled = true; #ifdef LGE_NFC_READ_IRQ_MODIFY do_reading=0;//DY_TEST #endif // #if !defined(LGE_NFC_HW_QCT_MSM8660) enable_irq_wake(pn544_get_irq_pin(pn544_dev)); #endif enable_irq(pn544_get_irq_pin(pn544_dev)); #ifdef LGE_NFC_READ_IRQ_MODIFY ret = wait_event_interruptible(pn544_dev->read_wq, do_reading); #else ret = wait_event_interruptible(pn544_dev->read_wq, gpio_get_value(pn544_dev->irq_gpio)); #endif pn544_disable_irq(pn544_dev); //dprintk(PN544_DRV_NAME ":wait_event_interruptible : %d\n", ret); #ifdef LGE_NFC_READ_IRQ_MODIFY //DY_TEST if(cancle_read == true) { cancle_read = false; ret = -1; goto fail; } #endif if (ret) goto fail; } } /* Read data */ memset(tmp, 0x00, MAX_BUFFER_SIZE); ret = i2c_master_recv(pn544_dev->client, tmp, count); mutex_unlock(&pn544_dev->read_mutex); if (ret < 0) { pr_err("%s: i2c_master_recv returned %d\n", __func__, ret); return ret; } if (ret > count) { pr_err("%s: received too many bytes from i2c (%d)\n", __func__, ret); return -EIO; } if (copy_to_user(buf, tmp, ret)) { pr_warning("%s : failed to copy to user space\n", __func__); return -EFAULT; } return ret; fail: mutex_unlock(&pn544_dev->read_mutex); return ret; }
static ssize_t pn544_dev_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct pn544_dev *pn544_dev = filp->private_data; int ret,i; char tmp[MAX_BUFFER_SIZE]; if (count > MAX_BUFFER_SIZE) count = MAX_BUFFER_SIZE; printk("pn544 %s : reading %zu bytes.\n", __func__, count); mutex_lock(&pn544_dev->read_mutex); if (!mt_get_gpio_in(IRQ_PIN)) { printk("pn544 read no event\n"); if (filp->f_flags & O_NONBLOCK) { ret = -EAGAIN; goto fail; } printk("pn544 read wait event\n"); pn544_dev->irq_enabled = true; mt65xx_eint_unmask(EINT_NUM); ret = wait_event_interruptible(pn544_dev->read_wq, mt_get_gpio_in(IRQ_PIN)); pn544_disable_irq(pn544_dev); if (ret) { printk("pn544 read wait event error\n"); goto fail; } } /* Read data */ ret = i2c_master_recv(pn544_dev->client, tmp, count); mutex_unlock(&pn544_dev->read_mutex); if (ret < 0) { pr_err("pn544 %s: i2c_master_recv returned %d\n", __func__, ret); return ret; } if (ret > count) { pr_err("pn544 %s: received too many bytes from i2c (%d)\n", __func__, ret); return -EIO; } if (copy_to_user(buf, tmp, ret)) { pr_warning("pn544 %s : failed to copy to user space\n", __func__); return -EFAULT; } printk("pn544 IFD->PC:"); for(i = 0; i < ret; i++) { printk(" %02X", tmp[i]); } printk("\n"); return ret; fail: mutex_unlock(&pn544_dev->read_mutex); return ret; }
int pn544_i2c_read(struct i2c_client *client, u8 *buf, int buflen) { int ret=0; u8 len=0; int i = 0; PN544_DEBUG("%s:entered\n",__func__); /* You could read a packet in one go, but then you'd need to read * max size and rest would be 0xff fill, so we do split reads. */ ret = i2c_master_recv(client, &len, sizeof(len)); PN544_DEBUG("%s:recv1: ret=%d,len=%d\n", __func__, ret , len); if (0==pn544_use_read_irq) { /* if we do not use irq when the data is not ready we need to delay * sometime to receive again */ if(len==PN544_NODATA) { mdelay(10); ret = i2c_master_recv(client, &len, sizeof(len)); PN544_DEBUG("%s:recv2: ret=%d,len=%d\n", __func__, ret , len); } } if (ret != 1) return -EREMOTEIO; if(PN544_NODATA == len) return -EREMOTEIO; /* we make sure the length is legal for the LLC Layer*/ if (len < PN544_LLC_HCI_OVERHEAD) len = PN544_LLC_HCI_OVERHEAD; else if (len > (PN544_MSG_MAX_SIZE - 1)) len = PN544_MSG_MAX_SIZE - 1; if (1 + len > buflen) /* len+(data+crc16) */ return -EMSGSIZE; buf[0] = len; ret = i2c_master_recv(client, buf + 1, len); if (ret != len) return -EREMOTEIO; usleep_range(3000, 6000); PN544_DEBUG("IFD->PC: "); for(i = 0; i < len; i++) { PN544_DEBUG("%02X", buf[i]); } PN544_DEBUG("\n"); return ret + 1; }
int wacom_i2c_coord(struct wacom_i2c *wac_i2c) { bool prox = false; int ret = 0; u8 *data; int rubber, stylus; static u16 x, y, pressure; static u16 tmp; int rdy = 0; data = wac_i2c->wac_feature->data; ret = i2c_master_recv(wac_i2c->client, data, COM_COORD_NUM); if (ret >= 0) { #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) pr_debug("[E-PEN] %x, %x, %x, %x, %x, %x, %x\n", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); #endif if (data[0] & 0x80) { /* enable emr device */ if (!wac_i2c->pen_prox) { wac_i2c->pen_prox = 1; if (data[0] & 0x40) wac_i2c->tool = BTN_TOOL_RUBBER; else wac_i2c->tool = BTN_TOOL_PEN; #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) pr_debug("[E-PEN] is in(%d)\n", wac_i2c->tool); #endif } prox = !!(data[0] & 0x10); stylus = !!(data[0] & 0x20); rubber = !!(data[0] & 0x40); rdy = !!(data[0] & 0x80); x = ((u16) data[1] << 8) + (u16) data[2]; y = ((u16) data[3] << 8) + (u16) data[4]; pressure = ((u16) data[5] << 8) + (u16) data[6]; #ifdef WACOM_IMPORT_FW_ALGO /* Change Position to Active Area */ if (x <= origin_offset[0]) x = 0; else x = x - origin_offset[0]; if (y <= origin_offset[1]) y = 0; else y = y - origin_offset[1]; #ifdef COOR_WORK_AROUND wacom_i2c_coord_offset(&x, &y); wacom_i2c_coord_average(&x, &y, rdy); #endif #endif if (wac_i2c->wac_pdata->x_invert) x = wac_i2c->wac_feature->x_max - x; if (wac_i2c->wac_pdata->y_invert) y = wac_i2c->wac_feature->y_max - y; if (wac_i2c->wac_pdata->xy_switch) { tmp = x; x = y; y = tmp; } #ifdef COOR_WORK_AROUND /* Add offset */ x = x + tilt_offsetX[user_hand][screen_rotate]; y = y + tilt_offsetY[user_hand][screen_rotate]; #endif if (wacom_i2c_coord_range(&x, &y)) { input_report_abs(wac_i2c->input_dev, ABS_X, x); input_report_abs(wac_i2c->input_dev, ABS_Y, y); input_report_abs(wac_i2c->input_dev, ABS_PRESSURE, pressure); input_report_key(wac_i2c->input_dev, BTN_STYLUS, stylus); input_report_key(wac_i2c->input_dev, BTN_TOUCH, prox); input_report_key(wac_i2c->input_dev, wac_i2c->tool, 1); input_sync(wac_i2c->input_dev); if (prox && !wac_i2c->pen_pressed) { #ifdef SEC_DVFS_LOCK set_dvfs_lock(wac_i2c, true); #endif #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) printk(KERN_DEBUG "[E-PEN] is pressed(%d,%d,%d)(%d)\n", x, y, pressure, wac_i2c->tool); #else printk(KERN_DEBUG "[E-PEN] pressed\n"); #endif } else if (!prox && wac_i2c->pen_pressed) { #ifdef SEC_DVFS_LOCK set_dvfs_lock(wac_i2c, false); #endif #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) printk(KERN_DEBUG "[E-PEN] is released(%d,%d,%d)(%d)\n", x, y, pressure, wac_i2c->tool); #else printk(KERN_DEBUG "[E-PEN] released\n"); #endif } wac_i2c->pen_pressed = prox; #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) if (stylus && !wac_i2c->side_pressed) printk(KERN_DEBUG "[E-PEN] side on"); else if (!stylus && wac_i2c->side_pressed) printk(KERN_DEBUG "[E-PEN] side off"); #endif wac_i2c->side_pressed = stylus; } #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) else printk("[E-PEN] raw data x=0x%x, y=0x%x\n", x, y); #endif } else { #ifdef COOR_WORK_AROUND /* enable emr device */ wacom_i2c_coord_average(0, 0, 0); #endif if (wac_i2c->pen_prox) { /* input_report_abs(wac->input_dev, ABS_X, x); */ /* input_report_abs(wac->input_dev, ABS_Y, y); */ input_report_abs(wac_i2c->input_dev, ABS_PRESSURE, 0); input_report_key(wac_i2c->input_dev, BTN_STYLUS, 0); input_report_key(wac_i2c->input_dev, BTN_TOUCH, 0); input_report_key(wac_i2c->input_dev, wac_i2c->tool, 0); input_sync(wac_i2c->input_dev); #if defined(CONFIG_SAMSUNG_KERNEL_DEBUG_USER) if (wac_i2c->pen_pressed || wac_i2c->side_pressed) printk(KERN_DEBUG "[E-PEN] is out"); else printk(KERN_DEBUG "[E-PEN] is out"); #endif } wac_i2c->pen_prox = 0; wac_i2c->pen_pressed = 0; wac_i2c->side_pressed = 0; #ifdef SEC_DVFS_LOCK set_dvfs_lock(wac_i2c, false); #endif } } else { printk(KERN_ERR "[E-PEN]: failed to read i2c\n"); return -1; } return 0; }
static void adp5588_work_func( struct work_struct *work) { int rc,i; uint8_t reg=ADP5588_REG_KEY_EVENTA; struct adp5588_keypad_data *kp = container_of(work, struct adp5588_keypad_data, work); struct i2c_client *client=kp->client; uint8_t scan_code; /* set read address */ I2C_MUTEX_LOCK; if ((rc = i2c_master_send(client, ®, 1)) <0) { dev_err(&client->dev," %s(%s):i2c_master_send error %d\n", __FILE__, __FUNCTION__, rc); /* I2c Write error . exit now , enable IRQ and read again if IRQ pin still low */ } else { /* read scancodes until queue is empty */ i=0; do { scan_code =ADP5588_KEY_FIFO_EMPTY; if ((rc = i2c_master_recv(client, &scan_code,1 )) < 0 ) { dev_err(&client->dev," %s(%s):i2c_master_recv error %d\n", __FILE__, __FUNCTION__, rc); break; } if( scan_code != ADP5588_KEY_FIFO_EMPTY ) { kp->last_key = ADP5588_KEY_CODE & scan_code ; kp->last_key_state = !!(ADP5588_KEY_RELEASE & scan_code); dev_dbg(&client->dev,"ADP5588 got scancode %d ,keycode 0x%x ( %d ) state %d \n", scan_code, kp->last_key, kp->last_key,kp->last_key_state ); if( kp->last_key == ADP5588_GPIO_KEY ) { /* got RINGER/SILENCE switch event */ adp5588_data.ringer_switch = kp->last_key_state; switch_set_state(&adp5588_data.sw_mute_dev, !adp5588_data.ringer_switch); } else { /* got regular key event */ input_report_key(kp->input_dev, kp->last_key, kp->last_key_state); } // Sync is removed. It does not required for key event // input_sync(kp->input_dev); } else if( i == 0 ) { /*IRQ without the code ? , must be key release HW problem , Wait 5ms */ clk_busy_wait(5000); } } while( scan_code && (i++ <10) ); } I2C_MUTEX_UNLOCK; /* Clear IRQ and enable it */ if (kp->use_irq) { if ( adp5588_clear_irq(client)<0) { /* I2c Problem , do not enable IRQ but wait 1 sec */ hrtimer_start(&kp->timer, ktime_set(1,0), HRTIMER_MODE_REL); } else enable_irq(client->irq); } }
static int fdp_nci_i2c_read(struct fdp_i2c_phy *phy, struct sk_buff **skb) { int r, len; u8 tmp[FDP_NCI_I2C_MAX_PAYLOAD], lrc, k; u16 i; struct i2c_client *client = phy->i2c_dev; *skb = NULL; /* Read the length packet and the data packet */ for (k = 0; k < 2; k++) { len = phy->next_read_size; r = i2c_master_recv(client, tmp, len); if (r != len) { dev_dbg(&client->dev, "%s: i2c recv err: %d\n", __func__, r); goto flush; } /* Check packet integruty */ for (lrc = i = 0; i < r; i++) lrc ^= tmp[i]; /* * LRC check failed. This may due to transmission error or * desynchronization between driver and FDP. Drop the paquet * and force resynchronization */ if (lrc) { dev_dbg(&client->dev, "%s: corrupted packet\n", __func__); phy->next_read_size = 5; goto flush; } /* Packet that contains a length */ if (tmp[0] == 0 && tmp[1] == 0) { phy->next_read_size = (tmp[2] << 8) + tmp[3] + 3; } else { phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD; *skb = alloc_skb(len, GFP_KERNEL); if (*skb == NULL) { r = -ENOMEM; goto flush; } memcpy(skb_put(*skb, len), tmp, len); fdp_nci_i2c_dump_skb(&client->dev, "fdp_rd", *skb); fdp_nci_i2c_remove_len_lrc(*skb); } } return 0; flush: /* Flush the remaining data */ if (i2c_master_recv(client, tmp, sizeof(tmp)) < 0) r = -EREMOTEIO; return r; }
static void irda_remocon_work(struct ir_remocon_data *ir_data, int count) { struct ir_remocon_data *data = ir_data; struct i2c_client *client = data->client; int buf_size = count+2; int ret, retry; int sleep_timing; int end_data; int emission_time; int ack_pin_onoff; #ifdef DEBUG u8 buf[8]; #endif if (count_number >= 100) count_number = 0; count_number++; data->on_off = 1; irda_vdd_onoff(1); gpio_set_value(data->pdata->irda_poweron, 0); data->pdata->ir_wake_en(data->pdata, 0); msleep(100); gpio_set_value(data->pdata->irda_poweron, 1); data->pdata->ir_wake_en(data->pdata,1); gpio_tlmm_config(GPIO_CFG(ir_data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE); msleep(125); printk(KERN_INFO "%s: total buf_size: %d\n", __func__, buf_size); #ifdef DEBUG ret = i2c_master_recv(client, buf, MC96_READ_LENGTH); if (ret < 0) printk(KERN_CRIT "%s: I2C read err %d\n", __func__, ret); print_hex_dump(KERN_CRIT, "irda: IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf, 8, 1); #endif irda_add_checksum_length(data, count); mutex_lock(&data->mutex); ret = i2c_master_send(client, data->signal, buf_size); if (ret < 0) { dev_err(&client->dev, "%s: err1 %d\n", __func__, ret); ret = i2c_master_send(client, data->signal, buf_size); if (ret < 0) dev_err(&client->dev, "%s: err2 %d\n", __func__, ret); } msleep(10); ack_pin_onoff = 0; for(retry = 0; retry < 10; retry++) { if (gpio_get_value(data->pdata->irda_irq_gpio)) { if(retry == 9) { printk(KERN_INFO "%s : %d Checksum NG!\n", __func__, count_number); } ack_pin_onoff = 1; msleep(3); } else { printk(KERN_INFO "%s : %d Checksum OK!\n", __func__, count_number); ack_pin_onoff = 2; break; } } ack_number = ack_pin_onoff; mutex_unlock(&data->mutex); #if 0 for (i = 0; i < buf_size; i++) { printk(KERN_INFO "%s: data[%d] : 0x%02x\n", __func__, i, data->signal[i]); } #endif data->count = 2; end_data = data->signal[count-2] << 8 | data->signal[count-1]; emission_time = \ (1000 * (data->ir_sum - end_data) / (data->ir_freq)) + 10; sleep_timing = emission_time - 130; if (sleep_timing > 0) msleep(sleep_timing); /* printk(KERN_INFO "%s: sleep_timing = %d\n", __func__, sleep_timing); */ emission_time = \ (1000 * (data->ir_sum) / (data->ir_freq)) + 50; if (emission_time > 0) msleep(emission_time); printk(KERN_INFO "%s: emission_time = %d\n", __func__, emission_time); for(retry = 0; retry < 30; retry++) { if (gpio_get_value(data->pdata->irda_irq_gpio)) { printk(KERN_INFO "%s : %d Sending IR OK!\n", __func__, count_number); ack_pin_onoff = 4; break; } else { if(retry == 29) { printk(KERN_INFO "%s : %d Sending IR NG!\n", __func__, count_number); } ack_pin_onoff = 2; msleep(65); } } ack_number += ack_pin_onoff; #ifndef USE_STOP_MODE data->on_off = 0; data->pdata->ir_wake_en(data->pdata,0); irda_vdd_onoff(0); gpio_set_value(data->pdata->irda_poweron, 0); #endif data->ir_freq = 0; data->ir_sum = 0; gpio_tlmm_config(GPIO_CFG(ir_data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE); }
static int cypress_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct input_dev *input_dev; struct cypress_touchkey_devdata *devdata; u8 data[3]; int err; int cnt; if (!dev->platform_data) { dev_err(dev, "%s: Platform data is NULL\n", __func__); return -EINVAL; } devdata = kzalloc(sizeof(*devdata), GFP_KERNEL); if (devdata == NULL) { dev_err(dev, "%s: failed to create our state\n", __func__); return -ENODEV; } devdata->client = client; i2c_set_clientdata(client, devdata); devdata->pdata = client->dev.platform_data; if (!devdata->pdata->keycode) { dev_err(dev, "%s: Invalid platform data\n", __func__); err = -EINVAL; goto err_null_keycodes; } strlcpy(devdata->client->name, DEVICE_NAME, I2C_NAME_SIZE); input_dev = input_allocate_device(); if (!input_dev) { err = -ENOMEM; goto err_input_alloc_dev; } devdata->input_dev = input_dev; dev_set_drvdata(&input_dev->dev, devdata); input_dev->name = DEVICE_NAME; input_dev->id.bustype = BUS_HOST; for (cnt = 0; cnt < devdata->pdata->keycode_cnt; cnt++) input_set_capability(input_dev, EV_KEY, devdata->pdata->keycode[cnt]); devdata->is_powering_on = true; devdata->pdata->touchkey_onoff(TOUCHKEY_ON); err = i2c_master_recv(client, data, sizeof(data)); if (err < sizeof(data)) { if (err >= 0) err = -EIO; dev_err(dev, "%s: error reading hardware version\n", __func__); goto err_read; } dev_info(dev, "%s: hardware rev1 = %#02x, rev2 = %#02x\n", __func__, data[1], data[2]); if (data[1] != 0xa || data[2] < 0x9) input_dev->open = cypress_touchkey_open; err = input_register_device(input_dev); if (err) goto err_input_reg_dev; set_device_params(devdata, data); err = i2c_touchkey_write_byte(devdata, devdata->backlight_on); if (err) { dev_err(dev, "%s: touch keypad backlight on failed\n", __func__); /* The device may not be responding because of bad firmware * Allow the firmware to be reflashed if it needs to be */ if (!input_dev->open) goto err_backlight_on; } err = request_threaded_irq(client->irq, touchkey_interrupt_handler, touchkey_interrupt_thread, IRQF_TRIGGER_FALLING, DEVICE_NAME, devdata); if (err) { dev_err(dev, "%s: Can't allocate irq.\n", __func__); goto err_req_irq; } #ifdef CONFIG_HAS_EARLYSUSPEND devdata->early_suspend.suspend = cypress_touchkey_early_suspend; devdata->early_suspend.resume = cypress_touchkey_early_resume; #endif register_early_suspend(&devdata->early_suspend); devdata->is_powering_on = false; #ifdef CONFIG_GENERIC_BLN blndevdata = devdata; register_bln_implementation(&cypress_touchkey_bln); #endif #ifdef CONFIG_BLD blddevdata = devdata; register_bld_implementation(&cypress_touchkey_bld); #endif #ifdef CONFIG_TOUCH_WAKE touchwakedevdata = devdata; register_touchwake_implementation(&cypress_touchwake); #endif return 0; err_req_irq: err_backlight_on: input_unregister_device(input_dev); goto touchkey_off; err_input_reg_dev: err_read: input_free_device(input_dev); touchkey_off: devdata->pdata->touchkey_onoff(TOUCHKEY_OFF); err_input_alloc_dev: err_null_keycodes: kfree(devdata); return err; }
/* [function]: read out data from ctpm,the destination address is 0. [parameters]: pbt_buf[out] :point to data buffer; bt_len[in] :the data numbers; [return]: FTS_TRUE :success; FTS_FALSE :io fail; */ FTS_BOOL byte_read(struct i2c_client *client,FTS_BYTE* pbt_buf, FTS_BYTE bt_len) { return i2c_master_recv(client, pbt_buf, bt_len); }
static ssize_t pn544_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { /*use global var instead of container_of funcation*/ struct pn544_info *info = pn544_info; /*unused var variable 'len'*/ int ret = -1; int i = 0; char tmp[PN544_MAX_PACK_LEN]; PN544_DEBUG("%s:entered\n",__func__); if (count > PN544_MAX_PACK_LEN) count = PN544_MAX_PACK_LEN; PN544_DEBUG("%s : reading %zu bytes.\n", __func__, count); //mutex_lock(&info->mutex); /*if gpio value is high we should enable irq*/ PN544_DEBUG("%s:GPIO_NFC_INT value %d\n", __func__, gpio_get_value(GPIO_NFC_INT)); if(!gpio_get_value(GPIO_NFC_INT)) { PN544_DEBUG("%s:enable pn544irq !\n", __func__); pn544_info->irq_enabled = true; enable_irq(pn544_info->i2c_dev ->irq); ret = wait_event_interruptible(pn544_info->read_wait, gpio_get_value(GPIO_NFC_INT)); pn544_disable_irq(pn544_info); PN544_DEBUG("%s:enable pn544irq! ret=%d!\n", __func__, ret); if (ret) { goto out; } } if (update) { PN544_DEBUG("updateing****!\n"); } /* Read data */ ret = i2c_master_recv(info->i2c_dev, tmp, count); PN544_DEBUG("%s:read datasize: ret=%d count=%d\n", __func__, ret, count); //mutex_unlock(&info->mutex); if (ret < 0) { printk("%s: receive error! i2c_master_recv returned %d\n", __func__, ret); return ret; } if (ret > count) { printk("%s: received too many bytes from i2c (%d)\n", __func__, ret); return -EIO; } PN544_DEBUG("IFD->PC: "); for(i = 0; i < count; i++) { PN544_DEBUG("%02X", tmp[i]); } PN544_DEBUG("\n"); if (copy_to_user(buf, tmp, ret)) { printk("%s : failed to copy to user space\n", __func__); return -EFAULT; } PN544_DEBUG("%s:exit ret=%d\n",__func__,ret); return ret; out: //mutex_unlock(&info->mutex); return ret; }
static int bh1721_read_value(struct i2c_client *client, char *buf) { return i2c_master_recv(client, buf, NUM_OF_BYTES_READ); }
static ssize_t pn547_dev_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct pn547_dev *pn547_dev = filp->private_data; char tmp[MAX_BUFFER_SIZE]; int ret = 0; if (count > MAX_BUFFER_SIZE) { count = MAX_BUFFER_SIZE; } else if (count == 0) { dev_info(&pn547_dev->client->dev, "pn547 : read 0bytes\n"); return ret; } #if NFC_DEBUG dev_info(&pn547_dev->client->dev, "%s : reading %zu bytes. irq=%s\n", __func__, count, gpio_get_value(pn547_dev->irq_gpio) ? "1" : "0"); dev_info(&pn547_dev->client->dev, "pn547 : + r\n"); #endif mutex_lock(&pn547_dev->read_mutex); if (!gpio_get_value(pn547_dev->irq_gpio)) { #ifdef NXP_KR_READ_IRQ_MODIFY do_reading = false; #endif if (filp->f_flags & O_NONBLOCK) { dev_info(&pn547_dev->client->dev, "%s : O_NONBLOCK\n", __func__); ret = -EAGAIN; goto fail; } #if NFC_DEBUG dev_info(&pn547_dev->client->dev, "wait_event_interruptible : in\n"); #endif #ifdef NXP_KR_READ_IRQ_MODIFY ret = wait_event_interruptible(pn547_dev->read_wq, do_reading); #else ret = wait_event_interruptible(pn547_dev->read_wq, gpio_get_value(pn547_dev->irq_gpio)); #endif #if NFC_DEBUG dev_info(&pn547_dev->client->dev, "wait_event_interruptible : out\n"); #endif #ifdef NXP_KR_READ_IRQ_MODIFY if (cancle_read == true) { cancle_read = false; ret = -1; goto fail; } #endif if (ret) goto fail; } /* Read data */ ret = i2c_master_recv(pn547_dev->client, tmp, count); mutex_unlock(&pn547_dev->read_mutex); if (ret < 0) { dev_err(&pn547_dev->client->dev, "%s: i2c_master_recv returned %d\n", __func__, ret); return ret; } if (ret > count) { dev_err(&pn547_dev->client->dev, "%s: received too many bytes from i2c (%d)\n", __func__, ret); return -EIO; } if (copy_to_user(buf, tmp, ret)) { dev_err(&pn547_dev->client->dev, "%s : failed to copy to user space\n", __func__); return -EFAULT; } return ret; fail: mutex_unlock(&pn547_dev->read_mutex); return ret; }
static int irda_fw_update(struct ir_remocon_data *ir_data) { struct ir_remocon_data *data = ir_data; struct i2c_client *client = data->client; int i, k, ret, ret2, checksum, checksum2; u8 buf_ir_test[8]; data->pdata->ir_vdd_onoff(&client->dev, 0); data->pdata->ir_wake_en(data->pdata, 0); msleep(100); data->pdata->ir_vdd_onoff(&client->dev, 1); data->pdata->ir_wake_en(data->pdata,1); gpio_tlmm_config(GPIO_CFG(data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE); msleep(70); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) { printk(KERN_ERR "%s: err %d\n", __func__, ret); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) { printk(KERN_INFO "%s: broken FW!\n", __func__); retry_count = 1; } } #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif ret = buf_ir_test[2] << 8 | buf_ir_test[3]; if (ret == 0x101) { data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(&client->dev,0); data->on_off = 0; msleep(100); download_pass = 1; return 0; } if ((ret != FW_VERSION) || (retry_count != 0)) { printk(KERN_INFO "2. %s: chip : %04x, bin : %04x, need update!\n", __func__, ret, FW_VERSION); data->pdata->ir_vdd_onoff(&client->dev, 0); data->pdata->ir_wake_en(data->pdata, 0); msleep(100); data->pdata->ir_vdd_onoff(&client->dev,1); msleep(70); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) printk(KERN_ERR " %s: err %d\n", __func__, ret); #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif ret = buf_ir_test[6] << 8 | buf_ir_test[7]; checksum = 0; for (k = 0; k < 6; k++) checksum += buf_ir_test[k]; if (ret == checksum) printk(KERN_INFO "%s: boot mode, FW download start! ret=%04x\n", __func__, ret); else { printk(KERN_ERR "ABOV IC bootcode broken\n"); goto err_bootmode; } msleep(30); for (i = 0; i < FRAME_COUNT; i++) { if (i == FRAME_COUNT-1) { ret = i2c_master_send(client, &IRDA_binary[i * 70], 6); if (ret < 0) goto err_update; } else { ret = i2c_master_send(client, &IRDA_binary[i * 70], 70); if (ret < 0) goto err_update; } msleep(30); } ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) printk(KERN_ERR "5. %s: err %d\n", __func__, ret); #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif ret = buf_ir_test[6] << 8 | buf_ir_test[7]; checksum = 0; for (k = 0; k < 6; k++) checksum += buf_ir_test[k]; msleep(20); ret2 = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret2 < 0) printk(KERN_ERR "6. %s: err %d\n", __func__, ret2); ret2 = buf_ir_test[6] << 8 | buf_ir_test[7]; for (k = 0; k < 6; k++) checksum2 += buf_ir_test[k]; if (ret == checksum) { printk(KERN_INFO "1. %s: boot down complete\n", __func__); download_pass = 1; } else if (ret2 == checksum2) { printk(KERN_INFO "2. %s: boot down complete\n", __func__); download_pass = 1; } else { retry_count++; printk(KERN_ERR "FW Checksum fail. Retry = %d\n", retry_count); goto err_bootmode; } data->pdata->ir_vdd_onoff(&client->dev, 0); msleep(100); data->pdata->ir_vdd_onoff(&client->dev, 1); data->pdata->ir_wake_en(data->pdata, 1); msleep(70); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); ret = buf_ir_test[2] << 8 | buf_ir_test[3]; printk(KERN_INFO "7. %s: user mode : Upgrade FW_version : %04x\n", __func__, ret); #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(&client->dev,0); data->on_off = 0; } else { if (ret != DUMMY) printk(KERN_INFO "8. %s: chip : %04x, bin : %04x, latest FW_ver\n", __func__, ret, FW_VERSION); data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(&client->dev,0); data->on_off = 0; msleep(100); if (ret == FW_VERSION) download_pass = 1; } return 0; err_update: printk(KERN_ERR "%s: update fail! count : %x, ret = %x\n", __func__, i, ret); return ret; err_bootmode: printk(KERN_ERR "%s: update fail, checksum = %x ret = %x\n", __func__, checksum, ret); data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(&client->dev,0); data->on_off = 0; return ret; }
static int saa6752hs_chip_command(struct i2c_client* client, enum saa6752hs_command command) { unsigned char buf[3]; unsigned long timeout; int status = 0; // execute the command switch(command) { case SAA6752HS_COMMAND_RESET: buf[0] = 0x00; break; case SAA6752HS_COMMAND_STOP: buf[0] = 0x03; break; case SAA6752HS_COMMAND_START: buf[0] = 0x02; break; case SAA6752HS_COMMAND_PAUSE: buf[0] = 0x04; break; case SAA6752HS_COMMAND_RECONFIGURE: buf[0] = 0x05; break; case SAA6752HS_COMMAND_SLEEP: buf[0] = 0x06; break; case SAA6752HS_COMMAND_RECONFIGURE_FORCE: buf[0] = 0x07; break; default: return -EINVAL; } // set it and wait for it to be so i2c_master_send(client, buf, 1); timeout = jiffies + HZ * 3; for (;;) { // get the current status buf[0] = 0x10; i2c_master_send(client, buf, 1); i2c_master_recv(client, buf, 1); if (!(buf[0] & 0x20)) break; if (time_after(jiffies,timeout)) { status = -ETIMEDOUT; break; } // wait a bit set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ/100); } // delay a bit to let encoder settle set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ/20); // done return status; }
int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 andmask, u8 ormask) { u8 regandval[2] = {reg, 0}; int err; err = mutex_lock_interruptible(&ab3100->access_mutex); if (err) return err; /* First read out the target register */ err = i2c_master_send(ab3100->i2c_client, ®, 1); if (err < 0) { dev_err(ab3100->dev, "write error (maskset send address): %d\n", err); goto get_maskset_unlock; } else if (err != 1) { dev_err(ab3100->dev, "write error (maskset send address) " "%d bytes transferred (expected 1)\n", err); err = -EIO; goto get_maskset_unlock; } err = i2c_master_recv(ab3100->i2c_client, ®andval[1], 1); if (err < 0) { dev_err(ab3100->dev, "write error (maskset read register): %d\n", err); goto get_maskset_unlock; } else if (err != 1) { dev_err(ab3100->dev, "write error (maskset read register) " "%d bytes transferred (expected 1)\n", err); err = -EIO; goto get_maskset_unlock; } /* Modify the register */ regandval[1] &= andmask; regandval[1] |= ormask; /* Write the register */ err = i2c_master_send(ab3100->i2c_client, regandval, 2); if (err < 0) { dev_err(ab3100->dev, "write error (write register): %d\n", err); goto get_maskset_unlock; } else if (err != 2) { dev_err(ab3100->dev, "write error (write register) " "%d bytes transferred (expected 2)\n", err); err = -EIO; goto get_maskset_unlock; } /* All is well */ err = 0; get_maskset_unlock: mutex_unlock(&ab3100->access_mutex); return err; }
static int max1363_read_single_chan(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, long m) { int ret = 0; s32 data; char rxbuf[2]; long mask; struct max1363_state *st = iio_priv(indio_dev); struct i2c_client *client = st->client; mutex_lock(&indio_dev->mlock); /* * If monitor mode is enabled, the method for reading a single * channel will have to be rather different and has not yet * been implemented. */ if (st->monitor_on) { ret = -EBUSY; goto error_ret; } /* If ring buffer capture is occurring, query the buffer */ if (iio_ring_enabled(indio_dev)) { mask = max1363_mode_table[chan->address].modemask; data = max1363_single_channel_from_ring(mask, st); if (data < 0) { ret = data; goto error_ret; } } else { /* Check to see if current scan mode is correct */ if (st->current_mode != &max1363_mode_table[chan->address]) { /* Update scan mode if needed */ st->current_mode = &max1363_mode_table[chan->address]; ret = max1363_set_scan_mode(st); if (ret < 0) goto error_ret; } if (st->chip_info->bits != 8) { /* Get reading */ data = i2c_master_recv(client, rxbuf, 2); if (data < 0) { ret = data; goto error_ret; } data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; } else { /* Get reading */ data = i2c_master_recv(client, rxbuf, 1); if (data < 0) { ret = data; goto error_ret; } data = rxbuf[0]; } } *val = data; error_ret: mutex_unlock(&indio_dev->mlock); return ret; }
static int irda_fw_update(struct ir_remocon_data *ir_data) { struct ir_remocon_data *data = ir_data; struct i2c_client *client = data->client; int i, k, ret, ret2, checksum, checksum2; u8 buf_ir_test[8]; msleep(20); data->pdata->ir_vdd_onoff(0); msleep(20); data->pdata->ir_vdd_onoff(1); data->pdata->ir_wake_en(data->pdata,1); msleep(100); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) { printk(KERN_ERR "%s: err %d\n", __func__, ret); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) { printk(KERN_INFO "%s: broken FW!\n", __func__); retry_count = 1; } } ret = buf_ir_test[2] << 8 | buf_ir_test[3]; if ((ret != FW_VERSION) || (retry_count != 0)) { printk(KERN_INFO "2. %s: chip : %04x, bin : %04x, need update!\n", __func__, ret, FW_VERSION); data->pdata->ir_vdd_onoff(0); data->pdata->ir_wake_en(data->pdata,0); msleep(20); data->pdata->ir_vdd_onoff(1); msleep(100); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) printk(KERN_ERR "3. %s: err %d\n", __func__, ret); ret = buf_ir_test[6] << 8 | buf_ir_test[7]; checksum = 0; for (k = 0; k < 6; k++) checksum += buf_ir_test[k]; if (ret == checksum) printk(KERN_INFO "%s: boot mode, FW download start! ret=%04x\n", __func__, ret); else { printk(KERN_ERR "ABOV IC bootcode broken\n"); goto err_bootmode; } msleep(30); for (i = 0; i < FRAME_COUNT; i++) { if (i == FRAME_COUNT-1) { ret = i2c_master_send(client, &IRDA_binary[i * 70], 6); if (ret < 0) goto err_update; } else { ret = i2c_master_send(client, &IRDA_binary[i * 70], 70); if (ret < 0) goto err_update; } msleep(30); } ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) printk(KERN_ERR "5. %s: err %d\n", __func__, ret); ret = buf_ir_test[6] << 8 | buf_ir_test[7]; checksum = 0; for (k = 0; k < 6; k++) checksum += buf_ir_test[k]; msleep(20); ret2 = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret2 < 0) printk(KERN_ERR "6. %s: err %d\n", __func__, ret2); ret2 = buf_ir_test[6] << 8 | buf_ir_test[7]; for (k = 0; k < 6; k++) checksum2 += buf_ir_test[k]; if (ret == checksum) { printk(KERN_INFO "1. %s: boot down complete\n", __func__); download_pass = 1; } else if (ret2 == checksum2) { printk(KERN_INFO "2. %s: boot down complete\n", __func__); download_pass = 1; } else { retry_count++; printk(KERN_ERR "FW Checksum fail. Retry = %d\n", retry_count); goto err_bootmode; } data->pdata->ir_vdd_onoff(0); msleep(20); data->pdata->ir_vdd_onoff(1); data->pdata->ir_wake_en(data->pdata,1); msleep(60); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); ret = buf_ir_test[2] << 8 | buf_ir_test[3]; printk(KERN_INFO "7. %s: user mode : Upgrade FW_version : %04x\n", __func__, ret); data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(0); data->on_off = 0; msleep(100); } else { if (ret != DUMMY) printk(KERN_INFO "8. %s: chip : %04x, bin : %04x, latest FW_ver\n", __func__, ret, FW_VERSION); data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(0); data->on_off = 0; msleep(100); if (ret == FW_VERSION) download_pass = 1; } return 0; err_update: printk(KERN_ERR "%s: update fail! count : %x, ret = %x\n", __func__, i, ret); return ret; err_bootmode: printk(KERN_ERR "%s: update fail, checksum = %x ret = %x\n", __func__, checksum, ret); data->pdata->ir_wake_en(data->pdata,0); data->pdata->ir_vdd_onoff(0); data->on_off = 0; return ret; }
static int irda_fw_update(struct ir_remocon_data *ir_data) { struct ir_remocon_data *data = ir_data; struct i2c_client *client = data->client; int i, k, ret, ret2, checksum, checksum2, frame_count; u8 buf_ir_test[8]; const u8 *IRDA_fw; ret = 0; ret = irda_vdd_onoff(0); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->pdata->ir_wake_en(data->pdata, 0); msleep(100); ret = irda_vdd_onoff(1); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->pdata->ir_wake_en(data->pdata,1); gpio_tlmm_config(GPIO_CFG(data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE); msleep(70); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) { pr_err("%s: err %d\n", __func__, ret); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) { pr_info("%s: broken FW!\n", __func__); goto err_bootmode; } } #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif ret = buf_ir_test[2] << 8 | buf_ir_test[3]; if (ret == MC96FR116C_0x103) { data->pdata->ir_wake_en(data->pdata,0); ret = irda_vdd_onoff(0); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->on_off = 0; msleep(100); download_pass = 1; return 0; } else if (ret == MC96FR116C_0x101) { IRDA_fw = IRDA_binary_103; frame_count = FRAME_COUNT_103; pr_err("%s: chip : %04x, bin : %04x, need update!\n", __func__, ret, MC96FR116C_0x103); } else goto err_bootmode; pr_err("irda frame count = %d\n", frame_count); ret = irda_vdd_onoff(0); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->pdata->ir_wake_en(data->pdata, 0); msleep(100); ret = irda_vdd_onoff(1); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } msleep(70); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) pr_err(KERN_ERR " %s: err %d\n", __func__, ret); #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif ret = buf_ir_test[6] << 8 | buf_ir_test[7]; checksum = 0; for (k = 0; k < 6; k++) checksum += buf_ir_test[k]; if (ret == checksum) pr_info("%s: boot mode, FW download start! ret=%04x\n", __func__, ret); else { pr_err("ABOV IC bootcode broken\n"); goto err_bootmode; } msleep(30); for (i = 0; i < frame_count; i++) { if (i == frame_count-1) { ret = i2c_master_send(client, &IRDA_fw[i * 70], 6); if (ret < 0) goto err_update; } else { ret = i2c_master_send(client, &IRDA_fw[i * 70], 70); if (ret < 0) goto err_update; } msleep(30); } ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret < 0) pr_err("5. %s: err %d\n", __func__, ret); #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif ret = buf_ir_test[6] << 8 | buf_ir_test[7]; checksum = 0; for (k = 0; k < 6; k++) checksum += buf_ir_test[k]; msleep(20); ret2 = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); if (ret2 < 0) pr_err("6. %s: err %d\n", __func__, ret2); ret2 = buf_ir_test[6] << 8 | buf_ir_test[7]; for (k = 0; k < 6; k++) checksum2 += buf_ir_test[k]; if (ret == checksum) { pr_info("1. %s: boot down complete\n", __func__); download_pass = 1; } else if (ret2 == checksum2) { pr_info("2. %s: boot down complete\n", __func__); download_pass = 1; } else { pr_err("FW Checksum fail\n"); goto err_bootmode; } ret = irda_vdd_onoff(0); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } msleep(100); ret = irda_vdd_onoff(1); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->pdata->ir_wake_en(data->pdata, 1); msleep(70); ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH); ret = buf_ir_test[2] << 8 | buf_ir_test[3]; pr_info("7. %s: user mode : Upgrade FW_version : %04x\n", __func__, ret); #ifdef DEBUG print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1, DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1); #endif data->pdata->ir_wake_en(data->pdata,0); ret = irda_vdd_onoff(0); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->on_off = 0; if (ret == MC96FR116C_0x103) download_pass = 1; return 0; err_update: pr_err("%s: update fail! count : %x, ret = %x\n", __func__, i, ret); return ret; err_bootmode: pr_err("%s: update fail, checksum = %x ret = %x\n", __func__, checksum, ret); data->pdata->ir_wake_en(data->pdata,0); ret = irda_vdd_onoff(0); if (ret) { pr_err("%s Regulator setting failed\n", __func__); goto err_regulator; } data->on_off = 0; err_regulator: return ret; }
static int synaptics_ts_probe( struct i2c_client *client, const struct i2c_device_id *id) { struct synaptics_ts_data *ts; uint8_t i2c_addr = 0x1B; uint8_t buf[3], buf_tmp[3]={0,0,0}; uint8_t addr[1]; int i, ret; #if defined (CONFIG_TOUCHSCREEN_MMS128_TASSCOOPER) printk("[TSP][Synaptics][%s] %s\n", __func__,"Called"); if(Is_MMS128_Connected()== 1) { printk("[TSP][Synaptics][%s] %s\n", __func__,"Melfas already detected !!"); return -ENXIO; } #endif printk("[TSP] %s, %d\n", __func__, __LINE__ ); touch_ctrl_regulator(TOUCH_ON); msleep(100); touch_ctrl_regulator(TOUCH_OFF); msleep(200); touch_ctrl_regulator(TOUCH_ON); msleep(100); ts = kzalloc(sizeof(*ts), GFP_KERNEL); if (ts == NULL) { ret = -ENOMEM; goto err_alloc_data_failed; } #if USE_THREADED_IRQ #else INIT_WORK(&ts->work, synaptics_ts_work_func); #endif ts->client = client; i2c_set_clientdata(client, ts); ts_global = ts; tsp_irq=client->irq; #if defined (CONFIG_TOUCHSCREEN_MMS128_TASSCOOPER) ret = synaptics_ts_check(); if (ret <= 0) { i2c_release_client(client); touch_ctrl_regulator(TOUCH_OFF); ret = -ENXIO; goto err_input_dev_alloc_failed; } #else /* Check point - i2c check - start */ //ret = tsp_i2c_read( 0x1B, buf_tmp, sizeof(buf_tmp)); for (i = 0; i < 1; i++) { printk("[TSP] %s, %d, send\n", __func__, __LINE__ ); addr[0] = 0x1B; //address ret = i2c_master_send(ts_global->client, addr, 1); if (ret >= 0) { printk("[TSP] %s, %d, receive\n", __func__, __LINE__ ); ret = i2c_master_recv(ts_global->client, buf_tmp, 3); if (ret >= 0) break; // i2c success } printk("[TSP] %s, %d, fail\n", __func__, __LINE__ ); } touch_vendor_id = buf_tmp[0]; touch_hw_ver = buf_tmp[1]; touch_sw_ver = buf_tmp[2]; printk("[TSP] %s:%d, ver tsp=%x, HW=%x, SW=%x\n", __func__,__LINE__, touch_vendor_id, touch_hw_ver, touch_sw_ver); #endif HW_ver = touch_hw_ver; if (ret <= 0) { printk("[TSP] %s, ln:%d, Failed to register TSP!!!\n\tcheck the i2c line!!!, ret=%d\n", __func__,__LINE__, ret); goto err_check_functionality_failed; } /* Check point - i2c check - end */ ts->input_dev = input_allocate_device(); if (ts->input_dev == NULL) { ret = -ENOMEM; printk(KERN_ERR "synaptics_ts_probe: Failed to allocate input device\n"); goto err_input_dev_alloc_failed; } ts->input_dev->name = "synaptics-rmi-touchscreen"; ts->input_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); ts->input_dev->keybit[BIT_WORD(KEY_POWER)] |= BIT_MASK(KEY_POWER); set_bit(BTN_TOUCH, ts->input_dev->keybit); set_bit(EV_ABS, ts->input_dev->evbit); ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, MAX_X, 0, 0); input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, MAX_Y, 0, 0); input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); set_bit(EV_SYN, ts->input_dev->evbit); set_bit(EV_KEY, ts->input_dev->evbit); /* ts->input_dev->name = ts->keypad_info->name; */ ret = input_register_device(ts->input_dev); if (ret) { printk(KERN_ERR "synaptics_ts_probe: Unable to register %s input device\n", ts->input_dev->name); goto err_input_register_device_failed; } printk("[TSP] %s, irq=%d\n", __func__, client->irq ); if (client->irq) { #if USE_THREADED_IRQ ret = request_threaded_irq(client->irq, synaptics_ts_irq_handler, synaptics_ts_work_func, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, client->name, ts); #else ret = request_irq(client->irq, synaptics_ts_irq_handler, IRQF_TRIGGER_FALLING, client->name, ts); #endif if (ret == 0) ts->use_irq = 1; else dev_err(&client->dev, "request_irq failed\n"); } if (!ts->use_irq) { hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); ts->timer.function = synaptics_ts_timer_func; hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL); } #if 1 #ifdef CONFIG_HAS_EARLYSUSPEND ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; ts->early_suspend.suspend = synaptics_ts_early_suspend; ts->early_suspend.resume = synaptics_ts_late_resume; register_early_suspend(&ts->early_suspend); #endif #endif printk(KERN_INFO "synaptics_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name, ts->use_irq ? "interrupt" : "polling"); /* sys fs */ touch_class = class_create(THIS_MODULE, "touch"); if (IS_ERR(touch_class)) pr_err("Failed to create class(touch)!\n"); firmware_dev = device_create(touch_class, NULL, 0, NULL, "firmware"); if (IS_ERR(firmware_dev)) pr_err("Failed to create device(firmware)!\n"); if (device_create_file(firmware_dev, &dev_attr_firmware) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_firmware.attr.name); if (device_create_file(firmware_dev, &dev_attr_firmware_ret) < 0) pr_err("Failed to create device file(%s)!\n", dev_attr_firmware_ret.attr.name); /* sys fs */ #if 0 if(buf_tmp[0]<HEX_HW_VER){ //Firmware Update firm_update(); }else if((buf_tmp[1]<HEX_SW_VER)||((buf_tmp[1]&0xF0)==0xF0)||(buf_tmp[1]==0)){ printk("[TSP] firm_update START!!, ln=%d\n",__LINE__); firm_update(); }else{ printk("[TSP] Firmware Version is Up-to-date.\n"); } #endif return 0; err_input_register_device_failed: input_free_device(ts->input_dev); err_input_dev_alloc_failed: kfree(ts); err_alloc_data_failed: err_check_functionality_failed: return ret; }
static ssize_t pn547_dev_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { struct pn547_dev *pn547_dev = filp->private_data; char tmp[MAX_BUFFER_SIZE] = {0, }; int ret = 0; #ifdef CONFIG_NFC_PN544 int readingWatchdog = 0; #endif if (count > MAX_BUFFER_SIZE) count = MAX_BUFFER_SIZE; pr_debug("%s : reading %zu bytes. irq=%s\n", __func__, count, gpio_get_value(pn547_dev->irq_gpio) ? "1" : "0"); #if NFC_DEBUG pr_info("pn547 : + r\n"); #endif mutex_lock(&pn547_dev->read_mutex); #ifdef CONFIG_NFC_PN544 wait_irq: #endif if (!gpio_get_value(pn547_dev->irq_gpio)) { atomic_set(&pn547_dev->read_flag, 0); if (filp->f_flags & O_NONBLOCK) { pr_info("%s : O_NONBLOCK\n", __func__); ret = -EAGAIN; goto fail; } #if NFC_DEBUG pr_info("pn547: wait_event_interruptible : in\n"); #endif if (!gpio_get_value(pn547_dev->irq_gpio)) ret = wait_event_interruptible(pn547_dev->read_wq, atomic_read(&pn547_dev->read_flag)); #if NFC_DEBUG pr_info("pn547 : h\n"); #endif if (pn547_dev->cancel_read) { pn547_dev->cancel_read = false; ret = -1; goto fail; } if (ret) goto fail; } /* Read data */ ret = i2c_master_recv(pn547_dev->client, tmp, count); #ifdef CONFIG_NFC_PN544 /* If bad frame(from 0x51 to 0x57) is received from pn65n, * we need to read again after waiting that IRQ is down. * if data is not ready, pn65n will send from 0x51 to 0x57. */ if ((I2C_ADDR_READ_L <= tmp[0] && tmp[0] <= I2C_ADDR_READ_H) && readingWatchdog < MAX_TRY_I2C_READ) { pr_warn("%s: data is not ready yet.data = 0x%x, cnt=%d\n", __func__, tmp[0], readingWatchdog); usleep_range(2000, 2000); /* sleep 2ms to wait for IRQ */ readingWatchdog++; goto wait_irq; } #endif #if NFC_DEBUG pr_info("pn547: i2c_master_recv\n"); #endif mutex_unlock(&pn547_dev->read_mutex); if (ret < 0) { pr_err("%s: i2c_master_recv returned %d\n", __func__, ret); #ifdef CONFIG_SEC_K_PROJECT pn547_i2c_recovery(pn547_dev); #endif return ret; } if (ret > count) { pr_err("%s: received too many bytes from i2c (%d)\n", __func__, ret); return -EIO; } if (copy_to_user(buf, tmp, ret)) { pr_err("%s : failed to copy to user space\n", __func__); return -EFAULT; } return ret; fail: mutex_unlock(&pn547_dev->read_mutex); return ret; }
static int cypress_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct input_dev *input_dev; struct cypress_touchkey_devdata *devdata; u8 data[3]; int err; int cnt; #if defined(TOUCH_UPDATE) int ret; int retry = 10; #endif if (!dev->platform_data) { dev_err(dev, "%s: Platform data is NULL\n", __func__); return -EINVAL; } devdata = kzalloc(sizeof(*devdata), GFP_KERNEL); if (devdata == NULL) { dev_err(dev, "%s: failed to create our state\n", __func__); return -ENODEV; } devdata->client = client; i2c_set_clientdata(client, devdata); devdata->pdata = client->dev.platform_data; if (!devdata->pdata->keycode) { dev_err(dev, "%s: Invalid platform data\n", __func__); err = -EINVAL; goto err_null_keycodes; } strlcpy(devdata->client->name, DEVICE_NAME, I2C_NAME_SIZE); input_dev = input_allocate_device(); if (!input_dev) { err = -ENOMEM; goto err_input_alloc_dev; } devdata->input_dev = input_dev; dev_set_drvdata(&input_dev->dev, devdata); input_dev->name = DEVICE_NAME; input_dev->id.bustype = BUS_HOST; for (cnt = 0; cnt < devdata->pdata->keycode_cnt; cnt++) input_set_capability(input_dev, EV_KEY, devdata->pdata->keycode[cnt]); err = input_register_device(input_dev); if (err) goto err_input_reg_dev; devdata->is_powering_on = true; devdata->pdata->touchkey_onoff(TOUCHKEY_ON); err = i2c_master_recv(client, data, sizeof(data)); if (err < sizeof(data)) { if (err >= 0) err = -EIO; dev_err(dev, "%s: error reading hardware version\n", __func__); goto err_read; } dev_info(dev, "%s: hardware rev1 = %#02x, rev2 = %#02x\n", __func__, data[1], data[2]); devdata->backlight_on = BACKLIGHT_ON; devdata->backlight_off = BACKLIGHT_OFF; devdata->has_legacy_keycode = 1; #if 0 err = i2c_touchkey_write_byte(devdata, devdata->backlight_on); if (err) { dev_err(dev, "%s: touch keypad backlight on failed\n", __func__); goto err_backlight_on; } #endif if (request_threaded_irq(client->irq, touchkey_interrupt_handler, touchkey_interrupt_thread, IRQF_TRIGGER_FALLING, DEVICE_NAME, devdata)) { dev_err(dev, "%s: Can't allocate irq.\n", __func__); goto err_req_irq; } #ifdef CONFIG_HAS_EARLYSUSPEND devdata->early_suspend.suspend = cypress_touchkey_early_suspend; devdata->early_suspend.resume = cypress_touchkey_early_resume; #endif register_early_suspend(&devdata->early_suspend); devdata->is_powering_on = false; #if defined(TOUCH_UPDATE) ret = misc_register(&touchkey_update_device); if (ret) { printk("%s misc_register fail\n", __FUNCTION__); goto err_misc_reg; } dev_set_drvdata(touchkey_update_device.this_device, devdata); if (device_create_file (touchkey_update_device.this_device, &dev_attr_touch_version) < 0) { printk("%s device_create_file fail dev_attr_touch_version\n", __FUNCTION__); pr_err("Failed to create device file(%s)!\n", dev_attr_touch_version.attr.name); } if (device_create_file (touchkey_update_device.this_device, &dev_attr_touch_update) < 0) { printk("%s device_create_file fail dev_attr_touch_update\n", __FUNCTION__); pr_err("Failed to create device file(%s)!\n", dev_attr_touch_update.attr.name); } if (device_create_file (touchkey_update_device.this_device, &dev_attr_brightness) < 0) { printk("%s device_create_file fail dev_attr_touch_update\n", __FUNCTION__); pr_err("Failed to create device file(%s)!\n", dev_attr_brightness.attr.name); } if (device_create_file (touchkey_update_device.this_device, &dev_attr_enable_disable) < 0) { printk("%s device_create_file fail dev_attr_touch_update\n", __FUNCTION__); pr_err("Failed to create device file(%s)!\n", dev_attr_enable_disable.attr.name); } touchkey_wq = create_singlethread_workqueue(DEVICE_NAME); if (!touchkey_wq) goto err_create_wq; while (retry--) { if (get_touchkey_firmware(data) == 0) //melfas need delay for multiple read break; } printk("%s F/W version: 0x%x, Module version:0x%x\n", __FUNCTION__, data[1], data[2]); #endif #ifdef CONFIG_KEYPAD_CYPRESS_TOUCH_BLN pr_info("%s misc_register(%s)\n", __FUNCTION__, backlightnotification_device.name); err = misc_register(&backlightnotification_device); if (err) { pr_err("%s misc_register(%s) fail\n", __FUNCTION__, backlightnotification_device.name); }else { /* * keep a reference to the devdata, * misc driver does not give access to it (or i missed that somewhere) */ bln_devdata = devdata; /* add the backlightnotification attributes */ if (sysfs_create_group(&backlightnotification_device.this_device->kobj, &bln_interface_attributes_group) < 0) { pr_err("%s sysfs_create_group fail\n", __FUNCTION__); pr_err("Failed to create sysfs group for device (%s)!\n", backlightnotification_device.name); } } #endif setup_timer(&bl_timer, bl_timer_callback, 0); return 0; err_create_wq: #if defined(TOUCH_UPDATE) misc_deregister(&touchkey_update_device); #endif err_misc_reg: err_req_irq: err_backlight_on: err_read: devdata->pdata->touchkey_onoff(TOUCHKEY_OFF); input_unregister_device(input_dev); goto err_input_alloc_dev; err_input_reg_dev: input_free_device(input_dev); err_input_alloc_dev: err_null_keycodes: kfree(devdata); return err; }
Something is messed up #endif #endif #endif void main(void) { //Tmp Code unsigned char ADCbufferI2C[8]; unsigned char ADCBufferLen; char c; signed char length; unsigned char msgtype; unsigned char last_reg_recvd; uart_comm uc; // i2c_comm ic; unsigned char msgbuffer[MSGLEN + 1]; unsigned char i; uart_thread_struct uthread_data; // info for uart_lthread timer1_thread_struct t1thread_data; // info for timer1_lthread timer0_thread_struct t0thread_data; // info for timer0_lthread #ifdef __USE18F2680 OSCCON = 0xFC; // see datasheet // We have enough room below the Max Freq to enable the PLL for this chip OSCTUNEbits.PLLEN = 1; // 4x the clock speed in the previous line #else #ifdef __USE18F45J10 OSCCON = 0x82; // see datasheeet OSCTUNEbits.PLLEN = 0; // Makes the clock exceed the PIC's rated speed if the PLL is on #else #ifdef __USE18F26J50 OSCCON = 0xE0; // see datasheeet OSCTUNEbits.PLLEN = 1; #else Something is wrong #endif #endif #endif // initialize my uart recv handling code init_uart_snd_rcv(&uc); // initialize the i2c code // init_i2c(&ic); // init the timer1 lthread init_timer1_lthread(&t1thread_data); // initialize message queues before enabling any interrupts init_queues(); // set direction for PORTA to output TRISA = 0x00; LATA = 0x00; // how to set up PORTA for input (for the V4 board with the PIC2680) /* PORTA = 0x0; // clear the port LATA = 0x0; // clear the output latch ADCON1 = 0x0F; // turn off the A2D function on these pins // Only for 40-pin version of this chip CMCON = 0x07; // turn the comparator off TRISA = 0x0F; // set RA3-RA0 to inputs */ // initialize Timers OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_128); #ifdef __USE18F26J50 // MTJ added second argument for OpenTimer1() OpenTimer1(TIMER_INT_ON & T1_SOURCE_FOSC_4 & T1_PS_1_4 & T1_16BIT_RW & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF,0x0); #else OpenTimer1(TIMER_INT_ON & T1_PS_1_8 & T1_16BIT_RW & T1_SOURCE_INT & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF); #endif // Decide on the priority of the enabled peripheral interrupts // 0 is low, 1 is high // Timer1 interrupt IPR1bits.TMR1IP = 0; // USART RX interrupt IPR1bits.RCIP = 0; // I2C interrupt IPR1bits.SSPIP = 1; // configure the hardware i2c device as a slave (0x9E -> 0x4F) or (0x9A -> 0x4D) #if 1 // Note that the temperature sensor Address bits (A0, A1, A2) are also the // least significant bits of LATB -- take care when changing them // They *are* changed in the timer interrupt handlers if those timers are // enabled. They are just there to make the lights blink and can be // disabled. // i2c_configure_slave(0x9E); #else // If I want to test the temperature sensor from the ARM, I just make // sure this PIC does not have the same address and configure the // temperature sensor address bits and then just stay in an infinite loop i2c_configure_slave(0x9A); #ifdef __USE18F2680 LATBbits.LATB1 = 1; LATBbits.LATB0 = 1; LATBbits.LATB2 = 1; #endif for (;;); #endif // must specifically enable the I2C interrupts PIE1bits.SSPIE = 1; // configure the hardware USART device #ifdef __USE18F26J50 Open1USART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 0x19); #else // OpenUSART(USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & // USART_CONT_RX & USART_BRGH_LOW, 0x19); #endif // Peripheral interrupts can have their priority set to high or low // enable high-priority interrupts and low-priority interrupts enable_interrupts(); /* Junk to force an I2C interrupt in the simulator (if you wanted to) PIR1bits.SSPIF = 1; _asm goto 0x08 _endasm; */ // printf() is available, but is not advisable. It goes to the UART pin // on the PIC and then you must hook something up to that to view it. // It is also slow and is blocking, so it will perturb your code's operation // Here is how it looks: printf("Hello\r\n"); //Setup ad // adcInit(); // loop forever // This loop is responsible for "handing off" messages to the subroutines // that should get them. Although the subroutines are not threads, but // they can be equated with the tasks in your task diagram if you // structure them properly //Init I2C I2CInit(); // OpenI2C(MASTER, SLEW_OFF); //Load Drivers DriverColorAdd(0x4F); DriverIRAdd(0x49); while (1) { // Call a routine that blocks until either on the incoming // messages queues has a message (this may put the processor into // an idle mode) block_on_To_msgqueues(); // At this point, one or both of the queues has a message. It // makes sense to check the high-priority messages first -- in fact, // you may only want to check the low-priority messages when there // is not a high priority message. That is a design decision and // I haven't done it here. length = ToMainHigh_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer); if (length < 0) { // no message, check the error code to see if it is concern if (length != MSGQUEUE_EMPTY) { // This case be handled by your code. } } else { switch (msgtype) { case MSGT_TIMER0: { timer0_lthread(&t0thread_data, msgtype, length, msgbuffer); break; }; case MSGT_I2C_DATA: { if (msgbuffer[0] != 0xFF) { //LATAbits.LA3 = !LATAbits.LA3; } break; }; case MSGT_I2C_DBG: { // Here is where you could handle debugging, if you wanted // keep track of the first byte received for later use (if desired) last_reg_recvd = msgbuffer[0]; break; }; case MSGT_I2C_RQST: { // Generally, this is *NOT* how I recommend you handle an I2C slave request // I recommend that you handle it completely inside the i2c interrupt handler // by reading the data from a queue (i.e., you would not send a message, as is done // now, from the i2c interrupt handler to main to ask for data). // // The last byte received is the "register" that is trying to be read // The response is dependent on the register. // last_reg_recvd = msgbuffer[length-1]; /* i2cmsg *tmpPtr = i2c_addressable_registers + 2;//(last_reg_recvd - 0xA8); start_i2c_slave_reply(tmpPtr->length, tmpPtr->data); */ // start_i2c_slave_reply(ADCBufferLen, ADCbufferI2C); break; }; default: { // Your code should handle this error break; }; }; } // Check the low priority queue length = ToMainLow_recvmsg(MSGLEN, &msgtype, (void *) msgbuffer); if (length < 0) { // no message, check the error code to see if it is concern if (length != MSGQUEUE_EMPTY) { // Your code should handle this situation } } else { switch (msgtype) { case MSGT_TIMER1: { // for (unsigned char i = 0; i < NumberOfDrivers; ++i) // DriverTable[i].poll(DriverTable[i].context); // msgbuffer[0] = 0x10; // msgbuffer[1] = 0x5A; // i2c_master_send(0x4F, 1, msgbuffer); i2c_master_recv(0x4F, 0x10, 8); timer1_lthread(&t1thread_data, msgtype, length, msgbuffer); break; }; case MSGT_OVERRUN: case MSGT_UART_DATA: { uart_lthread(&uthread_data, msgtype, length, msgbuffer); break; }; default: { // Your code should handle this error break; }; }; } } }
static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data) { struct pixcir_i2c_ts_data *tsdata = data; u8 rdbuf[10], wrbuf[1] = { 0 }; u8 touch; int ret; ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf)); if (ret != sizeof(wrbuf)) { dev_err(&tsdata->client->dev, "%s: i2c_master_send failed(), ret=%d\n", __func__, ret); return; } ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf)); if (ret != sizeof(rdbuf)) { dev_err(&tsdata->client->dev, "%s: i2c_master_recv failed(), ret=%d\n", __func__, ret); return; } touch = rdbuf[0]; if (touch) { u16 posx1 = (rdbuf[3] << 8) | rdbuf[2]; u16 posy1 = (rdbuf[5] << 8) | rdbuf[4]; u16 posx2 = (rdbuf[7] << 8) | rdbuf[6]; u16 posy2 = (rdbuf[9] << 8) | rdbuf[8]; /* HACK * Even though Tango M32 specification gives data in following order * {touch, old_touch, x1, y1, x2, y2, ...}, we are not receiving data in * this order, may be bacause of worng orientation of LCD and touch panel * following hack will give us correct x,y coordinates */ pixcir_ts_swap(&posx1, &posy1); pixcir_ts_swap(&posx2, &posy2); posx1 = tsdata->chip->x_max - posx1; input_report_key(tsdata->input, BTN_TOUCH, 1); input_report_abs(tsdata->input, ABS_X, posx1); input_report_abs(tsdata->input, ABS_Y, posy1); input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1); input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1); input_mt_sync(tsdata->input); if (touch == 2) { posx2 = tsdata->chip->x_max - posx2; input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx2); input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy2); input_mt_sync(tsdata->input); } } else { input_report_key(tsdata->input, BTN_TOUCH, 0); } input_sync(tsdata->input); }
static int AMI304_Chipset_Init(int mode, int chipset) { u8 databuf[10]; u8 regaddr; u8 ctrl1, ctrl2, ctrl3; unsigned char ctrl4[2]; regaddr = AMI304_REG_CTRL1; i2c_master_send(ami304_i2c_client, ®addr, 1); i2c_master_recv(ami304_i2c_client, &ctrl1, 1); regaddr = AMI304_REG_CTRL2; i2c_master_send(ami304_i2c_client, ®addr, 1); i2c_master_recv(ami304_i2c_client, &ctrl2, 1); regaddr = AMI304_REG_CTRL3; i2c_master_send(ami304_i2c_client, ®addr, 1); i2c_master_recv(ami304_i2c_client, &ctrl3, 1); // regaddr = AMI304_REG_CTRL4; //2 bytes // i2c_master_send(ami304_i2c_client, ®addr, 1); // i2c_master_recv(ami304_i2c_client, &(ctrl4[0]), 2); databuf[0] = AMI304_REG_CTRL1; if( mode == AMI304_FORCE_MODE ) { databuf[1] = ctrl1 | AMI304_CTRL1_PC1 | AMI304_CTRL1_FS1_FORCE; write_lock(&ami304_data.lock); ami304_data.mode = AMI304_FORCE_MODE; write_unlock(&ami304_data.lock); } else { databuf[1] = ctrl1 | AMI304_CTRL1_PC1 | AMI304_CTRL1_FS1_NORMAL | AMI304_CTRL1_ODR1; write_lock(&ami304_data.lock); ami304_data.mode = AMI304_NORMAL_MODE; write_unlock(&ami304_data.lock); } i2c_master_send(ami304_i2c_client, databuf, 2); databuf[0] = AMI304_REG_CTRL2; databuf[1] = ctrl2 | AMI304_CTRL2_DREN | AMI304_CTRL2_DRP; i2c_master_send(ami304_i2c_client, databuf, 2); databuf[0] = AMI304_REG_CTRL3; databuf[1] = ctrl3 | AMI304_CTRL3_B0_LO_CLR; i2c_master_send(ami304_i2c_client, databuf, 2); databuf[0] = AMI304_REG_CTRL4; if( chipset == AMI304_CHIPSET ) //AMI304 { // ctrl4[1] = ctrl4[1] & AMI304_CTRL4_COMPASS_MODE; //0x5D ctrl4[0] = 0x00; ctrl4[1] = 0x00; } else //AMI306 //AMI306_CHIPSET { // ctrl4[1] = ctrl4[1] | AMI306_CTRL4_HIGHSPEED_MODE; //0x5D ctrl4[0] = 0x7e; ctrl4[1] = 0xa0; } databuf[1] = ctrl4[0]; databuf[2] = ctrl4[1]; i2c_master_send(ami304_i2c_client, databuf, 3); return 0; }