From patchwork Tue Aug 16 19:11:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 598441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE2D2C32772 for ; Tue, 16 Aug 2022 19:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236914AbiHPTMA (ORCPT ); Tue, 16 Aug 2022 15:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236912AbiHPTL6 (ORCPT ); Tue, 16 Aug 2022 15:11:58 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ADAB7D7B1 for ; Tue, 16 Aug 2022 12:11:55 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-334d894afd8so2263487b3.19 for ; Tue, 16 Aug 2022 12:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=X/YkdclUGRbmTWtx7pCDnwB6JcrES8yYvjN/AvuuOws=; b=JBdb3tVJtQfGAYooIHg8G+7xnscUXc++JpjvqR7BGlAPRhgIIj4wkFphcp86Z7i9NS PUJfpaF9JABxy8z2VQV3FQZZEqBYabfppu4jrHtpOD56BqjYQxHKiQ+FLCpcze4CsMNc Pamq6on1eG5br1FaYUz/d9wClBGS7YVZ+OmViTijj5PliDle+4Jp/Y3hhT7fu4m3r56U zbkP7GNwE54SrFjfa1EswAu26i3mlhuTOB3uh6xAwygXwr2rp0sjfnSzYfgSJyuh0A1A hmQLFAPLg1jbc9spY8ABgKRzroNWadrB5VVQSuoJ74O6EGAiLHAMZj6QCKVyEWAGf+qC 6Gyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=X/YkdclUGRbmTWtx7pCDnwB6JcrES8yYvjN/AvuuOws=; b=X2+fD9aGVLTcFYnbX24r90SpIXGscCsDr4ND/2AH1sIy5r36szNyqi3Ktu87YX0Lx5 JOC56ELcWybdugSUr8n3ExW5NBteGXTs/+Cd6a8ZWmiDr+htqWPqVcyJ6+8LUAFSmdIb jgQCT+nuJ3AdET4sn7izbW+TlTGy4hk6Z5wlckN4w6sXh61XWjUFkNcFaVJDPdo3evfC 9HDdm1a+TiJquhT+TOdMzexc8x9dMJw8urtUpSxmxJyxe1jNMeuEQF9cTe1kogJ1UHIm MoquwSznugAxto0OB80ChmXxgy7PbD/+bL9i21TvEn3lAbiZcNoQEpGPGLTRC+jt7owk r0WQ== X-Gm-Message-State: ACgBeo2+2chazStOKNxjd3577gSrj3y7AIfy7uHu70dTtwF81bjb5c1e i/KlWFFF/XbtkEs0TvgNLRZakNf9HSE= X-Google-Smtp-Source: AA6agR7Ej5XeN1kk6sRNudElC0yOv+aIVrLG/331kS3Qv0cvLOVPouvYbE4PRfNshRSWWbsHNbvnpkTNarM= X-Received: from badhri.mtv.corp.google.com ([2620:15c:211:201:2019:e66e:d39a:1a4c]) (user=badhri job=sendgmr) by 2002:a25:e756:0:b0:68f:f129:243c with SMTP id e83-20020a25e756000000b0068ff129243cmr117948ybh.493.1660677114308; Tue, 16 Aug 2022 12:11:54 -0700 (PDT) Date: Tue, 16 Aug 2022 12:11:50 -0700 Message-Id: <20220816191150.1432166-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH v2] usb: typec: tcpm: Return ENOTSUPP for power supply prop writes From: Badhri Jagan Sridharan To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso , stable@vger.kernel.org, Badhri Jagan Sridharan Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When the port does not support USB PD, prevent transition to PD only states when power supply property is written. In this case, TCPM transitions to SNK_NEGOTIATE_CAPABILITIES which should not be the case given that the port is not pd_capable. [ 84.308251] state change SNK_READY -> SNK_NEGOTIATE_CAPABILITIES [rev3 NONE_AMS] [ 84.308335] Setting usb_comm capable false [ 84.323367] set_auto_vbus_discharge_threshold mode:3 pps_active:n vbus:5000 ret:0 [ 84.323376] state change SNK_NEGOTIATE_CAPABILITIES -> SNK_WAIT_CAPABILITIES [rev3 NONE_AMS] Fixes: e9e6e164ed8f6 ("usb: typec: tcpm: Support non-PD mode") Signed-off-by: Badhri Jagan Sridharan --- Changes since v1: - Add Fixes tag. --- drivers/usb/typec/tcpm/tcpm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index ea5a917c51b1..904c7b4ce2f0 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -6320,6 +6320,13 @@ static int tcpm_psy_set_prop(struct power_supply *psy, struct tcpm_port *port = power_supply_get_drvdata(psy); int ret; + /* + * All the properties below are related to USB PD. The check needs to be + * property specific when a non-pd related property is added. + */ + if (!port->pd_supported) + return -EOPNOTSUPP; + switch (psp) { case POWER_SUPPLY_PROP_ONLINE: ret = tcpm_psy_set_online(port, val);