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