From patchwork Thu Jan 31 03:54:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Tso X-Patchwork-Id: 10789645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 265A8139A for ; Thu, 31 Jan 2019 03:54:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80E572FAD5 for ; Thu, 31 Jan 2019 03:54:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 745802FAE0; Thu, 31 Jan 2019 03:54:22 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL 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 193C72FAD5 for ; Thu, 31 Jan 2019 03:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726783AbfAaDyT (ORCPT ); Wed, 30 Jan 2019 22:54:19 -0500 Received: from mail-qt1-f201.google.com ([209.85.160.201]:37364 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbfAaDyT (ORCPT ); Wed, 30 Jan 2019 22:54:19 -0500 Received: by mail-qt1-f201.google.com with SMTP id d31so2203154qtc.4 for ; Wed, 30 Jan 2019 19:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=fnyzfi4yjVwz7Fyg+QDUndSTcoOupKEHKb/Z+jqY0/I=; b=wVw0VsGB3/bfde3sRiFR5/NSPzbTZVVA0Zoenf5cxc7HsgEM2ADLI7PyQ9ZRkeqjAo qFyICs8Hwj137HvaW7AphmwBVN4f33JEhwigZv7o1afl05FdLuMVb0GZKZgGM3xOu3gu NsDghCQk2MopTqhu9F8XpIhCARVrNUjk+l1tEnl2eYSCD5+ESegXWdo/nvRSPmHpaYp7 KWt+gHIulgVYQ1P6PDjN+MLhx2Z+WvtTvT6iQ7sYJUzQ1NxXHXTKSNGCCZ9pLZp4cFrI vxeN50qao/QJ6LoiDzSVj78TMzcq9ZxTosJF0mBUaqDCIsLrHJe8O9/0NH3PdaazeyrY G6kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=fnyzfi4yjVwz7Fyg+QDUndSTcoOupKEHKb/Z+jqY0/I=; b=B2xqAcr2FRjuVwIWvUbrKjm3RZrpxQQCdS+srfzib2ZPD4sF6SaVX6OssKuFW4kPCj kq8xWuItaoyoPMZdSg/pO/mlpIMI8IP0BfOzLHL7SYcHQxKHQ/GZiQIqLNInskqfg4Lq GtlCPlfeFfm4is7werJ1ub9ytUmvpjRLmPKj1PHjjFDeArta/MOAP4lbVFmC/+0QZgUI g49n6InSWj7H2Uqjc3gR3fski8vNSc5cZtHSiUqZdZ2doEtiq9VTnRtHHGGnxAgD38Fr LakPFHXxd9NIPQ8lCqITe+t1bTGj8MYzmBSXXdXAmjBlqPJAKx+rYV3/5Y/7agTvnJ+A Q9nw== X-Gm-Message-State: AHQUAuZ9Ozite4jXAskxhkFcAXigok5CNVohPK7F9FC1wejQMI0Uua6j 08tnx1yvCGK4JmkfzcCKL89oy+lCtNts X-Google-Smtp-Source: ALg8bN4LCQcrGgLGwmMNMvispYuVuT5K2DECeZwh5Hs0JJOMGFKD+sP2QewlgATLDVE3y2g6vbm3Ulo4Cxy9 X-Received: by 2002:ac8:17af:: with SMTP id o44mr8163254qtj.24.1548906858039; Wed, 30 Jan 2019 19:54:18 -0800 (PST) Date: Thu, 31 Jan 2019 11:54:11 +0800 Message-Id: <20190131035411.53576-1-kyletso@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.495.gaa96b0ce6b-goog Subject: [PATCH] usb: typec: tcpm: Export partner Source Capabilities From: Kyle Tso To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Kyle Tso 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 Provide a function to get the partner Source Capabilities. Signed-off-by: Kyle Tso --- drivers/usb/typec/tcpm/tcpm.c | 23 +++++++++++++++++++++++ include/linux/usb/tcpm.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index f1d3e54210df..29cd84ba9960 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4494,6 +4494,29 @@ int tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo, } EXPORT_SYMBOL_GPL(tcpm_update_sink_capabilities); +/* + * Don't call this function in interrupt context. Caller needs to free the + * memory itself. + */ +int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **src_pdo) +{ + unsigned int nr_pdo; + + if (port->nr_source_caps == 0) + return -ENODATA; + + *src_pdo = kcalloc(port->nr_source_caps, sizeof(u32), GFP_KERNEL); + if (!src_pdo) + return -ENOMEM; + + mutex_lock(&port->lock); + nr_pdo = tcpm_copy_pdos(*src_pdo, port->source_caps, + port->nr_source_caps); + mutex_unlock(&port->lock); + return nr_pdo; +} +EXPORT_SYMBOL_GPL(tcpm_get_partner_src_caps); + /* Power Supply access to expose source power information */ enum tcpm_psy_online_states { TCPM_PSY_OFFLINE = 0, diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h index 50c74a77db55..fe56d759567c 100644 --- a/include/linux/usb/tcpm.h +++ b/include/linux/usb/tcpm.h @@ -173,5 +173,6 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port, enum tcpm_transmit_status status); void tcpm_pd_hard_reset(struct tcpm_port *port); void tcpm_tcpc_reset(struct tcpm_port *port); +int tcpm_get_partner_src_caps(struct tcpm_port *port, u32 **pdo); #endif /* __LINUX_USB_TCPM_H */