MTK touchscreen 流程

1. kernel-3.18/drivers/input/touchscreen/mediatek/tpd_common_probe.c

1 static int __init tpd_probe_init(void)
2 {
3     tpd_device_init();
4     return 0;
5 }

2. kernel-3.18/drivers/input/touchscreen/mediatek/mtk_tpd.c

 1 int tpd_device_init(void)
 2 {
 3     int res = 0;
 4 
 5     tpd_init_workqueue = create_singlethread_workqueue("mtk-tpd");
 6     INIT_WORK(&tpd_init_work, tpd_init_work_callback);
 7 
 8     res = queue_work(tpd_init_workqueue, &tpd_init_work);
 9     if (!res)
10         pr_err("tpd : touch device init failed res:%d\n", res);
11     return 0;
12 }

 3. kernel-3.18/drivers/input/touchscreen/mediatek/mtk_tpd.c

1 /* called when loaded into kernel */
2 static void tpd_init_work_callback(struct work_struct *work)
3 {
4     TPD_DEBUG("MediaTek touch panel driver init\n");
5     
6     if (platform_driver_register(&tpd_driver) != 0)
7         TPD_DMESG("unable to register touch panel driver.\n");
8 }

platform_device 和 platform_driver 匹配后,调用tpd_probe

 1 static struct platform_driver tpd_driver = {
 2     .remove = tpd_remove,
 3     .shutdown = NULL,
 4     .probe = tpd_probe,
 5     .driver = {
 6             .name = TPD_DEVICE,
 7             .pm = &tpd_pm_ops,
 8             .owner = THIS_MODULE,
 9             .of_match_table = touch_of_match,
10     },
11 };
  1 /* touch panel probe */
  2 static int tpd_probe(struct platform_device *pdev)
  3 {
  4     int touch_type = 1;    /* 0:R-touch, 1: Cap-touch */
  5     int i = 0;
  6 #ifndef CONFIG_CUSTOM_LCM_X
  7 #ifdef CONFIG_LCM_WIDTH
  8     unsigned long tpd_res_x = 0, tpd_res_y = 0;
  9     int ret = 0;
 10 #endif
 11 #endif
 12 
 13     TPD_DMESG("enter %s, %d\n", __func__, __LINE__);
 14 
 15     if (misc_register(&tpd_misc_device))
 16         pr_err("mtk_tpd: tpd_misc_device register failed\n");
 17     tpd_get_gpio_info(pdev);
 18     tpd = kmalloc(sizeof(struct tpd_device), GFP_KERNEL);
 19     if (tpd == NULL)
 20         return -ENOMEM;
 21     memset(tpd, 0, sizeof(struct tpd_device));
 22 
 23     /* allocate input device */
 24     tpd->dev = input_allocate_device();
 25     if (tpd->dev == NULL) {
 26         kfree(tpd);
 27         return -ENOMEM;
 28     }
 29     /* TPD_RES_X = simple_strtoul(LCM_WIDTH, NULL, 0); */
 30     /* TPD_RES_Y = simple_strtoul(LCM_HEIGHT, NULL, 0); */
 31 
 32     #ifdef CONFIG_MTK_LCM_PHYSICAL_ROTATION
 33     if (0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "90", 2)
 34         || 0 == strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "270", 3)) {
 35 #ifdef CONFIG_MTK_FB    /*Fix build errors,as some projects  cannot support these apis while bring up*/
 36         TPD_RES_Y = DISP_GetScreenWidth();
 37         TPD_RES_X = DISP_GetScreenHeight();
 38 #endif
 39     } else
 40     #endif
 41     {
 42 #ifdef CONFIG_CUSTOM_LCM_X
 43 #ifndef CONFIG_MTK_FPGA
 44 #ifdef CONFIG_MTK_FB    /*Fix build errors,as some projects  cannot support these apis while bring up*/
 45         TPD_RES_X = DISP_GetScreenWidth();
 46         TPD_RES_Y = DISP_GetScreenHeight();
 47 #else/*for some projects, we do not use mtk framebuffer*/
 48     TPD_RES_X = tpd_dts_data.tpd_resolution[0];
 49     TPD_RES_Y = tpd_dts_data.tpd_resolution[1];
 50 #endif
 51 #endif
 52 #else
 53 #ifdef CONFIG_LCM_WIDTH
 54         ret = kstrtoul(CONFIG_LCM_WIDTH, 0, &tpd_res_x);
 55         if (ret < 0) {
 56             pr_err("Touch down get lcm_x failed");
 57             return ret;
 58         }
 59         TPD_RES_X = tpd_res_x;
 60         ret = kstrtoul(CONFIG_LCM_HEIGHT, 0, &tpd_res_y);
 61         if (ret < 0) {
 62             pr_err("Touch down get lcm_y failed");
 63             return ret;
 64         }
 65         TPD_RES_Y = tpd_res_y;
 66 #endif
 67 #endif
 68     }
 69 
 70     if (2560 == TPD_RES_X)
 71         TPD_RES_X = 2048;
 72     if (1600 == TPD_RES_Y)
 73         TPD_RES_Y = 1536;
 74     pr_debug("mtk_tpd: TPD_RES_X = %lu, TPD_RES_Y = %lu\n", TPD_RES_X, TPD_RES_Y);
 75 
 76     tpd_mode = TPD_MODE_NORMAL;
 77     tpd_mode_axis = 0;
 78     tpd_mode_min = TPD_RES_Y / 2;
 79     tpd_mode_max = TPD_RES_Y;
 80     tpd_mode_keypad_tolerance = TPD_RES_X * TPD_RES_X / 1600;
 81     /* struct input_dev dev initialization and registration */
 82     tpd->dev->name = TPD_DEVICE;
 83     set_bit(EV_ABS, tpd->dev->evbit);
 84     set_bit(EV_KEY, tpd->dev->evbit);
 85     set_bit(ABS_X, tpd->dev->absbit);
 86     set_bit(ABS_Y, tpd->dev->absbit);
 87     set_bit(ABS_PRESSURE, tpd->dev->absbit);
 88 #if !defined(CONFIG_MTK_S3320) && !defined(CONFIG_MTK_S3320_47)\
 89     && !defined(CONFIG_MTK_S3320_50) && !defined(CONFIG_MTK_MIT200) \
 90     && !defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) && !defined(CONFIG_MTK_S7020) \
 91     && !defined(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_3320_50)
 92     set_bit(BTN_TOUCH, tpd->dev->keybit);
 93 #endif /* CONFIG_MTK_S3320 */
 94     set_bit(INPUT_PROP_DIRECT, tpd->dev->propbit);
 95 
 96     /* save dev for regulator_get() before tpd_local_init() */
 97     tpd->tpd_dev = &pdev->dev;
 98     for (i = 1; i < TP_DRV_MAX_COUNT; i++) {
 99         /* add tpd driver into list */
100         if (tpd_driver_list[i].tpd_device_name != NULL) {
101             tpd_driver_list[i].tpd_local_init();
102             /* msleep(1); */
103             if (tpd_load_status == 1) {
104                 TPD_DMESG("[mtk-tpd]tpd_probe, tpd_driver_name=%s\n",
105                       tpd_driver_list[i].tpd_device_name);
106                 g_tpd_drv = &tpd_driver_list[i];
107                 break;
108             }
109         }
110     }
111     if (g_tpd_drv == NULL) {
112         if (tpd_driver_list[0].tpd_device_name != NULL) {
113             g_tpd_drv = &tpd_driver_list[0];
114             /* touch_type:0: r-touch, 1: C-touch */
115             touch_type = 0;
116             g_tpd_drv->tpd_local_init();
117             TPD_DMESG("[mtk-tpd]Generic touch panel driver\n");
118         } else {
119             TPD_DMESG("[mtk-tpd]cap touch and Generic touch both are not loaded!!\n");
120             return 0;
121         }
122     }
123     touch_resume_workqueue = create_singlethread_workqueue("touch_resume");
124     INIT_WORK(&touch_resume_work, touch_resume_workqueue_callback);
125     /* use fb_notifier */
126     tpd_fb_notifier.notifier_call = tpd_fb_notifier_callback;
127     if (fb_register_client(&tpd_fb_notifier))
128         TPD_DMESG("register fb_notifier fail!\n");
129     /* TPD_TYPE_CAPACITIVE handle */
130     if (touch_type == 1) {
131 
132         set_bit(ABS_MT_TRACKING_ID, tpd->dev->absbit);
133         set_bit(ABS_MT_TOUCH_MAJOR, tpd->dev->absbit);
134         set_bit(ABS_MT_TOUCH_MINOR, tpd->dev->absbit);
135         set_bit(ABS_MT_POSITION_X, tpd->dev->absbit);
136         set_bit(ABS_MT_POSITION_Y, tpd->dev->absbit);
137         input_set_abs_params(tpd->dev, ABS_MT_POSITION_X, 0, TPD_RES_X, 0, 0);
138         input_set_abs_params(tpd->dev, ABS_MT_POSITION_Y, 0, TPD_RES_Y, 0, 0);
139 #if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_47) \
140     || defined(CONFIG_MTK_S3320_50) || defined(CONFIG_MTK_MIT200) \
141     || defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) || defined(CONFIG_MTK_S7020) \
142     || defined(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_3320_50)
143         input_set_abs_params(tpd->dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
144         input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
145         input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MINOR, 0, 15, 0, 0);
146         input_mt_init_slots(tpd->dev, 10, 0);
147 #else
148         input_set_abs_params(tpd->dev, ABS_MT_TOUCH_MAJOR, 0, 100, 0, 0);
149         input_set_abs_params(tpd->dev, ABS_MT_TOUCH_MINOR, 0, 100, 0, 0);
150 #endif /* CONFIG_MTK_S3320 */
151         TPD_DMESG("Cap touch panel driver\n");
152     }
153     input_set_abs_params(tpd->dev, ABS_X, 0, TPD_RES_X, 0, 0);
154     input_set_abs_params(tpd->dev, ABS_Y, 0, TPD_RES_Y, 0, 0);
155     input_abs_set_res(tpd->dev, ABS_X, TPD_RES_X);
156     input_abs_set_res(tpd->dev, ABS_Y, TPD_RES_Y);
157     input_set_abs_params(tpd->dev, ABS_PRESSURE, 0, 255, 0, 0);
158     input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
159 
160     if (input_register_device(tpd->dev))
161         TPD_DMESG("input_register_device failed.(tpd)\n");
162     else
163         tpd_register_flag = 1;
164     if (g_tpd_drv->tpd_have_button)
165         tpd_button_init();
166 
167     if (g_tpd_drv->attrs.num)
168         tpd_create_attributes(&pdev->dev, &g_tpd_drv->attrs);
169 
170     return 0;
171 }

 

posted @ 2018-12-05 20:18  爱无限  阅读(1307)  评论(0编辑  收藏  举报