From patchwork Tue Dec 28 05:21:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 529389 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 7B65DC4321E for ; Tue, 28 Dec 2021 05:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234830AbhL1FUW (ORCPT ); Tue, 28 Dec 2021 00:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231245AbhL1FUS (ORCPT ); Tue, 28 Dec 2021 00:20:18 -0500 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F143EC061401 for ; Mon, 27 Dec 2021 21:20:17 -0800 (PST) Received: by mail-oi1-x231.google.com with SMTP id t19so28447495oij.1 for ; Mon, 27 Dec 2021 21:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ByvL2Uf/cXpEPeJ2AJET+qvtgysLCEvhZPeq63DSw38=; b=B4zhlUAr32kY5oZ8N53jC4N8hPIY76Y5v1jPJEOJ/8WQ/GGjZEEkjMyc62nzUR9fA+ iwn7SXOmsb3AMDCG7G2wARbdPuxKskTye7cWKkq7ezq1aFwZdRFDIvbp4aaDMdgev2mh n7F1qLKmmQwyw5aKDR116G9iStrWa+eiY2wPMCHmXks6ElcXzV7rettiqdDEZ6+MqD6w KQ75+fbrRwUTxPrV4tFrmnTSLRGx9+/YVu2ldIlYlJP93Pwva0AUASZGtPKEAvjFEI7U 0ljq2DhdsSpe3aUhVeYZoitZRvGXgDpIhWniyagk5LDACXH8GsQwmtBukZ0YqCumW61E qzOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ByvL2Uf/cXpEPeJ2AJET+qvtgysLCEvhZPeq63DSw38=; b=XnR+I9Z7PX8/7ACOtIpuCBJSqLvJlPXuP1bAlbrrU88xoqSzj/Lmj6oOhapAzyBC23 SFsoMvNM4cM6KmE01pZHZlsipdPqKxGB9/3od87Y5BaArLI/NRxoZVMQYFOsp0jxxuwk 3FVgF2zrp5Px8ktTG+R9NkSJKvuRbQ36s0pbawka65aATffsb566rijr6vI7jgqKmMyf mS90oiUHsRTzb1QBr4yIs9rEK0LSWCwkO+n4zRFXI2wmL0DBejq6ZpFM3fZbFDpyfSGV /P76jWR2D3dLjJsexu/G0qpI6ZwPCx9sebLGGROWfoqBIsIdOv2KZPz1rG/LHxrzcWQI GFJw== X-Gm-Message-State: AOAM533G6mwt0tZ06qRBo8ncEJSu3TpZAAboF1iRFr2sT3h4dx8Nd7aG ggxP+UsjBuJBe2QLAwvpV7ZRFA== X-Google-Smtp-Source: ABdhPJxct+CkbSvI41JFvkdLrfCsI0wdjHkYbiI93M8uVvOhwpL8J0QsaQ7QXmKuxWERI3iK92ZM+w== X-Received: by 2002:a05:6808:1408:: with SMTP id w8mr15463765oiv.54.1640668817343; Mon, 27 Dec 2021 21:20:17 -0800 (PST) Received: from ripper.. (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id j5sm3002277oou.23.2021.12.27.21.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Dec 2021 21:20:17 -0800 (PST) From: Bjorn Andersson To: Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Greg Kroah-Hartman , Heikki Krogerus , Hans de Goede Cc: "Rafael J. Wysocki" , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 1/8] dt-bindings: phy: qcom,qmp-usb3-dp: Add altmode/switch properties Date: Mon, 27 Dec 2021 21:21:09 -0800 Message-Id: <20211228052116.1748443-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228052116.1748443-1-bjorn.andersson@linaro.org> References: <20211228052116.1748443-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The QMP block deals with orientation switching and altmode switching between USB and DisplayPort. Add the necessary properties to the binding to allow it to be connected to a TypeC controller and trigger these operations. Signed-off-by: Bjorn Andersson --- .../bindings/phy/qcom,qmp-usb3-dp-phy.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/devicetree/bindings/phy/qcom,qmp-usb3-dp-phy.yaml b/Documentation/devicetree/bindings/phy/qcom,qmp-usb3-dp-phy.yaml index 60dc27834e1d..f8a745ec479c 100644 --- a/Documentation/devicetree/bindings/phy/qcom,qmp-usb3-dp-phy.yaml +++ b/Documentation/devicetree/bindings/phy/qcom,qmp-usb3-dp-phy.yaml @@ -77,6 +77,20 @@ properties: description: Phandle to a regulator supply to any specific refclk pll block. + port: + $ref: /schemas/graph.yaml#/properties/port + description: + A port node to link the QMP to a TypeC controller for the purpose of + handling altmode muxing and orientation switching. + + mode-switch: + description: Flag the port as possible handle of altmode switching + type: boolean + + orientation-switch: + description: Flag the port as possible handler of orientation switching + type: boolean + #Required nodes: patternProperties: "^usb3-phy@[0-9a-f]+$": From patchwork Tue Dec 28 05:21:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 529388 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 2544DC4167D for ; Tue, 28 Dec 2021 05:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233882AbhL1FUV (ORCPT ); Tue, 28 Dec 2021 00:20:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232766AbhL1FUT (ORCPT ); Tue, 28 Dec 2021 00:20:19 -0500 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE4BBC061757 for ; Mon, 27 Dec 2021 21:20:18 -0800 (PST) Received: by mail-oi1-x22e.google.com with SMTP id x10so23498911oix.6 for ; Mon, 27 Dec 2021 21:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z8LPxRUlnyWniNCCw5UabEOAyAKG7Nzy5pej2FOGirM=; b=g10SVVSk4fvxlX052YeCX7DS+qSSSDRiunx0KsTnBqPcMGZqJandwL7UYnNsG3Gtd2 DbNLfTumHVFgyWGtsILq6ZjHgGpiy45YT1bnom3i43TqLj3U9/mFrwYrFRUsAKbWrJ9T XBddn6yl0kbk2+G2x+4KJM9lOxHLAkPED0y3qVjnGMj8TUIyNpucIfstm9pGS40CgbnF Dp8ULhKpiGmhk9HpxcRKaVau9CXwpeqVwLX2axRSXwlfDubEQUFx+0SitsxVMEPjSlgP QiCD05nozdGlvf8V8H121VuOovwMYPcxpt0aZIxj6nLYRiiWZOmtKsutVwYJr3kuzwVv Vkqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z8LPxRUlnyWniNCCw5UabEOAyAKG7Nzy5pej2FOGirM=; b=d3keQ2vZGx9QEs0QehN+NfFf98Kq/x8Ek+9DnL81MZSrNDwNsbDcdgk7cofotTv652 UzSMcsPxyiTJvxtjq9lTqIK9ev3fefgM08a4t9+hr/rrbxSejbh8WIfU2OFN4K6iVhPh iiEFsyX8/XizExjI6R6H8FDRCH7YBzZ6RagVtJOFRqvBpQo7cOhl0NTr6IRE5Sm0CV36 /hJVMWfTAWvMBBefdh07MEmjTfJJbd63j9IbcjnTdDk0iJjxF2JEwFI6EX6ylB9pKy24 vZZvetBn7t1eN+OnMxe1Keh4bD6/E66knxSvxzZMXIdFUrumYDDIr36jnF5ajsOPLAR9 oZzQ== X-Gm-Message-State: AOAM531IFGbgdsOS0su00sHXcDOsApAL/O3kvYddIH/8TvO8S3aNMjtm X01p3lRvc6GC7VPBYO4+IP0LVQ== X-Google-Smtp-Source: ABdhPJz/UoJog8eWLqfdjo2/3QHmaA6A5yJ6+GP1ft+ufn483DhjlcdfLVyacIvgHZC/1+AbHTnAIQ== X-Received: by 2002:a05:6808:10ce:: with SMTP id s14mr14214591ois.137.1640668818160; Mon, 27 Dec 2021 21:20:18 -0800 (PST) Received: from ripper.. (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id j5sm3002277oou.23.2021.12.27.21.20.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Dec 2021 21:20:17 -0800 (PST) From: Bjorn Andersson To: Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Greg Kroah-Hartman , Heikki Krogerus , Hans de Goede Cc: "Rafael J. Wysocki" , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 2/8] phy: qcom-qmp: Register typec mux and orientation switch Date: Mon, 27 Dec 2021 21:21:10 -0800 Message-Id: <20211228052116.1748443-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228052116.1748443-1-bjorn.andersson@linaro.org> References: <20211228052116.1748443-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The QMP PHY handles muxing of USB vs DisplayPort, as well as orientation switching of the SuperSpeed lanes. So register typec handlers for the two types. The TypeC mux allows switching between four lanes of DisplayPort and a mixed USB+DP combination. This makes it possible to reach resolutions that requires 4 lanes. The TypeC switch allows switching the SuperSpeed pins and have been tested with both 2 and 4 lane DisplayPort. It's possible that in the USB mode the DP_MODE should be disabled, but this is left untouched. Signed-off-by: Bjorn Andersson --- My suggestion is that if/once this patch is deemed acceptable the PHY maintainers could create a immutable branch/tag which can be merged into the PHY tree as well as the USB tree. drivers/phy/qualcomm/phy-qcom-qmp.c | 176 +++++++++++++++++++++++++--- 1 file changed, 158 insertions(+), 18 deletions(-) diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c index 7bea6a60dc54..8d8139df9d8e 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include @@ -3017,6 +3019,9 @@ struct qmp_phy_dp_clks { * @phy_mutex: mutex lock for PHY common block initialization * @init_count: phy common block initialization count * @ufs_reset: optional UFS PHY reset handle + * @sw: typec switch for receiving orientation changes + * @mux: typec mux for DP muxing + * @orientation: carries current CC orientation */ struct qcom_qmp { struct device *dev; @@ -3032,6 +3037,10 @@ struct qcom_qmp { int init_count; struct reset_control *ufs_reset; + + struct typec_switch *sw; + struct typec_mux *mux; + enum typec_orientation orientation; }; static void qcom_qmp_v3_phy_dp_aux_init(struct qmp_phy *qphy); @@ -4378,30 +4387,23 @@ static void qcom_qmp_v3_phy_configure_dp_tx(struct qmp_phy *qphy) static bool qcom_qmp_phy_configure_dp_mode(struct qmp_phy *qphy) { + const struct phy_configure_opts_dp *dp_opts = &qphy->dp_opts; + bool reverse = qphy->qmp->orientation == TYPEC_ORIENTATION_REVERSE; u32 val; - bool reverse = false; val = DP_PHY_PD_CTL_PWRDN | DP_PHY_PD_CTL_AUX_PWRDN | DP_PHY_PD_CTL_PLL_PWRDN | DP_PHY_PD_CTL_DP_CLAMP_EN; - /* - * TODO: Assume orientation is CC1 for now and two lanes, need to - * use type-c connector to understand orientation and lanes. - * - * Otherwise val changes to be like below if this code understood - * the orientation of the type-c cable. - * - * if (lane_cnt == 4 || orientation == ORIENTATION_CC2) - * val |= DP_PHY_PD_CTL_LANE_0_1_PWRDN; - * if (lane_cnt == 4 || orientation == ORIENTATION_CC1) - * val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN; - * if (orientation == ORIENTATION_CC2) - * writel(0x4c, qphy->pcs + QSERDES_V3_DP_PHY_MODE); - */ - val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN; + if (dp_opts->lanes == 4 || reverse) + val |= DP_PHY_PD_CTL_LANE_0_1_PWRDN; + if (dp_opts->lanes == 4 || !reverse) + val |= DP_PHY_PD_CTL_LANE_2_3_PWRDN; writel(val, qphy->pcs + QSERDES_DP_PHY_PD_CTL); - writel(0x5c, qphy->pcs + QSERDES_DP_PHY_MODE); + if (reverse) + writel(0x4c, qphy->pcs + QSERDES_DP_PHY_MODE); + else + writel(0x5c, qphy->pcs + QSERDES_DP_PHY_MODE); return reverse; } @@ -5809,6 +5811,123 @@ static const struct dev_pm_ops qcom_qmp_phy_pm_ops = { qcom_qmp_phy_runtime_resume, NULL) }; +#if IS_ENABLED(CONFIG_TYPEC) +static int qcom_qmp_phy_typec_switch_set(struct typec_switch *sw, + enum typec_orientation orientation) +{ + struct qcom_qmp *qmp = typec_switch_get_drvdata(sw); + void __iomem *dp_com = qmp->dp_com; + + qmp->orientation = orientation; + + if (orientation == TYPEC_ORIENTATION_REVERSE) + qphy_setbits(dp_com, QPHY_V3_DP_COM_TYPEC_CTRL, 0x01); + else + qphy_clrbits(dp_com, QPHY_V3_DP_COM_TYPEC_CTRL, 0x01); + + return 0; +} + +static int qcom_qmp_phy_typec_mux_set(struct typec_mux *mux, + struct typec_mux_state *state) +{ + struct qcom_qmp *qmp = typec_mux_get_drvdata(mux); + void __iomem *dp_com = qmp->dp_com; + bool dp_mode; + bool usb_mode; + + switch (state->mode) { + case TYPEC_STATE_SAFE: + case TYPEC_STATE_USB: + /* + * TODO: Figure out if we should clear DP_MODE when we enter a + * USB-only state. + */ + dp_mode = true; + usb_mode = true; + break; + case TYPEC_DP_STATE_A: + case TYPEC_DP_STATE_C: + case TYPEC_DP_STATE_E: + dp_mode = true; + usb_mode = false; + break; + case TYPEC_DP_STATE_B: + case TYPEC_DP_STATE_D: + case TYPEC_DP_STATE_F: + dp_mode = true; + usb_mode = true; + break; + } + + qphy_setbits(dp_com, QPHY_V3_DP_COM_RESET_OVRD_CTRL, + SW_DPPHY_RESET_MUX | SW_USB3PHY_RESET_MUX); + if (dp_mode) + qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL, DP_MODE); + else + qphy_clrbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL, DP_MODE); + + if (usb_mode) + qphy_setbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL, USB3_MODE); + else + qphy_clrbits(dp_com, QPHY_V3_DP_COM_PHY_MODE_CTRL, USB3_MODE); + + qphy_setbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET); + qphy_clrbits(dp_com, QPHY_V3_DP_COM_SWI_CTRL, 0x03); + qphy_clrbits(dp_com, QPHY_V3_DP_COM_SW_RESET, SW_RESET); + + return 0; +} + +static int qcom_qmp_phy_typec_register(struct qcom_qmp *qmp, + const struct qmp_phy_cfg *cfg) +{ + struct typec_switch_desc sw_desc = {}; + struct typec_mux_desc mux_desc = {}; + struct device *dev = qmp->dev; + + if (!cfg->has_phy_dp_com_ctrl) + return 0; + + sw_desc.drvdata = qmp; + sw_desc.fwnode = dev->fwnode; + sw_desc.set = qcom_qmp_phy_typec_switch_set; + qmp->sw = typec_switch_register(dev, &sw_desc); + if (IS_ERR(qmp->sw)) { + dev_err(dev, "Error registering typec switch: %pe\n", qmp->sw); + return PTR_ERR(qmp->sw); + } + + mux_desc.drvdata = qmp; + mux_desc.fwnode = dev->fwnode; + mux_desc.set = qcom_qmp_phy_typec_mux_set; + qmp->mux = typec_mux_register(dev, &mux_desc); + if (IS_ERR(qmp->mux)) { + dev_err(dev, "Error registering typec mux: %pe\n", qmp->mux); + typec_switch_unregister(qmp->sw); + return PTR_ERR(qmp->mux); + } + + return 0; +} + +static void qcom_qmp_phy_typec_unregister(struct qcom_qmp *qmp) +{ + typec_mux_unregister(qmp->mux); + typec_switch_unregister(qmp->sw); +} +#else +static int qcom_qmp_phy_typec_register(struct qcom_qmp *qmp, + const struct qmp_phy_cfg *cfg) +{ + return 0; +} + +static void qcom_qmp_phy_typec_unregister(struct qcom_qmp *qmp) +{ +} +#endif + static int qcom_qmp_phy_probe(struct platform_device *pdev) { struct qcom_qmp *qmp; @@ -5891,7 +6010,15 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev) return ret; } - num = of_get_available_child_count(dev->of_node); + ret = qcom_qmp_phy_typec_register(qmp, cfg); + if (ret) + return ret; + + num = 0; + for_each_available_child_of_node(dev->of_node, child) { + if (!of_node_name_eq(child, "port")) + num++; + } /* do we have a rogue child node ? */ if (num > expected_phys) return -EINVAL; @@ -5918,6 +6045,9 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev) serdes = usb_serdes; } + if (of_node_name_eq(child, "port")) + continue; + /* Create per-lane phy */ ret = qcom_qmp_phy_create(dev, child, id, serdes, cfg); if (ret) { @@ -5962,8 +6092,18 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev) return ret; } +static int qcom_qmp_phy_remove(struct platform_device *pdev) +{ + struct qcom_qmp *qmp = platform_get_drvdata(pdev); + + qcom_qmp_phy_typec_unregister(qmp); + + return 0; +} + static struct platform_driver qcom_qmp_phy_driver = { .probe = qcom_qmp_phy_probe, + .remove = qcom_qmp_phy_remove, .driver = { .name = "qcom-qmp-phy", .pm = &qcom_qmp_phy_pm_ops, From patchwork Tue Dec 28 05:21:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 529387 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 281D9C433F5 for ; Tue, 28 Dec 2021 05:20:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234857AbhL1FU0 (ORCPT ); Tue, 28 Dec 2021 00:20:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbhL1FUW (ORCPT ); Tue, 28 Dec 2021 00:20:22 -0500 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F09FC06175B for ; Mon, 27 Dec 2021 21:20:22 -0800 (PST) Received: by mail-oi1-x230.google.com with SMTP id x10so23499108oix.6 for ; Mon, 27 Dec 2021 21:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RdZ0UWK+juD5hIJv/N6wqF64M3MWs7cXhgw6dZ2me2c=; b=gecW0ToB+ezNfgZBtqEGM4NktSYAlSPUX12ativA3a1GA5DK5dSZfmjRlt33U4Aa6a WEhhU5CLblKS1+CA7ZERcRbWGR8uuq0J9MdUvdmPk8lDjaX7Tr8riaDJzT8gbP619IM2 oqOORkabcQNMmloWNFDu+Opw0FwmA5CfNnTMhR9Juk4CRYDoRUDgv/mBBdd/M6vIf6cA vu+RbHLcaOtC33vXw3Z5D/vbN4wdtsgO1apBSbGgl74CtB9WbIPBxTStyhXfRl7roQhl IlDvaII5hZedcWXc0C2EAN/880yGAHj4uDi37gik9ud5QNNpPNsigSK/Gay5n2uKlaDv GqWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RdZ0UWK+juD5hIJv/N6wqF64M3MWs7cXhgw6dZ2me2c=; b=v2Z1zVxuB2Tj9fNUhPBqhDNfTPmRyRdn1vQ6V6eTpmG0WJX3XdLyrRBjpb1LpSmLPk pZ9yJT4NbWSPuwz8mVfpg8oJsnWw0VzsSm3izRd3gHf66x/xTS/zUngCN+1BYa9ZyCTE AHig6bKETSX3lbcrCtvOLajG4etRvI3s5QF6MjLD0GSNsl1rRWHXIpoB8KpFmagiTgmN UZQ1HL2g8pnTSSGEZLGyFMQIwAaWmdXPlEyaqRtnNKYCTX/dKL1uNSkR8fsD4Q437T23 jHo6m0Po+dgxB+Eb0jPq5Y42QOJpbvbJ6vgNpCTfyO6Pvy9dFOcAetlYIjU/x+AQ2Qyo fopQ== X-Gm-Message-State: AOAM530YIiHVnlgRZs7pCyF33FQspRnY+hfHaMQHiRrjTxRpEnoQ8X2V CjOdAsgscGRSlDYcPm+aa9j1gp+BOWA4zg== X-Google-Smtp-Source: ABdhPJxim6zcGg4oNp9c2nvgeHmzM4DmH7CrApzhOpfm+rBwgGbY1Q7Du7weKKBE0bh5D7NhZ28a8w== X-Received: by 2002:aca:6c5:: with SMTP id 188mr15108644oig.117.1640668821679; Mon, 27 Dec 2021 21:20:21 -0800 (PST) Received: from ripper.. (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id j5sm3002277oou.23.2021.12.27.21.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Dec 2021 21:20:21 -0800 (PST) From: Bjorn Andersson To: Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Greg Kroah-Hartman , Heikki Krogerus , Hans de Goede Cc: "Rafael J. Wysocki" , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 6/8] typec: mux: Allow multiple mux_devs per mux Date: Mon, 27 Dec 2021 21:21:14 -0800 Message-Id: <20211228052116.1748443-7-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228052116.1748443-1-bjorn.andersson@linaro.org> References: <20211228052116.1748443-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In the Qualcomm platforms the USB/DP PHY handles muxing and orientation switching of the SuperSpeed lines, but the SBU lines needs to be connected and switched by external (to the SoC) hardware. It's therefor necessary to be able to have the TypeC controller operate multiple TypeC muxes and switches. Use the newly introduced indirection object to handle this, to avoid having to taint the TypeC controllers with knowledge about the downstream hardware configuration. The max number of devs per indirection is set to 3, based on the number of ports defined in the usb-c-connector binding. Signed-off-by: Bjorn Andersson --- drivers/usb/typec/mux.c | 124 +++++++++++++++++++++++++++++++--------- 1 file changed, 98 insertions(+), 26 deletions(-) diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index d0b42c297aca..adf3681cf22d 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -17,8 +17,11 @@ #include "class.h" #include "mux.h" +#define TYPEC_MUX_MAX_DEVS 3 + struct typec_switch { - struct typec_switch_dev *sw_dev; + struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS]; + unsigned int num_sw_devs; }; static int switch_fwnode_match(struct device *dev, const void *fwnode) @@ -67,25 +70,48 @@ static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id, */ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode) { - struct typec_switch_dev *sw_dev; + struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS]; struct typec_switch *sw; + int count; + int err; + int i; sw = kzalloc(sizeof(*sw), GFP_KERNEL); if (!sw) return ERR_PTR(-ENOMEM); - sw_dev = fwnode_connection_find_match(fwnode, "orientation-switch", NULL, - typec_switch_match); - if (IS_ERR_OR_NULL(sw_dev)) { + count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL, + typec_switch_match, + (void **)sw_devs, + ARRAY_SIZE(sw_devs)); + if (count <= 0) { kfree(sw); - return ERR_CAST(sw_dev); + return NULL; } - WARN_ON(!try_module_get(sw_dev->dev.parent->driver->owner)); + for (i = 0; i < count; i++) { + if (IS_ERR(sw_devs[i])) { + err = PTR_ERR(sw_devs[i]); + goto put_sw_devs; + } + } + + for (i = 0; i < count; i++) { + WARN_ON(!try_module_get(sw_devs[i]->dev.parent->driver->owner)); + sw->sw_devs[i] = sw_devs[i]; + } - sw->sw_dev = sw_dev; + sw->num_sw_devs = count; return sw; + +put_sw_devs: + for (i = 0; i < count; i++) { + if (!IS_ERR(sw_devs[i])) + put_device(&sw_devs[i]->dev); + } + + return ERR_PTR(err); } EXPORT_SYMBOL_GPL(fwnode_typec_switch_get); @@ -98,14 +124,17 @@ EXPORT_SYMBOL_GPL(fwnode_typec_switch_get); void typec_switch_put(struct typec_switch *sw) { struct typec_switch_dev *sw_dev; + unsigned int i; if (IS_ERR_OR_NULL(sw)) return; - sw_dev = sw->sw_dev; + for (i = 0; i < sw->num_sw_devs; i++) { + sw_dev = sw->sw_devs[i]; - module_put(sw_dev->dev.parent->driver->owner); - put_device(&sw_dev->dev); + module_put(sw_dev->dev.parent->driver->owner); + put_device(&sw_dev->dev); + } kfree(sw); } EXPORT_SYMBOL_GPL(typec_switch_put); @@ -170,13 +199,21 @@ int typec_switch_set(struct typec_switch *sw, enum typec_orientation orientation) { struct typec_switch_dev *sw_dev; + unsigned int i; + int ret; if (IS_ERR_OR_NULL(sw)) return 0; - sw_dev = sw->sw_dev; + for (i = 0; i < sw->num_sw_devs; i++) { + sw_dev = sw->sw_devs[i]; + + ret = sw_dev->set(sw_dev, orientation); + if (ret) + return ret; + } - return sw_dev->set(sw_dev, orientation); + return 0; } EXPORT_SYMBOL_GPL(typec_switch_set); @@ -208,7 +245,8 @@ EXPORT_SYMBOL_GPL(typec_switch_get_drvdata); /* ------------------------------------------------------------------------- */ struct typec_mux { - struct typec_mux_dev *mux_dev; + struct typec_mux_dev *mux_devs[TYPEC_MUX_MAX_DEVS]; + unsigned int num_mux_devs; }; static int mux_fwnode_match(struct device *dev, const void *fwnode) @@ -291,25 +329,48 @@ static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id, struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode, const struct typec_altmode_desc *desc) { - struct typec_mux_dev *mux_dev; + struct typec_mux_dev *mux_devs[TYPEC_MUX_MAX_DEVS]; struct typec_mux *mux; + int count; + int err; + int i; mux = kzalloc(sizeof(*mux), GFP_KERNEL); if (!mux) return ERR_PTR(-ENOMEM); - mux_dev = fwnode_connection_find_match(fwnode, "mode-switch", (void *)desc, - typec_mux_match); - if (IS_ERR_OR_NULL(mux_dev)) { + count = fwnode_connection_find_matches(fwnode, "mode-switch", + (void *)desc, typec_mux_match, + (void **)mux_devs, + ARRAY_SIZE(mux_devs)); + if (count <= 0) { kfree(mux); - return ERR_CAST(mux_dev); + return NULL; } - WARN_ON(!try_module_get(mux_dev->dev.parent->driver->owner)); + for (i = 0; i < count; i++) { + if (IS_ERR(mux_devs[i])) { + err = PTR_ERR(mux_devs[i]); + goto put_mux_devs; + } + } + + for (i = 0; i < count; i++) { + WARN_ON(!try_module_get(mux_devs[i]->dev.parent->driver->owner)); + mux->mux_devs[i] = mux_devs[i]; + } - mux->mux_dev = mux_dev; + mux->num_mux_devs = count; return mux; + +put_mux_devs: + for (i = 0; i < count; i++) { + if (!IS_ERR(mux_devs[i])) + put_device(&mux_devs[i]->dev); + } + + return ERR_PTR(err); } EXPORT_SYMBOL_GPL(fwnode_typec_mux_get); @@ -322,13 +383,16 @@ EXPORT_SYMBOL_GPL(fwnode_typec_mux_get); void typec_mux_put(struct typec_mux *mux) { struct typec_mux_dev *mux_dev; + unsigned int i; if (IS_ERR_OR_NULL(mux)) return; - mux_dev = mux->mux_dev; - module_put(mux_dev->dev.parent->driver->owner); - put_device(&mux_dev->dev); + for (i = 0; i < mux->num_mux_devs; i++) { + mux_dev = mux->mux_devs[i]; + module_put(mux_dev->dev.parent->driver->owner); + put_device(&mux_dev->dev); + } kfree(mux); } EXPORT_SYMBOL_GPL(typec_mux_put); @@ -336,13 +400,21 @@ EXPORT_SYMBOL_GPL(typec_mux_put); int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state) { struct typec_mux_dev *mux_dev; + unsigned int i; + int ret; if (IS_ERR_OR_NULL(mux)) return 0; - mux_dev = mux->mux_dev; + for (i = 0; i < mux->num_mux_devs; i++) { + mux_dev = mux->mux_devs[i]; + + ret = mux_dev->set(mux_dev, state); + if (ret) + return ret; + } - return mux_dev->set(mux_dev, state); + return 0; } EXPORT_SYMBOL_GPL(typec_mux_set); From patchwork Tue Dec 28 05:21:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 529386 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 22224C4332F for ; Tue, 28 Dec 2021 05:20:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234879AbhL1FUb (ORCPT ); Tue, 28 Dec 2021 00:20:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232926AbhL1FUY (ORCPT ); Tue, 28 Dec 2021 00:20:24 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C70C061401 for ; Mon, 27 Dec 2021 21:20:24 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id p4so28388655oia.9 for ; Mon, 27 Dec 2021 21:20:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VN6g2mXvfM1KCsUt0asBDpDPGoZHaGgVVhC+vigu24g=; b=p3XsuBH5Ce+4XFxnUxDm5VhCHRNFmrL5SaMVH97RiQELYCAVjcUVXrtdL1H/IYGGPg QUVBViJiXyUF2G8BlpVkvwfCdFYf00fwIiqcAwlVzzwHghOYVC2WoG4Ly2wX2VlLHZzD RRG1qHfZDbJGMSRLiRVOBCvCu6NLySe/ZQNC+CWHkbhMKu6tgzfCZvDLpLRx8sFVrToy NA1cREOjgLEC2sImrGGz7h3BMI41jeYk9PnI89jbiotXiRZHzt2qMRXMCg4QXjf7mp91 rbz6eFl7rsGH69J0bX4/cHzpZEgB5iKPCRSw9tZMhB+EymL81IHLta5bQsEg7zT4+899 jc3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VN6g2mXvfM1KCsUt0asBDpDPGoZHaGgVVhC+vigu24g=; b=NsvyeU0Yt+QJg8Y8E97Kf9GYPopllDcB31Vu6o7us6EqQprlGGZBMxZiNBVz/++dwP uaXTXKHaqQqAYvRGRFmYTE+pGTdOnl0/kRX9NKxFBMpTgLLVVj4vhIhdFQngFqa8xLKO ytugFsEP0I0IZoU6C6KP/PnJnL7gombGwsrv6+IyEZA9Gk8QNuShcRdoqVTkcO654k07 bS0KmMSKCTB6jga4zgImSSBzry+7y4dElflNanfHBxN0RdYCKS8mDTZ4+PSh8qags9HG HZ9R3YZLxUjZuGEG0aq5BdF4i1VBwFlALwhBu2+O0C2AF0h3F20cFpqTq3CSXOiMGLlu 21og== X-Gm-Message-State: AOAM531nHELodrVQyRFNo+fFdCWzn3wHefMd1TLDNdTRmqfvbKFEM5KX TlGEtqTpFdCj/zEHl0nXURosAw== X-Google-Smtp-Source: ABdhPJxkRBJpLMaoG851Ug1pzt6f1LSJsisYbH6ezhVt++Ag/ATsiBQjESXSx28m+PmGh+VY+SBdAA== X-Received: by 2002:a05:6808:2309:: with SMTP id bn9mr15021540oib.42.1640668823417; Mon, 27 Dec 2021 21:20:23 -0800 (PST) Received: from ripper.. (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id j5sm3002277oou.23.2021.12.27.21.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Dec 2021 21:20:23 -0800 (PST) From: Bjorn Andersson To: Kishon Vijay Abraham I , Vinod Koul , Rob Herring , Greg Kroah-Hartman , Heikki Krogerus , Hans de Goede Cc: "Rafael J. Wysocki" , linux-arm-msm@vger.kernel.org, linux-phy@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 8/8] usb: typec: mux: Add On Semi fsa4480 driver Date: Mon, 27 Dec 2021 21:21:16 -0800 Message-Id: <20211228052116.1748443-9-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211228052116.1748443-1-bjorn.andersson@linaro.org> References: <20211228052116.1748443-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The ON Semiconductor FSA4480 is a USB Type-C port multimedia switch with support for analog audio headsets. It allows sharing a common USB Type-C port to pass USB2.0 signal, analog audio, sideband use wires and analog microphone signal. Due to lacking upstream audio support for testing, the audio muxing is left untouched, but implementation of muxing the SBU lines is provided as a pair of TypeC mux and switch devices. This provides the necessary support for enabling the DisplayPort altmode on devices with this circuit. Signed-off-by: Bjorn Andersson --- drivers/usb/typec/mux/Kconfig | 9 ++ drivers/usb/typec/mux/Makefile | 1 + drivers/usb/typec/mux/fsa4480.c | 220 ++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 drivers/usb/typec/mux/fsa4480.c diff --git a/drivers/usb/typec/mux/Kconfig b/drivers/usb/typec/mux/Kconfig index edead555835e..5e20112c3f51 100644 --- a/drivers/usb/typec/mux/Kconfig +++ b/drivers/usb/typec/mux/Kconfig @@ -2,6 +2,15 @@ menu "USB Type-C Multiplexer/DeMultiplexer Switch support" +config TYPEC_MUX_FSA4480 + tristate "ON Semi FSA4480 Analog Audio Switch driver" + depends on I2C + select REGMAP_I2C + help + Driver for the ON Semiconductor FSA4480 Analog Audio Switch, which + provides support for muxing analog audio and sideband signals on a + common USB Type-C connector. + config TYPEC_MUX_PI3USB30532 tristate "Pericom PI3USB30532 Type-C cross switch driver" depends on I2C diff --git a/drivers/usb/typec/mux/Makefile b/drivers/usb/typec/mux/Makefile index 280a6f553115..e52a56c16bfb 100644 --- a/drivers/usb/typec/mux/Makefile +++ b/drivers/usb/typec/mux/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_TYPEC_MUX_FSA4480) += fsa4480.o obj-$(CONFIG_TYPEC_MUX_PI3USB30532) += pi3usb30532.o obj-$(CONFIG_TYPEC_MUX_INTEL_PMC) += intel_pmc_mux.o diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c new file mode 100644 index 000000000000..ac2d8648db6a --- /dev/null +++ b/drivers/usb/typec/mux/fsa4480.c @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 Linaro Ltd. + * Copyright (C) 2018-2020 The Linux Foundation + */ + +#include +#include +#include +#include +#include +#include +#include + +#define FSA4480_SWITCH_ENABLE 0x04 +#define FSA4480_SWITCH_SELECT 0x05 +#define FSA4480_SWITCH_STATUS1 0x07 +#define FSA4480_SLOW_L 0x08 +#define FSA4480_SLOW_R 0x09 +#define FSA4480_SLOW_MIC 0x0a +#define FSA4480_SLOW_SENSE 0x0b +#define FSA4480_SLOW_GND 0x0c +#define FSA4480_DELAY_L_R 0x0d +#define FSA4480_DELAY_L_MIC 0x0e +#define FSA4480_DELAY_L_SENSE 0x0f +#define FSA4480_DELAY_L_AGND 0x10 +#define FSA4480_RESET 0x1e + +#define FSA4480_ENABLE_DEVICE BIT(7) +#define FSA4480_ENABLE_SBU GENMASK(6, 5) +#define FSA4480_ENABLE_USB GENMASK(4, 3) + +#define FSA4480_SEL_SBU_REVERSE GENMASK(6, 5) +#define FSA4480_SEL_USB GENMASK(4, 3) + +struct fsa4480 { + struct i2c_client *client; + + /* used to serialize concurrect change requests */ + struct mutex lock; + + struct typec_switch_dev *sw; + struct typec_mux_dev *mux; + + struct regmap *regmap; + + u8 cur_enable; + u8 cur_select; +}; + +static const struct regmap_config fsa4480_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = FSA4480_RESET, +}; + +static int fsa4480_switch_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + struct fsa4480 *fsa = typec_switch_get_drvdata(sw); + u8 new_sel; + + mutex_lock(&fsa->lock); + new_sel = FSA4480_SEL_USB; + if (orientation == TYPEC_ORIENTATION_REVERSE) + new_sel |= FSA4480_SEL_SBU_REVERSE; + + if (new_sel == fsa->cur_select) + goto out_unlock; + + if (fsa->cur_enable & FSA4480_ENABLE_SBU) { + /* Disable SBU output while re-configuring the switch */ + regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, + fsa->cur_enable & ~FSA4480_ENABLE_SBU); + + /* 35us to allow the SBU switch to turn off */ + usleep_range(35, 1000); + } + + regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, new_sel); + fsa->cur_select = new_sel; + + if (fsa->cur_enable & FSA4480_ENABLE_SBU) { + regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, fsa->cur_enable); + + /* 15us to allow the SBU switch to turn on again */ + usleep_range(15, 1000); + } + +out_unlock: + mutex_unlock(&fsa->lock); + + return 0; +} + +static int fsa4480_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) +{ + struct fsa4480 *fsa = typec_mux_get_drvdata(mux); + u8 new_enable; + + mutex_lock(&fsa->lock); + + new_enable = FSA4480_ENABLE_DEVICE | FSA4480_ENABLE_USB; + if (state->mode >= TYPEC_DP_STATE_A) + new_enable |= FSA4480_ENABLE_SBU; + + if (new_enable == fsa->cur_enable) + goto out_unlock; + + regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, new_enable); + fsa->cur_enable = new_enable; + + if (new_enable & FSA4480_ENABLE_SBU) { + /* 15us to allow the SBU switch to turn off */ + usleep_range(15, 1000); + } + +out_unlock: + mutex_unlock(&fsa->lock); + + return 0; +} + +static int fsa4480_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct typec_switch_desc sw_desc = { }; + struct typec_mux_desc mux_desc = { }; + struct fsa4480 *fsa; + + fsa = devm_kzalloc(dev, sizeof(*fsa), GFP_KERNEL); + if (!fsa) + return -ENOMEM; + + fsa->client = client; + mutex_init(&fsa->lock); + + fsa->regmap = devm_regmap_init_i2c(client, &fsa4480_regmap_config); + if (IS_ERR(fsa->regmap)) { + dev_err(dev, "failed to initialize regmap\n"); + return PTR_ERR(fsa->regmap); + } + + fsa->cur_enable = FSA4480_ENABLE_DEVICE | FSA4480_ENABLE_USB; + fsa->cur_select = FSA4480_SEL_USB; + + /* set default settings */ + regmap_write(fsa->regmap, FSA4480_SLOW_L, 0x00); + regmap_write(fsa->regmap, FSA4480_SLOW_R, 0x00); + regmap_write(fsa->regmap, FSA4480_SLOW_MIC, 0x00); + regmap_write(fsa->regmap, FSA4480_SLOW_SENSE, 0x00); + regmap_write(fsa->regmap, FSA4480_SLOW_GND, 0x00); + regmap_write(fsa->regmap, FSA4480_DELAY_L_R, 0x00); + regmap_write(fsa->regmap, FSA4480_DELAY_L_MIC, 0x00); + regmap_write(fsa->regmap, FSA4480_DELAY_L_SENSE, 0x00); + regmap_write(fsa->regmap, FSA4480_DELAY_L_AGND, 0x09); + regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, fsa->cur_select); + regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, fsa->cur_enable); + + sw_desc.drvdata = fsa; + sw_desc.fwnode = dev->fwnode; + sw_desc.set = fsa4480_switch_set; + + fsa->sw = typec_switch_register(dev, &sw_desc); + if (IS_ERR(fsa->sw)) { + dev_err(dev, "failed to register typec switch: %ld\n", PTR_ERR(fsa->sw)); + return PTR_ERR(fsa->sw); + } + + mux_desc.drvdata = fsa; + mux_desc.fwnode = dev->fwnode; + mux_desc.set = fsa4480_mux_set; + + fsa->mux = typec_mux_register(dev, &mux_desc); + if (IS_ERR(fsa->mux)) { + typec_switch_unregister(fsa->sw); + dev_err(dev, "failed to register typec mux: %ld\n", PTR_ERR(fsa->mux)); + return PTR_ERR(fsa->mux); + } + + i2c_set_clientdata(client, fsa); + return 0; +} + +static int fsa4480_remove(struct i2c_client *client) +{ + struct fsa4480 *fsa = i2c_get_clientdata(client); + + typec_mux_unregister(fsa->mux); + typec_switch_unregister(fsa->sw); + + return 0; +} + +static const struct i2c_device_id fsa4480_table[] = { + { "fsa4480" }, + { } +}; +MODULE_DEVICE_TABLE(i2c, fsa4480_table); + +static const struct of_device_id fsa4480_of_table[] = { + { .compatible = "fcs,fsa4480" }, + { } +}; +MODULE_DEVICE_TABLE(of, fsa4480_of_table); + +static struct i2c_driver fsa4480_driver = { + .driver = { + .name = "fsa4480", + .of_match_table = fsa4480_of_table, + }, + .probe_new = fsa4480_probe, + .remove = fsa4480_remove, + .id_table = fsa4480_table, +}; + +module_i2c_driver(fsa4480_driver); + +MODULE_DESCRIPTION("ON Semiconductor FSA4480 driver"); +MODULE_LICENSE("GPL v2");