diff options
| -rw-r--r-- | Documentation/devicetree/bindings/sound/wm8741.txt | 11 | ||||
| -rw-r--r-- | include/sound/soc-dapm.h | 3 | ||||
| -rw-r--r-- | include/sound/soc-topology.h | 168 | ||||
| -rw-r--r-- | include/sound/soc.h | 11 | ||||
| -rw-r--r-- | include/sound/tlv.h | 15 | ||||
| -rw-r--r-- | include/uapi/sound/asoc.h | 388 | ||||
| -rw-r--r-- | include/uapi/sound/tlv.h | 31 | ||||
| -rw-r--r-- | sound/soc/Makefile | 1 | ||||
| -rw-r--r-- | sound/soc/codecs/twl6040.c | 3 | ||||
| -rw-r--r-- | sound/soc/codecs/wm5100.c | 6 | ||||
| -rw-r--r-- | sound/soc/codecs/wm8741.c | 129 | ||||
| -rw-r--r-- | sound/soc/codecs/wm8741.h | 10 | ||||
| -rw-r--r-- | sound/soc/codecs/wm8960.c | 109 | ||||
| -rw-r--r-- | sound/soc/soc-core.c | 4 | ||||
| -rw-r--r-- | sound/soc/soc-topology.c | 1826 |
15 files changed, 2684 insertions, 31 deletions
diff --git a/Documentation/devicetree/bindings/sound/wm8741.txt b/Documentation/devicetree/bindings/sound/wm8741.txt index 74bda58c1bcf..a13315408719 100644 --- a/Documentation/devicetree/bindings/sound/wm8741.txt +++ b/Documentation/devicetree/bindings/sound/wm8741.txt | |||
| @@ -10,9 +10,20 @@ Required properties: | |||
| 10 | - reg : the I2C address of the device for I2C, the chip select | 10 | - reg : the I2C address of the device for I2C, the chip select |
| 11 | number for SPI. | 11 | number for SPI. |
| 12 | 12 | ||
| 13 | Optional properties: | ||
| 14 | |||
| 15 | - diff-mode: Differential output mode configuration. Default value for field | ||
| 16 | DIFF in register R8 (MODE_CONTROL_2). If absent, the default is 0, shall be: | ||
| 17 | 0 = stereo | ||
| 18 | 1 = mono left | ||
| 19 | 2 = stereo reversed | ||
| 20 | 3 = mono right | ||
| 21 | |||
| 13 | Example: | 22 | Example: |
| 14 | 23 | ||
| 15 | codec: wm8741@1a { | 24 | codec: wm8741@1a { |
| 16 | compatible = "wlf,wm8741"; | 25 | compatible = "wlf,wm8741"; |
| 17 | reg = <0x1a>; | 26 | reg = <0x1a>; |
| 27 | |||
| 28 | diff-mode = <3>; | ||
| 18 | }; | 29 | }; |
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 2f66e1c27f50..37d95a898275 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h | |||
| @@ -15,6 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | #include <linux/types.h> | 16 | #include <linux/types.h> |
| 17 | #include <sound/control.h> | 17 | #include <sound/control.h> |
| 18 | #include <sound/soc-topology.h> | ||
| 19 | #include <sound/asoc.h> | ||
| 18 | 20 | ||
| 19 | struct device; | 21 | struct device; |
| 20 | 22 | ||
| @@ -571,6 +573,7 @@ struct snd_soc_dapm_widget { | |||
| 571 | int num_kcontrols; | 573 | int num_kcontrols; |
| 572 | const struct snd_kcontrol_new *kcontrol_news; | 574 | const struct snd_kcontrol_new *kcontrol_news; |
| 573 | struct snd_kcontrol **kcontrols; | 575 | struct snd_kcontrol **kcontrols; |
| 576 | struct snd_soc_dobj dobj; | ||
| 574 | 577 | ||
| 575 | /* widget input and outputs */ | 578 | /* widget input and outputs */ |
| 576 | struct list_head sources; | 579 | struct list_head sources; |
diff --git a/include/sound/soc-topology.h b/include/sound/soc-topology.h new file mode 100644 index 000000000000..865a141b118b --- /dev/null +++ b/include/sound/soc-topology.h | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | /* | ||
| 2 | * linux/sound/soc-topology.h -- ALSA SoC Firmware Controls and DAPM | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 Texas Instruments Inc. | ||
| 5 | * Copyright (C) 2015 Intel Corporation. | ||
| 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 | * Simple file API to load FW that includes mixers, coefficients, DAPM graphs, | ||
| 12 | * algorithms, equalisers, DAIs, widgets, FE caps, BE caps, codec link caps etc. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __LINUX_SND_SOC_TPLG_H | ||
| 16 | #define __LINUX_SND_SOC_TPLG_H | ||
| 17 | |||
| 18 | #include <sound/asoc.h> | ||
| 19 | #include <linux/list.h> | ||
| 20 | |||
| 21 | struct firmware; | ||
| 22 | struct snd_kcontrol; | ||
| 23 | struct snd_soc_tplg_pcm_be; | ||
| 24 | struct snd_ctl_elem_value; | ||
| 25 | struct snd_ctl_elem_info; | ||
| 26 | struct snd_soc_dapm_widget; | ||
| 27 | struct snd_soc_component; | ||
| 28 | struct snd_soc_tplg_pcm_fe; | ||
| 29 | struct snd_soc_dapm_context; | ||
| 30 | struct snd_soc_card; | ||
| 31 | |||
| 32 | /* object scan be loaded and unloaded in groups with identfying indexes */ | ||
| 33 | #define SND_SOC_TPLG_INDEX_ALL 0 /* ID that matches all FW objects */ | ||
| 34 | |||
| 35 | /* dynamic object type */ | ||
| 36 | enum snd_soc_dobj_type { | ||
| 37 | SND_SOC_DOBJ_NONE = 0, /* object is not dynamic */ | ||
| 38 | SND_SOC_DOBJ_MIXER, | ||
| 39 | SND_SOC_DOBJ_ENUM, | ||
| 40 | SND_SOC_DOBJ_BYTES, | ||
| 41 | SND_SOC_DOBJ_PCM, | ||
| 42 | SND_SOC_DOBJ_DAI_LINK, | ||
| 43 | SND_SOC_DOBJ_CODEC_LINK, | ||
| 44 | SND_SOC_DOBJ_WIDGET, | ||
| 45 | }; | ||
| 46 | |||
| 47 | /* dynamic control object */ | ||
| 48 | struct snd_soc_dobj_control { | ||
| 49 | struct snd_kcontrol *kcontrol; | ||
| 50 | char **dtexts; | ||
| 51 | unsigned long *dvalues; | ||
| 52 | }; | ||
| 53 | |||
| 54 | /* dynamic widget object */ | ||
| 55 | struct snd_soc_dobj_widget { | ||
| 56 | unsigned int kcontrol_enum:1; /* this widget is an enum kcontrol */ | ||
| 57 | }; | ||
| 58 | |||
| 59 | /* dynamic PCM DAI object */ | ||
| 60 | struct snd_soc_dobj_pcm_dai { | ||
| 61 | struct snd_soc_tplg_pcm_dai *pd; | ||
| 62 | unsigned int count; | ||
| 63 | }; | ||
| 64 | |||
| 65 | /* generic dynamic object - all dynamic objects belong to this struct */ | ||
| 66 | struct snd_soc_dobj { | ||
| 67 | enum snd_soc_dobj_type type; | ||
| 68 | unsigned int index; /* objects can belong in different groups */ | ||
| 69 | struct list_head list; | ||
| 70 | struct snd_soc_tplg_ops *ops; | ||
| 71 | union { | ||
| 72 | struct snd_soc_dobj_control control; | ||
| 73 | struct snd_soc_dobj_widget widget; | ||
| 74 | struct snd_soc_dobj_pcm_dai pcm_dai; | ||
| 75 | }; | ||
| 76 | void *private; /* core does not touch this */ | ||
| 77 | }; | ||
| 78 | |||
| 79 | /* | ||
| 80 | * Kcontrol operations - used to map handlers onto firmware based controls. | ||
| 81 | */ | ||
| 82 | struct snd_soc_tplg_kcontrol_ops { | ||
| 83 | u32 id; | ||
| 84 | int (*get)(struct snd_kcontrol *kcontrol, | ||
| 85 | struct snd_ctl_elem_value *ucontrol); | ||
| 86 | int (*put)(struct snd_kcontrol *kcontrol, | ||
| 87 | struct snd_ctl_elem_value *ucontrol); | ||
| 88 | int (*info)(struct snd_kcontrol *kcontrol, | ||
| 89 | struct snd_ctl_elem_info *uinfo); | ||
| 90 | }; | ||
| 91 | |||
| 92 | /* | ||
| 93 | * DAPM widget event handlers - used to map handlers onto widgets. | ||
| 94 | */ | ||
| 95 | struct snd_soc_tplg_widget_events { | ||
| 96 | u16 type; | ||
| 97 | int (*event_handler)(struct snd_soc_dapm_widget *w, | ||
| 98 | struct snd_kcontrol *k, int event); | ||
| 99 | }; | ||
| 100 | |||
| 101 | /* | ||
| 102 | * Public API - Used by component drivers to load and unload dynamic objects | ||
| 103 | * and their resources. | ||
| 104 | */ | ||
| 105 | struct snd_soc_tplg_ops { | ||
| 106 | |||
| 107 | /* external kcontrol init - used for any driver specific init */ | ||
| 108 | int (*control_load)(struct snd_soc_component *, | ||
| 109 | struct snd_kcontrol_new *, struct snd_soc_tplg_ctl_hdr *); | ||
| 110 | int (*control_unload)(struct snd_soc_component *, | ||
| 111 | struct snd_soc_dobj *); | ||
| 112 | |||
| 113 | /* external widget init - used for any driver specific init */ | ||
| 114 | int (*widget_load)(struct snd_soc_component *, | ||
| 115 | struct snd_soc_dapm_widget *, | ||
| 116 | struct snd_soc_tplg_dapm_widget *); | ||
| 117 | int (*widget_unload)(struct snd_soc_component *, | ||
| 118 | struct snd_soc_dobj *); | ||
| 119 | |||
| 120 | /* FE - used for any driver specific init */ | ||
| 121 | int (*pcm_dai_load)(struct snd_soc_component *, | ||
| 122 | struct snd_soc_tplg_pcm_dai *pcm_dai, int num_fe); | ||
| 123 | int (*pcm_dai_unload)(struct snd_soc_component *, | ||
| 124 | struct snd_soc_dobj *); | ||
| 125 | |||
| 126 | /* callback to handle vendor bespoke data */ | ||
| 127 | int (*vendor_load)(struct snd_soc_component *, | ||
| 128 | struct snd_soc_tplg_hdr *); | ||
| 129 | int (*vendor_unload)(struct snd_soc_component *, | ||
| 130 | struct snd_soc_tplg_hdr *); | ||
| 131 | |||
| 132 | /* completion - called at completion of firmware loading */ | ||
| 133 | void (*complete)(struct snd_soc_component *); | ||
| 134 | |||
| 135 | /* manifest - optional to inform component of manifest */ | ||
| 136 | int (*manifest)(struct snd_soc_component *, | ||
| 137 | struct snd_soc_tplg_manifest *); | ||
| 138 | |||
| 139 | /* bespoke kcontrol handlers available for binding */ | ||
| 140 | const struct snd_soc_tplg_kcontrol_ops *io_ops; | ||
| 141 | int io_ops_count; | ||
| 142 | }; | ||
| 143 | |||
| 144 | /* gets a pointer to data from the firmware block header */ | ||
| 145 | static inline const void *snd_soc_tplg_get_data(struct snd_soc_tplg_hdr *hdr) | ||
| 146 | { | ||
| 147 | const void *ptr = hdr; | ||
| 148 | |||
| 149 | return ptr + sizeof(*hdr); | ||
| 150 | } | ||
| 151 | |||
| 152 | /* Dynamic Object loading and removal for component drivers */ | ||
| 153 | int snd_soc_tplg_component_load(struct snd_soc_component *comp, | ||
| 154 | struct snd_soc_tplg_ops *ops, const struct firmware *fw, | ||
| 155 | u32 index); | ||
| 156 | int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index); | ||
| 157 | |||
| 158 | /* Widget removal - widgets also removed wth component API */ | ||
| 159 | void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w); | ||
| 160 | void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm, | ||
| 161 | u32 index); | ||
| 162 | |||
| 163 | /* Binds event handlers to dynamic widgets */ | ||
| 164 | int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w, | ||
| 165 | const struct snd_soc_tplg_widget_events *events, int num_events, | ||
| 166 | u16 event_type); | ||
| 167 | |||
| 168 | #endif | ||
diff --git a/include/sound/soc.h b/include/sound/soc.h index f10f48fad5d5..93df8bf9d54a 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <sound/compress_driver.h> | 27 | #include <sound/compress_driver.h> |
| 28 | #include <sound/control.h> | 28 | #include <sound/control.h> |
| 29 | #include <sound/ac97_codec.h> | 29 | #include <sound/ac97_codec.h> |
| 30 | #include <sound/soc-topology.h> | ||
| 30 | 31 | ||
| 31 | /* | 32 | /* |
| 32 | * Convenience kcontrol builders | 33 | * Convenience kcontrol builders |
| @@ -776,6 +777,9 @@ struct snd_soc_component { | |||
| 776 | 777 | ||
| 777 | struct mutex io_mutex; | 778 | struct mutex io_mutex; |
| 778 | 779 | ||
| 780 | /* attached dynamic objects */ | ||
| 781 | struct list_head dobj_list; | ||
| 782 | |||
| 779 | #ifdef CONFIG_DEBUG_FS | 783 | #ifdef CONFIG_DEBUG_FS |
| 780 | struct dentry *debugfs_root; | 784 | struct dentry *debugfs_root; |
| 781 | #endif | 785 | #endif |
| @@ -1123,6 +1127,9 @@ struct snd_soc_card { | |||
| 1123 | struct list_head dapm_list; | 1127 | struct list_head dapm_list; |
| 1124 | struct list_head dapm_dirty; | 1128 | struct list_head dapm_dirty; |
| 1125 | 1129 | ||
| 1130 | /* attached dynamic objects */ | ||
| 1131 | struct list_head dobj_list; | ||
| 1132 | |||
| 1126 | /* Generic DAPM context for the card */ | 1133 | /* Generic DAPM context for the card */ |
| 1127 | struct snd_soc_dapm_context dapm; | 1134 | struct snd_soc_dapm_context dapm; |
| 1128 | struct snd_soc_dapm_stats dapm_stats; | 1135 | struct snd_soc_dapm_stats dapm_stats; |
| @@ -1182,6 +1189,7 @@ struct soc_mixer_control { | |||
| 1182 | unsigned int sign_bit; | 1189 | unsigned int sign_bit; |
| 1183 | unsigned int invert:1; | 1190 | unsigned int invert:1; |
| 1184 | unsigned int autodisable:1; | 1191 | unsigned int autodisable:1; |
| 1192 | struct snd_soc_dobj dobj; | ||
| 1185 | }; | 1193 | }; |
| 1186 | 1194 | ||
| 1187 | struct soc_bytes { | 1195 | struct soc_bytes { |
| @@ -1192,6 +1200,8 @@ struct soc_bytes { | |||
| 1192 | 1200 | ||
| 1193 | struct soc_bytes_ext { | 1201 | struct soc_bytes_ext { |
| 1194 | int max; | 1202 | int max; |
| 1203 | struct snd_soc_dobj dobj; | ||
| 1204 | |||
| 1195 | /* used for TLV byte control */ | 1205 | /* used for TLV byte control */ |
| 1196 | int (*get)(unsigned int __user *bytes, unsigned int size); | 1206 | int (*get)(unsigned int __user *bytes, unsigned int size); |
| 1197 | int (*put)(const unsigned int __user *bytes, unsigned int size); | 1207 | int (*put)(const unsigned int __user *bytes, unsigned int size); |
| @@ -1213,6 +1223,7 @@ struct soc_enum { | |||
| 1213 | const char * const *texts; | 1223 | const char * const *texts; |
| 1214 | const unsigned int *values; | 1224 | const unsigned int *values; |
| 1215 | unsigned int autodisable:1; | 1225 | unsigned int autodisable:1; |
| 1226 | struct snd_soc_dobj dobj; | ||
| 1216 | }; | 1227 | }; |
| 1217 | 1228 | ||
| 1218 | /** | 1229 | /** |
diff --git a/include/sound/tlv.h b/include/sound/tlv.h index e11e179420a1..df97d1966468 100644 --- a/include/sound/tlv.h +++ b/include/sound/tlv.h | |||
| @@ -31,12 +31,7 @@ | |||
| 31 | * ~(sizeof(unsigned int) - 1)) .... | 31 | * ~(sizeof(unsigned int) - 1)) .... |
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */ | 34 | #include <uapi/sound/tlv.h> |
| 35 | #define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */ | ||
| 36 | #define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */ | ||
| 37 | #define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */ | ||
| 38 | #define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */ | ||
| 39 | #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */ | ||
| 40 | 35 | ||
| 41 | #define TLV_ITEM(type, ...) \ | 36 | #define TLV_ITEM(type, ...) \ |
| 42 | (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__ | 37 | (type), TLV_LENGTH(__VA_ARGS__), __VA_ARGS__ |
| @@ -90,12 +85,4 @@ | |||
| 90 | 85 | ||
| 91 | #define TLV_DB_GAIN_MUTE -9999999 | 86 | #define TLV_DB_GAIN_MUTE -9999999 |
| 92 | 87 | ||
| 93 | /* | ||
| 94 | * channel-mapping TLV items | ||
| 95 | * TLV length must match with num_channels | ||
| 96 | */ | ||
| 97 | #define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */ | ||
| 98 | #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */ | ||
| 99 | #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */ | ||
| 100 | |||
| 101 | #endif /* __SOUND_TLV_H */ | 88 | #endif /* __SOUND_TLV_H */ |
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h new file mode 100644 index 000000000000..12215205ab8d --- /dev/null +++ b/include/uapi/sound/asoc.h | |||
| @@ -0,0 +1,388 @@ | |||
| 1 | /* | ||
| 2 | * uapi/sound/asoc.h -- ALSA SoC Firmware Controls and DAPM | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 Texas Instruments Inc. | ||
| 5 | * Copyright (C) 2015 Intel Corporation. | ||
| 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 | * Simple file API to load FW that includes mixers, coefficients, DAPM graphs, | ||
| 12 | * algorithms, equalisers, DAIs, widgets etc. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef __LINUX_UAPI_SND_ASOC_H | ||
| 16 | #define __LINUX_UAPI_SND_ASOC_H | ||
| 17 | |||
| 18 | #include <linux/types.h> | ||
| 19 | #include <sound/asound.h> | ||
| 20 | |||
| 21 | /* | ||
| 22 | * Maximum number of channels topology kcontrol can represent. | ||
| 23 | */ | ||
| 24 | #define SND_SOC_TPLG_MAX_CHAN 8 | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Maximum number of PCM formats capability | ||
| 28 | */ | ||
| 29 | #define SND_SOC_TPLG_MAX_FORMATS 16 | ||
| 30 | |||
| 31 | /* | ||
| 32 | * Maximum number of PCM stream configs | ||
| 33 | */ | ||
| 34 | #define SND_SOC_TPLG_STREAM_CONFIG_MAX 8 | ||
| 35 | |||
| 36 | /* individual kcontrol info types - can be mixed with other types */ | ||
| 37 | #define SND_SOC_TPLG_CTL_VOLSW 1 | ||
| 38 | #define SND_SOC_TPLG_CTL_VOLSW_SX 2 | ||
| 39 | #define SND_SOC_TPLG_CTL_VOLSW_XR_SX 3 | ||
| 40 | #define SND_SOC_TPLG_CTL_ENUM 4 | ||
| 41 | #define SND_SOC_TPLG_CTL_BYTES 5 | ||
| 42 | #define SND_SOC_TPLG_CTL_ENUM_VALUE 6 | ||
| 43 | #define SND_SOC_TPLG_CTL_RANGE 7 | ||
| 44 | #define SND_SOC_TPLG_CTL_STROBE 8 | ||
| 45 | |||
| 46 | |||
| 47 | /* individual widget kcontrol info types - can be mixed with other types */ | ||
| 48 | #define SND_SOC_TPLG_DAPM_CTL_VOLSW 64 | ||
| 49 | #define SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE 65 | ||
| 50 | #define SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT 66 | ||
| 51 | #define SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE 67 | ||
| 52 | #define SND_SOC_TPLG_DAPM_CTL_PIN 68 | ||
| 53 | |||
| 54 | /* DAPM widget types - add new items to the end */ | ||
| 55 | #define SND_SOC_TPLG_DAPM_INPUT 0 | ||
| 56 | #define SND_SOC_TPLG_DAPM_OUTPUT 1 | ||
| 57 | #define SND_SOC_TPLG_DAPM_MUX 2 | ||
| 58 | #define SND_SOC_TPLG_DAPM_MIXER 3 | ||
| 59 | #define SND_SOC_TPLG_DAPM_PGA 4 | ||
| 60 | #define SND_SOC_TPLG_DAPM_OUT_DRV 5 | ||
| 61 | #define SND_SOC_TPLG_DAPM_ADC 6 | ||
| 62 | #define SND_SOC_TPLG_DAPM_DAC 7 | ||
| 63 | #define SND_SOC_TPLG_DAPM_SWITCH 8 | ||
| 64 | #define SND_SOC_TPLG_DAPM_PRE 9 | ||
| 65 | #define SND_SOC_TPLG_DAPM_POST 10 | ||
| 66 | #define SND_SOC_TPLG_DAPM_AIF_IN 11 | ||
| 67 | #define SND_SOC_TPLG_DAPM_AIF_OUT 12 | ||
| 68 | #define SND_SOC_TPLG_DAPM_DAI_IN 13 | ||
| 69 | #define SND_SOC_TPLG_DAPM_DAI_OUT 14 | ||
| 70 | #define SND_SOC_TPLG_DAPM_DAI_LINK 15 | ||
| 71 | #define SND_SOC_TPLG_DAPM_LAST SND_SOC_TPLG_DAPM_DAI_LINK | ||
| 72 | |||
| 73 | /* Header magic number and string sizes */ | ||
| 74 | #define SND_SOC_TPLG_MAGIC 0x41536F43 /* ASoC */ | ||
| 75 | |||
| 76 | /* string sizes */ | ||
| 77 | #define SND_SOC_TPLG_NUM_TEXTS 16 | ||
| 78 | |||
| 79 | /* ABI version */ | ||
| 80 | #define SND_SOC_TPLG_ABI_VERSION 0x2 | ||
| 81 | |||
| 82 | /* Max size of TLV data */ | ||
| 83 | #define SND_SOC_TPLG_TLV_SIZE 32 | ||
| 84 | |||
| 85 | /* | ||
| 86 | * File and Block header data types. | ||
| 87 | * Add new generic and vendor types to end of list. | ||
| 88 | * Generic types are handled by the core whilst vendors types are passed | ||
| 89 | * to the component drivers for handling. | ||
| 90 | */ | ||
| 91 | #define SND_SOC_TPLG_TYPE_MIXER 1 | ||
| 92 | #define SND_SOC_TPLG_TYPE_BYTES 2 | ||
| 93 | #define SND_SOC_TPLG_TYPE_ENUM 3 | ||
| 94 | #define SND_SOC_TPLG_TYPE_DAPM_GRAPH 4 | ||
| 95 | #define SND_SOC_TPLG_TYPE_DAPM_WIDGET 5 | ||
| 96 | #define SND_SOC_TPLG_TYPE_DAI_LINK 6 | ||
| 97 | #define SND_SOC_TPLG_TYPE_PCM 7 | ||
| 98 | #define SND_SOC_TPLG_TYPE_MANIFEST 8 | ||
| 99 | #define SND_SOC_TPLG_TYPE_CODEC_LINK 9 | ||
| 100 | #define SND_SOC_TPLG_TYPE_MAX SND_SOC_TPLG_TYPE_CODEC_LINK | ||
| 101 | |||
| 102 | /* vendor block IDs - please add new vendor types to end */ | ||
| 103 | #define SND_SOC_TPLG_TYPE_VENDOR_FW 1000 | ||
| 104 | #define SND_SOC_TPLG_TYPE_VENDOR_CONFIG 1001 | ||
| 105 | #define SND_SOC_TPLG_TYPE_VENDOR_COEFF 1002 | ||
| 106 | #define SND_SOC_TPLG_TYPEVENDOR_CODEC 1003 | ||
| 107 | |||
| 108 | #define SND_SOC_TPLG_STREAM_PLAYBACK 0 | ||
| 109 | #define SND_SOC_TPLG_STREAM_CAPTURE 1 | ||
| 110 | |||
| 111 | /* | ||
| 112 | * Block Header. | ||
| 113 | * This header preceeds all object and object arrays below. | ||
| 114 | */ | ||
| 115 | struct snd_soc_tplg_hdr { | ||
| 116 | __le32 magic; /* magic number */ | ||
| 117 | __le32 abi; /* ABI version */ | ||
| 118 | __le32 version; /* optional vendor specific version details */ | ||
| 119 | __le32 type; /* SND_SOC_TPLG_TYPE_ */ | ||
| 120 | __le32 size; /* size of this structure */ | ||
| 121 | __le32 vendor_type; /* optional vendor specific type info */ | ||
| 122 | __le32 payload_size; /* data bytes, excluding this header */ | ||
| 123 | __le32 index; /* identifier for block */ | ||
| 124 | __le32 count; /* number of elements in block */ | ||
| 125 | } __attribute__((packed)); | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Private data. | ||
| 129 | * All topology objects may have private data that can be used by the driver or | ||
| 130 | * firmware. Core will ignore this data. | ||
| 131 | */ | ||
| 132 | struct snd_soc_tplg_private { | ||
| 133 | __le32 size; /* in bytes of private data */ | ||
| 134 | char data[0]; | ||
| 135 | } __attribute__((packed)); | ||
| 136 | |||
| 137 | /* | ||
| 138 | * Kcontrol TLV data. | ||
| 139 | */ | ||
| 140 | struct snd_soc_tplg_ctl_tlv { | ||
| 141 | __le32 size; /* in bytes aligned to 4 */ | ||
| 142 | __le32 numid; /* control element numeric identification */ | ||
| 143 | __le32 count; /* number of elem in data array */ | ||
| 144 | __le32 data[SND_SOC_TPLG_TLV_SIZE]; | ||
| 145 | } __attribute__((packed)); | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Kcontrol channel data | ||
| 149 | */ | ||
| 150 | struct snd_soc_tplg_channel { | ||
| 151 | __le32 size; /* in bytes of this structure */ | ||
| 152 | __le32 reg; | ||
| 153 | __le32 shift; | ||
| 154 | __le32 id; /* ID maps to Left, Right, LFE etc */ | ||
| 155 | } __attribute__((packed)); | ||
| 156 | |||
| 157 | /* | ||
| 158 | * Kcontrol Operations IDs | ||
| 159 | */ | ||
| 160 | struct snd_soc_tplg_kcontrol_ops_id { | ||
| 161 | __le32 get; | ||
| 162 | __le32 put; | ||
| 163 | __le32 info; | ||
| 164 | } __attribute__((packed)); | ||
| 165 | |||
| 166 | /* | ||
| 167 | * kcontrol header | ||
| 168 | */ | ||
| 169 | struct snd_soc_tplg_ctl_hdr { | ||
| 170 | __le32 size; /* in bytes of this structure */ | ||
| 171 | __le32 type; | ||
| 172 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 173 | __le32 access; | ||
| 174 | struct snd_soc_tplg_kcontrol_ops_id ops; | ||
| 175 | __le32 tlv_size; /* non zero means control has TLV data */ | ||
| 176 | } __attribute__((packed)); | ||
| 177 | |||
| 178 | /* | ||
| 179 | * Stream Capabilities | ||
| 180 | */ | ||
| 181 | struct snd_soc_tplg_stream_caps { | ||
| 182 | __le32 size; /* in bytes of this structure */ | ||
| 183 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 184 | __le64 formats[SND_SOC_TPLG_MAX_FORMATS]; /* supported formats SNDRV_PCM_FMTBIT_* */ | ||
| 185 | __le32 rates; /* supported rates SNDRV_PCM_RATE_* */ | ||
| 186 | __le32 rate_min; /* min rate */ | ||
| 187 | __le32 rate_max; /* max rate */ | ||
| 188 | __le32 channels_min; /* min channels */ | ||
| 189 | __le32 channels_max; /* max channels */ | ||
| 190 | __le32 periods_min; /* min number of periods */ | ||
| 191 | __le32 periods_max; /* max number of periods */ | ||
| 192 | __le32 period_size_min; /* min period size bytes */ | ||
| 193 | __le32 period_size_max; /* max period size bytes */ | ||
| 194 | __le32 buffer_size_min; /* min buffer size bytes */ | ||
| 195 | __le32 buffer_size_max; /* max buffer size bytes */ | ||
| 196 | } __attribute__((packed)); | ||
| 197 | |||
| 198 | /* | ||
| 199 | * FE or BE Stream configuration supported by SW/FW | ||
| 200 | */ | ||
| 201 | struct snd_soc_tplg_stream { | ||
| 202 | __le32 size; /* in bytes of this structure */ | ||
| 203 | __le64 format; /* SNDRV_PCM_FMTBIT_* */ | ||
| 204 | __le32 rate; /* SNDRV_PCM_RATE_* */ | ||
| 205 | __le32 period_bytes; /* size of period in bytes */ | ||
| 206 | __le32 buffer_bytes; /* size of buffer in bytes */ | ||
| 207 | __le32 channels; /* channels */ | ||
| 208 | __le32 tdm_slot; /* optional BE bitmask of supported TDM slots */ | ||
| 209 | __le32 dai_fmt; /* SND_SOC_DAIFMT_ */ | ||
| 210 | } __attribute__((packed)); | ||
| 211 | |||
| 212 | /* | ||
| 213 | * Duplex stream configuration supported by SW/FW. | ||
| 214 | */ | ||
| 215 | struct snd_soc_tplg_stream_config { | ||
| 216 | __le32 size; /* in bytes of this structure */ | ||
| 217 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 218 | struct snd_soc_tplg_stream playback; | ||
| 219 | struct snd_soc_tplg_stream capture; | ||
| 220 | } __attribute__((packed)); | ||
| 221 | |||
| 222 | /* | ||
| 223 | * Manifest. List totals for each payload type. Not used in parsing, but will | ||
| 224 | * be passed to the component driver before any other objects in order for any | ||
| 225 | * global componnent resource allocations. | ||
| 226 | * | ||
| 227 | * File block representation for manifest :- | ||
| 228 | * +-----------------------------------+----+ | ||
| 229 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 230 | * +-----------------------------------+----+ | ||
| 231 | * | struct snd_soc_tplg_manifest | 1 | | ||
| 232 | * +-----------------------------------+----+ | ||
| 233 | */ | ||
| 234 | struct snd_soc_tplg_manifest { | ||
| 235 | __le32 size; /* in bytes of this structure */ | ||
| 236 | __le32 control_elems; /* number of control elements */ | ||
| 237 | __le32 widget_elems; /* number of widget elements */ | ||
| 238 | __le32 graph_elems; /* number of graph elements */ | ||
| 239 | __le32 dai_elems; /* number of DAI elements */ | ||
| 240 | __le32 dai_link_elems; /* number of DAI link elements */ | ||
| 241 | } __attribute__((packed)); | ||
| 242 | |||
| 243 | /* | ||
| 244 | * Mixer kcontrol. | ||
| 245 | * | ||
| 246 | * File block representation for mixer kcontrol :- | ||
| 247 | * +-----------------------------------+----+ | ||
| 248 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 249 | * +-----------------------------------+----+ | ||
| 250 | * | struct snd_soc_tplg_mixer_control | N | | ||
| 251 | * +-----------------------------------+----+ | ||
| 252 | */ | ||
| 253 | struct snd_soc_tplg_mixer_control { | ||
| 254 | struct snd_soc_tplg_ctl_hdr hdr; | ||
| 255 | __le32 size; /* in bytes of this structure */ | ||
| 256 | __le32 min; | ||
| 257 | __le32 max; | ||
| 258 | __le32 platform_max; | ||
| 259 | __le32 invert; | ||
| 260 | __le32 num_channels; | ||
| 261 | struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; | ||
| 262 | struct snd_soc_tplg_ctl_tlv tlv; | ||
| 263 | struct snd_soc_tplg_private priv; | ||
| 264 | } __attribute__((packed)); | ||
| 265 | |||
| 266 | /* | ||
| 267 | * Enumerated kcontrol | ||
| 268 | * | ||
| 269 | * File block representation for enum kcontrol :- | ||
| 270 | * +-----------------------------------+----+ | ||
| 271 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 272 | * +-----------------------------------+----+ | ||
| 273 | * | struct snd_soc_tplg_enum_control | N | | ||
| 274 | * +-----------------------------------+----+ | ||
| 275 | */ | ||
| 276 | struct snd_soc_tplg_enum_control { | ||
| 277 | struct snd_soc_tplg_ctl_hdr hdr; | ||
| 278 | __le32 size; /* in bytes of this structure */ | ||
| 279 | __le32 num_channels; | ||
| 280 | struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN]; | ||
| 281 | __le32 items; | ||
| 282 | __le32 mask; | ||
| 283 | __le32 count; | ||
| 284 | char texts[SND_SOC_TPLG_NUM_TEXTS][SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 285 | __le32 values[SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN / 4]; | ||
| 286 | struct snd_soc_tplg_private priv; | ||
| 287 | } __attribute__((packed)); | ||
| 288 | |||
| 289 | /* | ||
| 290 | * Bytes kcontrol | ||
| 291 | * | ||
| 292 | * File block representation for bytes kcontrol :- | ||
| 293 | * +-----------------------------------+----+ | ||
| 294 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 295 | * +-----------------------------------+----+ | ||
| 296 | * | struct snd_soc_tplg_bytes_control | N | | ||
| 297 | * +-----------------------------------+----+ | ||
| 298 | */ | ||
| 299 | struct snd_soc_tplg_bytes_control { | ||
| 300 | struct snd_soc_tplg_ctl_hdr hdr; | ||
| 301 | __le32 size; /* in bytes of this structure */ | ||
| 302 | __le32 max; | ||
| 303 | __le32 mask; | ||
| 304 | __le32 base; | ||
| 305 | __le32 num_regs; | ||
| 306 | struct snd_soc_tplg_private priv; | ||
| 307 | } __attribute__((packed)); | ||
| 308 | |||
| 309 | /* | ||
| 310 | * DAPM Graph Element | ||
| 311 | * | ||
| 312 | * File block representation for DAPM graph elements :- | ||
| 313 | * +-------------------------------------+----+ | ||
| 314 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 315 | * +-------------------------------------+----+ | ||
| 316 | * | struct snd_soc_tplg_dapm_graph_elem | N | | ||
| 317 | * +-------------------------------------+----+ | ||
| 318 | */ | ||
| 319 | struct snd_soc_tplg_dapm_graph_elem { | ||
| 320 | char sink[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 321 | char control[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 322 | char source[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 323 | } __attribute__((packed)); | ||
| 324 | |||
| 325 | /* | ||
| 326 | * DAPM Widget. | ||
| 327 | * | ||
| 328 | * File block representation for DAPM widget :- | ||
| 329 | * +-------------------------------------+-----+ | ||
| 330 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 331 | * +-------------------------------------+-----+ | ||
| 332 | * | struct snd_soc_tplg_dapm_widget | N | | ||
| 333 | * +-------------------------------------+-----+ | ||
| 334 | * | struct snd_soc_tplg_enum_control | 0|1 | | ||
| 335 | * | struct snd_soc_tplg_mixer_control | 0|N | | ||
| 336 | * +-------------------------------------+-----+ | ||
| 337 | * | ||
| 338 | * Optional enum or mixer control can be appended to the end of each widget | ||
| 339 | * in the block. | ||
| 340 | */ | ||
| 341 | struct snd_soc_tplg_dapm_widget { | ||
| 342 | __le32 size; /* in bytes of this structure */ | ||
| 343 | __le32 id; /* SND_SOC_DAPM_CTL */ | ||
| 344 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 345 | char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 346 | |||
| 347 | __le32 reg; /* negative reg = no direct dapm */ | ||
| 348 | __le32 shift; /* bits to shift */ | ||
| 349 | __le32 mask; /* non-shifted mask */ | ||
| 350 | __u32 invert; /* invert the power bit */ | ||
| 351 | __u32 ignore_suspend; /* kept enabled over suspend */ | ||
| 352 | __u16 event_flags; | ||
| 353 | __u16 event_type; | ||
| 354 | __u16 num_kcontrols; | ||
| 355 | struct snd_soc_tplg_private priv; | ||
| 356 | /* | ||
| 357 | * kcontrols that relate to this widget | ||
| 358 | * follow here after widget private data | ||
| 359 | */ | ||
| 360 | } __attribute__((packed)); | ||
| 361 | |||
| 362 | struct snd_soc_tplg_pcm_cfg_caps { | ||
| 363 | struct snd_soc_tplg_stream_caps caps; | ||
| 364 | struct snd_soc_tplg_stream_config configs[SND_SOC_TPLG_STREAM_CONFIG_MAX]; | ||
| 365 | __le32 num_configs; /* number of configs */ | ||
| 366 | } __attribute__((packed)); | ||
| 367 | |||
| 368 | /* | ||
| 369 | * Describes SW/FW specific features of PCM or DAI link. | ||
| 370 | * | ||
| 371 | * File block representation for PCM/DAI-Link :- | ||
| 372 | * +-----------------------------------+-----+ | ||
| 373 | * | struct snd_soc_tplg_hdr | 1 | | ||
| 374 | * +-----------------------------------+-----+ | ||
| 375 | * | struct snd_soc_tplg_dapm_pcm_dai | N | | ||
| 376 | * +-----------------------------------+-----+ | ||
| 377 | */ | ||
| 378 | struct snd_soc_tplg_pcm_dai { | ||
| 379 | __le32 size; /* in bytes of this structure */ | ||
| 380 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | ||
| 381 | __le32 id; /* unique ID - used to match */ | ||
| 382 | __le32 playback; /* supports playback mode */ | ||
| 383 | __le32 capture; /* supports capture mode */ | ||
| 384 | __le32 compress; /* 1 = compressed; 0 = PCM */ | ||
| 385 | struct snd_soc_tplg_pcm_cfg_caps capconf[2]; /* capabilities and configs */ | ||
| 386 | } __attribute__((packed)); | ||
| 387 | |||
| 388 | #endif | ||
diff --git a/include/uapi/sound/tlv.h b/include/uapi/sound/tlv.h new file mode 100644 index 000000000000..ffc4f203146c --- /dev/null +++ b/include/uapi/sound/tlv.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* | ||
| 2 | * This program is free software; you can redistribute it and/or modify | ||
| 3 | * it under the terms of the GNU General Public License as published by | ||
| 4 | * the Free Software Foundation; either version 2 of the License, or | ||
| 5 | * (at your option) any later version. | ||
| 6 | * | ||
| 7 | * This program is distributed in the hope that it will be useful, | ||
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | * GNU General Public License for more details. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #ifndef __UAPI_SOUND_TLV_H | ||
| 14 | #define __UAPI_SOUND_TLV_H | ||
| 15 | |||
| 16 | #define SNDRV_CTL_TLVT_CONTAINER 0 /* one level down - group of TLVs */ | ||
| 17 | #define SNDRV_CTL_TLVT_DB_SCALE 1 /* dB scale */ | ||
| 18 | #define SNDRV_CTL_TLVT_DB_LINEAR 2 /* linear volume */ | ||
| 19 | #define SNDRV_CTL_TLVT_DB_RANGE 3 /* dB range container */ | ||
| 20 | #define SNDRV_CTL_TLVT_DB_MINMAX 4 /* dB scale with min/max */ | ||
| 21 | #define SNDRV_CTL_TLVT_DB_MINMAX_MUTE 5 /* dB scale with min/max with mute */ | ||
| 22 | |||
| 23 | /* | ||
| 24 | * channel-mapping TLV items | ||
| 25 | * TLV length must match with num_channels | ||
| 26 | */ | ||
| 27 | #define SNDRV_CTL_TLVT_CHMAP_FIXED 0x101 /* fixed channel position */ | ||
| 28 | #define SNDRV_CTL_TLVT_CHMAP_VAR 0x102 /* channels freely swappable */ | ||
| 29 | #define SNDRV_CTL_TLVT_CHMAP_PAIRED 0x103 /* pair-wise swappable */ | ||
| 30 | |||
| 31 | #endif | ||
diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 974ba708b482..c2ef1ecefcbd 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o | 1 | snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o |
| 2 | snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o | 2 | snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o |
| 3 | snd-soc-core-objs += soc-topology.o | ||
| 3 | 4 | ||
| 4 | ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) | 5 | ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) |
| 5 | snd-soc-core-objs += soc-generic-dmaengine-pcm.o | 6 | snd-soc-core-objs += soc-generic-dmaengine-pcm.o |
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c index 9db7408f6e05..4cad8929d262 100644 --- a/sound/soc/codecs/twl6040.c +++ b/sound/soc/codecs/twl6040.c | |||
| @@ -1121,7 +1121,8 @@ static int twl6040_probe(struct snd_soc_codec *codec) | |||
| 1121 | mutex_init(&priv->mutex); | 1121 | mutex_init(&priv->mutex); |
| 1122 | 1122 | ||
| 1123 | ret = request_threaded_irq(priv->plug_irq, NULL, | 1123 | ret = request_threaded_irq(priv->plug_irq, NULL, |
| 1124 | twl6040_audio_handler, IRQF_NO_SUSPEND, | 1124 | twl6040_audio_handler, |
| 1125 | IRQF_NO_SUSPEND | IRQF_ONESHOT, | ||
| 1125 | "twl6040_irq_plug", codec); | 1126 | "twl6040_irq_plug", codec); |
| 1126 | if (ret) { | 1127 | if (ret) { |
| 1127 | dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); | 1128 | dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); |
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c index 98495dd61239..4c10cd88c1af 100644 --- a/sound/soc/codecs/wm5100.c +++ b/sound/soc/codecs/wm5100.c | |||
| @@ -2570,11 +2570,13 @@ static int wm5100_i2c_probe(struct i2c_client *i2c, | |||
| 2570 | 2570 | ||
| 2571 | if (irq_flags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) | 2571 | if (irq_flags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) |
| 2572 | ret = request_threaded_irq(i2c->irq, NULL, | 2572 | ret = request_threaded_irq(i2c->irq, NULL, |
| 2573 | wm5100_edge_irq, irq_flags, | 2573 | wm5100_edge_irq, |
| 2574 | irq_flags | IRQF_ONESHOT, | ||
| 2574 | "wm5100", wm5100); | 2575 | "wm5100", wm5100); |
| 2575 | else | 2576 | else |
| 2576 | ret = request_threaded_irq(i2c->irq, NULL, wm5100_irq, | 2577 | ret = request_threaded_irq(i2c->irq, NULL, wm5100_irq, |
| 2577 | irq_flags, "wm5100", | 2578 | irq_flags | IRQF_ONESHOT, |
| 2579 | "wm5100", | ||
| 2578 | wm5100); | 2580 | wm5100); |
| 2579 | 2581 | ||
| 2580 | if (ret != 0) { | 2582 | if (ret != 0) { |
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c index 9e71c768966f..09ff01f2fc1e 100644 --- a/sound/soc/codecs/wm8741.c +++ b/sound/soc/codecs/wm8741.c | |||
| @@ -41,6 +41,7 @@ static const char *wm8741_supply_names[WM8741_NUM_SUPPLIES] = { | |||
| 41 | 41 | ||
| 42 | /* codec private data */ | 42 | /* codec private data */ |
| 43 | struct wm8741_priv { | 43 | struct wm8741_priv { |
| 44 | struct wm8741_platform_data pdata; | ||
| 44 | struct regmap *regmap; | 45 | struct regmap *regmap; |
| 45 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; | 46 | struct regulator_bulk_data supplies[WM8741_NUM_SUPPLIES]; |
| 46 | unsigned int sysclk; | 47 | unsigned int sysclk; |
| @@ -87,13 +88,27 @@ static int wm8741_reset(struct snd_soc_codec *codec) | |||
| 87 | static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, -12700, 13, 0); | 88 | static const DECLARE_TLV_DB_SCALE(dac_tlv_fine, -12700, 13, 0); |
| 88 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 400, 0); | 89 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 400, 0); |
| 89 | 90 | ||
| 90 | static const struct snd_kcontrol_new wm8741_snd_controls[] = { | 91 | static const struct snd_kcontrol_new wm8741_snd_controls_stereo[] = { |
| 91 | SOC_DOUBLE_R_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION, | 92 | SOC_DOUBLE_R_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION, |
| 92 | WM8741_DACRLSB_ATTENUATION, 1, 255, 1, dac_tlv_fine), | 93 | WM8741_DACRLSB_ATTENUATION, 1, 255, 1, dac_tlv_fine), |
| 93 | SOC_DOUBLE_R_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION, | 94 | SOC_DOUBLE_R_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION, |
| 94 | WM8741_DACRMSB_ATTENUATION, 0, 511, 1, dac_tlv), | 95 | WM8741_DACRMSB_ATTENUATION, 0, 511, 1, dac_tlv), |
| 95 | }; | 96 | }; |
| 96 | 97 | ||
| 98 | static const struct snd_kcontrol_new wm8741_snd_controls_mono_left[] = { | ||
| 99 | SOC_SINGLE_TLV("Fine Playback Volume", WM8741_DACLLSB_ATTENUATION, | ||
| 100 | 1, 255, 1, dac_tlv_fine), | ||
| 101 | SOC_SINGLE_TLV("Playback Volume", WM8741_DACLMSB_ATTENUATION, | ||
| 102 | 0, 511, 1, dac_tlv), | ||
| 103 | }; | ||
| 104 | |||
| 105 | static const struct snd_kcontrol_new wm8741_snd_controls_mono_right[] = { | ||
| 106 | SOC_SINGLE_TLV("Fine Playback Volume", WM8741_DACRLSB_ATTENUATION, | ||
| 107 | 1, 255, 1, dac_tlv_fine), | ||
| 108 | SOC_SINGLE_TLV("Playback Volume", WM8741_DACRMSB_ATTENUATION, | ||
| 109 | 0, 511, 1, dac_tlv), | ||
| 110 | }; | ||
| 111 | |||
| 97 | static const struct snd_soc_dapm_widget wm8741_dapm_widgets[] = { | 112 | static const struct snd_soc_dapm_widget wm8741_dapm_widgets[] = { |
| 98 | SND_SOC_DAPM_DAC("DACL", "Playback", SND_SOC_NOPM, 0, 0), | 113 | SND_SOC_DAPM_DAC("DACL", "Playback", SND_SOC_NOPM, 0, 0), |
| 99 | SND_SOC_DAPM_DAC("DACR", "Playback", SND_SOC_NOPM, 0, 0), | 114 | SND_SOC_DAPM_DAC("DACR", "Playback", SND_SOC_NOPM, 0, 0), |
| @@ -398,7 +413,7 @@ static struct snd_soc_dai_driver wm8741_dai = { | |||
| 398 | .name = "wm8741", | 413 | .name = "wm8741", |
| 399 | .playback = { | 414 | .playback = { |
| 400 | .stream_name = "Playback", | 415 | .stream_name = "Playback", |
| 401 | .channels_min = 2, /* Mono modes not yet supported */ | 416 | .channels_min = 2, |
| 402 | .channels_max = 2, | 417 | .channels_max = 2, |
| 403 | .rates = WM8741_RATES, | 418 | .rates = WM8741_RATES, |
| 404 | .formats = WM8741_FORMATS, | 419 | .formats = WM8741_FORMATS, |
| @@ -416,6 +431,65 @@ static int wm8741_resume(struct snd_soc_codec *codec) | |||
| 416 | #define wm8741_resume NULL | 431 | #define wm8741_resume NULL |
| 417 | #endif | 432 | #endif |
| 418 | 433 | ||
| 434 | static int wm8741_configure(struct snd_soc_codec *codec) | ||
| 435 | { | ||
| 436 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); | ||
| 437 | |||
| 438 | /* Configure differential mode */ | ||
| 439 | switch (wm8741->pdata.diff_mode) { | ||
| 440 | case WM8741_DIFF_MODE_STEREO: | ||
| 441 | case WM8741_DIFF_MODE_STEREO_REVERSED: | ||
| 442 | case WM8741_DIFF_MODE_MONO_LEFT: | ||
| 443 | case WM8741_DIFF_MODE_MONO_RIGHT: | ||
| 444 | snd_soc_update_bits(codec, WM8741_MODE_CONTROL_2, | ||
| 445 | WM8741_DIFF_MASK, | ||
| 446 | wm8741->pdata.diff_mode << WM8741_DIFF_SHIFT); | ||
| 447 | break; | ||
| 448 | default: | ||
| 449 | return -EINVAL; | ||
| 450 | } | ||
| 451 | |||
| 452 | /* Change some default settings - latch VU */ | ||
| 453 | snd_soc_update_bits(codec, WM8741_DACLLSB_ATTENUATION, | ||
| 454 | WM8741_UPDATELL, WM8741_UPDATELL); | ||
| 455 | snd_soc_update_bits(codec, WM8741_DACLMSB_ATTENUATION, | ||
| 456 | WM8741_UPDATELM, WM8741_UPDATELM); | ||
| 457 | snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION, | ||
| 458 | WM8741_UPDATERL, WM8741_UPDATERL); | ||
| 459 | snd_soc_update_bits(codec, WM8741_DACRMSB_ATTENUATION, | ||
| 460 | WM8741_UPDATERM, WM8741_UPDATERM); | ||
| 461 | |||
| 462 | return 0; | ||
| 463 | } | ||
| 464 | |||
| 465 | static int wm8741_add_controls(struct snd_soc_codec *codec) | ||
| 466 | { | ||
| 467 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); | ||
| 468 | |||
| 469 | switch (wm8741->pdata.diff_mode) { | ||
| 470 | case WM8741_DIFF_MODE_STEREO: | ||
| 471 | case WM8741_DIFF_MODE_STEREO_REVERSED: | ||
| 472 | snd_soc_add_codec_controls(codec, | ||
| 473 | wm8741_snd_controls_stereo, | ||
| 474 | ARRAY_SIZE(wm8741_snd_controls_stereo)); | ||
| 475 | break; | ||
| 476 | case WM8741_DIFF_MODE_MONO_LEFT: | ||
| 477 | snd_soc_add_codec_controls(codec, | ||
| 478 | wm8741_snd_controls_mono_left, | ||
| 479 | ARRAY_SIZE(wm8741_snd_controls_mono_left)); | ||
| 480 | break; | ||
| 481 | case WM8741_DIFF_MODE_MONO_RIGHT: | ||
| 482 | snd_soc_add_codec_controls(codec, | ||
| 483 | wm8741_snd_controls_mono_right, | ||
| 484 | ARRAY_SIZE(wm8741_snd_controls_mono_right)); | ||
| 485 | break; | ||
| 486 | default: | ||
| 487 | return -EINVAL; | ||
| 488 | } | ||
| 489 | |||
| 490 | return 0; | ||
| 491 | } | ||
| 492 | |||
| 419 | static int wm8741_probe(struct snd_soc_codec *codec) | 493 | static int wm8741_probe(struct snd_soc_codec *codec) |
| 420 | { | 494 | { |
| 421 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); | 495 | struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); |
| @@ -434,15 +508,17 @@ static int wm8741_probe(struct snd_soc_codec *codec) | |||
| 434 | goto err_enable; | 508 | goto err_enable; |
| 435 | } | 509 | } |
| 436 | 510 | ||
| 437 | /* Change some default settings - latch VU */ | 511 | ret = wm8741_configure(codec); |
| 438 | snd_soc_update_bits(codec, WM8741_DACLLSB_ATTENUATION, | 512 | if (ret < 0) { |
| 439 | WM8741_UPDATELL, WM8741_UPDATELL); | 513 | dev_err(codec->dev, "Failed to change default settings\n"); |
| 440 | snd_soc_update_bits(codec, WM8741_DACLMSB_ATTENUATION, | 514 | goto err_enable; |
| 441 | WM8741_UPDATELM, WM8741_UPDATELM); | 515 | } |
| 442 | snd_soc_update_bits(codec, WM8741_DACRLSB_ATTENUATION, | 516 | |
| 443 | WM8741_UPDATERL, WM8741_UPDATERL); | 517 | ret = wm8741_add_controls(codec); |
| 444 | snd_soc_update_bits(codec, WM8741_DACRMSB_ATTENUATION, | 518 | if (ret < 0) { |
| 445 | WM8741_UPDATERM, WM8741_UPDATERM); | 519 | dev_err(codec->dev, "Failed to add controls\n"); |
| 520 | goto err_enable; | ||
| 521 | } | ||
| 446 | 522 | ||
| 447 | dev_dbg(codec->dev, "Successful registration\n"); | 523 | dev_dbg(codec->dev, "Successful registration\n"); |
| 448 | return ret; | 524 | return ret; |
| @@ -467,8 +543,6 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8741 = { | |||
| 467 | .remove = wm8741_remove, | 543 | .remove = wm8741_remove, |
| 468 | .resume = wm8741_resume, | 544 | .resume = wm8741_resume, |
| 469 | 545 | ||
| 470 | .controls = wm8741_snd_controls, | ||
| 471 | .num_controls = ARRAY_SIZE(wm8741_snd_controls), | ||
| 472 | .dapm_widgets = wm8741_dapm_widgets, | 546 | .dapm_widgets = wm8741_dapm_widgets, |
| 473 | .num_dapm_widgets = ARRAY_SIZE(wm8741_dapm_widgets), | 547 | .num_dapm_widgets = ARRAY_SIZE(wm8741_dapm_widgets), |
| 474 | .dapm_routes = wm8741_dapm_routes, | 548 | .dapm_routes = wm8741_dapm_routes, |
| @@ -493,6 +567,23 @@ static const struct regmap_config wm8741_regmap = { | |||
| 493 | .readable_reg = wm8741_readable, | 567 | .readable_reg = wm8741_readable, |
| 494 | }; | 568 | }; |
| 495 | 569 | ||
| 570 | static int wm8741_set_pdata(struct device *dev, struct wm8741_priv *wm8741) | ||
| 571 | { | ||
| 572 | const struct wm8741_platform_data *pdata = dev_get_platdata(dev); | ||
| 573 | u32 diff_mode; | ||
| 574 | |||
| 575 | if (dev->of_node) { | ||
| 576 | if (of_property_read_u32(dev->of_node, "diff-mode", &diff_mode) | ||
| 577 | >= 0) | ||
| 578 | wm8741->pdata.diff_mode = diff_mode; | ||
| 579 | } else { | ||
| 580 | if (pdata != NULL) | ||
| 581 | memcpy(&wm8741->pdata, pdata, sizeof(wm8741->pdata)); | ||
| 582 | } | ||
| 583 | |||
| 584 | return 0; | ||
| 585 | } | ||
| 586 | |||
| 496 | #if IS_ENABLED(CONFIG_I2C) | 587 | #if IS_ENABLED(CONFIG_I2C) |
| 497 | static int wm8741_i2c_probe(struct i2c_client *i2c, | 588 | static int wm8741_i2c_probe(struct i2c_client *i2c, |
| 498 | const struct i2c_device_id *id) | 589 | const struct i2c_device_id *id) |
| @@ -522,6 +613,12 @@ static int wm8741_i2c_probe(struct i2c_client *i2c, | |||
| 522 | return ret; | 613 | return ret; |
| 523 | } | 614 | } |
| 524 | 615 | ||
| 616 | ret = wm8741_set_pdata(&i2c->dev, wm8741); | ||
| 617 | if (ret != 0) { | ||
| 618 | dev_err(&i2c->dev, "Failed to set pdata: %d\n", ret); | ||
| 619 | return ret; | ||
| 620 | } | ||
| 621 | |||
| 525 | i2c_set_clientdata(i2c, wm8741); | 622 | i2c_set_clientdata(i2c, wm8741); |
| 526 | 623 | ||
| 527 | ret = snd_soc_register_codec(&i2c->dev, | 624 | ret = snd_soc_register_codec(&i2c->dev, |
| @@ -582,6 +679,12 @@ static int wm8741_spi_probe(struct spi_device *spi) | |||
| 582 | return ret; | 679 | return ret; |
| 583 | } | 680 | } |
| 584 | 681 | ||
| 682 | ret = wm8741_set_pdata(&spi->dev, wm8741); | ||
| 683 | if (ret != 0) { | ||
| 684 | dev_err(&spi->dev, "Failed to set pdata: %d\n", ret); | ||
| 685 | return ret; | ||
| 686 | } | ||
| 687 | |||
| 585 | spi_set_drvdata(spi, wm8741); | 688 | spi_set_drvdata(spi, wm8741); |
| 586 | 689 | ||
| 587 | ret = snd_soc_register_codec(&spi->dev, | 690 | ret = snd_soc_register_codec(&spi->dev, |
diff --git a/sound/soc/codecs/wm8741.h b/sound/soc/codecs/wm8741.h index 56c1b1d4a681..c8835f65f342 100644 --- a/sound/soc/codecs/wm8741.h +++ b/sound/soc/codecs/wm8741.h | |||
| @@ -194,6 +194,12 @@ | |||
| 194 | #define WM8741_DITHER_SHIFT 0 /* DITHER - [1:0] */ | 194 | #define WM8741_DITHER_SHIFT 0 /* DITHER - [1:0] */ |
| 195 | #define WM8741_DITHER_WIDTH 2 /* DITHER - [1:0] */ | 195 | #define WM8741_DITHER_WIDTH 2 /* DITHER - [1:0] */ |
| 196 | 196 | ||
| 197 | /* DIFF field values */ | ||
| 198 | #define WM8741_DIFF_MODE_STEREO 0 /* stereo normal */ | ||
| 199 | #define WM8741_DIFF_MODE_STEREO_REVERSED 2 /* stereo reversed */ | ||
| 200 | #define WM8741_DIFF_MODE_MONO_LEFT 1 /* mono left */ | ||
| 201 | #define WM8741_DIFF_MODE_MONO_RIGHT 3 /* mono right */ | ||
| 202 | |||
| 197 | /* | 203 | /* |
| 198 | * R32 (0x20) - ADDITONAL_CONTROL_1 | 204 | * R32 (0x20) - ADDITONAL_CONTROL_1 |
| 199 | */ | 205 | */ |
| @@ -208,4 +214,8 @@ | |||
| 208 | 214 | ||
| 209 | #define WM8741_SYSCLK 0 | 215 | #define WM8741_SYSCLK 0 |
| 210 | 216 | ||
| 217 | struct wm8741_platform_data { | ||
| 218 | u32 diff_mode; /* Differential Output Mode */ | ||
| 219 | }; | ||
| 220 | |||
| 211 | #endif | 221 | #endif |
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index af095b64f880..761418f05d59 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c | |||
| @@ -127,6 +127,8 @@ struct wm8960_priv { | |||
| 127 | struct snd_soc_dapm_widget *out3; | 127 | struct snd_soc_dapm_widget *out3; |
| 128 | bool deemph; | 128 | bool deemph; |
| 129 | int playback_fs; | 129 | int playback_fs; |
| 130 | int bclk; | ||
| 131 | int sysclk; | ||
| 130 | struct wm8960_data pdata; | 132 | struct wm8960_data pdata; |
| 131 | }; | 133 | }; |
| 132 | 134 | ||
| @@ -563,6 +565,72 @@ static struct { | |||
| 563 | { 8000, 5 }, | 565 | { 8000, 5 }, |
| 564 | }; | 566 | }; |
| 565 | 567 | ||
| 568 | /* Multiply 256 for internal 256 div */ | ||
| 569 | static const int dac_divs[] = { 256, 384, 512, 768, 1024, 1408, 1536 }; | ||
| 570 | |||
| 571 | /* Multiply 10 to eliminate decimials */ | ||
| 572 | static const int bclk_divs[] = { | ||
| 573 | 10, 15, 20, 30, 40, 55, 60, 80, 110, | ||
| 574 | 120, 160, 220, 240, 320, 320, 320 | ||
| 575 | }; | ||
| 576 | |||
| 577 | static void wm8960_configure_clocking(struct snd_soc_codec *codec, | ||
| 578 | bool tx, int lrclk) | ||
| 579 | { | ||
| 580 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); | ||
| 581 | u16 iface1 = snd_soc_read(codec, WM8960_IFACE1); | ||
| 582 | u16 iface2 = snd_soc_read(codec, WM8960_IFACE2); | ||
| 583 | u32 sysclk; | ||
| 584 | int i, j; | ||
| 585 | |||
| 586 | if (!(iface1 & (1<<6))) { | ||
| 587 | dev_dbg(codec->dev, | ||
| 588 | "Codec is slave mode, no need to configure clock\n"); | ||
| 589 | return; | ||
| 590 | } | ||
| 591 | |||
| 592 | if (!wm8960->sysclk) { | ||
| 593 | dev_dbg(codec->dev, "No SYSCLK configured\n"); | ||
| 594 | return; | ||
| 595 | } | ||
| 596 | |||
| 597 | if (!wm8960->bclk || !lrclk) { | ||
| 598 | dev_dbg(codec->dev, "No audio clocks configured\n"); | ||
| 599 | return; | ||
| 600 | } | ||
| 601 | |||
| 602 | for (i = 0; i < ARRAY_SIZE(dac_divs); ++i) { | ||
| 603 | if (wm8960->sysclk == lrclk * dac_divs[i]) { | ||
| 604 | for (j = 0; j < ARRAY_SIZE(bclk_divs); ++j) { | ||
| 605 | sysclk = wm8960->bclk * bclk_divs[j] / 10; | ||
| 606 | if (wm8960->sysclk == sysclk) | ||
| 607 | break; | ||
| 608 | } | ||
| 609 | if(j != ARRAY_SIZE(bclk_divs)) | ||
| 610 | break; | ||
| 611 | } | ||
| 612 | } | ||
| 613 | |||
| 614 | if (i == ARRAY_SIZE(dac_divs)) { | ||
| 615 | dev_err(codec->dev, "Unsupported sysclk %d\n", wm8960->sysclk); | ||
| 616 | return; | ||
| 617 | } | ||
| 618 | |||
| 619 | /* | ||
| 620 | * configure frame clock. If ADCLRC configure as GPIO pin, DACLRC | ||
| 621 | * pin is used as a frame clock for ADCs and DACs. | ||
| 622 | */ | ||
| 623 | if (iface2 & (1<<6)) | ||
| 624 | snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 3, i << 3); | ||
| 625 | else if (tx) | ||
| 626 | snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 3, i << 3); | ||
| 627 | else if (!tx) | ||
| 628 | snd_soc_update_bits(codec, WM8960_CLOCK1, 0x7 << 6, i << 6); | ||
| 629 | |||
| 630 | /* configure bit clock */ | ||
| 631 | snd_soc_update_bits(codec, WM8960_CLOCK2, 0xf, j); | ||
| 632 | } | ||
| 633 | |||
| 566 | static int wm8960_hw_params(struct snd_pcm_substream *substream, | 634 | static int wm8960_hw_params(struct snd_pcm_substream *substream, |
| 567 | struct snd_pcm_hw_params *params, | 635 | struct snd_pcm_hw_params *params, |
| 568 | struct snd_soc_dai *dai) | 636 | struct snd_soc_dai *dai) |
| @@ -570,8 +638,13 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream, | |||
| 570 | struct snd_soc_codec *codec = dai->codec; | 638 | struct snd_soc_codec *codec = dai->codec; |
| 571 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); | 639 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 572 | u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; | 640 | u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; |
| 641 | bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; | ||
| 573 | int i; | 642 | int i; |
| 574 | 643 | ||
| 644 | wm8960->bclk = snd_soc_params_to_bclk(params); | ||
| 645 | if (params_channels(params) == 1) | ||
| 646 | wm8960->bclk *= 2; | ||
| 647 | |||
| 575 | /* bit size */ | 648 | /* bit size */ |
| 576 | switch (params_width(params)) { | 649 | switch (params_width(params)) { |
| 577 | case 16: | 650 | case 16: |
| @@ -582,6 +655,12 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream, | |||
| 582 | case 24: | 655 | case 24: |
| 583 | iface |= 0x0008; | 656 | iface |= 0x0008; |
| 584 | break; | 657 | break; |
| 658 | case 32: | ||
| 659 | /* right justify mode does not support 32 word length */ | ||
| 660 | if ((iface & 0x3) != 0) { | ||
| 661 | iface |= 0x000c; | ||
| 662 | break; | ||
| 663 | } | ||
| 585 | default: | 664 | default: |
| 586 | dev_err(codec->dev, "unsupported width %d\n", | 665 | dev_err(codec->dev, "unsupported width %d\n", |
| 587 | params_width(params)); | 666 | params_width(params)); |
| @@ -602,6 +681,9 @@ static int wm8960_hw_params(struct snd_pcm_substream *substream, | |||
| 602 | 681 | ||
| 603 | /* set iface */ | 682 | /* set iface */ |
| 604 | snd_soc_write(codec, WM8960_IFACE1, iface); | 683 | snd_soc_write(codec, WM8960_IFACE1, iface); |
| 684 | |||
| 685 | wm8960_configure_clocking(codec, tx, params_rate(params)); | ||
| 686 | |||
| 605 | return 0; | 687 | return 0; |
| 606 | } | 688 | } |
| 607 | 689 | ||
| @@ -946,11 +1028,35 @@ static int wm8960_set_bias_level(struct snd_soc_codec *codec, | |||
| 946 | return wm8960->set_bias_level(codec, level); | 1028 | return wm8960->set_bias_level(codec, level); |
| 947 | } | 1029 | } |
| 948 | 1030 | ||
| 1031 | static int wm8960_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id, | ||
| 1032 | unsigned int freq, int dir) | ||
| 1033 | { | ||
| 1034 | struct snd_soc_codec *codec = dai->codec; | ||
| 1035 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); | ||
| 1036 | |||
| 1037 | switch (clk_id) { | ||
| 1038 | case WM8960_SYSCLK_MCLK: | ||
| 1039 | snd_soc_update_bits(codec, WM8960_CLOCK1, | ||
| 1040 | 0x1, WM8960_SYSCLK_MCLK); | ||
| 1041 | break; | ||
| 1042 | case WM8960_SYSCLK_PLL: | ||
| 1043 | snd_soc_update_bits(codec, WM8960_CLOCK1, | ||
| 1044 | 0x1, WM8960_SYSCLK_PLL); | ||
| 1045 | break; | ||
| 1046 | default: | ||
| 1047 | return -EINVAL; | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | wm8960->sysclk = freq; | ||
| 1051 | |||
| 1052 | return 0; | ||
| 1053 | } | ||
| 1054 | |||
| 949 | #define WM8960_RATES SNDRV_PCM_RATE_8000_48000 | 1055 | #define WM8960_RATES SNDRV_PCM_RATE_8000_48000 |
| 950 | 1056 | ||
| 951 | #define WM8960_FORMATS \ | 1057 | #define WM8960_FORMATS \ |
| 952 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ | 1058 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
| 953 | SNDRV_PCM_FMTBIT_S24_LE) | 1059 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 954 | 1060 | ||
| 955 | static const struct snd_soc_dai_ops wm8960_dai_ops = { | 1061 | static const struct snd_soc_dai_ops wm8960_dai_ops = { |
| 956 | .hw_params = wm8960_hw_params, | 1062 | .hw_params = wm8960_hw_params, |
| @@ -958,6 +1064,7 @@ static const struct snd_soc_dai_ops wm8960_dai_ops = { | |||
| 958 | .set_fmt = wm8960_set_dai_fmt, | 1064 | .set_fmt = wm8960_set_dai_fmt, |
| 959 | .set_clkdiv = wm8960_set_dai_clkdiv, | 1065 | .set_clkdiv = wm8960_set_dai_clkdiv, |
| 960 | .set_pll = wm8960_set_dai_pll, | 1066 | .set_pll = wm8960_set_dai_pll, |
| 1067 | .set_sysclk = wm8960_set_dai_sysclk, | ||
| 961 | }; | 1068 | }; |
| 962 | 1069 | ||
| 963 | static struct snd_soc_dai_driver wm8960_dai = { | 1070 | static struct snd_soc_dai_driver wm8960_dai = { |
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 95f83bec1d14..3a4a5c0e3f97 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c | |||
| @@ -40,6 +40,7 @@ | |||
| 40 | #include <sound/pcm_params.h> | 40 | #include <sound/pcm_params.h> |
| 41 | #include <sound/soc.h> | 41 | #include <sound/soc.h> |
| 42 | #include <sound/soc-dpcm.h> | 42 | #include <sound/soc-dpcm.h> |
| 43 | #include <sound/soc-topology.h> | ||
| 43 | #include <sound/initval.h> | 44 | #include <sound/initval.h> |
| 44 | 45 | ||
| 45 | #define CREATE_TRACE_POINTS | 46 | #define CREATE_TRACE_POINTS |
| @@ -2418,6 +2419,7 @@ int snd_soc_register_card(struct snd_soc_card *card) | |||
| 2418 | card->rtd_aux[i].card = card; | 2419 | card->rtd_aux[i].card = card; |
| 2419 | 2420 | ||
| 2420 | INIT_LIST_HEAD(&card->dapm_dirty); | 2421 | INIT_LIST_HEAD(&card->dapm_dirty); |
| 2422 | INIT_LIST_HEAD(&card->dobj_list); | ||
| 2421 | card->instantiated = 0; | 2423 | card->instantiated = 0; |
| 2422 | mutex_init(&card->mutex); | 2424 | mutex_init(&card->mutex); |
| 2423 | mutex_init(&card->dapm_mutex); | 2425 | mutex_init(&card->dapm_mutex); |
| @@ -2733,6 +2735,7 @@ static void snd_soc_component_add_unlocked(struct snd_soc_component *component) | |||
| 2733 | } | 2735 | } |
| 2734 | 2736 | ||
| 2735 | list_add(&component->list, &component_list); | 2737 | list_add(&component->list, &component_list); |
| 2738 | INIT_LIST_HEAD(&component->dobj_list); | ||
| 2736 | } | 2739 | } |
| 2737 | 2740 | ||
| 2738 | static void snd_soc_component_add(struct snd_soc_component *component) | 2741 | static void snd_soc_component_add(struct snd_soc_component *component) |
| @@ -2809,6 +2812,7 @@ void snd_soc_unregister_component(struct device *dev) | |||
| 2809 | return; | 2812 | return; |
| 2810 | 2813 | ||
| 2811 | found: | 2814 | found: |
| 2815 | snd_soc_tplg_component_remove(cmpnt, SND_SOC_TPLG_INDEX_ALL); | ||
| 2812 | snd_soc_component_del_unlocked(cmpnt); | 2816 | snd_soc_component_del_unlocked(cmpnt); |
| 2813 | mutex_unlock(&client_mutex); | 2817 | mutex_unlock(&client_mutex); |
| 2814 | snd_soc_component_cleanup(cmpnt); | 2818 | snd_soc_component_cleanup(cmpnt); |
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c new file mode 100644 index 000000000000..d0960683c409 --- /dev/null +++ b/sound/soc/soc-topology.c | |||
| @@ -0,0 +1,1826 @@ | |||
| 1 | /* | ||
| 2 | * soc-topology.c -- ALSA SoC Topology | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 Texas Instruments Inc. | ||
| 5 | * Copyright (C) 2015 Intel Corporation. | ||
| 6 | * | ||
| 7 | * Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com> | ||
| 8 | * K, Mythri P <mythri.p.k@intel.com> | ||
| 9 | * Prusty, Subhransu S <subhransu.s.prusty@intel.com> | ||
| 10 | * B, Jayachandran <jayachandran.b@intel.com> | ||
| 11 | * Abdullah, Omair M <omair.m.abdullah@intel.com> | ||
| 12 | * Jin, Yao <yao.jin@intel.com> | ||
| 13 | * Lin, Mengdong <mengdong.lin@intel.com> | ||
| 14 | * | ||
| 15 | * This program is free software; you can redistribute it and/or modify it | ||
| 16 | * under the terms of the GNU General Public License as published by the | ||
| 17 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 18 | * option) any later version. | ||
| 19 | * | ||
| 20 | * Add support to read audio firmware topology alongside firmware text. The | ||
| 21 | * topology data can contain kcontrols, DAPM graphs, widgets, DAIs, DAI links, | ||
| 22 | * equalizers, firmware, coefficients etc. | ||
| 23 | * | ||
| 24 | * This file only manages the core ALSA and ASoC components, all other bespoke | ||
| 25 | * firmware topology data is passed to component drivers for bespoke handling. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <linux/kernel.h> | ||
| 29 | #include <linux/export.h> | ||
| 30 | #include <linux/list.h> | ||
| 31 | #include <linux/firmware.h> | ||
| 32 | #include <linux/slab.h> | ||
| 33 | #include <sound/soc.h> | ||
| 34 | #include <sound/soc-dapm.h> | ||
| 35 | #include <sound/soc-topology.h> | ||
| 36 | |||
| 37 | /* | ||
| 38 | * We make several passes over the data (since it wont necessarily be ordered) | ||
| 39 | * and process objects in the following order. This guarantees the component | ||
| 40 | * drivers will be ready with any vendor data before the mixers and DAPM objects | ||
| 41 | * are loaded (that may make use of the vendor data). | ||
| 42 | */ | ||
| 43 | #define SOC_TPLG_PASS_MANIFEST 0 | ||
| 44 | #define SOC_TPLG_PASS_VENDOR 1 | ||
| 45 | #define SOC_TPLG_PASS_MIXER 2 | ||
| 46 | #define SOC_TPLG_PASS_WIDGET 3 | ||
| 47 | #define SOC_TPLG_PASS_GRAPH 4 | ||
| 48 | #define SOC_TPLG_PASS_PINS 5 | ||
| 49 | #define SOC_TPLG_PASS_PCM_DAI 6 | ||
| 50 | |||
| 51 | #define SOC_TPLG_PASS_START SOC_TPLG_PASS_MANIFEST | ||
| 52 | #define SOC_TPLG_PASS_END SOC_TPLG_PASS_PCM_DAI | ||
| 53 | |||
| 54 | struct soc_tplg { | ||
| 55 | const struct firmware *fw; | ||
| 56 | |||
| 57 | /* runtime FW parsing */ | ||
| 58 | const u8 *pos; /* read postion */ | ||
| 59 | const u8 *hdr_pos; /* header position */ | ||
| 60 | unsigned int pass; /* pass number */ | ||
| 61 | |||
| 62 | /* component caller */ | ||
| 63 | struct device *dev; | ||
| 64 | struct snd_soc_component *comp; | ||
| 65 | u32 index; /* current block index */ | ||
| 66 | u32 req_index; /* required index, only loaded/free matching blocks */ | ||
| 67 | |||
| 68 | /* kcontrol operations */ | ||
| 69 | const struct snd_soc_tplg_kcontrol_ops *io_ops; | ||
| 70 | int io_ops_count; | ||
| 71 | |||
| 72 | /* optional fw loading callbacks to component drivers */ | ||
| 73 | struct snd_soc_tplg_ops *ops; | ||
| 74 | }; | ||
| 75 | |||
| 76 | static int soc_tplg_process_headers(struct soc_tplg *tplg); | ||
| 77 | static void soc_tplg_complete(struct soc_tplg *tplg); | ||
| 78 | struct snd_soc_dapm_widget * | ||
| 79 | snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, | ||
| 80 | const struct snd_soc_dapm_widget *widget); | ||
| 81 | struct snd_soc_dapm_widget * | ||
| 82 | snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, | ||
| 83 | const struct snd_soc_dapm_widget *widget); | ||
| 84 | |||
| 85 | /* check we dont overflow the data for this control chunk */ | ||
| 86 | static int soc_tplg_check_elem_count(struct soc_tplg *tplg, size_t elem_size, | ||
| 87 | unsigned int count, size_t bytes, const char *elem_type) | ||
| 88 | { | ||
| 89 | const u8 *end = tplg->pos + elem_size * count; | ||
| 90 | |||
| 91 | if (end > tplg->fw->data + tplg->fw->size) { | ||
| 92 | dev_err(tplg->dev, "ASoC: %s overflow end of data\n", | ||
| 93 | elem_type); | ||
| 94 | return -EINVAL; | ||
| 95 | } | ||
| 96 | |||
| 97 | /* check there is enough room in chunk for control. | ||
| 98 | extra bytes at the end of control are for vendor data here */ | ||
| 99 | if (elem_size * count > bytes) { | ||
| 100 | dev_err(tplg->dev, | ||
| 101 | "ASoC: %s count %d of size %zu is bigger than chunk %zu\n", | ||
| 102 | elem_type, count, elem_size, bytes); | ||
| 103 | return -EINVAL; | ||
| 104 | } | ||
| 105 | |||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | |||
| 109 | static inline int soc_tplg_is_eof(struct soc_tplg *tplg) | ||
| 110 | { | ||
| 111 | const u8 *end = tplg->hdr_pos; | ||
| 112 | |||
| 113 | if (end >= tplg->fw->data + tplg->fw->size) | ||
| 114 | return 1; | ||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | static inline unsigned long soc_tplg_get_hdr_offset(struct soc_tplg *tplg) | ||
| 119 | { | ||
| 120 | return (unsigned long)(tplg->hdr_pos - tplg->fw->data); | ||
| 121 | } | ||
| 122 | |||
| 123 | static inline unsigned long soc_tplg_get_offset(struct soc_tplg *tplg) | ||
| 124 | { | ||
| 125 | return (unsigned long)(tplg->pos - tplg->fw->data); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* mapping of Kcontrol types and associated operations. */ | ||
| 129 | static const struct snd_soc_tplg_kcontrol_ops io_ops[] = { | ||
| 130 | {SND_SOC_TPLG_CTL_VOLSW, snd_soc_get_volsw, | ||
| 131 | snd_soc_put_volsw, snd_soc_info_volsw}, | ||
| 132 | {SND_SOC_TPLG_CTL_VOLSW_SX, snd_soc_get_volsw_sx, | ||
| 133 | snd_soc_put_volsw_sx, NULL}, | ||
| 134 | {SND_SOC_TPLG_CTL_ENUM, snd_soc_get_enum_double, | ||
| 135 | snd_soc_put_enum_double, snd_soc_info_enum_double}, | ||
| 136 | {SND_SOC_TPLG_CTL_ENUM_VALUE, snd_soc_get_enum_double, | ||
| 137 | snd_soc_put_enum_double, NULL}, | ||
| 138 | {SND_SOC_TPLG_CTL_BYTES, snd_soc_bytes_get, | ||
| 139 | snd_soc_bytes_put, snd_soc_bytes_info}, | ||
| 140 | {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw_range, | ||
| 141 | snd_soc_put_volsw_range, snd_soc_info_volsw_range}, | ||
| 142 | {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx, | ||
| 143 | snd_soc_put_xr_sx, snd_soc_info_xr_sx}, | ||
| 144 | {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe, | ||
| 145 | snd_soc_put_strobe, NULL}, | ||
| 146 | {SND_SOC_TPLG_DAPM_CTL_VOLSW, snd_soc_dapm_get_volsw, | ||
| 147 | snd_soc_dapm_put_volsw, NULL}, | ||
| 148 | {SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE, snd_soc_dapm_get_enum_double, | ||
| 149 | snd_soc_dapm_put_enum_double, snd_soc_info_enum_double}, | ||
| 150 | {SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT, snd_soc_dapm_get_enum_double, | ||
| 151 | snd_soc_dapm_put_enum_double, NULL}, | ||
| 152 | {SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE, snd_soc_dapm_get_enum_double, | ||
| 153 | snd_soc_dapm_put_enum_double, NULL}, | ||
| 154 | {SND_SOC_TPLG_DAPM_CTL_PIN, snd_soc_dapm_get_pin_switch, | ||
| 155 | snd_soc_dapm_put_pin_switch, snd_soc_dapm_info_pin_switch}, | ||
| 156 | }; | ||
| 157 | |||
| 158 | struct soc_tplg_map { | ||
| 159 | int uid; | ||
| 160 | int kid; | ||
| 161 | }; | ||
| 162 | |||
| 163 | /* mapping of widget types from UAPI IDs to kernel IDs */ | ||
| 164 | static const struct soc_tplg_map dapm_map[] = { | ||
| 165 | {SND_SOC_TPLG_DAPM_INPUT, snd_soc_dapm_input}, | ||
| 166 | {SND_SOC_TPLG_DAPM_OUTPUT, snd_soc_dapm_output}, | ||
| 167 | {SND_SOC_TPLG_DAPM_MUX, snd_soc_dapm_mux}, | ||
| 168 | {SND_SOC_TPLG_DAPM_MIXER, snd_soc_dapm_mixer}, | ||
| 169 | {SND_SOC_TPLG_DAPM_PGA, snd_soc_dapm_pga}, | ||
| 170 | {SND_SOC_TPLG_DAPM_OUT_DRV, snd_soc_dapm_out_drv}, | ||
| 171 | {SND_SOC_TPLG_DAPM_ADC, snd_soc_dapm_adc}, | ||
| 172 | {SND_SOC_TPLG_DAPM_DAC, snd_soc_dapm_dac}, | ||
| 173 | {SND_SOC_TPLG_DAPM_SWITCH, snd_soc_dapm_switch}, | ||
| 174 | {SND_SOC_TPLG_DAPM_PRE, snd_soc_dapm_pre}, | ||
| 175 | {SND_SOC_TPLG_DAPM_POST, snd_soc_dapm_post}, | ||
| 176 | {SND_SOC_TPLG_DAPM_AIF_IN, snd_soc_dapm_aif_in}, | ||
| 177 | {SND_SOC_TPLG_DAPM_AIF_OUT, snd_soc_dapm_aif_out}, | ||
| 178 | {SND_SOC_TPLG_DAPM_DAI_IN, snd_soc_dapm_dai_in}, | ||
| 179 | {SND_SOC_TPLG_DAPM_DAI_OUT, snd_soc_dapm_dai_out}, | ||
| 180 | {SND_SOC_TPLG_DAPM_DAI_LINK, snd_soc_dapm_dai_link}, | ||
| 181 | }; | ||
| 182 | |||
| 183 | static int tplc_chan_get_reg(struct soc_tplg *tplg, | ||
| 184 | struct snd_soc_tplg_channel *chan, int map) | ||
| 185 | { | ||
| 186 | int i; | ||
| 187 | |||
| 188 | for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) { | ||
| 189 | if (chan[i].id == map) | ||
| 190 | return chan[i].reg; | ||
| 191 | } | ||
| 192 | |||
| 193 | return -EINVAL; | ||
| 194 | } | ||
| 195 | |||
| 196 | static int tplc_chan_get_shift(struct soc_tplg *tplg, | ||
| 197 | struct snd_soc_tplg_channel *chan, int map) | ||
| 198 | { | ||
| 199 | int i; | ||
| 200 | |||
| 201 | for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) { | ||
| 202 | if (chan[i].id == map) | ||
| 203 | return chan[i].shift; | ||
| 204 | } | ||
| 205 | |||
| 206 | return -EINVAL; | ||
| 207 | } | ||
| 208 | |||
| 209 | static int get_widget_id(int tplg_type) | ||
| 210 | { | ||
| 211 | int i; | ||
| 212 | |||
| 213 | for (i = 0; i < ARRAY_SIZE(dapm_map); i++) { | ||
| 214 | if (tplg_type == dapm_map[i].uid) | ||
| 215 | return dapm_map[i].kid; | ||
| 216 | } | ||
| 217 | |||
| 218 | return -EINVAL; | ||
| 219 | } | ||
| 220 | |||
| 221 | static enum snd_soc_dobj_type get_dobj_mixer_type( | ||
| 222 | struct snd_soc_tplg_ctl_hdr *control_hdr) | ||
| 223 | { | ||
| 224 | if (control_hdr == NULL) | ||
| 225 | return SND_SOC_DOBJ_NONE; | ||
| 226 | |||
| 227 | switch (control_hdr->ops.info) { | ||
| 228 | case SND_SOC_TPLG_CTL_VOLSW: | ||
| 229 | case SND_SOC_TPLG_CTL_VOLSW_SX: | ||
| 230 | case SND_SOC_TPLG_CTL_VOLSW_XR_SX: | ||
| 231 | case SND_SOC_TPLG_CTL_RANGE: | ||
| 232 | case SND_SOC_TPLG_CTL_STROBE: | ||
| 233 | return SND_SOC_DOBJ_MIXER; | ||
| 234 | case SND_SOC_TPLG_CTL_ENUM: | ||
| 235 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | ||
| 236 | return SND_SOC_DOBJ_ENUM; | ||
| 237 | case SND_SOC_TPLG_CTL_BYTES: | ||
| 238 | return SND_SOC_DOBJ_BYTES; | ||
| 239 | default: | ||
| 240 | return SND_SOC_DOBJ_NONE; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | static enum snd_soc_dobj_type get_dobj_type(struct snd_soc_tplg_hdr *hdr, | ||
| 245 | struct snd_soc_tplg_ctl_hdr *control_hdr) | ||
| 246 | { | ||
| 247 | switch (hdr->type) { | ||
| 248 | case SND_SOC_TPLG_TYPE_MIXER: | ||
| 249 | return get_dobj_mixer_type(control_hdr); | ||
| 250 | case SND_SOC_TPLG_TYPE_DAPM_GRAPH: | ||
| 251 | case SND_SOC_TPLG_TYPE_MANIFEST: | ||
| 252 | return SND_SOC_DOBJ_NONE; | ||
| 253 | case SND_SOC_TPLG_TYPE_DAPM_WIDGET: | ||
| 254 | return SND_SOC_DOBJ_WIDGET; | ||
| 255 | case SND_SOC_TPLG_TYPE_DAI_LINK: | ||
| 256 | return SND_SOC_DOBJ_DAI_LINK; | ||
| 257 | case SND_SOC_TPLG_TYPE_PCM: | ||
| 258 | return SND_SOC_DOBJ_PCM; | ||
| 259 | case SND_SOC_TPLG_TYPE_CODEC_LINK: | ||
| 260 | return SND_SOC_DOBJ_CODEC_LINK; | ||
| 261 | default: | ||
| 262 | return SND_SOC_DOBJ_NONE; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | static inline void soc_bind_err(struct soc_tplg *tplg, | ||
| 267 | struct snd_soc_tplg_ctl_hdr *hdr, int index) | ||
| 268 | { | ||
| 269 | dev_err(tplg->dev, | ||
| 270 | "ASoC: invalid control type (g,p,i) %d:%d:%d index %d at 0x%lx\n", | ||
| 271 | hdr->ops.get, hdr->ops.put, hdr->ops.info, index, | ||
| 272 | soc_tplg_get_offset(tplg)); | ||
| 273 | } | ||
| 274 | |||
| 275 | static inline void soc_control_err(struct soc_tplg *tplg, | ||
| 276 | struct snd_soc_tplg_ctl_hdr *hdr, const char *name) | ||
| 277 | { | ||
| 278 | dev_err(tplg->dev, | ||
| 279 | "ASoC: no complete mixer IO handler for %s type (g,p,i) %d:%d:%d at 0x%lx\n", | ||
| 280 | name, hdr->ops.get, hdr->ops.put, hdr->ops.info, | ||
| 281 | soc_tplg_get_offset(tplg)); | ||
| 282 | } | ||
| 283 | |||
| 284 | /* pass vendor data to component driver for processing */ | ||
| 285 | static int soc_tplg_vendor_load_(struct soc_tplg *tplg, | ||
| 286 | struct snd_soc_tplg_hdr *hdr) | ||
| 287 | { | ||
| 288 | int ret = 0; | ||
| 289 | |||
| 290 | if (tplg->comp && tplg->ops && tplg->ops->vendor_load) | ||
| 291 | ret = tplg->ops->vendor_load(tplg->comp, hdr); | ||
| 292 | else { | ||
| 293 | dev_err(tplg->dev, "ASoC: no vendor load callback for ID %d\n", | ||
| 294 | hdr->vendor_type); | ||
| 295 | return -EINVAL; | ||
| 296 | } | ||
| 297 | |||
| 298 | if (ret < 0) | ||
| 299 | dev_err(tplg->dev, | ||
| 300 | "ASoC: vendor load failed at hdr offset %ld/0x%lx for type %d:%d\n", | ||
| 301 | soc_tplg_get_hdr_offset(tplg), | ||
| 302 | soc_tplg_get_hdr_offset(tplg), | ||
| 303 | hdr->type, hdr->vendor_type); | ||
| 304 | return ret; | ||
| 305 | } | ||
| 306 | |||
| 307 | /* pass vendor data to component driver for processing */ | ||
| 308 | static int soc_tplg_vendor_load(struct soc_tplg *tplg, | ||
| 309 | struct snd_soc_tplg_hdr *hdr) | ||
| 310 | { | ||
| 311 | if (tplg->pass != SOC_TPLG_PASS_VENDOR) | ||
| 312 | return 0; | ||
| 313 | |||
| 314 | return soc_tplg_vendor_load_(tplg, hdr); | ||
| 315 | } | ||
| 316 | |||
| 317 | /* optionally pass new dynamic widget to component driver. This is mainly for | ||
| 318 | * external widgets where we can assign private data/ops */ | ||
| 319 | static int soc_tplg_widget_load(struct soc_tplg *tplg, | ||
| 320 | struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w) | ||
| 321 | { | ||
| 322 | if (tplg->comp && tplg->ops && tplg->ops->widget_load) | ||
| 323 | return tplg->ops->widget_load(tplg->comp, w, tplg_w); | ||
| 324 | |||
| 325 | return 0; | ||
| 326 | } | ||
| 327 | |||
| 328 | /* pass dynamic FEs configurations to component driver */ | ||
| 329 | static int soc_tplg_pcm_dai_load(struct soc_tplg *tplg, | ||
| 330 | struct snd_soc_tplg_pcm_dai *pcm_dai, int num_pcm_dai) | ||
| 331 | { | ||
| 332 | if (tplg->comp && tplg->ops && tplg->ops->pcm_dai_load) | ||
| 333 | return tplg->ops->pcm_dai_load(tplg->comp, pcm_dai, num_pcm_dai); | ||
| 334 | |||
| 335 | return 0; | ||
| 336 | } | ||
| 337 | |||
| 338 | /* tell the component driver that all firmware has been loaded in this request */ | ||
| 339 | static void soc_tplg_complete(struct soc_tplg *tplg) | ||
| 340 | { | ||
| 341 | if (tplg->comp && tplg->ops && tplg->ops->complete) | ||
| 342 | tplg->ops->complete(tplg->comp); | ||
| 343 | } | ||
| 344 | |||
| 345 | /* add a dynamic kcontrol */ | ||
| 346 | static int soc_tplg_add_dcontrol(struct snd_card *card, struct device *dev, | ||
| 347 | const struct snd_kcontrol_new *control_new, const char *prefix, | ||
| 348 | void *data, struct snd_kcontrol **kcontrol) | ||
| 349 | { | ||
| 350 | int err; | ||
| 351 | |||
| 352 | *kcontrol = snd_soc_cnew(control_new, data, control_new->name, prefix); | ||
| 353 | if (*kcontrol == NULL) { | ||
| 354 | dev_err(dev, "ASoC: Failed to create new kcontrol %s\n", | ||
| 355 | control_new->name); | ||
| 356 | return -ENOMEM; | ||
| 357 | } | ||
| 358 | |||
| 359 | err = snd_ctl_add(card, *kcontrol); | ||
| 360 | if (err < 0) { | ||
| 361 | dev_err(dev, "ASoC: Failed to add %s: %d\n", | ||
| 362 | control_new->name, err); | ||
| 363 | return err; | ||
| 364 | } | ||
| 365 | |||
| 366 | return 0; | ||
| 367 | } | ||
| 368 | |||
| 369 | /* add a dynamic kcontrol for component driver */ | ||
| 370 | static int soc_tplg_add_kcontrol(struct soc_tplg *tplg, | ||
| 371 | struct snd_kcontrol_new *k, struct snd_kcontrol **kcontrol) | ||
| 372 | { | ||
| 373 | struct snd_soc_component *comp = tplg->comp; | ||
| 374 | |||
| 375 | return soc_tplg_add_dcontrol(comp->card->snd_card, | ||
| 376 | comp->dev, k, NULL, comp, kcontrol); | ||
| 377 | } | ||
| 378 | |||
| 379 | /* remove a mixer kcontrol */ | ||
| 380 | static void remove_mixer(struct snd_soc_component *comp, | ||
| 381 | struct snd_soc_dobj *dobj, int pass) | ||
| 382 | { | ||
| 383 | struct snd_card *card = comp->card->snd_card; | ||
| 384 | struct soc_mixer_control *sm = | ||
| 385 | container_of(dobj, struct soc_mixer_control, dobj); | ||
| 386 | const unsigned int *p = NULL; | ||
| 387 | |||
| 388 | if (pass != SOC_TPLG_PASS_MIXER) | ||
| 389 | return; | ||
| 390 | |||
| 391 | if (dobj->ops && dobj->ops->control_unload) | ||
| 392 | dobj->ops->control_unload(comp, dobj); | ||
| 393 | |||
| 394 | if (sm->dobj.control.kcontrol->tlv.p) | ||
| 395 | p = sm->dobj.control.kcontrol->tlv.p; | ||
| 396 | snd_ctl_remove(card, sm->dobj.control.kcontrol); | ||
| 397 | list_del(&sm->dobj.list); | ||
| 398 | kfree(sm); | ||
| 399 | kfree(p); | ||
| 400 | } | ||
| 401 | |||
| 402 | /* remove an enum kcontrol */ | ||
| 403 | static void remove_enum(struct snd_soc_component *comp, | ||
| 404 | struct snd_soc_dobj *dobj, int pass) | ||
| 405 | { | ||
| 406 | struct snd_card *card = comp->card->snd_card; | ||
| 407 | struct soc_enum *se = container_of(dobj, struct soc_enum, dobj); | ||
| 408 | int i; | ||
| 409 | |||
| 410 | if (pass != SOC_TPLG_PASS_MIXER) | ||
| 411 | return; | ||
| 412 | |||
| 413 | if (dobj->ops && dobj->ops->control_unload) | ||
| 414 | dobj->ops->control_unload(comp, dobj); | ||
| 415 | |||
| 416 | snd_ctl_remove(card, se->dobj.control.kcontrol); | ||
| 417 | list_del(&se->dobj.list); | ||
| 418 | |||
| 419 | kfree(se->dobj.control.dvalues); | ||
| 420 | for (i = 0; i < se->items; i++) | ||
| 421 | kfree(se->dobj.control.dtexts[i]); | ||
| 422 | kfree(se); | ||
| 423 | } | ||
| 424 | |||
| 425 | /* remove a byte kcontrol */ | ||
| 426 | static void remove_bytes(struct snd_soc_component *comp, | ||
| 427 | struct snd_soc_dobj *dobj, int pass) | ||
| 428 | { | ||
| 429 | struct snd_card *card = comp->card->snd_card; | ||
| 430 | struct soc_bytes_ext *sb = | ||
| 431 | container_of(dobj, struct soc_bytes_ext, dobj); | ||
| 432 | |||
| 433 | if (pass != SOC_TPLG_PASS_MIXER) | ||
| 434 | return; | ||
| 435 | |||
| 436 | if (dobj->ops && dobj->ops->control_unload) | ||
| 437 | dobj->ops->control_unload(comp, dobj); | ||
| 438 | |||
| 439 | snd_ctl_remove(card, sb->dobj.control.kcontrol); | ||
| 440 | list_del(&sb->dobj.list); | ||
| 441 | kfree(sb); | ||
| 442 | } | ||
| 443 | |||
| 444 | /* remove a widget and it's kcontrols - routes must be removed first */ | ||
| 445 | static void remove_widget(struct snd_soc_component *comp, | ||
| 446 | struct snd_soc_dobj *dobj, int pass) | ||
| 447 | { | ||
| 448 | struct snd_card *card = comp->card->snd_card; | ||
| 449 | struct snd_soc_dapm_widget *w = | ||
| 450 | container_of(dobj, struct snd_soc_dapm_widget, dobj); | ||
| 451 | int i; | ||
| 452 | |||
| 453 | if (pass != SOC_TPLG_PASS_WIDGET) | ||
| 454 | return; | ||
| 455 | |||
| 456 | if (dobj->ops && dobj->ops->widget_unload) | ||
| 457 | dobj->ops->widget_unload(comp, dobj); | ||
| 458 | |||
| 459 | /* | ||
| 460 | * Dynamic Widgets either have 1 enum kcontrol or 1..N mixers. | ||
| 461 | * The enum may either have an array of values or strings. | ||
| 462 | */ | ||
| 463 | if (dobj->widget.kcontrol_enum) { | ||
| 464 | /* enumerated widget mixer */ | ||
| 465 | struct soc_enum *se = | ||
| 466 | (struct soc_enum *)w->kcontrols[0]->private_value; | ||
| 467 | |||
| 468 | snd_ctl_remove(card, w->kcontrols[0]); | ||
| 469 | |||
| 470 | kfree(se->dobj.control.dvalues); | ||
| 471 | for (i = 0; i < se->items; i++) | ||
| 472 | kfree(se->dobj.control.dtexts[i]); | ||
| 473 | |||
| 474 | kfree(se); | ||
| 475 | kfree(w->kcontrol_news); | ||
| 476 | } else { | ||
| 477 | /* non enumerated widget mixer */ | ||
| 478 | for (i = 0; i < w->num_kcontrols; i++) { | ||
| 479 | struct snd_kcontrol *kcontrol = w->kcontrols[i]; | ||
| 480 | struct soc_mixer_control *sm = | ||
| 481 | (struct soc_mixer_control *) kcontrol->private_value; | ||
| 482 | |||
| 483 | kfree(w->kcontrols[i]->tlv.p); | ||
| 484 | |||
| 485 | snd_ctl_remove(card, w->kcontrols[i]); | ||
| 486 | kfree(sm); | ||
| 487 | } | ||
| 488 | kfree(w->kcontrol_news); | ||
| 489 | } | ||
| 490 | /* widget w is freed by soc-dapm.c */ | ||
| 491 | } | ||
| 492 | |||
| 493 | /* remove PCM DAI configurations */ | ||
| 494 | static void remove_pcm_dai(struct snd_soc_component *comp, | ||
| 495 | struct snd_soc_dobj *dobj, int pass) | ||
| 496 | { | ||
| 497 | if (pass != SOC_TPLG_PASS_PCM_DAI) | ||
| 498 | return; | ||
| 499 | |||
| 500 | if (dobj->ops && dobj->ops->pcm_dai_unload) | ||
| 501 | dobj->ops->pcm_dai_unload(comp, dobj); | ||
| 502 | |||
| 503 | list_del(&dobj->list); | ||
| 504 | kfree(dobj); | ||
| 505 | } | ||
| 506 | |||
| 507 | /* bind a kcontrol to it's IO handlers */ | ||
| 508 | static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, | ||
| 509 | struct snd_kcontrol_new *k, | ||
| 510 | const struct snd_soc_tplg_kcontrol_ops *ops, int num_ops, | ||
| 511 | const struct snd_soc_tplg_kcontrol_ops *bops, int num_bops) | ||
| 512 | { | ||
| 513 | int i; | ||
| 514 | |||
| 515 | /* try and map standard kcontrols handler first */ | ||
| 516 | for (i = 0; i < num_ops; i++) { | ||
| 517 | |||
| 518 | if (ops[i].id == hdr->ops.put) | ||
| 519 | k->put = ops[i].put; | ||
| 520 | if (ops[i].id == hdr->ops.get) | ||
| 521 | k->get = ops[i].get; | ||
| 522 | if (ops[i].id == hdr->ops.info) | ||
| 523 | k->info = ops[i].info; | ||
| 524 | } | ||
| 525 | |||
| 526 | /* standard handlers found ? */ | ||
| 527 | if (k->put && k->get && k->info) | ||
| 528 | return 0; | ||
| 529 | |||
| 530 | /* none found so try bespoke handlers */ | ||
| 531 | for (i = 0; i < num_bops; i++) { | ||
| 532 | |||
| 533 | if (k->put == NULL && bops[i].id == hdr->ops.put) | ||
| 534 | k->put = bops[i].put; | ||
| 535 | if (k->get == NULL && bops[i].id == hdr->ops.get) | ||
| 536 | k->get = bops[i].get; | ||
| 537 | if (k->info == NULL && ops[i].id == hdr->ops.info) | ||
| 538 | k->info = bops[i].info; | ||
| 539 | } | ||
| 540 | |||
| 541 | /* bespoke handlers found ? */ | ||
| 542 | if (k->put && k->get && k->info) | ||
| 543 | return 0; | ||
| 544 | |||
| 545 | /* nothing to bind */ | ||
| 546 | return -EINVAL; | ||
| 547 | } | ||
| 548 | |||
| 549 | /* bind a widgets to it's evnt handlers */ | ||
| 550 | int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w, | ||
| 551 | const struct snd_soc_tplg_widget_events *events, | ||
| 552 | int num_events, u16 event_type) | ||
| 553 | { | ||
| 554 | int i; | ||
| 555 | |||
| 556 | w->event = NULL; | ||
| 557 | |||
| 558 | for (i = 0; i < num_events; i++) { | ||
| 559 | if (event_type == events[i].type) { | ||
| 560 | |||
| 561 | /* found - so assign event */ | ||
| 562 | w->event = events[i].event_handler; | ||
| 563 | return 0; | ||
| 564 | } | ||
| 565 | } | ||
| 566 | |||
| 567 | /* not found */ | ||
| 568 | return -EINVAL; | ||
| 569 | } | ||
| 570 | EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_bind_event); | ||
| 571 | |||
| 572 | /* optionally pass new dynamic kcontrol to component driver. */ | ||
| 573 | static int soc_tplg_init_kcontrol(struct soc_tplg *tplg, | ||
| 574 | struct snd_kcontrol_new *k, struct snd_soc_tplg_ctl_hdr *hdr) | ||
| 575 | { | ||
| 576 | if (tplg->comp && tplg->ops && tplg->ops->control_load) | ||
| 577 | return tplg->ops->control_load(tplg->comp, k, hdr); | ||
| 578 | |||
| 579 | return 0; | ||
| 580 | } | ||
| 581 | |||
| 582 | static int soc_tplg_create_tlv(struct soc_tplg *tplg, | ||
| 583 | struct snd_kcontrol_new *kc, u32 tlv_size) | ||
| 584 | { | ||
| 585 | struct snd_soc_tplg_ctl_tlv *tplg_tlv; | ||
| 586 | struct snd_ctl_tlv *tlv; | ||
| 587 | |||
| 588 | if (tlv_size == 0) | ||
| 589 | return 0; | ||
| 590 | |||
| 591 | tplg_tlv = (struct snd_soc_tplg_ctl_tlv *) tplg->pos; | ||
| 592 | tplg->pos += tlv_size; | ||
| 593 | |||
| 594 | tlv = kzalloc(sizeof(*tlv) + tlv_size, GFP_KERNEL); | ||
| 595 | if (tlv == NULL) | ||
| 596 | return -ENOMEM; | ||
| 597 | |||
| 598 | dev_dbg(tplg->dev, " created TLV type %d size %d bytes\n", | ||
| 599 | tplg_tlv->numid, tplg_tlv->size); | ||
| 600 | |||
| 601 | tlv->numid = tplg_tlv->numid; | ||
| 602 | tlv->length = tplg_tlv->size; | ||
| 603 | memcpy(tlv->tlv, tplg_tlv + 1, tplg_tlv->size); | ||
| 604 | kc->tlv.p = (void *)tlv; | ||
| 605 | |||
| 606 | return 0; | ||
| 607 | } | ||
| 608 | |||
| 609 | static inline void soc_tplg_free_tlv(struct soc_tplg *tplg, | ||
| 610 | struct snd_kcontrol_new *kc) | ||
| 611 | { | ||
| 612 | kfree(kc->tlv.p); | ||
| 613 | } | ||
| 614 | |||
| 615 | static int soc_tplg_dbytes_create(struct soc_tplg *tplg, unsigned int count, | ||
| 616 | size_t size) | ||
| 617 | { | ||
| 618 | struct snd_soc_tplg_bytes_control *be; | ||
| 619 | struct soc_bytes_ext *sbe; | ||
| 620 | struct snd_kcontrol_new kc; | ||
| 621 | int i, err; | ||
| 622 | |||
| 623 | if (soc_tplg_check_elem_count(tplg, | ||
| 624 | sizeof(struct snd_soc_tplg_bytes_control), count, | ||
| 625 | size, "mixer bytes")) { | ||
| 626 | dev_err(tplg->dev, "ASoC: Invalid count %d for byte control\n", | ||
| 627 | count); | ||
| 628 | return -EINVAL; | ||
| 629 | } | ||
| 630 | |||
| 631 | for (i = 0; i < count; i++) { | ||
| 632 | be = (struct snd_soc_tplg_bytes_control *)tplg->pos; | ||
| 633 | |||
| 634 | /* validate kcontrol */ | ||
| 635 | if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 636 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 637 | return -EINVAL; | ||
| 638 | |||
| 639 | sbe = kzalloc(sizeof(*sbe), GFP_KERNEL); | ||
| 640 | if (sbe == NULL) | ||
| 641 | return -ENOMEM; | ||
| 642 | |||
| 643 | tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + | ||
| 644 | be->priv.size); | ||
| 645 | |||
| 646 | dev_dbg(tplg->dev, | ||
| 647 | "ASoC: adding bytes kcontrol %s with access 0x%x\n", | ||
| 648 | be->hdr.name, be->hdr.access); | ||
| 649 | |||
| 650 | memset(&kc, 0, sizeof(kc)); | ||
| 651 | kc.name = be->hdr.name; | ||
| 652 | kc.private_value = (long)sbe; | ||
| 653 | kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
| 654 | kc.access = be->hdr.access; | ||
| 655 | |||
| 656 | sbe->max = be->max; | ||
| 657 | sbe->dobj.type = SND_SOC_DOBJ_BYTES; | ||
| 658 | sbe->dobj.ops = tplg->ops; | ||
| 659 | INIT_LIST_HEAD(&sbe->dobj.list); | ||
| 660 | |||
| 661 | /* map io handlers */ | ||
| 662 | err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc, io_ops, | ||
| 663 | ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); | ||
| 664 | if (err) { | ||
| 665 | soc_control_err(tplg, &be->hdr, be->hdr.name); | ||
| 666 | kfree(sbe); | ||
| 667 | continue; | ||
| 668 | } | ||
| 669 | |||
| 670 | /* pass control to driver for optional further init */ | ||
| 671 | err = soc_tplg_init_kcontrol(tplg, &kc, | ||
| 672 | (struct snd_soc_tplg_ctl_hdr *)be); | ||
| 673 | if (err < 0) { | ||
| 674 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | ||
| 675 | be->hdr.name); | ||
| 676 | kfree(sbe); | ||
| 677 | continue; | ||
| 678 | } | ||
| 679 | |||
| 680 | /* register control here */ | ||
| 681 | err = soc_tplg_add_kcontrol(tplg, &kc, | ||
| 682 | &sbe->dobj.control.kcontrol); | ||
| 683 | if (err < 0) { | ||
| 684 | dev_err(tplg->dev, "ASoC: failed to add %s\n", | ||
| 685 | be->hdr.name); | ||
| 686 | kfree(sbe); | ||
| 687 | continue; | ||
| 688 | } | ||
| 689 | |||
| 690 | list_add(&sbe->dobj.list, &tplg->comp->dobj_list); | ||
| 691 | } | ||
| 692 | return 0; | ||
| 693 | |||
| 694 | } | ||
| 695 | |||
| 696 | static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count, | ||
| 697 | size_t size) | ||
| 698 | { | ||
| 699 | struct snd_soc_tplg_mixer_control *mc; | ||
| 700 | struct soc_mixer_control *sm; | ||
| 701 | struct snd_kcontrol_new kc; | ||
| 702 | int i, err; | ||
| 703 | |||
| 704 | if (soc_tplg_check_elem_count(tplg, | ||
| 705 | sizeof(struct snd_soc_tplg_mixer_control), | ||
| 706 | count, size, "mixers")) { | ||
| 707 | |||
| 708 | dev_err(tplg->dev, "ASoC: invalid count %d for controls\n", | ||
| 709 | count); | ||
| 710 | return -EINVAL; | ||
| 711 | } | ||
| 712 | |||
| 713 | for (i = 0; i < count; i++) { | ||
| 714 | mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; | ||
| 715 | |||
| 716 | /* validate kcontrol */ | ||
| 717 | if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 718 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 719 | return -EINVAL; | ||
| 720 | |||
| 721 | sm = kzalloc(sizeof(*sm), GFP_KERNEL); | ||
| 722 | if (sm == NULL) | ||
| 723 | return -ENOMEM; | ||
| 724 | tplg->pos += (sizeof(struct snd_soc_tplg_mixer_control) + | ||
| 725 | mc->priv.size); | ||
| 726 | |||
| 727 | dev_dbg(tplg->dev, | ||
| 728 | "ASoC: adding mixer kcontrol %s with access 0x%x\n", | ||
| 729 | mc->hdr.name, mc->hdr.access); | ||
| 730 | |||
| 731 | memset(&kc, 0, sizeof(kc)); | ||
| 732 | kc.name = mc->hdr.name; | ||
| 733 | kc.private_value = (long)sm; | ||
| 734 | kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
| 735 | kc.access = mc->hdr.access; | ||
| 736 | |||
| 737 | /* we only support FL/FR channel mapping atm */ | ||
| 738 | sm->reg = tplc_chan_get_reg(tplg, mc->channel, | ||
| 739 | SNDRV_CHMAP_FL); | ||
| 740 | sm->rreg = tplc_chan_get_reg(tplg, mc->channel, | ||
| 741 | SNDRV_CHMAP_FR); | ||
| 742 | sm->shift = tplc_chan_get_shift(tplg, mc->channel, | ||
| 743 | SNDRV_CHMAP_FL); | ||
| 744 | sm->rshift = tplc_chan_get_shift(tplg, mc->channel, | ||
| 745 | SNDRV_CHMAP_FR); | ||
| 746 | |||
| 747 | sm->max = mc->max; | ||
| 748 | sm->min = mc->min; | ||
| 749 | sm->invert = mc->invert; | ||
| 750 | sm->platform_max = mc->platform_max; | ||
| 751 | sm->dobj.index = tplg->index; | ||
| 752 | sm->dobj.ops = tplg->ops; | ||
| 753 | sm->dobj.type = SND_SOC_DOBJ_MIXER; | ||
| 754 | INIT_LIST_HEAD(&sm->dobj.list); | ||
| 755 | |||
| 756 | /* map io handlers */ | ||
| 757 | err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc, io_ops, | ||
| 758 | ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); | ||
| 759 | if (err) { | ||
| 760 | soc_control_err(tplg, &mc->hdr, mc->hdr.name); | ||
| 761 | kfree(sm); | ||
| 762 | continue; | ||
| 763 | } | ||
| 764 | |||
| 765 | /* pass control to driver for optional further init */ | ||
| 766 | err = soc_tplg_init_kcontrol(tplg, &kc, | ||
| 767 | (struct snd_soc_tplg_ctl_hdr *) mc); | ||
| 768 | if (err < 0) { | ||
| 769 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | ||
| 770 | mc->hdr.name); | ||
| 771 | kfree(sm); | ||
| 772 | continue; | ||
| 773 | } | ||
| 774 | |||
| 775 | /* create any TLV data */ | ||
| 776 | soc_tplg_create_tlv(tplg, &kc, mc->hdr.tlv_size); | ||
| 777 | |||
| 778 | /* register control here */ | ||
| 779 | err = soc_tplg_add_kcontrol(tplg, &kc, | ||
| 780 | &sm->dobj.control.kcontrol); | ||
| 781 | if (err < 0) { | ||
| 782 | dev_err(tplg->dev, "ASoC: failed to add %s\n", | ||
| 783 | mc->hdr.name); | ||
| 784 | soc_tplg_free_tlv(tplg, &kc); | ||
| 785 | kfree(sm); | ||
| 786 | continue; | ||
| 787 | } | ||
| 788 | |||
| 789 | list_add(&sm->dobj.list, &tplg->comp->dobj_list); | ||
| 790 | } | ||
| 791 | |||
| 792 | return 0; | ||
| 793 | } | ||
| 794 | |||
| 795 | static int soc_tplg_denum_create_texts(struct soc_enum *se, | ||
| 796 | struct snd_soc_tplg_enum_control *ec) | ||
| 797 | { | ||
| 798 | int i, ret; | ||
| 799 | |||
| 800 | se->dobj.control.dtexts = | ||
| 801 | kzalloc(sizeof(char *) * ec->items, GFP_KERNEL); | ||
| 802 | if (se->dobj.control.dtexts == NULL) | ||
| 803 | return -ENOMEM; | ||
| 804 | |||
| 805 | for (i = 0; i < ec->items; i++) { | ||
| 806 | |||
| 807 | if (strnlen(ec->texts[i], SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 808 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) { | ||
| 809 | ret = -EINVAL; | ||
| 810 | goto err; | ||
| 811 | } | ||
| 812 | |||
| 813 | se->dobj.control.dtexts[i] = kstrdup(ec->texts[i], GFP_KERNEL); | ||
| 814 | if (!se->dobj.control.dtexts[i]) { | ||
| 815 | ret = -ENOMEM; | ||
| 816 | goto err; | ||
| 817 | } | ||
| 818 | } | ||
| 819 | |||
| 820 | return 0; | ||
| 821 | |||
| 822 | err: | ||
| 823 | for (--i; i >= 0; i--) | ||
| 824 | kfree(se->dobj.control.dtexts[i]); | ||
| 825 | kfree(se->dobj.control.dtexts); | ||
| 826 | return ret; | ||
| 827 | } | ||
| 828 | |||
| 829 | static int soc_tplg_denum_create_values(struct soc_enum *se, | ||
| 830 | struct snd_soc_tplg_enum_control *ec) | ||
| 831 | { | ||
| 832 | if (ec->items > sizeof(*ec->values)) | ||
| 833 | return -EINVAL; | ||
| 834 | |||
| 835 | se->dobj.control.dvalues = | ||
| 836 | kmalloc(ec->items * sizeof(u32), GFP_KERNEL); | ||
| 837 | if (!se->dobj.control.dvalues) | ||
| 838 | return -ENOMEM; | ||
| 839 | |||
| 840 | memcpy(se->dobj.control.dvalues, ec->values, ec->items * sizeof(u32)); | ||
| 841 | return 0; | ||
| 842 | } | ||
| 843 | |||
| 844 | static int soc_tplg_denum_create(struct soc_tplg *tplg, unsigned int count, | ||
| 845 | size_t size) | ||
| 846 | { | ||
| 847 | struct snd_soc_tplg_enum_control *ec; | ||
| 848 | struct soc_enum *se; | ||
| 849 | struct snd_kcontrol_new kc; | ||
| 850 | int i, ret, err; | ||
| 851 | |||
| 852 | if (soc_tplg_check_elem_count(tplg, | ||
| 853 | sizeof(struct snd_soc_tplg_enum_control), | ||
| 854 | count, size, "enums")) { | ||
| 855 | |||
| 856 | dev_err(tplg->dev, "ASoC: invalid count %d for enum controls\n", | ||
| 857 | count); | ||
| 858 | return -EINVAL; | ||
| 859 | } | ||
| 860 | |||
| 861 | for (i = 0; i < count; i++) { | ||
| 862 | ec = (struct snd_soc_tplg_enum_control *)tplg->pos; | ||
| 863 | tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + | ||
| 864 | ec->priv.size); | ||
| 865 | |||
| 866 | /* validate kcontrol */ | ||
| 867 | if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 868 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 869 | return -EINVAL; | ||
| 870 | |||
| 871 | se = kzalloc((sizeof(*se)), GFP_KERNEL); | ||
| 872 | if (se == NULL) | ||
| 873 | return -ENOMEM; | ||
| 874 | |||
| 875 | dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", | ||
| 876 | ec->hdr.name, ec->items); | ||
| 877 | |||
| 878 | memset(&kc, 0, sizeof(kc)); | ||
| 879 | kc.name = ec->hdr.name; | ||
| 880 | kc.private_value = (long)se; | ||
| 881 | kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
| 882 | kc.access = ec->hdr.access; | ||
| 883 | |||
| 884 | se->reg = tplc_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); | ||
| 885 | se->shift_l = tplc_chan_get_shift(tplg, ec->channel, | ||
| 886 | SNDRV_CHMAP_FL); | ||
| 887 | se->shift_r = tplc_chan_get_shift(tplg, ec->channel, | ||
| 888 | SNDRV_CHMAP_FL); | ||
| 889 | |||
| 890 | se->items = ec->items; | ||
| 891 | se->mask = ec->mask; | ||
| 892 | se->dobj.index = tplg->index; | ||
| 893 | se->dobj.type = SND_SOC_DOBJ_ENUM; | ||
| 894 | se->dobj.ops = tplg->ops; | ||
| 895 | INIT_LIST_HEAD(&se->dobj.list); | ||
| 896 | |||
| 897 | switch (ec->hdr.ops.info) { | ||
| 898 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | ||
| 899 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | ||
| 900 | err = soc_tplg_denum_create_values(se, ec); | ||
| 901 | if (err < 0) { | ||
| 902 | dev_err(tplg->dev, | ||
| 903 | "ASoC: could not create values for %s\n", | ||
| 904 | ec->hdr.name); | ||
| 905 | kfree(se); | ||
| 906 | continue; | ||
| 907 | } | ||
| 908 | /* fall through and create texts */ | ||
| 909 | case SND_SOC_TPLG_CTL_ENUM: | ||
| 910 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | ||
| 911 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | ||
| 912 | err = soc_tplg_denum_create_texts(se, ec); | ||
| 913 | if (err < 0) { | ||
| 914 | dev_err(tplg->dev, | ||
| 915 | "ASoC: could not create texts for %s\n", | ||
| 916 | ec->hdr.name); | ||
| 917 | kfree(se); | ||
| 918 | continue; | ||
| 919 | } | ||
| 920 | break; | ||
| 921 | default: | ||
| 922 | dev_err(tplg->dev, | ||
| 923 | "ASoC: invalid enum control type %d for %s\n", | ||
| 924 | ec->hdr.ops.info, ec->hdr.name); | ||
| 925 | kfree(se); | ||
| 926 | continue; | ||
| 927 | } | ||
| 928 | |||
| 929 | /* map io handlers */ | ||
| 930 | err = soc_tplg_kcontrol_bind_io(&ec->hdr, &kc, io_ops, | ||
| 931 | ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); | ||
| 932 | if (err) { | ||
| 933 | soc_control_err(tplg, &ec->hdr, ec->hdr.name); | ||
| 934 | kfree(se); | ||
| 935 | continue; | ||
| 936 | } | ||
| 937 | |||
| 938 | /* pass control to driver for optional further init */ | ||
| 939 | err = soc_tplg_init_kcontrol(tplg, &kc, | ||
| 940 | (struct snd_soc_tplg_ctl_hdr *) ec); | ||
| 941 | if (err < 0) { | ||
| 942 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | ||
| 943 | ec->hdr.name); | ||
| 944 | kfree(se); | ||
| 945 | continue; | ||
| 946 | } | ||
| 947 | |||
| 948 | /* register control here */ | ||
| 949 | ret = soc_tplg_add_kcontrol(tplg, | ||
| 950 | &kc, &se->dobj.control.kcontrol); | ||
| 951 | if (ret < 0) { | ||
| 952 | dev_err(tplg->dev, "ASoC: could not add kcontrol %s\n", | ||
| 953 | ec->hdr.name); | ||
| 954 | kfree(se); | ||
| 955 | continue; | ||
| 956 | } | ||
| 957 | |||
| 958 | list_add(&se->dobj.list, &tplg->comp->dobj_list); | ||
| 959 | } | ||
| 960 | |||
| 961 | return 0; | ||
| 962 | } | ||
| 963 | |||
| 964 | static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg, | ||
| 965 | struct snd_soc_tplg_hdr *hdr) | ||
| 966 | { | ||
| 967 | struct snd_soc_tplg_ctl_hdr *control_hdr; | ||
| 968 | int i; | ||
| 969 | |||
| 970 | if (tplg->pass != SOC_TPLG_PASS_MIXER) { | ||
| 971 | tplg->pos += hdr->size + hdr->payload_size; | ||
| 972 | return 0; | ||
| 973 | } | ||
| 974 | |||
| 975 | dev_dbg(tplg->dev, "ASoC: adding %d kcontrols at 0x%lx\n", hdr->count, | ||
| 976 | soc_tplg_get_offset(tplg)); | ||
| 977 | |||
| 978 | for (i = 0; i < hdr->count; i++) { | ||
| 979 | |||
| 980 | control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos; | ||
| 981 | |||
| 982 | switch (control_hdr->ops.info) { | ||
| 983 | case SND_SOC_TPLG_CTL_VOLSW: | ||
| 984 | case SND_SOC_TPLG_CTL_STROBE: | ||
| 985 | case SND_SOC_TPLG_CTL_VOLSW_SX: | ||
| 986 | case SND_SOC_TPLG_CTL_VOLSW_XR_SX: | ||
| 987 | case SND_SOC_TPLG_CTL_RANGE: | ||
| 988 | case SND_SOC_TPLG_DAPM_CTL_VOLSW: | ||
| 989 | case SND_SOC_TPLG_DAPM_CTL_PIN: | ||
| 990 | soc_tplg_dmixer_create(tplg, 1, hdr->payload_size); | ||
| 991 | break; | ||
| 992 | case SND_SOC_TPLG_CTL_ENUM: | ||
| 993 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | ||
| 994 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | ||
| 995 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | ||
| 996 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | ||
| 997 | soc_tplg_denum_create(tplg, 1, hdr->payload_size); | ||
| 998 | break; | ||
| 999 | case SND_SOC_TPLG_CTL_BYTES: | ||
| 1000 | soc_tplg_dbytes_create(tplg, 1, hdr->payload_size); | ||
| 1001 | break; | ||
| 1002 | default: | ||
| 1003 | soc_bind_err(tplg, control_hdr, i); | ||
| 1004 | return -EINVAL; | ||
| 1005 | } | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | return 0; | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, | ||
| 1012 | struct snd_soc_tplg_hdr *hdr) | ||
| 1013 | { | ||
| 1014 | struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; | ||
| 1015 | struct snd_soc_dapm_route route; | ||
| 1016 | struct snd_soc_tplg_dapm_graph_elem *elem; | ||
| 1017 | int count = hdr->count, i; | ||
| 1018 | |||
| 1019 | if (tplg->pass != SOC_TPLG_PASS_GRAPH) { | ||
| 1020 | tplg->pos += hdr->size + hdr->payload_size; | ||
| 1021 | return 0; | ||
| 1022 | } | ||
| 1023 | |||
| 1024 | if (soc_tplg_check_elem_count(tplg, | ||
| 1025 | sizeof(struct snd_soc_tplg_dapm_graph_elem), | ||
| 1026 | count, hdr->payload_size, "graph")) { | ||
| 1027 | |||
| 1028 | dev_err(tplg->dev, "ASoC: invalid count %d for DAPM routes\n", | ||
| 1029 | count); | ||
| 1030 | return -EINVAL; | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes\n", count); | ||
| 1034 | |||
| 1035 | for (i = 0; i < count; i++) { | ||
| 1036 | elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos; | ||
| 1037 | tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem); | ||
| 1038 | |||
| 1039 | /* validate routes */ | ||
| 1040 | if (strnlen(elem->source, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1041 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1042 | return -EINVAL; | ||
| 1043 | if (strnlen(elem->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1044 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1045 | return -EINVAL; | ||
| 1046 | if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1047 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1048 | return -EINVAL; | ||
| 1049 | |||
| 1050 | route.source = elem->source; | ||
| 1051 | route.sink = elem->sink; | ||
| 1052 | route.connected = NULL; /* set to NULL atm for tplg users */ | ||
| 1053 | if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) | ||
| 1054 | route.control = NULL; | ||
| 1055 | else | ||
| 1056 | route.control = elem->control; | ||
| 1057 | |||
| 1058 | /* add route, but keep going if some fail */ | ||
| 1059 | snd_soc_dapm_add_routes(dapm, &route, 1); | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | return 0; | ||
| 1063 | } | ||
| 1064 | |||
| 1065 | static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create( | ||
| 1066 | struct soc_tplg *tplg, int num_kcontrols) | ||
| 1067 | { | ||
| 1068 | struct snd_kcontrol_new *kc; | ||
| 1069 | struct soc_mixer_control *sm; | ||
| 1070 | struct snd_soc_tplg_mixer_control *mc; | ||
| 1071 | int i, err; | ||
| 1072 | |||
| 1073 | kc = kzalloc(sizeof(*kc) * num_kcontrols, GFP_KERNEL); | ||
| 1074 | if (kc == NULL) | ||
| 1075 | return NULL; | ||
| 1076 | |||
| 1077 | for (i = 0; i < num_kcontrols; i++) { | ||
| 1078 | mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; | ||
| 1079 | sm = kzalloc(sizeof(*sm), GFP_KERNEL); | ||
| 1080 | if (sm == NULL) | ||
| 1081 | goto err; | ||
| 1082 | |||
| 1083 | tplg->pos += (sizeof(struct snd_soc_tplg_mixer_control) + | ||
| 1084 | mc->priv.size); | ||
| 1085 | |||
| 1086 | /* validate kcontrol */ | ||
| 1087 | if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1088 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1089 | goto err_str; | ||
| 1090 | |||
| 1091 | dev_dbg(tplg->dev, " adding DAPM widget mixer control %s at %d\n", | ||
| 1092 | mc->hdr.name, i); | ||
| 1093 | |||
| 1094 | kc[i].name = mc->hdr.name; | ||
| 1095 | kc[i].private_value = (long)sm; | ||
| 1096 | kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
| 1097 | kc[i].access = mc->hdr.access; | ||
| 1098 | |||
| 1099 | /* we only support FL/FR channel mapping atm */ | ||
| 1100 | sm->reg = tplc_chan_get_reg(tplg, mc->channel, | ||
| 1101 | SNDRV_CHMAP_FL); | ||
| 1102 | sm->rreg = tplc_chan_get_reg(tplg, mc->channel, | ||
| 1103 | SNDRV_CHMAP_FR); | ||
| 1104 | sm->shift = tplc_chan_get_shift(tplg, mc->channel, | ||
| 1105 | SNDRV_CHMAP_FL); | ||
| 1106 | sm->rshift = tplc_chan_get_shift(tplg, mc->channel, | ||
| 1107 | SNDRV_CHMAP_FR); | ||
| 1108 | |||
| 1109 | sm->max = mc->max; | ||
| 1110 | sm->min = mc->min; | ||
| 1111 | sm->invert = mc->invert; | ||
| 1112 | sm->platform_max = mc->platform_max; | ||
| 1113 | sm->dobj.index = tplg->index; | ||
| 1114 | INIT_LIST_HEAD(&sm->dobj.list); | ||
| 1115 | |||
| 1116 | /* map io handlers */ | ||
| 1117 | err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc[i], io_ops, | ||
| 1118 | ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); | ||
| 1119 | if (err) { | ||
| 1120 | soc_control_err(tplg, &mc->hdr, mc->hdr.name); | ||
| 1121 | kfree(sm); | ||
| 1122 | continue; | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | /* pass control to driver for optional further init */ | ||
| 1126 | err = soc_tplg_init_kcontrol(tplg, &kc[i], | ||
| 1127 | (struct snd_soc_tplg_ctl_hdr *)mc); | ||
| 1128 | if (err < 0) { | ||
| 1129 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | ||
| 1130 | mc->hdr.name); | ||
| 1131 | kfree(sm); | ||
| 1132 | continue; | ||
| 1133 | } | ||
| 1134 | } | ||
| 1135 | return kc; | ||
| 1136 | |||
| 1137 | err_str: | ||
| 1138 | kfree(sm); | ||
| 1139 | err: | ||
| 1140 | for (--i; i >= 0; i--) | ||
| 1141 | kfree((void *)kc[i].private_value); | ||
| 1142 | kfree(kc); | ||
| 1143 | return NULL; | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create( | ||
| 1147 | struct soc_tplg *tplg) | ||
| 1148 | { | ||
| 1149 | struct snd_kcontrol_new *kc; | ||
| 1150 | struct snd_soc_tplg_enum_control *ec; | ||
| 1151 | struct soc_enum *se; | ||
| 1152 | int i, err; | ||
| 1153 | |||
| 1154 | ec = (struct snd_soc_tplg_enum_control *)tplg->pos; | ||
| 1155 | tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + | ||
| 1156 | ec->priv.size); | ||
| 1157 | |||
| 1158 | /* validate kcontrol */ | ||
| 1159 | if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1160 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1161 | return NULL; | ||
| 1162 | |||
| 1163 | kc = kzalloc(sizeof(*kc), GFP_KERNEL); | ||
| 1164 | if (kc == NULL) | ||
| 1165 | return NULL; | ||
| 1166 | |||
| 1167 | se = kzalloc(sizeof(*se), GFP_KERNEL); | ||
| 1168 | if (se == NULL) | ||
| 1169 | goto err; | ||
| 1170 | |||
| 1171 | dev_dbg(tplg->dev, " adding DAPM widget enum control %s\n", | ||
| 1172 | ec->hdr.name); | ||
| 1173 | |||
| 1174 | kc->name = ec->hdr.name; | ||
| 1175 | kc->private_value = (long)se; | ||
| 1176 | kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
| 1177 | kc->access = ec->hdr.access; | ||
| 1178 | |||
| 1179 | /* we only support FL/FR channel mapping atm */ | ||
| 1180 | se->reg = tplc_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); | ||
| 1181 | se->shift_l = tplc_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FL); | ||
| 1182 | se->shift_r = tplc_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FR); | ||
| 1183 | |||
| 1184 | se->items = ec->items; | ||
| 1185 | se->mask = ec->mask; | ||
| 1186 | se->dobj.index = tplg->index; | ||
| 1187 | |||
| 1188 | switch (ec->hdr.ops.info) { | ||
| 1189 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | ||
| 1190 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | ||
| 1191 | err = soc_tplg_denum_create_values(se, ec); | ||
| 1192 | if (err < 0) { | ||
| 1193 | dev_err(tplg->dev, "ASoC: could not create values for %s\n", | ||
| 1194 | ec->hdr.name); | ||
| 1195 | goto err_se; | ||
| 1196 | } | ||
| 1197 | /* fall through to create texts */ | ||
| 1198 | case SND_SOC_TPLG_CTL_ENUM: | ||
| 1199 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | ||
| 1200 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | ||
| 1201 | err = soc_tplg_denum_create_texts(se, ec); | ||
| 1202 | if (err < 0) { | ||
| 1203 | dev_err(tplg->dev, "ASoC: could not create texts for %s\n", | ||
| 1204 | ec->hdr.name); | ||
| 1205 | goto err_se; | ||
| 1206 | } | ||
| 1207 | break; | ||
| 1208 | default: | ||
| 1209 | dev_err(tplg->dev, "ASoC: invalid enum control type %d for %s\n", | ||
| 1210 | ec->hdr.ops.info, ec->hdr.name); | ||
| 1211 | goto err_se; | ||
| 1212 | } | ||
| 1213 | |||
| 1214 | /* map io handlers */ | ||
| 1215 | err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, io_ops, | ||
| 1216 | ARRAY_SIZE(io_ops), tplg->io_ops, tplg->io_ops_count); | ||
| 1217 | if (err) { | ||
| 1218 | soc_control_err(tplg, &ec->hdr, ec->hdr.name); | ||
| 1219 | goto err_se; | ||
| 1220 | } | ||
| 1221 | |||
| 1222 | /* pass control to driver for optional further init */ | ||
| 1223 | err = soc_tplg_init_kcontrol(tplg, kc, | ||
| 1224 | (struct snd_soc_tplg_ctl_hdr *)ec); | ||
| 1225 | if (err < 0) { | ||
| 1226 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | ||
| 1227 | ec->hdr.name); | ||
| 1228 | goto err_se; | ||
| 1229 | } | ||
| 1230 | |||
| 1231 | return kc; | ||
| 1232 | |||
| 1233 | err_se: | ||
| 1234 | /* free values and texts */ | ||
| 1235 | kfree(se->dobj.control.dvalues); | ||
| 1236 | for (i = 0; i < ec->items; i++) | ||
| 1237 | kfree(se->dobj.control.dtexts[i]); | ||
| 1238 | |||
| 1239 | kfree(se); | ||
| 1240 | err: | ||
| 1241 | kfree(kc); | ||
| 1242 | |||
| 1243 | return NULL; | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create( | ||
| 1247 | struct soc_tplg *tplg, int count) | ||
| 1248 | { | ||
| 1249 | struct snd_soc_tplg_bytes_control *be; | ||
| 1250 | struct soc_bytes_ext *sbe; | ||
| 1251 | struct snd_kcontrol_new *kc; | ||
| 1252 | int i, err; | ||
| 1253 | |||
| 1254 | kc = kzalloc(sizeof(*kc) * count, GFP_KERNEL); | ||
| 1255 | if (!kc) | ||
| 1256 | return NULL; | ||
| 1257 | |||
| 1258 | for (i = 0; i < count; i++) { | ||
| 1259 | be = (struct snd_soc_tplg_bytes_control *)tplg->pos; | ||
| 1260 | |||
| 1261 | /* validate kcontrol */ | ||
| 1262 | if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1263 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1264 | goto err; | ||
| 1265 | |||
| 1266 | sbe = kzalloc(sizeof(*sbe), GFP_KERNEL); | ||
| 1267 | if (sbe == NULL) | ||
| 1268 | goto err; | ||
| 1269 | |||
| 1270 | tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + | ||
| 1271 | be->priv.size); | ||
| 1272 | |||
| 1273 | dev_dbg(tplg->dev, | ||
| 1274 | "ASoC: adding bytes kcontrol %s with access 0x%x\n", | ||
| 1275 | be->hdr.name, be->hdr.access); | ||
| 1276 | |||
| 1277 | memset(kc, 0, sizeof(*kc)); | ||
| 1278 | kc[i].name = be->hdr.name; | ||
| 1279 | kc[i].private_value = (long)sbe; | ||
| 1280 | kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
| 1281 | kc[i].access = be->hdr.access; | ||
| 1282 | |||
| 1283 | sbe->max = be->max; | ||
| 1284 | INIT_LIST_HEAD(&sbe->dobj.list); | ||
| 1285 | |||
| 1286 | /* map standard io handlers and check for external handlers */ | ||
| 1287 | err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc[i], io_ops, | ||
| 1288 | ARRAY_SIZE(io_ops), tplg->io_ops, | ||
| 1289 | tplg->io_ops_count); | ||
| 1290 | if (err) { | ||
| 1291 | soc_control_err(tplg, &be->hdr, be->hdr.name); | ||
| 1292 | kfree(sbe); | ||
| 1293 | continue; | ||
| 1294 | } | ||
| 1295 | |||
| 1296 | /* pass control to driver for optional further init */ | ||
| 1297 | err = soc_tplg_init_kcontrol(tplg, &kc[i], | ||
| 1298 | (struct snd_soc_tplg_ctl_hdr *)be); | ||
| 1299 | if (err < 0) { | ||
| 1300 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | ||
| 1301 | be->hdr.name); | ||
| 1302 | kfree(sbe); | ||
| 1303 | continue; | ||
| 1304 | } | ||
| 1305 | } | ||
| 1306 | |||
| 1307 | return kc; | ||
| 1308 | |||
| 1309 | err: | ||
| 1310 | for (--i; i >= 0; i--) | ||
| 1311 | kfree((void *)kc[i].private_value); | ||
| 1312 | |||
| 1313 | kfree(kc); | ||
| 1314 | return NULL; | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg, | ||
| 1318 | struct snd_soc_tplg_dapm_widget *w) | ||
| 1319 | { | ||
| 1320 | struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; | ||
| 1321 | struct snd_soc_dapm_widget template, *widget; | ||
| 1322 | struct snd_soc_tplg_ctl_hdr *control_hdr; | ||
| 1323 | struct snd_soc_card *card = tplg->comp->card; | ||
| 1324 | int ret = 0; | ||
| 1325 | |||
| 1326 | if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1327 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1328 | return -EINVAL; | ||
| 1329 | if (strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | ||
| 1330 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | ||
| 1331 | return -EINVAL; | ||
| 1332 | |||
| 1333 | dev_dbg(tplg->dev, "ASoC: creating DAPM widget %s id %d\n", | ||
| 1334 | w->name, w->id); | ||
| 1335 | |||
| 1336 | memset(&template, 0, sizeof(template)); | ||
| 1337 | |||
| 1338 | /* map user to kernel widget ID */ | ||
| 1339 | template.id = get_widget_id(w->id); | ||
| 1340 | if (template.id < 0) | ||
| 1341 | return template.id; | ||
| 1342 | |||
| 1343 | template.name = kstrdup(w->name, GFP_KERNEL); | ||
| 1344 | if (!template.name) | ||
| 1345 | return -ENOMEM; | ||
| 1346 | template.sname = kstrdup(w->sname, GFP_KERNEL); | ||
| 1347 | if (!template.sname) { | ||
| 1348 | ret = -ENOMEM; | ||
| 1349 | goto err; | ||
| 1350 | } | ||
| 1351 | template.reg = w->reg; | ||
| 1352 | template.shift = w->shift; | ||
| 1353 | template.mask = w->mask; | ||
| 1354 | template.on_val = w->invert ? 0 : 1; | ||
| 1355 | template.off_val = w->invert ? 1 : 0; | ||
| 1356 | template.ignore_suspend = w->ignore_suspend; | ||
| 1357 | template.event_flags = w->event_flags; | ||
| 1358 | template.dobj.index = tplg->index; | ||
| 1359 | |||
| 1360 | tplg->pos += | ||
| 1361 | (sizeof(struct snd_soc_tplg_dapm_widget) + w->priv.size); | ||
| 1362 | if (w->num_kcontrols == 0) { | ||
| 1363 | template.num_kcontrols = 0; | ||
| 1364 | goto widget; | ||
| 1365 | } | ||
| 1366 | |||
| 1367 | control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos; | ||
| 1368 | dev_dbg(tplg->dev, "ASoC: template %s has %d controls of type %x\n", | ||
| 1369 | w->name, w->num_kcontrols, control_hdr->type); | ||
| 1370 | |||
| 1371 | switch (control_hdr->ops.info) { | ||
| 1372 | case SND_SOC_TPLG_CTL_VOLSW: | ||
| 1373 | case SND_SOC_TPLG_CTL_STROBE: | ||
| 1374 | case SND_SOC_TPLG_CTL_VOLSW_SX: | ||
| 1375 | case SND_SOC_TPLG_CTL_VOLSW_XR_SX: | ||
| 1376 | case SND_SOC_TPLG_CTL_RANGE: | ||
| 1377 | case SND_SOC_TPLG_DAPM_CTL_VOLSW: | ||
| 1378 | template.num_kcontrols = w->num_kcontrols; | ||
| 1379 | template.kcontrol_news = | ||
| 1380 | soc_tplg_dapm_widget_dmixer_create(tplg, | ||
| 1381 | template.num_kcontrols); | ||
| 1382 | if (!template.kcontrol_news) { | ||
| 1383 | ret = -ENOMEM; | ||
| 1384 | goto hdr_err; | ||
| 1385 | } | ||
| 1386 | break; | ||
| 1387 | case SND_SOC_TPLG_CTL_ENUM: | ||
| 1388 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | ||
| 1389 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | ||
| 1390 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | ||
| 1391 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | ||
| 1392 | template.dobj.widget.kcontrol_enum = 1; | ||
| 1393 | template.num_kcontrols = 1; | ||
| 1394 | template.kcontrol_news = | ||
| 1395 | soc_tplg_dapm_widget_denum_create(tplg); | ||
| 1396 | if (!template.kcontrol_news) { | ||
| 1397 | ret = -ENOMEM; | ||
| 1398 | goto hdr_err; | ||
| 1399 | } | ||
| 1400 | break; | ||
| 1401 | case SND_SOC_TPLG_CTL_BYTES: | ||
| 1402 | template.num_kcontrols = w->num_kcontrols; | ||
| 1403 | template.kcontrol_news = | ||
| 1404 | soc_tplg_dapm_widget_dbytes_create(tplg, | ||
| 1405 | template.num_kcontrols); | ||
| 1406 | if (!template.kcontrol_news) { | ||
| 1407 | ret = -ENOMEM; | ||
| 1408 | goto hdr_err; | ||
| 1409 | } | ||
| 1410 | break; | ||
| 1411 | default: | ||
| 1412 | dev_err(tplg->dev, "ASoC: invalid widget control type %d:%d:%d\n", | ||
| 1413 | control_hdr->ops.get, control_hdr->ops.put, | ||
| 1414 | control_hdr->ops.info); | ||
| 1415 | ret = -EINVAL; | ||
| 1416 | goto hdr_err; | ||
| 1417 | } | ||
| 1418 | |||
| 1419 | widget: | ||
| 1420 | ret = soc_tplg_widget_load(tplg, &template, w); | ||
| 1421 | if (ret < 0) | ||
| 1422 | goto hdr_err; | ||
| 1423 | |||
| 1424 | /* card dapm mutex is held by the core if we are loading topology | ||
| 1425 | * data during sound card init. */ | ||
| 1426 | if (card->instantiated) | ||
| 1427 | widget = snd_soc_dapm_new_control(dapm, &template); | ||
| 1428 | else | ||
| 1429 | widget = snd_soc_dapm_new_control_unlocked(dapm, &template); | ||
| 1430 | if (widget == NULL) { | ||
| 1431 | dev_err(tplg->dev, "ASoC: failed to create widget %s controls\n", | ||
| 1432 | w->name); | ||
| 1433 | goto hdr_err; | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | widget->dobj.type = SND_SOC_DOBJ_WIDGET; | ||
| 1437 | widget->dobj.ops = tplg->ops; | ||
| 1438 | widget->dobj.index = tplg->index; | ||
| 1439 | list_add(&widget->dobj.list, &tplg->comp->dobj_list); | ||
| 1440 | return 0; | ||
| 1441 | |||
| 1442 | hdr_err: | ||
| 1443 | kfree(template.sname); | ||
| 1444 | err: | ||
| 1445 | kfree(template.name); | ||
| 1446 | return ret; | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | static int soc_tplg_dapm_widget_elems_load(struct soc_tplg *tplg, | ||
| 1450 | struct snd_soc_tplg_hdr *hdr) | ||
| 1451 | { | ||
| 1452 | struct snd_soc_tplg_dapm_widget *widget; | ||
| 1453 | int ret, count = hdr->count, i; | ||
| 1454 | |||
| 1455 | if (tplg->pass != SOC_TPLG_PASS_WIDGET) | ||
| 1456 | return 0; | ||
| 1457 | |||
| 1458 | dev_dbg(tplg->dev, "ASoC: adding %d DAPM widgets\n", count); | ||
| 1459 | |||
| 1460 | for (i = 0; i < count; i++) { | ||
| 1461 | widget = (struct snd_soc_tplg_dapm_widget *) tplg->pos; | ||
| 1462 | ret = soc_tplg_dapm_widget_create(tplg, widget); | ||
| 1463 | if (ret < 0) | ||
| 1464 | dev_err(tplg->dev, "ASoC: failed to load widget %s\n", | ||
| 1465 | widget->name); | ||
| 1466 | } | ||
| 1467 | |||
| 1468 | return 0; | ||
| 1469 | } | ||
| 1470 | |||
| 1471 | static int soc_tplg_dapm_complete(struct soc_tplg *tplg) | ||
| 1472 | { | ||
| 1473 | struct snd_soc_card *card = tplg->comp->card; | ||
| 1474 | int ret; | ||
| 1475 | |||
| 1476 | /* Card might not have been registered at this point. | ||
| 1477 | * If so, just return success. | ||
| 1478 | */ | ||
| 1479 | if (!card || !card->instantiated) { | ||
| 1480 | dev_warn(tplg->dev, "ASoC: Parent card not yet available," | ||
| 1481 | "Do not add new widgets now\n"); | ||
| 1482 | return 0; | ||
| 1483 | } | ||
| 1484 | |||
| 1485 | ret = snd_soc_dapm_new_widgets(card); | ||
| 1486 | if (ret < 0) | ||
| 1487 | dev_err(tplg->dev, "ASoC: failed to create new widgets %d\n", | ||
| 1488 | ret); | ||
| 1489 | |||
| 1490 | return 0; | ||
| 1491 | } | ||
| 1492 | |||
| 1493 | static int soc_tplg_pcm_dai_elems_load(struct soc_tplg *tplg, | ||
| 1494 | struct snd_soc_tplg_hdr *hdr) | ||
| 1495 | { | ||
| 1496 | struct snd_soc_tplg_pcm_dai *pcm_dai; | ||
| 1497 | struct snd_soc_dobj *dobj; | ||
| 1498 | int count = hdr->count; | ||
| 1499 | int ret; | ||
| 1500 | |||
| 1501 | if (tplg->pass != SOC_TPLG_PASS_PCM_DAI) | ||
| 1502 | return 0; | ||
| 1503 | |||
| 1504 | pcm_dai = (struct snd_soc_tplg_pcm_dai *)tplg->pos; | ||
| 1505 | |||
| 1506 | if (soc_tplg_check_elem_count(tplg, | ||
| 1507 | sizeof(struct snd_soc_tplg_pcm_dai), count, | ||
| 1508 | hdr->payload_size, "PCM DAI")) { | ||
| 1509 | dev_err(tplg->dev, "ASoC: invalid count %d for PCM DAI elems\n", | ||
| 1510 | count); | ||
| 1511 | return -EINVAL; | ||
| 1512 | } | ||
| 1513 | |||
| 1514 | dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count); | ||
| 1515 | tplg->pos += sizeof(struct snd_soc_tplg_pcm_dai) * count; | ||
| 1516 | |||
| 1517 | dobj = kzalloc(sizeof(struct snd_soc_dobj), GFP_KERNEL); | ||
| 1518 | if (dobj == NULL) | ||
| 1519 | return -ENOMEM; | ||
| 1520 | |||
| 1521 | /* Call the platform driver call back to register the dais */ | ||
| 1522 | ret = soc_tplg_pcm_dai_load(tplg, pcm_dai, count); | ||
| 1523 | if (ret < 0) { | ||
| 1524 | dev_err(tplg->comp->dev, "ASoC: PCM DAI loading failed\n"); | ||
| 1525 | goto err; | ||
| 1526 | } | ||
| 1527 | |||
| 1528 | dobj->type = get_dobj_type(hdr, NULL); | ||
| 1529 | dobj->pcm_dai.count = count; | ||
| 1530 | dobj->pcm_dai.pd = pcm_dai; | ||
| 1531 | dobj->ops = tplg->ops; | ||
| 1532 | dobj->index = tplg->index; | ||
| 1533 | list_add(&dobj->list, &tplg->comp->dobj_list); | ||
| 1534 | return 0; | ||
| 1535 | |||
| 1536 | err: | ||
| 1537 | kfree(dobj); | ||
| 1538 | return ret; | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | static int soc_tplg_manifest_load(struct soc_tplg *tplg, | ||
| 1542 | struct snd_soc_tplg_hdr *hdr) | ||
| 1543 | { | ||
| 1544 | struct snd_soc_tplg_manifest *manifest; | ||
| 1545 | |||
| 1546 | if (tplg->pass != SOC_TPLG_PASS_MANIFEST) | ||
| 1547 | return 0; | ||
| 1548 | |||
| 1549 | manifest = (struct snd_soc_tplg_manifest *)tplg->pos; | ||
| 1550 | tplg->pos += sizeof(struct snd_soc_tplg_manifest); | ||
| 1551 | |||
| 1552 | if (tplg->comp && tplg->ops && tplg->ops->manifest) | ||
| 1553 | return tplg->ops->manifest(tplg->comp, manifest); | ||
| 1554 | |||
| 1555 | dev_err(tplg->dev, "ASoC: Firmware manifest not supported\n"); | ||
| 1556 | return 0; | ||
| 1557 | } | ||
| 1558 | |||
| 1559 | /* validate header magic, size and type */ | ||
| 1560 | static int soc_valid_header(struct soc_tplg *tplg, | ||
| 1561 | struct snd_soc_tplg_hdr *hdr) | ||
| 1562 | { | ||
| 1563 | if (soc_tplg_get_hdr_offset(tplg) >= tplg->fw->size) | ||
| 1564 | return 0; | ||
| 1565 | |||
| 1566 | /* big endian firmware objects not supported atm */ | ||
| 1567 | if (hdr->magic == cpu_to_be32(SND_SOC_TPLG_MAGIC)) { | ||
| 1568 | dev_err(tplg->dev, | ||
| 1569 | "ASoC: pass %d big endian not supported header got %x at offset 0x%lx size 0x%zx.\n", | ||
| 1570 | tplg->pass, hdr->magic, | ||
| 1571 | soc_tplg_get_hdr_offset(tplg), tplg->fw->size); | ||
| 1572 | return -EINVAL; | ||
| 1573 | } | ||
| 1574 | |||
| 1575 | if (hdr->magic != SND_SOC_TPLG_MAGIC) { | ||
| 1576 | dev_err(tplg->dev, | ||
| 1577 | "ASoC: pass %d does not have a valid header got %x at offset 0x%lx size 0x%zx.\n", | ||
| 1578 | tplg->pass, hdr->magic, | ||
| 1579 | soc_tplg_get_hdr_offset(tplg), tplg->fw->size); | ||
| 1580 | return -EINVAL; | ||
| 1581 | } | ||
| 1582 | |||
| 1583 | if (hdr->abi != SND_SOC_TPLG_ABI_VERSION) { | ||
| 1584 | dev_err(tplg->dev, | ||
| 1585 | "ASoC: pass %d invalid ABI version got 0x%x need 0x%x at offset 0x%lx size 0x%zx.\n", | ||
| 1586 | tplg->pass, hdr->abi, | ||
| 1587 | SND_SOC_TPLG_ABI_VERSION, soc_tplg_get_hdr_offset(tplg), | ||
| 1588 | tplg->fw->size); | ||
| 1589 | return -EINVAL; | ||
| 1590 | } | ||
| 1591 | |||
| 1592 | if (hdr->payload_size == 0) { | ||
| 1593 | dev_err(tplg->dev, "ASoC: header has 0 size at offset 0x%lx.\n", | ||
| 1594 | soc_tplg_get_hdr_offset(tplg)); | ||
| 1595 | return -EINVAL; | ||
| 1596 | } | ||
| 1597 | |||
| 1598 | if (tplg->pass == hdr->type) | ||
| 1599 | dev_dbg(tplg->dev, | ||
| 1600 | "ASoC: Got 0x%x bytes of type %d version %d vendor %d at pass %d\n", | ||
| 1601 | hdr->payload_size, hdr->type, hdr->version, | ||
| 1602 | hdr->vendor_type, tplg->pass); | ||
| 1603 | |||
| 1604 | return 1; | ||
| 1605 | } | ||
| 1606 | |||
| 1607 | /* check header type and call appropriate handler */ | ||
| 1608 | static int soc_tplg_load_header(struct soc_tplg *tplg, | ||
| 1609 | struct snd_soc_tplg_hdr *hdr) | ||
| 1610 | { | ||
| 1611 | tplg->pos = tplg->hdr_pos + sizeof(struct snd_soc_tplg_hdr); | ||
| 1612 | |||
| 1613 | /* check for matching ID */ | ||
| 1614 | if (hdr->index != tplg->req_index && | ||
| 1615 | hdr->index != SND_SOC_TPLG_INDEX_ALL) | ||
| 1616 | return 0; | ||
| 1617 | |||
| 1618 | tplg->index = hdr->index; | ||
| 1619 | |||
| 1620 | switch (hdr->type) { | ||
| 1621 | case SND_SOC_TPLG_TYPE_MIXER: | ||
| 1622 | case SND_SOC_TPLG_TYPE_ENUM: | ||
| 1623 | case SND_SOC_TPLG_TYPE_BYTES: | ||
| 1624 | return soc_tplg_kcontrol_elems_load(tplg, hdr); | ||
| 1625 | case SND_SOC_TPLG_TYPE_DAPM_GRAPH: | ||
| 1626 | return soc_tplg_dapm_graph_elems_load(tplg, hdr); | ||
| 1627 | case SND_SOC_TPLG_TYPE_DAPM_WIDGET: | ||
| 1628 | return soc_tplg_dapm_widget_elems_load(tplg, hdr); | ||
| 1629 | case SND_SOC_TPLG_TYPE_PCM: | ||
| 1630 | case SND_SOC_TPLG_TYPE_DAI_LINK: | ||
| 1631 | case SND_SOC_TPLG_TYPE_CODEC_LINK: | ||
| 1632 | return soc_tplg_pcm_dai_elems_load(tplg, hdr); | ||
| 1633 | case SND_SOC_TPLG_TYPE_MANIFEST: | ||
| 1634 | return soc_tplg_manifest_load(tplg, hdr); | ||
| 1635 | default: | ||
| 1636 | /* bespoke vendor data object */ | ||
| 1637 | return soc_tplg_vendor_load(tplg, hdr); | ||
| 1638 | } | ||
| 1639 | |||
| 1640 | return 0; | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | /* process the topology file headers */ | ||
| 1644 | static int soc_tplg_process_headers(struct soc_tplg *tplg) | ||
| 1645 | { | ||
| 1646 | struct snd_soc_tplg_hdr *hdr; | ||
| 1647 | int ret; | ||
| 1648 | |||
| 1649 | tplg->pass = SOC_TPLG_PASS_START; | ||
| 1650 | |||
| 1651 | /* process the header types from start to end */ | ||
| 1652 | while (tplg->pass <= SOC_TPLG_PASS_END) { | ||
| 1653 | |||
| 1654 | tplg->hdr_pos = tplg->fw->data; | ||
| 1655 | hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; | ||
| 1656 | |||
| 1657 | while (!soc_tplg_is_eof(tplg)) { | ||
| 1658 | |||
| 1659 | /* make sure header is valid before loading */ | ||
| 1660 | ret = soc_valid_header(tplg, hdr); | ||
| 1661 | if (ret < 0) | ||
| 1662 | return ret; | ||
| 1663 | else if (ret == 0) | ||
| 1664 | break; | ||
| 1665 | |||
| 1666 | /* load the header object */ | ||
| 1667 | ret = soc_tplg_load_header(tplg, hdr); | ||
| 1668 | if (ret < 0) | ||
| 1669 | return ret; | ||
| 1670 | |||
| 1671 | /* goto next header */ | ||
| 1672 | tplg->hdr_pos += hdr->payload_size + | ||
| 1673 | sizeof(struct snd_soc_tplg_hdr); | ||
| 1674 | hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; | ||
| 1675 | } | ||
| 1676 | |||
| 1677 | /* next data type pass */ | ||
| 1678 | tplg->pass++; | ||
| 1679 | } | ||
| 1680 | |||
| 1681 | /* signal DAPM we are complete */ | ||
| 1682 | ret = soc_tplg_dapm_complete(tplg); | ||
| 1683 | if (ret < 0) | ||
| 1684 | dev_err(tplg->dev, | ||
| 1685 | "ASoC: failed to initialise DAPM from Firmware\n"); | ||
| 1686 | |||
| 1687 | return ret; | ||
| 1688 | } | ||
| 1689 | |||
| 1690 | static int soc_tplg_load(struct soc_tplg *tplg) | ||
| 1691 | { | ||
| 1692 | int ret; | ||
| 1693 | |||
| 1694 | ret = soc_tplg_process_headers(tplg); | ||
| 1695 | if (ret == 0) | ||
| 1696 | soc_tplg_complete(tplg); | ||
| 1697 | |||
| 1698 | return ret; | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | /* load audio component topology from "firmware" file */ | ||
| 1702 | int snd_soc_tplg_component_load(struct snd_soc_component *comp, | ||
| 1703 | struct snd_soc_tplg_ops *ops, const struct firmware *fw, u32 id) | ||
| 1704 | { | ||
| 1705 | struct soc_tplg tplg; | ||
| 1706 | |||
| 1707 | /* setup parsing context */ | ||
| 1708 | memset(&tplg, 0, sizeof(tplg)); | ||
| 1709 | tplg.fw = fw; | ||
| 1710 | tplg.dev = comp->dev; | ||
| 1711 | tplg.comp = comp; | ||
| 1712 | tplg.ops = ops; | ||
| 1713 | tplg.req_index = id; | ||
| 1714 | tplg.io_ops = ops->io_ops; | ||
| 1715 | tplg.io_ops_count = ops->io_ops_count; | ||
| 1716 | |||
| 1717 | return soc_tplg_load(&tplg); | ||
| 1718 | } | ||
| 1719 | EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load); | ||
| 1720 | |||
| 1721 | /* remove this dynamic widget */ | ||
| 1722 | void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w) | ||
| 1723 | { | ||
| 1724 | /* make sure we are a widget */ | ||
| 1725 | if (w->dobj.type != SND_SOC_DOBJ_WIDGET) | ||
| 1726 | return; | ||
| 1727 | |||
| 1728 | remove_widget(w->dapm->component, &w->dobj, SOC_TPLG_PASS_WIDGET); | ||
| 1729 | } | ||
| 1730 | EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove); | ||
| 1731 | |||
| 1732 | /* remove all dynamic widgets from this DAPM context */ | ||
| 1733 | void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm, | ||
| 1734 | u32 index) | ||
| 1735 | { | ||
| 1736 | struct snd_soc_dapm_widget *w, *next_w; | ||
| 1737 | struct snd_soc_dapm_path *p, *next_p; | ||
| 1738 | |||
| 1739 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { | ||
| 1740 | |||
| 1741 | /* make sure we are a widget with correct context */ | ||
| 1742 | if (w->dobj.type != SND_SOC_DOBJ_WIDGET || w->dapm != dapm) | ||
| 1743 | continue; | ||
| 1744 | |||
| 1745 | /* match ID */ | ||
| 1746 | if (w->dobj.index != index && | ||
| 1747 | w->dobj.index != SND_SOC_TPLG_INDEX_ALL) | ||
| 1748 | continue; | ||
| 1749 | |||
| 1750 | list_del(&w->list); | ||
| 1751 | |||
| 1752 | /* | ||
| 1753 | * remove source and sink paths associated to this widget. | ||
| 1754 | * While removing the path, remove reference to it from both | ||
| 1755 | * source and sink widgets so that path is removed only once. | ||
| 1756 | */ | ||
| 1757 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { | ||
| 1758 | list_del(&p->list_sink); | ||
| 1759 | list_del(&p->list_source); | ||
| 1760 | list_del(&p->list); | ||
| 1761 | kfree(p); | ||
| 1762 | } | ||
| 1763 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { | ||
| 1764 | list_del(&p->list_sink); | ||
| 1765 | list_del(&p->list_source); | ||
| 1766 | list_del(&p->list); | ||
| 1767 | kfree(p); | ||
| 1768 | } | ||
| 1769 | /* check and free and dynamic widget kcontrols */ | ||
| 1770 | snd_soc_tplg_widget_remove(w); | ||
| 1771 | kfree(w->kcontrols); | ||
| 1772 | kfree(w->name); | ||
| 1773 | kfree(w); | ||
| 1774 | } | ||
| 1775 | } | ||
| 1776 | EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove_all); | ||
| 1777 | |||
| 1778 | /* remove dynamic controls from the component driver */ | ||
| 1779 | int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index) | ||
| 1780 | { | ||
| 1781 | struct snd_soc_dobj *dobj, *next_dobj; | ||
| 1782 | int pass = SOC_TPLG_PASS_END; | ||
| 1783 | |||
| 1784 | /* process the header types from end to start */ | ||
| 1785 | while (pass >= SOC_TPLG_PASS_START) { | ||
| 1786 | |||
| 1787 | /* remove mixer controls */ | ||
| 1788 | list_for_each_entry_safe(dobj, next_dobj, &comp->dobj_list, | ||
| 1789 | list) { | ||
| 1790 | |||
| 1791 | /* match index */ | ||
| 1792 | if (dobj->index != index && | ||
| 1793 | dobj->index != SND_SOC_TPLG_INDEX_ALL) | ||
| 1794 | continue; | ||
| 1795 | |||
| 1796 | switch (dobj->type) { | ||
| 1797 | case SND_SOC_DOBJ_MIXER: | ||
| 1798 | remove_mixer(comp, dobj, pass); | ||
| 1799 | break; | ||
| 1800 | case SND_SOC_DOBJ_ENUM: | ||
| 1801 | remove_enum(comp, dobj, pass); | ||
| 1802 | break; | ||
| 1803 | case SND_SOC_DOBJ_BYTES: | ||
| 1804 | remove_bytes(comp, dobj, pass); | ||
| 1805 | break; | ||
| 1806 | case SND_SOC_DOBJ_WIDGET: | ||
| 1807 | remove_widget(comp, dobj, pass); | ||
| 1808 | break; | ||
| 1809 | case SND_SOC_DOBJ_PCM: | ||
| 1810 | case SND_SOC_DOBJ_DAI_LINK: | ||
| 1811 | case SND_SOC_DOBJ_CODEC_LINK: | ||
| 1812 | remove_pcm_dai(comp, dobj, pass); | ||
| 1813 | break; | ||
| 1814 | default: | ||
| 1815 | dev_err(comp->dev, "ASoC: invalid component type %d for removal\n", | ||
| 1816 | dobj->type); | ||
| 1817 | break; | ||
| 1818 | } | ||
| 1819 | } | ||
| 1820 | pass--; | ||
| 1821 | } | ||
| 1822 | |||
| 1823 | /* let caller know if FW can be freed when no objects are left */ | ||
| 1824 | return !list_empty(&comp->dobj_list); | ||
| 1825 | } | ||
| 1826 | EXPORT_SYMBOL_GPL(snd_soc_tplg_component_remove); | ||
