static int touchkey_firmware_update(struct touchkey_i2c *tkey_i2c) { int retry = 3; int ret = 0; char data[3]; disable_irq(tkey_i2c->irq); ret = i2c_touchkey_read(tkey_i2c->client, KEYCODE_REG, data, 3); if (ret < 0) { pr_debug("[TouchKey] i2c read fail. do not excute firm update.\n"); data[1] = 0; data[2] = 0; } pr_err("%s F/W version: 0x%x, Module version:0x%x\n", __func__, data[1], data[2]); tkey_i2c->firmware_ver = data[1]; tkey_i2c->module_ver = data[2]; #if defined(CONFIG_MACH_M0) || defined(CONFIG_MACH_C1) \ || defined(CONFIG_MACH_C1VZW) || defined(CONFIG_MACH_C2) if ((tkey_i2c->firmware_ver < TK_FIRMWARE_VER) && (tkey_i2c->module_ver <= TK_MODULE_VER)) { #else if ((tkey_i2c->firmware_ver < TK_FIRMWARE_VER) && (tkey_i2c->module_ver == TK_MODULE_VER)) { #endif pr_debug("[TouchKey] firmware auto update excute\n"); tkey_i2c->update_status = TK_UPDATE_DOWN; while (retry--) { if (ISSP_main(tkey_i2c) == 0) { pr_debug("[TouchKey]firmware update succeeded\n"); tkey_i2c->update_status = TK_UPDATE_PASS; msleep(50); break; } msleep(50); pr_debug("[TouchKey] firmware update failed. retry\n"); } if (retry <= 0) { tkey_i2c->pdata->power_on(0); tkey_i2c->update_status = TK_UPDATE_FAIL; pr_debug("[TouchKey] firmware update failed.\n"); } ret = touchkey_i2c_check(tkey_i2c); if (ret < 0) { pr_debug("[TouchKey] i2c read fail.\n"); return TK_UPDATE_FAIL; } #if defined(CONFIG_TARGET_LOCALE_KOR) ret = i2c_touchkey_read(tkey_i2c->client, KEYCODE_REG, data, 3); if (ret < 0) { pr_debug("[TouchKey] i2c read fail. do not excute firm update.\n"); } tkey_i2c->firmware_ver = data[1]; tkey_i2c->module_ver = data[2]; #endif printk(KERN_DEBUG "[TouchKey] firm ver = %d, module ver = %d\n", tkey_i2c->firmware_ver, tkey_i2c->module_ver); } else { pr_debug("[TouchKey] firmware auto update do not excute\n"); pr_debug("[TouchKey] firmware_ver(banary=%d, current=%d)\n", TK_FIRMWARE_VER, tkey_i2c->firmware_ver); pr_debug("[TouchKey] module_ver(banary=%d, current=%d)\n", TK_MODULE_VER, tkey_i2c->module_ver); } enable_irq(tkey_i2c->irq); return TK_UPDATE_PASS; } #else static int touchkey_firmware_update(struct touchkey_i2c *tkey_i2c) { char data[3]; int retry; int ret = 0; ret = i2c_touchkey_read(tkey_i2c->client, KEYCODE_REG, data, 3); if (ret < 0) { pr_debug("[TouchKey] i2c read fail. do not excute firm update.\n"); return ret; } pr_err("%s F/W version: 0x%x, Module version:0x%x\n", __func__, data[1], data[2]); retry = 3; tkey_i2c->firmware_ver = data[1]; tkey_i2c->module_ver = data[2]; if (tkey_i2c->firmware_ver < 0x0A) { tkey_i2c->update_status = TK_UPDATE_DOWN; while (retry--) { if (ISSP_main(tkey_i2c) == 0) { pr_err("[TOUCHKEY]Touchkey_update succeeded\n"); tkey_i2c->update_status = TK_UPDATE_PASS; break; } pr_err("touchkey_update failed...retry...\n"); } if (retry <= 0) { tkey_i2c->pdata->power_on(0); tkey_i2c->update_status = TK_UPDATE_FAIL; ret = TK_UPDATE_FAIL; } } else { if (tkey_i2c->firmware_ver >= 0x0A) { pr_err("[TouchKey] Not F/W update. Cypess touch-key F/W version is latest\n"); } else { pr_err("[TouchKey] Not F/W update. Cypess touch-key version(module or F/W) is not valid\n"); } } return ret; }
static int touchkey_firmware_update(struct touchkey_i2c *tkey_i2c) { int retry = 3; int ret = 0; char data[3]; disable_irq(tkey_i2c->irq); ret = i2c_touchkey_read(tkey_i2c->client, KEYCODE_REG, data, 3); if (ret < 0) { printk(KERN_DEBUG "[TouchKey] i2c read fail. do not excute firm update.\n"); data[1] = 0; data[2] = 0; } printk(KERN_ERR "%s F/W version: 0x%x, Module version:0x%x\n", __func__, data[1], data[2]); tkey_i2c->firmware_ver = data[1]; tkey_i2c->module_ver = data[2]; if ((tkey_i2c->firmware_ver < TK_FIRMWARE_VER) && (tkey_i2c->module_ver <= TK_MODULE_VER)) { printk(KERN_DEBUG "[TouchKey] firmware auto update excute\n"); tkey_i2c->update_status = TK_UPDATE_DOWN; while (retry--) { if (ISSP_main(tkey_i2c) == 0) { printk(KERN_DEBUG "[TouchKey]firmware update succeeded\n"); tkey_i2c->update_status = TK_UPDATE_PASS; msleep(50); break; } msleep(50); printk(KERN_DEBUG "[TouchKey] firmware update failed. retry\n"); } if (retry <= 0) { //tkey_i2c->pdata->power_on(0); touchkey_led_on(tkey_i2c, 0); tkey_i2c->update_status = TK_UPDATE_FAIL; printk(KERN_DEBUG "[TouchKey] firmware update failed.\n"); } ret = touchkey_i2c_check(tkey_i2c); if (ret < 0) { printk(KERN_DEBUG "[TouchKey] i2c read fail.\n"); return TK_UPDATE_FAIL; } printk(KERN_DEBUG "[TouchKey] firm ver = %d, module ver = %d\n", tkey_i2c->firmware_ver, tkey_i2c->module_ver); } else { printk(KERN_DEBUG "[TouchKey] firmware auto update do not excute\n"); printk(KERN_DEBUG "[TouchKey] firmware_ver(banary=%d, current=%d)\n", TK_FIRMWARE_VER, tkey_i2c->firmware_ver); printk(KERN_DEBUG "[TouchKey] module_ver(banary=%d, current=%d)\n", TK_MODULE_VER, tkey_i2c->module_ver); } enable_irq(tkey_i2c->irq); return TK_UPDATE_PASS; }
static int i2c_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct touchkey_platform_data *pdata = client->dev.platform_data; struct touchkey_i2c *tkey_i2c; struct input_dev *input_dev; int err = 0; unsigned char data; int i; int ret; pr_debug("[TouchKey] i2c_touchkey_probe\n"); if (pdata == NULL) { printk(KERN_ERR "%s: no pdata\n", __func__); return -ENODEV; } /*Check I2C functionality */ ret = i2c_check_functionality(client->adapter, I2C_FUNC_I2C); if (ret == 0) { pr_err("[Touchkey] No I2C functionality found\n"); ret = -ENODEV; return ret; } /*Obtain kernel memory space for touchkey i2c */ tkey_i2c = kzalloc(sizeof(struct touchkey_i2c), GFP_KERNEL); if (NULL == tkey_i2c) { pr_err("[Touchkey] failed to allocate tkey_i2c.\n"); return -ENOMEM; } tkey_i2c_local = tkey_i2c; input_dev = input_allocate_device(); if (!input_dev) { pr_err("[Touchkey] failed to allocate input device\n"); kfree(tkey_i2c); return -ENOMEM; } input_dev->name = "sec_touchkey"; input_dev->phys = "sec_touchkey/input0"; input_dev->id.bustype = BUS_HOST; input_dev->dev.parent = &client->dev; /*tkey_i2c*/ tkey_i2c->pdata = pdata; tkey_i2c->input_dev = input_dev; tkey_i2c->client = client; tkey_i2c->irq = client->irq; tkey_i2c->name = "sec_touchkey"; set_bit(EV_SYN, input_dev->evbit); set_bit(EV_LED, input_dev->evbit); set_bit(LED_MISC, input_dev->ledbit); set_bit(EV_KEY, input_dev->evbit); for (i = 1; i < touchkey_count; i++) set_bit(touchkey_keycode[i], input_dev->keybit); input_set_drvdata(input_dev, tkey_i2c); ret = input_register_device(input_dev); if (ret) { pr_err("[Touchkey] failed to register input device\n"); input_free_device(input_dev); kfree(tkey_i2c); return err; } INIT_WORK(&tkey_i2c->update_work, touchkey_update_func); tkey_i2c->pdata->power_on(1); msleep(50); touchkey_enable = 1; data = 1; /*sysfs*/ tkey_i2c->dev = device_create(sec_class, NULL, 0, NULL, "sec_touchkey"); if (IS_ERR(tkey_i2c->dev)) { pr_err("[TouchKey] Failed to create device(tkey_i2c->dev)!\n"); input_unregister_device(input_dev); } else { dev_set_drvdata(tkey_i2c->dev, tkey_i2c); ret = sysfs_create_group(&tkey_i2c->dev->kobj, &touchkey_attr_group); if (ret) { pr_err("[TouchKey]: failed to create sysfs group\n"); } } #if defined(CONFIG_MACH_M0) || defined(CONFIG_MACH_C1) gpio_request(GPIO_OLED_DET, "OLED_DET"); ret = gpio_get_value(GPIO_OLED_DET); pr_debug("[TouchKey] OLED_DET = %d\n", ret); if (ret == 0) { pr_debug("[TouchKey] device wasn't connected to board\n"); input_unregister_device(input_dev); touchkey_probe = false; return -EBUSY; } #else ret = touchkey_i2c_check(tkey_i2c); if (ret < 0) { pr_debug("[TouchKey] probe failed\n"); input_unregister_device(input_dev); touchkey_probe = false; return -EBUSY; } #endif ret = request_threaded_irq(tkey_i2c->irq, NULL, touchkey_interrupt, IRQF_DISABLED | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, tkey_i2c->name, tkey_i2c); if (ret < 0) { pr_err("[Touchkey]: failed to request irq(%d) - %d\n", tkey_i2c->irq, ret); input_unregister_device(input_dev); touchkey_probe = false; return -EBUSY; } tkey_i2c->pdata->led_power_on(1); #if defined(TK_HAS_FIRMWARE_UPDATE) ret = touchkey_firmware_update(tkey_i2c); if (ret < 0) { pr_err("[Touchkey]: failed firmware updating process (%d)\n", ret); input_unregister_device(input_dev); touchkey_probe = false; return -EBUSY; } #endif #ifdef CONFIG_HAS_EARLYSUSPEND tkey_i2c->early_suspend.suspend = (void *)sec_touchkey_early_suspend; tkey_i2c->early_suspend.resume = (void *)sec_touchkey_late_resume; register_early_suspend(&tkey_i2c->early_suspend); #endif #if defined(TK_HAS_AUTOCAL) touchkey_autocalibration(tkey_i2c); #endif set_touchkey_debug('K'); // init workqueue tkey_i2c->wq = create_singlethread_workqueue("tkey_i2c_wq"); if (!tkey_i2c->wq) { ret = -ENOMEM; pr_err("[Touchkey] %s: could not create workqueue\n", __func__); } /* this is the thread function we run on the work queue */ INIT_WORK(&tkey_i2c->work, touch_led_timedout_work); return 0; }