From patchwork Mon May 28 02:52:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 10429711 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 7CC9560362 for ; Mon, 28 May 2018 03:09:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CCA328AF5 for ; Mon, 28 May 2018 03:09:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60EB428AF8; Mon, 28 May 2018 03:09:50 +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 ABE0028AF5 for ; Mon, 28 May 2018 03:09:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753147AbeE1DJr (ORCPT ); Sun, 27 May 2018 23:09:47 -0400 Received: from mail-eopbgr00087.outbound.protection.outlook.com ([40.107.0.87]:41092 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753137AbeE1DJq (ORCPT ); Sun, 27 May 2018 23:09:46 -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=a3Obguc6KmmbDhD/XW9v71jcZjSwHBQOz0rEsMGPCOk=; b=tpKcob16wT2xLkVbT69SfCiepnsiIDmQqer941wZLakDiAkI6OI2R60hQyIUbDwR0eMGr7QnHx5dDiXoWgF+Zwr/3zC7VvF5elm6CYekLTAKMkiNkmpSJXyU+kUA2n+SpO3EVA8GCNhTjJ02p0s/Ar7jkb5PoBHt/Aj3A2jwSxc= 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:38 +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 06/15] usb: typec: tcpm: support get typec and pd config from device properties Date: Mon, 28 May 2018 10:52:38 +0800 Message-Id: <1527475967-15201-7-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:5HbsCgI9B2heW7A8W3zPGoGl1Sf1ChYYBKYNJcYP/oD9yTD5jC1nEey0pQ3FLCspuZNvcxVMBA4AmB6q8Ijr5jyGaXurwdSbr3vpMp4PaopMuEUveDYfUAA9Xxw4gpM8VbCkbstUuvwqtgRFM37QjbaE/g4anNEp1QHAbF+rqZKa2yqeWEyYS/1hNqEWIdtmHzYkWZF1+MjnILSHGe7b96ShYuhMXvvvu7sz/lJq0oLfbOMBbd/J6MnCxYRVaIb1; 25:8levQc2FA34ZXdsK3hcbSvDk+cjZmDiAuMLQXqcjTQ+x7a6VNszUbSn/snR3aKl5gVWdEzO/CMeE486xznkQzSjCtrC/agHOrSE3IcIfgJhboW4xZvXRZ0af5bdh/p3KP68vI3r78nhzWxEdSnL+BNVn+5RDajcv3NpUCRgLRoTpOI562YzpQTibCbVNRJ/UGheYO4TE+N8X3mHTS+UdhJApWVLzWFxDv9vF0EQ2xkjM2NgdtPgP9afKWh3SUagDo0XPRBss9NXL9QpLULug95leMNwzCjdjqcWdgiI2S//AZwxw9bOF7H5jT/0CO6xuG0uKcyTj7I0hPfmsS9VzUw==; 31:4U75DDenOhiL5W+pLN6naVXjkQjL8uyHoYK6UXcZ6wrAw6cUDIVKjx9mD0e5CDczzCOiDinreacHY0ShmTGbOdN/zBMLIRenNYcWF9vLN2r8F+1WRaACYGu1Mv6ipDRmIRjYD5Ce8sLOcEZR+H/UMzxbxIF+myUE8SrYHsAYwltdHX5yt9h4lUgFUUocAyKBpErBFW1YAidBobBd1x4EvW8JdQT2UvV5+K0Ef9IDpt8= X-MS-TrafficTypeDiagnostic: VI1PR0402MB3919: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jun.li@nxp.com; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3919; 20:j1J1qUc+rp0FYPhSJj5aogEYDR+ffpCPpwcNvrO0PXBu9tIY8f8Xux14n2fxefgsjp8cnn9k9nwR0jp+Q6C6Wiy9MrVn8qAEQcGpHaSeQOWz8UYTlOUVplUz4UX3Wxe9fTNocfkFtFIHiAXwVQB8d4EiNSKeDDOuzADK21NocRZlA7tg4E6BeIRp7Si7KAWUkU6WWfW1hV2lU08csrEvFVea9tZLCHN5IIVXFcJC0siYi4k4Bo4hlpg2CH4SlfvJ8obnuUDNwu654L2IzERzdoIpZXBKWKJ84m0bmX2hnMrBj3MF8jXlAXKat/oCdvq7pvqSuwDBXGo+hcKOh2opGyWlR6YTpAyJ6suFYhqLyVr0zqxtMscs6cjcvujkQ7EOMbNPvDs8KRwQ+0SFAUOjLd63lcKLJdLPbezVL38Z4DCLJ/bJ7iJAA3MA2lFxFew1ZlmJs5HQ+b3f0VZ7kHSFK6OdjwGpQVkZfMSu2EzekQojMqZJZ8jHyf9lkOOvpvVp; 4:6UNHnoh+0PshYK/9GEgYXa+JKY2ruwSfsLI1Flj41bmxLKdT2JZpgvouucjkajhvkWIRQHScdK3X8ONJqn3c4yXqb5FbWu4ISZCleTWXUefkSe2t2KK7Z80xUJGTVR0R61HXi0pkvJF3zlvsOJ9weOnccB+IilwgB8YvtObp/N/z7KGiZQCmtCNxwfclIjoqUowl+ZR9YHSr9FNueOvs34eLd4+V6LGmqcIPUOILrcAYMKWQorf95znDsq4bCWotXqkFVcX9KcJqc4zlbrjb2BCb/o2eklNCvS04VbLL8smxLsGqrMtOVB6OI45y3Lyu 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)(59450400001)(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:QzKNKhqWTJWxDkUHJi0HNqia7WX41kfr3ISrBGq?= =?us-ascii?Q?MaCjh42/jHDc9YxApt5srU75w9Xvi2UKwho73aeGnYRfegnJ5NfDcr2xfdXa?= =?us-ascii?Q?2Pb3TSQRNQf/BDTqSR+znaAcO+GWEHUi2tTMm8apQJybbf4Oo6tF5bReJNB2?= =?us-ascii?Q?ZChe/5aTwnt8taTk9IfKovV4Z8wRO/lSRgoVD+yKRt5XQa5DTHmhpcXCNgT5?= =?us-ascii?Q?k+dWpf3PrsRTXsyN3NW4NsMz0xgWLg3YoZAgh5pEym7291n2IX/806WqEMgf?= =?us-ascii?Q?peNslKWC6pzzPYWKmpjGoYo0kQ6mPj6unxyPh2mrQCtYDPLEtjWOkiZoXOX3?= =?us-ascii?Q?J8k+U4YrYXD7fN7RbSM6gcR2k4DfcDYARMXOXpQW+Ik2RbUe0ljCrizVbJ7G?= =?us-ascii?Q?youjTZrPIGeG2aCJH740cGt0o5j/2P62cMT7djIAmyn/55iXlY3jbmoeyag9?= =?us-ascii?Q?cti68sVEuSg8N9Wia9AhMPF0qlo/cWoHzJIXiG9cl57WSV5vOZPbks7mtNwE?= =?us-ascii?Q?+K7Ec8GeIe2IUZoVP3uDTNcVOG4ypDRF6F75vT+/4izERckrqbP4vqXJRAYP?= =?us-ascii?Q?8XT4luX5RIDJeoaxS6w6tvtljNFhlgZWebAxm6Irh0GSDFwAtwkqcvp+eS/c?= =?us-ascii?Q?cxlqmCDUnaCUmPYioooPGw9NSC3MJJIzBD+KdagzgBmTlF5FrIhA/olziy3v?= =?us-ascii?Q?VpTJUb4uVCcAr1Wm+97WH7D7nhI3FKpKhabc3LbykpVbKBzGMwDgC6BMLocH?= =?us-ascii?Q?Hq1dwvyaGi8sCmK9j/KbJM2OYT+w3F2N8RGH42t5+pWjk6vxaa5pEGsx4gAv?= =?us-ascii?Q?JoUplLZ9yy68V7pCGOIpkreYESBNi4ZVNZiBNUqBCU5DblmIRP+yeuXcgphC?= =?us-ascii?Q?AczZg0zTynSkEQOIwi0soRlnu0RqnCesyl7a4IasrmLCt2EDgA1xbfHv39oO?= =?us-ascii?Q?HYQ4DwOacAmxrNVRfjEoSxfqol9kHZrLuly811v0OQRJdZmhZ6y5lqkIU3C2?= =?us-ascii?Q?vb8lMl+38PUdpz8wvo69WL66IaNt4JcDeQTVy3eMInHqRtsuRgoZFLQKsL6b?= =?us-ascii?Q?u0Cm1xcgSjlPLr+GZUdlmfXjZQZPhRk13W6RMuLiCMek8BIPa738htJc6A9V?= =?us-ascii?Q?pNKNDZJ3lQEMDcxsnuGTRcFFUTMTP+CP+QJWi4nXxwpyuvYAMqls874ZU/Bc?= =?us-ascii?Q?mDDBDyr+DyxNoEAU6UE/WPfj0g3vs7XZw9kzb?= X-Microsoft-Antispam-Message-Info: SKSbb4AMVzbXGLQpfU+yOo6S2S3o2t4gwSWvz40GDBjmBfxEliJiUgcjLBS3F+sILfxPszVv5Cx+OJJQxV9QdRcL7W0DPo8rpAWAsDnE/0BO+5ucu8jZsJiLCqtOl42EatV4r0VBo103WEUN0BY30c5qjyUR+aV4mCUqyLlwXEcKQgqKD7HqMBRyQuiWcSQj X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3919; 6:CYkVSVUUX3c2ho1aJoFlEHYKD5nemdGMFhBSHYaPCt2KqexjbecPvuNcUbJLMfaG/m0l5L8mmL7nsSMSxRmrqxDTWnpzRVls9oyqE2Y+0GuWQB86qf1hkoLHR1UmbLw+2MZ5MqFgyfY1WQZIr8qrSeY858+gxP0reps80zKDaunVKdqfkndgp0qTUJm8V4riY+K0idGR4FmksL6w7/IWVOgLRc+cohjuwXP6q8zhDIvxdmG07pwRZioz/bHc1p18H0ZrznfiSrLG6a4Cbe6P+1IjDJhPFa+NkweUulJjenWG3OTBxJ7eIGTuXi6ILEKjvJ1QchWSvNXRX6t8YDNIZTUIPm3ov/NmkxQfyFIPDXy+OckQJamAfHpvZEHrPrIUvIMGX+d+myOACbfxbiqbP9kod3YKPgK59wNEeTE/xlmYwRMPEz/JtNLQG/5qOvf3GbDc7HmtFkcRsDCRtXptsw==; 5:SqKnrhBDmrRp/Tbhzl+JyxtrKK3jaR1aORlu9xdpTBBDYYyMlb8igqG94evWhiCmetDLmbXNaCSSYnFOineQrz6qlc+jPZavPX+yvIEb198ZrqB49ttCIwK6/KYz3PauGxQJHqmHKlNiFken433lmpTFQoTVZ7cqOlwbwipxAbw=; 24:RzagFPgjPe6y30wle1Q6w2ummbz0TLsTSfapej8N2qBehA7BKKnx3mWBBoTKYyIFwaYeP+cAzca9CCSL/2P1ZmjsRKTa8dqi0xQOKN0q97c= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3919; 7:HbDLj9zM81sdYrJpR2BSfqk2nhZb1/Vu6PLYoHc3mzOXHe29GbKsijAwxhGtvzf7ajS3niJ8zYRHdV+AXF1+kJfPglXQD6VJFgwM6u9eaM6oDMffZnYLweiU4sPbOFI9RFiMz5lmWDonutPoXE/CaJIdODzSH4HS0oiZIw09+SLTn+KconZsN5OiSt7iiZkfRqw7dginqMvCs/zktaa52yqZlBnTuDfw/nDXTsaf/PTFbWrHSEY5Y72pt/lCPoJU X-MS-Office365-Filtering-Correlation-Id: 20b4cf40-c015-4fe6-a0de-08d5c44875e1 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 May 2018 03:09:38.3921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 20b4cf40-c015-4fe6-a0de-08d5c44875e1 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 support of get typec and power delivery config from firmware description. Signed-off-by: Li Jun Reviewed-by: Heikki Krogerus Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm.c | 132 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 22 deletions(-) diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index fcd22e8..aa17cd5 100644 --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -4241,6 +4241,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 (!port || !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 soruce 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) { @@ -4526,12 +4601,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) @@ -4561,30 +4660,19 @@ 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; + if (tcpc->config) + err = tcpm_copy_caps(port, tcpc->config); + else + err = tcpm_fw_get_caps(port, tcpc->fwnode); + 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; @@ -4594,7 +4682,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)) { @@ -4612,7 +4700,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;