summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/include/mach/tegra_das.h
blob: 39fe1705324eddba02b53236a8e55b699d059978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
 * arch/arm/mach-tegra/include/mach/tegra_das.h
 *
 * Declarations of Tegra Digital Audio Switch (das)
 *
 * Copyright (c) 2010-2011, NVIDIA Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __MACH_TEGRA_DAS_H
#define __MACH_TEGRA_DAS_H

#include <linux/kernel.h>

/*
                            -----------------
                            |               |
                            |               |<----> DAP1
                DAC1 <----> |    Digital    |
    ---------               |               |<----> DAP2
    |       |               |     Audio     |
    | Tegra |   DAC2 <----> |               |<----> DAP3
    |  SoC  |               |    Switch     |
    |       |               |               |<----> DAP4
    ---------               |     (DAS)     |
                DAC3 <----> |               |<----> DAP5
                            |               |
                            |               |
                            -----------------

*/

#define APB_MISC_DAS_DAP_CTRL_SEL_0			(0xc00)
#define APB_MISC_DAS_DAP_CTRL_SEL_1			(0xc04)
#define APB_MISC_DAS_DAP_CTRL_SEL_2			(0xc08)
#define APB_MISC_DAS_DAP_CTRL_SEL_3			(0xc0c)
#define APB_MISC_DAS_DAP_CTRL_SEL_4			(0xc10)
#define APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_0		(0xc40)
#define APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_1		(0xc44)
#define APB_MISC_DAS_DAC_INPUT_DATA_CLK_SEL_2		(0xc48)

#define DAP_MS_SEL_SHIFT		(31)
#define DAP_MS_SEL_DEFAULT_MASK		(0x1)
#define DAP_SDATA1_TX_RX_SHIFT		(30)
#define DAP_SDATA1_TX_RX_DEFAULT_MASK	(0x1)
#define DAP_SDATA2_RX_TX_SHIFT		(29)
#define DAP_SDATA2_RX_TX_DEFAULT_MASK	(0x1)
#define DAP_CTRL_SEL_SHIFT		(0)
#define DAP_CTRL_SEL_DEFAULT_MASK	(0x1f)

#define DAC_SDATA2_SEL_SHIFT		(28)
#define DAC_SDATA2_SEL_DEFAULT_MASK	(0xf)
#define DAC_SDATA1_SEL_SHIFT		(24)
#define DAC_SDATA1_SEL_DEFAULT_MASK	(0xf)
#define DAC_CLK_SEL_SHIFT		(0)
#define DAC_CLK_SEL_DEFAULT_MASK	(0xf)


#define DAP_CTRL_SEL_DAC1		(0)
#define DAP_CTRL_SEL_DAC2		(1)
#define DAP_CTRL_SEL_DAC3		(2)
#define DAP_CTRL_SEL_DAP1		(16)
#define DAP_CTRL_SEL_DAP2		(17)
#define DAP_CTRL_SEL_DAP3		(18)
#define DAP_CTRL_SEL_DAP4		(19)
#define DAP_CTRL_SEL_DAP5		(20)

#define MAX_CONNECTIONLINES 8

typedef enum tegra_das_port_t {
	tegra_das_port_none = 0,
	tegra_das_port_dap1,
	tegra_das_port_dap2,
	tegra_das_port_dap3,
	tegra_das_port_dap4,
	tegra_das_port_dap5,
	tegra_das_port_i2s1,
	tegra_das_port_i2s2,
	tegra_das_port_ac97
} tegra_das_port;

#define MAX_DAP_PORTS	(tegra_das_port_dap5 + 1)

/* defines possible hardware connected to DAP */
enum tegra_audio_codec_type {
	tegra_audio_codec_type_none = 0,
	tegra_audio_codec_type_hifi,
	tegra_audio_codec_type_voice,
	tegra_audio_codec_type_bluetooth,
	tegra_audio_codec_type_baseband,
	tegra_audio_codec_type_fm_radio,
};

