1/* SPDX-License-Identifier: GPL-2.0-only */
2
3#ifndef __SOC_SOF_CLIENT_H
4#define __SOC_SOF_CLIENT_H
5
6#include <linux/auxiliary_bus.h>
7#include <linux/device.h>
8#include <linux/list.h>
9#include <sound/sof.h>
10
11struct sof_ipc_fw_version;
12struct sof_ipc_cmd_hdr;
13struct snd_sof_dev;
14struct dentry;
15
16struct sof_ipc4_fw_module;
17
18/**
19 * struct sof_client_dev - SOF client device
20 * @auxdev:	auxiliary device
21 * @sdev:	pointer to SOF core device struct
22 * @list:	item in SOF core client dev list
23 * @data:	device specific data
24 */
25struct sof_client_dev {
26	struct auxiliary_device auxdev;
27	struct snd_sof_dev *sdev;
28	struct list_head list;
29	void *data;
30};
31
32#define sof_client_dev_to_sof_dev(cdev)		((cdev)->sdev)
33
34#define auxiliary_dev_to_sof_client_dev(auxiliary_dev) \
35	container_of(auxiliary_dev, struct sof_client_dev, auxdev)
36
37#define dev_to_sof_client_dev(dev) \
38	container_of(to_auxiliary_dev(dev), struct sof_client_dev, auxdev)
39
40int sof_client_ipc_tx_message(struct sof_client_dev *cdev, void *ipc_msg,
41			      void *reply_data, size_t reply_bytes);
42static inline int sof_client_ipc_tx_message_no_reply(struct sof_client_dev *cdev, void *ipc_msg)
43{
44	return sof_client_ipc_tx_message(cdev, ipc_msg, NULL, 0);
45}
46int sof_client_ipc_set_get_data(struct sof_client_dev *cdev, void *ipc_msg,
47				bool set);
48
49struct sof_ipc4_fw_module *sof_client_ipc4_find_module(struct sof_client_dev *c, const guid_t *u);
50
51struct dentry *sof_client_get_debugfs_root(struct sof_client_dev *cdev);
52struct device *sof_client_get_dma_dev(struct sof_client_dev *cdev);
53const struct sof_ipc_fw_version *sof_client_get_fw_version(struct sof_client_dev *cdev);
54size_t sof_client_get_ipc_max_payload_size(struct sof_client_dev *cdev);
55enum sof_ipc_type sof_client_get_ipc_type(struct sof_client_dev *cdev);
56
57/* module refcount management of SOF core */
58int sof_client_core_module_get(struct sof_client_dev *cdev);
59void sof_client_core_module_put(struct sof_client_dev *cdev);
60
61/* IPC notification */
62typedef void (*sof_client_event_callback)(struct sof_client_dev *cdev, void *msg_buf);
63
64int sof_client_register_ipc_rx_handler(struct sof_client_dev *cdev,
65				       u32 ipc_msg_type,
66				       sof_client_event_callback callback);
67void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
68					  u32 ipc_msg_type);
69
70/* DSP state notification and query */
71typedef void (*sof_client_fw_state_callback)(struct sof_client_dev *cdev,
72					     enum sof_fw_state state);
73
74int sof_client_register_fw_state_handler(struct sof_client_dev *cdev,
75					 sof_client_fw_state_callback callback);
76void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev);
77enum sof_fw_state sof_client_get_fw_state(struct sof_client_dev *cdev);
78int sof_client_ipc_rx_message(struct sof_client_dev *cdev, void *ipc_msg, void *msg_buf);
79
80#endif /* __SOC_SOF_CLIENT_H */
81