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> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/i2c.h> |
| 27 | #include <linux/usb.h> |
| 28 | #include <media/tuner.h> |
| 29 | #include <media/tveeprom.h> |
| 30 | #include <media/v4l2-common.h> |
| 31 | #include <media/v4l2-chip-ident.h> |
| 32 | |
| 33 | #include <media/cx25840.h> |
| 34 | #include "xc5000.h" |
| 35 | |
| 36 | #include "cx231xx.h" |
| 37 | |
| 38 | static int tuner = -1; |
| 39 | module_param(tuner, int, 0444); |
| 40 | MODULE_PARM_DESC(tuner, "tuner type"); |
| 41 | |
| 42 | static unsigned int disable_ir; |
| 43 | module_param(disable_ir, int, 0444); |
| 44 | MODULE_PARM_DESC(disable_ir, "disable infrared remote support"); |
| 45 | |
| 46 | /* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */ |
| 47 | static unsigned long cx231xx_devused; |
| 48 | |
| 49 | /* |
| 50 | * Reset sequences for analog/digital modes |
| 51 | */ |
| 52 | |
| 53 | static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 54 | {0x03, 0x01, 10}, |
| 55 | {0x03, 0x00, 30}, |
| 56 | {0x03, 0x01, 10}, |
| 57 | {-1, -1, -1}, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 58 | }; |
| 59 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 60 | /* |
| 61 | * Board definitions |
| 62 | */ |
| 63 | struct cx231xx_board cx231xx_boards[] = { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 64 | [CX231XX_BOARD_UNKNOWN] = { |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 65 | .name = "Unknown CX231xx video grabber", |
| 66 | .tuner_type = TUNER_ABSENT, |
| 67 | .input = {{ |
| 68 | .type = CX231XX_VMUX_TELEVISION, |
| 69 | .vmux = CX231XX_VIN_3_1, |
| 70 | .amux = CX231XX_AMUX_VIDEO, |
| 71 | .gpio = 0, |
| 72 | }, { |
| 73 | .type = CX231XX_VMUX_COMPOSITE1, |
| 74 | .vmux = CX231XX_VIN_2_1, |
| 75 | .amux = CX231XX_AMUX_LINE_IN, |
| 76 | .gpio = 0, |
| 77 | }, { |
| 78 | .type = CX231XX_VMUX_SVIDEO, |
| 79 | .vmux = CX231XX_VIN_1_1 | |
| 80 | (CX231XX_VIN_1_2 << 8) | |
| 81 | CX25840_SVIDEO_ON, |
| 82 | .amux = CX231XX_AMUX_LINE_IN, |
| 83 | .gpio = 0, |
| 84 | } |
| 85 | }, |
| 86 | }, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 87 | [CX231XX_BOARD_CNXT_RDE_250] = { |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 88 | .name = "Conexant Hybrid TV - RDE250", |
| 89 | .tuner_type = TUNER_XC5000, |
| 90 | .tuner_addr = 0x61, |
| 91 | .tuner_gpio = RDE250_XCV_TUNER, |
| 92 | .tuner_sif_gpio = 0x05, |
| 93 | .tuner_scl_gpio = 0x1a, |
| 94 | .tuner_sda_gpio = 0x1b, |
| 95 | .decoder = CX231XX_AVDECODER, |
| 96 | .demod_xfer_mode = 0, |
| 97 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 98 | .agc_analog_digital_select_gpio = 0x0c, |
| 99 | .gpio_pin_status_mask = 0x4001000, |
| 100 | .tuner_i2c_master = 1, |
| 101 | .demod_i2c_master = 2, |
| 102 | .has_dvb = 1, |
| 103 | .demod_addr = 0x02, |
| 104 | .norm = V4L2_STD_PAL, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 105 | |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 106 | .input = {{ |
| 107 | .type = CX231XX_VMUX_TELEVISION, |
| 108 | .vmux = CX231XX_VIN_3_1, |
| 109 | .amux = CX231XX_AMUX_VIDEO, |
| 110 | .gpio = 0, |
| 111 | }, { |
| 112 | .type = CX231XX_VMUX_COMPOSITE1, |
| 113 | .vmux = CX231XX_VIN_2_1, |
| 114 | .amux = CX231XX_AMUX_LINE_IN, |
| 115 | .gpio = 0, |
| 116 | }, { |
| 117 | .type = CX231XX_VMUX_SVIDEO, |
| 118 | .vmux = CX231XX_VIN_1_1 | |
| 119 | (CX231XX_VIN_1_2 << 8) | |
| 120 | CX25840_SVIDEO_ON, |
| 121 | .amux = CX231XX_AMUX_LINE_IN, |
| 122 | .gpio = 0, |
| 123 | } |
| 124 | }, |
| 125 | }, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 126 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 127 | [CX231XX_BOARD_CNXT_RDU_250] = { |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 128 | .name = "Conexant Hybrid TV - RDU250", |
| 129 | .tuner_type = TUNER_XC5000, |
| 130 | .tuner_addr = 0x61, |
| 131 | .tuner_gpio = RDE250_XCV_TUNER, |
| 132 | .tuner_sif_gpio = 0x05, |
| 133 | .tuner_scl_gpio = 0x1a, |
| 134 | .tuner_sda_gpio = 0x1b, |
| 135 | .decoder = CX231XX_AVDECODER, |
| 136 | .demod_xfer_mode = 0, |
| 137 | .ctl_pin_status_mask = 0xFFFFFFC4, |
| 138 | .agc_analog_digital_select_gpio = 0x0c, |
| 139 | .gpio_pin_status_mask = 0x4001000, |
| 140 | .tuner_i2c_master = 1, |
| 141 | .demod_i2c_master = 2, |
| 142 | .has_dvb = 1, |
| 143 | .demod_addr = 0x32, |
| 144 | .norm = V4L2_STD_NTSC, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 145 | |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 146 | .input = {{ |
| 147 | .type = CX231XX_VMUX_TELEVISION, |
| 148 | .vmux = CX231XX_VIN_3_1, |
| 149 | .amux = CX231XX_AMUX_VIDEO, |
| 150 | .gpio = 0, |
| 151 | }, { |
| 152 | .type = CX231XX_VMUX_COMPOSITE1, |
| 153 | .vmux = CX231XX_VIN_2_1, |
| 154 | .amux = CX231XX_AMUX_LINE_IN, |
| 155 | .gpio = 0, |
| 156 | }, { |
| 157 | .type = CX231XX_VMUX_SVIDEO, |
| 158 | .vmux = CX231XX_VIN_1_1 | |
| 159 | (CX231XX_VIN_1_2 << 8) | |
| 160 | CX25840_SVIDEO_ON, |
| 161 | .amux = CX231XX_AMUX_LINE_IN, |
| 162 | .gpio = 0, |
| 163 | } |
| 164 | }, |
| 165 | }, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 166 | }; |
| 167 | const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); |
| 168 | |
| 169 | /* table of devices that work with this driver */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 170 | struct usb_device_id cx231xx_id_table[] = { |
Sri Deevi | ed559ed | 2009-03-13 18:35:14 -0300 | [diff] [blame] | 171 | {USB_DEVICE(0x0572, 0x5A3C), |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 172 | .driver_info = CX231XX_BOARD_UNKNOWN}, |
| 173 | {USB_DEVICE(0x0572, 0x58A2), |
| 174 | .driver_info = CX231XX_BOARD_CNXT_RDE_250}, |
Sri Deevi | ed559ed | 2009-03-13 18:35:14 -0300 | [diff] [blame] | 175 | {USB_DEVICE(0x0572, 0x58A1), |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 176 | .driver_info = CX231XX_BOARD_CNXT_RDU_250}, |
| 177 | {}, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 178 | }; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 179 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 180 | MODULE_DEVICE_TABLE(usb, cx231xx_id_table); |
| 181 | |
| 182 | /* cx231xx_tuner_callback |
| 183 | * will be used to reset XC5000 tuner using GPIO pin |
| 184 | */ |
| 185 | |
| 186 | int cx231xx_tuner_callback(void *ptr, int component, int command, int arg) |
| 187 | { |
| 188 | int rc = 0; |
| 189 | struct cx231xx *dev = ptr; |
| 190 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 191 | if (dev->tuner_type == TUNER_XC5000) { |
| 192 | if (command == XC5000_TUNER_RESET) { |
| 193 | cx231xx_info |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 194 | ("Tuner CB: RESET: cmd %d : tuner type %d \n", |
| 195 | command, dev->tuner_type); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 196 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, |
| 197 | 1); |
| 198 | msleep(10); |
| 199 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, |
| 200 | 0); |
| 201 | msleep(330); |
| 202 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, |
| 203 | 1); |
| 204 | msleep(10); |
| 205 | } |
| 206 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 207 | return rc; |
| 208 | } |
| 209 | EXPORT_SYMBOL_GPL(cx231xx_tuner_callback); |
| 210 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 211 | static inline void cx231xx_set_model(struct cx231xx *dev) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 212 | { |
| 213 | memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board)); |
| 214 | } |
| 215 | |
| 216 | /* Since cx231xx_pre_card_setup() requires a proper dev->model, |
| 217 | * this won't work for boards with generic PCI IDs |
| 218 | */ |
| 219 | void cx231xx_pre_card_setup(struct cx231xx *dev) |
| 220 | { |
| 221 | |
| 222 | cx231xx_set_model(dev); |
| 223 | |
| 224 | cx231xx_info("Identified as %s (card=%d)\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 225 | dev->board.name, dev->model); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 226 | |
Sri Deevi | 6e4f574 | 2009-03-10 21:16:26 -0300 | [diff] [blame] | 227 | cx231xx_info("Precard: Board is %s\n", dev->board.name); |
| 228 | /* set the direction for GPIO pins */ |
| 229 | cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1); |
| 230 | cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1); |
| 231 | cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 232 | |
| 233 | /* request some modules if any required */ |
| 234 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 235 | /* reset the Tuner */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 236 | cx231xx_gpio_set(dev, dev->board.tuner_gpio); |
| 237 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 238 | /* set the mode to Analog mode initially */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 239 | cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); |
| 240 | |
| 241 | /* Unlock device */ |
| 242 | /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */ |
| 243 | |
| 244 | } |
| 245 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 246 | static void cx231xx_config_tuner(struct cx231xx *dev) |
| 247 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 248 | struct tuner_setup tun_setup; |
| 249 | struct v4l2_frequency f; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 250 | |
| 251 | if (dev->tuner_type == TUNER_ABSENT) |
| 252 | return; |
| 253 | |
| 254 | tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; |
| 255 | tun_setup.type = dev->tuner_type; |
| 256 | tun_setup.addr = dev->tuner_addr; |
| 257 | tun_setup.tuner_callback = cx231xx_tuner_callback; |
| 258 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 259 | tuner_call(dev, tuner, s_type_addr, &tun_setup); |
| 260 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 261 | #if 0 |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 262 | if (tun_setup.type == TUNER_XC5000) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 263 | static struct xc2028_ctrl ctrl = { |
| 264 | .fname = XC5000_DEFAULT_FIRMWARE, |
| 265 | .max_len = 64, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 266 | .demod = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 267 | }; |
| 268 | struct v4l2_priv_tun_config cfg = { |
| 269 | .tuner = dev->tuner_type, |
| 270 | .priv = &ctrl, |
| 271 | }; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 272 | tuner_call(dev, tuner, s_config, &cfg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 273 | } |
| 274 | #endif |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 275 | /* configure tuner */ |
| 276 | f.tuner = 0; |
| 277 | f.type = V4L2_TUNER_ANALOG_TV; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 278 | f.frequency = 9076; /* just a magic number */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 279 | dev->ctl_freq = f.frequency; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 280 | call_all(dev, tuner, s_frequency, &f); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 281 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 282 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 283 | |
| 284 | /* ----------------------------------------------------------------------- */ |
| 285 | void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir) |
| 286 | { |
| 287 | if (disable_ir) { |
| 288 | ir->get_key = NULL; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 289 | return; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* detect & configure */ |
| 293 | switch (dev->model) { |
| 294 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 295 | case CX231XX_BOARD_CNXT_RDE_250: |
| 296 | break; |
| 297 | case CX231XX_BOARD_CNXT_RDU_250: |
| 298 | break; |
| 299 | default: |
| 300 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | void cx231xx_card_setup(struct cx231xx *dev) |
| 305 | { |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 306 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 307 | cx231xx_set_model(dev); |
| 308 | |
| 309 | dev->tuner_type = cx231xx_boards[dev->model].tuner_type; |
| 310 | if (cx231xx_boards[dev->model].tuner_addr) |
| 311 | dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr; |
| 312 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 313 | cx231xx_info(": tuner type %d, tuner address %d \n", |
| 314 | dev->tuner_type, dev->tuner_addr); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 315 | |
| 316 | /* Do card specific if any */ |
| 317 | switch (dev->model) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 318 | case CX231XX_BOARD_CNXT_RDE_250: |
| 319 | /* do card specific GPIO settings if required */ |
Sri Deevi | ed559ed | 2009-03-13 18:35:14 -0300 | [diff] [blame] | 320 | cx231xx_info("Board is Conexant RDE 250\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 321 | break; |
| 322 | case CX231XX_BOARD_CNXT_RDU_250: |
| 323 | /* do card specific GPIO settings if required */ |
Sri Deevi | ed559ed | 2009-03-13 18:35:14 -0300 | [diff] [blame] | 324 | cx231xx_info("Board is Conexant RDU 250\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 325 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 326 | } |
| 327 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 328 | /* request some modules */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 329 | if (dev->board.decoder == CX231XX_AVDECODER) { |
| 330 | cx231xx_info(": Requesting cx25840 module\n"); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 331 | dev->sd_cx25840 = |
| 332 | v4l2_i2c_new_subdev(&dev->i2c_bus[0].i2c_adap, |
| 333 | "cx25840", "cx25840", 0x88 >> 1); |
| 334 | if (dev->sd_cx25840 == NULL) |
| 335 | cx231xx_info("cx25840 subdev registration failure\n"); |
| 336 | cx25840_call(dev, core, init, 0); |
| 337 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 338 | } |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 339 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 340 | if (dev->board.tuner_type != TUNER_ABSENT) { |
| 341 | cx231xx_info(": Requesting Tuner module\n"); |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 342 | dev->sd_tuner = |
| 343 | v4l2_i2c_new_subdev(&dev->i2c_bus[1].i2c_adap, |
| 344 | "tuner", "tuner", 0xc2 >> 1); |
| 345 | if (dev->sd_tuner == NULL) |
| 346 | cx231xx_info("tuner subdev registration failure\n"); |
| 347 | |
| 348 | cx231xx_config_tuner(dev); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 349 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 350 | |
| 351 | cx231xx_config_tuner(dev); |
| 352 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 353 | #if 0 |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 354 | /* TBD IR will be added later */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 355 | cx231xx_ir_init(dev); |
| 356 | #endif |
| 357 | } |
| 358 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 359 | /* |
| 360 | * cx231xx_config() |
| 361 | * inits registers with sane defaults |
| 362 | */ |
| 363 | int cx231xx_config(struct cx231xx *dev) |
| 364 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 365 | /* TBD need to add cx231xx specific code */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 366 | dev->mute = 1; /* maybe not the right place... */ |
| 367 | dev->volume = 0x1f; |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * cx231xx_config_i2c() |
| 374 | * configure i2c attached devices |
| 375 | */ |
| 376 | void cx231xx_config_i2c(struct cx231xx *dev) |
| 377 | { |
| 378 | struct v4l2_routing route; |
| 379 | |
| 380 | route.input = INPUT(dev->video_input)->vmux; |
| 381 | route.output = 0; |
| 382 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 383 | call_all(dev, video, s_stream, 1); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* |
| 387 | * cx231xx_realease_resources() |
| 388 | * unregisters the v4l2,i2c and usb devices |
| 389 | * called when the device gets disconected or at module unload |
| 390 | */ |
| 391 | void cx231xx_release_resources(struct cx231xx *dev) |
| 392 | { |
| 393 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 394 | #if 0 /* TBD IR related */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 395 | if (dev->ir) |
| 396 | cx231xx_ir_fini(dev); |
| 397 | #endif |
| 398 | |
| 399 | cx231xx_release_analog_resources(dev); |
| 400 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 401 | cx231xx_remove_from_devlist(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 402 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 403 | cx231xx_dev_uninit(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 404 | |
| 405 | usb_put_dev(dev->udev); |
| 406 | |
| 407 | /* Mark device as unused */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 408 | cx231xx_devused &= ~(1 << dev->devno); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 409 | } |
| 410 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 411 | /* |
| 412 | * cx231xx_init_dev() |
| 413 | * allocates and inits the device structs, registers i2c bus and v4l device |
| 414 | */ |
| 415 | 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] | 416 | int minor) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 417 | { |
| 418 | struct cx231xx *dev = *devhandle; |
| 419 | int retval = -ENOMEM; |
| 420 | int errCode; |
| 421 | unsigned int maxh, maxw; |
| 422 | |
| 423 | dev->udev = udev; |
| 424 | mutex_init(&dev->lock); |
| 425 | mutex_init(&dev->ctrl_urb_lock); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 426 | mutex_init(&dev->gpio_i2c_lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 427 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 428 | spin_lock_init(&dev->video_mode.slock); |
| 429 | spin_lock_init(&dev->vbi_mode.slock); |
| 430 | spin_lock_init(&dev->sliced_cc_mode.slock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 431 | |
| 432 | init_waitqueue_head(&dev->open); |
| 433 | init_waitqueue_head(&dev->wait_frame); |
| 434 | init_waitqueue_head(&dev->wait_stream); |
| 435 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 436 | dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg; |
| 437 | dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg; |
| 438 | dev->cx231xx_send_usb_command = cx231xx_send_usb_command; |
| 439 | dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read; |
| 440 | dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 441 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 442 | /* Query cx231xx to find what pcb config it is related to */ |
| 443 | initialize_cx231xx(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 444 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 445 | /* Cx231xx pre card setup */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 446 | cx231xx_pre_card_setup(dev); |
| 447 | |
| 448 | errCode = cx231xx_config(dev); |
| 449 | if (errCode) { |
| 450 | cx231xx_errdev("error configuring device\n"); |
| 451 | return -ENOMEM; |
| 452 | } |
| 453 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 454 | /* set default norm */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 455 | dev->norm = dev->board.norm; |
| 456 | |
| 457 | /* register i2c bus */ |
| 458 | errCode = cx231xx_dev_init(dev); |
| 459 | if (errCode < 0) { |
| 460 | cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 461 | __func__, errCode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 462 | return errCode; |
| 463 | } |
| 464 | |
| 465 | /* Do board specific init */ |
| 466 | cx231xx_card_setup(dev); |
| 467 | |
| 468 | /* configure the device */ |
| 469 | cx231xx_config_i2c(dev); |
| 470 | |
| 471 | maxw = norm_maxw(dev); |
| 472 | maxh = norm_maxh(dev); |
| 473 | |
| 474 | /* set default image size */ |
| 475 | dev->width = maxw; |
| 476 | dev->height = maxh; |
| 477 | dev->interlaced = 0; |
| 478 | dev->hscale = 0; |
| 479 | dev->vscale = 0; |
| 480 | dev->video_input = 0; |
| 481 | |
| 482 | errCode = cx231xx_config(dev); |
| 483 | if (errCode < 0) { |
| 484 | cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 485 | __func__, errCode); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 486 | return errCode; |
| 487 | } |
| 488 | |
| 489 | /* init video dma queues */ |
| 490 | INIT_LIST_HEAD(&dev->video_mode.vidq.active); |
| 491 | INIT_LIST_HEAD(&dev->video_mode.vidq.queued); |
| 492 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 493 | /* init vbi dma queues */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 494 | INIT_LIST_HEAD(&dev->vbi_mode.vidq.active); |
| 495 | INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued); |
| 496 | |
| 497 | /* Reset other chips required if they are tied up with GPIO pins */ |
| 498 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 499 | cx231xx_add_into_devlist(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 500 | |
| 501 | retval = cx231xx_register_analog_devices(dev); |
| 502 | if (retval < 0) { |
| 503 | cx231xx_release_resources(dev); |
| 504 | goto fail_reg_devices; |
| 505 | } |
| 506 | |
| 507 | cx231xx_init_extension(dev); |
| 508 | |
| 509 | return 0; |
| 510 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 511 | fail_reg_devices: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 512 | mutex_unlock(&dev->lock); |
| 513 | return retval; |
| 514 | } |
| 515 | |
| 516 | #if defined(CONFIG_MODULES) && defined(MODULE) |
| 517 | static void request_module_async(struct work_struct *work) |
| 518 | { |
| 519 | struct cx231xx *dev = container_of(work, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 520 | struct cx231xx, request_module_wk); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 521 | |
| 522 | if (dev->has_alsa_audio) |
| 523 | request_module("cx231xx-alsa"); |
| 524 | |
| 525 | if (dev->board.has_dvb) |
| 526 | request_module("cx231xx-dvb"); |
| 527 | |
| 528 | } |
| 529 | |
| 530 | static void request_modules(struct cx231xx *dev) |
| 531 | { |
| 532 | INIT_WORK(&dev->request_module_wk, request_module_async); |
| 533 | schedule_work(&dev->request_module_wk); |
| 534 | } |
| 535 | #else |
| 536 | #define request_modules(dev) |
| 537 | #endif /* CONFIG_MODULES */ |
| 538 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 539 | /* |
| 540 | * cx231xx_usb_probe() |
| 541 | * checks for supported devices |
| 542 | */ |
| 543 | static int cx231xx_usb_probe(struct usb_interface *interface, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 544 | const struct usb_device_id *id) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 545 | { |
| 546 | struct usb_device *udev; |
| 547 | struct usb_interface *uif; |
| 548 | struct cx231xx *dev = NULL; |
| 549 | int retval = -ENODEV; |
Hans Verkuil | d73abcf | 2009-03-12 18:38:40 -0300 | [diff] [blame] | 550 | int nr = 0, ifnum; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 551 | int i, isoc_pipe = 0; |
| 552 | char *speed; |
| 553 | char descr[255] = ""; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 554 | struct usb_interface *lif = NULL; |
| 555 | int skip_interface = 0; |
| 556 | struct usb_interface_assoc_descriptor *assoc_desc; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 557 | |
| 558 | udev = usb_get_dev(interface_to_usbdev(interface)); |
| 559 | ifnum = interface->altsetting[0].desc.bInterfaceNumber; |
| 560 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 561 | if (!ifnum) { |
| 562 | /* |
| 563 | * Interface number 0 - IR interface |
| 564 | */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 565 | /* Check to see next free device and mark as used */ |
| 566 | nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); |
| 567 | cx231xx_devused |= 1 << nr; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 568 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 569 | if (nr >= CX231XX_MAXBOARDS) { |
Mauro Carvalho Chehab | b905de3 | 2009-03-22 05:46:36 -0300 | [diff] [blame] | 570 | cx231xx_err(DRIVER_NAME ": Supports only %i cx231xx boards.\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 571 | CX231XX_MAXBOARDS); |
| 572 | cx231xx_devused &= ~(1 << nr); |
| 573 | return -ENOMEM; |
| 574 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 575 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 576 | /* allocate memory for our device state and initialize it */ |
| 577 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 578 | if (dev == NULL) { |
| 579 | cx231xx_err(DRIVER_NAME ": out of memory!\n"); |
| 580 | cx231xx_devused &= ~(1 << nr); |
| 581 | return -ENOMEM; |
| 582 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 583 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 584 | snprintf(dev->name, 29, "cx231xx #%d", nr); |
| 585 | dev->devno = nr; |
| 586 | dev->model = id->driver_info; |
| 587 | dev->video_mode.alt = -1; |
| 588 | dev->interface_count++; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 589 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 590 | /* reset gpio dir and value */ |
| 591 | dev->gpio_dir = 0; |
| 592 | dev->gpio_val = 0; |
| 593 | dev->xc_fw_load_done = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 594 | dev->has_alsa_audio = 1; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 595 | dev->power_mode = -1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 596 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 597 | /* 0 - vbi ; 1 -sliced cc mode */ |
| 598 | dev->vbi_or_sliced_cc_mode = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 599 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 600 | /* get maximum no.of IAD interfaces */ |
| 601 | assoc_desc = udev->actconfig->intf_assoc[0]; |
| 602 | dev->max_iad_interface_count = assoc_desc->bInterfaceCount; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 603 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 604 | /* init CIR module TBD */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 605 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 606 | /* store the current interface */ |
| 607 | lif = interface; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 608 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 609 | switch (udev->speed) { |
| 610 | case USB_SPEED_LOW: |
| 611 | speed = "1.5"; |
| 612 | break; |
| 613 | case USB_SPEED_UNKNOWN: |
| 614 | case USB_SPEED_FULL: |
| 615 | speed = "12"; |
| 616 | break; |
| 617 | case USB_SPEED_HIGH: |
| 618 | speed = "480"; |
| 619 | break; |
| 620 | default: |
| 621 | speed = "unknown"; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 622 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 623 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 624 | if (udev->manufacturer) |
| 625 | strlcpy(descr, udev->manufacturer, sizeof(descr)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 626 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 627 | if (udev->product) { |
| 628 | if (*descr) |
| 629 | strlcat(descr, " ", sizeof(descr)); |
| 630 | strlcat(descr, udev->product, sizeof(descr)); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 631 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 632 | if (*descr) |
| 633 | strlcat(descr, " ", sizeof(descr)); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 634 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 635 | cx231xx_info("New device %s@ %s Mbps " |
| 636 | "(%04x:%04x) with %d interfaces\n", |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 637 | descr, |
| 638 | speed, |
| 639 | le16_to_cpu(udev->descriptor.idVendor), |
| 640 | le16_to_cpu(udev->descriptor.idProduct), |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 641 | dev->max_iad_interface_count); |
| 642 | } else { |
| 643 | /* Get dev structure first */ |
| 644 | dev = usb_get_intfdata(udev->actconfig->interface[0]); |
| 645 | if (dev == NULL) { |
| 646 | cx231xx_err(DRIVER_NAME ": out of first interface!\n"); |
| 647 | return -ENODEV; |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 648 | } |
| 649 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 650 | /* store the interface 0 back */ |
| 651 | lif = udev->actconfig->interface[0]; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 652 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 653 | /* increment interface count */ |
| 654 | dev->interface_count++; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 655 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 656 | /* get device number */ |
| 657 | nr = dev->devno; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 658 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 659 | /* |
| 660 | * set skip interface, for all interfaces but |
| 661 | * interface 1 and the last one |
| 662 | */ |
| 663 | if ((ifnum != 1) && ((dev->interface_count - 1) |
| 664 | != dev->max_iad_interface_count)) |
| 665 | skip_interface = 1; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 666 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 667 | if (ifnum == 1) { |
| 668 | assoc_desc = udev->actconfig->intf_assoc[0]; |
| 669 | if (assoc_desc->bFirstInterface != ifnum) { |
| 670 | cx231xx_err(DRIVER_NAME ": Not found " |
| 671 | "matching IAD interface\n"); |
| 672 | return -ENODEV; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 673 | } |
| 674 | } |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 675 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 676 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 677 | if (skip_interface) |
| 678 | return -ENODEV; |
| 679 | |
| 680 | cx231xx_info("registering interface %d\n", ifnum); |
| 681 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 682 | /* save our data pointer in this interface device */ |
| 683 | usb_set_intfdata(lif, dev); |
| 684 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 685 | if ((dev->interface_count - 1) != dev->max_iad_interface_count) |
| 686 | return 0; |
| 687 | |
| 688 | /* |
| 689 | * AV device initialization - only done at the last interface |
| 690 | */ |
| 691 | |
| 692 | /* Create v4l2 device */ |
| 693 | snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), |
| 694 | "%s-%03d", "cx231xx", nr); |
| 695 | retval = v4l2_device_register(&udev->dev, &dev->v4l2_dev); |
| 696 | if (retval) { |
| 697 | cx231xx_errdev("v4l2_device_register failed\n"); |
| 698 | cx231xx_devused &= ~(1 << nr); |
| 699 | kfree(dev); |
| 700 | return -EIO; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 701 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 702 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 703 | /* allocate device struct */ |
| 704 | retval = cx231xx_init_dev(&dev, udev, nr); |
| 705 | if (retval) { |
| 706 | cx231xx_devused &= ~(1 << dev->devno); |
| 707 | v4l2_device_unregister(&dev->v4l2_dev); |
| 708 | kfree(dev); |
| 709 | return retval; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 710 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 711 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 712 | /* compute alternate max packet sizes for video */ |
| 713 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 714 | hs_config_info[0].interface_info.video_index + 1]; |
| 715 | |
| 716 | dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0]. |
| 717 | endpoint[isoc_pipe].desc.bEndpointAddress); |
| 718 | |
| 719 | dev->video_mode.num_alt = uif->num_altsetting; |
| 720 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 721 | dev->video_mode.end_point_addr, |
| 722 | dev->video_mode.num_alt); |
| 723 | dev->video_mode.alt_max_pkt_size = |
| 724 | kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); |
| 725 | |
| 726 | if (dev->video_mode.alt_max_pkt_size == NULL) { |
| 727 | cx231xx_errdev("out of memory!\n"); |
| 728 | cx231xx_devused &= ~(1 << nr); |
| 729 | v4l2_device_unregister(&dev->v4l2_dev); |
| 730 | kfree(dev); |
| 731 | return -ENOMEM; |
| 732 | } |
| 733 | |
| 734 | for (i = 0; i < dev->video_mode.num_alt; i++) { |
| 735 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 736 | desc.wMaxPacketSize); |
| 737 | dev->video_mode.alt_max_pkt_size[i] = |
| 738 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 739 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 740 | dev->video_mode.alt_max_pkt_size[i]); |
| 741 | } |
| 742 | |
| 743 | /* compute alternate max packet sizes for vbi */ |
| 744 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 745 | hs_config_info[0].interface_info. |
| 746 | vanc_index + 1]; |
| 747 | |
| 748 | dev->vbi_mode.end_point_addr = |
| 749 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 750 | bEndpointAddress); |
| 751 | |
| 752 | dev->vbi_mode.num_alt = uif->num_altsetting; |
| 753 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 754 | dev->vbi_mode.end_point_addr, |
| 755 | dev->vbi_mode.num_alt); |
| 756 | dev->vbi_mode.alt_max_pkt_size = |
| 757 | kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); |
| 758 | |
| 759 | if (dev->vbi_mode.alt_max_pkt_size == NULL) { |
| 760 | cx231xx_errdev("out of memory!\n"); |
| 761 | cx231xx_devused &= ~(1 << nr); |
| 762 | v4l2_device_unregister(&dev->v4l2_dev); |
| 763 | kfree(dev); |
| 764 | return -ENOMEM; |
| 765 | } |
| 766 | |
| 767 | for (i = 0; i < dev->vbi_mode.num_alt; i++) { |
| 768 | u16 tmp = |
| 769 | le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 770 | desc.wMaxPacketSize); |
| 771 | dev->vbi_mode.alt_max_pkt_size[i] = |
| 772 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 773 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 774 | dev->vbi_mode.alt_max_pkt_size[i]); |
| 775 | } |
| 776 | |
| 777 | /* compute alternate max packet sizes for sliced CC */ |
| 778 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 779 | hs_config_info[0].interface_info. |
| 780 | hanc_index + 1]; |
| 781 | |
| 782 | dev->sliced_cc_mode.end_point_addr = |
| 783 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. |
| 784 | bEndpointAddress); |
| 785 | |
| 786 | dev->sliced_cc_mode.num_alt = uif->num_altsetting; |
| 787 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 788 | dev->sliced_cc_mode.end_point_addr, |
| 789 | dev->sliced_cc_mode.num_alt); |
| 790 | dev->sliced_cc_mode.alt_max_pkt_size = |
| 791 | kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); |
| 792 | |
| 793 | if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { |
| 794 | cx231xx_errdev("out of memory!\n"); |
| 795 | cx231xx_devused &= ~(1 << nr); |
| 796 | v4l2_device_unregister(&dev->v4l2_dev); |
| 797 | kfree(dev); |
| 798 | return -ENOMEM; |
| 799 | } |
| 800 | |
| 801 | for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { |
| 802 | u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. |
| 803 | desc.wMaxPacketSize); |
| 804 | dev->sliced_cc_mode.alt_max_pkt_size[i] = |
| 805 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 806 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 807 | dev->sliced_cc_mode.alt_max_pkt_size[i]); |
| 808 | } |
| 809 | |
| 810 | if (dev->current_pcb_config.ts1_source != 0xff) { |
| 811 | /* compute alternate max packet sizes for TS1 */ |
| 812 | uif = udev->actconfig->interface[dev->current_pcb_config. |
| 813 | hs_config_info[0]. |
| 814 | interface_info. |
| 815 | ts1_index + 1]; |
| 816 | |
| 817 | dev->ts1_mode.end_point_addr = |
| 818 | le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. |
| 819 | desc.bEndpointAddress); |
| 820 | |
| 821 | dev->ts1_mode.num_alt = uif->num_altsetting; |
| 822 | cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", |
| 823 | dev->ts1_mode.end_point_addr, |
| 824 | dev->ts1_mode.num_alt); |
| 825 | dev->ts1_mode.alt_max_pkt_size = |
| 826 | kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); |
| 827 | |
| 828 | if (dev->ts1_mode.alt_max_pkt_size == NULL) { |
| 829 | cx231xx_errdev("out of memory!\n"); |
| 830 | cx231xx_devused &= ~(1 << nr); |
| 831 | v4l2_device_unregister(&dev->v4l2_dev); |
| 832 | kfree(dev); |
| 833 | return -ENOMEM; |
| 834 | } |
| 835 | |
| 836 | for (i = 0; i < dev->ts1_mode.num_alt; i++) { |
| 837 | u16 tmp = le16_to_cpu(uif->altsetting[i]. |
| 838 | endpoint[isoc_pipe].desc. |
| 839 | wMaxPacketSize); |
| 840 | dev->ts1_mode.alt_max_pkt_size[i] = |
| 841 | (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); |
| 842 | cx231xx_info("Alternate setting %i, max size= %i\n", i, |
| 843 | dev->ts1_mode.alt_max_pkt_size[i]); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | /* load other modules required */ |
| 848 | request_modules(dev); |
| 849 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | * cx231xx_usb_disconnect() |
| 855 | * called when the device gets diconencted |
| 856 | * video device will be unregistered on v4l2_close in case it is still open |
| 857 | */ |
| 858 | static void cx231xx_usb_disconnect(struct usb_interface *interface) |
| 859 | { |
| 860 | struct cx231xx *dev; |
| 861 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 862 | dev = usb_get_intfdata(interface); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 863 | usb_set_intfdata(interface, NULL); |
| 864 | |
| 865 | if (!dev) |
| 866 | return; |
| 867 | |
Mauro Carvalho Chehab | 9096074 | 2009-03-22 07:52:02 -0300 | [diff] [blame^] | 868 | if (!dev->udev) |
| 869 | return; |
| 870 | |
Sri Deevi | b119612 | 2009-03-20 23:33:48 -0300 | [diff] [blame] | 871 | /* delete v4l2 device */ |
| 872 | v4l2_device_unregister(&dev->v4l2_dev); |
| 873 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 874 | /* wait until all current v4l2 io is finished then deallocate |
| 875 | resources */ |
| 876 | mutex_lock(&dev->lock); |
| 877 | |
| 878 | wake_up_interruptible_all(&dev->open); |
| 879 | |
| 880 | if (dev->users) { |
| 881 | cx231xx_warn |
| 882 | ("device /dev/video%d is open! Deregistration and memory " |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 883 | "deallocation are deferred on close.\n", dev->vdev->num); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 884 | |
| 885 | dev->state |= DEV_MISCONFIGURED; |
| 886 | cx231xx_uninit_isoc(dev); |
| 887 | dev->state |= DEV_DISCONNECTED; |
| 888 | wake_up_interruptible(&dev->wait_frame); |
| 889 | wake_up_interruptible(&dev->wait_stream); |
| 890 | } else { |
| 891 | dev->state |= DEV_DISCONNECTED; |
| 892 | cx231xx_release_resources(dev); |
| 893 | } |
| 894 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 895 | cx231xx_close_extension(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 896 | |
| 897 | mutex_unlock(&dev->lock); |
| 898 | |
| 899 | if (!dev->users) { |
| 900 | kfree(dev->video_mode.alt_max_pkt_size); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 901 | kfree(dev->vbi_mode.alt_max_pkt_size); |
| 902 | kfree(dev->sliced_cc_mode.alt_max_pkt_size); |
| 903 | kfree(dev->ts1_mode.alt_max_pkt_size); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 904 | kfree(dev); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | static struct usb_driver cx231xx_usb_driver = { |
| 909 | .name = "cx231xx", |
| 910 | .probe = cx231xx_usb_probe, |
| 911 | .disconnect = cx231xx_usb_disconnect, |
| 912 | .id_table = cx231xx_id_table, |
| 913 | }; |
| 914 | |
| 915 | static int __init cx231xx_module_init(void) |
| 916 | { |
| 917 | int result; |
| 918 | |
Mauro Carvalho Chehab | 818fdf3 | 2009-03-13 07:41:58 -0300 | [diff] [blame] | 919 | printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 920 | |
| 921 | /* register this driver with the USB subsystem */ |
| 922 | result = usb_register(&cx231xx_usb_driver); |
| 923 | if (result) |
| 924 | cx231xx_err(DRIVER_NAME |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 925 | " usb_register failed. Error number %d.\n", result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 926 | |
| 927 | return result; |
| 928 | } |
| 929 | |
| 930 | static void __exit cx231xx_module_exit(void) |
| 931 | { |
| 932 | /* deregister this driver with the USB subsystem */ |
| 933 | usb_deregister(&cx231xx_usb_driver); |
| 934 | } |
| 935 | |
| 936 | module_init(cx231xx_module_init); |
| 937 | module_exit(cx231xx_module_exit); |