Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | hexium_gemini.c - v4l2 driver for Hexium Gemini frame grabber cards |
Mauro Carvalho Chehab | a8733ca | 2006-03-17 10:37:02 -0300 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | Visit http://www.mihu.de/linux/saa7146/ and follow the link |
| 5 | to "hexium" for further details about this card. |
Mauro Carvalho Chehab | a8733ca | 2006-03-17 10:37:02 -0300 | [diff] [blame] | 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | Copyright (C) 2003 Michael Hunold <michael@mihu.de> |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #define DEBUG_VARIABLE debug |
| 27 | |
Mauro Carvalho Chehab | d647f0b | 2015-11-13 19:40:07 -0200 | [diff] [blame] | 28 | #include <media/drv-intf/saa7146_vv.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
Jérémy Lefaure | e40d14a | 2017-10-01 15:30:41 -0400 | [diff] [blame] | 30 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 32 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | module_param(debug, int, 0); |
| 34 | MODULE_PARM_DESC(debug, "debug verbosity"); |
| 35 | |
| 36 | /* global variables */ |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 37 | static int hexium_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #define HEXIUM_GEMINI 4 |
| 40 | #define HEXIUM_GEMINI_DUAL 5 |
| 41 | |
| 42 | #define HEXIUM_INPUTS 9 |
| 43 | static struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = { |
Hans Verkuil | 332e799 | 2012-05-01 14:49:28 -0300 | [diff] [blame] | 44 | { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 45 | { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 46 | { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 47 | { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 48 | { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 49 | { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 50 | { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 51 | { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
| 52 | { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 0, 0, V4L2_STD_ALL, 0, V4L2_IN_CAP_STD }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | #define HEXIUM_AUDIOS 0 |
| 56 | |
| 57 | struct hexium_data |
| 58 | { |
| 59 | s8 adr; |
| 60 | u8 byte; |
| 61 | }; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define HEXIUM_GEMINI_V_1_0 1 |
| 64 | #define HEXIUM_GEMINI_DUAL_V_1_0 2 |
| 65 | |
| 66 | struct hexium |
| 67 | { |
| 68 | int type; |
| 69 | |
Hans Verkuil | 3ae863e | 2015-03-09 13:33:57 -0300 | [diff] [blame] | 70 | struct video_device video_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | struct i2c_adapter i2c_adapter; |
Mauro Carvalho Chehab | a8733ca | 2006-03-17 10:37:02 -0300 | [diff] [blame] | 72 | |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 73 | int cur_input; /* current input */ |
| 74 | v4l2_std_id cur_std; /* current standard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* Samsung KS0127B decoder default registers */ |
| 78 | static u8 hexium_ks0127b[0x100]={ |
| 79 | /*00*/ 0x00,0x52,0x30,0x40,0x01,0x0C,0x2A,0x10, |
| 80 | /*08*/ 0x00,0x00,0x00,0x60,0x00,0x00,0x0F,0x06, |
| 81 | /*10*/ 0x00,0x00,0xE4,0xC0,0x00,0x00,0x00,0x00, |
| 82 | /*18*/ 0x14,0x9B,0xFE,0xFF,0xFC,0xFF,0x03,0x22, |
| 83 | /*20*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 84 | /*28*/ 0x00,0x00,0x00,0x00,0x00,0x2C,0x9B,0x00, |
| 85 | /*30*/ 0x00,0x00,0x10,0x80,0x80,0x10,0x80,0x80, |
| 86 | /*38*/ 0x01,0x04,0x00,0x00,0x00,0x29,0xC0,0x00, |
| 87 | /*40*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 88 | /*48*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 89 | /*50*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 90 | /*58*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 91 | /*60*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 92 | /*68*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 93 | /*70*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 94 | /*78*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 95 | /*80*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 96 | /*88*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 97 | /*90*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 98 | /*98*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 99 | /*A0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 100 | /*A8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 101 | /*B0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 102 | /*B8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 103 | /*C0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 104 | /*C8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 105 | /*D0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 106 | /*D8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 107 | /*E0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 108 | /*E8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 109 | /*F0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 110 | /*F8*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 |
| 111 | }; |
| 112 | |
| 113 | static struct hexium_data hexium_pal[] = { |
| 114 | { 0x01, 0x52 }, { 0x12, 0x64 }, { 0x2D, 0x2C }, { 0x2E, 0x9B }, { -1 , 0xFF } |
| 115 | }; |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | static struct hexium_data hexium_ntsc[] = { |
| 118 | { 0x01, 0x53 }, { 0x12, 0x04 }, { 0x2D, 0x23 }, { 0x2E, 0x81 }, { -1 , 0xFF } |
| 119 | }; |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | static struct hexium_data hexium_secam[] = { |
| 122 | { 0x01, 0x52 }, { 0x12, 0x64 }, { 0x2D, 0x2C }, { 0x2E, 0x9B }, { -1 , 0xFF } |
| 123 | }; |
| 124 | |
| 125 | static struct hexium_data hexium_input_select[] = { |
| 126 | { 0x02, 0x60 }, |
| 127 | { 0x02, 0x64 }, |
| 128 | { 0x02, 0x61 }, |
| 129 | { 0x02, 0x65 }, |
| 130 | { 0x02, 0x62 }, |
| 131 | { 0x02, 0x66 }, |
| 132 | { 0x02, 0x68 }, |
| 133 | { 0x02, 0x69 }, |
| 134 | { 0x02, 0x6A }, |
| 135 | }; |
| 136 | |
| 137 | /* fixme: h_offset = 0 for Hexium Gemini *Dual*, which |
| 138 | are currently *not* supported*/ |
| 139 | static struct saa7146_standard hexium_standards[] = { |
| 140 | { |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 141 | .name = "PAL", .id = V4L2_STD_PAL, |
| 142 | .v_offset = 28, .v_field = 288, |
| 143 | .h_offset = 1, .h_pixels = 680, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | .v_max_out = 576, .h_max_out = 768, |
| 145 | }, { |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 146 | .name = "NTSC", .id = V4L2_STD_NTSC, |
| 147 | .v_offset = 28, .v_field = 240, |
| 148 | .h_offset = 1, .h_pixels = 640, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | .v_max_out = 480, .h_max_out = 640, |
| 150 | }, { |
Mauro Carvalho Chehab | 6e6a8b5 | 2018-01-04 13:08:56 -0500 | [diff] [blame] | 151 | .name = "SECAM", .id = V4L2_STD_SECAM, |
| 152 | .v_offset = 28, .v_field = 288, |
| 153 | .h_offset = 1, .h_pixels = 720, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | .v_max_out = 576, .h_max_out = 768, |
| 155 | } |
Mauro Carvalho Chehab | a8733ca | 2006-03-17 10:37:02 -0300 | [diff] [blame] | 156 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | /* bring hardware to a sane state. this has to be done, just in case someone |
| 159 | wants to capture from this device before it has been properly initialized. |
| 160 | the capture engine would badly fail, because no valid signal arrives on the |
| 161 | saa7146, thus leading to timeouts and stuff. */ |
| 162 | static int hexium_init_done(struct saa7146_dev *dev) |
| 163 | { |
| 164 | struct hexium *hexium = (struct hexium *) dev->ext_priv; |
| 165 | union i2c_smbus_data data; |
| 166 | int i = 0; |
| 167 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 168 | DEB_D("hexium_init_done called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /* initialize the helper ics to useful values */ |
| 171 | for (i = 0; i < sizeof(hexium_ks0127b); i++) { |
| 172 | data.byte = hexium_ks0127b[i]; |
| 173 | if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, i, I2C_SMBUS_BYTE_DATA, &data)) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 174 | pr_err("hexium_init_done() failed for address 0x%02x\n", |
| 175 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | static int hexium_set_input(struct hexium *hexium, int input) |
| 183 | { |
| 184 | union i2c_smbus_data data; |
| 185 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 186 | DEB_D("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | data.byte = hexium_input_select[input].byte; |
| 189 | if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, hexium_input_select[input].adr, I2C_SMBUS_BYTE_DATA, &data)) { |
| 190 | return -1; |
| 191 | } |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static int hexium_set_standard(struct hexium *hexium, struct hexium_data *vdec) |
| 197 | { |
| 198 | union i2c_smbus_data data; |
| 199 | int i = 0; |
| 200 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 201 | DEB_D("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | while (vdec[i].adr != -1) { |
| 204 | data.byte = vdec[i].byte; |
| 205 | if (0 != i2c_smbus_xfer(&hexium->i2c_adapter, 0x6c, 0, I2C_SMBUS_WRITE, vdec[i].adr, I2C_SMBUS_BYTE_DATA, &data)) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 206 | pr_err("hexium_init_done: hexium_set_standard() failed for address 0x%02x\n", |
| 207 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return -1; |
| 209 | } |
| 210 | i++; |
| 211 | } |
| 212 | return 0; |
| 213 | } |
| 214 | |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 215 | static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i) |
| 216 | { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 217 | DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 218 | |
Roel Kluin | 223ffe5 | 2009-05-02 16:38:47 -0300 | [diff] [blame] | 219 | if (i->index >= HEXIUM_INPUTS) |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 220 | return -EINVAL; |
| 221 | |
| 222 | memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input)); |
| 223 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 224 | DEB_D("v4l2_ioctl: VIDIOC_ENUMINPUT %d\n", i->index); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static int vidioc_g_input(struct file *file, void *fh, unsigned int *input) |
| 229 | { |
| 230 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 231 | struct hexium *hexium = (struct hexium *) dev->ext_priv; |
| 232 | |
| 233 | *input = hexium->cur_input; |
| 234 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 235 | DEB_D("VIDIOC_G_INPUT: %d\n", *input); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int vidioc_s_input(struct file *file, void *fh, unsigned int input) |
| 240 | { |
| 241 | struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; |
| 242 | struct hexium *hexium = (struct hexium *) dev->ext_priv; |
| 243 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 244 | DEB_EE("VIDIOC_S_INPUT %d\n", input); |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 245 | |
Roel Kluin | f14a297 | 2009-10-23 07:59:42 -0300 | [diff] [blame] | 246 | if (input >= HEXIUM_INPUTS) |
Hans Verkuil | b960074 | 2009-01-18 19:59:11 -0300 | [diff] [blame] | 247 | return -EINVAL; |
| 248 | |
| 249 | hexium->cur_input = input; |
| 250 | hexium_set_input(hexium, input); |
| 251 | return 0; |
| 252 | } |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | static struct saa7146_ext_vv vv_data; |
| 255 | |
| 256 | /* this function only gets called when the probing was successful */ |
| 257 | static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info) |
| 258 | { |
Julia Lawall | f00fd91 | 2011-08-04 07:29:33 -0300 | [diff] [blame] | 259 | struct hexium *hexium; |
Hans Verkuil | cd7d9beb | 2010-02-20 07:56:25 -0300 | [diff] [blame] | 260 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 262 | DEB_EE("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Markus Elfring | 2d3da59 | 2017-08-28 05:55:16 -0400 | [diff] [blame] | 264 | hexium = kzalloc(sizeof(*hexium), GFP_KERNEL); |
Markus Elfring | c38e865 | 2017-08-28 05:46:57 -0400 | [diff] [blame] | 265 | if (!hexium) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | return -ENOMEM; |
Markus Elfring | c38e865 | 2017-08-28 05:46:57 -0400 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | dev->ext_priv = hexium; |
| 269 | |
| 270 | /* enable i2c-port pins */ |
| 271 | saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26)); |
| 272 | |
Arnd Bergmann | 03aa4f1 | 2019-02-19 12:01:56 -0500 | [diff] [blame^] | 273 | strscpy(hexium->i2c_adapter.name, "hexium gemini", |
| 274 | sizeof(hexium->i2c_adapter.name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480); |
| 276 | if (i2c_add_adapter(&hexium->i2c_adapter) < 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 277 | DEB_S("cannot register i2c-device. skipping.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | kfree(hexium); |
| 279 | return -EFAULT; |
| 280 | } |
| 281 | |
| 282 | /* set HWControl GPIO number 2 */ |
| 283 | saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI); |
| 284 | |
| 285 | saa7146_write(dev, DD1_INIT, 0x07000700); |
| 286 | saa7146_write(dev, DD1_STREAM_B, 0x00000000); |
| 287 | saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); |
| 288 | |
| 289 | /* the rest */ |
| 290 | hexium->cur_input = 0; |
| 291 | hexium_init_done(dev); |
| 292 | |
| 293 | hexium_set_standard(hexium, hexium_pal); |
| 294 | hexium->cur_std = V4L2_STD_PAL; |
| 295 | |
| 296 | hexium_set_input(hexium, 0); |
| 297 | hexium->cur_input = 0; |
| 298 | |
| 299 | saa7146_vv_init(dev, &vv_data); |
Hans Verkuil | 332e799 | 2012-05-01 14:49:28 -0300 | [diff] [blame] | 300 | |
Hans Verkuil | ab49ae0 | 2012-05-01 12:57:57 -0300 | [diff] [blame] | 301 | vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input; |
| 302 | vv_data.vid_ops.vidioc_g_input = vidioc_g_input; |
| 303 | vv_data.vid_ops.vidioc_s_input = vidioc_s_input; |
Hans Verkuil | cd7d9beb | 2010-02-20 07:56:25 -0300 | [diff] [blame] | 304 | ret = saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER); |
| 305 | if (ret < 0) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 306 | pr_err("cannot register capture v4l2 device. skipping.\n"); |
Hans Verkuil | cd7d9beb | 2010-02-20 07:56:25 -0300 | [diff] [blame] | 307 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 310 | pr_info("found 'hexium gemini' frame grabber-%d\n", hexium_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | hexium_num++; |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int hexium_detach(struct saa7146_dev *dev) |
| 317 | { |
| 318 | struct hexium *hexium = (struct hexium *) dev->ext_priv; |
| 319 | |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 320 | DEB_EE("dev:%p\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | saa7146_unregister_device(&hexium->video_dev, dev); |
| 323 | saa7146_vv_release(dev); |
| 324 | |
| 325 | hexium_num--; |
| 326 | |
| 327 | i2c_del_adapter(&hexium->i2c_adapter); |
| 328 | kfree(hexium); |
| 329 | return 0; |
| 330 | } |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std) |
| 333 | { |
| 334 | struct hexium *hexium = (struct hexium *) dev->ext_priv; |
| 335 | |
| 336 | if (V4L2_STD_PAL == std->id) { |
| 337 | hexium_set_standard(hexium, hexium_pal); |
| 338 | hexium->cur_std = V4L2_STD_PAL; |
| 339 | return 0; |
| 340 | } else if (V4L2_STD_NTSC == std->id) { |
| 341 | hexium_set_standard(hexium, hexium_ntsc); |
| 342 | hexium->cur_std = V4L2_STD_NTSC; |
| 343 | return 0; |
| 344 | } else if (V4L2_STD_SECAM == std->id) { |
| 345 | hexium_set_standard(hexium, hexium_secam); |
| 346 | hexium->cur_std = V4L2_STD_SECAM; |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | return -1; |
| 351 | } |
| 352 | |
| 353 | static struct saa7146_extension hexium_extension; |
| 354 | |
| 355 | static struct saa7146_pci_extension_data hexium_gemini_4bnc = { |
| 356 | .ext_priv = "Hexium Gemini (4 BNC)", |
| 357 | .ext = &hexium_extension, |
| 358 | }; |
| 359 | |
| 360 | static struct saa7146_pci_extension_data hexium_gemini_dual_4bnc = { |
| 361 | .ext_priv = "Hexium Gemini Dual (4 BNC)", |
| 362 | .ext = &hexium_extension, |
| 363 | }; |
| 364 | |
Arvind Yadav | c6e3bdb | 2017-08-02 13:14:57 -0400 | [diff] [blame] | 365 | static const struct pci_device_id pci_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | { |
| 367 | .vendor = PCI_VENDOR_ID_PHILIPS, |
| 368 | .device = PCI_DEVICE_ID_PHILIPS_SAA7146, |
| 369 | .subvendor = 0x17c8, |
| 370 | .subdevice = 0x2401, |
| 371 | .driver_data = (unsigned long) &hexium_gemini_4bnc, |
| 372 | }, |
| 373 | { |
| 374 | .vendor = PCI_VENDOR_ID_PHILIPS, |
| 375 | .device = PCI_DEVICE_ID_PHILIPS_SAA7146, |
| 376 | .subvendor = 0x17c8, |
| 377 | .subdevice = 0x2402, |
| 378 | .driver_data = (unsigned long) &hexium_gemini_dual_4bnc, |
| 379 | }, |
| 380 | { |
| 381 | .vendor = 0, |
| 382 | } |
| 383 | }; |
| 384 | |
| 385 | MODULE_DEVICE_TABLE(pci, pci_tbl); |
| 386 | |
| 387 | static struct saa7146_ext_vv vv_data = { |
| 388 | .inputs = HEXIUM_INPUTS, |
| 389 | .capabilities = 0, |
| 390 | .stds = &hexium_standards[0], |
Jérémy Lefaure | e40d14a | 2017-10-01 15:30:41 -0400 | [diff] [blame] | 391 | .num_stds = ARRAY_SIZE(hexium_standards), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | .std_callback = &std_callback, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | static struct saa7146_extension hexium_extension = { |
| 396 | .name = "hexium gemini", |
| 397 | .flags = SAA7146_USE_I2C_IRQ, |
| 398 | |
| 399 | .pci_tbl = &pci_tbl[0], |
| 400 | .module = THIS_MODULE, |
| 401 | |
| 402 | .attach = hexium_attach, |
| 403 | .detach = hexium_detach, |
| 404 | |
| 405 | .irq_mask = 0, |
| 406 | .irq_func = NULL, |
| 407 | }; |
| 408 | |
| 409 | static int __init hexium_init_module(void) |
| 410 | { |
| 411 | if (0 != saa7146_register_extension(&hexium_extension)) { |
Joe Perches | 44d0b80 | 2011-08-21 19:56:44 -0300 | [diff] [blame] | 412 | DEB_S("failed to register extension\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return -ENODEV; |
| 414 | } |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static void __exit hexium_cleanup_module(void) |
| 420 | { |
| 421 | saa7146_unregister_extension(&hexium_extension); |
| 422 | } |
| 423 | |
| 424 | module_init(hexium_init_module); |
| 425 | module_exit(hexium_cleanup_module); |
| 426 | |
| 427 | MODULE_DESCRIPTION("video4linux-2 driver for Hexium Gemini frame grabber cards"); |
| 428 | MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); |
| 429 | MODULE_LICENSE("GPL"); |