提交 5b744981 编写于 作者: L Linus Torvalds

Merge tag 'tag-chrome-platform-for-v4.20' of...

Merge tag 'tag-chrome-platform-for-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/bleung/chrome-platform

Pull chrome-platform updates from Benson Leung:

 - Move mfd/cros_ec_lpc* includes to drivers/platform from mfd

 - Adding a new interrupt path for cros_ec_lpc

* tag 'tag-chrome-platform-for-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/bleung/chrome-platform:
  platform/chrome: chromeos_tbmc - Remove unneeded const
  platform/chrome: Add a new interrupt path for cros_ec_lpc
  mfd: cros_ec: Fix and improve kerneldoc comments.
  platform/chrome: Move mfd/cros_ec_lpc* includes to drivers/platform.
...@@ -26,12 +26,13 @@ ...@@ -26,12 +26,13 @@
#define CROS_EC_DEV_VERSION "1.0.0" #define CROS_EC_DEV_VERSION "1.0.0"
/* /**
* @offset: within EC_LPC_ADDR_MEMMAP region * struct cros_ec_readmem - Struct used to read mapped memory.
* @bytes: number of bytes to read. zero means "read a string" (including '\0') * @offset: Within EC_LPC_ADDR_MEMMAP region.
* (at most only EC_MEMMAP_SIZE bytes can be read) * @bytes: Number of bytes to read. Zero means "read a string" (including '\0')
* @buffer: where to store the result * At most only EC_MEMMAP_SIZE bytes can be read.
* ioctl returns the number of bytes read, negative on error * @buffer: Where to store the result. The ioctl returns the number of bytes
* read or negative on error.
*/ */
struct cros_ec_readmem { struct cros_ec_readmem {
uint32_t offset; uint32_t offset;
......
...@@ -99,7 +99,7 @@ static const struct acpi_device_id chromeos_tbmc_acpi_device_ids[] = { ...@@ -99,7 +99,7 @@ static const struct acpi_device_id chromeos_tbmc_acpi_device_ids[] = {
}; };
MODULE_DEVICE_TABLE(acpi, chromeos_tbmc_acpi_device_ids); MODULE_DEVICE_TABLE(acpi, chromeos_tbmc_acpi_device_ids);
static const SIMPLE_DEV_PM_OPS(chromeos_tbmc_pm_ops, NULL, static SIMPLE_DEV_PM_OPS(chromeos_tbmc_pm_ops, NULL,
chromeos_tbmc_resume); chromeos_tbmc_resume);
static struct acpi_driver chromeos_tbmc_driver = { static struct acpi_driver chromeos_tbmc_driver = {
......
...@@ -25,14 +25,16 @@ ...@@ -25,14 +25,16 @@
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/interrupt.h>
#include <linux/mfd/cros_ec.h> #include <linux/mfd/cros_ec.h>
#include <linux/mfd/cros_ec_commands.h> #include <linux/mfd/cros_ec_commands.h>
#include <linux/mfd/cros_ec_lpc_reg.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/printk.h> #include <linux/printk.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include "cros_ec_lpc_reg.h"
#define DRV_NAME "cros_ec_lpcs" #define DRV_NAME "cros_ec_lpcs"
#define ACPI_DRV_NAME "GOOG0004" #define ACPI_DRV_NAME "GOOG0004"
...@@ -248,7 +250,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) ...@@ -248,7 +250,7 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
acpi_status status; acpi_status status;
struct cros_ec_device *ec_dev; struct cros_ec_device *ec_dev;
u8 buf[2]; u8 buf[2];
int ret; int irq, ret;
if (!devm_request_region(dev, EC_LPC_ADDR_MEMMAP, EC_MEMMAP_SIZE, if (!devm_request_region(dev, EC_LPC_ADDR_MEMMAP, EC_MEMMAP_SIZE,
dev_name(dev))) { dev_name(dev))) {
...@@ -287,6 +289,18 @@ static int cros_ec_lpc_probe(struct platform_device *pdev) ...@@ -287,6 +289,18 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
sizeof(struct ec_response_get_protocol_info); sizeof(struct ec_response_get_protocol_info);
ec_dev->dout_size = sizeof(struct ec_host_request); ec_dev->dout_size = sizeof(struct ec_host_request);
/*
* Some boards do not have an IRQ allotted for cros_ec_lpc,
* which makes ENXIO an expected (and safe) scenario.
*/
irq = platform_get_irq(pdev, 0);
if (irq > 0)
ec_dev->irq = irq;
else if (irq != -ENXIO) {
dev_err(dev, "couldn't retrieve IRQ number (%d)\n", irq);
return irq;
}
ret = cros_ec_register(ec_dev); ret = cros_ec_register(ec_dev);
if (ret) { if (ret) {
dev_err(dev, "couldn't register ec_dev (%d)\n", ret); dev_err(dev, "couldn't register ec_dev (%d)\n", ret);
......
...@@ -24,10 +24,11 @@ ...@@ -24,10 +24,11 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/mfd/cros_ec_commands.h> #include <linux/mfd/cros_ec_commands.h>
#include <linux/mfd/cros_ec_lpc_mec.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/types.h> #include <linux/types.h>
#include "cros_ec_lpc_mec.h"
/* /*
* This mutex must be held while accessing the EMI unit. We can't rely on the * This mutex must be held while accessing the EMI unit. We can't rely on the
* EC mutex because memmap data may be accessed without it being held. * EC mutex because memmap data may be accessed without it being held.
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
* expensive. * expensive.
*/ */
#ifndef __LINUX_MFD_CROS_EC_MEC_H #ifndef __CROS_EC_LPC_MEC_H
#define __LINUX_MFD_CROS_EC_MEC_H #define __CROS_EC_LPC_MEC_H
#include <linux/mfd/cros_ec_commands.h> #include <linux/mfd/cros_ec_commands.h>
...@@ -87,4 +87,4 @@ void cros_ec_lpc_mec_destroy(void); ...@@ -87,4 +87,4 @@ void cros_ec_lpc_mec_destroy(void);
u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type, u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type,
unsigned int offset, unsigned int length, u8 *buf); unsigned int offset, unsigned int length, u8 *buf);
#endif /* __LINUX_MFD_CROS_EC_MEC_H */ #endif /* __CROS_EC_LPC_MEC_H */
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/mfd/cros_ec.h> #include <linux/mfd/cros_ec.h>
#include <linux/mfd/cros_ec_commands.h> #include <linux/mfd/cros_ec_commands.h>
#include <linux/mfd/cros_ec_lpc_mec.h>
#include "cros_ec_lpc_mec.h"
static u8 lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest) static u8 lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest)
{ {
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
* expensive. * expensive.
*/ */
#ifndef __LINUX_MFD_CROS_EC_REG_H #ifndef __CROS_EC_LPC_REG_H
#define __LINUX_MFD_CROS_EC_REG_H #define __CROS_EC_LPC_REG_H
/** /**
* cros_ec_lpc_read_bytes - Read bytes from a given LPC-mapped address. * cros_ec_lpc_read_bytes - Read bytes from a given LPC-mapped address.
...@@ -58,4 +58,4 @@ void cros_ec_lpc_reg_init(void); ...@@ -58,4 +58,4 @@ void cros_ec_lpc_reg_init(void);
*/ */
void cros_ec_lpc_reg_destroy(void); void cros_ec_lpc_reg_destroy(void);
#endif /* __LINUX_MFD_CROS_EC_REG_H */ #endif /* __CROS_EC_LPC_REG_H */
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* I2C requires 1 additional byte for requests. * I2C requires 1 additional byte for requests.
* I2C requires 2 additional bytes for responses. * I2C requires 2 additional bytes for responses.
* SPI requires up to 32 additional bytes for responses. * SPI requires up to 32 additional bytes for responses.
* */ */
#define EC_PROTO_VERSION_UNKNOWN 0 #define EC_PROTO_VERSION_UNKNOWN 0
#define EC_MAX_REQUEST_OVERHEAD 1 #define EC_MAX_REQUEST_OVERHEAD 1
#define EC_MAX_RESPONSE_OVERHEAD 32 #define EC_MAX_RESPONSE_OVERHEAD 32
...@@ -58,13 +58,14 @@ enum { ...@@ -58,13 +58,14 @@ enum {
EC_MAX_MSG_BYTES = 64 * 1024, EC_MAX_MSG_BYTES = 64 * 1024,
}; };
/* /**
* @version: Command version number (often 0) * struct cros_ec_command - Information about a ChromeOS EC command.
* @command: Command to send (EC_CMD_...) * @version: Command version number (often 0).
* @outsize: Outgoing length in bytes * @command: Command to send (EC_CMD_...).
* @insize: Max number of bytes to accept from EC * @outsize: Outgoing length in bytes.
* @result: EC's response to the command (separate from communication failure) * @insize: Max number of bytes to accept from the EC.
* @data: Where to put the incoming data from EC and outgoing data to EC * @result: EC's response to the command (separate from communication failure).
* @data: Where to put the incoming data from EC and outgoing data to EC.
*/ */
struct cros_ec_command { struct cros_ec_command {
uint32_t version; uint32_t version;
...@@ -76,48 +77,55 @@ struct cros_ec_command { ...@@ -76,48 +77,55 @@ struct cros_ec_command {
}; };
/** /**
* struct cros_ec_device - Information about a ChromeOS EC device * struct cros_ec_device - Information about a ChromeOS EC device.
* * @phys_name: Name of physical comms layer (e.g. 'i2c-4').
* @phys_name: name of physical comms layer (e.g. 'i2c-4')
* @dev: Device pointer for physical comms device * @dev: Device pointer for physical comms device
* @was_wake_device: true if this device was set to wake the system from * @was_wake_device: True if this device was set to wake the system from
* sleep at the last suspend * sleep at the last suspend.
* @cmd_readmem: direct read of the EC memory-mapped region, if supported * @cros_class: The class structure for this device.
* @offset is within EC_LPC_ADDR_MEMMAP region. * @cmd_readmem: Direct read of the EC memory-mapped region, if supported.
* @bytes: number of bytes to read. zero means "read a string" (including * @offset: Is within EC_LPC_ADDR_MEMMAP region.
* the trailing '\0'). At most only EC_MEMMAP_SIZE bytes can be read. * @bytes: Number of bytes to read. zero means "read a string" (including
* Caller must ensure that the buffer is large enough for the result when * the trailing '\0'). At most only EC_MEMMAP_SIZE bytes can be
* reading a string. * read. Caller must ensure that the buffer is large enough for the
* * result when reading a string.
* @priv: Private data * @max_request: Max size of message requested.
* @irq: Interrupt to use * @max_response: Max size of message response.
* @id: Device id * @max_passthru: Max sice of passthru message.
* @din: input buffer (for data from EC) * @proto_version: The protocol version used for this device.
* @dout: output buffer (for data to EC) * @priv: Private data.
* \note * @irq: Interrupt to use.
* These two buffers will always be dword-aligned and include enough * @id: Device id.
* space for up to 7 word-alignment bytes also, so we can ensure that * @din: Input buffer (for data from EC). This buffer will always be
* the body of the message is always dword-aligned (64-bit). * dword-aligned and include enough space for up to 7 word-alignment
* We use this alignment to keep ARM and x86 happy. Probably word * bytes also, so we can ensure that the body of the message is always
* alignment would be OK, there might be a small performance advantage * dword-aligned (64-bit). We use this alignment to keep ARM and x86
* to using dword. * happy. Probably word alignment would be OK, there might be a small
* @din_size: size of din buffer to allocate (zero to use static din) * performance advantage to using dword.
* @dout_size: size of dout buffer to allocate (zero to use static dout) * @dout: Output buffer (for data to EC). This buffer will always be
* @wake_enabled: true if this device can wake the system from sleep * dword-aligned and include enough space for up to 7 word-alignment
* @suspended: true if this device had been suspended * bytes also, so we can ensure that the body of the message is always
* @cmd_xfer: send command to EC and get response * dword-aligned (64-bit). We use this alignment to keep ARM and x86
* Returns the number of bytes received if the communication succeeded, but * happy. Probably word alignment would be OK, there might be a small
* that doesn't mean the EC was happy with the command. The caller * performance advantage to using dword.
* should check msg.result for the EC's result code. * @din_size: Size of din buffer to allocate (zero to use static din).
* @pkt_xfer: send packet to EC and get response * @dout_size: Size of dout buffer to allocate (zero to use static dout).
* @lock: one transaction at a time * @wake_enabled: True if this device can wake the system from sleep.
* @mkbp_event_supported: true if this EC supports the MKBP event protocol. * @suspended: True if this device had been suspended.
* @event_notifier: interrupt event notifier for transport devices. * @cmd_xfer: Send command to EC and get response.
* @event_data: raw payload transferred with the MKBP event. * Returns the number of bytes received if the communication
* @event_size: size in bytes of the event data. * succeeded, but that doesn't mean the EC was happy with the
* command. The caller should check msg.result for the EC's result
* code.
* @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.
* @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.
* @host_event_wake_mask: Mask of host events that cause wake from suspend.
*/ */
struct cros_ec_device { struct cros_ec_device {
/* These are used by other drivers that want to talk to the EC */ /* These are used by other drivers that want to talk to the EC */
const char *phys_name; const char *phys_name;
struct device *dev; struct device *dev;
...@@ -153,20 +161,19 @@ struct cros_ec_device { ...@@ -153,20 +161,19 @@ struct cros_ec_device {
}; };
/** /**
* struct cros_ec_sensor_platform - ChromeOS EC sensor platform information * struct cros_ec_sensor_platform - ChromeOS EC sensor platform information.
*
* @sensor_num: Id of the sensor, as reported by the EC. * @sensor_num: Id of the sensor, as reported by the EC.
*/ */
struct cros_ec_sensor_platform { struct cros_ec_sensor_platform {
u8 sensor_num; u8 sensor_num;
}; };
/* struct cros_ec_platform - ChromeOS EC platform information /**
* * struct cros_ec_platform - ChromeOS EC platform information.
* @ec_name: name of EC device (e.g. 'cros-ec', 'cros-pd', ...) * @ec_name: Name of EC device (e.g. 'cros-ec', 'cros-pd', ...)
* used in /dev/ and sysfs. * used in /dev/ and sysfs.
* @cmd_offset: offset to apply for each command. Set when * @cmd_offset: Offset to apply for each command. Set when
* registering a devicde behind another one. * registering a device behind another one.
*/ */
struct cros_ec_platform { struct cros_ec_platform {
const char *ec_name; const char *ec_name;
...@@ -175,16 +182,16 @@ struct cros_ec_platform { ...@@ -175,16 +182,16 @@ struct cros_ec_platform {
struct cros_ec_debugfs; struct cros_ec_debugfs;
/* /**
* struct cros_ec_dev - ChromeOS EC device entry point * struct cros_ec_dev - ChromeOS EC device entry point.
* * @class_dev: Device structure used in sysfs.
* @class_dev: Device structure used in sysfs * @cdev: Character device structure in /dev.
* @cdev: Character device structure in /dev * @ec_dev: cros_ec_device structure to talk to the physical device.
* @ec_dev: cros_ec_device structure to talk to the physical device * @dev: Pointer to the platform device.
* @dev: pointer to the platform device * @debug_info: cros_ec_debugfs structure for debugging information.
* @debug_info: cros_ec_debugfs structure for debugging information * @has_kb_wake_angle: True if at least 2 accelerometer are connected to the EC.
* @has_kb_wake_angle: true if at least 2 accelerometer are connected to the EC. * @cmd_offset: Offset to apply for each command.
* @cmd_offset: offset to apply for each command. * @features: Features supported by the EC.
*/ */
struct cros_ec_dev { struct cros_ec_dev {
struct device class_dev; struct device class_dev;
...@@ -200,124 +207,129 @@ struct cros_ec_dev { ...@@ -200,124 +207,129 @@ struct cros_ec_dev {
#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev) #define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
/** /**
* cros_ec_suspend - Handle a suspend operation for the ChromeOS EC device * cros_ec_suspend() - Handle a suspend operation for the ChromeOS EC device.
* @ec_dev: Device to suspend.
* *
* This can be called by drivers to handle a suspend event. * This can be called by drivers to handle a suspend event.
* *
* ec_dev: Device to suspend * Return: 0 on success or negative error code.
* @return 0 if ok, -ve on error
*/ */
int cros_ec_suspend(struct cros_ec_device *ec_dev); int cros_ec_suspend(struct cros_ec_device *ec_dev);
/** /**
* cros_ec_resume - Handle a resume operation for the ChromeOS EC device * cros_ec_resume() - Handle a resume operation for the ChromeOS EC device.
* @ec_dev: Device to resume.
* *
* This can be called by drivers to handle a resume event. * This can be called by drivers to handle a resume event.
* *
* @ec_dev: Device to resume * Return: 0 on success or negative error code.
* @return 0 if ok, -ve on error
*/ */
int cros_ec_resume(struct cros_ec_device *ec_dev); int cros_ec_resume(struct cros_ec_device *ec_dev);
/** /**
* cros_ec_prepare_tx - Prepare an outgoing message in the output buffer * cros_ec_prepare_tx() - Prepare an outgoing message in the output buffer.
* @ec_dev: Device to register.
* @msg: Message to write.
* *
* This is intended to be used by all ChromeOS EC drivers, but at present * This is intended to be used by all ChromeOS EC drivers, but at present
* only SPI uses it. Once LPC uses the same protocol it can start using it. * only SPI uses it. Once LPC uses the same protocol it can start using it.
* I2C could use it now, with a refactor of the existing code. * I2C could use it now, with a refactor of the existing code.
* *
* @ec_dev: Device to register * Return: 0 on success or negative error code.
* @msg: Message to write
*/ */
int cros_ec_prepare_tx(struct cros_ec_device *ec_dev, int cros_ec_prepare_tx(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg); struct cros_ec_command *msg);
/** /**
* cros_ec_check_result - Check ec_msg->result * cros_ec_check_result() - Check ec_msg->result.
* @ec_dev: EC device.
* @msg: Message to check.
* *
* This is used by ChromeOS EC drivers to check the ec_msg->result for * This is used by ChromeOS EC drivers to check the ec_msg->result for
* errors and to warn about them. * errors and to warn about them.
* *
* @ec_dev: EC device * Return: 0 on success or negative error code.
* @msg: Message to check
*/ */
int cros_ec_check_result(struct cros_ec_device *ec_dev, int cros_ec_check_result(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg); struct cros_ec_command *msg);
/** /**
* cros_ec_cmd_xfer - Send a command to the ChromeOS EC * cros_ec_cmd_xfer() - Send a command to the ChromeOS EC.
* @ec_dev: EC device.
* @msg: Message to write.
* *
* Call this to send a command to the ChromeOS EC. This should be used * Call this to send a command to the ChromeOS EC. This should be used
* instead of calling the EC's cmd_xfer() callback directly. * instead of calling the EC's cmd_xfer() callback directly.
* *
* @ec_dev: EC device * Return: 0 on success or negative error code.
* @msg: Message to write
*/ */
int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg); struct cros_ec_command *msg);
/** /**
* cros_ec_cmd_xfer_status - Send a command to the ChromeOS EC * cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
* @ec_dev: EC device.
* @msg: Message to write.
* *
* This function is identical to cros_ec_cmd_xfer, except it returns success * This function is identical to cros_ec_cmd_xfer, except it returns success
* status only if both the command was transmitted successfully and the EC * status only if both the command was transmitted successfully and the EC
* replied with success status. It's not necessary to check msg->result when * replied with success status. It's not necessary to check msg->result when
* using this function. * using this function.
* *
* @ec_dev: EC device * Return: The number of bytes transferred on success or negative error code.
* @msg: Message to write
* @return: Num. of bytes transferred on success, <0 on failure
*/ */
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev, int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg); struct cros_ec_command *msg);
/** /**
* cros_ec_remove - Remove a ChromeOS EC * cros_ec_remove() - Remove a ChromeOS EC.
* @ec_dev: Device to register.
* *
* Call this to deregister a ChromeOS EC, then clean up any private data. * Call this to deregister a ChromeOS EC, then clean up any private data.
* *
* @ec_dev: Device to register * Return: 0 on success or negative error code.
* @return 0 if ok, -ve on error
*/ */
int cros_ec_remove(struct cros_ec_device *ec_dev); int cros_ec_remove(struct cros_ec_device *ec_dev);
/** /**
* cros_ec_register - Register a new ChromeOS EC, using the provided info * cros_ec_register() - Register a new ChromeOS EC, using the provided info.
* @ec_dev: Device to register.
* *
* Before calling this, allocate a pointer to a new device and then fill * Before calling this, allocate a pointer to a new device and then fill
* in all the fields up to the --private-- marker. * in all the fields up to the --private-- marker.
* *
* @ec_dev: Device to register * Return: 0 on success or negative error code.
* @return 0 if ok, -ve on error
*/ */
int cros_ec_register(struct cros_ec_device *ec_dev); int cros_ec_register(struct cros_ec_device *ec_dev);
/** /**
* cros_ec_query_all - Query the protocol version supported by the ChromeOS EC * cros_ec_query_all() - Query the protocol version supported by the
* ChromeOS EC.
* @ec_dev: Device to register.
* *
* @ec_dev: Device to register * Return: 0 on success or negative error code.
* @return 0 if ok, -ve on error
*/ */
int cros_ec_query_all(struct cros_ec_device *ec_dev); int cros_ec_query_all(struct cros_ec_device *ec_dev);
/** /**
* cros_ec_get_next_event - Fetch next event from the ChromeOS EC * cros_ec_get_next_event() - Fetch next event from the ChromeOS EC.
* * @ec_dev: Device to fetch event from.
* @ec_dev: Device to fetch event from
* @wake_event: Pointer to a bool set to true upon return if the event might be * @wake_event: Pointer to a bool set to true upon return if the event might be
* treated as a wake event. Ignored if null. * treated as a wake event. Ignored if null.
* *
* Returns: 0 on success, Linux error number on failure * Return: 0 on success or negative error code.
*/ */
int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
/** /**
* cros_ec_get_host_event - Return a mask of event set by the EC. * cros_ec_get_host_event() - Return a mask of event set by the ChromeOS EC.
* @ec_dev: Device to fetch event from.
* *
* When MKBP is supported, when the EC raises an interrupt, * When MKBP is supported, when the EC raises an interrupt, we collect the
* We collect the events raised and call the functions in the ec notifier. * events raised and call the functions in the ec notifier. This function
* is a helper to know which events are raised.
* *
* This function is a helper to know which events are raised. * Return: 0 on success or negative error code.
*/ */
u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
......
...@@ -306,15 +306,18 @@ enum host_event_code { ...@@ -306,15 +306,18 @@ enum host_event_code {
/* Host event mask */ /* Host event mask */
#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1)) #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
/* Arguments at EC_LPC_ADDR_HOST_ARGS */ /**
* struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
* @flags: The host argument flags.
* @command_version: Command version.
* @data_size: The length of data.
* @checksum: Checksum; sum of command + flags + command_version + data_size +
* all params/response data bytes.
*/
struct ec_lpc_host_args { struct ec_lpc_host_args {
uint8_t flags; uint8_t flags;
uint8_t command_version; uint8_t command_version;
uint8_t data_size; uint8_t data_size;
/*
* Checksum; sum of command + flags + command_version + data_size +
* all params/response data bytes.
*/
uint8_t checksum; uint8_t checksum;
} __packed; } __packed;
...@@ -468,54 +471,43 @@ struct ec_lpc_host_args { ...@@ -468,54 +471,43 @@ struct ec_lpc_host_args {
#define EC_HOST_REQUEST_VERSION 3 #define EC_HOST_REQUEST_VERSION 3
/* Version 3 request from host */ /**
struct ec_host_request { * struct ec_host_request - Version 3 request from host.
/* Struct version (=3) * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
* * receives a header with a version it doesn't know how to
* EC will return EC_RES_INVALID_HEADER if it receives a header with a * parse.
* version it doesn't know how to parse. * @checksum: Checksum of request and data; sum of all bytes including checksum
*/
uint8_t struct_version;
/*
* Checksum of request and data; sum of all bytes including checksum
* should total to 0. * should total to 0.
* @command: Command to send (EC_CMD_...)
* @command_version: Command version.
* @reserved: Unused byte in current protocol version; set to 0.
* @data_len: Length of data which follows this header.
*/ */
struct ec_host_request {
uint8_t struct_version;
uint8_t checksum; uint8_t checksum;
/* Command code */
uint16_t command; uint16_t command;
/* Command version */
uint8_t command_version; uint8_t command_version;
/* Unused byte in current protocol version; set to 0 */
uint8_t reserved; uint8_t reserved;
/* Length of data which follows this header */
uint16_t data_len; uint16_t data_len;
} __packed; } __packed;
#define EC_HOST_RESPONSE_VERSION 3 #define EC_HOST_RESPONSE_VERSION 3
/* Version 3 response from EC */ /**
* struct ec_host_response - Version 3 response from EC.
* @struct_version: Struct version (=3).
* @checksum: Checksum of response and data; sum of all bytes including
* checksum should total to 0.
* @result: EC's response to the command (separate from communication failure)
* @data_len: Length of data which follows this header.
* @reserved: Unused bytes in current protocol version; set to 0.
*/
struct ec_host_response { struct ec_host_response {
/* Struct version (=3) */
uint8_t struct_version; uint8_t struct_version;
/*
* Checksum of response and data; sum of all bytes including checksum
* should total to 0.
*/
uint8_t checksum; uint8_t checksum;
/* Result code (EC_RES_*) */
uint16_t result; uint16_t result;
/* Length of data which follows this header */
uint16_t data_len; uint16_t data_len;
/* Unused bytes in current protocol version; set to 0 */
uint16_t reserved; uint16_t reserved;
} __packed; } __packed;
...@@ -540,6 +532,10 @@ struct ec_host_response { ...@@ -540,6 +532,10 @@ struct ec_host_response {
*/ */
#define EC_CMD_PROTO_VERSION 0x00 #define EC_CMD_PROTO_VERSION 0x00
/**
* struct ec_response_proto_version - Response to the proto version command.
* @version: The protocol version.
*/
struct ec_response_proto_version { struct ec_response_proto_version {
uint32_t version; uint32_t version;
} __packed; } __packed;
...@@ -550,12 +546,20 @@ struct ec_response_proto_version { ...@@ -550,12 +546,20 @@ struct ec_response_proto_version {
*/ */
#define EC_CMD_HELLO 0x01 #define EC_CMD_HELLO 0x01
/**
* struct ec_params_hello - Parameters to the hello command.
* @in_data: Pass anything here.
*/
struct ec_params_hello { struct ec_params_hello {
uint32_t in_data; /* Pass anything here */ uint32_t in_data;
} __packed; } __packed;
/**
* struct ec_response_hello - Response to the hello command.
* @out_data: Output will be in_data + 0x01020304.
*/
struct ec_response_hello { struct ec_response_hello {
uint32_t out_data; /* Output will be in_data + 0x01020304 */ uint32_t out_data;
} __packed; } __packed;
/* Get version number */ /* Get version number */
...@@ -567,22 +571,37 @@ enum ec_current_image { ...@@ -567,22 +571,37 @@ enum ec_current_image {
EC_IMAGE_RW EC_IMAGE_RW
}; };
/**
* struct ec_response_get_version - Response to the get version command.
* @version_string_ro: Null-terminated RO firmware version string.
* @version_string_rw: Null-terminated RW firmware version string.
* @reserved: Unused bytes; was previously RW-B firmware version string.
* @current_image: One of ec_current_image.
*/
struct ec_response_get_version { struct ec_response_get_version {
/* Null-terminated version strings for RO, RW */
char version_string_ro[32]; char version_string_ro[32];
char version_string_rw[32]; char version_string_rw[32];
char reserved[32]; /* Was previously RW-B string */ char reserved[32];
uint32_t current_image; /* One of ec_current_image */ uint32_t current_image;
} __packed; } __packed;
/* Read test */ /* Read test */
#define EC_CMD_READ_TEST 0x03 #define EC_CMD_READ_TEST 0x03
/**
* struct ec_params_read_test - Parameters for the read test command.
* @offset: Starting value for read buffer.
* @size: Size to read in bytes.
*/
struct ec_params_read_test { struct ec_params_read_test {
uint32_t offset; /* Starting value for read buffer */ uint32_t offset;
uint32_t size; /* Size to read in bytes */ uint32_t size;
} __packed; } __packed;
/**
* struct ec_response_read_test - Response to the read test command.
* @data: Data returned by the read test command.
*/
struct ec_response_read_test { struct ec_response_read_test {
uint32_t data[32]; uint32_t data[32];
} __packed; } __packed;
...@@ -597,18 +616,27 @@ struct ec_response_read_test { ...@@ -597,18 +616,27 @@ struct ec_response_read_test {
/* Get chip info */ /* Get chip info */
#define EC_CMD_GET_CHIP_INFO 0x05 #define EC_CMD_GET_CHIP_INFO 0x05
/**
* struct ec_response_get_chip_info - Response to the get chip info command.
* @vendor: Null-terminated string for chip vendor.
* @name: Null-terminated string for chip name.
* @revision: Null-terminated string for chip mask version.
*/
struct ec_response_get_chip_info { struct ec_response_get_chip_info {
/* Null-terminated strings */
char vendor[32]; char vendor[32];
char name[32]; char name[32];
char revision[32]; /* Mask version */ char revision[32];
} __packed; } __packed;
/* Get board HW version */ /* Get board HW version */
#define EC_CMD_GET_BOARD_VERSION 0x06 #define EC_CMD_GET_BOARD_VERSION 0x06
/**
* struct ec_response_board_version - Response to the board version command.
* @board_version: A monotonously incrementing number.
*/
struct ec_response_board_version { struct ec_response_board_version {
uint16_t board_version; /* A monotonously incrementing number. */ uint16_t board_version;
} __packed; } __packed;
/* /*
...@@ -621,27 +649,42 @@ struct ec_response_board_version { ...@@ -621,27 +649,42 @@ struct ec_response_board_version {
*/ */
#define EC_CMD_READ_MEMMAP 0x07 #define EC_CMD_READ_MEMMAP 0x07
/**
* struct ec_params_read_memmap - Parameters for the read memory map command.
* @offset: Offset in memmap (EC_MEMMAP_*).
* @size: Size to read in bytes.
*/
struct ec_params_read_memmap { struct ec_params_read_memmap {
uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */ uint8_t offset;
uint8_t size; /* Size to read in bytes */ uint8_t size;
} __packed; } __packed;
/* Read versions supported for a command */ /* Read versions supported for a command */
#define EC_CMD_GET_CMD_VERSIONS 0x08 #define EC_CMD_GET_CMD_VERSIONS 0x08
/**
* struct ec_params_get_cmd_versions - Parameters for the get command versions.
* @cmd: Command to check.
*/
struct ec_params_get_cmd_versions { struct ec_params_get_cmd_versions {
uint8_t cmd; /* Command to check */ uint8_t cmd;
} __packed; } __packed;
/**
* struct ec_params_get_cmd_versions_v1 - Parameters for the get command
* versions (v1)
* @cmd: Command to check.
*/
struct ec_params_get_cmd_versions_v1 { struct ec_params_get_cmd_versions_v1 {
uint16_t cmd; /* Command to check */ uint16_t cmd;
} __packed; } __packed;
struct ec_response_get_cmd_versions { /**
/* * struct ec_response_get_cmd_version - Response to the get command versions.
* Mask of supported versions; use EC_VER_MASK() to compare with a * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
* desired version. * a desired version.
*/ */
struct ec_response_get_cmd_versions {
uint32_t version_mask; uint32_t version_mask;
} __packed; } __packed;
...@@ -659,6 +702,11 @@ enum ec_comms_status { ...@@ -659,6 +702,11 @@ enum ec_comms_status {
EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */ EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
}; };
/**
* struct ec_response_get_comms_status - Response to the get comms status
* command.
* @flags: Mask of enum ec_comms_status.
*/
struct ec_response_get_comms_status { struct ec_response_get_comms_status {
uint32_t flags; /* Mask of enum ec_comms_status */ uint32_t flags; /* Mask of enum ec_comms_status */
} __packed; } __packed;
...@@ -685,19 +733,19 @@ struct ec_response_test_protocol { ...@@ -685,19 +733,19 @@ struct ec_response_test_protocol {
/* EC_RES_IN_PROGRESS may be returned if a command is slow */ /* EC_RES_IN_PROGRESS may be returned if a command is slow */
#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0) #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
/**
* struct ec_response_get_protocol_info - Response to the get protocol info.
* @protocol_versions: Bitmask of protocol versions supported (1 << n means
* version n).
* @max_request_packet_size: Maximum request packet size in bytes.
* @max_response_packet_size: Maximum response packet size in bytes.
* @flags: see EC_PROTOCOL_INFO_*
*/
struct ec_response_get_protocol_info { struct ec_response_get_protocol_info {
/* Fields which exist if at least protocol version 3 supported */ /* Fields which exist if at least protocol version 3 supported */
/* Bitmask of protocol versions supported (1 << n means version n)*/
uint32_t protocol_versions; uint32_t protocol_versions;
/* Maximum request packet size, in bytes */
uint16_t max_request_packet_size; uint16_t max_request_packet_size;
/* Maximum response packet size, in bytes */
uint16_t max_response_packet_size; uint16_t max_response_packet_size;
/* Flags; see EC_PROTOCOL_INFO_* */
uint32_t flags; uint32_t flags;
} __packed; } __packed;
...@@ -708,8 +756,10 @@ struct ec_response_get_protocol_info { ...@@ -708,8 +756,10 @@ struct ec_response_get_protocol_info {
/* The upper byte of .flags tells what to do (nothing means "get") */ /* The upper byte of .flags tells what to do (nothing means "get") */
#define EC_GSV_SET 0x80000000 #define EC_GSV_SET 0x80000000
/* The lower three bytes of .flags identifies the parameter, if that has /*
meaning for an individual command. */ * The lower three bytes of .flags identifies the parameter, if that has
* meaning for an individual command.
*/
#define EC_GSV_PARAM_MASK 0x00ffffff #define EC_GSV_PARAM_MASK 0x00ffffff
struct ec_params_get_set_value { struct ec_params_get_set_value {
...@@ -810,6 +860,7 @@ enum ec_feature_code { ...@@ -810,6 +860,7 @@ enum ec_feature_code {
#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
struct ec_response_get_features { struct ec_response_get_features {
uint32_t flags[2]; uint32_t flags[2];
} __packed; } __packed;
...@@ -820,24 +871,22 @@ struct ec_response_get_features { ...@@ -820,24 +871,22 @@ struct ec_response_get_features {
/* Get flash info */ /* Get flash info */
#define EC_CMD_FLASH_INFO 0x10 #define EC_CMD_FLASH_INFO 0x10
/* Version 0 returns these fields */ /**
* struct ec_response_flash_info - Response to the flash info command.
* @flash_size: Usable flash size in bytes.
* @write_block_size: Write block size. Write offset and size must be a
* multiple of this.
* @erase_block_size: Erase block size. Erase offset and size must be a
* multiple of this.
* @protect_block_size: Protection block size. Protection offset and size
* must be a multiple of this.
*
* Version 0 returns these fields.
*/
struct ec_response_flash_info { struct ec_response_flash_info {
/* Usable flash size, in bytes */
uint32_t flash_size; uint32_t flash_size;
/*
* Write block size. Write offset and size must be a multiple
* of this.
*/
uint32_t write_block_size; uint32_t write_block_size;
/*
* Erase block size. Erase offset and size must be a multiple
* of this.
*/
uint32_t erase_block_size; uint32_t erase_block_size;
/*
* Protection block size. Protection offset and size must be a
* multiple of this.
*/
uint32_t protect_block_size; uint32_t protect_block_size;
} __packed; } __packed;
...@@ -845,7 +894,22 @@ struct ec_response_flash_info { ...@@ -845,7 +894,22 @@ struct ec_response_flash_info {
/* EC flash erases bits to 0 instead of 1 */ /* EC flash erases bits to 0 instead of 1 */
#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0) #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
/* /**
* struct ec_response_flash_info_1 - Response to the flash info v1 command.
* @flash_size: Usable flash size in bytes.
* @write_block_size: Write block size. Write offset and size must be a
* multiple of this.
* @erase_block_size: Erase block size. Erase offset and size must be a
* multiple of this.
* @protect_block_size: Protection block size. Protection offset and size
* must be a multiple of this.
* @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
* size is exactly this and offset is a multiple of this.
* For example, an EC may have a write buffer which can do
* half-page operations if data is aligned, and a slower
* word-at-a-time write mode.
* @flags: Flags; see EC_FLASH_INFO_*
*
* Version 1 returns the same initial fields as version 0, with additional * Version 1 returns the same initial fields as version 0, with additional
* fields following. * fields following.
* *
...@@ -860,15 +924,7 @@ struct ec_response_flash_info_1 { ...@@ -860,15 +924,7 @@ struct ec_response_flash_info_1 {
uint32_t protect_block_size; uint32_t protect_block_size;
/* Version 1 adds these fields: */ /* Version 1 adds these fields: */
/*
* Ideal write size in bytes. Writes will be fastest if size is
* exactly this and offset is a multiple of this. For example, an EC
* may have a write buffer which can do half-page operations if data is
* aligned, and a slower word-at-a-time write mode.
*/
uint32_t write_ideal_size; uint32_t write_ideal_size;
/* Flags; see EC_FLASH_INFO_* */
uint32_t flags; uint32_t flags;
} __packed; } __packed;
...@@ -879,9 +935,14 @@ struct ec_response_flash_info_1 { ...@@ -879,9 +935,14 @@ struct ec_response_flash_info_1 {
*/ */
#define EC_CMD_FLASH_READ 0x11 #define EC_CMD_FLASH_READ 0x11
/**
* struct ec_params_flash_read - Parameters for the flash read command.
* @offset: Byte offset to read.
* @size: Size to read in bytes.
*/
struct ec_params_flash_read { struct ec_params_flash_read {
uint32_t offset; /* Byte offset to read */ uint32_t offset;
uint32_t size; /* Size to read in bytes */ uint32_t size;
} __packed; } __packed;
/* Write flash */ /* Write flash */
...@@ -891,18 +952,28 @@ struct ec_params_flash_read { ...@@ -891,18 +952,28 @@ struct ec_params_flash_read {
/* Version 0 of the flash command supported only 64 bytes of data */ /* Version 0 of the flash command supported only 64 bytes of data */
#define EC_FLASH_WRITE_VER0_SIZE 64 #define EC_FLASH_WRITE_VER0_SIZE 64
/**
* struct ec_params_flash_write - Parameters for the flash write command.
* @offset: Byte offset to write.
* @size: Size to write in bytes.
*/
struct ec_params_flash_write { struct ec_params_flash_write {
uint32_t offset; /* Byte offset to write */ uint32_t offset;
uint32_t size; /* Size to write in bytes */ uint32_t size;
/* Followed by data to write */ /* Followed by data to write */
} __packed; } __packed;
/* Erase flash */ /* Erase flash */
#define EC_CMD_FLASH_ERASE 0x13 #define EC_CMD_FLASH_ERASE 0x13
/**
* struct ec_params_flash_erase - Parameters for the flash erase command.
* @offset: Byte offset to erase.
* @size: Size to erase in bytes.
*/
struct ec_params_flash_erase { struct ec_params_flash_erase {
uint32_t offset; /* Byte offset to erase */ uint32_t offset;
uint32_t size; /* Size to erase in bytes */ uint32_t size;
} __packed; } __packed;
/* /*
...@@ -941,21 +1012,28 @@ struct ec_params_flash_erase { ...@@ -941,21 +1012,28 @@ struct ec_params_flash_erase {
/* Entile flash code protected when the EC boots */ /* Entile flash code protected when the EC boots */
#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6) #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
/**
* struct ec_params_flash_protect - Parameters for the flash protect command.
* @mask: Bits in flags to apply.
* @flags: New flags to apply.
*/
struct ec_params_flash_protect { struct ec_params_flash_protect {
uint32_t mask; /* Bits in flags to apply */ uint32_t mask;
uint32_t flags; /* New flags to apply */ uint32_t flags;
} __packed; } __packed;
/**
* struct ec_response_flash_protect - Response to the flash protect command.
* @flags: Current value of flash protect flags.
* @valid_flags: Flags which are valid on this platform. This allows the
* caller to distinguish between flags which aren't set vs. flags
* which can't be set on this platform.
* @writable_flags: Flags which can be changed given the current protection
* state.
*/
struct ec_response_flash_protect { struct ec_response_flash_protect {
/* Current value of flash protect flags */
uint32_t flags; uint32_t flags;
/*
* Flags which are valid on this platform. This allows the caller
* to distinguish between flags which aren't set vs. flags which can't
* be set on this platform.
*/
uint32_t valid_flags; uint32_t valid_flags;
/* Flags which can be changed given the current protection state */
uint32_t writable_flags; uint32_t writable_flags;
} __packed; } __packed;
...@@ -982,8 +1060,13 @@ enum ec_flash_region { ...@@ -982,8 +1060,13 @@ enum ec_flash_region {
EC_FLASH_REGION_COUNT, EC_FLASH_REGION_COUNT,
}; };
/**
* struct ec_params_flash_region_info - Parameters for the flash region info
* command.
* @region: Flash region; see EC_FLASH_REGION_*
*/
struct ec_params_flash_region_info { struct ec_params_flash_region_info {
uint32_t region; /* enum ec_flash_region */ uint32_t region;
} __packed; } __packed;
struct ec_response_flash_region_info { struct ec_response_flash_region_info {
...@@ -1094,7 +1177,9 @@ struct rgb_s { ...@@ -1094,7 +1177,9 @@ struct rgb_s {
}; };
#define LB_BATTERY_LEVELS 4 #define LB_BATTERY_LEVELS 4
/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
/*
* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
* host command, but the alignment is the same regardless. Keep it that way. * host command, but the alignment is the same regardless. Keep it that way.
*/ */
struct lightbar_params_v0 { struct lightbar_params_v0 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册