From patchwork Tue Jun 26 23:45:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 10490335 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 DDF0A60325 for ; Wed, 27 Jun 2018 00:03:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C441FF13 for ; Wed, 27 Jun 2018 00:03:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4D5426E54; Wed, 27 Jun 2018 00:03:01 +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 18CA81FF13 for ; Wed, 27 Jun 2018 00:03:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932520AbeF0AC6 (ORCPT ); Tue, 26 Jun 2018 20:02:58 -0400 Received: from mail-eopbgr00040.outbound.protection.outlook.com ([40.107.0.40]:27246 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932104AbeF0AC5 (ORCPT ); Tue, 26 Jun 2018 20:02:57 -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=5HUavPh0lOfUv9e4oNtQDAOd/BsYW5oelVcLgOW6BKA=; b=xayvGvoO4IschabSXbAEa4J/jcbMjnD6ID3+lql8VcvRSfm00NZHFPEt7tbaQBjLD5v8Cu1ffLJ4wEPsrDHUB89TW9cRA0Rx1LREVqDWdl11PAjmWlNJPvCdFRwlfDcxMZqUWkY+pKbg0LydpkOqcZu56LaImroODvYJIOi5bE0= 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:50 +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 06/14] usb: typec: tcpm: support get typec and pd config from device properties Date: Wed, 27 Jun 2018 07:45:24 +0800 Message-Id: <1530056732-9640-7-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: e360a0b8-3999-4991-4e56-08d5dbc15582 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:l1Fa56nWmSGwTzHbYhX85EHqKpPHvpHMQs8DWzw9TYv9PKFKUDzMMyhq1msdyf1pcxUoxjLRXOTVm5xPNg5xGDDg2S0wSDd8ZmrZglb2A/X2STfxqEsfjuyhKQV5NApNr5y7274ZJdzfUuqr00qowC4lQG9Sw5iBSebbpM3ETuZd0S8sltq6ejZZfQMJl75KEetjEx1rGkzHzAblaV6z1etWvwu3+msszx6ewjgkOTIn6sxehCgBloaBUWVJiD0Z; 25:fBeKGCKBKKJ3ugwG5DJHfy1ATt7eXkS1Bi0XHv1c+UnpCO4K73Yk18QpD0+trxLeSm/yoet82c7m3FjUxmUu09hRMfGJb4N8e0GfunJ0xS9gcZSnpsGvoxQcf6H1+d09HA0uw82XEEL/Cmxq0R5Yw+GbZ/3a3+2pSm049mxKwP4EqgsI394S/+LxcdwVacm2JcDbT0oqmOm4wjdzetDUJGxGTbdMNkyvbPKAeq72nftMOD8oPHtB2vZ7Fg9jdms6/TF3YIhVA+1FDN82QyV8dOPtuTFa8skU3TlQ6TARp09Z4bntToz81SvLHDryKl3SVNs5iv7+iyL49xd3waQDTw==; 31:+JiXHnuG8wByr9aHDSKW0XPNZRizF8lApKMBNV+ADtagwfxE//4aNIs7AG+T0+9D+ah2nK4fCd+x1ApxDYoJBYMfby6KdnzetbHj38B8V43NKt5w8btT1HK6kzKVDUQBk1+daw50puCaopqW0ECPLycHMJvkKnfA2r8GD/C6NiDBxNxYudIWfnG9Ocby5pKiGv/hRIHIa69Eym4inQjud+jMgEju/NY9zrKaYBcV4zg= X-MS-TrafficTypeDiagnostic: AM0PR0402MB3908: X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3908; 20:abEaLRR0IWyym8JY3HcTLkUfLztmO/T6+r5pZ93BIVRdKuBUXS8agDVysyCAR8vqD2gvb/ZaDXuYwdZ/ZxlLEJlSoeg3LoAE+6B6J5ZvCrE150MA/frC+M+6fe1QkxUkxexmaOkTzGOZRYpL09j+OJgKeBYSS7FHS11CMFD8CDR6yOtaS+ZgtYVmwWvPM6iNfx8pUgt6OBj7/Gq9bt78cmu1zhKDCIVoR+7yq2qBHEgrriesX109yJEs6r0rIPz9rmjnuKcZt1wDbtUY+laQMpCiKmrXz47ahjCfClKGmppsl9P25Edu0akPY00RLlDO9ZVfK8Hp5rHYboqTZ8FjBhwjsslLtSuo6rQqh3SeC4qvD+XGbcAaNYAqHP1CWeHtnnAIdeCcnfuxpdnFExJLcj30+JOkJ7mQAp3e1hEESPWXC5JHvxAsZFRdTpJPKLIJP09U1HW4ouXc/i16ORGwltumigEsh7YIvYU61DWSUbymPbrF5wNTJ7lk1uxpFBIY; 4:aDwaUcuH+DJPnLA/2oKD96vEFbCmd4/9KdJF2MI2B//JbIvwiGQ59W45C0U70/oHrByEEihraUzV8TA40ksYRIeSVMW8qnmEhExK5r5CYciSnMyaZQxJre0xRXOCQaB2nGEF14+sfFWskIMvJv6D/bi4KDvt6WjadMd2YyaWEycYIFfc8jUmVVGfd6Ud+bii8znB4tDCo/8c+cU0F/OyaQ0kIb2Fq+iT7ukyPsXiTQ+y6rQnM5Aa7US9yknx/ScYfMqhuk2xAZ5xCF+8lfrdcEVu3kvLp+vjmKIxkQYAsQ2KMffLKhBjB0Iblz+TQvCVkUefiqxrwmdMy2ZgXL14IPVVHG9q/uF8VF6QKHlYK5Q= 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:G1Fxi8QFUkYlDqxWgle9e2+fZ0LNc4SQFLS8icV?= =?us-ascii?Q?twvzPng1GNUOpjJg+SPm4yOrU/C921MAbMc/ZlI04zYpAuMNuN5jbDCJibW1?= =?us-ascii?Q?DOrUg+SajejJ0/jLveZibhbX6943VK1QpvsSIZ6KqAa9bXlgLDRpoWhyt84i?= =?us-ascii?Q?P5IizCCch7fckqmIooD73XGi5sQgev94PRa215+ScZpMpJ5wjPOmgTO8S742?= =?us-ascii?Q?nzAGTaj5+FmG4QQY+ZtlE3sSeljbyoAO1vw7BrqOac6OWKCu6fBwB+V81cJZ?= =?us-ascii?Q?Rs5MQlp1SFYgA/4p7hpgzQW5CK2E/WfhQ1qIvgoZAoedlxvCHGmwr+wdM6Cp?= =?us-ascii?Q?LyGhJkQl+vcLAAiTTSVAQLMk1QyPDgI8AlztOHtZHysWnIzCEO3e/olwqSRQ?= =?us-ascii?Q?vgMry5o2x1jK1iWPcnkRlwNkPODcV1pMwpc3jROWiHpi7YrEEcSeLeg/y/jh?= =?us-ascii?Q?Hh6I2RylZ1A4ael+xO4Hya004Jk+uFGOtYyozx6H1C0SSCwOuqHmT6m8UqTb?= =?us-ascii?Q?V2wQ15yVC//PePkRWHkwHvkmgK0saZvgH3ooYQWHnfdmJAM8salnJI1jQ4G2?= =?us-ascii?Q?EmFXhLap0QrPjkSqlTqsAq7T0qRlToOwnpSpeOtsbo13x6UJsD+u+WSsH1uX?= =?us-ascii?Q?YbQa9+3Or/HOBxjpwNuef4FcLaDW8YZWZ13A9TQYWndGC83ik+QuBCEjewrn?= =?us-ascii?Q?FKVju6AmSvrlINghIjF0MW3EkClknb0qtIzPdNDsIwvC1CmWbkHuPfRse4ZG?= =?us-ascii?Q?Af69wgGN3O2FOtnKkfOR6Gai9wZKJIUMMQPMAQH0bkYXAqyUweF53SwoMSwz?= =?us-ascii?Q?7M7c+/Cy3r+kOGRlcZM2Zu0v2oOHXvoJ93nlfvHwTTbI0yD8gMy4PQqTmYoV?= =?us-ascii?Q?h6uepfYPI9ziBskLOTjxAmLF8Uvj1O15aYyQrLDXXwxBkaqU2eBdkNRpFcuH?= =?us-ascii?Q?Jbv2aUagF6SONLyYw8aePaXjmCCXUeOCulJTLMhOcGFsIpkKivBtd0ZQxNbU?= =?us-ascii?Q?NAZSCuogEK1TOUs2kEM8yxwSXi42HDEfF+9D8/yLmJE6uNv2kzgSeiNfbIvQ?= =?us-ascii?Q?Vi+/BYNu8etc0DItEbWNE5yNytXrmIyCihyeraMqiGvNXAZDtORwvFjOzE7c?= =?us-ascii?Q?ANLEu/6a3ueGN8IAaf/Lae7cTCj8k4PSunRk/klutiGhMWCNyp6R1JA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Antispam-Message-Info: YrLGJypLi7ioAfv8oD0PCCWBk5TpSgwaeNfRt/SBiJpbbSrCoCXtYXk18iJayhIVAOqahzM7xEewVJ47HEvFG+eEhz9nR8QnajjBumwSpCQbpbnH259fJw32JvCAnDUCuR2ElKJJYLJfTU68n0v0fdcIb1E4ELklxkJ4sCXdb5igbtj3D8hyZdG74zdfZkCaqM1yam/r34X20Bix0O7LarYx1t/9McKAMt0niulsnPbwfz+8VHRThWhu8fLTRcbR5fDpyYiQPPPZ+/s9bDfr/Pr9ks5jkjyaGekKzR3df0c8RG9NM2VhjuagxZYQ06JOirDGX2/47e7ZqJi5XQ4LEtKxPm4dveSt+hqM82JtM8M= X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3908; 6:apKhpizLQk0LpdHOtdP14SEB7/T+A7+ZF1n/PALOuZoTlrk3g8hvl8VRzwQritsBYaQD7+85nCgxwnO5g+R+MMha1hjBtBSDHuAVup92TDaUN0bv1LdC5pF/gbp/adABvc3NMlEXeKnW64vGIOUSDw8/J4unu2d5Pad8yww2h9ycG0bzYCjZXTYD+CD6XT4eooRBacTDIInV/+a0f9I3wDYfno6wAbeKR31/ZaZHsVKe5jmLnBODFk/EsgrJelsVu7bC/JTRd8x3RkPJVGDcdhmQFvtOT7hp8SQP27RR+eWBR86Au6/FIA6SLwcKm0iovzVgqtj2g73vb5UOxgNCK8SRvXlUlyHFP1O/fyujomYWGr/bm/ecFrFnpmVok51LmE4WGR2LdcIsWP8CVs4QHuTzzamgaDrFJs+9teDof3Zotv2ShlcnqVh3NQvp9PRRH5LrkBxTPrvaWCo64MGwyw==; 5:FA9A64wL4tmJNrgc8DGiQ1hTXk3LYgjkdCeoUaaNqtxopEom4mjpSANLcoDUw3EI+crpncJHXRdVB6YQaqC3Al+Wm6+NL1v9ywq9x6X/90MHNZHfRRRX5Yd6c6YCIXEJRsAEp+oLSefk7JmSQIUQKKGDDS+O2+slSDMncBayGsI=; 24:73900vxw3adRNluqEsU4ta5fdInilFdtDGEu5PqIcDa69989FhXpD/KgytT3e5cNYWtKv0RTwTstosEMbvIO24FDdfh5PXGSvJnMPqFttEw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3908; 7:0Qk8ghLMqnjz40B++IinkfjKkOD3OiDSJaQbWmM68v4dkWjU3SywwmpklYQG7A7mE/6AQeOnS6C2J3KRdC/EktdEy7OuT+xtZSLV+F/wAYMioltgS1ivu94YIa5CVOiXD8OF7s70LEFQjsSpNHrL8Cn/xko/Cd4KVnqEZ1QQlEKvKdtskCYEaSgreSW5BW2tGr+b0GcYopr+rS5a6wd17aCyNp7ddYz4y0rfhErpSd6UPzmPvnGcgXCrTw2FhoN2 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jun 2018 00:02:50.6004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e360a0b8-3999-4991-4e56-08d5dbc15582 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 support of get typec and power delivery config from firmware description. Reviewed-by: Heikki Krogerus Reviewed-by: Guenter Roeck Signed-off-by: Li Jun Acked-by: Adam Thomson --- drivers/usb/typec/tcpm.c | 131 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 109 insertions(+), 22 deletions(-) diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index d22b37b..9dcab81 100644 --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -4236,6 +4236,81 @@ static int tcpm_copy_vdos(u32 *dest_vdo, const u32 *src_vdo, return nr_vdo; } +static int tcpm_fw_get_caps(struct tcpm_port *port, + struct fwnode_handle *fwnode) +{ + const char *cap_str; + int ret; + u32 mw; + + if (!fwnode) + return -EINVAL; + + /* USB data support is optional */ + ret = fwnode_property_read_string(fwnode, "data-role", &cap_str); + if (ret == 0) { + port->typec_caps.data = typec_find_port_data_role(cap_str); + if (port->typec_caps.data < 0) + return -EINVAL; + } + + ret = fwnode_property_read_string(fwnode, "power-role", &cap_str); + if (ret < 0) + return ret; + + port->typec_caps.type = typec_find_port_power_role(cap_str); + if (port->typec_caps.type < 0) + return -EINVAL; + port->port_type = port->typec_caps.type; + + if (port->port_type == TYPEC_PORT_SNK) + goto sink; + + /* Get source pdos */ + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", + NULL, 0); + if (ret <= 0) + return -EINVAL; + + port->nr_src_pdo = min(ret, PDO_MAX_OBJECTS); + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", + port->src_pdo, port->nr_src_pdo); + if ((ret < 0) || tcpm_validate_caps(port, port->src_pdo, + port->nr_src_pdo)) + return -EINVAL; + + if (port->port_type == TYPEC_PORT_SRC) + return 0; + + /* Get the preferred power role for DRP */ + ret = fwnode_property_read_string(fwnode, "try-power-role", &cap_str); + if (ret < 0) + return ret; + + port->typec_caps.prefer_role = typec_find_power_role(cap_str); + if (port->typec_caps.prefer_role < 0) + return -EINVAL; +sink: + /* Get sink pdos */ + ret = fwnode_property_read_u32_array(fwnode, "sink-pdos", + NULL, 0); + if (ret <= 0) + return -EINVAL; + + port->nr_snk_pdo = min(ret, PDO_MAX_OBJECTS); + ret = fwnode_property_read_u32_array(fwnode, "sink-pdos", + port->snk_pdo, port->nr_snk_pdo); + if ((ret < 0) || tcpm_validate_caps(port, port->snk_pdo, + port->nr_snk_pdo)) + return -EINVAL; + + if (fwnode_property_read_u32(fwnode, "op-sink-microwatt", &mw) < 0) + return -EINVAL; + port->operating_snk_mw = mw / 1000; + + return 0; +} + int tcpm_update_source_capabilities(struct tcpm_port *port, const u32 *pdo, unsigned int nr_pdo) { @@ -4521,12 +4596,36 @@ static int devm_tcpm_psy_register(struct tcpm_port *port) return PTR_ERR_OR_ZERO(port->psy); } +static int tcpm_copy_caps(struct tcpm_port *port, + const struct tcpc_config *tcfg) +{ + if (tcpm_validate_caps(port, tcfg->src_pdo, tcfg->nr_src_pdo) || + tcpm_validate_caps(port, tcfg->snk_pdo, tcfg->nr_snk_pdo)) + return -EINVAL; + + port->nr_src_pdo = tcpm_copy_pdos(port->src_pdo, tcfg->src_pdo, + tcfg->nr_src_pdo); + port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, tcfg->snk_pdo, + tcfg->nr_snk_pdo); + + port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcfg->snk_vdo, + tcfg->nr_snk_vdo); + + port->operating_snk_mw = tcfg->operating_snk_mw; + + port->typec_caps.prefer_role = tcfg->default_role; + port->typec_caps.type = tcfg->type; + port->typec_caps.data = tcfg->data; + + return 0; +} + struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) { struct tcpm_port *port; int i, err; - if (!dev || !tcpc || !tcpc->config || + if (!dev || !tcpc || !tcpc->get_vbus || !tcpc->set_cc || !tcpc->get_cc || !tcpc->set_polarity || !tcpc->set_vconn || !tcpc->set_vbus || !tcpc->set_pd_rx || !tcpc->set_roles || !tcpc->pd_transmit) @@ -4556,30 +4655,18 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) init_completion(&port->pps_complete); tcpm_debugfs_init(port); - if (tcpm_validate_caps(port, tcpc->config->src_pdo, - tcpc->config->nr_src_pdo) || - tcpm_validate_caps(port, tcpc->config->snk_pdo, - tcpc->config->nr_snk_pdo)) { - err = -EINVAL; + err = tcpm_fw_get_caps(port, tcpc->fwnode); + if ((err < 0) && tcpc->config) + err = tcpm_copy_caps(port, tcpc->config); + if (err < 0) goto out_destroy_wq; - } - port->nr_src_pdo = tcpm_copy_pdos(port->src_pdo, tcpc->config->src_pdo, - tcpc->config->nr_src_pdo); - port->nr_snk_pdo = tcpm_copy_pdos(port->snk_pdo, tcpc->config->snk_pdo, - tcpc->config->nr_snk_pdo); - port->nr_snk_vdo = tcpm_copy_vdos(port->snk_vdo, tcpc->config->snk_vdo, - tcpc->config->nr_snk_vdo); - - port->operating_snk_mw = tcpc->config->operating_snk_mw; - if (!tcpc->config->try_role_hw) - port->try_role = tcpc->config->default_role; + + if (!tcpc->config || !tcpc->config->try_role_hw) + port->try_role = port->typec_caps.prefer_role; else port->try_role = TYPEC_NO_PREFERRED_ROLE; port->typec_caps.fwnode = tcpc->fwnode; - port->typec_caps.prefer_role = tcpc->config->default_role; - port->typec_caps.type = tcpc->config->type; - port->typec_caps.data = tcpc->config->data; port->typec_caps.revision = 0x0120; /* Type-C spec release 1.2 */ port->typec_caps.pd_revision = 0x0300; /* USB-PD spec release 3.0 */ port->typec_caps.dr_set = tcpm_dr_set; @@ -4589,7 +4676,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->typec_caps.port_type_set = tcpm_port_type_set; port->partner_desc.identity = &port->partner_ident; - port->port_type = tcpc->config->type; + port->port_type = port->typec_caps.type; port->role_sw = usb_role_switch_get(port->dev); if (IS_ERR(port->role_sw)) { @@ -4607,7 +4694,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_destroy_wq; } - if (tcpc->config->alt_modes) { + if (tcpc->config && tcpc->config->alt_modes) { const struct typec_altmode_desc *paltmode = tcpc->config->alt_modes; i = 0;