Duncan Laurie | c2891f1 | 2020-04-29 12:34:38 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
| 4 | #include <acpi/acpi_device.h> |
| 5 | #include <acpi/acpi_soundwire.h> |
| 6 | #include <commonlib/helpers.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
| 9 | #include <device/soundwire.h> |
| 10 | #include <stdbool.h> |
Duncan Laurie | c2891f1 | 2020-04-29 12:34:38 -0700 | [diff] [blame] | 11 | |
| 12 | #include "soundwire.h" |
| 13 | #include "chip.h" |
| 14 | |
| 15 | __weak int soc_fill_soundwire_controller(struct intel_soundwire_controller **controller) |
| 16 | { |
| 17 | return -1; |
| 18 | } |
| 19 | |
| 20 | static bool link_enabled(const struct device *dev, unsigned int link) |
| 21 | { |
| 22 | struct device *child; |
| 23 | |
| 24 | for (child = dev->link_list->children; child; child = child->sibling) { |
| 25 | if (child->enabled && child->path.type == DEVICE_PATH_GENERIC && |
| 26 | child->path.generic.id == link) |
| 27 | return true; |
| 28 | } |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | static void intel_soundwire_link_prop_cb(struct acpi_dp *dsd, unsigned int id, |
| 33 | const struct soundwire_controller *controller) |
| 34 | { |
| 35 | struct intel_soundwire_controller *intel_controller = |
| 36 | container_of(controller, struct intel_soundwire_controller, sdw); |
| 37 | unsigned int quirk_mask = intel_controller->quirk_mask; |
| 38 | |
| 39 | /* Disable link if no are children enabled on this link device. */ |
| 40 | if (!link_enabled(intel_controller->dev, id)) |
| 41 | quirk_mask |= INTEL_SOUNDWIRE_QUIRK_BUS_DISABLE; |
| 42 | |
| 43 | acpi_dp_add_integer(dsd, "intel-sdw-ip-clock", intel_controller->ip_clock); |
| 44 | acpi_dp_add_integer(dsd, "intel-quirk-mask", quirk_mask); |
| 45 | } |
| 46 | |
| 47 | static void intel_soundwire_fill_ssdt(const struct device *dev) |
| 48 | { |
| 49 | struct acpi_dp *dsd; |
| 50 | struct intel_soundwire_controller *controller; |
| 51 | const char *scope = acpi_device_scope(dev); |
| 52 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame^] | 53 | if (!scope) |
Duncan Laurie | c2891f1 | 2020-04-29 12:34:38 -0700 | [diff] [blame] | 54 | return; |
| 55 | |
| 56 | if (soc_fill_soundwire_controller(&controller) < 0 || !controller) |
| 57 | return; |
| 58 | |
| 59 | /* Provide device pointer for link property callback function. */ |
| 60 | controller->dev = dev; |
| 61 | |
| 62 | acpigen_write_scope(scope); |
| 63 | acpigen_write_device(acpi_device_name(dev)); |
| 64 | acpigen_write_name_string("_DDN", dev->chip_ops->name); |
| 65 | acpigen_write_name_integer("_ADR", controller->acpi_address); |
| 66 | acpigen_write_name_string("_CID", ACPI_HID_CONTAINER); |
| 67 | |
| 68 | acpigen_write_STA(acpi_device_status(dev)); |
| 69 | |
| 70 | dsd = acpi_dp_new_table("_DSD"); |
| 71 | soundwire_gen_controller(dsd, &controller->sdw, &intel_soundwire_link_prop_cb); |
| 72 | acpi_dp_write(dsd); |
| 73 | |
| 74 | acpigen_pop_len(); /* Device */ |
| 75 | acpigen_pop_len(); /* Scope */ |
| 76 | } |
| 77 | |
| 78 | static const char *intel_soundwire_acpi_name(const struct device *dev) |
| 79 | { |
| 80 | return "SNDW"; |
| 81 | } |
| 82 | |
| 83 | static struct device_operations intel_soundwire_ops = { |
| 84 | .read_resources = noop_read_resources, |
| 85 | .set_resources = noop_set_resources, |
| 86 | .acpi_name = intel_soundwire_acpi_name, |
| 87 | .acpi_fill_ssdt = intel_soundwire_fill_ssdt, |
| 88 | .scan_bus = scan_static_bus, |
| 89 | }; |
| 90 | |
| 91 | static void intel_soundwire_enable(struct device *dev) |
| 92 | { |
| 93 | dev->ops = &intel_soundwire_ops; |
| 94 | } |
| 95 | |
| 96 | struct chip_operations drivers_intel_soundwire_ops = { |
| 97 | CHIP_NAME("Intel SoundWire Controller") |
| 98 | .enable_dev = intel_soundwire_enable |
| 99 | }; |