static int write_reg(struct i2c_client *client, u8 reg, u8 value) { struct go7007 *go = i2c_get_adapdata(client->adapter); struct go7007_usb *usb = go->hpi_context; int rc; int dev_addr = client->addr; u8 *buf; if (go == NULL) return -ENODEV; if (go->status == STATUS_SHUTDOWN) return -EBUSY; buf = kzalloc(16, GFP_KERNEL); if (buf == NULL) return -ENOMEM; if (down_interruptible(&usb->i2c_lock) != 0) { printk(KERN_INFO "i2c lock failed\n"); return -EINTR; } rc = go7007_usb_vendor_request(go, 0x55, dev_addr, (reg<<8 | value), buf, 16, 1); up(&usb->i2c_lock); kfree(buf); return rc; }
static int write_reg_fp(struct i2c_client *client, u16 addr, u16 val) { struct go7007 *go = i2c_get_adapdata(client->adapter); struct go7007_usb *usb = go->hpi_context; u8 *buf; struct s2250 *dec = i2c_get_clientdata(client); if (go == NULL) return -ENODEV; if (go->status == STATUS_SHUTDOWN) return -EBUSY; buf = kzalloc(16, GFP_KERNEL); if (buf == NULL) return -ENOMEM; memset(buf, 0xcd, 6); if (down_interruptible(&usb->i2c_lock) != 0) { printk(KERN_INFO "i2c lock failed\n"); return -EINTR; } if (go7007_usb_vendor_request(go, 0x57, addr, val, buf, 16, 1) < 0) return -EFAULT; up(&usb->i2c_lock); if (buf[0] == 0) { unsigned int subaddr, val_read; subaddr = (buf[4] << 8) + buf[5]; val_read = (buf[2] << 8) + buf[3]; if (val_read != val) { printk(KERN_INFO "invalid fp write %x %x\n", val_read, val); return -EFAULT; } if (subaddr != addr) { printk(KERN_INFO "invalid fp write addr %x %x\n", subaddr, addr); return -EFAULT; } } else return -EFAULT; /* save last 12b value */ if (addr == 0x12b) dec->reg12b_val = val; return 0; }
static int read_reg_fp(struct i2c_client *client, u16 addr, u16 *val) { struct go7007 *go = i2c_get_adapdata(client->adapter); struct go7007_usb *usb; u8 *buf; if (go == NULL) return -ENODEV; if (go->status == STATUS_SHUTDOWN) return -EBUSY; buf = kzalloc(16, GFP_KERNEL); if (buf == NULL) return -ENOMEM; memset(buf, 0xcd, 6); usb = go->hpi_context; if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { printk(KERN_INFO "i2c lock failed\n"); kfree(buf); return -EINTR; } if (go7007_usb_vendor_request(go, 0x58, addr, 0, buf, 16, 1) < 0) { kfree(buf); return -EFAULT; } mutex_unlock(&usb->i2c_lock); *val = (buf[0] << 8) | buf[1]; kfree(buf); return 0; }
static int s2250_detect(struct i2c_adapter *adapter, int addr, int kind) { struct i2c_client *client; struct s2250 *dec; u8 *data; struct go7007 *go = i2c_get_adapdata(adapter); struct go7007_usb *usb = go->hpi_context; client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); if (client == NULL) return -ENOMEM; memcpy(client, &s2250_client_templ, sizeof(s2250_client_templ)); client->adapter = adapter; dec = kmalloc(sizeof(struct s2250), GFP_KERNEL); if (dec == NULL) { kfree(client); return -ENOMEM; } dec->std = V4L2_STD_NTSC; dec->brightness = 50; dec->contrast = 50; dec->saturation = 50; dec->hue = 0; client->addr = TLV320_ADDRESS; i2c_set_clientdata(client, dec); printk(KERN_DEBUG "s2250: initializing video decoder on %s\n", adapter->name); /* initialize the audio */ client->addr = TLV320_ADDRESS; if (write_regs(client, aud_regs) < 0) { printk(KERN_ERR "s2250: error initializing audio\n"); kfree(client); kfree(dec); return 0; } client->addr = S2250_VIDDEC; i2c_set_clientdata(client, dec); if (write_regs(client, vid_regs) < 0) { printk(KERN_ERR "s2250: error initializing decoder\n"); kfree(client); kfree(dec); return 0; } if (write_regs_fp(client, vid_regs_fp) < 0) { printk(KERN_ERR "s2250: error initializing decoder\n"); kfree(client); kfree(dec); return 0; } /* set default channel */ /* composite */ write_reg_fp(client, 0x20, 0x020 | 1); write_reg_fp(client, 0x21, 0x662); write_reg_fp(client, 0x140, 0x060); /* set default audio input */ dec->audio_input = 0; write_reg(client, 0x08, 0x02); /* Line In */ if (down_interruptible(&usb->i2c_lock) == 0) { data = kzalloc(16, GFP_KERNEL); if (data != NULL) { int rc; rc = go7007_usb_vendor_request(go, 0x41, 0, 0, data, 16, 1); if (rc > 0) { u8 mask; data[0] = 0; mask = 1<<5; data[0] &= ~mask; data[1] |= mask; go7007_usb_vendor_request(go, 0x40, 0, (data[1]<<8) + data[1], data, 16, 0); } kfree(data); } up(&usb->i2c_lock); } i2c_attach_client(client); printk("s2250: initialized successfully\n"); return 0; }
static int s2250_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_client *audio; struct i2c_adapter *adapter = client->adapter; struct s2250 *dec; u8 *data; struct go7007 *go = i2c_get_adapdata(adapter); struct go7007_usb *usb = go->hpi_context; audio = i2c_new_dummy(adapter, TLV320_ADDRESS >> 1); if (audio == NULL) return -ENOMEM; dec = kmalloc(sizeof(struct s2250), GFP_KERNEL); if (dec == NULL) { i2c_unregister_device(audio); return -ENOMEM; } dec->std = V4L2_STD_NTSC; dec->brightness = 50; dec->contrast = 50; dec->saturation = 50; dec->hue = 0; dec->audio = audio; i2c_set_clientdata(client, dec); printk(KERN_DEBUG "s2250: initializing video decoder on %s\n", adapter->name); /* initialize the audio */ if (write_regs(audio, aud_regs) < 0) { printk(KERN_ERR "s2250: error initializing audio\n"); i2c_unregister_device(audio); kfree(dec); return 0; } if (write_regs(client, vid_regs) < 0) { printk(KERN_ERR "s2250: error initializing decoder\n"); i2c_unregister_device(audio); kfree(dec); return 0; } if (write_regs_fp(client, vid_regs_fp) < 0) { printk(KERN_ERR "s2250: error initializing decoder\n"); i2c_unregister_device(audio); kfree(dec); return 0; } /* set default channel */ /* composite */ write_reg_fp(client, 0x20, 0x020 | 1); write_reg_fp(client, 0x21, 0x662); write_reg_fp(client, 0x140, 0x060); /* set default audio input */ dec->audio_input = 0; write_reg(client, 0x08, 0x02); /* Line In */ if (mutex_lock_interruptible(&usb->i2c_lock) == 0) { data = kzalloc(16, GFP_KERNEL); if (data != NULL) { int rc; rc = go7007_usb_vendor_request(go, 0x41, 0, 0, data, 16, 1); if (rc > 0) { u8 mask; data[0] = 0; mask = 1<<5; data[0] &= ~mask; data[1] |= mask; go7007_usb_vendor_request(go, 0x40, 0, (data[1]<<8) + data[1], data, 16, 0); } kfree(data); } mutex_unlock(&usb->i2c_lock); } printk("s2250: initialized successfully\n"); return 0; }