Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Jun 2018 16:16:53 +0000 (09:16 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Jun 2018 16:16:53 +0000 (09:16 -0700)
Pull input updates from Dmitry Torokhov:

 - the main change is a fix for my brain-dead patch to PS/2 button
   reporting for some protocols that made it in 4.17

 - there is a new driver for Spreadtum vibrator that I intended to send
   during merge window but ended up not sending the 2nd pull request.
   Given that this is a brand new driver we should not see regressions
   here

 - a fixup to Elantech PS/2 driver to avoid decoding errors on Thinkpad
   P52

 - addition of few more ACPI IDs for Silead and Elan drivers

 - RMI4 is switched to using IRQ domain code instead of rolling its own
   implementation

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input:
  Input: psmouse - fix button reporting for basic protocols
  Input: xpad - fix GPD Win 2 controller name
  Input: elan_i2c_smbus - fix more potential stack buffer overflows
  Input: elan_i2c - add ELAN0618 (Lenovo v330 15IKB) ACPI ID
  Input: elantech - fix V4 report decoding for module with middle key
  Input: elantech - enable middle button of touchpads on ThinkPad P52
  Input: do not assign new tracking ID when changing tool type
  Input: make input_report_slot_state() return boolean
  Input: synaptics-rmi4 - fix axis-swap behavior
  Input: synaptics-rmi4 - fix the error return code in rmi_probe_interrupts()
  Input: synaptics-rmi4 - convert irq distribution to irq_domain
  Input: silead - add MSSL0002 ACPI HID
  Input: goldfish_events - fix checkpatch warnings
  Input: add Spreadtrum vibrator driver

1  2 
drivers/input/input-mt.c
drivers/input/misc/Kconfig
drivers/input/rmi4/rmi_driver.c
drivers/input/rmi4/rmi_f11.c
drivers/input/rmi4/rmi_f12.c
drivers/input/rmi4/rmi_f54.c

diff --combined drivers/input/input-mt.c
index cf30523c6ef64c956e5ebf77c730c6bb146c4a1f,4a69716e546145b90dc8ec569ededc030d10e710..6c7326c93721c495c4e61a73cac2dfaf9a5bc8fc
@@@ -49,7 -49,7 +49,7 @@@ int input_mt_init_slots(struct input_de
        if (mt)
                return mt->num_slots != num_slots ? -EINVAL : 0;
  
 -      mt = kzalloc(sizeof(*mt) + num_slots * sizeof(*mt->slots), GFP_KERNEL);
 +      mt = kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL);
        if (!mt)
                goto err_mem;
  
@@@ -131,8 -131,10 +131,10 @@@ EXPORT_SYMBOL(input_mt_destroy_slots)
   * inactive, or if the tool type is changed, a new tracking id is
   * assigned to the slot. The tool type is only reported if the
   * corresponding absbit field is set.
+  *
+  * Returns true if contact is active.
   */
void input_mt_report_slot_state(struct input_dev *dev,
bool input_mt_report_slot_state(struct input_dev *dev,
                                unsigned int tool_type, bool active)
  {
        struct input_mt *mt = dev->mt;
        int id;
  
        if (!mt)
-               return;
+               return false;
  
        slot = &mt->slots[mt->slot];
        slot->frame = mt->frame;
  
        if (!active) {
                input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1);
-               return;
+               return false;
        }
  
        id = input_mt_get_value(slot, ABS_MT_TRACKING_ID);
-       if (id < 0 || input_mt_get_value(slot, ABS_MT_TOOL_TYPE) != tool_type)
+       if (id < 0)
                id = input_mt_new_trkid(mt);
  
        input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id);
        input_event(dev, EV_ABS, ABS_MT_TOOL_TYPE, tool_type);
+       return true;
  }
  EXPORT_SYMBOL(input_mt_report_slot_state);
  
