1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
5 //
6 // Copyright(c) 2023 Advanced Micro Devices, Inc. All rights reserved.
7 //
8 // Authors: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
9
10 /*
11 * SDW AMD ACPI scan helper function
12 */
13
14 #include <linux/acpi.h>
15 #include <linux/bits.h>
16 #include <linux/bitfield.h>
17 #include <linux/device.h>
18 #include <linux/errno.h>
19 #include <linux/export.h>
20 #include <linux/fwnode.h>
21 #include <linux/module.h>
22 #include <linux/soundwire/sdw_amd.h>
23 #include <linux/string.h>
24
amd_sdw_scan_controller(struct sdw_amd_acpi_info * info)25 int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info)
26 {
27 struct acpi_device *adev = acpi_fetch_acpi_dev(info->handle);
28 u32 sdw_bitmap = 0;
29 u8 count = 0;
30 int ret;
31
32 if (!adev)
33 return -EINVAL;
34
35 /* Found controller, find links supported */
36 ret = fwnode_property_read_u32_array(acpi_fwnode_handle(adev),
37 "mipi-sdw-manager-list", &sdw_bitmap, 1);
38 if (ret) {
39 dev_err(&adev->dev,
40 "Failed to read mipi-sdw-manager-list: %d\n", ret);
41 return -EINVAL;
42 }
43 count = hweight32(sdw_bitmap);
44 /* Check count is within bounds */
45 if (count > info->count) {
46 dev_err(&adev->dev, "Manager count %d exceeds max %d\n",
47 count, info->count);
48 return -EINVAL;
49 }
50
51 if (!count) {
52 dev_dbg(&adev->dev, "No SoundWire Managers detected\n");
53 return -EINVAL;
54 }
55 dev_dbg(&adev->dev, "ACPI reports %d SoundWire Manager devices\n", count);
56 info->link_mask = sdw_bitmap;
57 return 0;
58 }
59 EXPORT_SYMBOL_NS(amd_sdw_scan_controller, SND_AMD_SOUNDWIRE_ACPI);
60
61 MODULE_LICENSE("Dual BSD/GPL");
62 MODULE_DESCRIPTION("AMD SoundWire ACPI helpers");
63