static int sec_touchkey_late_resume(struct early_suspend *h) { struct touchkey_i2c *tkey_i2c = container_of(h, struct touchkey_i2c, early_suspend); #ifdef TEST_JIG_MODE unsigned char get_touch = 0x40; #endif set_touchkey_debug('R'); printk(KERN_DEBUG "[TouchKey] sec_touchkey_late_resume\n"); #if defined(CONFIG_S2VE_TOUCHKEY_REV05) printk(KERN_ERR"sec_touchkey_late_resume++\n"); Touchkey_PowerOnOff(1); gpio_set_value(TOUCHKEY_SDA, 0); gpio_set_value(TOUCHKEY_SCL, 0); touchkey_led_on(tkey_i2c, 1); touchkey_suspended = 0; #else if (touchkey_enable < 0) { printk(KERN_DEBUG "[TouchKey] ---%s---touchkey_enable: %d\n", __func__, touchkey_enable); return 0; } msleep(50); touchkey_enable = 1; #if defined(TK_HAS_AUTOCAL) touchkey_autocalibration(tkey_i2c); #endif if (touchled_cmd_reversed) { touchled_cmd_reversed = 0; i2c_touchkey_write(tkey_i2c->client, (u8 *) &touchkey_led_status, 1); printk(KERN_DEBUG "[Touchkey] LED returned on\n"); } #ifdef TEST_JIG_MODE i2c_touchkey_write(tkey_i2c->client, &get_touch, 1); #endif enable_irq(tkey_i2c->irq); #endif return 0; }
static ssize_t autocalibration_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev); int data; sscanf(buf, "%d\n", &data); if (data == 1) touchkey_autocalibration(tkey_i2c); return size; }
static ssize_t set_touchkey_update_show(struct device *dev, struct device_attribute *attr, char *buf) { struct touchkey_i2c *tkey_i2c = dev_get_drvdata(dev); int count = 0; int retry = 3; tkey_i2c->update_status = TK_UPDATE_DOWN; disable_irq(tkey_i2c->irq); #ifdef TEST_JIG_MODE unsigned char get_touch = 0x40; #endif while (retry--) { if (ISSP_main(tkey_i2c) == 0) { printk(KERN_ERR "[TouchKey]Touchkey_update succeeded\n"); tkey_i2c->update_status = TK_UPDATE_PASS; count = 1; msleep(50); break; } printk(KERN_ERR "touchkey_update failed... retry...\n"); } if (retry <= 0) { /* disable ldo11 */ tkey_i2c->pdata->power_on(0); count = 0; printk(KERN_ERR "[TouchKey]Touchkey_update fail\n"); tkey_i2c->update_status = TK_UPDATE_FAIL; enable_irq(tkey_i2c->irq); return count; } #ifdef TEST_JIG_MODE i2c_touchkey_write(tkey_i2c->client, &get_touch, 1); #endif #if defined(TK_HAS_AUTOCAL) touchkey_autocalibration(tkey_i2c); #endif enable_irq(tkey_i2c->irq); return count; }
static int sec_touchkey_late_resume(struct early_suspend *h) { struct touchkey_i2c *tkey_i2c = container_of(h, struct touchkey_i2c, early_suspend); #ifdef TEST_JIG_MODE unsigned char get_touch = 0x40; #endif set_touchkey_debug('R'); pr_debug("[TouchKey] sec_touchkey_late_resume\n"); /* enable ldo11 */ tkey_i2c->pdata->power_on(1); if (touchkey_enable < 0) { pr_debug("[TouchKey] ---%s---touchkey_enable: %d\n", __func__, touchkey_enable); return 0; } msleep(50); tkey_i2c->pdata->led_power_on(1); touchkey_enable = 1; #if defined(TK_HAS_AUTOCAL) touchkey_autocalibration(tkey_i2c); #endif if (touchled_cmd_reversed) { touchled_cmd_reversed = 0; i2c_touchkey_write(tkey_i2c->client, (u8 *) &touchkey_led_status, 1); pr_debug("[Touchkey] LED returned on\n"); } #ifdef TEST_JIG_MODE i2c_touchkey_write(tkey_i2c->client, &get_touch, 1); #endif enable_irq(tkey_i2c->irq); return 0; }
static int melfas_touchkey_late_resume(struct early_suspend *h) { set_touchkey_debug('R'); printk(KERN_DEBUG "[TouchKey] melfas_touchkey_late_resume\n"); /* enable ldo20 */ touchkey_ldo_on(1); msleep(100); #ifdef WHY_DO_WE_NEED_THIS /* clear interrupt */ if (readl(gpio_pend_mask_mem) & (0x1 << 1)) { writel(readl(gpio_pend_mask_mem) | (0x1 << 1), gpio_pend_mask_mem); } #endif touchkey_enable = 1; enable_irq(IRQ_TOUCH_INT); if(touchled_cmd_reversed) { touchled_cmd_reversed = 0; i2c_touchkey_write(&touchkey_led_status, 1); printk("LED returned on..\n"); } #if 1 msleep(100); touchkey_autocalibration(); #endif #ifdef TEST_JIG_MODE i2c_touchkey_write(&get_touch, 1); #endif return 0; }
void touchkey_update_func(struct work_struct *work) { struct touchkey_i2c *tkey_i2c = container_of(work, struct touchkey_i2c, update_work); int retry = 3; char data[3]; i2c_touchkey_read(tkey_i2c->client, KEYCODE_REG, data, 3); printk(KERN_DEBUG "[%s] F/W version: 0x%x, Module version:0x%x\n", __func__, data[1], data[2]); tkey_i2c->update_status = TK_UPDATE_DOWN; printk(KERN_DEBUG "[TouchKey] %s start\n", __func__); touchkey_enable = 0; while (retry--) { if (ISSP_main(tkey_i2c) == 0) { printk(KERN_DEBUG "[TouchKey] touchkey_update succeeded\n"); msleep(50); touchkey_enable = 1; #if defined(TK_HAS_AUTOCAL) touchkey_autocalibration(tkey_i2c); #endif tkey_i2c->update_status = TK_UPDATE_PASS; enable_irq(tkey_i2c->irq); return; } // tkey_i2c->pdata->power_on(0); touchkey_led_on(tkey_i2c, 0); } enable_irq(tkey_i2c->irq); tkey_i2c->update_status = TK_UPDATE_FAIL; printk(KERN_DEBUG "[TouchKey] touchkey_update failed\n"); return; }
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; int i; int ret; printk("[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) { printk(KERN_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) { printk(KERN_ERR "[Touchkey] failed to allocate tkey_i2c.\n"); return -ENOMEM; } input_dev = input_allocate_device(); if (!input_dev) { printk(KERN_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; i2c_set_clientdata(client, tkey_i2c); 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); printk("[TouchKey]: tkey_i2c->irq : %d\n", tkey_i2c->irq); ret = input_register_device(input_dev); if (ret) { printk(KERN_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); #if defined(CONFIG_S2VE_TOUCHKEY_REV05) Touchkey_PowerOnOff(1); #endif touchkey_enable = 1; touchkey_led_on(tkey_i2c, 1); msleep(50); /*sysfs*/ tkey_i2c->dev = device_create(sec_class, NULL, 0, NULL, "sec_touchkey"); if (IS_ERR(tkey_i2c->dev)) { printk("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) { printk( "[TouchKey]: failed to create sysfs group\n"); } } ret = request_threaded_irq(tkey_i2c->irq, NULL /*touchkey_irq_handler*/, touchkey_interrupt, IRQF_DISABLED | IRQF_TRIGGER_FALLING /* | IRQF_ONESHOT */, tkey_i2c->name, tkey_i2c); if (ret < 0) { printk("[Touchkey]: failed to request irq(%d) - %d\n", tkey_i2c->irq, ret); input_unregister_device(input_dev); return -EBUSY; } #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 0 //defined(TK_HAS_FIRMWARE_UPDATE) ret = touchkey_firmware_update(tkey_i2c); if (ret < 0) { printk(KERN_ERR "[Touchkey]: failed firmware updating process (%d)\n", ret); input_unregister_device(input_dev); return -EBUSY; } #endif #if defined(TK_HAS_AUTOCAL) touchkey_autocalibration(tkey_i2c); #endif printk("[Touchkey]: %s Probe done! \n", __func__); set_touchkey_debug('K'); return 0; }
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; }
static int i2c_touchkey_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct input_dev *input_dev; int err = 0; unsigned char data; //struct regulator *regulator; printk(KERN_DEBUG "[TouchKey] melfas i2c_touchkey_probe\n"); touchkey_driver = kzalloc(sizeof(struct i2c_touchkey_driver), GFP_KERNEL); if (touchkey_driver == NULL) { dev_err(dev, "failed to create our state\n"); return -ENOMEM; } touchkey_driver->client = client; touchkey_driver->client->irq = IRQ_TOUCH_INT; strlcpy(touchkey_driver->client->name, "melfas-touchkey", I2C_NAME_SIZE); input_dev = input_allocate_device(); if (!input_dev) { return -ENOMEM; } touchkey_driver->input_dev = input_dev; input_dev->name = DEVICE_NAME; input_dev->phys = "melfas-touchkey/input0"; input_dev->id.bustype = BUS_HOST; set_bit(EV_SYN, input_dev->evbit); set_bit(EV_KEY, input_dev->evbit); set_bit(touchkey_keycode[1], input_dev->keybit); set_bit(touchkey_keycode[2], input_dev->keybit); set_bit(touchkey_keycode[3], input_dev->keybit); set_bit(touchkey_keycode[4], input_dev->keybit); err = input_register_device(input_dev); if (err) { input_free_device(input_dev); return err; } #ifdef WHY_DO_WE_NEED_THIS gpio_pend_mask_mem = ioremap(INT_PEND_BASE, 0x10); #endif #ifdef CONFIG_HAS_EARLYSUSPEND touchkey_driver->early_suspend.suspend = (void*) melfas_touchkey_early_suspend; touchkey_driver->early_suspend.resume = (void*) melfas_touchkey_late_resume; register_early_suspend(&touchkey_driver->early_suspend); #endif /* CONFIG_HAS_EARLYSUSPEND */ /* enable ldo11 */ touchkey_ldo_on(1); msleep(50); touchkey_enable = 1; data = 1; #if 0 i2c_touchkey_write(&data, 1); #endif #if 0 if (request_irq (IRQ_TOUCH_INT, touchkey_interrupt, IRQF_DISABLED, DEVICE_NAME, NULL)) { printk(KERN_ERR "[TouchKey] %s Can't allocate irq ..\n", __func__); return -EBUSY; } #else err = request_threaded_irq(IRQ_TOUCH_INT, NULL, touchkey_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DEVICE_NAME, NULL); if (err) { printk(KERN_ERR "[TouchKey] %s fail. Can't allocate irq\n", __func__); input_unregister_device(input_dev); return -EBUSY; } #endif /* enable ldo20 */ // touchkey_led_ldo_on(1); #if 1 // touchkey_firmware_update(); msleep(100); touchkey_autocalibration(); msleep(50); #endif set_touchkey_debug('K'); return 0; }