Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/path.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | #include "chip.h" |
| 10 | |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 11 | static const char *get_spkr_tplg_str(enum _spkr_tplg tplg) |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 12 | { |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 13 | switch (tplg) { |
| 14 | case max98373: return "max98373"; |
Matt DeVillier | e29b770 | 2023-05-15 10:36:59 -0500 | [diff] [blame] | 15 | case max98373_ssp2: return "max98373-ssp2"; |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 16 | case max98360a: return "max98360a"; |
| 17 | case max98357a: return "max98357a"; |
| 18 | case max98357a_tdm: return "max98357a-tdm"; |
| 19 | case max98390: return "max98390"; |
| 20 | case rt1011: return "rt1011"; |
| 21 | case rt1015: return "rt1015"; |
| 22 | default: return "default"; |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 26 | static const char *get_jack_tplg_str(enum _jack_tplg tplg) |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 27 | { |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 28 | switch (tplg) { |
| 29 | case cs42l42: return "cs42l42"; |
| 30 | case da7219: return "da7219"; |
| 31 | case nau8825: return "nau8825"; |
| 32 | case rt5682: return "rt5682"; |
| 33 | default: return "default"; |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 37 | static const char *get_mic_tplg_str(enum _mic_tplg tplg) |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 38 | { |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 39 | switch (tplg) { |
| 40 | case _1ch: return "1ch"; |
| 41 | case _2ch_pdm0: return "2ch-pdm0"; |
| 42 | case _2ch_pdm1: return "2ch-pdm1"; |
| 43 | case _4ch: return "4ch"; |
| 44 | default: return "default"; |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | static void sof_fill_ssdt_generator(const struct device *dev) |
| 49 | { |
| 50 | struct drivers_sof_config *config = dev->chip_info; |
| 51 | const char *scope = acpi_device_scope(dev); |
| 52 | struct acpi_dp *dsd; |
| 53 | |
| 54 | if (!dev->enabled || !config || !scope) |
| 55 | return; |
| 56 | |
| 57 | /* Device */ |
| 58 | acpigen_write_scope(scope); |
| 59 | |
| 60 | /* DSD */ |
| 61 | dsd = acpi_dp_new_table("_DSD"); |
| 62 | acpi_dp_add_string(dsd, "speaker-tplg", |
| 63 | get_spkr_tplg_str(config->spkr_tplg)); |
| 64 | acpi_dp_add_string(dsd, "hp-tplg", |
| 65 | get_jack_tplg_str(config->jack_tplg)); |
| 66 | acpi_dp_add_string(dsd, "mic-tplg", |
| 67 | get_mic_tplg_str(config->mic_tplg)); |
| 68 | acpi_dp_write(dsd); |
| 69 | acpigen_pop_len(); /* Scope */ |
| 70 | } |
| 71 | |
| 72 | |
| 73 | static struct device_operations sof_ops = { |
| 74 | .read_resources = noop_read_resources, |
| 75 | .set_resources = noop_set_resources, |
| 76 | .acpi_fill_ssdt = sof_fill_ssdt_generator, |
| 77 | }; |
| 78 | |
| 79 | static void sof_enable(struct device *dev) |
| 80 | { |
| 81 | dev->ops = &sof_ops; |
| 82 | } |
| 83 | |
| 84 | struct chip_operations drivers_sof_ops = { |
| 85 | CHIP_NAME("SOF") |
| 86 | .enable_dev = sof_enable |
| 87 | }; |