1/*
2 * HDIC HD29L2 DMB-TH demodulator driver
3 *
4 * Copyright (C) 2011 Metropolia University of Applied Sciences, Electria R&D
5 *
6 * Author: Antti Palosaari <crope@iki.fi>
7 *
8 *    This program is free software; you can redistribute it and/or modify
9 *    it under the terms of the GNU General Public License as published by
10 *    the Free Software Foundation; either version 2 of the License, or
11 *    (at your option) any later version.
12 *
13 *    This program is distributed in the hope that it will be useful,
14 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *    GNU General Public License for more details.
17 *
18 *    You should have received a copy of the GNU General Public License
19 *    along with this program; if not, write to the Free Software
20 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#ifndef HD29L2_PRIV
24#define HD29L2_PRIV
25
26#include <linux/dvb/version.h>
27#include "dvb_frontend.h"
28#include "dvb_math.h"
29#include "hd29l2.h"
30
31#define HD29L2_XTAL 30400000 /* Hz */
32
33
34#define HD29L2_QAM4NR 0x00
35#define HD29L2_QAM4   0x01
36#define HD29L2_QAM16  0x02
37#define HD29L2_QAM32  0x03
38#define HD29L2_QAM64  0x04
39
40#define HD29L2_CODE_RATE_04 0x00
41#define HD29L2_CODE_RATE_06 0x08
42#define HD29L2_CODE_RATE_08 0x10
43
44#define HD29L2_PN945 0x00
45#define HD29L2_PN595 0x01
46#define HD29L2_PN420 0x02
47
48#define HD29L2_CARRIER_SINGLE 0x00
49#define HD29L2_CARRIER_MULTI  0x01
50
51#define HD29L2_INTERLEAVER_720 0x00
52#define HD29L2_INTERLEAVER_420 0x01
53
54struct reg_val {
55	u8 reg;
56	u8 val;
57};
58
59struct reg_mod_vals {
60	u8 reg;
61	u8 val[5];
62};
63
64struct hd29l2_priv {
65	struct i2c_adapter *i2c;
66	struct dvb_frontend fe;
67	struct hd29l2_config cfg;
68	u8 tuner_i2c_addr_programmed:1;
69
70	fe_status_t fe_status;
71};
72
73static const struct reg_mod_vals reg_mod_vals_tab[] = {
74	/* REG, QAM4NR, QAM4,QAM16,QAM32,QAM64 */
75	{ 0x01, { 0x10, 0x10, 0x10, 0x10, 0x10 } },
76	{ 0x02, { 0x07, 0x07, 0x07, 0x07, 0x07 } },
77	{ 0x03, { 0x10, 0x10, 0x10, 0x10, 0x10 } },
78	{ 0x04, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
79	{ 0x05, { 0x61, 0x60, 0x60, 0x61, 0x60 } },
80	{ 0x06, { 0xff, 0xff, 0xff, 0xff, 0xff } },
81	{ 0x07, { 0xff, 0xff, 0xff, 0xff, 0xff } },
82	{ 0x08, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
83	{ 0x09, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
84	{ 0x0a, { 0x15, 0x15, 0x03, 0x03, 0x03 } },
85	{ 0x0d, { 0x78, 0x78, 0x88, 0x78, 0x78 } },
86	{ 0x0e, { 0xa0, 0x90, 0xa0, 0xa0, 0xa0 } },
87	{ 0x0f, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
88	{ 0x10, { 0xa0, 0xa0, 0x58, 0x38, 0x38 } },
89	{ 0x11, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
90	{ 0x12, { 0x5a, 0x5a, 0x5a, 0x5a, 0x5a } },
91	{ 0x13, { 0xa2, 0xa2, 0xa2, 0xa2, 0xa2 } },
92	{ 0x17, { 0x40, 0x40, 0x40, 0x40, 0x40 } },
93	{ 0x18, { 0x21, 0x21, 0x42, 0x52, 0x42 } },
94	{ 0x19, { 0x21, 0x21, 0x62, 0x72, 0x62 } },
95	{ 0x1a, { 0x32, 0x43, 0xa9, 0xb9, 0xa9 } },
96	{ 0x1b, { 0x32, 0x43, 0xb9, 0xd8, 0xb9 } },
97	{ 0x1c, { 0x02, 0x02, 0x03, 0x02, 0x03 } },
98	{ 0x1d, { 0x0c, 0x0c, 0x01, 0x02, 0x02 } },
99	{ 0x1e, { 0x02, 0x02, 0x02, 0x01, 0x02 } },
100	{ 0x1f, { 0x02, 0x02, 0x01, 0x02, 0x04 } },
101	{ 0x20, { 0x01, 0x02, 0x01, 0x01, 0x01 } },
102	{ 0x21, { 0x08, 0x08, 0x0a, 0x0a, 0x0a } },
103	{ 0x22, { 0x06, 0x06, 0x04, 0x05, 0x05 } },
104	{ 0x23, { 0x06, 0x06, 0x05, 0x03, 0x05 } },
105	{ 0x24, { 0x08, 0x08, 0x05, 0x07, 0x07 } },
106	{ 0x25, { 0x16, 0x10, 0x10, 0x0a, 0x10 } },
107	{ 0x26, { 0x14, 0x14, 0x04, 0x04, 0x04 } },
108	{ 0x27, { 0x58, 0x58, 0x58, 0x5c, 0x58 } },
109	{ 0x28, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
110	{ 0x29, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
111	{ 0x2a, { 0x08, 0x0a, 0x08, 0x08, 0x08 } },
112	{ 0x2b, { 0x08, 0x08, 0x08, 0x08, 0x08 } },
113	{ 0x2c, { 0x06, 0x06, 0x06, 0x06, 0x06 } },
114	{ 0x2d, { 0x05, 0x06, 0x06, 0x06, 0x06 } },
115	{ 0x2e, { 0x21, 0x21, 0x21, 0x21, 0x21 } },
116	{ 0x2f, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
117	{ 0x30, { 0x14, 0x14, 0x14, 0x14, 0x14 } },
118	{ 0x33, { 0xb7, 0xb7, 0xb7, 0xb7, 0xb7 } },
119	{ 0x34, { 0x81, 0x81, 0x81, 0x81, 0x81 } },
120	{ 0x35, { 0x80, 0x80, 0x80, 0x80, 0x80 } },
121	{ 0x37, { 0x70, 0x70, 0x70, 0x70, 0x70 } },
122	{ 0x38, { 0x04, 0x04, 0x02, 0x02, 0x02 } },
123	{ 0x39, { 0x07, 0x07, 0x05, 0x05, 0x05 } },
124	{ 0x3a, { 0x06, 0x06, 0x06, 0x06, 0x06 } },
125	{ 0x3b, { 0x03, 0x03, 0x03, 0x03, 0x03 } },
126	{ 0x3c, { 0x07, 0x06, 0x04, 0x04, 0x04 } },
127	{ 0x3d, { 0xf0, 0xf0, 0xf0, 0xf0, 0x80 } },
128	{ 0x3e, { 0x60, 0x60, 0x60, 0x60, 0xff } },
129	{ 0x3f, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
130	{ 0x40, { 0x5b, 0x5b, 0x5b, 0x57, 0x50 } },
131	{ 0x41, { 0x30, 0x30, 0x30, 0x30, 0x18 } },
132	{ 0x42, { 0x20, 0x20, 0x20, 0x00, 0x30 } },
133	{ 0x43, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
134	{ 0x44, { 0x3f, 0x3f, 0x3f, 0x3f, 0x3f } },
135	{ 0x45, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
136	{ 0x46, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
137	{ 0x47, { 0x00, 0x00, 0x95, 0x00, 0x95 } },
138	{ 0x48, { 0xc0, 0xc0, 0xc0, 0xc0, 0xc0 } },
139	{ 0x49, { 0xc0, 0xc0, 0xc0, 0xc0, 0xc0 } },
140	{ 0x4a, { 0x40, 0x40, 0x33, 0x11, 0x11 } },
141	{ 0x4b, { 0x40, 0x40, 0x00, 0x00, 0x00 } },
142	{ 0x4c, { 0x40, 0x40, 0x99, 0x11, 0x11 } },
143	{ 0x4d, { 0x40, 0x40, 0x00, 0x00, 0x00 } },
144	{ 0x4e, { 0x40, 0x40, 0x66, 0x77, 0x77 } },
145	{ 0x4f, { 0x40, 0x40, 0x00, 0x00, 0x00 } },
146	{ 0x50, { 0x40, 0x40, 0x88, 0x33, 0x11 } },
147	{ 0x51, { 0x40, 0x40, 0x00, 0x00, 0x00 } },
148	{ 0x52, { 0x40, 0x40, 0x88, 0x02, 0x02 } },
149	{ 0x53, { 0x40, 0x40, 0x00, 0x02, 0x02 } },
150	{ 0x54, { 0x00, 0x00, 0x88, 0x33, 0x33 } },
151	{ 0x55, { 0x40, 0x40, 0x00, 0x00, 0x00 } },
152	{ 0x56, { 0x00, 0x00, 0x00, 0x0b, 0x00 } },
153	{ 0x57, { 0x40, 0x40, 0x0a, 0x0b, 0x0a } },
154	{ 0x58, { 0xaa, 0x00, 0x00, 0x00, 0x00 } },
155	{ 0x59, { 0x7a, 0x40, 0x02, 0x02, 0x02 } },
156	{ 0x5a, { 0x18, 0x18, 0x01, 0x01, 0x01 } },
157	{ 0x5b, { 0x18, 0x18, 0x01, 0x01, 0x01 } },
158	{ 0x5c, { 0x18, 0x18, 0x01, 0x01, 0x01 } },
159	{ 0x5d, { 0x18, 0x18, 0x01, 0x01, 0x01 } },
160	{ 0x5e, { 0xc0, 0xc0, 0xc0, 0xff, 0xc0 } },
161	{ 0x5f, { 0xc0, 0xc0, 0xc0, 0xff, 0xc0 } },
162	{ 0x60, { 0x40, 0x40, 0x00, 0x30, 0x30 } },
163	{ 0x61, { 0x40, 0x40, 0x10, 0x30, 0x30 } },
164	{ 0x62, { 0x40, 0x40, 0x00, 0x30, 0x30 } },
165	{ 0x63, { 0x40, 0x40, 0x05, 0x30, 0x30 } },
166	{ 0x64, { 0x40, 0x40, 0x06, 0x00, 0x30 } },
167	{ 0x65, { 0x40, 0x40, 0x06, 0x08, 0x30 } },
168	{ 0x66, { 0x40, 0x40, 0x00, 0x00, 0x20 } },
169	{ 0x67, { 0x40, 0x40, 0x01, 0x04, 0x20 } },
170	{ 0x68, { 0x00, 0x00, 0x30, 0x00, 0x20 } },
171	{ 0x69, { 0xa0, 0xa0, 0x00, 0x08, 0x20 } },
172	{ 0x6a, { 0x00, 0x00, 0x30, 0x00, 0x25 } },
173	{ 0x6b, { 0xa0, 0xa0, 0x00, 0x06, 0x25 } },
174	{ 0x6c, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
175	{ 0x6d, { 0xa0, 0x60, 0x0c, 0x03, 0x0c } },
176	{ 0x6e, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
177	{ 0x6f, { 0xa0, 0x60, 0x04, 0x01, 0x04 } },
178	{ 0x70, { 0x58, 0x58, 0xaa, 0xaa, 0xaa } },
179	{ 0x71, { 0x58, 0x58, 0xaa, 0xaa, 0xaa } },
180	{ 0x72, { 0x58, 0x58, 0xff, 0xff, 0xff } },
181	{ 0x73, { 0x58, 0x58, 0xff, 0xff, 0xff } },
182	{ 0x74, { 0x06, 0x06, 0x09, 0x05, 0x05 } },
183	{ 0x75, { 0x06, 0x06, 0x0a, 0x10, 0x10 } },
184	{ 0x76, { 0x10, 0x10, 0x06, 0x0a, 0x0a } },
185	{ 0x77, { 0x12, 0x18, 0x28, 0x10, 0x28 } },
186	{ 0x78, { 0xf8, 0xf8, 0xf8, 0xf8, 0xf8 } },
187	{ 0x79, { 0x15, 0x15, 0x03, 0x03, 0x03 } },
188	{ 0x7a, { 0x02, 0x02, 0x01, 0x04, 0x03 } },
189	{ 0x7b, { 0x01, 0x02, 0x03, 0x03, 0x03 } },
190	{ 0x7c, { 0x28, 0x28, 0x28, 0x28, 0x28 } },
191	{ 0x7f, { 0x25, 0x92, 0x5f, 0x17, 0x2d } },
192	{ 0x80, { 0x64, 0x64, 0x64, 0x74, 0x64 } },
193	{ 0x83, { 0x06, 0x03, 0x04, 0x04, 0x04 } },
194	{ 0x84, { 0xff, 0xff, 0xff, 0xff, 0xff } },
195	{ 0x85, { 0x05, 0x05, 0x05, 0x05, 0x05 } },
196	{ 0x86, { 0x00, 0x00, 0x11, 0x11, 0x11 } },
197	{ 0x87, { 0x03, 0x03, 0x03, 0x03, 0x03 } },
198	{ 0x88, { 0x09, 0x09, 0x09, 0x09, 0x09 } },
199	{ 0x89, { 0x20, 0x20, 0x30, 0x20, 0x20 } },
200	{ 0x8a, { 0x03, 0x03, 0x02, 0x03, 0x02 } },
201	{ 0x8b, { 0x00, 0x07, 0x09, 0x00, 0x09 } },
202	{ 0x8c, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
203	{ 0x8d, { 0x4f, 0x4f, 0x4f, 0x3f, 0x4f } },
204	{ 0x8e, { 0xf0, 0xf0, 0x60, 0xf0, 0xa0 } },
205	{ 0x8f, { 0xe8, 0xe8, 0xe8, 0xe8, 0xe8 } },
206	{ 0x90, { 0x10, 0x10, 0x10, 0x10, 0x10 } },
207	{ 0x91, { 0x40, 0x40, 0x70, 0x70, 0x10 } },
208	{ 0x92, { 0x00, 0x00, 0x00, 0x00, 0x04 } },
209	{ 0x93, { 0x60, 0x60, 0x60, 0x60, 0x60 } },
210	{ 0x94, { 0x00, 0x00, 0x00, 0x00, 0x03 } },
211	{ 0x95, { 0x09, 0x09, 0x47, 0x47, 0x47 } },
212	{ 0x96, { 0x80, 0xa0, 0xa0, 0x40, 0xa0 } },
213	{ 0x97, { 0x60, 0x60, 0x60, 0x60, 0x60 } },
214	{ 0x98, { 0x50, 0x50, 0x50, 0x30, 0x50 } },
215	{ 0x99, { 0x10, 0x10, 0x10, 0x10, 0x10 } },
216	{ 0x9a, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
217	{ 0x9b, { 0x40, 0x40, 0x40, 0x30, 0x40 } },
218	{ 0x9c, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
219	{ 0xa0, { 0xf0, 0xf0, 0xf0, 0xf0, 0xf0 } },
220	{ 0xa1, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
221	{ 0xa2, { 0x30, 0x30, 0x00, 0x30, 0x00 } },
222	{ 0xa3, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
223	{ 0xa4, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
224	{ 0xa5, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
225	{ 0xa6, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
226	{ 0xa7, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
227	{ 0xa8, { 0x77, 0x77, 0x77, 0x77, 0x77 } },
228	{ 0xa9, { 0x02, 0x02, 0x02, 0x02, 0x02 } },
229	{ 0xaa, { 0x40, 0x40, 0x40, 0x40, 0x40 } },
230	{ 0xac, { 0x1f, 0x1f, 0x1f, 0x1f, 0x1f } },
231	{ 0xad, { 0x14, 0x14, 0x14, 0x14, 0x14 } },
232	{ 0xae, { 0x78, 0x78, 0x78, 0x78, 0x78 } },
233	{ 0xaf, { 0x06, 0x06, 0x06, 0x06, 0x07 } },
234	{ 0xb0, { 0x1b, 0x1b, 0x1b, 0x19, 0x1b } },
235	{ 0xb1, { 0x18, 0x17, 0x17, 0x18, 0x17 } },
236	{ 0xb2, { 0x35, 0x82, 0x82, 0x38, 0x82 } },
237	{ 0xb3, { 0xb6, 0xce, 0xc7, 0x5c, 0xb0 } },
238	{ 0xb4, { 0x3f, 0x3e, 0x3e, 0x3f, 0x3e } },
239	{ 0xb5, { 0x70, 0x58, 0x50, 0x68, 0x50 } },
240	{ 0xb6, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
241	{ 0xb7, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
242	{ 0xb8, { 0x03, 0x03, 0x01, 0x01, 0x01 } },
243	{ 0xb9, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
244	{ 0xba, { 0x06, 0x06, 0x0a, 0x05, 0x0a } },
245	{ 0xbb, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
246	{ 0xbc, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
247	{ 0xbd, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
248	{ 0xbe, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
249	{ 0xbf, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
250	{ 0xc0, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
251	{ 0xc1, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
252	{ 0xc2, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
253	{ 0xc3, { 0x00, 0x00, 0x88, 0x66, 0x88 } },
254	{ 0xc4, { 0x10, 0x10, 0x00, 0x00, 0x00 } },
255	{ 0xc5, { 0x00, 0x00, 0x44, 0x60, 0x44 } },
256	{ 0xc6, { 0x10, 0x0a, 0x00, 0x00, 0x00 } },
257	{ 0xc7, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
258	{ 0xc8, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
259	{ 0xc9, { 0x90, 0x04, 0x00, 0x00, 0x00 } },
260	{ 0xca, { 0x90, 0x08, 0x01, 0x01, 0x01 } },
261	{ 0xcb, { 0xa0, 0x04, 0x00, 0x44, 0x00 } },
262	{ 0xcc, { 0xa0, 0x10, 0x03, 0x00, 0x03 } },
263	{ 0xcd, { 0x06, 0x06, 0x06, 0x05, 0x06 } },
264	{ 0xce, { 0x05, 0x05, 0x01, 0x01, 0x01 } },
265	{ 0xcf, { 0x40, 0x20, 0x18, 0x18, 0x18 } },
266	{ 0xd0, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
267	{ 0xd1, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
268	{ 0xd2, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
269	{ 0xd3, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
270	{ 0xd4, { 0x05, 0x05, 0x05, 0x05, 0x05 } },
271	{ 0xd5, { 0x05, 0x05, 0x05, 0x03, 0x05 } },
272	{ 0xd6, { 0xac, 0x22, 0xca, 0x8f, 0xca } },
273	{ 0xd7, { 0x20, 0x20, 0x20, 0x20, 0x20 } },
274	{ 0xd8, { 0x01, 0x01, 0x01, 0x01, 0x01 } },
275	{ 0xd9, { 0x00, 0x00, 0x0f, 0x00, 0x0f } },
276	{ 0xda, { 0x00, 0xff, 0xff, 0x0e, 0xff } },
277	{ 0xdb, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
278	{ 0xdc, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
279	{ 0xdd, { 0x05, 0x05, 0x05, 0x05, 0x05 } },
280	{ 0xde, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
281	{ 0xdf, { 0x42, 0x42, 0x44, 0x44, 0x04 } },
282	{ 0xe0, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
283	{ 0xe1, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
284	{ 0xe2, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
285	{ 0xe3, { 0x00, 0x00, 0x26, 0x06, 0x26 } },
286	{ 0xe4, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
287	{ 0xe5, { 0x01, 0x0a, 0x01, 0x01, 0x01 } },
288	{ 0xe6, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
289	{ 0xe7, { 0x08, 0x08, 0x08, 0x08, 0x08 } },
290	{ 0xe8, { 0x63, 0x63, 0x63, 0x63, 0x63 } },
291	{ 0xe9, { 0x59, 0x59, 0x59, 0x59, 0x59 } },
292	{ 0xea, { 0x80, 0x80, 0x20, 0x80, 0x80 } },
293	{ 0xeb, { 0x37, 0x37, 0x78, 0x37, 0x77 } },
294	{ 0xec, { 0x1f, 0x1f, 0x25, 0x25, 0x25 } },
295	{ 0xed, { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a } },
296	{ 0xee, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
297	{ 0xef, { 0x70, 0x70, 0x58, 0x38, 0x58 } },
298	{ 0xf0, { 0x00, 0x00, 0x00, 0x00, 0x00 } },
299};
300
301#endif /* HD29L2_PRIV */
302