]> Git Repo - linux.git/commitdiff
Merge branch 'next' into for-linus
authorDmitry Torokhov <[email protected]>
Thu, 18 Dec 2014 18:02:39 +0000 (10:02 -0800)
committerDmitry Torokhov <[email protected]>
Thu, 18 Dec 2014 18:02:39 +0000 (10:02 -0800)
Second round of input updates for 3.19.

1  2 
drivers/input/keyboard/stmpe-keypad.c
drivers/input/mouse/alps.c

index ef5e67fb567e701365767a9949dd3ea722e4f260,64514e64d557f51c027d5dd9b7b077e90a3e8dcb..fe6e3f22eed76157c42a1d9b873b01e34f38b5f2
  #define STMPE_KEYPAD_MAX_ROWS         8
  #define STMPE_KEYPAD_MAX_COLS         8
  #define STMPE_KEYPAD_ROW_SHIFT                3
- #define STMPE_KEYPAD_KEYMAP_SIZE      \
+ #define STMPE_KEYPAD_KEYMAP_MAX_SIZE \
        (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)
  
  /**
   * struct stmpe_keypad_variant - model-specific attributes
   * @auto_increment: whether the KPC_DATA_BYTE register address
   *                auto-increments on multiple read
+  * @set_pullup: whether the pins need to have their pull-ups set
   * @num_data: number of data bytes
   * @num_normal_data: number of normal keys' data bytes
   * @max_cols: maximum number of columns supported
@@@ -61,6 -62,7 +62,7 @@@
   */
  struct stmpe_keypad_variant {
        bool            auto_increment;
+       bool            set_pullup;
        int             num_data;
        int             num_normal_data;
        int             max_cols;
@@@ -81,15 -83,17 +83,17 @@@ static const struct stmpe_keypad_varian
        },
        [STMPE2401] = {
                .auto_increment         = false,
+               .set_pullup             = true,
                .num_data               = 3,
                .num_normal_data        = 2,
                .max_cols               = 8,
                .max_rows               = 12,
                .col_gpios              = 0x0000ff,     /* GPIO 0 - 7*/
 -              .row_gpios              = 0x1fef00,     /* GPIO 8-14, 16-20 */
 +              .row_gpios              = 0x1f7f00,     /* GPIO 8-14, 16-20 */
        },
        [STMPE2403] = {
                .auto_increment         = true,
+               .set_pullup             = true,
                .num_data               = 5,
                .num_normal_data        = 3,
                .max_cols               = 8,
        },
  };
  
+ /**
+  * struct stmpe_keypad - STMPE keypad state container
+  * @stmpe: pointer to parent STMPE device
+  * @input: spawned input device
+  * @variant: STMPE variant
+  * @debounce_ms: debounce interval, in ms.  Maximum is
+  *             %STMPE_KEYPAD_MAX_DEBOUNCE.
+  * @scan_count: number of key scanning cycles to confirm key data.
+  *            Maximum is %STMPE_KEYPAD_MAX_SCAN_COUNT.
+  * @no_autorepeat: disable key autorepeat
+  * @rows: bitmask for the rows
+  * @cols: bitmask for the columns
+  * @keymap: the keymap
+  */
  struct stmpe_keypad {
        struct stmpe *stmpe;
        struct input_dev *input;
        const struct stmpe_keypad_variant *variant;
-       const struct stmpe_keypad_platform_data *plat;
+       unsigned int debounce_ms;
+       unsigned int scan_count;
+       bool no_autorepeat;
        unsigned int rows;
        unsigned int cols;
-       unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];
+       unsigned short keymap[STMPE_KEYPAD_KEYMAP_MAX_SIZE];
  };
  
  static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)
@@@ -171,7 -189,10 +189,10 @@@ static int stmpe_keypad_altfunc_init(st
        unsigned int col_gpios = variant->col_gpios;
        unsigned int row_gpios = variant->row_gpios;
        struct stmpe *stmpe = keypad->stmpe;
+       u8 pureg = stmpe->regs[STMPE_IDX_GPPUR_LSB];
        unsigned int pins = 0;
+       unsigned int pu_pins = 0;
+       int ret;
        int i;
  
        /*
        for (i = 0; i < variant->max_cols; i++) {
                int num = __ffs(col_gpios);
  
-               if (keypad->cols & (1 << i))
+               if (keypad->cols & (1 << i)) {
                        pins |= 1 << num;
+                       pu_pins |= 1 << num;
+               }
  
                col_gpios &= ~(1 << num);
        }
                row_gpios &= ~(1 << num);
        }
  
-       return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
+       ret = stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
+       if (ret)
+               return ret;
+       /*
+        * On STMPE24xx, set pin bias to pull-up on all keypad input
+        * pins (columns), this incidentally happen to be maximum 8 pins
+        * and placed at GPIO0-7 so only the LSB of the pull up register
+        * ever needs to be written.
+        */
+       if (variant->set_pullup) {
+               u8 val;
+               ret = stmpe_reg_read(stmpe, pureg);
+               if (ret)
+                       return ret;
+               /* Do not touch unused pins, may be used for GPIO */
+               val = ret & ~pu_pins;
+               val |= pu_pins;
+               ret = stmpe_reg_write(stmpe, pureg, val);
+       }
+       return 0;
  }
  
  static int stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
  {
-       const struct stmpe_keypad_platform_data *plat = keypad->plat;
        const struct stmpe_keypad_variant *variant = keypad->variant;
        struct stmpe *stmpe = keypad->stmpe;
        int ret;
  
-       if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
+       if (keypad->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
                return -EINVAL;
  
-       if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)
+       if (keypad->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)
                return -EINVAL;
  
        ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);
  
        ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,
                             STMPE_KPC_CTRL_MSB_SCAN_COUNT,
