Received: by 2002:a05:6512:e85:0:0:0:0 with SMTP id bi5csp48860lfb; Wed, 29 Jun 2022 17:05:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tbdeq+e4BYbRtkdLDCWQujWWWDVWG2gyA+eWNozFfPbcL7e/iUYdDa8ZSHe885tdERDH+U X-Received: by 2002:a05:6402:3511:b0:437:7eec:c44c with SMTP id b17-20020a056402351100b004377eecc44cmr7817271edd.11.1656547545027; Wed, 29 Jun 2022 17:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656547545; cv=none; d=google.com; s=arc-20160816; b=L0saOkV2OBt8/A94xpQTyeoOHBfhHNJgJ9V4bs2ppiR79f9AbmbIGO84DZyLnSPYiN CQ3+4/z4ue4dmwm//nZlBv6AMB4tKNBNvDjkPYpoQRHPC101rqea1ND9z/t6s7i2VeEd n5OVIK1emBaolU5sjfr0U+nXrI0j4+eiueT2GKjfqdGL0a63eQtdUw1mz6SMwwUB+N6H AKTlCo3dRkOVL76h/CMxk0iBNPbWCmzIqnz+vsCPNe4K3HE1goX0lPbMXZVfJbT/U6UN MV5gzapBomeh+aBL/kWQ3XG+vGWUp9eH6RCPdpJSNX0MaZ2kaOmKABYVNSOsOocxyfoi X6yQ== 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=CuvWwcvHM3CjPq4zOn6t6Lokqjtv/6pY0DnLIhVk+yY=; b=H+buOnO2mAjEv2TKMNtyrXCokX74m6nsAfmeaZ6vm1V/Ik7BJvaEPIbSdx7j9d7KG4 D0SaXg4lTeBiURAG4RxOZbzCtt/sYD7mKxjRyxbMl2tlz0kJyGcQEugnx7OTyPzGzpYi RVE/WZYzFc8sXpdLwWsQkoSUXjXzHCs4W0wIGlJ/wj1YilgX17jS1F//2JSEiLYUG8KA sviXsY3b+pMgdmP9odgHG9b8fTfkp9RLHDA1rz0oeHNozQu9+ou0G6L+KumLin75vv3G lr9++A3LPD4Hx9C5APk847aCZ3UX8vz6Upi+JPbzRR8A9opxMuCZdLugsoNWVGgyzVjV wBhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iMi7r4Es; 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 e10-20020a056402088a00b00428679d26b1si20140975edy.331.2022.06.29.17.05.17; Wed, 29 Jun 2022 17:05:45 -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=iMi7r4Es; 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 S229698AbiF2Xio (ORCPT + 99 others); Wed, 29 Jun 2022 19:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231772AbiF2Xih (ORCPT ); Wed, 29 Jun 2022 19:38:37 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11A56DF27 for ; Wed, 29 Jun 2022 16:38:36 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d5so15462497plo.12 for ; Wed, 29 Jun 2022 16:38:36 -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=CuvWwcvHM3CjPq4zOn6t6Lokqjtv/6pY0DnLIhVk+yY=; b=iMi7r4EsH0aKZCwW/2qReJ1ynuqAASO6Ooya/u3xURCjcx9d5iAUaXuuhiRInBWHpL NYmtwmhO+GYkWo/mBuuHXJqIgD1dz7arR7eEF9rnY1dZ0RWIAk9YGfV52s9f4vzywnW7 9+v1aP3vhp/TX80fV8NzFOP6IlsiBwvBSH3N4= 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=CuvWwcvHM3CjPq4zOn6t6Lokqjtv/6pY0DnLIhVk+yY=; b=mqXPEW2jzifthNhBQcdAwWglT6C5oVuCjaOBA2FgNBttAYZ2fTUBGQ/W/gdD6suzRZ FSfFhBm+a7Njbbojzh246bRGF4QphMbODlMVGiwsRmoORd+Il6azfYeqZwCJfu69uMWT /YSuCtdfvX3zW9+XC0pwCoRb8FOW+z6cGsiy3nUzytW9dH5rZKo0psjFif9SrYAeGMee Vvb7FDtgjypfzw6vZMAvzhsealGP0O4E6Qs9AS/HJqnGaJKH98T25aBDYQkfYbo28UBw 6tWYQiCpMx7/CLHRH/N2lgs0Iwn3YKecAMJYkkmfbTfy8sYXaXL9aexOzrN5fOvNVOBe NB9A== X-Gm-Message-State: AJIora+fdYchG+iMvS+fsfhra8v9L0eQlAMm+Jar13s4E5HQb6xbkgVQ EsSlCvHocr9FCPG5ya1K9tbIaaVBvQALIQ== X-Received: by 2002:a17:902:ea04:b0:16a:1f33:cb0d with SMTP id s4-20020a170902ea0400b0016a1f33cb0dmr12887257plg.103.1656545915267; Wed, 29 Jun 2022 16:38:35 -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 rm1-20020a17090b3ec100b001ed27d132c1sm127305pjb.2.2022.06.29.16.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jun 2022 16:38:34 -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" , Kees Cook , Sebastian Reichel Subject: [PATCH 7/9] platform/chrome: cros_typec_switch: Register mode switches Date: Wed, 29 Jun 2022 23:32:25 +0000 Message-Id: <20220629233314.3540377-8-pmalani@chromium.org> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog In-Reply-To: <20220629233314.3540377-1-pmalani@chromium.org> References: <20220629233314.3540377-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 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=ham 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 --- drivers/platform/chrome/cros_typec_switch.c | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/platform/chrome/cros_typec_switch.c b/drivers/platform/chrome/cros_typec_switch.c index a226f828514f..2ea42e6596b9 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) { @@ -164,9 +175,26 @@ 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); } } +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; +} + int cros_typec_register_retimer(struct cros_typec_port *port, struct fwnode_handle *fwnode) { struct typec_retimer_desc retimer_desc = { @@ -236,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.rc0.161.g10f37bed90-goog