From patchwork Sat Sep 23 07:39:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp156735vqu; Sat, 23 Sep 2023 05:49:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEodzq9k0A5g3XwP3sVyeUCLmGpHFMFqxe1R8A6ld/QRlz6l67bqAH17uPTjrGXL8qE42vD X-Received: by 2002:a05:6a20:1451:b0:157:b453:dbb9 with SMTP id a17-20020a056a20145100b00157b453dbb9mr2130475pzi.6.1695473393898; Sat, 23 Sep 2023 05:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695473393; cv=none; d=google.com; s=arc-20160816; b=rkoszdZ+3tArHZzQ+K9YAhRKE1KnlKFrp6OGRVeECYa8QG1s6u8oTpXVrpLGiCDj8G A/AbfXIB1Xg/+cQnaTtspaVFcyllYYeUQCKg7g7u+/TDm4y2qpmZcfjgTyZZx/EAuu46 zgyAgB3y7kUGByCFdmiIMDWxvAKnL6vn36ApdWMIuyukjelUmwA3WABZfftnFiOs1yc/ epbf8Ss5Q/SlT03ie6Uxjx/2QeUBOnd1IfiKO2JJgM1RMGihLTq9NlxcFa2ipTWjSlL3 ZaPexOMSvNIS9Wz3GcrVt9YDFlP8+qOThIB7aGN97gM7GFjRxvo3sc1ptjpgndKLlPql qk2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YKrPJWkjEs+cK0uLXs72u7EPbOGJFSfMi3rQJfH1tGU=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=LeJmE0poX9QL9C8R/BBF3w5uUx35NNGTAbNoZ2FBu45gQQxasO2f8tdlmRpNLpqJ51 K1JSJMg50MH5ROyVqAyru6QrUKRxQUw9cJnJ9au+f6yNnw+xRusbs6N6w34eGAVmwu1m PKU0Fe4njfLqlKgcGji5RMZZyIUh9USTxiPN3l7+6KDovqp9kqdxAX9+Fg9JYT1IOgZo b43NbazUu/cpopFbA0aUZu/z/GpJUoYCyxoubMP9Lc56SW6RvAWkWRNY/gZr2U1IlxSM 0eju3zW6EwxqFEF8Wy4aLdkol12DQXPxBCZ1mTaSWNqzpWHM8pGXes7tYSTGptbxjWV5 qsjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XpXotixH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id t19-20020a17090a951300b002748c1bbd79si8376711pjo.6.2023.09.23.05.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 05:49:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XpXotixH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 54060826EBA6; Sat, 23 Sep 2023 00:40:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbjIWHkx (ORCPT + 29 others); Sat, 23 Sep 2023 03:40:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjIWHkr (ORCPT ); Sat, 23 Sep 2023 03:40:47 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1272C198; Sat, 23 Sep 2023 00:40:37 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31fe2c8db0dso2914513f8f.3; Sat, 23 Sep 2023 00:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454835; x=1696059635; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YKrPJWkjEs+cK0uLXs72u7EPbOGJFSfMi3rQJfH1tGU=; b=XpXotixH/ksLEUKAvx6sE9Ol2rUjmpxU2HR4eyOakFDtWu9vljhafL8BZwt7KceT59 idMdabsIse9xos+jA/3cokT7Hmp/nYgw2+Gx8THBwfZXogtueZHgebwswFEJ2f89KMCv qwo+54aOUpEjSPwqsIDu1fGbuw3TmuKHiySjVoVNpoFhMiuoq1kIzwGeZLqqmkYQ0RGH m6pIzG+jVqt/eRn6oSqsRryktX4X77hwLSMHvIXLU5nxGA7T2H6N8hxpHhrzZryMZ4Jv 8QDlpG2zmp6qIDgqSJr0xXgnIT4WqmZSwCpYRBh0XX1LkX+zOahwqk0PJx2dElI8KU5x YZKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454835; x=1696059635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YKrPJWkjEs+cK0uLXs72u7EPbOGJFSfMi3rQJfH1tGU=; b=HkrnCJdK0CpdKqidPK/txgrxGEucwNIg5gIGzQNJkdAOF/XYTlGn4NS3JzLwetT2ZV 5oZx2o/5eX7hFIK5sMiM+9cxL0XRxfWPXmzxtY8tHRwqGrnz/4Tgx2m7Pp0wDuAa5xcq ygwN1QFvNxy8BLefESpc+KAb7pKw8Dq7CnhaPvmYdXPtmTzke4QVcF9+qLGBPwKI/28y y3+TCxC1EOeAsgIKwlgV7OqPxXR58KsGhl7ZWrC8fDMtX/KsRRrvDsbSN+zb09WCUbL/ eT9nADR/h9T4I41xsfuAlBEHjX97klxGfbINB0S3XxSoN0OOMbITslxFHNfcnNVPewjF BpJA== X-Gm-Message-State: AOJu0YyqwJ2o7LnYL9wFH+b0p5+vAOdn7ChaV3lGWv70dbEGfsxjbATp MQzyNc1TCRSWeRxRVp2xC58= X-Received: by 2002:a05:6000:819:b0:323:1689:6607 with SMTP id bt25-20020a056000081900b0032316896607mr1557349wrb.5.1695454835447; Sat, 23 Sep 2023 00:40:35 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:35 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 01/14] dt-bindings: usb: tps6598x: Add tps25750 Date: Sat, 23 Sep 2023 03:39:46 -0400 Message-Id: <20230923073959.86660-2-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:40:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777828914805391143 X-GMAIL-MSGID: 1777832709375022082 From: Abdel Alkuor TPS25750 is USB TypeC PD controller which is a subset of TPS6598x. Signed-off-by: Abdel Alkuor --- Changes in v6: - Use reg property for patch address Changes in v5: - Add tps25750 bindings .../devicetree/bindings/usb/ti,tps6598x.yaml | 80 ++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml b/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml index 5497a60cddbc..da299a2bb19e 100644 --- a/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml +++ b/Documentation/devicetree/bindings/usb/ti,tps6598x.yaml @@ -20,8 +20,7 @@ properties: enum: - ti,tps6598x - apple,cd321x - reg: - maxItems: 1 + - ti,tps25750 wakeup-source: true @@ -32,10 +31,55 @@ properties: items: - const: irq + firmware-name: + description: | + Should contain the name of the default patch binary + file located on the firmware search path which is + used to switch the controller into APP mode. + This is used when tps25750 doesn't have an EEPROM + connected to it. + maxItems: 1 + required: - compatible - reg +allOf: + - if: + properties: + compatible: + contains: + const: ti,tps25750 + then: + properties: + reg: + maxItems: 2 + + reg-names: + description: | + The first reg is PD device address and the second + reg is I2C slave address field in PBMs input data + which is used as the device address when writing the + patch for TPS25750. + The patch address can be any value except 0x00, 0x20, + 0x21, 0x22, and 0x23 + items: + - const: main + - const: patch-address + + connector: + required: + - data-role + + required: + - connector + - reg-names + else: + properties: + reg: + maxItems: 1 + + additionalProperties: true examples: @@ -68,4 +112,36 @@ examples: }; }; }; + + - | + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + + typec@21 { + compatible = "ti,tps25750"; + reg = <0x21>, <0x0f>; + reg-names = "main", "patch-address"; + + interrupt-parent = <&msmgpio>; + interrupts = <100 IRQ_TYPE_LEVEL_LOW>; + interrupt-names = "irq"; + firmware-name = "tps25750.bin"; + + pinctrl-names = "default"; + pinctrl-0 = <&typec_pins>; + + typec_con0: connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + port { + typec_ep0: endpoint { + remote-endpoint = <&otg_ep>; + }; + }; + }; + }; + }; ... From patchwork Sat Sep 23 07:39:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 144314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1075755vqu; Mon, 25 Sep 2023 02:13:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGA3vUkDwYiWQFsQMEKF7gRHU+oyCP3DU67vOSIVt52hJEM/hp5nWqeqoYUguNcXmpZrkSp X-Received: by 2002:a17:902:c94b:b0:1bb:ee1b:3cdf with SMTP id i11-20020a170902c94b00b001bbee1b3cdfmr4952069pla.67.1695633207530; Mon, 25 Sep 2023 02:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695633207; cv=none; d=google.com; s=arc-20160816; b=QGXXrNnWwmz5+VvQVRzW+alnQKgrRNDT/aDuqcdVACyjCo5PazJZohgs63kmUuCBW1 QbuK1IhDLUYrKyVOXjKOz+skZfrmT8J2vyrqLAkZ4yjf5W6aKzLZlCxbsnRe4D+8Z5kY Y6TesJo/kTyeK2McARTYNVdjWAWrr1W8cqyp35XENTtrKEaEgPoTwNr3YMhVMT3q0AqZ OJWMihTOgrXOGnWqqfJ41r+J3VXMJpRerwlQBBwzV45rvjVyvUu6R+QvyI2qkh0/rumm kdEwiElmhYup9oagpQogB5J1SJ/V3u7tBqHCr76HBVFLMFTNLfmM6LRRWlwMgKde2eQP YS/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mZWmQQmneNrgo+uT9K5V7AmPeAEWKJEhNBsXkP/XAfI=; fh=mMxHbh++PLXAKOMBGwJldjeTt2C4rRu3y2RX0ZZ/MOI=; b=ofuGdPVWzmM/jyDmfAfmY2FJDJ+sPo4U3V2HXtX5DdAaiB/c/Gr1hRI/Fa6pUXdkTL TILkbeK9/ut3RXVHj5XaSzQV/dq/os8KPfjmowdLLfppjnjVuKJ2j1rbeSYjgLxrS923 DdZaYEa72YPhkf7sewEpfNH+Em+ZVGRD9a18rupgnrfXxhzTr9ZR5eYpEXoirx61+GZH B9OCjImCkMxfFKt0G1VuKHc0wvbkwrO+Vq2Sx0cj4aMApQ9LEJ2D4vRSdm28qaHBg8Hd zwkTc9+MSpO8FUfCYkvotEy9rEOqrY9Frp6mxSgQZhzPqKrw409NL3rWdz1W5YWFqDyD vqBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RyaFFldn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j6-20020a170903024600b001c470c5906bsi10049661plh.221.2023.09.25.02.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 02:13:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RyaFFldn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C22BD835B4D6; Sat, 23 Sep 2023 00:41:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230215AbjIWHkw (ORCPT + 29 others); Sat, 23 Sep 2023 03:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbjIWHkr (ORCPT ); Sat, 23 Sep 2023 03:40:47 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2187199; Sat, 23 Sep 2023 00:40:38 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-405505b07dfso5841065e9.0; Sat, 23 Sep 2023 00:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454837; x=1696059637; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mZWmQQmneNrgo+uT9K5V7AmPeAEWKJEhNBsXkP/XAfI=; b=RyaFFldnJLF5ccfr/zjHocKQ8+Gt01VEDseNmbdQ3ZkRh7G3bzIi6MFO++dpmwFHS3 G1SIyVoNz3OwVnS0tYWKH347XNYXatUcMro76kX+yMIBtnrWOh8bPewG9ELez8knM7XX FGGUEY9/K5PRvJJUaRF8OR5+L91UrIXVV/FcYIFv1zZ+U8gk6cZhYnQ7TS4HTGnFLsAf Xe0A5Su4MrKGih3T1Rxbj8kmLKVJ2h/IX7e7p3m0lc1sDBwSXRHJOgkEc+kV457Cwl5j AL/DwV7O7TkDE/7i90tKyRnGOJXNnBzyJ1mFBFbLGTWCckasqR3bZdhag8VQSxHxOgA3 Parg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454837; x=1696059637; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mZWmQQmneNrgo+uT9K5V7AmPeAEWKJEhNBsXkP/XAfI=; b=aiyMb3r9ae2BVEMH/bP5CtBfqGkwOGeG/jwWS6t/c524jLMVHtgGzC2wmpcTo6jShJ RoL5wFzPmjEzgDhWXG6LtFyIzoZdF/4q0IY38aWebZIBcfJE/E7rnINNxJuGVMfGtbh6 SUiCXaKKMAfGu5bo24Ne0HN3ahZYwyfsMLQCmbLm61Yu91AlAWJJween0Pc7XgyUwZln wLGhNqCnoxKO7E9Aw1p8NMIRYqB8kumqfBULLsvqEDkEfYQwQh5oTjZq1XVaCk2oLgyY gSGPdBeqY4Lj3IxUMongJN6E1ewAQu5ucIEglyFOrgv0NtypmD+6zXRu5ENmTDTxfrcp 3B0Q== X-Gm-Message-State: AOJu0YwcfrVm5UB4D9A/WP10wsN7jAJjglPHULuXHaw4apgStbNc0MwS W0qAuy9oXaPvP4mHRvr81oA= X-Received: by 2002:a05:600c:450:b0:402:ebe1:7960 with SMTP id s16-20020a05600c045000b00402ebe17960mr1148778wmb.2.1695454837199; Sat, 23 Sep 2023 00:40:37 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:36 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 02/14] USB: typec: Add cmd timeout and response delay Date: Sat, 23 Sep 2023 03:39:47 -0400 Message-Id: <20230923073959.86660-3-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:41:01 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778000286354020346 X-GMAIL-MSGID: 1778000286354020346 Some commands in tps25750 take longer than 1 second to complete, and some responses need some delay before the result becomes available. Signed-off-by: Abdel Alkuor Reviewed-by: Heikki Krogerus --- Changes in v6: - Use tps6598x_exec_cmd as a wrapper Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 37b56ce75f39..32420c61660d 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -282,9 +282,10 @@ static void tps6598x_disconnect(struct tps6598x *tps, u32 status) power_supply_changed(tps->psy); } -static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, +static int tps6598x_exec_cmd_tmo(struct tps6598x *tps, const char *cmd, size_t in_len, u8 *in_data, - size_t out_len, u8 *out_data) + size_t out_len, u8 *out_data, + u32 cmd_timeout_ms, u32 res_delay_ms) { unsigned long timeout; u32 val; @@ -307,8 +308,7 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, if (ret < 0) return ret; - /* XXX: Using 1s for now, but it may not be enough for every command. */ - timeout = jiffies + msecs_to_jiffies(1000); + timeout = jiffies + msecs_to_jiffies(cmd_timeout_ms); do { ret = tps6598x_read32(tps, TPS_REG_CMD1, &val); @@ -321,6 +321,9 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, return -ETIMEDOUT; } while (val); + /* some commands require delay for the result to be available */ + mdelay(res_delay_ms); + if (out_len) { ret = tps6598x_block_read(tps, TPS_REG_DATA1, out_data, out_len); @@ -345,6 +348,14 @@ static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, return 0; } +static int tps6598x_exec_cmd(struct tps6598x *tps, const char *cmd, + size_t in_len, u8 *in_data, + size_t out_len, u8 *out_data) +{ + return tps6598x_exec_cmd_tmo(tps, cmd, in_len, in_data, + out_len, out_data, 1000, 0); +} + static int tps6598x_dr_set(struct typec_port *port, enum typec_data_role role) { const char *cmd = (role == TYPEC_DEVICE) ? "SWUF" : "SWDF"; From patchwork Sat Sep 23 07:39:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143849 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp60030vqu; Sat, 23 Sep 2023 01:45:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMgPQon6nEN5PCsa/0KmcyruJEzWsTOjo6YruvL1/cRQ8q2s5FEYnnmHM33L4eAP06bW8Y X-Received: by 2002:a05:6a20:2589:b0:13a:dd47:c31a with SMTP id k9-20020a056a20258900b0013add47c31amr6572430pzd.20.1695458752869; Sat, 23 Sep 2023 01:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695458752; cv=none; d=google.com; s=arc-20160816; b=C+fLCLIHVnMQOwineumFnnrldv1vgYnNcJA/1QW4y7lM+aOZBrQhKvzNYBtLrREDPD rfDBiH1KIskP7bbXD/qDH8MUE2nC7sbAAXOzBliswqp6t7UZifRl1jEaKvUnDWnMDgP3 KobB2y850lyzbkXK44j2JyzcZBNFsLnFx0+34hkMAB3FJzA/R66KLub2jLUF4wZapxrx 7N+Q/KQVsTZ0638S8CvkMZDxh1BofmZdgiCWBVbPfvYxRjTKzf4I/SNW7PV+MgjR8CcF NJ2vuEONNJAzV5EByZaYyhMxS8hpl+pcWRCUKMF9OvXISNfLalBQcLZmn6jiTfW98/QE 3ujg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a5WaQghfdBPPUPM6BGBEffjVf/GTvuPkbvL3qgXS12Q=; fh=mMxHbh++PLXAKOMBGwJldjeTt2C4rRu3y2RX0ZZ/MOI=; b=aoFz7KIywFjD3lM6S4Bid8LaaScmIu82uYysjPWzRUIgusE7xt4oiLtTuuwJkIWG3h ofbzkvKM+nQySxKG20BrlNfuniLrHfQ1me6slHLXTtZzk3DHeHSBKLCPPxpykaOT7893 Dktv2kEHO2/G2Zuqq0rxb+nnROdfE53+QPStViDIFyq6MITeCurIemE2CaljfBBuCQVu DuErnXMp1trIvS8n/yvvnNtg7N1M4Zeu4exLkT6CqgThYAA8F7BEtRGiYKG5IhLuw9dA wNY2Shdimn6ThUqEhvvcjAgHKP5e3qO2EbbzXWL155/EEGvbJkJrnbk+bWHcf5w95egY xDnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="jle+5t/6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x71-20020a63864a000000b0057d7cff25b8si2552449pgd.198.2023.09.23.01.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 01:45:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="jle+5t/6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 22095835B4E0; Sat, 23 Sep 2023 00:41:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbjIWHkz (ORCPT + 29 others); Sat, 23 Sep 2023 03:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjIWHks (ORCPT ); Sat, 23 Sep 2023 03:40:48 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBE419E; Sat, 23 Sep 2023 00:40:40 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-323168869daso727110f8f.2; Sat, 23 Sep 2023 00:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454839; x=1696059639; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a5WaQghfdBPPUPM6BGBEffjVf/GTvuPkbvL3qgXS12Q=; b=jle+5t/6LOQmDrv2I7O//erp3l225mtdhWseTgfo/I0obBfZtRRRiMdRhUFUIifN1V Dnc3Yo9X8MSLckYjppF3X88Q7JADdz4RuJJYQG0efQQB5aLXVPkO3ojOdXlFbAGfMTU0 0nuFxDiPrzYgjGliDiTUb6j0G2tM/zPtYgPoM0OSKQhoGlV/LFrN2qi1GPxmxKYTXYIl OUqmwEupkY+X/lB8w3v+4K2EkNNRH+yfevBoO6ugRLmCC7aEwA8jYi2kyB1qhWTpcVBv mBnbQmrOFX+PgjcHuD35f7QcmpHYl2L1sB7AK9oUzxbcOJvrnIb92BIvMVcujdS0l2bj 9Snw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454839; x=1696059639; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a5WaQghfdBPPUPM6BGBEffjVf/GTvuPkbvL3qgXS12Q=; b=sauF0ALJaPCjsj1CzdW81ZjQ0dzWBH2nMA4H2Uiz/+J0NQQkuVd1VRRavrFqgTA3dK 2q13GpjNS7dZd+fg48XRxhH2K6HQFXN5ivWNquJJKnrNVE/ku2sFfAphtJM53QStxsKH puiIH3AjNZ43RtfzlVAkMApAglbAKet07Nj62ewpv6ZkFx9+39TZQA2KpfMexBXJmZuE ADlT99S7t+RlwC25P26TOrQJO/A8wOuYSqyMCfe02hfynjSbd0O6oKlJxMpZghpLLFCJ kcmnRS6cIP6fm1+yHBc0BUmh4nEa1HbOyx87085nAA9080TODmSTOBauegASlyM0K6Ig ExVg== X-Gm-Message-State: AOJu0YxdfANImwPUF1xBn4opwffE0g/880if+EhN7/p72SYn+1UVq3IJ ocJgx/aWbP5AWrguv2rgDZ0= X-Received: by 2002:a05:6000:51:b0:319:77dd:61f9 with SMTP id k17-20020a056000005100b0031977dd61f9mr1437890wrx.35.1695454839065; Sat, 23 Sep 2023 00:40:39 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:38 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 03/14] USB: typec: Add patch mode to tps6598x Date: Sat, 23 Sep 2023 03:39:48 -0400 Message-Id: <20230923073959.86660-4-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:41:06 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777817357163197713 X-GMAIL-MSGID: 1777817357163197713 TPS25750 has a patch mode indicating the device requires a configuration to get the device into operational mode Signed-off-by: Abdel Alkuor --- Changes in v6: - Return current mode and check it directly Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 32420c61660d..58679b1c0cfe 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -68,6 +68,7 @@ enum { TPS_MODE_BOOT, TPS_MODE_BIST, TPS_MODE_DISC, + TPS_MODE_PTCH, }; static const char *const modes[] = { @@ -75,6 +76,7 @@ static const char *const modes[] = { [TPS_MODE_BOOT] = "BOOT", [TPS_MODE_BIST] = "BIST", [TPS_MODE_DISC] = "DISC", + [TPS_MODE_PTCH] = "PTCH", }; /* Unrecognized commands will be replaced with "!CMD" */ @@ -593,12 +595,15 @@ static int tps6598x_check_mode(struct tps6598x *tps) if (ret) return ret; - switch (match_string(modes, ARRAY_SIZE(modes), mode)) { + ret = match_string(modes, ARRAY_SIZE(modes), mode); + + switch (ret) { case TPS_MODE_APP: - return 0; + case TPS_MODE_PTCH: + return ret; case TPS_MODE_BOOT: dev_warn(tps->dev, "dead-battery condition\n"); - return 0; + return ret; case TPS_MODE_BIST: case TPS_MODE_DISC: default: @@ -765,7 +770,7 @@ static int tps6598x_probe(struct i2c_client *client) tps->irq_handler = irq_handler; /* Make sure the controller has application firmware running */ ret = tps6598x_check_mode(tps); - if (ret) + if (ret < 0) return ret; ret = tps6598x_write64(tps, TPS_REG_INT_MASK1, mask1); From patchwork Sat Sep 23 07:39:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp204749vqu; Sat, 23 Sep 2023 07:20:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsNiNArOJC9lKcixNM637j1iduBT+vt4kyxvZWbDv4oNgGMjVWym2xGZs2YWDuZFlf/bFV X-Received: by 2002:a05:6a00:1819:b0:690:25fb:bac1 with SMTP id y25-20020a056a00181900b0069025fbbac1mr2352559pfa.18.1695478828076; Sat, 23 Sep 2023 07:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695478828; cv=none; d=google.com; s=arc-20160816; b=Qt5/gL3tC44BbbG06jv7MY9j8YpqD1gZc68OOAx3Ec+kAIUOl9zgzc/f1wBKZ8lKcU Zu8fbnQhyU3uznHSSqOCqJisesi3XfuNchnNnHODz+bne9LiEt/WNO+HxWioybY6TY5x YYNKGZZDaqBJM4BP0BHgjUcoA4klr6MndZ04j1Svi9NsNgo6Ms1Atm5dze8iTFE9GElY VHHphbQnzVHunuQNhZgvg0QWcBbWcytqfjpS2ghggjKp0hWu5MlbjZZQ6PvIpWGStA8r OxWTfJbCO+j6DlxLEXxMnt5gfAjB42/IrfTrguDLogz2W0C5Xh4hirruHg316XvK5xuS N7Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8QbsBb7NU6XXzk13/XY8v33tLESBOIobB3qLem/J4eU=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=xSnq9rYXuq9TX6WZFw2Kg61uTcsqQgO7pTjrwoLeoApYHSAUCj6VqCSswi+ejFt5G7 4/Jz35Z78ovLEtSKFPp3AhUS83Ff+q91iSuETmQ9FkT8JY8to4gQiN2Fk0P4mJTWTWgt RXkdYp2UXWnFzfW/UV9qvg2UlCbMvu5p2cH2VxB6bu0WVWgzYdm1J+zC0z3JyMDLDgXG KvONDGinAW+SHPK9mFSt6DrmFRj/BR2rAGMfr+oUJnG0SpSUCn3URgUMdmwbNWR35q24 0OBrkrE//j8E/XxoHGFzJ8vwRhVqNnJwgjACdNSGfzmsA0lSHTnyC94BeQhtDWAavW18 BnaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PhVT0ZIB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id y1-20020a636401000000b00578c914490bsi6196597pgb.494.2023.09.23.07.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 07:20:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PhVT0ZIB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DC1888158EAD; Sat, 23 Sep 2023 00:41:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbjIWHlA (ORCPT + 29 others); Sat, 23 Sep 2023 03:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbjIWHkt (ORCPT ); Sat, 23 Sep 2023 03:40:49 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95162196; Sat, 23 Sep 2023 00:40:42 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-405621baba7so2331145e9.0; Sat, 23 Sep 2023 00:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454841; x=1696059641; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8QbsBb7NU6XXzk13/XY8v33tLESBOIobB3qLem/J4eU=; b=PhVT0ZIBhMJ1EqR0xtCU/uaPg3/6gnthmlkytaeGZRcqsCbTxKIdIaDbmkONIXm/qJ LcY2UHUwhPoVnj9BiyjMpThhRQwxBFwq2RAg6HFGnfPpXJLg8Q/fx5q9RVM5ThMusEpw tcFN581vPPluuZaS32zGIYDVaoLGMdrmjulYE93DW8vnJUq/ZaZU5PP8kWD4R+fwYfQe bySLLrLQspbJlucQpV24dSd6FCom03INEbVTW8j4a9TiLjJTA6iXVVHE4z+hGJkOyRTq tXLXC30YWix3m1+XA1j1rNa16NxFi4Hmb2UDeIu1h1nQ/7VxaJU+hXIiVuCPdsvejWB7 JrCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454841; x=1696059641; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8QbsBb7NU6XXzk13/XY8v33tLESBOIobB3qLem/J4eU=; b=Oyl0h2LSmakRRVIzuBeCrdnxESVXy8uYt7pqL1D6knuvQ79EHgDbGOHfWQ15sEvWBL 31hgYP4DK5XQr+9njCK/owTzSmDT0+nBW7SGMBpgMtb9a4zIGybU1yeBuZreL4JCkOSa uE0rDbHxTwu2TXSmndcbjuv/XEW5GyiMrz/8muDv9wR4lifZFnv3tzDeAWs3kqf+rZKx c/F9cRTkheKTRERetAGrEFb0sEBaUqpL/UVbgWCdI0ExoDZNXq3khMDZDrQvd4tbVVxr laFX9miGyDLgoQHmKVXykLLEaK0SsGKTH4S9idbWDp9EdqGbDDad2fZDN5MZRYyHkJGe bqmg== X-Gm-Message-State: AOJu0Yz7/IZfrqKXJU9fZ1xddkg9v9y1zsk43Y9Yft8MhQnbgsHHDAFG d0YvuFALkW54cBuzAAVqCAE= X-Received: by 2002:a5d:634f:0:b0:314:15b7:20a5 with SMTP id b15-20020a5d634f000000b0031415b720a5mr1381416wrw.54.1695454840952; Sat, 23 Sep 2023 00:40:40 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:40 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 04/14] USB: typec: Load TPS25750 patch bundle Date: Sat, 23 Sep 2023 03:39:49 -0400 Message-Id: <20230923073959.86660-5-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:41:22 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777838407879773572 X-GMAIL-MSGID: 1777838407879773572 From: Abdel Alkuor TPS25750 controller requires a binary to be loaded with a configuration binary by an EEPROM or a host. Appling a patch bundling using a host is implemented based on the flow diagram pg.62 in TPS25750 host interface manual. https://www.ti.com/lit/ug/slvuc05a/slvuc05a.pdf The flow diagram can be summarized as following: - Start the patch loading sequence with patch bundle information by executing PBMs - Write the whole patch at once - When writing the patch fails, execute PBMe which instructs the PD controller to end the patching process - After writing the patch successfully, execute PBMc which verifies the patch integrity and applies the patch internally - Wait for the device to switch into APP mode (normal operation) The execuation flow diagram polls the events register and then polls the corresponding register related to the event as well before advancing to the next state. Polling the events register is a redundant step, in this implementation only the corresponding register related to the event is polled. Signed-off-by: Abdel Alkuor --- Changes in v6: - Don't check VID for tps25750 as the VID register doesn't exist - Remove is_tps25750 flag from tps6598x struct - Get patch address from reg property Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 254 +++++++++++++++++++++++++++++++++- 1 file changed, 250 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 58679b1c0cfe..7e91cf488557 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "tps6598x.h" #include "trace.h" @@ -43,6 +44,23 @@ /* TPS_REG_SYSTEM_CONF bits */ #define TPS_SYSCONF_PORTINFO(c) ((c) & 7) +/* + * BPMs task timeout, recommended 5 seconds + * pg.48 TPS2575 Host Interface Technical Reference + * Manual (Rev. A) + * https://www.ti.com/lit/ug/slvuc05a/slvuc05a.pdf + */ +#define TPS_BUNDLE_TIMEOUT 0x32 + +/* BPMs return code */ +#define TPS_TASK_BPMS_INVALID_BUNDLE_SIZE 0x4 +#define TPS_TASK_BPMS_INVALID_SLAVE_ADDR 0x5 +#define TPS_TASK_BPMS_INVALID_TIMEOUT 0x6 + +/* PBMc data out */ +#define TPS_PBMC_RC 0 /* Return code */ +#define TPS_PBMC_DPCS 2 /* device patch complete status */ + enum { TPS_PORTINFO_SINK, TPS_PORTINFO_SINK_ACCESSORY, @@ -713,6 +731,213 @@ static int devm_tps6598_psy_register(struct tps6598x *tps) return PTR_ERR_OR_ZERO(tps->psy); } +static int +tps25750_write_firmware(struct tps6598x *tps, + u8 bpms_addr, const u8 *data, size_t len) +{ + struct i2c_client *client = to_i2c_client(tps->dev); + int ret; + u8 slave_addr; + int timeout; + + slave_addr = client->addr; + timeout = client->adapter->timeout; + + /* + * binary configuration size is around ~16Kbytes + * which might take some time to finish writing it + */ + client->adapter->timeout = msecs_to_jiffies(5000); + client->addr = bpms_addr; + + ret = regmap_raw_write(tps->regmap, data[0], &data[1], len - 1); + + client->addr = slave_addr; + client->adapter->timeout = timeout; + + return ret; +} + +static int +tps25750_exec_pbms(struct tps6598x *tps, u8 *in_data, size_t in_len) +{ + int ret; + u8 rc; + + ret = tps6598x_exec_cmd_tmo(tps, "PBMs", in_len, in_data, + sizeof(rc), &rc, 4000, 0); + if (ret) + return ret; + + switch (rc) { + case TPS_TASK_BPMS_INVALID_BUNDLE_SIZE: + dev_err(tps->dev, "%s: invalid fw size\n", __func__); + return -EINVAL; + case TPS_TASK_BPMS_INVALID_SLAVE_ADDR: + dev_err(tps->dev, "%s: invalid slave address\n", __func__); + return -EINVAL; + case TPS_TASK_BPMS_INVALID_TIMEOUT: + dev_err(tps->dev, "%s: timed out\n", __func__); + return -ETIMEDOUT; + default: + break; + } + + return 0; +} + +static int tps25750_abort_patch_process(struct tps6598x *tps) +{ + int ret; + + ret = tps6598x_exec_cmd(tps, "PBMe", 0, NULL, 0, NULL); + if (ret) + return ret; + + ret = tps6598x_check_mode(tps); + if (ret != TPS_MODE_PTCH) + dev_err(tps->dev, "failed to switch to \"PTCH\" mode\n"); + + return ret; +} + +static int tps25750_start_patch_burst_mode(struct tps6598x *tps) +{ + int ret; + const struct firmware *fw; + const char *firmware_name; + struct { + u32 fw_size; + u8 addr; + u8 timeout; + } __packed bpms_data; + u32 addr; + struct device_node *np = tps->dev->of_node; + + ret = device_property_read_string(tps->dev, "firmware-name", + &firmware_name); + if (ret) + return ret; + + ret = request_firmware(&fw, firmware_name, tps->dev); + if (ret) { + dev_err(tps->dev, "failed to retrieve \"%s\"\n", firmware_name); + return ret; + } + + if (fw->size == 0) { + ret = -EINVAL; + goto release_fw; + } + + ret = of_property_match_string(np, "reg-names", "patch-address"); + if (ret < 0) { + dev_err(tps->dev, "failed to get patch-address %d\n", ret); + return ret; + } + + ret = of_property_read_u32_index(np, "reg", ret, &addr); + if (ret) + return ret; + + if (addr == 0 || (addr >= 0x20 && addr <= 0x23)) { + dev_err(tps->dev, "wrong patch address %u\n", addr); + return -EINVAL; + } + + bpms_data.addr = addr; + bpms_data.fw_size = fw->size; + bpms_data.timeout = TPS_BUNDLE_TIMEOUT; + + ret = tps25750_exec_pbms(tps, (u8 *)&bpms_data, sizeof(bpms_data)); + if (ret) + goto release_fw; + + ret = tps25750_write_firmware(tps, bpms_data.addr, fw->data, fw->size); + if (ret) { + dev_err(tps->dev, "failed to write patch %s of %zu bytes\n", + firmware_name, fw->size); + goto release_fw; + } + + /* + * A delay of 500us is required after the firmware is written + * based on pg.62 in tps6598x Host Interface Technical + * Reference Manual + * https://www.ti.com/lit/ug/slvuc05a/slvuc05a.pdf + */ + udelay(500); + +release_fw: + release_firmware(fw); + + return ret; +} + +static int tps25750_complete_patch_process(struct tps6598x *tps) +{ + int ret; + u8 out_data[40]; + u8 dummy[2] = { }; + + /* + * Without writing something to DATA_IN, this command would + * return an error + */ + ret = tps6598x_exec_cmd_tmo(tps, "PBMc", sizeof(dummy), dummy, + sizeof(out_data), out_data, 2000, 20); + if (ret) + return ret; + + if (out_data[TPS_PBMC_RC]) { + dev_err(tps->dev, + "%s: pbmc failed: %u\n", __func__, + out_data[TPS_PBMC_RC]); + return -EIO; + } + + if (out_data[TPS_PBMC_DPCS]) { + dev_err(tps->dev, + "%s: failed device patch complete status: %u\n", + __func__, out_data[TPS_PBMC_DPCS]); + return -EIO; + } + + return 0; +} + +static int tps25750_apply_patch(struct tps6598x *tps) +{ + int ret; + unsigned long timeout; + + ret = tps25750_start_patch_burst_mode(tps); + if (ret) { + tps25750_abort_patch_process(tps); + return ret; + } + + ret = tps25750_complete_patch_process(tps); + if (ret) + return ret; + + timeout = jiffies + msecs_to_jiffies(1000); + + do { + ret = tps6598x_check_mode(tps); + if (ret < 0) + return ret; + + if (time_is_before_jiffies(timeout)) + return -ETIMEDOUT; + + } while (ret != TPS_MODE_APP); + + dev_info(tps->dev, "controller switched to \"APP\" mode\n"); + + return 0; +}; + static int tps6598x_probe(struct i2c_client *client) { irq_handler_t irq_handler = tps6598x_interrupt; @@ -725,6 +950,7 @@ static int tps6598x_probe(struct i2c_client *client) u32 vid; int ret; u64 mask1; + bool is_tps25750; tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); if (!tps) @@ -737,9 +963,12 @@ static int tps6598x_probe(struct i2c_client *client) if (IS_ERR(tps->regmap)) return PTR_ERR(tps->regmap); - ret = tps6598x_read32(tps, TPS_REG_VID, &vid); - if (ret < 0 || !vid) - return -ENODEV; + is_tps25750 = of_device_is_compatible(np, "ti,tps25750"); + if (!is_tps25750) { + ret = tps6598x_read32(tps, TPS_REG_VID, &vid); + if (ret < 0 || !vid) + return -ENODEV; + } /* * Checking can the adapter handle SMBus protocol. If it can not, the @@ -773,9 +1002,15 @@ static int tps6598x_probe(struct i2c_client *client) if (ret < 0) return ret; + if (is_tps25750 && ret == TPS_MODE_PTCH) { + ret = tps25750_apply_patch(tps); + if (ret) + return ret; + } + ret = tps6598x_write64(tps, TPS_REG_INT_MASK1, mask1); if (ret) - return ret; + goto err_reset_controller; ret = tps6598x_read32(tps, TPS_REG_STATUS, &status); if (ret < 0) @@ -895,19 +1130,29 @@ static int tps6598x_probe(struct i2c_client *client) fwnode_handle_put(fwnode); err_clear_mask: tps6598x_write64(tps, TPS_REG_INT_MASK1, 0); +err_reset_controller: + /* Reset PD controller to remove any applied patch */ + if (is_tps25750) + tps6598x_exec_cmd_tmo(tps, "GAID", 0, NULL, 0, NULL, 2000, 0); return ret; } static void tps6598x_remove(struct i2c_client *client) { struct tps6598x *tps = i2c_get_clientdata(client); + struct device_node *np = client->dev.of_node; if (!client->irq) cancel_delayed_work_sync(&tps->wq_poll); + devm_free_irq(tps->dev, client->irq, tps); tps6598x_disconnect(tps, 0); typec_unregister_port(tps->port); usb_role_switch_put(tps->role_sw); + + /* Reset PD controller to remove any applied patch */ + if (of_device_is_compatible(np, "ti,tps25750")) + tps6598x_exec_cmd_tmo(tps, "GAID", 0, NULL, 0, NULL, 2000, 0); } static int __maybe_unused tps6598x_suspend(struct device *dev) @@ -950,6 +1195,7 @@ static const struct dev_pm_ops tps6598x_pm_ops = { static const struct of_device_id tps6598x_of_match[] = { { .compatible = "ti,tps6598x", }, { .compatible = "apple,cd321x", }, + { .compatible = "ti,tps25750", }, {} }; MODULE_DEVICE_TABLE(of, tps6598x_of_match); From patchwork Sat Sep 23 07:39:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp73626vqu; Sat, 23 Sep 2023 02:25:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPZ6b694oWOkvh4Hz/7uapcm+Vn5Y0or++uMdSPxsf2oU7NIvSJI2T3HAoSXYRnRxF0rIa X-Received: by 2002:a05:6a00:1990:b0:68f:bbc3:df44 with SMTP id d16-20020a056a00199000b0068fbbc3df44mr2198774pfl.0.1695461121127; Sat, 23 Sep 2023 02:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695461121; cv=none; d=google.com; s=arc-20160816; b=LLRpOenlz4aKV1+jHYJY6zrBi/Le0w97eB6vSqieArQxhcmraO1kQ8iymBpDjxVvvg tYfSMKjO7t2mk7ZUMN9Luo8YOyzYuzNjcAbdc4JlavrAzA82i46awR/MpfbtmaPsvAyC f0HqOzqLH/9FhQQ/GJKVGoB4DsawHZ7t/aJOyuGy3me4xPZ13jHlrfN84BwR7DPbKdch CRPuTBbIruQqXNkkII/rV1NkBJwIXPNued5sCHyJu/WTwVWOsJVe3w7OhXDd1lPxDxnV fDB2QuXkcT/FBc9MLUH0JhGtU/UQ4vv0VHU7SXhtK3B6Y8kc48XIUxwfrDQSx/V26peo fGtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fIRa+aj4f6v9xT4/WGZX0P0iihhQsW2AVKNBUDiG5uU=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=1KsjH2cJUaE/PBf1uPDUc+Cot3tibE22c8oEZNh1PA1WLfDmVwIcZwF6BmBu21mxDe hiXB3TRlEeaJ5QjRBQGsrA8NF1SLd99acQ1rNnDbbQFhNspEH8NaZ4jYyHV5ZpavdnJI CIqjKbLCsoPnAmaHweB37MG0Q+W3odWMsT2CWFwm3pvkhf4e/GZzdbb+/kQkj6xjwOJy VZFkD3GuvroRo10DogY7y8uFlkWdg0WsWuidvmrG6ImGac3nqfE0eseEbyMsgMloK2XO S6s9zVWaeQmlZrtc2tw/KzlGNBeJSqUNrPHMySGwA9ddQ8bMsOE89pfMxgy+7WSXeXgZ Zxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MYYpMPRZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x3-20020a636303000000b0055fdd303745si5595660pgb.421.2023.09.23.02.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 02:25:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MYYpMPRZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F1AC6822074F; Sat, 23 Sep 2023 00:41:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbjIWHlK (ORCPT + 29 others); Sat, 23 Sep 2023 03:41:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbjIWHkz (ORCPT ); Sat, 23 Sep 2023 03:40:55 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA3BF1B3; Sat, 23 Sep 2023 00:40:48 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50317080342so5595594e87.2; Sat, 23 Sep 2023 00:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454847; x=1696059647; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fIRa+aj4f6v9xT4/WGZX0P0iihhQsW2AVKNBUDiG5uU=; b=MYYpMPRZiVoeBElScU4kKrpREl/FqOginl6g4pK6qKf7bfJuatcSp8MPBhGwFoP2V7 AgB0PQhMD5kxqq+z/eT/wIW2JrOFlOBsTXgolyKIdmixI2GaOjJo/6uBcb6K5fweT/ph 61H+zvszAZE2/u5gBDjC2jFVTKYLVPCeaCclMaPmpfEhgZcY5IDozNkDH4ZOKHn7+G8R HvIOtFWCltyBTHUBaoiYU2d+J+IDrG/pihzHF+oxVyXQlKWFnFiq8EasdIalsQHEOOat wAwF9MLxB7rmfKdDzihqRVyEP1nnQgSTIoYGy9spx1LaZu5jWKLsCstS254iUMjdemFN 7stQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454847; x=1696059647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fIRa+aj4f6v9xT4/WGZX0P0iihhQsW2AVKNBUDiG5uU=; b=F4kqxuW1Xqkd4nsfl7MuHzQcmVBlCVa0mRMEUrRBaooiqLIIf2G2Chfd7XV1+KVPVU EPOokPxnRz+YFOoCRYTfB41DYVANKgKxqZTL82uF13BpmwKmfaf3uiooeIF1nmbuWnTT 3Q4hBuQGy/5LO6G2riOXQkaoX1mdeeYuEcjd+e5mqfXBv/mepUHFKgF9kse66T72SJlQ Z3foPGT3a7G6Kf8K1Syi6mhD8xXhWw7E4rw0+LRkiJezHG7ldboGmsNMBbWVHQ/O7yzb A6Mo3WU8rUYV+LHwTKcg9I3P8l2XJGBpCAzNreQIFwAaTWuPrPO21UbrNsW6R1R2rXuJ BmMg== X-Gm-Message-State: AOJu0YzYxeHcAjGJF13nBIsZGZFoPSbNFbXVAKWxd7Wpi1/MaGHl0BFs eiRvU8y70dSdkmHJAKwX+Jo= X-Received: by 2002:a19:6506:0:b0:503:1bb0:a658 with SMTP id z6-20020a196506000000b005031bb0a658mr1092532lfb.32.1695454846430; Sat, 23 Sep 2023 00:40:46 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:46 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 07/14] USB: typec: Apply patch again after power resume Date: Sat, 23 Sep 2023 03:39:52 -0400 Message-Id: <20230923073959.86660-8-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:41:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777819840583050041 X-GMAIL-MSGID: 1777819840583050041 From: Abdel Alkuor TPS25750 PD controller might be powered off externally at power suspend, after resuming PD controller power back, apply the patch again. Signed-off-by: Abdel Alkuor --- Changes in v6: - Check tps25750 using is_compatiable device node Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 148b237d0df5..d77481f78100 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -1192,6 +1192,18 @@ static int __maybe_unused tps6598x_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); struct tps6598x *tps = i2c_get_clientdata(client); + struct device_node *np = client->dev.of_node; + int ret; + + ret = tps6598x_check_mode(tps); + if (ret < 0) + return ret; + + if (of_device_is_compatible(np, "ti,tps25750") && ret == TPS_MODE_PTCH) { + ret = tps25750_apply_patch(tps); + if (ret) + return ret; + } if (tps->wakeup) { disable_irq_wake(client->irq); From patchwork Sat Sep 23 07:39:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp183924vqu; Sat, 23 Sep 2023 06:41:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjuQaYoM9OSdUZg28B2SJVv2a+x0OfWO9eHLui0aqJ5N7Sss4WhiNGICQPPdQzCr3TQwP8 X-Received: by 2002:a17:90a:6c04:b0:274:9121:382 with SMTP id x4-20020a17090a6c0400b0027491210382mr7661445pjj.22.1695476505488; Sat, 23 Sep 2023 06:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695476505; cv=none; d=google.com; s=arc-20160816; b=ovhph68Oy2JYGw2Eng2dkC/KiRM5RfUwTNe2SHtX9aH3SrmqnltH8XBudrpdKLc2Kr lUmzv2uGA+xOEIQQgFJ3qSW9VrGKRZFLftnMR/I3RUbtHIuj57E6Dsozu+Xz/uMbF9OJ Jqt73tP/OrR2Y6B8QobOVe4EifsqLL9erEfjNr0FyinfaNzeA3Dn3wR1nIuV/T+relcp LVeQSlUPxKJ6TIKuLPVxfVJfxA3U5RrkYo7ZUFNJkn6sN7bcyzQSJ59IptMYz3JQb68y fwZSc5lJmJamUa6ZZ6RDHx62/+hwrcwAcvbuwPbYnGvzMRC0Ovyf1t5MBeV+udSAJb+i 07hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NngsX8OKUIlXcUyUeEx3ndnNs3TPCLexEhwQVJVkbuQ=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=xDwjM63EUtoWIqFCoagZlaCu/Q4vkeOk2oGlPCJpNnF2NriDWbmCkxq0QguMNuPaC3 pSyQM9i/4sgE+QRWSS1DX/hokZuH6K0IQJ3yH93IOxa8SVBxV/iZ+ZAIgVYbP+cAW9I7 FNposlTgvUzyDg3Z1It4nHF+//f4i8iIArobM3CUOONc50YwW6yXsAdIL+IJWCIjO0sg 2jp7ZvW384m7f4daXkD8acPIKZGoS0UbUI9ecNDi2344HIenHbzK1NAdiLvHQAXP2N5H iTNXidmUivyru3GKBGBHiVFDCyYr4SVD59OONbWTw+8jpnb9L4qLZLPvj5twQ6jEKW0Y 3evg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Hzz5s5CW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ja17-20020a170902efd100b001bf2dc67da3si5543633plb.209.2023.09.23.06.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 06:41:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Hzz5s5CW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CCA118218E68; Sat, 23 Sep 2023 00:41:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbjIWHlO (ORCPT + 29 others); Sat, 23 Sep 2023 03:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjIWHk5 (ORCPT ); Sat, 23 Sep 2023 03:40:57 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2739719E; Sat, 23 Sep 2023 00:40:50 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40537481094so30022165e9.0; Sat, 23 Sep 2023 00:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454848; x=1696059648; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NngsX8OKUIlXcUyUeEx3ndnNs3TPCLexEhwQVJVkbuQ=; b=Hzz5s5CW9IHN892hZa/nOLwGTbsoqNLM6Jh3CmYFnHV2a69A4BvINHZa0UFmY9qopT KYhB/RCVsL2n5upjiRddXX1yqZG6E0NsL+BXKfb37otR2IOuEVMIRszk19DBfRRFOWyC 7mpElL3A9hb4Z+wwBQpF7cn1QQAlOcpxJy5jTYHoaEnHo09sUUI9SslQoSd2ZoLyea/f PPPiwz56wc5azVVE2vWNlhij9gL29ihDP0NOYv60IC5oQeXg8THotng45UVEdReqkWUl VioyWNzREgImSccBKQew3hvvqJFZceUcQv4S45D6u8sDjufPbSh/QmjBAgyeLFtEF88I gsYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454848; x=1696059648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NngsX8OKUIlXcUyUeEx3ndnNs3TPCLexEhwQVJVkbuQ=; b=GTI/JdGKi+xbDv1TpJ2wncxd7Pj3HyPMzGAKX9mslvKvdsBJiO7eCPpLTTiJrif2X8 JDhZPgAnNQkNM89tph926aHqOPyybclCoj/DqIr92z7KtDEuZT/U7IXPGCnrlUN37G33 xfJHh00aar2WYQkLC9rd7o9uj4Uv/77srEXZWqmixPzrwVVhsO2zKca31jIWO33E9hWH 8lXmvJV9u5EUtAwodyd5jfyZE09w1n63px76xOLx2NjSErHY9CdunuJmQwYs6+rLFhKI xh0aPIhJT+hF11P9gbVNway3ppBWBY18enuX+KhuckL9xUw9l4+GMhMDQYDBkLAvzs4X Nd4A== X-Gm-Message-State: AOJu0YxXHD8sOuyf/VPGz0dKKErOcF6oOWzOgFzD4Z2e1smwVvTKUJc0 J95JEW7QhWwneS9TqxsC0Dz4pegraztAuL7dxec= X-Received: by 2002:a1c:4b04:0:b0:402:ff8d:609b with SMTP id y4-20020a1c4b04000000b00402ff8d609bmr1224520wma.33.1695454848232; Sat, 23 Sep 2023 00:40:48 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:47 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 08/14] USB: typec: Add interrupt support for TPS25750 Date: Sat, 23 Sep 2023 03:39:53 -0400 Message-Id: <20230923073959.86660-9-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:41:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777835972122943927 X-GMAIL-MSGID: 1777835972122943927 From: Abdel Alkuor tps25750 event registers structure is different than tps6598x's, tps25750 has 11 bytes of events which are read at once where tps6598x has two event registers of 8 bytes each which are read separately. Likewise MASK event registers. Also, not all events are supported in both devices. Update tps6598x interrupt handler to accommodate tps25750 interrupt Signed-off-by: Abdel Alkuor --- Changes in v6: - Create tipd callbacks factory Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 102 +++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 56ffffe225f2..cde52afe5097 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -101,6 +101,14 @@ static const char *const modes[] = { /* Unrecognized commands will be replaced with "!CMD" */ #define INVALID_CMD(_cmd_) (_cmd_ == 0x444d4321) +struct tps6598x; + +struct tipd_data { + irq_handler_t irq_handler; + int (*read_events)(struct tps6598x *tps, void *events); + int (*clear_events)(struct tps6598x *tps, void *events); +}; + struct tps6598x { struct device *dev; struct regmap *regmap; @@ -118,9 +126,11 @@ struct tps6598x { enum power_supply_usb_type usb_type; int wakeup; + u32 status; /* status reg */ u16 pwr_status; struct delayed_work wq_poll; - irq_handler_t irq_handler; + + struct tipd_data cb; }; static enum power_supply_property tps6598x_psy_props[] = { @@ -500,6 +510,32 @@ static void tps6598x_handle_plug_event(struct tps6598x *tps, u32 status) } } +static int tps6598x_read_events(struct tps6598x *tps, void *events) +{ + uint64_t *e = events; + + return tps6598x_read64(tps, TPS_REG_INT_EVENT1, &e[0]) | + tps6598x_read64(tps, TPS_REG_INT_EVENT2, &e[1]); +} + +static int tps6598x_clear_events(struct tps6598x *tps, void *events) +{ + uint64_t *e = events; + + return tps6598x_write64(tps, TPS_REG_INT_CLEAR1, e[0]) | + tps6598x_write64(tps, TPS_REG_INT_CLEAR2, e[1]); +} + +static int tps25750_read_events(struct tps6598x *tps, void *events) +{ + return tps6598x_block_read(tps, TPS_REG_INT_EVENT1, events, 11); +} + +static int tps25750_clear_events(struct tps6598x *tps, void *events) +{ + return tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, events, 11); +} + static irqreturn_t cd321x_interrupt(int irq, void *data) { struct tps6598x *tps = data; @@ -545,50 +581,60 @@ static irqreturn_t cd321x_interrupt(int irq, void *data) return IRQ_NONE; } +static bool tps6598x_has_role_changed(struct tps6598x *tps, u32 status) +{ + status ^= tps->status; + + return status & (TPS_STATUS_PORTROLE | TPS_STATUS_DATAROLE); +} + static irqreturn_t tps6598x_interrupt(int irq, void *data) { struct tps6598x *tps = data; - u64 event1 = 0; - u64 event2 = 0; + u64 event[2] = { }; u32 status; int ret; mutex_lock(&tps->lock); - ret = tps6598x_read64(tps, TPS_REG_INT_EVENT1, &event1); - ret |= tps6598x_read64(tps, TPS_REG_INT_EVENT2, &event2); + ret = tps->cb.read_events(tps, event); if (ret) { dev_err(tps->dev, "%s: failed to read events\n", __func__); goto err_unlock; } - trace_tps6598x_irq(event1, event2); + trace_tps6598x_irq(event[0], event[1]); - if (!(event1 | event2)) + if (!(event[0] | event[1])) goto err_unlock; if (!tps6598x_read_status(tps, &status)) goto err_clear_ints; - if ((event1 | event2) & TPS_REG_INT_POWER_STATUS_UPDATE) + if ((event[0] | event[1]) & TPS_REG_INT_POWER_STATUS_UPDATE) if (!tps6598x_read_power_status(tps)) goto err_clear_ints; - if ((event1 | event2) & TPS_REG_INT_DATA_STATUS_UPDATE) + if ((event[0] | event[1]) & TPS_REG_INT_DATA_STATUS_UPDATE) if (!tps6598x_read_data_status(tps)) goto err_clear_ints; - /* Handle plug insert or removal */ - if ((event1 | event2) & TPS_REG_INT_PLUG_EVENT) + /* + * data/port roles could be updated independently after + * a plug event. Therefore, we need to check + * for pr/dr status change to set TypeC dr/pr accordingly. + */ + if ((event[0] | event[1]) & TPS_REG_INT_PLUG_EVENT || + tps6598x_has_role_changed(tps, status)) tps6598x_handle_plug_event(tps, status); + tps->status = status; err_clear_ints: - tps6598x_write64(tps, TPS_REG_INT_CLEAR1, event1); - tps6598x_write64(tps, TPS_REG_INT_CLEAR2, event2); + tps->cb.clear_events(tps, event); err_unlock: mutex_unlock(&tps->lock); - if (event1 | event2) + if (event[0] | event[1]) return IRQ_HANDLED; return IRQ_NONE; } @@ -600,7 +646,7 @@ static void tps6598x_poll_work(struct work_struct *work) struct tps6598x *tps = container_of(to_delayed_work(work), struct tps6598x, wq_poll); - tps->irq_handler(0, tps); + tps->cb.irq_handler(0, tps); queue_delayed_work(system_power_efficient_wq, &tps->wq_poll, msecs_to_jiffies(POLL_INTERVAL)); } @@ -967,9 +1013,24 @@ static int tps25750_apply_patch(struct tps6598x *tps) return 0; }; +static const struct tipd_data cd321x_data = { + .irq_handler = cd321x_interrupt, +}; + +static const struct tipd_data tps6598x_data = { + .irq_handler = tps6598x_interrupt, + .read_events = tps6598x_read_events, + .clear_events = tps6598x_clear_events, +}; + +static const struct tipd_data tps25750_data = { + .irq_handler = tps6598x_interrupt, + .read_events = tps25750_read_events, + .clear_events = tps25750_clear_events, +}; + static int tps6598x_probe(struct i2c_client *client) { - irq_handler_t irq_handler = tps6598x_interrupt; struct device_node *np = client->dev.of_node; struct typec_capability typec_cap = { }; struct tps6598x *tps; @@ -1017,15 +1078,18 @@ static int tps6598x_probe(struct i2c_client *client) APPLE_CD_REG_INT_DATA_STATUS_UPDATE | APPLE_CD_REG_INT_PLUG_EVENT; - irq_handler = cd321x_interrupt; + tps->cb = cd321x_data; } else { + if (is_tps25750) + tps->cb = tps25750_data; + else + tps->cb = tps6598x_data; /* Enable power status, data status and plug event interrupts */ mask1 = TPS_REG_INT_POWER_STATUS_UPDATE | TPS_REG_INT_DATA_STATUS_UPDATE | TPS_REG_INT_PLUG_EVENT; } - tps->irq_handler = irq_handler; /* Make sure the controller has application firmware running */ ret = tps6598x_check_mode(tps); if (ret < 0) @@ -1125,7 +1189,7 @@ static int tps6598x_probe(struct i2c_client *client) if (client->irq) { ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, - irq_handler, + tps->cb.irq_handler, IRQF_SHARED | IRQF_ONESHOT, dev_name(&client->dev), tps); } else { From patchwork Sat Sep 23 07:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp77045vqu; Sat, 23 Sep 2023 02:36:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEab5kUKH1dm9a1t8OL8nrWZT4lRDm2wgJl+I43q4eVQQwFDZWVielmIFcDOIFsp0NIb+Md X-Received: by 2002:a05:6808:f8f:b0:3ad:f9f9:c1e0 with SMTP id o15-20020a0568080f8f00b003adf9f9c1e0mr2115001oiw.40.1695461773148; Sat, 23 Sep 2023 02:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695461773; cv=none; d=google.com; s=arc-20160816; b=03pbVddtu7BrHQdD6jpptoNSbWYfgMH5t48g70+9PUxeSTOoUM9hJnIiy6PuwAT25s k3b6gYaBvD6I+JBlkUL0Nbf3J6TXKgc+4ylQQt5u4pDw6d/wyzFcHPl2WFfq/8REKe9G hQkBcpPyPJ8sD6o4xqRc3IdDpHOeRrvwl7B3173qLgOXmwZPXFvMtL41AGg95dbzxZk3 g5y5d5jU0HZRRjngIDXr3bxYY8XMnzJK47SkghyjxdvE5vMAcN0PMoGPGoqdAq2Vuf5+ LaxFrPSMq0vY/a/o3SV7577tM349j7dKSMd1IBZiv2g0YoyAy6VwA6qltdvJuxxxhe5A MEUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QZxo1B/VHfhPPPS7W1orDfRrMmOmst2RNRIjfpEvVPA=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=07Yc4qD1kAhkntC3Bga4ts/46mT1KfRcKRaUjeJoRHrtgbOGdVGSiTjdKJOUDSlSFT kvEUJhAbvfllDjJgkWXoMhPSZ2/jp9vM0Dt+SIdNLMKXqdZq495DfkMqNgdgC++U4bmq o5zj+jTEWDpWy0n1c5eG1y5o2AZqCJHGXzA4vRIvZsLFfFsLYTX88H66jeOL8b8E42hp MF5QZiMXsCG1zMmgMq5PqmSuHR/m28FHKwibgebu64OjVxILDirDCX148894/IkMcXMj sAfq5lyabwhVuvWpqbmYZqDubzVrpSST2wQF2Ld7n5uYN9nawrrF0X5zUpdqIBvW6y5m qEHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eoIYFcn+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f20-20020a637554000000b00578a2438d6asi5632538pgn.209.2023.09.23.02.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 02:36:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eoIYFcn+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 13EA182A54E3; Sat, 23 Sep 2023 00:41:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbjIWHl0 (ORCPT + 29 others); Sat, 23 Sep 2023 03:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbjIWHlO (ORCPT ); Sat, 23 Sep 2023 03:41:14 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0207CC3; Sat, 23 Sep 2023 00:40:54 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-31dcf18f9e2so3191814f8f.0; Sat, 23 Sep 2023 00:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454852; x=1696059652; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QZxo1B/VHfhPPPS7W1orDfRrMmOmst2RNRIjfpEvVPA=; b=eoIYFcn+Me5PoGK3SgmaKD3cvcS1vGLp1CN2aChxezzh+bnrvVyUqPwBQGjGTyEvkN g2pjZvnpI6GAZfDQK6Rr1CFzOqCL9ZjtUsq2iJmRPwaZZi3oyzNFq13eEVC4lE20qqVl Tp3G1ASbLxVNQXdHNQhx6vAjsmA3nakR7BbtLTxjfquAk8ZcAr9W0PwTF3dAbZpO90vL s1pFwalbyaOdWc1AMfpa4NWC2SpNta725AptvhYNOi8dbqdV1G6nHnVoWxp0ByXy6D4v ZDF1j5Z3YyLGle1lk0hdAG37kYFzDaPDmyzF6QVkwp9YbgehyBskc9Fdn4A1plU5S4m3 Go4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454852; x=1696059652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QZxo1B/VHfhPPPS7W1orDfRrMmOmst2RNRIjfpEvVPA=; b=aTVyRbqw5vfTMBJARVemV4MpL9ObcYbjonJMsiV9QTM37qpQI6laj5HAC7YQtOYKIG /qjGqRpaPwteQt0S8CoJat3L7o3IM+cCNdZQIlUokmU1Y5K8gH4LShVGlaWUp7W2rGIv hNSZPznhmdwnEfezAHW1X7xUmBPDUmNwhOv4R01q8oz0Rds3A4DiWBB2Txq1m4pAq09+ L5pJU4qmy0o2+gqZOk9FsIa/6AnD3QlQf15qjYcSXM3tTBy3udCyuc6T4yeElXaNo5pN rM993aqX/eWKtD6p+txizfB63deEmeIAOjQJnc365sU4+1P+dd8j67LFnZQWL+d6/+ji gt0A== X-Gm-Message-State: AOJu0YxP7wK+L/oNwr6YXIBwo+3hiWnfBJAXTGQ34pkbKx66Epe+DXPY k9FiEE6Du2LilrtfNjX1emo= X-Received: by 2002:a5d:4e83:0:b0:319:785a:fce5 with SMTP id e3-20020a5d4e83000000b00319785afce5mr1454983wru.38.1695454851878; Sat, 23 Sep 2023 00:40:51 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:51 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 10/14] USB: typec: Add port registration for tps25750 Date: Sat, 23 Sep 2023 03:39:55 -0400 Message-Id: <20230923073959.86660-11-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:41:40 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777820524215335231 X-GMAIL-MSGID: 1777820524215335231 From: Abdel Alkuor TPS25750 doesn't have system configuration register to get dr/pr of the current applied binary configuration. Get data role from the device node and power role from PD status register. Signed-off-by: Abdel Alkuor --- Changes in v6: - Add port registration to tipd data factory Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 66 ++++++++++++++++++++++++++++++- drivers/usb/typec/tipd/tps6598x.h | 10 +++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index ee53011ec5e2..cfaad9a917a2 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -39,6 +39,7 @@ #define TPS_REG_CTRL_CONF 0x29 #define TPS_REG_BOOT_STATUS 0x2D #define TPS_REG_POWER_STATUS 0x3f +#define TPS_REG_PD_STATUS 0x40 #define TPS_REG_RX_IDENTITY_SOP 0x48 #define TPS_REG_DATA_STATUS 0x5f @@ -107,6 +108,7 @@ struct tipd_data { irq_handler_t irq_handler; int (*read_events)(struct tps6598x *tps, void *events); int (*clear_events)(struct tps6598x *tps, void *events); + int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); }; struct tps6598x { @@ -211,6 +213,11 @@ static inline int tps6598x_read64(struct tps6598x *tps, u8 reg, u64 *val) return tps6598x_block_read(tps, reg, val, sizeof(u64)); } +static inline int tps6598x_write8(struct tps6598x *tps, u8 reg, u8 val) +{ + return tps6598x_block_write(tps, reg, &val, sizeof(u8)); +} + static inline int tps6598x_write64(struct tps6598x *tps, u8 reg, u64 val) { return tps6598x_block_write(tps, reg, &val, sizeof(u64)); @@ -1051,20 +1058,77 @@ tps6598x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) return 0; } +static int +tps25750_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) +{ + struct typec_capability typec_cap = { }; + const char *data_role; + u8 pd_status; + int ret; + + ret = tps6598x_read8(tps, TPS_REG_PD_STATUS, &pd_status); + if (ret) + return ret; + + ret = fwnode_property_read_string(fwnode, "data-role", &data_role); + if (ret) { + dev_err(tps->dev, "data-role not found: %d\n", ret); + return ret; + } + + ret = typec_find_port_data_role(data_role); + if (ret < 0) { + dev_err(tps->dev, "unknown data-role: %s\n", data_role); + return ret; + } + + typec_cap.data = ret; + typec_cap.revision = USB_TYPEC_REV_1_3; + typec_cap.pd_revision = 0x300; + typec_cap.driver_data = tps; + typec_cap.ops = &tps6598x_ops; + typec_cap.fwnode = fwnode; + typec_cap.prefer_role = TYPEC_NO_PREFERRED_ROLE; + + switch (TPS_PD_STATUS_PORT_TYPE(pd_status)) { + case TPS_PD_STATUS_PORT_TYPE_SINK_SOURCE: + case TPS_PD_STATUS_PORT_TYPE_SOURCE_SINK: + typec_cap.type = TYPEC_PORT_DRP; + break; + case TPS_PD_STATUS_PORT_TYPE_SINK: + typec_cap.type = TYPEC_PORT_SNK; + break; + case TPS_PD_STATUS_PORT_TYPE_SOURCE: + typec_cap.type = TYPEC_PORT_SRC; + break; + default: + return -ENODEV; + } + + tps->port = typec_register_port(tps->dev, &typec_cap); + if (IS_ERR(tps->port)) + return PTR_ERR(tps->port); + + return 0; +} + static const struct tipd_data cd321x_data = { .irq_handler = cd321x_interrupt, + .register_port = tps6598x_register_port, }; static const struct tipd_data tps6598x_data = { .irq_handler = tps6598x_interrupt, .read_events = tps6598x_read_events, .clear_events = tps6598x_clear_events, + .register_port = tps6598x_register_port, }; static const struct tipd_data tps25750_data = { .irq_handler = tps6598x_interrupt, .read_events = tps25750_read_events, .clear_events = tps25750_clear_events, + .register_port = tps25750_register_port, }; static int tps6598x_probe(struct i2c_client *client) @@ -1167,7 +1231,7 @@ static int tps6598x_probe(struct i2c_client *client) if (ret) goto err_role_put; - ret = tps6598x_register_port(tps, fwnode); + ret = tps->cb.register_port(tps, fwnode); if (ret) goto err_role_put; diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index c000170f4547..3a9a43394134 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -203,4 +203,14 @@ #define TPS_BOOT_STATUS_DEAD_BATTERY_FLAG BIT(2) #define TPS_BOOT_STATUS_I2C_EEPROM_PRESENT BIT(3) +/* PD STATUS REG */ +#define TPS_REG_PD_STATUS_PORT_TYPE_MASK GENMASK(5, 4) +#define TPS_PD_STATUS_PORT_TYPE(x) \ + TPS_FIELD_GET(TPS_REG_PD_STATUS_PORT_TYPE_MASK, x) + +#define TPS_PD_STATUS_PORT_TYPE_SINK_SOURCE 0 +#define TPS_PD_STATUS_PORT_TYPE_SINK 1 +#define TPS_PD_STATUS_PORT_TYPE_SOURCE 2 +#define TPS_PD_STATUS_PORT_TYPE_SOURCE_SINK 3 + #endif /* __TPS6598X_H__ */ From patchwork Sat Sep 23 07:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp157037vqu; Sat, 23 Sep 2023 05:50:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHA7lqgFIab5iX1iU02NgGXD+Ap6krDnv18wa+vKgDlydnzeVtJ6+MHzyJGXYQKqMq2dW5G X-Received: by 2002:a05:6a20:9383:b0:138:2fb8:6a14 with SMTP id x3-20020a056a20938300b001382fb86a14mr2691016pzh.3.1695473431136; Sat, 23 Sep 2023 05:50:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695473431; cv=none; d=google.com; s=arc-20160816; b=L90md5JjWwiUBqYEpDRQeqyRAbdqY7lssNOjSOAw/8QZQV7Vs59X+lkMME/sTdV24G hu8Jz9q+ZkU9Gwe1SMTcyMqAf0/QaeaFpnCEAi7TCXTMKg0gigXZkxIbLA22C70tSj/J kJkCsOqiI5LHVtkZ7CHDxljTAmOzME/jRMll94BNB5f5VZYfoxFViwzu/HGF1aratUOf 3JFqjMnqYIlQF+MZR5C6aP80TClbowbAH+wHvgqtmEpjLXe+lYGen8Bgr91lGwQlY1cS DBKMO3AbgghUhh62ASlPYia4c8Vp1desX4E01w9mQPH1TBeP9+MVVdBbL78RDUMWDGcE ezZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lMU1+3f9rhhujzu3jJshYss3tD8nbrjDTUeRPgbi6ws=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=CYm2RdqxoCVFU6JrNnLqzAQvRfGZX8+WMFIqnw8eZVESN8bxJ7Jr1zbuzPvl2ERO58 QFP7h4A2LprXOOg4Xp+LKD2qruhdYMSOp03+jt9GVJry6LqKrtOfepHafYQkpsKr2jyi viEKDWyyLqCHLPhXb1PqWPNDrgN/swkyPR2NRsObQbIKxEJ5E5EOxIypR5CgNdKYqFMf XhVPjMb41/LhoS9wuZe1pnwDToRlEgAGx8dIhKE8mlmjIAYFRkJEtOrTLKfkOde891Nq L0s38a+jF6L0u//joJV+HSxBct02IKksqFeVEeRHUebf1xR9E0ktk3Ns6Prk4QQUDcvv nmmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=h4GcvH8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b00565bcc15ee2si6003673pgj.815.2023.09.23.05.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 05:50:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=h4GcvH8I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B17C382B0FD8; Sat, 23 Sep 2023 00:42:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbjIWHlq (ORCPT + 29 others); Sat, 23 Sep 2023 03:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbjIWHlb (ORCPT ); Sat, 23 Sep 2023 03:41:31 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 454B4E51; Sat, 23 Sep 2023 00:40:58 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-503397ee920so5315047e87.1; Sat, 23 Sep 2023 00:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454855; x=1696059655; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lMU1+3f9rhhujzu3jJshYss3tD8nbrjDTUeRPgbi6ws=; b=h4GcvH8ImLGjJoR8I5K0YeFbd7Kzu0jIohSCNT9pu4qKIVLja9HgJoV2VBum8DSNAK 6Bh2gHR1movCBbodJ9GA+L7Uc2FTrLa6fSeyQWP1g9g4X2oXrUJRfL8nLifTuki0x8Go sYpswUB0TSJRQY6ZZYoacdjg0RGj7b6HCV0rvtrXlV+TeXa4eO8h2w8vx6z6LnnOniWY +hLNkHqwzMwTy+kTEdui8BeqRfrHTRiI9EB37pfPsWhmjIaHDiapOsZPkpzh+hzG2+U8 npS1/1I3pJAv0uWvVLquCwbTKq2W5TMDVtBFeStSUvPol2Ve7EpgXypKpvWvN1xO71M4 rHPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454855; x=1696059655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lMU1+3f9rhhujzu3jJshYss3tD8nbrjDTUeRPgbi6ws=; b=TjgDkj4WLiaVabmCGDah1Kkq7YNee8Bmy1zvpUcxYlXShy2v1M8hmWEaFzoJBXJXkR FD76B/CCm8fdaFWJ/bXo031iTnqPD04LhLyIba/iYsVuETjyQi9FBNvVkDlHvosxClZJ UBDh+C70DaDhblmcajneu7dNfFYF4a0Lrh5RoCKHS76cnaMNudzxcWVnZtvOTW5o4Blc f89g/bB7KeT9uJkokl3sBoXV+jCChe0yEBzPhXkEB6ZS2v768x6EMZXnbDye+29JcT6i INkMr1jL3XLGLRuFTTHAUSw1s4WVMYCxZhOJ6M7iNenTvTeCxXGMlIW3B6betXlW6//j DL2Q== X-Gm-Message-State: AOJu0Yz1rN38MvjJtXc/xn3WnycqRb0/BhHH7h8Rm/p9SwkegMWJYYmZ 830GXvqMFBws8ZsZWpZk6sk= X-Received: by 2002:a05:6512:6cc:b0:500:7a21:3e78 with SMTP id u12-20020a05651206cc00b005007a213e78mr1545330lff.55.1695454855458; Sat, 23 Sep 2023 00:40:55 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:55 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 12/14] USB: typec: Add trace for tps25750 irq Date: Sat, 23 Sep 2023 03:39:57 -0400 Message-Id: <20230923073959.86660-13-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:42:20 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777832748856623532 X-GMAIL-MSGID: 1777832748856623532 From: Abdel Alkuor tps25750 event1 register doesn't have all bits in tps6598x event registers, only show the events that are masked Signed-off-by: Abdel Alkuor --- Changes in v6: - Add trace irq to tipd callbacks factory Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 17 ++++++++++++++++- drivers/usb/typec/tipd/trace.h | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index 661ded2ff2d5..ba28ce477f21 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -110,6 +110,7 @@ struct tipd_data { int (*read_events)(struct tps6598x *tps, void *events); int (*clear_events)(struct tps6598x *tps, void *events); int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); + void (*trace_irq)(void *events); }; struct tps6598x { @@ -534,6 +535,13 @@ static int tps6598x_clear_events(struct tps6598x *tps, void *events) tps6598x_write64(tps, TPS_REG_INT_CLEAR2, e[1]); } +static void tps6598x_trace_irq(void *events) +{ + uint64_t *e = events; + + trace_tps6598x_irq(e[0], e[1]); +} + static int tps25750_read_events(struct tps6598x *tps, void *events) { return tps6598x_block_read(tps, TPS_REG_INT_EVENT1, events, 11); @@ -544,6 +552,11 @@ static int tps25750_clear_events(struct tps6598x *tps, void *events) return tps6598x_block_write(tps, TPS_REG_INT_CLEAR1, events, 11); } +static void tps25750_trace_irq(void *events) +{ + trace_tps25750_irq(*(uint64_t *)events); +} + static irqreturn_t cd321x_interrupt(int irq, void *data) { struct tps6598x *tps = data; @@ -610,7 +623,7 @@ static irqreturn_t tps6598x_interrupt(int irq, void *data) dev_err(tps->dev, "%s: failed to read events\n", __func__); goto err_unlock; } - trace_tps6598x_irq(event[0], event[1]); + tps->cb.trace_irq(event); if (!(event[0] | event[1])) goto err_unlock; @@ -1155,6 +1168,7 @@ static const struct tipd_data tps6598x_data = { .read_events = tps6598x_read_events, .clear_events = tps6598x_clear_events, .register_port = tps6598x_register_port, + .trace_irq = tps6598x_trace_irq, }; static const struct tipd_data tps25750_data = { @@ -1162,6 +1176,7 @@ static const struct tipd_data tps25750_data = { .read_events = tps25750_read_events, .clear_events = tps25750_clear_events, .register_port = tps25750_register_port, + .trace_irq = tps25750_trace_irq, }; static int tps6598x_probe(struct i2c_client *client) diff --git a/drivers/usb/typec/tipd/trace.h b/drivers/usb/typec/tipd/trace.h index 12cad1bde7cc..28725234a2d8 100644 --- a/drivers/usb/typec/tipd/trace.h +++ b/drivers/usb/typec/tipd/trace.h @@ -74,6 +74,13 @@ { APPLE_CD_REG_INT_DATA_STATUS_UPDATE, "DATA_STATUS_UPDATE" }, \ { APPLE_CD_REG_INT_STATUS_UPDATE, "STATUS_UPDATE" }) +#define show_tps25750_irq_flags(flags) \ + __print_flags_u64(flags, "|", \ + { TPS_REG_INT_PLUG_EVENT, "PLUG_EVENT" }, \ + { TPS_REG_INT_POWER_STATUS_UPDATE, "POWER_STATUS_UPDATE" }, \ + { TPS_REG_INT_STATUS_UPDATE, "STATUS_UPDATE" }, \ + { TPS_REG_INT_PD_STATUS_UPDATE, "PD_STATUS_UPDATE" }) + #define TPS6598X_STATUS_FLAGS_MASK (GENMASK(31, 0) ^ (TPS_STATUS_CONN_STATE_MASK | \ TPS_STATUS_PP_5V0_SWITCH_MASK | \ TPS_STATUS_PP_HV_SWITCH_MASK | \ @@ -230,6 +237,21 @@ TRACE_EVENT(cd321x_irq, show_cd321x_irq_flags(__entry->event)) ); +TRACE_EVENT(tps25750_irq, + TP_PROTO(u64 event), + TP_ARGS(event), + + TP_STRUCT__entry( + __field(u64, event) + ), + + TP_fast_assign( + __entry->event = event; + ), + + TP_printk("event=%s", show_tps25750_irq_flags(__entry->event)) +); + TRACE_EVENT(tps6598x_status, TP_PROTO(u32 status), TP_ARGS(status), From patchwork Sat Sep 23 07:39:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abdel Alkuor X-Patchwork-Id: 143898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp165142vqu; Sat, 23 Sep 2023 06:05:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk71956WtOudSSiMh6IB6uXdeOSLUaxI8EzJeJM5Rri0pUFhacQk63yEO6IhGjz/GnRA6y X-Received: by 2002:a05:6a20:8f06:b0:145:47af:57d8 with SMTP id b6-20020a056a208f0600b0014547af57d8mr2865672pzk.2.1695474334378; Sat, 23 Sep 2023 06:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695474334; cv=none; d=google.com; s=arc-20160816; b=C/o4knZ7M8VDdcDPF/mjShNsG3p5/8HQl0CzbYZ++RPRbbMbuBUtr3A42qyKMRWw6X BpQnfFr2nfzf/NGd0DTwa5Ztl17zWnJvRtRftY8h7OUhiLOkxxoQGp6usNjW0DTuoyVf piaonNwTD5fG8Qkn76toUjpJHSUIkkVKVnEFb6mmW6Ygt2d6G/Pe4vhjbkLK6fnwSAZL ujhHo5Zu2ZsO3FbEd2ekmToG0IkNRaXaLY+q1bUJ8t9zW+hMkyfct28iphhmfLW+g/Ej nQoF4S8EkJkLbSUI+/LzAhG9GKTghI6Y1kR/uQe07nazJ66QjJs0AwufYlv5I7Fpwv6W zy4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VFRprVF8T6twSRScySzSwWxXFkNe84Dxw0ZjvDU4rH8=; fh=UDTK5wkdLkKA1RzU/KF6Y0FI+lzcfubocuuGO7tFl2w=; b=qx7gyLmFUS8/kRH5XkQlF2ipBkwRDTJb9EFKeqrNgNigqxPRIMdhbLGAF8XLrRDbsI LMq9Au9c9UoEomaKRsCfdjgo8Kc0+O1eP6dEVzw4o1uqtCN3+AC7qzse3oQ+67+Dwd6/ Ak2Y+WEQCyXjfyQbYdLRYpJ2chvNpgqLZ3okC1o87OPRs6FuAAlNNiAzSozdqiKzCx2X 9I9asfWYhff0kGm9ICEfDB1S2yyxSgzRQopSNGad+2XtJUSi2A1nVfyB97Uxcv8smlsd 4UUCFJG0M2z2jIoNPxmcZBu4Z8liPpFXBOi+oTlrcGmqhyugIg5Z0Jf4RMA00V43vmQ1 lE1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XH9XUUVR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id cq23-20020a056a00331700b0068e3b121545si5917836pfb.58.2023.09.23.06.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 06:05:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XH9XUUVR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id CDE41818C78E; Sat, 23 Sep 2023 00:42:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbjIWHlw (ORCPT + 29 others); Sat, 23 Sep 2023 03:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjIWHlk (ORCPT ); Sat, 23 Sep 2023 03:41:40 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13181E5E; Sat, 23 Sep 2023 00:40:58 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-307d20548adso2852253f8f.0; Sat, 23 Sep 2023 00:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695454857; x=1696059657; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VFRprVF8T6twSRScySzSwWxXFkNe84Dxw0ZjvDU4rH8=; b=XH9XUUVRxcFpWMUQGiZLjVCumR8xtRY0RJ6pmiEyU2taSxAckChJO2tOMn7GxB9tPH sDNaaldungjOaLiSNuB4xpRsS3btdAfaQcCMPs/6UZeV4YcFLPSORtVZcVS3uILeMadK nYnFcZokQqgWI2qYKje/4iGAFYtgII+W0AslZdWEEpMI/mogSJH3VLtqp4AVQ/qZ4TXQ GlY2HKmdc4G7ke6UUYOCYHlArKEEJSs+L09ljoRAG4ogGVhogTMSUy+2s57u+OgHDA1P /clCjdc66KPXGm11I+vmuy/QdgN8pV8Ku8giAWnqFzwIEXXX7q6mCzpkC3SJ4oSMtddk Hl4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695454857; x=1696059657; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VFRprVF8T6twSRScySzSwWxXFkNe84Dxw0ZjvDU4rH8=; b=BzRkas67prZMib2+uC+S6WLtUTvwRvUD6qcHskPbNNC3BZcwwbOwKCXP4WyRuR1fYo Rag3ks8zx1a1v1vYEvh0Pjs+8SV7MjbtCP/9cJJO2wVhzrijQsXmTQ0gRNLDatkMRMXs iuPLv7Xbf1OfjaKqGUH60h14sfUr8i5Xatv0J6ILJVDsHKFUXQ+BLNWga8OHMnqQeCYj VX6ysCFY02p1osyedy731NmIIffs9VwQTDPh/DmysRdCovEIwCc/z42NxRMhItcasHoh EvQ+3RXz0SvvMRCZpfxB/Z8u63nMggVoZD+0nMR3VrQsQ8n73Zkf5PQhcAYdEFp+6Fc/ GgHA== X-Gm-Message-State: AOJu0YzGWUQvZ8UjOzDJxQGPz7/uVEsFAbgnRtcXvJTS5jOpObEJpY2T H9dSZ1RLIV/PQy8FBG2+5SN7y3Q0anmHUpO+myQ= X-Received: by 2002:a5d:4fc9:0:b0:320:7272:8fbe with SMTP id h9-20020a5d4fc9000000b0032072728fbemr1765631wrw.17.1695454857228; Sat, 23 Sep 2023 00:40:57 -0700 (PDT) Received: from primary.. ([213.139.62.222]) by smtp.gmail.com with ESMTPSA id k6-20020adfe3c6000000b003196e992567sm6236955wrm.115.2023.09.23.00.40.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 00:40:56 -0700 (PDT) From: Abdel Alkuor To: heikki.krogerus@linux.intel.com, krzysztof.kozlowski+dt@linaro.org, bryan.odonoghue@linaro.org Cc: gregkh@linuxfoundation.org, robh+dt@kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, conor+dt@kernel.org, ryan.eleceng@gmail.com, Abdel Alkuor Subject: [PATCH v6 13/14] USB: typec: Add power status trace for tps25750 Date: Sat, 23 Sep 2023 03:39:58 -0400 Message-Id: <20230923073959.86660-14-alkuor@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923073959.86660-1-alkuor@gmail.com> References: <20230923073959.86660-1-alkuor@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 23 Sep 2023 00:42:05 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777833695914063298 X-GMAIL-MSGID: 1777833695914063298 From: Abdel Alkuor tps25750 power status register is a subset of tps6598x power status register. Signed-off-by: Abdel Alkuor --- Changes in v6: - Add trace power status to tipd data factory Changes in v5: - Incorporating tps25750 into tps6598x driver drivers/usb/typec/tipd/core.c | 8 +++++++- drivers/usb/typec/tipd/tps6598x.h | 19 ++++++++++++++++++ drivers/usb/typec/tipd/trace.h | 33 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c index a1acf682bde0..e8190f1f57ad 100644 --- a/drivers/usb/typec/tipd/core.c +++ b/drivers/usb/typec/tipd/core.c @@ -111,6 +111,7 @@ struct tipd_data { int (*clear_events)(struct tps6598x *tps, void *events); int (*register_port)(struct tps6598x *tps, struct fwnode_handle *node); void (*trace_irq)(void *events); + void (*trace_power_status)(u16 status); }; struct tps6598x { @@ -501,7 +502,9 @@ static bool tps6598x_read_power_status(struct tps6598x *tps) return false; } tps->pwr_status = pwr_status; - trace_tps6598x_power_status(pwr_status); + + if (tps->cb.trace_power_status) + tps->cb.trace_power_status(pwr_status); return true; } @@ -1146,6 +1149,7 @@ tps25750_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode) static const struct tipd_data cd321x_data = { .irq_handler = cd321x_interrupt, .register_port = tps6598x_register_port, + .trace_power_status = trace_tps6598x_power_status, }; static const struct tipd_data tps6598x_data = { @@ -1154,6 +1158,7 @@ static const struct tipd_data tps6598x_data = { .clear_events = tps6598x_clear_events, .register_port = tps6598x_register_port, .trace_irq = tps6598x_trace_irq, + .trace_power_status = trace_tps6598x_power_status, }; static const struct tipd_data tps25750_data = { @@ -1162,6 +1167,7 @@ static const struct tipd_data tps25750_data = { .clear_events = tps25750_clear_events, .register_port = tps25750_register_port, .trace_irq = tps25750_trace_irq, + .trace_power_status = trace_tps25750_power_status, }; static int tps6598x_probe(struct i2c_client *client) diff --git a/drivers/usb/typec/tipd/tps6598x.h b/drivers/usb/typec/tipd/tps6598x.h index f86b5e96efba..01609bf509e4 100644 --- a/drivers/usb/typec/tipd/tps6598x.h +++ b/drivers/usb/typec/tipd/tps6598x.h @@ -161,6 +161,25 @@ #define TPS_POWER_STATUS_BC12_STATUS_CDP 2 #define TPS_POWER_STATUS_BC12_STATUS_DCP 3 +/* TPS25750_REG_POWER_STATUS bits */ +#define TPS25750_POWER_STATUS_CHARGER_DETECT_STATUS_MASK GENMASK(7, 4) +#define TPS25750_POWER_STATUS_CHARGER_DETECT_STATUS(p) \ + TPS_FIELD_GET(TPS25750_POWER_STATUS_CHARGER_DETECT_STATUS_MASK, (p)) +#define TPS25750_POWER_STATUS_CHARGER_ADVERTISE_STATUS_MASK GENMASK(9, 8) +#define TPS25750_POWER_STATUS_CHARGER_ADVERTISE_STATUS(p) \ + TPS_FIELD_GET(TPS25750_POWER_STATUS_CHARGER_ADVERTISE_STATUS_MASK, (p)) + +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DISABLED 0 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_IN_PROGRESS 1 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_NONE 2 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_SPD 3 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_BC_1_2_CPD 4 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_BC_1_2_DPD 5 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DIV_1_DCP 6 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DIV_2_DCP 7 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DIV_3_DCP 8 +#define TPS25750_POWER_STATUS_CHARGER_DET_STATUS_1_2V_DCP 9 + /* TPS_REG_DATA_STATUS bits */ #define TPS_DATA_STATUS_DATA_CONNECTION BIT(0) #define TPS_DATA_STATUS_UPSIDE_DOWN BIT(1) diff --git a/drivers/usb/typec/tipd/trace.h b/drivers/usb/typec/tipd/trace.h index 28725234a2d8..739b0a2a867d 100644 --- a/drivers/usb/typec/tipd/trace.h +++ b/drivers/usb/typec/tipd/trace.h @@ -166,6 +166,19 @@ { TPS_POWER_STATUS_BC12_STATUS_CDP, "cdp" }, \ { TPS_POWER_STATUS_BC12_STATUS_SDP, "sdp" }) +#define show_tps25750_power_status_charger_detect_status(power_status) \ + __print_symbolic(TPS25750_POWER_STATUS_CHARGER_DETECT_STATUS(power_status), \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DISABLED, "disabled"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_IN_PROGRESS, "in progress"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_NONE, "none"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_SPD, "spd"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_BC_1_2_CPD, "cpd"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_BC_1_2_DPD, "dpd"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DIV_1_DCP, "divider 1 dcp"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DIV_2_DCP, "divider 2 dcp"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_DIV_3_DCP, "divider 3 dpc"}, \ + { TPS25750_POWER_STATUS_CHARGER_DET_STATUS_1_2V_DCP, "1.2V dpc"}) + #define TPS_DATA_STATUS_FLAGS_MASK (GENMASK(31, 0) ^ (TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK | \ TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK | \ TPS_DATA_STATUS_TBT_CABLE_GEN_MASK)) @@ -299,6 +312,26 @@ TRACE_EVENT(tps6598x_power_status, ) ); +TRACE_EVENT(tps25750_power_status, + TP_PROTO(u16 power_status), + TP_ARGS(power_status), + + TP_STRUCT__entry( + __field(u16, power_status) + ), + + TP_fast_assign( + __entry->power_status = power_status; + ), + + TP_printk("conn: %d, pwr-role: %s, typec: %s, charger detect: %s", + !!TPS_POWER_STATUS_CONNECTION(__entry->power_status), + show_power_status_source_sink(__entry->power_status), + show_power_status_typec_status(__entry->power_status), + show_tps25750_power_status_charger_detect_status(__entry->power_status) + ) +); + TRACE_EVENT(tps6598x_data_status, TP_PROTO(u32 data_status), TP_ARGS(data_status),