blob: 0573454b7d030fb8ede5cc48fccf70dc88f0e218 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurie6d5873d2017-08-07 17:43:26 -07003
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
5#include <acpi/acpi_device.h>
6#include <acpi/acpigen.h>
Duncan Laurie6d5873d2017-08-07 17:43:26 -07007#include <console/console.h>
8#include <device/i2c.h>
9#include <device/device.h>
10#include <device/path.h>
11#include <stdint.h>
Duncan Laurie6d5873d2017-08-07 17:43:26 -070012#include "chip.h"
13
14#define RT5663_ACPI_NAME "RT53"
15#define RT5663_ACPI_HID "10EC5663"
16
17#define RT5663_DP_INT(key, val) \
18 acpi_dp_add_integer(dp, "realtek," key, (val))
19
Furquan Shaikh7536a392020-04-24 21:59:21 -070020static void rt5663_fill_ssdt(const struct device *dev)
Duncan Laurie6d5873d2017-08-07 17:43:26 -070021{
22 struct drivers_i2c_rt5663_config *config = dev->chip_info;
23 const char *scope = acpi_device_scope(dev);
24 struct acpi_i2c i2c = {
25 .address = dev->path.i2c.device,
26 .mode_10bit = dev->path.i2c.mode_10bit,
27 .speed = config->bus_speed ? : I2C_SPEED_FAST,
28 .resource = scope,
29 };
30 struct acpi_dp *dp;
31
32 if (!dev->enabled || !scope)
33 return;
34
35 /* Device */
36 acpigen_write_scope(scope);
37 acpigen_write_device(acpi_device_name(dev));
38 acpigen_write_name_string("_HID", RT5663_ACPI_HID);
39 acpigen_write_name_integer("_UID", config->uid);
40 acpigen_write_name_string("_DDN", dev->chip_ops->name);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080041 acpigen_write_STA(acpi_device_status(dev));
Duncan Laurie6d5873d2017-08-07 17:43:26 -070042
43 /* Resources */
44 acpigen_write_name("_CRS");
45 acpigen_write_resourcetemplate_header();
46 acpi_device_write_i2c(&i2c);
47 /* Allow either GpioInt() or Interrupt() */
48 if (config->irq_gpio.pin_count)
49 acpi_device_write_gpio(&config->irq_gpio);
50 else
51 acpi_device_write_interrupt(&config->irq);
52 acpigen_write_resourcetemplate_footer();
53
54 /* Device Properties */
55 dp = acpi_dp_new_table("_DSD");
56 if (config->irq_gpio.pin_count)
57 acpi_dp_add_gpio(dp, "irq-gpios", acpi_device_path(dev), 0, 0,
58 config->irq_gpio.polarity == ACPI_GPIO_ACTIVE_LOW);
59 RT5663_DP_INT("dc_offset_l_manual", config->dc_offset_l_manual);
60 RT5663_DP_INT("dc_offset_r_manual", config->dc_offset_r_manual);
61 RT5663_DP_INT("dc_offset_l_manual_mic", config->dc_offset_l_manual_mic);
62 RT5663_DP_INT("dc_offset_r_manual_mic", config->dc_offset_r_manual_mic);
63 acpi_dp_write(dp);
64
65 acpigen_pop_len(); /* Device */
66 acpigen_pop_len(); /* Scope */
67
68 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
69 dev->chip_ops->name, dev->path.i2c.device);
70}
71
Aaron Durbinaa090cb2017-09-13 16:01:52 -060072static const char *rt5663_acpi_name(const struct device *dev)
Duncan Laurie6d5873d2017-08-07 17:43:26 -070073{
74 return RT5663_ACPI_NAME;
75}
76
77static struct device_operations rt5663_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020078 .read_resources = noop_read_resources,
79 .set_resources = noop_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +020080 .acpi_name = rt5663_acpi_name,
81 .acpi_fill_ssdt = rt5663_fill_ssdt,
Duncan Laurie6d5873d2017-08-07 17:43:26 -070082};
83
84static void rt5663_enable(struct device *dev)
85{
86 dev->ops = &rt5663_ops;
87}
88
89struct chip_operations drivers_i2c_rt5663_ops = {
90 CHIP_NAME("Realtek RT5663 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010091 .enable_dev = rt5663_enable
Duncan Laurie6d5873d2017-08-07 17:43:26 -070092};