• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef AUDIO_SAPM_H
10 #define AUDIO_SAPM_H
11 
12 #include "audio_core.h"
13 
14 #ifdef __cplusplus
15 #if __cplusplus
16 extern "C" {
17 #endif
18 #endif /* __cplusplus */
19 
20 /* sapm widget types */
21 enum AudioSapmType {
22     AUDIO_SAPM_INPUT = 0,       /* input pin */
23     AUDIO_SAPM_OUTPUT,          /* output pin */
24     AUDIO_SAPM_MUX,             /* selects 1 analog signal from many inputs */
25     AUDIO_SAPM_DEMUX,           /* connects the input to one of multiple outputs */
26     AUDIO_SAPM_VIRT_MUX,        /* virtual version of snd_soc_dapm_mux */
27     AUDIO_SAPM_VALUE_MUX,       /* selects 1 analog signal from many inputs */
28     AUDIO_SAPM_MIXER,           /* mixes several analog signals together */
29     AUDIO_SAPM_MIXER_NAMED_CTRL, /* mixer with named controls */
30     AUDIO_SAPM_PGA,             /* programmable gain/attenuation (volume) */
31     AUDIO_SAPM_OUT_DRV,         /* output driver */
32     AUDIO_SAPM_ADC,             /* analog to digital converter */
33     AUDIO_SAPM_DAC,             /* digital to analog converter */
34     AUDIO_SAPM_MICBIAS,         /* microphone bias (power) */
35     AUDIO_SAPM_MIC,             /* microphone */
36     AUDIO_SAPM_HP,              /* headphones */
37     AUDIO_SAPM_SPK,             /* speaker */
38     AUDIO_SAPM_LINE,            /* line input/output */
39     AUDIO_SAPM_ANALOG_SWITCH,   /* analog switch */
40     AUDIO_SAPM_VMID,            /* codec bias/vmid - to minimise pops */
41     AUDIO_SAPM_PRE,             /* machine specific pre component - exec first */
42     AUDIO_SAPM_POST,            /* machine specific post component - exec last */
43     AUDIO_SAPM_SUPPLY,          /* power/clock supply */
44     AUDIO_SAPM_REGULATOR_SUPPLY, /* external regulator */
45     AUDIO_SAPM_CLOCK_SUPPLY,    /* external clock */
46     AUDIO_SAPM_AIF_IN,          /* audio interface input */
47     AUDIO_SAPM_AIF_OUT,         /* audio interface output */
48     AUDIO_SAPM_SIGGEN,          /* signal generator */
49     AUDIO_SAPM_SINK,
50 };
51 
52 enum AudioBiasLevel {
53     AUDIO_BIAS_OFF = 0,
54     AUDIO_BIAS_STANDBY = 1,
55     AUDIO_BIAS_PREPARE = 2,
56     AUDIO_BIAS_ON = 3,
57 };
58 
59 /* SAPM context */
60 struct AudioSapmContext {
61     int32_t componentNum; /* number of components in this context */
62     enum AudioBiasLevel biasLevel;
63     enum AudioBiasLevel suspendBiasLevel;
64 
65     struct CodecDevice *codec; /* parent codec */
66     struct PlatformDevice *platform; /* parent platform */
67     struct AudioCard *card; /* parent card */
68 
69     /* used during SAPM updates */
70     enum AudioBiasLevel targetBiasLevel;
71     struct DListHead list;
72 };
73 
74 /* enumerated kcontrol */
75 struct AudioEnumKcontrol {
76     uint32_t reg;
77     uint32_t reg2;
78     uint8_t shiftLeft;
79     uint8_t shiftRight;
80     uint32_t max;
81     uint32_t mask;
82     const char * const *texts;
83     const uint32_t *values;
84     void *sapm;
85 };
86 
87 /* sapm audio path between two components */
88 struct AudioSapmpath {
89     char *name;
90 
91     /* source (input) and sink (output) components */
92     struct AudioSapmComponent *source;
93     struct AudioSapmComponent *sink;
94     struct AudioKcontrol *kcontrol;
95 
96     /* status */
97     uint8_t connect; /* source and sink components are connected */
98     uint8_t walked; /* path has been walked */
99     uint8_t weak; /* path ignored for power management */
100 
101     int32_t (*connected)(struct AudioSapmComponent *source, struct AudioSapmComponent *sink);
102 
103     struct DListHead listSource;
104     struct DListHead listSink;
105     struct DListHead list;
106 };
107 
108 /* sapm component */
109 struct AudioSapmComponent {
110     enum AudioSapmType sapmType;
111     char *componentName; /* component name */
112     char *streamName; /* stream name */
113     struct AudioSapmContext *sapm;
114     struct CodecDevice *codec; /* parent codec */
115     struct AccessoryDevice *accessory; /* parent accessory */
116     struct PlatformDevice *platform; /* parent platform */
117 
118     /* sapm control */
119     int16_t reg; /* negative reg = no direct sapm */
120     uint8_t shift; /* bits to shift */
121     uint8_t invert; /* invert the power bit */
122     uint8_t mask;
123     uint8_t connected; /* connected codec pin */
124     uint8_t external; /* has external components */
125     uint8_t active; /* active stream on DAC, ADC's */
126     uint8_t newPower; /* power checked this run */
127     uint8_t power;
128     uint8_t newCpt;
129 
130     /* external events */
131     uint16_t eventFlags;   /* flags to specify event types */
132     int32_t (*Event)(struct AudioSapmComponent*, struct AudioKcontrol *, int32_t);
133 
134     /* power check callback */
135     int32_t (*PowerCheck)(const struct AudioSapmComponent *);
136 
137     /* kcontrols that relate to this component */
138     int32_t kcontrolsNum;
139     struct AudioKcontrol *kcontrolNews;
140     struct AudioKcontrol **kcontrols;
141 
142     struct DListHead list;
143 
144     /* component input and outputs */
145     struct DListHead sources;
146     struct DListHead sinks;
147 
148     /* used during SAPM updates */
149     struct DListHead powerList;
150     struct DListHead dirty;
151 
152     /* reserve clock interface */
153     int32_t (*PowerClockOp)(struct AudioSapmComponent *);
154 };
155 
156 struct AudioSapmRoute {
157     const char *sink;
158     const char *control;
159     const char *source;
160 
161     /* Note: currently only supported for links where source is a supply */
162     uint32_t (*Connected)(struct AudioSapmComponent *source,
163         struct AudioSapmComponent *sink);
164 };
165 
166 int32_t AudioSapmNewComponents(struct AudioCard *audioCard,
167     const struct AudioSapmComponent *component, int32_t cptMaxNum);
168 int32_t AudioSapmAddRoutes(struct AudioCard *audioCard,
169     const struct AudioSapmRoute *route, int32_t routeMaxNum);
170 int32_t AudioSapmNewControls(struct AudioCard *audioCard);
171 int32_t AudioSapmSleep(const struct AudioCard *audioCard);
172 int32_t AudioSampPowerUp(const struct AudioCard *card);
173 int32_t AudioSampSetPowerMonitor(struct AudioCard *card, bool powerMonitorState);
174 
175 int32_t AudioCodecSapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
176 int32_t AudioCodecSapmGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
177 int32_t AudioAccessorySapmSetCtrlOps(const struct AudioKcontrol *kcontrol, const struct AudioCtrlElemValue *elemValue);
178 int32_t AudioAccessorySapmGetCtrlOps(const struct AudioKcontrol *kcontrol, struct AudioCtrlElemValue *elemValue);
179 
180 #ifdef __cplusplus
181 #if __cplusplus
182 }
183 #endif
184 #endif /* __cplusplus */
185 
186 #endif /* AUDIO_SAPM_H */
187