summaryrefslogtreecommitdiff
path: root/sound/soc/tegra/tegra_soc.h
blob: 7e262bd2c34da2785b020498e149d857d45d1c64 (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
/*
 * tegra_soc.h  --  SoC audio for tegra
 *
* Copyright (c) 2009-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
 * version 2 as published by the Free Software Foundation.
 *
 * 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 St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 * */

#ifndef __TEGRA_AUDIO__
#define __TEGRA_AUDIO__

#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/jiffies.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include <linux/kthread.h>
#include <linux/moduleparam.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/tegra_audio.h>
#include <linux/regulator/consumer.h>
#include <mach/iomap.h>
#include <mach/audio_manager.h>
#include <mach/irqs.h>
#include <mach/pinmux.h>
#include <mach/audio.h>
#include <mach/tegra_das.h>
#include <mach/dma.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/initval.h>
#include <sound/soc.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc-dapm.h>
#include <sound/soc-dai.h>
#include <sound/tlv.h>
#include <asm/io.h>
#include <asm/mach-types.h>
#include <asm/hardware/scoop.h>

#ifdef CONFIG_HAS_WAKELOCK
#include <linux/wakelock.h>
#endif

#define STATE_INIT	0
#define STATE_ABORT	1
#define STATE_EXIT	2
#define STATE_EXITED	3
#define STATE_INVALID	4

#define I2S1_CLK 		11289600
#define I2S2_CLK 		2000000
#define TEGRA_DEFAULT_SR	44100
#define TEGRA_INT_I2SLOOPBACK_ON	1
#define TEGRA_INT_I2SLOOPBACK_OFF	0

#define TEGRA_SAMPLE_RATES (SNDRV_PCM_RATE_8000_96000)
#define TEGRA_VOICE_SAMPLE_RATES SNDRV_PCM_RATE_8000

#define DMA_STEP_SIZE_MIN 8
#define DMA_REQ_QCOUNT 2

#define TEGRA_AUDIO_OFF		0x0
#define TEGRA_HEADPHONE		0x1
#define TEGRA_LINEOUT		0x2
#define TEGRA_SPK		0x4
#define TEGRA_EAR_SPK		0x8
#define TEGRA_INT_MIC		0x10
#define TEGRA_EXT_MIC		0x20
#define TEGRA_LINEIN		0x40
#define TEGRA_HEADSET_OUT	0x80
#define TEGRA_HEADSET_IN	0x100

struct tegra_dma_channel;

struct tegra_runtime_data {
	struct snd_pcm_substream *substream;
	int size;
	int dma_pos;
	int dma_tail_idx;
	int dma_head_idx;
	int period_index;
	int dma_state;
	struct tegra_dma_req dma_req[DMA_REQ_QCOUNT];
	struct tegra_dma_channel *dma_chan;
#ifdef CONFIG_HAS_WAKELOCK
	struct wake_lock wake_lock;
	char wake_lock_name[32];
#endif
};

struct tegra_audio_data {
	struct snd_soc_codec *codec;
	struct clk *dap_mclk;
	bool init_done;

	int play_device;
	int capture_device;
	bool is_call_mode;

	int codec_con;
};

/* i2s controller */
struct tegra_i2s_info {
	struct platform_device *pdev;
	struct tegra_audio_platform_data *pdata;

	unsigned int bit_format;
	bool i2s_master;
	int ref_count;
	aud_dev_info  i2sdev_info;
	struct das_regs_cache das_regs;
};

void tegra_ext_control(struct snd_soc_codec *codec, int new_con);
int tegra_controls_init(struct snd_soc_codec *codec);

int tegra_jack_init(struct snd_soc_codec *codec);
void tegra_jack_exit(void);
void tegra_jack_resume(void);
void tegra_switch_set_state(int state);

void setup_i2s_dma_request(struct snd_pcm_substream *substream,
			struct tegra_dma_req *req,
			void (*dma_callback)(struct tegra_dma_req *req),
			void *dma_data);
void free_i2s_dma_request(struct snd_pcm_substream *substream);

void setup_spdif_dma_request(struct snd_pcm_substream *substream,
			struct tegra_dma_req *req,
			void (*dma_callback)(struct tegra_dma_req *req),
			void *dma_data);
void free_spdif_dma_request(struct snd_pcm_substream *substream);
#endif