10 #include <linux/kernel.h>
11 #include <linux/i2c.h>
24 #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB9000: "); printk(args); printk("\n"); } } while (0)
25 #define MAX_NUMBER_OF_FRONTENDS 6
35 #define DIB9000_PID_FILTER_CTRL 0
36 #define DIB9000_PID_FILTER 1
59 #define DIB9000_GPIO_DEFAULT_DIRECTIONS 0xffff
61 #define DIB9000_GPIO_DEFAULT_VALUES 0x0000
63 #define DIB9000_GPIO_DEFAULT_PWM_POS 0xffff
72 struct dib9000_fe_memory_map {
84 #define MBX_MAX_WORDS (256 - 200 - 2)
85 #define DIB9000_MSG_CACHE_SIZE 2
110 static const u32 fe_info[44] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0
177 #define FE_MM_W_CHANNEL 0
178 #define FE_MM_W_FE_INFO 1
179 #define FE_MM_RW_SYNC 2
181 #define FE_SYNC_CHANNEL 1
182 #define FE_SYNC_W_GENERIC_MONIT 2
183 #define FE_SYNC_COMPONENT_ACCESS 3
185 #define FE_MM_R_CHANNEL_SEARCH_STATE 3
186 #define FE_MM_R_CHANNEL_UNION_CONTEXT 4
187 #define FE_MM_R_FE_INFO 5
188 #define FE_MM_R_FE_MONITOR 6
190 #define FE_MM_W_CHANNEL_HEAD 7
191 #define FE_MM_W_CHANNEL_UNION 8
192 #define FE_MM_W_CHANNEL_CONTEXT 9
193 #define FE_MM_R_CHANNEL_UNION 10
194 #define FE_MM_R_CHANNEL_CONTEXT 11
195 #define FE_MM_R_CHANNEL_TUNE_STATE 12
197 #define FE_MM_R_GENERIC_MONITORING_SIZE 13
198 #define FE_MM_W_GENERIC_MONITORING 14
199 #define FE_MM_R_GENERIC_MONITORING 15
201 #define FE_MM_W_COMPONENT_ACCESS 16
202 #define FE_MM_RW_COMPONENT_ACCESS_BUFFER 17
230 u32 chunk_size = 126;
235 return dib9000_risc_apb_access_read(state, reg, attribute,
NULL, 0, b, len);
238 state->
msg[0].addr = state->
i2c.i2c_addr >> 1;
239 state->
msg[0].flags = 0;
241 state->
msg[0].len = 2;
242 state->
msg[1].addr = state->
i2c.i2c_addr >> 1;
244 state->
msg[1].buf =
b;
245 state->
msg[1].len = len;
256 l = len < chunk_size ? len : chunk_size;
257 state->
msg[1].len =
l;
258 state->
msg[1].buf =
b;
261 dprintk(
"i2c read error on %d", reg);
268 if (!(attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT))
270 }
while ((ret == 0) && len);
278 {.addr = i2c->
i2c_addr >> 1, .flags = 0,
288 dprintk(
"read register %x error", reg);
297 if (dib9000_read16_attr(state, reg, state->
i2c_read_buffer, 2, 0) != 0)
310 #define dib9000_read16_noinc_attr(state, reg, b, len, attribute) dib9000_read16_attr(state, reg, b, len, (attribute) | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
314 u32 chunk_size = 126;
318 if (state->
platform.
risc.fw_is_running && (reg < 1024)) {
319 if (dib9000_risc_apb_access_write
326 state->
msg[0].addr = state->
i2c.i2c_addr >> 1;
327 state->
msg[0].flags = 0;
329 state->
msg[0].len = len + 2;
334 if (attribute & DATA_BUS_ACCESS_MODE_8BIT)
336 if (attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
340 l = len < chunk_size ? len : chunk_size;
341 state->
msg[0].len = l + 2;
349 if (!(attribute & DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT))
351 }
while ((ret == 0) && len);
373 u8 b[2] = { val >> 8, val & 0xff };
374 return dib9000_write16_attr(state, reg, b, 2, 0);
379 u8 b[2] = { val >> 8, val & 0xff };
380 return dib9000_write16_attr(state, reg, b, 2, attribute);
383 #define dib9000_write(state, reg, buf, len) dib9000_write16_attr(state, reg, buf, len, 0)
384 #define dib9000_write16_noinc(state, reg, buf, len) dib9000_write16_attr(state, reg, buf, len, DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
385 #define dib9000_write16_noinc_attr(state, reg, buf, len, attribute) dib9000_write16_attr(state, reg, buf, len, DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT | (attribute))
387 #define dib9000_mbx_send(state, id, data, len) dib9000_mbx_send_attr(state, id, data, len, 0)
388 #define dib9000_mbx_get_message(state, id, msg, len) dib9000_mbx_get_message_attr(state, id, msg, len, 0)
390 #define MAC_IRQ (1 << 1)
391 #define IRQ_POL_MSK (1 << 4)
393 #define dib9000_risc_mem_read_chunks(state, b, len) dib9000_read16_attr(state, 1063, b, len, DATA_BUS_ACCESS_MODE_8BIT | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
394 #define dib9000_risc_mem_write_chunks(state, buf, len) dib9000_write16_attr(state, 1063, buf, len, DATA_BUS_ACCESS_MODE_8BIT | DATA_BUS_ACCESS_MODE_NO_ADDRESS_INCREMENT)
406 b[4] = (
u8) (addr >> 8);
407 b[5] = (
u8) (addr & 0xff);
411 b[12] = (
u8) (addr >> 8);
412 b[13] = (
u8) (addr & 0xff);
417 b[8] = (
u8) (addr >> 8);
418 b[9] = (
u8) (addr & 0xff);
422 dib9000_write_word(state, 1056, (1 << 15) | 1);
428 struct dib9000_fe_memory_map *
m = &state->
platform.
risc.fe_mm[cmd & 0x7f];
431 !(cmd & 0x80 && m->size < 67))
433 dib9000_risc_mem_setup_cmd(state, m->addr, m->size, cmd & 0x80);
443 dprintk(
"could not get the lock");
446 dib9000_risc_mem_setup(state, cmd | 0x80);
452 static int dib9000_risc_mem_write(
struct dib9000_state *state,
u8 cmd,
const u8 * b)
459 dprintk(
"could not get the lock");
462 dib9000_risc_mem_setup(state, cmd);
478 dib9000_write_word(state, 1024 + offs, 0x000f);
479 dib9000_write_word(state, 1025 + offs, 0);
480 dib9000_write_word(state, 1031 + offs, key);
482 dprintk(
"going to download %dB of microcode", len);
484 dprintk(
"error while downloading microcode for RISC %c",
'A' + risc_id);
488 dprintk(
"Microcode for RISC %c loaded",
'A' + risc_id);
493 static int dib9000_mbx_host_init(
struct dib9000_state *state,
u8 risc_id)
505 dib9000_write_word(state, 1027 + mbox_offs, 0x8000);
509 reset_reg = dib9000_read_word(state, 1027 + mbox_offs);
511 }
while ((reset_reg & 0x8000) && --tries);
513 if (reset_reg & 0x8000) {
514 dprintk(
"MBX: init ERROR, no response from RISC %c",
'A' + risc_id);
521 #define MAX_MAILBOX_TRY 100
534 dprintk(
"could not get the lock");
539 size = dib9000_read_word_attr(state, 1043, attr) & 0xff;
541 dprintk(
"MBX: RISC mbx full, retrying");
554 dprintk(
"--> %02x %d ",
id, len + 1);
555 for (i = 0; i < len; i++)
562 for (i = 0; i < len; i++) {
577 ret = (
u8) dib9000_write_word_attr(state, 1043, 1 << 14, attr);
599 dprintk(
"could not get the lock");
608 *data = dib9000_read_word_attr(state, 1029 + mc_base, attr);
618 for (i = 0; i <
size; i++) {
620 *data = (tmp >> 8) | (tmp << 8);
626 for (i = 0; i < size + 1; i++)
631 dprintk(
"MBX: message is too big for message cache (%d), flushing message", size);
637 dib9000_write_word_attr(state, 1028 + mc_base, 1 << 14, attr);
646 u32 ts = data[1] << 16 | data[0];
647 char *b = (
char *)&data[2];
649 b[2 * (size - 2) - 1] =
'\0';
654 dprintk(
"RISC%d: %d.%04d %s", state->
fe_id, ts / 10000, ts % 10000, *b ? b :
"<emtpy>");
658 static int dib9000_mbx_fetch_to_cache(
struct dib9000_state *state,
u16 attr)
667 size = dib9000_mbx_read(state, block, 1, attr);
671 switch (*block >> 8) {
673 dib9000_risc_debug_buf(state, block + 1, size);
678 dib9000_risc_data_process(state, block + 1, size);
689 dprintk(
"MBX: no free cache-slot found for new message...");
696 return (
u8) (dib9000_read_word_attr(state, 1028, attr) >> 10) & 0x1f;
698 return (
u8) (dib9000_read_word_attr(state, 1044, attr) >> 8) & 0x7f;
709 dprintk(
"could not get the lock");
713 if (dib9000_mbx_count(state, 1, attr))
714 ret = dib9000_mbx_fetch_to_cache(state, attr);
716 dib9000_read_word_attr(state, 1229, attr);
735 if ((*block >> 8) ==
id) {
736 *size = (*block & 0xff) - 1;
737 memcpy(msg, block + 1, (*size) * 2);
747 if (dib9000_mbx_process(state, attr) == -1)
753 dprintk(
"waiting for message %d timed out",
id);
760 static int dib9000_risc_check_version(
struct dib9000_state *state)
772 fw_version = (r[0] << 8) | r[1];
773 dprintk(
"RISC: ver: %d.%02d (IC: %d)", fw_version >> 10, fw_version & 0x3ff, (r[2] << 8) | r[3]);
775 if ((fw_version >> 10) != 7)
778 switch (fw_version & 0x3ff) {
787 dprintk(
"RISC: invalid firmware version");
791 dprintk(
"RISC: valid firmware version");
795 static int dib9000_fw_boot(
struct dib9000_state *state,
const u8 * codeA,
u32 lenA,
const u8 * codeB,
u32 lenB)
798 dib9000_write_word(state, 1225, 0x02);
799 dib9000_write_word(state, 1226, 0x05);
802 dib9000_write_word(state, 1542, 1);
805 dib9000_write_word(state, 1074, 0);
806 dib9000_write_word(state, 1075, 0);
809 dib9000_write_word(state, 1237, 0);
813 dib9000_write_word(state, 1024, 2);
815 dib9000_write_word(state, 1024, 15);
817 dib9000_write_word(state, 1040, 2);
820 dib9000_firmware_download(state, 0, 0x1234, codeA, lenA);
822 dib9000_firmware_download(state, 1, 0x1234, codeB, lenB);
826 dib9000_write_word(state, 1024, 0);
828 dib9000_write_word(state, 1040, 0);
831 if (dib9000_mbx_host_init(state, 0) != 0)
834 if (dib9000_mbx_host_init(state, 1) != 0)
840 if (dib9000_risc_check_version(state) != 0)
851 value = dib9000_i2c_read16(client, 896);
852 if (value != 0x01b3) {
853 dprintk(
"wrong Vendor ID (0x%x)", value);
857 value = dib9000_i2c_read16(client, 897);
858 if (value != 0x4000 && value != 0x4001 && value != 0x4002 && value != 0x4003 && value != 0x4004 && value != 0x4005) {
859 dprintk(
"wrong Device ID (0x%x)", value);
864 if (value == 0x4000 && dib9000_i2c_read16(client, 769) == 0x4000) {
865 dprintk(
"this driver does not work with DiB7000PC");
871 dprintk(
"found DiB7000MA/PA/MB/PB");
896 u16 reg_903 = 0x3fff, reg_904 = 0xffff, reg_905 = 0xffff, reg_906;
904 reg_906 = dib9000_read_word(state, 906 + offset) | 0x3;
918 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 2));
922 reg_903 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10));
923 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 2));
924 reg_906 &= ~((1 << 0));
931 reg_906 &= ~((1 << 0));
938 reg_906 &= ~((1 << 0));
947 reg_904 |= (1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1);
953 dib9000_write_word(state, 903 + offset, reg_903);
954 dib9000_write_word(state, 904 + offset, reg_904);
955 dib9000_write_word(state, 905 + offset, reg_905);
956 dib9000_write_word(state, 906 + offset, reg_906);
963 dib9000_write_word(state, 1817, 0x0003);
965 dib9000_write_word(state, 1227, 1);
966 dib9000_write_word(state, 1227, 0);
968 switch ((state->
revision = dib9000_identify(&state->
i2c))) {
984 dib9000_write_word(state, 1794, dib9000_read_word(state, 1794) & ~(1 << 1));
985 dib9000_write_word(state, 1796, 0);
986 dib9000_write_word(state, 1805, 0x805);
989 dib9000_write_word(state, 898, 0xffff);
990 dib9000_write_word(state, 899, 0xffff);
991 dib9000_write_word(state, 900, 0x0001);
992 dib9000_write_word(state, 901, 0xff19);
993 dib9000_write_word(state, 902, 0x003c);
995 dib9000_write_word(state, 898, 0);
996 dib9000_write_word(state, 899, 0);
997 dib9000_write_word(state, 900, 0);
998 dib9000_write_word(state, 901, 0);
999 dib9000_write_word(state, 902, 0);
1001 dib9000_write_word(state, 911, state->
chip.
d9.cfg.if_drives);
1013 if (address >= 1024 || !state->
platform.
risc.fw_is_running)
1018 mb[0] = (
u16) address;
1024 for (i = 0; i <
s; i++) {
1025 b[i * 2] = (mb[i + 1] >> 8) & 0xff;
1026 b[i * 2 + 1] = (mb[i + 1]) & 0xff;
1035 static int dib9000_risc_apb_access_write(
struct dib9000_state *state,
u32 address,
u16 attribute,
const u8 * b,
u32 len)
1040 if (address >= 1024 || !state->
platform.
risc.fw_is_running)
1045 mb[0] = (
unsigned short)address;
1046 for (i = 0; i < len && i < 20; i += 2)
1047 mb[1 + (i / 2)] = (b[
i] << 8 | b[i + 1]);
1076 if (dib9000_fw_boot(state,
NULL, 0, state->
chip.
d9.cfg.microcode_B_fe_buffer, state->
chip.
d9.cfg.microcode_B_fe_size) != 0)
1081 f = &state->
chip.
d9.cfg.gpio_function[
i];
1101 b[0] = state->
chip.
d9.cfg.subband.size;
1102 for (i = 0; i < state->
chip.
d9.cfg.subband.size; i++) {
1103 b[1 + i * 4] = state->
chip.
d9.cfg.subband.subband[
i].f_mhz;
1104 b[2 + i * 4] = (
u16) state->
chip.
d9.cfg.subband.subband[i].gpio.mask;
1105 b[3 + i * 4] = (
u16) state->
chip.
d9.cfg.subband.subband[
i].gpio.direction;
1106 b[4 + i * 4] = (
u16) state->
chip.
d9.cfg.subband.subband[i].gpio.value;
1113 b[0] = (0 << 8) | 1;
1115 b[1] = (0 << 8) | (0);
1116 b[2] = (
u16) (((state->
chip.
d9.cfg.xtal_clock_khz * 1000) >> 16) & 0xffff);
1117 b[3] = (
u16) (((state->
chip.
d9.cfg.xtal_clock_khz * 1000)) & 0xffff);
1118 b[4] = (
u16) ((state->
chip.
d9.cfg.vcxo_timer >> 16) & 0xffff);
1119 b[5] = (
u16) ((state->
chip.
d9.cfg.vcxo_timer) & 0xffff);
1120 b[6] = (
u16) ((state->
chip.
d9.cfg.timing_frequency >> 16) & 0xffff);
1121 b[7] = (
u16) ((state->
chip.
d9.cfg.timing_frequency) & 0xffff);
1122 b[29] = state->
chip.
d9.cfg.if_drives;
1133 dprintk(
"error : firmware returned %dbytes needed but the used buffer has only %dbytes\n Firmware init ABORTED", size,
1138 for (i = 0; i <
size; i += 2) {
1146 static void dib9000_fw_set_channel_head(
struct dib9000_state *state)
1149 u32 freq = state->
fe[0]->dtv_property_cache.frequency / 1000;
1150 if (state->
fe_id % 2)
1153 b[0] = (
u8) ((freq >> 0) & 0xff);
1154 b[1] = (
u8) ((freq >> 8) & 0xff);
1155 b[2] = (
u8) ((freq >> 16) & 0xff);
1156 b[3] = (
u8) ((freq >> 24) & 0xff);
1157 b[4] = (
u8) ((state->
fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 0) & 0xff);
1158 b[5] = (
u8) ((state->
fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 8) & 0xff);
1159 b[6] = (
u8) ((state->
fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 16) & 0xff);
1160 b[7] = (
u8) ((state->
fe[0]->dtv_property_cache.bandwidth_hz / 1000 >> 24) & 0xff);
1162 if (state->
fe[0]->dtv_property_cache.delivery_system ==
SYS_DVBT)
1167 static int dib9000_fw_get_channel(
struct dvb_frontend *fe)
1170 struct dibDVBTChannel {
1171 s8 spectrum_inversion;
1185 struct dibDVBTChannel *ch;
1189 dprintk(
"could not get the lock");
1202 switch (ch->spectrum_inversion & 0x7) {
1229 switch (ch->guard) {
1247 switch (ch->constellation) {
1249 state->
fe[0]->dtv_property_cache.modulation =
QAM_64;
1252 state->
fe[0]->dtv_property_cache.modulation =
QAM_16;
1255 state->
fe[0]->dtv_property_cache.modulation =
QPSK;
1259 state->
fe[0]->dtv_property_cache.modulation =
QAM_AUTO;
1274 switch (ch->code_rate_hp) {
1276 state->
fe[0]->dtv_property_cache.code_rate_HP =
FEC_1_2;
1279 state->
fe[0]->dtv_property_cache.code_rate_HP =
FEC_2_3;
1282 state->
fe[0]->dtv_property_cache.code_rate_HP =
FEC_3_4;
1285 state->
fe[0]->dtv_property_cache.code_rate_HP =
FEC_5_6;
1288 state->
fe[0]->dtv_property_cache.code_rate_HP =
FEC_7_8;
1292 state->
fe[0]->dtv_property_cache.code_rate_HP =
FEC_AUTO;
1295 switch (ch->code_rate_lp) {
1297 state->
fe[0]->dtv_property_cache.code_rate_LP =
FEC_1_2;
1300 state->
fe[0]->dtv_property_cache.code_rate_LP =
FEC_2_3;
1303 state->
fe[0]->dtv_property_cache.code_rate_LP =
FEC_3_4;
1306 state->
fe[0]->dtv_property_cache.code_rate_LP =
FEC_5_6;
1309 state->
fe[0]->dtv_property_cache.code_rate_LP =
FEC_7_8;
1313 state->
fe[0]->dtv_property_cache.code_rate_LP =
FEC_AUTO;
1322 static int dib9000_fw_set_channel_union(
struct dvb_frontend *fe)
1325 struct dibDVBTChannel {
1326 s8 spectrum_inversion;
1340 struct dibDVBTChannel ch;
1342 switch (state->
fe[0]->dtv_property_cache.inversion) {
1344 ch.spectrum_inversion = 1;
1347 ch.spectrum_inversion = 0;
1351 ch.spectrum_inversion = -1;
1354 switch (state->
fe[0]->dtv_property_cache.transmission_mode) {
1369 switch (state->
fe[0]->dtv_property_cache.guard_interval) {
1387 switch (state->
fe[0]->dtv_property_cache.modulation) {
1389 ch.constellation = 2;
1392 ch.constellation = 1;
1395 ch.constellation = 0;
1399 ch.constellation = -1;
1402 switch (state->
fe[0]->dtv_property_cache.hierarchy) {
1417 switch (state->
fe[0]->dtv_property_cache.code_rate_HP) {
1419 ch.code_rate_hp = 1;
1422 ch.code_rate_hp = 2;
1425 ch.code_rate_hp = 3;
1428 ch.code_rate_hp = 5;
1431 ch.code_rate_hp = 7;
1435 ch.code_rate_hp = -1;
1438 switch (state->
fe[0]->dtv_property_cache.code_rate_LP) {
1440 ch.code_rate_lp = 1;
1443 ch.code_rate_lp = 2;
1446 ch.code_rate_lp = 3;
1449 ch.code_rate_lp = 5;
1452 ch.code_rate_lp = 7;
1456 ch.code_rate_lp = -1;
1460 ch.intlv_native = 1;
1475 dib9000_fw_set_channel_head(state);
1484 dib9000_fw_set_channel_union(fe);
1527 static int dib9000_fw_set_output_mode(
struct dvb_frontend *fe,
int mode)
1530 u16 outreg, smo_mode;
1532 dprintk(
"setting output mode for demod %p to %d", fe, mode);
1539 outreg = (1 << 10) | (1 << 6);
1542 outreg = (1 << 10) | (2 << 6) | (0 << 1);
1545 outreg = (1 << 10) | (4 << 6);
1548 outreg = (1 << 10) | (5 << 6);
1554 dprintk(
"Unhandled output_mode passed to be set for demod %p", &state->
fe[0]);
1558 dib9000_write_word(state, 1795, outreg);
1565 smo_mode = (dib9000_read_word(state, 295) & 0x0010) | (1 << 1);
1566 if (state->
chip.
d9.cfg.output_mpeg2_in_188_bytes)
1567 smo_mode |= (1 << 5);
1568 dib9000_write_word(state, 295, smo_mode);
1572 outreg = to_fw_output_mode(mode);
1576 static int dib9000_tuner_xfer(
struct i2c_adapter *i2c_adap,
struct i2c_msg msg[],
int num)
1579 u16 i, len,
t, index_msg;
1581 for (index_msg = 0; index_msg < num; index_msg++) {
1583 len = msg[index_msg].
len;
1587 if (dib9000_read_word(state, 790) != 0)
1588 dprintk(
"TunerITF: read busy");
1590 dib9000_write_word(state, 784, (
u16) (msg[index_msg].
addr));
1591 dib9000_write_word(state, 787, (len / 2) - 1);
1592 dib9000_write_word(state, 786, 1);
1595 while (dib9000_read_word(state, 790) != (len / 2) && i)
1599 dprintk(
"TunerITF: read failed");
1601 for (i = 0; i < len; i += 2) {
1602 t = dib9000_read_word(state, 785);
1603 msg[index_msg].
buf[
i] = (t >> 8) & 0xff;
1604 msg[index_msg].
buf[i + 1] = (
t) & 0xff;
1606 if (dib9000_read_word(state, 790) != 0)
1607 dprintk(
"TunerITF: read more data than expected");
1610 while (dib9000_read_word(state, 789) &&
i)
1613 dprintk(
"TunerITF: write busy");
1615 len = msg[index_msg].
len;
1619 for (i = 0; i < len; i += 2)
1620 dib9000_write_word(state, 785, (msg[index_msg].
buf[i] << 8) | msg[index_msg].
buf[i + 1]);
1621 dib9000_write_word(state, 784, (
u16) msg[index_msg].
addr);
1622 dib9000_write_word(state, 787, (len / 2) - 1);
1623 dib9000_write_word(state, 786, 0);
1626 while (dib9000_read_word(state, 791) > 0 && i)
1629 dprintk(
"TunerITF: write failed");
1644 static int dib9000_fw_component_bus_xfer(
struct i2c_adapter *i2c_adap,
struct i2c_msg msg[],
int num)
1655 p[2] = msg[0].
addr << 1;
1657 p[3] = (
u8) scl & 0xff;
1658 p[4] = (
u8) (scl >> 8);
1663 p[9] = (
u8) (msg[0].len);
1664 p[10] = (
u8) (msg[0].len >> 8);
1666 p[11] = (
u8) (msg[1].len);
1667 p[12] = (
u8) (msg[1].len >> 8);
1674 dprintk(
"could not get the lock");
1681 dib9000_risc_mem_setup_cmd(state, m->addr, msg[0].
len, 0);
1692 if ((num > 1) && (msg[1].
flags & I2C_M_RD))
1706 .master_xfer = dib9000_tuner_xfer,
1707 .functionality = dib9000_i2c_func,
1711 .master_xfer = dib9000_fw_component_bus_xfer,
1712 .functionality = dib9000_i2c_func,
1747 st->
gpio_dir = dib9000_read_word(st, 773);
1749 st->
gpio_dir |= (dir & 0x1) << num;
1750 dib9000_write_word(st, 773, st->
gpio_dir);
1752 st->
gpio_val = dib9000_read_word(st, 774);
1754 st->
gpio_val |= (val & 0x01) << num;
1755 dib9000_write_word(st, 774, st->
gpio_val);
1765 return dib9000_cfg_gpio(state, num, dir, val);
1777 dprintk(
"pid filter cmd postpone");
1785 dprintk(
"could not get the lock");
1789 val = dib9000_read_word(state, 294 + 1) & 0xffef;
1790 val |= (onoff & 0x1) << 4;
1792 dprintk(
"PID filter enabled %d", onoff);
1793 ret = dib9000_write_word(state, 294 + 1, val);
1807 dprintk(
"pid filter postpone");
1815 dprintk(
"can not add any more pid ctrl cmd");
1820 dprintk(
"could not get the lock");
1823 dprintk(
"Index %x, PID %d, OnOff %d",
id, pid, onoff);
1824 ret = dib9000_write_word(state, 300 + 1 +
id,
1825 onoff ? (1 << 13) | pid : 0);
1834 return dib9000_fw_init(state);
1838 static void dib9000_release(
struct dvb_frontend *demod)
1866 dprintk(
"could not get the lock");
1870 ret = state->
fe[index_frontend]->ops.sleep(state->
fe[index_frontend]);
1887 static int dib9000_get_frontend(
struct dvb_frontend *fe)
1890 u8 index_frontend, sub_index_frontend;
1896 dprintk(
"could not get the lock");
1902 state->
fe[index_frontend]->ops.read_status(state->
fe[index_frontend], &stat);
1904 dprintk(
"TPS lock on the slave%i", index_frontend);
1907 state->
fe[index_frontend]->ops.get_frontend(state->
fe[index_frontend]);
1909 sub_index_frontend++) {
1910 if (sub_index_frontend != index_frontend) {
1911 state->
fe[sub_index_frontend]->dtv_property_cache.modulation =
1912 state->
fe[index_frontend]->dtv_property_cache.modulation;
1913 state->
fe[sub_index_frontend]->dtv_property_cache.inversion =
1914 state->
fe[index_frontend]->dtv_property_cache.inversion;
1915 state->
fe[sub_index_frontend]->dtv_property_cache.transmission_mode =
1916 state->
fe[index_frontend]->dtv_property_cache.transmission_mode;
1917 state->
fe[sub_index_frontend]->dtv_property_cache.guard_interval =
1918 state->
fe[index_frontend]->dtv_property_cache.guard_interval;
1919 state->
fe[sub_index_frontend]->dtv_property_cache.hierarchy =
1920 state->
fe[index_frontend]->dtv_property_cache.hierarchy;
1921 state->
fe[sub_index_frontend]->dtv_property_cache.code_rate_HP =
1922 state->
fe[index_frontend]->dtv_property_cache.code_rate_HP;
1923 state->
fe[sub_index_frontend]->dtv_property_cache.code_rate_LP =
1924 state->
fe[index_frontend]->dtv_property_cache.code_rate_LP;
1925 state->
fe[sub_index_frontend]->dtv_property_cache.rolloff =
1926 state->
fe[index_frontend]->dtv_property_cache.rolloff;
1935 ret = dib9000_fw_get_channel(fe);
1942 state->
fe[index_frontend]->dtv_property_cache.transmission_mode = fe->
dtv_property_cache.transmission_mode;
1943 state->
fe[index_frontend]->dtv_property_cache.guard_interval = fe->
dtv_property_cache.guard_interval;
1946 state->
fe[index_frontend]->dtv_property_cache.code_rate_HP = fe->
dtv_property_cache.code_rate_HP;
1947 state->
fe[index_frontend]->dtv_property_cache.code_rate_LP = fe->
dtv_property_cache.code_rate_LP;
1982 static int dib9000_set_frontend(
struct dvb_frontend *fe)
1985 int sleep_time, sleep_time_slave;
1986 u32 frontend_status;
1987 u8 nbr_pending, exit_condition, index_frontend, index_frontend_success;
1991 if (state->
fe[0]->dtv_property_cache.frequency == 0) {
1992 dprintk(
"dib9000: must specify frequency ");
1996 if (state->
fe[0]->dtv_property_cache.bandwidth_hz == 0) {
1997 dprintk(
"dib9000: must specify bandwidth ");
2003 dprintk(
"could not get the lock");
2012 state->
fe[0]->dtv_property_cache.modulation ==
QAM_AUTO ||
2013 state->
fe[0]->dtv_property_cache.code_rate_HP ==
FEC_AUTO) {
2021 dib9000_fw_set_diversity_in(state->
fe[index_frontend], 1);
2026 state->
fe[index_frontend]->dtv_property_cache.delivery_system =
SYS_DVBT;
2029 dib9000_set_channel_status(state->
fe[index_frontend], &state->
channel_status);
2035 index_frontend_success = 0;
2037 sleep_time = dib9000_fw_tune(state->
fe[0]);
2039 sleep_time_slave = dib9000_fw_tune(state->
fe[index_frontend]);
2041 sleep_time = sleep_time_slave;
2043 sleep_time = sleep_time_slave;
2052 index_frontend_success = 0;
2054 frontend_status = -dib9000_get_status(state->
fe[index_frontend]);
2057 index_frontend_success = index_frontend;
2063 if ((exit_condition != 2) && (nbr_pending == 0))
2066 }
while (exit_condition == 0);
2069 if (exit_condition == 1) {
2077 dprintk(
"tune success on frontend%i", index_frontend_success);
2081 dib9000_get_frontend(state->
fe[0]);
2088 if (index_frontend != index_frontend_success) {
2089 dib9000_set_channel_status(state->
fe[index_frontend], &channel_status);
2096 if (index_frontend != index_frontend_success) {
2097 sleep_time_slave = dib9000_fw_tune(state->
fe[index_frontend]);
2099 sleep_time = sleep_time_slave;
2101 sleep_time = sleep_time_slave;
2111 if (index_frontend != index_frontend_success) {
2112 frontend_status = -dib9000_get_status(state->
fe[index_frontend]);
2117 }
while (nbr_pending != 0);
2120 dib9000_fw_set_output_mode(state->
fe[0], state->
chip.
d9.cfg.output_mode);
2125 dib9000_fw_set_diversity_in(state->
fe[index_frontend - 1], 0);
2129 u8 index_pid_filter_cmd;
2133 for (index_pid_filter_cmd = 0;
2134 index_pid_filter_cmd <= pid_ctrl_index;
2135 index_pid_filter_cmd++) {
2138 state->
pid_ctrl[index_pid_filter_cmd].onoff);
2141 state->
pid_ctrl[index_pid_filter_cmd].id,
2142 state->
pid_ctrl[index_pid_filter_cmd].pid,
2143 state->
pid_ctrl[index_pid_filter_cmd].onoff);
2156 return dib9000_read_word(state, 535);
2166 dprintk(
"could not get the lock");
2170 lock_slave |= dib9000_read_lock(state->
fe[index_frontend]);
2172 lock = dib9000_read_word(state, 535);
2176 if ((lock & 0x8000) || (lock_slave & 0x8000))
2178 if ((lock & 0x3000) || (lock_slave & 0x3000))
2180 if ((lock & 0x0100) || (lock_slave & 0x0100))
2182 if (((lock & 0x0038) == 0x38) || ((lock_slave & 0x0038) == 0x38))
2184 if ((lock & 0x0008) || (lock_slave & 0x0008))
2199 dprintk(
"could not get the lock");
2203 dprintk(
"could not get the lock");
2218 *ber = c[10] << 16 | c[11];
2225 static int dib9000_read_signal_strength(
struct dvb_frontend *fe,
u16 * strength)
2234 dprintk(
"could not get the lock");
2239 state->
fe[index_frontend]->ops.read_signal_strength(state->
fe[index_frontend], &
val);
2240 if (
val > 65535 - *strength)
2247 dprintk(
"could not get the lock");
2260 if (
val > 65535 - *strength)
2278 dprintk(
"could not get the lock");
2289 n = (
val >> 4) & 0xff;
2290 exp = ((
val & 0xf) << 2);
2292 exp += ((
val >> 14) & 0x3);
2293 if ((
exp & 0x20) != 0)
2297 s = (
val >> 6) & 0xFF;
2299 if ((
exp & 0x20) != 0)
2304 u32 t = (s /
n) << 16;
2305 return t + ((s << 16) - n * t) /
n;
2317 dprintk(
"could not get the lock");
2320 snr_master = dib9000_get_snr(fe);
2322 snr_master += dib9000_get_snr(state->
fe[index_frontend]);
2324 if ((snr_master >> 16) != 0) {
2325 snr_master = 10 *
intlog10(snr_master >> 16);
2326 *snr = snr_master / ((1 << 24) / 10);
2335 static int dib9000_read_unc_blocks(
struct dvb_frontend *fe,
u32 * unc)
2342 dprintk(
"could not get the lock");
2346 dprintk(
"could not get the lock");
2373 dprintk(
"%s: not enough memory", __func__);
2378 dprintk(
"%s: not enough memory", __func__);
2383 client.
i2c_addr = default_addr + 16;
2384 dib9000_i2c_write16(&client, 1796, 0x0);
2386 for (k = no_of_demods - 1; k >= 0; k--) {
2388 new_addr = first_addr + (k << 1);
2391 dib9000_i2c_write16(&client, 1817, 3);
2392 dib9000_i2c_write16(&client, 1796, 0);
2393 dib9000_i2c_write16(&client, 1227, 1);
2394 dib9000_i2c_write16(&client, 1227, 0);
2397 dib9000_i2c_write16(&client, 1817, 3);
2398 dib9000_i2c_write16(&client, 1796, 0);
2399 dib9000_i2c_write16(&client, 1227, 1);
2400 dib9000_i2c_write16(&client, 1227, 0);
2402 if (dib9000_identify(&client) == 0) {
2404 if (dib9000_identify(&client) == 0) {
2405 dprintk(
"DiB9000 #%d: not identified", k);
2411 dib9000_i2c_write16(&client, 1795, (1 << 10) | (4 << 6));
2412 dib9000_i2c_write16(&client, 1794, (new_addr << 2) | 2);
2414 dprintk(
"IC %d initialized (to i2c_address 0x%x)", k, new_addr);
2417 for (k = 0; k < no_of_demods; k++) {
2418 new_addr = first_addr | (k << 1);
2421 dib9000_i2c_write16(&client, 1794, (new_addr << 2));
2422 dib9000_i2c_write16(&client, 1795, 0);
2437 u8 index_frontend = 1;
2442 dprintk(
"set slave fe %p to index %i", fe_slave, index_frontend);
2443 state->
fe[index_frontend] = fe_slave;
2447 dprintk(
"too many slave frontend");
2455 u8 index_frontend = 1;
2459 if (index_frontend != 1) {
2460 dprintk(
"remove slave fe %p (index %i)", state->
fe[index_frontend - 1], index_frontend - 1);
2461 state->
fe[index_frontend] =
NULL;
2465 dprintk(
"no frontend to be removed");
2476 return state->
fe[slave_index];
2495 st->
i2c.i2c_adap = i2c_adap;
2496 st->
i2c.i2c_addr = i2c_addr;
2523 if (dib9000_identify(&st->
i2c) == 0)
2543 goto component_bus_add_error;
2545 dib9000_fw_reset(fe);
2549 component_bus_add_error:
2560 .name =
"DiBcom 9000",
2561 .frequency_min = 44250000,
2562 .frequency_max = 867250000,
2563 .frequency_stepsize = 62500,
2571 .release = dib9000_release,
2573 .init = dib9000_wakeup,
2574 .sleep = dib9000_sleep,
2576 .set_frontend = dib9000_set_frontend,
2577 .get_tune_settings = dib9000_fe_get_tune_settings,
2578 .get_frontend = dib9000_get_frontend,
2580 .read_status = dib9000_read_status,
2581 .read_ber = dib9000_read_ber,
2582 .read_signal_strength = dib9000_read_signal_strength,
2583 .read_snr = dib9000_read_snr,
2584 .read_ucblocks = dib9000_read_unc_blocks,