blob: b078674ef04dc65691783a53e76d4e5311f24e0d [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
N, Harshapriyac14a99f2017-11-27 15:38:53 -08002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
4#include <acpi/acpi_device.h>
5#include <acpi/acpigen.h>
N, Harshapriyac14a99f2017-11-27 15:38:53 -08006#include <console/console.h>
7#include <device/i2c_simple.h>
8#include <device/device.h>
9#include <device/path.h>
N, Harshapriyac14a99f2017-11-27 15:38:53 -080010#include "chip.h"
11
12#define MAX98373_ACPI_NAME "MAXI"
13#define MAX98373_ACPI_HID "MX98373"
14
Furquan Shaikh7536a392020-04-24 21:59:21 -070015static void max98373_fill_ssdt(const struct device *dev)
N, Harshapriyac14a99f2017-11-27 15:38:53 -080016{
17 struct drivers_i2c_max98373_config *config = dev->chip_info;
18 const char *scope = acpi_device_scope(dev);
19 struct acpi_i2c i2c = {
20 .address = dev->path.i2c.device,
21 .mode_10bit = dev->path.i2c.mode_10bit,
Furquan Shaikhdc8679c2019-02-13 22:37:26 -080022 .speed = config->bus_speed ? : I2C_SPEED_FAST,
N, Harshapriyac14a99f2017-11-27 15:38:53 -080023 .resource = scope,
24 };
25 struct acpi_dp *dp;
26
Karthikeyan Ramasubramaniand1c0f952020-11-02 16:26:52 -070027 if (!scope) {
Caveh Jalalic8e4dcb2020-04-21 05:00:48 -070028 printk(BIOS_ERR, "%s: dev not enabled\n", __func__);
N, Harshapriyac14a99f2017-11-27 15:38:53 -080029 return;
30 }
31
32 /* Device */
33 acpigen_write_scope(scope);
34 acpigen_write_device(acpi_device_name(dev));
35 acpigen_write_name_string("_HID", MAX98373_ACPI_HID);
36 acpigen_write_name_integer("_UID", config->uid);
37 if (config->desc)
38 acpigen_write_name_string("_DDN", config->desc);
Hung-Te Linb4be50c2018-09-10 10:55:49 +080039 acpigen_write_STA(acpi_device_status(dev));
N, Harshapriyac14a99f2017-11-27 15:38:53 -080040
41 /* Resources */
42 acpigen_write_name("_CRS");
43 acpigen_write_resourcetemplate_header();
44 acpi_device_write_i2c(&i2c);
45 acpigen_write_resourcetemplate_footer();
46
47 /* Device Properties */
48 dp = acpi_dp_new_table("_DSD");
49
Sathyanarayana Nujellaadb176b2018-05-24 23:46:51 -070050 if (config->interleave_mode)
51 acpi_dp_add_integer(dp, "maxim,interleave_mode",
52 config->interleave_mode);
53 acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
54 acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
N, Harshapriyac14a99f2017-11-27 15:38:53 -080055
56 acpi_dp_write(dp);
57
58 acpigen_pop_len(); /* Device */
59 acpigen_pop_len(); /* Scope */
60
61 printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev),
62 dev->chip_ops->name, dev->path.i2c.device);
63}
64
65static const char *max98373_acpi_name(const struct device *dev)
66{
67 struct drivers_i2c_max98373_config *config = dev->chip_info;
68
69 if (config->name)
70 return config->name;
71
72 return MAX98373_ACPI_NAME;
73}
74
75static struct device_operations max98373_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020076 .read_resources = noop_read_resources,
77 .set_resources = noop_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +020078 .acpi_name = max98373_acpi_name,
79 .acpi_fill_ssdt = max98373_fill_ssdt,
N, Harshapriyac14a99f2017-11-27 15:38:53 -080080};
81
82static void max98373_enable(struct device *dev)
83{
Naresh G Solanki69e9e712018-06-04 17:45:19 +053084 struct drivers_i2c_max98373_config *config = dev->chip_info;
85
N, Harshapriyac14a99f2017-11-27 15:38:53 -080086 dev->ops = &max98373_ops;
Naresh G Solanki69e9e712018-06-04 17:45:19 +053087
88 if (config && config->desc) {
89 dev->name = config->desc;
90 }
N, Harshapriyac14a99f2017-11-27 15:38:53 -080091}
92
93struct chip_operations drivers_i2c_max98373_ops = {
94 CHIP_NAME("Maxim MAX98373 Codec")
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010095 .enable_dev = max98373_enable
N, Harshapriyac14a99f2017-11-27 15:38:53 -080096};