index c25606e006938743d64498429cf3d0b69768d7fb,c761c0c4f2b86abfe7b2227fd3556414d641a6d0..ca59a2be9bc5344f65389ea7372a7740b74b5343
@@@ -411,7 -411,7 +411,7 @@@ config INPUT_YEALIN
          usb sound driver, so you might want to enable that as well.
  
          For information about how to use these additional functions, see
 -        <file:Documentation/input/yealink.txt>.
 +        <file:Documentation/input/devices/yealink.rst>.
  
          To compile this driver as a module, choose M here: the module will be
          called yealink.
@@@ -595,7 -595,7 +595,7 @@@ config INPUT_GPIO_ROTARY_ENCODE
        depends on GPIOLIB || COMPILE_TEST
        help
          Say Y here to add support for rotary encoders connected to GPIO lines.
 -        Check file:Documentation/input/rotary-encoder.txt for more
 +        Check file:Documentation/input/devices/rotary-encoder.rst for more
          information.
  
          To compile this driver as a module, choose M here: the
@@@ -841,4 -841,14 +841,14 @@@ config INPUT_RAVE_SP_PWRBUTTO
          To compile this driver as a module, choose M here: the
          module will be called rave-sp-pwrbutton.
  
+ config INPUT_SC27XX_VIBRA
+       tristate "Spreadtrum sc27xx vibrator support"
+       depends on MFD_SC27XX_PMIC || COMPILE_TEST
+       select INPUT_FF_MEMLESS
+       help
+         This option enables support for Spreadtrum sc27xx vibrator driver.
+         To compile this driver as a module, choose M here. The module will
+         be called sc27xx_vibra.
  endif
index 7d29053dfb0f06878ff7897b59f52039a299a089,cb6d983e80336aa5a882013f0264bd56610f54c6..fc3ab93b7aea454475ee324eecee91470c4a9dc3
@@@ -21,6 -21,7 +21,7 @@@
  #include <linux/pm.h>
  #include <linux/slab.h>
  #include <linux/of.h>
+ #include <linux/irqdomain.h>
  #include <uapi/linux/input.h>
  #include <linux/rmi.h>
  #include "rmi_bus.h"
@@@ -127,28 -128,11 +128,11 @@@ static int rmi_driver_process_config_re
        return 0;
  }
  
