1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 	STB6100 Silicon Tuner wrapper
4 	Copyright (C)2009 Igor M. Liplianin (liplianin@me.by)
5 
6 */
7 
8 #include <linux/dvb/frontend.h>
9 #include <media/dvb_frontend.h>
10 
stb6100_get_freq(struct dvb_frontend * fe,u32 * frequency)11 static int stb6100_get_freq(struct dvb_frontend *fe, u32 *frequency)
12 {
13 	struct dvb_frontend_ops	*frontend_ops = &fe->ops;
14 	struct dvb_tuner_ops	*tuner_ops = &frontend_ops->tuner_ops;
15 	int err = 0;
16 
17 	if (tuner_ops->get_frequency) {
18 		if (frontend_ops->i2c_gate_ctrl)
19 			frontend_ops->i2c_gate_ctrl(fe, 1);
20 
21 		err = tuner_ops->get_frequency(fe, frequency);
22 		if (err < 0) {
23 			printk("%s: Invalid parameter\n", __func__);
24 			return err;
25 		}
26 
27 		if (frontend_ops->i2c_gate_ctrl)
28 			frontend_ops->i2c_gate_ctrl(fe, 0);
29 	}
30 
31 	return 0;
32 }
33 
stb6100_set_freq(struct dvb_frontend * fe,u32 frequency)34 static int stb6100_set_freq(struct dvb_frontend *fe, u32 frequency)
35 {
36 	struct dvb_frontend_ops	*frontend_ops = &fe->ops;
37 	struct dvb_tuner_ops	*tuner_ops = &frontend_ops->tuner_ops;
38 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
39 	u32 bw = c->bandwidth_hz;
40 	int err = 0;
41 
42 	c->frequency = frequency;
43 	c->bandwidth_hz = 0;		/* Don't adjust the bandwidth */
44 
45 	if (tuner_ops->set_params) {
46 		if (frontend_ops->i2c_gate_ctrl)
47 			frontend_ops->i2c_gate_ctrl(fe, 1);
48 
49 		err = tuner_ops->set_params(fe);
50 		c->bandwidth_hz = bw;
51 		if (err < 0) {
52 			printk("%s: Invalid parameter\n", __func__);
53 			return err;
54 		}
55 
56 		if (frontend_ops->i2c_gate_ctrl)
57 			frontend_ops->i2c_gate_ctrl(fe, 0);
58 
59 	}
60 
61 	return 0;
62 }
63 
stb6100_get_bandw(struct dvb_frontend * fe,u32 * bandwidth)64 static int stb6100_get_bandw(struct dvb_frontend *fe, u32 *bandwidth)
65 {
66 	struct dvb_frontend_ops	*frontend_ops = &fe->ops;
67 	struct dvb_tuner_ops	*tuner_ops = &frontend_ops->tuner_ops;
68 	int err = 0;
69 
70 	if (tuner_ops->get_bandwidth) {
71 		if (frontend_ops->i2c_gate_ctrl)
72 			frontend_ops->i2c_gate_ctrl(fe, 1);
73 
74 		err = tuner_ops->get_bandwidth(fe, bandwidth);
75 		if (err < 0) {
76 			printk(KERN_ERR "%s: Invalid parameter\n", __func__);
77 			return err;
78 		}
79 
80 		if (frontend_ops->i2c_gate_ctrl)
81 			frontend_ops->i2c_gate_ctrl(fe, 0);
82 	}
83 
84 	return 0;
85 }
86 
stb6100_set_bandw(struct dvb_frontend * fe,u32 bandwidth)87 static int stb6100_set_bandw(struct dvb_frontend *fe, u32 bandwidth)
88 {
89 	struct dvb_frontend_ops	*frontend_ops = &fe->ops;
90 	struct dvb_tuner_ops	*tuner_ops = &frontend_ops->tuner_ops;
91 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
92 	u32 freq = c->frequency;
93 	int err = 0;
94 
95 	c->bandwidth_hz = bandwidth;
96 	c->frequency = 0;		/* Don't adjust the frequency */
97 
98 	if (tuner_ops->set_params) {
99 		if (frontend_ops->i2c_gate_ctrl)
100 			frontend_ops->i2c_gate_ctrl(fe, 1);
101 
102 		err = tuner_ops->set_params(fe);
103 		c->frequency = freq;
104 		if (err < 0) {
105 			printk(KERN_ERR "%s: Invalid parameter\n", __func__);
106 			return err;
107 		}
108 
109 		if (frontend_ops->i2c_gate_ctrl)
110 			frontend_ops->i2c_gate_ctrl(fe, 0);
111 
112 	}
113 
114 	return 0;
115 }
116