blob: 1429b59003cff99b0fc2ca115104bb4423825212 [file] [log] [blame]
Angel Ponsc80e3502020-04-03 01:21:49 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00002
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00003#include <string.h>
4#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpi.h>
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00006#include <device/device.h>
Elyes HAOUAS27820482019-12-22 14:20:45 +01007
Vladimir Serbinenko0e646172014-08-31 00:27:05 +02008#include "mainboard.h"
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +00009
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000010static long acpi_create_ecdt(acpi_ecdt_t * ecdt)
11{
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070012 /* Attention: Make sure these match the values from
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000013 * the DSDT's ec.asl
14 */
15 static const char ec_id[] = "\\_SB.PCI0.LPCB.EC0";
16 int ecdt_len = sizeof(acpi_ecdt_t) + strlen(ec_id) + 1;
17
18 acpi_header_t *header = &(ecdt->header);
19
Elyes Haouas486240f2022-11-18 15:21:03 +010020 memset((void *)ecdt, 0, ecdt_len);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000021
22 /* fill out header fields */
23 memcpy(header->signature, "ECDT", 4);
24 memcpy(header->oem_id, OEM_ID, 6);
25 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
26 memcpy(header->asl_compiler_id, ASLC, 4);
27
28 header->length = ecdt_len;
29 header->revision = 1;
30
31 /* Location of the two EC registers */
32 ecdt->ec_control.space_id = ACPI_ADDRESS_SPACE_IO;
33 ecdt->ec_control.bit_width = 8;
34 ecdt->ec_control.bit_offset = 0;
35 ecdt->ec_control.addrl = 0x66;
36 ecdt->ec_control.addrh = 0;
37
Elyes HAOUAS28db21c2020-07-19 11:04:08 +020038 ecdt->ec_data.space_id = ACPI_ADDRESS_SPACE_IO;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000039 ecdt->ec_data.bit_width = 8;
40 ecdt->ec_data.bit_offset = 0;
41 ecdt->ec_data.addrl = 0x62;
42 ecdt->ec_data.addrh = 0;
43
44 ecdt->uid = 1; // Must match _UID of the EC0 node.
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070045
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000046 ecdt->gpe_bit = 23; // SCI interrupt within GPEx_STS
47
Jacob Garber0db6e752019-07-16 15:48:28 -060048 memcpy(ecdt->ec_id, ec_id, sizeof(ec_id));
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000049
50 header->checksum =
Elyes Haouas486240f2022-11-18 15:21:03 +010051 acpi_checksum((void *)ecdt, ecdt_len);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000052
53 return header->length;
54}
55
Furquan Shaikh0f007d82020-04-24 06:41:18 -070056unsigned long mainboard_write_acpi_tables(const struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +020057 unsigned long start,
58 acpi_rsdp_t *rsdp)
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000059{
60 unsigned long current;
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000061 acpi_header_t *ecdt;
62
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000063 current = start;
64
65 /* Align ACPI tables to 16byte */
Aaron Durbin07a1b282015-12-10 17:07:38 -060066 current = acpi_align_current(current);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000067
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000068 printk(BIOS_DEBUG, "ACPI: * ECDT\n");
69 ecdt = (acpi_header_t *)current;
70 current += acpi_create_ecdt((acpi_ecdt_t *)current);
Aaron Durbin07a1b282015-12-10 17:07:38 -060071 current = acpi_align_current(current);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000072 acpi_add_table(rsdp, ecdt);
73
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000074 printk(BIOS_DEBUG, "current = %lx\n", current);
Stefan Reinauer7cfa7f92010-05-16 14:24:41 +000075 return current;
76}