Werner Zeh has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/47235 )
Change subject: drivers/i2c/rx6110sa: Add basic ACPI support ......................................................................
drivers/i2c/rx6110sa: Add basic ACPI support
This patch adds basic ACPI support for the RTC so that the OS is able to use this RTC via the ACPI interface.
Change-Id: I9b319e3088e6511592075b055f8fa3e2aedaa209 Signed-off-by: Werner Zeh werner.zeh@siemens.com --- M src/drivers/i2c/rx6110sa/chip.h M src/drivers/i2c/rx6110sa/rx6110sa.c M src/drivers/i2c/rx6110sa/rx6110sa.h 3 files changed, 68 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/35/47235/1
diff --git a/src/drivers/i2c/rx6110sa/chip.h b/src/drivers/i2c/rx6110sa/chip.h index 46ef7f1..feb9133 100644 --- a/src/drivers/i2c/rx6110sa/chip.h +++ b/src/drivers/i2c/rx6110sa/chip.h @@ -3,6 +3,7 @@ #include "rx6110sa.h"
struct drivers_i2c_rx6110sa_config { + unsigned int bus_speed; /* Bus clock in Hz (default 400 kHz)*/ /* The day (of the week) is indicated by 7 bits, bit 0 to bit 6. */ unsigned char user_weekday; /* User day of the week to set */ unsigned char user_day; /* User day to set */ @@ -23,4 +24,9 @@ unsigned char bks_on; unsigned char bks_off; unsigned char iocut_en; /* Disable backup of I/O circuit. */ + + const char *hid; /* ACPI _HID (required) */ + const char *desc; /* ACPI device description */ + const char *name; /* ACPI device name (optional) */ + }; diff --git a/src/drivers/i2c/rx6110sa/rx6110sa.c b/src/drivers/i2c/rx6110sa/rx6110sa.c index ca39bdb..e758728 100644 --- a/src/drivers/i2c/rx6110sa/rx6110sa.c +++ b/src/drivers/i2c/rx6110sa/rx6110sa.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */
+#include <acpi/acpi_device.h> +#include <acpi/acpigen.h> #include <device/i2c_bus.h> #include <device/device.h> #include <version.h> @@ -163,11 +165,67 @@ rx6110sa_write(dev, CTRL_REG, reg); }
+#if CONFIG(HAVE_ACPI_TABLES) +static void rx6110sa_fill_ssdt(const struct device *dev) +{ + struct drivers_i2c_rx6110sa_config *config = dev->chip_info; + const char *scope = acpi_device_scope(dev); + if (!dev->enabled || !scope) + return; + + if (!config->hid) { + printk(BIOS_ERR, "ERROR: HID for %s required\n", dev_path(dev)); + return; + } + struct acpi_i2c i2c = { + .address = dev->path.i2c.device, + .mode_10bit = dev->path.i2c.mode_10bit, + .speed = config->bus_speed ? : I2C_SPEED_FAST, + .resource = scope, + }; + + /* Device */ + acpigen_write_scope(scope); + acpigen_write_device(acpi_device_name(dev)); + acpigen_write_name_string("_HID", config->hid); + acpigen_write_name_string("_DDN", config->desc); + acpigen_write_STA(acpi_device_status(dev)); + + /* Resources */ + acpigen_write_name("_CRS"); + acpigen_write_resourcetemplate_header(); + acpi_device_write_i2c(&i2c); + + acpigen_write_resourcetemplate_footer(); + + acpigen_pop_len(); /* Device */ + acpigen_pop_len(); /* Scope */ + + printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), + dev->chip_ops->name, dev_path(dev)); +} + +/* Use name specified in config or take a fixed name. */ +static const char *rx6110sa_acpi_name(const struct device *dev) +{ + struct drivers_i2c_rx6110sa_config *config = dev->chip_info; + + if (config->name && strlen(config->name) == RX6110SA_ACPI_NAME_LEN) + return config->name; + else + return RX6110SA_ACPI_NAME; +} +#endif + static struct device_operations rx6110sa_ops = { .read_resources = noop_read_resources, .set_resources = noop_set_resources, .init = rx6110sa_init, - .final = rx6110sa_final + .final = rx6110sa_final, +#if CONFIG(HAVE_ACPI_TABLES) + .acpi_name = rx6110sa_acpi_name, + .acpi_fill_ssdt = rx6110sa_fill_ssdt, +#endif };
static void rx6110sa_enable(struct device *dev) diff --git a/src/drivers/i2c/rx6110sa/rx6110sa.h b/src/drivers/i2c/rx6110sa/rx6110sa.h index 187bad4..91685e9 100644 --- a/src/drivers/i2c/rx6110sa/rx6110sa.h +++ b/src/drivers/i2c/rx6110sa/rx6110sa.h @@ -7,6 +7,9 @@ #define RX6110SA_SLAVE_ADR 0x32 #define RX6110SA_I2C_CONTROLLER 0
+#define RX6110SA_ACPI_NAME "ERX6" +#define RX6110SA_ACPI_NAME_LEN 4 + /* Register layout */ #define SECOND_REG 0x10 #define MINUTE_REG 0x11