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 #define ACP70_PCI_REV_ID		0x70
32 #define ACP71_PCI_REV_ID		0x71
33 
34 struct acp_sdw_pdata {
35 	u16 instance;
36 	u32 acp_rev;
37 	/* mutex to protect acp common register access */
38 	struct mutex *acp_sdw_lock;
39 };
40 
41 /**
42  * struct sdw_amd_dai_runtime: AMD sdw dai runtime  data
43  *
44  * @name: SoundWire stream name
45  * @stream: stream runtime
46  * @bus: Bus handle
47  * @stream_type: Stream type
48  */
49 struct sdw_amd_dai_runtime {
50 	char *name;
51 	struct sdw_stream_runtime *stream;
52 	struct sdw_bus *bus;
53 	enum sdw_stream_type stream_type;
54 };
55 
56 /**
57  * struct amd_sdw_manager - amd manager driver context
58  * @bus: bus handle
59  * @dev: linux device
60  * @mmio: SoundWire registers mmio base
61  * @acp_mmio: acp registers mmio base
62  * @amd_sdw_irq_thread: SoundWire manager irq workqueue
63  * @amd_sdw_work: peripheral status work queue
64  * @acp_sdw_lock: mutex to protect acp share register access
65  * @status: peripheral devices status array
66  * @num_din_ports: number of input ports
67  * @num_dout_ports: number of output ports
68  * @cols_index: Column index in frame shape
69  * @rows_index: Rows index in frame shape
70  * @instance: SoundWire manager instance
71  * @quirks: SoundWire manager quirks
72  * @wake_en_mask: wake enable mask per SoundWire manager
73  * @acp_rev: acp pci device revision id
74  * @clk_stopped: flag set to true when clock is stopped
75  * @power_mode_mask: flag interprets amd SoundWire manager power mode
76  * @dai_runtime_array: dai runtime array
77  */
78 struct amd_sdw_manager {
79 	struct sdw_bus bus;
80 	struct device *dev;
81 
82 	void __iomem *mmio;
83 	void __iomem *acp_mmio;
84 
85 	struct work_struct amd_sdw_irq_thread;
86 	struct work_struct amd_sdw_work;
87 	/* mutex to protect acp common register access */
88 	struct mutex *acp_sdw_lock;
89 
90 	enum sdw_slave_status status[SDW_MAX_DEVICES + 1];
91 
92 	int num_din_ports;
93 	int num_dout_ports;
94 
95 	int cols_index;
96 	int rows_index;
97 
98 	u32 instance;
99 	u32 quirks;
100 	u32 wake_en_mask;
101 	u32 power_mode_mask;
102 	u32 acp_rev;
103 	bool clk_stopped;
104 
105 	struct sdw_amd_dai_runtime **dai_runtime_array;
106 };
107 
108 /**
109  * struct sdw_amd_acpi_info - Soundwire AMD information found in ACPI tables
110  * @handle: ACPI controller handle
111  * @count: maximum no of soundwire manager links supported on AMD platform.
112  * @link_mask: bit-wise mask listing links enabled by BIOS menu
113  */
114 struct sdw_amd_acpi_info {
115 	acpi_handle handle;
116 	int count;
117 	u32 link_mask;
118 };
119 
120 /**
121  * struct sdw_amd_ctx - context allocated by the controller driver probe
122  *
123  * @count: link count
124  * @link_mask: bit-wise mask listing SoundWire links reported by the
125  * Controller
126  * @pdev: platform device structure
127  * @peripherals: array representing Peripherals exposed across all enabled links
128  */
129 struct sdw_amd_ctx {
130 	int count;
131 	u32 link_mask;
132 	struct platform_device *pdev[AMD_SDW_MAX_MANAGER_COUNT];
133 	struct sdw_peripherals *peripherals;
134 };
135 
136 /**
137  * struct sdw_amd_res - Soundwire AMD global resource structure,
138  * typically populated by the DSP driver/Legacy driver
139  *
140  * @acp_rev: acp pci device revision id
141  * @addr: acp pci device resource start address
142  * @reg_range: ACP register range
143  * @link_mask: bit-wise mask listing links selected by the DSP driver/
144  * legacy driver
145  * @count: link count
146  * @mmio_base: mmio base of SoundWire registers
147  * @handle: ACPI parent handle
148  * @parent: parent device
149  * @dev: device implementing hwparams and free callbacks
150  * @acp_lock: mutex protecting acp common registers access
151  */
152 struct sdw_amd_res {
153 	u32 acp_rev;
154 	u32 addr;
155 	u32 reg_range;
156 	u32 link_mask;
157 	int count;
158 	void __iomem *mmio_base;
159 	acpi_handle handle;
160 	struct device *parent;
161 	struct device *dev;
162 	/* use to protect acp common registers access */
163 	struct mutex *acp_lock;
164 };
165 
166 int sdw_amd_probe(struct sdw_amd_res *res, struct sdw_amd_ctx **ctx);
167 
168 void sdw_amd_exit(struct sdw_amd_ctx *ctx);
169 
170 int sdw_amd_get_slave_info(struct sdw_amd_ctx *ctx);
171 
172 int amd_sdw_scan_controller(struct sdw_amd_acpi_info *info);
173 #endif
174