23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
35 static unsigned int verbose = 0;
39 static const struct stb0899_tab stb0899_cn_tab[] = {
69 static const struct stb0899_tab stb0899_dvbsrf_tab[] = {
110 static const struct stb0899_tab stb0899_dvbs2rf_tab[] = {
225 u8 b0[] = { reg >> 8, reg & 0xff };
230 .addr = state->
config->demod_address,
235 .addr = state->
config->demod_address,
246 "Read error, Reg=[0x%02x], Status=%d",
255 return (
unsigned int)
buf;
262 result = _stb0899_read_reg(state, reg);
268 if ((reg != 0xf2ff) && (reg != 0xf6ff) &&
269 (((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
270 _stb0899_read_reg(state, (reg | 0x00ff));
277 u32 stb0899_base_addr,
278 u16 stb0899_reg_offset)
319 tmpaddr = stb0899_reg_offset & 0xff00;
320 if (!(stb0899_reg_offset & 0x8))
321 tmpaddr = stb0899_reg_offset | 0x20;
329 printk(
KERN_ERR "%s ERR(1), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
330 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
351 printk(
KERN_ERR "%s ERR(2), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
352 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
359 printk(
KERN_ERR "%s ERR(3), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
360 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
364 data =
MAKEWORD32(buf[3], buf[2], buf[1], buf[0]);
366 printk(
KERN_DEBUG "%s Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
367 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, data);
377 u32 stb0899_base_addr,
378 u16 stb0899_reg_offset,
423 printk(
KERN_DEBUG "%s Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
424 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data);
429 printk(
KERN_ERR "%s ERR (1), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
430 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data, status);
436 printk(
KERN_ERR "%s ERR (2), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
437 __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data, status);
452 u8 b0[] = { reg >> 8, reg & 0xff };
461 .addr = state->
config->demod_address,
471 printk(
KERN_ERR "%s Read error, Reg=[0x%04x], Count=%u, Status=%d\n",
472 __func__, reg, count, status);
480 if ((reg != 0xf2ff) && (reg != 0xf6ff) &&
481 (((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
482 _stb0899_read_reg(state, (reg | 0x00ff));
488 for (i = 0; i <
count; i++) {
512 memcpy(&buf[2], data, count);
518 for (i = 0; i <
count; i++)
529 if ((((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
535 reg, data[0], count, ret);
557 mclk = (
div + 1) * state->
config->xtal_freq / 6;
575 mdiv = ((6 * Mclk) / state->
config->xtal_freq) - 1;
579 internal->master_clk = stb0899_get_mclk(state);
646 master_clk = stb0899_get_mclk(state);
647 internal->t_agc1 = 0;
648 internal->t_agc2 = 0;
650 internal->mclk = master_clk / 65536
L;
651 internal->rolloff = stb0899_get_alpha(state);
655 internal->agc_gain = 8154;
663 internal->center_freq = 0;
664 internal->av_frame_coarse = 10;
665 internal->av_frame_fine = 20;
666 internal->step_size = 2;
675 static int stb0899_wait_diseqc_fifo_empty(
struct stb0899_state *state,
int timeout)
684 if ((jiffies - start) > timeout) {
705 for (i = 0; i < cmd->
msg_len; i++) {
707 if (stb0899_wait_diseqc_fifo_empty(state, 100) < 0)
719 static int stb0899_wait_diseqc_rxidle(
struct stb0899_state *state,
int timeout)
726 if (jiffies - start > timeout) {
742 if (stb0899_wait_diseqc_rxidle(state, 100) < 0)
751 if (length >
sizeof (reply->
msg)) {
758 for (i = 0; i <
length; i++)
768 static int stb0899_wait_diseqc_txidle(
struct stb0899_state *state,
int timeout)
775 if (jiffies - start > timeout) {
790 if (stb0899_wait_diseqc_txidle(state, 100) < 0)
813 if (stb0899_wait_diseqc_txidle(state, 100) < 0)
843 mclk = stb0899_get_mclk(state);
844 f22_tx = mclk / (tx_freq * 32);
893 for (i = 0; config->
init_dev[
i].address != 0xffff; i++)
911 for (i = 0; config->
init_s2_fec[
i].offset != 0xffff; i++)
919 for (i = 0; config->
init_tst[
i].address != 0xffff; i++)
922 stb0899_init_calc(state);
923 stb0899_diseqc_init(state);
933 if (val < tab[min].
read)
935 else if (val >= tab[max].read)
938 while ((max - min) > 1) {
939 med = (max +
min) / 2;
940 if (val >= tab[min].read && val < tab[med].read)
946 (tab[max].real - tab[min].real) /
954 static int stb0899_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
972 *strength = stb0899_table_lookup(stb0899_dvbsrf_tab,
ARRAY_SIZE(stb0899_dvbsrf_tab) - 1, val);
975 val & 0xff, *strength);
984 *strength = stb0899_table_lookup(stb0899_dvbs2rf_tab,
ARRAY_SIZE(stb0899_dvbs2rf_tab) - 1, val);
987 val & 0x3fff, *strength);
1003 unsigned int val, quant, quantn = -1, est, estn = -1;
1018 *snr = stb0899_table_lookup(stb0899_cn_tab,
ARRAY_SIZE(stb0899_cn_tab) - 1, val);
1020 buf[0], buf[1], val, *snr);
1036 quantn = stb0899_table_lookup(stb0899_quant_tab,
ARRAY_SIZE(stb0899_quant_tab) - 1, quant * 100);
1038 estn = stb0899_table_lookup(stb0899_est_tab,
ARRAY_SIZE(stb0899_est_tab) - 1, est);
1040 val = (quantn - estn) / 10;
1044 quant, quantn, est, estn, val);
1089 "UWP & CSM Lock ! ---> DVB-S2 FE_HAS_CARRIER");
1095 "Packet Delineator Locked ! -----> DVB-S2 FE_HAS_LOCK");
1101 "Packet Delineator found VITERBI ! -----> DVB-S2 FE_HAS_VITERBI");
1106 "Packet Delineator found SYNC ! -----> DVB-S2 FE_HAS_SYNC");
1205 if (stb0899_wait_diseqc_txidle(state, 100) < 0)
1210 div = (
internal->master_clk / 100) / 5632;
1211 div = (div + 5) / 10;
1254 static inline void CONVERT32(
u32 x,
char *
str)
1256 *str++ = (x >> 24) & 0xff;
1257 *str++ = (x >> 16) & 0xff;
1258 *str++ = (x >> 8) & 0xff;
1259 *str++ = (x >> 0) & 0xff;
1267 u32 demod_ver = 0, fec_ver = 0;
1268 char demod_str[5] = { 0 };
1269 char fec_str[5] = { 0 };
1282 dprintk(state->
verbose,
FE_ERROR, 1,
"Demodulator Core ID=[%s], Version=[%d]", (
char *) &demod_str, demod_ver);
1285 if (! (chip_id > 0)) {
1295 static void stb0899_set_delivery(
struct stb0899_state *state)
1399 static void stb0899_set_iterations(
struct stb0899_state *state)
1407 iter_scale = 17 * (
internal->master_clk / 1000);
1408 iter_scale += 410000;
1409 iter_scale /= (
internal->srate / 1000000);
1435 SearchRange = 10000000;
1440 stb0899_set_delivery(state);
1442 if (state->
config->tuner_set_rfsiggain) {
1445 else if (
internal->srate > 5000000)
1449 state->
config->tuner_set_rfsiggain(fe, gain);
1452 if (i_params->
srate <= 5000000)
1453 stb0899_set_mclk(state, config->
lo_clk);
1455 stb0899_set_mclk(state, config->
hi_clk);
1461 internal->freq = i_params->
freq;
1462 internal->srate = i_params->
srate;
1469 internal->srch_range = SearchRange + 1500000 + (i_params->
srate / 5);
1470 internal->derot_percent = 30;
1476 if (state->
config->tuner_set_bandwidth)
1478 if (state->
config->tuner_get_bandwidth)
1492 "-------------------------------------> DVB-S LOCK !");
1508 internal->freq = i_params->
freq;
1509 internal->srate = i_params->
srate;
1510 internal->srch_range = SearchRange;
1515 if (state->
config->tuner_set_bandwidth)
1517 if (state->
config->tuner_get_bandwidth)
1529 stb0899_set_iterations(state);
1536 "-------------------------------------> DVB-S2 LOCK !");
1558 static int stb0899_get_frontend(
struct dvb_frontend *fe)
1579 .name =
"STB0899 Multistandard",
1580 .frequency_min = 950000,
1581 .frequency_max = 2150000,
1582 .frequency_stepsize = 0,
1583 .frequency_tolerance = 0,
1584 .symbol_rate_min = 5000000,
1585 .symbol_rate_max = 45000000,
1593 .release = stb0899_release,
1594 .init = stb0899_init,
1595 .sleep = stb0899_sleep,
1600 .get_frontend_algo = stb0899_frontend_algo,
1601 .search = stb0899_search,
1602 .get_frontend = stb0899_get_frontend,
1605 .read_status = stb0899_read_status,
1606 .read_snr = stb0899_read_snr,
1607 .read_signal_strength = stb0899_read_signal_strength,
1608 .read_ber = stb0899_read_ber,
1610 .set_voltage = stb0899_set_voltage,
1611 .set_tone = stb0899_set_tone,
1613 .diseqc_send_master_cmd = stb0899_send_diseqc_msg,
1614 .diseqc_recv_slave_reply = stb0899_recv_slave_reply,
1615 .diseqc_send_burst = stb0899_send_diseqc_burst,
1633 state->
internal.inversion = inversion;
1637 printk(
"%s: Exiting .. !\n", __func__);
1641 printk(
"%s: Attaching STB0899 \n", __func__);