Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1 | /* |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 2 | cx231xx-cards.c - driver for Conexant Cx23100/101/102 |
| 3 | USB video capture devices |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 4 | |
| 5 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 6 | Based on em28xx driver |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/i2c.h> |
| 28 | #include <linux/usb.h> |
| 29 | #include <media/tuner.h> |
| 30 | #include <media/tveeprom.h> |
| 31 | #include <media/v4l2-common.h> |
| 32 | #include <media/v4l2-chip-ident.h> |
| 33 | |
| 34 | #include <media/cx25840.h> |
Mauro Carvalho Chehab | 3bfb317 | 2010-09-03 10:50:24 -0300 | [diff] [blame] | 35 | #include "dvb-usb-ids.h" |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 36 | #include "xc5000.h" |
| 37 | |
| 38 | #include "cx231xx.h" |
| 39 | |
| 40 | static int tuner = -1; |
| 41 | module_param(tuner, int, 0444); |
| 42 | MODULE_PARM_DESC(tuner, "tuner type"); |
| 43 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 44 | static int transfer_mode = 1; |
| 45 | module_param(transfer_mode, int, 0444); |
| 46 | MODULE_PARM_DESC(transfer_mode, "transfer mode (1-ISO or 0-BULK)"); |
| 47 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 48 | static unsigned int disable_ir; |
| 49 | module_param(disable_ir, int, 0444); |
| 50 | MODULE_PARM_DESC(disable_ir, "disable infrared remote support"); |
| 51 | |
| 52 | /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */ |
| 53 | static unsigned long cx231xx_devused; |
| 54 | |
| 55 | /* |
| 56 | * Reset sequences for analog/digital modes |
| 57 | */ |
| 58 | |
| 59 | static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 60 | {0x03, 0x01, 10}, |
| 61 | {0x03, 0x00, 30}, |
| 62 | {0x03, 0x01, 10}, |
| 63 | {-1, -1, -1}, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 64 | }; |
| 65 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 66 | /* |
| 67 | * Board definitions |
| 68 | */ |
| 69 | struct cx231xx_board cx231xx_boards[] = { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 70 | [CX231XX_BOARD_UNKNOWN] = { |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 71 | .name = "Unknown CX231xx video grabber", |
| 72 | .tuner_type = TUNER_ABSENT, |
| 73 | .input = {{ |
| 74 | .type = CX231XX_VMUX_TELEVISION, |
| 75 | .vmux = CX231XX_VIN_3_1, |
| 76 | .amux = CX231XX_AMUX_VIDEO, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 77 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 78 | }, { |
| 79 | .type = CX231XX_VMUX_COMPOSITE1, |
| 80 | .vmux = CX231XX_VIN_2_1, |
| 81 | .amux = CX231XX_AMUX_LINE_IN, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 82 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 83 | }, { |
| 84 | .type = CX231XX_VMUX_SVIDEO, |
| 85 | .vmux = CX231XX_VIN_1_1 | |
| 86 | (CX231XX_VIN_1_2 << 8) | |
| 87 | CX25840_SVIDEO_ON, |
| 88 | .amux = CX231XX_AMUX_LINE_IN, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 89 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 90 | } |
| 91 | }, |
| 92 | }, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 93 | [CX231XX_BOARD_CNXT_CARRAERA] = { |
| 94 | .name = "Conexant Hybrid TV - CARRAERA", |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 95 | .tuner_type = TUNER_XC5000, |
| 96 | .tuner_addr = 0x61, |
| 97 | .tuner_gpio = RDE250_XCV_TUNER, |
| 98 | .tuner_sif_gpio = 0x05, |
| 99 | .tuner_scl_gpio = 0x1a, |
| 100 | .tuner_sda_gpio = 0x1b, |
| 101 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 102 | .output_mode = OUT_MODE_VIP11, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 103 | .demod_xfer_mode = 0, |
| 104 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 105 | .agc_analog_digital_select_gpio = 0x0c, |
| 106 | .gpio_pin_status_mask = 0x4001000, |
| 107 | .tuner_i2c_master = 1, |
| 108 | .demod_i2c_master = 2, |
| 109 | .has_dvb = 1, |
| 110 | .demod_addr = 0x02, |
| 111 | .norm = V4L2_STD_PAL, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 112 | |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 113 | .input = {{ |
| 114 | .type = CX231XX_VMUX_TELEVISION, |
| 115 | .vmux = CX231XX_VIN_3_1, |
| 116 | .amux = CX231XX_AMUX_VIDEO, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 117 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 118 | }, { |
| 119 | .type = CX231XX_VMUX_COMPOSITE1, |
| 120 | .vmux = CX231XX_VIN_2_1, |
| 121 | .amux = CX231XX_AMUX_LINE_IN, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 122 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 123 | }, { |
| 124 | .type = CX231XX_VMUX_SVIDEO, |
| 125 | .vmux = CX231XX_VIN_1_1 | |
| 126 | (CX231XX_VIN_1_2 << 8) | |
| 127 | CX25840_SVIDEO_ON, |
| 128 | .amux = CX231XX_AMUX_LINE_IN, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 129 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 130 | } |
| 131 | }, |
| 132 | }, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 133 | [CX231XX_BOARD_CNXT_SHELBY] = { |
| 134 | .name = "Conexant Hybrid TV - SHELBY", |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 135 | .tuner_type = TUNER_XC5000, |
| 136 | .tuner_addr = 0x61, |
| 137 | .tuner_gpio = RDE250_XCV_TUNER, |
| 138 | .tuner_sif_gpio = 0x05, |
| 139 | .tuner_scl_gpio = 0x1a, |
| 140 | .tuner_sda_gpio = 0x1b, |
| 141 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 142 | .output_mode = OUT_MODE_VIP11, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 143 | .demod_xfer_mode = 0, |
| 144 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 145 | .agc_analog_digital_select_gpio = 0x0c, |
| 146 | .gpio_pin_status_mask = 0x4001000, |
| 147 | .tuner_i2c_master = 1, |
| 148 | .demod_i2c_master = 2, |
| 149 | .has_dvb = 1, |
| 150 | .demod_addr = 0x32, |
| 151 | .norm = V4L2_STD_NTSC, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 152 | |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 153 | .input = {{ |
| 154 | .type = CX231XX_VMUX_TELEVISION, |
| 155 | .vmux = CX231XX_VIN_3_1, |
| 156 | .amux = CX231XX_AMUX_VIDEO, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 157 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 158 | }, { |
| 159 | .type = CX231XX_VMUX_COMPOSITE1, |
| 160 | .vmux = CX231XX_VIN_2_1, |
| 161 | .amux = CX231XX_AMUX_LINE_IN, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 162 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 163 | }, { |
| 164 | .type = CX231XX_VMUX_SVIDEO, |
| 165 | .vmux = CX231XX_VIN_1_1 | |
| 166 | (CX231XX_VIN_1_2 << 8) | |
| 167 | CX25840_SVIDEO_ON, |
| 168 | .amux = CX231XX_AMUX_LINE_IN, |
Márton Németh | 7ee0a28 | 2009-12-13 17:06:10 -0300 | [diff] [blame] | 169 | .gpio = NULL, |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 170 | } |
| 171 | }, |
| 172 | }, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 173 | [CX231XX_BOARD_CNXT_RDE_253S] = { |
| 174 | .name = "Conexant Hybrid TV - RDE253S", |
| 175 | .tuner_type = TUNER_NXP_TDA18271, |
| 176 | .tuner_addr = 0x60, |
| 177 | .tuner_gpio = RDE250_XCV_TUNER, |
| 178 | .tuner_sif_gpio = 0x05, |
| 179 | .tuner_scl_gpio = 0x1a, |
| 180 | .tuner_sda_gpio = 0x1b, |
| 181 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 182 | .output_mode = OUT_MODE_VIP11, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 183 | .demod_xfer_mode = 0, |
| 184 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 185 | .agc_analog_digital_select_gpio = 0x1c, |
| 186 | .gpio_pin_status_mask = 0x4001000, |
| 187 | .tuner_i2c_master = 1, |
| 188 | .demod_i2c_master = 2, |
| 189 | .has_dvb = 1, |
| 190 | .demod_addr = 0x02, |
| 191 | .norm = V4L2_STD_PAL, |
| 192 | |
| 193 | .input = {{ |
| 194 | .type = CX231XX_VMUX_TELEVISION, |
| 195 | .vmux = CX231XX_VIN_3_1, |
| 196 | .amux = CX231XX_AMUX_VIDEO, |
| 197 | .gpio = NULL, |
| 198 | }, { |
| 199 | .type = CX231XX_VMUX_COMPOSITE1, |
| 200 | .vmux = CX231XX_VIN_2_1, |
| 201 | .amux = CX231XX_AMUX_LINE_IN, |
| 202 | .gpio = NULL, |
| 203 | }, { |
| 204 | .type = CX231XX_VMUX_SVIDEO, |
| 205 | .vmux = CX231XX_VIN_1_1 | |
| 206 | (CX231XX_VIN_1_2 << 8) | |
| 207 | CX25840_SVIDEO_ON, |
| 208 | .amux = CX231XX_AMUX_LINE_IN, |
| 209 | .gpio = NULL, |
| 210 | } |
| 211 | }, |
| 212 | }, |
| 213 | |
| 214 | [CX231XX_BOARD_CNXT_RDU_253S] = { |
| 215 | .name = "Conexant Hybrid TV - RDU253S", |
| 216 | .tuner_type = TUNER_NXP_TDA18271, |
| 217 | .tuner_addr = 0x60, |
| 218 | .tuner_gpio = RDE250_XCV_TUNER, |
| 219 | .tuner_sif_gpio = 0x05, |
| 220 | .tuner_scl_gpio = 0x1a, |
| 221 | .tuner_sda_gpio = 0x1b, |
| 222 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 223 | .output_mode = OUT_MODE_VIP11, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 224 | .demod_xfer_mode = 0, |
| 225 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 226 | .agc_analog_digital_select_gpio = 0x1c, |
| 227 | .gpio_pin_status_mask = 0x4001000, |
| 228 | .tuner_i2c_master = 1, |
| 229 | .demod_i2c_master = 2, |
| 230 | .has_dvb = 1, |
| 231 | .demod_addr = 0x02, |
| 232 | .norm = V4L2_STD_PAL, |
| 233 | |
| 234 | .input = {{ |
| 235 | .type = CX231XX_VMUX_TELEVISION, |
| 236 | .vmux = CX231XX_VIN_3_1, |
| 237 | .amux = CX231XX_AMUX_VIDEO, |
| 238 | .gpio = NULL, |
| 239 | }, { |
| 240 | .type = CX231XX_VMUX_COMPOSITE1, |
| 241 | .vmux = CX231XX_VIN_2_1, |
| 242 | .amux = CX231XX_AMUX_LINE_IN, |
| 243 | .gpio = NULL, |
| 244 | }, { |
| 245 | .type = CX231XX_VMUX_SVIDEO, |
| 246 | .vmux = CX231XX_VIN_1_1 | |
| 247 | (CX231XX_VIN_1_2 << 8) | |
| 248 | CX25840_SVIDEO_ON, |
| 249 | .amux = CX231XX_AMUX_LINE_IN, |
| 250 | .gpio = NULL, |
| 251 | } |
| 252 | }, |
| 253 | }, |
| 254 | [CX231XX_BOARD_CNXT_VIDEO_GRABBER] = { |
| 255 | .name = "Conexant VIDEO GRABBER", |
Devin Heitmueller | 9f51259 | 2010-08-18 18:04:04 -0300 | [diff] [blame^] | 256 | .tuner_type = TUNER_ABSENT, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 257 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 258 | .output_mode = OUT_MODE_VIP11, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 259 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 260 | .agc_analog_digital_select_gpio = 0x1c, |
| 261 | .gpio_pin_status_mask = 0x4001000, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 262 | .norm = V4L2_STD_PAL, |
| 263 | |
| 264 | .input = {{ |
| 265 | .type = CX231XX_VMUX_COMPOSITE1, |
| 266 | .vmux = CX231XX_VIN_2_1, |
| 267 | .amux = CX231XX_AMUX_LINE_IN, |
| 268 | .gpio = NULL, |
| 269 | }, { |
| 270 | .type = CX231XX_VMUX_SVIDEO, |
| 271 | .vmux = CX231XX_VIN_1_1 | |
| 272 | (CX231XX_VIN_1_2 << 8) | |
| 273 | CX25840_SVIDEO_ON, |
| 274 | .amux = CX231XX_AMUX_LINE_IN, |
| 275 | .gpio = NULL, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 276 | } |
| 277 | }, |
| 278 | }, |
| 279 | [CX231XX_BOARD_CNXT_RDE_250] = { |
| 280 | .name = "Conexant Hybrid TV - rde 250", |
| 281 | .tuner_type = TUNER_XC5000, |
| 282 | .tuner_addr = 0x61, |
| 283 | .tuner_gpio = RDE250_XCV_TUNER, |
| 284 | .tuner_sif_gpio = 0x05, |
| 285 | .tuner_scl_gpio = 0x1a, |
| 286 | .tuner_sda_gpio = 0x1b, |
| 287 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 288 | .output_mode = OUT_MODE_VIP11, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 289 | .demod_xfer_mode = 0, |
| 290 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 291 | .agc_analog_digital_select_gpio = 0x0c, |
| 292 | .gpio_pin_status_mask = 0x4001000, |
| 293 | .tuner_i2c_master = 1, |
| 294 | .demod_i2c_master = 2, |
| 295 | .has_dvb = 1, |
| 296 | .demod_addr = 0x02, |
| 297 | .norm = V4L2_STD_PAL, |
| 298 | |
| 299 | .input = {{ |
| 300 | .type = CX231XX_VMUX_TELEVISION, |
| 301 | .vmux = CX231XX_VIN_2_1, |
| 302 | .amux = CX231XX_AMUX_VIDEO, |
| 303 | .gpio = NULL, |
| 304 | } |
| 305 | }, |
| 306 | }, |
| 307 | [CX231XX_BOARD_CNXT_RDU_250] = { |
| 308 | .name = "Conexant Hybrid TV - RDU 250", |
| 309 | .tuner_type = TUNER_XC5000, |
| 310 | .tuner_addr = 0x61, |
| 311 | .tuner_gpio = RDE250_XCV_TUNER, |
| 312 | .tuner_sif_gpio = 0x05, |
| 313 | .tuner_scl_gpio = 0x1a, |
| 314 | .tuner_sda_gpio = 0x1b, |
| 315 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 316 | .output_mode = OUT_MODE_VIP11, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 317 | .demod_xfer_mode = 0, |
| 318 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 319 | .agc_analog_digital_select_gpio = 0x0c, |
| 320 | .gpio_pin_status_mask = 0x4001000, |
| 321 | .tuner_i2c_master = 1, |
| 322 | .demod_i2c_master = 2, |
| 323 | .has_dvb = 1, |
| 324 | .demod_addr = 0x32, |
| 325 | .norm = V4L2_STD_NTSC, |
| 326 | |
| 327 | .input = {{ |
| 328 | .type = CX231XX_VMUX_TELEVISION, |
| 329 | .vmux = CX231XX_VIN_2_1, |
| 330 | .amux = CX231XX_AMUX_VIDEO, |
| 331 | .gpio = NULL, |
| 332 | } |
| 333 | }, |
| 334 | }, |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 335 | [CX231XX_BOARD_HAUPPAUGE_EXETER] = { |
| 336 | .name = "Hauppauge EXETER", |
| 337 | .tuner_type = TUNER_NXP_TDA18271, |
| 338 | .tuner_addr = 0x60, |
| 339 | .tuner_gpio = RDE250_XCV_TUNER, |
| 340 | .tuner_sif_gpio = 0x05, |
| 341 | .tuner_scl_gpio = 0x1a, |
| 342 | .tuner_sda_gpio = 0x1b, |
| 343 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 344 | .output_mode = OUT_MODE_VIP11, |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 345 | .demod_xfer_mode = 0, |
| 346 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 347 | .agc_analog_digital_select_gpio = 0x0c, |
| 348 | .gpio_pin_status_mask = 0x4001000, |
| 349 | .tuner_i2c_master = 1, |
| 350 | .demod_i2c_master = 2, |
| 351 | .has_dvb = 1, |
| 352 | .demod_addr = 0x0e, |
| 353 | .norm = V4L2_STD_NTSC, |
| 354 | |
| 355 | .input = {{ |
| 356 | .type = CX231XX_VMUX_TELEVISION, |
| 357 | .vmux = CX231XX_VIN_3_1, |
| 358 | .amux = CX231XX_AMUX_VIDEO, |
| 359 | .gpio = 0, |
| 360 | }, { |
| 361 | .type = CX231XX_VMUX_COMPOSITE1, |
| 362 | .vmux = CX231XX_VIN_2_1, |
| 363 | .amux = CX231XX_AMUX_LINE_IN, |
| 364 | .gpio = 0, |
| 365 | }, { |
| 366 | .type = CX231XX_VMUX_SVIDEO, |
| 367 | .vmux = CX231XX_VIN_1_1 | |
| 368 | (CX231XX_VIN_1_2 << 8) | |
| 369 | CX25840_SVIDEO_ON, |
| 370 | .amux = CX231XX_AMUX_LINE_IN, |
| 371 | .gpio = 0, |
| 372 | } }, |
| 373 | }, |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 374 | [CX231XX_BOARD_HAUPPAUGE_USBLIVE2] = { |
| 375 | .name = "Hauppauge USB Live 2", |
| 376 | .tuner_type = TUNER_ABSENT, |
| 377 | .decoder = CX231XX_AVDECODER, |
Devin Heitmueller | 8880621 | 2010-08-18 17:50:07 -0300 | [diff] [blame] | 378 | .output_mode = OUT_MODE_VIP11, |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 379 | .demod_xfer_mode = 0, |
| 380 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 381 | .agc_analog_digital_select_gpio = 0x0c, |
| 382 | .gpio_pin_status_mask = 0x4001000, |
| 383 | .norm = V4L2_STD_NTSC, |
| 384 | .input = {{ |
| 385 | .type = CX231XX_VMUX_COMPOSITE1, |
| 386 | .vmux = CX231XX_VIN_2_1, |
| 387 | .amux = CX231XX_AMUX_LINE_IN, |
| 388 | .gpio = 0, |
| 389 | }, { |
| 390 | .type = CX231XX_VMUX_SVIDEO, |
| 391 | .vmux = CX231XX_VIN_1_1 | |
| 392 | (CX231XX_VIN_1_2 << 8) | |
| 393 | CX25840_SVIDEO_ON, |
| 394 | .amux = CX231XX_AMUX_LINE_IN, |
| 395 | .gpio = 0, |
| 396 | } }, |
| 397 | }, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 398 | }; |
| 399 | const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); |
| 400 | |
| 401 | /* table of devices that work with this driver */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 402 | struct usb_device_id cx231xx_id_table[] = { |
Sri Deevi | ed559ed | 2009-03-13 18:35:14 -0300 | [diff] [blame] | 403 | {USB_DEVICE(0x0572, 0x5A3C), |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 404 | .driver_info = CX231XX_BOARD_UNKNOWN}, |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 405 | {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000,0x4fff), |
| 406 | .driver_info = CX231XX_BOARD_UNKNOWN}, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 407 | {USB_DEVICE(0x0572, 0x58A2), |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 408 | .driver_info = CX231XX_BOARD_CNXT_CARRAERA}, |
Sri Deevi | ed559ed | 2009-03-13 18:35:14 -0300 | [diff] [blame] | 409 | {USB_DEVICE(0x0572, 0x58A1), |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 410 | .driver_info = CX231XX_BOARD_CNXT_SHELBY}, |
| 411 | {USB_DEVICE(0x0572, 0x58A4), |
| 412 | .driver_info = CX231XX_BOARD_CNXT_RDE_253S}, |
| 413 | {USB_DEVICE(0x0572, 0x58A5), |
| 414 | .driver_info = CX231XX_BOARD_CNXT_RDU_253S}, |
| 415 | {USB_DEVICE(0x0572, 0x58A6), |
| 416 | .driver_info = CX231XX_BOARD_CNXT_VIDEO_GRABBER}, |
| 417 | {USB_DEVICE(0x0572, 0x589E), |
| 418 | .driver_info = CX231XX_BOARD_CNXT_RDE_250}, |
| 419 | {USB_DEVICE(0x0572, 0x58A0), |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 420 | .driver_info = CX231XX_BOARD_CNXT_RDU_250}, |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 421 | {USB_DEVICE(0x2040, 0xb120), |
| 422 | .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER}, |
Devin Heitmueller | d78148f | 2010-07-06 18:25:19 -0300 | [diff] [blame] | 423 | {USB_DEVICE(0x2040, 0xb140), |
| 424 | .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER}, |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 425 | {USB_DEVICE(0x2040, 0xc200), |
| 426 | .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2}, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 427 | {}, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 428 | }; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 429 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 430 | MODULE_DEVICE_TABLE(usb, cx231xx_id_table); |
| 431 | |
| 432 | /* cx231xx_tuner_callback |
| 433 | * will be used to reset XC5000 tuner using GPIO pin |
| 434 | */ |
| 435 | |
| 436 | int cx231xx_tuner_callback(void *ptr, int component, int command, int arg) |
| 437 | { |
| 438 | int rc = 0; |
| 439 | struct cx231xx *dev = ptr; |
| 440 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 441 | if (dev->tuner_type == TUNER_XC5000) { |
| 442 | if (command == XC5000_TUNER_RESET) { |
| 443 | cx231xx_info |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 444 | ("Tuner CB: RESET: cmd %d : tuner type %d \n", |
| 445 | command, dev->tuner_type); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 446 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, |
| 447 | 1); |
| 448 | msleep(10); |
| 449 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, |
| 450 | 0); |
| 451 | msleep(330); |
| 452 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, |
| 453 | 1); |
| 454 | msleep(10); |
| 455 | } |
| 456 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 457 | return rc; |
| 458 | } |
| 459 | EXPORT_SYMBOL_GPL(cx231xx_tuner_callback); |
| 460 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 461 | void cx231xx_reset_out(struct cx231xx *dev) |
| 462 | { |
| 463 | cx231xx_set_gpio_value(dev, CX23417_RESET, 1); |
| 464 | msleep(200); |
| 465 | cx231xx_set_gpio_value(dev, CX23417_RESET, 0); |
| 466 | msleep(200); |
| 467 | cx231xx_set_gpio_value(dev, CX23417_RESET, 1); |
| 468 | } |
| 469 | void cx231xx_enable_OSC(struct cx231xx *dev) |
| 470 | { |
| 471 | cx231xx_set_gpio_value(dev, CX23417_OSC_EN, 1); |
| 472 | } |
| 473 | void cx231xx_sleep_s5h1432(struct cx231xx *dev) |
| 474 | { |
| 475 | cx231xx_set_gpio_value(dev, SLEEP_S5H1432, 0); |
| 476 | } |
| 477 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 478 | static inline void cx231xx_set_model(struct cx231xx *dev) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 479 | { |
| 480 | memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board)); |
| 481 | } |
| 482 | |
| 483 | /* Since cx231xx_pre_card_setup() requires a proper dev->model, |
| 484 | * this won't work for boards with generic PCI IDs |
| 485 | */ |
| 486 | void cx231xx_pre_card_setup(struct cx231xx *dev) |
| 487 | { |
| 488 | |
| 489 | cx231xx_set_model(dev); |
| 490 | |
| 491 | cx231xx_info("Identified as %s (card=%d)\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 492 | dev->board.name, dev->model); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 493 | |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 494 | /* set the direction for GPIO pins */ |
Mauro Carvalho Chehab | c10469c | 2010-09-11 11:37:51 -0300 | [diff] [blame] | 495 | if (dev->board.tuner_gpio) { |
| 496 | cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1); |
| 497 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1); |
| 498 | cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 499 | |
Mauro Carvalho Chehab | c10469c | 2010-09-11 11:37:51 -0300 | [diff] [blame] | 500 | /* request some modules if any required */ |
Mauro Carvalho Chehab | c10469c | 2010-09-11 11:37:51 -0300 | [diff] [blame] | 501 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 502 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 503 | /* set the mode to Analog mode initially */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 504 | cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 505 | |
| 506 | /* Unlock device */ |
| 507 | /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */ |
| 508 | |
| 509 | } |
| 510 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 511 | static void cx231xx_config_tuner(struct cx231xx *dev) |
| 512 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 513 | struct tuner_setup tun_setup; |
| 514 | struct v4l2_frequency f; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 515 | |
| 516 | if (dev->tuner_type == TUNER_ABSENT) |
| 517 | return; |
| 518 | |
| 519 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; |
| 520 | tun_setup.type = dev->tuner_type; |
| 521 | tun_setup.addr = dev->tuner_addr; |
| 522 | tun_setup.tuner_callback = cx231xx_tuner_callback; |
| 523 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 524 | tuner_call(dev, tuner, s_type_addr, &tun_setup); |
| 525 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 526 | #if 0 |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 527 | if (tun_setup.type == TUNER_XC5000) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 528 | static struct xc2028_ctrl ctrl = { |
| 529 | .fname = XC5000_DEFAULT_FIRMWARE, |
| 530 | .max_len = 64, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 531 | .demod = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 532 | }; |
| 533 | struct v4l2_priv_tun_config cfg = { |
| 534 | .tuner = dev->tuner_type, |
| 535 | .priv = &ctrl, |
| 536 | }; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 537 | tuner_call(dev, tuner, s_config, &cfg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 538 | } |
| 539 | #endif |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 540 | /* configure tuner */ |
| 541 | f.tuner = 0; |
| 542 | f.type = V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 543 | f.frequency = 9076; /* just a magic number */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 544 | dev->ctl_freq = f.frequency; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 545 | call_all(dev, tuner, s_frequency, &f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 546 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 547 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 548 | |
| 549 | /* ----------------------------------------------------------------------- */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 550 | void cx231xx_register_i2c_ir(struct cx231xx *dev) |
| 551 | { |
| 552 | if (disable_ir) |
| 553 | return; |
| 554 | |
| 555 | /* REVISIT: instantiate IR device */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 556 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 557 | /* detect & configure */ |
| 558 | switch (dev->model) { |
| 559 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 560 | case CX231XX_BOARD_CNXT_CARRAERA: |
| 561 | break; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 562 | case CX231XX_BOARD_CNXT_RDE_250: |
| 563 | break; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 564 | case CX231XX_BOARD_CNXT_SHELBY: |
| 565 | break; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 566 | case CX231XX_BOARD_CNXT_RDU_250: |
| 567 | break; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 568 | case CX231XX_BOARD_CNXT_RDE_253S: |
| 569 | break; |
| 570 | case CX231XX_BOARD_CNXT_RDU_253S: |
| 571 | break; |
| 572 | case CX231XX_BOARD_CNXT_VIDEO_GRABBER: |
| 573 | break; |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 574 | case CX231XX_BOARD_HAUPPAUGE_EXETER: |
| 575 | break; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 576 | default: |
| 577 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | void cx231xx_card_setup(struct cx231xx *dev) |
| 582 | { |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 583 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 584 | cx231xx_set_model(dev); |
| 585 | |
| 586 | dev->tuner_type = cx231xx_boards[dev->model].tuner_type; |
| 587 | if (cx231xx_boards[dev->model].tuner_addr) |
| 588 | dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr; |
| 589 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 590 | /* request some modules */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 591 | if (dev->board.decoder == CX231XX_AVDECODER) { |
Hans Verkuil | e6574f2 | 2009-04-01 03:57:53 -0300 | [diff] [blame] | 592 | dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, |
| 593 | &dev->i2c_bus[0].i2c_adap, |
Hans Verkuil | 53dacb1 | 2009-08-10 02:49:08 -0300 | [diff] [blame] | 594 | "cx25840", "cx25840", 0x88 >> 1, NULL); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 595 | if (dev->sd_cx25840 == NULL) |
| 596 | cx231xx_info("cx25840 subdev registration failure\n"); |
Hans Verkuil | cc26b07 | 2009-03-29 19:20:26 -0300 | [diff] [blame] | 597 | cx25840_call(dev, core, load_fw); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 598 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 599 | } |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 600 | |
Devin Heitmueller | e3e0aaa | 2010-07-08 17:05:30 -0300 | [diff] [blame] | 601 | /* Initialize the tuner */ |
| 602 | if (dev->board.tuner_type != TUNER_ABSENT) { |
| 603 | dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, |
| 604 | &dev->i2c_bus[1].i2c_adap, |
| 605 | "tuner", "tuner", |
| 606 | dev->tuner_addr, NULL); |
| 607 | if (dev->sd_tuner == NULL) |
| 608 | cx231xx_info("tuner subdev registration failure\n"); |
| 609 | else |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 610 | cx231xx_config_tuner(dev); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 611 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 612 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 613 | #if 0 |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 614 | /* TBD IR will be added later */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 615 | cx231xx_ir_init(dev); |
| 616 | #endif |
| 617 | } |
| 618 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 619 | /* |
| 620 | * cx231xx_config() |
| 621 | * inits registers with sane defaults |
| 622 | */ |
| 623 | int cx231xx_config(struct cx231xx *dev) |
| 624 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 625 | /* TBD need to add cx231xx specific code */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 626 | dev->mute = 1; /* maybe not the right place... */ |
| 627 | dev->volume = 0x1f; |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | /* |
| 633 | * cx231xx_config_i2c() |
| 634 | * configure i2c attached devices |
| 635 | */ |
| 636 | void cx231xx_config_i2c(struct cx231xx *dev) |
| 637 | { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 638 | /* u32 input = INPUT(dev->video_input)->vmux; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 639 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 640 | call_all(dev, video, s_stream, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /* |
| 644 | * cx231xx_realease_resources() |
| 645 | * unregisters the v4l2,i2c and usb devices |
| 646 | * called when the device gets disconected or at module unload |
| 647 | */ |
| 648 | void cx231xx_release_resources(struct cx231xx *dev) |
| 649 | { |
| 650 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 651 | #if 0 /* TBD IR related */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 652 | if (dev->ir) |
| 653 | cx231xx_ir_fini(dev); |
| 654 | #endif |
| 655 | |
| 656 | cx231xx_release_analog_resources(dev); |
| 657 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 658 | cx231xx_remove_from_devlist(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 659 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 660 | cx231xx_dev_uninit(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 661 | |
| 662 | usb_put_dev(dev->udev); |
| 663 | |
| 664 | /* Mark device as unused */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 665 | cx231xx_devused &= ~(1 << dev->devno); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 666 | } |
| 667 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 668 | /* |
| 669 | * cx231xx_init_dev() |
| 670 | * allocates and inits the device structs, registers i2c bus and v4l device |
| 671 | */ |
| 672 | static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 673 | int minor) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 674 | { |
| 675 | struct cx231xx *dev = *devhandle; |
| 676 | int retval = -ENOMEM; |
| 677 | int errCode; |
| 678 | unsigned int maxh, maxw; |
| 679 | |
| 680 | dev->udev = udev; |
| 681 | mutex_init(&dev->lock); |
| 682 | mutex_init(&dev->ctrl_urb_lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 683 | mutex_init(&dev->gpio_i2c_lock); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 684 | mutex_init(&dev->i2c_lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 685 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 686 | spin_lock_init(&dev->video_mode.slock); |
| 687 | spin_lock_init(&dev->vbi_mode.slock); |
| 688 | spin_lock_init(&dev->sliced_cc_mode.slock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 689 | |
| 690 | init_waitqueue_head(&dev->open); |
| 691 | init_waitqueue_head(&dev->wait_frame); |
| 692 | init_waitqueue_head(&dev->wait_stream); |
| 693 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 694 | dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg; |
| 695 | dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg; |
| 696 | dev->cx231xx_send_usb_command = cx231xx_send_usb_command; |
| 697 | dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read; |
| 698 | dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 699 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 700 | /* Query cx231xx to find what pcb config it is related to */ |
| 701 | initialize_cx231xx(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 702 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 703 | /*To workaround error number=-71 on EP0 for VideoGrabber, |
| 704 | need set alt here.*/ |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 705 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER || |
| 706 | dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 707 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3); |
| 708 | cx231xx_set_alt_setting(dev, INDEX_VANC, 1); |
| 709 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 710 | /* Cx231xx pre card setup */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 711 | cx231xx_pre_card_setup(dev); |
| 712 | |
| 713 | errCode = cx231xx_config(dev); |
| 714 | if (errCode) { |
| 715 | cx231xx_errdev("error configuring device\n"); |
| 716 | return -ENOMEM; |
| 717 | } |
| 718 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 719 | /* set default norm */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 720 | dev->norm = dev->board.norm; |
| 721 | |
| 722 | /* register i2c bus */ |
| 723 | errCode = cx231xx_dev_init(dev); |
| 724 | if (errCode < 0) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 725 | cx231xx_dev_uninit(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 726 | cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 727 | __func__, errCode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 728 | return errCode; |
| 729 | } |
| 730 | |
| 731 | /* Do board specific init */ |
| 732 | cx231xx_card_setup(dev); |
| 733 | |
| 734 | /* configure the device */ |
| 735 | cx231xx_config_i2c(dev); |
| 736 | |
| 737 | maxw = norm_maxw(dev); |
| 738 | maxh = norm_maxh(dev); |
| 739 | |
| 740 | /* set default image size */ |
| 741 | dev->width = maxw; |
| 742 | dev->height = maxh; |
| 743 | dev->interlaced = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 744 | dev->video_input = 0; |
| 745 | |
| 746 | errCode = cx231xx_config(dev); |
| 747 | if (errCode < 0) { |
| 748 | cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 749 | __func__, errCode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 750 | return errCode; |
| 751 | } |
| 752 | |
| 753 | /* init video dma queues */ |
| 754 | INIT_LIST_HEAD(&dev->video_mode.vidq.active); |
| 755 | INIT_LIST_HEAD(&dev->video_mode.vidq.queued); |
| 756 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 757 | /* init vbi dma queues */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 758 | INIT_LIST_HEAD(&dev->vbi_mode.vidq.active); |
| 759 | INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued); |
| 760 | |
| 761 | /* Reset other chips required if they are tied up with GPIO pins */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 762 | cx231xx_add_into_devlist(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 763 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 764 | printk(KERN_INFO "attach 417 %d\n", dev->model); |
| 765 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) { |
| 766 | if (cx231xx_417_register(dev) < 0) { |
| 767 | printk(KERN_ERR |
| 768 | "%s() Failed to register 417 on VID_B\n", |
| 769 | __func__); |
| 770 | } |
| 771 | } |
| 772 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 773 | retval = cx231xx_register_analog_devices(dev); |
| 774 | if (retval < 0) { |
| 775 | cx231xx_release_resources(dev); |
| 776 | goto fail_reg_devices; |
| 777 | } |
| 778 | |
| 779 | cx231xx_init_extension(dev); |
| 780 | |
| 781 | return 0; |
| 782 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 783 | fail_reg_devices: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 784 | mutex_unlock(&dev->lock); |
| 785 | return retval; |
| 786 | } |
| 787 | |
| 788 | #if defined(CONFIG_MODULES) && defined(MODULE) |
| 789 | static void request_module_async(struct work_struct *work) |
| 790 | { |
| 791 | struct cx231xx *dev = container_of(work, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 792 | struct cx231xx, request_module_wk); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 793 | |
| 794 | if (dev->has_alsa_audio) |
| 795 | request_module("cx231xx-alsa"); |
| 796 | |
| 797 | if (dev->board.has_dvb) |
| 798 | request_module("cx231xx-dvb"); |
| 799 | |
| 800 | } |
| 801 | |
| 802 | static void request_modules(struct cx231xx *dev) |
| 803 | { |
| 804 | INIT_WORK(&dev->request_module_wk, request_module_async); |
| 805 | schedule_work(&dev->request_module_wk); |
| 806 | } |
| 807 | #else |
| 808 | #define request_modules(dev) |
| 809 | #endif /* CONFIG_MODULES */ |
| 810 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 811 | /* |
| 812 | * cx231xx_usb_probe() |
| 813 | * checks for supported devices |
| 814 | */ |
| 815 | static int cx231xx_usb_probe(struct usb_interface *interface, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 816 | const struct usb_device_id *id) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 817 | { |
| 818 | struct usb_device *udev; |
| 819 | struct usb_interface *uif; |
| 820 | struct cx231xx *dev = NULL; |
| 821 | int retval = -ENODEV; |
Hans Verkuil | d73abcf | 2009-03-12 18:38:40 -0300 | [diff] [blame] | 822 | int nr = 0, ifnum; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 823 | int i, isoc_pipe = 0; |
| 824 | char *speed; |
| 825 | char descr[255] = ""; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 826 | struct usb_interface *lif = NULL; |
| 827 | int skip_interface = 0; |
| 828 | struct usb_interface_assoc_descriptor *assoc_desc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 829 | |
| 830 | udev = usb_get_dev(interface_to_usbdev(interface)); |
| 831 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; |
| 832 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 833 | if (!ifnum) { |
| 834 | /* |
| 835 | * Interface number 0 - IR interface |
| 836 | */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 837 | /* Check to see next free device and mark as used */ |
| 838 | nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); |
| 839 | cx231xx_devused |= 1 << nr; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 840 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 841 | if (nr >= CX231XX_MAXBOARDS) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 842 | cx231xx_err(DRIVER_NAME |
| 843 | ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 844 | cx231xx_devused &= ~(1 << nr); |
| 845 | return -ENOMEM; |
| 846 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 847 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 848 | /* allocate memory for our device state and initialize it */ |
| 849 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 850 | if (dev == NULL) { |
| 851 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); |
| 852 | cx231xx_devused &= ~(1 << nr); |
| 853 | return -ENOMEM; |
| 854 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 855 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 856 | snprintf(dev->name, 29, "cx231xx #%d", nr); |
| 857 | dev->devno = nr; |
| 858 | dev->model = id->driver_info; |
| 859 | dev->video_mode.alt = -1; |
| 860 | dev->interface_count++; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 861 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 862 | /* reset gpio dir and value */ |
| 863 | dev->gpio_dir = 0; |
| 864 | dev->gpio_val = 0; |
| 865 | dev->xc_fw_load_done = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 866 | dev->has_alsa_audio = 1; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 867 | dev->power_mode = -1; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 868 | atomic_set(&dev->devlist_count, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 869 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 870 | /* 0 - vbi ; 1 -sliced cc mode */ |
| 871 | dev->vbi_or_sliced_cc_mode = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 872 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 873 | /* get maximum no.of IAD interfaces */ |
| 874 | assoc_desc = udev->actconfig->intf_assoc[0]; |
| 875 | dev->max_iad_interface_count = assoc_desc->bInterfaceCount; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 876 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 877 | /* init CIR module TBD */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 878 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 879 | /* store the current interface */ |
| 880 | lif = interface; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 881 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 882 | /*mode_tv: digital=1 or analog=0*/ |
| 883 | dev->mode_tv = 0; |
| 884 | |
| 885 | dev->USE_ISO = transfer_mode; |
| 886 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 887 | switch (udev->speed) { |
| 888 | case USB_SPEED_LOW: |
| 889 | speed = "1.5"; |
| 890 | break; |
| 891 | case USB_SPEED_UNKNOWN: |
| 892 | case USB_SPEED_FULL: |
| 893 | speed = "12"; |
| 894 | break; |
| 895 | case USB_SPEED_HIGH: |
| 896 | speed = "480"; |
| 897 | break; |
| 898 | default: |
| 899 | speed = "unknown"; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 900 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 901 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 902 | if (udev->manufacturer) |
| 903 | strlcpy(descr, udev->manufacturer, sizeof(descr)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 904 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 905 | if (udev->product) { |
| 906 | if (*descr) |
| 907 | strlcat(descr, " ", sizeof(descr)); |
| 908 | strlcat(descr, udev->product, sizeof(descr)); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 909 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 910 | if (*descr) |
| 911 | strlcat(descr, " ", sizeof(descr)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 912 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 913 | cx231xx_info("New device %s@ %s Mbps " |
| 914 | "(%04x:%04x) with %d interfaces\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 915 | descr, |
| 916 | speed, |
| 917 | le16_to_cpu(udev->descriptor.idVendor), |
| 918 | le16_to_cpu(udev->descriptor.idProduct), |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 919 | dev->max_iad_interface_count); |
| 920 | } else { |
| 921 | /* Get dev structure first */ |
| 922 | dev = usb_get_intfdata(udev->actconfig->interface[0]); |
| 923 | if (dev == NULL) { |
| 924 | cx231xx_err(DRIVER_NAME ": out of first interface!\n"); |
| 925 | return -ENODEV; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 926 | } |
| 927 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 928 | /* store the interface 0 back */ |
| 929 | lif = udev->actconfig->interface[0]; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 930 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 931 | /* increment interface count */ |
| 932 | dev->interface_count++; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 933 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 934 | /* get device number */ |
| 935 | nr = dev->devno; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 936 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 937 | /* |
| 938 | * set skip interface, for all interfaces but |
| 939 | * interface 1 and the last one |
| 940 | */ |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 941 | if ((ifnum != 1) && ((ifnum) |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 942 | != dev->max_iad_interface_count)) |
| 943 | skip_interface = 1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 944 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 945 | if (ifnum == 1) { |
| 946 | assoc_desc = udev->actconfig->intf_assoc[0]; |
| 947 | if (assoc_desc->bFirstInterface != ifnum) { |
| 948 | cx231xx_err(DRIVER_NAME ": Not found " |
| 949 | "matching IAD interface\n"); |
| 950 | return -ENODEV; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 951 | } |
| 952 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 953 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 954 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 955 | if (skip_interface) |
| 956 | return -ENODEV; |
| 957 | |
| 958 | cx231xx_info("registering interface %d\n", ifnum); |
| 959 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 960 | /* save our data pointer in this interface device */ |
| 961 | usb_set_intfdata(lif, dev); |
| 962 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 963 | if ((ifnum) != dev->max_iad_interface_count) |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 964 | return 0; |
| 965 | |
| 966 | /* |
| 967 | * AV device initialization - only done at the last interface |
| 968 | */ |
| 969 | |
| 970 | /* Create v4l2 device */ |
Janne Grunau | 7231748 | 2009-04-01 08:39:29 -0300 | [diff] [blame] | 971 | retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 972 | if (retval) { |
| 973 | cx231xx_errdev("v4l2_device_register failed\n"); |
| 974 | cx231xx_devused &= ~(1 << nr); |
| 975 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 976 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 977 | return -EIO; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 978 | } |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 979 | /* allocate device struct */ |
| 980 | retval = cx231xx_init_dev(&dev, udev, nr); |
| 981 | if (retval) { |
| 982 | cx231xx_devused &= ~(1 << dev->devno); |
| 983 | v4l2_device_unregister(&dev->v4l2_dev); |
| 984 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 985 | dev = NULL; |
| 986 | usb_set_intfdata(lif, NULL); |
| 987 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 988 | return retval; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 989 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 990 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 991 | /* compute alternate max packet sizes for video */ |
| 992 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 993 | hs_config_info[0].interface_info.video_index + 1]; |
| 994 | |
| 995 | dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0]. |
| 996 | endpoint[isoc_pipe].desc.bEndpointAddress); |
| 997 | |
| 998 | dev->video_mode.num_alt = uif->num_altsetting; |
| 999 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 1000 | dev->video_mode.end_point_addr, |
| 1001 | dev->video_mode.num_alt); |
| 1002 | dev->video_mode.alt_max_pkt_size = |
| 1003 | kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); |
| 1004 | |
| 1005 | if (dev->video_mode.alt_max_pkt_size == NULL) { |
| 1006 | cx231xx_errdev("out of memory!\n"); |
| 1007 | cx231xx_devused &= ~(1 << nr); |
| 1008 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1009 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1010 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1011 | return -ENOMEM; |
| 1012 | } |
| 1013 | |
| 1014 | for (i = 0; i < dev->video_mode.num_alt; i++) { |
| 1015 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 1016 | desc.wMaxPacketSize); |
| 1017 | dev->video_mode.alt_max_pkt_size[i] = |
| 1018 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1019 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 1020 | dev->video_mode.alt_max_pkt_size[i]); |
| 1021 | } |
| 1022 | |
| 1023 | /* compute alternate max packet sizes for vbi */ |
| 1024 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 1025 | hs_config_info[0].interface_info. |
| 1026 | vanc_index + 1]; |
| 1027 | |
| 1028 | dev->vbi_mode.end_point_addr = |
| 1029 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 1030 | bEndpointAddress); |
| 1031 | |
| 1032 | dev->vbi_mode.num_alt = uif->num_altsetting; |
| 1033 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 1034 | dev->vbi_mode.end_point_addr, |
| 1035 | dev->vbi_mode.num_alt); |
| 1036 | dev->vbi_mode.alt_max_pkt_size = |
| 1037 | kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); |
| 1038 | |
| 1039 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { |
| 1040 | cx231xx_errdev("out of memory!\n"); |
| 1041 | cx231xx_devused &= ~(1 << nr); |
| 1042 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1043 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1044 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1045 | return -ENOMEM; |
| 1046 | } |
| 1047 | |
| 1048 | for (i = 0; i < dev->vbi_mode.num_alt; i++) { |
| 1049 | u16 tmp = |
| 1050 | le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 1051 | desc.wMaxPacketSize); |
| 1052 | dev->vbi_mode.alt_max_pkt_size[i] = |
| 1053 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1054 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 1055 | dev->vbi_mode.alt_max_pkt_size[i]); |
| 1056 | } |
| 1057 | |
| 1058 | /* compute alternate max packet sizes for sliced CC */ |
| 1059 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 1060 | hs_config_info[0].interface_info. |
| 1061 | hanc_index + 1]; |
| 1062 | |
| 1063 | dev->sliced_cc_mode.end_point_addr = |
| 1064 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 1065 | bEndpointAddress); |
| 1066 | |
| 1067 | dev->sliced_cc_mode.num_alt = uif->num_altsetting; |
| 1068 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 1069 | dev->sliced_cc_mode.end_point_addr, |
| 1070 | dev->sliced_cc_mode.num_alt); |
| 1071 | dev->sliced_cc_mode.alt_max_pkt_size = |
| 1072 | kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); |
| 1073 | |
| 1074 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { |
| 1075 | cx231xx_errdev("out of memory!\n"); |
| 1076 | cx231xx_devused &= ~(1 << nr); |
| 1077 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1078 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1079 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1080 | return -ENOMEM; |
| 1081 | } |
| 1082 | |
| 1083 | for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { |
| 1084 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 1085 | desc.wMaxPacketSize); |
| 1086 | dev->sliced_cc_mode.alt_max_pkt_size[i] = |
| 1087 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1088 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 1089 | dev->sliced_cc_mode.alt_max_pkt_size[i]); |
| 1090 | } |
| 1091 | |
| 1092 | if (dev->current_pcb_config.ts1_source != 0xff) { |
| 1093 | /* compute alternate max packet sizes for TS1 */ |
| 1094 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 1095 | hs_config_info[0]. |
| 1096 | interface_info. |
| 1097 | ts1_index + 1]; |
| 1098 | |
| 1099 | dev->ts1_mode.end_point_addr = |
| 1100 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. |
| 1101 | desc.bEndpointAddress); |
| 1102 | |
| 1103 | dev->ts1_mode.num_alt = uif->num_altsetting; |
| 1104 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 1105 | dev->ts1_mode.end_point_addr, |
| 1106 | dev->ts1_mode.num_alt); |
| 1107 | dev->ts1_mode.alt_max_pkt_size = |
| 1108 | kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); |
| 1109 | |
| 1110 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { |
| 1111 | cx231xx_errdev("out of memory!\n"); |
| 1112 | cx231xx_devused &= ~(1 << nr); |
| 1113 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1114 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1115 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1116 | return -ENOMEM; |
| 1117 | } |
| 1118 | |
| 1119 | for (i = 0; i < dev->ts1_mode.num_alt; i++) { |
| 1120 | u16 tmp = le16_to_cpu(uif->altsetting[i]. |
| 1121 | endpoint[isoc_pipe].desc. |
| 1122 | wMaxPacketSize); |
| 1123 | dev->ts1_mode.alt_max_pkt_size[i] = |
| 1124 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1125 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 1126 | dev->ts1_mode.alt_max_pkt_size[i]); |
| 1127 | } |
| 1128 | } |
| 1129 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1130 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) { |
| 1131 | cx231xx_enable_OSC(dev); |
| 1132 | cx231xx_reset_out(dev); |
| 1133 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3); |
| 1134 | } |
| 1135 | |
| 1136 | if (dev->model == CX231XX_BOARD_CNXT_RDE_253S) |
| 1137 | cx231xx_sleep_s5h1432(dev); |
| 1138 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1139 | /* load other modules required */ |
| 1140 | request_modules(dev); |
| 1141 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | /* |
| 1146 | * cx231xx_usb_disconnect() |
| 1147 | * called when the device gets diconencted |
| 1148 | * video device will be unregistered on v4l2_close in case it is still open |
| 1149 | */ |
| 1150 | static void cx231xx_usb_disconnect(struct usb_interface *interface) |
| 1151 | { |
| 1152 | struct cx231xx *dev; |
| 1153 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1154 | dev = usb_get_intfdata(interface); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1155 | usb_set_intfdata(interface, NULL); |
| 1156 | |
| 1157 | if (!dev) |
| 1158 | return; |
| 1159 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1160 | if (!dev->udev) |
| 1161 | return; |
| 1162 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1163 | /* delete v4l2 device */ |
| 1164 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1165 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1166 | /* wait until all current v4l2 io is finished then deallocate |
| 1167 | resources */ |
| 1168 | mutex_lock(&dev->lock); |
| 1169 | |
| 1170 | wake_up_interruptible_all(&dev->open); |
| 1171 | |
| 1172 | if (dev->users) { |
| 1173 | cx231xx_warn |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1174 | ("device %s is open! Deregistration and memory " |
| 1175 | "deallocation are deferred on close.\n", |
| 1176 | video_device_node_name(dev->vdev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1177 | |
| 1178 | dev->state |= DEV_MISCONFIGURED; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1179 | if (dev->USE_ISO) |
| 1180 | cx231xx_uninit_isoc(dev); |
| 1181 | else |
| 1182 | cx231xx_uninit_bulk(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1183 | dev->state |= DEV_DISCONNECTED; |
| 1184 | wake_up_interruptible(&dev->wait_frame); |
| 1185 | wake_up_interruptible(&dev->wait_stream); |
| 1186 | } else { |
| 1187 | dev->state |= DEV_DISCONNECTED; |
| 1188 | cx231xx_release_resources(dev); |
| 1189 | } |
| 1190 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1191 | cx231xx_close_extension(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1192 | |
| 1193 | mutex_unlock(&dev->lock); |
| 1194 | |
| 1195 | if (!dev->users) { |
| 1196 | kfree(dev->video_mode.alt_max_pkt_size); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1197 | kfree(dev->vbi_mode.alt_max_pkt_size); |
| 1198 | kfree(dev->sliced_cc_mode.alt_max_pkt_size); |
| 1199 | kfree(dev->ts1_mode.alt_max_pkt_size); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1200 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1201 | dev = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | static struct usb_driver cx231xx_usb_driver = { |
| 1206 | .name = "cx231xx", |
| 1207 | .probe = cx231xx_usb_probe, |
| 1208 | .disconnect = cx231xx_usb_disconnect, |
| 1209 | .id_table = cx231xx_id_table, |
| 1210 | }; |
| 1211 | |
| 1212 | static int __init cx231xx_module_init(void) |
| 1213 | { |
| 1214 | int result; |
| 1215 | |
Mauro Carvalho Chehab | 818fdf3 | 2009-03-13 07:41:58 -0300 | [diff] [blame] | 1216 | printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1217 | |
| 1218 | /* register this driver with the USB subsystem */ |
| 1219 | result = usb_register(&cx231xx_usb_driver); |
| 1220 | if (result) |
| 1221 | cx231xx_err(DRIVER_NAME |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1222 | " usb_register failed. Error number %d.\n", result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1223 | |
| 1224 | return result; |
| 1225 | } |
| 1226 | |
| 1227 | static void __exit cx231xx_module_exit(void) |
| 1228 | { |
| 1229 | /* deregister this driver with the USB subsystem */ |
| 1230 | usb_deregister(&cx231xx_usb_driver); |
| 1231 | } |
| 1232 | |
| 1233 | module_init(cx231xx_module_init); |
| 1234 | module_exit(cx231xx_module_exit); |