diff mbox series

[U-Boot,35/45] cros_ec: Add support for v3 messages on LPC

Message ID 20181001182249.129565-36-sjg@chromium.org
State Accepted
Commit d07b6e145ec2f0e77aab0fbe15dfd87f40170a8c
Delegated to: Simon Glass
Headers show
Series Various fixes and improvements | expand

Commit Message

Simon Glass Oct. 1, 2018, 6:22 p.m. UTC
At present version 3 messages are only supported on SPI. Add support for
using LPC as well, as used on samus.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec_lpc.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Simon Glass Oct. 9, 2018, 11:54 p.m. UTC | #1
At present version 3 messages are only supported on SPI. Add support for
using LPC as well, as used on samus.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec_lpc.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Applied to u-boot-dm
diff mbox series

Patch

diff --git a/drivers/misc/cros_ec_lpc.c b/drivers/misc/cros_ec_lpc.c
index be17adcc5ac..71d03bfba2b 100644
--- a/drivers/misc/cros_ec_lpc.c
+++ b/drivers/misc/cros_ec_lpc.c
@@ -40,6 +40,38 @@  static int wait_for_sync(struct cros_ec_dev *dev)
 	return 0;
 }
 
+int cros_ec_lpc_packet(struct udevice *udev, int out_bytes, int in_bytes)
+{
+	struct cros_ec_dev *dev = dev_get_uclass_priv(udev);
+	uint8_t *d;
+	int i;
+
+	if (out_bytes > EC_LPC_HOST_PACKET_SIZE)
+		return log_msg_ret("Cannot send that many bytes\n", -E2BIG);
+
+	if (in_bytes > EC_LPC_HOST_PACKET_SIZE)
+		return log_msg_ret("Cannot receive that many bytes\n", -E2BIG);
+
+	if (wait_for_sync(dev))
+		return log_msg_ret("Timeout waiting ready\n", -ETIMEDOUT);
+
+	/* Write data */
+	for (i = 0, d = (uint8_t *)dev->dout; i < out_bytes; i++, d++)
+		outb(*d, EC_LPC_ADDR_HOST_PACKET + i);
+
+	/* Start the command */
+	outb(EC_COMMAND_PROTOCOL_3, EC_LPC_ADDR_HOST_CMD);
+
+	if (wait_for_sync(dev))
+		return log_msg_ret("Timeout waiting ready\n", -ETIMEDOUT);
+
+	/* Read back args */
+	for (i = 0, d = dev->din; i < in_bytes; i++, d++)
+		*d = inb(EC_LPC_ADDR_HOST_PACKET + i);
+
+	return in_bytes;
+}
+
 int cros_ec_lpc_command(struct udevice *udev, uint8_t cmd, int cmd_version,
 		     const uint8_t *dout, int dout_len,
 		     uint8_t **dinp, int din_len)
@@ -200,6 +232,7 @@  static int cros_ec_probe(struct udevice *dev)
 }
 
 static struct dm_cros_ec_ops cros_ec_ops = {
+	.packet = cros_ec_lpc_packet,
 	.command = cros_ec_lpc_command,
 	.check_version = cros_ec_lpc_check_version,
 };