Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi.h> |
| 5 | #include <arch/acpi_device.h> |
| 6 | #include <arch/acpigen.h> |
| 7 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 8 | #include <device/i2c_simple.h> |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/path.h> |
| 11 | #include <stdint.h> |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 12 | #include "chip.h" |
| 13 | |
| 14 | #define MAX98927_ACPI_NAME "MAXI" |
| 15 | #define MAX98927_ACPI_HID "MX98927" |
| 16 | |
| 17 | static void max98927_fill_ssdt(struct device *dev) |
| 18 | { |
| 19 | struct drivers_i2c_max98927_config *config = dev->chip_info; |
| 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 = config->bus_speed ? : I2C_SPEED_FAST, |
| 25 | .resource = scope, |
| 26 | }; |
| 27 | struct acpi_dp *dp; |
| 28 | |
| 29 | if (!dev->enabled || !scope) |
| 30 | return; |
| 31 | |
| 32 | /* Device */ |
| 33 | acpigen_write_scope(scope); |
| 34 | acpigen_write_device(acpi_device_name(dev)); |
| 35 | acpigen_write_name_string("_HID", MAX98927_ACPI_HID); |
| 36 | acpigen_write_name_integer("_UID", config->uid); |
| 37 | if (config->desc) |
| 38 | acpigen_write_name_string("_DDN", config->desc); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 39 | acpigen_write_STA(acpi_device_status(dev)); |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 40 | |
| 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 | |
| 50 | acpi_dp_add_integer(dp, "interleave_mode", config->interleave_mode); |
Harsha Priya | 1517735 | 2017-08-24 14:35:28 -0700 | [diff] [blame] | 51 | acpi_dp_add_integer(dp, "vmon-slot-no", config->vmon_slot_no); |
| 52 | acpi_dp_add_integer(dp, "imon-slot-no", config->imon_slot_no); |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 53 | |
| 54 | acpi_dp_write(dp); |
| 55 | |
| 56 | acpigen_pop_len(); /* Device */ |
| 57 | acpigen_pop_len(); /* Scope */ |
| 58 | |
| 59 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 60 | dev->chip_ops->name, dev->path.i2c.device); |
| 61 | } |
| 62 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 63 | static const char *max98927_acpi_name(const struct device *dev) |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 64 | { |
| 65 | struct drivers_i2c_max98927_config *config = dev->chip_info; |
| 66 | |
| 67 | if (config->name) |
| 68 | return config->name; |
| 69 | |
| 70 | return MAX98927_ACPI_NAME; |
| 71 | } |
| 72 | |
| 73 | static struct device_operations max98927_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame^] | 74 | .read_resources = noop_read_resources, |
| 75 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 76 | .acpi_name = max98927_acpi_name, |
| 77 | .acpi_fill_ssdt = max98927_fill_ssdt, |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | static void max98927_enable(struct device *dev) |
| 81 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 82 | struct drivers_i2c_max98927_config *config = dev->chip_info; |
| 83 | |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 84 | dev->ops = &max98927_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 85 | |
| 86 | if (config && config->desc) { |
| 87 | dev->name = config->desc; |
| 88 | } |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | struct chip_operations drivers_i2c_max98927_ops = { |
| 92 | CHIP_NAME("Maxim MAX98927 Codec") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 93 | .enable_dev = max98927_enable |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 94 | }; |