Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1284914imm; Tue, 22 May 2018 01:20:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdGkTibqwYyMLqfC0JYs/SzxLc3KKWFAgbHFW9ujAvv7k+M6xLGhRs4/icap7K1B0JdrMq X-Received: by 2002:a17:902:a703:: with SMTP id w3-v6mr2880392plq.111.1526977250174; Tue, 22 May 2018 01:20:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526977250; cv=none; d=google.com; s=arc-20160816; b=u1tHc6V7x7m9Tl9W2kKw7e+L5Bp9iljE1THyIQrlAcAzfVNBJ5t7HxL+VDXGzwttl3 D+1a7OzpZuHCm5w+OAEcdkSp8bgYXXBNJ89YLhvxoP0V+IPqHnEkmBuyxVYHI2+DP2nU F4ghNDfhG6UwNR8bVra/H9ZGWNFx7zImezFTuepyaFBXQFevjvDnTmknX+r9Tp2sYMDV jS6TSvAn6LZmYNVwYwgAue46HiKs05mSCzoXdQCWirYz8sjr36ulpyenE9ljBmShNav8 A9gvYQJF1TfNeQhLUA1Q5bFgZISVlhVufHXSqeeX/JGlX8iA8K/74RdwtHa7/iytivmf R3Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=5zVsjTMTbX5oGDf/3VwEJn45QcVShHByvVKsEDBuv3s=; b=mcrxQloz7kypuaCzfgkzWF3kKgmcV8yIGDKhtQZtu8KlMqmeIVXVfyDBJp3KqHwXhX 7i6Gwv0ySE1FTfm3klqdz2r+8JGw75gf96gersMl8+LljPJ5UtgunctgVQI6lOOAyGJT 16vYcIjeG/8o6Sj77wlxwQFZiovkEKuPIC4dp7ffpXzIDmJQzREmpEumwAjp8A+lY1UM EwdTwD0umktkqYCvUBvgkfTP3V8AaMycUOMdZrXg3N8SIQp8hsykNSGThcTbOVJwSYTl XqnecmHbyVQyr9iS7eLhI0frsd+xIEs1ephqunJByPIDDFIbK5n4tw2DAd6/jzcxXTst zBGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NG2BXHf0; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9-v6si15801926plk.587.2018.05.22.01.20.35; Tue, 22 May 2018 01:20:50 -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=@gmail.com header.s=20161025 header.b=NG2BXHf0; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751763AbeEVIUN (ORCPT + 99 others); Tue, 22 May 2018 04:20:13 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:41785 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751592AbeEVIUG (ORCPT ); Tue, 22 May 2018 04:20:06 -0400 Received: by mail-qt0-f195.google.com with SMTP id g13-v6so22320150qth.8; Tue, 22 May 2018 01:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5zVsjTMTbX5oGDf/3VwEJn45QcVShHByvVKsEDBuv3s=; b=NG2BXHf09cH7Enugl31U6C2+SL4MQp1/1auPt6wklAmyhjDWCHK//7rk9JOeYOLTZS jKzzqi7i/gFr8YHlXHpVAdGE7a9azvE2mKMBljkhRKh42tE0RjOckkc5VLUuJS2g0Kjp uurd/18oxeKrGZTy+WnjfgWHW7Am6evfz0JiiwJJb8nT7++GBqArPoZQ+bS0lcfrKEPU e4iEqXeeYzL3E70Q9KVRQyZwiC5yogV19MPV4BDqqqYrmHTOHIv3iwNXLtANvZWK+2Xa 34lFEuHN2/3Kr9EzDOu6PR0pzWvIlm8FQ0yoKKojoPKTEnnt4KBW/II9uzQAhopWRGLZ 4Vwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5zVsjTMTbX5oGDf/3VwEJn45QcVShHByvVKsEDBuv3s=; b=SbvC9WWg9kG07EWt9xLhp24o4JBvXXJ29O3UQgAzmHl6kLhmi94lm+a5UmospqOvhx xSu1wFNhYj42YDi9XxHEZi+jY+av3C0Kt+HctMK5k/HM0N7AY0RFINZOXKqZpUOx+MkK HAj/V1aaV70bllD8BS0RlggxhXGibHhNjLX7oAqeuRt5/vKYdSP4+zwbY0v6W1s8hbnP tjo87qqEsQyDy2WBKoFOD91lwsp4CAXKmo/ktDnvznpOEXyIFGKe2X0U1s1gFovtao9O JZUo/E2J1w20w7GsQL+m724v/NSTTGoS4LAi19Kx+BKYrZXufC6vX+Gq2xjrDA16JYQV nncA== X-Gm-Message-State: ALKqPwentYUWdAogVZiB1qANmW6VarWTqgHbi2E0jo4cjK4vT47hps/G hhqgh50QvbdATAmUV2zQvsgTwK9FFJReBnD3GWs= X-Received: by 2002:ac8:17b2:: with SMTP id o47-v6mr7792603qtj.176.1526977205926; Tue, 22 May 2018 01:20:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.237.58.170 with HTTP; Tue, 22 May 2018 01:20:05 -0700 (PDT) In-Reply-To: <1526912506-18406-4-git-send-email-narmstrong@baylibre.com> References: <1526912506-18406-1-git-send-email-narmstrong@baylibre.com> <1526912506-18406-4-git-send-email-narmstrong@baylibre.com> From: Enric Balletbo Serra Date: Tue, 22 May 2018 10:20:05 +0200 Message-ID: Subject: Re: [PATCH v4 3/5] mfd: cros-ec: Introduce CEC commands and events definitions. To: Neil Armstrong Cc: David Airlie , Hans Verkuil , Lee Jones , Olof Johansson , Sean Paul , sadolfsson@google.com, intel-gfx@lists.freedesktop.org, linux-kernel , dri-devel , Stefan Adolfsson , Fabien Parent , Felix Ekblom , =?UTF-8?Q?St=C3=A9phane_Marchesin?= , Benson Leung , darekm@google.com, linux-media@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Neil, 2018-05-21 16:21 GMT+02:00 Neil Armstrong : > 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 | 40 ++++++++++--- > include/linux/mfd/cros_ec.h | 2 +- > include/linux/mfd/cros_ec_commands.h | 103 ++++++++++++++++++++++++++++++++ > 3 files changed, 135 insertions(+), 10 deletions(-) > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > index e7bbdf9..c4f6c44 100644 > --- a/drivers/platform/chrome/cros_ec_proto.c > +++ b/drivers/platform/chrome/cros_ec_proto.c > @@ -504,10 +504,31 @@ 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, ec_dev->event_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; > > if (ec_dev->suspended) { > @@ -515,18 +536,19 @@ static int get_next_event(struct cros_ec_device *ec_dev) > 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(struct ec_response_get_next_event_v1)); > + if (ret < 0 || msg->result != EC_RES_INVALID_VERSION) > + return ret; > Thinking a bit more, there is a command to ask supported command versions (EC_CMD_GET_CMD_VERSION). So, i theory you should be able to ask for the versions supported by the command, see for example what is done in [1], [2] and [3]. Anyway I am fine with this for now, and after do some test seems that nothing breaks, so Tested-by: Enric Balletbo i Serra Thanks, Enric [1] https://chromium.googlesource.com/chromiumos/platform/ec/+/master/util/misc_util.c#98 [2] https://chromium.googlesource.com/chromiumos/platform/ec/+/master/util/misc_util.c#131 [3] https://chromium.googlesource.com/chromiumos/platform/ec/+/master/util/ectool.c#786 > - 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 f36125e..32caef3 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..9b8bc4a 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,82 @@ 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 > + > +/** > + * struct ec_params_cec_write - Message to write to the CEC bus > + * @msg: message content 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 - CEC parameters set > + * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS > + * @enable: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC > + * or 1 to enable CEC functionnality > + * @address: in case cmd is CEC_CMD_LOGICAL_ADDRESS, this field encodes the > + * requested logical address between 0 and 15 or 0xff to unregister > + */ > +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 - CEC parameters get > + * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS > + */ > +struct ec_params_cec_get { > + uint8_t cmd; /* enum cec_command */ > +} __packed; > + > +/** > + * struct ec_response_cec_get - CEC parameters get response > + * @enable: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is > + * disabled or 1 if CEC functionnality is enabled > + * @address: in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the > + * configured logical address between 0 and 15 or 0xff if unregistered > + */ > +struct ec_response_cec_get { > + union { > + uint8_t enable; > + uint8_t address; > + }; > +} __packed; > + > +/* CEC parameters command */ > +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 = BIT(0), > + EC_MKBP_CEC_SEND_FAILED = BIT(1), > +}; > > /*****************************************************************************/ > /* > -- > 2.7.4 > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel