Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | DVB device driver for cx231xx |
| 3 | |
| 4 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 5 | Based on em28xx driver |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 24 | #include <linux/usb.h> |
| 25 | |
| 26 | #include "cx231xx.h" |
| 27 | #include <media/v4l2-common.h> |
| 28 | #include <media/videobuf-vmalloc.h> |
| 29 | |
| 30 | #include "xc5000.h" |
| 31 | #include "dvb_dummy_fe.h" |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 32 | #include "s5h1432.h" |
| 33 | #include "tda18271.h" |
| 34 | #include "s5h1411.h" |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 35 | #include "lgdt3305.h" |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 36 | #include "mb86a20s.h" |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 37 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 38 | MODULE_DESCRIPTION("driver for cx231xx based DVB cards"); |
| 39 | MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | static unsigned int debug; |
| 43 | module_param(debug, int, 0644); |
| 44 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 45 | |
| 46 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 47 | |
| 48 | #define dprintk(level, fmt, arg...) do { \ |
| 49 | if (debug >= level) \ |
| 50 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ |
| 51 | } while (0) |
| 52 | |
| 53 | #define CX231XX_DVB_NUM_BUFS 5 |
| 54 | #define CX231XX_DVB_MAX_PACKETSIZE 564 |
| 55 | #define CX231XX_DVB_MAX_PACKETS 64 |
| 56 | |
| 57 | struct cx231xx_dvb { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 58 | struct dvb_frontend *frontend; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 59 | |
| 60 | /* feed count management */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 61 | struct mutex lock; |
| 62 | int nfeeds; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 63 | |
| 64 | /* general boilerplate stuff */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 65 | struct dvb_adapter adapter; |
| 66 | struct dvb_demux demux; |
| 67 | struct dmxdev dmxdev; |
| 68 | struct dmx_frontend fe_hw; |
| 69 | struct dmx_frontend fe_mem; |
| 70 | struct dvb_net net; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 71 | }; |
| 72 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 73 | static struct s5h1432_config dvico_s5h1432_config = { |
| 74 | .output_mode = S5H1432_SERIAL_OUTPUT, |
| 75 | .gpio = S5H1432_GPIO_ON, |
| 76 | .qam_if = S5H1432_IF_4000, |
| 77 | .vsb_if = S5H1432_IF_4000, |
| 78 | .inversion = S5H1432_INVERSION_OFF, |
| 79 | .status_mode = S5H1432_DEMODLOCKING, |
| 80 | .mpeg_timing = S5H1432_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 81 | }; |
| 82 | |
| 83 | static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = { |
| 84 | .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4, |
| 85 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 86 | .dvbt_7 = { .if_freq = 4000, .agc_mode = 3, .std = 5, |
| 87 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 88 | .dvbt_8 = { .if_freq = 4000, .agc_mode = 3, .std = 6, |
| 89 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 90 | }; |
| 91 | |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 92 | static struct tda18271_std_map mb86a20s_tda18271_config = { |
| 93 | .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4, |
| 94 | .if_lvl = 7, .rfagc_top = 0x37, }, |
| 95 | }; |
| 96 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 97 | static struct tda18271_config cnxt_rde253s_tunerconfig = { |
| 98 | .std_map = &cnxt_rde253s_tda18271_std_map, |
| 99 | .gate = TDA18271_GATE_ANALOG, |
| 100 | }; |
| 101 | |
| 102 | static struct s5h1411_config tda18271_s5h1411_config = { |
| 103 | .output_mode = S5H1411_SERIAL_OUTPUT, |
| 104 | .gpio = S5H1411_GPIO_OFF, |
| 105 | .vsb_if = S5H1411_IF_3250, |
| 106 | .qam_if = S5H1411_IF_4000, |
| 107 | .inversion = S5H1411_INVERSION_ON, |
| 108 | .status_mode = S5H1411_DEMODLOCKING, |
| 109 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 110 | }; |
| 111 | static struct s5h1411_config xc5000_s5h1411_config = { |
| 112 | .output_mode = S5H1411_SERIAL_OUTPUT, |
| 113 | .gpio = S5H1411_GPIO_OFF, |
| 114 | .vsb_if = S5H1411_IF_3250, |
| 115 | .qam_if = S5H1411_IF_3250, |
| 116 | .inversion = S5H1411_INVERSION_OFF, |
| 117 | .status_mode = S5H1411_DEMODLOCKING, |
| 118 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 119 | }; |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 120 | |
| 121 | static struct lgdt3305_config hcw_lgdt3305_config = { |
| 122 | .i2c_addr = 0x0e, |
| 123 | .mpeg_mode = LGDT3305_MPEG_SERIAL, |
| 124 | .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, |
| 125 | .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, |
| 126 | .deny_i2c_rptr = 1, |
| 127 | .spectral_inversion = 1, |
| 128 | .qam_if_khz = 4000, |
| 129 | .vsb_if_khz = 3250, |
| 130 | }; |
| 131 | |
| 132 | static struct tda18271_std_map hauppauge_tda18271_std_map = { |
| 133 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4, |
| 134 | .if_lvl = 1, .rfagc_top = 0x58, }, |
| 135 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5, |
| 136 | .if_lvl = 1, .rfagc_top = 0x58, }, |
| 137 | }; |
| 138 | |
| 139 | static struct tda18271_config hcw_tda18271_config = { |
| 140 | .std_map = &hauppauge_tda18271_std_map, |
| 141 | .gate = TDA18271_GATE_DIGITAL, |
| 142 | }; |
| 143 | |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 144 | static const struct mb86a20s_config pv_mb86a20s_config = { |
| 145 | .demod_address = 0x10, |
Mauro Carvalho Chehab | 7572f9c | 2010-10-03 16:48:49 -0300 | [diff] [blame] | 146 | .is_serial = true, |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | static struct tda18271_config pv_tda18271_config = { |
| 150 | .std_map = &mb86a20s_tda18271_config, |
| 151 | .gate = TDA18271_GATE_DIGITAL, |
| 152 | .small_i2c = TDA18271_03_BYTE_CHUNK_INIT, |
| 153 | }; |
| 154 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 155 | static inline void print_err_status(struct cx231xx *dev, int packet, int status) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 156 | { |
| 157 | char *errmsg = "Unknown"; |
| 158 | |
| 159 | switch (status) { |
| 160 | case -ENOENT: |
| 161 | errmsg = "unlinked synchronuously"; |
| 162 | break; |
| 163 | case -ECONNRESET: |
| 164 | errmsg = "unlinked asynchronuously"; |
| 165 | break; |
| 166 | case -ENOSR: |
| 167 | errmsg = "Buffer error (overrun)"; |
| 168 | break; |
| 169 | case -EPIPE: |
| 170 | errmsg = "Stalled (device not responding)"; |
| 171 | break; |
| 172 | case -EOVERFLOW: |
| 173 | errmsg = "Babble (bad cable?)"; |
| 174 | break; |
| 175 | case -EPROTO: |
| 176 | errmsg = "Bit-stuff error (bad cable?)"; |
| 177 | break; |
| 178 | case -EILSEQ: |
| 179 | errmsg = "CRC/Timeout (could be anything)"; |
| 180 | break; |
| 181 | case -ETIME: |
| 182 | errmsg = "Device does not respond"; |
| 183 | break; |
| 184 | } |
| 185 | if (packet < 0) { |
| 186 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 187 | } else { |
| 188 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 189 | packet, status, errmsg); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb) |
| 194 | { |
| 195 | int i; |
| 196 | |
| 197 | if (!dev) |
| 198 | return 0; |
| 199 | |
| 200 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 201 | return 0; |
| 202 | |
| 203 | if (urb->status < 0) { |
| 204 | print_err_status(dev, -1, urb->status); |
| 205 | if (urb->status == -ENOENT) |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | for (i = 0; i < urb->number_of_packets; i++) { |
| 210 | int status = urb->iso_frame_desc[i].status; |
| 211 | |
| 212 | if (status < 0) { |
| 213 | print_err_status(dev, i, status); |
| 214 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 215 | continue; |
| 216 | } |
| 217 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 218 | dvb_dmx_swfilter(&dev->dvb->demux, |
| 219 | urb->transfer_buffer + |
| 220 | urb->iso_frame_desc[i].offset, |
| 221 | urb->iso_frame_desc[i].actual_length); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 227 | static inline int dvb_bulk_copy(struct cx231xx *dev, struct urb *urb) |
| 228 | { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 229 | if (!dev) |
| 230 | return 0; |
| 231 | |
| 232 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 233 | return 0; |
| 234 | |
| 235 | if (urb->status < 0) { |
| 236 | print_err_status(dev, -1, urb->status); |
| 237 | if (urb->status == -ENOENT) |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | /* Feed the transport payload into the kernel demux */ |
| 242 | dvb_dmx_swfilter(&dev->dvb->demux, |
| 243 | urb->transfer_buffer, urb->actual_length); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 248 | static int start_streaming(struct cx231xx_dvb *dvb) |
| 249 | { |
| 250 | int rc; |
| 251 | struct cx231xx *dev = dvb->adapter.priv; |
| 252 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 253 | if (dev->USE_ISO) { |
| 254 | cx231xx_info("DVB transfer mode is ISO.\n"); |
Mauro Carvalho Chehab | a6f6fb9 | 2010-09-26 20:38:24 -0300 | [diff] [blame] | 255 | mutex_lock(&dev->i2c_lock); |
| 256 | cx231xx_enable_i2c_port_3(dev, false); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 257 | cx231xx_set_alt_setting(dev, INDEX_TS1, 4); |
Mauro Carvalho Chehab | a6f6fb9 | 2010-09-26 20:38:24 -0300 | [diff] [blame] | 258 | cx231xx_enable_i2c_port_3(dev, true); |
| 259 | mutex_unlock(&dev->i2c_lock); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 260 | rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
| 261 | if (rc < 0) |
| 262 | return rc; |
| 263 | dev->mode_tv = 1; |
| 264 | return cx231xx_init_isoc(dev, CX231XX_DVB_MAX_PACKETS, |
| 265 | CX231XX_DVB_NUM_BUFS, |
| 266 | dev->ts1_mode.max_pkt_size, |
| 267 | dvb_isoc_copy); |
| 268 | } else { |
| 269 | cx231xx_info("DVB transfer mode is BULK.\n"); |
| 270 | cx231xx_set_alt_setting(dev, INDEX_TS1, 0); |
| 271 | rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
| 272 | if (rc < 0) |
| 273 | return rc; |
| 274 | dev->mode_tv = 1; |
| 275 | return cx231xx_init_bulk(dev, CX231XX_DVB_MAX_PACKETS, |
| 276 | CX231XX_DVB_NUM_BUFS, |
| 277 | dev->ts1_mode.max_pkt_size, |
| 278 | dvb_bulk_copy); |
| 279 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 280 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static int stop_streaming(struct cx231xx_dvb *dvb) |
| 284 | { |
| 285 | struct cx231xx *dev = dvb->adapter.priv; |
| 286 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 287 | if (dev->USE_ISO) |
| 288 | cx231xx_uninit_isoc(dev); |
| 289 | else |
| 290 | cx231xx_uninit_bulk(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 291 | |
| 292 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int start_feed(struct dvb_demux_feed *feed) |
| 298 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 299 | struct dvb_demux *demux = feed->demux; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 300 | struct cx231xx_dvb *dvb = demux->priv; |
| 301 | int rc, ret; |
| 302 | |
| 303 | if (!demux->dmx.frontend) |
| 304 | return -EINVAL; |
| 305 | |
| 306 | mutex_lock(&dvb->lock); |
| 307 | dvb->nfeeds++; |
| 308 | rc = dvb->nfeeds; |
| 309 | |
| 310 | if (dvb->nfeeds == 1) { |
| 311 | ret = start_streaming(dvb); |
| 312 | if (ret < 0) |
| 313 | rc = ret; |
| 314 | } |
| 315 | |
| 316 | mutex_unlock(&dvb->lock); |
| 317 | return rc; |
| 318 | } |
| 319 | |
| 320 | static int stop_feed(struct dvb_demux_feed *feed) |
| 321 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 322 | struct dvb_demux *demux = feed->demux; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 323 | struct cx231xx_dvb *dvb = demux->priv; |
| 324 | int err = 0; |
| 325 | |
| 326 | mutex_lock(&dvb->lock); |
| 327 | dvb->nfeeds--; |
| 328 | |
| 329 | if (0 == dvb->nfeeds) |
| 330 | err = stop_streaming(dvb); |
| 331 | |
| 332 | mutex_unlock(&dvb->lock); |
| 333 | return err; |
| 334 | } |
| 335 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 336 | /* ------------------------------------------------------------------ */ |
| 337 | static int cx231xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 338 | { |
| 339 | struct cx231xx *dev = fe->dvb->priv; |
| 340 | |
| 341 | if (acquire) |
| 342 | return cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
| 343 | else |
| 344 | return cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 345 | } |
| 346 | |
| 347 | /* ------------------------------------------------------------------ */ |
| 348 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 349 | static struct xc5000_config cnxt_rde250_tunerconfig = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 350 | .i2c_address = 0x61, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 351 | .if_khz = 4000, |
| 352 | }; |
| 353 | static struct xc5000_config cnxt_rdu250_tunerconfig = { |
| 354 | .i2c_address = 0x61, |
| 355 | .if_khz = 3250, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 356 | }; |
| 357 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 358 | /* ------------------------------------------------------------------ */ |
| 359 | #if 0 |
| 360 | static int attach_xc5000(u8 addr, struct cx231xx *dev) |
| 361 | { |
| 362 | |
| 363 | struct dvb_frontend *fe; |
| 364 | struct xc5000_config cfg; |
| 365 | |
| 366 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 367 | cfg.i2c_adap = &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 368 | cfg.i2c_addr = addr; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 369 | |
| 370 | if (!dev->dvb->frontend) { |
| 371 | printk(KERN_ERR "%s/2: dvb frontend not attached. " |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 372 | "Can't attach xc5000\n", dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 373 | return -EINVAL; |
| 374 | } |
| 375 | |
| 376 | fe = dvb_attach(xc5000_attach, dev->dvb->frontend, &cfg); |
| 377 | if (!fe) { |
| 378 | printk(KERN_ERR "%s/2: xc5000 attach failed\n", dev->name); |
| 379 | dvb_frontend_detach(dev->dvb->frontend); |
| 380 | dev->dvb->frontend = NULL; |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | |
| 384 | printk(KERN_INFO "%s/2: xc5000 attached\n", dev->name); |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | #endif |
| 389 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 390 | int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 391 | { |
| 392 | int status = 0; |
| 393 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 394 | if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 395 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 396 | struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 397 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 398 | if (dops->set_analog_params != NULL) { |
| 399 | struct analog_parameters params; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 400 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 401 | params.frequency = freq; |
| 402 | params.std = dev->norm; |
| 403 | params.mode = 0; /* 0- Air; 1 - cable */ |
| 404 | /*params.audmode = ; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 405 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 406 | /* Set the analog parameters to set the frequency */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 407 | dops->set_analog_params(dev->dvb->frontend, ¶ms); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 408 | } |
| 409 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 410 | } |
| 411 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 412 | return status; |
| 413 | } |
| 414 | |
| 415 | int cx231xx_reset_analog_tuner(struct cx231xx *dev) |
| 416 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 417 | int status = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 418 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 419 | if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 420 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 421 | struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 422 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 423 | if (dops->init != NULL && !dev->xc_fw_load_done) { |
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_info("Reloading firmware for XC5000\n"); |
| 426 | status = dops->init(dev->dvb->frontend); |
| 427 | if (status == 0) { |
| 428 | dev->xc_fw_load_done = 1; |
| 429 | cx231xx_info |
| 430 | ("XC5000 firmware download completed\n"); |
| 431 | } else { |
| 432 | dev->xc_fw_load_done = 0; |
| 433 | cx231xx_info |
| 434 | ("XC5000 firmware download failed !!!\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 435 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 436 | } |
| 437 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 438 | } |
| 439 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 440 | return status; |
| 441 | } |
| 442 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 443 | /* ------------------------------------------------------------------ */ |
| 444 | |
| 445 | static int register_dvb(struct cx231xx_dvb *dvb, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 446 | struct module *module, |
| 447 | struct cx231xx *dev, struct device *device) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 448 | { |
| 449 | int result; |
| 450 | |
| 451 | mutex_init(&dvb->lock); |
| 452 | |
| 453 | /* register adapter */ |
| 454 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 455 | adapter_nr); |
| 456 | if (result < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 457 | printk(KERN_WARNING |
| 458 | "%s: dvb_register_adapter failed (errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 459 | dev->name, result); |
| 460 | goto fail_adapter; |
| 461 | } |
| 462 | |
| 463 | /* Ensure all frontends negotiate bus access */ |
| 464 | dvb->frontend->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl; |
| 465 | |
| 466 | dvb->adapter.priv = dev; |
| 467 | |
| 468 | /* register frontend */ |
| 469 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 470 | if (result < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 471 | printk(KERN_WARNING |
| 472 | "%s: dvb_register_frontend failed (errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 473 | dev->name, result); |
| 474 | goto fail_frontend; |
| 475 | } |
| 476 | |
| 477 | /* register demux stuff */ |
| 478 | dvb->demux.dmx.capabilities = |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 479 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 480 | DMX_MEMORY_BASED_FILTERING; |
| 481 | dvb->demux.priv = dvb; |
| 482 | dvb->demux.filternum = 256; |
| 483 | dvb->demux.feednum = 256; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 484 | dvb->demux.start_feed = start_feed; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 485 | dvb->demux.stop_feed = stop_feed; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 486 | |
| 487 | result = dvb_dmx_init(&dvb->demux); |
| 488 | if (result < 0) { |
| 489 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 490 | dev->name, result); |
| 491 | goto fail_dmx; |
| 492 | } |
| 493 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 494 | dvb->dmxdev.filternum = 256; |
| 495 | dvb->dmxdev.demux = &dvb->demux.dmx; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 496 | dvb->dmxdev.capabilities = 0; |
| 497 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 498 | if (result < 0) { |
| 499 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 500 | dev->name, result); |
| 501 | goto fail_dmxdev; |
| 502 | } |
| 503 | |
| 504 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 505 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 506 | if (result < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 507 | printk(KERN_WARNING |
| 508 | "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 509 | dev->name, result); |
| 510 | goto fail_fe_hw; |
| 511 | } |
| 512 | |
| 513 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 514 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 515 | if (result < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 516 | printk(KERN_WARNING |
| 517 | "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 518 | dev->name, result); |
| 519 | goto fail_fe_mem; |
| 520 | } |
| 521 | |
| 522 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 523 | if (result < 0) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 524 | printk(KERN_WARNING |
| 525 | "%s: connect_frontend failed (errno = %d)\n", dev->name, |
| 526 | result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 527 | goto fail_fe_conn; |
| 528 | } |
| 529 | |
| 530 | /* register network adapter */ |
| 531 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 532 | return 0; |
| 533 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 534 | fail_fe_conn: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 535 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 536 | fail_fe_mem: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 537 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 538 | fail_fe_hw: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 539 | dvb_dmxdev_release(&dvb->dmxdev); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 540 | fail_dmxdev: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 541 | dvb_dmx_release(&dvb->demux); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 542 | fail_dmx: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 543 | dvb_unregister_frontend(dvb->frontend); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 544 | fail_frontend: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 545 | dvb_frontend_detach(dvb->frontend); |
| 546 | dvb_unregister_adapter(&dvb->adapter); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 547 | fail_adapter: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 548 | return result; |
| 549 | } |
| 550 | |
| 551 | static void unregister_dvb(struct cx231xx_dvb *dvb) |
| 552 | { |
| 553 | dvb_net_release(&dvb->net); |
| 554 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 555 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 556 | dvb_dmxdev_release(&dvb->dmxdev); |
| 557 | dvb_dmx_release(&dvb->demux); |
| 558 | dvb_unregister_frontend(dvb->frontend); |
| 559 | dvb_frontend_detach(dvb->frontend); |
| 560 | dvb_unregister_adapter(&dvb->adapter); |
| 561 | } |
| 562 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 563 | static int dvb_init(struct cx231xx *dev) |
| 564 | { |
| 565 | int result = 0; |
| 566 | struct cx231xx_dvb *dvb; |
| 567 | |
| 568 | if (!dev->board.has_dvb) { |
| 569 | /* This device does not support the extension */ |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | dvb = kzalloc(sizeof(struct cx231xx_dvb), GFP_KERNEL); |
| 574 | |
| 575 | if (dvb == NULL) { |
| 576 | printk(KERN_INFO "cx231xx_dvb: memory allocation failed\n"); |
| 577 | return -ENOMEM; |
| 578 | } |
| 579 | dev->dvb = dvb; |
| 580 | dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 581 | dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 582 | |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 583 | mutex_lock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 584 | cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 585 | cx231xx_demod_reset(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 586 | /* init frontend */ |
| 587 | switch (dev->model) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 588 | case CX231XX_BOARD_CNXT_CARRAERA: |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 589 | case CX231XX_BOARD_CNXT_RDE_250: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 590 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 591 | dev->dvb->frontend = dvb_attach(s5h1432_attach, |
| 592 | &dvico_s5h1432_config, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 593 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 594 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 595 | if (dev->dvb->frontend == NULL) { |
| 596 | printk(DRIVER_NAME |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 597 | ": Failed to attach s5h1432 front end\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 598 | result = -EINVAL; |
| 599 | goto out_free; |
| 600 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 601 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 602 | /* define general-purpose callback pointer */ |
| 603 | dvb->frontend->callback = cx231xx_tuner_callback; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 604 | |
Márton Németh | d5abcc7 | 2010-01-16 13:21:59 -0300 | [diff] [blame] | 605 | if (!dvb_attach(xc5000_attach, dev->dvb->frontend, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 606 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
Márton Németh | d5abcc7 | 2010-01-16 13:21:59 -0300 | [diff] [blame] | 607 | &cnxt_rde250_tunerconfig)) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 608 | result = -EINVAL; |
| 609 | goto out_free; |
| 610 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 611 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 612 | break; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 613 | case CX231XX_BOARD_CNXT_SHELBY: |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 614 | case CX231XX_BOARD_CNXT_RDU_250: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 615 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 616 | dev->dvb->frontend = dvb_attach(s5h1411_attach, |
| 617 | &xc5000_s5h1411_config, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 618 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 619 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 620 | if (dev->dvb->frontend == NULL) { |
| 621 | printk(DRIVER_NAME |
| 622 | ": Failed to attach dummy front end\n"); |
| 623 | result = -EINVAL; |
| 624 | goto out_free; |
| 625 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 626 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 627 | /* define general-purpose callback pointer */ |
| 628 | dvb->frontend->callback = cx231xx_tuner_callback; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 629 | |
Márton Németh | d5abcc7 | 2010-01-16 13:21:59 -0300 | [diff] [blame] | 630 | if (!dvb_attach(xc5000_attach, dev->dvb->frontend, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 631 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 632 | &cnxt_rdu250_tunerconfig)) { |
| 633 | result = -EINVAL; |
| 634 | goto out_free; |
| 635 | } |
| 636 | break; |
| 637 | case CX231XX_BOARD_CNXT_RDE_253S: |
| 638 | |
| 639 | dev->dvb->frontend = dvb_attach(s5h1432_attach, |
| 640 | &dvico_s5h1432_config, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 641 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 642 | |
| 643 | if (dev->dvb->frontend == NULL) { |
| 644 | printk(DRIVER_NAME |
| 645 | ": Failed to attach s5h1432 front end\n"); |
| 646 | result = -EINVAL; |
| 647 | goto out_free; |
| 648 | } |
| 649 | |
| 650 | /* define general-purpose callback pointer */ |
| 651 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 652 | |
| 653 | if (!dvb_attach(tda18271_attach, dev->dvb->frontend, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 654 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 655 | &cnxt_rde253s_tunerconfig)) { |
| 656 | result = -EINVAL; |
| 657 | goto out_free; |
| 658 | } |
| 659 | break; |
| 660 | case CX231XX_BOARD_CNXT_RDU_253S: |
| 661 | |
| 662 | dev->dvb->frontend = dvb_attach(s5h1411_attach, |
| 663 | &tda18271_s5h1411_config, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 664 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 665 | |
| 666 | if (dev->dvb->frontend == NULL) { |
| 667 | printk(DRIVER_NAME |
| 668 | ": Failed to attach dummy front end\n"); |
| 669 | result = -EINVAL; |
| 670 | goto out_free; |
| 671 | } |
| 672 | |
| 673 | /* define general-purpose callback pointer */ |
| 674 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 675 | |
| 676 | if (!dvb_attach(tda18271_attach, dev->dvb->frontend, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 677 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 678 | &cnxt_rde253s_tunerconfig)) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 679 | result = -EINVAL; |
| 680 | goto out_free; |
| 681 | } |
| 682 | break; |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 683 | case CX231XX_BOARD_HAUPPAUGE_EXETER: |
| 684 | |
| 685 | printk(KERN_INFO "%s: looking for tuner / demod on i2c bus: %d\n", |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 686 | __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap)); |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 687 | |
| 688 | dev->dvb->frontend = dvb_attach(lgdt3305_attach, |
| 689 | &hcw_lgdt3305_config, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 690 | &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap); |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 691 | |
| 692 | if (dev->dvb->frontend == NULL) { |
| 693 | printk(DRIVER_NAME |
| 694 | ": Failed to attach LG3305 front end\n"); |
| 695 | result = -EINVAL; |
| 696 | goto out_free; |
| 697 | } |
| 698 | |
| 699 | /* define general-purpose callback pointer */ |
| 700 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 701 | |
| 702 | dvb_attach(tda18271_attach, dev->dvb->frontend, |
Mauro Carvalho Chehab | 1a4aa92 | 2010-09-26 20:01:51 -0300 | [diff] [blame] | 703 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 704 | &hcw_tda18271_config); |
| 705 | break; |
| 706 | |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 707 | case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID: |
| 708 | |
| 709 | printk(KERN_INFO "%s: looking for demod on i2c bus: %d\n", |
| 710 | __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap)); |
| 711 | |
| 712 | dev->dvb->frontend = dvb_attach(mb86a20s_attach, |
| 713 | &pv_mb86a20s_config, |
| 714 | &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap); |
| 715 | |
| 716 | if (dev->dvb->frontend == NULL) { |
| 717 | printk(DRIVER_NAME |
| 718 | ": Failed to attach mb86a20s demod\n"); |
| 719 | result = -EINVAL; |
| 720 | goto out_free; |
| 721 | } |
| 722 | |
| 723 | /* define general-purpose callback pointer */ |
| 724 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 725 | |
| 726 | dvb_attach(tda18271_attach, dev->dvb->frontend, |
| 727 | 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap, |
| 728 | &pv_tda18271_config); |
| 729 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 730 | |
| 731 | default: |
| 732 | printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 733 | " isn't supported yet\n", dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 734 | break; |
| 735 | } |
| 736 | if (NULL == dvb->frontend) { |
| 737 | printk(KERN_ERR |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 738 | "%s/2: frontend initialization failed\n", dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 739 | result = -EINVAL; |
| 740 | goto out_free; |
| 741 | } |
| 742 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 743 | /* register everything */ |
| 744 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
| 745 | |
| 746 | if (result < 0) |
| 747 | goto out_free; |
| 748 | |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 749 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 750 | printk(KERN_INFO "Successfully loaded cx231xx-dvb\n"); |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 751 | |
| 752 | ret: |
| 753 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 754 | mutex_unlock(&dev->lock); |
| 755 | return result; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 756 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 757 | out_free: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 758 | kfree(dvb); |
| 759 | dev->dvb = NULL; |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 760 | goto ret; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | static int dvb_fini(struct cx231xx *dev) |
| 764 | { |
| 765 | if (!dev->board.has_dvb) { |
| 766 | /* This device does not support the extension */ |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | if (dev->dvb) { |
| 771 | unregister_dvb(dev->dvb); |
| 772 | dev->dvb = NULL; |
| 773 | } |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | static struct cx231xx_ops dvb_ops = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 779 | .id = CX231XX_DVB, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 780 | .name = "Cx231xx dvb Extension", |
| 781 | .init = dvb_init, |
| 782 | .fini = dvb_fini, |
| 783 | }; |
| 784 | |
| 785 | static int __init cx231xx_dvb_register(void) |
| 786 | { |
| 787 | return cx231xx_register_extension(&dvb_ops); |
| 788 | } |
| 789 | |
| 790 | static void __exit cx231xx_dvb_unregister(void) |
| 791 | { |
| 792 | cx231xx_unregister_extension(&dvb_ops); |
| 793 | } |
| 794 | |
| 795 | module_init(cx231xx_dvb_register); |
| 796 | module_exit(cx231xx_dvb_unregister); |