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

Merge branch 'next' into for-linus

Prepare input updates for 5.16 merge window.

+1853 -480
+1
Documentation/devicetree/bindings/input/cap11xx.txt
··· 9 9 "microchip,cap1106" 10 10 "microchip,cap1126" 11 11 "microchip,cap1188" 12 + "microchip,cap1206" 12 13 13 14 reg: The I2C slave address of the device. 14 15
+61
Documentation/devicetree/bindings/input/cypress-sf.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/input/cypress-sf.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Cypress StreetFighter touchkey controller 8 + 9 + maintainers: 10 + - Yassine Oudjana <y.oudjana@protonmail.com> 11 + 12 + allOf: 13 + - $ref: input.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: cypress,sf3155 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + interrupts: 23 + maxItems: 1 24 + 25 + avdd-supply: 26 + description: Regulator for AVDD analog voltage 27 + 28 + vdd-supply: 29 + description: Regulator for VDD digital voltage 30 + 31 + linux,keycodes: 32 + minItems: 1 33 + maxItems: 8 34 + 35 + required: 36 + - compatible 37 + - reg 38 + - interrupts 39 + - avdd-supply 40 + - vdd-supply 41 + 42 + additionalProperties: false 43 + 44 + examples: 45 + - | 46 + #include <dt-bindings/input/input.h> 47 + #include <dt-bindings/interrupt-controller/irq.h> 48 + i2c { 49 + #address-cells = <1>; 50 + #size-cells = <0>; 51 + 52 + touchkey@28 { 53 + compatible = "cypress,sf3155"; 54 + reg = <0x28>; 55 + interrupt-parent = <&msmgpio>; 56 + interrupts = <77 IRQ_TYPE_EDGE_FALLING>; 57 + avdd-supply = <&vreg_l6a_1p8>; 58 + vdd-supply = <&vdd_3v2_tp>; 59 + linux,keycodes = <KEY_BACK KEY_MENU>; 60 + }; 61 + };
+10 -2
MAINTAINERS
··· 4301 4301 M: Hans de Goede <hdegoede@redhat.com> 4302 4302 L: linux-input@vger.kernel.org 4303 4303 S: Maintained 4304 - F: Documentation/devicetree/bindings/input/touchscreen/chipone_icn8318.txt 4304 + F: Documentation/devicetree/bindings/input/touchscreen/chipone,icn8318.yaml 4305 4305 F: drivers/input/touchscreen/chipone_icn8318.c 4306 4306 4307 4307 CHIPONE ICN8505 I2C TOUCHSCREEN DRIVER ··· 5005 5005 L: linux-input@vger.kernel.org 5006 5006 S: Maintained 5007 5007 F: drivers/input/touchscreen/cy8ctma140.c 5008 + 5009 + CYPRESS STREETFIGHTER TOUCHKEYS DRIVER 5010 + M: Yassine Oudjana <y.oudjana@protonmail.com> 5011 + L: linux-input@vger.kernel.org 5012 + S: Maintained 5013 + F: Documentation/devicetree/bindings/input/cypress-sf.yaml 5014 + F: drivers/input/keyboard/cypress-sf.c 5008 5015 5009 5016 CYTTSP TOUCHSCREEN DRIVER 5010 5017 M: Linus Walleij <linus.walleij@linaro.org> ··· 7716 7709 7717 7710 GOODIX TOUCHSCREEN 7718 7711 M: Bastien Nocera <hadess@hadess.net> 7712 + M: Hans de Goede <hdegoede@redhat.com> 7719 7713 L: linux-input@vger.kernel.org 7720 7714 S: Maintained 7721 - F: drivers/input/touchscreen/goodix.c 7715 + F: drivers/input/touchscreen/goodix* 7722 7716 7723 7717 GOOGLE ETHERNET DRIVERS 7724 7718 M: Catherine Sullivan <csully@google.com>
+10 -8
drivers/input/joystick/analog.c
··· 19 19 #include <linux/input.h> 20 20 #include <linux/gameport.h> 21 21 #include <linux/jiffies.h> 22 + #include <linux/seq_buf.h> 22 23 #include <linux/timex.h> 23 24 #include <linux/timekeeping.h> 24 25 ··· 339 338 340 339 static void analog_name(struct analog *analog) 341 340 { 342 - snprintf(analog->name, sizeof(analog->name), "Analog %d-axis %d-button", 341 + struct seq_buf s; 342 + 343 + seq_buf_init(&s, analog->name, sizeof(analog->name)); 344 + seq_buf_printf(&s, "Analog %d-axis %d-button", 343 345 hweight8(analog->mask & ANALOG_AXES_STD), 344 346 hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 + 345 347 hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4); 346 348 347 349 if (analog->mask & ANALOG_HATS_ALL) 348 - snprintf(analog->name, sizeof(analog->name), "%s %d-hat", 349 - analog->name, hweight16(analog->mask & ANALOG_HATS_ALL)); 350 + seq_buf_printf(&s, " %d-hat", 351 + hweight16(analog->mask & ANALOG_HATS_ALL)); 350 352 351 353 if (analog->mask & ANALOG_HAT_FCS) 352 - strlcat(analog->name, " FCS", sizeof(analog->name)); 354 + seq_buf_printf(&s, " FCS"); 353 355 if (analog->mask & ANALOG_ANY_CHF) 354 - strlcat(analog->name, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF", 355 - sizeof(analog->name)); 356 + seq_buf_printf(&s, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF"); 356 357 357 - strlcat(analog->name, (analog->mask & ANALOG_GAMEPAD) ? " gamepad": " joystick", 358 - sizeof(analog->name)); 358 + seq_buf_printf(&s, (analog->mask & ANALOG_GAMEPAD) ? " gamepad" : " joystick"); 359 359 } 360 360 361 361 /*
+1 -1
drivers/input/joystick/iforce/iforce-usb.c
··· 92 92 id, 93 93 USB_TYPE_VENDOR | USB_DIR_IN | 94 94 USB_RECIP_INTERFACE, 95 - 0, 0, buf, IFORCE_MAX_LENGTH, HZ); 95 + 0, 0, buf, IFORCE_MAX_LENGTH, 1000); 96 96 if (status < 0) { 97 97 dev_err(&iforce_usb->intf->dev, 98 98 "usb_submit_urb failed: %d\n", status);
+1 -1
drivers/input/joystick/tmdc.c
··· 83 83 const signed char *axes; 84 84 const short *buttons; 85 85 } tmdc_models[] = { 86 - { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy }, 86 + { 1, "ThrustMaster Millennium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy }, 87 87 { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, 88 88 { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at }, 89 89 { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm },
+10
drivers/input/keyboard/Kconfig
··· 791 791 To compile this driver as a module, choose M here: the 792 792 module will be called pmic-keys. 793 793 794 + config KEYBOARD_CYPRESS_SF 795 + tristate "Cypress StreetFighter touchkey support" 796 + depends on I2C 797 + help 798 + Say Y here if you want to enable support for Cypress StreetFighter 799 + touchkeys. 800 + 801 + To compile this driver as a module, choose M here: the 802 + module will be called cypress-sf. 803 + 794 804 endif
+1
drivers/input/keyboard/Makefile
··· 17 17 obj-$(CONFIG_KEYBOARD_CAP11XX) += cap11xx.o 18 18 obj-$(CONFIG_KEYBOARD_CLPS711X) += clps711x-keypad.o 19 19 obj-$(CONFIG_KEYBOARD_CROS_EC) += cros_ec_keyb.o 20 + obj-$(CONFIG_KEYBOARD_CYPRESS_SF) += cypress-sf.o 20 21 obj-$(CONFIG_KEYBOARD_DAVINCI) += davinci_keyscan.o 21 22 obj-$(CONFIG_KEYBOARD_DLINK_DIR685) += dlink-dir685-touchkeys.o 22 23 obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
+29 -14
drivers/input/keyboard/cap11xx.c
··· 91 91 u8 product_id; 92 92 unsigned int num_channels; 93 93 unsigned int num_leds; 94 + bool no_gain; 94 95 }; 95 96 96 97 enum { 97 98 CAP1106, 98 99 CAP1126, 99 100 CAP1188, 101 + CAP1206, 100 102 }; 101 103 102 104 static const struct cap11xx_hw_model cap11xx_devices[] = { 103 - [CAP1106] = { .product_id = 0x55, .num_channels = 6, .num_leds = 0 }, 104 - [CAP1126] = { .product_id = 0x53, .num_channels = 6, .num_leds = 2 }, 105 - [CAP1188] = { .product_id = 0x50, .num_channels = 8, .num_leds = 8 }, 105 + [CAP1106] = { .product_id = 0x55, .num_channels = 6, .num_leds = 0, .no_gain = false }, 106 + [CAP1126] = { .product_id = 0x53, .num_channels = 6, .num_leds = 2, .no_gain = false }, 107 + [CAP1188] = { .product_id = 0x50, .num_channels = 8, .num_leds = 8, .no_gain = false }, 108 + [CAP1206] = { .product_id = 0x67, .num_channels = 6, .num_leds = 0, .no_gain = true }, 106 109 }; 107 110 108 111 static const struct reg_default cap11xx_reg_defaults[] = { ··· 381 378 node = dev->of_node; 382 379 383 380 if (!of_property_read_u32(node, "microchip,sensor-gain", &gain32)) { 384 - if (is_power_of_2(gain32) && gain32 <= 8) 381 + if (cap->no_gain) 382 + dev_warn(dev, 383 + "This version doesn't support sensor gain\n"); 384 + else if (is_power_of_2(gain32) && gain32 <= 8) 385 385 gain = ilog2(gain32); 386 386 else 387 387 dev_err(dev, "Invalid sensor-gain value %d\n", gain32); 388 388 } 389 389 390 - if (of_property_read_bool(node, "microchip,irq-active-high")) { 391 - error = regmap_update_bits(priv->regmap, CAP11XX_REG_CONFIG2, 392 - CAP11XX_REG_CONFIG2_ALT_POL, 0); 393 - if (error) 394 - return error; 390 + if (id->driver_data != CAP1206) { 391 + if (of_property_read_bool(node, "microchip,irq-active-high")) { 392 + error = regmap_update_bits(priv->regmap, 393 + CAP11XX_REG_CONFIG2, 394 + CAP11XX_REG_CONFIG2_ALT_POL, 395 + 0); 396 + if (error) 397 + return error; 398 + } 395 399 } 396 400 397 401 /* Provide some useful defaults */ ··· 408 398 of_property_read_u32_array(node, "linux,keycodes", 409 399 priv->keycodes, cap->num_channels); 410 400 411 - error = regmap_update_bits(priv->regmap, CAP11XX_REG_MAIN_CONTROL, 412 - CAP11XX_REG_MAIN_CONTROL_GAIN_MASK, 413 - gain << CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT); 414 - if (error) 415 - return error; 401 + if (!cap->no_gain) { 402 + error = regmap_update_bits(priv->regmap, 403 + CAP11XX_REG_MAIN_CONTROL, 404 + CAP11XX_REG_MAIN_CONTROL_GAIN_MASK, 405 + gain << CAP11XX_REG_MAIN_CONTROL_GAIN_SHIFT); 406 + if (error) 407 + return error; 408 + } 416 409 417 410 /* Disable autorepeat. The Linux input system has its own handling. */ 418 411 error = regmap_write(priv->regmap, CAP11XX_REG_REPEAT_RATE, 0); ··· 483 470 { .compatible = "microchip,cap1106", }, 484 471 { .compatible = "microchip,cap1126", }, 485 472 { .compatible = "microchip,cap1188", }, 473 + { .compatible = "microchip,cap1206", }, 486 474 {} 487 475 }; 488 476 MODULE_DEVICE_TABLE(of, cap11xx_dt_ids); ··· 492 478 { "cap1106", CAP1106 }, 493 479 { "cap1126", CAP1126 }, 494 480 { "cap1188", CAP1188 }, 481 + { "cap1206", CAP1206 }, 495 482 {} 496 483 }; 497 484 MODULE_DEVICE_TABLE(i2c, cap11xx_i2c_ids);
+224
drivers/input/keyboard/cypress-sf.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Cypress StreetFighter Touchkey Driver 4 + * 5 + * Copyright (c) 2021 Yassine Oudjana <y.oudjana@protonmail.com> 6 + */ 7 + 8 + #include <linux/bitmap.h> 9 + #include <linux/bitops.h> 10 + #include <linux/device.h> 11 + #include <linux/i2c.h> 12 + #include <linux/input.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/module.h> 15 + #include <linux/pm.h> 16 + #include <linux/regulator/consumer.h> 17 + 18 + #define CYPRESS_SF_DEV_NAME "cypress-sf" 19 + 20 + #define CYPRESS_SF_REG_BUTTON_STATUS 0x4a 21 + 22 + struct cypress_sf_data { 23 + struct i2c_client *client; 24 + struct input_dev *input_dev; 25 + struct regulator_bulk_data regulators[2]; 26 + u32 *keycodes; 27 + unsigned long keystates; 28 + int num_keys; 29 + }; 30 + 31 + static irqreturn_t cypress_sf_irq_handler(int irq, void *devid) 32 + { 33 + struct cypress_sf_data *touchkey = devid; 34 + unsigned long keystates, changed; 35 + bool new_state; 36 + int val, key; 37 + 38 + val = i2c_smbus_read_byte_data(touchkey->client, 39 + CYPRESS_SF_REG_BUTTON_STATUS); 40 + if (val < 0) { 41 + dev_err(&touchkey->client->dev, 42 + "Failed to read button status: %d", val); 43 + return IRQ_NONE; 44 + } 45 + keystates = val; 46 + 47 + bitmap_xor(&changed, &keystates, &touchkey->keystates, 48 + touchkey->num_keys); 49 + 50 + for_each_set_bit(key, &changed, touchkey->num_keys) { 51 + new_state = keystates & BIT(key); 52 + dev_dbg(&touchkey->client->dev, 53 + "Key %d changed to %d", key, new_state); 54 + input_report_key(touchkey->input_dev, 55 + touchkey->keycodes[key], new_state); 56 + } 57 + 58 + input_sync(touchkey->input_dev); 59 + touchkey->keystates = keystates; 60 + 61 + return IRQ_HANDLED; 62 + } 63 + 64 + static int cypress_sf_probe(struct i2c_client *client) 65 + { 66 + struct cypress_sf_data *touchkey; 67 + int key, error; 68 + 69 + touchkey = devm_kzalloc(&client->dev, sizeof(*touchkey), GFP_KERNEL); 70 + if (!touchkey) 71 + return -ENOMEM; 72 + 73 + touchkey->client = client; 74 + i2c_set_clientdata(client, touchkey); 75 + 76 + touchkey->regulators[0].supply = "vdd"; 77 + touchkey->regulators[1].supply = "avdd"; 78 + 79 + error = devm_regulator_bulk_get(&client->dev, 80 + ARRAY_SIZE(touchkey->regulators), 81 + touchkey->regulators); 82 + if (error) { 83 + dev_err(&client->dev, "Failed to get regulators: %d\n", error); 84 + return error; 85 + } 86 + 87 + touchkey->num_keys = device_property_read_u32_array(&client->dev, 88 + "linux,keycodes", 89 + NULL, 0); 90 + if (touchkey->num_keys < 0) { 91 + /* Default key count */ 92 + touchkey->num_keys = 2; 93 + } 94 + 95 + touchkey->keycodes = devm_kcalloc(&client->dev, 96 + touchkey->num_keys, 97 + sizeof(*touchkey->keycodes), 98 + GFP_KERNEL); 99 + if (!touchkey->keycodes) 100 + return -ENOMEM; 101 + 102 + error = device_property_read_u32_array(&client->dev, "linux,keycodes", 103 + touchkey->keycodes, 104 + touchkey->num_keys); 105 + 106 + if (error) { 107 + dev_warn(&client->dev, 108 + "Failed to read keycodes: %d, using defaults\n", 109 + error); 110 + 111 + /* Default keycodes */ 112 + touchkey->keycodes[0] = KEY_BACK; 113 + touchkey->keycodes[1] = KEY_MENU; 114 + } 115 + 116 + error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), 117 + touchkey->regulators); 118 + if (error) { 119 + dev_err(&client->dev, 120 + "Failed to enable regulators: %d\n", error); 121 + return error; 122 + } 123 + 124 + touchkey->input_dev = devm_input_allocate_device(&client->dev); 125 + if (!touchkey->input_dev) { 126 + dev_err(&client->dev, "Failed to allocate input device\n"); 127 + return -ENOMEM; 128 + } 129 + 130 + touchkey->input_dev->name = CYPRESS_SF_DEV_NAME; 131 + touchkey->input_dev->id.bustype = BUS_I2C; 132 + 133 + for (key = 0; key < touchkey->num_keys; ++key) 134 + input_set_capability(touchkey->input_dev, 135 + EV_KEY, touchkey->keycodes[key]); 136 + 137 + error = input_register_device(touchkey->input_dev); 138 + if (error) { 139 + dev_err(&client->dev, 140 + "Failed to register input device: %d\n", error); 141 + return error; 142 + } 143 + 144 + error = devm_request_threaded_irq(&client->dev, client->irq, 145 + NULL, cypress_sf_irq_handler, 146 + IRQF_ONESHOT, 147 + CYPRESS_SF_DEV_NAME, touchkey); 148 + if (error) { 149 + dev_err(&client->dev, 150 + "Failed to register threaded irq: %d", error); 151 + return error; 152 + } 153 + 154 + return 0; 155 + }; 156 + 157 + static int __maybe_unused cypress_sf_suspend(struct device *dev) 158 + { 159 + struct i2c_client *client = to_i2c_client(dev); 160 + struct cypress_sf_data *touchkey = i2c_get_clientdata(client); 161 + int error; 162 + 163 + disable_irq(client->irq); 164 + 165 + error = regulator_bulk_disable(ARRAY_SIZE(touchkey->regulators), 166 + touchkey->regulators); 167 + if (error) { 168 + dev_err(dev, "Failed to disable regulators: %d", error); 169 + enable_irq(client->irq); 170 + return error; 171 + } 172 + 173 + return 0; 174 + } 175 + 176 + static int __maybe_unused cypress_sf_resume(struct device *dev) 177 + { 178 + struct i2c_client *client = to_i2c_client(dev); 179 + struct cypress_sf_data *touchkey = i2c_get_clientdata(client); 180 + int error; 181 + 182 + error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators), 183 + touchkey->regulators); 184 + if (error) { 185 + dev_err(dev, "Failed to enable regulators: %d", error); 186 + return error; 187 + } 188 + 189 + enable_irq(client->irq); 190 + 191 + return 0; 192 + } 193 + 194 + static SIMPLE_DEV_PM_OPS(cypress_sf_pm_ops, 195 + cypress_sf_suspend, cypress_sf_resume); 196 + 197 + static struct i2c_device_id cypress_sf_id_table[] = { 198 + { CYPRESS_SF_DEV_NAME, 0 }, 199 + { } 200 + }; 201 + MODULE_DEVICE_TABLE(i2c, cypress_sf_id_table); 202 + 203 + #ifdef CONFIG_OF 204 + static const struct of_device_id cypress_sf_of_match[] = { 205 + { .compatible = "cypress,sf3155", }, 206 + { }, 207 + }; 208 + MODULE_DEVICE_TABLE(of, cypress_sf_of_match); 209 + #endif 210 + 211 + static struct i2c_driver cypress_sf_driver = { 212 + .driver = { 213 + .name = CYPRESS_SF_DEV_NAME, 214 + .pm = &cypress_sf_pm_ops, 215 + .of_match_table = of_match_ptr(cypress_sf_of_match), 216 + }, 217 + .id_table = cypress_sf_id_table, 218 + .probe_new = cypress_sf_probe, 219 + }; 220 + module_i2c_driver(cypress_sf_driver); 221 + 222 + MODULE_AUTHOR("Yassine Oudjana <y.oudjana@protonmail.com>"); 223 + MODULE_DESCRIPTION("Cypress StreetFighter Touchkey Driver"); 224 + MODULE_LICENSE("GPL v2");
+64 -108
drivers/input/keyboard/ep93xx_keypad.c
··· 17 17 * flag. 18 18 */ 19 19 20 + #include <linux/bits.h> 20 21 #include <linux/module.h> 21 22 #include <linux/platform_device.h> 22 23 #include <linux/interrupt.h> ··· 27 26 #include <linux/slab.h> 28 27 #include <linux/soc/cirrus/ep93xx.h> 29 28 #include <linux/platform_data/keypad-ep93xx.h> 29 + #include <linux/pm_wakeirq.h> 30 30 31 31 /* 32 32 * Keypad Interface Register offsets ··· 37 35 #define KEY_REG 0x08 /* Key Value Capture register */ 38 36 39 37 /* Key Scan Initialization Register bit defines */ 40 - #define KEY_INIT_DBNC_MASK (0x00ff0000) 41 - #define KEY_INIT_DBNC_SHIFT (16) 42 - #define KEY_INIT_DIS3KY (1<<15) 43 - #define KEY_INIT_DIAG (1<<14) 44 - #define KEY_INIT_BACK (1<<13) 45 - #define KEY_INIT_T2 (1<<12) 46 - #define KEY_INIT_PRSCL_MASK (0x000003ff) 47 - #define KEY_INIT_PRSCL_SHIFT (0) 38 + #define KEY_INIT_DBNC_MASK GENMASK(23, 16) 39 + #define KEY_INIT_DBNC_SHIFT 16 40 + #define KEY_INIT_DIS3KY BIT(15) 41 + #define KEY_INIT_DIAG BIT(14) 42 + #define KEY_INIT_BACK BIT(13) 43 + #define KEY_INIT_T2 BIT(12) 44 + #define KEY_INIT_PRSCL_MASK GENMASK(9, 0) 45 + #define KEY_INIT_PRSCL_SHIFT 0 48 46 49 47 /* Key Scan Diagnostic Register bit defines */ 50 - #define KEY_DIAG_MASK (0x0000003f) 51 - #define KEY_DIAG_SHIFT (0) 48 + #define KEY_DIAG_MASK GENMASK(5, 0) 49 + #define KEY_DIAG_SHIFT 0 52 50 53 51 /* Key Value Capture Register bit defines */ 54 - #define KEY_REG_K (1<<15) 55 - #define KEY_REG_INT (1<<14) 56 - #define KEY_REG_2KEYS (1<<13) 57 - #define KEY_REG_1KEY (1<<12) 58 - #define KEY_REG_KEY2_MASK (0x00000fc0) 59 - #define KEY_REG_KEY2_SHIFT (6) 60 - #define KEY_REG_KEY1_MASK (0x0000003f) 61 - #define KEY_REG_KEY1_SHIFT (0) 52 + #define KEY_REG_K BIT(15) 53 + #define KEY_REG_INT BIT(14) 54 + #define KEY_REG_2KEYS BIT(13) 55 + #define KEY_REG_1KEY BIT(12) 56 + #define KEY_REG_KEY2_MASK GENMASK(11, 6) 57 + #define KEY_REG_KEY2_SHIFT 6 58 + #define KEY_REG_KEY1_MASK GENMASK(5, 0) 59 + #define KEY_REG_KEY1_SHIFT 0 62 60 63 61 #define EP93XX_MATRIX_SIZE (EP93XX_MATRIX_ROWS * EP93XX_MATRIX_COLS) 64 62 ··· 177 175 } 178 176 179 177 180 - #ifdef CONFIG_PM_SLEEP 181 - static int ep93xx_keypad_suspend(struct device *dev) 178 + static int __maybe_unused ep93xx_keypad_suspend(struct device *dev) 182 179 { 183 180 struct platform_device *pdev = to_platform_device(dev); 184 181 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); ··· 192 191 193 192 mutex_unlock(&input_dev->mutex); 194 193 195 - if (device_may_wakeup(&pdev->dev)) 196 - enable_irq_wake(keypad->irq); 197 - 198 194 return 0; 199 195 } 200 196 201 - static int ep93xx_keypad_resume(struct device *dev) 197 + static int __maybe_unused ep93xx_keypad_resume(struct device *dev) 202 198 { 203 199 struct platform_device *pdev = to_platform_device(dev); 204 200 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); 205 201 struct input_dev *input_dev = keypad->input_dev; 206 - 207 - if (device_may_wakeup(&pdev->dev)) 208 - disable_irq_wake(keypad->irq); 209 202 210 203 mutex_lock(&input_dev->mutex); 211 204 ··· 215 220 216 221 return 0; 217 222 } 218 - #endif 219 223 220 224 static SIMPLE_DEV_PM_OPS(ep93xx_keypad_pm_ops, 221 225 ep93xx_keypad_suspend, ep93xx_keypad_resume); 226 + 227 + static void ep93xx_keypad_release_gpio_action(void *_pdev) 228 + { 229 + struct platform_device *pdev = _pdev; 230 + 231 + ep93xx_keypad_release_gpio(pdev); 232 + } 222 233 223 234 static int ep93xx_keypad_probe(struct platform_device *pdev) 224 235 { ··· 234 233 struct resource *res; 235 234 int err; 236 235 237 - keypad = kzalloc(sizeof(struct ep93xx_keypad), GFP_KERNEL); 236 + keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); 238 237 if (!keypad) 239 238 return -ENOMEM; 240 239 241 240 keypad->pdata = dev_get_platdata(&pdev->dev); 242 - if (!keypad->pdata) { 243 - err = -EINVAL; 244 - goto failed_free; 245 - } 241 + if (!keypad->pdata) 242 + return -EINVAL; 246 243 247 244 keymap_data = keypad->pdata->keymap_data; 248 - if (!keymap_data) { 249 - err = -EINVAL; 250 - goto failed_free; 251 - } 245 + if (!keymap_data) 246 + return -EINVAL; 252 247 253 248 keypad->irq = platform_get_irq(pdev, 0); 254 - if (keypad->irq < 0) { 255 - err = keypad->irq; 256 - goto failed_free; 257 - } 249 + if (keypad->irq < 0) 250 + return keypad->irq; 258 251 259 252 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 260 - if (!res) { 261 - err = -ENXIO; 262 - goto failed_free; 263 - } 253 + if (!res) 254 + return -ENXIO; 264 255 265 - res = request_mem_region(res->start, resource_size(res), pdev->name); 266 - if (!res) { 267 - err = -EBUSY; 268 - goto failed_free; 269 - } 270 - 271 - keypad->mmio_base = ioremap(res->start, resource_size(res)); 272 - if (keypad->mmio_base == NULL) { 273 - err = -ENXIO; 274 - goto failed_free_mem; 275 - } 256 + keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res); 257 + if (IS_ERR(keypad->mmio_base)) 258 + return PTR_ERR(keypad->mmio_base); 276 259 277 260 err = ep93xx_keypad_acquire_gpio(pdev); 278 261 if (err) 279 - goto failed_free_io; 262 + return err; 280 263 281 - keypad->clk = clk_get(&pdev->dev, NULL); 282 - if (IS_ERR(keypad->clk)) { 283 - err = PTR_ERR(keypad->clk); 284 - goto failed_free_gpio; 285 - } 264 + err = devm_add_action_or_reset(&pdev->dev, 265 + ep93xx_keypad_release_gpio_action, pdev); 266 + if (err) 267 + return err; 286 268 287 - input_dev = input_allocate_device(); 288 - if (!input_dev) { 289 - err = -ENOMEM; 290 - goto failed_put_clk; 291 - } 269 + keypad->clk = devm_clk_get(&pdev->dev, NULL); 270 + if (IS_ERR(keypad->clk)) 271 + return PTR_ERR(keypad->clk); 272 + 273 + input_dev = devm_input_allocate_device(&pdev->dev); 274 + if (!input_dev) 275 + return -ENOMEM; 292 276 293 277 keypad->input_dev = input_dev; 294 278 ··· 281 295 input_dev->id.bustype = BUS_HOST; 282 296 input_dev->open = ep93xx_keypad_open; 283 297 input_dev->close = ep93xx_keypad_close; 284 - input_dev->dev.parent = &pdev->dev; 285 298 286 299 err = matrix_keypad_build_keymap(keymap_data, NULL, 287 300 EP93XX_MATRIX_ROWS, EP93XX_MATRIX_COLS, 288 301 keypad->keycodes, input_dev); 289 302 if (err) 290 - goto failed_free_dev; 303 + return err; 291 304 292 305 if (keypad->pdata->flags & EP93XX_KEYPAD_AUTOREPEAT) 293 306 __set_bit(EV_REP, input_dev->evbit); 294 307 input_set_drvdata(input_dev, keypad); 295 308 296 - err = request_irq(keypad->irq, ep93xx_keypad_irq_handler, 297 - 0, pdev->name, keypad); 309 + err = devm_request_irq(&pdev->dev, keypad->irq, 310 + ep93xx_keypad_irq_handler, 311 + 0, pdev->name, keypad); 298 312 if (err) 299 - goto failed_free_dev; 313 + return err; 300 314 301 315 err = input_register_device(input_dev); 302 316 if (err) 303 - goto failed_free_irq; 317 + return err; 304 318 305 319 platform_set_drvdata(pdev, keypad); 320 + 306 321 device_init_wakeup(&pdev->dev, 1); 322 + err = dev_pm_set_wake_irq(&pdev->dev, keypad->irq); 323 + if (err) 324 + dev_warn(&pdev->dev, "failed to set up wakeup irq: %d\n", err); 307 325 308 326 return 0; 309 - 310 - failed_free_irq: 311 - free_irq(keypad->irq, keypad); 312 - failed_free_dev: 313 - input_free_device(input_dev); 314 - failed_put_clk: 315 - clk_put(keypad->clk); 316 - failed_free_gpio: 317 - ep93xx_keypad_release_gpio(pdev); 318 - failed_free_io: 319 - iounmap(keypad->mmio_base); 320 - failed_free_mem: 321 - release_mem_region(res->start, resource_size(res)); 322 - failed_free: 323 - kfree(keypad); 324 - return err; 325 327 } 326 328 327 329 static int ep93xx_keypad_remove(struct platform_device *pdev) 328 330 { 329 - struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); 330 - struct resource *res; 331 - 332 - free_irq(keypad->irq, keypad); 333 - 334 - if (keypad->enabled) 335 - clk_disable(keypad->clk); 336 - clk_put(keypad->clk); 337 - 338 - input_unregister_device(keypad->input_dev); 339 - 340 - ep93xx_keypad_release_gpio(pdev); 341 - 342 - iounmap(keypad->mmio_base); 343 - 344 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 345 - release_mem_region(res->start, resource_size(res)); 346 - 347 - kfree(keypad); 331 + dev_pm_clear_wake_irq(&pdev->dev); 348 332 349 333 return 0; 350 334 }
+2 -2
drivers/input/keyboard/mpr121_touchkey.c
··· 107 107 return ERR_PTR(err); 108 108 } 109 109 110 - err = devm_add_action(dev, mpr121_vdd_supply_disable, vdd_supply); 110 + err = devm_add_action_or_reset(dev, mpr121_vdd_supply_disable, 111 + vdd_supply); 111 112 if (err) { 112 - regulator_disable(vdd_supply); 113 113 dev_err(dev, "failed to add disable regulator action: %d\n", 114 114 err); 115 115 return ERR_PTR(err);
+1 -2
drivers/input/keyboard/omap-keypad.c
··· 190 190 row_shift = get_count_order(pdata->cols); 191 191 keycodemax = pdata->rows << row_shift; 192 192 193 - omap_kp = kzalloc(sizeof(struct omap_kp) + 194 - keycodemax * sizeof(unsigned short), GFP_KERNEL); 193 + omap_kp = kzalloc(struct_size(omap_kp, keymap, keycodemax), GFP_KERNEL); 195 194 input_dev = input_allocate_device(); 196 195 if (!omap_kp || !input_dev) { 197 196 kfree(omap_kp);
+7
drivers/input/keyboard/tm2-touchkey.c
··· 156 156 goto out; 157 157 } 158 158 159 + input_event(touchkey->input_dev, EV_MSC, MSC_SCAN, index); 160 + 159 161 if (data & TM2_TOUCHKEY_BIT_PRESS_EV) { 160 162 for (i = 0; i < touchkey->num_keycodes; i++) 161 163 input_report_key(touchkey->input_dev, ··· 252 250 touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME; 253 251 touchkey->input_dev->id.bustype = BUS_I2C; 254 252 253 + touchkey->input_dev->keycode = touchkey->keycodes; 254 + touchkey->input_dev->keycodemax = touchkey->num_keycodes; 255 + touchkey->input_dev->keycodesize = sizeof(touchkey->keycodes[0]); 256 + 257 + input_set_capability(touchkey->input_dev, EV_MSC, MSC_SCAN); 255 258 for (i = 0; i < touchkey->num_keycodes; i++) 256 259 input_set_capability(touchkey->input_dev, EV_KEY, 257 260 touchkey->keycodes[i]);
+3 -1
drivers/input/misc/adxl34x-i2c.c
··· 103 103 { 104 104 struct adxl34x *ac = i2c_get_clientdata(client); 105 105 106 - return adxl34x_remove(ac); 106 + adxl34x_remove(ac); 107 + 108 + return 0; 107 109 } 108 110 109 111 static int __maybe_unused adxl34x_i2c_suspend(struct device *dev)
+3 -1
drivers/input/misc/adxl34x-spi.c
··· 91 91 { 92 92 struct adxl34x *ac = spi_get_drvdata(spi); 93 93 94 - return adxl34x_remove(ac); 94 + adxl34x_remove(ac); 95 + 96 + return 0; 95 97 } 96 98 97 99 static int __maybe_unused adxl34x_spi_suspend(struct device *dev)
+2 -4
drivers/input/misc/adxl34x.c
··· 237 237 238 238 static void adxl34x_get_triple(struct adxl34x *ac, struct axis_triple *axis) 239 239 { 240 - short buf[3]; 240 + __le16 buf[3]; 241 241 242 242 ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf); 243 243 ··· 896 896 } 897 897 EXPORT_SYMBOL_GPL(adxl34x_probe); 898 898 899 - int adxl34x_remove(struct adxl34x *ac) 899 + void adxl34x_remove(struct adxl34x *ac) 900 900 { 901 901 sysfs_remove_group(&ac->dev->kobj, &adxl34x_attr_group); 902 902 free_irq(ac->irq, ac); 903 903 input_unregister_device(ac->input); 904 904 dev_dbg(ac->dev, "unregistered accelerometer\n"); 905 905 kfree(ac); 906 - 907 - return 0; 908 906 } 909 907 EXPORT_SYMBOL_GPL(adxl34x_remove); 910 908
+1 -1
drivers/input/misc/adxl34x.h
··· 25 25 struct adxl34x *adxl34x_probe(struct device *dev, int irq, 26 26 bool fifo_delay_default, 27 27 const struct adxl34x_bus_ops *bops); 28 - int adxl34x_remove(struct adxl34x *ac); 28 + void adxl34x_remove(struct adxl34x *ac); 29 29 30 30 #endif
+7
drivers/input/misc/ariel-pwrbutton.c
··· 149 149 }; 150 150 MODULE_DEVICE_TABLE(of, ariel_pwrbutton_of_match); 151 151 152 + static const struct spi_device_id ariel_pwrbutton_spi_ids[] = { 153 + { .name = "wyse-ariel-ec-input" }, 154 + { } 155 + }; 156 + MODULE_DEVICE_TABLE(spi, ariel_pwrbutton_spi_ids); 157 + 152 158 static struct spi_driver ariel_pwrbutton_driver = { 153 159 .driver = { 154 160 .name = "dell-wyse-ariel-ec-input", 155 161 .of_match_table = ariel_pwrbutton_of_match, 156 162 }, 157 163 .probe = ariel_pwrbutton_probe, 164 + .id_table = ariel_pwrbutton_spi_ids, 158 165 }; 159 166 module_spi_driver(ariel_pwrbutton_driver); 160 167
+5 -2
drivers/input/misc/cpcap-pwrbutton.c
··· 54 54 static int cpcap_power_button_probe(struct platform_device *pdev) 55 55 { 56 56 struct cpcap_power_button *button; 57 - int irq = platform_get_irq(pdev, 0); 57 + int irq; 58 58 int err; 59 + 60 + irq = platform_get_irq(pdev, 0); 61 + if (irq < 0) 62 + return irq; 59 63 60 64 button = devm_kmalloc(&pdev->dev, sizeof(*button), GFP_KERNEL); 61 65 if (!button) ··· 77 73 78 74 button->idev->name = "cpcap-pwrbutton"; 79 75 button->idev->phys = "cpcap-pwrbutton/input0"; 80 - button->idev->dev.parent = button->dev; 81 76 input_set_capability(button->idev, EV_KEY, KEY_POWER); 82 77 83 78 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
-1
drivers/input/misc/max77693-haptic.c
··· 424 424 MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>"); 425 425 MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>"); 426 426 MODULE_DESCRIPTION("MAXIM 77693/77843 Haptic driver"); 427 - MODULE_ALIAS("platform:max77693-haptic"); 428 427 MODULE_LICENSE("GPL");
+1 -1
drivers/input/misc/max8925_onkey.c
··· 1 - /** 1 + /* 2 2 * MAX8925 ONKEY driver 3 3 * 4 4 * Copyright (C) 2009 Marvell International Ltd.
+5
drivers/input/misc/palmas-pwrbutton.c
··· 210 210 INIT_DELAYED_WORK(&pwron->input_work, palmas_power_button_work); 211 211 212 212 pwron->irq = platform_get_irq(pdev, 0); 213 + if (pwron->irq < 0) { 214 + error = pwron->irq; 215 + goto err_free_input; 216 + } 217 + 213 218 error = request_threaded_irq(pwron->irq, NULL, pwron_irq, 214 219 IRQF_TRIGGER_HIGH | 215 220 IRQF_TRIGGER_LOW |
+5 -1
drivers/input/misc/pm8941-pwrkey.c
··· 29 29 #define PON_PS_HOLD_RST_CTL2 0x5b 30 30 #define PON_PS_HOLD_ENABLE BIT(7) 31 31 #define PON_PS_HOLD_TYPE_MASK 0x0f 32 + #define PON_PS_HOLD_TYPE_WARM_RESET 1 32 33 #define PON_PS_HOLD_TYPE_SHUTDOWN 4 33 34 #define PON_PS_HOLD_TYPE_HARD_RESET 7 34 35 ··· 100 99 break; 101 100 case SYS_RESTART: 102 101 default: 103 - reset_type = PON_PS_HOLD_TYPE_HARD_RESET; 102 + if (reboot_mode == REBOOT_WARM) 103 + reset_type = PON_PS_HOLD_TYPE_WARM_RESET; 104 + else 105 + reset_type = PON_PS_HOLD_TYPE_HARD_RESET; 104 106 break; 105 107 } 106 108
+13
drivers/input/mouse/elantech.c
··· 517 517 case 0x16008020U: 518 518 case 0x26800010U: 519 519 case 0x36808000U: 520 + 521 + /* 522 + * This firmware misreport coordinates for trackpoint 523 + * occasionally. Discard packets outside of [-127, 127] range 524 + * to prevent cursor jumps. 525 + */ 526 + if (packet[4] == 0x80 || packet[5] == 0x80 || 527 + packet[1] >> 7 == packet[4] >> 7 || 528 + packet[2] >> 7 == packet[5] >> 7) { 529 + elantech_debug("discarding packet [%6ph]\n", packet); 530 + break; 531 + 532 + } 520 533 x = packet[4] - (int)((packet[1]^0x80) << 1); 521 534 y = (int)((packet[2]^0x80) << 1) - packet[5]; 522 535
+1
drivers/input/rmi4/rmi_bus.c
··· 90 90 91 91 rmi_dev->dev.bus = &rmi_bus_type; 92 92 rmi_dev->dev.type = &rmi_device_type; 93 + rmi_dev->dev.parent = xport->dev; 93 94 94 95 xport->rmi_dev = rmi_dev; 95 96
+14
drivers/input/serio/i8042-x86ia64io.h
··· 273 273 }, 274 274 }, 275 275 { 276 + /* Fujitsu Lifebook T725 laptop */ 277 + .matches = { 278 + DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 279 + DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK T725"), 280 + }, 281 + }, 282 + { 276 283 /* Fujitsu Lifebook U745 */ 277 284 .matches = { 278 285 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), ··· 845 838 .matches = { 846 839 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 847 840 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK AH544"), 841 + }, 842 + }, 843 + { 844 + /* Fujitsu Lifebook T725 laptop */ 845 + .matches = { 846 + DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 847 + DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK T725"), 848 848 }, 849 849 }, 850 850 {
+1
drivers/input/touchscreen/Kconfig
··· 425 425 config TOUCHSCREEN_ILI210X 426 426 tristate "Ilitek ILI210X based touchscreen" 427 427 depends on I2C 428 + select CRC_CCITT 428 429 help 429 430 Say Y here if you have a ILI210X based touchscreen 430 431 controller. This driver supports models ILI2102,
+2 -1
drivers/input/touchscreen/Makefile
··· 6 6 # Each configuration option enables a list of files. 7 7 8 8 wm97xx-ts-y := wm97xx-core.o 9 + goodix_ts-y := goodix.o goodix_fwupload.o 9 10 10 11 obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o 11 12 obj-$(CONFIG_TOUCHSCREEN_AD7877) += ad7877.o ··· 45 44 obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL) += egalax_ts_serial.o 46 45 obj-$(CONFIG_TOUCHSCREEN_EXC3000) += exc3000.o 47 46 obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o 48 - obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix.o 47 + obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix_ts.o 49 48 obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o 50 49 obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o 51 50 obj-$(CONFIG_TOUCHSCREEN_ILITEK) += ilitek_ts_i2c.o
+76 -124
drivers/input/touchscreen/ads7846.c
··· 101 101 struct spi_device *spi; 102 102 struct regulator *reg; 103 103 104 - #if IS_ENABLED(CONFIG_HWMON) 105 - struct device *hwmon; 106 - #endif 107 - 108 104 u16 model; 109 105 u16 vref_mv; 110 106 u16 vref_delay_usecs; ··· 138 142 139 143 int (*filter)(void *data, int data_idx, int *val); 140 144 void *filter_data; 141 - void (*filter_cleanup)(void *data); 142 145 int (*get_pendown_state)(void); 143 146 int gpio_pendown; 144 147 145 148 void (*wait_for_sync)(void); 149 + }; 150 + 151 + enum ads7846_filter { 152 + ADS7846_FILTER_OK, 153 + ADS7846_FILTER_REPEAT, 154 + ADS7846_FILTER_IGNORE, 146 155 }; 147 156 148 157 /* leave chip selected when we're done, for quicker re-select? */ ··· 550 549 551 550 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) 552 551 { 552 + struct device *hwmon; 553 + 553 554 /* hwmon sensors need a reference voltage */ 554 555 switch (ts->model) { 555 556 case 7846: ··· 572 569 break; 573 570 } 574 571 575 - ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, 576 - ts, ads7846_attr_groups); 572 + hwmon = devm_hwmon_device_register_with_groups(&spi->dev, 573 + spi->modalias, ts, 574 + ads7846_attr_groups); 577 575 578 - return PTR_ERR_OR_ZERO(ts->hwmon); 579 - } 580 - 581 - static void ads784x_hwmon_unregister(struct spi_device *spi, 582 - struct ads7846 *ts) 583 - { 584 - if (ts->hwmon) 585 - hwmon_device_unregister(ts->hwmon); 576 + return PTR_ERR_OR_ZERO(hwmon); 586 577 } 587 578 588 579 #else ··· 584 587 struct ads7846 *ts) 585 588 { 586 589 return 0; 587 - } 588 - 589 - static inline void ads784x_hwmon_unregister(struct spi_device *spi, 590 - struct ads7846 *ts) 591 - { 592 590 } 593 591 #endif 594 592 ··· 1006 1014 ts->get_pendown_state = pdata->get_pendown_state; 1007 1015 } else if (gpio_is_valid(pdata->gpio_pendown)) { 1008 1016 1009 - err = gpio_request_one(pdata->gpio_pendown, GPIOF_IN, 1010 - "ads7846_pendown"); 1017 + err = devm_gpio_request_one(&spi->dev, pdata->gpio_pendown, 1018 + GPIOF_IN, "ads7846_pendown"); 1011 1019 if (err) { 1012 1020 dev_err(&spi->dev, 1013 1021 "failed to request/setup pendown GPIO%d: %d\n", ··· 1204 1212 } 1205 1213 #endif 1206 1214 1215 + static void ads7846_regulator_disable(void *regulator) 1216 + { 1217 + regulator_disable(regulator); 1218 + } 1219 + 1207 1220 static int ads7846_probe(struct spi_device *spi) 1208 1221 { 1209 1222 const struct ads7846_platform_data *pdata; 1210 1223 struct ads7846 *ts; 1224 + struct device *dev = &spi->dev; 1211 1225 struct ads7846_packet *packet; 1212 1226 struct input_dev *input_dev; 1213 1227 unsigned long irq_flags; 1214 1228 int err; 1215 1229 1216 1230 if (!spi->irq) { 1217 - dev_dbg(&spi->dev, "no IRQ?\n"); 1231 + dev_dbg(dev, "no IRQ?\n"); 1218 1232 return -EINVAL; 1219 1233 } 1220 1234 1221 1235 /* don't exceed max specified sample rate */ 1222 1236 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { 1223 - dev_err(&spi->dev, "f(sample) %d KHz?\n", 1224 - (spi->max_speed_hz/SAMPLE_BITS)/1000); 1237 + dev_err(dev, "f(sample) %d KHz?\n", 1238 + (spi->max_speed_hz/SAMPLE_BITS)/1000); 1225 1239 return -EINVAL; 1226 1240 } 1227 1241 ··· 1243 1245 if (err < 0) 1244 1246 return err; 1245 1247 1246 - ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 1247 - packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL); 1248 - input_dev = input_allocate_device(); 1249 - if (!ts || !packet || !input_dev) { 1250 - err = -ENOMEM; 1251 - goto err_free_mem; 1252 - } 1248 + ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); 1249 + if (!ts) 1250 + return -ENOMEM; 1251 + 1252 + packet = devm_kzalloc(dev, sizeof(struct ads7846_packet), GFP_KERNEL); 1253 + if (!packet) 1254 + return -ENOMEM; 1255 + 1256 + input_dev = devm_input_allocate_device(dev); 1257 + if (!input_dev) 1258 + return -ENOMEM; 1253 1259 1254 1260 spi_set_drvdata(spi, ts); 1255 1261 ··· 1264 1262 mutex_init(&ts->lock); 1265 1263 init_waitqueue_head(&ts->wait); 1266 1264 1267 - pdata = dev_get_platdata(&spi->dev); 1265 + pdata = dev_get_platdata(dev); 1268 1266 if (!pdata) { 1269 - pdata = ads7846_probe_dt(&spi->dev); 1270 - if (IS_ERR(pdata)) { 1271 - err = PTR_ERR(pdata); 1272 - goto err_free_mem; 1273 - } 1267 + pdata = ads7846_probe_dt(dev); 1268 + if (IS_ERR(pdata)) 1269 + return PTR_ERR(pdata); 1274 1270 } 1275 1271 1276 1272 ts->model = pdata->model ? : 7846; ··· 1276 1276 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; 1277 1277 ts->vref_mv = pdata->vref_mv; 1278 1278 1279 - if (pdata->filter != NULL) { 1280 - if (pdata->filter_init != NULL) { 1281 - err = pdata->filter_init(pdata, &ts->filter_data); 1282 - if (err < 0) 1283 - goto err_free_mem; 1284 - } 1285 - ts->filter = pdata->filter; 1286 - ts->filter_cleanup = pdata->filter_cleanup; 1287 - } else if (pdata->debounce_max) { 1279 + if (pdata->debounce_max) { 1288 1280 ts->debounce_max = pdata->debounce_max; 1289 1281 if (ts->debounce_max < 2) 1290 1282 ts->debounce_max = 2; ··· 1290 1298 1291 1299 err = ads7846_setup_pendown(spi, ts, pdata); 1292 1300 if (err) 1293 - goto err_cleanup_filter; 1301 + return err; 1294 1302 1295 1303 if (pdata->penirq_recheck_delay_usecs) 1296 1304 ts->penirq_recheck_delay_usecs = ··· 1298 1306 1299 1307 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; 1300 1308 1301 - snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); 1309 + snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); 1302 1310 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); 1303 1311 1304 1312 input_dev->name = ts->name; 1305 1313 input_dev->phys = ts->phys; 1306 - input_dev->dev.parent = &spi->dev; 1307 1314 1308 - input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 1309 - input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 1315 + input_dev->id.bustype = BUS_SPI; 1316 + input_dev->id.product = pdata->model; 1317 + 1318 + input_set_capability(input_dev, EV_KEY, BTN_TOUCH); 1310 1319 input_set_abs_params(input_dev, ABS_X, 1311 1320 pdata->x_min ? : 0, 1312 1321 pdata->x_max ? : MAX_12BIT, ··· 1338 1345 1339 1346 ads7846_setup_spi_msg(ts, pdata); 1340 1347 1341 - ts->reg = regulator_get(&spi->dev, "vcc"); 1348 + ts->reg = devm_regulator_get(dev, "vcc"); 1342 1349 if (IS_ERR(ts->reg)) { 1343 1350 err = PTR_ERR(ts->reg); 1344 - dev_err(&spi->dev, "unable to get regulator: %d\n", err); 1345 - goto err_free_gpio; 1351 + dev_err(dev, "unable to get regulator: %d\n", err); 1352 + return err; 1346 1353 } 1347 1354 1348 1355 err = regulator_enable(ts->reg); 1349 1356 if (err) { 1350 - dev_err(&spi->dev, "unable to enable regulator: %d\n", err); 1351 - goto err_put_regulator; 1357 + dev_err(dev, "unable to enable regulator: %d\n", err); 1358 + return err; 1352 1359 } 1360 + 1361 + err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); 1362 + if (err) 1363 + return err; 1353 1364 1354 1365 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; 1355 1366 irq_flags |= IRQF_ONESHOT; 1356 1367 1357 - err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, 1358 - irq_flags, spi->dev.driver->name, ts); 1359 - if (err && !pdata->irq_flags) { 1360 - dev_info(&spi->dev, 1368 + err = devm_request_threaded_irq(dev, spi->irq, 1369 + ads7846_hard_irq, ads7846_irq, 1370 + irq_flags, dev->driver->name, ts); 1371 + if (err && err != -EPROBE_DEFER && !pdata->irq_flags) { 1372 + dev_info(dev, 1361 1373 "trying pin change workaround on irq %d\n", spi->irq); 1362 1374 irq_flags |= IRQF_TRIGGER_RISING; 1363 - err = request_threaded_irq(spi->irq, 1364 - ads7846_hard_irq, ads7846_irq, 1365 - irq_flags, spi->dev.driver->name, ts); 1375 + err = devm_request_threaded_irq(dev, spi->irq, 1376 + ads7846_hard_irq, ads7846_irq, 1377 + irq_flags, dev->driver->name, 1378 + ts); 1366 1379 } 1367 1380 1368 1381 if (err) { 1369 - dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 1370 - goto err_disable_regulator; 1382 + dev_dbg(dev, "irq %d busy?\n", spi->irq); 1383 + return err; 1371 1384 } 1372 1385 1373 1386 err = ads784x_hwmon_register(spi, ts); 1374 1387 if (err) 1375 - goto err_free_irq; 1388 + return err; 1376 1389 1377 - dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); 1390 + dev_info(dev, "touchscreen, irq %d\n", spi->irq); 1378 1391 1379 1392 /* 1380 1393 * Take a first sample, leaving nPENIRQ active and vREF off; avoid 1381 1394 * the touchscreen, in case it's not connected. 1382 1395 */ 1383 1396 if (ts->model == 7845) 1384 - ads7845_read12_ser(&spi->dev, PWRDOWN); 1397 + ads7845_read12_ser(dev, PWRDOWN); 1385 1398 else 1386 - (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux)); 1399 + (void) ads7846_read12_ser(dev, READ_12BIT_SER(vaux)); 1387 1400 1388 - err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); 1401 + err = devm_device_add_group(dev, &ads784x_attr_group); 1389 1402 if (err) 1390 - goto err_remove_hwmon; 1403 + return err; 1391 1404 1392 1405 err = input_register_device(input_dev); 1393 1406 if (err) 1394 - goto err_remove_attr_group; 1407 + return err; 1395 1408 1396 - device_init_wakeup(&spi->dev, pdata->wakeup); 1409 + device_init_wakeup(dev, pdata->wakeup); 1397 1410 1398 1411 /* 1399 1412 * If device does not carry platform data we must have allocated it 1400 1413 * when parsing DT data. 1401 1414 */ 1402 - if (!dev_get_platdata(&spi->dev)) 1403 - devm_kfree(&spi->dev, (void *)pdata); 1415 + if (!dev_get_platdata(dev)) 1416 + devm_kfree(dev, (void *)pdata); 1404 1417 1405 1418 return 0; 1406 - 1407 - err_remove_attr_group: 1408 - sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); 1409 - err_remove_hwmon: 1410 - ads784x_hwmon_unregister(spi, ts); 1411 - err_free_irq: 1412 - free_irq(spi->irq, ts); 1413 - err_disable_regulator: 1414 - regulator_disable(ts->reg); 1415 - err_put_regulator: 1416 - regulator_put(ts->reg); 1417 - err_free_gpio: 1418 - if (!ts->get_pendown_state) 1419 - gpio_free(ts->gpio_pendown); 1420 - err_cleanup_filter: 1421 - if (ts->filter_cleanup) 1422 - ts->filter_cleanup(ts->filter_data); 1423 - err_free_mem: 1424 - input_free_device(input_dev); 1425 - kfree(packet); 1426 - kfree(ts); 1427 - return err; 1428 1419 } 1429 1420 1430 1421 static int ads7846_remove(struct spi_device *spi) 1431 1422 { 1432 1423 struct ads7846 *ts = spi_get_drvdata(spi); 1433 1424 1434 - sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); 1435 - 1436 - ads7846_disable(ts); 1437 - free_irq(ts->spi->irq, ts); 1438 - 1439 - input_unregister_device(ts->input); 1440 - 1441 - ads784x_hwmon_unregister(spi, ts); 1442 - 1443 - regulator_put(ts->reg); 1444 - 1445 - if (!ts->get_pendown_state) { 1446 - /* 1447 - * If we are not using specialized pendown method we must 1448 - * have been relying on gpio we set up ourselves. 1449 - */ 1450 - gpio_free(ts->gpio_pendown); 1451 - } 1452 - 1453 - if (ts->filter_cleanup) 1454 - ts->filter_cleanup(ts->filter_data); 1455 - 1456 - kfree(ts->packet); 1457 - kfree(ts); 1458 - 1459 - dev_dbg(&spi->dev, "unregistered touchscreen\n"); 1425 + ads7846_stop(ts); 1460 1426 1461 1427 return 0; 1462 1428 }
+2 -2
drivers/input/touchscreen/elants_i2c.c
··· 1439 1439 if (error) 1440 1440 return error; 1441 1441 1442 - error = devm_add_action(&client->dev, elants_i2c_power_off, ts); 1442 + error = devm_add_action_or_reset(&client->dev, 1443 + elants_i2c_power_off, ts); 1443 1444 if (error) { 1444 1445 dev_err(&client->dev, 1445 1446 "failed to install power off action: %d\n", error); 1446 - elants_i2c_power_off(ts); 1447 1447 return error; 1448 1448 } 1449 1449
+126 -145
drivers/input/touchscreen/goodix.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/dmi.h> 16 16 #include <linux/firmware.h> 17 - #include <linux/gpio/consumer.h> 18 - #include <linux/i2c.h> 19 - #include <linux/input.h> 20 - #include <linux/input/mt.h> 21 - #include <linux/input/touchscreen.h> 22 17 #include <linux/module.h> 23 18 #include <linux/delay.h> 24 19 #include <linux/irq.h> 25 20 #include <linux/interrupt.h> 26 - #include <linux/regulator/consumer.h> 27 21 #include <linux/slab.h> 28 22 #include <linux/acpi.h> 29 23 #include <linux/of.h> 30 24 #include <asm/unaligned.h> 25 + #include "goodix.h" 31 26 32 27 #define GOODIX_GPIO_INT_NAME "irq" 33 28 #define GOODIX_GPIO_RST_NAME "reset" ··· 33 38 #define GOODIX_CONTACT_SIZE 8 34 39 #define GOODIX_MAX_CONTACT_SIZE 9 35 40 #define GOODIX_MAX_CONTACTS 10 36 - #define GOODIX_MAX_KEYS 7 37 41 38 42 #define GOODIX_CONFIG_MIN_LENGTH 186 39 43 #define GOODIX_CONFIG_911_LENGTH 186 40 44 #define GOODIX_CONFIG_967_LENGTH 228 41 45 #define GOODIX_CONFIG_GT9X_LENGTH 240 42 - #define GOODIX_CONFIG_MAX_LENGTH 240 43 - 44 - /* Register defines */ 45 - #define GOODIX_REG_COMMAND 0x8040 46 - #define GOODIX_CMD_SCREEN_OFF 0x05 47 - 48 - #define GOODIX_READ_COOR_ADDR 0x814E 49 - #define GOODIX_GT1X_REG_CONFIG_DATA 0x8050 50 - #define GOODIX_GT9X_REG_CONFIG_DATA 0x8047 51 - #define GOODIX_REG_ID 0x8140 52 46 53 47 #define GOODIX_BUFFER_STATUS_READY BIT(7) 54 48 #define GOODIX_HAVE_KEY BIT(4) ··· 52 68 #define ACPI_GPIO_SUPPORT 53 69 #endif 54 70 55 - struct goodix_ts_data; 56 - 57 - enum goodix_irq_pin_access_method { 58 - IRQ_PIN_ACCESS_NONE, 59 - IRQ_PIN_ACCESS_GPIO, 60 - IRQ_PIN_ACCESS_ACPI_GPIO, 61 - IRQ_PIN_ACCESS_ACPI_METHOD, 62 - }; 63 - 64 - struct goodix_chip_data { 65 - u16 config_addr; 66 - int config_len; 67 - int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len); 68 - void (*calc_config_checksum)(struct goodix_ts_data *ts); 69 - }; 70 - 71 71 struct goodix_chip_id { 72 72 const char *id; 73 73 const struct goodix_chip_data *data; 74 - }; 75 - 76 - #define GOODIX_ID_MAX_LEN 4 77 - 78 - struct goodix_ts_data { 79 - struct i2c_client *client; 80 - struct input_dev *input_dev; 81 - const struct goodix_chip_data *chip; 82 - struct touchscreen_properties prop; 83 - unsigned int max_touch_num; 84 - unsigned int int_trigger_type; 85 - struct regulator *avdd28; 86 - struct regulator *vddio; 87 - struct gpio_desc *gpiod_int; 88 - struct gpio_desc *gpiod_rst; 89 - int gpio_count; 90 - int gpio_int_idx; 91 - char id[GOODIX_ID_MAX_LEN + 1]; 92 - u16 version; 93 - const char *cfg_name; 94 - bool reset_controller_at_probe; 95 - bool load_cfg_from_disk; 96 - struct completion firmware_loading_complete; 97 - unsigned long irq_flags; 98 - enum goodix_irq_pin_access_method irq_pin_access_method; 99 - unsigned int contact_size; 100 - u8 config[GOODIX_CONFIG_MAX_LENGTH]; 101 - unsigned short keymap[GOODIX_MAX_KEYS]; 102 74 }; 103 75 104 76 static int goodix_check_cfg_8(struct goodix_ts_data *ts, ··· 200 260 * @buf: raw write data buffer. 201 261 * @len: length of the buffer to write 202 262 */ 203 - static int goodix_i2c_read(struct i2c_client *client, 204 - u16 reg, u8 *buf, int len) 263 + int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len) 205 264 { 206 265 struct i2c_msg msgs[2]; 207 266 __be16 wbuf = cpu_to_be16(reg); ··· 217 278 msgs[1].buf = buf; 218 279 219 280 ret = i2c_transfer(client->adapter, msgs, 2); 220 - return ret < 0 ? ret : (ret != ARRAY_SIZE(msgs) ? -EIO : 0); 281 + if (ret >= 0) 282 + ret = (ret == ARRAY_SIZE(msgs) ? 0 : -EIO); 283 + 284 + if (ret) 285 + dev_err(&client->dev, "Error reading %d bytes from 0x%04x: %d\n", 286 + len, reg, ret); 287 + return ret; 221 288 } 222 289 223 290 /** ··· 234 289 * @buf: raw data buffer to write. 235 290 * @len: length of the buffer to write 236 291 */ 237 - static int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, 238 - unsigned len) 292 + int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len) 239 293 { 240 294 u8 *addr_buf; 241 295 struct i2c_msg msg; ··· 254 310 msg.len = len + 2; 255 311 256 312 ret = i2c_transfer(client->adapter, &msg, 1); 313 + if (ret >= 0) 314 + ret = (ret == 1 ? 0 : -EIO); 315 + 257 316 kfree(addr_buf); 258 - return ret < 0 ? ret : (ret != 1 ? -EIO : 0); 317 + 318 + if (ret) 319 + dev_err(&client->dev, "Error writing %d bytes to 0x%04x: %d\n", 320 + len, reg, ret); 321 + return ret; 259 322 } 260 323 261 - static int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value) 324 + int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value) 262 325 { 263 326 return goodix_i2c_write(client, reg, &value, sizeof(value)); 264 327 } ··· 304 353 do { 305 354 error = goodix_i2c_read(ts->client, addr, data, 306 355 header_contact_keycode_size); 307 - if (error) { 308 - dev_err(&ts->client->dev, "I2C transfer error: %d\n", 309 - error); 356 + if (error) 310 357 return error; 311 - } 312 358 313 359 if (data[0] & GOODIX_BUFFER_STATUS_READY) { 314 360 touch_num = data[0] & 0x0f; ··· 324 376 } 325 377 326 378 return touch_num; 379 + } 380 + 381 + if (data[0] == 0 && ts->firmware_name) { 382 + if (goodix_handle_fw_request(ts)) 383 + return 0; 327 384 } 328 385 329 386 usleep_range(1000, 2000); /* Poll every 1 - 2 ms */ ··· 433 480 struct goodix_ts_data *ts = dev_id; 434 481 435 482 goodix_process_events(ts); 436 - 437 - if (goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0) < 0) 438 - dev_err(&ts->client->dev, "I2C write end_cmd error\n"); 483 + goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0); 439 484 440 485 return IRQ_HANDLED; 441 486 } ··· 549 598 * @cfg: config firmware to write to device 550 599 * @len: config data length 551 600 */ 552 - static int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len) 601 + int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len) 553 602 { 554 603 int error; 555 604 ··· 558 607 return error; 559 608 560 609 error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg, len); 561 - if (error) { 562 - dev_err(&ts->client->dev, "Failed to write config data: %d", 563 - error); 610 + if (error) 564 611 return error; 565 - } 612 + 566 613 dev_dbg(&ts->client->dev, "Config sent successfully."); 567 614 568 615 /* Let the firmware reconfigure itself, so sleep for 10ms */ ··· 645 696 return -EINVAL; /* Never reached */ 646 697 } 647 698 648 - static int goodix_int_sync(struct goodix_ts_data *ts) 699 + int goodix_int_sync(struct goodix_ts_data *ts) 649 700 { 650 701 int error; 651 702 652 703 error = goodix_irq_direction_output(ts, 0); 653 704 if (error) 654 - return error; 705 + goto error; 655 706 656 707 msleep(50); /* T5: 50ms */ 657 708 658 709 error = goodix_irq_direction_input(ts); 659 710 if (error) 660 - return error; 711 + goto error; 661 712 662 713 return 0; 714 + 715 + error: 716 + dev_err(&ts->client->dev, "Controller irq sync failed.\n"); 717 + return error; 718 + } 719 + 720 + /** 721 + * goodix_reset_no_int_sync - Reset device, leaving interrupt line in output mode 722 + * 723 + * @ts: goodix_ts_data pointer 724 + */ 725 + int goodix_reset_no_int_sync(struct goodix_ts_data *ts) 726 + { 727 + int error; 728 + 729 + /* begin select I2C slave addr */ 730 + error = gpiod_direction_output(ts->gpiod_rst, 0); 731 + if (error) 732 + goto error; 733 + 734 + msleep(20); /* T2: > 10ms */ 735 + 736 + /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ 737 + error = goodix_irq_direction_output(ts, ts->client->addr == 0x14); 738 + if (error) 739 + goto error; 740 + 741 + usleep_range(100, 2000); /* T3: > 100us */ 742 + 743 + error = gpiod_direction_output(ts->gpiod_rst, 1); 744 + if (error) 745 + goto error; 746 + 747 + usleep_range(6000, 10000); /* T4: > 5ms */ 748 + 749 + /* end select I2C slave addr */ 750 + error = gpiod_direction_input(ts->gpiod_rst); 751 + if (error) 752 + goto error; 753 + 754 + return 0; 755 + 756 + error: 757 + dev_err(&ts->client->dev, "Controller reset failed.\n"); 758 + return error; 663 759 } 664 760 665 761 /** ··· 716 722 { 717 723 int error; 718 724 719 - /* begin select I2C slave addr */ 720 - error = gpiod_direction_output(ts->gpiod_rst, 0); 725 + error = goodix_reset_no_int_sync(ts); 721 726 if (error) 722 727 return error; 723 728 724 - msleep(20); /* T2: > 10ms */ 725 - 726 - /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */ 727 - error = goodix_irq_direction_output(ts, ts->client->addr == 0x14); 728 - if (error) 729 - return error; 730 - 731 - usleep_range(100, 2000); /* T3: > 100us */ 732 - 733 - error = gpiod_direction_output(ts->gpiod_rst, 1); 734 - if (error) 735 - return error; 736 - 737 - usleep_range(6000, 10000); /* T4: > 5ms */ 738 - 739 - /* end select I2C slave addr */ 740 - error = gpiod_direction_input(ts->gpiod_rst); 741 - if (error) 742 - return error; 743 - 744 - error = goodix_int_sync(ts); 745 - if (error) 746 - return error; 747 - 748 - return 0; 729 + return goodix_int_sync(ts); 749 730 } 750 731 751 732 #ifdef ACPI_GPIO_SUPPORT ··· 945 976 int x_max, y_max; 946 977 int error; 947 978 948 - error = goodix_i2c_read(ts->client, ts->chip->config_addr, 949 - ts->config, ts->chip->config_len); 950 - if (error) { 951 - dev_warn(&ts->client->dev, "Error reading config: %d\n", 952 - error); 953 - ts->int_trigger_type = GOODIX_INT_TRIGGER; 954 - ts->max_touch_num = GOODIX_MAX_CONTACTS; 955 - return; 979 + /* 980 + * On controllers where we need to upload the firmware 981 + * (controllers without flash) ts->config already has the config 982 + * at this point and the controller itself does not have it yet! 983 + */ 984 + if (!ts->firmware_name) { 985 + error = goodix_i2c_read(ts->client, ts->chip->config_addr, 986 + ts->config, ts->chip->config_len); 987 + if (error) { 988 + ts->int_trigger_type = GOODIX_INT_TRIGGER; 989 + ts->max_touch_num = GOODIX_MAX_CONTACTS; 990 + return; 991 + } 956 992 } 957 993 958 994 ts->int_trigger_type = ts->config[TRIGGER_LOC] & 0x03; ··· 985 1011 char id_str[GOODIX_ID_MAX_LEN + 1]; 986 1012 987 1013 error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf)); 988 - if (error) { 989 - dev_err(&ts->client->dev, "read version failed: %d\n", error); 1014 + if (error) 990 1015 return error; 991 - } 992 1016 993 1017 memcpy(id_str, buf, GOODIX_ID_MAX_LEN); 994 1018 id_str[GOODIX_ID_MAX_LEN] = 0; ··· 1012 1040 u8 test; 1013 1041 1014 1042 while (retry++ < 2) { 1015 - error = goodix_i2c_read(client, GOODIX_REG_ID, 1016 - &test, 1); 1043 + error = goodix_i2c_read(client, GOODIX_REG_ID, &test, 1); 1017 1044 if (!error) 1018 1045 return 0; 1019 1046 1020 - dev_err(&client->dev, "i2c test failed attempt %d: %d\n", 1021 - retry, error); 1022 1047 msleep(20); 1023 1048 } 1024 1049 ··· 1151 1182 struct goodix_ts_data *ts = ctx; 1152 1183 int error; 1153 1184 1154 - if (cfg) { 1185 + if (ts->firmware_name) { 1186 + if (!cfg) 1187 + goto err_release_cfg; 1188 + 1189 + error = goodix_check_cfg(ts, cfg->data, cfg->size); 1190 + if (error) 1191 + goto err_release_cfg; 1192 + 1193 + memcpy(ts->config, cfg->data, cfg->size); 1194 + } else if (cfg) { 1155 1195 /* send device configuration to the firmware */ 1156 1196 error = goodix_send_cfg(ts, cfg->data, cfg->size); 1157 1197 if (error) ··· 1186 1208 const struct i2c_device_id *id) 1187 1209 { 1188 1210 struct goodix_ts_data *ts; 1211 + const char *cfg_name; 1189 1212 int error; 1190 1213 1191 1214 dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr); ··· 1236 1257 if (ts->reset_controller_at_probe) { 1237 1258 /* reset the controller */ 1238 1259 error = goodix_reset(ts); 1239 - if (error) { 1240 - dev_err(&client->dev, "Controller reset failed.\n"); 1260 + if (error) 1241 1261 return error; 1242 - } 1243 1262 } 1244 1263 1245 1264 error = goodix_i2c_test(client); ··· 1252 1275 return error; 1253 1276 } 1254 1277 1255 - error = goodix_read_version(ts); 1256 - if (error) { 1257 - dev_err(&client->dev, "Read version failed.\n"); 1278 + error = goodix_firmware_check(ts); 1279 + if (error) 1258 1280 return error; 1259 - } 1281 + 1282 + error = goodix_read_version(ts); 1283 + if (error) 1284 + return error; 1260 1285 1261 1286 ts->chip = goodix_get_chip_data(ts->id); 1262 1287 1263 1288 if (ts->load_cfg_from_disk) { 1264 1289 /* update device config */ 1265 - ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL, 1266 - "goodix_%s_cfg.bin", ts->id); 1267 - if (!ts->cfg_name) 1268 - return -ENOMEM; 1290 + error = device_property_read_string(&client->dev, 1291 + "goodix,config-name", 1292 + &cfg_name); 1293 + if (!error) 1294 + snprintf(ts->cfg_name, sizeof(ts->cfg_name), 1295 + "goodix/%s", cfg_name); 1296 + else 1297 + snprintf(ts->cfg_name, sizeof(ts->cfg_name), 1298 + "goodix_%s_cfg.bin", ts->id); 1269 1299 1270 1300 error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name, 1271 1301 &client->dev, GFP_KERNEL, ts, ··· 1322 1338 /* Free IRQ as IRQ pin is used as output in the suspend sequence */ 1323 1339 goodix_free_irq(ts); 1324 1340 1341 + /* Save reference (calibration) info if necessary */ 1342 + goodix_save_bak_ref(ts); 1343 + 1325 1344 /* Output LOW on the INT pin for 5 ms */ 1326 1345 error = goodix_irq_direction_output(ts, 0); 1327 1346 if (error) { ··· 1337 1350 error = goodix_i2c_write_u8(ts->client, GOODIX_REG_COMMAND, 1338 1351 GOODIX_CMD_SCREEN_OFF); 1339 1352 if (error) { 1340 - dev_err(&ts->client->dev, "Screen off command failed\n"); 1341 1353 goodix_irq_direction_input(ts); 1342 1354 goodix_request_irq(ts); 1343 1355 return -EAGAIN; ··· 1379 1393 1380 1394 error = goodix_i2c_read(ts->client, ts->chip->config_addr, 1381 1395 &config_ver, 1); 1382 - if (error) 1383 - dev_warn(dev, "Error reading config version: %d, resetting controller\n", 1384 - error); 1385 - else if (config_ver != ts->config[0]) 1396 + if (!error && config_ver != ts->config[0]) 1386 1397 dev_info(dev, "Config version mismatch %d != %d, resetting controller\n", 1387 1398 config_ver, ts->config[0]); 1388 1399 1389 1400 if (error != 0 || config_ver != ts->config[0]) { 1390 1401 error = goodix_reset(ts); 1391 - if (error) { 1392 - dev_err(dev, "Controller reset failed.\n"); 1402 + if (error) 1393 1403 return error; 1394 - } 1395 1404 1396 1405 error = goodix_send_cfg(ts, ts->config, ts->chip->config_len); 1397 1406 if (error)
+117
drivers/input/touchscreen/goodix.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + #ifndef __GOODIX_H__ 3 + #define __GOODIX_H__ 4 + 5 + #include <linux/gpio/consumer.h> 6 + #include <linux/i2c.h> 7 + #include <linux/input.h> 8 + #include <linux/input/mt.h> 9 + #include <linux/input/touchscreen.h> 10 + #include <linux/regulator/consumer.h> 11 + 12 + /* Register defines */ 13 + #define GOODIX_REG_MISCTL_DSP_CTL 0x4010 14 + #define GOODIX_REG_MISCTL_SRAM_BANK 0x4048 15 + #define GOODIX_REG_MISCTL_MEM_CD_EN 0x4049 16 + #define GOODIX_REG_MISCTL_CACHE_EN 0x404B 17 + #define GOODIX_REG_MISCTL_TMR0_EN 0x40B0 18 + #define GOODIX_REG_MISCTL_SWRST 0x4180 19 + #define GOODIX_REG_MISCTL_CPU_SWRST_PULSE 0x4184 20 + #define GOODIX_REG_MISCTL_BOOTCTL 0x4190 21 + #define GOODIX_REG_MISCTL_BOOT_OPT 0x4218 22 + #define GOODIX_REG_MISCTL_BOOT_CTL 0x5094 23 + 24 + #define GOODIX_REG_FW_SIG 0x8000 25 + #define GOODIX_FW_SIG_LEN 10 26 + 27 + #define GOODIX_REG_MAIN_CLK 0x8020 28 + #define GOODIX_MAIN_CLK_LEN 6 29 + 30 + #define GOODIX_REG_COMMAND 0x8040 31 + #define GOODIX_CMD_SCREEN_OFF 0x05 32 + 33 + #define GOODIX_REG_SW_WDT 0x8041 34 + 35 + #define GOODIX_REG_REQUEST 0x8043 36 + #define GOODIX_RQST_RESPONDED 0x00 37 + #define GOODIX_RQST_CONFIG 0x01 38 + #define GOODIX_RQST_BAK_REF 0x02 39 + #define GOODIX_RQST_RESET 0x03 40 + #define GOODIX_RQST_MAIN_CLOCK 0x04 41 + /* 42 + * Unknown request which gets send by the controller aprox. 43 + * every 34 seconds once it is up and running. 44 + */ 45 + #define GOODIX_RQST_UNKNOWN 0x06 46 + #define GOODIX_RQST_IDLE 0xFF 47 + 48 + #define GOODIX_REG_STATUS 0x8044 49 + 50 + #define GOODIX_GT1X_REG_CONFIG_DATA 0x8050 51 + #define GOODIX_GT9X_REG_CONFIG_DATA 0x8047 52 + #define GOODIX_REG_ID 0x8140 53 + #define GOODIX_READ_COOR_ADDR 0x814E 54 + #define GOODIX_REG_BAK_REF 0x99D0 55 + 56 + #define GOODIX_ID_MAX_LEN 4 57 + #define GOODIX_CONFIG_MAX_LENGTH 240 58 + #define GOODIX_MAX_KEYS 7 59 + 60 + enum goodix_irq_pin_access_method { 61 + IRQ_PIN_ACCESS_NONE, 62 + IRQ_PIN_ACCESS_GPIO, 63 + IRQ_PIN_ACCESS_ACPI_GPIO, 64 + IRQ_PIN_ACCESS_ACPI_METHOD, 65 + }; 66 + 67 + struct goodix_ts_data; 68 + 69 + struct goodix_chip_data { 70 + u16 config_addr; 71 + int config_len; 72 + int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len); 73 + void (*calc_config_checksum)(struct goodix_ts_data *ts); 74 + }; 75 + 76 + struct goodix_ts_data { 77 + struct i2c_client *client; 78 + struct input_dev *input_dev; 79 + const struct goodix_chip_data *chip; 80 + const char *firmware_name; 81 + struct touchscreen_properties prop; 82 + unsigned int max_touch_num; 83 + unsigned int int_trigger_type; 84 + struct regulator *avdd28; 85 + struct regulator *vddio; 86 + struct gpio_desc *gpiod_int; 87 + struct gpio_desc *gpiod_rst; 88 + int gpio_count; 89 + int gpio_int_idx; 90 + char id[GOODIX_ID_MAX_LEN + 1]; 91 + char cfg_name[64]; 92 + u16 version; 93 + bool reset_controller_at_probe; 94 + bool load_cfg_from_disk; 95 + struct completion firmware_loading_complete; 96 + unsigned long irq_flags; 97 + enum goodix_irq_pin_access_method irq_pin_access_method; 98 + unsigned int contact_size; 99 + u8 config[GOODIX_CONFIG_MAX_LENGTH]; 100 + unsigned short keymap[GOODIX_MAX_KEYS]; 101 + u8 main_clk[GOODIX_MAIN_CLK_LEN]; 102 + int bak_ref_len; 103 + u8 *bak_ref; 104 + }; 105 + 106 + int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len); 107 + int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf, int len); 108 + int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value); 109 + int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len); 110 + int goodix_int_sync(struct goodix_ts_data *ts); 111 + int goodix_reset_no_int_sync(struct goodix_ts_data *ts); 112 + 113 + int goodix_firmware_check(struct goodix_ts_data *ts); 114 + bool goodix_handle_fw_request(struct goodix_ts_data *ts); 115 + void goodix_save_bak_ref(struct goodix_ts_data *ts); 116 + 117 + #endif
+427
drivers/input/touchscreen/goodix_fwupload.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Goodix Touchscreen firmware upload support 4 + * 5 + * Copyright (c) 2021 Hans de Goede <hdegoede@redhat.com> 6 + * 7 + * This is a rewrite of gt9xx_update.c from the Allwinner H3 BSP which is: 8 + * Copyright (c) 2010 - 2012 Goodix Technology. 9 + * Author: andrew@goodix.com 10 + */ 11 + 12 + #include <linux/device.h> 13 + #include <linux/firmware.h> 14 + #include <linux/i2c.h> 15 + #include "goodix.h" 16 + 17 + #define GOODIX_FW_HEADER_LENGTH sizeof(struct goodix_fw_header) 18 + #define GOODIX_FW_SECTION_LENGTH 0x2000 19 + #define GOODIX_FW_DSP_LENGTH 0x1000 20 + #define GOODIX_FW_UPLOAD_ADDRESS 0xc000 21 + 22 + #define GOODIX_CFG_LOC_HAVE_KEY 7 23 + #define GOODIX_CFG_LOC_DRVA_NUM 27 24 + #define GOODIX_CFG_LOC_DRVB_NUM 28 25 + #define GOODIX_CFG_LOC_SENS_NUM 29 26 + 27 + struct goodix_fw_header { 28 + u8 hw_info[4]; 29 + u8 pid[8]; 30 + u8 vid[2]; 31 + } __packed; 32 + 33 + static u16 goodix_firmware_checksum(const u8 *data, int size) 34 + { 35 + u16 checksum = 0; 36 + int i; 37 + 38 + for (i = 0; i < size; i += 2) 39 + checksum += (data[i] << 8) + data[i + 1]; 40 + 41 + return checksum; 42 + } 43 + 44 + static int goodix_firmware_verify(struct device *dev, const struct firmware *fw) 45 + { 46 + const struct goodix_fw_header *fw_header; 47 + size_t expected_size; 48 + const u8 *data; 49 + u16 checksum; 50 + char buf[9]; 51 + 52 + expected_size = GOODIX_FW_HEADER_LENGTH + 4 * GOODIX_FW_SECTION_LENGTH + 53 + GOODIX_FW_DSP_LENGTH; 54 + if (fw->size != expected_size) { 55 + dev_err(dev, "Firmware has wrong size, expected %zu got %zu\n", 56 + expected_size, fw->size); 57 + return -EINVAL; 58 + } 59 + 60 + data = fw->data + GOODIX_FW_HEADER_LENGTH; 61 + checksum = goodix_firmware_checksum(data, 4 * GOODIX_FW_SECTION_LENGTH); 62 + if (checksum) { 63 + dev_err(dev, "Main firmware checksum error\n"); 64 + return -EINVAL; 65 + } 66 + 67 + data += 4 * GOODIX_FW_SECTION_LENGTH; 68 + checksum = goodix_firmware_checksum(data, GOODIX_FW_DSP_LENGTH); 69 + if (checksum) { 70 + dev_err(dev, "DSP firmware checksum error\n"); 71 + return -EINVAL; 72 + } 73 + 74 + fw_header = (const struct goodix_fw_header *)fw->data; 75 + dev_info(dev, "Firmware hardware info %02x%02x%02x%02x\n", 76 + fw_header->hw_info[0], fw_header->hw_info[1], 77 + fw_header->hw_info[2], fw_header->hw_info[3]); 78 + /* pid is a 8 byte buffer containing a string, weird I know */ 79 + memcpy(buf, fw_header->pid, 8); 80 + buf[8] = 0; 81 + dev_info(dev, "Firmware PID: %s VID: %02x%02x\n", buf, 82 + fw_header->vid[0], fw_header->vid[1]); 83 + return 0; 84 + } 85 + 86 + static int goodix_enter_upload_mode(struct i2c_client *client) 87 + { 88 + int tries, error; 89 + u8 val; 90 + 91 + tries = 200; 92 + do { 93 + error = goodix_i2c_write_u8(client, 94 + GOODIX_REG_MISCTL_SWRST, 0x0c); 95 + if (error) 96 + return error; 97 + 98 + error = goodix_i2c_read(client, 99 + GOODIX_REG_MISCTL_SWRST, &val, 1); 100 + if (error) 101 + return error; 102 + 103 + if (val == 0x0c) 104 + break; 105 + } while (--tries); 106 + 107 + if (!tries) { 108 + dev_err(&client->dev, "Error could not hold ss51 & dsp\n"); 109 + return -EIO; 110 + } 111 + 112 + /* DSP_CK and DSP_ALU_CK PowerOn */ 113 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_DSP_CTL, 0x00); 114 + if (error) 115 + return error; 116 + 117 + /* Disable watchdog */ 118 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_TMR0_EN, 0x00); 119 + if (error) 120 + return error; 121 + 122 + /* Clear cache enable */ 123 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_CACHE_EN, 0x00); 124 + if (error) 125 + return error; 126 + 127 + /* Set boot from SRAM */ 128 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_BOOTCTL, 0x02); 129 + if (error) 130 + return error; 131 + 132 + /* Software reboot */ 133 + error = goodix_i2c_write_u8(client, 134 + GOODIX_REG_MISCTL_CPU_SWRST_PULSE, 0x01); 135 + if (error) 136 + return error; 137 + 138 + /* Clear control flag */ 139 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_BOOTCTL, 0x00); 140 + if (error) 141 + return error; 142 + 143 + /* Set scramble */ 144 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_BOOT_OPT, 0x00); 145 + if (error) 146 + return error; 147 + 148 + /* Enable accessing code */ 149 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_MEM_CD_EN, 0x01); 150 + if (error) 151 + return error; 152 + 153 + return 0; 154 + } 155 + 156 + static int goodix_start_firmware(struct i2c_client *client) 157 + { 158 + int error; 159 + u8 val; 160 + 161 + /* Init software watchdog */ 162 + error = goodix_i2c_write_u8(client, GOODIX_REG_SW_WDT, 0xaa); 163 + if (error) 164 + return error; 165 + 166 + /* Release SS51 & DSP */ 167 + error = goodix_i2c_write_u8(client, GOODIX_REG_MISCTL_SWRST, 0x00); 168 + if (error) 169 + return error; 170 + 171 + error = goodix_i2c_read(client, GOODIX_REG_SW_WDT, &val, 1); 172 + if (error) 173 + return error; 174 + 175 + /* The value we've written to SW_WDT should have been cleared now */ 176 + if (val == 0xaa) { 177 + dev_err(&client->dev, "Error SW_WDT reg not cleared on fw startup\n"); 178 + return -EIO; 179 + } 180 + 181 + /* Re-init software watchdog */ 182 + error = goodix_i2c_write_u8(client, GOODIX_REG_SW_WDT, 0xaa); 183 + if (error) 184 + return error; 185 + 186 + return 0; 187 + } 188 + 189 + static int goodix_firmware_upload(struct goodix_ts_data *ts) 190 + { 191 + const struct firmware *fw; 192 + char fw_name[64]; 193 + const u8 *data; 194 + int error; 195 + 196 + snprintf(fw_name, sizeof(fw_name), "goodix/%s", ts->firmware_name); 197 + 198 + error = request_firmware(&fw, fw_name, &ts->client->dev); 199 + if (error) { 200 + dev_err(&ts->client->dev, "Firmware request error %d\n", error); 201 + return error; 202 + } 203 + 204 + error = goodix_firmware_verify(&ts->client->dev, fw); 205 + if (error) 206 + goto release; 207 + 208 + error = goodix_reset_no_int_sync(ts); 209 + if (error) 210 + return error; 211 + 212 + error = goodix_enter_upload_mode(ts->client); 213 + if (error) 214 + goto release; 215 + 216 + /* Select SRAM bank 0 and upload section 1 & 2 */ 217 + error = goodix_i2c_write_u8(ts->client, 218 + GOODIX_REG_MISCTL_SRAM_BANK, 0x00); 219 + if (error) 220 + goto release; 221 + 222 + data = fw->data + GOODIX_FW_HEADER_LENGTH; 223 + error = goodix_i2c_write(ts->client, GOODIX_FW_UPLOAD_ADDRESS, 224 + data, 2 * GOODIX_FW_SECTION_LENGTH); 225 + if (error) 226 + goto release; 227 + 228 + /* Select SRAM bank 1 and upload section 3 & 4 */ 229 + error = goodix_i2c_write_u8(ts->client, 230 + GOODIX_REG_MISCTL_SRAM_BANK, 0x01); 231 + if (error) 232 + goto release; 233 + 234 + data += 2 * GOODIX_FW_SECTION_LENGTH; 235 + error = goodix_i2c_write(ts->client, GOODIX_FW_UPLOAD_ADDRESS, 236 + data, 2 * GOODIX_FW_SECTION_LENGTH); 237 + if (error) 238 + goto release; 239 + 240 + /* Select SRAM bank 2 and upload the DSP firmware */ 241 + error = goodix_i2c_write_u8(ts->client, 242 + GOODIX_REG_MISCTL_SRAM_BANK, 0x02); 243 + if (error) 244 + goto release; 245 + 246 + data += 2 * GOODIX_FW_SECTION_LENGTH; 247 + error = goodix_i2c_write(ts->client, GOODIX_FW_UPLOAD_ADDRESS, 248 + data, GOODIX_FW_DSP_LENGTH); 249 + if (error) 250 + goto release; 251 + 252 + error = goodix_start_firmware(ts->client); 253 + if (error) 254 + goto release; 255 + 256 + error = goodix_int_sync(ts); 257 + release: 258 + release_firmware(fw); 259 + return error; 260 + } 261 + 262 + static int goodix_prepare_bak_ref(struct goodix_ts_data *ts) 263 + { 264 + u8 have_key, driver_num, sensor_num; 265 + 266 + if (ts->bak_ref) 267 + return 0; /* Already done */ 268 + 269 + have_key = (ts->config[GOODIX_CFG_LOC_HAVE_KEY] & 0x01); 270 + 271 + driver_num = (ts->config[GOODIX_CFG_LOC_DRVA_NUM] & 0x1f) + 272 + (ts->config[GOODIX_CFG_LOC_DRVB_NUM] & 0x1f); 273 + if (have_key) 274 + driver_num--; 275 + 276 + sensor_num = (ts->config[GOODIX_CFG_LOC_SENS_NUM] & 0x0f) + 277 + ((ts->config[GOODIX_CFG_LOC_SENS_NUM] >> 4) & 0x0f); 278 + 279 + dev_dbg(&ts->client->dev, "Drv %d Sen %d Key %d\n", 280 + driver_num, sensor_num, have_key); 281 + 282 + ts->bak_ref_len = (driver_num * (sensor_num - 2) + 2) * 2; 283 + 284 + ts->bak_ref = devm_kzalloc(&ts->client->dev, 285 + ts->bak_ref_len, GFP_KERNEL); 286 + if (!ts->bak_ref) 287 + return -ENOMEM; 288 + 289 + /* 290 + * The bak_ref array contains the backup of an array of (self/auto) 291 + * calibration related values which the Android version of the driver 292 + * stores on the filesystem so that it can be restored after reboot. 293 + * The mainline kernel never writes directly to the filesystem like 294 + * this, we always start will all the values which give a correction 295 + * factor in approx. the -20 - +20 range (in 2s complement) set to 0. 296 + * 297 + * Note the touchscreen works fine without restoring the reference 298 + * values after a reboot / power-cycle. 299 + * 300 + * The last 2 bytes are a 16 bits unsigned checksum which is expected 301 + * to make the addition al all 16 bit unsigned values in the array add 302 + * up to 1 (rather then the usual 0), so we must set the last byte to 1. 303 + */ 304 + ts->bak_ref[ts->bak_ref_len - 1] = 1; 305 + 306 + return 0; 307 + } 308 + 309 + static int goodix_send_main_clock(struct goodix_ts_data *ts) 310 + { 311 + u32 main_clk = 54; /* Default main clock */ 312 + u8 checksum = 0; 313 + int i; 314 + 315 + device_property_read_u32(&ts->client->dev, 316 + "goodix,main-clk", &main_clk); 317 + 318 + for (i = 0; i < (GOODIX_MAIN_CLK_LEN - 1); i++) { 319 + ts->main_clk[i] = main_clk; 320 + checksum += main_clk; 321 + } 322 + 323 + /* The value of all bytes combines must be 0 */ 324 + ts->main_clk[GOODIX_MAIN_CLK_LEN - 1] = 256 - checksum; 325 + 326 + return goodix_i2c_write(ts->client, GOODIX_REG_MAIN_CLK, 327 + ts->main_clk, GOODIX_MAIN_CLK_LEN); 328 + } 329 + 330 + int goodix_firmware_check(struct goodix_ts_data *ts) 331 + { 332 + device_property_read_string(&ts->client->dev, 333 + "firmware-name", &ts->firmware_name); 334 + if (!ts->firmware_name) 335 + return 0; 336 + 337 + if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) { 338 + dev_err(&ts->client->dev, "Error no IRQ-pin access method, cannot upload fw.\n"); 339 + return -EINVAL; 340 + } 341 + 342 + dev_info(&ts->client->dev, "Touchscreen controller needs fw-upload\n"); 343 + ts->load_cfg_from_disk = true; 344 + 345 + return goodix_firmware_upload(ts); 346 + } 347 + 348 + bool goodix_handle_fw_request(struct goodix_ts_data *ts) 349 + { 350 + int error; 351 + u8 val; 352 + 353 + error = goodix_i2c_read(ts->client, GOODIX_REG_REQUEST, &val, 1); 354 + if (error) 355 + return false; 356 + 357 + switch (val) { 358 + case GOODIX_RQST_RESPONDED: 359 + /* 360 + * If we read back our own last ack the IRQ was not for 361 + * a request. 362 + */ 363 + return false; 364 + case GOODIX_RQST_CONFIG: 365 + error = goodix_send_cfg(ts, ts->config, ts->chip->config_len); 366 + if (error) 367 + return false; 368 + 369 + break; 370 + case GOODIX_RQST_BAK_REF: 371 + error = goodix_prepare_bak_ref(ts); 372 + if (error) 373 + return false; 374 + 375 + error = goodix_i2c_write(ts->client, GOODIX_REG_BAK_REF, 376 + ts->bak_ref, ts->bak_ref_len); 377 + if (error) 378 + return false; 379 + 380 + break; 381 + case GOODIX_RQST_RESET: 382 + error = goodix_firmware_upload(ts); 383 + if (error) 384 + return false; 385 + 386 + break; 387 + case GOODIX_RQST_MAIN_CLOCK: 388 + error = goodix_send_main_clock(ts); 389 + if (error) 390 + return false; 391 + 392 + break; 393 + case GOODIX_RQST_UNKNOWN: 394 + case GOODIX_RQST_IDLE: 395 + break; 396 + default: 397 + dev_err_ratelimited(&ts->client->dev, "Unknown Request: 0x%02x\n", val); 398 + } 399 + 400 + /* Ack the request */ 401 + goodix_i2c_write_u8(ts->client, 402 + GOODIX_REG_REQUEST, GOODIX_RQST_RESPONDED); 403 + return true; 404 + } 405 + 406 + void goodix_save_bak_ref(struct goodix_ts_data *ts) 407 + { 408 + int error; 409 + u8 val; 410 + 411 + if (!ts->firmware_name) 412 + return; 413 + 414 + error = goodix_i2c_read(ts->client, GOODIX_REG_STATUS, &val, 1); 415 + if (error) 416 + return; 417 + 418 + if (!(val & 0x80)) 419 + return; 420 + 421 + error = goodix_i2c_read(ts->client, GOODIX_REG_BAK_REF, 422 + ts->bak_ref, ts->bak_ref_len); 423 + if (error) { 424 + memset(ts->bak_ref, 0, ts->bak_ref_len); 425 + ts->bak_ref[ts->bak_ref_len - 1] = 1; 426 + } 427 + }
+548 -11
drivers/input/touchscreen/ili210x.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 + #include <linux/crc-ccitt.h> 2 3 #include <linux/delay.h> 3 4 #include <linux/gpio/consumer.h> 4 5 #include <linux/i2c.h> 6 + #include <linux/ihex.h> 5 7 #include <linux/input.h> 6 8 #include <linux/input/mt.h> 7 9 #include <linux/input/touchscreen.h> ··· 14 12 #include <linux/slab.h> 15 13 #include <asm/unaligned.h> 16 14 17 - #define ILI2XXX_POLL_PERIOD 20 15 + #define ILI2XXX_POLL_PERIOD 15 18 16 19 17 #define ILI210X_DATA_SIZE 64 20 18 #define ILI211X_DATA_SIZE 43 ··· 24 22 /* Touchscreen commands */ 25 23 #define REG_TOUCHDATA 0x10 26 24 #define REG_PANEL_INFO 0x20 25 + #define REG_FIRMWARE_VERSION 0x40 26 + #define REG_PROTOCOL_VERSION 0x42 27 + #define REG_KERNEL_VERSION 0x61 28 + #define REG_IC_BUSY 0x80 29 + #define REG_IC_BUSY_NOT_BUSY 0x50 30 + #define REG_GET_MODE 0xc0 31 + #define REG_GET_MODE_AP 0x5a 32 + #define REG_GET_MODE_BL 0x55 33 + #define REG_SET_MODE_AP 0xc1 34 + #define REG_SET_MODE_BL 0xc2 35 + #define REG_WRITE_DATA 0xc3 36 + #define REG_WRITE_ENABLE 0xc4 37 + #define REG_READ_DATA_CRC 0xc7 27 38 #define REG_CALIBRATE 0xcc 39 + 40 + #define ILI251X_FW_FILENAME "ilitek/ili251x.bin" 28 41 29 42 struct ili2xxx_chip { 30 43 int (*read_reg)(struct i2c_client *client, u8 reg, ··· 52 35 unsigned int max_touches; 53 36 unsigned int resolution; 54 37 bool has_calibrate_reg; 38 + bool has_firmware_proto; 55 39 bool has_pressure_reg; 56 40 }; 57 41 ··· 62 44 struct gpio_desc *reset_gpio; 63 45 struct touchscreen_properties prop; 64 46 const struct ili2xxx_chip *chip; 47 + u8 version_firmware[8]; 48 + u8 version_kernel[5]; 49 + u8 version_proto[2]; 50 + u8 ic_mode[2]; 65 51 bool stop; 66 52 }; 67 53 ··· 224 202 .has_calibrate_reg = true, 225 203 }; 226 204 227 - static int ili251x_read_reg(struct i2c_client *client, 228 - u8 reg, void *buf, size_t len) 205 + static int ili251x_read_reg_common(struct i2c_client *client, 206 + u8 reg, void *buf, size_t len, 207 + unsigned int delay) 229 208 { 230 209 int error; 231 210 int ret; 232 211 233 212 ret = i2c_master_send(client, &reg, 1); 234 213 if (ret == 1) { 235 - usleep_range(5000, 5500); 214 + if (delay) 215 + usleep_range(delay, delay + 500); 236 216 237 217 ret = i2c_master_recv(client, buf, len); 238 218 if (ret == len) ··· 246 222 return ret; 247 223 } 248 224 225 + static int ili251x_read_reg(struct i2c_client *client, 226 + u8 reg, void *buf, size_t len) 227 + { 228 + return ili251x_read_reg_common(client, reg, buf, len, 5000); 229 + } 230 + 249 231 static int ili251x_read_touch_data(struct i2c_client *client, u8 *data) 250 232 { 251 233 int error; 252 234 253 - error = ili251x_read_reg(client, REG_TOUCHDATA, 254 - data, ILI251X_DATA_SIZE1); 235 + error = ili251x_read_reg_common(client, REG_TOUCHDATA, 236 + data, ILI251X_DATA_SIZE1, 0); 255 237 if (!error && data[0] == 2) { 256 238 error = i2c_master_recv(client, data + ILI251X_DATA_SIZE1, 257 239 ILI251X_DATA_SIZE2); ··· 298 268 .continue_polling = ili251x_check_continue_polling, 299 269 .max_touches = 10, 300 270 .has_calibrate_reg = true, 271 + .has_firmware_proto = true, 301 272 .has_pressure_reg = true, 302 273 }; 303 274 ··· 334 303 const struct ili2xxx_chip *chip = priv->chip; 335 304 u8 touchdata[ILI210X_DATA_SIZE] = { 0 }; 336 305 bool keep_polling; 306 + ktime_t time_next; 307 + s64 time_delta; 337 308 bool touch; 338 309 int error; 339 310 340 311 do { 312 + time_next = ktime_add_ms(ktime_get(), ILI2XXX_POLL_PERIOD); 341 313 error = chip->get_touch_data(client, touchdata); 342 314 if (error) { 343 315 dev_err(&client->dev, ··· 350 316 351 317 touch = ili210x_report_events(priv, touchdata); 352 318 keep_polling = chip->continue_polling(touchdata, touch); 353 - if (keep_polling) 354 - msleep(ILI2XXX_POLL_PERIOD); 319 + if (keep_polling) { 320 + time_delta = ktime_us_delta(time_next, ktime_get()); 321 + if (time_delta > 0) 322 + usleep_range(time_delta, time_delta + 1000); 323 + } 355 324 } while (!priv->stop && keep_polling); 356 325 357 326 return IRQ_HANDLED; 358 327 } 328 + 329 + static int ili251x_firmware_update_resolution(struct device *dev) 330 + { 331 + struct i2c_client *client = to_i2c_client(dev); 332 + struct ili210x *priv = i2c_get_clientdata(client); 333 + u16 resx, resy; 334 + u8 rs[10]; 335 + int error; 336 + 337 + /* The firmware update blob might have changed the resolution. */ 338 + error = priv->chip->read_reg(client, REG_PANEL_INFO, &rs, sizeof(rs)); 339 + if (error) 340 + return error; 341 + 342 + resx = le16_to_cpup((__le16 *)rs); 343 + resy = le16_to_cpup((__le16 *)(rs + 2)); 344 + 345 + /* The value reported by the firmware is invalid. */ 346 + if (!resx || resx == 0xffff || !resy || resy == 0xffff) 347 + return -EINVAL; 348 + 349 + input_abs_set_max(priv->input, ABS_X, resx - 1); 350 + input_abs_set_max(priv->input, ABS_Y, resy - 1); 351 + input_abs_set_max(priv->input, ABS_MT_POSITION_X, resx - 1); 352 + input_abs_set_max(priv->input, ABS_MT_POSITION_Y, resy - 1); 353 + 354 + return 0; 355 + } 356 + 357 + static ssize_t ili251x_firmware_update_firmware_version(struct device *dev) 358 + { 359 + struct i2c_client *client = to_i2c_client(dev); 360 + struct ili210x *priv = i2c_get_clientdata(client); 361 + int error; 362 + u8 fw[8]; 363 + 364 + /* Get firmware version */ 365 + error = priv->chip->read_reg(client, REG_FIRMWARE_VERSION, 366 + &fw, sizeof(fw)); 367 + if (!error) 368 + memcpy(priv->version_firmware, fw, sizeof(fw)); 369 + 370 + return error; 371 + } 372 + 373 + static ssize_t ili251x_firmware_update_kernel_version(struct device *dev) 374 + { 375 + struct i2c_client *client = to_i2c_client(dev); 376 + struct ili210x *priv = i2c_get_clientdata(client); 377 + int error; 378 + u8 kv[5]; 379 + 380 + /* Get kernel version */ 381 + error = priv->chip->read_reg(client, REG_KERNEL_VERSION, 382 + &kv, sizeof(kv)); 383 + if (!error) 384 + memcpy(priv->version_kernel, kv, sizeof(kv)); 385 + 386 + return error; 387 + } 388 + 389 + static ssize_t ili251x_firmware_update_protocol_version(struct device *dev) 390 + { 391 + struct i2c_client *client = to_i2c_client(dev); 392 + struct ili210x *priv = i2c_get_clientdata(client); 393 + int error; 394 + u8 pv[2]; 395 + 396 + /* Get protocol version */ 397 + error = priv->chip->read_reg(client, REG_PROTOCOL_VERSION, 398 + &pv, sizeof(pv)); 399 + if (!error) 400 + memcpy(priv->version_proto, pv, sizeof(pv)); 401 + 402 + return error; 403 + } 404 + 405 + static ssize_t ili251x_firmware_update_ic_mode(struct device *dev) 406 + { 407 + struct i2c_client *client = to_i2c_client(dev); 408 + struct ili210x *priv = i2c_get_clientdata(client); 409 + int error; 410 + u8 md[2]; 411 + 412 + /* Get chip boot mode */ 413 + error = priv->chip->read_reg(client, REG_GET_MODE, &md, sizeof(md)); 414 + if (!error) 415 + memcpy(priv->ic_mode, md, sizeof(md)); 416 + 417 + return error; 418 + } 419 + 420 + static int ili251x_firmware_update_cached_state(struct device *dev) 421 + { 422 + struct i2c_client *client = to_i2c_client(dev); 423 + struct ili210x *priv = i2c_get_clientdata(client); 424 + int error; 425 + 426 + if (!priv->chip->has_firmware_proto) 427 + return 0; 428 + 429 + /* Wait for firmware to boot and stabilize itself. */ 430 + msleep(200); 431 + 432 + /* Firmware does report valid information. */ 433 + error = ili251x_firmware_update_resolution(dev); 434 + if (error) 435 + return error; 436 + 437 + error = ili251x_firmware_update_firmware_version(dev); 438 + if (error) 439 + return error; 440 + 441 + error = ili251x_firmware_update_kernel_version(dev); 442 + if (error) 443 + return error; 444 + 445 + error = ili251x_firmware_update_protocol_version(dev); 446 + if (error) 447 + return error; 448 + 449 + error = ili251x_firmware_update_ic_mode(dev); 450 + if (error) 451 + return error; 452 + 453 + return 0; 454 + } 455 + 456 + static ssize_t ili251x_firmware_version_show(struct device *dev, 457 + struct device_attribute *attr, 458 + char *buf) 459 + { 460 + struct i2c_client *client = to_i2c_client(dev); 461 + struct ili210x *priv = i2c_get_clientdata(client); 462 + u8 *fw = priv->version_firmware; 463 + 464 + return sysfs_emit(buf, "%02x%02x.%02x%02x.%02x%02x.%02x%02x\n", 465 + fw[0], fw[1], fw[2], fw[3], 466 + fw[4], fw[5], fw[6], fw[7]); 467 + } 468 + static DEVICE_ATTR(firmware_version, 0444, ili251x_firmware_version_show, NULL); 469 + 470 + static ssize_t ili251x_kernel_version_show(struct device *dev, 471 + struct device_attribute *attr, 472 + char *buf) 473 + { 474 + struct i2c_client *client = to_i2c_client(dev); 475 + struct ili210x *priv = i2c_get_clientdata(client); 476 + u8 *kv = priv->version_kernel; 477 + 478 + return sysfs_emit(buf, "%02x.%02x.%02x.%02x.%02x\n", 479 + kv[0], kv[1], kv[2], kv[3], kv[4]); 480 + } 481 + static DEVICE_ATTR(kernel_version, 0444, ili251x_kernel_version_show, NULL); 482 + 483 + static ssize_t ili251x_protocol_version_show(struct device *dev, 484 + struct device_attribute *attr, 485 + char *buf) 486 + { 487 + struct i2c_client *client = to_i2c_client(dev); 488 + struct ili210x *priv = i2c_get_clientdata(client); 489 + u8 *pv = priv->version_proto; 490 + 491 + return sysfs_emit(buf, "%02x.%02x\n", pv[0], pv[1]); 492 + } 493 + static DEVICE_ATTR(protocol_version, 0444, ili251x_protocol_version_show, NULL); 494 + 495 + static ssize_t ili251x_mode_show(struct device *dev, 496 + struct device_attribute *attr, char *buf) 497 + { 498 + struct i2c_client *client = to_i2c_client(dev); 499 + struct ili210x *priv = i2c_get_clientdata(client); 500 + u8 *md = priv->ic_mode; 501 + char *mode = "AP"; 502 + 503 + if (md[0] == REG_GET_MODE_AP) /* Application Mode */ 504 + mode = "AP"; 505 + else if (md[0] == REG_GET_MODE_BL) /* BootLoader Mode */ 506 + mode = "BL"; 507 + else /* Unknown Mode */ 508 + mode = "??"; 509 + 510 + return sysfs_emit(buf, "%02x.%02x:%s\n", md[0], md[1], mode); 511 + } 512 + static DEVICE_ATTR(mode, 0444, ili251x_mode_show, NULL); 359 513 360 514 static ssize_t ili210x_calibrate(struct device *dev, 361 515 struct device_attribute *attr, ··· 571 349 } 572 350 static DEVICE_ATTR(calibrate, S_IWUSR, NULL, ili210x_calibrate); 573 351 352 + static int ili251x_firmware_to_buffer(const struct firmware *fw, 353 + u8 **buf, u16 *ac_end, u16 *df_end) 354 + { 355 + const struct ihex_binrec *rec; 356 + u32 fw_addr, fw_last_addr = 0; 357 + u16 fw_len; 358 + u8 *fw_buf; 359 + int error; 360 + 361 + /* 362 + * The firmware ihex blob can never be bigger than 64 kiB, so make this 363 + * simple -- allocate a 64 kiB buffer, iterate over the ihex blob records 364 + * once, copy them all into this buffer at the right locations, and then 365 + * do all operations on this linear buffer. 366 + */ 367 + fw_buf = kzalloc(SZ_64K, GFP_KERNEL); 368 + if (!fw_buf) 369 + return -ENOMEM; 370 + 371 + rec = (const struct ihex_binrec *)fw->data; 372 + while (rec) { 373 + fw_addr = be32_to_cpu(rec->addr); 374 + fw_len = be16_to_cpu(rec->len); 375 + 376 + /* The last 32 Byte firmware block can be 0xffe0 */ 377 + if (fw_addr + fw_len > SZ_64K || fw_addr > SZ_64K - 32) { 378 + error = -EFBIG; 379 + goto err_big; 380 + } 381 + 382 + /* Find the last address before DF start address, that is AC end */ 383 + if (fw_addr == 0xf000) 384 + *ac_end = fw_last_addr; 385 + fw_last_addr = fw_addr + fw_len; 386 + 387 + memcpy(fw_buf + fw_addr, rec->data, fw_len); 388 + rec = ihex_next_binrec(rec); 389 + } 390 + 391 + /* DF end address is the last address in the firmware blob */ 392 + *df_end = fw_addr + fw_len; 393 + *buf = fw_buf; 394 + return 0; 395 + 396 + err_big: 397 + kfree(fw_buf); 398 + return error; 399 + } 400 + 401 + /* Switch mode between Application and BootLoader */ 402 + static int ili251x_switch_ic_mode(struct i2c_client *client, u8 cmd_mode) 403 + { 404 + struct ili210x *priv = i2c_get_clientdata(client); 405 + u8 cmd_wren[3] = { REG_WRITE_ENABLE, 0x5a, 0xa5 }; 406 + u8 md[2]; 407 + int error; 408 + 409 + error = priv->chip->read_reg(client, REG_GET_MODE, md, sizeof(md)); 410 + if (error) 411 + return error; 412 + /* Mode already set */ 413 + if ((cmd_mode == REG_SET_MODE_AP && md[0] == REG_GET_MODE_AP) || 414 + (cmd_mode == REG_SET_MODE_BL && md[0] == REG_GET_MODE_BL)) 415 + return 0; 416 + 417 + /* Unlock writes */ 418 + error = i2c_master_send(client, cmd_wren, sizeof(cmd_wren)); 419 + if (error != sizeof(cmd_wren)) 420 + return -EINVAL; 421 + 422 + mdelay(20); 423 + 424 + /* Select mode (BootLoader or Application) */ 425 + error = i2c_master_send(client, &cmd_mode, 1); 426 + if (error != 1) 427 + return -EINVAL; 428 + 429 + mdelay(200); /* Reboot into bootloader takes a lot of time ... */ 430 + 431 + /* Read back mode */ 432 + error = priv->chip->read_reg(client, REG_GET_MODE, md, sizeof(md)); 433 + if (error) 434 + return error; 435 + /* Check if mode is correct now. */ 436 + if ((cmd_mode == REG_SET_MODE_AP && md[0] == REG_GET_MODE_AP) || 437 + (cmd_mode == REG_SET_MODE_BL && md[0] == REG_GET_MODE_BL)) 438 + return 0; 439 + 440 + return -EINVAL; 441 + } 442 + 443 + static int ili251x_firmware_busy(struct i2c_client *client) 444 + { 445 + struct ili210x *priv = i2c_get_clientdata(client); 446 + int error, i = 0; 447 + u8 data; 448 + 449 + do { 450 + /* The read_reg already contains suitable delay */ 451 + error = priv->chip->read_reg(client, REG_IC_BUSY, &data, 1); 452 + if (error) 453 + return error; 454 + if (i++ == 100000) 455 + return -ETIMEDOUT; 456 + } while (data != REG_IC_BUSY_NOT_BUSY); 457 + 458 + return 0; 459 + } 460 + 461 + static int ili251x_firmware_write_to_ic(struct device *dev, u8 *fwbuf, 462 + u16 start, u16 end, u8 dataflash) 463 + { 464 + struct i2c_client *client = to_i2c_client(dev); 465 + struct ili210x *priv = i2c_get_clientdata(client); 466 + u8 cmd_crc = REG_READ_DATA_CRC; 467 + u8 crcrb[4] = { 0 }; 468 + u8 fw_data[33]; 469 + u16 fw_addr; 470 + int error; 471 + 472 + /* 473 + * The DF (dataflash) needs 2 bytes offset for unknown reasons, 474 + * the AC (application) has 2 bytes CRC16-CCITT at the end. 475 + */ 476 + u16 crc = crc_ccitt(0, fwbuf + start + (dataflash ? 2 : 0), 477 + end - start - 2); 478 + 479 + /* Unlock write to either AC (application) or DF (dataflash) area */ 480 + u8 cmd_wr[10] = { 481 + REG_WRITE_ENABLE, 0x5a, 0xa5, dataflash, 482 + (end >> 16) & 0xff, (end >> 8) & 0xff, end & 0xff, 483 + (crc >> 16) & 0xff, (crc >> 8) & 0xff, crc & 0xff 484 + }; 485 + 486 + error = i2c_master_send(client, cmd_wr, sizeof(cmd_wr)); 487 + if (error != sizeof(cmd_wr)) 488 + return -EINVAL; 489 + 490 + error = ili251x_firmware_busy(client); 491 + if (error) 492 + return error; 493 + 494 + for (fw_addr = start; fw_addr < end; fw_addr += 32) { 495 + fw_data[0] = REG_WRITE_DATA; 496 + memcpy(&(fw_data[1]), fwbuf + fw_addr, 32); 497 + error = i2c_master_send(client, fw_data, 33); 498 + if (error != sizeof(fw_data)) 499 + return error; 500 + error = ili251x_firmware_busy(client); 501 + if (error) 502 + return error; 503 + } 504 + 505 + error = i2c_master_send(client, &cmd_crc, 1); 506 + if (error != 1) 507 + return -EINVAL; 508 + 509 + error = ili251x_firmware_busy(client); 510 + if (error) 511 + return error; 512 + 513 + error = priv->chip->read_reg(client, REG_READ_DATA_CRC, 514 + &crcrb, sizeof(crcrb)); 515 + if (error) 516 + return error; 517 + 518 + /* Check CRC readback */ 519 + if ((crcrb[0] != (crc & 0xff)) || crcrb[1] != ((crc >> 8) & 0xff)) 520 + return -EINVAL; 521 + 522 + return 0; 523 + } 524 + 525 + static int ili251x_firmware_reset(struct i2c_client *client) 526 + { 527 + u8 cmd_reset[2] = { 0xf2, 0x01 }; 528 + int error; 529 + 530 + error = i2c_master_send(client, cmd_reset, sizeof(cmd_reset)); 531 + if (error != sizeof(cmd_reset)) 532 + return -EINVAL; 533 + 534 + return ili251x_firmware_busy(client); 535 + } 536 + 537 + static void ili251x_hardware_reset(struct device *dev) 538 + { 539 + struct i2c_client *client = to_i2c_client(dev); 540 + struct ili210x *priv = i2c_get_clientdata(client); 541 + 542 + /* Reset the controller */ 543 + gpiod_set_value_cansleep(priv->reset_gpio, 1); 544 + usleep_range(10000, 15000); 545 + gpiod_set_value_cansleep(priv->reset_gpio, 0); 546 + msleep(300); 547 + } 548 + 549 + static ssize_t ili210x_firmware_update_store(struct device *dev, 550 + struct device_attribute *attr, 551 + const char *buf, size_t count) 552 + { 553 + struct i2c_client *client = to_i2c_client(dev); 554 + const char *fwname = ILI251X_FW_FILENAME; 555 + const struct firmware *fw; 556 + u16 ac_end, df_end; 557 + u8 *fwbuf; 558 + int error; 559 + int i; 560 + 561 + error = request_ihex_firmware(&fw, fwname, dev); 562 + if (error) { 563 + dev_err(dev, "Failed to request firmware %s, error=%d\n", 564 + fwname, error); 565 + return error; 566 + } 567 + 568 + error = ili251x_firmware_to_buffer(fw, &fwbuf, &ac_end, &df_end); 569 + release_firmware(fw); 570 + if (error) 571 + return error; 572 + 573 + /* 574 + * Disable touchscreen IRQ, so that we would not get spurious touch 575 + * interrupt during firmware update, and so that the IRQ handler won't 576 + * trigger and interfere with the firmware update. There is no bit in 577 + * the touch controller to disable the IRQs during update, so we have 578 + * to do it this way here. 579 + */ 580 + disable_irq(client->irq); 581 + 582 + dev_dbg(dev, "Firmware update started, firmware=%s\n", fwname); 583 + 584 + ili251x_hardware_reset(dev); 585 + 586 + error = ili251x_firmware_reset(client); 587 + if (error) 588 + goto exit; 589 + 590 + /* This may not succeed on first try, so re-try a few times. */ 591 + for (i = 0; i < 5; i++) { 592 + error = ili251x_switch_ic_mode(client, REG_SET_MODE_BL); 593 + if (!error) 594 + break; 595 + } 596 + 597 + if (error) 598 + goto exit; 599 + 600 + dev_dbg(dev, "IC is now in BootLoader mode\n"); 601 + 602 + msleep(200); /* The bootloader seems to need some time too. */ 603 + 604 + error = ili251x_firmware_write_to_ic(dev, fwbuf, 0xf000, df_end, 1); 605 + if (error) { 606 + dev_err(dev, "DF firmware update failed, error=%d\n", error); 607 + goto exit; 608 + } 609 + 610 + dev_dbg(dev, "DataFlash firmware written\n"); 611 + 612 + error = ili251x_firmware_write_to_ic(dev, fwbuf, 0x2000, ac_end, 0); 613 + if (error) { 614 + dev_err(dev, "AC firmware update failed, error=%d\n", error); 615 + goto exit; 616 + } 617 + 618 + dev_dbg(dev, "Application firmware written\n"); 619 + 620 + /* This may not succeed on first try, so re-try a few times. */ 621 + for (i = 0; i < 5; i++) { 622 + error = ili251x_switch_ic_mode(client, REG_SET_MODE_AP); 623 + if (!error) 624 + break; 625 + } 626 + 627 + if (error) 628 + goto exit; 629 + 630 + dev_dbg(dev, "IC is now in Application mode\n"); 631 + 632 + error = ili251x_firmware_update_cached_state(dev); 633 + if (error) 634 + goto exit; 635 + 636 + error = count; 637 + 638 + exit: 639 + ili251x_hardware_reset(dev); 640 + dev_dbg(dev, "Firmware update ended, error=%i\n", error); 641 + enable_irq(client->irq); 642 + kfree(fwbuf); 643 + return error; 644 + } 645 + 646 + static DEVICE_ATTR(firmware_update, 0200, NULL, ili210x_firmware_update_store); 647 + 574 648 static struct attribute *ili210x_attributes[] = { 575 649 &dev_attr_calibrate.attr, 650 + &dev_attr_firmware_update.attr, 651 + &dev_attr_firmware_version.attr, 652 + &dev_attr_kernel_version.attr, 653 + &dev_attr_protocol_version.attr, 654 + &dev_attr_mode.attr, 576 655 NULL, 577 656 }; 578 657 579 - static umode_t ili210x_calibrate_visible(struct kobject *kobj, 658 + static umode_t ili210x_attributes_visible(struct kobject *kobj, 580 659 struct attribute *attr, int index) 581 660 { 582 661 struct device *dev = kobj_to_dev(kobj); 583 662 struct i2c_client *client = to_i2c_client(dev); 584 663 struct ili210x *priv = i2c_get_clientdata(client); 585 664 586 - return priv->chip->has_calibrate_reg ? attr->mode : 0; 665 + /* Calibrate is present on all ILI2xxx which have calibrate register */ 666 + if (attr == &dev_attr_calibrate.attr) 667 + return priv->chip->has_calibrate_reg ? attr->mode : 0; 668 + 669 + /* Firmware/Kernel/Protocol/BootMode is implememted only for ILI251x */ 670 + if (!priv->chip->has_firmware_proto) 671 + return 0; 672 + 673 + return attr->mode; 587 674 } 588 675 589 676 static const struct attribute_group ili210x_attr_group = { 590 677 .attrs = ili210x_attributes, 591 - .is_visible = ili210x_calibrate_visible, 678 + .is_visible = ili210x_attributes_visible, 592 679 }; 593 680 594 681 static void ili210x_power_down(void *data) ··· 980 449 input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_xy, 0, 0); 981 450 if (priv->chip->has_pressure_reg) 982 451 input_set_abs_params(input, ABS_MT_PRESSURE, 0, 0xa, 0, 0); 452 + error = ili251x_firmware_update_cached_state(dev); 453 + if (error) { 454 + dev_err(dev, "Unable to cache firmware information, err: %d\n", 455 + error); 456 + return error; 457 + } 983 458 touchscreen_parse_properties(input, true, &priv->prop); 984 459 985 460 error = input_mt_init_slots(input, priv->chip->max_touches,
+45 -9
drivers/input/touchscreen/raydium_i2c_ts.c
··· 37 37 #define RM_CMD_BOOT_READ 0x44 /* send wait bl data ready*/ 38 38 39 39 #define RM_BOOT_RDY 0xFF /* bl data ready */ 40 + #define RM_BOOT_CMD_READHWID 0x0E /* read hwid */ 40 41 41 42 /* I2C main commands */ 42 43 #define RM_CMD_QUERY_BANK 0x2B ··· 291 290 return 0; 292 291 } 293 292 293 + static int raydium_i2c_query_ts_bootloader_info(struct raydium_data *ts) 294 + { 295 + struct i2c_client *client = ts->client; 296 + static const u8 get_hwid[] = { RM_BOOT_CMD_READHWID, 297 + 0x10, 0xc0, 0x01, 0x00, 0x04, 0x00 }; 298 + u8 rbuf[5] = { 0 }; 299 + u32 hw_ver; 300 + int error; 301 + 302 + error = raydium_i2c_send(client, RM_CMD_BOOT_WRT, 303 + get_hwid, sizeof(get_hwid)); 304 + if (error) { 305 + dev_err(&client->dev, "WRT HWID command failed: %d\n", error); 306 + return error; 307 + } 308 + 309 + error = raydium_i2c_send(client, RM_CMD_BOOT_ACK, rbuf, 1); 310 + if (error) { 311 + dev_err(&client->dev, "Ack HWID command failed: %d\n", error); 312 + return error; 313 + } 314 + 315 + error = raydium_i2c_read(client, RM_CMD_BOOT_CHK, rbuf, sizeof(rbuf)); 316 + if (error) { 317 + dev_err(&client->dev, "Read HWID command failed: %d (%4ph)\n", 318 + error, rbuf + 1); 319 + hw_ver = 0xffffffffUL; 320 + } else { 321 + hw_ver = get_unaligned_be32(rbuf + 1); 322 + } 323 + 324 + ts->info.hw_ver = cpu_to_le32(hw_ver); 325 + ts->info.main_ver = 0xff; 326 + ts->info.sub_ver = 0xff; 327 + 328 + return error; 329 + } 330 + 294 331 static int raydium_i2c_query_ts_info(struct raydium_data *ts) 295 332 { 296 333 struct i2c_client *client = ts->client; ··· 427 388 if (error) 428 389 ts->boot_mode = RAYDIUM_TS_BLDR; 429 390 430 - if (ts->boot_mode == RAYDIUM_TS_BLDR) { 431 - ts->info.hw_ver = cpu_to_le32(0xffffffffUL); 432 - ts->info.main_ver = 0xff; 433 - ts->info.sub_ver = 0xff; 434 - } else { 391 + if (ts->boot_mode == RAYDIUM_TS_BLDR) 392 + raydium_i2c_query_ts_bootloader_info(ts); 393 + else 435 394 raydium_i2c_query_ts_info(ts); 436 - } 437 395 438 396 return error; 439 397 } ··· 1118 1082 if (error) 1119 1083 return error; 1120 1084 1121 - error = devm_add_action(&client->dev, raydium_i2c_power_off, ts); 1085 + error = devm_add_action_or_reset(&client->dev, 1086 + raydium_i2c_power_off, ts); 1122 1087 if (error) { 1123 1088 dev_err(&client->dev, 1124 1089 "failed to install power off action: %d\n", error); 1125 - raydium_i2c_power_off(ts); 1126 1090 return error; 1127 1091 } 1128 1092 ··· 1254 1218 raydium_i2c_suspend, raydium_i2c_resume); 1255 1219 1256 1220 static const struct i2c_device_id raydium_i2c_id[] = { 1257 - { "raydium_i2c" , 0 }, 1221 + { "raydium_i2c", 0 }, 1258 1222 { "rm32380", 0 }, 1259 1223 { /* sentinel */ } 1260 1224 };
+2 -1
drivers/input/touchscreen/st1232.c
··· 92 92 unsigned int retries; 93 93 int error; 94 94 95 - for (retries = 10; retries; retries--) { 95 + for (retries = 100; retries; retries--) { 96 96 error = st1232_ts_read_data(ts, REG_STATUS, 1); 97 97 if (!error) { 98 98 switch (ts->read_buf[0]) { ··· 389 389 .driver = { 390 390 .name = ST1232_TS_NAME, 391 391 .of_match_table = st1232_ts_dt_ids, 392 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 392 393 .pm = &st1232_ts_pm_ops, 393 394 }, 394 395 };
+3 -1
drivers/input/touchscreen/tsc2004.c
··· 45 45 46 46 static int tsc2004_remove(struct i2c_client *i2c) 47 47 { 48 - return tsc200x_remove(&i2c->dev); 48 + tsc200x_remove(&i2c->dev); 49 + 50 + return 0; 49 51 } 50 52 51 53 static const struct i2c_device_id tsc2004_idtable[] = {
+3 -1
drivers/input/touchscreen/tsc2005.c
··· 66 66 67 67 static int tsc2005_remove(struct spi_device *spi) 68 68 { 69 - return tsc200x_remove(&spi->dev); 69 + tsc200x_remove(&spi->dev); 70 + 71 + return 0; 70 72 } 71 73 72 74 #ifdef CONFIG_OF
+1 -3
drivers/input/touchscreen/tsc200x-core.c
··· 577 577 } 578 578 EXPORT_SYMBOL_GPL(tsc200x_probe); 579 579 580 - int tsc200x_remove(struct device *dev) 580 + void tsc200x_remove(struct device *dev) 581 581 { 582 582 struct tsc200x *ts = dev_get_drvdata(dev); 583 583 584 584 sysfs_remove_group(&dev->kobj, &tsc200x_attr_group); 585 585 586 586 regulator_disable(ts->vio); 587 - 588 - return 0; 589 587 } 590 588 EXPORT_SYMBOL_GPL(tsc200x_remove); 591 589
+1 -1
drivers/input/touchscreen/tsc200x-core.h
··· 74 74 int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id, 75 75 struct regmap *regmap, 76 76 int (*tsc200x_cmd)(struct device *dev, u8 cmd)); 77 - int tsc200x_remove(struct device *dev); 77 + void tsc200x_remove(struct device *dev); 78 78 79 79 #endif
+16 -6
drivers/input/touchscreen/wacom_i2c.c
··· 6 6 * <tobita.tatsunosuke@wacom.co.jp> 7 7 */ 8 8 9 + #include <linux/bits.h> 9 10 #include <linux/module.h> 10 11 #include <linux/input.h> 11 12 #include <linux/i2c.h> ··· 15 14 #include <linux/interrupt.h> 16 15 #include <asm/unaligned.h> 17 16 17 + /* Bitmasks (for data[3]) */ 18 + #define WACOM_TIP_SWITCH BIT(0) 19 + #define WACOM_BARREL_SWITCH BIT(1) 20 + #define WACOM_ERASER BIT(2) 21 + #define WACOM_INVERT BIT(3) 22 + #define WACOM_BARREL_SWITCH_2 BIT(4) 23 + #define WACOM_IN_PROXIMITY BIT(5) 24 + 25 + /* Registers */ 18 26 #define WACOM_CMD_QUERY0 0x04 19 27 #define WACOM_CMD_QUERY1 0x00 20 28 #define WACOM_CMD_QUERY2 0x33 ··· 109 99 if (error < 0) 110 100 goto out; 111 101 112 - tsw = data[3] & 0x01; 113 - ers = data[3] & 0x04; 114 - f1 = data[3] & 0x02; 115 - f2 = data[3] & 0x10; 102 + tsw = data[3] & WACOM_TIP_SWITCH; 103 + ers = data[3] & WACOM_ERASER; 104 + f1 = data[3] & WACOM_BARREL_SWITCH; 105 + f2 = data[3] & WACOM_BARREL_SWITCH_2; 116 106 x = le16_to_cpup((__le16 *)&data[4]); 117 107 y = le16_to_cpup((__le16 *)&data[6]); 118 108 pressure = le16_to_cpup((__le16 *)&data[8]); 119 109 120 110 if (!wac_i2c->prox) 121 - wac_i2c->tool = (data[3] & 0x0c) ? 111 + wac_i2c->tool = (data[3] & (WACOM_ERASER | WACOM_INVERT)) ? 122 112 BTN_TOOL_RUBBER : BTN_TOOL_PEN; 123 113 124 - wac_i2c->prox = data[3] & 0x20; 114 + wac_i2c->prox = data[3] & WACOM_IN_PROXIMITY; 125 115 126 116 input_report_key(input, BTN_TOUCH, tsw || ers); 127 117 input_report_key(input, wac_i2c->tool, wac_i2c->prox);
-10
include/linux/input/cy8ctmg110_pdata.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _LINUX_CY8CTMG110_PDATA_H 3 - #define _LINUX_CY8CTMG110_PDATA_H 4 - 5 - struct cy8ctmg110_pdata 6 - { 7 - int reset_pin; /* Reset pin is wired to this GPIO (optional) */ 8 - }; 9 - 10 - #endif
-15
include/linux/spi/ads7846.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 /* linux/spi/ads7846.h */ 3 3 4 - /* Touchscreen characteristics vary between boards and models. The 5 - * platform_data for the device's "struct device" holds this information. 6 - * 7 - * It's OK if the min/max values are zero. 8 - */ 9 - enum ads7846_filter { 10 - ADS7846_FILTER_OK, 11 - ADS7846_FILTER_REPEAT, 12 - ADS7846_FILTER_IGNORE, 13 - }; 14 - 15 4 struct ads7846_platform_data { 16 5 u16 model; /* 7843, 7845, 7846, 7873. */ 17 6 u16 vref_delay_usecs; /* 0 for external vref; etc */ ··· 40 51 int gpio_pendown_debounce; /* platform specific debounce time for 41 52 * the gpio_pendown */ 42 53 int (*get_pendown_state)(void); 43 - int (*filter_init) (const struct ads7846_platform_data *pdata, 44 - void **filter_data); 45 - int (*filter) (void *filter_data, int data_idx, int *val); 46 - void (*filter_cleanup)(void *filter_data); 47 54 void (*wait_for_sync)(void); 48 55 bool wakeup; 49 56 unsigned long irq_flags;
+1
kernel/reboot.c
··· 32 32 #define DEFAULT_REBOOT_MODE 33 33 #endif 34 34 enum reboot_mode reboot_mode DEFAULT_REBOOT_MODE; 35 + EXPORT_SYMBOL_GPL(reboot_mode); 35 36 enum reboot_mode panic_reboot_mode = REBOOT_UNDEFINED; 36 37 37 38 /*