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: 762538 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E218A1864D for ; Sat, 13 Jan 2024 20:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="raUpzt/Q" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50ea8fbf261so8753150e87.2 for ; Sat, 13 Jan 2024 12:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705179363; x=1705784163; darn=vger.kernel.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=raUpzt/QSNnwPtLIC3DEDciQSVr2gjiQY+ELZE4qchzyiTvo3kp9/8B2CdkTSDxG9D N+iHIgmQPlOaSef9hlWVMYqTE6cHtp04A4spVDShIxHct1qPz1K/mr5xSGT33hpR8CQt o7Zpr3kvFESHr155OdP0ADEXnwesBxNgzeb19ob+tVFU+CGvB7nFva01UfNx0TM1OzgH k+f+ofT5QxzTio0pRmjYyZWarHB6ZNwgX0c0Sph3IspWOLkdMIi/cdLUQKVU7qPP1dhZ W/DBc2ZbiuPlk9VQEpsjHVjoHF1TjUEKVDJJuLqM79Ue37kyPSkxzrWmDHRICr6ZbUV1 B2Cg== 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=SDKtpPPtwy2KMDQaYkIXcOuL9hHl6XI1abIitOdOwh5lZvX3Ae8VYoIthyeUAf36A/ bk6dAGSqAy9PBryk5lAs4Q37rnAI4sH1SziIf5Wrjh+8LnZIABX8I5qJpV17SvZA4YEl hCG3X8CHjh9z2ay3bGavx/2AOmXjZVLZfC+14L6eCWUOJJw0cCqN75tBGA8DWUzZ1B3w blr7iWdlYiz5JAY3Xj3MDkEVbJ8/v2S7QU1/ZM1QiTBTLphXwAF2M26dus5nHoMn69Ca /rKn9wyAUCiBBZcFS+wAK4xZ8Xffxm3vtfSK0S7zW1WGvM1TDCyHPUmzD/KPkJUTES1i wwUA== X-Gm-Message-State: AOJu0YygPfDiszCjWhuNfBgt/sx4ZKqIgZDYXrqCXtLpJCkFyWtozqVk FMV6TwA2Q/27NX1m3Bhqw/3+0j0+6fQl6g== 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 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 {