]> err.no Git - linux-2.6/blob - drivers/media/dvb/frontends/qt1010.h
V4L/DVB (5136): M920x: correct oops when loading module
[linux-2.6] / drivers / media / dvb / frontends / qt1010.h
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)
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_adapter *adap = fe->dvb->priv;
83         unsigned long freq = params->frequency;
84
85         if (freq % QT1010_MIN_STEP)
86                 printk("frequency not supported.\n");
87
88         div = (freq - QT1010_MIN_FREQ) / QT1010_MIN_STEP;
89         mod = (div + 16 - 9) % 16;
90
91         /* 0x5 */
92         if (div >= 377)
93                 rd[2].value = 0x74;
94         else if (div >=  265)
95                 rd[2].value = 0x54;
96         else if (div >=  121)
97                 rd[2].value = 0x34;
98         else
99                 rd[2].value = 0x14;
100
101         /* 0x7 */
102         rd[4].value = (((freq - QT1010_MIN_FREQ) / 1000000) * 9975 + 12960000) / 320000;
103
104         /* 09 */
105         if (mod < 4)
106                 rd[6].value = 0x1d;
107         else
108                 rd[6].value = 0x1c;
109
110         /* 0a */
111         if (mod < 2)
112                 rd[7].value = 0x09;
113         else if (mod < 4)
114                 rd[7].value = 0x08;
115         else if (mod < 6)
116                 rd[7].value = 0x0f;
117         else if (mod < 8)
118                 rd[7].value = 0x0e;
119         else if (mod < 10)
120                 rd[7].value = 0x0d;
121         else if (mod < 12)
122                 rd[7].value = 0x0c;
123         else if (mod < 14)
124                 rd[7].value = 0x0b;
125         else
126                 rd[7].value = 0x0a;
127
128         /* 0b */
129         if (div & 1)
130                 rd[8].value = 0x45;
131         else
132                 rd[8].value = 0x44;
133
134         /* 1a */
135         if (div & 1)
136                 rd[10].value = 0x78;
137         else
138                 rd[10].value = 0xf8;
139
140         /* 11 */
141         if (div >= 265)
142                 rd[13].value = 0xf9;
143         else if (div >=  121)
144                 rd[13].value = 0xfd;
145         else
146                 rd[13].value = 0xf9;
147
148         /* 22 */
149         if (div < 201)
150                 rd[15].value = 0xd0;
151         else if (div < 217)
152                 rd[15].value = 0xd3;
153         else if (div < 233)
154                 rd[15].value = 0xd6;
155         else if (div < 249)
156                 rd[15].value = 0xd9;
157         else if (div < 265)
158                 rd[15].value = 0xda;
159         else
160                 rd[15].value = 0xd0;
161
162         /* 05 */
163         if (div >= 377)
164                 rd[34].value = 0x70;
165         else if (div >=  265)
166                 rd[34].value = 0x50;
167         else if (div >=  121)
168                 rd[34].value = 0x30;
169         else
170                 rd[34].value = 0x10;
171
172         /* 1f */
173         if (mod < 4)
174                 rd[39].value = 0x64;
175         else if (mod < 6)
176                 rd[39].value = 0x66;
177         else if (mod < 8)
178                 rd[39].value = 0x67;
179         else if (mod < 12)
180                 rd[39].value = 0x68;
181         else if (mod < 14)
182                 rd[39].value = 0x69;
183         else
184                 rd[39].value = 0x6a;
185
186         /* 20 */
187         if (mod < 4)
188                 rd[40].value = 0x10;
189         else if (mod < 6)
190                 rd[40].value = 0x11;
191         else if (mod < 10)
192                 rd[40].value = 0x12;
193         else if (mod < 12)
194                 rd[40].value = 0x13;
195         else if (mod < 14)
196                 rd[40].value = 0x14;
197         else
198                 rd[40].value = 0x15;
199
200         for (i = 0; i < sizeof(rd) / sizeof(*rd); i++) {
201                 if (rd[i].read)
202                         continue;
203
204                 msg.flags = 0;
205                 msg.len = 2;
206                 msg.addr = adap->dev->adapter[0].pll_addr;
207                 msg.buf = &rd[i].reg;
208
209                 if (i2c_transfer(&adap->dev->i2c_adap, &msg, 1) != 1) {
210                         printk("tuner write failed\n");
211                         return -EIO;
212                 }
213         }
214
215         return 0;
216 }
217
218 static int qt1010_tuner_attach(struct dvb_usb_adapter *adap)
219 {
220         adap->pll_addr = 0xc4;
221         adap->pll_desc = NULL;
222         adap->fe->ops.tuner_ops.set_params = qt1010_set_params;
223
224         return 0;
225 }
226 #endif