Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2017 Intel Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi.h> |
| 17 | #include <arch/acpi_device.h> |
| 18 | #include <arch/acpigen.h> |
| 19 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 20 | #include <device/i2c_simple.h> |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/path.h> |
| 23 | #include <stdint.h> |
| 24 | #include <string.h> |
| 25 | #include "chip.h" |
| 26 | |
| 27 | #define MAX98927_ACPI_NAME "MAXI" |
| 28 | #define MAX98927_ACPI_HID "MX98927" |
| 29 | |
| 30 | static void max98927_fill_ssdt(struct device *dev) |
| 31 | { |
| 32 | struct drivers_i2c_max98927_config *config = dev->chip_info; |
| 33 | const char *scope = acpi_device_scope(dev); |
| 34 | struct acpi_i2c i2c = { |
| 35 | .address = dev->path.i2c.device, |
| 36 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 37 | .speed = config->bus_speed ? : I2C_SPEED_FAST, |
| 38 | .resource = scope, |
| 39 | }; |
| 40 | struct acpi_dp *dp; |
| 41 | |
| 42 | if (!dev->enabled || !scope) |
| 43 | return; |
| 44 | |
| 45 | /* Device */ |
| 46 | acpigen_write_scope(scope); |
| 47 | acpigen_write_device(acpi_device_name(dev)); |
| 48 | acpigen_write_name_string("_HID", MAX98927_ACPI_HID); |
| 49 | acpigen_write_name_integer("_UID", config->uid); |
| 50 | if (config->desc) |
| 51 | acpigen_write_name_string("_DDN", config->desc); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame^] | 52 | acpigen_write_STA(acpi_device_status(dev)); |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 53 | |
| 54 | /* Resources */ |
| 55 | acpigen_write_name("_CRS"); |
| 56 | acpigen_write_resourcetemplate_header(); |
| 57 | acpi_device_write_i2c(&i2c); |
| 58 | acpigen_write_resourcetemplate_footer(); |
| 59 | |
| 60 | /* Device Properties */ |
| 61 | dp = acpi_dp_new_table("_DSD"); |
| 62 | |
| 63 | acpi_dp_add_integer(dp, "interleave_mode", config->interleave_mode); |
Harsha Priya | 1517735 | 2017-08-24 14:35:28 -0700 | [diff] [blame] | 64 | acpi_dp_add_integer(dp, "vmon-slot-no", config->vmon_slot_no); |
| 65 | acpi_dp_add_integer(dp, "imon-slot-no", config->imon_slot_no); |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 66 | |
| 67 | acpi_dp_write(dp); |
| 68 | |
| 69 | acpigen_pop_len(); /* Device */ |
| 70 | acpigen_pop_len(); /* Scope */ |
| 71 | |
| 72 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 73 | dev->chip_ops->name, dev->path.i2c.device); |
| 74 | } |
| 75 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 76 | static const char *max98927_acpi_name(const struct device *dev) |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 77 | { |
| 78 | struct drivers_i2c_max98927_config *config = dev->chip_info; |
| 79 | |
| 80 | if (config->name) |
| 81 | return config->name; |
| 82 | |
| 83 | return MAX98927_ACPI_NAME; |
| 84 | } |
| 85 | |
| 86 | static struct device_operations max98927_ops = { |
| 87 | .read_resources = DEVICE_NOOP, |
| 88 | .set_resources = DEVICE_NOOP, |
| 89 | .enable_resources = DEVICE_NOOP, |
| 90 | .acpi_name = &max98927_acpi_name, |
| 91 | .acpi_fill_ssdt_generator = &max98927_fill_ssdt, |
| 92 | }; |
| 93 | |
| 94 | static void max98927_enable(struct device *dev) |
| 95 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 96 | struct drivers_i2c_max98927_config *config = dev->chip_info; |
| 97 | |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 98 | dev->ops = &max98927_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 99 | |
| 100 | if (config && config->desc) { |
| 101 | dev->name = config->desc; |
| 102 | } |
Rizwan Qureshi | 4979d76 | 2017-01-13 22:17:01 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | struct chip_operations drivers_i2c_max98927_ops = { |
| 106 | CHIP_NAME("Maxim MAX98927 Codec") |
| 107 | .enable_dev = &max98927_enable |
| 108 | }; |