diff options
Diffstat (limited to 'drivers/input/touchscreen/rmi4/rmi_f54.c')
-rw-r--r-- | drivers/input/touchscreen/rmi4/rmi_f54.c | 1347 |
1 files changed, 1347 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/rmi4/rmi_f54.c b/drivers/input/touchscreen/rmi4/rmi_f54.c new file mode 100644 index 00000000000..11bb0b934be --- /dev/null +++ b/drivers/input/touchscreen/rmi4/rmi_f54.c | |||
@@ -0,0 +1,1347 @@ | |||
1 | |||
2 | /* | ||
3 | * Copyright (c) 2011 Synaptics Incorporated | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | */ | ||
19 | #include <linux/hrtimer.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/rmi.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/version.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include "rmi_driver.h" | ||
26 | |||
27 | /* Set this to 1 for raw hex dump of returned data. */ | ||
28 | #define RAW_HEX 0 | ||
29 | /* Set this to 1 for human readable dump of returned data. */ | ||
30 | #define HUMAN_READABLE 0 | ||
31 | /* The watchdog timer can be useful when debugging certain firmware related | ||
32 | * issues. | ||
33 | */ | ||
34 | #define F54_WATCHDOG 1 | ||
35 | |||
36 | #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) | ||
37 | #define KERNEL_VERSION_ABOVE_2_6_32 1 | ||
38 | #endif | ||
39 | |||
40 | /* define fn $54 commands */ | ||
41 | #define GET_REPORT 1 | ||
42 | #define FORCE_CAL 2 | ||
43 | |||
44 | /* status */ | ||
45 | #define BUSY 1 | ||
46 | #define IDLE 0 | ||
47 | |||
48 | /* Offsets for data */ | ||
49 | #define RMI_F54_REPORT_DATA_OFFSET 3 | ||
50 | #define RMI_F54_FIFO_OFFSET 1 | ||
51 | #define RMI_F54_NUM_TX_OFFSET 1 | ||
52 | #define RMI_F54_NUM_RX_OFFSET 0 | ||
53 | |||
54 | /* Fixed sizes of reports */ | ||
55 | #define RMI_54_FULL_RAW_CAP_MIN_MAX_SIZE 4 | ||
56 | #define RMI_54_HIGH_RESISTANCE_SIZE 6 | ||
57 | |||
58 | /* definitions for F54 Query Registers in ultra-portable unionstruct form */ | ||
59 | struct f54_ad_query { | ||
60 | /* query 0 */ | ||
61 | u8 number_of_receiver_electrodes; | ||
62 | |||
63 | /* query 1 */ | ||
64 | u8 number_of_transmitter_electrodes; | ||
65 | |||
66 | union { | ||
67 | struct { | ||
68 | /* query2 */ | ||
69 | u8 f54_ad_query2_b0__1:2; | ||
70 | u8 has_baseline:1; | ||
71 | u8 has_image8:1; | ||
72 | u8 f54_ad_query2_b4__5:2; | ||
73 | u8 has_image16:1; | ||
74 | u8 f54_ad_query2_b7:1; | ||
75 | }; | ||
76 | u8 f54_ad_query2; | ||
77 | }; | ||
78 | |||
79 | /* query 3.0 and 3.1 */ | ||
80 | u16 clock_rate; | ||
81 | |||
82 | /* query 4 */ | ||
83 | u8 touch_controller_family; | ||
84 | |||
85 | /* query 5 */ | ||
86 | union { | ||
87 | struct { | ||
88 | u8 has_pixel_touch_threshold_adjustment:1; | ||
89 | u8 f54_ad_query5_b1__7:7; | ||
90 | }; | ||
91 | u8 f54_ad_query5; | ||
92 | }; | ||
93 | |||
94 | /* query 6 */ | ||
95 | union { | ||
96 | struct { | ||
97 | u8 has_sensor_assignment:1; | ||
98 | u8 has_interference_metric:1; | ||
99 | u8 has_sense_frequency_control:1; | ||
100 | u8 has_firmware_noise_mitigation:1; | ||
101 | u8 f54_ad_query6_b4:1; | ||
102 | u8 has_two_byte_report_rate:1; | ||
103 | u8 has_one_byte_report_rate:1; | ||
104 | u8 has_relaxation_control:1; | ||
105 | }; | ||
106 | u8 f54_ad_query6; | ||
107 | }; | ||
108 | |||
109 | /* query 7 */ | ||
110 | union { | ||
111 | struct { | ||
112 | u8 curve_compensation_mode:2; | ||
113 | u8 f54_ad_query7_b2__7:6; | ||
114 | }; | ||
115 | u8 f54_ad_query7; | ||
116 | }; | ||
117 | |||
118 | /* query 8 */ | ||
119 | union { | ||
120 | struct { | ||
121 | u8 f54_ad_query2_b0:1; | ||
122 | u8 has_iir_filter:1; | ||
123 | u8 has_cmn_removal:1; | ||
124 | u8 has_cmn_maximum:1; | ||
125 | u8 has_pixel_threshold_hysteresis:1; | ||
126 | u8 has_edge_compensation:1; | ||
127 | u8 has_perf_frequency_noisecontrol:1; | ||
128 | u8 f54_ad_query8_b7:1; | ||
129 | }; | ||
130 | u8 f54_ad_query8; | ||
131 | }; | ||
132 | |||
133 | u8 f54_ad_query9; | ||
134 | u8 f54_ad_query10; | ||
135 | u8 f54_ad_query11; | ||
136 | |||
137 | /* query 12 */ | ||
138 | union { | ||
139 | struct { | ||
140 | u8 number_of_sensing_frequencies:4; | ||
141 | u8 f54_ad_query12_b4__7:4; | ||
142 | }; | ||
143 | u8 f54_ad_query12; | ||
144 | }; | ||
145 | }; | ||
146 | |||
147 | /* define report types */ | ||
148 | enum f54_report_types { | ||
149 | /* The numbering should follow automatically, here for clarity */ | ||
150 | F54_8BIT_IMAGE = 1, | ||
151 | F54_16BIT_IMAGE = 2, | ||
152 | F54_RAW_16BIT_IMAGE = 3, | ||
153 | F54_HIGH_RESISTANCE = 4, | ||
154 | F54_TX_TO_TX_SHORT = 5, | ||
155 | F54_RX_TO_RX1 = 7, | ||
156 | F54_TRUE_BASELINE = 9, | ||
157 | F54_FULL_RAW_CAP_MIN_MAX = 13, | ||
158 | F54_RX_OPENS1 = 14, | ||
159 | F54_TX_OPEN = 15, | ||
160 | F54_TX_TO_GROUND = 16, | ||
161 | F54_RX_TO_RX2 = 17, | ||
162 | F54_RX_OPENS2 = 18, | ||
163 | F54_FULL_RAW_CAP = 19, | ||
164 | F54_FULL_RAW_CAP_RX_COUPLING_COMP = 20 | ||
165 | }; | ||
166 | |||
167 | /* data specific to fn $54 that needs to be kept around */ | ||
168 | struct rmi_fn_54_data { | ||
169 | struct f54_ad_query query; | ||
170 | u8 cmd; | ||
171 | enum f54_report_types report_type; | ||
172 | u16 fifoindex; | ||
173 | signed char status; | ||
174 | bool no_auto_cal; | ||
175 | /* | ||
176 | * May need to do something to make sure this reflects what is currently | ||
177 | * in data. | ||
178 | */ | ||
179 | unsigned int report_size; | ||
180 | unsigned char *report_data; | ||
181 | unsigned int bufsize; | ||
182 | struct mutex data_mutex; | ||
183 | struct lock_class_key data_key; | ||
184 | struct mutex status_mutex; | ||
185 | struct lock_class_key status_key; | ||
186 | #if F54_WATCHDOG | ||
187 | struct hrtimer watchdog; | ||
188 | #endif | ||
189 | struct rmi_function_container *fc; | ||
190 | struct work_struct work; | ||
191 | }; | ||
192 | |||
193 | /* sysfs functions */ | ||
194 | static ssize_t rmi_fn_54_report_type_show(struct device *dev, | ||
195 | struct device_attribute *attr, char *buf); | ||
196 | |||
197 | static ssize_t rmi_fn_54_report_type_store(struct device *dev, | ||
198 | struct device_attribute *attr, | ||
199 | const char *buf, size_t count); | ||
200 | |||
201 | static ssize_t rmi_fn_54_get_report_store(struct device *dev, | ||
202 | struct device_attribute *attr, | ||
203 | const char *buf, size_t count); | ||
204 | |||
205 | static ssize_t rmi_fn_54_force_cal_store(struct device *dev, | ||
206 | struct device_attribute *attr, | ||
207 | const char *buf, size_t count); | ||
208 | |||
209 | static ssize_t rmi_fn_54_status_show(struct device *dev, | ||
210 | struct device_attribute *attr, char *buf); | ||
211 | |||
212 | #ifdef KERNEL_VERSION_ABOVE_2_6_32 | ||
213 | static ssize_t rmi_fn_54_data_read(struct file *data_file, struct kobject *kobj, | ||
214 | #else | ||
215 | static ssize_t rmi_fn_54_data_read(struct kobject *kobj, | ||
216 | #endif | ||
217 | struct bin_attribute *attributes, | ||
218 | char *buf, loff_t pos, size_t count); | ||
219 | |||
220 | static ssize_t rmi_fn_54_num_rx_electrodes_show(struct device *dev, | ||
221 | struct device_attribute *attr, char *buf); | ||
222 | |||
223 | static ssize_t rmi_fn_54_num_tx_electrodes_show(struct device *dev, | ||
224 | struct device_attribute *attr, char *buf); | ||
225 | |||
226 | static ssize_t rmi_fn_54_has_image16_show(struct device *dev, | ||
227 | struct device_attribute *attr, char *buf); | ||
228 | |||
229 | static ssize_t rmi_fn_54_has_image8_show(struct device *dev, | ||
230 | struct device_attribute *attr, char *buf); | ||
231 | |||
232 | static ssize_t rmi_fn_54_has_baseline_show(struct device *dev, | ||
233 | struct device_attribute *attr, char *buf); | ||
234 | |||
235 | static ssize_t rmi_fn_54_clock_rate_show(struct device *dev, | ||
236 | struct device_attribute *attr, char *buf); | ||
237 | |||
238 | |||
239 | static ssize_t rmi_fn_54_touch_controller_family_show(struct device *dev, | ||
240 | struct device_attribute *attr, char *buf); | ||
241 | |||
242 | |||
243 | static ssize_t rmi_fn_54_has_pixel_touch_threshold_adjustment_show( | ||
244 | struct device *dev, struct device_attribute *attr, char *buf); | ||
245 | |||
246 | static ssize_t rmi_fn_54_has_sensor_assignment_show(struct device *dev, | ||
247 | struct device_attribute *attr, char *buf); | ||
248 | |||
249 | static ssize_t rmi_fn_54_has_interference_metric_show(struct device *dev, | ||
250 | struct device_attribute *attr, char *buf); | ||
251 | |||
252 | static ssize_t rmi_fn_54_has_sense_frequency_control_show(struct device *dev, | ||
253 | struct device_attribute *attr, char *buf); | ||
254 | |||
255 | static ssize_t rmi_fn_54_has_firmware_noise_mitigation_show(struct device *dev, | ||
256 | struct device_attribute *attr, char *buf); | ||
257 | |||
258 | static ssize_t rmi_fn_54_has_two_byte_report_rate_show(struct device *dev, | ||
259 | struct device_attribute *attr, char *buf); | ||
260 | |||
261 | static ssize_t rmi_fn_54_has_one_byte_report_rate_show(struct device *dev, | ||
262 | struct device_attribute *attr, char *buf); | ||
263 | |||
264 | static ssize_t rmi_fn_54_has_relaxation_control_show(struct device *dev, | ||
265 | struct device_attribute *attr, char *buf); | ||
266 | |||
267 | static ssize_t rmi_fn_54_curve_compensation_mode_show(struct device *dev, | ||
268 | struct device_attribute *attr, char *buf); | ||
269 | |||
270 | static ssize_t rmi_fn_54_has_iir_filter_show(struct device *dev, | ||
271 | struct device_attribute *attr, char *buf); | ||
272 | |||
273 | static ssize_t rmi_fn_54_has_cmn_removal_show(struct device *dev, | ||
274 | struct device_attribute *attr, char *buf); | ||
275 | |||
276 | static ssize_t rmi_fn_54_has_cmn_maximum_show(struct device *dev, | ||
277 | struct device_attribute *attr, char *buf); | ||
278 | |||
279 | static ssize_t rmi_fn_54_has_pixel_threshold_hysteresis_show(struct device *dev, | ||
280 | struct device_attribute *attr, char *buf); | ||
281 | |||
282 | static ssize_t rmi_fn_54_has_edge_compensation_show(struct device *dev, | ||
283 | struct device_attribute *attr, char *buf); | ||
284 | |||
285 | static ssize_t rmi_fn_54_has_perf_frequency_noisecontrol_show( | ||
286 | struct device *dev, struct device_attribute *attr, char *buf); | ||
287 | |||
288 | static ssize_t rmi_fn_54_number_of_sensing_frequencies_show(struct device *dev, | ||
289 | struct device_attribute *attr, char *buf); | ||
290 | |||
291 | static ssize_t rmi_fn_54_no_auto_cal_show(struct device *dev, | ||
292 | struct device_attribute *attr, char *buf); | ||
293 | |||
294 | static ssize_t rmi_fn_54_no_auto_cal_store(struct device *dev, | ||
295 | struct device_attribute *attr, | ||
296 | const char *buf, size_t count); | ||
297 | |||
298 | static ssize_t rmi_fn_54_fifoindex_show(struct device *dev, | ||
299 | struct device_attribute *attr, char *buf); | ||
300 | |||
301 | static ssize_t rmi_fn_54_fifoindex_store(struct device *dev, | ||
302 | struct device_attribute *attr, | ||
303 | const char *buf, size_t count); | ||
304 | |||
305 | static struct device_attribute attrs[] = { | ||
306 | __ATTR(report_type, RMI_RW_ATTR, | ||
307 | rmi_fn_54_report_type_show, rmi_fn_54_report_type_store), | ||
308 | __ATTR(get_report, RMI_WO_ATTR, | ||
309 | rmi_show_error, rmi_fn_54_get_report_store), | ||
310 | __ATTR(force_cal, RMI_WO_ATTR, | ||
311 | rmi_show_error, rmi_fn_54_force_cal_store), | ||
312 | __ATTR(status, RMI_RO_ATTR, | ||
313 | rmi_fn_54_status_show, rmi_store_error), | ||
314 | __ATTR(num_rx_electrodes, RMI_RO_ATTR, | ||
315 | rmi_fn_54_num_rx_electrodes_show, rmi_store_error), | ||
316 | __ATTR(num_tx_electrodes, RMI_RO_ATTR, | ||
317 | rmi_fn_54_num_tx_electrodes_show, rmi_store_error), | ||
318 | __ATTR(has_image16, RMI_RO_ATTR, | ||
319 | rmi_fn_54_has_image16_show, rmi_store_error), | ||
320 | __ATTR(has_image8, RMI_RO_ATTR, | ||
321 | rmi_fn_54_has_image8_show, rmi_store_error), | ||
322 | __ATTR(has_baseline, RMI_RO_ATTR, | ||
323 | rmi_fn_54_has_baseline_show, rmi_store_error), | ||
324 | __ATTR(clock_rate, RMI_RO_ATTR, | ||
325 | rmi_fn_54_clock_rate_show, rmi_store_error), | ||
326 | __ATTR(touch_controller_family, RMI_RO_ATTR, | ||
327 | rmi_fn_54_touch_controller_family_show, rmi_store_error), | ||
328 | __ATTR(has_pixel_touch_threshold_adjustment, RMI_RO_ATTR, | ||
329 | rmi_fn_54_has_pixel_touch_threshold_adjustment_show | ||
330 | , rmi_store_error), | ||
331 | __ATTR(has_sensor_assignment, RMI_RO_ATTR, | ||
332 | rmi_fn_54_has_sensor_assignment_show, rmi_store_error), | ||
333 | __ATTR(has_interference_metric, RMI_RO_ATTR, | ||
334 | rmi_fn_54_has_interference_metric_show, rmi_store_error), | ||
335 | __ATTR(has_sense_frequency_control, RMI_RO_ATTR, | ||
336 | rmi_fn_54_has_sense_frequency_control_show, rmi_store_error), | ||
337 | __ATTR(has_firmware_noise_mitigation, RMI_RO_ATTR, | ||
338 | rmi_fn_54_has_firmware_noise_mitigation_show, rmi_store_error), | ||
339 | __ATTR(has_two_byte_report_rate, RMI_RO_ATTR, | ||
340 | rmi_fn_54_has_two_byte_report_rate_show, rmi_store_error), | ||
341 | __ATTR(has_one_byte_report_rate, RMI_RO_ATTR, | ||
342 | rmi_fn_54_has_one_byte_report_rate_show, rmi_store_error), | ||
343 | __ATTR(has_relaxation_control, RMI_RO_ATTR, | ||
344 | rmi_fn_54_has_relaxation_control_show, rmi_store_error), | ||
345 | __ATTR(curve_compensation_mode, RMI_RO_ATTR, | ||
346 | rmi_fn_54_curve_compensation_mode_show, rmi_store_error), | ||
347 | __ATTR(has_iir_filter, RMI_RO_ATTR, | ||
348 | rmi_fn_54_has_iir_filter_show, rmi_store_error), | ||
349 | __ATTR(has_cmn_removal, RMI_RO_ATTR, | ||
350 | rmi_fn_54_has_cmn_removal_show, rmi_store_error), | ||
351 | __ATTR(has_cmn_maximum, RMI_RO_ATTR, | ||
352 | rmi_fn_54_has_cmn_maximum_show, rmi_store_error), | ||
353 | __ATTR(has_pixel_threshold_hysteresis, RMI_RO_ATTR, | ||
354 | rmi_fn_54_has_pixel_threshold_hysteresis_show, rmi_store_error), | ||
355 | __ATTR(has_edge_compensation, RMI_RO_ATTR, | ||
356 | rmi_fn_54_has_edge_compensation_show, rmi_store_error), | ||
357 | __ATTR(has_perf_frequency_noisecontrol, RMI_RO_ATTR, | ||
358 | rmi_fn_54_has_perf_frequency_noisecontrol_show, rmi_store_error), | ||
359 | __ATTR(number_of_sensing_frequencies, RMI_RO_ATTR, | ||
360 | rmi_fn_54_number_of_sensing_frequencies_show, rmi_store_error), | ||
361 | __ATTR(no_auto_cal, RMI_RW_ATTR, | ||
362 | rmi_fn_54_no_auto_cal_show, rmi_fn_54_no_auto_cal_store), | ||
363 | __ATTR(fifoindex, RMI_RW_ATTR, | ||
364 | rmi_fn_54_fifoindex_show, rmi_fn_54_fifoindex_store), | ||
365 | }; | ||
366 | |||
367 | struct bin_attribute dev_rep_data = { | ||
368 | .attr = { | ||
369 | .name = "rep_data", | ||
370 | .mode = RMI_RO_ATTR}, | ||
371 | .size = 0, | ||
372 | .read = rmi_fn_54_data_read, | ||
373 | }; | ||
374 | |||
375 | #if F54_WATCHDOG | ||
376 | static enum hrtimer_restart clear_status(struct hrtimer *timer); | ||
377 | |||
378 | static void clear_status_worker(struct work_struct *work); | ||
379 | #endif | ||
380 | |||
381 | static int rmi_f54_init(struct rmi_function_container *fc) | ||
382 | { | ||
383 | struct rmi_fn_54_data *instance_data; | ||
384 | int retval = 0; | ||
385 | int attr_count = 0; | ||
386 | |||
387 | dev_info(&fc->dev, "Intializing F54."); | ||
388 | |||
389 | instance_data = kzalloc(sizeof(struct rmi_fn_54_data), GFP_KERNEL); | ||
390 | if (!instance_data) { | ||
391 | dev_err(&fc->dev, "Failed to allocate rmi_fn_54_data.\n"); | ||
392 | retval = -ENOMEM; | ||
393 | goto error_exit; | ||
394 | } | ||
395 | fc->data = instance_data; | ||
396 | instance_data->fc = fc; | ||
397 | |||
398 | #if F54_WATCHDOG | ||
399 | /* Set up watchdog timer to catch unanswered get_report commands */ | ||
400 | hrtimer_init(&instance_data->watchdog, CLOCK_MONOTONIC, | ||
401 | HRTIMER_MODE_REL); | ||
402 | instance_data->watchdog.function = clear_status; | ||
403 | |||
404 | /* work function to do unlocking */ | ||
405 | INIT_WORK(&instance_data->work, clear_status_worker); | ||
406 | #endif | ||
407 | |||
408 | /* Read F54 Query Data */ | ||
409 | retval = rmi_read_block(fc->rmi_dev, fc->fd.query_base_addr, | ||
410 | (u8 *)&instance_data->query, sizeof(instance_data->query)); | ||
411 | if (retval < 0) { | ||
412 | dev_err(&fc->dev, "Could not read query registers" | ||
413 | " from 0x%04x\n", fc->fd.query_base_addr); | ||
414 | goto error_exit; | ||
415 | } | ||
416 | |||
417 | __mutex_init(&instance_data->data_mutex, "data_mutex", | ||
418 | &instance_data->data_key); | ||
419 | |||
420 | __mutex_init(&instance_data->status_mutex, "status_mutex", | ||
421 | &instance_data->status_key); | ||
422 | |||
423 | dev_dbg(&fc->dev, "Creating sysfs files."); | ||
424 | /* Set up sysfs device attributes. */ | ||
425 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { | ||
426 | if (sysfs_create_file | ||
427 | (&fc->dev.kobj, &attrs[attr_count].attr) < 0) { | ||
428 | dev_err(&fc->dev, "Failed to create sysfs file for %s.", | ||
429 | attrs[attr_count].attr.name); | ||
430 | retval = -ENODEV; | ||
431 | goto error_exit; | ||
432 | } | ||
433 | } | ||
434 | /* Binary sysfs file to report the data back */ | ||
435 | retval = sysfs_create_bin_file(&fc->dev.kobj, &dev_rep_data); | ||
436 | if (retval < 0) { | ||
437 | dev_err(&fc->dev, "Failed to create sysfs file for F54 data " | ||
438 | "(error = %d).\n", retval); | ||
439 | retval = -ENODEV; | ||
440 | goto error_exit; | ||
441 | } | ||
442 | instance_data->status = IDLE; | ||
443 | return retval; | ||
444 | |||
445 | error_exit: | ||
446 | dev_err(&fc->dev, "An error occured in F54 init!\n"); | ||
447 | for (attr_count--; attr_count >= 0; attr_count--) | ||
448 | sysfs_remove_file(&fc->dev.kobj, | ||
449 | &attrs[attr_count].attr); | ||
450 | kfree(instance_data); | ||
451 | return retval; | ||
452 | } | ||
453 | |||
454 | static void set_report_size(struct rmi_fn_54_data *data) | ||
455 | { | ||
456 | u8 rx = data->query.number_of_receiver_electrodes; | ||
457 | u8 tx = data->query.number_of_transmitter_electrodes; | ||
458 | switch (data->report_type) { | ||
459 | case F54_8BIT_IMAGE: | ||
460 | data->report_size = rx * tx; | ||
461 | break; | ||
462 | case F54_16BIT_IMAGE: | ||
463 | case F54_RAW_16BIT_IMAGE: | ||
464 | case F54_TRUE_BASELINE: | ||
465 | case F54_FULL_RAW_CAP: | ||
466 | case F54_FULL_RAW_CAP_RX_COUPLING_COMP: | ||
467 | data->report_size = 2 * rx * tx; | ||
468 | break; | ||
469 | case F54_HIGH_RESISTANCE: | ||
470 | data->report_size = RMI_54_HIGH_RESISTANCE_SIZE; | ||
471 | break; | ||
472 | case F54_FULL_RAW_CAP_MIN_MAX: | ||
473 | data->report_size = RMI_54_FULL_RAW_CAP_MIN_MAX_SIZE; | ||
474 | break; | ||
475 | case F54_TX_TO_TX_SHORT: | ||
476 | case F54_TX_OPEN: | ||
477 | case F54_TX_TO_GROUND: | ||
478 | data->report_size = (tx + 7) / 8; | ||
479 | break; | ||
480 | case F54_RX_TO_RX1: | ||
481 | case F54_RX_OPENS1: | ||
482 | if (rx < tx) | ||
483 | data->report_size = 2 * rx * rx; | ||
484 | else | ||
485 | data->report_size = 2 * rx * tx; | ||
486 | break; | ||
487 | case F54_RX_TO_RX2: | ||
488 | case F54_RX_OPENS2: | ||
489 | if (rx <= tx) | ||
490 | data->report_size = 0; | ||
491 | else | ||
492 | data->report_size = 2 * rx * (rx - tx); | ||
493 | break; | ||
494 | default: | ||
495 | data->report_size = 0; | ||
496 | } | ||
497 | } | ||
498 | |||
499 | int rmi_f54_attention(struct rmi_function_container *fc, u8 *irq_bits) | ||
500 | { | ||
501 | struct rmi_driver *driver = fc->rmi_dev->driver; | ||
502 | char fifo[2]; | ||
503 | struct rmi_fn_54_data *data = fc->data; | ||
504 | int error = 0; | ||
505 | |||
506 | set_report_size(data); | ||
507 | if (data->report_size == 0) { | ||
508 | dev_err(&fc->dev, "Invalid report type set in %s. " | ||
509 | "This should never happen.\n", __func__); | ||
510 | error = -EINVAL; | ||
511 | goto error_exit; | ||
512 | } | ||
513 | /* | ||
514 | * We need to ensure the buffer is big enough. A Buffer size of 0 means | ||
515 | * that the buffer has not been allocated. | ||
516 | */ | ||
517 | if (data->bufsize < data->report_size) { | ||
518 | mutex_lock(&data->data_mutex); | ||
519 | if (data->bufsize > 0) | ||
520 | kfree(data->report_data); | ||
521 | data->report_data = kzalloc(data->report_size, GFP_KERNEL); | ||
522 | if (!data->report_data) { | ||
523 | dev_err(&fc->dev, "Failed to allocate report_data.\n"); | ||
524 | error = -ENOMEM; | ||
525 | data->bufsize = 0; | ||
526 | mutex_unlock(&data->data_mutex); | ||
527 | goto error_exit; | ||
528 | } | ||
529 | data->bufsize = data->report_size; | ||
530 | mutex_unlock(&data->data_mutex); | ||
531 | } | ||
532 | dev_vdbg(&fc->dev, "F54 Interrupt handler is running.\nSize: %d\n", | ||
533 | data->report_size); | ||
534 | /* | ||
535 | * Read report type, fifo high, and fifo low | ||
536 | * error = rmi_read_multiple(rmifninfo->sensor, | ||
537 | * rmifninfo->function_descriptor.data_base_addr , | ||
538 | * repfifo,3); | ||
539 | */ | ||
540 | /* Write 0 to fifohi and fifolo. */ | ||
541 | fifo[0] = 0; | ||
542 | fifo[1] = 0; | ||
543 | error = rmi_write_block(fc->rmi_dev, fc->fd.data_base_addr | ||
544 | + RMI_F54_FIFO_OFFSET, fifo, sizeof(fifo)); | ||
545 | if (error < 0) | ||
546 | dev_err(&fc->dev, "Failed to write fifo to zero!\n"); | ||
547 | else | ||
548 | error = rmi_read_block(fc->rmi_dev, | ||
549 | fc->fd.data_base_addr + RMI_F54_REPORT_DATA_OFFSET, | ||
550 | data->report_data, data->report_size); | ||
551 | if (error < 0) | ||
552 | dev_err(&fc->dev, "F54 data read failed. Code: %d.\n", error); | ||
553 | else if (error != data->report_size) { | ||
554 | error = -EINVAL; | ||
555 | goto error_exit; | ||
556 | } | ||
557 | #if RAW_HEX | ||
558 | int l; | ||
559 | /* Debugging: Print out the file in hex. */ | ||
560 | pr_info("Report data (raw hex):\n"); | ||
561 | for (l = 0; l < data->report_size; l += 2) { | ||
562 | pr_info("%03d: 0x%02x%02x\n", l/2, | ||
563 | data->report_data[l+1], data->report_data[l]); | ||
564 | } | ||
565 | #endif | ||
566 | #if HUMAN_READABLE | ||
567 | /* Debugging: Print out file in human understandable image */ | ||
568 | switch (data->report_type) { | ||
569 | case F54_16BIT_IMAGE: | ||
570 | case F54_RAW_16BIT_IMAGE: | ||
571 | case F54_TRUE_BASELINE: | ||
572 | case F54_FULL_RAW_CAP: | ||
573 | case F54_FULL_RAW_CAP_RX_COUPLING_COMP: | ||
574 | pr_info("Report data (Image):\n"); | ||
575 | int i, j, k; | ||
576 | char c[2]; | ||
577 | short s; | ||
578 | k = 0; | ||
579 | for (i = 0; i < data->query.number_of_transmitter_electrodes; | ||
580 | i++) { | ||
581 | for (j = 0; j < | ||
582 | data->query.number_of_receiver_electrodes; j++) { | ||
583 | c[0] = data->report_data[k]; | ||
584 | c[1] = data->report_data[k+1]; | ||
585 | memcpy(&s, &c, 2); | ||
586 | if (s < -64) | ||
587 | printk("."); | ||
588 | else if (s < 0) | ||
589 | printk("-"); | ||
590 | else if (s > 64) | ||
591 | printk("*"); | ||
592 | else if (s > 0) | ||
593 | printk("+"); | ||
594 | else | ||
595 | printk("0"); | ||
596 | k += 2; | ||
597 | } | ||
598 | pr_info("\n"); | ||
599 | } | ||
600 | pr_info("EOF\n"); | ||
601 | break; | ||
602 | default: | ||
603 | pr_info("Report type %d debug image not supported", | ||
604 | data->report_type); | ||
605 | } | ||
606 | #endif | ||
607 | error = IDLE; | ||
608 | error_exit: | ||
609 | mutex_lock(&data->status_mutex); | ||
610 | /* Turn back on other interupts, if it | ||
611 | * appears that we turned them off. */ | ||
612 | if (driver->restore_irq_mask) { | ||
613 | dev_dbg(&fc->dev, "Restoring interupts!\n"); | ||
614 | driver->restore_irq_mask(fc->rmi_dev); | ||
615 | } else { | ||
616 | dev_err(&fc->dev, "No way to restore interrupts!\n"); | ||
617 | } | ||
618 | data->status = error; | ||
619 | mutex_unlock(&data->status_mutex); | ||
620 | return data->status; | ||
621 | } | ||
622 | |||
623 | |||
624 | #if F54_WATCHDOG | ||
625 | static void clear_status_worker(struct work_struct *work) | ||
626 | { | ||
627 | struct rmi_fn_54_data *data = container_of(work, | ||
628 | struct rmi_fn_54_data, work); | ||
629 | struct rmi_function_container *fc = data->fc; | ||
630 | struct rmi_driver *driver = fc->rmi_dev->driver; | ||
631 | char command; | ||
632 | int result; | ||
633 | |||
634 | mutex_lock(&data->status_mutex); | ||
635 | if (data->status == BUSY) { | ||
636 | pr_info("F54 Timout Occured: Determining status.\n"); | ||
637 | result = rmi_read_block(fc->rmi_dev, fc->fd.command_base_addr, | ||
638 | &command, 1); | ||
639 | if (result < 0) { | ||
640 | dev_err(&fc->dev, "Could not read get_report register " | ||
641 | "from 0x%04x\n", fc->fd.command_base_addr); | ||
642 | data->status = -ETIMEDOUT; | ||
643 | } else { | ||
644 | if (command & GET_REPORT) { | ||
645 | dev_warn(&fc->dev, "Report type unsupported!"); | ||
646 | data->status = -EINVAL; | ||
647 | } else { | ||
648 | data->status = -ETIMEDOUT; | ||
649 | } | ||
650 | } | ||
651 | if (driver->restore_irq_mask) { | ||
652 | dev_dbg(&fc->dev, "Restoring interupts!\n"); | ||
653 | driver->restore_irq_mask(fc->rmi_dev); | ||
654 | } else { | ||
655 | dev_err(&fc->dev, "No way to restore interrupts!\n"); | ||
656 | } | ||
657 | } | ||
658 | mutex_unlock(&data->status_mutex); | ||
659 | } | ||
660 | |||
661 | static enum hrtimer_restart clear_status(struct hrtimer *timer) | ||
662 | { | ||
663 | struct rmi_fn_54_data *data = container_of(timer, | ||
664 | struct rmi_fn_54_data, watchdog); | ||
665 | schedule_work(&(data->work)); | ||
666 | return HRTIMER_NORESTART; | ||
667 | } | ||
668 | #endif | ||
669 | |||
670 | /* Check if report_type is valid */ | ||
671 | static bool is_report_type_valid(enum f54_report_types reptype) | ||
672 | { | ||
673 | /* Basic checks on report_type to ensure we write a valid type | ||
674 | * to the sensor. | ||
675 | * TODO: Check Query3 to see if some specific reports are | ||
676 | * available. This is currently listed as a reserved register. | ||
677 | */ | ||
678 | switch (reptype) { | ||
679 | case F54_8BIT_IMAGE: | ||
680 | case F54_16BIT_IMAGE: | ||
681 | case F54_RAW_16BIT_IMAGE: | ||
682 | case F54_HIGH_RESISTANCE: | ||
683 | case F54_TX_TO_TX_SHORT: | ||
684 | case F54_RX_TO_RX1: | ||
685 | case F54_TRUE_BASELINE: | ||
686 | case F54_FULL_RAW_CAP_MIN_MAX: | ||
687 | case F54_RX_OPENS1: | ||
688 | case F54_TX_OPEN: | ||
689 | case F54_TX_TO_GROUND: | ||
690 | case F54_RX_TO_RX2: | ||
691 | case F54_RX_OPENS2: | ||
692 | case F54_FULL_RAW_CAP: | ||
693 | case F54_FULL_RAW_CAP_RX_COUPLING_COMP: | ||
694 | return true; | ||
695 | break; | ||
696 | default: | ||
697 | return false; | ||
698 | } | ||
699 | } | ||
700 | |||
701 | /* SYSFS file show/store functions */ | ||
702 | static ssize_t rmi_fn_54_report_type_show(struct device *dev, | ||
703 | struct device_attribute *attr, char *buf) { | ||
704 | struct rmi_function_container *fc; | ||
705 | struct rmi_fn_54_data *instance_data; | ||
706 | |||
707 | fc = to_rmi_function_container(dev); | ||
708 | instance_data = fc->data; | ||
709 | |||
710 | return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->report_type); | ||
711 | } | ||
712 | |||
713 | static ssize_t rmi_fn_54_report_type_store(struct device *dev, | ||
714 | struct device_attribute *attr, | ||
715 | const char *buf, size_t count) { | ||
716 | int result; | ||
717 | unsigned long val; | ||
718 | unsigned char data; | ||
719 | struct rmi_function_container *fc; | ||
720 | struct rmi_fn_54_data *instance_data; | ||
721 | fc = to_rmi_function_container(dev); | ||
722 | instance_data = fc->data; | ||
723 | |||
724 | /* need to convert the string data to an actual value */ | ||
725 | result = strict_strtoul(buf, 10, &val); | ||
726 | if (result) | ||
727 | return result; | ||
728 | if (!is_report_type_valid(val)) { | ||
729 | dev_err(dev, "%s : Report type %d is invalid.\n", | ||
730 | __func__, (u8) val); | ||
731 | return -EINVAL; | ||
732 | } | ||
733 | mutex_lock(&instance_data->status_mutex); | ||
734 | if (instance_data->status != BUSY) { | ||
735 | instance_data->report_type = (enum f54_report_types)val; | ||
736 | data = (char)val; | ||
737 | /* Write the Report Type back to the first Block | ||
738 | * Data registers (F54_AD_Data0). */ | ||
739 | result = | ||
740 | rmi_write_block(fc->rmi_dev, fc->fd.data_base_addr, | ||
741 | &data, 1); | ||
742 | mutex_unlock(&instance_data->status_mutex); | ||
743 | if (result < 0) { | ||
744 | dev_err(dev, "%s : Could not write report type to" | ||
745 | " 0x%x\n", __func__, fc->fd.data_base_addr); | ||
746 | return result; | ||
747 | } | ||
748 | return count; | ||
749 | } else { | ||
750 | dev_err(dev, "%s : Report type cannot be changed in the middle" | ||
751 | " of command.\n", __func__); | ||
752 | mutex_unlock(&instance_data->status_mutex); | ||
753 | return -EINVAL; | ||
754 | } | ||
755 | } | ||
756 | |||
757 | static ssize_t rmi_fn_54_get_report_store(struct device *dev, | ||
758 | struct device_attribute *attr, | ||
759 | const char *buf, size_t count) { | ||
760 | unsigned long val; | ||
761 | int error, result; | ||
762 | struct rmi_function_container *fc; | ||
763 | struct rmi_fn_54_data *instance_data; | ||
764 | struct rmi_driver *driver; | ||
765 | u8 command; | ||
766 | fc = to_rmi_function_container(dev); | ||
767 | instance_data = fc->data; | ||
768 | driver = fc->rmi_dev->driver; | ||
769 | |||
770 | /* need to convert the string data to an actual value */ | ||
771 | error = strict_strtoul(buf, 10, &val); | ||
772 | if (error) | ||
773 | return error; | ||
774 | /* Do nothing if not set to 1. This prevents accidental commands. */ | ||
775 | if (val != 1) | ||
776 | return count; | ||
777 | command = (unsigned char)GET_REPORT; | ||
778 | /* Basic checks on report_type to ensure we write a valid type | ||
779 | * to the sensor. | ||
780 | * TODO: Check Query3 to see if some specific reports are | ||
781 | * available. This is currently listed as a reserved register. | ||
782 | */ | ||
783 | if (!is_report_type_valid(instance_data->report_type)) { | ||
784 | dev_err(dev, "%s : Report type %d is invalid.\n", | ||
785 | __func__, instance_data->report_type); | ||
786 | return -EINVAL; | ||
787 | } | ||
788 | mutex_lock(&instance_data->status_mutex); | ||
789 | if (instance_data->status != IDLE) { | ||
790 | if (instance_data->status != BUSY) { | ||
791 | dev_err(dev, "F54 status is in an abnormal state: 0x%x", | ||
792 | instance_data->status); | ||
793 | } | ||
794 | mutex_unlock(&instance_data->status_mutex); | ||
795 | return count; | ||
796 | } | ||
797 | /* Store interrupts */ | ||
798 | /* Do not exit if we fail to turn off interupts. We are likely | ||
799 | * to still get useful data. The report data can, however, be | ||
800 | * corrupted, and there may be unexpected behavior. | ||
801 | */ | ||
802 | dev_dbg(dev, "Storing and overriding interupts\n"); | ||
803 | if (driver->store_irq_mask) | ||
804 | driver->store_irq_mask(fc->rmi_dev, | ||
805 | fc->irq_mask); | ||
806 | else | ||
807 | dev_err(dev, "No way to store interupts!\n"); | ||
808 | instance_data->status = BUSY; | ||
809 | |||
810 | /* small delay to avoid race condition in firmare. This value is a bit | ||
811 | * higher than absolutely necessary. Should be removed once issue is | ||
812 | * resolved in firmware. */ | ||
813 | |||
814 | mdelay(2); | ||
815 | |||
816 | /* Write the command to the command register */ | ||
817 | result = rmi_write_block(fc->rmi_dev, fc->fd.command_base_addr, | ||
818 | &command, 1); | ||
819 | mutex_unlock(&instance_data->status_mutex); | ||
820 | if (result < 0) { | ||
821 | dev_err(dev, "%s : Could not write command to 0x%x\n", | ||
822 | __func__, fc->fd.command_base_addr); | ||
823 | return result; | ||
824 | } | ||
825 | #if F54_WATCHDOG | ||
826 | /* start watchdog timer */ | ||
827 | hrtimer_start(&instance_data->watchdog, ktime_set(1, 0), | ||
828 | HRTIMER_MODE_REL); | ||
829 | #endif | ||
830 | return count; | ||
831 | } | ||
832 | |||
833 | static ssize_t rmi_fn_54_force_cal_store(struct device *dev, | ||
834 | struct device_attribute *attr, | ||
835 | const char *buf, size_t count) { | ||
836 | unsigned long val; | ||
837 | int error, result; | ||
838 | struct rmi_function_container *fc; | ||
839 | struct rmi_fn_54_data *instance_data; | ||
840 | struct rmi_driver *driver; | ||
841 | u8 command; | ||
842 | |||
843 | fc = to_rmi_function_container(dev); | ||
844 | instance_data = fc->data; | ||
845 | driver = fc->rmi_dev->driver; | ||
846 | |||
847 | /* need to convert the string data to an actual value */ | ||
848 | error = strict_strtoul(buf, 10, &val); | ||
849 | if (error) | ||
850 | return error; | ||
851 | /* Do nothing if not set to 1. This prevents accidental commands. */ | ||
852 | if (val != 1) | ||
853 | return count; | ||
854 | |||
855 | command = (unsigned char)FORCE_CAL; | ||
856 | |||
857 | if (instance_data->status == BUSY) | ||
858 | return -EBUSY; | ||
859 | /* Write the command to the command register */ | ||
860 | result = rmi_write_block(fc->rmi_dev, fc->fd.command_base_addr, | ||
861 | &command, 1); | ||
862 | if (result < 0) { | ||
863 | dev_err(dev, "%s : Could not write command to 0x%x\n", | ||
864 | __func__, fc->fd.command_base_addr); | ||
865 | return result; | ||
866 | } | ||
867 | return count; | ||
868 | } | ||
869 | |||
870 | static ssize_t rmi_fn_54_status_show(struct device *dev, | ||
871 | struct device_attribute *attr, char *buf) { | ||
872 | struct rmi_function_container *fc; | ||
873 | struct rmi_fn_54_data *instance_data; | ||
874 | |||
875 | fc = to_rmi_function_container(dev); | ||
876 | instance_data = fc->data; | ||
877 | |||
878 | return snprintf(buf, PAGE_SIZE, "%d\n", instance_data->status); | ||
879 | } | ||
880 | |||
881 | static ssize_t rmi_fn_54_num_rx_electrodes_show(struct device *dev, | ||
882 | struct device_attribute *attr, char *buf) { | ||
883 | struct rmi_function_container *fc; | ||
884 | struct rmi_fn_54_data *data; | ||
885 | |||
886 | fc = to_rmi_function_container(dev); | ||
887 | data = fc->data; | ||
888 | |||
889 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
890 | data->query.number_of_receiver_electrodes); | ||
891 | } | ||
892 | |||
893 | static ssize_t rmi_fn_54_num_tx_electrodes_show(struct device *dev, | ||
894 | struct device_attribute *attr, char *buf) { | ||
895 | struct rmi_function_container *fc; | ||
896 | struct rmi_fn_54_data *data; | ||
897 | |||
898 | fc = to_rmi_function_container(dev); | ||
899 | data = fc->data; | ||
900 | |||
901 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
902 | data->query.number_of_transmitter_electrodes); | ||
903 | } | ||
904 | |||
905 | static ssize_t rmi_fn_54_has_image16_show(struct device *dev, | ||
906 | struct device_attribute *attr, char *buf) { | ||
907 | struct rmi_function_container *fc; | ||
908 | struct rmi_fn_54_data *data; | ||
909 | |||
910 | fc = to_rmi_function_container(dev); | ||
911 | data = fc->data; | ||
912 | |||
913 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
914 | data->query.has_image16); | ||
915 | } | ||
916 | |||
917 | static ssize_t rmi_fn_54_has_image8_show(struct device *dev, | ||
918 | struct device_attribute *attr, char *buf) { | ||
919 | struct rmi_function_container *fc; | ||
920 | struct rmi_fn_54_data *data; | ||
921 | |||
922 | fc = to_rmi_function_container(dev); | ||
923 | data = fc->data; | ||
924 | |||
925 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
926 | data->query.has_image8); | ||
927 | } | ||
928 | |||
929 | static ssize_t rmi_fn_54_has_baseline_show(struct device *dev, | ||
930 | struct device_attribute *attr, char *buf) { | ||
931 | struct rmi_function_container *fc; | ||
932 | struct rmi_fn_54_data *data; | ||
933 | |||
934 | fc = to_rmi_function_container(dev); | ||
935 | data = fc->data; | ||
936 | |||
937 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
938 | data->query.has_baseline); | ||
939 | } | ||
940 | |||
941 | static ssize_t rmi_fn_54_clock_rate_show(struct device *dev, | ||
942 | struct device_attribute *attr, char *buf) { | ||
943 | struct rmi_function_container *fc; | ||
944 | struct rmi_fn_54_data *data; | ||
945 | |||
946 | fc = to_rmi_function_container(dev); | ||
947 | data = fc->data; | ||
948 | |||
949 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
950 | data->query.clock_rate); | ||
951 | } | ||
952 | |||
953 | |||
954 | static ssize_t rmi_fn_54_touch_controller_family_show(struct device *dev, | ||
955 | struct device_attribute *attr, char *buf) { | ||
956 | struct rmi_function_container *fc; | ||
957 | struct rmi_fn_54_data *data; | ||
958 | |||
959 | fc = to_rmi_function_container(dev); | ||
960 | data = fc->data; | ||
961 | |||
962 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
963 | data->query.touch_controller_family); | ||
964 | } | ||
965 | |||
966 | |||
967 | static ssize_t rmi_fn_54_has_pixel_touch_threshold_adjustment_show( | ||
968 | struct device *dev, struct device_attribute *attr, char *buf) { | ||
969 | struct rmi_function_container *fc; | ||
970 | struct rmi_fn_54_data *data; | ||
971 | |||
972 | fc = to_rmi_function_container(dev); | ||
973 | data = fc->data; | ||
974 | |||
975 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
976 | data->query.has_pixel_touch_threshold_adjustment); | ||
977 | } | ||
978 | |||
979 | static ssize_t rmi_fn_54_has_sensor_assignment_show(struct device *dev, | ||
980 | struct device_attribute *attr, char *buf) { | ||
981 | struct rmi_function_container *fc; | ||
982 | struct rmi_fn_54_data *data; | ||
983 | |||
984 | fc = to_rmi_function_container(dev); | ||
985 | data = fc->data; | ||
986 | |||
987 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
988 | data->query.has_sensor_assignment); | ||
989 | } | ||
990 | |||
991 | static ssize_t rmi_fn_54_has_interference_metric_show(struct device *dev, | ||
992 | struct device_attribute *attr, char *buf) { | ||
993 | struct rmi_function_container *fc; | ||
994 | struct rmi_fn_54_data *data; | ||
995 | |||
996 | fc = to_rmi_function_container(dev); | ||
997 | data = fc->data; | ||
998 | |||
999 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1000 | data->query.has_interference_metric); | ||
1001 | } | ||
1002 | |||
1003 | static ssize_t rmi_fn_54_has_sense_frequency_control_show(struct device *dev, | ||
1004 | struct device_attribute *attr, char *buf) { | ||
1005 | struct rmi_function_container *fc; | ||
1006 | struct rmi_fn_54_data *data; | ||
1007 | |||
1008 | fc = to_rmi_function_container(dev); | ||
1009 | data = fc->data; | ||
1010 | |||
1011 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1012 | data->query.has_sense_frequency_control); | ||
1013 | } | ||
1014 | |||
1015 | static ssize_t rmi_fn_54_has_firmware_noise_mitigation_show(struct device *dev, | ||
1016 | struct device_attribute *attr, char *buf) { | ||
1017 | struct rmi_function_container *fc; | ||
1018 | struct rmi_fn_54_data *data; | ||
1019 | |||
1020 | fc = to_rmi_function_container(dev); | ||
1021 | data = fc->data; | ||
1022 | |||
1023 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1024 | data->query.has_firmware_noise_mitigation); | ||
1025 | } | ||
1026 | |||
1027 | static ssize_t rmi_fn_54_has_two_byte_report_rate_show(struct device *dev, | ||
1028 | struct device_attribute *attr, char *buf) { | ||
1029 | struct rmi_function_container *fc; | ||
1030 | struct rmi_fn_54_data *data; | ||
1031 | |||
1032 | fc = to_rmi_function_container(dev); | ||
1033 | data = fc->data; | ||
1034 | |||
1035 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1036 | data->query.has_two_byte_report_rate); | ||
1037 | } | ||
1038 | |||
1039 | static ssize_t rmi_fn_54_has_one_byte_report_rate_show(struct device *dev, | ||
1040 | struct device_attribute *attr, char *buf) { | ||
1041 | struct rmi_function_container *fc; | ||
1042 | struct rmi_fn_54_data *data; | ||
1043 | |||
1044 | fc = to_rmi_function_container(dev); | ||
1045 | data = fc->data; | ||
1046 | |||
1047 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1048 | data->query.has_one_byte_report_rate); | ||
1049 | } | ||
1050 | |||
1051 | static ssize_t rmi_fn_54_has_relaxation_control_show(struct device *dev, | ||
1052 | struct device_attribute *attr, char *buf) { | ||
1053 | struct rmi_function_container *fc; | ||
1054 | struct rmi_fn_54_data *data; | ||
1055 | |||
1056 | fc = to_rmi_function_container(dev); | ||
1057 | data = fc->data; | ||
1058 | |||
1059 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1060 | data->query.has_relaxation_control); | ||
1061 | } | ||
1062 | |||
1063 | static ssize_t rmi_fn_54_curve_compensation_mode_show(struct device *dev, | ||
1064 | struct device_attribute *attr, char *buf) { | ||
1065 | struct rmi_function_container *fc; | ||
1066 | struct rmi_fn_54_data *data; | ||
1067 | |||
1068 | fc = to_rmi_function_container(dev); | ||
1069 | data = fc->data; | ||
1070 | |||
1071 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1072 | data->query.curve_compensation_mode); | ||
1073 | } | ||
1074 | |||
1075 | static ssize_t rmi_fn_54_has_iir_filter_show(struct device *dev, | ||
1076 | struct device_attribute *attr, char *buf) { | ||
1077 | struct rmi_function_container *fc; | ||
1078 | struct rmi_fn_54_data *data; | ||
1079 | |||
1080 | fc = to_rmi_function_container(dev); | ||
1081 | data = fc->data; | ||
1082 | |||
1083 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1084 | data->query.has_iir_filter); | ||
1085 | } | ||
1086 | |||
1087 | static ssize_t rmi_fn_54_has_cmn_removal_show(struct device *dev, | ||
1088 | struct device_attribute *attr, char *buf) { | ||
1089 | struct rmi_function_container *fc; | ||
1090 | struct rmi_fn_54_data *data; | ||
1091 | |||
1092 | fc = to_rmi_function_container(dev); | ||
1093 | data = fc->data; | ||
1094 | |||
1095 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1096 | data->query.has_cmn_removal); | ||
1097 | } | ||
1098 | |||
1099 | static ssize_t rmi_fn_54_has_cmn_maximum_show(struct device *dev, | ||
1100 | struct device_attribute *attr, char *buf) { | ||
1101 | struct rmi_function_container *fc; | ||
1102 | struct rmi_fn_54_data *data; | ||
1103 | |||
1104 | fc = to_rmi_function_container(dev); | ||
1105 | data = fc->data; | ||
1106 | |||
1107 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1108 | data->query.has_cmn_maximum); | ||
1109 | } | ||
1110 | |||
1111 | static ssize_t rmi_fn_54_has_pixel_threshold_hysteresis_show(struct device *dev, | ||
1112 | struct device_attribute *attr, char *buf) { | ||
1113 | struct rmi_function_container *fc; | ||
1114 | struct rmi_fn_54_data *data; | ||
1115 | |||
1116 | fc = to_rmi_function_container(dev); | ||
1117 | data = fc->data; | ||
1118 | |||
1119 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1120 | data->query.has_pixel_threshold_hysteresis); | ||
1121 | } | ||
1122 | |||
1123 | static ssize_t rmi_fn_54_has_edge_compensation_show(struct device *dev, | ||
1124 | struct device_attribute *attr, char *buf) { | ||
1125 | struct rmi_function_container *fc; | ||
1126 | struct rmi_fn_54_data *data; | ||
1127 | |||
1128 | fc = to_rmi_function_container(dev); | ||
1129 | data = fc->data; | ||
1130 | |||
1131 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1132 | data->query.has_edge_compensation); | ||
1133 | } | ||
1134 | |||
1135 | static ssize_t rmi_fn_54_has_perf_frequency_noisecontrol_show( | ||
1136 | struct device *dev, struct device_attribute *attr, char *buf) { | ||
1137 | struct rmi_function_container *fc; | ||
1138 | struct rmi_fn_54_data *data; | ||
1139 | |||
1140 | fc = to_rmi_function_container(dev); | ||
1141 | data = fc->data; | ||
1142 | |||
1143 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1144 | data->query.has_perf_frequency_noisecontrol); | ||
1145 | } | ||
1146 | |||
1147 | static ssize_t rmi_fn_54_number_of_sensing_frequencies_show(struct device *dev, | ||
1148 | struct device_attribute *attr, char *buf) { | ||
1149 | struct rmi_function_container *fc; | ||
1150 | struct rmi_fn_54_data *data; | ||
1151 | |||
1152 | fc = to_rmi_function_container(dev); | ||
1153 | data = fc->data; | ||
1154 | |||
1155 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1156 | data->query.number_of_sensing_frequencies); | ||
1157 | } | ||
1158 | |||
1159 | |||
1160 | static ssize_t rmi_fn_54_no_auto_cal_show(struct device *dev, | ||
1161 | struct device_attribute *attr, char *buf) { | ||
1162 | struct rmi_function_container *fc; | ||
1163 | struct rmi_fn_54_data *instance_data; | ||
1164 | |||
1165 | fc = to_rmi_function_container(dev); | ||
1166 | instance_data = fc->data; | ||
1167 | |||
1168 | return snprintf(buf, PAGE_SIZE, "%u\n", | ||
1169 | instance_data->no_auto_cal ? 1 : 0); | ||
1170 | } | ||
1171 | |||
1172 | static ssize_t rmi_fn_54_no_auto_cal_store(struct device *dev, | ||
1173 | struct device_attribute *attr, | ||
1174 | const char *buf, size_t count) { | ||
1175 | int result; | ||
1176 | unsigned long val; | ||
1177 | unsigned char data; | ||
1178 | struct rmi_function_container *fc; | ||
1179 | struct rmi_fn_54_data *instance_data; | ||
1180 | |||
1181 | fc = to_rmi_function_container(dev); | ||
1182 | instance_data = fc->data; | ||
1183 | |||
1184 | /* need to convert the string data to an actual value */ | ||
1185 | result = strict_strtoul(buf, 10, &val); | ||
1186 | |||
1187 | /* if an error occured, return it */ | ||
1188 | if (result) | ||
1189 | return result; | ||
1190 | /* Do nothing if not 0 or 1. This prevents accidental commands. */ | ||
1191 | if (val > 1) | ||
1192 | return count; | ||
1193 | /* Read current control values */ | ||
1194 | result = | ||
1195 | rmi_read_block(fc->rmi_dev, fc->fd.control_base_addr, &data, 1); | ||
1196 | |||
1197 | /* if the current control registers are already set as we want them, do | ||
1198 | * nothing to them */ | ||
1199 | if ((data & 1) == val) | ||
1200 | return count; | ||
1201 | /* Write the control back to the control register (F54_AD_Ctrl0) | ||
1202 | * Ignores everything but bit 0 */ | ||
1203 | data = (data & ~1) | (val & 0x01); /* bit mask for lowest bit */ | ||
1204 | result = | ||
1205 | rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr, &data, 1); | ||
1206 | if (result < 0) { | ||
1207 | dev_err(dev, "%s : Could not write control to 0x%x\n", | ||
1208 | __func__, fc->fd.control_base_addr); | ||
1209 | return result; | ||
1210 | } | ||
1211 | /* update our internal representation iff the write succeeds */ | ||
1212 | instance_data->no_auto_cal = (val == 1); | ||
1213 | return count; | ||
1214 | } | ||
1215 | |||
1216 | static ssize_t rmi_fn_54_fifoindex_show(struct device *dev, | ||
1217 | struct device_attribute *attr, char *buf) { | ||
1218 | struct rmi_function_container *fc; | ||
1219 | struct rmi_fn_54_data *instance_data; | ||
1220 | struct rmi_driver *driver; | ||
1221 | unsigned char temp_buf[2]; | ||
1222 | int retval; | ||
1223 | |||
1224 | fc = to_rmi_function_container(dev); | ||
1225 | instance_data = fc->data; | ||
1226 | driver = fc->rmi_dev->driver; | ||
1227 | |||
1228 | /* Read fifoindex from device */ | ||
1229 | retval = rmi_read_block(fc->rmi_dev, | ||
1230 | fc->fd.data_base_addr + RMI_F54_FIFO_OFFSET, | ||
1231 | temp_buf, ARRAY_SIZE(temp_buf)); | ||
1232 | |||
1233 | if (retval < 0) { | ||
1234 | dev_err(dev, "Could not read fifoindex from 0x%04x\n", | ||
1235 | fc->fd.data_base_addr + RMI_F54_FIFO_OFFSET); | ||
1236 | return retval; | ||
1237 | } | ||
1238 | batohs(&instance_data->fifoindex, temp_buf); | ||
1239 | return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->fifoindex); | ||
1240 | } | ||
1241 | static ssize_t rmi_fn_54_fifoindex_store(struct device *dev, | ||
1242 | struct device_attribute *attr, | ||
1243 | const char *buf, | ||
1244 | size_t count) | ||
1245 | { | ||
1246 | int error; | ||
1247 | unsigned long val; | ||
1248 | unsigned char data[2]; | ||
1249 | struct rmi_function_container *fc; | ||
1250 | struct rmi_fn_54_data *instance_data; | ||
1251 | |||
1252 | fc = to_rmi_function_container(dev); | ||
1253 | instance_data = fc->data; | ||
1254 | |||
1255 | /* need to convert the string data to an actual value */ | ||
1256 | error = strict_strtoul(buf, 10, &val); | ||
1257 | |||
1258 | if (error) | ||
1259 | return error; | ||
1260 | |||
1261 | instance_data->fifoindex = val; | ||
1262 | |||
1263 | /* Write the FifoIndex back to the first data registers. */ | ||
1264 | hstoba(data, (unsigned short)val); | ||
1265 | |||
1266 | error = rmi_write_block(fc->rmi_dev, | ||
1267 | fc->fd.data_base_addr + RMI_F54_FIFO_OFFSET, | ||
1268 | data, | ||
1269 | ARRAY_SIZE(data)); | ||
1270 | |||
1271 | if (error < 0) { | ||
1272 | dev_err(dev, "%s : Could not write fifoindex to 0x%x\n", | ||
1273 | __func__, fc->fd.data_base_addr + RMI_F54_FIFO_OFFSET); | ||
1274 | return error; | ||
1275 | } | ||
1276 | return count; | ||
1277 | } | ||
1278 | |||
1279 | /* Provide access to last report */ | ||
1280 | #ifdef KERNEL_VERSION_ABOVE_2_6_32 | ||
1281 | static ssize_t rmi_fn_54_data_read(struct file *data_file, struct kobject *kobj, | ||
1282 | #else | ||
1283 | static ssize_t rmi_fn_54_data_read(struct kobject *kobj, | ||
1284 | #endif | ||
1285 | struct bin_attribute *attributes, | ||
1286 | char *buf, loff_t pos, size_t count) | ||
1287 | { | ||
1288 | struct device *dev; | ||
1289 | struct rmi_function_container *fc; | ||
1290 | struct rmi_fn_54_data *instance_data; | ||
1291 | |||
1292 | dev = container_of(kobj, struct device, kobj); | ||
1293 | fc = to_rmi_function_container(dev); | ||
1294 | instance_data = fc->data; | ||
1295 | mutex_lock(&instance_data->data_mutex); | ||
1296 | if (count < instance_data->report_size) { | ||
1297 | dev_err(dev, | ||
1298 | "%s: F54 report size too large for buffer: %d." | ||
1299 | " Need at least: %d for Report type: %d.\n", | ||
1300 | __func__, count, instance_data->report_size, | ||
1301 | instance_data->report_type); | ||
1302 | mutex_unlock(&instance_data->data_mutex); | ||
1303 | return -EINVAL; | ||
1304 | } | ||
1305 | if (instance_data->report_data) { | ||
1306 | /* Copy data from instance_data to buffer */ | ||
1307 | memcpy(buf, instance_data->report_data, | ||
1308 | instance_data->report_size); | ||
1309 | mutex_unlock(&instance_data->data_mutex); | ||
1310 | dev_dbg(dev, "%s: Presumably successful.", __func__); | ||
1311 | return instance_data->report_size; | ||
1312 | } else { | ||
1313 | dev_err(dev, "%s: F54 report_data does not exist!\n", __func__); | ||
1314 | mutex_unlock(&instance_data->data_mutex); | ||
1315 | return -EINVAL; | ||
1316 | } | ||
1317 | } | ||
1318 | |||
1319 | static struct rmi_function_handler function_handler = { | ||
1320 | .func = 0x54, | ||
1321 | .init = rmi_f54_init, | ||
1322 | .attention = rmi_f54_attention | ||
1323 | }; | ||
1324 | |||
1325 | static int __init rmi_f54_module_init(void) | ||
1326 | { | ||
1327 | int error; | ||
1328 | |||
1329 | error = rmi_register_function_driver(&function_handler); | ||
1330 | if (error < 0) { | ||
1331 | pr_err("%s: register failed!\n", __func__); | ||
1332 | return error; | ||
1333 | } | ||
1334 | return 0; | ||
1335 | } | ||
1336 | |||
1337 | static void rmi_f54_module_exit(void) | ||
1338 | { | ||
1339 | rmi_unregister_function_driver(&function_handler); | ||
1340 | } | ||
1341 | |||
1342 | module_init(rmi_f54_module_init); | ||
1343 | module_exit(rmi_f54_module_exit); | ||
1344 | |||
1345 | MODULE_AUTHOR("Daniel Rosenberg <daniel.rosenberg@synaptics.com>"); | ||
1346 | MODULE_DESCRIPTION("RMI F54 module"); | ||
1347 | MODULE_LICENSE("GPL"); | ||