Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * BYD TouchPad PS/2 mouse driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2015 Chris Diamand <chris@diamand.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2015 Richard Pospesel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2015 Tai Chi Minh Ralph Eastwood
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2015 Martin Wimpress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2015 Jay Kuri
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/libps2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/serio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "psmouse.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "byd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* PS2 Bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define PS2_Y_OVERFLOW	BIT_MASK(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define PS2_X_OVERFLOW	BIT_MASK(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define PS2_Y_SIGN	BIT_MASK(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define PS2_X_SIGN	BIT_MASK(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define PS2_ALWAYS_1	BIT_MASK(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define PS2_MIDDLE	BIT_MASK(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define PS2_RIGHT	BIT_MASK(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define PS2_LEFT	BIT_MASK(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * BYD pad constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * True device resolution is unknown, however experiments show the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * resolution is about 111 units/mm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Absolute coordinate packets are in the range 0-255 for both X and Y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * we pick ABS_X/ABS_Y dimensions which are multiples of 256 and in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * the right ballpark given the touchpad's physical dimensions and estimate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * resolution per spec sheet, device active area dimensions are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * 101.6 x 60.1 mm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define BYD_PAD_WIDTH		11264
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define BYD_PAD_HEIGHT		6656
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define BYD_PAD_RESOLUTION	111
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Given the above dimensions, relative packets velocity is in multiples of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * 1 unit / 11 milliseconds.  We use this dt to estimate distance traveled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define BYD_DT			11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* Time in jiffies used to timeout various touch events (64 ms) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define BYD_TOUCH_TIMEOUT	msecs_to_jiffies(64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) /* BYD commands reverse engineered from windows driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * Swipe gesture from off-pad to on-pad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *  0 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *  1 : enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define BYD_CMD_SET_OFFSCREEN_SWIPE		0x10cc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * Tap and drag delay time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *  0 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *  1 - 8 : least to most delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define BYD_CMD_SET_TAP_DRAG_DELAY_TIME		0x10cf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * Physical buttons function mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *  0 : enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *  4 : normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *  5 : left button custom command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *  6 : right button custom command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *  8 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define BYD_CMD_SET_PHYSICAL_BUTTONS		0x10d0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * Absolute mode (1 byte X/Y resolution)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *  0 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  *  2 : enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define BYD_CMD_SET_ABSOLUTE_MODE		0x10d1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * Two finger scrolling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *  1 : vertical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  *  2 : horizontal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  *  3 : vertical + horizontal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *  4 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define BYD_CMD_SET_TWO_FINGER_SCROLL		0x10d2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * Handedness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *  1 : right handed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  *  2 : left handed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define BYD_CMD_SET_HANDEDNESS			0x10d3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * Tap to click
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *  1 : enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *  2 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define BYD_CMD_SET_TAP				0x10d4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Tap and drag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  *  1 : tap and hold to drag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  *  2 : tap and hold to drag + lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  *  3 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define BYD_CMD_SET_TAP_DRAG			0x10d5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * Touch sensitivity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  *  1 - 7 : least to most sensitive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define BYD_CMD_SET_TOUCH_SENSITIVITY		0x10d6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * One finger scrolling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *  1 : vertical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *  2 : horizontal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *  3 : vertical + horizontal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  *  4 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define BYD_CMD_SET_ONE_FINGER_SCROLL		0x10d7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * One finger scrolling function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *  1 : free scrolling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *  2 : edge motion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  *  3 : free scrolling + edge motion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  *  4 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define BYD_CMD_SET_ONE_FINGER_SCROLL_FUNC	0x10d8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * Sliding speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *  1 - 5 : slowest to fastest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define BYD_CMD_SET_SLIDING_SPEED		0x10da
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * Edge motion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  *  1 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  *  2 : enable when dragging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  *  3 : enable when dragging and pointing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define BYD_CMD_SET_EDGE_MOTION			0x10db
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * Left edge region size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  *  0 - 7 : smallest to largest width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define BYD_CMD_SET_LEFT_EDGE_REGION		0x10dc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * Top edge region size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *  0 - 9 : smallest to largest height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define BYD_CMD_SET_TOP_EDGE_REGION		0x10dd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * Disregard palm press as clicks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  *  1 - 6 : smallest to largest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define BYD_CMD_SET_PALM_CHECK			0x10de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * Right edge region size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *  0 - 7 : smallest to largest width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #define BYD_CMD_SET_RIGHT_EDGE_REGION		0x10df
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * Bottom edge region size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  *  0 - 9 : smallest to largest height
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define BYD_CMD_SET_BOTTOM_EDGE_REGION		0x10e1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * Multitouch gestures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  *  1 : enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  *  2 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define BYD_CMD_SET_MULTITOUCH			0x10e3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * Edge motion speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *  0 : control with finger pressure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *  1 - 9 : slowest to fastest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #define BYD_CMD_SET_EDGE_MOTION_SPEED		0x10e4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * Two finger scolling function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *  0 : free scrolling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  *  1 : free scrolling (with momentum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *  2 : edge motion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *  3 : free scrolling (with momentum) + edge motion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  *  4 : disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define BYD_CMD_SET_TWO_FINGER_SCROLL_FUNC	0x10e5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * The touchpad generates a mixture of absolute and relative packets, indicated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * by the the last byte of each packet being set to one of the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define BYD_PACKET_ABSOLUTE			0xf8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #define BYD_PACKET_RELATIVE			0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* Multitouch gesture packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #define BYD_PACKET_PINCH_IN			0xd8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define BYD_PACKET_PINCH_OUT			0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #define BYD_PACKET_ROTATE_CLOCKWISE		0x29
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #define BYD_PACKET_ROTATE_ANTICLOCKWISE		0xd7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #define BYD_PACKET_TWO_FINGER_SCROLL_RIGHT	0x2a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define BYD_PACKET_TWO_FINGER_SCROLL_DOWN	0x2b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define BYD_PACKET_TWO_FINGER_SCROLL_UP		0xd5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #define BYD_PACKET_TWO_FINGER_SCROLL_LEFT	0xd6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define BYD_PACKET_THREE_FINGER_SWIPE_RIGHT	0x2c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define BYD_PACKET_THREE_FINGER_SWIPE_DOWN	0x2d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #define BYD_PACKET_THREE_FINGER_SWIPE_UP	0xd3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define BYD_PACKET_THREE_FINGER_SWIPE_LEFT	0xd4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #define BYD_PACKET_FOUR_FINGER_DOWN		0x33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #define BYD_PACKET_FOUR_FINGER_UP		0xcd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define BYD_PACKET_REGION_SCROLL_RIGHT		0x35
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) #define BYD_PACKET_REGION_SCROLL_DOWN		0x36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define BYD_PACKET_REGION_SCROLL_UP		0xca
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define BYD_PACKET_REGION_SCROLL_LEFT		0xcb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #define BYD_PACKET_RIGHT_CORNER_CLICK		0xd2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #define BYD_PACKET_LEFT_CORNER_CLICK		0x2e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #define BYD_PACKET_LEFT_AND_RIGHT_CORNER_CLICK	0x2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define BYD_PACKET_ONTO_PAD_SWIPE_RIGHT		0x37
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define BYD_PACKET_ONTO_PAD_SWIPE_DOWN		0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define BYD_PACKET_ONTO_PAD_SWIPE_UP		0xd0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define BYD_PACKET_ONTO_PAD_SWIPE_LEFT		0xc9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct byd_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct psmouse *psmouse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	s32 abs_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	s32 abs_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	typeof(jiffies) last_touch_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	bool btn_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	bool btn_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	bool touch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void byd_report_input(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct byd_data *priv = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	input_report_key(dev, BTN_TOUCH, priv->touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	input_report_key(dev, BTN_TOOL_FINGER, priv->touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	input_report_abs(dev, ABS_X, priv->abs_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	input_report_abs(dev, ABS_Y, priv->abs_y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	input_report_key(dev, BTN_LEFT, priv->btn_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	input_report_key(dev, BTN_RIGHT, priv->btn_right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static void byd_clear_touch(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct byd_data *priv = from_timer(priv, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct psmouse *psmouse = priv->psmouse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	serio_pause_rx(psmouse->ps2dev.serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	priv->touch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	byd_report_input(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	serio_continue_rx(psmouse->ps2dev.serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 * Move cursor back to center of pad when we lose touch - this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	 * specifically improves user experience when moving cursor with one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	 * finger, and pressing a button with another.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	priv->abs_x = BYD_PAD_WIDTH / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	priv->abs_y = BYD_PAD_HEIGHT / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static psmouse_ret_t byd_process_byte(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct byd_data *priv = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	u8 *pkt = psmouse->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (psmouse->pktcnt > 0 && !(pkt[0] & PS2_ALWAYS_1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		psmouse_warn(psmouse, "Always_1 bit not 1. pkt[0] = %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			     pkt[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		return PSMOUSE_BAD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (psmouse->pktcnt < psmouse->pktsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return PSMOUSE_GOOD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* Otherwise, a full packet has been received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	switch (pkt[3]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	case BYD_PACKET_ABSOLUTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		/* Only use absolute packets for the start of movement. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (!priv->touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			/* needed to detect tap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			typeof(jiffies) tap_time =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				priv->last_touch_time + BYD_TOUCH_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			priv->touch = time_after(jiffies, tap_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			/* init abs position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			priv->abs_x = pkt[1] * (BYD_PAD_WIDTH / 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			priv->abs_y = (255 - pkt[2]) * (BYD_PAD_HEIGHT / 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	case BYD_PACKET_RELATIVE: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		/* Standard packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		/* Sign-extend if a sign bit is set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		u32 signx = pkt[0] & PS2_X_SIGN ? ~0xFF : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		u32 signy = pkt[0] & PS2_Y_SIGN ? ~0xFF : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		s32 dx = signx | (int) pkt[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		s32 dy = signy | (int) pkt[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		/* Update position based on velocity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		priv->abs_x += dx * BYD_DT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		priv->abs_y -= dy * BYD_DT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		priv->touch = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		psmouse_warn(psmouse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			     "Unrecognized Z: pkt = %02x %02x %02x %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			     psmouse->packet[0], psmouse->packet[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			     psmouse->packet[2], psmouse->packet[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return PSMOUSE_BAD_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	priv->btn_left = pkt[0] & PS2_LEFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	priv->btn_right = pkt[0] & PS2_RIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	byd_report_input(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	/* Reset time since last touch. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (priv->touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		priv->last_touch_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		mod_timer(&priv->timer, jiffies + BYD_TOUCH_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return PSMOUSE_FULL_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int byd_reset_touchpad(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	struct ps2dev *ps2dev = &psmouse->ps2dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	u8 param[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		u16 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		u8 arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	} seq[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		 * Intellimouse initialization sequence, to get 4-byte instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		 * of 3-byte packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		{ PSMOUSE_CMD_SETRATE, 0xC8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		{ PSMOUSE_CMD_SETRATE, 0x64 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		{ PSMOUSE_CMD_SETRATE, 0x50 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		{ PSMOUSE_CMD_GETID, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		{ PSMOUSE_CMD_ENABLE, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		 * BYD-specific initialization, which enables absolute mode and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		 * (if desired), the touchpad's built-in gesture detection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		{ 0x10E2, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		{ 0x10E0, 0x02 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		/* The touchpad should reply with 4 seemingly-random bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		{ 0x14E0, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		/* Pairs of parameters and values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		{ BYD_CMD_SET_HANDEDNESS, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		{ BYD_CMD_SET_PHYSICAL_BUTTONS, 0x04 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		{ BYD_CMD_SET_TAP, 0x02 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		{ BYD_CMD_SET_ONE_FINGER_SCROLL, 0x04 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		{ BYD_CMD_SET_ONE_FINGER_SCROLL_FUNC, 0x04 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		{ BYD_CMD_SET_EDGE_MOTION, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		{ BYD_CMD_SET_PALM_CHECK, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		{ BYD_CMD_SET_MULTITOUCH, 0x02 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		{ BYD_CMD_SET_TWO_FINGER_SCROLL, 0x04 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		{ BYD_CMD_SET_TWO_FINGER_SCROLL_FUNC, 0x04 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		{ BYD_CMD_SET_LEFT_EDGE_REGION, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		{ BYD_CMD_SET_TOP_EDGE_REGION, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		{ BYD_CMD_SET_RIGHT_EDGE_REGION, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		{ BYD_CMD_SET_BOTTOM_EDGE_REGION, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		{ BYD_CMD_SET_ABSOLUTE_MODE, 0x02 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		/* Finalize initialization. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		{ 0x10E0, 0x00 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		{ 0x10E2, 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	for (i = 0; i < ARRAY_SIZE(seq); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		memset(param, 0, sizeof(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		param[0] = seq[i].arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		if (ps2_command(ps2dev, param, seq[i].command))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int byd_reconnect(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	int retry = 0, error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	psmouse_dbg(psmouse, "Reconnect\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		psmouse_reset(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		if (retry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			ssleep(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		error = byd_detect(psmouse, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	} while (error && ++retry < 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	psmouse_dbg(psmouse, "Reconnected after %d attempts\n", retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	error = byd_reset_touchpad(psmouse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		psmouse_err(psmouse, "Unable to initialize device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static void byd_disconnect(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	struct byd_data *priv = psmouse->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		del_timer(&priv->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		kfree(psmouse->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		psmouse->private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) int byd_detect(struct psmouse *psmouse, bool set_properties)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct ps2dev *ps2dev = &psmouse->ps2dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	u8 param[4] = {0x03, 0x00, 0x00, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	if (ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (param[1] != 0x03 || param[2] != 0x64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	psmouse_dbg(psmouse, "BYD touchpad detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (set_properties) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		psmouse->vendor = "BYD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		psmouse->name = "TouchPad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int byd_init(struct psmouse *psmouse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct input_dev *dev = psmouse->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct byd_data *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (psmouse_reset(psmouse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	if (byd_reset_touchpad(psmouse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	priv->psmouse = psmouse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	timer_setup(&priv->timer, byd_clear_touch, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	psmouse->private = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	psmouse->disconnect = byd_disconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	psmouse->reconnect = byd_reconnect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	psmouse->protocol_handler = byd_process_byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	psmouse->pktsize = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	psmouse->resync_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	__set_bit(INPUT_PROP_POINTER, dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	/* Touchpad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	__set_bit(BTN_TOUCH, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	__set_bit(BTN_TOOL_FINGER, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	/* Buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	__set_bit(BTN_LEFT, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	__set_bit(BTN_RIGHT, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	__clear_bit(BTN_MIDDLE, dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	/* Absolute position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	__set_bit(EV_ABS, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	input_set_abs_params(dev, ABS_X, 0, BYD_PAD_WIDTH, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	input_set_abs_params(dev, ABS_Y, 0, BYD_PAD_HEIGHT, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	input_abs_set_res(dev, ABS_X, BYD_PAD_RESOLUTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	input_abs_set_res(dev, ABS_Y, BYD_PAD_RESOLUTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	/* No relative support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	__clear_bit(EV_REL, dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	__clear_bit(REL_X, dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	__clear_bit(REL_Y, dev->relbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }