diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2006-09-23 19:40:20 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2007-02-21 10:34:50 -0500 |
commit | 017cf012570c955c3e1ff025802d7cb46fd1d37b (patch) | |
tree | 7cceec55fdfdbc40751198d267c89f8ea13473bd /drivers/media/dvb/frontends/qt1010.h | |
parent | 2a2bfa7d61b29170b7f9bbf42712a77229e6b935 (diff) |
V4L/DVB (5129): M920x: break out qt1010 tuner code into a separate file
qt1010 is a tuner used in some other devices, so this code should be put
into a separate file so that it could be reused by other drivers.
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/frontends/qt1010.h')
-rw-r--r-- | drivers/media/dvb/frontends/qt1010.h | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/qt1010.h b/drivers/media/dvb/frontends/qt1010.h new file mode 100644 index 000000000000..e526e3c23265 --- /dev/null +++ b/drivers/media/dvb/frontends/qt1010.h | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | * qt1010.h - DVB-T Tuner support | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #ifndef _QT1010_H_ | ||
20 | #define _QT1010_H_ | ||
21 | |||
22 | #define QT1010_W 0 | ||
23 | #define QT1010_R 1 | ||
24 | /* Not actual hw limits. */ | ||
25 | #define QT1010_MIN_STEP 2000000 | ||
26 | #define QT1010_MIN_FREQ 48000000 | ||
27 | |||
28 | static int qt1010_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8 *buf, int buf_len) | ||
29 | { | ||
30 | int i; | ||
31 | int div, mod; | ||
32 | struct { | ||
33 | u8 read, reg, value; | ||
34 | } rd[46] = { { QT1010_W, 0x01, 0x80 }, | ||
35 | { QT1010_W, 0x02, 0x3f }, | ||
36 | { QT1010_W, 0x05, 0xff }, /* c */ | ||
37 | { QT1010_W, 0x06, 0x44 }, | ||
38 | { QT1010_W, 0x07, 0xff }, /* c */ | ||
39 | { QT1010_W, 0x08, 0x08 }, | ||
40 | { QT1010_W, 0x09, 0xff }, /* c */ | ||
41 | { QT1010_W, 0x0a, 0xff }, /* c */ | ||
42 | { QT1010_W, 0x0b, 0xff }, /* c */ | ||
43 | { QT1010_W, 0x0c, 0xe1 }, | ||
44 | { QT1010_W, 0x1a, 0xff }, /* 10 c */ | ||
45 | { QT1010_W, 0x1b, 0x00 }, | ||
46 | { QT1010_W, 0x1c, 0x89 }, | ||
47 | { QT1010_W, 0x11, 0xff }, /* c */ | ||
48 | { QT1010_W, 0x12, 0x91 }, | ||
49 | { QT1010_W, 0x22, 0xff }, /* c */ | ||
50 | { QT1010_W, 0x1e, 0x00 }, | ||
51 | { QT1010_W, 0x1e, 0xd0 }, | ||
52 | { QT1010_R, 0x22, 0xff }, /* c read */ | ||
53 | { QT1010_W, 0x1e, 0x00 }, | ||
54 | { QT1010_R, 0x05, 0xff }, /* 20 c read */ | ||
55 | { QT1010_R, 0x22, 0xff }, /* c read */ | ||
56 | { QT1010_W, 0x23, 0xd0 }, | ||
57 | { QT1010_W, 0x1e, 0x00 }, | ||
58 | { QT1010_W, 0x1e, 0xe0 }, | ||
59 | { QT1010_R, 0x23, 0xff }, /* c read */ | ||
60 | { QT1010_W, 0x1e, 0x00 }, | ||
61 | { QT1010_W, 0x24, 0xd0 }, | ||
62 | { QT1010_W, 0x1e, 0x00 }, | ||
63 | { QT1010_W, 0x1e, 0xf0 }, | ||
64 | { QT1010_R, 0x24, 0xff }, /* 30 c read */ | ||
65 | { QT1010_W, 0x1e, 0x00 }, | ||
66 | { QT1010_W, 0x14, 0x7f }, | ||
67 | { QT1010_W, 0x15, 0x7f }, | ||
68 | { QT1010_W, 0x05, 0xff }, /* c */ | ||
69 | { QT1010_W, 0x06, 0x00 }, | ||
70 | { QT1010_W, 0x15, 0x1f }, | ||
71 | { QT1010_W, 0x16, 0xff }, | ||
72 | { QT1010_W, 0x18, 0xff }, | ||
73 | { QT1010_W, 0x1f, 0xff }, /* c */ | ||
74 | { QT1010_W, 0x20, 0xff }, /* 40 c */ | ||
75 | { QT1010_W, 0x21, 0x53 }, | ||
76 | { QT1010_W, 0x25, 0xbd }, | ||
77 | { QT1010_W, 0x26, 0x15 }, | ||
78 | { QT1010_W, 0x02, 0x00 }, | ||
79 | { QT1010_W, 0x01, 0x00 }, | ||
80 | }; | ||
81 | struct i2c_msg msg; | ||
82 | struct dvb_usb_device *d = fe->dvb->priv; | ||
83 | unsigned long freq = params->frequency; | ||
84 | |||
85 | if (freq % QT1010_MIN_STEP) | ||
86 | printk("frequency not supported.\n"); | ||
87 | |||
88 | (void) buf; | ||
89 | (void) buf_len; | ||
90 | |||
91 | div = (freq - QT1010_MIN_FREQ) / QT1010_MIN_STEP; | ||
92 | mod = (div + 16 - 9) % 16; | ||
93 | |||
94 | /* 0x5 */ | ||
95 | if (div >= 377) | ||
96 | rd[2].value = 0x74; | ||
97 | else if (div >= 265) | ||
98 | rd[2].value = 0x54; | ||
99 | else if (div >= 121) | ||
100 | rd[2].value = 0x34; | ||
101 | else | ||
102 | rd[2].value = 0x14; | ||
103 | |||
104 | /* 0x7 */ | ||
105 | rd[4].value = (((freq - QT1010_MIN_FREQ) / 1000000) * 9975 + 12960000) / 320000; | ||
106 | |||
107 | /* 09 */ | ||
108 | if (mod < 4) | ||
109 | rd[6].value = 0x1d; | ||
110 | else | ||
111 | rd[6].value = 0x1c; | ||
112 | |||
113 | /* 0a */ | ||
114 | if (mod < 2) | ||
115 | rd[7].value = 0x09; | ||
116 | else if (mod < 4) | ||
117 | rd[7].value = 0x08; | ||
118 | else if (mod < 6) | ||
119 | rd[7].value = 0x0f; | ||
120 | else if (mod < 8) | ||
121 | rd[7].value = 0x0e; | ||
122 | else if (mod < 10) | ||
123 | rd[7].value = 0x0d; | ||
124 | else if (mod < 12) | ||
125 | rd[7].value = 0x0c; | ||
126 | else if (mod < 14) | ||
127 | rd[7].value = 0x0b; | ||
128 | else | ||
129 | rd[7].value = 0x0a; | ||
130 | |||
131 | /* 0b */ | ||
132 | if (div & 1) | ||
133 | rd[8].value = 0x45; | ||
134 | else | ||
135 | rd[8].value = 0x44; | ||
136 | |||
137 | /* 1a */ | ||
138 | if (div & 1) | ||
139 | rd[10].value = 0x78; | ||
140 | else | ||
141 | rd[10].value = 0xf8; | ||
142 | |||
143 | /* 11 */ | ||
144 | if (div >= 265) | ||
145 | rd[13].value = 0xf9; | ||
146 | else if (div >= 121) | ||
147 | rd[13].value = 0xfd; | ||
148 | else | ||
149 | rd[13].value = 0xf9; | ||
150 | |||
151 | /* 22 */ | ||
152 | if (div < 201) | ||
153 | rd[15].value = 0xd0; | ||
154 | else if (div < 217) | ||
155 | rd[15].value = 0xd3; | ||
156 | else if (div < 233) | ||
157 | rd[15].value = 0xd6; | ||
158 | else if (div < 249) | ||
159 | rd[15].value = 0xd9; | ||
160 | else if (div < 265) | ||
161 | rd[15].value = 0xda; | ||
162 | else | ||
163 | rd[15].value = 0xd0; | ||
164 | |||
165 | /* 05 */ | ||
166 | if (div >= 377) | ||
167 | rd[34].value = 0x70; | ||
168 | else if (div >= 265) | ||
169 | rd[34].value = 0x50; | ||
170 | else if (div >= 121) | ||
171 | rd[34].value = 0x30; | ||
172 | else | ||
173 | rd[34].value = 0x10; | ||
174 | |||
175 | /* 1f */ | ||
176 | if (mod < 4) | ||
177 | rd[39].value = 0x64; | ||
178 | else if (mod < 6) | ||
179 | rd[39].value = 0x66; | ||
180 | else if (mod < 8) | ||
181 | rd[39].value = 0x67; | ||
182 | else if (mod < 12) | ||
183 | rd[39].value = 0x68; | ||
184 | else if (mod < 14) | ||
185 | rd[39].value = 0x69; | ||
186 | else | ||
187 | rd[39].value = 0x6a; | ||
188 | |||
189 | /* 20 */ | ||
190 | if (mod < 4) | ||
191 | rd[40].value = 0x10; | ||
192 | else if (mod < 6) | ||
193 | rd[40].value = 0x11; | ||
194 | else if (mod < 10) | ||
195 | rd[40].value = 0x12; | ||
196 | else if (mod < 12) | ||
197 | rd[40].value = 0x13; | ||
198 | else if (mod < 14) | ||
199 | rd[40].value = 0x14; | ||
200 | else | ||
201 | rd[40].value = 0x15; | ||
202 | |||
203 | for (i = 0; i < sizeof(rd) / sizeof(*rd); i++) { | ||
204 | if (rd[i].read) | ||
205 | continue; | ||
206 | |||
207 | msg.flags = 0; | ||
208 | msg.len = 2; | ||
209 | msg.addr = 0xc4; | ||
210 | msg.buf = &rd[i].reg; | ||
211 | |||
212 | if (i2c_transfer(&d->i2c_adap, &msg, 1) != 1) { | ||
213 | printk("tuner write failed\n"); | ||
214 | return -EIO; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | #endif | ||