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); |
Mauro Carvalho Chehab | 78bb6df | 2010-09-26 20:48:38 -0300 | [diff] [blame] | 498 | } |
| 499 | if (dev->board.tuner_sif_gpio >= 0) |
Mauro Carvalho Chehab | c10469c | 2010-09-11 11:37:51 -0300 | [diff] [blame] | 500 | cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 501 | |
Mauro Carvalho Chehab | 78bb6df | 2010-09-26 20:48:38 -0300 | [diff] [blame] | 502 | /* request some modules if any required */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 503 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 504 | /* set the mode to Analog mode initially */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 505 | cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 506 | |
| 507 | /* Unlock device */ |
| 508 | /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */ |
| 509 | |
| 510 | } |
| 511 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 512 | static void cx231xx_config_tuner(struct cx231xx *dev) |
| 513 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 514 | struct tuner_setup tun_setup; |
| 515 | struct v4l2_frequency f; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 516 | |
| 517 | if (dev->tuner_type == TUNER_ABSENT) |
| 518 | return; |
| 519 | |
| 520 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; |
| 521 | tun_setup.type = dev->tuner_type; |
| 522 | tun_setup.addr = dev->tuner_addr; |
| 523 | tun_setup.tuner_callback = cx231xx_tuner_callback; |
| 524 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 525 | tuner_call(dev, tuner, s_type_addr, &tun_setup); |
| 526 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 527 | #if 0 |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 528 | if (tun_setup.type == TUNER_XC5000) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 529 | static struct xc2028_ctrl ctrl = { |
| 530 | .fname = XC5000_DEFAULT_FIRMWARE, |
| 531 | .max_len = 64, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 532 | .demod = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 533 | }; |
| 534 | struct v4l2_priv_tun_config cfg = { |
| 535 | .tuner = dev->tuner_type, |
| 536 | .priv = &ctrl, |
| 537 | }; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 538 | tuner_call(dev, tuner, s_config, &cfg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 539 | } |
| 540 | #endif |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 541 | /* configure tuner */ |
| 542 | f.tuner = 0; |
| 543 | f.type = V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 544 | f.frequency = 9076; /* just a magic number */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 545 | dev->ctl_freq = f.frequency; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 546 | call_all(dev, tuner, s_frequency, &f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 547 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 548 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 549 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 550 | void cx231xx_card_setup(struct cx231xx *dev) |
| 551 | { |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 552 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 553 | cx231xx_set_model(dev); |
| 554 | |
| 555 | dev->tuner_type = cx231xx_boards[dev->model].tuner_type; |
| 556 | if (cx231xx_boards[dev->model].tuner_addr) |
| 557 | dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr; |
| 558 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 559 | /* request some modules */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 560 | if (dev->board.decoder == CX231XX_AVDECODER) { |
Hans Verkuil | e6574f2 | 2009-04-01 03:57:53 -0300 | [diff] [blame] | 561 | dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, |
| 562 | &dev->i2c_bus[0].i2c_adap, |
Laurent Pinchart | 1532a07 | 2010-09-24 07:58:29 -0300 | [diff] [blame] | 563 | NULL, "cx25840", 0x88 >> 1, NULL); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 564 | if (dev->sd_cx25840 == NULL) |
| 565 | cx231xx_info("cx25840 subdev registration failure\n"); |
Hans Verkuil | cc26b07 | 2009-03-29 19:20:26 -0300 | [diff] [blame] | 566 | cx25840_call(dev, core, load_fw); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 567 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 568 | } |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 569 | |
Devin Heitmueller | e3e0aaa | 2010-07-08 17:05:30 -0300 | [diff] [blame] | 570 | /* Initialize the tuner */ |
| 571 | if (dev->board.tuner_type != TUNER_ABSENT) { |
| 572 | dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 573 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
Laurent Pinchart | 1532a07 | 2010-09-24 07:58:29 -0300 | [diff] [blame] | 574 | NULL, "tuner", |
Devin Heitmueller | e3e0aaa | 2010-07-08 17:05:30 -0300 | [diff] [blame] | 575 | dev->tuner_addr, NULL); |
| 576 | if (dev->sd_tuner == NULL) |
| 577 | cx231xx_info("tuner subdev registration failure\n"); |
| 578 | else |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 579 | cx231xx_config_tuner(dev); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 580 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 581 | } |
| 582 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 583 | /* |
| 584 | * cx231xx_config() |
| 585 | * inits registers with sane defaults |
| 586 | */ |
| 587 | int cx231xx_config(struct cx231xx *dev) |
| 588 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 589 | /* TBD need to add cx231xx specific code */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 590 | dev->mute = 1; /* maybe not the right place... */ |
| 591 | dev->volume = 0x1f; |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | /* |
| 597 | * cx231xx_config_i2c() |
| 598 | * configure i2c attached devices |
| 599 | */ |
| 600 | void cx231xx_config_i2c(struct cx231xx *dev) |
| 601 | { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 602 | /* u32 input = INPUT(dev->video_input)->vmux; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 603 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 604 | call_all(dev, video, s_stream, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /* |
| 608 | * cx231xx_realease_resources() |
| 609 | * unregisters the v4l2,i2c and usb devices |
| 610 | * called when the device gets disconected or at module unload |
| 611 | */ |
| 612 | void cx231xx_release_resources(struct cx231xx *dev) |
| 613 | { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 614 | cx231xx_release_analog_resources(dev); |
| 615 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 616 | cx231xx_remove_from_devlist(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 617 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 618 | cx231xx_dev_uninit(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 619 | |
| 620 | usb_put_dev(dev->udev); |
| 621 | |
| 622 | /* Mark device as unused */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 623 | cx231xx_devused &= ~(1 << dev->devno); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 624 | } |
| 625 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 626 | /* |
| 627 | * cx231xx_init_dev() |
| 628 | * allocates and inits the device structs, registers i2c bus and v4l device |
| 629 | */ |
| 630 | 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] | 631 | int minor) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 632 | { |
| 633 | struct cx231xx *dev = *devhandle; |
| 634 | int retval = -ENOMEM; |
| 635 | int errCode; |
| 636 | unsigned int maxh, maxw; |
| 637 | |
| 638 | dev->udev = udev; |
| 639 | mutex_init(&dev->lock); |
| 640 | mutex_init(&dev->ctrl_urb_lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 641 | mutex_init(&dev->gpio_i2c_lock); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 642 | mutex_init(&dev->i2c_lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 643 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 644 | spin_lock_init(&dev->video_mode.slock); |
| 645 | spin_lock_init(&dev->vbi_mode.slock); |
| 646 | spin_lock_init(&dev->sliced_cc_mode.slock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 647 | |
| 648 | init_waitqueue_head(&dev->open); |
| 649 | init_waitqueue_head(&dev->wait_frame); |
| 650 | init_waitqueue_head(&dev->wait_stream); |
| 651 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 652 | dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg; |
| 653 | dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg; |
| 654 | dev->cx231xx_send_usb_command = cx231xx_send_usb_command; |
| 655 | dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read; |
| 656 | dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 657 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 658 | /* Query cx231xx to find what pcb config it is related to */ |
| 659 | initialize_cx231xx(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 660 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 661 | /*To workaround error number=-71 on EP0 for VideoGrabber, |
| 662 | need set alt here.*/ |
Devin Heitmueller | 4270c3c | 2010-07-31 00:49:01 -0300 | [diff] [blame] | 663 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER || |
| 664 | dev->model == CX231XX_BOARD_HAUPPAUGE_USBLIVE2) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 665 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3); |
| 666 | cx231xx_set_alt_setting(dev, INDEX_VANC, 1); |
| 667 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 668 | /* Cx231xx pre card setup */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 669 | cx231xx_pre_card_setup(dev); |
| 670 | |
| 671 | errCode = cx231xx_config(dev); |
| 672 | if (errCode) { |
| 673 | cx231xx_errdev("error configuring device\n"); |
| 674 | return -ENOMEM; |
| 675 | } |
| 676 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 677 | /* set default norm */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 678 | dev->norm = dev->board.norm; |
| 679 | |
| 680 | /* register i2c bus */ |
| 681 | errCode = cx231xx_dev_init(dev); |
| 682 | if (errCode < 0) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 683 | cx231xx_dev_uninit(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 684 | cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 685 | __func__, errCode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 686 | return errCode; |
| 687 | } |
| 688 | |
| 689 | /* Do board specific init */ |
| 690 | cx231xx_card_setup(dev); |
| 691 | |
| 692 | /* configure the device */ |
| 693 | cx231xx_config_i2c(dev); |
| 694 | |
| 695 | maxw = norm_maxw(dev); |
| 696 | maxh = norm_maxh(dev); |
| 697 | |
| 698 | /* set default image size */ |
| 699 | dev->width = maxw; |
| 700 | dev->height = maxh; |
| 701 | dev->interlaced = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 702 | dev->video_input = 0; |
| 703 | |
| 704 | errCode = cx231xx_config(dev); |
| 705 | if (errCode < 0) { |
| 706 | cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 707 | __func__, errCode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 708 | return errCode; |
| 709 | } |
| 710 | |
| 711 | /* init video dma queues */ |
| 712 | INIT_LIST_HEAD(&dev->video_mode.vidq.active); |
| 713 | INIT_LIST_HEAD(&dev->video_mode.vidq.queued); |
| 714 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 715 | /* init vbi dma queues */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 716 | INIT_LIST_HEAD(&dev->vbi_mode.vidq.active); |
| 717 | INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued); |
| 718 | |
| 719 | /* 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] | 720 | cx231xx_add_into_devlist(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 721 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 722 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) { |
Devin Heitmueller | 2b43db3 | 2010-08-18 18:09:28 -0300 | [diff] [blame] | 723 | printk(KERN_INFO "attach 417 %d\n", dev->model); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 724 | if (cx231xx_417_register(dev) < 0) { |
| 725 | printk(KERN_ERR |
| 726 | "%s() Failed to register 417 on VID_B\n", |
| 727 | __func__); |
| 728 | } |
| 729 | } |
| 730 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 731 | retval = cx231xx_register_analog_devices(dev); |
| 732 | if (retval < 0) { |
| 733 | cx231xx_release_resources(dev); |
| 734 | goto fail_reg_devices; |
| 735 | } |
| 736 | |
| 737 | cx231xx_init_extension(dev); |
| 738 | |
| 739 | return 0; |
| 740 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 741 | fail_reg_devices: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 742 | mutex_unlock(&dev->lock); |
| 743 | return retval; |
| 744 | } |
| 745 | |
| 746 | #if defined(CONFIG_MODULES) && defined(MODULE) |
| 747 | static void request_module_async(struct work_struct *work) |
| 748 | { |
| 749 | struct cx231xx *dev = container_of(work, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 750 | struct cx231xx, request_module_wk); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 751 | |
| 752 | if (dev->has_alsa_audio) |
| 753 | request_module("cx231xx-alsa"); |
| 754 | |
| 755 | if (dev->board.has_dvb) |
| 756 | request_module("cx231xx-dvb"); |
| 757 | |
| 758 | } |
| 759 | |
| 760 | static void request_modules(struct cx231xx *dev) |
| 761 | { |
| 762 | INIT_WORK(&dev->request_module_wk, request_module_async); |
| 763 | schedule_work(&dev->request_module_wk); |
| 764 | } |
| 765 | #else |
| 766 | #define request_modules(dev) |
| 767 | #endif /* CONFIG_MODULES */ |
| 768 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 769 | /* |
| 770 | * cx231xx_usb_probe() |
| 771 | * checks for supported devices |
| 772 | */ |
| 773 | static int cx231xx_usb_probe(struct usb_interface *interface, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 774 | const struct usb_device_id *id) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 775 | { |
| 776 | struct usb_device *udev; |
| 777 | struct usb_interface *uif; |
| 778 | struct cx231xx *dev = NULL; |
| 779 | int retval = -ENODEV; |
Hans Verkuil | d73abcf | 2009-03-12 18:38:40 -0300 | [diff] [blame] | 780 | int nr = 0, ifnum; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 781 | int i, isoc_pipe = 0; |
| 782 | char *speed; |
| 783 | char descr[255] = ""; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 784 | struct usb_interface *lif = NULL; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 785 | struct usb_interface_assoc_descriptor *assoc_desc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 786 | |
| 787 | udev = usb_get_dev(interface_to_usbdev(interface)); |
| 788 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; |
| 789 | |
Mauro Carvalho Chehab | 10e4ebb | 2010-10-18 21:10:46 -0300 | [diff] [blame] | 790 | if (ifnum == 1) { |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 791 | /* |
| 792 | * Interface number 0 - IR interface |
| 793 | */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 794 | /* Check to see next free device and mark as used */ |
| 795 | nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); |
| 796 | cx231xx_devused |= 1 << nr; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 797 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 798 | if (nr >= CX231XX_MAXBOARDS) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 799 | cx231xx_err(DRIVER_NAME |
| 800 | ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 801 | cx231xx_devused &= ~(1 << nr); |
| 802 | return -ENOMEM; |
| 803 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 804 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 805 | /* allocate memory for our device state and initialize it */ |
| 806 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 807 | if (dev == NULL) { |
| 808 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); |
| 809 | cx231xx_devused &= ~(1 << nr); |
| 810 | return -ENOMEM; |
| 811 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 812 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 813 | snprintf(dev->name, 29, "cx231xx #%d", nr); |
| 814 | dev->devno = nr; |
| 815 | dev->model = id->driver_info; |
| 816 | dev->video_mode.alt = -1; |
| 817 | dev->interface_count++; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 818 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 819 | /* reset gpio dir and value */ |
| 820 | dev->gpio_dir = 0; |
| 821 | dev->gpio_val = 0; |
| 822 | dev->xc_fw_load_done = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 823 | dev->has_alsa_audio = 1; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 824 | dev->power_mode = -1; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 825 | atomic_set(&dev->devlist_count, 0); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 826 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 827 | /* 0 - vbi ; 1 -sliced cc mode */ |
| 828 | dev->vbi_or_sliced_cc_mode = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 829 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 830 | /* get maximum no.of IAD interfaces */ |
| 831 | assoc_desc = udev->actconfig->intf_assoc[0]; |
| 832 | dev->max_iad_interface_count = assoc_desc->bInterfaceCount; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 833 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 834 | /* init CIR module TBD */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 835 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 836 | /* store the current interface */ |
| 837 | lif = interface; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 838 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 839 | /*mode_tv: digital=1 or analog=0*/ |
| 840 | dev->mode_tv = 0; |
| 841 | |
| 842 | dev->USE_ISO = transfer_mode; |
| 843 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 844 | switch (udev->speed) { |
| 845 | case USB_SPEED_LOW: |
| 846 | speed = "1.5"; |
| 847 | break; |
| 848 | case USB_SPEED_UNKNOWN: |
| 849 | case USB_SPEED_FULL: |
| 850 | speed = "12"; |
| 851 | break; |
| 852 | case USB_SPEED_HIGH: |
| 853 | speed = "480"; |
| 854 | break; |
| 855 | default: |
| 856 | speed = "unknown"; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 857 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 858 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 859 | if (udev->manufacturer) |
| 860 | strlcpy(descr, udev->manufacturer, sizeof(descr)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 861 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 862 | if (udev->product) { |
| 863 | if (*descr) |
| 864 | strlcat(descr, " ", sizeof(descr)); |
| 865 | strlcat(descr, udev->product, sizeof(descr)); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 866 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 867 | if (*descr) |
| 868 | strlcat(descr, " ", sizeof(descr)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 869 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 870 | cx231xx_info("New device %s@ %s Mbps " |
| 871 | "(%04x:%04x) with %d interfaces\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 872 | descr, |
| 873 | speed, |
| 874 | le16_to_cpu(udev->descriptor.idVendor), |
| 875 | le16_to_cpu(udev->descriptor.idProduct), |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 876 | dev->max_iad_interface_count); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 877 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 878 | /* store the interface 0 back */ |
| 879 | lif = udev->actconfig->interface[0]; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 880 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 881 | /* increment interface count */ |
| 882 | dev->interface_count++; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 883 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 884 | /* get device number */ |
| 885 | nr = dev->devno; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 886 | |
Mauro Carvalho Chehab | 10e4ebb | 2010-10-18 21:10:46 -0300 | [diff] [blame] | 887 | assoc_desc = udev->actconfig->intf_assoc[0]; |
| 888 | if (assoc_desc->bFirstInterface != ifnum) { |
| 889 | cx231xx_err(DRIVER_NAME ": Not found " |
| 890 | "matching IAD interface\n"); |
| 891 | return -ENODEV; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 892 | } |
Mauro Carvalho Chehab | 10e4ebb | 2010-10-18 21:10:46 -0300 | [diff] [blame] | 893 | } else { |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 894 | return -ENODEV; |
Mauro Carvalho Chehab | 10e4ebb | 2010-10-18 21:10:46 -0300 | [diff] [blame] | 895 | } |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 896 | |
| 897 | cx231xx_info("registering interface %d\n", ifnum); |
| 898 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 899 | /* save our data pointer in this interface device */ |
| 900 | usb_set_intfdata(lif, dev); |
| 901 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 902 | /* |
| 903 | * AV device initialization - only done at the last interface |
| 904 | */ |
| 905 | |
| 906 | /* Create v4l2 device */ |
Janne Grunau | 7231748 | 2009-04-01 08:39:29 -0300 | [diff] [blame] | 907 | retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 908 | if (retval) { |
| 909 | cx231xx_errdev("v4l2_device_register failed\n"); |
| 910 | cx231xx_devused &= ~(1 << nr); |
| 911 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 912 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 913 | return -EIO; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 914 | } |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 915 | /* allocate device struct */ |
| 916 | retval = cx231xx_init_dev(&dev, udev, nr); |
| 917 | if (retval) { |
| 918 | cx231xx_devused &= ~(1 << dev->devno); |
| 919 | v4l2_device_unregister(&dev->v4l2_dev); |
| 920 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 921 | dev = NULL; |
| 922 | usb_set_intfdata(lif, NULL); |
| 923 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 924 | return retval; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 925 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 926 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 927 | /* compute alternate max packet sizes for video */ |
| 928 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 929 | hs_config_info[0].interface_info.video_index + 1]; |
| 930 | |
| 931 | dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0]. |
| 932 | endpoint[isoc_pipe].desc.bEndpointAddress); |
| 933 | |
| 934 | dev->video_mode.num_alt = uif->num_altsetting; |
| 935 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 936 | dev->video_mode.end_point_addr, |
| 937 | dev->video_mode.num_alt); |
| 938 | dev->video_mode.alt_max_pkt_size = |
| 939 | kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); |
| 940 | |
| 941 | if (dev->video_mode.alt_max_pkt_size == NULL) { |
| 942 | cx231xx_errdev("out of memory!\n"); |
| 943 | cx231xx_devused &= ~(1 << nr); |
| 944 | v4l2_device_unregister(&dev->v4l2_dev); |
| 945 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 946 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 947 | return -ENOMEM; |
| 948 | } |
| 949 | |
| 950 | for (i = 0; i < dev->video_mode.num_alt; i++) { |
| 951 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 952 | desc.wMaxPacketSize); |
| 953 | dev->video_mode.alt_max_pkt_size[i] = |
| 954 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 955 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 956 | dev->video_mode.alt_max_pkt_size[i]); |
| 957 | } |
| 958 | |
| 959 | /* compute alternate max packet sizes for vbi */ |
| 960 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 961 | hs_config_info[0].interface_info. |
| 962 | vanc_index + 1]; |
| 963 | |
| 964 | dev->vbi_mode.end_point_addr = |
| 965 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 966 | bEndpointAddress); |
| 967 | |
| 968 | dev->vbi_mode.num_alt = uif->num_altsetting; |
| 969 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 970 | dev->vbi_mode.end_point_addr, |
| 971 | dev->vbi_mode.num_alt); |
| 972 | dev->vbi_mode.alt_max_pkt_size = |
| 973 | kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); |
| 974 | |
| 975 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { |
| 976 | cx231xx_errdev("out of memory!\n"); |
| 977 | cx231xx_devused &= ~(1 << nr); |
| 978 | v4l2_device_unregister(&dev->v4l2_dev); |
| 979 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 980 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 981 | return -ENOMEM; |
| 982 | } |
| 983 | |
| 984 | for (i = 0; i < dev->vbi_mode.num_alt; i++) { |
| 985 | u16 tmp = |
| 986 | le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 987 | desc.wMaxPacketSize); |
| 988 | dev->vbi_mode.alt_max_pkt_size[i] = |
| 989 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 990 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 991 | dev->vbi_mode.alt_max_pkt_size[i]); |
| 992 | } |
| 993 | |
| 994 | /* compute alternate max packet sizes for sliced CC */ |
| 995 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 996 | hs_config_info[0].interface_info. |
| 997 | hanc_index + 1]; |
| 998 | |
| 999 | dev->sliced_cc_mode.end_point_addr = |
| 1000 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 1001 | bEndpointAddress); |
| 1002 | |
| 1003 | dev->sliced_cc_mode.num_alt = uif->num_altsetting; |
| 1004 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 1005 | dev->sliced_cc_mode.end_point_addr, |
| 1006 | dev->sliced_cc_mode.num_alt); |
| 1007 | dev->sliced_cc_mode.alt_max_pkt_size = |
| 1008 | kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); |
| 1009 | |
| 1010 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { |
| 1011 | cx231xx_errdev("out of memory!\n"); |
| 1012 | cx231xx_devused &= ~(1 << nr); |
| 1013 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1014 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1015 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1016 | return -ENOMEM; |
| 1017 | } |
| 1018 | |
| 1019 | for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { |
| 1020 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 1021 | desc.wMaxPacketSize); |
| 1022 | dev->sliced_cc_mode.alt_max_pkt_size[i] = |
| 1023 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1024 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 1025 | dev->sliced_cc_mode.alt_max_pkt_size[i]); |
| 1026 | } |
| 1027 | |
| 1028 | if (dev->current_pcb_config.ts1_source != 0xff) { |
| 1029 | /* compute alternate max packet sizes for TS1 */ |
| 1030 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 1031 | hs_config_info[0]. |
| 1032 | interface_info. |
| 1033 | ts1_index + 1]; |
| 1034 | |
| 1035 | dev->ts1_mode.end_point_addr = |
| 1036 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. |
| 1037 | desc.bEndpointAddress); |
| 1038 | |
| 1039 | dev->ts1_mode.num_alt = uif->num_altsetting; |
| 1040 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 1041 | dev->ts1_mode.end_point_addr, |
| 1042 | dev->ts1_mode.num_alt); |
| 1043 | dev->ts1_mode.alt_max_pkt_size = |
| 1044 | kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); |
| 1045 | |
| 1046 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { |
| 1047 | cx231xx_errdev("out of memory!\n"); |
| 1048 | cx231xx_devused &= ~(1 << nr); |
| 1049 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1050 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1051 | dev = NULL; |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1052 | return -ENOMEM; |
| 1053 | } |
| 1054 | |
| 1055 | for (i = 0; i < dev->ts1_mode.num_alt; i++) { |
| 1056 | u16 tmp = le16_to_cpu(uif->altsetting[i]. |
| 1057 | endpoint[isoc_pipe].desc. |
| 1058 | wMaxPacketSize); |
| 1059 | dev->ts1_mode.alt_max_pkt_size[i] = |
| 1060 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 1061 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 1062 | dev->ts1_mode.alt_max_pkt_size[i]); |
| 1063 | } |
| 1064 | } |
| 1065 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1066 | if (dev->model == CX231XX_BOARD_CNXT_VIDEO_GRABBER) { |
| 1067 | cx231xx_enable_OSC(dev); |
| 1068 | cx231xx_reset_out(dev); |
| 1069 | cx231xx_set_alt_setting(dev, INDEX_VIDEO, 3); |
| 1070 | } |
| 1071 | |
| 1072 | if (dev->model == CX231XX_BOARD_CNXT_RDE_253S) |
| 1073 | cx231xx_sleep_s5h1432(dev); |
| 1074 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1075 | /* load other modules required */ |
| 1076 | request_modules(dev); |
| 1077 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | /* |
| 1082 | * cx231xx_usb_disconnect() |
| 1083 | * called when the device gets diconencted |
| 1084 | * video device will be unregistered on v4l2_close in case it is still open |
| 1085 | */ |
| 1086 | static void cx231xx_usb_disconnect(struct usb_interface *interface) |
| 1087 | { |
| 1088 | struct cx231xx *dev; |
| 1089 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1090 | dev = usb_get_intfdata(interface); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1091 | usb_set_intfdata(interface, NULL); |
| 1092 | |
| 1093 | if (!dev) |
| 1094 | return; |
| 1095 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame] | 1096 | if (!dev->udev) |
| 1097 | return; |
| 1098 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 1099 | /* delete v4l2 device */ |
| 1100 | v4l2_device_unregister(&dev->v4l2_dev); |
| 1101 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1102 | /* wait until all current v4l2 io is finished then deallocate |
| 1103 | resources */ |
| 1104 | mutex_lock(&dev->lock); |
| 1105 | |
| 1106 | wake_up_interruptible_all(&dev->open); |
| 1107 | |
| 1108 | if (dev->users) { |
| 1109 | cx231xx_warn |
Laurent Pinchart | 38c7c03 | 2009-11-27 13:57:15 -0300 | [diff] [blame] | 1110 | ("device %s is open! Deregistration and memory " |
| 1111 | "deallocation are deferred on close.\n", |
| 1112 | video_device_node_name(dev->vdev)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1113 | |
| 1114 | dev->state |= DEV_MISCONFIGURED; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1115 | if (dev->USE_ISO) |
| 1116 | cx231xx_uninit_isoc(dev); |
| 1117 | else |
| 1118 | cx231xx_uninit_bulk(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1119 | dev->state |= DEV_DISCONNECTED; |
| 1120 | wake_up_interruptible(&dev->wait_frame); |
| 1121 | wake_up_interruptible(&dev->wait_stream); |
| 1122 | } else { |
| 1123 | dev->state |= DEV_DISCONNECTED; |
| 1124 | cx231xx_release_resources(dev); |
| 1125 | } |
| 1126 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1127 | cx231xx_close_extension(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1128 | |
| 1129 | mutex_unlock(&dev->lock); |
| 1130 | |
| 1131 | if (!dev->users) { |
| 1132 | kfree(dev->video_mode.alt_max_pkt_size); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1133 | kfree(dev->vbi_mode.alt_max_pkt_size); |
| 1134 | kfree(dev->sliced_cc_mode.alt_max_pkt_size); |
| 1135 | kfree(dev->ts1_mode.alt_max_pkt_size); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1136 | kfree(dev); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 1137 | dev = NULL; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | static struct usb_driver cx231xx_usb_driver = { |
| 1142 | .name = "cx231xx", |
| 1143 | .probe = cx231xx_usb_probe, |
| 1144 | .disconnect = cx231xx_usb_disconnect, |
| 1145 | .id_table = cx231xx_id_table, |
| 1146 | }; |
| 1147 | |
| 1148 | static int __init cx231xx_module_init(void) |
| 1149 | { |
| 1150 | int result; |
| 1151 | |
Mauro Carvalho Chehab | 818fdf3 | 2009-03-13 07:41:58 -0300 | [diff] [blame] | 1152 | printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1153 | |
| 1154 | /* register this driver with the USB subsystem */ |
| 1155 | result = usb_register(&cx231xx_usb_driver); |
| 1156 | if (result) |
| 1157 | cx231xx_err(DRIVER_NAME |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1158 | " usb_register failed. Error number %d.\n", result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1159 | |
| 1160 | return result; |
| 1161 | } |
| 1162 | |
| 1163 | static void __exit cx231xx_module_exit(void) |
| 1164 | { |
| 1165 | /* deregister this driver with the USB subsystem */ |
| 1166 | usb_deregister(&cx231xx_usb_driver); |
| 1167 | } |
| 1168 | |
| 1169 | module_init(cx231xx_module_init); |
| 1170 | module_exit(cx231xx_module_exit); |