Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/i2c_simple.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 9 | #include "chip.h" |
| 10 | |
| 11 | #define MAX98373_ACPI_NAME "MAXI" |
| 12 | #define MAX98373_ACPI_HID "MX98373" |
| 13 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 14 | static void max98373_fill_ssdt(const struct device *dev) |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 15 | { |
| 16 | struct drivers_i2c_max98373_config *config = dev->chip_info; |
| 17 | const char *scope = acpi_device_scope(dev); |
| 18 | struct acpi_i2c i2c = { |
| 19 | .address = dev->path.i2c.device, |
| 20 | .mode_10bit = dev->path.i2c.mode_10bit, |
Furquan Shaikh | dc8679c | 2019-02-13 22:37:26 -0800 | [diff] [blame] | 21 | .speed = config->bus_speed ? : I2C_SPEED_FAST, |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 22 | .resource = scope, |
| 23 | }; |
| 24 | struct acpi_dp *dp; |
| 25 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 26 | if (!scope) { |
Caveh Jalali | c8e4dcb | 2020-04-21 05:00:48 -0700 | [diff] [blame] | 27 | printk(BIOS_ERR, "%s: dev not enabled\n", __func__); |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 28 | return; |
| 29 | } |
| 30 | |
| 31 | /* Device */ |
| 32 | acpigen_write_scope(scope); |
| 33 | acpigen_write_device(acpi_device_name(dev)); |
| 34 | acpigen_write_name_string("_HID", MAX98373_ACPI_HID); |
| 35 | acpigen_write_name_integer("_UID", config->uid); |
| 36 | if (config->desc) |
| 37 | acpigen_write_name_string("_DDN", config->desc); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 38 | acpigen_write_STA(acpi_device_status(dev)); |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 39 | |
| 40 | /* Resources */ |
| 41 | acpigen_write_name("_CRS"); |
| 42 | acpigen_write_resourcetemplate_header(); |
| 43 | acpi_device_write_i2c(&i2c); |
| 44 | acpigen_write_resourcetemplate_footer(); |
| 45 | |
| 46 | /* Device Properties */ |
| 47 | dp = acpi_dp_new_table("_DSD"); |
| 48 | |
Sathyanarayana Nujella | adb176b | 2018-05-24 23:46:51 -0700 | [diff] [blame] | 49 | if (config->interleave_mode) |
| 50 | acpi_dp_add_integer(dp, "maxim,interleave_mode", |
| 51 | config->interleave_mode); |
| 52 | acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no); |
| 53 | acpi_dp_add_integer(dp, "maxim,imon-slot-no", config->imon_slot_no); |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 54 | |
| 55 | acpi_dp_write(dp); |
| 56 | |
| 57 | acpigen_pop_len(); /* Device */ |
| 58 | acpigen_pop_len(); /* Scope */ |
| 59 | |
| 60 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 61 | dev->chip_ops->name, dev->path.i2c.device); |
| 62 | } |
| 63 | |
| 64 | static const char *max98373_acpi_name(const struct device *dev) |
| 65 | { |
| 66 | struct drivers_i2c_max98373_config *config = dev->chip_info; |
| 67 | |
| 68 | if (config->name) |
| 69 | return config->name; |
| 70 | |
| 71 | return MAX98373_ACPI_NAME; |
| 72 | } |
| 73 | |
| 74 | static struct device_operations max98373_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 75 | .read_resources = noop_read_resources, |
| 76 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 77 | .acpi_name = max98373_acpi_name, |
| 78 | .acpi_fill_ssdt = max98373_fill_ssdt, |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static void max98373_enable(struct device *dev) |
| 82 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 83 | struct drivers_i2c_max98373_config *config = dev->chip_info; |
| 84 | |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 85 | dev->ops = &max98373_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 86 | |
| 87 | if (config && config->desc) { |
| 88 | dev->name = config->desc; |
| 89 | } |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | struct chip_operations drivers_i2c_max98373_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame^] | 93 | .name = "Maxim MAX98373 Codec", |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 94 | .enable_dev = max98373_enable |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 95 | }; |