From nobody Mon Sep 28 13:17:46 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (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 32FA8437473; Fri, 21 Aug 2026 08:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300804; cv=none; b=OlkDefYyw27noYtTwmvCtT7SpyxusE8V1SijFjr92ZF5w0RDowbgReKuEJdcBuNA6GPJ+9c5sF+QTScse/NLjAVmAnJW1bL41t1+RyGln/aaKK6BoJNSVI9hLQWM8SatNIt9fwhh7h9kxBsn+v+8ayN8I1D3d5v8TUZ6ySiZA64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300804; c=relaxed/simple; bh=S8rAFC4kXT2BBExVLVQG2pMHEqohecFIGxPB3nprXVM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WIK3zo7nDniMEB+x2r6UHeVhwWLhPFL8wngFsFmdrRqq89prJ+zhe/6SYffqf9ZAYLK6EvdZR8BXdulnZxhrSc73CTYK0NLziGESSmWE2hwXKbWJ21yxEtGhxU3U2CFtmf3cyFJUx3Vm7R4x+RVmQE6GTTYiN28W4qFkjAmcGng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=nCF2czA4; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="nCF2czA4" Received: by chaosmail.tech (Postfix) id 4B7A71C89AD; Fri, 21 Aug 2026 08:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1787300789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6AjHsz8ywMeNWf5nPv3DrZzyk1diaThBgEcH9zvlRBQ=; b=nCF2czA4zvvVe6J9Zx1SrxcBwr9W/1WQH7+9pQ+5bq+uMcszdzSGX/4ZmVpf6F1Z1AQiU0 fEqJ4VhkhlLSvxcZ/YrXNP8t01TX4QouFaQhxoBiA5Q/NhijoOCNF4z4C6NwSijqJ/E2bH GO2THdaZs5j9HZ+I6lMbOEX8RseUVyE= From: Sasha Finkelstein Date: Fri, 21 Aug 2026 10:26:19 +0200 Subject: [PATCH v5 1/3] dt-bindings: usb: tps6598x: Add sn201202x/ACE3 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: <20260821-tipd-ace3-v5-1-3244ed3bdc3f@chaosmail.tech> References: <20260821-tipd-ace3-v5-0-3244ed3bdc3f@chaosmail.tech> In-Reply-To: <20260821-tipd-ace3-v5-0-3244ed3bdc3f@chaosmail.tech> To: Sven Peter , Janne Grunau , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heikki Krogerus Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sasha Finkelstein X-Developer-Signature: v=1; a=ed25519-sha256; t=1787300788; l=3467; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=S8rAFC4kXT2BBExVLVQG2pMHEqohecFIGxPB3nprXVM=; b=fZX1Q9hCEb/vbnmF8nrJgNeofawXUCsHU07OrxzGgx8lo+K8l7mka1sNiqq4pWgDa6YeWZlfO 3Q9gpKuWY1JBrtEl6B2gaIU+z3zJSaSJCZCjgfUaBvRHzdhLybErDrJ X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= A variant of tps6598x that is attached to a SPMI bus and is found on Apple devices starting from the M3 series Reviewed-by: Rob Herring (Arm) Signed-off-by: Sasha Finkelstein --- Documentation/devicetree/bindings/usb/apple,sn201202x.yaml | 78 ++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 79 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml b/D= ocumentation/devicetree/bindings/usb/apple,sn201202x.yaml new file mode 100644 index 000000000000..133a71bbedb7 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/apple,sn201202x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments sn201202x Type-C Power Delivery controller + +maintainers: + - Sasha Finkelstein + +description: | + Texas Instruments sn201202x Type-C Power Delivery controller + + A variant of tps6598x controller also known as Apple ACE3 + present on hardware with Apple SoCs starting from the M3. + +properties: + compatible: + enum: + - apple,sn201202x + + reg: + maxItems: 1 + + interrupts: + items: + - description: Primary irq used for tps6598x events + - description: Logical register selection completed + - description: Standby command completed + - description: Wakeup command completed + + interrupt-names: + items: + - const: irq + - const: select + - const: sleep + - const: wake + + connector: + $ref: /schemas/connector/usb-connector.yaml# + +required: + - compatible + - reg + - interrupts + - interrupt-names + +additionalProperties: false + +examples: + - | + #include + #include + spmi { + #address-cells =3D <2>; + #size-cells =3D <0>; + usb-pd@c { + compatible =3D "apple,sn201202x"; + reg =3D <0xc SPMI_USID>; + interrupts =3D <11 IRQ_TYPE_EDGE_RISING>, + <13 IRQ_TYPE_EDGE_RISING>, + <17 IRQ_TYPE_EDGE_RISING>, + <19 IRQ_TYPE_EDGE_RISING>; + interrupt-names =3D "irq", "select", "sleep", "wake"; + + connector { + compatible =3D "usb-c-connector"; + label =3D "USB-C"; + + port { + typec_ep: endpoint { + remote-endpoint =3D <&otg_ep>; + }; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 8014b9f8253e..62030ad60baa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2610,6 +2610,7 @@ F: Documentation/devicetree/bindings/rtc/apple,smc-rt= c.yaml F: Documentation/devicetree/bindings/spi/apple,spi.yaml F: Documentation/devicetree/bindings/spmi/apple,spmi.yaml F: Documentation/devicetree/bindings/usb/apple,dwc3.yaml +F: Documentation/devicetree/bindings/usb/apple,sn201202x.yaml F: Documentation/devicetree/bindings/watchdog/apple,wdt.yaml F: Documentation/hwmon/macsmc-hwmon.rst F: arch/arm64/boot/dts/apple/ --=20 2.55.0 From nobody Mon Sep 28 13:17:46 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (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 E030F42BEBA; Fri, 21 Aug 2026 08:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300805; cv=none; b=BT2BXboG1dX5aFwq0mHdsJ2SQfsTQt4ps5uXeN9juFs0riS+9zldRYHN+jeh3KgVBiAkeYnW2/03rzZ+Eh8TsQAUArKFKHHi4maZ+Qh3UlEhAqBiU7g10HHvkFNBzSJvQkIiw777k2SRftcsES0ymk26KuTP9vfHj5rfWpu+iNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300805; c=relaxed/simple; bh=D10unKdbr7g7pycqzcoa4L8+WDNs36lF8xOdie1QbiE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sicZGVc4QrK/13zjiaQuTGBIidegeGdA1+7WaySBtMNV9o23t1EPH1cbXU4r+b5C+8K2pmxM8GAjOnQOQjcDNPSK09itT+bNpcjcI2J6HcN888JjKd+pGJnIgEPoVb/CIPzMzAgC37KEqEcvmy64M5e7/2i5zYjWepCHezSrD7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=HnRRKt98; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="HnRRKt98" Received: by chaosmail.tech (Postfix) id 08E591C975B; Fri, 21 Aug 2026 08:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1787300790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4eTQtIWDeYX0nFSbVMRJTv9kxbReYCoOBTmtdsGVrgg=; b=HnRRKt98k1v7mimewBogdiviL7pjUcrPGLwUML4tf8AIUQESHmmYoJHto/Zof+H/EhfqjV neKZ+6oZsHwu4ZwQxsLJ+k7LIiroo4ivk28Mi6dvjGiip1bnkHGTIByFftyQP8q1FFg1Cl aoPgUjR8bDRRR13z1YD7JzmpMTkeOY8= From: Sasha Finkelstein Date: Fri, 21 Aug 2026 10:26:20 +0200 Subject: [PATCH v5 2/3] usb: typec: tipd: Factor out i2c specifics 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: <20260821-tipd-ace3-v5-2-3244ed3bdc3f@chaosmail.tech> References: <20260821-tipd-ace3-v5-0-3244ed3bdc3f@chaosmail.tech> In-Reply-To: <20260821-tipd-ace3-v5-0-3244ed3bdc3f@chaosmail.tech> To: Sven Peter , Janne Grunau , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heikki Krogerus Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sasha Finkelstein , Alyssa Milburn X-Developer-Signature: v=1; a=ed25519-sha256; t=1787300788; l=21351; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=8lO9vjrmhJMiv7akDFbNdly/sWGRa+kvIuVXiA2w1Lg=; b=jEuq5upSC20/pgctMqYDpBtw3CJRC2N4eeuqx/8tPAtKB6grQUpj7Mz3eztFtcranzHImhlqZ RTDEfPUCDFCCPvI5wkJnkMlrhVZch6kVwUNGkIfHVbL/WHD5cu8IQ7m X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= From: Alyssa Milburn Make the core driver more bus-agnostic to prepare for SPMI variants of the tipd chip Signed-off-by: Alyssa Milburn Reviewed-by: Heikki Krogerus Signed-off-by: Sasha Finkelstein --- drivers/usb/typec/tipd/Kconfig | 8 +++-- drivers/usb/typec/tipd/Makefile | 11 ++++--- drivers/usb/typec/tipd/core.c | 230 ++++++++++++++++++++++++----------= ---------------------------------------------------------------------------= ---------------------------------- drivers/usb/typec/tipd/i2c.c | 106 ++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++ drivers/usb/typec/tipd/tps6598x.h | 123 ++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 280 insertions(+), 198 deletions(-) diff --git a/drivers/usb/typec/tipd/Kconfig b/drivers/usb/typec/tipd/Kconfig index b82715293072..c87cbe6109ca 100644 --- a/drivers/usb/typec/tipd/Kconfig +++ b/drivers/usb/typec/tipd/Kconfig @@ -1,9 +1,13 @@ +config TYPEC_TPS6598X_CORE + tristate + select USB_ROLE_SWITCH + select POWER_SUPPLY + config TYPEC_TPS6598X tristate "TI TPS6598x USB Power Delivery controller driver" depends on I2C - select POWER_SUPPLY select REGMAP_I2C - select USB_ROLE_SWITCH + select TYPEC_TPS6598X_CORE help Say Y or M here if your system has TI TPS65982 or TPS65983 USB Power Delivery controller. diff --git a/drivers/usb/typec/tipd/Makefile b/drivers/usb/typec/tipd/Makef= ile index aa439f80a889..c741bf44f52f 100644 --- a/drivers/usb/typec/tipd/Makefile +++ b/drivers/usb/typec/tipd/Makefile @@ -1,6 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 -CFLAGS_trace.o :=3D -I$(src) +CFLAGS_trace.o :=3D -I$(src) =20 -obj-$(CONFIG_TYPEC_TPS6598X) +=3D tps6598x.o -tps6598x-y :=3D core.o -tps6598x-$(CONFIG_TRACING) +=3D trace.o +obj-$(CONFIG_TYPEC_TPS6598X_CORE) +=3D tps6598x-core.o +tps6598x-core-y :=3D core.o +tps6598x-core-$(CONFIG_TRACING) +=3D trace.o + +obj-$(CONFIG_TYPEC_TPS6598X) +=3D tps6598x.o +tps6598x-y :=3D i2c.o diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 522f56742aa9..36fccd45858b 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -9,11 +9,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -92,31 +90,6 @@ struct tps6598x_rx_identity_reg { struct usb_pd_identity identity; } __packed; =20 -/* TPS_REG_USB4_STATUS */ -struct tps6598x_usb4_status_reg { - u8 mode_status; - __le32 eudo; - __le32 unknown; -} __packed; - -/* TPS_REG_DP_SID_STATUS */ -struct tps6598x_dp_sid_status_reg { - u8 mode_status; - __le32 status_tx; - __le32 status_rx; - __le32 configure; - __le32 mode_data; -} __packed; - -/* TPS_REG_INTEL_VID_STATUS */ -struct tps6598x_intel_vid_status_reg { - u8 mode_status; - __le32 attention_vdo; - __le16 enter_vdo; - __le16 device_mode; - __le16 cable_mode; -} __packed; - /* Standard Task return codes */ #define TPS_TASK_TIMEOUT 1 #define TPS_TASK_REJECTED 3 @@ -145,82 +118,6 @@ static const char *const modes[] =3D { /* Unrecognized commands will be replaced with "!CMD" */ #define INVALID_CMD(_cmd_) (_cmd_ =3D=3D 0x444d4321) =20 -struct tps6598x; - -struct tipd_data { - irq_handler_t irq_handler; - u64 irq_mask1; - size_t tps_struct_size; - void (*remove)(struct tps6598x *tps); - int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); - void (*unregister_port)(struct tps6598x *tps); - void (*trace_data_status)(u32 status); - void (*trace_power_status)(u16 status); - void (*trace_status)(u32 status); - int (*apply_patch)(struct tps6598x *tps); - int (*init)(struct tps6598x *tps); - int (*switch_power_state)(struct tps6598x *tps, u8 target_state); - bool (*read_data_status)(struct tps6598x *tps); - bool (*read_power_status)(struct tps6598x *tps); - int (*reset)(struct tps6598x *tps); - int (*connect)(struct tps6598x *tps, u32 status); -}; - -struct tps6598x { - struct device *dev; - struct regmap *regmap; - struct mutex lock; /* device lock */ - u8 i2c_protocol:1; - - struct gpio_desc *reset; - struct typec_port *port; - struct typec_partner *partner; - struct usb_pd_identity partner_identity; - struct usb_role_switch *role_sw; - struct typec_capability typec_cap; - - struct power_supply *psy; - struct power_supply_desc psy_desc; - enum power_supply_usb_type usb_type; - - int wakeup; - u32 status; /* status reg */ - u32 data_status; - u16 pwr_status; - struct delayed_work wq_poll; - - const struct tipd_data *data; -}; - -struct cd321x_status { - u32 status; - u32 pwr_status; - u32 data_status; - u32 status_changed; - struct usb_pd_identity partner_identity; - struct tps6598x_dp_sid_status_reg dp_sid_status; - struct tps6598x_intel_vid_status_reg intel_vid_status; - struct tps6598x_usb4_status_reg usb4_status; -}; - -struct cd321x { - struct tps6598x tps; - - struct tps6598x_dp_sid_status_reg dp_sid_status; - struct tps6598x_intel_vid_status_reg intel_vid_status; - struct tps6598x_usb4_status_reg usb4_status; - - struct typec_altmode *port_altmode_dp; - struct typec_altmode *port_altmode_tbt; - - struct typec_mux *mux; - struct typec_mux_state state; - - struct cd321x_status update_status; - struct delayed_work update_work; - struct usb_pd_identity cur_partner_identity; -}; - static enum power_supply_property tps6598x_psy_props[] =3D { POWER_SUPPLY_PROP_USB_TYPE, POWER_SUPPLY_PROP_ONLINE, @@ -1127,11 +1024,12 @@ static int tps6598x_check_mode(struct tps6598x *tps) return -ENODEV; } =20 -static const struct regmap_config tps6598x_regmap_config =3D { +const struct regmap_config tps6598x_regmap_config =3D { .reg_bits =3D 8, .val_bits =3D 8, .max_register =3D 0x7F, }; +EXPORT_SYMBOL_GPL(tps6598x_regmap_config); =20 static int tps6598x_psy_get_online(struct tps6598x *tps, union power_supply_propval *val) @@ -1778,27 +1676,13 @@ static void cd321x_remove(struct tps6598x *tps) cancel_delayed_work_sync(&cd321x->update_work); } =20 -static int tps6598x_probe(struct i2c_client *client) +int tipd_init(struct tps6598x *tps) { - const struct tipd_data *data; - struct tps6598x *tps; struct fwnode_handle *fwnode; u32 status; u32 vid =3D 0; int ret; =20 - data =3D i2c_get_match_data(client); - if (!data) - return -EINVAL; - - tps =3D devm_kzalloc(&client->dev, data->tps_struct_size, GFP_KERNEL); - if (!tps) - return -ENOMEM; - - mutex_init(&tps->lock); - tps->dev =3D &client->dev; - tps->data =3D data; - tps->reset =3D devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(tps->reset)) return dev_err_probe(tps->dev, PTR_ERR(tps->reset), @@ -1806,10 +1690,6 @@ static int tps6598x_probe(struct i2c_client *client) if (tps->reset) msleep(TPS_SETUP_MS); =20 - tps->regmap =3D devm_regmap_init_i2c(client, &tps6598x_regmap_config); - if (IS_ERR(tps->regmap)) - return PTR_ERR(tps->regmap); - if (!device_is_compatible(tps->dev, "ti,tps25750")) { ret =3D tps6598x_read32(tps, TPS_REG_VID, &vid); if (ret < 0 || !vid) { @@ -1819,13 +1699,6 @@ static int tps6598x_probe(struct i2c_client *client) } } =20 - /* - * Checking can the adapter handle SMBus protocol. If it can not, the - * driver needs to take care of block reads separately. - */ - if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) - tps->i2c_protocol =3D true; - if (tps->data->switch_power_state) { ret =3D tps->data->switch_power_state(tps, TPS_SYSTEM_POWER_STATE_S0); if (ret) @@ -1861,7 +1734,7 @@ static int tps6598x_probe(struct i2c_client *client) * with existing DT files, we work around this by deleting any * fwnode_links to/from this fwnode. */ - fwnode =3D device_get_named_child_node(&client->dev, "connector"); + fwnode =3D device_get_named_child_node(tps->dev, "connector"); if (fwnode) fw_devlink_purge_absent_suppliers(fwnode); =20 @@ -1887,14 +1760,14 @@ static int tps6598x_probe(struct i2c_client *client) goto err_unregister_port; ret =3D tps->data->connect(tps, status); if (ret) - dev_err(&client->dev, "failed to register partner\n"); + dev_err(tps->dev, "failed to register partner\n"); } =20 - if (client->irq) { - ret =3D devm_request_threaded_irq(&client->dev, client->irq, NULL, + if (tps->irq) { + ret =3D devm_request_threaded_irq(tps->dev, tps->irq, NULL, tps->data->irq_handler, IRQF_SHARED | IRQF_ONESHOT, - dev_name(&client->dev), tps); + dev_name(tps->dev), tps); } else { dev_dbg(tps->dev, "no IRQ specified, using polling mode\n"); INIT_DELAYED_WORK(&tps->wq_poll, tps6598x_poll_work); @@ -1905,13 +1778,12 @@ static int tps6598x_probe(struct i2c_client *client) if (ret) goto err_disconnect; =20 - i2c_set_clientdata(client, tps); fwnode_handle_put(fwnode); =20 tps->wakeup =3D device_property_read_bool(tps->dev, "wakeup-source"); - if (tps->wakeup && client->irq) { - devm_device_init_wakeup(&client->dev); - enable_irq_wake(client->irq); + if (tps->wakeup && tps->irq) { + devm_device_init_wakeup(tps->dev); + enable_irq_wake(tps->irq); } =20 return 0; @@ -1932,15 +1804,14 @@ static int tps6598x_probe(struct i2c_client *client) =20 return ret; } +EXPORT_SYMBOL_GPL(tipd_init); =20 -static void tps6598x_remove(struct i2c_client *client) +void tipd_remove(struct tps6598x *tps) { - struct tps6598x *tps =3D i2c_get_clientdata(client); - - if (!client->irq) + if (!tps->irq) cancel_delayed_work_sync(&tps->wq_poll); else - devm_free_irq(tps->dev, client->irq, tps); + devm_free_irq(tps->dev, tps->irq, tps); =20 if (tps->data->remove) tps->data->remove(tps); @@ -1955,29 +1826,26 @@ static void tps6598x_remove(struct i2c_client *clie= nt) if (tps->reset) gpiod_set_value_cansleep(tps->reset, 1); } +EXPORT_SYMBOL_GPL(tipd_remove); =20 -static int __maybe_unused tps6598x_suspend(struct device *dev) +int tipd_suspend(struct tps6598x *tps) { - struct i2c_client *client =3D to_i2c_client(dev); - struct tps6598x *tps =3D i2c_get_clientdata(client); - if (tps->wakeup) { - disable_irq(client->irq); - enable_irq_wake(client->irq); + disable_irq(tps->irq); + enable_irq_wake(tps->irq); } else if (tps->reset) { gpiod_set_value_cansleep(tps->reset, 1); } =20 - if (!client->irq) + if (!tps->irq) cancel_delayed_work_sync(&tps->wq_poll); =20 return 0; } +EXPORT_SYMBOL_GPL(tipd_suspend); =20 -static int __maybe_unused tps6598x_resume(struct device *dev) +int tipd_resume(struct tps6598x *tps) { - struct i2c_client *client =3D to_i2c_client(dev); - struct tps6598x *tps =3D i2c_get_clientdata(client); int ret; =20 ret =3D tps6598x_check_mode(tps); @@ -1991,25 +1859,22 @@ static int __maybe_unused tps6598x_resume(struct de= vice *dev) } =20 if (tps->wakeup) { - disable_irq_wake(client->irq); - enable_irq(client->irq); + disable_irq_wake(tps->irq); + enable_irq(tps->irq); } else if (tps->reset) { gpiod_set_value_cansleep(tps->reset, 0); msleep(TPS_SETUP_MS); } =20 - if (!client->irq) + if (!tps->irq) queue_delayed_work(system_power_efficient_wq, &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL)); =20 return 0; } +EXPORT_SYMBOL_GPL(tipd_resume); =20 -static const struct dev_pm_ops tps6598x_pm_ops =3D { - SET_SYSTEM_SLEEP_PM_OPS(tps6598x_suspend, tps6598x_resume) -}; - -static const struct tipd_data cd321x_data =3D { +static const struct tipd_data tipd_cd321x_data =3D { .irq_handler =3D cd321x_interrupt, .irq_mask1 =3D APPLE_CD_REG_INT_POWER_STATUS_UPDATE | APPLE_CD_REG_INT_DATA_STATUS_UPDATE | @@ -2029,7 +1894,7 @@ static const struct tipd_data cd321x_data =3D { .connect =3D cd321x_connect, }; =20 -static const struct tipd_data tps6598x_data =3D { +static const struct tipd_data tipd_tps6598x_data =3D { .irq_handler =3D tps6598x_interrupt, .irq_mask1 =3D TPS_REG_INT_POWER_STATUS_UPDATE | TPS_REG_INT_DATA_STATUS_UPDATE | @@ -2048,7 +1913,7 @@ static const struct tipd_data tps6598x_data =3D { .connect =3D tps6598x_connect, }; =20 -static const struct tipd_data tps66993_data =3D { +static const struct tipd_data tipd_tps66993_data =3D { .irq_handler =3D tps6598x_interrupt, .irq_mask1 =3D TPS_REG_INT_DATA_STATUS_UPDATE | TPS_REG_INT_PLUG_EVENT, @@ -2066,7 +1931,7 @@ static const struct tipd_data tps66993_data =3D { .connect =3D tps6598x_connect, }; =20 -static const struct tipd_data tps25750_data =3D { +static const struct tipd_data tipd_tps25750_data =3D { .irq_handler =3D tps25750_interrupt, .irq_mask1 =3D TPS_REG_INT_POWER_STATUS_UPDATE | TPS_REG_INT_DATA_STATUS_UPDATE | @@ -2085,33 +1950,14 @@ static const struct tipd_data tps25750_data =3D { .connect =3D tps6598x_connect, }; =20 -static const struct of_device_id tps6598x_of_match[] =3D { - { .compatible =3D "ti,tps6598x", &tps6598x_data}, - { .compatible =3D "ti,tps66993", &tps66993_data}, - { .compatible =3D "apple,cd321x", &cd321x_data}, - { .compatible =3D "ti,tps25750", &tps25750_data}, - {} -}; -MODULE_DEVICE_TABLE(of, tps6598x_of_match); - -static const struct i2c_device_id tps6598x_id[] =3D { - { .name =3D "tps6598x", .driver_data =3D (kernel_ulong_t)&tps6598x_data }, - { } -}; -MODULE_DEVICE_TABLE(i2c, tps6598x_id); - -static struct i2c_driver tps6598x_i2c_driver =3D { - .driver =3D { - .name =3D "tps6598x", - .pm =3D &tps6598x_pm_ops, - .of_match_table =3D tps6598x_of_match, - }, - .probe =3D tps6598x_probe, - .remove =3D tps6598x_remove, - .id_table =3D tps6598x_id, +const struct tipd_data *tipd_hw_variants[] =3D { + [TIPD_VARIANT_CD321X] =3D &tipd_cd321x_data, + [TIPD_VARIANT_TPS6598X] =3D &tipd_tps6598x_data, + [TIPD_VARIANT_TPS66993] =3D &tipd_tps6598x_data, + [TIPD_VARIANT_TPS25750] =3D &tipd_tps25750_data, }; -module_i2c_driver(tps6598x_i2c_driver); +EXPORT_SYMBOL_GPL(tipd_hw_variants); =20 MODULE_AUTHOR("Heikki Krogerus "); -MODULE_LICENSE("GPL v2"); -MODULE_DESCRIPTION("TI TPS6598x USB Power Delivery Controller Driver"); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("TI TPS6598x USB Power Delivery Controller Core Functio= ns"); diff --git a/drivers/usb/typec/tipd/i2c.c b/drivers/usb/typec/tipd/i2c.c new file mode 100644 index 000000000000..f852cdc327f5 --- /dev/null +++ b/drivers/usb/typec/tipd/i2c.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for TI TPS6598x USB Power Delivery controller family + * + * Copyright (C) The Asahi Linux Contributors + */ + +#include +#include +#include + +#include "tps6598x.h" + +static int tps6598x_probe_i2c(struct i2c_client *client) +{ + enum tipd_hw_variant variant; + const struct tipd_data *data; + struct tps6598x *tps; + int ret; + + variant =3D (enum tipd_hw_variant)i2c_get_match_data(client); + if (!variant || variant >=3D TIPD_VARIANT_MAX) + return -EINVAL; + data =3D tipd_hw_variants[variant]; + + tps =3D devm_kzalloc(&client->dev, data->tps_struct_size, GFP_KERNEL); + if (!tps) + return -ENOMEM; + + mutex_init(&tps->lock); + tps->dev =3D &client->dev; + tps->data =3D data; + tps->irq =3D client->irq; + + tps->regmap =3D devm_regmap_init_i2c(client, &tps6598x_regmap_config); + if (IS_ERR(tps->regmap)) + return PTR_ERR(tps->regmap); + + /* + * Checking can the adapter handle SMBus protocol. If it can not, the + * driver needs to take care of block reads separately. + */ + if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + tps->i2c_protocol =3D true; + + ret =3D tipd_init(tps); + + if (ret =3D=3D 0) + i2c_set_clientdata(client, tps); + + return ret; +} + +static void tps6598x_remove_i2c(struct i2c_client *client) +{ + struct tps6598x *tps =3D i2c_get_clientdata(client); + + tipd_remove(tps); +} + +static int __maybe_unused tps6598x_suspend(struct device *dev) +{ + struct tps6598x *tps =3D dev_get_drvdata(dev); + + return tipd_suspend(tps); +} + +static int __maybe_unused tps6598x_resume(struct device *dev) +{ + struct tps6598x *tps =3D dev_get_drvdata(dev); + + return tipd_resume(tps); +} + +static const struct dev_pm_ops tps6598x_pm_ops =3D { + SET_SYSTEM_SLEEP_PM_OPS(tps6598x_suspend, tps6598x_resume) +}; + +static const struct of_device_id tps6598x_of_match[] =3D { + { .compatible =3D "ti,tps6598x", (void *)TIPD_VARIANT_TPS6598X}, + { .compatible =3D "apple,cd321x", (void *)TIPD_VARIANT_CD321X}, + { .compatible =3D "ti,tps25750", (void *)TIPD_VARIANT_TPS25750}, + {} +}; +MODULE_DEVICE_TABLE(of, tps6598x_of_match); + +static const struct i2c_device_id tps6598x_id[] =3D { + { .name =3D "tps6598x", .driver_data =3D (kernel_ulong_t)TIPD_VARIANT_TPS= 6598X }, + { } +}; +MODULE_DEVICE_TABLE(i2c, tps6598x_id); + +static struct i2c_driver tps6598x_i2c_driver =3D { + .driver =3D { + .name =3D "tps6598x", + .pm =3D &tps6598x_pm_ops, + .of_match_table =3D tps6598x_of_match, + }, + .probe =3D tps6598x_probe_i2c, + .remove =3D tps6598x_remove_i2c, + .id_table =3D tps6598x_id, +}; +module_i2c_driver(tps6598x_i2c_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("TI TPS6598x USB Power Delivery Controller Driver"); diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps= 6598x.h index d4140f4da5bb..6b9785c62afd 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -8,6 +8,10 @@ =20 #include #include +#include +#include +#include +#include =20 #ifndef __TPS6598X_H__ #define __TPS6598X_H__ @@ -273,4 +277,123 @@ #define TPS_65981_2_6_INTEVENT_LEN 8 #define TPS_65987_8_INTEVENT_LEN 11 =20 +enum tipd_hw_variant { + TIPD_VARIANT_INVALID =3D 0, + TIPD_VARIANT_CD321X, + TIPD_VARIANT_TPS6598X, + TIPD_VARIANT_TPS66993, + TIPD_VARIANT_TPS25750, + TIPD_VARIANT_MAX, +}; + +struct tps6598x; + +struct tipd_data { + irq_handler_t irq_handler; + u64 irq_mask1; + size_t tps_struct_size; + void (*remove)(struct tps6598x *tps); + int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); + void (*unregister_port)(struct tps6598x *tps); + void (*trace_data_status)(u32 status); + void (*trace_power_status)(u16 status); + void (*trace_status)(u32 status); + int (*apply_patch)(struct tps6598x *tps); + int (*init)(struct tps6598x *tps); + int (*switch_power_state)(struct tps6598x *tps, u8 target_state); + bool (*read_data_status)(struct tps6598x *tps); + bool (*read_power_status)(struct tps6598x *tps); + int (*reset)(struct tps6598x *tps); + int (*connect)(struct tps6598x *tps, u32 status); +}; + +struct tps6598x { + struct device *dev; + struct regmap *regmap; + struct mutex lock; /* device lock */ + int irq; + u8 i2c_protocol:1; + + struct gpio_desc *reset; + struct typec_port *port; + struct typec_partner *partner; + struct usb_pd_identity partner_identity; + struct usb_role_switch *role_sw; + struct typec_capability typec_cap; + + struct power_supply *psy; + struct power_supply_desc psy_desc; + enum power_supply_usb_type usb_type; + + int wakeup; + u32 status; /* status reg */ + u32 data_status; + u16 pwr_status; + struct delayed_work wq_poll; + + const struct tipd_data *data; +}; + +/* TPS_REG_USB4_STATUS */ +struct tps6598x_usb4_status_reg { + u8 mode_status; + __le32 eudo; + __le32 unknown; +} __packed; + +/* TPS_REG_DP_SID_STATUS */ +struct tps6598x_dp_sid_status_reg { + u8 mode_status; + __le32 status_tx; + __le32 status_rx; + __le32 configure; + __le32 mode_data; +} __packed; + +/* TPS_REG_INTEL_VID_STATUS */ +struct tps6598x_intel_vid_status_reg { + u8 mode_status; + __le32 attention_vdo; + __le16 enter_vdo; + __le16 device_mode; + __le16 cable_mode; +} __packed; + +struct cd321x_status { + u32 status; + u32 pwr_status; + u32 data_status; + u32 status_changed; + struct usb_pd_identity partner_identity; + struct tps6598x_dp_sid_status_reg dp_sid_status; + struct tps6598x_intel_vid_status_reg intel_vid_status; + struct tps6598x_usb4_status_reg usb4_status; +}; + +struct cd321x { + struct tps6598x tps; + + struct tps6598x_dp_sid_status_reg dp_sid_status; + struct tps6598x_intel_vid_status_reg intel_vid_status; + struct tps6598x_usb4_status_reg usb4_status; + + struct typec_altmode *port_altmode_dp; + struct typec_altmode *port_altmode_tbt; + + struct typec_mux *mux; + struct typec_mux_state state; + + struct cd321x_status update_status; + struct delayed_work update_work; + struct usb_pd_identity cur_partner_identity; +}; + +extern const struct tipd_data *tipd_hw_variants[]; +extern const struct regmap_config tps6598x_regmap_config; + +int tipd_init(struct tps6598x *tps); +void tipd_remove(struct tps6598x *tps); +int tipd_suspend(struct tps6598x *tps); +int tipd_resume(struct tps6598x *tps); + #endif /* __TPS6598X_H__ */ --=20 2.55.0 From nobody Mon Sep 28 13:17:46 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (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 339E943BDCB; Fri, 21 Aug 2026 08:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300804; cv=none; b=qmTghzVkfMm4IK3mSvk+gJDyTyo4+lmxcJOliizTSjidbyVwG/NVHBGf1YIwQAMefI+C4zYbrkyjKR2SRjleaB2Fd8hb/J8dmUiRq0TqpEn28ARl4r4voCTyGN8LRWgFckDrNbVqCgIGg9rSYE5SiLSjLDOa9E/j1XOkjm+vE2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787300804; c=relaxed/simple; bh=s1QFEyLwI8H6Ws9ZWK6XgSNxUAp7uTU/DFY60XW6T1U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t40773OzJsxijyFepnUDOoII10caRCzumEzJP+tkOUlfelURRz4xOB9nW3sf+IAyH0+0em20h19L6PgzfpagycX6vMTJZeVqrjt/dq39pV8sVOma0Yzo0OcpiS5LF77Si99JoMZNSbu6J1voU6d5tCHDGkKVrXqUBC9AB/NTexk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=dz/YmkcS; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="dz/YmkcS" Received: by chaosmail.tech (Postfix) id D1BFC1C97BC; Fri, 21 Aug 2026 08:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1787300791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cvXUBalgEG0j11NTAYY73TfRTXAskvdJc5l6JuSDFdo=; b=dz/YmkcSJ2Fv7YAdjnCgl4tEixsuXPWqnm/2JXzI4TcIHRAZFdrS6AX/1kb41GtGce7vfU SBtmNys/qTVRvY/7OfnSJ4CESDQ5PN8OC0PNyxkLjFSIqPb86q58fuq/UDNKspY6pDatfg QEHzpbacy0YRk+KsQWMPBFNoXTvy6q8= From: Sasha Finkelstein Date: Fri, 21 Aug 2026 10:26:21 +0200 Subject: [PATCH v5 3/3] usb: typec: tipd: Add sn201202x support 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: <20260821-tipd-ace3-v5-3-3244ed3bdc3f@chaosmail.tech> References: <20260821-tipd-ace3-v5-0-3244ed3bdc3f@chaosmail.tech> In-Reply-To: <20260821-tipd-ace3-v5-0-3244ed3bdc3f@chaosmail.tech> To: Sven Peter , Janne Grunau , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heikki Krogerus Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sasha Finkelstein , Alyssa Milburn X-Developer-Signature: v=1; a=ed25519-sha256; t=1787300788; l=12300; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=s1QFEyLwI8H6Ws9ZWK6XgSNxUAp7uTU/DFY60XW6T1U=; b=QkUOGpMRWvdxrzj9VdnZD+nMwO6TvqI4LLTt4yslhr1kfvLuB+tnWsk17Y/TFy+PS9VnUeLOC gzeiojfy9WBBYk7dIOVzswJmRoMaJpymrcqm2o5F4DnIVzIqDoGPlzo X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= Add support for sn201202x (aka ACE3), a tipd variant that uses a very similar register map, that is exposed over a "logical register" interface on the SPMI bus. Reviewed-by: Heikki Krogerus Co-developed-by: Alyssa Milburn Signed-off-by: Alyssa Milburn Signed-off-by: Sasha Finkelstein --- MAINTAINERS | 1 + drivers/usb/typec/tipd/Kconfig | 12 ++++++ drivers/usb/typec/tipd/Makefile | 3 ++ drivers/usb/typec/tipd/core.c | 20 ++++++++++ drivers/usb/typec/tipd/spmi.c | 300 ++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++ drivers/usb/typec/tipd/tps6598x.h | 9 +++++ 6 files changed, 345 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 62030ad60baa..afe38cb1156b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2641,6 +2641,7 @@ F: drivers/soc/apple/* F: drivers/spi/spi-apple.c F: drivers/spmi/spmi-apple-controller.c F: drivers/usb/dwc3/dwc3-apple.c +F: drivers/usb/typec/tipd/spmi.c F: drivers/video/backlight/apple_dwi_bl.c F: drivers/watchdog/apple_wdt.c F: include/dt-bindings/interrupt-controller/apple-aic.h diff --git a/drivers/usb/typec/tipd/Kconfig b/drivers/usb/typec/tipd/Kconfig index c87cbe6109ca..8177f860f89d 100644 --- a/drivers/usb/typec/tipd/Kconfig +++ b/drivers/usb/typec/tipd/Kconfig @@ -14,3 +14,15 @@ config TYPEC_TPS6598X =20 If you choose to build this driver as a dynamically linked module, the module will be called tps6598x.ko. + +config TYPEC_SN201202X + tristate "TI SN201202x USB Power Delivery controller support" + depends on SPMI + select TYPEC_TPS6598X_CORE + help + Say Y here to enable support for SN201202x, a TPS6598x variant + that uses SPMI as a host bus, and is found on Apple devices starting + from the M3 series. + + If you choose to build this driver as a dynamically linked module, the + module will be called sn201202x.ko. diff --git a/drivers/usb/typec/tipd/Makefile b/drivers/usb/typec/tipd/Makef= ile index c741bf44f52f..6f5ebc1e1a5f 100644 --- a/drivers/usb/typec/tipd/Makefile +++ b/drivers/usb/typec/tipd/Makefile @@ -7,3 +7,6 @@ tps6598x-core-$(CONFIG_TRACING) +=3D trace.o =20 obj-$(CONFIG_TYPEC_TPS6598X) +=3D tps6598x.o tps6598x-y :=3D i2c.o + +obj-$(CONFIG_TYPEC_SN201202X) +=3D sn201202x.o +sn201202x-y :=3D spmi.o diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 36fccd45858b..296bc8adcc91 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -1950,11 +1950,31 @@ static const struct tipd_data tipd_tps25750_data = =3D { .connect =3D tps6598x_connect, }; =20 +static const struct tipd_data tipd_sn201202x_data =3D { + .irq_handler =3D cd321x_interrupt, + .irq_mask1 =3D APPLE_CD_REG_INT_POWER_STATUS_UPDATE | + APPLE_CD_REG_INT_DATA_STATUS_UPDATE | + APPLE_CD_REG_INT_PLUG_EVENT, + .tps_struct_size =3D sizeof(struct sn201202x), + .remove =3D cd321x_remove, + .register_port =3D cd321x_register_port, + .unregister_port =3D cd321x_unregister_port, + .trace_data_status =3D trace_cd321x_data_status, + .trace_power_status =3D trace_tps6598x_power_status, + .trace_status =3D trace_tps6598x_status, + .init =3D cd321x_init, + .read_data_status =3D cd321x_read_data_status, + .reset =3D cd321x_reset, + .switch_power_state =3D cd321x_switch_power_state, + .connect =3D cd321x_connect, +}; + const struct tipd_data *tipd_hw_variants[] =3D { [TIPD_VARIANT_CD321X] =3D &tipd_cd321x_data, [TIPD_VARIANT_TPS6598X] =3D &tipd_tps6598x_data, [TIPD_VARIANT_TPS66993] =3D &tipd_tps6598x_data, [TIPD_VARIANT_TPS25750] =3D &tipd_tps25750_data, + [TIPD_VARIANT_SN201202X] =3D &tipd_sn201202x_data, }; EXPORT_SYMBOL_GPL(tipd_hw_variants); =20 diff --git a/drivers/usb/typec/tipd/spmi.c b/drivers/usb/typec/tipd/spmi.c new file mode 100644 index 000000000000..15976d15d9bc --- /dev/null +++ b/drivers/usb/typec/tipd/spmi.c @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +#include "tps6598x.h" + +#define tps_to_sn(tps) container_of_const((tps), struct sn201202x, cd.tps) + +static int regmap_sn201202x_select_reg(struct spmi_device *sdev, u8 reg) +{ + int err; + u8 val; + bool warned =3D false; + int attempts =3D 5; + struct tps6598x *tps =3D spmi_device_get_drvdata(sdev); + struct sn201202x *sn =3D tps_to_sn(tps); + + if (reg >=3D 0x80) { + WARN_ON(1); + return -EINVAL; + } + reinit_completion(&sn->select_completion); + err =3D spmi_register_zero_write(sdev, reg); + if (err) + return err; + + if (!wait_for_completion_timeout(&sn->select_completion, msecs_to_jiffies= (100))) + return -ETIMEDOUT; + + while (--attempts) { + err =3D spmi_register_read(sdev, 0, &val); + if (err) + return err; + if (val =3D=3D (reg | 0x80)) { + if (!warned) { + dev_warn(tps->dev, + "Got interrupt but selection not complete?\n"); + warned =3D true; + } + msleep(20); + continue; + } + if (val =3D=3D reg) + return 0; + return -EIO; + } + + return -EIO; +} + +static int regmap_sn201202x_read(void *context, + const void *reg, size_t reg_size, + void *val, size_t val_size) +{ + int err; + unsigned int offset =3D 0x20; + size_t len; + u8 addr; + + if (reg_size !=3D 1) { + WARN_ON(1); + return -EINVAL; + } + if (val_size > 0x40) { + WARN_ON(1); + return -EINVAL; + } + + addr =3D *(u8 *)reg; + + err =3D regmap_sn201202x_select_reg(context, addr); + if (err) + return err; + + while (val_size) { + len =3D min_t(size_t, val_size, 16); + err =3D spmi_ext_register_read(context, offset, val, len); + if (err) + return err; + offset +=3D len; + val +=3D len; + val_size -=3D len; + } + + return 0; +} + +static int regmap_sn201202x_write(void *context, const void *data, + size_t count) +{ + int err =3D 0; + unsigned int offset =3D 0xa0; + size_t len; + u8 addr; + + if (count < 1) { + WARN_ON(1); + return -EINVAL; + } + + addr =3D *(u8 *)data; + data +=3D 1; + count -=3D 1; + + if (count > 0x40) { + WARN_ON(1); + return -EINVAL; + } + + err =3D regmap_sn201202x_select_reg(context, addr); + if (err) + return err; + + while (count) { + len =3D min_t(size_t, count, 16); + err =3D spmi_ext_register_write(context, offset, data, len); + if (err) + return err; + offset +=3D len; + data +=3D len; + count -=3D len; + } + + return err; +} + +static irqreturn_t sn201202x_irq(int irq, void *data) +{ + struct completion *c =3D data; + + complete(c); + return IRQ_HANDLED; +} + +static const struct regmap_bus regmap_sn201202x =3D { + .read =3D regmap_sn201202x_read, + .write =3D regmap_sn201202x_write, + .reg_format_endian_default =3D REGMAP_ENDIAN_NATIVE, + .val_format_endian_default =3D REGMAP_ENDIAN_NATIVE, +}; + +static struct regmap *__devm_regmap_init_sn201202x(struct spmi_device *sde= v, + const struct regmap_config *config, + struct lock_class_key *lock_key, + const char *lock_name) +{ + return __devm_regmap_init(&sdev->dev, ®map_sn201202x, sdev, config, + lock_key, lock_name); +} + +#define devm_regmap_init_sn201202x(dev, config) \ + __regmap_lockdep_wrapper(__devm_regmap_init_sn201202x, #config, \ + dev, config) + +static const struct of_device_id sn201202x_of_match[] =3D { + { .compatible =3D "apple,sn201202x", (void *)TIPD_VARIANT_SN201202X}, + {} +}; + +static int sn201202x_probe(struct spmi_device *device) +{ + const struct of_device_id *match; + const struct tipd_data *data; + struct sn201202x *sn; + struct tps6598x *tps; + int irq_select, irq_sleep, irq_wake; + int ret; + + match =3D of_match_device(sn201202x_of_match, &device->dev); + if (!match) + return -EINVAL; + data =3D tipd_hw_variants[(enum tipd_hw_variant)match->data]; + + sn =3D devm_kzalloc(&device->dev, data->tps_struct_size, GFP_KERNEL); + if (!sn) + return -ENOMEM; + sn->sdev =3D device; + tps =3D &sn->cd.tps; + + mutex_init(&tps->lock); + tps->dev =3D &device->dev; + tps->data =3D data; + + tps->irq =3D of_irq_get_byname(device->dev.of_node, "irq"); + if (tps->irq < 0) + return tps->irq; + irq_select =3D of_irq_get_byname(device->dev.of_node, "select"); + if (irq_select < 0) + return irq_select; + irq_sleep =3D of_irq_get_byname(device->dev.of_node, "sleep"); + if (irq_sleep < 0) + return irq_sleep; + irq_wake =3D of_irq_get_byname(device->dev.of_node, "wake"); + if (irq_wake < 0) + return irq_wake; + + init_completion(&sn->select_completion); + init_completion(&sn->sleep_completion); + init_completion(&sn->wake_completion); + + ret =3D devm_request_irq(&device->dev, irq_select, sn201202x_irq, + 0, NULL, &sn->select_completion); + if (ret) + return ret; + ret =3D devm_request_irq(&device->dev, irq_sleep, sn201202x_irq, + 0, NULL, &sn->sleep_completion); + if (ret) + return ret; + ret =3D devm_request_irq(&device->dev, irq_wake, sn201202x_irq, + 0, NULL, &sn->wake_completion); + if (ret) + return ret; + + spmi_device_set_drvdata(device, tps); + tps->regmap =3D devm_regmap_init_sn201202x(device, &tps6598x_regmap_confi= g); + if (IS_ERR(tps->regmap)) + return PTR_ERR(tps->regmap); + + ret =3D spmi_command_wakeup(device); + if (ret) + return ret; + if (!wait_for_completion_timeout(&sn->wake_completion, msecs_to_jiffies(1= 00))) + return -ETIMEDOUT; + + ret =3D tipd_init(tps); + if (ret) + spmi_command_sleep(device); + return ret; +} + +static void sn201202x_remove(struct spmi_device *device) +{ + struct tps6598x *tps =3D spmi_device_get_drvdata(device); + struct sn201202x *sn =3D tps_to_sn(tps); + + tipd_remove(tps); + spmi_command_sleep(sn->sdev); +} + +static int __maybe_unused sn201202x_resume(struct device *dev) +{ + struct tps6598x *tps =3D dev_get_drvdata(dev); + struct sn201202x *sn =3D tps_to_sn(tps); + int err; + + reinit_completion(&sn->wake_completion); + err =3D spmi_command_wakeup(sn->sdev); + if (err) + return err; + if (!wait_for_completion_timeout(&sn->wake_completion, msecs_to_jiffies(1= 00))) + return -ETIMEDOUT; + return tipd_resume(tps); +} + +static int __maybe_unused sn201202x_suspend(struct device *dev) +{ + struct tps6598x *tps =3D dev_get_drvdata(dev); + struct sn201202x *sn =3D tps_to_sn(tps); + int err; + + err =3D tipd_suspend(tps); + if (err) + return err; + reinit_completion(&sn->sleep_completion); + err =3D spmi_command_sleep(sn->sdev); + if (err) + goto out_resume; + if (!wait_for_completion_timeout(&sn->sleep_completion, msecs_to_jiffies(= 100))) + dev_err(dev, "Waiting for sleep complete irq timed out"); + + return 0; + +out_resume: + tipd_resume(tps); + return err; +} + +MODULE_DEVICE_TABLE(of, sn201202x_of_match); + +static const struct dev_pm_ops sn201202x_pm_ops =3D { + SET_SYSTEM_SLEEP_PM_OPS(sn201202x_suspend, sn201202x_resume) +}; + +static struct spmi_driver sn201202x_driver =3D { + .driver =3D { + .name =3D "sn201202x", + .pm =3D &sn201202x_pm_ops, + .of_match_table =3D sn201202x_of_match, + }, + .probe =3D sn201202x_probe, + .remove =3D sn201202x_remove, +}; +module_spmi_driver(sn201202x_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("TI SN201202x USB Power Delivery Controller Driver"); diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps= 6598x.h index 6b9785c62afd..297be9738037 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -283,6 +283,7 @@ enum tipd_hw_variant { TIPD_VARIANT_TPS6598X, TIPD_VARIANT_TPS66993, TIPD_VARIANT_TPS25750, + TIPD_VARIANT_SN201202X, TIPD_VARIANT_MAX, }; =20 @@ -388,6 +389,14 @@ struct cd321x { struct usb_pd_identity cur_partner_identity; }; =20 +struct sn201202x { + struct cd321x cd; + struct completion select_completion; + struct completion sleep_completion; + struct completion wake_completion; + struct spmi_device *sdev; +}; + extern const struct tipd_data *tipd_hw_variants[]; extern const struct regmap_config tps6598x_regmap_config; =20 --=20 2.55.0