Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp347820ybh; Thu, 12 Mar 2020 03:11:35 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvKd0x+x7eN5hje9Cs2nx6hQd2e9j7WeAIpBXmPohq2CWAR+fKt/ZqqBItCFWPyJljfYvAt X-Received: by 2002:a4a:83d3:: with SMTP id r19mr3442758oog.26.1584007895278; Thu, 12 Mar 2020 03:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584007895; cv=none; d=google.com; s=arc-20160816; b=dVIhKskDIUCMIINJxLvr6zgzmXAcdmP6tM1dBV4/XTo6tYAtXEkevTEC/vU4AuutcT SNkVglirpFwPum5c6Yq99Gvz0DqhdottMVm9OOBbA/J5cAnwC8kUDgKeJOlQCZSBS9V5 f1yfowZZVouGNnWHCImRMnM5yXZ03anTJh1BoYcXrjsbIgeZNNmLxPmwvZW+Y+a2r+CD CRn85Ir74xtaoXgO1GzJbpjpz4MaC2Xbc4D7exMS0JyKLPeTrbDJVVmzmxK8aVay/sA1 yBPNrrBoYuvUJ1U351UtLylx5TVZoKBrD9DbdMXTB52BrxL8L49HvYtobK12SjSmW9Q4 5gig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Zvlb+FvFd6kbdQoEVk7MAktkpupjBY4PDAWlePBUw3c=; b=qWvo8qPWYThTtm4GUuG3JhoJr/RjlUWyMM1ngTh6z6lHZyQnVN+pmxCe14SeV0JOcp wyTOH5ni55tZe6hEDdz7ZlQ6JusvEbloe8aiM/PQ5yRZ/LRYReM85u0jW+u+tCkwiM5V sJ1lIghF+Mpm02KfWmcmj2vo9WL/9L352nJ3EVjv6ctasOLnou5fMbl5AaKmzwvlCx+b sCaAdKF20x1Qmq9Q2cOZNEq1l0IKzPVhbYwARii1svCsrw50NwDqYaWgIuWlwiRtfzQx dPwfnSjNnktbnJGsy1wW6S2BqYh7KMU5uQuKSqJCaJMGf2eZ0wcyJ9rGSBM6KiwEoOy8 xNIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dNDXdnQ1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q21si1437938ooq.38.2020.03.12.03.11.22; Thu, 12 Mar 2020 03:11:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dNDXdnQ1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726492AbgCLKJe (ORCPT + 99 others); Thu, 12 Mar 2020 06:09:34 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42344 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725268AbgCLKJe (ORCPT ); Thu, 12 Mar 2020 06:09:34 -0400 Received: by mail-pf1-f196.google.com with SMTP id x2so2661552pfn.9 for ; Thu, 12 Mar 2020 03:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zvlb+FvFd6kbdQoEVk7MAktkpupjBY4PDAWlePBUw3c=; b=dNDXdnQ1qE/HwYnjjnnNZoYKZirtiihAIwEltN5ws+SuQJeaZ4WwWdCnwJlJXWPnZs yp2xQGpOUXLrcMiXLv77Tkpd8SecEzsHPauCoo8nnuTGhOUxomINnpxpwGB4F4ZkntrH 4fLuvwfZMyYBjFomHT71QuGRLK1Aou0EyXviQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zvlb+FvFd6kbdQoEVk7MAktkpupjBY4PDAWlePBUw3c=; b=ZVhz0AhXFnb9lsi4hx/xR8dacTEspy11IkGD47PNNhm37/6PSDPGojGZV1NaSxRXJj tiEqUAM196/6XlEAqfwTNA5oVbKm3BPWsjDSMMJCdvu90L6uxUjGZcSKs4Ih//m9hVuz 546wrDAV3uAKuOVPiXKwfQH6tfFo3EO8zV2dFjAhKQZ/RYHsRFjZ1hGYVFfrtp5rcEXE k6sZPoCQUMGpemI905A+xuWU6zmYlMO8nooPOFDjUbTq5hBaIg/glrrQ9w61wdSQyLEM kP14X+BYo5lLSIzpWy8hS9zzdU0UAWQSWuxg9+S2iO2t9rIIRM+tcaR1inLbrj5Ocw47 g4eQ== X-Gm-Message-State: ANhLgQ2/NgpeGVNW0P4/hHvkc1QVdwlQrDqJLWvQ9IswsEzciul9nfgf 2T1ym+J8uffiv5gbjpOFGFoTZmlFMR0= X-Received: by 2002:a62:17d1:: with SMTP id 200mr7151259pfx.227.1584007771016; Thu, 12 Mar 2020 03:09:31 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:476b:691:abc3:38db]) by smtp.gmail.com with ESMTPSA id s19sm3678368pfh.218.2020.03.12.03.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:09:30 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org Cc: furquan@chromium.org, Prashant Malani , Benson Leung , Enric Balletbo i Serra Subject: [PATCH 3/3] platform/chrome: notify: Pull PD_HOST_EVENT status Date: Thu, 12 Mar 2020 03:08:11 -0700 Message-Id: <20200312100809.21153-4-pmalani@chromium.org> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog In-Reply-To: <20200312100809.21153-1-pmalani@chromium.org> References: <20200312100809.21153-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Read the PD host even status from the EC and send that to the notifier listeners, for more fine-grained event information. Signed-off-by: Prashant Malani --- drivers/platform/chrome/cros_usbpd_notify.c | 87 ++++++++++++++++++++- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platform/chrome/cros_usbpd_notify.c index d2dbf7017e29c..3d9db4146217e 100644 --- a/drivers/platform/chrome/cros_usbpd_notify.c +++ b/drivers/platform/chrome/cros_usbpd_notify.c @@ -53,11 +53,91 @@ void cros_usbpd_unregister_notify(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(cros_usbpd_unregister_notify); +/** + * cros_ec_pd_command - Send a command to the EC. + * + * @ec_dev: EC device + * @command: EC command + * @outdata: EC command output data + * @outsize: Size of outdata + * @indata: EC command input data + * @insize: Size of indata + * + * Return: 0 on success, < 0 on failure. + */ +static int cros_ec_pd_command(struct cros_ec_device *ec_dev, + int command, + uint8_t *outdata, + int outsize, + uint8_t *indata, + int insize) +{ + int ret; + struct cros_ec_command *msg; + + msg = kzalloc(sizeof(*msg) + max(insize, outsize), GFP_KERNEL); + if (!msg) + return -EC_RES_ERROR; + + msg->command = command; + msg->outsize = outsize; + msg->insize = insize; + + if (outsize) + memcpy(msg->data, outdata, outsize); + + ret = cros_ec_cmd_xfer_status(ec_dev, msg); + if (ret < 0) + goto error; + + if (insize) + memcpy(indata, msg->data, insize); + ret = EC_RES_SUCCESS; +error: + kfree(msg); + return ret; +} + +static void cros_usbpd_get_event_and_notify(struct device *dev, + struct cros_ec_device *ec_dev) +{ + struct ec_response_host_event_status host_event_status; + u32 event = 0; + int ret; + + /* + * We still send a 0 event out to older devices which don't + * have the updated device heirarchy. + */ + if (!ec_dev) { + dev_dbg(dev, + "EC device inaccessible; sending 0 event status.\n"); + goto send_notify; + } + + /* Check for PD host events on EC. */ + ret = cros_ec_pd_command(ec_dev, EC_CMD_PD_HOST_EVENT_STATUS, + NULL, 0, + (uint8_t *)&host_event_status, + sizeof(host_event_status)); + if (ret < 0) { + dev_warn(dev, "Can't get host event status (err: %d)\n", ret); + goto send_notify; + } + + event = host_event_status.status; + +send_notify: + blocking_notifier_call_chain(&cros_usbpd_notifier_list, event, NULL); +} + #ifdef CONFIG_ACPI static void cros_usbpd_notify_acpi(acpi_handle device, u32 event, void *data) { - blocking_notifier_call_chain(&cros_usbpd_notifier_list, event, NULL); + struct cros_usbpd_notify_data *pdnotify = data; + + cros_usbpd_get_event_and_notify(pdnotify->dev, pdnotify->ec); } static int cros_usbpd_notify_probe_acpi(struct platform_device *pdev) @@ -144,6 +224,8 @@ static int cros_usbpd_notify_plat(struct notifier_block *nb, unsigned long queued_during_suspend, void *data) { + struct cros_usbpd_notify_data *pdnotify = container_of(nb, + struct cros_usbpd_notify_data, nb); struct cros_ec_device *ec_dev = (struct cros_ec_device *)data; u32 host_event = cros_ec_get_host_event(ec_dev); @@ -151,8 +233,7 @@ static int cros_usbpd_notify_plat(struct notifier_block *nb, return NOTIFY_BAD; if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU)) { - blocking_notifier_call_chain(&cros_usbpd_notifier_list, - host_event, NULL); + cros_usbpd_get_event_and_notify(pdnotify->dev, ec_dev); return NOTIFY_OK; } return NOTIFY_DONE; -- 2.25.1.696.g5e7596f4ac-goog