aboutsummaryrefslogtreecommitdiff
path: root/sound/soc/codecs/tfa9888_init.c
blob: 4140786bf13619a5dffbbdfd52ed1aacc7659a8a (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
/*
* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only 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.
*/

/*
 * initTfa9888.c
 *
 *  Created on: Jun 26, 2014
 *      Author: wim
 */

#include "tfa_dsp_fw.h"
#include "tfa_service.h"
#include "tfa_internal.h"

#include "tfa98xx_tfafieldnames.h"

static void tfa98xx_interrupt_setup_9888(unsigned int handle)
{
	uint16_t ie_reg;

	handles_local[handle].interrupt_enable[0] = 0;
	ie_reg = 0;
	TFA_SET_BF_VALUE(handle, IEMWSRC, 1, &ie_reg);
	handles_local[handle].interrupt_enable[1] = ie_reg;
	handles_local[handle].interrupt_enable[2] = 0;
}

static enum Tfa98xx_Error tfa9888_specific(Tfa98xx_handle_t handle)
{
	enum Tfa98xx_Error error = Tfa98xx_Error_Ok;
	unsigned short value, xor;

	if (!tfa98xx_handle_is_open(handle))
		return Tfa98xx_Error_NotOpen;

	if ((handles_local[handle].rev & 0xff) != 0x88) {
		pr_err("This code is not for this device type: %x\n", handles_local[handle].rev);
		return Tfa98xx_Error_Bad_Parameter;
	}

	/* Unlock keys to write settings */
	error = tfa98xx_write_register16(handle, 0x0F, 0x5A6B);
	error = tfa98xx_read_register16(handle, 0xFB, &value);
	xor = value ^ 0x005A;
	error = tfa98xx_write_register16(handle, 0xA0, xor);

	/* The optimal settings are different for 1c, 2c, 3b and 2b/1b */
	if (handles_local[handle].rev == 0x2c88) {
		/* ----- generated code start ----- */
		/* --------- Version v1 ---------- */
		tfa98xx_write_register16(handle, 0x00, 0x164d); /* POR=0x064d */
		tfa98xx_write_register16(handle, 0x01, 0x828b); /* POR=0x92cb */
		tfa98xx_write_register16(handle, 0x02, 0x1dc8); /* POR=0x1828 */
		tfa98xx_write_register16(handle, 0x0e, 0x0080); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x20, 0x089e); /* POR=0x0890 */
		tfa98xx_write_register16(handle, 0x22, 0x543c); /* POR=0x545c */
		tfa98xx_write_register16(handle, 0x23, 0x0006); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x24, 0x0014); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x25, 0x000a); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x26, 0x0100); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x28, 0x1000); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x51, 0x0000); /* POR=0x00c0 */
		tfa98xx_write_register16(handle, 0x52, 0xfafe); /* POR=0xbaf6 */
		tfa98xx_write_register16(handle, 0x70, 0x3ee4); /* POR=0x3ee6 */
		tfa98xx_write_register16(handle, 0x71, 0x1074); /* POR=0x3074 */
		tfa98xx_write_register16(handle, 0x83, 0x0014); /* POR=0x0013 */
		/* ----- generated code end   ----- */
	} else if (handles_local[handle].rev == 0x1c88) {
		/* ----- generated code start ----- */
		/* --------- Version v6 ---------- */
		tfa98xx_write_register16(handle, 0x00, 0x164d); /* POR=0x064d */
		tfa98xx_write_register16(handle, 0x01, 0x828b); /* POR=0x92cb */
		tfa98xx_write_register16(handle, 0x02, 0x1dc8); /* POR=0x1828 */
		tfa98xx_write_register16(handle, 0x0e, 0x0080); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x20, 0x089e); /* POR=0x0890 */
		tfa98xx_write_register16(handle, 0x22, 0x543c); /* POR=0x545c */
		tfa98xx_write_register16(handle, 0x23, 0x0006); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x24, 0x0014); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x25, 0x000a); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x26, 0x0100); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x28, 0x1000); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x51, 0x0000); /* POR=0x00c0 */
		tfa98xx_write_register16(handle, 0x52, 0xfafe); /* POR=0xbaf6 */
		tfa98xx_write_register16(handle, 0x70, 0x3ee4); /* POR=0x3ee6 */
		tfa98xx_write_register16(handle, 0x71, 0x1074); /* POR=0x3074 */
		tfa98xx_write_register16(handle, 0x83, 0x0014); /* POR=0x0013 */
		/* ----- generated code end   ----- */
	} else if (handles_local[handle].rev == 0x3b88) {
		/* ----- generated code start ----- */
		/* --------- Version v20 ---------- */
		tfa98xx_write_register16(handle, 0x01, 0x828b); /* POR=0x92cb */
		tfa98xx_write_register16(handle, 0x02, 0x1dc8); /* POR=0x1828 */
		tfa98xx_write_register16(handle, 0x20, 0x089e); /* POR=0x0890 */
		tfa98xx_write_register16(handle, 0x22, 0x543c); /* POR=0x545c */
		tfa98xx_write_register16(handle, 0x23, 0x0c06); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x24, 0x0014); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x25, 0x000a); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x26, 0x0100); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x28, 0x1000); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x51, 0x0000); /* POR=0x00c0 */
		tfa98xx_write_register16(handle, 0x52, 0xfafe); /* POR=0xbaf6 */
		tfa98xx_write_register16(handle, 0x58, 0x1e1c); /* POR=0x161c */
		tfa98xx_write_register16(handle, 0x70, 0x3ee4); /* POR=0x3ee6 */
		tfa98xx_write_register16(handle, 0x71, 0x1074); /* POR=0x3074 */
		tfa98xx_write_register16(handle, 0x83, 0x0014); /* POR=0x0013 */
		/* ----- generated code end   ----- */
	} else {
		/* If not 1c or 3b assume older version */
		/* ----- generated code start ----- */
		/* --------- Version v19 ---------- */
		tfa98xx_write_register16(handle, 0x00, 0x1e5d); /* POR=0x064d */
		tfa98xx_write_register16(handle, 0x01, 0x828b); /* POR=0x92cb */
		tfa98xx_write_register16(handle, 0x20, 0x089e); /* POR=0x0890 */
		tfa98xx_write_register16(handle, 0x23, 0x0c06); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x24, 0x0014); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x25, 0x000a); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x26, 0x0100); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x28, 0x1000); /* POR=0x0000 */
		tfa98xx_write_register16(handle, 0x51, 0x0000); /* POR=0x00c0 */
		tfa98xx_write_register16(handle, 0x52, 0x9ae2); /* POR=0xbaf6 */
		tfa98xx_write_register16(handle, 0x58, 0x1e1c); /* POR=0x161c */
		tfa98xx_write_register16(handle, 0x70, 0x3ce6); /* POR=0x3ee6 */
		tfa98xx_write_register16(handle, 0x71, 0x1074); /* POR=0x3074 */
		tfa98xx_write_register16(handle, 0x83, 0x0014); /* POR=0x0013 */
		/* ----- generated code end   ----- */
	}

	tfa98xx_interrupt_setup_9888(handle);

	return error;
}

