Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp691036imm; Tue, 15 May 2018 07:47:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr/wNcUDDOQ3Ujor9/LlNos4PxxpmwBgmkkzmTqNqIFKoxCt0quin2s2ZGyK/pLj1RcKn/+ X-Received: by 2002:a62:de02:: with SMTP id h2-v6mr15390239pfg.205.1526395673290; Tue, 15 May 2018 07:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526395673; cv=none; d=google.com; s=arc-20160816; b=d6/09uiGqw4YZnxvmkVdCbKRcP/6PB+6jLphBNmc2pQOTLwdaZKLZEHTG/NVMVbN0o 8f4eycxVOmQ+Sq+WIwNYqyIvjEiUMYqacqowSGxRG4EGhPKctPf95KCNl9j9vQVBVmRf Lpq5dz1EC8s48pi/pYBrC/sPjelTkFBb+Kqlm4Ai/86ulp1iY5dyHBARU23BfM6LcJnn IjMFvdnC3Rto+q7NyHKp8MhMAjnhF5OANQEL/ZUpz9AnQqJPxOP7Q18dS5d5/NhixIHI 1F/5od5stUt1mC7lk+xkdZqeO6gEf42YN14Ie/QlMN7XLgnf9HGNKbi58Kc+tcAeyTip /OCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=CRK2DT2+CeEvGsgq2Dnr+MOXNcS1ZA1y6QUNO0cqt9I=; b=XREdqVJKifwROusQiaIBLlpA6zStnmi90WO1vOcY9zozkEIuopt9p2S0KyTRLKTx2n jDYW2ggtan5M/ee36H+8LJCjV8ERz0Fle39gBEV11dSkoDyDeu5w5kmh/LJd3hH96aZK uoWSHkjTSOH8sFgrYkUQu0O+fyaL7EsX1EXOe+b9WjauK+eyxzi+dUCMzPkFeis9jOZl G/KSlDzvMehiLX8gysapE7nSRc/aF5Lp5hQ4aqQBeNAXoT6+7mKnMlTVu5vDJZPKI5rp PxqKzsobAO5BEQUI3u+vNk5Zez6PHf+xehzwTPxlGYHBQwP4gdaYFqfYYdpmQTB6UnU7 jz9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=F7HoRb7g; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4-v6si172752pgp.103.2018.05.15.07.47.26; Tue, 15 May 2018 07:47:53 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=F7HoRb7g; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932073AbeEOOmq (ORCPT + 99 others); Tue, 15 May 2018 10:42:46 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:36872 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754179AbeEOOmm (ORCPT ); Tue, 15 May 2018 10:42:42 -0400 Received: by mail-qt0-f193.google.com with SMTP id q13-v6so557910qtp.4 for ; Tue, 15 May 2018 07:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CRK2DT2+CeEvGsgq2Dnr+MOXNcS1ZA1y6QUNO0cqt9I=; b=F7HoRb7gTXKf4lF1pc8OiQOY1P5ywMAdyvhowdNCsK2Ufn5vPDrDWzGy7+O8HMyfBE qlbvTclDajJNK0nvlC5DgZZqhfmx/Gu0tv5i7pVxmuFkNyr0S1k0hkVUKdk4AuOqEfIM CnFPjx/sXpP60wZkaFzb3p+nYJLNmdA68zR+9x8N8yKAkQ6dtLyMedQUNXkkyiL3/opN b8FPLTOX5o/yHF8ToevNaZ2BJ9ilpHVZxzdL3O00TOSk/NFUc0Y84KN1S20izNuNWBax j3pALQX0qiWsuv6viGz+7SU2nDI35BAI9yG5Z6adbQcgb9EdX7VSfwIfHPbXHxMdnX5u KssQ== 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; bh=CRK2DT2+CeEvGsgq2Dnr+MOXNcS1ZA1y6QUNO0cqt9I=; b=XmdL+ioIjkvupAqOjVAbojtekB7fkoiyH/03ygiCBR3YVGGE5rTvdFBWmDHWHni61g UlZ1YeNzU/MHgSsjiOcyti9Tdjz4MC7/7F5dve95rPOxbmOTOeLCQ0n10NLChdpij/z1 6dauV4B0kX810MQ6OAKqlZlCQtuo1/5SrbwSYOJhMNJ3Dwh5iXNhb89kpCHEcME9Y1Bl gmkavgy+cGkIcbpTgRRp2SzVDr6FEN0CIVLqDbr5bdGJ01gPw5uhqOPOz4PfgqYMkyp8 4HFOBItIx0gGbkCHt5qPlncxeFqblG/r7WEF57Qd7xvqVeJkuya8fL3ebKeAyrudNLKG AbCA== X-Gm-Message-State: ALKqPwcrBYer4cwJ9sblON8WxdWjkZP/p60XP/A7ic90cAkHYXCnNsCZ /gaYZqjduQkepya7EAcUnLnnhQ== X-Received: by 2002:aed:3802:: with SMTP id j2-v6mr13700445qte.205.1526395361829; Tue, 15 May 2018 07:42:41 -0700 (PDT) Received: from localhost.localdomain ([2620:0:1043:fd00:748b:2433:2688:e1f]) by smtp.gmail.com with ESMTPSA id z5-v6sm132693qtb.88.2018.05.15.07.42.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 May 2018 07:42:41 -0700 (PDT) From: Neil Armstrong To: airlied@linux.ie, hans.verkuil@cisco.com, lee.jones@linaro.org, olof@lixom.net, seanpaul@google.com Cc: Neil Armstrong , sadolfsson@google.com, felixe@google.com, bleung@google.com, darekm@google.com, marcheu@chromium.org, fparent@baylibre.com, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Stefan Adolfsson Subject: [PATCH v2 3/5] mfd: cros-ec: Introduce CEC commands and events definitions. Date: Tue, 15 May 2018 16:42:20 +0200 Message-Id: <1526395342-15481-4-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526395342-15481-1-git-send-email-narmstrong@baylibre.com> References: <1526395342-15481-1-git-send-email-narmstrong@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The EC can expose a CEC bus, this patch adds the CEC related definitions needed by the cros-ec-cec driver. Having a 16 byte mkbp event size makes it possible to send CEC messages from the EC to the AP directly inside the mkbp event instead of first doing a notification and then a read. Signed-off-by: Stefan Adolfsson Signed-off-by: Neil Armstrong --- drivers/platform/chrome/cros_ec_proto.c | 42 +++++++++++++---- include/linux/mfd/cros_ec.h | 2 +- include/linux/mfd/cros_ec_commands.h | 80 +++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 10 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index e7bbdf9..ba47f79 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -504,29 +504,53 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, } EXPORT_SYMBOL(cros_ec_cmd_xfer_status); +static int get_next_event_xfer(struct cros_ec_device *ec_dev, + struct cros_ec_command *msg, + int version, uint32_t size) +{ + int ret; + + msg->version = version; + msg->command = EC_CMD_GET_NEXT_EVENT; + msg->insize = size; + msg->outsize = 0; + + ret = cros_ec_cmd_xfer(ec_dev, msg); + if (ret > 0) { + ec_dev->event_size = ret - 1; + memcpy(&ec_dev->event_data, msg->data, size); + } + + return ret; +} + static int get_next_event(struct cros_ec_device *ec_dev) { u8 buffer[sizeof(struct cros_ec_command) + sizeof(ec_dev->event_data)]; struct cros_ec_command *msg = (struct cros_ec_command *)&buffer; + static int cmd_version = 1; int ret; + BUILD_BUG_ON(sizeof(union ec_response_get_next_data_v1) != 16); + if (ec_dev->suspended) { dev_dbg(ec_dev->dev, "Device suspended.\n"); return -EHOSTDOWN; } - msg->version = 0; - msg->command = EC_CMD_GET_NEXT_EVENT; - msg->insize = sizeof(ec_dev->event_data); - msg->outsize = 0; + if (cmd_version == 1) { + ret = get_next_event_xfer(ec_dev, msg, cmd_version, + sizeof(ec_dev->event_data)); + if (ret != EC_RES_INVALID_VERSION) + return ret; - ret = cros_ec_cmd_xfer(ec_dev, msg); - if (ret > 0) { - ec_dev->event_size = ret - 1; - memcpy(&ec_dev->event_data, msg->data, - sizeof(ec_dev->event_data)); + /* Fallback to version 0 for future send attempts */ + cmd_version = 0; } + ret = get_next_event_xfer(ec_dev, msg, cmd_version, + sizeof(struct ec_response_get_next_event)); + return ret; } diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h index 2d4e23c..f3415eb 100644 --- a/include/linux/mfd/cros_ec.h +++ b/include/linux/mfd/cros_ec.h @@ -147,7 +147,7 @@ struct cros_ec_device { bool mkbp_event_supported; struct blocking_notifier_head event_notifier; - struct ec_response_get_next_event event_data; + struct ec_response_get_next_event_v1 event_data; int event_size; u32 host_event_wake_mask; }; diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h index f2edd99..18df466 100644 --- a/include/linux/mfd/cros_ec_commands.h +++ b/include/linux/mfd/cros_ec_commands.h @@ -804,6 +804,8 @@ enum ec_feature_code { EC_FEATURE_MOTION_SENSE_FIFO = 24, /* EC has RTC feature that can be controlled by host commands */ EC_FEATURE_RTC = 27, + /* EC supports CEC commands */ + EC_FEATURE_CEC = 35, }; #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) @@ -2078,6 +2080,12 @@ enum ec_mkbp_event { /* EC sent a sysrq command */ EC_MKBP_EVENT_SYSRQ = 6, + /* Notify the AP that something happened on CEC */ + EC_MKBP_CEC_EVENT = 8, + + /* Send an incoming CEC message to the AP */ + EC_MKBP_EVENT_CEC_MESSAGE = 9, + /* Number of MKBP events */ EC_MKBP_EVENT_COUNT, }; @@ -2093,12 +2101,31 @@ union ec_response_get_next_data { uint32_t sysrq; } __packed; +union ec_response_get_next_data_v1 { + uint8_t key_matrix[16]; + + /* Unaligned */ + uint32_t host_event; + + uint32_t buttons; + uint32_t switches; + uint32_t sysrq; + uint32_t cec_events; + uint8_t cec_message[16]; +} __packed; + struct ec_response_get_next_event { uint8_t event_type; /* Followed by event data if any */ union ec_response_get_next_data data; } __packed; +struct ec_response_get_next_event_v1 { + uint8_t event_type; + /* Followed by event data if any */ + union ec_response_get_next_data_v1 data; +} __packed; + /* Bit indices for buttons and switches.*/ /* Buttons */ #define EC_MKBP_POWER_BUTTON 0 @@ -2828,6 +2855,59 @@ struct ec_params_reboot_ec { /* Current version of ACPI memory address space */ #define EC_ACPI_MEM_VERSION_CURRENT 1 +/*****************************************************************************/ +/* + * HDMI CEC commands + * + * These commands are for sending and receiving message via HDMI CEC + */ +#define MAX_CEC_MSG_LEN 16 + +/* CEC message from the AP to be written on the CEC bus */ +#define EC_CMD_CEC_WRITE_MSG 0x00B8 + +/* Message to write to the CEC bus */ +struct ec_params_cec_write { + uint8_t msg[MAX_CEC_MSG_LEN]; +} __packed; + +/* Set various CEC parameters */ +#define EC_CMD_CEC_SET 0x00BA + +struct ec_params_cec_set { + uint8_t cmd; /* enum cec_command */ + union { + uint8_t enable; + uint8_t address; + }; +} __packed; + +/* Read various CEC parameters */ +#define EC_CMD_CEC_GET 0x00BB + +struct ec_params_cec_get { + uint8_t cmd; /* enum cec_command */ +} __packed; + +struct ec_response_cec_get { + union { + uint8_t enable; + uint8_t address; + }; +} __packed; + +enum cec_command { + /* CEC reading, writing and events enable */ + CEC_CMD_ENABLE, + /* CEC logical address */ + CEC_CMD_LOGICAL_ADDRESS, +}; + +/* Events from CEC to AP */ +enum mkbp_cec_event { + EC_MKBP_CEC_SEND_OK = 1 << 0, + EC_MKBP_CEC_SEND_FAILED = 1 << 1, +}; /*****************************************************************************/ /* -- 2.7.4