Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/sound/soc.h -- ALSA SoC Layer |
| 3 | * |
| 4 | * Author: Liam Girdwood |
| 5 | * Created: Aug 11th 2005 |
| 6 | * Copyright: Wolfson Microelectronics. PLC. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __LINUX_SND_SOC_H |
| 14 | #define __LINUX_SND_SOC_H |
| 15 | |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/types.h> |
Andrew Morton | 4484bb2 | 2006-12-15 09:30:07 +0100 | [diff] [blame] | 18 | #include <linux/workqueue.h> |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 19 | #include <sound/core.h> |
| 20 | #include <sound/pcm.h> |
| 21 | #include <sound/control.h> |
| 22 | #include <sound/ac97_codec.h> |
| 23 | |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 24 | /* |
| 25 | * Convenience kcontrol builders |
| 26 | */ |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 27 | #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \ |
| 28 | ((unsigned long)&(struct soc_mixer_control) \ |
Mark Brown | 762b8df | 2008-10-30 12:37:08 +0000 | [diff] [blame] | 29 | {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \ |
| 30 | .invert = xinvert}) |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 31 | #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \ |
| 32 | ((unsigned long)&(struct soc_mixer_control) \ |
| 33 | {.reg = xreg, .max = xmax, .invert = xinvert}) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 34 | #define SOC_SINGLE(xname, reg, shift, max, invert) \ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 35 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 36 | .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ |
| 37 | .put = snd_soc_put_volsw, \ |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 38 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } |
| 39 | #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \ |
| 40 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 41 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ |
| 42 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ |
| 43 | .tlv.p = (tlv_array), \ |
| 44 | .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ |
| 45 | .put = snd_soc_put_volsw, \ |
| 46 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 47 | #define SOC_DOUBLE(xname, xreg, shift_left, shift_right, xmax, xinvert) \ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 48 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ |
| 49 | .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ |
| 50 | .put = snd_soc_put_volsw, \ |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 51 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 52 | {.reg = xreg, .shift = shift_left, .rshift = shift_right, \ |
| 53 | .max = xmax, .invert = xinvert} } |
| 54 | #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 55 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ |
| 56 | .info = snd_soc_info_volsw_2r, \ |
| 57 | .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \ |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 58 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 59 | {.reg = reg_left, .rreg = reg_right, .shift = xshift, \ |
| 60 | .max = xmax, .invert = xinvert} } |
| 61 | #define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \ |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 62 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ |
| 63 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ |
| 64 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ |
| 65 | .tlv.p = (tlv_array), \ |
| 66 | .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \ |
| 67 | .put = snd_soc_put_volsw, \ |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 68 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 69 | {.reg = xreg, .shift = shift_left, .rshift = shift_right,\ |
| 70 | .max = xmax, .invert = xinvert} } |
| 71 | #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \ |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 72 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ |
| 73 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ |
| 74 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ |
| 75 | .tlv.p = (tlv_array), \ |
| 76 | .info = snd_soc_info_volsw_2r, \ |
| 77 | .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \ |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 78 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 79 | {.reg = reg_left, .rreg = reg_right, .shift = xshift, \ |
| 80 | .max = xmax, .invert = xinvert} } |
| 81 | #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \ |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 82 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \ |
| 83 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 84 | SNDRV_CTL_ELEM_ACCESS_READWRITE, \ |
| 85 | .tlv.p = (tlv_array), \ |
| 86 | .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \ |
| 87 | .put = snd_soc_put_volsw_s8, \ |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 88 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 89 | {.reg = xreg, .min = xmin, .max = xmax} } |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 90 | #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 91 | { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \ |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 92 | .max = xmax, .texts = xtexts } |
| 93 | #define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \ |
| 94 | SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts) |
| 95 | #define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \ |
| 96 | { .max = xmax, .texts = xtexts } |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 97 | #define SOC_ENUM(xname, xenum) \ |
| 98 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\ |
| 99 | .info = snd_soc_info_enum_double, \ |
| 100 | .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \ |
| 101 | .private_value = (unsigned long)&xenum } |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 102 | #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 103 | xhandler_get, xhandler_put) \ |
| 104 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 105 | .info = snd_soc_info_volsw, \ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 106 | .get = xhandler_get, .put = xhandler_put, \ |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 107 | .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) } |
| 108 | #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\ |
Mike Montour | 10144c0 | 2008-06-11 13:47:13 +0100 | [diff] [blame] | 109 | xhandler_get, xhandler_put, tlv_array) \ |
| 110 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 111 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ |
| 112 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ |
| 113 | .tlv.p = (tlv_array), \ |
| 114 | .info = snd_soc_info_volsw, \ |
| 115 | .get = xhandler_get, .put = xhandler_put, \ |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 116 | .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) } |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 117 | #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \ |
| 118 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 119 | .info = snd_soc_info_bool_ext, \ |
| 120 | .get = xhandler_get, .put = xhandler_put, \ |
| 121 | .private_value = xdata } |
| 122 | #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \ |
| 123 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 124 | .info = snd_soc_info_enum_ext, \ |
| 125 | .get = xhandler_get, .put = xhandler_put, \ |
| 126 | .private_value = (unsigned long)&xenum } |
| 127 | |
| 128 | /* |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 129 | * Bias levels |
| 130 | * |
| 131 | * @ON: Bias is fully on for audio playback and capture operations. |
| 132 | * @PREPARE: Prepare for audio operations. Called before DAPM switching for |
| 133 | * stream start and stop operations. |
| 134 | * @STANDBY: Low power standby state when no playback/capture operations are |
| 135 | * in progress. NOTE: The transition time between STANDBY and ON |
| 136 | * should be as fast as possible and no longer than 10ms. |
| 137 | * @OFF: Power Off. No restrictions on transition times. |
| 138 | */ |
| 139 | enum snd_soc_bias_level { |
| 140 | SND_SOC_BIAS_ON, |
| 141 | SND_SOC_BIAS_PREPARE, |
| 142 | SND_SOC_BIAS_STANDBY, |
| 143 | SND_SOC_BIAS_OFF, |
| 144 | }; |
| 145 | |
| 146 | /* |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 147 | * Digital Audio Interface (DAI) types |
| 148 | */ |
| 149 | #define SND_SOC_DAI_AC97 0x1 |
| 150 | #define SND_SOC_DAI_I2S 0x2 |
| 151 | #define SND_SOC_DAI_PCM 0x4 |
Liam Girdwood | a68660e | 2007-05-10 19:27:27 +0200 | [diff] [blame] | 152 | #define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * DAI hardware audio formats |
| 156 | */ |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 157 | #define SND_SOC_DAIFMT_I2S 0 /* I2S mode */ |
| 158 | #define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */ |
| 159 | #define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */ |
| 160 | #define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */ |
| 161 | #define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */ |
| 162 | #define SND_SOC_DAIFMT_AC97 5 /* AC97 */ |
| 163 | |
| 164 | #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J |
| 165 | #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J |
| 166 | |
| 167 | /* |
| 168 | * DAI Gating |
| 169 | */ |
| 170 | #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */ |
| 171 | #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 172 | |
| 173 | /* |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 174 | * DAI Sync |
| 175 | * Synchronous LR (Left Right) clocks and Frame signals. |
| 176 | */ |
| 177 | #define SND_SOC_DAIFMT_SYNC (0 << 5) /* Tx FRM = Rx FRM */ |
| 178 | #define SND_SOC_DAIFMT_ASYNC (1 << 5) /* Tx FRM ~ Rx FRM */ |
| 179 | |
| 180 | /* |
| 181 | * TDM |
| 182 | */ |
| 183 | #define SND_SOC_DAIFMT_TDM (1 << 6) |
| 184 | |
| 185 | /* |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 186 | * DAI hardware signal inversions |
| 187 | */ |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 188 | #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bclk + frm */ |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 189 | #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */ |
| 190 | #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */ |
| 191 | #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 192 | |
| 193 | /* |
| 194 | * DAI hardware clock masters |
| 195 | * This is wrt the codec, the inverse is true for the interface |
| 196 | * i.e. if the codec is clk and frm master then the interface is |
| 197 | * clk and frame slave. |
| 198 | */ |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 199 | #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */ |
| 200 | #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */ |
| 201 | #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */ |
| 202 | #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 203 | |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 204 | #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f |
| 205 | #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0 |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 206 | #define SND_SOC_DAIFMT_INV_MASK 0x0f00 |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 207 | #define SND_SOC_DAIFMT_MASTER_MASK 0xf000 |
| 208 | |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 209 | |
| 210 | /* |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 211 | * Master Clock Directions |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 212 | */ |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 213 | #define SND_SOC_CLOCK_IN 0 |
| 214 | #define SND_SOC_CLOCK_OUT 1 |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | * AC97 codec ID's bitmask |
| 218 | */ |
| 219 | #define SND_SOC_DAI_AC97_ID0 (1 << 0) |
| 220 | #define SND_SOC_DAI_AC97_ID1 (1 << 1) |
| 221 | #define SND_SOC_DAI_AC97_ID2 (1 << 2) |
| 222 | #define SND_SOC_DAI_AC97_ID3 (1 << 3) |
| 223 | |
| 224 | struct snd_soc_device; |
| 225 | struct snd_soc_pcm_stream; |
| 226 | struct snd_soc_ops; |
| 227 | struct snd_soc_dai_mode; |
| 228 | struct snd_soc_pcm_runtime; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 229 | struct snd_soc_dai; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 230 | struct snd_soc_codec; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 231 | struct soc_enum; |
| 232 | struct snd_soc_ac97_ops; |
| 233 | struct snd_soc_clock_info; |
| 234 | |
| 235 | typedef int (*hw_write_t)(void *,const char* ,int); |
| 236 | typedef int (*hw_read_t)(void *,char* ,int); |
| 237 | |
| 238 | extern struct snd_ac97_bus_ops soc_ac97_ops; |
| 239 | |
| 240 | /* pcm <-> DAI connect */ |
| 241 | void snd_soc_free_pcms(struct snd_soc_device *socdev); |
| 242 | int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid); |
| 243 | int snd_soc_register_card(struct snd_soc_device *socdev); |
| 244 | |
| 245 | /* set runtime hw params */ |
| 246 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
| 247 | const struct snd_pcm_hardware *hw); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 248 | |
| 249 | /* codec IO */ |
| 250 | #define snd_soc_read(codec, reg) codec->read(codec, reg) |
| 251 | #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value) |
| 252 | |
| 253 | /* codec register bit access */ |
| 254 | int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg, |
| 255 | unsigned short mask, unsigned short value); |
| 256 | int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg, |
| 257 | unsigned short mask, unsigned short value); |
| 258 | |
| 259 | int snd_soc_new_ac97_codec(struct snd_soc_codec *codec, |
| 260 | struct snd_ac97_bus_ops *ops, int num); |
| 261 | void snd_soc_free_ac97_codec(struct snd_soc_codec *codec); |
| 262 | |
Liam Girdwood | 8c6529d | 2008-07-08 13:19:13 +0100 | [diff] [blame] | 263 | /* Digital Audio Interface clocking API.*/ |
| 264 | int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 265 | unsigned int freq, int dir); |
| 266 | |
| 267 | int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, |
| 268 | int div_id, int div); |
| 269 | |
| 270 | int snd_soc_dai_set_pll(struct snd_soc_dai *dai, |
| 271 | int pll_id, unsigned int freq_in, unsigned int freq_out); |
| 272 | |
| 273 | /* Digital Audio interface formatting */ |
| 274 | int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt); |
| 275 | |
| 276 | int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, |
| 277 | unsigned int mask, int slots); |
| 278 | |
| 279 | int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate); |
| 280 | |
| 281 | /* Digital Audio Interface mute */ |
| 282 | int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute); |
| 283 | |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 284 | /* |
| 285 | *Controls |
| 286 | */ |
| 287 | struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, |
| 288 | void *data, char *long_name); |
| 289 | int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, |
| 290 | struct snd_ctl_elem_info *uinfo); |
| 291 | int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, |
| 292 | struct snd_ctl_elem_info *uinfo); |
| 293 | int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol, |
| 294 | struct snd_ctl_elem_value *ucontrol); |
| 295 | int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, |
| 296 | struct snd_ctl_elem_value *ucontrol); |
| 297 | int snd_soc_info_volsw(struct snd_kcontrol *kcontrol, |
| 298 | struct snd_ctl_elem_info *uinfo); |
| 299 | int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol, |
| 300 | struct snd_ctl_elem_info *uinfo); |
Philipp Zabel | 392abe9 | 2008-05-13 14:03:40 +0200 | [diff] [blame] | 301 | #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 302 | int snd_soc_get_volsw(struct snd_kcontrol *kcontrol, |
| 303 | struct snd_ctl_elem_value *ucontrol); |
| 304 | int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, |
| 305 | struct snd_ctl_elem_value *ucontrol); |
| 306 | int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol, |
| 307 | struct snd_ctl_elem_info *uinfo); |
| 308 | int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol, |
| 309 | struct snd_ctl_elem_value *ucontrol); |
| 310 | int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol, |
| 311 | struct snd_ctl_elem_value *ucontrol); |
Mark Brown | e13ac2e | 2008-05-28 17:58:05 +0100 | [diff] [blame] | 312 | int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol, |
| 313 | struct snd_ctl_elem_info *uinfo); |
| 314 | int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, |
| 315 | struct snd_ctl_elem_value *ucontrol); |
| 316 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
| 317 | struct snd_ctl_elem_value *ucontrol); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 318 | |
| 319 | /* SoC PCM stream information */ |
| 320 | struct snd_soc_pcm_stream { |
| 321 | char *stream_name; |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 322 | u64 formats; /* SNDRV_PCM_FMTBIT_* */ |
| 323 | unsigned int rates; /* SNDRV_PCM_RATE_* */ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 324 | unsigned int rate_min; /* min rate */ |
| 325 | unsigned int rate_max; /* max rate */ |
| 326 | unsigned int channels_min; /* min channels */ |
| 327 | unsigned int channels_max; /* max channels */ |
| 328 | unsigned int active:1; /* stream is in use */ |
| 329 | }; |
| 330 | |
| 331 | /* SoC audio ops */ |
| 332 | struct snd_soc_ops { |
| 333 | int (*startup)(struct snd_pcm_substream *); |
| 334 | void (*shutdown)(struct snd_pcm_substream *); |
| 335 | int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *); |
| 336 | int (*hw_free)(struct snd_pcm_substream *); |
| 337 | int (*prepare)(struct snd_pcm_substream *); |
| 338 | int (*trigger)(struct snd_pcm_substream *, int); |
| 339 | }; |
| 340 | |
Mark Brown | 1ef6ab7 | 2008-05-19 12:31:55 +0200 | [diff] [blame] | 341 | /* ASoC DAI ops */ |
| 342 | struct snd_soc_dai_ops { |
| 343 | /* DAI clocking configuration */ |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 344 | int (*set_sysclk)(struct snd_soc_dai *dai, |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 345 | int clk_id, unsigned int freq, int dir); |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 346 | int (*set_pll)(struct snd_soc_dai *dai, |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 347 | int pll_id, unsigned int freq_in, unsigned int freq_out); |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 348 | int (*set_clkdiv)(struct snd_soc_dai *dai, int div_id, int div); |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 349 | |
Mark Brown | 1ef6ab7 | 2008-05-19 12:31:55 +0200 | [diff] [blame] | 350 | /* DAI format configuration */ |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 351 | int (*set_fmt)(struct snd_soc_dai *dai, unsigned int fmt); |
| 352 | int (*set_tdm_slot)(struct snd_soc_dai *dai, |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 353 | unsigned int mask, int slots); |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 354 | int (*set_tristate)(struct snd_soc_dai *dai, int tristate); |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 355 | |
| 356 | /* digital mute */ |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 357 | int (*digital_mute)(struct snd_soc_dai *dai, int mute); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 358 | }; |
| 359 | |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 360 | /* SoC DAI (Digital Audio Interface) */ |
| 361 | struct snd_soc_dai { |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 362 | /* DAI description */ |
| 363 | char *name; |
| 364 | unsigned int id; |
| 365 | unsigned char type; |
| 366 | |
| 367 | /* DAI callbacks */ |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 368 | int (*probe)(struct platform_device *pdev, |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 369 | struct snd_soc_dai *dai); |
Mark Brown | bdb9287 | 2008-06-11 13:47:10 +0100 | [diff] [blame] | 370 | void (*remove)(struct platform_device *pdev, |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 371 | struct snd_soc_dai *dai); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 372 | int (*suspend)(struct platform_device *pdev, |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 373 | struct snd_soc_dai *dai); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 374 | int (*resume)(struct platform_device *pdev, |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 375 | struct snd_soc_dai *dai); |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 376 | |
| 377 | /* ops */ |
| 378 | struct snd_soc_ops ops; |
Mark Brown | 1ef6ab7 | 2008-05-19 12:31:55 +0200 | [diff] [blame] | 379 | struct snd_soc_dai_ops dai_ops; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 380 | |
| 381 | /* DAI capabilities */ |
| 382 | struct snd_soc_pcm_stream capture; |
| 383 | struct snd_soc_pcm_stream playback; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 384 | |
| 385 | /* DAI runtime info */ |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 386 | struct snd_pcm_runtime *runtime; |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 387 | struct snd_soc_codec *codec; |
| 388 | unsigned int active; |
| 389 | unsigned char pop_wait:1; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 390 | void *dma_data; |
| 391 | |
| 392 | /* DAI private data */ |
| 393 | void *private_data; |
| 394 | }; |
| 395 | |
| 396 | /* SoC Audio Codec */ |
| 397 | struct snd_soc_codec { |
| 398 | char *name; |
| 399 | struct module *owner; |
| 400 | struct mutex mutex; |
| 401 | |
| 402 | /* callbacks */ |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 403 | int (*set_bias_level)(struct snd_soc_codec *, |
| 404 | enum snd_soc_bias_level level); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 405 | |
| 406 | /* runtime */ |
| 407 | struct snd_card *card; |
| 408 | struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */ |
| 409 | unsigned int active; |
| 410 | unsigned int pcm_devs; |
| 411 | void *private_data; |
| 412 | |
| 413 | /* codec IO */ |
| 414 | void *control_data; /* codec control (i2c/3wire) data */ |
| 415 | unsigned int (*read)(struct snd_soc_codec *, unsigned int); |
| 416 | int (*write)(struct snd_soc_codec *, unsigned int, unsigned int); |
Mark Brown | 58cd33c | 2008-07-29 11:42:25 +0100 | [diff] [blame] | 417 | int (*display_register)(struct snd_soc_codec *, char *, |
| 418 | size_t, unsigned int); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 419 | hw_write_t hw_write; |
| 420 | hw_read_t hw_read; |
| 421 | void *reg_cache; |
| 422 | short reg_cache_size; |
| 423 | short reg_cache_step; |
| 424 | |
| 425 | /* dapm */ |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 426 | u32 pop_time; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 427 | struct list_head dapm_widgets; |
| 428 | struct list_head dapm_paths; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 429 | enum snd_soc_bias_level bias_level; |
| 430 | enum snd_soc_bias_level suspend_bias_level; |
Takashi Iwai | 1321b16 | 2006-12-21 11:02:06 +0100 | [diff] [blame] | 431 | struct delayed_work delayed_work; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 432 | |
| 433 | /* codec DAI's */ |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 434 | struct snd_soc_dai *dai; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 435 | unsigned int num_dai; |
| 436 | }; |
| 437 | |
| 438 | /* codec device */ |
| 439 | struct snd_soc_codec_device { |
| 440 | int (*probe)(struct platform_device *pdev); |
| 441 | int (*remove)(struct platform_device *pdev); |
| 442 | int (*suspend)(struct platform_device *pdev, pm_message_t state); |
| 443 | int (*resume)(struct platform_device *pdev); |
| 444 | }; |
| 445 | |
| 446 | /* SoC platform interface */ |
| 447 | struct snd_soc_platform { |
| 448 | char *name; |
| 449 | |
| 450 | int (*probe)(struct platform_device *pdev); |
| 451 | int (*remove)(struct platform_device *pdev); |
| 452 | int (*suspend)(struct platform_device *pdev, |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 453 | struct snd_soc_dai *dai); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 454 | int (*resume)(struct platform_device *pdev, |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 455 | struct snd_soc_dai *dai); |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 456 | |
| 457 | /* pcm creation and destruction */ |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 458 | int (*pcm_new)(struct snd_card *, struct snd_soc_dai *, |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 459 | struct snd_pcm *); |
| 460 | void (*pcm_free)(struct snd_pcm *); |
| 461 | |
| 462 | /* platform stream ops */ |
| 463 | struct snd_pcm_ops *pcm_ops; |
| 464 | }; |
| 465 | |
| 466 | /* SoC machine DAI configuration, glues a codec and cpu DAI together */ |
| 467 | struct snd_soc_dai_link { |
| 468 | char *name; /* Codec name */ |
| 469 | char *stream_name; /* Stream name */ |
| 470 | |
| 471 | /* DAI */ |
Liam Girdwood | 3c4b266 | 2008-07-07 16:07:17 +0100 | [diff] [blame] | 472 | struct snd_soc_dai *codec_dai; |
| 473 | struct snd_soc_dai *cpu_dai; |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 474 | |
| 475 | /* machine stream operations */ |
| 476 | struct snd_soc_ops *ops; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 477 | |
| 478 | /* codec/machine specific init - e.g. add machine controls */ |
| 479 | int (*init)(struct snd_soc_codec *codec); |
Liam Girdwood | 4ccab3e | 2008-01-10 14:39:01 +0100 | [diff] [blame] | 480 | |
| 481 | /* DAI pcm */ |
| 482 | struct snd_pcm *pcm; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 483 | }; |
| 484 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame^] | 485 | /* SoC card */ |
| 486 | struct snd_soc_card { |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 487 | char *name; |
| 488 | |
| 489 | int (*probe)(struct platform_device *pdev); |
| 490 | int (*remove)(struct platform_device *pdev); |
| 491 | |
| 492 | /* the pre and post PM functions are used to do any PM work before and |
| 493 | * after the codec and DAI's do any PM work. */ |
| 494 | int (*suspend_pre)(struct platform_device *pdev, pm_message_t state); |
| 495 | int (*suspend_post)(struct platform_device *pdev, pm_message_t state); |
| 496 | int (*resume_pre)(struct platform_device *pdev); |
| 497 | int (*resume_post)(struct platform_device *pdev); |
| 498 | |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 499 | /* callbacks */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame^] | 500 | int (*set_bias_level)(struct snd_soc_card *, |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 501 | enum snd_soc_bias_level level); |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 502 | |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 503 | /* CPU <--> Codec DAI links */ |
| 504 | struct snd_soc_dai_link *dai_link; |
| 505 | int num_links; |
| 506 | }; |
| 507 | |
| 508 | /* SoC Device - the audio subsystem */ |
| 509 | struct snd_soc_device { |
| 510 | struct device *dev; |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame^] | 511 | struct snd_soc_card *card; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 512 | struct snd_soc_platform *platform; |
| 513 | struct snd_soc_codec *codec; |
| 514 | struct snd_soc_codec_device *codec_dev; |
Andrew Morton | 4484bb2 | 2006-12-15 09:30:07 +0100 | [diff] [blame] | 515 | struct delayed_work delayed_work; |
Andy Green | 6ed2597 | 2008-06-13 16:24:05 +0100 | [diff] [blame] | 516 | struct work_struct deferred_resume_work; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 517 | void *codec_data; |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 518 | #ifdef CONFIG_DEBUG_FS |
| 519 | struct dentry *debugfs_root; |
| 520 | #endif |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | /* runtime channel data */ |
| 524 | struct snd_soc_pcm_runtime { |
Graeme Gregory | 1c433fb | 2007-02-02 17:13:05 +0100 | [diff] [blame] | 525 | struct snd_soc_dai_link *dai; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 526 | struct snd_soc_device *socdev; |
| 527 | }; |
| 528 | |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 529 | /* mixer control */ |
| 530 | struct soc_mixer_control { |
| 531 | int min, max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 532 | unsigned int reg, rreg, shift, rshift, invert; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 533 | }; |
| 534 | |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 535 | /* enumerated kcontrol */ |
| 536 | struct soc_enum { |
| 537 | unsigned short reg; |
| 538 | unsigned short reg2; |
| 539 | unsigned char shift_l; |
| 540 | unsigned char shift_r; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 541 | unsigned int max; |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 542 | const char **texts; |
| 543 | void *dapm; |
| 544 | }; |
| 545 | |
Richard Purdie | 808db4a | 2006-10-06 18:20:14 +0200 | [diff] [blame] | 546 | #endif |