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

Input: cyttsp - switch to using device properties

Drop support for platform data passed via a C-structure and switch to
device properties instead, which should make the driver compatible
with all platforms: OF, ACPI and static boards. Static boards should
use property sets to communicate device parameters to the driver.

Signed-off-by: Oreste Salerno <oreste.salerno@tomtom.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Oreste Salerno and committed by
Dmitry Torokhov
707b61bb 69a12402

+198 -59
+95
Documentation/devicetree/bindings/input/touchscreen/cyttsp.txt
··· 1 + * Cypress cyttsp touchscreen controller 2 + 3 + Required properties: 4 + - compatible : must be "cypress,cyttsp-i2c" or "cypress,cyttsp-spi" 5 + - reg : Device I2C address or SPI chip select number 6 + - spi-max-frequency : Maximum SPI clocking speed of the device (for cyttsp-spi) 7 + - interrupt-parent : the phandle for the gpio controller 8 + (see interrupt binding[0]). 9 + - interrupts : (gpio) interrupt to which the chip is connected 10 + (see interrupt binding[0]). 11 + - bootloader-key : the 8-byte bootloader key that is required to switch 12 + the chip from bootloader mode (default mode) to 13 + application mode. 14 + This property has to be specified as an array of 8 15 + '/bits/ 8' values. 16 + 17 + Optional properties: 18 + - reset-gpios : the reset gpio the chip is connected to 19 + (see GPIO binding[1] for more details). 20 + - touchscreen-size-x : horizontal resolution of touchscreen (in pixels) 21 + - touchscreen-size-y : vertical resolution of touchscreen (in pixels) 22 + - touchscreen-fuzz-x : horizontal noise value of the absolute input device 23 + (in pixels) 24 + - touchscreen-fuzz-y : vertical noise value of the absolute input device 25 + (in pixels) 26 + - active-distance : the distance in pixels beyond which a touch must move 27 + before movement is detected and reported by the device. 28 + Valid values: 0-15. 29 + - active-interval-ms : the minimum period in ms between consecutive 30 + scanning/processing cycles when the chip is in active mode. 31 + Valid values: 0-255. 32 + - lowpower-interval-ms : the minimum period in ms between consecutive 33 + scanning/processing cycles when the chip is in low-power mode. 34 + Valid values: 0-2550 35 + - touch-timeout-ms : minimum time in ms spent in the active power state while no 36 + touches are detected before entering low-power mode. 37 + Valid values: 0-2550 38 + - use-handshake : enable register-based handshake (boolean). This should 39 + only be used if the chip is configured to use 'blocking 40 + communication with timeout' (in this case the device 41 + generates an interrupt at the end of every 42 + scanning/processing cycle). 43 + 44 + [0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt 45 + [1]: Documentation/devicetree/bindings/gpio/gpio.txt 46 + 47 + Example: 48 + &i2c1 { 49 + /* ... */ 50 + cyttsp@a { 51 + compatible = "cypress,cyttsp-i2c"; 52 + reg = <0xa>; 53 + interrupt-parent = <&gpio0>; 54 + interrupts = <28 0>; 55 + reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; 56 + 57 + touchscreen-size-x = <800>; 58 + touchscreen-size-y = <480>; 59 + touchscreen-fuzz-x = <4>; 60 + touchscreen-fuzz-y = <7>; 61 + 62 + bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>; 63 + active-distance = <8>; 64 + active-interval-ms = <0>; 65 + lowpower-interval-ms = <200>; 66 + touch-timeout-ms = <100>; 67 + }; 68 + 69 + /* ... */ 70 + }; 71 + 72 + &mcspi1 { 73 + /* ... */ 74 + cyttsp@0 { 75 + compatible = "cypress,cyttsp-spi"; 76 + spi-max-frequency = <6000000>; 77 + reg = <0>; 78 + interrupt-parent = <&gpio0>; 79 + interrupts = <28 0>; 80 + reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>; 81 + 82 + touchscreen-size-x = <800>; 83 + touchscreen-size-y = <480>; 84 + touchscreen-fuzz-x = <4>; 85 + touchscreen-fuzz-y = <7>; 86 + 87 + bootloader-key = /bits/ 8 <0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08>; 88 + active-distance = <8>; 89 + active-interval-ms = <0>; 90 + lowpower-interval-ms = <200>; 91 + touch-timeout-ms = <100>; 92 + }; 93 + 94 + /* ... */ 95 + };
+95 -43
drivers/input/touchscreen/cyttsp_core.c
··· 30 30 #include <linux/delay.h> 31 31 #include <linux/input.h> 32 32 #include <linux/input/mt.h> 33 + #include <linux/input/touchscreen.h> 33 34 #include <linux/gpio.h> 34 35 #include <linux/interrupt.h> 35 36 #include <linux/slab.h> 37 + #include <linux/property.h> 38 + #include <linux/gpio/consumer.h> 36 39 37 40 #include "cyttsp_core.h" 38 41 ··· 60 57 #define CY_DELAY_DFLT 20 /* ms */ 61 58 #define CY_DELAY_MAX 500 62 59 #define CY_ACT_DIST_DFLT 0xF8 60 + #define CY_ACT_DIST_MASK 0x0F 63 61 #define CY_HNDSHK_BIT 0x80 64 62 /* device mode bits */ 65 63 #define CY_OPERATE_MODE 0x00 ··· 124 120 125 121 static int cyttsp_handshake(struct cyttsp *ts) 126 122 { 127 - if (ts->pdata->use_hndshk) 123 + if (ts->use_hndshk) 128 124 return ttsp_send_command(ts, 129 125 ts->xy_data.hst_mode ^ CY_HNDSHK_BIT); 130 126 ··· 146 142 u8 bl_cmd[sizeof(bl_command)]; 147 143 148 144 memcpy(bl_cmd, bl_command, sizeof(bl_command)); 149 - if (ts->pdata->bl_keys) 145 + if (ts->bl_keys) 150 146 memcpy(&bl_cmd[sizeof(bl_command) - CY_NUM_BL_KEYS], 151 - ts->pdata->bl_keys, CY_NUM_BL_KEYS); 147 + ts->bl_keys, CY_NUM_BL_KEYS); 152 148 153 149 error = ttsp_write_block_data(ts, CY_REG_BASE, 154 150 sizeof(bl_cmd), bl_cmd); ··· 221 217 { 222 218 int retval = 0; 223 219 224 - if (ts->pdata->act_intrvl != CY_ACT_INTRVL_DFLT || 225 - ts->pdata->tch_tmout != CY_TCH_TMOUT_DFLT || 226 - ts->pdata->lp_intrvl != CY_LP_INTRVL_DFLT) { 220 + if (ts->act_intrvl != CY_ACT_INTRVL_DFLT || 221 + ts->tch_tmout != CY_TCH_TMOUT_DFLT || 222 + ts->lp_intrvl != CY_LP_INTRVL_DFLT) { 227 223 228 224 u8 intrvl_ray[] = { 229 - ts->pdata->act_intrvl, 230 - ts->pdata->tch_tmout, 231 - ts->pdata->lp_intrvl 225 + ts->act_intrvl, 226 + ts->tch_tmout, 227 + ts->lp_intrvl 232 228 }; 233 229 234 230 /* set intrvl registers */ ··· 267 263 268 264 static int cyttsp_act_dist_setup(struct cyttsp *ts) 269 265 { 270 - u8 act_dist_setup = ts->pdata->act_dist; 266 + u8 act_dist_setup = ts->act_dist; 271 267 272 268 /* Init gesture; active distance setup */ 273 269 return ttsp_write_block_data(ts, CY_REG_ACT_DIST, ··· 532 528 cyttsp_disable(ts); 533 529 } 534 530 535 - static void cyttsp_platform_exit(void *data) 531 + static int cyttsp_parse_properties(struct cyttsp *ts) 536 532 { 537 - struct cyttsp *ts = data; 533 + struct device *dev = ts->dev; 534 + u32 dt_value; 535 + int ret; 538 536 539 - if (ts->pdata->exit) 540 - ts->pdata->exit(); 537 + ts->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL); 538 + if (!ts->bl_keys) 539 + return -ENOMEM; 540 + 541 + /* Set some default values */ 542 + ts->use_hndshk = false; 543 + ts->act_dist = CY_ACT_DIST_DFLT; 544 + ts->act_intrvl = CY_ACT_INTRVL_DFLT; 545 + ts->tch_tmout = CY_TCH_TMOUT_DFLT; 546 + ts->lp_intrvl = CY_LP_INTRVL_DFLT; 547 + 548 + ret = device_property_read_u8_array(dev, "bootloader-key", 549 + ts->bl_keys, CY_NUM_BL_KEYS); 550 + if (ret) { 551 + dev_err(dev, 552 + "bootloader-key property could not be retrieved\n"); 553 + return ret; 554 + } 555 + 556 + ts->use_hndshk = device_property_present(dev, "use-handshake"); 557 + 558 + if (!device_property_read_u32(dev, "active-distance", &dt_value)) { 559 + if (dt_value > 15) { 560 + dev_err(dev, "active-distance (%u) must be [0-15]\n", 561 + dt_value); 562 + return -EINVAL; 563 + } 564 + ts->act_dist &= ~CY_ACT_DIST_MASK; 565 + ts->act_dist |= dt_value; 566 + } 567 + 568 + if (!device_property_read_u32(dev, "active-interval-ms", &dt_value)) { 569 + if (dt_value > 255) { 570 + dev_err(dev, "active-interval-ms (%u) must be [0-255]\n", 571 + dt_value); 572 + return -EINVAL; 573 + } 574 + ts->act_intrvl = dt_value; 575 + } 576 + 577 + if (!device_property_read_u32(dev, "lowpower-interval-ms", &dt_value)) { 578 + if (dt_value > 2550) { 579 + dev_err(dev, "lowpower-interval-ms (%u) must be [0-2550]\n", 580 + dt_value); 581 + return -EINVAL; 582 + } 583 + /* Register value is expressed in 0.01s / bit */ 584 + ts->lp_intrvl = dt_value / 10; 585 + } 586 + 587 + if (!device_property_read_u32(dev, "touch-timeout-ms", &dt_value)) { 588 + if (dt_value > 2550) { 589 + dev_err(dev, "touch-timeout-ms (%u) must be [0-2550]\n", 590 + dt_value); 591 + return -EINVAL; 592 + } 593 + /* Register value is expressed in 0.01s / bit */ 594 + ts->tch_tmout = dt_value / 10; 595 + } 596 + 597 + return 0; 541 598 } 542 599 543 600 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops, 544 601 struct device *dev, int irq, size_t xfer_buf_size) 545 602 { 546 - const struct cyttsp_platform_data *pdata = dev_get_platdata(dev); 547 603 struct cyttsp *ts; 548 604 struct input_dev *input_dev; 549 605 int error; 550 - 551 - if (!pdata || !pdata->name || irq <= 0) 552 - return ERR_PTR(-EINVAL); 553 606 554 607 ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL); 555 608 if (!ts) ··· 618 557 619 558 ts->dev = dev; 620 559 ts->input = input_dev; 621 - ts->pdata = dev_get_platdata(dev); 622 560 ts->bus_ops = bus_ops; 623 561 ts->irq = irq; 562 + 563 + ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); 564 + if (IS_ERR(ts->reset_gpio)) { 565 + error = PTR_ERR(ts->reset_gpio); 566 + dev_err(dev, "Failed to request reset gpio, error %d\n", error); 567 + return ERR_PTR(error); 568 + } 569 + 570 + error = cyttsp_parse_properties(ts); 571 + if (error) 572 + return ERR_PTR(error); 624 573 625 574 init_completion(&ts->bl_ready); 626 575 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); 627 576 628 - error = devm_add_action(dev, cyttsp_platform_exit, ts); 629 - if (error) { 630 - dev_err(dev, "failed to install exit action: %d\n", error); 631 - return ERR_PTR(error); 632 - } 633 - 634 - if (pdata->init) { 635 - error = pdata->init(); 636 - if (error) { 637 - dev_err(ts->dev, "platform init failed, err: %d\n", 638 - error); 639 - return ERR_PTR(error); 640 - } 641 - } 642 - 643 - input_dev->name = pdata->name; 577 + input_dev->name = "Cypress TTSP TouchScreen"; 644 578 input_dev->phys = ts->phys; 645 579 input_dev->id.bustype = bus_ops->bustype; 646 580 input_dev->dev.parent = ts->dev; ··· 645 589 646 590 input_set_drvdata(input_dev, ts); 647 591 648 - __set_bit(EV_ABS, input_dev->evbit); 649 - input_set_abs_params(input_dev, ABS_MT_POSITION_X, 650 - 0, pdata->maxx, 0, 0); 651 - input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 652 - 0, pdata->maxy, 0, 0); 653 - input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 654 - 0, CY_MAXZ, 0, 0); 592 + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); 593 + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); 594 + touchscreen_parse_properties(input_dev, true); 655 595 656 596 error = input_mt_init_slots(input_dev, CY_MAX_ID, 0); 657 597 if (error) { ··· 657 605 658 606 error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq, 659 607 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 660 - pdata->name, ts); 608 + "cyttsp", ts); 661 609 if (error) { 662 610 dev_err(ts->dev, "failed to request IRQ %d, err: %d\n", 663 611 ts->irq, error);
+8 -1
drivers/input/touchscreen/cyttsp_core.h
··· 129 129 int irq; 130 130 struct input_dev *input; 131 131 char phys[32]; 132 - const struct cyttsp_platform_data *pdata; 133 132 const struct cyttsp_bus_ops *bus_ops; 134 133 struct cyttsp_bootloader_data bl_data; 135 134 struct cyttsp_sysinfo_data sysinfo_data; ··· 136 137 struct completion bl_ready; 137 138 enum cyttsp_state state; 138 139 bool suspended; 140 + 141 + struct gpio_desc *reset_gpio; 142 + bool use_hndshk; 143 + u8 act_dist; 144 + u8 act_intrvl; 145 + u8 tch_tmout; 146 + u8 lp_intrvl; 147 + u8 *bl_keys; 139 148 140 149 u8 xfer_buf[] ____cacheline_aligned; 141 150 };
-15
include/linux/input/cyttsp.h
··· 40 40 /* Active distance in pixels for a gesture to be reported */ 41 41 #define CY_ACT_DIST_DFLT 0xF8 /* pixels */ 42 42 43 - struct cyttsp_platform_data { 44 - u32 maxx; 45 - u32 maxy; 46 - bool use_hndshk; 47 - u8 act_dist; /* Active distance */ 48 - u8 act_intrvl; /* Active refresh interval; ms */ 49 - u8 tch_tmout; /* Active touch timeout; ms */ 50 - u8 lp_intrvl; /* Low power refresh interval; ms */ 51 - int (*init)(void); 52 - void (*exit)(void); 53 - char *name; 54 - s16 irq_gpio; 55 - u8 *bl_keys; 56 - }; 57 - 58 43 #endif /* _CYTTSP_H_ */