blob: 576667176a0b88b9dd6359e48ea4cadc8a83f986 [file] [log] [blame]
N, Harshapriyac14a99f2017-11-27 15:38:53 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2017 Intel Corporation.
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_simple.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 MAX98373_ACPI_NAME "MAXI"
28#define MAX98373_ACPI_HID "MX98373"
29
30static void max98373_fill_ssdt(struct device *dev)
31{
32 struct drivers_i2c_max98373_config *config = dev->chip_info;
33 const char *scope = acpi_device_scope(dev);
34 struct acpi_i2c i2c = {
35 .address = dev->path.i2c.device,
36 .mode_10bit = dev->path.i2c.mode_10bit,
37 .speed = config->bus_speed ? : I2C_SPEED_STANDARD,
38 .resource = scope,
39 };
40 struct acpi_dp *dp;
41
42 if (!dev->enabled || !scope) {
43 printk(BIOS_ERR, "%s: dev not enabled", __func__);
44 return;
45 }
46
47 /* Device */
48 acpigen_write_scope(scope);
49 acpigen_write_device(acpi_device_name(dev));
50 acpigen_write_name_string("_HID", MAX98373_ACPI_HID);
51 acpigen_write_name_integer("_UID", config->uid);
52 if (config->desc)
53 acpigen_write_name_string("_DDN", config->desc);
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 acpigen_write_resourcetemplate_footer();
61
62 /* Device Properties */
63 dp = acpi_dp_new_table("_DSD");
64
65 acpi_dp_add_integer(dp, "interleave_mode", config->interleave_mode);
66 acpi_dp_add_integer(dp, "vmon-slot-no", config->vmon_slot_no);
67 acpi_dp_add_integer(dp, "imon-slot-no", config->imon_slot_no);
68
69 acpi_dp_write(dp);
70
71 acpigen_pop_len(); /* Device */
72 acpigen_pop_len(); /* Scope */
73
74 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
75 dev->chip_ops->name, dev->path.i2c.device);
76}
77
78static const char *max98373_acpi_name(const struct device *dev)
79{
80 struct drivers_i2c_max98373_config *config = dev->chip_info;
81
82 if (config->name)
83 return config->name;
84
85 return MAX98373_ACPI_NAME;
86}
87
88static struct device_operations max98373_ops = {
89 .read_resources = DEVICE_NOOP,
90 .set_resources = DEVICE_NOOP,
91 .enable_resources = DEVICE_NOOP,
92 .acpi_name = &max98373_acpi_name,
93 .acpi_fill_ssdt_generator = &max98373_fill_ssdt,
94};
95
96static void max98373_enable(struct device *dev)
97{
98 dev->ops = &max98373_ops;
99}
100
101struct chip_operations drivers_i2c_max98373_ops = {
102 CHIP_NAME("Maxim MAX98373 Codec")
103 .enable_dev = &max98373_enable
104};