Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the NXP SAA7164 PCIe bridge |
| 3 | * |
Steven Toth | 9b8b019 | 2010-07-31 14:39:44 -0300 | [diff] [blame] | 4 | * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 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, |
Michael Krufky | bc809ab | 2009-09-28 16:44:52 -0300 | [diff] [blame] | 71 | .output_opt = TDA18271_OUTPUT_LT_OFF, |
Steven Toth | 90e801a | 2009-08-27 18:08:21 -0300 | [diff] [blame] | 72 | .rf_cal_on_startup = 1 |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static struct s5h1411_config hauppauge_s5h1411_config = { |
| 76 | .output_mode = S5H1411_SERIAL_OUTPUT, |
| 77 | .gpio = S5H1411_GPIO_ON, |
| 78 | .qam_if = S5H1411_IF_4000, |
| 79 | .vsb_if = S5H1411_IF_3250, |
| 80 | .inversion = S5H1411_INVERSION_ON, |
| 81 | .status_mode = S5H1411_DEMODLOCKING, |
| 82 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 83 | }; |
| 84 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 85 | static int saa7164_dvb_stop_port(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 86 | { |
| 87 | struct saa7164_dev *dev = port->dev; |
| 88 | int ret; |
| 89 | |
| 90 | ret = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 91 | if ((ret != SAA_OK) && (ret != SAA_ERR_ALREADY_STOPPED)) { |
| 92 | printk(KERN_ERR "%s() stop transition failed, ret = 0x%x\n", |
| 93 | __func__, ret); |
| 94 | ret = -EIO; |
| 95 | } else { |
| 96 | dprintk(DBGLVL_DVB, "%s() Stopped\n", __func__); |
| 97 | ret = 0; |
| 98 | } |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 103 | static int saa7164_dvb_acquire_port(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 104 | { |
| 105 | struct saa7164_dev *dev = port->dev; |
| 106 | int ret; |
| 107 | |
| 108 | ret = saa7164_api_transition_port(port, SAA_DMASTATE_ACQUIRE); |
| 109 | if ((ret != SAA_OK) && (ret != SAA_ERR_ALREADY_STOPPED)) { |
| 110 | printk(KERN_ERR "%s() acquire transition failed, ret = 0x%x\n", |
| 111 | __func__, ret); |
| 112 | ret = -EIO; |
| 113 | } else { |
| 114 | dprintk(DBGLVL_DVB, "%s() Acquired\n", __func__); |
| 115 | ret = 0; |
| 116 | } |
| 117 | |
| 118 | return ret; |
| 119 | } |
| 120 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 121 | static int saa7164_dvb_pause_port(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 122 | { |
| 123 | struct saa7164_dev *dev = port->dev; |
| 124 | int ret; |
| 125 | |
| 126 | ret = saa7164_api_transition_port(port, SAA_DMASTATE_PAUSE); |
| 127 | if ((ret != SAA_OK) && (ret != SAA_ERR_ALREADY_STOPPED)) { |
| 128 | printk(KERN_ERR "%s() pause transition failed, ret = 0x%x\n", |
| 129 | __func__, ret); |
| 130 | ret = -EIO; |
| 131 | } else { |
| 132 | dprintk(DBGLVL_DVB, "%s() Paused\n", __func__); |
| 133 | ret = 0; |
| 134 | } |
| 135 | |
| 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | /* Firmware is very windows centric, meaning you have to transition |
| 140 | * the part through AVStream / KS Windows stages, forwards or backwards. |
| 141 | * States are: stopped, acquired (h/w), paused, started. |
| 142 | */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 143 | static int saa7164_dvb_stop_streaming(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 144 | { |
| 145 | struct saa7164_dev *dev = port->dev; |
| 146 | int ret; |
| 147 | |
| 148 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 149 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 150 | ret = saa7164_dvb_pause_port(port); |
| 151 | ret = saa7164_dvb_acquire_port(port); |
| 152 | ret = saa7164_dvb_stop_port(port); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 153 | |
| 154 | return ret; |
| 155 | } |
| 156 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 157 | static int saa7164_dvb_start_port(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 158 | { |
| 159 | struct saa7164_dev *dev = port->dev; |
| 160 | int ret = 0, result; |
| 161 | |
| 162 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 163 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 164 | saa7164_buffer_cfg_port(port); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 165 | |
| 166 | /* Acquire the hardware */ |
| 167 | result = saa7164_api_transition_port(port, SAA_DMASTATE_ACQUIRE); |
| 168 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 169 | printk(KERN_ERR "%s() acquire transition failed, res = 0x%x\n", |
| 170 | __func__, result); |
| 171 | |
| 172 | /* Stop the hardware, regardless */ |
| 173 | result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 174 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 175 | printk(KERN_ERR "%s() acquire/forced stop transition " |
| 176 | "failed, res = 0x%x\n", __func__, result); |
| 177 | } |
| 178 | ret = -EIO; |
| 179 | goto out; |
| 180 | } else |
| 181 | dprintk(DBGLVL_DVB, "%s() Acquired\n", __func__); |
| 182 | |
| 183 | /* Pause the hardware */ |
| 184 | result = saa7164_api_transition_port(port, SAA_DMASTATE_PAUSE); |
| 185 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 186 | printk(KERN_ERR "%s() pause transition failed, res = 0x%x\n", |
| 187 | __func__, result); |
| 188 | |
| 189 | /* Stop the hardware, regardless */ |
| 190 | result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 191 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 192 | printk(KERN_ERR "%s() pause/forced stop transition " |
| 193 | "failed, res = 0x%x\n", __func__, result); |
| 194 | } |
| 195 | |
| 196 | ret = -EIO; |
| 197 | goto out; |
| 198 | } else |
| 199 | dprintk(DBGLVL_DVB, "%s() Paused\n", __func__); |
| 200 | |
| 201 | /* Start the hardware */ |
| 202 | result = saa7164_api_transition_port(port, SAA_DMASTATE_RUN); |
| 203 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 204 | printk(KERN_ERR "%s() run transition failed, result = 0x%x\n", |
| 205 | __func__, result); |
| 206 | |
| 207 | /* Stop the hardware, regardless */ |
| 208 | result = saa7164_api_transition_port(port, SAA_DMASTATE_STOP); |
| 209 | if ((result != SAA_OK) && (result != SAA_ERR_ALREADY_STOPPED)) { |
| 210 | printk(KERN_ERR "%s() run/forced stop transition " |
| 211 | "failed, res = 0x%x\n", __func__, result); |
| 212 | } |
| 213 | |
| 214 | ret = -EIO; |
| 215 | } else |
| 216 | dprintk(DBGLVL_DVB, "%s() Running\n", __func__); |
| 217 | |
| 218 | out: |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | static int saa7164_dvb_start_feed(struct dvb_demux_feed *feed) |
| 223 | { |
| 224 | struct dvb_demux *demux = feed->demux; |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 225 | struct saa7164_port *port = (struct saa7164_port *) demux->priv; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 226 | struct saa7164_dvb *dvb = &port->dvb; |
| 227 | struct saa7164_dev *dev = port->dev; |
| 228 | int ret = 0; |
| 229 | |
| 230 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 231 | |
| 232 | if (!demux->dmx.frontend) |
| 233 | return -EINVAL; |
| 234 | |
| 235 | if (dvb) { |
| 236 | mutex_lock(&dvb->lock); |
| 237 | if (dvb->feeding++ == 0) { |
| 238 | /* Start transport */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 239 | ret = saa7164_dvb_start_port(port); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 240 | } |
| 241 | mutex_unlock(&dvb->lock); |
| 242 | dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n", |
| 243 | __func__, port->nr, dvb->feeding); |
| 244 | } |
| 245 | |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | static int saa7164_dvb_stop_feed(struct dvb_demux_feed *feed) |
| 250 | { |
| 251 | struct dvb_demux *demux = feed->demux; |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 252 | struct saa7164_port *port = (struct saa7164_port *) demux->priv; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 253 | struct saa7164_dvb *dvb = &port->dvb; |
| 254 | struct saa7164_dev *dev = port->dev; |
| 255 | int ret = 0; |
| 256 | |
| 257 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 258 | |
| 259 | if (dvb) { |
| 260 | mutex_lock(&dvb->lock); |
| 261 | if (--dvb->feeding == 0) { |
| 262 | /* Stop transport */ |
| 263 | ret = saa7164_dvb_stop_streaming(port); |
| 264 | } |
| 265 | mutex_unlock(&dvb->lock); |
| 266 | dprintk(DBGLVL_DVB, "%s(port=%d) now feeding = %d\n", |
| 267 | __func__, port->nr, dvb->feeding); |
| 268 | } |
| 269 | |
| 270 | return ret; |
| 271 | } |
| 272 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 273 | static int dvb_register(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 274 | { |
| 275 | struct saa7164_dvb *dvb = &port->dvb; |
| 276 | struct saa7164_dev *dev = port->dev; |
| 277 | struct saa7164_buffer *buf; |
| 278 | int result, i; |
| 279 | |
| 280 | dprintk(DBGLVL_DVB, "%s(port=%d)\n", __func__, port->nr); |
| 281 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 282 | if (port->type != SAA7164_MPEG_DVB) |
| 283 | BUG(); |
| 284 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 285 | /* Sanity check that the PCI configuration space is active */ |
| 286 | if (port->hwcfg.BARLocation == 0) { |
| 287 | result = -ENOMEM; |
| 288 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 289 | "(errno = %d), NO PCI configuration\n", |
| 290 | DRIVER_NAME, result); |
| 291 | goto fail_adapter; |
| 292 | } |
| 293 | |
| 294 | /* Init and establish defaults */ |
| 295 | port->hw_streamingparams.bitspersample = 8; |
| 296 | port->hw_streamingparams.samplesperline = 188; |
| 297 | port->hw_streamingparams.numberoflines = |
| 298 | (SAA7164_TS_NUMBER_OF_LINES * 188) / 188; |
| 299 | |
| 300 | port->hw_streamingparams.pitch = 188; |
| 301 | port->hw_streamingparams.linethreshold = 0; |
| 302 | port->hw_streamingparams.pagetablelistvirt = 0; |
| 303 | port->hw_streamingparams.pagetablelistphys = 0; |
| 304 | port->hw_streamingparams.numpagetables = 2 + |
| 305 | ((SAA7164_TS_NUMBER_OF_LINES * 188) / PAGE_SIZE); |
| 306 | |
| 307 | port->hw_streamingparams.numpagetableentries = port->hwcfg.buffercount; |
| 308 | |
| 309 | /* Allocate the PCI resources */ |
| 310 | for (i = 0; i < port->hwcfg.buffercount; i++) { |
| 311 | buf = saa7164_buffer_alloc(port, |
| 312 | port->hw_streamingparams.numberoflines * |
| 313 | port->hw_streamingparams.pitch); |
| 314 | |
| 315 | if (!buf) { |
| 316 | result = -ENOMEM; |
| 317 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 318 | "(errno = %d), unable to allocate buffers\n", |
| 319 | DRIVER_NAME, result); |
| 320 | goto fail_adapter; |
| 321 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 322 | |
| 323 | mutex_lock(&port->dmaqueue_lock); |
| 324 | list_add_tail(&buf->list, &port->dmaqueue.list); |
| 325 | mutex_unlock(&port->dmaqueue_lock); |
| 326 | } |
| 327 | |
| 328 | /* register adapter */ |
| 329 | result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE, |
| 330 | &dev->pci->dev, adapter_nr); |
| 331 | if (result < 0) { |
| 332 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 333 | "(errno = %d)\n", DRIVER_NAME, result); |
| 334 | goto fail_adapter; |
| 335 | } |
| 336 | dvb->adapter.priv = port; |
| 337 | |
| 338 | /* register frontend */ |
| 339 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 340 | if (result < 0) { |
| 341 | printk(KERN_ERR "%s: dvb_register_frontend failed " |
| 342 | "(errno = %d)\n", DRIVER_NAME, result); |
| 343 | goto fail_frontend; |
| 344 | } |
| 345 | |
| 346 | /* register demux stuff */ |
| 347 | dvb->demux.dmx.capabilities = |
| 348 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 349 | DMX_MEMORY_BASED_FILTERING; |
| 350 | dvb->demux.priv = port; |
| 351 | dvb->demux.filternum = 256; |
| 352 | dvb->demux.feednum = 256; |
| 353 | dvb->demux.start_feed = saa7164_dvb_start_feed; |
| 354 | dvb->demux.stop_feed = saa7164_dvb_stop_feed; |
| 355 | result = dvb_dmx_init(&dvb->demux); |
| 356 | if (result < 0) { |
| 357 | printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d)\n", |
| 358 | DRIVER_NAME, result); |
| 359 | goto fail_dmx; |
| 360 | } |
| 361 | |
| 362 | dvb->dmxdev.filternum = 256; |
| 363 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 364 | dvb->dmxdev.capabilities = 0; |
| 365 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 366 | if (result < 0) { |
| 367 | printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 368 | DRIVER_NAME, result); |
| 369 | goto fail_dmxdev; |
| 370 | } |
| 371 | |
| 372 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 373 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 374 | if (result < 0) { |
| 375 | printk(KERN_ERR "%s: add_frontend failed " |
| 376 | "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME, result); |
| 377 | goto fail_fe_hw; |
| 378 | } |
| 379 | |
| 380 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 381 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 382 | if (result < 0) { |
| 383 | printk(KERN_ERR "%s: add_frontend failed " |
| 384 | "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME, result); |
| 385 | goto fail_fe_mem; |
| 386 | } |
| 387 | |
| 388 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 389 | if (result < 0) { |
| 390 | printk(KERN_ERR "%s: connect_frontend failed (errno = %d)\n", |
| 391 | DRIVER_NAME, result); |
| 392 | goto fail_fe_conn; |
| 393 | } |
| 394 | |
| 395 | /* register network adapter */ |
| 396 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 397 | return 0; |
| 398 | |
| 399 | fail_fe_conn: |
| 400 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 401 | fail_fe_mem: |
| 402 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 403 | fail_fe_hw: |
| 404 | dvb_dmxdev_release(&dvb->dmxdev); |
| 405 | fail_dmxdev: |
| 406 | dvb_dmx_release(&dvb->demux); |
| 407 | fail_dmx: |
| 408 | dvb_unregister_frontend(dvb->frontend); |
| 409 | fail_frontend: |
| 410 | dvb_frontend_detach(dvb->frontend); |
| 411 | dvb_unregister_adapter(&dvb->adapter); |
| 412 | fail_adapter: |
| 413 | return result; |
| 414 | } |
| 415 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 416 | int saa7164_dvb_unregister(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 417 | { |
| 418 | struct saa7164_dvb *dvb = &port->dvb; |
| 419 | struct saa7164_dev *dev = port->dev; |
| 420 | struct saa7164_buffer *b; |
| 421 | struct list_head *c, *n; |
| 422 | |
| 423 | dprintk(DBGLVL_DVB, "%s()\n", __func__); |
| 424 | |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 425 | if (port->type != SAA7164_MPEG_DVB) |
| 426 | BUG(); |
| 427 | |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 428 | /* Remove any allocated buffers */ |
| 429 | mutex_lock(&port->dmaqueue_lock); |
| 430 | list_for_each_safe(c, n, &port->dmaqueue.list) { |
| 431 | b = list_entry(c, struct saa7164_buffer, list); |
| 432 | list_del(c); |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 433 | saa7164_buffer_dealloc(b); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 434 | } |
| 435 | mutex_unlock(&port->dmaqueue_lock); |
| 436 | |
| 437 | if (dvb->frontend == NULL) |
| 438 | return 0; |
| 439 | |
| 440 | dvb_net_release(&dvb->net); |
| 441 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 442 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 443 | dvb_dmxdev_release(&dvb->dmxdev); |
| 444 | dvb_dmx_release(&dvb->demux); |
| 445 | dvb_unregister_frontend(dvb->frontend); |
| 446 | dvb_frontend_detach(dvb->frontend); |
| 447 | dvb_unregister_adapter(&dvb->adapter); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | /* All the DVB attach calls go here, this function get's modified |
| 452 | * for each new card. |
| 453 | */ |
Steven Toth | add3f58 | 2010-07-31 14:43:07 -0300 | [diff] [blame^] | 454 | int saa7164_dvb_register(struct saa7164_port *port) |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 455 | { |
| 456 | struct saa7164_dev *dev = port->dev; |
| 457 | struct saa7164_dvb *dvb = &port->dvb; |
| 458 | struct saa7164_i2c *i2c_bus = NULL; |
| 459 | int ret; |
| 460 | |
| 461 | dprintk(DBGLVL_DVB, "%s()\n", __func__); |
| 462 | |
| 463 | /* init frontend */ |
| 464 | switch (dev->board) { |
| 465 | case SAA7164_BOARD_HAUPPAUGE_HVR2200: |
| 466 | case SAA7164_BOARD_HAUPPAUGE_HVR2200_2: |
| 467 | case SAA7164_BOARD_HAUPPAUGE_HVR2200_3: |
Steven Toth | 8bfd4b2 | 2009-08-29 14:33:06 -0300 | [diff] [blame] | 468 | i2c_bus = &dev->i2c_bus[port->nr + 1]; |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 469 | switch (port->nr) { |
| 470 | case 0: |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 471 | port->dvb.frontend = dvb_attach(tda10048_attach, |
| 472 | &hauppauge_hvr2200_1_config, |
| 473 | &i2c_bus->i2c_adap); |
| 474 | |
| 475 | if (port->dvb.frontend != NULL) { |
Steven Toth | 1f8c40b | 2009-08-29 14:22:05 -0300 | [diff] [blame] | 476 | /* TODO: addr is in the card struct */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 477 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 478 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
| 479 | &hauppauge_hvr22x0_tuner_config); |
| 480 | } |
| 481 | |
| 482 | break; |
| 483 | case 1: |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 484 | port->dvb.frontend = dvb_attach(tda10048_attach, |
| 485 | &hauppauge_hvr2200_2_config, |
| 486 | &i2c_bus->i2c_adap); |
| 487 | |
| 488 | if (port->dvb.frontend != NULL) { |
Steven Toth | 1f8c40b | 2009-08-29 14:22:05 -0300 | [diff] [blame] | 489 | /* TODO: addr is in the card struct */ |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 490 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 491 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
Steven Toth | 151ec0d9 | 2009-08-29 14:41:18 -0300 | [diff] [blame] | 492 | &hauppauge_hvr22x0s_tuner_config); |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | break; |
| 496 | } |
| 497 | break; |
| 498 | case SAA7164_BOARD_HAUPPAUGE_HVR2250: |
| 499 | case SAA7164_BOARD_HAUPPAUGE_HVR2250_2: |
Steven Toth | e333522 | 2009-05-11 22:03:07 -0300 | [diff] [blame] | 500 | case SAA7164_BOARD_HAUPPAUGE_HVR2250_3: |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 501 | i2c_bus = &dev->i2c_bus[port->nr + 1]; |
| 502 | |
| 503 | port->dvb.frontend = dvb_attach(s5h1411_attach, |
| 504 | &hauppauge_s5h1411_config, |
| 505 | &i2c_bus->i2c_adap); |
| 506 | |
| 507 | if (port->dvb.frontend != NULL) { |
Steven Toth | 90e801a | 2009-08-27 18:08:21 -0300 | [diff] [blame] | 508 | if (port->nr == 0) { |
| 509 | /* Master TDA18271 */ |
| 510 | /* TODO: addr is in the card struct */ |
| 511 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 512 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
| 513 | &hauppauge_hvr22x0_tuner_config); |
| 514 | } else { |
| 515 | /* Slave TDA18271 */ |
| 516 | dvb_attach(tda18271_attach, port->dvb.frontend, |
| 517 | 0xc0 >> 1, &i2c_bus->i2c_adap, |
| 518 | &hauppauge_hvr22x0s_tuner_config); |
| 519 | } |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | break; |
| 523 | default: |
| 524 | printk(KERN_ERR "%s: The frontend isn't supported\n", |
| 525 | dev->name); |
| 526 | break; |
| 527 | } |
| 528 | if (NULL == dvb->frontend) { |
| 529 | printk(KERN_ERR "%s() Frontend initialization failed\n", |
| 530 | __func__); |
| 531 | return -1; |
| 532 | } |
| 533 | |
| 534 | /* Put the analog decoder in standby to keep it quiet */ |
| 535 | |
| 536 | /* register everything */ |
| 537 | ret = dvb_register(port); |
| 538 | if (ret < 0) { |
| 539 | if (dvb->frontend->ops.release) |
| 540 | dvb->frontend->ops.release(dvb->frontend); |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |