aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/adv7175.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2008-09-07 06:58:46 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-10-17 16:16:08 -0400
commitbba0d98262ea17fd2fd4a25f8a2be65647e5cf32 (patch)
tree1f9a059fd317984faeb3dc6f31089536988494a7 /drivers/media/video/adv7175.c
parentb9a21f84bc0ac39fc0b959b40aa27b2f66af243c (diff)
V4L/DVB (9199): adv7175: convert i2c driver for new i2c API
- Convert to use v4l2-i2c-drv-legacy.h to be able to handle the new i2c API - Cleanups - Use v4l_dbg/v4l_info to have uniform kernel messages Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/adv7175.c')
-rw-r--r--drivers/media/video/adv7175.c243
1 files changed, 60 insertions, 183 deletions
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 8ee07a68f702..6008e84653f1 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -25,43 +25,24 @@
25 */ 25 */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/delay.h>
30#include <linux/errno.h>
31#include <linux/fs.h>
32#include <linux/kernel.h>
33#include <linux/major.h>
34#include <linux/slab.h>
35#include <linux/mm.h>
36#include <linux/signal.h>
37#include <linux/types.h> 28#include <linux/types.h>
38#include <linux/i2c.h> 29#include <linux/ioctl.h>
39#include <asm/io.h>
40#include <asm/pgtable.h>
41#include <asm/page.h>
42#include <asm/uaccess.h> 30#include <asm/uaccess.h>
43 31#include <linux/i2c.h>
32#include <linux/i2c-id.h>
44#include <linux/videodev.h> 33#include <linux/videodev.h>
45#include <linux/video_encoder.h> 34#include <linux/video_encoder.h>
35#include <media/v4l2-common.h>
36#include <media/v4l2-i2c-drv-legacy.h>
46 37
47MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver"); 38MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver");
48MODULE_AUTHOR("Dave Perks"); 39MODULE_AUTHOR("Dave Perks");
49MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
50 41
51
52#define I2C_NAME(s) (s)->name
53
54
55static int debug; 42static int debug;
56module_param(debug, int, 0); 43module_param(debug, int, 0);
57MODULE_PARM_DESC(debug, "Debug level (0-1)"); 44MODULE_PARM_DESC(debug, "Debug level (0-1)");
58 45
59#define dprintk(num, format, args...) \
60 do { \
61 if (debug >= num) \
62 printk(format, ##args); \
63 } while (0)
64
65/* ----------------------------------------------------------------------- */ 46/* ----------------------------------------------------------------------- */
66 47
67struct adv7175 { 48struct adv7175 {
@@ -77,33 +58,23 @@ struct adv7175 {
77#define I2C_ADV7175 0xd4 58#define I2C_ADV7175 0xd4
78#define I2C_ADV7176 0x54 59#define I2C_ADV7176 0x54
79 60
80static char adv7175_name[] = "adv7175";
81static char adv7176_name[] = "adv7176";
82
83static char *inputs[] = { "pass_through", "play_back", "color_bar" }; 61static char *inputs[] = { "pass_through", "play_back", "color_bar" };
84static char *norms[] = { "PAL", "NTSC", "SECAM->PAL (may not work!)" }; 62static char *norms[] = { "PAL", "NTSC", "SECAM->PAL (may not work!)" };
85 63
86/* ----------------------------------------------------------------------- */ 64/* ----------------------------------------------------------------------- */
87 65
88static inline int 66static inline int adv7175_write(struct i2c_client *client, u8 reg, u8 value)
89adv7175_write (struct i2c_client *client,
90 u8 reg,
91 u8 value)
92{ 67{
93 return i2c_smbus_write_byte_data(client, reg, value); 68 return i2c_smbus_write_byte_data(client, reg, value);
94} 69}
95 70
96static inline int 71static inline int adv7175_read(struct i2c_client *client, u8 reg)
97adv7175_read (struct i2c_client *client,
98 u8 reg)
99{ 72{
100 return i2c_smbus_read_byte_data(client, reg); 73 return i2c_smbus_read_byte_data(client, reg);
101} 74}
102 75
103static int 76static int adv7175_write_block(struct i2c_client *client,
104adv7175_write_block (struct i2c_client *client, 77 const u8 *data, unsigned int len)
105 const u8 *data,
106 unsigned int len)
107{ 78{
108 int ret = -1; 79 int ret = -1;
109 u8 reg; 80 u8 reg;
@@ -123,18 +94,17 @@ adv7175_write_block (struct i2c_client *client,
123 reg++; 94 reg++;
124 len -= 2; 95 len -= 2;
125 data += 2; 96 data += 2;
126 } while (len >= 2 && data[0] == reg && 97 } while (len >= 2 && data[0] == reg && block_len < 32);
127 block_len < 32); 98 ret = i2c_master_send(client, block_data, block_len);
128 if ((ret = i2c_master_send(client, block_data, 99 if (ret < 0)
129 block_len)) < 0)
130 break; 100 break;
131 } 101 }
132 } else { 102 } else {
133 /* do some slow I2C emulation kind of thing */ 103 /* do some slow I2C emulation kind of thing */
134 while (len >= 2) { 104 while (len >= 2) {
135 reg = *data++; 105 reg = *data++;
136 if ((ret = adv7175_write(client, reg, 106 ret = adv7175_write(client, reg, *data++);
137 *data++)) < 0) 107 if (ret < 0)
138 break; 108 break;
139 len -= 2; 109 len -= 2;
140 } 110 }
@@ -143,13 +113,11 @@ adv7175_write_block (struct i2c_client *client,
143 return ret; 113 return ret;
144} 114}
145 115
146static void 116static void set_subcarrier_freq(struct i2c_client *client, int pass_through)
147set_subcarrier_freq (struct i2c_client *client,
148 int pass_through)
149{ 117{
150 /* for some reason pass_through NTSC needs 118 /* for some reason pass_through NTSC needs
151 * a different sub-carrier freq to remain stable. */ 119 * a different sub-carrier freq to remain stable. */
152 if(pass_through) 120 if (pass_through)
153 adv7175_write(client, 0x02, 0x00); 121 adv7175_write(client, 0x02, 0x00);
154 else 122 else
155 adv7175_write(client, 0x02, 0x55); 123 adv7175_write(client, 0x02, 0x55);
@@ -160,12 +128,12 @@ set_subcarrier_freq (struct i2c_client *client,
160} 128}
161 129
162/* ----------------------------------------------------------------------- */ 130/* ----------------------------------------------------------------------- */
163// Output filter: S-Video Composite 131/* Output filter: S-Video Composite */
164 132
165#define MR050 0x11 //0x09 133#define MR050 0x11 /* 0x09 */
166#define MR060 0x14 //0x0c 134#define MR060 0x14 /* 0x0c */
167 135
168//--------------------------------------------------------------------------- 136/* ----------------------------------------------------------------------- */
169 137
170#define TR0MODE 0x46 138#define TR0MODE 0x46
171#define TR0RST 0x80 139#define TR0RST 0x80
@@ -216,15 +184,11 @@ static const unsigned char init_ntsc[] = {
216 0x06, 0x1a, /* subc. phase */ 184 0x06, 0x1a, /* subc. phase */
217}; 185};
218 186
219static int 187static int adv7175_command(struct i2c_client *client, unsigned cmd, void *arg)
220adv7175_command (struct i2c_client *client,
221 unsigned int cmd,
222 void *arg)
223{ 188{
224 struct adv7175 *encoder = i2c_get_clientdata(client); 189 struct adv7175 *encoder = i2c_get_clientdata(client);
225 190
226 switch (cmd) { 191 switch (cmd) {
227
228 case 0: 192 case 0:
229 /* This is just for testing!!! */ 193 /* This is just for testing!!! */
230 adv7175_write_block(client, init_common, 194 adv7175_write_block(client, init_common,
@@ -242,15 +206,14 @@ adv7175_command (struct i2c_client *client,
242 VIDEO_ENCODER_SECAM; /* well, hacky */ 206 VIDEO_ENCODER_SECAM; /* well, hacky */
243 cap->inputs = 2; 207 cap->inputs = 2;
244 cap->outputs = 1; 208 cap->outputs = 1;
245 }
246 break; 209 break;
210 }
247 211
248 case ENCODER_SET_NORM: 212 case ENCODER_SET_NORM:
249 { 213 {
250 int iarg = *(int *) arg; 214 int iarg = *(int *) arg;
251 215
252 switch (iarg) { 216 switch (iarg) {
253
254 case VIDEO_MODE_NTSC: 217 case VIDEO_MODE_NTSC:
255 adv7175_write_block(client, init_ntsc, 218 adv7175_write_block(client, init_ntsc,
256 sizeof(init_ntsc)); 219 sizeof(init_ntsc));
@@ -284,16 +247,13 @@ adv7175_command (struct i2c_client *client,
284 adv7175_write(client, 0x07, TR0MODE); 247 adv7175_write(client, 0x07, TR0MODE);
285 break; 248 break;
286 default: 249 default:
287 dprintk(1, KERN_ERR "%s: illegal norm: %d\n", 250 v4l_dbg(1, debug, client, "illegal norm: %d\n", iarg);
288 I2C_NAME(client), iarg);
289 return -EINVAL; 251 return -EINVAL;
290
291 } 252 }
292 dprintk(1, KERN_INFO "%s: switched to %s\n", I2C_NAME(client), 253 v4l_dbg(1, debug, client, "switched to %s\n", norms[iarg]);
293 norms[iarg]);
294 encoder->norm = iarg; 254 encoder->norm = iarg;
295 }
296 break; 255 break;
256 }
297 257
298 case ENCODER_SET_INPUT: 258 case ENCODER_SET_INPUT:
299 { 259 {
@@ -304,7 +264,6 @@ adv7175_command (struct i2c_client *client,
304 *iarg = 2: color bar */ 264 *iarg = 2: color bar */
305 265
306 switch (iarg) { 266 switch (iarg) {
307
308 case 0: 267 case 0:
309 adv7175_write(client, 0x01, 0x00); 268 adv7175_write(client, 0x01, 0x00);
310 269
@@ -331,7 +290,7 @@ adv7175_command (struct i2c_client *client,
331 adv7175_write(client, 0x0d, 0x49); 290 adv7175_write(client, 0x0d, 0x49);
332 adv7175_write(client, 0x07, TR0MODE | TR0RST); 291 adv7175_write(client, 0x07, TR0MODE | TR0RST);
333 adv7175_write(client, 0x07, TR0MODE); 292 adv7175_write(client, 0x07, TR0MODE);
334 //udelay(10); 293 /* udelay(10); */
335 break; 294 break;
336 295
337 case 2: 296 case 2:
@@ -343,39 +302,35 @@ adv7175_command (struct i2c_client *client,
343 adv7175_write(client, 0x0d, 0x49); 302 adv7175_write(client, 0x0d, 0x49);
344 adv7175_write(client, 0x07, TR0MODE | TR0RST); 303 adv7175_write(client, 0x07, TR0MODE | TR0RST);
345 adv7175_write(client, 0x07, TR0MODE); 304 adv7175_write(client, 0x07, TR0MODE);
346 //udelay(10); 305 /* udelay(10); */
347 break; 306 break;
348 307
349 default: 308 default:
350 dprintk(1, KERN_ERR "%s: illegal input: %d\n", 309 v4l_dbg(1, debug, client, "illegal input: %d\n", iarg);
351 I2C_NAME(client), iarg);
352 return -EINVAL; 310 return -EINVAL;
353
354 } 311 }
355 dprintk(1, KERN_INFO "%s: switched to %s\n", I2C_NAME(client), 312 v4l_dbg(1, debug, client, "switched to %s\n", inputs[iarg]);
356 inputs[iarg]);
357 encoder->input = iarg; 313 encoder->input = iarg;
358 }
359 break; 314 break;
315 }
360 316
361 case ENCODER_SET_OUTPUT: 317 case ENCODER_SET_OUTPUT:
362 { 318 {
363 int *iarg = arg; 319 int *iarg = arg;
364 320
365 /* not much choice of outputs */ 321 /* not much choice of outputs */
366 if (*iarg != 0) { 322 if (*iarg != 0)
367 return -EINVAL; 323 return -EINVAL;
368 }
369 }
370 break; 324 break;
325 }
371 326
372 case ENCODER_ENABLE_OUTPUT: 327 case ENCODER_ENABLE_OUTPUT:
373 { 328 {
374 int *iarg = arg; 329 int *iarg = arg;
375 330
376 encoder->enable = !!*iarg; 331 encoder->enable = !!*iarg;
377 }
378 break; 332 break;
333 }
379 334
380 default: 335 default:
381 return -EINVAL; 336 return -EINVAL;
@@ -390,145 +345,67 @@ adv7175_command (struct i2c_client *client,
390 * Generic i2c probe 345 * Generic i2c probe
391 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 346 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
392 */ 347 */
393static unsigned short normal_i2c[] = 348static unsigned short normal_i2c[] = {
394 { I2C_ADV7175 >> 1, (I2C_ADV7175 >> 1) + 1, 349 I2C_ADV7175 >> 1, (I2C_ADV7175 >> 1) + 1,
395 I2C_ADV7176 >> 1, (I2C_ADV7176 >> 1) + 1, 350 I2C_ADV7176 >> 1, (I2C_ADV7176 >> 1) + 1,
396 I2C_CLIENT_END 351 I2C_CLIENT_END
397}; 352};
398 353
399static unsigned short ignore = I2C_CLIENT_END; 354I2C_CLIENT_INSMOD;
400
401static struct i2c_client_address_data addr_data = {
402 .normal_i2c = normal_i2c,
403 .probe = &ignore,
404 .ignore = &ignore,
405};
406
407static struct i2c_driver i2c_driver_adv7175;
408 355
409static int 356static int adv7175_probe(struct i2c_client *client,
410adv7175_detect_client (struct i2c_adapter *adapter, 357 const struct i2c_device_id *id)
411 int address,
412 int kind)
413{ 358{
414 int i; 359 int i;
415 struct i2c_client *client;
416 struct adv7175 *encoder; 360 struct adv7175 *encoder;
417 char *dname;
418
419 dprintk(1,
420 KERN_INFO
421 "adv7175.c: detecting adv7175 client on address 0x%x\n",
422 address << 1);
423 361
424 /* Check if the adapter supports the needed features */ 362 /* Check if the adapter supports the needed features */
425 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 363 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
426 return 0; 364 return -ENODEV;
427 365
428 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 366 v4l_info(client, "chip found @ 0x%x (%s)\n",
429 if (!client) 367 client->addr << 1, client->adapter->name);
430 return -ENOMEM;
431 client->addr = address;
432 client->adapter = adapter;
433 client->driver = &i2c_driver_adv7175;
434 if ((client->addr == I2C_ADV7175 >> 1) ||
435 (client->addr == (I2C_ADV7175 >> 1) + 1)) {
436 dname = adv7175_name;
437 } else if ((client->addr == I2C_ADV7176 >> 1) ||
438 (client->addr == (I2C_ADV7176 >> 1) + 1)) {
439 dname = adv7176_name;
440 } else {
441 /* We should never get here!!! */
442 kfree(client);
443 return 0;
444 }
445 strlcpy(I2C_NAME(client), dname, sizeof(I2C_NAME(client)));
446 368
447 encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL); 369 encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL);
448 if (encoder == NULL) { 370 if (encoder == NULL)
449 kfree(client);
450 return -ENOMEM; 371 return -ENOMEM;
451 }
452 encoder->norm = VIDEO_MODE_PAL; 372 encoder->norm = VIDEO_MODE_PAL;
453 encoder->input = 0; 373 encoder->input = 0;
454 encoder->enable = 1; 374 encoder->enable = 1;
455 i2c_set_clientdata(client, encoder); 375 i2c_set_clientdata(client, encoder);
456 376
457 i = i2c_attach_client(client);
458 if (i) {
459 kfree(client);
460 kfree(encoder);
461 return i;
462 }
463
464 i = adv7175_write_block(client, init_common, sizeof(init_common)); 377 i = adv7175_write_block(client, init_common, sizeof(init_common));
465 if (i >= 0) { 378 if (i >= 0) {
466 i = adv7175_write(client, 0x07, TR0MODE | TR0RST); 379 i = adv7175_write(client, 0x07, TR0MODE | TR0RST);
467 i = adv7175_write(client, 0x07, TR0MODE); 380 i = adv7175_write(client, 0x07, TR0MODE);
468 i = adv7175_read(client, 0x12); 381 i = adv7175_read(client, 0x12);
469 dprintk(1, KERN_INFO "%s_attach: rev. %d at 0x%x\n", 382 v4l_dbg(1, debug, client, "revision %d\n", i & 1);
470 I2C_NAME(client), i & 1, client->addr << 1);
471 } 383 }
472 if (i < 0) { 384 if (i < 0)
473 dprintk(1, KERN_ERR "%s_attach: init error 0x%x\n", 385 v4l_dbg(1, debug, client, "init error 0x%x\n", i);
474 I2C_NAME(client), i);
475 }
476
477 return 0; 386 return 0;
478} 387}
479 388
480static int 389static int adv7175_remove(struct i2c_client *client)
481adv7175_attach_adapter (struct i2c_adapter *adapter)
482{
483 dprintk(1,
484 KERN_INFO
485 "adv7175.c: starting probe for adapter %s (0x%x)\n",
486 I2C_NAME(adapter), adapter->id);
487 return i2c_probe(adapter, &addr_data, &adv7175_detect_client);
488}
489
490static int
491adv7175_detach_client (struct i2c_client *client)
492{ 390{
493 struct adv7175 *encoder = i2c_get_clientdata(client); 391 kfree(i2c_get_clientdata(client));
494 int err;
495
496 err = i2c_detach_client(client);
497 if (err) {
498 return err;
499 }
500
501 kfree(encoder);
502 kfree(client);
503
504 return 0; 392 return 0;
505} 393}
506 394
507/* ----------------------------------------------------------------------- */ 395/* ----------------------------------------------------------------------- */
508 396
509static struct i2c_driver i2c_driver_adv7175 = { 397static const struct i2c_device_id adv7175_id[] = {
510 .driver = { 398 { "adv7175", 0 },
511 .name = "adv7175", /* name */ 399 { "adv7176", 0 },
512 }, 400 { }
513 401};
514 .id = I2C_DRIVERID_ADV7175, 402MODULE_DEVICE_TABLE(i2c, adv7175_id);
515 403
516 .attach_adapter = adv7175_attach_adapter, 404static struct v4l2_i2c_driver_data v4l2_i2c_data = {
517 .detach_client = adv7175_detach_client, 405 .name = "adv7175",
406 .driverid = I2C_DRIVERID_ADV7175,
518 .command = adv7175_command, 407 .command = adv7175_command,
408 .probe = adv7175_probe,
409 .remove = adv7175_remove,
410 .id_table = adv7175_id,
519}; 411};
520
521static int __init
522adv7175_init (void)
523{
524 return i2c_add_driver(&i2c_driver_adv7175);
525}
526
527static void __exit
528adv7175_exit (void)
529{
530 i2c_del_driver(&i2c_driver_adv7175);
531}
532
533module_init(adv7175_init);
534module_exit(adv7175_exit);