From: Melody Olvera <quic_molvera@quicinc.com>
To: Souradeep Chowdhury <quic_schowdhu@quicinc.com>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Trilok Soni <quic_tsoni@quicinc.com>,
Satya Durga Srinivasu Prabhala <quic_satyap@quicinc.com>,
Elson Serrao <quic_eserrao@quicinc.com>
Cc: <cros-qcom-dts-watchers@chromium.org>,
<linux-arm-msm@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
Melody Olvera <quic_molvera@quicinc.com>
Subject: [PATCH v1 2/3] usb: misc: qcom_eud: Access mode manager through secure calls
Date: Wed, 7 Aug 2024 11:32:03 -0700 [thread overview]
Message-ID: <20240807183205.803847-3-quic_molvera@quicinc.com> (raw)
In-Reply-To: <20240807183205.803847-1-quic_molvera@quicinc.com>
On many SoCs, the EUD mode manager needs to be accessed through
calls to the secure monitor, so add a compatible string and a config
to assess how the mode manager must be accessed and change behavior
accordingly.
Signed-off-by: Melody Olvera <quic_molvera@quicinc.com>
---
drivers/usb/misc/qcom_eud.c | 53 ++++++++++++++++++++++++++++++++-----
1 file changed, 47 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/misc/qcom_eud.c b/drivers/usb/misc/qcom_eud.c
index 19906301a4eb..77ef089a3ebf 100644
--- a/drivers/usb/misc/qcom_eud.c
+++ b/drivers/usb/misc/qcom_eud.c
@@ -5,6 +5,7 @@
#include <linux/bitops.h>
#include <linux/err.h>
+#include <linux/firmware/qcom/qcom_scm.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/iopoll.h>
@@ -35,18 +36,31 @@ struct eud_chip {
struct usb_role_switch *role_sw;
void __iomem *base;
void __iomem *mode_mgr;
+ phys_addr_t mode_mgr_phys;
unsigned int int_status;
int irq;
bool enabled;
bool usb_attached;
};
+struct eud_cfg {
+ bool secure_eud_en;
+};
+
static int enable_eud(struct eud_chip *priv)
{
+ int ret;
+
writel(EUD_ENABLE, priv->base + EUD_REG_CSR_EUD_EN);
writel(EUD_INT_VBUS | EUD_INT_SAFE_MODE,
priv->base + EUD_REG_INT1_EN_MASK);
- writel(1, priv->mode_mgr + EUD_REG_EUD_EN2);
+ if (priv->mode_mgr_phys && !priv->mode_mgr) {
+ ret = qcom_scm_io_writel(priv->mode_mgr_phys + EUD_REG_EUD_EN2, 1);
+ if (ret)
+ return ret;
+ } else {
+ writel(1, priv->mode_mgr + EUD_REG_EUD_EN2);
+ }
return usb_role_switch_set_role(priv->role_sw, USB_ROLE_DEVICE);
}
@@ -54,7 +68,10 @@ static int enable_eud(struct eud_chip *priv)
static void disable_eud(struct eud_chip *priv)
{
writel(0, priv->base + EUD_REG_CSR_EUD_EN);
- writel(0, priv->mode_mgr + EUD_REG_EUD_EN2);
+ if (priv->mode_mgr_phys && !priv->mode_mgr)
+ qcom_scm_io_writel(priv->mode_mgr_phys + EUD_REG_EUD_EN2, 0);
+ else
+ writel(0, priv->mode_mgr + EUD_REG_EUD_EN2);
}
static ssize_t enable_show(struct device *dev,
@@ -178,6 +195,8 @@ static void eud_role_switch_release(void *data)
static int eud_probe(struct platform_device *pdev)
{
struct eud_chip *chip;
+ struct resource *res;
+ const struct eud_cfg *cfg;
int ret;
chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
@@ -200,9 +219,22 @@ static int eud_probe(struct platform_device *pdev)
if (IS_ERR(chip->base))
return PTR_ERR(chip->base);
- chip->mode_mgr = devm_platform_ioremap_resource(pdev, 1);
- if (IS_ERR(chip->mode_mgr))
- return PTR_ERR(chip->mode_mgr);
+ cfg = of_device_get_match_data(&pdev->dev);
+ if (!cfg)
+ return -EINVAL;
+
+ if (cfg->secure_eud_en) {
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ if (!res)
+ return -ENODEV;
+ chip->mode_mgr_phys = res->start;
+ chip->mode_mgr = NULL;
+ } else {
+ chip->mode_mgr = devm_platform_ioremap_resource(pdev, 1);
+ if (IS_ERR(chip->mode_mgr))
+ return PTR_ERR(chip->mode_mgr);
+ chip->mode_mgr_phys = 0;
+ }
chip->irq = platform_get_irq(pdev, 0);
if (chip->irq < 0)
@@ -231,8 +263,17 @@ static void eud_remove(struct platform_device *pdev)
disable_irq_wake(chip->irq);
}
+static const struct eud_cfg nonsecure_eud = {
+ .secure_eud_en = false,
+};
+
+static const struct eud_cfg secure_eud = {
+ .secure_eud_en = true,
+};
+
static const struct of_device_id eud_dt_match[] = {
- { .compatible = "qcom,eud" },
+ { .compatible = "qcom,eud", .data = &nonsecure_eud },
+ { .compatible = "qcom,secure-eud", .data = &secure_eud },
{ }
};
MODULE_DEVICE_TABLE(of, eud_dt_match);
--
2.45.2
next prev parent reply other threads:[~2024-08-07 18:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-07 18:32 [PATCH v1 0/3] Add compatibles for different eud access modes Melody Olvera
2024-08-07 18:32 ` [PATCH v1 1/3] dt-bindings: soc: qcom: eud: Update compatible strings for eud Melody Olvera
2024-08-08 11:00 ` Krzysztof Kozlowski
2024-08-13 20:03 ` Melody Olvera
2024-08-14 6:15 ` Krzysztof Kozlowski
2024-08-14 10:30 ` Konrad Dybcio
2024-08-14 17:33 ` Melody Olvera
2024-08-14 20:25 ` Konrad Dybcio
2024-08-14 22:09 ` Trilok Soni
2024-08-20 18:21 ` Melody Olvera
2024-08-20 19:19 ` Konrad Dybcio
2024-08-21 6:48 ` Krzysztof Kozlowski
2024-08-21 17:27 ` Konrad Dybcio
2024-08-14 17:20 ` Melody Olvera
2024-08-07 18:32 ` Melody Olvera [this message]
2024-08-07 18:32 ` [PATCH v1 3/3] arm64: dts: qcom: sc7280: Update eud compatible string Melody Olvera
2024-08-08 11:03 ` Krzysztof Kozlowski
2024-08-13 20:05 ` Melody Olvera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240807183205.803847-3-quic_molvera@quicinc.com \
--to=quic_molvera@quicinc.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=cros-qcom-dts-watchers@chromium.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_eserrao@quicinc.com \
--cc=quic_satyap@quicinc.com \
--cc=quic_schowdhu@quicinc.com \
--cc=quic_tsoni@quicinc.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox