blob: 71ba75b9fef531f2656bf02aa8c442b14f3e1193 [file] [log] [blame]
N, Harshapriyac14a99f2017-11-27 15:38:53 -08001/*
2 * This file is part of the coreboot project.
3 *
N, Harshapriyac14a99f2017-11-27 15:38:53 -08004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <arch/acpi.h>
15#include <arch/acpi_device.h>
16#include <arch/acpigen.h>
17#include <console/console.h>
18#include <device/i2c_simple.h>
19#include <device/device.h>
20#include <device/path.h>
21#include <stdint.h>
N, Harshapriyac14a99f2017-11-27 15:38:53 -080022#include "chip.h"
23
24#define MAX98373_ACPI_NAME "MAXI"
25#define MAX98373_ACPI_HID "MX98373"
26
27static void max98373_fill_ssdt(struct device *dev)
28{
29 struct drivers_i2c_max98373_config *config = dev->chip_info;
30 const char *scope = acpi_device_scope(dev);
31 struct acpi_i2c i2c = {
32 .address = dev->path.i2c.device,
33 .mode_10bit = dev->path.i2c.mode_10bit,
Furquan Shaikhdc8679c2019-02-13 22:37:26 -080034 .speed = config->bus_speed ? : I2C_SPEED_FAST,
N, Harshapriyac14a99f2017-11-27 15:38:53 -080035 .resource = scope,
36 };
37 struct acpi_dp *dp;
38
39 if (!dev->enabled || !scope) {
40 printk(BIOS_ERR, "%s: dev not enabled", __func__);
41 return;
42 }
43
44 /* Device */
45 acpigen_write_scope(scope);
46 acpigen_write_device(acpi_device_name(dev));
47 acpigen_write_name_string("_HID", MAX98373_ACPI_HID);
48 acpigen_write_name_integer("_UID", config->uid);
49 if (config->desc)
50 acpigen_write_name_string("_DDN", config->desc);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080051 acpigen_write_STA(acpi_device_status(dev));
N, Harshapriyac14a99f2017-11-27 15:38:53 -080052
53 /* Resources */
54 acpigen_write_name("_CRS");
55 acpigen_write_resourcetemplate_header();
56 acpi_device_write_i2c(&i2c);
57 acpigen_write_resourcetemplate_footer();
58
59 /* Device Properties */
60 dp = acpi_dp_new_table("_DSD");
61
Sathyanarayana Nujellaadb176b2018-05-24 23:46:51 -070062 if (config->interleave_mode)
63 acpi_dp_add_integer(dp, "maxim,interleave_mode",
64 config->interleave_mode);
65 acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
66 acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
N, Harshapriyac14a99f2017-11-27 15:38:53 -080067
68 acpi_dp_write(dp);
69
70 acpigen_pop_len(); /* Device */
71 acpigen_pop_len(); /* Scope */
72
73 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
74 dev->chip_ops->name, dev->path.i2c.device);
75}
76
77static const char *max98373_acpi_name(const struct device *dev)
78{
79 struct drivers_i2c_max98373_config *config = dev->chip_info;
80
81 if (config->name)
82 return config->name;
83
84 return MAX98373_ACPI_NAME;
85}
86
87static struct device_operations max98373_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +020088 .read_resources = DEVICE_NOOP,
89 .set_resources = DEVICE_NOOP,
90 .enable_resources = DEVICE_NOOP,
91 .acpi_name = max98373_acpi_name,
92 .acpi_fill_ssdt = max98373_fill_ssdt,
N, Harshapriyac14a99f2017-11-27 15:38:53 -080093};
94
95static void max98373_enable(struct device *dev)
96{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053097 struct drivers_i2c_max98373_config *config = dev->chip_info;
98
N, Harshapriyac14a99f2017-11-27 15:38:53 -080099 dev->ops = &max98373_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +0530100
101 if (config && config->desc) {
102 dev->name = config->desc;
103 }
N, Harshapriyac14a99f2017-11-27 15:38:53 -0800104}
105
106struct chip_operations drivers_i2c_max98373_ops = {
107 CHIP_NAME("Maxim MAX98373 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100108 .enable_dev = max98373_enable
N, Harshapriyac14a99f2017-11-27 15:38:53 -0800109};