From patchwork Wed Sep 11 00:07:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Sunil Dhamne X-Patchwork-Id: 13799560 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 D63EA8F6C for ; Wed, 11 Sep 2024 00:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726013284; cv=none; b=mddMNDWPw7J2rBxWYXsv3SZDGI6wRiA51WOuUcnNP65cjbhCsBhOpI3ONMAu7Tk00wnoWAcu/xrisrlDwAWDOF3JObVtY8eSNFvoDKOR7vnpjkFkMl2nAkGKlfGuF2vBcqZzzthyE3I7IOPye4z4PdG6A6mGGHicHN0yH/Xe7Wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726013284; c=relaxed/simple; bh=HCzm6/XYJgVg038NOuIBT5dfy7b7uGQ2TF8ZuJ2Crj0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k1K+SilD2z00IJUloi4Pty2cu+ukqFl4mw3bzwnNHgWJcd5dw1MBGoaJ+gKYyAs6R/YljrXIUtbGAG+VFAuvCAcC6ofXZjwP0IWERABoIJiYVeAGSEztdMW4/9GhHr7OXjQ5tznoQIdmvCt3v7awo1Tm1D0x2iyE/bGbcRe2OhQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--amitsd.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nxdBQFve; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--amitsd.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nxdBQFve" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d5235d1bcaso181263937b3.2 for ; Tue, 10 Sep 2024 17:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726013281; x=1726618081; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=20SC5znsIjYm+2KNyb0KEnPeyTx6kqJyFPelaWmdQXA=; b=nxdBQFveAs71K0OseGgzO3bN9zZ/6myW6oE5YztW/00IyP1dK7eNUawCwZf/MlwOSN tUntpso4u9vB0TwnkGf8AXrQv3wZMV4DVWwttXjyYyym3aJhCAMQFTvVVC7it7+Egltl uafMCt8l1pNLeoIEVSKvvdxe+ijL+xJjidJTstR3WXUUrJ+aSGwWoxgR8zoDb7ZuDfj8 hD350mJge27F8gzqp+4rC1nbAw7Ft302mr9ItwHr7ln/kDIZZDDCTG68O8AkZx3DL5JL 7+Is/2+nP8zriZ7uzGL3vsUSFB7w+XzhR9bNwljFZWFBkLwsc/zey8MjGyv3C1ET6T5Y g4Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726013281; x=1726618081; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=20SC5znsIjYm+2KNyb0KEnPeyTx6kqJyFPelaWmdQXA=; b=JzX3ZY9ExNcbMr43Po8XbQm8emqFqHprwCdJk+dshYqKt7jGx2RC9Yc1x6pDSJMNK7 yFA+UxQaboiVkYPL+fW0/uwAVCEXLI6YEi1J4gi/HI7H7AbeWvzRRr6+5CEgFLpzU/ig yt3YIFqpp7r17exCCuYl05b6qoLowL5VmWYWkC5looRSjl/yf/7Zhr9jyqoEs9qxJi/A bbM0xDTKeLFPQmwvYqOzVrCVVTu0bVkdZcX/y6NrXgyIxUrID/vQmB6HD0iBj3RUt78E oMO2Dah//eHyM/Ldpw42QBSaOiZIRY35/84MP03XU8GPAqHgI7HQs6axZGGQILvE+KTy Q+Gw== X-Forwarded-Encrypted: i=1; AJvYcCXOKcTbsWI3le+f8nUye0VRA2uhEvcPRs0grg+lJ7cM7KW5Z+4hRa9z+Iu0+Xcw+xvoVkJ8c7kAqC4=@vger.kernel.org X-Gm-Message-State: AOJu0YwGIBGeX+CTTIa7/4bsZv4EsS1Ush08rwNYPBqNCAVINDNVc8AJ hRJih5mzLkmqVgp2UDzRqQjKLb7wjwqPk2XEchtldmOWsc/+lFQucEM77FPeeaf/hCQXD8u5GVb FFQ== X-Google-Smtp-Source: AGHT+IE667GhT1HoNc/PHmcsLt+AJfIx+Hx1SkvhKuEFRZUjW1lbjJ3YKeeUz2y1ehuLDAgex6elLCsr8SE= X-Received: from amitsd-gti.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:827]) (user=amitsd job=sendgmr) by 2002:a25:680b:0:b0:e0b:958a:3344 with SMTP id 3f1490d57ef6-e1d34a3abb7mr41869276.10.1726013280867; Tue, 10 Sep 2024 17:08:00 -0700 (PDT) Date: Tue, 10 Sep 2024 17:07:05 -0700 In-Reply-To: <20240911000715.554184-1-amitsd@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240911000715.554184-1-amitsd@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911000715.554184-2-amitsd@google.com> Subject: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values From: Amit Sunil Dhamne To: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, kyletso@google.com, rdbabiera@google.com, Amit Sunil Dhamne , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, devicetree@vger.kernel.org This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values. Cc: Badhri Jagan Sridharan Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Amit Sunil Dhamne --- .../bindings/connector/usb-connector.yaml | 23 +++++++++++++++++++ include/dt-bindings/usb/pd.h | 8 +++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/devicetree/bindings/connector/usb-connector.yaml b/Documentation/devicetree/bindings/connector/usb-connector.yaml index fb216ce68bb3..9be4ed12f13c 100644 --- a/Documentation/devicetree/bindings/connector/usb-connector.yaml +++ b/Documentation/devicetree/bindings/connector/usb-connector.yaml @@ -253,6 +253,16 @@ properties: additionalProperties: false + pd-timers: + description: An array of u32 integers, where an even index (i) is the timer (referenced in + dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer + "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for + the appropriate value). For certain timers the PD spec defines a range rather than a fixed + value. The timers may need to be tuned based on the platform. This dt property allows the user + to assign specific values based on the platform. If these values are not explicitly defined, + TCPM will use a valid default value for such timers. + $ref: /schemas/types.yaml#/definitions/uint32-array + dependencies: sink-vdos-v1: [ sink-vdos ] sink-vdos: [ sink-vdos-v1 ] @@ -478,3 +488,16 @@ examples: }; }; }; + + # USB-C connector with PD timers + - | + #include + usb { + connector { + compatible = "usb-c-connector"; + label = "USB-C"; + pd-timers = + , + ; + }; + }; diff --git a/include/dt-bindings/usb/pd.h b/include/dt-bindings/usb/pd.h index e6526b138174..6c58c30f3f39 100644 --- a/include/dt-bindings/usb/pd.h +++ b/include/dt-bindings/usb/pd.h @@ -465,4 +465,12 @@ | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7 \ | ((gi) & 0x3f) << 1 | (ct)) +/* PD Timer definitions */ +/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */ +#define PD_TIMER_SINK_WAIT_CAP 0 +/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */ +#define PD_TIMER_PS_SOURCE_OFF 1 +/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */ +#define PD_TIMER_CC_DEBOUNCE 2 + #endif /* __DT_POWER_DELIVERY_H */ From patchwork Wed Sep 11 00:07:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Sunil Dhamne X-Patchwork-Id: 13799561 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 BB4F88F6D for ; Wed, 11 Sep 2024 00:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726013292; cv=none; b=LeQaLykedEyFeDCucPKvnPw9RVRlTqV5rDgvyGEuUx0VDnxwUnbBTbwdGrlgwT2SkRpH+I4SKykd3SFL5twyFTsDwuyQjCRQ19uY76NpR/nxvV0pcfAI1PB03h3kqbw7BAJKRm4eZj0x0n6z6ta85Pxg+73jV+yOgd/yKZJ7nxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726013292; c=relaxed/simple; bh=p79RmnNeFZRiI1qyJp0oe5UH7x2O20vRmHYB8e1pjnU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m5LaV8meNQnazWPuV3sNiiBAIfQFMW97JoK+Eo8F7K4WYPpzXCSy34HCz/KgAjEwOv/eT/sj6v3OcwgnfxJYT7k9wOWHpdDDT879bpj9TnwlOa2mxbIQRXsFvtQpxmVWYB3+XZTd9sjxk/KHc+tf7KMGpS4/Es5pMokkMYL7Zdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--amitsd.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G3E0PZr3; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--amitsd.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G3E0PZr3" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0353b731b8so2553280276.2 for ; Tue, 10 Sep 2024 17:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726013290; x=1726618090; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zSuZrkmmWtMnows6Vqiwj1CrlHfoTWnGKJn8p+iwjqk=; b=G3E0PZr3jvZ46JvdIf/bM3AoppGphJgPI7oscHs47zWsAHiTl1MqYeqlhYm0s2YpII +ABhOu+NO++geDm+WZnggxcbifWH/akgKbIDJIUqmVqVhRbOvUE/FbXMYGth3l+3l/mz Zt4p7BBp63TcI57mKPhtvErwZGTLpYf8vVZe3Chy0m7Q3NjsQjjlkb9ekZ0h9mCLRtVU 2rBf8Dg2y+PzrjtgSoBRQYY1C0DtFCDrjzYf1fwwyqbBwvRq/aeffPBIHkUKBplDR1q1 hD91rBH4O8mR2DcePUiAUb/NQV7cRMUae0I8EjRRon6wdGhkUnMQUa9a3vVJwgSAJjTB t87A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726013290; x=1726618090; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zSuZrkmmWtMnows6Vqiwj1CrlHfoTWnGKJn8p+iwjqk=; b=nLr13k97+wbTXwprvOWeouTpj7rkFO5RK5FIgo5y21z0r7xs71qkXZOGU9TwvTjVFf EyvvXmhi8j0tJQUoAO1jNeMqLaFSQ3WoWW1gN4MX/mB1idz9Ap9qE+fHMQEDC7hp02ZE QjdIjPiizgJOmnU6te5BhWsJrqyv8QjvNhfsyJw723bANcPzjiVFsmWn9ivDjONG2oCp OyQ5tg7FCQe8gRPwny5O6Ii5Jbji1DL/ePcRLHKzAk8YzT5G+1z8tirssAdRVcrFmC2S JS9zy3Qu8fXfi9OpaMgEvEKeM++ZXIhrRdB8ZnHxu+79pdaw1F+n4fKVa4S3q2TlQiJ4 G7Ug== X-Forwarded-Encrypted: i=1; AJvYcCXqlE9DrGLZgsBd1g6cnhj2WtstN6iwf6+7e/C3N+kfQ97I2QSejamOUOhPh6h1WhWBagpnVcqCE3s=@vger.kernel.org X-Gm-Message-State: AOJu0YwPvjYse/xz0VzEVJKFtKWx8OsEG/XdigAdTiP05lRm2tsJVMTk oP6e2z21JhPxjzAbIlLzegL1jp/SB5uisdSaA2i3RjxH4y4IcdAGOpeFzdjntEDNqmDmimy6zZJ l4w== X-Google-Smtp-Source: AGHT+IHOqIdoAg2rmgyqW9sBWtxtlOruH3pbEyFufuku6W/fDinOxjHZ62GG721mGzE+Hp6WvzdAchgSRiU= X-Received: from amitsd-gti.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:827]) (user=amitsd job=sendgmr) by 2002:a5b:648:0:b0:e0e:4350:d7de with SMTP id 3f1490d57ef6-e1d8c539e89mr1680276.9.1726013289313; Tue, 10 Sep 2024 17:08:09 -0700 (PDT) Date: Tue, 10 Sep 2024 17:07:06 -0700 In-Reply-To: <20240911000715.554184-1-amitsd@google.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240911000715.554184-1-amitsd@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911000715.554184-3-amitsd@google.com> Subject: [RFC 2/2] usb: typec: tcpm: Add support for pd-timers DT property From: Amit Sunil Dhamne To: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, kyletso@google.com, rdbabiera@google.com, Amit Sunil Dhamne , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Add support for DT property "pd-timers" to allow users to define platform specific values. For values that have not been explicitly defined in DT using this attribute, default values will be set. Therefore making this change backward compatible. Cc: Badhri Jagan Sridharan Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Amit Sunil Dhamne --- drivers/usb/typec/tcpm/tcpm.c | 110 ++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 4b02d6474259..596d19ff85ac 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -574,6 +574,31 @@ static const char * const pd_rev[] = { [PD_REV30] = "rev3", }; +/* + * Though "pd-timers" is a 1D array, it can be imagined as a table with 2 + * columns, key at even index (that represents timer definition) & value + * at odd index (that represents timer values in ms). + */ +#define NUM_TIMER_TABLE_COLS 2 + +/* + * PD Timer definitions for timers that can be tuned based on platform/board via DT. + * The timer definition value should always match that of macros defined in + * dt-bindings/usb/pd.h. + */ +enum pd_timer { + PD_TIMER_SINK_WAIT_CAP, + PD_TIMER_PS_SOURCE_OFF, + PD_TIMER_CC_DEBOUNCE, + PD_NUM_TIMERS +}; + +static u32 pd_timers[PD_NUM_TIMERS] = { + [PD_TIMER_SINK_WAIT_CAP] = PD_T_SINK_WAIT_CAP, + [PD_TIMER_PS_SOURCE_OFF] = PD_T_PS_SOURCE_OFF, + [PD_TIMER_CC_DEBOUNCE] = PD_T_CC_DEBOUNCE, +}; + #define tcpm_cc_is_sink(cc) \ ((cc) == TYPEC_CC_RP_DEF || (cc) == TYPEC_CC_RP_1_5 || \ (cc) == TYPEC_CC_RP_3_0) @@ -4601,7 +4626,7 @@ static void run_state_machine(struct tcpm_port *port) { int ret; enum typec_pwr_opmode opmode; - unsigned int msecs; + unsigned int msecs, timer_val_msecs; enum tcpm_state upcoming_state; if (port->tcpc->check_contaminant && port->state != CHECK_CONTAMINANT) @@ -4637,17 +4662,18 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK); break; case SRC_ATTACH_WAIT: + timer_val_msecs = pd_timers[PD_TIMER_CC_DEBOUNCE]; if (tcpm_port_is_debug(port)) tcpm_set_state(port, DEBUG_ACC_ATTACHED, - PD_T_CC_DEBOUNCE); + timer_val_msecs); else if (tcpm_port_is_audio(port)) tcpm_set_state(port, AUDIO_ACC_ATTACHED, - PD_T_CC_DEBOUNCE); + timer_val_msecs); else if (tcpm_port_is_source(port) && port->vbus_vsafe0v) tcpm_set_state(port, tcpm_try_snk(port) ? SNK_TRY : SRC_ATTACHED, - PD_T_CC_DEBOUNCE); + timer_val_msecs); break; case SNK_TRY: @@ -4698,7 +4724,7 @@ static void run_state_machine(struct tcpm_port *port) } break; case SRC_TRYWAIT_DEBOUNCE: - tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE); + tcpm_set_state(port, SRC_ATTACHED, pd_timers[PD_TIMER_CC_DEBOUNCE]); break; case SRC_TRYWAIT_UNATTACHED: tcpm_set_state(port, SNK_UNATTACHED, 0); @@ -4896,12 +4922,13 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC); break; case SNK_ATTACH_WAIT: + timer_val_msecs = pd_timers[PD_TIMER_CC_DEBOUNCE]; if ((port->cc1 == TYPEC_CC_OPEN && port->cc2 != TYPEC_CC_OPEN) || (port->cc1 != TYPEC_CC_OPEN && port->cc2 == TYPEC_CC_OPEN)) tcpm_set_state(port, SNK_DEBOUNCED, - PD_T_CC_DEBOUNCE); + timer_val_msecs); else if (tcpm_port_is_disconnected(port)) tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE); @@ -4941,7 +4968,7 @@ static void run_state_machine(struct tcpm_port *port) break; case SNK_TRYWAIT: tcpm_set_cc(port, TYPEC_CC_RD); - tcpm_set_state(port, SNK_TRYWAIT_VBUS, PD_T_CC_DEBOUNCE); + tcpm_set_state(port, SNK_TRYWAIT_VBUS, pd_timers[PD_TIMER_CC_DEBOUNCE]); break; case SNK_TRYWAIT_VBUS: /* @@ -5014,7 +5041,7 @@ static void run_state_machine(struct tcpm_port *port) break; case SNK_DISCOVERY_DEBOUNCE: tcpm_set_state(port, SNK_DISCOVERY_DEBOUNCE_DONE, - PD_T_CC_DEBOUNCE); + pd_timers[PD_TIMER_CC_DEBOUNCE]); break; case SNK_DISCOVERY_DEBOUNCE_DONE: if (!tcpm_port_is_disconnected(port) && @@ -5032,6 +5059,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, SNK_READY, 0); break; } + timer_val_msecs = pd_timers[PD_TIMER_SINK_WAIT_CAP]; /* * If VBUS has never been low, and we time out waiting * for source cap, try a soft reset first, in case we @@ -5041,10 +5069,10 @@ static void run_state_machine(struct tcpm_port *port) if (port->vbus_never_low) { port->vbus_never_low = false; tcpm_set_state(port, SNK_SOFT_RESET, - PD_T_SINK_WAIT_CAP); + timer_val_msecs); } else { tcpm_set_state(port, SNK_WAIT_CAPABILITIES_TIMEOUT, - PD_T_SINK_WAIT_CAP); + timer_val_msecs); } break; case SNK_WAIT_CAPABILITIES_TIMEOUT: @@ -5054,7 +5082,7 @@ static void run_state_machine(struct tcpm_port *port) * sending Source Capability messages after a soft reset. The * specification suggests to do a hard reset when no Source * capability message is received within PD_T_SINK_WAIT_CAP, - * but that might effectively kil the machine's power source. + * but that might effectively kill the machine's power source. * * This slightly diverges from the specification and tries to * recover from this by explicitly asking for the capabilities @@ -5066,7 +5094,8 @@ static void run_state_machine(struct tcpm_port *port) if (tcpm_pd_send_control(port, PD_CTRL_GET_SOURCE_CAP, TCPC_TX_SOP)) tcpm_set_state_cond(port, hard_reset_state(port), 0); else - tcpm_set_state(port, hard_reset_state(port), PD_T_SINK_WAIT_CAP); + tcpm_set_state(port, hard_reset_state(port), + pd_timers[PD_TIMER_SINK_WAIT_CAP]); break; case SNK_NEGOTIATE_CAPABILITIES: port->pd_capable = true; @@ -5203,7 +5232,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, ACC_UNATTACHED, 0); break; case AUDIO_ACC_DEBOUNCE: - tcpm_set_state(port, ACC_UNATTACHED, PD_T_CC_DEBOUNCE); + tcpm_set_state(port, ACC_UNATTACHED, pd_timers[PD_TIMER_CC_DEBOUNCE]); break; /* Hard_Reset states */ @@ -5420,7 +5449,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, ERROR_RECOVERY, 0); break; case FR_SWAP_SNK_SRC_TRANSITION_TO_OFF: - tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_OFF); + tcpm_set_state(port, ERROR_RECOVERY, pd_timers[PD_TIMER_PS_SOURCE_OFF]); break; case FR_SWAP_SNK_SRC_NEW_SINK_READY: if (port->vbus_source) @@ -5475,7 +5504,7 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_cc(port, TYPEC_CC_RD); /* allow CC debounce */ tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF_CC_DEBOUNCED, - PD_T_CC_DEBOUNCE); + pd_timers[PD_TIMER_CC_DEBOUNCE]); break; case PR_SWAP_SRC_SNK_SOURCE_OFF_CC_DEBOUNCED: /* @@ -5510,7 +5539,7 @@ static void run_state_machine(struct tcpm_port *port) port->pps_data.active, 0); tcpm_set_charge(port, false); tcpm_set_state(port, hard_reset_state(port), - PD_T_PS_SOURCE_OFF); + pd_timers[PD_TIMER_PS_SOURCE_OFF]); break; case PR_SWAP_SNK_SRC_SOURCE_ON: tcpm_enable_auto_vbus_discharge(port, true); @@ -5666,7 +5695,7 @@ static void run_state_machine(struct tcpm_port *port) case PORT_RESET_WAIT_OFF: tcpm_set_state(port, tcpm_default_state(port), - port->vbus_present ? PD_T_PS_SOURCE_OFF : 0); + port->vbus_present ? pd_timers[PD_TIMER_PS_SOURCE_OFF] : 0); break; /* AMS intermediate state */ @@ -6157,7 +6186,7 @@ static void _tcpm_pd_vbus_vsafe0v(struct tcpm_port *port) case SRC_ATTACH_WAIT: if (tcpm_port_is_source(port)) tcpm_set_state(port, tcpm_try_snk(port) ? SNK_TRY : SRC_ATTACHED, - PD_T_CC_DEBOUNCE); + pd_timers[PD_TIMER_CC_DEBOUNCE]); break; case SRC_STARTUP: case SRC_SEND_CAPABILITIES: @@ -7273,6 +7302,47 @@ static int tcpm_fw_get_snk_vdos(struct tcpm_port *port, struct fwnode_handle *fw return 0; } +static int tcpm_fw_get_pd_timers(struct tcpm_port *port, struct fwnode_handle *fwnode) +{ + int ret, i, len; + u32 *buf; + + /* pd-timers is an optional property */ + ret = fwnode_property_count_u32(fwnode, "pd-timers"); + if (ret < 0) { + tcpm_log(port, "Unable to locate 'pd-timers' connector property (%d)", ret); + return 0; + } + + if (ret % NUM_TIMER_TABLE_COLS || ret == 0) { + tcpm_log(port, "Incorrect 'pd-timers' value. Found %d u32 elements in array", ret); + return 0; + } + + len = min(ret, PD_NUM_TIMERS * NUM_TIMER_TABLE_COLS); + + buf = kcalloc(len, sizeof(*buf), GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = fwnode_property_read_u32_array(fwnode, "pd-timers", buf, len); + if (ret) { + dev_err(port->dev, "Unable to read pd-timers property (%d)", ret); + goto done; + } + + for (i = 0; i < len - 1; i += NUM_TIMER_TABLE_COLS) { + if (buf[i] >= PD_NUM_TIMERS) + tcpm_log(port, "Unable to find timer index %d, skipping.", buf[i]); + else + pd_timers[buf[i]] = buf[i + 1]; + } + +done: + kfree(buf); + return ret; +} + /* Power Supply access to expose source power information */ enum tcpm_psy_online_states { TCPM_PSY_OFFLINE = 0, @@ -7608,6 +7678,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) init_completion(&port->pps_complete); tcpm_debugfs_init(port); + err = tcpm_fw_get_pd_timers(port, tcpc->fwnode); + if (err) + goto out_destroy_wq; + err = tcpm_fw_get_caps(port, tcpc->fwnode); if (err < 0) goto out_destroy_wq;