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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #include "dvb_frontend.h" |
| 46 | #include "dvbdev.h" |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 47 | #include <linux/dvb/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | static int dvb_frontend_debug; |
Oliver Endriss | 849be2c | 2007-08-25 12:22:16 -0300 | [diff] [blame] | 50 | static int dvb_shutdown_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static int dvb_force_auto_inversion; |
| 52 | static int dvb_override_tune_delay; |
| 53 | static int dvb_powerdown_on_sleep = 1; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 54 | static int dvb_mfe_wait_time = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | module_param_named(frontend_debug, dvb_frontend_debug, int, 0644); |
Johannes Stezenbach | f4f009a | 2005-05-16 21:54:21 -0700 | [diff] [blame] | 57 | 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] | 58 | module_param(dvb_shutdown_timeout, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | 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] | 60 | module_param(dvb_force_auto_inversion, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | 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] | 62 | module_param(dvb_override_tune_delay, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 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] | 64 | module_param(dvb_powerdown_on_sleep, int, 0644); |
Uwe Bugla | a8558577 | 2006-04-11 10:21:37 -0300 | [diff] [blame] | 65 | 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] | 66 | module_param(dvb_mfe_wait_time, int, 0644); |
| 67 | 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] | 68 | |
| 69 | #define dprintk if (dvb_frontend_debug) printk |
| 70 | |
| 71 | #define FESTATE_IDLE 1 |
| 72 | #define FESTATE_RETUNE 2 |
| 73 | #define FESTATE_TUNING_FAST 4 |
| 74 | #define FESTATE_TUNING_SLOW 8 |
| 75 | #define FESTATE_TUNED 16 |
| 76 | #define FESTATE_ZIGZAG_FAST 32 |
| 77 | #define FESTATE_ZIGZAG_SLOW 64 |
| 78 | #define FESTATE_DISEQC 128 |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 79 | #define FESTATE_ERROR 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC) |
| 81 | #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST) |
| 82 | #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW) |
| 83 | #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW) |
Manu Abraham | 0249ef1 | 2006-06-21 10:27:31 -0300 | [diff] [blame] | 84 | |
| 85 | #define FE_ALGO_HW 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* |
| 87 | * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling. |
| 88 | * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune. |
| 89 | * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress. |
| 90 | * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower. |
| 91 | * FESTATE_TUNED. The frontend has successfully locked on. |
| 92 | * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it. |
| 93 | * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower. |
| 94 | * FESTATE_DISEQC. A DISEQC command has just been issued. |
| 95 | * FESTATE_WAITFORLOCK. When we're waiting for a lock. |
| 96 | * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan. |
| 97 | * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan. |
| 98 | * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again. |
| 99 | */ |
| 100 | |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 101 | #define DVB_FE_NO_EXIT 0 |
| 102 | #define DVB_FE_NORMAL_EXIT 1 |
| 103 | #define DVB_FE_DEVICE_REMOVED 2 |
| 104 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 105 | static DEFINE_MUTEX(frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | struct dvb_frontend_private { |
| 108 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 109 | /* thread/frontend values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | struct dvb_device *dvbdev; |
Andreas Oberritter | a5959db | 2011-05-08 20:03:40 -0300 | [diff] [blame] | 111 | struct dvb_frontend_parameters parameters_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct dvb_fe_events events; |
| 113 | struct semaphore sem; |
| 114 | struct list_head list_head; |
| 115 | wait_queue_head_t wait_queue; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 116 | struct task_struct *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | unsigned long release_jiffies; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 118 | unsigned int exit; |
| 119 | unsigned int wakeup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | fe_status_t status; |
Peter Beutner | 400b708 | 2006-01-09 15:32:43 -0200 | [diff] [blame] | 121 | unsigned long tune_mode_flags; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 122 | unsigned int delay; |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 123 | unsigned int reinitialise; |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 124 | int tone; |
| 125 | int voltage; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 126 | |
| 127 | /* swzigzag values */ |
| 128 | unsigned int state; |
| 129 | unsigned int bending; |
| 130 | int lnb_drift; |
| 131 | unsigned int inversion; |
| 132 | unsigned int auto_step; |
| 133 | unsigned int auto_sub_step; |
| 134 | unsigned int started_auto_step; |
| 135 | unsigned int min_delay; |
| 136 | unsigned int max_drift; |
| 137 | unsigned int step_size; |
| 138 | int quality; |
| 139 | unsigned int check_wrapped; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 140 | enum dvbfe_search algo_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 143 | static void dvb_frontend_wakeup(struct dvb_frontend *fe); |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 144 | static int dtv_get_frontend(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 145 | struct dvb_frontend_parameters *p_out); |
| 146 | |
| 147 | static bool has_get_frontend(struct dvb_frontend *fe) |
| 148 | { |
Mauro Carvalho Chehab | b1e9a6501 | 2011-12-26 16:43:32 -0300 | [diff] [blame] | 149 | return fe->ops.get_frontend; |
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: |
| 180 | case SYS_DMBTH: |
| 181 | return DVBV3_OFDM; |
| 182 | case SYS_ATSC: |
| 183 | case SYS_DVBC_ANNEX_B: |
| 184 | return DVBV3_ATSC; |
| 185 | case SYS_UNDEFINED: |
| 186 | case SYS_ISDBC: |
| 187 | case SYS_DVBH: |
| 188 | case SYS_DAB: |
| 189 | case SYS_ATSCMH: |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status) |
| 202 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 203 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | struct dvb_fe_events *events = &fepriv->events; |
| 205 | struct dvb_frontend_event *e; |
| 206 | int wp; |
| 207 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 208 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 210 | if ((status & FE_HAS_LOCK) && has_get_frontend(fe)) |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 211 | dtv_get_frontend(fe, &fepriv->parameters_out); |
Andreas Oberritter | 77b1e2f | 2011-08-04 12:33:15 -0300 | [diff] [blame] | 212 | |
| 213 | mutex_lock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | wp = (events->eventw + 1) % MAX_EVENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (wp == events->eventr) { |
| 217 | events->overflow = 1; |
| 218 | events->eventr = (events->eventr + 1) % MAX_EVENT; |
| 219 | } |
| 220 | |
| 221 | e = &events->events[events->eventw]; |
Andreas Oberritter | 77b1e2f | 2011-08-04 12:33:15 -0300 | [diff] [blame] | 222 | e->status = status; |
Andreas Oberritter | a5959db | 2011-05-08 20:03:40 -0300 | [diff] [blame] | 223 | e->parameters = fepriv->parameters_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | events->eventw = wp; |
| 226 | |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 227 | mutex_unlock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | wake_up_interruptible (&events->wait_queue); |
| 230 | } |
| 231 | |
| 232 | static int dvb_frontend_get_event(struct dvb_frontend *fe, |
| 233 | struct dvb_frontend_event *event, int flags) |
| 234 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 235 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | struct dvb_fe_events *events = &fepriv->events; |
| 237 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 238 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | if (events->overflow) { |
| 241 | events->overflow = 0; |
| 242 | return -EOVERFLOW; |
| 243 | } |
| 244 | |
| 245 | if (events->eventw == events->eventr) { |
| 246 | int ret; |
| 247 | |
| 248 | if (flags & O_NONBLOCK) |
| 249 | return -EWOULDBLOCK; |
| 250 | |
| 251 | up(&fepriv->sem); |
| 252 | |
| 253 | ret = wait_event_interruptible (events->wait_queue, |
| 254 | events->eventw != events->eventr); |
| 255 | |
| 256 | if (down_interruptible (&fepriv->sem)) |
| 257 | return -ERESTARTSYS; |
| 258 | |
| 259 | if (ret < 0) |
| 260 | return ret; |
| 261 | } |
| 262 | |
Andreas Oberritter | 77b1e2f | 2011-08-04 12:33:15 -0300 | [diff] [blame] | 263 | mutex_lock(&events->mtx); |
| 264 | *event = events->events[events->eventr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | events->eventr = (events->eventr + 1) % MAX_EVENT; |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 266 | mutex_unlock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Andreas Oberritter | 20640be | 2011-08-04 12:33:14 -0300 | [diff] [blame] | 271 | static void dvb_frontend_clear_events(struct dvb_frontend *fe) |
| 272 | { |
| 273 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 274 | struct dvb_fe_events *events = &fepriv->events; |
| 275 | |
| 276 | mutex_lock(&events->mtx); |
| 277 | events->eventr = events->eventw; |
| 278 | mutex_unlock(&events->mtx); |
| 279 | } |
| 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | static void dvb_frontend_init(struct dvb_frontend *fe) |
| 282 | { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 283 | dprintk ("DVB: initialising adapter %i frontend %i (%s)...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | fe->dvb->num, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 285 | fe->id, |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 286 | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 312 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 314 | if (locked) |
| 315 | (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256; |
| 316 | else |
| 317 | (fepriv->quality) = (fepriv->quality * 220 + 0) / 256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 319 | q2 = fepriv->quality - 128; |
| 320 | q2 *= q2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 322 | fepriv->delay = fepriv->min_delay + q2 * HZ / (128*128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Performs automatic twiddling of frontend parameters. |
| 327 | * |
| 328 | * @param fe The frontend concerned. |
| 329 | * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT |
| 330 | * @returns Number of complete iterations that have been performed. |
| 331 | */ |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 332 | 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] | 333 | { |
| 334 | int autoinversion; |
| 335 | int ready = 0; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 336 | int fe_set_err = 0; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 337 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 338 | struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp; |
| 339 | int original_inversion = c->inversion; |
| 340 | u32 original_frequency = c->frequency; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* are we using autoinversion? */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 343 | autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 344 | (c->inversion == INVERSION_AUTO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | /* setup parameters correctly */ |
| 347 | while(!ready) { |
| 348 | /* calculate the lnb_drift */ |
| 349 | fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size; |
| 350 | |
| 351 | /* wrap the auto_step if we've exceeded the maximum drift */ |
| 352 | if (fepriv->lnb_drift > fepriv->max_drift) { |
| 353 | fepriv->auto_step = 0; |
| 354 | fepriv->auto_sub_step = 0; |
| 355 | fepriv->lnb_drift = 0; |
| 356 | } |
| 357 | |
| 358 | /* perform inversion and +/- zigzag */ |
| 359 | switch(fepriv->auto_sub_step) { |
| 360 | case 0: |
| 361 | /* try with the current inversion and current drift setting */ |
| 362 | ready = 1; |
| 363 | break; |
| 364 | |
| 365 | case 1: |
| 366 | if (!autoinversion) break; |
| 367 | |
| 368 | fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF; |
| 369 | ready = 1; |
| 370 | break; |
| 371 | |
| 372 | case 2: |
| 373 | if (fepriv->lnb_drift == 0) break; |
| 374 | |
| 375 | fepriv->lnb_drift = -fepriv->lnb_drift; |
| 376 | ready = 1; |
| 377 | break; |
| 378 | |
| 379 | case 3: |
| 380 | if (fepriv->lnb_drift == 0) break; |
| 381 | if (!autoinversion) break; |
| 382 | |
| 383 | fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF; |
| 384 | fepriv->lnb_drift = -fepriv->lnb_drift; |
| 385 | ready = 1; |
| 386 | break; |
| 387 | |
| 388 | default: |
| 389 | fepriv->auto_step++; |
| 390 | fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */ |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | if (!ready) fepriv->auto_sub_step++; |
| 395 | } |
| 396 | |
| 397 | /* if this attempt would hit where we started, indicate a complete |
| 398 | * iteration has occurred */ |
| 399 | if ((fepriv->auto_step == fepriv->started_auto_step) && |
| 400 | (fepriv->auto_sub_step == 0) && check_wrapped) { |
| 401 | return 1; |
| 402 | } |
| 403 | |
| 404 | dprintk("%s: drift:%i inversion:%i auto_step:%i " |
| 405 | "auto_sub_step:%i started_auto_step:%i\n", |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 406 | __func__, fepriv->lnb_drift, fepriv->inversion, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step); |
| 408 | |
| 409 | /* set the frontend itself */ |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 410 | c->frequency += fepriv->lnb_drift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | if (autoinversion) |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 412 | c->inversion = fepriv->inversion; |
| 413 | tmp = *c; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 414 | if (fe->ops.set_frontend) |
Mauro Carvalho Chehab | bc9cd27 | 2011-12-20 15:31:54 -0300 | [diff] [blame] | 415 | fe_set_err = fe->ops.set_frontend(fe); |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 416 | *c = tmp; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 417 | if (fe_set_err < 0) { |
| 418 | fepriv->state = FESTATE_ERROR; |
| 419 | return fe_set_err; |
| 420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 422 | c->frequency = original_frequency; |
| 423 | c->inversion = original_inversion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | fepriv->auto_sub_step++; |
| 426 | return 0; |
| 427 | } |
| 428 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 429 | static void dvb_frontend_swzigzag(struct dvb_frontend *fe) |
| 430 | { |
Andrew de Quincey | 30d9464 | 2006-11-16 22:12:40 -0300 | [diff] [blame] | 431 | fe_status_t s = 0; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 432 | int retval = 0; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 433 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 434 | struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 435 | |
| 436 | /* if we've got no parameters, just keep idling */ |
| 437 | if (fepriv->state & FESTATE_IDLE) { |
| 438 | fepriv->delay = 3*HZ; |
| 439 | fepriv->quality = 0; |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | /* in SCAN mode, we just set the frontend when asked and leave it alone */ |
| 444 | if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) { |
| 445 | if (fepriv->state & FESTATE_RETUNE) { |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 446 | tmp = *c; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 447 | if (fe->ops.set_frontend) |
Mauro Carvalho Chehab | bc9cd27 | 2011-12-20 15:31:54 -0300 | [diff] [blame] | 448 | retval = fe->ops.set_frontend(fe); |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 449 | *c = tmp; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 450 | if (retval < 0) |
| 451 | fepriv->state = FESTATE_ERROR; |
| 452 | else |
| 453 | fepriv->state = FESTATE_TUNED; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 454 | } |
| 455 | fepriv->delay = 3*HZ; |
| 456 | fepriv->quality = 0; |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | /* get the frontend status */ |
| 461 | if (fepriv->state & FESTATE_RETUNE) { |
| 462 | s = 0; |
| 463 | } else { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 464 | if (fe->ops.read_status) |
| 465 | fe->ops.read_status(fe, &s); |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 466 | if (s != fepriv->status) { |
| 467 | dvb_frontend_add_event(fe, s); |
| 468 | fepriv->status = s; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /* if we're not tuned, and we have a lock, move to the TUNED state */ |
| 473 | if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) { |
| 474 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 475 | fepriv->state = FESTATE_TUNED; |
| 476 | |
| 477 | /* if we're tuned, then we have determined the correct inversion */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 478 | if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && |
Mauro Carvalho Chehab | ac3852c | 2011-12-30 09:30:25 -0300 | [diff] [blame] | 479 | (c->inversion == INVERSION_AUTO)) { |
| 480 | c->inversion = fepriv->inversion; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 481 | } |
| 482 | return; |
| 483 | } |
| 484 | |
| 485 | /* if we are tuned already, check we're still locked */ |
| 486 | if (fepriv->state & FESTATE_TUNED) { |
| 487 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 488 | |
| 489 | /* we're tuned, and the lock is still good... */ |
| 490 | if (s & FE_HAS_LOCK) { |
| 491 | return; |
| 492 | } else { /* if we _WERE_ tuned, but now don't have a lock */ |
| 493 | fepriv->state = FESTATE_ZIGZAG_FAST; |
| 494 | fepriv->started_auto_step = fepriv->auto_step; |
| 495 | fepriv->check_wrapped = 0; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | /* don't actually do anything if we're in the LOSTLOCK state, |
| 500 | * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */ |
| 501 | if ((fepriv->state & FESTATE_LOSTLOCK) && |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 502 | (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 503 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 504 | return; |
| 505 | } |
| 506 | |
| 507 | /* don't do anything if we're in the DISEQC state, since this |
| 508 | * might be someone with a motorized dish controlled by DISEQC. |
| 509 | * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */ |
| 510 | if (fepriv->state & FESTATE_DISEQC) { |
| 511 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | /* if we're in the RETUNE state, set everything up for a brand |
| 516 | * new scan, keeping the current inversion setting, as the next |
| 517 | * tune is _very_ likely to require the same */ |
| 518 | if (fepriv->state & FESTATE_RETUNE) { |
| 519 | fepriv->lnb_drift = 0; |
| 520 | fepriv->auto_step = 0; |
| 521 | fepriv->auto_sub_step = 0; |
| 522 | fepriv->started_auto_step = 0; |
| 523 | fepriv->check_wrapped = 0; |
| 524 | } |
| 525 | |
| 526 | /* fast zigzag. */ |
| 527 | if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) { |
| 528 | fepriv->delay = fepriv->min_delay; |
| 529 | |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 530 | /* perform a tune */ |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 531 | retval = dvb_frontend_swzigzag_autotune(fe, |
| 532 | fepriv->check_wrapped); |
| 533 | if (retval < 0) { |
| 534 | return; |
| 535 | } else if (retval) { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 536 | /* OK, if we've run out of trials at the fast speed. |
| 537 | * Drop back to slow for the _next_ attempt */ |
| 538 | fepriv->state = FESTATE_SEARCHING_SLOW; |
| 539 | fepriv->started_auto_step = fepriv->auto_step; |
| 540 | return; |
| 541 | } |
| 542 | fepriv->check_wrapped = 1; |
| 543 | |
| 544 | /* if we've just retuned, enter the ZIGZAG_FAST state. |
| 545 | * This ensures we cannot return from an |
| 546 | * FE_SET_FRONTEND ioctl before the first frontend tune |
| 547 | * occurs */ |
| 548 | if (fepriv->state & FESTATE_RETUNE) { |
| 549 | fepriv->state = FESTATE_TUNING_FAST; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /* slow zigzag */ |
| 554 | if (fepriv->state & FESTATE_SEARCHING_SLOW) { |
| 555 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 556 | |
| 557 | /* Note: don't bother checking for wrapping; we stay in this |
| 558 | * state until we get a lock */ |
| 559 | dvb_frontend_swzigzag_autotune(fe, 0); |
| 560 | } |
| 561 | } |
| 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | static int dvb_frontend_is_exiting(struct dvb_frontend *fe) |
| 564 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 565 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 567 | if (fepriv->exit != DVB_FE_NO_EXIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | return 1; |
| 569 | |
| 570 | if (fepriv->dvbdev->writers == 1) |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 571 | if (time_after_eq(jiffies, fepriv->release_jiffies + |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 572 | dvb_shutdown_timeout * HZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return 1; |
| 574 | |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | static int dvb_frontend_should_wakeup(struct dvb_frontend *fe) |
| 579 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 580 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | if (fepriv->wakeup) { |
| 583 | fepriv->wakeup = 0; |
| 584 | return 1; |
| 585 | } |
| 586 | return dvb_frontend_is_exiting(fe); |
| 587 | } |
| 588 | |
| 589 | static void dvb_frontend_wakeup(struct dvb_frontend *fe) |
| 590 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 591 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
| 593 | fepriv->wakeup = 1; |
| 594 | wake_up_interruptible(&fepriv->wait_queue); |
| 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | static int dvb_frontend_thread(void *data) |
| 598 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 599 | struct dvb_frontend *fe = data; |
| 600 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | fe_status_t s; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 602 | enum dvbfe_algo algo; |
| 603 | |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 604 | bool re_tune = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 606 | dprintk("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 608 | fepriv->check_wrapped = 0; |
| 609 | fepriv->quality = 0; |
| 610 | fepriv->delay = 3*HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | fepriv->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | fepriv->wakeup = 0; |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 613 | fepriv->reinitialise = 0; |
| 614 | |
| 615 | dvb_frontend_init(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 617 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | while (1) { |
| 619 | up(&fepriv->sem); /* is locked when we enter the thread... */ |
akpm@linux-foundation.org | 6591691 | 2007-02-08 14:36:57 -0300 | [diff] [blame] | 620 | restart: |
Hans Verkuil | 94238e9 | 2011-08-27 11:30:25 -0300 | [diff] [blame] | 621 | wait_event_interruptible_timeout(fepriv->wait_queue, |
Rafael J. Wysocki | e42837b | 2007-10-18 03:04:45 -0700 | [diff] [blame] | 622 | dvb_frontend_should_wakeup(fe) || kthread_should_stop() |
| 623 | || freezing(current), |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 624 | fepriv->delay); |
| 625 | |
| 626 | if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | /* got signal or quitting */ |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 628 | fepriv->exit = DVB_FE_NORMAL_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | break; |
| 630 | } |
| 631 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 632 | if (try_to_freeze()) |
akpm@linux-foundation.org | 6591691 | 2007-02-08 14:36:57 -0300 | [diff] [blame] | 633 | goto restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
| 635 | if (down_interruptible(&fepriv->sem)) |
| 636 | break; |
| 637 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 638 | if (fepriv->reinitialise) { |
| 639 | dvb_frontend_init(fe); |
Andreas Oberritter | 42f4e77 | 2011-08-24 14:33:52 -0300 | [diff] [blame] | 640 | if (fe->ops.set_tone && fepriv->tone != -1) |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 641 | fe->ops.set_tone(fe, fepriv->tone); |
Andreas Oberritter | 42f4e77 | 2011-08-24 14:33:52 -0300 | [diff] [blame] | 642 | if (fe->ops.set_voltage && fepriv->voltage != -1) |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 643 | fe->ops.set_voltage(fe, fepriv->voltage); |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 644 | fepriv->reinitialise = 0; |
| 645 | } |
| 646 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 647 | /* do an iteration of the tuning loop */ |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 648 | if (fe->ops.get_frontend_algo) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 649 | algo = fe->ops.get_frontend_algo(fe); |
| 650 | switch (algo) { |
| 651 | case DVBFE_ALGO_HW: |
| 652 | dprintk("%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 653 | |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 654 | if (fepriv->state & FESTATE_RETUNE) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 655 | dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__); |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 656 | re_tune = true; |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 657 | fepriv->state = FESTATE_TUNED; |
| 658 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 660 | if (fe->ops.tune) |
Mauro Carvalho Chehab | 7e07222 | 2011-12-26 17:48:33 -0300 | [diff] [blame] | 661 | 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] | 662 | |
Darron Broad | 2fac9a0 | 2008-12-18 06:27:50 -0300 | [diff] [blame] | 663 | if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 664 | dprintk("%s: state changed, adding current state\n", __func__); |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 665 | dvb_frontend_add_event(fe, s); |
| 666 | fepriv->status = s; |
| 667 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 668 | break; |
| 669 | case DVBFE_ALGO_SW: |
| 670 | dprintk("%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__); |
Manu Abraham | 70d9063 | 2006-06-29 22:05:23 -0300 | [diff] [blame] | 671 | dvb_frontend_swzigzag(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 672 | break; |
| 673 | case DVBFE_ALGO_CUSTOM: |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 674 | dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state); |
| 675 | if (fepriv->state & FESTATE_RETUNE) { |
| 676 | dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__); |
| 677 | fepriv->state = FESTATE_TUNED; |
| 678 | } |
| 679 | /* Case where we are going to search for a carrier |
| 680 | * User asked us to retune again for some reason, possibly |
| 681 | * requesting a search with a new set of parameters |
| 682 | */ |
| 683 | if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) { |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 684 | if (fe->ops.search) { |
Mauro Carvalho Chehab | 41da532 | 2011-12-26 18:03:12 -0300 | [diff] [blame] | 685 | fepriv->algo_status = fe->ops.search(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 686 | /* We did do a search as was requested, the flags are |
| 687 | * now unset as well and has the flags wrt to search. |
| 688 | */ |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 689 | } else { |
| 690 | fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN; |
| 691 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 692 | } |
| 693 | /* Track the carrier if the search was successful */ |
Mauro Carvalho Chehab | 1b5d871 | 2011-12-26 18:11:25 -0300 | [diff] [blame] | 694 | if (fepriv->algo_status != DVBFE_ALGO_SEARCH_SUCCESS) { |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 695 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 696 | fepriv->delay = HZ / 2; |
| 697 | } |
| 698 | fe->ops.read_status(fe, &s); |
| 699 | if (s != fepriv->status) { |
| 700 | dvb_frontend_add_event(fe, s); /* update event list */ |
| 701 | fepriv->status = s; |
| 702 | if (!(s & FE_HAS_LOCK)) { |
| 703 | fepriv->delay = HZ / 10; |
| 704 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 705 | } else { |
| 706 | fepriv->delay = 60 * HZ; |
| 707 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 708 | } |
| 709 | break; |
| 710 | default: |
| 711 | dprintk("%s: UNDEFINED ALGO !\n", __func__); |
| 712 | break; |
| 713 | } |
| 714 | } else { |
Manu Abraham | 4a4edcc | 2006-06-25 05:46:26 -0300 | [diff] [blame] | 715 | dvb_frontend_swzigzag(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 716 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Oliver Endriss | 608f62d | 2007-08-25 13:17:53 -0300 | [diff] [blame] | 719 | if (dvb_powerdown_on_sleep) { |
| 720 | if (fe->ops.set_voltage) |
| 721 | fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 722 | if (fe->ops.tuner_ops.sleep) { |
Devin Heitmueller | 41286d9 | 2008-11-16 00:44:52 -0300 | [diff] [blame] | 723 | if (fe->ops.i2c_gate_ctrl) |
| 724 | fe->ops.i2c_gate_ctrl(fe, 1); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 725 | fe->ops.tuner_ops.sleep(fe); |
| 726 | if (fe->ops.i2c_gate_ctrl) |
| 727 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 7eef5dd | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 728 | } |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 729 | if (fe->ops.sleep) |
| 730 | fe->ops.sleep(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 733 | fepriv->thread = NULL; |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 734 | if (kthread_should_stop()) |
| 735 | fepriv->exit = DVB_FE_DEVICE_REMOVED; |
| 736 | else |
| 737 | fepriv->exit = DVB_FE_NO_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | mb(); |
| 739 | |
| 740 | dvb_frontend_wakeup(fe); |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static void dvb_frontend_stop(struct dvb_frontend *fe) |
| 745 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 746 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 748 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 750 | fepriv->exit = DVB_FE_NORMAL_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | mb(); |
| 752 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 753 | if (!fepriv->thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | return; |
| 755 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 756 | kthread_stop(fepriv->thread); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 757 | |
Thomas Gleixner | a0a4714 | 2010-09-07 11:33:27 -0300 | [diff] [blame] | 758 | sema_init(&fepriv->sem, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | fepriv->state = FESTATE_IDLE; |
| 760 | |
| 761 | /* paranoia check in case a signal arrived */ |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 762 | if (fepriv->thread) |
| 763 | printk("dvb_frontend_stop: warning: thread %p won't exit\n", |
| 764 | fepriv->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 767 | s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime) |
| 768 | { |
| 769 | return ((curtime.tv_usec < lasttime.tv_usec) ? |
| 770 | 1000000 - lasttime.tv_usec + curtime.tv_usec : |
| 771 | curtime.tv_usec - lasttime.tv_usec); |
| 772 | } |
| 773 | EXPORT_SYMBOL(timeval_usec_diff); |
| 774 | |
| 775 | static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec) |
| 776 | { |
| 777 | curtime->tv_usec += add_usec; |
| 778 | if (curtime->tv_usec >= 1000000) { |
| 779 | curtime->tv_usec -= 1000000; |
| 780 | curtime->tv_sec++; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | /* |
| 785 | * Sleep until gettimeofday() > waketime + add_usec |
| 786 | * This needs to be as precise as possible, but as the delay is |
| 787 | * usually between 2ms and 32ms, it is done using a scheduled msleep |
| 788 | * followed by usleep (normally a busy-wait loop) for the remainder |
| 789 | */ |
| 790 | void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec) |
| 791 | { |
| 792 | struct timeval lasttime; |
| 793 | s32 delta, newdelta; |
| 794 | |
| 795 | timeval_usec_add(waketime, add_usec); |
| 796 | |
| 797 | do_gettimeofday(&lasttime); |
| 798 | delta = timeval_usec_diff(lasttime, *waketime); |
| 799 | if (delta > 2500) { |
| 800 | msleep((delta - 1500) / 1000); |
| 801 | do_gettimeofday(&lasttime); |
| 802 | newdelta = timeval_usec_diff(lasttime, *waketime); |
| 803 | delta = (newdelta > delta) ? 0 : newdelta; |
| 804 | } |
| 805 | if (delta > 0) |
| 806 | udelay(delta); |
| 807 | } |
| 808 | EXPORT_SYMBOL(dvb_frontend_sleep_until); |
| 809 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | static int dvb_frontend_start(struct dvb_frontend *fe) |
| 811 | { |
| 812 | int ret; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 813 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 814 | struct task_struct *fe_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 816 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 818 | if (fepriv->thread) { |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 819 | if (fepriv->exit == DVB_FE_NO_EXIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | return 0; |
| 821 | else |
| 822 | dvb_frontend_stop (fe); |
| 823 | } |
| 824 | |
| 825 | if (signal_pending(current)) |
| 826 | return -EINTR; |
| 827 | if (down_interruptible (&fepriv->sem)) |
| 828 | return -EINTR; |
| 829 | |
| 830 | fepriv->state = FESTATE_IDLE; |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 831 | fepriv->exit = DVB_FE_NO_EXIT; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 832 | fepriv->thread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | mb(); |
| 834 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 835 | fe_thread = kthread_run(dvb_frontend_thread, fe, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 836 | "kdvb-ad-%i-fe-%i", fe->dvb->num,fe->id); |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 837 | if (IS_ERR(fe_thread)) { |
| 838 | ret = PTR_ERR(fe_thread); |
| 839 | printk("dvb_frontend_start: failed to start kthread (%d)\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | up(&fepriv->sem); |
| 841 | return ret; |
| 842 | } |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 843 | fepriv->thread = fe_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | return 0; |
| 845 | } |
| 846 | |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 847 | static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe, |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 848 | u32 *freq_min, u32 *freq_max) |
| 849 | { |
| 850 | *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min); |
| 851 | |
| 852 | if (fe->ops.info.frequency_max == 0) |
| 853 | *freq_max = fe->ops.tuner_ops.info.frequency_max; |
| 854 | else if (fe->ops.tuner_ops.info.frequency_max == 0) |
| 855 | *freq_max = fe->ops.info.frequency_max; |
| 856 | else |
| 857 | *freq_max = min(fe->ops.info.frequency_max, fe->ops.tuner_ops.info.frequency_max); |
| 858 | |
| 859 | if (*freq_min == 0 || *freq_max == 0) |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 860 | printk(KERN_WARNING "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n", |
| 861 | fe->dvb->num,fe->id); |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 862 | } |
| 863 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 864 | static int dvb_frontend_check_parameters(struct dvb_frontend *fe) |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 865 | { |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 866 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 867 | u32 freq_min; |
| 868 | u32 freq_max; |
| 869 | |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 870 | /* range check: frequency */ |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 871 | dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 872 | if ((freq_min && c->frequency < freq_min) || |
| 873 | (freq_max && c->frequency > freq_max)) { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 874 | printk(KERN_WARNING "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n", |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 875 | fe->dvb->num, fe->id, c->frequency, freq_min, freq_max); |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 876 | return -EINVAL; |
| 877 | } |
| 878 | |
| 879 | /* range check: symbol rate */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 880 | switch (c->delivery_system) { |
| 881 | case SYS_DVBS: |
| 882 | case SYS_DVBS2: |
| 883 | case SYS_TURBO: |
| 884 | case SYS_DVBC_ANNEX_A: |
| 885 | case SYS_DVBC_ANNEX_C: |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 886 | if ((fe->ops.info.symbol_rate_min && |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 887 | c->symbol_rate < fe->ops.info.symbol_rate_min) || |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 888 | (fe->ops.info.symbol_rate_max && |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 889 | c->symbol_rate > fe->ops.info.symbol_rate_max)) { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 890 | printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n", |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 891 | fe->dvb->num, fe->id, c->symbol_rate, |
| 892 | fe->ops.info.symbol_rate_min, |
| 893 | fe->ops.info.symbol_rate_max); |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 894 | return -EINVAL; |
| 895 | } |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 896 | default: |
| 897 | break; |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 903 | static int dvb_frontend_clear_cache(struct dvb_frontend *fe) |
| 904 | { |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 905 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 906 | int i; |
Mauro Carvalho Chehab | 149709f | 2012-01-13 11:46:36 -0200 | [diff] [blame^] | 907 | u32 delsys; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 908 | |
Mauro Carvalho Chehab | 149709f | 2012-01-13 11:46:36 -0200 | [diff] [blame^] | 909 | delsys = c->delivery_system; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 910 | memset(c, 0, sizeof(struct dtv_frontend_properties)); |
Mauro Carvalho Chehab | 149709f | 2012-01-13 11:46:36 -0200 | [diff] [blame^] | 911 | c->delivery_system = delsys; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 912 | |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 913 | c->state = DTV_CLEAR; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 914 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 915 | dprintk("%s() Clearing cache for delivery system %d\n", __func__, |
| 916 | c->delivery_system); |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 917 | |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 918 | c->transmission_mode = TRANSMISSION_MODE_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 919 | c->bandwidth_hz = 0; /* AUTO */ |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 920 | c->guard_interval = GUARD_INTERVAL_AUTO; |
| 921 | c->hierarchy = HIERARCHY_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 922 | c->symbol_rate = 0; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 923 | c->code_rate_HP = FEC_AUTO; |
| 924 | c->code_rate_LP = FEC_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 925 | c->fec_inner = FEC_AUTO; |
Mauro Carvalho Chehab | 39ce61a | 2011-11-11 12:46:23 -0200 | [diff] [blame] | 926 | c->rolloff = ROLLOFF_AUTO; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 927 | c->voltage = SEC_VOLTAGE_OFF; |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 928 | c->sectone = SEC_TONE_OFF; |
| 929 | c->pilot = PILOT_AUTO; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 930 | |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 931 | c->isdbt_partial_reception = 0; |
| 932 | c->isdbt_sb_mode = 0; |
| 933 | c->isdbt_sb_subchannel = 0; |
| 934 | c->isdbt_sb_segment_idx = 0; |
| 935 | c->isdbt_sb_segment_count = 0; |
| 936 | c->isdbt_layer_enabled = 0; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 937 | for (i = 0; i < 3; i++) { |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 938 | c->layer[i].fec = FEC_AUTO; |
| 939 | c->layer[i].modulation = QAM_AUTO; |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 940 | c->layer[i].interleaving = 0; |
| 941 | c->layer[i].segment_count = 0; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 942 | } |
| 943 | |
Mauro Carvalho Chehab | 26c924f | 2012-01-01 16:11:10 -0300 | [diff] [blame] | 944 | c->isdbs_ts_id = 0; |
| 945 | c->dvbt2_plp_id = 0; |
| 946 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 947 | switch (c->delivery_system) { |
| 948 | case SYS_DVBS: |
| 949 | case SYS_DVBS2: |
| 950 | case SYS_TURBO: |
| 951 | c->modulation = QPSK; /* implied for DVB-S in legacy API */ |
| 952 | c->rolloff = ROLLOFF_35;/* implied for DVB-S */ |
| 953 | break; |
| 954 | case SYS_ATSC: |
| 955 | c->modulation = VSB_8; |
| 956 | break; |
| 957 | default: |
| 958 | c->modulation = QAM_AUTO; |
| 959 | break; |
| 960 | } |
| 961 | |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | #define _DTV_CMD(n, s, b) \ |
| 966 | [n] = { \ |
| 967 | .name = #n, \ |
| 968 | .cmd = n, \ |
| 969 | .set = s,\ |
| 970 | .buffer = b \ |
| 971 | } |
| 972 | |
Andreas Oberritter | ec05a64 | 2011-05-26 07:54:14 -0300 | [diff] [blame] | 973 | static struct dtv_cmds_h dtv_cmds[DTV_MAX_COMMAND + 1] = { |
Mauro Carvalho Chehab | 06d3a39 | 2009-10-23 20:09:42 -0300 | [diff] [blame] | 974 | _DTV_CMD(DTV_TUNE, 1, 0), |
| 975 | _DTV_CMD(DTV_CLEAR, 1, 0), |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 976 | |
| 977 | /* Set */ |
Mauro Carvalho Chehab | 06d3a39 | 2009-10-23 20:09:42 -0300 | [diff] [blame] | 978 | _DTV_CMD(DTV_FREQUENCY, 1, 0), |
| 979 | _DTV_CMD(DTV_BANDWIDTH_HZ, 1, 0), |
| 980 | _DTV_CMD(DTV_MODULATION, 1, 0), |
| 981 | _DTV_CMD(DTV_INVERSION, 1, 0), |
| 982 | _DTV_CMD(DTV_DISEQC_MASTER, 1, 1), |
| 983 | _DTV_CMD(DTV_SYMBOL_RATE, 1, 0), |
| 984 | _DTV_CMD(DTV_INNER_FEC, 1, 0), |
| 985 | _DTV_CMD(DTV_VOLTAGE, 1, 0), |
| 986 | _DTV_CMD(DTV_TONE, 1, 0), |
| 987 | _DTV_CMD(DTV_PILOT, 1, 0), |
| 988 | _DTV_CMD(DTV_ROLLOFF, 1, 0), |
| 989 | _DTV_CMD(DTV_DELIVERY_SYSTEM, 1, 0), |
| 990 | _DTV_CMD(DTV_HIERARCHY, 1, 0), |
| 991 | _DTV_CMD(DTV_CODE_RATE_HP, 1, 0), |
| 992 | _DTV_CMD(DTV_CODE_RATE_LP, 1, 0), |
| 993 | _DTV_CMD(DTV_GUARD_INTERVAL, 1, 0), |
| 994 | _DTV_CMD(DTV_TRANSMISSION_MODE, 1, 0), |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 995 | |
| 996 | _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 1, 0), |
| 997 | _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 1, 0), |
| 998 | _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 1, 0), |
| 999 | _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 1, 0), |
| 1000 | _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 1, 0), |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1001 | _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 1, 0), |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1002 | _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 1, 0), |
| 1003 | _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 1, 0), |
| 1004 | _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 1, 0), |
| 1005 | _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 1, 0), |
| 1006 | _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 1, 0), |
| 1007 | _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 1, 0), |
| 1008 | _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 1, 0), |
| 1009 | _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 1, 0), |
| 1010 | _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 1, 0), |
| 1011 | _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 1, 0), |
| 1012 | _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 1, 0), |
| 1013 | _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 1, 0), |
| 1014 | |
| 1015 | _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 0, 0), |
| 1016 | _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 0, 0), |
| 1017 | _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 0, 0), |
| 1018 | _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 0, 0), |
| 1019 | _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 0, 0), |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1020 | _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 0, 0), |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1021 | _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 0, 0), |
| 1022 | _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 0, 0), |
| 1023 | _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 0, 0), |
| 1024 | _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 0, 0), |
| 1025 | _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 0, 0), |
| 1026 | _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 0, 0), |
| 1027 | _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 0, 0), |
| 1028 | _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 0, 0), |
| 1029 | _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 0, 0), |
| 1030 | _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 0, 0), |
| 1031 | _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 0, 0), |
| 1032 | _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 0, 0), |
| 1033 | |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1034 | _DTV_CMD(DTV_ISDBS_TS_ID, 1, 0), |
Andreas Oberritter | ec05a64 | 2011-05-26 07:54:14 -0300 | [diff] [blame] | 1035 | _DTV_CMD(DTV_DVBT2_PLP_ID, 1, 0), |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1036 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1037 | /* Get */ |
Mauro Carvalho Chehab | 06d3a39 | 2009-10-23 20:09:42 -0300 | [diff] [blame] | 1038 | _DTV_CMD(DTV_DISEQC_SLAVE_REPLY, 0, 1), |
| 1039 | _DTV_CMD(DTV_API_VERSION, 0, 0), |
| 1040 | _DTV_CMD(DTV_CODE_RATE_HP, 0, 0), |
| 1041 | _DTV_CMD(DTV_CODE_RATE_LP, 0, 0), |
| 1042 | _DTV_CMD(DTV_GUARD_INTERVAL, 0, 0), |
| 1043 | _DTV_CMD(DTV_TRANSMISSION_MODE, 0, 0), |
| 1044 | _DTV_CMD(DTV_HIERARCHY, 0, 0), |
Manu Abraham | ba2780c | 2011-11-13 18:47:44 -0300 | [diff] [blame] | 1045 | |
| 1046 | _DTV_CMD(DTV_ENUM_DELSYS, 0, 0), |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1047 | }; |
| 1048 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1049 | static void dtv_property_dump(struct dtv_property *tvp) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1050 | { |
| 1051 | int i; |
| 1052 | |
Mauro Carvalho Chehab | 106ff9e | 2011-07-15 08:49:06 -0300 | [diff] [blame] | 1053 | if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) { |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1054 | printk(KERN_WARNING "%s: tvp.cmd = 0x%08x undefined\n", |
Darron Broad | 4aae8ef | 2008-10-03 11:50:00 -0300 | [diff] [blame] | 1055 | __func__, tvp->cmd); |
| 1056 | return; |
| 1057 | } |
| 1058 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1059 | dprintk("%s() tvp.cmd = 0x%08x (%s)\n" |
| 1060 | ,__func__ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1061 | ,tvp->cmd |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1062 | ,dtv_cmds[ tvp->cmd ].name); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1063 | |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1064 | if(dtv_cmds[ tvp->cmd ].buffer) { |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1065 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1066 | dprintk("%s() tvp.u.buffer.len = 0x%02x\n" |
| 1067 | ,__func__ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1068 | ,tvp->u.buffer.len); |
| 1069 | |
| 1070 | for(i = 0; i < tvp->u.buffer.len; i++) |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1071 | dprintk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n" |
| 1072 | ,__func__ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1073 | ,i |
| 1074 | ,tvp->u.buffer.data[i]); |
| 1075 | |
| 1076 | } else |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1077 | dprintk("%s() tvp.u.data = 0x%08x\n", __func__, tvp->u.data); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1078 | } |
| 1079 | |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1080 | /* Synchronise the legacy tuning parameters into the cache, so that demodulator |
| 1081 | * drivers can use a single set_frontend tuning function, regardless of whether |
| 1082 | * it's being used for the legacy or new API, reducing code and complexity. |
| 1083 | */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1084 | static int dtv_property_cache_sync(struct dvb_frontend *fe, |
| 1085 | struct dtv_frontend_properties *c, |
| 1086 | const struct dvb_frontend_parameters *p) |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1087 | { |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1088 | c->frequency = p->frequency; |
| 1089 | c->inversion = p->inversion; |
| 1090 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1091 | switch (dvbv3_type(c->delivery_system)) { |
| 1092 | case DVBV3_QPSK: |
| 1093 | dprintk("%s() Preparing QPSK req\n", __func__); |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1094 | c->symbol_rate = p->u.qpsk.symbol_rate; |
| 1095 | c->fec_inner = p->u.qpsk.fec_inner; |
| 1096 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1097 | case DVBV3_QAM: |
| 1098 | dprintk("%s() Preparing QAM req\n", __func__); |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1099 | c->symbol_rate = p->u.qam.symbol_rate; |
| 1100 | c->fec_inner = p->u.qam.fec_inner; |
| 1101 | c->modulation = p->u.qam.modulation; |
| 1102 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1103 | case DVBV3_OFDM: |
| 1104 | dprintk("%s() Preparing OFDM req\n", __func__); |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1105 | switch (p->u.ofdm.bandwidth) { |
| 1106 | case BANDWIDTH_10_MHZ: |
| 1107 | c->bandwidth_hz = 10000000; |
| 1108 | break; |
| 1109 | case BANDWIDTH_8_MHZ: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1110 | c->bandwidth_hz = 8000000; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1111 | break; |
| 1112 | case BANDWIDTH_7_MHZ: |
| 1113 | c->bandwidth_hz = 7000000; |
| 1114 | break; |
| 1115 | case BANDWIDTH_6_MHZ: |
| 1116 | c->bandwidth_hz = 6000000; |
| 1117 | break; |
| 1118 | case BANDWIDTH_5_MHZ: |
| 1119 | c->bandwidth_hz = 5000000; |
| 1120 | break; |
| 1121 | case BANDWIDTH_1_712_MHZ: |
| 1122 | c->bandwidth_hz = 1712000; |
| 1123 | break; |
| 1124 | case BANDWIDTH_AUTO: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1125 | c->bandwidth_hz = 0; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1126 | } |
| 1127 | |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1128 | c->code_rate_HP = p->u.ofdm.code_rate_HP; |
| 1129 | c->code_rate_LP = p->u.ofdm.code_rate_LP; |
| 1130 | c->modulation = p->u.ofdm.constellation; |
| 1131 | c->transmission_mode = p->u.ofdm.transmission_mode; |
| 1132 | c->guard_interval = p->u.ofdm.guard_interval; |
| 1133 | c->hierarchy = p->u.ofdm.hierarchy_information; |
| 1134 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1135 | case DVBV3_ATSC: |
| 1136 | dprintk("%s() Preparing ATSC req\n", __func__); |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1137 | c->modulation = p->u.vsb.modulation; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1138 | if ((c->modulation == VSB_8) || (c->modulation == VSB_16)) |
| 1139 | c->delivery_system = SYS_ATSC; |
| 1140 | else |
| 1141 | c->delivery_system = SYS_DVBC_ANNEX_B; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1142 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1143 | case DVBV3_UNKNOWN: |
| 1144 | printk(KERN_ERR |
| 1145 | "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n", |
| 1146 | __func__, c->delivery_system); |
| 1147 | return -EINVAL; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1148 | } |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1149 | |
| 1150 | return 0; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1151 | } |
| 1152 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1153 | /* Ensure the cached values are set correctly in the frontend |
| 1154 | * legacy tuning structures, for the advanced tuning API. |
| 1155 | */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1156 | static int dtv_property_legacy_params_sync(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1157 | struct dvb_frontend_parameters *p) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1158 | { |
Andreas Oberritter | 15cc2bb | 2011-05-08 20:03:35 -0300 | [diff] [blame] | 1159 | const struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1160 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1161 | p->frequency = c->frequency; |
| 1162 | p->inversion = c->inversion; |
| 1163 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1164 | switch (dvbv3_type(c->delivery_system)) { |
| 1165 | case DVBV3_UNKNOWN: |
| 1166 | printk(KERN_ERR |
| 1167 | "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n", |
| 1168 | __func__, c->delivery_system); |
| 1169 | return -EINVAL; |
| 1170 | case DVBV3_QPSK: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1171 | dprintk("%s() Preparing QPSK req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1172 | p->u.qpsk.symbol_rate = c->symbol_rate; |
| 1173 | p->u.qpsk.fec_inner = c->fec_inner; |
| 1174 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1175 | case DVBV3_QAM: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1176 | dprintk("%s() Preparing QAM req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1177 | p->u.qam.symbol_rate = c->symbol_rate; |
| 1178 | p->u.qam.fec_inner = c->fec_inner; |
| 1179 | p->u.qam.modulation = c->modulation; |
| 1180 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1181 | case DVBV3_OFDM: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1182 | dprintk("%s() Preparing OFDM req\n", __func__); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1183 | |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1184 | switch (c->bandwidth_hz) { |
| 1185 | case 10000000: |
| 1186 | p->u.ofdm.bandwidth = BANDWIDTH_10_MHZ; |
| 1187 | break; |
| 1188 | case 8000000: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1189 | p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1190 | break; |
| 1191 | case 7000000: |
| 1192 | p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ; |
| 1193 | break; |
| 1194 | case 6000000: |
| 1195 | p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ; |
| 1196 | break; |
| 1197 | case 5000000: |
| 1198 | p->u.ofdm.bandwidth = BANDWIDTH_5_MHZ; |
| 1199 | break; |
| 1200 | case 1712000: |
| 1201 | p->u.ofdm.bandwidth = BANDWIDTH_1_712_MHZ; |
| 1202 | break; |
| 1203 | case 0: |
| 1204 | default: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1205 | p->u.ofdm.bandwidth = BANDWIDTH_AUTO; |
Mauro Carvalho Chehab | 9a27e6a | 2012-01-01 16:11:11 -0300 | [diff] [blame] | 1206 | } |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1207 | p->u.ofdm.code_rate_HP = c->code_rate_HP; |
| 1208 | p->u.ofdm.code_rate_LP = c->code_rate_LP; |
| 1209 | p->u.ofdm.constellation = c->modulation; |
| 1210 | p->u.ofdm.transmission_mode = c->transmission_mode; |
| 1211 | p->u.ofdm.guard_interval = c->guard_interval; |
| 1212 | p->u.ofdm.hierarchy_information = c->hierarchy; |
| 1213 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1214 | case DVBV3_ATSC: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1215 | dprintk("%s() Preparing VSB req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1216 | p->u.vsb.modulation = c->modulation; |
| 1217 | break; |
| 1218 | } |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1219 | return 0; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1220 | } |
| 1221 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1222 | /** |
| 1223 | * dtv_get_frontend - calls a callback for retrieving DTV parameters |
| 1224 | * @fe: struct dvb_frontend pointer |
| 1225 | * @c: struct dtv_frontend_properties pointer (DVBv5 cache) |
| 1226 | * @p_out struct dvb_frontend_parameters pointer (DVBv3 FE struct) |
| 1227 | * |
| 1228 | * This routine calls either the DVBv3 or DVBv5 get_frontend call. |
| 1229 | * If c is not null, it will update the DVBv5 cache struct pointed by it. |
| 1230 | * If p_out is not null, it will update the DVBv3 params pointed by it. |
| 1231 | */ |
| 1232 | static int dtv_get_frontend(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1233 | struct dvb_frontend_parameters *p_out) |
| 1234 | { |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1235 | int r; |
| 1236 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1237 | if (fe->ops.get_frontend) { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1238 | r = fe->ops.get_frontend(fe); |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1239 | if (unlikely(r < 0)) |
| 1240 | return r; |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1241 | if (p_out) |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1242 | dtv_property_legacy_params_sync(fe, p_out); |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1246 | /* As everything is in cache, get_frontend fops are always supported */ |
Mauro Carvalho Chehab | b1e9a6501 | 2011-12-26 16:43:32 -0300 | [diff] [blame] | 1247 | return 0; |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1248 | } |
| 1249 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1250 | static int dvb_frontend_ioctl_legacy(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1251 | unsigned int cmd, void *parg); |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1252 | static int dvb_frontend_ioctl_properties(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1253 | unsigned int cmd, void *parg); |
| 1254 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1255 | static int dtv_property_process_get(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1256 | const struct dtv_frontend_properties *c, |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1257 | struct dtv_property *tvp, |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1258 | struct file *file) |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1259 | { |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1260 | int r, ncaps; |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1261 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1262 | switch(tvp->cmd) { |
Manu Abraham | ba2780c | 2011-11-13 18:47:44 -0300 | [diff] [blame] | 1263 | case DTV_ENUM_DELSYS: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1264 | ncaps = 0; |
| 1265 | while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) { |
| 1266 | tvp->u.buffer.data[ncaps] = fe->ops.delsys[ncaps]; |
| 1267 | ncaps++; |
| 1268 | } |
| 1269 | tvp->u.buffer.len = ncaps; |
Manu Abraham | ba2780c | 2011-11-13 18:47:44 -0300 | [diff] [blame] | 1270 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1271 | case DTV_FREQUENCY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1272 | tvp->u.data = c->frequency; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1273 | break; |
| 1274 | case DTV_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1275 | tvp->u.data = c->modulation; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1276 | break; |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1277 | case DTV_BANDWIDTH_HZ: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1278 | tvp->u.data = c->bandwidth_hz; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1279 | break; |
| 1280 | case DTV_INVERSION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1281 | tvp->u.data = c->inversion; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1282 | break; |
| 1283 | case DTV_SYMBOL_RATE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1284 | tvp->u.data = c->symbol_rate; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1285 | break; |
| 1286 | case DTV_INNER_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1287 | tvp->u.data = c->fec_inner; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1288 | break; |
| 1289 | case DTV_PILOT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1290 | tvp->u.data = c->pilot; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1291 | break; |
| 1292 | case DTV_ROLLOFF: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1293 | tvp->u.data = c->rolloff; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1294 | break; |
| 1295 | case DTV_DELIVERY_SYSTEM: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1296 | tvp->u.data = c->delivery_system; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1297 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1298 | case DTV_VOLTAGE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1299 | tvp->u.data = c->voltage; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1300 | break; |
| 1301 | case DTV_TONE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1302 | tvp->u.data = c->sectone; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1303 | break; |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 1304 | case DTV_API_VERSION: |
| 1305 | tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR; |
| 1306 | break; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1307 | case DTV_CODE_RATE_HP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1308 | tvp->u.data = c->code_rate_HP; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1309 | break; |
| 1310 | case DTV_CODE_RATE_LP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1311 | tvp->u.data = c->code_rate_LP; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1312 | break; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1313 | case DTV_GUARD_INTERVAL: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1314 | tvp->u.data = c->guard_interval; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1315 | break; |
| 1316 | case DTV_TRANSMISSION_MODE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1317 | tvp->u.data = c->transmission_mode; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1318 | break; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1319 | case DTV_HIERARCHY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1320 | tvp->u.data = c->hierarchy; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1321 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1322 | |
| 1323 | /* ISDB-T Support here */ |
| 1324 | case DTV_ISDBT_PARTIAL_RECEPTION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1325 | tvp->u.data = c->isdbt_partial_reception; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1326 | break; |
| 1327 | case DTV_ISDBT_SOUND_BROADCASTING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1328 | tvp->u.data = c->isdbt_sb_mode; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1329 | break; |
| 1330 | case DTV_ISDBT_SB_SUBCHANNEL_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1331 | tvp->u.data = c->isdbt_sb_subchannel; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1332 | break; |
| 1333 | case DTV_ISDBT_SB_SEGMENT_IDX: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1334 | tvp->u.data = c->isdbt_sb_segment_idx; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1335 | break; |
| 1336 | case DTV_ISDBT_SB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1337 | tvp->u.data = c->isdbt_sb_segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1338 | break; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1339 | case DTV_ISDBT_LAYER_ENABLED: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1340 | tvp->u.data = c->isdbt_layer_enabled; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1341 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1342 | case DTV_ISDBT_LAYERA_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1343 | tvp->u.data = c->layer[0].fec; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1344 | break; |
| 1345 | case DTV_ISDBT_LAYERA_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1346 | tvp->u.data = c->layer[0].modulation; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1347 | break; |
| 1348 | case DTV_ISDBT_LAYERA_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1349 | tvp->u.data = c->layer[0].segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1350 | break; |
| 1351 | case DTV_ISDBT_LAYERA_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1352 | tvp->u.data = c->layer[0].interleaving; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1353 | break; |
| 1354 | case DTV_ISDBT_LAYERB_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1355 | tvp->u.data = c->layer[1].fec; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1356 | break; |
| 1357 | case DTV_ISDBT_LAYERB_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1358 | tvp->u.data = c->layer[1].modulation; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1359 | break; |
| 1360 | case DTV_ISDBT_LAYERB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1361 | tvp->u.data = c->layer[1].segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1362 | break; |
| 1363 | case DTV_ISDBT_LAYERB_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1364 | tvp->u.data = c->layer[1].interleaving; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1365 | break; |
| 1366 | case DTV_ISDBT_LAYERC_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1367 | tvp->u.data = c->layer[2].fec; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1368 | break; |
| 1369 | case DTV_ISDBT_LAYERC_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1370 | tvp->u.data = c->layer[2].modulation; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1371 | break; |
| 1372 | case DTV_ISDBT_LAYERC_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1373 | tvp->u.data = c->layer[2].segment_count; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1374 | break; |
| 1375 | case DTV_ISDBT_LAYERC_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1376 | tvp->u.data = c->layer[2].interleaving; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1377 | break; |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1378 | case DTV_ISDBS_TS_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1379 | tvp->u.data = c->isdbs_ts_id; |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1380 | break; |
Andreas Oberritter | 94d56ff | 2011-05-12 18:11:06 -0300 | [diff] [blame] | 1381 | case DTV_DVBT2_PLP_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1382 | tvp->u.data = c->dvbt2_plp_id; |
Andreas Oberritter | 94d56ff | 2011-05-12 18:11:06 -0300 | [diff] [blame] | 1383 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1384 | default: |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1385 | return -EINVAL; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1386 | } |
| 1387 | |
Andreas Oberritter | e23d9ae | 2011-05-08 20:03:36 -0300 | [diff] [blame] | 1388 | /* Allow the frontend to override outgoing properties */ |
| 1389 | if (fe->ops.get_property) { |
| 1390 | r = fe->ops.get_property(fe, tvp); |
| 1391 | if (r < 0) |
| 1392 | return r; |
| 1393 | } |
| 1394 | |
Mauro Carvalho Chehab | 639544d | 2009-12-31 17:49:32 -0300 | [diff] [blame] | 1395 | dtv_property_dump(tvp); |
| 1396 | |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1397 | return 0; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1398 | } |
| 1399 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1400 | static int dtv_set_frontend(struct dvb_frontend *fe); |
| 1401 | |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1402 | static bool is_dvbv3_delsys(u32 delsys) |
| 1403 | { |
| 1404 | bool status; |
| 1405 | |
| 1406 | status = (delsys == SYS_DVBT) || (delsys == SYS_DVBC_ANNEX_A) || |
| 1407 | (delsys == SYS_DVBS) || (delsys == SYS_ATSC); |
| 1408 | |
| 1409 | return status; |
| 1410 | } |
| 1411 | |
| 1412 | static int set_delivery_system(struct dvb_frontend *fe, u32 desired_system) |
| 1413 | { |
| 1414 | int ncaps, i; |
| 1415 | u32 delsys = SYS_UNDEFINED; |
| 1416 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1417 | enum dvbv3_emulation_type type; |
| 1418 | |
Mauro Carvalho Chehab | f4b1952 | 2012-01-13 11:09:23 -0200 | [diff] [blame] | 1419 | /* |
| 1420 | * It was reported that some old DVBv5 applications were |
| 1421 | * filling delivery_system with SYS_UNDEFINED. If this happens, |
| 1422 | * assume that the application wants to use the first supported |
| 1423 | * delivery system. |
| 1424 | */ |
| 1425 | if (c->delivery_system == SYS_UNDEFINED) |
| 1426 | c->delivery_system = fe->ops.delsys[0]; |
| 1427 | |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1428 | if (desired_system == SYS_UNDEFINED) { |
| 1429 | /* |
| 1430 | * A DVBv3 call doesn't know what's the desired system. |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1431 | * Also, DVBv3 applications don't know that ops.info->type |
| 1432 | * could be changed, and they simply dies when it doesn't |
| 1433 | * match. |
| 1434 | * So, don't change the current delivery system, as it |
| 1435 | * may be trying to do the wrong thing, like setting an |
| 1436 | * ISDB-T frontend as DVB-T. Instead, find the closest |
| 1437 | * DVBv3 system that matches the delivery system. |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1438 | */ |
| 1439 | if (is_dvbv3_delsys(c->delivery_system)) { |
| 1440 | dprintk("%s() Using delivery system to %d\n", |
| 1441 | __func__, c->delivery_system); |
| 1442 | return 0; |
| 1443 | } |
| 1444 | type = dvbv3_type(c->delivery_system); |
| 1445 | switch (type) { |
| 1446 | case DVBV3_QPSK: |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1447 | desired_system = SYS_DVBS; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1448 | break; |
| 1449 | case DVBV3_QAM: |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1450 | desired_system = SYS_DVBC_ANNEX_A; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1451 | break; |
| 1452 | case DVBV3_ATSC: |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1453 | desired_system = SYS_ATSC; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1454 | break; |
| 1455 | case DVBV3_OFDM: |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1456 | desired_system = SYS_DVBT; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1457 | break; |
| 1458 | default: |
| 1459 | dprintk("%s(): This frontend doesn't support DVBv3 calls\n", |
| 1460 | __func__); |
| 1461 | return -EINVAL; |
| 1462 | } |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1463 | } else { |
| 1464 | /* |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1465 | * This is a DVBv5 call. So, it likely knows the supported |
| 1466 | * delivery systems. |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1467 | */ |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1468 | |
| 1469 | /* Check if the desired delivery system is supported */ |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1470 | ncaps = 0; |
| 1471 | while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) { |
| 1472 | if (fe->ops.delsys[ncaps] == desired_system) { |
| 1473 | c->delivery_system = desired_system; |
| 1474 | dprintk("%s() Changing delivery system to %d\n", |
| 1475 | __func__, desired_system); |
| 1476 | return 0; |
| 1477 | } |
Mauro Carvalho Chehab | 6c4b78c | 2012-01-05 11:24:41 -0200 | [diff] [blame] | 1478 | ncaps++; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1479 | } |
| 1480 | type = dvbv3_type(desired_system); |
| 1481 | |
| 1482 | /* |
| 1483 | * The delivery system is not supported. See if it can be |
| 1484 | * emulated. |
| 1485 | * The emulation only works if the desired system is one of the |
| 1486 | * DVBv3 delivery systems |
| 1487 | */ |
| 1488 | if (!is_dvbv3_delsys(desired_system)) { |
| 1489 | dprintk("%s() can't use a DVBv3 FE_SET_FRONTEND call on this frontend\n", |
| 1490 | __func__); |
| 1491 | return -EINVAL; |
| 1492 | } |
| 1493 | |
| 1494 | /* |
| 1495 | * Get the last non-DVBv3 delivery system that has the same type |
| 1496 | * of the desired system |
| 1497 | */ |
| 1498 | ncaps = 0; |
| 1499 | while (fe->ops.delsys[ncaps] && ncaps < MAX_DELSYS) { |
| 1500 | if ((dvbv3_type(fe->ops.delsys[ncaps]) == type) && |
| 1501 | !is_dvbv3_delsys(fe->ops.delsys[ncaps])) |
| 1502 | delsys = fe->ops.delsys[ncaps]; |
| 1503 | ncaps++; |
| 1504 | } |
| 1505 | /* There's nothing compatible with the desired delivery system */ |
| 1506 | if (delsys == SYS_UNDEFINED) { |
| 1507 | dprintk("%s() Incompatible DVBv3 FE_SET_FRONTEND call for this frontend\n", |
| 1508 | __func__); |
| 1509 | return -EINVAL; |
| 1510 | } |
| 1511 | c->delivery_system = delsys; |
| 1512 | } |
| 1513 | |
| 1514 | /* |
Mauro Carvalho Chehab | 37fa53c | 2012-01-05 14:39:05 -0200 | [diff] [blame] | 1515 | * The DVBv3 or DVBv5 call is requesting a different system. So, |
| 1516 | * emulation is needed. |
| 1517 | * |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1518 | * Emulate newer delivery systems like ISDBT, DVBT and DMBTH |
| 1519 | * for older DVBv5 applications. The emulation will try to use |
| 1520 | * the auto mode for most things, and will assume that the desired |
| 1521 | * delivery system is the last one at the ops.delsys[] array |
| 1522 | */ |
| 1523 | dprintk("%s() Using delivery system %d emulated as if it were a %d\n", |
| 1524 | __func__, delsys, desired_system); |
| 1525 | |
| 1526 | /* |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 1527 | * For now, handles ISDB-T calls. More code may be needed here for the |
| 1528 | * other emulated stuff |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1529 | */ |
| 1530 | if (type == DVBV3_OFDM) { |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 1531 | if (c->delivery_system == SYS_ISDBT) { |
| 1532 | dprintk("%s() Using defaults for SYS_ISDBT\n", |
| 1533 | __func__); |
| 1534 | if (!c->bandwidth_hz) |
| 1535 | c->bandwidth_hz = 6000000; |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1536 | |
Mauro Carvalho Chehab | a520ca9 | 2012-01-01 16:11:15 -0300 | [diff] [blame] | 1537 | c->isdbt_partial_reception = 0; |
| 1538 | c->isdbt_sb_mode = 0; |
| 1539 | c->isdbt_sb_subchannel = 0; |
| 1540 | c->isdbt_sb_segment_idx = 0; |
| 1541 | c->isdbt_sb_segment_count = 0; |
| 1542 | c->isdbt_layer_enabled = 0; |
| 1543 | for (i = 0; i < 3; i++) { |
| 1544 | c->layer[i].fec = FEC_AUTO; |
| 1545 | c->layer[i].modulation = QAM_AUTO; |
| 1546 | c->layer[i].interleaving = 0; |
| 1547 | c->layer[i].segment_count = 0; |
| 1548 | } |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1549 | } |
| 1550 | } |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1551 | dprintk("change delivery system on cache to %d\n", c->delivery_system); |
| 1552 | |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1553 | return 0; |
| 1554 | } |
| 1555 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1556 | static int dtv_property_process_set(struct dvb_frontend *fe, |
| 1557 | struct dtv_property *tvp, |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1558 | struct file *file) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1559 | { |
| 1560 | int r = 0; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1561 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1562 | |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1563 | /* Allow the frontend to validate incoming properties */ |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1564 | if (fe->ops.set_property) { |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1565 | r = fe->ops.set_property(fe, tvp); |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1566 | if (r < 0) |
| 1567 | return r; |
| 1568 | } |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1569 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1570 | switch(tvp->cmd) { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1571 | case DTV_CLEAR: |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1572 | /* |
| 1573 | * Reset a cache of data specific to the frontend here. This does |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1574 | * not effect hardware. |
| 1575 | */ |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1576 | dvb_frontend_clear_cache(fe); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1577 | break; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1578 | case DTV_TUNE: |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1579 | /* interpret the cache of data, build either a traditional frontend |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1580 | * tunerequest so we can pass validation in the FE_SET_FRONTEND |
| 1581 | * ioctl. |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1582 | */ |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1583 | c->state = tvp->cmd; |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1584 | dprintk("%s() Finalised property cache\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1585 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1586 | r = dtv_set_frontend(fe); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1587 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1588 | case DTV_FREQUENCY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1589 | c->frequency = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1590 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1591 | case DTV_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1592 | c->modulation = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1593 | break; |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1594 | case DTV_BANDWIDTH_HZ: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1595 | c->bandwidth_hz = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1596 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1597 | case DTV_INVERSION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1598 | c->inversion = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1599 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1600 | case DTV_SYMBOL_RATE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1601 | c->symbol_rate = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1602 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1603 | case DTV_INNER_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1604 | c->fec_inner = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1605 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1606 | case DTV_PILOT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1607 | c->pilot = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1608 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1609 | case DTV_ROLLOFF: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1610 | c->rolloff = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1611 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1612 | case DTV_DELIVERY_SYSTEM: |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 1613 | r = set_delivery_system(fe, tvp->u.data); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1614 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1615 | case DTV_VOLTAGE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1616 | c->voltage = tvp->u.data; |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1617 | r = dvb_frontend_ioctl_legacy(file, FE_SET_VOLTAGE, |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1618 | (void *)c->voltage); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1619 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1620 | case DTV_TONE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1621 | c->sectone = tvp->u.data; |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1622 | r = dvb_frontend_ioctl_legacy(file, FE_SET_TONE, |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1623 | (void *)c->sectone); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1624 | break; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1625 | case DTV_CODE_RATE_HP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1626 | c->code_rate_HP = tvp->u.data; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1627 | break; |
| 1628 | case DTV_CODE_RATE_LP: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1629 | c->code_rate_LP = tvp->u.data; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1630 | break; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1631 | case DTV_GUARD_INTERVAL: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1632 | c->guard_interval = tvp->u.data; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1633 | break; |
| 1634 | case DTV_TRANSMISSION_MODE: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1635 | c->transmission_mode = tvp->u.data; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1636 | break; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1637 | case DTV_HIERARCHY: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1638 | c->hierarchy = tvp->u.data; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1639 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1640 | |
| 1641 | /* ISDB-T Support here */ |
| 1642 | case DTV_ISDBT_PARTIAL_RECEPTION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1643 | c->isdbt_partial_reception = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1644 | break; |
| 1645 | case DTV_ISDBT_SOUND_BROADCASTING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1646 | c->isdbt_sb_mode = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1647 | break; |
| 1648 | case DTV_ISDBT_SB_SUBCHANNEL_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1649 | c->isdbt_sb_subchannel = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1650 | break; |
| 1651 | case DTV_ISDBT_SB_SEGMENT_IDX: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1652 | c->isdbt_sb_segment_idx = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1653 | break; |
| 1654 | case DTV_ISDBT_SB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1655 | c->isdbt_sb_segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1656 | break; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1657 | case DTV_ISDBT_LAYER_ENABLED: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1658 | c->isdbt_layer_enabled = tvp->u.data; |
Patrick Boettcher | e7b7949 | 2009-08-14 05:24:19 -0300 | [diff] [blame] | 1659 | break; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1660 | case DTV_ISDBT_LAYERA_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1661 | c->layer[0].fec = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1662 | break; |
| 1663 | case DTV_ISDBT_LAYERA_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1664 | c->layer[0].modulation = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1665 | break; |
| 1666 | case DTV_ISDBT_LAYERA_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1667 | c->layer[0].segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1668 | break; |
| 1669 | case DTV_ISDBT_LAYERA_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1670 | c->layer[0].interleaving = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1671 | break; |
| 1672 | case DTV_ISDBT_LAYERB_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1673 | c->layer[1].fec = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1674 | break; |
| 1675 | case DTV_ISDBT_LAYERB_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1676 | c->layer[1].modulation = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1677 | break; |
| 1678 | case DTV_ISDBT_LAYERB_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1679 | c->layer[1].segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1680 | break; |
| 1681 | case DTV_ISDBT_LAYERB_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1682 | c->layer[1].interleaving = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1683 | break; |
| 1684 | case DTV_ISDBT_LAYERC_FEC: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1685 | c->layer[2].fec = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1686 | break; |
| 1687 | case DTV_ISDBT_LAYERC_MODULATION: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1688 | c->layer[2].modulation = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1689 | break; |
| 1690 | case DTV_ISDBT_LAYERC_SEGMENT_COUNT: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1691 | c->layer[2].segment_count = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1692 | break; |
| 1693 | case DTV_ISDBT_LAYERC_TIME_INTERLEAVING: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1694 | c->layer[2].interleaving = tvp->u.data; |
Patrick Boettcher | b6e760f | 2009-08-03 14:39:15 -0300 | [diff] [blame] | 1695 | break; |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1696 | case DTV_ISDBS_TS_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1697 | c->isdbs_ts_id = tvp->u.data; |
HIRANO Takahito | 98293ef | 2009-09-18 11:17:54 -0300 | [diff] [blame] | 1698 | break; |
Andreas Oberritter | 94d56ff | 2011-05-12 18:11:06 -0300 | [diff] [blame] | 1699 | case DTV_DVBT2_PLP_ID: |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1700 | c->dvbt2_plp_id = tvp->u.data; |
Andreas Oberritter | 94d56ff | 2011-05-12 18:11:06 -0300 | [diff] [blame] | 1701 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1702 | default: |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1703 | return -EINVAL; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1704 | } |
| 1705 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1706 | return r; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1707 | } |
| 1708 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1709 | static int dvb_frontend_ioctl(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | unsigned int cmd, void *parg) |
| 1711 | { |
| 1712 | struct dvb_device *dvbdev = file->private_data; |
| 1713 | struct dvb_frontend *fe = dvbdev->priv; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1714 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1715 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | int err = -EOPNOTSUPP; |
| 1717 | |
Mauro Carvalho Chehab | fb8253b | 2009-12-31 18:14:54 -0300 | [diff] [blame] | 1718 | dprintk("%s (%d)\n", __func__, _IOC_NR(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 1720 | if (fepriv->exit != DVB_FE_NO_EXIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | return -ENODEV; |
| 1722 | |
| 1723 | if ((file->f_flags & O_ACCMODE) == O_RDONLY && |
| 1724 | (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT || |
| 1725 | cmd == FE_DISEQC_RECV_SLAVE_REPLY)) |
| 1726 | return -EPERM; |
| 1727 | |
| 1728 | if (down_interruptible (&fepriv->sem)) |
| 1729 | return -ERESTARTSYS; |
| 1730 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1731 | if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY)) |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1732 | err = dvb_frontend_ioctl_properties(file, cmd, parg); |
Steven Toth | 4dd88be | 2008-09-13 15:09:07 -0300 | [diff] [blame] | 1733 | else { |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1734 | c->state = DTV_UNDEFINED; |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1735 | err = dvb_frontend_ioctl_legacy(file, cmd, parg); |
Steven Toth | 4dd88be | 2008-09-13 15:09:07 -0300 | [diff] [blame] | 1736 | } |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1737 | |
| 1738 | up(&fepriv->sem); |
| 1739 | return err; |
| 1740 | } |
| 1741 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1742 | static int dvb_frontend_ioctl_properties(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1743 | unsigned int cmd, void *parg) |
| 1744 | { |
| 1745 | struct dvb_device *dvbdev = file->private_data; |
| 1746 | struct dvb_frontend *fe = dvbdev->priv; |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1747 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Igor M. Liplianin | e6f9ec8 | 2008-09-12 14:49:06 -0300 | [diff] [blame] | 1748 | int err = 0; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1749 | |
| 1750 | struct dtv_properties *tvps = NULL; |
| 1751 | struct dtv_property *tvp = NULL; |
| 1752 | int i; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1753 | |
| 1754 | dprintk("%s\n", __func__); |
| 1755 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1756 | if(cmd == FE_SET_PROPERTY) { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1757 | tvps = (struct dtv_properties __user *)parg; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1758 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1759 | dprintk("%s() properties.num = %d\n", __func__, tvps->num); |
| 1760 | dprintk("%s() properties.props = %p\n", __func__, tvps->props); |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1761 | |
| 1762 | /* Put an arbitrary limit on the number of messages that can |
| 1763 | * be sent at once */ |
Steven Toth | 6068f50 | 2008-10-06 22:46:08 -0300 | [diff] [blame] | 1764 | if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1765 | return -EINVAL; |
| 1766 | |
Thiago Farina | 6e3924a | 2010-01-16 10:25:38 -0300 | [diff] [blame] | 1767 | tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL); |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1768 | if (!tvp) { |
| 1769 | err = -ENOMEM; |
| 1770 | goto out; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1771 | } |
| 1772 | |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1773 | if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) { |
| 1774 | err = -EFAULT; |
| 1775 | goto out; |
| 1776 | } |
| 1777 | |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 1778 | for (i = 0; i < tvps->num; i++) { |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1779 | err = dtv_property_process_set(fe, tvp + i, file); |
| 1780 | if (err < 0) |
| 1781 | goto out; |
| 1782 | (tvp + i)->result = err; |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 1783 | } |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1784 | |
Andreas Oberritter | 5072771 | 2011-05-08 20:03:39 -0300 | [diff] [blame] | 1785 | if (c->state == DTV_TUNE) |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1786 | dprintk("%s() Property cache is full, tuning\n", __func__); |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1787 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1788 | } else |
| 1789 | if(cmd == FE_GET_PROPERTY) { |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1790 | tvps = (struct dtv_properties __user *)parg; |
| 1791 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1792 | dprintk("%s() properties.num = %d\n", __func__, tvps->num); |
| 1793 | dprintk("%s() properties.props = %p\n", __func__, tvps->props); |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1794 | |
| 1795 | /* Put an arbitrary limit on the number of messages that can |
| 1796 | * be sent at once */ |
Steven Toth | 6068f50 | 2008-10-06 22:46:08 -0300 | [diff] [blame] | 1797 | if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1798 | return -EINVAL; |
| 1799 | |
Thiago Farina | 6e3924a | 2010-01-16 10:25:38 -0300 | [diff] [blame] | 1800 | tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL); |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1801 | if (!tvp) { |
| 1802 | err = -ENOMEM; |
| 1803 | goto out; |
| 1804 | } |
| 1805 | |
| 1806 | if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) { |
| 1807 | err = -EFAULT; |
| 1808 | goto out; |
| 1809 | } |
| 1810 | |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1811 | /* |
| 1812 | * Fills the cache out struct with the cache contents, plus |
Mauro Carvalho Chehab | b1e9a6501 | 2011-12-26 16:43:32 -0300 | [diff] [blame] | 1813 | * the data retrieved from get_frontend. |
Mauro Carvalho Chehab | a689e36 | 2011-12-22 14:47:48 -0300 | [diff] [blame] | 1814 | */ |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1815 | dtv_get_frontend(fe, NULL); |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 1816 | for (i = 0; i < tvps->num; i++) { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 1817 | err = dtv_property_process_get(fe, c, tvp + i, file); |
Andreas Oberritter | aff8ab5 | 2011-05-09 00:03:34 +0100 | [diff] [blame] | 1818 | if (err < 0) |
| 1819 | goto out; |
| 1820 | (tvp + i)->result = err; |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 1821 | } |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1822 | |
| 1823 | if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) { |
| 1824 | err = -EFAULT; |
| 1825 | goto out; |
| 1826 | } |
| 1827 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1828 | } else |
| 1829 | err = -EOPNOTSUPP; |
| 1830 | |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1831 | out: |
| 1832 | kfree(tvp); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1833 | return err; |
| 1834 | } |
| 1835 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1836 | static int dtv_set_frontend(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1837 | { |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1838 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 1839 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1840 | struct dvb_frontend_tune_settings fetunesettings; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1841 | u32 rolloff = 0; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1842 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1843 | if (dvb_frontend_check_parameters(fe) < 0) |
| 1844 | return -EINVAL; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1845 | |
| 1846 | /* |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1847 | * Be sure that the bandwidth will be filled for all |
| 1848 | * non-satellite systems, as tuners need to know what |
| 1849 | * low pass/Nyquist half filter should be applied, in |
| 1850 | * order to avoid inter-channel noise. |
| 1851 | * |
| 1852 | * ISDB-T and DVB-T/T2 already sets bandwidth. |
| 1853 | * ATSC and DVB-C don't set, so, the core should fill it. |
| 1854 | * |
| 1855 | * On DVB-C Annex A and C, the bandwidth is a function of |
| 1856 | * the roll-off and symbol rate. Annex B defines different |
| 1857 | * roll-off factors depending on the modulation. Fortunately, |
| 1858 | * Annex B is only used with 6MHz, so there's no need to |
| 1859 | * calculate it. |
| 1860 | * |
| 1861 | * While not officially supported, a side effect of handling it at |
| 1862 | * the cache level is that a program could retrieve the bandwidth |
| 1863 | * via DTV_BANDWIDTH_HZ, which may be useful for test programs. |
| 1864 | */ |
| 1865 | switch (c->delivery_system) { |
| 1866 | case SYS_ATSC: |
| 1867 | case SYS_DVBC_ANNEX_B: |
| 1868 | c->bandwidth_hz = 6000000; |
| 1869 | break; |
| 1870 | case SYS_DVBC_ANNEX_A: |
| 1871 | rolloff = 115; |
| 1872 | break; |
| 1873 | case SYS_DVBC_ANNEX_C: |
| 1874 | rolloff = 113; |
| 1875 | break; |
| 1876 | default: |
| 1877 | break; |
| 1878 | } |
| 1879 | if (rolloff) |
| 1880 | c->bandwidth_hz = (c->symbol_rate * rolloff) / 100; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1881 | |
| 1882 | /* force auto frequency inversion if requested */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1883 | if (dvb_force_auto_inversion) |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1884 | c->inversion = INVERSION_AUTO; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1885 | |
| 1886 | /* |
| 1887 | * without hierarchical coding code_rate_LP is irrelevant, |
| 1888 | * so we tolerate the otherwise invalid FEC_NONE setting |
| 1889 | */ |
| 1890 | if (c->hierarchy == HIERARCHY_NONE && c->code_rate_LP == FEC_NONE) |
| 1891 | c->code_rate_LP = FEC_AUTO; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1892 | |
| 1893 | /* get frontend-specific tuning settings */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1894 | memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings)); |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1895 | if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) { |
| 1896 | fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000; |
| 1897 | fepriv->max_drift = fetunesettings.max_drift; |
| 1898 | fepriv->step_size = fetunesettings.step_size; |
| 1899 | } else { |
| 1900 | /* default values */ |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1901 | switch (c->delivery_system) { |
| 1902 | case SYS_DVBC_ANNEX_A: |
| 1903 | case SYS_DVBC_ANNEX_C: |
| 1904 | fepriv->min_delay = HZ / 20; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1905 | fepriv->step_size = c->symbol_rate / 16000; |
| 1906 | fepriv->max_drift = c->symbol_rate / 2000; |
| 1907 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1908 | case SYS_DVBT: |
| 1909 | case SYS_DVBT2: |
| 1910 | case SYS_ISDBT: |
| 1911 | case SYS_DMBTH: |
| 1912 | fepriv->min_delay = HZ / 20; |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1913 | fepriv->step_size = fe->ops.info.frequency_stepsize * 2; |
| 1914 | fepriv->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1; |
| 1915 | break; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1916 | default: |
| 1917 | /* |
| 1918 | * FIXME: This sounds wrong! if freqency_stepsize is |
| 1919 | * defined by the frontend, why not use it??? |
| 1920 | */ |
| 1921 | fepriv->min_delay = HZ / 20; |
| 1922 | fepriv->step_size = 0; /* no zigzag */ |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 1923 | fepriv->max_drift = 0; |
| 1924 | break; |
| 1925 | } |
| 1926 | } |
| 1927 | if (dvb_override_tune_delay > 0) |
| 1928 | fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000; |
| 1929 | |
| 1930 | fepriv->state = FESTATE_RETUNE; |
| 1931 | |
| 1932 | /* Request the search algorithm to search */ |
| 1933 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 1934 | |
| 1935 | dvb_frontend_clear_events(fe); |
| 1936 | dvb_frontend_add_event(fe, 0); |
| 1937 | dvb_frontend_wakeup(fe); |
| 1938 | fepriv->status = 0; |
| 1939 | |
| 1940 | return 0; |
| 1941 | } |
| 1942 | |
| 1943 | |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 1944 | static int dvb_frontend_ioctl_legacy(struct file *file, |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1945 | unsigned int cmd, void *parg) |
| 1946 | { |
| 1947 | struct dvb_device *dvbdev = file->private_data; |
| 1948 | struct dvb_frontend *fe = dvbdev->priv; |
| 1949 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1950 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Michael Krufky | 9133aee | 2009-05-23 18:00:59 -0300 | [diff] [blame] | 1951 | int cb_err, err = -EOPNOTSUPP; |
| 1952 | |
| 1953 | if (fe->dvb->fe_ioctl_override) { |
| 1954 | cb_err = fe->dvb->fe_ioctl_override(fe, cmd, parg, |
| 1955 | DVB_FE_IOCTL_PRE); |
| 1956 | if (cb_err < 0) |
| 1957 | return cb_err; |
| 1958 | if (cb_err > 0) |
| 1959 | return 0; |
| 1960 | /* fe_ioctl_override returning 0 allows |
| 1961 | * dvb-core to continue handling the ioctl */ |
| 1962 | } |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | switch (cmd) { |
| 1965 | case FE_GET_INFO: { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1966 | struct dvb_frontend_info* info = parg; |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1967 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1968 | memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info)); |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 1969 | dvb_frontend_get_frequency_limits(fe, &info->frequency_min, &info->frequency_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1971 | /* |
| 1972 | * Associate the 4 delivery systems supported by DVBv3 |
| 1973 | * API with their DVBv5 counterpart. For the other standards, |
| 1974 | * use the closest type, assuming that it would hopefully |
| 1975 | * work with a DVBv3 application. |
| 1976 | * It should be noticed that, on multi-frontend devices with |
| 1977 | * different types (terrestrial and cable, for example), |
| 1978 | * a pure DVBv3 application won't be able to use all delivery |
| 1979 | * systems. Yet, changing the DVBv5 cache to the other delivery |
| 1980 | * system should be enough for making it work. |
| 1981 | */ |
| 1982 | switch (dvbv3_type(c->delivery_system)) { |
| 1983 | case DVBV3_QPSK: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1984 | info->type = FE_QPSK; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1985 | break; |
| 1986 | case DVBV3_ATSC: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1987 | info->type = FE_ATSC; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1988 | break; |
| 1989 | case DVBV3_QAM: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1990 | info->type = FE_QAM; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1991 | break; |
| 1992 | case DVBV3_OFDM: |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 1993 | info->type = FE_OFDM; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 1994 | break; |
| 1995 | default: |
| 1996 | printk(KERN_ERR |
| 1997 | "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n", |
| 1998 | __func__, c->delivery_system); |
| 1999 | fe->ops.info.type = FE_OFDM; |
| 2000 | } |
Mauro Carvalho Chehab | 9474c5e | 2012-01-05 12:28:20 -0200 | [diff] [blame] | 2001 | dprintk("current delivery system on cache: %d, V3 type: %d\n", |
| 2002 | c->delivery_system, fe->ops.info.type); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't |
| 2005 | * do it, it is done for it. */ |
| 2006 | info->caps |= FE_CAN_INVERSION_AUTO; |
| 2007 | err = 0; |
| 2008 | break; |
| 2009 | } |
| 2010 | |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2011 | case FE_READ_STATUS: { |
| 2012 | fe_status_t* status = parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2014 | /* if retune was requested but hasn't occurred yet, prevent |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2015 | * that user get signal state from previous tuning */ |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 2016 | if (fepriv->state == FESTATE_RETUNE || |
| 2017 | fepriv->state == FESTATE_ERROR) { |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2018 | err=0; |
| 2019 | *status = 0; |
| 2020 | break; |
| 2021 | } |
| 2022 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2023 | if (fe->ops.read_status) |
| 2024 | err = fe->ops.read_status(fe, status); |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 2025 | break; |
| 2026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | case FE_READ_BER: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2028 | if (fe->ops.read_ber) |
| 2029 | err = fe->ops.read_ber(fe, (__u32*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | break; |
| 2031 | |
| 2032 | case FE_READ_SIGNAL_STRENGTH: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2033 | if (fe->ops.read_signal_strength) |
| 2034 | err = fe->ops.read_signal_strength(fe, (__u16*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | break; |
| 2036 | |
| 2037 | case FE_READ_SNR: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2038 | if (fe->ops.read_snr) |
| 2039 | err = fe->ops.read_snr(fe, (__u16*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | break; |
| 2041 | |
| 2042 | case FE_READ_UNCORRECTED_BLOCKS: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2043 | if (fe->ops.read_ucblocks) |
| 2044 | err = fe->ops.read_ucblocks(fe, (__u32*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | break; |
| 2046 | |
| 2047 | |
| 2048 | case FE_DISEQC_RESET_OVERLOAD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2049 | if (fe->ops.diseqc_reset_overload) { |
| 2050 | err = fe->ops.diseqc_reset_overload(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | fepriv->state = FESTATE_DISEQC; |
| 2052 | fepriv->status = 0; |
| 2053 | } |
| 2054 | break; |
| 2055 | |
| 2056 | case FE_DISEQC_SEND_MASTER_CMD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2057 | if (fe->ops.diseqc_send_master_cmd) { |
| 2058 | err = fe->ops.diseqc_send_master_cmd(fe, (struct dvb_diseqc_master_cmd*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | fepriv->state = FESTATE_DISEQC; |
| 2060 | fepriv->status = 0; |
| 2061 | } |
| 2062 | break; |
| 2063 | |
| 2064 | case FE_DISEQC_SEND_BURST: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2065 | if (fe->ops.diseqc_send_burst) { |
| 2066 | err = fe->ops.diseqc_send_burst(fe, (fe_sec_mini_cmd_t) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | fepriv->state = FESTATE_DISEQC; |
| 2068 | fepriv->status = 0; |
| 2069 | } |
| 2070 | break; |
| 2071 | |
| 2072 | case FE_SET_TONE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2073 | if (fe->ops.set_tone) { |
| 2074 | err = fe->ops.set_tone(fe, (fe_sec_tone_mode_t) parg); |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 2075 | fepriv->tone = (fe_sec_tone_mode_t) parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | fepriv->state = FESTATE_DISEQC; |
| 2077 | fepriv->status = 0; |
| 2078 | } |
| 2079 | break; |
| 2080 | |
| 2081 | case FE_SET_VOLTAGE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2082 | if (fe->ops.set_voltage) { |
| 2083 | err = fe->ops.set_voltage(fe, (fe_sec_voltage_t) parg); |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 2084 | fepriv->voltage = (fe_sec_voltage_t) parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | fepriv->state = FESTATE_DISEQC; |
| 2086 | fepriv->status = 0; |
| 2087 | } |
| 2088 | break; |
| 2089 | |
| 2090 | case FE_DISHNETWORK_SEND_LEGACY_CMD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2091 | if (fe->ops.dishnetwork_send_legacy_command) { |
| 2092 | err = fe->ops.dishnetwork_send_legacy_command(fe, (unsigned long) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | fepriv->state = FESTATE_DISEQC; |
| 2094 | fepriv->status = 0; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2095 | } else if (fe->ops.set_voltage) { |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2096 | /* |
| 2097 | * NOTE: This is a fallback condition. Some frontends |
| 2098 | * (stv0299 for instance) take longer than 8msec to |
| 2099 | * respond to a set_voltage command. Those switches |
| 2100 | * need custom routines to switch properly. For all |
Guillaume Audirac | 2030c03 | 2010-05-06 09:30:25 -0300 | [diff] [blame] | 2101 | * other frontends, the following should work ok. |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2102 | * Dish network legacy switches (as used by Dish500) |
| 2103 | * are controlled by sending 9-bit command words |
| 2104 | * spaced 8msec apart. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2105 | * the actual command word is switch/port dependent |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2106 | * so it is up to the userspace application to send |
| 2107 | * the right command. |
| 2108 | * The command must always start with a '0' after |
| 2109 | * initialization, so parg is 8 bits and does not |
| 2110 | * include the initialization or start bit |
| 2111 | */ |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2112 | unsigned long swcmd = ((unsigned long) parg) << 1; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2113 | struct timeval nexttime; |
| 2114 | struct timeval tv[10]; |
| 2115 | int i; |
| 2116 | u8 last = 1; |
| 2117 | if (dvb_frontend_debug) |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2118 | printk("%s switch command: 0x%04lx\n", __func__, swcmd); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2119 | do_gettimeofday(&nexttime); |
| 2120 | if (dvb_frontend_debug) |
| 2121 | memcpy(&tv[0], &nexttime, sizeof(struct timeval)); |
| 2122 | /* before sending a command, initialize by sending |
| 2123 | * a 32ms 18V to the switch |
| 2124 | */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2125 | fe->ops.set_voltage(fe, SEC_VOLTAGE_18); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2126 | dvb_frontend_sleep_until(&nexttime, 32000); |
| 2127 | |
| 2128 | for (i = 0; i < 9; i++) { |
| 2129 | if (dvb_frontend_debug) |
| 2130 | do_gettimeofday(&tv[i + 1]); |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2131 | if ((swcmd & 0x01) != last) { |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2132 | /* set voltage to (last ? 13V : 18V) */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2133 | fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2134 | last = (last) ? 0 : 1; |
| 2135 | } |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 2136 | swcmd = swcmd >> 1; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2137 | if (i != 8) |
| 2138 | dvb_frontend_sleep_until(&nexttime, 8000); |
| 2139 | } |
| 2140 | if (dvb_frontend_debug) { |
| 2141 | 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] | 2142 | __func__, fe->dvb->num); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 2143 | for (i = 1; i < 10; i++) |
| 2144 | printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); |
| 2145 | } |
| 2146 | err = 0; |
| 2147 | fepriv->state = FESTATE_DISEQC; |
| 2148 | fepriv->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | } |
| 2150 | break; |
| 2151 | |
| 2152 | case FE_DISEQC_RECV_SLAVE_REPLY: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2153 | if (fe->ops.diseqc_recv_slave_reply) |
| 2154 | 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] | 2155 | break; |
| 2156 | |
| 2157 | case FE_ENABLE_HIGH_LNB_VOLTAGE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2158 | if (fe->ops.enable_high_lnb_voltage) |
| 2159 | err = fe->ops.enable_high_lnb_voltage(fe, (long) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | break; |
| 2161 | |
Mauro Carvalho Chehab | 9682cea | 2012-01-01 16:11:12 -0300 | [diff] [blame] | 2162 | case FE_SET_FRONTEND: |
Mauro Carvalho Chehab | 04be0f7 | 2012-01-01 16:11:14 -0300 | [diff] [blame] | 2163 | err = set_delivery_system(fe, SYS_UNDEFINED); |
| 2164 | if (err) |
| 2165 | break; |
| 2166 | |
Mauro Carvalho Chehab | e399ce7 | 2012-01-01 16:11:16 -0300 | [diff] [blame] | 2167 | err = dtv_property_cache_sync(fe, c, parg); |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2168 | if (err) |
| 2169 | break; |
| 2170 | err = dtv_set_frontend(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | case FE_GET_EVENT: |
| 2173 | err = dvb_frontend_get_event (fe, parg, file->f_flags); |
| 2174 | break; |
| 2175 | |
| 2176 | case FE_GET_FRONTEND: |
Mauro Carvalho Chehab | e399ce7 | 2012-01-01 16:11:16 -0300 | [diff] [blame] | 2177 | err = dtv_get_frontend(fe, parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | break; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 2179 | |
| 2180 | case FE_SET_FRONTEND_TUNE_MODE: |
Hans Verkuil | e18828e | 2006-01-09 15:25:28 -0200 | [diff] [blame] | 2181 | fepriv->tune_mode_flags = (unsigned long) parg; |
Trent Piepho | 1b172e0 | 2006-06-29 13:16:04 -0300 | [diff] [blame] | 2182 | err = 0; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 2183 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | }; |
| 2185 | |
Michael Krufky | 9133aee | 2009-05-23 18:00:59 -0300 | [diff] [blame] | 2186 | if (fe->dvb->fe_ioctl_override) { |
| 2187 | cb_err = fe->dvb->fe_ioctl_override(fe, cmd, parg, |
| 2188 | DVB_FE_IOCTL_POST); |
| 2189 | if (cb_err < 0) |
| 2190 | return cb_err; |
| 2191 | } |
| 2192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | return err; |
| 2194 | } |
| 2195 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 2196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait) |
| 2198 | { |
| 2199 | struct dvb_device *dvbdev = file->private_data; |
| 2200 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2201 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 2203 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | |
| 2205 | poll_wait (file, &fepriv->events.wait_queue, wait); |
| 2206 | |
| 2207 | if (fepriv->events.eventw != fepriv->events.eventr) |
| 2208 | return (POLLIN | POLLRDNORM | POLLPRI); |
| 2209 | |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
| 2213 | static int dvb_frontend_open(struct inode *inode, struct file *file) |
| 2214 | { |
| 2215 | struct dvb_device *dvbdev = file->private_data; |
| 2216 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2217 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2218 | struct dvb_adapter *adapter = fe->dvb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | int ret; |
| 2220 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 2221 | dprintk ("%s\n", __func__); |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 2222 | if (fepriv->exit == DVB_FE_DEVICE_REMOVED) |
| 2223 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2225 | if (adapter->mfe_shared) { |
| 2226 | mutex_lock (&adapter->mfe_lock); |
Darron Broad | 6594690 | 2008-10-15 13:37:59 -0300 | [diff] [blame] | 2227 | |
| 2228 | if (adapter->mfe_dvbdev == NULL) |
| 2229 | adapter->mfe_dvbdev = dvbdev; |
| 2230 | |
| 2231 | else if (adapter->mfe_dvbdev != dvbdev) { |
| 2232 | struct dvb_device |
| 2233 | *mfedev = adapter->mfe_dvbdev; |
| 2234 | struct dvb_frontend |
| 2235 | *mfe = mfedev->priv; |
| 2236 | struct dvb_frontend_private |
| 2237 | *mfepriv = mfe->frontend_priv; |
| 2238 | int mferetry = (dvb_mfe_wait_time << 1); |
| 2239 | |
| 2240 | mutex_unlock (&adapter->mfe_lock); |
| 2241 | while (mferetry-- && (mfedev->users != -1 || |
| 2242 | mfepriv->thread != NULL)) { |
| 2243 | if(msleep_interruptible(500)) { |
| 2244 | if(signal_pending(current)) |
| 2245 | return -EINTR; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2246 | } |
| 2247 | } |
Darron Broad | 6594690 | 2008-10-15 13:37:59 -0300 | [diff] [blame] | 2248 | |
| 2249 | mutex_lock (&adapter->mfe_lock); |
| 2250 | if(adapter->mfe_dvbdev != dvbdev) { |
| 2251 | mfedev = adapter->mfe_dvbdev; |
| 2252 | mfe = mfedev->priv; |
| 2253 | mfepriv = mfe->frontend_priv; |
| 2254 | if (mfedev->users != -1 || |
| 2255 | mfepriv->thread != NULL) { |
| 2256 | mutex_unlock (&adapter->mfe_lock); |
| 2257 | return -EBUSY; |
| 2258 | } |
| 2259 | adapter->mfe_dvbdev = dvbdev; |
| 2260 | } |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2264 | if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { |
| 2265 | if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2266 | goto err0; |
Devin Heitmueller | 2d19693 | 2011-07-04 21:55:01 -0300 | [diff] [blame] | 2267 | |
| 2268 | /* If we took control of the bus, we need to force |
| 2269 | reinitialization. This is because many ts_bus_ctrl() |
| 2270 | functions strobe the RESET pin on the demod, and if the |
| 2271 | frontend thread already exists then the dvb_init() routine |
| 2272 | won't get called (which is what usually does initial |
| 2273 | register configuration). */ |
| 2274 | fepriv->reinitialise = 1; |
Steven Toth | ba7e6f3 | 2006-09-25 12:41:53 -0300 | [diff] [blame] | 2275 | } |
| 2276 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2277 | if ((ret = dvb_generic_open (inode, file)) < 0) |
| 2278 | goto err1; |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 2279 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2280 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 2281 | /* normal tune mode when opened R/W */ |
| 2282 | fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT; |
| 2283 | fepriv->tone = -1; |
| 2284 | fepriv->voltage = -1; |
| 2285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | ret = dvb_frontend_start (fe); |
| 2287 | if (ret) |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2288 | goto err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | |
| 2290 | /* empty event queue */ |
| 2291 | fepriv->events.eventr = fepriv->events.eventw = 0; |
| 2292 | } |
| 2293 | |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2294 | if (adapter->mfe_shared) |
| 2295 | mutex_unlock (&adapter->mfe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | return ret; |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2297 | |
| 2298 | err2: |
| 2299 | dvb_generic_release(inode, file); |
| 2300 | err1: |
| 2301 | if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) |
| 2302 | fe->ops.ts_bus_ctrl(fe, 0); |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 2303 | err0: |
| 2304 | if (adapter->mfe_shared) |
| 2305 | mutex_unlock (&adapter->mfe_lock); |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2306 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | static int dvb_frontend_release(struct inode *inode, struct file *file) |
| 2310 | { |
| 2311 | struct dvb_device *dvbdev = file->private_data; |
| 2312 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2313 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2314 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 2316 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 2318 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | fepriv->release_jiffies = jiffies; |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 2320 | mb(); |
| 2321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2323 | ret = dvb_generic_release (inode, file); |
| 2324 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2325 | if (dvbdev->users == -1) { |
Andreas Oberritter | b9d5efc | 2011-12-09 21:37:00 -0300 | [diff] [blame] | 2326 | wake_up(&fepriv->wait_queue); |
matthieu castet | e36309f | 2010-05-05 15:59:20 -0300 | [diff] [blame] | 2327 | if (fepriv->exit != DVB_FE_NO_EXIT) { |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2328 | fops_put(file->f_op); |
| 2329 | file->f_op = NULL; |
| 2330 | wake_up(&dvbdev->wait_queue); |
| 2331 | } |
| 2332 | if (fe->ops.ts_bus_ctrl) |
| 2333 | fe->ops.ts_bus_ctrl(fe, 0); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2334 | } |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 2335 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2336 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Jan Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 2339 | static const struct file_operations dvb_frontend_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | .owner = THIS_MODULE, |
Arnd Bergmann | 16ef8de | 2010-04-27 00:24:00 +0200 | [diff] [blame] | 2341 | .unlocked_ioctl = dvb_generic_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | .poll = dvb_frontend_poll, |
| 2343 | .open = dvb_frontend_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 2344 | .release = dvb_frontend_release, |
| 2345 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | }; |
| 2347 | |
| 2348 | int dvb_register_frontend(struct dvb_adapter* dvb, |
| 2349 | struct dvb_frontend* fe) |
| 2350 | { |
| 2351 | struct dvb_frontend_private *fepriv; |
| 2352 | static const struct dvb_device dvbdev_template = { |
| 2353 | .users = ~0, |
| 2354 | .writers = 1, |
| 2355 | .readers = (~0)-1, |
| 2356 | .fops = &dvb_frontend_fops, |
| 2357 | .kernel_ioctl = dvb_frontend_ioctl |
| 2358 | }; |
| 2359 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 2360 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2362 | if (mutex_lock_interruptible(&frontend_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | return -ERESTARTSYS; |
| 2364 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 2365 | fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | if (fe->frontend_priv == NULL) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2367 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | return -ENOMEM; |
| 2369 | } |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2370 | fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | |
Thomas Gleixner | a0a4714 | 2010-09-07 11:33:27 -0300 | [diff] [blame] | 2372 | sema_init(&fepriv->sem, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | init_waitqueue_head (&fepriv->wait_queue); |
| 2374 | init_waitqueue_head (&fepriv->events.wait_queue); |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 2375 | mutex_init(&fepriv->events.mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | fe->dvb = dvb; |
| 2377 | fepriv->inversion = INVERSION_OFF; |
| 2378 | |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 2379 | printk ("DVB: registering adapter %i frontend %i (%s)...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | fe->dvb->num, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 2381 | fe->id, |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 2382 | fe->ops.info.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
| 2384 | dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template, |
| 2385 | fe, DVB_DEVICE_FRONTEND); |
| 2386 | |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2387 | /* |
| 2388 | * Initialize the cache to the proper values according with the |
| 2389 | * first supported delivery system (ops->delsys[0]) |
| 2390 | */ |
Mauro Carvalho Chehab | 240ab50 | 2012-01-10 18:00:50 -0300 | [diff] [blame] | 2391 | |
| 2392 | fe->dtv_property_cache.delivery_system = fe->ops.delsys[0]; |
Mauro Carvalho Chehab | 5bfaadd | 2012-01-01 16:11:13 -0300 | [diff] [blame] | 2393 | dvb_frontend_clear_cache(fe); |
| 2394 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2395 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | return 0; |
| 2397 | } |
| 2398 | EXPORT_SYMBOL(dvb_register_frontend); |
| 2399 | |
| 2400 | int dvb_unregister_frontend(struct dvb_frontend* fe) |
| 2401 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 2402 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 2403 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | |
Markus Rechberger | 57861b4 | 2007-04-14 10:19:18 -0300 | [diff] [blame] | 2405 | mutex_lock(&frontend_mutex); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 2406 | dvb_frontend_stop (fe); |
Markus Rechberger | 57861b4 | 2007-04-14 10:19:18 -0300 | [diff] [blame] | 2407 | mutex_unlock(&frontend_mutex); |
| 2408 | |
| 2409 | if (fepriv->dvbdev->users < -1) |
| 2410 | wait_event(fepriv->dvbdev->wait_queue, |
| 2411 | fepriv->dvbdev->users==-1); |
| 2412 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2413 | mutex_lock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | dvb_unregister_device (fepriv->dvbdev); |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 2415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | /* fe is invalid now */ |
| 2417 | kfree(fepriv); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 2418 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | return 0; |
| 2420 | } |
| 2421 | EXPORT_SYMBOL(dvb_unregister_frontend); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2422 | |
Mauro Carvalho Chehab | 149ef72 | 2008-04-29 21:38:46 -0300 | [diff] [blame] | 2423 | #ifdef CONFIG_MEDIA_ATTACH |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2424 | void dvb_frontend_detach(struct dvb_frontend* fe) |
| 2425 | { |
| 2426 | void *ptr; |
| 2427 | |
| 2428 | if (fe->ops.release_sec) { |
| 2429 | fe->ops.release_sec(fe); |
| 2430 | symbol_put_addr(fe->ops.release_sec); |
| 2431 | } |
| 2432 | if (fe->ops.tuner_ops.release) { |
| 2433 | fe->ops.tuner_ops.release(fe); |
| 2434 | symbol_put_addr(fe->ops.tuner_ops.release); |
| 2435 | } |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 2436 | if (fe->ops.analog_ops.release) { |
| 2437 | fe->ops.analog_ops.release(fe); |
| 2438 | symbol_put_addr(fe->ops.analog_ops.release); |
| 2439 | } |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2440 | ptr = (void*)fe->ops.release; |
| 2441 | if (ptr) { |
| 2442 | fe->ops.release(fe); |
| 2443 | symbol_put_addr(ptr); |
| 2444 | } |
| 2445 | } |
| 2446 | #else |
| 2447 | void dvb_frontend_detach(struct dvb_frontend* fe) |
| 2448 | { |
| 2449 | if (fe->ops.release_sec) |
| 2450 | fe->ops.release_sec(fe); |
| 2451 | if (fe->ops.tuner_ops.release) |
| 2452 | fe->ops.tuner_ops.release(fe); |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 2453 | if (fe->ops.analog_ops.release) |
| 2454 | fe->ops.analog_ops.release(fe); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2455 | if (fe->ops.release) |
| 2456 | fe->ops.release(fe); |
| 2457 | } |
| 2458 | #endif |
| 2459 | EXPORT_SYMBOL(dvb_frontend_detach); |