xref: /linux/include/sound/sdca_class.h (revision 3273ec3e149ade420500014d442e4159bcc0d264)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * The MIPI SDCA specification is available for public downloads at
4  * https://www.mipi.org/mipi-sdca-v1-0-download
5  *
6  * Copyright (C) 2025 Cirrus Logic, Inc. and
7  *                    Cirrus Logic International Semiconductor Ltd.
8  */
9 
10 #ifndef __SDCA_CLASS_H__
11 #define __SDCA_CLASS_H__
12 
13 #include <linux/completion.h>
14 #include <linux/mutex.h>
15 #include <linux/workqueue.h>
16 
17 struct device;
18 struct regmap;
19 struct sdw_slave;
20 struct sdca_function_data;
21 
22 /**
23  * struct sdca_class_ops - optional codec-provided class callbacks
24  * @populate_function: fill @function (entities, clusters, init_table, ...)
25  *           from static tables in place of sdca_parse_function() on
26  *           DT/non-DisCo platforms.  Called once per SDCA function with
27  *           @dev pointing at that function's device.  Pure data source;
28  *           performs no bus I/O.  Return 0 on success or a negative errno.
29  */
30 struct sdca_class_ops {
31 	int (*populate_function)(struct device *dev,
32 				 struct sdca_function_data *function);
33 };
34 
35 struct sdca_class_drv {
36 	struct device *dev;
37 	struct regmap *dev_regmap;
38 	struct sdw_slave *sdw;
39 
40 	struct sdca_interrupt_info *irq_info;
41 
42 	const struct sdca_class_ops *ops;
43 
44 	struct mutex regmap_lock;
45 	/* Serialise function initialisations */
46 	struct mutex init_lock;
47 	struct work_struct boot_work;
48 };
49 
50 /* Library helpers used by codec-specific SDCA SoundWire drivers. */
51 int sdca_class_probe(struct sdw_slave *sdw,
52 		     struct sdca_class_drv *drv,
53 		     const struct sdca_class_ops *ops);
54 void sdca_class_remove(struct sdca_class_drv *drv);
55 
56 /*
57  * PM helpers.  Codec drivers embed sdca_class_drv in their own priv,
58  * own dev_set_drvdata(), and compose these into their own dev_pm_ops:
59  *
60  *	static int wcd_runtime_suspend(struct device *dev) {
61  *		struct wcd_priv *priv = dev_get_drvdata(dev);
62  *		return sdca_class_runtime_suspend(&priv->class);
63  *	}
64  */
65 int sdca_class_runtime_suspend(struct sdca_class_drv *drv);
66 int sdca_class_runtime_resume(struct sdca_class_drv *drv);
67 int sdca_class_system_suspend(struct sdca_class_drv *drv);
68 int sdca_class_system_resume(struct sdca_class_drv *drv);
69 
70 #endif /* __SDCA_CLASS_H__ */
71