18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci hexium_gemini.c - v4l2 driver for Hexium Gemini frame grabber cards 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci Visit http://www.mihu.de/linux/saa7146/ and follow the link 68c2ecf20Sopenharmony_ci to "hexium" for further details about this card. 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci Copyright (C) 2003 Michael Hunold <michael@mihu.de> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci*/ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define DEBUG_VARIABLE debug 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <media/drv-intf/saa7146_vv.h> 178c2ecf20Sopenharmony_ci#include <linux/module.h> 188c2ecf20Sopenharmony_ci#include <linux/kernel.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic int debug; 218c2ecf20Sopenharmony_cimodule_param(debug, int, 0); 228c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "debug verbosity"); 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* global variables */ 258c2ecf20Sopenharmony_cistatic int hexium_num; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define HEXIUM_GEMINI 4 288c2ecf20Sopenharmony_ci#define HEXIUM_GEMINI_DUAL 5 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define HEXIUM_INPUTS 9 318c2ecf20Sopenharmony_cistatic struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = { 328c2ecf20Sopenharmony_ci { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 338c2ecf20Sopenharmony_ci { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 348c2ecf20Sopenharmony_ci { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 358c2ecf20Sopenharmony_ci { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 368c2ecf20Sopenharmony_ci { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 378c2ecf20Sopenharmony_ci { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 388c2ecf20Sopenharmony_ci { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 398c2ecf20Sopenharmony_ci { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 408c2ecf20Sopenharmony_ci { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define HEXIUM_AUDIOS 0 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct hexium_data 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci s8 adr; 488c2ecf20Sopenharmony_ci u8 byte; 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define HEXIUM_GEMINI_V_1_0 1 528c2ecf20Sopenharmony_ci#define HEXIUM_GEMINI_DUAL_V_1_0 2 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct hexium 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci int type; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci struct video_device video_dev; 598c2ecf20Sopenharmony_ci struct i2c_adapter i2c_adapter; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci int cur_input; /* current input */ 628c2ecf20Sopenharmony_ci v4l2_std_id cur_std; /* current standard */ 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* Samsung KS0127B decoder default registers */ 668c2ecf20Sopenharmony_cistatic u8 hexium_ks0127b[0x100]={ 678c2ecf20Sopenharmony_ci/*00*/ 0x00,0x52,0x30,0x40,0x01,0x0C,0x2A,0x10, 688c2ecf20Sopenharmony_ci/*08*/ 0x00,0x00,0x00,0x60,0x00,0x00,0x0F,0x06, 698c2ecf20Sopenharmony_ci/*10*/ 0x00,0x00,0xE4,0xC0,0x00,0x00,0x00,0x00, 708c2ecf20Sopenharmony_ci/*18*/ 0x14,0x9B,0xFE,0xFF,0xFC,0xFF,0x03,0x22, 718c2ecf20Sopenharmony_ci/*20*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 728c2ecf20Sopenharmony_ci/*28*/ 0x00,0x00,0x00,0x00,0x00,0x2C,0x9B,0x00, 738c2ecf20Sopenharmony_ci/*30*/ 0x00,0x00,0x10,0x80,0x80,0x10,0x80,0x80, 748c2ecf20Sopenharmony_ci/*38*/ 0x01,0x04,0x00,0x00,0x00,0x29,0xC0,0x00, 758c2ecf20Sopenharmony_ci/*40*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 768c2ecf20Sopenharmony_ci/*48*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 778c2ecf20Sopenharmony_ci/*50*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 788c2ecf20Sopenharmony_ci/*58*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 798c2ecf20Sopenharmony_ci/*60*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 808c2ecf20Sopenharmony_ci/*68*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 818c2ecf20Sopenharmony_ci/*70*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 828c2ecf20Sopenharmony_ci/*78*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 838c2ecf20Sopenharmony_ci/*80*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 848c2ecf20Sopenharmony_ci/*88*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 858c2ecf20Sopenharmony_ci/*90*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 868c2ecf20Sopenharmony_ci/*98*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 878c2ecf20Sopenharmony_ci/*A0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 888c2ecf20Sopenharmony_ci/*A8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 898c2ecf20Sopenharmony_ci/*B0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 908c2ecf20Sopenharmony_ci/*B8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 918c2ecf20Sopenharmony_ci/*C0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 928c2ecf20Sopenharmony_ci/*C8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 938c2ecf20Sopenharmony_ci/*D0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 948c2ecf20Sopenharmony_ci/*D8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 958c2ecf20Sopenharmony_ci/*E0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 968c2ecf20Sopenharmony_ci/*E8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 978c2ecf20Sopenharmony_ci/*F0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 988c2ecf20Sopenharmony_ci/*F8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic struct hexium_data hexium_pal[] = { 1028c2ecf20Sopenharmony_ci { 0x01, 0x52 }, { 0x12, 0x64 }, { 0x2D, 0x2C }, { 0x2E, 0x9B }, { -1 , 0xFF } 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistatic struct hexium_data hexium_ntsc[] = { 1068c2ecf20Sopenharmony_ci { 0x01, 0x53 }, { 0x12, 0x04 }, { 0x2D, 0x23 }, { 0x2E, 0x81 }, { -1 , 0xFF } 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic struct hexium_data hexium_secam[] = { 1108c2ecf20Sopenharmony_ci { 0x01, 0x52 }, { 0x12, 0x64 }, { 0x2D, 0x2C }, { 0x2E, 0x9B }, { -1 , 0xFF } 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic struct hexium_data hexium_input_select[] = { 1148c2ecf20Sopenharmony_ci { 0x02, 0x60 }, 1158c2ecf20Sopenharmony_ci { 0x02, 0x64 }, 1168c2ecf20Sopenharmony_ci { 0x02, 0x61 }, 1178c2ecf20Sopenharmony_ci { 0x02, 0x65 }, 1188c2ecf20Sopenharmony_ci { 0x02, 0x62 }, 1198c2ecf20Sopenharmony_ci { 0x02, 0x66 }, 1208c2ecf20Sopenharmony_ci { 0x02, 0x68 }, 1218c2ecf20Sopenharmony_ci { 0x02, 0x69 }, 1228c2ecf20Sopenharmony_ci { 0x02, 0x6A }, 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* fixme: h_offset = 0 for Hexium Gemini *Dual*, which 1268c2ecf20Sopenharmony_ci are currently *not* supported*/ 1278c2ecf20Sopenharmony_cistatic struct saa7146_standard hexium_standards[] = { 1288c2ecf20Sopenharmony_ci { 1298c2ecf20Sopenharmony_ci .name = "PAL", .id = V4L2_STD_PAL, 1308c2ecf20Sopenharmony_ci .v_offset = 28, .v_field = 288, 1318c2ecf20Sopenharmony_ci .h_offset = 1, .h_pixels = 680, 1328c2ecf20Sopenharmony_ci .v_max_out = 576, .h_max_out = 768, 1338c2ecf20Sopenharmony_ci }, { 1348c2ecf20Sopenharmony_ci .name = "NTSC", .id = V4L2_STD_NTSC, 1358c2ecf20Sopenharmony_ci .v_offset = 28, .v_field = 240, 1368c2ecf20Sopenharmony_ci .h_offset = 1, .h_pixels = 640, 1378c2ecf20Sopenharmony_ci .v_max_out = 480, .h_max_out = 640, 1388c2ecf20Sopenharmony_ci }, { 1398c2ecf20Sopenharmony_ci .name = "SECAM", .id = V4L2_STD_SECAM, 1408c2ecf20Sopenharmony_ci .v_offset = 28, .v_field = 288, 1418c2ecf20Sopenharmony_ci .h_offset = 1, .h_pixels = 720, 1428c2ecf20Sopenharmony_ci .v_max_out = 576, .h_max_out = 768, 1438c2ecf20Sopenharmony_ci } 1448c2ecf20Sopenharmony_ci}; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* bring hardware to a sane state. this has to be done, just in case someone 1478c2ecf20Sopenharmony_ci wants to capture from this device before it has been properly initialized. 1488c2ecf20Sopenharmony_ci the capture engine would badly fail, because no valid signal arrives on the 1498c2ecf20Sopenharmony_ci saa7146, thus leading to timeouts and stuff. */ 1508c2ecf20Sopenharmony_cistatic int hexium_init_done(struct saa7146_dev *dev) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci struct hexium *hexium = (struct hexium *) dev->ext_priv; 1538c2ecf20Sopenharmony_ci union i2c_smbus_data data; 1548c2ecf20Sopenharmony_ci int i = 0; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci DEB_D("hexium_init_done called\n"); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci /* initialize the helper ics to useful values */ 1598c2ecf20Sopenharmony_ci for (i = 0; i < sizeof(hexium_ks0127b); i++) { 1608c2ecf20Sopenharmony_ci data.byte = hexium_ks0127b[i]; 1618c2ecf20Sopenharmony_ci if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, i, I2C_SMBUS_BYTE_DATA, &data)) { 1628c2ecf20Sopenharmony_ci pr_err("hexium_init_done() failed for address 0x%02x\n", 1638c2ecf20Sopenharmony_ci i); 1648c2ecf20Sopenharmony_ci } 1658c2ecf20Sopenharmony_ci } 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci return 0; 1688c2ecf20Sopenharmony_ci} 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistatic int hexium_set_input(struct hexium *hexium, int input) 1718c2ecf20Sopenharmony_ci{ 1728c2ecf20Sopenharmony_ci union i2c_smbus_data data; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci DEB_D("\n"); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci data.byte = hexium_input_select[input].byte; 1778c2ecf20Sopenharmony_ci if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, hexium_input_select[input].adr, I2C_SMBUS_BYTE_DATA, &data)) { 1788c2ecf20Sopenharmony_ci return -1; 1798c2ecf20Sopenharmony_ci } 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci return 0; 1828c2ecf20Sopenharmony_ci} 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic int hexium_set_standard(struct hexium *hexium, struct hexium_data *vdec) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci union i2c_smbus_data data; 1878c2ecf20Sopenharmony_ci int i = 0; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci DEB_D("\n"); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci while (vdec[i].adr != -1) { 1928c2ecf20Sopenharmony_ci data.byte = vdec[i].byte; 1938c2ecf20Sopenharmony_ci if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, vdec[i].adr, I2C_SMBUS_BYTE_DATA, &data)) { 1948c2ecf20Sopenharmony_ci pr_err("hexium_init_done: hexium_set_standard() failed for address 0x%02x\n", 1958c2ecf20Sopenharmony_ci i); 1968c2ecf20Sopenharmony_ci return -1; 1978c2ecf20Sopenharmony_ci } 1988c2ecf20Sopenharmony_ci i++; 1998c2ecf20Sopenharmony_ci } 2008c2ecf20Sopenharmony_ci return 0; 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i) 2048c2ecf20Sopenharmony_ci{ 2058c2ecf20Sopenharmony_ci DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci if (i->index >= HEXIUM_INPUTS) 2088c2ecf20Sopenharmony_ci return -EINVAL; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input)); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci DEB_D("v4l2_ioctl: VIDIOC_ENUMINPUT %d\n", i->index); 2138c2ecf20Sopenharmony_ci return 0; 2148c2ecf20Sopenharmony_ci} 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cistatic int vidioc_g_input(struct file *file, void *fh, unsigned int *input) 2178c2ecf20Sopenharmony_ci{ 2188c2ecf20Sopenharmony_ci struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 2198c2ecf20Sopenharmony_ci struct hexium *hexium = (struct hexium *) dev->ext_priv; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci *input = hexium->cur_input; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci DEB_D("VIDIOC_G_INPUT: %d\n", *input); 2248c2ecf20Sopenharmony_ci return 0; 2258c2ecf20Sopenharmony_ci} 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_cistatic int vidioc_s_input(struct file *file, void *fh, unsigned int input) 2288c2ecf20Sopenharmony_ci{ 2298c2ecf20Sopenharmony_ci struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 2308c2ecf20Sopenharmony_ci struct hexium *hexium = (struct hexium *) dev->ext_priv; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci DEB_EE("VIDIOC_S_INPUT %d\n", input); 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci if (input >= HEXIUM_INPUTS) 2358c2ecf20Sopenharmony_ci return -EINVAL; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci hexium->cur_input = input; 2388c2ecf20Sopenharmony_ci hexium_set_input(hexium, input); 2398c2ecf20Sopenharmony_ci return 0; 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic struct saa7146_ext_vv vv_data; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/* this function only gets called when the probing was successful */ 2458c2ecf20Sopenharmony_cistatic int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info) 2468c2ecf20Sopenharmony_ci{ 2478c2ecf20Sopenharmony_ci struct hexium *hexium; 2488c2ecf20Sopenharmony_ci int ret; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci DEB_EE("\n"); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci hexium = kzalloc(sizeof(*hexium), GFP_KERNEL); 2538c2ecf20Sopenharmony_ci if (!hexium) 2548c2ecf20Sopenharmony_ci return -ENOMEM; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci dev->ext_priv = hexium; 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* enable i2c-port pins */ 2598c2ecf20Sopenharmony_ci saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26)); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci strscpy(hexium->i2c_adapter.name, "hexium gemini", 2628c2ecf20Sopenharmony_ci sizeof(hexium->i2c_adapter.name)); 2638c2ecf20Sopenharmony_ci saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480); 2648c2ecf20Sopenharmony_ci if (i2c_add_adapter(&hexium->i2c_adapter) < 0) { 2658c2ecf20Sopenharmony_ci DEB_S("cannot register i2c-device. skipping.\n"); 2668c2ecf20Sopenharmony_ci kfree(hexium); 2678c2ecf20Sopenharmony_ci return -EFAULT; 2688c2ecf20Sopenharmony_ci } 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci /* set HWControl GPIO number 2 */ 2718c2ecf20Sopenharmony_ci saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci saa7146_write(dev, DD1_INIT, 0x07000700); 2748c2ecf20Sopenharmony_ci saa7146_write(dev, DD1_STREAM_B, 0x00000000); 2758c2ecf20Sopenharmony_ci saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci /* the rest */ 2788c2ecf20Sopenharmony_ci hexium->cur_input = 0; 2798c2ecf20Sopenharmony_ci hexium_init_done(dev); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci hexium_set_standard(hexium, hexium_pal); 2828c2ecf20Sopenharmony_ci hexium->cur_std = V4L2_STD_PAL; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci hexium_set_input(hexium, 0); 2858c2ecf20Sopenharmony_ci hexium->cur_input = 0; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci ret = saa7146_vv_init(dev, &vv_data); 2888c2ecf20Sopenharmony_ci if (ret) { 2898c2ecf20Sopenharmony_ci i2c_del_adapter(&hexium->i2c_adapter); 2908c2ecf20Sopenharmony_ci kfree(hexium); 2918c2ecf20Sopenharmony_ci return ret; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input; 2958c2ecf20Sopenharmony_ci vv_data.vid_ops.vidioc_g_input = vidioc_g_input; 2968c2ecf20Sopenharmony_ci vv_data.vid_ops.vidioc_s_input = vidioc_s_input; 2978c2ecf20Sopenharmony_ci ret = saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_VIDEO); 2988c2ecf20Sopenharmony_ci if (ret < 0) { 2998c2ecf20Sopenharmony_ci pr_err("cannot register capture v4l2 device. skipping.\n"); 3008c2ecf20Sopenharmony_ci saa7146_vv_release(dev); 3018c2ecf20Sopenharmony_ci i2c_del_adapter(&hexium->i2c_adapter); 3028c2ecf20Sopenharmony_ci kfree(hexium); 3038c2ecf20Sopenharmony_ci return ret; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci pr_info("found 'hexium gemini' frame grabber-%d\n", hexium_num); 3078c2ecf20Sopenharmony_ci hexium_num++; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci return 0; 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_cistatic int hexium_detach(struct saa7146_dev *dev) 3138c2ecf20Sopenharmony_ci{ 3148c2ecf20Sopenharmony_ci struct hexium *hexium = (struct hexium *) dev->ext_priv; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci DEB_EE("dev:%p\n", dev); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci saa7146_unregister_device(&hexium->video_dev, dev); 3198c2ecf20Sopenharmony_ci saa7146_vv_release(dev); 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci hexium_num--; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci i2c_del_adapter(&hexium->i2c_adapter); 3248c2ecf20Sopenharmony_ci kfree(hexium); 3258c2ecf20Sopenharmony_ci return 0; 3268c2ecf20Sopenharmony_ci} 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_cistatic int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std) 3298c2ecf20Sopenharmony_ci{ 3308c2ecf20Sopenharmony_ci struct hexium *hexium = (struct hexium *) dev->ext_priv; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci if (V4L2_STD_PAL == std->id) { 3338c2ecf20Sopenharmony_ci hexium_set_standard(hexium, hexium_pal); 3348c2ecf20Sopenharmony_ci hexium->cur_std = V4L2_STD_PAL; 3358c2ecf20Sopenharmony_ci return 0; 3368c2ecf20Sopenharmony_ci } else if (V4L2_STD_NTSC == std->id) { 3378c2ecf20Sopenharmony_ci hexium_set_standard(hexium, hexium_ntsc); 3388c2ecf20Sopenharmony_ci hexium->cur_std = V4L2_STD_NTSC; 3398c2ecf20Sopenharmony_ci return 0; 3408c2ecf20Sopenharmony_ci } else if (V4L2_STD_SECAM == std->id) { 3418c2ecf20Sopenharmony_ci hexium_set_standard(hexium, hexium_secam); 3428c2ecf20Sopenharmony_ci hexium->cur_std = V4L2_STD_SECAM; 3438c2ecf20Sopenharmony_ci return 0; 3448c2ecf20Sopenharmony_ci } 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci return -1; 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistatic struct saa7146_extension hexium_extension; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic struct saa7146_pci_extension_data hexium_gemini_4bnc = { 3528c2ecf20Sopenharmony_ci .ext_priv = "Hexium Gemini (4 BNC)", 3538c2ecf20Sopenharmony_ci .ext = &hexium_extension, 3548c2ecf20Sopenharmony_ci}; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_cistatic struct saa7146_pci_extension_data hexium_gemini_dual_4bnc = { 3578c2ecf20Sopenharmony_ci .ext_priv = "Hexium Gemini Dual (4 BNC)", 3588c2ecf20Sopenharmony_ci .ext = &hexium_extension, 3598c2ecf20Sopenharmony_ci}; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistatic const struct pci_device_id pci_tbl[] = { 3628c2ecf20Sopenharmony_ci { 3638c2ecf20Sopenharmony_ci .vendor = PCI_VENDOR_ID_PHILIPS, 3648c2ecf20Sopenharmony_ci .device = PCI_DEVICE_ID_PHILIPS_SAA7146, 3658c2ecf20Sopenharmony_ci .subvendor = 0x17c8, 3668c2ecf20Sopenharmony_ci .subdevice = 0x2401, 3678c2ecf20Sopenharmony_ci .driver_data = (unsigned long) &hexium_gemini_4bnc, 3688c2ecf20Sopenharmony_ci }, 3698c2ecf20Sopenharmony_ci { 3708c2ecf20Sopenharmony_ci .vendor = PCI_VENDOR_ID_PHILIPS, 3718c2ecf20Sopenharmony_ci .device = PCI_DEVICE_ID_PHILIPS_SAA7146, 3728c2ecf20Sopenharmony_ci .subvendor = 0x17c8, 3738c2ecf20Sopenharmony_ci .subdevice = 0x2402, 3748c2ecf20Sopenharmony_ci .driver_data = (unsigned long) &hexium_gemini_dual_4bnc, 3758c2ecf20Sopenharmony_ci }, 3768c2ecf20Sopenharmony_ci { 3778c2ecf20Sopenharmony_ci .vendor = 0, 3788c2ecf20Sopenharmony_ci } 3798c2ecf20Sopenharmony_ci}; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, pci_tbl); 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_cistatic struct saa7146_ext_vv vv_data = { 3848c2ecf20Sopenharmony_ci .inputs = HEXIUM_INPUTS, 3858c2ecf20Sopenharmony_ci .capabilities = 0, 3868c2ecf20Sopenharmony_ci .stds = &hexium_standards[0], 3878c2ecf20Sopenharmony_ci .num_stds = ARRAY_SIZE(hexium_standards), 3888c2ecf20Sopenharmony_ci .std_callback = &std_callback, 3898c2ecf20Sopenharmony_ci}; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_cistatic struct saa7146_extension hexium_extension = { 3928c2ecf20Sopenharmony_ci .name = "hexium gemini", 3938c2ecf20Sopenharmony_ci .flags = SAA7146_USE_I2C_IRQ, 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci .pci_tbl = &pci_tbl[0], 3968c2ecf20Sopenharmony_ci .module = THIS_MODULE, 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci .attach = hexium_attach, 3998c2ecf20Sopenharmony_ci .detach = hexium_detach, 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci .irq_mask = 0, 4028c2ecf20Sopenharmony_ci .irq_func = NULL, 4038c2ecf20Sopenharmony_ci}; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_cistatic int __init hexium_init_module(void) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci if (0 != saa7146_register_extension(&hexium_extension)) { 4088c2ecf20Sopenharmony_ci DEB_S("failed to register extension\n"); 4098c2ecf20Sopenharmony_ci return -ENODEV; 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci return 0; 4138c2ecf20Sopenharmony_ci} 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_cistatic void __exit hexium_cleanup_module(void) 4168c2ecf20Sopenharmony_ci{ 4178c2ecf20Sopenharmony_ci saa7146_unregister_extension(&hexium_extension); 4188c2ecf20Sopenharmony_ci} 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_cimodule_init(hexium_init_module); 4218c2ecf20Sopenharmony_cimodule_exit(hexium_cleanup_module); 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("video4linux-2 driver for Hexium Gemini frame grabber cards"); 4248c2ecf20Sopenharmony_ciMODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 4258c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 426