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