From patchwork Wed Jun 7 08:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 13270139 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 EB4D5C7EE23 for ; Wed, 7 Jun 2023 08:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239198AbjFGIFY (ORCPT ); Wed, 7 Jun 2023 04:05:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239013AbjFGIFN (ORCPT ); Wed, 7 Jun 2023 04:05:13 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D1C710F8 for ; Wed, 7 Jun 2023 01:05:11 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-307d58b3efbso5864973f8f.0 for ; Wed, 07 Jun 2023 01:05:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686125110; x=1688717110; 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=MtzYn96ig+lorMysgzvmIhs2jjpLBGL4+9ZV/9hvBQI=; b=uNYTQtE0Za4Fy+tKFPNhJ5JJ7XmY3nhTJ0LHaaoKZajPOjUK/aXGdu+bOtrlW2uJhF nNC10FIKbMoaBQ2KfdE4o3xxxysUJ+l2MepabkB8b8KXeS/NGgk8zZ5SG6lQnWzeKZPA XU4U3CldeyTxvAjn/Qd1BJXQ3GXP/L78T2BVIP2JVEaDmmB+wFv0/I9TRB8JDvX937Jl 1R5VfPRioTjeQvjJDF83ZPwW5JTUctlbEYa7+33MTaAkH7n6nTMZsKTAOgpRpf7UEkw0 b3aV1Y1j/p2FPqkOl6k36PrKGM7UPpzlS/3IclDSLRxp+Bb6unTkHlxCjnLz6AFDanAV pvWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686125110; x=1688717110; 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=MtzYn96ig+lorMysgzvmIhs2jjpLBGL4+9ZV/9hvBQI=; b=Q7+vBDmqkpzhq0FW3UksCJvJ35d/VM5D0ogU+x2cmBRMRIXG2U3oA0gDktcJhLOeDY CXcDu039ZObPsD64xfBlPrDpwXRgLopufjtcTVVJcnItiEe5N50W6eWqWj+1FOxzn4+q 6UzblDRzgAVk3PPuIeimk4nAkHyNsV7T2vwGHiaYZfBZTonVvhn0/Eo4YnoBDKQAOb6W pkVdsbUe7T8CR5M+HoGlclRU8UZ87MhSnobcu50MzzvEszgPCfEvH1Qi1YLfjq3LhyTx 4ExzHBAwYKyLOlM7S63LLz5c0m2h0YEh6Nyq2BFbp6kjpbcPYQbkqkagW5Iy15Nooxnl Cfhw== X-Gm-Message-State: AC+VfDxWJ4L7lTTrQpW1IR+nWJu62YOWSqA4dYTSlWupoyGbsaFiertv KKPqnra7SNascMJq1q80cATT4A== X-Google-Smtp-Source: ACHHUZ4FuRhoHzUiKf+yOibOeZljiDY9bUJxusfzOPQix1/WrJYnTWsWIjkHZ/PZsWdwMuC17ndy7Q== X-Received: by 2002:a05:6000:550:b0:30e:3c81:ca1c with SMTP id b16-20020a056000055000b0030e3c81ca1cmr3432223wrf.29.1686125109803; Wed, 07 Jun 2023 01:05:09 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:8261:5fff:fe11:bdda]) by smtp.gmail.com with ESMTPSA id h8-20020adfe988000000b0030ae5a0516csm14706269wrm.17.2023.06.07.01.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 01:05:09 -0700 (PDT) From: Neil Armstrong Date: Wed, 07 Jun 2023 10:05:02 +0200 Subject: [PATCH v2 3/8] usb: ucsi: glink: use the connector orientation GPIO to provide switch events MIME-Version: 1.0 Message-Id: <20230601-topic-sm8550-upstream-type-c-v2-3-3bbdf37575c3@linaro.org> References: <20230601-topic-sm8550-upstream-type-c-v2-0-3bbdf37575c3@linaro.org> In-Reply-To: <20230601-topic-sm8550-upstream-type-c-v2-0-3bbdf37575c3@linaro.org> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andy Gross , Bjorn Andersson , Konrad Dybcio , Heikki Krogerus , Greg Kroah-Hartman Cc: Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3632; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=dJsk94W4hJQWsF7UZ7NHEWxATRmNKuU8IakNNu3DGzw=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBkgDou7uKydBdy68HGNJVUOuX2u93V9pItw/FCCqCb S3p9hguJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZIA6LgAKCRB33NvayMhJ0e3SEA CCKMPH4CVrYSjY5mzcsv9iYk6a/p4pT35wnTqwE4FxqM0mL+Ce2XQ70S7Ez0g09/x9QASPNdJwNhLp ksqByU/Tr+JT9NWRMEShlMz3b8ojNOUG2Qq20rhIMXYzNMoIE2Utu/lHbvcdnTjzP+d8UQGOyx3GLv SuQ171ozUEGtD+1vNjVkwHUFkFnMh1hKn6peJjkQRG42rGwXaVC/TTvaGJwndI1kGeOkXiMc6LLIEG wl1jZ9+hMoJ7vGg8MgGYAJf/zF+pfPUGQd+PI14vbuTA3dfoKu19pX02bZ5j47P81khssnJqo8aWcq Ek+Xy3VYLkb6ALlzvBrfaTzItKXu/P+tARUe1Qmo5AJlGedOkDCl6ebJHOYYFSWhjTG3samL0TGemj X8NUIwXkV5dG66DKq5FVQb6vvNoV83afeOBvWTShRHqTpQ8bKGevB+lJMKbKj4cE4IkQr3P0dgx3kO bOskE6XWSTkDOBqhslAe5Jn3Aql1g3RkHeSrFBonCfZX/SXofmb5W2IhR7W3LpI3lmZBuOsU4u3zRp t5O6kfZHdrKQCKENfZ4GKLRUYKwkYOOhU6W7sVulA4ZXXr0XDIgw2VKF/FQU917AzwR3I/iElaLon0 Tf4QEU1ZEsr35JGok73G4Q/m+7Vv1Px8PNMUyAM33elYM5wZ5GIuWSrjtFiA== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org On SM8550, the non-altmode orientation is not given anymore within altmode events, even with USB SVIDs events. On the other side, the Type-C connector orientation is correctly reported by a signal from the PMIC. Take this gpio signal when we detect some Type-C port activity to notify any Type-C switches tied to the Type-C port connectors. Acked-by: Heikki Krogerus Signed-off-by: Neil Armstrong --- drivers/usb/typec/ucsi/ucsi_glink.c | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi_glink.c b/drivers/usb/typec/ucsi/ucsi_glink.c index 1fe9cb5b6bd9..88491dbff7e3 100644 --- a/drivers/usb/typec/ucsi/ucsi_glink.c +++ b/drivers/usb/typec/ucsi/ucsi_glink.c @@ -9,9 +9,13 @@ #include #include #include +#include +#include #include #include "ucsi.h" +#define PMIC_GLINK_MAX_PORTS 2 + #define UCSI_BUF_SIZE 48 #define MSG_TYPE_REQ_RESP 1 @@ -53,6 +57,9 @@ struct ucsi_notify_ind_msg { struct pmic_glink_ucsi { struct device *dev; + struct gpio_desc *port_orientation[PMIC_GLINK_MAX_PORTS]; + struct typec_switch *port_switch[PMIC_GLINK_MAX_PORTS]; + struct pmic_glink_client *client; struct ucsi *ucsi; @@ -221,8 +228,20 @@ static void pmic_glink_ucsi_notify(struct work_struct *work) } con_num = UCSI_CCI_CONNECTOR(cci); - if (con_num) + if (con_num) { + if (con_num < PMIC_GLINK_MAX_PORTS && + ucsi->port_orientation[con_num - 1]) { + int orientation = gpiod_get_value(ucsi->port_orientation[con_num - 1]); + + if (orientation >= 0) { + typec_switch_set(ucsi->port_switch[con_num - 1], + orientation ? TYPEC_ORIENTATION_REVERSE + : TYPEC_ORIENTATION_NORMAL); + } + } + ucsi_connector_change(ucsi->ucsi, con_num); + } if (ucsi->sync_pending && cci & UCSI_CCI_BUSY) { ucsi->sync_val = -EBUSY; @@ -283,6 +302,7 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev, { struct pmic_glink_ucsi *ucsi; struct device *dev = &adev->dev; + struct fwnode_handle *fwnode; int ret; ucsi = devm_kzalloc(dev, sizeof(*ucsi), GFP_KERNEL); @@ -310,6 +330,36 @@ static int pmic_glink_ucsi_probe(struct auxiliary_device *adev, ucsi_set_drvdata(ucsi->ucsi, ucsi); + device_for_each_child_node(dev, fwnode) { + u32 port; + + ret = fwnode_property_read_u32(fwnode, "reg", &port); + if (ret < 0) { + dev_err(dev, "missing reg property of %pOFn\n", fwnode); + return ret; + } + + if (port >= PMIC_GLINK_MAX_PORTS) { + dev_warn(dev, "invalid connector number, ignoring\n"); + continue; + } + + ucsi->port_orientation[port] = devm_fwnode_gpiod_get(&adev->dev, fwnode, + "orientation", + GPIOD_IN, NULL); + if (IS_ERR(ucsi->port_orientation[port])) + return dev_err_probe(dev, PTR_ERR(ucsi->port_orientation[port]), + "unable to acquire orientation gpio\n"); + + if (!ucsi->port_orientation[port]) + continue; + + ucsi->port_switch[port] = fwnode_typec_switch_get(fwnode); + if (IS_ERR(ucsi->port_switch[port])) + return dev_err_probe(dev, PTR_ERR(ucsi->port_switch[port]), + "failed to acquire orientation-switch\n"); + } + ucsi->client = devm_pmic_glink_register_client(dev, PMIC_GLINK_OWNER_USBC, pmic_glink_ucsi_callback,