1 /* SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Copyright (c) 2018 Baylibre SAS.
4 * Author: Jerome Brunet <jbrunet@baylibre.com>
7 #ifndef _MESON_AXG_TDM_H
8 #define _MESON_AXG_TDM_H
10 #include <linux/clk.h>
11 #include <linux/regmap.h>
12 #include <sound/pcm.h>
13 #include <sound/soc.h>
14 #include <sound/soc-dai.h>
16 #define AXG_TDM_NUM_LANES 4
17 #define AXG_TDM_CHANNEL_MAX 128
18 #define AXG_TDM_RATES (SNDRV_PCM_RATE_5512 | \
19 SNDRV_PCM_RATE_8000_192000)
20 #define AXG_TDM_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
21 SNDRV_PCM_FMTBIT_S16_LE | \
22 SNDRV_PCM_FMTBIT_S20_LE | \
23 SNDRV_PCM_FMTBIT_S24_LE | \
24 SNDRV_PCM_FMTBIT_S32_LE)
26 struct axg_tdm_iface
{
30 unsigned long mclk_rate
;
32 /* format is common to all the DAIs of the iface */
35 unsigned int slot_width
;
37 /* For component wide symmetry */
41 static inline bool axg_tdm_lrclk_invert(unsigned int fmt
)
43 return ((fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) == SND_SOC_DAIFMT_I2S
) ^
44 !!(fmt
& (SND_SOC_DAIFMT_IB_IF
| SND_SOC_DAIFMT_NB_IF
));
47 static inline bool axg_tdm_sclk_invert(unsigned int fmt
)
49 return fmt
& (SND_SOC_DAIFMT_IB_IF
| SND_SOC_DAIFMT_IB_NF
);
52 struct axg_tdm_stream
{
53 struct axg_tdm_iface
*iface
;
54 struct list_head formatter_list
;
56 unsigned int channels
;
58 unsigned int physical_width
;
63 struct axg_tdm_stream
*axg_tdm_stream_alloc(struct axg_tdm_iface
*iface
);
64 void axg_tdm_stream_free(struct axg_tdm_stream
*ts
);
65 int axg_tdm_stream_start(struct axg_tdm_stream
*ts
);
66 void axg_tdm_stream_stop(struct axg_tdm_stream
*ts
);
68 static inline int axg_tdm_stream_reset(struct axg_tdm_stream
*ts
)
70 axg_tdm_stream_stop(ts
);
71 return axg_tdm_stream_start(ts
);
74 int axg_tdm_set_tdm_slots(struct snd_soc_dai
*dai
, u32
*tx_mask
,
75 u32
*rx_mask
, unsigned int slots
,
76 unsigned int slot_width
);
78 #endif /* _MESON_AXG_TDM_H */