From patchwork Mon Jun 25 08:08: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: 10485247 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 4EF686031B for ; Mon, 25 Jun 2018 08:26:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F6328863 for ; Mon, 25 Jun 2018 08:26:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E24F288E8; Mon, 25 Jun 2018 08:26:17 +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 9647428863 for ; Mon, 25 Jun 2018 08:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753245AbeFYI0O (ORCPT ); Mon, 25 Jun 2018 04:26:14 -0400 Received: from mail-db5eur01on0082.outbound.protection.outlook.com ([104.47.2.82]:12096 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753155AbeFYI0M (ORCPT ); Mon, 25 Jun 2018 04:26:12 -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=BuXOrIe/fWl0jkvi318nzle+SdUIjueJadV1BfNJJi4=; b=l5HRob0t6eoDrkNnDWl4ULfvREjpFGmF8MiyMqQdMFdZN8BpwrmOzlqtqOLIscNc5UjP7X25NRGiErDLDZ9kk48TIQgOFcwX7mewuEcMAtvPXHyBbJSCDOou6zf1+Nz1n+nATWY3LNA4+l63HH9+of62azGJewgE0W3ic28TtNI= 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 VI1PR0402MB3920.eurprd04.prod.outlook.com (2603:10a6:803:23::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.24; Mon, 25 Jun 2018 08:26:04 +0000 From: Li Jun To: robh+dt@kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, linux@roeck-us.net Cc: a.hajda@samsung.com, jun.li@nxp.com, cw00.choi@samsung.com, shufan_lee@richtek.com, peter.chen@nxp.com, devicetree@vger.kernel.org, linux-usb@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v7 05/14] usb: typec: add API to get typec basic port power and data config Date: Mon, 25 Jun 2018 16:08:37 +0800 Message-Id: <1529914126-22550-6-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529914126-22550-1-git-send-email-jun.li@nxp.com> References: <1529914126-22550-1-git-send-email-jun.li@nxp.com> MIME-Version: 1.0 X-Originating-IP: [92.121.68.129] X-ClientProxiedBy: HK0PR04CA0004.apcprd04.prod.outlook.com (2603:1096:203:36::16) To VI1PR0402MB3920.eurprd04.prod.outlook.com (2603:10a6:803:23::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c8630670-d0bd-41d9-f245-08d5da754d7d X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:VI1PR0402MB3920; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3920; 3:DNILBrtGPDCZX4i+Lkg3RrOvBxbgvl0SLcfBGe7bJJ2Yna+jFDrFihIrZQSRE1gScNcDJPnwxnZv7P4zvuBgThrkV8PJZNkIkT+ZWzQHOlD9obzi0AG8XY6oFahniqEodrzPzZAlSe9EhOD/K7DET/rCUy8quxGDkJaJz92CQJTO+5pbDYv/cjwp5BSq968981bggelbllG1+ZCLMpQ2LMkzQed1qVDBHtTG63S/1VUIfLbbVv4dOrpa9BemtXeE; 25:MQWQ6HzbXbHLA13m8CamDS9lY6+jN6HbYBnDSnAXohb7FVCK+wK6oySXnA1zRWEgMEVpYT/HNeps9qachbxPUnvAGaCD9GgKX9EX5OAxylcKS2HdU2MSF6jSDXac8WALRisLZYcF60G0Q0LEswaM4cNb5ZIV/1xVyngIo/6x72Xsvs7oCx2wZ3Q0hohzscSF6VMqczxW04wfA9Uyg4A1mNLj+7MZCIVfue6pJp4KjobKNjlqGeqXA8HqQz60auUicZAwttaXTFmI4pJxd9P7keWwaUXF589lR7GGid50k10aPN1hmSFqgPlkmXiErToSmb8KQLAM42PRMDsu2Gteig==; 31:SD2sjG52cg/kf3jUiS0ft9FAxRAiRmMS6N+tN3u5Qiq52NfBAPflpuU7t00/k6bSmvHEfdGNgf/rM5vNxhdtbj2mDuAlI9T632ENH53uMFQYevwDxdkTqmuRtI4GRm9m0/Yl6/ofwzwk0O+l+T+NWrTdGbrY0ATokM8td9DNWJZpHGPuwJbgr7yYAYd0EiZK/h80XpLAF/IplYVW2+2v7c3vs25hK6lfzfhKLJnmyrc= X-MS-TrafficTypeDiagnostic: VI1PR0402MB3920: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3920; 20:82+GK/05LwBfyR4gN51zPU3dcD14K6dOujl6UCGhjU9c/HS+j1+33auwyYki0iNYAERYHD8zseMTZMDM/adn1kDWFqkhmo8DQ3RLEn9kzDNtgEQmeTorYr6uBBrdbf6og6FiP8II2iMyTHPJxkgP7iPubgT3gNHe9JEASDXIP6YDoJOQWSND5R1pP39V9K39hwAZwfCi5oyzOBDeVRrReiXTtGSyCeDJQ/vX1F8TKwgdebMGWOp9i/UugQmXLh25osYrfof46qKALQA+Apr6JnMUdAiRO60SpIuiIyTH9qCvo1LC3o7sJ4U7Pj7xltpCXVVHw/Dzvtq26o7bqqCMckG0H35BPHKiT6Kk28BRMKzdiY2lSI35z8DENl0iq4B+vwIypkZ6VMWf1jGC3DuF/UXLpZxTT07o6EKSUoya1A+k4nHScZ/K1vy10ZhlnwzAz6gp08mCY9EHLTdLnvpecs5Vzn2Dxmeat5slfdLnpl5TlYsocvojmoit0l1BKEhP; 4:RckXNK9sNPsAE4bwXW6yTPLK5/0tmkrAoQhWImTbZZtLRHyceefe/8jGriHzRIeBYwAxTYw1Nm3WGeBfIqBEsBp19WTQvBWzh+/u+DyxHau/+Ismsl8yJe9NZStB3kxB3j0H0AO8DfzJjAOW1FFdykaiE/PHh5uM+jCXG0juXcrTUzIshOhaoH7GCQfxE+UvazGRJoqepPXwovo0z7+UXivckwGMazrj46L21Bky8ryjyTm3iQJ28HgPi+qWOBjv6WXwGVwklGLgEWpPJ/sxiPqjzflB3O+Hrz/uTOI1XGxHSv7IT7Izo86oh3R4KJiZ 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)(93006095)(93001095)(10201501046)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:VI1PR0402MB3920; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0402MB3920; X-Forefront-PRVS: 0714841678 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(346002)(39380400002)(39860400002)(396003)(376002)(199004)(189003)(53936002)(25786009)(47776003)(316002)(2906002)(16586007)(6486002)(36756003)(4326008)(386003)(6506007)(186003)(6512007)(478600001)(26005)(16526019)(97736004)(8936002)(86362001)(59450400001)(50226002)(52116002)(476003)(81166006)(81156014)(486006)(76176011)(305945005)(51416003)(8676002)(2616005)(6666003)(105586002)(68736007)(446003)(11346002)(66066001)(5660300001)(7736002)(50466002)(3846002)(106356001)(48376002)(6116002)(956004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3920; 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; VI1PR0402MB3920; 23:DdTYmlfBkyCqsJ+/nVoB6klc0PPEHDfxd+7PRrl?= =?us-ascii?Q?F/qSNGC67Uhk1FVAcX4y/igEdI9wfuL/d770a9nl9EFWw3Gxkw1/WYio01+d?= =?us-ascii?Q?K3N8tJwap1eTs06HZXHTdDl5fzQ/UrXwO9q/NWTXESIoFeFBw4YqeZ0zTppM?= =?us-ascii?Q?DICALUnQiyf3ikyxJm7kYJgCN02As82Q9WKbhKbslq2B7lXPOFjXV0viQ4mo?= =?us-ascii?Q?/B9g11ZwyHrLvdtWpOsDNPHaVp8+9D4QOyHksU/zqDQZq5gYcp7yfNsbXwvJ?= =?us-ascii?Q?z+CV2N8qey942bxrKyuan3/qXwcrUMJxsFgON3TT69K0IJS7Ic8PNrUaUybw?= =?us-ascii?Q?2KVdxQPSqe2IW8UEpsGvHJRr9WYUEhg/W9I8mjBYOsfErVEp/x+Xq/SgTS+Q?= =?us-ascii?Q?tL0L/j1xtjAD4xmIG5X8ELxU2KwoCsBf086FayuueoySOLFrU7Cq+6/9OcuZ?= =?us-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qijcSfBM33Sc1pYpKFUDePDozCdzTSNJmM4nfO/f0r5CZlJUqz+0nrYSR/SISCuRcIJH5ozjDns4P1AV0fuSyMHd3UK/YXIU7aj2VfV8H0vvn7n6jL0NKOIfXEla9JkZsyy2fO2Zwx0mKwGMVwlUDDNh8e2H6X/OwdVHSvle1RRH6kT7c4BYcBYvaBYgukY0jkrZM9deoaWH3mAl/DwsbBOI/yxU= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3920; 6:izuTqvV48JFvOyIUrGMTbu6vzUqwHYXWTSVYXoC/IxCq0zgYRzFI6JdG4FYew/kn0uBnJ6xx4qHuNqG/h9+BWsN9QsXFbG+kAIbtsvprm2QrLhzNymOcaIKfh/PqhJ1mEe5J/fcI4oUtnr8dVdKaS6H/xKZOts1o89LrfoaRLvu+DKz/O367hKG0ars7k/e2Gys9UtdXhJTrcTnn9d5+OJmUf+luqPcR7ndCXxIlcfol/fROGkfMbOJBlvL0FFL0tJ79apv8rMBoZ8tcw7m6s/buwu24asntc5AUHC2qEE1q6a0rT8jwXXT078rcmiw4pbqTCHiD/7bXdxP8+Ke72x+3KbHA0HgD1U4kwpZ0SspT05vY7K7ob0Yplqol0sA6y0sw1EDbI6UvxVoiHqRV2VywE+oDk8RUw8oGipXlGHCfai8/ltoZDNozTihBo416yfu9BM60WWWYL68W0moSGA==; 5:wFP/vHEDEiGSz7IpHLLUnpFEHHlUTZTIfgxyJyEDsHvFeHnxIyiY+2j7RH23+aVv2m8qOuvV78nWV8HmrXcIqEPpFbbvL9OOSevAbAaJ7x2v+gl52VxlS2oXF1+ojuwJlU6x14OWcjGeTbQufMLHa5MYK5c5rkZMHKLceue7/9U=; 24:BejL1B8Kyi4dEcaguvR8CSX1iknd1ExKPG8SNT4lRaKHOmf52J31AEwRmdbDTecnvClpNCrKla5sGegB6RBVeIqwX7YH1xlH+h3DC1zQ7wM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3920; 7:PLebEiWAyVwWUCAjF6GdE9Agyz/PDnCfQVH3ftMDylXsiBWFbEeG5oNmUuRzuQh5Y8gsnyCEjui/FeGsUIUooYnblXQ51WjUXwk7VH8JNZSLwhd6A47vKlc3cHQ0iHLnK6t5noMl2uTUSFywcPCEbhU9SLRWL12V2UXJ61IdhQnWOidti7NC41csvvkUj+GXUyaGqRsezxNDB+gIzcNz1O6y6YHxPkuFGIajHrVU4Wfa0J5To+fX4fAstAc52QDT X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2018 08:26:04.3296 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8630670-d0bd-41d9-f245-08d5da754d7d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3920 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 Reviewed-by: Heikki Krogerus --- drivers/usb/typec/class.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- include/linux/usb/typec.h | 3 +++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 53df10d..6331059 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -796,12 +796,18 @@ static const char * const typec_data_roles[] = { [TYPEC_HOST] = "host", }; -static const char * const typec_port_types[] = { +static const char * const typec_port_power_roles[] = { [TYPEC_PORT_SRC] = "source", [TYPEC_PORT_SNK] = "sink", [TYPEC_PORT_DRP] = "dual", }; +static const char * const typec_port_data_roles[] = { + [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]", @@ -932,7 +938,7 @@ static ssize_t power_role_store(struct device *dev, mutex_lock(&port->port_type_lock); if (port->port_type != TYPEC_PORT_DRP) { dev_dbg(dev, "port type fixed at \"%s\"", - typec_port_types[port->port_type]); + typec_port_power_roles[port->port_type]); ret = -EOPNOTSUPP; goto unlock_and_ret; } @@ -973,7 +979,7 @@ port_type_store(struct device *dev, struct device_attribute *attr, return -EOPNOTSUPP; } - ret = sysfs_match_string(typec_port_types, buf); + ret = sysfs_match_string(typec_port_power_roles, buf); if (ret < 0) return ret; @@ -1007,7 +1013,7 @@ port_type_show(struct device *dev, struct device_attribute *attr, return sprintf(buf, "%s\n", typec_port_types_drp[port->port_type]); - return sprintf(buf, "[%s]\n", typec_port_types[port->cap->type]); + return sprintf(buf, "[%s]\n", typec_port_power_roles[port->cap->type]); } static DEVICE_ATTR_RW(port_type); @@ -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_power_roles, + ARRAY_SIZE(typec_port_power_roles), name); +} +EXPORT_SYMBOL_GPL(typec_find_port_power_role); + +/** + * 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_power_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_port_data_roles, + ARRAY_SIZE(typec_port_data_roles), name); +} +EXPORT_SYMBOL_GPL(typec_find_port_data_role); + /* ------------------------------------------ */ /* 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 */