xref: /openbmc/linux/sound/soc/bcm/cygnus-ssp.h (revision 287dcc2b)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2014-2015 Broadcom Corporation */
3 #ifndef __CYGNUS_SSP_H__
4 #define __CYGNUS_SSP_H__
5 
6 #define CYGNUS_TDM_DAI_MAX_SLOTS 16
7 
8 #define CYGNUS_MAX_PLAYBACK_PORTS 4
9 #define CYGNUS_MAX_CAPTURE_PORTS 3
10 #define CYGNUS_MAX_I2S_PORTS 3
11 #define CYGNUS_MAX_PORTS  CYGNUS_MAX_PLAYBACK_PORTS
12 #define CYGNUS_AUIDO_MAX_NUM_CLKS 3
13 
14 #define CYGNUS_SSP_FRAMEBITS_DIV 1
15 
16 #define CYGNUS_SSPMODE_I2S 0
17 #define CYGNUS_SSPMODE_TDM 1
18 #define CYGNUS_SSPMODE_UNKNOWN -1
19 
20 #define CYGNUS_SSP_CLKSRC_PLL      0
21 
22 /* Max string length of our dt property names */
23 #define PROP_LEN_MAX 40
24 
25 struct ringbuf_regs {
26 	unsigned rdaddr;
27 	unsigned wraddr;
28 	unsigned baseaddr;
29 	unsigned endaddr;
30 	unsigned fmark;   /* freemark for play, fullmark for caputure */
31 	unsigned period_bytes;
32 	unsigned buf_size;
33 };
34 
35 #define RINGBUF_REG_PLAYBACK(num) ((struct ringbuf_regs) { \
36 	.rdaddr = SRC_RBUF_ ##num## _RDADDR_OFFSET, \
37 	.wraddr = SRC_RBUF_ ##num## _WRADDR_OFFSET, \
38 	.baseaddr = SRC_RBUF_ ##num## _BASEADDR_OFFSET, \
39 	.endaddr = SRC_RBUF_ ##num## _ENDADDR_OFFSET, \
40 	.fmark = SRC_RBUF_ ##num## _FREE_MARK_OFFSET, \
41 	.period_bytes = 0, \
42 	.buf_size = 0, \
43 })
44 
45 #define RINGBUF_REG_CAPTURE(num) ((struct ringbuf_regs)  { \
46 	.rdaddr = DST_RBUF_ ##num## _RDADDR_OFFSET, \
47 	.wraddr = DST_RBUF_ ##num## _WRADDR_OFFSET, \
48 	.baseaddr = DST_RBUF_ ##num## _BASEADDR_OFFSET, \
49 	.endaddr = DST_RBUF_ ##num## _ENDADDR_OFFSET, \
50 	.fmark = DST_RBUF_ ##num## _FULL_MARK_OFFSET, \
51 	.period_bytes = 0, \
52 	.buf_size = 0, \
53 })
54 
55 enum cygnus_audio_port_type {
56 	PORT_TDM,
57 	PORT_SPDIF,
58 };
59 
60 struct cygnus_ssp_regs {
61 	u32 i2s_stream_cfg;
62 	u32 i2s_cfg;
63 	u32 i2s_cap_stream_cfg;
64 	u32 i2s_cap_cfg;
65 	u32 i2s_mclk_cfg;
66 
67 	u32 bf_destch_ctrl;
68 	u32 bf_destch_cfg;
69 	u32 bf_sourcech_ctrl;
70 	u32 bf_sourcech_cfg;
71 	u32 bf_sourcech_grp;
72 };
73 
74 struct cygnus_track_clk {
75 	bool cap_en;
76 	bool play_en;
77 	bool cap_clk_en;
78 	bool play_clk_en;
79 };
80 
81 struct cygnus_aio_port {
82 	int portnum;
83 	int mode;
84 	bool is_slave;
85 	int streams_on;   /* will be 0 if both capture and play are off */
86 	int fsync_width;
87 	int port_type;
88 
89 	u32 mclk;
90 	u32 lrclk;
91 	u32 bit_per_frame;
92 	u32 pll_clk_num;
93 
94 	struct cygnus_audio *cygaud;
95 	struct cygnus_ssp_regs regs;
96 
97 	struct ringbuf_regs play_rb_regs;
98 	struct ringbuf_regs capture_rb_regs;
99 
100 	struct snd_pcm_substream *play_stream;
101 	struct snd_pcm_substream *capture_stream;
102 
103 	struct cygnus_track_clk clk_trace;
104 };
105 
106 
107 struct cygnus_audio {
108 	struct cygnus_aio_port  portinfo[CYGNUS_MAX_PORTS];
109 
110 	int irq_num;
111 	void __iomem *audio;
112 	struct device *dev;
113 	void __iomem *i2s_in;
114 
115 	struct clk *audio_clk[CYGNUS_AUIDO_MAX_NUM_CLKS];
116 	int active_ports;
117 	unsigned long vco_rate;
118 };
119 
120 extern int cygnus_ssp_get_mode(struct snd_soc_dai *cpu_dai);
121 extern int cygnus_ssp_add_pll_tweak_controls(struct snd_soc_pcm_runtime *rtd);
122 extern int cygnus_ssp_set_custom_fsync_width(struct snd_soc_dai *cpu_dai,
123 						int len);
124 extern int cygnus_soc_platform_register(struct device *dev,
125 					struct cygnus_audio *cygaud);
126 extern int cygnus_soc_platform_unregister(struct device *dev);
127 extern int cygnus_ssp_set_custom_fsync_width(struct snd_soc_dai *cpu_dai,
128 	int len);
129 #endif
130