xref: /openbmc/linux/sound/aoa/aoa.h (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
1d6869352SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2f3d9478bSJohannes Berg /*
3f3d9478bSJohannes Berg  * Apple Onboard Audio definitions
4f3d9478bSJohannes Berg  *
5f3d9478bSJohannes Berg  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6f3d9478bSJohannes Berg  */
7f3d9478bSJohannes Berg 
8f3d9478bSJohannes Berg #ifndef __AOA_H
9f3d9478bSJohannes Berg #define __AOA_H
10f3d9478bSJohannes Berg #include <asm/prom.h>
11f3d9478bSJohannes Berg #include <linux/module.h>
12f3d9478bSJohannes Berg #include <sound/core.h>
13f3d9478bSJohannes Berg #include <sound/asound.h>
14f3d9478bSJohannes Berg #include <sound/control.h>
15f3d9478bSJohannes Berg #include "aoa-gpio.h"
16f3d9478bSJohannes Berg #include "soundbus/soundbus.h"
17f3d9478bSJohannes Berg 
18f3d9478bSJohannes Berg #define MAX_CODEC_NAME_LEN	32
19f3d9478bSJohannes Berg 
20f3d9478bSJohannes Berg struct aoa_codec {
21f3d9478bSJohannes Berg 	char	name[MAX_CODEC_NAME_LEN];
22f3d9478bSJohannes Berg 
23f3d9478bSJohannes Berg 	struct module *owner;
24f3d9478bSJohannes Berg 
25f3d9478bSJohannes Berg 	/* called when the fabric wants to init this codec.
26f3d9478bSJohannes Berg 	 * Do alsa card manipulations from here. */
27f3d9478bSJohannes Berg 	int (*init)(struct aoa_codec *codec);
28f3d9478bSJohannes Berg 
29f3d9478bSJohannes Berg 	/* called when the fabric is done with the codec.
30f3d9478bSJohannes Berg 	 * The alsa card will be cleaned up so don't bother. */
31f3d9478bSJohannes Berg 	void (*exit)(struct aoa_codec *codec);
32f3d9478bSJohannes Berg 
33f3d9478bSJohannes Berg 	/* May be NULL, but can be used by the fabric.
34f3d9478bSJohannes Berg 	 * Refcounting is the codec driver's responsibility */
35f3d9478bSJohannes Berg 	struct device_node *node;
36f3d9478bSJohannes Berg 
37f3d9478bSJohannes Berg 	/* assigned by fabric before init() is called, points
38f3d9478bSJohannes Berg 	 * to the soundbus device. Cannot be NULL. */
39f3d9478bSJohannes Berg 	struct soundbus_dev *soundbus_dev;
40f3d9478bSJohannes Berg 
41f3d9478bSJohannes Berg 	/* assigned by the fabric before init() is called, points
42f3d9478bSJohannes Berg 	 * to the fabric's gpio runtime record for the relevant
43f3d9478bSJohannes Berg 	 * device. */
44f3d9478bSJohannes Berg 	struct gpio_runtime *gpio;
45f3d9478bSJohannes Berg 
46f3d9478bSJohannes Berg 	/* assigned by the fabric before init() is called, contains
47f3d9478bSJohannes Berg 	 * a codec specific bitmask of what outputs and inputs are
48f3d9478bSJohannes Berg 	 * actually connected */
49f3d9478bSJohannes Berg 	u32 connected;
50f3d9478bSJohannes Berg 
51f3d9478bSJohannes Berg 	/* data the fabric can associate with this structure */
52f3d9478bSJohannes Berg 	void *fabric_data;
53f3d9478bSJohannes Berg 
54f3d9478bSJohannes Berg 	/* private! */
55f3d9478bSJohannes Berg 	struct list_head list;
56f3d9478bSJohannes Berg 	struct aoa_fabric *fabric;
57f3d9478bSJohannes Berg };
58f3d9478bSJohannes Berg 
59f3d9478bSJohannes Berg /* return 0 on success */
60f3d9478bSJohannes Berg extern int
61f3d9478bSJohannes Berg aoa_codec_register(struct aoa_codec *codec);
62f3d9478bSJohannes Berg extern void
63f3d9478bSJohannes Berg aoa_codec_unregister(struct aoa_codec *codec);
64f3d9478bSJohannes Berg 
65f3d9478bSJohannes Berg #define MAX_LAYOUT_NAME_LEN	32
66f3d9478bSJohannes Berg 
67f3d9478bSJohannes Berg struct aoa_fabric {
68f3d9478bSJohannes Berg 	char	name[MAX_LAYOUT_NAME_LEN];
69f3d9478bSJohannes Berg 
70f3d9478bSJohannes Berg 	struct module *owner;
71f3d9478bSJohannes Berg 
72f3d9478bSJohannes Berg 	/* once codecs register, they are passed here after.
73f3d9478bSJohannes Berg 	 * They are of course not initialised, since the
74f3d9478bSJohannes Berg 	 * fabric is responsible for initialising some fields
75f3d9478bSJohannes Berg 	 * in the codec structure! */
76f3d9478bSJohannes Berg 	int (*found_codec)(struct aoa_codec *codec);
77f3d9478bSJohannes Berg 	/* called for each codec when it is removed,
78f3d9478bSJohannes Berg 	 * also in the case that aoa_fabric_unregister
79f3d9478bSJohannes Berg 	 * is called and all codecs are removed
80f3d9478bSJohannes Berg 	 * from this fabric.
81f3d9478bSJohannes Berg 	 * Also called if found_codec returned 0 but
82f3d9478bSJohannes Berg 	 * the codec couldn't initialise. */
83f3d9478bSJohannes Berg 	void (*remove_codec)(struct aoa_codec *codec);
84f3d9478bSJohannes Berg 	/* If found_codec returned 0, and the codec
85f3d9478bSJohannes Berg 	 * could be initialised, this is called. */
86f3d9478bSJohannes Berg 	void (*attached_codec)(struct aoa_codec *codec);
87f3d9478bSJohannes Berg };
88f3d9478bSJohannes Berg 
89f3d9478bSJohannes Berg /* return 0 on success, -EEXIST if another fabric is
90f3d9478bSJohannes Berg  * registered, -EALREADY if the same fabric is registered.
91f3d9478bSJohannes Berg  * Passing NULL can be used to test for the presence
92f3d9478bSJohannes Berg  * of another fabric, if -EALREADY is returned there is
93f3d9478bSJohannes Berg  * no other fabric present.
94f3d9478bSJohannes Berg  * In the case that the function returns -EALREADY
95f3d9478bSJohannes Berg  * and the fabric passed is not NULL, all codecs
96f3d9478bSJohannes Berg  * that are not assigned yet are passed to the fabric
97f3d9478bSJohannes Berg  * again for reconsideration. */
98f3d9478bSJohannes Berg extern int
9961e77107SOlaf Hering aoa_fabric_register(struct aoa_fabric *fabric, struct device *dev);
100f3d9478bSJohannes Berg 
101f3d9478bSJohannes Berg /* it is vital to call this when the fabric exits!
102f3d9478bSJohannes Berg  * When calling, the remove_codec will be called
103f3d9478bSJohannes Berg  * for all codecs, unless it is NULL. */
104f3d9478bSJohannes Berg extern void
105f3d9478bSJohannes Berg aoa_fabric_unregister(struct aoa_fabric *fabric);
106f3d9478bSJohannes Berg 
107f3d9478bSJohannes Berg /* if for some reason you want to get rid of a codec
108f3d9478bSJohannes Berg  * before the fabric is removed, use this.
109f3d9478bSJohannes Berg  * Note that remove_codec is called for it! */
110f3d9478bSJohannes Berg extern void
111f3d9478bSJohannes Berg aoa_fabric_unlink_codec(struct aoa_codec *codec);
112f3d9478bSJohannes Berg 
113f3d9478bSJohannes Berg /* alsa help methods */
114f3d9478bSJohannes Berg struct aoa_card {
115f3d9478bSJohannes Berg 	struct snd_card *alsa_card;
116f3d9478bSJohannes Berg };
117f3d9478bSJohannes Berg 
1189ce50543STakashi Iwai extern int aoa_snd_device_new(enum snd_device_type type,
119*e6f2a617STakashi Iwai 	void *device_data, const struct snd_device_ops *ops);
120f3d9478bSJohannes Berg extern struct snd_card *aoa_get_card(void);
121f3d9478bSJohannes Berg extern int aoa_snd_ctl_add(struct snd_kcontrol* control);
122f3d9478bSJohannes Berg 
123f3d9478bSJohannes Berg /* GPIO stuff */
124f3d9478bSJohannes Berg extern struct gpio_methods *pmf_gpio_methods;
125f3d9478bSJohannes Berg extern struct gpio_methods *ftr_gpio_methods;
126f3d9478bSJohannes Berg /* extern struct gpio_methods *map_gpio_methods; */
127f3d9478bSJohannes Berg 
128f3d9478bSJohannes Berg #endif /* __AOA_H */
129