blob: 257156b0f48168688b8810f7b421b76b5d70f9f7 [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. */
N, Harshapriyac14a99f2017-11-27 15:38:53 -08003
4#include <arch/acpi.h>
5#include <arch/acpi_device.h>
6#include <arch/acpigen.h>
7#include <console/console.h>
8#include <device/i2c_simple.h>
9#include <device/device.h>
10#include <device/path.h>
11#include <stdint.h>
N, Harshapriyac14a99f2017-11-27 15:38:53 -080012#include "chip.h"
13
14#define MAX98373_ACPI_NAME "MAXI"
15#define MAX98373_ACPI_HID "MX98373"
16
17static void max98373_fill_ssdt(struct device *dev)
18{
19 struct drivers_i2c_max98373_config *config = dev->chip_info;
20 const char *scope = acpi_device_scope(dev);
21 struct acpi_i2c i2c = {
22 .address = dev->path.i2c.device,
23 .mode_10bit = dev->path.i2c.mode_10bit,
Furquan Shaikhdc8679c2019-02-13 22:37:26 -080024 .speed = config->bus_speed ? : I2C_SPEED_FAST,
N, Harshapriyac14a99f2017-11-27 15:38:53 -080025 .resource = scope,
26 };
27 struct acpi_dp *dp;
28
29 if (!dev->enabled || !scope) {
30 printk(BIOS_ERR, "%s: dev not enabled", __func__);
31 return;
32 }
33
34 /* Device */
35 acpigen_write_scope(scope);
36 acpigen_write_device(acpi_device_name(dev));
37 acpigen_write_name_string("_HID", MAX98373_ACPI_HID);
38 acpigen_write_name_integer("_UID", config->uid);
39 if (config->desc)
40 acpigen_write_name_string("_DDN", config->desc);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080041 acpigen_write_STA(acpi_device_status(dev));
N, Harshapriyac14a99f2017-11-27 15:38:53 -080042
43 /* Resources */
44 acpigen_write_name("_CRS");
45 acpigen_write_resourcetemplate_header();
46 acpi_device_write_i2c(&i2c);
47 acpigen_write_resourcetemplate_footer();
48
49 /* Device Properties */
50 dp = acpi_dp_new_table("_DSD");
51
Sathyanarayana Nujellaadb176b2018-05-24 23:46:51 -070052 if (config->interleave_mode)
53 acpi_dp_add_integer(dp, "maxim,interleave_mode",
54 config->interleave_mode);
55 acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
56 acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
N, Harshapriyac14a99f2017-11-27 15:38:53 -080057
58 acpi_dp_write(dp);
59
60 acpigen_pop_len(); /* Device */
61 acpigen_pop_len(); /* Scope */
62
63 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
64 dev->chip_ops->name, dev->path.i2c.device);
65}
66
67static const char *max98373_acpi_name(const struct device *dev)
68{
69 struct drivers_i2c_max98373_config *config = dev->chip_info;
70
71 if (config->name)
72 return config->name;
73
74 return MAX98373_ACPI_NAME;
75}
76
77static struct device_operations max98373_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +020078 .read_resources = DEVICE_NOOP,
79 .set_resources = DEVICE_NOOP,
80 .enable_resources = DEVICE_NOOP,
81 .acpi_name = max98373_acpi_name,
82 .acpi_fill_ssdt = max98373_fill_ssdt,
N, Harshapriyac14a99f2017-11-27 15:38:53 -080083};
84
85static void max98373_enable(struct device *dev)
86{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053087 struct drivers_i2c_max98373_config *config = dev->chip_info;
88
N, Harshapriyac14a99f2017-11-27 15:38:53 -080089 dev->ops = &max98373_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +053090
91 if (config && config->desc) {
92 dev->name = config->desc;
93 }
N, Harshapriyac14a99f2017-11-27 15:38:53 -080094}
95
96struct chip_operations drivers_i2c_max98373_ops = {
97 CHIP_NAME("Maxim MAX98373 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010098 .enable_dev = max98373_enable
N, Harshapriyac14a99f2017-11-27 15:38:53 -080099};