blob: af75a40e0ff17daaa2cf779eb3f381e69fe761dd [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Igor M. Liplianinb699c272009-11-16 22:22:32 -03002/*
3 STB6100 Silicon Tuner wrapper
4 Copyright (C)2009 Igor M. Liplianin (liplianin@me.by)
5
Igor M. Liplianinb699c272009-11-16 22:22:32 -03006*/
7
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -02008#include <linux/dvb/frontend.h>
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -05009#include <media/dvb_frontend.h>
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020010
Igor M. Liplianinb699c272009-11-16 22:22:32 -030011static int stb6100_get_freq(struct dvb_frontend *fe, u32 *frequency)
12{
Emil Goode20721182014-06-24 18:42:27 -030013 struct dvb_frontend_ops *frontend_ops = &fe->ops;
14 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030015 int err = 0;
16
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020017 if (tuner_ops->get_frequency) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030018 if (frontend_ops->i2c_gate_ctrl)
19 frontend_ops->i2c_gate_ctrl(fe, 1);
20
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020021 err = tuner_ops->get_frequency(fe, frequency);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030022 if (err < 0) {
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020023 printk("%s: Invalid parameter\n", __func__);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030024 return err;
25 }
26
27 if (frontend_ops->i2c_gate_ctrl)
28 frontend_ops->i2c_gate_ctrl(fe, 0);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030029 }
30
31 return 0;
32}
33
34static int stb6100_set_freq(struct dvb_frontend *fe, u32 frequency)
35{
Emil Goode20721182014-06-24 18:42:27 -030036 struct dvb_frontend_ops *frontend_ops = &fe->ops;
37 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020038 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
39 u32 bw = c->bandwidth_hz;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030040 int err = 0;
41
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020042 c->frequency = frequency;
43 c->bandwidth_hz = 0; /* Don't adjust the bandwidth */
Emil Goode20721182014-06-24 18:42:27 -030044
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020045 if (tuner_ops->set_params) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030046 if (frontend_ops->i2c_gate_ctrl)
47 frontend_ops->i2c_gate_ctrl(fe, 1);
48
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020049 err = tuner_ops->set_params(fe);
50 c->bandwidth_hz = bw;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030051 if (err < 0) {
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020052 printk("%s: Invalid parameter\n", __func__);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030053 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
64static int stb6100_get_bandw(struct dvb_frontend *fe, u32 *bandwidth)
65{
Emil Goode20721182014-06-24 18:42:27 -030066 struct dvb_frontend_ops *frontend_ops = &fe->ops;
67 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030068 int err = 0;
69
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020070 if (tuner_ops->get_bandwidth) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030071 if (frontend_ops->i2c_gate_ctrl)
72 frontend_ops->i2c_gate_ctrl(fe, 1);
73
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020074 err = tuner_ops->get_bandwidth(fe, bandwidth);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030075 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);
Igor M. Liplianinb699c272009-11-16 22:22:32 -030082 }
83
84 return 0;
85}
86
87static int stb6100_set_bandw(struct dvb_frontend *fe, u32 bandwidth)
88{
Emil Goode20721182014-06-24 18:42:27 -030089 struct dvb_frontend_ops *frontend_ops = &fe->ops;
90 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops;
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020091 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
92 u32 freq = c->frequency;
Igor M. Liplianinb699c272009-11-16 22:22:32 -030093 int err = 0;
94
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020095 c->bandwidth_hz = bandwidth;
96 c->frequency = 0; /* Don't adjust the frequency */
Emil Goode20721182014-06-24 18:42:27 -030097
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -020098 if (tuner_ops->set_params) {
Igor M. Liplianinb699c272009-11-16 22:22:32 -030099 if (frontend_ops->i2c_gate_ctrl)
100 frontend_ops->i2c_gate_ctrl(fe, 1);
101
Mauro Carvalho Chehab65f0f682015-11-11 18:42:00 -0200102 err = tuner_ops->set_params(fe);
103 c->frequency = freq;
Igor M. Liplianinb699c272009-11-16 22:22:32 -0300104 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}