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

Input: bu21013_ts - switch to using standard touchscreen properties

This switches the driver over to the standard touchscreen properties for
coordinate transformation, while keeping old bindings working as well.

Tested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+46 -24
+13 -3
Documentation/devicetree/bindings/input/touchscreen/bu21013.txt
··· 10 10 Optional properties: 11 11 - touch-gpios : GPIO pin registering a touch event 12 12 - <supply_name>-supply : Phandle to a regulator supply 13 + - touchscreen-size-x : General touchscreen binding, see [1]. 14 + - touchscreen-size-y : General touchscreen binding, see [1]. 15 + - touchscreen-inverted-x : General touchscreen binding, see [1]. 16 + - touchscreen-inverted-y : General touchscreen binding, see [1]. 17 + - touchscreen-swapped-x-y : General touchscreen binding, see [1]. 18 + 19 + [1] All general touchscreen properties are described in 20 + Documentation/devicetree/bindings/input/touchscreen/touchscreen.txt. 21 + 22 + Deprecated properties: 13 23 - rohm,touch-max-x : Maximum outward permitted limit in the X axis 14 24 - rohm,touch-max-y : Maximum outward permitted limit in the Y axis 15 25 - rohm,flip-x : Flip touch coordinates on the X axis ··· 36 26 touch-gpio = <&gpio2 20 GPIO_ACTIVE_LOW>; 37 27 avdd-supply = <&ab8500_ldo_aux1_reg>; 38 28 39 - rohm,touch-max-x = <384>; 40 - rohm,touch-max-y = <704>; 41 - rohm,flip-y; 29 + touchscreen-size-x = <384>; 30 + touchscreen-size-y = <704>; 31 + touchscreen-inverted-y; 42 32 }; 43 33 };
+33 -21
drivers/input/touchscreen/bu21013_ts.c
··· 10 10 #include <linux/i2c.h> 11 11 #include <linux/input.h> 12 12 #include <linux/input/mt.h> 13 + #include <linux/input/touchscreen.h> 13 14 #include <linux/interrupt.h> 14 15 #include <linux/kernel.h> 15 16 #include <linux/module.h> ··· 140 139 * struct bu21013_ts - touch panel data structure 141 140 * @client: pointer to the i2c client 142 141 * @in_dev: pointer to the input device structure 142 + * @props: the device coordinate transformation properties 143 143 * @regulator: pointer to the Regulator used for touch screen 144 144 * @cs_gpiod: chip select GPIO line 145 145 * @int_gpiod: touch interrupt GPIO line ··· 157 155 struct bu21013_ts { 158 156 struct i2c_client *client; 159 157 struct input_dev *in_dev; 158 + struct touchscreen_properties props; 160 159 struct regulator *regulator; 161 160 struct gpio_desc *cs_gpiod; 162 161 struct gpio_desc *int_gpiod; ··· 204 201 205 202 for (i = 0; i < MAX_FINGERS; i++) { 206 203 const u8 *data = &buf[4 * i + 3]; 207 - struct input_mt_pos *p = &pos[finger_down_count]; 204 + unsigned int x, y; 208 205 209 - p->x = data[0] << SHIFT_2 | (data[1] & MASK_BITS); 210 - p->y = data[2] << SHIFT_2 | (data[3] & MASK_BITS); 211 - if (p->x == 0 || p->y == 0) 212 - continue; 213 - 214 - finger_down_count++; 215 - 216 - if (ts->x_flip) 217 - p->x = ts->touch_x_max - p->x; 218 - if (ts->y_flip) 219 - p->y = ts->touch_y_max - p->y; 206 + x = data[0] << SHIFT_2 | (data[1] & MASK_BITS); 207 + y = data[2] << SHIFT_2 | (data[3] & MASK_BITS); 208 + if (x != 0 && y != 0) 209 + touchscreen_set_mt_pos(&pos[finger_down_count++], 210 + &ts->props, x, y); 220 211 } 221 212 222 213 if (finger_down_count == 2 && ··· 409 412 { 410 413 struct bu21013_ts *ts; 411 414 struct input_dev *in_dev; 415 + struct input_absinfo *info; 416 + u32 max_x = 0, max_y = 0; 412 417 int error; 413 418 414 419 if (!i2c_check_functionality(client->adapter, ··· 433 434 ts->x_flip = device_property_read_bool(&client->dev, "rohm,flip-x"); 434 435 ts->y_flip = device_property_read_bool(&client->dev, "rohm,flip-y"); 435 436 436 - device_property_read_u32(&client->dev, "rohm,touch-max-x", 437 - &ts->touch_x_max); 438 - device_property_read_u32(&client->dev, "rohm,touch-max-y", 439 - &ts->touch_y_max); 440 - 441 437 in_dev = devm_input_allocate_device(&client->dev); 442 438 if (!in_dev) { 443 439 dev_err(&client->dev, "device memory alloc failed\n"); ··· 445 451 in_dev->name = DRIVER_TP; 446 452 in_dev->id.bustype = BUS_I2C; 447 453 448 - input_set_abs_params(in_dev, ABS_MT_POSITION_X, 449 - 0, ts->touch_x_max, 0, 0); 450 - input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 451 - 0, ts->touch_y_max, 0, 0); 454 + device_property_read_u32(&client->dev, "rohm,touch-max-x", &max_x); 455 + device_property_read_u32(&client->dev, "rohm,touch-max-y", &max_y); 456 + 457 + input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0); 458 + input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0); 459 + 460 + touchscreen_parse_properties(in_dev, true, &ts->props); 461 + 462 + /* Adjust for the legacy "flip" properties, if present */ 463 + if (!ts->props.invert_x && 464 + device_property_read_bool(&client->dev, "rohm,flip-x")) { 465 + info = &in_dev->absinfo[ABS_MT_POSITION_X]; 466 + info->maximum -= info->minimum; 467 + info->minimum = 0; 468 + } 469 + 470 + if (!ts->props.invert_y && 471 + device_property_read_bool(&client->dev, "rohm,flip-y")) { 472 + info = &in_dev->absinfo[ABS_MT_POSITION_Y]; 473 + info->maximum -= info->minimum; 474 + info->minimum = 0; 475 + } 452 476 453 477 error = input_mt_init_slots(in_dev, MAX_FINGERS, 454 478 INPUT_MT_DIRECT | INPUT_MT_TRACK |