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