From patchwork Mon May 28 02:52:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 10429713 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 4FDF760362 for ; Mon, 28 May 2018 03:09:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 408CC28AF4 for ; Mon, 28 May 2018 03:09:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3530F28AF7; Mon, 28 May 2018 03:09:54 +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_SIGNED, 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 AC7C828AF4 for ; Mon, 28 May 2018 03:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753145AbeE1DJl (ORCPT ); Sun, 27 May 2018 23:09:41 -0400 Received: from mail-eopbgr00046.outbound.protection.outlook.com ([40.107.0.46]:14834 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753137AbeE1DJk (ORCPT ); Sun, 27 May 2018 23:09:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y6e0hAOe59Zq8HOYmQIiGG6qc6pevgfoTvx1qhZj9IU=; b=WL9L3FrTcv0hbjckPa4SMN44BZlaSvni2d/3ySvHrKaA8wCMJC8nN+qCxrldhIFjdJlAnS/I2Q13LkVTtdcPp55/6puyfSswuF+Ysn6Md20xeKsvPkRGIYb5VUjzdXOdxUmuyTnQzl4fb0IAnGXvuhAQrBrZ9TsqEPIUpgcx6UY= Received: from b47624-OptiPlex-7040.ap.freescale.net (92.121.68.129) by VI1PR0402MB3919.eurprd04.prod.outlook.com (2603:10a6:803:22::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Mon, 28 May 2018 03:09:32 +0000 From: Li Jun To: robh+dt@kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, linux@roeck-us.net Cc: cw00.choi@samsung.com, a.hajda@samsung.com, shufan_lee@richtek.com, peter.chen@nxp.com, garsilva@embeddedor.com, gsomlo@gmail.com, jun.li@nxp.com, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v6 05/15] usb: typec: add API to get typec basic port power and data config Date: Mon, 28 May 2018 10:52:37 +0800 Message-Id: <1527475967-15201-6-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527475967-15201-1-git-send-email-jun.li@nxp.com> References: <1527475967-15201-1-git-send-email-jun.li@nxp.com> MIME-Version: 1.0 X-Originating-IP: [92.121.68.129] X-ClientProxiedBy: HK2PR0302CA0015.apcprd03.prod.outlook.com (2603:1096:202::25) To VI1PR0402MB3919.eurprd04.prod.outlook.com (2603:10a6:803:22::32) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0402MB3919; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3919; 3:jpKGhLx26P3xdMurf+gxGrec0Onxt9BBfBJI9PNfWOeft6iGgYtlXPTyQWimF5XsG2D1kue0ueDyxwJDdtqdZcv78XrCPh09LNGrFEYA3WvJwPq0JV7JlS8ZwFg7RhU6KqcDWYdEmGzwWpjHWuGgN4jgQ5leEgPYypx2AafH2tQStKd3hvTisidHaJUTQkJZDWICS3h7ncN2OzjXzXh7k+IAUzG5STU3oI36Ycyo4Y+oJCXxE6Quorj9/XpdaPUx; 25:YNLDCWszf/LFwjpWA0wtafg09COHGGeNjBKdFlhWwIUGAz+0OsGys7eep0PN86ICFliXN71K/B8LcrjnVu0uhfwSUozTNQ/TiGLuI2m+e+fBjeC/xIy0TVCjODDYFa5aw6qjbMTPOZSUiXUovNbBwfRndsrJa4gJF/U9Ged2aKmKaHkU4ik/oytYKMoIxzOpl42YQbFjRVXdhSwm5GFXfRdort2AGnacAfQZh90YpErOF4w3bAfehavq7dgVCwCz8klAhz/O+QQGXNltqlx0ilNee4d0vd5ygmee3Opb4J4mZN+OuGcHcyg5hQ3UhtGeBoqzsMCoVIPFC1zhTWDxoA==; 31:LzpdqJZgDlaX3bFrtFk6KRBvywv+xqRmZmJuMZQp4XJsMiW+T1GxozlIyHmLb7ONyZT19kbbeieeipOzYralzQ6dNVyn35yOe2SceQw1oDnEk/wfkPbW0xjTkq7rNoxYoF4Vt2yY6YeCHWL3cZc2x3EzlILnbTWDQvDPZWu2k1YbWnIsMX2CJz/nhccujv/pLMCG/tsEt5pFemxah/ugnUtpH3XNlPHrhJx7PaOtHFE= X-MS-TrafficTypeDiagnostic: VI1PR0402MB3919: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jun.li@nxp.com; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3919; 20:NdQ+F5YnHTRH56+AC4iYY4vnFFC25yVd3iDh0DyMhlUe9DfjQG/UXKXcQUix1rDLcjQx+hFwI7xsp5slTcCqui65ywM8jNl8JiGkV95mejXbCY7ClznyPc0ainPFo2iCkdiAmUQm0Av6rlLyNg29RUErXATe3UO7FmJfxT84PSH4rmZlxynBhMKXAVa9W0+xL0CovQ/BtXdWxjTFkLmwKQQN8C/rP3JNCmPkL8552OHNTi9phYot3ZMXbhqhyjN4kOXwA0kRc+6e1VKhozuyP/l4qBPqePx+2H2roqLx1cK3FC1bjG7QJw76D9JxvywyN6Biv+7eNxTvF0y4lwpg9Wd0sp8wZA3mBsqrfWTHElJaIpFVIw7gtUOSyT1YDcra/VlzmX5ernDvPDDBM5t8WrIZFBHLszTL/hccq0UnTwtX7KitX5lNs7LMOBXk6lRX3IreMZYjvNoSXBFljK13d3iD3kOW+iCZyWV2q2RcmtDiTAiaz7lv94CaL5qKL1rD; 4:SWuWw+tdPVJqKXMFY9oQ6ctoo3D5aNUv0lecegsHoWJGKbdq4UMCtJdY9+BWoBhqJEZ+awaGdHpeqni2rSWFaD2H/t42Aw75M7dKPOFirysGwDwsrDS6dvbl2z7Z+unOXuiSxzs6zIQl1tMNEXyDQwpuxIRbv+fiXTnMzHCAvWdMprOcvVmOY+0n7+y7o+NnocKjVVdf//GgVimKsdNpQfprUlDfUXrrFW2BlbMvhs97uoxl8ohMkBBQtiwHK+zLFFI9kphc0Fd78jvICheVtHTFIfZ/+MkCa5p0wgJ3DAtjAFZjH9mxhE9RXxpMVq02 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(10201501046)(93006095)(93001095)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:VI1PR0402MB3919; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0402MB3919; X-Forefront-PRVS: 06860EDC7B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(396003)(39860400002)(366004)(346002)(376002)(199004)(189003)(6506007)(8676002)(16526019)(305945005)(26005)(7736002)(386003)(486006)(446003)(48376002)(11346002)(956004)(2616005)(2906002)(66066001)(81156014)(186003)(3846002)(81166006)(478600001)(8936002)(50466002)(6486002)(5660300001)(6116002)(7416002)(36756003)(50226002)(47776003)(39060400002)(476003)(86362001)(106356001)(68736007)(53936002)(51416003)(105586002)(16586007)(316002)(4326008)(6512007)(76176011)(97736004)(25786009)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3919; H:b47624-OptiPlex-7040.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0402MB3919; 23:Wdoqmh0vItHqflbVkd5zPJlwLZh63N881qVlETl?= =?us-ascii?Q?MtpC7+96skphy5MEG97ku78H15B+fI5zKEyWbmBspwLSoi3foOoSPBykTpnt?= =?us-ascii?Q?omDDfZ31gJYqmW0oUo1neaaboTg7P985wCFF7QLt/7bDMOsoEiLz1hJUQwzZ?= =?us-ascii?Q?jciefz3zko4n9LIq/Lvi7IVeXlCIcMFVlD2Syw2URDY2ccDjWg2DaXUBD7ES?= =?us-ascii?Q?q95UOyxOuCXjv6rM0mNRI7BB/qMiqynjwtKvENOppobdZGSvk3HUyzQXKLLj?= =?us-ascii?Q?BmqYp6nfY9dpD2/Vvo7OiMCUghAuzBMRK06SUcubws8Ru5ggFJORiVbBtQnK?= =?us-ascii?Q?sHvTKv1wRhX6YTkY2upWw0/EORrEJmQMcIin3v/7V7wZB0hLoy5vBRnvs2Px?= =?us-ascii?Q?5nVs+6axm1JJbnI2LDuZIDhqef1w9I22gbuLvVYQoNrXvvvk02kZKaERhadK?= =?us-ascii?Q?9tgyw6++yivmTctU9EIKhy1j3iJh3+OBnx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uzqQhUnPPz5FPl3bjKPD67mh11r4xDEOAFzY/6uModP3gdOfxMuz1kbU/d5ZKMxc2VxNL2 X-MS-Office365-Filtering-Correlation-Id: 526a3116-f2db-4e61-8d68-08d5c4487244 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2018 03:09:32.2358 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 526a3116-f2db-4e61-8d68-08d5c4487244 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3919 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 adds 3 APIs to get the typec port power and data type, and preferred power role by its name string. Signed-off-by: Li Jun --- drivers/usb/typec/class.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 3 +++ 2 files changed, 53 insertions(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 53df10d..4c7d18c 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -802,6 +802,12 @@ static const char * const typec_port_types[] = { [TYPEC_PORT_DRP] = "dual", }; +static const char * const typec_data_caps[] = { + [TYPEC_PORT_DFP] = "host", + [TYPEC_PORT_UFP] = "device", + [TYPEC_PORT_DRD] = "dual", +}; + static const char * const typec_port_types_drp[] = { [TYPEC_PORT_SRC] = "dual [source] sink", [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1258,50 @@ void typec_set_pwr_opmode(struct typec_port *port, } EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); +/** + * typec_find_port_power_role - Get the typec port power capability + * @name: port power capability string + * + * This routine is used to find the typec_port_type by its string name. + * + * Returns typec_port_type if success, otherwise negative error code. + */ +int typec_find_port_power_role(const char *name) +{ + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), + name); +} +EXPORT_SYMBOL_GPL(typec_find_power_type); + +/** + * typec_find_power_role - Find the typec one specific power role + * @name: power role string + * + * This routine is used to find the typec_role by its string name. + * + * Returns typec_role if success, otherwise negative error code. + */ +int typec_find_power_role(const char *name) +{ + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); +} +EXPORT_SYMBOL_GPL(typec_find_preferred_role); + +/** + * typec_find_port_data_role - Get the typec port data capability + * @name: port data capability string + * + * This routine is used to find the typec_port_data by its string name. + * + * Returns typec_port_data if success, otherwise negative error code. + */ +int typec_find_port_data_role(const char *name) +{ + return match_string(typec_data_caps, ARRAY_SIZE(typec_data_caps), + name); +} +EXPORT_SYMBOL_GPL(typec_find_data_type); + /* ------------------------------------------ */ /* API for Multiplexer/DeMultiplexer Switches */ diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 672b39b..15f8d9a 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -267,4 +267,7 @@ int typec_set_orientation(struct typec_port *port, enum typec_orientation orientation); int typec_set_mode(struct typec_port *port, int mode); +int typec_find_port_power_role(const char *name); +int typec_find_power_role(const char *name); +int typec_find_port_data_role(const char *name); #endif /* __LINUX_USB_TYPEC_H */