/* index for possible connection based on the use case */
enum tegra_das_port_con_id {
	tegra_das_port_con_id_none = 0,
	tegra_das_port_con_id_hifi,
	tegra_das_port_con_id_voice,
	tegra_das_port_con_id_analog_radio,
	tegra_das_port_con_id_digital_radio,
	tegra_das_port_con_id_bt_codec,
	tegra_das_port_con_id_voicecall_no_bt,
	tegra_das_port_con_id_voicecall_no_bt_record,
	tegra_das_port_con_id_voicecall_with_bt,
	tegra_das_port_con_id_voicecall_with_bt_record,

	tegra_das_port_con_id_max
};

/* data format supported */
enum dac_dap_data_format {
	dac_dap_data_format_none = 0x0,
	dac_dap_data_format_i2s = 0x1,
	dac_dap_data_format_dsp = 0x2,
	dac_dap_data_format_rjm = 0x4,
	dac_dap_data_format_ljm = 0x8,

	dac_dap_data_format_all = 0x7FFFFFFF
};

struct audio_dev_property {
	unsigned int num_channels;
	unsigned int bits_per_sample;
	unsigned int rate;
	unsigned int dac_dap_data_comm_format;
};

/*
 * structure which contains dap endpoint
 * dac_port contains dac port for particular dap and
 * codec_type contains possible codec which can be connected to dap port
 */
struct tegra_dap_property {
	tegra_das_port dac_port;
	tegra_das_port dap_port;
	enum  tegra_audio_codec_type codec_type;
	struct audio_dev_property device_property;
};

struct tegra_das_con_line {
	tegra_das_port src;
	tegra_das_port dest;
	bool src_master;
};

struct tegra_das_con {
	enum tegra_das_port_con_id con_id;
	unsigned int num_entries;
	struct tegra_das_con_line con_line[MAX_CONNECTIONLINES];
};

struct tegra_das_platform_data {
	void *driver_data;
	const char *dap_clk;
	const struct tegra_dap_property tegra_dap_port_info_table[MAX_DAP_PORTS];
	const struct tegra_das_con tegra_das_con_table[MAX_DAP_PORTS];
};

struct tegra_das_mux_select {
	tegra_das_port port_type;
	u32 reg_offset;
	u32 mux_mask;
	u32 mux_shift;
	u32 sdata1_mask;
	u32 sdata1_shift;
	u32 sdata2_mask;
	u32 sdata2_shift;
	u32 ms_mode_mask;
	u32 ms_mode_shift;
	u32 mux_value;
};

struct das_regs_cache {
	u32 das_dap_ctrl_0;
	u32 das_dap_ctrl_1;
	u32 das_dap_ctrl_2;
	u32 das_dap_ctrl_3;
	u32 das_dap_ctrl_4;
	u32 das_dac_input_data_clk_0;
	u32 das_dac_input_data_clk_1;
	u32 das_dac_input_data_clk_2;
};


int tegra_das_open(void);

int tegra_das_close(void);

/*
 * Function to make connections between dac and dap.
 * con_id specifies the enum depending on the required port connections
 * enable, if true do connections else disconnect
 */
int tegra_das_set_connection(enum tegra_das_port_con_id new_con_id);

/*
 * Function to get current port connection for das
 */
int tegra_das_get_connection(void);

/*
 * Function to query if certain das port need to be
 * configured as master for current das connection
 */
bool tegra_das_is_port_master(enum tegra_audio_codec_type codec_type);

/*
 * Function to get data format for certain codec for current das connection
 */
int tegra_das_get_codec_data_fmt(enum tegra_audio_codec_type codec_type);

/*
 * Function to get dap Mclk handle
 */
struct clk* tegra_das_get_dap_mclk(void);

/*
 * Function to set power state on das's dap port
 * if is_normal is true then power mode is normal else tristated
 */
int tegra_das_power_mode(bool is_normal);

/*
 * Function to get the content of all the das registers
 */
void tegra_das_get_all_regs(struct das_regs_cache* regs);

/*
 * Function to set values in all the das registers
 */
void tegra_das_set_all_regs(struct das_regs_cache* regs);

#endif