coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
max98390.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/i2c.h>
7 #include <device/device.h>
8 #include <device/path.h>
9 #include <stdint.h>
10 #include <vendorcode/google/chromeos/chromeos.h>
11 #include "chip.h"
12 
13 #define MAX98390_ACPI_HID "MX98390"
14 
15 #define MAX98390_DP_INT(key, val) acpi_dp_add_integer(dp, "maxim," key, (val))
16 
17 static void max98390_fill_ssdt(const struct device *dev)
18 {
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,
24  .speed = I2C_SPEED_FAST,
25  .resource = scope,
26  };
27  struct acpi_dp *dp = NULL;
28  uint64_t r0_value, temp_value;
29  char dsm_name[80] = {};
30 
31  if (!scope)
32  return;
33 
34  /* Device */
35  acpigen_write_scope(scope);
38  acpigen_write_name_integer("_UID", config->uid);
39  acpigen_write_name_string("_DDN", config->desc);
41 
42  /* Resources */
43  acpigen_write_name("_CRS");
47 
48  /* Device Properties */
49  if (CONFIG(CHROMEOS_DSM_CALIB)) {
50  if (get_dsm_calibration_from_key(config->r0_calib_key, &r0_value)
51  || get_dsm_calibration_from_key(config->temperature_calib_key,
52  &temp_value)) {
54  "Failed to get dsm_calib parameters from VPD"
55  " with key %s and %s\n",
56  config->r0_calib_key, config->temperature_calib_key);
57  } else {
58  dp = acpi_dp_new_table("_DSD");
59  MAX98390_DP_INT("r0_calib", r0_value);
60  MAX98390_DP_INT("temperature_calib", temp_value);
61  printk(BIOS_INFO, "set dsm_calib properties\n");
62  }
63  }
64 
65  if (CONFIG(CHROMEOS_DSM_PARAM_FILE_NAME)) {
66  if (config->dsm_param_file_name) {
67  if (!dp)
68  dp = acpi_dp_new_table("_DSD");
69 
70  size_t chars = snprintf(dsm_name, sizeof(dsm_name), "%s_%s_%s.bin",
71  config->dsm_param_file_name, CONFIG_MAINBOARD_VENDOR,
72  CONFIG_MAINBOARD_PART_NUMBER);
73 
74  if (chars >= sizeof(dsm_name))
75  printk(BIOS_ERR, "String too long in %s\n", __func__);
76 
77  acpi_dp_add_string(dp, "maxim,dsm_param_name", dsm_name);
78  }
79  }
80 
81  if (!dp)
82  dp = acpi_dp_new_table("_DSD");
83 
84  acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no);
85  acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no);
86 
87  if (dp)
88  acpi_dp_write(dp);
89 
90  acpigen_pop_len(); /* Device */
91  acpigen_pop_len(); /* Scope */
92 
93  printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), dev->chip_ops->name,
94  dev->path.i2c.device);
95 }
96 
97 static const char *max98390_acpi_name(const struct device *dev)
98 {
100  static char name[5];
101 
102  if (config->name)
103  return config->name;
104 
105  snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
106  return name;
107 }
108 
109 static struct device_operations max98390_ops = {
111  .set_resources = noop_set_resources,
112  .acpi_name = max98390_acpi_name,
113  .acpi_fill_ssdt = max98390_fill_ssdt,
114 };
115 
116 static void max98390_enable(struct device *dev)
117 {
119 
120  if (!config)
121  return;
122 
123  dev->ops = &max98390_ops;
124 
125  /* Name the device as per description provided in devicetree */
126  if (config->desc)
127  dev->name = config->desc;
128 }
129 
131  CHIP_NAME("Maxim MAX98390 Codec")
132  .enable_dev = max98390_enable
133 };
const char * acpi_device_path(const struct device *dev)
Definition: device.c:144
struct acpi_dp * acpi_dp_add_string(struct acpi_dp *dp, const char *name, const char *string)
Definition: device.c:991
struct acpi_dp * acpi_dp_add_integer(struct acpi_dp *dp, const char *name, uint64_t value)
Definition: device.c:977
void acpi_device_write_i2c(const struct acpi_i2c *i2c)
Definition: device.c:399
void acpi_dp_write(struct acpi_dp *table)
Definition: device.c:898
int acpi_device_status(const struct device *dev)
Definition: device.c:193
const char * acpi_device_name(const struct device *dev)
Definition: device.c:49
struct acpi_dp * acpi_dp_new_table(const char *name)
Definition: device.c:930
const char * acpi_device_scope(const struct device *dev)
Definition: device.c:158
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_scope(const char *name)
Definition: acpigen.c:326
void acpigen_write_resourcetemplate_footer(void)
Definition: acpigen.c:1165
void acpigen_write_name_integer(const char *name, uint64_t val)
Definition: acpigen.c:170
void acpigen_write_STA(uint8_t status)
Definition: acpigen.c:783
void acpigen_write_resourcetemplate_header(void)
Definition: acpigen.c:1147
void acpigen_write_device(const char *name)
Definition: acpigen.c:769
void acpigen_write_name(const char *name)
Definition: acpigen.c:320
void acpigen_write_name_string(const char *name, const char *string)
Definition: acpigen.c:176
const char * name
Definition: mmu.c:92
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
@ I2C_SPEED_FAST
Definition: i2c.h:45
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
enum board_config config
Definition: memory.c:448
static void max98390_fill_ssdt(const struct device *dev)
Definition: max98390.c:17
struct chip_operations drivers_i2c_max98390_ops
Definition: max98390.c:130
#define MAX98390_DP_INT(key, val)
Definition: max98390.c:15
#define MAX98390_ACPI_HID
Definition: max98390.c:13
static const char * max98390_acpi_name(const struct device *dev)
Definition: max98390.c:97
static void max98390_enable(struct device *dev)
Definition: max98390.c:116
static struct device_operations max98390_ops
Definition: max98390.c:109
#define NULL
Definition: stddef.h:19
unsigned long long uint64_t
Definition: stdint.h:17
uint16_t address
Definition: acpi_device.h:304
const char * name
Definition: device.h:29
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct i2c_path i2c
Definition: path.h:118
Definition: device.h:107
struct chip_operations * chip_ops
Definition: device.h:144
const char * name
Definition: device.h:145
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int device
Definition: path.h:63
unsigned int mode_10bit
Definition: path.h:64
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35