From patchwork Thu May 3 00:24:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 10376831 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 534B76038F for ; Thu, 3 May 2018 00:41:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43F9029150 for ; Thu, 3 May 2018 00:41:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 385E629153; Thu, 3 May 2018 00:41:46 +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 9D9F929137 for ; Thu, 3 May 2018 00:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751861AbeECAln (ORCPT ); Wed, 2 May 2018 20:41:43 -0400 Received: from mail-eopbgr10043.outbound.protection.outlook.com ([40.107.1.43]:21952 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751747AbeECAlm (ORCPT ); Wed, 2 May 2018 20:41:42 -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; bh=boRwak1L4XQ3126CyIGoRzkyqfwRRJT+9OC9up5IN3I=; b=dPex5tg3uTjM8p6aU4uICUYyNcThn+VYrbqpy3rPu9bH6rK3xmAKgcchJ8Cu0Wck6ceYnVp77L/IEV2I8dvUhNWN9By2lSP1DO3YY6Z3I06+/jLr6T6eGlPQAdhAcg6FZ6+KHchkVFGbS2Hwb0WPTvzPYkcVGz5TMbW1xT/E3OU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jun.li@nxp.com; Received: from b47624-OptiPlex-7040.ap.freescale.net (92.121.68.129) by DB3PR0402MB3914.eurprd04.prod.outlook.com (2603:10a6:8:f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.715.24; Thu, 3 May 2018 00:41:31 +0000 From: Li Jun To: robh+dt@kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, linux@roeck-us.net Cc: jun.li@nxp.com, a.hajda@samsung.com, cw00.choi@samsung.com, shufan_lee@richtek.com, peter.chen@nxp.com, gsomlo@gmail.com, devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v5 05/14] usb: typec: add API to get typec basic port power and data config Date: Thu, 3 May 2018 08:24:45 +0800 Message-Id: <1525307094-27402-6-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525307094-27402-1-git-send-email-jun.li@nxp.com> References: <1525307094-27402-1-git-send-email-jun.li@nxp.com> MIME-Version: 1.0 X-Originating-IP: [92.121.68.129] X-ClientProxiedBy: OSAPR01CA0012.jpnprd01.prod.outlook.com (2603:1096:603:2a::24) To DB3PR0402MB3914.eurprd04.prod.outlook.com (2603:10a6:8:f::29) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB3PR0402MB3914; X-Microsoft-Exchange-Diagnostics: 1; DB3PR0402M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43lSaAgsannE8n4BTVZoZIIDnpRs1/44vIeuSM1LDL+315rriceTb+0fVlkmBMEcAq6lJit8Ukw/2TnmoKToVhFLq4xhSIGmx61aeYPwfwK9WMHyMEGJkQhZXE5VxTDgt4IFENUdsjCKdfvkOEkXU3GaKFDy2ybZ9wROLZXg1Cin6B7+Dlg4ONxCQN+YohzHsWEBsc56J2DHmNAjYzSEM/7TZaUrt87rUYDP0XffjGA73czg/Nm+XK65yiad1rRso02Z1cRRl24mm4aR78o2LONyFj2cHrwc4pKtPYtxbIVH4B3vmcs5o4IR+JkmdOCgWnYLQ4MIOhM0UJ/2dsPqZ+uOxEkw9m8bXxOzh6UIgP; 4:caGrY9+urGajY2WQVYds5g3JxKexzXJEYW31QmU1XLuUZtShOt4e2jd6JMEYWuVUvRoKJa7TfR3xkpPtYuT8qqkyL64GQiAys+9PYlsPAK06H8nJ0BZnCaF2u29S5DSCBdaUikor8UGGKGp+mH70SAMDoURWpC6jAe2sCn4fV0uVTj7IPYK1NIZSHp71kxZltNaYWIvIFchOk5ydTnqvV8wC3LxBXD022FHJVXyUl0SbP+qCRGpa2f3JgSx0K9/9VOnFQ4IaofYEMM2VCWd6O/2wT80eg04J5ZS5MIgTFyGhoxVlP3wI7L1Xk+b9L100 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(3231254)(944501410)(52105095)(6055026)(6041310)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011); SRVR:DB3PR0402MB3914; BCL:0; PCL:0; RULEID:; SRVR:DB3PR0402MB3914; X-Forefront-PRVS: 066153096A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39380400002)(376002)(39860400002)(346002)(366004)(189003)(199004)(7416002)(47776003)(7736002)(8936002)(66066001)(305945005)(106356001)(2906002)(5660300001)(6486002)(105586002)(6116002)(3846002)(6666003)(81166006)(8676002)(50226002)(68736007)(81156014)(36756003)(956004)(2616005)(386003)(16586007)(476003)(50466002)(6506007)(6512007)(97736004)(316002)(446003)(39060400002)(52116002)(26005)(76176011)(48376002)(4326008)(11346002)(486006)(16526019)(86362001)(51416003)(53936002)(186003)(478600001)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0402MB3914; H:b47624-OptiPlex-7040.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB3PR0402MB3914; 23:qn32hTMnoypumWCu3F01zC3tz9cUVMJ8HXoYWBi?= =?us-ascii?Q?+2sb2BcEQ8NsFJhL01otXBD+0xQvyIh6JtuCUWwnIrzWHarOY5wieYGt7WGr?= =?us-ascii?Q?csQlbRni1Q2M2w8rq6638k++S1rQE+iyVKeBNkP0rSUv0XevIsZEYhjUnKld?= =?us-ascii?Q?EPguGP1uRPVhIpxFo/tBn7EfjKT4WTuJee4HhTRTjfOd6I2IaoYmFQ5kPfNQ?= =?us-ascii?Q?l2/UbLHTOPnpTjSHvvA89TVNO/+6KaDBzgBZOxr0UVFDgKUAj7gX+b59TB7c?= =?us-ascii?Q?t0bAyw9fBFZtY718DSn4xQLfgzQFNqrWt+wnJIE1OHuF80SeEkMPMLGBV5mI?= =?us-ascii?Q?5uCvJOlzCyg0WhtIvV1ootANR5aioEQfkqt34EBhraPTOfLlWpF3b65kff9O?= =?us-ascii?Q?Y6/0Au2/B0bTNN0Jjcho9/sBf6fKVx61/3XqAKWo+ICagck8U8/S4LUhMaB2?= =?us-ascii?Q?Jk83sePi8ouLFKAG8hg1ZoqUoBXs3D4svN0OvuemjTPHpr9upkZSRQHIsFd1?= =?us-ascii?Q?XBg4yfoRwM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-Diagnostics: 1; DB3PR0402MB3914; 6:lH+qpABZ/Pgc/o5EK59tNtA3Zjhaozq8d0+y3qr1YS9PO+EjgeTypM7C7A5FqOTJtoIzoVqvuF7OWh3pONnucpv2MYb03fek4HziqHGvFoag+yp+2ovRQ91tvDzi+ZBFilxTMkSL1Rf+BdZ9nLeUT1Z2eh4IBZNmwdCVOUxHvO0FkJL9klJ/qAvl0z0fAbENHj+/m7YN83O6FNvCEhxKJYIcEBgjh8aBhPAEKudHzuYfAbi17j0K/f+mKTSvKA6T/ROWNXaramOIs8DXJphHFyAnwKGXhs1aa6arvOQjgT1dAlnzygsr0EUuKoP3v3TVNsuZnanQ/4khYjwHN6tTBBzplltzOr80k5F4ZmlpApibTT89lCCSNzf9Nxh/SHFy63Uoq8oo2o+kmXCRdrJk2yjVKKVUWIKs6p+he69vA9ydcgspBt8f2FQZwSs+pJptHsHSdTeix2k6ADvOMWneDw==; 5:BPYy319ajwY0Ey/C1FzE4VVkL39i7Se8i2zoSMnM19JCk/E+vX+9Sushg1W8k2TleDzo03QL7acd7M1AXNyp1LL+33c85Pl0ib2I8f/GS3auA88TwDad0ZzN3ucdXaZqnQrXa36UtcQM87W4az5WIki+IpcXb3GJgJQsSMAmnqw=; 24:dUfTzoyi/IBcghgjARIfv19aV7Jwnhzxt3Ay1UfUgIZSLe06OWbTkONA2GDygri+VIGwVAQfZzK2q4GWUCNvowWnDWn4SfS7gcyAL747A60= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB3PR0402MB3914; 7:K53mRfmaJVpSsc8Q+NmF4JbdFehDv1JOfKl4t4fFj/BgC9HLuryeuGwI3Q7/3t5cgZ5ryUN34e9riI5jYqvbdYRg3fPNFxMgFV9CybZDuOf8qNI1d2AqZyg/OAV/SHhPd4HRxEE3u9R9ovATPnNt+E+VisN9Bxpzb8FKt4HflimdNWUHoabQNk9X6KE8+heDmbNIq5P+LVhoRFBdwaMNJVPwyOuKZlyQVNE5qgC7ZqPe6nAkk8x4e0AXdV4ZIVV8 X-MS-Office365-Filtering-Correlation-Id: 6a6e1608-ebf9-4014-a035-08d5b08ea09a X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2018 00:41:31.3343 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a6e1608-ebf9-4014-a035-08d5b08ea09a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3914 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 | 52 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 3 +++ 2 files changed, 55 insertions(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 53df10d..5981e18 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { [TYPEC_PORT_DRP] = "dual", }; +static const char * const typec_data_types[] = { + [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 +1259,51 @@ void typec_set_pwr_opmode(struct typec_port *port, } EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); +/** + * typec_find_power_type - Get the typec port power type + * @name: port type 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_power_type(const char *name) +{ + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), + name); +} +EXPORT_SYMBOL_GPL(typec_find_power_type); + +/** + * typec_find_preferred_role - Find the typec drp port preferred power role + * @name: power role string + * + * This routine is used to find the typec_role by its string name of + * preferred power role(Try.SRC or Try.SNK). + * + * Returns typec_role if success, otherwise negative error code. + */ +int typec_find_preferred_role(const char *name) +{ + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); +} +EXPORT_SYMBOL_GPL(typec_find_preferred_role); + +/** + * typec_find_data_type - Get the typec port data capability + * @name: data type 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_data_type(const char *name) +{ + return match_string(typec_data_types, ARRAY_SIZE(typec_data_types), + 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..00c93e7 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_power_type(const char *name); +int typec_find_preferred_role(const char *name); +int typec_find_data_type(const char *name); #endif /* __LINUX_USB_TYPEC_H */