xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/cyttsp5/cyttsp5_platform.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * cyttsp5_platform.c
3  * Parade TrueTouch(TM) Standard Product V5 Platform Module.
4  * For use with Parade touchscreen controllers.
5  * Supported parts include:
6  * CYTMA5XX
7  * CYTMA448
8  * CYTMA445A
9  * CYTT21XXX
10  * CYTT31XXX
11  *
12  * Copyright (C) 2015 Parade Technologies
13  * Copyright (C) 2013-2015 Cypress Semiconductor
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2, and only version 2, as published by the
18  * Free Software Foundation.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * Contact Parade Technologies at www.paradetech.com <ttdrivers@paradetech.com>
26  *
27  */
28 
29 #include "cyttsp5_regs.h"
30 #include "cyttsp5_platform.h"
31 
32 #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_FW_UPGRADE
33 /* FW for Panel ID = 0x00 */
34 #include "cyttsp5_fw_pid00.h"
35 static struct cyttsp5_touch_firmware cyttsp5_firmware_pid00 = {
36 	.img = cyttsp4_img_pid00,
37 	.size = ARRAY_SIZE(cyttsp4_img_pid00),
38 	.ver = cyttsp4_ver_pid00,
39 	.vsize = ARRAY_SIZE(cyttsp4_ver_pid00),
40 	.panel_id = 0x00,
41 };
42 
43 /* FW for Panel ID = 0x01 */
44 #include "cyttsp5_fw_pid01.h"
45 static struct cyttsp5_touch_firmware cyttsp5_firmware_pid01 = {
46 	.img = cyttsp4_img_pid01,
47 	.size = ARRAY_SIZE(cyttsp4_img_pid01),
48 	.ver = cyttsp4_ver_pid01,
49 	.vsize = ARRAY_SIZE(cyttsp4_ver_pid01),
50 	.panel_id = 0x01,
51 };
52 
53 /* FW for Panel ID not enabled (legacy) */
54 #include "cyttsp5_fw.h"
55 static struct cyttsp5_touch_firmware cyttsp5_firmware = {
56 	.img = cyttsp4_img,
57 	.size = ARRAY_SIZE(cyttsp4_img),
58 	.ver = cyttsp4_ver,
59 	.vsize = ARRAY_SIZE(cyttsp4_ver),
60 };
61 #else
62 /* FW for Panel ID not enabled (legacy) */
63 static struct cyttsp5_touch_firmware cyttsp5_firmware = {
64 	.img = NULL,
65 	.size = 0,
66 	.ver = NULL,
67 	.vsize = 0,
68 };
69 #endif
70 
71 #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_TTCONFIG_UPGRADE
72 /* TT Config for Panel ID = 0x00 */
73 #include "cyttsp5_params_pid00.h"
74 static struct touch_settings cyttsp5_sett_param_regs_pid00 = {
75 	.data = (uint8_t *)&cyttsp4_param_regs_pid00[0],
76 	.size = ARRAY_SIZE(cyttsp4_param_regs_pid00),
77 	.tag = 0,
78 };
79 
80 static struct touch_settings cyttsp5_sett_param_size_pid00 = {
81 	.data = (uint8_t *)&cyttsp4_param_size_pid00[0],
82 	.size = ARRAY_SIZE(cyttsp4_param_size_pid00),
83 	.tag = 0,
84 };
85 
86 static struct cyttsp5_touch_config cyttsp5_ttconfig_pid00 = {
87 	.param_regs = &cyttsp5_sett_param_regs_pid00,
88 	.param_size = &cyttsp5_sett_param_size_pid00,
89 	.fw_ver = ttconfig_fw_ver_pid00,
90 	.fw_vsize = ARRAY_SIZE(ttconfig_fw_ver_pid00),
91 	.panel_id = 0x00,
92 };
93 
94 /* TT Config for Panel ID = 0x01 */
95 #include "cyttsp5_params_pid01.h"
96 static struct touch_settings cyttsp5_sett_param_regs_pid01 = {
97 	.data = (uint8_t *)&cyttsp4_param_regs_pid01[0],
98 	.size = ARRAY_SIZE(cyttsp4_param_regs_pid01),
99 	.tag = 0,
100 };
101 
102 static struct touch_settings cyttsp5_sett_param_size_pid01 = {
103 	.data = (uint8_t *)&cyttsp4_param_size_pid01[0],
104 	.size = ARRAY_SIZE(cyttsp4_param_size_pid01),
105 	.tag = 0,
106 };
107 
108 static struct cyttsp5_touch_config cyttsp5_ttconfig_pid01 = {
109 	.param_regs = &cyttsp5_sett_param_regs_pid01,
110 	.param_size = &cyttsp5_sett_param_size_pid01,
111 	.fw_ver = ttconfig_fw_ver_pid01,
112 	.fw_vsize = ARRAY_SIZE(ttconfig_fw_ver_pid01),
113 	.panel_id = 0x01,
114 };
115 
116 /* TT Config for Panel ID not enabled (legacy)*/
117 #include "cyttsp5_params.h"
118 static struct touch_settings cyttsp5_sett_param_regs = {
119 	.data = (uint8_t *)&cyttsp4_param_regs[0],
120 	.size = ARRAY_SIZE(cyttsp4_param_regs),
121 	.tag = 0,
122 };
123 
124 static struct touch_settings cyttsp5_sett_param_size = {
125 	.data = (uint8_t *)&cyttsp4_param_size[0],
126 	.size = ARRAY_SIZE(cyttsp4_param_size),
127 	.tag = 0,
128 };
129 
130 static struct cyttsp5_touch_config cyttsp5_ttconfig = {
131 	.param_regs = &cyttsp5_sett_param_regs,
132 	.param_size = &cyttsp5_sett_param_size,
133 	.fw_ver = ttconfig_fw_ver,
134 	.fw_vsize = ARRAY_SIZE(ttconfig_fw_ver),
135 };
136 #else
137 /* TT Config for Panel ID not enabled (legacy)*/
138 static struct cyttsp5_touch_config cyttsp5_ttconfig = {
139 	.param_regs = NULL,
140 	.param_size = NULL,
141 	.fw_ver = NULL,
142 	.fw_vsize = 0,
143 };
144 #endif
145 
146 static struct cyttsp5_touch_firmware *cyttsp5_firmwares[] = {
147 #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_FW_UPGRADE
148 	&cyttsp5_firmware_pid00,
149 	&cyttsp5_firmware_pid01,
150 #endif
151 	NULL, /* Last item should always be NULL */
152 };
153 
154 static struct cyttsp5_touch_config *cyttsp5_ttconfigs[] = {
155 #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PLATFORM_TTCONFIG_UPGRADE
156 	&cyttsp5_ttconfig_pid00,
157 	&cyttsp5_ttconfig_pid01,
158 #endif
159 	NULL, /* Last item should always be NULL */
160 };
161 
162 struct cyttsp5_loader_platform_data _cyttsp5_loader_platform_data = {
163 	.fw = &cyttsp5_firmware,
164 	.ttconfig = &cyttsp5_ttconfig,
165 	.fws = cyttsp5_firmwares,
166 	.ttconfigs = cyttsp5_ttconfigs,
167 	.flags = CY_LOADER_FLAG_NONE,
168 };
169 
cyttsp5_xres(struct cyttsp5_core_platform_data * pdata,struct device * dev)170 int cyttsp5_xres(struct cyttsp5_core_platform_data *pdata,
171 		struct device *dev)
172 {
173 	int rst_gpio = pdata->rst_gpio;
174 	int rc = 0;
175 
176 	gpio_set_value(rst_gpio, 1);
177 	msleep(20);
178 	gpio_set_value(rst_gpio, 0);
179 	msleep(40);
180 	gpio_set_value(rst_gpio, 1);
181 	msleep(20);
182 	dev_info(dev,
183 		"%s: RESET CYTTSP gpio=%d r=%d\n", __func__,
184 		pdata->rst_gpio, rc);
185 	return rc;
186 }
187 
cyttsp5_init(struct cyttsp5_core_platform_data * pdata,int on,struct device * dev)188 int cyttsp5_init(struct cyttsp5_core_platform_data *pdata,
189 		int on, struct device *dev)
190 {
191 	int rst_gpio = pdata->rst_gpio;
192 	int irq_gpio = pdata->irq_gpio;
193 	int rc = 0;
194 
195 	if (on) {
196 		rc = gpio_request(rst_gpio, NULL);
197 		if (rc < 0) {
198 			gpio_free(rst_gpio);
199 			rc = gpio_request(rst_gpio, NULL);
200 		}
201 		if (rc < 0) {
202 			dev_err(dev,
203 				"%s: Fail request gpio=%d\n", __func__,
204 				rst_gpio);
205 		} else {
206 			rc = gpio_direction_output(rst_gpio, 1);
207 			if (rc < 0) {
208 				pr_err("%s: Fail set output gpio=%d\n",
209 					__func__, rst_gpio);
210 				gpio_free(rst_gpio);
211 			} else {
212 				rc = gpio_request(irq_gpio, NULL);
213 				if (rc < 0) {
214 					gpio_free(irq_gpio);
215 					rc = gpio_request(irq_gpio,
216 						NULL);
217 				}
218 				if (rc < 0) {
219 					dev_err(dev,
220 						"%s: Fail request gpio=%d\n",
221 						__func__, irq_gpio);
222 					gpio_free(rst_gpio);
223 				} else {
224 					gpio_direction_input(irq_gpio);
225 				}
226 			}
227 		}
228 	} else {
229 		gpio_free(rst_gpio);
230 		gpio_free(irq_gpio);
231 	}
232 
233 	dev_info(dev, "%s: INIT CYTTSP RST gpio=%d and IRQ gpio=%d r=%d\n",
234 		__func__, rst_gpio, irq_gpio, rc);
235 	return rc;
236 }
237 
cyttsp5_wakeup(struct cyttsp5_core_platform_data * pdata,struct device * dev,atomic_t * ignore_irq)238 static int cyttsp5_wakeup(struct cyttsp5_core_platform_data *pdata,
239 		struct device *dev, atomic_t *ignore_irq)
240 {
241 	return 0;
242 }
243 
cyttsp5_sleep(struct cyttsp5_core_platform_data * pdata,struct device * dev,atomic_t * ignore_irq)244 static int cyttsp5_sleep(struct cyttsp5_core_platform_data *pdata,
245 		struct device *dev, atomic_t *ignore_irq)
246 {
247 	return 0;
248 }
249 
cyttsp5_power(struct cyttsp5_core_platform_data * pdata,int on,struct device * dev,atomic_t * ignore_irq)250 int cyttsp5_power(struct cyttsp5_core_platform_data *pdata,
251 		int on, struct device *dev, atomic_t *ignore_irq)
252 {
253 	if (on)
254 		return cyttsp5_wakeup(pdata, dev, ignore_irq);
255 
256 	return cyttsp5_sleep(pdata, dev, ignore_irq);
257 }
258 
cyttsp5_irq_stat(struct cyttsp5_core_platform_data * pdata,struct device * dev)259 int cyttsp5_irq_stat(struct cyttsp5_core_platform_data *pdata,
260 		struct device *dev)
261 {
262 	return gpio_get_value(pdata->irq_gpio);
263 }
264 
265 #ifdef CYTTSP5_DETECT_HW
cyttsp5_detect(struct cyttsp5_core_platform_data * pdata,struct device * dev,cyttsp5_platform_read read)266 int cyttsp5_detect(struct cyttsp5_core_platform_data *pdata,
267 		struct device *dev, cyttsp5_platform_read read)
268 {
269 	int retry = 3;
270 	int rc;
271 	char buf[1];
272 
273 	while (retry--) {
274 		/* Perform reset, wait for 100 ms and perform read */
275 		parade_debug(dev, DEBUG_LEVEL_2, "%s: Performing a reset\n",
276 			__func__);
277 		pdata->xres(pdata, dev);
278 		msleep(100);
279 		rc = read(dev, buf, 1);
280 		if (!rc)
281 			return 0;
282 
283 		parade_debug(dev, DEBUG_LEVEL_2, "%s: Read unsuccessful, try=%d\n",
284 			__func__, 3 - retry);
285 	}
286 
287 	return rc;
288 }
289 #endif
290