From patchwork Tue May 1 22:21:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mats Karrman X-Patchwork-Id: 10374571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9D33760234 for ; Tue, 1 May 2018 22:22:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8304128D75 for ; Tue, 1 May 2018 22:22:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81CEF28D80; Tue, 1 May 2018 22:22:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1363E28D75 for ; Tue, 1 May 2018 22:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751178AbeEAWVr (ORCPT ); Tue, 1 May 2018 18:21:47 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:45769 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751090AbeEAWVo (ORCPT ); Tue, 1 May 2018 18:21:44 -0400 Received: by mail-lf0-f68.google.com with SMTP id y14-v6so17705817lfy.12 for ; Tue, 01 May 2018 15:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CEmFUcP9QU2EpC1CznWMaRJMd5M4DqXyD5u0vQZ4DQk=; b=rXPvPUqzXNjvg+B2CT34QKWYekNimfmN75B/mFKO7om1ogiGzAQHTe3A9QCj44lVio CBp3tN0KMXg9TAGJ9eFu6bUluq4KiejqhmDLjfvSMbhrgmBvGhL0tr3ELEQY6p52env7 tyGqXLPqlniBXdXmBgaxFZdI0Ls4Wp67MXwWkZdpNvPwCztiAbqFNtcK41fjLe35zETW LxQh9lzRRCk+MTx3k74q8QkQ/Frcx30p4efNxTGrhPFFnpD/WV51Ia5STVeOdjCI6f0D Kb/qezdYhmkLprBaQTmx1tG1I2dcFoFY48y2NWR9xlz8fbcSuB73qErBPWKE/yPxLl+4 KKfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CEmFUcP9QU2EpC1CznWMaRJMd5M4DqXyD5u0vQZ4DQk=; b=drkaPQNJ/TtdQgn0/2cnIvbE/XXShyeeaosurOh1adGZWL9hGyYNmYxkn1bTPaDRFz VudxPl1m9VNXpelM/gYyYE0T41uEXLTymI6y+Zff6FJK7aTJM65Gi14fplZu6vWajTpi sK3n2RMgRphJkcSu59eMOChV4UYDU3rDzNTS2Sq6BIGBeWWoprUh7g6c+UIVRlH/jUlD UZYTxnt4cTbVBrUevzImuh8Ny5NaEem5BHzHuYBsYLbfmbUnNhAHMhBA6XaIkSy8tKC3 NdWaW1yn6E0GmK/1Dn7pGGhg6rAZnH3mFBkgIvdvoYkRSSlqFv1rMibqbmO6JeeSZRz3 qMMQ== X-Gm-Message-State: ALQs6tDquBeMYUiNueBi4ZgLcDkb8fhaUyMyH/Tq2bdAUJ5TKbDyrRSr 6nKHgXAwh+cJYyu34svbZ9M= X-Google-Smtp-Source: AB8JxZo+YWqdwLy3mHjMmKwPrxItXIg4xeNP4SnIAygi8TnO1SbfGpng1vfzmdCoQMFdfOHyVqV5oQ== X-Received: by 2002:a19:b54a:: with SMTP id e71-v6mr10046410lff.94.1525213303250; Tue, 01 May 2018 15:21:43 -0700 (PDT) Received: from matsnb.lan ([195.84.96.49]) by smtp.gmail.com with ESMTPSA id j85-v6sm2196840lfh.5.2018.05.01.15.21.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 May 2018 15:21:42 -0700 (PDT) From: Mats Karrman To: Heikki Krogerus , Hans de Goede , Guenter Roeck , Greg Kroah-Hartman Cc: Rob Herring , linux-usb@vger.kernel.org Subject: [RFC PATCH 7/7] usb: typec: mux: Allow default mux mode to be specified Date: Wed, 2 May 2018 00:21:13 +0200 Message-Id: <1525213273-6103-8-git-send-email-mats.dev.list@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525213273-6103-1-git-send-email-mats.dev.list@gmail.com> References: <1525213273-6103-1-git-send-email-mats.dev.list@gmail.com> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows the default mux mode to be specified using a firmware property. Signed-off-by: Mats Karrman --- drivers/usb/typec/mux/pi3usb30532.c | 18 ++++++++++++++++++ drivers/usb/typec/tcpm.c | 2 +- include/linux/usb/typec.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/mux/pi3usb30532.c b/drivers/usb/typec/mux/pi3usb30532.c index 3e564e6..d1de12c 100644 --- a/drivers/usb/typec/mux/pi3usb30532.c +++ b/drivers/usb/typec/mux/pi3usb30532.c @@ -26,6 +26,7 @@ struct pi3usb30532 { struct mutex lock; /* protects the cached conf register */ struct typec_switch sw; struct typec_mux mux; + enum typec_mux_mode default_mux_mode; /* Mode for TYPEC_MUX_DEFAULT */ u8 mode_support; /* Modes supported by hardware as bit flags */ u8 conf; }; @@ -84,6 +85,9 @@ static int pi3usb30532_mux_set(struct typec_mux *mux, enum typec_mux_mode mode) mutex_lock(&pi->lock); new_conf = pi->conf; + if (mode == TYPEC_MUX_DEFAULT) + mode = pi->default_mux_mode; + switch (mode) { default: case TYPEC_MUX_NONE: @@ -116,6 +120,7 @@ static int pi3usb30532_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct pi3usb30532 *pi; + const char *mode_str; int ret; pi = devm_kzalloc(dev, sizeof(*pi), GFP_KERNEL); @@ -129,6 +134,19 @@ static int pi3usb30532_probe(struct i2c_client *client) pi->mux.set = pi3usb30532_mux_set; mutex_init(&pi->lock); + if (!device_property_present(dev, "default-mux-mode")) { + pi->default_mux_mode = TYPEC_MUX_2CH_USBSS; + } else { + ret = device_property_read_string(dev, "default-mux-mode", + &mode_str); + if (ret) + return ret; + ret = typec_find_mux_mode(mode_str); + if (ret < 0) + return ret; + pi->default_mux_mode = ret; + } + if (device_property_present(dev, "have-2ch-usbss")) pi->mode_support |= 0x1 << TYPEC_MUX_2CH_USBSS; if (device_property_present(dev, "have-4ch-am")) diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index aaf6d57..8a9dc1a 100644 --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -790,7 +790,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached, else usb_role = USB_ROLE_DEVICE; - ret = tcpm_mux_set(port, TYPEC_MUX_2CH_USBSS, usb_role, orientation); + ret = tcpm_mux_set(port, TYPEC_MUX_DEFAULT, usb_role, orientation); if (ret < 0) return ret; diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 72cd4a7..85df816 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -74,6 +74,7 @@ enum typec_orientation { enum typec_mux_mode { TYPEC_MUX_NONE, /* Open switch */ + TYPEC_MUX_DEFAULT, /* Initial mode after connect */ TYPEC_MUX_2CH_USBSS, /* 2ch USB SS */ TYPEC_MUX_4CH_AM, /* 4ch Alt Mode */ TYPEC_MUX_2CH_USBSS_2CH_AM, /* 2ch USB SS + 2ch Alt Mode */