- static void process_one_interrupt(struct rmi_driver_data *data,
-                                 struct rmi_function *fn)
- {
-       struct rmi_function_handler *fh;
-       if (!fn || !fn->dev.driver)
-               return;
-       fh = to_rmi_function_handler(fn->dev.driver);
-       if (fh->attention) {
-               bitmap_and(data->fn_irq_bits, data->irq_status, fn->irq_mask,
-                               data->irq_count);
-               if (!bitmap_empty(data->fn_irq_bits, data->irq_count))
-                       fh->attention(fn, data->fn_irq_bits);
-       }
- }
  static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev)
  {
        struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
        struct device *dev = &rmi_dev->dev;
-       struct rmi_function *entry;
+       int i;
        int error;
  
        if (!data)
         */
        mutex_unlock(&data->irq_mutex);
  
-       /*
-        * It would be nice to be able to use irq_chip to handle these
-        * nested IRQs.  Unfortunately, most of the current customers for
-        * this driver are using older kernels (3.0.x) that don't support
-        * the features required for that.  Once they've shifted to more
-        * recent kernels (say, 3.3 and higher), this should be switched to
-        * use irq_chip.
-        */
-       list_for_each_entry(entry, &data->function_list, node)
-               process_one_interrupt(data, entry);
+       for_each_set_bit(i, data->irq_status, data->irq_count)
+               handle_nested_irq(irq_find_mapping(data->irqdomain, i));
  
        if (data->input)
                input_sync(data->input);
@@@ -636,10 -612,9 +612,10 @@@ int rmi_read_register_desc(struct rmi_d
        rdesc->num_registers = bitmap_weight(rdesc->presense_map,
                                                RMI_REG_DESC_PRESENSE_BITS);
  
 -      rdesc->registers = devm_kzalloc(&d->dev, rdesc->num_registers *
 -                              sizeof(struct rmi_register_desc_item),
 -                              GFP_KERNEL);
 +      rdesc->registers = devm_kcalloc(&d->dev,
 +                                      rdesc->num_registers,
 +                                      sizeof(struct rmi_register_desc_item),
 +                                      GFP_KERNEL);
        if (!rdesc->registers)
                return -ENOMEM;
  
@@@ -1001,9 -976,13 +977,13 @@@ EXPORT_SYMBOL_GPL(rmi_driver_resume)
  static int rmi_driver_remove(struct device *dev)
  {
        struct rmi_device *rmi_dev = to_rmi_device(dev);
+       struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
  
        rmi_disable_irq(rmi_dev, false);
  
+       irq_domain_remove(data->irqdomain);
+       data->irqdomain = NULL;
        rmi_f34_remove_sysfs(rmi_dev);
        rmi_free_function_list(rmi_dev);
  
@@@ -1035,7 -1014,8 +1015,8 @@@ int rmi_probe_interrupts(struct rmi_dri
  {
        struct rmi_device *rmi_dev = data->rmi_dev;
        struct device *dev = &rmi_dev->dev;
-       int irq_count;
+       struct fwnode_handle *fwnode = rmi_dev->xport->dev->fwnode;
+       int irq_count = 0;
        size_t size;
        int retval;
  
         * being accessed.
         */
        rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Counting IRQs.\n", __func__);
-       irq_count = 0;
        data->bootloader_mode = false;
  
        retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_count_irqs);
        if (data->bootloader_mode)
                dev_warn(dev, "Device in bootloader mode.\n");
  
+       /* Allocate and register a linear revmap irq_domain */
+       data->irqdomain = irq_domain_create_linear(fwnode, irq_count,
+                                                  &irq_domain_simple_ops,
+                                                  data);
+       if (!data->irqdomain) {
+               dev_err(&rmi_dev->dev, "Failed to create IRQ domain\n");
+               return -ENOMEM;
+       }
        data->irq_count = irq_count;
        data->num_of_irq_regs = (data->irq_count + 7) / 8;
  
        size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long);
 -      data->irq_memory = devm_kzalloc(dev, size * 4, GFP_KERNEL);
 +      data->irq_memory = devm_kcalloc(dev, size, 4, GFP_KERNEL);
        if (!data->irq_memory) {
                dev_err(dev, "Failed to allocate memory for irq masks.\n");
                return -ENOMEM;
@@@ -1080,10 -1068,9 +1069,9 @@@ int rmi_init_functions(struct rmi_drive
  {
        struct rmi_device *rmi_dev = data->rmi_dev;
        struct device *dev = &rmi_dev->dev;
-       int irq_count;
+       int irq_count = 0;
        int retval;
  
-       irq_count = 0;
        rmi_dbg(RMI_DEBUG_CORE, dev, "%s: Creating functions.\n", __func__);
        retval = rmi_scan_pdt(rmi_dev, &irq_count, rmi_create_function);
        if (retval < 0) {
index 12a233251793c24c754224ae1b379de52db34e7d,5f2e1ef5accc21e6f06aed55b5da0e4c1d52a5b5..df64d6aed4f7e10b8eb78eb78619a15d7bcaaf56
@@@ -570,9 -570,7 +570,7 @@@ static inline u8 rmi_f11_parse_finger_s
  }
  
  static void rmi_f11_finger_handler(struct f11_data *f11,
-                                  struct rmi_2d_sensor *sensor,
-                                  unsigned long *irq_bits, int num_irq_regs,
-                                  int size)
+                                  struct rmi_2d_sensor *sensor, int size)
  {
        const u8 *f_state = f11->data.f_state;
        u8 finger_state;
        int rel_fingers;
        int abs_size = sensor->nbr_fingers * RMI_F11_ABS_BYTES;
  
-       int abs_bits = bitmap_and(f11->result_bits, irq_bits, f11->abs_mask,
-                                 num_irq_regs * 8);
-       int rel_bits = bitmap_and(f11->result_bits, irq_bits, f11->rel_mask,
-                                 num_irq_regs * 8);
-       if (abs_bits) {
+       if (sensor->report_abs) {
                if (abs_size > size)
                        abs_fingers = size / RMI_F11_ABS_BYTES;
                else
                        rmi_f11_abs_pos_process(f11, sensor, &sensor->objs[i],
                                                        finger_state, i);
                }
-       }
  
-       if (rel_bits) {
-               if ((abs_size + sensor->nbr_fingers * RMI_F11_REL_BYTES) > size)
-                       rel_fingers = (size - abs_size) / RMI_F11_REL_BYTES;
-               else
-                       rel_fingers = sensor->nbr_fingers;
-               for (i = 0; i < rel_fingers; i++)
-                       rmi_f11_rel_pos_report(f11, i);
-       }
-       if (abs_bits) {
                /*
                 * the absolute part is made in 2 parts to allow the kernel
                 * tracking to take place.
                }
  
                input_mt_sync_frame(sensor->input);
+       } else if (sensor->report_rel) {
+               if ((abs_size + sensor->nbr_fingers * RMI_F11_REL_BYTES) > size)
+                       rel_fingers = (size - abs_size) / RMI_F11_REL_BYTES;
+               else
+                       rel_fingers = sensor->nbr_fingers;
+               for (i = 0; i < rel_fingers; i++)
+                       rmi_f11_rel_pos_report(f11, i);
        }
  }
  
  static int f11_2d_construct_data(struct f11_data *f11)
@@@ -1190,15 -1180,14 +1180,15 @@@ static int rmi_f11_initialize(struct rm
                f11->sensor.attn_size += f11->sensor.nbr_fingers * 2;
  
        /* allocate the in-kernel tracking buffers */
 -      sensor->tracking_pos = devm_kzalloc(&fn->dev,
 -                      sizeof(struct input_mt_pos) * sensor->nbr_fingers,
 +      sensor->tracking_pos = devm_kcalloc(&fn->dev,
 +                      sensor->nbr_fingers, sizeof(struct input_mt_pos),
 +                      GFP_KERNEL);
 +      sensor->tracking_slots = devm_kcalloc(&fn->dev,
 +                      sensor->nbr_fingers, sizeof(int), GFP_KERNEL);
 +      sensor->objs = devm_kcalloc(&fn->dev,
 +                      sensor->nbr_fingers,
 +                      sizeof(struct rmi_2d_sensor_abs_object),
                        GFP_KERNEL);
 -      sensor->tracking_slots = devm_kzalloc(&fn->dev,
 -                      sizeof(int) * sensor->nbr_fingers, GFP_KERNEL);
 -      sensor->objs = devm_kzalloc(&fn->dev,
 -                      sizeof(struct rmi_2d_sensor_abs_object)
 -                      * sensor->nbr_fingers, GFP_KERNEL);
        if (!sensor->tracking_pos || !sensor->tracking_slots || !sensor->objs)
                return -ENOMEM;
  
@@@ -1276,8 -1265,9 +1266,9 @@@ static int rmi_f11_config(struct rmi_fu
        return 0;
  }
  
- static int rmi_f11_attention(struct rmi_function *fn, unsigned long *irq_bits)
+ static irqreturn_t rmi_f11_attention(int irq, void *ctx)
  {
+       struct rmi_function *fn = ctx;
        struct rmi_device *rmi_dev = fn->rmi_dev;
        struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
        struct f11_data *f11 = dev_get_drvdata(&fn->dev);
                                data_base_addr, f11->sensor.data_pkt,
                                f11->sensor.pkt_size);
                if (error < 0)
-                       return error;
+                       return IRQ_RETVAL(error);
        }
  
-       rmi_f11_finger_handler(f11, &f11->sensor, irq_bits,
-                               drvdata->num_of_irq_regs, valid_bytes);
+       rmi_f11_finger_handler(f11, &f11->sensor, valid_bytes);
  
-       return 0;
+       return IRQ_HANDLED;
  }
  
  static int rmi_f11_resume(struct rmi_function *fn)
index a3d1aa88f2a9ce27fcd1f89d2f87d58b21686fce,e226def74d8280d88ce8eca0e3d4f4cbeaf47abb..5c7f489157792bf32da34e982b715824ec17eaff
@@@ -197,10 -197,10 +197,10 @@@ static void rmi_f12_process_objects(str
                rmi_2d_sensor_abs_report(sensor, &sensor->objs[i], i);
  }
  
- static int rmi_f12_attention(struct rmi_function *fn,
-                            unsigned long *irq_nr_regs)
+ static irqreturn_t rmi_f12_attention(int irq, void *ctx)
  {
        int retval;
+       struct rmi_function *fn = ctx;
        struct rmi_device *rmi_dev = fn->rmi_dev;
        struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
        struct f12_data *f12 = dev_get_drvdata(&fn->dev);
                if (retval < 0) {
                        dev_err(&fn->dev, "Failed to read object data. Code: %d.\n",
                                retval);
-                       return retval;
+                       return IRQ_RETVAL(retval);
                }
        }
  
  
        input_mt_sync_frame(sensor->input);
  
-       return 0;
+       return IRQ_HANDLED;
  }
  
  static int rmi_f12_write_control_regs(struct rmi_function *fn)
@@@ -502,15 -502,14 +502,15 @@@ static int rmi_f12_probe(struct rmi_fun
        }
  
        /* allocate the in-kernel tracking buffers */
 -      sensor->tracking_pos = devm_kzalloc(&fn->dev,
 -                      sizeof(struct input_mt_pos) * sensor->nbr_fingers,
 +      sensor->tracking_pos = devm_kcalloc(&fn->dev,
 +                      sensor->nbr_fingers, sizeof(struct input_mt_pos),
 +                      GFP_KERNEL);
 +      sensor->tracking_slots = devm_kcalloc(&fn->dev,
 +                      sensor->nbr_fingers, sizeof(int), GFP_KERNEL);
 +      sensor->objs = devm_kcalloc(&fn->dev,
 +                      sensor->nbr_fingers,
 +                      sizeof(struct rmi_2d_sensor_abs_object),
                        GFP_KERNEL);
 -      sensor->tracking_slots = devm_kzalloc(&fn->dev,
 -                      sizeof(int) * sensor->nbr_fingers, GFP_KERNEL);
 -      sensor->objs = devm_kzalloc(&fn->dev,
 -                      sizeof(struct rmi_2d_sensor_abs_object)
 -                      * sensor->nbr_fingers, GFP_KERNEL);
        if (!sensor->tracking_pos || !sensor->tracking_slots || !sensor->objs)
                return -ENOMEM;
  
index e8a59d1640192b75e6f83db0e2ad355064c19ff9,98a935efec8e2d4254691700bba27154c874e2b9..a6f515bcab2228a8783f10dbf10fae30462fd852
@@@ -610,11 -610,6 +610,6 @@@ error
        mutex_unlock(&f54->data_mutex);
  }
  
- static int rmi_f54_attention(struct rmi_function *fn, unsigned long *irqbits)
- {
-       return 0;
- }
  static int rmi_f54_config(struct rmi_function *fn)
  {
        struct rmi_driver *drv = fn->rmi_dev->driver;
@@@ -685,7 -680,7 +680,7 @@@ static int rmi_f54_probe(struct rmi_fun
        rx = f54->num_rx_electrodes;
        tx = f54->num_tx_electrodes;
        f54->report_data = devm_kzalloc(&fn->dev,
 -                                      sizeof(u16) * tx * rx,
 +                                      array3_size(tx, rx, sizeof(u16)),
                                        GFP_KERNEL);
        if (f54->report_data == NULL)
                return -ENOMEM;
@@@ -756,6 -751,5 +751,5 @@@ struct rmi_function_handler rmi_f54_han
        .func = 0x54,
        .probe = rmi_f54_probe,
        .config = rmi_f54_config,
-       .attention = rmi_f54_attention,
        .remove = rmi_f54_remove,
  };