aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/frontends')
-rw-r--r--drivers/media/dvb/frontends/atbm8830_priv.h2
-rw-r--r--drivers/media/dvb/frontends/au8522_decoder.c7
-rw-r--r--drivers/media/dvb/frontends/au8522_dig.c26
-rw-r--r--drivers/media/dvb/frontends/au8522_priv.h5
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c35
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c36
-rw-r--r--drivers/media/dvb/frontends/dib8000.h1
-rw-r--r--drivers/media/dvb/frontends/ds3000.c2
-rw-r--r--drivers/media/dvb/frontends/stv0900_core.c16
-rw-r--r--drivers/media/dvb/frontends/stv090x.c94
-rw-r--r--drivers/media/dvb/frontends/stv090x.h1
-rw-r--r--drivers/media/dvb/frontends/stv6110x.c34
-rw-r--r--drivers/media/dvb/frontends/stv6110x.h1
13 files changed, 170 insertions, 90 deletions
diff --git a/drivers/media/dvb/frontends/atbm8830_priv.h b/drivers/media/dvb/frontends/atbm8830_priv.h
index ce960f76092..d460058d497 100644
--- a/drivers/media/dvb/frontends/atbm8830_priv.h
+++ b/drivers/media/dvb/frontends/atbm8830_priv.h
@@ -18,7 +18,7 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#ifndef __ATBM8830_PRIV_H 22#ifndef __ATBM8830_PRIV_H
23#define __ATBM8830_PRIV_H 23#define __ATBM8830_PRIV_H
24 24
diff --git a/drivers/media/dvb/frontends/au8522_decoder.c b/drivers/media/dvb/frontends/au8522_decoder.c
index 24268ef2753..68dba3a4b4d 100644
--- a/drivers/media/dvb/frontends/au8522_decoder.c
+++ b/drivers/media/dvb/frontends/au8522_decoder.c
@@ -664,6 +664,13 @@ static int au8522_reset(struct v4l2_subdev *sd, u32 val)
664{ 664{
665 struct au8522_state *state = to_state(sd); 665 struct au8522_state *state = to_state(sd);
666 666
667 state->operational_mode = AU8522_ANALOG_MODE;
668
669 /* Clear out any state associated with the digital side of the
670 chip, so that when it gets powered back up it won't think
671 that it is already tuned */
672 state->current_frequency = 0;
673
667 au8522_writereg(state, 0xa4, 1 << 5); 674 au8522_writereg(state, 0xa4, 1 << 5);
668 675
669 return 0; 676 return 0;
diff --git a/drivers/media/dvb/frontends/au8522_dig.c b/drivers/media/dvb/frontends/au8522_dig.c
index a1fed0fa8ed..65f6a36dfb2 100644
--- a/drivers/media/dvb/frontends/au8522_dig.c
+++ b/drivers/media/dvb/frontends/au8522_dig.c
@@ -84,6 +84,14 @@ static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
84 84
85 dprintk("%s(%d)\n", __func__, enable); 85 dprintk("%s(%d)\n", __func__, enable);
86 86
87 if (state->operational_mode == AU8522_ANALOG_MODE) {
88 /* We're being asked to manage the gate even though we're
89 not in digital mode. This can occur if we get switched
90 over to analog mode before the dvb_frontend kernel thread
91 has completely shutdown */
92 return 0;
93 }
94
87 if (enable) 95 if (enable)
88 return au8522_writereg(state, 0x106, 1); 96 return au8522_writereg(state, 0x106, 1);
89 else 97 else
@@ -608,6 +616,13 @@ int au8522_init(struct dvb_frontend *fe)
608 struct au8522_state *state = fe->demodulator_priv; 616 struct au8522_state *state = fe->demodulator_priv;
609 dprintk("%s()\n", __func__); 617 dprintk("%s()\n", __func__);
610 618
619 state->operational_mode = AU8522_DIGITAL_MODE;
620
621 /* Clear out any state associated with the digital side of the
622 chip, so that when it gets powered back up it won't think
623 that it is already tuned */
624 state->current_frequency = 0;
625
611 au8522_writereg(state, 0xa4, 1 << 5); 626 au8522_writereg(state, 0xa4, 1 << 5);
612 627
613 au8522_i2c_gate_ctrl(fe, 1); 628 au8522_i2c_gate_ctrl(fe, 1);
@@ -704,6 +719,15 @@ int au8522_sleep(struct dvb_frontend *fe)
704 struct au8522_state *state = fe->demodulator_priv; 719 struct au8522_state *state = fe->demodulator_priv;
705 dprintk("%s()\n", __func__); 720 dprintk("%s()\n", __func__);
706 721
722 /* Only power down if the digital side is currently using the chip */
723 if (state->operational_mode == AU8522_ANALOG_MODE) {
724 /* We're not in one of the expected power modes, which means
725 that the DVB thread is probably telling us to go to sleep
726 even though the analog frontend has already started using
727 the chip. So ignore the request */
728 return 0;
729 }
730
707 /* turn off led */ 731 /* turn off led */
708 au8522_led_ctrl(state, 0); 732 au8522_led_ctrl(state, 0);
709 733
@@ -932,6 +956,8 @@ struct dvb_frontend *au8522_attach(const struct au8522_config *config,
932 /* setup the state */ 956 /* setup the state */
933 state->config = config; 957 state->config = config;
934 state->i2c = i2c; 958 state->i2c = i2c;
959 state->operational_mode = AU8522_DIGITAL_MODE;
960
935 /* create dvb_frontend */ 961 /* create dvb_frontend */
936 memcpy(&state->frontend.ops, &au8522_ops, 962 memcpy(&state->frontend.ops, &au8522_ops,
937 sizeof(struct dvb_frontend_ops)); 963 sizeof(struct dvb_frontend_ops));
diff --git a/drivers/media/dvb/frontends/au8522_priv.h b/drivers/media/dvb/frontends/au8522_priv.h
index c74c4e72fe9..609cf04bc31 100644
--- a/drivers/media/dvb/frontends/au8522_priv.h
+++ b/drivers/media/dvb/frontends/au8522_priv.h
@@ -34,10 +34,15 @@
34#include "au8522.h" 34#include "au8522.h"
35#include "tuner-i2c.h" 35#include "tuner-i2c.h"
36 36
37#define AU8522_ANALOG_MODE 0
38#define AU8522_DIGITAL_MODE 1
39
37struct au8522_state { 40struct au8522_state {
38 struct i2c_client *c; 41 struct i2c_client *c;
39 struct i2c_adapter *i2c; 42 struct i2c_adapter *i2c;
40 43
44 u8 operational_mode;
45
41 /* Used for sharing of the state between analog and digital mode */ 46 /* Used for sharing of the state between analog and digital mode */
42 struct tuner_i2c_props i2c_props; 47 struct tuner_i2c_props i2c_props;
43 struct list_head hybrid_tuner_instance_list; 48 struct list_head hybrid_tuner_instance_list;
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 40a09981027..afad252abf4 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -814,42 +814,51 @@ EXPORT_SYMBOL(dib3000mc_set_config);
814 814
815int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib3000mc_config cfg[]) 815int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib3000mc_config cfg[])
816{ 816{
817 struct dib3000mc_state st = { .i2c_adap = i2c }; 817 struct dib3000mc_state *dmcst;
818 int k; 818 int k;
819 u8 new_addr; 819 u8 new_addr;
820 820
821 static u8 DIB3000MC_I2C_ADDRESS[] = {20,22,24,26}; 821 static u8 DIB3000MC_I2C_ADDRESS[] = {20,22,24,26};
822 822
823 dmcst = kzalloc(sizeof(struct dib3000mc_state), GFP_KERNEL);
824 if (dmcst == NULL)
825 return -ENODEV;
826
827 dmcst->i2c_adap = i2c;
828
823 for (k = no_of_demods-1; k >= 0; k--) { 829 for (k = no_of_demods-1; k >= 0; k--) {
824 st.cfg = &cfg[k]; 830 dmcst->cfg = &cfg[k];
825 831
826 /* designated i2c address */ 832 /* designated i2c address */
827 new_addr = DIB3000MC_I2C_ADDRESS[k]; 833 new_addr = DIB3000MC_I2C_ADDRESS[k];
828 st.i2c_addr = new_addr; 834 dmcst->i2c_addr = new_addr;
829 if (dib3000mc_identify(&st) != 0) { 835 if (dib3000mc_identify(dmcst) != 0) {
830 st.i2c_addr = default_addr; 836 dmcst->i2c_addr = default_addr;
831 if (dib3000mc_identify(&st) != 0) { 837 if (dib3000mc_identify(dmcst) != 0) {
832 dprintk("-E- DiB3000P/MC #%d: not identified\n", k); 838 dprintk("-E- DiB3000P/MC #%d: not identified\n", k);
839 kfree(dmcst);
833 return -ENODEV; 840 return -ENODEV;
834 } 841 }
835 } 842 }
836 843
837 dib3000mc_set_output_mode(&st, OUTMODE_MPEG2_PAR_CONT_CLK); 844 dib3000mc_set_output_mode(dmcst, OUTMODE_MPEG2_PAR_CONT_CLK);
838 845
839 // set new i2c address and force divstr (Bit 1) to value 0 (Bit 0) 846 // set new i2c address and force divstr (Bit 1) to value 0 (Bit 0)
840 dib3000mc_write_word(&st, 1024, (new_addr << 3) | 0x1); 847 dib3000mc_write_word(dmcst, 1024, (new_addr << 3) | 0x1);
841 st.i2c_addr = new_addr; 848 dmcst->i2c_addr = new_addr;
842 } 849 }
843 850
844 for (k = 0; k < no_of_demods; k++) { 851 for (k = 0; k < no_of_demods; k++) {
845 st.cfg = &cfg[k]; 852 dmcst->cfg = &cfg[k];
846 st.i2c_addr = DIB3000MC_I2C_ADDRESS[k]; 853 dmcst->i2c_addr = DIB3000MC_I2C_ADDRESS[k];
847 854
848 dib3000mc_write_word(&st, 1024, st.i2c_addr << 3); 855 dib3000mc_write_word(dmcst, 1024, dmcst->i2c_addr << 3);
849 856
850 /* turn off data output */ 857 /* turn off data output */
851 dib3000mc_set_output_mode(&st, OUTMODE_HIGH_Z); 858 dib3000mc_set_output_mode(dmcst, OUTMODE_HIGH_Z);
852 } 859 }
860
861 kfree(dmcst);
853 return 0; 862 return 0;
854} 863}
855EXPORT_SYMBOL(dib3000mc_i2c_enumeration); 864EXPORT_SYMBOL(dib3000mc_i2c_enumeration);
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 85468a45c34..2e28b973dfd 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -1324,46 +1324,54 @@ EXPORT_SYMBOL(dib7000p_pid_filter);
1324 1324
1325int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]) 1325int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[])
1326{ 1326{
1327 struct dib7000p_state st = { .i2c_adap = i2c }; 1327 struct dib7000p_state *dpst;
1328 int k = 0; 1328 int k = 0;
1329 u8 new_addr = 0; 1329 u8 new_addr = 0;
1330 1330
1331 dpst = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
1332 if (!dpst)
1333 return -ENOMEM;
1334
1335 dpst->i2c_adap = i2c;
1336
1331 for (k = no_of_demods-1; k >= 0; k--) { 1337 for (k = no_of_demods-1; k >= 0; k--) {
1332 st.cfg = cfg[k]; 1338 dpst->cfg = cfg[k];
1333 1339
1334 /* designated i2c address */ 1340 /* designated i2c address */
1335 new_addr = (0x40 + k) << 1; 1341 new_addr = (0x40 + k) << 1;
1336 st.i2c_addr = new_addr; 1342 dpst->i2c_addr = new_addr;
1337 dib7000p_write_word(&st, 1287, 0x0003); /* sram lead in, rdy */ 1343 dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
1338 if (dib7000p_identify(&st) != 0) { 1344 if (dib7000p_identify(dpst) != 0) {
1339 st.i2c_addr = default_addr; 1345 dpst->i2c_addr = default_addr;
1340 dib7000p_write_word(&st, 1287, 0x0003); /* sram lead in, rdy */ 1346 dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
1341 if (dib7000p_identify(&st) != 0) { 1347 if (dib7000p_identify(dpst) != 0) {
1342 dprintk("DiB7000P #%d: not identified\n", k); 1348 dprintk("DiB7000P #%d: not identified\n", k);
1349 kfree(dpst);
1343 return -EIO; 1350 return -EIO;
1344 } 1351 }
1345 } 1352 }
1346 1353
1347 /* start diversity to pull_down div_str - just for i2c-enumeration */ 1354 /* start diversity to pull_down div_str - just for i2c-enumeration */
1348 dib7000p_set_output_mode(&st, OUTMODE_DIVERSITY); 1355 dib7000p_set_output_mode(dpst, OUTMODE_DIVERSITY);
1349 1356
1350 /* set new i2c address and force divstart */ 1357 /* set new i2c address and force divstart */
1351 dib7000p_write_word(&st, 1285, (new_addr << 2) | 0x2); 1358 dib7000p_write_word(dpst, 1285, (new_addr << 2) | 0x2);
1352 1359
1353 dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr); 1360 dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
1354 } 1361 }
1355 1362
1356 for (k = 0; k < no_of_demods; k++) { 1363 for (k = 0; k < no_of_demods; k++) {
1357 st.cfg = cfg[k]; 1364 dpst->cfg = cfg[k];
1358 st.i2c_addr = (0x40 + k) << 1; 1365 dpst->i2c_addr = (0x40 + k) << 1;
1359 1366
1360 // unforce divstr 1367 // unforce divstr
1361 dib7000p_write_word(&st, 1285, st.i2c_addr << 2); 1368 dib7000p_write_word(dpst, 1285, dpst->i2c_addr << 2);
1362 1369
1363 /* deactivate div - it was just for i2c-enumeration */ 1370 /* deactivate div - it was just for i2c-enumeration */
1364 dib7000p_set_output_mode(&st, OUTMODE_HIGH_Z); 1371 dib7000p_set_output_mode(dpst, OUTMODE_HIGH_Z);
1365 } 1372 }
1366 1373
1374 kfree(dpst);
1367 return 0; 1375 return 0;
1368} 1376}
1369EXPORT_SYMBOL(dib7000p_i2c_enumeration); 1377EXPORT_SYMBOL(dib7000p_i2c_enumeration);
diff --git a/drivers/media/dvb/frontends/dib8000.h b/drivers/media/dvb/frontends/dib8000.h
index b1ee2079963..e0a9ded11df 100644
--- a/drivers/media/dvb/frontends/dib8000.h
+++ b/drivers/media/dvb/frontends/dib8000.h
@@ -109,6 +109,7 @@ static inline void dib8000_pwm_agc_reset(struct dvb_frontend *fe)
109static inline s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode) 109static inline s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode)
110{ 110{
111 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 111 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
112 return 0;
112} 113}
113#endif 114#endif
114 115
diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
index cff3535566f..78001e8bcdb 100644
--- a/drivers/media/dvb/frontends/ds3000.c
+++ b/drivers/media/dvb/frontends/ds3000.c
@@ -719,7 +719,7 @@ static int ds3000_read_snr(struct dvb_frontend *fe, u16 *snr)
719 (ds3000_readreg(state, 0x8d) << 4); 719 (ds3000_readreg(state, 0x8d) << 4);
720 dvbs2_signal_reading = ds3000_readreg(state, 0x8e); 720 dvbs2_signal_reading = ds3000_readreg(state, 0x8e);
721 tmp = dvbs2_signal_reading * dvbs2_signal_reading >> 1; 721 tmp = dvbs2_signal_reading * dvbs2_signal_reading >> 1;
722 if (dvbs2_signal_reading == 0) { 722 if (tmp == 0) {
723 *snr = 0x0000; 723 *snr = 0x0000;
724 return 0; 724 return 0;
725 } 725 }
diff --git a/drivers/media/dvb/frontends/stv0900_core.c b/drivers/media/dvb/frontends/stv0900_core.c
index 01f8f1f802f..4f5e7d3a0e6 100644
--- a/drivers/media/dvb/frontends/stv0900_core.c
+++ b/drivers/media/dvb/frontends/stv0900_core.c
@@ -1583,7 +1583,7 @@ static enum dvbfe_search stv0900_search(struct dvb_frontend *fe,
1583 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1583 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1584 1584
1585 struct stv0900_search_params p_search; 1585 struct stv0900_search_params p_search;
1586 struct stv0900_signal_info p_result; 1586 struct stv0900_signal_info p_result = intp->result[demod];
1587 1587
1588 enum fe_stv0900_error error = STV0900_NO_ERROR; 1588 enum fe_stv0900_error error = STV0900_NO_ERROR;
1589 1589
@@ -1842,6 +1842,19 @@ static void stv0900_release(struct dvb_frontend *fe)
1842 kfree(state); 1842 kfree(state);
1843} 1843}
1844 1844
1845static int stv0900_get_frontend(struct dvb_frontend *fe,
1846 struct dvb_frontend_parameters *p)
1847{
1848 struct stv0900_state *state = fe->demodulator_priv;
1849 struct stv0900_internal *intp = state->internal;
1850 enum fe_stv0900_demod_num demod = state->demod;
1851 struct stv0900_signal_info p_result = intp->result[demod];
1852
1853 p->frequency = p_result.locked ? p_result.frequency : 0;
1854 p->u.qpsk.symbol_rate = p_result.locked ? p_result.symbol_rate : 0;
1855 return 0;
1856}
1857
1845static struct dvb_frontend_ops stv0900_ops = { 1858static struct dvb_frontend_ops stv0900_ops = {
1846 1859
1847 .info = { 1860 .info = {
@@ -1862,6 +1875,7 @@ static struct dvb_frontend_ops stv0900_ops = {
1862 }, 1875 },
1863 .release = stv0900_release, 1876 .release = stv0900_release,
1864 .init = stv0900_init, 1877 .init = stv0900_init,
1878 .get_frontend = stv0900_get_frontend,
1865 .get_frontend_algo = stv0900_frontend_algo, 1879 .get_frontend_algo = stv0900_frontend_algo,
1866 .i2c_gate_ctrl = stv0900_i2c_gate_ctrl, 1880 .i2c_gate_ctrl = stv0900_i2c_gate_ctrl,
1867 .diseqc_send_master_cmd = stv0900_send_master_cmd, 1881 .diseqc_send_master_cmd = stv0900_send_master_cmd,
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index 96972804f4a..425e7a43ae1 100644
--- a/drivers/media/dvb/frontends/stv090x.c
+++ b/drivers/media/dvb/frontends/stv090x.c
@@ -754,11 +754,19 @@ static int stv090x_write_reg(struct stv090x_state *state, unsigned int reg, u8 d
754 return stv090x_write_regs(state, reg, &data, 1); 754 return stv090x_write_regs(state, reg, &data, 1);
755} 755}
756 756
757static int stv090x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) 757static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
758{ 758{
759 struct stv090x_state *state = fe->demodulator_priv;
760 u32 reg; 759 u32 reg;
761 760
761 /*
762 * NOTE! A lock is used as a FSM to control the state in which
763 * access is serialized between two tuners on the same demod.
764 * This has nothing to do with a lock to protect a critical section
765 * which may in some other cases be confused with protecting I/O
766 * access to the demodulator gate.
767 * In case of any error, the lock is unlocked and exit within the
768 * relevant operations themselves.
769 */
762 if (enable) 770 if (enable)
763 mutex_lock(&state->internal->tuner_lock); 771 mutex_lock(&state->internal->tuner_lock);
764 772
@@ -1778,7 +1786,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1778 freq -= cur_step * car_step; 1786 freq -= cur_step * car_step;
1779 1787
1780 /* Setup tuner */ 1788 /* Setup tuner */
1781 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 1789 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
1782 goto err; 1790 goto err;
1783 1791
1784 if (state->config->tuner_set_frequency) { 1792 if (state->config->tuner_set_frequency) {
@@ -1791,12 +1799,12 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1791 goto err_gateoff; 1799 goto err_gateoff;
1792 } 1800 }
1793 1801
1794 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 1802 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
1795 goto err; 1803 goto err;
1796 1804
1797 msleep(50); 1805 msleep(50);
1798 1806
1799 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 1807 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
1800 goto err; 1808 goto err;
1801 1809
1802 if (state->config->tuner_get_status) { 1810 if (state->config->tuner_get_status) {
@@ -1809,7 +1817,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1809 else 1817 else
1810 dprintk(FE_DEBUG, 1, "Tuner unlocked"); 1818 dprintk(FE_DEBUG, 1, "Tuner unlocked");
1811 1819
1812 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 1820 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
1813 goto err; 1821 goto err;
1814 1822
1815 } 1823 }
@@ -1822,7 +1830,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1822 return srate_coarse; 1830 return srate_coarse;
1823 1831
1824err_gateoff: 1832err_gateoff:
1825 stv090x_i2c_gate_ctrl(fe, 0); 1833 stv090x_i2c_gate_ctrl(state, 0);
1826err: 1834err:
1827 dprintk(FE_ERROR, 1, "I/O error"); 1835 dprintk(FE_ERROR, 1, "I/O error");
1828 return -1; 1836 return -1;
@@ -2167,7 +2175,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2167 freq -= cur_step * car_step; 2175 freq -= cur_step * car_step;
2168 2176
2169 /* Setup tuner */ 2177 /* Setup tuner */
2170 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 2178 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2171 goto err; 2179 goto err;
2172 2180
2173 if (state->config->tuner_set_frequency) { 2181 if (state->config->tuner_set_frequency) {
@@ -2180,12 +2188,12 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2180 goto err_gateoff; 2188 goto err_gateoff;
2181 } 2189 }
2182 2190
2183 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2191 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2184 goto err; 2192 goto err;
2185 2193
2186 msleep(50); 2194 msleep(50);
2187 2195
2188 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 2196 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2189 goto err; 2197 goto err;
2190 2198
2191 if (state->config->tuner_get_status) { 2199 if (state->config->tuner_get_status) {
@@ -2198,7 +2206,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2198 else 2206 else
2199 dprintk(FE_DEBUG, 1, "Tuner unlocked"); 2207 dprintk(FE_DEBUG, 1, "Tuner unlocked");
2200 2208
2201 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2209 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2202 goto err; 2210 goto err;
2203 2211
2204 STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c); 2212 STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c);
@@ -2222,7 +2230,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2222 return lock; 2230 return lock;
2223 2231
2224err_gateoff: 2232err_gateoff:
2225 stv090x_i2c_gate_ctrl(fe, 0); 2233 stv090x_i2c_gate_ctrl(state, 0);
2226err: 2234err:
2227 dprintk(FE_ERROR, 1, "I/O error"); 2235 dprintk(FE_ERROR, 1, "I/O error");
2228 return -1; 2236 return -1;
@@ -2591,7 +2599,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2591 } 2599 }
2592 state->delsys = stv090x_get_std(state); 2600 state->delsys = stv090x_get_std(state);
2593 2601
2594 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 2602 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2595 goto err; 2603 goto err;
2596 2604
2597 if (state->config->tuner_get_frequency) { 2605 if (state->config->tuner_get_frequency) {
@@ -2599,7 +2607,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2599 goto err_gateoff; 2607 goto err_gateoff;
2600 } 2608 }
2601 2609
2602 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2610 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2603 goto err; 2611 goto err;
2604 2612
2605 offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000; 2613 offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000;
@@ -2619,7 +2627,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2619 2627
2620 if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) { 2628 if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) {
2621 2629
2622 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 2630 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
2623 goto err; 2631 goto err;
2624 2632
2625 if (state->config->tuner_get_frequency) { 2633 if (state->config->tuner_get_frequency) {
@@ -2627,7 +2635,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2627 goto err_gateoff; 2635 goto err_gateoff;
2628 } 2636 }
2629 2637
2630 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2638 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
2631 goto err; 2639 goto err;
2632 2640
2633 if (abs(offst_freq) <= ((state->search_range / 2000) + 500)) 2641 if (abs(offst_freq) <= ((state->search_range / 2000) + 500))
@@ -2646,7 +2654,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2646 return STV090x_OUTOFRANGE; 2654 return STV090x_OUTOFRANGE;
2647 2655
2648err_gateoff: 2656err_gateoff:
2649 stv090x_i2c_gate_ctrl(fe, 0); 2657 stv090x_i2c_gate_ctrl(state, 0);
2650err: 2658err:
2651 dprintk(FE_ERROR, 1, "I/O error"); 2659 dprintk(FE_ERROR, 1, "I/O error");
2652 return -1; 2660 return -1;
@@ -3000,7 +3008,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
3000 3008
3001 if (state->algo != STV090x_WARM_SEARCH) { 3009 if (state->algo != STV090x_WARM_SEARCH) {
3002 3010
3003 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 3011 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3004 goto err; 3012 goto err;
3005 3013
3006 if (state->config->tuner_set_bandwidth) { 3014 if (state->config->tuner_set_bandwidth) {
@@ -3008,7 +3016,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
3008 goto err_gateoff; 3016 goto err_gateoff;
3009 } 3017 }
3010 3018
3011 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 3019 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3012 goto err; 3020 goto err;
3013 3021
3014 } 3022 }
@@ -3059,7 +3067,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
3059 return 0; 3067 return 0;
3060 3068
3061err_gateoff: 3069err_gateoff:
3062 stv090x_i2c_gate_ctrl(fe, 0); 3070 stv090x_i2c_gate_ctrl(state, 0);
3063err: 3071err:
3064 dprintk(FE_ERROR, 1, "I/O error"); 3072 dprintk(FE_ERROR, 1, "I/O error");
3065 return -1; 3073 return -1;
@@ -3235,7 +3243,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3235 } 3243 }
3236 3244
3237 /* Setup tuner */ 3245 /* Setup tuner */
3238 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 3246 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3239 goto err; 3247 goto err;
3240 3248
3241 if (state->config->tuner_set_bbgain) { 3249 if (state->config->tuner_set_bbgain) {
@@ -3256,17 +3264,17 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3256 goto err_gateoff; 3264 goto err_gateoff;
3257 } 3265 }
3258 3266
3259 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 3267 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3260 goto err; 3268 goto err;
3261 3269
3262 msleep(50); 3270 msleep(50);
3263 3271
3264 if (state->config->tuner_get_status) { 3272 if (state->config->tuner_get_status) {
3265 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 3273 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3266 goto err; 3274 goto err;
3267 if (state->config->tuner_get_status(fe, &reg) < 0) 3275 if (state->config->tuner_get_status(fe, &reg) < 0)
3268 goto err_gateoff; 3276 goto err_gateoff;
3269 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 3277 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3270 goto err; 3278 goto err;
3271 3279
3272 if (reg) 3280 if (reg)
@@ -3400,7 +3408,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3400 return signal_state; 3408 return signal_state;
3401 3409
3402err_gateoff: 3410err_gateoff:
3403 stv090x_i2c_gate_ctrl(fe, 0); 3411 stv090x_i2c_gate_ctrl(state, 0);
3404err: 3412err:
3405 dprintk(FE_ERROR, 1, "I/O error"); 3413 dprintk(FE_ERROR, 1, "I/O error");
3406 return -1; 3414 return -1;
@@ -3839,6 +3847,17 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3839 struct stv090x_state *state = fe->demodulator_priv; 3847 struct stv090x_state *state = fe->demodulator_priv;
3840 u32 reg; 3848 u32 reg;
3841 3849
3850 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
3851 goto err;
3852
3853 if (state->config->tuner_sleep) {
3854 if (state->config->tuner_sleep(fe) < 0)
3855 goto err_gateoff;
3856 }
3857
3858 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
3859 goto err;
3860
3842 dprintk(FE_DEBUG, 1, "Set %s to sleep", 3861 dprintk(FE_DEBUG, 1, "Set %s to sleep",
3843 state->device == STV0900 ? "STV0900" : "STV0903"); 3862 state->device == STV0900 ? "STV0900" : "STV0903");
3844 3863
@@ -3853,6 +3872,9 @@ static int stv090x_sleep(struct dvb_frontend *fe)
3853 goto err; 3872 goto err;
3854 3873
3855 return 0; 3874 return 0;
3875
3876err_gateoff:
3877 stv090x_i2c_gate_ctrl(state, 0);
3856err: 3878err:
3857 dprintk(FE_ERROR, 1, "I/O error"); 3879 dprintk(FE_ERROR, 1, "I/O error");
3858 return -1; 3880 return -1;
@@ -4311,6 +4333,20 @@ static int stv090x_init(struct dvb_frontend *fe)
4311 u32 reg; 4333 u32 reg;
4312 4334
4313 if (state->internal->mclk == 0) { 4335 if (state->internal->mclk == 0) {
4336 /* call tuner init to configure the tuner's clock output
4337 divider directly before setting up the master clock of
4338 the stv090x. */
4339 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
4340 goto err;
4341
4342 if (config->tuner_init) {
4343 if (config->tuner_init(fe) < 0)
4344 goto err_gateoff;
4345 }
4346
4347 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
4348 goto err;
4349
4314 stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */ 4350 stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */
4315 msleep(5); 4351 msleep(5);
4316 if (stv090x_write_reg(state, STV090x_SYNTCTRL, 4352 if (stv090x_write_reg(state, STV090x_SYNTCTRL,
@@ -4336,7 +4372,7 @@ static int stv090x_init(struct dvb_frontend *fe)
4336 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) 4372 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0)
4337 goto err; 4373 goto err;
4338 4374
4339 if (stv090x_i2c_gate_ctrl(fe, 1) < 0) 4375 if (stv090x_i2c_gate_ctrl(state, 1) < 0)
4340 goto err; 4376 goto err;
4341 4377
4342 if (config->tuner_set_mode) { 4378 if (config->tuner_set_mode) {
@@ -4349,7 +4385,7 @@ static int stv090x_init(struct dvb_frontend *fe)
4349 goto err_gateoff; 4385 goto err_gateoff;
4350 } 4386 }
4351 4387
4352 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 4388 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
4353 goto err; 4389 goto err;
4354 4390
4355 if (stv090x_set_tspath(state) < 0) 4391 if (stv090x_set_tspath(state) < 0)
@@ -4358,7 +4394,7 @@ static int stv090x_init(struct dvb_frontend *fe)
4358 return 0; 4394 return 0;
4359 4395
4360err_gateoff: 4396err_gateoff:
4361 stv090x_i2c_gate_ctrl(fe, 0); 4397 stv090x_i2c_gate_ctrl(state, 0);
4362err: 4398err:
4363 dprintk(FE_ERROR, 1, "I/O error"); 4399 dprintk(FE_ERROR, 1, "I/O error");
4364 return -1; 4400 return -1;
@@ -4503,8 +4539,6 @@ static struct dvb_frontend_ops stv090x_ops = {
4503 .sleep = stv090x_sleep, 4539 .sleep = stv090x_sleep,
4504 .get_frontend_algo = stv090x_frontend_algo, 4540 .get_frontend_algo = stv090x_frontend_algo,
4505 4541
4506 .i2c_gate_ctrl = stv090x_i2c_gate_ctrl,
4507
4508 .diseqc_send_master_cmd = stv090x_send_diseqc_msg, 4542 .diseqc_send_master_cmd = stv090x_send_diseqc_msg,
4509 .diseqc_send_burst = stv090x_send_diseqc_burst, 4543 .diseqc_send_burst = stv090x_send_diseqc_burst,
4510 .diseqc_recv_slave_reply = stv090x_recv_slave_reply, 4544 .diseqc_recv_slave_reply = stv090x_recv_slave_reply,
diff --git a/drivers/media/dvb/frontends/stv090x.h b/drivers/media/dvb/frontends/stv090x.h
index 30f01a6902a..dd1b93ae4e9 100644
--- a/drivers/media/dvb/frontends/stv090x.h
+++ b/drivers/media/dvb/frontends/stv090x.h
@@ -87,6 +87,7 @@ struct stv090x_config {
87 bool diseqc_envelope_mode; 87 bool diseqc_envelope_mode;
88 88
89 int (*tuner_init) (struct dvb_frontend *fe); 89 int (*tuner_init) (struct dvb_frontend *fe);
90 int (*tuner_sleep) (struct dvb_frontend *fe);
90 int (*tuner_set_mode) (struct dvb_frontend *fe, enum tuner_mode mode); 91 int (*tuner_set_mode) (struct dvb_frontend *fe, enum tuner_mode mode);
91 int (*tuner_set_frequency) (struct dvb_frontend *fe, u32 frequency); 92 int (*tuner_set_frequency) (struct dvb_frontend *fe, u32 frequency);
92 int (*tuner_get_frequency) (struct dvb_frontend *fe, u32 *frequency); 93 int (*tuner_get_frequency) (struct dvb_frontend *fe, u32 *frequency);
diff --git a/drivers/media/dvb/frontends/stv6110x.c b/drivers/media/dvb/frontends/stv6110x.c
index dea4245f077..42591ce1aaa 100644
--- a/drivers/media/dvb/frontends/stv6110x.c
+++ b/drivers/media/dvb/frontends/stv6110x.c
@@ -338,14 +338,12 @@ static struct dvb_tuner_ops stv6110x_ops = {
338 .frequency_max = 2150000, 338 .frequency_max = 2150000,
339 .frequency_step = 0, 339 .frequency_step = 0,
340 }, 340 },
341
342 .init = stv6110x_init,
343 .sleep = stv6110x_sleep,
344 .release = stv6110x_release 341 .release = stv6110x_release
345}; 342};
346 343
347static struct stv6110x_devctl stv6110x_ctl = { 344static struct stv6110x_devctl stv6110x_ctl = {
348 .tuner_init = stv6110x_init, 345 .tuner_init = stv6110x_init,
346 .tuner_sleep = stv6110x_sleep,
349 .tuner_set_mode = stv6110x_set_mode, 347 .tuner_set_mode = stv6110x_set_mode,
350 .tuner_set_frequency = stv6110x_set_frequency, 348 .tuner_set_frequency = stv6110x_set_frequency,
351 .tuner_get_frequency = stv6110x_get_frequency, 349 .tuner_get_frequency = stv6110x_get_frequency,
@@ -363,11 +361,10 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
363{ 361{
364 struct stv6110x_state *stv6110x; 362 struct stv6110x_state *stv6110x;
365 u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e}; 363 u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e};
366 int ret;
367 364
368 stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL); 365 stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL);
369 if (stv6110x == NULL) 366 if (!stv6110x)
370 goto error; 367 return NULL;
371 368
372 stv6110x->i2c = i2c; 369 stv6110x->i2c = i2c;
373 stv6110x->config = config; 370 stv6110x->config = config;
@@ -392,34 +389,11 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
392 break; 389 break;
393 } 390 }
394 391
395 if (fe->ops.i2c_gate_ctrl) {
396 ret = fe->ops.i2c_gate_ctrl(fe, 1);
397 if (ret < 0)
398 goto error;
399 }
400
401 ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs,
402 ARRAY_SIZE(stv6110x->regs));
403 if (ret < 0) {
404 dprintk(FE_ERROR, 1, "Initialization failed");
405 goto error;
406 }
407
408 if (fe->ops.i2c_gate_ctrl) {
409 ret = fe->ops.i2c_gate_ctrl(fe, 0);
410 if (ret < 0)
411 goto error;
412 }
413
414 fe->tuner_priv = stv6110x; 392 fe->tuner_priv = stv6110x;
415 fe->ops.tuner_ops = stv6110x_ops; 393 fe->ops.tuner_ops = stv6110x_ops;
416 394
417 printk("%s: Attaching STV6110x \n", __func__); 395 printk(KERN_INFO "%s: Attaching STV6110x\n", __func__);
418 return stv6110x->devctl; 396 return stv6110x->devctl;
419
420error:
421 kfree(stv6110x);
422 return NULL;
423} 397}
424EXPORT_SYMBOL(stv6110x_attach); 398EXPORT_SYMBOL(stv6110x_attach);
425 399
diff --git a/drivers/media/dvb/frontends/stv6110x.h b/drivers/media/dvb/frontends/stv6110x.h
index 2429ae6d784..47516753929 100644
--- a/drivers/media/dvb/frontends/stv6110x.h
+++ b/drivers/media/dvb/frontends/stv6110x.h
@@ -40,6 +40,7 @@ enum tuner_status {
40 40
41struct stv6110x_devctl { 41struct stv6110x_devctl {
42 int (*tuner_init) (struct dvb_frontend *fe); 42 int (*tuner_init) (struct dvb_frontend *fe);
43 int (*tuner_sleep) (struct dvb_frontend *fe);
43 int (*tuner_set_mode) (struct dvb_frontend *fe, enum tuner_mode mode); 44 int (*tuner_set_mode) (struct dvb_frontend *fe, enum tuner_mode mode);
44 int (*tuner_set_frequency) (struct dvb_frontend *fe, u32 frequency); 45 int (*tuner_set_frequency) (struct dvb_frontend *fe, u32 frequency);
45 int (*tuner_get_frequency) (struct dvb_frontend *fe, u32 *frequency); 46 int (*tuner_get_frequency) (struct dvb_frontend *fe, u32 *frequency);