-                            plat->scan_count << 4);
+                            keypad->scan_count << 4);
        if (ret < 0)
                return ret;
  
                              STMPE_KPC_CTRL_LSB_SCAN |
                              STMPE_KPC_CTRL_LSB_DEBOUNCE,
                              STMPE_KPC_CTRL_LSB_SCAN |
-                             (plat->debounce_ms << 1));
+                             (keypad->debounce_ms << 1));
  }
  
- static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad)
+ static void stmpe_keypad_fill_used_pins(struct stmpe_keypad *keypad,
+                                       u32 used_rows, u32 used_cols)
  {
        int row, col;
  
-       for (row = 0; row < STMPE_KEYPAD_MAX_ROWS; row++) {
-               for (col = 0; col < STMPE_KEYPAD_MAX_COLS; col++) {
+       for (row = 0; row < used_rows; row++) {
+               for (col = 0; col < used_cols; col++) {
                        int code = MATRIX_SCAN_CODE(row, col,
-                                               STMPE_KEYPAD_ROW_SHIFT);
+                                                   STMPE_KEYPAD_ROW_SHIFT);
                        if (keypad->keymap[code] != KEY_RESERVED) {
                                keypad->rows |= 1 << row;
                                keypad->cols |= 1 << col;
        }
  }
  
- #ifdef CONFIG_OF
- static const struct stmpe_keypad_platform_data *
- stmpe_keypad_of_probe(struct device *dev)
- {
-       struct device_node *np = dev->of_node;
-       struct stmpe_keypad_platform_data *plat;
-       if (!np)
-               return ERR_PTR(-ENODEV);
-       plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL);
-       if (!plat)
-               return ERR_PTR(-ENOMEM);
-       of_property_read_u32(np, "debounce-interval", &plat->debounce_ms);
-       of_property_read_u32(np, "st,scan-count", &plat->scan_count);
-       plat->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat");
-       return plat;
- }
- #else
- static inline const struct stmpe_keypad_platform_data *
- stmpe_keypad_of_probe(struct device *dev)
- {
-       return ERR_PTR(-EINVAL);
- }
- #endif
  static int stmpe_keypad_probe(struct platform_device *pdev)
  {
        struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
-       const struct stmpe_keypad_platform_data *plat;
+       struct device_node *np = pdev->dev.of_node;
        struct stmpe_keypad *keypad;
        struct input_dev *input;
+       u32 rows;
+       u32 cols;
        int error;
        int irq;
  
-       plat = stmpe->pdata->keypad;
-       if (!plat) {
-               plat = stmpe_keypad_of_probe(&pdev->dev);
-               if (IS_ERR(plat))
-                       return PTR_ERR(plat);
-       }
        irq = platform_get_irq(pdev, 0);
        if (irq < 0)
                return irq;
        if (!keypad)
                return -ENOMEM;
  
+       keypad->stmpe = stmpe;
+       keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
+       of_property_read_u32(np, "debounce-interval", &keypad->debounce_ms);
+       of_property_read_u32(np, "st,scan-count", &keypad->scan_count);
+       keypad->no_autorepeat = of_property_read_bool(np, "st,no-autorepeat");
        input = devm_input_allocate_device(&pdev->dev);
        if (!input)
                return -ENOMEM;
        input->id.bustype = BUS_I2C;
        input->dev.parent = &pdev->dev;
  
-       error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
-                                          STMPE_KEYPAD_MAX_ROWS,
-                                          STMPE_KEYPAD_MAX_COLS,
+       error = matrix_keypad_parse_of_params(&pdev->dev, &rows, &cols);
+       if (error)
+               return error;
+       error = matrix_keypad_build_keymap(NULL, NULL, rows, cols,
                                           keypad->keymap, input);
        if (error)
                return error;
  
        input_set_capability(input, EV_MSC, MSC_SCAN);
-       if (!plat->no_autorepeat)
+       if (!keypad->no_autorepeat)
                __set_bit(EV_REP, input->evbit);
  
-       stmpe_keypad_fill_used_pins(keypad);
+       stmpe_keypad_fill_used_pins(keypad, rows, cols);
  
-       keypad->stmpe = stmpe;
-       keypad->plat = plat;
        keypad->input = input;
-       keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
  
        error = stmpe_keypad_chip_init(keypad);
        if (error < 0)
index d125a019383f10155dcafb88903f47e0f5297080,0faea6df228b390c0508a967ca7dfa7688488f91..d88d73d835526a16d2e5e4e48c6a2562c802a4cf
@@@ -835,8 -835,8 +835,8 @@@ static void alps_process_packet_v4(stru
                f->fingers = alps_process_bitmap(priv, f);
        }
  
 -      f->left = packet[4] & 0x01;
 -      f->right = packet[4] & 0x02;
 +      f->left = !!(packet[4] & 0x01);
 +      f->right = !!(packet[4] & 0x02);
  
        f->st.x = ((packet[1] & 0x7f) << 4) | ((packet[3] & 0x30) >> 2) |
                  ((packet[0] & 0x30) >> 4);
@@@ -881,6 -881,34 +881,34 @@@ static void alps_get_finger_coordinate_
                                          unsigned char *pkt,
                                          unsigned char pkt_id)
  {
+       /*
+        *       packet-fmt    b7   b6    b5   b4   b3   b2   b1   b0
+        * Byte0 TWO & MULTI    L    1     R    M    1 Y0-2 Y0-1 Y0-0
+        * Byte0 NEW            L    1  X1-5    1    1 Y0-2 Y0-1 Y0-0
+        * Byte1            Y0-10 Y0-9  Y0-8 Y0-7 Y0-6 Y0-5 Y0-4 Y0-3
+        * Byte2            X0-11    1 X0-10 X0-9 X0-8 X0-7 X0-6 X0-5
+        * Byte3            X1-11    1  X0-4 X0-3    1 X0-2 X0-1 X0-0
+        * Byte4 TWO        X1-10  TWO  X1-9 X1-8 X1-7 X1-6 X1-5 X1-4
+        * Byte4 MULTI      X1-10  TWO  X1-9 X1-8 X1-7 X1-6 Y1-5    1
+        * Byte4 NEW        X1-10  TWO  X1-9 X1-8 X1-7 X1-6    0    0
+        * Byte5 TWO & NEW  Y1-10    0  Y1-9 Y1-8 Y1-7 Y1-6 Y1-5 Y1-4
+        * Byte5 MULTI      Y1-10    0  Y1-9 Y1-8 Y1-7 Y1-6  F-1  F-0
+        * L:         Left button
+        * R / M:     Non-clickpads: Right / Middle button
+        *            Clickpads: When > 2 fingers are down, and some fingers
+        *            are in the button area, then the 2 coordinates reported
+        *            are for fingers outside the button area and these report
+        *            extra fingers being present in the right / left button
+        *            area. Note these fingers are not added to the F field!
+        *            so if a TWO packet is received and R = 1 then there are
+        *            3 fingers down, etc.
+        * TWO:       1: Two touches present, byte 0/4/5 are in TWO fmt
+        *            0: If byte 4 bit 0 is 1, then byte 0/4/5 are in MULTI fmt
+        *               otherwise byte 0 bit 4 must be set and byte 0/4/5 are
+        *               in NEW fmt
+        * F:         Number of fingers - 3, 0 means 3 fingers, 1 means 4 ...
+        */
        mt[0].x = ((pkt[2] & 0x80) << 4);
        mt[0].x |= ((pkt[2] & 0x3F) << 5);
        mt[0].x |= ((pkt[3] & 0x30) >> 1);
  
  static int alps_get_mt_count(struct input_mt_pos *mt)
  {
-       int i;
+       int i, fingers = 0;
  
-       for (i = 0; i < MAX_TOUCHES && mt[i].x != 0 && mt[i].y != 0; i++)
-               /* empty */;
+       for (i = 0; i < MAX_TOUCHES; i++) {
+               if (mt[i].x != 0 || mt[i].y != 0)
+                       fingers++;
+       }
  
-       return i;
+       return fingers;
  }
  
  static int alps_decode_packet_v7(struct alps_fields *f,
                                  unsigned char *p,
                                  struct psmouse *psmouse)
  {
+       struct alps_data *priv = psmouse->private;
        unsigned char pkt_id;
  
        pkt_id = alps_get_packet_id_v7(p);
                return 0;
        if (pkt_id == V7_PACKET_ID_UNKNOWN)
                return -1;
+       /*
+        * NEW packets are send to indicate a discontinuity in the finger
+        * coordinate reporting. Specifically a finger may have moved from
+        * slot 0 to 1 or vice versa. INPUT_MT_TRACK takes care of this for
+        * us.
+        *
+        * NEW packets have 3 problems:
+        * 1) They do not contain middle / right button info (on non clickpads)
+        *    this can be worked around by preserving the old button state
+        * 2) They do not contain an accurate fingercount, and they are
+        *    typically send when the number of fingers changes. We cannot use
+        *    the old finger count as that may mismatch with the amount of
+        *    touch coordinates we've available in the NEW packet
+        * 3) Their x data for the second touch is inaccurate leading to
+        *    a possible jump of the x coordinate by 16 units when the first
+        *    non NEW packet comes in
+        * Since problems 2 & 3 cannot be worked around, just ignore them.
+        */
+       if (pkt_id == V7_PACKET_ID_NEW)
+               return 1;
  
        alps_get_finger_coordinate_v7(f->mt, p, pkt_id);
  
-       if (pkt_id == V7_PACKET_ID_TWO || pkt_id == V7_PACKET_ID_MULTI) {
-               f->left = (p[0] & 0x80) >> 7;
+       if (pkt_id == V7_PACKET_ID_TWO)
+               f->fingers = alps_get_mt_count(f->mt);
+       else /* pkt_id == V7_PACKET_ID_MULTI */
+               f->fingers = 3 + (p[5] & 0x03);
+       f->left = (p[0] & 0x80) >> 7;
+       if (priv->flags & ALPS_BUTTONPAD) {
+               if (p[0] & 0x20)
+                       f->fingers++;
+               if (p[0] & 0x10)
+                       f->fingers++;
+       } else {
                f->right = (p[0] & 0x20) >> 5;
                f->middle = (p[0] & 0x10) >> 4;
        }
  
-       if (pkt_id == V7_PACKET_ID_TWO)
-               f->fingers = alps_get_mt_count(f->mt);
-       else if (pkt_id == V7_PACKET_ID_MULTI)
-               f->fingers = 3 + (p[5] & 0x03);
+       /* Sometimes a single touch is reported in mt[1] rather then mt[0] */
+       if (f->fingers == 1 && f->mt[0].x == 0 && f->mt[0].y == 0) {
+               f->mt[0].x = f->mt[1].x;
+               f->mt[0].y = f->mt[1].y;
+               f->mt[1].x = 0;
+               f->mt[1].y = 0;
+       }
  
        return 0;
  }
@@@ -1156,13 -1220,7 +1220,13 @@@ static psmouse_ret_t alps_process_byte(
  {
        struct alps_data *priv = psmouse->private;
  
 -      if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */
 +      /*
 +       * Check if we are dealing with a bare PS/2 packet, presumably from
 +       * a device connected to the external PS/2 port. Because bare PS/2
 +       * protocol does not have enough constant bits to self-synchronize
 +       * properly we only do this if the device is fully synchronized.
 +       */
 +      if (!psmouse->out_of_sync_cnt && (psmouse->packet[0] & 0xc8) == 0x08) {
                if (psmouse->pktcnt == 3) {
                        alps_report_bare_ps2_packet(psmouse, psmouse->packet,
                                                    true);
        }
  
        /* Bytes 2 - pktsize should have 0 in the highest bit */
 -      if ((priv->proto_version < ALPS_PROTO_V5) &&
 +      if (priv->proto_version < ALPS_PROTO_V5 &&
            psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
            (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
                psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
                            psmouse->pktcnt - 1,
                            psmouse->packet[psmouse->pktcnt - 1]);
 +
 +              if (priv->proto_version == ALPS_PROTO_V3 &&
 +                  psmouse->pktcnt == psmouse->pktsize) {
 +                      /*
 +                       * Some Dell boxes, such as Latitude E6440 or E7440
 +                       * with closed lid, quite often smash last byte of
 +                       * otherwise valid packet with 0xff. Given that the
 +                       * next packet is very likely to be valid let's
 +                       * report PSMOUSE_FULL_PACKET but not process data,
 +                       * rather than reporting PSMOUSE_BAD_DATA and
 +                       * filling the logs.
 +                       */
 +                      return PSMOUSE_FULL_PACKET;
 +              }
 +
                return PSMOUSE_BAD_DATA;
        }
  
@@@ -2410,9 -2453,6 +2474,9 @@@ int alps_init(struct psmouse *psmouse
        /* We are having trouble resyncing ALPS touchpads so disable it for now */
        psmouse->resync_time = 0;
  
 +      /* Allow 2 invalid packets without resetting device */
 +      psmouse->resetafter = psmouse->pktsize * 2;
 +
        return 0;
  
  init_fail:
This page took 0.105427 seconds and 4 git commands to generate.