Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the NXP SAA7164 PCIe bridge |
| 3 | * |
| 4 | * Copyright (c) 2009 Steven Toth <stoth@kernellabs.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 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 "saa7164.h" |
| 23 | |
| 24 | #include "tda10048.h" |
| 25 | #include "tda18271.h" |
| 26 | #include "s5h1411.h" |
| 27 | |
| 28 | #define DRIVER_NAME "saa7164" |
| 29 | |
| 30 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 31 | |
| 32 | /* addr is in the card struct, get it from there */ |
| 33 | static struct tda10048_config hauppauge_hvr2200_1_config = { |
| 34 | .demod_address = 0x10 >> 1, |
| 35 | .output_mode = TDA10048_SERIAL_OUTPUT, |
| 36 | .fwbulkwritelen = TDA10048_BULKWRITE_200, |
Steven Toth | 7aa2e79 | 2009-05-10 10:25:34 -0300 | [diff] [blame] | 37 | .inversion = TDA10048_INVERSION_ON, |
Steven Toth | 3224401 | 2009-05-15 21:13:32 -0300 | [diff] [blame] | 38 | .dtv6_if_freq_khz = TDA10048_IF_3300, |
| 39 | .dtv7_if_freq_khz = TDA10048_IF_3500, |
| 40 | .dtv8_if_freq_khz = TDA10048_IF_4000, |
Steven Toth | 7aa2e79 | 2009-05-10 10:25:34 -0300 | [diff] [blame] | 41 | .clk_freq_khz = TDA10048_CLK_16000, |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 42 | }; |
| 43 | static struct tda10048_config hauppauge_hvr2200_2_config = { |
| 44 | .demod_address = 0x12 >> 1, |
| 45 | .output_mode = TDA10048_SERIAL_OUTPUT, |
| 46 | .fwbulkwritelen = TDA10048_BULKWRITE_200, |
Steven Toth | 7aa2e79 | 2009-05-10 10:25:34 -0300 | [diff] [blame] | 47 | .inversion = TDA10048_INVERSION_ON, |
Steven Toth | 3224401 | 2009-05-15 21:13:32 -0300 | [diff] [blame] | 48 | .dtv6_if_freq_khz = TDA10048_IF_3300, |
| 49 | .dtv7_if_freq_khz = TDA10048_IF_3500, |
| 50 | .dtv8_if_freq_khz = TDA10048_IF_4000, |
Steven Toth | 7aa2e79 | 2009-05-10 10:25:34 -0300 | [diff] [blame] | 51 | .clk_freq_khz = TDA10048_CLK_16000, |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static struct tda18271_std_map hauppauge_tda18271_std_map = { |
| 55 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 3, |
| 56 | .if_lvl = 6, .rfagc_top = 0x37 }, |
| 57 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0, |
| 58 | .if_lvl = 6, .rfagc_top = 0x37 }, |
| 59 | }; |
| 60 | |
| 61 | static struct tda18271_config hauppauge_hvr22x0_tuner_config = { |
| 62 | .std_map = &hauppauge_tda18271_std_map, |
| 63 | .gate = TDA18271_GATE_ANALOG, |
Steven Toth | 90e801a | 2009-08-27 18:08:21 -0300 | [diff] [blame] | 64 | .role = TDA18271_MASTER, |
| 65 | }; |
| 66 | |
| 67 | static struct tda18271_config hauppauge_hvr22x0s_tuner_config = { |
| 68 | .std_map = &hauppauge_tda18271_std_map, |
| 69 | .gate = TDA18271_GATE_ANALOG, |
| 70 | .role = TDA18271_SLAVE, |
| 71 | .rf_cal_on_startup = 1 |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static struct s5h1411_config hauppauge_s5h1411_config = { |
| 75 | .output_mode = S5H1411_SERIAL_OUTPUT, |
| 76 | .gpio = S5H1411_GPIO_ON, |
| 77 | .qam_if = S5H1411_IF_4000, |
| 78 | .vsb_if = S5H1411_IF_3250, |
| 79 | .inversion = S5H1411_INVERSION_ON, |
| 80 | .status_mode = S5H1411_DEMODLOCKING, |
| 81 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 82 | }; |
| 83 | |
| 84 | static int saa7164_dvb_stop_tsport(struct saa7164_tsport *port) |
| 85 | { |
| 86 | struct saa7164_dev *dev = port->dev; |
| 87 | int ret; |
| 88 | |
| 89 | ret = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 90 | if ((ret != SAA_OK) && (ret != SAA_ERR_ALREADY_STOPPED)) { |
| 91 | printk(KERN_ERR "%s() stop transition failed, ret = 0x%x\n", |
| 92 | __func__, ret); |
| 93 | ret = -EIO; |
| 94 | } else { |
| 95 | dprintk(DBGLVL_DVB, "%s() Stopped\n", __func__); |
| 96 | ret = 0; |
| 97 | } |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | static int saa7164_dvb_acquire_tsport(struct saa7164_tsport *port) |
| 103 | { |
| 104 | struct saa7164_dev *dev = port->dev; |
| 105 | int ret; |
| 106 | |
| 107 | ret = saa7164_api_transition_port(port, SAA_DMASTATE_ACQUIRE); |
| 108 | if ((ret != SAA_OK) && (ret != SAA_ERR_ALREADY_STOPPED)) { |
| 109 | printk(KERN_ERR "%s() acquire transition failed, ret = 0x%x\n", |
| 110 | __func__, ret); |
| 111 | ret = -EIO; |
| 112 | } else { |
| 113 | dprintk(DBGLVL_DVB, "%s() Acquired\n", __func__); |
| 114 | ret = 0; |
| 115 | } |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | static int saa7164_dvb_pause_tsport(struct saa7164_tsport *port) |
| 121 | { |
| 122 | struct saa7164_dev *dev = port->dev; |
| 123 | int ret; |
| 124 | |
| 125 | ret = saa7164_api_transition_port(port, SAA_DMASTATE_PAUSE); |
| 126 | if ((ret != SAA_OK) && (ret != SAA_ERR_ALREADY_STOPPED)) { |
| 127 | printk(KERN_ERR "%s() pause transition failed, ret = 0x%x\n", |
| 128 | __func__, ret); |
| 129 | ret = -EIO; |
| 130 | } else { |
| 131 | dprintk(DBGLVL_DVB, "%s() Paused\n", __func__); |
| 132 | ret = 0; |
| 133 | } |
| 134 | |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | /* Firmware is very windows centric, meaning you have to transition |
| 139 | * the part through AVStream / KS Windows stages, forwards or backwards. |
| 140 | * States are: stopped, acquired (h/w), paused, started. |
| 141 | */ |
| 142 | static int saa7164_dvb_stop_streaming(struct saa7164_tsport *port) |
| 143 | { |
| 144 | struct saa7164_dev *dev = port->dev; |
| 145 | int ret; |
| 146 | |
| 147 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 148 | |
| 149 | ret = saa7164_dvb_pause_tsport(port); |
| 150 | ret = saa7164_dvb_acquire_tsport(port); |
| 151 | ret = saa7164_dvb_stop_tsport(port); |
| 152 | |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | static int saa7164_dvb_cfg_tsport(struct saa7164_tsport *port) |
| 157 | { |
| 158 | tmHWStreamParameters_t *params = &port->hw_streamingparams; |
| 159 | struct saa7164_dev *dev = port->dev; |
| 160 | struct saa7164_buffer *buf; |
| 161 | struct list_head *c, *n; |
| 162 | int i = 0; |
| 163 | |
| 164 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 165 | |
| 166 | saa7164_writel(port->pitch, params->pitch); |
| 167 | saa7164_writel(port->bufsize, params->pitch * params->numberoflines); |
| 168 | |
| 169 | dprintk(DBGLVL_DVB, " configured:\n"); |
Steven Toth | 207b42c | 2009-05-09 21:30:05 -0300 | [diff] [blame] | 170 | dprintk(DBGLVL_DVB, " lmmio 0x%p\n", dev->lmmio); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 171 | dprintk(DBGLVL_DVB, " bufcounter 0x%x = 0x%x\n", port->bufcounter, |
| 172 | saa7164_readl(port->bufcounter)); |
| 173 | |
| 174 | dprintk(DBGLVL_DVB, " pitch 0x%x = %d\n", port->pitch, |
| 175 | saa7164_readl(port->pitch)); |
| 176 | |
| 177 | dprintk(DBGLVL_DVB, " bufsize 0x%x = %d\n", port->bufsize, |
| 178 | saa7164_readl(port->bufsize)); |
| 179 | |
| 180 | dprintk(DBGLVL_DVB, " buffercount = %d\n", port->hwcfg.buffercount); |
| 181 | dprintk(DBGLVL_DVB, " bufoffset = 0x%x\n", port->bufoffset); |
| 182 | dprintk(DBGLVL_DVB, " bufptr32h = 0x%x\n", port->bufptr32h); |
| 183 | dprintk(DBGLVL_DVB, " bufptr32l = 0x%x\n", port->bufptr32l); |
| 184 | |
| 185 | /* Poke the buffers and offsets into PCI space */ |
| 186 | mutex_lock(&port->dmaqueue_lock); |
| 187 | list_for_each_safe(c, n, &port->dmaqueue.list) { |
| 188 | buf = list_entry(c, struct saa7164_buffer, list); |
| 189 | |
| 190 | /* TODO: Review this in light of 32v64 assignments */ |
| 191 | saa7164_writel(port->bufoffset + (sizeof(u32) * i), 0); |
| 192 | saa7164_writel(port->bufptr32h + ((sizeof(u32) * 2) * i), |
| 193 | buf->pt_dma); |
| 194 | saa7164_writel(port->bufptr32l + ((sizeof(u32) * 2) * i), 0); |
| 195 | |
| 196 | dprintk(DBGLVL_DVB, |
Steven Toth | 207b42c | 2009-05-09 21:30:05 -0300 | [diff] [blame] | 197 | " buf[%d] offset 0x%llx (0x%x) " |
| 198 | "buf 0x%llx/%llx (0x%x/%x)\n", |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 199 | i, |
Steven Toth | 207b42c | 2009-05-09 21:30:05 -0300 | [diff] [blame] | 200 | (u64)port->bufoffset + (i * sizeof(u32)), |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 201 | saa7164_readl(port->bufoffset + (sizeof(u32) * i)), |
Steven Toth | 207b42c | 2009-05-09 21:30:05 -0300 | [diff] [blame] | 202 | (u64)port->bufptr32h + ((sizeof(u32) * 2) * i), |
| 203 | (u64)port->bufptr32l + ((sizeof(u32) * 2) * i), |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 204 | saa7164_readl(port->bufptr32h + ((sizeof(u32) * i) |
| 205 | * 2)), |
| 206 | saa7164_readl(port->bufptr32l + ((sizeof(u32) * i) |
| 207 | * 2))); |
| 208 | |
| 209 | if (i++ > port->hwcfg.buffercount) |
| 210 | BUG(); |
| 211 | |
| 212 | } |
| 213 | mutex_unlock(&port->dmaqueue_lock); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static int saa7164_dvb_start_tsport(struct saa7164_tsport *port) |
| 219 | { |
| 220 | struct saa7164_dev *dev = port->dev; |
| 221 | int ret = 0, result; |
| 222 | |
| 223 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 224 | |
| 225 | saa7164_dvb_cfg_tsport(port); |
| 226 | |
| 227 | /* Acquire the hardware */ |
| 228 | result = saa7164_api_transition_port(port, SAA_DMASTATE_ACQUIRE); |
| 229 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 230 | printk(KERN_ERR "%s() acquire transition failed, res = 0x%x\n", |
| 231 | __func__, result); |
| 232 | |
| 233 | /* Stop the hardware, regardless */ |
| 234 | result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 235 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 236 | printk(KERN_ERR "%s() acquire/forced stop transition " |
| 237 | "failed, res = 0x%x\n", __func__, result); |
| 238 | } |
| 239 | ret = -EIO; |
| 240 | goto out; |
| 241 | } else |
| 242 | dprintk(DBGLVL_DVB, "%s() Acquired\n", __func__); |
| 243 | |
| 244 | /* Pause the hardware */ |
| 245 | result = saa7164_api_transition_port(port, SAA_DMASTATE_PAUSE); |
| 246 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 247 | printk(KERN_ERR "%s() pause transition failed, res = 0x%x\n", |
| 248 | __func__, result); |
| 249 | |
| 250 | /* Stop the hardware, regardless */ |
| 251 | result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 252 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 253 | printk(KERN_ERR "%s() pause/forced stop transition " |
| 254 | "failed, res = 0x%x\n", __func__, result); |
| 255 | } |
| 256 | |
| 257 | ret = -EIO; |
| 258 | goto out; |
| 259 | } else |
| 260 | dprintk(DBGLVL_DVB, "%s() Paused\n", __func__); |
| 261 | |
| 262 | /* Start the hardware */ |
| 263 | result = saa7164_api_transition_port(port, SAA_DMASTATE_RUN); |
| 264 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 265 | printk(KERN_ERR "%s() run transition failed, result = 0x%x\n", |
| 266 | __func__, result); |
| 267 | |
| 268 | /* Stop the hardware, regardless */ |
| 269 | result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 270 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 271 | printk(KERN_ERR "%s() run/forced stop transition " |
| 272 | "failed, res = 0x%x\n", __func__, result); |
| 273 | } |
| 274 | |
| 275 | ret = -EIO; |
| 276 | } else |
| 277 | dprintk(DBGLVL_DVB, "%s() Running\n", __func__); |
| 278 | |
| 279 | out: |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | static int saa7164_dvb_start_feed(struct dvb_demux_feed *feed) |
| 284 | { |
| 285 | struct dvb_demux *demux = feed->demux; |
| 286 | struct saa7164_tsport *port = (struct saa7164_tsport *) demux->priv; |
| 287 | struct saa7164_dvb *dvb = &port->dvb; |
| 288 | struct saa7164_dev *dev = port->dev; |
| 289 | int ret = 0; |
| 290 | |
| 291 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 292 | |
| 293 | if (!demux->dmx.frontend) |
| 294 | return -EINVAL; |
| 295 | |
| 296 | if (dvb) { |
| 297 | mutex_lock(&dvb->lock); |
| 298 | if (dvb->feeding++ == 0) { |
| 299 | /* Start transport */ |
| 300 | ret = saa7164_dvb_start_tsport(port); |
| 301 | } |
| 302 | mutex_unlock(&dvb->lock); |
| 303 | dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n", |
| 304 | __func__, port->nr, dvb->feeding); |
| 305 | } |
| 306 | |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | static int saa7164_dvb_stop_feed(struct dvb_demux_feed *feed) |
| 311 | { |
| 312 | struct dvb_demux *demux = feed->demux; |
| 313 | struct saa7164_tsport *port = (struct saa7164_tsport *) demux->priv; |
| 314 | struct saa7164_dvb *dvb = &port->dvb; |
| 315 | struct saa7164_dev *dev = port->dev; |
| 316 | int ret = 0; |
| 317 | |
| 318 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 319 | |
| 320 | if (dvb) { |
| 321 | mutex_lock(&dvb->lock); |
| 322 | if (--dvb->feeding == 0) { |
| 323 | /* Stop transport */ |
| 324 | ret = saa7164_dvb_stop_streaming(port); |
| 325 | } |
| 326 | mutex_unlock(&dvb->lock); |
| 327 | dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n", |
| 328 | __func__, port->nr, dvb->feeding); |
| 329 | } |
| 330 | |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | static int dvb_register(struct saa7164_tsport *port) |
| 335 | { |
| 336 | struct saa7164_dvb *dvb = &port->dvb; |
| 337 | struct saa7164_dev *dev = port->dev; |
| 338 | struct saa7164_buffer *buf; |
| 339 | int result, i; |
| 340 | |
| 341 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 342 | |
| 343 | /* Sanity check that the PCI configuration space is active */ |
| 344 | if (port->hwcfg.BARLocation == 0) { |
| 345 | result = -ENOMEM; |
| 346 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 347 | "(errno = %d), NO PCI configuration\n", |
| 348 | DRIVER_NAME, result); |
| 349 | goto fail_adapter; |
| 350 | } |
| 351 | |
| 352 | /* Init and establish defaults */ |
| 353 | port->hw_streamingparams.bitspersample = 8; |
| 354 | port->hw_streamingparams.samplesperline = 188; |
| 355 | port->hw_streamingparams.numberoflines = |
| 356 | (SAA7164_TS_NUMBER_OF_LINES * 188) / 188; |
| 357 | |
| 358 | port->hw_streamingparams.pitch = 188; |
| 359 | port->hw_streamingparams.linethreshold = 0; |
| 360 | port->hw_streamingparams.pagetablelistvirt = 0; |
| 361 | port->hw_streamingparams.pagetablelistphys = 0; |
| 362 | port->hw_streamingparams.numpagetables = 2 + |
| 363 | ((SAA7164_TS_NUMBER_OF_LINES * 188) / PAGE_SIZE); |
| 364 | |
| 365 | port->hw_streamingparams.numpagetableentries = port->hwcfg.buffercount; |
| 366 | |
| 367 | /* Allocate the PCI resources */ |
| 368 | for (i = 0; i < port->hwcfg.buffercount; i++) { |
| 369 | buf = saa7164_buffer_alloc(port, |
| 370 | port->hw_streamingparams.numberoflines * |
| 371 | port->hw_streamingparams.pitch); |
| 372 | |
| 373 | if (!buf) { |
| 374 | result = -ENOMEM; |
| 375 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 376 | "(errno = %d), unable to allocate buffers\n", |
| 377 | DRIVER_NAME, result); |
| 378 | goto fail_adapter; |
| 379 | } |
| 380 | buf->nr = i; |
| 381 | |
| 382 | mutex_lock(&port->dmaqueue_lock); |
| 383 | list_add_tail(&buf->list, &port->dmaqueue.list); |
| 384 | mutex_unlock(&port->dmaqueue_lock); |
| 385 | } |
| 386 | |
| 387 | /* register adapter */ |
| 388 | result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE, |
| 389 | &dev->pci->dev, adapter_nr); |
| 390 | if (result < 0) { |
| 391 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 392 | "(errno = %d)\n", DRIVER_NAME, result); |
| 393 | goto fail_adapter; |
| 394 | } |
| 395 | dvb->adapter.priv = port; |
| 396 | |
| 397 | /* register frontend */ |
| 398 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 399 | if (result < 0) { |
| 400 | printk(KERN_ERR "%s: dvb_register_frontend failed " |
| 401 | "(errno = %d)\n", DRIVER_NAME, result); |
| 402 | goto fail_frontend; |
| 403 | } |
| 404 | |
| 405 | /* register demux stuff */ |
| 406 | dvb->demux.dmx.capabilities = |
| 407 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 408 | DMX_MEMORY_BASED_FILTERING; |
| 409 | dvb->demux.priv = port; |
| 410 | dvb->demux.filternum = 256; |
| 411 | dvb->demux.feednum = 256; |
| 412 | dvb->demux.start_feed = saa7164_dvb_start_feed; |
| 413 | dvb->demux.stop_feed = saa7164_dvb_stop_feed; |
| 414 | result = dvb_dmx_init(&dvb->demux); |
| 415 | if (result < 0) { |
| 416 | printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d)\n", |
| 417 | DRIVER_NAME, result); |
| 418 | goto fail_dmx; |
| 419 | } |
| 420 | |
| 421 | dvb->dmxdev.filternum = 256; |
| 422 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 423 | dvb->dmxdev.capabilities = 0; |
| 424 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 425 | if (result < 0) { |
| 426 | printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 427 | DRIVER_NAME, result); |
| 428 | goto fail_dmxdev; |
| 429 | } |
| 430 | |
| 431 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 432 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 433 | if (result < 0) { |
| 434 | printk(KERN_ERR "%s: add_frontend failed " |
| 435 | "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME, result); |
| 436 | goto fail_fe_hw; |
| 437 | } |
| 438 | |
| 439 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 440 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 441 | if (result < 0) { |
| 442 | printk(KERN_ERR "%s: add_frontend failed " |
| 443 | "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME, result); |
| 444 | goto fail_fe_mem; |
| 445 | } |
| 446 | |
| 447 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 448 | if (result < 0) { |
| 449 | printk(KERN_ERR "%s: connect_frontend failed (errno = %d)\n", |
| 450 | DRIVER_NAME, result); |
| 451 | goto fail_fe_conn; |
| 452 | } |
| 453 | |
| 454 | /* register network adapter */ |
| 455 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 456 | return 0; |
| 457 | |
| 458 | fail_fe_conn: |
| 459 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 460 | fail_fe_mem: |
| 461 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 462 | fail_fe_hw: |
| 463 | dvb_dmxdev_release(&dvb->dmxdev); |
| 464 | fail_dmxdev: |
| 465 | dvb_dmx_release(&dvb->demux); |
| 466 | fail_dmx: |
| 467 | dvb_unregister_frontend(dvb->frontend); |
| 468 | fail_frontend: |
| 469 | dvb_frontend_detach(dvb->frontend); |
| 470 | dvb_unregister_adapter(&dvb->adapter); |
| 471 | fail_adapter: |
| 472 | return result; |
| 473 | } |
| 474 | |
| 475 | int saa7164_dvb_unregister(struct saa7164_tsport *port) |
| 476 | { |
| 477 | struct saa7164_dvb *dvb = &port->dvb; |
| 478 | struct saa7164_dev *dev = port->dev; |
| 479 | struct saa7164_buffer *b; |
| 480 | struct list_head *c, *n; |
| 481 | |
| 482 | dprintk(DBGLVL_DVB, "%s()\n", __func__); |
| 483 | |
| 484 | /* Remove any allocated buffers */ |
| 485 | mutex_lock(&port->dmaqueue_lock); |
| 486 | list_for_each_safe(c, n, &port->dmaqueue.list) { |
| 487 | b = list_entry(c, struct saa7164_buffer, list); |
| 488 | list_del(c); |
| 489 | saa7164_buffer_dealloc(port, b); |
| 490 | } |
| 491 | mutex_unlock(&port->dmaqueue_lock); |
| 492 | |
| 493 | if (dvb->frontend == NULL) |
| 494 | return 0; |
| 495 | |
| 496 | dvb_net_release(&dvb->net); |
| 497 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 498 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 499 | dvb_dmxdev_release(&dvb->dmxdev); |
| 500 | dvb_dmx_release(&dvb->demux); |
| 501 | dvb_unregister_frontend(dvb->frontend); |
| 502 | dvb_frontend_detach(dvb->frontend); |
| 503 | dvb_unregister_adapter(&dvb->adapter); |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | /* All the DVB attach calls go here, this function get's modified |
| 508 | * for each new card. |
| 509 | */ |
| 510 | int saa7164_dvb_register(struct saa7164_tsport *port) |
| 511 | { |
| 512 | struct saa7164_dev *dev = port->dev; |
| 513 | struct saa7164_dvb *dvb = &port->dvb; |
| 514 | struct saa7164_i2c *i2c_bus = NULL; |
| 515 | int ret; |
| 516 | |
| 517 | dprintk(DBGLVL_DVB, "%s()\n", __func__); |
| 518 | |
| 519 | /* init frontend */ |
| 520 | switch (dev->board) { |
| 521 | case SAA7164_BOARD_HAUPPAUGE_HVR2200: |
| 522 | case SAA7164_BOARD_HAUPPAUGE_HVR2200_2: |
| 523 | case SAA7164_BOARD_HAUPPAUGE_HVR2200_3: |
Steven Toth | 8bfd4b2 | 2009-08-29 14:33:06 -0300 | [diff] [blame] | 524 | i2c_bus = &dev->i2c_bus[port->nr + 1]; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 525 | switch (port->nr) { |
| 526 | case 0: |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 527 | port->dvb.frontend = dvb_attach(tda10048_attach, |
| 528 | &hauppauge_hvr2200_1_config, |
| 529 | &i2c_bus->i2c_adap); |
| 530 | |
| 531 | if (port->dvb.frontend != NULL) { |
Steven Toth | 1f8c40b | 2009-08-29 14:22:05 -0300 | [diff] [blame] | 532 | /* TODO: addr is in the card struct */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 533 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 534 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
| 535 | &hauppauge_hvr22x0_tuner_config); |
| 536 | } |
| 537 | |
| 538 | break; |
| 539 | case 1: |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 540 | port->dvb.frontend = dvb_attach(tda10048_attach, |
| 541 | &hauppauge_hvr2200_2_config, |
| 542 | &i2c_bus->i2c_adap); |
| 543 | |
| 544 | if (port->dvb.frontend != NULL) { |
Steven Toth | 1f8c40b | 2009-08-29 14:22:05 -0300 | [diff] [blame] | 545 | /* TODO: addr is in the card struct */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 546 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 547 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
Steven Toth | 151ec0d9 | 2009-08-29 14:41:18 -0300 | [diff] [blame] | 548 | &hauppauge_hvr22x0s_tuner_config); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | break; |
| 552 | } |
| 553 | break; |
| 554 | case SAA7164_BOARD_HAUPPAUGE_HVR2250: |
| 555 | case SAA7164_BOARD_HAUPPAUGE_HVR2250_2: |
Steven Toth | e333522 | 2009-05-11 22:03:07 -0300 | [diff] [blame] | 556 | case SAA7164_BOARD_HAUPPAUGE_HVR2250_3: |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 557 | i2c_bus = &dev->i2c_bus[port->nr + 1]; |
| 558 | |
| 559 | port->dvb.frontend = dvb_attach(s5h1411_attach, |
| 560 | &hauppauge_s5h1411_config, |
| 561 | &i2c_bus->i2c_adap); |
| 562 | |
| 563 | if (port->dvb.frontend != NULL) { |
Steven Toth | 90e801a | 2009-08-27 18:08:21 -0300 | [diff] [blame] | 564 | if (port->nr == 0) { |
| 565 | /* Master TDA18271 */ |
| 566 | /* TODO: addr is in the card struct */ |
| 567 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 568 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
| 569 | &hauppauge_hvr22x0_tuner_config); |
| 570 | } else { |
| 571 | /* Slave TDA18271 */ |
| 572 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 573 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
| 574 | &hauppauge_hvr22x0s_tuner_config); |
| 575 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | break; |
| 579 | default: |
| 580 | printk(KERN_ERR "%s: The frontend isn't supported\n", |
| 581 | dev->name); |
| 582 | break; |
| 583 | } |
| 584 | if (NULL == dvb->frontend) { |
| 585 | printk(KERN_ERR "%s() Frontend initialization failed\n", |
| 586 | __func__); |
| 587 | return -1; |
| 588 | } |
| 589 | |
| 590 | /* Put the analog decoder in standby to keep it quiet */ |
| 591 | |
| 592 | /* register everything */ |
| 593 | ret = dvb_register(port); |
| 594 | if (ret < 0) { |
| 595 | if (dvb->frontend->ops.release) |
| 596 | dvb->frontend->ops.release(dvb->frontend); |
| 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |