From patchwork Wed Jul 10 10:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812308 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 46EC118FA32 for ; Wed, 10 Jul 2024 10:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607788; cv=none; b=NBGWJbZpl3AwC0or5KIduQFUChmG0HD6dbhazRc31OM6Qt9/+u1wbHgBx7KjAqF93Gdf+wSgQ+Vx1pmErEqeG1CTEunMw+HQ91BF/jIoGSBXO3r1lDNvN7SVr10Da7Gg7yVWoFn0Ga3012M/UBzAmNw1KzqkORsv08BdEmeqn7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607788; c=relaxed/simple; bh=9GJRHNLrHyHetG9QLvl+hM3eRSeIWSgSwKE96DTJrig=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H+RqquNdXur75/kkc5GpJi92Jznz5doyL8NemnuVeVVvJnmWKY/K0GUpT2NpPkG5RudfC89PHJDlK8lARfvPCSBLQ3hQqRFdTqVquj7JDCQGkaLgZIJ5+e0oHyW07ldknBa/OniQbdkFRtWJMXR4CVdfioPXd7D/iKajHzxXz8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=QwXIKgjh; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="QwXIKgjh" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a77baa87743so665833266b.3 for ; Wed, 10 Jul 2024 03:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607783; x=1721212583; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0AjlT5eFQ6h9gEvtReCv6ZkrzRkpXg8KUXrIWg1LtUo=; b=QwXIKgjhD6bDJw8VKDx1Lszk9zYCPpfUWHEGgpo7W+U4JwSNMRw7bo+Xk/dIFXuAKU XEpVLV3F5oTq69QgBk0kQtmKoecsQY4gfEWsbEKsHkMlrC7U1TVMbIjpK7BgFCFhheQS qmyvlxjvB2C1uoyxw/Rp38V3aWYFdgRvqZO7a5nrd+v5MJ03DgT/GQd/w7aapp0Iu2Ik 9hs2OudEZa66R3cS1dIxa9o7tpUOE/xbI5bZ7gIPX3y4hmIbsF3A1qeMG4FQcrlnLqwb g/sWUTxNlJsOXQeCOZKI50V19idl15Mayy6ail9/0tB9YJEbXWxygDy/79e1xl+FPPSj 9NSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607783; x=1721212583; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0AjlT5eFQ6h9gEvtReCv6ZkrzRkpXg8KUXrIWg1LtUo=; b=LrgY+q55SNw3kbrxjBqdiUyAkqyoWQ2+OdLE+4woyPpVHe1y5s7SB5IiUzFmxC1UOD Hy0ktQnhzU04lv5yEQLHkx3JXVtBQnhUozIIcm07Y3DaVDYKQv8acOZwScXBFXnabceW muMv5G0FUOyeEEVDpkOVgaeQKQsvksboDrm4G1TxsaB3CoTxnqOa7XihNGCS6v/Id9D1 XGNVhc6Px8tk5ViKuCW4PpOPmhDzmQFaFoYj6YxeT8qOUtp9f7xLIqA3idpI7RX6UPf8 deLMe8j/aIPENK0NFS4xWK3Ra2BoGzw2ILmr9XGCr7dgt5QeOccTKvdFTS9Iz4MWmyXQ lqFQ== X-Forwarded-Encrypted: i=1; AJvYcCXX6Tm2ihJc57+FoGlLHBXCPgqc2l1rSpYWtDlhowEmPVPoRqw/7kOq+S3jQkUqb5kjyIOvCO2+aa8HMemFvUyrQ7dXuPUTCp5V X-Gm-Message-State: AOJu0Yxe91OxSOC5ji5BYrxCBEV3vFcH+rD08pGarsPAHicsYXfHJOL1 AkabxyzOoFG9DRKHCWegTFCQ8WhTeGAqzJjccrjGgYzfXGIfRQY9vMTHMhtZ91M= X-Google-Smtp-Source: AGHT+IEBYPb6oMofA153AVchD/c6t8lwHvb5LurkHVdmpGrU7RToq5FYqM5J4DT8aQ52uq/60Vf3SA== X-Received: by 2002:a17:907:9711:b0:a77:b0a4:7d88 with SMTP id a640c23a62f3a-a780b689270mr567665866b.10.1720607783633; Wed, 10 Jul 2024 03:36:23 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:23 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:08 +0100 Subject: [PATCH 01/15] usb: typec: tcpci: fix a comment typo Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-1-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 autonously -> autonomously Signed-off-by: André Draszik --- include/linux/usb/tcpci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 0ab39b6ea205..d27fe0c22a8b 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -190,7 +190,7 @@ struct tcpci; * Optional; Callback to perform chip specific operations when FRS * is sourcing vbus. * @auto_discharge_disconnect: - * Optional; Enables TCPC to autonously discharge vbus on disconnect. + * Optional; Enables TCPC to autonomously discharge vbus on disconnect. * @vbus_vsafe0v: * optional; Set when TCPC can detect whether vbus is at VSAFE0V. * @set_partner_usb_comm_capable: From patchwork Wed Jul 10 10:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812042 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 DC70118FA06 for ; Wed, 10 Jul 2024 10:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607787; cv=none; b=n5rmLcaUJRH3GNUCF8okHiFZusdJp6kc+ehOHJQBi5k31r4PSpzkXPhCHVZ2845+nknFvDCtjoVDEySRKn+p3bSdw7C0LvCJoQ4oumZ8YHcf94a9KNYNzGWoQFlakatyR/UYcPHrtzQrvzRRliM83OMCKjMKtVKXa8YOjh3Bw9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607787; c=relaxed/simple; bh=mil0Paw7dKSF+yYmtF7z93+PPTbySeNKiljnw4gmtA8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BrLXWDT9/2hbJ4rXy4+7g4rEmJNjdATAc7TDNYkgUqBAicYYUL8fsLhwduN1CvPg6hZUBJ95cbuEKtv6lH2PbDr01xuLdPrPBqjBysiWSbjmRpa3l4tLaA9f59MLIBRnbPgL93DlaXGv4Z37FcKcBNF33GVvLx2uWcpTlbTvINc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tY5w+BVA; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tY5w+BVA" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a77b60cafecso748181366b.1 for ; Wed, 10 Jul 2024 03:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607784; x=1721212584; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ugko5125K/DlhjBE+oAKmwE1ZDstjFq/scQfmJhd89w=; b=tY5w+BVAKh/Jbp1CuBRSpHMzAMn4dc/KnCJZF9W/turj5AR40sYiT/FFH0DqHzzI7M ZfwHV3y/tosY3DwpHVdCHDEHi06LAxQvEGbGsOOd8h64iwhg2X1nhc1i25Emx6TevizU MJUr91lTl8ovxB+uTgAeOaEus34YoEMjdB2qIVPxKxh4DP6FEvXWezZ4SnDa8ldoZvTh EamkVQ9Z2Lu1c45Nrm4BxkuvVFzDDQO/prWV72lSn///mQmC7Ed6kLjU+q+XoBHTjf+B h1JJpF85qC7bwhh+Zsmz8qIe97Sz31sRcCOu3lw48V9cEJmrlVVOl7LdqCANOitrALVb T/9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607784; x=1721212584; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ugko5125K/DlhjBE+oAKmwE1ZDstjFq/scQfmJhd89w=; b=OgzwJ2LuzI8yKnzlsPuXjHyqx3d0qUKGfg2SbxG4Rvny5Svxg0ZsZ1TDPu+DnTVa1V u0Wl26+NEPXP665LPXaz/jbGl1xAJsMIteTWB9n6vO7WRuq+UOUm+CQz2BETSRwzej3z I0r4SmBFkSbf0vdRmCIwxUJv0imZtbALOKHllCgyCC0/n31flWaImYGiWTZpHiyOFVzn agpzUC1FFuQoEiDO7i9WKm/VSn8hdglw4HGuYLkB7Ps2iUY+JME4dtA4/1U6U1Yr5d8D ZePd0SnltIsLfsjja6uQBYw14Yaxd8T2otm0PNG0/oD6Mb5vIPFx8sRYWVksB9LzNvzM sHgg== X-Forwarded-Encrypted: i=1; AJvYcCU3T1sful+HZa1mwrAtf2t7qpkCFHfndfR2LRUzam5k++KLLKH4JXabjoB/ox+VAkAWVpj2pOmeooANA1wxwp2T1hyvhIJPyfgc X-Gm-Message-State: AOJu0YwevDEAUCQk+XFpltkoeMKyiBGG9X3WvaKz62J0Itz7z8AvJFhx Y1XAbvZLhR+5yOc8h+ipU1JC+W+8iup/FfD+Nu2qQoyM8/aN0EqyWgquRwa7PoA= X-Google-Smtp-Source: AGHT+IFn15u2cejyFoefO6hJ902KlcwxPbEv119zyj3cGShttSJFkxT2Jd9K7A4TdHzThGIHgNPh9Q== X-Received: by 2002:a17:907:7717:b0:a77:daa9:402 with SMTP id a640c23a62f3a-a780b6fe400mr324241666b.35.1720607784079; Wed, 10 Jul 2024 03:36:24 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:23 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:09 +0100 Subject: [PATCH 02/15] usb: typec: tcpm/tcpci_maxim: clarify a comment Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-2-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 We loop while the status is != 0, so rephrase the comment slightly for clarity. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index eec3bcec119c..87102b4d060d 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -397,7 +397,7 @@ static irqreturn_t max_tcpci_irq(int irq, void *dev_id) } while (status) { irq_return = _max_tcpci_irq(chip, status); - /* Do not return if the ALERT is already set. */ + /* Do not return if a (new) ALERT is set (again). */ ret = max_tcpci_read16(chip, TCPC_ALERT, &status); if (ret < 0) break; From patchwork Wed Jul 10 10:36:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812041 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 42D6D18FA2F for ; Wed, 10 Jul 2024 10:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607788; cv=none; b=gl9vUnypUS9sMCqDTVPa6X0wSkn83J+d07DJ4KjOCDhad4HSMk0aMS3XK4fPJGwJTsh2oeG4Bcs8ug9Bd8sKADGgtpZwOTAl3mt8bXPOdcPHdtQwzGLlj3FAkhgmYb+t9VO0P+92CJMZoF8rlNkx22o51Szjnnrn1bS0F07Pw88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607788; c=relaxed/simple; bh=ie2JmEfSUiTUhNpHVLVkQZYkMP0gFDlAbOaRX85e2bw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DOIVL/n3XjeMgxE4xpy6Fxg3WvDuzyhdu7SLAh9YWnFrag8Lu1GyZffqrEHGIZkGS/4RiKhm0Y+3yYjiJYl/m2SscFX9Xb5C1Fltk6LgGjluOO4mb3LV+WGAhzt8DFtXLUsMchajy/euuTmty9IE0QZLfj3wkkSQY0lBsVIcu9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=g4Xms5P0; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="g4Xms5P0" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77c1658c68so661902066b.0 for ; Wed, 10 Jul 2024 03:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607784; x=1721212584; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PwfQalACRRVjjbxpGdsLscOtRao7Xr+Lw/le1ijWaFk=; b=g4Xms5P0k3NYhR6cEKZ6Yg1+AQ7kQHEelBWQdxPUz/TkNav9AUo8vI7rYlc5hiSIEP z2Gfdlr8X367sGxpAIZaKIpoOEb+wkX0hHXaXVlUcpdx7mP+bcmsxT2BfYqz0fu35z44 bKMm8X3zIpeZDrGpQIONUD5ifR8XC07jAqreZjanPKasA3Us4j8jLKbXQTPRqV+Cw87P FJSgFY7OUtH8FOSVK2f13/mzcG8cmTgCCLUYDhkDvfpRSg/j2qWLqqO1PIhUeZyhZmNo uTbbqRv3ge34vFmExB7IbM3OUC1/MWCYuCp8PdQg0iYxjX2Gg93qKV7IcurRB/9Wq6Ic TnAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607784; x=1721212584; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PwfQalACRRVjjbxpGdsLscOtRao7Xr+Lw/le1ijWaFk=; b=RokcrU5EIuhQZTvEuXpylcSOAPQOdf3MjbhMtDy27B5OUM61RaQ62x/EdwprY98R0f /1VUuk7WcMZpmTCevstkuibZXbJIcD9CMMPyxLBN16EOhG+5OCksm5bpI0O9Ak7LcfNp uByD8EKy7rwvkhixjDBfyWSKD5rUim/GkmsMUL4liHrlDzsqXkfR4lCTIvU6P52hFcwK 5uBX9rfaq2g9jvsIrPx78KEf1a67vUq5w3cEYZBS4742AdG1XXcEcG00YNk3w6pl6b1O E9RcDXmbqN5lFTdBiHh3q8I+Gn6235l9WxKxPlQzQawu68kpSF5TI7fsosFj87mKY/tW fahw== X-Forwarded-Encrypted: i=1; AJvYcCUo7YrrhTPLwDl8fMLDpCWo/jgjJGQlgV4ZmubBCXonGvxc1DhWrW5QSYYiE0KnU1xeQTSyhC2d1M+bdwiR2lbPefmz5qqOFaBb X-Gm-Message-State: AOJu0YzqBPZlnF1Kh+a7Gc3YQmLmuuwnU1XCm63bJilBDtrN9jrC8FHz Z84bpfnv9XlPqvGBlAaMdzn7ZFgN5zarni2hB5Zysm5ALLifU90ryWSUCavzbjo= X-Google-Smtp-Source: AGHT+IHBIzsNTce5pBOT96MfRjxpyaoMRtCO0GXv5dj4EAemMgtOGhYPOOBtYMfTkQaIQZk1FTryeQ== X-Received: by 2002:a17:907:7da8:b0:a6f:e456:4207 with SMTP id a640c23a62f3a-a780b88498fmr439952166b.61.1720607784519; Wed, 10 Jul 2024 03:36:24 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:24 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:10 +0100 Subject: [PATCH 03/15] usb: typec: tcpci: use GENMASK() for TCPC_CC_STATUS_CC[12] Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-3-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 The existing code here, particularly in maxim_contaminant.c, is arguably quite hard to read due to the open-coded masking and shifting spanning multiple lines. Use GENMASK() and FIELD_GET() instead, which arguably make the code much easier to follow. While at it, use the symbolic name TCPC_CC_STATE_SRC_OPEN for one instance of open-coded 0x0. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/maxim_contaminant.c | 8 +++----- drivers/usb/typec/tcpm/tcpci.c | 7 +++---- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 7 +++---- include/linux/usb/tcpci.h | 8 +++----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c index f8504a90da26..e7687aeb69c0 100644 --- a/drivers/usb/typec/tcpm/maxim_contaminant.c +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c @@ -5,6 +5,7 @@ * USB-C module to reduce wakeups due to contaminants. */ +#include #include #include #include @@ -48,11 +49,8 @@ enum fladc_select { #define STATUS_CHECK(reg, mask, val) (((reg) & (mask)) == (val)) #define IS_CC_OPEN(cc_status) \ - (STATUS_CHECK((cc_status), TCPC_CC_STATUS_CC1_MASK << TCPC_CC_STATUS_CC1_SHIFT, \ - TCPC_CC_STATE_SRC_OPEN) && STATUS_CHECK((cc_status), \ - TCPC_CC_STATUS_CC2_MASK << \ - TCPC_CC_STATUS_CC2_SHIFT, \ - TCPC_CC_STATE_SRC_OPEN)) + (FIELD_GET(TCPC_CC_STATUS_CC1, cc_status) == TCPC_CC_STATE_SRC_OPEN \ + && FIELD_GET(TCPC_CC_STATUS_CC2, cc_status) == TCPC_CC_STATE_SRC_OPEN) static int max_contaminant_adc_to_mv(struct max_tcpci_chip *chip, enum fladc_select channel, bool ua_src, u8 fladc) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 8a18d561b063..ce11a154c7dc 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -5,6 +5,7 @@ * USB Type-C Port Controller Interface. */ +#include #include #include #include @@ -241,12 +242,10 @@ static int tcpci_get_cc(struct tcpc_dev *tcpc, if (ret < 0) return ret; - *cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) & - TCPC_CC_STATUS_CC1_MASK, + *cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, reg), reg & TCPC_CC_STATUS_TERM || tcpc_presenting_rd(role_control, CC1)); - *cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) & - TCPC_CC_STATUS_CC2_MASK, + *cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, reg), reg & TCPC_CC_STATUS_TERM || tcpc_presenting_rd(role_control, CC2)); diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index 67422d45eb54..c6dbccf6b17a 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -5,6 +5,7 @@ * Richtek RT1711H Type-C Chip Driver */ +#include #include #include #include @@ -195,12 +196,10 @@ static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, u8 status) if (ret < 0) return ret; - cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) & - TCPC_CC_STATUS_CC1_MASK, + cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, status), status & TCPC_CC_STATUS_TERM || tcpc_presenting_rd(role, CC1)); - cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) & - TCPC_CC_STATUS_CC2_MASK, + cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, status), status & TCPC_CC_STATUS_TERM || tcpc_presenting_rd(role, CC2)); diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index d27fe0c22a8b..31d21ccf662b 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -92,11 +92,9 @@ #define TCPC_CC_STATUS_TERM BIT(4) #define TCPC_CC_STATUS_TERM_RP 0 #define TCPC_CC_STATUS_TERM_RD 1 +#define TCPC_CC_STATUS_CC2 GENMASK(3, 2) +#define TCPC_CC_STATUS_CC1 GENMASK(1, 0) #define TCPC_CC_STATE_SRC_OPEN 0 -#define TCPC_CC_STATUS_CC2_SHIFT 2 -#define TCPC_CC_STATUS_CC2_MASK 0x3 -#define TCPC_CC_STATUS_CC1_SHIFT 0 -#define TCPC_CC_STATUS_CC1_MASK 0x3 #define TCPC_POWER_STATUS 0x1e #define TCPC_POWER_STATUS_DBG_ACC_CON BIT(7) @@ -256,7 +254,7 @@ static inline enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink) if (sink) return TYPEC_CC_RP_3_0; fallthrough; - case 0x0: + case TCPC_CC_STATE_SRC_OPEN: default: return TYPEC_CC_OPEN; } From patchwork Wed Jul 10 10:36:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812040 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 9EE1A18FC61 for ; Wed, 10 Jul 2024 10:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; cv=none; b=aS/7MPXbzLTiWv27aFToDcrO517NSYu30cNHNHYg9fLCTOvKSfYsiBWzny8fv9w/1Cv8yS9ZHPKEw2VkpvhyX8CckiU/k0GTShv2AtLdPejmLjeuieF0gfoib3qLGUfYMLtGaZPPuHQT+CXJEYaOhXRvud1qIVe2ZpQGf+R9CMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; c=relaxed/simple; bh=UpNyt3hPB6krYjnIMNVu3bl0PxDu7L8l/9FunFkfXJ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ig7B54RHxyFM4rajtHjHP2T8riNIryaagUS73B17vYwvUrOGYw1H1knz0scmn9fFsewope+xmU02/0BcHjT2/y0IR4hqqCQc3MAIxwHvkUChG9cjSPXJyQHUeGWNwzlCKIe6FqtCwKmpiUFGM0qUUHkt0sC1bp9m+fX56Nde6+Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=vLWkzrnD; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vLWkzrnD" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-58ba3e38028so7892288a12.0 for ; Wed, 10 Jul 2024 03:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607785; x=1721212585; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kKvNmNonW4k4hzY7mYArULLqBs8XeH3VnuyLyDk7L3s=; b=vLWkzrnDXi0yzGDSJmyQHAGTZv6O4P0x9ckO0yt9v+0wJFeXJLvWc2kxCKQEGlLgpG 9B7CDTCT37kf/qa9nu6/ULkxr5Tt6R9gDsUnoQrvzgrkIZEYE80DkifDeiUhJHlc1Qpg VfSmwt1vjaWDo9fi4CsJexjcVKCS2ZclVbQPrUOteaDl0ocVwBtnzf2FeBIznJpW2Kni BLCHzQjkqwrAGGZ5XMKLWGnYHZYHe49b0SEHfZhDsj59RBlyv5cQfNvqXbN9l2kc+/v5 Jp09Ux0j+O2cbOvJiGmjwSvN+JEiTziImEPKhlWqsk3UddI+0rW8Pew8eJv0+skIYc6k bqIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607785; x=1721212585; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kKvNmNonW4k4hzY7mYArULLqBs8XeH3VnuyLyDk7L3s=; b=ozNKVzm9TxBbi0hpejIIrrjUBi4myr5GIwUog5fQ80cU8c2jjshCH0/rIvXYmQcoSk tO7eHPrFCKm2JhwOnPBVYvj+FSywPrBeeFt1gjDS7f2RdSQNWo7CwIlbftRc5S/uVkgR mL15HQ+++F2tmbofaAjSCkUNyE0Lnl9HFaRSqvWlNcXE5qYr06k8HsNgy7bNb2dwY9P+ DKTGuL3mosyuFnkoHj2Sg7RHVJ5RuBMo+AC2DeNlI5Ek1ZirMq3FjLSHP3uzPrUy+vwg YxB/Xfjnw1Y28cb0yUn5cOovv2JUcH8Bi8nKFRXlZR+ZPX6B8Dm5UcwBO7GB4WkmIbYb JzTQ== X-Forwarded-Encrypted: i=1; AJvYcCVWov4f0vJTGbqnB8USplyT0QsmcLxT6PsUdXiqr7StwivizDffUqDp+uLU6t6+xDn921+/MdLQ73HrY5qR3DKsBRXfPRT0uB2o X-Gm-Message-State: AOJu0Yy1YAQnfgyXZaRmF2Tb7g/maCxc4IkqR/uGPo0g4D5fqrVwVHPx OAPHox77ygxJkZ083DzsUVakKkcKWu9St/j70mXKd+hz1WRbCCSzsFSGPimVhyI= X-Google-Smtp-Source: AGHT+IEANfZn8xYveZOZpH1PlIfZ5CExCb4Ai1+KB0oG2AncjlZQBjTB2r9uGvLZ2yNxiX3Q8zHqjg== X-Received: by 2002:a17:906:a848:b0:a77:e2e3:355f with SMTP id a640c23a62f3a-a780b7051f2mr279818966b.41.1720607784952; Wed, 10 Jul 2024 03:36:24 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:24 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:11 +0100 Subject: [PATCH 04/15] usb: typec: tcpci: use GENMASK() for TCPC_ROLE_CTRL_CC[12] Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-4-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 All this open-coded shifting and masking is quite hard to read, in particular the if-statement in tcpci_apply_rc(). Declare TCPC_ROLE_CTRL_CC[12] using GENMASK() which allows using FIELD_GET() and FIELD_PREP() to arguably make the code more legible. Signed-off-by: André Draszik --- drivers/usb/typec/anx7411.c | 5 ++- drivers/usb/typec/tcpm/tcpci.c | 73 +++++++++++++++------------------- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 8 ++-- include/linux/usb/tcpci.h | 9 ++--- 4 files changed, 43 insertions(+), 52 deletions(-) diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c index b12a07edc71b..78b0d856cfc1 100644 --- a/drivers/usb/typec/anx7411.c +++ b/drivers/usb/typec/anx7411.c @@ -6,6 +6,7 @@ * Copyright(c) 2022, Analogix Semiconductor. All rights reserved. * */ +#include #include #include #include @@ -884,8 +885,8 @@ static void anx7411_chip_standby(struct anx7411_data *ctx) OCM_RESET); ret |= anx7411_reg_write(ctx->tcpc_client, ANALOG_CTRL_10, 0x80); /* Set TCPC to RD and DRP enable */ - cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT; - cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT; + cc1 = FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD); + cc2 = FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD); ret |= anx7411_reg_write(ctx->tcpc_client, TCPC_ROLE_CTRL, TCPC_ROLE_CTRL_DRP | cc1 | cc2); diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index ce11a154c7dc..cd71ece7b956 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -104,45 +104,42 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) switch (cc) { case TYPEC_CC_RA: - reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT); + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RA) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RA)); break; case TYPEC_CC_RD: - reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD)); break; case TYPEC_CC_RP_DEF: - reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) | - (TCPC_ROLE_CTRL_RP_VAL_DEF << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) + | (TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); break; case TYPEC_CC_RP_1_5: - reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) | - (TCPC_ROLE_CTRL_RP_VAL_1_5 << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) + | (TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); break; case TYPEC_CC_RP_3_0: - reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) | - (TCPC_ROLE_CTRL_RP_VAL_3_0 << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) + | (TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); break; case TYPEC_CC_OPEN: default: - reg = (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT); + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN)); break; } if (vconn_pres) { if (polarity == TYPEC_POLARITY_CC2) { - reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT); - reg |= (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT); + reg &= ~TCPC_ROLE_CTRL_CC1; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN); } else { - reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT); - reg |= (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT); + reg &= ~TCPC_ROLE_CTRL_CC2; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN); } } @@ -168,15 +165,11 @@ static int tcpci_apply_rc(struct tcpc_dev *tcpc, enum typec_cc_status cc, * APPLY_RC state is when ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2 and vbus autodischarge on * disconnect is disabled. Bail out when ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2. */ - if (((reg & (TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT)) >> - TCPC_ROLE_CTRL_CC2_SHIFT) != - ((reg & (TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT)) >> - TCPC_ROLE_CTRL_CC1_SHIFT)) + if (FIELD_GET(TCPC_ROLE_CTRL_CC2, reg) != FIELD_GET(TCPC_ROLE_CTRL_CC1, reg)) return 0; return regmap_update_bits(tcpci->regmap, TCPC_ROLE_CTRL, polarity == TYPEC_POLARITY_CC1 ? - TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT : - TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT, + TCPC_ROLE_CTRL_CC2 : TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN); } @@ -215,11 +208,11 @@ static int tcpci_start_toggling(struct tcpc_dev *tcpc, } if (cc == TYPEC_CC_RD) - reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD)); else - reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT); + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP)); ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); if (ret < 0) return ret; @@ -281,28 +274,28 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc, reg = reg & ~TCPC_ROLE_CTRL_DRP; if (polarity == TYPEC_POLARITY_CC2) { - reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT); + reg &= ~TCPC_ROLE_CTRL_CC2; /* Local port is source */ if (cc2 == TYPEC_CC_RD) /* Role control would have the Rp setting when DRP was enabled */ - reg |= TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP); else - reg |= TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD); } else { - reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT); + reg &= ~TCPC_ROLE_CTRL_CC1; /* Local port is source */ if (cc1 == TYPEC_CC_RD) /* Role control would have the Rp setting when DRP was enabled */ - reg |= TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP); else - reg |= TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD); } } if (polarity == TYPEC_POLARITY_CC2) - reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN); else - reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT; + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN); ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); if (ret < 0) return ret; diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index c6dbccf6b17a..bdb78d08b5b5 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -246,11 +246,11 @@ static int rt1711h_start_drp_toggling(struct tcpci *tcpci, } if (cc == TYPEC_CC_RD) - reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD)); else - reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT); + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP)); ret = rt1711h_write8(chip, TCPC_ROLE_CTRL, reg); if (ret < 0) diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 31d21ccf662b..552d074429f0 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -68,10 +68,8 @@ #define TCPC_ROLE_CTRL_RP_VAL_DEF 0x0 #define TCPC_ROLE_CTRL_RP_VAL_1_5 0x1 #define TCPC_ROLE_CTRL_RP_VAL_3_0 0x2 -#define TCPC_ROLE_CTRL_CC2_SHIFT 2 -#define TCPC_ROLE_CTRL_CC2_MASK 0x3 -#define TCPC_ROLE_CTRL_CC1_SHIFT 0 -#define TCPC_ROLE_CTRL_CC1_MASK 0x3 +#define TCPC_ROLE_CTRL_CC2 GENMASK(3, 2) +#define TCPC_ROLE_CTRL_CC1 GENMASK(1, 0) #define TCPC_ROLE_CTRL_CC_RA 0x0 #define TCPC_ROLE_CTRL_CC_RP 0x1 #define TCPC_ROLE_CTRL_CC_RD 0x2 @@ -176,8 +174,7 @@ #define tcpc_presenting_rd(reg, cc) \ (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ - (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \ - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT))) + FIELD_GET(TCPC_ROLE_CTRL_## cc, reg) == TCPC_ROLE_CTRL_CC_RD) struct tcpci; From patchwork Wed Jul 10 10:36:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812305 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.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 E984F18FC95 for ; Wed, 10 Jul 2024 10:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; cv=none; b=pPuviyU2FqgCQSxBblB+VuyFj2hQ/kZ26Wuj5BBEVSZrTxe1FAlGR3i6lhMByflod5qpxJcBHwgvCQ0lN3O3vTtzfX1NTpLx35zX6Ottb2+lJtGtqYowRuVQ5iDr8WG2lZNej+S/tnTYe7hY/OXi+Uo0Mw22q2orPXCEhCGwcUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; c=relaxed/simple; bh=sW84uVhoT7q6hbhpajXvF+A6OZDizFcmPHMcYOMyMro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aeWRKQpI7I66MN0OlzzdYSDGy7lcK1WG+rVJcvJzR4/GTv/ipHAYpF3oyBoUBpcRWDpm0dHxfOORXlbNuNpsK3qC/ed+iidyB1J73MxA1X6aBloot08LMEeqG2qce3uMlOMBfEZZnP969sa344OyoLmS82iP4ecyaX+8yd8RDuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MbUzYNLY; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MbUzYNLY" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a77d85f7fa3so102966666b.0 for ; Wed, 10 Jul 2024 03:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607785; x=1721212585; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Vwjavj6RPqeiyQNJ3n68uYX4MUqGmZQjpRSOl94gIO0=; b=MbUzYNLYxDzq9Qfykkx1E5YrdzPMOByvMZYXzW+l8RpJ6t+x1XTib61G+Q9c+uSu0Z C3RE97krPhKSV5Qv33V4g2FRPcvdRTVQ25bFrVWsKLN7VEUNIK+5MfSW3E+5tAWQNcjb yoyUtOTNf5rh/B8N7Pqt7FrIqBSCnN3ZIt/y9Rt4PBmoajVf0jPSkmXgB+Pj0HgYsNiC 8BuTNbCYbmnCHtMR5Wqs7TUvsjqFV8CJCI9rF1sXxoTQeWu/ZW9fOfJ33Y/ggjp04HVB xYtYJNZN8YziEL6b2Kb7g8NAgSreORQp2hgbnQMKSnw7Cl2c+JNeQ9RL3BJh8BbdEesL CKcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607785; x=1721212585; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vwjavj6RPqeiyQNJ3n68uYX4MUqGmZQjpRSOl94gIO0=; b=HkJkay4WkNFGzghWArKt9M+hvQ78R9egWEI2epp78rUxoSTM7PLMKqdEtqYf58COzu r8oUQmytV90a5lIHYeHc4yUmvcdeywkAzu/v3u9r6MywL6mdS7BgKpE24swfvOmF55pd WAWHAQuHgjAMT3ZHXNC+9fOnYkLYjxGi+96OJRkgFmIWxRGvZPcw2tB7JmOv5aZTK543 CzyYyS7nfoY0y9lfY2FCRJ6XD2ZsthhIWZGFMvzcBXbwLpGu933LGGXFe911mJYeGs99 os8IxGULIgv8VqX0A85YmcAqiBwsMU/k+xlOM4zwSaKS3/IAkXB8VwEyQVwK9QT9Mu6f blsw== X-Forwarded-Encrypted: i=1; AJvYcCWcxaPd1XscKJhUOSoquIYrDILFQodIzwNM3SCldP1qrG1lNvJkIKzl4NwA2N2BygjmhAnNQA8rbYQ8c84AZOmhzRe1MnV3tOhA X-Gm-Message-State: AOJu0Yxk+vJgxk4zaPJViPGM5nQhyBJHQ5BzzkAezJ23urx6m5Rwk8Oy tQHgiRSmEdkijYBxMGcczqwmw1TPsPXIPfArTQ//F/FQQXo6XKH+FzgG8EqAeMI= X-Google-Smtp-Source: AGHT+IHUTKIvR3XwPGDJ3agEObdSPf5IVHYSTkjhYzMGwyHu0kgGSWWMEcYfIz+1xNw58nSsctD10A== X-Received: by 2002:a17:907:3fa0:b0:a6f:e03a:99d with SMTP id a640c23a62f3a-a780d0a4445mr454600466b.0.1720607785399; Wed, 10 Jul 2024 03:36:25 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:25 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:12 +0100 Subject: [PATCH 05/15] usb: typec: tcpci: use GENMASK() for TCPC_ROLE_CTRL_RP_VAL Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-5-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Align the last remaining field TCPC_ROLE_CTRL_RP_VAL with the other fields in the TCPC_ROLE_CTRL register by using GENMASK() and FIELD_PREP(). Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci.c | 21 ++++++++++++--------- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 12 ++++++------ include/linux/usb/tcpci.h | 3 +-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index cd71ece7b956..5ad05a5bbbd1 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -114,17 +114,20 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) case TYPEC_CC_RP_DEF: reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) - | (TCPC_ROLE_CTRL_RP_VAL_DEF << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_DEF)); break; case TYPEC_CC_RP_1_5: reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) - | (TCPC_ROLE_CTRL_RP_VAL_1_5 << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_1_5)); break; case TYPEC_CC_RP_3_0: reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) - | (TCPC_ROLE_CTRL_RP_VAL_3_0 << TCPC_ROLE_CTRL_RP_VAL_SHIFT)); + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_3_0)); break; case TYPEC_CC_OPEN: default: @@ -194,16 +197,16 @@ static int tcpci_start_toggling(struct tcpc_dev *tcpc, switch (cc) { default: case TYPEC_CC_RP_DEF: - reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_DEF); break; case TYPEC_CC_RP_1_5: - reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_1_5); break; case TYPEC_CC_RP_3_0: - reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_3_0); break; } diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index bdb78d08b5b5..64f6dd0dc660 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -232,16 +232,16 @@ static int rt1711h_start_drp_toggling(struct tcpci *tcpci, switch (cc) { default: case TYPEC_CC_RP_DEF: - reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_DEF); break; case TYPEC_CC_RP_1_5: - reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_1_5); break; case TYPEC_CC_RP_3_0: - reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 << - TCPC_ROLE_CTRL_RP_VAL_SHIFT); + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, + TCPC_ROLE_CTRL_RP_VAL_3_0); break; } diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 552d074429f0..80652d4f722e 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -63,8 +63,7 @@ #define TCPC_ROLE_CTRL 0x1a #define TCPC_ROLE_CTRL_DRP BIT(6) -#define TCPC_ROLE_CTRL_RP_VAL_SHIFT 4 -#define TCPC_ROLE_CTRL_RP_VAL_MASK 0x3 +#define TCPC_ROLE_CTRL_RP_VAL GENMASK(5, 4) #define TCPC_ROLE_CTRL_RP_VAL_DEF 0x0 #define TCPC_ROLE_CTRL_RP_VAL_1_5 0x1 #define TCPC_ROLE_CTRL_RP_VAL_3_0 0x2 From patchwork Wed Jul 10 10:36:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812306 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 8707718FDB6 for ; Wed, 10 Jul 2024 10:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; cv=none; b=Rp5EOlEGRZSdRvmIvSP4NV12dpRFhnvCXgeUuqKydCR+en+TJRP9/1tR7FP05yGISPLx2cEAfJzkpy6dRaqM9LqBgej4ikJ9BMEDug4StfIDN8L7urgazp1JT8nV5nb1Okgcgd5LKsDDqtt871FnCEJvgoRjrMhknJjH/AQWKTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; c=relaxed/simple; bh=0vbDgVH+LSdHvPglDs4hdbAbxgr/GDEnxmyEdgVM9sM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YXJxbKhLTruHqbDN44RCw8SDjMzUkvhwe3bNW1OcCs2acSJEf22K0Et1rV4lhPl+HPjNkEZ/OZN5LkFfjmqUeEkG25JfbITJB8DHyoHO5CnxXPULJYFdd8G7bw+z9tfrRf+uXDpD92xWbGmteX89a2blw/4RuLWBqB9pCR5lpo0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=USJhRoTg; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="USJhRoTg" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a77c9d3e593so565573466b.0 for ; Wed, 10 Jul 2024 03:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607786; x=1721212586; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KpWex0J8opffQtz+HUwL/QKrEncZVAbQ4+K0E+2/CaU=; b=USJhRoTgxFgki0VT4S+OdQ4RMBP1d819V979VEXK2VUWPLhaL5W65ba0qrWd4L8WbW yWmHD8Ka0DFQW50HXxfQZ4iLInUDUbnA+t3ZZVNFY1gDX762XIGynem3rjM+mP47Qull pca15ku0inlkxh7VN1uyYGYQvs+SFuOXmHI69Mcesm0gMIcjXO9ZotjiF48BTt/0ALNL 0ATNAnYaX0EI45J6LYcCyT2rDdBfsYTkErvJ0Nu7lM1bP7BaChx+9CWvItOr4V48NE+e rnqEQBfTOk0PMw9e7TTeQoIuWfuZVEU0yMiliyZHKz0u6Q40l2J6dqSXC0nLxcK5bwgF bsog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607786; x=1721212586; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KpWex0J8opffQtz+HUwL/QKrEncZVAbQ4+K0E+2/CaU=; b=kogAD9NUtlkxbdfj2G4NufDTt7VDbkFZxSoq6+k1jfm+ZnaX+Vq1gd4oP7xo9DsIyT VD4KlX8FQV8ZBHxlRqTQN+PrXms4rWdvA2Jro3I+vyp9aIKxNFfDiigYkdxHgtUugvX2 KkMX8cjMZNp+idOIYyT/90nsPvnX1m9OU1Hh1D/bFRoMartXCU7s8YOhF7W0o7KI2xvG NCjokiPYQb454bNxoSe7aQMH+eW29XRluJmpKb1yU7bdtBYKsXBzZVUUhU5SWuadZile XxC5gdM/l0Ad/cL2eMybdsYR48Q1Awe1HeyjMCu99DiwsWi15xpS/lxz2NmgKLRAtTco BzHQ== X-Forwarded-Encrypted: i=1; AJvYcCW4VDutnJV+8UPNYeX/PmuleBFMn7c1cg3Iyu2S/8rvEtT51lJU2d5KCZFQqZS8lQnx8pqqjr24bU0AZNGLHSX0wUnPGka56q1U X-Gm-Message-State: AOJu0YyH2SX1hQ3wREAIfKYHuS0Nol22vEcRdRvkmec4nWBOpxi5U8OQ 7PWorrckRCUWaeHu1CbvCzeZCkG9Bclt1lYI5KOic1RB2cVhnBJMfZhxKzmpGMs= X-Google-Smtp-Source: AGHT+IGbCQykmyEoSZSMY+LIphQ2ikV/yNZ7fum8Hdl9038LaHNouuQhLYHMn+WIDwmXvJrV1rS1Ag== X-Received: by 2002:a17:906:32cc:b0:a77:da14:8401 with SMTP id a640c23a62f3a-a780b688941mr381186166b.10.1720607785890; Wed, 10 Jul 2024 03:36:25 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:25 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:13 +0100 Subject: [PATCH 06/15] usb: typec: tcpci: use GENMASK() for TCPC_MSG_HDR_INFO_REV Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-6-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Convert field TCPC_MSG_HDR_INFO_REV from register TCPC_MSG_HDR_INFO to using GENMASK() and FIELD_PREP() so as to keep using a similar approach for all fields. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci.c | 2 +- include/linux/usb/tcpci.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 5ad05a5bbbd1..ad5c9d5bf6a9 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -456,7 +456,7 @@ static int tcpci_set_roles(struct tcpc_dev *tcpc, bool attached, unsigned int reg; int ret; - reg = PD_REV20 << TCPC_MSG_HDR_INFO_REV_SHIFT; + reg = FIELD_PREP(TCPC_MSG_HDR_INFO_REV, PD_REV20); if (role == TYPEC_SOURCE) reg |= TCPC_MSG_HDR_INFO_PWR_ROLE; if (data == TYPEC_HOST) diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 80652d4f722e..3cd61e9f73b3 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -129,9 +129,8 @@ #define TCPC_MSG_HDR_INFO 0x2e #define TCPC_MSG_HDR_INFO_DATA_ROLE BIT(3) +#define TCPC_MSG_HDR_INFO_REV GENMASK(2, 1) #define TCPC_MSG_HDR_INFO_PWR_ROLE BIT(0) -#define TCPC_MSG_HDR_INFO_REV_SHIFT 1 -#define TCPC_MSG_HDR_INFO_REV_MASK 0x3 #define TCPC_RX_DETECT 0x2f #define TCPC_RX_DETECT_HARD_RESET BIT(5) From patchwork Wed Jul 10 10:36:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812039 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 BCDFA18FDC7 for ; Wed, 10 Jul 2024 10:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; cv=none; b=IqVWZuFfKUU09ZUZ/tQo5hqkDUMuLdnTOykS/MsH7rcsxFjKsO77Dje0Fqv3F3SOnC8z+YMzOHEDOYvoLlO14XUVnYB3PDHgnDNEAPAC6oR+71MTt0fj4SMmvf6SiOhwGjfEDuDkqSfVymWo9gwHnzRokLW9itEieVRNTz0RCqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607789; c=relaxed/simple; bh=L+ZjCKgJQd3G0PXfqSF2z2XSQSaCrAKVX6BKXiPVSoU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qK28K61hbJ84jmEmUlvEEYcAxYxJAIY4sMcLTIu5gyFHODroQI9mlAnwIWUqXTqi0O5X9ceNqcnAlWk8injS+abYXPXABjx13BGgq+UGI9ofeNW2ObCrHlBlA9KvdpT4oBjLy5r1cxFiMBNPNMeXc2S6yRIXwfIqpRTL7gI7cQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=O5cofXG1; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="O5cofXG1" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a77b60cafecso748184766b.1 for ; Wed, 10 Jul 2024 03:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607786; x=1721212586; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=YiC5Ast8q9nR3kdM0WnbV9ytZ6Sn5cRnJD9TbOLzqZ8=; b=O5cofXG1F5FTXiDem2ZXmdm63Tz7E/sZfwGlp6XBwmu06Wfz0E4DlisfC6plvw2A5u zbiqhwrzWLJIwX52TpPpAX/C4MwAaaTrKecASXBhWevtFLzW1k45aSBJxdb6RCIFTy3q QXESoHOm2R4gbT4SbTG0opUub+jpauCeltzzn7Wgvl6PQUTfY30bw9jv+4Wu9IWC8sak IUIvLoUySWV+pdrnItLHK2XfvKJuO9L8iYZNYaXwa1Zw4Yqps6TObaBvtz8gCesD0C00 8E03OpzYWrnfEA80lSjiuRIc9oyO6fXpc7IRP9itpM2QwFm5YX2BdiVjHn7Gj5Ubz6ak R0Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607786; x=1721212586; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YiC5Ast8q9nR3kdM0WnbV9ytZ6Sn5cRnJD9TbOLzqZ8=; b=sf2o+y7OyySKdDkJ5kil3u8+EKVyz0SH8YF0hE5Fflb3+y5Pq3Uv6/sjm47lnnS478 D8XmlBpR9x4K9RgE7KZqV8qsd9Cc/m93M2Kpd74/A7WkrG8YsfnZ+noqmTFBMIjJgrXV 33bbfsDTT34xFQjaUUJl55yRGOJii+XgkIUYNwu+Sj38TTr1EhZjKbAp3dR2OcfGMqR3 BD7tqVW5vVoQRyWxey0fKdwmai8axapcm1kYAY60o3dLlIGAMDDw/jYGBesWueLjC6cQ BCZbaLLCO5QGrJuPu1/HJ4UvIQMkc3XLfmYtIqNcpL4q1vvmCHedZqW93qPYuc5HYnSQ jbJg== X-Forwarded-Encrypted: i=1; AJvYcCX8+FMlznM2jUNvW+q3Knt82Aha3IUQf4YXcqwcMjhaK/OyfznUM5ZqkMNYWNhFYt6u4KeGVnVxHX/SMuO/kLuuQPjtIvICgCfz X-Gm-Message-State: AOJu0Yz83+F5Pe7Ozi15AA4SPhpxLKJmNVKO2Eypaz7Dkzl/Rede5iXa EK9DroIuPvnzVA9fwptLOSzSdmGm9vnY5CiTYYeXyTSld7XOUvQUI3UAaENbtP8= X-Google-Smtp-Source: AGHT+IE+yjpCcruIKHgr/jvVPlk1m+tPU0e6J3vGdtJfJHpFEX7F5AeCWZd8y9c3wpmTQ6Iekk68xw== X-Received: by 2002:a17:906:7d1:b0:a6f:e47d:a965 with SMTP id a640c23a62f3a-a780b6ff0ecmr330515266b.41.1720607786309; Wed, 10 Jul 2024 03:36:26 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:26 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:14 +0100 Subject: [PATCH 07/15] usb: typec: tcpci: use GENMASK() for TCPC_TRANSMIT register fields Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-7-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Convert all fields from register TCPC_TRANSMIT to using GENMASK() and FIELD_PREP() so as to keep using a similar approach throughout the code base and make it arguably easier to read. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci.c | 7 +++++-- include/linux/usb/tcpci.h | 6 ++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index ad5c9d5bf6a9..b9ee9ccff99b 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -607,8 +607,11 @@ static int tcpci_pd_transmit(struct tcpc_dev *tcpc, enum tcpm_transmit_type type } /* nRetryCount is 3 in PD2.0 spec where 2 in PD3.0 spec */ - reg = ((negotiated_rev > PD_REV20 ? PD_RETRY_COUNT_3_0_OR_HIGHER : PD_RETRY_COUNT_DEFAULT) - << TCPC_TRANSMIT_RETRY_SHIFT) | (type << TCPC_TRANSMIT_TYPE_SHIFT); + reg = FIELD_PREP(TCPC_TRANSMIT_RETRY, + (negotiated_rev > PD_REV20 + ? PD_RETRY_COUNT_3_0_OR_HIGHER + : PD_RETRY_COUNT_DEFAULT)); + reg |= FIELD_PREP(TCPC_TRANSMIT_TYPE, type); ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg); if (ret < 0) return ret; diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 3cd61e9f73b3..f7f5cfbdef12 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -148,10 +148,8 @@ #define TCPC_RX_DATA 0x34 /* through 0x4f */ #define TCPC_TRANSMIT 0x50 -#define TCPC_TRANSMIT_RETRY_SHIFT 4 -#define TCPC_TRANSMIT_RETRY_MASK 0x3 -#define TCPC_TRANSMIT_TYPE_SHIFT 0 -#define TCPC_TRANSMIT_TYPE_MASK 0x7 +#define TCPC_TRANSMIT_RETRY GENMASK(5, 4) +#define TCPC_TRANSMIT_TYPE GENMASK(2, 0) #define TCPC_TX_BYTE_CNT 0x51 #define TCPC_TX_HDR 0x52 From patchwork Wed Jul 10 10:36:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812038 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 7E5EF190693 for ; Wed, 10 Jul 2024 10:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607790; cv=none; b=d5fwr7VLVZYRMywhNeSMogio9Ae5hNZ0zEso9a7yvB4/1Ypaaw4Yja6bAcmpAuQqBWM0ARo7t8XKqQgbaDcL00howtTWYl4EgW5sK5YzRxITNgq905OF+b4aYNJfDUZWu9y4mqA3YUlF3mh7H/hEBf4wgkTKv+O5ydxWWXsMCCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607790; c=relaxed/simple; bh=UAK71+lPiVudSRvlmklIgP5araaTerPQgArmnySOaQo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HCdyk0G/79/NoLaJe4zIW9lWE/OZyJJAG1WGrKbohQHIweqxn+xwsTzcAygy3kK5a+ybBtQTEACLfE2xiaWCZz9oUTWlQnnT6ee7WjQYykWABYeCOQS8NgCC95QkEB54puveSLQ+ujSrjmXT9Epxand9F7BvvN7DeDPTaWNN/zk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=GHuzfaLA; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GHuzfaLA" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52ea5dc3c66so8751513e87.3 for ; Wed, 10 Jul 2024 03:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607787; x=1721212587; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NJ8rGYIkXyuBqurWfe+RKCWq1Fp47kuxHXtN7U7bICs=; b=GHuzfaLAfxUEjxmPSRYkzl70rG/3RBNa1geqPCG3Ge7EEjCoI/vLmrJPr0mT2YxRWR HddaGLk0x5+/elP/DzuDvVDEw0B4NFCeb27C8k+RjYz3bNyHiEZ+NpBFt7h0IR8Bgt10 LguNxBKsj9BVLb6/9MZpTdFiij5mI78+A8iAnl5YOLxO7Phf+RFIf3dniU4yXYKcUZxz 73fMFhhUftbvK53W++kKycUh3mgh6MkOqsWjRqSBvV1ie1y/LvhDO9X/TACT6HYHFJcK O/iYsfdqG15Td1lhDb7JFLw9syiV2zD6oKeA9DheDEQ/8uaB8o5LR7xgiHXRomWlYFvT MQhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607787; x=1721212587; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NJ8rGYIkXyuBqurWfe+RKCWq1Fp47kuxHXtN7U7bICs=; b=SFQ6hE/7yOboEhZK7/pgvo+gY7tULrDFdvO7pVORDNuLcZ2FFSdON8PCm6zWV167Zn k39xNPODELfT5OQbDycxRdk1gmfrGy6PXOQX4OFoT/IxqGt8sGee+4ougCStYwFkGiSX TZdwjiKMZ0qdRZvut3UJDeFqlfoGv7o9awiwK1NrvUy8lfm9UywhZFcSw0xvJ/qAo2Hq covCAJb0IfdTWQNHp8ARTaEWyTMdFm/uL21qLSMqBy2c7SXvCz5sPpYQeDMT6Q0Yj+uF g61uatQi/qUTBpWZ05MWOJaDVWIaMmtUA6SKMyw767j9XF2wZGjAeL9CHIIrZyZoLUqK CqsQ== X-Forwarded-Encrypted: i=1; AJvYcCXSC1fuY0JShCKmeDQ9Bp78Z09B6xZpxFjnv+oTTh76yi81jUtQaLcrX7pTvKIEzsG+iBik8LOuTKLA2jHN4+RL2ThUbKPbViBx X-Gm-Message-State: AOJu0Yx5f0/drFkpzKf1HfkWd6Jv9E5LFcNUHQiwaNgBgH6Ed9D+hLgQ IhxQOKrz546cLznKIOWAx3aZE9BWeK8ttI57u0cS8JgIseCo2NFtY4HxD3f/2bk= X-Google-Smtp-Source: AGHT+IEAemkZcOpN1KiuMHE8Tjf4sRBQIebOpKvSDum9xj1upl9bH+uRFUUVBjy4KJUn2DphCFwPWA== X-Received: by 2002:ac2:4355:0:b0:52c:cb8d:637d with SMTP id 2adb3069b0e04-52eb9991e7bmr3322394e87.5.1720607786736; Wed, 10 Jul 2024 03:36:26 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:26 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:15 +0100 Subject: [PATCH 08/15] usb: typec: tcpm/tcpci_maxim: sort TCPC_ALERT_MASK values by bit Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-8-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 This makes it easier to see what's missing and what's being programmed. While at it, add brackets to help with formatting and remove a comment that doesn't add much value. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index 87102b4d060d..ad9bb61fd9e0 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -97,11 +97,13 @@ static void max_tcpci_init_regs(struct max_tcpci_chip *chip) if (ret < 0) return; - alert_mask = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_TX_FAILED | - TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_RX_STATUS | TCPC_ALERT_CC_STATUS | - TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | TCPC_ALERT_POWER_STATUS | - /* Enable Extended alert for detecting Fast Role Swap Signal */ - TCPC_ALERT_EXTND | TCPC_ALERT_EXTENDED_STATUS | TCPC_ALERT_FAULT; + alert_mask = (TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_DISCARDED | + TCPC_ALERT_TX_FAILED | TCPC_ALERT_RX_HARD_RST | + TCPC_ALERT_RX_STATUS | TCPC_ALERT_POWER_STATUS | + TCPC_ALERT_CC_STATUS | + TCPC_ALERT_EXTND | TCPC_ALERT_EXTENDED_STATUS | + TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | + TCPC_ALERT_FAULT); ret = max_tcpci_write16(chip, TCPC_ALERT_MASK, alert_mask); if (ret < 0) { From patchwork Wed Jul 10 10:36:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812304 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 BD4ED1922DE for ; Wed, 10 Jul 2024 10:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607792; cv=none; b=O9UNeRWCSTfwQSxsmMB+hBlp1R1BKWaWTD1kaND5Iumjy1KxvqC3yJA3WRKIYO6+AWJOdajwInfhGSxvO2UifXUOHeHzIRj/wrCBlVWGHvF6V4SvlWtSbyNBRlQOxX5ufC2XebvfV9mO8CHOU7QjRd6YZ6C9MOx9LPUr+Lfx6Kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607792; c=relaxed/simple; bh=Gh7tR4aP9b3dMS0ig0OinTPBM3NkuA777qx/jRALIJk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WG3pISJL42CTblYvHe4mBfyZbTx0QsWMEspd6ZjlVOa/UC/AVtDlzyXi75OOm0dnQKrqWxE8WQgVyaP1/D5lFlkuNsMQX849GSgD6tmWwQdNWlyRjfJt4uBLnCNhLJd9DKXbFnp4luHHGjGj3q5/WhKwvZp+4qNCs1FNRzIMJNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MeLVdz1U; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MeLVdz1U" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a77e85cb9b4so430888766b.0 for ; Wed, 10 Jul 2024 03:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607788; x=1721212588; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WjiPMEKAWGEGZZNGnZ5jjN6tgFH5yhFtTqyqgRl8h3E=; b=MeLVdz1UA7b8E76eKlPSLQFo9v78NM8jo11fLJlWW5xsmHpvEtIqewy8EjQ0YPcRIZ 588IxYu/Vhy4fDnW0GGbO4hlU5sKsae5amiz3AVgw5XSAQoZ1y2429Y2h0ra071bD3Zw Pvm6btEKO8S6NnMoRu9KClBYri44stFdEr+EAfJx5yOzNX1w24qhpGszaPm1f9hcWkK2 Ja42NT96mN5v96SIwCdPgwEElXFqQ6YM3WIPuK/4XK75A/NGPhZXegYlwjJDq85d7RO/ ik7d3m2goVUuWeplFuKizPTnTZA/wvX/txdl24TslinNR/CQfWAuNHoFf/h9TF5N3cOW bDsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607788; x=1721212588; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WjiPMEKAWGEGZZNGnZ5jjN6tgFH5yhFtTqyqgRl8h3E=; b=THziSd9MyMnakDZF9R3Ff7wOycLlC0Zv0EmvBwfSwoo9+8bkx+qaZseVNDHHCvzuOn uEVVC/O/Wd6E+S0WZjov86iT254yR8AqNwiheif6wRj7Gur16XfVmmyZxkiEkHfrOuex WRBIIp+5NSBcUqYzJYYe2cjo0l28AKjrdsm/avGbYmq4EExkhX7a3ic+9IKjRcDPMM44 ZXu1Q/SwGXLj2jQhKccCN+Lrra5Ow9ICvqLii5gmLud64dsDHuZAKyQ3iB5HEHc9Ody5 YbuMGw58H9E73lAUcP/GLm9UAXZF68ZnkUSfuFcagYWq+wwt+AneSG5FZUf8BK6kgzTz xFIw== X-Forwarded-Encrypted: i=1; AJvYcCUZkveixpBI+Z8khqtDBhMTpydMtt9QK4wBnNJPUDzdjzu+KgygxR5Tt35Se45GTWSDMMpCgEDq9/pJoiH8tVA4k26E/zWLvm3T X-Gm-Message-State: AOJu0Yzb+fooYukZwOb6Do4W3LzmOPOINjk2GodRUCYOoBMbi/hWH/Do 8jDrkrCK2kFrGxLpIin0qoYv81sph3ATf/W22PgkgRZ0oRiIoiIEd6uMUM/Sx8k= X-Google-Smtp-Source: AGHT+IE5hxKfVWgP9N3rYz80ioQEE8TEjgdhOaRO1OuJCq2mi7IUtcanoHfuvuVGxv5EDLkBBXZiWw== X-Received: by 2002:a17:906:1782:b0:a77:f2c5:84c4 with SMTP id a640c23a62f3a-a780b68a1d4mr333328766b.12.1720607788116; Wed, 10 Jul 2024 03:36:28 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:26 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:16 +0100 Subject: [PATCH 09/15] usb: typec: tcpm/tcpci_maxim: simplify clearing of TCPC_ALERT_RX_BUF_OVF Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-9-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 There is no need for using the ternary if/else here, simply mask TCPC_ALERT_RX_BUF_OVF as necessary, which arguably makes the code easier to read. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index ad9bb61fd9e0..5b5441db7047 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -193,9 +193,8 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status) * Read complete, clear RX status alert bit. * Clear overflow as well if set. */ - ret = max_tcpci_write16(chip, TCPC_ALERT, status & TCPC_ALERT_RX_BUF_OVF ? - TCPC_ALERT_RX_STATUS | TCPC_ALERT_RX_BUF_OVF : - TCPC_ALERT_RX_STATUS); + ret = max_tcpci_write16(chip, TCPC_ALERT, + TCPC_ALERT_RX_STATUS | (status & TCPC_ALERT_RX_BUF_OVF)); if (ret < 0) return; @@ -297,9 +296,8 @@ static irqreturn_t _max_tcpci_irq(struct max_tcpci_chip *chip, u16 status) * be cleared until we have successfully retrieved message. */ if (status & ~TCPC_ALERT_RX_STATUS) { - mask = status & TCPC_ALERT_RX_BUF_OVF ? - status & ~(TCPC_ALERT_RX_STATUS | TCPC_ALERT_RX_BUF_OVF) : - status & ~TCPC_ALERT_RX_STATUS; + mask = status & ~(TCPC_ALERT_RX_STATUS + | (status & TCPC_ALERT_RX_BUF_OVF)); ret = max_tcpci_write16(chip, TCPC_ALERT, mask); if (ret < 0) { dev_err(chip->dev, "ALERT clear failed\n"); From patchwork Wed Jul 10 10:36:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812037 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 7046A193077 for ; Wed, 10 Jul 2024 10:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607792; cv=none; b=f+1+1FbHNlgoXpHCKtkvSQkBm6i4vGYuzJggdRH1MtxZeJc/l5k1Pik5HUA7uP4Tfg4cFqtcw+1z/2lACyWKIVb4/Gl2zqgAKGr8nzs2lABBqNUA0wRLNrZFJa5MHaAEW4rxKszmYv+0KIHfbIgegJq/i4VVRP6HXX6aphaSBuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607792; c=relaxed/simple; bh=Ju9WlpABJdDrRTF/57aRXBECK1G9qdIeBIwu/UKN1oY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hf80fXiKjylGvIj8niOGpNdAbdl4AUylA04shcNA1OiprRosS2BXNfpBTkLsSSKJr9JtAjcVMSPdgOrBRHjidIXSWy2HWPgNg8nP21LzG6YYyD9p6yzvhtRi3yuVIorMY8D2YRKDT7PoDBssifrAf1s3Fvrwp8DHmUfxIHgPTlY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UWP61PZO; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UWP61PZO" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2eea8ea8bb0so53048701fa.1 for ; Wed, 10 Jul 2024 03:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607789; x=1721212589; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6OaJXkmGsoVDOS/uUKpK/gkJkaOn2bDjRVF7bUSlD2Q=; b=UWP61PZOTBH+43o19N/jnIyrCq5VV1vuT1jPAws+ISosKcVU/hYWwYhvq8iLOXsAlO q12piSif9bf2UmLenLmfTc8OEHhbK4hZtz5V/i7DhAPaVg+ZWp/yyCfr+pi7LM67wuF/ ekX5XnVUaCvFCs2HL4QA+P6O0ImuwcpBkhRUX9xz8wh63XHmG3E+oyPZqILOECiE2oBr Q+TZyNdzUJ037IW6UI2kVSnG8l3lnrN0djyoFCBKNCQgVG4CTtR0pIZm/gOSerFnHXNJ RCE/D8zR3L5baVP7+BDojte/NiuLx+64nuriclY37sn6cX1hZ5kRnrxA+C7lWMJREXYc IFXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607789; x=1721212589; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6OaJXkmGsoVDOS/uUKpK/gkJkaOn2bDjRVF7bUSlD2Q=; b=gJJnCcgS6+mkqSdaxFiLhIpRyA6QpLlVnAj8mEDf1B/Csfeys8qowjMWKgHj/t5ai+ Zp8rvOy2cT1GFo9zV6eNxDzdrj6kFRRyWnZPSwodN+DUER2a9sQMFYRKBhJ2ujQ600SW p4WSreEBXLKhKNwsSFclWKLzyW8uNZ2lxinPkFhMJdDFmxvDo7Di55b5Es6ZefLFBIld EJDEmcYgecgPOgTO+EHB6F1EpTLKwnioQ9xh1pg9vmfMUqNlVj1UKfkpmahX4ydYsxBy keDGlRfdwyTkJrDtbSoC+oPX5n+zfS/jqKRAAXl3vSJhWo4OeTml+BwBcsO34oIkLrt4 jd2A== X-Forwarded-Encrypted: i=1; AJvYcCU2Z2eA20qvFBS5YKSQf0r5pqzK8Mnmq88917WldLRq1AXx8+yJDiAP6ayDwPad9gexUeItqYc8xT4qOc+SKlH2kNR9ayD6EFlP X-Gm-Message-State: AOJu0YyOyIrvDKfKUKW/DGM5d661fEvaZNZraROT14TXAwpwzl6my6dr qg7z2lBZQpg306UZpY3mKbV3XyA7124UJ4D0mDvq+XXgg7A/EaF81nReNGkqC3I= X-Google-Smtp-Source: AGHT+IEMpfogYtC0LRvrYarAjzqKHCaspVd/d5SG1JDi4DhoiWZSU86bS9h+zxWDd25iFHnSWgJRwQ== X-Received: by 2002:a05:6512:1286:b0:52d:582e:4111 with SMTP id 2adb3069b0e04-52eb999b398mr4345456e87.18.1720607788683; Wed, 10 Jul 2024 03:36:28 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:28 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:17 +0100 Subject: [PATCH 10/15] usb: typec: tcpm/tcpci_maxim: drop STATUS_CHECK() Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-10-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Only one user of STATUS_CHECK() remains, and the code can actually be made more legible by simply avoiding the use of that wrapper macro, allowing to also drop the macro altogether. Do so. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/maxim_contaminant.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c index e7687aeb69c0..8ac8eeade277 100644 --- a/drivers/usb/typec/tcpm/maxim_contaminant.c +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c @@ -46,8 +46,6 @@ enum fladc_select { #define READ1_SLEEP_MS 10 #define READ2_SLEEP_MS 5 -#define STATUS_CHECK(reg, mask, val) (((reg) & (mask)) == (val)) - #define IS_CC_OPEN(cc_status) \ (FIELD_GET(TCPC_CC_STATUS_CC1, cc_status) == TCPC_CC_STATE_SRC_OPEN \ && FIELD_GET(TCPC_CC_STATUS_CC2, cc_status) == TCPC_CC_STATE_SRC_OPEN) @@ -368,7 +366,7 @@ bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect } return false; } else if (chip->contaminant_state == DETECTED) { - if (STATUS_CHECK(cc_status, TCPC_CC_STATUS_TOGGLING, 0)) { + if (!(cc_status & TCPC_CC_STATUS_TOGGLING)) { chip->contaminant_state = max_contaminant_detect_contaminant(chip); if (chip->contaminant_state == DETECTED) { max_contaminant_enable_dry_detection(chip); From patchwork Wed Jul 10 10:36:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812303 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 BB169190044 for ; Wed, 10 Jul 2024 10:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607793; cv=none; b=nltJDiunxSOQTFyUP4LUITmeNkkQNsD6eUw2UULqYwtq5LJHntm9WHhP7rMLxG0HopTm7rsemaXHdfDwG0IgyZAqcFTBZmJgWXbsUsY450CXafqDQshPT1+yT+VeGQBKRb1RmTG4p0cqj/Tb2Lz5r+eVq9ufn70W7Ty7apEEXJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607793; c=relaxed/simple; bh=iKZAjrHtfdkDTBcwqIT8IIAuEteBm+oT+4/Ldd8Zv/s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GV8h2K7GQPIzqNNqrsQpKdyVimWITxiJ3Q/XFEqgyEs/XkVdGDh+b5pIlgOmtkN+5M7A3YE/AI3Hm76BLPIWnsijguLrPcBLK5IqymQQiENomVQefHJDUGGkV4D2pw0yBpTqmAmZE+wL0SAd9/2cL2bXl6b4GiDaXtQX9j9IwWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=XSEVjnrf; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="XSEVjnrf" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a77e7a6cfa7so392416166b.1 for ; Wed, 10 Jul 2024 03:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607789; x=1721212589; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4f4U8/fOsC4P4OR6kmi2OCEmKlH0wqzpnH4yJN7zB2M=; b=XSEVjnrfrZwSrgh4Il98HiOYv0vLV+uEN6PJkWiSU+kVeRhLw8EU08D+4RZ2rNgvvb w93W6aaJmau7Y0bb22oMqWoNIJItBmPSbTH+BuFSEuS+tzy/bfR0ji4zNSSM7ExVoSqN 2OMj/uFdEU39EBsT8P82by/+B6HemnaRTO6OMYr7SwHbbiGs5pFC7UnFAvlx+zhVz4cL GonW+VMwARPSVCAtREXDjio+TuEh3Uo/l+DuJzlkPJoEmZzGKNVuRm5YKkS+FF2xsc8P v5lAeRMCi0Fzs/0ZNOLdBzAqKQ4fkXEMRxFf61egaCJZf34lbh6wbvJC6gRMvjE1xSqn 8XaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607789; x=1721212589; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4f4U8/fOsC4P4OR6kmi2OCEmKlH0wqzpnH4yJN7zB2M=; b=TcHO4E2iN5kQduFfRDopdttgUJlClE6gZhMjYZYiiH3xXU3l85/vQ5aHKGrS8JbP7L YfucgsfTgdMh/5Vqrr1bpdo/gWBCWevCERfK7HOF2shOA6y7W8L5XiGoazJxszjPtMI9 HeaVz4FlLlYLIhuTul1PlTeN+2c9EcfLw1ZQyAE48jSfy7UJnqxJRXgqDvxkYQ2toPgU wUKaZCFmOjmCRX0nA8pLHidNrnsBg9jsEmQ/rFi+u5a0o1erbhglEkLk2HR+efyw8x4J y2QKm019yCGn3gxnt5k/dwsIZNOhwEzAcISpuUFXqftAyzPIJROuIsFWeyZU7YrFztrZ +L7Q== X-Forwarded-Encrypted: i=1; AJvYcCXAMc6uiFkKpTjutFnKV5yks53B5Y6TbQ0RuoVUmRSxg+Hbw5TsLW2MgFP2msWwJBY1NsPKmRjBQ1Jo5b1iXnzlmAJUU6bURQuC X-Gm-Message-State: AOJu0YzRAG3mr6z5UczVVVtCF6lLCazRU9kO8RenpEhrvlseuhuTidnr KaeRfESbz4tERzI7gns8vT4HHG58g1HAaFy55+OKNZDz44WlEcFmggbGZZ8OQ30= X-Google-Smtp-Source: AGHT+IEvqzy9YTroir6a8Gy3exKL8AyeWU3F+zp1bH+uYbn1XzaklbsibxtyHBAUB/KlXQLl381+AQ== X-Received: by 2002:a17:907:7e82:b0:a77:bf32:b91e with SMTP id a640c23a62f3a-a780b8848e7mr366241666b.49.1720607789137; Wed, 10 Jul 2024 03:36:29 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:28 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:18 +0100 Subject: [PATCH 11/15] usb: typec: tcpm/tcpci_maxim: use GENMASK() for TCPC_VENDOR_CC_CTRL2 register Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-11-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Convert register TCPC_VENDOR_CC_CTRL2 to using GENMASK() and FIELD_PREP() so as to keep using a similar approach throughout the code base and make it arguably easier to read. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/maxim_contaminant.c | 18 +++++++++++------- drivers/usb/typec/tcpm/tcpci_maxim.h | 6 +++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c index 8ac8eeade277..f7acaa42329f 100644 --- a/drivers/usb/typec/tcpm/maxim_contaminant.c +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c @@ -116,13 +116,14 @@ static int max_contaminant_read_resistance_kohm(struct max_tcpci_chip *chip, if (channel == CC1_SCALE1 || channel == CC2_SCALE1 || channel == CC1_SCALE2 || channel == CC2_SCALE2) { /* Enable 1uA current source */ - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL_MASK, - ULTRA_LOW_POWER_MODE); + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL, + FIELD_PREP(CCLPMODESEL, ULTRA_LOW_POWER_MODE)); if (ret < 0) return ret; /* Enable 1uA current source */ - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL_MASK, UA_1_SRC); + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL, + FIELD_PREP(CCRPCTRL, UA_1_SRC)); if (ret < 0) return ret; @@ -176,7 +177,8 @@ static int max_contaminant_read_comparators(struct max_tcpci_chip *chip, u8 *ven int ret; /* Enable 80uA source */ - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL_MASK, UA_80_SRC); + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL, + FIELD_PREP(CCRPCTRL, UA_80_SRC)); if (ret < 0) return ret; @@ -209,7 +211,8 @@ static int max_contaminant_read_comparators(struct max_tcpci_chip *chip, u8 *ven if (ret < 0) return ret; - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL_MASK, 0); + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL, + FIELD_PREP(CCRPCTRL, 0)); if (ret < 0) return ret; @@ -298,8 +301,9 @@ static int max_contaminant_enable_dry_detection(struct max_tcpci_chip *chip) if (ret < 0) return ret; - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL_MASK, - ULTRA_LOW_POWER_MODE); + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL, + FIELD_PREP(CCLPMODESEL, + ULTRA_LOW_POWER_MODE)); if (ret < 0) return ret; ret = max_tcpci_read8(chip, TCPC_VENDOR_CC_CTRL2, &temp); diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.h b/drivers/usb/typec/tcpm/tcpci_maxim.h index 78ff3b73ee7e..92c9a628ebe1 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim.h +++ b/drivers/usb/typec/tcpm/tcpci_maxim.h @@ -20,9 +20,9 @@ #define SBUOVPDIS BIT(7) #define CCOVPDIS BIT(6) #define SBURPCTRL BIT(5) -#define CCLPMODESEL_MASK GENMASK(4, 3) -#define ULTRA_LOW_POWER_MODE BIT(3) -#define CCRPCTRL_MASK GENMASK(2, 0) +#define CCLPMODESEL GENMASK(4, 3) +#define ULTRA_LOW_POWER_MODE 1 +#define CCRPCTRL GENMASK(2, 0) #define UA_1_SRC 1 #define UA_80_SRC 3 From patchwork Wed Jul 10 10:36:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812036 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.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 02501193446 for ; Wed, 10 Jul 2024 10:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607793; cv=none; b=O/YshJDfkeDyTpRPLNF8Q4b7SelCm+ySh6ulwnPu1RMCTKXTSLmK8gDx/vPuaWePIy64S7dzNa9TLCq8Jpe8q7qJd8W9vm7grv7YnIqW1SO/OqD5V0MKmbwsWfIo+wQLAtHnxM0UtbtKiRDOtvdXXXnzpx+jMF8KXyGYHfioZ9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607793; c=relaxed/simple; bh=6F4oRj5CmywAwgGMzR18n53zdqYf4amN+tox2qEAYDs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qMhCOTrbRsMRFlCT0cGXDZMd0/1KTcvfp8hf9Vt7BqriCrC2CzsucJw624gy+Xu2pslFakq5Y2NU3E7eHoe0wW3F9MRWh5fzuDCtChcaVESu6SFBBp2KqEowdvLEdbZLNYUyTtoJl0tQ9pE0NVFEVmw5LyAGyW+x75wv4OSPyYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=bGne+uzr; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bGne+uzr" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a77b550128dso772816366b.0 for ; Wed, 10 Jul 2024 03:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607789; x=1721212589; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JA4sofr4YaUcqBd7byii4fe2UEfxA6G4UUKcsqWmUZ0=; b=bGne+uzr3FXLVEhxk33ogphKsevCf2S6tkk2PnvPuP/LB+tAx4DPfgp0nUdSHFN5su 0A272eJelDZ42zcg219dzSBJLvGDAfrCh5QTxvU3bLYpszRG3KiUF5UEGdTBcXel5NO4 aaszfCXgrx2233FtT/lZ4f+taNmn+m2TOJ1njx3Uw4dFDQyksx+hVpNUIeVypOpRQr/l QNvT7fihPz+RZgQ5NfBlPFhqaNOuwdKcMOFUYkI3ZruGjBZcPhvefrjXc5A9RpBR84+G KjUUaTvNVn9bqz0yL6snOslZvO1kLOj3Gj2FqNKJkmsPcWgw/rc8qf4KrCd5ADud/bcn +arQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607789; x=1721212589; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JA4sofr4YaUcqBd7byii4fe2UEfxA6G4UUKcsqWmUZ0=; b=dHtFJuUEn2pDL7JRztOAjvkgde2/LOZxAyBqc92OpoEQoGq58qPk0h58l28BTRZVsG 2SiRl3fzEF+6HfUqIAAn8Blh8EWanJxEXrBUc2c7F6BTxYyI55H7Dmyct1Vkv4fP3M0y PzKC2HJTnj2Yr12Co13nEFJEJXVlum2KREpBoFjZDwcaN/YI6FDsYGM6VD1LCnpUKyN/ j/t8tDxcu62YIg3futJZFaC3MX4hprwyEO0TaFT3HToF7ixzjDj08su9+6gWThtN+Lid DDvX7pHjzAfQVIP4Rm3sE8i3vmrRPOuRIdj6SW4i6tPuU64DRlb/rAR4KD9JBm3SQI7G Mtuw== X-Forwarded-Encrypted: i=1; AJvYcCX/Cg+Imcu69aJgXuFGOgtq6RVqaHXCwid6dV/6+qN72MGmykXSs5NWYNngCpYKo1d675jkrTDUy80Pm5Wox3kXCBs/+ap7MZJx X-Gm-Message-State: AOJu0YyxXHYjCNIpGa5QjpXzvprPU2/tSFKSUO2ERynlzr2ugxEDFb3Y jaKOuA7FbD2VPCCw95CTM3JUAIyvw33mo/1qqvvVv/k3qDdb+/Pp9YocuGej+50= X-Google-Smtp-Source: AGHT+IGijgZ/qjIv9JTzm6BbhLw1tuyBkh+jw/5AUldqnh2NXH3H9j2aMvTMeUXMF7JiFKpsZTYgIg== X-Received: by 2002:a17:906:4e98:b0:a6e:d339:c09c with SMTP id a640c23a62f3a-a780b882737mr402489866b.48.1720607789565; Wed, 10 Jul 2024 03:36:29 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:29 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:19 +0100 Subject: [PATCH 12/15] usb: typec: tcpm/tcpci_maxim: use GENMASK() for TCPC_VENDOR_CC_CTRL3 register Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-12-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Convert register TCPC_VENDOR_CC_CTRL3 to using GENMASK() so as to keep using a similar approach throughout the code base and make it arguably easier to read. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/maxim_contaminant.c | 9 +++++---- drivers/usb/typec/tcpm/tcpci_maxim.h | 9 +++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c index f7acaa42329f..cf9887de96c9 100644 --- a/drivers/usb/typec/tcpm/maxim_contaminant.c +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c @@ -283,10 +283,11 @@ static int max_contaminant_enable_dry_detection(struct max_tcpci_chip *chip) u8 temp; int ret; - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL3, CCWTRDEB_MASK | CCWTRSEL_MASK - | WTRCYCLE_MASK, CCWTRDEB_1MS << CCWTRDEB_SHIFT | - CCWTRSEL_1V << CCWTRSEL_SHIFT | WTRCYCLE_4_8_S << - WTRCYCLE_SHIFT); + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL3, + CCWTRDEB | CCWTRSEL | WTRCYCLE, + FIELD_PREP(CCWTRDEB, CCWTRDEB_1MS) + | FIELD_PREP(CCWTRSEL, CCWTRSEL_1V) + | FIELD_PREP(WTRCYCLE, WTRCYCLE_4_8_S)); if (ret < 0) return ret; diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.h b/drivers/usb/typec/tcpm/tcpci_maxim.h index 92c9a628ebe1..34076069444f 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim.h +++ b/drivers/usb/typec/tcpm/tcpci_maxim.h @@ -27,15 +27,12 @@ #define UA_80_SRC 3 #define TCPC_VENDOR_CC_CTRL3 0x8e -#define CCWTRDEB_MASK GENMASK(7, 6) -#define CCWTRDEB_SHIFT 6 +#define CCWTRDEB GENMASK(7, 6) #define CCWTRDEB_1MS 1 -#define CCWTRSEL_MASK GENMASK(5, 3) -#define CCWTRSEL_SHIFT 3 +#define CCWTRSEL GENMASK(5, 3) #define CCWTRSEL_1V 0x4 #define CCLADDERDIS BIT(2) -#define WTRCYCLE_MASK BIT(0) -#define WTRCYCLE_SHIFT 0 +#define WTRCYCLE GENMASK(0, 0) #define WTRCYCLE_2_4_S 0 #define WTRCYCLE_4_8_S 1 From patchwork Wed Jul 10 10:36:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812301 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 8FB2D18EFF9 for ; Wed, 10 Jul 2024 10:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607795; cv=none; b=GQSQ1VEdhNa1fsyd8HToY3QxQqzi5WZeJ37HzSc8rJHHUBEVVXMNs7z0NHKZDUWELNhlFZG409WGPu01R5DG04BfJ1sPvT2GgnpWRBbNBE/KE8zPesVRjO8Zdn1hoROMkW3UNQsQT3dkTw7rofnmlwpc+2c5vZ34tB1cGAUBw7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607795; c=relaxed/simple; bh=5yRLOBbpIkonyEMF2zlkIakdxYmFf6q9yRfJ8EyXCI0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oK3vYLS5jOWgyr0+lYzcZdu+adS4fMZhsglwKUmCRGbs/j9dE/8o8Pfg8OF15CH3oWs+LdqHeJokRjmRoW5Op2QAJGQGr5ctLZJMcjCPwmPMEfaONmyXZOy65vGEUOI1EAiac62xNFlTodlY0z0XzUbNAXAM7GPF4SWItPyIdDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=t2iuUmxu; arc=none smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="t2iuUmxu" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a77dc08db60so568207266b.1 for ; Wed, 10 Jul 2024 03:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607790; x=1721212590; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kYMGxlVQPX5oebPOJL95p63LDeiB2wZboyKuWqi62pM=; b=t2iuUmxu/JD0RJmUdNdUC6/sahYaSXdMd9idXe/zvL6WBe2JddU1mNjG1j5O0A3jTH 7R3zxhioJLND98IyPN38hf2sPQh/l1m2NS5tzeD6LBMy6sN0fBMXnBzaS+3lUgPIMNVh wpWqCQIlcTDtdJMCnT5NGOcRa4VOMmvhXD9hqfcdDL43mcIZRZQNMKaV7LtOGz+B3j1l rpgySzBrU0MpzyIKJ/i3Lg6zxS9LXwPN70qF2j05Sg187ph2/b7eMGTlVUwzlKda2qo6 cek+H56/A6WZFZg9sUlYjgig5cipxBuGBub/H1WEXtzwcp4SSk1MEy2QCs4RgMohx77b v+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607790; x=1721212590; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kYMGxlVQPX5oebPOJL95p63LDeiB2wZboyKuWqi62pM=; b=Bp7ug27DDZaPOvgpo3u/yy0ceUbrl2HNQHdaDJ/fMDas8eiklHAgzJapbMiDqalJvC 89p9AL1R8ovUmhM8wdG6lE9uhR0kqz8yUFl2MNjadd3YyFrbVjJAgh0ghX96m6oesHfm o5cIEFQeWhR1Gn4SK3Etr73M3u+clDMvCQG+PB45OBcjzLSUbQFnzRghwWaYKBJBOwyo K8J0qDo7PSU+ywXmjRXXYs0ynq0XsKU+E7+MfvjPYQyMptxudchXnU47945sGXajsrDF SPui+ec29POppeSMpCLCv/6jG1Pzi7AeNFtvTR8rUpCWHJgn13AVqGVvklH9lEGNeDiH 85uA== X-Forwarded-Encrypted: i=1; AJvYcCWCUrNe20Cm7jpaCIy3UiRLhj24PDESipCyF6Vrf3l2rQ61VpPTeu6ITW0DFVIJ/4gI+oF5eVL2foCh8r9KM5CF2wm+GjyZ7cqb X-Gm-Message-State: AOJu0YwGCiUmVUZ/Z9bUKtqFQGgPDguvmtkPUGYVrE14NURrilWSWezN NFtNoVXKWlggDji83zGM2KxUXJqIGvlarU4CU943gHBS2B2OBmp3W7FHSVtQzkI= X-Google-Smtp-Source: AGHT+IF1B0nCfAGt+fXGX3owUMA0Hi5Y5naIp5/iV6A4WHwQy1qFb0eKndiXPEm0xY4mUwcKTmld6A== X-Received: by 2002:a17:906:1610:b0:a72:aeff:dfed with SMTP id a640c23a62f3a-a780b8826b7mr381618866b.53.1720607789980; Wed, 10 Jul 2024 03:36:29 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:29 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:20 +0100 Subject: [PATCH 13/15] usb: typec: tcpm/tcpci_maxim: use GENMASK() for TCPC_VENDOR_ADC_CTRL1 register Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-13-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Convert register TCPC_VENDOR_ADC_CTRL1 to using GENMASK() and FIELD_PREP() so as to keep using a similar approach throughout the code base and make it arguably easier to read. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/maxim_contaminant.c | 7 ++++--- drivers/usb/typec/tcpm/tcpci_maxim.h | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c index cf9887de96c9..7bfec45e8f4f 100644 --- a/drivers/usb/typec/tcpm/maxim_contaminant.c +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c @@ -76,8 +76,8 @@ static int max_contaminant_read_adc_mv(struct max_tcpci_chip *chip, enum fladc_s int ret; /* Channel & scale select */ - ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL_MASK, - channel << ADC_CHANNEL_OFFSET); + ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL, + FIELD_PREP(ADCINSEL, channel)); if (ret < 0) return ret; @@ -96,7 +96,8 @@ static int max_contaminant_read_adc_mv(struct max_tcpci_chip *chip, enum fladc_s if (ret < 0) return ret; - ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL_MASK, 0); + ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL, + FIELD_PREP(ADCINSEL, 0)); if (ret < 0) return ret; diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.h b/drivers/usb/typec/tcpm/tcpci_maxim.h index 34076069444f..a41ca9e7ad08 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim.h +++ b/drivers/usb/typec/tcpm/tcpci_maxim.h @@ -37,8 +37,7 @@ #define WTRCYCLE_4_8_S 1 #define TCPC_VENDOR_ADC_CTRL1 0x91 -#define ADCINSEL_MASK GENMASK(7, 5) -#define ADC_CHANNEL_OFFSET 5 +#define ADCINSEL GENMASK(7, 5) #define ADCEN BIT(0) enum contamiant_state { From patchwork Wed Jul 10 10:36:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812302 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 F1DCB19346A for ; Wed, 10 Jul 2024 10:36:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607794; cv=none; b=bHPPNX5sLysWMvDBxZ7EGQIrx29StL1YMs5huGCFQqAoJqAdGcjNIauauNMGn7N61le/dmpKjwnYUveb8It0Ktb/yTyT+wqdwcOYBJVhynkpFC1JMZYNRBmeijqHiRpNS4PFaOQf3aJ7BEgVyR4RR3i95jQkjEFEj8w4zfnJctY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607794; c=relaxed/simple; bh=kTwbKe61QUCPrnbb1cpVQTggcXTOn/D7Df0XXPC5NLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=G2rHRqx7gmlmXe3ECqotgI6FcCwG6ozK2y4lKzNFlBs4aEw+cNMTiVqPnD0fQnUJJNVGtZ8nWxtDDBAive6DD57ZnRpgcwJOVzzOhx4scXaPHDB70p4IsuqwrGRCbiNBI+yhRrCVDrSIgpiP8v9HbhJLX15Pkv8MvDBhJUjJAeY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=aN6AsiSq; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aN6AsiSq" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a77dc08db60so568208566b.1 for ; Wed, 10 Jul 2024 03:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607790; x=1721212590; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LBsGAX5ucZSs0rabFc3mHUKWbMSbxv4GqyzeE6M9P0w=; b=aN6AsiSqKEPV/GkeK3JuGMezSZlnBUuSDp0gfUsz/zlELkF9A3i4RSOof1ePNraetk 2PUPPjW8C7vx/poo4SprZYa/tf9QkXHotlpj0H98weKFBjhX7pn5dYXNRuziZvmltxFx eyoB0eKlsUesjwY34YL5+vj5E7SO7fpR1wq4EWDR6X010EvpihQOWI0nFQX2xeFacxZy 997Q1pFhZn/TvUM1n+YxrQCT+dQoD9AV/SVFogFfHeQ2mmNuGALUqgwlvVVOY5cJnXcX TVe5JRPGRFTULq1rL7MIv9zUWpUQPa/fD9ONfksqCuAM+5mfjdbxzLBl0xseU/K+dRSt ZBlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607790; x=1721212590; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LBsGAX5ucZSs0rabFc3mHUKWbMSbxv4GqyzeE6M9P0w=; b=g3Mgj4xo+BOrwNKJB1xUyzq55+TmZsKMseWcWNC0fqySBH3p6kf6irHEq3C1uRbvPM JRVv0IHSI/UhYNy8b1Zdrm+yso9jKyKBuWotHyRgCcgX7P4avFbhgSxCYbU5znY2l9Pw WuM/djvJS1YZ0Bw53rUMisL6p/J/xf3uypp/SFqAUZBV/OQSxWYfWGrZDkfCpaJYcf1j 5UahiQrJsTCEIpONrY9wbzAbkNTCgV2rGadc2GFWnt6iwWhFbkzYPACbS+L6PrBzZBjR BFCUtitubOXW96KQJ4gxSeqwxrwtToX7PQyz3aOA7n567XOS76NnMs0PVXBWFLnr+OBi hXug== X-Forwarded-Encrypted: i=1; AJvYcCWBTYHXR9QW7RWAXnGCUVPyu++nB6rMm08/R4OJ9vVZnbn0+8QtII5qawJSAdD4w7GIjD5Yt72w5Q1BaACpw/V43an2ofcW7j5D X-Gm-Message-State: AOJu0Yz4wF9tIVxg752+SfZ+vYyY9V+YzuYZD+aieRUzNa2FNKmmRd2m BGFnvWdyK4GShquLxIErYaNSfLIMsK49S9iCPrcszHTq1MmjCJuLphS+UgxiVAM= X-Google-Smtp-Source: AGHT+IHX+sxCHXBwTJmD4epP7d3YbfxuGZjRjObQdw7BJhHSOlvO1QQLECp833J9njXjW0as97YSGg== X-Received: by 2002:a17:907:3f25:b0:a77:c13c:2170 with SMTP id a640c23a62f3a-a780b89ddb8mr357976066b.77.1720607790415; Wed, 10 Jul 2024 03:36:30 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:30 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:21 +0100 Subject: [PATCH 14/15] usb: typec: tcpm/tcpci_maxim: convert to dev_err_probe() Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-14-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 dev_err_probe() exists as a useful helper ensuring standardized error messages during .probe() and using it also helps to make the code more legible. Use it. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index 5b5441db7047..ee3e86797f17 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -484,17 +484,17 @@ static int max_tcpci_probe(struct i2c_client *client) chip->client = client; chip->data.regmap = devm_regmap_init_i2c(client, &max_tcpci_regmap_config); - if (IS_ERR(chip->data.regmap)) { - dev_err(&client->dev, "Regmap init failed\n"); - return PTR_ERR(chip->data.regmap); - } + if (IS_ERR(chip->data.regmap)) + return dev_err_probe(&client->dev, PTR_ERR(chip->data.regmap), + "Regmap init failed\n"); chip->dev = &client->dev; i2c_set_clientdata(client, chip); ret = max_tcpci_read8(chip, TCPC_POWER_STATUS, &power_status); if (ret < 0) - return ret; + return dev_err_probe(&client->dev, ret, + "Failed to read TCPC_POWER_STATUS\n"); /* Chip level tcpci callbacks */ chip->data.set_vbus = max_tcpci_set_vbus; @@ -511,10 +511,10 @@ static int max_tcpci_probe(struct i2c_client *client) max_tcpci_init_regs(chip); chip->tcpci = tcpci_register_port(chip->dev, &chip->data); - if (IS_ERR(chip->tcpci)) { - dev_err(&client->dev, "TCPCI port registration failed\n"); - return PTR_ERR(chip->tcpci); - } + if (IS_ERR(chip->tcpci)) + return dev_err_probe(&client->dev, PTR_ERR(chip->tcpci), + "TCPCI port registration failed\n"); + chip->port = tcpci_get_tcpm_port(chip->tcpci); ret = max_tcpci_init_alert(chip, client); if (ret < 0) @@ -526,7 +526,8 @@ static int max_tcpci_probe(struct i2c_client *client) unreg_port: tcpci_unregister_port(chip->tcpci); - return ret; + return dev_err_probe(&client->dev, ret, + "Maxim TCPCI driver initialization failed\n"); } static void max_tcpci_remove(struct i2c_client *client) From patchwork Wed Jul 10 10:36:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 812035 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (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 5EEB8194082 for ; Wed, 10 Jul 2024 10:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607794; cv=none; b=ObIV0bwIdbt1gw4XEB5FJs8z+9HPepiNCY5Pqb1tN2ef8Pv4Mdzw+0F/bWzIcDOzw7h0tyAr31WDAS2vauRGTV+FpBqmupLEUnQrwy7FuxIdB8CtHNieXRSPirhsO1QcS7EACCuKgmjBG0AK0HG3iU2glUnGyxvKciW0akSeWeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720607794; c=relaxed/simple; bh=v+I5fZKIK+3f31tZX+uZTfNTTOvQkNNPPT3FGfrJxo0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B89jn2xzuH1YGFzvFwlXlkvsiJ+ZzjT2Sy+qvU3IBAew0OJB/xCj7QrKkWCBzyZk+1JKRNT+VxxU8GxrXrT59lEOap67FPlYuRmv0VXyke2pITvf49BwGsDEI0qwFJi/PFPLw8CUmptSkzXW3bQLQY+zVLOzjP6rttAY0mb2cB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=GtbYkouH; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="GtbYkouH" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a77cbb5e987so589521066b.3 for ; Wed, 10 Jul 2024 03:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720607791; x=1721212591; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=2EHz6jGnv+MSlXLIFJTYz0j3V4QrlhRk5xlWpqxujXQ=; b=GtbYkouH9DhQu2BJZIWgcBQ4f0ismW72b1jmrRUmxnpCiiZy2uwhg8I9gg8LCvGRbv /+/yqIb9CykbiIhZx17d0Zxm1KNqRVu9CagxlPg6dEws/PYB9xIxQHTBYLxyAQE88thl 7+0DynZW4zNv0iHD56phWgIOWJdvFVBR+UzakpaF9Pf+9ZF1PZl874vtvKQdY2kzd4nV 8QXRZj+njSC3RSlC4KTbehFkuzQbXOK6HPeeJWkd8c75IClf2/E7Xuod2WFsDmyRGEcX 8hXGknAPyciJYOcA8y8fpaPWElHzOgWG7TOBCfMDAfxI1Zii3Zeco8untVBxASf88mzs /exQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720607791; x=1721212591; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2EHz6jGnv+MSlXLIFJTYz0j3V4QrlhRk5xlWpqxujXQ=; b=gMS05NWq/mKYCwvRu6c3zHxiIqXe8cWyTqHGcsOMjeLtyCiqEk0UtunnY4Pk62gDvs 9YgxF9Yh6Tjy/kQaEdd1a3jmOsq+HAn0GVbprEdFwpvzazIda+SciWcG9gs6A/DQt64j FNcIe1N/F6plgr4Sr6iTAe0zCmJkh2sRsI8LQQiN97ntAF9lGC1cgjI6C0zBJDAxusom 01yopvMdFlauzKrMJ51zWIbUuBNagzFGtQIY6kWbR5wjUOnvYCTBuiJ0u+VUxWDhkAXM bohlL6EaVWHaqbynG9n4oic9OHnCBm7ktTpyP1/GGS226YGLAbhK51FoAS9YAtR47cPi 49dA== X-Forwarded-Encrypted: i=1; AJvYcCWT9jN5VTZDfr6si0oVgz77yiGOzh6zNcsIvFjNhGJhKWOIra/vPZgHlGgw7ZeHPDjsFnBLi25IUV2oWxX8P7C24LfoBEPQN2Ji X-Gm-Message-State: AOJu0YwRTPjBA9wF4onob7oi98TbdwnscmFipHlnnsQwQk/arIP7mvN3 Coyd+VWK+k5PY7wmuzQIXoXbBjZL0fvIUq9yNs2ZWCGndRyhQ0fsr5sAK2SW6hs= X-Google-Smtp-Source: AGHT+IHONz7ukaXxFyPTjynNVCKibzciLGDtNH5tc/vYHzKXbY/8i2tsQWiv7EwjCwlhWObWe5BgqA== X-Received: by 2002:a17:907:2d2b:b0:a75:2d52:8ca8 with SMTP id a640c23a62f3a-a780b89f457mr441045866b.75.1720607790824; Wed, 10 Jul 2024 03:36:30 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc77dsm146576966b.52.2024.07.10.03.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 03:36:30 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Wed, 10 Jul 2024 11:36:22 +0100 Subject: [PATCH 15/15] usb: typec: tcpm/tcpci_maxim: use device managed TCPCI port deregistration Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240710-tcpc-cleanup-v1-15-0ec1f41f4263@linaro.org> References: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> In-Reply-To: <20240710-tcpc-cleanup-v1-0-0ec1f41f4263@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Peter Griffin , Tudor Ambarus , Will McVicker , Badhri Jagan Sridharan , kernel-team@android.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Draszik?= X-Mailer: b4 0.13.0 Instead of open-coding the call to tcpci_unregister_port() in various places, let's just register a hook using devm_add_action_or_reset() so that it gets called automatically as and when necessary by the device management APIs. Signed-off-by: André Draszik --- drivers/usb/typec/tcpm/tcpci_maxim_core.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c index ee3e86797f17..7abfd29b4b01 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c @@ -472,6 +472,11 @@ static bool max_tcpci_attempt_vconn_swap_discovery(struct tcpci *tcpci, struct t return true; } +static void max_tcpci_unregister_tcpci_port(void *tcpci) +{ + tcpci_unregister_port(tcpci); +} + static int max_tcpci_probe(struct i2c_client *client) { int ret; @@ -515,27 +520,21 @@ static int max_tcpci_probe(struct i2c_client *client) return dev_err_probe(&client->dev, PTR_ERR(chip->tcpci), "TCPCI port registration failed\n"); + ret = devm_add_action_or_reset(&client->dev, + max_tcpci_unregister_tcpci_port, + chip->tcpci); + if (ret) + return ret; + chip->port = tcpci_get_tcpm_port(chip->tcpci); + ret = max_tcpci_init_alert(chip, client); if (ret < 0) - goto unreg_port; + return dev_err_probe(&client->dev, ret, + "IRQ initialization failed\n"); device_init_wakeup(chip->dev, true); return 0; - -unreg_port: - tcpci_unregister_port(chip->tcpci); - - return dev_err_probe(&client->dev, ret, - "Maxim TCPCI driver initialization failed\n"); -} - -static void max_tcpci_remove(struct i2c_client *client) -{ - struct max_tcpci_chip *chip = i2c_get_clientdata(client); - - if (!IS_ERR_OR_NULL(chip->tcpci)) - tcpci_unregister_port(chip->tcpci); } static const struct i2c_device_id max_tcpci_id[] = { @@ -558,7 +557,6 @@ static struct i2c_driver max_tcpci_i2c_driver = { .of_match_table = of_match_ptr(max_tcpci_of_match), }, .probe = max_tcpci_probe, - .remove = max_tcpci_remove, .id_table = max_tcpci_id, }; module_i2c_driver(max_tcpci_i2c_driver);