aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/tuner-xc2028.c347
-rw-r--r--drivers/media/video/tuner-xc2028.h12
2 files changed, 175 insertions, 184 deletions
diff --git a/drivers/media/video/tuner-xc2028.c b/drivers/media/video/tuner-xc2028.c
index b9135b7c4337..473fa73b1819 100644
--- a/drivers/media/video/tuner-xc2028.c
+++ b/drivers/media/video/tuner-xc2028.c
@@ -11,7 +11,7 @@
11#include <linux/i2c.h> 11#include <linux/i2c.h>
12#include <asm/div64.h> 12#include <asm/div64.h>
13#include <linux/firmware.h> 13#include <linux/firmware.h>
14#include <linux/videodev.h> 14#include <linux/videodev2.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <media/tuner.h> 16#include <media/tuner.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
@@ -65,27 +65,31 @@ struct xc2028_data {
65 struct mutex lock; 65 struct mutex lock;
66}; 66};
67 67
68#define i2c_send(rc, priv, buf, size) \ 68#define i2c_send(rc, priv, buf, size) do { \
69if (size != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size))) \ 69 rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \
70 tuner_info("i2c output error: rc = %d (should be %d)\n", \ 70 if (size != rc) \
71 rc, (int)size); 71 tuner_info("i2c output error: rc = %d (should be %d)\n",\
72 72 rc, (int)size); \
73#define i2c_rcv(rc, priv, buf, size) \ 73} while (0)
74if (size != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size))) \ 74
75 tuner_info("i2c input error: rc = %d (should be %d)\n", \ 75#define i2c_rcv(rc, priv, buf, size) do { \
76 rc, (int)size); 76 rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \
77 77 if (size != rc) \
78#define send_seq(priv, data...) \ 78 tuner_info("i2c input error: rc = %d (should be %d)\n", \
79{ int rc; \ 79 rc, (int)size); \
80} while (0)
81
82#define send_seq(priv, data...) do { \
83 int rc; \
80 static u8 _val[] = data; \ 84 static u8 _val[] = data; \
81 if (sizeof(_val) != \ 85 if (sizeof(_val) != \
82 (rc = tuner_i2c_xfer_send (&priv->i2c_props, \ 86 (rc = tuner_i2c_xfer_send(&priv->i2c_props, \
83 _val, sizeof(_val)))) { \ 87 _val, sizeof(_val)))) { \
84 tuner_info("Error on line %d: %d\n",__LINE__,rc); \ 88 tuner_info("Error on line %d: %d\n", __LINE__, rc); \
85 return -EINVAL; \ 89 return -EINVAL; \
86 } \ 90 } \
87 msleep (10); \ 91 msleep(10); \
88} 92} while (0)
89 93
90static int xc2028_get_reg(struct xc2028_data *priv, u16 reg) 94static int xc2028_get_reg(struct xc2028_data *priv, u16 reg)
91{ 95{
@@ -94,42 +98,42 @@ static int xc2028_get_reg(struct xc2028_data *priv, u16 reg)
94 98
95 tuner_info("%s called\n", __FUNCTION__); 99 tuner_info("%s called\n", __FUNCTION__);
96 100
97 buf[0]= reg; 101 buf[0] = reg;
98 102
99 i2c_send(rc, priv, buf, sizeof(buf)); 103 i2c_send(rc, priv, buf, sizeof(buf));
100 if (rc<0) 104 if (rc < 0)
101 return rc; 105 return rc;
102 106
103 i2c_rcv(rc, priv, buf, 2); 107 i2c_rcv(rc, priv, buf, 2);
104 if (rc<0) 108 if (rc < 0)
105 return rc; 109 return rc;
106 110
107 return (buf[1])|(buf[0]<<8); 111 return (buf[1]) | (buf[0] << 8);
108} 112}
109 113
110static void free_firmware (struct xc2028_data *priv) 114static void free_firmware(struct xc2028_data *priv)
111{ 115{
112 int i; 116 int i;
113 117
114 if (!priv->firm) 118 if (!priv->firm)
115 return; 119 return;
116 120
117 for (i=0;i<priv->firm_size;i++) { 121 for (i = 0; i < priv->firm_size; i++)
118 if (priv->firm[i].ptr) 122 kfree(priv->firm[i].ptr);
119 kfree(priv->firm[i].ptr); 123
120 }
121 kfree(priv->firm); 124 kfree(priv->firm);
122 125
123 priv->firm=NULL; 126 priv->firm = NULL;
124 priv->need_load_generic = 1; 127 priv->need_load_generic = 1;
125} 128}
126 129
127static int load_all_firmwares (struct dvb_frontend *fe) 130static int load_all_firmwares(struct dvb_frontend *fe)
128{ 131{
129 struct xc2028_data *priv = fe->tuner_priv; 132 struct xc2028_data *priv = fe->tuner_priv;
130 const struct firmware *fw=NULL; 133 const struct firmware *fw = NULL;
131 unsigned char *p, *endp; 134 unsigned char *p, *endp;
132 int rc=0, n, n_array; 135 int rc = 0;
136 int n, n_array;
133 char name[33]; 137 char name[33];
134 138
135 tuner_info("%s called\n", __FUNCTION__); 139 tuner_info("%s called\n", __FUNCTION__);
@@ -137,7 +141,7 @@ static int load_all_firmwares (struct dvb_frontend *fe)
137 tuner_info("Loading firmware %s\n", priv->ctrl.fname); 141 tuner_info("Loading firmware %s\n", priv->ctrl.fname);
138 rc = request_firmware(&fw, priv->ctrl.fname, priv->dev); 142 rc = request_firmware(&fw, priv->ctrl.fname, priv->dev);
139 if (rc < 0) { 143 if (rc < 0) {
140 if (rc==-ENOENT) 144 if (rc == -ENOENT)
141 tuner_info("Error: firmware %s not found.\n", 145 tuner_info("Error: firmware %s not found.\n",
142 priv->ctrl.fname); 146 priv->ctrl.fname);
143 else 147 else
@@ -146,44 +150,44 @@ static int load_all_firmwares (struct dvb_frontend *fe)
146 150
147 return rc; 151 return rc;
148 } 152 }
149 p=fw->data; 153 p = fw->data;
150 endp=p+fw->size; 154 endp = p + fw->size;
151 155
152 if(fw->size<sizeof(name)-1+2) { 156 if (fw->size < sizeof(name) - 1 + 2) {
153 tuner_info("Error: firmware size is zero!\n"); 157 tuner_info("Error: firmware size is zero!\n");
154 rc=-EINVAL; 158 rc = -EINVAL;
155 goto done; 159 goto done;
156 } 160 }
157 161
158 memcpy(name,p,sizeof(name)-1); 162 memcpy(name, p, sizeof(name) - 1);
159 name[sizeof(name)-1]=0; 163 name[sizeof(name) - 1] = 0;
160 p+=sizeof(name)-1; 164 p += sizeof(name) - 1;
161 165
162 priv->version = le16_to_cpu(*(__u16 *)p); 166 priv->version = le16_to_cpu(*(__u16 *) p);
163 p += 2; 167 p += 2;
164 168
165 tuner_info("firmware: %s, ver %d.%d\n", name, 169 tuner_info("firmware: %s, ver %d.%d\n", name,
166 priv->version>>8, priv->version&0xff); 170 priv->version >> 8, priv->version & 0xff);
167 171
168 if (p+2>endp) 172 if (p + 2 > endp)
169 goto corrupt; 173 goto corrupt;
170 174
171 n_array = le16_to_cpu(*(__u16 *)p); 175 n_array = le16_to_cpu(*(__u16 *) p);
172 p += 2; 176 p += 2;
173 177
174 tuner_info("there are %d firmwares at %s\n", n_array, priv->ctrl.fname); 178 tuner_info("there are %d firmwares at %s\n", n_array, priv->ctrl.fname);
175 179
176 priv->firm=kzalloc(sizeof(*priv->firm)*n_array,GFP_KERNEL); 180 priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
177 181
178 if (!fw) { 182 if (!fw) {
179 tuner_info("Not enough memory for loading firmware.\n"); 183 tuner_info("Not enough memory for loading firmware.\n");
180 rc=-ENOMEM; 184 rc = -ENOMEM;
181 goto done; 185 goto done;
182 } 186 }
183 187
184 priv->firm_size = n_array; 188 priv->firm_size = n_array;
185 n=-1; 189 n = -1;
186 while (p<endp) { 190 while (p < endp) {
187 __u32 type, size; 191 __u32 type, size;
188 v4l2_std_id id; 192 v4l2_std_id id;
189 193
@@ -194,34 +198,34 @@ static int load_all_firmwares (struct dvb_frontend *fe)
194 } 198 }
195 199
196 /* Checks if there's enough bytes to read */ 200 /* Checks if there's enough bytes to read */
197 if (p+sizeof(type)+sizeof(id)+sizeof(size)>endp) { 201 if (p + sizeof(type) + sizeof(id) + sizeof(size) > endp) {
198 tuner_info("Lost firmware!\n"); 202 tuner_info("Lost firmware!\n");
199 goto corrupt; 203 goto corrupt;
200 } 204 }
201 205
202 type = le32_to_cpu(*(__u32 *)p); 206 type = le32_to_cpu(*(__u32 *) p);
203 p += sizeof(type); 207 p += sizeof(type);
204 208
205 id = le64_to_cpu(*(v4l2_std_id *)p); 209 id = le64_to_cpu(*(v4l2_std_id *) p);
206 p += sizeof(id); 210 p += sizeof(id);
207 211
208 size = le32_to_cpu(*(v4l2_std_id *)p); 212 size = le32_to_cpu(*(v4l2_std_id *) p);
209 p += sizeof(size); 213 p += sizeof(size);
210 214
211 if ((!size)||(size+p>endp)) { 215 if ((!size) || (size + p > endp)) {
212 tuner_info("Firmware type %x, id %lx corrupt\n", 216 tuner_info("Firmware type %x, id %lx corrupt\n",
213 type, (unsigned long) id); 217 type, (unsigned long)id);
214 goto corrupt; 218 goto corrupt;
215 } 219 }
216 220
217 priv->firm[n].ptr=kzalloc(size,GFP_KERNEL); 221 priv->firm[n].ptr = kzalloc(size, GFP_KERNEL);
218 if (!priv->firm[n].ptr) { 222 if (!priv->firm[n].ptr) {
219 tuner_info("Not enough memory.\n"); 223 tuner_info("Not enough memory.\n");
220 rc=-ENOMEM; 224 rc = -ENOMEM;
221 goto err; 225 goto err;
222 } 226 }
223 tuner_info("Loading firmware type %x, id %lx, size=%d.\n", 227 tuner_info("Loading firmware type %x, id %lx, size=%d.\n",
224 type, (unsigned long) id, size); 228 type, (unsigned long)id, size);
225 229
226 memcpy(priv->firm[n].ptr, p, size); 230 memcpy(priv->firm[n].ptr, p, size);
227 priv->firm[n].type = type; 231 priv->firm[n].type = type;
@@ -231,7 +235,7 @@ static int load_all_firmwares (struct dvb_frontend *fe)
231 p += size; 235 p += size;
232 } 236 }
233 237
234 if (n+1 != priv->firm_size) { 238 if (n + 1 != priv->firm_size) {
235 tuner_info("Firmware file is incomplete!\n"); 239 tuner_info("Firmware file is incomplete!\n");
236 goto corrupt; 240 goto corrupt;
237 } 241 }
@@ -239,7 +243,7 @@ static int load_all_firmwares (struct dvb_frontend *fe)
239 goto done; 243 goto done;
240 244
241corrupt: 245corrupt:
242 rc=-EINVAL; 246 rc = -EINVAL;
243 tuner_info("Error: firmware file is corrupted!\n"); 247 tuner_info("Error: firmware file is corrupted!\n");
244 248
245err: 249err:
@@ -254,46 +258,44 @@ done:
254 return rc; 258 return rc;
255} 259}
256 260
257static int load_firmware (struct dvb_frontend *fe, unsigned int type, 261static int load_firmware(struct dvb_frontend *fe, unsigned int type,
258 v4l2_std_id *id) 262 v4l2_std_id * id)
259{ 263{
260 struct xc2028_data *priv = fe->tuner_priv; 264 struct xc2028_data *priv = fe->tuner_priv;
261 int i, rc; 265 int i, rc;
262 unsigned char *p, *endp, buf[priv->max_len]; 266 unsigned char *p, *endp, buf[priv->max_len];
263 267
264 tuner_info("%s called\n", __FUNCTION__); 268 tuner_info("%s called\n", __FUNCTION__);
265 269
266 if (!priv->firm) { 270 if (!priv->firm) {
267 printk (KERN_ERR PREFIX "Error! firmware not loaded\n"); 271 printk(KERN_ERR PREFIX "Error! firmware not loaded\n");
268 return -EINVAL; 272 return -EINVAL;
269 } 273 }
270 274
271 if ((type == 0) && (*id == 0)) 275 if ((type == 0) && (*id == 0))
272 *id=V4L2_STD_PAL; 276 *id = V4L2_STD_PAL;
273 277
274 /* Seek for exact match */ 278 /* Seek for exact match */
275 for (i=0;i<priv->firm_size;i++) { 279 for (i = 0; i < priv->firm_size; i++) {
276 if ( (type == priv->firm[i].type) && 280 if ((type == priv->firm[i].type) && (*id == priv->firm[i].id))
277 (*id == priv->firm[i].id))
278 goto found; 281 goto found;
279 } 282 }
280 283
281 /* Seek for generic video standard match */ 284 /* Seek for generic video standard match */
282 for (i=0;i<priv->firm_size;i++) { 285 for (i = 0; i < priv->firm_size; i++) {
283 if ( (type == priv->firm[i].type) && (*id & priv->firm[i].id)) 286 if ((type == priv->firm[i].type) && (*id & priv->firm[i].id))
284 goto found; 287 goto found;
285 } 288 }
286 289
287 /*FIXME: Would make sense to seek for type "hint" match ? */ 290 /*FIXME: Would make sense to seek for type "hint" match ? */
288 291
289 tuner_info ("Can't find firmware for type=%x, id=%lx\n", type, 292 tuner_info("Can't find firmware for type=%x, id=%lx\n", type,
290 (long int)*id); 293 (long int)*id);
291 return -EINVAL; 294 return -EINVAL;
292 295
293found: 296found:
294 *id = priv->firm[i].id; 297 *id = priv->firm[i].id;
295 tuner_info ("Found firmware for type=%x, id=%lx\n", type, 298 tuner_info("Found firmware for type=%x, id=%lx\n", type, (long int)*id);
296 (long int)*id);
297 299
298 p = priv->firm[i].ptr; 300 p = priv->firm[i].ptr;
299 301
@@ -301,19 +303,18 @@ found:
301 printk(KERN_ERR PREFIX "Firmware pointer were freed!"); 303 printk(KERN_ERR PREFIX "Firmware pointer were freed!");
302 return -EINVAL; 304 return -EINVAL;
303 } 305 }
304 endp = p+priv->firm[i].size; 306 endp = p + priv->firm[i].size;
305 307
306 while (p<endp) { 308 while (p < endp) {
307 __u16 size; 309 __u16 size;
308 310
309 /* Checks if there's enough bytes to read */ 311 /* Checks if there's enough bytes to read */
310 if (p+sizeof(size)>endp) { 312 if (p + sizeof(size) > endp) {
311 tuner_info("missing bytes\n"); 313 tuner_info("missing bytes\n");
312 return -EINVAL; 314 return -EINVAL;
313 } 315 }
314 316
315 317 size = le16_to_cpu(*(__u16 *) p);
316 size = le16_to_cpu(*(__u16 *)p);
317 p += sizeof(size); 318 p += sizeof(size);
318 319
319 if (size == 0xffff) 320 if (size == 0xffff)
@@ -322,10 +323,10 @@ found:
322 if (!size) { 323 if (!size) {
323 /* Special callback command received */ 324 /* Special callback command received */
324 rc = priv->tuner_callback(priv->video_dev, 325 rc = priv->tuner_callback(priv->video_dev,
325 XC2028_TUNER_RESET, 0); 326 XC2028_TUNER_RESET, 0);
326 if (rc<0) { 327 if (rc < 0) {
327 tuner_info("Error at RESET code %d\n", 328 tuner_info("Error at RESET code %d\n",
328 (*p)&0x7f); 329 (*p) & 0x7f);
329 return -EINVAL; 330 return -EINVAL;
330 } 331 }
331 continue; 332 continue;
@@ -333,13 +334,13 @@ found:
333 334
334 /* Checks for a sleep command */ 335 /* Checks for a sleep command */
335 if (size & 0x8000) { 336 if (size & 0x8000) {
336 msleep (size & 0x7fff); 337 msleep(size & 0x7fff);
337 continue; 338 continue;
338 } 339 }
339 340
340 if ((size + p > endp)) { 341 if ((size + p > endp)) {
341 tuner_info("missing bytes: need %d, have %d\n", 342 tuner_info("missing bytes: need %d, have %d\n",
342 size, (int)(endp-p)); 343 size, (int)(endp - p));
343 return -EINVAL; 344 return -EINVAL;
344 } 345 }
345 346
@@ -348,14 +349,15 @@ found:
348 size--; 349 size--;
349 350
350 /* Sends message chunks */ 351 /* Sends message chunks */
351 while (size>0) { 352 while (size > 0) {
352 int len = (size<priv->max_len-1)?size:priv->max_len-1; 353 int len = (size < priv->max_len - 1) ?
354 size : priv->max_len - 1;
353 355
354 memcpy(buf+1, p, len); 356 memcpy(buf + 1, p, len);
355 357
356 i2c_send(rc, priv, buf, len+1); 358 i2c_send(rc, priv, buf, len + 1);
357 if (rc<0) { 359 if (rc < 0) {
358 tuner_info("%d returned from send\n",rc); 360 tuner_info("%d returned from send\n", rc);
359 return -EINVAL; 361 return -EINVAL;
360 } 362 }
361 363
@@ -367,13 +369,12 @@ found:
367} 369}
368 370
369static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode, 371static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
370 v4l2_std_id std, 372 v4l2_std_id std, fe_bandwidth_t bandwidth)
371 fe_bandwidth_t bandwidth)
372{ 373{
373 struct xc2028_data *priv = fe->tuner_priv; 374 struct xc2028_data *priv = fe->tuner_priv;
374 int rc, version; 375 int rc, version;
375 v4l2_std_id std0=0; 376 v4l2_std_id std0 = 0;
376 unsigned int type0=0,type=0; 377 unsigned int type0 = 0, type = 0;
377 int change_digital_bandwidth; 378 int change_digital_bandwidth;
378 379
379 tuner_info("%s called\n", __FUNCTION__); 380 tuner_info("%s called\n", __FUNCTION__);
@@ -382,58 +383,56 @@ static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
382 if (!priv->ctrl.fname) 383 if (!priv->ctrl.fname)
383 return -EINVAL; 384 return -EINVAL;
384 385
385 rc=load_all_firmwares(fe); 386 rc = load_all_firmwares(fe);
386 if (rc<0) 387 if (rc < 0)
387 return rc; 388 return rc;
388 } 389 }
389 390
390 tuner_info( "I am in mode %u and I should switch to mode %i\n", 391 tuner_info("I am in mode %u and I should switch to mode %i\n",
391 priv->mode, new_mode); 392 priv->mode, new_mode);
392 393
393 /* first of all, determine whether we have switched the mode */ 394 /* first of all, determine whether we have switched the mode */
394 if(new_mode != priv->mode) { 395 if (new_mode != priv->mode) {
395 priv->mode = new_mode; 396 priv->mode = new_mode;
396 priv->need_load_generic = 1; 397 priv->need_load_generic = 1;
397 } 398 }
398 399
399 change_digital_bandwidth = (priv->mode == T_DIGITAL_TV 400 change_digital_bandwidth = (priv->mode == T_DIGITAL_TV
400 && bandwidth != priv->bandwidth) ? 1 : 0; 401 && bandwidth != priv->bandwidth) ? 1 : 0;
401 tuner_info("old bandwidth %u, new bandwidth %u\n", priv->bandwidth, 402 tuner_info("old bandwidth %u, new bandwidth %u\n", priv->bandwidth,
402 bandwidth); 403 bandwidth);
403 404
404 if (priv->need_load_generic) { 405 if (priv->need_load_generic) {
405 /* Reset is needed before loading firmware */ 406 /* Reset is needed before loading firmware */
406 rc = priv->tuner_callback(priv->video_dev, 407 rc = priv->tuner_callback(priv->video_dev,
407 XC2028_TUNER_RESET, 0); 408 XC2028_TUNER_RESET, 0);
408 if (rc<0) 409 if (rc < 0)
409 return rc; 410 return rc;
410 411
411 type0=BASE; 412 type0 = BASE;
412 413
413 if (priv->ctrl.type == XC2028_FIRM_MTS) 414 if (priv->ctrl.type == XC2028_FIRM_MTS)
414 type0 |= MTS; 415 type0 |= MTS;
415 416
416 if (priv->bandwidth==8) 417 if (priv->bandwidth == 8)
417 type0 |= F8MHZ; 418 type0 |= F8MHZ;
418 419
419 /* FIXME: How to load FM and FM|INPUT1 firmwares? */ 420 /* FIXME: How to load FM and FM|INPUT1 firmwares? */
420 421
421 rc = load_firmware(fe, type0, &std0); 422 rc = load_firmware(fe, type0, &std0);
422 if (rc<0) { 423 if (rc < 0) {
423 tuner_info("Error %d while loading generic firmware\n", 424 tuner_info("Error %d while loading generic firmware\n",
424 rc); 425 rc);
425 return rc; 426 return rc;
426 } 427 }
427 428
428 priv->need_load_generic=0; 429 priv->need_load_generic = 0;
429 priv->firm_type=0; 430 priv->firm_type = 0;
430 if(priv->mode == T_DIGITAL_TV) { 431 if (priv->mode == T_DIGITAL_TV)
431 change_digital_bandwidth=1; 432 change_digital_bandwidth = 1;
432 }
433 } 433 }
434 434
435 tuner_info("I should change bandwidth %u\n", 435 tuner_info("I should change bandwidth %u\n", change_digital_bandwidth);
436 change_digital_bandwidth);
437 436
438 if (change_digital_bandwidth) { 437 if (change_digital_bandwidth) {
439 438
@@ -442,7 +441,7 @@ static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
442 441
443 /* FIXME: When should select a DTV78 firmware? 442 /* FIXME: When should select a DTV78 firmware?
444 */ 443 */
445 switch(bandwidth) { 444 switch (bandwidth) {
446 case BANDWIDTH_8_MHZ: 445 case BANDWIDTH_8_MHZ:
447 type |= DTV8; 446 type |= DTV8;
448 break; 447 break;
@@ -475,21 +474,21 @@ static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
475 if (priv->ctrl.type == XC2028_FIRM_MTS) 474 if (priv->ctrl.type == XC2028_FIRM_MTS)
476 type |= MTS; 475 type |= MTS;
477 476
478 tuner_info("firmware standard to load: %08lx\n",(unsigned long) std); 477 tuner_info("firmware standard to load: %08lx\n", (unsigned long)std);
479 if (priv->firm_type & std) { 478 if (priv->firm_type & std) {
480 tuner_info("no need to load a std-specific firmware.\n"); 479 tuner_info("no need to load a std-specific firmware.\n");
481 return 0; 480 return 0;
482 } 481 }
483 482
484 rc = load_firmware(fe, type, &std); 483 rc = load_firmware(fe, type, &std);
485 if (rc<0) 484 if (rc < 0)
486 return rc; 485 return rc;
487 486
488 version = xc2028_get_reg(priv, 0x4); 487 version = xc2028_get_reg(priv, 0x4);
489 tuner_info("Firmware version is %d.%d\n", 488 tuner_info("Firmware version is %d.%d\n",
490 (version>>4)&0x0f,(version)&0x0f); 489 (version >> 4) & 0x0f, (version) & 0x0f);
491 490
492 priv->firm_type=std; 491 priv->firm_type = std;
493 492
494 return 0; 493 return 0;
495} 494}
@@ -497,7 +496,7 @@ static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode,
497static int xc2028_signal(struct dvb_frontend *fe, u16 *strength) 496static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
498{ 497{
499 struct xc2028_data *priv = fe->tuner_priv; 498 struct xc2028_data *priv = fe->tuner_priv;
500 int frq_lock, signal=0; 499 int frq_lock, signal = 0;
501 500
502 tuner_info("%s called\n", __FUNCTION__); 501 tuner_info("%s called\n", __FUNCTION__);
503 502
@@ -506,16 +505,15 @@ static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
506 *strength = 0; 505 *strength = 0;
507 506
508 frq_lock = xc2028_get_reg(priv, 0x2); 507 frq_lock = xc2028_get_reg(priv, 0x2);
509 if (frq_lock<=0) 508 if (frq_lock <= 0)
510 goto ret; 509 goto ret;
511 510
512 /* Frequency is locked. Return signal quality */ 511 /* Frequency is locked. Return signal quality */
513 512
514 signal = xc2028_get_reg(priv, 0x40); 513 signal = xc2028_get_reg(priv, 0x40);
515 514
516 if(signal<=0) { 515 if (signal <= 0)
517 signal=frq_lock; 516 signal = frq_lock;
518 }
519 517
520ret: 518ret:
521 mutex_unlock(&priv->lock); 519 mutex_unlock(&priv->lock);
@@ -527,15 +525,14 @@ ret:
527 525
528#define DIV 15625 526#define DIV 15625
529 527
530static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */, 528static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */ ,
531 enum tuner_mode new_mode, 529 enum tuner_mode new_mode,
532 v4l2_std_id std, 530 v4l2_std_id std, fe_bandwidth_t bandwidth)
533 fe_bandwidth_t bandwidth)
534{ 531{
535 struct xc2028_data *priv = fe->tuner_priv; 532 struct xc2028_data *priv = fe->tuner_priv;
536 int rc=-EINVAL; 533 int rc = -EINVAL;
537 unsigned char buf[5]; 534 unsigned char buf[5];
538 u32 div, offset = 0; 535 u32 div, offset = 0;
539 536
540 tuner_info("%s called\n", __FUNCTION__); 537 tuner_info("%s called\n", __FUNCTION__);
541 538
@@ -544,56 +541,56 @@ static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */,
544 /* HACK: It seems that specific firmware need to be reloaded 541 /* HACK: It seems that specific firmware need to be reloaded
545 when freq is changed */ 542 when freq is changed */
546 543
547 priv->firm_type=0; 544 priv->firm_type = 0;
548 545
549 /* Reset GPIO 1 */ 546 /* Reset GPIO 1 */
550 rc = priv->tuner_callback(priv->video_dev, XC2028_TUNER_RESET, 0); 547 rc = priv->tuner_callback(priv->video_dev, XC2028_TUNER_RESET, 0);
551 if (rc<0) 548 if (rc < 0)
552 goto ret; 549 goto ret;
553 550
554 msleep(10); 551 msleep(10);
555 tuner_info("should set frequency %d kHz)\n", freq / 1000); 552 tuner_info("should set frequency %d kHz)\n", freq / 1000);
556 553
557 if (check_firmware(fe, new_mode, std, bandwidth)<0) 554 if (check_firmware(fe, new_mode, std, bandwidth) < 0)
558 goto ret; 555 goto ret;
559 556
560 if(new_mode == T_DIGITAL_TV) 557 if (new_mode == T_DIGITAL_TV)
561 offset = 2750000; 558 offset = 2750000;
562 559
563 div = (freq - offset + DIV/2)/DIV; 560 div = (freq - offset + DIV / 2) / DIV;
564 561
565 /* CMD= Set frequency */ 562 /* CMD= Set frequency */
566 563
567 if (priv->version<0x0202) { 564 if (priv->version < 0x0202) {
568 send_seq(priv, {0x00, 0x02, 0x00, 0x00}); 565 send_seq(priv, {0x00, 0x02, 0x00, 0x00});
569 } else { 566 } else {
570 send_seq(priv, {0x80, 0x02, 0x00, 0x00}); 567 send_seq(priv, {0x80, 0x02, 0x00, 0x00});
571 } 568 }
572 569
573 rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1); 570 rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
574 if (rc<0) 571 if (rc < 0)
575 goto ret; 572 goto ret;
576 573
577 msleep(10); 574 msleep(10);
578 575
579 buf[0]= 0xff & (div>>24); 576 buf[0] = 0xff & (div >> 24);
580 buf[1]= 0xff & (div>>16); 577 buf[1] = 0xff & (div >> 16);
581 buf[2]= 0xff & (div>>8); 578 buf[2] = 0xff & (div >> 8);
582 buf[3]= 0xff & (div); 579 buf[3] = 0xff & (div);
583 buf[4]= 0; 580 buf[4] = 0;
584 581
585 i2c_send(rc, priv, buf, sizeof(buf)); 582 i2c_send(rc, priv, buf, sizeof(buf));
586 if (rc<0) 583 if (rc < 0)
587 goto ret; 584 goto ret;
588 msleep(100); 585 msleep(100);
589 586
590 priv->frequency=freq; 587 priv->frequency = freq;
591 588
592 printk("divider= %02x %02x %02x %02x (freq=%d.%02d)\n", 589 printk("divider= %02x %02x %02x %02x (freq=%d.%02d)\n",
593 buf[1],buf[2],buf[3],buf[4], 590 buf[1], buf[2], buf[3], buf[4],
594 freq / 1000000, (freq%1000000)/10000); 591 freq / 1000000, (freq % 1000000) / 10000);
595 592
596 rc=0; 593 rc = 0;
597 594
598ret: 595ret:
599 mutex_unlock(&priv->lock); 596 mutex_unlock(&priv->lock);
@@ -602,15 +599,14 @@ ret:
602} 599}
603 600
604static int xc2028_set_tv_freq(struct dvb_frontend *fe, 601static int xc2028_set_tv_freq(struct dvb_frontend *fe,
605 struct analog_parameters *p) 602 struct analog_parameters *p)
606{ 603{
607 struct xc2028_data *priv = fe->tuner_priv; 604 struct xc2028_data *priv = fe->tuner_priv;
608 605
609 tuner_info("%s called\n", __FUNCTION__); 606 tuner_info("%s called\n", __FUNCTION__);
610 607
611 return generic_set_tv_freq(fe, 62500l*p->frequency, T_ANALOG_TV, 608 return generic_set_tv_freq(fe, 62500l * p->frequency, T_ANALOG_TV,
612 p->std, 609 p->std, BANDWIDTH_8_MHZ /* NOT USED */);
613 BANDWIDTH_8_MHZ /* NOT USED */);
614} 610}
615 611
616static int xc2028_set_params(struct dvb_frontend *fe, 612static int xc2028_set_params(struct dvb_frontend *fe,
@@ -622,13 +618,13 @@ static int xc2028_set_params(struct dvb_frontend *fe,
622 618
623 /* FIXME: Only OFDM implemented */ 619 /* FIXME: Only OFDM implemented */
624 if (fe->ops.info.type != FE_OFDM) { 620 if (fe->ops.info.type != FE_OFDM) {
625 tuner_info ("DTV type not implemented.\n"); 621 tuner_info("DTV type not implemented.\n");
626 return -EINVAL; 622 return -EINVAL;
627 } 623 }
628 624
629 return generic_set_tv_freq(fe, p->frequency, T_DIGITAL_TV, 625 return generic_set_tv_freq(fe, p->frequency, T_DIGITAL_TV,
630 0, /* NOT USED */ 626 0 /* NOT USED */,
631 p->u.ofdm.bandwidth); 627 p->u.ofdm.bandwidth);
632 628
633} 629}
634 630
@@ -643,11 +639,10 @@ static int xc2028_dvb_release(struct dvb_frontend *fe)
643 if (!priv->count) { 639 if (!priv->count) {
644 list_del(&priv->xc2028_list); 640 list_del(&priv->xc2028_list);
645 641
646 if (priv->ctrl.fname) 642 kfree(priv->ctrl.fname);
647 kfree(priv->ctrl.fname);
648 643
649 free_firmware(priv); 644 free_firmware(priv);
650 kfree (priv); 645 kfree(priv);
651 } 646 }
652 647
653 return 0; 648 return 0;
@@ -664,7 +659,7 @@ static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
664 return 0; 659 return 0;
665} 660}
666 661
667static int xc2028_set_config (struct dvb_frontend *fe, void *priv_cfg) 662static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
668{ 663{
669 struct xc2028_data *priv = fe->tuner_priv; 664 struct xc2028_data *priv = fe->tuner_priv;
670 struct xc2028_ctrl *p = priv_cfg; 665 struct xc2028_ctrl *p = priv_cfg;
@@ -674,10 +669,9 @@ static int xc2028_set_config (struct dvb_frontend *fe, void *priv_cfg)
674 priv->ctrl.type = p->type; 669 priv->ctrl.type = p->type;
675 670
676 if (p->fname) { 671 if (p->fname) {
677 if (priv->ctrl.fname) 672 kfree(priv->ctrl.fname);
678 kfree(priv->ctrl.fname);
679 673
680 priv->ctrl.fname = kmalloc(strlen(p->fname)+1, GFP_KERNEL); 674 priv->ctrl.fname = kmalloc(strlen(p->fname) + 1, GFP_KERNEL);
681 if (!priv->ctrl.fname) 675 if (!priv->ctrl.fname)
682 return -ENOMEM; 676 return -ENOMEM;
683 677
@@ -685,7 +679,7 @@ static int xc2028_set_config (struct dvb_frontend *fe, void *priv_cfg)
685 strcpy(priv->ctrl.fname, p->fname); 679 strcpy(priv->ctrl.fname, p->fname);
686 } 680 }
687 681
688 if (p->max_len>0) 682 if (p->max_len > 0)
689 priv->max_len = p->max_len; 683 priv->max_len = p->max_len;
690 684
691 tuner_info("%s OK\n", __FUNCTION__); 685 tuner_info("%s OK\n", __FUNCTION__);
@@ -695,11 +689,11 @@ static int xc2028_set_config (struct dvb_frontend *fe, void *priv_cfg)
695 689
696static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = { 690static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
697 .info = { 691 .info = {
698 .name = "Xceive XC3028", 692 .name = "Xceive XC3028",
699 .frequency_min = 42000000, 693 .frequency_min = 42000000,
700 .frequency_max = 864000000, 694 .frequency_max = 864000000,
701 .frequency_step = 50000, 695 .frequency_step = 50000,
702 }, 696 },
703 697
704 .set_config = xc2028_set_config, 698 .set_config = xc2028_set_config,
705 .set_analog_params = xc2028_set_tv_freq, 699 .set_analog_params = xc2028_set_tv_freq,
@@ -708,18 +702,15 @@ static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
708 .get_rf_strength = xc2028_signal, 702 .get_rf_strength = xc2028_signal,
709 .set_params = xc2028_set_params, 703 .set_params = xc2028_set_params,
710 704
711// int (*sleep)(struct dvb_frontend *fe);
712// int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
713// int (*get_status)(struct dvb_frontend *fe, u32 *status);
714}; 705};
715 706
716int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter* i2c_adap, 707int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c_adap,
717 u8 i2c_addr, struct device *dev, void *video_dev, 708 u8 i2c_addr, struct device *dev, void *video_dev,
718 int (*tuner_callback) (void *dev, int command,int arg)) 709 int (*tuner_callback) (void *dev, int command, int arg))
719{ 710{
720 struct xc2028_data *priv; 711 struct xc2028_data *priv;
721 712
722 printk( KERN_INFO PREFIX "Xcv2028/3028 init called!\n"); 713 printk(KERN_INFO PREFIX "Xcv2028/3028 init called!\n");
723 714
724 if (NULL == dev) 715 if (NULL == dev)
725 return -ENODEV; 716 return -ENODEV;
@@ -728,14 +719,13 @@ int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter* i2c_adap,
728 return -ENODEV; 719 return -ENODEV;
729 720
730 if (!tuner_callback) { 721 if (!tuner_callback) {
731 printk( KERN_ERR PREFIX "No tuner callback!\n"); 722 printk(KERN_ERR PREFIX "No tuner callback!\n");
732 return -EINVAL; 723 return -EINVAL;
733 } 724 }
734 725
735 list_for_each_entry(priv, &xc2028_list, xc2028_list) { 726 list_for_each_entry(priv, &xc2028_list, xc2028_list) {
736 if (priv->dev == dev) { 727 if (priv->dev == dev)
737 dev = NULL; 728 dev = NULL;
738 }
739 } 729 }
740 730
741 if (dev) { 731 if (dev) {
@@ -745,8 +735,8 @@ int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter* i2c_adap,
745 735
746 fe->tuner_priv = priv; 736 fe->tuner_priv = priv;
747 737
748 priv->bandwidth=BANDWIDTH_6_MHZ; 738 priv->bandwidth = BANDWIDTH_6_MHZ;
749 priv->need_load_generic=1; 739 priv->need_load_generic = 1;
750 priv->mode = T_UNINITIALIZED; 740 priv->mode = T_UNINITIALIZED;
751 priv->i2c_props.addr = i2c_addr; 741 priv->i2c_props.addr = i2c_addr;
752 priv->i2c_props.adap = i2c_adap; 742 priv->i2c_props.adap = i2c_adap;
@@ -758,18 +748,17 @@ int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter* i2c_adap,
758 748
759 mutex_init(&priv->lock); 749 mutex_init(&priv->lock);
760 750
761 list_add_tail(&priv->xc2028_list,&xc2028_list); 751 list_add_tail(&priv->xc2028_list, &xc2028_list);
762 } 752 }
763 priv->count++; 753 priv->count++;
764 754
765 memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops, 755 memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
766 sizeof(xc2028_dvb_tuner_ops)); 756 sizeof(xc2028_dvb_tuner_ops));
767 757
768 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner"); 758 tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner");
769 759
770 return 0; 760 return 0;
771} 761}
772
773EXPORT_SYMBOL(xc2028_attach); 762EXPORT_SYMBOL(xc2028_attach);
774 763
775MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver"); 764MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver");
diff --git a/drivers/media/video/tuner-xc2028.h b/drivers/media/video/tuner-xc2028.h
index 4e5e4d5d1b5f..e04611e653e4 100644
--- a/drivers/media/video/tuner-xc2028.h
+++ b/drivers/media/video/tuner-xc2028.h
@@ -27,15 +27,17 @@ struct xc2028_ctrl {
27#define XC2028_RESET_CLK 1 27#define XC2028_RESET_CLK 1
28 28
29#if defined(CONFIG_TUNER_XC2028) || (defined(CONFIG_TUNER_XC2028_MODULE) && defined(MODULE)) 29#if defined(CONFIG_TUNER_XC2028) || (defined(CONFIG_TUNER_XC2028_MODULE) && defined(MODULE))
30int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter* i2c_adap, 30int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c_adap,
31 u8 i2c_addr, struct device *dev, void *video_dev, 31 u8 i2c_addr, struct device *dev, void *video_dev,
32 int (*tuner_callback) (void *dev, int command,int arg)); 32 int (*tuner_callback) (void *dev, int command, int arg));
33 33
34#else 34#else
35static inline int xc2028_attach(struct dvb_frontend *fe, 35static inline int xc2028_attach(struct dvb_frontend *fe,
36 struct i2c_adapter* i2c_adap, 36 struct i2c_adapter *i2c_adap,
37 u8 i2c_addr, struct device *dev, void *video_dev, 37 u8 i2c_addr, struct device *dev,
38 int (*tuner_callback) (void *dev, int command,int arg)) 38 void *video_dev,
39 int (*tuner_callback) (void *dev, int command,
40 int arg))
39{ 41{
40 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n", 42 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
41 __FUNCTION__); 43 __FUNCTION__);