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