2 * Raydium RM31080 touchscreen driver
4 * Copyright (C) 2012-2014, Raydium Semiconductor Corporation.
6 * Copyright (C) 2012-2014, NVIDIA Corporation. All Rights Reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
14 /*=============================================================================
16 =============================================================================*/
17 #include <linux/module.h>
18 #include <linux/input.h> /* BUS_SPI */
19 #include <linux/spi/spi.h>
20 #include <linux/device.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/slab.h>
27 #include <linux/gpio.h>
29 #include <linux/of_device.h>
30 #include <linux/of_gpio.h>
31 #include <linux/sched.h> /* wake_up_process() */
32 #include <linux/sched/rt.h>
33 #include <linux/kthread.h> /* kthread_create(),kthread_run() */
34 #include <linux/uaccess.h> /* copy_to_user() */
35 #include <linux/miscdevice.h>
36 #include <asm/siginfo.h> /* siginfo */
37 #include <linux/rcupdate.h> /* rcu_read_lock */
38 #include <linux/sched.h> /* find_task_by_pid_type */
39 #include <linux/syscalls.h> /* sys_clock_gettime() */
40 #include <linux/random.h> /* random32() */
41 #include <linux/suspend.h> /* pm_notifier */
42 #include <linux/workqueue.h>
43 #include <linux/wakelock.h> /* wakelock */
44 #include <linux/regulator/consumer.h> /* regulator & voltage */
45 #include <linux/clk.h> /* clock */
46 #ifdef CONFIG_HAS_EARLYSUSPEND
47 #include <linux/earlysuspend.h>
50 #include <linux/timer.h>
52 #include <linux/spi/rm31080a_ts.h>
53 #include <linux/spi/rm31080a_ctrl.h>
55 #define CREATE_TRACE_POINTS
56 #include <trace/events/touchscreen_raydium.h>
58 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_B)
59 #include <linux/input/mt.h>
62 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
66 /*=============================================================================
68 =============================================================================*/
69 #define MAX_SPI_FREQ_HZ 50000000
70 #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50)
72 #define QUEUE_COUNT 128
73 #define RM_RAW_DATA_LENGTH 6144
75 #define RM_SCAN_ACTIVE_MODE 0x00
76 #define RM_SCAN_PRE_IDLE_MODE 0x01
77 #define RM_SCAN_IDLE_MODE 0x02
79 #define RM_NEED_NONE 0x00
80 #define RM_NEED_TO_SEND_SCAN 0x01
81 #define RM_NEED_TO_READ_RAW_DATA 0x02
82 #define RM_NEED_TO_SEND_SIGNAL 0x04
84 #define TCH_WAKE_LOCK_TIMEOUT (HZ/2)
86 #if ENABLE_FREQ_HOPPING /*ENABLE_SCAN_DATA_HEADER*/
87 #define QUEUE_HEADER_NUM (8)
88 #define SCAN_TYPE_MT (1)
90 #define QUEUE_HEADER_NUM 0
93 #ifdef ENABLE_SLOW_SCAN
94 #define RM_SLOW_SCAN_INTERVAL 20
95 #define RM_SLOW_SCAN_CMD_COUNT 0x10
96 enum RM_SLOW_SCAN_LEVELS {
97 RM_SLOW_SCAN_LEVEL_NORMAL,
98 RM_SLOW_SCAN_LEVEL_20,
99 RM_SLOW_SCAN_LEVEL_40,
100 RM_SLOW_SCAN_LEVEL_60,
101 RM_SLOW_SCAN_LEVEL_80,
102 RM_SLOW_SCAN_LEVEL_100,
103 RM_SLOW_SCAN_LEVEL_MAX,
104 RM_SLOW_SCAN_LEVEL_COUNT
110 RM_TEST_MODE_IDLE_SHOW,
111 RM_TEST_MODE_IDLE_LEVEL,
112 RM_TEST_MODE_CALC_TIME_SHOW,
116 #ifdef ENABLE_SMOOTH_LEVEL
117 #define RM_SMOOTH_LEVEL_NORMAL 0
118 #define RM_SMOOTH_LEVEL_MAX 4
121 #define TS_TIMER_PERIOD HZ
123 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_B)
124 #define MAX_SUPPORT_SLOT_AMOUNT MAX_REPORT_TOUCHED_POINTS
127 /*#define CS_SUPPORT*/
128 #define MASK_USER_SPACE_POINTER 0x00000000FFFFFFFF /* 64-bit support */
130 #define ISR_POST_HANDLER WORK_QUEUE /*or KTHREAD*/
134 /* do not use printk in kernel files */
135 #define rm_printk(msg...) dev_info(&g_spi->dev, msg)
137 /*=============================================================================
138 STRUCTURE DECLARATION
139 =============================================================================*/
140 /* TouchScreen Parameters */
141 struct rm31080a_ts_para {
145 bool b_enable_scriber;
149 u32 u32_watch_dog_cnt;
151 u8 u8_watch_dog_enable;
152 bool b_watch_dog_check;
153 u32 u32_watch_dog_time;
155 u8 u8_scan_mode_state;
158 #ifdef ENABLE_SLOW_SCAN
159 bool b_enable_slow_scan;
160 bool b_slow_scan_flg;
161 u32 u32_slow_scan_level;
164 u8 u8_touchfile_check;
167 #ifdef ENABLE_SMOOTH_LEVEL
168 u32 u32_smooth_level;
170 bool b_selftest_enable;
171 u8 u8_selftest_status;
172 u8 u8_selftest_result;
179 u8 u8_test_mode_type;
180 #if ENABLE_FREQ_HOPPING
186 struct wake_lock wakelock_initialization;
188 struct mutex mutex_scan_mode;
189 struct mutex mutex_ns_mode;
191 #if (ISR_POST_HANDLER == WORK_QUEUE)
192 struct workqueue_struct *rm_workqueue;
193 struct work_struct rm_work;
194 #elif (ISR_POST_HANDLER == KTHREAD)
195 struct mutex mutex_irq_wait;
196 bool b_irq_is_waited;
197 struct task_struct *rm_irq_post_thread;
198 struct sched_param thread_sched;
200 bool b_thread_active;
201 wait_queue_head_t rm_thread_wait_q;
204 struct workqueue_struct *rm_timer_workqueue;
205 struct work_struct rm_timer_work;
209 const struct rm_tch_bus_ops *bops;
211 struct input_dev *input;
214 struct mutex access_mutex;
215 #ifdef CONFIG_HAS_EARLYSUSPEND
216 struct early_suspend early_suspend;
218 struct regulator *regulator_3v3;
219 struct regulator *regulator_1v8;
220 struct notifier_block nb_3v3;
221 struct notifier_block nb_1v8;
223 unsigned char u8_repeat_counter;
224 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
225 struct notifier_block fb_notifier;
229 struct rm_tch_bus_ops {
231 int (*read) (struct device *dev, u8 reg);
232 int (*write) (struct device *dev, u8 reg, u16 val);
235 struct rm_tch_queue_info {
236 u8(*p_u8_queue)[RM_RAW_DATA_LENGTH];
241 /*=============================================================================
242 GLOBAL VARIABLES DECLARATION
243 =============================================================================*/
244 struct input_dev *g_input_dev;
245 struct spi_device *g_spi;
246 struct rm31080a_ts_para g_st_ts;
247 struct rm_tch_queue_info g_st_q;
249 bool g_timer_queue_is_flush;
250 #if (ISR_POST_HANDLER == WORK_QUEUE)
251 bool g_worker_queue_is_flush;
254 unsigned char *g_pu8_burstread_buf;
256 unsigned char g_st_cmd_set_idle[KRL_SIZE_SET_IDLE];
257 unsigned char g_st_cmd_pause_auto[KRL_SIZE_PAUSE_AUTO];
258 unsigned char g_st_rm_resume_cmd[KRL_SIZE_RM_RESUME];
259 unsigned char g_st_rm_suspend_cmd[KRL_SIZE_RM_SUSPEND];
260 unsigned char g_st_rm_readimg_cmd[KRL_SIZE_RM_READ_IMG];
261 unsigned char g_st_rm_watchdog_cmd[KRL_SIZE_RM_WATCHDOG];
262 unsigned char g_st_rm_testmode_cmd[KRL_SIZE_RM_TESTMODE];
263 unsigned char g_st_rm_slow_scan_cmd[KRL_SIZE_RM_SLOWSCAN];
264 unsigned char g_st_rm_clear_int_cmd[KRL_SIZE_RM_CLEARINT];
265 unsigned char g_st_rm_scan_start_cmd[KRL_SIZE_RM_SCANSTART];
266 unsigned char g_st_rm_wait_scan_ok_cmd[KRL_SIZE_RM_WAITSCANOK];
267 unsigned char g_st_rm_set_rep_time_cmd[KRL_SIZE_RM_SETREPTIME];
268 unsigned char g_st_rm_ns_para_cmd[KRL_SIZE_RM_NS_PARA];
269 unsigned char g_st_rm_writeimg_cmd[KRL_SIZE_RM_WRITE_IMAGE];
270 unsigned char g_st_rm_tlk_cmd[KRL_SIZE_RM_TLK];
271 unsigned char g_st_rm_kl_testmode_cmd[KRL_SIZE_RM_KL_TESTMODE];
273 int g_service_busy_report_count;
274 struct timer_list ts_timer_triggle;
276 static unsigned char g_spi_buf[8192];
277 static unsigned int g_spi_bufsize; /*= 0; remove by checkpatch*/
278 static unsigned char g_spi_addr;
280 u8 g_u8_update_baseline[RM_RAW_DATA_LENGTH];
282 size_t g_u8_test_mode_count;
283 char *g_u8_test_mode_buf;
285 /*=============================================================================
287 =============================================================================*/
288 static int rm_tch_cmd_process(u8 u8_sel_case, u8 *p_cmd_tbl,
289 struct rm_tch_ts *ts);
290 #if (ISR_POST_HANDLER == KTHREAD)
291 static int rm_work_thread_function(void *data);
293 static int rm_tch_read_image_data(unsigned char *p);
294 #ifdef CONFIG_HAS_EARLYSUSPEND
295 static void rm_tch_early_suspend(struct early_suspend *es);
296 static void rm_tch_early_resume(struct early_suspend *es);
298 static int rm_tch_ts_send_signal(int pid, int i_info);
299 static void rm_tch_enter_test_mode(u8 flag);
300 static void rm_ctrl_suspend(struct rm_tch_ts *ts);
301 static void rm_ctrl_resume(struct rm_tch_ts *ts);
302 static void rm_ctrl_watchdog_func(unsigned int u32_enable);
303 static void init_ts_timer(void);
304 static void ts_timer_triggle_function(unsigned long option);
306 /*=============================================================================
308 RM31080 spi interface.
314 =============================================================================*/
315 static int rm_tch_spi_read(u8 u8addr, u8 *rxbuf, size_t len)
318 struct spi_message message;
319 struct spi_transfer x[2];
321 if (g_st_ts.u8_spi_locked) {
322 memset(rxbuf, 0, len);
323 if (g_st_ctrl.u8_kernel_msg & DEBUG_REGISTER)
324 rm_printk("Raydium - SPI Read Locked!! 0x%x:%d\n",
326 /*return RETURN_FAIL;*/
330 spi_message_init(&message);
331 memset(x, 0, sizeof(x));
335 x[0].tx_buf = &u8addr;
336 spi_message_add_tail(&x[0], &message);
340 spi_message_add_tail(&x[1], &message);
342 /*It returns zero on succcess,else a negative error code.*/
343 status = spi_sync(g_spi, &message);
345 if (g_st_ctrl.u8_kernel_msg & DEBUG_REGISTER)
346 if (g_st_ts.b_init_finish == 0)
347 rm_printk("Raydium - READ: addr=0x%2x, value=0x%2x",
348 (u8addr&0x7F), rxbuf[0]);
351 dev_err(&g_spi->dev, "Raydium - %s : spi_async failed - error %d\n",
359 /*=============================================================================
361 RM31080 spi interface.
367 =============================================================================*/
368 static int rm_tch_spi_write(u8 *txbuf, size_t len)
371 /*It returns zero on succcess,else a negative error code.*/
373 if (g_st_ts.u8_spi_locked) {
374 if (g_st_ctrl.u8_kernel_msg & DEBUG_REGISTER)
375 rm_printk("Raydium - SPI write Locked!! 0x%x:0x%x\n",
377 /*return RETURN_FAIL;*/
381 status = spi_write(g_spi, txbuf, len);
383 if (g_st_ctrl.u8_kernel_msg & DEBUG_REGISTER)
384 if (g_st_ts.b_init_finish == 0)
385 rm_printk("Raydium - WRITE: addr=0x%2x, value=0x%2x",
389 dev_err(&g_spi->dev, "Raydium - %s : spi_write failed - error %d\n",
397 /*=============================================================================
399 RM31080 spi interface.
405 =============================================================================*/
406 static int rm_tch_spi_burst_write(u8 reg, u8 *txbuf, size_t len)
410 /*to do: check result*/
411 p_u8_Tmp = kmalloc(len + 1, GFP_KERNEL);
413 if (p_u8_Tmp == NULL)
415 for (i = 0; i < len; i++)
416 p_u8_Tmp[i + 1] = txbuf[i];
417 rm_tch_spi_write(p_u8_Tmp, len + 1);
422 /*=============================================================================
424 RM31080 spi interface.
430 =============================================================================*/
431 int rm_tch_spi_byte_read(unsigned char u8_addr, unsigned char *p_u8_value)
433 return rm_tch_spi_read(u8_addr, p_u8_value, 1);
436 /*=============================================================================
438 RM31080 spi interface.
444 =============================================================================*/
445 int rm_tch_spi_byte_write(unsigned char u8_addr, unsigned char u8_value)
450 return rm_tch_spi_write(buf, 2);
453 /*===========================================================================*/
454 static void rm_tch_generate_event(struct rm_tch_ts *dev_touch,
455 enum tch_update_reason reason)
460 case STYLUS_DISABLE_BY_WATER:
461 envp[0] = "STYLUS_DISABLE=Water";
463 case STYLUS_DISABLE_BY_NOISE:
464 envp[0] = "STYLUS_DISABLE=Noise";
466 case STYLUS_IS_ENABLED:
467 envp[0] = "STYLUS_DISABLE=None";
470 envp[0] = "STYLUS_DISABLE=Others";
474 kobject_uevent_env(&dev_touch->dev->kobj, KOBJ_CHANGE, envp);
477 /*===========================================================================*/
478 void raydium_change_scan_mode(u8 u8_touch_count)
480 static u32 u32_no_touch_count; /*= 0; remove by checkpatch*/
481 u16 u16_nt_count_thd;
483 u16_nt_count_thd = (u16)g_st_ctrl.u8_time2idle * 100;
485 if (u8_touch_count) {
486 u32_no_touch_count = 0;
490 if (u32_no_touch_count < u16_nt_count_thd)
491 u32_no_touch_count++;
493 mutex_lock(&g_st_ts.mutex_scan_mode);
494 if (g_st_ts.u8_scan_mode_state == RM_SCAN_ACTIVE_MODE) {
495 g_st_ts.u8_scan_mode_state = RM_SCAN_PRE_IDLE_MODE;
496 u32_no_touch_count = 0;
498 mutex_unlock(&g_st_ts.mutex_scan_mode);
502 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_A)
503 void raydium_report_pointer(void *p)
505 static unsigned char u8_last_touch_count; /*= 0; remove by checkpatch*/
508 int i_max_x, i_max_y;
509 struct rm_touch_event *sp_tp;
512 sp_tp = kmalloc(sizeof(struct rm_touch_event), GFP_KERNEL);
516 missing = copy_from_user(sp_tp, p, sizeof(struct rm_touch_event));
518 dev_err(&g_spi->dev, "Raydium - %s : copy failed - len:%d, miss:%d\n",
519 __func__, sizeof(struct rm_touch_event), missing);
524 if ((g_st_ctrl.u16_resolution_x != 0) &&
525 (g_st_ctrl.u16_resolution_y != 0)) {
526 i_max_x = g_st_ctrl.u16_resolution_x;
527 i_max_y = g_st_ctrl.u16_resolution_y;
529 i_max_x = RM_INPUT_RESOLUTION_X;
530 i_max_y = RM_INPUT_RESOLUTION_Y;
533 i_count = max(u8_last_touch_count, sp_tp->uc_touch_count);
535 if (i_count && !sp_tp->uc_touch_count) {
536 u8_last_touch_count = 0;
537 input_report_key(g_input_dev,
539 input_mt_sync(g_input_dev);
540 input_sync(g_input_dev);
541 } else if (i_count) {
542 for (i = 0; i < i_count; i++) {
543 if (i == MAX_REPORT_TOUCHED_POINTS)
546 if ((sp_tp->uc_tool_type[i] == POINT_TYPE_ERASER) &&
547 (sp_tp->uc_slot[i] & INPUT_POINT_RESET)) {
548 input_report_key(g_input_dev,
550 input_mt_sync(g_input_dev);
554 if (i < sp_tp->uc_touch_count) {
555 switch (sp_tp->uc_tool_type[i]) {
556 case POINT_TYPE_FINGER:
557 input_report_abs(g_input_dev,
561 case POINT_TYPE_STYLUS:
562 input_report_abs(g_input_dev,
566 case POINT_TYPE_ERASER:
567 input_report_key(g_input_dev,
572 "Raydium - point %d is invalid input tool type: %d\n",
573 i, sp_tp->uc_tool_type[i]);
577 input_report_abs(g_input_dev,
581 if (sp_tp->us_x[i] >= (i_max_x - 1))
582 input_report_abs(g_input_dev,
586 input_report_abs(g_input_dev,
590 if (sp_tp->us_y[i] >= (i_max_y - 1))
591 input_report_abs(g_input_dev,
595 input_report_abs(g_input_dev,
599 input_report_abs(g_input_dev,
604 input_mt_sync(g_input_dev);
606 input_sync(g_input_dev);
607 u8_last_touch_count = sp_tp->uc_touch_count;
610 /*if (g_st_ctrl.u8_power_mode)
611 raydium_change_scan_mode(sp_tp->uc_touch_count); */
615 #else /*(INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_B)*/
616 void raydium_report_pointer(void *p)
618 static unsigned char u8_last_touch_count; /*= 0; remove by checkpatch*/
619 unsigned int target_abs_mt_tool = MT_TOOL_FINGER;
620 unsigned int target_key_evt_btn_tool = BTN_TOOL_FINGER;
623 int i_max_x, i_max_y;
624 struct rm_touch_event *sp_tp;
626 sp_tp = kmalloc(sizeof(struct rm_touch_event), GFP_KERNEL);
630 missing = copy_from_user(sp_tp, p, sizeof(struct rm_touch_event));
632 dev_err(&g_spi->dev, "Raydium - %s : copy failed - len:%d, miss:%d\n",
633 __func__, sizeof(struct rm_touch_event), missing);
638 if ((g_st_ctrl.u16_resolution_x != 0) &&
639 (g_st_ctrl.u16_resolution_y != 0)) {
640 i_max_x = g_st_ctrl.u16_resolution_x;
641 i_max_y = g_st_ctrl.u16_resolution_y;
643 i_max_x = RM_INPUT_RESOLUTION_X;
644 i_max_y = RM_INPUT_RESOLUTION_Y;
647 i_count = max(u8_last_touch_count, sp_tp->uc_touch_count);
650 /*if (g_st_ctrl.u8_power_mode)
651 raydium_change_scan_mode(sp_tp->uc_touch_count);*/
656 for (i = 0; i < i_count; i++) {
657 if (i < sp_tp->uc_touch_count) {
659 input_mt_slot(g_input_dev,
660 sp_tp->uc_slot[i] & 0x7F);
662 if ((sp_tp->uc_slot[i] & 0x80) ||
663 (sp_tp->uc_id[i] == 0xFF)) {
664 switch (sp_tp->uc_pre_tool_type[i]) {
665 case POINT_TYPE_FINGER:
666 if (i == MAX_SUPPORT_SLOT_AMOUNT)
668 target_abs_mt_tool = MT_TOOL_FINGER;
670 case POINT_TYPE_STYLUS:
671 if (i == MAX_SUPPORT_SLOT_AMOUNT)
673 target_abs_mt_tool = MT_TOOL_PEN;
675 case POINT_TYPE_ERASER:
676 if (i == MAX_SUPPORT_SLOT_AMOUNT)
678 target_abs_mt_tool = MT_TOOL_PEN;
679 target_key_evt_btn_tool =
683 if (sp_tp->uc_id[i] != 0xFF) {
685 "Raydium - point %d release invalid input tool type: %d, id=%d\n",
686 i, sp_tp->uc_pre_tool_type[i],
692 input_mt_report_slot_state(
694 target_abs_mt_tool, false);
696 if (sp_tp->uc_pre_tool_type[i] ==
700 target_key_evt_btn_tool, false);
703 if (sp_tp->uc_id[i] != 0xFF) {
704 switch (sp_tp->uc_tool_type[i]) {
705 case POINT_TYPE_FINGER:
706 if (i == MAX_SUPPORT_SLOT_AMOUNT)
708 target_abs_mt_tool = MT_TOOL_FINGER;
710 case POINT_TYPE_STYLUS:
711 if (i == MAX_SUPPORT_SLOT_AMOUNT)
713 target_abs_mt_tool = MT_TOOL_PEN;
715 case POINT_TYPE_ERASER:
716 if (i == MAX_SUPPORT_SLOT_AMOUNT)
718 target_abs_mt_tool = MT_TOOL_PEN;
719 target_key_evt_btn_tool =
724 "Raydium - point %d has invalid input tool type: %d, id=%d\n",
725 i, sp_tp->uc_tool_type[i],
730 input_mt_report_slot_state(
732 target_abs_mt_tool, true);
734 if (sp_tp->us_x[i] >= (i_max_x - 1))
745 if (sp_tp->us_y[i] >= (i_max_y - 1))
761 if (sp_tp->uc_tool_type[i] == POINT_TYPE_ERASER)
764 target_key_evt_btn_tool, true);
768 u8_last_touch_count = sp_tp->uc_touch_count;
769 input_sync(g_input_dev);
771 /*if (g_st_ctrl.u8_power_mode)
772 raydium_change_scan_mode(sp_tp->uc_touch_count);*/
778 /*=============================================================================
779 Description: Read Sensor Raw Data
782 *p : Raw Data Buffer Address
785 =============================================================================*/
786 static int rm_tch_read_image_data(unsigned char *p)
790 g_pu8_burstread_buf = p;
792 #if ENABLE_FREQ_HOPPING /*ENABLE_SCAN_DATA_HEADER*/
793 g_pu8_burstread_buf[0] = SCAN_TYPE_MT;
794 g_pu8_burstread_buf[1] = (u8)(g_st_ctrl.u16_data_length >> 8);
795 g_pu8_burstread_buf[2] = (u8)(g_st_ctrl.u16_data_length);
796 if (g_st_ctrl.u8_ns_func_enable&0x01)
797 g_pu8_burstread_buf[3] = g_st_ts.u8_ns_sel;
799 g_pu8_burstread_buf[3] = 0;
800 g_pu8_burstread_buf[4] = g_st_ts.u8_test_mode_type;
801 g_pu8_burstread_buf[5] = 0x00;
802 g_pu8_burstread_buf[6] = 0x00;
803 g_pu8_burstread_buf[7] = 0x00;
806 ret = rm_tch_cmd_process(0, g_st_rm_readimg_cmd, NULL);
810 void rm_tch_ctrl_set_baseline(u8 *arg, u16 u16Len)
814 b_bl_updated = FALSE;
815 missing = copy_from_user(g_u8_update_baseline, arg, u16Len);
821 static int rm_tch_write_image_data(void)
825 ret = rm_tch_cmd_process(0, g_st_rm_writeimg_cmd, NULL);
829 #if ENABLE_FREQ_HOPPING
830 void rm_set_ns_para(u8 u8Idx, u8 *u8Para)
833 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
835 for (ii = 0; ii < g_st_rm_ns_para_cmd[2]; ii++) {
836 ts->u8_repeat_counter = u8Para[ii*3+u8Idx];
837 rm_tch_cmd_process(ii, g_st_rm_ns_para_cmd, ts);
842 void rm_tch_ctrl_enter_auto_mode(void)
844 g_st_ctrl.u8_idle_mode_check &= ~0x01;
846 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
847 rm_printk("Raydium - Enter Auto Scan Mode, bl_update=%d\n",
851 rm_tch_write_image_data();
852 b_bl_updated = FALSE;
855 rm_set_repeat_times(g_st_ctrl.u8_idle_digital_repeat_times);
856 rm_tch_cmd_process(1, g_st_cmd_set_idle, NULL);
859 void rm_tch_ctrl_leave_auto_mode(void)
861 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
863 g_st_ctrl.u8_idle_mode_check |= 0x01;
865 #if ENABLE_FREQ_HOPPING
866 if (g_st_ctrl.u8_ns_func_enable&0x01) {
867 mutex_lock(&g_st_ts.mutex_ns_mode);
868 rm_set_ns_para(0, (u8 *)&g_st_ts.u8_ns_para[0]);
869 mutex_unlock(&g_st_ts.mutex_ns_mode);
873 rm_tch_cmd_process(0, g_st_cmd_set_idle, ts);
874 rm_set_repeat_times(g_st_ctrl.u8_active_digital_repeat_times);
876 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
877 rm_printk("Raydium - Leave Auto Scan Mode\n");
880 void rm_ctrl_pause_auto_mode(void)
882 rm_tch_cmd_process(0, g_st_cmd_pause_auto, NULL);
885 int rm_tch_ctrl_clear_int(void)
887 return rm_tch_cmd_process(0, g_st_rm_clear_int_cmd, NULL);
891 int rm_tch_ctrl_wait_for_scan_finish(u8 u8Idx)
895 for (i = 0; i < 50; i++) { /*50ms = 20Hz*/
896 rm_tch_cmd_process(0, g_st_rm_wait_scan_ok_cmd, NULL);
898 if (g_st_ts.u16_read_para & 0x01) {
902 usleep_range(1000, 2000); /* msleep(1); */
909 int rm_tch_ctrl_scan_start(void)
911 #if ENABLE_FREQ_HOPPING
912 static u8 u8NsSel = 0, u8Rpt = 1;
913 if (g_st_ctrl.u8_ns_func_enable&0x01) {
914 if (rm_tch_ctrl_wait_for_scan_finish(1))
915 return rm_tch_cmd_process(0, g_st_rm_scan_start_cmd,
918 mutex_lock(&g_st_ts.mutex_ns_mode);
919 g_st_ts.u8_ns_sel = g_st_ts.u8_ns_para[u8NsSel];
921 if (u8NsSel < g_st_ts.u8_ns_mode)
926 if (u8Rpt != g_st_ts.u8_ns_rpt) {
927 u8Rpt = g_st_ts.u8_ns_rpt;
928 rm_set_repeat_times(u8Rpt);
930 rm_set_ns_para(u8NsSel, (u8 *)&g_st_ts.u8_ns_para[0]);
932 mutex_unlock(&g_st_ts.mutex_ns_mode);
935 g_st_ts.u8_ns_sel = 0;
938 return rm_tch_cmd_process(0, g_st_rm_scan_start_cmd, NULL);
941 void rm_set_repeat_times(u8 u8Times)
943 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
948 u8Times = u8Times - 1;
953 /*ts->u8_repeat_counter = (u8Times & 0x1F);*/
954 ts->u8_repeat_counter = (u8Times & 0x7F);
956 rm_tch_cmd_process(0, g_st_rm_set_rep_time_cmd, ts);
958 rm_tch_cmd_process(1, g_st_rm_set_rep_time_cmd, ts);
961 static u32 rm_tch_ctrl_configure(void)
965 switch (g_st_ts.u8_scan_mode_state) {
966 case RM_SCAN_ACTIVE_MODE:
968 RM_NEED_TO_SEND_SCAN |
969 RM_NEED_TO_READ_RAW_DATA |
970 RM_NEED_TO_SEND_SIGNAL;
973 case RM_SCAN_PRE_IDLE_MODE:
974 rm_tch_ctrl_enter_auto_mode();
975 g_st_ts.u8_scan_mode_state = RM_SCAN_IDLE_MODE;
976 u32_flag = RM_NEED_NONE;
979 case RM_SCAN_IDLE_MODE:
980 rm_tch_ctrl_leave_auto_mode();
981 g_st_ts.u8_scan_mode_state = RM_SCAN_ACTIVE_MODE;
982 u32_flag = RM_NEED_TO_SEND_SCAN;
986 u32_flag = RM_NEED_NONE;
993 int KRL_CMD_CONFIG_1V8_Handler(u8 u8_cmd, u8 u8_on_off, struct rm_tch_ts *ts)
995 int ret = RETURN_FAIL;
996 struct rm_spi_ts_platform_data *pdata;
998 pdata = g_input_dev->dev.parent->platform_data;
1000 if (u8_cmd == KRL_SUB_CMD_SET_1V8_REGULATOR) {
1002 if (ts->regulator_1v8) {
1004 ret = regulator_enable(
1007 dev_err(&g_spi->dev,
1008 "Raydium - regulator 1.8V enable failed: %d\n",
1011 ret = regulator_disable(
1014 dev_err(&g_spi->dev,
1015 "Raydium - regulator 1.8V disable failed: %d\n",
1019 dev_err(&g_spi->dev,
1020 "Raydium - regulator 1.8V handler fail: %d\n",
1023 dev_err(&g_spi->dev,
1024 "Raydium - regulator 1.8V ts fail: %d\n",
1026 } else if (u8_cmd == KRL_SUB_CMD_SET_1V8_GPIO)
1027 ret = gpio_direction_output(pdata->gpio_1v8, u8_on_off);
1032 int KRL_CMD_CONFIG_3V3_Handler(u8 u8_cmd, u8 u8_on_off, struct rm_tch_ts *ts)
1034 int ret = RETURN_FAIL;
1035 struct rm_spi_ts_platform_data *pdata;
1037 pdata = g_input_dev->dev.parent->platform_data;
1039 if (u8_cmd == KRL_SUB_CMD_SET_3V3_REGULATOR) {
1041 if (ts->regulator_3v3) {
1043 ret = regulator_enable(
1046 dev_err(&g_spi->dev,
1047 "Raydium - regulator 3.3V enable failed: %d\n",
1050 ret = regulator_disable(
1053 dev_err(&g_spi->dev,
1054 "Raydium - regulator 3.3V disable failed: %d\n",
1058 dev_err(&g_spi->dev,
1059 "Raydium - regulator 3.3V handler fail: %d\n",
1062 dev_err(&g_spi->dev,
1063 "Raydium - regulator 3.3V ts fail: %d\n",
1065 } else if (u8_cmd == KRL_SUB_CMD_SET_3V3_GPIO)
1066 ret = gpio_direction_output(pdata->gpio_3v3, u8_on_off);
1071 void rm_show_kernel_tbl_name(u8 *p_cmd_tbl)
1073 char target_table_name[32];
1075 memset(target_table_name, 0,
1076 sizeof(target_table_name));
1078 if (p_cmd_tbl == g_st_cmd_set_idle)
1079 snprintf(target_table_name,
1080 sizeof(target_table_name), "Set Idle");
1081 else if (p_cmd_tbl == g_st_cmd_pause_auto)
1082 snprintf(target_table_name,
1083 sizeof(target_table_name), "Pause Auto");
1084 else if (p_cmd_tbl == g_st_rm_resume_cmd)
1085 snprintf(target_table_name,
1086 sizeof(target_table_name), "Resume");
1087 else if (p_cmd_tbl == g_st_rm_suspend_cmd)
1088 snprintf(target_table_name,
1089 sizeof(target_table_name), "Suspend");
1090 else if (p_cmd_tbl == g_st_rm_readimg_cmd)
1091 snprintf(target_table_name,
1092 sizeof(target_table_name), "Read Image");
1093 else if (p_cmd_tbl == g_st_rm_watchdog_cmd)
1094 snprintf(target_table_name,
1095 sizeof(target_table_name), "WatchDog");
1096 else if (p_cmd_tbl == g_st_rm_testmode_cmd)
1097 snprintf(target_table_name,
1098 sizeof(target_table_name), "Test Mode");
1099 else if (p_cmd_tbl == g_st_rm_slow_scan_cmd)
1100 snprintf(target_table_name,
1101 sizeof(target_table_name), "Slowscan");
1102 else if (p_cmd_tbl == g_st_rm_clear_int_cmd)
1103 snprintf(target_table_name,
1104 sizeof(target_table_name), "Clear Intterupt");
1105 else if (p_cmd_tbl == g_st_rm_scan_start_cmd)
1106 snprintf(target_table_name,
1107 sizeof(target_table_name), "Scan Start");
1108 else if (p_cmd_tbl == g_st_rm_wait_scan_ok_cmd)
1109 snprintf(target_table_name,
1110 sizeof(target_table_name), "Wait Scan Okay");
1111 else if (p_cmd_tbl == g_st_rm_set_rep_time_cmd)
1112 snprintf(target_table_name,
1113 sizeof(target_table_name), "Set Repeat Time");
1114 else if (p_cmd_tbl == g_st_rm_ns_para_cmd)
1115 snprintf(target_table_name,
1116 sizeof(target_table_name), "Ns Parameter");
1117 else if (p_cmd_tbl == g_st_rm_writeimg_cmd)
1118 snprintf(target_table_name,
1119 sizeof(target_table_name), "Write Image");
1120 else if (p_cmd_tbl == g_st_rm_tlk_cmd)
1121 snprintf(target_table_name,
1122 sizeof(target_table_name), "TLK");
1123 else if (p_cmd_tbl == g_st_rm_kl_testmode_cmd)
1124 snprintf(target_table_name,
1125 sizeof(target_table_name), "Kernel_Test");
1127 dev_err(&g_spi->dev, "Raydium - %s : no such kernel table - err:%p\n",
1128 __func__, p_cmd_tbl);
1130 dev_err(&g_spi->dev, "Raydium - Table %s cmd failed\n",
1134 static int rm_tch_cmd_process(u8 u8_sel_case,
1135 u8 *p_cmd_tbl, struct rm_tch_ts *ts)
1138 #define _ADDR (u16j+1)
1139 #define _SUB_CMD (u16j+1)
1140 #define _DATA (u16j+2)
1142 static DEFINE_MUTEX(lock);
1143 u16 u16j = 0, u16strIdx, u16TblLenth, u16Tmp;
1146 int ret = RETURN_FAIL;
1147 struct rm_spi_ts_platform_data *pdata;
1151 pdata = g_input_dev->dev.parent->platform_data;
1153 if (p_cmd_tbl[KRL_TBL_FIELD_POS_LEN_H]) {
1154 u16TblLenth = p_cmd_tbl[KRL_TBL_FIELD_POS_LEN_H];
1156 u16TblLenth |= p_cmd_tbl[KRL_TBL_FIELD_POS_LEN_L];
1158 u16TblLenth = p_cmd_tbl[KRL_TBL_FIELD_POS_LEN_L];
1160 if (u16TblLenth < 3) {
1161 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
1162 dev_info(&g_spi->dev, "Raydium - Null u8_cmd %s : [%p]\n",
1163 __func__, p_cmd_tbl);
1164 mutex_unlock(&lock);
1168 u16strIdx = KRL_TBL_FIELD_POS_CASE_NUM
1169 + p_cmd_tbl[KRL_TBL_FIELD_POS_CASE_NUM] + 1;
1172 for (u8i = 0; u8i < u8_sel_case; u8i++)
1173 u16strIdx += (p_cmd_tbl[u8i + KRL_TBL_FIELD_POS_CMD_NUM]
1177 for (u8i = 0; u8i < p_cmd_tbl[u8_sel_case + KRL_TBL_FIELD_POS_CMD_NUM];
1179 u16j = u16strIdx + (KRL_TBL_CMD_LEN * u8i);
1181 switch (p_cmd_tbl[_CMD]) {
1183 ret = rm_tch_spi_read(p_cmd_tbl[_ADDR], &u8reg, 1);
1184 g_st_ts.u16_read_para = u8reg;
1185 /*rm_printk("Raydium - KRL_CMD_READ "
1186 "- 0x%x:0x%x\n", p_cmd_tbl[_ADDR], u8reg);*/
1188 case KRL_CMD_WRITE_WO_DATA:
1189 /*rm_printk("Raydium - KRL_CMD_WRITE_WO_DATA "
1190 "- 0x%x:0x%x\n", p_cmd_tbl[_ADDR], u8reg);*/
1191 ret = rm_tch_spi_byte_write(p_cmd_tbl[_ADDR], u8reg);
1193 case KRL_CMD_IF_AND_OR:
1194 if (u8reg & p_cmd_tbl[_ADDR])
1195 u8reg |= p_cmd_tbl[_DATA];
1199 u8reg &= p_cmd_tbl[_DATA];
1203 u8reg |= p_cmd_tbl[_DATA];
1206 case KRL_CMD_DRAM_INIT:
1207 ret = rm_tch_spi_byte_write(0x01, 0x00);
1208 ret = rm_tch_spi_byte_write(0x02, 0x00);
1210 case KRL_CMD_READ_IMG:
1211 /*rm_printk("Raydium - KRL_CMD_READ_IMG "
1214 g_pu8_burstread_buf,
1215 g_st_ctrl.u16_data_length);*/
1216 if (g_pu8_burstread_buf != NULL) {
1217 ret = rm_tch_spi_read(p_cmd_tbl[_ADDR],
1218 g_pu8_burstread_buf + QUEUE_HEADER_NUM,
1219 g_st_ctrl.u16_data_length
1220 /* - QUEUE_HEADER_NUM*/);
1222 g_pu8_burstread_buf = NULL;
1224 case KRL_CMD_WRITE_W_DATA:
1225 /*rm_printk("Raydium - KRL_CMD_WRITE_W_DATA "
1226 "- 0x%x:0x%x\n", p_cmd_tbl[_ADDR], p_cmd_tbl[_DATA]);*/
1227 ret = rm_tch_spi_byte_write(p_cmd_tbl[_ADDR],
1232 /*g_st_ts.u16_read_para = u8reg;*/
1236 u8reg ^= p_cmd_tbl[_DATA];
1239 case KRL_CMD_SEND_SIGNAL:
1240 u16Tmp = p_cmd_tbl[_DATA];
1241 /*rm_printk("Raydium - KRL_CMD_SEND_SIGNAL "
1242 "- %d\n", u16Tmp);*/
1243 ret = rm_tch_ts_send_signal(g_st_ts.u32_hal_pid,
1245 if (u16Tmp == RM_SIGNAL_RESUME)
1246 g_st_ts.u8_resume_cnt++;
1248 case KRL_CMD_CONFIG_RST:
1249 /*rm_printk("Raydium - KRL_CMD_CONFIG_RST "
1250 "- %d - %d\n", p_cmd_tbl[_SUB_CMD], p_cmd_tbl[_DATA]);*/
1251 switch (p_cmd_tbl[_SUB_CMD]) {
1252 case KRL_SUB_CMD_SET_RST_GPIO:
1253 ret = gpio_direction_output(pdata->gpio_reset,
1256 case KRL_SUB_CMD_SET_RST_VALUE:
1257 gpio_set_value(pdata->gpio_reset,
1263 case KRL_CMD_CONFIG_3V3:/*Need to check qpio setting*/
1264 /*rm_printk("Raydium - KRL_CMD_CONFIG_3V3 "
1265 "- %d - %d\n", p_cmd_tbl[_SUB_CMD], p_cmd_tbl[_DATA]);
1266 rm_printk("Raydium - 3.3V regulator is %d\n",
1267 regulator_is_enabled(ts->regulator_3v3));*/
1268 ret = KRL_CMD_CONFIG_3V3_Handler(p_cmd_tbl[_SUB_CMD],
1269 p_cmd_tbl[_DATA], ts);
1270 /*rm_printk("Raydium - 3.3V regulator is %d\n",
1271 regulator_is_enabled(ts->regulator_3v3));*/
1273 case KRL_CMD_CONFIG_1V8:/*Need to check qpio setting*/
1274 /*rm_printk("Raydium - KRL_CMD_CONFIG_1V8 "
1275 "- %d - %d\n", p_cmd_tbl[_SUB_CMD], p_cmd_tbl[_DATA]);
1276 rm_printk("Raydium - 1.8V regulator is %d\n",
1277 regulator_is_enabled(ts->regulator_1v8));*/
1278 ret = KRL_CMD_CONFIG_1V8_Handler(p_cmd_tbl[_SUB_CMD],
1279 p_cmd_tbl[_DATA], ts);
1280 /*rm_printk("Raydium - 1.8V regulator is %d\n",
1281 regulator_is_enabled(ts->regulator_1v8));*/
1283 case KRL_CMD_CONFIG_CLK:
1284 /*rm_printk("Raydium - KRL_CMD_CONFIG_CLK"
1285 " - %d - %d\n", p_cmd_tbl[_SUB_CMD],
1286 p_cmd_tbl[_DATA]);*/
1287 if (p_cmd_tbl[_SUB_CMD] == KRL_SUB_CMD_SET_CLK) {
1288 if (ts && ts->clk) {
1289 if (p_cmd_tbl[_DATA])
1290 ret = clk_enable(ts->clk);
1292 clk_disable(ts->clk);
1296 dev_err(&g_spi->dev, "Raydium - %s : No clk handler!\n",
1303 case KRL_CMD_CONFIG_CS:
1304 /*rm_printk("Raydium - KRL_CMD_CONFIG_CS "
1305 "- %d - %d\n", p_cmd_tbl[_SUB_CMD], p_cmd_tbl[_DATA]);*/
1306 switch (p_cmd_tbl[_SUB_CMD]) {
1307 case KRL_SUB_CMD_SET_CS_LOW:
1310 * spi_cs_low - set chip select pin state
1311 * @spi: device for which chip select pin state to be set
1312 * state: if true chip select pin will be kept low else
1314 * The return value is zero for success, else
1315 * errno status code.
1317 * int spi_cs_low(struct spi_device *spi, bool state)
1319 ret = spi_cs_low(g_spi,
1320 (bool)!!p_cmd_tbl[_DATA]);
1327 case KRL_CMD_SET_TIMER:
1328 /*rm_printk("Raydium - KRL_CMD_SET_TIMER "
1329 "- %d\n", p_cmd_tbl[_SUB_CMD]);*/
1331 if (p_cmd_tbl[_SUB_CMD] == KRL_SUB_CMD_INIT_TIMER)
1333 else if (p_cmd_tbl[_SUB_CMD] == KRL_SUB_CMD_ADD_TIMER) {
1334 if (!timer_pending(&ts_timer_triggle))
1335 add_timer(&ts_timer_triggle);
1336 } else if (p_cmd_tbl[_SUB_CMD] == KRL_SUB_CMD_DEL_TIMER)
1337 /*del_timer of an inactive timer returns 0,
1338 del_timer of an active timer returns 1*/
1339 del_timer(&ts_timer_triggle);
1343 case KRL_CMD_MSLEEP:
1344 /*rm_printk("Raydium - KRL_CMD_MSLEEP "
1345 "- %d ms\n", p_cmd_tbl[_DATA] |
1346 (p_cmd_tbl[_SUB_CMD] << 8));*/
1347 u32Tmp = (u16)(p_cmd_tbl[_DATA] |
1348 (p_cmd_tbl[_SUB_CMD] << 8));
1351 usleep_range(u32Tmp, u32Tmp + 200);
1354 case KRL_CMD_FLUSH_QU:
1355 /*rm_printk("Raydium - KRL_CMD_FLUSH_QU "
1356 "- %d\n", p_cmd_tbl[_SUB_CMD]);*/
1358 if (p_cmd_tbl[_SUB_CMD] == KRL_SUB_CMD_SENSOR_QU) {
1359 #if (ISR_POST_HANDLER == WORK_QUEUE)
1360 mutex_unlock(&lock);
1361 flush_workqueue(g_st_ts.rm_workqueue);
1362 g_worker_queue_is_flush = true;
1365 } else if (p_cmd_tbl[_SUB_CMD] ==
1366 KRL_SUB_CMD_TIMER_QU) {
1367 mutex_unlock(&lock);
1368 flush_workqueue(g_st_ts.rm_timer_workqueue);
1369 g_timer_queue_is_flush = true;
1374 case KRL_CMD_WRITE_W_COUNT:
1375 /*rm_printk("Raydium - KRL_CMD_WRITE_W_COUNT "
1376 "- 0x%x: 0x%x..0x%x\n", p_cmd_tbl[_ADDR], u8reg,
1377 ts->u8_repeat_counter);*/
1379 ret = rm_tch_spi_byte_write(p_cmd_tbl[_ADDR],
1380 u8reg | (ts->u8_repeat_counter));
1384 case KRL_CMD_RETURN_RESULT:
1385 g_st_ts.u16_read_para = u8reg;
1388 case KRL_CMD_RETURN_VALUE:
1389 g_st_ts.u16_read_para = (p_cmd_tbl[_ADDR] << 8)
1390 + (p_cmd_tbl[_DATA]);
1392 /*rm_printk("Raydium - KRL_CMD_RETURN_VALUE,
1395 case KRL_CMD_WRITE_IMG:
1396 /*rm_printk("Raydium - KRL_CMD_WRITE_IMG -
1397 0x%x:0x%x:%d\n", p_cmd_tbl[_ADDR], g_pu8_burstread_buf,
1398 g_st_ctrl.u16_data_length);*/
1399 ret = rm_tch_spi_burst_write(p_cmd_tbl[_ADDR],
1400 &g_u8_update_baseline[0],
1401 g_st_ctrl.u16_data_length);
1403 case KRL_CMD_CONFIG_IRQ:
1404 if (ts && (p_cmd_tbl[_SUB_CMD]
1405 == KRL_SUB_CMD_SET_IRQ)) {
1407 if (p_cmd_tbl[_DATA])
1408 enable_irq(ts->irq);
1410 disable_irq(ts->irq);
1412 dev_err(&g_spi->dev,
1413 "Raydium - %s : No irq handler!\n",
1425 rm_show_kernel_tbl_name(p_cmd_tbl);
1427 dev_err(&g_spi->dev, "Raydium - u8_cmd:0x%x, addr:0x%x, data:0x%x\n",
1435 mutex_unlock(&lock);
1440 int rm_set_kernel_tbl(int i_func_idx, u8 *p_u8_src)
1447 switch (i_func_idx) {
1448 case KRL_INDEX_FUNC_SET_IDLE:
1449 p_u8_dst = g_st_cmd_set_idle;
1451 case KRL_INDEX_FUNC_PAUSE_AUTO:
1452 p_u8_dst = g_st_cmd_pause_auto;
1454 case KRL_INDEX_RM_RESUME:
1455 p_u8_dst = g_st_rm_resume_cmd;
1457 case KRL_INDEX_RM_SUSPEND:
1458 p_u8_dst = g_st_rm_suspend_cmd;
1460 case KRL_INDEX_RM_READ_IMG:
1461 p_u8_dst = g_st_rm_readimg_cmd;
1463 case KRL_INDEX_RM_WATCHDOG:
1464 p_u8_dst = g_st_rm_watchdog_cmd;
1466 case KRL_INDEX_RM_TESTMODE:
1467 p_u8_dst = g_st_rm_testmode_cmd;
1469 case KRL_INDEX_RM_SLOWSCAN:
1470 p_u8_dst = g_st_rm_slow_scan_cmd;
1472 case KRL_INDEX_RM_CLEARINT:
1473 p_u8_dst = g_st_rm_clear_int_cmd;
1475 case KRL_INDEX_RM_SCANSTART:
1476 p_u8_dst = g_st_rm_scan_start_cmd;
1478 case KRL_INDEX_RM_WAITSCANOK:
1479 p_u8_dst = g_st_rm_wait_scan_ok_cmd;
1481 case KRL_INDEX_RM_SETREPTIME:
1482 p_u8_dst = g_st_rm_set_rep_time_cmd;
1484 case KRL_INDEX_RM_NSPARA:
1485 p_u8_dst = g_st_rm_ns_para_cmd;
1487 case KRL_INDEX_RM_WRITE_IMG:
1488 p_u8_dst = g_st_rm_writeimg_cmd;
1490 case KRL_INDEX_RM_TLK:
1491 p_u8_dst = g_st_rm_tlk_cmd;
1493 case KRL_INDEX_RM_KL_TESTMODE:
1494 p_u8_dst = g_st_rm_kl_testmode_cmd;
1497 dev_err(&g_spi->dev, "Raydium - %s : no such kernel table - err:%d\n",
1498 __func__, i_func_idx);
1502 p_u8_len = kmalloc(KRL_TBL_FIELD_POS_CASE_NUM, GFP_KERNEL);
1503 if (p_u8_len == NULL)
1506 missing = copy_from_user(p_u8_len, p_u8_src,
1507 KRL_TBL_FIELD_POS_CASE_NUM);
1509 dev_err(&g_spi->dev, "Raydium - %s : copy failed - len:%d, miss:%d\n",
1510 __func__, KRL_TBL_FIELD_POS_CASE_NUM, missing);
1515 u16_len = p_u8_len[KRL_TBL_FIELD_POS_LEN_H];
1517 u16_len |= p_u8_len[KRL_TBL_FIELD_POS_LEN_L];
1519 missing = copy_from_user(p_u8_dst, p_u8_src, u16_len);
1521 dev_err(&g_spi->dev, "Raydium - %s : copy failed - len:%d, miss:%d\n",
1522 __func__, u16_len, missing);
1530 /*=============================================================================
1532 =============================================================================*/
1533 static void rm_tch_enter_manual_mode(void)
1535 #if (ISR_POST_HANDLER == WORK_QUEUE)
1536 flush_workqueue(g_st_ts.rm_workqueue);
1538 mutex_lock(&g_st_ts.mutex_scan_mode);
1539 if (g_st_ts.u8_scan_mode_state == RM_SCAN_ACTIVE_MODE) {
1540 mutex_unlock(&g_st_ts.mutex_scan_mode);
1544 if (g_st_ts.u8_scan_mode_state == RM_SCAN_PRE_IDLE_MODE) {
1545 g_st_ts.u8_scan_mode_state = RM_SCAN_ACTIVE_MODE;
1546 mutex_unlock(&g_st_ts.mutex_scan_mode);
1550 if (g_st_ts.u8_scan_mode_state == RM_SCAN_IDLE_MODE) {
1551 rm_tch_ctrl_leave_auto_mode();
1552 g_st_ts.u8_scan_mode_state = RM_SCAN_ACTIVE_MODE;
1553 mutex_unlock(&g_st_ts.mutex_scan_mode);
1554 usleep_range(10000, 10050);/*msleep(10);*/
1558 mutex_unlock(&g_st_ts.mutex_scan_mode);
1561 static u32 rm_tch_get_platform_id(u8 *p)
1564 struct rm_spi_ts_platform_data *pdata;
1565 pdata = g_input_dev->dev.parent->platform_data;
1567 u32Ret = copy_to_user(p, &pdata->platform_id,
1568 sizeof(pdata->platform_id));
1573 static u32 rm_tch_get_gpio_sensor_select(u8 *p)
1576 struct rm_spi_ts_platform_data *pdata;
1577 pdata = g_input_dev->dev.parent->platform_data;
1580 u32Ret = gpio_set_value(pdata->gpio_sensor_select0)
1581 | (1 << gpio_set_value(pdata->gpio_sensor_select1));
1584 /* Read from data struct */
1585 if (pdata->gpio_sensor_select0)
1587 if (pdata->gpio_sensor_select1)
1590 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
1591 rm_printk("Raydium - %s : %d\n",
1594 u32Ret = copy_to_user(p, &u32Ret, sizeof(u32Ret));
1599 static u32 rm_tch_get_spi_lock_status(u8 *p)
1603 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
1604 rm_printk("Raydium - SPI_LOCK = %d\n", g_st_ts.u8_spi_locked);
1606 u32Ret = copy_to_user(p, &g_st_ts.u8_spi_locked,
1607 sizeof(g_st_ts.u8_spi_locked));
1609 if (g_st_ts.u8_spi_locked && g_st_ts.u8_resume_cnt)
1610 g_st_ts.u8_resume_cnt--;
1615 /*===========================================================================*/
1616 static int rm_tch_ts_send_signal(int pid, int i_info)
1618 struct siginfo info;
1619 struct task_struct *t;
1620 int ret = RETURN_OK;
1623 dev_err(&g_spi->dev, "Raydium - %s : pid failed\n", __func__);
1627 /* send the signal */
1628 memset(&info, 0, sizeof(struct siginfo));
1629 info.si_signo = RM_TS_SIGNAL;
1630 info.si_code = SI_QUEUE;
1632 this is bit of a trickery: SI_QUEUE is normally
1633 used by sigqueue from user space, and kernel
1634 space should use SI_KERNEL. But if SI_KERNEL
1635 is used the real_time data is not delivered to
1636 the user space signal handler function.
1638 info.si_int = i_info; /*real time signals may have 32 bits of data.*/
1641 t = find_task_by_vpid(pid);
1644 dev_err(&g_spi->dev, "Raydium - %s : no such pid\n", __func__);
1646 } else /*send the signal*/
1647 ret = send_sig_info(RM_TS_SIGNAL, &info, t);
1650 dev_err(&g_spi->dev, "Raydium - %s : send sig failed err:%d\n",
1656 /*=============================================================================
1664 =============================================================================*/
1665 static void rm_tch_queue_reset(void)
1667 g_st_q.u16_rear = 0;
1668 g_st_q.u16_front = 0;
1671 static int rm_tch_queue_init(void)
1673 rm_tch_queue_reset();
1674 g_st_q.p_u8_queue = kmalloc(QUEUE_COUNT * RM_RAW_DATA_LENGTH,
1676 if (g_st_q.p_u8_queue == NULL)
1682 static void rm_tch_queue_free(void)
1684 if (!g_st_q.p_u8_queue)
1686 kfree(g_st_q.p_u8_queue);
1687 g_st_q.p_u8_queue = NULL;
1690 #ifdef ENABLE_CALC_QUEUE_COUNT
1691 static int rm_tch_queue_get_current_count(void)
1693 if (g_st_q.u16_rear >= g_st_q.u16_front)
1694 return g_st_q.u16_rear - g_st_q.u16_front;
1696 return (QUEUE_COUNT - g_st_q.u16_front) + g_st_q.u16_rear;
1700 /*=============================================================================
1702 About full/empty buffer distinction,
1703 There are a number of solutions like:
1704 1.Always keep one slot open.
1705 2.Use a fill count to distinguish the two cases.
1706 3.Use read and write counts to get the fill count from.
1707 4.Use absolute indices.
1708 we chose "keep one slot open" to make it simple and robust
1709 and also avoid race condition.
1715 =============================================================================*/
1716 static int rm_tch_queue_is_empty(void)
1718 if (g_st_q.u16_rear == g_st_q.u16_front)
1723 /*=============================================================================
1731 =============================================================================*/
1732 static int rm_tch_queue_is_full(void)
1734 u16 u16_front = g_st_q.u16_front;
1736 if (g_st_q.u16_rear + 1 == u16_front)
1739 if ((g_st_q.u16_rear == (QUEUE_COUNT - 1)) && (u16_front == 0))
1745 static void *rm_tch_enqueue_start(void)
1747 if (!g_st_q.p_u8_queue) /*error handling for no memory*/
1750 if (!rm_tch_queue_is_full()) {
1751 g_service_busy_report_count = 100;
1752 return &g_st_q.p_u8_queue[g_st_q.u16_rear];
1755 if (g_service_busy_report_count < 0) {
1756 g_service_busy_report_count = 100;
1757 rm_printk("Raydium - touch service is busy,try again.\n");
1759 g_service_busy_report_count--;
1764 static void rm_tch_enqueue_finish(void)
1766 if (g_st_q.u16_rear == (QUEUE_COUNT - 1))
1767 g_st_q.u16_rear = 0;
1772 static void *rm_tch_dequeue_start(void)
1774 if (!rm_tch_queue_is_empty())
1775 return &g_st_q.p_u8_queue[g_st_q.u16_front];
1780 static void rm_tch_dequeue_finish(void)
1782 if (g_st_q.u16_front == (QUEUE_COUNT - 1))
1783 g_st_q.u16_front = 0;
1788 static long rm_tch_queue_read_raw_data(u8 *p, u32 u32Len)
1792 p_u8_queue = rm_tch_dequeue_start();
1796 u32Ret = copy_to_user(p, p_u8_queue, u32Len);
1800 rm_tch_dequeue_finish();
1804 /*===========================================================================*/
1805 #if (ISR_POST_HANDLER == WORK_QUEUE)
1806 static void rm_work_handler(struct work_struct *work)
1808 void *p_kernel_buffer;
1812 if (!g_st_ts.b_init_finish
1813 || g_st_ts.b_is_suspended
1814 || g_worker_queue_is_flush)
1817 i_ret = rm_tch_ctrl_clear_int();
1819 #ifdef ENABLE_SLOW_SCAN
1820 if (g_st_ts.b_slow_scan_flg == true) {
1821 rm_tch_cmd_process((u8)(g_st_ts.u32_slow_scan_level - 1),
1822 g_st_rm_slow_scan_cmd, NULL);
1823 g_st_ts.b_slow_scan_flg = false;
1825 #endif ENABLE_SLOW_SCAN
1827 u32_flag = rm_tch_ctrl_configure();
1829 if (u32_flag & RM_NEED_TO_SEND_SCAN)
1830 rm_tch_ctrl_scan_start();
1832 if (u32_flag & RM_NEED_TO_READ_RAW_DATA) {
1833 p_kernel_buffer = rm_tch_enqueue_start();
1834 if (p_kernel_buffer) {
1835 i_ret = rm_tch_read_image_data((u8 *) p_kernel_buffer);
1837 rm_tch_enqueue_finish();
1841 if (u32_flag & RM_NEED_TO_SEND_SIGNAL) {
1842 if (g_st_ts.b_calc_finish) {
1843 g_st_ts.b_calc_finish = 0;
1844 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid,
1849 #elif (ISR_POST_HANDLER == KTHREAD)
1850 static int rm_work_thread_function(void *data)
1852 void *p_kernel_buffer;
1856 sched_setscheduler(current_thread_info()->task,
1857 SCHED_FIFO, &g_st_ts.thread_sched);
1860 wait_event_interruptible(g_st_ts.rm_thread_wait_q,
1861 g_st_ts.b_thread_active);
1863 if (!g_st_ts.b_init_finish || g_st_ts.b_is_suspended)
1866 i_ret = rm_tch_ctrl_clear_int();
1868 u32_flag = rm_tch_ctrl_configure();
1870 if (u32_flag & RM_NEED_TO_SEND_SCAN)
1871 rm_tch_ctrl_scan_start();
1873 if (u32_flag & RM_NEED_TO_READ_RAW_DATA) {
1874 p_kernel_buffer = rm_tch_enqueue_start();
1875 if (p_kernel_buffer) {
1876 i_ret = rm_tch_read_image_data(
1877 (u8 *) p_kernel_buffer);
1879 rm_tch_enqueue_finish();
1883 if (u32_flag & RM_NEED_TO_SEND_SIGNAL) {
1884 if (g_st_ts.b_calc_finish) {
1885 g_st_ts.b_calc_finish = 0;
1886 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid,
1890 mutex_lock(&g_st_ts.mutex_irq_wait);
1891 if (!g_st_ts.b_irq_is_waited)
1892 g_st_ts.b_thread_active = false;
1894 g_st_ts.b_irq_is_waited = false;
1895 mutex_unlock(&g_st_ts.mutex_irq_wait);
1896 } while (!kthread_should_stop());
1902 static void rm_tch_init_ts_structure_part(void)
1904 g_st_ts.b_init_finish = 0;
1905 g_st_ts.b_calc_finish = 0;
1906 g_st_ts.b_enable_scriber = 0;
1908 #ifdef ENABLE_SLOW_SCAN
1909 g_st_ts.b_enable_slow_scan = false;
1910 g_st_ts.b_slow_scan_flg = false;
1912 g_st_ts.u8_scan_mode_state = RM_SCAN_ACTIVE_MODE;
1914 g_st_ctrl.u8_event_report_mode = EVENT_REPORT_MODE_STYLUS_ERASER_FINGER;
1916 g_pu8_burstread_buf = NULL;
1917 #if (ISR_POST_HANDLER == WORK_QUEUE)
1918 g_worker_queue_is_flush = false;
1919 #elif (ISR_POST_HANDLER == KTHREAD)
1920 g_st_ts.b_irq_is_waited = false;
1922 g_timer_queue_is_flush = false;
1923 g_st_ts.u16_read_para = 0;
1925 rm_ctrl_watchdog_func(0);
1927 g_st_ts.b_is_suspended = 0;
1928 /*g_st_ts.u8_test_mode = false;*/
1929 g_st_ts.u8_test_mode_type = RM_TEST_MODE_NULL;
1931 b_bl_updated = false;
1934 /*===========================================================================*/
1935 static void rm_ctrl_watchdog_func(unsigned int u32_enable)
1937 g_st_ts.u8_watch_dog_flg = 0;
1938 g_st_ts.u32_watch_dog_cnt = 0;
1939 g_st_ts.b_watch_dog_check = 0;
1941 g_st_ts.u8_watch_dog_enable = u32_enable & 0x01;
1942 g_st_ts.u32_watch_dog_time = u32_enable >> 16;
1944 if (u32_enable&0x01) {
1945 g_st_ts.u8_watch_dog_enable = 1;
1946 g_st_ts.u32_watch_dog_time = u32_enable >> 16;
1948 g_st_ts.u8_watch_dog_enable = 0;
1949 g_st_ts.u32_watch_dog_time = 0xFFFFFFFF;
1952 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
1953 rm_printk("Raydium - WatchDogEnable=%d, WatchDogTime=%d\n",
1954 g_st_ts.u8_watch_dog_enable,
1955 g_st_ts.u32_watch_dog_time);
1958 static void rm_watchdog_work_function(unsigned char scan_mode)
1960 if ((g_st_ts.u8_watch_dog_enable == 0) ||
1961 (g_st_ts.b_init_finish == 0))
1964 if (g_st_ts.u32_watch_dog_cnt++ >= g_st_ts.u32_watch_dog_time) {
1965 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
1966 rm_printk("Raydium - watchdog work: Time:%dsec Cnt:%d,Flg:%d(%x)\n",
1967 g_st_ts.u32_watch_dog_time,
1968 g_st_ts.u32_watch_dog_cnt,
1969 g_st_ts.u8_watch_dog_flg,
1970 g_st_ts.u8_scan_mode_state);
1972 switch (scan_mode) {
1973 case RM_SCAN_ACTIVE_MODE:
1974 g_st_ts.u32_watch_dog_cnt = 0;
1975 g_st_ts.u8_watch_dog_flg = 1;
1977 case RM_SCAN_IDLE_MODE:
1978 g_st_ts.u32_watch_dog_cnt = 0;
1979 g_st_ts.b_watch_dog_check = 1;
1984 if (g_st_ts.u8_watch_dog_flg) {
1986 /*rm_printk("Raydium - WatchDog Resume\n");*/
1987 rm_tch_init_ts_structure_part();
1988 g_st_ts.b_is_suspended = true;
1989 rm_tch_cmd_process(0, g_st_rm_watchdog_cmd, NULL);
1990 g_st_ts.b_is_suspended = false;
1996 static u8 rm_timer_trigger_function(void)
1998 static u32 u32TimerCnt; /*= 0; remove by checkpatch*/
2000 if (u32TimerCnt++ < g_st_ctrl.u8_timer_trigger_scale) {
2003 /*rm_printk("Raydium - rm_timer_work_handler:%x,%x\n",
2004 g_st_ctrl.u8_timer_trigger_scale, u32TimerCnt);*/
2010 static void rm_timer_work_handler(struct work_struct *work)
2012 static u16 u32TimerCnt; /*= 0; remove by checkpatch*/
2013 if (g_st_ts.b_is_suspended)
2016 if (g_timer_queue_is_flush == true)
2019 if (rm_timer_trigger_function()) {
2020 mutex_lock(&g_st_ts.mutex_scan_mode);
2021 if (g_st_ts.u8_scan_mode_state != RM_SCAN_ACTIVE_MODE)
2022 rm_watchdog_work_function(RM_SCAN_IDLE_MODE);
2024 rm_watchdog_work_function(RM_SCAN_ACTIVE_MODE);
2025 mutex_unlock(&g_st_ts.mutex_scan_mode);
2028 if (g_st_ts.b_watch_dog_check == 1) {
2029 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid,
2030 RM_SIGNAL_WATCH_DOG_CHECK);
2031 g_st_ts.b_watch_dog_check = 0;
2034 if (g_st_ts.u8_watch_dog_enable) {
2036 if (u32TimerCnt > g_st_ts.u32_watch_dog_time &&
2037 g_st_ts.u32_watch_dog_time !=
2038 g_st_ctrl.u8_watch_dog_normal_cnt) {
2039 g_st_ts.u32_watch_dog_time =
2040 g_st_ctrl.u8_watch_dog_normal_cnt;
2041 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2042 rm_printk("Raydium - WDT:Normal mode\n");
2050 /*========================================================================= */
2051 static void rm_tch_enable_irq(struct rm_tch_ts *ts)
2053 enable_irq(ts->irq);
2056 static void rm_tch_disable_irq(struct rm_tch_ts *ts)
2058 disable_irq(ts->irq);
2061 #ifdef ENABLE_SLOW_SCAN
2062 /*=============================================================================
2064 * Context dependent touch system.
2065 * Change scan speed for slowscan function.
2066 * Change scan speed flow: (by CY,20120305)
2067 * 1.Disable auto scan ([0x09]bit4=0,[0x09]bit6=1)
2068 * 2.Clear Scan start bit ([0x11]bit0=0)
2069 * 3.Read Scan start bit until it equals 0
2070 * 4.Set LACTIVE and YACTIVE configuration
2071 * 5.Enable autoscan ([0x09]bit4=1,[0x09]bit6=1)
2072 * 6.Sleep 1 minisecond.
2073 * 7.Set Scan start bit ([0x11]bit0=1)
2078 *===========================================================================*/
2079 static void rm_tch_ctrl_slowscan(u32 level)
2081 if (level == RM_SLOW_SCAN_LEVEL_NORMAL)
2082 level = RM_SLOW_SCAN_LEVEL_20;
2083 if (level > RM_SLOW_SCAN_LEVEL_100)
2084 level = RM_SLOW_SCAN_LEVEL_MAX;
2086 g_st_ts.u32_slow_scan_level = level;
2087 g_st_ts.b_slow_scan_flg = true;
2089 if (g_st_ts.u8_scan_mode_state == RM_SCAN_IDLE_MODE) {
2090 g_st_ts.u8_scan_mode_state = RM_SCAN_PRE_IDLE_MODE;
2091 rm_tch_ctrl_leave_auto_mode();
2095 static u32 rm_tch_slowscan_round(u32 val)
2099 for (i = 0; i < RM_SLOW_SCAN_LEVEL_COUNT; i++) {
2100 if ((i * RM_SLOW_SCAN_INTERVAL) >= val)
2104 if (i > RM_SLOW_SCAN_LEVEL_MAX)
2105 i = RM_SLOW_SCAN_LEVEL_MAX;
2110 static ssize_t rm_tch_slowscan_handler(const char *buf, size_t count)
2119 ret = (ssize_t) count;
2122 if (buf[0] == '0') {
2123 mutex_lock(&g_st_ts.mutex_scan_mode);
2124 g_st_ts.b_enable_slow_scan = false;
2125 rm_tch_ctrl_slowscan(RM_SLOW_SCAN_LEVEL_MAX);
2126 mutex_unlock(&g_st_ts.mutex_scan_mode);
2127 } else if (buf[0] == '1') {
2128 mutex_lock(&g_st_ts.mutex_scan_mode);
2129 g_st_ts.b_enable_slow_scan = true;
2130 rm_tch_ctrl_slowscan(RM_SLOW_SCAN_LEVEL_60);
2131 mutex_unlock(&g_st_ts.mutex_scan_mode);
2133 } else if ((buf[0] == '2') && (buf[1] == ' ')) {
2134 error = kstrtoul(&buf[2], 10, &val);
2139 mutex_lock(&g_st_ts.mutex_scan_mode);
2140 g_st_ts.b_enable_slow_scan = true;
2141 rm_tch_ctrl_slowscan(rm_tch_slowscan_round((u32)val));
2142 mutex_unlock(&g_st_ts.mutex_scan_mode);
2149 static ssize_t rm_tch_slowscan_show(struct device *dev,
2150 struct device_attribute *attr, char *buf)
2152 #ifdef ENABLE_SLOW_SCAN
2153 return sprintf(buf, "Slow Scan:%s\nScan Rate:%dHz\n",
2154 g_st_ts.b_enable_slow_scan ?
2155 "Enabled" : "Disabled",
2156 g_st_ts.u32_slow_scan_level * RM_SLOW_SCAN_INTERVAL);
2158 return sprintf(buf, "Not implemented yet\n");
2162 static ssize_t rm_tch_slowscan_store(struct device *dev,
2163 struct device_attribute *attr,
2164 const char *buf, size_t count)
2166 #ifdef ENABLE_SLOW_SCAN
2167 return rm_tch_slowscan_handler(buf, count);
2173 static ssize_t rm_tch_touchfile_check_show(struct device *dev,
2174 struct device_attribute *attr,
2177 return sprintf(buf, "0x%x\n",
2178 g_st_ts.u8_touchfile_check);
2181 static ssize_t rm_tch_touchfile_check_store(struct device *dev,
2182 struct device_attribute *attr,
2183 const char *buf, size_t count)
2188 static ssize_t rm_tch_touch_event_show(struct device *dev,
2189 struct device_attribute *attr,
2192 return sprintf(buf, "0x%x\n",
2193 g_st_ts.u8_touch_event);
2196 static ssize_t rm_tch_touch_event_store(struct device *dev,
2197 struct device_attribute *attr,
2198 const char *buf, size_t count)
2203 static void rm_tch_smooth_level_change(unsigned long val)
2207 if (val > RM_SMOOTH_LEVEL_MAX)
2210 g_st_ts.u32_smooth_level = val;
2212 i_info = (RM_SIGNAL_PARA_SMOOTH << 24) |
2214 RM_SIGNAL_CHANGE_PARA;
2216 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid, i_info);
2219 static ssize_t rm_tch_smooth_level_handler(const char *buf, size_t count)
2228 ret = (ssize_t) count;
2229 error = kstrtoul(buf, 10, &val);
2234 rm_tch_smooth_level_change(val);
2239 static ssize_t rm_tch_smooth_level_show(struct device *dev,
2240 struct device_attribute *attr,
2243 return sprintf(buf, "Smooth level:%d\n", g_st_ts.u32_smooth_level);
2246 static ssize_t rm_tch_smooth_level_store(struct device *dev,
2247 struct device_attribute *attr,
2248 const char *buf, size_t count)
2250 rm_tch_smooth_level_handler(buf, count);
2254 void rm_set_kernel_test_para(u8 u8Idx, u8 u8Para)
2256 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
2258 ts->u8_repeat_counter = u8Para;
2259 rm_tch_cmd_process(u8Idx, g_st_rm_kl_testmode_cmd, ts);
2262 static ssize_t rm_tch_testmode_handler(const char *buf, size_t count)
2264 unsigned long val = 0;
2271 ret = (ssize_t) count;
2274 if (buf[0] == '0') {
2275 g_st_ts.u8_test_mode = false;
2276 g_st_ts.u8_test_mode_type = RM_TEST_MODE_NULL;
2277 rm_set_kernel_test_para(0, g_st_ctrl.u8_idle_mode_thd);
2278 } else if (buf[0] == '1') {
2279 g_st_ts.u8_test_mode = true;
2280 g_st_ts.u8_test_mode_type = RM_TEST_MODE_IDLE_SHOW;
2282 } else if ((buf[0] == '2') && (buf[1] == ' ')) {
2283 error = kstrtoul(&buf[2], 10, &val);
2286 if ((buf[2] == '2') && (buf[3] == ' ')) {
2287 g_st_ts.u8_test_mode = true;
2288 g_st_ts.u8_test_mode_type =
2289 RM_TEST_MODE_IDLE_LEVEL;
2290 error = kstrtoul(&buf[4], 10, &val);
2292 g_st_ts.u8_test_mode = false;
2295 rm_set_kernel_test_para(0, val);
2298 g_st_ts.u8_test_mode = false;
2302 g_st_ts.u8_test_mode = true;
2303 g_st_ts.u8_test_mode_type = 1 << ((u8)val - 1);
2305 case RM_TEST_MODE_IDLE_SHOW:
2306 if (g_st_ts.u8_scan_mode_state == RM_SCAN_IDLE_MODE)
2307 #if (ISR_POST_HANDLER == WORK_QUEUE)
2308 queue_work(g_st_ts.rm_workqueue,
2310 #elif (ISR_POST_HANDLER == KTHREAD)
2312 if (waitqueue_active(&g_st_ts.rm_thread_wait_q)) {
2313 g_st_ts.b_thread_active = true;
2314 wake_up_interruptible(&g_st_ts.rm_thread_wait_q);
2316 mutex_lock(&g_st_ts.mutex_irq_wait);
2317 g_st_ts.b_irq_is_waited = true;
2318 mutex_unlock(&g_st_ts.mutex_irq_wait);
2323 case RM_TEST_MODE_IDLE_LEVEL:
2324 if ((buf[2] == '2') && (buf[3] == ' ')) {
2325 error = kstrtoul(&buf[4], 0, &val);
2327 g_st_ts.u8_test_mode = false;
2330 rm_set_kernel_test_para(0, val);
2334 case RM_TEST_MODE_CALC_TIME_SHOW:
2337 g_st_ts.u8_test_mode = false;
2338 g_st_ts.u8_test_mode_type = 0;
2343 rm_printk("Raydium - rm_kernel_test_mode:%s,Type:%d,Para:%d",
2344 g_st_ts.u8_test_mode ?
2345 "Enabled" : "Disabled",
2346 g_st_ts.u8_test_mode_type, (u8)val);
2350 static ssize_t rm_tch_test_mode_show(struct device *dev,
2351 struct device_attribute *attr,
2354 return sprintf(buf, "Test Mode:%s\nType:%d\n",
2355 g_st_ts.u8_test_mode ?
2356 "Enabled" : "Disabled",
2357 g_st_ts.u8_test_mode_type);
2360 static ssize_t rm_tch_test_mode_store(struct device *dev,
2361 struct device_attribute *attr,
2362 const char *buf, size_t count)
2364 g_u8_test_mode_count = count;
2365 memcpy(&g_u8_test_mode_buf, &buf, sizeof(buf));
2367 return rm_tch_testmode_handler(buf, count);
2370 static ssize_t rm_tch_self_test_handler(struct rm_tch_ts *ts,
2371 const char *buf, size_t count)
2378 ret = (ssize_t) count;
2383 if (g_st_ts.u8_selftest_status == RM_SELF_TEST_STATUS_TESTING)
2386 rm_tch_enter_test_mode(1);
2388 g_st_ts.u8_selftest_result = RM_SELF_TEST_RESULT_PASS;
2390 error = kstrtoul(buf, 10, &val);
2394 rm_tch_enter_test_mode(0);
2395 } else if (val == 0) {
2396 rm_tch_enter_test_mode(0);
2397 } else if ((val >= 0x01) && (val <= 0xFF)) {
2398 i_info = (RM_SIGNAL_PARA_SELF_TEST << 24) |
2400 RM_SIGNAL_CHANGE_PARA;
2401 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid, i_info);
2406 static ssize_t selftest_platform_id_gpio_set(struct device *dev,
2407 struct device_attribute *attr,
2408 const char *buf, size_t count)
2413 static ssize_t selftest_platform_id_gpio_get(struct device *dev,
2414 struct device_attribute *attr,
2417 struct rm_spi_ts_platform_data *pdata;
2419 pdata = g_input_dev->dev.parent->platform_data;
2421 buf[0] = (char)pdata->platform_id;
2423 /* Read from data struct */
2424 if (pdata->gpio_sensor_select0)
2426 if (pdata->gpio_sensor_select1)
2431 static ssize_t selftest_enable_set(struct device *dev,
2432 struct device_attribute *attr,
2433 const char *buf, size_t count)
2435 rm_printk("enter test mode buf[0] = %d\n", buf[0]);
2436 rm_tch_enter_test_mode(buf[0]);
2440 static ssize_t selftest_enable_get(struct device *dev,
2441 struct device_attribute *attr,
2447 static ssize_t rm_tch_self_test_show(struct device *dev,
2448 struct device_attribute *attr,
2451 return sprintf(buf, "Self_Test:Status:%d ,Result:%d\n",
2452 g_st_ts.u8_selftest_status,
2453 g_st_ts.u8_selftest_result);
2456 static ssize_t rm_tch_self_test_store(struct device *dev,
2457 struct device_attribute *attr,
2458 const char *buf, size_t count)
2460 struct rm_tch_ts *ts = dev_get_drvdata(dev);
2461 rm_tch_self_test_handler(ts, buf, count);
2465 static ssize_t rm_tch_version_show(struct device *dev,
2466 struct device_attribute *attr,
2469 return sprintf(buf, "Release V 0x%02X, Test V 0x%02X\n",
2471 g_st_ts.u8_test_version);
2474 static ssize_t rm_tch_version_store(struct device *dev,
2475 struct device_attribute *attr,
2476 const char *buf, size_t count)
2481 static ssize_t rm_tch_module_detect_show(struct device *dev,
2482 struct device_attribute *attr,
2485 return sprintf(buf, "%s\n", "Raydium Touch Module");
2488 static ssize_t rm_tch_module_detect_store(struct device *dev,
2489 struct device_attribute *attr,
2490 const char *buf, size_t count)
2495 static void rm_tch_report_mode_change(unsigned long val)
2499 g_st_ctrl.u8_event_report_mode = (u8)val;
2501 i_info = (RM_SIGNAL_PARA_REPORT_MODE_CHANGE << 24) |
2502 (g_st_ctrl.u8_event_report_mode << 16) |
2503 RM_SIGNAL_REPORT_MODE_CHANGE;
2505 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid, i_info);
2508 static ssize_t rm_tch_report_mode_handler(const char *buf, size_t count)
2517 ret = (ssize_t) count;
2518 error = kstrtoul(buf, 10, &val);
2523 if ((val >= EVENT_REPORT_MODE_STYLUS_ERASER_FINGER) &&
2524 (val < (EVENT_REPORT_MODE_TYPE_NUM |
2525 EVENT_REPORT_MODE_ALL_TYPE_POINTS)))
2526 rm_tch_report_mode_change(val);
2534 static ssize_t rm_tch_report_mode_show(struct device *dev,
2535 struct device_attribute *attr,
2538 return sprintf(buf, "Raydium Touch Report Mode : 0x%x\n",
2539 g_st_ctrl.u8_event_report_mode);
2542 static ssize_t rm_tch_report_mode_store(struct device *dev,
2543 struct device_attribute *attr,
2544 const char *buf, size_t count)
2546 rm_tch_report_mode_handler(buf, count);
2550 static ssize_t selftest_spi_byte_read_get(struct device *dev,
2551 struct device_attribute *attr, char *buf)
2553 buf[0] = g_spi_buf[0];
2557 static ssize_t selftest_spi_byte_read_set(struct device *dev,
2558 struct device_attribute *attr,
2559 const char *buf, size_t count)
2561 return rm_tch_spi_byte_read(buf[0], &g_spi_buf[0]);
2564 static ssize_t selftest_spi_byte_write_get(struct device *dev,
2565 struct device_attribute *attr, char *buf)
2570 static ssize_t selftest_spi_byte_write_set(struct device *dev,
2571 struct device_attribute *attr,
2572 const char *buf, size_t count)
2574 return rm_tch_spi_byte_write(buf[0], buf[1]);
2577 static ssize_t selftest_spi_burst_read_get(struct device *dev,
2578 struct device_attribute *attr, char *buf)
2582 /*rm_printk("selftest_spi_burst_read_get %d", g_spi_bufsize);*/
2583 ret = rm_tch_spi_read(g_spi_addr, buf, g_spi_bufsize);
2584 if (ret == RETURN_OK)
2585 return g_spi_bufsize;
2591 static ssize_t selftest_spi_burst_read_set(struct device *dev,
2592 struct device_attribute *attr,
2593 const char *buf, size_t count)
2595 /*rm_printk("selftest_spi_burst_read_set %d",count);*/
2598 g_spi_addr = buf[0];
2599 g_spi_bufsize = buf[1];
2600 g_spi_bufsize <<= 8;
2601 g_spi_bufsize |= buf[2];
2606 static ssize_t selftest_spi_burst_write_get(struct device *dev,
2607 struct device_attribute *attr, char *buf)
2612 static ssize_t selftest_spi_burst_write_set(struct device *dev,
2613 struct device_attribute *attr,
2614 const char *buf, size_t count)
2616 return rm_tch_spi_write((u8 *)buf, count);
2619 static DEVICE_ATTR(get_platform_id_gpio, 0640,
2620 selftest_platform_id_gpio_get,
2621 selftest_platform_id_gpio_set);
2623 static DEVICE_ATTR(selftest_enable, 0640,
2624 selftest_enable_get,
2625 selftest_enable_set);
2627 static DEVICE_ATTR(selftest_spi_byte_read, 0640,
2628 selftest_spi_byte_read_get,
2629 selftest_spi_byte_read_set);
2631 static DEVICE_ATTR(selftest_spi_byte_write, 0640,
2632 selftest_spi_byte_write_get,
2633 selftest_spi_byte_write_set);
2635 static DEVICE_ATTR(selftest_spi_burst_read, 0640,
2636 selftest_spi_burst_read_get,
2637 selftest_spi_burst_read_set);
2639 static DEVICE_ATTR(selftest_spi_burst_write, 0640,
2640 selftest_spi_burst_write_get,
2641 selftest_spi_burst_write_set);
2643 static DEVICE_ATTR(slowscan_enable, 0640,
2644 rm_tch_slowscan_show,
2645 rm_tch_slowscan_store);
2647 static DEVICE_ATTR(touchfile_check, 0640,
2648 rm_tch_touchfile_check_show,
2649 rm_tch_touchfile_check_store);
2651 static DEVICE_ATTR(touch_event, 0640,
2652 rm_tch_touch_event_show,
2653 rm_tch_touch_event_store);
2655 static DEVICE_ATTR(smooth_level, 0640,
2656 rm_tch_smooth_level_show,
2657 rm_tch_smooth_level_store);
2659 static DEVICE_ATTR(self_test, 0640,
2660 rm_tch_self_test_show,
2661 rm_tch_self_test_store);
2663 static DEVICE_ATTR(version, 0640,
2664 rm_tch_version_show,
2665 rm_tch_version_store);
2667 static DEVICE_ATTR(module_detect, 0640,
2668 rm_tch_module_detect_show,
2669 rm_tch_module_detect_store);
2671 static DEVICE_ATTR(report_mode, 0640,
2672 rm_tch_report_mode_show,
2673 rm_tch_report_mode_store);
2675 static DEVICE_ATTR(test_mode, 0640,
2676 rm_tch_test_mode_show,
2677 rm_tch_test_mode_store);
2679 static struct attribute *rm_ts_attributes[] = {
2680 &dev_attr_get_platform_id_gpio.attr,
2681 &dev_attr_slowscan_enable.attr,
2682 &dev_attr_touchfile_check.attr,
2683 &dev_attr_touch_event.attr,
2684 &dev_attr_selftest_enable.attr,
2685 &dev_attr_selftest_spi_byte_read.attr,
2686 &dev_attr_selftest_spi_byte_write.attr,
2687 &dev_attr_selftest_spi_burst_read.attr,
2688 &dev_attr_selftest_spi_burst_write.attr,
2689 &dev_attr_smooth_level.attr,
2690 &dev_attr_self_test.attr,
2691 &dev_attr_version.attr,
2692 &dev_attr_module_detect.attr,
2693 &dev_attr_report_mode.attr,
2694 &dev_attr_test_mode.attr,
2698 static const struct attribute_group rm_ts_attr_group = {
2699 .attrs = rm_ts_attributes,
2702 static int rm_tch_input_open(struct input_dev *input)
2704 struct rm_tch_ts *ts = input_get_drvdata(input);
2706 rm_tch_enable_irq(ts);
2711 static void rm_tch_input_close(struct input_dev *input)
2713 struct rm_tch_ts *ts = input_get_drvdata(input);
2715 rm_tch_disable_irq(ts);
2718 static irqreturn_t rm_tch_irq(int irq, void *handle)
2720 g_st_ts.u32_watch_dog_cnt = 0;
2722 trace_touchscreen_raydium_irq("Raydium_interrupt");
2724 if (/*g_st_ctrl.u8_power_mode &&*/
2725 (g_st_ts.u8_scan_mode_state == RM_SCAN_IDLE_MODE)) {
2726 input_event(g_input_dev, EV_MSC, MSC_ACTIVITY, 1);
2727 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_B)
2728 input_sync(g_input_dev);
2732 if (g_st_ts.b_init_service && g_st_ts.b_init_finish
2733 && g_st_ts.b_is_suspended == false) {
2734 #if (ISR_POST_HANDLER == WORK_QUEUE)
2735 queue_work(g_st_ts.rm_workqueue, &g_st_ts.rm_work);
2736 #elif (ISR_POST_HANDLER == KTHREAD)
2737 if (waitqueue_active(&g_st_ts.rm_thread_wait_q)) {
2738 g_st_ts.b_thread_active = true;
2739 wake_up_interruptible(&g_st_ts.rm_thread_wait_q);
2741 mutex_lock(&g_st_ts.mutex_irq_wait);
2742 g_st_ts.b_irq_is_waited = true;
2743 mutex_unlock(&g_st_ts.mutex_irq_wait);
2751 static void rm_tch_enter_test_mode(u8 flag)
2753 if (flag) { /*enter test mode*/
2754 g_st_ts.b_selftest_enable = 1;
2755 g_st_ts.u8_selftest_status = RM_SELF_TEST_STATUS_TESTING;
2756 g_st_ts.b_is_suspended = true;
2757 #if (ISR_POST_HANDLER == WORK_QUEUE)
2758 flush_workqueue(g_st_ts.rm_workqueue);
2760 flush_workqueue(g_st_ts.rm_timer_workqueue);
2761 } else { /*leave test mode*/
2762 g_st_ts.b_selftest_enable = 0;
2764 rm_tch_init_ts_structure_part();
2765 g_st_ts.b_is_suspended = false;
2768 rm_tch_cmd_process(flag, g_st_rm_testmode_cmd, NULL);
2771 g_st_ts.u8_selftest_status = RM_SELF_TEST_STATUS_FINISH;
2774 void rm_tch_set_variable(unsigned int index, unsigned int arg)
2776 #if ENABLE_FREQ_HOPPING
2779 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
2782 case RM_VARIABLE_SELF_TEST_RESULT:
2783 g_st_ts.u8_selftest_result = (u8) arg;
2784 rm_tch_enter_test_mode(0);
2786 case RM_VARIABLE_SCRIBER_FLAG:
2787 g_st_ts.b_enable_scriber = (bool) arg;
2789 case RM_VARIABLE_AUTOSCAN_FLAG:
2790 /*g_st_ctrl.u8_power_mode = (bool) arg;*/
2791 mutex_lock(&g_st_ts.mutex_scan_mode);
2792 if (g_st_ts.u8_scan_mode_state == RM_SCAN_ACTIVE_MODE)
2793 g_st_ts.u8_scan_mode_state = RM_SCAN_PRE_IDLE_MODE;
2794 mutex_unlock(&g_st_ts.mutex_scan_mode);
2796 case RM_VARIABLE_TEST_VERSION:
2797 g_st_ts.u8_test_version = (u8) arg;
2799 case RM_VARIABLE_VERSION:
2800 g_st_ts.u8_version = (u8) arg;
2801 dev_info(&g_spi->dev, "Raydium - Firmware v%d.%d\n",
2802 g_st_ts.u8_version, g_st_ts.u8_test_version);
2804 case RM_VARIABLE_IDLEMODECHECK:
2805 g_st_ctrl.u8_idle_mode_check = (u8) arg;
2806 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2807 rm_printk("Raydium - u8_idle_mode_check %2x\n",
2810 case RM_VARIABLE_REPEAT:
2811 /*rm_printk("Raydium - Repeat %d\n", arg);*/
2812 g_st_ts.u8_repeat = (u8) arg;
2813 #if ENABLE_FREQ_HOPPING
2814 g_st_ts.u8_ns_rpt = (u8) arg;
2815 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2816 rm_printk("g_st_ctrl.u8_ns_rpt %d\n",
2820 case RM_VARIABLE_WATCHDOG_FLAG:
2821 rm_ctrl_watchdog_func(arg);
2822 g_st_ctrl.u8_ns_func_enable = ((u8)arg >> 6);
2823 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2824 rm_printk("g_st_ctrl.u8_ns_func_enable %d\n",
2825 g_st_ctrl.u8_ns_func_enable);
2827 case RM_VARIABLE_SET_SPI_UNLOCK:
2828 if (g_st_ts.u8_resume_cnt > 1)
2830 g_st_ts.u8_spi_locked = 0;
2831 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2832 rm_printk("Raydium - SET_SPI_UNLOCK\n");
2834 case RM_VARIABLE_SET_WAKE_UNLOCK:
2835 if (wake_lock_active(&g_st_ts.wakelock_initialization))
2836 wake_unlock(&g_st_ts.wakelock_initialization);
2838 #if ENABLE_FREQ_HOPPING
2839 case RM_VARIABLE_DPW:
2840 mutex_lock(&g_st_ts.mutex_ns_mode);
2841 missing = copy_from_user(&g_st_ts.u8_ns_para[0],
2843 /*missing = copy_from_user(&g_st_ts.bDP[0],
2845 /*missing += copy_from_user(&g_st_ts.bSWCPW[0],
2846 (((u8 *)arg) + 3), 3);*/
2847 /*missing += copy_from_user(&g_st_ts.bSWC[0],
2848 (((u8 *)arg) + 6), 3);*/
2849 mutex_unlock(&g_st_ts.mutex_ns_mode);
2851 dev_err(&g_spi->dev, "Raydium - %s RM_VARIABLE_DPW : copy failed - miss:%d\n",
2853 /*memcpy(&g_st_ts.bDP[0], ((u8 *)arg), 3);*/
2854 /*memcpy(&g_st_ts.bSWCPW[0], (((u8 *)arg) + 3), 3);*/
2855 /*memcpy(&g_st_ts.bSWC[0], (((u8 *)arg) + 6), 3);*/
2856 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2857 rm_printk("g_st_ctrl.DPW 0x%x:0x%x:0x%x # 0x%x:0x%x:0x%x,# 0x%x:0x%x:0x%x\n",
2858 /*g_st_ts.bDP[0], g_st_ts.bDP[1],
2859 g_st_ts.bDP[2], g_st_ts.bSWCPW[0],
2860 g_st_ts.bSWCPW[1], g_st_ts.bSWCPW[2],
2861 g_st_ts.bSWC[0], g_st_ts.bSWC[1],
2863 g_st_ts.u8_ns_para[0], g_st_ts.u8_ns_para[1],
2864 g_st_ts.u8_ns_para[2], g_st_ts.u8_ns_para[3],
2865 g_st_ts.u8_ns_para[4], g_st_ts.u8_ns_para[5],
2866 g_st_ts.u8_ns_para[6], g_st_ts.u8_ns_para[7],
2867 g_st_ts.u8_ns_para[8]);
2869 case RM_VARIABLE_NS_MODE:
2870 mutex_lock(&g_st_ts.mutex_ns_mode);
2871 g_st_ts.u8_ns_mode = (u8)arg;
2872 mutex_unlock(&g_st_ts.mutex_ns_mode);
2873 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2874 rm_printk("g_st_ctrl.u8_ns_mode=%d\n",
2875 g_st_ts.u8_ns_mode);
2878 case RM_VARIABLE_TOUCHFILE_STATUS:
2879 g_st_ts.u8_touchfile_check = (u8)(arg);
2882 case RM_VARIABLE_TOUCH_EVENT:
2883 g_st_ts.u8_touch_event = (u8)(arg);
2884 rm_tch_generate_event(ts, g_st_ts.u8_touch_event);
2893 static u32 rm_tch_get_variable(unsigned int index, u8 *arg)
2895 u32 ret = RETURN_OK;
2897 case RM_VARIABLE_PLATFORM_ID:
2898 ret = rm_tch_get_platform_id((u8 *) arg);
2900 case RM_VARIABLE_GPIO_SELECT:
2901 ret = rm_tch_get_gpio_sensor_select((u8 *) arg);
2903 case RM_VARIABLE_CHECK_SPI_LOCK:
2904 ret = rm_tch_get_spi_lock_status((u8 *) arg);
2913 static void rm_tch_init_ts_structure(void)
2915 g_st_ts.u32_hal_pid = 0;
2916 memset(&g_st_ts, 0, sizeof(struct rm31080a_ts_para));
2918 #ifdef ENABLE_SLOW_SCAN
2919 g_st_ts.u32_slow_scan_level = RM_SLOW_SCAN_LEVEL_MAX;
2922 #if (ISR_POST_HANDLER == WORK_QUEUE)
2923 g_st_ts.rm_workqueue = create_singlethread_workqueue("rm_work");
2924 INIT_WORK(&g_st_ts.rm_work, rm_work_handler);
2925 #elif (ISR_POST_HANDLER == KTHREAD)
2926 init_waitqueue_head(&g_st_ts.rm_thread_wait_q);
2927 g_st_ts.b_thread_active = false;
2928 g_st_ts.b_thread_alive = false;
2929 mutex_init(&g_st_ts.mutex_irq_wait);
2932 g_st_ts.rm_timer_workqueue =
2933 create_singlethread_workqueue("rm_idle_work");
2934 INIT_WORK(&g_st_ts.rm_timer_work, rm_timer_work_handler);
2936 wake_lock_init(&g_st_ts.wakelock_initialization,
2937 WAKE_LOCK_SUSPEND, "TouchInitialLock");
2939 mutex_init(&g_st_ts.mutex_scan_mode);
2940 mutex_init(&g_st_ts.mutex_ns_mode);
2942 g_st_ts.u8_resume_cnt = 0;
2943 g_st_ts.u8_touchfile_check = 0xFF;
2944 g_st_ts.u8_touch_event = 0xFF;
2945 g_st_ts.b_init_service = false;
2946 g_st_ts.u8_test_mode = false;
2950 static int rm31080_voltage_notifier_1v8(struct notifier_block *nb,
2951 unsigned long event, void *ignored)
2953 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2954 rm_printk("Raydium - REGULATOR EVENT 1.8V:0x%x\n",
2955 (unsigned int)event);
2960 static int rm31080_voltage_notifier_3v3(struct notifier_block *nb,
2961 unsigned long event, void *ignored)
2963 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2964 rm_printk("Raydium - REGULATOR EVENT 3.3V:0x%x\n",
2965 (unsigned int)event);
2970 /*===========================================================================*/
2971 static void rm_ctrl_resume(struct rm_tch_ts *ts)
2973 g_st_ts.u8_spi_locked = 1;
2974 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
2975 rm_printk("Raydium - SPI_LOCKED by resume!!\n");
2977 mutex_lock(&g_st_ts.mutex_scan_mode);
2978 rm_tch_init_ts_structure_part();
2979 rm_tch_cmd_process(0, g_st_rm_resume_cmd, ts);
2980 mutex_unlock(&g_st_ts.mutex_scan_mode);
2982 if (g_st_ts.u8_test_mode)
2983 rm_tch_testmode_handler(g_u8_test_mode_buf,
2984 g_u8_test_mode_count);
2987 static void rm_ctrl_suspend(struct rm_tch_ts *ts)
2989 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_B)
2992 if (g_st_ts.b_is_suspended == true)
2995 g_st_ts.b_is_suspended = true;
2996 g_st_ts.b_init_finish = 0;
2998 if (g_st_ts.u8_scan_mode_state == RM_SCAN_IDLE_MODE)
2999 rm_ctrl_pause_auto_mode();
3001 rm_tch_ctrl_wait_for_scan_finish(0);
3003 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_B)
3004 for (i = 0; i < MAX_SUPPORT_SLOT_AMOUNT; i++) {
3005 input_mt_slot(g_input_dev, i);
3007 input_mt_report_slot_state(
3009 MT_TOOL_PEN, false);
3013 BTN_STYLUS2, false);
3015 input_sync(g_input_dev);
3018 #if (ISR_POST_HANDLER == KTHREAD)
3019 if (!IS_ERR(g_st_ts.rm_irq_post_thread)) {
3020 g_st_ts.b_thread_active = true;
3021 wake_up_interruptible(&g_st_ts.rm_thread_wait_q);
3022 if (kthread_stop(g_st_ts.rm_irq_post_thread)) {
3023 if (g_st_ctrl.u8_kernel_msg & DEBUG_KTHREAD)
3024 rm_printk("Raydium - Kill IRQ poster failed!\n");
3026 g_st_ts.b_thread_alive = false;
3027 if (g_st_ctrl.u8_kernel_msg & DEBUG_KTHREAD)
3028 rm_printk("Raydium - Kill IRQ poster successfully!\n");
3031 if (g_st_ctrl.u8_kernel_msg & DEBUG_KTHREAD)
3032 rm_printk("Raydium - No IRQ poster exist!\n");
3035 mutex_lock(&g_st_ts.mutex_scan_mode);
3036 rm_tch_cmd_process(0, g_st_rm_suspend_cmd, ts);
3037 rm_tch_ctrl_wait_for_scan_finish(0);
3038 rm_tch_cmd_process(1, g_st_rm_suspend_cmd, ts);
3039 mutex_unlock(&g_st_ts.mutex_scan_mode);
3040 g_st_ts.u8_spi_locked = 1;
3041 if (g_st_ctrl.u8_kernel_msg & DEBUG_DRIVER)
3042 rm_printk("Raydium - SPI_LOCKED by suspend!!\n");
3047 static int rm_tch_suspend(struct device *dev)
3049 struct rm_tch_ts *ts = dev_get_drvdata(dev);
3050 if (g_st_ts.b_init_service) {
3051 dev_info(ts->dev, "Raydium - Disable input device\n");
3052 rm_ctrl_suspend(ts);
3053 dev_info(ts->dev, "Raydium - Disable input device done\n");
3058 static int rm_tch_resume(struct device *dev)
3060 struct rm_tch_ts *ts = dev_get_drvdata(dev);
3062 if (g_st_ts.b_init_service) {
3063 dev_info(ts->dev, "Raydium - Enable input device\n");
3064 if (wake_lock_active(&g_st_ts.wakelock_initialization))
3065 wake_unlock(&g_st_ts.wakelock_initialization);
3066 wake_lock_timeout(&g_st_ts.wakelock_initialization,
3067 TCH_WAKE_LOCK_TIMEOUT);
3073 #ifdef CONFIG_HAS_EARLYSUSPEND
3074 static void rm_tch_early_suspend(struct early_suspend *es)
3076 struct rm_tch_ts *ts;
3079 #if !(ENABLE_FB_CALLBACK && defined(CONFIG_FB))
3080 ts = container_of(es, struct rm_tch_ts, early_suspend);
3083 if (rm_tch_suspend(dev))
3084 dev_err(dev, "Raydium - %s : failed\n", __func__);
3088 static void rm_tch_early_resume(struct early_suspend *es)
3090 struct rm_tch_ts *ts;
3092 #if !(ENABLE_FB_CALLBACK && defined(CONFIG_FB))
3093 ts = container_of(es, struct rm_tch_ts, early_suspend);
3096 if (rm_tch_resume(dev))
3097 dev_err(dev, "Raydium - %s : failed\n", __func__);
3100 #endif /*CONFIG_HAS_EARLYSUSPEND*/
3101 #endif /*CONFIG_PM*/
3103 /* NVIDIA 20121026 */
3104 /* support to disable power and clock when display is off */
3105 static int rm_tch_input_enable(struct input_dev *in_dev)
3107 int error = RETURN_OK;
3109 #if !(ENABLE_FB_CALLBACK && defined(CONFIG_FB))
3111 struct rm_tch_ts *ts = input_get_drvdata(in_dev);
3113 error = rm_tch_resume(ts->dev);
3115 dev_err(ts->dev, "Raydium - %s : failed\n", __func__);
3121 static int rm_tch_input_disable(struct input_dev *in_dev)
3123 int error = RETURN_OK;
3125 #if !(ENABLE_FB_CALLBACK && defined(CONFIG_FB))
3127 struct rm_tch_ts *ts = input_get_drvdata(in_dev);
3129 error = rm_tch_suspend(ts->dev);
3131 dev_err(ts->dev, "Raydium - %s : failed\n", __func__);
3138 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
3139 static int rm_fb_notifier_callback(struct notifier_block *self,
3140 unsigned long event, void *data)
3142 struct fb_event *evdata = data;
3144 struct rm_tch_ts *ts = container_of(self,
3145 struct rm_tch_ts, fb_notifier);
3146 if (g_st_ts.b_init_service && evdata && evdata->data
3147 && event == FB_EVENT_BLANK) {
3148 blank = evdata->data;
3149 if (*blank == FB_BLANK_UNBLANK)
3150 rm_tch_resume(ts->dev);
3151 else if (*blank == FB_BLANK_POWERDOWN)
3152 rm_tch_suspend(ts->dev);
3158 #if defined(CONFIG_TRUSTED_LITTLE_KERNEL)
3159 /*===========================================================================*/
3160 void raydium_tlk_ns_touch_suspend(void)
3162 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
3164 rm_printk("tlk_ns_touch_suspend\n");
3166 rm_tch_enter_manual_mode();
3167 mutex_lock(&g_st_ts.mutex_scan_mode);
3168 mutex_lock(&g_st_ts.mutex_ns_mode);
3169 rm_tch_cmd_process(0, g_st_rm_tlk_cmd, ts);
3171 EXPORT_SYMBOL(raydium_tlk_ns_touch_suspend);
3173 /*===========================================================================*/
3174 void raydium_tlk_ns_touch_resume(void)
3176 struct rm_tch_ts *ts = input_get_drvdata(g_input_dev);
3178 rm_printk("tlk_ns_touch_resume\n");
3180 rm_tch_ts_send_signal(g_st_ts.u32_hal_pid, 0x03);
3181 rm_tch_cmd_process(1, g_st_rm_tlk_cmd, ts);
3183 mutex_unlock(&g_st_ts.mutex_scan_mode);
3184 mutex_unlock(&g_st_ts.mutex_ns_mode);
3186 EXPORT_SYMBOL(raydium_tlk_ns_touch_resume);
3187 /*===========================================================================*/
3188 #endif /*CONFIG_TRUSTED_LITTLE_KERNEL*/
3190 static void rm_tch_set_input_resolution(unsigned int x, unsigned int y)
3192 input_set_abs_params(g_input_dev, ABS_MT_POSITION_X, 0, x - 1, 0, 0);
3193 input_set_abs_params(g_input_dev, ABS_MT_POSITION_Y, 0, y - 1, 0, 0);
3196 static struct rm_spi_ts_platform_data *rm_ts_parse_dt(struct device *dev,
3199 struct rm_spi_ts_platform_data *pdata;
3200 struct device_node *np = dev->of_node;
3202 int ret, val, irq_gpio;
3204 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
3206 return ERR_PTR(-ENOMEM);
3208 pdata->gpio_reset = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL);
3209 if (!gpio_is_valid(pdata->gpio_reset)) {
3210 dev_err(dev, "Invalid reset-gpio\n");
3211 return ERR_PTR(-EINVAL);
3213 ret = gpio_request(pdata->gpio_reset, "reset-gpio");
3215 dev_err(dev, "gpio_request fail\n");
3216 return ERR_PTR(-EINVAL);
3218 gpio_direction_output(pdata->gpio_reset, 0);
3220 ret = of_property_read_u32(np, "interrupts", &irq_gpio);
3221 if (!gpio_is_valid(irq_gpio)) {
3222 dev_err(dev, "Invalid irq-gpio\n");
3224 goto exit_release_reset_gpio;
3227 ret = gpio_request(irq_gpio, "irq-gpio");
3229 dev_err(dev, "irq_request fail\n");
3231 goto exit_release_reset_gpio;
3233 gpio_direction_input(irq_gpio);
3235 ret = of_property_read_u32(np, "config", &val);
3237 goto exit_release_all_gpio;
3238 pdata->config = (unsigned char *)val;
3240 ret = of_property_read_u32(np, "platform-id", &val);
3242 goto exit_release_all_gpio;
3243 pdata->platform_id = val;
3245 ret = of_property_read_string(np, "name-of-clock", &str);
3247 goto exit_release_all_gpio;
3248 pdata->name_of_clock = (char *)str;
3250 ret = of_property_read_string(np, "name-of-clock-con", &str);
3252 goto exit_release_all_gpio;
3253 pdata->name_of_clock_con = (char *)str;
3257 exit_release_all_gpio:
3258 gpio_free(irq_gpio);
3260 exit_release_reset_gpio:
3261 gpio_free(pdata->gpio_reset);
3262 return ERR_PTR(ret);
3265 struct rm_tch_ts *rm_tch_input_init(struct device *dev, unsigned int irq,
3266 const struct rm_tch_bus_ops *bops)
3268 struct rm_tch_ts *ts;
3269 struct input_dev *input_dev;
3270 struct rm_spi_ts_platform_data *pdata;
3274 dev_err(dev, "Raydium - no IRQ?\n");
3279 ts = kzalloc(sizeof(struct rm_tch_ts), GFP_KERNEL);
3281 input_dev = input_allocate_device();
3283 if (!ts || !input_dev) {
3284 dev_err(dev, "Raydium - Failed to allocate memory\n");
3289 g_input_dev = input_dev;
3293 ts->input = input_dev;
3298 pr_info("Load platform data from DT.\n");
3299 pdata = rm_ts_parse_dt(dev, irq);
3300 if (IS_ERR(pdata)) {
3301 dev_err(&g_spi->dev, "Raydium - failed to parse dt\n");
3305 dev->platform_data = pdata;
3308 pdata = dev->platform_data;
3310 if (pdata->name_of_clock || pdata->name_of_clock_con) {
3311 ts->clk = clk_get_sys(pdata->name_of_clock,
3312 pdata->name_of_clock_con);
3313 if (IS_ERR(ts->clk)) {
3314 dev_err(&g_spi->dev, "Raydium - failed to get touch_clk: (%s, %s)\n",
3315 pdata->name_of_clock, pdata->name_of_clock_con);
3321 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev));
3323 input_dev->name = "touch";
3324 input_dev->phys = ts->phys;
3325 input_dev->dev.parent = dev;
3326 input_dev->id.bustype = bops->bustype;
3328 input_dev->enable = rm_tch_input_enable;
3329 input_dev->disable = rm_tch_input_disable;
3330 input_dev->enabled = true;
3331 input_dev->open = rm_tch_input_open;
3332 input_dev->close = rm_tch_input_close;
3333 input_dev->hint_events_per_packet = 256U;
3335 input_set_drvdata(input_dev, ts);
3336 input_set_capability(input_dev, EV_MSC, MSC_ACTIVITY);
3338 #if (INPUT_PROTOCOL_CURRENT_SUPPORT == INPUT_PROTOCOL_TYPE_A)
3339 __set_bit(EV_ABS, input_dev->evbit);
3340 input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 0xFF, 0, 0);
3341 input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 32, 0, 0);
3343 __set_bit(EV_KEY, input_dev->evbit);
3344 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3346 __set_bit(EV_KEY, input_dev->evbit);
3347 __set_bit(EV_ABS, input_dev->evbit);
3348 input_set_abs_params(input_dev, ABS_MT_PRESSURE,
3351 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
3352 #ifdef INPUT_MT_DIRECT
3353 input_mt_init_slots(input_dev,
3354 MAX_SUPPORT_SLOT_AMOUNT,
3357 input_mt_init_slots(input_dev,
3358 MAX_SUPPORT_SLOT_AMOUNT);
3361 input_set_abs_params(input_dev,
3362 ABS_MT_TOOL_TYPE, 0,
3365 rm_tch_set_input_resolution(RM_INPUT_RESOLUTION_X,
3366 RM_INPUT_RESOLUTION_Y);
3368 err = request_threaded_irq(ts->irq, NULL, rm_tch_irq,
3369 IRQF_TRIGGER_RISING | IRQF_ONESHOT, dev_name(dev), ts);
3371 dev_err(dev, "Raydium - irq %d busy?\n", ts->irq);
3374 mutex_init(&ts->access_mutex);
3375 #ifdef CONFIG_HAS_EARLYSUSPEND
3376 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
3377 ts->early_suspend.suspend = rm_tch_early_suspend;
3378 ts->early_suspend.resume = rm_tch_early_resume;
3379 register_early_suspend(&ts->early_suspend);
3382 rm_tch_disable_irq(ts);
3384 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
3385 ts->fb_notifier.notifier_call = rm_fb_notifier_callback;
3386 err = fb_register_client(&ts->fb_notifier);
3388 dev_err(dev, "Raydium - Unable to register fb_notifier: %d\n"
3394 err = sysfs_create_group(&dev->kobj, &rm_ts_attr_group);
3395 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
3397 goto err_unregister_fb;
3403 err = input_register_device(input_dev);
3405 goto err_remove_attr;
3410 sysfs_remove_group(&dev->kobj, &rm_ts_attr_group);
3411 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
3413 fb_unregister_client(&ts->fb_notifier);
3416 free_irq(ts->irq, ts);
3418 input_free_device(input_dev);
3421 return ERR_PTR(err);
3424 static int dev_open(struct inode *inode, struct file *filp)
3429 static int dev_release(struct inode *inode, struct file *filp)
3431 g_st_ts.b_init_finish = 0;
3433 rm_tch_enter_manual_mode();
3438 dev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos)
3440 ssize_t missing, status;
3444 p_u8_my_buf = kmalloc(count, GFP_KERNEL);
3445 if (p_u8_my_buf == NULL)
3448 p_u8_my_buf[0] = buf[0];
3449 ret = rm_tch_spi_read(p_u8_my_buf[0], p_u8_my_buf, count);
3453 rm_printk("Raydium - rm_tch_spi_read() fail\n");
3456 missing = copy_to_user(buf, p_u8_my_buf, count);
3459 if (missing == status)
3462 status = status - missing;
3470 static ssize_t dev_write(struct file *filp,
3471 const char __user *buf, size_t count, loff_t *pos)
3475 unsigned long missing;
3478 p_u8_my_buf = kmalloc(count, GFP_KERNEL);
3479 if (p_u8_my_buf == NULL)
3482 missing = copy_from_user(p_u8_my_buf, buf, count);
3486 ret = rm_tch_spi_write(p_u8_my_buf, count);
3497 /*=============================================================================
3507 Note: To avoid context switch,please don't add debug message
3509 =============================================================================*/
3510 static long dev_ioctl(struct file *file,
3511 unsigned int u8_cmd, unsigned long arg)
3513 long ret = RETURN_OK;
3516 index = (u8_cmd >> 16) & 0xFFFF;
3518 switch (u8_cmd & 0xFFFF) {
3519 case RM_IOCTL_REPORT_POINT:
3520 raydium_report_pointer((void *)(arg & MASK_USER_SPACE_POINTER));
3522 case RM_IOCTL_FINISH_CALC:
3523 g_st_ts.b_calc_finish = 1;
3525 case RM_IOCTL_READ_RAW_DATA:
3526 ret = rm_tch_queue_read_raw_data(
3527 (u8 *)(arg & MASK_USER_SPACE_POINTER),
3530 case RM_IOCTL_GET_SACN_MODE:
3531 ret = rm_tch_ctrl_get_idle_mode(
3532 (u8 *)(arg & MASK_USER_SPACE_POINTER));
3534 case RM_IOCTL_SET_HAL_PID:
3535 g_st_ts.u32_hal_pid = (u32)arg;
3537 case RM_IOCTL_WATCH_DOG:
3538 g_st_ts.u8_watch_dog_flg = 1;
3539 g_st_ts.b_watch_dog_check = 0;
3541 case RM_IOCTL_GET_VARIABLE:
3542 ret = rm_tch_get_variable(index,
3543 ((u8 *)(arg & MASK_USER_SPACE_POINTER)));
3545 case RM_IOCTL_INIT_START:
3546 g_st_ts.b_init_finish = 0;
3547 rm_tch_enter_manual_mode();
3549 case RM_IOCTL_INIT_END:
3550 g_st_ts.b_init_finish = 1;
3551 g_st_ts.b_calc_finish = 1;
3552 g_st_ts.b_is_suspended = false;
3553 if (g_st_ts.u8_resume_cnt) /* In case issued by boot-up*/
3554 g_st_ts.u8_resume_cnt--;
3555 if (wake_lock_active(&g_st_ts.wakelock_initialization))
3556 wake_unlock(&g_st_ts.wakelock_initialization);
3557 #if (ISR_POST_HANDLER == KTHREAD)
3558 if (!g_st_ts.b_thread_alive) {
3559 g_st_ts.thread_sched.sched_priority =
3560 MAX_USER_RT_PRIO / 2;
3561 g_st_ts.rm_irq_post_thread =
3562 kthread_run(rm_work_thread_function,
3563 NULL, "RaydiumIrq_Poster");
3564 if (IS_ERR(g_st_ts.rm_irq_post_thread)) {
3565 if (g_st_ctrl.u8_kernel_msg & DEBUG_KTHREAD)
3566 rm_printk("Raydium - Create IRQ poster failed!\n");
3568 g_st_ts.b_thread_active = false;
3569 g_st_ts.b_thread_alive = true;
3570 mutex_lock(&g_st_ts.mutex_irq_wait);
3571 g_st_ts.b_irq_is_waited = false;
3572 mutex_unlock(&g_st_ts.mutex_irq_wait);
3573 if (g_st_ctrl.u8_kernel_msg & DEBUG_KTHREAD)
3574 rm_printk("Raydium - Create IRQ poster successfully!\n");
3577 if (g_st_ctrl.u8_kernel_msg & DEBUG_KTHREAD)
3578 rm_printk("Raydium - IRQ poster is alive!\n");
3581 rm_printk("Raydium - Enable input device done\n");
3583 case RM_IOCTL_SCRIBER_CTRL:
3584 g_st_ts.b_enable_scriber = (bool) arg;
3586 case RM_IOCTL_SET_PARAMETER:
3587 rm_tch_ctrl_set_parameter(
3588 (void *)(arg & MASK_USER_SPACE_POINTER));
3589 rm_tch_set_input_resolution(g_st_ctrl.u16_resolution_x,
3590 g_st_ctrl.u16_resolution_y);
3592 case RM_IOCTL_SET_BASELINE:
3593 rm_tch_ctrl_set_baseline(
3594 (u8 *)(arg & MASK_USER_SPACE_POINTER),
3595 g_st_ctrl.u16_data_length);
3597 case RM_IOCTL_SET_VARIABLE:
3598 rm_tch_set_variable(index, arg);
3600 case RM_IOCTL_SET_KRL_TBL:
3601 ret = rm_set_kernel_tbl(index,
3602 ((u8 *)(arg & MASK_USER_SPACE_POINTER)));
3604 case RM_IOCTL_INIT_SERVICE:
3605 g_st_ts.b_init_service = true;
3615 static const struct file_operations dev_fops = {
3616 .owner = THIS_MODULE,
3618 .release = dev_release,
3621 .unlocked_ioctl = dev_ioctl,
3624 static struct miscdevice raydium_ts_miscdev = {
3625 .minor = MISC_DYNAMIC_MINOR,
3630 static const struct rm_tch_bus_ops rm_tch_spi_bus_ops = {
3634 static void init_ts_timer(void)
3636 init_timer(&ts_timer_triggle);
3637 ts_timer_triggle.function = ts_timer_triggle_function;
3638 ts_timer_triggle.data = ((unsigned long) 0);
3639 ts_timer_triggle.expires = jiffies + TS_TIMER_PERIOD;
3642 static void ts_timer_triggle_function(unsigned long option)
3644 queue_work(g_st_ts.rm_timer_workqueue, &g_st_ts.rm_timer_work);
3645 ts_timer_triggle.expires = jiffies + TS_TIMER_PERIOD;
3646 add_timer(&ts_timer_triggle);
3649 /*===========================================================================*/
3650 #if ENABLE_SPI_SETTING
3651 static int rm_tch_spi_setting(u32 speed)
3654 if ((speed == 0) || (speed > 18))
3657 g_spi->max_speed_hz = speed * 1000 * 1000;
3658 err = spi_setup(g_spi);
3660 dev_dbg(&g_spi->dev, "Raydium - Change SPI setting failed\n");
3667 static int rm_tch_spi_remove(struct spi_device *spi)
3669 struct rm_tch_ts *ts = spi_get_drvdata(spi);
3671 del_timer(&ts_timer_triggle);
3672 if (g_st_ts.rm_timer_workqueue)
3673 destroy_workqueue(g_st_ts.rm_timer_workqueue);
3675 rm_tch_queue_free();
3677 #if (ISR_POST_HANDLER == WORK_QUEUE)
3678 if (g_st_ts.rm_workqueue)
3679 destroy_workqueue(g_st_ts.rm_workqueue);
3682 if (&g_st_ts.wakelock_initialization)
3683 wake_lock_destroy(&g_st_ts.wakelock_initialization);
3685 mutex_destroy(&g_st_ts.mutex_scan_mode);
3686 mutex_destroy(&g_st_ts.mutex_ns_mode);
3688 sysfs_remove_group(&raydium_ts_miscdev.this_device->kobj,
3690 misc_deregister(&raydium_ts_miscdev);
3691 sysfs_remove_group(&ts->dev->kobj, &rm_ts_attr_group);
3692 free_irq(ts->irq, ts);
3693 input_unregister_device(ts->input);
3695 #if ENABLE_FB_CALLBACK && defined(CONFIG_FB)
3696 fb_unregister_client(&ts->fb_notifier);
3699 if (ts->regulator_3v3 && ts->regulator_1v8) {
3700 regulator_unregister_notifier(ts->regulator_3v3, &ts->nb_3v3);
3701 regulator_unregister_notifier(ts->regulator_1v8, &ts->nb_1v8);
3702 regulator_disable(ts->regulator_3v3);
3703 regulator_disable(ts->regulator_1v8);
3707 clk_disable(ts->clk);
3710 spi_set_drvdata(spi, NULL);
3715 static int rm_tch_regulator_init(struct rm_tch_ts *ts)
3719 ts->regulator_3v3 = devm_regulator_get(&g_spi->dev, "avdd");
3720 if (IS_ERR(ts->regulator_3v3)) {
3721 dev_err(&g_spi->dev, "Raydium - regulator_get failed: %ld\n",
3722 PTR_ERR(ts->regulator_3v3));
3723 goto err_null_regulator;
3726 ts->regulator_1v8 = devm_regulator_get(&g_spi->dev, "dvdd");
3727 if (IS_ERR(ts->regulator_1v8)) {
3728 dev_err(&g_spi->dev, "Raydium - regulator_get failed: %ld\n",
3729 PTR_ERR(ts->regulator_1v8));
3730 goto err_null_regulator;
3733 /* Enable 1v8 first*/
3734 if (regulator_is_enabled(ts->regulator_1v8))
3735 rm_printk("Raydium - %s : 1.8V regulator is already enabled!\n",
3738 error = regulator_enable(ts->regulator_1v8);
3740 dev_err(&g_spi->dev,
3741 "Raydium - 1.8V regulator enable failed: %d\n", error);
3742 goto err_null_regulator;
3745 usleep_range(5000, 6000);
3746 /* Enable 3v3 then*/
3747 if (regulator_is_enabled(ts->regulator_3v3))
3748 rm_printk("Raydium - %s : 3.3V regulator is already enabled!\n",
3750 error = regulator_enable(ts->regulator_3v3);
3752 dev_err(&g_spi->dev,
3753 "Raydium - regulator enable failed: %d\n", error);
3754 goto err_disable_1v8_regulator;
3757 ts->nb_1v8.notifier_call = &rm31080_voltage_notifier_1v8;
3758 error = regulator_register_notifier(ts->regulator_1v8, &ts->nb_1v8);
3760 dev_err(&g_spi->dev,
3761 "Raydium - regulator notifier request failed: %d\n",
3763 goto err_disable_regulator;
3766 ts->nb_3v3.notifier_call = &rm31080_voltage_notifier_3v3;
3767 error = regulator_register_notifier(ts->regulator_3v3, &ts->nb_3v3);
3769 dev_err(&g_spi->dev,
3770 "Raydium - regulator notifier request failed: %d\n",
3772 goto err_unregister_notifier;
3777 err_unregister_notifier:
3778 regulator_unregister_notifier(ts->regulator_1v8, &ts->nb_1v8);
3779 err_disable_regulator:
3780 regulator_disable(ts->regulator_3v3);
3781 err_disable_1v8_regulator:
3782 regulator_disable(ts->regulator_1v8);
3784 ts->regulator_3v3 = NULL;
3785 ts->regulator_1v8 = NULL;
3789 static int rm_tch_spi_probe(struct spi_device *spi)
3791 struct rm_tch_ts *ts;
3792 struct rm_spi_ts_platform_data *pdata;
3797 rm_tch_init_ts_structure();
3798 rm_tch_init_ts_structure_part();
3800 if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
3801 dev_err(&spi->dev, "Raydium - SPI CLK %d Hz?\n",
3806 ts = rm_tch_input_init(&spi->dev, spi->irq, &rm_tch_spi_bus_ops);
3808 dev_err(&spi->dev, "Raydium - Input Device Initialization Fail!\n");
3813 spi_set_drvdata(spi, ts);
3815 if (rm_tch_regulator_init(ts)) {
3816 dev_err(&spi->dev, "Raydium - regulator Initialization Fail!\n");
3818 goto err_regulator_init;
3820 pdata = g_input_dev->dev.parent->platform_data;
3821 usleep_range(5000, 6000);
3823 clk_enable(ts->clk);
3825 gpio_set_value(pdata->gpio_reset, 0);
3827 gpio_set_value(pdata->gpio_reset, 1);
3830 ret = misc_register(&raydium_ts_miscdev);
3832 dev_err(&spi->dev, "Raydium - cannot register miscdev: %d\n",
3836 ret = sysfs_create_group(&raydium_ts_miscdev.this_device->kobj,
3839 dev_err(&spi->dev, "Raydium - cannot create group: %d\n",
3841 goto err_create_sysfs;
3844 ret = rm_tch_queue_init();
3846 dev_err(&spi->dev, "Raydium - could not init queue: %d\n",
3848 goto err_queue_init;
3852 add_timer(&ts_timer_triggle);
3854 rm_printk("Raydium - Spi Probe Done!!\n");
3858 sysfs_remove_group(&raydium_ts_miscdev.this_device->kobj,
3861 misc_deregister(&raydium_ts_miscdev);
3863 if (ts->regulator_3v3 && ts->regulator_1v8) {
3864 regulator_unregister_notifier(ts->regulator_3v3, &ts->nb_3v3);
3865 regulator_unregister_notifier(ts->regulator_1v8, &ts->nb_1v8);
3866 regulator_disable(ts->regulator_3v3);
3867 regulator_disable(ts->regulator_1v8);
3871 clk_disable(ts->clk);
3874 spi_set_drvdata(spi, NULL);
3875 input_unregister_device(ts->input);
3876 sysfs_remove_group(&ts->dev->kobj, &rm_ts_attr_group);
3877 #ifdef CONFIG_HAS_EARLYSUSPEND
3878 unregister_early_suspend(&ts->early_suspend);
3880 mutex_destroy(&ts->access_mutex);
3881 free_irq(ts->irq, ts);
3882 input_free_device(g_input_dev);
3885 if (g_st_ts.rm_timer_workqueue)
3886 destroy_workqueue(g_st_ts.rm_timer_workqueue);
3887 #if (ISR_POST_HANDLER == WORK_QUEUE)
3888 if (g_st_ts.rm_workqueue)
3889 destroy_workqueue(g_st_ts.rm_workqueue);
3891 mutex_destroy(&g_st_ts.mutex_scan_mode);
3892 mutex_destroy(&g_st_ts.mutex_ns_mode);
3896 static const struct of_device_id rm_ts_dt_match[] = {
3897 { .compatible = "raydium, rm_ts_spidev" },
3900 MODULE_DEVICE_TABLE(of, rm_ts_dt_match);
3902 static struct spi_driver rm_tch_spi_driver = {
3904 .name = "rm_ts_spidev",
3905 .bus = &spi_bus_type,
3906 .owner = THIS_MODULE,
3908 .of_match_table = rm_ts_dt_match,
3911 .probe = rm_tch_spi_probe,
3912 .remove = rm_tch_spi_remove,
3915 static int __init rm_tch_spi_init(void)
3917 return spi_register_driver(&rm_tch_spi_driver);
3920 static void __exit rm_tch_spi_exit(void)
3922 spi_unregister_driver(&rm_tch_spi_driver);
3925 module_init(rm_tch_spi_init);
3926 module_exit(rm_tch_spi_exit);
3928 MODULE_AUTHOR("Valentine Hsu <valentine.hsu@rad-ic.com>");
3929 MODULE_DESCRIPTION("Raydium touchscreen SPI bus driver");
3930 MODULE_LICENSE("GPL");
3931 MODULE_ALIAS("spi:raydium-t007");