From patchwork Tue Apr 17 06:01:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 10344401 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 672386039A for ; Tue, 17 Apr 2018 06:17:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58A2128767 for ; Tue, 17 Apr 2018 06:17:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CE98287B7; Tue, 17 Apr 2018 06:17:27 +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 7686328767 for ; Tue, 17 Apr 2018 06:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751191AbeDQGRZ (ORCPT ); Tue, 17 Apr 2018 02:17:25 -0400 Received: from mail-eopbgr00076.outbound.protection.outlook.com ([40.107.0.76]:54089 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751057AbeDQGRY (ORCPT ); Tue, 17 Apr 2018 02:17:24 -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; bh=ZuTVHTdveQeNNbNUuTpQ1l7xBeT4XE/JQm9Cab43y14=; b=wd3lV2z8U40t0t97dlzeYEuPWKSHY3oWYoUPqgtD5NFEdvxI3cSo6OsciM50trLDvancHHoR/70hzVsNILGNCGSqGLNh5RGRx8HEcW71OfvjiW+yFy9xmiUvjEwsoTDLN8poBfixlWC1cjOxvliEgH7hzinQgB3OKlwQcHwe0PU= 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 AM0PR0402MB3906.eurprd04.prod.outlook.com (2603:10a6:208:f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.10; Tue, 17 Apr 2018 06:17:19 +0000 From: Li Jun To: hdegoede@redhat.com, linux@roeck-us.net, heikki.krogerus@linux.intel.com Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH RFC] usb: typec: tcpm: remove operating_snk_mw for rdo Date: Tue, 17 Apr 2018 14:01:48 +0800 Message-Id: <1523944908-8350-1-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [92.121.68.129] X-ClientProxiedBy: HK0PR03CA0034.apcprd03.prod.outlook.com (2603:1096:203:2f::22) To AM0PR0402MB3906.eurprd04.prod.outlook.com (2603:10a6:208:f::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM0PR0402MB3906; X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3906; 3:VMbNqjDuWazo4gp8cS4Airz0+9NEfjAOu/I92F+8H99vAF/U9f88AQuuTTYm9fCyF7jmefra74BsMO2KNcwr5PHo+j7TS9TYakFkfdsyHr2fAltPT1GJaJ2yIC+13PVjYqG8aZGctTLna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RohCPZmH9Tap56qa69lc0ib0LnB485wrWLVLWFUhTrJDwjtvjm8U9Ex+rs+cKQxXua7fBQZUeyf3eeQXN487t2UfRzPcfxASND3mjNIZ+i2qkGF0X1ucPcKNSGN6K7qJ1rKoT6COoUn4cdM/xx02HpaDGuy7lEYh1rl5J8063TJFe3ffb5RJ3IjyT6lax8KnkIZcudYH6T/OOgXPd8ml53s9eKxlT; 4:SoDpEssYGvKdKk13opLYw1qJ9CsC8Ac2P+9meTWDvc5LwzpC1/6PgANNJKBQCN2Mkq75PP/4KdT9+4l10/7/yqJhC4U7rHV7RDRowcJjGhQiYEUOReeORCcD0ws88GgD6I+KCHdVhEwWsX00D+kcK6mHw2OXVUprqO/GDuvohSoj1AHN12AhyZqIR9S/t4OBb8s36craijrCWdtuexGUmOi8GzPV9SrI3cETmrGD38orKV5JjHQWcxLJNszf+kn69ahetM9OdrYShiNB8musm2h4aUqMOPzkOZCyTU2kjOWUKbrOb1bLKyhvcGHpWLxt X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231232)(944501327)(52105095)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:AM0PR0402MB3906; BCL:0; PCL:0; RULEID:; SRVR:AM0PR0402MB3906; X-Forefront-PRVS: 0645BEB7AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39380400002)(346002)(376002)(39860400002)(366004)(189003)(199004)(50466002)(478600001)(48376002)(8676002)(7736002)(81166006)(106356001)(81156014)(2906002)(6306002)(3846002)(6116002)(105586002)(6486002)(8936002)(66066001)(6512007)(50226002)(25786009)(86362001)(476003)(97736004)(68736007)(956004)(26005)(2616005)(6506007)(47776003)(386003)(36756003)(186003)(51416003)(52116002)(316002)(305945005)(486006)(16526019)(6666003)(4326008)(16586007)(5660300001)(59450400001)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0402MB3906; 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; AM0PR0402MB3906; 23:nYD8UUNYNKBB0Dzn0V0NhKb6rjSGQxNAihf3hLn?= =?us-ascii?Q?UqYA63fxazl0CnFtXH+XJORJmkV9kQ/5lPV+ll3Nbto3RD2s/z2wx/Af19pn?= =?us-ascii?Q?skVeQjLxHecszLZ0nAzweJwlUkUDRd2V4bOW/Oago9HoIxjIN9bpxr1YrSMX?= =?us-ascii?Q?NF/lVPPHVlV6RCbDcjdqK5PvlFXfSDmVOigLSfO2k/5WJxDHMTzRm/GGzPI7?= =?us-ascii?Q?xa+IES5nQ8bhaz61yek50VJXiCf7lhK+TFP6YYfHnbshhyfbb5b2WRnOUP0c?= =?us-ascii?Q?5OhJ8ydvThPFLZb/QYOID+rkIcrIJQ4hqffcW6EXzqnwwJUnCY5F0POkqGTI?= =?us-ascii?Q?CYI5Iromzl/t3Moql5W2nixawKB0PU7DPhpdVGI3ausiWK8S3GtXbsU5rQUL?= =?us-ascii?Q?SPraPLotqRu8CdQ+6JeeArKY7KFXe+P9geE850LCe+N8Ko8TfG4LO4MaH2gF?= =?us-ascii?Q?bhyXHf5PNYm/mcUSo/o6ZzTktkcjo8Klo8BmM7W2lmHDcr2DeQj02UuS66PB?= =?us-ascii?Q?nnCcnTycU+ksTULbyCuwkBWshoO+H/QcfnKskSm3j3OItYv7DV/Ntpum4vHE?= =?us-ascii?Q?IEGJDBDx69dySH9QyqK8F8+UTKiwZwh/Czc2PufXnKB6u3ccCQookV9Z9XvC?= =?us-ascii?Q?2hNSRQDnCahLA9hphV/Woi2Tcqai7GwHVjuuUEo8Tm6VHeJuRAYnJup53eos?= =?us-ascii?Q?jimVwtkL59MShbfaOVG3UUAhud0MIovka0sblFdTqySayOHEyLfRdgVux5MJ?= =?us-ascii?Q?VJO+7jl/eoqSzaN1U1Myqv1lCdh/ozBZLZSdl8yiBFAF0drpyglHuhtMB3/j?= =?us-ascii?Q?3iR23p4HvbMpzSfYWqBKCVqGY4P+4A8vnAFgjWGcbMkrW/TY4od8nwxQB1g3?= =?us-ascii?Q?DzgEghv2BBtnlit4W3+N68NZwE3G7Zk1XosKC9yt2XeFhFHVvbyWBPf/Tadx?= =?us-ascii?Q?7mGkXnbe87UIPEvHv+OsmZKAAUNSpgLnO8vZqJ9eUpjyYN8//8q0n+nJEVyh?= =?us-ascii?Q?ZPW1He2V0gb6FkJBesoxEqdAhLmycIZP7homUQFt/erdmjqbqXZmg59qOMxQ?= =?us-ascii?Q?aeZx2GJThM7XZJWfLCZMO/OHLUA333ih4ljC1WCNPv7oW1WZxNtaau7DEl2k?= =?us-ascii?Q?sdGtc/mxuvm2S6d+SRrJdqQvJZYB3Vqrj?= X-Microsoft-Antispam-Message-Info: tq/kzEMgUPUTlcWGfN/RBE/2CKVqDCWjEXGlDTZuOmxidfCZ78Il6bCg7rvRsq2yQtq6T1xN3Fy6ggCxmntiwgf/BUOx1h8KMxIPEEbv/IcaEh8yl+9rAXsR6b2P/Y185AkOPTqjBg7RwSE6NIzo/rPZl4oheX/WM2ObWPQa4hsizYfg4e9k2/Kic4QkQjbl X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3906; 6:E5GCad7YyBmBy1VVbYEJ9jix0w3iDrf8nbQtENek1ti9+fnTE2CUIi9O57Pz3VTsl8/f8QQVVq1eo0d0O9S+sZTnHV8LlUt1UqcYio5GIDK430VMJSgAiKxrpzD9bbNiaC8UXDSAB7dXKi16V1GGrxDJCxYFJbRlBrPWfodXL1ghbLDjrBragsmPN0GnYeMKXX7hKYuluZU5v24aF7UhLnrItw9FOoU1uPpuk3a+3HOyvy5yCUAn880cbep2RSNbVgkJ3uy4hKCnu5dASk8mShORnW9OpMvLlM2wWdMh3JaPtdZrliozPxl+60PPA4PtWrpNQ0fKN8qVeYZ8I7J4lAl927t6hGw4/Npzulw2hmZxMcZm7KtXL/v9H5uVilb9O9+rbgk5dxZmrxUlwZdr6hvPJS6OQZ2ZdZDCr7Hqn8X+NOn5DdmuNWQD+1hY99fr0jJkHJmUKzla3bmVodNIGA==; 5:LT46y0aXE/CWJZIKhtuMK9QEsISdyzEMUmsTq+K1IZro4wswo82hz3eSZOaEEVeaiTXKG8utU19dkb5GlYlaHszUwyFfHbMrIuFlaR9NVNJkUqH+cznq7SCtpBi5w64Y8D0iymp7Rl+EN5GPlfcLi+6/hHaarde1Wbb+B9JHBn4=; 24:Oq0Xw3rvDpO+nkUHIL/nt0eEVGphc3Ds+y3me2ctP/9xRiM8sZVBBXqrIqalsncX1OX8GCYO5DPXQHMeEyLEGoFEsigBO8WnX8lYLBQNY00= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR0402MB3906; 7:EzCUkTGT9jMYxqbMri2/Wfd+W+SfI1mJjRkbqKoO8BfDOsaVvF8co0RiCvvUw5BZC6XUxJ/uca9gIM2ekLGlNXmqlvyw+PFpRILk/9QMIoV3WfTKclqXW0fPkUlqntRIiAYLNVG8WM9W3ylUI0c9VBEbMIluPhWL5Rmvb93/2yv3OQQiyzgUykjV8l3GbFxxk5MRAssDwvzL7OBo18aOLQHkbkmwcGImB9VNhLqihfNk599IFX+1EjkFLVf88uZ0 X-MS-Office365-Filtering-Correlation-Id: 4a960b27-8510-4b23-3d81-08d5a42ae152 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2018 06:17:19.2700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4a960b27-8510-4b23-3d81-08d5a42ae152 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0402MB3906 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 is a further update for rdo based on [1], which removed max_snk_ma/mv/mw but kept operating_snk_mw. operating_snk_mw is only used to judge capability mismatch, per PD spec, we can achieve this via compare the selected source PDO and matching sink PDO, also after patch [1], we don't limit the PDO matching between the same type, so the rdo operating and max current/power calculation should be updated accordingly. [1]https://patchwork.kernel.org/patch/10342299/ Signed-off-by: Li Jun --- drivers/usb/typec/tcpm.c | 52 ++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/drivers/usb/typec/tcpm.c b/drivers/usb/typec/tcpm.c index 27192083..0be04b3 100644 --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -1854,28 +1854,42 @@ static int tcpm_pd_build_request(struct tcpm_port *port, u32 *rdo) else mv = pdo_min_voltage(pdo); - /* Select maximum available current within the sink pdo's limit */ - if (type == PDO_TYPE_BATT) { - mw = min_power(pdo, matching_snk_pdo); - ma = 1000 * mw / mv; - } else { - ma = min_current(pdo, matching_snk_pdo); - mw = ma * mv / 1000; - } - flags = RDO_USB_COMM | RDO_NO_SUSPEND; - /* Set mismatch bit if offered power is less than operating power */ - max_ma = ma; - max_mw = mw; - if (mw < port->operating_snk_mw) { - flags |= RDO_CAP_MISMATCH; - if (type == PDO_TYPE_BATT && - (pdo_max_power(matching_snk_pdo) > pdo_max_power(pdo))) - max_mw = pdo_max_power(matching_snk_pdo); - else if (pdo_max_current(matching_snk_pdo) > - pdo_max_current(pdo)) + switch (type) { + case PDO_TYPE_FIXED: + case PDO_TYPE_VAR: + if (pdo_type(matching_snk_pdo) == PDO_TYPE_BATT) + max_ma = pdo_max_power(matching_snk_pdo) * 1000 / mv; + else max_ma = pdo_max_current(matching_snk_pdo); + + if (max_ma > pdo_max_current(pdo)) { + flags |= RDO_CAP_MISMATCH; + ma = pdo_max_current(pdo); + } else { + ma = max_ma; + } + break; + case PDO_TYPE_BATT: + if (pdo_type(matching_snk_pdo) == PDO_TYPE_BATT) + max_mw = pdo_max_power(matching_snk_pdo); + else + max_mw = pdo_max_current(matching_snk_pdo) * + pdo_min_voltage(matching_snk_pdo) / + 1000; + + if (max_mw > pdo_max_power(pdo)) { + flags |= RDO_CAP_MISMATCH; + mw = pdo_max_power(pdo); + } else { + mw = max_mw; + } + + ma = mw * 1000 / mv; + break; + default: + break; } tcpm_log(port, "cc=%d cc1=%d cc2=%d vbus=%d vconn=%s polarity=%d",