From patchwork Mon Jun 25 08:08: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: 10485249 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 F1DFA601D5 for ; Mon, 25 Jun 2018 08:26:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC63528845 for ; Mon, 25 Jun 2018 08:26:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEE6D288E8; Mon, 25 Jun 2018 08:26:21 +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 1AB8B288A9 for ; Mon, 25 Jun 2018 08:26:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753199AbeFYI0T (ORCPT ); Mon, 25 Jun 2018 04:26:19 -0400 Received: from mail-eopbgr60074.outbound.protection.outlook.com ([40.107.6.74]:9739 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753155AbeFYI0R (ORCPT ); Mon, 25 Jun 2018 04:26:17 -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=xVyPA1Of/CyXP1uVP3zpRXufIwlFQ9PChIvwW6yoj5k=; b=kgrVPD1d3mlaFritq59zEJiJMNWIF0tcrHN5RMAzFwLgZ3FaZrJHyrYVodC3e/IxW12J5MpjLQdhiH89q6PlBqXpocFFPev1EJQDgEXmi9qWujJBE91Zd9pz695ubyMazo2+5H69Qq0knK/7+dBXNfm8EbsHYw53xYKhcgKq/F4= 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:09 +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 06/14] usb: typec: tcpm: support get typec and pd config from device properties Date: Mon, 25 Jun 2018 16:08:38 +0800 Message-Id: <1529914126-22550-7-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: ec41f34e-5959-4617-6c09-08d5da7550a1 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:DCRB/88zBpN4pfSaRIOBbeuL+972CZuarM6taEFL3CrDSRF58FlMGPoRsS88XtGaQR4sJ6hE3TrzUE5yTW4qRUJmr/fNAZC5rI7863lEFZmSNrQANpjFeEOD09N3WkqYDbnDggP6rMEtgB+NAzM3TVDi+7ch9cSwIBX6amWlBLoCezkUsKYeD190sMnObfCDEAHD5iOoA//DY5urs/Jk3AUdc61lU4LBo3QbT7eUW4xBTba3qM6jkxEnee4vCpaC; 25:cxOgnqOKZTNDqxiXIUP8s65THjxd0uZKZ+MK48rz0CcP8dfMIWX1lDj5LURgMpiE0AOakJO1ipEWq4QownPToYeeJSdWdK4a/emCR8ipej4cUuepuk9CTdZMwTBMLKrXP1zzywfH9wujtrNXM5P2V406B8Oqc7ISdfLeAMj3QS2sWMYeCqBYeYmvHgsvkBuAw4nNNdhgPnnGu316h9T1B9X6mZMl1UY9jbK3qKWKDCL8pHBflpLpglLCUaTacSZSGP1/fpceYnqYeroszSDc7LwGjZu7zNtR3/ghfFpVpIee2JUbVsCixaOsR9+OOoVD2EWgldsldNsRLhFhxNvxJA==; 31:j5l57DYGOEluUQtS6WqYEAsJx6CDBwKrNSZ4dFX+nsh69Vm6bFJvnpvzKOsxl8QksovslQHKm86QpKG3BoA9+53ZsHoJdOi95J4hvkbgBahtxwc/geJLL5NXumWDvi+tl5Ym1FECU/OSK1K7gJRiApxkwSmFEgcycfbgd4W1yD+klZY6GrOfJyapF79os8uVfe4PIahozX5JONF7+b0F3oDwHIaGcniEjq3LjZAMy6M= X-MS-TrafficTypeDiagnostic: VI1PR0402MB3920: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3920; 20:UcBpLS5+6SECqTD8K9f1IcaXY+QNVLExYJKqSYlzj/pw62DKAL86P5PwQODhljrmL2tx6+jhqL6ry/ZsuKxPhnfUe+JKmjXfFU7v03kF+0e8Z3/2Bp2jjeSfdgqTHvyUbq3e0C/wHjRvr996klfXH1PajiobgDcW8yzfXfdnX4Q1jg8G+weYCf8oZZLw5VuH46auqjnYloLK0WHbmnhf5GJUlmY3BzWKX0NVDbLKkeERlzd8j8JaB2RPIwAHyIQf0HxsNHJXn1UmLboRVMg5RTePW38JCvJmmQky0CbG7cJ8/mgbw4QleiesYl+ybjTaRoC/TFkyB7o2n6yQcTREj9eFXKJcvSWXpv2GwSuB+kIVdo24Qtxas0RRVY44ljFlcFAD5y0sxWUt9EbXe/tIQRnLP6Y/rfYfbF3E4ffLkRDFwN6NU++hQfh3Z3Q/pGQnrVw3IxBoSLTeKRkVAwUyDIonY6t8M9rKZPLyN3qXrKTy33SNnr1hEK3MqcIP9NfU; 4:UOI5Zz7C9Ix/snWyFr+mZ1YyshUniuVgKMOgGt73aLD4l0fquh/0zCfsWQp6i6pGeH7fYzBH5RQdaM0QDDXAOMKmrs8CRV/wSOrJ3kkB0AWShgX6DearrRVHnvvbnihs5QEYP/AZ381gpj7leOTEOmRByN61qUNKkJQVv433kLBkHSZ5ct7Y7V0vNfeoPES6FneoiTaRr6XmU5x/nfqICk2cIbzQ4fOjisqvYxuObrFLjTMTqtCECj2dgDux1N7L254nyL+mlRHimX+D6oVdMcImJ+FYpCqs1b/IN0sV78ADvLORRDP21+xNvNXWlIdNi8icqZFVyNalwDPXaNDUeJ3W7g5VHTs+wzFTQF0PDw0= 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: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:HiDcGdlZQmef90MFuezKxxxa0S+W/I9cOMNeiQ3?= =?us-ascii?Q?LXNswjZTueL7MxJJ3DVkPC0b4gZoWqgFMalhcKU7TWvuSjPUwjc5r1rLeHuC?= =?us-ascii?Q?JPn5tfmPmOG2zMOYDLKX2dg64j1sDihgATa9k5M5W+Yetttmg2lAbqi9Zexz?= =?us-ascii?Q?Foq9A5Zux69dUE5W1fNxcWkRzrkqND6NdKr7KwESmgrtdIp7qALwh/ytM6nt?= =?us-ascii?Q?zFsVVVRj3wriv8wT7kQ76ihSU+/LB1T7bVzSEVZ+3Xty3MXXYxKz0BWTsjxa?= =?us-ascii?Q?TYFME9bMqOrSXoL2wkXWajR3Zhh5EOO6CmD0vMjOr3degrq5xOK0PLR9/pNH?= =?us-ascii?Q?Eh+Z5BDq0Ix46LTmmUqji5tkoZqZkR4G9FL7atS7g9xCoSA501yxez/ytFtK?= =?us-ascii?Q?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dJ+ho= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0402MB3920; 7:jvVpnIlaHhA57zy2Zwz8Z5PQ4U4tUN/fOECccSZUzBASNRLGPBL+HJS3p2qCRvIobtd4C+YBrpWD4f8BQeplyn5ypogM09sDXIk3LxaS9IqWLH3tphCDodXkg6cmwA9F3k9FJgftODb03Qrd/3kiJU5sQPX4dPsk77v6L0XuZAP33iEOa9+g8EBwrJeZVqRq53iwQaWpTsP9iFIQONcO3HSv0UjKAWjZnb3FyUGD6Jtg0X4d736vIsc8zb6FBSta X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2018 08:26:09.5952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec41f34e-5959-4617-6c09-08d5da7550a1 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 support of get typec and power delivery config from firmware description. Reviewed-by: Heikki Krogerus Reviewed-by: Guenter Roeck Signed-off-by: Li Jun --- 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 d22b37b..0454654 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,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; @@ -4589,7 +4677,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 +4695,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;