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