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"; |
Matt DeVillier | c4a81b39 | 2023-09-08 19:47:22 -0500 | [diff] [blame] | 22 | case rt1019: return "rt1019"; |
Matt DeVillier | 7f53e11 | 2023-09-22 11:47:22 -0500 | [diff] [blame] | 23 | case rt5650_sp: return "rt5650"; |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 24 | default: return "default"; |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 25 | } |
| 26 | } |
| 27 | |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 28 | static const char *get_jack_tplg_str(enum _jack_tplg tplg) |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 29 | { |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 30 | switch (tplg) { |
| 31 | case cs42l42: return "cs42l42"; |
| 32 | case da7219: return "da7219"; |
| 33 | case nau8825: return "nau8825"; |
Matt DeVillier | 7f53e11 | 2023-09-22 11:47:22 -0500 | [diff] [blame] | 34 | case rt5650_hp: return "rt5650"; |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 35 | case rt5682: return "rt5682"; |
| 36 | default: return "default"; |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 40 | static const char *get_mic_tplg_str(enum _mic_tplg tplg) |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 41 | { |
Matt DeVillier | 4c5ec21 | 2023-05-15 10:32:00 -0500 | [diff] [blame] | 42 | switch (tplg) { |
| 43 | case _1ch: return "1ch"; |
| 44 | case _2ch_pdm0: return "2ch-pdm0"; |
| 45 | case _2ch_pdm1: return "2ch-pdm1"; |
| 46 | case _4ch: return "4ch"; |
| 47 | default: return "default"; |
Matt DeVillier | 3a4ac3a | 2023-01-17 10:57:42 -0600 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | static void sof_fill_ssdt_generator(const struct device *dev) |
| 52 | { |
| 53 | struct drivers_sof_config *config = dev->chip_info; |
| 54 | const char *scope = acpi_device_scope(dev); |
| 55 | struct acpi_dp *dsd; |
| 56 | |
| 57 | if (!dev->enabled || !config || !scope) |
| 58 | return; |
| 59 | |
| 60 | /* Device */ |
| 61 | acpigen_write_scope(scope); |
| 62 | |
| 63 | /* DSD */ |
| 64 | dsd = acpi_dp_new_table("_DSD"); |
| 65 | acpi_dp_add_string(dsd, "speaker-tplg", |
| 66 | get_spkr_tplg_str(config->spkr_tplg)); |
| 67 | acpi_dp_add_string(dsd, "hp-tplg", |
| 68 | get_jack_tplg_str(config->jack_tplg)); |
| 69 | acpi_dp_add_string(dsd, "mic-tplg", |
| 70 | get_mic_tplg_str(config->mic_tplg)); |
| 71 | acpi_dp_write(dsd); |
| 72 | acpigen_pop_len(); /* Scope */ |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static struct device_operations sof_ops = { |
| 77 | .read_resources = noop_read_resources, |
| 78 | .set_resources = noop_set_resources, |
| 79 | .acpi_fill_ssdt = sof_fill_ssdt_generator, |
| 80 | }; |
| 81 | |
| 82 | static void sof_enable(struct device *dev) |
| 83 | { |
| 84 | dev->ops = &sof_ops; |
| 85 | } |
| 86 | |
| 87 | struct chip_operations drivers_sof_ops = { |
| 88 | CHIP_NAME("SOF") |
| 89 | .enable_dev = sof_enable |
| 90 | }; |