📄 saa7113.c
字号:
switch (*iarg) { case VIDEO_MODE_NTSC: saa7113_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x40); saa7113_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f)); break; case VIDEO_MODE_PAL: saa7113_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x00); saa7113_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f)); break; case VIDEO_MODE_SECAM: saa7113_write(client, 0x08, (decoder->reg[0x0e] & 0x3f) | 0x00); saa7113_write(client, 0x0e, (decoder->reg[0x0e] & 0x8f) | 0x50); break; case VIDEO_MODE_AUTO: saa7113_write(client, 0x08, (decoder->reg[0x08] & 0x3f) | 0x80); saa7113_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 > 7) { return -EINVAL; } if (decoder->input != *iarg) { decoder->input = *iarg; /* select mode */ saa7113_write(client, 0x02, (decoder-> reg[0x02] & 0xf8) | decoder->input); /* bypass chrominance trap for modes 4..7 */ saa7113_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) { saa7113_write(client, 0x02, (decoder-> reg[0x02] & 0xf8) | decoder->input); saa7113_write(client, 0x08, (decoder->reg[0x08] & 0xfb)); saa7113_write(client, 0x11, (decoder-> reg[0x11] & 0xf3) | 0x0c); } else { saa7113_write(client, 0x02, (decoder->reg[0x02] & 0xf8)); saa7113_write(client, 0x08, (decoder-> reg[0x08] & 0xfb) | 0x04); saa7113_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; saa7113_write(client, 0x0a, decoder->bright >> 8); } if (decoder->contrast != pic->contrast) { /* We want 0 to 127 we get 0-65535 */ decoder->contrast = pic->contrast; saa7113_write(client, 0x0b, decoder->contrast >> 9); } if (decoder->sat != pic->colour) { /* We want 0 to 127 we get 0-65535 */ decoder->sat = pic->colour; saa7113_write(client, 0x0c, decoder->sat >> 9); } if (decoder->hue != pic->hue) { /* We want -128 to 127 we get 0-65535 */ decoder->hue = pic->hue; saa7113_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' */static unsigned short normal_i2c[] = { I2C_SAA7113 >> 1, I2C_CLIENT_END };static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };static unsigned short probe[2] = { I2C_CLIENT_END, I2C_CLIENT_END };static unsigned short probe_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };static unsigned short ignore[2] = { I2C_CLIENT_END, I2C_CLIENT_END };static unsigned short ignore_range[2] = { I2C_CLIENT_END, I2C_CLIENT_END };static unsigned short force[2] = { I2C_CLIENT_END , I2C_CLIENT_END }; static struct i2c_client_address_data addr_data = { .normal_i2c = normal_i2c, .normal_i2c_range = normal_i2c_range, .probe = probe, .probe_range = probe_range, .ignore = ignore, .ignore_range = ignore_range, .force = force};#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)static int saa7113_i2c_id = 0;#endifstatic struct i2c_driver i2c_driver_saa7113;static intsaa7113_detect_client (struct i2c_adapter *adapter, int address, int kind){ int i; struct i2c_client *client; struct saa7113 *decoder; struct video_decoder_init vdi; dprintk(1, KERN_INFO "saa7113.c: detecting saa7113 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 = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); if (client == 0) return -ENOMEM; memset(client, 0, sizeof(struct i2c_client)); client->addr = address; client->adapter = adapter; client->driver = &i2c_driver_saa7113; client->flags = I2C_CLIENT_ALLOW_USE;#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11) client->id = saa7113_i2c_id++; snprintf(I2C_NAME(client), sizeof(I2C_NAME(client)) - 1, "saa7111[%d]", client->id); #else strlcpy(I2C_NAME(client), "saa7113", sizeof(I2C_NAME(client)));#endif decoder = kmalloc(sizeof(struct saa7113), GFP_KERNEL); if (decoder == NULL) { kfree(client); return -ENOMEM; } memset(decoder, 0, sizeof(struct saa7113)); 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 = saa7113_i2c_init; vdi.len = sizeof(saa7113_i2c_init); i = saa7113_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), saa7113_read(client, 0x00) >> 4, client->addr << 1); } return 0;}static intsaa7113_attach_adapter (struct i2c_adapter *adapter){ dprintk(1, KERN_INFO "saa7113.c: starting probe for adapter %s (0x%x)\n", I2C_NAME(adapter), adapter->id); return i2c_probe(adapter, &addr_data, &saa7113_detect_client);}static intsaa7113_detach_client (struct i2c_client *client){ struct saa7113 *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_saa7113 = { .owner = THIS_MODULE, .name = "saa7113", .id = I2C_DRIVERID_SAA7113, .flags = I2C_DF_NOTIFY, .attach_adapter = saa7113_attach_adapter, .detach_client = saa7113_detach_client, .command = saa7113_command,};static int __initsaa7113_init (void){ return i2c_add_driver(&i2c_driver_saa7113);}static void __exitsaa7113_exit (void){ i2c_del_driver(&i2c_driver_saa7113);}module_init(saa7113_init);module_exit(saa7113_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -