From patchwork Thu Jan 12 22:16:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13099559 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 D4020C63797 for ; Thu, 12 Jan 2023 22:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240643AbjALWXB (ORCPT ); Thu, 12 Jan 2023 17:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240098AbjALWWk (ORCPT ); Thu, 12 Jan 2023 17:22:40 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F4241C916 for ; Thu, 12 Jan 2023 14:16:25 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id g20so14845478pfb.3 for ; Thu, 12 Jan 2023 14:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DjiuF0nk2Kld9KpyTDhRe2O6SrSLJ1BXqR8sAU0pb9U=; b=oZlwH+7eiNMzSIWcVe5eQOtedrPcUmvYsQ9xgKiam4GhJtqz9USbZasRnjKseYbjGy 5hNUOJCi1IrDGf9VQHhDgRf5oWzCSJi6nRjDnqXi7kLkWOD316vLo1N1u64Nftmlu4fj G8cBo7eSLqFgU5dWh+Ei1rPvnGc3Q2aNkITKg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DjiuF0nk2Kld9KpyTDhRe2O6SrSLJ1BXqR8sAU0pb9U=; b=25jmklPz57JOmeZoJvT48IIflQMvYZWoYccC//+jD4zJEegYkttFvWUVa9/P2NwYX1 hePMnUSSrI80zRSPh/mnOtcq3aGcCUcfKx2fr6AI4IfCymqP2t+QBqDJ21hFnV8H740P c7iHP8KbyL4EHbgwue3XzOIjFLFgnxO5UVhy9lcOnVcgwUtaAi9XdXGHEYlIQslVHq33 QxRCrFUN2JBDtxGvnxJWwO8fZjmOni73dLd+G4n6LOIMR7WnH9WXJ+haQMQJK4pLbHjl /+cbEwBTeKHO0YDcvQADGTk4C6R7izlm+EmkRU7LlAIvTxdj92oPoJGzDgsxwqLKq5C6 YUtQ== X-Gm-Message-State: AFqh2ko46IyFoEDpaiUIWiRaPbjvBwQ4cdPKhtCcJYk6ywy+4GyPhuMY TqnJg6h3Y3ZPUktwH22DgEsEmxb7KjwyKN8g X-Google-Smtp-Source: AMrXdXurxr+VIziGlnQiBgwKaswKl4TWFukGIKJbTAbZII2HoYU9eQx7fzUE0kwb+hx3J0V9Tcasaw== X-Received: by 2002:a62:5801:0:b0:574:a541:574a with SMTP id m1-20020a625801000000b00574a541574amr72123429pfb.0.1673561785239; Thu, 12 Jan 2023 14:16:25 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id d191-20020a621dc8000000b0058193135f6bsm12330658pfd.84.2023.01.12.14.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 14:16:24 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Greg Kroah-Hartman Subject: [PATCH 1/3] usb: typec: Add retimer handle to port altmode Date: Thu, 12 Jan 2023 22:16:06 +0000 Message-Id: <20230112221609.540754-2-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230112221609.540754-1-pmalani@chromium.org> References: <20230112221609.540754-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Just like it does with muxes, the Type-C bus code can update the state of connected retimers (especially when altmode-related transitions occur). Add a retimer handle to the port altmode struct to enable this. Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- drivers/usb/typec/bus.h | 2 ++ drivers/usb/typec/class.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/bus.h b/drivers/usb/typec/bus.h index 56dec268d4dd..c89168857417 100644 --- a/drivers/usb/typec/bus.h +++ b/drivers/usb/typec/bus.h @@ -7,11 +7,13 @@ struct bus_type; struct typec_mux; +struct typec_retimer; struct altmode { unsigned int id; struct typec_altmode adev; struct typec_mux *mux; + struct typec_retimer *retimer; enum typec_port_data roles; diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 5897905cb4f0..ed3d070b1ca4 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -583,6 +583,7 @@ void typec_unregister_altmode(struct typec_altmode *adev) { if (IS_ERR_OR_NULL(adev)) return; + typec_retimer_put(to_altmode(adev)->retimer); typec_mux_put(to_altmode(adev)->mux); device_unregister(&adev->dev); } @@ -2108,16 +2109,26 @@ typec_port_register_altmode(struct typec_port *port, { struct typec_altmode *adev; struct typec_mux *mux; + struct typec_retimer *retimer; mux = typec_mux_get(&port->dev, desc); if (IS_ERR(mux)) return ERR_CAST(mux); + retimer = typec_retimer_get(&port->dev); + if (IS_ERR(retimer)) { + typec_mux_put(mux); + return ERR_CAST(retimer); + } + adev = typec_register_altmode(&port->dev, desc); - if (IS_ERR(adev)) + if (IS_ERR(adev)) { + typec_retimer_put(retimer); typec_mux_put(mux); - else + } else { to_altmode(adev)->mux = mux; + to_altmode(adev)->retimer = retimer; + } return adev; } From patchwork Thu Jan 12 22:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13099560 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 43CDEC54EBE for ; Thu, 12 Jan 2023 22:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236847AbjALWXC (ORCPT ); Thu, 12 Jan 2023 17:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233217AbjALWWk (ORCPT ); Thu, 12 Jan 2023 17:22:40 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEC01C12A for ; Thu, 12 Jan 2023 14:16:28 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id a184so14838344pfa.9 for ; Thu, 12 Jan 2023 14:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZaweIEmq0HPzqbMZsHX/5KqxEfI0AK60Sg/9xC2e0nw=; b=AEnDVzdmu2UBDjpJSwKIR+H3w4ZA+cGy28te8O8B6LwcJ3OHPDMy7KuF7X/BTuAYow LSZJOk/Vpya21bQ8eEVdUWudOzXg2h0zt/0KH2rINXDqPGueIKrY/YM2nGCbe1UJyGzW woxeEE3JKSEUivGkiHmPgfmY8PUqlwSRtpcBg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZaweIEmq0HPzqbMZsHX/5KqxEfI0AK60Sg/9xC2e0nw=; b=gKSEDFcbDV2xFEhriIHfXjFnziEwnkDRA4ij/WH/EMiu+KhpOp7rl5h5ZmyFegQi/V 8er8diPt7Q01weaF3zdyOoZNYJR1GbtnAxoQvk8B11rqvpO7IB+aK7+xfzRuwtEoFDmz pMnvzbPRuMHKV24p9IdYq/u4OlVUlSNo6lCKl0hjeA4J6xEDBNfq5FzUjUnDJHOrj3Dg 9lAslR3i0UZ/5xR0fKzBbn5DvZKkLkaZa2Ljv8Q9gFKxkUkLtAsV2kDbrIFNvN/2PY3S BvLFVUeSQM6MqNK8988FYImztqxjWOMkpG/zUaz2QMhMSkIDZ25LGT81Y4POjqOwLkcZ A4aQ== X-Gm-Message-State: AFqh2krnGyJLnfNtqhdJnZbYLwMjj8nwloqjVd8oy836lo4EyuTVGOnq XWQaDdsXuiuiLETQpvZZkENrxA== X-Google-Smtp-Source: AMrXdXulBBi75TVTDqJKRdehZ+kuf8IyHmC3L9jSLnsD7CySIXZ4pY8l8TV7oI8z1UiL34Yj1ySrkw== X-Received: by 2002:a62:1887:0:b0:582:5886:e1b7 with SMTP id 129-20020a621887000000b005825886e1b7mr38083089pfy.14.1673561788350; Thu, 12 Jan 2023 14:16:28 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id d191-20020a621dc8000000b0058193135f6bsm12330658pfd.84.2023.01.12.14.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 14:16:28 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Greg Kroah-Hartman Subject: [PATCH 2/3] usb: typec: Add wrapper for bus switch set code Date: Thu, 12 Jan 2023 22:16:07 +0000 Message-Id: <20230112221609.540754-3-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230112221609.540754-1-pmalani@chromium.org> References: <20230112221609.540754-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a wrapper that calls the set() function for various switches associated with a port altmode. Right now, it just wraps the existing typec_mux_set() command, but it can be expanded to include other switches in future patches. No functional changes introduced by this patch. Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- drivers/usb/typec/bus.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index 31c2a3130cad..9f1bbd26ca47 100644 --- a/drivers/usb/typec/bus.c +++ b/drivers/usb/typec/bus.c @@ -27,6 +27,13 @@ typec_altmode_set_mux(struct altmode *alt, unsigned long conf, void *data) return typec_mux_set(alt->mux, &state); } +/* Wrapper to set various Type-C port switches together. */ +static inline int +typec_altmode_set_switches(struct altmode *alt, unsigned long conf, void *data) +{ + return typec_altmode_set_mux(alt, conf, data); +} + static int typec_altmode_set_state(struct typec_altmode *adev, unsigned long conf, void *data) { @@ -35,7 +42,7 @@ static int typec_altmode_set_state(struct typec_altmode *adev, port_altmode = is_port ? to_altmode(adev) : to_altmode(adev)->partner; - return typec_altmode_set_mux(port_altmode, conf, data); + return typec_altmode_set_switches(port_altmode, conf, data); } /* -------------------------------------------------------------------------- */ @@ -73,7 +80,7 @@ int typec_altmode_notify(struct typec_altmode *adev, is_port = is_typec_port(adev->dev.parent); partner = altmode->partner; - ret = typec_altmode_set_mux(is_port ? altmode : partner, conf, data); + ret = typec_altmode_set_switches(is_port ? altmode : partner, conf, data); if (ret) return ret; From patchwork Thu Jan 12 22:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13099561 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 403ECC677F1 for ; Thu, 12 Jan 2023 22:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240229AbjALWXE (ORCPT ); Thu, 12 Jan 2023 17:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240197AbjALWWl (ORCPT ); Thu, 12 Jan 2023 17:22:41 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 615E81C400 for ; Thu, 12 Jan 2023 14:16:33 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id 200so8678016pfx.7 for ; Thu, 12 Jan 2023 14:16:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HkTLc1JhoYqMaaSpYl6NjHEmEMaKe24mQDtcgzRm6SA=; b=NwLL3cGlWAqecjjWMIePO/VbFJDy2XUOI5/qdVpiCUq0EckUGu/5j6Vp9tvJRzjoYQ GQdfLylJSd4qj5BMlvzNNJ/mHcln91tySW6DlhghM4B6qEFYGV06w88nAgHdpOrjqPkg gpd8k0s0/DytaeePtdTqyGeWCK8Iw990vOn9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HkTLc1JhoYqMaaSpYl6NjHEmEMaKe24mQDtcgzRm6SA=; b=74L39jOR5wTQbtSG5o+JAPN6HwtnkbHrC+qqVbwIyakHaigRh+cXRQAGY67dPmGRC6 Ro+8gDvfdzJmiz09gKWiz062wM411ToTU+BaXiwspjgcy7aV3Dw7E5rMhqBF+qHo3DNJ BWK9XHHZp8cFDx6N3cxEeNlBxAfUH+/uJ/hyQxB8T02MsTdLjlLJEXe+TMu/33yLV3r9 LRgXuTPMI5HYOLV6N3jnh6Iy/kAStiqDOJcU8KjWl5dT6rBerVy+MGBlEQ5OfLzV3/9s 1VLhpUxyX2qjwo1S1ZYodDMNGRZ/8UBVLzO5bBNLteapRfkKr6b1PNzu28l+gNh+JfqE ZVGw== X-Gm-Message-State: AFqh2krgKUcfuU7Y85B+34h99RDxGuWHxyEJQgUFyeAlX4H6eJAIbSQs G/wwMIrPnSI91h9N9T5XA3EcUQ== X-Google-Smtp-Source: AMrXdXu7TKCZLDuVqub1CbHP5FcMT2Ikb234wbbgK+KrHmlZ69SXJ33Vm/CgeCPW7pI4tTF273r0bQ== X-Received: by 2002:a05:6a00:3311:b0:582:6732:ee03 with SMTP id cq17-20020a056a00331100b005826732ee03mr8142964pfb.9.1673561793131; Thu, 12 Jan 2023 14:16:33 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id d191-20020a621dc8000000b0058193135f6bsm12330658pfd.84.2023.01.12.14.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 14:16:32 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Greg Kroah-Hartman Subject: [PATCH 3/3] usb: typec: Make bus switch code retimer-aware Date: Thu, 12 Jan 2023 22:16:08 +0000 Message-Id: <20230112221609.540754-4-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230112221609.540754-1-pmalani@chromium.org> References: <20230112221609.540754-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Since ports can have retimers associated with them, update the Type-C alternate mode bus code to also set retimer state when the switch state is updated. While we are here, make the typec_retimer_dev_type declaration in the retimer.h file as extern, so that the header file can be successfully included in the bus code without redeclaration compilation errors. Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- drivers/usb/typec/bus.c | 22 ++++++++++++++++++++++ drivers/usb/typec/retimer.h | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index 9f1bbd26ca47..0c8d554240be 100644 --- a/drivers/usb/typec/bus.c +++ b/drivers/usb/typec/bus.c @@ -11,6 +11,22 @@ #include "bus.h" #include "class.h" #include "mux.h" +#include "retimer.h" + +static inline int +typec_altmode_set_retimer(struct altmode *alt, unsigned long conf, void *data) +{ + struct typec_retimer_state state; + + if (!alt->retimer) + return 0; + + state.alt = &alt->adev; + state.mode = conf; + state.data = data; + + return typec_retimer_set(alt->retimer, &state); +} static inline int typec_altmode_set_mux(struct altmode *alt, unsigned long conf, void *data) @@ -31,6 +47,12 @@ typec_altmode_set_mux(struct altmode *alt, unsigned long conf, void *data) static inline int typec_altmode_set_switches(struct altmode *alt, unsigned long conf, void *data) { + int ret; + + ret = typec_altmode_set_retimer(alt, conf, data); + if (ret) + return ret; + return typec_altmode_set_mux(alt, conf, data); } diff --git a/drivers/usb/typec/retimer.h b/drivers/usb/typec/retimer.h index e34bd23323be..d6a5ef9881e1 100644 --- a/drivers/usb/typec/retimer.h +++ b/drivers/usb/typec/retimer.h @@ -12,7 +12,7 @@ struct typec_retimer { #define to_typec_retimer(_dev_) container_of(_dev_, struct typec_retimer, dev) -const struct device_type typec_retimer_dev_type; +extern const struct device_type typec_retimer_dev_type; #define is_typec_retimer(dev) ((dev)->type == &typec_retimer_dev_type)