From patchwork Tue Jun 26 23:45:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 10490333 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 4A00B60386 for ; Wed, 27 Jun 2018 00:02:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DDD21FF13 for ; Wed, 27 Jun 2018 00:02:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30A7C26E54; Wed, 27 Jun 2018 00:02:56 +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 958EE1FF13 for ; Wed, 27 Jun 2018 00:02:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932242AbeF0ACx (ORCPT ); Tue, 26 Jun 2018 20:02:53 -0400 Received: from mail-eopbgr00049.outbound.protection.outlook.com ([40.107.0.49]:56225 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932104AbeF0ACv (ORCPT ); Tue, 26 Jun 2018 20:02:51 -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=d8x7DyrVEUfmOOfAtTP/Eul3LIHK04k2e/mKyQMjvfk=; b=G5m7E0fAJYeAfdy86sX9DjmLx1Ss/MWjRh+fscPy0YT7HHKZd18RaYJAuyIMsoMHINeP4HsBt5tdHwBs/xued0dBjZH1pDOPZT0x4sGsWzyeZAxH6QmCTuW6lKD6K0ZCmwJxqf6vdTMhgKCakUyzOP0Azs/0DOGgakrowVGY8pY= 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 AM0PR0402MB3908.eurprd04.prod.outlook.com (2603:10a6:208:f::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.22; Wed, 27 Jun 2018 00:02:45 +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 v8 05/14] usb: typec: add API to get typec basic port power and data config Date: Wed, 27 Jun 2018 07:45:23 +0800 Message-Id: <1530056732-9640-6-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530056732-9640-1-git-send-email-jun.li@nxp.com> References: <1530056732-9640-1-git-send-email-jun.li@nxp.com> MIME-Version: 1.0 X-Originating-IP: [92.121.68.129] X-ClientProxiedBy: HK0P153CA0011.APCP153.PROD.OUTLOOK.COM (2603:1096:203:18::23) To AM0PR0402MB3908.eurprd04.prod.outlook.com (2603:10a6:208:f::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b3c9c288-4fe5-445a-83f7-08d5dbc15250 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:AM0PR0402MB3908; X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3908; 3:KhdzsRML8B1dTyqm8ZuF93UwknsjIuu6WbWWltk3/BJqAjzXkNGyeIJGAw7cvaoYJMCZfOgD1bILUXBkRySyQV+kln0IhMLxltbGjMmG+owpIoq8xoebvf+2kaETGKeozFPYXeHMOytXt+cwmVBT30FCHjy8Y/wQhD4gHrTfwRRg+D/0DN+42NYiOLWwfc6nv5TZpKzbDJSbNTXjYdOlf5US706+ZXLfXHuV214Zy8MGX0xG9YLJYKHawIi9MZtY; 25:V0U4JQ7EK3H2BNFoC43RV02fu5fr1D868ftZPIXXjWOTdvJaXBPccIxbUdqZFUdD2ritY14pRfne40n2sIpm4ns61JbiBzdQBsD2ZO4m7JbpWXqITfklLB9fS5lzKzBVesshAL8Z2kj3veYH3Ou96SXgLU9VYVE9YoTjAnxdq98R9izXFSrVE791xUhPtO02EziWBTAwEjvH2Va5s5DXpQbtvtybTIHkQ6Nfr/d4GtuGYQ0IuYEePB4YBe+BeLOEVYaHbm5CLYaKkjFhrhfv7xHgB/s/l8IdzUkTz7cgR8Wie79LEvRaCA5qVL9hlpb3Ea0xw/7w49LasbNoM+QulQ==; 31:XVMnJkKLRVeTWgVgyh6mMvJL7PcYSyAKt8d6GjIDCusGISvtUr7FQNkqhdWfEjtsfmwTszgOKhLFoqSC1x8yxUKuI2XeZG98D2+j/ZD31zEMjWPOBf2tNq5q1vTJPkbOHPP2i8X86LIuXTUmmXjheLAEWoPxvbrKcp/0D6K8oxQgkLkqNAas4OanxwpHWTGOY6KaOwCl98GQB9yOFmNONNXulMWKk3zSFaA13N71uRg= X-MS-TrafficTypeDiagnostic: AM0PR0402MB3908: X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3908; 20:3QrFE9xge3kL+ES1Ba8wXP8RnykiVOShYbUT3vj3aDIWDL7AAQ/AFKHa8pdFPLUrjN8Jmda9GYg7fTFYizZ/StKxkM2QYpccrTBcZRnc8joRTKUnV5HqDY0cJjoHSxg+AhLz/kdsF8AYlI+60LTppea5G+kcKPbnZqpMyAIXzGWE7XxEQssA25ynfPuF9LfJjgincYeI3SlaaD98Gw49NngsCa2/lZW5rAdjVOJ54RIi7cg4kHPqdiN7BT76GKTs2tKqXndY+Lb2J458YBKYt0vrhiLRippOvjOCrOAQLnVXe/GiCwmiMkkm1XQnRUu9/wJ9pMeHVtRP1fphT03BgXPsrtqdgxvVBexa0TykOMnfKqWsVK8d/9Aq5iIJhfRu0x6Ny+Sbf4RkzgBuwh62pP9XBVazvYbBWAaRd8GuU840gDtDdqKJcAFl293Crn710+05cpcBVS0vg7tse2zeXa91JQspcQCSc+Exc0ObJBPyTZX0wqA+9QFgG3HtBuuq; 4:pdiznBgC7Mzm74b0b0WukEw4C9MmxpQf12dS3gxRuaka9cIqUdsWr8k1863/NhV8TJBhi6sNc1F6xLHIDJc2Lo/2TgFe5m5cleQalsQ2mEqRmE+RcwrNeRypRnk4ZtoRRlSl4Rp0k83YFVU/u/h1Upf3r9WLrabHuYF3hPI/u/xYA92VMZVFEXbsQh62/UfKTHi7OUnjW6/6eeja9dqmXlLckT74asuhVAn0HoU8nfW0AlhHufBa4yC1/FlerDmdteJLN55j1NzgYEURlOCrs9abCg1Mj4V1v9Dc8Dmjx3dfeCWdRvDptLEBOv4RxM7pb0JzaN+xnw9uKxqbI1SHBpqoXbqf//xitXr+1b2hAvY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); 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:AM0PR0402MB3908; BCL:0; PCL:0; RULEID:; SRVR:AM0PR0402MB3908; X-Forefront-PRVS: 0716E70AB6 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(136003)(376002)(366004)(39860400002)(396003)(189003)(199004)(2906002)(14444005)(7736002)(26005)(6486002)(305945005)(486006)(48376002)(478600001)(86362001)(25786009)(4326008)(16526019)(186003)(36756003)(50466002)(16586007)(68736007)(6512007)(47776003)(51416003)(52116002)(53936002)(3846002)(386003)(6506007)(6116002)(76176011)(316002)(97736004)(50226002)(476003)(2616005)(956004)(6666003)(11346002)(446003)(106356001)(8936002)(81156014)(66066001)(5660300001)(81166006)(8676002)(105586002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0402MB3908; 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; AM0PR0402MB3908; 23:exT/MimlKS96vOO+jrDhr0ClwAon1VqYKKPi+0L?= =?us-ascii?Q?Kbf7wHSQfAbKzjZiXsdzjEKn8hYYur465CcMt6D67HUiScQLLwhEm8CliLAK?= =?us-ascii?Q?mSlLHFOWKQeJwFHSjdXgI2o9SyUaBy8Ok+6GYs6JArCu6GhPDpM1TKC3zG9v?= =?us-ascii?Q?EQJcgxEf1vsvytKJit5TI5JDdvU21jB4aU9C2YkGmkPqIgLi8s35AlDDmE9x?= =?us-ascii?Q?JZiXwHHq9p1ZwSHuNNRUDUM+EYz4nu+t4c83IWTjldfybXUmR7liFbnqNIJM?= =?us-ascii?Q?jvrmj5VswK5hxvvbKQgEw6NPY9a+LvyF+/AD09/cs582sDiIJr3RlqCEThnb?= =?us-ascii?Q?izjlHtP18uL+aZrXXUNbKbNiApmvigccqPrbHt+65vyxKOLg751o05WGC1/A?= =?us-asc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pamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3908; 7:I+OWMJ86C3qgSNG0F76BzDGsEalJd3qo2U9T2RyMPBZfn2fi2pv2D1WScuU4umpt08kFIowiIeHHUhxuAcI9d30AMJL2tCqKeTy6IrxFrTdlfabnMWf4okzbJWWbS/1idlKEMDEKV+SBZ+VMd70ixl0dYqeTF2W/8Ly84u6QACtaLg6HVihi4ZfPstCW45kyrW3xy2pqQECdeJOP102o7kEWTvrbL44SZia4DqTMsj/x1ZRbIqlRKxHGZpBTtSJo X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2018 00:02:45.3659 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b3c9c288-4fe5-445a-83f7-08d5dbc15250 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3908 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. Reviewed-by: Heikki Krogerus Signed-off-by: Li Jun --- 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 */