Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3076996imw; Mon, 11 Jul 2022 00:55:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ucBrJQhSe/cX//26fsa/cP7BieJ5O4yFgZobA+nnJ4ah0k9wG8J//b2MmQH1Im8ocbOsvF X-Received: by 2002:a05:6402:3301:b0:43a:9ad4:633 with SMTP id e1-20020a056402330100b0043a9ad40633mr23834321eda.261.1657526158669; Mon, 11 Jul 2022 00:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657526158; cv=none; d=google.com; s=arc-20160816; b=kIOeJ4cXPavveEzrtvauFUe80BakNccKcU6Qk3ydmYVvzFikFrb0jTS/0WNFEoE5yi BPfbQ935rYrBRrPAPYl/2Uerr7IPI8t70VM1TXSJgG6Azs5JnmzMNv+ZzPivVZjpxOYg oI3FeMDCUCJUYbwtYo37ouFQD/2SrwHBHAQ2NmeN1wlyUgAkxLxF0W3tyHm95LFDxn0i JHZMA7B5+eOkad68e2LoHccX29luXekzCmZFoX8RWcezT11Yo660XSGB4jTKxYnP+djv eEsF2NN8gq/9sxEeWwyjz2a53/mg4QE/rafQzG5fFLvv8V+NrN/3h6ny9cSaJNbhn3L2 m6Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+189CxxcoXTJww1vvNRT20TPCnm9kCVhx1btF3TMXi8=; b=ufwWAi5jLn8+RAUuyTlnF6LcLGS+DVrRXPitqMsqcB6An+94uuSGt9wXGbb8uMw5vf A34gGTOTWQcYvJ7jCVFI1Xs+zKoADXRSL7aA1y2YfN1jVKA5HOM0xoUTlN8yJQ0mbuEU NwP7Mw8Bm/oK7phM8H1U3dyUrZ4G66150DacyZlJqGoo6ZaqkpS38LlW1JV8MhBDSM7D UBD52okCSwY36cb75iaAdUugYpNTgCJWfIif2YP/g53nEUBRSe5wetY01Z1Zu8rhTb1P LOme794PAlAPHfFzdig9JAVxMu1Pdkzv+hWQLV9sjNoclI+/wuFMPC3OMqmIdb+S2pmp IqPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k74DOFzN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg18-20020a170907a41200b007262b057924si2125668ejc.900.2022.07.11.00.55.33; Mon, 11 Jul 2022 00:55:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k74DOFzN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbiGKH2s (ORCPT + 99 others); Mon, 11 Jul 2022 03:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229594AbiGKH2q (ORCPT ); Mon, 11 Jul 2022 03:28:46 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8039BA1A8 for ; Mon, 11 Jul 2022 00:28:45 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id z1so3748895plb.1 for ; Mon, 11 Jul 2022 00:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+189CxxcoXTJww1vvNRT20TPCnm9kCVhx1btF3TMXi8=; b=k74DOFzNKkceSWgme9B9za4lw91QGrG2qroaIHb8gns+t7uTeteRvn4NBHF6QGCAz7 3PaEWSWLS9kbrum42fuA4GA6Tko9EfKdNPyTKFyn1UXvXVfw6Abh+Wyp9v/uWQbAAfjC HHnYXgeP+D9JEx0OYFvlogJ2vUNGnqXtBqEUY= 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=+189CxxcoXTJww1vvNRT20TPCnm9kCVhx1btF3TMXi8=; b=iiJ5uTpHlIKZGw0gjyHJpf2qD7ZlHUVkRiQAUq3ooNZyU1cpZGVPBkUN2JJVUhD6Bz oC8NzsDM8zXe9PSEEIIH/C+SBaC9dPgUz0ei3EcOreZNAtRrXR39w6jezn5G50x+oK3U TCkglcxY2IS4kM7xQwrdREzyttjKPYq0kIUkQUYeThdnR0AMxgKfdb2c4vPL2UeHkKzs Cv07/hCd2bMqeW9DGoFL3qsxFF4D5EyjLVxUtiRHg3hvYVouDQuxTEWLVrDszjqVFbRm zM161cLquQUYKSWrJ78cKoacereNxSfdul05t1vEmwiVkqiELYOphafZNzCw+s93qobk c2rQ== X-Gm-Message-State: AJIora+/iX0EysdIDVtOl7msMM/102aJdVZUuf0iGQ3Vqz3REPFu+JfA /2s+mTCLMXos+DcR83ji6743uiSkmJ7H/A== X-Received: by 2002:a17:90b:4f85:b0:1f0:95d:c02b with SMTP id qe5-20020a17090b4f8500b001f0095dc02bmr14519392pjb.89.1657524524861; Mon, 11 Jul 2022 00:28:44 -0700 (PDT) Received: from pmalani.c.googlers.com.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id z8-20020aa79e48000000b0051bc5f4df1csm4012839pfq.154.2022.07.11.00.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 00:28:44 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: bleung@chromium.org, heikki.krogerus@linux.intel.com, Prashant Malani , Daisuke Nojiri , "Dustin L. Howett" , Greg Kroah-Hartman , Guenter Roeck , "Gustavo A. R. Silva" , Sebastian Reichel , Tzung-Bi Shih Subject: [PATCH v4 7/9] platform/chrome: cros_typec_switch: Register mode switches Date: Mon, 11 Jul 2022 07:23:01 +0000 Message-Id: <20220711072333.2064341-8-pmalani@chromium.org> X-Mailer: git-send-email 2.37.0.144.g8ac04bfd2-goog In-Reply-To: <20220711072333.2064341-1-pmalani@chromium.org> References: <20220711072333.2064341-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Register mode switch devices for Type C connectors, when they are specified by firmware. These control Type C configuration for any USB Type-C mode switches (sometimes known as "muxes") which are controlled by the Chrome EC. Signed-off-by: Prashant Malani --- Changes since v3: - No changes. Changes since v2: - Fixed missing "static" identifier. Changes since v1: - No changes. drivers/platform/chrome/cros_typec_switch.c | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index 7c01957a032d..024a2bb146b2 100644 --- a/drivers/platform/chrome/cros_typec_switch.c +++ b/drivers/platform/chrome/cros_typec_switch.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #define DRV_NAME "cros-typec-switch" @@ -22,6 +23,7 @@ /* Handles and other relevant data required for each port's switches. */ struct cros_typec_port { int port_num; + struct typec_mux_dev *mode_switch; struct typec_retimer *retimer; struct cros_typec_switch_data *sdata; }; @@ -147,6 +149,15 @@ static int cros_typec_configure_mux(struct cros_typec_switch_data *sdata, int po return -ETIMEDOUT; } +static int cros_typec_mode_switch_set(struct typec_mux_dev *mode_switch, + struct typec_mux_state *state) +{ + struct cros_typec_port *port = typec_mux_get_drvdata(mode_switch); + + /* Mode switches have index 0. */ + return cros_typec_configure_mux(port->sdata, port->port_num, 0, state->mode, state->alt); +} + static int cros_typec_retimer_set(struct typec_retimer *retimer, struct typec_retimer_state *state) { struct cros_typec_port *port = typec_retimer_get_drvdata(retimer); @@ -163,9 +174,27 @@ static void cros_typec_unregister_switches(struct cros_typec_switch_data *sdata) if (!sdata->ports[i]) continue; typec_retimer_unregister(sdata->ports[i]->retimer); + typec_mux_unregister(sdata->ports[i]->mode_switch); } } +static int cros_typec_register_mode_switch(struct cros_typec_port *port, + struct fwnode_handle *fwnode) +{ + struct typec_mux_desc mode_switch_desc = { + .fwnode = fwnode, + .drvdata = port, + .name = fwnode_get_name(fwnode), + .set = cros_typec_mode_switch_set, + }; + + port->mode_switch = typec_mux_register(port->sdata->dev, &mode_switch_desc); + if (IS_ERR(port->mode_switch)) + return PTR_ERR(port->mode_switch); + + return 0; +} + static int cros_typec_register_retimer(struct cros_typec_port *port, struct fwnode_handle *fwnode) { struct typec_retimer_desc retimer_desc = { @@ -235,6 +264,17 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata) } dev_dbg(dev, "Retimer switch registered for index %llu\n", index); + + if (!fwnode_property_read_bool(fwnode, "mode-switch")) + continue; + + ret = cros_typec_register_mode_switch(port, fwnode); + if (ret) { + dev_err(dev, "Mode switch register failed\n"); + goto err_switch; + } + + dev_dbg(dev, "Mode switch registered for index %llu\n", index); } return 0; -- 2.37.0.144.g8ac04bfd2-goog