static enum Tfa98xx_Error tfa9888_tfa_dsp_write_tables(Tfa98xx_handle_t handle, int sample_rate)
{
	unsigned char buffer[15] = {0};
	int size = 15 * sizeof(char);

	/* Write the fractional delay in the hardware register 'cs_frac_delay' */
	switch (sample_rate) {
	case 0:	/* 8kHz */
		TFA_SET_BF(handle, FRACTDEL, 40);
		break;
	case 1:	/* 11.025KHz */
		TFA_SET_BF(handle, FRACTDEL, 38);
		break;
	case 2:	/* 12kHz */
		TFA_SET_BF(handle, FRACTDEL, 37);
		break;
	case 3:	/* 16kHz */
		TFA_SET_BF(handle, FRACTDEL, 59);
		break;
	case 4:	/* 22.05KHz */
		TFA_SET_BF(handle, FRACTDEL, 56);
		break;
	case 5:	/* 24kHz */
		TFA_SET_BF(handle, FRACTDEL, 56);
		break;
	case 6:	/* 32kHz */
		TFA_SET_BF(handle, FRACTDEL, 52);
		break;
	case 7:	/* 44.1kHz */
		TFA_SET_BF(handle, FRACTDEL, 48);
		break;
	case 8:
	default:/* 48kHz */
		TFA_SET_BF(handle, FRACTDEL, 46);
		break;
	}

	/* First copy the msg_id to the buffer */
	buffer[0] = (uint8_t) 0;
	buffer[1] = (uint8_t) MODULE_FRAMEWORK + 128;
	buffer[2] = (uint8_t) FW_PAR_ID_SET_SENSES_DELAY;

	/* Required for all FS exept 8kHz (8kHz is all zero) */
	if (sample_rate != 0) {
		buffer[5] = 1;	/* Vdelay_P */
		buffer[8] = 0;	/* Idelay_P */
		buffer[11] = 1; /* Vdelay_S */
		buffer[14] = 0; /* Idelay_S */
	}

	/* send SetSensesDelay msg */
	return tfa_dsp_msg(handle, size, (char *)buffer);
}

/*
 * register device specifics functions
 */
void tfa9888_ops(struct tfa_device_ops *ops)
{
	ops->tfa_init = tfa9888_specific;
	ops->tfa_dsp_write_tables = tfa9888_tfa_dsp_write_tables;
}