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