Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 2 | /* |
| 3 | STB6100 Silicon Tuner wrapper |
| 4 | Copyright (C)2009 Igor M. Liplianin (liplianin@me.by) |
| 5 | |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 6 | */ |
| 7 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 8 | #include <linux/dvb/frontend.h> |
Mauro Carvalho Chehab | fada193 | 2017-12-28 13:03:51 -0500 | [diff] [blame] | 9 | #include <media/dvb_frontend.h> |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 10 | |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 11 | static int stb6100_get_freq(struct dvb_frontend *fe, u32 *frequency) |
| 12 | { |
Emil Goode | 2072118 | 2014-06-24 18:42:27 -0300 | [diff] [blame] | 13 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 14 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 15 | int err = 0; |
| 16 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 17 | if (tuner_ops->get_frequency) { |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 18 | if (frontend_ops->i2c_gate_ctrl) |
| 19 | frontend_ops->i2c_gate_ctrl(fe, 1); |
| 20 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 21 | err = tuner_ops->get_frequency(fe, frequency); |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 22 | if (err < 0) { |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 23 | printk("%s: Invalid parameter\n", __func__); |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 24 | return err; |
| 25 | } |
| 26 | |
| 27 | if (frontend_ops->i2c_gate_ctrl) |
| 28 | frontend_ops->i2c_gate_ctrl(fe, 0); |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int stb6100_set_freq(struct dvb_frontend *fe, u32 frequency) |
| 35 | { |
Emil Goode | 2072118 | 2014-06-24 18:42:27 -0300 | [diff] [blame] | 36 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 37 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 38 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 39 | u32 bw = c->bandwidth_hz; |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 40 | int err = 0; |
| 41 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 42 | c->frequency = frequency; |
| 43 | c->bandwidth_hz = 0; /* Don't adjust the bandwidth */ |
Emil Goode | 2072118 | 2014-06-24 18:42:27 -0300 | [diff] [blame] | 44 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 45 | if (tuner_ops->set_params) { |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 46 | if (frontend_ops->i2c_gate_ctrl) |
| 47 | frontend_ops->i2c_gate_ctrl(fe, 1); |
| 48 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 49 | err = tuner_ops->set_params(fe); |
| 50 | c->bandwidth_hz = bw; |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 51 | if (err < 0) { |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 52 | printk("%s: Invalid parameter\n", __func__); |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 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 | |
| 64 | static int stb6100_get_bandw(struct dvb_frontend *fe, u32 *bandwidth) |
| 65 | { |
Emil Goode | 2072118 | 2014-06-24 18:42:27 -0300 | [diff] [blame] | 66 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 67 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 68 | int err = 0; |
| 69 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 70 | if (tuner_ops->get_bandwidth) { |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 71 | if (frontend_ops->i2c_gate_ctrl) |
| 72 | frontend_ops->i2c_gate_ctrl(fe, 1); |
| 73 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 74 | err = tuner_ops->get_bandwidth(fe, bandwidth); |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 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); |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static int stb6100_set_bandw(struct dvb_frontend *fe, u32 bandwidth) |
| 88 | { |
Emil Goode | 2072118 | 2014-06-24 18:42:27 -0300 | [diff] [blame] | 89 | struct dvb_frontend_ops *frontend_ops = &fe->ops; |
| 90 | struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 91 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 92 | u32 freq = c->frequency; |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 93 | int err = 0; |
| 94 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 95 | c->bandwidth_hz = bandwidth; |
| 96 | c->frequency = 0; /* Don't adjust the frequency */ |
Emil Goode | 2072118 | 2014-06-24 18:42:27 -0300 | [diff] [blame] | 97 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 98 | if (tuner_ops->set_params) { |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 99 | if (frontend_ops->i2c_gate_ctrl) |
| 100 | frontend_ops->i2c_gate_ctrl(fe, 1); |
| 101 | |
Mauro Carvalho Chehab | 65f0f68 | 2015-11-11 18:42:00 -0200 | [diff] [blame] | 102 | err = tuner_ops->set_params(fe); |
| 103 | c->frequency = freq; |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 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 | } |