Skip to content

Commit 5e13bea

Browse files
committed
Input: cypress_ps2 - use u8 when dealing with byte data
When dealing with byte data use u8 instead of unsigned char or int. Stop layering error handling in cypress_ps2_sendbyte() and simply pass on error code from ps2_sendbyte(). Additionally use u8 instead of unisgned char throughout the code. Link: https://lore.kernel.org/r/20240628224728.2180126-5-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 93f25f9 commit 5e13bea

1 file changed

Lines changed: 34 additions & 44 deletions

File tree

drivers/input/mouse/cypress_ps2.c

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,30 @@ static void cypress_set_packet_size(struct psmouse *psmouse, unsigned int n)
3232
cytp->pkt_size = n;
3333
}
3434

35-
static const unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200};
36-
static const unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};
35+
static const u8 cytp_rate[] = {10, 20, 40, 60, 100, 200};
36+
static const u8 cytp_resolution[] = {0x00, 0x01, 0x02, 0x03};
3737

38-
static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value)
38+
static int cypress_ps2_sendbyte(struct psmouse *psmouse, u8 cmd)
3939
{
4040
struct ps2dev *ps2dev = &psmouse->ps2dev;
4141
int error;
4242

43-
error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT);
43+
error = ps2_sendbyte(ps2dev, cmd, CYTP_CMD_TIMEOUT);
4444
if (error) {
4545
psmouse_dbg(psmouse,
4646
"sending command 0x%02x failed, resp 0x%02x, error %d\n",
47-
value & 0xff, ps2dev->nak, error);
47+
cmd, ps2dev->nak, error);
4848
return error;
4949
}
5050

5151
#ifdef CYTP_DEBUG_VERBOSE
52-
psmouse_dbg(psmouse, "sending command 0x%02x succeeded, resp 0xfa\n",
53-
value & 0xff);
52+
psmouse_dbg(psmouse, "sending command 0x%02x succeeded\n", cmd);
5453
#endif
5554

5655
return 0;
5756
}
5857

59-
static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
60-
unsigned char data)
58+
static int cypress_ps2_ext_cmd(struct psmouse *psmouse, u8 prefix, u8 nibble)
6159
{
6260
struct ps2dev *ps2dev = &psmouse->ps2dev;
6361
int tries = CYTP_PS2_CMD_TRIES;
@@ -71,17 +69,17 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
7169
* If sending the command fails, send recovery command
7270
* to make the device return to the ready state.
7371
*/
74-
rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff);
72+
rc = cypress_ps2_sendbyte(psmouse, prefix);
7573
if (rc == -EAGAIN) {
7674
rc = cypress_ps2_sendbyte(psmouse, 0x00);
7775
if (rc == -EAGAIN)
7876
rc = cypress_ps2_sendbyte(psmouse, 0x0a);
7977
}
8078

8179
if (!rc) {
82-
rc = cypress_ps2_sendbyte(psmouse, data);
80+
rc = cypress_ps2_sendbyte(psmouse, nibble);
8381
if (rc == -EAGAIN)
84-
rc = cypress_ps2_sendbyte(psmouse, data);
82+
rc = cypress_ps2_sendbyte(psmouse, nibble);
8583

8684
if (!rc)
8785
break;
@@ -94,8 +92,7 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd,
9492
}
9593

9694
static int cypress_ps2_read_cmd_status(struct psmouse *psmouse,
97-
unsigned char cmd,
98-
unsigned char *param)
95+
u8 cmd, u8 *param)
9996
{
10097
struct ps2dev *ps2dev = &psmouse->ps2dev;
10198
enum psmouse_state old_state;
@@ -111,7 +108,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse,
111108
pktsize = (cmd == CYTP_CMD_READ_TP_METRICS) ? 8 : 3;
112109
memset(param, 0, pktsize);
113110

114-
rc = cypress_ps2_sendbyte(psmouse, 0xe9);
111+
rc = cypress_ps2_sendbyte(psmouse, PSMOUSE_CMD_GETINFO & 0xff);
115112
if (rc)
116113
goto out;
117114

@@ -136,8 +133,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse,
136133
return rc;
137134
}
138135

139-
static bool cypress_verify_cmd_state(struct psmouse *psmouse,
140-
unsigned char cmd, unsigned char *param)
136+
static bool cypress_verify_cmd_state(struct psmouse *psmouse, u8 cmd, u8* param)
141137
{
142138
bool rate_match = false;
143139
bool resolution_match = false;
@@ -167,31 +163,24 @@ static bool cypress_verify_cmd_state(struct psmouse *psmouse,
167163
return false;
168164
}
169165

170-
static int cypress_send_ext_cmd(struct psmouse *psmouse, unsigned char cmd,
171-
unsigned char *param)
166+
static int cypress_send_ext_cmd(struct psmouse *psmouse, u8 cmd, u8 *param)
172167
{
168+
u8 cmd_prefix = PSMOUSE_CMD_SETRES & 0xff;
173169
int tries = CYTP_PS2_CMD_TRIES;
174-
int rc;
170+
int error;
175171

176172
psmouse_dbg(psmouse, "send extension cmd 0x%02x, [%d %d %d %d]\n",
177173
cmd, DECODE_CMD_AA(cmd), DECODE_CMD_BB(cmd),
178174
DECODE_CMD_CC(cmd), DECODE_CMD_DD(cmd));
179175

180176
do {
181-
cypress_ps2_ext_cmd(psmouse,
182-
PSMOUSE_CMD_SETRES, DECODE_CMD_DD(cmd));
183-
cypress_ps2_ext_cmd(psmouse,
184-
PSMOUSE_CMD_SETRES, DECODE_CMD_CC(cmd));
185-
cypress_ps2_ext_cmd(psmouse,
186-
PSMOUSE_CMD_SETRES, DECODE_CMD_BB(cmd));
187-
cypress_ps2_ext_cmd(psmouse,
188-
PSMOUSE_CMD_SETRES, DECODE_CMD_AA(cmd));
189-
190-
rc = cypress_ps2_read_cmd_status(psmouse, cmd, param);
191-
if (rc)
192-
continue;
193-
194-
if (cypress_verify_cmd_state(psmouse, cmd, param))
177+
cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_DD(cmd));
178+
cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_CC(cmd));
179+
cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_BB(cmd));
180+
cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_AA(cmd));
181+
182+
error = cypress_ps2_read_cmd_status(psmouse, cmd, param);
183+
if (!error && cypress_verify_cmd_state(psmouse, cmd, param))
195184
return 0;
196185

197186
} while (--tries > 0);
@@ -201,7 +190,7 @@ static int cypress_send_ext_cmd(struct psmouse *psmouse, unsigned char cmd,
201190

202191
int cypress_detect(struct psmouse *psmouse, bool set_properties)
203192
{
204-
unsigned char param[3];
193+
u8 param[3];
205194

206195
if (cypress_send_ext_cmd(psmouse, CYTP_CMD_READ_CYPRESS_ID, param))
207196
return -ENODEV;
@@ -221,7 +210,7 @@ int cypress_detect(struct psmouse *psmouse, bool set_properties)
221210
static int cypress_read_fw_version(struct psmouse *psmouse)
222211
{
223212
struct cytp_data *cytp = psmouse->private;
224-
unsigned char param[3];
213+
u8 param[3];
225214

226215
if (cypress_send_ext_cmd(psmouse, CYTP_CMD_READ_CYPRESS_ID, param))
227216
return -ENODEV;
@@ -250,7 +239,7 @@ static int cypress_read_fw_version(struct psmouse *psmouse)
250239
static int cypress_read_tp_metrics(struct psmouse *psmouse)
251240
{
252241
struct cytp_data *cytp = psmouse->private;
253-
unsigned char param[8];
242+
u8 param[8];
254243

255244
/* set default values for tp metrics. */
256245
cytp->tp_width = CYTP_DEFAULT_WIDTH;
@@ -338,7 +327,7 @@ static int cypress_query_hardware(struct psmouse *psmouse)
338327
static int cypress_set_absolute_mode(struct psmouse *psmouse)
339328
{
340329
struct cytp_data *cytp = psmouse->private;
341-
unsigned char param[3];
330+
u8 param[3];
342331
int error;
343332

344333
error = cypress_send_ext_cmd(psmouse, CYTP_CMD_ABS_WITH_PRESSURE_MODE,
@@ -418,9 +407,9 @@ static int cypress_set_input_params(struct input_dev *input,
418407
return 0;
419408
}
420409

421-
static int cypress_get_finger_count(unsigned char header_byte)
410+
static int cypress_get_finger_count(u8 header_byte)
422411
{
423-
unsigned char bits6_7;
412+
u8 bits6_7;
424413
int finger_count;
425414

426415
bits6_7 = header_byte >> 6;
@@ -445,10 +434,11 @@ static int cypress_get_finger_count(unsigned char header_byte)
445434

446435

447436
static int cypress_parse_packet(struct psmouse *psmouse,
448-
struct cytp_data *cytp, struct cytp_report_data *report_data)
437+
struct cytp_data *cytp,
438+
struct cytp_report_data *report_data)
449439
{
450-
unsigned char *packet = psmouse->packet;
451-
unsigned char header_byte = packet[0];
440+
u8 *packet = psmouse->packet;
441+
u8 header_byte = packet[0];
452442

453443
memset(report_data, 0, sizeof(struct cytp_report_data));
454444

@@ -563,7 +553,7 @@ static psmouse_ret_t cypress_validate_byte(struct psmouse *psmouse)
563553
{
564554
int contact_cnt;
565555
int index = psmouse->pktcnt - 1;
566-
unsigned char *packet = psmouse->packet;
556+
u8 *packet = psmouse->packet;
567557
struct cytp_data *cytp = psmouse->private;
568558

569559
if (index < 0 || index > cytp->pkt_size)

0 commit comments

Comments
 (0)