blob: 16237d6203f4d96e87731e1b53991b3b586216ea [file] [log] [blame]
Duncan Laurie6d5873d2017-08-07 17:43:26 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2017 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpi.h>
17#include <arch/acpi_device.h>
18#include <arch/acpigen.h>
19#include <console/console.h>
20#include <device/i2c.h>
21#include <device/device.h>
22#include <device/path.h>
23#include <stdint.h>
24#include <string.h>
25#include "chip.h"
26
27#define RT5663_ACPI_NAME "RT53"
28#define RT5663_ACPI_HID "10EC5663"
29
30#define RT5663_DP_INT(key, val) \
31 acpi_dp_add_integer(dp, "realtek," key, (val))
32
33static void rt5663_fill_ssdt(struct device *dev)
34{
35 struct drivers_i2c_rt5663_config *config = dev->chip_info;
36 const char *scope = acpi_device_scope(dev);
37 struct acpi_i2c i2c = {
38 .address = dev->path.i2c.device,
39 .mode_10bit = dev->path.i2c.mode_10bit,
40 .speed = config->bus_speed ? : I2C_SPEED_FAST,
41 .resource = scope,
42 };
43 struct acpi_dp *dp;
44
45 if (!dev->enabled || !scope)
46 return;
47
48 /* Device */
49 acpigen_write_scope(scope);
50 acpigen_write_device(acpi_device_name(dev));
51 acpigen_write_name_string("_HID", RT5663_ACPI_HID);
52 acpigen_write_name_integer("_UID", config->uid);
53 acpigen_write_name_string("_DDN", dev->chip_ops->name);
54 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
55
56 /* Resources */
57 acpigen_write_name("_CRS");
58 acpigen_write_resourcetemplate_header();
59 acpi_device_write_i2c(&i2c);
60 /* Allow either GpioInt() or Interrupt() */
61 if (config->irq_gpio.pin_count)
62 acpi_device_write_gpio(&config->irq_gpio);
63 else
64 acpi_device_write_interrupt(&config->irq);
65 acpigen_write_resourcetemplate_footer();
66
67 /* Device Properties */
68 dp = acpi_dp_new_table("_DSD");
69 if (config->irq_gpio.pin_count)
70 acpi_dp_add_gpio(dp, "irq-gpios", acpi_device_path(dev), 0, 0,
71 config->irq_gpio.polarity == ACPI_GPIO_ACTIVE_LOW);
72 RT5663_DP_INT("dc_offset_l_manual", config->dc_offset_l_manual);
73 RT5663_DP_INT("dc_offset_r_manual", config->dc_offset_r_manual);
74 RT5663_DP_INT("dc_offset_l_manual_mic", config->dc_offset_l_manual_mic);
75 RT5663_DP_INT("dc_offset_r_manual_mic", config->dc_offset_r_manual_mic);
76 acpi_dp_write(dp);
77
78 acpigen_pop_len(); /* Device */
79 acpigen_pop_len(); /* Scope */
80
81 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
82 dev->chip_ops->name, dev->path.i2c.device);
83}
84
Aaron Durbinaa090cb2017-09-13 16:01:52 -060085static const char *rt5663_acpi_name(const struct device *dev)
Duncan Laurie6d5873d2017-08-07 17:43:26 -070086{
87 return RT5663_ACPI_NAME;
88}
89
90static struct device_operations rt5663_ops = {
91 .read_resources = DEVICE_NOOP,
92 .set_resources = DEVICE_NOOP,
93 .enable_resources = DEVICE_NOOP,
94 .acpi_name = &rt5663_acpi_name,
95 .acpi_fill_ssdt_generator = &rt5663_fill_ssdt,
96};
97
98static void rt5663_enable(struct device *dev)
99{
100 dev->ops = &rt5663_ops;
101}
102
103struct chip_operations drivers_i2c_rt5663_ops = {
104 CHIP_NAME("Realtek RT5663 Codec")
105 .enable_dev = &rt5663_enable
106};