blob: 50ffa21e387116976874b20a2c7befe9f9472da6 [file] [log] [blame]
Igor M. Liplianinb699c272009-11-16 22:22:32 -03001/*
2 STB6100 Silicon Tuner wrapper
3 Copyright (C)2009 Igor M. Liplianin (liplianin@me.by)
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020020#include <linux/dvb/frontend.h>
21#include "dvb_frontend.h"
22
Igor M. Liplianinb699c272009-11-16 22:22:32 -030023static int stb6100_get_freq(struct dvb_frontend *fe, u32 *frequency)
24{
Emil Goode20721182014-06-24 18:42:27 -030025 struct dvb_frontend_ops *frontend_ops = &fe->ops;
26 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030027 int err = 0;
28
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020029 if (tuner_ops->get_frequency) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030030 if (frontend_ops->i2c_gate_ctrl)
31 frontend_ops->i2c_gate_ctrl(fe, 1);
32
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020033 err = tuner_ops->get_frequency(fe, frequency);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030034 if (err < 0) {
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020035 printk("%s: Invalid parameter\n", __func__);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030036 return err;
37 }
38
39 if (frontend_ops->i2c_gate_ctrl)
40 frontend_ops->i2c_gate_ctrl(fe, 0);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030041 }
42
43 return 0;
44}
45
46static int stb6100_set_freq(struct dvb_frontend *fe, u32 frequency)
47{
Emil Goode20721182014-06-24 18:42:27 -030048 struct dvb_frontend_ops *frontend_ops = &fe->ops;
49 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020050 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
51 u32 bw = c->bandwidth_hz;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030052 int err = 0;
53
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020054 c->frequency = frequency;
55 c->bandwidth_hz = 0; /* Don't adjust the bandwidth */
Emil Goode20721182014-06-24 18:42:27 -030056
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020057 if (tuner_ops->set_params) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030058 if (frontend_ops->i2c_gate_ctrl)
59 frontend_ops->i2c_gate_ctrl(fe, 1);
60
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020061 err = tuner_ops->set_params(fe);
62 c->bandwidth_hz = bw;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030063 if (err < 0) {
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020064 printk("%s: Invalid parameter\n", __func__);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030065 return err;
66 }
67
68 if (frontend_ops->i2c_gate_ctrl)
69 frontend_ops->i2c_gate_ctrl(fe, 0);
70
71 }
72
73 return 0;
74}
75
76static int stb6100_get_bandw(struct dvb_frontend *fe, u32 *bandwidth)
77{
Emil Goode20721182014-06-24 18:42:27 -030078 struct dvb_frontend_ops *frontend_ops = &fe->ops;
79 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030080 int err = 0;
81
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020082 if (tuner_ops->get_bandwidth) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030083 if (frontend_ops->i2c_gate_ctrl)
84 frontend_ops->i2c_gate_ctrl(fe, 1);
85
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020086 err = tuner_ops->get_bandwidth(fe, bandwidth);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030087 if (err < 0) {
88 printk(KERN_ERR "%s: Invalid parameter\n", __func__);
89 return err;
90 }
91
92 if (frontend_ops->i2c_gate_ctrl)
93 frontend_ops->i2c_gate_ctrl(fe, 0);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030094 }
95
96 return 0;
97}
98
99static int stb6100_set_bandw(struct dvb_frontend *fe, u32 bandwidth)
100{
Emil Goode20721182014-06-24 18:42:27 -0300101 struct dvb_frontend_ops *frontend_ops = &fe->ops;
102 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -0200103 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
104 u32 freq = c->frequency;
Igor M. Liplianinb699c272009-11-16 22:22:32 -0300105 int err = 0;
106
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -0200107 c->bandwidth_hz = bandwidth;
108 c->frequency = 0; /* Don't adjust the frequency */
Emil Goode20721182014-06-24 18:42:27 -0300109
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -0200110 if (tuner_ops->set_params) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -0300111 if (frontend_ops->i2c_gate_ctrl)
112 frontend_ops->i2c_gate_ctrl(fe, 1);
113
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -0200114 err = tuner_ops->set_params(fe);
115 c->frequency = freq;
Igor M. Liplianinb699c272009-11-16 22:22:32 -0300116 if (err < 0) {
117 printk(KERN_ERR "%s: Invalid parameter\n", __func__);
118 return err;
119 }
120
121 if (frontend_ops->i2c_gate_ctrl)
122 frontend_ops->i2c_gate_ctrl(fe, 0);
123
124 }
125
126 return 0;
127}