Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
| 3 | * soc-component.h |
| 4 | * |
| 5 | * Copyright (c) 2019 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #ifndef __SOC_COMPONENT_H |
| 12 | #define __SOC_COMPONENT_H |
| 13 | |
| 14 | #include <sound/soc.h> |
| 15 | |
| 16 | /* |
| 17 | * Component probe and remove ordering levels for components with runtime |
| 18 | * dependencies. |
| 19 | */ |
| 20 | #define SND_SOC_COMP_ORDER_FIRST -2 |
| 21 | #define SND_SOC_COMP_ORDER_EARLY -1 |
| 22 | #define SND_SOC_COMP_ORDER_NORMAL 0 |
| 23 | #define SND_SOC_COMP_ORDER_LATE 1 |
| 24 | #define SND_SOC_COMP_ORDER_LAST 2 |
| 25 | |
| 26 | #define for_each_comp_order(order) \ |
| 27 | for (order = SND_SOC_COMP_ORDER_FIRST; \ |
| 28 | order <= SND_SOC_COMP_ORDER_LAST; \ |
| 29 | order++) |
| 30 | |
| 31 | /* component interface */ |
| 32 | struct snd_soc_component_driver { |
| 33 | const char *name; |
| 34 | |
| 35 | /* Default control and setup, added after probe() is run */ |
| 36 | const struct snd_kcontrol_new *controls; |
| 37 | unsigned int num_controls; |
| 38 | const struct snd_soc_dapm_widget *dapm_widgets; |
| 39 | unsigned int num_dapm_widgets; |
| 40 | const struct snd_soc_dapm_route *dapm_routes; |
| 41 | unsigned int num_dapm_routes; |
| 42 | |
| 43 | int (*probe)(struct snd_soc_component *component); |
| 44 | void (*remove)(struct snd_soc_component *component); |
| 45 | int (*suspend)(struct snd_soc_component *component); |
| 46 | int (*resume)(struct snd_soc_component *component); |
| 47 | |
| 48 | unsigned int (*read)(struct snd_soc_component *component, |
| 49 | unsigned int reg); |
| 50 | int (*write)(struct snd_soc_component *component, |
| 51 | unsigned int reg, unsigned int val); |
| 52 | |
| 53 | /* pcm creation and destruction */ |
| 54 | int (*pcm_new)(struct snd_soc_pcm_runtime *rtd); |
| 55 | void (*pcm_free)(struct snd_pcm *pcm); |
| 56 | |
| 57 | /* component wide operations */ |
| 58 | int (*set_sysclk)(struct snd_soc_component *component, |
| 59 | int clk_id, int source, unsigned int freq, int dir); |
| 60 | int (*set_pll)(struct snd_soc_component *component, int pll_id, |
| 61 | int source, unsigned int freq_in, unsigned int freq_out); |
| 62 | int (*set_jack)(struct snd_soc_component *component, |
| 63 | struct snd_soc_jack *jack, void *data); |
| 64 | |
| 65 | /* DT */ |
| 66 | int (*of_xlate_dai_name)(struct snd_soc_component *component, |
| 67 | struct of_phandle_args *args, |
| 68 | const char **dai_name); |
| 69 | int (*of_xlate_dai_id)(struct snd_soc_component *comment, |
| 70 | struct device_node *endpoint); |
| 71 | void (*seq_notifier)(struct snd_soc_component *component, |
| 72 | enum snd_soc_dapm_type type, int subseq); |
| 73 | int (*stream_event)(struct snd_soc_component *component, int event); |
| 74 | int (*set_bias_level)(struct snd_soc_component *component, |
| 75 | enum snd_soc_bias_level level); |
| 76 | |
| 77 | const struct snd_pcm_ops *ops; |
| 78 | const struct snd_compr_ops *compr_ops; |
| 79 | |
| 80 | /* probe ordering - for components with runtime dependencies */ |
| 81 | int probe_order; |
| 82 | int remove_order; |
| 83 | |
| 84 | /* |
| 85 | * signal if the module handling the component should not be removed |
| 86 | * if a pcm is open. Setting this would prevent the module |
| 87 | * refcount being incremented in probe() but allow it be incremented |
| 88 | * when a pcm is opened and decremented when it is closed. |
| 89 | */ |
| 90 | unsigned int module_get_upon_open:1; |
| 91 | |
| 92 | /* bits */ |
| 93 | unsigned int idle_bias_on:1; |
| 94 | unsigned int suspend_bias_off:1; |
| 95 | unsigned int use_pmdown_time:1; /* care pmdown_time at stop */ |
| 96 | unsigned int endianness:1; |
| 97 | unsigned int non_legacy_dai_naming:1; |
| 98 | |
| 99 | /* this component uses topology and ignore machine driver FEs */ |
| 100 | const char *ignore_machine; |
| 101 | const char *topology_name_prefix; |
| 102 | int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd, |
| 103 | struct snd_pcm_hw_params *params); |
| 104 | bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */ |
| 105 | int be_pcm_base; /* base device ID for all BE PCMs */ |
| 106 | }; |
| 107 | |
| 108 | struct snd_soc_component { |
| 109 | const char *name; |
| 110 | int id; |
| 111 | const char *name_prefix; |
| 112 | struct device *dev; |
| 113 | struct snd_soc_card *card; |
| 114 | |
| 115 | unsigned int active; |
| 116 | |
| 117 | unsigned int suspended:1; /* is in suspend PM state */ |
| 118 | |
| 119 | struct list_head list; |
| 120 | struct list_head card_aux_list; /* for auxiliary bound components */ |
| 121 | struct list_head card_list; |
| 122 | |
| 123 | const struct snd_soc_component_driver *driver; |
| 124 | |
| 125 | struct list_head dai_list; |
| 126 | int num_dai; |
| 127 | |
| 128 | struct regmap *regmap; |
| 129 | int val_bytes; |
| 130 | |
| 131 | struct mutex io_mutex; |
| 132 | |
| 133 | /* attached dynamic objects */ |
| 134 | struct list_head dobj_list; |
| 135 | |
| 136 | /* |
| 137 | * DO NOT use any of the fields below in drivers, they are temporary and |
| 138 | * are going to be removed again soon. If you use them in driver code |
| 139 | * the driver will be marked as BROKEN when these fields are removed. |
| 140 | */ |
| 141 | |
| 142 | /* Don't use these, use snd_soc_component_get_dapm() */ |
| 143 | struct snd_soc_dapm_context dapm; |
| 144 | |
| 145 | /* machine specific init */ |
| 146 | int (*init)(struct snd_soc_component *component); |
| 147 | |
| 148 | #ifdef CONFIG_DEBUG_FS |
| 149 | struct dentry *debugfs_root; |
| 150 | const char *debugfs_prefix; |
| 151 | #endif |
| 152 | }; |
| 153 | |
| 154 | #define for_each_component_dais(component, dai)\ |
| 155 | list_for_each_entry(dai, &(component)->dai_list, list) |
| 156 | #define for_each_component_dais_safe(component, dai, _dai)\ |
| 157 | list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list) |
| 158 | |
| 159 | /** |
| 160 | * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is |
| 161 | * embedded in |
| 162 | * @dapm: The DAPM context to cast to the component |
| 163 | * |
| 164 | * This function must only be used on DAPM contexts that are known to be part of |
| 165 | * a component (e.g. in a component driver). Otherwise the behavior is |
| 166 | * undefined. |
| 167 | */ |
| 168 | static inline struct snd_soc_component *snd_soc_dapm_to_component( |
| 169 | struct snd_soc_dapm_context *dapm) |
| 170 | { |
| 171 | return container_of(dapm, struct snd_soc_component, dapm); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * snd_soc_component_get_dapm() - Returns the DAPM context associated with a |
| 176 | * component |
| 177 | * @component: The component for which to get the DAPM context |
| 178 | */ |
| 179 | static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm( |
| 180 | struct snd_soc_component *component) |
| 181 | { |
| 182 | return &component->dapm; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level |
| 187 | * @component: The COMPONENT for which to initialize the DAPM bias level |
| 188 | * @level: The DAPM level to initialize to |
| 189 | * |
| 190 | * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level() |
| 191 | */ |
| 192 | static inline void |
| 193 | snd_soc_component_init_bias_level(struct snd_soc_component *component, |
| 194 | enum snd_soc_bias_level level) |
| 195 | { |
| 196 | snd_soc_dapm_init_bias_level( |
| 197 | snd_soc_component_get_dapm(component), level); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level |
| 202 | * @component: The COMPONENT for which to get the DAPM bias level |
| 203 | * |
| 204 | * Returns: The current DAPM bias level of the COMPONENT. |
| 205 | */ |
| 206 | static inline enum snd_soc_bias_level |
| 207 | snd_soc_component_get_bias_level(struct snd_soc_component *component) |
| 208 | { |
| 209 | return snd_soc_dapm_get_bias_level( |
| 210 | snd_soc_component_get_dapm(component)); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level |
| 215 | * @component: The COMPONENT for which to set the level |
| 216 | * @level: The level to set to |
| 217 | * |
| 218 | * Forces the COMPONENT bias level to a specific state. See |
| 219 | * snd_soc_dapm_force_bias_level(). |
| 220 | */ |
| 221 | static inline int |
| 222 | snd_soc_component_force_bias_level(struct snd_soc_component *component, |
| 223 | enum snd_soc_bias_level level) |
| 224 | { |
| 225 | return snd_soc_dapm_force_bias_level( |
| 226 | snd_soc_component_get_dapm(component), |
| 227 | level); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * snd_soc_dapm_kcontrol_component() - Returns the component associated to a |
| 232 | * kcontrol |
| 233 | * @kcontrol: The kcontrol |
| 234 | * |
| 235 | * This function must only be used on DAPM contexts that are known to be part of |
| 236 | * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined |
| 237 | */ |
| 238 | static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component( |
| 239 | struct snd_kcontrol *kcontrol) |
| 240 | { |
| 241 | return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol)); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * snd_soc_component_cache_sync() - Sync the register cache with the hardware |
| 246 | * @component: COMPONENT to sync |
| 247 | * |
| 248 | * Note: This function will call regcache_sync() |
| 249 | */ |
| 250 | static inline int snd_soc_component_cache_sync( |
| 251 | struct snd_soc_component *component) |
| 252 | { |
| 253 | return regcache_sync(component->regmap); |
| 254 | } |
| 255 | |
| 256 | /* component IO */ |
| 257 | int snd_soc_component_read(struct snd_soc_component *component, |
| 258 | unsigned int reg, unsigned int *val); |
| 259 | unsigned int snd_soc_component_read32(struct snd_soc_component *component, |
| 260 | unsigned int reg); |
| 261 | int snd_soc_component_write(struct snd_soc_component *component, |
| 262 | unsigned int reg, unsigned int val); |
| 263 | int snd_soc_component_update_bits(struct snd_soc_component *component, |
| 264 | unsigned int reg, unsigned int mask, |
| 265 | unsigned int val); |
| 266 | int snd_soc_component_update_bits_async(struct snd_soc_component *component, |
| 267 | unsigned int reg, unsigned int mask, |
| 268 | unsigned int val); |
| 269 | void snd_soc_component_async_complete(struct snd_soc_component *component); |
| 270 | int snd_soc_component_test_bits(struct snd_soc_component *component, |
| 271 | unsigned int reg, unsigned int mask, |
| 272 | unsigned int value); |
| 273 | |
| 274 | /* component wide operations */ |
| 275 | int snd_soc_component_set_sysclk(struct snd_soc_component *component, |
| 276 | int clk_id, int source, |
| 277 | unsigned int freq, int dir); |
| 278 | int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, |
| 279 | int source, unsigned int freq_in, |
| 280 | unsigned int freq_out); |
| 281 | int snd_soc_component_set_jack(struct snd_soc_component *component, |
| 282 | struct snd_soc_jack *jack, void *data); |
| 283 | |
| 284 | #ifdef CONFIG_REGMAP |
| 285 | void snd_soc_component_init_regmap(struct snd_soc_component *component, |
| 286 | struct regmap *regmap); |
| 287 | void snd_soc_component_exit_regmap(struct snd_soc_component *component); |
| 288 | #endif |
| 289 | |
Kuninori Morimoto | 4a81e8f | 2019-07-26 13:49:54 +0900 | [diff] [blame] | 290 | #define snd_soc_component_module_get_when_probe(component)\ |
| 291 | snd_soc_component_module_get(component, 0) |
| 292 | #define snd_soc_component_module_get_when_open(component) \ |
| 293 | snd_soc_component_module_get(component, 1) |
| 294 | int snd_soc_component_module_get(struct snd_soc_component *component, |
| 295 | int upon_open); |
| 296 | #define snd_soc_component_module_put_when_remove(component) \ |
| 297 | snd_soc_component_module_put(component, 0) |
| 298 | #define snd_soc_component_module_put_when_close(component) \ |
| 299 | snd_soc_component_module_put(component, 1) |
| 300 | void snd_soc_component_module_put(struct snd_soc_component *component, |
| 301 | int upon_open); |
| 302 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 303 | static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c, |
| 304 | void *data) |
| 305 | { |
| 306 | dev_set_drvdata(c->dev, data); |
| 307 | } |
| 308 | |
| 309 | static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c) |
| 310 | { |
| 311 | return dev_get_drvdata(c->dev); |
| 312 | } |
| 313 | |
| 314 | static inline bool snd_soc_component_is_active( |
| 315 | struct snd_soc_component *component) |
| 316 | { |
| 317 | return component->active != 0; |
| 318 | } |
| 319 | |
| 320 | /* component pin */ |
| 321 | int snd_soc_component_enable_pin(struct snd_soc_component *component, |
| 322 | const char *pin); |
| 323 | int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component, |
| 324 | const char *pin); |
| 325 | int snd_soc_component_disable_pin(struct snd_soc_component *component, |
| 326 | const char *pin); |
| 327 | int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component, |
| 328 | const char *pin); |
| 329 | int snd_soc_component_nc_pin(struct snd_soc_component *component, |
| 330 | const char *pin); |
| 331 | int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component, |
| 332 | const char *pin); |
| 333 | int snd_soc_component_get_pin_status(struct snd_soc_component *component, |
| 334 | const char *pin); |
| 335 | int snd_soc_component_force_enable_pin(struct snd_soc_component *component, |
| 336 | const char *pin); |
| 337 | int snd_soc_component_force_enable_pin_unlocked( |
| 338 | struct snd_soc_component *component, |
| 339 | const char *pin); |
| 340 | |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 341 | /* component driver ops */ |
| 342 | int snd_soc_component_open(struct snd_soc_component *component, |
| 343 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | 3672beb | 2019-07-26 13:50:07 +0900 | [diff] [blame] | 344 | int snd_soc_component_close(struct snd_soc_component *component, |
| 345 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | 6d53723 | 2019-07-26 13:50:13 +0900 | [diff] [blame] | 346 | int snd_soc_component_prepare(struct snd_soc_component *component, |
| 347 | struct snd_pcm_substream *substream); |
Kuninori Morimoto | 245c539 | 2019-07-26 13:50:19 +0900 | [diff] [blame^] | 348 | int snd_soc_component_hw_params(struct snd_soc_component *component, |
| 349 | struct snd_pcm_substream *substream, |
| 350 | struct snd_pcm_hw_params *params); |
Kuninori Morimoto | ae2f484 | 2019-07-26 13:50:01 +0900 | [diff] [blame] | 351 | |
Kuninori Morimoto | 4ff1fef | 2019-07-26 13:49:48 +0900 | [diff] [blame] | 352 | #endif /* __SOC_COMPONENT_H */ |