diff options
author | Andrew de Quincy <devnull@localhost> | 2004-11-12 13:51:21 +0000 |
---|---|---|
committer | Andrew de Quincy <devnull@localhost> | 2004-11-12 13:51:21 +0000 |
commit | 6619ffef1ac825f47ff0ac16eecfa0225bdc7f2a (patch) | |
tree | 56f9ee78bb36ac4e01932812c5d85a7381885d9c /linux | |
parent | fed16c767f240aabd0ab2ab38fb36a783922b6c5 (diff) | |
download | mediapointer-dvb-s2-6619ffef1ac825f47ff0ac16eecfa0225bdc7f2a.tar.gz mediapointer-dvb-s2-6619ffef1ac825f47ff0ac16eecfa0225bdc7f2a.tar.bz2 |
Support for KNC1/Cinergy CI modules. Patch by Olivier Gournet and myself.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/drivers/media/dvb/dvb-core/dvb_ca_en50221.c | 942 | ||||
-rw-r--r-- | linux/drivers/media/dvb/ttpci/budget-av.c | 1374 | ||||
-rw-r--r-- | linux/drivers/media/dvb/ttpci/budget-ci.c | 1510 | ||||
-rw-r--r-- | linux/drivers/media/dvb/ttpci/budget-core.c | 579 | ||||
-rw-r--r-- | linux/drivers/media/dvb/ttpci/budget.h | 62 |
5 files changed, 2487 insertions, 1980 deletions
diff --git a/linux/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/linux/drivers/media/dvb/dvb-core/dvb_ca_en50221.c index b33e22749..2f96cdf0f 100644 --- a/linux/drivers/media/dvb/dvb-core/dvb_ca_en50221.c +++ b/linux/drivers/media/dvb/dvb-core/dvb_ca_en50221.c @@ -42,8 +42,8 @@ static int dvb_ca_en50221_debug; -module_param_named(cam_debug, dvb_ca_en50221_debug, int, 0644); -MODULE_PARM_DESC(cam_debug, "enable verbose debug messages"); +module_param_named (cam_debug, dvb_ca_en50221_debug, int, 0644); +MODULE_PARM_DESC (cam_debug, "enable verbose debug messages"); #define dprintk if (dvb_ca_en50221_debug) printk @@ -61,19 +61,19 @@ MODULE_PARM_DESC(cam_debug, "enable verbose debug messages"); #define CTRLIF_SIZE_LOW 2 #define CTRLIF_SIZE_HIGH 3 -#define CMDREG_HC 1 /* Host control */ -#define CMDREG_SW 2 /* Size write */ -#define CMDREG_SR 4 /* Size read */ -#define CMDREG_RS 8 /* Reset interface */ -#define CMDREG_FRIE 0x40 /* Enable FR interrupt */ -#define CMDREG_DAIE 0x80 /* Enable DA interrupt */ +#define CMDREG_HC 1 /* Host control */ +#define CMDREG_SW 2 /* Size write */ +#define CMDREG_SR 4 /* Size read */ +#define CMDREG_RS 8 /* Reset interface */ +#define CMDREG_FRIE 0x40 /* Enable FR interrupt */ +#define CMDREG_DAIE 0x80 /* Enable DA interrupt */ #define IRQEN (CMDREG_DAIE) -#define STATUSREG_RE 1 /* read error */ -#define STATUSREG_WE 2 /* write error */ -#define STATUSREG_FR 0x40 /* module free */ -#define STATUSREG_DA 0x80 /* data available */ -#define STATUSREG_TXERR (STATUSREG_RE|STATUSREG_WE) /* general transfer error */ +#define STATUSREG_RE 1 /* read error */ +#define STATUSREG_WE 2 /* write error */ +#define STATUSREG_FR 0x40 /* module free */ +#define STATUSREG_DA 0x80 /* data available */ +#define STATUSREG_TXERR (STATUSREG_RE|STATUSREG_WE) /* general transfer error */ #define DVB_CA_SLOTSTATE_NONE 0 @@ -124,7 +124,7 @@ struct dvb_ca_slot { struct dvb_ca_private { /* pointer back to the public data structure */ - struct dvb_ca_en50221* pub; + struct dvb_ca_en50221 *pub; /* the DVB device */ struct dvb_device *dvbdev; @@ -136,7 +136,7 @@ struct dvb_ca_private { unsigned int slot_count; /* information on each slot */ - struct dvb_ca_slot* slot_info; + struct dvb_ca_slot *slot_info; /* wait queues for read() and write() operations */ wait_queue_head_t wait_queue; @@ -163,9 +163,11 @@ struct dvb_ca_private { int next_read_slot; }; -static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private* ca); -static int dvb_ca_en50221_read_data(struct dvb_ca_private* ca, int slot, u8* ebuf, int ecount); -static int dvb_ca_en50221_write_data(struct dvb_ca_private* ca, int slot, u8* ebuf, int ecount); +static void dvb_ca_en50221_thread_wakeup (struct dvb_ca_private *ca); +static int dvb_ca_en50221_read_data (struct dvb_ca_private *ca, int slot, + u8 * ebuf, int ecount); +static int dvb_ca_en50221_write_data (struct dvb_ca_private *ca, int slot, + u8 * ebuf, int ecount); /** @@ -177,14 +179,16 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private* ca, int slot, u8* eb * @param nlen Number of bytes in needle. * @return Pointer into haystack needle was found at, or NULL if not found. */ -static u8* findstr(u8* haystack, int hlen, u8* needle, int nlen) +static u8 *findstr (u8 * haystack, int hlen, u8 * needle, int nlen) { int i; - if (hlen < nlen) return NULL; + if (hlen < nlen) + return NULL; - for(i=0; i<= hlen - nlen; i++) { - if (!strncmp(haystack+i, needle, nlen)) return haystack+i; + for (i = 0; i <= hlen - nlen; i++) { + if (!strncmp (haystack + i, needle, nlen)) + return haystack + i; } return NULL; @@ -199,7 +203,7 @@ static u8* findstr(u8* haystack, int hlen, u8* needle, int nlen) /** * Check CAM status. */ -static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private* ca, int slot) +static int dvb_ca_en50221_check_camstatus (struct dvb_ca_private *ca, int slot) { int slot_status; int cam_present_now; @@ -207,14 +211,14 @@ static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private* ca, int slot) /* IRQ mode */ if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) { - return (atomic_read(&ca->slot_info[slot].camchange_count) != 0); + return (atomic_read (&ca->slot_info[slot].camchange_count) != 0); } /* poll mode */ - slot_status = ca->pub->poll_slot_status(ca->pub, slot); + slot_status = ca->pub->poll_slot_status (ca->pub, slot); - cam_present_now = (slot_status & DVB_CA_EN50221_POLL_CAM_PRESENT) ? 1: 0; - cam_changed = (slot_status & DVB_CA_EN50221_POLL_CAM_CHANGED) ? 1: 0; + cam_present_now = (slot_status & DVB_CA_EN50221_POLL_CAM_PRESENT) ? 1 : 0; + cam_changed = (slot_status & DVB_CA_EN50221_POLL_CAM_CHANGED) ? 1 : 0; if (!cam_changed) { int cam_present_old = (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE); cam_changed = (cam_present_now != cam_present_old); @@ -226,7 +230,7 @@ static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private* ca, int slot) } else { ca->slot_info[slot].camchange_type = DVB_CA_EN50221_CAMCHANGE_INSERTED; } - atomic_set(&ca->slot_info[slot].camchange_count, 1); + atomic_set (&ca->slot_info[slot].camchange_count, 1); } else { if ((ca->slot_info[slot].slot_state == DVB_CA_SLOTSTATE_WAITREADY) && (slot_status & DVB_CA_EN50221_POLL_CAM_READY)) { @@ -250,7 +254,8 @@ static int dvb_ca_en50221_check_camstatus(struct dvb_ca_private* ca, int slot) * * @return 0 on success, nonzero on error. */ -static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private* ca, int slot, u8 waitfor, int timeout_hz) +static int dvb_ca_en50221_wait_if_status (struct dvb_ca_private *ca, int slot, + u8 waitfor, int timeout_hz) { unsigned long timeout; unsigned long start; @@ -260,27 +265,30 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private* ca, int slot, u8 /* loop until timeout elapsed */ start = jiffies; timeout = jiffies + timeout_hz; - while(1) { + while (1) { /* read the status and check for error */ - int res = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS); - if (res < 0) return -EIO; + int res = ca->pub->read_cam_control (ca->pub, slot, + CTRLIF_STATUS); + if (res < 0) + return -EIO; /* if we got the flags, it was successful! */ if (res & waitfor) { - dprintk("%s succeeded timeout:%lu\n", __FUNCTION__, jiffies - start); + dprintk ("%s succeeded timeout:%lu\n", __FUNCTION__, + jiffies - start); return 0; } /* check for timeout */ - if (time_after(jiffies, timeout)) { + if (time_after (jiffies, timeout)) { break; } /* wait for a bit */ - msleep(1); + msleep (1); } - dprintk("%s failed timeout:%lu\n", __FUNCTION__, jiffies - start); + dprintk ("%s failed timeout:%lu\n", __FUNCTION__, jiffies - start); /* if we get here, we've timed out */ return -ETIMEDOUT; @@ -295,7 +303,7 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private* ca, int slot, u8 * * @return 0 on success, nonzero on failure. */ -static int dvb_ca_en50221_link_init(struct dvb_ca_private* ca, int slot) +static int dvb_ca_en50221_link_init (struct dvb_ca_private *ca, int slot) { int ret; int buf_size; @@ -311,24 +319,33 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private* ca, int slot) ca->slot_info[slot].link_buf_size = 2; /* read the buffer size from the CAM */ - if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_SR)) != 0) return ret; - if ((ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_DA, HZ/10)) != 0) return ret; - if ((ret = dvb_ca_en50221_read_data(ca, slot, buf, 2)) != 2) return -EIO; - if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN)) != 0) return ret; + if ((ret = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_SR)) != 0) + return ret; + if ((ret = dvb_ca_en50221_wait_if_status (ca, slot, STATUSREG_DA, HZ / 10)) != 0) + return ret; + if ((ret = dvb_ca_en50221_read_data (ca, slot, buf, 2)) != 2) + return -EIO; + if ((ret = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, IRQEN)) != 0) + return ret; /* store it, and choose the minimum of our buffer and the CAM's buffer size */ buf_size = (buf[0] << 8) | buf[1]; - if (buf_size > HOST_LINK_BUF_SIZE) buf_size = HOST_LINK_BUF_SIZE; + if (buf_size > HOST_LINK_BUF_SIZE) + buf_size = HOST_LINK_BUF_SIZE; ca->slot_info[slot].link_buf_size = buf_size; buf[0] = buf_size >> 8; buf[1] = buf_size & 0xff; - dprintk("Chosen link buffer size of %i\n", buf_size); + dprintk ("Chosen link buffer size of %i\n", buf_size); /* write the buffer size to the CAM */ - if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_SW)) != 0) return ret; - if ((ret = dvb_ca_en50221_wait_if_status(ca, slot, STATUSREG_FR, HZ/10)) != 0) return ret; - if ((ret = dvb_ca_en50221_write_data(ca, slot, buf, 2)) != 2) return -EIO; - if ((ret = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN)) != 0) return ret; + if ((ret = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_SW)) != 0) + return ret; + if ((ret = dvb_ca_en50221_wait_if_status (ca, slot, STATUSREG_FR, HZ / 10)) != 0) + return ret; + if ((ret = dvb_ca_en50221_write_data (ca, slot, buf, 2)) != 2) + return -EIO; + if ((ret = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, IRQEN)) != 0) + return ret; /* success */ return 0; @@ -346,8 +363,9 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private* ca, int slot) * * @return 0 on success, nonzero on error. */ -static int dvb_ca_en50221_read_tuple(struct dvb_ca_private* ca, int slot, - int* address, int* tupleType, int* tupleLength, u8* tuple) +static int dvb_ca_en50221_read_tuple (struct dvb_ca_private *ca, int slot, + int *address, int *tupleType, + int *tupleLength, u8 * tuple) { int i; int _tupleType; @@ -355,25 +373,30 @@ static int dvb_ca_en50221_read_tuple(struct dvb_ca_private* ca, int slot, int _address = *address; /* grab the next tuple length and type */ - if ((_tupleType = ca->pub->read_attribute_mem(ca->pub, slot, _address)) < 0) return _tupleType; + if ((_tupleType = ca->pub->read_attribute_mem (ca->pub, slot, _address)) < 0) + return _tupleType; if (_tupleType == 0xff) { - dprintk("END OF CHAIN TUPLE type:0x%x\n", _tupleType); + dprintk ("END OF CHAIN TUPLE type:0x%x\n", _tupleType); *address += 2; *tupleType = _tupleType; *tupleLength = 0; return 0; } - if ((_tupleLength = ca->pub->read_attribute_mem(ca->pub, slot, _address+2)) < 0) return _tupleLength; + if ((_tupleLength = ca->pub->read_attribute_mem (ca->pub, slot, _address + 2)) < 0) + return _tupleLength; _address += 4; - dprintk("TUPLE type:0x%x length:%i\n", _tupleType, _tupleLength); + dprintk ("TUPLE type:0x%x length:%i\n", _tupleType, _tupleLength); /* read in the whole tuple */ - for(i=0; i< _tupleLength; i++) { - tuple[i] = ca->pub->read_attribute_mem(ca->pub, slot, _address + (i*2)); - dprintk(" 0x%02x: 0x%02x %c\n", i, tuple[i] & 0xff, ((tuple[i] > 31) && (tuple[i] < 127)) ? tuple[i] : '.'); + for (i = 0; i < _tupleLength; i++) { + tuple[i] = ca->pub->read_attribute_mem (ca->pub, slot, + _address + (i * 2)); + dprintk (" 0x%02x: 0x%02x %c\n", i, tuple[i] & 0xff, + ((tuple[i] > 31) + && (tuple[i] < 127)) ? tuple[i] : '.'); } - _address += (_tupleLength*2); + _address += (_tupleLength * 2); // success *tupleType = _tupleType; @@ -392,13 +415,13 @@ static int dvb_ca_en50221_read_tuple(struct dvb_ca_private* ca, int slot, * * @return 0 on success, <0 on failure. */ -static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private* ca, int slot) +static int dvb_ca_en50221_parse_attributes (struct dvb_ca_private *ca, int slot) { int address = 0; int tupleLength; int tupleType; u8 tuple[257]; - char* dvb_str; + char *dvb_str; int rasz; int status; int got_cftableentry = 0; @@ -409,96 +432,116 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private* ca, int slot) // CISTPL_DEVICE_0A - if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status; - if (tupleType != 0x1D) return -EINVAL; + if ((status = dvb_ca_en50221_read_tuple (ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) + return status; + if (tupleType != 0x1D) + return -EINVAL; // CISTPL_DEVICE_0C - if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status; - if (tupleType != 0x1C) return -EINVAL; + if ((status = dvb_ca_en50221_read_tuple (ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) + return status; + if (tupleType != 0x1C) + return -EINVAL; // CISTPL_VERS_1 - if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status; - if (tupleType != 0x15) return -EINVAL; + if ((status = dvb_ca_en50221_read_tuple (ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) + return status; + if (tupleType != 0x15) + return -EINVAL; // CISTPL_MANFID - if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status; - if (tupleType != 0x20) return -EINVAL; - if (tupleLength != 4) return -EINVAL; + if ((status = dvb_ca_en50221_read_tuple (ca, slot, &address, &tupleType, + &tupleLength, tuple)) < 0) + return status; + if (tupleType != 0x20) + return -EINVAL; + if (tupleLength != 4) + return -EINVAL; manfid = (tuple[1] << 8) | tuple[0]; devid = (tuple[3] << 8) | tuple[2]; // CISTPL_CONFIG - if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status; - if (tupleType != 0x1A) return -EINVAL; - if (tupleLength < 3) return -EINVAL; + if ((status = dvb_ca_en50221_read_tuple (ca, slot, &address, &tupleType, + &tupleLength, tuple)) < 0) + return status; + if (tupleType != 0x1A) + return -EINVAL; + if (tupleLength < 3) + return -EINVAL; /* extract the configbase */ rasz = tuple[0] & 3; - if (tupleLength < (3 + rasz + 14)) return -EINVAL; + if (tupleLength < (3 + rasz + 14)) + return -EINVAL; ca->slot_info[slot].config_base = 0; - for(i=0; i< rasz+1; i++) { - ca->slot_info[slot].config_base |= (tuple[2+i] << (8*i)); + for (i = 0; i < rasz + 1; i++) { + ca->slot_info[slot].config_base |= (tuple[2 + i] << (8 * i)); } /* check it contains the correct DVB string */ - dvb_str = findstr(tuple, tupleLength, "DVB_CI_V", 8); - if (dvb_str == NULL) return -EINVAL; - if (tupleLength < ((dvb_str - (char*) tuple) + 12)) return -EINVAL; + dvb_str = findstr (tuple, tupleLength, "DVB_CI_V", 8); + if (dvb_str == NULL) + return -EINVAL; + if (tupleLength < ((dvb_str - (char *) tuple) + 12)) + return -EINVAL; /* is it a version we support? */ - if (strncmp(dvb_str + 8, "1.00", 4)) { - printk("dvb_ca adapter %d: Unsupported DVB CAM module version %c%c%c%c\n", - ca->dvbdev->adapter->num, dvb_str[8], dvb_str[9], dvb_str[10], dvb_str[11]); + if (strncmp (dvb_str + 8, "1.00", 4)) { + printk ("dvb_ca adapter %d: Unsupported DVB CAM module version %c%c%c%c\n", ca->dvbdev->adapter->num, dvb_str[8], dvb_str[9], dvb_str[10], dvb_str[11]); return -EINVAL; } /* process the CFTABLE_ENTRY tuples, and any after those */ - while((!end_chain) && (address < 0x1000)) { - if ((status = dvb_ca_en50221_read_tuple(ca, slot, &address, &tupleType, &tupleLength, tuple)) < 0) return status; - switch(tupleType) { - case 0x1B: // CISTPL_CFTABLE_ENTRY - if (tupleLength < (2+11+17)) break; + while ((!end_chain) && (address < 0x1000)) { + if ((status = dvb_ca_en50221_read_tuple (ca, slot, &address, &tupleType, + &tupleLength, tuple)) < 0) + return status; + switch (tupleType) { + case 0x1B: // CISTPL_CFTABLE_ENTRY + if (tupleLength < (2 + 11 + 17)) + break; /* if we've already parsed one, just use it */ - if (got_cftableentry) break; + if (got_cftableentry) + break; /* get the config option */ ca->slot_info[slot].config_option = tuple[0] & 0x3f; /* OK, check it contains the correct strings */ - if ((findstr(tuple, tupleLength, "DVB_HOST", 8) == NULL) || - (findstr(tuple, tupleLength, "DVB_CI_MODULE", 13) == NULL)) break; + if ((findstr (tuple, tupleLength, "DVB_HOST", 8) == NULL) || + (findstr (tuple, tupleLength, "DVB_CI_MODULE", 13) == NULL)) + break; got_cftableentry = 1; break; - case 0x14: // CISTPL_NO_LINK + case 0x14: // CISTPL_NO_LINK break; - case 0xFF: // CISTPL_END + case 0xFF: // CISTPL_END end_chain = 1; break; - default: /* Unknown tuple type - just skip this tuple and move to the next one */ - dprintk("dvb_ca: Skipping unknown tuple type:0x%x length:0x%x\n", tupleType, tupleLength); + default: /* Unknown tuple type - just skip this tuple and move to the next one */ + dprintk ("dvb_ca: Skipping unknown tuple type:0x%x length:0x%x\n", tupleType, tupleLength); break; } } - if ((address > 0x1000) || (!got_cftableentry)) return -EINVAL; + if ((address > 0x1000) || (!got_cftableentry)) + return -EINVAL; - dprintk("Valid DVB CAM detected MANID:%x DEVID:%x CONFIGBASE:0x%x CONFIGOPTION:0x%x\n", - manfid, devid, - ca->slot_info[slot].config_base, - ca->slot_info[slot].config_option); + dprintk ("Valid DVB CAM detected MANID:%x DEVID:%x CONFIGBASE:0x%x CONFIGOPTION:0x%x\n", + manfid, devid, ca->slot_info[slot].config_base, ca->slot_info[slot].config_option); // success! return 0; @@ -511,19 +554,22 @@ static int dvb_ca_en50221_parse_attributes(struct dvb_ca_private* ca, int slot) * @param ca CA instance. * @param slot Slot containing the CAM. */ -static int dvb_ca_en50221_set_configoption(struct dvb_ca_private* ca, int slot) +static int dvb_ca_en50221_set_configoption (struct dvb_ca_private *ca, int slot) { int configoption; dprintk ("%s\n", __FUNCTION__); /* set the config option */ - ca->pub->write_attribute_mem(ca->pub, slot, ca->slot_info[slot].config_base, ca->slot_info[slot].config_option); + ca->pub->write_attribute_mem (ca->pub, slot, + ca->slot_info[slot].config_base, + ca->slot_info[slot].config_option); /* check it */ - configoption = ca->pub->read_attribute_mem(ca->pub, slot, ca->slot_info[slot].config_base); - dprintk("Set configoption 0x%x, read configoption 0x%x\n", - ca->slot_info[slot].config_option, configoption & 0x3f); + configoption = ca->pub->read_attribute_mem (ca->pub, slot, + ca->slot_info[slot].config_base); + dprintk ("Set configoption 0x%x, read configoption 0x%x\n", + ca->slot_info[slot].config_option, configoption & 0x3f); /* fine! */ return 0; @@ -544,7 +590,8 @@ static int dvb_ca_en50221_set_configoption(struct dvb_ca_private* ca, int slot) * * @return Number of bytes read, or < 0 on error */ -static int dvb_ca_en50221_read_data(struct dvb_ca_private* ca, int slot, u8* ebuf, int ecount) +static int dvb_ca_en50221_read_data (struct dvb_ca_private *ca, int slot, + u8 * ebuf, int ecount) { int bytes_read; int status; @@ -555,89 +602,98 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private* ca, int slot, u8* ebu /* check if we have space for a link buf in the rx_buffer */ if (ebuf == NULL) { - int buf_free; - - down_read(&ca->slot_info[slot].sem); - buf_free = dvb_ringbuffer_free(&ca->slot_info[slot].rx_buffer); - up_read(&ca->slot_info[slot].sem); - + int buf_free; + + down_read (&ca->slot_info[slot].sem); + buf_free = dvb_ringbuffer_free (&ca->slot_info[slot].rx_buffer); + up_read (&ca->slot_info[slot].sem); + if (buf_free < (ca->slot_info[slot].link_buf_size + DVB_RINGBUFFER_PKTHDRSIZE)) { - status = -EAGAIN; - goto exit; + status = -EAGAIN; + goto exit; } } /* check if there is data available */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_STATUS)) < 0) + goto exit; if (!(status & STATUSREG_DA)) { - /* no data */ - status = 0; - goto exit; - } + /* no data */ + status = 0; + goto exit; + } /* read the amount of data */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_SIZE_HIGH)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_SIZE_HIGH)) < 0) + goto exit; bytes_read = status << 8; - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_SIZE_LOW)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_SIZE_LOW)) < 0) + goto exit; bytes_read |= status; /* check it will fit */ if (ebuf == NULL) { if (bytes_read > ca->slot_info[slot].link_buf_size) { - printk("dvb_ca adapter %d: CAM tried to send a buffer larger than the link buffer size!\n", ca->dvbdev->adapter->num); - ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; + printk ("dvb_ca adapter %d: CAM tried to send a buffer larger than the link buffer size!\n", ca->dvbdev->adapter->num); + ca->slot_info[slot].slot_state = + DVB_CA_SLOTSTATE_LINKINIT; status = -EIO; - goto exit; + goto exit; } if (bytes_read < 2) { - printk("dvb_ca adapter %d: CAM sent a buffer that was less than 2 bytes!\n", ca->dvbdev->adapter->num); - ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; + printk ("dvb_ca adapter %d: CAM sent a buffer that was less than 2 bytes!\n", ca->dvbdev->adapter->num); + ca->slot_info[slot].slot_state = + DVB_CA_SLOTSTATE_LINKINIT; status = -EIO; - goto exit; + goto exit; } } else { if (bytes_read > ecount) { - printk("dvb_ca adapter %d: CAM tried to send a buffer larger than the ecount size!\n", ca->dvbdev->adapter->num); + printk ("dvb_ca adapter %d: CAM tried to send a buffer larger than the ecount size!\n", ca->dvbdev->adapter->num); status = -EIO; - goto exit; + goto exit; } } /* fill the buffer */ - for(i=0; i < bytes_read; i++) { + for (i = 0; i < bytes_read; i++) { /* read byte and check */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_DATA)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, + CTRLIF_DATA)) < 0) + goto exit; /* OK, store it in the buffer */ buf[i] = status; } /* check for read error (RE should now be 0) */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_STATUS)) < 0) + goto exit; if (status & STATUSREG_RE) { - ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; - status = -EIO; - goto exit; - } + ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; + status = -EIO; + goto exit; + } - /* OK, add it to the receive buffer, or copy into external buffer if supplied */ + /* OK, add it to the receive buffer, or copy into external buffer if supplied */ if (ebuf == NULL) { - down_read(&ca->slot_info[slot].sem); - dvb_ringbuffer_pkt_write(&ca->slot_info[slot].rx_buffer, buf, bytes_read); - up_read(&ca->slot_info[slot].sem); + down_read (&ca->slot_info[slot].sem); + dvb_ringbuffer_pkt_write (&ca->slot_info[slot].rx_buffer, buf, + bytes_read); + up_read (&ca->slot_info[slot].sem); } else { - memcpy(ebuf, buf, bytes_read); + memcpy (ebuf, buf, bytes_read); } - - dprintk("Received CA packet for slot %i connection id 0x%x last_frag:%i size:0x%x\n", slot, buf[0], (buf[1] & 0x80) == 0, bytes_read); + + dprintk ("Received CA packet for slot %i connection id 0x%x last_frag:%i size:0x%x\n", slot, buf[0], (buf[1] & 0x80) == 0, bytes_read); /* wake up readers when a last_fragment is received */ if ((buf[1] & 0x80) == 0x00) { - wake_up_interruptible(&ca->wait_queue); + wake_up_interruptible (&ca->wait_queue); } - status = bytes_read; + status = bytes_read; -exit: + exit: return status; } @@ -654,7 +710,8 @@ exit: * * @return Number of bytes written, or < 0 on error. */ -static int dvb_ca_en50221_write_data(struct dvb_ca_private* ca, int slot, u8* buf, int bytes_write) +static int dvb_ca_en50221_write_data (struct dvb_ca_private *ca, int slot, + u8 * buf, int bytes_write) { int status; int i; @@ -663,50 +720,62 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private* ca, int slot, u8* bu // sanity check - if (bytes_write > ca->slot_info[slot].link_buf_size) return -EINVAL; + if (bytes_write > ca->slot_info[slot].link_buf_size) + return -EINVAL; /* check if interface is actually waiting for us to read from it, or if a read is in progress */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exitnowrite; - if (status & (STATUSREG_DA|STATUSREG_RE)) { - status = -EAGAIN; - goto exitnowrite; - } + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_STATUS)) < 0) + goto exitnowrite; + if (status & (STATUSREG_DA | STATUSREG_RE)) { + status = -EAGAIN; + goto exitnowrite; + } /* OK, set HC bit */ - if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN | CMDREG_HC)) != 0) goto exit; + if ((status = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, + IRQEN | CMDREG_HC)) != 0) + goto exit; /* check if interface is still free */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_STATUS)) < 0) + goto exit; if (!(status & STATUSREG_FR)) { - /* it wasn't free => try again later */ - status = -EAGAIN; - goto exit; - } + /* it wasn't free => try again later */ + status = -EAGAIN; + goto exit; + } /* send the amount of data */ - if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_SIZE_HIGH, bytes_write >> 8)) != 0) goto exit; - if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_SIZE_LOW, bytes_write & 0xff)) != 0) goto exit; + if ((status = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_SIZE_HIGH, + bytes_write >> 8)) != 0) + goto exit; + if ((status = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_SIZE_LOW, + bytes_write & 0xff)) != 0) + goto exit; /* send the buffer */ - for(i=0; i < bytes_write; i++) { - if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_DATA, buf[i])) != 0) goto exit; + for (i = 0; i < bytes_write; i++) { + if ((status = ca->pub->write_cam_control (ca->pub, slot, CTRLIF_DATA, + buf[i])) != 0) + goto exit; } /* check for write error (WE should now be 0) */ - if ((status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS)) < 0) goto exit; + if ((status = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_STATUS)) < 0) + goto exit; if (status & STATUSREG_WE) { - ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; - status = -EIO; - goto exit; - } + ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; + status = -EIO; + goto exit; + } status = bytes_write; - dprintk("Wrote CA packet for slot %i, connection id 0x%x last_frag:%i size:0x%x\n", slot, buf[0], (buf[1] & 0x80) == 0, bytes_write); - -exit: - ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, IRQEN); + dprintk ("Wrote CA packet for slot %i, connection id 0x%x last_frag:%i size:0x%x\n", slot, buf[0], (buf[1] & 0x80) == 0, bytes_write); -exitnowrite: + exit: + ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, IRQEN); + + exitnowrite: return status; } @@ -722,22 +791,23 @@ exitnowrite: * @param ca CA instance. * @param slot Slot to shut down. */ -static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private* ca, int slot) +static int dvb_ca_en50221_slot_shutdown (struct dvb_ca_private *ca, int slot) { dprintk ("%s\n", __FUNCTION__); - down_write(&ca->slot_info[slot].sem); - ca->pub->slot_shutdown(ca->pub, slot); + down_write (&ca->slot_info[slot].sem); + ca->pub->slot_shutdown (ca->pub, slot); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_NONE; - if (ca->slot_info[slot].rx_buffer.data) vfree(ca->slot_info[slot].rx_buffer.data); + if (ca->slot_info[slot].rx_buffer.data) + vfree (ca->slot_info[slot].rx_buffer.data); ca->slot_info[slot].rx_buffer.data = NULL; - up_write(&ca->slot_info[slot].sem); + up_write (&ca->slot_info[slot].sem); /* need to wake up all processes to check if they're now trying to write to a defunct CAM */ - wake_up_interruptible(&ca->wait_queue); + wake_up_interruptible (&ca->wait_queue); - dprintk("Slot %i shutdown\n", slot); + dprintk ("Slot %i shutdown\n", slot); /* success */ return 0; @@ -751,13 +821,14 @@ static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private* ca, int slot) * @param slot Slot concerned. * @param change_type One of the DVB_CA_CAMCHANGE_* values. */ -void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221* pubca, int slot, int change_type) +void dvb_ca_en50221_camchange_irq (struct dvb_ca_en50221 *pubca, int slot, + int change_type) { - struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private; + struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; - dprintk("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type); + dprintk ("CAMCHANGE IRQ slot:%i change_type:%i\n", slot, change_type); - switch(change_type) { + switch (change_type) { case DVB_CA_EN50221_CAMCHANGE_REMOVED: case DVB_CA_EN50221_CAMCHANGE_INSERTED: break; @@ -767,8 +838,8 @@ void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221* pubca, int slot, int ch } ca->slot_info[slot].camchange_type = change_type; - atomic_inc(&ca->slot_info[slot].camchange_count); - dvb_ca_en50221_thread_wakeup(ca); + atomic_inc (&ca->slot_info[slot].camchange_count); + dvb_ca_en50221_thread_wakeup (ca); } @@ -778,15 +849,15 @@ void dvb_ca_en50221_camchange_irq(struct dvb_ca_en50221* pubca, int slot, int ch * @param ca CA instance. * @param slot Slot concerned. */ -void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221* pubca, int slot) +void dvb_ca_en50221_camready_irq (struct dvb_ca_en50221 *pubca, int slot) { - struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private; + struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; - dprintk("CAMREADY IRQ slot:%i\n", slot); + dprintk ("CAMREADY IRQ slot:%i\n", slot); if (ca->slot_info[slot].slot_state == DVB_CA_SLOTSTATE_WAITREADY) { ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_VALIDATE; - dvb_ca_en50221_thread_wakeup(ca); + dvb_ca_en50221_thread_wakeup (ca); } } @@ -797,24 +868,25 @@ void dvb_ca_en50221_camready_irq(struct dvb_ca_en50221* pubca, int slot) * @param ca CA instance. * @param slot Slot concerned. */ -void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221* pubca, int slot) +void dvb_ca_en50221_frda_irq (struct dvb_ca_en50221 *pubca, int slot) { - struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private; + struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; int flags; - dprintk("FR/DA IRQ slot:%i\n", slot); + dprintk ("FR/DA IRQ slot:%i\n", slot); - switch(ca->slot_info[slot].slot_state) { + switch (ca->slot_info[slot].slot_state) { case DVB_CA_SLOTSTATE_LINKINIT: - flags = ca->pub->read_cam_control(pubca, slot, CTRLIF_STATUS); + flags = ca->pub->read_cam_control (pubca, slot, CTRLIF_STATUS); if (flags & STATUSREG_DA) { - dprintk("CAM supports DA IRQ\n"); + dprintk ("CAM supports DA IRQ\n"); ca->slot_info[slot].da_irq_supported = 1; - } + } break; case DVB_CA_SLOTSTATE_RUNNING: - if (ca->open) dvb_ca_en50221_read_data(ca, slot, NULL, 0); + if (ca->open) + dvb_ca_en50221_read_data (ca, slot, NULL, 0); break; } } @@ -829,14 +901,14 @@ void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221* pubca, int slot) * * @param ca CA instance. */ -static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private* ca) +static void dvb_ca_en50221_thread_wakeup (struct dvb_ca_private *ca) { dprintk ("%s\n", __FUNCTION__); ca->wakeup = 1; - mb(); - wake_up_interruptible(&ca->thread_queue); + mb (); + wake_up_interruptible (&ca->thread_queue); } /** @@ -844,14 +916,15 @@ static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private* ca) * * @param ca CA instance. */ -static int dvb_ca_en50221_thread_should_wakeup(struct dvb_ca_private* ca) +static int dvb_ca_en50221_thread_should_wakeup (struct dvb_ca_private *ca) { if (ca->wakeup) { ca->wakeup = 0; return 1; } - if (ca->exit) return 1; - + if (ca->exit) + return 1; + return 0; } @@ -861,20 +934,20 @@ static int dvb_ca_en50221_thread_should_wakeup(struct dvb_ca_private* ca) * * @param ca CA instance. */ -static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private* ca) +static void dvb_ca_en50221_thread_update_delay (struct dvb_ca_private *ca) { int delay; int curdelay = 100000000; int slot; - for(slot=0; slot < ca->slot_count; slot++) { - switch(ca->slot_info[slot].slot_state) { + for (slot = 0; slot < ca->slot_count; slot++) { + switch (ca->slot_info[slot].slot_state) { default: case DVB_CA_SLOTSTATE_NONE: case DVB_CA_SLOTSTATE_INVALID: - delay = HZ*60; + delay = HZ * 60; if (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) { - delay = HZ/10; + delay = HZ / 10; } break; @@ -883,24 +956,25 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private* ca) case DVB_CA_SLOTSTATE_VALIDATE: case DVB_CA_SLOTSTATE_WAITFR: case DVB_CA_SLOTSTATE_LINKINIT: - delay = HZ/10; + delay = HZ / 10; break; case DVB_CA_SLOTSTATE_RUNNING: - delay = HZ*60; + delay = HZ * 60; if (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE)) { - delay = HZ/10; + delay = HZ / 10; } if (ca->open) { if ((!ca->slot_info[slot].da_irq_supported) || (!(ca->flags & DVB_CA_EN50221_FLAG_IRQ_DA))) { - delay = HZ/100; + delay = HZ / 100; } } break; } - if (delay < curdelay) curdelay = delay; + if (delay < curdelay) + curdelay = delay; } ca->delay = curdelay; @@ -911,19 +985,20 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private* ca) /** * Kernel thread which monitors CA slots for CAM changes, and performs data transfers. */ -static int dvb_ca_en50221_thread(void* data) +static int dvb_ca_en50221_thread (void *data) { - struct dvb_ca_private *ca = (struct dvb_ca_private*) data; + struct dvb_ca_private *ca = (struct dvb_ca_private *) data; char name[15]; int slot; int flags; int pktcount; - void* rxbuf; + void *rxbuf; dprintk ("%s\n", __FUNCTION__); /* setup kernel thread */ - snprintf(name, sizeof(name), "kdvb-ca-%i:%i", ca->dvbdev->adapter->num, ca->dvbdev->id); + snprintf (name, sizeof (name), "kdvb-ca-%i:%i", + ca->dvbdev->adapter->num, ca->dvbdev->id); lock_kernel (); daemonize (name); @@ -931,13 +1006,15 @@ static int dvb_ca_en50221_thread(void* data) unlock_kernel (); /* choose the correct initial delay */ - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); /* main loop */ - while(!ca->exit) { + while (!ca->exit) { /* sleep for a bit */ if (!ca->wakeup) { - flags = wait_event_interruptible_timeout(ca->thread_queue, dvb_ca_en50221_thread_should_wakeup(ca), ca->delay); + flags = wait_event_interruptible_timeout (ca->thread_queue, + dvb_ca_en50221_thread_should_wakeup(ca), + ca->delay); if ((flags == -ERESTARTSYS) || ca->exit) { /* got signal or quitting */ break; @@ -946,12 +1023,13 @@ static int dvb_ca_en50221_thread(void* data) ca->wakeup = 0; /* go through all the slots processing them */ - for(slot=0; slot < ca->slot_count; slot++) { + for (slot = 0; slot < ca->slot_count; slot++) { // check the cam status + deal with CAMCHANGEs - while(dvb_ca_en50221_check_camstatus(ca, slot)) { + while (dvb_ca_en50221_check_camstatus (ca, slot)) { /* clear down an old CI slot if necessary */ - if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE) dvb_ca_en50221_slot_shutdown(ca, slot); + if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE) + dvb_ca_en50221_slot_shutdown (ca, slot); /* if a CAM is NOW present, initialise it */ if (ca->slot_info[slot].camchange_type == DVB_CA_EN50221_CAMCHANGE_INSERTED) { @@ -959,12 +1037,12 @@ static int dvb_ca_en50221_thread(void* data) } /* we've handled one CAMCHANGE */ - dvb_ca_en50221_thread_update_delay(ca); - atomic_dec(&ca->slot_info[slot].camchange_count); + dvb_ca_en50221_thread_update_delay (ca); + atomic_dec (&ca->slot_info[slot].camchange_count); } // CAM state machine - switch(ca->slot_info[slot].slot_state) { + switch (ca->slot_info[slot].slot_state) { case DVB_CA_SLOTSTATE_NONE: case DVB_CA_SLOTSTATE_INVALID: // no action needed @@ -972,40 +1050,41 @@ static int dvb_ca_en50221_thread(void* data) case DVB_CA_SLOTSTATE_UNINITIALISED: ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_WAITREADY; - ca->pub->slot_reset(ca->pub, slot); + ca->pub->slot_reset (ca->pub, slot); ca->slot_info[slot].timeout = jiffies + (INIT_TIMEOUT_SECS * HZ); break; case DVB_CA_SLOTSTATE_WAITREADY: if (time_after(jiffies, ca->slot_info[slot].timeout)) { - printk("dvb_ca adaptor %d: PC card did not respond :(\n", ca->dvbdev->adapter->num); + printk ("dvb_ca adaptor %d: PC card did not respond :(\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } // no other action needed; will automatically change state when ready break; case DVB_CA_SLOTSTATE_VALIDATE: - if (dvb_ca_en50221_parse_attributes(ca, slot) != 0) { - printk("dvb_ca adapter %d: Invalid PC card inserted :(\n", ca->dvbdev->adapter->num); + if (dvb_ca_en50221_parse_attributes (ca, slot) + != 0) { + printk ("dvb_ca adapter %d: Invalid PC card inserted :(\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } - if (dvb_ca_en50221_set_configoption(ca, slot) != 0) { - printk("dvb_ca adapter %d: Unable to initialise CAM :(\n", ca->dvbdev->adapter->num); + if (dvb_ca_en50221_set_configoption (ca, slot) != 0) { + printk ("dvb_ca adapter %d: Unable to initialise CAM :(\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } - if (ca->pub->write_cam_control(ca->pub, slot, CTRLIF_COMMAND, CMDREG_RS) != 0) { - printk("dvb_ca adapter %d: Unable to reset CAM IF\n", ca->dvbdev->adapter->num); + if (ca->pub->write_cam_control (ca->pub, slot, CTRLIF_COMMAND, CMDREG_RS) != 0) { + printk ("dvb_ca adapter %d: Unable to reset CAM IF\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } - dprintk("DVB CAM validated successfully\n"); + dprintk ("DVB CAM validated successfully\n"); ca->slot_info[slot].timeout = jiffies + (INIT_TIMEOUT_SECS * HZ); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_WAITFR; @@ -1014,13 +1093,13 @@ static int dvb_ca_en50221_thread(void* data) case DVB_CA_SLOTSTATE_WAITFR: if (time_after(jiffies, ca->slot_info[slot].timeout)) { - printk("dvb_ca adapter %d: DVB CAM did not respond :(\n", ca->dvbdev->adapter->num); + printk ("dvb_ca adapter %d: DVB CAM did not respond :(\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } - flags = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS); + flags = ca->pub->read_cam_control (ca->pub, slot, CTRLIF_STATUS); if (flags & STATUSREG_FR) { ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_LINKINIT; ca->wakeup = 1; @@ -1028,38 +1107,41 @@ static int dvb_ca_en50221_thread(void* data) break; case DVB_CA_SLOTSTATE_LINKINIT: - if (dvb_ca_en50221_link_init(ca, slot) != 0) { - printk("dvb_ca adapter %d: DVB CAM link initialisation failed :(\n", ca->dvbdev->adapter->num); + if (dvb_ca_en50221_link_init (ca, slot) != 0) { + printk ("dvb_ca adapter %d: DVB CAM link initialisation failed :(\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } - rxbuf = vmalloc(RX_BUFFER_SIZE); + rxbuf = vmalloc (RX_BUFFER_SIZE); if (rxbuf == NULL) { - printk("dvb_ca adapter %d: Unable to allocate CAM rx buffer :(\n", ca->dvbdev->adapter->num); + printk ("dvb_ca adapter %d: Unable to allocate CAM rx buffer :(\n", ca->dvbdev->adapter->num); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_INVALID; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); break; } - dvb_ringbuffer_init(&ca->slot_info[slot].rx_buffer, rxbuf, RX_BUFFER_SIZE); + dvb_ringbuffer_init (&ca->slot_info[slot].rx_buffer, rxbuf, RX_BUFFER_SIZE); - ca->pub->slot_ts_enable(ca->pub, slot); + ca->pub->slot_ts_enable (ca->pub, slot); ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_RUNNING; - dvb_ca_en50221_thread_update_delay(ca); - printk("dvb_ca adapter %d: DVB CAM detected and initialised successfully\n", ca->dvbdev->adapter->num); + dvb_ca_en50221_thread_update_delay (ca); + printk ("dvb_ca adapter %d: DVB CAM detected and initialised successfully\n", ca->dvbdev->adapter->num); break; case DVB_CA_SLOTSTATE_RUNNING: - if (!ca->open) break; - - // no need to poll if the CAM supports IRQs - if (ca->slot_info[slot].da_irq_supported) break; + if (!ca->open) + break; - // poll mode + // no need to poll if the CAM supports IRQs + if (ca->slot_info[slot].da_irq_supported) + break; + + // poll mode pktcount = 0; - while(dvb_ca_en50221_read_data(ca, slot, NULL, 0) > 0) { - if (!ca->open) break; + while (dvb_ca_en50221_read_data(ca, slot, NULL, 0) > 0) { + if (!ca->open) + break; /* if a CAMCHANGE occurred at some point, do not do any more processing of this slot */ if (dvb_ca_en50221_check_camstatus(ca, slot)) { @@ -1082,7 +1164,7 @@ static int dvb_ca_en50221_thread(void* data) /* completed */ ca->thread_pid = 0; - mb(); + mb (); wake_up_interruptible (&ca->thread_queue); return 0; } @@ -1103,43 +1185,44 @@ static int dvb_ca_en50221_thread(void* data) * * @return 0 on success, <0 on error. */ -static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *parg) +static int dvb_ca_en50221_io_do_ioctl (struct inode *inode, struct file *file, + unsigned int cmd, void *parg) { - struct dvb_device* dvbdev=(struct dvb_device*) file->private_data; - struct dvb_ca_private* ca = (struct dvb_ca_private*) dvbdev->priv; - int err=0; + struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; + struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; + int err = 0; int slot; dprintk ("%s\n", __FUNCTION__); switch (cmd) { case CA_RESET: - for(slot = 0; slot < ca->slot_count; slot++) { + for (slot = 0; slot < ca->slot_count; slot++) { if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_NONE) { - dvb_ca_en50221_slot_shutdown(ca, slot); + dvb_ca_en50221_slot_shutdown (ca, slot); if (ca->flags & DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE) - dvb_ca_en50221_camchange_irq(ca->pub, slot, DVB_CA_EN50221_CAMCHANGE_INSERTED); + dvb_ca_en50221_camchange_irq (ca->pub,slot,DVB_CA_EN50221_CAMCHANGE_INSERTED); + else + ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_NONE; } } ca->next_read_slot = 0; - dvb_ca_en50221_thread_wakeup(ca); + dvb_ca_en50221_thread_wakeup (ca); break; - case CA_GET_CAP: - { - struct ca_caps *caps = (struct ca_caps*) parg; + case CA_GET_CAP: { + struct ca_caps *caps = (struct ca_caps *) parg; - caps->slot_num=ca->slot_count; - caps->slot_type=CA_CI_LINK; - caps->descr_num=0; - caps->descr_type=0; + caps->slot_num = ca->slot_count; + caps->slot_type = CA_CI_LINK; + caps->descr_num = 0; + caps->descr_type = 0; break; } - - case CA_GET_SLOT_INFO: - { - struct ca_slot_info *info=(struct ca_slot_info *)parg; + case CA_GET_SLOT_INFO: { + struct ca_slot_info *info = + (struct ca_slot_info *) parg; if ((info->num > ca->slot_count) || (info->num < 0)) return -EINVAL; @@ -1157,7 +1240,7 @@ static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file, un } default: - err=-EINVAL; + err = -EINVAL; break; } @@ -1175,9 +1258,10 @@ static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file, un * * @return 0 on success, <0 on error. */ -static int dvb_ca_en50221_io_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) +static int dvb_ca_en50221_io_ioctl (struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) { - return dvb_usercopy(inode, file, cmd, arg, dvb_ca_en50221_io_do_ioctl); + return dvb_usercopy (inode, file, cmd, arg, dvb_ca_en50221_io_do_ioctl); } @@ -1191,10 +1275,12 @@ static int dvb_ca_en50221_io_ioctl(struct inode *inode, struct file *file, unsig * * @return Number of bytes read, or <0 on error. */ -static ssize_t dvb_ca_en50221_io_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) +static ssize_t dvb_ca_en50221_io_write (struct file *file, + const char __user * buf, size_t count, + loff_t * ppos) { - struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; - struct dvb_ca_private *ca=(struct dvb_ca_private*) dvbdev->priv; + struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; + struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; u8 slot, connection_id; int status; char fragbuf[HOST_LINK_BUF_SIZE]; @@ -1206,48 +1292,55 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file, const char __user *buf dprintk ("%s\n", __FUNCTION__); /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */ - if (count < 2) return -EINVAL; + if (count < 2) + return -EINVAL; /* extract slot & connection id */ - if (copy_from_user(&slot, buf, 1)) return -EFAULT; - if (copy_from_user(&connection_id, buf+1, 1)) return -EFAULT; - buf+=2; - count-=2; + if (copy_from_user (&slot, buf, 1)) + return -EFAULT; + if (copy_from_user (&connection_id, buf + 1, 1)) + return -EFAULT; + buf += 2; + count -= 2; /* check if the slot is actually running */ - if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) return -EINVAL; + if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) + return -EINVAL; /* fragment the packets & store in the buffer */ - while(fragpos < count) { + while (fragpos < count) { fraglen = ca->slot_info[slot].link_buf_size - 2; - if ((count - fragpos) < fraglen) fraglen = count - fragpos; + if ((count - fragpos) < fraglen) + fraglen = count - fragpos; fragbuf[0] = connection_id; fragbuf[1] = ((fragpos + fraglen) < count) ? 0x80 : 0x00; - if ((status = copy_from_user(fragbuf+2, buf+fragpos, fraglen)) != 0) goto exit; - - timeout = jiffies + HZ/2; - written = 0; - while(!time_after(jiffies, timeout)) { - status = dvb_ca_en50221_write_data(ca, slot, fragbuf, fraglen+2); - if (status == (fraglen+2)) { - written = 1; - break; - } - if (status != -EAGAIN) goto exit; - - msleep(1); + if ((status = copy_from_user (fragbuf + 2, buf + fragpos, fraglen)) != 0) + goto exit; + + timeout = jiffies + HZ / 2; + written = 0; + while (!time_after (jiffies, timeout)) { + status = dvb_ca_en50221_write_data (ca, slot, fragbuf, fraglen + 2); + if (status == (fraglen + 2)) { + written = 1; + break; + } + if (status != -EAGAIN) + goto exit; + + msleep (1); + } + if (!written) { + status = -EIO; + goto exit; } - if (!written) { - status = -EIO; - goto exit; - } fragpos += fraglen; } status = count + 2; -exit: + exit: return status; } @@ -1255,7 +1348,8 @@ exit: /** * Condition for waking up in dvb_ca_en50221_io_read_condition */ -static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private* ca, int* result, int* _slot) +static int dvb_ca_en50221_io_read_condition (struct dvb_ca_private *ca, + int *result, int *_slot) { int slot; int slot_count = 0; @@ -1266,27 +1360,30 @@ static int dvb_ca_en50221_io_read_condition(struct dvb_ca_private* ca, int* resu u8 hdr[2]; slot = ca->next_read_slot; - while((slot_count < ca->slot_count) && (!found)) { - if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) goto nextslot; + while ((slot_count < ca->slot_count) && (!found)) { + if (ca->slot_info[slot].slot_state != DVB_CA_SLOTSTATE_RUNNING) + goto nextslot; - down_read(&ca->slot_info[slot].sem); + down_read (&ca->slot_info[slot].sem); - idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, -1, &fraglen); - while(idx != -1) { - dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2, 0); - if (connection_id == -1) connection_id = hdr[0]; + idx = dvb_ringbuffer_pkt_next (&ca->slot_info[slot].rx_buffer, -1, &fraglen); + while (idx != -1) { + dvb_ringbuffer_pkt_read (&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2, 0); + if (connection_id == -1) + connection_id = hdr[0]; if ((hdr[0] == connection_id) && ((hdr[1] & 0x80) == 0)) { *_slot = slot; found = 1; break; } - idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, idx, &fraglen); + idx = dvb_ringbuffer_pkt_next (&ca->slot_info[slot].rx_buffer, idx, &fraglen); } - if (!found) up_read(&ca->slot_info[slot].sem); + if (!found) + up_read (&ca->slot_info[slot].sem); -nextslot: + nextslot: slot = (slot + 1) % ca->slot_count; slot_count++; } @@ -1306,10 +1403,11 @@ nextslot: * * @return Number of bytes read, or <0 on error. */ -static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) +static ssize_t dvb_ca_en50221_io_read (struct file *file, char __user * buf, + size_t count, loff_t * ppos) { - struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; - struct dvb_ca_private *ca=(struct dvb_ca_private*) dvbdev->priv; + struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; + struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; int status; int result = 0; u8 hdr[2]; @@ -1324,33 +1422,39 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, size_ dprintk ("%s\n", __FUNCTION__); /* Outgoing packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */ - if (count < 2) return -EINVAL; + if (count < 2) + return -EINVAL; /* wait for some data */ - if ((status = dvb_ca_en50221_io_read_condition(ca, &result, &slot)) == 0) { + if ((status = dvb_ca_en50221_io_read_condition (ca, &result, &slot)) == 0) { /* if we're in nonblocking mode, exit immediately */ - if (file->f_flags & O_NONBLOCK) return -EWOULDBLOCK; + if (file->f_flags & O_NONBLOCK) + return -EWOULDBLOCK; /* wait for some data */ - status = wait_event_interruptible(ca->wait_queue, dvb_ca_en50221_io_read_condition(ca, &result, &slot)); + status = wait_event_interruptible (ca->wait_queue, + dvb_ca_en50221_io_read_condition(ca, &result, &slot)); } if ((status < 0) || (result < 0)) { - if (result) return result; + if (result) + return result; return status; } - idx = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, -1, &fraglen); + idx = dvb_ringbuffer_pkt_next (&ca->slot_info[slot].rx_buffer, -1, + &fraglen); pktlen = 2; do { if (idx == -1) { - printk("dvb_ca adapter %d: BUG: read packet ended before last_fragment encountered\n", ca->dvbdev->adapter->num); + printk ("dvb_ca adapter %d: BUG: read packet ended before last_fragment encountered\n", ca->dvbdev->adapter->num); status = -EIO; goto exit; } - dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2, 0); - if (connection_id == -1) connection_id = hdr[0]; + dvb_ringbuffer_pkt_read (&ca->slot_info[slot].rx_buffer, idx, 0, hdr, 2, 0); + if (connection_id == -1) + connection_id = hdr[0]; if (hdr[0] == connection_id) { if (pktlen < count) { if ((pktlen + fraglen - 2) > count) { @@ -1359,29 +1463,35 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user *buf, size_ fraglen -= 2; } - if ((status = dvb_ringbuffer_pkt_read(&ca->slot_info[slot].rx_buffer, idx, 2, buf + pktlen, fraglen, 1)) < 0) { + if ((status = + dvb_ringbuffer_pkt_read (&ca->slot_info[slot].rx_buffer, idx, 2, + buf + pktlen, fraglen, 1)) < 0) { goto exit; } pktlen += fraglen; } - if ((hdr[1] & 0x80) == 0) last_fragment = 1; + if ((hdr[1] & 0x80) == 0) + last_fragment = 1; dispose = 1; } - idx2 = dvb_ringbuffer_pkt_next(&ca->slot_info[slot].rx_buffer, idx, &fraglen); - if (dispose) dvb_ringbuffer_pkt_dispose(&ca->slot_info[slot].rx_buffer, idx); + idx2 = dvb_ringbuffer_pkt_next (&ca->slot_info[slot].rx_buffer, + idx, &fraglen); + if (dispose) + dvb_ringbuffer_pkt_dispose (&ca->slot_info[slot].rx_buffer, idx); idx = idx2; dispose = 0; } while (!last_fragment); hdr[0] = slot; hdr[1] = connection_id; - if ((status = copy_to_user(buf, hdr, 2)) != 0) goto exit; + if ((status = copy_to_user (buf, hdr, 2)) != 0) + goto exit; status = pktlen; -exit: - up_read(&ca->slot_info[slot].sem); + exit: + up_read (&ca->slot_info[slot].sem); return status; } @@ -1394,30 +1504,30 @@ exit: * * @return 0 on success, <0 on failure. */ -static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file) +static int dvb_ca_en50221_io_open (struct inode *inode, struct file *file) { struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; - struct dvb_ca_private *ca = (struct dvb_ca_private*) dvbdev->priv; + struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; int err; int i; dprintk ("%s\n", __FUNCTION__); - err=dvb_generic_open(inode, file); - if (err<0) + err = dvb_generic_open (inode, file); + if (err < 0) return err; - for(i=0; i< ca->slot_count; i++) { + for (i = 0; i < ca->slot_count; i++) { if (ca->slot_info[i].slot_state == DVB_CA_SLOTSTATE_RUNNING) { - down_write(&ca->slot_info[i].sem); - dvb_ringbuffer_flush(&ca->slot_info[i].rx_buffer); - up_write(&ca->slot_info[i].sem); + down_write (&ca->slot_info[i].sem); + dvb_ringbuffer_flush (&ca->slot_info[i].rx_buffer); + up_write (&ca->slot_info[i].sem); } } ca->open = 1; - dvb_ca_en50221_thread_update_delay(ca); - dvb_ca_en50221_thread_wakeup(ca); + dvb_ca_en50221_thread_update_delay (ca); + dvb_ca_en50221_thread_wakeup (ca); return 0; } @@ -1431,20 +1541,20 @@ static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file) * * @return 0 on success, <0 on failure. */ -static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file) +static int dvb_ca_en50221_io_release (struct inode *inode, struct file *file) { - struct dvb_device *dvbdev=(struct dvb_device *) file->private_data; - struct dvb_ca_private *ca=(struct dvb_ca_private*) dvbdev->priv; + struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; + struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; int err; dprintk ("%s\n", __FUNCTION__); /* mark the CA device as closed */ ca->open = 0; - dvb_ca_en50221_thread_update_delay(ca); + dvb_ca_en50221_thread_update_delay (ca); - err=dvb_generic_release(inode, file); - if (err<0) + err = dvb_generic_release (inode, file); + if (err < 0) return err; return 0; } @@ -1458,29 +1568,31 @@ static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file) * * @return Standard poll mask. */ -static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table *wait) +static unsigned int dvb_ca_en50221_io_poll (struct file *file, + poll_table * wait) { - struct dvb_device* dvbdev = (struct dvb_device*) file->private_data; - struct dvb_ca_private* ca = (struct dvb_ca_private*) dvbdev->priv; - unsigned int mask=0; + struct dvb_device *dvbdev = (struct dvb_device *) file->private_data; + struct dvb_ca_private *ca = (struct dvb_ca_private *) dvbdev->priv; + unsigned int mask = 0; int slot; int result = 0; dprintk ("%s\n", __FUNCTION__); - if (dvb_ca_en50221_io_read_condition(ca, &result, &slot) == 1) { - up_read(&ca->slot_info[slot].sem); + if (dvb_ca_en50221_io_read_condition (ca, &result, &slot) == 1) { + up_read (&ca->slot_info[slot].sem); mask |= POLLIN; } /* if there is something, return now */ - if (mask) return mask; + if (mask) + return mask; /* wait for something to happen */ - poll_wait(file, &ca->wait_queue, wait); + poll_wait (file, &ca->wait_queue, wait); - if (dvb_ca_en50221_io_read_condition(ca, &result, &slot) == 1) { - up_read(&ca->slot_info[slot].sem); + if (dvb_ca_en50221_io_read_condition (ca, &result, &slot) == 1) { + up_read (&ca->slot_info[slot].sem); mask |= POLLIN; } @@ -1489,21 +1601,21 @@ static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table *wait) static struct file_operations dvb_ca_fops = { - .owner = THIS_MODULE, - .read = dvb_ca_en50221_io_read, - .write = dvb_ca_en50221_io_write, - .ioctl = dvb_ca_en50221_io_ioctl, - .open = dvb_ca_en50221_io_open, - .release= dvb_ca_en50221_io_release, - .poll = dvb_ca_en50221_io_poll, + .owner = THIS_MODULE, + .read = dvb_ca_en50221_io_read, + .write = dvb_ca_en50221_io_write, + .ioctl = dvb_ca_en50221_io_ioctl, + .open = dvb_ca_en50221_io_open, + .release = dvb_ca_en50221_io_release, + .poll = dvb_ca_en50221_io_poll, }; static struct dvb_device dvbdev_ca = { - .priv = NULL, - .users = 1, - .readers= 1, - .writers= 1, - .fops = &dvb_ca_fops, + .priv = NULL, + .users = 1, + .readers = 1, + .writers = 1, + .fops = &dvb_ca_fops, }; @@ -1521,33 +1633,36 @@ static struct dvb_device dvbdev_ca = { * * @return 0 on success, nonzero on failure */ -int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, struct dvb_ca_en50221* pubca, int flags, int slot_count) +int dvb_ca_en50221_init (struct dvb_adapter *dvb_adapter, + struct dvb_ca_en50221 *pubca, int flags, + int slot_count) { int ret; - struct dvb_ca_private* ca = NULL; + struct dvb_ca_private *ca = NULL; int i; dprintk ("%s\n", __FUNCTION__); - if (slot_count < 1) return -EINVAL; + if (slot_count < 1) + return -EINVAL; /* initialise the system data */ - if ((ca = (struct dvb_ca_private*) kmalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) == NULL) { + if ((ca = (struct dvb_ca_private *) kmalloc (sizeof (struct dvb_ca_private), GFP_KERNEL)) == NULL) { ret = -ENOMEM; goto error; } - memset(ca, 0, sizeof(struct dvb_ca_private)); + memset (ca, 0, sizeof (struct dvb_ca_private)); ca->pub = pubca; ca->flags = flags; ca->slot_count = slot_count; - if ((ca->slot_info = kmalloc(sizeof(struct dvb_ca_slot) * slot_count, GFP_KERNEL)) == NULL) { + if ((ca->slot_info = kmalloc (sizeof (struct dvb_ca_slot) * slot_count, GFP_KERNEL)) == NULL) { ret = -ENOMEM; goto error; } - memset(ca->slot_info, 0, sizeof(struct dvb_ca_slot) * slot_count); - init_waitqueue_head(&ca->wait_queue); + memset (ca->slot_info, 0, sizeof (struct dvb_ca_slot) * slot_count); + init_waitqueue_head (&ca->wait_queue); ca->thread_pid = 0; - init_waitqueue_head(&ca->thread_queue); + init_waitqueue_head (&ca->thread_queue); ca->exit = 0; ca->open = 0; ca->wakeup = 0; @@ -1555,30 +1670,33 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, struct dvb_ca_en50221* pubca->private = ca; /* register the DVB device */ - ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA); - if (ret) goto error; + ret = dvb_register_device (dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, + DVB_DEVICE_CA); + if (ret) + goto error; /* now initialise each slot */ - for(i=0; i< slot_count; i++) { - memset(&ca->slot_info[i], 0, sizeof(struct dvb_ca_slot)); + for (i = 0; i < slot_count; i++) { + memset (&ca->slot_info[i], 0, sizeof (struct dvb_ca_slot)); ca->slot_info[i].slot_state = DVB_CA_SLOTSTATE_NONE; - atomic_set(&ca->slot_info[i].camchange_count, 0); + atomic_set (&ca->slot_info[i].camchange_count, 0); ca->slot_info[i].camchange_type = DVB_CA_EN50221_CAMCHANGE_REMOVED; - init_rwsem(&ca->slot_info[i].sem); + init_rwsem (&ca->slot_info[i].sem); } - if (signal_pending(current)) { + if (signal_pending (current)) { ret = -EINTR; goto error; } - mb(); + mb (); /* create a kthread for monitoring this CA device */ ret = kernel_thread (dvb_ca_en50221_thread, ca, 0); if (ret < 0) { - printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret); + printk ("dvb_ca_init: failed to start kernel_thread (%d)\n", + ret); goto error; } ca->thread_pid = ret; @@ -1586,9 +1704,11 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter, struct dvb_ca_en50221* error: if (ca != NULL) { - if (ca->dvbdev != NULL) dvb_unregister_device(ca->dvbdev); - if (ca->slot_info != NULL) kfree(ca->slot_info); - kfree(ca); + if (ca->dvbdev != NULL) + dvb_unregister_device (ca->dvbdev); + if (ca->slot_info != NULL) + kfree (ca->slot_info); + kfree (ca); } pubca->private = NULL; return ret; @@ -1602,31 +1722,31 @@ error: * @param ca_dev The dvb_device_t instance for the CA device. * @param ca The associated dvb_ca instance. */ -void dvb_ca_en50221_release(struct dvb_ca_en50221* pubca) +void dvb_ca_en50221_release (struct dvb_ca_en50221 *pubca) { - struct dvb_ca_private* ca = (struct dvb_ca_private*) pubca->private; + struct dvb_ca_private *ca = (struct dvb_ca_private *) pubca->private; int i; dprintk ("%s\n", __FUNCTION__); /* shutdown the thread if there was one */ if (ca->thread_pid) { - if (kill_proc(ca->thread_pid, 0, 1) == -ESRCH) { - printk("dvb_ca_release adapter %d: thread PID %d already died\n", ca->dvbdev->adapter->num, ca->thread_pid); + if (kill_proc (ca->thread_pid, 0, 1) == -ESRCH) { + printk ("dvb_ca_release adapter %d: thread PID %d already died\n", ca->dvbdev->adapter->num, ca->thread_pid); } else { ca->exit = 1; - mb(); - dvb_ca_en50221_thread_wakeup(ca); - wait_event_interruptible(ca->thread_queue, ca->thread_pid == 0); + mb (); + dvb_ca_en50221_thread_wakeup (ca); + wait_event_interruptible (ca->thread_queue, + ca->thread_pid == 0); } } - for(i=0; i< ca->slot_count; i++) { - dvb_ca_en50221_slot_shutdown(ca, i); + for (i = 0; i < ca->slot_count; i++) { + dvb_ca_en50221_slot_shutdown (ca, i); } - kfree(ca->slot_info); - dvb_unregister_device(ca->dvbdev); - kfree(ca); + kfree (ca->slot_info); + dvb_unregister_device (ca->dvbdev); + kfree (ca); pubca->private = NULL; } - diff --git a/linux/drivers/media/dvb/ttpci/budget-av.c b/linux/drivers/media/dvb/ttpci/budget-av.c index 941d5f3c9..1cf473d13 100644 --- a/linux/drivers/media/dvb/ttpci/budget-av.c +++ b/linux/drivers/media/dvb/ttpci/budget-av.c @@ -1,31 +1,34 @@ /* * budget-av.c: driver for the SAA7146 based Budget DVB cards - * with analog video in + * with analog video in * - * Compiled from various sources by Michael Hunold <michael@mihu.de> + * Compiled from various sources by Michael Hunold <michael@mihu.de> + * + * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> & + * Andrew de Quincey <adq_dvb@lidskialf.net> * * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de> * - * Copyright (C) 1999-2002 Ralph Metzler + * Copyright (C) 1999-2002 Ralph Metzler * & Marcus Metzler for convergence integrated media GmbH * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html - * + * * * the project's page is at http://www.linuxtv.org/dvb/ */ @@ -35,699 +38,974 @@ #include "tda10021.h" #include "tda1004x.h" #include <media/saa7146_vv.h> +#include <linux/module.h> +#include <linux/errno.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/input.h> +#include <linux/spinlock.h> + +#include "dvb_ca_en50221.h" + +#define DEBICICAM 0x02420000 struct budget_av { - struct budget budget; - struct video_device *vd; - int cur_input; - int has_saa7113; + struct budget budget; + struct video_device *vd; + int cur_input; + int has_saa7113; + struct tasklet_struct ciintf_irq_tasklet; + int slot_status; + struct dvb_ca_en50221 ca; }; +int enable_ci = 0; + + /**************************************************************************** * INITIALIZATION ****************************************************************************/ static u8 i2c_readreg (struct i2c_adapter *i2c, u8 id, u8 reg) { - u8 mm1[] = {0x00}; - u8 mm2[] = {0x00}; - struct i2c_msg msgs[2]; - - msgs[0].flags = 0; - msgs[1].flags = I2C_M_RD; - msgs[0].addr = msgs[1].addr=id/2; - mm1[0] = reg; - msgs[0].len = 1; msgs[1].len = 1; - msgs[0].buf = mm1; msgs[1].buf = mm2; - - i2c_transfer(i2c, msgs, 2); - - return mm2[0]; + u8 mm1[] = { 0x00 }; + u8 mm2[] = { 0x00 }; + struct i2c_msg msgs[2]; + + msgs[0].flags = 0; + msgs[1].flags = I2C_M_RD; + msgs[0].addr = msgs[1].addr = id / 2; + mm1[0] = reg; + msgs[0].len = 1; + msgs[1].len = 1; + msgs[0].buf = mm1; + msgs[1].buf = mm2; + + i2c_transfer (i2c, msgs, 2); + + return mm2[0]; } -static int i2c_readregs(struct i2c_adapter *i2c, u8 id, u8 reg, u8 *buf, u8 len) +static int i2c_readregs (struct i2c_adapter *i2c, u8 id, u8 reg, u8 * buf, + u8 len) { u8 mm1[] = { reg }; struct i2c_msg msgs[2] = { - { .addr = id/2, .flags = 0, .buf = mm1, .len = 1 }, - { .addr = id/2, .flags = I2C_M_RD, .buf = buf, .len = len } - }; + {.addr = id / 2,.flags = 0,.buf = mm1,.len = 1}, + {.addr = id / 2,.flags = I2C_M_RD,.buf = buf,.len = len} + }; - if (i2c_transfer(i2c, msgs, 2) != 2) - return -EIO; + if (i2c_transfer (i2c, msgs, 2) != 2) + return -EIO; - return 0; + return 0; } static int i2c_writereg (struct i2c_adapter *i2c, u8 id, u8 reg, u8 val) { - u8 msg[2]={ reg, val }; + u8 msg[2] = { reg, val }; struct i2c_msg msgs; - msgs.flags=0; - msgs.addr=id/2; - msgs.len=2; - msgs.buf=msg; - return i2c_transfer(i2c, &msgs, 1); + msgs.flags = 0; + msgs.addr = id / 2; + msgs.len = 2; + msgs.buf = msg; + return i2c_transfer (i2c, &msgs, 1); +} + +static int ciintf_read_attribute_mem (struct dvb_ca_en50221 *ca, int slot, + int address) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + + if (slot != 0) + return -EINVAL; + + saa7146_setgpio (budget_av->budget.dev, 1, SAA7146_GPIO_OUTHI); + return ttpci_budget_debiread (&budget_av->budget, DEBICICAM, address & 0xfff, 1); } +static int ciintf_write_attribute_mem (struct dvb_ca_en50221 *ca, int slot, + int address, u8 value) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + + if (slot != 0) + return -EINVAL; + + saa7146_setgpio (budget_av->budget.dev, 1, SAA7146_GPIO_OUTHI); + return ttpci_budget_debiwrite (&budget_av->budget, DEBICICAM, address & 0xfff, 1, value); +} + +static int ciintf_read_cam_control (struct dvb_ca_en50221 *ca, int slot, + u8 address) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + + if (slot != 0) + return -EINVAL; + + saa7146_setgpio (budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO); + return ttpci_budget_debiread (&budget_av->budget, DEBICICAM, address & 3, 1); +} + +static int ciintf_write_cam_control (struct dvb_ca_en50221 *ca, int slot, + u8 address, u8 value) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + + if (slot != 0) + return -EINVAL; + + saa7146_setgpio (budget_av->budget.dev, 1, SAA7146_GPIO_OUTLO); + return ttpci_budget_debiwrite (&budget_av->budget, DEBICICAM, address & 3, 1, value); +} + +static int ciintf_slot_reset (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + struct saa7146_dev *saa = budget_av->budget.dev; + + if (slot != 0) + return -EINVAL; + + dprintk (1, "ciintf_slot_reset\n"); + + /* reset the card */ + saa7146_setgpio (saa, 0, SAA7146_GPIO_OUTHI); + msleep(100); + saa7146_setgpio (saa, 0, SAA7146_GPIO_OUTLO); + msleep(2000); /* horrendous I know, but its the only way to be absolutely sure without an IRQ line! */ + + ttpci_budget_set_video_port (saa, BUDGET_VIDEO_PORTB); + return 0; +} + +static int ciintf_slot_shutdown (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + struct saa7146_dev *saa = budget_av->budget.dev; + + if (slot != 0) + return -EINVAL; + + dprintk (1, "ciintf_slot_shutdown\n"); + + ttpci_budget_set_video_port (saa, BUDGET_VIDEO_PORTB); + budget_av->slot_status = 0; + return 0; +} + +static int ciintf_slot_ts_enable (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + struct saa7146_dev *saa = budget_av->budget.dev; + + if (slot != 0) + return -EINVAL; + + dprintk (1, "ciintf_slot_ts_enable: %d\n", budget_av->slot_status); + + ttpci_budget_set_video_port (saa, BUDGET_VIDEO_PORTA); + return 0; +} + +static int ciintf_poll_slot_status (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_av *budget_av = (struct budget_av *) ca->data; + struct saa7146_dev *saa = budget_av->budget.dev; + int cam = 0; + + if (slot != 0) + return -EINVAL; + + saa7146_setgpio (saa, 3, SAA7146_GPIO_INPUT); + udelay(1); + cam = saa7146_read (saa, PSR) & MASK_06; + saa7146_setgpio (saa, 3, SAA7146_GPIO_OUTLO); + + if (cam && (!budget_av->slot_status)) { + budget_av->slot_status = 1; + } else if ((!cam) && budget_av->slot_status) { + budget_av->slot_status = 0; + } + + if (budget_av->slot_status == 1) + return DVB_CA_EN50221_POLL_CAM_PRESENT | DVB_CA_EN50221_POLL_CAM_READY; + + return 0; +} + +static int ciintf_init (struct budget_av *budget_av) +{ + struct saa7146_dev *saa = budget_av->budget.dev; + int result; + + memset (&budget_av->ca, 0, sizeof (struct dvb_ca_en50221)); + + /* setup GPIOs */ + saa7146_setgpio (saa, 1, SAA7146_GPIO_OUTHI); + saa7146_setgpio (saa, 2, SAA7146_GPIO_OUTLO); + saa7146_setgpio (saa, 3, SAA7146_GPIO_OUTLO); + + /* Reset the card */ + saa7146_setgpio (saa, 0, SAA7146_GPIO_OUTHI); + msleep (50); + saa7146_setgpio (saa, 0, SAA7146_GPIO_OUTLO); + msleep (100); + + /* Enable DEBI pins */ + saa7146_write (saa, MC1, + saa7146_read (saa, MC1) | (0x800 << 16) | 0x800); + + /* register CI interface */ + budget_av->ca.read_attribute_mem = ciintf_read_attribute_mem; + budget_av->ca.write_attribute_mem = ciintf_write_attribute_mem; + budget_av->ca.read_cam_control = ciintf_read_cam_control; + budget_av->ca.write_cam_control = ciintf_write_cam_control; + budget_av->ca.slot_reset = ciintf_slot_reset; + budget_av->ca.slot_shutdown = ciintf_slot_shutdown; + budget_av->ca.slot_ts_enable = ciintf_slot_ts_enable; + budget_av->ca.poll_slot_status = ciintf_poll_slot_status; + budget_av->ca.data = budget_av; + if ((result = dvb_ca_en50221_init (budget_av->budget.dvb_adapter, + &budget_av->ca, 0, 1)) != 0) { + printk ("budget_av: CI interface detected, but initialisation failed.\n"); + goto error; + } + + // success! + printk ("ciintf_init: CI interface initialised\n"); + budget_av->budget.ci_present = 1; + return 0; + +error: + saa7146_write (saa, MC1, saa7146_read (saa, MC1) | (0x800 << 16)); + return result; +} + +static void ciintf_deinit (struct budget_av *budget_av) +{ + struct saa7146_dev *saa = budget_av->budget.dev; + + saa7146_setgpio (saa, 0, SAA7146_GPIO_INPUT); + saa7146_setgpio (saa, 1, SAA7146_GPIO_INPUT); + saa7146_setgpio (saa, 2, SAA7146_GPIO_INPUT); + saa7146_setgpio (saa, 3, SAA7146_GPIO_INPUT); + + /* release the CA device */ + dvb_ca_en50221_release (&budget_av->ca); + + /* disable DEBI pins */ + saa7146_write (saa, MC1, saa7146_read (saa, MC1) | (0x800 << 16)); +} + + static const u8 saa7113_tab[] = { - 0x01, 0x08, - 0x02, 0xc0, - 0x03, 0x33, - 0x04, 0x00, - 0x05, 0x00, - 0x06, 0xeb, - 0x07, 0xe0, - 0x08, 0x28, - 0x09, 0x00, - 0x0a, 0x80, - 0x0b, 0x47, - 0x0c, 0x40, - 0x0d, 0x00, - 0x0e, 0x01, + 0x01, 0x08, + 0x02, 0xc0, + 0x03, 0x33, + 0x04, 0x00, + 0x05, 0x00, + 0x06, 0xeb, + 0x07, 0xe0, + 0x08, 0x28, + 0x09, 0x00, + 0x0a, 0x80, + 0x0b, 0x47, + 0x0c, 0x40, + 0x0d, 0x00, + 0x0e, 0x01, 0x0f, 0x44, - 0x10, 0x08, - 0x11, 0x0c, - 0x12, 0x7b, - 0x13, 0x00, - 0x15, 0x00, 0x16, 0x00, 0x17, 0x00, + 0x10, 0x08, + 0x11, 0x0c, + 0x12, 0x7b, + 0x13, 0x00, + 0x15, 0x00, 0x16, 0x00, 0x17, 0x00, - 0x57, 0xff, - 0x40, 0x82, 0x58, 0x00, 0x59, 0x54, 0x5a, 0x07, - 0x5b, 0x83, 0x5e, 0x00, + 0x57, 0xff, + 0x40, 0x82, 0x58, 0x00, 0x59, 0x54, 0x5a, 0x07, + 0x5b, 0x83, 0x5e, 0x00, 0xff }; static int saa7113_init (struct budget_av *budget_av) { - struct budget *budget = &budget_av->budget; - const u8 *data = saa7113_tab; + struct budget *budget = &budget_av->budget; + const u8 *data = saa7113_tab; if (i2c_writereg (&budget->i2c_adap, 0x4a, 0x01, 0x08) != 1) { - dprintk(1, "saa7113 not found on KNC card\n"); + dprintk (1, "saa7113 not found on KNC card\n"); return -ENODEV; } - dprintk(1, "saa7113 detected and initializing\n"); + dprintk (1, "saa7113 detected and initializing\n"); - while (*data != 0xff) { - i2c_writereg(&budget->i2c_adap, 0x4a, *data, *(data+1)); + while (*data != 0xff) { + i2c_writereg (&budget->i2c_adap, 0x4a, *data, *(data + 1)); data += 2; } - dprintk(1, "saa7113 status=%02x\n", i2c_readreg(&budget->i2c_adap, 0x4a, 0x1f)); + dprintk (1, "saa7113 status=%02x\n", + i2c_readreg (&budget->i2c_adap, 0x4a, 0x1f)); - return 0; + return 0; } static int saa7113_setinput (struct budget_av *budget_av, int input) { - struct budget *budget = &budget_av->budget; - - if ( 1 != budget_av->has_saa7113 ) - return -ENODEV; - - if (input == 1) { - i2c_writereg(&budget->i2c_adap, 0x4a, 0x02, 0xc7); - i2c_writereg(&budget->i2c_adap, 0x4a, 0x09, 0x80); - } else if (input == 0) { - i2c_writereg(&budget->i2c_adap, 0x4a, 0x02, 0xc0); - i2c_writereg(&budget->i2c_adap, 0x4a, 0x09, 0x00); - } else - return -EINVAL; - - budget_av->cur_input = input; - return 0; + struct budget *budget = &budget_av->budget; + + if (1 != budget_av->has_saa7113) + return -ENODEV; + + if (input == 1) { + i2c_writereg (&budget->i2c_adap, 0x4a, 0x02, 0xc7); + i2c_writereg (&budget->i2c_adap, 0x4a, 0x09, 0x80); + } else if (input == 0) { + i2c_writereg (&budget->i2c_adap, 0x4a, 0x02, 0xc0); + i2c_writereg (&budget->i2c_adap, 0x4a, 0x09, 0x00); + } else + return -EINVAL; + + budget_av->cur_input = input; + return 0; } -static int philips_su1278_ty_ci_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio) +static int philips_su1278_ty_ci_set_symbol_rate (struct dvb_frontend *fe, + u32 srate, u32 ratio) { - u8 aclk = 0; - u8 bclk = 0; - u8 m1; - - aclk = 0xb5; - if (srate < 2000000) bclk = 0x86; - else if (srate < 5000000) bclk = 0x89; - else if (srate < 15000000) bclk = 0x8f; - else if (srate < 45000000) bclk = 0x95; - - m1 = 0x14; - if (srate < 4000000) m1 = 0x10; - - stv0299_writereg (fe, 0x13, aclk); - stv0299_writereg (fe, 0x14, bclk); - stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); - stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); - stv0299_writereg (fe, 0x21, (ratio ) & 0xf0); - stv0299_writereg (fe, 0x0f, 0x80 | m1); - - return 0; + u8 aclk = 0; + u8 bclk = 0; + u8 m1; + + aclk = 0xb5; + if (srate < 2000000) + bclk = 0x86; + else if (srate < 5000000) + bclk = 0x89; + else if (srate < 15000000) + bclk = 0x8f; + else if (srate < 45000000) + bclk = 0x95; + + m1 = 0x14; + if (srate < 4000000) + m1 = 0x10; + + stv0299_writereg (fe, 0x13, aclk); + stv0299_writereg (fe, 0x14, bclk); + stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); + stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); + stv0299_writereg (fe, 0x21, (ratio) & 0xf0); + stv0299_writereg (fe, 0x0f, 0x80 | m1); + + return 0; } -static int philips_su1278_ty_ci_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) +static int philips_su1278_ty_ci_pll_set (struct dvb_frontend *fe, + struct dvb_frontend_parameters *params) { - struct budget_av* budget_av = (struct budget_av*) fe->dvb->priv; - u32 div; - u8 buf[4]; - struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; - - if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL; - - div = (params->frequency + (125 - 1)) / 125; // round correctly - buf[0] = (div >> 8) & 0x7f; - buf[1] = div & 0xff; - buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4; - buf[3] = 0x20; - - if (params->u.qpsk.symbol_rate < 4000000) buf[3] |= 1; - - if (params->frequency < 1250000) buf[3] |= 0; - else if (params->frequency < 1550000) buf[3] |= 0x40; - else if (params->frequency < 2050000) buf[3] |= 0x80; - else if (params->frequency < 2150000) buf[3] |= 0xC0; - - if (i2c_transfer (&budget_av->budget.i2c_adap, &msg, 1) != 1) return -EIO; - return 0; + struct budget_av *budget_av = (struct budget_av *) fe->dvb->priv; + u32 div; + u8 buf[4]; + struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof (buf) }; + + if ((params->frequency < 950000) || (params->frequency > 2150000)) + return -EINVAL; + + div = (params->frequency + (125 - 1)) / 125; // round correctly + buf[0] = (div >> 8) & 0x7f; + buf[1] = div & 0xff; + buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4; + buf[3] = 0x20; + + if (params->u.qpsk.symbol_rate < 4000000) + buf[3] |= 1; + + if (params->frequency < 1250000) + buf[3] |= 0; + else if (params->frequency < 1550000) + buf[3] |= 0x40; + else if (params->frequency < 2050000) + buf[3] |= 0x80; + else if (params->frequency < 2150000) + buf[3] |= 0xC0; + + if (i2c_transfer (&budget_av->budget.i2c_adap, &msg, 1) != 1) + return -EIO; + return 0; } static u8 typhoon_cinergy1200s_inittab[] = { - 0x01, 0x15, - 0x02, 0x30, - 0x03, 0x00, - 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ - 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ - 0x06, 0x40, /* DAC not used, set to high impendance mode */ - 0x07, 0x00, /* DAC LSB */ - 0x08, 0x40, /* DiSEqC off */ - 0x09, 0x00, /* FIFO */ - 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ - 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ - 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ - 0x10, 0x3f, // AGC2 0x3d - 0x11, 0x84, - 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on - 0x15, 0xc9, // lock detector threshold - 0x16, 0x00, - 0x17, 0x00, - 0x18, 0x00, - 0x19, 0x00, - 0x1a, 0x00, - 0x1f, 0x50, - 0x20, 0x00, - 0x21, 0x00, - 0x22, 0x00, - 0x23, 0x00, - 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 - 0x29, 0x1e, // 1/2 threshold - 0x2a, 0x14, // 2/3 threshold - 0x2b, 0x0f, // 3/4 threshold - 0x2c, 0x09, // 5/6 threshold - 0x2d, 0x05, // 7/8 threshold - 0x2e, 0x01, - 0x31, 0x1f, // test all FECs - 0x32, 0x19, // viterbi and synchro search - 0x33, 0xfc, // rs control - 0x34, 0x93, // error control - 0x0f, 0x92, - 0xff, 0xff + 0x01, 0x15, + 0x02, 0x30, + 0x03, 0x00, + 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ + 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ + 0x06, 0x40, /* DAC not used, set to high impendance mode */ + 0x07, 0x00, /* DAC LSB */ + 0x08, 0x40, /* DiSEqC off */ + 0x09, 0x00, /* FIFO */ + 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ + 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ + 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ + 0x10, 0x3f, // AGC2 0x3d + 0x11, 0x84, + 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on + 0x15, 0xc9, // lock detector threshold + 0x16, 0x00, + 0x17, 0x00, + 0x18, 0x00, + 0x19, 0x00, + 0x1a, 0x00, + 0x1f, 0x50, + 0x20, 0x00, + 0x21, 0x00, + 0x22, 0x00, + 0x23, 0x00, + 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 + 0x29, 0x1e, // 1/2 threshold + 0x2a, 0x14, // 2/3 threshold + 0x2b, 0x0f, // 3/4 threshold + 0x2c, 0x09, // 5/6 threshold + 0x2d, 0x05, // 7/8 threshold + 0x2e, 0x01, + 0x31, 0x1f, // test all FECs + 0x32, 0x19, // viterbi and synchro search + 0x33, 0xfc, // rs control + 0x34, 0x93, // error control + 0x0f, 0x92, + 0xff, 0xff }; static struct stv0299_config typhoon_config = { - .demod_address = 0x68, - .inittab = typhoon_cinergy1200s_inittab, - .mclk = 88000000UL, - .invert = 0, - .enhanced_tuning = 0, - .skip_reinit = 0, - .lock_output = STV0229_LOCKOUTPUT_1, - .volt13_op0_op1 = STV0299_VOLT13_OP0, - .min_delay_ms = 100, - .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, - .pll_set = philips_su1278_ty_ci_pll_set, + .demod_address = 0x68, + .inittab = typhoon_cinergy1200s_inittab, + .mclk = 88000000UL, + .invert = 0, + .enhanced_tuning = 0, + .skip_reinit = 0, + .lock_output = STV0229_LOCKOUTPUT_1, + .volt13_op0_op1 = STV0299_VOLT13_OP0, + .min_delay_ms = 100, + .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, + .pll_set = philips_su1278_ty_ci_pll_set, }; static struct stv0299_config cinergy_1200s_config = { - .demod_address = 0x68, - .inittab = typhoon_cinergy1200s_inittab, - .mclk = 88000000UL, - .invert = 0, - .enhanced_tuning = 0, - .skip_reinit = 0, - .lock_output = STV0229_LOCKOUTPUT_0, - .volt13_op0_op1 = STV0299_VOLT13_OP0, - .min_delay_ms = 100, - .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, - .pll_set = philips_su1278_ty_ci_pll_set, + .demod_address = 0x68, + .inittab = typhoon_cinergy1200s_inittab, + .mclk = 88000000UL, + .invert = 0, + .enhanced_tuning = 0, + .skip_reinit = 0, + .lock_output = STV0229_LOCKOUTPUT_0, + .volt13_op0_op1 = STV0299_VOLT13_OP0, + .min_delay_ms = 100, + .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, + .pll_set = philips_su1278_ty_ci_pll_set, }; -static int philips_cu1216_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) +static int philips_cu1216_pll_set (struct dvb_frontend *fe, + struct dvb_frontend_parameters *params) { - struct budget* budget = (struct budget*) fe->dvb->priv; - u8 buf[4]; - struct i2c_msg msg= { .addr=0x60,.flags=0,.buf=buf,.len=sizeof(buf) }; + struct budget *budget = (struct budget *) fe->dvb->priv; + u8 buf[4]; + struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof (buf) }; #define TUNER_MUL 62500 - - u32 div = (params->frequency + 36125000 + TUNER_MUL/2) / TUNER_MUL; - buf[0] = (div>>8) & 0x7f; - buf[1] = div & 0xff; - buf[2] = 0x8e; - buf[3] =(params->frequency < 174500000 ? 0xa1 : - params->frequency < 454000000 ? 0x92 : 0x34); + u32 div = (params->frequency + 36125000 + TUNER_MUL / 2) / TUNER_MUL; - if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) return -EIO; - return 0; + buf[0] = (div >> 8) & 0x7f; + buf[1] = div & 0xff; + buf[2] = 0x8e; + buf[3] = (params->frequency < 174500000 ? 0xa1 : + params->frequency < 454000000 ? 0x92 : 0x34); + + if (i2c_transfer (&budget->i2c_adap, &msg, 1) != 1) + return -EIO; + return 0; } static struct tda10021_config philips_cu1216_config = { - .demod_address = 0x0c, - .pll_set = philips_cu1216_pll_set, + .demod_address = 0x0c, + .pll_set = philips_cu1216_pll_set, }; -static int philips_tu1216_pll_init(struct dvb_frontend* fe) +static int philips_tu1216_pll_init (struct dvb_frontend *fe) { - struct budget* budget = (struct budget*) fe->dvb->priv; - static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab }; - static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 }; - struct i2c_msg tuner_msg = { .addr=0x60, .flags=0, .buf=tu1216_init, .len=sizeof(tu1216_init) }; - - // setup PLL configuration - if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) return -EIO; - msleep(1); - - // disable the mc44BC374c (do not check for errors) - tuner_msg.addr = 0x65; - tuner_msg.buf = disable_mc44BC374c; - tuner_msg.len = sizeof(disable_mc44BC374c); - if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) { - i2c_transfer(&budget->i2c_adap, &tuner_msg, 1); - } - - return 0; + struct budget *budget = (struct budget *) fe->dvb->priv; + static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab }; + static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 }; + struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof (tu1216_init) }; + + // setup PLL configuration + if (i2c_transfer (&budget->i2c_adap, &tuner_msg, 1) != 1) + return -EIO; + msleep (1); + + // disable the mc44BC374c (do not check for errors) + tuner_msg.addr = 0x65; + tuner_msg.buf = disable_mc44BC374c; + tuner_msg.len = sizeof (disable_mc44BC374c); + if (i2c_transfer (&budget->i2c_adap, &tuner_msg, 1) != 1) { + i2c_transfer (&budget->i2c_adap, &tuner_msg, 1); + } + + return 0; } -static int philips_tu1216_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) +static int philips_tu1216_pll_set (struct dvb_frontend *fe, + struct dvb_frontend_parameters *params) { - struct budget* budget = (struct budget*) fe->dvb->priv; - u8 tuner_buf[4]; - struct i2c_msg tuner_msg = {.addr=0x60, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) }; - int tuner_frequency = 0; - u8 band, cp, filter; - - // determine charge pump - tuner_frequency = params->frequency + 36130000; - if (tuner_frequency < 87000000) return -EINVAL; - else if (tuner_frequency < 130000000) cp = 3; - else if (tuner_frequency < 160000000) cp = 5; - else if (tuner_frequency < 200000000) cp = 6; - else if (tuner_frequency < 290000000) cp = 3; - else if (tuner_frequency < 420000000) cp = 5; - else if (tuner_frequency < 480000000) cp = 6; - else if (tuner_frequency < 620000000) cp = 3; - else if (tuner_frequency < 830000000) cp = 5; - else if (tuner_frequency < 895000000) cp = 7; - else return -EINVAL; - - // determine band - if (params->frequency < 49000000) return -EINVAL; - else if (params->frequency < 159000000) band = 1; - else if (params->frequency < 444000000) band = 2; - else if (params->frequency < 861000000) band = 4; - else return -EINVAL; - - // setup PLL filter - switch (params->u.ofdm.bandwidth) { - case BANDWIDTH_6_MHZ: - tda1004x_write_byte(fe, 0x0C, 0); - filter = 0; - break; - - case BANDWIDTH_7_MHZ: - tda1004x_write_byte(fe, 0x0C, 0); - filter = 0; - break; - - case BANDWIDTH_8_MHZ: - tda1004x_write_byte(fe, 0x0C, 0xFF); - filter = 1; - break; - - default: - return -EINVAL; - } - - // calculate divisor - // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6) - tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000; - - // setup tuner buffer - tuner_buf[0] = tuner_frequency >> 8; - tuner_buf[1] = tuner_frequency & 0xff; - tuner_buf[2] = 0xca; - tuner_buf[3] = (cp << 5) | (filter << 3) | band; - - if (i2c_transfer(&budget->i2c_adap, &tuner_msg, 1) != 1) return -EIO; - - msleep(1); - return 0; + struct budget *budget = (struct budget *) fe->dvb->priv; + u8 tuner_buf[4]; + struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len = sizeof (tuner_buf) }; + int tuner_frequency = 0; + u8 band, cp, filter; + + // determine charge pump + tuner_frequency = params->frequency + 36130000; + if (tuner_frequency < 87000000) + return -EINVAL; + else if (tuner_frequency < 130000000) + cp = 3; + else if (tuner_frequency < 160000000) + cp = 5; + else if (tuner_frequency < 200000000) + cp = 6; + else if (tuner_frequency < 290000000) + cp = 3; + else if (tuner_frequency < 420000000) + cp = 5; + else if (tuner_frequency < 480000000) + cp = 6; + else if (tuner_frequency < 620000000) + cp = 3; + else if (tuner_frequency < 830000000) + cp = 5; + else if (tuner_frequency < 895000000) + cp = 7; + else + return -EINVAL; + + // determine band + if (params->frequency < 49000000) + return -EINVAL; + else if (params->frequency < 159000000) + band = 1; + else if (params->frequency < 444000000) + band = 2; + else if (params->frequency < 861000000) + band = 4; + else + return -EINVAL; + + // setup PLL filter + switch (params->u.ofdm.bandwidth) { + case BANDWIDTH_6_MHZ: + tda1004x_write_byte (fe, 0x0C, 0); + filter = 0; + break; + + case BANDWIDTH_7_MHZ: + tda1004x_write_byte (fe, 0x0C, 0); + filter = 0; + break; + + case BANDWIDTH_8_MHZ: + tda1004x_write_byte (fe, 0x0C, 0xFF); + filter = 1; + break; + + default: + return -EINVAL; + } + + // calculate divisor + // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6) + tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000; + + // setup tuner buffer + tuner_buf[0] = tuner_frequency >> 8; + tuner_buf[1] = tuner_frequency & 0xff; + tuner_buf[2] = 0xca; + tuner_buf[3] = (cp << 5) | (filter << 3) | band; + + if (i2c_transfer (&budget->i2c_adap, &tuner_msg, 1) != 1) + return -EIO; + + msleep (1); + return 0; } -static int philips_tu1216_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) +static int philips_tu1216_request_firmware (struct dvb_frontend *fe, + const struct firmware **fw, + char *name) { - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = (struct budget *) fe->dvb->priv; - return request_firmware(fw, name, &budget->dev->pci->dev); + return request_firmware (fw, name, &budget->dev->pci->dev); } struct tda1004x_config philips_tu1216_config = { - .demod_address = 0x8, - .invert = 1, - .pll_init = philips_tu1216_pll_init, - .pll_set = philips_tu1216_pll_set, - .request_firmware = philips_tu1216_request_firmware, + .demod_address = 0x8, + .invert = 1, + .pll_init = philips_tu1216_pll_init, + .pll_set = philips_tu1216_pll_set, + .request_firmware = philips_tu1216_request_firmware, }; -static u8 read_pwm(struct budget_av* budget_av) +static u8 read_pwm (struct budget_av *budget_av) { - u8 b = 0xff; - u8 pwm; - struct i2c_msg msg[] = { { .addr = 0x50,.flags = 0,.buf = &b,.len = 1 }, - { .addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} }; + u8 b = 0xff; + u8 pwm; + struct i2c_msg msg[] = { {.addr = 0x50,.flags = 0,.buf = &b,.len = 1}, + {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} }; - if ((i2c_transfer(&budget_av->budget.i2c_adap, msg, 2) != 2) || (pwm == 0xff)) - pwm = 0x48; + if ((i2c_transfer (&budget_av->budget.i2c_adap, msg, 2) != 2) + || (pwm == 0xff)) + pwm = 0x48; - return pwm; + return pwm; } -static void frontend_init(struct budget_av *budget_av) +static void frontend_init (struct budget_av *budget_av) { - switch(budget_av->budget.dev->pci->subsystem_device) { - case 0x4f56: // Typhoon/KNC1 DVB-S budget (stv0299/Philips SU1278(tsa5059)) - budget_av->budget.dvb_frontend = stv0299_attach(&typhoon_config, &budget_av->budget.i2c_adap); - if (budget_av->budget.dvb_frontend != NULL) { - break; - } - break; - - case 0x0020: // KNC1 DVB-C budget (tda10021/Philips CU1216(tua6034)) - budget_av->budget.dvb_frontend = tda10021_attach(&philips_cu1216_config, &budget_av->budget.i2c_adap, read_pwm(budget_av)); - if (budget_av->budget.dvb_frontend != NULL) { - break; - } - break; - - case 0x0030: // KNC1 DVB-T budget (tda10046/Philips TU1216(tda6651tt)) - budget_av->budget.dvb_frontend = tda10046_attach(&philips_tu1216_config, &budget_av->budget.i2c_adap); - if (budget_av->budget.dvb_frontend != NULL) { - break; - } - break; - - case 0x1154: // TerraTec Cinergy 1200 DVB-S (stv0299/Philips SU1278(tsa5059)) - budget_av->budget.dvb_frontend = stv0299_attach(&cinergy_1200s_config, &budget_av->budget.i2c_adap); - if (budget_av->budget.dvb_frontend != NULL) { - break; - } - break; - - case 0x1156: // Terratec Cinergy 1200 DVB-C (tda10021/Philips CU1216(tua6034)) - budget_av->budget.dvb_frontend = tda10021_attach(&philips_cu1216_config, &budget_av->budget.i2c_adap, read_pwm(budget_av)); - if (budget_av->budget.dvb_frontend) { - break; - } - break; - - case 0x1157: // Terratec Cinergy 1200 DVB-T (tda10046/Philips TU1216(tda6651tt)) - budget_av->budget.dvb_frontend = tda10046_attach(&philips_tu1216_config, &budget_av->budget.i2c_adap); - if (budget_av->budget.dvb_frontend) { - break; - } - break; - } - - if (budget_av->budget.dvb_frontend == NULL) { - printk("budget_av: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", - budget_av->budget.dev->pci->vendor, - budget_av->budget.dev->pci->device, - budget_av->budget.dev->pci->subsystem_vendor, - budget_av->budget.dev->pci->subsystem_device); - } else { - if (dvb_register_frontend(budget_av->budget.dvb_adapter, budget_av->budget.dvb_frontend)) { - printk("budget-av: Frontend registration failed!\n"); - if (budget_av->budget.dvb_frontend->ops->release) - budget_av->budget.dvb_frontend->ops->release(budget_av->budget.dvb_frontend); - budget_av->budget.dvb_frontend = NULL; - } - } + switch (budget_av->budget.dev->pci->subsystem_device) { + case 0x4f56: // Typhoon/KNC1 DVB-S budget (stv0299/Philips SU1278(tsa5059)) + budget_av->budget.dvb_frontend = + stv0299_attach (&typhoon_config, + &budget_av->budget.i2c_adap); + if (budget_av->budget.dvb_frontend != NULL) { + break; + } + break; + + case 0x0020: // KNC1 DVB-C budget (tda10021/Philips CU1216(tua6034)) + budget_av->budget.dvb_frontend = + tda10021_attach (&philips_cu1216_config, + &budget_av->budget.i2c_adap, + read_pwm (budget_av)); + if (budget_av->budget.dvb_frontend != NULL) { + break; + } + break; + + case 0x0030: // KNC1 DVB-T budget (tda10046/Philips TU1216(tda6651tt)) + budget_av->budget.dvb_frontend = + tda10046_attach (&philips_tu1216_config, + &budget_av->budget.i2c_adap); + if (budget_av->budget.dvb_frontend != NULL) { + break; + } + break; + + case 0x1154: // TerraTec Cinergy 1200 DVB-S (stv0299/Philips SU1278(tsa5059)) + budget_av->budget.dvb_frontend = + stv0299_attach (&cinergy_1200s_config, + &budget_av->budget.i2c_adap); + if (budget_av->budget.dvb_frontend != NULL) { + break; + } + break; + + case 0x1156: // Terratec Cinergy 1200 DVB-C (tda10021/Philips CU1216(tua6034)) + budget_av->budget.dvb_frontend = + tda10021_attach (&philips_cu1216_config, + &budget_av->budget.i2c_adap, + read_pwm (budget_av)); + if (budget_av->budget.dvb_frontend) { + break; + } + break; + + case 0x1157: // Terratec Cinergy 1200 DVB-T (tda10046/Philips TU1216(tda6651tt)) + budget_av->budget.dvb_frontend = + tda10046_attach (&philips_tu1216_config, + &budget_av->budget.i2c_adap); + if (budget_av->budget.dvb_frontend) { + break; + } + break; + } + + if (budget_av->budget.dvb_frontend == NULL) { + printk ("budget_av: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", + budget_av->budget.dev->pci->vendor, + budget_av->budget.dev->pci->device, + budget_av->budget.dev->pci->subsystem_vendor, + budget_av->budget.dev->pci->subsystem_device); + } else { + if (dvb_register_frontend(budget_av->budget.dvb_adapter, budget_av->budget.dvb_frontend)) { + printk ("budget-av: Frontend registration failed!\n"); + if (budget_av->budget.dvb_frontend->ops->release) + budget_av->budget.dvb_frontend->ops->release (budget_av->budget.dvb_frontend); + budget_av->budget.dvb_frontend = NULL; + } + } } +static void budget_av_irq (struct saa7146_dev *dev, u32 * isr) +{ + struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; + + dprintk (8, "dev: %p, budget_av: %p\n", dev, budget_av); + + if (*isr & MASK_10) + ttpci_budget_irq10_handler (dev, isr); +} + static int budget_av_detach (struct saa7146_dev *dev) { - struct budget_av *budget_av = (struct budget_av*) dev->ext_priv; - int err; + struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; + int err; - dprintk(2, "dev: %p\n", dev); + dprintk (2, "dev: %p\n", dev); - if ( 1 == budget_av->has_saa7113 ) { - saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTLO); + if (1 == budget_av->has_saa7113) { + saa7146_setgpio (dev, 0, SAA7146_GPIO_OUTLO); - msleep(200); + msleep (200); - saa7146_unregister_device (&budget_av->vd, dev); - } - if (budget_av->budget.dvb_frontend != NULL) dvb_unregister_frontend(budget_av->budget.dvb_frontend); - err = ttpci_budget_deinit (&budget_av->budget); + saa7146_unregister_device (&budget_av->vd, dev); + } + + if (budget_av->budget.ci_present) + ciintf_deinit (budget_av); - kfree (budget_av); + if (budget_av->budget.dvb_frontend != NULL) + dvb_unregister_frontend (budget_av->budget.dvb_frontend); + err = ttpci_budget_deinit (&budget_av->budget); - return err; + kfree (budget_av); + + return err; } static struct saa7146_ext_vv vv_data; -static int budget_av_attach (struct saa7146_dev* dev, - struct saa7146_pci_extension_data *info) +static int budget_av_attach (struct saa7146_dev *dev, + struct saa7146_pci_extension_data *info) { - struct budget_av *budget_av; - u8 *mac; - int err; - - dprintk(2, "dev: %p\n", dev); - - if (!(budget_av = kmalloc(sizeof(struct budget_av), GFP_KERNEL))) - return -ENOMEM; - - memset(budget_av, 0, sizeof(struct budget_av)); - - dev->ext_priv = budget_av; - - if ((err = ttpci_budget_init(&budget_av->budget, dev, info))) { - kfree(budget_av); - return err; - } - - /* knc1 initialization */ - saa7146_write(dev, DD1_STREAM_B, 0x04000000); - saa7146_write(dev, DD1_INIT, 0x07000600); - saa7146_write(dev, MC2, MASK_09 | MASK_25 | MASK_10 | MASK_26); - - //test_knc_ci(av7110); - - saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTHI); - msleep(500); - - if ( 0 == saa7113_init(budget_av) ) { - budget_av->has_saa7113 = 1; - - if ( 0 != saa7146_vv_init(dev,&vv_data)) { - /* fixme: proper cleanup here */ - ERR(("cannot init vv subsystem.\n")); - return err; - } - - if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", - VFL_TYPE_GRABBER))) - { - /* fixme: proper cleanup here */ - ERR(("cannot register capture v4l2 device.\n")); - return err; - } - - /* beware: this modifies dev->vv ... */ - saa7146_set_hps_source_and_sync(dev, SAA7146_HPS_SOURCE_PORT_A, - SAA7146_HPS_SYNC_PORT_A); - - saa7113_setinput (budget_av, 0); - } else { - budget_av->has_saa7113 = 0; - - saa7146_setgpio(dev, 0, SAA7146_GPIO_OUTLO); - } - - /* fixme: find some sane values here... */ - saa7146_write(dev, PCI_BT_V1, 0x1c00101f); - - mac = budget_av->budget.dvb_adapter->proposed_mac; - if (i2c_readregs(&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) { - printk("KNC1-%d: Could not read MAC from KNC1 card\n", - budget_av->budget.dvb_adapter->num); - memset(mac, 0, 6); - } - else - printk("KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", - budget_av->budget.dvb_adapter->num, - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - budget_av->budget.dvb_adapter->priv = budget_av; - frontend_init(budget_av); - - return 0; + struct budget_av *budget_av; + u8 *mac; + int err; + + dprintk (2, "dev: %p\n", dev); + + if (!(budget_av = kmalloc (sizeof (struct budget_av), GFP_KERNEL))) + return -ENOMEM; + + memset (budget_av, 0, sizeof (struct budget_av)); + + budget_av->budget.ci_present = 0; + + dev->ext_priv = budget_av; + + if ((err = ttpci_budget_init (&budget_av->budget, dev, info))) { + kfree (budget_av); + return err; + } + + /* knc1 initialization */ + saa7146_write (dev, DD1_STREAM_B, 0x04000000); + saa7146_write (dev, DD1_INIT, 0x07000600); + saa7146_write (dev, MC2, MASK_09 | MASK_25 | MASK_10 | MASK_26); + + saa7146_setgpio (dev, 0, SAA7146_GPIO_OUTHI); + msleep (500); + + if (0 == saa7113_init (budget_av)) { + budget_av->has_saa7113 = 1; + + if (0 != saa7146_vv_init (dev, &vv_data)) { + /* fixme: proper cleanup here */ + ERR (("cannot init vv subsystem.\n")); + return err; + } + + if ((err = saa7146_register_device (&budget_av->vd, dev, "knc1", + VFL_TYPE_GRABBER))) { + /* fixme: proper cleanup here */ + ERR (("cannot register capture v4l2 device.\n")); + return err; + } + + /* beware: this modifies dev->vv ... */ + saa7146_set_hps_source_and_sync (dev, SAA7146_HPS_SOURCE_PORT_A, + SAA7146_HPS_SYNC_PORT_A); + + saa7113_setinput (budget_av, 0); + } else { + budget_av->has_saa7113 = 0; + + saa7146_setgpio (dev, 0, SAA7146_GPIO_OUTLO); + } + + /* fixme: find some sane values here... */ + saa7146_write (dev, PCI_BT_V1, 0x1c00101f); + + mac = budget_av->budget.dvb_adapter->proposed_mac; + if (i2c_readregs (&budget_av->budget.i2c_adap, 0xa0, 0x30, mac, 6)) { + printk ("KNC1-%d: Could not read MAC from KNC1 card\n", + budget_av->budget.dvb_adapter->num); + memset (mac, 0, 6); + } else { + printk ("KNC1-%d: MAC addr = %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", + budget_av->budget.dvb_adapter->num, + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + } + + budget_av->budget.dvb_adapter->priv = budget_av; + frontend_init (budget_av); + + if (enable_ci) + ciintf_init (budget_av); + + return 0; } #define KNC1_INPUTS 2 static struct v4l2_input knc1_inputs[KNC1_INPUTS] = { - { 0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, - { 1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, + {0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, + {1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, }; static struct saa7146_extension_ioctls ioctls[] = { - { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE }, - { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE }, - { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE }, - { 0, 0 } + {VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE}, + {VIDIOC_G_INPUT, SAA7146_EXCLUSIVE}, + {VIDIOC_S_INPUT, SAA7146_EXCLUSIVE}, + {0, 0} }; -static int av_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) +static int av_ioctl (struct saa7146_fh *fh, unsigned int cmd, void *arg) { - struct saa7146_dev *dev = fh->dev; - struct budget_av *budget_av = (struct budget_av*) dev->ext_priv; -/* - struct saa7146_vv *vv = dev->vv_data; -*/ - switch(cmd) { - case VIDIOC_ENUMINPUT: - { - struct v4l2_input *i = arg; - - dprintk(1, "VIDIOC_ENUMINPUT %d.\n", i->index); - if( i->index < 0 || i->index >= KNC1_INPUTS) { - return -EINVAL; - } - memcpy(i, &knc1_inputs[i->index], sizeof(struct v4l2_input)); - return 0; - } - case VIDIOC_G_INPUT: - { - int *input = (int *)arg; - - *input = budget_av->cur_input; - - dprintk(1, "VIDIOC_G_INPUT %d.\n", *input); - return 0; - } - case VIDIOC_S_INPUT: - { - int input = *(int *)arg; - dprintk(1, "VIDIOC_S_INPUT %d.\n", input); - return saa7113_setinput (budget_av, input); - } - default: - return -ENOIOCTLCMD; - } - return 0; + struct saa7146_dev *dev = fh->dev; + struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; + + switch (cmd) { + case VIDIOC_ENUMINPUT: { + struct v4l2_input *i = arg; + + dprintk (1, "VIDIOC_ENUMINPUT %d.\n", i->index); + if (i->index < 0 || i->index >= KNC1_INPUTS) { + return -EINVAL; + } + memcpy (i, &knc1_inputs[i->index], sizeof (struct v4l2_input)); + return 0; + } + case VIDIOC_G_INPUT: { + int *input = (int *) arg; + + *input = budget_av->cur_input; + + dprintk (1, "VIDIOC_G_INPUT %d.\n", *input); + return 0; + } + case VIDIOC_S_INPUT: { + int input = *(int *) arg; + dprintk (1, "VIDIOC_S_INPUT %d.\n", input); + return saa7113_setinput (budget_av, input); + } + default: + return -ENOIOCTLCMD; + } + return 0; } static struct saa7146_standard standard[] = { - { - .name = "PAL", .id = V4L2_STD_PAL, - .v_offset = 0x17, .v_field = 288, - .h_offset = 0x14, .h_pixels = 680, - .v_max_out = 576, .h_max_out = 768 - }, { - .name = "NTSC", .id = V4L2_STD_NTSC, - .v_offset = 0x16, .v_field = 240, - .h_offset = 0x06, .h_pixels = 708, - .v_max_out = 480, .h_max_out = 640, - } -}; + { + .name = "PAL",.id = V4L2_STD_PAL, + .v_offset = 0x17,.v_field = 288, + .h_offset = 0x14,.h_pixels = 680, + .v_max_out = 576,.h_max_out = 768 + }, + { + .name = "NTSC",.id = + V4L2_STD_NTSC, + .v_offset = 0x16,.v_field = 240, + .h_offset = 0x06,.h_pixels = 708, + .v_max_out = 480,.h_max_out = 640, + } +}; static struct saa7146_ext_vv vv_data = { - .inputs = 2, - .capabilities = 0, // perhaps later: V4L2_CAP_VBI_CAPTURE, but that need tweaking with the saa7113 - .flags = 0, - .stds = &standard[0], - .num_stds = sizeof(standard)/sizeof(struct saa7146_standard), - .ioctls = &ioctls[0], - .ioctl = av_ioctl, + .inputs = 2, + .capabilities = 0, // perhaps later: V4L2_CAP_VBI_CAPTURE, but that need tweaking with the saa7113 + .flags = 0, + .stds = &standard[0], + .num_stds = sizeof (standard) / sizeof (struct saa7146_standard), + .ioctls = &ioctls[0], + .ioctl = av_ioctl, }; static struct saa7146_extension budget_extension; -MAKE_BUDGET_INFO(knc1s, "KNC1 DVB-S", BUDGET_KNC1S); -MAKE_BUDGET_INFO(knc1c, "KNC1 DVB-C", BUDGET_KNC1C); -MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T); -MAKE_BUDGET_INFO(cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S); -MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C); -MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T); - -static struct pci_device_id pci_tbl [] = { - MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x4f56), - MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020), - MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030), - MAKE_EXTENSION_PCI(cin1200s, 0x153b, 0x1154), - MAKE_EXTENSION_PCI(cin1200c, 0x153b, 0x1156), - MAKE_EXTENSION_PCI(cin1200t, 0x153b, 0x1157), - { - .vendor = 0, - } +MAKE_BUDGET_INFO (knc1s, "KNC1 DVB-S", BUDGET_KNC1S); +MAKE_BUDGET_INFO (knc1c, "KNC1 DVB-C", BUDGET_KNC1C); +MAKE_BUDGET_INFO (knc1t, "KNC1 DVB-T", BUDGET_KNC1T); +MAKE_BUDGET_INFO (cin1200s, "TerraTec Cinergy 1200 DVB-S", BUDGET_CIN1200S); +MAKE_BUDGET_INFO (cin1200c, "Terratec Cinergy 1200 DVB-C", BUDGET_CIN1200C); +MAKE_BUDGET_INFO (cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T); + +static struct pci_device_id pci_tbl[] = { + MAKE_EXTENSION_PCI (knc1s, 0x1131, 0x4f56), + MAKE_EXTENSION_PCI (knc1c, 0x1894, 0x0020), + MAKE_EXTENSION_PCI (knc1t, 0x1894, 0x0030), + MAKE_EXTENSION_PCI (cin1200s, 0x153b, 0x1154), + MAKE_EXTENSION_PCI (cin1200c, 0x153b, 0x1156), + MAKE_EXTENSION_PCI (cin1200t, 0x153b, 0x1157), + { + .vendor = 0, + } }; -MODULE_DEVICE_TABLE(pci, pci_tbl); +MODULE_DEVICE_TABLE (pci, pci_tbl); static struct saa7146_extension budget_extension = { - .name = "budget dvb /w video in\0", - .pci_tbl = pci_tbl, + .name = "budget dvb /w video in\0", + .pci_tbl = pci_tbl, - .module = THIS_MODULE, - .attach = budget_av_attach, - .detach = budget_av_detach, + .module = THIS_MODULE, + .attach = budget_av_attach, + .detach = budget_av_detach, - .irq_mask = MASK_10, - .irq_func = ttpci_budget_irq10_handler, -}; + .irq_mask = MASK_10, + .irq_func = budget_av_irq, +}; -static int __init budget_av_init(void) +static int __init budget_av_init (void) { - return saa7146_register_extension(&budget_extension); + return saa7146_register_extension (&budget_extension); } -static void __exit budget_av_exit(void) +static void __exit budget_av_exit (void) { - saa7146_unregister_extension(&budget_extension); + saa7146_unregister_extension (&budget_extension); } -module_init(budget_av_init); -module_exit(budget_av_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, Michael Hunold, others"); -MODULE_DESCRIPTION("driver for the SAA7146 based so-called " - "budget PCI DVB w/ analog input (e.g. the KNC cards)"); +module_init (budget_av_init); +module_exit (budget_av_exit); +MODULE_LICENSE ("GPL"); +MODULE_AUTHOR ("Ralph Metzler, Marcus Metzler, Michael Hunold, others"); +MODULE_DESCRIPTION ("driver for the SAA7146 based so-called " + "budget PCI DVB w/ analog input and CI-module (e.g. the KNC cards)"); +module_param_named (enable_ci, enable_ci, int, 0644); +MODULE_PARM_DESC (enable_ci, "Turn on/off CI module (default:off)."); diff --git a/linux/drivers/media/dvb/ttpci/budget-ci.c b/linux/drivers/media/dvb/ttpci/budget-ci.c index bbd1dc0a3..361cab9bf 100644 --- a/linux/drivers/media/dvb/ttpci/budget-ci.c +++ b/linux/drivers/media/dvb/ttpci/budget-ci.c @@ -62,921 +62,951 @@ #define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY) struct budget_ci { - struct budget budget; - struct input_dev input_dev; - struct tasklet_struct msp430_irq_tasklet; - struct tasklet_struct ciintf_irq_tasklet; - spinlock_t debilock; - int slot_status; - struct dvb_ca_en50221 ca; - char ir_dev_name[50]; + struct budget budget; + struct input_dev input_dev; + struct tasklet_struct msp430_irq_tasklet; + struct tasklet_struct ciintf_irq_tasklet; + int slot_status; + struct dvb_ca_en50221 ca; + char ir_dev_name[50]; }; -static u32 budget_debiread (struct budget_ci* budget_ci, u32 config, int addr, int count) -{ - struct saa7146_dev *saa = budget_ci->budget.dev; - u32 result = 0; - unsigned long flags; - - if (count > 4 || count <= 0) - return 0; - - spin_lock_irqsave(&budget_ci->debilock, flags); - - if (saa7146_wait_for_debi_done(saa) < 0) { - spin_unlock_irqrestore(&budget_ci->debilock, flags); - return 0; - } - - saa7146_write (saa, DEBI_COMMAND, - (count << 17) | 0x10000 | (addr & 0xffff)); - saa7146_write(saa, DEBI_CONFIG, config); - saa7146_write(saa, DEBI_PAGE, 0); - saa7146_write(saa, MC2, (2 << 16) | 2); - - saa7146_wait_for_debi_done(saa); - - result = saa7146_read(saa, 0x88); - result &= (0xffffffffUL >> ((4 - count) * 8)); - - spin_unlock_irqrestore(&budget_ci->debilock, flags); - return result; -} - -static u8 budget_debiwrite (struct budget_ci* budget_ci, u32 config, int addr, int count, u32 value) -{ - struct saa7146_dev *saa = budget_ci->budget.dev; - unsigned long flags; - - if (count > 4 || count <= 0) - return 0; - - spin_lock_irqsave(&budget_ci->debilock, flags); - - if (saa7146_wait_for_debi_done(saa) < 0) { - spin_unlock_irqrestore(&budget_ci->debilock, flags); - return 0; - } - - saa7146_write (saa, DEBI_COMMAND, - (count << 17) | 0x00000 | (addr & 0xffff)); - saa7146_write(saa, DEBI_CONFIG, config); - saa7146_write(saa, DEBI_PAGE, 0); - saa7146_write(saa, DEBI_AD, value); - saa7146_write(saa, MC2, (2 << 16) | 2); - - saa7146_wait_for_debi_done(saa); - - spin_unlock_irqrestore(&budget_ci->debilock, flags); - return 0; -} - /* from reading the following remotes: Zenith Universal 7 / TV Mode 807 / VCR Mode 837 Hauppauge (from NOVA-CI-s box product) i've taken a "middle of the road" approach and note the differences */ -static u16 key_map[64] = { - /* 0x0X */ - KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, - KEY_9, - KEY_ENTER, - KEY_RED, - KEY_POWER, /* RADIO on Hauppauge */ - KEY_MUTE, - 0, - KEY_A, /* TV on Hauppauge */ - /* 0x1X */ - KEY_VOLUMEUP, KEY_VOLUMEDOWN, - 0, 0, - KEY_B, - 0, 0, 0, 0, 0, 0, 0, - KEY_UP, KEY_DOWN, - KEY_OPTION, /* RESERVED on Hauppauge */ - KEY_BREAK, - /* 0x2X */ - KEY_CHANNELUP, KEY_CHANNELDOWN, - KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */ - 0, KEY_RESTART, KEY_OK, - KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */ - 0, - KEY_ENTER, /* VCR mode on Zenith */ - KEY_PAUSE, - 0, - KEY_RIGHT, KEY_LEFT, - 0, - KEY_MENU, /* FULL SCREEN on Hauppauge */ - 0, - /* 0x3X */ - KEY_SLOW, - KEY_PREVIOUS, /* VCR mode on Zenith */ - KEY_REWIND, - 0, - KEY_FASTFORWARD, - KEY_PLAY, KEY_STOP, - KEY_RECORD, - KEY_TUNER, /* TV/VCR on Zenith */ - 0, - KEY_C, - 0, - KEY_EXIT, - KEY_POWER2, - KEY_TUNER, /* VCR mode on Zenith */ - 0, +static u16 key_map[64] = { + /* 0x0X */ + KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, + KEY_9, + KEY_ENTER, + KEY_RED, + KEY_POWER, /* RADIO on Hauppauge */ + KEY_MUTE, + 0, + KEY_A, /* TV on Hauppauge */ + /* 0x1X */ + KEY_VOLUMEUP, KEY_VOLUMEDOWN, + 0, 0, + KEY_B, + 0, 0, 0, 0, 0, 0, 0, + KEY_UP, KEY_DOWN, + KEY_OPTION, /* RESERVED on Hauppauge */ + KEY_BREAK, + /* 0x2X */ + KEY_CHANNELUP, KEY_CHANNELDOWN, + KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */ + 0, KEY_RESTART, KEY_OK, + KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */ + 0, + KEY_ENTER, /* VCR mode on Zenith */ + KEY_PAUSE, + 0, + KEY_RIGHT, KEY_LEFT, + 0, + KEY_MENU, /* FULL SCREEN on Hauppauge */ + 0, + /* 0x3X */ + KEY_SLOW, + KEY_PREVIOUS, /* VCR mode on Zenith */ + KEY_REWIND, + 0, + KEY_FASTFORWARD, + KEY_PLAY, KEY_STOP, + KEY_RECORD, + KEY_TUNER, /* TV/VCR on Zenith */ + 0, + KEY_C, + 0, + KEY_EXIT, + KEY_POWER2, + KEY_TUNER, /* VCR mode on Zenith */ + 0, }; static void msp430_ir_debounce (unsigned long data) { - struct input_dev *dev = (struct input_dev *) data; + struct input_dev *dev = (struct input_dev *) data; - if (dev->rep[0] == 0 || dev->rep[0] == ~0) { - input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0); - return; - } + if (dev->rep[0] == 0 || dev->rep[0] == ~0) { + input_event (dev, EV_KEY, key_map[dev->repeat_key], !!0); + return; + } - dev->rep[0] = 0; - dev->timer.expires = jiffies + HZ * 350 / 1000; - add_timer(&dev->timer); - input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */ + dev->rep[0] = 0; + dev->timer.expires = jiffies + HZ * 350 / 1000; + add_timer (&dev->timer); + input_event (dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */ } static void msp430_ir_interrupt (unsigned long data) { - struct budget_ci *budget_ci = (struct budget_ci*) data; - struct input_dev *dev = &budget_ci->input_dev; - unsigned int code = budget_debiread(budget_ci, DEBINOSWAP, DEBIADDR_IR, 2) >> 8; - - if (code & 0x40) { - code &= 0x3f; - - if (timer_pending(&dev->timer)) { - if (code == dev->repeat_key) { - ++dev->rep[0]; - return; - } - del_timer(&dev->timer); - input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0); - } - - if (!key_map[code]) { - printk ("DVB (%s): no key for %02x!\n", - __FUNCTION__, code); - return; - } - - /* initialize debounce and repeat */ - dev->repeat_key = code; - /* Zenith remote _always_ sends 2 sequences */ - dev->rep[0] = ~0; - /* 350 milliseconds */ - dev->timer.expires = jiffies + HZ * 350 / 1000; - /* MAKE */ - input_event(dev, EV_KEY, key_map[code], !0); - add_timer(&dev->timer); - } + struct budget_ci *budget_ci = (struct budget_ci *) data; + struct input_dev *dev = &budget_ci->input_dev; + unsigned int code = + ttpci_budget_debiread (&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2) >> 8; + + if (code & 0x40) { + code &= 0x3f; + + if (timer_pending (&dev->timer)) { + if (code == dev->repeat_key) { + ++dev->rep[0]; + return; + } + del_timer (&dev->timer); + input_event (dev, EV_KEY, key_map[dev->repeat_key], + !!0); + } + + if (!key_map[code]) { + printk ("DVB (%s): no key for %02x!\n", + __FUNCTION__, code); + return; + } + + /* initialize debounce and repeat */ + dev->repeat_key = code; + /* Zenith remote _always_ sends 2 sequences */ + dev->rep[0] = ~0; + /* 350 milliseconds */ + dev->timer.expires = jiffies + HZ * 350 / 1000; + /* MAKE */ + input_event (dev, EV_KEY, key_map[code], !0); + add_timer (&dev->timer); + } } static int msp430_ir_init (struct budget_ci *budget_ci) { - struct saa7146_dev *saa = budget_ci->budget.dev; - int i; + struct saa7146_dev *saa = budget_ci->budget.dev; + int i; - memset(&budget_ci->input_dev, 0, sizeof(struct input_dev)); + memset (&budget_ci->input_dev, 0, sizeof (struct input_dev)); - sprintf (budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name); - budget_ci->input_dev.name = budget_ci->ir_dev_name; + sprintf (budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", + saa->name); + budget_ci->input_dev.name = budget_ci->ir_dev_name; - set_bit(EV_KEY, budget_ci->input_dev.evbit); + set_bit (EV_KEY, budget_ci->input_dev.evbit); - for (i=0; i<sizeof(key_map)/sizeof(*key_map); i++) - if (key_map[i]) - set_bit(key_map[i], budget_ci->input_dev.keybit); + for (i = 0; i < sizeof (key_map) / sizeof (*key_map); i++) + if (key_map[i]) + set_bit (key_map[i], budget_ci->input_dev.keybit); - input_register_device(&budget_ci->input_dev); + input_register_device (&budget_ci->input_dev); - budget_ci->input_dev.timer.function = msp430_ir_debounce; + budget_ci->input_dev.timer.function = msp430_ir_debounce; - saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06); + saa7146_write (saa, IER, saa7146_read (saa, IER) | MASK_06); - saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI); + saa7146_setgpio (saa, 3, SAA7146_GPIO_IRQHI); - return 0; + return 0; } static void msp430_ir_deinit (struct budget_ci *budget_ci) { - struct saa7146_dev *saa = budget_ci->budget.dev; - struct input_dev *dev = &budget_ci->input_dev; + struct saa7146_dev *saa = budget_ci->budget.dev; + struct input_dev *dev = &budget_ci->input_dev; - saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06); - saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); + saa7146_write (saa, IER, saa7146_read (saa, IER) & ~MASK_06); + saa7146_setgpio (saa, 3, SAA7146_GPIO_INPUT); - if (del_timer(&dev->timer)) - input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0); + if (del_timer (&dev->timer)) + input_event (dev, EV_KEY, key_map[dev->repeat_key], !!0); - input_unregister_device(dev); + input_unregister_device (dev); } -static int ciintf_read_attribute_mem(struct dvb_ca_en50221* ca, int slot, int address) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; +static int ciintf_read_attribute_mem (struct dvb_ca_en50221 *ca, int slot, + int address) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; - if (slot != 0) return -EINVAL; + if (slot != 0) + return -EINVAL; - return budget_debiread(budget_ci, DEBICICAM, DEBIADDR_ATTR | (address & 0xfff), 1); + return ttpci_budget_debiread (&budget_ci->budget, DEBICICAM, + DEBIADDR_ATTR | (address & 0xfff), 1); } -static int ciintf_write_attribute_mem(struct dvb_ca_en50221* ca, int slot, int address, u8 value) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; +static int ciintf_write_attribute_mem (struct dvb_ca_en50221 *ca, int slot, + int address, u8 value) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; - if (slot != 0) return -EINVAL; + if (slot != 0) + return -EINVAL; - return budget_debiwrite(budget_ci, DEBICICAM, DEBIADDR_ATTR | (address & 0xfff), 1, value); + return ttpci_budget_debiwrite (&budget_ci->budget, DEBICICAM, + DEBIADDR_ATTR | (address & 0xfff), 1, value); } -static int ciintf_read_cam_control(struct dvb_ca_en50221* ca, int slot, u8 address) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; +static int ciintf_read_cam_control (struct dvb_ca_en50221 *ca, int slot, + u8 address) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; - if (slot != 0) return -EINVAL; + if (slot != 0) + return -EINVAL; - return budget_debiread(budget_ci, DEBICICAM, DEBIADDR_IO | (address & 3), 1); + return ttpci_budget_debiread (&budget_ci->budget, DEBICICAM, + DEBIADDR_IO | (address & 3), 1); } -static int ciintf_write_cam_control(struct dvb_ca_en50221* ca, int slot, u8 address, u8 value) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; +static int ciintf_write_cam_control (struct dvb_ca_en50221 *ca, int slot, + u8 address, u8 value) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; - if (slot != 0) return -EINVAL; + if (slot != 0) + return -EINVAL; - return budget_debiwrite(budget_ci, DEBICICAM, DEBIADDR_IO | (address & 3), 1, value); + return ttpci_budget_debiwrite (&budget_ci->budget, DEBICICAM, + DEBIADDR_IO | (address & 3), 1, value); } -static int ciintf_slot_reset(struct dvb_ca_en50221* ca, int slot) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; - struct saa7146_dev *saa = budget_ci->budget.dev; - - if (slot != 0) return -EINVAL; - - // trigger on RISING edge during reset so we know when READY is re-asserted - saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI); - budget_ci->slot_status = SLOTSTATUS_RESET; - budget_debiwrite(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1, 0); - msleep(1); - budget_debiwrite(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1, CICONTROL_RESET); - - saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI); - ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB); - return 0; +static int ciintf_slot_reset (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct saa7146_dev *saa = budget_ci->budget.dev; + + if (slot != 0) + return -EINVAL; + + // trigger on RISING edge during reset so we know when READY is re-asserted + saa7146_setgpio (saa, 0, SAA7146_GPIO_IRQHI); + budget_ci->slot_status = SLOTSTATUS_RESET; + ttpci_budget_debiwrite (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0); + msleep (1); + ttpci_budget_debiwrite (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, + CICONTROL_RESET); + + saa7146_setgpio (saa, 1, SAA7146_GPIO_OUTHI); + ttpci_budget_set_video_port (saa, BUDGET_VIDEO_PORTB); + return 0; } -static int ciintf_slot_shutdown(struct dvb_ca_en50221* ca, int slot) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; - struct saa7146_dev *saa = budget_ci->budget.dev; +static int ciintf_slot_shutdown (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct saa7146_dev *saa = budget_ci->budget.dev; - if (slot != 0) return -EINVAL; + if (slot != 0) + return -EINVAL; - saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTHI); - ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTB); - return 0; + saa7146_setgpio (saa, 1, SAA7146_GPIO_OUTHI); + ttpci_budget_set_video_port (saa, BUDGET_VIDEO_PORTB); + return 0; } -static int ciintf_slot_ts_enable(struct dvb_ca_en50221* ca, int slot) { - struct budget_ci* budget_ci = (struct budget_ci*) ca->data; - struct saa7146_dev *saa = budget_ci->budget.dev; - int tmp; +static int ciintf_slot_ts_enable (struct dvb_ca_en50221 *ca, int slot) +{ + struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct saa7146_dev *saa = budget_ci->budget.dev; + int tmp; - if (slot != 0) return -EINVAL; + if (slot != 0) + return -EINVAL; - saa7146_setgpio(saa, 1, SAA7146_GPIO_OUTLO); + saa7146_setgpio (saa, 1, SAA7146_GPIO_OUTLO); - tmp = budget_debiread(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1); - budget_debiwrite(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1, tmp | CICONTROL_ENABLETS); + tmp = ttpci_budget_debiread (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1); + ttpci_budget_debiwrite (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, + tmp | CICONTROL_ENABLETS); - ttpci_budget_set_video_port(saa, BUDGET_VIDEO_PORTA); - return 0; + ttpci_budget_set_video_port (saa, BUDGET_VIDEO_PORTA); + return 0; } static void ciintf_interrupt (unsigned long data) { - struct budget_ci *budget_ci = (struct budget_ci*) data; - struct saa7146_dev *saa = budget_ci->budget.dev; - unsigned int flags; - - // ensure we don't get spurious IRQs during initialisation - if (!budget_ci->budget.ci_present) return; - - // read the CAM status - flags = budget_debiread(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1); - if (flags & CICONTROL_CAMDETECT) { - - // GPIO should be set to trigger on falling edge if a CAM is present - saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO); - - if (budget_ci->slot_status & SLOTSTATUS_NONE) { - // CAM insertion IRQ - budget_ci->slot_status = SLOTSTATUS_PRESENT; - dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, DVB_CA_EN50221_CAMCHANGE_INSERTED); - - } else if (budget_ci->slot_status & SLOTSTATUS_RESET) { - // CAM ready (reset completed) - budget_ci->slot_status = SLOTSTATUS_READY; - dvb_ca_en50221_camready_irq(&budget_ci->ca, 0); - - } else if (budget_ci->slot_status & SLOTSTATUS_READY) { - // FR/DA IRQ - dvb_ca_en50221_frda_irq(&budget_ci->ca, 0); - } - } else { - - // trigger on rising edge if a CAM is not present - when a CAM is inserted, we - // only want to get the IRQ when it sets READY. If we trigger on the falling edge, - // the CAM might not actually be ready yet. - saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI); - - // generate a CAM removal IRQ if we haven't already - if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) { - // CAM removal IRQ - budget_ci->slot_status = SLOTSTATUS_NONE; - dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, DVB_CA_EN50221_CAMCHANGE_REMOVED); - } - } + struct budget_ci *budget_ci = (struct budget_ci *) data; + struct saa7146_dev *saa = budget_ci->budget.dev; + unsigned int flags; + + // ensure we don't get spurious IRQs during initialisation + if (!budget_ci->budget.ci_present) + return; + + // read the CAM status + flags = ttpci_budget_debiread (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1); + if (flags & CICONTROL_CAMDETECT) { + + // GPIO should be set to trigger on falling edge if a CAM is present + saa7146_setgpio (saa, 0, SAA7146_GPIO_IRQLO); + + if (budget_ci->slot_status & SLOTSTATUS_NONE) { + // CAM insertion IRQ + budget_ci->slot_status = SLOTSTATUS_PRESENT; + dvb_ca_en50221_camchange_irq (&budget_ci->ca, 0, + DVB_CA_EN50221_CAMCHANGE_INSERTED); + + } else if (budget_ci->slot_status & SLOTSTATUS_RESET) { + // CAM ready (reset completed) + budget_ci->slot_status = SLOTSTATUS_READY; + dvb_ca_en50221_camready_irq (&budget_ci->ca, 0); + + } else if (budget_ci->slot_status & SLOTSTATUS_READY) { + // FR/DA IRQ + dvb_ca_en50221_frda_irq (&budget_ci->ca, 0); + } + } else { + + // trigger on rising edge if a CAM is not present - when a CAM is inserted, we + // only want to get the IRQ when it sets READY. If we trigger on the falling edge, + // the CAM might not actually be ready yet. + saa7146_setgpio (saa, 0, SAA7146_GPIO_IRQHI); + + // generate a CAM removal IRQ if we haven't already + if (budget_ci->slot_status & SLOTSTATUS_OCCUPIED) { + // CAM removal IRQ + budget_ci->slot_status = SLOTSTATUS_NONE; + dvb_ca_en50221_camchange_irq (&budget_ci->ca, 0, + DVB_CA_EN50221_CAMCHANGE_REMOVED); + } + } } -static int ciintf_init(struct budget_ci* budget_ci) +static int ciintf_init (struct budget_ci *budget_ci) { - struct saa7146_dev *saa = budget_ci->budget.dev; - int flags; - int result; - - memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221)); - - // enable DEBI pins - saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800); - - // test if it is there - if ((budget_debiread(budget_ci, DEBICICTL, DEBIADDR_CIVERSION, 1) & 0xa0) != 0xa0) { - result = -ENODEV; - goto error; - } - - // determine whether a CAM is present or not - flags = budget_debiread(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1); - budget_ci->slot_status = SLOTSTATUS_NONE; - if (flags & CICONTROL_CAMDETECT) budget_ci->slot_status = SLOTSTATUS_PRESENT; - - // register CI interface - budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem; - budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem; - budget_ci->ca.read_cam_control = ciintf_read_cam_control; - budget_ci->ca.write_cam_control = ciintf_write_cam_control; - budget_ci->ca.slot_reset = ciintf_slot_reset; - budget_ci->ca.slot_shutdown = ciintf_slot_shutdown; - budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable; - budget_ci->ca.data = budget_ci; - if ((result = dvb_ca_en50221_init(budget_ci->budget.dvb_adapter, - &budget_ci->ca, - DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE | - DVB_CA_EN50221_FLAG_IRQ_FR | - DVB_CA_EN50221_FLAG_IRQ_DA, - 1)) != 0) { - printk("budget_ci: CI interface detected, but initialisation failed.\n"); - goto error; - } - - // Setup CI slot IRQ - tasklet_init (&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, (unsigned long) budget_ci); - if (budget_ci->slot_status != SLOTSTATUS_NONE) { - saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQLO); - } else { - saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI); - } - saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03); - budget_debiwrite(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1, CICONTROL_RESET); - - // success! - printk("budget_ci: CI interface initialised\n"); - budget_ci->budget.ci_present = 1; - - // forge a fake CI IRQ so the CAM state is setup correctly - flags = DVB_CA_EN50221_CAMCHANGE_REMOVED; - if (budget_ci->slot_status != SLOTSTATUS_NONE) flags = DVB_CA_EN50221_CAMCHANGE_INSERTED; - dvb_ca_en50221_camchange_irq(&budget_ci->ca, 0, flags); - - return 0; - -error: - saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16)); - return result; + struct saa7146_dev *saa = budget_ci->budget.dev; + int flags; + int result; + + memset (&budget_ci->ca, 0, sizeof (struct dvb_ca_en50221)); + + // enable DEBI pins + saa7146_write (saa, MC1, + saa7146_read (saa, MC1) | (0x800 << 16) | 0x800); + + // test if it is there + if ((ttpci_budget_debiread (&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1) & 0xa0) != 0xa0) { + result = -ENODEV; + goto error; + } + + // determine whether a CAM is present or not + flags = ttpci_budget_debiread (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1); + budget_ci->slot_status = SLOTSTATUS_NONE; + if (flags & CICONTROL_CAMDETECT) + budget_ci->slot_status = SLOTSTATUS_PRESENT; + + // register CI interface + budget_ci->ca.read_attribute_mem = ciintf_read_attribute_mem; + budget_ci->ca.write_attribute_mem = ciintf_write_attribute_mem; + budget_ci->ca.read_cam_control = ciintf_read_cam_control; + budget_ci->ca.write_cam_control = ciintf_write_cam_control; + budget_ci->ca.slot_reset = ciintf_slot_reset; + budget_ci->ca.slot_shutdown = ciintf_slot_shutdown; + budget_ci->ca.slot_ts_enable = ciintf_slot_ts_enable; + budget_ci->ca.data = budget_ci; + if ((result = dvb_ca_en50221_init (budget_ci->budget.dvb_adapter, + &budget_ci->ca, + DVB_CA_EN50221_FLAG_IRQ_CAMCHANGE | + DVB_CA_EN50221_FLAG_IRQ_FR | + DVB_CA_EN50221_FLAG_IRQ_DA, + 1)) != 0) { + printk ("budget_ci: CI interface detected, but initialisation failed.\n"); + goto error; + } + + // Setup CI slot IRQ + tasklet_init (&budget_ci->ciintf_irq_tasklet, ciintf_interrupt, + (unsigned long) budget_ci); + if (budget_ci->slot_status != SLOTSTATUS_NONE) { + saa7146_setgpio (saa, 0, SAA7146_GPIO_IRQLO); + } else { + saa7146_setgpio (saa, 0, SAA7146_GPIO_IRQHI); + } + saa7146_write (saa, IER, saa7146_read (saa, IER) | MASK_03); + ttpci_budget_debiwrite (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, + CICONTROL_RESET); + + // success! + printk ("budget_ci: CI interface initialised\n"); + budget_ci->budget.ci_present = 1; + + // forge a fake CI IRQ so the CAM state is setup correctly + flags = DVB_CA_EN50221_CAMCHANGE_REMOVED; + if (budget_ci->slot_status != SLOTSTATUS_NONE) + flags = DVB_CA_EN50221_CAMCHANGE_INSERTED; + dvb_ca_en50221_camchange_irq (&budget_ci->ca, 0, flags); + + return 0; + + error: + saa7146_write (saa, MC1, saa7146_read (saa, MC1) | (0x800 << 16)); + return result; } -static void ciintf_deinit(struct budget_ci* budget_ci) +static void ciintf_deinit (struct budget_ci *budget_ci) { - struct saa7146_dev *saa = budget_ci->budget.dev; + struct saa7146_dev *saa = budget_ci->budget.dev; - // disable CI interrupts - saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03); - saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT); - tasklet_kill(&budget_ci->ciintf_irq_tasklet); - budget_debiwrite(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1, 0); - msleep(1); - budget_debiwrite(budget_ci, DEBICICTL, DEBIADDR_CICONTROL, 1, CICONTROL_RESET); + // disable CI interrupts + saa7146_write (saa, IER, saa7146_read (saa, IER) & ~MASK_03); + saa7146_setgpio (saa, 0, SAA7146_GPIO_INPUT); + tasklet_kill (&budget_ci->ciintf_irq_tasklet); + ttpci_budget_debiwrite (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, 0); + msleep (1); + ttpci_budget_debiwrite (&budget_ci->budget, DEBICICTL, DEBIADDR_CICONTROL, 1, + CICONTROL_RESET); - // disable TS data stream to CI interface - saa7146_setgpio(saa, 1, SAA7146_GPIO_INPUT); + // disable TS data stream to CI interface + saa7146_setgpio (saa, 1, SAA7146_GPIO_INPUT); - // release the CA device - dvb_ca_en50221_release(&budget_ci->ca); + // release the CA device + dvb_ca_en50221_release (&budget_ci->ca); - // disable DEBI pins - saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16)); + // disable DEBI pins + saa7146_write (saa, MC1, saa7146_read (saa, MC1) | (0x800 << 16)); } -static void budget_ci_irq (struct saa7146_dev *dev, u32 *isr) +static void budget_ci_irq (struct saa7146_dev *dev, u32 * isr) { - struct budget_ci *budget_ci = (struct budget_ci*) dev->ext_priv; + struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv; - dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci); + dprintk (8, "dev: %p, budget_ci: %p\n", dev, budget_ci); - if (*isr & MASK_06) - tasklet_schedule (&budget_ci->msp430_irq_tasklet); + if (*isr & MASK_06) + tasklet_schedule (&budget_ci->msp430_irq_tasklet); - if (*isr & MASK_10) - ttpci_budget_irq10_handler (dev, isr); + if (*isr & MASK_10) + ttpci_budget_irq10_handler (dev, isr); - if ((*isr & MASK_03) && (budget_ci->budget.ci_present)) - tasklet_schedule (&budget_ci->ciintf_irq_tasklet); + if ((*isr & MASK_03) && (budget_ci->budget.ci_present)) + tasklet_schedule (&budget_ci->ciintf_irq_tasklet); } static u8 alps_bsru6_inittab[] = { - 0x01, 0x15, - 0x02, 0x00, - 0x03, 0x00, - 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ - 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ - 0x06, 0x40, /* DAC not used, set to high impendance mode */ - 0x07, 0x00, /* DAC LSB */ - 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */ - 0x09, 0x00, /* FIFO */ - 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ - 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ - 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ - 0x10, 0x3f, // AGC2 0x3d - 0x11, 0x84, - 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on - 0x15, 0xc9, // lock detector threshold - 0x16, 0x00, - 0x17, 0x00, - 0x18, 0x00, - 0x19, 0x00, - 0x1a, 0x00, - 0x1f, 0x50, - 0x20, 0x00, - 0x21, 0x00, - 0x22, 0x00, - 0x23, 0x00, - 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 - 0x29, 0x1e, // 1/2 threshold - 0x2a, 0x14, // 2/3 threshold - 0x2b, 0x0f, // 3/4 threshold - 0x2c, 0x09, // 5/6 threshold - 0x2d, 0x05, // 7/8 threshold - 0x2e, 0x01, - 0x31, 0x1f, // test all FECs - 0x32, 0x19, // viterbi and synchro search - 0x33, 0xfc, // rs control - 0x34, 0x93, // error control - 0x0f, 0x52, - 0xff, 0xff + 0x01, 0x15, + 0x02, 0x00, + 0x03, 0x00, + 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ + 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ + 0x06, 0x40, /* DAC not used, set to high impendance mode */ + 0x07, 0x00, /* DAC LSB */ + 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */ + 0x09, 0x00, /* FIFO */ + 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ + 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ + 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ + 0x10, 0x3f, // AGC2 0x3d + 0x11, 0x84, + 0x12, 0xb5, // Lock detect: -64 Carrier freq detect:on + 0x15, 0xc9, // lock detector threshold + 0x16, 0x00, + 0x17, 0x00, + 0x18, 0x00, + 0x19, 0x00, + 0x1a, 0x00, + 0x1f, 0x50, + 0x20, 0x00, + 0x21, 0x00, + 0x22, 0x00, + 0x23, 0x00, + 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0 + 0x29, 0x1e, // 1/2 threshold + 0x2a, 0x14, // 2/3 threshold + 0x2b, 0x0f, // 3/4 threshold + 0x2c, 0x09, // 5/6 threshold + 0x2d, 0x05, // 7/8 threshold + 0x2e, 0x01, + 0x31, 0x1f, // test all FECs + 0x32, 0x19, // viterbi and synchro search + 0x33, 0xfc, // rs control + 0x34, 0x93, // error control + 0x0f, 0x52, + 0xff, 0xff }; -static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio) +static int alps_bsru6_set_symbol_rate (struct dvb_frontend *fe, u32 srate, + u32 ratio) { - u8 aclk = 0; - u8 bclk = 0; - - if (srate < 1500000) { aclk = 0xb7; bclk = 0x47; } - else if (srate < 3000000) { aclk = 0xb7; bclk = 0x4b; } - else if (srate < 7000000) { aclk = 0xb7; bclk = 0x4f; } - else if (srate < 14000000) { aclk = 0xb7; bclk = 0x53; } - else if (srate < 30000000) { aclk = 0xb6; bclk = 0x53; } - else if (srate < 45000000) { aclk = 0xb4; bclk = 0x51; } - - stv0299_writereg (fe, 0x13, aclk); - stv0299_writereg (fe, 0x14, bclk); - stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); - stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); - stv0299_writereg (fe, 0x21, (ratio ) & 0xf0); - - return 0; + u8 aclk = 0; + u8 bclk = 0; + + if (srate < 1500000) { + aclk = 0xb7; + bclk = 0x47; + } else if (srate < 3000000) { + aclk = 0xb7; + bclk = 0x4b; + } else if (srate < 7000000) { + aclk = 0xb7; + bclk = 0x4f; + } else if (srate < 14000000) { + aclk = 0xb7; + bclk = 0x53; + } else if (srate < 30000000) { + aclk = 0xb6; + bclk = 0x53; + } else if (srate < 45000000) { + aclk = 0xb4; + bclk = 0x51; + } + + stv0299_writereg (fe, 0x13, aclk); + stv0299_writereg (fe, 0x14, bclk); + stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); + stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); + stv0299_writereg (fe, 0x21, (ratio) & 0xf0); + + return 0; } -static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) +static int alps_bsru6_pll_set (struct dvb_frontend *fe, + struct dvb_frontend_parameters *params) { - struct budget_ci* budget_ci = (struct budget_ci*) fe->dvb->priv; - u8 buf[4]; - u32 div; - struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; - - if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL; - - div = (params->frequency + (125 - 1)) / 125; // round correctly - buf[0] = (div >> 8) & 0x7f; - buf[1] = div & 0xff; - buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4; - buf[3] = 0xC4; - - if (params->frequency > 1530000) buf[3] = 0xc0; - - if (i2c_transfer (&budget_ci->budget.i2c_adap, &msg, 1) != 1) return -EIO; - return 0; + struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + u8 buf[4]; + u32 div; + struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof (buf) }; + + if ((params->frequency < 950000) || (params->frequency > 2150000)) + return -EINVAL; + + div = (params->frequency + (125 - 1)) / 125; // round correctly + buf[0] = (div >> 8) & 0x7f; + buf[1] = div & 0xff; + buf[2] = 0x80 | ((div & 0x18000) >> 10) | 4; + buf[3] = 0xC4; + + if (params->frequency > 1530000) + buf[3] = 0xc0; + + if (i2c_transfer (&budget_ci->budget.i2c_adap, &msg, 1) != 1) + return -EIO; + return 0; } static struct stv0299_config alps_bsru6_config = { - .demod_address = 0x68, - .inittab = alps_bsru6_inittab, - .mclk = 88000000UL, - .invert = 1, - .enhanced_tuning = 0, - .skip_reinit = 0, - .lock_output = STV0229_LOCKOUTPUT_1, - .volt13_op0_op1 = STV0299_VOLT13_OP1, - .min_delay_ms = 100, - .set_symbol_rate = alps_bsru6_set_symbol_rate, - .pll_set = alps_bsru6_pll_set, + .demod_address = 0x68, + .inittab = alps_bsru6_inittab, + .mclk = 88000000UL, + .invert = 1, + .enhanced_tuning = 0, + .skip_reinit = 0, + .lock_output = STV0229_LOCKOUTPUT_1, + .volt13_op0_op1 = STV0299_VOLT13_OP1, + .min_delay_ms = 100, + .set_symbol_rate = alps_bsru6_set_symbol_rate, + .pll_set = alps_bsru6_pll_set, }; static u8 philips_su1278_tt_inittab[] = { - 0x01, 0x0f, - 0x02, 0x30, - 0x03, 0x00, - 0x04, 0x5b, - 0x05, 0x85, - 0x06, 0x02, - 0x07, 0x00, - 0x08, 0x02, - 0x09, 0x00, - 0x0C, 0x01, - 0x0D, 0x81, - 0x0E, 0x44, - 0x0f, 0x14, - 0x10, 0x3c, - 0x11, 0x84, - 0x12, 0xda, - 0x13, 0x97, - 0x14, 0x95, - 0x15, 0xc9, - 0x16, 0x19, - 0x17, 0x8c, - 0x18, 0x59, - 0x19, 0xf8, - 0x1a, 0xfe, - 0x1c, 0x7f, - 0x1d, 0x00, - 0x1e, 0x00, - 0x1f, 0x50, - 0x20, 0x00, - 0x21, 0x00, - 0x22, 0x00, - 0x23, 0x00, - 0x28, 0x00, - 0x29, 0x28, - 0x2a, 0x14, - 0x2b, 0x0f, - 0x2c, 0x09, - 0x2d, 0x09, - 0x31, 0x1f, - 0x32, 0x19, - 0x33, 0xfc, - 0x34, 0x93, - 0xff, 0xff + 0x01, 0x0f, + 0x02, 0x30, + 0x03, 0x00, + 0x04, 0x5b, + 0x05, 0x85, + 0x06, 0x02, + 0x07, 0x00, + 0x08, 0x02, + 0x09, 0x00, + 0x0C, 0x01, + 0x0D, 0x81, + 0x0E, 0x44, + 0x0f, 0x14, + 0x10, 0x3c, + 0x11, 0x84, + 0x12, 0xda, + 0x13, 0x97, + 0x14, 0x95, + 0x15, 0xc9, + 0x16, 0x19, + 0x17, 0x8c, + 0x18, 0x59, + 0x19, 0xf8, + 0x1a, 0xfe, + 0x1c, 0x7f, + 0x1d, 0x00, + 0x1e, 0x00, + 0x1f, 0x50, + 0x20, 0x00, + 0x21, 0x00, + 0x22, 0x00, + 0x23, 0x00, + 0x28, 0x00, + 0x29, 0x28, + 0x2a, 0x14, + 0x2b, 0x0f, + 0x2c, 0x09, + 0x2d, 0x09, + 0x31, 0x1f, + 0x32, 0x19, + 0x33, 0xfc, + 0x34, 0x93, + 0xff, 0xff }; -static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ratio) +static int philips_su1278_tt_set_symbol_rate (struct dvb_frontend *fe, + u32 srate, u32 ratio) { - stv0299_writereg (fe, 0x0e, 0x44); - if (srate >= 10000000) { - stv0299_writereg (fe, 0x13, 0x97); - stv0299_writereg (fe, 0x14, 0x95); - stv0299_writereg (fe, 0x15, 0xc9); - stv0299_writereg (fe, 0x17, 0x8c); - stv0299_writereg (fe, 0x1a, 0xfe); - stv0299_writereg (fe, 0x1c, 0x7f); - stv0299_writereg (fe, 0x2d, 0x09); - } else { - stv0299_writereg (fe, 0x13, 0x99); - stv0299_writereg (fe, 0x14, 0x8d); - stv0299_writereg (fe, 0x15, 0xce); - stv0299_writereg (fe, 0x17, 0x43); - stv0299_writereg (fe, 0x1a, 0x1d); - stv0299_writereg (fe, 0x1c, 0x12); - stv0299_writereg (fe, 0x2d, 0x05); - } - stv0299_writereg (fe, 0x0e, 0x23); - stv0299_writereg (fe, 0x0f, 0x94); - stv0299_writereg (fe, 0x10, 0x39); - stv0299_writereg (fe, 0x15, 0xc9); - - stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); - stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); - stv0299_writereg (fe, 0x21, (ratio ) & 0xf0); - - return 0; + stv0299_writereg (fe, 0x0e, 0x44); + if (srate >= 10000000) { + stv0299_writereg (fe, 0x13, 0x97); + stv0299_writereg (fe, 0x14, 0x95); + stv0299_writereg (fe, 0x15, 0xc9); + stv0299_writereg (fe, 0x17, 0x8c); + stv0299_writereg (fe, 0x1a, 0xfe); + stv0299_writereg (fe, 0x1c, 0x7f); + stv0299_writereg (fe, 0x2d, 0x09); + } else { + stv0299_writereg (fe, 0x13, 0x99); + stv0299_writereg (fe, 0x14, 0x8d); + stv0299_writereg (fe, 0x15, 0xce); + stv0299_writereg (fe, 0x17, 0x43); + stv0299_writereg (fe, 0x1a, 0x1d); + stv0299_writereg (fe, 0x1c, 0x12); + stv0299_writereg (fe, 0x2d, 0x05); + } + stv0299_writereg (fe, 0x0e, 0x23); + stv0299_writereg (fe, 0x0f, 0x94); + stv0299_writereg (fe, 0x10, 0x39); + stv0299_writereg (fe, 0x15, 0xc9); + + stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff); + stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff); + stv0299_writereg (fe, 0x21, (ratio) & 0xf0); + + return 0; } -static int philips_su1278_tt_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) +static int philips_su1278_tt_pll_set (struct dvb_frontend *fe, + struct dvb_frontend_parameters *params) { - struct budget_ci* budget_ci = (struct budget_ci*) fe->dvb->priv; - u32 div; - u8 buf[4]; - struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf) }; - - if ((params->frequency < 950000) || (params->frequency > 2150000)) return -EINVAL; - - div = (params->frequency + (500 - 1)) / 500; // round correctly - buf[0] = (div >> 8) & 0x7f; - buf[1] = div & 0xff; - buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2; - buf[3] = 0x20; - - if (params->u.qpsk.symbol_rate < 4000000) buf[3] |= 1; - - if (params->frequency < 1250000) buf[3] |= 0; - else if (params->frequency < 1550000) buf[3] |= 0x40; - else if (params->frequency < 2050000) buf[3] |= 0x80; - else if (params->frequency < 2150000) buf[3] |= 0xC0; - - if (i2c_transfer (&budget_ci->budget.i2c_adap, &msg, 1) != 1) return -EIO; - return 0; + struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + u32 div; + u8 buf[4]; + struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof (buf) }; + + if ((params->frequency < 950000) || (params->frequency > 2150000)) + return -EINVAL; + + div = (params->frequency + (500 - 1)) / 500; // round correctly + buf[0] = (div >> 8) & 0x7f; + buf[1] = div & 0xff; + buf[2] = 0x80 | ((div & 0x18000) >> 10) | 2; + buf[3] = 0x20; + + if (params->u.qpsk.symbol_rate < 4000000) + buf[3] |= 1; + + if (params->frequency < 1250000) + buf[3] |= 0; + else if (params->frequency < 1550000) + buf[3] |= 0x40; + else if (params->frequency < 2050000) + buf[3] |= 0x80; + else if (params->frequency < 2150000) + buf[3] |= 0xC0; + + if (i2c_transfer (&budget_ci->budget.i2c_adap, &msg, 1) != 1) + return -EIO; + return 0; } static struct stv0299_config philips_su1278_tt_config = { - .demod_address = 0x68, - .inittab = philips_su1278_tt_inittab, - .mclk = 64000000UL, - .invert = 0, - .enhanced_tuning = 1, - .skip_reinit = 1, - .lock_output = STV0229_LOCKOUTPUT_1, - .volt13_op0_op1 = STV0299_VOLT13_OP1, - .min_delay_ms = 50, - .set_symbol_rate = philips_su1278_tt_set_symbol_rate, - .pll_set = philips_su1278_tt_pll_set, + .demod_address = 0x68, + .inittab = philips_su1278_tt_inittab, + .mclk = 64000000UL, + .invert = 0, + .enhanced_tuning = 1, + .skip_reinit = 1, + .lock_output = STV0229_LOCKOUTPUT_1, + .volt13_op0_op1 = STV0299_VOLT13_OP1, + .min_delay_ms = 50, + .set_symbol_rate = philips_su1278_tt_set_symbol_rate, + .pll_set = philips_su1278_tt_pll_set, }; -static int philips_tdm1316l_pll_init(struct dvb_frontend* fe) +static int philips_tdm1316l_pll_init (struct dvb_frontend *fe) { - struct budget_ci* budget_ci = (struct budget_ci*) fe->dvb->priv; - static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab }; - static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 }; - struct i2c_msg tuner_msg = { .addr=0x63, .flags=0, .buf=td1316_init, .len=sizeof(td1316_init) }; - - // setup PLL configuration - if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) return -EIO; - msleep(1); - - // disable the mc44BC374c (do not check for errors) - tuner_msg.addr = 0x65; - tuner_msg.buf = disable_mc44BC374c; - tuner_msg.len = sizeof(disable_mc44BC374c); - if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) { - i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1); - } - - return 0; + struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab }; + static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 }; + struct i2c_msg tuner_msg = {.addr = 0x63,.flags = 0,.buf = td1316_init,.len = sizeof (td1316_init) }; + + // setup PLL configuration + if (i2c_transfer (&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) + return -EIO; + msleep (1); + + // disable the mc44BC374c (do not check for errors) + tuner_msg.addr = 0x65; + tuner_msg.buf = disable_mc44BC374c; + tuner_msg.len = sizeof (disable_mc44BC374c); + if (i2c_transfer (&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) { + i2c_transfer (&budget_ci->budget.i2c_adap, &tuner_msg, 1); + } + + return 0; } -static int philips_tdm1316l_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) +static int philips_tdm1316l_pll_set (struct dvb_frontend *fe, + struct dvb_frontend_parameters *params) { - struct budget_ci* budget_ci = (struct budget_ci*) fe->dvb->priv; - u8 tuner_buf[4]; - struct i2c_msg tuner_msg = {.addr=0x63, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) }; - int tuner_frequency = 0; - u8 band, cp, filter; - - // determine charge pump - tuner_frequency = params->frequency + 36130000; - if (tuner_frequency < 87000000) return -EINVAL; - else if (tuner_frequency < 130000000) cp = 3; - else if (tuner_frequency < 160000000) cp = 5; - else if (tuner_frequency < 200000000) cp = 6; - else if (tuner_frequency < 290000000) cp = 3; - else if (tuner_frequency < 420000000) cp = 5; - else if (tuner_frequency < 480000000) cp = 6; - else if (tuner_frequency < 620000000) cp = 3; - else if (tuner_frequency < 830000000) cp = 5; - else if (tuner_frequency < 895000000) cp = 7; - else return -EINVAL; - - // determine band - if (params->frequency < 49000000) return -EINVAL; - else if (params->frequency < 159000000) band = 1; - else if (params->frequency < 444000000) band = 2; - else if (params->frequency < 861000000) band = 4; - else return -EINVAL; - - // setup PLL filter and TDA9889 - switch (params->u.ofdm.bandwidth) { - case BANDWIDTH_6_MHZ: - tda1004x_write_byte(fe, 0x0C, 0x14); - filter = 0; - break; - - case BANDWIDTH_7_MHZ: - tda1004x_write_byte(fe, 0x0C, 0x80); - filter = 0; - break; - - case BANDWIDTH_8_MHZ: - tda1004x_write_byte(fe, 0x0C, 0x14); - filter = 1; - break; - - default: - return -EINVAL; - } - - // calculate divisor - // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6) - tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000; - - // setup tuner buffer - tuner_buf[0] = tuner_frequency >> 8; - tuner_buf[1] = tuner_frequency & 0xff; - tuner_buf[2] = 0xca; - tuner_buf[3] = (cp << 5) | (filter << 3) | band; - - if (i2c_transfer(&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) return -EIO; - - msleep(1); - return 0; + struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + u8 tuner_buf[4]; + struct i2c_msg tuner_msg = {.addr = 0x63,.flags = 0,.buf = tuner_buf,.len = sizeof (tuner_buf) }; + int tuner_frequency = 0; + u8 band, cp, filter; + + // determine charge pump + tuner_frequency = params->frequency + 36130000; + if (tuner_frequency < 87000000) + return -EINVAL; + else if (tuner_frequency < 130000000) + cp = 3; + else if (tuner_frequency < 160000000) + cp = 5; + else if (tuner_frequency < 200000000) + cp = 6; + else if (tuner_frequency < 290000000) + cp = 3; + else if (tuner_frequency < 420000000) + cp = 5; + else if (tuner_frequency < 480000000) + cp = 6; + else if (tuner_frequency < 620000000) + cp = 3; + else if (tuner_frequency < 830000000) + cp = 5; + else if (tuner_frequency < 895000000) + cp = 7; + else + return -EINVAL; + + // determine band + if (params->frequency < 49000000) + return -EINVAL; + else if (params->frequency < 159000000) + band = 1; + else if (params->frequency < 444000000) + band = 2; + else if (params->frequency < 861000000) + band = 4; + else + return -EINVAL; + + // setup PLL filter and TDA9889 + switch (params->u.ofdm.bandwidth) { + case BANDWIDTH_6_MHZ: + tda1004x_write_byte (fe, 0x0C, 0x14); + filter = 0; + break; + + case BANDWIDTH_7_MHZ: + tda1004x_write_byte (fe, 0x0C, 0x80); + filter = 0; + break; + + case BANDWIDTH_8_MHZ: + tda1004x_write_byte (fe, 0x0C, 0x14); + filter = 1; + break; + + default: + return -EINVAL; + } + + // calculate divisor + // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6) + tuner_frequency = (((params->frequency / 1000) * 6) + 217280) / 1000; + + // setup tuner buffer + tuner_buf[0] = tuner_frequency >> 8; + tuner_buf[1] = tuner_frequency & 0xff; + tuner_buf[2] = 0xca; + tuner_buf[3] = (cp << 5) | (filter << 3) | band; + + if (i2c_transfer (&budget_ci->budget.i2c_adap, &tuner_msg, 1) != 1) + return -EIO; + + msleep (1); + return 0; } -static int philips_tdm1316l_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) +static int philips_tdm1316l_request_firmware (struct dvb_frontend *fe, + const struct firmware **fw, + char *name) { - struct budget_ci* budget_ci = (struct budget_ci*) fe->dvb->priv; + struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; - return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev); + return request_firmware (fw, name, &budget_ci->budget.dev->pci->dev); } struct tda1004x_config philips_tdm1316l_config = { - .demod_address = 0x8, - .invert = 0, - .pll_init = philips_tdm1316l_pll_init, - .pll_set = philips_tdm1316l_pll_set, - .request_firmware = philips_tdm1316l_request_firmware, + .demod_address = 0x8, + .invert = 0, + .pll_init = philips_tdm1316l_pll_init, + .pll_set = philips_tdm1316l_pll_set, + .request_firmware = philips_tdm1316l_request_firmware, }; -static void frontend_init(struct budget_ci *budget_ci) -{ - switch(budget_ci->budget.dev->pci->subsystem_device) { - case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059)) - budget_ci->budget.dvb_frontend = stv0299_attach(&alps_bsru6_config, &budget_ci->budget.i2c_adap); - if (budget_ci->budget.dvb_frontend) { - break; - } - break; - - case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059)) - budget_ci->budget.dvb_frontend = stv0299_attach(&philips_su1278_tt_config, &budget_ci->budget.i2c_adap); - if (budget_ci->budget.dvb_frontend) { - break; - } - break; - - case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889) - budget_ci->budget.dvb_frontend = tda10045_attach(&philips_tdm1316l_config, &budget_ci->budget.i2c_adap); - if (budget_ci->budget.dvb_frontend) { - break; - } - break; - } - - if (budget_ci->budget.dvb_frontend == NULL) { - printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", - budget_ci->budget.dev->pci->vendor, - budget_ci->budget.dev->pci->device, - budget_ci->budget.dev->pci->subsystem_vendor, - budget_ci->budget.dev->pci->subsystem_device); - } else { - if (dvb_register_frontend(budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) { - printk("budget-ci: Frontend registration failed!\n"); - if (budget_ci->budget.dvb_frontend->ops->release) - budget_ci->budget.dvb_frontend->ops->release(budget_ci->budget.dvb_frontend); - budget_ci->budget.dvb_frontend = NULL; - } - } +static void frontend_init (struct budget_ci *budget_ci) +{ + switch (budget_ci->budget.dev->pci->subsystem_device) { + case 0x100c: // Hauppauge/TT Nova-CI budget (stv0299/ALPS BSRU6(tsa5059)) + budget_ci->budget.dvb_frontend = + stv0299_attach (&alps_bsru6_config, + &budget_ci->budget.i2c_adap); + if (budget_ci->budget.dvb_frontend) { + break; + } + break; + + case 0x100f: // Hauppauge/TT Nova-CI budget (stv0299b/Philips su1278(tsa5059)) + budget_ci->budget.dvb_frontend = + stv0299_attach (&philips_su1278_tt_config, + &budget_ci->budget.i2c_adap); + if (budget_ci->budget.dvb_frontend) { + break; + } + break; + + case 0x1011: // Hauppauge/TT Nova-T budget (tda10045/Philips tdm1316l(tda6651tt) + TDA9889) + budget_ci->budget.dvb_frontend = + tda10045_attach (&philips_tdm1316l_config, + &budget_ci->budget.i2c_adap); + if (budget_ci->budget.dvb_frontend) { + break; + } + break; + } + + if (budget_ci->budget.dvb_frontend == NULL) { + printk ("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", + budget_ci->budget.dev->pci->vendor, + budget_ci->budget.dev->pci->device, + budget_ci->budget.dev->pci->subsystem_vendor, + budget_ci->budget.dev->pci->subsystem_device); + } else { + if (dvb_register_frontend(budget_ci->budget.dvb_adapter, budget_ci->budget.dvb_frontend)) { + printk ("budget-ci: Frontend registration failed!\n"); + if (budget_ci->budget.dvb_frontend->ops->release) + budget_ci->budget.dvb_frontend->ops->release (budget_ci->budget.dvb_frontend); + budget_ci->budget.dvb_frontend = NULL; + } + } } -static int budget_ci_attach (struct saa7146_dev* dev, - struct saa7146_pci_extension_data *info) +static int budget_ci_attach (struct saa7146_dev *dev, + struct saa7146_pci_extension_data *info) { - struct budget_ci *budget_ci; - int err; - - if (!(budget_ci = kmalloc (sizeof(struct budget_ci), GFP_KERNEL))) - return -ENOMEM; + struct budget_ci *budget_ci; + int err; - dprintk(2, "budget_ci: %p\n", budget_ci); + if (!(budget_ci = kmalloc (sizeof (struct budget_ci), GFP_KERNEL))) + return -ENOMEM; - spin_lock_init(&budget_ci->debilock); - budget_ci->budget.ci_present = 0; + dprintk (2, "budget_ci: %p\n", budget_ci); - dev->ext_priv = budget_ci; + budget_ci->budget.ci_present = 0; - if ((err = ttpci_budget_init (&budget_ci->budget, dev, info))) { - kfree (budget_ci); - return err; - } + dev->ext_priv = budget_ci; - tasklet_init (&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt, - (unsigned long) budget_ci); + if ((err = ttpci_budget_init (&budget_ci->budget, dev, info))) { + kfree (budget_ci); + return err; + } - msp430_ir_init (budget_ci); + tasklet_init (&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt, + (unsigned long) budget_ci); - ciintf_init(budget_ci); + msp430_ir_init (budget_ci); - budget_ci->budget.dvb_adapter->priv = budget_ci; - frontend_init(budget_ci); + ciintf_init (budget_ci); - return 0; + budget_ci->budget.dvb_adapter->priv = budget_ci; + frontend_init (budget_ci); + + return 0; } -static int budget_ci_detach (struct saa7146_dev* dev) +static int budget_ci_detach (struct saa7146_dev *dev) { - struct budget_ci *budget_ci = (struct budget_ci*) dev->ext_priv; - struct saa7146_dev *saa = budget_ci->budget.dev; - int err; + struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv; + struct saa7146_dev *saa = budget_ci->budget.dev; + int err; - if (budget_ci->budget.ci_present) ciintf_deinit(budget_ci); - if (budget_ci->budget.dvb_frontend) dvb_unregister_frontend(budget_ci->budget.dvb_frontend); - err = ttpci_budget_deinit (&budget_ci->budget); + if (budget_ci->budget.ci_present) + ciintf_deinit (budget_ci); + if (budget_ci->budget.dvb_frontend) + dvb_unregister_frontend (budget_ci->budget.dvb_frontend); + err = ttpci_budget_deinit (&budget_ci->budget); - tasklet_kill (&budget_ci->msp430_irq_tasklet); + tasklet_kill (&budget_ci->msp430_irq_tasklet); - msp430_ir_deinit (budget_ci); + msp430_ir_deinit (budget_ci); - // disable frontend and CI interface - saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT); + // disable frontend and CI interface + saa7146_setgpio (saa, 2, SAA7146_GPIO_INPUT); - kfree (budget_ci); + kfree (budget_ci); - return err; + return err; } static struct saa7146_extension budget_extension; -MAKE_BUDGET_INFO(ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC); -MAKE_BUDGET_INFO(ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); +MAKE_BUDGET_INFO (ttbci, "TT-Budget/WinTV-NOVA-CI PCI", BUDGET_TT_HW_DISEQC); +MAKE_BUDGET_INFO (ttbt2, "TT-Budget/WinTV-NOVA-T PCI", BUDGET_TT); static struct pci_device_id pci_tbl[] = { - MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c), - MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f), - MAKE_EXTENSION_PCI(ttbt2, 0x13c2, 0x1011), - { - .vendor = 0, - } + MAKE_EXTENSION_PCI (ttbci, 0x13c2, 0x100c), + MAKE_EXTENSION_PCI (ttbci, 0x13c2, 0x100f), + MAKE_EXTENSION_PCI (ttbt2, 0x13c2, 0x1011), + { + .vendor = 0, + } }; -MODULE_DEVICE_TABLE(pci, pci_tbl); +MODULE_DEVICE_TABLE (pci, pci_tbl); static struct saa7146_extension budget_extension = { - .name = "budget_ci dvb\0", - .flags = 0, + .name = "budget_ci dvb\0", + .flags = 0, - .module = THIS_MODULE, - .pci_tbl = &pci_tbl[0], - .attach = budget_ci_attach, - .detach = budget_ci_detach, + .module = THIS_MODULE, + .pci_tbl = &pci_tbl[0], + .attach = budget_ci_attach, + .detach = budget_ci_detach, - .irq_mask = MASK_03 | MASK_06 | MASK_10, - .irq_func = budget_ci_irq, + .irq_mask = MASK_03 | MASK_06 | MASK_10, + .irq_func = budget_ci_irq, }; -static int __init budget_ci_init(void) +static int __init budget_ci_init (void) { - return saa7146_register_extension(&budget_extension); + return saa7146_register_extension (&budget_extension); } -static void __exit budget_ci_exit(void) +static void __exit budget_ci_exit (void) { - saa7146_unregister_extension(&budget_extension); + saa7146_unregister_extension (&budget_extension); } -module_init(budget_ci_init); -module_exit(budget_ci_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Michael Hunold, Jack Thomasson, Andrew de Quincey, others"); -MODULE_DESCRIPTION("driver for the SAA7146 based so-called " - "budget PCI DVB cards w/ CI-module produced by " - "Siemens, Technotrend, Hauppauge"); +module_init (budget_ci_init); +module_exit (budget_ci_exit); +MODULE_LICENSE ("GPL"); +MODULE_AUTHOR ("Michael Hunold, Jack Thomasson, Andrew de Quincey, others"); +MODULE_DESCRIPTION ("driver for the SAA7146 based so-called " + "budget PCI DVB cards w/ CI-module produced by " + "Siemens, Technotrend, Hauppauge"); diff --git a/linux/drivers/media/dvb/ttpci/budget-core.c b/linux/drivers/media/dvb/ttpci/budget-core.c index 7334119a4..86c7d2b93 100644 --- a/linux/drivers/media/dvb/ttpci/budget-core.c +++ b/linux/drivers/media/dvb/ttpci/budget-core.c @@ -40,359 +40,434 @@ #include "ttpci-eeprom.h" int budget_debug; -module_param_named(debug, budget_debug, int, 0644); -MODULE_PARM_DESC(budget_debug, "Turn on/off budget debugging (default:off)."); +module_param_named (debug, budget_debug, int, 0644); +MODULE_PARM_DESC (budget_debug, "Turn on/off budget debugging (default:off)."); /**************************************************************************** * TT budget / WinTV Nova ****************************************************************************/ -static int stop_ts_capture(struct budget *budget) +static int stop_ts_capture (struct budget *budget) { - dprintk(2, "budget: %p\n", budget); + dprintk (2, "budget: %p\n", budget); - if (--budget->feeding) - return budget->feeding; + if (--budget->feeding) + return budget->feeding; - saa7146_write(budget->dev, MC1, MASK_20); // DMA3 off - IER_DISABLE(budget->dev, MASK_10); - return 0; + saa7146_write (budget->dev, MC1, MASK_20); // DMA3 off + IER_DISABLE (budget->dev, MASK_10); + return 0; } static int start_ts_capture (struct budget *budget) { - struct saa7146_dev *dev=budget->dev; - - dprintk(2, "budget: %p\n", budget); - - if (budget->feeding) - return ++budget->feeding; - - saa7146_write(dev, MC1, MASK_20); // DMA3 off - - memset(budget->grabbing, 0x00, TS_HEIGHT*TS_WIDTH); - - saa7146_write(dev, PCI_BT_V1, 0x001c0000 | - (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000)); - - budget->tsf=0xff; - budget->ttbp=0; - - /* - * Signal path on the Activy: - * - * tuner -> SAA7146 port A -> SAA7146 BRS -> SAA7146 DMA3 -> memory - * - * Since the tuner feeds 204 bytes packets into the SAA7146, - * DMA3 is configured to strip the trailing 16 FEC bytes: - * Pitch: 188, NumBytes3: 188, NumLines3: 1024 - */ - - if (budget->card->type == BUDGET_FS_ACTIVY) { - saa7146_write(dev, DD1_INIT, 0x04000000); - saa7146_write(dev, MC2, (MASK_09 | MASK_25)); - saa7146_write(dev, BRS_CTRL, 0x00000000); - } else { - if (budget->video_port == BUDGET_VIDEO_PORTA) { - saa7146_write(dev, DD1_INIT, 0x06000200); - saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); - saa7146_write(dev, BRS_CTRL, 0x00000000); - } else { - saa7146_write(dev, DD1_INIT, 0x02000600); - saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); - saa7146_write(dev, BRS_CTRL, 0x60000000); - } - } - - saa7146_write(dev, MC2, (MASK_08 | MASK_24)); - mdelay(10); - - saa7146_write(dev, BASE_ODD3, 0); - saa7146_write(dev, BASE_EVEN3, 0); - saa7146_write(dev, PROT_ADDR3, TS_WIDTH*TS_HEIGHT); - saa7146_write(dev, BASE_PAGE3, budget->pt.dma |ME1|0x90); - - if (budget->card->type == BUDGET_FS_ACTIVY) { - saa7146_write(dev, PITCH3, TS_WIDTH/2); - saa7146_write(dev, NUM_LINE_BYTE3, ((TS_HEIGHT*2)<<16)|(TS_WIDTH/2)); - } else { - saa7146_write(dev, PITCH3, TS_WIDTH); - saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT<<16)|TS_WIDTH); - } - - saa7146_write(dev, MC2, (MASK_04 | MASK_20)); - saa7146_write(dev, MC1, (MASK_04 | MASK_20)); // DMA3 on - - IER_ENABLE(budget->dev, MASK_10); // VPE - - return ++budget->feeding; + struct saa7146_dev *dev = budget->dev; + + dprintk (2, "budget: %p\n", budget); + + if (budget->feeding) + return ++budget->feeding; + + saa7146_write (dev, MC1, MASK_20); // DMA3 off + + memset (budget->grabbing, 0x00, TS_HEIGHT * TS_WIDTH); + + saa7146_write (dev, PCI_BT_V1, 0x001c0000 | + (saa7146_read (dev, PCI_BT_V1) & ~0x001f0000)); + + budget->tsf = 0xff; + budget->ttbp = 0; + + /* + * Signal path on the Activy: + * + * tuner -> SAA7146 port A -> SAA7146 BRS -> SAA7146 DMA3 -> memory + * + * Since the tuner feeds 204 bytes packets into the SAA7146, + * DMA3 is configured to strip the trailing 16 FEC bytes: + * Pitch: 188, NumBytes3: 188, NumLines3: 1024 + */ + + if (budget->card->type == BUDGET_FS_ACTIVY) { + saa7146_write (dev, DD1_INIT, 0x04000000); + saa7146_write (dev, MC2, (MASK_09 | MASK_25)); + saa7146_write (dev, BRS_CTRL, 0x00000000); + } else { + if (budget->video_port == BUDGET_VIDEO_PORTA) { + saa7146_write (dev, DD1_INIT, 0x06000200); + saa7146_write (dev, MC2, + (MASK_09 | MASK_25 | MASK_10 | MASK_26)); + saa7146_write (dev, BRS_CTRL, 0x00000000); + } else { + saa7146_write (dev, DD1_INIT, 0x02000600); + saa7146_write (dev, MC2, + (MASK_09 | MASK_25 | MASK_10 | MASK_26)); + saa7146_write (dev, BRS_CTRL, 0x60000000); + } + } + + saa7146_write (dev, MC2, (MASK_08 | MASK_24)); + mdelay (10); + + saa7146_write (dev, BASE_ODD3, 0); + saa7146_write (dev, BASE_EVEN3, 0); + saa7146_write (dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT); + saa7146_write (dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90); + + if (budget->card->type == BUDGET_FS_ACTIVY) { + saa7146_write (dev, PITCH3, TS_WIDTH / 2); + saa7146_write (dev, NUM_LINE_BYTE3, + ((TS_HEIGHT * 2) << 16) | (TS_WIDTH / 2)); + } else { + saa7146_write (dev, PITCH3, TS_WIDTH); + saa7146_write (dev, NUM_LINE_BYTE3, + (TS_HEIGHT << 16) | TS_WIDTH); + } + + saa7146_write (dev, MC2, (MASK_04 | MASK_20)); + saa7146_write (dev, MC1, (MASK_04 | MASK_20)); // DMA3 on + + IER_ENABLE (budget->dev, MASK_10); // VPE + + return ++budget->feeding; } static void vpeirq (unsigned long data) { - struct budget *budget = (struct budget*) data; - u8 *mem = (u8 *)(budget->grabbing); - u32 olddma = budget->ttbp; - u32 newdma = saa7146_read(budget->dev, PCI_VDP3); - - /* nearest lower position divisible by 188 */ - newdma -= newdma % 188; - - if (newdma >= TS_BUFLEN) - return; - - budget->ttbp = newdma; - - if(budget->feeding == 0 || newdma == olddma) - return; - - if (newdma > olddma) { /* no wraparound, dump olddma..newdma */ - dvb_dmx_swfilter_packets(&budget->demux, - mem+olddma, (newdma-olddma) / 188); - } else { /* wraparound, dump olddma..buflen and 0..newdma */ - dvb_dmx_swfilter_packets(&budget->demux, - mem+olddma, (TS_BUFLEN-olddma) / 188); - dvb_dmx_swfilter_packets(&budget->demux, - mem, newdma / 188); - } + struct budget *budget = (struct budget *) data; + u8 *mem = (u8 *) (budget->grabbing); + u32 olddma = budget->ttbp; + u32 newdma = saa7146_read (budget->dev, PCI_VDP3); + + /* nearest lower position divisible by 188 */ + newdma -= newdma % 188; + + if (newdma >= TS_BUFLEN) + return; + + budget->ttbp = newdma; + + if (budget->feeding == 0 || newdma == olddma) + return; + + if (newdma > olddma) { /* no wraparound, dump olddma..newdma */ + dvb_dmx_swfilter_packets (&budget->demux, + mem + olddma, + (newdma - olddma) / 188); + } else { /* wraparound, dump olddma..buflen and 0..newdma */ + dvb_dmx_swfilter_packets (&budget->demux, + mem + olddma, + (TS_BUFLEN - olddma) / 188); + dvb_dmx_swfilter_packets (&budget->demux, mem, newdma / 188); + } } + +u32 ttpci_budget_debiread (struct budget *budget, u32 config, int addr, + int count) +{ + struct saa7146_dev *saa = budget->dev; + u32 result = 0; + unsigned long flags; + + if (count > 4 || count <= 0) + return 0; + + spin_lock_irqsave (&budget->debilock, flags); + + if (saa7146_wait_for_debi_done (saa) < 0) { + spin_unlock_irqrestore (&budget->debilock, flags); + return 0; + } + + saa7146_write (saa, DEBI_COMMAND, + (count << 17) | 0x10000 | (addr & 0xffff)); + saa7146_write (saa, DEBI_CONFIG, config); + saa7146_write (saa, DEBI_PAGE, 0); + saa7146_write (saa, MC2, (2 << 16) | 2); + + saa7146_wait_for_debi_done (saa); + + result = saa7146_read (saa, DEBI_AD); + result &= (0xffffffffUL >> ((4 - count) * 8)); + + spin_unlock_irqrestore (&budget->debilock, flags); + + return result; +} + +u8 ttpci_budget_debiwrite (struct budget *budget, u32 config, int addr, + int count, u32 value) +{ + struct saa7146_dev *saa = budget->dev; + unsigned long flags; + + if (count > 4 || count <= 0) + return 0; + + spin_lock_irqsave (&budget->debilock, flags); + + if (saa7146_wait_for_debi_done (saa) < 0) { + spin_unlock_irqrestore (&budget->debilock, flags); + return 0; + } + + saa7146_write (saa, DEBI_COMMAND, + (count << 17) | 0x00000 | (addr & 0xffff)); + saa7146_write (saa, DEBI_CONFIG, config); + saa7146_write (saa, DEBI_PAGE, 0); + saa7146_write (saa, DEBI_AD, value); + saa7146_write (saa, MC2, (2 << 16) | 2); + + saa7146_wait_for_debi_done (saa); + + spin_unlock_irqrestore (&budget->debilock, flags); + return 0; +} + + /**************************************************************************** * DVB API SECTION ****************************************************************************/ -static int budget_start_feed(struct dvb_demux_feed *feed) +static int budget_start_feed (struct dvb_demux_feed *feed) { - struct dvb_demux *demux = feed->demux; - struct budget *budget = (struct budget*) demux->priv; - int status; + struct dvb_demux *demux = feed->demux; + struct budget *budget = (struct budget *) demux->priv; + int status; - dprintk(2, "budget: %p\n", budget); + dprintk (2, "budget: %p\n", budget); - if (!demux->dmx.frontend) - return -EINVAL; + if (!demux->dmx.frontend) + return -EINVAL; - spin_lock(&budget->feedlock); - status = start_ts_capture (budget); - spin_unlock(&budget->feedlock); - return status; + spin_lock (&budget->feedlock); + status = start_ts_capture (budget); + spin_unlock (&budget->feedlock); + return status; } -static int budget_stop_feed(struct dvb_demux_feed *feed) +static int budget_stop_feed (struct dvb_demux_feed *feed) { - struct dvb_demux *demux = feed->demux; - struct budget *budget = (struct budget *) demux->priv; - int status; + struct dvb_demux *demux = feed->demux; + struct budget *budget = (struct budget *) demux->priv; + int status; - dprintk(2, "budget: %p\n", budget); + dprintk (2, "budget: %p\n", budget); - spin_lock(&budget->feedlock); - status = stop_ts_capture (budget); - spin_unlock(&budget->feedlock); - return status; + spin_lock (&budget->feedlock); + status = stop_ts_capture (budget); + spin_unlock (&budget->feedlock); + return status; } -static int budget_register(struct budget *budget) +static int budget_register (struct budget *budget) { - struct dvb_demux *dvbdemux = &budget->demux; - int ret; + struct dvb_demux *dvbdemux = &budget->demux; + int ret; - dprintk(2, "budget: %p\n", budget); + dprintk (2, "budget: %p\n", budget); - dvbdemux->priv = (void *) budget; + dvbdemux->priv = (void *) budget; - dvbdemux->filternum = 256; - dvbdemux->feednum = 256; - dvbdemux->start_feed = budget_start_feed; - dvbdemux->stop_feed = budget_stop_feed; - dvbdemux->write_to_decoder = NULL; + dvbdemux->filternum = 256; + dvbdemux->feednum = 256; + dvbdemux->start_feed = budget_start_feed; + dvbdemux->stop_feed = budget_stop_feed; + dvbdemux->write_to_decoder = NULL; - dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING | - DMX_MEMORY_BASED_FILTERING); + dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING | + DMX_MEMORY_BASED_FILTERING); - dvb_dmx_init(&budget->demux); + dvb_dmx_init (&budget->demux); - budget->dmxdev.filternum = 256; - budget->dmxdev.demux = &dvbdemux->dmx; - budget->dmxdev.capabilities = 0; + budget->dmxdev.filternum = 256; + budget->dmxdev.demux = &dvbdemux->dmx; + budget->dmxdev.capabilities = 0; - dvb_dmxdev_init(&budget->dmxdev, budget->dvb_adapter); + dvb_dmxdev_init (&budget->dmxdev, budget->dvb_adapter); - budget->hw_frontend.source = DMX_FRONTEND_0; + budget->hw_frontend.source = DMX_FRONTEND_0; - ret = dvbdemux->dmx.add_frontend(&dvbdemux->dmx, &budget->hw_frontend); + ret = dvbdemux->dmx.add_frontend (&dvbdemux->dmx, &budget->hw_frontend); - if (ret < 0) - return ret; + if (ret < 0) + return ret; - budget->mem_frontend.source = DMX_MEMORY_FE; - ret=dvbdemux->dmx.add_frontend (&dvbdemux->dmx, - &budget->mem_frontend); - if (ret<0) - return ret; + budget->mem_frontend.source = DMX_MEMORY_FE; + ret = dvbdemux->dmx.add_frontend (&dvbdemux->dmx, + &budget->mem_frontend); + if (ret < 0) + return ret; - ret=dvbdemux->dmx.connect_frontend (&dvbdemux->dmx, - &budget->hw_frontend); - if (ret < 0) - return ret; + ret = dvbdemux->dmx.connect_frontend (&dvbdemux->dmx, + &budget->hw_frontend); + if (ret < 0) + return ret; - dvb_net_init(budget->dvb_adapter, &budget->dvb_net, &dvbdemux->dmx); + dvb_net_init (budget->dvb_adapter, &budget->dvb_net, &dvbdemux->dmx); - return 0; + return 0; } -static void budget_unregister(struct budget *budget) +static void budget_unregister (struct budget *budget) { - struct dvb_demux *dvbdemux=&budget->demux; + struct dvb_demux *dvbdemux = &budget->demux; - dprintk(2, "budget: %p\n", budget); + dprintk (2, "budget: %p\n", budget); - dvb_net_release(&budget->dvb_net); + dvb_net_release (&budget->dvb_net); - dvbdemux->dmx.close(&dvbdemux->dmx); - dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &budget->hw_frontend); - dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &budget->mem_frontend); + dvbdemux->dmx.close (&dvbdemux->dmx); + dvbdemux->dmx.remove_frontend (&dvbdemux->dmx, &budget->hw_frontend); + dvbdemux->dmx.remove_frontend (&dvbdemux->dmx, &budget->mem_frontend); - dvb_dmxdev_release(&budget->dmxdev); - dvb_dmx_release(&budget->demux); + dvb_dmxdev_release (&budget->dmxdev); + dvb_dmx_release (&budget->demux); } int ttpci_budget_init (struct budget *budget, - struct saa7146_dev* dev, - struct saa7146_pci_extension_data *info) + struct saa7146_dev *dev, + struct saa7146_pci_extension_data *info) { - int length = TS_WIDTH*TS_HEIGHT; - int ret = 0; - struct budget_info *bi = info->ext_priv; + int length = TS_WIDTH * TS_HEIGHT; + int ret = 0; + struct budget_info *bi = info->ext_priv; - memset(budget, 0, sizeof(struct budget)); + memset (budget, 0, sizeof (struct budget)); - dprintk(2, "dev: %p, budget: %p\n", dev, budget); + dprintk (2, "dev: %p, budget: %p\n", dev, budget); - budget->card = bi; - budget->dev = (struct saa7146_dev *) dev; + budget->card = bi; + budget->dev = (struct saa7146_dev *) dev; - dvb_register_adapter(&budget->dvb_adapter, budget->card->name, THIS_MODULE); + dvb_register_adapter (&budget->dvb_adapter, budget->card->name, + THIS_MODULE); - /* set dd1 stream a & b */ - saa7146_write(dev, DD1_STREAM_B, 0x00000000); - saa7146_write(dev, MC2, (MASK_09 | MASK_25)); - saa7146_write(dev, MC2, (MASK_10 | MASK_26)); - saa7146_write(dev, DD1_INIT, 0x02000000); - saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); + /* set dd1 stream a & b */ + saa7146_write (dev, DD1_STREAM_B, 0x00000000); + saa7146_write (dev, MC2, (MASK_09 | MASK_25)); + saa7146_write (dev, MC2, (MASK_10 | MASK_26)); + saa7146_write (dev, DD1_INIT, 0x02000000); + saa7146_write (dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26)); - if (bi->type != BUDGET_FS_ACTIVY) - budget->video_port = BUDGET_VIDEO_PORTB; - else - budget->video_port = BUDGET_VIDEO_PORTA; - spin_lock_init(&budget->feedlock); + if (bi->type != BUDGET_FS_ACTIVY) + budget->video_port = BUDGET_VIDEO_PORTB; + else + budget->video_port = BUDGET_VIDEO_PORTA; + spin_lock_init (&budget->feedlock); + spin_lock_init (&budget->debilock); - /* the Siemens DVB needs this if you want to have the i2c chips - get recognized before the main driver is loaded */ - if (bi->type != BUDGET_FS_ACTIVY) - saa7146_write(dev, GPIO_CTRL, 0x500000); /* GPIO 3 = 1 */ + /* the Siemens DVB needs this if you want to have the i2c chips + get recognized before the main driver is loaded */ + if (bi->type != BUDGET_FS_ACTIVY) + saa7146_write (dev, GPIO_CTRL, 0x500000); /* GPIO 3 = 1 */ #ifdef I2C_ADAP_CLASS_TV_DIGITAL - budget->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL; + budget->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL; #else - budget->i2c_adap.class = I2C_CLASS_TV_DIGITAL; + budget->i2c_adap.class = I2C_CLASS_TV_DIGITAL; #endif - - strlcpy(budget->i2c_adap.name, budget->card->name, sizeof(budget->i2c_adap.name)); - saa7146_i2c_adapter_prepare(dev, &budget->i2c_adap, SAA7146_I2C_BUS_BIT_RATE_120); - strcpy(budget->i2c_adap.name, budget->card->name); + strlcpy (budget->i2c_adap.name, budget->card->name, + sizeof (budget->i2c_adap.name)); + + saa7146_i2c_adapter_prepare (dev, &budget->i2c_adap, + SAA7146_I2C_BUS_BIT_RATE_120); + strcpy (budget->i2c_adap.name, budget->card->name); - if (i2c_add_adapter(&budget->i2c_adap) < 0) { - dvb_unregister_adapter (budget->dvb_adapter); - return -ENOMEM; - } + if (i2c_add_adapter (&budget->i2c_adap) < 0) { + dvb_unregister_adapter (budget->dvb_adapter); + return -ENOMEM; + } - ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter->proposed_mac); + ttpci_eeprom_parse_mac (&budget->i2c_adap, + budget->dvb_adapter->proposed_mac); - if( NULL == (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci,length,&budget->pt))) { - ret = -ENOMEM; - goto err; - } + if (NULL == (budget->grabbing = saa7146_vmalloc_build_pgtable (dev->pci, length, &budget->pt))) { + ret = -ENOMEM; + goto err; + } - saa7146_write(dev, PCI_BT_V1, 0x001c0000); - /* upload all */ - saa7146_write(dev, GPIO_CTRL, 0x000000); + saa7146_write (dev, PCI_BT_V1, 0x001c0000); + /* upload all */ + saa7146_write (dev, GPIO_CTRL, 0x000000); - tasklet_init (&budget->vpe_tasklet, vpeirq, (unsigned long) budget); + tasklet_init (&budget->vpe_tasklet, vpeirq, (unsigned long) budget); - /* frontend power on */ - if (bi->type == BUDGET_FS_ACTIVY) - saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); - else - saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI); + /* frontend power on */ + if (bi->type == BUDGET_FS_ACTIVY) + saa7146_setgpio (dev, 1, SAA7146_GPIO_OUTHI); + else + saa7146_setgpio (dev, 2, SAA7146_GPIO_OUTHI); - if (budget_register(budget) == 0) { - return 0; - } -err: - i2c_del_adapter(&budget->i2c_adap); + if (budget_register (budget) == 0) { + return 0; + } + err: + i2c_del_adapter (&budget->i2c_adap); - if (budget->grabbing) - vfree(budget->grabbing); + if (budget->grabbing) + vfree (budget->grabbing); - dvb_unregister_adapter (budget->dvb_adapter); + dvb_unregister_adapter (budget->dvb_adapter); - return ret; + return ret; } int ttpci_budget_deinit (struct budget *budget) { - struct saa7146_dev *dev = budget->dev; + struct saa7146_dev *dev = budget->dev; - dprintk(2, "budget: %p\n", budget); + dprintk (2, "budget: %p\n", budget); - budget_unregister (budget); + budget_unregister (budget); - i2c_del_adapter(&budget->i2c_adap); + i2c_del_adapter (&budget->i2c_adap); - dvb_unregister_adapter (budget->dvb_adapter); + dvb_unregister_adapter (budget->dvb_adapter); - tasklet_kill (&budget->vpe_tasklet); + tasklet_kill (&budget->vpe_tasklet); - saa7146_pgtable_free (dev->pci, &budget->pt); + saa7146_pgtable_free (dev->pci, &budget->pt); - vfree (budget->grabbing); + vfree (budget->grabbing); - return 0; + return 0; } -void ttpci_budget_irq10_handler (struct saa7146_dev* dev, u32 *isr) +void ttpci_budget_irq10_handler (struct saa7146_dev *dev, u32 * isr) { - struct budget *budget = (struct budget*)dev->ext_priv; + struct budget *budget = (struct budget *) dev->ext_priv; - dprintk(8, "dev: %p, budget: %p\n",dev,budget); + dprintk (8, "dev: %p, budget: %p\n", dev, budget); - if (*isr & MASK_10) - tasklet_schedule (&budget->vpe_tasklet); + if (*isr & MASK_10) + tasklet_schedule (&budget->vpe_tasklet); } -void ttpci_budget_set_video_port(struct saa7146_dev* dev, int video_port) +void ttpci_budget_set_video_port (struct saa7146_dev *dev, int video_port) { - struct budget *budget = (struct budget*)dev->ext_priv; - - spin_lock(&budget->feedlock); - budget->video_port = video_port; - if (budget->feeding) { - int oldfeeding = budget->feeding; - budget->feeding = 1; - stop_ts_capture(budget); - start_ts_capture(budget); - budget->feeding = oldfeeding; - } - spin_unlock(&budget->feedlock); + struct budget *budget = (struct budget *) dev->ext_priv; + + spin_lock (&budget->feedlock); + budget->video_port = video_port; + if (budget->feeding) { + int oldfeeding = budget->feeding; + budget->feeding = 1; + stop_ts_capture (budget); + start_ts_capture (budget); + budget->feeding = oldfeeding; + } + spin_unlock (&budget->feedlock); } -EXPORT_SYMBOL_GPL(ttpci_budget_init); -EXPORT_SYMBOL_GPL(ttpci_budget_deinit); -EXPORT_SYMBOL_GPL(ttpci_budget_irq10_handler); -EXPORT_SYMBOL_GPL(ttpci_budget_set_video_port); -EXPORT_SYMBOL_GPL(budget_debug); - -MODULE_LICENSE("GPL"); +EXPORT_SYMBOL_GPL (ttpci_budget_debiread); +EXPORT_SYMBOL_GPL (ttpci_budget_debiwrite); +EXPORT_SYMBOL_GPL (ttpci_budget_init); +EXPORT_SYMBOL_GPL (ttpci_budget_deinit); +EXPORT_SYMBOL_GPL (ttpci_budget_irq10_handler); +EXPORT_SYMBOL_GPL (ttpci_budget_set_video_port); +EXPORT_SYMBOL_GPL (budget_debug); +MODULE_LICENSE ("GPL"); diff --git a/linux/drivers/media/dvb/ttpci/budget.h b/linux/drivers/media/dvb/ttpci/budget.h index d97bece77..de7c0bf34 100644 --- a/linux/drivers/media/dvb/ttpci/budget.h +++ b/linux/drivers/media/dvb/ttpci/budget.h @@ -21,49 +21,51 @@ extern int budget_debug; do { if ((budget_debug & level)) { printk("%s: %s(): ",__stringify(KBUILD_MODNAME), __FUNCTION__); printk(args); } } while (0) struct budget_info { - char *name; - int type; + char *name; + int type; }; /* place to store all the necessary device information */ struct budget { /* devices */ - struct dvb_device dvb_dev; - struct dvb_net dvb_net; + struct dvb_device dvb_dev; + struct dvb_net dvb_net; - struct saa7146_dev *dev; + struct saa7146_dev *dev; - struct i2c_adapter i2c_adap; - struct budget_info *card; + struct i2c_adapter i2c_adap; + struct budget_info *card; - unsigned char *grabbing; - struct saa7146_pgtable pt; + unsigned char *grabbing; + struct saa7146_pgtable pt; - struct tasklet_struct fidb_tasklet; - struct tasklet_struct vpe_tasklet; + struct tasklet_struct fidb_tasklet; + struct tasklet_struct vpe_tasklet; - struct dmxdev dmxdev; - struct dvb_demux demux; + struct dmxdev dmxdev; + struct dvb_demux demux; - struct dmx_frontend hw_frontend; - struct dmx_frontend mem_frontend; + struct dmx_frontend hw_frontend; + struct dmx_frontend mem_frontend; - int fe_synced; - struct semaphore pid_mutex; - - int ci_present; - int video_port; + int fe_synced; + struct semaphore pid_mutex; + + int ci_present; + int video_port; u8 tsf; u32 ttbp; int feeding; - spinlock_t feedlock; + spinlock_t feedlock; + + spinlock_t debilock; - struct dvb_adapter *dvb_adapter; - struct dvb_frontend *dvb_frontend; - void *priv; + struct dvb_adapter *dvb_adapter; + struct dvb_frontend *dvb_frontend; + void *priv; }; #define MAKE_BUDGET_INFO(x_var,x_name,x_type) \ @@ -94,11 +96,13 @@ static struct saa7146_pci_extension_data x_var = { \ #define BUDGET_VIDEO_PORTB 1 extern int ttpci_budget_init (struct budget *budget, - struct saa7146_dev* dev, - struct saa7146_pci_extension_data *info); + struct saa7146_dev *dev, + struct saa7146_pci_extension_data *info); extern int ttpci_budget_deinit (struct budget *budget); -extern void ttpci_budget_irq10_handler (struct saa7146_dev* dev, u32 *isr); -extern void ttpci_budget_set_video_port(struct saa7146_dev* dev, int video_port); +extern void ttpci_budget_irq10_handler (struct saa7146_dev *dev, u32 * isr); +extern void ttpci_budget_set_video_port (struct saa7146_dev *dev, + int video_port); +extern u32 ttpci_budget_debiread (struct budget *budget, u32 config, int addr, int count); +extern u8 ttpci_budget_debiwrite (struct budget *budget, u32 config, int addr, int count, u32 value); #endif - |