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