N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [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> |
| 20 | #include <device/i2c_simple.h> |
| 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 MAX98373_ACPI_NAME "MAXI" |
| 28 | #define MAX98373_ACPI_HID "MX98373" |
| 29 | |
| 30 | static void max98373_fill_ssdt(struct device *dev) |
| 31 | { |
| 32 | struct drivers_i2c_max98373_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_STANDARD, |
| 38 | .resource = scope, |
| 39 | }; |
| 40 | struct acpi_dp *dp; |
| 41 | |
| 42 | if (!dev->enabled || !scope) { |
| 43 | printk(BIOS_ERR, "%s: dev not enabled", __func__); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | /* Device */ |
| 48 | acpigen_write_scope(scope); |
| 49 | acpigen_write_device(acpi_device_name(dev)); |
| 50 | acpigen_write_name_string("_HID", MAX98373_ACPI_HID); |
| 51 | acpigen_write_name_integer("_UID", config->uid); |
| 52 | if (config->desc) |
| 53 | acpigen_write_name_string("_DDN", config->desc); |
| 54 | acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON); |
| 55 | |
| 56 | /* Resources */ |
| 57 | acpigen_write_name("_CRS"); |
| 58 | acpigen_write_resourcetemplate_header(); |
| 59 | acpi_device_write_i2c(&i2c); |
| 60 | acpigen_write_resourcetemplate_footer(); |
| 61 | |
| 62 | /* Device Properties */ |
| 63 | dp = acpi_dp_new_table("_DSD"); |
| 64 | |
Sathyanarayana Nujella | adb176b | 2018-05-24 23:46:51 -0700 | [diff] [blame] | 65 | if (config->interleave_mode) |
| 66 | acpi_dp_add_integer(dp, "maxim,interleave_mode", |
| 67 | config->interleave_mode); |
| 68 | acpi_dp_add_integer(dp, "maxim,vmon-slot-no", config->vmon_slot_no); |
| 69 | 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] | 70 | |
| 71 | acpi_dp_write(dp); |
| 72 | |
| 73 | acpigen_pop_len(); /* Device */ |
| 74 | acpigen_pop_len(); /* Scope */ |
| 75 | |
| 76 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 77 | dev->chip_ops->name, dev->path.i2c.device); |
| 78 | } |
| 79 | |
| 80 | static const char *max98373_acpi_name(const struct device *dev) |
| 81 | { |
| 82 | struct drivers_i2c_max98373_config *config = dev->chip_info; |
| 83 | |
| 84 | if (config->name) |
| 85 | return config->name; |
| 86 | |
| 87 | return MAX98373_ACPI_NAME; |
| 88 | } |
| 89 | |
| 90 | static struct device_operations max98373_ops = { |
| 91 | .read_resources = DEVICE_NOOP, |
| 92 | .set_resources = DEVICE_NOOP, |
| 93 | .enable_resources = DEVICE_NOOP, |
| 94 | .acpi_name = &max98373_acpi_name, |
| 95 | .acpi_fill_ssdt_generator = &max98373_fill_ssdt, |
| 96 | }; |
| 97 | |
| 98 | static void max98373_enable(struct device *dev) |
| 99 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 100 | struct drivers_i2c_max98373_config *config = dev->chip_info; |
| 101 | |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 102 | dev->ops = &max98373_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 103 | |
| 104 | if (config && config->desc) { |
| 105 | dev->name = config->desc; |
| 106 | } |
N, Harshapriya | c14a99f | 2017-11-27 15:38:53 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | struct chip_operations drivers_i2c_max98373_ops = { |
| 110 | CHIP_NAME("Maxim MAX98373 Codec") |
| 111 | .enable_dev = &max98373_enable |
| 112 | }; |