Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp72454img; Wed, 20 Mar 2019 14:23:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoKZ85UACjtIhA70EgjTBv+fa1dyQb++vHBA9KNqxy70zUuTcvWGCE1OBFvL0ZTc032wqL X-Received: by 2002:a63:158:: with SMTP id 85mr43717pgb.351.1553116982012; Wed, 20 Mar 2019 14:23:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553116982; cv=none; d=google.com; s=arc-20160816; b=0eV7JEkympUHUfEsTjTxZYtXrHhFQ8ThIXdudKWKfit7OIjsOutgJUihjVCstzs0d9 x0xirBlUShSoqH+4i6cqpYKDfzGWMM0bedALMkJVXvB6PMkRARKS3ojIBGRl0AE7seGR zsYvvbwdqVsRwO17Wq2Tk8xXKqpaAnIEBfJCg4Kc4TvTNT/gHpYNR0VrAQVVrnEEs6B3 0JSCtvqP/vJM2RKM0vzB/aehW/qYEU3CeyL1XECOVjeC9Zj09QXIbzLK7NBACUYxZTEN xd/CEIdLlXYPBLG+xaVVqvUP4vcgflMOS/3p9eoUeT3vrqTfhLrMza01uZ8A1EWeQadu eIxg== 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=irvMbISskK/KpJ3A2VOS6FKNJ4d1rqkwk9RIpQHEpwQ=; b=zV/ymW3mHzEJJWTW8SdSqa4bpSx5VB0kKttJVjvNWvSxGEzDjOEm3rEK97iXgHL0D8 QZ5MlGvE4AqT/XtquqLU5kfGEUfdGJ23H9K5Elb4D/vNgbty8x/nv9VzKWKSCR2cNqVt L7rzcf4spObAobdEQVlkg62rN59jHVbfoC6vT7DaLMkVmkj6l71pOS9q8PMuS3XdSLRd EsJIMxDhRB+1GaOZrbrLkSpe4+h8KL5mnCIfI+dkDrheIg8wMkqqGYQWcdQB/T3SqbX7 GKoQZainQJ0URCnbC1zBu3N8D2Ftprcv55oIrmcrIiiT15OFA6Z2Pf9GVaJuZi/yeP7W CL6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fpDBk1lf; 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 c10si2610657pgd.18.2019.03.20.14.22.46; Wed, 20 Mar 2019 14:23:01 -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=fpDBk1lf; 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 S1727668AbfCTVVE (ORCPT + 99 others); Wed, 20 Mar 2019 17:21:04 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35482 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727381AbfCTVVE (ORCPT ); Wed, 20 Mar 2019 17:21:04 -0400 Received: by mail-pf1-f194.google.com with SMTP id t21so2070017pfe.2 for ; Wed, 20 Mar 2019 14:21:03 -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=irvMbISskK/KpJ3A2VOS6FKNJ4d1rqkwk9RIpQHEpwQ=; b=fpDBk1lfpiNfT+iMmTIWLG17IrS51L7bbAsFjCFj9U8XPGRFAD6FAw362vt6F4yVVW EfC/1z+1KSHdaSoTYVYrwlGagElG2L/OsbZS+RiB0lOFFpoVdjaZdZppHBlTrzz9qqtJ ucZ6GFdJ9VCuyl11YaA10zV0ZhcbM22IWs1yg= 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=irvMbISskK/KpJ3A2VOS6FKNJ4d1rqkwk9RIpQHEpwQ=; b=kqg2YSwpPdhf8kuZyd+5+ZqNdwhzsMxfl1gAMjVjTfNmXKXkcmopl1/Jd/gbv3WxTV nfttmtFdtZQnGU0qeVNOMhIuUe1ZWjRYyZ0FX+62H9+z+gDfbawscMCTXX47oGDuQHXS QRWT1umovxEw46BwXyxqTaKOo9NKBJ4/3S0GBoSqugIsBaySb7AMFlbPGLvX+ZrxtXHb Pgp7+PGa0ryXgJY6SFae6xx6BwQEDaJZ2vK0jahUYtDzFbqlAnLvyQNCwP2taXXouYSD OVHb1+4+scQfxJ5ljO3bBucRYR6Am15iWZHZCBHrpSQANFKU6m87/TW6hjRO8tR4cHko B8ew== X-Gm-Message-State: APjAAAU6j4bmsznOPaPD08w1o6cwDd29UX97ajXmkrP8Su6ZcOkmEwCM R9B2Ltu0wv8a4UNz6BZiK/UnvQ== X-Received: by 2002:a17:902:9a43:: with SMTP id x3mr10571446plv.173.1553116862799; Wed, 20 Mar 2019 14:21:02 -0700 (PDT) Received: from evgreen2.mtv.corp.google.com ([2620:15c:202:201:ffda:7716:9afc:1301]) by smtp.gmail.com with ESMTPSA id u13sm5288609pfa.169.2019.03.20.14.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Mar 2019 14:21:02 -0700 (PDT) From: Evan Green To: Benson Leung , Enric Balletbo i Serra Cc: Furquan Shaikh , Rajat Jain , Evan Green , linux-kernel@vger.kernel.org, Guenter Roeck , Lee Jones Subject: [PATCH 2/2] platform/chrome: Add support for v1 of host sleep event Date: Wed, 20 Mar 2019 14:20:30 -0700 Message-Id: <20190320212030.43682-3-evgreen@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190320212030.43682-1-evgreen@chromium.org> References: <20190320212030.43682-1-evgreen@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 Add support in code for the new forms of the host sleep event. Detects the presence of this version of the command at runtime, and use whichever form the EC supports. At this time, always request the default timeout, and only report the failing response via a WARN(). Future versions could accept the sleep parameter from outside the driver, and return the response information to usermode or elsewhere. Signed-off-by: Evan Green --- drivers/mfd/cros_ec.c | 37 +++++++++++++++++++++---- drivers/platform/chrome/cros_ec_proto.c | 9 ++++++ include/linux/mfd/cros_ec.h | 2 ++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c index 6acfe036d522..5305ea706aa9 100644 --- a/drivers/mfd/cros_ec.c +++ b/drivers/mfd/cros_ec.c @@ -75,20 +75,47 @@ static irqreturn_t ec_irq_thread(int irq, void *data) static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event) { + int ret; struct { struct cros_ec_command msg; - struct ec_params_host_sleep_event req; + union { + struct ec_params_host_sleep_event req0; + struct ec_params_host_sleep_event_v1 req1; + struct ec_response_host_sleep_event_v1 resp1; + } u; } __packed buf; memset(&buf, 0, sizeof(buf)); - buf.req.sleep_event = sleep_event; + if (ec_dev->host_sleep_v1) { + buf.u.req1.sleep_event = sleep_event; + buf.u.req1.u.suspend_params.sleep_timeout_ms = + EC_HOST_SLEEP_TIMEOUT_DEFAULT; + + buf.msg.outsize = sizeof(buf.u.req1); + buf.msg.insize = sizeof(buf.u.resp1); + buf.msg.version = 1; + + } else { + buf.u.req0.sleep_event = sleep_event; + buf.msg.outsize = sizeof(buf.u.req0); + buf.msg.version = 0; + } buf.msg.command = EC_CMD_HOST_SLEEP_EVENT; - buf.msg.version = 0; - buf.msg.outsize = sizeof(buf.req); - return cros_ec_cmd_xfer(ec_dev, &buf.msg); + ret = cros_ec_cmd_xfer(ec_dev, &buf.msg); + + /* For now, report failure to transition to S0ix with a warning. */ + if (ret >= 0 && ec_dev->host_sleep_v1 && + (sleep_event == HOST_SLEEP_EVENT_S0IX_RESUME)) + WARN(buf.u.resp1.u.resume_response.sleep_transitions & + EC_HOST_RESUME_SLEEP_TIMEOUT, + "EC detected sleep transition timeout. Total slp_s0 transitions: %d", + buf.u.resp1.u.resume_response.sleep_transitions & + EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK); + + return ret; } int cros_ec_register(struct cros_ec_device *ec_dev) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 97a068dff192..78ceab659a36 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -414,6 +414,15 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev) else ec_dev->mkbp_event_supported = 1; + /* Probe if host sleep v1 is supported for S0ix failure detection. */ + ret = cros_ec_get_host_command_version_mask(ec_dev, + EC_CMD_HOST_SLEEP_EVENT, + &ver_mask); + if (ret < 0 || !(ver_mask & EC_VER_MASK(1))) + ec_dev->host_sleep_v1 = 0; + else + ec_dev->host_sleep_v1 = 1; + /* * Get host event wake mask, assume all events are wake events * if unavailable. diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h index 8f2a8918bfa3..b6442201f77f 100644 --- a/include/linux/mfd/cros_ec.h +++ b/include/linux/mfd/cros_ec.h @@ -120,6 +120,7 @@ struct cros_ec_command { * @pkt_xfer: Send packet to EC and get response. * @lock: One transaction at a time. * @mkbp_event_supported: True if this EC supports the MKBP event protocol. + * @host_sleep_v1: True if this EC supports the sleep v1 command. * @event_notifier: Interrupt event notifier for transport devices. * @event_data: Raw payload transferred with the MKBP event. * @event_size: Size in bytes of the event data. @@ -153,6 +154,7 @@ struct cros_ec_device { struct cros_ec_command *msg); struct mutex lock; bool mkbp_event_supported; + bool host_sleep_v1; struct blocking_notifier_head event_notifier; struct ec_response_get_next_event_v1 event_data; -- 2.20.1