📄 saa711x.c
字号:
case VIDEO_MODE_NTSC: saa711x_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x40); saa711x_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f)); break; case VIDEO_MODE_PAL: saa711x_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x00); saa711x_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f)); break; case VIDEO_MODE_SECAM: saa711x_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x00); saa711x_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f) | 0x50); break; case VIDEO_MODE_AUTO: saa711x_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x80); saa711x_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f)); break; default: return -EINVAL; } decoder->norm = *iarg; } break; case DECODER_SET_INPUT: { int *iarg = arg; if (*iarg < 0 || *iarg > 9) { return -EINVAL; } if (decoder->input != *iarg) { decoder->input = *iarg; /* select mode */ saa711x_write(client, 0x02, (decoder->reg[0x02] & 0xf0) | decoder->input); /* bypass chrominance trap for modes 4..7 */ saa711x_write(client, 0x09, (decoder->reg[0x09] & 0x7f) | ((decoder->input > 3) ? 0x80 : 0)); } } break; case DECODER_SET_OUTPUT: { int *iarg = arg; /* not much choice of outputs */ if (*iarg != 0) { return -EINVAL; } } break; case DECODER_ENABLE_OUTPUT: { int *iarg = arg; int enable = (*iarg != 0); if (decoder->enable != enable) { decoder->enable = enable; /* RJ: If output should be disabled (for * playing videos), we also need a open PLL. * The input is set to 0 (where no input * source is connected), although this * is not necessary. * * If output should be enabled, we have to * reverse the above. */ if (decoder->enable) { saa711x_write(client, 0x02, (decoder-> reg[0x02] & 0xf8) | decoder->input); saa711x_write(client, 0x08, (decoder->reg[0x08] & 0xfb)); saa711x_write(client, 0x11, (decoder-> reg[0x11] & 0xf3) | 0x0c); } else { saa711x_write(client, 0x02, (decoder->reg[0x02] & 0xf8)); saa711x_write(client, 0x08, (decoder-> reg[0x08] & 0xfb) | 0x04); saa711x_write(client, 0x11, (decoder->reg[0x11] & 0xf3)); } } } break; case DECODER_SET_PICTURE: { struct video_picture *pic = arg; if (decoder->bright != pic->brightness) { /* We want 0 to 255 we get 0-65535 */ decoder->bright = pic->brightness; saa711x_write(client, 0x0a, decoder->bright >> 8); } if (decoder->contrast != pic->contrast) { /* We want 0 to 127 we get 0-65535 */ decoder->contrast = pic->contrast; saa711x_write(client, 0x0b, decoder->contrast >> 9); } if (decoder->sat != pic->colour) { /* We want 0 to 127 we get 0-65535 */ decoder->sat = pic->colour; saa711x_write(client, 0x0c, decoder->sat >> 9); } if (decoder->hue != pic->hue) { /* We want -128 to 127 we get 0-65535 */ decoder->hue = pic->hue; saa711x_write(client, 0x0d, (decoder->hue - 32768) >> 8); } } break; default: return -EINVAL; } return 0;}/* ----------------------------------------------------------------------- *//* * Generic i2c probe * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' *//* standard i2c insmod options */static unsigned short normal_i2c[] = { I2C_SAA7113>>1, /* saa7113 */ I2C_SAA7114>>1, /* saa7114 */ I2C_CLIENT_END};#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };#endifI2C_CLIENT_INSMOD;#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)static int saa711x_i2c_id = 0;#endifstatic struct i2c_driver i2c_driver_saa711x;#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)static intsaa711x_detect_client (struct i2c_adapter *adapter, int address, int kind)#elsestatic intsaa711x_detect_client (struct i2c_adapter *adapter, int address, unsigned short flags, int kind)#endif{ int i; struct i2c_client *client; struct saa711x *decoder; struct video_decoder_init vdi; dprintk(1, KERN_INFO "saa711x.c: detecting saa711x client on address 0x%x\n", address << 1); /* Check if the adapter supports the needed features */ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return 0; client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); if (client == 0) return -ENOMEM; client->addr = address; client->adapter = adapter; client->driver = &i2c_driver_saa711x;#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,15) client->flags = I2C_CLIENT_ALLOW_USE;#endif#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11) client->id = saa711x_i2c_id++; snprintf(I2C_NAME(client), sizeof(I2C_NAME(client)) - 1, "saa7111[%d]", client->id);#else strlcpy(I2C_NAME(client), "saa711x", sizeof(I2C_NAME(client)));#endif decoder = kzalloc(sizeof(struct saa711x), GFP_KERNEL); if (decoder == NULL) { kfree(client); return -ENOMEM; } decoder->norm = VIDEO_MODE_NTSC; decoder->input = 0; decoder->enable = 1; decoder->bright = 32768; decoder->contrast = 32768; decoder->hue = 32768; decoder->sat = 32768; i2c_set_clientdata(client, decoder); i = i2c_attach_client(client); if (i) { kfree(client); kfree(decoder); return i; } vdi.data = saa711x_i2c_init; vdi.len = sizeof(saa711x_i2c_init); i = saa711x_init_decoder(client, &vdi); if (i < 0) { dprintk(1, KERN_ERR "%s_attach error: init status %d\n", I2C_NAME(client), i); } else { dprintk(1, KERN_INFO "%s_attach: chip version %x at address 0x%x\n", I2C_NAME(client), saa711x_read(client, 0x00) >> 4, client->addr << 1); } return 0;}static intsaa711x_attach_adapter (struct i2c_adapter *adapter){ dprintk(1, KERN_INFO "saa711x.c: starting probe for adapter %s (0x%x)\n", I2C_NAME(adapter), adapter->id); return i2c_probe(adapter, &addr_data, &saa711x_detect_client);}static intsaa711x_detach_client (struct i2c_client *client){ struct saa711x *decoder = i2c_get_clientdata(client); int err; err = i2c_detach_client(client); if (err) { return err; } kfree(decoder); kfree(client); return 0;}/* ----------------------------------------------------------------------- */static struct i2c_driver i2c_driver_saa711x = {#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))&&(LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,15)) .owner = THIS_MODULE,#endif#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,15) .name = "saa711x", .flags = I2C_DF_NOTIFY,#else .driver = { .name = "saa711x", },#endif .id = I2C_DRIVERID_SAA711X, .attach_adapter = saa711x_attach_adapter, .detach_client = saa711x_detach_client, .command = saa711x_command,};static int __initsaa711x_init (void){ return i2c_add_driver(&i2c_driver_saa711x);}static void __exitsaa711x_exit (void){ i2c_del_driver(&i2c_driver_saa711x);}module_init(saa711x_init);module_exit(saa711x_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -