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