Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dvb_frontend.c: DVB frontend tuning interface/thread |
| 3 | * |
| 4 | * |
| 5 | * Copyright (C) 1999-2001 Ralph Metzler |
| 6 | * Marcus Metzler |
| 7 | * Holger Waechtler |
| 8 | * for convergence integrated media GmbH |
| 9 | * |
| 10 | * Copyright (C) 2004 Andrew de Quincey (tuning thread cleanup) |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | * Or, point your browser to http://www.gnu.org/copyleft/gpl.html |
| 26 | */ |
| 27 | |
Mauro Carvalho Chehab | 8de8594 | 2011-12-26 20:22:50 -0300 | [diff] [blame] | 28 | /* Enables DVBv3 compatibility bits at the headers */ |
| 29 | #define __DVB_CORE__ |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/string.h> |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/sched.h> |
| 34 | #include <linux/wait.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/poll.h> |
Andrew Morton | 4c4cb1b | 2009-12-01 13:17:41 -0800 | [diff] [blame] | 37 | #include <linux/semaphore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/list.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 40 | #include <linux/freezer.h> |
Johannes Stezenbach | cc89c22 | 2005-06-23 22:02:39 -0700 | [diff] [blame] | 41 | #include <linux/jiffies.h> |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 42 | #include <linux/kthread.h> |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 43 | #include <linux/ktime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include "dvb_frontend.h" |
| 47 | #include "dvbdev.h" |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 48 | #include <linux/dvb/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | static int dvb_frontend_debug; |
Oliver Endriss | 849be2c | 2007-08-25 12:22:16 -0300 | [diff] [blame] | 51 | static int dvb_shutdown_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static int dvb_force_auto_inversion; |
| 53 | static int dvb_override_tune_delay; |
| 54 | static int dvb_powerdown_on_sleep = 1; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 55 | static int dvb_mfe_wait_time = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | module_param_named(frontend_debug, dvb_frontend_debug, int, 0644); |
Johannes Stezenbach | f4f009a | 2005-05-16 21:54:21 -0700 | [diff] [blame] | 58 | MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off)."); |
Manu Abraham | 6baad3f | 2006-02-27 00:09:32 -0300 | [diff] [blame] | 59 | module_param(dvb_shutdown_timeout, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware"); |
Manu Abraham | 6baad3f | 2006-02-27 00:09:32 -0300 | [diff] [blame] | 61 | module_param(dvb_force_auto_inversion, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always"); |
Manu Abraham | 6baad3f | 2006-02-27 00:09:32 -0300 | [diff] [blame] | 63 | module_param(dvb_override_tune_delay, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt"); |
Manu Abraham | 6baad3f | 2006-02-27 00:09:32 -0300 | [diff] [blame] | 65 | module_param(dvb_powerdown_on_sleep, int, 0644); |
Uwe Bugla | a8558577 | 2006-04-11 10:21:37 -0300 | [diff] [blame] | 66 | MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB voltage off on sleep (default)"); |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 67 | module_param(dvb_mfe_wait_time, int, 0644); |
| 68 | MODULE_PARM_DESC(dvb_mfe_wait_time, "Wait up to <mfe_wait_time> seconds on open() for multi-frontend to become available (default:5 seconds)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #define FESTATE_IDLE 1 |
| 71 | #define FESTATE_RETUNE 2 |
| 72 | #define FESTATE_TUNING_FAST 4 |
| 73 | #define FESTATE_TUNING_SLOW 8 |
| 74 | #define FESTATE_TUNED 16 |
| 75 | #define FESTATE_ZIGZAG_FAST 32 |
| 76 | #define FESTATE_ZIGZAG_SLOW 64 |
| 77 | #define FESTATE_DISEQC 128 |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 78 | #define FESTATE_ERROR 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC) |
| 80 | #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST) |
| 81 | #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW) |
| 82 | #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW) |
Manu Abraham | 0249ef1 | 2006-06-21 10:27:31 -0300 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* |
| 85 | * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling. |
| 86 | * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune. |
| 87 | * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress. |
| 88 | * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower. |
| 89 | * FESTATE_TUNED. The frontend has successfully locked on. |
| 90 | * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it. |
| 91 | * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower. |
| 92 | * FESTATE_DISEQC. A DISEQC command has just been issued. |
| 93 | * FESTATE_WAITFORLOCK. When we're waiting for a lock. |
| 94 | * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan. |
| 95 | * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan. |
| 96 | * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again. |
| 97 | */ |
| 98 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 99 | static DEFINE_MUTEX(frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | struct dvb_frontend_private { |
| 102 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 103 | /* thread/frontend values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | struct dvb_device *dvbdev; |
Andreas Oberritter | a5959db | 2011-05-08 20:03:40 -0300 | [diff] [blame] | 105 | struct dvb_frontend_parameters parameters_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | struct dvb_fe_events events; |
| 107 | struct semaphore sem; |
| 108 | struct list_head list_head; |
| 109 | wait_queue_head_t wait_queue; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 110 | struct task_struct *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | unsigned long release_jiffies; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 112 | unsigned int wakeup; |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 113 | enum fe_status status; |
Peter Beutner | 400b708 | 2006-01-09 15:32:43 -0200 | [diff] [blame] | 114 | unsigned long tune_mode_flags; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 115 | unsigned int delay; |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 116 | unsigned int reinitialise; |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 117 | int tone; |
| 118 | int voltage; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 119 | |
| 120 | /* swzigzag values */ |
| 121 | unsigned int state; |
| 122 | unsigned int bending; |
| 123 | int lnb_drift; |
| 124 | unsigned int inversion; |
| 125 | unsigned int auto_step; |
| 126 | unsigned int auto_sub_step; |
| 127 | unsigned int started_auto_step; |
| 128 | unsigned int min_delay; |
| 129 | unsigned int max_drift; |
| 130 | unsigned int step_size; |
| 131 | int quality; |
| 132 | unsigned int check_wrapped; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 133 | enum dvbfe_search algo_status; |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 134 | |
| 135 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
| 136 | struct media_pipeline pipe; |
| 137 | struct media_entity *pipe_start_entity; |
| 138 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 141 | static void dvb_frontend_wakeup(struct dvb_frontend *fe); |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 142 | static int dtv_get_frontend(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 143 | struct dvb_frontend_parameters *p_out); |
Chris Rankin | 556a044 | 2012-04-06 18:38:18 -0300 | [diff] [blame] | 144 | static int dtv_property_legacy_params_sync(struct dvb_frontend *fe, |
| 145 | struct dvb_frontend_parameters *p); |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 146 | |
| 147 | static bool has_get_frontend(struct dvb_frontend *fe) |
| 148 | { |
Hans Petter Selasky | c065f5b | 2012-03-27 12:53:19 -0300 | [diff] [blame] | 149 | return fe->ops.get_frontend != NULL; |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 152 | /* |
| 153 | * Due to DVBv3 API calls, a delivery system should be mapped into one of |
| 154 | * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC), |
| 155 | * otherwise, a DVBv3 call will fail. |
| 156 | */ |
| 157 | enum dvbv3_emulation_type { |
| 158 | DVBV3_UNKNOWN, |
| 159 | DVBV3_QPSK, |
| 160 | DVBV3_QAM, |
| 161 | DVBV3_OFDM, |
| 162 | DVBV3_ATSC, |
| 163 | }; |
| 164 | |
| 165 | static enum dvbv3_emulation_type dvbv3_type(u32 delivery_system) |
| 166 | { |
| 167 | switch (delivery_system) { |
| 168 | case SYS_DVBC_ANNEX_A: |
| 169 | case SYS_DVBC_ANNEX_C: |
| 170 | return DVBV3_QAM; |
| 171 | case SYS_DVBS: |
| 172 | case SYS_DVBS2: |
| 173 | case SYS_TURBO: |
| 174 | case SYS_ISDBS: |
| 175 | case SYS_DSS: |
| 176 | return DVBV3_QPSK; |
| 177 | case SYS_DVBT: |
| 178 | case SYS_DVBT2: |
| 179 | case SYS_ISDBT: |
Antti Palosaari | 224b664 | 2012-08-12 22:33:21 -0300 | [diff] [blame] | 180 | case SYS_DTMB: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 181 | return DVBV3_OFDM; |
| 182 | case SYS_ATSC: |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 183 | case SYS_ATSCMH: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 184 | case SYS_DVBC_ANNEX_B: |
| 185 | return DVBV3_ATSC; |
| 186 | case SYS_UNDEFINED: |
| 187 | case SYS_ISDBC: |
| 188 | case SYS_DVBH: |
| 189 | case SYS_DAB: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 190 | default: |
| 191 | /* |
| 192 | * Doesn't know how to emulate those types and/or |
| 193 | * there's no frontend driver from this type yet |
| 194 | * with some emulation code, so, we're not sure yet how |
| 195 | * to handle them, or they're not compatible with a DVBv3 call. |
| 196 | */ |
| 197 | return DVBV3_UNKNOWN; |
| 198 | } |
| 199 | } |
| 200 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 201 | static void dvb_frontend_add_event(struct dvb_frontend *fe, |
| 202 | enum fe_status status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 204 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | struct dvb_fe_events *events = &fepriv->events; |
| 206 | struct dvb_frontend_event *e; |
| 207 | int wp; |
| 208 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 209 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 211 | if ((status & FE_HAS_LOCK) && has_get_frontend(fe)) |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 212 | dtv_get_frontend(fe, &fepriv->parameters_out); |
Andreas Oberritter | 77b1e2f | 2011-08-04 12:33:15 -0300 | [diff] [blame] | 213 | |
| 214 | mutex_lock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | wp = (events->eventw + 1) % MAX_EVENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (wp == events->eventr) { |
| 218 | events->overflow = 1; |
| 219 | events->eventr = (events->eventr + 1) % MAX_EVENT; |
| 220 | } |
| 221 | |
| 222 | e = &events->events[events->eventw]; |
Andreas Oberritter | 77b1e2f | 2011-08-04 12:33:15 -0300 | [diff] [blame] | 223 | e->status = status; |
Andreas Oberritter | a5959db | 2011-05-08 20:03:40 -0300 | [diff] [blame] | 224 | e->parameters = fepriv->parameters_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | events->eventw = wp; |
| 227 | |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 228 | mutex_unlock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | wake_up_interruptible (&events->wait_queue); |
| 231 | } |
| 232 | |
| 233 | static int dvb_frontend_get_event(struct dvb_frontend *fe, |
| 234 | struct dvb_frontend_event *event, int flags) |
| 235 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 236 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | struct dvb_fe_events *events = &fepriv->events; |
| 238 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 239 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | if (events->overflow) { |
| 242 | events->overflow = 0; |
| 243 | return -EOVERFLOW; |
| 244 | } |
| 245 | |
| 246 | if (events->eventw == events->eventr) { |
| 247 | int ret; |
| 248 | |
| 249 | if (flags & O_NONBLOCK) |
| 250 | return -EWOULDBLOCK; |
| 251 | |
| 252 | up(&fepriv->sem); |
| 253 | |
| 254 | ret = wait_event_interruptible (events->wait_queue, |
| 255 | events->eventw != events->eventr); |
| 256 | |
| 257 | if (down_interruptible (&fepriv->sem)) |
| 258 | return -ERESTARTSYS; |
| 259 | |
| 260 | if (ret < 0) |
| 261 | return ret; |
| 262 | } |
| 263 | |
Andreas Oberritter | 77b1e2f | 2011-08-04 12:33:15 -0300 | [diff] [blame] | 264 | mutex_lock(&events->mtx); |
| 265 | *event = events->events[events->eventr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | events->eventr = (events->eventr + 1) % MAX_EVENT; |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 267 | mutex_unlock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
Andreas Oberritter | 20640be | 2011-08-04 12:33:14 -0300 | [diff] [blame] | 272 | static void dvb_frontend_clear_events(struct dvb_frontend *fe) |
| 273 | { |
| 274 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 275 | struct dvb_fe_events *events = &fepriv->events; |
| 276 | |
| 277 | mutex_lock(&events->mtx); |
| 278 | events->eventr = events->eventw; |
| 279 | mutex_unlock(&events->mtx); |
| 280 | } |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | static void dvb_frontend_init(struct dvb_frontend *fe) |
| 283 | { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 284 | dev_dbg(fe->dvb->device, |
| 285 | "%s: initialising adapter %i frontend %i (%s)...\n", |
| 286 | __func__, fe->dvb->num, fe->id, fe->ops.info.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 288 | if (fe->ops.init) |
| 289 | fe->ops.init(fe); |
| 290 | if (fe->ops.tuner_ops.init) { |
Manu Abraham | 3b37a15 | 2008-10-20 18:14:14 -0300 | [diff] [blame] | 291 | if (fe->ops.i2c_gate_ctrl) |
| 292 | fe->ops.i2c_gate_ctrl(fe, 1); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 293 | fe->ops.tuner_ops.init(fe); |
| 294 | if (fe->ops.i2c_gate_ctrl) |
| 295 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 7eef5dd | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 299 | void dvb_frontend_reinitialise(struct dvb_frontend *fe) |
| 300 | { |
| 301 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 302 | |
| 303 | fepriv->reinitialise = 1; |
| 304 | dvb_frontend_wakeup(fe); |
| 305 | } |
| 306 | EXPORT_SYMBOL(dvb_frontend_reinitialise); |
| 307 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 308 | static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 310 | int q2; |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 311 | struct dvb_frontend *fe = fepriv->dvbdev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 313 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 315 | if (locked) |
| 316 | (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256; |
| 317 | else |
| 318 | (fepriv->quality) = (fepriv->quality * 220 + 0) / 256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 320 | q2 = fepriv->quality - 128; |
| 321 | q2 *= q2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 323 | fepriv->delay = fepriv->min_delay + q2 * HZ / (128*128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Performs automatic twiddling of frontend parameters. |
| 328 | * |
| 329 | * @param fe The frontend concerned. |
| 330 | * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT |
| 331 | * @returns Number of complete iterations that have been performed. |
| 332 | */ |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 333 | static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wrapped) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | int autoinversion; |
| 336 | int ready = 0; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 337 | int fe_set_err = 0; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 338 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 339 | struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp; |
| 340 | int original_inversion = c->inversion; |
| 341 | u32 original_frequency = c->frequency; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* are we using autoinversion? */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 344 | autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 345 | (c->inversion == INVERSION_AUTO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
| 347 | /* setup parameters correctly */ |
| 348 | while(!ready) { |
| 349 | /* calculate the lnb_drift */ |
| 350 | fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size; |
| 351 | |
| 352 | /* wrap the auto_step if we've exceeded the maximum drift */ |
| 353 | if (fepriv->lnb_drift > fepriv->max_drift) { |
| 354 | fepriv->auto_step = 0; |
| 355 | fepriv->auto_sub_step = 0; |
| 356 | fepriv->lnb_drift = 0; |
| 357 | } |
| 358 | |
| 359 | /* perform inversion and +/- zigzag */ |
| 360 | switch(fepriv->auto_sub_step) { |
| 361 | case 0: |
| 362 | /* try with the current inversion and current drift setting */ |
| 363 | ready = 1; |
| 364 | break; |
| 365 | |
| 366 | case 1: |
| 367 | if (!autoinversion) break; |
| 368 | |
| 369 | fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF; |
| 370 | ready = 1; |
| 371 | break; |
| 372 | |
| 373 | case 2: |
| 374 | if (fepriv->lnb_drift == 0) break; |
| 375 | |
| 376 | fepriv->lnb_drift = -fepriv->lnb_drift; |
| 377 | ready = 1; |
| 378 | break; |
| 379 | |
| 380 | case 3: |
| 381 | if (fepriv->lnb_drift == 0) break; |
| 382 | if (!autoinversion) break; |
| 383 | |
| 384 | fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF; |
| 385 | fepriv->lnb_drift = -fepriv->lnb_drift; |
| 386 | ready = 1; |
| 387 | break; |
| 388 | |
| 389 | default: |
| 390 | fepriv->auto_step++; |
| 391 | fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */ |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | if (!ready) fepriv->auto_sub_step++; |
| 396 | } |
| 397 | |
| 398 | /* if this attempt would hit where we started, indicate a complete |
| 399 | * iteration has occurred */ |
| 400 | if ((fepriv->auto_step == fepriv->started_auto_step) && |
| 401 | (fepriv->auto_sub_step == 0) && check_wrapped) { |
| 402 | return 1; |
| 403 | } |
| 404 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 405 | dev_dbg(fe->dvb->device, "%s: drift:%i inversion:%i auto_step:%i " \ |
| 406 | "auto_sub_step:%i started_auto_step:%i\n", |
| 407 | __func__, fepriv->lnb_drift, fepriv->inversion, |
| 408 | fepriv->auto_step, fepriv->auto_sub_step, |
| 409 | fepriv->started_auto_step); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* set the frontend itself */ |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 412 | c->frequency += fepriv->lnb_drift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | if (autoinversion) |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 414 | c->inversion = fepriv->inversion; |
| 415 | tmp = *c; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 416 | if (fe->ops.set_frontend) |
Mauro Carvalho Chehab | bc9cd27 | 2011-12-20 15:31:54 -0300 | [diff] [blame] | 417 | fe_set_err = fe->ops.set_frontend(fe); |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 418 | *c = tmp; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 419 | if (fe_set_err < 0) { |
| 420 | fepriv->state = FESTATE_ERROR; |
| 421 | return fe_set_err; |
| 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 424 | c->frequency = original_frequency; |
| 425 | c->inversion = original_inversion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | fepriv->auto_sub_step++; |
| 428 | return 0; |
| 429 | } |
| 430 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 431 | static void dvb_frontend_swzigzag(struct dvb_frontend *fe) |
| 432 | { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 433 | enum fe_status s = 0; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 434 | int retval = 0; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 435 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 436 | struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 437 | |
| 438 | /* if we've got no parameters, just keep idling */ |
| 439 | if (fepriv->state & FESTATE_IDLE) { |
| 440 | fepriv->delay = 3*HZ; |
| 441 | fepriv->quality = 0; |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | /* in SCAN mode, we just set the frontend when asked and leave it alone */ |
| 446 | if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) { |
| 447 | if (fepriv->state & FESTATE_RETUNE) { |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 448 | tmp = *c; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 449 | if (fe->ops.set_frontend) |
Mauro Carvalho Chehab | bc9cd27 | 2011-12-20 15:31:54 -0300 | [diff] [blame] | 450 | retval = fe->ops.set_frontend(fe); |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 451 | *c = tmp; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 452 | if (retval < 0) |
| 453 | fepriv->state = FESTATE_ERROR; |
| 454 | else |
| 455 | fepriv->state = FESTATE_TUNED; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 456 | } |
| 457 | fepriv->delay = 3*HZ; |
| 458 | fepriv->quality = 0; |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | /* get the frontend status */ |
| 463 | if (fepriv->state & FESTATE_RETUNE) { |
| 464 | s = 0; |
| 465 | } else { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 466 | if (fe->ops.read_status) |
| 467 | fe->ops.read_status(fe, &s); |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 468 | if (s != fepriv->status) { |
| 469 | dvb_frontend_add_event(fe, s); |
| 470 | fepriv->status = s; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /* if we're not tuned, and we have a lock, move to the TUNED state */ |
| 475 | if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) { |
| 476 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 477 | fepriv->state = FESTATE_TUNED; |
| 478 | |
| 479 | /* if we're tuned, then we have determined the correct inversion */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 480 | if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 481 | (c->inversion == INVERSION_AUTO)) { |
| 482 | c->inversion = fepriv->inversion; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 483 | } |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | /* if we are tuned already, check we're still locked */ |
| 488 | if (fepriv->state & FESTATE_TUNED) { |
| 489 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 490 | |
| 491 | /* we're tuned, and the lock is still good... */ |
| 492 | if (s & FE_HAS_LOCK) { |
| 493 | return; |
| 494 | } else { /* if we _WERE_ tuned, but now don't have a lock */ |
| 495 | fepriv->state = FESTATE_ZIGZAG_FAST; |
| 496 | fepriv->started_auto_step = fepriv->auto_step; |
| 497 | fepriv->check_wrapped = 0; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* don't actually do anything if we're in the LOSTLOCK state, |
| 502 | * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */ |
| 503 | if ((fepriv->state & FESTATE_LOSTLOCK) && |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 504 | (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 505 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | /* don't do anything if we're in the DISEQC state, since this |
| 510 | * might be someone with a motorized dish controlled by DISEQC. |
| 511 | * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */ |
| 512 | if (fepriv->state & FESTATE_DISEQC) { |
| 513 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | /* if we're in the RETUNE state, set everything up for a brand |
| 518 | * new scan, keeping the current inversion setting, as the next |
| 519 | * tune is _very_ likely to require the same */ |
| 520 | if (fepriv->state & FESTATE_RETUNE) { |
| 521 | fepriv->lnb_drift = 0; |
| 522 | fepriv->auto_step = 0; |
| 523 | fepriv->auto_sub_step = 0; |
| 524 | fepriv->started_auto_step = 0; |
| 525 | fepriv->check_wrapped = 0; |
| 526 | } |
| 527 | |
| 528 | /* fast zigzag. */ |
| 529 | if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) { |
| 530 | fepriv->delay = fepriv->min_delay; |
| 531 | |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 532 | /* perform a tune */ |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 533 | retval = dvb_frontend_swzigzag_autotune(fe, |
| 534 | fepriv->check_wrapped); |
| 535 | if (retval < 0) { |
| 536 | return; |
| 537 | } else if (retval) { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 538 | /* OK, if we've run out of trials at the fast speed. |
| 539 | * Drop back to slow for the _next_ attempt */ |
| 540 | fepriv->state = FESTATE_SEARCHING_SLOW; |
| 541 | fepriv->started_auto_step = fepriv->auto_step; |
| 542 | return; |
| 543 | } |
| 544 | fepriv->check_wrapped = 1; |
| 545 | |
| 546 | /* if we've just retuned, enter the ZIGZAG_FAST state. |
| 547 | * This ensures we cannot return from an |
| 548 | * FE_SET_FRONTEND ioctl before the first frontend tune |
| 549 | * occurs */ |
| 550 | if (fepriv->state & FESTATE_RETUNE) { |
| 551 | fepriv->state = FESTATE_TUNING_FAST; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* slow zigzag */ |
| 556 | if (fepriv->state & FESTATE_SEARCHING_SLOW) { |
| 557 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 558 | |
| 559 | /* Note: don't bother checking for wrapping; we stay in this |
| 560 | * state until we get a lock */ |
| 561 | dvb_frontend_swzigzag_autotune(fe, 0); |
| 562 | } |
| 563 | } |
| 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | static int dvb_frontend_is_exiting(struct dvb_frontend *fe) |
| 566 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 567 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 569 | if (fe->exit != DVB_FE_NO_EXIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | return 1; |
| 571 | |
| 572 | if (fepriv->dvbdev->writers == 1) |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 573 | if (time_after_eq(jiffies, fepriv->release_jiffies + |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 574 | dvb_shutdown_timeout * HZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | return 1; |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static int dvb_frontend_should_wakeup(struct dvb_frontend *fe) |
| 581 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 582 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | if (fepriv->wakeup) { |
| 585 | fepriv->wakeup = 0; |
| 586 | return 1; |
| 587 | } |
| 588 | return dvb_frontend_is_exiting(fe); |
| 589 | } |
| 590 | |
| 591 | static void dvb_frontend_wakeup(struct dvb_frontend *fe) |
| 592 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 593 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | fepriv->wakeup = 1; |
| 596 | wake_up_interruptible(&fepriv->wait_queue); |
| 597 | } |
| 598 | |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 599 | /** |
| 600 | * dvb_enable_media_tuner() - tries to enable the DVB tuner |
| 601 | * |
| 602 | * @fe: struct dvb_frontend pointer |
| 603 | * |
| 604 | * This function ensures that just one media tuner is enabled for a given |
| 605 | * frontend. It has two different behaviors: |
| 606 | * - For trivial devices with just one tuner: |
| 607 | * it just enables the existing tuner->fe link |
| 608 | * - For devices with more than one tuner: |
| 609 | * It is up to the driver to implement the logic that will enable one tuner |
| 610 | * and disable the other ones. However, if more than one tuner is enabled for |
| 611 | * the same frontend, it will print an error message and return -EINVAL. |
| 612 | * |
| 613 | * At return, it will return the error code returned by media_entity_setup_link, |
| 614 | * or 0 if everything is OK, if no tuner is linked to the frontend or if the |
| 615 | * mdev is NULL. |
| 616 | */ |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 617 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 618 | static int dvb_enable_media_tuner(struct dvb_frontend *fe) |
| 619 | { |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 620 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 621 | struct dvb_adapter *adapter = fe->dvb; |
| 622 | struct media_device *mdev = adapter->mdev; |
| 623 | struct media_entity *entity, *source; |
| 624 | struct media_link *link, *found_link = NULL; |
| 625 | int i, ret, n_links = 0, active_links = 0; |
| 626 | |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 627 | fepriv->pipe_start_entity = NULL; |
| 628 | |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 629 | if (!mdev) |
| 630 | return 0; |
| 631 | |
| 632 | entity = fepriv->dvbdev->entity; |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 633 | fepriv->pipe_start_entity = entity; |
| 634 | |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 635 | for (i = 0; i < entity->num_links; i++) { |
| 636 | link = &entity->links[i]; |
| 637 | if (link->sink->entity == entity) { |
| 638 | found_link = link; |
| 639 | n_links++; |
| 640 | if (link->flags & MEDIA_LNK_FL_ENABLED) |
| 641 | active_links++; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | if (!n_links || active_links == 1 || !found_link) |
| 646 | return 0; |
| 647 | |
| 648 | /* |
| 649 | * If a frontend has more than one tuner linked, it is up to the driver |
| 650 | * to select with one will be the active one, as the frontend core can't |
| 651 | * guess. If the driver doesn't do that, it is a bug. |
| 652 | */ |
| 653 | if (n_links > 1 && active_links != 1) { |
| 654 | dev_err(fe->dvb->device, |
| 655 | "WARNING: there are %d active links among %d tuners. This is a driver's bug!\n", |
| 656 | active_links, n_links); |
| 657 | return -EINVAL; |
| 658 | } |
| 659 | |
| 660 | source = found_link->source->entity; |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 661 | fepriv->pipe_start_entity = source; |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 662 | for (i = 0; i < source->num_links; i++) { |
| 663 | struct media_entity *sink; |
| 664 | int flags = 0; |
| 665 | |
| 666 | link = &source->links[i]; |
| 667 | sink = link->sink->entity; |
| 668 | |
| 669 | if (sink == entity) |
| 670 | flags = MEDIA_LNK_FL_ENABLED; |
| 671 | |
| 672 | ret = media_entity_setup_link(link, flags); |
| 673 | if (ret) { |
| 674 | dev_err(fe->dvb->device, |
| 675 | "Couldn't change link %s->%s to %s. Error %d\n", |
| 676 | source->name, sink->name, |
| 677 | flags ? "enabled" : "disabled", |
| 678 | ret); |
| 679 | return ret; |
| 680 | } else |
| 681 | dev_dbg(fe->dvb->device, |
| 682 | "link %s->%s was %s\n", |
| 683 | source->name, sink->name, |
| 684 | flags ? "ENABLED" : "disabled"); |
| 685 | } |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 686 | return 0; |
| 687 | } |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 688 | #endif |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | static int dvb_frontend_thread(void *data) |
| 691 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 692 | struct dvb_frontend *fe = data; |
| 693 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 694 | enum fe_status s; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 695 | enum dvbfe_algo algo; |
Mauro Carvalho Chehab | c1bd57d | 2015-02-18 11:43:44 -0300 | [diff] [blame] | 696 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 697 | int ret; |
Mauro Carvalho Chehab | c1bd57d | 2015-02-18 11:43:44 -0300 | [diff] [blame] | 698 | #endif |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 699 | |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 700 | bool re_tune = false; |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 701 | bool semheld = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 703 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 705 | fepriv->check_wrapped = 0; |
| 706 | fepriv->quality = 0; |
| 707 | fepriv->delay = 3*HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | fepriv->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | fepriv->wakeup = 0; |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 710 | fepriv->reinitialise = 0; |
| 711 | |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 712 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 713 | ret = dvb_enable_media_tuner(fe); |
| 714 | if (ret) { |
| 715 | /* FIXME: return an error if it fails */ |
| 716 | dev_info(fe->dvb->device, |
| 717 | "proceeding with FE task\n"); |
Mauro Carvalho Chehab | 8a26a25 | 2015-02-23 09:41:17 -0300 | [diff] [blame] | 718 | } else if (fepriv->pipe_start_entity) { |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 719 | ret = media_entity_pipeline_start(fepriv->pipe_start_entity, |
| 720 | &fepriv->pipe); |
| 721 | if (ret) |
| 722 | return ret; |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 723 | } |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 724 | #endif |
Mauro Carvalho Chehab | 9239effd | 2015-01-06 13:57:55 -0300 | [diff] [blame] | 725 | |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 726 | dvb_frontend_init(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 728 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | while (1) { |
| 730 | up(&fepriv->sem); /* is locked when we enter the thread... */ |
akpm@linux-foundation.org | 6591691 | 2007-02-08 14:36:57 -0300 | [diff] [blame] | 731 | restart: |
Hans Verkuil | 94238e9 | 2011-08-27 11:30:25 -0300 | [diff] [blame] | 732 | wait_event_interruptible_timeout(fepriv->wait_queue, |
Rafael J. Wysocki | e42837b | 2007-10-18 03:04:45 -0700 | [diff] [blame] | 733 | dvb_frontend_should_wakeup(fe) || kthread_should_stop() |
| 734 | || freezing(current), |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 735 | fepriv->delay); |
| 736 | |
| 737 | if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | /* got signal or quitting */ |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 739 | if (!down_interruptible(&fepriv->sem)) |
| 740 | semheld = true; |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 741 | fe->exit = DVB_FE_NORMAL_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | break; |
| 743 | } |
| 744 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 745 | if (try_to_freeze()) |
akpm@linux-foundation.org | 6591691 | 2007-02-08 14:36:57 -0300 | [diff] [blame] | 746 | goto restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | if (down_interruptible(&fepriv->sem)) |
| 749 | break; |
| 750 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 751 | if (fepriv->reinitialise) { |
| 752 | dvb_frontend_init(fe); |
Andreas Oberritter | 42f4e77 | 2011-08-24 14:33:52 -0300 | [diff] [blame] | 753 | if (fe->ops.set_tone && fepriv->tone != -1) |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 754 | fe->ops.set_tone(fe, fepriv->tone); |
Andreas Oberritter | 42f4e77 | 2011-08-24 14:33:52 -0300 | [diff] [blame] | 755 | if (fe->ops.set_voltage && fepriv->voltage != -1) |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 756 | fe->ops.set_voltage(fe, fepriv->voltage); |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 757 | fepriv->reinitialise = 0; |
| 758 | } |
| 759 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 760 | /* do an iteration of the tuning loop */ |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 761 | if (fe->ops.get_frontend_algo) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 762 | algo = fe->ops.get_frontend_algo(fe); |
| 763 | switch (algo) { |
| 764 | case DVBFE_ALGO_HW: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 765 | dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 766 | |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 767 | if (fepriv->state & FESTATE_RETUNE) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 768 | dev_dbg(fe->dvb->device, "%s: Retune requested, FESTATE_RETUNE\n", __func__); |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 769 | re_tune = true; |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 770 | fepriv->state = FESTATE_TUNED; |
Simon Arlott | 45145b6 | 2012-02-06 17:57:01 -0300 | [diff] [blame] | 771 | } else { |
| 772 | re_tune = false; |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 773 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 775 | if (fe->ops.tune) |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 776 | fe->ops.tune(fe, re_tune, fepriv->tune_mode_flags, &fepriv->delay, &s); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 777 | |
Darron Broad | 2fac9a0 | 2008-12-18 06:27:50 -0300 | [diff] [blame] | 778 | if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 779 | dev_dbg(fe->dvb->device, "%s: state changed, adding current state\n", __func__); |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 780 | dvb_frontend_add_event(fe, s); |
| 781 | fepriv->status = s; |
| 782 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 783 | break; |
| 784 | case DVBFE_ALGO_SW: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 785 | dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__); |
Manu Abraham | 70d9063 | 2006-06-29 22:05:23 -0300 | [diff] [blame] | 786 | dvb_frontend_swzigzag(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 787 | break; |
| 788 | case DVBFE_ALGO_CUSTOM: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 789 | dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 790 | if (fepriv->state & FESTATE_RETUNE) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 791 | dev_dbg(fe->dvb->device, "%s: Retune requested, FESTAT_RETUNE\n", __func__); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 792 | fepriv->state = FESTATE_TUNED; |
| 793 | } |
| 794 | /* Case where we are going to search for a carrier |
| 795 | * User asked us to retune again for some reason, possibly |
| 796 | * requesting a search with a new set of parameters |
| 797 | */ |
| 798 | if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) { |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 799 | if (fe->ops.search) { |
Mauro Carvalho Chehab | 41da532 | 2011-12-26 18:03:12 -0300 | [diff] [blame] | 800 | fepriv->algo_status = fe->ops.search(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 801 | /* We did do a search as was requested, the flags are |
| 802 | * now unset as well and has the flags wrt to search. |
| 803 | */ |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 804 | } else { |
| 805 | fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN; |
| 806 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 807 | } |
| 808 | /* Track the carrier if the search was successful */ |
Mauro Carvalho Chehab | 1b5d871 | 2011-12-26 18:11:25 -0300 | [diff] [blame] | 809 | if (fepriv->algo_status != DVBFE_ALGO_SEARCH_SUCCESS) { |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 810 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 811 | fepriv->delay = HZ / 2; |
| 812 | } |
Chris Rankin | 556a044 | 2012-04-06 18:38:18 -0300 | [diff] [blame] | 813 | dtv_property_legacy_params_sync(fe, &fepriv->parameters_out); |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 814 | fe->ops.read_status(fe, &s); |
| 815 | if (s != fepriv->status) { |
| 816 | dvb_frontend_add_event(fe, s); /* update event list */ |
| 817 | fepriv->status = s; |
| 818 | if (!(s & FE_HAS_LOCK)) { |
| 819 | fepriv->delay = HZ / 10; |
| 820 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 821 | } else { |
| 822 | fepriv->delay = 60 * HZ; |
| 823 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 824 | } |
| 825 | break; |
| 826 | default: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 827 | dev_dbg(fe->dvb->device, "%s: UNDEFINED ALGO !\n", __func__); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 828 | break; |
| 829 | } |
| 830 | } else { |
Manu Abraham | 4a4edcc | 2006-06-25 05:46:26 -0300 | [diff] [blame] | 831 | dvb_frontend_swzigzag(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 832 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 835 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
Mauro Carvalho Chehab | 8a26a25 | 2015-02-23 09:41:17 -0300 | [diff] [blame] | 836 | if (fepriv->pipe_start_entity) |
| 837 | media_entity_pipeline_stop(fepriv->pipe_start_entity); |
Mauro Carvalho Chehab | 135f9be | 2015-01-06 17:53:15 -0300 | [diff] [blame] | 838 | fepriv->pipe_start_entity = NULL; |
| 839 | #endif |
| 840 | |
Oliver Endriss | 608f62d | 2007-08-25 13:17:53 -0300 | [diff] [blame] | 841 | if (dvb_powerdown_on_sleep) { |
| 842 | if (fe->ops.set_voltage) |
| 843 | fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 844 | if (fe->ops.tuner_ops.sleep) { |
Devin Heitmueller | 41286d9 | 2008-11-16 00:44:52 -0300 | [diff] [blame] | 845 | if (fe->ops.i2c_gate_ctrl) |
| 846 | fe->ops.i2c_gate_ctrl(fe, 1); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 847 | fe->ops.tuner_ops.sleep(fe); |
| 848 | if (fe->ops.i2c_gate_ctrl) |
| 849 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 7eef5dd | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 850 | } |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 851 | if (fe->ops.sleep) |
| 852 | fe->ops.sleep(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 855 | fepriv->thread = NULL; |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 856 | if (kthread_should_stop()) |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 857 | fe->exit = DVB_FE_DEVICE_REMOVED; |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 858 | else |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 859 | fe->exit = DVB_FE_NO_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | mb(); |
| 861 | |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 862 | if (semheld) |
| 863 | up(&fepriv->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | dvb_frontend_wakeup(fe); |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | static void dvb_frontend_stop(struct dvb_frontend *fe) |
| 869 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 870 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 872 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 874 | if (fe->exit != DVB_FE_DEVICE_REMOVED) |
| 875 | fe->exit = DVB_FE_NORMAL_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | mb(); |
| 877 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 878 | if (!fepriv->thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | return; |
| 880 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 881 | kthread_stop(fepriv->thread); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 882 | |
Thomas Gleixner | a0a4714 | 2010-09-07 11:33:27 -0300 | [diff] [blame] | 883 | sema_init(&fepriv->sem, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | fepriv->state = FESTATE_IDLE; |
| 885 | |
| 886 | /* paranoia check in case a signal arrived */ |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 887 | if (fepriv->thread) |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 888 | dev_warn(fe->dvb->device, |
| 889 | "dvb_frontend_stop: warning: thread %p won't exit\n", |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 890 | fepriv->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | } |
| 892 | |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 893 | /* |
Mauro Carvalho Chehab | 4deea4c | 2015-11-09 23:24:10 -0200 | [diff] [blame] | 894 | * Sleep for the amount of time given by add_usec parameter |
| 895 | * |
| 896 | * This needs to be as precise as possible, as it affects the detection of |
| 897 | * the dish tone command at the satellite subsystem. The precision is improved |
| 898 | * by using a scheduled msleep followed by udelay for the remainder. |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 899 | */ |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 900 | void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec) |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 901 | { |
Mauro Carvalho Chehab | a733a41 | 2015-11-18 12:55:47 -0200 | [diff] [blame] | 902 | s32 delta; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 903 | |
Mauro Carvalho Chehab | a733a41 | 2015-11-18 12:55:47 -0200 | [diff] [blame] | 904 | *waketime = ktime_add_us(*waketime, add_usec); |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 905 | delta = ktime_us_delta(ktime_get_real(), *waketime); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 906 | if (delta > 2500) { |
| 907 | msleep((delta - 1500) / 1000); |
Mauro Carvalho Chehab | a733a41 | 2015-11-18 12:55:47 -0200 | [diff] [blame] | 908 | delta = ktime_us_delta(ktime_get_real(), *waketime); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 909 | } |
| 910 | if (delta > 0) |
| 911 | udelay(delta); |
| 912 | } |
| 913 | EXPORT_SYMBOL(dvb_frontend_sleep_until); |
| 914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | static int dvb_frontend_start(struct dvb_frontend *fe) |
| 916 | { |
| 917 | int ret; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 918 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 919 | struct task_struct *fe_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 921 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 923 | if (fepriv->thread) { |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 924 | if (fe->exit == DVB_FE_NO_EXIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | return 0; |
| 926 | else |
| 927 | dvb_frontend_stop (fe); |
| 928 | } |
| 929 | |
| 930 | if (signal_pending(current)) |
| 931 | return -EINTR; |
| 932 | if (down_interruptible (&fepriv->sem)) |
| 933 | return -EINTR; |
| 934 | |
| 935 | fepriv->state = FESTATE_IDLE; |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 936 | fe->exit = DVB_FE_NO_EXIT; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 937 | fepriv->thread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | mb(); |
| 939 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 940 | fe_thread = kthread_run(dvb_frontend_thread, fe, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 941 | "kdvb-ad-%i-fe-%i", fe->dvb->num,fe->id); |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 942 | if (IS_ERR(fe_thread)) { |
| 943 | ret = PTR_ERR(fe_thread); |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 944 | dev_warn(fe->dvb->device, |
| 945 | "dvb_frontend_start: failed to start kthread (%d)\n", |
| 946 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | up(&fepriv->sem); |
| 948 | return ret; |
| 949 | } |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 950 | fepriv->thread = fe_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | return 0; |
| 952 | } |
| 953 | |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 954 | static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe, |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 955 | u32 *freq_min, u32 *freq_max) |
| 956 | { |
| 957 | *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min); |
| 958 | |
| 959 | if (fe->ops.info.frequency_max == 0) |
| 960 | *freq_max = fe->ops.tuner_ops.info.frequency_max; |
| 961 | else if (fe->ops.tuner_ops.info.frequency_max == 0) |
| 962 | *freq_max = fe->ops.info.frequency_max; |
| 963 | else |
| 964 | *freq_max = min(fe->ops.info.frequency_max, fe->ops.tuner_ops.info.frequency_max); |
| 965 | |
| 966 | if (*freq_min == 0 || *freq_max == 0) |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 967 | dev_warn(fe->dvb->device, "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n", |
| 968 | fe->dvb->num, fe->id); |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 969 | } |
| 970 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 971 | static int dvb_frontend_check_parameters(struct dvb_frontend *fe) |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 972 | { |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 973 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 974 | u32 freq_min; |
| 975 | u32 freq_max; |
| 976 | |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 977 | /* range check: frequency */ |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 978 | dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 979 | if ((freq_min && c->frequency < freq_min) || |
| 980 | (freq_max && c->frequency > freq_max)) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 981 | dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n", |
| 982 | fe->dvb->num, fe->id, c->frequency, |
| 983 | freq_min, freq_max); |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 984 | return -EINVAL; |
| 985 | } |
| 986 | |
| 987 | /* range check: symbol rate */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 988 | switch (c->delivery_system) { |
| 989 | case SYS_DVBS: |
| 990 | case SYS_DVBS2: |
| 991 | case SYS_TURBO: |
| 992 | case SYS_DVBC_ANNEX_A: |
| 993 | case SYS_DVBC_ANNEX_C: |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 994 | if ((fe->ops.info.symbol_rate_min && |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 995 | c->symbol_rate < fe->ops.info.symbol_rate_min) || |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 996 | (fe->ops.info.symbol_rate_max && |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 997 | c->symbol_rate > fe->ops.info.symbol_rate_max)) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 998 | dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n", |
| 999 | fe->dvb->num, fe->id, c->symbol_rate, |
| 1000 | fe->ops.info.symbol_rate_min, |
| 1001 | fe->ops.info.symbol_rate_max); |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 1002 | return -EINVAL; |
| 1003 | } |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1004 | default: |
| 1005 | break; |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1011 | static int dvb_frontend_clear_cache(struct dvb_frontend *fe) |
| 1012 | { |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1013 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1014 | int i; |
Mauro Carvalho Chehab | 149709f | 2012-01-13 11:46:36 -0200 | [diff] [blame] | 1015 | u32 delsys; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1016 | |
Mauro Carvalho Chehab | 149709f | 2012-01-13 11:46:36 -0200 | [diff] [blame] | 1017 | delsys = c->delivery_system; |
Mauro Carvalho Chehab | 808d24d | 2013-03-20 10:39:31 -0300 | [diff] [blame] | 1018 | memset(c, 0, offsetof(struct dtv_frontend_properties, strength)); |
Mauro Carvalho Chehab | 149709f | 2012-01-13 11:46:36 -0200 | [diff] [blame] | 1019 | c->delivery_system = delsys; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1020 | |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1021 | c->state = DTV_CLEAR; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1022 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1023 | dev_dbg(fe->dvb->device, "%s: Clearing cache for delivery system %d\n", |
| 1024 | __func__, c->delivery_system); |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1025 | |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1026 | c->transmission_mode = TRANSMISSION_MODE_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1027 | c->bandwidth_hz = 0; /* AUTO */ |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1028 | c->guard_interval = GUARD_INTERVAL_AUTO; |
| 1029 | c->hierarchy = HIERARCHY_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1030 | c->symbol_rate = 0; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1031 | c->code_rate_HP = FEC_AUTO; |
| 1032 | c->code_rate_LP = FEC_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1033 | c->fec_inner = FEC_AUTO; |
Mauro Carvalho Chehab | 39ce61a | 2011-11-11 12:46:23 -0200 | [diff] [blame] | 1034 | c->rolloff = ROLLOFF_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1035 | c->voltage = SEC_VOLTAGE_OFF; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1036 | c->sectone = SEC_TONE_OFF; |
| 1037 | c->pilot = PILOT_AUTO; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1038 | |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 1039 | c->isdbt_partial_reception = 0; |
| 1040 | c->isdbt_sb_mode = 0; |
| 1041 | c->isdbt_sb_subchannel = 0; |
| 1042 | c->isdbt_sb_segment_idx = 0; |
| 1043 | c->isdbt_sb_segment_count = 0; |
| 1044 | c->isdbt_layer_enabled = 0; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1045 | for (i = 0; i < 3; i++) { |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1046 | c->layer[i].fec = FEC_AUTO; |
| 1047 | c->layer[i].modulation = QAM_AUTO; |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 1048 | c->layer[i].interleaving = 0; |
| 1049 | c->layer[i].segment_count = 0; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1050 | } |
| 1051 | |
Evgeny Plehov | 287cefd | 2012-09-13 10:13:30 -0300 | [diff] [blame] | 1052 | c->stream_id = NO_STREAM_ID_FILTER; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 1053 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1054 | switch (c->delivery_system) { |
| 1055 | case SYS_DVBS: |
| 1056 | case SYS_DVBS2: |
| 1057 | case SYS_TURBO: |
| 1058 | c->modulation = QPSK; /* implied for DVB-S in legacy API */ |
| 1059 | c->rolloff = ROLLOFF_35;/* implied for DVB-S */ |
| 1060 | break; |
| 1061 | case SYS_ATSC: |
| 1062 | c->modulation = VSB_8; |
| 1063 | break; |
Akihiro Tsukada | 8e281fa | 2014-10-31 10:19:39 -0300 | [diff] [blame] | 1064 | case SYS_ISDBS: |
| 1065 | c->symbol_rate = 28860000; |
| 1066 | c->rolloff = ROLLOFF_35; |
| 1067 | c->bandwidth_hz = c->symbol_rate / 100 * 135; |
| 1068 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1069 | default: |
| 1070 | c->modulation = QAM_AUTO; |
| 1071 | break; |
| 1072 | } |
| 1073 | |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 1074 | c->lna = LNA_AUTO; |
| 1075 | |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1076 | return 0; |
| 1077 | } |
| 1078 | |
| 1079 | #define _DTV_CMD(n, s, b) \ |
| 1080 | [n] = { \ |
| 1081 | .name = #n, \ |
| 1082 | .cmd = n, \ |
| 1083 | .set = s,\ |
| 1084 | .buffer = b \ |
| 1085 | } |
| 1086 | |
Andreas Oberritter | ec05a64 | 2011-05-26 07:54:14 -0300 | [diff] [blame] | 1087 | static struct dtv_cmds_h dtv_cmds[DTV_MAX_COMMAND + 1] = { |
Mauro Carvalho Chehab | 06d3a39 | 2009-10-23 20:09:42 -0300 | [diff] [blame] | 1088 | _DTV_CMD(DTV_TUNE, 1, 0), |
| 1089 | _DTV_CMD(DTV_CLEAR, 1, 0), |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1090 | |
| 1091 | /* Set */ |
Mauro Carvalho Chehab | 06d3a39 | 2009-10-23 20:09:42 -0300 | [diff] [blame] | 1092 | _DTV_CMD(DTV_FREQUENCY, 1, 0), |
| 1093 | _DTV_CMD(DTV_BANDWIDTH_HZ, 1, 0), |
| 1094 | _DTV_CMD(DTV_MODULATION, 1, 0), |
| 1095 | _DTV_CMD(DTV_INVERSION, 1, 0), |
| 1096 | _DTV_CMD(DTV_DISEQC_MASTER, 1, 1), |
| 1097 | _DTV_CMD(DTV_SYMBOL_RATE, 1, 0), |
| 1098 | _DTV_CMD(DTV_INNER_FEC, 1, 0), |
| 1099 | _DTV_CMD(DTV_VOLTAGE, 1, 0), |
| 1100 | _DTV_CMD(DTV_TONE, 1, 0), |
| 1101 | _DTV_CMD(DTV_PILOT, 1, 0), |
| 1102 | _DTV_CMD(DTV_ROLLOFF, 1, 0), |
| 1103 | _DTV_CMD(DTV_DELIVERY_SYSTEM, 1, 0), |
| 1104 | _DTV_CMD(DTV_HIERARCHY, 1, 0), |
| 1105 | _DTV_CMD(DTV_CODE_RATE_HP, 1, 0), |
| 1106 | _DTV_CMD(DTV_CODE_RATE_LP, 1, 0), |
| 1107 | _DTV_CMD(DTV_GUARD_INTERVAL, 1, 0), |
| 1108 | _DTV_CMD(DTV_TRANSMISSION_MODE, 1, 0), |
Antti Palosaari | 224b664 | 2012-08-12 22:33:21 -0300 | [diff] [blame] | 1109 | _DTV_CMD(DTV_INTERLEAVING, 1, 0), |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1110 | |
| 1111 | _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 1, 0), |
| 1112 | _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 1, 0), |
| 1113 | _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 1, 0), |
| 1114 | _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 1, 0), |
| 1115 | _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 1, 0), |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1116 | _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 1, 0), |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1117 | _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 1, 0), |
| 1118 | _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 1, 0), |
| 1119 | _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 1, 0), |
| 1120 | _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 1, 0), |
| 1121 | _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 1, 0), |
| 1122 | _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 1, 0), |
| 1123 | _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 1, 0), |
| 1124 | _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 1, 0), |
| 1125 | _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 1, 0), |
| 1126 | _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 1, 0), |
| 1127 | _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 1, 0), |
| 1128 | _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 1, 0), |
| 1129 | |
Evgeny Plehov | 287cefd | 2012-09-13 10:13:30 -0300 | [diff] [blame] | 1130 | _DTV_CMD(DTV_STREAM_ID, 1, 0), |
| 1131 | _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY, 1, 0), |
Antti Palosaari | 8a2697a | 2012-07-11 21:54:50 -0300 | [diff] [blame] | 1132 | _DTV_CMD(DTV_LNA, 1, 0), |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1133 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1134 | /* Get */ |
Mauro Carvalho Chehab | 06d3a39 | 2009-10-23 20:09:42 -0300 | [diff] [blame] | 1135 | _DTV_CMD(DTV_DISEQC_SLAVE_REPLY, 0, 1), |
| 1136 | _DTV_CMD(DTV_API_VERSION, 0, 0), |
Manu Abraham | ba2780c | 2011-11-13 18:47:44 -0300 | [diff] [blame] | 1137 | |
| 1138 | _DTV_CMD(DTV_ENUM_DELSYS, 0, 0), |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1139 | |
| 1140 | _DTV_CMD(DTV_ATSCMH_PARADE_ID, 1, 0), |
| 1141 | _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE, 1, 0), |
| 1142 | |
| 1143 | _DTV_CMD(DTV_ATSCMH_FIC_VER, 0, 0), |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1144 | _DTV_CMD(DTV_ATSCMH_NOG, 0, 0), |
| 1145 | _DTV_CMD(DTV_ATSCMH_TNOG, 0, 0), |
| 1146 | _DTV_CMD(DTV_ATSCMH_SGN, 0, 0), |
| 1147 | _DTV_CMD(DTV_ATSCMH_PRC, 0, 0), |
| 1148 | _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE, 0, 0), |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1149 | _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI, 0, 0), |
| 1150 | _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC, 0, 0), |
| 1151 | _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE, 0, 0), |
| 1152 | _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A, 0, 0), |
| 1153 | _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B, 0, 0), |
| 1154 | _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C, 0, 0), |
| 1155 | _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D, 0, 0), |
Mauro Carvalho Chehab | 7cd4ece | 2013-01-07 15:41:35 -0300 | [diff] [blame] | 1156 | |
| 1157 | /* Statistics API */ |
| 1158 | _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH, 0, 0), |
| 1159 | _DTV_CMD(DTV_STAT_CNR, 0, 0), |
| 1160 | _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT, 0, 0), |
| 1161 | _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT, 0, 0), |
| 1162 | _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT, 0, 0), |
| 1163 | _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT, 0, 0), |
| 1164 | _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT, 0, 0), |
| 1165 | _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT, 0, 0), |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1166 | }; |
| 1167 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1168 | static void dtv_property_dump(struct dvb_frontend *fe, struct dtv_property *tvp) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1169 | { |
| 1170 | int i; |
| 1171 | |
Mauro Carvalho Chehab | 106ff9e | 2011-07-15 08:49:06 -0300 | [diff] [blame] | 1172 | if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1173 | dev_warn(fe->dvb->device, "%s: tvp.cmd = 0x%08x undefined\n", |
| 1174 | __func__, tvp->cmd); |
Darron Broad | 4aae8ef | 2008-10-03 11:50:00 -0300 | [diff] [blame] | 1175 | return; |
| 1176 | } |
| 1177 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1178 | dev_dbg(fe->dvb->device, "%s: tvp.cmd = 0x%08x (%s)\n", __func__, |
| 1179 | tvp->cmd, dtv_cmds[tvp->cmd].name); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1180 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1181 | if (dtv_cmds[tvp->cmd].buffer) { |
| 1182 | dev_dbg(fe->dvb->device, "%s: tvp.u.buffer.len = 0x%02x\n", |
| 1183 | __func__, tvp->u.buffer.len); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1184 | |
| 1185 | for(i = 0; i < tvp->u.buffer.len; i++) |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1186 | dev_dbg(fe->dvb->device, |
| 1187 | "%s: tvp.u.buffer.data[0x%02x] = 0x%02x\n", |
| 1188 | __func__, i, tvp->u.buffer.data[i]); |
| 1189 | } else { |
| 1190 | dev_dbg(fe->dvb->device, "%s: tvp.u.data = 0x%08x\n", __func__, |
| 1191 | tvp->u.data); |
| 1192 | } |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1193 | } |
| 1194 | |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1195 | /* Synchronise the legacy tuning parameters into the cache, so that demodulator |
| 1196 | * drivers can use a single set_frontend tuning function, regardless of whether |
| 1197 | * it's being used for the legacy or new API, reducing code and complexity. |
| 1198 | */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1199 | static int dtv_property_cache_sync(struct dvb_frontend *fe, |
| 1200 | struct dtv_frontend_properties *c, |
| 1201 | const struct dvb_frontend_parameters *p) |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1202 | { |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1203 | c->frequency = p->frequency; |
| 1204 | c->inversion = p->inversion; |
| 1205 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1206 | switch (dvbv3_type(c->delivery_system)) { |
| 1207 | case DVBV3_QPSK: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1208 | dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__); |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1209 | c->symbol_rate = p->u.qpsk.symbol_rate; |
| 1210 | c->fec_inner = p->u.qpsk.fec_inner; |
| 1211 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1212 | case DVBV3_QAM: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1213 | dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__); |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1214 | c->symbol_rate = p->u.qam.symbol_rate; |
| 1215 | c->fec_inner = p->u.qam.fec_inner; |
| 1216 | c->modulation = p->u.qam.modulation; |
| 1217 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1218 | case DVBV3_OFDM: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1219 | dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__); |
| 1220 | |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1221 | switch (p->u.ofdm.bandwidth) { |
| 1222 | case BANDWIDTH_10_MHZ: |
| 1223 | c->bandwidth_hz = 10000000; |
| 1224 | break; |
| 1225 | case BANDWIDTH_8_MHZ: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1226 | c->bandwidth_hz = 8000000; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1227 | break; |
| 1228 | case BANDWIDTH_7_MHZ: |
| 1229 | c->bandwidth_hz = 7000000; |
| 1230 | break; |
| 1231 | case BANDWIDTH_6_MHZ: |
| 1232 | c->bandwidth_hz = 6000000; |
| 1233 | break; |
| 1234 | case BANDWIDTH_5_MHZ: |
| 1235 | c->bandwidth_hz = 5000000; |
| 1236 | break; |
| 1237 | case BANDWIDTH_1_712_MHZ: |
| 1238 | c->bandwidth_hz = 1712000; |
| 1239 | break; |
| 1240 | case BANDWIDTH_AUTO: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1241 | c->bandwidth_hz = 0; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1242 | } |
| 1243 | |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1244 | c->code_rate_HP = p->u.ofdm.code_rate_HP; |
| 1245 | c->code_rate_LP = p->u.ofdm.code_rate_LP; |
| 1246 | c->modulation = p->u.ofdm.constellation; |
| 1247 | c->transmission_mode = p->u.ofdm.transmission_mode; |
| 1248 | c->guard_interval = p->u.ofdm.guard_interval; |
| 1249 | c->hierarchy = p->u.ofdm.hierarchy_information; |
| 1250 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1251 | case DVBV3_ATSC: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1252 | dev_dbg(fe->dvb->device, "%s: Preparing ATSC req\n", __func__); |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1253 | c->modulation = p->u.vsb.modulation; |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1254 | if (c->delivery_system == SYS_ATSCMH) |
| 1255 | break; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1256 | if ((c->modulation == VSB_8) || (c->modulation == VSB_16)) |
| 1257 | c->delivery_system = SYS_ATSC; |
| 1258 | else |
| 1259 | c->delivery_system = SYS_DVBC_ANNEX_B; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1260 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1261 | case DVBV3_UNKNOWN: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1262 | dev_err(fe->dvb->device, |
| 1263 | "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n", |
| 1264 | __func__, c->delivery_system); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1265 | return -EINVAL; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1266 | } |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1267 | |
| 1268 | return 0; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1269 | } |
| 1270 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1271 | /* Ensure the cached values are set correctly in the frontend |
| 1272 | * legacy tuning structures, for the advanced tuning API. |
| 1273 | */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1274 | static int dtv_property_legacy_params_sync(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1275 | struct dvb_frontend_parameters *p) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1276 | { |
Andreas Oberritter | 15cc2bb | 2011-05-08 20:03:35 -0300 | [diff] [blame] | 1277 | const struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1278 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1279 | p->frequency = c->frequency; |
| 1280 | p->inversion = c->inversion; |
| 1281 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1282 | switch (dvbv3_type(c->delivery_system)) { |
| 1283 | case DVBV3_UNKNOWN: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1284 | dev_err(fe->dvb->device, |
| 1285 | "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n", |
| 1286 | __func__, c->delivery_system); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1287 | return -EINVAL; |
| 1288 | case DVBV3_QPSK: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1289 | dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1290 | p->u.qpsk.symbol_rate = c->symbol_rate; |
| 1291 | p->u.qpsk.fec_inner = c->fec_inner; |
| 1292 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1293 | case DVBV3_QAM: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1294 | dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1295 | p->u.qam.symbol_rate = c->symbol_rate; |
| 1296 | p->u.qam.fec_inner = c->fec_inner; |
| 1297 | p->u.qam.modulation = c->modulation; |
| 1298 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1299 | case DVBV3_OFDM: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1300 | dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__); |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1301 | switch (c->bandwidth_hz) { |
| 1302 | case 10000000: |
| 1303 | p->u.ofdm.bandwidth = BANDWIDTH_10_MHZ; |
| 1304 | break; |
| 1305 | case 8000000: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1306 | p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1307 | break; |
| 1308 | case 7000000: |
| 1309 | p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ; |
| 1310 | break; |
| 1311 | case 6000000: |
| 1312 | p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ; |
| 1313 | break; |
| 1314 | case 5000000: |
| 1315 | p->u.ofdm.bandwidth = BANDWIDTH_5_MHZ; |
| 1316 | break; |
| 1317 | case 1712000: |
| 1318 | p->u.ofdm.bandwidth = BANDWIDTH_1_712_MHZ; |
| 1319 | break; |
| 1320 | case 0: |
| 1321 | default: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1322 | p->u.ofdm.bandwidth = BANDWIDTH_AUTO; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1323 | } |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1324 | p->u.ofdm.code_rate_HP = c->code_rate_HP; |
| 1325 | p->u.ofdm.code_rate_LP = c->code_rate_LP; |
| 1326 | p->u.ofdm.constellation = c->modulation; |
| 1327 | p->u.ofdm.transmission_mode = c->transmission_mode; |
| 1328 | p->u.ofdm.guard_interval = c->guard_interval; |
| 1329 | p->u.ofdm.hierarchy_information = c->hierarchy; |
| 1330 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1331 | case DVBV3_ATSC: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1332 | dev_dbg(fe->dvb->device, "%s: Preparing VSB req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1333 | p->u.vsb.modulation = c->modulation; |
| 1334 | break; |
| 1335 | } |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1336 | return 0; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1337 | } |
| 1338 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1339 | /** |
| 1340 | * dtv_get_frontend - calls a callback for retrieving DTV parameters |
| 1341 | * @fe: struct dvb_frontend pointer |
| 1342 | * @c: struct dtv_frontend_properties pointer (DVBv5 cache) |
| 1343 | * @p_out struct dvb_frontend_parameters pointer (DVBv3 FE struct) |
| 1344 | * |
| 1345 | * This routine calls either the DVBv3 or DVBv5 get_frontend call. |
| 1346 | * If c is not null, it will update the DVBv5 cache struct pointed by it. |
| 1347 | * If p_out is not null, it will update the DVBv3 params pointed by it. |
| 1348 | */ |
| 1349 | static int dtv_get_frontend(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1350 | struct dvb_frontend_parameters *p_out) |
| 1351 | { |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1352 | int r; |
| 1353 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1354 | if (fe->ops.get_frontend) { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1355 | r = fe->ops.get_frontend(fe); |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1356 | if (unlikely(r < 0)) |
| 1357 | return r; |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1358 | if (p_out) |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1359 | dtv_property_legacy_params_sync(fe, p_out); |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1363 | /* As everything is in cache, get_frontend fops are always supported */ |
Mauro Carvalho Chehab | b1e9a6501 | 2011-12-26 16:43:32 -0300 | [diff] [blame] | 1364 | return 0; |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1365 | } |
| 1366 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1367 | static int dvb_frontend_ioctl_legacy(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1368 | unsigned int cmd, void *parg); |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1369 | static int dvb_frontend_ioctl_properties(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1370 | unsigned int cmd, void *parg); |
| 1371 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1372 | static int dtv_property_process_get(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1373 | const struct dtv_frontend_properties *c, |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1374 | struct dtv_property *tvp, |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1375 | struct file *file) |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1376 | { |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1377 | int r, ncaps; |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1378 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1379 | switch(tvp->cmd) { |
Manu Abraham | ba2780c | 2011-11-13 18:47:44 -0300 | [diff] [blame] | 1380 | case DTV_ENUM_DELSYS: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1381 | ncaps = 0; |
Ole Ernst | 0123f29 | 2014-03-05 14:08:15 -0300 | [diff] [blame] | 1382 | while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) { |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1383 | tvp->u.buffer.data[ncaps] = fe->ops.delsys[ncaps]; |
| 1384 | ncaps++; |
| 1385 | } |
| 1386 | tvp->u.buffer.len = ncaps; |
Manu Abraham | ba2780c | 2011-11-13 18:47:44 -0300 | [diff] [blame] | 1387 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1388 | case DTV_FREQUENCY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1389 | tvp->u.data = c->frequency; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1390 | break; |
| 1391 | case DTV_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1392 | tvp->u.data = c->modulation; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1393 | break; |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1394 | case DTV_BANDWIDTH_HZ: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1395 | tvp->u.data = c->bandwidth_hz; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1396 | break; |
| 1397 | case DTV_INVERSION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1398 | tvp->u.data = c->inversion; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1399 | break; |
| 1400 | case DTV_SYMBOL_RATE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1401 | tvp->u.data = c->symbol_rate; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1402 | break; |
| 1403 | case DTV_INNER_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1404 | tvp->u.data = c->fec_inner; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1405 | break; |
| 1406 | case DTV_PILOT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1407 | tvp->u.data = c->pilot; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1408 | break; |
| 1409 | case DTV_ROLLOFF: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1410 | tvp->u.data = c->rolloff; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1411 | break; |
| 1412 | case DTV_DELIVERY_SYSTEM: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1413 | tvp->u.data = c->delivery_system; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1414 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1415 | case DTV_VOLTAGE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1416 | tvp->u.data = c->voltage; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1417 | break; |
| 1418 | case DTV_TONE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1419 | tvp->u.data = c->sectone; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1420 | break; |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 1421 | case DTV_API_VERSION: |
| 1422 | tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR; |
| 1423 | break; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1424 | case DTV_CODE_RATE_HP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1425 | tvp->u.data = c->code_rate_HP; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1426 | break; |
| 1427 | case DTV_CODE_RATE_LP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1428 | tvp->u.data = c->code_rate_LP; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1429 | break; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1430 | case DTV_GUARD_INTERVAL: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1431 | tvp->u.data = c->guard_interval; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1432 | break; |
| 1433 | case DTV_TRANSMISSION_MODE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1434 | tvp->u.data = c->transmission_mode; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1435 | break; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1436 | case DTV_HIERARCHY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1437 | tvp->u.data = c->hierarchy; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1438 | break; |
Antti Palosaari | 224b664 | 2012-08-12 22:33:21 -0300 | [diff] [blame] | 1439 | case DTV_INTERLEAVING: |
| 1440 | tvp->u.data = c->interleaving; |
| 1441 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1442 | |
| 1443 | /* ISDB-T Support here */ |
| 1444 | case DTV_ISDBT_PARTIAL_RECEPTION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1445 | tvp->u.data = c->isdbt_partial_reception; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1446 | break; |
| 1447 | case DTV_ISDBT_SOUND_BROADCASTING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1448 | tvp->u.data = c->isdbt_sb_mode; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1449 | break; |
| 1450 | case DTV_ISDBT_SB_SUBCHANNEL_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1451 | tvp->u.data = c->isdbt_sb_subchannel; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1452 | break; |
| 1453 | case DTV_ISDBT_SB_SEGMENT_IDX: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1454 | tvp->u.data = c->isdbt_sb_segment_idx; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1455 | break; |
| 1456 | case DTV_ISDBT_SB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1457 | tvp->u.data = c->isdbt_sb_segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1458 | break; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1459 | case DTV_ISDBT_LAYER_ENABLED: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1460 | tvp->u.data = c->isdbt_layer_enabled; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1461 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1462 | case DTV_ISDBT_LAYERA_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1463 | tvp->u.data = c->layer[0].fec; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1464 | break; |
| 1465 | case DTV_ISDBT_LAYERA_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1466 | tvp->u.data = c->layer[0].modulation; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1467 | break; |
| 1468 | case DTV_ISDBT_LAYERA_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1469 | tvp->u.data = c->layer[0].segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1470 | break; |
| 1471 | case DTV_ISDBT_LAYERA_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1472 | tvp->u.data = c->layer[0].interleaving; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1473 | break; |
| 1474 | case DTV_ISDBT_LAYERB_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1475 | tvp->u.data = c->layer[1].fec; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1476 | break; |
| 1477 | case DTV_ISDBT_LAYERB_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1478 | tvp->u.data = c->layer[1].modulation; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1479 | break; |
| 1480 | case DTV_ISDBT_LAYERB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1481 | tvp->u.data = c->layer[1].segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1482 | break; |
| 1483 | case DTV_ISDBT_LAYERB_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1484 | tvp->u.data = c->layer[1].interleaving; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1485 | break; |
| 1486 | case DTV_ISDBT_LAYERC_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1487 | tvp->u.data = c->layer[2].fec; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1488 | break; |
| 1489 | case DTV_ISDBT_LAYERC_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1490 | tvp->u.data = c->layer[2].modulation; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1491 | break; |
| 1492 | case DTV_ISDBT_LAYERC_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1493 | tvp->u.data = c->layer[2].segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1494 | break; |
| 1495 | case DTV_ISDBT_LAYERC_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1496 | tvp->u.data = c->layer[2].interleaving; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1497 | break; |
Evgeny Plehov | 287cefd | 2012-09-13 10:13:30 -0300 | [diff] [blame] | 1498 | |
| 1499 | /* Multistream support */ |
| 1500 | case DTV_STREAM_ID: |
| 1501 | case DTV_DVBT2_PLP_ID_LEGACY: |
| 1502 | tvp->u.data = c->stream_id; |
Andreas Oberritter | 94d56ff | 2011-05-12 18:11:06 -0300 | [diff] [blame] | 1503 | break; |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1504 | |
| 1505 | /* ATSC-MH */ |
| 1506 | case DTV_ATSCMH_FIC_VER: |
| 1507 | tvp->u.data = fe->dtv_property_cache.atscmh_fic_ver; |
| 1508 | break; |
| 1509 | case DTV_ATSCMH_PARADE_ID: |
| 1510 | tvp->u.data = fe->dtv_property_cache.atscmh_parade_id; |
| 1511 | break; |
| 1512 | case DTV_ATSCMH_NOG: |
| 1513 | tvp->u.data = fe->dtv_property_cache.atscmh_nog; |
| 1514 | break; |
| 1515 | case DTV_ATSCMH_TNOG: |
| 1516 | tvp->u.data = fe->dtv_property_cache.atscmh_tnog; |
| 1517 | break; |
| 1518 | case DTV_ATSCMH_SGN: |
| 1519 | tvp->u.data = fe->dtv_property_cache.atscmh_sgn; |
| 1520 | break; |
| 1521 | case DTV_ATSCMH_PRC: |
| 1522 | tvp->u.data = fe->dtv_property_cache.atscmh_prc; |
| 1523 | break; |
| 1524 | case DTV_ATSCMH_RS_FRAME_MODE: |
| 1525 | tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_mode; |
| 1526 | break; |
| 1527 | case DTV_ATSCMH_RS_FRAME_ENSEMBLE: |
| 1528 | tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_ensemble; |
| 1529 | break; |
| 1530 | case DTV_ATSCMH_RS_CODE_MODE_PRI: |
| 1531 | tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_pri; |
| 1532 | break; |
| 1533 | case DTV_ATSCMH_RS_CODE_MODE_SEC: |
| 1534 | tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_sec; |
| 1535 | break; |
| 1536 | case DTV_ATSCMH_SCCC_BLOCK_MODE: |
| 1537 | tvp->u.data = fe->dtv_property_cache.atscmh_sccc_block_mode; |
| 1538 | break; |
| 1539 | case DTV_ATSCMH_SCCC_CODE_MODE_A: |
| 1540 | tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_a; |
| 1541 | break; |
| 1542 | case DTV_ATSCMH_SCCC_CODE_MODE_B: |
| 1543 | tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_b; |
| 1544 | break; |
| 1545 | case DTV_ATSCMH_SCCC_CODE_MODE_C: |
| 1546 | tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_c; |
| 1547 | break; |
| 1548 | case DTV_ATSCMH_SCCC_CODE_MODE_D: |
| 1549 | tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_d; |
| 1550 | break; |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1551 | |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 1552 | case DTV_LNA: |
| 1553 | tvp->u.data = c->lna; |
| 1554 | break; |
| 1555 | |
Mauro Carvalho Chehab | 7cd4ece | 2013-01-07 15:41:35 -0300 | [diff] [blame] | 1556 | /* Fill quality measures */ |
| 1557 | case DTV_STAT_SIGNAL_STRENGTH: |
| 1558 | tvp->u.st = c->strength; |
| 1559 | break; |
| 1560 | case DTV_STAT_CNR: |
| 1561 | tvp->u.st = c->cnr; |
| 1562 | break; |
| 1563 | case DTV_STAT_PRE_ERROR_BIT_COUNT: |
| 1564 | tvp->u.st = c->pre_bit_error; |
| 1565 | break; |
| 1566 | case DTV_STAT_PRE_TOTAL_BIT_COUNT: |
| 1567 | tvp->u.st = c->pre_bit_count; |
| 1568 | break; |
| 1569 | case DTV_STAT_POST_ERROR_BIT_COUNT: |
| 1570 | tvp->u.st = c->post_bit_error; |
| 1571 | break; |
| 1572 | case DTV_STAT_POST_TOTAL_BIT_COUNT: |
| 1573 | tvp->u.st = c->post_bit_count; |
| 1574 | break; |
| 1575 | case DTV_STAT_ERROR_BLOCK_COUNT: |
| 1576 | tvp->u.st = c->block_error; |
| 1577 | break; |
| 1578 | case DTV_STAT_TOTAL_BLOCK_COUNT: |
| 1579 | tvp->u.st = c->block_count; |
| 1580 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1581 | default: |
Mauro Carvalho Chehab | 94a93e5 | 2013-01-23 17:06:02 -0300 | [diff] [blame] | 1582 | dev_dbg(fe->dvb->device, |
| 1583 | "%s: FE property %d doesn't exist\n", |
| 1584 | __func__, tvp->cmd); |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1585 | return -EINVAL; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1586 | } |
| 1587 | |
Andreas Oberritter | e23d9ae | 2011-05-08 20:03:36 -0300 | [diff] [blame] | 1588 | /* Allow the frontend to override outgoing properties */ |
| 1589 | if (fe->ops.get_property) { |
| 1590 | r = fe->ops.get_property(fe, tvp); |
| 1591 | if (r < 0) |
| 1592 | return r; |
| 1593 | } |
| 1594 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1595 | dtv_property_dump(fe, tvp); |
Mauro Carvalho Chehab | 639544d | 2009-12-31 17:49:32 -0300 | [diff] [blame] | 1596 | |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1597 | return 0; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1598 | } |
| 1599 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1600 | static int dtv_set_frontend(struct dvb_frontend *fe); |
| 1601 | |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1602 | static bool is_dvbv3_delsys(u32 delsys) |
| 1603 | { |
| 1604 | bool status; |
| 1605 | |
| 1606 | status = (delsys == SYS_DVBT) || (delsys == SYS_DVBC_ANNEX_A) || |
| 1607 | (delsys == SYS_DVBS) || (delsys == SYS_ATSC); |
| 1608 | |
| 1609 | return status; |
| 1610 | } |
| 1611 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1612 | /** |
| 1613 | * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type |
| 1614 | * @fe: struct frontend; |
| 1615 | * @delsys: DVBv5 type that will be used for emulation |
| 1616 | * |
| 1617 | * Provides emulation for delivery systems that are compatible with the old |
| 1618 | * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows |
| 1619 | * using a DVB-S2 only frontend just like it were a DVB-S, if the frontent |
| 1620 | * parameters are compatible with DVB-S spec. |
| 1621 | */ |
| 1622 | static int emulate_delivery_system(struct dvb_frontend *fe, u32 delsys) |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1623 | { |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1624 | int i; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1625 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1626 | |
Mauro Carvalho Chehab | 3626479 | 2012-04-17 18:32:19 -0300 | [diff] [blame] | 1627 | c->delivery_system = delsys; |
| 1628 | |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1629 | /* |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1630 | * If the call is for ISDB-T, put it into full-seg, auto mode, TV |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1631 | */ |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1632 | if (c->delivery_system == SYS_ISDBT) { |
| 1633 | dev_dbg(fe->dvb->device, |
| 1634 | "%s: Using defaults for SYS_ISDBT\n", |
| 1635 | __func__); |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1636 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1637 | if (!c->bandwidth_hz) |
| 1638 | c->bandwidth_hz = 6000000; |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1639 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1640 | c->isdbt_partial_reception = 0; |
| 1641 | c->isdbt_sb_mode = 0; |
| 1642 | c->isdbt_sb_subchannel = 0; |
| 1643 | c->isdbt_sb_segment_idx = 0; |
| 1644 | c->isdbt_sb_segment_count = 0; |
| 1645 | c->isdbt_layer_enabled = 7; |
| 1646 | for (i = 0; i < 3; i++) { |
| 1647 | c->layer[i].fec = FEC_AUTO; |
| 1648 | c->layer[i].modulation = QAM_AUTO; |
| 1649 | c->layer[i].interleaving = 0; |
| 1650 | c->layer[i].segment_count = 0; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1651 | } |
| 1652 | } |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1653 | dev_dbg(fe->dvb->device, "%s: change delivery system on cache to %d\n", |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1654 | __func__, c->delivery_system); |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1655 | |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1656 | return 0; |
| 1657 | } |
| 1658 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1659 | /** |
| 1660 | * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call |
| 1661 | * @fe: frontend struct |
| 1662 | * @desired_system: delivery system requested by the user |
| 1663 | * |
| 1664 | * A DVBv5 call know what's the desired system it wants. So, set it. |
| 1665 | * |
| 1666 | * There are, however, a few known issues with early DVBv5 applications that |
| 1667 | * are also handled by this logic: |
| 1668 | * |
| 1669 | * 1) Some early apps use SYS_UNDEFINED as the desired delivery system. |
| 1670 | * This is an API violation, but, as we don't want to break userspace, |
| 1671 | * convert it to the first supported delivery system. |
| 1672 | * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for |
| 1673 | * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of |
| 1674 | * ISDB-T provided backward compat with DVB-T. |
| 1675 | */ |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1676 | static int dvbv5_set_delivery_system(struct dvb_frontend *fe, |
| 1677 | u32 desired_system) |
| 1678 | { |
| 1679 | int ncaps; |
| 1680 | u32 delsys = SYS_UNDEFINED; |
| 1681 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1682 | enum dvbv3_emulation_type type; |
| 1683 | |
| 1684 | /* |
| 1685 | * It was reported that some old DVBv5 applications were |
| 1686 | * filling delivery_system with SYS_UNDEFINED. If this happens, |
| 1687 | * assume that the application wants to use the first supported |
| 1688 | * delivery system. |
| 1689 | */ |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1690 | if (desired_system == SYS_UNDEFINED) |
| 1691 | desired_system = fe->ops.delsys[0]; |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1692 | |
| 1693 | /* |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1694 | * This is a DVBv5 call. So, it likely knows the supported |
| 1695 | * delivery systems. So, check if the desired delivery system is |
| 1696 | * supported |
| 1697 | */ |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1698 | ncaps = 0; |
Ole Ernst | 0123f29 | 2014-03-05 14:08:15 -0300 | [diff] [blame] | 1699 | while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) { |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1700 | if (fe->ops.delsys[ncaps] == desired_system) { |
| 1701 | c->delivery_system = desired_system; |
| 1702 | dev_dbg(fe->dvb->device, |
| 1703 | "%s: Changing delivery system to %d\n", |
| 1704 | __func__, desired_system); |
| 1705 | return 0; |
| 1706 | } |
| 1707 | ncaps++; |
| 1708 | } |
| 1709 | |
| 1710 | /* |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1711 | * The requested delivery system isn't supported. Maybe userspace |
| 1712 | * is requesting a DVBv3 compatible delivery system. |
| 1713 | * |
| 1714 | * The emulation only works if the desired system is one of the |
| 1715 | * delivery systems supported by DVBv3 API |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1716 | */ |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1717 | if (!is_dvbv3_delsys(desired_system)) { |
| 1718 | dev_dbg(fe->dvb->device, |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1719 | "%s: Delivery system %d not supported.\n", |
| 1720 | __func__, desired_system); |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1721 | return -EINVAL; |
| 1722 | } |
| 1723 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1724 | type = dvbv3_type(desired_system); |
| 1725 | |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1726 | /* |
| 1727 | * Get the last non-DVBv3 delivery system that has the same type |
| 1728 | * of the desired system |
| 1729 | */ |
| 1730 | ncaps = 0; |
Ole Ernst | 0123f29 | 2014-03-05 14:08:15 -0300 | [diff] [blame] | 1731 | while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) { |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1732 | if (dvbv3_type(fe->ops.delsys[ncaps]) == type) |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1733 | delsys = fe->ops.delsys[ncaps]; |
| 1734 | ncaps++; |
| 1735 | } |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1736 | |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1737 | /* There's nothing compatible with the desired delivery system */ |
| 1738 | if (delsys == SYS_UNDEFINED) { |
| 1739 | dev_dbg(fe->dvb->device, |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1740 | "%s: Delivery system %d not supported on emulation mode.\n", |
| 1741 | __func__, desired_system); |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1742 | return -EINVAL; |
| 1743 | } |
| 1744 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1745 | dev_dbg(fe->dvb->device, |
| 1746 | "%s: Using delivery system %d emulated as if it were %d\n", |
| 1747 | __func__, delsys, desired_system); |
| 1748 | |
| 1749 | return emulate_delivery_system(fe, desired_system); |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1750 | } |
| 1751 | |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1752 | /** |
| 1753 | * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call |
| 1754 | * @fe: frontend struct |
| 1755 | * |
| 1756 | * A DVBv3 call doesn't know what's the desired system it wants. It also |
| 1757 | * doesn't allow to switch between different types. Due to that, userspace |
| 1758 | * should use DVBv5 instead. |
| 1759 | * However, in order to avoid breaking userspace API, limited backward |
| 1760 | * compatibility support is provided. |
| 1761 | * |
| 1762 | * There are some delivery systems that are incompatible with DVBv3 calls. |
| 1763 | * |
| 1764 | * This routine should work fine for frontends that support just one delivery |
| 1765 | * system. |
| 1766 | * |
| 1767 | * For frontends that support multiple frontends: |
| 1768 | * 1) It defaults to use the first supported delivery system. There's an |
| 1769 | * userspace application that allows changing it at runtime; |
| 1770 | * |
| 1771 | * 2) If the current delivery system is not compatible with DVBv3, it gets |
| 1772 | * the first one that it is compatible. |
| 1773 | * |
| 1774 | * NOTE: in order for this to work with applications like Kaffeine that |
| 1775 | * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to |
| 1776 | * DVB-S, drivers that support both DVB-S and DVB-S2 should have the |
| 1777 | * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back |
| 1778 | * to DVB-S. |
| 1779 | */ |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1780 | static int dvbv3_set_delivery_system(struct dvb_frontend *fe) |
| 1781 | { |
| 1782 | int ncaps; |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1783 | u32 delsys = SYS_UNDEFINED; |
| 1784 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1785 | |
| 1786 | /* If not set yet, defaults to the first supported delivery system */ |
| 1787 | if (c->delivery_system == SYS_UNDEFINED) |
| 1788 | c->delivery_system = fe->ops.delsys[0]; |
| 1789 | |
| 1790 | /* |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1791 | * Trivial case: just use the current one, if it already a DVBv3 |
| 1792 | * delivery system |
| 1793 | */ |
| 1794 | if (is_dvbv3_delsys(c->delivery_system)) { |
| 1795 | dev_dbg(fe->dvb->device, |
| 1796 | "%s: Using delivery system to %d\n", |
| 1797 | __func__, c->delivery_system); |
| 1798 | return 0; |
| 1799 | } |
| 1800 | |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1801 | /* |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1802 | * Seek for the first delivery system that it is compatible with a |
| 1803 | * DVBv3 standard |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1804 | */ |
| 1805 | ncaps = 0; |
Ole Ernst | 0123f29 | 2014-03-05 14:08:15 -0300 | [diff] [blame] | 1806 | while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) { |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1807 | if (dvbv3_type(fe->ops.delsys[ncaps]) != DVBV3_UNKNOWN) { |
| 1808 | delsys = fe->ops.delsys[ncaps]; |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1809 | break; |
| 1810 | } |
| 1811 | ncaps++; |
| 1812 | } |
| 1813 | if (delsys == SYS_UNDEFINED) { |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1814 | dev_dbg(fe->dvb->device, |
| 1815 | "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n", |
| 1816 | __func__); |
| 1817 | return -EINVAL; |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1818 | } |
Mauro Carvalho Chehab | 52dee39 | 2013-03-18 15:25:37 -0300 | [diff] [blame] | 1819 | return emulate_delivery_system(fe, delsys); |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1820 | } |
| 1821 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1822 | static int dtv_property_process_set(struct dvb_frontend *fe, |
| 1823 | struct dtv_property *tvp, |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1824 | struct file *file) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1825 | { |
| 1826 | int r = 0; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1827 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1828 | |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1829 | /* Allow the frontend to validate incoming properties */ |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1830 | if (fe->ops.set_property) { |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1831 | r = fe->ops.set_property(fe, tvp); |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1832 | if (r < 0) |
| 1833 | return r; |
| 1834 | } |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1835 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1836 | switch(tvp->cmd) { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1837 | case DTV_CLEAR: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1838 | /* |
| 1839 | * Reset a cache of data specific to the frontend here. This does |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1840 | * not effect hardware. |
| 1841 | */ |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1842 | dvb_frontend_clear_cache(fe); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1843 | break; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1844 | case DTV_TUNE: |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1845 | /* interpret the cache of data, build either a traditional frontend |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1846 | * tunerequest so we can pass validation in the FE_SET_FRONTEND |
| 1847 | * ioctl. |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1848 | */ |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1849 | c->state = tvp->cmd; |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 1850 | dev_dbg(fe->dvb->device, "%s: Finalised property cache\n", |
| 1851 | __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1852 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1853 | r = dtv_set_frontend(fe); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1854 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1855 | case DTV_FREQUENCY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1856 | c->frequency = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1857 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1858 | case DTV_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1859 | c->modulation = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1860 | break; |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1861 | case DTV_BANDWIDTH_HZ: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1862 | c->bandwidth_hz = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1863 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1864 | case DTV_INVERSION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1865 | c->inversion = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1866 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1867 | case DTV_SYMBOL_RATE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1868 | c->symbol_rate = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1869 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1870 | case DTV_INNER_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1871 | c->fec_inner = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1872 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1873 | case DTV_PILOT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1874 | c->pilot = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1875 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1876 | case DTV_ROLLOFF: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1877 | c->rolloff = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1878 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1879 | case DTV_DELIVERY_SYSTEM: |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 1880 | r = dvbv5_set_delivery_system(fe, tvp->u.data); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1881 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1882 | case DTV_VOLTAGE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1883 | c->voltage = tvp->u.data; |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1884 | r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE, |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1885 | (void *)c->voltage); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1886 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1887 | case DTV_TONE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1888 | c->sectone = tvp->u.data; |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1889 | r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE, |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1890 | (void *)c->sectone); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1891 | break; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1892 | case DTV_CODE_RATE_HP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1893 | c->code_rate_HP = tvp->u.data; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1894 | break; |
| 1895 | case DTV_CODE_RATE_LP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1896 | c->code_rate_LP = tvp->u.data; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1897 | break; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1898 | case DTV_GUARD_INTERVAL: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1899 | c->guard_interval = tvp->u.data; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1900 | break; |
| 1901 | case DTV_TRANSMISSION_MODE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1902 | c->transmission_mode = tvp->u.data; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1903 | break; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1904 | case DTV_HIERARCHY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1905 | c->hierarchy = tvp->u.data; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1906 | break; |
Antti Palosaari | 224b664 | 2012-08-12 22:33:21 -0300 | [diff] [blame] | 1907 | case DTV_INTERLEAVING: |
| 1908 | c->interleaving = tvp->u.data; |
| 1909 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1910 | |
| 1911 | /* ISDB-T Support here */ |
| 1912 | case DTV_ISDBT_PARTIAL_RECEPTION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1913 | c->isdbt_partial_reception = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1914 | break; |
| 1915 | case DTV_ISDBT_SOUND_BROADCASTING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1916 | c->isdbt_sb_mode = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1917 | break; |
| 1918 | case DTV_ISDBT_SB_SUBCHANNEL_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1919 | c->isdbt_sb_subchannel = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1920 | break; |
| 1921 | case DTV_ISDBT_SB_SEGMENT_IDX: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1922 | c->isdbt_sb_segment_idx = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1923 | break; |
| 1924 | case DTV_ISDBT_SB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1925 | c->isdbt_sb_segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1926 | break; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1927 | case DTV_ISDBT_LAYER_ENABLED: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1928 | c->isdbt_layer_enabled = tvp->u.data; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1929 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1930 | case DTV_ISDBT_LAYERA_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1931 | c->layer[0].fec = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1932 | break; |
| 1933 | case DTV_ISDBT_LAYERA_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1934 | c->layer[0].modulation = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1935 | break; |
| 1936 | case DTV_ISDBT_LAYERA_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1937 | c->layer[0].segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1938 | break; |
| 1939 | case DTV_ISDBT_LAYERA_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1940 | c->layer[0].interleaving = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1941 | break; |
| 1942 | case DTV_ISDBT_LAYERB_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1943 | c->layer[1].fec = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1944 | break; |
| 1945 | case DTV_ISDBT_LAYERB_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1946 | c->layer[1].modulation = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1947 | break; |
| 1948 | case DTV_ISDBT_LAYERB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1949 | c->layer[1].segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1950 | break; |
| 1951 | case DTV_ISDBT_LAYERB_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1952 | c->layer[1].interleaving = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1953 | break; |
| 1954 | case DTV_ISDBT_LAYERC_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1955 | c->layer[2].fec = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1956 | break; |
| 1957 | case DTV_ISDBT_LAYERC_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1958 | c->layer[2].modulation = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1959 | break; |
| 1960 | case DTV_ISDBT_LAYERC_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1961 | c->layer[2].segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1962 | break; |
| 1963 | case DTV_ISDBT_LAYERC_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1964 | c->layer[2].interleaving = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1965 | break; |
Evgeny Plehov | 287cefd | 2012-09-13 10:13:30 -0300 | [diff] [blame] | 1966 | |
| 1967 | /* Multistream support */ |
| 1968 | case DTV_STREAM_ID: |
| 1969 | case DTV_DVBT2_PLP_ID_LEGACY: |
| 1970 | c->stream_id = tvp->u.data; |
Andreas Oberritter | 94d56ff | 2011-05-12 18:11:06 -0300 | [diff] [blame] | 1971 | break; |
Michael Krufky | ca68948 | 2012-01-29 15:44:58 -0300 | [diff] [blame] | 1972 | |
| 1973 | /* ATSC-MH */ |
| 1974 | case DTV_ATSCMH_PARADE_ID: |
| 1975 | fe->dtv_property_cache.atscmh_parade_id = tvp->u.data; |
| 1976 | break; |
| 1977 | case DTV_ATSCMH_RS_FRAME_ENSEMBLE: |
| 1978 | fe->dtv_property_cache.atscmh_rs_frame_ensemble = tvp->u.data; |
| 1979 | break; |
| 1980 | |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 1981 | case DTV_LNA: |
| 1982 | c->lna = tvp->u.data; |
| 1983 | if (fe->ops.set_lna) |
| 1984 | r = fe->ops.set_lna(fe); |
Mauro Carvalho Chehab | e687669 | 2014-02-16 06:36:17 -0300 | [diff] [blame] | 1985 | if (r < 0) |
| 1986 | c->lna = LNA_AUTO; |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 1987 | break; |
| 1988 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1989 | default: |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1990 | return -EINVAL; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1991 | } |
| 1992 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1993 | return r; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1994 | } |
| 1995 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1996 | static int dvb_frontend_ioctl(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | unsigned int cmd, void *parg) |
| 1998 | { |
| 1999 | struct dvb_device *dvbdev = file->private_data; |
| 2000 | struct dvb_frontend *fe = dvbdev->priv; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 2001 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2002 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | ac89758 | 2013-02-15 13:39:31 -0200 | [diff] [blame] | 2003 | int err = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2005 | dev_dbg(fe->dvb->device, "%s: (%d)\n", __func__, _IOC_NR(cmd)); |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 2006 | if (down_interruptible(&fepriv->sem)) |
| 2007 | return -ERESTARTSYS; |
| 2008 | |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 2009 | if (fe->exit != DVB_FE_NO_EXIT) { |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 2010 | up(&fepriv->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | return -ENODEV; |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 2012 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
| 2014 | if ((file->f_flags & O_ACCMODE) == O_RDONLY && |
| 2015 | (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT || |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 2016 | cmd == FE_DISEQC_RECV_SLAVE_REPLY)) { |
| 2017 | up(&fepriv->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | return -EPERM; |
Juergen Lock | 6ae2322 | 2012-12-23 17:23:06 -0300 | [diff] [blame] | 2019 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2021 | if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY)) |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 2022 | err = dvb_frontend_ioctl_properties(file, cmd, parg); |
Steven Toth | 4dd88be | 2008-09-13 15:09:07 -0300 | [diff] [blame] | 2023 | else { |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 2024 | c->state = DTV_UNDEFINED; |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 2025 | err = dvb_frontend_ioctl_legacy(file, cmd, parg); |
Steven Toth | 4dd88be | 2008-09-13 15:09:07 -0300 | [diff] [blame] | 2026 | } |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2027 | |
| 2028 | up(&fepriv->sem); |
| 2029 | return err; |
| 2030 | } |
| 2031 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 2032 | static int dvb_frontend_ioctl_properties(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2033 | unsigned int cmd, void *parg) |
| 2034 | { |
| 2035 | struct dvb_device *dvbdev = file->private_data; |
| 2036 | struct dvb_frontend *fe = dvbdev->priv; |
Mauro Carvalho Chehab | 51dcb19 | 2012-01-17 16:20:37 -0200 | [diff] [blame] | 2037 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 2038 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Igor M. Liplianin | e6f9ec8 | 2008-09-12 14:49:06 -0300 | [diff] [blame] | 2039 | int err = 0; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2040 | |
Mauro Carvalho Chehab | 71d1b2b | 2014-09-24 10:15:22 -0300 | [diff] [blame] | 2041 | struct dtv_properties *tvps = parg; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2042 | struct dtv_property *tvp = NULL; |
| 2043 | int i; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2044 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2045 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2046 | |
Mauro Carvalho Chehab | 71d1b2b | 2014-09-24 10:15:22 -0300 | [diff] [blame] | 2047 | if (cmd == FE_SET_PROPERTY) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2048 | dev_dbg(fe->dvb->device, "%s: properties.num = %d\n", __func__, tvps->num); |
| 2049 | dev_dbg(fe->dvb->device, "%s: properties.props = %p\n", __func__, tvps->props); |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2050 | |
| 2051 | /* Put an arbitrary limit on the number of messages that can |
| 2052 | * be sent at once */ |
Steven Toth | 6068f50 | 2008-10-06 22:46:08 -0300 | [diff] [blame] | 2053 | if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2054 | return -EINVAL; |
| 2055 | |
Thiago Farina | 6e3924a | 2010-01-16 10:25:38 -0300 | [diff] [blame] | 2056 | tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL); |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2057 | if (!tvp) { |
| 2058 | err = -ENOMEM; |
| 2059 | goto out; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 2060 | } |
| 2061 | |
Mauro Carvalho Chehab | 71d1b2b | 2014-09-24 10:15:22 -0300 | [diff] [blame] | 2062 | if (copy_from_user(tvp, (void __user *)tvps->props, |
| 2063 | tvps->num * sizeof(struct dtv_property))) { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2064 | err = -EFAULT; |
| 2065 | goto out; |
| 2066 | } |
| 2067 | |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 2068 | for (i = 0; i < tvps->num; i++) { |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 2069 | err = dtv_property_process_set(fe, tvp + i, file); |
| 2070 | if (err < 0) |
| 2071 | goto out; |
| 2072 | (tvp + i)->result = err; |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 2073 | } |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2074 | |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 2075 | if (c->state == DTV_TUNE) |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2076 | dev_dbg(fe->dvb->device, "%s: Property cache is full, tuning\n", __func__); |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 2077 | |
Mauro Carvalho Chehab | 71d1b2b | 2014-09-24 10:15:22 -0300 | [diff] [blame] | 2078 | } else if (cmd == FE_GET_PROPERTY) { |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2079 | dev_dbg(fe->dvb->device, "%s: properties.num = %d\n", __func__, tvps->num); |
| 2080 | dev_dbg(fe->dvb->device, "%s: properties.props = %p\n", __func__, tvps->props); |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2081 | |
| 2082 | /* Put an arbitrary limit on the number of messages that can |
| 2083 | * be sent at once */ |
Steven Toth | 6068f50 | 2008-10-06 22:46:08 -0300 | [diff] [blame] | 2084 | if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2085 | return -EINVAL; |
| 2086 | |
Thiago Farina | 6e3924a | 2010-01-16 10:25:38 -0300 | [diff] [blame] | 2087 | tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL); |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2088 | if (!tvp) { |
| 2089 | err = -ENOMEM; |
| 2090 | goto out; |
| 2091 | } |
| 2092 | |
Mauro Carvalho Chehab | 71d1b2b | 2014-09-24 10:15:22 -0300 | [diff] [blame] | 2093 | if (copy_from_user(tvp, (void __user *)tvps->props, |
| 2094 | tvps->num * sizeof(struct dtv_property))) { |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2095 | err = -EFAULT; |
| 2096 | goto out; |
| 2097 | } |
| 2098 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 2099 | /* |
| 2100 | * Fills the cache out struct with the cache contents, plus |
Mauro Carvalho Chehab | 51dcb19 | 2012-01-17 16:20:37 -0200 | [diff] [blame] | 2101 | * the data retrieved from get_frontend, if the frontend |
| 2102 | * is not idle. Otherwise, returns the cached content |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 2103 | */ |
Mauro Carvalho Chehab | 51dcb19 | 2012-01-17 16:20:37 -0200 | [diff] [blame] | 2104 | if (fepriv->state != FESTATE_IDLE) { |
| 2105 | err = dtv_get_frontend(fe, NULL); |
| 2106 | if (err < 0) |
| 2107 | goto out; |
| 2108 | } |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 2109 | for (i = 0; i < tvps->num; i++) { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 2110 | err = dtv_property_process_get(fe, c, tvp + i, file); |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 2111 | if (err < 0) |
| 2112 | goto out; |
| 2113 | (tvp + i)->result = err; |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 2114 | } |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2115 | |
Mauro Carvalho Chehab | 71d1b2b | 2014-09-24 10:15:22 -0300 | [diff] [blame] | 2116 | if (copy_to_user((void __user *)tvps->props, tvp, |
| 2117 | tvps->num * sizeof(struct dtv_property))) { |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2118 | err = -EFAULT; |
| 2119 | goto out; |
| 2120 | } |
| 2121 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2122 | } else |
Mauro Carvalho Chehab | ac89758 | 2013-02-15 13:39:31 -0200 | [diff] [blame] | 2123 | err = -EOPNOTSUPP; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 2124 | |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 2125 | out: |
| 2126 | kfree(tvp); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2127 | return err; |
| 2128 | } |
| 2129 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2130 | static int dtv_set_frontend(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2131 | { |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2132 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 2133 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 2134 | struct dvb_frontend_tune_settings fetunesettings; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2135 | u32 rolloff = 0; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2136 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2137 | if (dvb_frontend_check_parameters(fe) < 0) |
| 2138 | return -EINVAL; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2139 | |
| 2140 | /* |
Chris Rankin | 556a044 | 2012-04-06 18:38:18 -0300 | [diff] [blame] | 2141 | * Initialize output parameters to match the values given by |
| 2142 | * the user. FE_SET_FRONTEND triggers an initial frontend event |
| 2143 | * with status = 0, which copies output parameters to userspace. |
| 2144 | */ |
| 2145 | dtv_property_legacy_params_sync(fe, &fepriv->parameters_out); |
| 2146 | |
| 2147 | /* |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2148 | * Be sure that the bandwidth will be filled for all |
| 2149 | * non-satellite systems, as tuners need to know what |
| 2150 | * low pass/Nyquist half filter should be applied, in |
| 2151 | * order to avoid inter-channel noise. |
| 2152 | * |
| 2153 | * ISDB-T and DVB-T/T2 already sets bandwidth. |
| 2154 | * ATSC and DVB-C don't set, so, the core should fill it. |
| 2155 | * |
| 2156 | * On DVB-C Annex A and C, the bandwidth is a function of |
| 2157 | * the roll-off and symbol rate. Annex B defines different |
| 2158 | * roll-off factors depending on the modulation. Fortunately, |
| 2159 | * Annex B is only used with 6MHz, so there's no need to |
| 2160 | * calculate it. |
| 2161 | * |
| 2162 | * While not officially supported, a side effect of handling it at |
| 2163 | * the cache level is that a program could retrieve the bandwidth |
| 2164 | * via DTV_BANDWIDTH_HZ, which may be useful for test programs. |
| 2165 | */ |
| 2166 | switch (c->delivery_system) { |
| 2167 | case SYS_ATSC: |
| 2168 | case SYS_DVBC_ANNEX_B: |
| 2169 | c->bandwidth_hz = 6000000; |
| 2170 | break; |
| 2171 | case SYS_DVBC_ANNEX_A: |
| 2172 | rolloff = 115; |
| 2173 | break; |
| 2174 | case SYS_DVBC_ANNEX_C: |
| 2175 | rolloff = 113; |
| 2176 | break; |
Mauro Carvalho Chehab | c623ed6 | 2014-08-22 10:30:17 -0500 | [diff] [blame] | 2177 | case SYS_DVBS: |
| 2178 | case SYS_TURBO: |
Akihiro Tsukada | 8e281fa | 2014-10-31 10:19:39 -0300 | [diff] [blame] | 2179 | case SYS_ISDBS: |
Mauro Carvalho Chehab | c623ed6 | 2014-08-22 10:30:17 -0500 | [diff] [blame] | 2180 | rolloff = 135; |
| 2181 | break; |
| 2182 | case SYS_DVBS2: |
| 2183 | switch (c->rolloff) { |
| 2184 | case ROLLOFF_20: |
| 2185 | rolloff = 120; |
| 2186 | break; |
| 2187 | case ROLLOFF_25: |
| 2188 | rolloff = 125; |
| 2189 | break; |
| 2190 | default: |
| 2191 | case ROLLOFF_35: |
| 2192 | rolloff = 135; |
| 2193 | } |
| 2194 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2195 | default: |
| 2196 | break; |
| 2197 | } |
| 2198 | if (rolloff) |
Antti Palosaari | 2a80f29 | 2015-04-14 15:12:54 -0300 | [diff] [blame] | 2199 | c->bandwidth_hz = mult_frac(c->symbol_rate, rolloff, 100); |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2200 | |
| 2201 | /* force auto frequency inversion if requested */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2202 | if (dvb_force_auto_inversion) |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2203 | c->inversion = INVERSION_AUTO; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2204 | |
| 2205 | /* |
| 2206 | * without hierarchical coding code_rate_LP is irrelevant, |
| 2207 | * so we tolerate the otherwise invalid FEC_NONE setting |
| 2208 | */ |
| 2209 | if (c->hierarchy == HIERARCHY_NONE && c->code_rate_LP == FEC_NONE) |
| 2210 | c->code_rate_LP = FEC_AUTO; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2211 | |
| 2212 | /* get frontend-specific tuning settings */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2213 | memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings)); |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2214 | if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) { |
| 2215 | fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000; |
| 2216 | fepriv->max_drift = fetunesettings.max_drift; |
| 2217 | fepriv->step_size = fetunesettings.step_size; |
| 2218 | } else { |
| 2219 | /* default values */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2220 | switch (c->delivery_system) { |
Mauro Carvalho Chehab | 910a5f2 | 2012-05-07 15:01:37 -0300 | [diff] [blame] | 2221 | case SYS_DVBS: |
| 2222 | case SYS_DVBS2: |
| 2223 | case SYS_ISDBS: |
| 2224 | case SYS_TURBO: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2225 | case SYS_DVBC_ANNEX_A: |
| 2226 | case SYS_DVBC_ANNEX_C: |
| 2227 | fepriv->min_delay = HZ / 20; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2228 | fepriv->step_size = c->symbol_rate / 16000; |
| 2229 | fepriv->max_drift = c->symbol_rate / 2000; |
| 2230 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2231 | case SYS_DVBT: |
| 2232 | case SYS_DVBT2: |
| 2233 | case SYS_ISDBT: |
Antti Palosaari | 224b664 | 2012-08-12 22:33:21 -0300 | [diff] [blame] | 2234 | case SYS_DTMB: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2235 | fepriv->min_delay = HZ / 20; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2236 | fepriv->step_size = fe->ops.info.frequency_stepsize * 2; |
| 2237 | fepriv->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1; |
| 2238 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2239 | default: |
| 2240 | /* |
| 2241 | * FIXME: This sounds wrong! if freqency_stepsize is |
| 2242 | * defined by the frontend, why not use it??? |
| 2243 | */ |
| 2244 | fepriv->min_delay = HZ / 20; |
| 2245 | fepriv->step_size = 0; /* no zigzag */ |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2246 | fepriv->max_drift = 0; |
| 2247 | break; |
| 2248 | } |
| 2249 | } |
| 2250 | if (dvb_override_tune_delay > 0) |
| 2251 | fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000; |
| 2252 | |
| 2253 | fepriv->state = FESTATE_RETUNE; |
| 2254 | |
| 2255 | /* Request the search algorithm to search */ |
| 2256 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 2257 | |
| 2258 | dvb_frontend_clear_events(fe); |
| 2259 | dvb_frontend_add_event(fe, 0); |
| 2260 | dvb_frontend_wakeup(fe); |
| 2261 | fepriv->status = 0; |
| 2262 | |
| 2263 | return 0; |
| 2264 | } |
| 2265 | |
| 2266 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 2267 | static int dvb_frontend_ioctl_legacy(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2268 | unsigned int cmd, void *parg) |
| 2269 | { |
| 2270 | struct dvb_device *dvbdev = file->private_data; |
| 2271 | struct dvb_frontend *fe = dvbdev->priv; |
| 2272 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2273 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | ac89758 | 2013-02-15 13:39:31 -0200 | [diff] [blame] | 2274 | int err = -EOPNOTSUPP; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 2275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | switch (cmd) { |
| 2277 | case FE_GET_INFO: { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2278 | struct dvb_frontend_info* info = parg; |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 2279 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2280 | memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info)); |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 2281 | dvb_frontend_get_frequency_limits(fe, &info->frequency_min, &info->frequency_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2283 | /* |
| 2284 | * Associate the 4 delivery systems supported by DVBv3 |
| 2285 | * API with their DVBv5 counterpart. For the other standards, |
| 2286 | * use the closest type, assuming that it would hopefully |
| 2287 | * work with a DVBv3 application. |
| 2288 | * It should be noticed that, on multi-frontend devices with |
| 2289 | * different types (terrestrial and cable, for example), |
| 2290 | * a pure DVBv3 application won't be able to use all delivery |
| 2291 | * systems. Yet, changing the DVBv5 cache to the other delivery |
| 2292 | * system should be enough for making it work. |
| 2293 | */ |
| 2294 | switch (dvbv3_type(c->delivery_system)) { |
| 2295 | case DVBV3_QPSK: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 2296 | info->type = FE_QPSK; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2297 | break; |
| 2298 | case DVBV3_ATSC: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 2299 | info->type = FE_ATSC; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2300 | break; |
| 2301 | case DVBV3_QAM: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 2302 | info->type = FE_QAM; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2303 | break; |
| 2304 | case DVBV3_OFDM: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 2305 | info->type = FE_OFDM; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2306 | break; |
| 2307 | default: |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2308 | dev_err(fe->dvb->device, |
| 2309 | "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n", |
| 2310 | __func__, c->delivery_system); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2311 | fe->ops.info.type = FE_OFDM; |
| 2312 | } |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2313 | dev_dbg(fe->dvb->device, "%s: current delivery system on cache: %d, V3 type: %d\n", |
| 2314 | __func__, c->delivery_system, fe->ops.info.type); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2315 | |
Malcolm Priestley | c9d57de | 2015-08-31 06:13:45 -0300 | [diff] [blame] | 2316 | /* Set CAN_INVERSION_AUTO bit on in other than oneshot mode */ |
| 2317 | if (!(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) |
| 2318 | info->caps |= FE_CAN_INVERSION_AUTO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | err = 0; |
| 2320 | break; |
| 2321 | } |
| 2322 | |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2323 | case FE_READ_STATUS: { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 2324 | enum fe_status *status = parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2326 | /* if retune was requested but hasn't occurred yet, prevent |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2327 | * that user get signal state from previous tuning */ |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 2328 | if (fepriv->state == FESTATE_RETUNE || |
| 2329 | fepriv->state == FESTATE_ERROR) { |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2330 | err=0; |
| 2331 | *status = 0; |
| 2332 | break; |
| 2333 | } |
| 2334 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2335 | if (fe->ops.read_status) |
| 2336 | err = fe->ops.read_status(fe, status); |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2337 | break; |
| 2338 | } |
Antti Palosaari | 48caa6f | 2012-08-09 19:00:51 -0300 | [diff] [blame] | 2339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | case FE_READ_BER: |
Antti Palosaari | 48caa6f | 2012-08-09 19:00:51 -0300 | [diff] [blame] | 2341 | if (fe->ops.read_ber) { |
| 2342 | if (fepriv->thread) |
| 2343 | err = fe->ops.read_ber(fe, (__u32 *) parg); |
| 2344 | else |
| 2345 | err = -EAGAIN; |
| 2346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | break; |
| 2348 | |
| 2349 | case FE_READ_SIGNAL_STRENGTH: |
Antti Palosaari | 48caa6f | 2012-08-09 19:00:51 -0300 | [diff] [blame] | 2350 | if (fe->ops.read_signal_strength) { |
| 2351 | if (fepriv->thread) |
| 2352 | err = fe->ops.read_signal_strength(fe, (__u16 *) parg); |
| 2353 | else |
| 2354 | err = -EAGAIN; |
| 2355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | break; |
| 2357 | |
| 2358 | case FE_READ_SNR: |
Antti Palosaari | 48caa6f | 2012-08-09 19:00:51 -0300 | [diff] [blame] | 2359 | if (fe->ops.read_snr) { |
| 2360 | if (fepriv->thread) |
| 2361 | err = fe->ops.read_snr(fe, (__u16 *) parg); |
| 2362 | else |
| 2363 | err = -EAGAIN; |
| 2364 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | break; |
| 2366 | |
| 2367 | case FE_READ_UNCORRECTED_BLOCKS: |
Antti Palosaari | 48caa6f | 2012-08-09 19:00:51 -0300 | [diff] [blame] | 2368 | if (fe->ops.read_ucblocks) { |
| 2369 | if (fepriv->thread) |
| 2370 | err = fe->ops.read_ucblocks(fe, (__u32 *) parg); |
| 2371 | else |
| 2372 | err = -EAGAIN; |
| 2373 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | break; |
| 2375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | case FE_DISEQC_RESET_OVERLOAD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2377 | if (fe->ops.diseqc_reset_overload) { |
| 2378 | err = fe->ops.diseqc_reset_overload(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | fepriv->state = FESTATE_DISEQC; |
| 2380 | fepriv->status = 0; |
| 2381 | } |
| 2382 | break; |
| 2383 | |
| 2384 | case FE_DISEQC_SEND_MASTER_CMD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2385 | if (fe->ops.diseqc_send_master_cmd) { |
Dan Carpenter | 8d7e506 | 2015-06-06 13:55:22 -0300 | [diff] [blame] | 2386 | struct dvb_diseqc_master_cmd *cmd = parg; |
| 2387 | |
| 2388 | if (cmd->msg_len > sizeof(cmd->msg)) { |
| 2389 | err = -EINVAL; |
| 2390 | break; |
| 2391 | } |
| 2392 | err = fe->ops.diseqc_send_master_cmd(fe, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | fepriv->state = FESTATE_DISEQC; |
| 2394 | fepriv->status = 0; |
| 2395 | } |
| 2396 | break; |
| 2397 | |
| 2398 | case FE_DISEQC_SEND_BURST: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2399 | if (fe->ops.diseqc_send_burst) { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 2400 | err = fe->ops.diseqc_send_burst(fe, |
| 2401 | (enum fe_sec_mini_cmd)parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | fepriv->state = FESTATE_DISEQC; |
| 2403 | fepriv->status = 0; |
| 2404 | } |
| 2405 | break; |
| 2406 | |
| 2407 | case FE_SET_TONE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2408 | if (fe->ops.set_tone) { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 2409 | err = fe->ops.set_tone(fe, |
| 2410 | (enum fe_sec_tone_mode)parg); |
| 2411 | fepriv->tone = (enum fe_sec_tone_mode)parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | fepriv->state = FESTATE_DISEQC; |
| 2413 | fepriv->status = 0; |
| 2414 | } |
| 2415 | break; |
| 2416 | |
| 2417 | case FE_SET_VOLTAGE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2418 | if (fe->ops.set_voltage) { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 2419 | err = fe->ops.set_voltage(fe, |
| 2420 | (enum fe_sec_voltage)parg); |
| 2421 | fepriv->voltage = (enum fe_sec_voltage)parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | fepriv->state = FESTATE_DISEQC; |
| 2423 | fepriv->status = 0; |
| 2424 | } |
| 2425 | break; |
| 2426 | |
| 2427 | case FE_DISHNETWORK_SEND_LEGACY_CMD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2428 | if (fe->ops.dishnetwork_send_legacy_command) { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 2429 | err = fe->ops.dishnetwork_send_legacy_command(fe, |
| 2430 | (unsigned long)parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | fepriv->state = FESTATE_DISEQC; |
| 2432 | fepriv->status = 0; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2433 | } else if (fe->ops.set_voltage) { |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2434 | /* |
| 2435 | * NOTE: This is a fallback condition. Some frontends |
| 2436 | * (stv0299 for instance) take longer than 8msec to |
| 2437 | * respond to a set_voltage command. Those switches |
| 2438 | * need custom routines to switch properly. For all |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 2439 | * other frontends, the following should work ok. |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2440 | * Dish network legacy switches (as used by Dish500) |
| 2441 | * are controlled by sending 9-bit command words |
| 2442 | * spaced 8msec apart. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2443 | * the actual command word is switch/port dependent |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2444 | * so it is up to the userspace application to send |
| 2445 | * the right command. |
| 2446 | * The command must always start with a '0' after |
| 2447 | * initialization, so parg is 8 bits and does not |
| 2448 | * include the initialization or start bit |
| 2449 | */ |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2450 | unsigned long swcmd = ((unsigned long) parg) << 1; |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 2451 | ktime_t nexttime; |
| 2452 | ktime_t tv[10]; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2453 | int i; |
| 2454 | u8 last = 1; |
| 2455 | if (dvb_frontend_debug) |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2456 | printk("%s switch command: 0x%04lx\n", __func__, swcmd); |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 2457 | nexttime = ktime_get_real(); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2458 | if (dvb_frontend_debug) |
Ezequiel Garcia | b9b1b3a | 2012-10-23 15:57:23 -0300 | [diff] [blame] | 2459 | tv[0] = nexttime; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2460 | /* before sending a command, initialize by sending |
| 2461 | * a 32ms 18V to the switch |
| 2462 | */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2463 | fe->ops.set_voltage(fe, SEC_VOLTAGE_18); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2464 | dvb_frontend_sleep_until(&nexttime, 32000); |
| 2465 | |
| 2466 | for (i = 0; i < 9; i++) { |
| 2467 | if (dvb_frontend_debug) |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 2468 | tv[i+1] = ktime_get_real(); |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2469 | if ((swcmd & 0x01) != last) { |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2470 | /* set voltage to (last ? 13V : 18V) */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2471 | fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2472 | last = (last) ? 0 : 1; |
| 2473 | } |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2474 | swcmd = swcmd >> 1; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2475 | if (i != 8) |
| 2476 | dvb_frontend_sleep_until(&nexttime, 8000); |
| 2477 | } |
| 2478 | if (dvb_frontend_debug) { |
| 2479 | printk("%s(%d): switch delay (should be 32k followed by all 8k\n", |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 2480 | __func__, fe->dvb->num); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2481 | for (i = 1; i < 10; i++) |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 2482 | printk("%d: %d\n", i, |
| 2483 | (int) ktime_us_delta(tv[i], tv[i-1])); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2484 | } |
| 2485 | err = 0; |
| 2486 | fepriv->state = FESTATE_DISEQC; |
| 2487 | fepriv->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | } |
| 2489 | break; |
| 2490 | |
| 2491 | case FE_DISEQC_RECV_SLAVE_REPLY: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2492 | if (fe->ops.diseqc_recv_slave_reply) |
| 2493 | err = fe->ops.diseqc_recv_slave_reply(fe, (struct dvb_diseqc_slave_reply*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | break; |
| 2495 | |
| 2496 | case FE_ENABLE_HIGH_LNB_VOLTAGE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2497 | if (fe->ops.enable_high_lnb_voltage) |
| 2498 | err = fe->ops.enable_high_lnb_voltage(fe, (long) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | break; |
| 2500 | |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2501 | case FE_SET_FRONTEND: |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 2502 | err = dvbv3_set_delivery_system(fe); |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 2503 | if (err) |
| 2504 | break; |
| 2505 | |
Mauro Carvalho Chehab | e399ce7 | 2012-01-01 16:11:16 -0300 | [diff] [blame] | 2506 | err = dtv_property_cache_sync(fe, c, parg); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2507 | if (err) |
| 2508 | break; |
| 2509 | err = dtv_set_frontend(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | case FE_GET_EVENT: |
| 2512 | err = dvb_frontend_get_event (fe, parg, file->f_flags); |
| 2513 | break; |
| 2514 | |
| 2515 | case FE_GET_FRONTEND: |
Mauro Carvalho Chehab | e399ce7 | 2012-01-01 16:11:16 -0300 | [diff] [blame] | 2516 | err = dtv_get_frontend(fe, parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | break; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 2518 | |
| 2519 | case FE_SET_FRONTEND_TUNE_MODE: |
Hans Verkuil | e18828e | 2006-01-09 15:25:28 -0200 | [diff] [blame] | 2520 | fepriv->tune_mode_flags = (unsigned long) parg; |
Trent Piepho | 1b172e0 | 2006-06-29 13:16:04 -0300 | [diff] [blame] | 2521 | err = 0; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 2522 | break; |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 2523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | return err; |
| 2526 | } |
| 2527 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 2528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait) |
| 2530 | { |
| 2531 | struct dvb_device *dvbdev = file->private_data; |
| 2532 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2533 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2535 | dev_dbg_ratelimited(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | |
| 2537 | poll_wait (file, &fepriv->events.wait_queue, wait); |
| 2538 | |
| 2539 | if (fepriv->events.eventw != fepriv->events.eventr) |
| 2540 | return (POLLIN | POLLRDNORM | POLLPRI); |
| 2541 | |
| 2542 | return 0; |
| 2543 | } |
| 2544 | |
| 2545 | static int dvb_frontend_open(struct inode *inode, struct file *file) |
| 2546 | { |
| 2547 | struct dvb_device *dvbdev = file->private_data; |
| 2548 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2549 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2550 | struct dvb_adapter *adapter = fe->dvb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | int ret; |
| 2552 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2553 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 2554 | if (fe->exit == DVB_FE_DEVICE_REMOVED) |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 2555 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2557 | if (adapter->mfe_shared) { |
| 2558 | mutex_lock (&adapter->mfe_lock); |
Darron Broad | 6594690 | 2008-10-15 13:37:59 -0300 | [diff] [blame] | 2559 | |
| 2560 | if (adapter->mfe_dvbdev == NULL) |
| 2561 | adapter->mfe_dvbdev = dvbdev; |
| 2562 | |
| 2563 | else if (adapter->mfe_dvbdev != dvbdev) { |
| 2564 | struct dvb_device |
| 2565 | *mfedev = adapter->mfe_dvbdev; |
| 2566 | struct dvb_frontend |
| 2567 | *mfe = mfedev->priv; |
| 2568 | struct dvb_frontend_private |
| 2569 | *mfepriv = mfe->frontend_priv; |
| 2570 | int mferetry = (dvb_mfe_wait_time << 1); |
| 2571 | |
| 2572 | mutex_unlock (&adapter->mfe_lock); |
| 2573 | while (mferetry-- && (mfedev->users != -1 || |
| 2574 | mfepriv->thread != NULL)) { |
| 2575 | if(msleep_interruptible(500)) { |
| 2576 | if(signal_pending(current)) |
| 2577 | return -EINTR; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2578 | } |
| 2579 | } |
Darron Broad | 6594690 | 2008-10-15 13:37:59 -0300 | [diff] [blame] | 2580 | |
| 2581 | mutex_lock (&adapter->mfe_lock); |
| 2582 | if(adapter->mfe_dvbdev != dvbdev) { |
| 2583 | mfedev = adapter->mfe_dvbdev; |
| 2584 | mfe = mfedev->priv; |
| 2585 | mfepriv = mfe->frontend_priv; |
| 2586 | if (mfedev->users != -1 || |
| 2587 | mfepriv->thread != NULL) { |
| 2588 | mutex_unlock (&adapter->mfe_lock); |
| 2589 | return -EBUSY; |
| 2590 | } |
| 2591 | adapter->mfe_dvbdev = dvbdev; |
| 2592 | } |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2596 | if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { |
| 2597 | if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2598 | goto err0; |
Devin Heitmueller | 2d19693 | 2011-07-04 21:55:01 -0300 | [diff] [blame] | 2599 | |
| 2600 | /* If we took control of the bus, we need to force |
| 2601 | reinitialization. This is because many ts_bus_ctrl() |
| 2602 | functions strobe the RESET pin on the demod, and if the |
| 2603 | frontend thread already exists then the dvb_init() routine |
| 2604 | won't get called (which is what usually does initial |
| 2605 | register configuration). */ |
| 2606 | fepriv->reinitialise = 1; |
Steven Toth | ba7e6f3 | 2006-09-25 12:41:53 -0300 | [diff] [blame] | 2607 | } |
| 2608 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2609 | if ((ret = dvb_generic_open (inode, file)) < 0) |
| 2610 | goto err1; |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 2611 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2612 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 2613 | /* normal tune mode when opened R/W */ |
| 2614 | fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT; |
| 2615 | fepriv->tone = -1; |
| 2616 | fepriv->voltage = -1; |
| 2617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | ret = dvb_frontend_start (fe); |
| 2619 | if (ret) |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2620 | goto err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | |
| 2622 | /* empty event queue */ |
| 2623 | fepriv->events.eventr = fepriv->events.eventw = 0; |
| 2624 | } |
| 2625 | |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2626 | if (adapter->mfe_shared) |
| 2627 | mutex_unlock (&adapter->mfe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | return ret; |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2629 | |
| 2630 | err2: |
| 2631 | dvb_generic_release(inode, file); |
| 2632 | err1: |
| 2633 | if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) |
| 2634 | fe->ops.ts_bus_ctrl(fe, 0); |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2635 | err0: |
| 2636 | if (adapter->mfe_shared) |
| 2637 | mutex_unlock (&adapter->mfe_lock); |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2638 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | static int dvb_frontend_release(struct inode *inode, struct file *file) |
| 2642 | { |
| 2643 | struct dvb_device *dvbdev = file->private_data; |
| 2644 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2645 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2646 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2648 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 2650 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | fepriv->release_jiffies = jiffies; |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 2652 | mb(); |
| 2653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2655 | ret = dvb_generic_release (inode, file); |
| 2656 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2657 | if (dvbdev->users == -1) { |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 2658 | wake_up(&fepriv->wait_queue); |
Shuah Khan | 18ed286 | 2014-07-12 13:44:12 -0300 | [diff] [blame] | 2659 | if (fe->exit != DVB_FE_NO_EXIT) |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2660 | wake_up(&dvbdev->wait_queue); |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2661 | if (fe->ops.ts_bus_ctrl) |
| 2662 | fe->ops.ts_bus_ctrl(fe, 0); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2663 | } |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2664 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2665 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
Jan Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 2668 | static const struct file_operations dvb_frontend_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | .owner = THIS_MODULE, |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 2670 | .unlocked_ioctl = dvb_generic_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | .poll = dvb_frontend_poll, |
| 2672 | .open = dvb_frontend_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 2673 | .release = dvb_frontend_release, |
| 2674 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | }; |
| 2676 | |
Antti Palosaari | 06bae12 | 2012-08-14 22:21:06 -0300 | [diff] [blame] | 2677 | int dvb_frontend_suspend(struct dvb_frontend *fe) |
| 2678 | { |
| 2679 | int ret = 0; |
| 2680 | |
| 2681 | dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num, |
| 2682 | fe->id); |
| 2683 | |
Mauro Carvalho Chehab | 59d7889 | 2014-08-09 21:47:19 -0300 | [diff] [blame] | 2684 | if (fe->ops.tuner_ops.suspend) |
| 2685 | ret = fe->ops.tuner_ops.suspend(fe); |
| 2686 | else if (fe->ops.tuner_ops.sleep) |
Antti Palosaari | 06bae12 | 2012-08-14 22:21:06 -0300 | [diff] [blame] | 2687 | ret = fe->ops.tuner_ops.sleep(fe); |
| 2688 | |
| 2689 | if (fe->ops.sleep) |
| 2690 | ret = fe->ops.sleep(fe); |
| 2691 | |
| 2692 | return ret; |
| 2693 | } |
| 2694 | EXPORT_SYMBOL(dvb_frontend_suspend); |
| 2695 | |
| 2696 | int dvb_frontend_resume(struct dvb_frontend *fe) |
| 2697 | { |
| 2698 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 2699 | int ret = 0; |
| 2700 | |
| 2701 | dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num, |
| 2702 | fe->id); |
| 2703 | |
Shuah Khan | 87cd0fa | 2014-07-24 13:02:14 -0300 | [diff] [blame] | 2704 | fe->exit = DVB_FE_DEVICE_RESUME; |
Antti Palosaari | 06bae12 | 2012-08-14 22:21:06 -0300 | [diff] [blame] | 2705 | if (fe->ops.init) |
| 2706 | ret = fe->ops.init(fe); |
| 2707 | |
Mauro Carvalho Chehab | 59d7889 | 2014-08-09 21:47:19 -0300 | [diff] [blame] | 2708 | if (fe->ops.tuner_ops.resume) |
| 2709 | ret = fe->ops.tuner_ops.resume(fe); |
| 2710 | else if (fe->ops.tuner_ops.init) |
Antti Palosaari | 06bae12 | 2012-08-14 22:21:06 -0300 | [diff] [blame] | 2711 | ret = fe->ops.tuner_ops.init(fe); |
| 2712 | |
Mauro Carvalho Chehab | 3663b31 | 2015-11-10 11:50:30 -0200 | [diff] [blame] | 2713 | if (fe->ops.set_tone && fepriv->tone != -1) |
| 2714 | fe->ops.set_tone(fe, fepriv->tone); |
| 2715 | if (fe->ops.set_voltage && fepriv->voltage != -1) |
| 2716 | fe->ops.set_voltage(fe, fepriv->voltage); |
| 2717 | |
Shuah Khan | 87cd0fa | 2014-07-24 13:02:14 -0300 | [diff] [blame] | 2718 | fe->exit = DVB_FE_NO_EXIT; |
Antti Palosaari | 06bae12 | 2012-08-14 22:21:06 -0300 | [diff] [blame] | 2719 | fepriv->state = FESTATE_RETUNE; |
| 2720 | dvb_frontend_wakeup(fe); |
| 2721 | |
| 2722 | return ret; |
| 2723 | } |
| 2724 | EXPORT_SYMBOL(dvb_frontend_resume); |
| 2725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | int dvb_register_frontend(struct dvb_adapter* dvb, |
| 2727 | struct dvb_frontend* fe) |
| 2728 | { |
| 2729 | struct dvb_frontend_private *fepriv; |
Mauro Carvalho Chehab | c1b31b1 | 2015-01-02 11:00:17 -0300 | [diff] [blame] | 2730 | const struct dvb_device dvbdev_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | .users = ~0, |
| 2732 | .writers = 1, |
| 2733 | .readers = (~0)-1, |
| 2734 | .fops = &dvb_frontend_fops, |
Mauro Carvalho Chehab | c1b31b1 | 2015-01-02 11:00:17 -0300 | [diff] [blame] | 2735 | #if defined(CONFIG_MEDIA_CONTROLLER_DVB) |
| 2736 | .name = fe->ops.info.name, |
| 2737 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | .kernel_ioctl = dvb_frontend_ioctl |
| 2739 | }; |
| 2740 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2741 | dev_dbg(dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2743 | if (mutex_lock_interruptible(&frontend_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | return -ERESTARTSYS; |
| 2745 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 2746 | fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | if (fe->frontend_priv == NULL) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2748 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | return -ENOMEM; |
| 2750 | } |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2751 | fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | |
Thomas Gleixner | a0a4714 | 2010-09-07 11:33:27 -0300 | [diff] [blame] | 2753 | sema_init(&fepriv->sem, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | init_waitqueue_head (&fepriv->wait_queue); |
| 2755 | init_waitqueue_head (&fepriv->events.wait_queue); |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 2756 | mutex_init(&fepriv->events.mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | fe->dvb = dvb; |
| 2758 | fepriv->inversion = INVERSION_OFF; |
| 2759 | |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2760 | dev_info(fe->dvb->device, |
| 2761 | "DVB: registering adapter %i frontend %i (%s)...\n", |
| 2762 | fe->dvb->num, fe->id, fe->ops.info.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
| 2764 | dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template, |
| 2765 | fe, DVB_DEVICE_FRONTEND); |
| 2766 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2767 | /* |
| 2768 | * Initialize the cache to the proper values according with the |
| 2769 | * first supported delivery system (ops->delsys[0]) |
| 2770 | */ |
Mauro Carvalho Chehab | 240ab50 | 2012-01-10 18:00:50 -0300 | [diff] [blame] | 2771 | |
Mauro Carvalho Chehab | be431b1 | 2013-03-18 15:25:36 -0300 | [diff] [blame] | 2772 | fe->dtv_property_cache.delivery_system = fe->ops.delsys[0]; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2773 | dvb_frontend_clear_cache(fe); |
| 2774 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2775 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | return 0; |
| 2777 | } |
| 2778 | EXPORT_SYMBOL(dvb_register_frontend); |
| 2779 | |
| 2780 | int dvb_unregister_frontend(struct dvb_frontend* fe) |
| 2781 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2782 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Antti Palosaari | 36bdbc3 | 2012-08-15 20:28:37 -0300 | [diff] [blame] | 2783 | dev_dbg(fe->dvb->device, "%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | |
Markus Rechberger | 57861b4 | 2007-04-14 10:19:18 -0300 | [diff] [blame] | 2785 | mutex_lock(&frontend_mutex); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2786 | dvb_frontend_stop (fe); |
Markus Rechberger | 57861b4 | 2007-04-14 10:19:18 -0300 | [diff] [blame] | 2787 | mutex_unlock(&frontend_mutex); |
| 2788 | |
| 2789 | if (fepriv->dvbdev->users < -1) |
| 2790 | wait_event(fepriv->dvbdev->wait_queue, |
| 2791 | fepriv->dvbdev->users==-1); |
| 2792 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2793 | mutex_lock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | dvb_unregister_device (fepriv->dvbdev); |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 2795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | /* fe is invalid now */ |
| 2797 | kfree(fepriv); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2798 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | return 0; |
| 2800 | } |
| 2801 | EXPORT_SYMBOL(dvb_unregister_frontend); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2802 | |
Mauro Carvalho Chehab | 149ef72 | 2008-04-29 21:38:46 -0300 | [diff] [blame] | 2803 | #ifdef CONFIG_MEDIA_ATTACH |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2804 | void dvb_frontend_detach(struct dvb_frontend* fe) |
| 2805 | { |
| 2806 | void *ptr; |
| 2807 | |
| 2808 | if (fe->ops.release_sec) { |
| 2809 | fe->ops.release_sec(fe); |
Mauro Carvalho Chehab | 4647f48 | 2014-05-29 09:20:13 -0300 | [diff] [blame] | 2810 | dvb_detach(fe->ops.release_sec); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2811 | } |
| 2812 | if (fe->ops.tuner_ops.release) { |
| 2813 | fe->ops.tuner_ops.release(fe); |
Mauro Carvalho Chehab | 4647f48 | 2014-05-29 09:20:13 -0300 | [diff] [blame] | 2814 | dvb_detach(fe->ops.tuner_ops.release); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2815 | } |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 2816 | if (fe->ops.analog_ops.release) { |
| 2817 | fe->ops.analog_ops.release(fe); |
Mauro Carvalho Chehab | 4647f48 | 2014-05-29 09:20:13 -0300 | [diff] [blame] | 2818 | dvb_detach(fe->ops.analog_ops.release); |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 2819 | } |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2820 | ptr = (void*)fe->ops.release; |
| 2821 | if (ptr) { |
| 2822 | fe->ops.release(fe); |
Mauro Carvalho Chehab | 4647f48 | 2014-05-29 09:20:13 -0300 | [diff] [blame] | 2823 | dvb_detach(ptr); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2824 | } |
| 2825 | } |
| 2826 | #else |
| 2827 | void dvb_frontend_detach(struct dvb_frontend* fe) |
| 2828 | { |
| 2829 | if (fe->ops.release_sec) |
| 2830 | fe->ops.release_sec(fe); |
| 2831 | if (fe->ops.tuner_ops.release) |
| 2832 | fe->ops.tuner_ops.release(fe); |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 2833 | if (fe->ops.analog_ops.release) |
| 2834 | fe->ops.analog_ops.release(fe); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2835 | if (fe->ops.release) |
| 2836 | fe->ops.release(fe); |
| 2837 | } |
| 2838 | #endif |
| 2839 | EXPORT_SYMBOL(dvb_frontend_detach); |