chenx | 587bb98 | 2017-08-31 15:46:23 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Synaptics DSX touchscreen driver |
| 3 | * |
| 4 | * Copyright (C) 2012-2016 Synaptics Incorporated. All rights reserved. |
| 5 | * |
| 6 | * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com> |
| 7 | * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS |
| 20 | * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, |
| 22 | * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS. |
| 23 | * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION |
| 25 | * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED |
| 26 | * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 27 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF |
| 28 | * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES |
| 29 | * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS' |
| 30 | * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S. |
| 31 | * DOLLARS. |
| 32 | */ |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/input.h> |
| 39 | #include <linux/gpio.h> |
| 40 | #include <linux/platform_device.h> |
| 41 | #include <linux/regulator/consumer.h> |
| 42 | #include <linux/input/synaptics_dsx.h> |
| 43 | #include "synaptics_dsx_core.h" |
| 44 | #ifdef KERNEL_ABOVE_2_6_38 |
| 45 | #include <linux/input/mt.h> |
| 46 | #endif |
| 47 | |
| 48 | #include <linux/msm_drm_notify.h> |
| 49 | |
| 50 | #define INPUT_PHYS_NAME "synaptics_dsx/touch_input" |
| 51 | #define STYLUS_PHYS_NAME "synaptics_dsx/stylus" |
| 52 | |
| 53 | #define VIRTUAL_KEY_MAP_FILE_NAME "virtualkeys." PLATFORM_DRIVER_NAME |
| 54 | |
| 55 | #ifdef KERNEL_ABOVE_2_6_38 |
| 56 | #define TYPE_B_PROTOCOL |
| 57 | #endif |
| 58 | |
| 59 | /* |
| 60 | #define USE_DATA_SERVER |
| 61 | */ |
| 62 | |
| 63 | #define WAKEUP_GESTURE false |
| 64 | |
| 65 | #define NO_0D_WHILE_2D |
| 66 | #define REPORT_2D_Z |
| 67 | #define REPORT_2D_W |
| 68 | /* |
| 69 | #define REPORT_2D_PRESSURE |
| 70 | */ |
| 71 | |
| 72 | #define F12_DATA_15_WORKAROUND |
| 73 | |
| 74 | #define IGNORE_FN_INIT_FAILURE |
| 75 | #define FB_READY_RESET |
| 76 | #define FB_READY_WAIT_MS 100 |
| 77 | #define FB_READY_TIMEOUT_S 30 |
| 78 | #ifdef SYNA_TDDI |
| 79 | #define TDDI_LPWG_WAIT_US 10 |
| 80 | #endif |
| 81 | #define RPT_TYPE (1 << 0) |
| 82 | #define RPT_X_LSB (1 << 1) |
| 83 | #define RPT_X_MSB (1 << 2) |
| 84 | #define RPT_Y_LSB (1 << 3) |
| 85 | #define RPT_Y_MSB (1 << 4) |
| 86 | #define RPT_Z (1 << 5) |
| 87 | #define RPT_WX (1 << 6) |
| 88 | #define RPT_WY (1 << 7) |
| 89 | #define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB) |
| 90 | |
| 91 | #define REBUILD_WORK_DELAY_MS 500 /* ms */ |
| 92 | |
| 93 | #define EXP_FN_WORK_DELAY_MS 500 /* ms */ |
| 94 | #define MAX_F11_TOUCH_WIDTH 15 |
| 95 | #define MAX_F12_TOUCH_WIDTH 255 |
| 96 | |
| 97 | #define CHECK_STATUS_TIMEOUT_MS 100 |
| 98 | |
| 99 | #define F01_STD_QUERY_LEN 21 |
| 100 | #define F01_BUID_ID_OFFSET 18 |
| 101 | |
| 102 | #define STATUS_NO_ERROR 0x00 |
| 103 | #define STATUS_RESET_OCCURRED 0x01 |
| 104 | #define STATUS_INVALID_CONFIG 0x02 |
| 105 | #define STATUS_DEVICE_FAILURE 0x03 |
| 106 | #define STATUS_CONFIG_CRC_FAILURE 0x04 |
| 107 | #define STATUS_FIRMWARE_CRC_FAILURE 0x05 |
| 108 | #define STATUS_CRC_IN_PROGRESS 0x06 |
| 109 | |
| 110 | #define NORMAL_OPERATION (0 << 0) |
| 111 | #define SENSOR_SLEEP (1 << 0) |
| 112 | #define NO_SLEEP_OFF (0 << 2) |
| 113 | #define NO_SLEEP_ON (1 << 2) |
| 114 | #define CONFIGURED (1 << 7) |
| 115 | |
| 116 | #define F11_CONTINUOUS_MODE 0x00 |
| 117 | #define F11_WAKEUP_GESTURE_MODE 0x04 |
| 118 | #define F12_CONTINUOUS_MODE 0x00 |
| 119 | #define F12_WAKEUP_GESTURE_MODE 0x02 |
| 120 | #define F12_UDG_DETECT 0x0f |
| 121 | |
| 122 | static int synaptics_rmi4_check_status(struct synaptics_rmi4_data *rmi4_data, |
| 123 | bool *was_in_bl_mode); |
| 124 | static int synaptics_rmi4_free_fingers(struct synaptics_rmi4_data *rmi4_data); |
| 125 | static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data); |
| 126 | static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data, |
| 127 | bool rebuild); |
| 128 | #ifdef CONFIG_FB |
| 129 | static int synaptics_rmi4_dsi_panel_notifier_cb(struct notifier_block *self, |
| 130 | unsigned long event, void *data); |
| 131 | #endif |
| 132 | |
| 133 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 134 | #ifndef CONFIG_FB |
| 135 | #define USE_EARLYSUSPEND |
| 136 | #endif |
| 137 | #endif |
| 138 | |
| 139 | #ifdef USE_EARLYSUSPEND |
| 140 | static int synaptics_rmi4_early_suspend(struct early_suspend *h); |
| 141 | |
| 142 | static int synaptics_rmi4_late_resume(struct early_suspend *h); |
| 143 | #endif |
| 144 | |
| 145 | static int synaptics_rmi4_suspend(struct device *dev); |
| 146 | |
| 147 | static int synaptics_rmi4_resume(struct device *dev); |
| 148 | |
| 149 | static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev, |
| 150 | struct device_attribute *attr, const char *buf, size_t count); |
| 151 | |
| 152 | static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev, |
| 153 | struct device_attribute *attr, char *buf); |
| 154 | |
| 155 | static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev, |
| 156 | struct device_attribute *attr, char *buf); |
| 157 | |
| 158 | static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev, |
| 159 | struct device_attribute *attr, char *buf); |
| 160 | |
| 161 | static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev, |
| 162 | struct device_attribute *attr, char *buf); |
| 163 | |
| 164 | static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev, |
| 165 | struct device_attribute *attr, const char *buf, size_t count); |
| 166 | |
| 167 | static ssize_t synaptics_rmi4_suspend_store(struct device *dev, |
| 168 | struct device_attribute *attr, const char *buf, size_t count); |
| 169 | |
| 170 | static ssize_t synaptics_rmi4_wake_gesture_show(struct device *dev, |
| 171 | struct device_attribute *attr, char *buf); |
| 172 | |
| 173 | static ssize_t synaptics_rmi4_wake_gesture_store(struct device *dev, |
| 174 | struct device_attribute *attr, const char *buf, size_t count); |
| 175 | |
| 176 | #ifdef USE_DATA_SERVER |
| 177 | static ssize_t synaptics_rmi4_synad_pid_store(struct device *dev, |
| 178 | struct device_attribute *attr, const char *buf, size_t count); |
| 179 | #endif |
| 180 | |
| 181 | static ssize_t synaptics_rmi4_virtual_key_map_show(struct kobject *kobj, |
| 182 | struct kobj_attribute *attr, char *buf); |
| 183 | |
| 184 | struct synaptics_rmi4_f01_device_status { |
| 185 | union { |
| 186 | struct { |
| 187 | unsigned char status_code:4; |
| 188 | unsigned char reserved:2; |
| 189 | unsigned char flash_prog:1; |
| 190 | unsigned char unconfigured:1; |
| 191 | } __packed; |
| 192 | unsigned char data[1]; |
| 193 | }; |
| 194 | }; |
| 195 | |
| 196 | struct synaptics_rmi4_f11_query_0_5 { |
| 197 | union { |
| 198 | struct { |
| 199 | /* query 0 */ |
| 200 | unsigned char f11_query0_b0__2:3; |
| 201 | unsigned char has_query_9:1; |
| 202 | unsigned char has_query_11:1; |
| 203 | unsigned char has_query_12:1; |
| 204 | unsigned char has_query_27:1; |
| 205 | unsigned char has_query_28:1; |
| 206 | |
| 207 | /* query 1 */ |
| 208 | unsigned char num_of_fingers:3; |
| 209 | unsigned char has_rel:1; |
| 210 | unsigned char has_abs:1; |
| 211 | unsigned char has_gestures:1; |
| 212 | unsigned char has_sensitibity_adjust:1; |
| 213 | unsigned char f11_query1_b7:1; |
| 214 | |
| 215 | /* query 2 */ |
| 216 | unsigned char num_of_x_electrodes; |
| 217 | |
| 218 | /* query 3 */ |
| 219 | unsigned char num_of_y_electrodes; |
| 220 | |
| 221 | /* query 4 */ |
| 222 | unsigned char max_electrodes:7; |
| 223 | unsigned char f11_query4_b7:1; |
| 224 | |
| 225 | /* query 5 */ |
| 226 | unsigned char abs_data_size:2; |
| 227 | unsigned char has_anchored_finger:1; |
| 228 | unsigned char has_adj_hyst:1; |
| 229 | unsigned char has_dribble:1; |
| 230 | unsigned char has_bending_correction:1; |
| 231 | unsigned char has_large_object_suppression:1; |
| 232 | unsigned char has_jitter_filter:1; |
| 233 | } __packed; |
| 234 | unsigned char data[6]; |
| 235 | }; |
| 236 | }; |
| 237 | |
| 238 | struct synaptics_rmi4_f11_query_7_8 { |
| 239 | union { |
| 240 | struct { |
| 241 | /* query 7 */ |
| 242 | unsigned char has_single_tap:1; |
| 243 | unsigned char has_tap_and_hold:1; |
| 244 | unsigned char has_double_tap:1; |
| 245 | unsigned char has_early_tap:1; |
| 246 | unsigned char has_flick:1; |
| 247 | unsigned char has_press:1; |
| 248 | unsigned char has_pinch:1; |
| 249 | unsigned char has_chiral_scroll:1; |
| 250 | |
| 251 | /* query 8 */ |
| 252 | unsigned char has_palm_detect:1; |
| 253 | unsigned char has_rotate:1; |
| 254 | unsigned char has_touch_shapes:1; |
| 255 | unsigned char has_scroll_zones:1; |
| 256 | unsigned char individual_scroll_zones:1; |
| 257 | unsigned char has_multi_finger_scroll:1; |
| 258 | unsigned char has_multi_finger_scroll_edge_motion:1; |
| 259 | unsigned char has_multi_finger_scroll_inertia:1; |
| 260 | } __packed; |
| 261 | unsigned char data[2]; |
| 262 | }; |
| 263 | }; |
| 264 | |
| 265 | struct synaptics_rmi4_f11_query_9 { |
| 266 | union { |
| 267 | struct { |
| 268 | unsigned char has_pen:1; |
| 269 | unsigned char has_proximity:1; |
| 270 | unsigned char has_large_object_sensitivity:1; |
| 271 | unsigned char has_suppress_on_large_object_detect:1; |
| 272 | unsigned char has_two_pen_thresholds:1; |
| 273 | unsigned char has_contact_geometry:1; |
| 274 | unsigned char has_pen_hover_discrimination:1; |
| 275 | unsigned char has_pen_hover_and_edge_filters:1; |
| 276 | } __packed; |
| 277 | unsigned char data[1]; |
| 278 | }; |
| 279 | }; |
| 280 | |
| 281 | struct synaptics_rmi4_f11_query_12 { |
| 282 | union { |
| 283 | struct { |
| 284 | unsigned char has_small_object_detection:1; |
| 285 | unsigned char has_small_object_detection_tuning:1; |
| 286 | unsigned char has_8bit_w:1; |
| 287 | unsigned char has_2d_adjustable_mapping:1; |
| 288 | unsigned char has_general_information_2:1; |
| 289 | unsigned char has_physical_properties:1; |
| 290 | unsigned char has_finger_limit:1; |
| 291 | unsigned char has_linear_cofficient_2:1; |
| 292 | } __packed; |
| 293 | unsigned char data[1]; |
| 294 | }; |
| 295 | }; |
| 296 | |
| 297 | struct synaptics_rmi4_f11_query_27 { |
| 298 | union { |
| 299 | struct { |
| 300 | unsigned char f11_query27_b0:1; |
| 301 | unsigned char has_pen_position_correction:1; |
| 302 | unsigned char has_pen_jitter_filter_coefficient:1; |
| 303 | unsigned char has_group_decomposition:1; |
| 304 | unsigned char has_wakeup_gesture:1; |
| 305 | unsigned char has_small_finger_correction:1; |
| 306 | unsigned char has_data_37:1; |
| 307 | unsigned char f11_query27_b7:1; |
| 308 | } __packed; |
| 309 | unsigned char data[1]; |
| 310 | }; |
| 311 | }; |
| 312 | |
| 313 | struct synaptics_rmi4_f11_ctrl_6_9 { |
| 314 | union { |
| 315 | struct { |
| 316 | unsigned char sensor_max_x_pos_7_0; |
| 317 | unsigned char sensor_max_x_pos_11_8:4; |
| 318 | unsigned char f11_ctrl7_b4__7:4; |
| 319 | unsigned char sensor_max_y_pos_7_0; |
| 320 | unsigned char sensor_max_y_pos_11_8:4; |
| 321 | unsigned char f11_ctrl9_b4__7:4; |
| 322 | } __packed; |
| 323 | unsigned char data[4]; |
| 324 | }; |
| 325 | }; |
| 326 | |
| 327 | struct synaptics_rmi4_f11_data_1_5 { |
| 328 | union { |
| 329 | struct { |
| 330 | unsigned char x_position_11_4; |
| 331 | unsigned char y_position_11_4; |
| 332 | unsigned char x_position_3_0:4; |
| 333 | unsigned char y_position_3_0:4; |
| 334 | unsigned char wx:4; |
| 335 | unsigned char wy:4; |
| 336 | unsigned char z; |
| 337 | } __packed; |
| 338 | unsigned char data[5]; |
| 339 | }; |
| 340 | }; |
| 341 | |
| 342 | struct synaptics_rmi4_f12_query_5 { |
| 343 | union { |
| 344 | struct { |
| 345 | unsigned char size_of_query6; |
| 346 | struct { |
| 347 | unsigned char ctrl0_is_present:1; |
| 348 | unsigned char ctrl1_is_present:1; |
| 349 | unsigned char ctrl2_is_present:1; |
| 350 | unsigned char ctrl3_is_present:1; |
| 351 | unsigned char ctrl4_is_present:1; |
| 352 | unsigned char ctrl5_is_present:1; |
| 353 | unsigned char ctrl6_is_present:1; |
| 354 | unsigned char ctrl7_is_present:1; |
| 355 | } __packed; |
| 356 | struct { |
| 357 | unsigned char ctrl8_is_present:1; |
| 358 | unsigned char ctrl9_is_present:1; |
| 359 | unsigned char ctrl10_is_present:1; |
| 360 | unsigned char ctrl11_is_present:1; |
| 361 | unsigned char ctrl12_is_present:1; |
| 362 | unsigned char ctrl13_is_present:1; |
| 363 | unsigned char ctrl14_is_present:1; |
| 364 | unsigned char ctrl15_is_present:1; |
| 365 | } __packed; |
| 366 | struct { |
| 367 | unsigned char ctrl16_is_present:1; |
| 368 | unsigned char ctrl17_is_present:1; |
| 369 | unsigned char ctrl18_is_present:1; |
| 370 | unsigned char ctrl19_is_present:1; |
| 371 | unsigned char ctrl20_is_present:1; |
| 372 | unsigned char ctrl21_is_present:1; |
| 373 | unsigned char ctrl22_is_present:1; |
| 374 | unsigned char ctrl23_is_present:1; |
| 375 | } __packed; |
| 376 | struct { |
| 377 | unsigned char ctrl24_is_present:1; |
| 378 | unsigned char ctrl25_is_present:1; |
| 379 | unsigned char ctrl26_is_present:1; |
| 380 | unsigned char ctrl27_is_present:1; |
| 381 | unsigned char ctrl28_is_present:1; |
| 382 | unsigned char ctrl29_is_present:1; |
| 383 | unsigned char ctrl30_is_present:1; |
| 384 | unsigned char ctrl31_is_present:1; |
| 385 | } __packed; |
| 386 | struct { |
| 387 | unsigned char ctrl32_is_present:1; |
| 388 | unsigned char ctrl33_is_present:1; |
| 389 | unsigned char ctrl34_is_present:1; |
| 390 | unsigned char ctrl35_is_present:1; |
| 391 | unsigned char ctrl36_is_present:1; |
| 392 | unsigned char ctrl37_is_present:1; |
| 393 | unsigned char ctrl38_is_present:1; |
| 394 | unsigned char ctrl39_is_present:1; |
| 395 | } __packed; |
| 396 | struct { |
| 397 | unsigned char ctrl40_is_present:1; |
| 398 | unsigned char ctrl41_is_present:1; |
| 399 | unsigned char ctrl42_is_present:1; |
| 400 | unsigned char ctrl43_is_present:1; |
| 401 | unsigned char ctrl44_is_present:1; |
| 402 | unsigned char ctrl45_is_present:1; |
| 403 | unsigned char ctrl46_is_present:1; |
| 404 | unsigned char ctrl47_is_present:1; |
| 405 | } __packed; |
| 406 | struct { |
| 407 | unsigned char ctrl48_is_present:1; |
| 408 | unsigned char ctrl49_is_present:1; |
| 409 | unsigned char ctrl50_is_present:1; |
| 410 | unsigned char ctrl51_is_present:1; |
| 411 | unsigned char ctrl52_is_present:1; |
| 412 | unsigned char ctrl53_is_present:1; |
| 413 | unsigned char ctrl54_is_present:1; |
| 414 | unsigned char ctrl55_is_present:1; |
| 415 | } __packed; |
| 416 | struct { |
| 417 | unsigned char ctrl56_is_present:1; |
| 418 | unsigned char ctrl57_is_present:1; |
| 419 | unsigned char ctrl58_is_present:1; |
| 420 | unsigned char ctrl59_is_present:1; |
| 421 | unsigned char ctrl60_is_present:1; |
| 422 | unsigned char ctrl61_is_present:1; |
| 423 | unsigned char ctrl62_is_present:1; |
| 424 | unsigned char ctrl63_is_present:1; |
| 425 | } __packed; |
| 426 | }; |
| 427 | unsigned char data[9]; |
| 428 | }; |
| 429 | }; |
| 430 | |
| 431 | struct synaptics_rmi4_f12_query_8 { |
| 432 | union { |
| 433 | struct { |
| 434 | unsigned char size_of_query9; |
| 435 | struct { |
| 436 | unsigned char data0_is_present:1; |
| 437 | unsigned char data1_is_present:1; |
| 438 | unsigned char data2_is_present:1; |
| 439 | unsigned char data3_is_present:1; |
| 440 | unsigned char data4_is_present:1; |
| 441 | unsigned char data5_is_present:1; |
| 442 | unsigned char data6_is_present:1; |
| 443 | unsigned char data7_is_present:1; |
| 444 | } __packed; |
| 445 | struct { |
| 446 | unsigned char data8_is_present:1; |
| 447 | unsigned char data9_is_present:1; |
| 448 | unsigned char data10_is_present:1; |
| 449 | unsigned char data11_is_present:1; |
| 450 | unsigned char data12_is_present:1; |
| 451 | unsigned char data13_is_present:1; |
| 452 | unsigned char data14_is_present:1; |
| 453 | unsigned char data15_is_present:1; |
| 454 | } __packed; |
| 455 | struct { |
| 456 | unsigned char data16_is_present:1; |
| 457 | unsigned char data17_is_present:1; |
| 458 | unsigned char data18_is_present:1; |
| 459 | unsigned char data19_is_present:1; |
| 460 | unsigned char data20_is_present:1; |
| 461 | unsigned char data21_is_present:1; |
| 462 | unsigned char data22_is_present:1; |
| 463 | unsigned char data23_is_present:1; |
| 464 | } __packed; |
| 465 | struct { |
| 466 | unsigned char data24_is_present:1; |
| 467 | unsigned char data25_is_present:1; |
| 468 | unsigned char data26_is_present:1; |
| 469 | unsigned char data27_is_present:1; |
| 470 | unsigned char data28_is_present:1; |
| 471 | unsigned char data29_is_present:1; |
| 472 | unsigned char data30_is_present:1; |
| 473 | unsigned char data31_is_present:1; |
| 474 | } __packed; |
| 475 | }; |
| 476 | unsigned char data[5]; |
| 477 | }; |
| 478 | }; |
| 479 | |
| 480 | struct synaptics_rmi4_f12_ctrl_8 { |
| 481 | union { |
| 482 | struct { |
| 483 | unsigned char max_x_coord_lsb; |
| 484 | unsigned char max_x_coord_msb; |
| 485 | unsigned char max_y_coord_lsb; |
| 486 | unsigned char max_y_coord_msb; |
| 487 | unsigned char rx_pitch_lsb; |
| 488 | unsigned char rx_pitch_msb; |
| 489 | unsigned char tx_pitch_lsb; |
| 490 | unsigned char tx_pitch_msb; |
| 491 | unsigned char low_rx_clip; |
| 492 | unsigned char high_rx_clip; |
| 493 | unsigned char low_tx_clip; |
| 494 | unsigned char high_tx_clip; |
| 495 | unsigned char num_of_rx; |
| 496 | unsigned char num_of_tx; |
| 497 | }; |
| 498 | unsigned char data[14]; |
| 499 | }; |
| 500 | }; |
| 501 | |
| 502 | struct synaptics_rmi4_f12_ctrl_23 { |
| 503 | union { |
| 504 | struct { |
| 505 | unsigned char finger_enable:1; |
| 506 | unsigned char active_stylus_enable:1; |
| 507 | unsigned char palm_enable:1; |
| 508 | unsigned char unclassified_object_enable:1; |
| 509 | unsigned char hovering_finger_enable:1; |
| 510 | unsigned char gloved_finger_enable:1; |
| 511 | unsigned char f12_ctr23_00_b6__7:2; |
| 512 | unsigned char max_reported_objects; |
| 513 | unsigned char f12_ctr23_02_b0:1; |
| 514 | unsigned char report_active_stylus_as_finger:1; |
| 515 | unsigned char report_palm_as_finger:1; |
| 516 | unsigned char report_unclassified_object_as_finger:1; |
| 517 | unsigned char report_hovering_finger_as_finger:1; |
| 518 | unsigned char report_gloved_finger_as_finger:1; |
| 519 | unsigned char report_narrow_object_swipe_as_finger:1; |
| 520 | unsigned char report_handedge_as_finger:1; |
| 521 | unsigned char cover_enable:1; |
| 522 | unsigned char stylus_enable:1; |
| 523 | unsigned char eraser_enable:1; |
| 524 | unsigned char small_object_enable:1; |
| 525 | unsigned char f12_ctr23_03_b4__7:4; |
| 526 | unsigned char report_cover_as_finger:1; |
| 527 | unsigned char report_stylus_as_finger:1; |
| 528 | unsigned char report_eraser_as_finger:1; |
| 529 | unsigned char report_small_object_as_finger:1; |
| 530 | unsigned char f12_ctr23_04_b4__7:4; |
| 531 | }; |
| 532 | unsigned char data[5]; |
| 533 | }; |
| 534 | }; |
| 535 | |
| 536 | struct synaptics_rmi4_f12_ctrl_31 { |
| 537 | union { |
| 538 | struct { |
| 539 | unsigned char max_x_coord_lsb; |
| 540 | unsigned char max_x_coord_msb; |
| 541 | unsigned char max_y_coord_lsb; |
| 542 | unsigned char max_y_coord_msb; |
| 543 | unsigned char rx_pitch_lsb; |
| 544 | unsigned char rx_pitch_msb; |
| 545 | unsigned char rx_clip_low; |
| 546 | unsigned char rx_clip_high; |
| 547 | unsigned char wedge_clip_low; |
| 548 | unsigned char wedge_clip_high; |
| 549 | unsigned char num_of_p; |
| 550 | unsigned char num_of_q; |
| 551 | }; |
| 552 | unsigned char data[12]; |
| 553 | }; |
| 554 | }; |
| 555 | |
| 556 | struct synaptics_rmi4_f12_ctrl_58 { |
| 557 | union { |
| 558 | struct { |
| 559 | unsigned char reporting_format; |
| 560 | unsigned char f12_ctr58_00_reserved; |
| 561 | unsigned char min_force_lsb; |
| 562 | unsigned char min_force_msb; |
| 563 | unsigned char max_force_lsb; |
| 564 | unsigned char max_force_msb; |
| 565 | unsigned char light_press_threshold_lsb; |
| 566 | unsigned char light_press_threshold_msb; |
| 567 | unsigned char light_press_hysteresis_lsb; |
| 568 | unsigned char light_press_hysteresis_msb; |
| 569 | unsigned char hard_press_threshold_lsb; |
| 570 | unsigned char hard_press_threshold_msb; |
| 571 | unsigned char hard_press_hysteresis_lsb; |
| 572 | unsigned char hard_press_hysteresis_msb; |
| 573 | }; |
| 574 | unsigned char data[14]; |
| 575 | }; |
| 576 | }; |
| 577 | |
| 578 | struct synaptics_rmi4_f12_finger_data { |
| 579 | unsigned char object_type_and_status; |
| 580 | unsigned char x_lsb; |
| 581 | unsigned char x_msb; |
| 582 | unsigned char y_lsb; |
| 583 | unsigned char y_msb; |
| 584 | #ifdef REPORT_2D_Z |
| 585 | unsigned char z; |
| 586 | #endif |
| 587 | #ifdef REPORT_2D_W |
| 588 | unsigned char wx; |
| 589 | unsigned char wy; |
| 590 | #endif |
| 591 | }; |
| 592 | |
| 593 | struct synaptics_rmi4_f1a_query { |
| 594 | union { |
| 595 | struct { |
| 596 | unsigned char max_button_count:3; |
| 597 | unsigned char f1a_query0_b3__4:2; |
| 598 | unsigned char has_query4:1; |
| 599 | unsigned char has_query3:1; |
| 600 | unsigned char has_query2:1; |
| 601 | unsigned char has_general_control:1; |
| 602 | unsigned char has_interrupt_enable:1; |
| 603 | unsigned char has_multibutton_select:1; |
| 604 | unsigned char has_tx_rx_map:1; |
| 605 | unsigned char has_perbutton_threshold:1; |
| 606 | unsigned char has_release_threshold:1; |
| 607 | unsigned char has_strongestbtn_hysteresis:1; |
| 608 | unsigned char has_filter_strength:1; |
| 609 | } __packed; |
| 610 | unsigned char data[2]; |
| 611 | }; |
| 612 | }; |
| 613 | |
| 614 | struct synaptics_rmi4_f1a_query_4 { |
| 615 | union { |
| 616 | struct { |
| 617 | unsigned char has_ctrl19:1; |
| 618 | unsigned char f1a_query4_b1__4:4; |
| 619 | unsigned char has_ctrl24:1; |
| 620 | unsigned char f1a_query4_b6__7:2; |
| 621 | } __packed; |
| 622 | unsigned char data[1]; |
| 623 | }; |
| 624 | }; |
| 625 | |
| 626 | struct synaptics_rmi4_f1a_control_0 { |
| 627 | union { |
| 628 | struct { |
| 629 | unsigned char multibutton_report:2; |
| 630 | unsigned char filter_mode:2; |
| 631 | unsigned char reserved:4; |
| 632 | } __packed; |
| 633 | unsigned char data[1]; |
| 634 | }; |
| 635 | }; |
| 636 | |
| 637 | struct synaptics_rmi4_f1a_control { |
| 638 | struct synaptics_rmi4_f1a_control_0 general_control; |
| 639 | unsigned char button_int_enable; |
| 640 | unsigned char multi_button; |
| 641 | unsigned char *txrx_map; |
| 642 | unsigned char *button_threshold; |
| 643 | unsigned char button_release_threshold; |
| 644 | unsigned char strongest_button_hysteresis; |
| 645 | unsigned char filter_strength; |
| 646 | }; |
| 647 | |
| 648 | struct synaptics_rmi4_f1a_handle { |
| 649 | int button_bitmask_size; |
| 650 | unsigned char max_count; |
| 651 | unsigned char valid_button_count; |
| 652 | unsigned char *button_data_buffer; |
| 653 | unsigned char *button_map; |
| 654 | struct synaptics_rmi4_f1a_query button_query; |
| 655 | struct synaptics_rmi4_f1a_control button_control; |
| 656 | }; |
| 657 | |
| 658 | struct synaptics_rmi4_exp_fhandler { |
| 659 | struct synaptics_rmi4_exp_fn *exp_fn; |
| 660 | bool insert; |
| 661 | bool remove; |
| 662 | struct list_head link; |
| 663 | }; |
| 664 | |
| 665 | struct synaptics_rmi4_exp_fn_data { |
| 666 | bool initialized; |
| 667 | bool queue_work; |
| 668 | struct mutex mutex; |
| 669 | struct list_head list; |
| 670 | struct delayed_work work; |
| 671 | struct workqueue_struct *workqueue; |
| 672 | struct synaptics_rmi4_data *rmi4_data; |
| 673 | }; |
| 674 | |
| 675 | static struct synaptics_rmi4_exp_fn_data exp_data; |
| 676 | |
| 677 | static struct synaptics_dsx_button_map *vir_button_map; |
| 678 | |
| 679 | #ifdef USE_DATA_SERVER |
| 680 | static pid_t synad_pid; |
| 681 | static struct task_struct *synad_task; |
| 682 | static struct siginfo interrupt_signal; |
| 683 | #endif |
| 684 | |
| 685 | static struct device_attribute attrs[] = { |
| 686 | __ATTR(reset, 0220, |
| 687 | synaptics_rmi4_show_error, |
| 688 | synaptics_rmi4_f01_reset_store), |
| 689 | __ATTR(productinfo, 0444, |
| 690 | synaptics_rmi4_f01_productinfo_show, |
| 691 | synaptics_rmi4_store_error), |
| 692 | __ATTR(buildid, 0444, |
| 693 | synaptics_rmi4_f01_buildid_show, |
| 694 | synaptics_rmi4_store_error), |
| 695 | __ATTR(flashprog, 0444, |
| 696 | synaptics_rmi4_f01_flashprog_show, |
| 697 | synaptics_rmi4_store_error), |
| 698 | __ATTR(0dbutton, 0664, |
| 699 | synaptics_rmi4_0dbutton_show, |
| 700 | synaptics_rmi4_0dbutton_store), |
| 701 | __ATTR(suspend, 0220, |
| 702 | synaptics_rmi4_show_error, |
| 703 | synaptics_rmi4_suspend_store), |
| 704 | __ATTR(wake_gesture, 0664, |
| 705 | synaptics_rmi4_wake_gesture_show, |
| 706 | synaptics_rmi4_wake_gesture_store), |
| 707 | #ifdef USE_DATA_SERVER |
| 708 | __ATTR(synad_pid, 0220, |
| 709 | synaptics_rmi4_show_error, |
| 710 | synaptics_rmi4_synad_pid_store), |
| 711 | #endif |
| 712 | }; |
| 713 | |
| 714 | static struct kobj_attribute virtual_key_map_attr = { |
| 715 | .attr = { |
| 716 | .name = VIRTUAL_KEY_MAP_FILE_NAME, |
| 717 | .mode = 0444, |
| 718 | }, |
| 719 | .show = synaptics_rmi4_virtual_key_map_show, |
| 720 | }; |
| 721 | |
| 722 | static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev, |
| 723 | struct device_attribute *attr, const char *buf, size_t count) |
| 724 | { |
| 725 | int retval; |
| 726 | unsigned int reset; |
| 727 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 728 | |
| 729 | if (kstrtouint(buf, 10, &reset) != 1) |
| 730 | return -EINVAL; |
| 731 | |
| 732 | if (reset != 1) |
| 733 | return -EINVAL; |
| 734 | |
| 735 | retval = synaptics_rmi4_reset_device(rmi4_data, false); |
| 736 | if (retval < 0) { |
| 737 | dev_err(rmi4_data->pdev->dev.parent, |
| 738 | "%s: Failed to issue reset command, error = %d\n", |
| 739 | __func__, retval); |
| 740 | return retval; |
| 741 | } |
| 742 | |
| 743 | return count; |
| 744 | } |
| 745 | |
| 746 | static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev, |
| 747 | struct device_attribute *attr, char *buf) |
| 748 | { |
| 749 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 750 | |
| 751 | return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n", |
| 752 | (rmi4_data->rmi4_mod_info.product_info[0]), |
| 753 | (rmi4_data->rmi4_mod_info.product_info[1])); |
| 754 | } |
| 755 | |
| 756 | static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev, |
| 757 | struct device_attribute *attr, char *buf) |
| 758 | { |
| 759 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 760 | |
| 761 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 762 | rmi4_data->firmware_id); |
| 763 | } |
| 764 | |
| 765 | static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev, |
| 766 | struct device_attribute *attr, char *buf) |
| 767 | { |
| 768 | int retval; |
| 769 | struct synaptics_rmi4_f01_device_status device_status; |
| 770 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 771 | |
| 772 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 773 | rmi4_data->f01_data_base_addr, |
| 774 | device_status.data, |
| 775 | sizeof(device_status.data)); |
| 776 | if (retval < 0) { |
| 777 | dev_err(rmi4_data->pdev->dev.parent, |
| 778 | "%s: Failed to read device status, error = %d\n", |
| 779 | __func__, retval); |
| 780 | return retval; |
| 781 | } |
| 782 | |
| 783 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 784 | device_status.flash_prog); |
| 785 | } |
| 786 | |
| 787 | static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev, |
| 788 | struct device_attribute *attr, char *buf) |
| 789 | { |
| 790 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 791 | |
| 792 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 793 | rmi4_data->button_0d_enabled); |
| 794 | } |
| 795 | |
| 796 | static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev, |
| 797 | struct device_attribute *attr, const char *buf, size_t count) |
| 798 | { |
| 799 | int retval; |
| 800 | unsigned int input; |
| 801 | unsigned char ii; |
| 802 | unsigned char intr_enable; |
| 803 | struct synaptics_rmi4_fn *fhandler; |
| 804 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 805 | struct synaptics_rmi4_device_info *rmi; |
| 806 | |
| 807 | rmi = &(rmi4_data->rmi4_mod_info); |
| 808 | |
| 809 | if (kstrtouint(buf, 10, &input) != 1) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | input = input > 0 ? 1 : 0; |
| 813 | |
| 814 | if (rmi4_data->button_0d_enabled == input) |
| 815 | return count; |
| 816 | |
| 817 | if (list_empty(&rmi->support_fn_list)) |
| 818 | return -ENODEV; |
| 819 | |
| 820 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 821 | if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) { |
| 822 | ii = fhandler->intr_reg_num; |
| 823 | |
| 824 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 825 | rmi4_data->f01_ctrl_base_addr + 1 + ii, |
| 826 | &intr_enable, |
| 827 | sizeof(intr_enable)); |
| 828 | if (retval < 0) |
| 829 | return retval; |
| 830 | |
| 831 | if (input == 1) |
| 832 | intr_enable |= fhandler->intr_mask; |
| 833 | else |
| 834 | intr_enable &= ~fhandler->intr_mask; |
| 835 | |
| 836 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 837 | rmi4_data->f01_ctrl_base_addr + 1 + ii, |
| 838 | &intr_enable, |
| 839 | sizeof(intr_enable)); |
| 840 | if (retval < 0) |
| 841 | return retval; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | rmi4_data->button_0d_enabled = input; |
| 846 | |
| 847 | return count; |
| 848 | } |
| 849 | |
| 850 | static ssize_t synaptics_rmi4_suspend_store(struct device *dev, |
| 851 | struct device_attribute *attr, const char *buf, size_t count) |
| 852 | { |
| 853 | unsigned int input; |
| 854 | |
| 855 | if (kstrtouint(buf, 10, &input) != 1) |
| 856 | return -EINVAL; |
| 857 | |
| 858 | if (input == 1) |
| 859 | synaptics_rmi4_suspend(dev); |
| 860 | else if (input == 0) |
| 861 | synaptics_rmi4_resume(dev); |
| 862 | else |
| 863 | return -EINVAL; |
| 864 | |
| 865 | return count; |
| 866 | } |
| 867 | |
| 868 | static ssize_t synaptics_rmi4_wake_gesture_show(struct device *dev, |
| 869 | struct device_attribute *attr, char *buf) |
| 870 | { |
| 871 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 872 | |
| 873 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 874 | rmi4_data->enable_wakeup_gesture); |
| 875 | } |
| 876 | |
| 877 | static ssize_t synaptics_rmi4_wake_gesture_store(struct device *dev, |
| 878 | struct device_attribute *attr, const char *buf, size_t count) |
| 879 | { |
| 880 | unsigned int input; |
| 881 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 882 | |
| 883 | if (kstrtouint(buf, 10, &input) != 1) |
| 884 | return -EINVAL; |
| 885 | |
| 886 | input = input > 0 ? 1 : 0; |
| 887 | |
| 888 | if (rmi4_data->f11_wakeup_gesture || rmi4_data->f12_wakeup_gesture) |
| 889 | rmi4_data->enable_wakeup_gesture = input; |
| 890 | |
| 891 | return count; |
| 892 | } |
| 893 | |
| 894 | #ifdef USE_DATA_SERVER |
| 895 | static ssize_t synaptics_rmi4_synad_pid_store(struct device *dev, |
| 896 | struct device_attribute *attr, const char *buf, size_t count) |
| 897 | { |
| 898 | unsigned int input; |
| 899 | |
| 900 | if (kstrtouint(buf, 10, &input) != 1) |
| 901 | return -EINVAL; |
| 902 | |
| 903 | synad_pid = input; |
| 904 | |
| 905 | if (synad_pid) { |
| 906 | synad_task = pid_task(find_vpid(synad_pid), PIDTYPE_PID); |
| 907 | if (!synad_task) |
| 908 | return -EINVAL; |
| 909 | } |
| 910 | |
| 911 | return count; |
| 912 | } |
| 913 | #endif |
| 914 | |
| 915 | static ssize_t synaptics_rmi4_virtual_key_map_show(struct kobject *kobj, |
| 916 | struct kobj_attribute *attr, char *buf) |
| 917 | { |
| 918 | int ii; |
| 919 | int cnt; |
| 920 | int count = 0; |
| 921 | |
| 922 | for (ii = 0; ii < vir_button_map->nbuttons; ii++) { |
| 923 | cnt = snprintf(buf, PAGE_SIZE - count, "0x01:%d:%d:%d:%d:%d\n", |
| 924 | vir_button_map->map[ii * 5 + 0], |
| 925 | vir_button_map->map[ii * 5 + 1], |
| 926 | vir_button_map->map[ii * 5 + 2], |
| 927 | vir_button_map->map[ii * 5 + 3], |
| 928 | vir_button_map->map[ii * 5 + 4]); |
| 929 | buf += cnt; |
| 930 | count += cnt; |
| 931 | } |
| 932 | |
| 933 | return count; |
| 934 | } |
| 935 | |
| 936 | static int synaptics_rmi4_f11_wg(struct synaptics_rmi4_data *rmi4_data, |
| 937 | bool enable) |
| 938 | { |
| 939 | int retval; |
| 940 | unsigned char reporting_control; |
| 941 | struct synaptics_rmi4_fn *fhandler; |
| 942 | struct synaptics_rmi4_device_info *rmi; |
| 943 | |
| 944 | rmi = &(rmi4_data->rmi4_mod_info); |
| 945 | |
| 946 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 947 | if (fhandler->fn_number == SYNAPTICS_RMI4_F11) |
| 948 | break; |
| 949 | } |
| 950 | |
| 951 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 952 | fhandler->full_addr.ctrl_base, |
| 953 | &reporting_control, |
| 954 | sizeof(reporting_control)); |
| 955 | if (retval < 0) { |
| 956 | dev_err(rmi4_data->pdev->dev.parent, |
| 957 | "%s: Failed to change reporting mode\n", |
| 958 | __func__); |
| 959 | return retval; |
| 960 | } |
| 961 | |
| 962 | reporting_control = (reporting_control & ~MASK_3BIT); |
| 963 | if (enable) |
| 964 | reporting_control |= F11_WAKEUP_GESTURE_MODE; |
| 965 | else |
| 966 | reporting_control |= F11_CONTINUOUS_MODE; |
| 967 | |
| 968 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 969 | fhandler->full_addr.ctrl_base, |
| 970 | &reporting_control, |
| 971 | sizeof(reporting_control)); |
| 972 | if (retval < 0) { |
| 973 | dev_err(rmi4_data->pdev->dev.parent, |
| 974 | "%s: Failed to change reporting mode\n", |
| 975 | __func__); |
| 976 | return retval; |
| 977 | } |
| 978 | |
| 979 | return retval; |
| 980 | } |
| 981 | |
| 982 | static int synaptics_rmi4_f12_wg(struct synaptics_rmi4_data *rmi4_data, |
| 983 | bool enable) |
| 984 | { |
| 985 | int retval; |
| 986 | unsigned char offset; |
| 987 | unsigned char reporting_control[3]; |
| 988 | struct synaptics_rmi4_f12_extra_data *extra_data; |
| 989 | struct synaptics_rmi4_fn *fhandler; |
| 990 | struct synaptics_rmi4_device_info *rmi; |
| 991 | |
| 992 | rmi = &(rmi4_data->rmi4_mod_info); |
| 993 | |
| 994 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 995 | if (fhandler->fn_number == SYNAPTICS_RMI4_F12) |
| 996 | break; |
| 997 | } |
| 998 | |
| 999 | extra_data = (struct synaptics_rmi4_f12_extra_data *)fhandler->extra; |
| 1000 | offset = extra_data->ctrl20_offset; |
| 1001 | |
| 1002 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1003 | fhandler->full_addr.ctrl_base + offset, |
| 1004 | reporting_control, |
| 1005 | sizeof(reporting_control)); |
| 1006 | if (retval < 0) { |
| 1007 | dev_err(rmi4_data->pdev->dev.parent, |
| 1008 | "%s: Failed to change reporting mode\n", |
| 1009 | __func__); |
| 1010 | return retval; |
| 1011 | } |
| 1012 | |
| 1013 | if (enable) |
| 1014 | reporting_control[rmi4_data->set_wakeup_gesture] = F12_WAKEUP_GESTURE_MODE; |
| 1015 | else |
| 1016 | reporting_control[rmi4_data->set_wakeup_gesture] = F12_CONTINUOUS_MODE; |
| 1017 | |
| 1018 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 1019 | fhandler->full_addr.ctrl_base + offset, |
| 1020 | reporting_control, |
| 1021 | sizeof(reporting_control)); |
| 1022 | if (retval < 0) { |
| 1023 | dev_err(rmi4_data->pdev->dev.parent, |
| 1024 | "%s: Failed to change reporting mode\n", |
| 1025 | __func__); |
| 1026 | return retval; |
| 1027 | } |
| 1028 | |
| 1029 | return retval; |
| 1030 | } |
| 1031 | |
| 1032 | static void synaptics_rmi4_wakeup_gesture(struct synaptics_rmi4_data *rmi4_data, |
| 1033 | bool enable) |
| 1034 | { |
| 1035 | if (rmi4_data->f11_wakeup_gesture) |
| 1036 | synaptics_rmi4_f11_wg(rmi4_data, enable); |
| 1037 | else if (rmi4_data->f12_wakeup_gesture) |
| 1038 | synaptics_rmi4_f12_wg(rmi4_data, enable); |
| 1039 | } |
| 1040 | |
| 1041 | static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data, |
| 1042 | struct synaptics_rmi4_fn *fhandler) |
| 1043 | { |
| 1044 | int retval; |
| 1045 | unsigned char touch_count = 0; /* number of touch points */ |
| 1046 | unsigned char reg_index; |
| 1047 | unsigned char finger; |
| 1048 | unsigned char fingers_supported; |
| 1049 | unsigned char num_of_finger_status_regs; |
| 1050 | unsigned char finger_shift; |
| 1051 | unsigned char finger_status; |
| 1052 | unsigned char finger_status_reg[3]; |
| 1053 | unsigned char detected_gestures; |
| 1054 | unsigned short data_addr; |
| 1055 | unsigned short data_offset; |
| 1056 | int x; |
| 1057 | int y; |
| 1058 | int wx; |
| 1059 | int wy; |
| 1060 | int temp; |
| 1061 | struct synaptics_rmi4_f11_data_1_5 data; |
| 1062 | struct synaptics_rmi4_f11_extra_data *extra_data; |
| 1063 | |
| 1064 | /* |
| 1065 | * The number of finger status registers is determined by the |
| 1066 | * maximum number of fingers supported - 2 bits per finger. So |
| 1067 | * the number of finger status registers to read is: |
| 1068 | * register_count = ceil(max_num_of_fingers / 4) |
| 1069 | */ |
| 1070 | fingers_supported = fhandler->num_of_data_points; |
| 1071 | num_of_finger_status_regs = (fingers_supported + 3) / 4; |
| 1072 | data_addr = fhandler->full_addr.data_base; |
| 1073 | |
| 1074 | extra_data = (struct synaptics_rmi4_f11_extra_data *)fhandler->extra; |
| 1075 | |
| 1076 | if (rmi4_data->suspend && rmi4_data->enable_wakeup_gesture) { |
| 1077 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1078 | data_addr + extra_data->data38_offset, |
| 1079 | &detected_gestures, |
| 1080 | sizeof(detected_gestures)); |
| 1081 | if (retval < 0) |
| 1082 | return 0; |
| 1083 | |
| 1084 | if (detected_gestures) { |
| 1085 | input_report_key(rmi4_data->input_dev, KEY_WAKEUP, 1); |
| 1086 | input_sync(rmi4_data->input_dev); |
| 1087 | input_report_key(rmi4_data->input_dev, KEY_WAKEUP, 0); |
| 1088 | input_sync(rmi4_data->input_dev); |
| 1089 | rmi4_data->suspend = false; |
| 1090 | } |
| 1091 | /* synaptics_rmi4_wakeup_gesture(rmi4_data, false); */ |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1096 | data_addr, |
| 1097 | finger_status_reg, |
| 1098 | num_of_finger_status_regs); |
| 1099 | if (retval < 0) |
| 1100 | return 0; |
| 1101 | |
| 1102 | mutex_lock(&(rmi4_data->rmi4_report_mutex)); |
| 1103 | |
| 1104 | for (finger = 0; finger < fingers_supported; finger++) { |
| 1105 | reg_index = finger / 4; |
| 1106 | finger_shift = (finger % 4) * 2; |
| 1107 | finger_status = (finger_status_reg[reg_index] >> finger_shift) |
| 1108 | & MASK_2BIT; |
| 1109 | |
| 1110 | /* |
| 1111 | * Each 2-bit finger status field represents the following: |
| 1112 | * 00 = finger not present |
| 1113 | * 01 = finger present and data accurate |
| 1114 | * 10 = finger present but data may be inaccurate |
| 1115 | * 11 = reserved |
| 1116 | */ |
| 1117 | #ifdef TYPE_B_PROTOCOL |
| 1118 | input_mt_slot(rmi4_data->input_dev, finger); |
| 1119 | input_mt_report_slot_state(rmi4_data->input_dev, |
| 1120 | MT_TOOL_FINGER, finger_status); |
| 1121 | #endif |
| 1122 | |
| 1123 | if (finger_status) { |
| 1124 | data_offset = data_addr + |
| 1125 | num_of_finger_status_regs + |
| 1126 | (finger * sizeof(data.data)); |
| 1127 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1128 | data_offset, |
| 1129 | data.data, |
| 1130 | sizeof(data.data)); |
| 1131 | if (retval < 0) { |
| 1132 | touch_count = 0; |
| 1133 | goto exit; |
| 1134 | } |
| 1135 | |
| 1136 | x = (data.x_position_11_4 << 4) | data.x_position_3_0; |
| 1137 | y = (data.y_position_11_4 << 4) | data.y_position_3_0; |
| 1138 | wx = data.wx; |
| 1139 | wy = data.wy; |
| 1140 | |
| 1141 | if (rmi4_data->hw_if->board_data->swap_axes) { |
| 1142 | temp = x; |
| 1143 | x = y; |
| 1144 | y = temp; |
| 1145 | temp = wx; |
| 1146 | wx = wy; |
| 1147 | wy = temp; |
| 1148 | } |
| 1149 | |
| 1150 | if (rmi4_data->hw_if->board_data->x_flip) |
| 1151 | x = rmi4_data->sensor_max_x - x; |
| 1152 | if (rmi4_data->hw_if->board_data->y_flip) |
| 1153 | y = rmi4_data->sensor_max_y - y; |
| 1154 | |
| 1155 | input_report_key(rmi4_data->input_dev, |
| 1156 | BTN_TOUCH, 1); |
| 1157 | input_report_key(rmi4_data->input_dev, |
| 1158 | BTN_TOOL_FINGER, 1); |
| 1159 | input_report_abs(rmi4_data->input_dev, |
| 1160 | ABS_MT_POSITION_X, x); |
| 1161 | input_report_abs(rmi4_data->input_dev, |
| 1162 | ABS_MT_POSITION_Y, y); |
| 1163 | #ifdef REPORT_2D_W |
| 1164 | input_report_abs(rmi4_data->input_dev, |
| 1165 | ABS_MT_TOUCH_MAJOR, max(wx, wy)); |
| 1166 | input_report_abs(rmi4_data->input_dev, |
| 1167 | ABS_MT_TOUCH_MINOR, min(wx, wy)); |
| 1168 | #endif |
| 1169 | #ifndef TYPE_B_PROTOCOL |
| 1170 | input_mt_sync(rmi4_data->input_dev); |
| 1171 | #endif |
| 1172 | |
| 1173 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1174 | "%s: Finger %d: status = 0x%02x, x = %d, y = %d, wx = %d, wy = %d\n", |
| 1175 | __func__, finger, |
| 1176 | finger_status, |
| 1177 | x, y, wx, wy); |
| 1178 | |
| 1179 | touch_count++; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | if (touch_count == 0) { |
| 1184 | input_report_key(rmi4_data->input_dev, |
| 1185 | BTN_TOUCH, 0); |
| 1186 | input_report_key(rmi4_data->input_dev, |
| 1187 | BTN_TOOL_FINGER, 0); |
| 1188 | #ifndef TYPE_B_PROTOCOL |
| 1189 | input_mt_sync(rmi4_data->input_dev); |
| 1190 | #endif |
| 1191 | } |
| 1192 | |
| 1193 | input_sync(rmi4_data->input_dev); |
| 1194 | |
| 1195 | exit: |
| 1196 | mutex_unlock(&(rmi4_data->rmi4_report_mutex)); |
| 1197 | |
| 1198 | return touch_count; |
| 1199 | } |
| 1200 | |
| 1201 | static int synaptics_rmi4_f12_abs_report(struct synaptics_rmi4_data *rmi4_data, |
| 1202 | struct synaptics_rmi4_fn *fhandler) |
| 1203 | { |
| 1204 | int retval; |
| 1205 | unsigned char touch_count = 0; /* number of touch points */ |
| 1206 | unsigned char index; |
| 1207 | unsigned char finger; |
| 1208 | unsigned char fingers_to_process; |
| 1209 | unsigned char finger_status; |
| 1210 | unsigned char size_of_2d_data; |
| 1211 | unsigned char gesture_type; |
| 1212 | unsigned short data_addr; |
| 1213 | int x; |
| 1214 | int y; |
| 1215 | int wx; |
| 1216 | int wy; |
| 1217 | int temp; |
| 1218 | #if defined(REPORT_2D_PRESSURE) || defined(F51_DISCRETE_FORCE) |
| 1219 | int pressure; |
| 1220 | #endif |
| 1221 | #ifdef REPORT_2D_PRESSURE |
| 1222 | unsigned char f_fingers; |
| 1223 | unsigned char f_lsb; |
| 1224 | unsigned char f_msb; |
| 1225 | unsigned char *f_data; |
| 1226 | #endif |
| 1227 | #ifdef F51_DISCRETE_FORCE |
| 1228 | unsigned char force_level; |
| 1229 | #endif |
| 1230 | struct synaptics_rmi4_f12_extra_data *extra_data; |
| 1231 | struct synaptics_rmi4_f12_finger_data *data; |
| 1232 | struct synaptics_rmi4_f12_finger_data *finger_data; |
| 1233 | static unsigned char finger_presence; |
| 1234 | static unsigned char stylus_presence; |
| 1235 | #ifdef F12_DATA_15_WORKAROUND |
| 1236 | static unsigned char objects_already_present; |
| 1237 | #endif |
| 1238 | |
| 1239 | fingers_to_process = fhandler->num_of_data_points; |
| 1240 | data_addr = fhandler->full_addr.data_base; |
| 1241 | extra_data = (struct synaptics_rmi4_f12_extra_data *)fhandler->extra; |
| 1242 | size_of_2d_data = sizeof(struct synaptics_rmi4_f12_finger_data); |
| 1243 | |
| 1244 | if (rmi4_data->suspend && rmi4_data->enable_wakeup_gesture) { |
| 1245 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1246 | data_addr + extra_data->data4_offset, |
| 1247 | rmi4_data->gesture_detection, |
| 1248 | sizeof(rmi4_data->gesture_detection)); |
| 1249 | if (retval < 0) |
| 1250 | return 0; |
| 1251 | |
| 1252 | gesture_type = rmi4_data->gesture_detection[0]; |
| 1253 | |
| 1254 | if (gesture_type && gesture_type != F12_UDG_DETECT) { |
| 1255 | input_report_key(rmi4_data->input_dev, KEY_WAKEUP, 1); |
| 1256 | input_sync(rmi4_data->input_dev); |
| 1257 | input_report_key(rmi4_data->input_dev, KEY_WAKEUP, 0); |
| 1258 | input_sync(rmi4_data->input_dev); |
| 1259 | /* synaptics_rmi4_wakeup_gesture(rmi4_data, false); */ |
| 1260 | /* rmi4_data->suspend = false; */ |
| 1261 | } |
| 1262 | |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
| 1266 | /* Determine the total number of fingers to process */ |
| 1267 | if (extra_data->data15_size) { |
| 1268 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1269 | data_addr + extra_data->data15_offset, |
| 1270 | extra_data->data15_data, |
| 1271 | extra_data->data15_size); |
| 1272 | if (retval < 0) |
| 1273 | return 0; |
| 1274 | |
| 1275 | /* Start checking from the highest bit */ |
| 1276 | index = extra_data->data15_size - 1; /* Highest byte */ |
| 1277 | finger = (fingers_to_process - 1) % 8; /* Highest bit */ |
| 1278 | do { |
| 1279 | if (extra_data->data15_data[index] & (1 << finger)) |
| 1280 | break; |
| 1281 | |
| 1282 | if (finger) { |
| 1283 | finger--; |
| 1284 | } else if (index > 0) { |
| 1285 | index--; /* Move to the next lower byte */ |
| 1286 | finger = 7; |
| 1287 | } |
| 1288 | |
| 1289 | fingers_to_process--; |
| 1290 | } while (fingers_to_process); |
| 1291 | |
| 1292 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1293 | "%s: Number of fingers to process = %d\n", |
| 1294 | __func__, fingers_to_process); |
| 1295 | } |
| 1296 | |
| 1297 | #ifdef F12_DATA_15_WORKAROUND |
| 1298 | fingers_to_process = max(fingers_to_process, objects_already_present); |
| 1299 | #endif |
| 1300 | |
| 1301 | if (!fingers_to_process) { |
| 1302 | synaptics_rmi4_free_fingers(rmi4_data); |
| 1303 | finger_presence = 0; |
| 1304 | stylus_presence = 0; |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1309 | data_addr + extra_data->data1_offset, |
| 1310 | (unsigned char *)fhandler->data, |
| 1311 | fingers_to_process * size_of_2d_data); |
| 1312 | if (retval < 0) |
| 1313 | return 0; |
| 1314 | |
| 1315 | data = (struct synaptics_rmi4_f12_finger_data *)fhandler->data; |
| 1316 | |
| 1317 | #ifdef REPORT_2D_PRESSURE |
| 1318 | if (rmi4_data->report_pressure) { |
| 1319 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1320 | data_addr + extra_data->data29_offset, |
| 1321 | extra_data->data29_data, |
| 1322 | extra_data->data29_size); |
| 1323 | if (retval < 0) |
| 1324 | return 0; |
| 1325 | } |
| 1326 | #endif |
| 1327 | |
| 1328 | mutex_lock(&(rmi4_data->rmi4_report_mutex)); |
| 1329 | |
| 1330 | for (finger = 0; finger < fingers_to_process; finger++) { |
| 1331 | finger_data = data + finger; |
| 1332 | finger_status = finger_data->object_type_and_status; |
| 1333 | |
| 1334 | #ifdef F12_DATA_15_WORKAROUND |
| 1335 | objects_already_present = finger + 1; |
| 1336 | #endif |
| 1337 | |
| 1338 | x = (finger_data->x_msb << 8) | (finger_data->x_lsb); |
| 1339 | y = (finger_data->y_msb << 8) | (finger_data->y_lsb); |
| 1340 | #ifdef REPORT_2D_W |
| 1341 | wx = finger_data->wx; |
| 1342 | wy = finger_data->wy; |
| 1343 | #endif |
| 1344 | |
| 1345 | if (rmi4_data->hw_if->board_data->swap_axes) { |
| 1346 | temp = x; |
| 1347 | x = y; |
| 1348 | y = temp; |
| 1349 | temp = wx; |
| 1350 | wx = wy; |
| 1351 | wy = temp; |
| 1352 | } |
| 1353 | |
| 1354 | if (rmi4_data->hw_if->board_data->x_flip) |
| 1355 | x = rmi4_data->sensor_max_x - x; |
| 1356 | if (rmi4_data->hw_if->board_data->y_flip) |
| 1357 | y = rmi4_data->sensor_max_y - y; |
| 1358 | |
| 1359 | switch (finger_status) { |
| 1360 | case F12_FINGER_STATUS: |
| 1361 | case F12_GLOVED_FINGER_STATUS: |
| 1362 | /* Stylus has priority over fingers */ |
| 1363 | if (stylus_presence) |
| 1364 | break; |
| 1365 | #ifdef TYPE_B_PROTOCOL |
| 1366 | input_mt_slot(rmi4_data->input_dev, finger); |
| 1367 | input_mt_report_slot_state(rmi4_data->input_dev, |
| 1368 | MT_TOOL_FINGER, 1); |
| 1369 | #endif |
| 1370 | |
| 1371 | input_report_key(rmi4_data->input_dev, |
| 1372 | BTN_TOUCH, 1); |
| 1373 | input_report_key(rmi4_data->input_dev, |
| 1374 | BTN_TOOL_FINGER, 1); |
| 1375 | input_report_abs(rmi4_data->input_dev, |
| 1376 | ABS_MT_POSITION_X, x); |
| 1377 | input_report_abs(rmi4_data->input_dev, |
| 1378 | ABS_MT_POSITION_Y, y); |
| 1379 | #ifdef REPORT_2D_W |
| 1380 | if (rmi4_data->wedge_sensor) { |
| 1381 | input_report_abs(rmi4_data->input_dev, |
| 1382 | ABS_MT_TOUCH_MAJOR, wx); |
| 1383 | input_report_abs(rmi4_data->input_dev, |
| 1384 | ABS_MT_TOUCH_MINOR, wx); |
| 1385 | } else { |
| 1386 | input_report_abs(rmi4_data->input_dev, |
| 1387 | ABS_MT_TOUCH_MAJOR, |
| 1388 | max(wx, wy)); |
| 1389 | input_report_abs(rmi4_data->input_dev, |
| 1390 | ABS_MT_TOUCH_MINOR, |
| 1391 | min(wx, wy)); |
| 1392 | } |
| 1393 | #endif |
| 1394 | #ifdef REPORT_2D_PRESSURE |
| 1395 | if (rmi4_data->report_pressure) { |
| 1396 | f_fingers = extra_data->data29_size / 2; |
| 1397 | f_data = extra_data->data29_data; |
| 1398 | if (finger + 1 > f_fingers) { |
| 1399 | pressure = 1; |
| 1400 | } else { |
| 1401 | f_lsb = finger * 2; |
| 1402 | f_msb = finger * 2 + 1; |
| 1403 | pressure = (int)f_data[f_lsb] << 0 | |
| 1404 | (int)f_data[f_msb] << 8; |
| 1405 | } |
| 1406 | pressure = pressure > 0 ? pressure : 1; |
| 1407 | if (pressure > rmi4_data->force_max) |
| 1408 | pressure = rmi4_data->force_max; |
| 1409 | input_report_abs(rmi4_data->input_dev, |
| 1410 | ABS_MT_PRESSURE, pressure); |
| 1411 | } |
| 1412 | #elif defined(F51_DISCRETE_FORCE) |
| 1413 | if (finger == 0) { |
| 1414 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1415 | FORCE_LEVEL_ADDR, |
| 1416 | &force_level, |
| 1417 | sizeof(force_level)); |
| 1418 | if (retval < 0) |
| 1419 | return 0; |
| 1420 | pressure = force_level > 0 ? force_level : 1; |
| 1421 | } else { |
| 1422 | pressure = 1; |
| 1423 | } |
| 1424 | input_report_abs(rmi4_data->input_dev, |
| 1425 | ABS_MT_PRESSURE, pressure); |
| 1426 | #endif |
| 1427 | #ifndef TYPE_B_PROTOCOL |
| 1428 | input_mt_sync(rmi4_data->input_dev); |
| 1429 | #endif |
| 1430 | |
| 1431 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1432 | "%s: Finger %d: status = 0x%02x, x = %d, y = %d, wx = %d, wy = %d\n", |
| 1433 | __func__, finger, |
| 1434 | finger_status, |
| 1435 | x, y, wx, wy); |
| 1436 | |
| 1437 | finger_presence = 1; |
| 1438 | touch_count++; |
| 1439 | break; |
| 1440 | case F12_PALM_STATUS: |
| 1441 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1442 | "%s: Finger %d: x = %d, y = %d, wx = %d, wy = %d\n", |
| 1443 | __func__, finger, |
| 1444 | x, y, wx, wy); |
| 1445 | break; |
| 1446 | case F12_STYLUS_STATUS: |
| 1447 | case F12_ERASER_STATUS: |
| 1448 | if (!rmi4_data->stylus_enable) |
| 1449 | break; |
| 1450 | /* Stylus has priority over fingers */ |
| 1451 | if (finger_presence) { |
| 1452 | mutex_unlock(&(rmi4_data->rmi4_report_mutex)); |
| 1453 | synaptics_rmi4_free_fingers(rmi4_data); |
| 1454 | mutex_lock(&(rmi4_data->rmi4_report_mutex)); |
| 1455 | finger_presence = 0; |
| 1456 | } |
| 1457 | if (stylus_presence) {/* Allow one stylus at a timee */ |
| 1458 | if (finger + 1 != stylus_presence) |
| 1459 | break; |
| 1460 | } |
| 1461 | input_report_key(rmi4_data->stylus_dev, |
| 1462 | BTN_TOUCH, 1); |
| 1463 | if (finger_status == F12_STYLUS_STATUS) { |
| 1464 | input_report_key(rmi4_data->stylus_dev, |
| 1465 | BTN_TOOL_PEN, 1); |
| 1466 | } else { |
| 1467 | input_report_key(rmi4_data->stylus_dev, |
| 1468 | BTN_TOOL_RUBBER, 1); |
| 1469 | } |
| 1470 | input_report_abs(rmi4_data->stylus_dev, |
| 1471 | ABS_X, x); |
| 1472 | input_report_abs(rmi4_data->stylus_dev, |
| 1473 | ABS_Y, y); |
| 1474 | input_sync(rmi4_data->stylus_dev); |
| 1475 | |
| 1476 | stylus_presence = finger + 1; |
| 1477 | touch_count++; |
| 1478 | break; |
| 1479 | default: |
| 1480 | #ifdef TYPE_B_PROTOCOL |
| 1481 | input_mt_slot(rmi4_data->input_dev, finger); |
| 1482 | input_mt_report_slot_state(rmi4_data->input_dev, |
| 1483 | MT_TOOL_FINGER, 0); |
| 1484 | #endif |
| 1485 | break; |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | if (touch_count == 0) { |
| 1490 | finger_presence = 0; |
| 1491 | #ifdef F12_DATA_15_WORKAROUND |
| 1492 | objects_already_present = 0; |
| 1493 | #endif |
| 1494 | input_report_key(rmi4_data->input_dev, |
| 1495 | BTN_TOUCH, 0); |
| 1496 | input_report_key(rmi4_data->input_dev, |
| 1497 | BTN_TOOL_FINGER, 0); |
| 1498 | #ifndef TYPE_B_PROTOCOL |
| 1499 | input_mt_sync(rmi4_data->input_dev); |
| 1500 | #endif |
| 1501 | |
| 1502 | if (rmi4_data->stylus_enable) { |
| 1503 | stylus_presence = 0; |
| 1504 | input_report_key(rmi4_data->stylus_dev, |
| 1505 | BTN_TOUCH, 0); |
| 1506 | input_report_key(rmi4_data->stylus_dev, |
| 1507 | BTN_TOOL_PEN, 0); |
| 1508 | if (rmi4_data->eraser_enable) { |
| 1509 | input_report_key(rmi4_data->stylus_dev, |
| 1510 | BTN_TOOL_RUBBER, 0); |
| 1511 | } |
| 1512 | input_sync(rmi4_data->stylus_dev); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | input_sync(rmi4_data->input_dev); |
| 1517 | |
| 1518 | mutex_unlock(&(rmi4_data->rmi4_report_mutex)); |
| 1519 | |
| 1520 | return touch_count; |
| 1521 | } |
| 1522 | |
| 1523 | static int synaptics_rmi4_f1a_report(struct synaptics_rmi4_data *rmi4_data, |
| 1524 | struct synaptics_rmi4_fn *fhandler) |
| 1525 | { |
| 1526 | int retval; |
| 1527 | unsigned char touch_count = 0; |
| 1528 | unsigned char button; |
| 1529 | unsigned char index; |
| 1530 | unsigned char shift; |
| 1531 | unsigned char status; |
| 1532 | unsigned char *data; |
| 1533 | unsigned short data_addr = fhandler->full_addr.data_base; |
| 1534 | struct synaptics_rmi4_f1a_handle *f1a = fhandler->data; |
| 1535 | static unsigned char do_once = 1; |
| 1536 | static bool current_status[MAX_NUMBER_OF_BUTTONS]; |
| 1537 | #ifdef NO_0D_WHILE_2D |
| 1538 | static bool before_2d_status[MAX_NUMBER_OF_BUTTONS]; |
| 1539 | static bool while_2d_status[MAX_NUMBER_OF_BUTTONS]; |
| 1540 | #endif |
| 1541 | |
| 1542 | if (do_once) { |
| 1543 | memset(current_status, 0, sizeof(current_status)); |
| 1544 | #ifdef NO_0D_WHILE_2D |
| 1545 | memset(before_2d_status, 0, sizeof(before_2d_status)); |
| 1546 | memset(while_2d_status, 0, sizeof(while_2d_status)); |
| 1547 | #endif |
| 1548 | do_once = 0; |
| 1549 | } |
| 1550 | |
| 1551 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1552 | data_addr, |
| 1553 | f1a->button_data_buffer, |
| 1554 | f1a->button_bitmask_size); |
| 1555 | if (retval < 0) { |
| 1556 | dev_err(rmi4_data->pdev->dev.parent, |
| 1557 | "%s: Failed to read button data registers\n", |
| 1558 | __func__); |
| 1559 | return retval; |
| 1560 | } |
| 1561 | |
| 1562 | data = f1a->button_data_buffer; |
| 1563 | |
| 1564 | mutex_lock(&(rmi4_data->rmi4_report_mutex)); |
| 1565 | |
| 1566 | for (button = 0; button < f1a->valid_button_count; button++) { |
| 1567 | index = button / 8; |
| 1568 | shift = button % 8; |
| 1569 | status = ((data[index] >> shift) & MASK_1BIT); |
| 1570 | |
| 1571 | if (current_status[button] == status) |
| 1572 | continue; |
| 1573 | else |
| 1574 | current_status[button] = status; |
| 1575 | |
| 1576 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1577 | "%s: Button %d (code %d) ->%d\n", |
| 1578 | __func__, button, |
| 1579 | f1a->button_map[button], |
| 1580 | status); |
| 1581 | #ifdef NO_0D_WHILE_2D |
| 1582 | if (rmi4_data->fingers_on_2d == false) { |
| 1583 | if (status == 1) { |
| 1584 | before_2d_status[button] = 1; |
| 1585 | } else { |
| 1586 | if (while_2d_status[button] == 1) { |
| 1587 | while_2d_status[button] = 0; |
| 1588 | continue; |
| 1589 | } else { |
| 1590 | before_2d_status[button] = 0; |
| 1591 | } |
| 1592 | } |
| 1593 | touch_count++; |
| 1594 | input_report_key(rmi4_data->input_dev, |
| 1595 | f1a->button_map[button], |
| 1596 | status); |
| 1597 | } else { |
| 1598 | if (before_2d_status[button] == 1) { |
| 1599 | before_2d_status[button] = 0; |
| 1600 | touch_count++; |
| 1601 | input_report_key(rmi4_data->input_dev, |
| 1602 | f1a->button_map[button], |
| 1603 | status); |
| 1604 | } else { |
| 1605 | if (status == 1) |
| 1606 | while_2d_status[button] = 1; |
| 1607 | else |
| 1608 | while_2d_status[button] = 0; |
| 1609 | } |
| 1610 | } |
| 1611 | #else |
| 1612 | touch_count++; |
| 1613 | input_report_key(rmi4_data->input_dev, |
| 1614 | f1a->button_map[button], |
| 1615 | status); |
| 1616 | #endif |
| 1617 | } |
| 1618 | |
| 1619 | if (touch_count) |
| 1620 | input_sync(rmi4_data->input_dev); |
| 1621 | |
| 1622 | mutex_unlock(&(rmi4_data->rmi4_report_mutex)); |
| 1623 | |
| 1624 | return retval; |
| 1625 | } |
| 1626 | |
| 1627 | static void synaptics_rmi4_report_touch(struct synaptics_rmi4_data *rmi4_data, |
| 1628 | struct synaptics_rmi4_fn *fhandler) |
| 1629 | { |
| 1630 | unsigned char touch_count_2d; |
| 1631 | |
| 1632 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1633 | "%s: Function %02x reporting\n", |
| 1634 | __func__, fhandler->fn_number); |
| 1635 | |
| 1636 | switch (fhandler->fn_number) { |
| 1637 | case SYNAPTICS_RMI4_F11: |
| 1638 | touch_count_2d = synaptics_rmi4_f11_abs_report(rmi4_data, |
| 1639 | fhandler); |
| 1640 | |
| 1641 | if (touch_count_2d) |
| 1642 | rmi4_data->fingers_on_2d = true; |
| 1643 | else |
| 1644 | rmi4_data->fingers_on_2d = false; |
| 1645 | break; |
| 1646 | case SYNAPTICS_RMI4_F12: |
| 1647 | touch_count_2d = synaptics_rmi4_f12_abs_report(rmi4_data, |
| 1648 | fhandler); |
| 1649 | |
| 1650 | if (touch_count_2d) |
| 1651 | rmi4_data->fingers_on_2d = true; |
| 1652 | else |
| 1653 | rmi4_data->fingers_on_2d = false; |
| 1654 | break; |
| 1655 | case SYNAPTICS_RMI4_F1A: |
| 1656 | synaptics_rmi4_f1a_report(rmi4_data, fhandler); |
| 1657 | break; |
| 1658 | #ifdef USE_DATA_SERVER |
| 1659 | case SYNAPTICS_RMI4_F21: |
| 1660 | if (synad_pid) |
| 1661 | send_sig_info(SIGIO, &interrupt_signal, synad_task); |
| 1662 | break; |
| 1663 | #endif |
| 1664 | default: |
| 1665 | break; |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *rmi4_data, |
| 1670 | bool report) |
| 1671 | { |
| 1672 | int retval; |
| 1673 | unsigned char data[MAX_INTR_REGISTERS + 1]; |
| 1674 | unsigned char *intr = &data[1]; |
| 1675 | bool was_in_bl_mode; |
| 1676 | struct synaptics_rmi4_f01_device_status status; |
| 1677 | struct synaptics_rmi4_fn *fhandler; |
| 1678 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 1679 | struct synaptics_rmi4_device_info *rmi; |
| 1680 | |
| 1681 | rmi = &(rmi4_data->rmi4_mod_info); |
| 1682 | |
| 1683 | /* |
| 1684 | * Get interrupt status information from F01 Data1 register to |
| 1685 | * determine the source(s) that are flagging the interrupt. |
| 1686 | */ |
| 1687 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1688 | rmi4_data->f01_data_base_addr, |
| 1689 | data, |
| 1690 | rmi4_data->num_of_intr_regs + 1); |
| 1691 | if (retval < 0) { |
| 1692 | dev_err(rmi4_data->pdev->dev.parent, |
| 1693 | "%s: Failed to read interrupt status\n", |
| 1694 | __func__); |
| 1695 | return retval; |
| 1696 | } |
| 1697 | |
| 1698 | status.data[0] = data[0]; |
| 1699 | if (status.status_code == STATUS_CRC_IN_PROGRESS) { |
| 1700 | retval = synaptics_rmi4_check_status(rmi4_data, |
| 1701 | &was_in_bl_mode); |
| 1702 | if (retval < 0) { |
| 1703 | dev_err(rmi4_data->pdev->dev.parent, |
| 1704 | "%s: Failed to check status\n", |
| 1705 | __func__); |
| 1706 | return retval; |
| 1707 | } |
| 1708 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1709 | rmi4_data->f01_data_base_addr, |
| 1710 | status.data, |
| 1711 | sizeof(status.data)); |
| 1712 | if (retval < 0) { |
| 1713 | dev_err(rmi4_data->pdev->dev.parent, |
| 1714 | "%s: Failed to read device status\n", |
| 1715 | __func__); |
| 1716 | return retval; |
| 1717 | } |
| 1718 | } |
| 1719 | if (status.unconfigured && !status.flash_prog) { |
| 1720 | pr_notice("%s: spontaneous reset detected\n", __func__); |
| 1721 | retval = synaptics_rmi4_reinit_device(rmi4_data); |
| 1722 | if (retval < 0) { |
| 1723 | dev_err(rmi4_data->pdev->dev.parent, |
| 1724 | "%s: Failed to reinit device\n", |
| 1725 | __func__); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | if (!report) |
| 1730 | return retval; |
| 1731 | |
| 1732 | /* |
| 1733 | * Traverse the function handler list and service the source(s) |
| 1734 | * of the interrupt accordingly. |
| 1735 | */ |
| 1736 | if (!list_empty(&rmi->support_fn_list)) { |
| 1737 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 1738 | if (fhandler->num_of_data_sources) { |
| 1739 | if (fhandler->intr_mask & |
| 1740 | intr[fhandler->intr_reg_num]) { |
| 1741 | synaptics_rmi4_report_touch(rmi4_data, |
| 1742 | fhandler); |
| 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | mutex_lock(&exp_data.mutex); |
| 1749 | if (!list_empty(&exp_data.list)) { |
| 1750 | list_for_each_entry(exp_fhandler, &exp_data.list, link) { |
| 1751 | if (!exp_fhandler->insert && |
| 1752 | !exp_fhandler->remove && |
| 1753 | (exp_fhandler->exp_fn->attn != NULL)) |
| 1754 | exp_fhandler->exp_fn->attn(rmi4_data, intr[0]); |
| 1755 | } |
| 1756 | } |
| 1757 | mutex_unlock(&exp_data.mutex); |
| 1758 | |
| 1759 | return retval; |
| 1760 | } |
| 1761 | |
| 1762 | static irqreturn_t synaptics_rmi4_irq(int irq, void *data) |
| 1763 | { |
| 1764 | struct synaptics_rmi4_data *rmi4_data = data; |
| 1765 | const struct synaptics_dsx_board_data *bdata = |
| 1766 | rmi4_data->hw_if->board_data; |
| 1767 | |
| 1768 | if (gpio_get_value(bdata->irq_gpio) != bdata->irq_on_state) |
| 1769 | goto exit; |
| 1770 | |
| 1771 | synaptics_rmi4_sensor_report(rmi4_data, true); |
| 1772 | |
| 1773 | exit: |
| 1774 | return IRQ_HANDLED; |
| 1775 | } |
| 1776 | |
| 1777 | static int synaptics_rmi4_int_enable(struct synaptics_rmi4_data *rmi4_data, |
| 1778 | bool enable) |
| 1779 | { |
| 1780 | int retval = 0; |
| 1781 | unsigned char ii; |
| 1782 | unsigned char zero = 0x00; |
| 1783 | unsigned char *intr_mask; |
| 1784 | unsigned short intr_addr; |
| 1785 | |
| 1786 | intr_mask = rmi4_data->intr_mask; |
| 1787 | |
| 1788 | for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) { |
| 1789 | if (intr_mask[ii] != 0x00) { |
| 1790 | intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii; |
| 1791 | if (enable) { |
| 1792 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 1793 | intr_addr, |
| 1794 | &(intr_mask[ii]), |
| 1795 | sizeof(intr_mask[ii])); |
| 1796 | if (retval < 0) |
| 1797 | return retval; |
| 1798 | } else { |
| 1799 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 1800 | intr_addr, |
| 1801 | &zero, |
| 1802 | sizeof(zero)); |
| 1803 | if (retval < 0) |
| 1804 | return retval; |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | return retval; |
| 1810 | } |
| 1811 | |
| 1812 | static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data, |
| 1813 | bool enable, bool attn_only) |
| 1814 | { |
| 1815 | int retval = 0; |
| 1816 | unsigned char data[MAX_INTR_REGISTERS]; |
| 1817 | const struct synaptics_dsx_board_data *bdata = |
| 1818 | rmi4_data->hw_if->board_data; |
| 1819 | |
| 1820 | mutex_lock(&(rmi4_data->rmi4_irq_enable_mutex)); |
| 1821 | |
| 1822 | if (attn_only) { |
| 1823 | retval = synaptics_rmi4_int_enable(rmi4_data, enable); |
| 1824 | goto exit; |
| 1825 | } |
| 1826 | |
| 1827 | if (enable) { |
| 1828 | if (rmi4_data->irq_enabled) { |
| 1829 | dev_err(rmi4_data->pdev->dev.parent, |
| 1830 | "%s: Interrupt already enabled\n", |
| 1831 | __func__); |
| 1832 | goto exit; |
| 1833 | } |
| 1834 | |
| 1835 | retval = synaptics_rmi4_int_enable(rmi4_data, false); |
| 1836 | if (retval < 0) |
| 1837 | goto exit; |
| 1838 | |
| 1839 | /* Clear interrupts */ |
| 1840 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1841 | rmi4_data->f01_data_base_addr + 1, |
| 1842 | data, |
| 1843 | rmi4_data->num_of_intr_regs); |
| 1844 | if (retval < 0) { |
| 1845 | dev_err(rmi4_data->pdev->dev.parent, |
| 1846 | "%s: Failed to read interrupt status\n", |
| 1847 | __func__); |
| 1848 | goto exit; |
| 1849 | } |
| 1850 | |
| 1851 | retval = request_threaded_irq(rmi4_data->irq, NULL, |
| 1852 | synaptics_rmi4_irq, bdata->irq_flags, |
| 1853 | PLATFORM_DRIVER_NAME, rmi4_data); |
| 1854 | if (retval < 0) { |
| 1855 | dev_err(rmi4_data->pdev->dev.parent, |
| 1856 | "%s: Failed to create irq thread\n", |
| 1857 | __func__); |
| 1858 | goto exit; |
| 1859 | } |
| 1860 | |
| 1861 | retval = synaptics_rmi4_int_enable(rmi4_data, true); |
| 1862 | if (retval < 0) |
| 1863 | goto exit; |
| 1864 | |
| 1865 | rmi4_data->irq_enabled = true; |
| 1866 | } else { |
| 1867 | if (rmi4_data->irq_enabled) { |
| 1868 | disable_irq(rmi4_data->irq); |
| 1869 | free_irq(rmi4_data->irq, rmi4_data); |
| 1870 | rmi4_data->irq_enabled = false; |
| 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | exit: |
| 1875 | mutex_unlock(&(rmi4_data->rmi4_irq_enable_mutex)); |
| 1876 | |
| 1877 | return retval; |
| 1878 | } |
| 1879 | |
| 1880 | static void synaptics_rmi4_set_intr_mask(struct synaptics_rmi4_fn *fhandler, |
| 1881 | struct synaptics_rmi4_fn_desc *fd, |
| 1882 | unsigned int intr_count) |
| 1883 | { |
| 1884 | unsigned char ii; |
| 1885 | unsigned char intr_offset; |
| 1886 | |
| 1887 | fhandler->intr_reg_num = (intr_count + 7) / 8; |
| 1888 | if (fhandler->intr_reg_num != 0) |
| 1889 | fhandler->intr_reg_num -= 1; |
| 1890 | |
| 1891 | /* Set an enable bit for each data source */ |
| 1892 | intr_offset = intr_count % 8; |
| 1893 | fhandler->intr_mask = 0; |
| 1894 | for (ii = intr_offset; |
| 1895 | ii < (fd->intr_src_count + intr_offset); |
| 1896 | ii++) |
| 1897 | fhandler->intr_mask |= 1 << ii; |
| 1898 | } |
| 1899 | |
| 1900 | static int synaptics_rmi4_f01_init(struct synaptics_rmi4_data *rmi4_data, |
| 1901 | struct synaptics_rmi4_fn *fhandler, |
| 1902 | struct synaptics_rmi4_fn_desc *fd, |
| 1903 | unsigned int intr_count) |
| 1904 | { |
| 1905 | fhandler->fn_number = fd->fn_number; |
| 1906 | fhandler->num_of_data_sources = fd->intr_src_count; |
| 1907 | fhandler->data = NULL; |
| 1908 | fhandler->extra = NULL; |
| 1909 | |
| 1910 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); |
| 1911 | |
| 1912 | rmi4_data->f01_query_base_addr = fd->query_base_addr; |
| 1913 | rmi4_data->f01_ctrl_base_addr = fd->ctrl_base_addr; |
| 1914 | rmi4_data->f01_data_base_addr = fd->data_base_addr; |
| 1915 | rmi4_data->f01_cmd_base_addr = fd->cmd_base_addr; |
| 1916 | |
| 1917 | return 0; |
| 1918 | } |
| 1919 | |
| 1920 | static int synaptics_rmi4_f11_init(struct synaptics_rmi4_data *rmi4_data, |
| 1921 | struct synaptics_rmi4_fn *fhandler, |
| 1922 | struct synaptics_rmi4_fn_desc *fd, |
| 1923 | unsigned int intr_count) |
| 1924 | { |
| 1925 | int retval; |
| 1926 | int temp; |
| 1927 | unsigned char offset; |
| 1928 | unsigned char fingers_supported; |
| 1929 | struct synaptics_rmi4_f11_extra_data *extra_data; |
| 1930 | struct synaptics_rmi4_f11_query_0_5 query_0_5; |
| 1931 | struct synaptics_rmi4_f11_query_7_8 query_7_8; |
| 1932 | struct synaptics_rmi4_f11_query_9 query_9; |
| 1933 | struct synaptics_rmi4_f11_query_12 query_12; |
| 1934 | struct synaptics_rmi4_f11_query_27 query_27; |
| 1935 | struct synaptics_rmi4_f11_ctrl_6_9 control_6_9; |
| 1936 | const struct synaptics_dsx_board_data *bdata = |
| 1937 | rmi4_data->hw_if->board_data; |
| 1938 | |
| 1939 | fhandler->fn_number = fd->fn_number; |
| 1940 | fhandler->num_of_data_sources = fd->intr_src_count; |
| 1941 | fhandler->extra = kmalloc(sizeof(*extra_data), GFP_KERNEL); |
| 1942 | if (!fhandler->extra) { |
| 1943 | dev_err(rmi4_data->pdev->dev.parent, |
| 1944 | "%s: Failed to alloc mem for fhandler->extra\n", |
| 1945 | __func__); |
| 1946 | return -ENOMEM; |
| 1947 | } |
| 1948 | extra_data = (struct synaptics_rmi4_f11_extra_data *)fhandler->extra; |
| 1949 | |
| 1950 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1951 | fhandler->full_addr.query_base, |
| 1952 | query_0_5.data, |
| 1953 | sizeof(query_0_5.data)); |
| 1954 | if (retval < 0) |
| 1955 | return retval; |
| 1956 | |
| 1957 | /* Maximum number of fingers supported */ |
| 1958 | if (query_0_5.num_of_fingers <= 4) |
| 1959 | fhandler->num_of_data_points = query_0_5.num_of_fingers + 1; |
| 1960 | else if (query_0_5.num_of_fingers == 5) |
| 1961 | fhandler->num_of_data_points = 10; |
| 1962 | |
| 1963 | rmi4_data->num_of_fingers = fhandler->num_of_data_points; |
| 1964 | |
| 1965 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 1966 | fhandler->full_addr.ctrl_base + 6, |
| 1967 | control_6_9.data, |
| 1968 | sizeof(control_6_9.data)); |
| 1969 | if (retval < 0) |
| 1970 | return retval; |
| 1971 | |
| 1972 | /* Maximum x and y */ |
| 1973 | rmi4_data->sensor_max_x = control_6_9.sensor_max_x_pos_7_0 | |
| 1974 | (control_6_9.sensor_max_x_pos_11_8 << 8); |
| 1975 | rmi4_data->sensor_max_y = control_6_9.sensor_max_y_pos_7_0 | |
| 1976 | (control_6_9.sensor_max_y_pos_11_8 << 8); |
| 1977 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 1978 | "%s: Function %02x max x = %d max y = %d\n", |
| 1979 | __func__, fhandler->fn_number, |
| 1980 | rmi4_data->sensor_max_x, |
| 1981 | rmi4_data->sensor_max_y); |
| 1982 | |
| 1983 | rmi4_data->max_touch_width = MAX_F11_TOUCH_WIDTH; |
| 1984 | |
| 1985 | if (bdata->swap_axes) { |
| 1986 | temp = rmi4_data->sensor_max_x; |
| 1987 | rmi4_data->sensor_max_x = rmi4_data->sensor_max_y; |
| 1988 | rmi4_data->sensor_max_y = temp; |
| 1989 | } |
| 1990 | |
| 1991 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); |
| 1992 | |
| 1993 | fhandler->data = NULL; |
| 1994 | |
| 1995 | offset = sizeof(query_0_5.data); |
| 1996 | |
| 1997 | /* query 6 */ |
| 1998 | if (query_0_5.has_rel) |
| 1999 | offset += 1; |
| 2000 | |
| 2001 | /* queries 7 8 */ |
| 2002 | if (query_0_5.has_gestures) { |
| 2003 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2004 | fhandler->full_addr.query_base + offset, |
| 2005 | query_7_8.data, |
| 2006 | sizeof(query_7_8.data)); |
| 2007 | if (retval < 0) |
| 2008 | return retval; |
| 2009 | |
| 2010 | offset += sizeof(query_7_8.data); |
| 2011 | } |
| 2012 | |
| 2013 | /* query 9 */ |
| 2014 | if (query_0_5.has_query_9) { |
| 2015 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2016 | fhandler->full_addr.query_base + offset, |
| 2017 | query_9.data, |
| 2018 | sizeof(query_9.data)); |
| 2019 | if (retval < 0) |
| 2020 | return retval; |
| 2021 | |
| 2022 | offset += sizeof(query_9.data); |
| 2023 | } |
| 2024 | |
| 2025 | /* query 10 */ |
| 2026 | if (query_0_5.has_gestures && query_7_8.has_touch_shapes) |
| 2027 | offset += 1; |
| 2028 | |
| 2029 | /* query 11 */ |
| 2030 | if (query_0_5.has_query_11) |
| 2031 | offset += 1; |
| 2032 | |
| 2033 | /* query 12 */ |
| 2034 | if (query_0_5.has_query_12) { |
| 2035 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2036 | fhandler->full_addr.query_base + offset, |
| 2037 | query_12.data, |
| 2038 | sizeof(query_12.data)); |
| 2039 | if (retval < 0) |
| 2040 | return retval; |
| 2041 | |
| 2042 | offset += sizeof(query_12.data); |
| 2043 | } |
| 2044 | |
| 2045 | /* query 13 */ |
| 2046 | if (query_0_5.has_jitter_filter) |
| 2047 | offset += 1; |
| 2048 | |
| 2049 | /* query 14 */ |
| 2050 | if (query_0_5.has_query_12 && query_12.has_general_information_2) |
| 2051 | offset += 1; |
| 2052 | |
| 2053 | /* queries 15 16 17 18 19 20 21 22 23 24 25 26*/ |
| 2054 | if (query_0_5.has_query_12 && query_12.has_physical_properties) |
| 2055 | offset += 12; |
| 2056 | |
| 2057 | /* query 27 */ |
| 2058 | if (query_0_5.has_query_27) { |
| 2059 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2060 | fhandler->full_addr.query_base + offset, |
| 2061 | query_27.data, |
| 2062 | sizeof(query_27.data)); |
| 2063 | if (retval < 0) |
| 2064 | return retval; |
| 2065 | |
| 2066 | rmi4_data->f11_wakeup_gesture = query_27.has_wakeup_gesture; |
| 2067 | } |
| 2068 | |
| 2069 | if (!rmi4_data->f11_wakeup_gesture) |
| 2070 | return retval; |
| 2071 | |
| 2072 | /* data 0 */ |
| 2073 | fingers_supported = fhandler->num_of_data_points; |
| 2074 | offset = (fingers_supported + 3) / 4; |
| 2075 | |
| 2076 | /* data 1 2 3 4 5 */ |
| 2077 | offset += 5 * fingers_supported; |
| 2078 | |
| 2079 | /* data 6 7 */ |
| 2080 | if (query_0_5.has_rel) |
| 2081 | offset += 2 * fingers_supported; |
| 2082 | |
| 2083 | /* data 8 */ |
| 2084 | if (query_0_5.has_gestures && query_7_8.data[0]) |
| 2085 | offset += 1; |
| 2086 | |
| 2087 | /* data 9 */ |
| 2088 | if (query_0_5.has_gestures && (query_7_8.data[0] || query_7_8.data[1])) |
| 2089 | offset += 1; |
| 2090 | |
| 2091 | /* data 10 */ |
| 2092 | if (query_0_5.has_gestures && |
| 2093 | (query_7_8.has_pinch || query_7_8.has_flick)) |
| 2094 | offset += 1; |
| 2095 | |
| 2096 | /* data 11 12 */ |
| 2097 | if (query_0_5.has_gestures && |
| 2098 | (query_7_8.has_flick || query_7_8.has_rotate)) |
| 2099 | offset += 2; |
| 2100 | |
| 2101 | /* data 13 */ |
| 2102 | if (query_0_5.has_gestures && query_7_8.has_touch_shapes) |
| 2103 | offset += (fingers_supported + 3) / 4; |
| 2104 | |
| 2105 | /* data 14 15 */ |
| 2106 | if (query_0_5.has_gestures && |
| 2107 | (query_7_8.has_scroll_zones || |
| 2108 | query_7_8.has_multi_finger_scroll || |
| 2109 | query_7_8.has_chiral_scroll)) |
| 2110 | offset += 2; |
| 2111 | |
| 2112 | /* data 16 17 */ |
| 2113 | if (query_0_5.has_gestures && |
| 2114 | (query_7_8.has_scroll_zones && |
| 2115 | query_7_8.individual_scroll_zones)) |
| 2116 | offset += 2; |
| 2117 | |
| 2118 | /* data 18 19 20 21 22 23 24 25 26 27 */ |
| 2119 | if (query_0_5.has_query_9 && query_9.has_contact_geometry) |
| 2120 | offset += 10 * fingers_supported; |
| 2121 | |
| 2122 | /* data 28 */ |
| 2123 | if (query_0_5.has_bending_correction || |
| 2124 | query_0_5.has_large_object_suppression) |
| 2125 | offset += 1; |
| 2126 | |
| 2127 | /* data 29 30 31 */ |
| 2128 | if (query_0_5.has_query_9 && query_9.has_pen_hover_discrimination) |
| 2129 | offset += 3; |
| 2130 | |
| 2131 | /* data 32 */ |
| 2132 | if (query_0_5.has_query_12 && |
| 2133 | query_12.has_small_object_detection_tuning) |
| 2134 | offset += 1; |
| 2135 | |
| 2136 | /* data 33 34 */ |
| 2137 | if (query_0_5.has_query_27 && query_27.f11_query27_b0) |
| 2138 | offset += 2; |
| 2139 | |
| 2140 | /* data 35 */ |
| 2141 | if (query_0_5.has_query_12 && query_12.has_8bit_w) |
| 2142 | offset += fingers_supported; |
| 2143 | |
| 2144 | /* data 36 */ |
| 2145 | if (query_0_5.has_bending_correction) |
| 2146 | offset += 1; |
| 2147 | |
| 2148 | /* data 37 */ |
| 2149 | if (query_0_5.has_query_27 && query_27.has_data_37) |
| 2150 | offset += 1; |
| 2151 | |
| 2152 | /* data 38 */ |
| 2153 | if (query_0_5.has_query_27 && query_27.has_wakeup_gesture) |
| 2154 | extra_data->data38_offset = offset; |
| 2155 | |
| 2156 | return retval; |
| 2157 | } |
| 2158 | |
| 2159 | static int synaptics_rmi4_f12_set_enables(struct synaptics_rmi4_data *rmi4_data, |
| 2160 | unsigned short ctrl28) |
| 2161 | { |
| 2162 | int retval; |
| 2163 | static unsigned short ctrl_28_address; |
| 2164 | |
| 2165 | if (ctrl28) |
| 2166 | ctrl_28_address = ctrl28; |
| 2167 | |
| 2168 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 2169 | ctrl_28_address, |
| 2170 | &rmi4_data->report_enable, |
| 2171 | sizeof(rmi4_data->report_enable)); |
| 2172 | if (retval < 0) |
| 2173 | return retval; |
| 2174 | |
| 2175 | return retval; |
| 2176 | } |
| 2177 | |
| 2178 | static int synaptics_rmi4_f12_find_sub(struct synaptics_rmi4_data *rmi4_data, |
| 2179 | struct synaptics_rmi4_fn *fhandler, |
| 2180 | unsigned char *presence, unsigned char presence_size, |
| 2181 | unsigned char structure_offset, unsigned char reg, |
| 2182 | unsigned char sub) |
| 2183 | { |
| 2184 | int retval; |
| 2185 | unsigned char cnt; |
| 2186 | unsigned char regnum; |
| 2187 | unsigned char bitnum; |
| 2188 | unsigned char p_index; |
| 2189 | unsigned char s_index; |
| 2190 | unsigned char offset; |
| 2191 | unsigned char max_reg; |
| 2192 | unsigned char *structure; |
| 2193 | |
| 2194 | max_reg = (presence_size - 1) * 8 - 1; |
| 2195 | |
| 2196 | if (reg > max_reg) { |
| 2197 | dev_err(rmi4_data->pdev->dev.parent, |
| 2198 | "%s: Register number (%d) over limit\n", |
| 2199 | __func__, reg); |
| 2200 | return -EINVAL; |
| 2201 | } |
| 2202 | |
| 2203 | p_index = reg / 8 + 1; |
| 2204 | bitnum = reg % 8; |
| 2205 | if ((presence[p_index] & (1 << bitnum)) == 0x00) { |
| 2206 | dev_err(rmi4_data->pdev->dev.parent, |
| 2207 | "%s: Register %d is not present\n", |
| 2208 | __func__, reg); |
| 2209 | return -EINVAL; |
| 2210 | } |
| 2211 | |
| 2212 | structure = kmalloc(presence[0], GFP_KERNEL); |
| 2213 | if (!structure) { |
| 2214 | dev_err(rmi4_data->pdev->dev.parent, |
| 2215 | "%s: Failed to alloc mem for structure register\n", |
| 2216 | __func__); |
| 2217 | return -ENOMEM; |
| 2218 | } |
| 2219 | |
| 2220 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2221 | fhandler->full_addr.query_base + structure_offset, |
| 2222 | structure, |
| 2223 | presence[0]); |
| 2224 | if (retval < 0) |
| 2225 | goto exit; |
| 2226 | |
| 2227 | s_index = 0; |
| 2228 | |
| 2229 | for (regnum = 0; regnum < reg; regnum++) { |
| 2230 | p_index = regnum / 8 + 1; |
| 2231 | bitnum = regnum % 8; |
| 2232 | if ((presence[p_index] & (1 << bitnum)) == 0x00) |
| 2233 | continue; |
| 2234 | |
| 2235 | if (structure[s_index] == 0x00) |
| 2236 | s_index += 3; |
| 2237 | else |
| 2238 | s_index++; |
| 2239 | |
| 2240 | while (structure[s_index] & ~MASK_7BIT) |
| 2241 | s_index++; |
| 2242 | |
| 2243 | s_index++; |
| 2244 | } |
| 2245 | |
| 2246 | cnt = 0; |
| 2247 | s_index++; |
| 2248 | offset = sub / 7; |
| 2249 | bitnum = sub % 7; |
| 2250 | |
| 2251 | do { |
| 2252 | if (cnt == offset) { |
| 2253 | if (structure[s_index + cnt] & (1 << bitnum)) |
| 2254 | retval = 1; |
| 2255 | else |
| 2256 | retval = 0; |
| 2257 | goto exit; |
| 2258 | } |
| 2259 | cnt++; |
| 2260 | } while (structure[s_index + cnt - 1] & ~MASK_7BIT); |
| 2261 | |
| 2262 | retval = 0; |
| 2263 | |
| 2264 | exit: |
| 2265 | kfree(structure); |
| 2266 | |
| 2267 | return retval; |
| 2268 | } |
| 2269 | |
| 2270 | static int synaptics_rmi4_f12_init(struct synaptics_rmi4_data *rmi4_data, |
| 2271 | struct synaptics_rmi4_fn *fhandler, |
| 2272 | struct synaptics_rmi4_fn_desc *fd, |
| 2273 | unsigned int intr_count) |
| 2274 | { |
| 2275 | int retval = 0; |
| 2276 | int temp; |
| 2277 | unsigned char subpacket; |
| 2278 | unsigned char ctrl_23_size; |
| 2279 | unsigned char size_of_2d_data; |
| 2280 | unsigned char size_of_query5; |
| 2281 | unsigned char size_of_query8; |
| 2282 | unsigned char ctrl_8_offset; |
| 2283 | unsigned char ctrl_20_offset; |
| 2284 | unsigned char ctrl_23_offset; |
| 2285 | unsigned char ctrl_28_offset; |
| 2286 | unsigned char ctrl_31_offset; |
| 2287 | unsigned char ctrl_58_offset; |
| 2288 | unsigned char num_of_fingers; |
| 2289 | struct synaptics_rmi4_f12_extra_data *extra_data; |
| 2290 | struct synaptics_rmi4_f12_query_5 *query_5 = NULL; |
| 2291 | struct synaptics_rmi4_f12_query_8 *query_8 = NULL; |
| 2292 | struct synaptics_rmi4_f12_ctrl_8 *ctrl_8 = NULL; |
| 2293 | struct synaptics_rmi4_f12_ctrl_23 *ctrl_23 = NULL; |
| 2294 | struct synaptics_rmi4_f12_ctrl_31 *ctrl_31 = NULL; |
| 2295 | struct synaptics_rmi4_f12_ctrl_58 *ctrl_58 = NULL; |
| 2296 | const struct synaptics_dsx_board_data *bdata = |
| 2297 | rmi4_data->hw_if->board_data; |
| 2298 | |
| 2299 | fhandler->fn_number = fd->fn_number; |
| 2300 | fhandler->num_of_data_sources = fd->intr_src_count; |
| 2301 | fhandler->extra = kmalloc(sizeof(*extra_data), GFP_KERNEL); |
| 2302 | if (!fhandler->extra) { |
| 2303 | dev_err(rmi4_data->pdev->dev.parent, |
| 2304 | "%s: Failed to alloc mem for fhandler->extra\n", |
| 2305 | __func__); |
| 2306 | return -ENOMEM; |
| 2307 | } |
| 2308 | extra_data = (struct synaptics_rmi4_f12_extra_data *)fhandler->extra; |
| 2309 | size_of_2d_data = sizeof(struct synaptics_rmi4_f12_finger_data); |
| 2310 | |
| 2311 | query_5 = kzalloc(sizeof(*query_5), GFP_KERNEL); |
| 2312 | if (!query_5) { |
| 2313 | dev_err(rmi4_data->pdev->dev.parent, |
| 2314 | "%s: Failed to alloc mem for query_5\n", |
| 2315 | __func__); |
| 2316 | retval = -ENOMEM; |
| 2317 | goto exit; |
| 2318 | } |
| 2319 | |
| 2320 | query_8 = kzalloc(sizeof(*query_8), GFP_KERNEL); |
| 2321 | if (!query_8) { |
| 2322 | dev_err(rmi4_data->pdev->dev.parent, |
| 2323 | "%s: Failed to alloc mem for query_8\n", |
| 2324 | __func__); |
| 2325 | retval = -ENOMEM; |
| 2326 | goto exit; |
| 2327 | } |
| 2328 | |
| 2329 | ctrl_8 = kzalloc(sizeof(*ctrl_8), GFP_KERNEL); |
| 2330 | if (!ctrl_8) { |
| 2331 | dev_err(rmi4_data->pdev->dev.parent, |
| 2332 | "%s: Failed to alloc mem for ctrl_8\n", |
| 2333 | __func__); |
| 2334 | retval = -ENOMEM; |
| 2335 | goto exit; |
| 2336 | } |
| 2337 | |
| 2338 | ctrl_23 = kzalloc(sizeof(*ctrl_23), GFP_KERNEL); |
| 2339 | if (!ctrl_23) { |
| 2340 | dev_err(rmi4_data->pdev->dev.parent, |
| 2341 | "%s: Failed to alloc mem for ctrl_23\n", |
| 2342 | __func__); |
| 2343 | retval = -ENOMEM; |
| 2344 | goto exit; |
| 2345 | } |
| 2346 | |
| 2347 | ctrl_31 = kzalloc(sizeof(*ctrl_31), GFP_KERNEL); |
| 2348 | if (!ctrl_31) { |
| 2349 | dev_err(rmi4_data->pdev->dev.parent, |
| 2350 | "%s: Failed to alloc mem for ctrl_31\n", |
| 2351 | __func__); |
| 2352 | retval = -ENOMEM; |
| 2353 | goto exit; |
| 2354 | } |
| 2355 | |
| 2356 | ctrl_58 = kzalloc(sizeof(*ctrl_58), GFP_KERNEL); |
| 2357 | if (!ctrl_58) { |
| 2358 | dev_err(rmi4_data->pdev->dev.parent, |
| 2359 | "%s: Failed to alloc mem for ctrl_58\n", |
| 2360 | __func__); |
| 2361 | retval = -ENOMEM; |
| 2362 | goto exit; |
| 2363 | } |
| 2364 | |
| 2365 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2366 | fhandler->full_addr.query_base + 4, |
| 2367 | &size_of_query5, |
| 2368 | sizeof(size_of_query5)); |
| 2369 | if (retval < 0) |
| 2370 | goto exit; |
| 2371 | |
| 2372 | if (size_of_query5 > sizeof(query_5->data)) |
| 2373 | size_of_query5 = sizeof(query_5->data); |
| 2374 | memset(query_5->data, 0x00, sizeof(query_5->data)); |
| 2375 | |
| 2376 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2377 | fhandler->full_addr.query_base + 5, |
| 2378 | query_5->data, |
| 2379 | size_of_query5); |
| 2380 | if (retval < 0) |
| 2381 | goto exit; |
| 2382 | |
| 2383 | ctrl_8_offset = query_5->ctrl0_is_present + |
| 2384 | query_5->ctrl1_is_present + |
| 2385 | query_5->ctrl2_is_present + |
| 2386 | query_5->ctrl3_is_present + |
| 2387 | query_5->ctrl4_is_present + |
| 2388 | query_5->ctrl5_is_present + |
| 2389 | query_5->ctrl6_is_present + |
| 2390 | query_5->ctrl7_is_present; |
| 2391 | |
| 2392 | ctrl_20_offset = ctrl_8_offset + |
| 2393 | query_5->ctrl8_is_present + |
| 2394 | query_5->ctrl9_is_present + |
| 2395 | query_5->ctrl10_is_present + |
| 2396 | query_5->ctrl11_is_present + |
| 2397 | query_5->ctrl12_is_present + |
| 2398 | query_5->ctrl13_is_present + |
| 2399 | query_5->ctrl14_is_present + |
| 2400 | query_5->ctrl15_is_present + |
| 2401 | query_5->ctrl16_is_present + |
| 2402 | query_5->ctrl17_is_present + |
| 2403 | query_5->ctrl18_is_present + |
| 2404 | query_5->ctrl19_is_present; |
| 2405 | |
| 2406 | ctrl_23_offset = ctrl_20_offset + |
| 2407 | query_5->ctrl20_is_present + |
| 2408 | query_5->ctrl21_is_present + |
| 2409 | query_5->ctrl22_is_present; |
| 2410 | |
| 2411 | ctrl_28_offset = ctrl_23_offset + |
| 2412 | query_5->ctrl23_is_present + |
| 2413 | query_5->ctrl24_is_present + |
| 2414 | query_5->ctrl25_is_present + |
| 2415 | query_5->ctrl26_is_present + |
| 2416 | query_5->ctrl27_is_present; |
| 2417 | |
| 2418 | ctrl_31_offset = ctrl_28_offset + |
| 2419 | query_5->ctrl28_is_present + |
| 2420 | query_5->ctrl29_is_present + |
| 2421 | query_5->ctrl30_is_present; |
| 2422 | |
| 2423 | ctrl_58_offset = ctrl_31_offset + |
| 2424 | query_5->ctrl31_is_present + |
| 2425 | query_5->ctrl32_is_present + |
| 2426 | query_5->ctrl33_is_present + |
| 2427 | query_5->ctrl34_is_present + |
| 2428 | query_5->ctrl35_is_present + |
| 2429 | query_5->ctrl36_is_present + |
| 2430 | query_5->ctrl37_is_present + |
| 2431 | query_5->ctrl38_is_present + |
| 2432 | query_5->ctrl39_is_present + |
| 2433 | query_5->ctrl40_is_present + |
| 2434 | query_5->ctrl41_is_present + |
| 2435 | query_5->ctrl42_is_present + |
| 2436 | query_5->ctrl43_is_present + |
| 2437 | query_5->ctrl44_is_present + |
| 2438 | query_5->ctrl45_is_present + |
| 2439 | query_5->ctrl46_is_present + |
| 2440 | query_5->ctrl47_is_present + |
| 2441 | query_5->ctrl48_is_present + |
| 2442 | query_5->ctrl49_is_present + |
| 2443 | query_5->ctrl50_is_present + |
| 2444 | query_5->ctrl51_is_present + |
| 2445 | query_5->ctrl52_is_present + |
| 2446 | query_5->ctrl53_is_present + |
| 2447 | query_5->ctrl54_is_present + |
| 2448 | query_5->ctrl55_is_present + |
| 2449 | query_5->ctrl56_is_present + |
| 2450 | query_5->ctrl57_is_present; |
| 2451 | |
| 2452 | ctrl_23_size = 2; |
| 2453 | for (subpacket = 2; subpacket <= 4; subpacket++) { |
| 2454 | retval = synaptics_rmi4_f12_find_sub(rmi4_data, |
| 2455 | fhandler, query_5->data, sizeof(query_5->data), |
| 2456 | 6, 23, subpacket); |
| 2457 | if (retval == 1) |
| 2458 | ctrl_23_size++; |
| 2459 | else if (retval < 0) |
| 2460 | goto exit; |
| 2461 | |
| 2462 | } |
| 2463 | |
| 2464 | retval = synaptics_rmi4_f12_find_sub(rmi4_data, |
| 2465 | fhandler, query_5->data, sizeof(query_5->data), |
| 2466 | 6, 20, 0); |
| 2467 | if (retval == 1) |
| 2468 | rmi4_data->set_wakeup_gesture = 2; |
| 2469 | else if (retval == 0) |
| 2470 | rmi4_data->set_wakeup_gesture = 0; |
| 2471 | else if (retval < 0) |
| 2472 | goto exit; |
| 2473 | |
| 2474 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2475 | fhandler->full_addr.ctrl_base + ctrl_23_offset, |
| 2476 | ctrl_23->data, |
| 2477 | ctrl_23_size); |
| 2478 | if (retval < 0) |
| 2479 | goto exit; |
| 2480 | |
| 2481 | /* Maximum number of fingers supported */ |
| 2482 | fhandler->num_of_data_points = min_t(unsigned char, |
| 2483 | ctrl_23->max_reported_objects, |
| 2484 | (unsigned char)F12_FINGERS_TO_SUPPORT); |
| 2485 | |
| 2486 | num_of_fingers = fhandler->num_of_data_points; |
| 2487 | rmi4_data->num_of_fingers = num_of_fingers; |
| 2488 | |
| 2489 | rmi4_data->stylus_enable = ctrl_23->stylus_enable; |
| 2490 | rmi4_data->eraser_enable = ctrl_23->eraser_enable; |
| 2491 | |
| 2492 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2493 | fhandler->full_addr.query_base + 7, |
| 2494 | &size_of_query8, |
| 2495 | sizeof(size_of_query8)); |
| 2496 | if (retval < 0) |
| 2497 | goto exit; |
| 2498 | |
| 2499 | if (size_of_query8 > sizeof(query_8->data)) |
| 2500 | size_of_query8 = sizeof(query_8->data); |
| 2501 | memset(query_8->data, 0x00, sizeof(query_8->data)); |
| 2502 | |
| 2503 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2504 | fhandler->full_addr.query_base + 8, |
| 2505 | query_8->data, |
| 2506 | size_of_query8); |
| 2507 | if (retval < 0) |
| 2508 | goto exit; |
| 2509 | |
| 2510 | /* Determine the presence of the Data0 register */ |
| 2511 | extra_data->data1_offset = query_8->data0_is_present; |
| 2512 | |
| 2513 | if ((size_of_query8 >= 3) && (query_8->data15_is_present)) { |
| 2514 | extra_data->data15_offset = query_8->data0_is_present + |
| 2515 | query_8->data1_is_present + |
| 2516 | query_8->data2_is_present + |
| 2517 | query_8->data3_is_present + |
| 2518 | query_8->data4_is_present + |
| 2519 | query_8->data5_is_present + |
| 2520 | query_8->data6_is_present + |
| 2521 | query_8->data7_is_present + |
| 2522 | query_8->data8_is_present + |
| 2523 | query_8->data9_is_present + |
| 2524 | query_8->data10_is_present + |
| 2525 | query_8->data11_is_present + |
| 2526 | query_8->data12_is_present + |
| 2527 | query_8->data13_is_present + |
| 2528 | query_8->data14_is_present; |
| 2529 | extra_data->data15_size = (num_of_fingers + 7) / 8; |
| 2530 | } else { |
| 2531 | extra_data->data15_size = 0; |
| 2532 | } |
| 2533 | |
| 2534 | #ifdef REPORT_2D_PRESSURE |
| 2535 | if ((size_of_query8 >= 5) && (query_8->data29_is_present)) { |
| 2536 | extra_data->data29_offset = query_8->data0_is_present + |
| 2537 | query_8->data1_is_present + |
| 2538 | query_8->data2_is_present + |
| 2539 | query_8->data3_is_present + |
| 2540 | query_8->data4_is_present + |
| 2541 | query_8->data5_is_present + |
| 2542 | query_8->data6_is_present + |
| 2543 | query_8->data7_is_present + |
| 2544 | query_8->data8_is_present + |
| 2545 | query_8->data9_is_present + |
| 2546 | query_8->data10_is_present + |
| 2547 | query_8->data11_is_present + |
| 2548 | query_8->data12_is_present + |
| 2549 | query_8->data13_is_present + |
| 2550 | query_8->data14_is_present + |
| 2551 | query_8->data15_is_present + |
| 2552 | query_8->data16_is_present + |
| 2553 | query_8->data17_is_present + |
| 2554 | query_8->data18_is_present + |
| 2555 | query_8->data19_is_present + |
| 2556 | query_8->data20_is_present + |
| 2557 | query_8->data21_is_present + |
| 2558 | query_8->data22_is_present + |
| 2559 | query_8->data23_is_present + |
| 2560 | query_8->data24_is_present + |
| 2561 | query_8->data25_is_present + |
| 2562 | query_8->data26_is_present + |
| 2563 | query_8->data27_is_present + |
| 2564 | query_8->data28_is_present; |
| 2565 | extra_data->data29_size = 0; |
| 2566 | for (subpacket = 0; subpacket <= num_of_fingers; subpacket++) { |
| 2567 | retval = synaptics_rmi4_f12_find_sub(rmi4_data, |
| 2568 | fhandler, query_8->data, |
| 2569 | sizeof(query_8->data), |
| 2570 | 9, 29, subpacket); |
| 2571 | if (retval == 1) |
| 2572 | extra_data->data29_size += 2; |
| 2573 | else if (retval < 0) |
| 2574 | goto exit; |
| 2575 | } |
| 2576 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2577 | fhandler->full_addr.ctrl_base + ctrl_58_offset, |
| 2578 | ctrl_58->data, |
| 2579 | sizeof(ctrl_58->data)); |
| 2580 | if (retval < 0) |
| 2581 | goto exit; |
| 2582 | rmi4_data->force_min = |
| 2583 | (int)(ctrl_58->min_force_lsb << 0) | |
| 2584 | (int)(ctrl_58->min_force_msb << 8); |
| 2585 | rmi4_data->force_max = |
| 2586 | (int)(ctrl_58->max_force_lsb << 0) | |
| 2587 | (int)(ctrl_58->max_force_msb << 8); |
| 2588 | rmi4_data->report_pressure = true; |
| 2589 | } else { |
| 2590 | extra_data->data29_size = 0; |
| 2591 | rmi4_data->report_pressure = false; |
| 2592 | } |
| 2593 | #endif |
| 2594 | |
| 2595 | rmi4_data->report_enable = RPT_DEFAULT; |
| 2596 | #ifdef REPORT_2D_Z |
| 2597 | rmi4_data->report_enable |= RPT_Z; |
| 2598 | #endif |
| 2599 | #ifdef REPORT_2D_W |
| 2600 | rmi4_data->report_enable |= (RPT_WX | RPT_WY); |
| 2601 | #endif |
| 2602 | |
| 2603 | retval = synaptics_rmi4_f12_set_enables(rmi4_data, |
| 2604 | fhandler->full_addr.ctrl_base + ctrl_28_offset); |
| 2605 | if (retval < 0) |
| 2606 | goto exit; |
| 2607 | |
| 2608 | if (query_5->ctrl8_is_present) { |
| 2609 | rmi4_data->wedge_sensor = false; |
| 2610 | |
| 2611 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2612 | fhandler->full_addr.ctrl_base + ctrl_8_offset, |
| 2613 | ctrl_8->data, |
| 2614 | sizeof(ctrl_8->data)); |
| 2615 | if (retval < 0) |
| 2616 | goto exit; |
| 2617 | |
| 2618 | /* Maximum x and y */ |
| 2619 | rmi4_data->sensor_max_x = |
| 2620 | ((unsigned int)ctrl_8->max_x_coord_lsb << 0) | |
| 2621 | ((unsigned int)ctrl_8->max_x_coord_msb << 8); |
| 2622 | rmi4_data->sensor_max_y = |
| 2623 | ((unsigned int)ctrl_8->max_y_coord_lsb << 0) | |
| 2624 | ((unsigned int)ctrl_8->max_y_coord_msb << 8); |
| 2625 | |
| 2626 | rmi4_data->max_touch_width = MAX_F12_TOUCH_WIDTH; |
| 2627 | } else { |
| 2628 | rmi4_data->wedge_sensor = true; |
| 2629 | |
| 2630 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2631 | fhandler->full_addr.ctrl_base + ctrl_31_offset, |
| 2632 | ctrl_31->data, |
| 2633 | sizeof(ctrl_31->data)); |
| 2634 | if (retval < 0) |
| 2635 | goto exit; |
| 2636 | |
| 2637 | /* Maximum x and y */ |
| 2638 | rmi4_data->sensor_max_x = |
| 2639 | ((unsigned int)ctrl_31->max_x_coord_lsb << 0) | |
| 2640 | ((unsigned int)ctrl_31->max_x_coord_msb << 8); |
| 2641 | rmi4_data->sensor_max_y = |
| 2642 | ((unsigned int)ctrl_31->max_y_coord_lsb << 0) | |
| 2643 | ((unsigned int)ctrl_31->max_y_coord_msb << 8); |
| 2644 | |
| 2645 | rmi4_data->max_touch_width = MAX_F12_TOUCH_WIDTH; |
| 2646 | } |
| 2647 | |
| 2648 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 2649 | "%s: Function %02x max x = %d max y = %d\n", |
| 2650 | __func__, fhandler->fn_number, |
| 2651 | rmi4_data->sensor_max_x, |
| 2652 | rmi4_data->sensor_max_y); |
| 2653 | |
| 2654 | if (bdata->swap_axes) { |
| 2655 | temp = rmi4_data->sensor_max_x; |
| 2656 | rmi4_data->sensor_max_x = rmi4_data->sensor_max_y; |
| 2657 | rmi4_data->sensor_max_y = temp; |
| 2658 | } |
| 2659 | |
| 2660 | rmi4_data->f12_wakeup_gesture = query_5->ctrl27_is_present; |
| 2661 | if (rmi4_data->f12_wakeup_gesture) { |
| 2662 | extra_data->ctrl20_offset = ctrl_20_offset; |
| 2663 | extra_data->data4_offset = query_8->data0_is_present + |
| 2664 | query_8->data1_is_present + |
| 2665 | query_8->data2_is_present + |
| 2666 | query_8->data3_is_present; |
| 2667 | } |
| 2668 | |
| 2669 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); |
| 2670 | |
| 2671 | /* Allocate memory for finger data storage space */ |
| 2672 | fhandler->data_size = num_of_fingers * size_of_2d_data; |
| 2673 | fhandler->data = kmalloc(fhandler->data_size, GFP_KERNEL); |
| 2674 | if (!fhandler->data) { |
| 2675 | dev_err(rmi4_data->pdev->dev.parent, |
| 2676 | "%s: Failed to alloc mem for fhandler->data\n", |
| 2677 | __func__); |
| 2678 | retval = -ENOMEM; |
| 2679 | goto exit; |
| 2680 | } |
| 2681 | |
| 2682 | exit: |
| 2683 | kfree(query_5); |
| 2684 | kfree(query_8); |
| 2685 | kfree(ctrl_8); |
| 2686 | kfree(ctrl_23); |
| 2687 | kfree(ctrl_31); |
| 2688 | kfree(ctrl_58); |
| 2689 | |
| 2690 | return retval; |
| 2691 | } |
| 2692 | |
| 2693 | static int synaptics_rmi4_f1a_alloc_mem(struct synaptics_rmi4_data *rmi4_data, |
| 2694 | struct synaptics_rmi4_fn *fhandler) |
| 2695 | { |
| 2696 | int retval; |
| 2697 | struct synaptics_rmi4_f1a_handle *f1a; |
| 2698 | |
| 2699 | f1a = kzalloc(sizeof(*f1a), GFP_KERNEL); |
| 2700 | if (!f1a) { |
| 2701 | dev_err(rmi4_data->pdev->dev.parent, |
| 2702 | "%s: Failed to alloc mem for function handle\n", |
| 2703 | __func__); |
| 2704 | return -ENOMEM; |
| 2705 | } |
| 2706 | |
| 2707 | fhandler->data = (void *)f1a; |
| 2708 | fhandler->extra = NULL; |
| 2709 | |
| 2710 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2711 | fhandler->full_addr.query_base, |
| 2712 | f1a->button_query.data, |
| 2713 | sizeof(f1a->button_query.data)); |
| 2714 | if (retval < 0) { |
| 2715 | dev_err(rmi4_data->pdev->dev.parent, |
| 2716 | "%s: Failed to read query registers\n", |
| 2717 | __func__); |
| 2718 | return retval; |
| 2719 | } |
| 2720 | |
| 2721 | f1a->max_count = f1a->button_query.max_button_count + 1; |
| 2722 | |
| 2723 | f1a->button_control.txrx_map = kzalloc(f1a->max_count * 2, GFP_KERNEL); |
| 2724 | if (!f1a->button_control.txrx_map) { |
| 2725 | dev_err(rmi4_data->pdev->dev.parent, |
| 2726 | "%s: Failed to alloc mem for tx rx mapping\n", |
| 2727 | __func__); |
| 2728 | return -ENOMEM; |
| 2729 | } |
| 2730 | |
| 2731 | f1a->button_bitmask_size = (f1a->max_count + 7) / 8; |
| 2732 | |
| 2733 | f1a->button_data_buffer = kcalloc(f1a->button_bitmask_size, |
| 2734 | sizeof(*(f1a->button_data_buffer)), GFP_KERNEL); |
| 2735 | if (!f1a->button_data_buffer) { |
| 2736 | dev_err(rmi4_data->pdev->dev.parent, |
| 2737 | "%s: Failed to alloc mem for data buffer\n", |
| 2738 | __func__); |
| 2739 | return -ENOMEM; |
| 2740 | } |
| 2741 | |
| 2742 | f1a->button_map = kcalloc(f1a->max_count, |
| 2743 | sizeof(*(f1a->button_map)), GFP_KERNEL); |
| 2744 | if (!f1a->button_map) { |
| 2745 | dev_err(rmi4_data->pdev->dev.parent, |
| 2746 | "%s: Failed to alloc mem for button map\n", |
| 2747 | __func__); |
| 2748 | return -ENOMEM; |
| 2749 | } |
| 2750 | |
| 2751 | return 0; |
| 2752 | } |
| 2753 | |
| 2754 | static int synaptics_rmi4_f1a_button_map(struct synaptics_rmi4_data *rmi4_data, |
| 2755 | struct synaptics_rmi4_fn *fhandler) |
| 2756 | { |
| 2757 | int retval; |
| 2758 | unsigned char ii; |
| 2759 | unsigned char offset = 0; |
| 2760 | struct synaptics_rmi4_f1a_query_4 query_4; |
| 2761 | struct synaptics_rmi4_f1a_handle *f1a = fhandler->data; |
| 2762 | const struct synaptics_dsx_board_data *bdata = |
| 2763 | rmi4_data->hw_if->board_data; |
| 2764 | |
| 2765 | rmi4_data->valid_button_count = f1a->valid_button_count; |
| 2766 | |
| 2767 | offset = f1a->button_query.has_general_control + |
| 2768 | f1a->button_query.has_interrupt_enable + |
| 2769 | f1a->button_query.has_multibutton_select; |
| 2770 | |
| 2771 | if (f1a->button_query.has_tx_rx_map) { |
| 2772 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2773 | fhandler->full_addr.ctrl_base + offset, |
| 2774 | f1a->button_control.txrx_map, |
| 2775 | f1a->max_count * 2); |
| 2776 | if (retval < 0) { |
| 2777 | dev_err(rmi4_data->pdev->dev.parent, |
| 2778 | "%s: Failed to read tx rx mapping\n", |
| 2779 | __func__); |
| 2780 | return retval; |
| 2781 | } |
| 2782 | |
| 2783 | rmi4_data->button_txrx_mapping = f1a->button_control.txrx_map; |
| 2784 | } |
| 2785 | |
| 2786 | if (f1a->button_query.has_query4) { |
| 2787 | offset = 2 + f1a->button_query.has_query2 + |
| 2788 | f1a->button_query.has_query3; |
| 2789 | |
| 2790 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2791 | fhandler->full_addr.query_base + offset, |
| 2792 | query_4.data, |
| 2793 | sizeof(query_4.data)); |
| 2794 | if (retval < 0) { |
| 2795 | dev_err(rmi4_data->pdev->dev.parent, |
| 2796 | "%s: Failed to read button features 4\n", |
| 2797 | __func__); |
| 2798 | return retval; |
| 2799 | } |
| 2800 | |
| 2801 | if (query_4.has_ctrl24) |
| 2802 | rmi4_data->external_afe_buttons = true; |
| 2803 | else |
| 2804 | rmi4_data->external_afe_buttons = false; |
| 2805 | } |
| 2806 | |
| 2807 | if (!bdata->cap_button_map) { |
| 2808 | dev_err(rmi4_data->pdev->dev.parent, |
| 2809 | "%s: cap_button_map is NULL in board file\n", |
| 2810 | __func__); |
| 2811 | return -ENODEV; |
| 2812 | } else if (!bdata->cap_button_map->map) { |
| 2813 | dev_err(rmi4_data->pdev->dev.parent, |
| 2814 | "%s: Button map is missing in board file\n", |
| 2815 | __func__); |
| 2816 | return -ENODEV; |
| 2817 | } else { |
| 2818 | if (bdata->cap_button_map->nbuttons != f1a->max_count) { |
| 2819 | f1a->valid_button_count = min(f1a->max_count, |
| 2820 | bdata->cap_button_map->nbuttons); |
| 2821 | } else { |
| 2822 | f1a->valid_button_count = f1a->max_count; |
| 2823 | } |
| 2824 | |
| 2825 | for (ii = 0; ii < f1a->valid_button_count; ii++) |
| 2826 | f1a->button_map[ii] = bdata->cap_button_map->map[ii]; |
| 2827 | |
| 2828 | rmi4_data->valid_button_count = f1a->valid_button_count; |
| 2829 | } |
| 2830 | |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
| 2834 | static void synaptics_rmi4_f1a_kfree(struct synaptics_rmi4_fn *fhandler) |
| 2835 | { |
| 2836 | struct synaptics_rmi4_f1a_handle *f1a = fhandler->data; |
| 2837 | |
| 2838 | if (f1a) { |
| 2839 | kfree(f1a->button_control.txrx_map); |
| 2840 | kfree(f1a->button_data_buffer); |
| 2841 | kfree(f1a->button_map); |
| 2842 | kfree(f1a); |
| 2843 | fhandler->data = NULL; |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | static int synaptics_rmi4_f1a_init(struct synaptics_rmi4_data *rmi4_data, |
| 2848 | struct synaptics_rmi4_fn *fhandler, |
| 2849 | struct synaptics_rmi4_fn_desc *fd, |
| 2850 | unsigned int intr_count) |
| 2851 | { |
| 2852 | int retval; |
| 2853 | |
| 2854 | fhandler->fn_number = fd->fn_number; |
| 2855 | fhandler->num_of_data_sources = fd->intr_src_count; |
| 2856 | |
| 2857 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); |
| 2858 | |
| 2859 | retval = synaptics_rmi4_f1a_alloc_mem(rmi4_data, fhandler); |
| 2860 | if (retval < 0) |
| 2861 | goto error_exit; |
| 2862 | |
| 2863 | retval = synaptics_rmi4_f1a_button_map(rmi4_data, fhandler); |
| 2864 | if (retval < 0) |
| 2865 | goto error_exit; |
| 2866 | |
| 2867 | rmi4_data->button_0d_enabled = 1; |
| 2868 | |
| 2869 | return 0; |
| 2870 | |
| 2871 | error_exit: |
| 2872 | synaptics_rmi4_f1a_kfree(fhandler); |
| 2873 | |
| 2874 | return retval; |
| 2875 | } |
| 2876 | |
| 2877 | static void synaptics_rmi4_empty_fn_list(struct synaptics_rmi4_data *rmi4_data) |
| 2878 | { |
| 2879 | struct synaptics_rmi4_fn *fhandler; |
| 2880 | struct synaptics_rmi4_fn *fhandler_temp; |
| 2881 | struct synaptics_rmi4_device_info *rmi; |
| 2882 | |
| 2883 | rmi = &(rmi4_data->rmi4_mod_info); |
| 2884 | |
| 2885 | if (!list_empty(&rmi->support_fn_list)) { |
| 2886 | list_for_each_entry_safe(fhandler, |
| 2887 | fhandler_temp, |
| 2888 | &rmi->support_fn_list, |
| 2889 | link) { |
| 2890 | if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) { |
| 2891 | synaptics_rmi4_f1a_kfree(fhandler); |
| 2892 | } else { |
| 2893 | kfree(fhandler->extra); |
| 2894 | kfree(fhandler->data); |
| 2895 | } |
| 2896 | list_del(&fhandler->link); |
| 2897 | kfree(fhandler); |
| 2898 | } |
| 2899 | } |
| 2900 | INIT_LIST_HEAD(&rmi->support_fn_list); |
| 2901 | } |
| 2902 | |
| 2903 | static int synaptics_rmi4_check_status(struct synaptics_rmi4_data *rmi4_data, |
| 2904 | bool *was_in_bl_mode) |
| 2905 | { |
| 2906 | int retval; |
| 2907 | int timeout = CHECK_STATUS_TIMEOUT_MS; |
| 2908 | struct synaptics_rmi4_f01_device_status status; |
| 2909 | |
| 2910 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2911 | rmi4_data->f01_data_base_addr, |
| 2912 | status.data, |
| 2913 | sizeof(status.data)); |
| 2914 | if (retval < 0) |
| 2915 | return retval; |
| 2916 | |
| 2917 | while (status.status_code == STATUS_CRC_IN_PROGRESS) { |
| 2918 | if (timeout > 0) |
| 2919 | msleep(20); |
| 2920 | else |
| 2921 | return -EINVAL; |
| 2922 | |
| 2923 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2924 | rmi4_data->f01_data_base_addr, |
| 2925 | status.data, |
| 2926 | sizeof(status.data)); |
| 2927 | if (retval < 0) |
| 2928 | return retval; |
| 2929 | |
| 2930 | timeout -= 20; |
| 2931 | } |
| 2932 | |
| 2933 | if (timeout != CHECK_STATUS_TIMEOUT_MS) |
| 2934 | *was_in_bl_mode = true; |
| 2935 | |
| 2936 | if (status.flash_prog == 1) { |
| 2937 | rmi4_data->flash_prog_mode = true; |
| 2938 | pr_notice("%s: In flash prog mode, status = 0x%02x\n", |
| 2939 | __func__, |
| 2940 | status.status_code); |
| 2941 | } else { |
| 2942 | rmi4_data->flash_prog_mode = false; |
| 2943 | } |
| 2944 | |
| 2945 | return 0; |
| 2946 | } |
| 2947 | |
| 2948 | static int synaptics_rmi4_set_configured(struct synaptics_rmi4_data *rmi4_data) |
| 2949 | { |
| 2950 | int retval; |
| 2951 | unsigned char device_ctrl; |
| 2952 | |
| 2953 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 2954 | rmi4_data->f01_ctrl_base_addr, |
| 2955 | &device_ctrl, |
| 2956 | sizeof(device_ctrl)); |
| 2957 | if (retval < 0) { |
| 2958 | dev_err(rmi4_data->pdev->dev.parent, |
| 2959 | "%s: Failed to set configured\n", |
| 2960 | __func__); |
| 2961 | return retval; |
| 2962 | } |
| 2963 | |
| 2964 | rmi4_data->no_sleep_setting = device_ctrl & NO_SLEEP_ON; |
| 2965 | device_ctrl |= CONFIGURED; |
| 2966 | |
| 2967 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 2968 | rmi4_data->f01_ctrl_base_addr, |
| 2969 | &device_ctrl, |
| 2970 | sizeof(device_ctrl)); |
| 2971 | if (retval < 0) { |
| 2972 | dev_err(rmi4_data->pdev->dev.parent, |
| 2973 | "%s: Failed to set configured\n", |
| 2974 | __func__); |
| 2975 | } |
| 2976 | |
| 2977 | return retval; |
| 2978 | } |
| 2979 | |
| 2980 | static int synaptics_rmi4_alloc_fh(struct synaptics_rmi4_fn **fhandler, |
| 2981 | struct synaptics_rmi4_fn_desc *rmi_fd, int page_number) |
| 2982 | { |
| 2983 | *fhandler = kzalloc(sizeof(**fhandler), GFP_KERNEL); |
| 2984 | if (!(*fhandler)) |
| 2985 | return -ENOMEM; |
| 2986 | |
| 2987 | (*fhandler)->full_addr.data_base = |
| 2988 | (rmi_fd->data_base_addr | |
| 2989 | (page_number << 8)); |
| 2990 | (*fhandler)->full_addr.ctrl_base = |
| 2991 | (rmi_fd->ctrl_base_addr | |
| 2992 | (page_number << 8)); |
| 2993 | (*fhandler)->full_addr.cmd_base = |
| 2994 | (rmi_fd->cmd_base_addr | |
| 2995 | (page_number << 8)); |
| 2996 | (*fhandler)->full_addr.query_base = |
| 2997 | (rmi_fd->query_base_addr | |
| 2998 | (page_number << 8)); |
| 2999 | |
| 3000 | return 0; |
| 3001 | } |
| 3002 | |
| 3003 | static int synaptics_rmi4_query_device(struct synaptics_rmi4_data *rmi4_data) |
| 3004 | { |
| 3005 | int retval; |
| 3006 | unsigned char page_number; |
| 3007 | unsigned char intr_count; |
| 3008 | unsigned char *f01_query; |
| 3009 | unsigned short pdt_entry_addr; |
| 3010 | bool f01found; |
| 3011 | bool f35found; |
| 3012 | bool was_in_bl_mode; |
| 3013 | struct synaptics_rmi4_fn_desc rmi_fd; |
| 3014 | struct synaptics_rmi4_fn *fhandler; |
| 3015 | struct synaptics_rmi4_device_info *rmi; |
| 3016 | |
| 3017 | rmi = &(rmi4_data->rmi4_mod_info); |
| 3018 | |
| 3019 | rescan_pdt: |
| 3020 | f01found = false; |
| 3021 | f35found = false; |
| 3022 | was_in_bl_mode = false; |
| 3023 | intr_count = 0; |
| 3024 | INIT_LIST_HEAD(&rmi->support_fn_list); |
| 3025 | |
| 3026 | /* Scan the page description tables of the pages to service */ |
| 3027 | for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) { |
| 3028 | for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END; |
| 3029 | pdt_entry_addr -= PDT_ENTRY_SIZE) { |
| 3030 | pdt_entry_addr |= (page_number << 8); |
| 3031 | |
| 3032 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 3033 | pdt_entry_addr, |
| 3034 | (unsigned char *)&rmi_fd, |
| 3035 | sizeof(rmi_fd)); |
| 3036 | if (retval < 0) |
| 3037 | return retval; |
| 3038 | |
| 3039 | pdt_entry_addr &= ~(MASK_8BIT << 8); |
| 3040 | |
| 3041 | fhandler = NULL; |
| 3042 | |
| 3043 | if (rmi_fd.fn_number == 0) { |
| 3044 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 3045 | "%s: Reached end of PDT\n", |
| 3046 | __func__); |
| 3047 | break; |
| 3048 | } |
| 3049 | |
| 3050 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 3051 | "%s: F%02x found (page %d)\n", |
| 3052 | __func__, rmi_fd.fn_number, |
| 3053 | page_number); |
| 3054 | |
| 3055 | switch (rmi_fd.fn_number) { |
| 3056 | case SYNAPTICS_RMI4_F01: |
| 3057 | if (rmi_fd.intr_src_count == 0) |
| 3058 | break; |
| 3059 | |
| 3060 | f01found = true; |
| 3061 | |
| 3062 | retval = synaptics_rmi4_alloc_fh(&fhandler, |
| 3063 | &rmi_fd, page_number); |
| 3064 | if (retval < 0) { |
| 3065 | dev_err(rmi4_data->pdev->dev.parent, |
| 3066 | "%s: Failed to alloc for F%d\n", |
| 3067 | __func__, |
| 3068 | rmi_fd.fn_number); |
| 3069 | return retval; |
| 3070 | } |
| 3071 | |
| 3072 | retval = synaptics_rmi4_f01_init(rmi4_data, |
| 3073 | fhandler, &rmi_fd, intr_count); |
| 3074 | if (retval < 0) |
| 3075 | return retval; |
| 3076 | |
| 3077 | retval = synaptics_rmi4_check_status(rmi4_data, |
| 3078 | &was_in_bl_mode); |
| 3079 | if (retval < 0) { |
| 3080 | dev_err(rmi4_data->pdev->dev.parent, |
| 3081 | "%s: Failed to check status\n", |
| 3082 | __func__); |
| 3083 | return retval; |
| 3084 | } |
| 3085 | |
| 3086 | if (was_in_bl_mode) { |
| 3087 | kfree(fhandler); |
| 3088 | fhandler = NULL; |
| 3089 | goto rescan_pdt; |
| 3090 | } |
| 3091 | |
| 3092 | if (rmi4_data->flash_prog_mode) |
| 3093 | goto flash_prog_mode; |
| 3094 | |
| 3095 | break; |
| 3096 | case SYNAPTICS_RMI4_F11: |
| 3097 | if (rmi_fd.intr_src_count == 0) |
| 3098 | break; |
| 3099 | |
| 3100 | retval = synaptics_rmi4_alloc_fh(&fhandler, |
| 3101 | &rmi_fd, page_number); |
| 3102 | if (retval < 0) { |
| 3103 | dev_err(rmi4_data->pdev->dev.parent, |
| 3104 | "%s: Failed to alloc for F%d\n", |
| 3105 | __func__, |
| 3106 | rmi_fd.fn_number); |
| 3107 | return retval; |
| 3108 | } |
| 3109 | |
| 3110 | retval = synaptics_rmi4_f11_init(rmi4_data, |
| 3111 | fhandler, &rmi_fd, intr_count); |
| 3112 | if (retval < 0) |
| 3113 | return retval; |
| 3114 | break; |
| 3115 | case SYNAPTICS_RMI4_F12: |
| 3116 | if (rmi_fd.intr_src_count == 0) |
| 3117 | break; |
| 3118 | |
| 3119 | retval = synaptics_rmi4_alloc_fh(&fhandler, |
| 3120 | &rmi_fd, page_number); |
| 3121 | if (retval < 0) { |
| 3122 | dev_err(rmi4_data->pdev->dev.parent, |
| 3123 | "%s: Failed to alloc for F%d\n", |
| 3124 | __func__, |
| 3125 | rmi_fd.fn_number); |
| 3126 | return retval; |
| 3127 | } |
| 3128 | |
| 3129 | retval = synaptics_rmi4_f12_init(rmi4_data, |
| 3130 | fhandler, &rmi_fd, intr_count); |
| 3131 | if (retval < 0) |
| 3132 | return retval; |
| 3133 | break; |
| 3134 | case SYNAPTICS_RMI4_F1A: |
| 3135 | if (rmi_fd.intr_src_count == 0) |
| 3136 | break; |
| 3137 | |
| 3138 | retval = synaptics_rmi4_alloc_fh(&fhandler, |
| 3139 | &rmi_fd, page_number); |
| 3140 | if (retval < 0) { |
| 3141 | dev_err(rmi4_data->pdev->dev.parent, |
| 3142 | "%s: Failed to alloc for F%d\n", |
| 3143 | __func__, |
| 3144 | rmi_fd.fn_number); |
| 3145 | return retval; |
| 3146 | } |
| 3147 | |
| 3148 | retval = synaptics_rmi4_f1a_init(rmi4_data, |
| 3149 | fhandler, &rmi_fd, intr_count); |
| 3150 | if (retval < 0) { |
| 3151 | #ifdef IGNORE_FN_INIT_FAILURE |
| 3152 | kfree(fhandler); |
| 3153 | fhandler = NULL; |
| 3154 | #else |
| 3155 | return retval; |
| 3156 | #endif |
| 3157 | } |
| 3158 | break; |
| 3159 | #ifdef USE_DATA_SERVER |
| 3160 | case SYNAPTICS_RMI4_F21: |
| 3161 | if (rmi_fd.intr_src_count == 0) |
| 3162 | break; |
| 3163 | |
| 3164 | retval = synaptics_rmi4_alloc_fh(&fhandler, |
| 3165 | &rmi_fd, page_number); |
| 3166 | if (retval < 0) { |
| 3167 | dev_err(rmi4_data->pdev->dev.parent, |
| 3168 | "%s: Failed to alloc for F%d\n", |
| 3169 | __func__, |
| 3170 | rmi_fd.fn_number); |
| 3171 | return retval; |
| 3172 | } |
| 3173 | |
| 3174 | fhandler->fn_number = rmi_fd.fn_number; |
| 3175 | fhandler->num_of_data_sources = |
| 3176 | rmi_fd.intr_src_count; |
| 3177 | |
| 3178 | synaptics_rmi4_set_intr_mask(fhandler, &rmi_fd, |
| 3179 | intr_count); |
| 3180 | break; |
| 3181 | #endif |
| 3182 | case SYNAPTICS_RMI4_F35: |
| 3183 | f35found = true; |
| 3184 | break; |
| 3185 | #ifdef F51_DISCRETE_FORCE |
| 3186 | case SYNAPTICS_RMI4_F51: |
| 3187 | rmi4_data->f51_query_base_addr = |
| 3188 | rmi_fd.query_base_addr | |
| 3189 | (page_number << 8); |
| 3190 | break; |
| 3191 | #endif |
| 3192 | } |
| 3193 | |
| 3194 | /* Accumulate the interrupt count */ |
| 3195 | intr_count += rmi_fd.intr_src_count; |
| 3196 | |
| 3197 | if (fhandler && rmi_fd.intr_src_count) { |
| 3198 | list_add_tail(&fhandler->link, |
| 3199 | &rmi->support_fn_list); |
| 3200 | } |
| 3201 | } |
| 3202 | } |
| 3203 | |
| 3204 | if (!f01found) { |
| 3205 | dev_err(rmi4_data->pdev->dev.parent, |
| 3206 | "%s: Failed to find F01\n", |
| 3207 | __func__); |
| 3208 | if (!f35found) { |
| 3209 | dev_err(rmi4_data->pdev->dev.parent, |
| 3210 | "%s: Failed to find F35\n", |
| 3211 | __func__); |
| 3212 | return -EINVAL; |
| 3213 | } else { |
| 3214 | pr_notice("%s: In microbootloader mode\n", |
| 3215 | __func__); |
| 3216 | return 0; |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | flash_prog_mode: |
| 3221 | rmi4_data->num_of_intr_regs = (intr_count + 7) / 8; |
| 3222 | dev_dbg(rmi4_data->pdev->dev.parent, |
| 3223 | "%s: Number of interrupt registers = %d\n", |
| 3224 | __func__, rmi4_data->num_of_intr_regs); |
| 3225 | |
| 3226 | f01_query = kmalloc(F01_STD_QUERY_LEN, GFP_KERNEL); |
| 3227 | if (!f01_query) { |
| 3228 | dev_err(rmi4_data->pdev->dev.parent, |
| 3229 | "%s: Failed to alloc mem for f01_query\n", |
| 3230 | __func__); |
| 3231 | return -ENOMEM; |
| 3232 | } |
| 3233 | |
| 3234 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 3235 | rmi4_data->f01_query_base_addr, |
| 3236 | f01_query, |
| 3237 | F01_STD_QUERY_LEN); |
| 3238 | if (retval < 0) { |
| 3239 | kfree(f01_query); |
| 3240 | return retval; |
| 3241 | } |
| 3242 | |
| 3243 | /* RMI Version 4.0 currently supported */ |
| 3244 | rmi->version_major = 4; |
| 3245 | rmi->version_minor = 0; |
| 3246 | |
| 3247 | rmi->manufacturer_id = f01_query[0]; |
| 3248 | rmi->product_props = f01_query[1]; |
| 3249 | rmi->product_info[0] = f01_query[2]; |
| 3250 | rmi->product_info[1] = f01_query[3]; |
| 3251 | retval = secure_memcpy(rmi->product_id_string, |
| 3252 | sizeof(rmi->product_id_string), |
| 3253 | &f01_query[11], |
| 3254 | F01_STD_QUERY_LEN - 11, |
| 3255 | PRODUCT_ID_SIZE); |
| 3256 | if (retval < 0) { |
| 3257 | dev_err(rmi4_data->pdev->dev.parent, |
| 3258 | "%s: Failed to copy product ID string\n", |
| 3259 | __func__); |
| 3260 | } |
| 3261 | |
| 3262 | kfree(f01_query); |
| 3263 | |
| 3264 | if (rmi->manufacturer_id != 1) { |
| 3265 | dev_err(rmi4_data->pdev->dev.parent, |
| 3266 | "%s: Non-Synaptics device found, manufacturer ID = %d\n", |
| 3267 | __func__, rmi->manufacturer_id); |
| 3268 | } |
| 3269 | |
| 3270 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 3271 | rmi4_data->f01_query_base_addr + F01_BUID_ID_OFFSET, |
| 3272 | rmi->build_id, |
| 3273 | sizeof(rmi->build_id)); |
| 3274 | if (retval < 0) |
| 3275 | return retval; |
| 3276 | |
| 3277 | rmi4_data->firmware_id = (unsigned int)rmi->build_id[0] + |
| 3278 | (unsigned int)rmi->build_id[1] * 0x100 + |
| 3279 | (unsigned int)rmi->build_id[2] * 0x10000; |
| 3280 | |
| 3281 | memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask)); |
| 3282 | |
| 3283 | /* |
| 3284 | * Map out the interrupt bit masks for the interrupt sources |
| 3285 | * from the registered function handlers. |
| 3286 | */ |
| 3287 | if (!list_empty(&rmi->support_fn_list)) { |
| 3288 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 3289 | if (fhandler->num_of_data_sources) { |
| 3290 | rmi4_data->intr_mask[fhandler->intr_reg_num] |= |
| 3291 | fhandler->intr_mask; |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | |
| 3296 | if (rmi4_data->f11_wakeup_gesture || rmi4_data->f12_wakeup_gesture) |
| 3297 | rmi4_data->enable_wakeup_gesture = WAKEUP_GESTURE; |
| 3298 | else |
| 3299 | rmi4_data->enable_wakeup_gesture = false; |
| 3300 | |
| 3301 | synaptics_rmi4_set_configured(rmi4_data); |
| 3302 | |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
| 3306 | static int synaptics_rmi4_gpio_setup(int gpio, bool config, int dir, int state) |
| 3307 | { |
| 3308 | int retval = 0; |
| 3309 | unsigned char buf[16]; |
| 3310 | |
| 3311 | if (config) { |
| 3312 | snprintf(buf, PAGE_SIZE, "dsx_gpio_%u\n", gpio); |
| 3313 | |
| 3314 | retval = gpio_request(gpio, buf); |
| 3315 | if (retval) { |
| 3316 | pr_err("%s: Failed to get gpio %d (code: %d)", |
| 3317 | __func__, gpio, retval); |
| 3318 | return retval; |
| 3319 | } |
| 3320 | |
| 3321 | if (dir == 0) |
| 3322 | retval = gpio_direction_input(gpio); |
| 3323 | else |
| 3324 | retval = gpio_direction_output(gpio, state); |
| 3325 | if (retval) { |
| 3326 | pr_err("%s: Failed to set gpio %d direction", |
| 3327 | __func__, gpio); |
| 3328 | return retval; |
| 3329 | } |
| 3330 | } else { |
| 3331 | gpio_free(gpio); |
| 3332 | } |
| 3333 | |
| 3334 | return retval; |
| 3335 | } |
| 3336 | |
| 3337 | static void synaptics_rmi4_set_params(struct synaptics_rmi4_data *rmi4_data) |
| 3338 | { |
| 3339 | unsigned char ii; |
| 3340 | struct synaptics_rmi4_f1a_handle *f1a; |
| 3341 | struct synaptics_rmi4_fn *fhandler; |
| 3342 | struct synaptics_rmi4_device_info *rmi; |
| 3343 | |
| 3344 | rmi = &(rmi4_data->rmi4_mod_info); |
| 3345 | |
| 3346 | input_set_abs_params(rmi4_data->input_dev, |
| 3347 | ABS_MT_POSITION_X, 0, |
| 3348 | rmi4_data->sensor_max_x, 0, 0); |
| 3349 | input_set_abs_params(rmi4_data->input_dev, |
| 3350 | ABS_MT_POSITION_Y, 0, |
| 3351 | rmi4_data->sensor_max_y, 0, 0); |
| 3352 | #ifdef REPORT_2D_W |
| 3353 | input_set_abs_params(rmi4_data->input_dev, |
| 3354 | ABS_MT_TOUCH_MAJOR, 0, |
| 3355 | rmi4_data->max_touch_width, 0, 0); |
| 3356 | input_set_abs_params(rmi4_data->input_dev, |
| 3357 | ABS_MT_TOUCH_MINOR, 0, |
| 3358 | rmi4_data->max_touch_width, 0, 0); |
| 3359 | #endif |
| 3360 | |
| 3361 | rmi4_data->input_settings.sensor_max_x = rmi4_data->sensor_max_x; |
| 3362 | rmi4_data->input_settings.sensor_max_y = rmi4_data->sensor_max_y; |
| 3363 | rmi4_data->input_settings.max_touch_width = rmi4_data->max_touch_width; |
| 3364 | |
| 3365 | #ifdef REPORT_2D_PRESSURE |
| 3366 | if (rmi4_data->report_pressure) { |
| 3367 | input_set_abs_params(rmi4_data->input_dev, |
| 3368 | ABS_MT_PRESSURE, rmi4_data->force_min, |
| 3369 | rmi4_data->force_max, 0, 0); |
| 3370 | |
| 3371 | rmi4_data->input_settings.force_min = rmi4_data->force_min; |
| 3372 | rmi4_data->input_settings.force_max = rmi4_data->force_max; |
| 3373 | } |
| 3374 | #elif defined(F51_DISCRETE_FORCE) |
| 3375 | input_set_abs_params(rmi4_data->input_dev, |
| 3376 | ABS_MT_PRESSURE, 0, |
| 3377 | FORCE_LEVEL_MAX, 0, 0); |
| 3378 | #endif |
| 3379 | |
| 3380 | #ifdef TYPE_B_PROTOCOL |
| 3381 | #ifdef KERNEL_ABOVE_3_6 |
| 3382 | input_mt_init_slots(rmi4_data->input_dev, |
| 3383 | rmi4_data->num_of_fingers, INPUT_MT_DIRECT); |
| 3384 | #else |
| 3385 | input_mt_init_slots(rmi4_data->input_dev, |
| 3386 | rmi4_data->num_of_fingers); |
| 3387 | #endif |
| 3388 | #endif |
| 3389 | |
| 3390 | rmi4_data->input_settings.num_of_fingers = rmi4_data->num_of_fingers; |
| 3391 | |
| 3392 | f1a = NULL; |
| 3393 | if (!list_empty(&rmi->support_fn_list)) { |
| 3394 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 3395 | if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) |
| 3396 | f1a = fhandler->data; |
| 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | if (f1a) { |
| 3401 | for (ii = 0; ii < f1a->valid_button_count; ii++) { |
| 3402 | set_bit(f1a->button_map[ii], |
| 3403 | rmi4_data->input_dev->keybit); |
| 3404 | input_set_capability(rmi4_data->input_dev, |
| 3405 | EV_KEY, f1a->button_map[ii]); |
| 3406 | } |
| 3407 | |
| 3408 | rmi4_data->input_settings.valid_button_count = |
| 3409 | f1a->valid_button_count; |
| 3410 | } |
| 3411 | |
| 3412 | if (vir_button_map->nbuttons) { |
| 3413 | for (ii = 0; ii < vir_button_map->nbuttons; ii++) { |
| 3414 | set_bit(vir_button_map->map[ii * 5], |
| 3415 | rmi4_data->input_dev->keybit); |
| 3416 | input_set_capability(rmi4_data->input_dev, |
| 3417 | EV_KEY, vir_button_map->map[ii * 5]); |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | if (rmi4_data->f11_wakeup_gesture || rmi4_data->f12_wakeup_gesture) { |
| 3422 | set_bit(KEY_WAKEUP, rmi4_data->input_dev->keybit); |
| 3423 | input_set_capability(rmi4_data->input_dev, EV_KEY, KEY_WAKEUP); |
| 3424 | } |
| 3425 | } |
| 3426 | |
| 3427 | static int synaptics_rmi4_set_input_dev(struct synaptics_rmi4_data *rmi4_data) |
| 3428 | { |
| 3429 | int retval; |
| 3430 | const struct synaptics_dsx_board_data *bdata = |
| 3431 | rmi4_data->hw_if->board_data; |
| 3432 | |
| 3433 | rmi4_data->input_dev = input_allocate_device(); |
| 3434 | if (rmi4_data->input_dev == NULL) { |
| 3435 | dev_err(rmi4_data->pdev->dev.parent, |
| 3436 | "%s: Failed to allocate input device\n", |
| 3437 | __func__); |
| 3438 | retval = -ENOMEM; |
| 3439 | goto err_input_device; |
| 3440 | } |
| 3441 | |
| 3442 | retval = synaptics_rmi4_query_device(rmi4_data); |
| 3443 | if (retval < 0) { |
| 3444 | dev_err(rmi4_data->pdev->dev.parent, |
| 3445 | "%s: Failed to query device\n", |
| 3446 | __func__); |
| 3447 | goto err_query_device; |
| 3448 | } |
| 3449 | |
| 3450 | rmi4_data->input_dev->name = PLATFORM_DRIVER_NAME; |
| 3451 | rmi4_data->input_dev->phys = INPUT_PHYS_NAME; |
| 3452 | rmi4_data->input_dev->id.product = SYNAPTICS_DSX_DRIVER_PRODUCT; |
| 3453 | rmi4_data->input_dev->id.version = SYNAPTICS_DSX_DRIVER_VERSION; |
| 3454 | rmi4_data->input_dev->dev.parent = rmi4_data->pdev->dev.parent; |
| 3455 | input_set_drvdata(rmi4_data->input_dev, rmi4_data); |
| 3456 | |
| 3457 | set_bit(EV_SYN, rmi4_data->input_dev->evbit); |
| 3458 | set_bit(EV_KEY, rmi4_data->input_dev->evbit); |
| 3459 | set_bit(EV_ABS, rmi4_data->input_dev->evbit); |
| 3460 | set_bit(BTN_TOUCH, rmi4_data->input_dev->keybit); |
| 3461 | set_bit(BTN_TOOL_FINGER, rmi4_data->input_dev->keybit); |
| 3462 | #ifdef INPUT_PROP_DIRECT |
| 3463 | set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit); |
| 3464 | #endif |
| 3465 | |
| 3466 | if (bdata->max_y_for_2d >= 0) |
| 3467 | rmi4_data->sensor_max_y = bdata->max_y_for_2d; |
| 3468 | |
| 3469 | synaptics_rmi4_set_params(rmi4_data); |
| 3470 | |
| 3471 | retval = input_register_device(rmi4_data->input_dev); |
| 3472 | if (retval) { |
| 3473 | dev_err(rmi4_data->pdev->dev.parent, |
| 3474 | "%s: Failed to register input device\n", |
| 3475 | __func__); |
| 3476 | goto err_register_input; |
| 3477 | } |
| 3478 | |
| 3479 | rmi4_data->input_settings.stylus_enable = rmi4_data->stylus_enable; |
| 3480 | rmi4_data->input_settings.eraser_enable = rmi4_data->eraser_enable; |
| 3481 | |
| 3482 | if (!rmi4_data->stylus_enable) |
| 3483 | return 0; |
| 3484 | |
| 3485 | rmi4_data->stylus_dev = input_allocate_device(); |
| 3486 | if (rmi4_data->stylus_dev == NULL) { |
| 3487 | dev_err(rmi4_data->pdev->dev.parent, |
| 3488 | "%s: Failed to allocate stylus device\n", |
| 3489 | __func__); |
| 3490 | retval = -ENOMEM; |
| 3491 | goto err_stylus_device; |
| 3492 | } |
| 3493 | |
| 3494 | rmi4_data->stylus_dev->name = STYLUS_DRIVER_NAME; |
| 3495 | rmi4_data->stylus_dev->phys = STYLUS_PHYS_NAME; |
| 3496 | rmi4_data->stylus_dev->id.product = SYNAPTICS_DSX_DRIVER_PRODUCT; |
| 3497 | rmi4_data->stylus_dev->id.version = SYNAPTICS_DSX_DRIVER_VERSION; |
| 3498 | rmi4_data->stylus_dev->dev.parent = rmi4_data->pdev->dev.parent; |
| 3499 | input_set_drvdata(rmi4_data->stylus_dev, rmi4_data); |
| 3500 | |
| 3501 | set_bit(EV_KEY, rmi4_data->stylus_dev->evbit); |
| 3502 | set_bit(EV_ABS, rmi4_data->stylus_dev->evbit); |
| 3503 | set_bit(BTN_TOUCH, rmi4_data->stylus_dev->keybit); |
| 3504 | set_bit(BTN_TOOL_PEN, rmi4_data->stylus_dev->keybit); |
| 3505 | if (rmi4_data->eraser_enable) |
| 3506 | set_bit(BTN_TOOL_RUBBER, rmi4_data->stylus_dev->keybit); |
| 3507 | #ifdef INPUT_PROP_DIRECT |
| 3508 | set_bit(INPUT_PROP_DIRECT, rmi4_data->stylus_dev->propbit); |
| 3509 | #endif |
| 3510 | |
| 3511 | input_set_abs_params(rmi4_data->stylus_dev, ABS_X, 0, |
| 3512 | rmi4_data->sensor_max_x, 0, 0); |
| 3513 | input_set_abs_params(rmi4_data->stylus_dev, ABS_Y, 0, |
| 3514 | rmi4_data->sensor_max_y, 0, 0); |
| 3515 | |
| 3516 | retval = input_register_device(rmi4_data->stylus_dev); |
| 3517 | if (retval) { |
| 3518 | dev_err(rmi4_data->pdev->dev.parent, |
| 3519 | "%s: Failed to register stylus device\n", |
| 3520 | __func__); |
| 3521 | goto err_register_stylus; |
| 3522 | } |
| 3523 | |
| 3524 | return 0; |
| 3525 | |
| 3526 | err_register_stylus: |
| 3527 | rmi4_data->stylus_dev = NULL; |
| 3528 | |
| 3529 | err_stylus_device: |
| 3530 | input_unregister_device(rmi4_data->input_dev); |
| 3531 | rmi4_data->input_dev = NULL; |
| 3532 | |
| 3533 | err_register_input: |
| 3534 | err_query_device: |
| 3535 | synaptics_rmi4_empty_fn_list(rmi4_data); |
| 3536 | input_free_device(rmi4_data->input_dev); |
| 3537 | |
| 3538 | err_input_device: |
| 3539 | return retval; |
| 3540 | } |
| 3541 | |
| 3542 | static int synaptics_rmi4_set_gpio(struct synaptics_rmi4_data *rmi4_data) |
| 3543 | { |
| 3544 | int retval; |
| 3545 | const struct synaptics_dsx_board_data *bdata = |
| 3546 | rmi4_data->hw_if->board_data; |
| 3547 | |
| 3548 | retval = synaptics_rmi4_gpio_setup( |
| 3549 | bdata->irq_gpio, |
| 3550 | true, 0, 0); |
| 3551 | if (retval < 0) { |
| 3552 | dev_err(rmi4_data->pdev->dev.parent, |
| 3553 | "%s: Failed to configure attention GPIO\n", |
| 3554 | __func__); |
| 3555 | goto err_gpio_irq; |
| 3556 | } |
| 3557 | |
| 3558 | if (bdata->power_gpio >= 0) { |
| 3559 | retval = synaptics_rmi4_gpio_setup( |
| 3560 | bdata->power_gpio, |
| 3561 | true, 1, !bdata->power_on_state); |
| 3562 | if (retval < 0) { |
| 3563 | dev_err(rmi4_data->pdev->dev.parent, |
| 3564 | "%s: Failed to configure power GPIO\n", |
| 3565 | __func__); |
| 3566 | goto err_gpio_power; |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | if (bdata->reset_gpio >= 0) { |
| 3571 | retval = synaptics_rmi4_gpio_setup( |
| 3572 | bdata->reset_gpio, |
| 3573 | true, 1, !bdata->reset_on_state); |
| 3574 | if (retval < 0) { |
| 3575 | dev_err(rmi4_data->pdev->dev.parent, |
| 3576 | "%s: Failed to configure reset GPIO\n", |
| 3577 | __func__); |
| 3578 | goto err_gpio_reset; |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | if (bdata->power_gpio >= 0) { |
| 3583 | gpio_set_value(bdata->power_gpio, bdata->power_on_state); |
| 3584 | msleep(bdata->power_delay_ms); |
| 3585 | } |
| 3586 | |
| 3587 | if (bdata->reset_gpio >= 0) { |
| 3588 | gpio_set_value(bdata->reset_gpio, bdata->reset_on_state); |
| 3589 | msleep(bdata->reset_active_ms); |
| 3590 | gpio_set_value(bdata->reset_gpio, !bdata->reset_on_state); |
| 3591 | msleep(bdata->reset_delay_ms); |
| 3592 | } |
| 3593 | |
| 3594 | return 0; |
| 3595 | |
| 3596 | err_gpio_reset: |
| 3597 | if (bdata->power_gpio >= 0) |
| 3598 | synaptics_rmi4_gpio_setup(bdata->power_gpio, false, 0, 0); |
| 3599 | |
| 3600 | err_gpio_power: |
| 3601 | synaptics_rmi4_gpio_setup(bdata->irq_gpio, false, 0, 0); |
| 3602 | |
| 3603 | err_gpio_irq: |
| 3604 | return retval; |
| 3605 | } |
| 3606 | |
| 3607 | static int synaptics_dsx_pinctrl_init(struct synaptics_rmi4_data *rmi4_data) |
| 3608 | { |
| 3609 | int retval; |
| 3610 | |
| 3611 | /* Get pinctrl if target uses pinctrl */ |
| 3612 | rmi4_data->ts_pinctrl = devm_pinctrl_get((rmi4_data->pdev->dev.parent)); |
| 3613 | if (IS_ERR_OR_NULL(rmi4_data->ts_pinctrl)) { |
| 3614 | retval = PTR_ERR(rmi4_data->ts_pinctrl); |
| 3615 | dev_err(rmi4_data->pdev->dev.parent, |
| 3616 | "Target does not use pinctrl %d\n", retval); |
| 3617 | goto err_pinctrl_get; |
| 3618 | } |
| 3619 | |
| 3620 | rmi4_data->pinctrl_state_active |
| 3621 | = pinctrl_lookup_state(rmi4_data->ts_pinctrl, "pmx_ts_active"); |
| 3622 | if (IS_ERR_OR_NULL(rmi4_data->pinctrl_state_active)) { |
| 3623 | retval = PTR_ERR(rmi4_data->pinctrl_state_active); |
| 3624 | dev_err(rmi4_data->pdev->dev.parent, |
| 3625 | "Can not lookup %s pinstate %d\n", |
| 3626 | PINCTRL_STATE_ACTIVE, retval); |
| 3627 | goto err_pinctrl_lookup; |
| 3628 | } |
| 3629 | |
| 3630 | rmi4_data->pinctrl_state_suspend |
| 3631 | = pinctrl_lookup_state(rmi4_data->ts_pinctrl, "pmx_ts_suspend"); |
| 3632 | if (IS_ERR_OR_NULL(rmi4_data->pinctrl_state_suspend)) { |
| 3633 | retval = PTR_ERR(rmi4_data->pinctrl_state_suspend); |
| 3634 | dev_err(rmi4_data->pdev->dev.parent, |
| 3635 | "Can not lookup %s pinstate %d\n", |
| 3636 | PINCTRL_STATE_SUSPEND, retval); |
| 3637 | goto err_pinctrl_lookup; |
| 3638 | } |
| 3639 | |
| 3640 | rmi4_data->pinctrl_state_release |
| 3641 | = pinctrl_lookup_state(rmi4_data->ts_pinctrl, "pmx_ts_release"); |
| 3642 | if (IS_ERR_OR_NULL(rmi4_data->pinctrl_state_release)) { |
| 3643 | retval = PTR_ERR(rmi4_data->pinctrl_state_release); |
| 3644 | dev_err(rmi4_data->pdev->dev.parent, |
| 3645 | "Can not lookup %s pinstate %d\n", |
| 3646 | PINCTRL_STATE_RELEASE, retval); |
| 3647 | } |
| 3648 | |
| 3649 | return 0; |
| 3650 | |
| 3651 | err_pinctrl_lookup: |
| 3652 | devm_pinctrl_put(rmi4_data->ts_pinctrl); |
| 3653 | err_pinctrl_get: |
| 3654 | rmi4_data->ts_pinctrl = NULL; |
| 3655 | return retval; |
| 3656 | } |
| 3657 | |
| 3658 | |
| 3659 | static int synaptics_rmi4_get_reg(struct synaptics_rmi4_data *rmi4_data, |
| 3660 | bool get) |
| 3661 | { |
| 3662 | int retval; |
| 3663 | const struct synaptics_dsx_board_data *bdata = |
| 3664 | rmi4_data->hw_if->board_data; |
| 3665 | |
| 3666 | if (!get) { |
| 3667 | retval = 0; |
| 3668 | goto regulator_put; |
| 3669 | } |
| 3670 | |
| 3671 | if ((bdata->pwr_reg_name != NULL) && (*bdata->pwr_reg_name != 0)) { |
| 3672 | rmi4_data->pwr_reg = regulator_get(rmi4_data->pdev->dev.parent, |
| 3673 | bdata->pwr_reg_name); |
| 3674 | if (IS_ERR(rmi4_data->pwr_reg)) { |
| 3675 | dev_err(rmi4_data->pdev->dev.parent, |
| 3676 | "%s: Failed to get power regulator\n", |
| 3677 | __func__); |
| 3678 | retval = PTR_ERR(rmi4_data->pwr_reg); |
| 3679 | goto regulator_put; |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | retval = regulator_set_load(rmi4_data->pwr_reg, |
| 3684 | 20000); |
| 3685 | if (retval < 0) { |
| 3686 | dev_err(rmi4_data->pdev->dev.parent, |
| 3687 | "%s: Failed to set regulator current avdd\n", |
| 3688 | __func__); |
| 3689 | goto regulator_put; |
| 3690 | } |
| 3691 | |
| 3692 | retval = regulator_set_voltage(rmi4_data->pwr_reg, |
| 3693 | 3000000, |
| 3694 | 3000000); |
| 3695 | if (retval < 0) { |
| 3696 | dev_err(rmi4_data->pdev->dev.parent, |
| 3697 | "%s: Failed to set regulator voltage avdd\n", |
| 3698 | __func__); |
| 3699 | goto regulator_put; |
| 3700 | } |
| 3701 | |
| 3702 | if ((bdata->bus_reg_name != NULL) && (*bdata->bus_reg_name != 0)) { |
| 3703 | rmi4_data->bus_reg = regulator_get(rmi4_data->pdev->dev.parent, |
| 3704 | bdata->bus_reg_name); |
| 3705 | if (IS_ERR(rmi4_data->bus_reg)) { |
| 3706 | dev_err(rmi4_data->pdev->dev.parent, |
| 3707 | "%s: Failed to get bus pullup regulator\n", |
| 3708 | __func__); |
| 3709 | retval = PTR_ERR(rmi4_data->bus_reg); |
| 3710 | goto regulator_put; |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | retval = regulator_set_load(rmi4_data->bus_reg, |
| 3715 | 62000); |
| 3716 | if (retval < 0) { |
| 3717 | dev_err(rmi4_data->pdev->dev.parent, |
| 3718 | "%s: Failed to set regulator current vdd\n", |
| 3719 | __func__); |
| 3720 | goto regulator_put; |
| 3721 | } |
| 3722 | |
| 3723 | retval = regulator_set_voltage(rmi4_data->bus_reg, |
| 3724 | 1800000, |
| 3725 | 1800000); |
| 3726 | if (retval < 0) { |
| 3727 | dev_err(rmi4_data->pdev->dev.parent, |
| 3728 | "%s: Failed to set regulator voltage avdd\n", |
| 3729 | __func__); |
| 3730 | goto regulator_put; |
| 3731 | } |
| 3732 | |
| 3733 | return 0; |
| 3734 | |
| 3735 | regulator_put: |
| 3736 | if (rmi4_data->pwr_reg) { |
| 3737 | regulator_put(rmi4_data->pwr_reg); |
| 3738 | rmi4_data->pwr_reg = NULL; |
| 3739 | } |
| 3740 | |
| 3741 | if (rmi4_data->bus_reg) { |
| 3742 | regulator_put(rmi4_data->bus_reg); |
| 3743 | rmi4_data->bus_reg = NULL; |
| 3744 | } |
| 3745 | |
| 3746 | return retval; |
| 3747 | } |
| 3748 | |
| 3749 | static int synaptics_rmi4_enable_reg(struct synaptics_rmi4_data *rmi4_data, |
| 3750 | bool enable) |
| 3751 | { |
| 3752 | int retval; |
| 3753 | const struct synaptics_dsx_board_data *bdata = |
| 3754 | rmi4_data->hw_if->board_data; |
| 3755 | |
| 3756 | if (!enable) { |
| 3757 | retval = 0; |
| 3758 | goto disable_pwr_reg; |
| 3759 | } |
| 3760 | |
| 3761 | if (rmi4_data->bus_reg && rmi4_data->vdd_status == 0) { |
| 3762 | retval = regulator_enable(rmi4_data->bus_reg); |
| 3763 | if (retval < 0) { |
| 3764 | dev_err(rmi4_data->pdev->dev.parent, |
| 3765 | "%s: Failed to enable bus pullup regulator\n", |
| 3766 | __func__); |
| 3767 | goto exit; |
| 3768 | } |
| 3769 | rmi4_data->vdd_status = 1; |
| 3770 | } |
| 3771 | |
| 3772 | if (rmi4_data->pwr_reg && rmi4_data->avdd_status == 0) { |
| 3773 | retval = regulator_enable(rmi4_data->pwr_reg); |
| 3774 | if (retval < 0) { |
| 3775 | dev_err(rmi4_data->pdev->dev.parent, |
| 3776 | "%s: Failed to enable power regulator\n", |
| 3777 | __func__); |
| 3778 | goto disable_bus_reg; |
| 3779 | } |
| 3780 | rmi4_data->avdd_status = 1; |
| 3781 | msleep(bdata->power_delay_ms); |
| 3782 | } |
| 3783 | |
| 3784 | return 0; |
| 3785 | |
| 3786 | disable_pwr_reg: |
| 3787 | if (rmi4_data->pwr_reg && rmi4_data->avdd_status == 1) { |
| 3788 | regulator_disable(rmi4_data->pwr_reg); |
| 3789 | rmi4_data->avdd_status = 0; |
| 3790 | } |
| 3791 | |
| 3792 | disable_bus_reg: |
| 3793 | if (rmi4_data->bus_reg && rmi4_data->vdd_status == 1) { |
| 3794 | regulator_disable(rmi4_data->bus_reg); |
| 3795 | rmi4_data->vdd_status = 0; |
| 3796 | } |
| 3797 | |
| 3798 | exit: |
| 3799 | return retval; |
| 3800 | } |
| 3801 | |
| 3802 | static int synaptics_rmi4_free_fingers(struct synaptics_rmi4_data *rmi4_data) |
| 3803 | { |
| 3804 | unsigned char ii; |
| 3805 | |
| 3806 | mutex_lock(&(rmi4_data->rmi4_report_mutex)); |
| 3807 | |
| 3808 | #ifdef TYPE_B_PROTOCOL |
| 3809 | for (ii = 0; ii < rmi4_data->num_of_fingers; ii++) { |
| 3810 | input_mt_slot(rmi4_data->input_dev, ii); |
| 3811 | input_mt_report_slot_state(rmi4_data->input_dev, |
| 3812 | MT_TOOL_FINGER, 0); |
| 3813 | } |
| 3814 | #endif |
| 3815 | input_report_key(rmi4_data->input_dev, |
| 3816 | BTN_TOUCH, 0); |
| 3817 | input_report_key(rmi4_data->input_dev, |
| 3818 | BTN_TOOL_FINGER, 0); |
| 3819 | #ifndef TYPE_B_PROTOCOL |
| 3820 | input_mt_sync(rmi4_data->input_dev); |
| 3821 | #endif |
| 3822 | input_sync(rmi4_data->input_dev); |
| 3823 | |
| 3824 | if (rmi4_data->stylus_enable) { |
| 3825 | input_report_key(rmi4_data->stylus_dev, |
| 3826 | BTN_TOUCH, 0); |
| 3827 | input_report_key(rmi4_data->stylus_dev, |
| 3828 | BTN_TOOL_PEN, 0); |
| 3829 | if (rmi4_data->eraser_enable) { |
| 3830 | input_report_key(rmi4_data->stylus_dev, |
| 3831 | BTN_TOOL_RUBBER, 0); |
| 3832 | } |
| 3833 | input_sync(rmi4_data->stylus_dev); |
| 3834 | } |
| 3835 | |
| 3836 | mutex_unlock(&(rmi4_data->rmi4_report_mutex)); |
| 3837 | |
| 3838 | rmi4_data->fingers_on_2d = false; |
| 3839 | |
| 3840 | return 0; |
| 3841 | } |
| 3842 | |
| 3843 | static int synaptics_rmi4_sw_reset(struct synaptics_rmi4_data *rmi4_data) |
| 3844 | { |
| 3845 | int retval; |
| 3846 | unsigned char command = 0x01; |
| 3847 | |
| 3848 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 3849 | rmi4_data->f01_cmd_base_addr, |
| 3850 | &command, |
| 3851 | sizeof(command)); |
| 3852 | if (retval < 0) |
| 3853 | return retval; |
| 3854 | |
| 3855 | msleep(rmi4_data->hw_if->board_data->reset_delay_ms); |
| 3856 | |
| 3857 | if (rmi4_data->hw_if->ui_hw_init) { |
| 3858 | retval = rmi4_data->hw_if->ui_hw_init(rmi4_data); |
| 3859 | if (retval < 0) |
| 3860 | return retval; |
| 3861 | } |
| 3862 | |
| 3863 | return 0; |
| 3864 | } |
| 3865 | |
| 3866 | static int synaptics_rmi4_do_rebuild(struct synaptics_rmi4_data *rmi4_data) |
| 3867 | { |
| 3868 | struct synaptics_rmi4_input_settings *settings; |
| 3869 | |
| 3870 | settings = &(rmi4_data->input_settings); |
| 3871 | |
| 3872 | if (settings->num_of_fingers != rmi4_data->num_of_fingers) |
| 3873 | return 1; |
| 3874 | |
| 3875 | if (settings->valid_button_count != rmi4_data->valid_button_count) |
| 3876 | return 1; |
| 3877 | |
| 3878 | if (settings->max_touch_width != rmi4_data->max_touch_width) |
| 3879 | return 1; |
| 3880 | |
| 3881 | if (settings->sensor_max_x != rmi4_data->sensor_max_x) |
| 3882 | return 1; |
| 3883 | |
| 3884 | if (settings->sensor_max_y != rmi4_data->sensor_max_y) |
| 3885 | return 1; |
| 3886 | |
| 3887 | if (settings->force_min != rmi4_data->force_min) |
| 3888 | return 1; |
| 3889 | |
| 3890 | if (settings->force_max != rmi4_data->force_max) |
| 3891 | return 1; |
| 3892 | |
| 3893 | if (settings->stylus_enable != rmi4_data->stylus_enable) |
| 3894 | return 1; |
| 3895 | |
| 3896 | if (settings->eraser_enable != rmi4_data->eraser_enable) |
| 3897 | return 1; |
| 3898 | |
| 3899 | return 0; |
| 3900 | } |
| 3901 | |
| 3902 | static void synaptics_rmi4_rebuild_work(struct work_struct *work) |
| 3903 | { |
| 3904 | int retval; |
| 3905 | unsigned char attr_count; |
| 3906 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 3907 | struct delayed_work *delayed_work = |
| 3908 | container_of(work, struct delayed_work, work); |
| 3909 | struct synaptics_rmi4_data *rmi4_data = |
| 3910 | container_of(delayed_work, struct synaptics_rmi4_data, |
| 3911 | rb_work); |
| 3912 | |
| 3913 | mutex_lock(&(rmi4_data->rmi4_reset_mutex)); |
| 3914 | |
| 3915 | mutex_lock(&exp_data.mutex); |
| 3916 | |
| 3917 | synaptics_rmi4_irq_enable(rmi4_data, false, false); |
| 3918 | |
| 3919 | if (!list_empty(&exp_data.list)) { |
| 3920 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 3921 | if (exp_fhandler->exp_fn->remove != NULL) |
| 3922 | exp_fhandler->exp_fn->remove(rmi4_data); |
| 3923 | } |
| 3924 | |
| 3925 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { |
| 3926 | sysfs_remove_file(&rmi4_data->input_dev->dev.kobj, |
| 3927 | &attrs[attr_count].attr); |
| 3928 | } |
| 3929 | |
| 3930 | synaptics_rmi4_free_fingers(rmi4_data); |
| 3931 | synaptics_rmi4_empty_fn_list(rmi4_data); |
| 3932 | input_unregister_device(rmi4_data->input_dev); |
| 3933 | rmi4_data->input_dev = NULL; |
| 3934 | if (rmi4_data->stylus_enable) { |
| 3935 | input_unregister_device(rmi4_data->stylus_dev); |
| 3936 | rmi4_data->stylus_dev = NULL; |
| 3937 | } |
| 3938 | |
| 3939 | retval = synaptics_rmi4_set_input_dev(rmi4_data); |
| 3940 | if (retval < 0) { |
| 3941 | dev_err(rmi4_data->pdev->dev.parent, |
| 3942 | "%s: Failed to set up input device\n", |
| 3943 | __func__); |
| 3944 | goto exit; |
| 3945 | } |
| 3946 | |
| 3947 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { |
| 3948 | retval = sysfs_create_file(&rmi4_data->input_dev->dev.kobj, |
| 3949 | &attrs[attr_count].attr); |
| 3950 | if (retval < 0) { |
| 3951 | dev_err(rmi4_data->pdev->dev.parent, |
| 3952 | "%s: Failed to create sysfs attributes\n", |
| 3953 | __func__); |
| 3954 | goto exit; |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | if (!list_empty(&exp_data.list)) { |
| 3959 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 3960 | if (exp_fhandler->exp_fn->init != NULL) |
| 3961 | exp_fhandler->exp_fn->init(rmi4_data); |
| 3962 | } |
| 3963 | |
| 3964 | exit: |
| 3965 | synaptics_rmi4_irq_enable(rmi4_data, true, false); |
| 3966 | |
| 3967 | mutex_unlock(&exp_data.mutex); |
| 3968 | |
| 3969 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); |
| 3970 | } |
| 3971 | |
| 3972 | static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data) |
| 3973 | { |
| 3974 | int retval; |
| 3975 | struct synaptics_rmi4_fn *fhandler; |
| 3976 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 3977 | struct synaptics_rmi4_device_info *rmi; |
| 3978 | |
| 3979 | rmi = &(rmi4_data->rmi4_mod_info); |
| 3980 | |
| 3981 | mutex_lock(&(rmi4_data->rmi4_reset_mutex)); |
| 3982 | |
| 3983 | synaptics_rmi4_free_fingers(rmi4_data); |
| 3984 | |
| 3985 | if (!list_empty(&rmi->support_fn_list)) { |
| 3986 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { |
| 3987 | if (fhandler->fn_number == SYNAPTICS_RMI4_F12) { |
| 3988 | synaptics_rmi4_f12_set_enables(rmi4_data, 0); |
| 3989 | break; |
| 3990 | } |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | retval = synaptics_rmi4_int_enable(rmi4_data, true); |
| 3995 | if (retval < 0) |
| 3996 | goto exit; |
| 3997 | |
| 3998 | mutex_lock(&exp_data.mutex); |
| 3999 | if (!list_empty(&exp_data.list)) { |
| 4000 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 4001 | if (exp_fhandler->exp_fn->reinit != NULL) |
| 4002 | exp_fhandler->exp_fn->reinit(rmi4_data); |
| 4003 | } |
| 4004 | mutex_unlock(&exp_data.mutex); |
| 4005 | |
| 4006 | synaptics_rmi4_set_configured(rmi4_data); |
| 4007 | |
| 4008 | retval = 0; |
| 4009 | |
| 4010 | exit: |
| 4011 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); |
| 4012 | return retval; |
| 4013 | } |
| 4014 | |
| 4015 | static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data, |
| 4016 | bool rebuild) |
| 4017 | { |
| 4018 | int retval; |
| 4019 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4020 | |
| 4021 | mutex_lock(&(rmi4_data->rmi4_reset_mutex)); |
| 4022 | |
| 4023 | synaptics_rmi4_irq_enable(rmi4_data, false, false); |
| 4024 | |
| 4025 | retval = synaptics_rmi4_sw_reset(rmi4_data); |
| 4026 | if (retval < 0) { |
| 4027 | dev_err(rmi4_data->pdev->dev.parent, |
| 4028 | "%s: Failed to issue reset command\n", |
| 4029 | __func__); |
| 4030 | goto exit; |
| 4031 | } |
| 4032 | |
| 4033 | synaptics_rmi4_free_fingers(rmi4_data); |
| 4034 | |
| 4035 | synaptics_rmi4_empty_fn_list(rmi4_data); |
| 4036 | |
| 4037 | retval = synaptics_rmi4_query_device(rmi4_data); |
| 4038 | if (retval < 0) { |
| 4039 | dev_err(rmi4_data->pdev->dev.parent, |
| 4040 | "%s: Failed to query device\n", |
| 4041 | __func__); |
| 4042 | goto exit; |
| 4043 | } |
| 4044 | |
| 4045 | mutex_lock(&exp_data.mutex); |
| 4046 | if (!list_empty(&exp_data.list)) { |
| 4047 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 4048 | if (exp_fhandler->exp_fn->reset != NULL) |
| 4049 | exp_fhandler->exp_fn->reset(rmi4_data); |
| 4050 | } |
| 4051 | mutex_unlock(&exp_data.mutex); |
| 4052 | |
| 4053 | retval = 0; |
| 4054 | |
| 4055 | exit: |
| 4056 | synaptics_rmi4_irq_enable(rmi4_data, true, false); |
| 4057 | |
| 4058 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); |
| 4059 | |
| 4060 | if (rebuild && synaptics_rmi4_do_rebuild(rmi4_data)) { |
| 4061 | queue_delayed_work(rmi4_data->rb_workqueue, |
| 4062 | &rmi4_data->rb_work, |
| 4063 | msecs_to_jiffies(REBUILD_WORK_DELAY_MS)); |
| 4064 | } |
| 4065 | |
| 4066 | return retval; |
| 4067 | } |
| 4068 | |
| 4069 | #ifdef FB_READY_RESET |
| 4070 | static void synaptics_rmi4_reset_work(struct work_struct *work) |
| 4071 | { |
| 4072 | int retval = 0; |
| 4073 | unsigned int timeout; |
| 4074 | struct synaptics_rmi4_data *rmi4_data = |
| 4075 | container_of(work, struct synaptics_rmi4_data, |
| 4076 | reset_work); |
| 4077 | |
| 4078 | timeout = FB_READY_TIMEOUT_S * 1000 / FB_READY_WAIT_MS + 1; |
| 4079 | |
| 4080 | while (!rmi4_data->fb_ready) { |
| 4081 | msleep(FB_READY_WAIT_MS); |
| 4082 | timeout--; |
| 4083 | if (timeout == 0) { |
| 4084 | dev_err(rmi4_data->pdev->dev.parent, |
| 4085 | "%s: Timed out waiting for FB ready\n", |
| 4086 | __func__); |
| 4087 | goto err; |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | mutex_lock(&rmi4_data->rmi4_exp_init_mutex); |
| 4092 | |
| 4093 | retval = synaptics_rmi4_reset_device(rmi4_data, false); |
| 4094 | if (retval < 0) { |
| 4095 | dev_err(rmi4_data->pdev->dev.parent, |
| 4096 | "%s: Failed to issue reset command\n", |
| 4097 | __func__); |
| 4098 | } |
| 4099 | |
| 4100 | mutex_unlock(&rmi4_data->rmi4_exp_init_mutex); |
| 4101 | err: |
| 4102 | |
| 4103 | dev_err(rmi4_data->pdev->dev.parent, |
| 4104 | "%s: Timed out waiting for FB ready\n", |
| 4105 | __func__); |
| 4106 | |
| 4107 | } |
| 4108 | #endif |
| 4109 | |
| 4110 | static int synaptics_rmi4_sleep_enable(struct synaptics_rmi4_data *rmi4_data, |
| 4111 | bool enable) |
| 4112 | { |
| 4113 | int retval; |
| 4114 | unsigned char device_ctrl; |
| 4115 | unsigned char no_sleep_setting = rmi4_data->no_sleep_setting; |
| 4116 | |
| 4117 | retval = synaptics_rmi4_reg_read(rmi4_data, |
| 4118 | rmi4_data->f01_ctrl_base_addr, |
| 4119 | &device_ctrl, |
| 4120 | sizeof(device_ctrl)); |
| 4121 | if (retval < 0) { |
| 4122 | dev_err(rmi4_data->pdev->dev.parent, |
| 4123 | "%s: Failed to read device control\n", |
| 4124 | __func__); |
| 4125 | return retval; |
| 4126 | } |
| 4127 | |
| 4128 | device_ctrl = device_ctrl & ~MASK_3BIT; |
| 4129 | if (enable) |
| 4130 | device_ctrl = device_ctrl | SENSOR_SLEEP; |
| 4131 | else |
| 4132 | device_ctrl = device_ctrl | no_sleep_setting | NORMAL_OPERATION; |
| 4133 | |
| 4134 | retval = synaptics_rmi4_reg_write(rmi4_data, |
| 4135 | rmi4_data->f01_ctrl_base_addr, |
| 4136 | &device_ctrl, |
| 4137 | sizeof(device_ctrl)); |
| 4138 | if (retval < 0) { |
| 4139 | dev_err(rmi4_data->pdev->dev.parent, |
| 4140 | "%s: Failed to write device control\n", |
| 4141 | __func__); |
| 4142 | return retval; |
| 4143 | } |
| 4144 | |
| 4145 | rmi4_data->sensor_sleep = enable; |
| 4146 | |
| 4147 | return retval; |
| 4148 | } |
| 4149 | |
| 4150 | static void synaptics_rmi4_exp_fn_work(struct work_struct *work) |
| 4151 | { |
| 4152 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4153 | struct synaptics_rmi4_exp_fhandler *exp_fhandler_temp; |
| 4154 | struct synaptics_rmi4_data *rmi4_data = exp_data.rmi4_data; |
| 4155 | |
| 4156 | mutex_lock(&rmi4_data->rmi4_exp_init_mutex); |
| 4157 | mutex_lock(&rmi4_data->rmi4_reset_mutex); |
| 4158 | mutex_lock(&exp_data.mutex); |
| 4159 | if (!list_empty(&exp_data.list)) { |
| 4160 | list_for_each_entry_safe(exp_fhandler, |
| 4161 | exp_fhandler_temp, |
| 4162 | &exp_data.list, |
| 4163 | link) { |
| 4164 | if ((exp_fhandler->exp_fn->init != NULL) && |
| 4165 | exp_fhandler->insert) { |
| 4166 | exp_fhandler->exp_fn->init(rmi4_data); |
| 4167 | exp_fhandler->insert = false; |
| 4168 | } else if ((exp_fhandler->exp_fn->remove != NULL) && |
| 4169 | exp_fhandler->remove) { |
| 4170 | exp_fhandler->exp_fn->remove(rmi4_data); |
| 4171 | list_del(&exp_fhandler->link); |
| 4172 | kfree(exp_fhandler); |
| 4173 | } |
| 4174 | } |
| 4175 | } |
| 4176 | mutex_unlock(&exp_data.mutex); |
| 4177 | mutex_unlock(&rmi4_data->rmi4_reset_mutex); |
| 4178 | mutex_unlock(&rmi4_data->rmi4_exp_init_mutex); |
| 4179 | } |
| 4180 | |
| 4181 | void synaptics_rmi4_new_function(struct synaptics_rmi4_exp_fn *exp_fn, |
| 4182 | bool insert) |
| 4183 | { |
| 4184 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4185 | |
| 4186 | if (!exp_data.initialized) { |
| 4187 | mutex_init(&exp_data.mutex); |
| 4188 | INIT_LIST_HEAD(&exp_data.list); |
| 4189 | exp_data.initialized = true; |
| 4190 | } |
| 4191 | |
| 4192 | mutex_lock(&exp_data.mutex); |
| 4193 | if (insert) { |
| 4194 | exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL); |
| 4195 | if (!exp_fhandler) { |
| 4196 | pr_err("%s: Failed to alloc mem for expansion function\n", |
| 4197 | __func__); |
| 4198 | goto exit; |
| 4199 | } |
| 4200 | exp_fhandler->exp_fn = exp_fn; |
| 4201 | exp_fhandler->insert = true; |
| 4202 | exp_fhandler->remove = false; |
| 4203 | list_add_tail(&exp_fhandler->link, &exp_data.list); |
| 4204 | } else if (!list_empty(&exp_data.list)) { |
| 4205 | list_for_each_entry(exp_fhandler, &exp_data.list, link) { |
| 4206 | if (exp_fhandler->exp_fn->fn_type == exp_fn->fn_type) { |
| 4207 | exp_fhandler->insert = false; |
| 4208 | exp_fhandler->remove = true; |
| 4209 | goto exit; |
| 4210 | } |
| 4211 | } |
| 4212 | } |
| 4213 | |
| 4214 | exit: |
| 4215 | mutex_unlock(&exp_data.mutex); |
| 4216 | |
| 4217 | if (exp_data.queue_work) { |
| 4218 | queue_delayed_work(exp_data.workqueue, |
| 4219 | &exp_data.work, |
| 4220 | msecs_to_jiffies(EXP_FN_WORK_DELAY_MS)); |
| 4221 | } |
| 4222 | } |
| 4223 | EXPORT_SYMBOL(synaptics_rmi4_new_function); |
| 4224 | |
| 4225 | static int synaptics_rmi4_probe(struct platform_device *pdev) |
| 4226 | { |
| 4227 | int retval; |
| 4228 | unsigned char attr_count; |
| 4229 | struct synaptics_rmi4_data *rmi4_data; |
| 4230 | const struct synaptics_dsx_hw_interface *hw_if; |
| 4231 | const struct synaptics_dsx_board_data *bdata; |
| 4232 | |
| 4233 | hw_if = pdev->dev.platform_data; |
| 4234 | if (!hw_if) { |
| 4235 | dev_err(&pdev->dev, |
| 4236 | "%s: No hardware interface found\n", |
| 4237 | __func__); |
| 4238 | return -EINVAL; |
| 4239 | } |
| 4240 | |
| 4241 | bdata = hw_if->board_data; |
| 4242 | if (!bdata) { |
| 4243 | dev_err(&pdev->dev, |
| 4244 | "%s: No board data found\n", |
| 4245 | __func__); |
| 4246 | return -EINVAL; |
| 4247 | } |
| 4248 | |
| 4249 | rmi4_data = kzalloc(sizeof(*rmi4_data), GFP_KERNEL); |
| 4250 | if (!rmi4_data) { |
| 4251 | dev_err(&pdev->dev, |
| 4252 | "%s: Failed to alloc mem for rmi4_data\n", |
| 4253 | __func__); |
| 4254 | return -ENOMEM; |
| 4255 | } |
| 4256 | |
| 4257 | rmi4_data->pdev = pdev; |
| 4258 | rmi4_data->current_page = MASK_8BIT; |
| 4259 | rmi4_data->hw_if = hw_if; |
| 4260 | rmi4_data->suspend = false; |
| 4261 | rmi4_data->irq_enabled = false; |
| 4262 | rmi4_data->fingers_on_2d = false; |
| 4263 | |
| 4264 | rmi4_data->reset_device = synaptics_rmi4_reset_device; |
| 4265 | rmi4_data->irq_enable = synaptics_rmi4_irq_enable; |
| 4266 | rmi4_data->sleep_enable = synaptics_rmi4_sleep_enable; |
| 4267 | rmi4_data->report_touch = synaptics_rmi4_report_touch; |
| 4268 | |
| 4269 | mutex_init(&(rmi4_data->rmi4_reset_mutex)); |
| 4270 | mutex_init(&(rmi4_data->rmi4_report_mutex)); |
| 4271 | mutex_init(&(rmi4_data->rmi4_io_ctrl_mutex)); |
| 4272 | mutex_init(&(rmi4_data->rmi4_exp_init_mutex)); |
| 4273 | mutex_init(&(rmi4_data->rmi4_irq_enable_mutex)); |
| 4274 | |
| 4275 | platform_set_drvdata(pdev, rmi4_data); |
| 4276 | |
| 4277 | vir_button_map = bdata->vir_button_map; |
| 4278 | |
| 4279 | retval = synaptics_rmi4_get_reg(rmi4_data, true); |
| 4280 | if (retval < 0) { |
| 4281 | dev_err(&pdev->dev, |
| 4282 | "%s: Failed to get regulators\n", |
| 4283 | __func__); |
| 4284 | goto err_get_reg; |
| 4285 | } |
| 4286 | |
| 4287 | retval = synaptics_rmi4_enable_reg(rmi4_data, true); |
| 4288 | if (retval < 0) { |
| 4289 | dev_err(&pdev->dev, |
| 4290 | "%s: Failed to enable regulators\n", |
| 4291 | __func__); |
| 4292 | goto err_enable_reg; |
| 4293 | } |
| 4294 | |
| 4295 | retval = synaptics_rmi4_set_gpio(rmi4_data); |
| 4296 | if (retval < 0) { |
| 4297 | dev_err(&pdev->dev, |
| 4298 | "%s: Failed to set up GPIO's\n", |
| 4299 | __func__); |
| 4300 | goto err_set_gpio; |
| 4301 | } |
| 4302 | |
| 4303 | retval = synaptics_dsx_pinctrl_init(rmi4_data); |
| 4304 | if (!retval && rmi4_data->ts_pinctrl) { |
| 4305 | /* |
| 4306 | * Pinctrl handle is optional. If pinctrl handle is found |
| 4307 | * let pins to be configured in active state. If not |
| 4308 | * found continue further without error. |
| 4309 | */ |
| 4310 | retval = pinctrl_select_state(rmi4_data->ts_pinctrl, |
| 4311 | rmi4_data->pinctrl_state_active); |
| 4312 | if (retval < 0) { |
| 4313 | dev_err(&pdev->dev, |
| 4314 | "%s: Failed to select %s pinstate %d\n", |
| 4315 | __func__, PINCTRL_STATE_ACTIVE, retval); |
| 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | if (hw_if->ui_hw_init) { |
| 4320 | retval = hw_if->ui_hw_init(rmi4_data); |
| 4321 | if (retval < 0) { |
| 4322 | dev_err(&pdev->dev, |
| 4323 | "%s: Failed to initialize hardware interface\n", |
| 4324 | __func__); |
| 4325 | goto err_ui_hw_init; |
| 4326 | } |
| 4327 | } |
| 4328 | |
| 4329 | retval = synaptics_rmi4_set_input_dev(rmi4_data); |
| 4330 | if (retval < 0) { |
| 4331 | dev_err(&pdev->dev, |
| 4332 | "%s: Failed to set up input device\n", |
| 4333 | __func__); |
| 4334 | goto err_set_input_dev; |
| 4335 | } |
| 4336 | |
| 4337 | #ifdef CONFIG_FB |
| 4338 | rmi4_data->fb_notifier.notifier_call = synaptics_rmi4_dsi_panel_notifier_cb; |
| 4339 | retval = msm_drm_register_client(&rmi4_data->fb_notifier); |
| 4340 | if (retval < 0) { |
| 4341 | |
| 4342 | |
| 4343 | dev_err(&pdev->dev, |
| 4344 | "%s: Failed to register fb notifier client\n", |
| 4345 | __func__); |
| 4346 | } |
| 4347 | #endif |
| 4348 | |
| 4349 | #ifdef USE_EARLYSUSPEND |
| 4350 | rmi4_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; |
| 4351 | rmi4_data->early_suspend.suspend = synaptics_rmi4_early_suspend; |
| 4352 | rmi4_data->early_suspend.resume = synaptics_rmi4_late_resume; |
| 4353 | register_early_suspend(&rmi4_data->early_suspend); |
| 4354 | #endif |
| 4355 | |
| 4356 | if (!exp_data.initialized) { |
| 4357 | mutex_init(&exp_data.mutex); |
| 4358 | INIT_LIST_HEAD(&exp_data.list); |
| 4359 | exp_data.initialized = true; |
| 4360 | } |
| 4361 | |
| 4362 | rmi4_data->irq = gpio_to_irq(bdata->irq_gpio); |
| 4363 | |
| 4364 | retval = synaptics_rmi4_irq_enable(rmi4_data, true, false); |
| 4365 | if (retval < 0) { |
| 4366 | dev_err(&pdev->dev, |
| 4367 | "%s: Failed to enable attention interrupt\n", |
| 4368 | __func__); |
| 4369 | goto err_enable_irq; |
| 4370 | } |
| 4371 | |
| 4372 | if (vir_button_map->nbuttons) { |
| 4373 | rmi4_data->board_prop_dir = kobject_create_and_add( |
| 4374 | "board_properties", NULL); |
| 4375 | if (!rmi4_data->board_prop_dir) { |
| 4376 | dev_err(&pdev->dev, |
| 4377 | "%s: Failed to create board_properties directory\n", |
| 4378 | __func__); |
| 4379 | goto err_virtual_buttons; |
| 4380 | } else { |
| 4381 | retval = sysfs_create_file(rmi4_data->board_prop_dir, |
| 4382 | &virtual_key_map_attr.attr); |
| 4383 | if (retval < 0) { |
| 4384 | dev_err(&pdev->dev, |
| 4385 | "%s: Failed to create virtual key map file\n", |
| 4386 | __func__); |
| 4387 | goto err_virtual_buttons; |
| 4388 | } |
| 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { |
| 4393 | retval = sysfs_create_file(&rmi4_data->input_dev->dev.kobj, |
| 4394 | &attrs[attr_count].attr); |
| 4395 | if (retval < 0) { |
| 4396 | dev_err(&pdev->dev, |
| 4397 | "%s: Failed to create sysfs attributes\n", |
| 4398 | __func__); |
| 4399 | goto err_sysfs; |
| 4400 | } |
| 4401 | } |
| 4402 | |
| 4403 | #ifdef USE_DATA_SERVER |
| 4404 | memset(&interrupt_signal, 0, sizeof(interrupt_signal)); |
| 4405 | interrupt_signal.si_signo = SIGIO; |
| 4406 | interrupt_signal.si_code = SI_USER; |
| 4407 | #endif |
| 4408 | |
| 4409 | rmi4_data->rb_workqueue = |
| 4410 | create_singlethread_workqueue("dsx_rebuild_workqueue"); |
| 4411 | INIT_DELAYED_WORK(&rmi4_data->rb_work, synaptics_rmi4_rebuild_work); |
| 4412 | |
| 4413 | exp_data.workqueue = create_singlethread_workqueue("dsx_exp_workqueue"); |
| 4414 | INIT_DELAYED_WORK(&exp_data.work, synaptics_rmi4_exp_fn_work); |
| 4415 | exp_data.rmi4_data = rmi4_data; |
| 4416 | exp_data.queue_work = true; |
| 4417 | queue_delayed_work(exp_data.workqueue, |
| 4418 | &exp_data.work, |
| 4419 | 0); |
| 4420 | |
| 4421 | #ifdef FB_READY_RESET |
| 4422 | rmi4_data->reset_workqueue = |
| 4423 | create_singlethread_workqueue("dsx_reset_workqueue"); |
| 4424 | INIT_WORK(&rmi4_data->reset_work, synaptics_rmi4_reset_work); |
| 4425 | queue_work(rmi4_data->reset_workqueue, &rmi4_data->reset_work); |
| 4426 | #endif |
| 4427 | |
| 4428 | return retval; |
| 4429 | |
| 4430 | err_sysfs: |
| 4431 | for (attr_count--; attr_count >= 0; attr_count--) { |
| 4432 | sysfs_remove_file(&rmi4_data->input_dev->dev.kobj, |
| 4433 | &attrs[attr_count].attr); |
| 4434 | } |
| 4435 | |
| 4436 | err_virtual_buttons: |
| 4437 | if (rmi4_data->board_prop_dir) { |
| 4438 | sysfs_remove_file(rmi4_data->board_prop_dir, |
| 4439 | &virtual_key_map_attr.attr); |
| 4440 | kobject_put(rmi4_data->board_prop_dir); |
| 4441 | } |
| 4442 | |
| 4443 | synaptics_rmi4_irq_enable(rmi4_data, false, false); |
| 4444 | |
| 4445 | err_enable_irq: |
| 4446 | #ifdef CONFIG_FB |
| 4447 | msm_drm_unregister_client(&rmi4_data->fb_notifier); |
| 4448 | #endif |
| 4449 | |
| 4450 | #ifdef USE_EARLYSUSPEND |
| 4451 | unregister_early_suspend(&rmi4_data->early_suspend); |
| 4452 | #endif |
| 4453 | |
| 4454 | synaptics_rmi4_empty_fn_list(rmi4_data); |
| 4455 | input_unregister_device(rmi4_data->input_dev); |
| 4456 | rmi4_data->input_dev = NULL; |
| 4457 | if (rmi4_data->stylus_enable) { |
| 4458 | input_unregister_device(rmi4_data->stylus_dev); |
| 4459 | rmi4_data->stylus_dev = NULL; |
| 4460 | } |
| 4461 | |
| 4462 | err_set_input_dev: |
| 4463 | synaptics_rmi4_gpio_setup(bdata->irq_gpio, false, 0, 0); |
| 4464 | |
| 4465 | if (bdata->reset_gpio >= 0) |
| 4466 | synaptics_rmi4_gpio_setup(bdata->reset_gpio, false, 0, 0); |
| 4467 | |
| 4468 | if (bdata->power_gpio >= 0) |
| 4469 | synaptics_rmi4_gpio_setup(bdata->power_gpio, false, 0, 0); |
| 4470 | |
| 4471 | err_ui_hw_init: |
| 4472 | err_set_gpio: |
| 4473 | synaptics_rmi4_enable_reg(rmi4_data, false); |
| 4474 | |
| 4475 | if (rmi4_data->ts_pinctrl) { |
| 4476 | if (IS_ERR_OR_NULL(rmi4_data->pinctrl_state_release)) { |
| 4477 | devm_pinctrl_put(rmi4_data->ts_pinctrl); |
| 4478 | rmi4_data->ts_pinctrl = NULL; |
| 4479 | } else { |
| 4480 | retval = pinctrl_select_state( |
| 4481 | rmi4_data->ts_pinctrl, |
| 4482 | rmi4_data->pinctrl_state_release); |
| 4483 | if (retval) |
| 4484 | dev_err(&pdev->dev, |
| 4485 | "%s: Failed to create sysfs attributes\n", |
| 4486 | __func__); |
| 4487 | } |
| 4488 | } |
| 4489 | |
| 4490 | err_enable_reg: |
| 4491 | synaptics_rmi4_get_reg(rmi4_data, false); |
| 4492 | |
| 4493 | err_get_reg: |
| 4494 | kfree(rmi4_data); |
| 4495 | |
| 4496 | return retval; |
| 4497 | } |
| 4498 | |
| 4499 | static int synaptics_rmi4_remove(struct platform_device *pdev) |
| 4500 | { |
| 4501 | unsigned char attr_count; |
| 4502 | struct synaptics_rmi4_data *rmi4_data = platform_get_drvdata(pdev); |
| 4503 | const struct synaptics_dsx_board_data *bdata = |
| 4504 | rmi4_data->hw_if->board_data; |
| 4505 | |
| 4506 | #ifdef FB_READY_RESET |
| 4507 | cancel_work_sync(&rmi4_data->reset_work); |
| 4508 | flush_workqueue(rmi4_data->reset_workqueue); |
| 4509 | destroy_workqueue(rmi4_data->reset_workqueue); |
| 4510 | #endif |
| 4511 | |
| 4512 | cancel_delayed_work_sync(&exp_data.work); |
| 4513 | flush_workqueue(exp_data.workqueue); |
| 4514 | destroy_workqueue(exp_data.workqueue); |
| 4515 | |
| 4516 | cancel_delayed_work_sync(&rmi4_data->rb_work); |
| 4517 | flush_workqueue(rmi4_data->rb_workqueue); |
| 4518 | destroy_workqueue(rmi4_data->rb_workqueue); |
| 4519 | |
| 4520 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { |
| 4521 | sysfs_remove_file(&rmi4_data->input_dev->dev.kobj, |
| 4522 | &attrs[attr_count].attr); |
| 4523 | } |
| 4524 | |
| 4525 | if (rmi4_data->board_prop_dir) { |
| 4526 | sysfs_remove_file(rmi4_data->board_prop_dir, |
| 4527 | &virtual_key_map_attr.attr); |
| 4528 | kobject_put(rmi4_data->board_prop_dir); |
| 4529 | } |
| 4530 | |
| 4531 | synaptics_rmi4_irq_enable(rmi4_data, false, false); |
| 4532 | |
| 4533 | #ifdef CONFIG_FB |
| 4534 | msm_drm_unregister_client(&rmi4_data->fb_notifier); |
| 4535 | #endif |
| 4536 | |
| 4537 | #ifdef USE_EARLYSUSPEND |
| 4538 | unregister_early_suspend(&rmi4_data->early_suspend); |
| 4539 | #endif |
| 4540 | |
| 4541 | synaptics_rmi4_empty_fn_list(rmi4_data); |
| 4542 | input_unregister_device(rmi4_data->input_dev); |
| 4543 | rmi4_data->input_dev = NULL; |
| 4544 | if (rmi4_data->stylus_enable) { |
| 4545 | input_unregister_device(rmi4_data->stylus_dev); |
| 4546 | rmi4_data->stylus_dev = NULL; |
| 4547 | } |
| 4548 | |
| 4549 | synaptics_rmi4_gpio_setup(bdata->irq_gpio, false, 0, 0); |
| 4550 | |
| 4551 | if (bdata->reset_gpio >= 0) |
| 4552 | synaptics_rmi4_gpio_setup(bdata->reset_gpio, false, 0, 0); |
| 4553 | |
| 4554 | if (bdata->power_gpio >= 0) |
| 4555 | synaptics_rmi4_gpio_setup(bdata->power_gpio, false, 0, 0); |
| 4556 | |
| 4557 | if (rmi4_data->ts_pinctrl) { |
| 4558 | if (IS_ERR_OR_NULL(rmi4_data->pinctrl_state_release)) { |
| 4559 | devm_pinctrl_put(rmi4_data->ts_pinctrl); |
| 4560 | rmi4_data->ts_pinctrl = NULL; |
| 4561 | } else { |
| 4562 | pinctrl_select_state( |
| 4563 | rmi4_data->ts_pinctrl, |
| 4564 | rmi4_data->pinctrl_state_release); |
| 4565 | } |
| 4566 | } |
| 4567 | |
| 4568 | synaptics_rmi4_enable_reg(rmi4_data, false); |
| 4569 | synaptics_rmi4_get_reg(rmi4_data, false); |
| 4570 | |
| 4571 | kfree(rmi4_data); |
| 4572 | |
| 4573 | return 0; |
| 4574 | } |
| 4575 | |
| 4576 | #ifdef CONFIG_FB |
| 4577 | static int synaptics_rmi4_dsi_panel_notifier_cb(struct notifier_block *self, |
| 4578 | unsigned long event, void *data) |
| 4579 | { |
| 4580 | int transition; |
| 4581 | struct msm_drm_notifier *evdata = data; |
| 4582 | struct synaptics_rmi4_data *rmi4_data = |
| 4583 | container_of(self, struct synaptics_rmi4_data, |
| 4584 | fb_notifier); |
| 4585 | |
| 4586 | if (!evdata || (evdata->id != 0)) |
| 4587 | return 0; |
| 4588 | |
| 4589 | if (evdata && evdata->data && rmi4_data) { |
| 4590 | if (event == MSM_DRM_EVENT_BLANK) { |
| 4591 | transition = *(int *)evdata->data; |
| 4592 | if (transition == MSM_DRM_BLANK_POWERDOWN) { |
| 4593 | synaptics_rmi4_suspend(&rmi4_data->pdev->dev); |
| 4594 | rmi4_data->fb_ready = false; |
| 4595 | } else if (transition == MSM_DRM_BLANK_UNBLANK) { |
| 4596 | synaptics_rmi4_resume(&rmi4_data->pdev->dev); |
| 4597 | rmi4_data->fb_ready = true; |
| 4598 | } |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | return 0; |
| 4603 | } |
| 4604 | #endif |
| 4605 | |
| 4606 | #ifdef USE_EARLYSUSPEND |
| 4607 | static int synaptics_rmi4_early_suspend(struct early_suspend *h) |
| 4608 | { |
| 4609 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4610 | struct synaptics_rmi4_data *rmi4_data = |
| 4611 | container_of(h, struct synaptics_rmi4_data, |
| 4612 | early_suspend); |
| 4613 | unsigned char device_ctrl; |
| 4614 | |
| 4615 | if (rmi4_data->stay_awake) |
| 4616 | return retval; |
| 4617 | |
| 4618 | if (rmi4_data->enable_wakeup_gesture) { |
| 4619 | if (rmi4_data->no_sleep_setting) { |
| 4620 | synaptics_rmi4_reg_read(rmi4_data, |
| 4621 | rmi4_data->f01_ctrl_base_addr, |
| 4622 | &device_ctrl, |
| 4623 | sizeof(device_ctrl)); |
| 4624 | device_ctrl = device_ctrl & ~NO_SLEEP_ON; |
| 4625 | synaptics_rmi4_reg_write(rmi4_data, |
| 4626 | rmi4_data->f01_ctrl_base_addr, |
| 4627 | &device_ctrl, |
| 4628 | sizeof(device_ctrl)); |
| 4629 | } |
| 4630 | synaptics_rmi4_wakeup_gesture(rmi4_data, true); |
| 4631 | enable_irq_wake(rmi4_data->irq); |
| 4632 | goto exit; |
| 4633 | } |
| 4634 | |
| 4635 | #ifdef SYNA_TDDI |
| 4636 | if (rmi4_data->no_sleep_setting) { |
| 4637 | synaptics_rmi4_reg_read(rmi4_data, |
| 4638 | rmi4_data->f01_ctrl_base_addr, |
| 4639 | &device_ctrl, |
| 4640 | sizeof(device_ctrl)); |
| 4641 | device_ctrl = device_ctrl & ~NO_SLEEP_ON; |
| 4642 | synaptics_rmi4_reg_write(rmi4_data, |
| 4643 | rmi4_data->f01_ctrl_base_addr, |
| 4644 | &device_ctrl, |
| 4645 | sizeof(device_ctrl)); |
| 4646 | } |
| 4647 | synaptics_rmi4_wakeup_gesture(rmi4_data, true); |
| 4648 | usleep(TDDI_LPWG_WAIT_US); |
| 4649 | #endif |
| 4650 | synaptics_rmi4_irq_enable(rmi4_data, false, false); |
| 4651 | synaptics_rmi4_sleep_enable(rmi4_data, true); |
| 4652 | synaptics_rmi4_free_fingers(rmi4_data); |
| 4653 | |
| 4654 | exit: |
| 4655 | mutex_lock(&exp_data.mutex); |
| 4656 | if (!list_empty(&exp_data.list)) { |
| 4657 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 4658 | if (exp_fhandler->exp_fn->early_suspend != NULL) |
| 4659 | exp_fhandler->exp_fn->early_suspend(rmi4_data); |
| 4660 | } |
| 4661 | mutex_unlock(&exp_data.mutex); |
| 4662 | |
| 4663 | rmi4_data->suspend = true; |
| 4664 | |
| 4665 | return retval; |
| 4666 | } |
| 4667 | |
| 4668 | static int synaptics_rmi4_late_resume(struct early_suspend *h) |
| 4669 | { |
| 4670 | #ifdef FB_READY_RESET |
| 4671 | int retval; |
| 4672 | #endif |
| 4673 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4674 | struct synaptics_rmi4_data *rmi4_data = |
| 4675 | container_of(h, struct synaptics_rmi4_data, |
| 4676 | early_suspend); |
| 4677 | |
| 4678 | if (rmi4_data->stay_awake) |
| 4679 | return retval; |
| 4680 | |
| 4681 | if (rmi4_data->enable_wakeup_gesture) { |
| 4682 | disable_irq_wake(rmi4_data->irq); |
| 4683 | goto exit; |
| 4684 | } |
| 4685 | |
| 4686 | rmi4_data->current_page = MASK_8BIT; |
| 4687 | |
| 4688 | if (rmi4_data->suspend) { |
| 4689 | synaptics_rmi4_sleep_enable(rmi4_data, false); |
| 4690 | synaptics_rmi4_irq_enable(rmi4_data, true, false); |
| 4691 | } |
| 4692 | |
| 4693 | exit: |
| 4694 | #ifdef FB_READY_RESET |
| 4695 | if (rmi4_data->suspend) { |
| 4696 | retval = synaptics_rmi4_reset_device(rmi4_data, false); |
| 4697 | if (retval < 0) { |
| 4698 | dev_err(rmi4_data->pdev->dev.parent, |
| 4699 | "%s: Failed to issue reset command\n", |
| 4700 | __func__); |
| 4701 | } |
| 4702 | } |
| 4703 | #endif |
| 4704 | mutex_lock(&exp_data.mutex); |
| 4705 | if (!list_empty(&exp_data.list)) { |
| 4706 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 4707 | if (exp_fhandler->exp_fn->late_resume != NULL) |
| 4708 | exp_fhandler->exp_fn->late_resume(rmi4_data); |
| 4709 | } |
| 4710 | mutex_unlock(&exp_data.mutex); |
| 4711 | |
| 4712 | rmi4_data->suspend = false; |
| 4713 | |
| 4714 | return retval; |
| 4715 | } |
| 4716 | #endif |
| 4717 | |
| 4718 | static int synaptics_rmi4_suspend(struct device *dev) |
| 4719 | { |
| 4720 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4721 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 4722 | unsigned char device_ctrl; |
| 4723 | |
| 4724 | if (rmi4_data->stay_awake) |
| 4725 | return 0; |
| 4726 | |
| 4727 | if (rmi4_data->enable_wakeup_gesture) { |
| 4728 | if (rmi4_data->no_sleep_setting) { |
| 4729 | synaptics_rmi4_reg_read(rmi4_data, |
| 4730 | rmi4_data->f01_ctrl_base_addr, |
| 4731 | &device_ctrl, |
| 4732 | sizeof(device_ctrl)); |
| 4733 | device_ctrl = device_ctrl & ~NO_SLEEP_ON; |
| 4734 | synaptics_rmi4_reg_write(rmi4_data, |
| 4735 | rmi4_data->f01_ctrl_base_addr, |
| 4736 | &device_ctrl, |
| 4737 | sizeof(device_ctrl)); |
| 4738 | } |
| 4739 | synaptics_rmi4_wakeup_gesture(rmi4_data, true); |
| 4740 | enable_irq_wake(rmi4_data->irq); |
| 4741 | goto exit; |
| 4742 | } |
| 4743 | |
| 4744 | if (!rmi4_data->suspend) { |
| 4745 | #ifdef SYNA_TDDI |
| 4746 | if (rmi4_data->no_sleep_setting) { |
| 4747 | synaptics_rmi4_reg_read(rmi4_data, |
| 4748 | rmi4_data->f01_ctrl_base_addr, |
| 4749 | &device_ctrl, |
| 4750 | sizeof(device_ctrl)); |
| 4751 | device_ctrl = device_ctrl & ~NO_SLEEP_ON; |
| 4752 | synaptics_rmi4_reg_write(rmi4_data, |
| 4753 | rmi4_data->f01_ctrl_base_addr, |
| 4754 | &device_ctrl, |
| 4755 | sizeof(device_ctrl)); |
| 4756 | } |
| 4757 | synaptics_rmi4_wakeup_gesture(rmi4_data, true); |
| 4758 | usleep(TDDI_LPWG_WAIT_US); |
| 4759 | #endif |
| 4760 | synaptics_rmi4_irq_enable(rmi4_data, false, false); |
| 4761 | synaptics_rmi4_sleep_enable(rmi4_data, true); |
| 4762 | synaptics_rmi4_free_fingers(rmi4_data); |
| 4763 | } |
| 4764 | |
| 4765 | if (rmi4_data->ts_pinctrl) |
| 4766 | pinctrl_select_state(rmi4_data->ts_pinctrl, |
| 4767 | rmi4_data->pinctrl_state_suspend); |
| 4768 | |
| 4769 | synaptics_rmi4_enable_reg(rmi4_data, false); |
| 4770 | |
| 4771 | exit: |
| 4772 | mutex_lock(&exp_data.mutex); |
| 4773 | if (!list_empty(&exp_data.list)) { |
| 4774 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 4775 | if (exp_fhandler->exp_fn->suspend != NULL) |
| 4776 | exp_fhandler->exp_fn->suspend(rmi4_data); |
| 4777 | } |
| 4778 | mutex_unlock(&exp_data.mutex); |
| 4779 | |
| 4780 | rmi4_data->suspend = true; |
| 4781 | |
| 4782 | return 0; |
| 4783 | } |
| 4784 | |
| 4785 | static int synaptics_rmi4_resume(struct device *dev) |
| 4786 | { |
| 4787 | #ifdef FB_READY_RESET |
| 4788 | int retval; |
| 4789 | #endif |
| 4790 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; |
| 4791 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); |
| 4792 | |
| 4793 | if (rmi4_data->stay_awake) |
| 4794 | return 0; |
| 4795 | |
| 4796 | if (rmi4_data->enable_wakeup_gesture) { |
| 4797 | disable_irq_wake(rmi4_data->irq); |
| 4798 | synaptics_rmi4_wakeup_gesture(rmi4_data, false); |
| 4799 | goto exit; |
| 4800 | } |
| 4801 | |
| 4802 | synaptics_rmi4_enable_reg(rmi4_data, true); |
| 4803 | |
| 4804 | if (rmi4_data->ts_pinctrl) |
| 4805 | pinctrl_select_state(rmi4_data->ts_pinctrl, |
| 4806 | rmi4_data->pinctrl_state_active); |
| 4807 | |
| 4808 | rmi4_data->current_page = MASK_8BIT; |
| 4809 | |
| 4810 | synaptics_rmi4_sleep_enable(rmi4_data, false); |
| 4811 | synaptics_rmi4_irq_enable(rmi4_data, true, false); |
| 4812 | |
| 4813 | exit: |
| 4814 | #ifdef FB_READY_RESET |
| 4815 | retval = synaptics_rmi4_reset_device(rmi4_data, false); |
| 4816 | if (retval < 0) { |
| 4817 | dev_err(rmi4_data->pdev->dev.parent, |
| 4818 | "%s: Failed to issue reset command\n", |
| 4819 | __func__); |
| 4820 | } |
| 4821 | #endif |
| 4822 | mutex_lock(&exp_data.mutex); |
| 4823 | if (!list_empty(&exp_data.list)) { |
| 4824 | list_for_each_entry(exp_fhandler, &exp_data.list, link) |
| 4825 | if (exp_fhandler->exp_fn->resume != NULL) |
| 4826 | exp_fhandler->exp_fn->resume(rmi4_data); |
| 4827 | } |
| 4828 | mutex_unlock(&exp_data.mutex); |
| 4829 | |
| 4830 | rmi4_data->suspend = false; |
| 4831 | |
| 4832 | return 0; |
| 4833 | } |
| 4834 | |
| 4835 | #ifdef CONFIG_PM |
| 4836 | static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = { |
| 4837 | #ifndef CONFIG_FB |
| 4838 | .suspend = synaptics_rmi4_suspend, |
| 4839 | .resume = synaptics_rmi4_resume, |
| 4840 | #endif |
| 4841 | }; |
| 4842 | #endif |
| 4843 | |
| 4844 | static struct platform_driver synaptics_rmi4_driver = { |
| 4845 | .driver = { |
| 4846 | .name = PLATFORM_DRIVER_NAME, |
| 4847 | .owner = THIS_MODULE, |
| 4848 | #ifdef CONFIG_PM |
| 4849 | .pm = &synaptics_rmi4_dev_pm_ops, |
| 4850 | #endif |
| 4851 | }, |
| 4852 | .probe = synaptics_rmi4_probe, |
| 4853 | .remove = synaptics_rmi4_remove, |
| 4854 | }; |
| 4855 | |
| 4856 | static int __init synaptics_rmi4_init(void) |
| 4857 | { |
| 4858 | int retval; |
| 4859 | |
| 4860 | retval = synaptics_rmi4_bus_init(); |
| 4861 | if (retval) |
| 4862 | return retval; |
| 4863 | |
| 4864 | return platform_driver_register(&synaptics_rmi4_driver); |
| 4865 | } |
| 4866 | |
| 4867 | static void __exit synaptics_rmi4_exit(void) |
| 4868 | { |
| 4869 | platform_driver_unregister(&synaptics_rmi4_driver); |
| 4870 | |
| 4871 | synaptics_rmi4_bus_exit(); |
| 4872 | } |
| 4873 | |
| 4874 | module_init(synaptics_rmi4_init); |
| 4875 | module_exit(synaptics_rmi4_exit); |
| 4876 | |
| 4877 | MODULE_AUTHOR("Synaptics, Inc."); |
| 4878 | MODULE_DESCRIPTION("Synaptics DSX Touch Driver"); |
| 4879 | MODULE_LICENSE("GPL v2"); |