xref: /linux/drivers/platform/chrome/cros_ec_lpc_mec.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
11058ca94SEnric Balletbo i Serra /* SPDX-License-Identifier: GPL-2.0 */
2cc8a4ea1SEnric Balletbo i Serra /*
31058ca94SEnric Balletbo i Serra  * LPC variant I/O for Microchip EC
4cc8a4ea1SEnric Balletbo i Serra  *
5cc8a4ea1SEnric Balletbo i Serra  * Copyright (C) 2016 Google, Inc
6cc8a4ea1SEnric Balletbo i Serra  */
7cc8a4ea1SEnric Balletbo i Serra 
8cc8a4ea1SEnric Balletbo i Serra #ifndef __CROS_EC_LPC_MEC_H
9cc8a4ea1SEnric Balletbo i Serra #define __CROS_EC_LPC_MEC_H
10cc8a4ea1SEnric Balletbo i Serra 
11*60c7df66SBen Walsh #include <linux/acpi.h>
12*60c7df66SBen Walsh 
13cc8a4ea1SEnric Balletbo i Serra enum cros_ec_lpc_mec_emi_access_mode {
14cc8a4ea1SEnric Balletbo i Serra 	/* 8-bit access */
15cc8a4ea1SEnric Balletbo i Serra 	ACCESS_TYPE_BYTE = 0x0,
16cc8a4ea1SEnric Balletbo i Serra 	/* 16-bit access */
17cc8a4ea1SEnric Balletbo i Serra 	ACCESS_TYPE_WORD = 0x1,
18cc8a4ea1SEnric Balletbo i Serra 	/* 32-bit access */
19cc8a4ea1SEnric Balletbo i Serra 	ACCESS_TYPE_LONG = 0x2,
20cc8a4ea1SEnric Balletbo i Serra 	/*
21cc8a4ea1SEnric Balletbo i Serra 	 * 32-bit access, read or write of MEC_EMI_EC_DATA_B3 causes the
22cc8a4ea1SEnric Balletbo i Serra 	 * EC data register to be incremented.
23cc8a4ea1SEnric Balletbo i Serra 	 */
24cc8a4ea1SEnric Balletbo i Serra 	ACCESS_TYPE_LONG_AUTO_INCREMENT = 0x3,
25cc8a4ea1SEnric Balletbo i Serra };
26cc8a4ea1SEnric Balletbo i Serra 
27cc8a4ea1SEnric Balletbo i Serra enum cros_ec_lpc_mec_io_type {
28cc8a4ea1SEnric Balletbo i Serra 	MEC_IO_READ,
29cc8a4ea1SEnric Balletbo i Serra 	MEC_IO_WRITE,
30cc8a4ea1SEnric Balletbo i Serra };
31cc8a4ea1SEnric Balletbo i Serra 
32cc8a4ea1SEnric Balletbo i Serra /* EMI registers are relative to base */
336b7cb222SNick Crews #define MEC_EMI_HOST_TO_EC(MEC_EMI_BASE)	((MEC_EMI_BASE) + 0)
346b7cb222SNick Crews #define MEC_EMI_EC_TO_HOST(MEC_EMI_BASE)	((MEC_EMI_BASE) + 1)
356b7cb222SNick Crews #define MEC_EMI_EC_ADDRESS_B0(MEC_EMI_BASE)	((MEC_EMI_BASE) + 2)
366b7cb222SNick Crews #define MEC_EMI_EC_ADDRESS_B1(MEC_EMI_BASE)	((MEC_EMI_BASE) + 3)
376b7cb222SNick Crews #define MEC_EMI_EC_DATA_B0(MEC_EMI_BASE)	((MEC_EMI_BASE) + 4)
386b7cb222SNick Crews #define MEC_EMI_EC_DATA_B1(MEC_EMI_BASE)	((MEC_EMI_BASE) + 5)
396b7cb222SNick Crews #define MEC_EMI_EC_DATA_B2(MEC_EMI_BASE)	((MEC_EMI_BASE) + 6)
406b7cb222SNick Crews #define MEC_EMI_EC_DATA_B3(MEC_EMI_BASE)	((MEC_EMI_BASE) + 7)
41cc8a4ea1SEnric Balletbo i Serra 
426b7cb222SNick Crews /**
436b7cb222SNick Crews  * cros_ec_lpc_mec_init() - Initialize MEC I/O.
44cc8a4ea1SEnric Balletbo i Serra  *
456b7cb222SNick Crews  * @base: MEC EMI Base address
466b7cb222SNick Crews  * @end: MEC EMI End address
47cc8a4ea1SEnric Balletbo i Serra  */
486b7cb222SNick Crews void cros_ec_lpc_mec_init(unsigned int base, unsigned int end);
49cc8a4ea1SEnric Balletbo i Serra 
50cc8a4ea1SEnric Balletbo i Serra /**
51*60c7df66SBen Walsh  * cros_ec_lpc_mec_acpi_mutex() - Find and set ACPI mutex for MEC
52*60c7df66SBen Walsh  *
53*60c7df66SBen Walsh  * @adev:     Parent ACPI device
54*60c7df66SBen Walsh  * @pathname: Name of AML mutex
55*60c7df66SBen Walsh  * @return:   Negative error code, or zero for success
56*60c7df66SBen Walsh  */
57*60c7df66SBen Walsh int cros_ec_lpc_mec_acpi_mutex(struct acpi_device *adev, const char *pathname);
58*60c7df66SBen Walsh 
59*60c7df66SBen Walsh /**
606b7cb222SNick Crews  * cros_ec_lpc_mec_in_range() - Determine if addresses are in MEC EMI range.
616b7cb222SNick Crews  *
626b7cb222SNick Crews  * @offset: Address offset
636b7cb222SNick Crews  * @length: Number of bytes to check
646b7cb222SNick Crews  *
656b7cb222SNick Crews  * Return: 1 if in range, 0 if not, and -EINVAL on failure
666b7cb222SNick Crews  *         such as the mec range not being initialized
676b7cb222SNick Crews  */
686b7cb222SNick Crews int cros_ec_lpc_mec_in_range(unsigned int offset, unsigned int length);
696b7cb222SNick Crews 
706b7cb222SNick Crews /**
71cc8a4ea1SEnric Balletbo i Serra  * cros_ec_lpc_io_bytes_mec - Read / write bytes to MEC EMI port
72cc8a4ea1SEnric Balletbo i Serra  *
73cc8a4ea1SEnric Balletbo i Serra  * @io_type: MEC_IO_READ or MEC_IO_WRITE, depending on request
74cc8a4ea1SEnric Balletbo i Serra  * @offset:  Base read / write address
75cc8a4ea1SEnric Balletbo i Serra  * @length:  Number of bytes to read / write
76cc8a4ea1SEnric Balletbo i Serra  * @buf:     Destination / source buffer
77cc8a4ea1SEnric Balletbo i Serra  *
7868dbac0aSBen Walsh  * @return:  A negative error code on error, or 8-bit checksum of all
7968dbac0aSBen Walsh  *           bytes read / written
80cc8a4ea1SEnric Balletbo i Serra  */
8168dbac0aSBen Walsh int cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type,
82cc8a4ea1SEnric Balletbo i Serra 			     unsigned int offset, unsigned int length, u8 *buf);
83cc8a4ea1SEnric Balletbo i Serra 
84cc8a4ea1SEnric Balletbo i Serra #endif /* __CROS_EC_LPC_MEC_H */
85