Add driver support for ITE IT9135 device
Subsystems (2)
PATCH 1/1 Add driver support for ITE IT9135 device
This is DVB USB Linux driver for ITEtech IT9135 base USB TV module. It supported the IT9135 AX and BX chip versions.
--- Documentation/dvb/get_dvb_firmware | 17 +- drivers/media/dvb/dvb-usb/Kconfig | 6 + drivers/media/dvb/dvb-usb/Makefile | 3 + drivers/media/dvb/dvb-usb/dvb-usb-ids.h | 4 + drivers/media/dvb/dvb-usb/it9135-fe.c | 4743 +++++++++++++++++++++++++++++++ drivers/media/dvb/dvb-usb/it9135-fe.h | 1632 +++++++++++ drivers/media/dvb/dvb-usb/it9135.c | 2492 ++++++++++++++++ drivers/media/dvb/dvb-usb/it9135.h | 155 + 8 files changed, 9051 insertions(+), 1 deletions(-) mode change 100644 => 100755 Documentation/dvb/get_dvb_firmware create mode 100644 drivers/media/dvb/dvb-usb/it9135-fe.c create mode 100644 drivers/media/dvb/dvb-usb/it9135-fe.h create mode 100644 drivers/media/dvb/dvb-usb/it9135.c create mode 100644 drivers/media/dvb/dvb-usb/it9135.h
Documentation/dvb/get_dvb_firmware +16 -1
@@ -27,7 +27,7 @@ use IO::Handle; "or51211", "or51132_qam", "or51132_vsb", "bluebird", "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718", "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395", - "lme2510c_s7395_old"); + "lme2510c_s7395_old", "it9135"); # Check args syntax() if (scalar(@ARGV) != 1);
@@ -634,6 +634,21 @@ sub lme2510c_s7395_old { $outfile; } +sub it9135 { + my $sourcefile = "dvb-usb-it9135.zip"; + my $url = "http://www.ite.com.tw/uploads/firmware/v3.6.0.0/$sourcefile"; + my $hash = "1e55f6c8833f1d0ae067c2bb2953e6a9"; + my $outfile = "dvb-usb-it9135.fw"; + + checkstandard(); + + wgetfile($sourcefile, $url); + unzip($sourcefile, ""); + verify("$outfile", $hash); + + $outfile; +} + # --------------------------------------------------------------- # Utilities
drivers/media/dvb/dvb-usb/Kconfig +6 -0
@@ -373,3 +373,9 @@ config DVB_USB_TECHNISAT_USB2 select DVB_STV6110x if !DVB_FE_CUSTOMISE help Say Y here to support the Technisat USB2 DVB-S/S2 device + +config DVB_USB_IT9135 + tristate "ITEtech IT9135 DVB-T USB2.0 support" + depends on DVB_USB + help + Say Y here to support the ITE IT9135 based DVB-T USB2.0 receiver
drivers/media/dvb/dvb-usb/Makefile +3 -0
@@ -94,6 +94,9 @@ obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o dvb-usb-technisat-usb2-objs = technisat-usb2.o obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o +dvb-usb-it9135-objs := it9135.o it9135-fe.o +obj-$(CONFIG_DVB_USB_IT9135) += dvb-usb-it9135.o + EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ # due to tuner-xc3028 EXTRA_CFLAGS += -Idrivers/media/common/tuners
drivers/media/dvb/dvb-usb/dvb-usb-ids.h +4 -0
@@ -67,6 +67,7 @@#define USB_VID_EVOLUTEPC 0x1e59#define USB_VID_AZUREWAVE 0x13d3#define USB_VID_TECHNISAT 0x14f7 +#define USB_VID_ITETECH 0x048d/* Product IDs */ #define USB_PID_ADSTECH_USB2_COLD 0xa333
@@ -320,4 +321,7 @@#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002#define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004#define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500 +#define USB_PID_ITETECH_IT9135 0x9135 +#define USB_PID_ITETECH_IT9135_9005 0x9005 +#define USB_PID_ITETECH_IT9135_9006 0x9006#endif
drivers/media/dvb/dvb-usb/it9135-fe.c new file +4743 -0
2,939 lines not on this page · raw message
drivers/media/dvb/dvb-usb/it9135-fe.h new file +1632 -0
1,632 lines not on this page · raw message
drivers/media/dvb/dvb-usb/it9135.c new file +2492 -0
2,492 lines not on this page · raw message
drivers/media/dvb/dvb-usb/it9135.h new file +155 -0
155 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
PATCH 1/2 IT9135 Add support for KWORLD_UB499_2T_T09 (id 1b80:e409)
Add support for KWORLD_UB499_2T_T09 to IT9135 Driver
***Please note*** that adapter 2 on this device does not function correctly.
--- drivers/media/dvb/dvb-usb/dvb-usb-ids.h | 1 + drivers/media/dvb/dvb-usb/it9135.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-)
drivers/media/dvb/dvb-usb/dvb-usb-ids.h +1 -0
@@ -137,6 +137,7 @@#define USB_PID_KWORLD_PC160_2T 0xc160#define USB_PID_KWORLD_PC160_T 0xc161#define USB_PID_KWORLD_UB383_T 0xe383 +#define USB_PID_KWORLD_UB499_2T_T09 0xe409#define USB_PID_KWORLD_VSTREAM_COLD 0x17de#define USB_PID_KWORLD_VSTREAM_WARM 0x17df#define USB_PID_TERRATEC_CINERGY_T_USB_XE 0x0055
drivers/media/dvb/dvb-usb/it9135.c +12 -11
@@ -2256,6 +2256,7 @@ struct usb_device_id it9135_usb_id_table[] = { {USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135)}, {USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9005)}, {USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006)}, + {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09)}, {0}, /* Terminating entry */ };
@@ -2319,18 +2320,18 @@ struct dvb_usb_device_properties it9135_properties[] = { } } }, - }, - .num_device_descs = 1, + }, + .num_device_descs = 2, .devices = { - {"ITEtech USB2.0 DVB-T Recevier", - {&it9135_usb_id_table[0], &it9135_usb_id_table[1], - &it9135_usb_id_table[2], NULL}, - {NULL}, - }, - {NULL}, - - } - } + { "ITEtech USB2.0 DVB-T Recevier", + { &it9135_usb_id_table[0], &it9135_usb_id_table[1], + &it9135_usb_id_table[2], NULL }, + }, + { "Kworld UB499-2T T09", + { &it9135_usb_id_table[3], NULL }, + }, + } + } }; int it9135_device_count = ARRAY_SIZE(it9135_properties);
Signature · 1 line
1.7.4.1
PATCH 2/2 IT9135 add MFE support to driver
In reply to jasondongAdd MFE Support.
--- drivers/media/dvb/dvb-usb/it9135.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/media/dvb/dvb-usb/it9135.c +3 -5
@@ -1781,8 +1781,7 @@ static struct dvb_frontend_ops it9135_ops = {static int it9135_pid_filter_ctrl (struct dvb_usb_adapter *adap,int onoff) { -struct it9135_dev_ctx *dev = - (struct it9135_dev_ctx *)adap->fe->demodulator_priv; +struct it9135_dev_ctx *dev = adap->fe[0 ]->demodulator_priv;int ret =0 ;deb_info ("%s: onoff:%d\n" , __func__, onoff);
@@ -1813,8 +1812,7 @@ static int it9135_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)static int it9135_pid_filter (struct dvb_usb_adapter *adap,int index,u16 pidnum,int onoff) { -struct it9135_dev_ctx *dev = - (struct it9135_dev_ctx *)adap->fe->demodulator_priv; +struct it9135_dev_ctx *dev = adap->fe[0 ]->demodulator_priv;unsigned short pid;int ret =0 ;
@@ -2234,7 +2232,7 @@ static int it9135_frontend_attach(struct dvb_usb_adapter *adap) {deb_func ("Enter %s Function - chip=%d\n" , __func__, adap->id); - adap->fe =it9135_attach (adap); + adap->fe[0 ] =it9135_attach (adap);return adap->fe ==NULL ? -ENODEV :0 ; }
Signature · 1 line
1.7.4.1
Quoted 2 lines · jasondong
This is DVB USB Linux driver for ITEtech IT9135 base USB TV module. It supported the IT9135 AX and BX chip versions.
Hi,
The quick review by crop@freenode was:
"I quick check it and didnt like much since it is not plitted logically correct, as usb-bridge, demod and tuner. now all are rather much one big blob".
so I guess you have to split it into pieces in a way other dvb drivers already in kernel tree are done. Unfortunately I don't know which existing driver is the best example on how to do things.
ps. are the IT9135 docs available anywhere?
ps2. on current linus 3.1 git + your 2 patches it is at least detected (cannot test more yet - no dbv-t signal here; it's to be available in incoming days)
[ 1152.752132] usb 2-2: new high speed USB device number 10 using ehci_hcd [ 1152.820365] hub 2-0:1.0: unable to enumerate USB device on port 2 [ 1153.156792] hub 6-0:1.0: unable to enumerate USB device on port 2 [ 1157.056107] usb 2-1: new high speed USB device number 11 using ehci_hcd [ 1157.192287] usb 2-1: New USB device found, idVendor=048d, idProduct=9005 [ 1157.192297] usb 2-1: New USB device strings: Mfr=1, Product=0, SerialNumber=3 [ 1157.192304] usb 2-1: Manufacturer: ITE Technologies, Inc. [ 1157.192309] usb 2-1: SerialNumber: AF0102020700001 [ 1157.193145] dvb-usb: found a 'ITEtech USB2.0 DVB-T Recevier' in cold state, will try to load a firmware [ 1157.196882] dvb-usb: downloading firmware from file 'dvb-usb-it9135.fw' [ 1157.198578] IT9135: This is IT9135 chip v1 [ 1157.198678] IT9135: ~~~ .Fw file only include Omega1 firmware, Scripts1&2!! [ 1157.198684] IT9135: ========================================= [ 1157.198689] IT9135: DRIVER_RELEASE_VERSION: v11.08.02.1 [ 1157.198694] IT9135: FW_RELEASE_VERSION: V1_0_26_2 [ 1157.198700] IT9135: API_RELEASE_VERSION: 203.20110426.0 [ 1157.198705] IT9135: ========================================= [ 1157.504659] IT9135: it9135_device_init success!! [ 1157.504686] dvb-usb: found a 'ITEtech USB2.0 DVB-T Recevier' in warm state. [ 1157.504708] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer. [ 1157.505522] DVB: registering new adapter (ITEtech USB2.0 DVB-T Recevier) [ 1157.506763] DVB: registering adapter 0 frontend 0 (IT9135 USB DVB-T)... [ 1157.506920] dvb-usb: ITEtech USB2.0 DVB-T Recevier successfully initialized
and connected.
Signature · 2 lines
Arkadiusz Miśkiewicz PLD/Linux Team arekm / maven.pl http://ftp.pld-linux.org/
Quoted 8 lines · Arkadiusz Miskiewicz
Quoted 2 lines · jasondong
This is DVB USB Linux driver for ITEtech IT9135 base USB TV module. It supported the IT9135 AX and BX chip versions.
Hi,
The quick review by crop@freenode was:
Quoted 7 lines
"I quick check it and didnt like much since it is not plitted logically correct, as usb-bridge, demod and tuner. now all are rather much one big blob".
so I guess you have to split it into pieces in a way other dvb drivers already in kernel tree are done. Unfortunately I don't know which existing driver is the best example on how to do things.
More comments from irc:
"22:09 < crope> arekm: any current DVB USB driver. there is very many of integrated (2-in-1, or 3-in-1) drivers which are splitted correctly 22:10 < crope> ec168, af9015, some dibcom models?, ce6320, rtl2831u 22:11 < crope> you *must* implement all logical parts as own drivers no matter of those are integrated to one silicon or not. it is generally seen those
parts used are sold as not integrated too
22:12 < crope> for example that IT9135, I really think it uses af9033 demod, which is sold as own part and also integrated to af9015. and very likely IT9135
contains same USB-brdge than AF9035. only difference is
integrated tuner
22:13 < crope> so IT9135 == AF9035+ ITXXXX tuner in one package. when you split driver correctly to logical parts you can use same drivers 22:14 < crope> and AF9035 == AF903XX USB-bridge + AF9033 demod 22:17 < crope> all DVB USB drivers we have consist of 2 parts (drivers). 1) USB-interface driver (aka DVB USB) 2) demodulator driver 3) tuner driver 22:17 < crope> all DVB USB drivers we have consist of 3 parts (drivers). 1) USB-interface driver (aka DVB USB) 2) demodulator driver 3) tuner driver "
Signature · 2 lines
Arkadiusz Miśkiewicz PLD/Linux Team arekm / maven.pl http://ftp.pld-linux.org/
Hi Jason,
Em 05-08-2011 07:24, jasondong escreveu:
Quoted 2 lines
This is DVB USB Linux driver for ITEtech IT9135 base USB TV module. It supported the IT9135 AX and BX chip versions.
See my comments bellow.
Thanks,
Mauro
Quoted 129 lines
Signed-off-by jasondong <[email protected]>--- Documentation/dvb/get_dvb_firmware | 17 +- drivers/media/dvb/dvb-usb/Kconfig | 6 + drivers/media/dvb/dvb-usb/Makefile | 3 + drivers/media/dvb/dvb-usb/dvb-usb-ids.h | 4 + drivers/media/dvb/dvb-usb/it9135-fe.c | 4743 +++++++++++++++++++++++++++++++ drivers/media/dvb/dvb-usb/it9135-fe.h | 1632 +++++++++++ drivers/media/dvb/dvb-usb/it9135.c | 2492 ++++++++++++++++ drivers/media/dvb/dvb-usb/it9135.h | 155 + 8 files changed, 9051 insertions(+), 1 deletions(-) mode change 100644 => 100755 Documentation/dvb/get_dvb_firmware create mode 100644 drivers/media/dvb/dvb-usb/it9135-fe.c create mode 100644 drivers/media/dvb/dvb-usb/it9135-fe.h create mode 100644 drivers/media/dvb/dvb-usb/it9135.c create mode 100644 drivers/media/dvb/dvb-usb/it9135.hDocumentation/dvb/get_dvb_firmware +16
-1@@ -27,7 +27,7 @@ use IO::Handle; "or51211", "or51132_qam", "or51132_vsb", "bluebird", "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718", "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395", - "lme2510c_s7395_old"); + "lme2510c_s7395_old", "it9135"); # Check args syntax() if (scalar(@ARGV) != 1);@@ -634,6 +634,21 @@ sub lme2510c_s7395_old { $outfile; } +sub it9135 { + my $sourcefile = "dvb-usb-it9135.zip"; + my $url = "http://www.ite.com.tw/uploads/firmware/v3.6.0.0/$sourcefile"; + my $hash = "1e55f6c8833f1d0ae067c2bb2953e6a9"; + my $outfile = "dvb-usb-it9135.fw"; + + checkstandard(); + + wgetfile($sourcefile, $url); + unzip($sourcefile, ""); + verify("$outfile", $hash); + + $outfile; +} + # --------------------------------------------------------------- # Utilitiesdrivers/media/dvb/dvb-usb/Kconfig +6
-0@@ -373,3 +373,9 @@ config DVB_USB_TECHNISAT_USB2 select DVB_STV6110x if !DVB_FE_CUSTOMISE help Say Y here to support the Technisat USB2 DVB-S/S2 device + +config DVB_USB_IT9135 + tristate "ITEtech IT9135 DVB-T USB2.0 support" + depends on DVB_USB + help + Say Y here to support the ITE IT9135 based DVB-T USB2.0 receiverdrivers/media/dvb/dvb-usb/Makefile +3
-0@@ -94,6 +94,9 @@ obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o dvb-usb-technisat-usb2-objs = technisat-usb2.o obj-$(CONFIG_DVB_USB_TECHNISAT_USB2) += dvb-usb-technisat-usb2.o +dvb-usb-it9135-objs := it9135.o it9135-fe.o +obj-$(CONFIG_DVB_USB_IT9135) += dvb-usb-it9135.o + EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ # due to tuner-xc3028 EXTRA_CFLAGS += -Idrivers/media/common/tunersdrivers/media/dvb/dvb-usb/dvb-usb-ids.h +4
-0@@ -67,6 +67,7 @@#define USB_VID_EVOLUTEPC 0x1e59#define USB_VID_AZUREWAVE 0x13d3#define USB_VID_TECHNISAT 0x14f7 +#define USB_VID_ITETECH 0x048d/* Product IDs */ #define USB_PID_ADSTECH_USB2_COLD 0xa333@@ -320,4 +321,7 @@#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002#define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004#define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500 +#define USB_PID_ITETECH_IT9135 0x9135 +#define USB_PID_ITETECH_IT9135_9005 0x9005 +#define USB_PID_ITETECH_IT9135_9006 0x9006#endif drivers/media/dvb/dvb-usb/it9135-fe.c new file +20
-0@@ -0,0 +1,4743 @@ +/* +* DVB USB Linux driver for IT9135 DVB-T USB2.0 receiver +* +* Copyright (C) 2011 ITE Technologies, INC. +* +* 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. +*/ + +#include <linux/delay.h> + +#include "it9135.h" + +static unsigned long it9135_enter_mutex (struct it9135_data *data) +{ +/* +* ToDo: Add code here +*/
drivers/media/dvb/dvb-usb/it9135-fe.c line 30
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+return ERROR_NO_ERROR ; +} + +static unsigned long it9135_leave_mutex (struct it9135_data *data) +{ +/* +* ToDo: Add code here +*/ +return ERROR_NO_ERROR ; +}
Hmmm... please implement mutexes were needed, but, instead of calling a "generic" code for that, just call mutex_lock/mutex_unlock where needed.
drivers/media/dvb/dvb-usb/it9135-fe.c line 41
Quoted 11 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +11
-0+ +/* +* IT9135 command functions +*/ +#define IT9135_MAX_CMD_SIZE 63 + +static unsigned long it9135_cmd_add_checksum (struct it9135_data *data, +unsigned long *buff_len, +unsigned char *buffer) +{ +unsigned long error =ERROR_NO_ERROR ;
Don't create your own errorspace. Linux has its own.
In this specific case, the better would be to just define this function as
static void it9135_cmd_add_checksum(...)
Quoted 32 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +32
-0+unsigned long loop = (*buff_len -1 ) /2 ; +unsigned long remain = (*buff_len -1 ) %2 ; +unsigned long i; +unsigned short checksum =0 ; + +for (i =0 ; i < loop; i++) + checksum += + (unsigned short )(buffer[2 * i +1 ] <<8 ) + + (unsigned short )(buffer[2 * i +2 ]); +if (remain) + checksum += (unsigned short )(buffer[*buff_len -1 ] <<8 ); + + checksum = ~checksum; + buffer[*buff_len] = (unsigned char )((checksum &0xFF00 ) >>8 ); + buffer[*buff_len +1 ] = (unsigned char )(checksum &0x00FF ); + buffer[0 ] = (unsigned char )(*buff_len +1 ); + *buff_len +=2 ; + +return error; +} + +static unsigned long it9135_cmd_remove_checksum (struct it9135_data *data, +unsigned long *buff_len, +unsigned char *buffer) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned long loop = (*buff_len -3 ) /2 ; +unsigned long remain = (*buff_len -3 ) %2 ; +unsigned long i; +unsigned short checksum =0 ; + +for (i =0 ; i < loop; i++)
drivers/media/dvb/dvb-usb/it9135-fe.c line 83
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ checksum += + (unsigned short )(buffer[2 * i +1 ] <<8 ) + + (unsigned short )(buffer[2 * i +2 ]); +if (remain) + checksum += (unsigned short )(buffer[*buff_len -3 ] <<8 ); + + checksum = ~checksum; +if (((unsigned short )(buffer[*buff_len -2 ] <<8 ) + + (unsigned short )(buffer[*buff_len -1 ])) != checksum) { + error =ERROR_WRONG_CHECKSUM ;
If that means that the message arrived wrong, -EIO is the proper error code.
drivers/media/dvb/dvb-usb/it9135-fe.c line 96
Quoted 13 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +13
-0+ goto exit; + } +if (buffer[2 ]) + error =ERROR_FIRMWARE_STATUS | buffer[2 ]; + + buffer[0 ] = (unsigned char )(*buff_len -3 ); + *buff_len -=2 ; + +exit: +return error; +} + +#define IT9135_USB_BULK_TIMEOUT 2000
Better to put such define at the beginning of the file.
Quoted 4 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +4
-0+ +static unsigned long it9135_cmd_bus_tx (struct it9135_data *data, +unsigned long buff_len, +unsigned char *buffer)
drivers/media/dvb/dvb-usb/it9135-fe.c line 110
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+{ +unsigned long error =ERROR_NO_ERROR ; +int act_len, ret; + + ret =usb_bulk_msg (usb_get_dev (data->driver), +usb_sndbulkpipe (usb_get_dev (data->driver),0x02 ), + buffer, buff_len, &act_len,IT9135_USB_BULK_TIMEOUT ); + +if (ret) { + error =ERROR_USB_WRITE_FAIL ;
No. Please return the error code from usb_bulk_msg.
Quoted 9 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +9
-0+err (" it9135_cmd_bus_tx fail : %d!" , ret); + } + +return error; +} + +static unsigned long it9135_cmd_bus_rx (struct it9135_data *data, +unsigned long buff_len, +unsigned char *buffer)
drivers/media/dvb/dvb-usb/it9135-fe.c line 129
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+{ +unsigned long error =ERROR_NO_ERROR ; +int act_len, ret; + + ret =usb_bulk_msg (usb_get_dev (data->driver), +usb_rcvbulkpipe (usb_get_dev (data->driver),129 ), + buffer,125 , &act_len,IT9135_USB_BULK_TIMEOUT ); + +if (ret) { + error =ERROR_USB_WRITE_FAIL ;
No. Please return the error code from usb_bulk_msg.
I won't repeat this over and over. All functions that return errors should just use the standard error codes defined on Linux, or 0 if no error.
Quoted 7 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +7
-0+err (" it9135_cmd_bus_rx fail: %d!" , ret); + } + +return error; +} + +static unsigned long it9135_cmd_loadfirmware(struct it9135_data *data,
drivers/media/dvb/dvb-usb/it9135-fe.c line 146
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+unsigned long length, + unsigned char *firmware) +{ + unsigned long error = ERROR_NO_ERROR; +unsigned short command; +unsigned long loop; +unsigned long remain; +unsigned long i, j, k; +unsigned char buffer[255 ]; +unsigned long payloadLength;
Please don't use CamelCase in Linux. "payload_len" is a better naming.
Quoted 73 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +72
-0+unsigned long buff_len; +unsigned long remain_len; +unsigned long send_len; + +it9135_enter_mutex (data); + + payloadLength = (IT9135_MAX_CMD_SIZE -6 ); + loop = length / payloadLength; + remain = length % payloadLength; + + k =0 ; + command =it9135_build_command (CMD_FW_DOWNLOAD ,PROCESSOR_LINK ,0 ); +for (i =0 ; i < loop; i++) { + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + +for (j =0 ; j < payloadLength; j++) + buffer[4 + j] = firmware[j + i * payloadLength]; + + buff_len =4 + payloadLength; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + + send_len =0 ; + remain_len =IT9135_MAX_CMD_SIZE ; +while (remain_len >0 ) { + k = (remain_len > +IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, k, &buffer[send_len]); +if (error) + goto exit; + + send_len += k; + remain_len -= k; + } + } + +if (remain) { + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + +for (j =0 ; j < remain; j++) + buffer[4 + j] = firmware[j + i * payloadLength]; + + buff_len =4 + remain; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + k = (remain_len > +IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, k, &buffer[send_len]); +if (error) + goto exit; + + send_len += k; + remain_len -= k; + } + } + +exit: +it9135_leave_mutex (data); +return error; +}
drivers/media/dvb/dvb-usb/it9135-fe.c line 228
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ +static unsigned long it9135_cmd_reboot (struct it9135_data *data, +unsigned char chip) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short command; +unsigned char buffer[255 ]; +unsigned long buff_len; + +it9135_enter_mutex (data);
Please use, instead, something like:
mutex_lock(data->mutex);
Quoted 6 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +6
-0+ + command =it9135_build_command (CMD_REBOOT ,PROCESSOR_LINK , chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + buff_len =4 ;
drivers/media/dvb/dvb-usb/it9135-fe.c line 244
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + + error =it9135_cmd_bus_tx (data, buff_len, buffer); +if (error) + goto exit; + +exit: +it9135_leave_mutex (data);
mutex_unlock(data->mutex);
Quoted 8 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +8
-0+return error; +} + +/* +* Send the command to device. +* +* @param struct it9135_data the handle of IT9135. +* @param command the command to be send.
drivers/media/dvb/dvb-usb/it9135-fe.c line 262
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+* @param chip The index of IT9135. The possible values are 0~7. +* @param processor The processor of specified register. Because each chip +* has two processor so user have to specify the processor. The +* possible values are PROCESSOR_LINK and PROCESSOR_OFDM. +* @param w_buff_len the number of registers to be write. +* @param w_buff a unsigned char array which is used to store values to be write. +* @param r_buff_len the number of registers to be read. +* @param r_buff a unsigned char array which is used to store values to be read. +* @return ERROR_NO_ERROR: successful, non-zero error code otherwise. +*/
The function prototype is wrong. If you're commenting the arguments, it should be instead:
/**
* it9135_cmd_sendcommand() - Send the command to device *
* @data: the handle of IT9135.
...
Please read Documentation/kernel-doc-nano-HOWTO.txt for more details.
Quoted 7 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +7
-0+static unsigned long it9135_cmd_sendcommand(struct it9135_data *data, + unsigned short command, + unsigned char chip, + unsigned char processor, + unsigned long w_buff_len, + unsigned char *w_buff, + unsigned long r_buff_len,
drivers/media/dvb/dvb-usb/it9135-fe.c line 279
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ unsigned char *r_buff) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char buffer[255 ]; +unsigned long buff_len; +unsigned long remain_len; +unsigned long send_len; +unsigned long i, k; + +it9135_enter_mutex (data);
Again, use the proper mutex call. I won't be repeating this forever. So, replace it on all places at the document. Please remember to properly initialize the mutex with mutex_init() when you initialize the "data" struct, otherwise you'll get oopses.
drivers/media/dvb/dvb-usb/it9135-fe.c line 282
Quoted 3 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +3
-0+ +if ((w_buff_len +6 ) >IT9135_MAX_CMD_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ;
-EINVAL.
Quoted 118 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +118
-0+ goto exit; + } + +if ((r_buff_len +5 ) >IT9135_MAX_PKT_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +if ((r_buff_len +5 ) >IT9135_MAX_CMD_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +if (w_buff_len ==0 ) { + command =it9135_build_command (command, processor, chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + buff_len =4 ; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +/* send command packet */ + i =0 ; + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + i = (remain_len > +IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, i, &buffer[send_len]); +if (error) + goto exit; + + send_len += i; + remain_len -= i; + } + }else { + command =it9135_build_command (command, processor, chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; +for (k =0 ; k < w_buff_len; k++) + buffer[k +4 ] = w_buff[k]; + + buff_len =4 + w_buff_len; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +/* send command */ + i =0 ; + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + i = (remain_len > +IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, i, &buffer[send_len]); +if (error) + goto exit; + + send_len += i; + remain_len -= i; + } + } + + buff_len =5 + r_buff_len; + + error =it9135_cmd_bus_rx (data, buff_len, buffer); +if (error) + goto exit; + + error =it9135_cmd_remove_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +if (r_buff_len) { +for (k =0 ; k < r_buff_len; k++) + r_buff[k] = buffer[k +3 ]; + } + +exit: +it9135_leave_mutex (data); +return error; +} + +/* +* IT9135 tuner functions +*/ + +static unsigned int it9135_tuner_get_nv (unsigned int nc) +{ +unsigned int nv; + +switch (nc) { +case 0 : + nv =48 ; +break ; +case 1 : + nv =32 ; +break ; +case 2 : + nv =24 ; +break ; +case 3 : + nv =16 ; +break ; +case 4 : + nv =12 ; +break ; +case 5 : + nv =8 ; +break ; +case 6 : + nv =6 ; +break ;
drivers/media/dvb/dvb-usb/it9135-fe.c line 409
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +9
-0+case 7 : + nv =4 ; +break ; +case 8 :/* L-band */ + nv =2 ; +break ; +default : + nv =2 ; +break ;
Just do, instead:
case 8: /* L-band */ default: nv = 2; break;
Quoted 14 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +14
-0+ } + +return nv; +} + +static unsigned int it9135_fn_min[] = { +53000 ,74000 ,111000 ,148000 ,222000 ,296000 ,445000 ,573000 ,950000 +}; + +static unsigned long it9135_tuner_init (struct it9135_data *data, +unsigned char chip) +{ +unsigned long error =0 ; +unsigned char buf[4 ], val;
drivers/media/dvb/dvb-usb/it9135-fe.c line 433
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+unsigned int m_bdry, nc, nv; +unsigned long tmp_numer, tmp_denom; +unsigned int cnt; + +#define OMEGA_TUNER_INIT_POLL_INTERVAL 2 +#define OMEGA_TUNER_INIT_POLL_COUNTS 50 + +/* ----- read ----- */ +/* p_reg_p_tsm_init_clock_mode */ + error =it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xEC86 ,1 , buf);
We generally use lowercase for hexadecimal values.
Quoted 58 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +58
-0+if (error) + goto exit; +/* p_reg_p_fbc_n_code */ + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xED03 ,1 , &buf[1 ]); +if (error) + goto exit; +/* r_reg_r_fbc_m_bdry_7_0 */ + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xED23 ,2 , &buf[2 ]); +if (error) + goto exit; + +/* ----- set_clock_mode ----- */ + data->clock_mode = buf[0 ]; + +/* ----- set_fref_kHz & m_cal ----- */ +switch (data->clock_mode) { +case 0 :/* 12.00MHz, 12000/18 = 2000/3 */ + data->fxtal_khz =2000 ; + data->fdiv =3 ; + val =16 ; +break ; +case 1 :/* 20.48MHz, 20480/32 = 640/1 */ + data->fxtal_khz =640 ; + data->fdiv =1 ; + val =6 ; +break ; +default :/* 20.48MHz, 20480/32 = 640/1 */ + data->fxtal_khz =640 ; + data->fdiv =1 ; + val =6 ; +break ; + } + +/* ----- set_fbdry ----- */ + nc = buf[1 ]; + nv =it9135_tuner_get_nv (nc); + m_bdry = (buf[3 ] <<8 ) + buf[2 ];/* m_bdry = m_bdry_15_8 << 8 + m_bdry_7_0 */ + +/* ----- patch to wait for fbc done ----- */ + cnt =1 ; +while (m_bdry ==0 && cnt <OMEGA_TUNER_INIT_POLL_COUNTS ) { +mdelay (OMEGA_TUNER_INIT_POLL_INTERVAL ); +/* r_reg_r_fbc_m_bdry_7_0 */ + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xED23 ,2 , + &buf[2 ]); +if (error) + goto exit; + m_bdry = (buf[3 ] <<8 ) + buf[2 ];/* m_bdry = m_bdry_15_8 << 8 + m_bdry_7_0 */ + cnt++; + } + +if (m_bdry ==0 ) { + error =ERROR_TUNER_INIT_FAIL ; + goto exit; + }
drivers/media/dvb/dvb-usb/it9135-fe.c line 501
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ + tmp_numer = (unsigned long )data->fxtal_khz * (unsigned long )m_bdry; + tmp_denom = (unsigned long )data->fdiv * (unsigned long )nv; + it9135_fn_min[7 ] = (unsigned int )(tmp_numer / tmp_denom); + +/* ----- patch to wait for all cal done, borrow p_reg_p_tsm_init_mode ----- */ + cnt =1 ; + +if (data->chip_type ==0x9135 && data->chip_ver ==2 ) { +mdelay (50 );/* for omega2 */
Except if you really need an exact time, don't use mdelay(). It makes the CPU to run a loop, blocking it to be used by other proccesses, so, impacting at the machine performance, instead of letting it to do something else or to save energy. Normal delays should use, instead:
msleep(50);
Quoted 44 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +44
-0+ }else { +/* p_reg_p_tsm_init_mode */ + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xEC82 ,1 , + buf); +if (error) + goto exit; + +while (buf[0 ] ==0 && cnt <OMEGA_TUNER_INIT_POLL_COUNTS ) { +mdelay (OMEGA_TUNER_INIT_POLL_INTERVAL ); +/* p_reg_p_tsm_init_mode */ + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xEC82 , +1 , buf); +if (error) + goto exit; + cnt++; + } +if (buf[0 ] ==0 ) { + error =ERROR_TUNER_INIT_FAIL ; + goto exit; + } + } + +/* p_reg_p_iqik_m_cal */ + error =it9135_write_regs (data, chip,PROCESSOR_OFDM ,0xED81 ,1 , &val); + +exit: +return error; +} + +static unsigned int it9135_tuner_get_nc (unsigned int rf_freq_khz) +{ +unsigned int nc; + +if ((rf_freq_khz <= it9135_fn_min[1 ])) {/* 74 */ + nc =0 ; + }else if ((rf_freq_khz > it9135_fn_min[1 ]) && (rf_freq_khz <= it9135_fn_min[2 ])) {/* 74 111 */ + nc =1 ; + }else if ((rf_freq_khz > it9135_fn_min[2 ]) && (rf_freq_khz <= it9135_fn_min[3 ])) {/* 111 148 */ + nc =2 ; + }else if ((rf_freq_khz > it9135_fn_min[3 ]) && (rf_freq_khz <= it9135_fn_min[4 ])) {/* 148 222 */ + nc =3 ; + }else if ((rf_freq_khz > it9135_fn_min[4 ]) && (rf_freq_khz <= it9135_fn_min[5 ])) {/* 222 296 */
drivers/media/dvb/dvb-usb/it9135-fe.c line 555
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ nc =4 ; + }else if ((rf_freq_khz > it9135_fn_min[5 ]) && (rf_freq_khz <= it9135_fn_min[6 ])) {/* 296 445 */ + nc =5 ; + }else if ((rf_freq_khz > it9135_fn_min[6 ]) && (rf_freq_khz <= it9135_fn_min[7 ])) {/* 445 573 */ + nc =6 ; + }else if ((rf_freq_khz > it9135_fn_min[7 ]) && (rf_freq_khz <= it9135_fn_min[8 ])) {/* 573 890 */ + nc =7 ; + }else {/* L-band */ + nc =8 ; + }
Code will be cleaner if you use a for loop.
Quoted 5 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +5
-0+ +return nc; +} + +static unsigned int it9135_tuner_get_freq_code(struct it9135_data *data,
drivers/media/dvb/dvb-usb/it9135-fe.c line 570
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+unsigned int rf_freq_khz, + unsigned int *nc, + unsigned int *nv, + unsigned int *mv) +{ + unsigned int freq_code; +unsigned long tmp_tg, tmp_cal, tmp_m; + + *nc =it9135_tuner_get_nc (rf_freq_khz); + *nv =it9135_tuner_get_nv (*nc);
The better would be to merge both functions into one, and use a loop inside it, instead of 8 if's and 8 case conditions.
drivers/media/dvb/dvb-usb/it9135-fe.c line 575
Quoted 5 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +5
-0+ tmp_tg = + (unsigned long )rf_freq_khz * (unsigned long )(*nv) * + (unsigned long )data->fdiv; + tmp_m = (tmp_tg / (unsigned long )data->fxtal_khz); + tmp_cal = tmp_m * (unsigned long )data->fxtal_khz;
On Linux, both "long" and "int" have 32 bits. If 32 bits is ok, you can just remove the typecast and define tmp_* as unsigned int. On the other hand, if you need 64 bits to avoid overflow, you'll need to use "u64" and use div_u64() for division.
Quoted 55 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +55
-0+ +if ((tmp_tg - tmp_cal) >= (data->fxtal_khz >>1 )) + tmp_m = tmp_m +1 ; + + *mv = (unsigned int )(tmp_m); + + freq_code = (((*nc) &0x07 ) <<13 ) + (*mv); + +return freq_code; +} + +static unsigned int it9135_tuner_get_freq_iqik (struct it9135_data *data, +unsigned int rf_freq_khz, +unsigned char iqik_m_cal) +{ +unsigned int nc, nv, mv, cal_freq; + +#define OMEGA_IQIK_M_CAL_MAX 64 +#define OMEGA_IQIK_M_CAL_MID 32 + + cal_freq =it9135_tuner_get_freq_code (data, rf_freq_khz, &nc, &nv, &mv); +if (data->clock_mode ==0 && (iqik_m_cal <OMEGA_IQIK_M_CAL_MID )) { + mv = mv + ((((unsigned int )iqik_m_cal) * nv *9 ) >>5 ); + }else if (data->clock_mode ==0 + && (iqik_m_cal >=OMEGA_IQIK_M_CAL_MID )) { + iqik_m_cal =OMEGA_IQIK_M_CAL_MAX - iqik_m_cal; + mv = mv - ((((unsigned int )iqik_m_cal) * nv *9 ) >>5 ); + }else if (data->clock_mode ==1 && (iqik_m_cal <OMEGA_IQIK_M_CAL_MID )) { + mv = mv + ((((unsigned int )iqik_m_cal) * nv) >>1 ); + }else {/* (data->clock_mode==1 && (iqik_m_cal >= OMEGA_IQIK_M_CAL_MID)) */ + iqik_m_cal =OMEGA_IQIK_M_CAL_MAX - iqik_m_cal; + mv = mv - ((((unsigned int )iqik_m_cal) * nv) >>1 ); + } + cal_freq = ((nc &0x07 ) <<13 ) + mv; + +return cal_freq; +} + +/* the reason to use 392000(but not 400000) because cal_rssi will use 400000-8000= 392000; */ +static unsigned int it9135_lna_fband_min[] = { +392000 ,440000 ,484000 ,533000 ,587000 ,645000 ,710000 ,782000 ,860000 , +1450000 ,1492000 ,1660000 ,1685000 +}; + +static unsigned char it9135_tuner_get_lna_cap_sel (unsigned int rf_freq_khz) +{ +unsigned char lna_cap_sel; + +if (rf_freq_khz <= it9135_lna_fband_min[1 ]) {/* <=440 */ + lna_cap_sel =0 ; + }else if (rf_freq_khz > it9135_lna_fband_min[1 ] && rf_freq_khz <= it9135_lna_fband_min[2 ]) {/* 440 484 */ + lna_cap_sel =1 ; + }else if (rf_freq_khz > it9135_lna_fband_min[2 ] && rf_freq_khz <= it9135_lna_fband_min[3 ]) {/* 484 533 */ + lna_cap_sel =2 ; + }else if (rf_freq_khz > it9135_lna_fband_min[3 ] && rf_freq_khz <= it9135_lna_fband_min[4 ]) {/* 533 587 */
drivers/media/dvb/dvb-usb/it9135-fe.c line 640
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ lna_cap_sel =3 ; + }else if (rf_freq_khz > it9135_lna_fband_min[4 ] && rf_freq_khz <= it9135_lna_fband_min[5 ]) {/* 587 645 */ + lna_cap_sel =4 ; + }else if (rf_freq_khz > it9135_lna_fband_min[5 ] && rf_freq_khz <= it9135_lna_fband_min[6 ]) {/* 645 710 */ + lna_cap_sel =5 ; + }else if (rf_freq_khz > it9135_lna_fband_min[6 ] && rf_freq_khz <= it9135_lna_fband_min[7 ]) {/* 710 782 */ + lna_cap_sel =6 ; + }else {/* >782 */ + lna_cap_sel =7 ; + }
Same as above: Please use a loop for it.
Quoted 52 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +52
-0+ +return lna_cap_sel; +} + +static unsigned int it9135_tuner_get_lo_freq (struct it9135_data *data, +unsigned int rf_freq_khz) +{ +unsigned int nc, nv, mv, lo_freq; + + lo_freq =it9135_tuner_get_freq_code (data, rf_freq_khz, &nc, &nv, &mv); + +return lo_freq; +} + +static unsigned char it9135_tuner_get_lpf_bw (unsigned int bw_khz) +{ +unsigned char lpf_bw; + +switch (bw_khz) {/*5.0MHz */ +case 5000 : + lpf_bw =0 ; +break ; +case 5500 :/*5.5MHz */ + lpf_bw =1 ; +break ; +case 6000 :/*6.0MHz */ + lpf_bw =2 ; +break ; +case 6500 :/*6.5MHz */ + lpf_bw =3 ; +break ; +case 7000 :/*7.0MHz */ + lpf_bw =4 ; +break ; +case 7500 :/*7.5MHz */ + lpf_bw =5 ; +break ; +case 8000 :/*8.0MHz */ + lpf_bw =6 ; +break ; +case 8500 :/*8.5MHz */ + lpf_bw =7 ; +break ; +default :/*default: 8MHz */ + lpf_bw =6 ; +break ; + } + +return lpf_bw; +} + +static unsigned long it9135_tuner_set_freq(struct it9135_data *data,
drivers/media/dvb/dvb-usb/it9135-fe.c line 702
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+unsigned char chip, + unsigned int bw_khz, + unsigned int rf_freq_khz) +{ + unsigned long error = 0; +unsigned char val[7 ]; +unsigned char buf[2 ]; +unsigned int tmp; + +#define IT9135_CAP_FREQ_UHF_MIN 392000
Better to put all those devices altogheter on the beginning of the file.
Quoted 89 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +89
-0+ +/* p_reg_t_ctrl */ + error =it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xEC4C ,1 , buf); +if (error) + goto exit; +/* p_reg_p_iqik_m_cal */ + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM ,0xED81 ,1 , &buf[1 ]); +if (error) + goto exit; + + val[0 ] =it9135_tuner_get_lna_cap_sel (rf_freq_khz); + val[1 ] =it9135_tuner_get_lpf_bw (bw_khz); + +/* ----- set_rf_mode ----- */ +if (rf_freq_khz <IT9135_CAP_FREQ_UHF_MIN ) + val[2 ] = buf[0 ] &0xE7 ;/* ctrl<4:3>=0b00 for VHF */ +else + val[2 ] = (buf[0 ] &0xE7 ) |0x08 ;/* ctrl<4:3>=0b01 for UHF */ + +/* ----- set_cal_freq ----- */ + tmp =it9135_tuner_get_freq_iqik (data, rf_freq_khz, buf[1 ]); + val[3 ] = (unsigned char )(tmp &0xFF ); + val[4 ] = (unsigned char )((tmp >>8 ) &0xFF ); +/* ----- set_lo_freq ----- */ + tmp =it9135_tuner_get_lo_freq (data, rf_freq_khz); + val[5 ] = (unsigned char )(tmp &0xFF ); + val[6 ] = (unsigned char )((tmp >>8 ) &0xFF ); +/* ----- write ----- */ + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM , var_pre_lna_cap_sel, +1 , val); +if (error) + goto exit; +/* p_reg_t_lpf_bw */ + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM ,0xEC56 ,1 , &val[1 ]); +if (error) + goto exit; +/* p_reg_t_ctrl */ + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM ,0xEC4C ,1 , &val[2 ]); +if (error) + goto exit; +/*----- the writing sequence is important for cal_freq and lo_freq, thus separate ----- */ +/* p_reg_t_cal_freq_7_0 */ + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM ,0xEC4D ,1 , &val[3 ]); +if (error) + goto exit; +/* p_reg_t_cal_freq_15_8 */ + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM ,0xEC4E ,1 , &val[4 ]); +if (error) + goto exit; + + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM , var_pre_lo_freq_7_0, +1 , &val[5 ]); +if (error) + goto exit; + + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM , var_pre_lo_freq_15_8, +1 , &val[6 ]); + +exit: +return error; +} + +/* +* Demodular functions +*/ + +static unsigned long it9135_divider (struct it9135_data *data,unsigned long a, +unsigned long b,unsigned long x) +{ +unsigned long answer =0 ; +unsigned long c =0 ; +unsigned long i =0 ; + +if (a > b) { + c = a / b; + a = a - c * b; + } + +for (i =0 ; i < x; i++) { +if (a >= b) { + answer +=1 ;
drivers/media/dvb/dvb-usb/it9135-fe.c line 801
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ a -= b; + } + a <<=1 ; + answer <<=1 ; + } + + answer = (c << (long )x) + answer; + +return answer; +}
As I've explained above, "long" is 32 bits on Linux. You don't need that. On the other hand, if you need 64 bits, just use one of the functions defined on include/linux/math64.h.
Quoted 252 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +252
-0+ +/* @param crystal_Freq: Crystal frequency (Hz) */ +static unsigned long it9135_compute_crystal (struct it9135_data *data, +long crystal_frequency, +unsigned long *crystal) +{ +unsigned long error =ERROR_NO_ERROR ; + + *crystal = + (long )it9135_divider (data, (unsigned long )crystal_frequency, +1000000ul ,19ul ); + +return error; +} + +/* @param adcFrequency: ADC frequency (Hz) */ +static unsigned long it9135_compute_adc (struct it9135_data *data,long adc_freq, +unsigned long *adc) +{ +unsigned long error =ERROR_NO_ERROR ; + + *adc = + (long )it9135_divider (data, (unsigned long )adc_freq,1000000ul , +19ul ); + +return error; +} + +/* +* @param adcFrequency: ADC frequency (Hz) +* @param ifFrequency: IF frequency (Hz) +* @param inversion: RF spectrum inversion +*/ +static unsigned long it9135_compute_fcw (struct it9135_data *data, +long adc_frequency,long if_frequency, +int inversion,unsigned long *fcw) +{ +unsigned long error =ERROR_NO_ERROR ; +long if_freq; +long adc_freq; +long adc_freq_half; +long adc_freq_sample; +long inv_bfs; +long ctrl_word; +unsigned char adc_multiplier; + + adc_freq = adc_frequency; + if_freq = if_frequency; + adc_freq_half = adc_freq /2 ; + +if (inversion) + if_freq =-1 * if_freq; + + adc_freq_sample = if_freq; + +if (adc_freq_sample >=0 ) { + inv_bfs =1 ; + }else { + inv_bfs =-1 ; + adc_freq_sample = adc_freq_sample *-1 ; + } + +while (adc_freq_sample > adc_freq_half) + adc_freq_sample = adc_freq_sample - adc_freq; + +/* Sample, spectrum at positive frequency */ +if (adc_freq_sample >=0 ) { + inv_bfs = inv_bfs *-1 ; + }else { + inv_bfs = inv_bfs *1 ; + adc_freq_sample = adc_freq_sample * (-1 );/* Absolute value */ + } + + ctrl_word = + (long )it9135_divider (data, (unsigned long )adc_freq_sample, + (unsigned long )adc_freq,23ul ); + +if (inv_bfs ==-1 ) + ctrl_word *=-1 ; + +/* Get ADC multiplier */ + error = +it9135_read_reg (data,0 ,PROCESSOR_OFDM , adcx2, &adc_multiplier); +if (error) + goto exit; + +if (adc_multiplier ==1 ) + ctrl_word /=2 ; + + *fcw = ctrl_word &0x7FFFFF ; + +exit: +return error; +} + +static unsigned long it9135_mask_dca_output (struct it9135_data *data) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char i; + +if ((data->chip_num >1 ) + && (data->architecture ==ARCHITECTURE_DCA )) { +for (i =0 ; i < data->chip_num; i++) { + error = +it9135_write_reg_bits (data, i, +PROCESSOR_OFDM , + p_reg_dca_upper_out_en, + reg_dca_upper_out_en_pos, + reg_dca_upper_out_en_len,0 ); +if (error) + goto exit; + } +mdelay (5 ); + } + +exit: +return error; +} + +static struct it9135_coeff_param coeff_tab[] = { +/* adc_freq 20156250 */ + {20156250 ,5000 ,0x02449b5c ,0x01224dae ,0x00912b60 ,0x009126d7 , +0x0091224e ,0x01224dae ,0x009126d7 ,0x0048936b ,0x0387 ,0x0122 }, + {20156250 ,6000 ,0x02b8ba6e ,0x015c5d37 ,0x00ae340d ,0x00ae2e9b , +0x00ae292a ,0x015c5d37 ,0x00ae2e9b ,0x0057174e ,0x02f1 ,0x015c }, + {20156250 ,7000 ,0x032cd980 ,0x01966cc0 ,0x00cb3cba ,0x00cb3660 , +0x00cb3007 ,0x01966cc0 ,0x00cb3660 ,0x00659b30 ,0x0285 ,0x0196 }, + {20156250 ,8000 ,0x03a0f893 ,0x01d07c49 ,0x00e84567 ,0x00e83e25 , +0x00e836e3 ,0x01d07c49 ,0x00e83e25 ,0x00741f12 ,0x0234 ,0x01d0 }, +/* adc_freq 20187500 */ + {20187500 ,5000 ,0x0243b546 ,0x0121daa3 ,0x0090f1d9 ,0x0090ed51 , +0x0090e8ca ,0x0121daa3 ,0x0090ed51 ,0x004876a9 ,0x0388 ,0x0122 }, + {20187500 ,6000 ,0x02b7a654 ,0x015bd32a ,0x00adef04 ,0x00ade995 , +0x00ade426 ,0x015bd32a ,0x00ade995 ,0x0056f4ca ,0x02f2 ,0x015c }, + {20187500 ,7000 ,0x032b9761 ,0x0195cbb1 ,0x00caec30 ,0x00cae5d8 , +0x00cadf81 ,0x0195cbb1 ,0x00cae5d8 ,0x006572ec ,0x0286 ,0x0196 }, + {20187500 ,8000 ,0x039f886f ,0x01cfc438 ,0x00e7e95b ,0x00e7e21c , +0x00e7dadd ,0x01cfc438 ,0x00e7e21c ,0x0073f10e ,0x0235 ,0x01d0 }, +/* adc_freq 20250000 */ + {20250000 ,5000 ,0x0241eb3b ,0x0120f59e ,0x00907f53 ,0x00907acf , +0x0090764b ,0x0120f59e ,0x00907acf ,0x00483d67 ,0x038b ,0x0121 }, + {20250000 ,6000 ,0x02b580ad ,0x015ac057 ,0x00ad6597 ,0x00ad602b , +0x00ad5ac1 ,0x015ac057 ,0x00ad602b ,0x0056b016 ,0x02f4 ,0x015b }, + {20250000 ,7000 ,0x03291620 ,0x01948b10 ,0x00ca4bda ,0x00ca4588 , +0x00ca3f36 ,0x01948b10 ,0x00ca4588 ,0x006522c4 ,0x0288 ,0x0195 }, + {20250000 ,8000 ,0x039cab92 ,0x01ce55c9 ,0x00e7321e ,0x00e72ae4 , +0x00e723ab ,0x01ce55c9 ,0x00e72ae4 ,0x00739572 ,0x0237 ,0x01ce }, +/* adc_freq 20583333 */ + {20583333 ,5000 ,0x02388f54 ,0x011c47aa ,0x008e2846 ,0x008e23d5 , +0x008e1f64 ,0x011c47aa ,0x008e23d5 ,0x004711ea ,0x039a ,0x011c }, + {20583333 ,6000 ,0x02aa4598 ,0x015522cc ,0x00aa96bb ,0x00aa9166 , +0x00aa8c12 ,0x015522cc ,0x00aa9166 ,0x005548b3 ,0x0300 ,0x0155 }, + {20583333 ,7000 ,0x031bfbdc ,0x018dfdee ,0x00c7052f ,0x00c6fef7 , +0x00c6f8bf ,0x018dfdee ,0x00c6fef7 ,0x00637f7b ,0x0293 ,0x018e }, + {20583333 ,8000 ,0x038db21f ,0x01c6d910 ,0x00e373a3 ,0x00e36c88 , +0x00e3656d ,0x01c6d910 ,0x00e36c88 ,0x0071b644 ,0x0240 ,0x01c7 }, +/* adc_freq 20416667 */ + {20416667 ,5000 ,0x023d337f ,0x011e99c0 ,0x008f515a ,0x008f4ce0 , +0x008f4865 ,0x011e99c0 ,0x008f4ce0 ,0x0047a670 ,0x0393 ,0x011f }, + {20416667 ,6000 ,0x02afd765 ,0x0157ebb3 ,0x00abfb39 ,0x00abf5d9 , +0x00abf07a ,0x0157ebb3 ,0x00abf5d9 ,0x0055faed ,0x02fa ,0x0158 }, + {20416667 ,7000 ,0x03227b4b ,0x01913da6 ,0x00c8a518 ,0x00c89ed3 , +0x00c8988e ,0x01913da6 ,0x00c89ed3 ,0x00644f69 ,0x028d ,0x0191 }, + {20416667 ,8000 ,0x03951f32 ,0x01ca8f99 ,0x00e54ef7 ,0x00e547cc , +0x00e540a2 ,0x01ca8f99 ,0x00e547cc ,0x0072a3e6 ,0x023c ,0x01cb }, +/* adc_freq 20480000 */ + {20480000 ,5000 ,0x023b6db7 ,0x011db6db ,0x008edfe5 ,0x008edb6e , +0x008ed6f7 ,0x011db6db ,0x008edb6e ,0x00476db7 ,0x0396 ,0x011e }, + {20480000 ,6000 ,0x02adb6db ,0x0156db6e ,0x00ab7312 ,0x00ab6db7 , +0x00ab685c ,0x0156db6e ,0x00ab6db7 ,0x0055b6db ,0x02fd ,0x0157 }, + {20480000 ,7000 ,0x03200000 ,0x01900000 ,0x00c80640 ,0x00c80000 , +0x00c7f9c0 ,0x01900000 ,0x00c80000 ,0x00640000 ,0x028f ,0x0190 }, + {20480000 ,8000 ,0x03924925 ,0x01c92492 ,0x00e4996e ,0x00e49249 , +0x00e48b25 ,0x01c92492 ,0x00e49249 ,0x00724925 ,0x023d ,0x01c9 }, +/* adc_freq 20500000 */ + {20500000 ,5000 ,0x023adeff ,0x011d6f80 ,0x008ebc36 ,0x008eb7c0 , +0x008eb34a ,0x011d6f80 ,0x008eb7c0 ,0x00475be0 ,0x0396 ,0x011d }, + {20500000 ,6000 ,0x02ad0b99 ,0x015685cc ,0x00ab4840 ,0x00ab42e6 , +0x00ab3d8c ,0x015685cc ,0x00ab42e6 ,0x0055a173 ,0x02fd ,0x0157 }, + {20500000 ,7000 ,0x031f3832 ,0x018f9c19 ,0x00c7d44b ,0x00c7ce0c , +0x00c7c7ce ,0x018f9c19 ,0x00c7ce0c ,0x0063e706 ,0x0290 ,0x0190 }, + {20500000 ,8000 ,0x039164cb ,0x01c8b266 ,0x00e46056 ,0x00e45933 , +0x00e45210 ,0x01c8b266 ,0x00e45933 ,0x00722c99 ,0x023e ,0x01c9 }, +/* adc_freq 20625000 */ + {20625000 ,5000 ,0x02376948 ,0x011bb4a4 ,0x008ddec1 ,0x008dda52 , +0x008dd5e3 ,0x011bb4a4 ,0x008dda52 ,0x0046ed29 ,0x039c ,0x011c }, + {20625000 ,6000 ,0x02a8e4bd ,0x0154725e ,0x00aa3e81 ,0x00aa392f , +0x00aa33de ,0x0154725e ,0x00aa392f ,0x00551c98 ,0x0302 ,0x0154 }, + {20625000 ,7000 ,0x031a6032 ,0x018d3019 ,0x00c69e41 ,0x00c6980c , +0x00c691d8 ,0x018d3019 ,0x00c6980c ,0x00634c06 ,0x0294 ,0x018d }, + {20625000 ,8000 ,0x038bdba6 ,0x01c5edd3 ,0x00e2fe02 ,0x00e2f6ea , +0x00e2efd2 ,0x01c5edd3 ,0x00e2f6ea ,0x00717b75 ,0x0242 ,0x01c6 } +}; + +static int it915_coeff_tab_count =ARRAY_SIZE (coeff_tab); + +static unsigned long it9135_get_coeff_param (struct it9135_coeff_param *coeff) +{ +unsigned long error =ERROR_NO_ERROR ; +int i; + +deb_info ("it9135_get_coeff_param - %ld, %d\n" , coeff->adc_freq, + coeff->bandwidth); + +for (i =0 ; i < it915_coeff_tab_count; i++) { +if ((coeff->adc_freq == coeff_tab[i].adc_freq) + && (coeff->bandwidth == coeff_tab[i].bandwidth)) { +memcpy (coeff, &coeff_tab[i],sizeof (*coeff)); +deb_info ("find coeff table - %ld, %d\n" , + coeff->adc_freq, coeff->bandwidth); +break ; + } + } + +if (i == it915_coeff_tab_count) + error =ERROR_INVALID_BW ; + +return error; +} + +/* +* Program the bandwidth related parameters to IT9135. +* +* @param struct it9135_data the handle of IT9135. +* @param chip The index of IT9135. The possible values are 0~7. +* NOTE: When the architecture is set to ARCHITECTURE_DCA +* this parameter is regard as don't care. +* @param bandwidth DVB channel bandwidth in KHz. The possible values +* are 5000, 6000, 7000, and 8000 (KHz). +* @param adc_freq The value of desire internal ADC frequency (Hz) ex: 20480000. +* @return ERROR_NO_ERROR: successful, non-zero error code otherwise. +*/ +static unsigned long it9135_select_bandwidth (struct it9135_data *data, +unsigned char chip, +unsigned short bandwidth, +unsigned long adc_freq) +{ +unsigned long error =ERROR_NO_ERROR ; +struct it9135_coeff_param coeff; +unsigned char temp0; +unsigned char temp1; +unsigned char temp2; +unsigned char temp3; +unsigned char buffer[36 ]; +unsigned char bw; +unsigned char adc_multiplier; + +switch (bandwidth) { +case 5000 : + bw =3 ; +break ; +case 6000 :
drivers/media/dvb/dvb-usb/it9135-fe.c line 1063
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ bw =0 ; +break ; +case 7000 : + bw =1 ; +break ; +case 8000 : + bw =2 ; +break ; +default : + error =ERROR_INVALID_BW ;
-EINVAL
Quoted 1,062 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +1062
-0+ goto exit; + } + + error = +it9135_write_reg_bits (data, chip,PROCESSOR_OFDM , g_reg_bw, + reg_bw_pos, reg_bw_len, bw); +if (error) + goto exit; + +/* Program CFOE */ + coeff.adc_freq = adc_freq; + coeff.bandwidth = bandwidth; + error =it9135_get_coeff_param (&coeff); +if (error) + goto exit; + +/* Get ADC multiplier */ + error = +it9135_read_reg (data,0 ,PROCESSOR_OFDM , adcx2, &adc_multiplier); +if (error) + goto exit; + +if (adc_multiplier ==1 ) { + coeff.coeff1_2048Nu /=2 ; + coeff.coeff1_4096Nu /=2 ; + coeff.coeff1_8191Nu /=2 ; + coeff.coeff1_8192Nu /=2 ; + coeff.coeff1_8193Nu /=2 ; + coeff.coeff2_2k /=2 ; + coeff.coeff2_4k /=2 ; + coeff.coeff2_8k /=2 ; + } + +/* Write coeff1_2048Nu */ +/* Get unsigned char0 */ + temp0 = (unsigned char )(coeff.coeff1_2048Nu &0x000000FF ); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff1_2048Nu &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff1_2048Nu &0x00FF0000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff1_2048Nu &0x03000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_2048_coeff1_25_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_2048_coeff1_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_2048_coeff1_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_2048_coeff1_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff2_2k */ +/* Get unsigned char0 */ + temp0 = (unsigned char )((coeff.coeff2_2k &0x000000FF )); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff2_2k &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff2_2k &0x00FF0000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff2_2k &0x01000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_2k_coeff2_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_2k_coeff2_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_2k_coeff2_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_2k_coeff2_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff1_8191Nu */ +/* Get unsigned char0 */ + temp0 = (unsigned char )((coeff.coeff1_8191Nu &0x000000FF )); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff1_8191Nu &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff1_8191Nu &0x00FFC000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff1_8191Nu &0x03000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_8191_coeff1_25_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_8191_coeff1_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_8191_coeff1_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_8191_coeff1_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff1_8192Nu */ +/* Get unsigned char0 */ + temp0 = (unsigned char )(coeff.coeff1_8192Nu &0x000000FF ); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff1_8192Nu &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff1_8192Nu &0x00FFC000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff1_8192Nu &0x03000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_8192_coeff1_25_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_8192_coeff1_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_8192_coeff1_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_8192_coeff1_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff1_8193Nu */ +/* Get unsigned char0 */ + temp0 = (unsigned char )((coeff.coeff1_8193Nu &0x000000FF )); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff1_8193Nu &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff1_8193Nu &0x00FFC000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff1_8193Nu &0x03000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_8193_coeff1_25_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_8193_coeff1_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_8193_coeff1_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_8193_coeff1_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff2_8k */ +/* Get unsigned char0 */ + temp0 = (unsigned char )((coeff.coeff2_8k &0x000000FF )); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff2_8k &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff2_8k &0x00FF0000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff2_8k &0x01000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_8k_coeff2_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_8k_coeff2_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_8k_coeff2_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_8k_coeff2_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff1_4096Nu */ +/* Get unsigned char0 */ + temp0 = (unsigned char )(coeff.coeff1_4096Nu &0x000000FF ); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff1_4096Nu &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff1_4096Nu &0x00FF0000 ) >>16 ); +/* Get unsigned char3[1:0] */ +/* Bit[7:2] will be written soon and so don't have to care them */ + temp3 = (unsigned char )((coeff.coeff1_4096Nu &0x03000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_4096_coeff1_25_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_4096_coeff1_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_4096_coeff1_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_4096_coeff1_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Write coeff2_4k */ +/* Get unsigned char0 */ + temp0 = (unsigned char )((coeff.coeff2_4k &0x000000FF )); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.coeff2_4k &0x0000FF00 ) >>8 ); +/* Get unsigned char2 */ + temp2 = (unsigned char )((coeff.coeff2_4k &0x00FF0000 ) >>16 ); +/* Get unsigned char3 */ + temp3 = (unsigned char )((coeff.coeff2_4k &0x01000000 ) >>24 ); + +/* Big endian to make 8051 happy */ + buffer[cfoe_NS_4k_coeff2_24 - cfoe_NS_2048_coeff1_25_24] = temp3; + buffer[cfoe_NS_4k_coeff2_23_16 - cfoe_NS_2048_coeff1_25_24] = temp2; + buffer[cfoe_NS_4k_coeff2_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[cfoe_NS_4k_coeff2_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Get unsigned char0 */ + temp0 = (unsigned char )(coeff.bfsfcw_fftindex_ratio &0x00FF ); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.bfsfcw_fftindex_ratio &0xFF00 ) >>8 ); + +/* Big endian to make 8051 happy */ + buffer[bfsfcw_fftindex_ratio_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[bfsfcw_fftindex_ratio_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + +/* Get unsigned char0 */ + temp0 = (unsigned char )(coeff.fftindex_bfsfcw_ratio &0x00FF ); +/* Get unsigned char1 */ + temp1 = (unsigned char )((coeff.fftindex_bfsfcw_ratio &0xFF00 ) >>8 ); + +/* Big endian to make 8051 happy */ + buffer[fftindex_bfsfcw_ratio_15_8 - cfoe_NS_2048_coeff1_25_24] = temp1; + buffer[fftindex_bfsfcw_ratio_7_0 - cfoe_NS_2048_coeff1_25_24] = temp0; + + error = +it9135_write_regs (data, chip,PROCESSOR_OFDM , + cfoe_NS_2048_coeff1_25_24,36 , buffer); +if (error) + goto exit; + +exit: +return error; +} + +/* +* The type defination of band table. +*/ +struct it9135_freq_band { +unsigned long mini;/* The minimum frequency of this band */ +unsigned long max;/* The maximum frequency of this band */ +}; + +static struct it9135_freq_band it9135_freq_band_tab[] = { + {30000 ,300000 },/* VHF 30MHz ~ 300MHz */ + {300000 ,1000000 },/* UHF 300MHz ~ 1000MHz */ + {1670000 ,1680000 }/* L-BAND */ +}; + +static int it915_freq_band_tab_count =ARRAY_SIZE (it9135_freq_band_tab); + +/* +* Set frequency. +* +* @param struct it9135_data the handle of IT9135. +* @param chip The index of IT9135. The possible values are 0~7. +* @param frequency The desired frequency. +* @return ERROR_NO_ERROR: successful, other non-zero error code otherwise. +*/ +static unsigned long it9135_set_frequency (struct it9135_data *data, +unsigned char chip, +unsigned long frequency) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned long freq = frequency; +unsigned char band; +unsigned char i; + +/* Clear easy mode flag first */ + error = +it9135_write_reg (data, chip,PROCESSOR_OFDM , Training_Mode,0x00 ); +if (error) + goto exit; + +/* Clear empty_channel_status lock flag */ + error = +it9135_write_reg (data, chip,PROCESSOR_OFDM , empty_channel_status, +0x00 ); +if (error) + goto exit; + +/* Clear MPEG2 lock flag */ + error = +it9135_write_reg_bits (data, chip,PROCESSOR_OFDM , + r_mp2if_sync_byte_locked, + mp2if_sync_byte_locked_pos, + mp2if_sync_byte_locked_len,0x00 ); +if (error) + goto exit; + +/* Determine frequency band */ + band =0xFF ; +for (i =0 ; i < it915_freq_band_tab_count; i++) { +if ((frequency >= it9135_freq_band_tab[i].mini) + && (frequency <= it9135_freq_band_tab[i].max)) { + band = i; +break ; + } + } + error =it9135_write_reg (data, chip,PROCESSOR_OFDM , FreBand, band); +if (error) + goto exit; + +if (data->chip_num >1 && chip ==0 ) + freq +=100 ; +else if (data->chip_num >1 && chip ==1 ) + freq -=100 ; + + error = +it9135_tuner_set_freq (data, chip, data->bandwidth[chip], frequency); +if (error) + goto exit; + +/* Trigger ofsm */ + error =it9135_write_reg (data, chip,PROCESSOR_OFDM , trigger_ofsm,0 ); +if (error) + goto exit; + + data->frequency[chip] = frequency; + +exit: +return error; +} + +/* +* Load firmware to device +* +* @param struct it9135_data the handle of IT9135. +* @fw_codes pointer to fw binary. +* @fw_segs pointer to fw segments. +* @fw_parts pointer to fw partition. +* @return ERROR_NO_ERROR: successful, non-zero error code otherwise. +*/ +static unsigned long it9135_load_firmware (struct it9135_data *data, +unsigned char *fw_codes, +struct it9135_segment *fw_segs, +unsigned char *fw_parts) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned long beginPartition =0 ; +unsigned long endPartition =0 ; +unsigned long version; +unsigned long firmwareLength; +unsigned char *firmwareCodesPointer; +unsigned short command; +unsigned long i; + +/* Define I2C master speed, the default value 0x07 means 366KHz (1000000000 / (24.4 * 16 * User_I2C_SPEED)). */ +#define User_I2C_SPEED 0x07 + +/* Set I2C master clock speed. */ + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , + p_reg_one_cycle_counter_tuner, User_I2C_SPEED); +if (error) + goto exit; + + firmwareCodesPointer = fw_codes; + + beginPartition =0 ; + endPartition = fw_parts[0 ]; + +for (i = beginPartition; i < endPartition; i++) { + firmwareLength = fw_segs[i].length; +if (fw_segs[i].type ==0 ) { +/* Dwonload firmware */ + error = +it9135_cmd_sendcommand (data,CMD_FW_DOWNLOAD_BEGIN , +0 ,PROCESSOR_LINK ,0 ,NULL , +0 ,NULL ); +if (error) + goto exit; + error = +it9135_cmd_loadfirmware (data, firmwareLength, + firmwareCodesPointer); +if (error) + goto exit; + error = +it9135_cmd_sendcommand (data,CMD_FW_DOWNLOAD_END ,0 , +PROCESSOR_LINK ,0 ,NULL ,0 , +NULL ); +if (error) + goto exit; + }else if (fw_segs[i].type ==1 ) { +/* Copy firmware */ + error = +it9135_cmd_sendcommand (data, +CMD_SCATTER_WRITE ,0 , +PROCESSOR_LINK , + firmwareLength, + firmwareCodesPointer,0 , +NULL ); +if (error) + goto exit; + }else { +/* Direct write firmware */ + command = + (unsigned short )(firmwareCodesPointer[0 ] <<8 ) + + (unsigned short )firmwareCodesPointer[1 ]; + error = +it9135_cmd_sendcommand (data, command,0 , +PROCESSOR_LINK , + firmwareLength -2 , + firmwareCodesPointer +2 ,0 , +NULL ); +if (error) + goto exit; + } + firmwareCodesPointer += firmwareLength; + } + +/* Boot */ + error = +it9135_cmd_sendcommand (data,CMD_BOOT ,0 ,PROCESSOR_LINK ,0 ,NULL , +0 ,NULL ); +if (error) + goto exit; + +mdelay (10 ); + +/* Check if firmware is running */ + version =0 ; + error =it9135_get_fw_ver (data,PROCESSOR_LINK , &version); +if (error) + goto exit; +if (version ==0 ) + error =ERROR_BOOT_FAIL ; + +exit: +return error; +} + +/* +* Load initial script to device +* +* @param struct it9135_data the handle of IT9135. +* @script_sets pointer to script_sets. +* @scripts pointer to fw scripts. +* @tuner_script_sets pointer to tunerScriptSets. +* @tuner_scripts pointer to tunerScripts. +* @return ERROR_NO_ERROR: successful, non-zero error code otherwise. +*/ +static unsigned long it9135_load_script (struct it9135_data *data, +unsigned short *script_sets, +struct it9135_val_set *scripts, +unsigned short *tuner_script_sets, +struct it9135_val_set *tuner_scripts) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short beginScript; +unsigned short endScript; +unsigned char i, value1 =0 , prechip_version =0 , supportRelay = +0 , chip_num =0 , bufferLens =1 ; +unsigned short j; +unsigned char buffer[20 ] = {0 }; +unsigned long tunerAddr, tunerAddrTemp; + +/* Querry SupportRelayCommandWrite */ + error =it9135_read_reg (data,0 ,PROCESSOR_OFDM ,0x004D , &supportRelay); +if (error) + goto exit; + +if (supportRelay && data->chip_num ==2 ) + chip_num =1 ; +else + chip_num = data->chip_num; + +/* Enable RelayCommandWrite */ +if (supportRelay) { + error =it9135_write_reg (data,0 ,PROCESSOR_OFDM ,0x004E ,1 ); +if (error) + goto exit; + } + +if ((script_sets[0 ] !=0 ) && (scripts !=NULL )) { + beginScript =0 ; + endScript = script_sets[0 ]; + +for (i =0 ; i < chip_num; i++) { +/* Load OFSM init script */ +for (j = beginScript; j < endScript; j++) { + tunerAddr = tunerAddrTemp = scripts[j].address; + buffer[0 ] = scripts[j].value; + +while (j < endScript && bufferLens <20 ) { + tunerAddrTemp +=1 ; +if (tunerAddrTemp != + scripts[j +1 ].address) +break ; + + buffer[bufferLens] = + scripts[j +1 ].value; + bufferLens++; + j++; + } + + error = +it9135_write_regs (data, i,PROCESSOR_OFDM , + tunerAddr, bufferLens, + buffer); +if (error) + goto exit; + bufferLens =1 ; + } + } + } + +/* Distinguish chip type */ + error = +it9135_read_reg (data,0 ,PROCESSOR_LINK , chip_version_7_0, &value1); +if (error) + goto exit; + + error = +it9135_read_reg (data,0 ,PROCESSOR_LINK , prechip_version_7_0, + &prechip_version); +if (error) + goto exit; + +if ((tuner_script_sets[0 ] !=0 ) && (tuner_scripts !=NULL )) { +if (tuner_script_sets[1 ] == tuner_script_sets[0 ] + && !(data->chip_ver ==0xF8 && prechip_version ==0xEA )) { +/* New version */ + beginScript = tuner_script_sets[0 ]; + endScript = tuner_script_sets[0 ] + tuner_script_sets[1 ]; + }else { +/* Old version */ + beginScript =0 ; + endScript = tuner_script_sets[0 ]; + } + +for (i =0 ; i < chip_num; i++) { +/* Load tuner init script */ +for (j = beginScript; j < endScript; j++) { + tunerAddr = tunerAddrTemp = + tuner_scripts[j].address; + buffer[0 ] = tuner_scripts[j].value; + +while (j < endScript && bufferLens <20 ) { + tunerAddrTemp +=1 ; +if (tunerAddrTemp != + tuner_scripts[j +1 ].address) +break ; + + buffer[bufferLens] = + tuner_scripts[j +1 ].value; + bufferLens++; + j++; + } + + error = +it9135_write_regs (data, i,PROCESSOR_OFDM , + tunerAddr, bufferLens, + buffer); +if (error) + goto exit; + bufferLens =1 ; + } + } + } + +/* Disable RelayCommandWrite */ +if (supportRelay) { + error =it9135_write_reg (data,0 ,PROCESSOR_OFDM ,0x004E ,0 ); +if (error) + goto exit; + } + +exit: +return error; +} + +/* end of local functions */ + +unsigned long it9135_write_regs (struct it9135_data *data,unsigned char chip, +unsigned char processor,unsigned long reg_addr, +unsigned long w_buff_len,unsigned char *w_buff) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short command; +unsigned char buffer[255 ]; +unsigned long buff_len; +unsigned long remain_len; +unsigned long send_len; +unsigned long i; +unsigned char reg_addr_len =2 ; + +it9135_enter_mutex (data); + +if (w_buff_len ==0 ) + goto exit; +if (reg_addr_len >4 ) { + error =ERROR_PROTOCOL_FORMAT_INVALID ; + goto exit; + } + +if ((w_buff_len +12 ) >IT9135_MAX_CMD_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +/* add frame header */ + command =it9135_build_command (CMD_REG_DEMOD_WRITE , processor, chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + buffer[4 ] = (unsigned char )w_buff_len; + buffer[5 ] = (unsigned char )reg_addr_len; + buffer[6 ] = (unsigned char )((reg_addr) >>24 );/* Get first unsigned char of reg. address */ + buffer[7 ] = (unsigned char )((reg_addr) >>16 );/* Get second unsigned char of reg. address */ + buffer[8 ] = (unsigned char )((reg_addr) >>8 );/* Get third unsigned char of reg. address */ + buffer[9 ] = (unsigned char )(reg_addr);/* Get fourth unsigned char of reg. address */ + +/* add frame data */ +for (i =0 ; i < w_buff_len; i++) + buffer[10 + i] = w_buff[i]; + +/* add frame check-sum */ + buff_len =10 + w_buff_len; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +/* send frame */ + i =0 ; + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + i = (remain_len >IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, i, &buffer[send_len]); +if (error) + goto exit; + + send_len += i; + remain_len -= i; + } + +/* get reply frame */ + buff_len =5 ; + error =it9135_cmd_bus_rx (data, buff_len, buffer); +if (error) + goto exit; + +/* remove check-sum from reply frame */ + error =it9135_cmd_remove_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +exit: +it9135_leave_mutex (data); +return error; +} + +unsigned long it9135_write_gen_regs (struct it9135_data *data, +unsigned char chip, +unsigned char interfaceIndex, +unsigned char slaveAddress, +unsigned char buff_len, +unsigned char *buffer) +{ +unsigned char w_buff[256 ]; +unsigned char i; + + w_buff[0 ] = buff_len; + w_buff[1 ] = interfaceIndex; + w_buff[2 ] = slaveAddress; + +for (i =0 ; i < buff_len; i++) + w_buff[3 + i] = buffer[i]; + +return it9135_cmd_sendcommand (data,CMD_GENERIC_WRITE , chip, +PROCESSOR_LINK , buff_len +3 , w_buff,0 , +NULL ); +} + +unsigned long it9135_write_reg (struct it9135_data *data,unsigned char chip, +unsigned char processor,unsigned long reg_addr, +unsigned char value) +{ +return it9135_write_regs (data, chip, processor, reg_addr,1 , &value); +} + +unsigned long it9135_write_ee_vals (struct it9135_data *data,unsigned char chip, +unsigned short reg_addr, +unsigned char w_buff_len, +unsigned char *w_buff) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short command; +unsigned char buffer[255 ]; +unsigned long buff_len; +unsigned long remain_len; +unsigned long send_len; +unsigned long i; +unsigned char eeprom_addr =1 ; +unsigned char reg_addr_len =1 ; + +it9135_enter_mutex (data); + +if (w_buff_len ==0 ) + goto exit; + +if ((unsigned long )(w_buff_len +11 ) >IT9135_MAX_CMD_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +/* add frame header */ + command = +it9135_build_command (CMD_REG_EEPROM_WRITE ,PROCESSOR_LINK , chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + buffer[4 ] = (unsigned char )w_buff_len; + buffer[5 ] = (unsigned char )eeprom_addr; + buffer[6 ] = (unsigned char )reg_addr_len; + buffer[7 ] = (unsigned char )(reg_addr >>8 );/* Get high unsigned char of reg. address */ + buffer[8 ] = (unsigned char )reg_addr;/* Get low unsigned char of reg. address */ + +/* add frame data */ +for (i =0 ; i < w_buff_len; i++) + buffer[9 + i] = w_buff[i]; + +/* add frame check-sum */ + buff_len =9 + w_buff_len; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +/* send frame */ + i =0 ; + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + i = (remain_len >IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, i, &buffer[send_len]); +if (error) + goto exit; + + send_len += i; + remain_len -= i; + } + +/* get reply frame */ + buff_len =5 ; + error =it9135_cmd_bus_rx (data, buff_len, buffer); +if (error) + goto exit; + +/* remove check-sum from reply frame */ + error =it9135_cmd_remove_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +exit: +it9135_leave_mutex (data); +return error; +} + +static unsigned char it9135_reg_bit_mask[8 ] = { +0x01 ,0x03 ,0x07 ,0x0F ,0x1F ,0x3F ,0x7F ,0xFF +}; + +unsigned long it9135_write_reg_bits (struct it9135_data *data, +unsigned char chip,unsigned char processor, +unsigned long reg_addr, +unsigned char position, +unsigned char length,unsigned char value) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp; + +if (length ==8 ) { + error = +it9135_write_regs (data, chip, processor, reg_addr,1 , + &value); + }else { + error = +it9135_read_regs (data, chip, processor, reg_addr,1 , &temp); +if (error) + goto exit; + + temp = +REG_CREATE (it9135_reg_bit_mask, value, temp, position, + length); + + error = +it9135_write_regs (data, chip, processor, reg_addr,1 , + &temp); + } + +exit: +return error; +} + +unsigned long it9135_read_reg (struct it9135_data *data,unsigned char chip, +unsigned char processor,unsigned long reg_addr, +unsigned char *value) +{ +return it9135_read_regs (data, chip, processor, reg_addr,1 , value); +} + +unsigned long it9135_read_regs (struct it9135_data *data,unsigned char chip, +unsigned char processor,unsigned long reg_addr, +unsigned long r_buff_len,unsigned char *r_buff) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short command; +unsigned char buffer[255 ]; +unsigned long buff_len; +unsigned long send_len; +unsigned long remain_len; +unsigned long i, k; +unsigned char reg_addr_len =2 ; + +it9135_enter_mutex (data); + +if (r_buff_len ==0 ) + goto exit; +if (reg_addr_len >4 ) { + error =ERROR_PROTOCOL_FORMAT_INVALID ; + goto exit; + } + +if ((r_buff_len +5 ) >IT9135_MAX_PKT_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +if ((r_buff_len +5 ) >IT9135_MAX_CMD_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +/* add frame header */ + command =it9135_build_command (CMD_REG_DEMOD_READ , processor, chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + buffer[4 ] = (unsigned char )r_buff_len; + buffer[5 ] = (unsigned char )reg_addr_len; + buffer[6 ] = (unsigned char )(reg_addr >>24 );/* Get first unsigned char of reg. address */ + buffer[7 ] = (unsigned char )(reg_addr >>16 );/* Get second unsigned char of reg. address */ + buffer[8 ] = (unsigned char )(reg_addr >>8 );/* Get third unsigned char of reg. address */ + buffer[9 ] = (unsigned char )(reg_addr);/* Get fourth unsigned char of reg. address */ + +/* add frame check-sum */ + buff_len =10 ; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +/* send frame */ + i =0 ; + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + i = (remain_len >IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, i, &buffer[send_len]); +if (error) + goto exit; + + send_len += i; + remain_len -= i; + } + +/* get reply frame */ + buff_len =5 + r_buff_len; + error =it9135_cmd_bus_rx (data, buff_len, buffer); +if (error) + goto exit; + +/* remove check-sum from reply frame */ + error =it9135_cmd_remove_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +for (k =0 ; k < r_buff_len; k++) + r_buff[k] = buffer[k +3 ]; + +exit: +it9135_leave_mutex (data); +return error; +} + +unsigned long it9135_read_gen_regs (struct it9135_data *data,unsigned char chip, +unsigned char interfaceIndex, +unsigned char slaveAddress, +unsigned char buff_len, +unsigned char *buffer) +{ +unsigned char w_buff[3 ]; + + w_buff[0 ] = buff_len; + w_buff[1 ] = interfaceIndex; + w_buff[2 ] = slaveAddress; + +return it9135_cmd_sendcommand (data,CMD_GENERIC_READ , chip, +PROCESSOR_LINK ,3 , w_buff, buff_len, + buffer); +} + +unsigned long it9135_read_ee_vals (struct it9135_data *data,unsigned char chip, +unsigned short reg_addr, +unsigned char r_buff_len, +unsigned char *r_buff) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short command; +unsigned char buffer[255 ]; +unsigned long buff_len; +unsigned long remain_len; +unsigned long send_len; +unsigned long i, k; +unsigned char eeprom_addr =1 ; +unsigned char reg_addr_len =1 ; + +it9135_enter_mutex (data); + +if (r_buff_len ==0 ) + goto exit; + +if ((unsigned long )(r_buff_len +5 ) >IT9135_MAX_PKT_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +if ((unsigned long )(r_buff_len +5 ) >IT9135_MAX_CMD_SIZE ) { + error =ERROR_INVALID_DATA_LENGTH ; + goto exit; + } + +/* add command header */ + command = +it9135_build_command (CMD_REG_EEPROM_READ ,PROCESSOR_LINK , chip); + buffer[1 ] = (unsigned char )(command >>8 ); + buffer[2 ] = (unsigned char )command; + buffer[3 ] = (unsigned char )data->cmd_seq++; + buffer[4 ] = (unsigned char )r_buff_len; + buffer[5 ] = (unsigned char )eeprom_addr; + buffer[6 ] = (unsigned char )reg_addr_len; + buffer[7 ] = (unsigned char )(reg_addr >>8 );/* Get high unsigned char of reg. address */ + buffer[8 ] = (unsigned char )reg_addr;/* Get low unsigned char of reg. address */ + +/* add frame check-sum */ + buff_len =9 ; + error =it9135_cmd_add_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +/* send frame */ + i =0 ; + send_len =0 ; + remain_len = buff_len; +while (remain_len >0 ) { + i = (remain_len >IT9135_MAX_PKT_SIZE ) ? (IT9135_MAX_PKT_SIZE ) + : (remain_len); + error =it9135_cmd_bus_tx (data, i, &buffer[send_len]); +if (error) + goto exit; + + send_len += i; + remain_len -= i; + } + +/* get reply frame */ + buff_len =5 + r_buff_len; + error =it9135_cmd_bus_rx (data, buff_len, buffer); +if (error) + goto exit; + +/* remove frame check-sum */ + error =it9135_cmd_remove_checksum (data, &buff_len, buffer); +if (error) + goto exit; + +for (k =0 ; k < r_buff_len; k++) + r_buff[k] = buffer[k +3 ]; + +exit: +it9135_leave_mutex (data); +return error; +} + +unsigned long it9135_read_reg_bits (struct it9135_data *data, +unsigned char chip,unsigned char processor, +unsigned long reg_addr, +unsigned char position,unsigned char length, +unsigned char *value) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp =0 ; + + error =it9135_read_regs (data, chip, processor, reg_addr,1 , &temp); +if (error) + goto exit; + +if (length ==8 ) { + *value = temp; + }else { + temp =REG_GET (it9135_reg_bit_mask, temp, position, length); + *value = temp; + } + +exit: +return error; +} + +unsigned long it9135_get_fw_ver (struct it9135_data *data, +unsigned char processor,unsigned long *version) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char w_buff[1 ] = {1 }; +unsigned char r_buff[4 ] = {0 ,0 ,0 ,0 }; + + error = +it9135_cmd_sendcommand (data,CMD_QUERYINFO ,0 , processor,1 , w_buff, +4 , r_buff); +if (error) + goto exit; + + *version = + (unsigned long )(((unsigned long )r_buff[0 ] <<24 ) + + ((unsigned long )r_buff[1 ] <<16 ) + + ((unsigned long )r_buff[2 ] <<8 ) + + (unsigned long )r_buff[3 ]); + +exit: +return error; +} + +/* +* Set the counting range for Post-Viterbi and Post-Viterbi. +* +* @param struct it9135_data the handle of IT9135. +* @param chip The index of IT9135. The possible values are 0~7. +* NOTE: When the architecture is set to ARCHITECTURE_DCA +* this parameter is regard as don't care. +* @param post_err_cnt the number of super frame for Pre-Viterbi (24 bits). +* @param post_bit_cnt the number of packet unit for Post-Viterbi (16 bits). +* @return ERROR_NO_ERROR: successful, non-zero error code otherwise. +*/ +unsigned long it9135_get_post_vitber (struct it9135_data *data, +unsigned char chip, +unsigned long *post_err_cnt, +unsigned long *post_bit_cnt, +unsigned short *abort_cnt) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned long err_cnt; +unsigned long bit_cnt; +unsigned char buffer[7 ]; +unsigned short abort; + + *post_err_cnt =0 ; + *post_bit_cnt =0 ; + + error = +it9135_read_regs (data, chip,PROCESSOR_OFDM , + rsd_abort_packet_cnt_7_0, + r_rsd_packet_unit_15_8 - rsd_abort_packet_cnt_7_0 + +1 , buffer); +if (error) + goto exit; + + abort = ((unsigned short ) + buffer[rsd_abort_packet_cnt_15_8 - rsd_abort_packet_cnt_7_0] + <<8 ) + buffer[rsd_abort_packet_cnt_7_0 - + rsd_abort_packet_cnt_7_0]; + err_cnt = ((unsigned long ) + buffer[rsd_bit_err_cnt_23_16 - + rsd_abort_packet_cnt_7_0] <<16 ) + ((unsigned long ) + buffer + [rsd_bit_err_cnt_15_8 + - + rsd_abort_packet_cnt_7_0] + <<8 ) + + buffer[rsd_bit_err_cnt_7_0 - rsd_abort_packet_cnt_7_0]; + bit_cnt = ((unsigned long ) + buffer[r_rsd_packet_unit_15_8 - + rsd_abort_packet_cnt_7_0] <<8 ) + + buffer[r_rsd_packet_unit_7_0 - rsd_abort_packet_cnt_7_0]; + +if (bit_cnt ==0 ) { +/*error = ERROR_RSD_PKT_CNT_0; */ + *post_err_cnt =1 ; + *post_bit_cnt =2 ; + *abort_cnt =1000 ; + goto exit; + } + + *abort_cnt = abort; + bit_cnt = bit_cnt - (unsigned long )abort; +if (bit_cnt ==0 ) { + *post_err_cnt =1 ; + *post_bit_cnt =2 ; + }else { + *post_err_cnt = err_cnt - (unsigned long )abort *8 *8 ; + *post_bit_cnt = bit_cnt *204 *8 ; + } + +exit: +return error; +}
drivers/media/dvb/dvb-usb/it9135-fe.c line 2135
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ +/* NorDig 3.4.4.6 & Table 3.4 */ +static int it9135_Pref_values[3 ][5 ] = { + {-93 ,-91 ,-90 ,-89 ,-88 },/* QPSK CodeRate 1/2 ~ 7/8 Pref Values */ + {-87 ,-85 ,-84 ,-83 ,-82 },/* 16QAM CodeRate 1/2 ~ 7/8 Pref Values */ + {-82 ,-80 ,-78 ,-77 ,-76 },/* 64QAM CodeRate 1/2 ~ 7/8 Pref Values */ +}; + +/* +* Get siganl quality.
typo: signal instead of siganl
Quoted 8 lines
+ *
+ * @param structit9135_datathe handle of IT9135.
+ * @param chip The index of IT9135. The possible values are 0~7.
+ * NOTE: When the architecture is set toARCHITECTURE_DCA
+ * this parameter is regard as don't care.
+ * @param quality The value of signal quality.
+ * @returnERROR_NO_ERROR: successful, non-zero error code otherwise.
+ */
drivers/media/dvb/dvb-usb/it9135-fe.c line 2152
Quoted 9 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +9
-0+unsigned long it9135_get_signal_quality (struct it9135_data *data, +unsigned char chip, +unsigned char *quality) +{ +unsigned long error =ERROR_NO_ERROR ; + + error =it9135_read_reg (data, chip,PROCESSOR_OFDM , signal_quality, quality); + +return (error);
Don't use parenthesis for return. You should check your code with:
scripts/checkpatch.pl
This script points you about trivial Coding Style issues like that.
Quoted 164 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +164
-0+} + +unsigned long it9135_get_strength (struct it9135_data *data,unsigned char chip, +unsigned char *strength) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp, lna_gain_offset; +struct it9135_ch_modulation ch_modulation; +int Prec, Pref, Prel; + + error = +it9135_read_reg (data, chip,PROCESSOR_OFDM , var_p_inband, &temp); +if (error) + goto exit; + + error =it9135_get_ch_modulation (data, chip, &ch_modulation); +if (error) + goto exit; + +if (ch_modulation.frequency <300000 ) + lna_gain_offset =7 ;/* VHF */ +else + lna_gain_offset =14 ;/* UHF */ + + Prec = (temp -100 ) - lna_gain_offset; + +if (ch_modulation.priority ==PRIORITY_HIGH ) + Pref = it9135_Pref_values[ch_modulation.constellation] + [ch_modulation.h_code_rate]; +else + Pref = it9135_Pref_values[ch_modulation.constellation] + [ch_modulation.l_code_rate]; + + Prel = Prec - Pref; + +if (Prel <-15 ) + *strength =0 ; +else if ((-15 <= Prel) && (Prel <0 )) + *strength = (unsigned char )((2 * (Prel +15 )) /3 ); +else if ((0 <= Prel) && (Prel <20 )) + *strength = (unsigned char )(4 * Prel +10 ); +else if ((20 <= Prel) && (Prel <35 )) + *strength = ((unsigned char )(2 * (Prel -20 )) /3 +90 ); +else if (Prel >=35 ) + *strength =100 ; + +exit: +return error; +} + +/* @param strength_dbm: DBm */ +unsigned long it9135_get_strength_dbm (struct it9135_data *data, +unsigned char chip,long *strength_dbm) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp; + + error = +it9135_read_reg (data, chip,PROCESSOR_OFDM , var_p_inband, &temp); +if (error) + goto exit; + + *strength_dbm = (long )(temp -100 ); + +exit: +return error; +} + +unsigned long it9135_load_ir_tab (struct it9135_data *data, +unsigned short tab_len,unsigned char *table) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char base_high; +unsigned char base_low; +unsigned short reg_base; +unsigned short i; + + error = +it9135_read_reg (data,0 ,PROCESSOR_LINK , ir_table_start_15_8, + &base_high); +if (error) + goto exit; + error = +it9135_read_reg (data,0 ,PROCESSOR_LINK , ir_table_start_7_0, + &base_low); +if (error) + goto exit; + + reg_base = (unsigned short )(base_high <<8 ) + (unsigned short )base_low; + +if (reg_base) { +for (i =0 ; i < tab_len; i++) { + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , + reg_base + i, table[i]); +if (error) + goto exit; + } + } + +exit: +return error; +} + +static struct it9135_freq_clk it9135_freq_clk_tab[2 ] = { + {12000 ,20250000 }, + {20480 ,20480000 } +}; + +unsigned long it9135_dev_init (struct it9135_data *data,unsigned char chip_num, +unsigned short saw_band,unsigned char streamType, +unsigned char architecture) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned long crystal =0 ; +unsigned long adc =0 ; +unsigned long fcw =0 ; +unsigned char buffer[4 ]; +unsigned long version =0 ; +unsigned short *tuner_script_sets =NULL ; +struct it9135_val_set *tuner_scripts =NULL ; +unsigned char i; +unsigned char var[2 ]; + +#define IT9135_IF_FREQUENCY 0 +#define IT9135_IF_INVERSION 0 +/* Define I2C address of secondary chip when Diversity mode or PIP mode is active. */ +#define IT9135_CHIP2_I2C_ADDR 0x3A + + data->chip_num = chip_num; + data->fcw =0x00000000 ; + data->frequency[0 ] =642000 ; + data->frequency[1 ] =642000 ; + data->inited =0 ; + data->host_if[0 ] =0 ; + data->cmd_seq =0 ; + data->pid_info.pid_init =0 ; + + error = +it9135_read_reg (data,0 ,PROCESSOR_LINK , chip_version_7_0, + &data->chip_ver); +if (error) + goto exit; + error = +it9135_read_regs (data,0 ,PROCESSOR_LINK , chip_version_7_0 +1 ,2 , + var); +if (error) + goto exit; + data->chip_type = var[1 ] <<8 | var[0 ]; + +if (data->busId ==0xFFFF || data->tuner_desc.id ==0xFFFF ) + goto exit; + + error =it9135_get_fw_ver (data,PROCESSOR_LINK , &version); +if (error) + goto exit; +if (version !=0 ) + data->booted =1 ; +else + data->booted =0 ; + +/*if (data->chip_type == 0x9135 && data->chip_ver == 2) { +data->fw_codes = FirmwareV2_codes; +data->fw_segs = FirmwareV2_segments;
drivers/media/dvb/dvb-usb/it9135-fe.c line 2326
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+data->fw_parts = FirmwareV2_partitions; +data->script_sets = FirmwareV2_scriptSets; +data->scripts = FirmwareV2_scripts; +} else { +data->fw_codes = Firmware_codes; +data->fw_segs = Firmware_segments; +data->fw_parts = Firmware_partitions; +data->script_sets = Firmware_scriptSets; +data->scripts = Firmware_scripts; +} */
Better to put commented code like the above into:
#if 0 dead_code();
#endif
Also, identation of the above is broken.
Btw, doesn't it needed to be uncommented? Maybe you should add there something like:
#if 0 /* FIXME: add support for version 2 of the chipset */
...
#endif
Quoted 2,019 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +2019
-0+ tuner_script_sets = data->tuner_desc.script_sets; + tuner_scripts = data->tuner_desc.scripts; + + error = +it9135_read_reg_bits (data,0 ,PROCESSOR_LINK , + r_io_mux_pwron_clk_strap, + io_mux_pwron_clk_strap_pos, + io_mux_pwron_clk_strap_len, &i); +if (error) + goto exit; + + data->crystal_Freq = it9135_freq_clk_tab[0 ].crystal_Freq; + data->adc_freq = it9135_freq_clk_tab[0 ].adc_freq; + +/* Write secondary I2C address to device */ +/* Enable or disable clock for 2nd chip power saving */ +if (data->chip_num >1 ) { + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , + second_i2c_address,IT9135_CHIP2_I2C_ADDR ); +if (error) + goto exit; + + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , p_reg_top_clkoen, +1 ); +if (error) + goto exit; + + }else { + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , + second_i2c_address,0x00 ); +if (error) + goto exit; + + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , p_reg_top_clkoen, +0 ); +if (error) + goto exit; + } + +/* Load firmware */ +if (data->fw_codes !=NULL ) { +if (!data->booted) { + error = +it9135_load_firmware (data, + data->fw_codes, data->fw_segs, + &data->fw_parts); +if (error) + goto exit; + data->booted =1 ; + } + } + +/* Set I2C master clock 100k in order to support tuner I2C. */ + error = +it9135_write_reg (data,0 ,PROCESSOR_LINK , + p_reg_one_cycle_counter_tuner,0x1a ); +if (error) + goto exit; + +for (i =0 ; i < data->chip_num; i++) { + error =it9135_write_reg (data, i,PROCESSOR_OFDM ,0xEC4C ,0x68 ); +if (error) + goto exit; +mdelay (10 ); + } + +if (data->chip_type ==0x9135 && data->chip_ver ==1 ) { +/* Open tuner */ +for (i =0 ; i < data->chip_num; i++) { + +/* Set 0xD827 to 0 as open drain for tuner i2c */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_padodpu,0 ); +if (error) + goto exit; + +/* Set 0xD829 to 0 as push pull for tuner AGC */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_agc_od,0 ); +if (error) + goto exit; + } + +for (i =0 ; i < data->chip_num; i++) { + error =it9135_tuner_init (data, i); +if (error) + goto exit; + } + } + +for (i =0 ; i < data->chip_num; i++) { +/* Tell firmware the type of tuner. */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_link_ofsm_dummy_15_8, + (unsigned char )data->tuner_desc.id); +if (error) + goto exit; + } + +/* Initialize OFDM */ +if (data->booted) { +for (i =0 ; i < data->chip_num; i++) { +/* Set read-update bit to 1 for constellation */ + error = +it9135_write_reg_bits (data, i, +PROCESSOR_OFDM , + p_reg_feq_read_update, + reg_feq_read_update_pos, + reg_feq_read_update_len,1 ); +if (error) + goto exit; + +/* Enable FEC Monitor */ + error = +it9135_write_reg_bits (data, i, +PROCESSOR_OFDM , + p_fec_vtb_rsd_mon_en, + fec_vtb_rsd_mon_en_pos, + fec_vtb_rsd_mon_en_len,1 ); +if (error) + goto exit; + } + +/* Compute ADC and load them to device */ + error = +it9135_compute_crystal (data, + (long )data->crystal_Freq *1000 , + &crystal); +if (error) + goto exit; + + buffer[0 ] = (unsigned char )(crystal &0x000000FF ); + buffer[1 ] = (unsigned char )((crystal &0x0000FF00 ) >>8 ); + buffer[2 ] = (unsigned char )((crystal &0x00FF0000 ) >>16 ); + buffer[3 ] = (unsigned char )((crystal &0xFF000000 ) >>24 ); +for (i =0 ; i < data->chip_num; i++) { + error = +it9135_write_regs (data, i,PROCESSOR_OFDM , + crystal_clk_7_0,4 , buffer); +if (error) + goto exit; + } + +/* Compute ADC and load them to device */ + error =it9135_compute_adc (data, (long )data->adc_freq, &adc); +if (error) + goto exit; + + buffer[0 ] = (unsigned char )(adc &0x000000FF ); + buffer[1 ] = (unsigned char )((adc &0x0000FF00 ) >>8 ); + buffer[2 ] = (unsigned char )((adc &0x00FF0000 ) >>16 ); +for (i =0 ; i < data->chip_num; i++) { + error = +it9135_write_regs (data, i,PROCESSOR_OFDM , + p_reg_f_adc_7_0,3 , buffer); +if (error) + goto exit; + } + +/* Compute FCW and load them to device */ + error = +it9135_compute_fcw (data, + (long )data->adc_freq, + (long )IT9135_IF_FREQUENCY , +IT9135_IF_INVERSION , &fcw); +if (error) + goto exit; + data->fcw = fcw; + + buffer[0 ] = (unsigned char )(fcw &0x000000FF ); + buffer[1 ] = (unsigned char )((fcw &0x0000FF00 ) >>8 ); + buffer[2 ] = (unsigned char )((fcw &0x007F0000 ) >>16 ); +for (i =0 ; i < data->chip_num; i++) { + error = +it9135_write_regs (data, i, +PROCESSOR_OFDM , bfs_fcw_7_0, + bfs_fcw_22_16 - bfs_fcw_7_0 +1 , + buffer); +if (error) + goto exit; + } + } + +/* Load script */ +if (data->scripts !=NULL ) { + error = +it9135_load_script (data, data->script_sets, + data->scripts, tuner_script_sets, + tuner_scripts); +if (error) + goto exit; + } + +if ((data->chip_type ==0x9135 && data->chip_ver ==2 ) + || data->chip_type ==0x9175 ) { +for (i =0 ; i < data->chip_num; i++) { + error = +it9135_write_reg (data, i,PROCESSOR_OFDM , + trigger_ofsm,0x01 ); +if (error) + goto exit; + } + +/* Open tuner */ +for (i =0 ; i < data->chip_num; i++) { + +/* Set 0xD827 to 0 as open drain for tuner i2c */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_padodpu,0 ); +if (error) + goto exit; + +/* Set 0xD829 to 0 as push pull for tuner AGC */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_agc_od,0 ); +if (error) + goto exit; + } + +for (i =0 ; i < data->chip_num; i++) { + error =it9135_tuner_init (data, i); +if (error) + goto exit; + } + } + +/* Set the desired stream type */ + error =it9135_set_stream_type (data, streamType); +if (error) + goto exit; + +/* Set the desired architecture type */ + error =it9135_set_arch (data, architecture); +if (error) + goto exit; + +for (i =0 ; i < data->chip_num; i++) { +/* Set H/W MPEG2 locked detection */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_lock3_out,1 ); +if (error) + goto exit; + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_padmiscdrsr,1 ); +if (error) + goto exit; +/* Set registers for driving power 0xD830 */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_padmiscdr2,0 ); +if (error) + goto exit; +/* enhance the performance while using DIP crystals */ + error =it9135_write_reg (data, i,PROCESSOR_OFDM ,0xEC57 ,0 ); +if (error) + goto exit; + error =it9135_write_reg (data, i,PROCESSOR_OFDM ,0xEC58 ,0 ); +if (error) + goto exit; +/* Set ADC frequency multiplier */ + error =it9135_set_multiplier (data, Multiplier_2X); +if (error) + goto exit; +/* Set registers for driving power 0xD831 */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_padmiscdr4,0 ); +if (error) + goto exit; +/* Set registers for driving power 0xD832 */ + error = +it9135_write_reg (data, i,PROCESSOR_LINK , + p_reg_top_padmiscdr8,0 ); +if (error) + goto exit; + } + + data->inited =1 ; + +exit: +return error; +} + +unsigned long it9135_tps_locked (struct it9135_data *data,unsigned char chip, +int *locked) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp; + + *locked =0 ; + + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , p_fd_tpsd_lock, + fd_tpsd_lock_pos, fd_tpsd_lock_len, &temp); +if (error) + goto exit; +if (temp) + *locked =1 ; + +exit: +return error; +} + +unsigned long it9135_mp2_locked (struct it9135_data *data,unsigned char chip, +int *locked) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp; + + *locked =0 ; + + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , + r_mp2if_sync_byte_locked, + mp2if_sync_byte_locked_pos, + mp2if_sync_byte_locked_len, &temp); +if (error) + goto exit; + +if (temp) + *locked =1 ; + +exit: +return error; +} + +unsigned long it9135_freq_locked (struct it9135_data *data,unsigned char chip, +int *locked) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned short empty_loop =0 ; +unsigned short tps_loop =0 ; +unsigned short mpeg2_loop =0 ; +unsigned char channels[2 ]; +unsigned char begin; +unsigned char end; +unsigned char i; +unsigned char empty_ch =1 ; +unsigned char tps_locked =0 ; +int retry =1 ; + +check_lock: + *locked =0 ; + +if (data->architecture ==ARCHITECTURE_DCA ) { + begin =0 ; + end = data->chip_num; + }else { + begin = chip; + end = begin +1 ; + } + +for (i = begin; i < end; i++) { + data->statistic[i].presented =0 ; + data->statistic[i].locked =0 ; + data->statistic[i].quality =0 ; + data->statistic[i].strength =0 ; + } + + channels[0 ] =2 ; + channels[1 ] =2 ; +while (empty_loop <40 ) { +for (i = begin; i < end; i++) { + error = +it9135_read_reg (data, i,PROCESSOR_OFDM , + empty_channel_status, &channels[i]); +if (error) + goto exit; + } +if ((channels[0 ] ==1 ) || (channels[1 ] ==1 )) { + empty_ch =0 ; +break ; + } +if ((channels[0 ] ==2 ) && (channels[1 ] ==2 )) { + empty_ch =1 ; + goto exit; + } +mdelay (25 ); + empty_loop++; + } + +if (empty_ch ==1 ) + goto exit; + +while (tps_loop <50 ) { +for (i = begin; i < end; i++) { +/* TPS check */ + error = +it9135_tps_locked (data, i, + &data->statistic[i].presented); +if (error) + goto exit; +if (data->statistic[i].presented) { + tps_locked =1 ; +break ; + } + } + +if (tps_locked ==1 ) +break ; + +mdelay (25 ); + tps_loop++; + } + +if (tps_locked ==0 ) + goto exit; + +while (mpeg2_loop <40 ) { +if (data->architecture ==ARCHITECTURE_DCA ) { + error = +it9135_mp2_locked (data,0 , + &data->statistic[0 ].locked); +if (error) + goto exit; +if (data->statistic[0 ].locked) { +for (i = begin; i < end; i++) { + data->statistic[i].quality =80 ; + data->statistic[i].strength =80 ; + } + *locked =1 ; +break ; + } + }else { + error = +it9135_mp2_locked (data, chip, + &data->statistic[chip].locked); +if (error) + goto exit; +if (data->statistic[chip].locked) { + data->statistic[chip].quality =80 ; + data->statistic[chip].strength =80 ; + *locked =1 ; +break ; + } + } +mdelay (25 ); + mpeg2_loop++; + } +for (i = begin; i < end; i++) { + data->statistic[i].quality =0 ; + data->statistic[i].strength =20 ; + } + +exit: +if (*locked ==0 && retry ==1 ) { + retry =0 ; + mpeg2_loop =0 ; + tps_loop =0 ; + empty_loop =0 ; + empty_ch =1 ; + tps_locked =0 ; +/* Clear empty_channel_status lock flag */ + error = +it9135_write_reg (data, chip,PROCESSOR_OFDM , + empty_channel_status,0x00 ); +if (error) + goto exit; + +/* Trigger ofsm */ + error = +it9135_write_reg (data, chip,PROCESSOR_OFDM , trigger_ofsm, +0 ); +if (error) + goto exit; + + goto check_lock; + } + +return error; +} + +unsigned long it9135_get_ch_modulation (struct it9135_data *data, +unsigned char chip, +struct it9135_ch_modulation + *ch_modulation) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char temp; + +/* Get constellation type */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , + g_reg_tpsd_const, reg_tpsd_const_pos, + reg_tpsd_const_len, &temp); +if (error) + goto exit; + ch_modulation->constellation = temp; + +/* Get TPS hierachy and alpha value */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , + g_reg_tpsd_hier, reg_tpsd_hier_pos, + reg_tpsd_hier_len, &temp); +if (error) + goto exit; + ch_modulation->hierarchy = temp; + +/* Get high/low priority */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , g_reg_dec_pri, + reg_dec_pri_pos, reg_dec_pri_len, &temp); +if (error) + goto exit; +if (temp) + ch_modulation->priority =PRIORITY_HIGH ; +else + ch_modulation->priority =PRIORITY_LOW ; + +/* Get high code rate */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , + g_reg_tpsd_hpcr, reg_tpsd_hpcr_pos, + reg_tpsd_hpcr_len, &temp); +if (error) + goto exit; + ch_modulation->h_code_rate = temp; + +/* Get low code rate */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , + g_reg_tpsd_lpcr, reg_tpsd_lpcr_pos, + reg_tpsd_lpcr_len, &temp); +if (error) + goto exit; + ch_modulation->l_code_rate = temp; + +/* Get guard interval */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , g_reg_tpsd_gi, + reg_tpsd_gi_pos, reg_tpsd_gi_len, &temp); +if (error) + goto exit; + ch_modulation->interval = temp; + +/* Get FFT mode */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , + g_reg_tpsd_txmod, reg_tpsd_txmod_pos, + reg_tpsd_txmod_len, &temp); +if (error) + goto exit; + ch_modulation->trans_mode = temp; + +/* Get bandwidth */ + error = +it9135_read_reg_bits (data, chip,PROCESSOR_OFDM , g_reg_bw, + reg_bw_pos, reg_bw_len, &temp); +if (error) + goto exit; + ch_modulation->bandwidth = temp; + +/* Get frequency */ + ch_modulation->frequency = data->frequency[chip]; + +exit: +return error; +} + +unsigned long it9135_acquire_ch (struct it9135_data *data,unsigned char chip, +unsigned short bandwidth, +unsigned long frequency) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char begin; +unsigned char end; +unsigned char i; + +if (data->architecture ==ARCHITECTURE_DCA ) { + begin =0 ; + end = data->chip_num; + }else { + begin = chip; + end = begin +1 ; + } + +for (i = begin; i < end; i++) { + error = +it9135_select_bandwidth (data, i, bandwidth, data->adc_freq); +if (error) + goto exit; + data->bandwidth[i] = bandwidth; + } + + error =it9135_mask_dca_output (data); +if (error) + goto exit; + +/* Set frequency */ +for (i = begin; i < end; i++) { + error =it9135_set_frequency (data, i, frequency); +if (error) + goto exit; + } + +exit: +return error; +}Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
drivers/media/dvb/dvb-usb/it9135-fe.c line 2945
Quoted 10 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +10
-0+ +unsigned long it9135_set_stream_type (struct it9135_data *data, +unsigned char streamType) +{ +unsigned long error =ERROR_NO_ERROR ; +unsigned char i; + +for (i =0 ; i < data->chip_num; i++) { + error = + it9135_write_reg_bits(data, i, PROCESSOR_OFDM,
The above function seems weird for me. Maximum value for SNR in Linux should be 65535, and not 32. It seems that all you need is to do something like (for CONSTELLATION_64QAM. Same logic applies also to the other constellation):
if (snr_value >= 0x626BE)
*snr = 65535;
else {
u64 snr64 = snr_value * 65536;
*snr = do_div_u64 (snr64, 0x626BE);
}drivers/media/dvb/dvb-usb/it9135-fe.c
Quoted 196 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +196
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Please split the tuner code from the main driver. How are tuner is interconnected? Via I2C? If so, the tuner should use I2C core.
drivers/media/dvb/dvb-usb/it9135-fe.h
Quoted 975 lines
drivers/media/dvb/dvb-usb/it9135-fe.c new file +192
-0Lines of this file are not shown. View the raw message.
drivers/media/dvb/dvb-usb/it9135-fe.h new file +777
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Please, don't create your own error space. Error codes on Linux are well defined, and specified at the DVB API spec. For example, the generic error codes are:
http://linuxtv.org/downloads/v4l-dvb-apis/gen_errors.html#gen-errors
And some ioctl's also device special meanings for some error codes, like:
http://linuxtv.org/downloads/v4l-dvb-apis/frontend_fcalls.html#FE_SET_FRONTEND
drivers/media/dvb/dvb-usb/it9135.c
Quoted 1,126 lines
drivers/media/dvb/dvb-usb/it9135-fe.h new file +855
-0Lines of this file are not shown. View the raw message.
drivers/media/dvb/dvb-usb/it9135.c new file +265
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
No! Please use the standard request_firmware() call, instead of implementing it by hand.
drivers/media/dvb/dvb-usb/it9135.c
Quoted 359 lines
drivers/media/dvb/dvb-usb/it9135.c new file +359
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
What are those "ID" values? tuner type? if so, please put those "magic" numbers into defines.
drivers/media/dvb/dvb-usb/it9135.c
Quoted 1,555 lines
drivers/media/dvb/dvb-usb/it9135.c new file +1555
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
What does that "@@@@@@" mean?
drivers/media/dvb/dvb-usb/it9135.c
Quoted 143 lines
drivers/media/dvb/dvb-usb/it9135.c new file +143
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Hmm... from the above code, it seems that remote controller is supported. However, I'm not seeing it referenced here.
Quoted 331 lines
drivers/media/dvb/dvb-usb/it9135.c new file +170
-0Lines of this file are not shown. View the raw message.
drivers/media/dvb/dvb-usb/it9135.h new file +155
-0Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.