From patchwork Wed Jun 14 13:10:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 693219 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 AD687EB64DC for ; Wed, 14 Jun 2023 13:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244850AbjFNNLM (ORCPT ); Wed, 14 Jun 2023 09:11:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244825AbjFNNLL (ORCPT ); Wed, 14 Jun 2023 09:11:11 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13DC82686 for ; Wed, 14 Jun 2023 06:10:46 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f736e0c9b1so6928755e9.3 for ; Wed, 14 Jun 2023 06:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686748244; x=1689340244; 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=HclWVyX80bhOFPdvQBpaJpPvaaJ2GD6Ys/9aQx4/1wc=; b=ZSdd12LYj/Kv9D9GAb3sJ3+7Bo5IpcnzyxCjSPxGpNG5wlx4ijp8JvuERRYOFYjHBo 7lbCTh+CK/nvTRcuanXk06s+mtaO6/zQDNh7r0YGHkgUQPVw7XJVvjkIQtQ6WjoL7nXz +5I4LTQTFfXgukUbcI5rJlZRa7t53ErPqdZdpXrFdPm+nqn4ffXjPEgtOX9jfbnK8isz BGHVAeQoSg3/2krtGW3xbIcmE1AN/vKrs5AFcd6cAvBupCU0Ql3pcWlYk4IupDW4pG+B d8sD+emx6XWBpqhUK+R4ATqU+gI5lbrnuwiV5E4K4ysRumkgRKcVXfgSFaiWh4kYsk85 e7Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686748244; x=1689340244; 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=HclWVyX80bhOFPdvQBpaJpPvaaJ2GD6Ys/9aQx4/1wc=; b=bav0snoVzJz8XHkwxXBZaardXPRDfDWP2b083cE/Hb1wlPoTV7NnkM3BubzvMDoc8N veuCL3qx0/izMC4AYiwK5VUf7pLLoQIb9F/3AcUX6JzTt/66mTugfsMvqe4Mek6z2Ldz iHp5/micJCSXhERoUWMtPgNKvepjXi5QyLTshqSvbbS3uEk+58g75+b0rXkTjR1WkahV lfFeB0t5DNJOv2PGKCgLxvTy6kWIFqik2RSAORrCsS+wH4kfkGRTvHwdXCPB1ZhyUO1B JA8yvzRY2Swy3XtMeU8dpmDZc+1RTUwV86KJj9lMxPabRKHGmKO0ZTZ1ETVp43Iwxr1J iWZA== X-Gm-Message-State: AC+VfDzxeSwBzqgnu9iiX0MaOTcVnaItSRhr3OC/G/aN8oWKoap8B8Po Ghu2jli3M54iiby6WAZX16X5HQ== X-Google-Smtp-Source: ACHHUZ4Tu7DdIbjz+CQUImQwiBv2U020Y2/C3uQep0sjkwJlz93iyXariO6Qg3fKaDSpci4DHgQswQ== X-Received: by 2002:a05:600c:2141:b0:3f8:afe:5c40 with SMTP id v1-20020a05600c214100b003f80afe5c40mr10867975wml.1.1686748244505; Wed, 14 Jun 2023 06:10:44 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id a7-20020a05600c224700b003f60a9ccd34sm17548661wmm.37.2023.06.14.06.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 06:10:44 -0700 (PDT) From: Neil Armstrong Date: Wed, 14 Jun 2023 15:10:39 +0200 Subject: [PATCH 1/3] usb: typec: ucsi: call typec_set_mode on non-altmode partner change MIME-Version: 1.0 Message-Id: <20230614-topic-sm8550-upstream-type-c-audio-v1-1-15a92565146b@linaro.org> References: <20230614-topic-sm8550-upstream-type-c-audio-v1-0-15a92565146b@linaro.org> In-Reply-To: <20230614-topic-sm8550-upstream-type-c-audio-v1-0-15a92565146b@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Krzysztof Kozlowski , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1579; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=PGFbR5syJg5NTdmizgxwbBoZ3GYDeK4EiGxX2vNbnno=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBkibxReHuJHWn9DyKqKHMz06Y4DW1u0rOTKOJfwIzb FgBpCTSJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZIm8UQAKCRB33NvayMhJ0VwfD/ sHgM9OXt8gMsAv2gGSYhLccRScaCG/+Z6W1x85rxqst2icVK6hShU50RSvVaRMYzedbI2MNKv7xtG/ F5mJSNpVubPaUU8XPpiwAMpjLGnUQm8peyOf+z/K5ibXwqNqpCgJGguKD9WsHiwRt/VIug9O16KAth wDjK6eEc/hmIVc5ecxrasDNz0MqDroZC55MTwMJTs0/KUlM9Puqh3kczG619xFat+bMHfiMDPiWGYZ f0AWFMO+yb7P9hE6DcUWXt4tirFEKrgXi6vFSaqPguShzRGKwLi8eMkaLH7qxtNulQ6kn4A2EK+81k SQNz2ILxub286IaifHPO2eHl+mJstwxR3hMjE4cfF5T3J4g2U2yoLeBp+jiEgA+jAOEe6roRAclqEL FDTSPOP5cLvKecUHZGK1mNRZ0PanlZWaIc8i71ueKXETeEuNDkblmiEuXKEEf3Ch+wKYn8+LavsOFw W50yvT0UM8y+iXkAXxBdwYgMHSMMHeH1nuRDKe43sLXps6MfFpuh3i6kl4Vgy4Csfhez+qilS+IdBv aHD3ZWky21K+TgwNrcAL+euKWdn9APOwYDN0uE+CTmI01ouMdFEjhr+ZNWHvm0hMUmDyJ8kpwS+7pc kFns3U2Mo7sg3fjaBeFCX0JzvnvJg/siXItbawJL1Npt/f78CZkCdbkgU9Dw== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add support for calling typec_set_mode() for the DEBUG, AUDIO accessory modes. Let's also call typec_set_mode() for USB as default and SAFE when partner is disconnected. The USB state is only called when ALT mode is specifically not specified by the partner status flags in order to leave the altmode handlers setup the proper mode to switches, muxes and retimers. Signed-off-by: Neil Armstrong --- drivers/usb/typec/ucsi/ucsi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 2b472ec01dc4..44f43cdea5c1 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -809,6 +809,23 @@ static void ucsi_partner_change(struct ucsi_connector *con) break; } + if (con->status.flags & UCSI_CONSTAT_CONNECTED) { + switch (UCSI_CONSTAT_PARTNER_TYPE(con->status.flags)) { + case UCSI_CONSTAT_PARTNER_TYPE_DEBUG: + typec_set_mode(con->port, TYPEC_MODE_DEBUG); + break; + case UCSI_CONSTAT_PARTNER_TYPE_AUDIO: + typec_set_mode(con->port, TYPEC_MODE_AUDIO); + break; + default: + if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) == + UCSI_CONSTAT_PARTNER_FLAG_USB) + typec_set_mode(con->port, TYPEC_STATE_USB); + } + } else { + typec_set_mode(con->port, TYPEC_STATE_SAFE); + } + /* Only notify USB controller if partner supports USB data */ if (!(UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) & UCSI_CONSTAT_PARTNER_FLAG_USB)) u_role = USB_ROLE_NONE; From patchwork Wed Jun 14 13:10:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 692968 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 151ADEB64DD for ; Wed, 14 Jun 2023 13:11:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244855AbjFNNLN (ORCPT ); Wed, 14 Jun 2023 09:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244816AbjFNNLM (ORCPT ); Wed, 14 Jun 2023 09:11:12 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2EE81FD6 for ; Wed, 14 Jun 2023 06:10:46 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f7e7fc9fe6so7758975e9.3 for ; Wed, 14 Jun 2023 06:10:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686748245; x=1689340245; 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=6ryHJYj8SuHK1Fpj/7T+/dhtmp5a7mPpMgbt52XOOoY=; b=yHbrEfRM/nMoPaU6NJkYzVxOGVz7j/pY3q+K9Ga56ay0Bl/tIVeFPzUmwnBYqcmGbi ItyMTegESrBhrcMvn6nFPEXd1mbnkazEvxRKz3QNJkJbRe+nqv8ve30swTrXEGbXu41C nWIql+TaSFhsZIUYBkhy5sb6WRAhvilmUbd5Dg3aGSu/SvmbWDfV5qvyZhzswV8arNml 2X4WOpmxYVoNKdGd7VmurpUGXIR1gVoGfBRHMQid/u++KnIC1PE5D1UcziXclrgfNebG 8r9zfkS5K6axx8ErhcoW5KbpqzthyOhTFoO0O9fwtmtE0Rlk8+d4JM2InX4ltj4nAf40 PEXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686748245; x=1689340245; 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=6ryHJYj8SuHK1Fpj/7T+/dhtmp5a7mPpMgbt52XOOoY=; b=YdUqNy6B53ToJ81zh6WZN7qLueIOAdm6wH5MQ3hpFmDCG9rm7J9MTtJNcpoYF8OY9+ HtgIx0B6q36mAugkgfwtXvU1PhLd5Ugxk79L7Fw7Mjt+l+7O2QviSsGo5BtWjWRPbBKg PLdF1ONG4AA2Sfs99vd9CfgynUhWf3GyAQ/Ne+AGxIwoe22x3ONGmKXwe5sIScLXsO87 uMK/NKcEEMNi9xiR1tauoyoUEC9BtVqNBwIQ0KVcZOr0IgwCN8fvPxqoHhK12JZ1tmQp M9VRfm8/2aDjmEfagnOI5BHA+MzCkIoEG4qS1jY1uER3j1oF/CG5MiTUunapyyYR3ZTb TSFw== X-Gm-Message-State: AC+VfDz8RlAc9Mwr46Qc+lrIZRCljV8wshVaMVcLFgfCBYgrovWxd906 Qou6DXyvlU8Ry+9488V63JpVCg== X-Google-Smtp-Source: ACHHUZ4LPZs0WrsTGUtJ6EUJ+pfuunak8jjNQdc5Zq6hLEf93D82dKWEQpYf8GODfNMyFlQAbFSmlA== X-Received: by 2002:a7b:c4da:0:b0:3f7:f90c:4978 with SMTP id g26-20020a7bc4da000000b003f7f90c4978mr11817404wmk.21.1686748245323; Wed, 14 Jun 2023 06:10:45 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id a7-20020a05600c224700b003f60a9ccd34sm17548661wmm.37.2023.06.14.06.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 06:10:44 -0700 (PDT) From: Neil Armstrong Date: Wed, 14 Jun 2023 15:10:40 +0200 Subject: [PATCH 2/3] usb: typec: fsa4480: rework mux & switch setup to handle more states MIME-Version: 1.0 Message-Id: <20230614-topic-sm8550-upstream-type-c-audio-v1-2-15a92565146b@linaro.org> References: <20230614-topic-sm8550-upstream-type-c-audio-v1-0-15a92565146b@linaro.org> In-Reply-To: <20230614-topic-sm8550-upstream-type-c-audio-v1-0-15a92565146b@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Krzysztof Kozlowski , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5398; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=QarI/JISSj/rhGR4VdIVmKxfvzqx9rkOwDJ/2WosLjU=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBkibxSHRni5b6A/0yaMrWRH2dqpShK1pJn0rgEcOaT 7bUY38aJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZIm8UgAKCRB33NvayMhJ0a/LEA DMo3j2DaCaw6ioaGzRmATCzZpwL0rEoHVw3mZ+qCiMPZ//lDkDnEKEnk8F0anWD5q26d/OJduz2N5F ATUMVRFKD/oAs5D5WYMx3PBBuQ2P6QT93X/Our/Eb9lx3QQuGKC+nskR+Sd7poyIYXqUMV5gjCRH97 v/2cG+lTWHbtgdfsdNJtOuRAQio0lB+YZrs+DiF+SzPwGXl0VKQ3OGR1lv046xB99QUPxwKqz9bBjG xHiokT5rIl7qTBCFN3Kx52v3AafnLQg3uXbV1DqIrl+wf6QRFtSBHmaUAiSA1MoaodRQHs+UFy8ZpM 7yHcB30Re63woYtcvXEtrM9BbdAIb5Jua/D2nZjmd6cyJXbyF8kSWrSE5MeijblLohNQJeTbLrbnQY vWedOihhOKvJJexBMt7tYlIAnN2SEnj2l4nsleJ21QFsoORg+imp7NKu5TmX6129v33n7vhIi7lOdd 46W+oYclJzsX/vIUzsW4hItnmxlrU2PejCBtiJSF54bM6AxX06vIOu5LkuwIgoFoemCDq5DlqNgYkV FS1OswD+Xc0WNPcqB6+eHzsj+oaBmDdxlRHmw2VoUqZsMi9FuGEmlol6jCP6utJcZ1smvh+2E9QUFP 2KCzzpo1b5uHRKUt9BBRTM0J/z2maX7XdCpXQeMxJ/DeHvclGQz0nI9nOkqQ== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In order to handle the Audio Accessory mode, refactor the mux and switch setup in a single function. The refactor will help add new states and make the process simpler to understand. Signed-off-by: Neil Armstrong Tested-by: Krzysztof Kozlowski --- drivers/usb/typec/mux/fsa4480.c | 111 +++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 36 deletions(-) diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c index d6495e533e58..b2913594a58f 100644 --- a/drivers/usb/typec/mux/fsa4480.c +++ b/drivers/usb/typec/mux/fsa4480.c @@ -46,8 +46,11 @@ struct fsa4480 { struct regmap *regmap; + enum typec_orientation orientation; + unsigned long mode; + unsigned int svid; + u8 cur_enable; - u8 cur_select; }; static const struct regmap_config fsa4480_regmap_config = { @@ -58,19 +61,42 @@ static const struct regmap_config fsa4480_regmap_config = { .disable_locking = true, }; -static int fsa4480_switch_set(struct typec_switch_dev *sw, - enum typec_orientation orientation) +static int fsa4480_set(struct fsa4480 *fsa) { - 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; + bool reverse = (fsa->orientation == TYPEC_ORIENTATION_REVERSE); + u8 enable = FSA4480_ENABLE_DEVICE; + u8 sel = 0; + + /* USB Mode */ + if (fsa->mode < TYPEC_STATE_MODAL || + (!fsa->svid && (fsa->mode == TYPEC_MODE_USB2 || + fsa->mode == TYPEC_MODE_USB3))) { + enable |= FSA4480_ENABLE_USB; + sel = FSA4480_SEL_USB; + } else if (fsa->svid) { + switch (fsa->mode) { + /* DP Only */ + case TYPEC_DP_STATE_C: + case TYPEC_DP_STATE_E: + enable |= FSA4480_ENABLE_SBU; + if (reverse) + sel = FSA4480_SEL_SBU_REVERSE; + break; + + /* DP + USB */ + case TYPEC_DP_STATE_D: + case TYPEC_DP_STATE_F: + enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_SBU; + sel = FSA4480_SEL_USB; + if (reverse) + sel |= FSA4480_SEL_SBU_REVERSE; + break; + + default: + return -EOPNOTSUPP; + } + } else + return -EOPNOTSUPP; if (fsa->cur_enable & FSA4480_ENABLE_SBU) { /* Disable SBU output while re-configuring the switch */ @@ -81,48 +107,59 @@ static int fsa4480_switch_set(struct typec_switch_dev *sw, 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); + regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, sel); + regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, enable); + if (enable & FSA4480_ENABLE_SBU) { /* 15us to allow the SBU switch to turn on again */ usleep_range(15, 1000); } -out_unlock: - mutex_unlock(&fsa->lock); + fsa->cur_enable = enable; return 0; } +static int fsa4480_switch_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + struct fsa4480 *fsa = typec_switch_get_drvdata(sw); + int ret = 0; + + mutex_lock(&fsa->lock); + + if (fsa->orientation != orientation) { + fsa->orientation = orientation; + + ret = fsa4480_set(fsa); + } + + mutex_unlock(&fsa->lock); + + return ret; +} + 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; + int ret = 0; 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 (fsa->mode != state->mode) { + fsa->mode = state->mode; - if (new_enable == fsa->cur_enable) - goto out_unlock; + if (state->alt) + fsa->svid = state->alt->svid; + else + fsa->svid = 0; // No SVID - 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); + ret = fsa4480_set(fsa); } -out_unlock: mutex_unlock(&fsa->lock); - return 0; + return ret; } static int fsa4480_probe(struct i2c_client *client) @@ -143,8 +180,10 @@ static int fsa4480_probe(struct i2c_client *client) if (IS_ERR(fsa->regmap)) return dev_err_probe(dev, PTR_ERR(fsa->regmap), "failed to initialize regmap\n"); + /* Safe mode */ fsa->cur_enable = FSA4480_ENABLE_DEVICE | FSA4480_ENABLE_USB; - fsa->cur_select = FSA4480_SEL_USB; + fsa->mode = TYPEC_STATE_SAFE; + fsa->orientation = TYPEC_ORIENTATION_NONE; /* set default settings */ regmap_write(fsa->regmap, FSA4480_SLOW_L, 0x00); @@ -156,7 +195,7 @@ static int fsa4480_probe(struct i2c_client *client) 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_SELECT, FSA4480_SEL_USB); regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, fsa->cur_enable); sw_desc.drvdata = fsa; From patchwork Wed Jun 14 13:10:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 693218 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 1C28BEB64D9 for ; Wed, 14 Jun 2023 13:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244864AbjFNNLO (ORCPT ); Wed, 14 Jun 2023 09:11:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244857AbjFNNLN (ORCPT ); Wed, 14 Jun 2023 09:11:13 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F2B268D for ; Wed, 14 Jun 2023 06:10:47 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f8cc04c287so6013095e9.0 for ; Wed, 14 Jun 2023 06:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686748246; x=1689340246; 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=dRzG+HV9GN4lfJMfWqgxlfRDbNNuf4h9SVoZ/Ln+yfM=; b=Abt84zPG1mZC7LoNsgyS/gG+GrkwXO5EYd4Oyn762VvhrHxIk7SUotb1Ogslm71/I0 ATLqAshTF7CDjww/zykZLRHWnCj5rVshi7dDPRp92TZaM2Qyo2G7LNyl1p4v8IEHyiX2 4hBA/wC9ZdQMuN3UwYfRU6lia70FeBwcj2aYgPZFeAg0hzZKDsn/v6obhqLNPHbS0U2G WxH0CSDpjPE/pkJtBxJngH8RqGQn8GBq6Sg5uXbDShG/HU/mPaL6ORWMAzK3BvOyNtGM hnm43phqzmWoRJbDZA40KxAx0N0kFXSOk+QGK8QwlJeNLyKLvufe3lgs5TB+HRHv6fOM me5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686748246; x=1689340246; 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=dRzG+HV9GN4lfJMfWqgxlfRDbNNuf4h9SVoZ/Ln+yfM=; b=PrUNfQQwOKLvZKsC53l6HS3qC6CDpyyMtYr5uMGN5oB+z3atctZgIPSq6meXrs+xuL MOrtcwO1N93UBoI9+k9PeVf9PFi66/KsZVpd1OI+cTYW+IWDoDBpCMMSVWaWvjGiElh8 UkMRWda+RDPu023vfPz4rWiVthHSObnHD3PGrlZFF2OunFNvRjU/JGIHnhaep/Eqgadu exNtQrRb1Mf3NoM+h+YHYwO9lrZdkqyOe0PLSErmEyoE6/IQD6nhc5FYu3cq7IcWMQI9 QfMIFD71v7xL/llT1oYiryTY0AzW5TViHkF2BuGspGJvUimN9Jq3F+Klr/k83CjCske7 itVA== X-Gm-Message-State: AC+VfDxUAGYHv/o/hs7SKJ0A2w9tKAV0sPRJJAJHn18tIRi35IvKZSw6 Jfq9XVO0Y4Q4cg9yCOih0SjY9g== X-Google-Smtp-Source: ACHHUZ7j42D1SG7rrT1Cld1gmzJEwnGxajVFXglzCpGYyHpVVCce1ptErw8HFvkeJ3zahOIhanxkOQ== X-Received: by 2002:a7b:ce88:0:b0:3f7:34dc:ed0d with SMTP id q8-20020a7bce88000000b003f734dced0dmr11048944wmj.25.1686748246152; Wed, 14 Jun 2023 06:10:46 -0700 (PDT) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id a7-20020a05600c224700b003f60a9ccd34sm17548661wmm.37.2023.06.14.06.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 06:10:45 -0700 (PDT) From: Neil Armstrong Date: Wed, 14 Jun 2023 15:10:41 +0200 Subject: [PATCH 3/3] usb: typec: fsa4480: add support for Audio Accessory Mode MIME-Version: 1.0 Message-Id: <20230614-topic-sm8550-upstream-type-c-audio-v1-3-15a92565146b@linaro.org> References: <20230614-topic-sm8550-upstream-type-c-audio-v1-0-15a92565146b@linaro.org> In-Reply-To: <20230614-topic-sm8550-upstream-type-c-audio-v1-0-15a92565146b@linaro.org> To: Heikki Krogerus , Greg Kroah-Hartman Cc: Krzysztof Kozlowski , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2308; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=AmK9tGuhBzHU6OgDlD+wPAdxUZOMyPGmnDLrHwn/j/c=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBkibxSO3IckWWolI0nLUXzFCyCRUwuqC71q47oYIZ3 SH4yGcyJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZIm8UgAKCRB33NvayMhJ0fUBD/ 4+WAQp8FuGaqCALfEFyB70ECb1yhUyo7bs4XJUARqa3sklwtH4oeb2nhWCJvcQKHKX510tvXmGMfmn ZNVpF7o9zHgYbSu9ICVa7CiROfCeNzYZ0BJR4dk1Lp9ua307BnoB57leUyaCR/QhacygzrGsJBoK2y 4sWwdIXHXSVF1SXFFel2eHWuFuOCPBlx2g+nsF9iW/Jvwe4FNsoJLLMfq37u/j4BkkG91aDJ/L724x NMNJLZYuGhrtVWi1TW0qy2PTdgp3t1GLGdTlTPZEWqaB8ifSla4zbHALA/t7WyvXa2cs+4S6VO60nB cVCtBUxRdYaczIE4E4XMH60AXVanHmqk2leErKRG6UO4zYhFjKgaCrMIlJXTPuF7gi92ZEE/t9FeZT 6OqrFwf/fxCcM5U5cZgyjTsYY0e7hbcGcT7Lkj+8XKGX9lyTNBLOnxOxzlGZB2wmri08aM2CjlOQvl TcpgOsruioWe++bQIhSwv0x28FDyMtsbTUr/OmwRx9uzCaHbVhLMY6pen4sSpaWnWaPDUFkznkAVWo ZNczyznmecSJdCkR2x5g54u2z5Avlhp1u0nf8XyXyZf4fOr3zkGL7QQhY32mZQ64dmxGE4/2FeANT9 0g2KeO/o8bPb61OlVA70idWgqBCFcDqfU56csnUWRMvgBjIJjE8WBftgUNtA== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The FSA4480 Type-C switch supports switching the Audio R/L, AGND and MIC signals to the USB-C DP/DM and SBU1/2 to support the Audio Accessory Mode. The FSA4480 has an integrated Audio jack detection mechanism to automatically mux the AGND, MIX and Sense to the correct SBU lines to support 3 pole and both 4 pole TRRS pinouts. Signed-off-by: Neil Armstrong Acked-by: Heikki Krogerus --- drivers/usb/typec/mux/fsa4480.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c index b2913594a58f..45f5683b7d81 100644 --- a/drivers/usb/typec/mux/fsa4480.c +++ b/drivers/usb/typec/mux/fsa4480.c @@ -25,15 +25,24 @@ #define FSA4480_DELAY_L_MIC 0x0e #define FSA4480_DELAY_L_SENSE 0x0f #define FSA4480_DELAY_L_AGND 0x10 +#define FSA4480_FUNCTION_ENABLE 0x12 #define FSA4480_RESET 0x1e #define FSA4480_MAX_REGISTER 0x1f #define FSA4480_ENABLE_DEVICE BIT(7) #define FSA4480_ENABLE_SBU GENMASK(6, 5) #define FSA4480_ENABLE_USB GENMASK(4, 3) +#define FSA4480_ENABLE_SENSE BIT(2) +#define FSA4480_ENABLE_MIC BIT(1) +#define FSA4480_ENABLE_AGND BIT(0) #define FSA4480_SEL_SBU_REVERSE GENMASK(6, 5) #define FSA4480_SEL_USB GENMASK(4, 3) +#define FSA4480_SEL_SENSE BIT(2) +#define FSA4480_SEL_MIC BIT(1) +#define FSA4480_SEL_AGND BIT(0) + +#define FSA4480_ENABLE_AUTO_JACK_DETECT BIT(0) struct fsa4480 { struct i2c_client *client; @@ -95,6 +104,9 @@ static int fsa4480_set(struct fsa4480 *fsa) default: return -EOPNOTSUPP; } + } else if (fsa->mode == TYPEC_MODE_AUDIO) { + /* Audio Accessory Mode, setup to auto Jack Detection */ + enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_AGND; } else return -EOPNOTSUPP; @@ -110,6 +122,11 @@ static int fsa4480_set(struct fsa4480 *fsa) regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, sel); regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, enable); + /* Start AUDIO JACK DETECTION to setup MIC, AGND & Sense muxes */ + if (enable & FSA4480_ENABLE_AGND) + regmap_write(fsa->regmap, FSA4480_FUNCTION_ENABLE, + FSA4480_ENABLE_AUTO_JACK_DETECT); + if (enable & FSA4480_ENABLE_SBU) { /* 15us to allow the SBU switch to turn on again */ usleep_range(15, 1000);