Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Input: zinitix - add touchkey support

Zinitix touch controllers can use some of the sense lines for virtual
keys (like those found on many phones). Add support for those keys.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Nikita Travkin <nikita@trvn.ru>
Link: https://lore.kernel.org/r/20240717-zinitix-tkey-v5-2-52ea4cd4bd50@trvn.ru
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Nikita Travkin and committed by
Dmitry Torokhov
075d9b22 1dbd1ab5

+60 -3
+60 -3
drivers/input/touchscreen/zinitix.c
··· 10 10 #include <linux/kernel.h> 11 11 #include <linux/module.h> 12 12 #include <linux/of.h> 13 + #include <linux/property.h> 13 14 #include <linux/regulator/consumer.h> 14 15 #include <linux/slab.h> 15 16 ··· 120 119 121 120 #define DEFAULT_TOUCH_POINT_MODE 2 122 121 #define MAX_SUPPORTED_FINGER_NUM 5 122 + #define MAX_SUPPORTED_BUTTON_NUM 8 123 123 124 124 #define CHIP_ON_DELAY 15 // ms 125 125 #define FIRMWARE_ON_DELAY 40 // ms ··· 148 146 struct touchscreen_properties prop; 149 147 struct regulator_bulk_data supplies[2]; 150 148 u32 zinitix_mode; 149 + u32 keycodes[MAX_SUPPORTED_BUTTON_NUM]; 150 + int num_keycodes; 151 151 }; 152 152 153 153 static int zinitix_read_data(struct i2c_client *client, ··· 199 195 struct i2c_client *client = bt541->client; 200 196 int i; 201 197 int error; 198 + u16 int_flags; 202 199 203 200 error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); 204 201 if (error) { ··· 230 225 if (error) 231 226 return error; 232 227 228 + error = zinitix_write_u16(client, ZINITIX_BUTTON_SUPPORTED_NUM, 229 + bt541->num_keycodes); 230 + if (error) 231 + return error; 232 + 233 233 error = zinitix_write_u16(client, ZINITIX_INITIAL_TOUCH_MODE, 234 234 bt541->zinitix_mode); 235 235 if (error) ··· 245 235 if (error) 246 236 return error; 247 237 248 - error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 249 - BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | 250 - BIT_UP); 238 + int_flags = BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | BIT_UP; 239 + if (bt541->num_keycodes) 240 + int_flags |= BIT_ICON_EVENT; 241 + 242 + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, int_flags); 251 243 if (error) 252 244 return error; 253 245 ··· 362 350 } 363 351 } 364 352 353 + static void zinitix_report_keys(struct bt541_ts_data *bt541, u16 icon_events) 354 + { 355 + int i; 356 + 357 + for (i = 0; i < bt541->num_keycodes; i++) 358 + input_report_key(bt541->input_dev, 359 + bt541->keycodes[i], icon_events & BIT(i)); 360 + } 361 + 365 362 static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler) 366 363 { 367 364 struct bt541_ts_data *bt541 = bt541_handler; 368 365 struct i2c_client *client = bt541->client; 369 366 struct touch_event touch_event; 370 367 unsigned long finger_mask; 368 + __le16 icon_events; 371 369 int error; 372 370 int i; 373 371 ··· 388 366 if (error) { 389 367 dev_err(&client->dev, "Failed to read in touchpoint struct\n"); 390 368 goto out; 369 + } 370 + 371 + if (le16_to_cpu(touch_event.status) & BIT_ICON_EVENT) { 372 + error = zinitix_read_data(bt541->client, ZINITIX_ICON_STATUS_REG, 373 + &icon_events, sizeof(icon_events)); 374 + if (error) { 375 + dev_err(&client->dev, "Failed to read icon events\n"); 376 + goto out; 377 + } 378 + 379 + zinitix_report_keys(bt541, le16_to_cpu(icon_events)); 391 380 } 392 381 393 382 finger_mask = touch_event.finger_mask; ··· 486 453 { 487 454 struct input_dev *input_dev; 488 455 int error; 456 + int i; 489 457 490 458 input_dev = devm_input_allocate_device(&bt541->client->dev); 491 459 if (!input_dev) { ··· 503 469 input_dev->id.bustype = BUS_I2C; 504 470 input_dev->open = zinitix_input_open; 505 471 input_dev->close = zinitix_input_close; 472 + 473 + if (bt541->num_keycodes) { 474 + input_dev->keycode = bt541->keycodes; 475 + input_dev->keycodemax = bt541->num_keycodes; 476 + input_dev->keycodesize = sizeof(bt541->keycodes[0]); 477 + for (i = 0; i < bt541->num_keycodes; i++) 478 + input_set_capability(input_dev, EV_KEY, bt541->keycodes[i]); 479 + } 506 480 507 481 input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); 508 482 input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); ··· 573 531 client->name, bt541); 574 532 if (error) { 575 533 dev_err(&client->dev, "Failed to request IRQ: %d\n", error); 534 + return error; 535 + } 536 + 537 + bt541->num_keycodes = device_property_count_u32(&client->dev, "linux,keycodes"); 538 + if (bt541->num_keycodes > ARRAY_SIZE(bt541->keycodes)) { 539 + dev_err(&client->dev, "too many keys defined (%d)\n", bt541->num_keycodes); 540 + return -EINVAL; 541 + } 542 + 543 + error = device_property_read_u32_array(&client->dev, "linux,keycodes", 544 + bt541->keycodes, 545 + bt541->num_keycodes); 546 + if (error) { 547 + dev_err(&client->dev, 548 + "Unable to parse \"linux,keycodes\" property: %d\n", error); 576 549 return error; 577 550 } 578 551