30 #include <linux/module.h>
33 #include <linux/poll.h>
35 #include <asm/div64.h>
36 #include <linux/pci.h>
44 static int one_adapter;
48 static int shutdown_workaround;
50 MODULE_PARM_DESC(shutdown_workaround,
"Activate workaround for shutdown problem with some chipsets.");
58 #define dprintk if (debug) printk
60 #define ngwriteb(dat, adr) writeb((dat), (char *)(dev->iomem + (adr)))
61 #define ngwritel(dat, adr) writel((dat), (char *)(dev->iomem + (adr)))
62 #define ngwriteb(dat, adr) writeb((dat), (char *)(dev->iomem + (adr)))
63 #define ngreadl(adr) readl(dev->iomem + (adr))
64 #define ngreadb(adr) readb(dev->iomem + (adr))
65 #define ngcpyto(adr, src, count) memcpy_toio((char *) \
66 (dev->iomem + (adr)), (src), (count))
67 #define ngcpyfrom(dst, adr, count) memcpy_fromio((dst), (char *) \
68 (dev->iomem + (adr)), (count))
74 static void event_tasklet(
unsigned long data)
92 static void demux_tasklet(
unsigned long data)
141 ": Update AudioDTO = %d\n",
203 if (tmpCmdDoneByte &&
233 spin_lock(&dev->
channel[i].state_lock);
235 if (dev->
channel[i].nextBuffer) {
236 if ((dev->
channel[i].nextBuffer->
237 ngeneBuffer.SR.Flags & 0xC0) == 0x80) {
239 ngeneBuffer.SR.Flags |= 0x40;
241 &dev->
channel[i].demux_tasklet);
245 spin_unlock(&dev->
channel[i].state_lock);
256 static void dump_command_io(
struct ngene *dev)
323 ": Command timeout cmd=%02x prev=%02x\n",
325 dump_command_io(dev);
346 result = ngene_command_mutex(dev, com);
352 static int ngene_command_load_firmware(
struct ngene *dev,
355 #define FIRSTCHUNK (1024)
366 cleft = (size + 3) & ~3;
367 if (cleft > FIRSTCHUNK) {
386 static int ngene_command_config_buf(
struct ngene *dev,
u8 config)
401 static int ngene_command_config_free_buf(
struct ngene *dev,
u8 *config)
454 static u8 TSFeatureDecoderSetup[8 * 5] = {
455 0x42, 0x00, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
456 0x40, 0x06, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
457 0x71, 0x07, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
458 0x72, 0x00, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
459 0x40, 0x07, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
463 static u8 I2SConfiguration[] = {
464 0x00, 0x10, 0x00, 0x00,
465 0x80, 0x10, 0x00, 0x00,
468 static u8 SPDIFConfiguration[10] = {
469 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
474 static u8 TS_I2SConfiguration[4] = { 0x3E, 0x18, 0x00, 0x00 };
476 static u8 TS_I2SOutConfiguration[4] = { 0x80, 0x04, 0x00, 0x00 };
478 static u8 ITUDecoderSetup[4][16] = {
479 {0x1c, 0x13, 0x01, 0x68, 0x3d, 0x90, 0x14, 0x20,
480 0x00, 0x00, 0x01, 0xb0, 0x9c, 0x00, 0x00, 0x00},
481 {0x9c, 0x03, 0x23, 0xC0, 0x60, 0x0E, 0x13, 0x00,
482 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00},
483 {0x9f, 0x00, 0x23, 0xC0, 0x60, 0x0F, 0x13, 0x00,
484 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00},
485 {0x9c, 0x01, 0x23, 0xC0, 0x60, 0x0E, 0x13, 0x00,
486 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00},
496 static u8 ITUFeatureDecoderSetup[8] = {
497 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x04, 0x00
523 val = chan->
nextBuffer->ngeneBuffer.SR.Flags & 0x80;
559 static int ngene_command_stream_control(
struct ngene *dev,
u8 stream,
564 u16 BsUVI = ((stream & 1) ? 0x9400 : 0x9300);
565 u16 BsSDI = ((stream & 1) ? 0x9600 : 0x9500);
566 u16 BsSPI = ((stream & 1) ? 0x9800 : 0x9700);
570 memset(&com, 0,
sizeof(com));
583 ": Stream=%02x, Control=%02x, Mode=%02x\n",
589 if (!(control & 0x80)) {
643 if (mode & SMODE_AUDIO_CAPTURE) {
647 sizeof(SPDIFConfiguration);
650 SPDIFConfiguration,
sizeof(SPDIFConfiguration));
658 }
else if (mode & SMODE_TRANSPORT_STREAM) {
663 sizeof(TS_I2SOutConfiguration);
666 TS_I2SOutConfiguration,
667 sizeof(TS_I2SOutConfiguration));
670 sizeof(TS_I2SConfiguration);
674 sizeof(TS_I2SConfiguration));
680 TSFeatureDecoderSetup +
686 16 +
sizeof(ITUFeatureDecoderSetup);
689 ITUDecoderSetup[chan->
itumode], 16);
691 ITUFeatureDecoderSetup,
sizeof(ITUFeatureDecoderSetup));
695 if (mode & SMODE_TRANSPORT_STREAM)
711 u8 control = 0, mode = 0, flags = 0;
733 dev->
card_info->switch_ctrl(chan, 1, state ^ 1);
759 ret = ngene_command_stream_control(dev, chan->
number,
760 control, mode, flags);
792 Cur->scList1->Address);
798 Cur->scList2->Address);
808 static void free_idlebuffer(
struct ngene *dev,
817 free_ringbuffer(dev, rb);
821 Cur->ngeneBuffer.Address_of_first_entry_2 = 0;
822 Cur->ngeneBuffer.Number_of_entries_2 = 0;
826 static void free_common_buffers(
struct ngene *dev)
861 u64 PARingBufferHead;
863 u64 PARingBufferNext;
875 PARingBufferHead =
tmp;
882 PARingBufferCur = PARingBufferHead;
885 for (i = 0; i < NumBuffers - 1; i++) {
892 PARingBufferCur = PARingBufferNext;
900 descr->
PAHead = PARingBufferHead;
906 static int AllocateRingBuffers(
struct pci_dev *pci_dev,
909 u32 Buffer1Length,
u32 Buffer2Length)
925 if (SCListMemSize < 4096)
926 SCListMemSize = 4096;
931 if (SCListMem ==
NULL)
934 memset(SCListMem, 0, SCListMemSize);
942 SCListEntry = SCListMem;
943 PASCListEntry = PASCListMem;
944 Cur = pRingBuffer->
Head;
946 for (i = 0; i < pRingBuffer->
NumBuffers; i += 1, Cur = Cur->
Next) {
958 SCListEntry->
Address = PABuffer;
959 SCListEntry->
Length = Buffer1Length;
962 Cur->
ngeneBuffer.Address_of_first_entry_1 = PASCListEntry;
969 #if NUM_SCATTER_GATHER_ENTRIES > 1
990 SCListEntry->
Address = PABuffer;
991 SCListEntry->
Length = Buffer2Length;
994 Cur->
ngeneBuffer.Address_of_first_entry_2 = PASCListEntry;
1001 #if NUM_SCATTER_GATHER_ENTRIES > 1
1002 for (j = 0; j < NUM_SCATTER_GATHER_ENTRIES - 1; j++) {
1031 for (i = 0; i <
n; i++) {
1035 pIdleBuffer->
Head->ngeneBuffer.
1038 pIdleBuffer->
Head->ngeneBuffer.Number_of_entries_1;
1057 MAX_AUDIO_BUFFER_SIZE
1069 static int AllocCommonBuffers(
struct ngene *dev)
1094 status = create_ring_buffer(dev->
pci_dev,
1096 RingBufferSizes[i]);
1101 status = AllocateRingBuffers(dev->
pci_dev,
1111 status = AllocateRingBuffers(dev->
pci_dev,
1125 status = create_ring_buffer(dev->
pci_dev,
1131 status = AllocateRingBuffers(dev->
pci_dev,
1141 status = create_ring_buffer(dev->
pci_dev,
1146 status = AllocateRingBuffers(dev->
pci_dev,
1153 FillTSIdleBuffer(&dev->
channel[i].TSIdleBuffer,
1154 &dev->
channel[i].TSRingBuffer);
1160 static void ngene_release_buffers(
struct ngene *dev)
1164 free_common_buffers(dev);
1172 static int ngene_get_buffers(
struct ngene *dev)
1174 if (AllocCommonBuffers(dev))
1176 if (dev->
card_info->io_type[4] & NGENE_IO_TSOUT) {
1196 if (dev->
card_info->io_type[0] & NGENE_IO_HDTV) {
1210 static void ngene_init(
struct ngene *dev)
1235 static int ngene_load_firm(
struct ngene *dev)
1250 fw_name =
"ngene_15.fw";
1255 fw_name =
"ngene_16.fw";
1260 fw_name =
"ngene_17.fw";
1265 fw_name =
"ngene_18.fw";
1271 ": Could not load firmware file %s.\n", fw_name);
1273 ": Copy %s to your hotplug directory!\n", fw_name);
1278 if (size != fw->
size) {
1280 ": Firmware %s has invalid size!", fw_name);
1284 ": Loading firmware file %s.\n", fw_name);
1285 ngene_fw = (
u8 *) fw->
data;
1286 err = ngene_command_load_firmware(dev, ngene_fw, size);
1294 static void ngene_stop(
struct ngene *dev)
1307 #ifdef CONFIG_PCI_MSI
1313 static int ngene_buffer_config(
struct ngene *dev)
1318 u8 tsin12_config[6] = { 0x60, 0x60, 0x00, 0x00, 0x00, 0x00 };
1319 u8 tsin1234_config[6] = { 0x30, 0x30, 0x00, 0x30, 0x30, 0x00 };
1320 u8 tsio1235_config[6] = { 0x30, 0x30, 0x00, 0x28, 0x00, 0x38 };
1321 u8 *bconf = tsin12_config;
1325 bconf = tsin1234_config;
1326 if (dev->
card_info->io_type[4]&NGENE_IO_TSOUT &&
1328 bconf = tsio1235_config;
1330 stat = ngene_command_config_free_buf(dev, bconf);
1336 stat = ngene_command_config_buf(dev, bconf);
1342 static int ngene_start(
struct ngene *dev)
1370 stat = ngene_load_firm(dev);
1374 #ifdef CONFIG_PCI_MSI
1377 unsigned long flags;
1381 stat = pci_enable_msi(dev->
pci_dev);
1384 ": MSI not available\n");
1391 flags,
"nGene", dev);
1411 #ifdef CONFIG_PCI_MSI
1449 dvbdemux->
dmx.close(&dvbdemux->
dmx);
1450 dvbdemux->
dmx.remove_frontend(&dvbdemux->
dmx,
1452 dvbdemux->
dmx.remove_frontend(&dvbdemux->
dmx,
1493 if (!dev->
ci.en && (io & NGENE_IO_TSOUT))
1496 if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
1504 &chan->
dev->pci_dev->dev,
1515 if (dev->
ci.en && (io & NGENE_IO_TSOUT)) {
1535 chan->
fe2->tuner_priv = chan->
fe->tuner_priv;
1537 &chan->
fe->ops.tuner_ops,
1558 release_channel(chan);
1562 static int init_channels(
struct ngene *dev)
1568 if (init_channel(&dev->
channel[i]) < 0) {
1569 for (j = i - 1; j >= 0; j--)
1570 release_channel(&dev->
channel[j]);
1584 static void cxd_attach(
struct ngene *dev)
1593 static void cxd_detach(
struct ngene *dev)
1606 static void ngene_unlink(
struct ngene *dev)
1619 ngene_command_mutex(dev, &com);
1625 struct ngene *dev = (
struct ngene *)pci_get_drvdata(pdev);
1627 if (!dev || !shutdown_workaround)
1641 struct ngene *dev = pci_get_drvdata(pdev);
1645 for (i = MAX_STREAM - 1; i >= 0; i--)
1646 release_channel(&dev->
channel[i]);
1650 ngene_release_buffers(dev);
1651 pci_set_drvdata(pdev,
NULL);
1674 pci_set_drvdata(pci_dev, dev);
1677 stat = ngene_get_buffers(dev);
1680 stat = ngene_start(dev);
1686 stat = ngene_buffer_config(dev);
1694 if (init_channels(dev) < 0)
1702 ngene_release_buffers(dev);
1705 pci_set_drvdata(pci_dev,
NULL);