123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599 |
- /*
- * cypress_touchkey.c - Platform data for cypress touchkey driver
- *
- * Copyright (C) 2011 Samsung Electronics
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
- #define SEC_TOUCHKEY_DEBUG
- /* #define SEC_TOUCHKEY_VERBOSE_DEBUG */
- #include <linux/module.h>
- #include <linux/input.h>
- #include <linux/init.h>
- #include <linux/slab.h>
- #include <linux/i2c.h>
- #include <linux/interrupt.h>
- #include <linux/irq.h>
- #include <linux/delay.h>
- #include <linux/platform_device.h>
- #include <linux/gpio.h>
- #include <linux/miscdevice.h>
- #include <linux/earlysuspend.h>
- #include "cypress_tkey_fw.h"
- #include <linux/regulator/consumer.h>
- #include <linux/mutex.h>
- #include <linux/workqueue.h>
- #include <linux/leds.h>
- #include <asm/mach-types.h>
- #include <linux/of_gpio.h>
- #include "cypress_touchkey.h"
- #if defined(CONFIG_LCD_CONNECTION_CHECK)
- extern int is_lcd_attached(void);
- #endif
- #if 0 // enable if you use home-touchkey
- #define HOME_KEY_USE
- #endif
- #define CYPRESS_GEN 0X00
- #define CYPRESS_FW_VER 0X01
- #define CYPRESS_MODULE_VER 0X02
- #define CYPRESS_2ND_HOST 0X03
- #define CYPRESS_THRESHOLD 0X04
- #define CYPRESS_AUTO_CAL_FLG 0X05
- #define CYPRESS_IDAC_MENU 0X07
- #define CYPRESS_IDAC_BACK 0X06
- #ifdef HOME_KEY_USE
- #define CYPRESS_IDAC_HOME 0X08
- #endif
- #define CYPRESS_DIFF_MENU 0x0C
- #define CYPRESS_DIFF_BACK 0x0A
- #ifdef HOME_KEY_USE
- #define CYPRESS_DIFF_HOME 0x0E
- #endif
- #define CYPRESS_RAW_DATA_MENU 0x10
- #define CYPRESS_RAW_DATA_BACK 0x0E
- #ifdef HOME_KEY_USE
- #define CYPRESS_RAW_DATA_HOME 0x12
- #endif
- #define CYPRESS_RAW_DATA_BACK_GOGH 0x14
- #define CYPRESS_LED_ON 0X10
- #define CYPRESS_LED_OFF 0X20
- #define CYPRESS_DATA_UPDATE 0X40
- #define CYPRESS_AUTO_CAL 0X50
- #define CYPRESS_LED_CONTROL_ON 0X60
- #define CYPRESS_LED_CONTROL_OFF 0X70
- #define CYPRESS_SLEEP 0X80
- static int vol_mv_level = 33;
- #define USE_OPEN_CLOSE
- #define TOUCHKEY_BACKLIGHT "button-backlight"
- /* bit masks*/
- #define PRESS_BIT_MASK 0X08
- #define KEYCODE_BIT_MASK 0X07
- #define TOUCHKEY_LOG(k, v) dev_notice(&info->client->dev, "key[%d] %d\n", k, v);
- #define FUNC_CALLED dev_notice(&info->client->dev, "%s: called.\n", __func__);
- #define NUM_OF_RETRY_UPDATE 3
- #define NUM_OF_KEY 4
- #ifdef USE_OPEN_CLOSE
- static int cypress_input_open(struct input_dev *dev);
- static void cypress_input_close(struct input_dev *dev);
- #endif
- /*
- struct cypress_touchkey_info {
- struct i2c_client *client;
- struct cypress_touchkey_platform_data *pdata;
- struct input_dev *input_dev;
- struct early_suspend early_suspend;
- char phys[32];
- unsigned char keycode[NUM_OF_KEY];
- u8 sensitivity[NUM_OF_KEY];
- int irq;
- u8 fw_ver;
- void (*power_onoff)(int);
- int touchkey_update_status;
- struct led_classdev leds;
- enum led_brightness brightness;
- struct mutex touchkey_led_mutex;
- struct workqueue_struct *led_wq;
- struct work_struct led_work;
- bool is_powering_on;
- };
- */
- #ifdef CONFIG_HAS_EARLYSUSPEND
- static void cypress_touchkey_early_suspend(struct early_suspend *h);
- static void cypress_touchkey_late_resume(struct early_suspend *h);
- #endif
- static int touchkey_led_status;
- static int touchled_cmd_reversed;
- static void cypress_touchkey_led_work(struct work_struct *work)
- {
- struct cypress_touchkey_info *info =
- container_of(work, struct cypress_touchkey_info, led_work);
- u8 buf;
- int ret;
- if (info->brightness == LED_OFF)
- buf = CYPRESS_LED_OFF;
- else
- buf = CYPRESS_LED_ON;
- mutex_lock(&info->touchkey_mutex);
- ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, buf);
- if (ret < 0)
- touchled_cmd_reversed = 1;
- touchkey_led_status = buf;
- mutex_unlock(&info->touchkey_mutex);
- }
- static void cypress_touchkey_brightness_set(struct led_classdev *led_cdev,
- enum led_brightness brightness)
- {
- /* Must not sleep, use a workqueue if needed */
- struct cypress_touchkey_info *info =
- container_of(led_cdev, struct cypress_touchkey_info, leds);
- info->brightness = brightness;
- queue_work(info->led_wq, &info->led_work);
- }
- static int reg_set_optimum_mode_check(struct regulator *reg, int load_uA)
- {
- return (regulator_count_voltages(reg) > 0) ?
- regulator_set_optimum_mode(reg, load_uA) : 0;
- }
- void cypress_power_onoff(struct cypress_touchkey_info *info, int onoff)
- {
- int ret = 0, rc = 0;
- dev_info(&info->client->dev, "%s: power %s\n",
- __func__, onoff ? "on" : "off");
- if (info->pdata->vdd_led < 0) {
- if (!info->vdd_led) {
- info->vdd_led = regulator_get(&info->client->dev,
- "vdd_led");
- if (IS_ERR(info->vdd_led)) {
- rc = PTR_ERR(info->vdd_led);
- dev_info(&info->client->dev,
- "Regulator(vdd_led) get failed rc=%d\n", rc);
- goto error_get_vtg_i2c;
- }
- }
- }
- if (onoff) {
- if (info->pdata->i2c_pull_up) {
- if (info->pdata->vdd_led < 0) {
- rc = reg_set_optimum_mode_check(info->vdd_led,
- 10000);
- if (rc < 0) {
- dev_info(&info->client->dev,
- "Regulator vdd_led set_opt failed rc=%d\n",
- rc);
- goto error_reg_opt_i2c;
- }
- rc = regulator_enable(info->vdd_led);
- if (rc) {
- dev_info(&info->client->dev,
- "Regulator vdd_led enable failed rc=%d\n",
- rc);
- goto error_reg_en_vcc_en;
- }
- }
- }
- } else {
- if (info->pdata->i2c_pull_up) {
- if (info->pdata->vdd_led < 0) {
- reg_set_optimum_mode_check(info->vdd_led, 0);
- regulator_disable(info->vdd_led);
- }
- }
- }
- //msleep(50);
- ret = gpio_direction_output(info->pdata->vdd_en, onoff);
- if (ret) {
- pr_err("[TKEY]%s: unable to set_direction for mms_vdd_en [%d]\n",
- __func__, info->pdata->vdd_en);
- }
- if (info->pdata->vdd_led > 0) {
- ret = gpio_direction_output(info->pdata->vdd_led, onoff);
- if (ret) {
- dev_info(&info->client->dev,
- "[TKEY]%s: unable to set_direction for vdd_led [%d]\n",
- __func__, info->pdata->vdd_led);
- }
- //msleep(30);
- }
- return;
- error_reg_en_vcc_en:
- if (info->pdata->i2c_pull_up) {
- // reg_set_optimum_mode_check(info->vcc_en, 0);
- if (info->pdata->vdd_led < 0)
- reg_set_optimum_mode_check(info->vdd_led, 0);
- }
- error_reg_opt_i2c:
- //error_set_vtg_i2c:
- // regulator_put(info->vcc_en);
- if (info->pdata->vdd_led < 0)
- regulator_put(info->vdd_led);
- error_get_vtg_i2c:
- return;
- }
- static void change_touch_key_led_voltage(int vol_mv)
- {
- struct regulator *tled_regulator;
- int ret;
- vol_mv_level = vol_mv;
- tled_regulator = regulator_get(NULL, "8921_l10");
- if (IS_ERR(tled_regulator)) {
- pr_err("%s: failed to get resource %s\n", __func__,
- "touch_led");
- return;
- }
- ret = regulator_set_voltage(tled_regulator,
- vol_mv * 100000, vol_mv * 100000);
- if (ret)
- printk(KERN_ERR"error setting voltage\n");
- regulator_put(tled_regulator);
- }
- static ssize_t brightness_control(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- int data;
- if (sscanf(buf, "%2d\n", &data) == 1) {
- printk(KERN_ERR"[TouchKey] touch_led_brightness: %d\n", data);
- change_touch_key_led_voltage(data);
- } else {
- printk(KERN_ERR "[TouchKey] touch_led_brightness Error\n");
- }
- return size;
- }
- static ssize_t brightness_level_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int count;
- count = sprintf(buf, "%d\n", vol_mv_level);
- printk(KERN_DEBUG "[TouchKey] Touch LED voltage = %d\n", vol_mv_level);
- return count;
- }
- static irqreturn_t cypress_touchkey_interrupt(int irq, void *dev_id)
- {
- struct cypress_touchkey_info *info = dev_id;
- u8 buf[10] = {0,};
- int code;
- int press;
- int ret;
- ret = gpio_get_value(info->pdata->gpio_int);
- if (ret) {
- dev_err(&info->client->dev, "not real interrupt (%d).\n", ret);
- goto out;
- }
- if (info->is_powering_on) {
- dev_err(&info->client->dev, "%s: ignoring spurious boot "
- "interrupt\n", __func__);
- return IRQ_HANDLED;
- }
- #if defined(SEC_TOUCHKEY_VERBOSE_DEBUG)
- ret = i2c_smbus_read_i2c_block_data(info->client,
- CYPRESS_GEN, ARRAY_SIZE(buf), buf);
- if (ret != ARRAY_SIZE(buf)) {
- dev_err(&info->client->dev, "interrupt failed with %d.\n", ret);
- goto out;
- }
- print_hex_dump(KERN_DEBUG, "cypress_touchkey: ",
- DUMP_PREFIX_OFFSET, 32, 1, buf, 10, false);
- #else
- buf[0] = i2c_smbus_read_byte_data(info->client, CYPRESS_GEN);
- if (buf[0] < 0) {
- dev_err(&info->client->dev, "interrupt failed with %d.\n", ret);
- goto out;
- }
- #endif
- press = !(buf[0] & PRESS_BIT_MASK);
- code = (int)(buf[0] & KEYCODE_BIT_MASK) - 1;
- dev_dbg(&info->client->dev,
- "[TouchKey]press=%d, code=%d\n", press, code);
- if (code < 0) {
- dev_err(&info->client->dev,
- "not profer interrupt 0x%2X.\n", buf[0]);
- goto out;
- }
- #if defined(SEC_TOUCHKEY_DEBUG)
- TOUCHKEY_LOG(info->keycode[code], press);
- #endif
- // if (touch_is_pressed && press) {
- // printk(KERN_ERR "[TouchKey] don't send event because touch is pressed.\n");
- // printk(KERN_ERR "[TouchKey] touch_pressed = %d\n",
- // touch_is_pressed);
- // } else {
- input_report_key(info->input_dev, info->keycode[code], press);
- input_sync(info->input_dev);
- // }
- out:
- return IRQ_HANDLED;
- }
- static void cypress_touchkey_con_hw(struct cypress_touchkey_info *dev_info,
- bool flag)
- {
- struct cypress_touchkey_info *info = dev_info;
- gpio_set_value(info->pdata->gpio_led_en, flag ? 1 : 0);
- #if defined(SEC_TOUCHKEY_DEBUG)
- dev_notice(&info->client->dev,
- "%s : called with flag %d.\n", __func__, flag);
- #endif
- }
- static int cypress_touchkey_auto_cal(struct cypress_touchkey_info *dev_info)
- {
- struct cypress_touchkey_info *info = dev_info;
- u8 data[6] = { 0, };
- int count = 0;
- unsigned short retry = 0;
- while (retry < 3) {
- int ret = 0;
- ret = i2c_smbus_read_i2c_block_data(info->client,
- CYPRESS_GEN, 4, data);
- if (ret < 0) {
- printk(KERN_ERR "[TouchKey]i2c read fail.\n");
- return ret;
- }
- data[0] = 0x50;
- data[3] = 0x01;
- count = i2c_smbus_write_i2c_block_data(info->client,
- CYPRESS_GEN, 4, data);
- printk(KERN_DEBUG
- "[TouchKey] data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n",
- data[0], data[1], data[2], data[3]);
- msleep(50);
- ret = i2c_smbus_read_i2c_block_data(info->client,
- CYPRESS_GEN, 6, data);
- if ((data[5] & 0x80)) {
- printk(KERN_DEBUG "[Touchkey] autocal Enabled\n");
- break;
- } else {
- printk(KERN_DEBUG "[Touchkey] autocal disabled, retry %d\n",
- retry);
- }
- retry = retry + 1;
- }
- if (retry == 3)
- printk(KERN_DEBUG "[Touchkey] autocal failed\n");
- return count;
- }
- static int cypress_touchkey_led_on(struct cypress_touchkey_info *dev_info)
- {
- struct cypress_touchkey_info *info = dev_info;
- u8 buf = CYPRESS_LED_ON;
- int ret;
- ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, buf);
- if (ret < 0) {
- dev_err(&info->client->dev,
- "[Touchkey] i2c write error [%d]\n", ret);
- }
- return ret;
- }
- static int cypress_touchkey_led_off(struct cypress_touchkey_info *dev_info)
- {
- struct cypress_touchkey_info *info = dev_info;
- u8 buf = CYPRESS_LED_OFF;
- int ret;
- ret = i2c_smbus_write_byte_data(info->client, CYPRESS_GEN, buf);
- if (ret < 0) {
- dev_err(&info->client->dev,
- "[Touchkey] i2c write error [%d]\n", ret);
- }
- return ret;
- }
- static ssize_t touch_version_read(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- u8 data;
- int count;
- data = i2c_smbus_read_byte_data(info->client, CYPRESS_FW_VER);
- count = snprintf(buf, 20, "0x%02x\n", data);
- dev_dbg(&info->client->dev,
- "[TouchKey] %s : FW Ver 0x%02x\n", __func__, data);
- return count;
- }
- static ssize_t touch_version_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int count;
- count = snprintf(buf, 20, "0x%02x\n", BIN_FW_VERSION);
- return count;
- }
- static ssize_t touchkey_firm_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int count = 0;
- #if defined(CONFIG_MACH_JAGUAR)
- // char buff[16] = {0};
- #else
- char buff[16] = {0};
- #endif
- dev_dbg(&info->client->dev, "[TouchKey] touchkey_update_status: %d\n",
- info->touchkey_update_status);
- #if defined(CONFIG_MACH_JAGUAR)
- if (info->touchkey_update_status == 0)
- count = sprintf(buf, "PASS\n");
- else if (info->touchkey_update_status == 1)
- count = sprintf(buf, "Downloading\n");
- else if (info->touchkey_update_status == -1)
- count = sprintf(buf, "Fail\n");
- #else
- if (info->touchkey_update_status == 0)
- count = snprintf(buff, sizeof(buff), "PASS\n");
- else if (info->touchkey_update_status == 1)
- count = snprintf(buff, sizeof(buff), "Downloading\n");
- else if (info->touchkey_update_status == -1)
- count = snprintf(buff, sizeof(buff), "Fail\n");
- #endif
- return count;
- }
- static ssize_t touch_update_read(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int count = 0;
- char buff[16] = {0};
- dev_dbg(&info->client->dev, "[TouchKey] touchkey_update_read: %d\n",
- info->touchkey_update_status);
- if (info->touchkey_update_status == 0)
- count = snprintf(buff, sizeof(buff), "PASS\n");
- else if (info->touchkey_update_status == 1)
- count = snprintf(buff, sizeof(buff), "Downloading\n");
- else if (info->touchkey_update_status == -1)
- count = snprintf(buff, sizeof(buff), "Fail\n");
- return count;
- }
- static ssize_t touch_update_write(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t size)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int count = 0;
- int retry = NUM_OF_RETRY_UPDATE;
- char buff[16] = {0};
- u8 data;
- info->touchkey_update_status = 1;
- dev_err(dev, "[TOUCHKEY] touch_update_write!\n");
- disable_irq(info->irq);
- while (retry--) {
- if (ISSP_main() == 0) {
- dev_err(&info->client->dev,
- "[TOUCHKEY] Update success!\n");
- msleep(50);
- cypress_touchkey_auto_cal(info);
- info->touchkey_update_status = 0;
- count = 1;
- enable_irq(info->irq);
- break;
- }
- dev_err(&info->client->dev,
- "[TOUCHKEY] Touchkey_update failed... retry...\n");
- }
- if (retry <= 0) {
- if (info->pdata->gpio_led_en)
- cypress_touchkey_con_hw(info, false);
- msleep(300);
- count = 0;
- dev_err(&info->client->dev, "[TOUCHKEY]Touchkey_update fail\n");
- info->touchkey_update_status = -1;
- return count;
- }
- msleep(500);
- data = i2c_smbus_read_byte_data(info->client, CYPRESS_FW_VER);
- count = snprintf(buff, sizeof(buff), "0x%02x\n", data);
- dev_err(&info->client->dev,
- "[TouchKey] %s : FW Ver 0x%02x\n", __func__, data);
- return count;
- }
- static ssize_t touch_led_control(struct device *dev,
- struct device_attribute *attr, const char *buf,
- size_t size)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int data;
- dev_dbg(&info->client->dev, "called %s\n", __func__);
- data = kstrtoul(buf, (int)NULL, 0);
- if (data == 1) {
- if (data)
- cypress_touchkey_led_on(info);
- else
- cypress_touchkey_led_off(info);
- #if defined(SEC_TOUCHKEY_DEBUG)
- dev_dbg(&info->client->dev,
- "[TouchKey] touch_led_control : %d\n", data);
- #endif
- } else
- dev_dbg(&info->client->dev, "[TouchKey] touch_led_control Error\n");
- return size;
- }
- static ssize_t touch_sensitivity_control(struct device *dev,
- struct device_attribute *attr, const char *buf,
- size_t size)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int ret;
- ret = i2c_smbus_write_byte_data(info->client,
- CYPRESS_GEN, CYPRESS_DATA_UPDATE);
- if (ret < 0) {
- dev_err(&info->client->dev,
- "[Touchkey] fail to CYPRESS_DATA_UPDATE.\n");
- return ret;
- }
- msleep(150);
- return size;
- }
- static ssize_t touchkey_menu_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 menu_sensitivity;
- u8 data[2] = {0,};
- int ret;
- bool touchkey;
- touchkey = info->pdata->touchkey_order;
- ret = i2c_smbus_write_byte_data(info->client,
- CYPRESS_GEN, CYPRESS_DATA_UPDATE);
- if (ret < 0) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to write menu sensitivity.\n");
- return ret;
- }
- // if (machine_is_GOGH()) {
- // ret = i2c_smbus_read_i2c_block_data(info->client,
- // CYPRESS_DIFF_BACK, ARRAY_SIZE(data), data);
- // } else {
- ret = i2c_smbus_read_i2c_block_data(info->client,
- touchkey ? CYPRESS_DIFF_BACK : CYPRESS_DIFF_MENU,
- ARRAY_SIZE(data), data);
- // }
- if (ret != ARRAY_SIZE(data)) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to read menu sensitivity.\n");
- return ret;
- }
- menu_sensitivity = ((0x00FF & data[0])<<8) | data[1];
- dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
- __func__, data[0], data[1]);
- return snprintf(buf, 20, "%d\n", menu_sensitivity);
- }
- static ssize_t touchkey_back_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 back_sensitivity;
- u8 data[2] = {0,};
- int ret;
- bool touchkey;
- touchkey = info->pdata->touchkey_order;
- ret = i2c_smbus_write_byte_data(info->client,
- CYPRESS_GEN, CYPRESS_DATA_UPDATE);
- if (ret < 0) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to write back sensitivity.\n");
- return ret;
- }
- // if (machine_is_GOGH()) {
- // ret = i2c_smbus_read_i2c_block_data(info->client,
- // CYPRESS_DIFF_HOME, ARRAY_SIZE(data), data);
- // } else {
- ret = i2c_smbus_read_i2c_block_data(info->client,
- touchkey ? CYPRESS_DIFF_MENU : CYPRESS_DIFF_BACK,
- ARRAY_SIZE(data), data);
- // }
- if (ret != ARRAY_SIZE(data)) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to read back sensitivity.\n");
- return ret;
- }
- back_sensitivity = ((0x00FF & data[0])<<8) | data[1];
- dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
- __func__, data[0], data[1]);
- return snprintf(buf, 20, "%d\n", back_sensitivity);
- }
- #ifdef HOME_KEY_USE
- static ssize_t touchkey_home_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 home_sensitivity;
- u8 data[2] = {0,};
- int ret;
- ret = i2c_smbus_read_i2c_block_data(info->client,
- CYPRESS_DIFF_MENU, ARRAY_SIZE(data), data);
- if (ret != ARRAY_SIZE(data)) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to read home sensitivity.\n");
- return ret;
- }
- home_sensitivity = ((0x00FF & data[0])<<8) | data[1];
- dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
- __func__, data[0], data[1]);
- return snprintf(buf, 20, "%d\n", home_sensitivity);
- }
- #endif
- static ssize_t touchkey_raw_data0_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u16 raw_data0;
- u8 data[2] = {0,};
- int ret;
- bool touchkey;
- touchkey = info->pdata->touchkey_order;
- // if (machine_is_GOGH()) {
- // ret = i2c_smbus_read_i2c_block_data(info->client,
- // CYPRESS_RAW_DATA_MENU, ARRAY_SIZE(data), data);
- // } else {
- ret = i2c_smbus_read_i2c_block_data(info->client,
- touchkey ? CYPRESS_RAW_DATA_BACK : CYPRESS_RAW_DATA_MENU,
- ARRAY_SIZE(data), data);
- // }
- if (ret != ARRAY_SIZE(data)) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to read MENU raw data.\n");
- return ret;
- }
- raw_data0 = ((0x00FF & data[0])<<8) | data[1];
- dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
- __func__, data[0], data[1]);
- return snprintf(buf, 20, "%d\n", raw_data0);
- }
- static ssize_t touchkey_raw_data1_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u16 raw_data1;
- u8 data[2] = {0,};
- int ret;
- bool touchkey;
- touchkey = info->pdata->touchkey_order;
- // if (machine_is_GOGH()) {
- // ret = i2c_smbus_read_i2c_block_data(info->client,
- // CYPRESS_RAW_DATA_BACK_GOGH, ARRAY_SIZE(data), data);
- // } else {
- ret = i2c_smbus_read_i2c_block_data(info->client,
- touchkey ? CYPRESS_RAW_DATA_MENU : CYPRESS_RAW_DATA_BACK,
- ARRAY_SIZE(data), data);
- // }
- if (ret != ARRAY_SIZE(data)) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to read HOME raw data.\n");
- return ret;
- }
- raw_data1 = ((0x00FF & data[0])<<8) | data[1];
- dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
- __func__, data[0], data[1]);
- return snprintf(buf, 20, "%d\n", raw_data1);
- }
- #ifdef HOME_KEY_USE
- static ssize_t touchkey_raw_data2_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u16 raw_data1;
- u8 data[2] = {0,};
- int ret;
- ret = i2c_smbus_read_i2c_block_data(info->client,
- CYPRESS_RAW_DATA_HOME, ARRAY_SIZE(data), data);
- if (ret != ARRAY_SIZE(data)) {
- dev_err(&info->client->dev,
- "[TouchKey] fail to read HOME raw data.\n");
- return ret;
- }
- raw_data1 = ((0x00FF & data[0])<<8) | data[1];
- dev_dbg(&info->client->dev, "called %s , data : %d %d\n",
- __func__, data[0], data[1]);
- return snprintf(buf, 20, "%d\n", raw_data1);
- }
- #endif
- static ssize_t touchkey_idac0_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 idac0;
- u8 data = 0;
- bool touchkey;
- touchkey = info->pdata->touchkey_order;
- // if (machine_is_GOGH()) {
- // data = i2c_smbus_read_byte_data(info->client,
- // CYPRESS_IDAC_BACK);
- // } else {
- data = i2c_smbus_read_byte_data(info->client,
- touchkey ? CYPRESS_IDAC_BACK : CYPRESS_IDAC_MENU);
- // }
- dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
- idac0 = data;
- return snprintf(buf, 20, "%d\n", idac0);
- }
- static ssize_t touchkey_idac1_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 idac1;
- u8 data = 0;
- bool touchkey;
- touchkey = info->pdata->touchkey_order;
- // if (machine_is_GOGH()) {
- // data = i2c_smbus_read_byte_data(info->client,
- // CYPRESS_IDAC_MENU);
- // } else {
- data = i2c_smbus_read_byte_data(info->client,
- touchkey ? CYPRESS_IDAC_MENU : CYPRESS_IDAC_BACK);
- // }
- dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
- idac1 = data;
- return snprintf(buf, 20, "%d\n", idac1);
- }
- #ifdef HOME_KEY_USE
- static ssize_t touchkey_idac2_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 idac1;
- u8 data = 0;
- data = i2c_smbus_read_byte_data(info->client, CYPRESS_IDAC_HOME);
- dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
- idac1 = data;
- return snprintf(buf, 20, "%d\n", idac1);
- }
- #endif
- static ssize_t touchkey_threshold_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- static u8 touchkey_threshold;
- u8 data = 0;
- data = i2c_smbus_read_byte_data(info->client, CYPRESS_THRESHOLD);
- dev_dbg(&info->client->dev, "called %s , data : %d\n", __func__, data);
- touchkey_threshold = data;
- return snprintf(buf, 20, "%d\n", touchkey_threshold);
- }
- static ssize_t touch_autocal_testmode(struct device *dev,
- struct device_attribute *attr, const char *buf,
- size_t size)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int count = 0;
- int on_off;
- if (sscanf(buf, "%2d\n", &on_off) == 1) {
- printk(KERN_ERR "[TouchKey] Test Mode : %d\n", on_off);
- if (on_off == 1) {
- count = i2c_smbus_write_byte_data(info->client,
- CYPRESS_GEN, CYPRESS_DATA_UPDATE);
- }
- } else {
- if (info->pdata->gpio_led_en) {
- cypress_touchkey_con_hw(info, false);
- msleep(50);
- cypress_touchkey_con_hw(info, true);
- msleep(50);
- }
- cypress_touchkey_auto_cal(info);
- }
- return count;
- }
- static ssize_t autocalibration_enable(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t size)
- {
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- int data;
- sscanf(buf, "%2d\n", &data);
- if (data == 1)
- cypress_touchkey_auto_cal(info);
- return 0;
- }
- static ssize_t autocalibration_status(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- u8 data[6];
- struct cypress_touchkey_info *info = dev_get_drvdata(dev);
- printk(KERN_DEBUG "[Touchkey] %s\n", __func__);
- i2c_smbus_read_i2c_block_data(info->client, CYPRESS_GEN, 6, data);
- if ((data[5] & 0x80))
- return sprintf(buf, "Enabled\n");
- else
- return sprintf(buf, "Disabled\n");
- }
- static DEVICE_ATTR(touchkey_firm_update_status,
- S_IRUGO | S_IWUSR | S_IWGRP, touchkey_firm_status_show, NULL);
- static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO,
- touch_version_read, NULL);
- static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO,
- touch_version_show, NULL);
- static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP,
- touch_update_read, touch_update_write);
- static DEVICE_ATTR(touchkey_brightness, S_IRUGO,
- NULL, touch_led_control);
- static DEVICE_ATTR(touch_sensitivity, S_IRUGO | S_IWUSR | S_IWGRP,
- NULL, touch_sensitivity_control);
- static DEVICE_ATTR(touchkey_menu, S_IRUGO, touchkey_menu_show, NULL);
- static DEVICE_ATTR(touchkey_back, S_IRUGO, touchkey_back_show, NULL);
- #ifdef HOME_KEY_USE
- static DEVICE_ATTR(touchkey_home, S_IRUGO, touchkey_home_show, NULL);
- #endif
- static DEVICE_ATTR(touchkey_raw_data0, S_IRUGO, touchkey_raw_data0_show, NULL);
- static DEVICE_ATTR(touchkey_raw_data1, S_IRUGO, touchkey_raw_data1_show, NULL);
- #ifdef HOME_KEY_USE
- static DEVICE_ATTR(touchkey_raw_data2, S_IRUGO, touchkey_raw_data2_show, NULL);
- #endif
- static DEVICE_ATTR(touchkey_idac0, S_IRUGO, touchkey_idac0_show, NULL);
- static DEVICE_ATTR(touchkey_idac1, S_IRUGO, touchkey_idac1_show, NULL);
- #ifdef HOME_KEY_USE
- static DEVICE_ATTR(touchkey_idac2, S_IRUGO, touchkey_idac2_show, NULL);
- #endif
- static DEVICE_ATTR(touchkey_threshold, S_IRUGO, touchkey_threshold_show, NULL);
- static DEVICE_ATTR(touchkey_autocal_start, S_IRUGO | S_IWUSR | S_IWGRP,
- NULL, touch_autocal_testmode);
- static DEVICE_ATTR(autocal_enable, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
- autocalibration_enable);
- static DEVICE_ATTR(autocal_stat, S_IRUGO | S_IWUSR | S_IWGRP,
- autocalibration_status, NULL);
- static DEVICE_ATTR(touchkey_brightness_level, S_IRUGO | S_IWUSR | S_IWGRP,
- brightness_level_show, brightness_control);
- #ifdef CONFIG_OF
- static void cypress_request_gpio(struct cypress_touchkey_platform_data *pdata)
- {
- int ret;
- ret = gpio_request(pdata->gpio_scl, "touchkey_scl");
- if (ret) {
- printk(KERN_ERR "%s: unable to request touchkey_scl [%d]\n",
- __func__, pdata->gpio_scl);
- return;
- }
- gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
- ret = gpio_request(pdata->gpio_sda, "touchkey_sda");
- if (ret) {
- printk(KERN_ERR "%s: unable to request touchkey_sda [%d]\n",
- __func__, pdata->gpio_sda);
- return;
- }
- gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 3, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
- ret = gpio_request(pdata->gpio_int, "touchkey_irq");
- if (ret) {
- printk(KERN_ERR "%s: unable to request touchkey_irq [%d]\n",
- __func__, pdata->gpio_int);
- return;
- }
- ret = gpio_request(pdata->vdd_en, "melfas_vdd_en");
- if (ret) {
- pr_err("[TKEY]%s: unable to request melfas_vdd_en [%d]\n",
- __func__, pdata->vdd_en);
- return;
- }
- if (pdata->vdd_led > 0) {
- ret = gpio_request(pdata->vdd_led, "touchkey_vdd_led");
- if (ret) {
- printk(KERN_ERR "%s: unable to request touchkey_vdd_led [%d]\n",
- __func__, pdata->vdd_led);
- return;
- }
- }
- }
- static int cypress_get_keycodes(struct device *dev, char *name,
- struct cypress_touchkey_platform_data *pdata)
- {
- struct property *prop;
- struct device_node *np = dev->of_node;
- int rc;
- prop = of_find_property(np, name, NULL);
- if (!prop)
- return -EINVAL;
- if (!prop->value)
- return -ENODATA;
- pdata->keycodes_size = prop->length / sizeof(u32);
- rc = of_property_read_u32_array(np, name, pdata->touchkey_keycode,
- pdata->keycodes_size);
- if (rc && (rc != -EINVAL)) {
- dev_info(dev, "%s: Unable to read %s\n", __func__, name);
- return rc;
- }
- return 0;
- }
- static int cypress_parse_dt(struct device *dev,
- struct cypress_touchkey_platform_data *pdata)
- {
- int rc;
- struct device_node *np = dev->of_node;
- rc = cypress_get_keycodes(dev, "cypress,tkey-keycodes", pdata);
- if (rc)
- return rc;
- /* regulator info */
- pdata->i2c_pull_up = of_property_read_bool(np, "cypress,i2c-pull-up");
- pdata->vdd_led = of_get_named_gpio(np, "vdd_led-gpio", 0);
- pdata->vdd_en = of_get_named_gpio(np, "vdd_en-gpio", 0);
- /* reset, irq gpio info */
- pdata->gpio_scl = of_get_named_gpio_flags(np, "cypress,scl-gpio",
- 0, &pdata->scl_gpio_flags);
- pdata->gpio_sda = of_get_named_gpio_flags(np, "cypress,sda-gpio",
- 0, &pdata->sda_gpio_flags);
- pdata->gpio_int = of_get_named_gpio_flags(np, "cypress,irq-gpio",
- 0, &pdata->irq_gpio_flags);
- return 0;
- }
- #else
- static int cypress_parse_dt(struct device *dev,
- struct cypress_touchkey_platform_data *pdata)
- {
- return -ENODEV;
- }
- #endif
- static int __devinit cypress_touchkey_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
- {
- struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
- struct cypress_touchkey_platform_data *pdata =
- client->dev.platform_data;
- struct cypress_touchkey_info *info;
- struct input_dev *input_dev;
- int ret = 0;
- int i;
- // int retry = NUM_OF_RETRY_UPDATE;
- int ic_fw_ver;
- int error;
- struct device *sec_touchkey;
- printk("[TKEY] %s _ %d\n",__func__,__LINE__);
- if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
- return -EIO;
- #ifdef CONFIG_OF
- if (client->dev.of_node) {
- pdata = devm_kzalloc(&client->dev,
- sizeof(struct cypress_touchkey_platform_data),
- GFP_KERNEL);
- if (!pdata) {
- dev_info(&client->dev, "Failed to allocate memory\n");
- return -ENOMEM;
- }
- error = cypress_parse_dt(&client->dev, pdata);
- if (error)
- return error;
- } else
- pdata = client->dev.platform_data;
- cypress_request_gpio(pdata);
- #endif
- info = kzalloc(sizeof(*info), GFP_KERNEL);
- if (!info) {
- dev_err(&client->dev, "fail to memory allocation.\n");
- goto err_mem_alloc;
- }
- input_dev = input_allocate_device();
- if (!input_dev) {
- dev_err(&client->dev, "fail to allocate input device.\n");
- goto err_input_dev_alloc;
- }
- client->irq = gpio_to_irq(pdata->gpio_int);
- info->client = client;
- info->input_dev = input_dev;
- info->pdata = pdata;
- info->irq = client->irq;
- info->touchkey_update_status = 0;
-
- input_dev->name = "sec_touchkey";
- input_dev->phys = info->phys;
- input_dev->id.bustype = BUS_I2C;
- input_dev->dev.parent = &client->dev;
- info->is_powering_on = true;
- cypress_power_onoff(info, 1);
- msleep(50);
- set_bit(EV_SYN, input_dev->evbit);
- set_bit(EV_KEY, input_dev->evbit);
- set_bit(EV_LED, input_dev->evbit);
- set_bit(LED_MISC, input_dev->ledbit);
- for (i = 0; i < pdata->keycodes_size; i++) {
- info->keycode[i] = pdata->touchkey_keycode[i];
- set_bit(info->keycode[i], input_dev->keybit);
- }
- input_set_drvdata(input_dev, info);
- mutex_init(&info->touchkey_mutex);
- ret = input_register_device(input_dev);
- if (ret) {
- dev_err(&client->dev, "[TOUCHKEY] failed to register input dev (%d).\n",
- ret);
- goto err_reg_input_dev;
- }
- i2c_set_clientdata(client, info);
- if (info->pdata->gpio_led_en) {
- ret = gpio_request(info->pdata->gpio_led_en,
- "gpio_touchkey_led");
- if (ret < 0) {
- dev_err(&client->dev,
- "gpio_touchkey_led gpio_request is failed\n");
- goto err_gpio_request;
- }
- gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_led_en, 0,
- GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
- cypress_touchkey_con_hw(info, true);
- }
- #ifdef USE_OPEN_CLOSE
- input_dev->open = cypress_input_open;
- input_dev->close = cypress_input_close;
- #endif
- dev_info(&info->client->dev, "gpio_to_irq IRQ %d\n",
- client->irq);
- ret = request_threaded_irq(client->irq, NULL,
- cypress_touchkey_interrupt,
- IRQF_TRIGGER_FALLING, client->dev.driver->name, info);
- if (ret < 0) {
- dev_err(&client->dev, "Failed to request IRQ %d (err: %d).\n",
- client->irq, ret);
- goto err_req_irq;
- }
- #ifdef CONFIG_HAS_EARLYSUSPEND
- info->early_suspend.suspend = cypress_touchkey_early_suspend;
- info->early_suspend.resume = cypress_touchkey_late_resume;
- register_early_suspend(&info->early_suspend);
- #endif /* CONFIG_HAS_EARLYSUSPEND */
- info->led_wq = create_singlethread_workqueue("cypress_touchkey");
- INIT_WORK(&info->led_work, cypress_touchkey_led_work);
- info->leds.name = TOUCHKEY_BACKLIGHT;
- info->leds.brightness = LED_FULL;
- info->leds.max_brightness = LED_FULL;
- info->leds.brightness_set = cypress_touchkey_brightness_set;
- ret = led_classdev_register(&client->dev, &info->leds);
- if (ret)
- goto err_req_irq;
- #if defined(CONFIG_LCD_CONNECTION_CHECK) //for SMD test
- if (is_lcd_attached() == 0) {
- disable_irq(client->irq);
- printk("[TSK] %s : is_lcd_attached()=0 \n",__func__);
-
- }
- else{
- #endif
- msleep(20);
- ic_fw_ver = i2c_smbus_read_byte_data(client, CYPRESS_FW_VER);
- dev_err(&client->dev, "Touchkey FW Version: 0x%02x\n", ic_fw_ver);
- #if defined(CONFIG_MACH_M2_ATT) || defined(CONFIG_MACH_M2_DCM) \
- || defined(CONFIG_MACH_M2_SKT) || defined(CONFIG_MACH_M2_KDI)
- dev_err(&client->dev, "Touchkey FW Version: 0x%02x, system_rev: %x\n",
- ic_fw_ver, system_rev);
- if (0 /* ic_fw_ver < BIN_FW_VERSION */) {
- dev_err(&client->dev, "[TOUCHKEY] touchkey_update Start!!\n");
- disable_irq(client->irq);
- while (retry--) {
- if (ISSP_main() == 0) {
- dev_err(&client->dev, "[TOUCHKEY] Update success!\n");
- enable_irq(client->irq);
- break;
- }
- dev_err(&client->dev,
- "[TOUCHKEY] Touchkey_update failed... retry...\n");
- }
- if (retry <= 0) {
- if (info->pdata->gpio_led_en)
- cypress_touchkey_con_hw(info, false);
- msleep(300);
- dev_err(&client->dev, "[TOUCHKEY]Touchkey_update fail\n");
- }
- msleep(500);
- ic_fw_ver = i2c_smbus_read_byte_data(info->client,
- CYPRESS_FW_VER);
- dev_err(&client->dev,
- "[TouchKey] %s : FW Ver 0x%02x\n", __func__, ic_fw_ver);
- } else {
- dev_err(&client->dev, "[TouchKey] FW update does not need!\n");
- }
- #endif
- cypress_touchkey_auto_cal(info);
- #if defined(CONFIG_LCD_CONNECTION_CHECK) //for SMD test
- }
- #endif
- sec_touchkey = device_create(sec_class, NULL, 0, NULL, "sec_touchkey");
- if (IS_ERR(sec_touchkey)) {
- pr_err("Failed to create device(sec_touchkey)!\n");
- goto err_sysfs;
- }
- dev_set_drvdata(sec_touchkey, info);
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_firm_update_status) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_firm_update.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_firm_update) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_firm_update.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_firm_version_panel) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_firm_version_panel.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_firm_version_phone) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_firm_version_phone.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_brightness) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_brightness.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touch_sensitivity) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touch_sensitivity.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_menu) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_menu.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_back) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_back.attr.name);
- goto err_sysfs;
- }
- #ifdef HOME_KEY_USE
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_home) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_home.attr.name);
- goto err_sysfs;
- }
- #endif
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_raw_data0) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_raw_data0.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_raw_data1) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_raw_data1.attr.name);
- goto err_sysfs;
- }
- #ifdef HOME_KEY_USE
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_raw_data2) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_raw_data2.attr.name);
- goto err_sysfs;
- }
- #endif
- if (device_create_file(sec_touchkey, &dev_attr_touchkey_idac0) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_idac0.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey, &dev_attr_touchkey_idac1) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_idac1.attr.name);
- goto err_sysfs;
- }
- #ifdef HOME_KEY_USE
- if (device_create_file(sec_touchkey, &dev_attr_touchkey_idac2) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_idac2.attr.name);
- goto err_sysfs;
- }
- #endif
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_threshold) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_threshold.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_autocal_start) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_touchkey_autocal_start.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_autocal_enable) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_autocal_enable.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_autocal_stat) < 0) {
- pr_err("Failed to create device file(%s)!\n",
- dev_attr_autocal_stat.attr.name);
- goto err_sysfs;
- }
- if (device_create_file(sec_touchkey,
- &dev_attr_touchkey_brightness_level) < 0) {
- printk(KERN_ERR "Failed to create device file(%s)!\n",
- dev_attr_touchkey_brightness_level.attr.name);
- goto err_sysfs;
- }
- info->is_powering_on = false;
- return 0;
- err_req_irq:
- err_gpio_request:
- input_unregister_device(input_dev);
- err_reg_input_dev:
- input_free_device(input_dev);
- input_dev = NULL;
- mutex_destroy(&info->touchkey_mutex);
- err_input_dev_alloc:
- kfree(info);
- err_sysfs:
- return -ENXIO;
- err_mem_alloc:
- return ret;
- }
- static int __devexit cypress_touchkey_remove(struct i2c_client *client)
- {
- struct cypress_touchkey_info *info = i2c_get_clientdata(client);
- if (info->irq >= 0)
- free_irq(info->irq, info);
- mutex_destroy(&info->touchkey_mutex);
- led_classdev_unregister(&info->leds);
- input_unregister_device(info->input_dev);
- input_free_device(info->input_dev);
- kfree(info);
- return 0;
- }
- #if defined(CONFIG_PM) || defined(CONFIG_HAS_EARLYSUSPEND)
- static int cypress_touchkey_suspend(struct device *dev)
- {
- struct i2c_client *client = to_i2c_client(dev);
- struct cypress_touchkey_info *info = i2c_get_clientdata(client);
- int ret = 0;
- info->is_powering_on = true;
- disable_irq(info->irq);
- if (info->pdata->gpio_led_en)
- cypress_touchkey_con_hw(info, false);
- cypress_power_onoff(info, 0);
- return ret;
- }
- static int cypress_touchkey_resume(struct device *dev)
- {
- struct i2c_client *client = to_i2c_client(dev);
- struct cypress_touchkey_info *info = i2c_get_clientdata(client);
- int ret = 0;
- cypress_power_onoff(info, 1);
- if (info->pdata->gpio_led_en)
- cypress_touchkey_con_hw(info, true);
- msleep(50);
- cypress_touchkey_auto_cal(info);
- if (touchled_cmd_reversed) {
- touchled_cmd_reversed = 0;
- i2c_smbus_write_byte_data(info->client,
- CYPRESS_GEN, touchkey_led_status);
- printk(KERN_DEBUG "LED returned on\n");
- }
- enable_irq(info->irq);
- info->is_powering_on = false;
- return ret;
- }
- #endif
- #ifdef CONFIG_HAS_EARLYSUSPEND
- static void cypress_touchkey_early_suspend(struct early_suspend *h)
- {
- struct cypress_touchkey_info *info;
- info = container_of(h, struct cypress_touchkey_info, early_suspend);
- cypress_touchkey_suspend(&info->client->dev);
- }
- static void cypress_touchkey_late_resume(struct early_suspend *h)
- {
- struct cypress_touchkey_info *info;
- info = container_of(h, struct cypress_touchkey_info, early_suspend);
- cypress_touchkey_resume(&info->client->dev);
- }
- #endif
- static const struct i2c_device_id cypress_touchkey_id[] = {
- {"cypress_touchkey", 0},
- {}
- };
- MODULE_DEVICE_TABLE(i2c, cypress_touchkey_id);
- #ifdef CONFIG_OF
- static struct of_device_id cypress_match_table[] = {
- { .compatible = "cypress,cypress-tkey",},
- { },
- };
- #else
- #define cypress_match_table NULL
- #endif
- #ifdef USE_OPEN_CLOSE
- static int cypress_input_open(struct input_dev *dev)
- {
- struct cypress_touchkey_info *info = input_get_drvdata(dev);
- dev_info(&info->client->dev, "%s.\n", __func__);
- cypress_touchkey_resume(&info->client->dev);
- gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
- gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
- return 0;
- }
- static void cypress_input_close(struct input_dev *dev)
- {
- struct cypress_touchkey_info *info = input_get_drvdata(dev);
- dev_info(&info->client->dev, "%s.\n", __func__);
-
- gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_scl, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
- gpio_tlmm_config(GPIO_CFG(info->pdata->gpio_sda, 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), 1);
- cypress_touchkey_suspend(&info->client->dev);
- }
- #endif
- #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
- static const struct dev_pm_ops cypress_touchkey_pm_ops = {
- .suspend = cypress_touchkey_suspend,
- .resume = cypress_touchkey_resume,
- };
- #endif
- struct i2c_driver cypress_touchkey_driver = {
- .probe = cypress_touchkey_probe,
- .remove = cypress_touchkey_remove,
- .driver = {
- .name = "cypress_touchkey",
- #ifdef CONFIG_OF
- .of_match_table = cypress_match_table,
- #endif
- #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND) && !defined(USE_OPEN_CLOSE)
- .pm = &cypress_touchkey_pm_ops,
- #endif
- },
- .id_table = cypress_touchkey_id,
- };
- module_i2c_driver(cypress_touchkey_driver);
- /*t cypress_touchkey_init(void)
- {
- int ret = 0;
- ret = i2c_add_driver(&cypress_touchkey_driver);
- if (ret) {
- pr_err("[TouchKey] cypress touch keypad registration failed. ret= %d\n",
- ret);
- }
- return ret;
- }
- static void __exit cypress_touchkey_exit(void)
- {
- i2c_del_driver(&cypress_touchkey_driver);
- }
- late_initcall(cypress_touchkey_init);
- module_exit(cypress_touchkey_exit);
- */
- MODULE_DESCRIPTION("Touchkey driver for Cypress touchkey controller ");
- MODULE_LICENSE("GPL");
|