static int saa7185_detect_client (struct i2c_adapter *adapter, int address, int kind) { int i; struct i2c_client *client; struct saa7185 *encoder; dprintk(1, KERN_INFO "saa7185.c: detecting saa7185 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_saa7185; strlcpy(I2C_NAME(client), "saa7185", sizeof(I2C_NAME(client))); encoder = kzalloc(sizeof(struct saa7185), GFP_KERNEL); if (encoder == NULL) { kfree(client); return -ENOMEM; } encoder->norm = VIDEO_MODE_NTSC; encoder->enable = 1; i2c_set_clientdata(client, encoder); i = i2c_attach_client(client); if (i) { kfree(client); kfree(encoder); return i; } i = saa7185_write_block(client, init_common, sizeof(init_common)); if (i >= 0) { i = saa7185_write_block(client, init_ntsc, sizeof(init_ntsc)); } if (i < 0) { dprintk(1, KERN_ERR "%s_attach: init error %d\n", I2C_NAME(client), i); } else { dprintk(1, KERN_INFO "%s_attach: chip version %d at address 0x%x\n", I2C_NAME(client), saa7185_read(client) >> 5, client->addr << 1); } return 0; }
static int saa7185_detect_client (struct i2c_adapter *adapter, int address, #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) unsigned short flags, #endif int kind) { int i; struct i2c_client *client; struct saa7185 *encoder; dprintk(1, KERN_INFO "saa7185.c: detecting saa7185 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_saa7185; client->flags = I2C_CLIENT_ALLOW_USE; client->id = saa7185_i2c_id++; snprintf(I2C_NAME(client), sizeof(I2C_NAME(client)) - 1, "saa7185[%d]", client->id); encoder = kmalloc(sizeof(struct saa7185), GFP_KERNEL); if (encoder == NULL) { kfree(client); return -ENOMEM; } memset(encoder, 0, sizeof(struct saa7185)); encoder->norm = VIDEO_MODE_NTSC; encoder->enable = 1; i2c_set_clientdata(client, encoder); i = i2c_attach_client(client); if (i) { kfree(client); kfree(encoder); return i; } i = saa7185_write_block(client, init_common, sizeof(init_common)); if (i >= 0) { i = saa7185_write_block(client, init_ntsc, sizeof(init_ntsc)); } if (i < 0) { dprintk(1, KERN_ERR "%s_attach: init error %d\n", I2C_NAME(client), i); } else { dprintk(1, KERN_INFO "%s_attach: chip version %d at address 0x%x\n", I2C_NAME(client), saa7185_read(client) >> 5, client->addr << 1); } return 0; }
static int saa7185_command (struct i2c_client *client, unsigned int cmd, void *arg) { struct saa7185 *encoder = i2c_get_clientdata(client); switch (cmd) { case 0: saa7185_write_block(client, init_common, sizeof(init_common)); switch (encoder->norm) { case VIDEO_MODE_NTSC: saa7185_write_block(client, init_ntsc, sizeof(init_ntsc)); break; case VIDEO_MODE_PAL: saa7185_write_block(client, init_pal, sizeof(init_pal)); break; } break; case ENCODER_GET_CAPABILITIES: { struct video_encoder_capability *cap = arg; cap->flags = VIDEO_ENCODER_PAL | VIDEO_ENCODER_NTSC | VIDEO_ENCODER_SECAM | VIDEO_ENCODER_CCIR; cap->inputs = 1; cap->outputs = 1; } break; case ENCODER_SET_NORM: { int *iarg = arg; //saa7185_write_block(client, init_common, sizeof(init_common)); switch (*iarg) { case VIDEO_MODE_NTSC: saa7185_write_block(client, init_ntsc, sizeof(init_ntsc)); break; case VIDEO_MODE_PAL: saa7185_write_block(client, init_pal, sizeof(init_pal)); break; case VIDEO_MODE_SECAM: default: return -EINVAL; } encoder->norm = *iarg; } break; case ENCODER_SET_INPUT: { int *iarg = arg; /* RJ: *iarg = 0: input is from SA7111 *iarg = 1: input is from ZR36060 */ switch (*iarg) { case 0: /* Switch RTCE to 1 */ saa7185_write(client, 0x61, (encoder->reg[0x61] & 0xf7) | 0x08); saa7185_write(client, 0x6e, 0x01); break; case 1: /* Switch RTCE to 0 */ saa7185_write(client, 0x61, (encoder->reg[0x61] & 0xf7) | 0x00); /* SW: a slight sync problem... */ saa7185_write(client, 0x6e, 0x00); break; default: return -EINVAL; } } break; case ENCODER_SET_OUTPUT: { int *iarg = arg; /* not much choice of outputs */ if (*iarg != 0) { return -EINVAL; } } break; case ENCODER_ENABLE_OUTPUT: { int *iarg = arg; encoder->enable = !!*iarg; saa7185_write(client, 0x61, (encoder->reg[0x61] & 0xbf) | (encoder->enable ? 0x00 : 0x40)); } break; default: return -EINVAL; } return 0; }