From patchwork Wed Oct 25 11:49:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 738428 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 BB239C07545 for ; Wed, 25 Oct 2023 11:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234926AbjJYL41 (ORCPT ); Wed, 25 Oct 2023 07:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjJYL40 (ORCPT ); Wed, 25 Oct 2023 07:56:26 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BDCD12A for ; Wed, 25 Oct 2023 04:56:24 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-507c8316abcso7451522e87.1 for ; Wed, 25 Oct 2023 04:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698234982; x=1698839782; 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=OgafwTCUkzd/7BTG9BN3pSpU4yRcAwFDImAKova/XoA=; b=jcjJUlh5ZzvkM1V6/GDDWV2U3VGj/czgiX4G7LIW0YezENPjGEKC4oZD1e2jaYS6pc pTIrW4KvBunkGPEcYXlW1Na06H2YZX0JloBhfPtyk/mxyGyMFM14Tf3WSiewyhox736p 3C6Feqwkqj8KeCelfy9ce3kgx8Gf5CDEYkUq04ldcndJMPHtjnirc29drtlVosAN1b6B PvELXPmBFJeAdibQPo3itf2Q26Mc5/qyV/GdNqF2/4l+idHD7Jvpj5B6ZbmpYzblP2pO Uszi1hhlYC5R3DHUzMMBWq24IwkjCkYVVyOew2wIO/H10PxGE02L8tC7CBw301HVskuF 3zAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698234982; x=1698839782; 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=OgafwTCUkzd/7BTG9BN3pSpU4yRcAwFDImAKova/XoA=; b=hrzuTBXPTDvHMFkS+MuIxYYgFLmzodfdpBuisr4McV0NFQ78qmcnTfhzQfXFetMAlb +eSym7afnTIzB5nxqjd4/D6KJ2SVX+RpnFFADQUPrHjnMHOI8OUJjMYiTxy6739mOL+p Nv5UhbAH/ZB1il7+iyGOyfwiJ+Lh2bAj980PVBqptseefbkkL93n9SUXtNGWfZWhTkMj IAoUifoKMlt6PfUyYc5mf99RKlRds3YgmcoV/GfMiPCTRb1UXrHAqbT6/SYfzEEB86Kp oyuKoHzGLI5SzHKwCR7ffUero6CTAsh5VS7RQWvZ56Jc5GB7jU3v6oET8VSly4HmGRVZ pt7g== X-Gm-Message-State: AOJu0Yx81KgQyM3AjDrY7noMWUb0WjdAmoC6f5ai1ua82VSxMSq5x1++ ljH0NDej4FKISlNRGjuyg8Z7Gg== X-Google-Smtp-Source: AGHT+IHEIBCnx7OnsCe5XYKl5N63Ra0I89CUF8iLcsMYFynDWvY4bHIMX8F4T9v8aDlCUP1hxBLdww== X-Received: by 2002:a05:6512:3c8f:b0:507:cd39:a005 with SMTP id h15-20020a0565123c8f00b00507cd39a005mr13071713lfv.39.1698234982595; Wed, 25 Oct 2023 04:56:22 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id 22-20020ac25f56000000b004fde41a2059sm2511751lfz.305.2023.10.25.04.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 04:56:22 -0700 (PDT) From: Dmitry Baryshkov To: Heikki Krogerus , Greg Kroah-Hartman , Andy Gross , Bjorn Andersson , Konrad Dybcio , Neil Armstrong Cc: Rob Herring , linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v2 1/2] usb: typec: ucsi: fix UCSI on buggy Qualcomm devices Date: Wed, 25 Oct 2023 14:49:29 +0300 Message-ID: <20231025115620.905538-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231025115620.905538-1-dmitry.baryshkov@linaro.org> References: <20231025115620.905538-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On sevral Qualcomm platforms (SC8180X, SM8350, SC8280XP) a call to UCSI_GET_PDOS for non-PD partners will cause a firmware crash with no easy way to recover from it. Since we have no easy way to determine whether the partner really has PD support, shortcut UCSI_GET_PDOS on such platforms. This allows us to enable UCSI support on such devices. Signed-off-by: Dmitry Baryshkov Acked-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 3 +++ drivers/usb/typec/ucsi/ucsi.h | 3 +++ drivers/usb/typec/ucsi/ucsi_glink.c | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 61b64558f96c..5392ec698959 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -578,6 +578,9 @@ static int ucsi_read_pdos(struct ucsi_connector *con, u64 command; int ret; + if (ucsi->quirks & UCSI_NO_PARTNER_PDOS) + return 0; + command = UCSI_COMMAND(UCSI_GET_PDOS) | UCSI_CONNECTOR_NUMBER(con->num); command |= UCSI_GET_PDOS_PARTNER_PDO(is_partner); command |= UCSI_GET_PDOS_PDO_OFFSET(offset); diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 474315a72c77..6478016d5cb8 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -317,6 +317,9 @@ struct ucsi { #define EVENT_PENDING 0 #define COMMAND_PENDING 1 #define ACK_PENDING 2 + + unsigned long quirks; +#define UCSI_NO_PARTNER_PDOS BIT(0) /* Don't read partner's PDOs */ }; #define UCSI_MAX_SVID 5 diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c index db6e248f8208..a94e2df6fd45 100644 --- a/drivers/usb/typec/ucsi/ucsi_glink.c +++ b/drivers/usb/typec/ucsi/ucsi_glink.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -296,11 +297,19 @@ static void pmic_glink_ucsi_destroy(void *data) mutex_unlock(&ucsi->lock); } +static const struct of_device_id pmic_glink_ucsi_of_quirks[] = { + { .compatible = "qcom,sc8180x-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, }, + { .compatible = "qcom,sc8280xp-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, }, + { .compatible = "qcom,sm8350-pmic-glink", .data = (void *)UCSI_NO_PARTNER_PDOS, }, + {} +}; + static int pmic_glink_ucsi_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id) { struct pmic_glink_ucsi *ucsi; struct device *dev = &adev->dev; + const struct of_device_id *match; struct fwnode_handle *fwnode; int ret; @@ -327,6 +336,10 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev, if (ret) return ret; + match = of_match_device(pmic_glink_ucsi_of_quirks, dev->parent); + if (match) + ucsi->ucsi->quirks = (unsigned long)match->data; + ucsi_set_drvdata(ucsi->ucsi, ucsi); device_for_each_child_node(dev, fwnode) { From patchwork Wed Oct 25 11:49:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 737956 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 6626AC25B47 for ; Wed, 25 Oct 2023 11:56:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232666AbjJYL43 (ORCPT ); Wed, 25 Oct 2023 07:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233317AbjJYL41 (ORCPT ); Wed, 25 Oct 2023 07:56:27 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE7F182 for ; Wed, 25 Oct 2023 04:56:25 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-507cee17b00so8194697e87.2 for ; Wed, 25 Oct 2023 04:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698234983; x=1698839783; 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=FwKoRn1S3grUkj3T+P+0SLhXPECqB0f/S2wVYwKKKrw=; b=wywRBGAYCTFOg1YlDFolwLM4oiq53GZoYqfbmC6JTndmc7K36s/sVcAjFgLEhnrmqY WAA8Lp0uU86eskDBuFP9XoEsGF6VXLwQyoDioQEnaIlG/PARMV52HDTCEsdJbIrvI5QN XNk1fuN597rURYuO3qRYNYs2bxcm5Y37lXnNTkep8/7RjuoSv4ysgccqpf2yVqzLsgTG ZAcUnM4WTB43Arndw550xm4GJ8bZxr+VSnhFaaM4114LJCmV4xwDur8f/5CnruTYIuo2 HYI3pq02Q1ban+qt2wyGV21bRW26gzEOxi04ccPUN2VGYHYkzsxW1+5jF/lgEZTcNg3/ jqwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698234983; x=1698839783; 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=FwKoRn1S3grUkj3T+P+0SLhXPECqB0f/S2wVYwKKKrw=; b=aR7pBws0fGB7uLkwuUBfPGGlsRRFGwgZKhR2Z9dTzi68lnhMCwB/hGqV1Q6xbyk6Nz S0H5phVwhY6Rs877JFWBnX/KCrJeXszv/nUYI/R6Zzbu3b8AhNMnRDkJJMAI63Igb9k+ W8xlxjRCmRZ16b5KTu/+sBeH07Ju1RO3QdAwVz8nTtLVdZiMaqCtwgSwV8Vf7lx9/sLu icBU0vAVkDkn1P42jzBg+9zogGmqj/cfqmk4xpNc2R4LvXBwz/EiWQXw84ORBiEyzu83 Dyqmu5+5m3jq6dL94C21xKFLitPedTmPici8SyJJ2FVpQT5NOfeOjzAemoEjkpsFhy00 LScQ== X-Gm-Message-State: AOJu0Yw40F45LeuDhwfSc8xGtjF3rXKJJ9vM+MHea6/UEAzii/Lm4Bn8 +23jc87NpBdvoSyC3objxIr+Ng== X-Google-Smtp-Source: AGHT+IHVl0hvJGVOtsM48MxwtP1bLdahgW8rvBkoJexq6T0r5k2WH0HRFRiy+gmOHZV2HATZeoH86g== X-Received: by 2002:a05:6512:3d23:b0:508:1227:5a0f with SMTP id d35-20020a0565123d2300b0050812275a0fmr2575756lfv.65.1698234983371; Wed, 25 Oct 2023 04:56:23 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id 22-20020ac25f56000000b004fde41a2059sm2511751lfz.305.2023.10.25.04.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 04:56:22 -0700 (PDT) From: Dmitry Baryshkov To: Heikki Krogerus , Greg Kroah-Hartman , Andy Gross , Bjorn Andersson , Konrad Dybcio , Neil Armstrong Cc: Rob Herring , linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v2 2/2] soc: qcom: pmic_glink: enable UCSI by default Date: Wed, 25 Oct 2023 14:49:30 +0300 Message-ID: <20231025115620.905538-3-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231025115620.905538-1-dmitry.baryshkov@linaro.org> References: <20231025115620.905538-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Now as the issue with the UCSI_GET_PDOS is worked around, enable UCSI support for all PMIC_GLINK platforms except Qualcomm SC8180X. The mentioned SoC has slightly different UCSI implementation, which I would like be tested properly before enabling it. Signed-off-by: Dmitry Baryshkov Reviewed-by: Neil Armstrong --- drivers/soc/qcom/pmic_glink.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/soc/qcom/pmic_glink.c b/drivers/soc/qcom/pmic_glink.c index 914057331afd..71d8901a9389 100644 --- a/drivers/soc/qcom/pmic_glink.c +++ b/drivers/soc/qcom/pmic_glink.c @@ -18,9 +18,6 @@ enum { PMIC_GLINK_CLIENT_UCSI, }; -#define PMIC_GLINK_CLIENT_DEFAULT (BIT(PMIC_GLINK_CLIENT_BATT) | \ - BIT(PMIC_GLINK_CLIENT_ALTMODE)) - struct pmic_glink { struct device *dev; struct pdr_handle *pdr; @@ -263,10 +260,10 @@ static int pmic_glink_probe(struct platform_device *pdev) mutex_init(&pg->state_lock); match_data = (unsigned long *)of_device_get_match_data(&pdev->dev); - if (match_data) - pg->client_mask = *match_data; - else - pg->client_mask = PMIC_GLINK_CLIENT_DEFAULT; + if (!match_data) + return -EINVAL; + + pg->client_mask = *match_data; if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) { ret = pmic_glink_add_aux_device(pg, &pg->ucsi_aux, "ucsi"); @@ -336,14 +333,16 @@ static void pmic_glink_remove(struct platform_device *pdev) mutex_unlock(&__pmic_glink_lock); } +static const unsigned long pmic_glink_sc8180x_client_mask = BIT(PMIC_GLINK_CLIENT_BATT) | + BIT(PMIC_GLINK_CLIENT_ALTMODE); + static const unsigned long pmic_glink_sm8450_client_mask = BIT(PMIC_GLINK_CLIENT_BATT) | BIT(PMIC_GLINK_CLIENT_ALTMODE) | BIT(PMIC_GLINK_CLIENT_UCSI); static const struct of_device_id pmic_glink_of_match[] = { - { .compatible = "qcom,sm8450-pmic-glink", .data = &pmic_glink_sm8450_client_mask }, - { .compatible = "qcom,sm8550-pmic-glink", .data = &pmic_glink_sm8450_client_mask }, - { .compatible = "qcom,pmic-glink" }, + { .compatible = "qcom,sc8180x-pmic-glink", .data = &pmic_glink_sc8180x_client_mask }, + { .compatible = "qcom,pmic-glink", .data = &pmic_glink_sm8450_client_mask }, {} }; MODULE_DEVICE_TABLE(of, pmic_glink_of_match);