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