-
Notifications
You must be signed in to change notification settings - Fork 1
/
rt5671_ioctl.c
223 lines (201 loc) · 5.69 KB
/
rt5671_ioctl.c
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
/* LGE_CHANGE_S
* Comment : add realtek alsa sound driver for woden R2
* 2013-03-05, [email protected]
*/
/*
* rt5671_ioctl.h -- RT5671 ALSA SoC audio driver IO control
*
* Copyright 2012 Realtek Microelectronics
* Author: Bard <[email protected]>
*
* 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.
*/
#include <linux/spi/spi.h>
#include <sound/soc.h>
#include "rt_codec_ioctl.h"
#include "rt5671_ioctl.h"
#include "rt5671.h"
#include "rt5671-dsp.h"
hweq_t hweq_param[] = {
{/* NORMAL */
{0},
{0},
0x0000,
},
{/* SPK */
{0},
{0x1bbc, 0x0c73, 0x030b, 0xff24, 0x1ea6, 0xe4d9, 0x1c98, 0x589d,
0x01bd, 0xd344, 0x01ca, 0x2940, 0xd8cb, 0x1bbc, 0x0000, 0xef01,
0x1bbc, 0x0000, 0xef01, 0x1bbc, 0x0000, 0x0257, 0x0000, 0x1cc9,
0x02eb, 0x1cee, 0x0800, 0x0800},
0x0000,
},
{/* HP */
{0},
{0x1bbc, 0x0c73, 0x030b, 0xff24, 0x1ea6, 0xe4d9, 0x1c98, 0x589d,
0x01bd, 0xd344, 0x01ca, 0x2940, 0xd8cb, 0x1bbc, 0x0000, 0xef01,
0x1bbc, 0x0000, 0xef01, 0x1bbc, 0x0000, 0x0257, 0x0000, 0x1cc9,
0x02eb, 0x1cee, 0x0800, 0x0800},
0x0000,
},
{/* ADC_TYPE1 */
{0},
{0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4,
0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0x1c10, 0x01f4,
0x0800, 0x0800},
0x0000,
},
{/* ADC_TYPE2 */
{0},
{0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4,
0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0x1c10, 0x01f4,
0x0800, 0x0800},
0x0000,
},
{/* ADC_TYPE3 */
{0},
{0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4,
0xe904, 0x1c10, 0x01f4, 0xe904, 0x1c10, 0x01f4, 0x1c10, 0x01f4,
0x0800, 0x0800},
0x0000,
},
};
#define RT5671_HWEQ_LEN ARRAY_SIZE(hweq_param)
int eqreg[EQ_CH_NUM][EQ_REG_NUM] = {
{0xa4, 0xa5, 0xeb, 0xec, 0xed, 0xee, 0xe7, 0xe8, 0xe9, 0xea, 0xe5,
0xe6, 0xae, 0xaf, 0xb0, 0xb4, 0xb5, 0xb6, 0xba, 0xbb, 0xbc, 0xc0,
0xc1, 0xc4, 0xc5, 0xc6, 0xca, 0xcc},
{0xa6, 0xa7, 0xf5, 0xf6, 0xf7, 0xf8, 0xf1, 0xf2, 0xf3, 0xf4, 0xef,
0xf0, 0xb1, 0xb2, 0xb3, 0xb7, 0xb8, 0xb9, 0xbd, 0xbe, 0xbf, 0xc2,
0xc3, 0xc7, 0xc8, 0xc9, 0xcb, 0xcd},
{0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xe1, 0xe2},
};
hwalc_t hwalc_param[] = {
/* 0xb2, 0xb3, 0xb5, 0xb6, 0xb7, 0xb4 */
{/* ALC_NORMAL */
{0x0000, 0x001f, 0x1f00, 0x0000, 0x0000, 0x2206},
},
{/* ALC_TYPE1 */
{0x0000, 0x001f, 0x1f00, 0x0000, 0x0000, 0x2206},
},
{/* ALC_TYPE2 */
{0x0000, 0x001f, 0x1f00, 0x0000, 0x0000, 0x2206},
},
{/* ALC_TYPE3 */
{0x0000, 0x001f, 0x1f00, 0x0000, 0x0000, 0x2206},
},
};
#define RT5671_HWALC_LEN ARRAY_SIZE(hwalc_param)
int alcreg[ALC_REG_NUM] = {0xb2, 0xb3, 0xb5, 0xb6, 0xb7, 0xb4};
int rt5671_update_eqmode(
struct snd_soc_codec *codec, int channel, int mode)
{
struct rt_codec_ops *ioctl_ops = rt_codec_get_ioctl_ops();
int i, upd_reg, reg, mask;
if (codec == NULL || mode >= RT5671_HWEQ_LEN)
return -EINVAL;
dev_dbg(codec->dev, "%s(): mode=%d\n", __func__, mode);
if (mode != NORMAL) {
for (i = 0; i <= EQ_REG_NUM; i++) {
hweq_param[mode].reg[i] = eqreg[channel][i];
}
for (i = 0; i <= EQ_REG_NUM; i++) {
if (hweq_param[mode].reg[i])
ioctl_ops->index_write(codec, hweq_param[mode].reg[i],
hweq_param[mode].value[i]);
else
break;
}
}
switch (channel) {
case EQ_CH_DACL:
reg = RT5671_EQ_CTRL2;
mask = 0x11fe;
upd_reg = RT5671_EQ_CTRL1;
break;
case EQ_CH_DACR:
reg = RT5671_EQ_CTRL2;
mask = 0x22fe;
upd_reg = RT5671_EQ_CTRL1;
break;
case EQ_CH_ADC:
reg = RT5671_ADC_EQ_CTRL2;
mask = 0x01bf;
upd_reg = RT5671_ADC_EQ_CTRL1;
break;
default:
printk(KERN_ERR "Invalid EQ channel\n");
return -EINVAL;
}
snd_soc_update_bits(codec, reg, mask, hweq_param[mode].ctrl);
snd_soc_update_bits(codec, upd_reg,
RT5671_EQ_UPD, RT5671_EQ_UPD);
snd_soc_update_bits(codec, upd_reg, RT5671_EQ_UPD, 0);
return 0;
}
int rt5671_update_alcmode(struct snd_soc_codec *codec, int mode)
{
int i;
if (codec == NULL || mode >= RT5671_HWALC_LEN)
return -EINVAL;
dev_dbg(codec->dev, "%s(): mode=%d\n", __func__, mode);
for (i = 0; i < ALC_REG_NUM - 1; i++)
snd_soc_write(codec, alcreg[i], hwalc_param[mode].value[i]);
snd_soc_write(codec, alcreg[i],
hwalc_param[mode].value[i] | RT5671_DRC_AGC_UPD);
return 0;
}
int rt5671_ioctl_common(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct snd_soc_codec *codec = hw->private_data;
struct rt_codec_cmd __user *_rt_codec = (struct rt_codec_cmd *)arg;
struct rt_codec_cmd rt_codec;
int *buf;
static int eq_mode[EQ_CH_NUM];
if (copy_from_user(&rt_codec, _rt_codec, sizeof(rt_codec))) {
dev_err(codec->dev, "copy_from_user faild\n");
return -EFAULT;
}
dev_dbg(codec->dev, "%s(): rt_codec.number=%d, cmd=%d\n",
__func__, rt_codec.number, cmd);
buf = kmalloc(sizeof(*buf) * rt_codec.number, GFP_KERNEL);
if (buf == NULL)
return -ENOMEM;
if (copy_from_user(buf, rt_codec.buf,
sizeof(*buf) * rt_codec.number))
goto err;
switch (cmd) {
case RT_SET_CODEC_HWEQ_IOCTL:
if (*buf >= EQ_CH_NUM)
break;
if (eq_mode[*buf] == *(buf + 1))
break;
eq_mode[*buf] = *(buf + 1);
rt5671_update_eqmode(codec, eq_mode[*buf], *buf);
break;
case RT_GET_CODEC_ID:
*buf = snd_soc_read(codec, RT5671_VENDOR_ID2);
if (copy_to_user(rt_codec.buf, buf,
sizeof(*buf) * rt_codec.number))
goto err;
break;
case RT_READ_CODEC_DSP_IOCTL:
case RT_WRITE_CODEC_DSP_IOCTL:
case RT_GET_CODEC_DSP_MODE_IOCTL:
return rt5671_dsp_ioctl_common(hw, file, cmd, arg);
break;
default:
break;
}
kfree(buf);
return 0;
err:
kfree(buf);
return -EFAULT;
}
EXPORT_SYMBOL_GPL(rt5671_ioctl_common);
/* LGE_CHANGE_E */