soc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. #ifndef __LINUX_SND_SOC_H
  13. #define __LINUX_SND_SOC_H
  14. #include <linux/platform_device.h>
  15. #include <linux/types.h>
  16. #include <linux/workqueue.h>
  17. #include <sound/driver.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/control.h>
  21. #include <sound/ac97_codec.h>
  22. #define SND_SOC_VERSION "0.13.1"
  23. /*
  24. * Convenience kcontrol builders
  25. */
  26. #define SOC_SINGLE_VALUE(reg,shift,mask,invert) ((reg) | ((shift) << 8) |\
  27. ((shift) << 12) | ((mask) << 16) | ((invert) << 24))
  28. #define SOC_SINGLE_VALUE_EXT(reg,mask,invert) ((reg) | ((mask) << 16) |\
  29. ((invert) << 31))
  30. #define SOC_SINGLE(xname, reg, shift, mask, invert) \
  31. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  32. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  33. .put = snd_soc_put_volsw, \
  34. .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
  35. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
  36. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  37. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  38. .put = snd_soc_put_volsw, \
  39. .private_value = (reg) | ((shift_left) << 8) | \
  40. ((shift_right) << 12) | ((mask) << 16) | ((invert) << 24) }
  41. #define SOC_DOUBLE_R(xname, reg_left, reg_right, shift, mask, invert) \
  42. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  43. .info = snd_soc_info_volsw_2r, \
  44. .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
  45. .private_value = (reg_left) | ((shift) << 8) | \
  46. ((mask) << 12) | ((invert) << 20) | ((reg_right) << 24) }
  47. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xtexts) \
  48. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  49. .mask = xmask, .texts = xtexts }
  50. #define SOC_ENUM_SINGLE(xreg, xshift, xmask, xtexts) \
  51. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xtexts)
  52. #define SOC_ENUM_SINGLE_EXT(xmask, xtexts) \
  53. { .mask = xmask, .texts = xtexts }
  54. #define SOC_ENUM(xname, xenum) \
  55. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  56. .info = snd_soc_info_enum_double, \
  57. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  58. .private_value = (unsigned long)&xenum }
  59. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmask, xinvert,\
  60. xhandler_get, xhandler_put) \
  61. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  62. .info = snd_soc_info_volsw, \
  63. .get = xhandler_get, .put = xhandler_put, \
  64. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmask, xinvert) }
  65. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  66. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  67. .info = snd_soc_info_bool_ext, \
  68. .get = xhandler_get, .put = xhandler_put, \
  69. .private_value = xdata }
  70. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  71. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  72. .info = snd_soc_info_enum_ext, \
  73. .get = xhandler_get, .put = xhandler_put, \
  74. .private_value = (unsigned long)&xenum }
  75. /*
  76. * Digital Audio Interface (DAI) types
  77. */
  78. #define SND_SOC_DAI_AC97 0x1
  79. #define SND_SOC_DAI_I2S 0x2
  80. #define SND_SOC_DAI_PCM 0x4
  81. #define SND_SOC_DAI_AC97_BUS 0x8 /* for custom i.e. non ac97_codec.c */
  82. /*
  83. * DAI hardware audio formats
  84. */
  85. #define SND_SOC_DAIFMT_I2S 0 /* I2S mode */
  86. #define SND_SOC_DAIFMT_RIGHT_J 1 /* Right justified mode */
  87. #define SND_SOC_DAIFMT_LEFT_J 2 /* Left Justified mode */
  88. #define SND_SOC_DAIFMT_DSP_A 3 /* L data msb after FRM or LRC */
  89. #define SND_SOC_DAIFMT_DSP_B 4 /* L data msb during FRM or LRC */
  90. #define SND_SOC_DAIFMT_AC97 5 /* AC97 */
  91. #define SND_SOC_DAIFMT_MSB SND_SOC_DAIFMT_LEFT_J
  92. #define SND_SOC_DAIFMT_LSB SND_SOC_DAIFMT_RIGHT_J
  93. /*
  94. * DAI Gating
  95. */
  96. #define SND_SOC_DAIFMT_CONT (0 << 4) /* continuous clock */
  97. #define SND_SOC_DAIFMT_GATED (1 << 4) /* clock is gated when not Tx/Rx */
  98. /*
  99. * DAI hardware signal inversions
  100. */
  101. #define SND_SOC_DAIFMT_NB_NF (0 << 8) /* normal bit clock + frame */
  102. #define SND_SOC_DAIFMT_NB_IF (1 << 8) /* normal bclk + inv frm */
  103. #define SND_SOC_DAIFMT_IB_NF (2 << 8) /* invert bclk + nor frm */
  104. #define SND_SOC_DAIFMT_IB_IF (3 << 8) /* invert bclk + frm */
  105. /*
  106. * DAI hardware clock masters
  107. * This is wrt the codec, the inverse is true for the interface
  108. * i.e. if the codec is clk and frm master then the interface is
  109. * clk and frame slave.
  110. */
  111. #define SND_SOC_DAIFMT_CBM_CFM (0 << 12) /* codec clk & frm master */
  112. #define SND_SOC_DAIFMT_CBS_CFM (1 << 12) /* codec clk slave & frm master */
  113. #define SND_SOC_DAIFMT_CBM_CFS (2 << 12) /* codec clk master & frame slave */
  114. #define SND_SOC_DAIFMT_CBS_CFS (3 << 12) /* codec clk & frm slave */
  115. #define SND_SOC_DAIFMT_FORMAT_MASK 0x000f
  116. #define SND_SOC_DAIFMT_CLOCK_MASK 0x00f0
  117. #define SND_SOC_DAIFMT_INV_MASK 0x0f00
  118. #define SND_SOC_DAIFMT_MASTER_MASK 0xf000
  119. /*
  120. * Master Clock Directions
  121. */
  122. #define SND_SOC_CLOCK_IN 0
  123. #define SND_SOC_CLOCK_OUT 1
  124. /*
  125. * AC97 codec ID's bitmask
  126. */
  127. #define SND_SOC_DAI_AC97_ID0 (1 << 0)
  128. #define SND_SOC_DAI_AC97_ID1 (1 << 1)
  129. #define SND_SOC_DAI_AC97_ID2 (1 << 2)
  130. #define SND_SOC_DAI_AC97_ID3 (1 << 3)
  131. struct snd_soc_device;
  132. struct snd_soc_pcm_stream;
  133. struct snd_soc_ops;
  134. struct snd_soc_dai_mode;
  135. struct snd_soc_pcm_runtime;
  136. struct snd_soc_codec_dai;
  137. struct snd_soc_cpu_dai;
  138. struct snd_soc_codec;
  139. struct snd_soc_machine_config;
  140. struct soc_enum;
  141. struct snd_soc_ac97_ops;
  142. struct snd_soc_clock_info;
  143. typedef int (*hw_write_t)(void *,const char* ,int);
  144. typedef int (*hw_read_t)(void *,char* ,int);
  145. extern struct snd_ac97_bus_ops soc_ac97_ops;
  146. /* pcm <-> DAI connect */
  147. void snd_soc_free_pcms(struct snd_soc_device *socdev);
  148. int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid);
  149. int snd_soc_register_card(struct snd_soc_device *socdev);
  150. /* set runtime hw params */
  151. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  152. const struct snd_pcm_hardware *hw);
  153. /* codec IO */
  154. #define snd_soc_read(codec, reg) codec->read(codec, reg)
  155. #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
  156. /* codec register bit access */
  157. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  158. unsigned short mask, unsigned short value);
  159. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  160. unsigned short mask, unsigned short value);
  161. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  162. struct snd_ac97_bus_ops *ops, int num);
  163. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  164. /*
  165. *Controls
  166. */
  167. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  168. void *data, char *long_name);
  169. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  170. struct snd_ctl_elem_info *uinfo);
  171. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  172. struct snd_ctl_elem_info *uinfo);
  173. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  174. struct snd_ctl_elem_value *ucontrol);
  175. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  176. struct snd_ctl_elem_value *ucontrol);
  177. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  178. struct snd_ctl_elem_info *uinfo);
  179. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  180. struct snd_ctl_elem_info *uinfo);
  181. int snd_soc_info_bool_ext(struct snd_kcontrol *kcontrol,
  182. struct snd_ctl_elem_info *uinfo);
  183. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  184. struct snd_ctl_elem_value *ucontrol);
  185. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  186. struct snd_ctl_elem_value *ucontrol);
  187. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  188. struct snd_ctl_elem_info *uinfo);
  189. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  190. struct snd_ctl_elem_value *ucontrol);
  191. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  192. struct snd_ctl_elem_value *ucontrol);
  193. /* SoC PCM stream information */
  194. struct snd_soc_pcm_stream {
  195. char *stream_name;
  196. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  197. unsigned int rates; /* SNDRV_PCM_RATE_* */
  198. unsigned int rate_min; /* min rate */
  199. unsigned int rate_max; /* max rate */
  200. unsigned int channels_min; /* min channels */
  201. unsigned int channels_max; /* max channels */
  202. unsigned int active:1; /* stream is in use */
  203. };
  204. /* SoC audio ops */
  205. struct snd_soc_ops {
  206. int (*startup)(struct snd_pcm_substream *);
  207. void (*shutdown)(struct snd_pcm_substream *);
  208. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  209. int (*hw_free)(struct snd_pcm_substream *);
  210. int (*prepare)(struct snd_pcm_substream *);
  211. int (*trigger)(struct snd_pcm_substream *, int);
  212. };
  213. /* ASoC codec DAI ops */
  214. struct snd_soc_codec_ops {
  215. /* codec DAI clocking configuration */
  216. int (*set_sysclk)(struct snd_soc_codec_dai *codec_dai,
  217. int clk_id, unsigned int freq, int dir);
  218. int (*set_pll)(struct snd_soc_codec_dai *codec_dai,
  219. int pll_id, unsigned int freq_in, unsigned int freq_out);
  220. int (*set_clkdiv)(struct snd_soc_codec_dai *codec_dai,
  221. int div_id, int div);
  222. /* CPU DAI format configuration */
  223. int (*set_fmt)(struct snd_soc_codec_dai *codec_dai,
  224. unsigned int fmt);
  225. int (*set_tdm_slot)(struct snd_soc_codec_dai *codec_dai,
  226. unsigned int mask, int slots);
  227. int (*set_tristate)(struct snd_soc_codec_dai *, int tristate);
  228. /* digital mute */
  229. int (*digital_mute)(struct snd_soc_codec_dai *, int mute);
  230. };
  231. /* ASoC cpu DAI ops */
  232. struct snd_soc_cpu_ops {
  233. /* CPU DAI clocking configuration */
  234. int (*set_sysclk)(struct snd_soc_cpu_dai *cpu_dai,
  235. int clk_id, unsigned int freq, int dir);
  236. int (*set_clkdiv)(struct snd_soc_cpu_dai *cpu_dai,
  237. int div_id, int div);
  238. int (*set_pll)(struct snd_soc_cpu_dai *cpu_dai,
  239. int pll_id, unsigned int freq_in, unsigned int freq_out);
  240. /* CPU DAI format configuration */
  241. int (*set_fmt)(struct snd_soc_cpu_dai *cpu_dai,
  242. unsigned int fmt);
  243. int (*set_tdm_slot)(struct snd_soc_cpu_dai *cpu_dai,
  244. unsigned int mask, int slots);
  245. int (*set_tristate)(struct snd_soc_cpu_dai *, int tristate);
  246. };
  247. /* SoC Codec DAI */
  248. struct snd_soc_codec_dai {
  249. char *name;
  250. int id;
  251. unsigned char type;
  252. /* DAI capabilities */
  253. struct snd_soc_pcm_stream playback;
  254. struct snd_soc_pcm_stream capture;
  255. /* DAI runtime info */
  256. struct snd_soc_codec *codec;
  257. unsigned int active;
  258. unsigned char pop_wait:1;
  259. /* ops */
  260. struct snd_soc_ops ops;
  261. struct snd_soc_codec_ops dai_ops;
  262. /* DAI private data */
  263. void *private_data;
  264. };
  265. /* SoC CPU DAI */
  266. struct snd_soc_cpu_dai {
  267. /* DAI description */
  268. char *name;
  269. unsigned int id;
  270. unsigned char type;
  271. /* DAI callbacks */
  272. int (*probe)(struct platform_device *pdev);
  273. void (*remove)(struct platform_device *pdev);
  274. int (*suspend)(struct platform_device *pdev,
  275. struct snd_soc_cpu_dai *cpu_dai);
  276. int (*resume)(struct platform_device *pdev,
  277. struct snd_soc_cpu_dai *cpu_dai);
  278. /* ops */
  279. struct snd_soc_ops ops;
  280. struct snd_soc_cpu_ops dai_ops;
  281. /* DAI capabilities */
  282. struct snd_soc_pcm_stream capture;
  283. struct snd_soc_pcm_stream playback;
  284. /* DAI runtime info */
  285. struct snd_pcm_runtime *runtime;
  286. unsigned char active:1;
  287. void *dma_data;
  288. /* DAI private data */
  289. void *private_data;
  290. };
  291. /* SoC Audio Codec */
  292. struct snd_soc_codec {
  293. char *name;
  294. struct module *owner;
  295. struct mutex mutex;
  296. /* callbacks */
  297. int (*dapm_event)(struct snd_soc_codec *codec, int event);
  298. /* runtime */
  299. struct snd_card *card;
  300. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  301. unsigned int active;
  302. unsigned int pcm_devs;
  303. void *private_data;
  304. /* codec IO */
  305. void *control_data; /* codec control (i2c/3wire) data */
  306. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  307. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  308. hw_write_t hw_write;
  309. hw_read_t hw_read;
  310. void *reg_cache;
  311. short reg_cache_size;
  312. short reg_cache_step;
  313. /* dapm */
  314. struct list_head dapm_widgets;
  315. struct list_head dapm_paths;
  316. unsigned int dapm_state;
  317. unsigned int suspend_dapm_state;
  318. struct delayed_work delayed_work;
  319. /* codec DAI's */
  320. struct snd_soc_codec_dai *dai;
  321. unsigned int num_dai;
  322. };
  323. /* codec device */
  324. struct snd_soc_codec_device {
  325. int (*probe)(struct platform_device *pdev);
  326. int (*remove)(struct platform_device *pdev);
  327. int (*suspend)(struct platform_device *pdev, pm_message_t state);
  328. int (*resume)(struct platform_device *pdev);
  329. };
  330. /* SoC platform interface */
  331. struct snd_soc_platform {
  332. char *name;
  333. int (*probe)(struct platform_device *pdev);
  334. int (*remove)(struct platform_device *pdev);
  335. int (*suspend)(struct platform_device *pdev,
  336. struct snd_soc_cpu_dai *cpu_dai);
  337. int (*resume)(struct platform_device *pdev,
  338. struct snd_soc_cpu_dai *cpu_dai);
  339. /* pcm creation and destruction */
  340. int (*pcm_new)(struct snd_card *, struct snd_soc_codec_dai *,
  341. struct snd_pcm *);
  342. void (*pcm_free)(struct snd_pcm *);
  343. /* platform stream ops */
  344. struct snd_pcm_ops *pcm_ops;
  345. };
  346. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  347. struct snd_soc_dai_link {
  348. char *name; /* Codec name */
  349. char *stream_name; /* Stream name */
  350. /* DAI */
  351. struct snd_soc_codec_dai *codec_dai;
  352. struct snd_soc_cpu_dai *cpu_dai;
  353. /* machine stream operations */
  354. struct snd_soc_ops *ops;
  355. /* codec/machine specific init - e.g. add machine controls */
  356. int (*init)(struct snd_soc_codec *codec);
  357. };
  358. /* SoC machine */
  359. struct snd_soc_machine {
  360. char *name;
  361. int (*probe)(struct platform_device *pdev);
  362. int (*remove)(struct platform_device *pdev);
  363. /* the pre and post PM functions are used to do any PM work before and
  364. * after the codec and DAI's do any PM work. */
  365. int (*suspend_pre)(struct platform_device *pdev, pm_message_t state);
  366. int (*suspend_post)(struct platform_device *pdev, pm_message_t state);
  367. int (*resume_pre)(struct platform_device *pdev);
  368. int (*resume_post)(struct platform_device *pdev);
  369. /* CPU <--> Codec DAI links */
  370. struct snd_soc_dai_link *dai_link;
  371. int num_links;
  372. };
  373. /* SoC Device - the audio subsystem */
  374. struct snd_soc_device {
  375. struct device *dev;
  376. struct snd_soc_machine *machine;
  377. struct snd_soc_platform *platform;
  378. struct snd_soc_codec *codec;
  379. struct snd_soc_codec_device *codec_dev;
  380. struct delayed_work delayed_work;
  381. void *codec_data;
  382. };
  383. /* runtime channel data */
  384. struct snd_soc_pcm_runtime {
  385. struct snd_soc_dai_link *dai;
  386. struct snd_soc_device *socdev;
  387. };
  388. /* enumerated kcontrol */
  389. struct soc_enum {
  390. unsigned short reg;
  391. unsigned short reg2;
  392. unsigned char shift_l;
  393. unsigned char shift_r;
  394. unsigned int mask;
  395. const char **texts;
  396. void *dapm;
  397. };
  398. #endif