From patchwork Tue May 1 22:21:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mats Karrman X-Patchwork-Id: 10374567 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 65EBF60234 for ; Tue, 1 May 2018 22:22:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49A1928DC3 for ; Tue, 1 May 2018 22:22:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36DD628DBB; Tue, 1 May 2018 22:22:11 +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 3014A28DC3 for ; Tue, 1 May 2018 22:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751174AbeEAWVt (ORCPT ); Tue, 1 May 2018 18:21:49 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:42759 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751080AbeEAWVk (ORCPT ); Tue, 1 May 2018 18:21:40 -0400 Received: by mail-lf0-f66.google.com with SMTP id u21-v6so18072727lfu.9 for ; Tue, 01 May 2018 15:21:40 -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=e4xdTlmntZmdg8qBtrXO0SL68KOctnmDU+f73fTjfcw=; b=JXhrXNH03j5JU+K6L4A7KtrXsJe1JVJoqr2PCVBnaO3wcrcbqw206WjWGqLwJ1Z6se D1jVra+ErdnvBNoURdLIzvmV9QoTGGgc8Vz56bC32N+BZ4w81LycdiZ/oKIF+3wR3C8W H+qKMkj/d/pGvAC003ww040yo9bIs/jilbyPSrVQ11/d6MDkv/S6mmOOMHrgXfzlvVaw S7thtyP9GxdMhLGcVnAZR6cIDcW7+Tc9SVW5/+FTO173BXmT41uoW3c3/MGjTzwdxO/S GqHOyxKgdCX+KMBJ5x7SAZgkEP79Q3tYTg1MqcoIAw2Cko7FV7d6WhKr/apMIoCYgJRL e3Tw== 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=e4xdTlmntZmdg8qBtrXO0SL68KOctnmDU+f73fTjfcw=; b=mhG9oXqtEZ/m3ICD/Z4gUcam4uk/bx/n7fsqRuajnG/gPzAGeZUq8nPs86EYETd7xb s5oFtszDEvttltNAYxrZzImj1yLEJbxXPTBg4wsutHE/nV1rpdmDUFCTacb6jKLM3IfV /oMSh4JBH5RQSkAkNGm9ECzzAiWcUPtP5K+pzY/1ldgA+qi/3oNPEtaENRhIqwuqE0lv QyHTtt0BcpeIWe+JEPcGZExrzD6EdNfYa7sK6nNAJLGoCG3kLlStdAADswF4oOBntIeM JEdU4Ii+SDD3CfWJU5DQb0ZtIz07284h75aebd3kWE8y26HHcn6q7j21LkLLg+piRNfQ GgDg== X-Gm-Message-State: ALQs6tDViN2jZraUekCY67FRP0PjKcIzLM7+BH0N+6l2uIptLNNZ8XRy beVW5pYvDY2ka0svA0LoSq8= X-Google-Smtp-Source: AB8JxZqPkfATkp0bOXHBqdhFe7D1smo7cxg+hP2Mb0uEpjAG7zNSOgVwZxsJIvMoRA1JjcRWmNIKWg== X-Received: by 2002:a2e:2402:: with SMTP id k2-v6mr12374189ljk.20.1525213299377; Tue, 01 May 2018 15:21:39 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 May 2018 15:21:38 -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 3/7] usb: typec: Add API to find mux mode from its string representation Date: Wed, 2 May 2018 00:21:09 +0200 Message-Id: <1525213273-6103-4-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 Signed-off-by: Mats Karrman --- drivers/usb/typec/class.c | 22 ++++++++++++++++++++++ include/linux/usb/typec.h | 1 + 2 files changed, 23 insertions(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 53df10d..c5432f4 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1255,6 +1255,28 @@ EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); /* ------------------------------------------ */ /* API for Multiplexer/DeMultiplexer Switches */ +static const char * const typec_mux_modes[] = { + [TYPEC_MUX_NONE] = "none", + [TYPEC_MUX_2CH_USBSS] = "2ch-usbss", + [TYPEC_MUX_4CH_AM] = "4ch-am", + [TYPEC_MUX_2CH_USBSS_2CH_AM] = "2ch-usbss-2ch-am", + [TYPEC_MUX_4CH_USBSS] = "4ch-usbss", + [TYPEC_MUX_2CH_USBSS_2CH_AM_B] = "2ch-usbss-2ch-am-b", +}; + +/** + * typec_find_mux_mode - Get the typec mux mode from its string representation + * @name: mux mode string + * + * Returns typec_mux_mode if success, otherwise negative error code. + */ +int typec_find_mux_mode(const char *name) +{ + return match_string(typec_mux_modes, ARRAY_SIZE(typec_mux_modes), + name); +} +EXPORT_SYMBOL_GPL(typec_find_mux_mode); + /** * typec_set_orientation - Set USB Type-C cable plug orientation * @port: USB Type-C Port diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index d356577..72cd4a7 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -274,6 +274,7 @@ void typec_set_pwr_role(struct typec_port *port, enum typec_role role); void typec_set_vconn_role(struct typec_port *port, enum typec_role role); void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode); +int typec_find_mux_mode(const char *name); int typec_set_orientation(struct typec_port *port, enum typec_orientation orientation); int typec_set_mode(struct typec_port *port, int mode);