Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp50523imm; Mon, 21 May 2018 02:00:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpt2Tc5gjfEgD7qZUvCjavE/L8CNWMR1AJ4BnXm7PcDxkM/c5GZy1eldcoSP1uAIym1qTws X-Received: by 2002:a62:ba09:: with SMTP id k9-v6mr19165043pff.245.1526893256194; Mon, 21 May 2018 02:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526893256; cv=none; d=google.com; s=arc-20160816; b=W+ryyFeZdfJMfZmNnsJprbrUAbK8HfB74G1wP59Pdculal9Lm6jKMaA7l7B7+tJWLA C0cQn1XNYIIt3JD76G4QF8ws1iPtMDWwWhcC9hifU202/qGe9YfJthMD4Jt/85hnfpDT N8Z+oW1wGVHYYnEP2hPSwMfOOqipGRCaP1rcdexxemYYkjUFZn7R37j1iDuoPL6nP5V5 y0UuMfUxSsYZ6Mx8xSLhqfQWw+xsCpzTxktlXkZXDzMCgx5EtVpkTjjd7PTrpCZk1Wby ZhPWuoyOxK8jnoRLT61PV0hHgnCzPjQoMWB9dDAdZyOkXewHUWtQUMMBjNtqjFrB7TKw RSJA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject:dkim-signature:arc-authentication-results; bh=QyeeAuiMqa9m1OoLIxlI2C++iKRftyn9cmsEOQAuykA=; b=DFm2AMqgRsaK5B/Av0MOVB+BHeHUsIizxsmjAWkdg5sQZ18BtA4ly/fuogGR7t/bCw yZgyr1F9Hril7uPpL33CyQLrKm372+g3nAMDY55PkohD77HhLoqo9YQ/wS00fSvZNlYn 33NfqzUXIdLDH6n/VWpejx7SR8ekczzrhsukgRnK0xgXzgA/NbXfPRRZ93yY955q+wdb pwupBnBJQJlJ/SYW5msW3JWAW1NEM2E7Hhov/Cl3xUHfD+OIrDn1gbAVWas87TgZjwGy 3AeTwmAKPo3AWVeQKZBTPA75JYC1VSuwDB6VA2A3PBas2/HYkr3uxiy+CdNBOPlziyvH E1tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=X++i2WKJ; 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 v10-v6si14416918plz.190.2018.05.21.02.00.41; Mon, 21 May 2018 02:00:56 -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=X++i2WKJ; 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 S1751141AbeEUJAZ (ORCPT + 99 others); Mon, 21 May 2018 05:00:25 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:54930 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbeEUJAW (ORCPT ); Mon, 21 May 2018 05:00:22 -0400 Received: by mail-wm0-f68.google.com with SMTP id f6-v6so23992458wmc.4 for ; Mon, 21 May 2018 02:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:openpgp:autocrypt:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=QyeeAuiMqa9m1OoLIxlI2C++iKRftyn9cmsEOQAuykA=; b=X++i2WKJ6I8FmsgMKKDj+O/7n+n/RDJpbgYdBhcPgtJH09c0/E+UIYHUxj5pwjFcbU en2y9cr1Aol8TnIUJ5KcqGLgjJgpVBJ4zLbv/EvUnRni0FFJ77+toioebf0jurrv2Y8/ ovYfkLlOuVdT6g6U0+SXu6UotwZ2m16lHDNBODTnja9KpCW6GZHXo2YN044+cj7FCb6/ Pvwr3vwlDVvarpoMb/qX0DrUqjhZpQJseE+bjhBhAVAa7i6UMcs5Th5onZ2/sUCxuBD9 CpdnohgnZj4Fm39S/nKX6O6ICVsh6s8rEcsf4y5Q2kVANd35ACm/cedSbEb2Sq7mnJpo aTNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=QyeeAuiMqa9m1OoLIxlI2C++iKRftyn9cmsEOQAuykA=; b=r4/WdT0JKFWpCxy8btjr9U8/kKeGk+jL+IyUI/ruY1K6UlbjjXcM2j0YSlURdqRQ6Z j18RE5JoInqd+EvWner5lkoIraeJ1ddAqZG5hSv9ovRdR3XaEPYp/xzhxDQgW7xoZ4jC iQypJUbM1LWuFN/jLjI26z/Gk2cy7qHJOUh4+M/ZEg2NL9gTlzKJymvWARdvWmXZJKGE 6GQkdZzu3hQ5LwxIM5mEnphBAw8BkNoSJ/hZg4x60LiErYQd1d1gY9/28engsk34ZrCS ITWwoWv3gvDQvdkoEViC76tE6cAA2k56eVji2T3UiS1WiAWNaVsNaxHZ86w0fbYdsELo 9SgQ== X-Gm-Message-State: ALKqPwd4/ObFeW0dW4cSbNBZ2h2145rJBlxY604B4o0Vj3ZaV3O/ti2a nCt3Lmsefe0e90DEBqB9Rmfehg== X-Received: by 2002:a1c:d546:: with SMTP id m67-v6mr11151008wmg.117.1526893220882; Mon, 21 May 2018 02:00:20 -0700 (PDT) Received: from ?IPv6:2a01:cb1d:4ce:ea00:748b:2433:2688:e1f? ([2a01:cb1d:4ce:ea00:748b:2433:2688:e1f]) by smtp.gmail.com with ESMTPSA id h81-v6sm24411620wmd.0.2018.05.21.02.00.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 May 2018 02:00:20 -0700 (PDT) Subject: Re: [PATCH v2 3/5] mfd: cros-ec: Introduce CEC commands and events definitions. To: Enric Balletbo Serra Cc: David Airlie , Hans Verkuil , Lee Jones , Olof Johansson , Sean Paul , sadolfsson@google.com, Felix Ekblom , Benson Leung , darekm@google.com, =?UTF-8?Q?St=c3=a9phane_Marchesin?= , Fabien Parent , dri-devel , linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-kernel , Stefan Adolfsson References: <1526648704-16873-1-git-send-email-narmstrong@baylibre.com> <1526648704-16873-4-git-send-email-narmstrong@baylibre.com> From: Neil Armstrong Openpgp: preference=signencrypt Autocrypt: addr=narmstrong@baylibre.com; prefer-encrypt=mutual; keydata= xsBNBE1ZBs8BCAD78xVLsXPwV/2qQx2FaO/7mhWL0Qodw8UcQJnkrWmgTFRobtTWxuRx8WWP GTjuhvbleoQ5Cxjr+v+1ARGCH46MxFP5DwauzPekwJUD5QKZlaw/bURTLmS2id5wWi3lqVH4 BVF2WzvGyyeV1o4RTCYDnZ9VLLylJ9bneEaIs/7cjCEbipGGFlfIML3sfqnIvMAxIMZrvcl9 qPV2k+KQ7q+aXavU5W+yLNn7QtXUB530Zlk/d2ETgzQ5FLYYnUDAaRl+8JUTjc0CNOTpCeik 80TZcE6f8M76Xa6yU8VcNko94Ck7iB4vj70q76P/J7kt98hklrr85/3NU3oti3nrIHmHABEB AAHNKE5laWwgQXJtc3Ryb25nIDxuYXJtc3Ryb25nQGJheWxpYnJlLmNvbT7CwHsEEwEKACUC GyMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheABQJXDO2CAhkBAAoJEBaat7Gkz/iubGIH/iyk Rqv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UsMYu4NzLu7uZF Acmp6h8g Organization: Baylibre Message-ID: <414f69e8-1d47-f5c8-4a09-7a1bbd6ffa33@baylibre.com> Date: Mon, 21 May 2018 11:00:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Enric, On 18/05/2018 18:19, Enric Balletbo Serra wrote: > Hi Neil, > > 2018-05-18 15:05 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 | 80 +++++++++++++++++++++++++++++++++ >> 3 files changed, 112 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; > > Personal opinion, but I don't like this static here, and also I don't > think this is scalable. Could we ask for the command version? I don't have an opinion, I only followed how it was implemented on the chromeos kernel and adapted to mainline. If you have a better way, I'll use it ! > >> 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; >> >> - 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; >> } >> > > So we always do a failed transfer on all these EC devices that does > not support CEC. I am wondering if wouldn't be better pass the command > version to the cros_ec_get_next_event function. The driver should know > which version to use, just a random idea. No, the driver cannot know the command version, this depends on the FW version and the platform. AFAIK this must be discovered. > >> + 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..16c3a2b 100644 >> --- a/include/linux/mfd/cros_ec_commands.h >> +++ b/include/linux/mfd/cros_ec_commands.h > > This file is going to be very big and as requested by Lee I plan to > convert this file to the kernel-doc format, this patch introduces some > new structs so could you document the new structs in the suggested > format? Ok > >> @@ -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, > > Use the BIT() macro. Ok > >> +}; >> >> /*****************************************************************************/ >> /* >> -- >> 2.7.4 >> > > Thanks, > Enric >