axg-tdm.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. *
  3. * Copyright (c) 2018 Baylibre SAS.
  4. * Author: Jerome Brunet <jbrunet@baylibre.com>
  5. */
  6. #ifndef _MESON_AXG_TDM_H
  7. #define _MESON_AXG_TDM_H
  8. #include <linux/clk.h>
  9. #include <linux/regmap.h>
  10. #include <sound/pcm.h>
  11. #include <sound/soc.h>
  12. #include <sound/soc-dai.h>
  13. #define AXG_TDM_NUM_LANES 4
  14. #define AXG_TDM_CHANNEL_MAX 128
  15. #define AXG_TDM_RATES (SNDRV_PCM_RATE_5512 | \
  16. SNDRV_PCM_RATE_8000_192000)
  17. #define AXG_TDM_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
  18. SNDRV_PCM_FMTBIT_S16_LE | \
  19. SNDRV_PCM_FMTBIT_S20_LE | \
  20. SNDRV_PCM_FMTBIT_S24_LE | \
  21. SNDRV_PCM_FMTBIT_S32_LE)
  22. struct axg_tdm_iface {
  23. struct clk *sclk;
  24. struct clk *lrclk;
  25. struct clk *mclk;
  26. unsigned long mclk_rate;
  27. /* format is common to all the DAIs of the iface */
  28. unsigned int fmt;
  29. unsigned int slots;
  30. unsigned int slot_width;
  31. /* For component wide symmetry */
  32. int rate;
  33. };
  34. static inline bool axg_tdm_lrclk_invert(unsigned int fmt)
  35. {
  36. return ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S) ^
  37. !!(fmt & (SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_NB_IF));
  38. }
  39. static inline bool axg_tdm_sclk_invert(unsigned int fmt)
  40. {
  41. return fmt & (SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_IB_NF);
  42. }
  43. struct axg_tdm_stream {
  44. struct axg_tdm_iface *iface;
  45. struct list_head formatter_list;
  46. struct mutex lock;
  47. unsigned int channels;
  48. unsigned int width;
  49. unsigned int physical_width;
  50. u32 *mask;
  51. bool ready;
  52. };
  53. struct axg_tdm_stream *axg_tdm_stream_alloc(struct axg_tdm_iface *iface);
  54. void axg_tdm_stream_free(struct axg_tdm_stream *ts);
  55. int axg_tdm_stream_start(struct axg_tdm_stream *ts);
  56. void axg_tdm_stream_stop(struct axg_tdm_stream *ts);
  57. static inline int axg_tdm_stream_reset(struct axg_tdm_stream *ts)
  58. {
  59. axg_tdm_stream_stop(ts);
  60. return axg_tdm_stream_start(ts);
  61. }
  62. int axg_tdm_set_tdm_slots(struct snd_soc_dai *dai, u32 *tx_mask,
  63. u32 *rx_mask, unsigned int slots,
  64. unsigned int slot_width);
  65. #endif /* _MESON_AXG_TDM_H */