| 1 |
|
| 2 |
|
| 3 |
#include <arch/io.h> |
| 4 |
#include <stdint.h> |
| 5 |
|
| 6 |
#include "ec.h" |
| 7 |
|
| 8 |
|
| 9 |
#define EMI_RANGE_START EC_HOST_CMD_REGION0 |
| 10 |
#define EMI_RANGE_END (EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SIZE) |
| 11 |
|
| 12 |
#define HOSTCMD_PARAM_MEM_BASE CONFIG_EC_GOOGLE_CHROMEEC_LPC_GENERIC_MEMORY_BASE |
| 13 |
#define ACPI_MEM_BASE (HOSTCMD_PARAM_MEM_BASE + 0x100) |
| 14 |
|
| 15 |
#define SIO_CONFIG_PORT 0x2e |
| 16 |
#define SIO_DATA_PORT 0x2f |
| 17 |
#define SIO_LDN 0x07 |
| 18 |
#define EMI0_LDN 0x06 |
| 19 |
#define EMI1_LDN 0x07 |
| 20 |
|
| 21 |
#define EMI_ADDR3 0xf0 |
| 22 |
#define EMI_ADDR2 0xf1 |
| 23 |
#define EMI_ADDR1 0xf2 |
| 24 |
#define EMI_CTRL 0x30 |
| 25 |
|
| 26 |
static bool is_emi_inited; |
| 27 |
|
| 28 |
static inline void sio_write_config(uint8_t reg, uint8_t value) |
| 29 |
{ |
| 30 |
outb(reg, SIO_CONFIG_PORT); |
| 31 |
outb(value, SIO_DATA_PORT); |
| 32 |
} |
| 33 |
|
| 34 |
static void host_emi_init(void) |
| 35 |
{ |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
if (is_emi_inited) |
| 42 |
return; |
| 43 |
|
| 44 |
printk(BIOS_INFO, "RTS5915 EMI: start init ...\n"); |
| 45 |
|
| 46 |
|
| 47 |
sio_write_config(SIO_LDN, EMI0_LDN); |
| 48 |
sio_write_config(EMI_ADDR3, HOSTCMD_PARAM_MEM_BASE >> 24 & 0xff); |
| 49 |
sio_write_config(EMI_ADDR2, HOSTCMD_PARAM_MEM_BASE >> 16 & 0xff); |
| 50 |
sio_write_config(EMI_ADDR1, HOSTCMD_PARAM_MEM_BASE >> 8 & 0xff); |
| 51 |
sio_write_config(EMI_CTRL, 0x01); |
| 52 |
|
| 53 |
|
| 54 |
sio_write_config(SIO_LDN, EMI1_LDN); |
| 55 |
sio_write_config(EMI_ADDR3, ACPI_MEM_BASE >> 24 & 0xff); |
| 56 |
sio_write_config(EMI_ADDR2, ACPI_MEM_BASE >> 16 & 0xff); |
| 57 |
sio_write_config(EMI_ADDR1, ACPI_MEM_BASE >> 8 & 0xff); |
| 58 |
sio_write_config(EMI_CTRL, 0x01); |
| 59 |
|
| 60 |
printk(BIOS_INFO, "RTS5915 EMI: done\n"); |
| 61 |
|
| 62 |
is_emi_inited = true; |
| 63 |
} |
| 64 |
|
| 65 |
bool chipset_emi_read_bytes(u16 port, size_t length, u8 *dest, u8 *csum) |
| 66 |
{ |
| 67 |
size_t i; |
| 68 |
|
| 69 |
host_emi_init(); |
| 70 |
|
| 71 |
printk(BIOS_DEBUG, "RTS5915: read port 0x%x, size %zu\n", port, length); |
| 72 |
|
| 73 |
if (port >= EMI_RANGE_START && port <= EMI_RANGE_END) { |
| 74 |
uint8_t *p = (uint8_t *)(uintptr_t)(HOSTCMD_PARAM_MEM_BASE |
| 75 |
+ (port - EMI_RANGE_START)); |
| 76 |
for (i = 0; i < length; ++i) { |
| 77 |
dest[i] = p[i]; |
| 78 |
if (csum) |
| 79 |
*csum += dest[i]; |
| 80 |
} |
| 81 |
return true; |
| 82 |
} |
| 83 |
return false; |
| 84 |
} |
| 85 |
|
| 86 |
bool chipset_emi_write_bytes(u16 port, size_t length, u8 *msg, u8 *csum) |
| 87 |
{ |
| 88 |
size_t i; |
| 89 |
|
| 90 |
host_emi_init(); |
| 91 |
|
| 92 |
printk(BIOS_DEBUG, "RTS5915: write port 0x%x, size %zu\n", port, length); |
| 93 |
|
| 94 |
if (port >= EMI_RANGE_START && port <= EMI_RANGE_END) { |
| 95 |
uint8_t *p = (uint8_t *)(uintptr_t)(HOSTCMD_PARAM_MEM_BASE |
| 96 |
+ (port - EMI_RANGE_START)); |
| 97 |
for (i = 0; i < length; ++i) { |
| 98 |
p[i] = msg[i]; |
| 99 |
if (csum) |
| 100 |
*csum += msg[i]; |
| 101 |
} |
| 102 |
return true; |
| 103 |
} |
| 104 |
|
| 105 |
return false; |
| 106 |
} |