1 // SPDX-License-Identifier: GPL-2.0
2 // LPC interface for ChromeOS Embedded Controller
4 // Copyright (C) 2016 Google, Inc
7 #include <linux/mfd/cros_ec.h>
8 #include <linux/mfd/cros_ec_commands.h>
10 #include "cros_ec_lpc_mec.h"
12 static u8 lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest)
17 for (i = 0; i < length; ++i) {
18 dest[i] = inb(offset + i);
22 /* Return checksum of all bytes read */
26 static u8 lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg)
31 for (i = 0; i < length; ++i) {
32 outb(msg[i], offset + i);
36 /* Return checksum of all bytes written */
40 #ifdef CONFIG_CROS_EC_LPC_MEC
42 u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest)
44 int in_range = cros_ec_lpc_mec_in_range(offset, length);
50 cros_ec_lpc_io_bytes_mec(MEC_IO_READ,
51 offset - EC_HOST_CMD_REGION0,
53 lpc_read_bytes(offset, length, dest);
56 u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg)
58 int in_range = cros_ec_lpc_mec_in_range(offset, length);
64 cros_ec_lpc_io_bytes_mec(MEC_IO_WRITE,
65 offset - EC_HOST_CMD_REGION0,
67 lpc_write_bytes(offset, length, msg);
70 void cros_ec_lpc_reg_init(void)
72 cros_ec_lpc_mec_init(EC_HOST_CMD_REGION0,
73 EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE);
76 void cros_ec_lpc_reg_destroy(void)
78 cros_ec_lpc_mec_destroy();
81 #else /* CONFIG_CROS_EC_LPC_MEC */
83 u8 cros_ec_lpc_read_bytes(unsigned int offset, unsigned int length, u8 *dest)
85 return lpc_read_bytes(offset, length, dest);
88 u8 cros_ec_lpc_write_bytes(unsigned int offset, unsigned int length, u8 *msg)
90 return lpc_write_bytes(offset, length, msg);
93 void cros_ec_lpc_reg_init(void)
97 void cros_ec_lpc_reg_destroy(void)
101 #endif /* CONFIG_CROS_EC_LPC_MEC */