From patchwork Sat Jan 13 20:55:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13519053 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF99FC4707C for ; Sat, 13 Jan 2024 20:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tKthAz1kC4y9u3mHlUA99UVON0Ldy5XBUQ/VjZ6bDhE=; b=p+9EAtEyaOoAfv Amd1oHZyQfng1E3APlNpxaKgsKmph3luehgFAw9Ymd6bORAeGgs/fWV496Bgwfa2PYIMpbYDaGdCZ bIAhr8nuB1b3IMYK++eDG312YmmMquzAy1tl2o4/jVx+6p5wS32mnnF6WvGvFLoNL+B5fWWKdeA1S oivTr7UUAgqw3IkRMjxG/P02l7WYwwwDtVKRwJlR7Nr40rTUrWvAAZcm9NhvrCKgRImUDuYajLZ1M jB5gTdiuSS/kKeWQDtf5zXPrV/HA40B9mh9vd1AqgUTtaN5TNsJdJ58pd1OdzklOjXiRVqrateNeh 45fkR8nAl0QdboHm6vhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rOl36-005gq2-28; Sat, 13 Jan 2024 20:56:12 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rOl30-005gjf-1n for linux-phy@lists.infradead.org; Sat, 13 Jan 2024 20:56:08 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50e7d6565b5so8863023e87.0 for ; Sat, 13 Jan 2024 12:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705179363; x=1705784163; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EDmXNNNMDIUsx3SecO6xUq1d/5Ek5JHAsPdmOAwi4V4=; b=LdfkNWRpInin+rUJC7jGnmUlb4cKcpUtCa4VcK6f2zl1sN++Q2m/3xIt9mkKMyGqpu XxQ5YemEbvPKbbhEpnRr3H+8P0ky1O6twTqSalcPTi+hrFYNhLdl9UBkRxK4IZR3ye0j exMUuJL5JOdW8nvnkc/rhcHERrJFy2kE8iu+E0ThZ2k/EUo2NTUXSAR+p3e8DRvyKD46 NEDMfRYU6mLphuO5Db8aUwRzIB7Xf0/PDm0IFch2j/rFVnWDlfI1s58MXN+bWoYvyh8v I58q1zmMseJZ8+wxVoi+aSaiveH4mv7plZBx9/R2pGUCU0yt4a7SERDG/M+1IC99PQor EGyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705179363; x=1705784163; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EDmXNNNMDIUsx3SecO6xUq1d/5Ek5JHAsPdmOAwi4V4=; b=lmpgad15BoZkp/0FS+nS8XDqZokdzcnHWjH9R0iNoVTZsclkbxWLZauIDXL0HG27xm +h6JBVjZWkH7hVTtNROwLPHtw2sUgtkdkO8ttpu1VmCErnJza5fweJ8bRgMsgPF0JZLG fR5yKluC3na8RDcPcLvrMpW5MZvLyqnXoX4nczfIE2n0kSJwYv1fa19vv2o8NEtk+z+D mWe9wICggbTxvmmqcS018cgiDnmkko5kQPep593Q2NJN66svTFGBkWSSQsNq+e2gqnzl /5F+Sc4JchaEn8I2Zrh3VM1mXxvfc9SIC+IK3L2c+aJvKfXDRLjVu+k8CN9TAl/PpSXY ULRw== X-Gm-Message-State: AOJu0YzH23aOX3IiidyH1sIGABVE4N9gO+dwJaiq2zeRcIfDmJHZ6rsx /6wMjGdyK7eCDiR7v2ADzjnyXZ5nunpBqA== X-Google-Smtp-Source: AGHT+IHg1ChbCZhYhZVrw3GoGq+oWnuqO7CKhbyVRPhKsJFnZBYWQnt2AS+4IMR8gs4bIWRNSuFg6Q== X-Received: by 2002:a19:9115:0:b0:50e:4fd8:d293 with SMTP id t21-20020a199115000000b0050e4fd8d293mr1526154lfd.124.1705179363099; Sat, 13 Jan 2024 12:56:03 -0800 (PST) Received: from umbar.lan ([192.130.178.91]) by smtp.gmail.com with ESMTPSA id p14-20020a056512328e00b0050e9355d7eesm919802lfe.103.2024.01.13.12.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jan 2024 12:56:02 -0800 (PST) From: Dmitry Baryshkov Date: Sat, 13 Jan 2024 22:55:55 +0200 Subject: [PATCH v2 12/15] phy: qcom: qmp-usbc: add support for the Type-C handling MIME-Version: 1.0 Message-Id: <20240113-pmi632-typec-v2-12-182d9aa0a5b3@linaro.org> References: <20240113-pmi632-typec-v2-0-182d9aa0a5b3@linaro.org> In-Reply-To: <20240113-pmi632-typec-v2-0-182d9aa0a5b3@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Wesley Cheng , Bryan O'Donoghue , Greg Kroah-Hartman , Vinod Koul , Kishon Vijay Abraham I , Guenter Roeck , Heikki Krogerus , Philipp Zabel Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-phy@lists.infradead.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=5165; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=AyyWXpZHbJcJG3JSjU+Vci0NPOyVsEJSPF3MW67UenM=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBlovjX7Ul2DQgqlUqachDmhog01C0SodaYjP0t9 arg9gqjLj+JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZaL41wAKCRCLPIo+Aiko 1fQzB/9dVLzfCNGXvel2vaFvwwCyM21MknDLKlm3leyef7xE88Jdl9+nbbt3kj9MfA9d9Xn6wyA yBfU6HRvwfp1OVgmyThFk2EDROuv+X0PvZC4X3G8e7xr65Fz/Paxmqnces5ZnBKuma6GkVPqadP 35jX0Aum4tkSU6bm25JxH1A+7k0Kt6wVWMP4vLmWJGKnjZ6LKsc5CyHtcBGgG4vscnUJ5NR+RMp xz0bUqc0+mzyImP+VUKj6UGoJfFzEVFy7zT+8pmoJENX8dgV+c/FzNUSG2T/7mJvt4CKLz1tmiS IiFAKIbS2O1ZTCNavaofNoyC/gzi8OVFAmtnT1kFgbDbEj4a X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240113_125606_605707_CF990482 X-CRM114-Status: GOOD ( 19.91 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org The USB-C PHYs on the msm8998, QCM2290 and SM6115 platforms use special register to control which lanes of the Type-C port are used for the SuperSpeed USB connection. Mimic the qmp-combo driver and handle this register. Signed-off-by: Dmitry Baryshkov --- drivers/phy/qualcomm/phy-qcom-qmp-usbc.c | 97 +++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c b/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c index 52f1b3f7b81e..214cf4203de4 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "phy-qcom-qmp.h" #include "phy-qcom-qmp-pcs-misc-v3.h" @@ -374,11 +376,17 @@ struct qmp_usbc { struct reset_control_bulk_data *resets; struct regulator_bulk_data *vregs; + struct mutex phy_mutex; + enum phy_mode mode; + unsigned int usb_init_count; struct phy *phy; struct clk_fixed_rate pipe_clk_fixed; + + struct typec_switch_dev *sw; + enum typec_orientation orientation; }; static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val) @@ -497,6 +505,7 @@ static int qmp_usbc_init(struct phy *phy) struct qmp_usbc *qmp = phy_get_drvdata(phy); const struct qmp_phy_cfg *cfg = qmp->cfg; void __iomem *pcs = qmp->pcs; + u32 val = 0; int ret; ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs); @@ -523,6 +532,14 @@ static int qmp_usbc_init(struct phy *phy) qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN); +#define SW_PORTSELECT_VAL BIT(0) +#define SW_PORTSELECT_MUX BIT(1) + /* Use software based port select and switch on typec orientation */ + val = SW_PORTSELECT_MUX; + if (qmp->orientation == TYPEC_ORIENTATION_REVERSE) + val |= SW_PORTSELECT_VAL; + writel(val, qmp->pcs_misc); + return 0; err_assert_reset: @@ -620,23 +637,34 @@ static int qmp_usbc_power_off(struct phy *phy) static int qmp_usbc_enable(struct phy *phy) { + struct qmp_usbc *qmp = phy_get_drvdata(phy); int ret; + mutex_lock(&qmp->phy_mutex); + ret = qmp_usbc_init(phy); if (ret) - return ret; + goto out_unlock; ret = qmp_usbc_power_on(phy); - if (ret) + if (ret) { qmp_usbc_exit(phy); + goto out_unlock; + } + + qmp->usb_init_count++; +out_unlock: + mutex_unlock(&qmp->phy_mutex); return ret; } static int qmp_usbc_disable(struct phy *phy) { + struct qmp_usbc *qmp = phy_get_drvdata(phy); int ret; + qmp->usb_init_count--; ret = qmp_usbc_power_off(phy); if (ret) return ret; @@ -874,6 +902,61 @@ static int phy_pipe_clk_register(struct qmp_usbc *qmp, struct device_node *np) return devm_add_action_or_reset(qmp->dev, phy_clk_release_provider, np); } +#if IS_ENABLED(CONFIG_TYPEC) +static int qmp_usbc_typec_switch_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + struct qmp_usbc *qmp = typec_switch_get_drvdata(sw); + + if (orientation == qmp->orientation || orientation == TYPEC_ORIENTATION_NONE) + return 0; + + mutex_lock(&qmp->phy_mutex); + qmp->orientation = orientation; + + if (qmp->usb_init_count) { + qmp_usbc_power_off(qmp->phy); + qmp_usbc_exit(qmp->phy); + + qmp_usbc_init(qmp->phy); + qmp_usbc_power_on(qmp->phy); + } + + mutex_unlock(&qmp->phy_mutex); + + return 0; +} + +static void qmp_usbc_typec_unregister(void *data) +{ + struct qmp_usbc *qmp = data; + + typec_switch_unregister(qmp->sw); +} + +static int qmp_usbc_typec_switch_register(struct qmp_usbc *qmp) +{ + struct typec_switch_desc sw_desc = {}; + struct device *dev = qmp->dev; + + sw_desc.drvdata = qmp; + sw_desc.fwnode = dev->fwnode; + sw_desc.set = qmp_usbc_typec_switch_set; + qmp->sw = typec_switch_register(dev, &sw_desc); + if (IS_ERR(qmp->sw)) { + dev_err(dev, "Unable to register typec switch: %pe\n", qmp->sw); + return PTR_ERR(qmp->sw); + } + + return devm_add_action_or_reset(dev, qmp_usbc_typec_unregister, qmp); +} +#else +static int qmp_usbc_typec_switch_register(struct qmp_usbc *qmp) +{ + return 0; +} +#endif + static int qmp_usbc_parse_dt_legacy(struct qmp_usbc *qmp, struct device_node *np) { struct platform_device *pdev = to_platform_device(qmp->dev); @@ -994,16 +1077,24 @@ static int qmp_usbc_probe(struct platform_device *pdev) qmp->dev = dev; + qmp->orientation = TYPEC_ORIENTATION_NORMAL; + qmp->cfg = of_device_get_match_data(dev); if (!qmp->cfg) return -EINVAL; + mutex_init(&qmp->phy_mutex); + ret = qmp_usbc_vreg_init(qmp); if (ret) return ret; + ret = qmp_usbc_typec_switch_register(qmp); + if (ret) + return ret; + /* Check for legacy binding with child node. */ - np = of_get_next_available_child(dev->of_node, NULL); + np = of_get_child_by_name(dev->of_node, "phy"); if (np) { ret = qmp_usbc_parse_dt_legacy(qmp, np); } else {