From patchwork Fri Jun 28 22:47:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 808433 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95678374F6; Fri, 28 Jun 2024 22:47:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614859; cv=none; b=lQ6nejEofnEJJzLtanJStlN/n1uBiASGz3X03PmrSL66DrXqNpgqb4ZAxCp/w3fT2G1c/u4Uyo0B7kOeMeybQr0oq74HxOxKbybfe4wWRQuHPBebIWvrcaWt2QYXd4e/cuW++KHiH4YcdZUvH52Z6k9OIKU4m9Ph0WOLKjJ3uaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614859; c=relaxed/simple; bh=VjjujlCVFcHz2nze48uuOYdNp99HkR1aJ2t0p77G3vo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ifVewnjoagr7peBl+ckAThNzgWhQYKxjC/bJyUTQ7uOn/8OzAqpWKUepB+j4Obmq9f8SsOCIE+BKI7W4KSgdXwNJthxOH0qGleoZwwMAVMPaQIG2RegkdMNaeSuU88FDSK4U7p3sXH5o/Equm6h4h95YvDZIsOEz9HUEaoPo0zc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HOeHdQBi; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HOeHdQBi" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2c70c372755so858680a91.1; Fri, 28 Jun 2024 15:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719614857; x=1720219657; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=C65iYCiYAPW1ZdKuKBfIjw9waLCg7LXK5ZuuXcqO96E=; b=HOeHdQBiPlFUtYwThxvqFZ7CNuzVcdg5WxThHQRpWS7irTO54a8GP3/f0PWGfdCxri KtK4ckVnSmpDndroXQD1tGkw7WTxrbQsfS71tel3sGsqcxeKDUEWW6RYsLmN1jI95h54 2SFhrTcPZgwLeXVMmKzZVr1+JTVPbyPlbdvKQFon0esCCyipUY+5LELlCX2AsOMsSZa2 zIhMSDhfcn+JVm6eYqtb0XYYACu4+Jdb1qEmyMqLU4p3Dkjor9MPRYrg8ESoYrWU/zRS lmvfLtuHPbk+48tita2Zaejclj/HNStDaqYU4h1dECuYJ2VJo4jddyXelMZI+j995Jpj Nf/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719614857; x=1720219657; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=C65iYCiYAPW1ZdKuKBfIjw9waLCg7LXK5ZuuXcqO96E=; b=UoUQxNZJZWHM1eN3/qo/e07Wsw6cxeMbp8PzD+2Sg4/1OIK5djBTTTgp/RGaH8/AyM sbCNZ13wWvYd6l7QDzl5sTd0KYRI2F9cu5BLrSgTK4Zr4SVEAqP4AA5KswIaNXGlRzvs oMLKsjQ6Sd7EhVix+NshTr49AWIw9ZxblsE0FPocJA8Vi3LVoVbY8avcO//Q6tPYsC3T al7FvrrLrFmAX1VSE+lISsW2UZg3OPdYFQ+qWMI5Gat3D1I0a7dbnQVct12Y8MROqeyD 2zCZmjeKQJXGe2fsuufxnNyRbkmtERb5q+U2c2zA1kMmgOa055q8M8KK/ZxnnZ+IFEwu fXIQ== X-Gm-Message-State: AOJu0YyxmRXvhbO/sMTVNOKU8Ze02GgEg1F21ANbwNZk7mGwP5kvFJYF EMokmbekM6dzCKzV0FGRpTSrdv53cZBKT13M7u8RIlSgTRLIr3EAoukCPw== X-Google-Smtp-Source: AGHT+IG2ibJMUsuW/RAww0S7aXD48nptuMYJbS/NsA8uub/9qUsG1O75gWKKCAQVT7+TU0itlTurDQ== X-Received: by 2002:a17:90a:77c4:b0:2c7:cfdb:7789 with SMTP id 98e67ed59e1d1-2c8612a60demr14319885a91.16.1719614856419; Fri, 28 Jun 2024 15:47:36 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:9c98:1988:ce15:c0ac]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm2187163a91.24.2024.06.28.15.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 15:47:36 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/5] Input: cypress_ps2 - clean up setting reporting rate Date: Fri, 28 Jun 2024 15:47:23 -0700 Message-ID: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Casting an integer field containing desired rate to a pointer to bytes works on little endian architectures where the driver is used, but not a good practice. Use a temporary of proper type instead. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index c693130bef41..32b55b2b9b76 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -612,6 +612,7 @@ static psmouse_ret_t cypress_protocol_handler(struct psmouse *psmouse) static void cypress_set_rate(struct psmouse *psmouse, unsigned int rate) { struct cytp_data *cytp = psmouse->private; + u8 rate_param; if (rate >= 80) { psmouse->rate = 80; @@ -621,8 +622,8 @@ static void cypress_set_rate(struct psmouse *psmouse, unsigned int rate) cytp->mode &= ~CYTP_BIT_HIGH_RATE; } - ps2_command(&psmouse->ps2dev, (unsigned char *)&psmouse->rate, - PSMOUSE_CMD_SETRATE); + rate_param = (u8)rate; + ps2_command(&psmouse->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE); } static void cypress_disconnect(struct psmouse *psmouse) From patchwork Fri Jun 28 22:47:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 808570 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C5B91878; Fri, 28 Jun 2024 22:47:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614860; cv=none; b=Lgf1pjGDMyu2XBKHxHcJeZtfBLxk5rmFW+/Ys7ag4CDwao9b1W9cF6xUAEvEfZecZDuI657v8d0YV6RbTd/MAd1aFdys0gKYO1m4ZL5VfTcknRfNQ2JBnglKlXm+gvcUuUpiPr6Iz02E5Qzp5EAWZLFarqGZGxP+sKuXGAnRJa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614860; c=relaxed/simple; bh=3HIqvIYUAQL50HyfJ4OI6Kxr8Eqop7cMJtS61eP4Sck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SRZ9qmBHU04fde2x7kVMvQ9WwjLLj98/m8oNXjXdltDBWYJKmAO3+FuqKp4MGCCFiTT9mkQ342fKm+0SXhsQ8sgTKbZ0S/yCyl45ItM8UmoUjQHam+vOEk+V+2TjnKpvJaQ22ZV7ObhCpslzAP1cVc+Z5LA+xSnvHED1ePGATYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=glDK0p7p; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="glDK0p7p" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f65a3abd01so8016375ad.3; Fri, 28 Jun 2024 15:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719614857; x=1720219657; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eru8IeZwD6XePaAEBRnTFg580BiWX6RJC2I+6NuvGFY=; b=glDK0p7pitK1kkNqx6o8UwmMDpvXQY+T/v4agcNnQIncNcmCVANCG614cwTRC7Br+N gZt7SBFwjTPQIksV/PcjkgQFZx60jEnZ/P2Z+a/y7og/l9k7ShW2aRD9mSZOxT9LOVly 9OxIks8+8s3SQrUEp1fLN6NIVci58R4DLjP7DoPCT+kUc28jRWN8R+IgkJv/0EzE+l/I cDJ3bKDPwfw0bVkENM+ETC9ANUiXJ3KCrACnJJVNga4WsxtnyQiqEoy1pY+zs2u6n0YO Y5BwbmC+mOKHVSvMAqUaNw8PhQxxziLQTjTI1apr00LBrsP2nlgUkK66vsX/fgFdoxq5 VNCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719614857; x=1720219657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eru8IeZwD6XePaAEBRnTFg580BiWX6RJC2I+6NuvGFY=; b=ie4lkF2gmPu2hh+mzX2PToKzDwG3hlizfO3faMf9uX1z3g50jLaUe8ZNMgK75N+2ef LpV90VG5FObLzogK01ybjOqGRkrujfs6wdS0jxOB1hw++YJfV6ZnGNIJ4/xoFORzuu/A /aTkXkWLQ5JXkMcNPiDlk5afzUCjbUmSl7/Y8iSbBE0R/ZHZAQ0dRdcerZIhnRXmNFZT vuQo/5pFYMfQqccNFo9nt+ZTqeTR8jaO3jGPGC8pjETt/rtaO0SLzhAb25k50gUXoNDc xKCx4axiW6moBuEFXFlVpqocYiMG69VaOU8EEoVG5VZK7XMkYyyGu5LlnGp5zy725Ydg 21Mg== X-Gm-Message-State: AOJu0YzI36alv5I888DIuD3l1NvBMsYIKV86pliXSjw0loiQWrZpgryv o73//jqa7jfjmcdZDZ1eB1XRIDu1TxBFUNHnGX3d3R1ejj8DmiZWG6T0AQ== X-Google-Smtp-Source: AGHT+IGdczk/zd9Cfyxa9Tm4aTvvfasnp2SxFSkrROiPFSDGPpPOAQkOXAnR492T0B/wLaubwvtIAg== X-Received: by 2002:a05:6a21:99a7:b0:1bd:2d02:b219 with SMTP id adf61e73a8af0-1becd4c0663mr10103866637.1.1719614857163; Fri, 28 Jun 2024 15:47:37 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:9c98:1988:ce15:c0ac]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm2187163a91.24.2024.06.28.15.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 15:47:36 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Igor Artemiev Subject: [PATCH 2/5] Input: cypress_ps2 - fix error handling when sending command fails Date: Fri, 28 Jun 2024 15:47:24 -0700 Message-ID: <20240628224728.2180126-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> References: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Stop layering error handling in cypress_ps2_sendbyte() and simply pass on error code from ps2_sendbyte() and use it in the callers. This fixes mishandling of error condition in cypress_ps2_read_cmd_status() which expects errors to be negative. Reported-by: Igor Artemiev Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 32 +++++++++++++++---------------- drivers/input/mouse/cypress_ps2.h | 6 ------ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 32b55b2b9b76..fcc3921e49e0 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -38,15 +38,14 @@ static const unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03}; static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value) { struct ps2dev *ps2dev = &psmouse->ps2dev; + int error; - if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) { + error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT); + if (error) { psmouse_dbg(psmouse, - "sending command 0x%02x failed, resp 0x%02x\n", - value & 0xff, ps2dev->nak); - if (ps2dev->nak == CYTP_PS2_RETRY) - return CYTP_PS2_RETRY; - else - return CYTP_PS2_ERROR; + "sending command 0x%02x failed, resp 0x%02x, error %d\n", + value & 0xff, ps2dev->nak, error); + return error; } #ifdef CYTP_DEBUG_VERBOSE @@ -73,21 +72,20 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, * to make the device return to the ready state. */ rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff); - if (rc == CYTP_PS2_RETRY) { + if (rc == -EAGAIN) { rc = cypress_ps2_sendbyte(psmouse, 0x00); - if (rc == CYTP_PS2_RETRY) + if (rc == -EAGAIN) rc = cypress_ps2_sendbyte(psmouse, 0x0a); } - if (rc == CYTP_PS2_ERROR) - continue; - rc = cypress_ps2_sendbyte(psmouse, data); - if (rc == CYTP_PS2_RETRY) + if (!rc) { rc = cypress_ps2_sendbyte(psmouse, data); - if (rc == CYTP_PS2_ERROR) - continue; - else - break; + if (rc == -EAGAIN) + rc = cypress_ps2_sendbyte(psmouse, data); + + if (!rc) + break; + } } while (--tries > 0); ps2_end_command(ps2dev); diff --git a/drivers/input/mouse/cypress_ps2.h b/drivers/input/mouse/cypress_ps2.h index bb4979d06bf9..47d538a49089 100644 --- a/drivers/input/mouse/cypress_ps2.h +++ b/drivers/input/mouse/cypress_ps2.h @@ -72,12 +72,6 @@ #define CYTP_DATA_TIMEOUT 30 #define CYTP_EXT_CMD 0xe8 -#define CYTP_PS2_RETRY 0xfe -#define CYTP_PS2_ERROR 0xfc - -#define CYTP_RESP_RETRY 0x01 -#define CYTP_RESP_ERROR 0xfe - #define CYTP_105001_WIDTH 97 /* Dell XPS 13 */ #define CYTP_105001_HIGH 59 From patchwork Fri Jun 28 22:47:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 808432 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D62957710F; Fri, 28 Jun 2024 22:47:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614860; cv=none; b=bKfgWvIv5YwcK/nhPVYQCdDuIEcrfCAt0/igWsEPTfrrWgVrnXcxIic6V3bFmFiIE+coh5H5UXwrfm062dmO2SX/Mz3BQI/5/4CaOt3fitqUhfwc9T9+0DlD2VsOoEImhCoctvqy5ebBJ3y3xtFsH0SslwkllN2z5WEYe/BTFpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614860; c=relaxed/simple; bh=Q4E71o09lIMNcgDY5btbMXU0Xfz4FaS1Bb48PBZdZgM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aemBYvPBG1whUy0ASR4Adi6ajIRzPVTqHV3Z+QXD3lfTDLwFDDzj4ojhqfez/T8cfoo4vTTtlNFMnQ+cHNbwBeOOpezHCbJItfj3Nis5JiwursphC8Yr1yBir0aFfPuu0DD/hghxVDsb4vIzztiqidpuSPuxScWGq3D6gVGPDBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QIO5DiGa; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QIO5DiGa" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2c9015b075bso1644139a91.1; Fri, 28 Jun 2024 15:47:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719614858; x=1720219658; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h5A3XKf+a9Yvo+n5TD1I8PnKFpNkJknS2WF7vO0WiSw=; b=QIO5DiGauKkl46iDkO1AqP7mall1fsBP66swNrs47hZBDdXZHXhU+euaagNZnkUVGs NXE4UyYnPYg66s1hq8d3zie3hM9F6KdPdAAiqKysiCVdwmyzFQRfH5fcSMUKUmN/ZBCS HVV0Q5SjUvtoJqZk/IQPrr2w9kJkvH+Dm9C84dtGi2NMf2lXlf8KoNgOLriqFqQgcusb GNnIxyd4DWl8yxlntuClhm1szwcCyfZgs2g45UdTTDi01sC9hrtMUWKz83zvcYIKOSW2 uyt++sMR3ohqNn9GB3AzbIm51KScjmuuIza260dfqjVvsBnpYEkxY/5NYwsMY3BoOsXp EGnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719614858; x=1720219658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h5A3XKf+a9Yvo+n5TD1I8PnKFpNkJknS2WF7vO0WiSw=; b=IilIZR8fRTcwAcOdtcPazXOSu29knhISaV1bAHKwTEY0DmOUgIHFfoUfHd/VRVwGfT 82wqAl0PTsBmzHvMoEkDkEtrE/RKj4JCHbYW/yqlY/bniW6C1Mv+mVZ8adr4gzkGdJ3a 2Lc/PGIsi8qwYSPQIPtTPVKii52Xa1a6vWs4tQ5unF2zUUtXGqCH5UxUZ9A1NxuH6SJZ cKGt7TruZHp6K9QFhrO8lqqQ50ViRTQEvWD10GKltqGx9cKFLXOWIw77LNSg0DKQv3pZ Gi50Vq0vBsMs7HNP7DRNFNwvoKBb0HTWLuiKDwPuNXziblCf2IUnP5NvEo8J9Nqda/zF bVDQ== X-Gm-Message-State: AOJu0YyEUvWzGUm4tmw09esD6DUnQXiPgdNRHgTPGQp028mzigkzwAQ+ 5mJjtQa9haHVTTH1oXXhCIhTWLpF2HpsFQg1ldfAVZ8RyKLnOQR1s7pTwQ== X-Google-Smtp-Source: AGHT+IHOU7PhTa7Pp6yBxsRL5SMJ4peVWAbU2vg1Kj8MDnvjlz+jvWb0UrrqgPfKoz0LV4CTpQI5BQ== X-Received: by 2002:a17:90a:9af:b0:2c8:da9e:6f63 with SMTP id 98e67ed59e1d1-2c92803af4bmr4521630a91.23.1719614857822; Fri, 28 Jun 2024 15:47:37 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:9c98:1988:ce15:c0ac]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm2187163a91.24.2024.06.28.15.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 15:47:37 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/5] Input: cypress_ps2 - report timeouts when reading command status Date: Fri, 28 Jun 2024 15:47:25 -0700 Message-ID: <20240628224728.2180126-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> References: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Report -ETIMEDOUT error code from cypress_ps2_read_cmd_status() when device does not send enough data within the allotted time in response to a command. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index fcc3921e49e0..8e17cd0bc437 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -115,9 +115,12 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, if (rc < 0) goto out; - wait_event_timeout(ps2dev->wait, - (psmouse->pktcnt >= pktsize), - msecs_to_jiffies(CYTP_CMD_TIMEOUT)); + if (!wait_event_timeout(ps2dev->wait, + psmouse->pktcnt >= pktsize, + msecs_to_jiffies(CYTP_CMD_TIMEOUT))) { + rc = -ETIMEDOUT; + goto out; + } memcpy(param, psmouse->packet, pktsize); From patchwork Fri Jun 28 22:47:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 808569 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 318F581ADB; Fri, 28 Jun 2024 22:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614861; cv=none; b=i14HiMlxwejWANLDcxcwtg2ATXnE9jOnhInVO5+brRcqdHlw2FZgiXmluntmd5DxRb36R6HIMxOi6h0sdox0Bz/39Wx0AqBaJ+TXsxQtje5FI3W3fjZufTLUqckzDO+Tq8NLtAHqzTGsYC+JcNFgNpYTaOKZCsCLGgELW4WnKGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614861; c=relaxed/simple; bh=bxWyiBWYPW2+buNmHaUgN3u/vnNpNcPGkK464MtKleM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JGW+nTTvTzLerYw0wLQofkzK0l3QGnHZEYchZpzSu9Vi5Pijd6n1h8htD7KKgtRGAdHXyQifKJRumDYDpEMrgp4GsRltsN5r58d/jJjGf0OU71JNvMMs86t43fJN/c/zLQjDZcmFGw7Ml7pwYfxfBWLacvziRmDVOaXukzwbZLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bb+chhMb; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bb+chhMb" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2c7b3c513f9so743094a91.3; Fri, 28 Jun 2024 15:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719614859; x=1720219659; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=grngmqCY15ZFkaN4yPlMDR3cMPW3TlCebrSNgkV3ENk=; b=Bb+chhMbmcEMyy/Q8sdQM17DpjBa9u+O4qNdRX5Xbj9sk/UXkpKhx6mfPm1f8aiDQN H6vsRCCL33e1b2SIJuYA6ph4AwUUJLZBW+IJtRJ9iPsldNHXUWU4lahwqqM0HHzFazKR Eqeb7i7uexB9tKChhp8VpkHgPxEYOzg9Zzh2TuVvo81nVSm6Bi8y3KhbkJvdTbMH2uKT 5UKewVvSEcGuaYYZJ5a5XAXqR6c0xZ0MAR3FJpP0LrgssJyYjlFbP33dR3vEx05QOHPF f+vBDeLsEKB/ypdA7uwsJoK/Wd3g5sbOumi0gBAevsKFQZ3Vm3mDFwLeygVqcXEtCAAA Vqqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719614859; x=1720219659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=grngmqCY15ZFkaN4yPlMDR3cMPW3TlCebrSNgkV3ENk=; b=G0uUcWHUUUNXqmpfc4B5U+zVdN1lqjPNxmMpAHVOgAG4m2vfxrIBoEKlJ1u30J2e8A C/jzCzsCkv70zXFHodR92L5rSAJsama7LffpkImFexUYR3S8lHY+tAwAm/TKqx2OYkIv YryShXvx0kXrDH8lzOVTa9dc0Yl9icTuS9PVHPIoOV7TOgdi0DgBhHbJBdBphEKioF0F zONSGdbNqJBdcWv7cGf/E+zY3Wca+bo0T3EsTPrt+FGjiAWq2Rkt4c8svjSQ6Jj7Tkyu 5BhpJWCRT/Fd/HNZB6CVeduzE535qiAU0oYHmXd8sIkDLaHLbyZixXVvTzjdp6hPmfej qyTw== X-Gm-Message-State: AOJu0YzmNsGRXzKz+00Wz6e9kJbJhAko5TPqT7Ihp0fajXo+yMjjCWXh Ln4dcn/k1o6TQDtHMUBcB7PgYnVeC3LZOwBjt0+nA1ImtxuAPqNefPJ7ig== X-Google-Smtp-Source: AGHT+IFErHAjL8SN0MVSSUbo2xu2yuSye8VDkA/wXgIw9DoTE0ztbxvz5WvoFCTpkA55oUWttegjxw== X-Received: by 2002:a17:90a:3fc6:b0:2c7:da20:524b with SMTP id 98e67ed59e1d1-2c8504c7dbamr15211307a91.10.1719614859146; Fri, 28 Jun 2024 15:47:39 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:9c98:1988:ce15:c0ac]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm2187163a91.24.2024.06.28.15.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 15:47:38 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 4/5] Input: cypress_ps2 - propagate errors from lower layers Date: Fri, 28 Jun 2024 15:47:26 -0700 Message-ID: <20240628224728.2180126-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> References: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not override errors reported by lower layers with generic "-1", but propagate them to the callers. Change the checks for errors to be in the form of "if (error)" to maintain consistency. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 62 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 8e17cd0bc437..87b87f14e749 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -97,10 +97,10 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, unsigned char cmd, unsigned char *param) { - int rc; struct ps2dev *ps2dev = &psmouse->ps2dev; enum psmouse_state old_state; int pktsize; + int rc; ps2_begin_command(ps2dev); @@ -112,7 +112,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, memset(param, 0, pktsize); rc = cypress_ps2_sendbyte(psmouse, 0xe9); - if (rc < 0) + if (rc) goto out; if (!wait_event_timeout(ps2dev->wait, @@ -322,15 +322,15 @@ static int cypress_read_tp_metrics(struct psmouse *psmouse) static int cypress_query_hardware(struct psmouse *psmouse) { - int ret; + int error; - ret = cypress_read_fw_version(psmouse); - if (ret) - return ret; + error = cypress_read_fw_version(psmouse); + if (error) + return error; - ret = cypress_read_tp_metrics(psmouse); - if (ret) - return ret; + error = cypress_read_tp_metrics(psmouse); + if (error) + return error; return 0; } @@ -339,9 +339,12 @@ static int cypress_set_absolute_mode(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; unsigned char param[3]; + int error; - if (cypress_send_ext_cmd(psmouse, CYTP_CMD_ABS_WITH_PRESSURE_MODE, param) < 0) - return -1; + error = cypress_send_ext_cmd(psmouse, CYTP_CMD_ABS_WITH_PRESSURE_MODE, + param); + if (error) + return error; cytp->mode = (cytp->mode & ~CYTP_BIT_ABS_REL_MASK) | CYTP_BIT_ABS_PRESSURE; @@ -366,7 +369,7 @@ static void cypress_reset(struct psmouse *psmouse) static int cypress_set_input_params(struct input_dev *input, struct cytp_data *cytp) { - int ret; + int error; if (!cytp->tp_res_x || !cytp->tp_res_y) return -EINVAL; @@ -383,10 +386,10 @@ static int cypress_set_input_params(struct input_dev *input, input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cytp->tp_max_abs_y, 0, 0); input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0); - ret = input_mt_init_slots(input, CYTP_MAX_MT_SLOTS, - INPUT_MT_DROP_UNUSED|INPUT_MT_TRACK); - if (ret < 0) - return ret; + error = input_mt_init_slots(input, CYTP_MAX_MT_SLOTS, + INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK); + if (error) + return error; __set_bit(INPUT_PROP_SEMI_MT, input->propbit); @@ -637,21 +640,22 @@ static void cypress_disconnect(struct psmouse *psmouse) static int cypress_reconnect(struct psmouse *psmouse) { int tries = CYTP_PS2_CMD_TRIES; - int rc; + int error; do { cypress_reset(psmouse); - rc = cypress_detect(psmouse, false); - } while (rc && (--tries > 0)); + error = cypress_detect(psmouse, false); + } while (error && (--tries > 0)); - if (rc) { + if (error) { psmouse_err(psmouse, "Reconnect: unable to detect trackpad.\n"); - return -1; + return error; } - if (cypress_set_absolute_mode(psmouse)) { + error = cypress_set_absolute_mode(psmouse); + if (error) { psmouse_err(psmouse, "Reconnect: Unable to initialize Cypress absolute mode.\n"); - return -1; + return error; } return 0; @@ -660,6 +664,7 @@ static int cypress_reconnect(struct psmouse *psmouse) int cypress_init(struct psmouse *psmouse) { struct cytp_data *cytp; + int error; cytp = kzalloc(sizeof(*cytp), GFP_KERNEL); if (!cytp) @@ -670,17 +675,20 @@ int cypress_init(struct psmouse *psmouse) cypress_reset(psmouse); - if (cypress_query_hardware(psmouse)) { + error = cypress_query_hardware(psmouse); + if (error) { psmouse_err(psmouse, "Unable to query Trackpad hardware.\n"); goto err_exit; } - if (cypress_set_absolute_mode(psmouse)) { + error = cypress_set_absolute_mode(psmouse); + if (error) { psmouse_err(psmouse, "init: Unable to initialize Cypress absolute mode.\n"); goto err_exit; } - if (cypress_set_input_params(psmouse->dev, cytp) < 0) { + error = cypress_set_input_params(psmouse->dev, cytp); + if (error) { psmouse_err(psmouse, "init: Unable to set input params.\n"); goto err_exit; } @@ -705,5 +713,5 @@ int cypress_init(struct psmouse *psmouse) psmouse->private = NULL; kfree(cytp); - return -1; + return error; } From patchwork Fri Jun 28 22:47:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 808431 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EA2385285; Fri, 28 Jun 2024 22:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614863; cv=none; b=CCF5mBNp00VLL6A/HmNRskpKiCjTv81+23ppYeUkgKUj6exCWXUhciaPRJ1//W/9dV7HDORegsFXdLd0J3++x7jceh2/TAerV69d7oq3FvBqS5QKDoQdhPGXF8yn4CKwIiombdxPWard3VXX6Rf+mEZDANeUS0Mm9cvKv71P0yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719614863; c=relaxed/simple; bh=+8nNly24xuCx20eSYpE+qDD01oAcNayYe8T7Y/xuscw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OlDw/8t4yVoNn2qCQ4cZC1jzddDLi8GpNDCV6bgY7ESO0J+75YN8OdOOh0frgePlCpAPZ79dduyyJQtrQNbVF+QwDwqFES/V+FEOZDX4q2juUHDoSFdrWQuqze0hDaTBgxdXKm1uxy5aQZ3aCzbfRjzvdgXihn3JbPqqTMFHfn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Af3tsJkk; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Af3tsJkk" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1fa3bdd91c1so8259325ad.2; Fri, 28 Jun 2024 15:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719614860; x=1720219660; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OFNDKpw6QkRM2hybf3Ehw0BO3Qpr8ju6XyIUPGNVdl4=; b=Af3tsJkkleq4JJJ6U2ZTRjkj7uIHACZXG7EnvG33skojnLiCZTcN5c/d5I4fAHLh2V cMtTAkmAKExrfuXQFZyj5OvSSYCXMdMF+viyVdlTmWFnUmJAyOK5Cl5/jiJ5znv+y5e4 WsGQPv1oxEk+enYmVRsPIbGLwJ9N3T3UON6LHAYFpWjKJVd4iDWx3glINt6ScUzNjivb vgwaMpW7ZnO3z0mjKhmcequuxd24EirPJOB/VNetnkCVtOrivNWcLSrjCGL651axeLFw LTUyJcZAV8/k+h3Yoov9EL/2rxg6jcKS3haEi4jxPis1AbO3/MF0If4e+1CB4H+fiFpk nL+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719614860; x=1720219660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OFNDKpw6QkRM2hybf3Ehw0BO3Qpr8ju6XyIUPGNVdl4=; b=wUvDFoT0GP4P3Nfg9gy6FQ8CoHtLeavTYnZsA6i8scCPnPJXWdYhzKd5x/wBI6H/2V lGV+2WuCuqmKNjJAbtBng7Vne7RrVqy9PEs8RTq+vlgLNuwgPVZk4yvH3OwWZfCg5htj CATSby2PADuPYpcBo9J0MbQnGNzMPGA0NXnpfm5FojhnBDYqfYp++gKYQRkWGA62R+uT l/4Li5x4oEcWKXsJ8jFi+s9Lci9++++W8QC6n1cOr1dKhBZAy/mIjkuyDTbbHWWE44US PJgpp8m6oCKecd2r5HqwhvLZ7S5QoC0ecLHO+jo3chd/UlfDM8uUkOCecWE/vNBrMvvy /1iw== X-Gm-Message-State: AOJu0YxMrxaro7n1S0PAynxka0zFcJ7MH1hezCnIgqdVkDHYgRObASAI b60X1Z1bpJ2FH37xOZ8Qd9/FA5y17szboPZkPKuWoMRq1i+DZGqVkHP5BA== X-Google-Smtp-Source: AGHT+IH1RMusHDvaC5rsF76b8ZnLdMQucMVlLxtx2vgOFFp00lGuInrqSXv51dW4moylnLYoHtxirA== X-Received: by 2002:a17:90a:d397:b0:2bf:9566:7c58 with SMTP id 98e67ed59e1d1-2c86141c69bmr15632363a91.41.1719614860509; Fri, 28 Jun 2024 15:47:40 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:9c98:1988:ce15:c0ac]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce58877sm2187163a91.24.2024.06.28.15.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 15:47:39 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/5] Input: cypress_ps2 - use u8 when dealing with byte data Date: Fri, 28 Jun 2024 15:47:27 -0700 Message-ID: <20240628224728.2180126-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> References: <20240628224728.2180126-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 78 ++++++++++++++----------------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 87b87f14e749..b3c34ebcc4ef 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -32,32 +32,30 @@ static void cypress_set_packet_size(struct psmouse *psmouse, unsigned int n) cytp->pkt_size = n; } -static const unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200}; -static const unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03}; +static const u8 cytp_rate[] = {10, 20, 40, 60, 100, 200}; +static const u8 cytp_resolution[] = {0x00, 0x01, 0x02, 0x03}; -static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value) +static int cypress_ps2_sendbyte(struct psmouse *psmouse, u8 cmd) { struct ps2dev *ps2dev = &psmouse->ps2dev; int error; - error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT); + error = ps2_sendbyte(ps2dev, cmd, CYTP_CMD_TIMEOUT); if (error) { psmouse_dbg(psmouse, "sending command 0x%02x failed, resp 0x%02x, error %d\n", - value & 0xff, ps2dev->nak, error); + cmd, ps2dev->nak, error); return error; } #ifdef CYTP_DEBUG_VERBOSE - psmouse_dbg(psmouse, "sending command 0x%02x succeeded, resp 0xfa\n", - value & 0xff); + psmouse_dbg(psmouse, "sending command 0x%02x succeeded\n", cmd); #endif return 0; } -static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, - unsigned char data) +static int cypress_ps2_ext_cmd(struct psmouse *psmouse, u8 prefix, u8 nibble) { struct ps2dev *ps2dev = &psmouse->ps2dev; int tries = CYTP_PS2_CMD_TRIES; @@ -71,7 +69,7 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, * If sending the command fails, send recovery command * to make the device return to the ready state. */ - rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff); + rc = cypress_ps2_sendbyte(psmouse, prefix); if (rc == -EAGAIN) { rc = cypress_ps2_sendbyte(psmouse, 0x00); if (rc == -EAGAIN) @@ -79,9 +77,9 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, } if (!rc) { - rc = cypress_ps2_sendbyte(psmouse, data); + rc = cypress_ps2_sendbyte(psmouse, nibble); if (rc == -EAGAIN) - rc = cypress_ps2_sendbyte(psmouse, data); + rc = cypress_ps2_sendbyte(psmouse, nibble); if (!rc) break; @@ -94,8 +92,7 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, } static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, - unsigned char cmd, - unsigned char *param) + u8 cmd, u8 *param) { struct ps2dev *ps2dev = &psmouse->ps2dev; enum psmouse_state old_state; @@ -111,7 +108,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, pktsize = (cmd == CYTP_CMD_READ_TP_METRICS) ? 8 : 3; memset(param, 0, pktsize); - rc = cypress_ps2_sendbyte(psmouse, 0xe9); + rc = cypress_ps2_sendbyte(psmouse, PSMOUSE_CMD_GETINFO & 0xff); if (rc) goto out; @@ -136,8 +133,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, return rc; } -static bool cypress_verify_cmd_state(struct psmouse *psmouse, - unsigned char cmd, unsigned char *param) +static bool cypress_verify_cmd_state(struct psmouse *psmouse, u8 cmd, u8* param) { bool rate_match = false; bool resolution_match = false; @@ -167,31 +163,24 @@ static bool cypress_verify_cmd_state(struct psmouse *psmouse, return false; } -static int cypress_send_ext_cmd(struct psmouse *psmouse, unsigned char cmd, - unsigned char *param) +static int cypress_send_ext_cmd(struct psmouse *psmouse, u8 cmd, u8 *param) { + u8 cmd_prefix = PSMOUSE_CMD_SETRES & 0xff; int tries = CYTP_PS2_CMD_TRIES; - int rc; + int error; psmouse_dbg(psmouse, "send extension cmd 0x%02x, [%d %d %d %d]\n", cmd, DECODE_CMD_AA(cmd), DECODE_CMD_BB(cmd), DECODE_CMD_CC(cmd), DECODE_CMD_DD(cmd)); do { - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_DD(cmd)); - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_CC(cmd)); - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_BB(cmd)); - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_AA(cmd)); - - rc = cypress_ps2_read_cmd_status(psmouse, cmd, param); - if (rc) - continue; - - if (cypress_verify_cmd_state(psmouse, cmd, param)) + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_DD(cmd)); + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_CC(cmd)); + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_BB(cmd)); + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_AA(cmd)); + + error = cypress_ps2_read_cmd_status(psmouse, cmd, param); + if (!error && cypress_verify_cmd_state(psmouse, cmd, param)) return 0; } while (--tries > 0); @@ -201,7 +190,7 @@ static int cypress_send_ext_cmd(struct psmouse *psmouse, unsigned char cmd, int cypress_detect(struct psmouse *psmouse, bool set_properties) { - unsigned char param[3]; + u8 param[3]; if (cypress_send_ext_cmd(psmouse, CYTP_CMD_READ_CYPRESS_ID, param)) return -ENODEV; @@ -221,7 +210,7 @@ int cypress_detect(struct psmouse *psmouse, bool set_properties) static int cypress_read_fw_version(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; - unsigned char param[3]; + u8 param[3]; if (cypress_send_ext_cmd(psmouse, CYTP_CMD_READ_CYPRESS_ID, param)) return -ENODEV; @@ -250,7 +239,7 @@ static int cypress_read_fw_version(struct psmouse *psmouse) static int cypress_read_tp_metrics(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; - unsigned char param[8]; + u8 param[8]; /* set default values for tp metrics. */ cytp->tp_width = CYTP_DEFAULT_WIDTH; @@ -338,7 +327,7 @@ static int cypress_query_hardware(struct psmouse *psmouse) static int cypress_set_absolute_mode(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; - unsigned char param[3]; + u8 param[3]; int error; 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, return 0; } -static int cypress_get_finger_count(unsigned char header_byte) +static int cypress_get_finger_count(u8 header_byte) { - unsigned char bits6_7; + u8 bits6_7; int finger_count; bits6_7 = header_byte >> 6; @@ -445,10 +434,11 @@ static int cypress_get_finger_count(unsigned char header_byte) static int cypress_parse_packet(struct psmouse *psmouse, - struct cytp_data *cytp, struct cytp_report_data *report_data) + struct cytp_data *cytp, + struct cytp_report_data *report_data) { - unsigned char *packet = psmouse->packet; - unsigned char header_byte = packet[0]; + u8 *packet = psmouse->packet; + u8 header_byte = packet[0]; memset(report_data, 0, sizeof(struct cytp_report_data)); @@ -563,7 +553,7 @@ static psmouse_ret_t cypress_validate_byte(struct psmouse *psmouse) { int contact_cnt; int index = psmouse->pktcnt - 1; - unsigned char *packet = psmouse->packet; + u8 *packet = psmouse->packet; struct cytp_data *cytp = psmouse->private; if (index < 0 || index > cytp->pkt_size)