From nobody Tue Sep 29 07:48:13 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DC251F8AC5; Tue, 11 Aug 2026 03:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786419138; cv=none; b=LDjGRJTO+xknDy62OAKUbHH/GXbDk34RAjalO9Z609kNo5bOzNSBg/9ZDg7xHmpgJxCEl72GfqPxgDMV+HalvGVeSfl31tKD9etFEHVgHg9q3ojRMzK4wvZlt8dGwrn1dIfQjpu2w9NP16EiBPgGh1jLEeKdlr/SpsncqLtCaVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786419138; c=relaxed/simple; bh=wWPDqbtE9IjjVOj38eLfwO5U/9DHuOFyX+RgCqVoio0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WdQDdBZCmNYLb2yv3hZhceExOh4bZHMpBFw99Y9AhjTWC6NeglprBljwq3Kx+QI31g0fXAY1+KJptoy+xJ9Z0RpSmCdXEjmNeySMdoVel13wtz0c7YotGHQy/6D0ZrAbon9GZIbI60IfhYZ9o2Yd6UGAlrMCVFrmXq3RpnA3Co8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MAeG1LB0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MAeG1LB0" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7208EC2BCF7; Tue, 11 Aug 2026 03:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1786419138; bh=wWPDqbtE9IjjVOj38eLfwO5U/9DHuOFyX+RgCqVoio0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=MAeG1LB0qJ/M1qIUQh8unWjfJ4qsvvQ+hwXud3mG/3HhD6TmdxH0VGT4ndS70b+b5 gN4D7cL9CzOJLhIEzjIQpWE3q73xgUOeFBolm0dyPitCqrMxUXZHkp7W6sw+5tZFwQ P6PHIAQjKpIHhJF60ZvzopmckOQXgw5p0KaPciyjIgu7ysBldCpOgkyiMeYPWX0hCo 1c7d4XGyZw3ORuW3zdnNjdSxpw8H6QKZpC2YjcDOOil+Ay0vedMrR9yrnm94gQJYqD mfCRJGEDNpm9iq1afDgYwtIH83xsBVHOfP+/Q7S/W1lqmg175py83Q1GRf4UWf5EMn bhwNEGArrgOAw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FB11C5AD7B; Tue, 11 Aug 2026 03:32:18 +0000 (UTC) From: Esteban Urrutia via B4 Relay Date: Mon, 10 Aug 2026 23:31:36 -0400 Subject: [PATCH v3 1/2] dt-bindings: usb: Add Parade PS5169 redriver bindings Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260810-ps5169-bup-v3-1-a2178b2834d7@proton.me> References: <20260810-ps5169-bup-v3-0-a2178b2834d7@proton.me> In-Reply-To: <20260810-ps5169-bup-v3-0-a2178b2834d7@proton.me> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heikki Krogerus Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, Esteban Urrutia X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786419136; l=5639; i=esteuwu@proton.me; s=20260622; h=from:subject:message-id; bh=B7m2pd9kvS3C97uNpoakZ1NLas4KObjMwrJoNHsnny0=; b=FKics0VG7D5waIfkoZq7BAaT5p2wgj9xNLNUoAhKjG0iODlve8k8kxrLfQM8qQvsl+4eZDYzr DLFs4rZYygYAy0fBwCcWU+drPLn866kNNX6Ac9bNS6BRFURijPeS+3H X-Developer-Key: i=esteuwu@proton.me; a=ed25519; pk=wToFt4mOAWkzbqb15Ye1hrhevI13vK9BcMUFiQ/me1M= X-Endpoint-Received: by B4 Relay for esteuwu@proton.me/20260622 with auth_id=835 X-Original-From: Esteban Urrutia Reply-To: esteuwu@proton.me From: Esteban Urrutia Add bindings for the Parade PS5169 and PS5170 USB Type-C linear redrivers. Unline PS5170, PS5169 doesn't have an integrated AUX switch and only performs AUX channel monitoring. Future-proof the binding by adding PS5170 as well. Signed-off-by: Esteban Urrutia --- .../devicetree/bindings/usb/parade,ps5169.yaml | 193 +++++++++++++++++= ++++ 1 file changed, 193 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/parade,ps5169.yaml b/Doc= umentation/devicetree/bindings/usb/parade,ps5169.yaml new file mode 100644 index 000000000000..fe202e481c8c --- /dev/null +++ b/Documentation/devicetree/bindings/usb/parade,ps5169.yaml @@ -0,0 +1,193 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/parade,ps5169.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Parade PS5169 USB Type-C linear redriver + +maintainers: + - Esteban Urrutia + +properties: + compatible: + oneOf: + - items: + - const: parade,ps5170 + - const: parade,ps5169 + - const: parade,ps5169 + + reg: + maxItems: 1 + + vcc-supply: + description: 1.8V power supply + + reset-gpios: + maxItems: 1 + + orientation-switch: true + retimer-switch: true + + parade,dp-eq-db: + description: + Equalization for DP channels. + For example, <6 5> denotes an equalization of 6.5 dB. + oneOf: + - items: + - enum: [ 2, 8, 10 ] + - const: 0 + - items: + - enum: [ 5, 6, 7, 8, 9 ] + - const: 5 + + parade,usb-rx-eq-db: + description: + Equalization for USB receive channels. + For example, <5 2> denotes an equalization of 5.2 dB. + oneOf: + - items: + - enum: [ 5, 11 ] + - const: 2 + - items: + - enum: [ 6, 7, 8 ] + - const: 0 + - items: + - const: 8 + - const: 8 + - items: + - const: 9 + - const: 6 + - items: + - const: 10 + - const: 4 + + parade,usb-tx-eq-db: + description: + Equalization for USB transmit channels. + For example, <6 5> denotes an equalization of 6.5 dB. + oneOf: + - items: + - enum: [ 2, 8, 10 ] + - const: 0 + - items: + - enum: [ 5, 6, 7, 8, 9 ] + - const: 5 + + parade,fine-tune-lfps-swing: + type: boolean + description: + Set a 50 ohm termination for USB receive channels. + Usage of this property is design-specific. + + parade,dp-set-gain: + type: boolean + description: + Set a -0.9 dB gain for DP channels. + + parade,usb-rx-set-gain: + type: boolean + description: + Set a -0.9 dB gain for USB receive channels. + + parade,usb-tx-set-gain: + type: boolean + description: + Set a -0.9 dB gain for USB transmit channels. + + ports: + $ref: /schemas/graph.yaml#/properties/ports + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: Super Speed (SS) Output endpoint to the Type-C connec= tor + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Super Speed (SS) Input endpoint from the Super-Speed = PHY + unevaluatedProperties: false + + port@2: + $ref: /schemas/graph.yaml#/properties/port + description: + Sideband Use (SBU) AUX lines endpoint to the Type-C connector fo= r the purpose of + handling altmode muxing and orientation switching. + +required: + - compatible + - reg + - vcc-supply + - reset-gpios + - orientation-switch + - retimer-switch + +allOf: + - $ref: usb-switch.yaml# + - $ref: usb-switch-ports.yaml# + - if: + properties: + compatible: + contains: + const: parade,ps5170 + then: + properties: + ports: + required: + - port@2 + + else: + properties: + ports: + properties: + # PS5169 only performs AUX channel monitoring and doesn't have= an integrated AUX switch + port@2: false + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + typec-retimer@30 { + compatible =3D "parade,ps5169"; + reg =3D <0x30>; + + vcc-supply =3D <&vreg_s10b_1p8>; + reset-gpios =3D <&tlmm 54 GPIO_ACTIVE_LOW>; + + orientation-switch; + retimer-switch; + + parade,dp-eq-db =3D <2 0>; /* 2 dB */ + parade,usb-rx-eq-db =3D <5 2>; /* 5.2 dB */ + parade,usb-tx-eq-db =3D <2 0>; /* 2 dB */ + + parade,fine-tune-lfps-swing; + + ports { + #address-cells =3D <1>; + #size-cells =3D <0>; + + port@0 { + reg =3D <0>; + usb_con_ss: endpoint { + remote-endpoint =3D <&typec_con_ss>; + }; + }; + + port@1 { + reg =3D <1>; + phy_con_ss: endpoint { + remote-endpoint =3D <&usb_phy_ss>; + }; + }; + + /* PS5169 doesn't have an integrated AUX switch, so no por= t@2 */ + }; + }; + }; +... --=20 2.55.0 From nobody Tue Sep 29 07:48:13 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE232387362; Tue, 11 Aug 2026 03:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786419138; cv=none; b=qC/UMpleOAu1HivEcvzN8Zs/q+Tl3eBsaGDifWGLuD3kOwDr+/DAPzXlH4miFEYyc7hRD/aXULjl/atNcFQQ7fgeVuZ9qBkypksQHCAmP0oCpspt7TNzwujd0hnZzWgcXqBR4c8nNDT9xE/zWtLKvz5gcsvEdA7JVWH66SdEQzo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786419138; c=relaxed/simple; bh=qM0h2/hPk2yjF7VgFPLLO7cS8CzUpHz9mHyxQEpiZj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZAns272KrFXxsHg6+cnNEEu5cqiltFU7HbY29JwPZ/H9nSa8p6wKOg345KrlGj+pPAp4Qa+g6j1FpcnUw8afNX3wheKjvv9/v/3SQin20YPhj8/1ZXPKCRu2F/MvNhm48PhZtW+1fyPE5bwjfQzk0RwDve2lEHi/zQkfWcc9Bio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=imvEYnO/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="imvEYnO/" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7E99DC2BCFA; Tue, 11 Aug 2026 03:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1786419138; bh=qM0h2/hPk2yjF7VgFPLLO7cS8CzUpHz9mHyxQEpiZj8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=imvEYnO/v6MmS4U8gbWuUbHQn+q+9xiLWFSxkfKo1AsqmNyihp75I2GtBNP8z1JfN uk5L5mWmxsiadtjdvaaaN9SsOViEw8RNmyHFtNAH+YIp1aBorR3lbBk1N7ikzT3Lmi /pYbyYR9iceWfHbaw4P+RrRkoguDZeY3ZlfPwxT1lUnol1pKUY2bB9iN5VLzNbMFq7 DPmnmXzBcSVrKwQhmhzGM9tUp1Rqg3Gd1pQ63ukEmcRvOuUXKWw3LjGLpppC5zprQ1 NprcNIYs9pEPMwizQ8wy/5HKGyyZ1X3NENWPDLk418MyTuGYQGBQOIHbnA0/c1VTi8 s/wp5vCUUgMLA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DDC5C5B56A; Tue, 11 Aug 2026 03:32:18 +0000 (UTC) From: Esteban Urrutia via B4 Relay Date: Mon, 10 Aug 2026 23:31:37 -0400 Subject: [PATCH v3 2/2] usb: typec: Add support for Parade PS5169 USB Type-C redriver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260810-ps5169-bup-v3-2-a2178b2834d7@proton.me> References: <20260810-ps5169-bup-v3-0-a2178b2834d7@proton.me> In-Reply-To: <20260810-ps5169-bup-v3-0-a2178b2834d7@proton.me> To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heikki Krogerus Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, Esteban Urrutia X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786419136; l=19402; i=esteuwu@proton.me; s=20260622; h=from:subject:message-id; bh=fqyfs4yhNtpKPrC0p6KgL7zzm2LBsFexqBXocLgUHI8=; b=qUEUUqOfpYnFjWeeFdvFtD+F7Fg0ryvFGpxOZEmQxe+rtZGiftpVtEDm9iLmsP1QtD/G3xRF0 KIrgXaUj6YvBX7/8QvUQTM8ymyxsYkwPF5J6nMGPOCaxE9pzw4JwbhV X-Developer-Key: i=esteuwu@proton.me; a=ed25519; pk=wToFt4mOAWkzbqb15Ye1hrhevI13vK9BcMUFiQ/me1M= X-Endpoint-Received: by B4 Relay for esteuwu@proton.me/20260622 with auth_id=835 X-Original-From: Esteban Urrutia Reply-To: esteuwu@proton.me From: Esteban Urrutia Add driver for the Parade PS5169, an USB Type-C redriver capable of handling 10Gb/s USB signals and 8.1Gb/s DP signals. Signed-off-by: Esteban Urrutia --- MAINTAINERS | 7 + drivers/usb/typec/mux/Kconfig | 10 + drivers/usb/typec/mux/Makefile | 1 + drivers/usb/typec/mux/ps5169.c | 592 +++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 610 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index da14a58df9e8..1b751a8ce0a8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -28369,6 +28369,13 @@ F: drivers/usb/typec/tcpm/tcpm.c F: include/linux/usb/tcpci.h F: include/linux/usb/tcpm.h =20 +USB TYPEC PS5169 MUX DRIVER +M: Esteban Urrutia +L: linux-usb@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/usb/parade,ps5169.yaml +F: drivers/usb/typec/mux/ps5169.c + USB TYPEC TUSB1046 MUX DRIVER M: Romain Gantois L: linux-usb@vger.kernel.org diff --git a/drivers/usb/typec/mux/Kconfig b/drivers/usb/typec/mux/Kconfig index 6dd8f961b593..2838a53ce564 100644 --- a/drivers/usb/typec/mux/Kconfig +++ b/drivers/usb/typec/mux/Kconfig @@ -56,6 +56,16 @@ config TYPEC_MUX_NB7VPQ904M Say Y or M if your system has a On Semiconductor NB7VPQ904M Type-C redriver chip found on some devices with a Type-C port. =20 +config TYPEC_MUX_PS5169 + tristate "Parade PS5169 Type-C redriver driver" + depends on I2C + depends on DRM || DRM=3Dn + select DRM_AUX_BRIDGE if DRM_BRIDGE && OF + select REGMAP_I2C + help + Say Y or M if your system has a Parade PS5169 Type-C redriver chip + found on some devices with a Type-C port. + config TYPEC_MUX_PS883X tristate "Parade PS883x Type-C retimer driver" depends on I2C diff --git a/drivers/usb/typec/mux/Makefile b/drivers/usb/typec/mux/Makefile index b4f599eb5053..c775bfa12068 100644 --- a/drivers/usb/typec/mux/Makefile +++ b/drivers/usb/typec/mux/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_TYPEC_MUX_PI3USB30532) +=3D pi3usb30532.o obj-$(CONFIG_TYPEC_MUX_INTEL_PMC) +=3D intel_pmc_mux.o obj-$(CONFIG_TYPEC_MUX_IT5205) +=3D it5205.o obj-$(CONFIG_TYPEC_MUX_NB7VPQ904M) +=3D nb7vpq904m.o +obj-$(CONFIG_TYPEC_MUX_PS5169) +=3D ps5169.o obj-$(CONFIG_TYPEC_MUX_PS883X) +=3D ps883x.o obj-$(CONFIG_TYPEC_MUX_PTN36502) +=3D ptn36502.o obj-$(CONFIG_TYPEC_MUX_TUSB1046) +=3D tusb1046.o diff --git a/drivers/usb/typec/mux/ps5169.c b/drivers/usb/typec/mux/ps5169.c new file mode 100644 index 000000000000..5fbc452249d0 --- /dev/null +++ b/drivers/usb/typec/mux/ps5169.c @@ -0,0 +1,592 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for Parade PS5169 USB Type-C linear redriver + * Registers and bits decoded from downstream drivers + * + * Copyright (c) 2026 Esteban Urrutia + */ + +#include + +#include +#include + +#include +#include +#include +#include + +/* Useful constants */ +#define PS5169_DP_EQ_REG_COUNT 2 +#define PS5169_USB_RX_EQ_REG_COUNT 4 +#define PS5169_USB_TX_EQ_REG_COUNT 3 + +#define PS5169_DP_EQ_LEVEL_COUNT 8 +#define PS5169_USB_RX_EQ_LEVEL_COUNT 8 +#define PS5169_USB_TX_EQ_LEVEL_COUNT 8 + +/* PS5169 registers */ +#define PS5169_CONFIG_REG 0x40 +#define PS5169_GAIN_REG 0x5c +#define PS5169_USB_RX1_LFPS_REG 0x8d +#define PS5169_USB_RX2_LFPS_REG 0x90 +#define PS5169_AUX_RX_DATA_REG 0x9f +#define PS5169_AUX_MONITORING_REG 0xa0 +#define PS5169_HPD_LEVEL_REG 0xa1 +#define PS5169_CHIP_ID_REG 0xac +#define PS5169_CHIP_REVISION_REG 0xae +/* Chip revision is split in two registers */ +#define PS5169_MAX_REG (PS5169_CHIP_REVISION_REG + 1) + +/* PS5169 register bits */ +#define PS5169_CONFIG_REVERSE_BIT BIT(4) +#define PS5169_CONFIG_DP_EN_BIT BIT(5) +#define PS5169_CONFIG_USB3_EN_BIT BIT(6) +#define PS5169_CONFIG_BASE_BIT BIT(7) + +#define PS5169_GAIN_DP_BIT BIT(4) +#define PS5169_GAIN_USB_RX_BIT BIT(2) +#define PS5169_GAIN_USB_TX_BIT BIT(0) + +#define PS5169_USB_RX_LFPS_50_OHM_BIT BIT(0) + +#define PS5169_AUX_RX_DATA_REVERSE_BIT BIT(1) + +#define PS5169_AUX_MONITORING_BIT BIT(1) +#define PS5169_HPD_LEVEL_BIT BIT(2) + +/* PS5169 register values */ +#define PS5169_CHIP_ID_VAL 0x6987 + +struct ps5169_eq_db { + const int major; + const int minor; +}; + +struct ps5169_eq_data { + const char *propname; + const struct ps5169_eq_db *db; + const int nlevels; +}; + +/* PS5169 EQ registers */ +static const int ps5169_dp_eq_reg[PS5169_DP_EQ_REG_COUNT] =3D {0x52, 0x5e= }; +static const int ps5169_usb_rx_eq_reg[PS5169_USB_RX_EQ_REG_COUNT] =3D {0x5= 1, 0x77, 0x54, 0x78}; +static const int ps5169_usb_tx_eq_reg[PS5169_USB_TX_EQ_REG_COUNT] =3D {0x5= 0, 0x5d, 0x54}; + +/* PS5169 EQ register masks */ +static const int ps5169_dp_eq_mask[PS5169_DP_EQ_REG_COUNT] =3D {0x70, 0x0= 7}; +static const int ps5169_usb_rx_eq_mask[PS5169_USB_RX_EQ_REG_COUNT] =3D {0x= f6, 0xf0, 0x0f, 0xe1}; +static const int ps5169_usb_tx_eq_mask[PS5169_USB_TX_EQ_REG_COUNT] =3D {0x= 70, 0x70, 0xf0}; + +/* PS5169 EQ register values */ +static const int ps5169_dp_eq_val[PS5169_DP_EQ_LEVEL_COUNT][PS5169_DP_EQ_R= EG_COUNT] =3D { + {0x00, 0x04}, + {0x10, 0x05}, + {0x20, 0x06}, + {0x30, 0x06}, + {0x40, 0x06}, + {0x50, 0x07}, + {0x60, 0x07}, + {0x70, 0x07}, +}; + +static const int ps5169_usb_rx_eq_val[PS5169_USB_RX_EQ_LEVEL_COUNT][PS5169= _USB_RX_EQ_REG_COUNT] =3D { + {0x86, 0x00, 0x00, 0x20}, + {0x96, 0x00, 0x01, 0x20}, + {0xa6, 0x50, 0x01, 0x40}, + {0xb6, 0x50, 0x05, 0x40}, + {0xc6, 0xb0, 0x0c, 0x80}, + {0xd6, 0xf0, 0x05, 0x80}, + {0xe6, 0xf0, 0x0f, 0x80}, + {0xf6, 0x30, 0x0f, 0xa1}, +}; + +static const int ps5169_usb_tx_eq_val[PS5169_USB_TX_EQ_LEVEL_COUNT][PS5169= _USB_TX_EQ_REG_COUNT] =3D { + {0x00, 0x40, 0x00}, + {0x10, 0x50, 0x10}, + {0x20, 0x60, 0x10}, + {0x30, 0x60, 0x50}, + {0x40, 0x60, 0xc0}, + {0x50, 0x70, 0x50}, + {0x60, 0x70, 0xf0}, + {0x70, 0x70, 0xf0}, +}; + +/* PS5169 EQ decibels */ +static const struct ps5169_eq_db ps5169_dp_eq_db[PS5169_DP_EQ_LEVEL_COUNT]= =3D { + {2, 0}, + {5, 5}, + {6, 5}, + {7, 5}, + {8, 0}, + {8, 5}, + {9, 5}, + {10, 0}, /* Supposedly */ +}; + +static const struct ps5169_eq_db ps5169_usb_rx_eq_db[PS5169_USB_RX_EQ_LEVE= L_COUNT] =3D { + {5, 2}, + {6, 0}, + {7, 0}, + {8, 0}, + {8, 8}, + {9, 6}, + {10, 4}, + {11, 2}, +}; + +static const struct ps5169_eq_db ps5169_usb_tx_eq_db[PS5169_USB_TX_EQ_LEVE= L_COUNT] =3D { + {2, 0}, + {5, 5}, + {6, 5}, + {7, 5}, + {8, 0}, + {8, 5}, + {9, 5}, + {10, 0}, /* Supposedly */ +}; + +/* PS5169 EQ data */ +static const struct ps5169_eq_data ps5169_dp_eq_data =3D { + .propname =3D "parade,dp-eq-db", + .db =3D ps5169_dp_eq_db, + .nlevels =3D PS5169_DP_EQ_LEVEL_COUNT, +}; + +static const struct ps5169_eq_data ps5169_usb_rx_eq_data =3D { + .propname =3D "parade,usb-rx-eq-db", + .db =3D ps5169_usb_rx_eq_db, + .nlevels =3D PS5169_USB_RX_EQ_LEVEL_COUNT, +}; + +static const struct ps5169_eq_data ps5169_usb_tx_eq_data =3D { + .propname =3D "parade,usb-tx-eq-db", + .db =3D ps5169_usb_tx_eq_db, + .nlevels =3D PS5169_USB_TX_EQ_LEVEL_COUNT, +}; + +struct redriver { + struct regulator *vcc; + struct gpio_desc *reset_gpio; + + struct regmap *regmap; + + struct typec_switch *typec_switch; + struct typec_mux *typec_mux; + + struct typec_switch_dev *sw; + struct typec_retimer *retimer; + + unsigned long mode; + enum typec_orientation orientation; + + unsigned int dp_eq_level; + unsigned int usb_rx_eq_level; + unsigned int usb_tx_eq_level; + + bool tune_lfps; + + bool dp_set_gain; + bool usb_rx_set_gain; + bool usb_tx_set_gain; + + struct mutex lock; /* protect non-concurrent retimer & switch */ + + unsigned int svid; +}; + +static const struct regmap_config ps5169_regmap =3D { + .max_register =3D PS5169_MAX_REG, + .reg_bits =3D 8, + .val_bits =3D 8, + /* Accesses only done under ps5169->lock */ + .disable_locking =3D true, +}; + +static void ps5169_write(struct redriver *ps5169, unsigned int reg, unsign= ed int val) +{ + regmap_write(ps5169->regmap, reg, val); + + if (val & PS5169_CONFIG_DP_EN_BIT) { + /* Clearing this bit will enable the AUX channel */ + regmap_clear_bits(ps5169->regmap, PS5169_AUX_MONITORING_REG, + PS5169_AUX_MONITORING_BIT); + /* Setting this bit will set a high HPD level */ + regmap_set_bits(ps5169->regmap, PS5169_HPD_LEVEL_REG, PS5169_HPD_LEVEL_B= IT); + } else { + /* Setting this bit will disable the AUX channel */ + regmap_set_bits(ps5169->regmap, PS5169_AUX_MONITORING_REG, + PS5169_AUX_MONITORING_BIT); + /* Clearing this bit will set a low HPD level */ + regmap_clear_bits(ps5169->regmap, PS5169_HPD_LEVEL_REG, PS5169_HPD_LEVEL= _BIT); + } + + if (ps5169->tune_lfps) { + if (val & PS5169_CONFIG_USB3_EN_BIT) { + /* Setting these bits will enable a 50 ohm termination on USB RX */ + regmap_set_bits(ps5169->regmap, PS5169_USB_RX1_LFPS_REG, + PS5169_USB_RX_LFPS_50_OHM_BIT); + regmap_set_bits(ps5169->regmap, PS5169_USB_RX2_LFPS_REG, + PS5169_USB_RX_LFPS_50_OHM_BIT); + } else { + /* Clearing these bits will disable a 50 ohm termination on USB RX */ + regmap_clear_bits(ps5169->regmap, PS5169_USB_RX1_LFPS_REG, + PS5169_USB_RX_LFPS_50_OHM_BIT); + regmap_clear_bits(ps5169->regmap, PS5169_USB_RX2_LFPS_REG, + PS5169_USB_RX_LFPS_50_OHM_BIT); + } + } +} + +static int ps5169_set(struct redriver *ps5169) +{ + bool reverse =3D (ps5169->orientation =3D=3D TYPEC_ORIENTATION_REVERSE); + unsigned int val =3D PS5169_CONFIG_BASE_BIT; + + switch (ps5169->mode) { + case TYPEC_STATE_SAFE: + ps5169_write(ps5169, PS5169_CONFIG_REG, val); + + return 0; + + case TYPEC_STATE_USB: + val |=3D PS5169_CONFIG_USB3_EN_BIT; + if (reverse) + val |=3D PS5169_CONFIG_REVERSE_BIT; + ps5169_write(ps5169, PS5169_CONFIG_REG, val); + + return 0; + + default: + if (ps5169->svid !=3D USB_TYPEC_DP_SID) + return -EINVAL; + + break; + } + + switch (ps5169->mode) { + case TYPEC_DP_STATE_C: + case TYPEC_DP_STATE_E: + val |=3D PS5169_CONFIG_DP_EN_BIT; + if (reverse) + val |=3D PS5169_CONFIG_REVERSE_BIT; + ps5169_write(ps5169, PS5169_CONFIG_REG, val); + + break; + + case TYPEC_DP_STATE_D: + val |=3D PS5169_CONFIG_DP_EN_BIT | PS5169_CONFIG_USB3_EN_BIT; + if (reverse) + val |=3D PS5169_CONFIG_REVERSE_BIT; + ps5169_write(ps5169, PS5169_CONFIG_REG, val); + + break; + + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static int ps5169_switch_set(struct typec_switch_dev *sw, enum typec_orien= tation orientation) +{ + struct redriver *ps5169 =3D typec_switch_get_drvdata(sw); + int ret; + + ret =3D typec_switch_set(ps5169->typec_switch, orientation); + if (ret) + return ret; + + mutex_lock(&ps5169->lock); + + if (ps5169->orientation !=3D orientation) { + ps5169->orientation =3D orientation; + + ret =3D ps5169_set(ps5169); + } + + mutex_unlock(&ps5169->lock); + + return ret; +} + +static int ps5169_retimer_set(struct typec_retimer *retimer, struct typec_= retimer_state *state) +{ + struct redriver *ps5169 =3D typec_retimer_get_drvdata(retimer); + struct typec_mux_state mux_state; + int ret =3D 0; + + mutex_lock(&ps5169->lock); + + if (ps5169->mode !=3D state->mode) { + ps5169->mode =3D state->mode; + + if (state->alt) + ps5169->svid =3D state->alt->svid; + else + ps5169->svid =3D 0; // No SVID + + ret =3D ps5169_set(ps5169); + } + + mutex_unlock(&ps5169->lock); + + if (ret) + return ret; + + mux_state.alt =3D state->alt; + mux_state.data =3D state->data; + mux_state.mode =3D state->mode; + + return typec_mux_set(ps5169->typec_mux, &mux_state); +} + +static int ps5169_eq_from_dt(const struct device *dev, const struct ps5169= _eq_data *data, + unsigned int *val) +{ + int ret; + u32 db[2]; + unsigned int i; + + if (device_property_present(dev, data->propname)) { + /* Read property */ + ret =3D device_property_read_u32_array(dev, data->propname, db, ARRAY_SI= ZE(db)); + if (ret) { + dev_err(dev, "Failed to read %s\n", data->propname); + return ret; + } + + /* Map to level */ + for (i =3D 0; i < data->nlevels; i++) { + if (db[0] =3D=3D data->db[i].major && db[1] =3D=3D data->db[i].minor) { + *val =3D i; + return 0; + } + } + + /* Invalid dB in property */ + dev_err(dev, "%s out of range\n", data->propname); + return -EINVAL; + } + + /* A redriver is present for a reason, so raise a warning if property is = not present */ + dev_warn(dev, "Missing %s property\n", data->propname); + *val =3D U32_MAX; + return 0; +} + +static void ps5169_init(struct redriver *ps5169) +{ + int i; + + /* DP equalization */ + if (ps5169->dp_eq_level !=3D U32_MAX) + for (i =3D 0; i < PS5169_DP_EQ_REG_COUNT; i++) + regmap_update_bits(ps5169->regmap, ps5169_dp_eq_reg[i], + ps5169_dp_eq_mask[i], + ps5169_dp_eq_val[ps5169->dp_eq_level][i]); + + /* USB RX equalization */ + if (ps5169->usb_rx_eq_level !=3D U32_MAX) + for (i =3D 0; i < PS5169_USB_RX_EQ_REG_COUNT; i++) + regmap_update_bits(ps5169->regmap, ps5169_usb_rx_eq_reg[i], + ps5169_usb_rx_eq_mask[i], + ps5169_usb_rx_eq_val[ps5169->usb_rx_eq_level][i]); + + /* USB TX equalization */ + if (ps5169->usb_tx_eq_level !=3D U32_MAX) + for (i =3D 0; i < PS5169_USB_TX_EQ_REG_COUNT; i++) + regmap_update_bits(ps5169->regmap, ps5169_usb_tx_eq_reg[i], + ps5169_usb_tx_eq_mask[i], + ps5169_usb_tx_eq_val[ps5169->usb_tx_eq_level][i]); + + /* If these bits are assigned a -0.9 dB gain will be set on the correspon= ding channels */ + regmap_assign_bits(ps5169->regmap, PS5169_GAIN_REG, PS5169_GAIN_DP_BIT, + ps5169->dp_set_gain); + regmap_assign_bits(ps5169->regmap, PS5169_GAIN_REG, PS5169_GAIN_USB_RX_BI= T, + ps5169->usb_rx_set_gain); + regmap_assign_bits(ps5169->regmap, PS5169_GAIN_REG, PS5169_GAIN_USB_TX_BI= T, + ps5169->usb_tx_set_gain); +} + +static int ps5169_probe(struct i2c_client *client) +{ + struct redriver *ps5169; + struct device *dev =3D &client->dev; + int ret; + __le16 chip_id, chip_revision; + struct typec_switch_desc switch_desc =3D { }; + struct typec_retimer_desc retimer_desc =3D { }; + + ps5169 =3D devm_kzalloc(dev, sizeof(*ps5169), GFP_KERNEL); + if (!ps5169) + return -ENOMEM; + + mutex_init(&ps5169->lock); + + ps5169->vcc =3D devm_regulator_get(dev, "vcc"); + if (IS_ERR(ps5169->vcc)) + return dev_err_probe(dev, PTR_ERR(ps5169->vcc), "Failed to get vcc-suppl= y\n"); + + ps5169->reset_gpio =3D devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(ps5169->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(ps5169->reset_gpio), + "Failed to get reset-gpios\n"); + + ps5169->regmap =3D devm_regmap_init_i2c(client, &ps5169_regmap); + if (IS_ERR(ps5169->regmap)) + return dev_err_probe(dev, PTR_ERR(ps5169->regmap), "Failed to initialize= regmap\n"); + + ps5169->typec_switch =3D typec_switch_get(dev); + if (IS_ERR(ps5169->typec_switch)) + return dev_err_probe(dev, PTR_ERR(ps5169->typec_switch), + "Failed to get orientation-switch\n"); + + ps5169->typec_mux =3D typec_mux_get(dev); + if (IS_ERR(ps5169->typec_mux)) { + ret =3D dev_err_probe(dev, PTR_ERR(ps5169->typec_mux), "Failed to get mo= de-switch\n"); + goto switch_put; + } + + ret =3D regulator_enable(ps5169->vcc); + if (ret) { + dev_err(dev, "Failed to enable vcc-supply\n"); + goto mux_put; + } + + /* Reset the retimer */ + gpiod_set_value(ps5169->reset_gpio, 1); + usleep_range(1000, 1500); + gpiod_set_value(ps5169->reset_gpio, 0); + usleep_range(10000, 11000); + + ret =3D regmap_raw_read(ps5169->regmap, PS5169_CHIP_ID_REG, &chip_id, siz= eof(chip_id)); + if (ret) { + dev_err(dev, "Failed to read chip ID\n"); + goto vcc_disable; + } + + /* Compare chip IDs */ + if (chip_id !=3D PS5169_CHIP_ID_VAL) { + dev_err(dev, "Unexpected chip ID 0x%04x\n", chip_id); + ret =3D -EINVAL; + goto vcc_disable; + } + + /* Read chip revision */ + ret =3D regmap_raw_read(ps5169->regmap, PS5169_CHIP_REVISION_REG, &chip_r= evision, + sizeof(chip_revision)); + if (ret) { + dev_err(dev, "Failed to read chip revision\n"); + goto vcc_disable; + } + dev_dbg(dev, "Found PS5169 with chip revision 0x%04x\n", chip_revision); + + /* DP equalization */ + ret =3D ps5169_eq_from_dt(dev, &ps5169_dp_eq_data, &(ps5169->dp_eq_level)= ); + if (ret) + goto vcc_disable; + + /* USB RX equalization */ + ret =3D ps5169_eq_from_dt(dev, &ps5169_usb_rx_eq_data, &(ps5169->usb_rx_e= q_level)); + if (ret) + goto vcc_disable; + + /* USB TX equalization */ + ret =3D ps5169_eq_from_dt(dev, &ps5169_usb_tx_eq_data, &(ps5169->usb_tx_e= q_level)); + if (ret) + goto vcc_disable; + + /* Read properties from DT */ + ps5169->tune_lfps =3D device_property_read_bool(dev, "parade,fine-tune-lf= ps-swing"); + + ps5169->dp_set_gain =3D device_property_read_bool(dev, "parade,dp-set-gai= n"); + ps5169->usb_rx_set_gain =3D device_property_read_bool(dev, "parade,usb-rx= -set-gain"); + ps5169->usb_tx_set_gain =3D device_property_read_bool(dev, "parade,usb-tx= -set-gain"); + + ret =3D drm_aux_bridge_register(dev); + if (ret) { + dev_err(dev, "Failed to register aux_bridge\n"); + goto vcc_disable; + } + + ps5169->mode =3D TYPEC_STATE_SAFE; + ps5169->orientation =3D TYPEC_ORIENTATION_NONE; + + /* orientation-switch */ + switch_desc.drvdata =3D ps5169; + switch_desc.fwnode =3D dev_fwnode(dev); + switch_desc.set =3D ps5169_switch_set; + + ps5169->sw =3D typec_switch_register(dev, &switch_desc); + if (IS_ERR(ps5169->sw)) { + ret =3D dev_err_probe(dev, PTR_ERR(ps5169->sw), "Failed to register swit= ch\n"); + goto vcc_disable; + } + + /* retimer-switch */ + retimer_desc.drvdata =3D ps5169; + retimer_desc.fwnode =3D dev_fwnode(dev); + retimer_desc.set =3D ps5169_retimer_set; + + ps5169->retimer =3D typec_retimer_register(dev, &retimer_desc); + if (IS_ERR(ps5169->retimer)) { + ret =3D dev_err_probe(dev, PTR_ERR(ps5169->retimer), "Failed to register= retimer\n"); + goto switch_unregister; + } + + ps5169_init(ps5169); + + i2c_set_clientdata(client, ps5169); + + return 0; + +switch_unregister: + typec_switch_unregister(ps5169->sw); + +vcc_disable: + regulator_disable(ps5169->vcc); + +mux_put: + typec_mux_put(ps5169->typec_mux); +switch_put: + typec_switch_put(ps5169->typec_switch); + + return ret; +} + +static void ps5169_remove(struct i2c_client *client) +{ + struct redriver *ps5169 =3D i2c_get_clientdata(client); + + typec_retimer_unregister(ps5169->retimer); + typec_switch_unregister(ps5169->sw); + + regulator_disable(ps5169->vcc); + + typec_mux_put(ps5169->typec_mux); + typec_switch_put(ps5169->typec_switch); +} + +static const struct of_device_id ps5169_of_match_table[] =3D { + { .compatible =3D "parade,ps5169" }, + { }, +}; +MODULE_DEVICE_TABLE(of, ps5169_of_match_table); + +static struct i2c_driver ps5169_driver =3D { + .driver =3D { + .name =3D "ps5169", + .of_match_table =3D ps5169_of_match_table, + }, + .probe =3D ps5169_probe, + .remove =3D ps5169_remove, +}; + +module_i2c_driver(ps5169_driver); + +MODULE_AUTHOR("Esteban Urrutia "); +MODULE_DESCRIPTION("Driver for Parade PS5169 USB Type-C linear redriver"); +MODULE_LICENSE("GPL"); --=20 2.55.0