blob: 7979fe32a044aed16ed42882649bf6d28e144ce2 [file] [log] [blame]
Rizwan Qureshi4979d762017-01-13 22:17:01 +05301/*
2 * This file is part of the coreboot project.
3 *
Rizwan Qureshi4979d762017-01-13 22:17:01 +05304 * 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>
Nico Huber0f2dd1e2017-08-01 14:02:40 +020018#include <device/i2c_simple.h>
Rizwan Qureshi4979d762017-01-13 22:17:01 +053019#include <device/device.h>
20#include <device/path.h>
21#include <stdint.h>
Rizwan Qureshi4979d762017-01-13 22:17:01 +053022#include "chip.h"
23
24#define MAX98927_ACPI_NAME "MAXI"
25#define MAX98927_ACPI_HID "MX98927"
26
27static void max98927_fill_ssdt(struct device *dev)
28{
29 struct drivers_i2c_max98927_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,
34 .speed = config->bus_speed ? : I2C_SPEED_FAST,
35 .resource = scope,
36 };
37 struct acpi_dp *dp;
38
39 if (!dev->enabled || !scope)
40 return;
41
42 /* Device */
43 acpigen_write_scope(scope);
44 acpigen_write_device(acpi_device_name(dev));
45 acpigen_write_name_string("_HID", MAX98927_ACPI_HID);
46 acpigen_write_name_integer("_UID", config->uid);
47 if (config->desc)
48 acpigen_write_name_string("_DDN", config->desc);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080049 acpigen_write_STA(acpi_device_status(dev));
Rizwan Qureshi4979d762017-01-13 22:17:01 +053050
51 /* Resources */
52 acpigen_write_name("_CRS");
53 acpigen_write_resourcetemplate_header();
54 acpi_device_write_i2c(&i2c);
55 acpigen_write_resourcetemplate_footer();
56
57 /* Device Properties */
58 dp = acpi_dp_new_table("_DSD");
59
60 acpi_dp_add_integer(dp, "interleave_mode", config->interleave_mode);
Harsha Priya15177352017-08-24 14:35:28 -070061 acpi_dp_add_integer(dp, "vmon-slot-no", config->vmon_slot_no);
62 acpi_dp_add_integer(dp, "imon-slot-no", config->imon_slot_no);
Rizwan Qureshi4979d762017-01-13 22:17:01 +053063
64 acpi_dp_write(dp);
65
66 acpigen_pop_len(); /* Device */
67 acpigen_pop_len(); /* Scope */
68
69 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
70 dev->chip_ops->name, dev->path.i2c.device);
71}
72
Aaron Durbinaa090cb2017-09-13 16:01:52 -060073static const char *max98927_acpi_name(const struct device *dev)
Rizwan Qureshi4979d762017-01-13 22:17:01 +053074{
75 struct drivers_i2c_max98927_config *config = dev->chip_info;
76
77 if (config->name)
78 return config->name;
79
80 return MAX98927_ACPI_NAME;
81}
82
83static struct device_operations max98927_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +020084 .read_resources = DEVICE_NOOP,
85 .set_resources = DEVICE_NOOP,
86 .enable_resources = DEVICE_NOOP,
87 .acpi_name = max98927_acpi_name,
88 .acpi_fill_ssdt = max98927_fill_ssdt,
Rizwan Qureshi4979d762017-01-13 22:17:01 +053089};
90
91static void max98927_enable(struct device *dev)
92{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053093 struct drivers_i2c_max98927_config *config = dev->chip_info;
94
Rizwan Qureshi4979d762017-01-13 22:17:01 +053095 dev->ops = &max98927_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +053096
97 if (config && config->desc) {
98 dev->name = config->desc;
99 }
Rizwan Qureshi4979d762017-01-13 22:17:01 +0530100}
101
102struct chip_operations drivers_i2c_max98927_ops = {
103 CHIP_NAME("Maxim MAX98927 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +0100104 .enable_dev = max98927_enable
Rizwan Qureshi4979d762017-01-13 22:17:01 +0530105};