2 * Copyright (C) 2010,Imagis Technology Co. Ltd. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 #include <linux/mutex.h>
18 #include <linux/i2c.h>
19 #include <linux/delay.h>
20 #include <linux/slab.h>
21 #include <linux/input.h>
22 #include <linux/stat.h>
23 #include <linux/err.h>
26 #include "ist30xx_update.h"
27 #include "ist30xx_misc.h"
30 static char IsfwUpdate[20] = { 0 };
32 #define FW_DOWNLOADING "Downloading"
33 #define FW_DOWNLOAD_COMPLETE "Complete"
34 #define FW_DOWNLOAD_FAIL "FAIL"
36 #define FACTORY_BUF_SIZE (1024)
40 #define CMD_STATE_WAITING (0)
41 #define CMD_STATE_RUNNING (1)
42 #define CMD_STATE_OK (2)
43 #define CMD_STATE_FAIL (3)
44 #define CMD_STATE_NA (4)
46 #define TSP_NODE_DEBUG (1)
48 static u16 node_value[TSP_TOTAL_NUM];
50 extern struct ist30xx_data *ts_data;
51 extern TSP_INFO ist30xx_tsp_info;
52 extern TKEY_INFO ist30xx_tkey_info;
55 #define TSP_CMD(name, func) .cmd_name = name, .cmd_func = func
57 struct list_head list;
58 const char * cmd_name;
59 void (*cmd_func)(void *dev_data);
62 u32 ist30xxb_get_fw_ver(struct ist30xx_data *data)
64 u32 addr = data->tags.cfg_addr + 4;
69 ist30xx_disable_irq(data);
70 ret = ist30xx_cmd_reg(data->client, CMD_ENTER_REG_ACCESS);
74 ret = ist30xx_write_cmd(data->client, IST30XX_RX_CNT_ADDR, len);
78 ret = ist30xx_read_cmd(data->client, addr, &ver);
82 tsp_debug("Reg addr: %x, ver: %x\n", addr, ver);
84 ret = ist30xx_cmd_reg(data->client, CMD_EXIT_REG_ACCESS);
92 ist30xx_cmd_start_scan(data->client);
93 ist30xx_enable_irq(data);
98 u32 key_sensitivity = 0;
99 int ist30xxb_get_key_sensitivity(struct ist30xx_data *data, int id)
101 u32 addr = IST30XXB_MEM_KEYSENSITIVITY + 4 * sizeof(u32);
104 if (unlikely(id >= ist30xx_tkey_info.key_num))
107 if (ist30xx_intr_wait(30) < 0)
110 ist30xx_read_cmd(data->client, addr, &val);
111 if ((val & 0xFFF) == 0xFFF)
112 return (key_sensitivity >> (16 * id)) & 0xFFFF;
114 key_sensitivity = val;
116 tsp_debug("Reg addr: %x, val: %8x\n", addr, val);
120 return (int)(val & 0xFFFF);
124 /* Factory CMD function */
125 static void set_default_result(struct sec_factory *sec)
129 memset(sec->cmd_result, 0, ARRAY_SIZE(sec->cmd_result));
130 memcpy(sec->cmd_result, sec->cmd, strlen(sec->cmd));
131 strncat(sec->cmd_result, &delim, CMD_STATE_RUNNING);
134 static void set_cmd_result(struct sec_factory *sec, char *buf, int len)
136 strncat(sec->cmd_result, buf, len);
139 static void not_support_cmd(void *dev_data)
141 char buf[16] = { 0 };
143 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
144 struct sec_factory *sec = (struct sec_factory *)&data->sec;
146 set_default_result(sec);
147 snprintf(buf, sizeof(buf), "%s", "NA");
148 tsp_info("%s(), %s\n", __func__, buf);
150 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
151 sec->cmd_state = CMD_STATE_NA;
152 dev_info(&data->client->dev, "%s: \"%s(%d)\"\n", __func__,
153 buf, strnlen(buf, sizeof(buf)));
157 static void get_chip_vendor(void *dev_data)
159 char buf[16] = { 0 };
161 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
162 struct sec_factory *sec = (struct sec_factory *)&data->sec;
164 set_default_result(sec);
165 snprintf(buf, sizeof(buf), "%s", TSP_CHIP_VENDOR);
166 tsp_info("%s(), %s\n", __func__, buf);
168 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
169 sec->cmd_state = CMD_STATE_OK;
170 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__,
171 buf, strnlen(buf, sizeof(buf)));
174 static void get_chip_name(void *dev_data)
176 char buf[16] = { 0 };
178 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
179 struct sec_factory *sec = (struct sec_factory *)&data->sec;
181 set_default_result(sec);
182 snprintf(buf, sizeof(buf), "%s", TSP_CHIP_NAME);
183 tsp_info("%s(), %s\n", __func__, buf);
185 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
186 sec->cmd_state = CMD_STATE_OK;
187 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__,
188 buf, strnlen(buf, sizeof(buf)));
191 static void get_chip_id(void *dev_data)
193 char buf[16] = { 0 };
195 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
196 struct sec_factory *sec = (struct sec_factory *)&data->sec;
198 set_default_result(sec);
199 snprintf(buf, sizeof(buf), "%#02x", data->chip_id);
200 tsp_info("%s(), %s\n", __func__, buf);
202 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
203 sec->cmd_state = CMD_STATE_OK;
204 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__,
205 buf, strnlen(buf, sizeof(buf)));
207 #include <linux/uaccess.h>
208 #define MAX_FW_PATH 255
209 extern u32 ist30xx_fw_ver;
210 extern u32 ist30xx_param_ver;
211 extern u32 ist30xx_sub_ver;
212 static void fw_update(void *dev_data)
215 char buf[16] = { 0 };
216 mm_segment_t old_fs = {0};
217 struct file *fp = NULL;
218 long fsize = 0, nread = 0;
220 char fw_path[MAX_FW_PATH+1];
222 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
223 struct sec_factory *sec = (struct sec_factory *)&data->sec;
225 set_default_result(sec);
227 tsp_info("%s(), %d\n", __func__, sec->cmd_param[0]);
229 switch (sec->cmd_param[0]) {
231 sec->cmd_state = CMD_STATE_OK;
232 ret = ist30xx_fw_recovery(data);
234 sec->cmd_state = CMD_STATE_FAIL;
237 sec->cmd_state = CMD_STATE_OK;
241 snprintf(fw_path, MAX_FW_PATH, "/sdcard/%s", IST30XXB_FW_NAME);
242 fp = filp_open(fw_path, O_RDONLY, 0);
244 tsp_warn("%s(), file %s open error:%d\n", __func__,
246 sec->cmd_state= CMD_STATE_FAIL;
251 fsize = fp->f_path.dentry->d_inode->i_size;
252 if (fsize != data->fw.buf_size) {
253 tsp_warn("%s(), invalid fw size!!\n", __func__);
254 sec->cmd_state = CMD_STATE_FAIL;
258 fw = kzalloc((size_t)fsize, GFP_KERNEL);
260 tsp_warn("%s(), failed to alloc buffer for fw\n", __func__);
261 sec->cmd_state = CMD_STATE_FAIL;
262 filp_close(fp, NULL);
266 nread = vfs_read(fp, (char __user *)fw, fsize, &fp->f_pos);
267 if (nread != fsize) {
268 tsp_warn("%s(), failed to read fw\n", __func__);
269 sec->cmd_state = CMD_STATE_FAIL;
270 filp_close(fp, NULL);
275 filp_close(fp, current->files);
277 tsp_info("%s(), ums fw is loaded!!\n", __func__);
279 ist30xx_get_update_info(ts_data, fw, fsize);
280 ist30xx_fw_ver = ist30xx_parse_ver(FLAG_FW, fw);
281 ist30xx_param_ver = ist30xx_parse_ver(FLAG_PARAM, fw);
282 ist30xx_sub_ver = ist30xx_parse_ver(FLAG_SUB, fw);
284 mutex_lock(&ist30xx_mutex);
285 ist30xx_fw_update(data->client, fw, fsize, true);
286 mutex_unlock(&ist30xx_mutex);
288 ist30xx_calibrate(1);
292 tsp_warn("%s(), Invalid fw file type!\n", __func__);
296 if (sec->cmd_state == CMD_STATE_OK)
297 snprintf(buf, sizeof(buf), "%s", "OK");
299 snprintf(buf, sizeof(buf), "%s", "NG");
301 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
305 static void get_fw_ver_bin(void *dev_data)
308 char buf[16] = { 0 };
310 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
311 struct sec_factory *sec = (struct sec_factory *)&data->sec;
313 set_default_result(sec);
315 ver = ist30xx_parse_ver(FLAG_PARAM, data->fw.buf);
316 snprintf(buf, sizeof(buf), "IM00%04x", ver);
317 tsp_info("%s(), %s\n", __func__, buf);
319 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
320 sec->cmd_state = CMD_STATE_OK;
321 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__,
322 buf, strnlen(buf, sizeof(buf)));
325 static void get_fw_ver_ic(void *dev_data)
329 char buf[16] = { 0 };
331 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
332 struct sec_factory *sec = (struct sec_factory *)&data->sec;
334 set_default_result(sec);
336 if (data->status.power == 1)
337 ver = ist30xxb_get_fw_ver(ts_data);
339 snprintf(buf, sizeof(buf), "IM00%04x", ver & 0xFFFF);
341 if (data->fw.sub_ver > 0) {
342 sprintf(msg, "(T%d)", data->fw.sub_ver);
346 tsp_info("%s(), %s\n", __func__, buf);
348 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
349 sec->cmd_state = CMD_STATE_OK;
350 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__,
351 buf, strnlen(buf, sizeof(buf)));
354 static void get_threshold(void *dev_data)
356 char buf[16] = { 0 };
360 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
361 struct sec_factory *sec = (struct sec_factory *)&data->sec;
363 set_default_result(sec);
365 ist30xx_get_update_info(data, data->fw.buf, data->fw.buf_size);
366 cfg_buf = (u32 *)&data->fw.buf[data->tags.cfg_addr];
368 threshold = (int)(cfg_buf[0x2C / IST30XX_DATA_LEN] & 0xFFFF);
370 snprintf(buf, sizeof(buf), "%d", threshold);
371 tsp_info("%s(), %s\n", __func__, buf);
373 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
374 sec->cmd_state = CMD_STATE_OK;
375 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__,
376 buf, strnlen(buf, sizeof(buf)));
379 static void get_x_num(void *dev_data)
381 int val = ist30xx_tsp_info.width;
382 char buf[16] = { 0 };
384 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
385 struct sec_factory *sec = (struct sec_factory *)&data->sec;
387 set_default_result(sec);
390 snprintf(buf, sizeof(buf), "%u", val);
391 sec->cmd_state = CMD_STATE_OK;
392 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__, buf,
393 strnlen(buf, sizeof(buf)));
395 snprintf(buf, sizeof(buf), "%s", "NG");
396 sec->cmd_state = CMD_STATE_FAIL;
397 dev_info(&data->client->dev,
398 "%s: fail to read num of x (%d).\n", __func__, val);
400 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
401 tsp_info("%s(), %s\n", __func__, buf);
404 static void get_y_num(void *dev_data)
406 int val = ist30xx_tsp_info.height;
407 char buf[16] = { 0 };
409 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
410 struct sec_factory *sec = (struct sec_factory *)&data->sec;
412 set_default_result(sec);
415 snprintf(buf, sizeof(buf), "%u", val);
416 sec->cmd_state = CMD_STATE_OK;
417 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__, buf,
418 strnlen(buf, sizeof(buf)));
420 snprintf(buf, sizeof(buf), "%s", "NG");
421 sec->cmd_state = CMD_STATE_FAIL;
422 dev_info(&data->client->dev,
423 "%s: fail to read num of x (%d).\n", __func__, val);
425 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
426 tsp_info("%s(), %s\n", __func__, buf);
429 int check_tsp_channel(void *dev_data)
433 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
434 struct sec_factory *sec = (struct sec_factory *)&data->sec;
435 TSP_INFO *tsp = &ist30xx_tsp_info;
437 if ((sec->cmd_param[0] < 0) || (sec->cmd_param[0] >= tsp->width) ||
438 (sec->cmd_param[1] < 0) || (sec->cmd_param[1] >= tsp->height)) {
439 dev_info(&data->client->dev, "%s: parameter error: %u,%u\n",
440 __func__, sec->cmd_param[0], sec->cmd_param[1]);
442 node = sec->cmd_param[0] + sec->cmd_param[1] * tsp->width;
443 dev_info(&data->client->dev, "%s: node = %d\n", __func__, node);
450 extern int parse_tsp_node(u8 flag, struct TSP_NODE_BUF *node, s16 *buf16);
451 void run_raw_read(void *dev_data)
454 int min_val, max_val;
455 char buf[16] = { 0 };
456 u8 flag = NODE_FLAG_RAW;
458 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
459 struct sec_factory *sec = (struct sec_factory *)&data->sec;
460 TSP_INFO *tsp = &ist30xx_tsp_info;
462 set_default_result(sec);
464 ret = ist30xx_read_touch_node(flag, &tsp->node);
466 sec->cmd_state = CMD_STATE_FAIL;
467 tsp_warn("%s(), tsp node read fail!\n", __func__);
470 ist30xx_parse_touch_node(flag, &tsp->node);
472 ret = parse_tsp_node(flag, &tsp->node, node_value);
474 sec->cmd_state = CMD_STATE_FAIL;
475 tsp_warn("%s(), tsp node parse fail - flag: %d\n", __func__, flag);
479 min_val = max_val = node_value[0];
480 for (i = 0; i < tsp->width * tsp->height; i++) {
482 if ((i % tsp->width) == 0)
483 printk("\n%s %4d: ", IST30XX_DEBUG_TAG, i);
485 printk("%4d ", node_value[i]);
488 max_val = max(max_val, (int)node_value[i]);
489 min_val = min(min_val, (int)node_value[i]);
492 snprintf(buf, sizeof(buf), "%d,%d", min_val, max_val);
493 tsp_info("%s(), %s\n", __func__, buf);
495 sec->cmd_state = CMD_STATE_OK;
496 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
497 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__, buf,
498 strnlen(buf, sizeof(buf)));
501 void get_raw_value(void *dev_data)
504 char buf[16] = { 0 };
506 struct ist30xx_data *data = (struct ist30xx_data *)dev_data;
507 struct sec_factory *sec = (struct sec_factory *)&data->sec;
509 set_default_result(sec);
511 idx = check_tsp_channel(data);
512 if (idx < 0) { // Parameter parsing fail
513 snprintf(buf, sizeof(buf), "%s", "NG");
514 sec->cmd_state = CMD_STATE_FAIL;
516 snprintf(buf, sizeof(buf), "%d", node_value[idx]);
517 sec->cmd_state = CMD_STATE_OK;
520 set_cmd_result(sec, buf, strnlen(buf, sizeof(buf)));
521 tsp_info("%s(), [%d][%d]: %s\n", __func__,
522 sec->cmd_param[0], sec->cmd_param[1], buf);
523 dev_info(&data->client->dev, "%s: %s(%d)\n", __func__, buf,
524 strnlen(buf, sizeof(buf)));
529 /* sysfs: /sys/class/sec/tsp/close_tsp_test */
530 static ssize_t show_close_tsp_test(struct device *dev,
531 struct device_attribute *attr, char *buf)
533 return snprintf(buf, FACTORY_BUF_SIZE, "%u\n", 0);
536 /* sysfs: /sys/class/sec/tsp/cmd */
537 static ssize_t store_cmd(struct device *dev, struct device_attribute
538 *devattr, const char *buf, size_t count)
540 struct ist30xx_data *data = dev_get_drvdata(dev);
541 struct sec_factory *sec = (struct sec_factory *)&data->sec;
542 struct i2c_client *client = data->client;
544 char *cur, *start, *end;
545 char msg[SEC_CMD_STR_LEN] = { 0 };
547 struct tsp_cmd *tsp_cmd_ptr = NULL;
549 bool cmd_found = false;
553 if (sec->cmd_is_running == true) {
554 dev_err(&client->dev, "tsp_cmd: other cmd is running.\n");
555 tsp_err("tsp_cmd: other cmd is running.\n");
560 mutex_lock(&sec->cmd_lock);
561 sec->cmd_is_running = true;
562 mutex_unlock(&sec->cmd_lock);
564 sec->cmd_state = CMD_STATE_RUNNING;
566 for (i = 0; i < ARRAY_SIZE(sec->cmd_param); i++)
567 sec->cmd_param[i] = 0;
570 if (*(buf + len - 1) == '\n')
572 memset(sec->cmd, 0, ARRAY_SIZE(sec->cmd));
573 memcpy(sec->cmd, buf, len);
575 cur = strchr(buf, (int)delim);
577 memcpy(msg, buf, cur - buf);
579 memcpy(msg, buf, len);
581 list_for_each_entry(tsp_cmd_ptr, &sec->cmd_list_head, list) {
582 if (!strcmp(msg, tsp_cmd_ptr->cmd_name)) {
588 /* set not_support_cmd */
590 list_for_each_entry(tsp_cmd_ptr, &sec->cmd_list_head, list) {
591 if (!strcmp("not_support_cmd", tsp_cmd_ptr->cmd_name))
596 /* parsing parameters */
597 if (cur && cmd_found) {
600 memset(msg, 0, ARRAY_SIZE(msg));
602 if (*cur == delim || cur - buf == len) {
604 memcpy(msg, start, end - start);
605 *(msg + strlen(msg)) = '\0';
606 ret = kstrtoint(msg, 10, \
607 sec->cmd_param + param_cnt);
609 memset(msg, 0, ARRAY_SIZE(msg));
613 } while (cur - buf <= len);
615 dev_info(&client->dev, "cmd = %s\n", tsp_cmd_ptr->cmd_name);
616 tsp_info("SEC CMD = %s\n", tsp_cmd_ptr->cmd_name);
618 for (i = 0; i < param_cnt; i++)
619 dev_info(&client->dev, "cmd param %d= %d\n", i, sec->cmd_param[i]);
621 tsp_cmd_ptr->cmd_func(data);
627 /* sysfs: /sys/class/sec/tsp/cmd_status */
628 static ssize_t show_cmd_status(struct device *dev,
629 struct device_attribute *devattr, char *buf)
631 struct ist30xx_data *data = dev_get_drvdata(dev);
632 struct sec_factory *sec = (struct sec_factory *)&data->sec;
633 char msg[16] = { 0 };
635 dev_info(&data->client->dev, "tsp cmd: status:%d\n", sec->cmd_state);
637 if (sec->cmd_state == CMD_STATE_WAITING)
638 snprintf(msg, sizeof(msg), "WAITING");
639 else if (sec->cmd_state == CMD_STATE_RUNNING)
640 snprintf(msg, sizeof(msg), "RUNNING");
641 else if (sec->cmd_state == CMD_STATE_OK)
642 snprintf(msg, sizeof(msg), "OK");
643 else if (sec->cmd_state == CMD_STATE_FAIL)
644 snprintf(msg, sizeof(msg), "FAIL");
645 else if (sec->cmd_state == CMD_STATE_NA)
646 snprintf(msg, sizeof(msg), "NOT_APPLICABLE");
648 return snprintf(buf, FACTORY_BUF_SIZE, "%s\n", msg);
651 /* sysfs: /sys/class/sec/tsp/result */
652 static ssize_t show_cmd_result(struct device *dev, struct device_attribute
655 struct ist30xx_data *data = dev_get_drvdata(dev);
656 struct sec_factory *sec = (struct sec_factory *)&data->sec;
658 dev_info(&data->client->dev, "tsp cmd: result: %s\n", sec->cmd_result);
660 mutex_lock(&sec->cmd_lock);
661 sec->cmd_is_running = false;
662 mutex_unlock(&sec->cmd_lock);
664 sec->cmd_state = CMD_STATE_WAITING;
666 return snprintf(buf, FACTORY_BUF_SIZE, "%s\n", sec->cmd_result);
671 /* sysfs: /sys/class/sec/sec_touchscreen/tsp_firm_version_phone */
672 static ssize_t phone_firmware_show(struct device *dev,
673 struct device_attribute *attr, char *buf)
675 u32 ver = ist30xx_parse_ver(FLAG_PARAM, ts_data->fw.buf);
677 tsp_info("%s(), IM00%04x\n", __func__, ver);
679 return sprintf(buf, "IM00%04x", ver);
682 /* sysfs: /sys/class/sec/sec_touchscreen/tsp_firm_version_panel */
683 static ssize_t part_firmware_show(struct device *dev,
684 struct device_attribute *attr, char *buf)
688 if (ts_data->status.power == 1)
689 ver = ist30xxb_get_fw_ver(ts_data);
691 tsp_info("%s(), IM00%04x\n", __func__, ver);
693 return sprintf(buf, "IM00%04x", ver);
696 /* sysfs: /sys/class/sec/sec_touchscreen/tsp_threshold */
697 static ssize_t threshold_firmware_show(struct device *dev,
698 struct device_attribute *attr, char *buf)
703 ist30xx_get_update_info(ts_data, ts_data->fw.buf, ts_data->fw.buf_size);
704 cfg_buf = (u32 *)&ts_data->fw.buf[ts_data->tags.cfg_addr];
706 threshold = (int)(cfg_buf[0x2C / IST30XX_DATA_LEN] & 0xFFFF);
708 tsp_info("%s(), %d\n", __func__, threshold);
710 return sprintf(buf, "%d", threshold);
713 /* sysfs: /sys/class/sec/sec_touchscreen/tsp_firm_update */
714 static ssize_t firmware_update(struct device *dev,
715 struct device_attribute *attr, char *buf)
719 sprintf(IsfwUpdate, "%s\n", FW_DOWNLOADING);
720 tsp_info("%s(), %s\n", __func__, IsfwUpdate);
722 ret = ist30xx_fw_recovery(ts_data);
723 ret = (ret == 0 ? 1 : -1);
725 sprintf(IsfwUpdate, "%s\n",
726 (ret > 0 ? FW_DOWNLOAD_COMPLETE : FW_DOWNLOAD_FAIL));
727 tsp_info("%s(), %s\n", __func__, IsfwUpdate);
729 return sprintf(buf, "%d", ret);
732 /* sysfs: /sys/class/sec/sec_touchscreen/tsp_firm_update_status */
733 static ssize_t firmware_update_status(struct device *dev,
734 struct device_attribute *attr, char *buf)
736 tsp_info("%s(), %s\n", __func__, IsfwUpdate);
738 return sprintf(buf, "%s\n", IsfwUpdate);
741 /* sysfs: /sys/class/sec/sec_touchkey/touchkey_recent */
742 static ssize_t recent_sensitivity_show(struct device *dev,
743 struct device_attribute *attr, char *buf)
745 int sensitivity = ist30xxb_get_key_sensitivity(ts_data, 0);
747 tsp_info("%s(), %d\n", __func__, sensitivity);
749 return sprintf(buf, "%d", sensitivity);
752 /* sysfs: /sys/class/sec/sec_touchkey/touchkey_back */
753 static ssize_t back_sensitivity_show(struct device *dev,
754 struct device_attribute *attr, char *buf)
756 int sensitivity = ist30xxb_get_key_sensitivity(ts_data, 1);
758 tsp_info("%s(), %d\n", __func__, sensitivity);
760 return sprintf(buf, "%d", sensitivity);
763 /* sysfs: /sys/class/sec/sec_touchkey/touchkey_threshold */
764 static ssize_t touchkey_threshold_show(struct device *dev,
765 struct device_attribute *attr, char *buf)
770 ist30xx_get_update_info(ts_data, ts_data->fw.buf, ts_data->fw.buf_size);
771 cfg_buf = (u32 *)&ts_data->fw.buf[ts_data->tags.cfg_addr];
773 threshold = (int)(cfg_buf[0x30 / IST30XX_DATA_LEN] & 0xFFFF);
775 tsp_info("%s(), %d\n", __func__, threshold);
777 return snprintf(buf, sizeof(int), "%d\n", threshold);
780 struct tsp_cmd tsp_cmds[] = {
781 { TSP_CMD("get_chip_vendor", get_chip_vendor), },
782 { TSP_CMD("get_chip_name", get_chip_name), },
783 { TSP_CMD("get_chip_id", get_chip_id), },
784 { TSP_CMD("fw_update", fw_update), },
785 { TSP_CMD("get_fw_ver_bin", get_fw_ver_bin), },
786 { TSP_CMD("get_fw_ver_ic", get_fw_ver_ic), },
787 { TSP_CMD("get_threshold", get_threshold), },
788 { TSP_CMD("get_x_num", get_x_num), },
789 { TSP_CMD("get_y_num", get_y_num), },
790 { TSP_CMD("run_raw_read", run_raw_read), },
791 { TSP_CMD("get_raw_value", get_raw_value), },
792 { TSP_CMD("not_support_cmd", not_support_cmd), },
795 #define SEC_DEFAULT_ATTR (S_IRUGO | S_IWUSR | S_IWOTH | S_IXOTH)
796 /* sysfs - touchscreen */
797 static DEVICE_ATTR(tsp_firm_version_phone, SEC_DEFAULT_ATTR,
798 phone_firmware_show, NULL);
799 static DEVICE_ATTR(tsp_firm_version_panel, SEC_DEFAULT_ATTR,
800 part_firmware_show, NULL);
801 static DEVICE_ATTR(tsp_threshold, SEC_DEFAULT_ATTR,
802 threshold_firmware_show, NULL);
803 static DEVICE_ATTR(tsp_firm_update, SEC_DEFAULT_ATTR,
804 firmware_update, NULL);
805 static DEVICE_ATTR(tsp_firm_update_status, SEC_DEFAULT_ATTR,
806 firmware_update_status, NULL);
808 /* sysfs - touchkey */
809 static DEVICE_ATTR(touchkey_recent, SEC_DEFAULT_ATTR,
810 recent_sensitivity_show, NULL);
811 static DEVICE_ATTR(touchkey_back, SEC_DEFAULT_ATTR,
812 back_sensitivity_show, NULL);
813 static DEVICE_ATTR(touchkey_threshold, SEC_DEFAULT_ATTR,
814 touchkey_threshold_show, NULL);
817 static DEVICE_ATTR(close_tsp_test, S_IRUGO, show_close_tsp_test, NULL);
818 static DEVICE_ATTR(cmd, S_IWUSR | S_IWGRP, NULL, store_cmd);
819 static DEVICE_ATTR(cmd_status, S_IRUGO, show_cmd_status, NULL);
820 static DEVICE_ATTR(cmd_result, S_IRUGO, show_cmd_result, NULL);
822 static struct attribute *sec_tsp_attributes[] = {
823 &dev_attr_tsp_firm_version_phone.attr,
824 &dev_attr_tsp_firm_version_panel.attr,
825 &dev_attr_tsp_threshold.attr,
826 &dev_attr_tsp_firm_update.attr,
827 &dev_attr_tsp_firm_update_status.attr,
831 static struct attribute *sec_tkey_attributes[] = {
832 &dev_attr_touchkey_recent.attr,
833 &dev_attr_touchkey_back.attr,
834 &dev_attr_touchkey_threshold.attr,
838 static struct attribute *sec_touch_facotry_attributes[] = {
839 &dev_attr_close_tsp_test.attr,
841 &dev_attr_cmd_status.attr,
842 &dev_attr_cmd_result.attr,
846 static struct attribute_group sec_tsp_attr_group = {
847 .attrs = sec_tsp_attributes,
850 static struct attribute_group sec_tkey_attr_group = {
851 .attrs = sec_tkey_attributes,
854 static struct attribute_group sec_touch_factory_attr_group = {
855 .attrs = sec_touch_facotry_attributes,
858 extern struct class *sec_class;
859 struct device *sec_touchscreen;
860 EXPORT_SYMBOL(sec_touchscreen);
861 struct device *sec_touchkey;
862 EXPORT_SYMBOL(sec_touchkey);
863 struct device *sec_fac_dev;
866 int sec_touch_sysfs(struct ist30xx_data *data)
868 /* /sys/class/sec/sec_touchscreen */
869 sec_touchscreen = device_create(sec_class, NULL, 0, NULL,
871 if (IS_ERR(sec_touchscreen)) {
872 tsp_err("Failed to create device (%s)!\n", "sec_touchscreen");
875 /* /sys/class/sec/sec_touchscreen/... */
876 if (sysfs_create_group(&sec_touchscreen->kobj, &sec_tsp_attr_group))
877 tsp_err("Failed to create sysfs group(%s)!\n", "sec_touchscreen");
879 /* /sys/class/sec/sec_touchkey */
880 sec_touchkey = device_create(sec_class, NULL, 0, NULL, "sec_touchkey");
881 if (IS_ERR(sec_touchkey)) {
882 tsp_err("Failed to create device (%s)!\n", "sec_touchkey");
885 /* /sys/class/sec/sec_touchkey/... */
886 if (sysfs_create_group(&sec_touchkey->kobj, &sec_tkey_attr_group))
887 tsp_err("Failed to create sysfs group(%s)!\n", "sec_touchkey");
889 /* /sys/class/sec/tsp */
890 sec_fac_dev = device_create(sec_class, NULL, 0, data, "tsp");
891 if (IS_ERR(sec_fac_dev)) {
892 tsp_err("Failed to create device (%s)!\n", "tsp");
895 /* /sys/class/sec/tsp/... */
896 if (sysfs_create_group(&sec_fac_dev->kobj, &sec_touch_factory_attr_group))
897 tsp_err("Failed to create sysfs group(%s)!\n", "tsp");
901 EXPORT_SYMBOL(sec_touch_sysfs);
902 int sec_fac_cmd_init(struct ist30xx_data *data)
905 struct sec_factory *sec = (struct sec_factory *)&data->sec;
907 INIT_LIST_HEAD(&sec->cmd_list_head);
908 for (i = 0; i < ARRAY_SIZE(tsp_cmds); i++)
909 list_add_tail(&tsp_cmds[i].list, &sec->cmd_list_head);
911 mutex_init(&sec->cmd_lock);
912 sec->cmd_is_running = false;
916 EXPORT_SYMBOL(sec_fac_cmd_init);