1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /*
3  * Copyright (C) 2023-24 Advanced Micro Devices, Inc. All rights reserved.
4  */
5 
6 #ifndef __SDW_AMD_H
7 #define __SDW_AMD_H
8 
9 #include <linux/acpi.h>
10 #include <linux/soundwire/sdw.h>
11 
12 /* AMD pm_runtime quirk definitions */
13 
14 /*
15  * Force the clock to stop(ClockStopMode0) when suspend callback
16  * is invoked.
17  */
18 #define AMD_SDW_CLK_STOP_MODE		1
19 
20 /*
21  * Stop the bus when runtime suspend/system level suspend callback
22  * is invoked. If set, a complete bus reset and re-enumeration will
23  * be performed when the bus restarts. In-band wake interrupts are
24  * not supported in this mode.
25  */
26 #define AMD_SDW_POWER_OFF_MODE		2
27 #define ACP_SDW0	0
28 #define ACP_SDW1	1
29 #define AMD_SDW_MAX_MANAGER_COUNT	2
30 #define ACP63_PCI_REV_ID		0x63
31 
32 struct acp_sdw_pdata {
33 	u16 instance;
34 	u32 acp_rev;
35 	/* mutex to protect acp common register access */
36 	struct mutex *acp_sdw_lock;
37 };
38 
39 /**
40  * struct sdw_amd_dai_runtime: AMD sdw dai runtime  data
41  *
42  * @name: SoundWire stream name
43  * @stream: stream runtime
44  * @bus: Bus handle
45  * @stream_type: Stream type
46  */
47 struct sdw_amd_dai_runtime {
48 	char *name;
49 	struct sdw_stream_runtime *stream;
50 	struct sdw_bus *bus;
51 	enum sdw_stream_type stream_type;
52 };
53 
54 /**
55  * struct amd_sdw_manager - amd manager driver context
56  * @bus: bus handle
57  * @dev: linux device
58  * @mmio: SoundWire registers mmio base
59  * @acp_mmio: acp registers mmio base
60  * @amd_sdw_irq_thread: SoundWire manager irq workqueue
61  * @amd_sdw_work: peripheral status work queue
62  * @acp_sdw_lock: mutex to protect acp share register access
63  * @status: peripheral devices status array
64  * @num_din_ports: number of input ports
65  * @num_dout_ports: number of output ports
66  * @cols_index: Column index in frame shape
67  * @rows_index: Rows index in frame shape
68  * @instance: SoundWire manager instance
69  * @quirks: SoundWire manager quirks
70  * @wake_en_mask: wake enable mask per SoundWire manager
71  * @acp_rev: acp pci device revision id
72  * @clk_stopped: flag set to true when clock is stopped
73  * @power_mode_mask: flag interprets amd SoundWire manager power mode
74  * @dai_runtime_array: dai runtime array
75  */
76 struct amd_sdw_manager {
77 	struct sdw_bus bus;
78 	struct device *dev;
79 
80 	void __iomem *mmio;
81 	void __iomem *acp_mmio;
82 
83 	struct work_struct amd_sdw_irq_thread;
84 	struct work_struct amd_sdw_work;
85 	/* mutex to protect acp common register access */
86 	struct mutex *acp_sdw_lock;
87 
88 	enum sdw_slave_status status[SDW_MAX_DEVICES + 1];
89 
90 	int num_din_ports;
91 	int num_dout_ports;
92 
93 	int cols_index;
94 	int rows_index;
95 
96 	u32 instance;
97 	u32 quirks;
98 	u32 wake_en_mask;
99 	u32 power_mode_mask;
100 	u32 acp_rev;
101 	bool clk_stopped;
102 
103 	struct sdw_amd_dai_runtime **dai_runtime_array;
104 };
105 
106 /**
107  * struct sdw_amd_acpi_info - Soundwire AMD information found in ACPI tables
108  * @handle: ACPI controller handle
109  * @count: maximum no of soundwire manager links supported on AMD platform.
110  * @link_mask: bit-wise mask listing links enabled by BIOS menu
111  */
112 struct sdw_amd_acpi_info {
113 	acpi_handle handle;
114 	int count;
115 	u32 link_mask;
116 };
117 
118 /**
119  * struct sdw_amd_ctx - context allocated by the controller driver probe
120  *
121  * @count: link count
122  * @link_mask: bit-wise mask listing SoundWire links reported by the
123  * Controller
124  * @pdev: platform device structure
125  * @peripherals: array representing Peripherals exposed across all enabled links
126  */
127 struct sdw_amd_ctx {
128 	int count;
129 	u32 link_mask;
130 	struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
131 	struct sdw_peripherals *peripherals;
132 };
133 
134 /**
135  * struct sdw_amd_res - Soundwire AMD global resource structure,
136  * typically populated by the DSP driver/Legacy driver
137  *
138  * @acp_rev: acp pci device revision id
139  * @addr: acp pci device resource start address
140  * @reg_range: ACP register range
141  * @link_mask: bit-wise mask listing links selected by the DSP driver/
142  * legacy driver
143  * @count: link count
144  * @mmio_base: mmio base of SoundWire registers
145  * @handle: ACPI parent handle
146  * @parent: parent device
147  * @dev: device implementing hwparams and free callbacks
148  * @acp_lock: mutex protecting acp common registers access
149  */
150 struct sdw_amd_res {
151 	u32 acp_rev;
152 	u32 addr;
153 	u32 reg_range;
154 	u32 link_mask;
155 	int count;
156 	void __iomem *mmio_base;
157 	acpi_handle handle;
158 	struct device *parent;
159 	struct device *dev;
160 	/* use to protect acp common registers access */
161 	struct mutex *acp_lock;
162 };
163 
164 int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **ctx);
165 
166 void sdw_amd_exit(struct sdw_amd_ctx *ctx);
167 
168 int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx);
169 
170 int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
171 #endif
172