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 | |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/sched.h> |
| 31 | #include <linux/wait.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/poll.h> |
| 34 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/list.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 36 | #include <linux/freezer.h> |
Johannes Stezenbach | cc89c22 | 2005-06-23 22:02:39 -0700 | [diff] [blame] | 37 | #include <linux/jiffies.h> |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 38 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | #include "dvb_frontend.h" |
| 42 | #include "dvbdev.h" |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 43 | #include <linux/dvb/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | static int dvb_frontend_debug; |
Oliver Endriss | 849be2c | 2007-08-25 12:22:16 -0300 | [diff] [blame] | 46 | static int dvb_shutdown_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static int dvb_force_auto_inversion; |
| 48 | static int dvb_override_tune_delay; |
| 49 | static int dvb_powerdown_on_sleep = 1; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 50 | static int dvb_mfe_wait_time = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | module_param_named(frontend_debug, dvb_frontend_debug, int, 0644); |
Johannes Stezenbach | f4f009a | 2005-05-16 21:54:21 -0700 | [diff] [blame] | 53 | 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] | 54 | module_param(dvb_shutdown_timeout, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | 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] | 56 | module_param(dvb_force_auto_inversion, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | 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] | 58 | module_param(dvb_override_tune_delay, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | 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] | 60 | module_param(dvb_powerdown_on_sleep, int, 0644); |
Uwe Bugla | a855857 | 2006-04-11 10:21:37 -0300 | [diff] [blame] | 61 | 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] | 62 | module_param(dvb_mfe_wait_time, int, 0644); |
| 63 | 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] | 64 | |
| 65 | #define dprintk if (dvb_frontend_debug) printk |
| 66 | |
| 67 | #define FESTATE_IDLE 1 |
| 68 | #define FESTATE_RETUNE 2 |
| 69 | #define FESTATE_TUNING_FAST 4 |
| 70 | #define FESTATE_TUNING_SLOW 8 |
| 71 | #define FESTATE_TUNED 16 |
| 72 | #define FESTATE_ZIGZAG_FAST 32 |
| 73 | #define FESTATE_ZIGZAG_SLOW 64 |
| 74 | #define FESTATE_DISEQC 128 |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 75 | #define FESTATE_ERROR 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC) |
| 77 | #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST) |
| 78 | #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW) |
| 79 | #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW) |
Manu Abraham | 0249ef1 | 2006-06-21 10:27:31 -0300 | [diff] [blame] | 80 | |
| 81 | #define FE_ALGO_HW 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* |
| 83 | * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling. |
| 84 | * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune. |
| 85 | * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress. |
| 86 | * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower. |
| 87 | * FESTATE_TUNED. The frontend has successfully locked on. |
| 88 | * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it. |
| 89 | * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower. |
| 90 | * FESTATE_DISEQC. A DISEQC command has just been issued. |
| 91 | * FESTATE_WAITFORLOCK. When we're waiting for a lock. |
| 92 | * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan. |
| 93 | * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan. |
| 94 | * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again. |
| 95 | */ |
| 96 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 97 | static DEFINE_MUTEX(frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | struct dvb_frontend_private { |
| 100 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 101 | /* thread/frontend values */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | struct dvb_device *dvbdev; |
| 103 | struct dvb_frontend_parameters parameters; |
| 104 | struct dvb_fe_events events; |
| 105 | struct semaphore sem; |
| 106 | struct list_head list_head; |
| 107 | wait_queue_head_t wait_queue; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 108 | struct task_struct *thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | unsigned long release_jiffies; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 110 | unsigned int exit; |
| 111 | unsigned int wakeup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | fe_status_t status; |
Peter Beutner | 400b708 | 2006-01-09 15:32:43 -0200 | [diff] [blame] | 113 | unsigned long tune_mode_flags; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 114 | unsigned int delay; |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 115 | unsigned int reinitialise; |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 116 | int tone; |
| 117 | int voltage; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 118 | |
| 119 | /* swzigzag values */ |
| 120 | unsigned int state; |
| 121 | unsigned int bending; |
| 122 | int lnb_drift; |
| 123 | unsigned int inversion; |
| 124 | unsigned int auto_step; |
| 125 | unsigned int auto_sub_step; |
| 126 | unsigned int started_auto_step; |
| 127 | unsigned int min_delay; |
| 128 | unsigned int max_drift; |
| 129 | unsigned int step_size; |
| 130 | int quality; |
| 131 | unsigned int check_wrapped; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 132 | enum dvbfe_search algo_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 135 | static void dvb_frontend_wakeup(struct dvb_frontend *fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status) |
| 138 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 139 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | struct dvb_fe_events *events = &fepriv->events; |
| 141 | struct dvb_frontend_event *e; |
| 142 | int wp; |
| 143 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 144 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 146 | if (mutex_lock_interruptible (&events->mtx)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return; |
| 148 | |
| 149 | wp = (events->eventw + 1) % MAX_EVENT; |
| 150 | |
| 151 | if (wp == events->eventr) { |
| 152 | events->overflow = 1; |
| 153 | events->eventr = (events->eventr + 1) % MAX_EVENT; |
| 154 | } |
| 155 | |
| 156 | e = &events->events[events->eventw]; |
| 157 | |
| 158 | memcpy (&e->parameters, &fepriv->parameters, |
| 159 | sizeof (struct dvb_frontend_parameters)); |
| 160 | |
| 161 | if (status & FE_HAS_LOCK) |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 162 | if (fe->ops.get_frontend) |
| 163 | fe->ops.get_frontend(fe, &e->parameters); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | events->eventw = wp; |
| 166 | |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 167 | mutex_unlock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | e->status = status; |
| 170 | |
| 171 | wake_up_interruptible (&events->wait_queue); |
| 172 | } |
| 173 | |
| 174 | static int dvb_frontend_get_event(struct dvb_frontend *fe, |
| 175 | struct dvb_frontend_event *event, int flags) |
| 176 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 177 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | struct dvb_fe_events *events = &fepriv->events; |
| 179 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 180 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (events->overflow) { |
| 183 | events->overflow = 0; |
| 184 | return -EOVERFLOW; |
| 185 | } |
| 186 | |
| 187 | if (events->eventw == events->eventr) { |
| 188 | int ret; |
| 189 | |
| 190 | if (flags & O_NONBLOCK) |
| 191 | return -EWOULDBLOCK; |
| 192 | |
| 193 | up(&fepriv->sem); |
| 194 | |
| 195 | ret = wait_event_interruptible (events->wait_queue, |
| 196 | events->eventw != events->eventr); |
| 197 | |
| 198 | if (down_interruptible (&fepriv->sem)) |
| 199 | return -ERESTARTSYS; |
| 200 | |
| 201 | if (ret < 0) |
| 202 | return ret; |
| 203 | } |
| 204 | |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 205 | if (mutex_lock_interruptible (&events->mtx)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return -ERESTARTSYS; |
| 207 | |
| 208 | memcpy (event, &events->events[events->eventr], |
| 209 | sizeof(struct dvb_frontend_event)); |
| 210 | |
| 211 | events->eventr = (events->eventr + 1) % MAX_EVENT; |
| 212 | |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 213 | mutex_unlock(&events->mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static void dvb_frontend_init(struct dvb_frontend *fe) |
| 219 | { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 220 | dprintk ("DVB: initialising adapter %i frontend %i (%s)...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | fe->dvb->num, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 222 | fe->id, |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 223 | fe->ops.info.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 225 | if (fe->ops.init) |
| 226 | fe->ops.init(fe); |
| 227 | if (fe->ops.tuner_ops.init) { |
Manu Abraham | 3b37a15 | 2008-10-20 18:14:14 -0300 | [diff] [blame] | 228 | if (fe->ops.i2c_gate_ctrl) |
| 229 | fe->ops.i2c_gate_ctrl(fe, 1); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 230 | fe->ops.tuner_ops.init(fe); |
| 231 | if (fe->ops.i2c_gate_ctrl) |
| 232 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 7eef5dd | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 236 | void dvb_frontend_reinitialise(struct dvb_frontend *fe) |
| 237 | { |
| 238 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 239 | |
| 240 | fepriv->reinitialise = 1; |
| 241 | dvb_frontend_wakeup(fe); |
| 242 | } |
| 243 | EXPORT_SYMBOL(dvb_frontend_reinitialise); |
| 244 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 245 | 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] | 246 | { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 247 | int q2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 249 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 251 | if (locked) |
| 252 | (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256; |
| 253 | else |
| 254 | (fepriv->quality) = (fepriv->quality * 220 + 0) / 256; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 256 | q2 = fepriv->quality - 128; |
| 257 | q2 *= q2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 259 | fepriv->delay = fepriv->min_delay + q2 * HZ / (128*128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Performs automatic twiddling of frontend parameters. |
| 264 | * |
| 265 | * @param fe The frontend concerned. |
| 266 | * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT |
| 267 | * @returns Number of complete iterations that have been performed. |
| 268 | */ |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 269 | 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] | 270 | { |
| 271 | int autoinversion; |
| 272 | int ready = 0; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 273 | int fe_set_err = 0; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 274 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | int original_inversion = fepriv->parameters.inversion; |
| 276 | u32 original_frequency = fepriv->parameters.frequency; |
| 277 | |
| 278 | /* are we using autoinversion? */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 279 | autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | (fepriv->parameters.inversion == INVERSION_AUTO)); |
| 281 | |
| 282 | /* setup parameters correctly */ |
| 283 | while(!ready) { |
| 284 | /* calculate the lnb_drift */ |
| 285 | fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size; |
| 286 | |
| 287 | /* wrap the auto_step if we've exceeded the maximum drift */ |
| 288 | if (fepriv->lnb_drift > fepriv->max_drift) { |
| 289 | fepriv->auto_step = 0; |
| 290 | fepriv->auto_sub_step = 0; |
| 291 | fepriv->lnb_drift = 0; |
| 292 | } |
| 293 | |
| 294 | /* perform inversion and +/- zigzag */ |
| 295 | switch(fepriv->auto_sub_step) { |
| 296 | case 0: |
| 297 | /* try with the current inversion and current drift setting */ |
| 298 | ready = 1; |
| 299 | break; |
| 300 | |
| 301 | case 1: |
| 302 | if (!autoinversion) break; |
| 303 | |
| 304 | fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF; |
| 305 | ready = 1; |
| 306 | break; |
| 307 | |
| 308 | case 2: |
| 309 | if (fepriv->lnb_drift == 0) break; |
| 310 | |
| 311 | fepriv->lnb_drift = -fepriv->lnb_drift; |
| 312 | ready = 1; |
| 313 | break; |
| 314 | |
| 315 | case 3: |
| 316 | if (fepriv->lnb_drift == 0) break; |
| 317 | if (!autoinversion) break; |
| 318 | |
| 319 | fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF; |
| 320 | fepriv->lnb_drift = -fepriv->lnb_drift; |
| 321 | ready = 1; |
| 322 | break; |
| 323 | |
| 324 | default: |
| 325 | fepriv->auto_step++; |
| 326 | fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */ |
| 327 | break; |
| 328 | } |
| 329 | |
| 330 | if (!ready) fepriv->auto_sub_step++; |
| 331 | } |
| 332 | |
| 333 | /* if this attempt would hit where we started, indicate a complete |
| 334 | * iteration has occurred */ |
| 335 | if ((fepriv->auto_step == fepriv->started_auto_step) && |
| 336 | (fepriv->auto_sub_step == 0) && check_wrapped) { |
| 337 | return 1; |
| 338 | } |
| 339 | |
| 340 | dprintk("%s: drift:%i inversion:%i auto_step:%i " |
| 341 | "auto_sub_step:%i started_auto_step:%i\n", |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 342 | __func__, fepriv->lnb_drift, fepriv->inversion, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step); |
| 344 | |
| 345 | /* set the frontend itself */ |
| 346 | fepriv->parameters.frequency += fepriv->lnb_drift; |
| 347 | if (autoinversion) |
| 348 | fepriv->parameters.inversion = fepriv->inversion; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 349 | if (fe->ops.set_frontend) |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 350 | fe_set_err = fe->ops.set_frontend(fe, &fepriv->parameters); |
| 351 | if (fe_set_err < 0) { |
| 352 | fepriv->state = FESTATE_ERROR; |
| 353 | return fe_set_err; |
| 354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | fepriv->parameters.frequency = original_frequency; |
| 357 | fepriv->parameters.inversion = original_inversion; |
| 358 | |
| 359 | fepriv->auto_sub_step++; |
| 360 | return 0; |
| 361 | } |
| 362 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 363 | static void dvb_frontend_swzigzag(struct dvb_frontend *fe) |
| 364 | { |
Andrew de Quincey | 30d9464 | 2006-11-16 22:12:40 -0300 | [diff] [blame] | 365 | fe_status_t s = 0; |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 366 | int retval = 0; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 367 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 368 | |
| 369 | /* if we've got no parameters, just keep idling */ |
| 370 | if (fepriv->state & FESTATE_IDLE) { |
| 371 | fepriv->delay = 3*HZ; |
| 372 | fepriv->quality = 0; |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | /* in SCAN mode, we just set the frontend when asked and leave it alone */ |
| 377 | if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) { |
| 378 | if (fepriv->state & FESTATE_RETUNE) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 379 | if (fe->ops.set_frontend) |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 380 | retval = fe->ops.set_frontend(fe, |
| 381 | &fepriv->parameters); |
| 382 | if (retval < 0) |
| 383 | fepriv->state = FESTATE_ERROR; |
| 384 | else |
| 385 | fepriv->state = FESTATE_TUNED; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 386 | } |
| 387 | fepriv->delay = 3*HZ; |
| 388 | fepriv->quality = 0; |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | /* get the frontend status */ |
| 393 | if (fepriv->state & FESTATE_RETUNE) { |
| 394 | s = 0; |
| 395 | } else { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 396 | if (fe->ops.read_status) |
| 397 | fe->ops.read_status(fe, &s); |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 398 | if (s != fepriv->status) { |
| 399 | dvb_frontend_add_event(fe, s); |
| 400 | fepriv->status = s; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /* if we're not tuned, and we have a lock, move to the TUNED state */ |
| 405 | if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) { |
| 406 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 407 | fepriv->state = FESTATE_TUNED; |
| 408 | |
| 409 | /* if we're tuned, then we have determined the correct inversion */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 410 | if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) && |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 411 | (fepriv->parameters.inversion == INVERSION_AUTO)) { |
| 412 | fepriv->parameters.inversion = fepriv->inversion; |
| 413 | } |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | /* if we are tuned already, check we're still locked */ |
| 418 | if (fepriv->state & FESTATE_TUNED) { |
| 419 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 420 | |
| 421 | /* we're tuned, and the lock is still good... */ |
| 422 | if (s & FE_HAS_LOCK) { |
| 423 | return; |
| 424 | } else { /* if we _WERE_ tuned, but now don't have a lock */ |
| 425 | fepriv->state = FESTATE_ZIGZAG_FAST; |
| 426 | fepriv->started_auto_step = fepriv->auto_step; |
| 427 | fepriv->check_wrapped = 0; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /* don't actually do anything if we're in the LOSTLOCK state, |
| 432 | * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */ |
| 433 | if ((fepriv->state & FESTATE_LOSTLOCK) && |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 434 | (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 435 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | /* don't do anything if we're in the DISEQC state, since this |
| 440 | * might be someone with a motorized dish controlled by DISEQC. |
| 441 | * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */ |
| 442 | if (fepriv->state & FESTATE_DISEQC) { |
| 443 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | /* if we're in the RETUNE state, set everything up for a brand |
| 448 | * new scan, keeping the current inversion setting, as the next |
| 449 | * tune is _very_ likely to require the same */ |
| 450 | if (fepriv->state & FESTATE_RETUNE) { |
| 451 | fepriv->lnb_drift = 0; |
| 452 | fepriv->auto_step = 0; |
| 453 | fepriv->auto_sub_step = 0; |
| 454 | fepriv->started_auto_step = 0; |
| 455 | fepriv->check_wrapped = 0; |
| 456 | } |
| 457 | |
| 458 | /* fast zigzag. */ |
| 459 | if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) { |
| 460 | fepriv->delay = fepriv->min_delay; |
| 461 | |
| 462 | /* peform a tune */ |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 463 | retval = dvb_frontend_swzigzag_autotune(fe, |
| 464 | fepriv->check_wrapped); |
| 465 | if (retval < 0) { |
| 466 | return; |
| 467 | } else if (retval) { |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 468 | /* OK, if we've run out of trials at the fast speed. |
| 469 | * Drop back to slow for the _next_ attempt */ |
| 470 | fepriv->state = FESTATE_SEARCHING_SLOW; |
| 471 | fepriv->started_auto_step = fepriv->auto_step; |
| 472 | return; |
| 473 | } |
| 474 | fepriv->check_wrapped = 1; |
| 475 | |
| 476 | /* if we've just retuned, enter the ZIGZAG_FAST state. |
| 477 | * This ensures we cannot return from an |
| 478 | * FE_SET_FRONTEND ioctl before the first frontend tune |
| 479 | * occurs */ |
| 480 | if (fepriv->state & FESTATE_RETUNE) { |
| 481 | fepriv->state = FESTATE_TUNING_FAST; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /* slow zigzag */ |
| 486 | if (fepriv->state & FESTATE_SEARCHING_SLOW) { |
| 487 | dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK); |
| 488 | |
| 489 | /* Note: don't bother checking for wrapping; we stay in this |
| 490 | * state until we get a lock */ |
| 491 | dvb_frontend_swzigzag_autotune(fe, 0); |
| 492 | } |
| 493 | } |
| 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | static int dvb_frontend_is_exiting(struct dvb_frontend *fe) |
| 496 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 497 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | if (fepriv->exit) |
| 500 | return 1; |
| 501 | |
| 502 | if (fepriv->dvbdev->writers == 1) |
Johannes Stezenbach | cc89c22 | 2005-06-23 22:02:39 -0700 | [diff] [blame] | 503 | if (time_after(jiffies, fepriv->release_jiffies + |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 504 | dvb_shutdown_timeout * HZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return 1; |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static int dvb_frontend_should_wakeup(struct dvb_frontend *fe) |
| 511 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 512 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | if (fepriv->wakeup) { |
| 515 | fepriv->wakeup = 0; |
| 516 | return 1; |
| 517 | } |
| 518 | return dvb_frontend_is_exiting(fe); |
| 519 | } |
| 520 | |
| 521 | static void dvb_frontend_wakeup(struct dvb_frontend *fe) |
| 522 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 523 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | fepriv->wakeup = 1; |
| 526 | wake_up_interruptible(&fepriv->wait_queue); |
| 527 | } |
| 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | static int dvb_frontend_thread(void *data) |
| 530 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 531 | struct dvb_frontend *fe = data; |
| 532 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | unsigned long timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | fe_status_t s; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 535 | enum dvbfe_algo algo; |
| 536 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 537 | struct dvb_frontend_parameters *params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 539 | dprintk("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 541 | fepriv->check_wrapped = 0; |
| 542 | fepriv->quality = 0; |
| 543 | fepriv->delay = 3*HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | fepriv->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | fepriv->wakeup = 0; |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 546 | fepriv->reinitialise = 0; |
| 547 | |
| 548 | dvb_frontend_init(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 550 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | while (1) { |
| 552 | up(&fepriv->sem); /* is locked when we enter the thread... */ |
akpm@linux-foundation.org | 6591691 | 2007-02-08 14:36:57 -0300 | [diff] [blame] | 553 | restart: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | timeout = wait_event_interruptible_timeout(fepriv->wait_queue, |
Rafael J. Wysocki | e42837b | 2007-10-18 03:04:45 -0700 | [diff] [blame] | 555 | dvb_frontend_should_wakeup(fe) || kthread_should_stop() |
| 556 | || freezing(current), |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 557 | fepriv->delay); |
| 558 | |
| 559 | if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | /* got signal or quitting */ |
Devin Heitmueller | 57594a5 | 2009-05-04 21:43:02 -0300 | [diff] [blame] | 561 | fepriv->exit = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | break; |
| 563 | } |
| 564 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 565 | if (try_to_freeze()) |
akpm@linux-foundation.org | 6591691 | 2007-02-08 14:36:57 -0300 | [diff] [blame] | 566 | goto restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | if (down_interruptible(&fepriv->sem)) |
| 569 | break; |
| 570 | |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 571 | if (fepriv->reinitialise) { |
| 572 | dvb_frontend_init(fe); |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 573 | if (fepriv->tone != -1) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 574 | fe->ops.set_tone(fe, fepriv->tone); |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 575 | } |
| 576 | if (fepriv->voltage != -1) { |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 577 | fe->ops.set_voltage(fe, fepriv->voltage); |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 578 | } |
Andrew de Quincey | 86f40cc | 2006-03-30 15:53:35 -0300 | [diff] [blame] | 579 | fepriv->reinitialise = 0; |
| 580 | } |
| 581 | |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 582 | /* do an iteration of the tuning loop */ |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 583 | if (fe->ops.get_frontend_algo) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 584 | algo = fe->ops.get_frontend_algo(fe); |
| 585 | switch (algo) { |
| 586 | case DVBFE_ALGO_HW: |
| 587 | dprintk("%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__); |
| 588 | params = NULL; /* have we been asked to RETUNE ? */ |
| 589 | |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 590 | if (fepriv->state & FESTATE_RETUNE) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 591 | dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__); |
Matthias Schwarzott | f7c9bf9 | 2008-10-28 05:58:04 -0300 | [diff] [blame] | 592 | params = &fepriv->parameters; |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 593 | fepriv->state = FESTATE_TUNED; |
| 594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 596 | if (fe->ops.tune) |
| 597 | fe->ops.tune(fe, params, fepriv->tune_mode_flags, &fepriv->delay, &s); |
| 598 | |
Darron Broad | 2fac9a0 | 2008-12-18 06:27:50 -0300 | [diff] [blame] | 599 | if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 600 | dprintk("%s: state changed, adding current state\n", __func__); |
Manu Abraham | d772bd0 | 2006-06-24 11:18:58 -0300 | [diff] [blame] | 601 | dvb_frontend_add_event(fe, s); |
| 602 | fepriv->status = s; |
| 603 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 604 | break; |
| 605 | case DVBFE_ALGO_SW: |
| 606 | dprintk("%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__); |
Manu Abraham | 70d9063 | 2006-06-29 22:05:23 -0300 | [diff] [blame] | 607 | dvb_frontend_swzigzag(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 608 | break; |
| 609 | case DVBFE_ALGO_CUSTOM: |
| 610 | params = NULL; /* have we been asked to RETUNE ? */ |
| 611 | dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state); |
| 612 | if (fepriv->state & FESTATE_RETUNE) { |
| 613 | dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__); |
Manu Abraham | f04c3ca | 2008-10-28 06:11:24 -0300 | [diff] [blame] | 614 | params = &fepriv->parameters; |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 615 | fepriv->state = FESTATE_TUNED; |
| 616 | } |
| 617 | /* Case where we are going to search for a carrier |
| 618 | * User asked us to retune again for some reason, possibly |
| 619 | * requesting a search with a new set of parameters |
| 620 | */ |
| 621 | if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) { |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 622 | if (fe->ops.search) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 623 | fepriv->algo_status = fe->ops.search(fe, &fepriv->parameters); |
| 624 | /* We did do a search as was requested, the flags are |
| 625 | * now unset as well and has the flags wrt to search. |
| 626 | */ |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 627 | } else { |
| 628 | fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN; |
| 629 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 630 | } |
| 631 | /* Track the carrier if the search was successful */ |
| 632 | if (fepriv->algo_status == DVBFE_ALGO_SEARCH_SUCCESS) { |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 633 | if (fe->ops.track) |
| 634 | fe->ops.track(fe, &fepriv->parameters); |
Arvo Jarve | 7bcbdf3 | 2008-10-20 06:05:21 -0300 | [diff] [blame] | 635 | } else { |
| 636 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 637 | fepriv->delay = HZ / 2; |
| 638 | } |
| 639 | fe->ops.read_status(fe, &s); |
| 640 | if (s != fepriv->status) { |
| 641 | dvb_frontend_add_event(fe, s); /* update event list */ |
| 642 | fepriv->status = s; |
| 643 | if (!(s & FE_HAS_LOCK)) { |
| 644 | fepriv->delay = HZ / 10; |
| 645 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 646 | } else { |
| 647 | fepriv->delay = 60 * HZ; |
| 648 | } |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 649 | } |
| 650 | break; |
| 651 | default: |
| 652 | dprintk("%s: UNDEFINED ALGO !\n", __func__); |
| 653 | break; |
| 654 | } |
| 655 | } else { |
Manu Abraham | 4a4edcc | 2006-06-25 05:46:26 -0300 | [diff] [blame] | 656 | dvb_frontend_swzigzag(fe); |
Manu Abraham | c59e787 | 2008-10-14 16:34:07 -0300 | [diff] [blame] | 657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Oliver Endriss | 608f62d | 2007-08-25 13:17:53 -0300 | [diff] [blame] | 660 | if (dvb_powerdown_on_sleep) { |
| 661 | if (fe->ops.set_voltage) |
| 662 | fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 663 | if (fe->ops.tuner_ops.sleep) { |
Devin Heitmueller | 41286d9 | 2008-11-16 00:44:52 -0300 | [diff] [blame] | 664 | if (fe->ops.i2c_gate_ctrl) |
| 665 | fe->ops.i2c_gate_ctrl(fe, 1); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 666 | fe->ops.tuner_ops.sleep(fe); |
| 667 | if (fe->ops.i2c_gate_ctrl) |
| 668 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 7eef5dd | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 669 | } |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 670 | if (fe->ops.sleep) |
| 671 | fe->ops.sleep(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 674 | fepriv->thread = NULL; |
Devin Heitmueller | a5beb7b | 2009-05-20 23:58:16 -0300 | [diff] [blame] | 675 | fepriv->exit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | mb(); |
| 677 | |
| 678 | dvb_frontend_wakeup(fe); |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | static void dvb_frontend_stop(struct dvb_frontend *fe) |
| 683 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 684 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 686 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | fepriv->exit = 1; |
| 689 | mb(); |
| 690 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 691 | if (!fepriv->thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | return; |
| 693 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 694 | kthread_stop(fepriv->thread); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 695 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 696 | init_MUTEX (&fepriv->sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | fepriv->state = FESTATE_IDLE; |
| 698 | |
| 699 | /* paranoia check in case a signal arrived */ |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 700 | if (fepriv->thread) |
| 701 | printk("dvb_frontend_stop: warning: thread %p won't exit\n", |
| 702 | fepriv->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 705 | s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime) |
| 706 | { |
| 707 | return ((curtime.tv_usec < lasttime.tv_usec) ? |
| 708 | 1000000 - lasttime.tv_usec + curtime.tv_usec : |
| 709 | curtime.tv_usec - lasttime.tv_usec); |
| 710 | } |
| 711 | EXPORT_SYMBOL(timeval_usec_diff); |
| 712 | |
| 713 | static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec) |
| 714 | { |
| 715 | curtime->tv_usec += add_usec; |
| 716 | if (curtime->tv_usec >= 1000000) { |
| 717 | curtime->tv_usec -= 1000000; |
| 718 | curtime->tv_sec++; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | /* |
| 723 | * Sleep until gettimeofday() > waketime + add_usec |
| 724 | * This needs to be as precise as possible, but as the delay is |
| 725 | * usually between 2ms and 32ms, it is done using a scheduled msleep |
| 726 | * followed by usleep (normally a busy-wait loop) for the remainder |
| 727 | */ |
| 728 | void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec) |
| 729 | { |
| 730 | struct timeval lasttime; |
| 731 | s32 delta, newdelta; |
| 732 | |
| 733 | timeval_usec_add(waketime, add_usec); |
| 734 | |
| 735 | do_gettimeofday(&lasttime); |
| 736 | delta = timeval_usec_diff(lasttime, *waketime); |
| 737 | if (delta > 2500) { |
| 738 | msleep((delta - 1500) / 1000); |
| 739 | do_gettimeofday(&lasttime); |
| 740 | newdelta = timeval_usec_diff(lasttime, *waketime); |
| 741 | delta = (newdelta > delta) ? 0 : newdelta; |
| 742 | } |
| 743 | if (delta > 0) |
| 744 | udelay(delta); |
| 745 | } |
| 746 | EXPORT_SYMBOL(dvb_frontend_sleep_until); |
| 747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | static int dvb_frontend_start(struct dvb_frontend *fe) |
| 749 | { |
| 750 | int ret; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 751 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 752 | struct task_struct *fe_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 754 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 756 | if (fepriv->thread) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (!fepriv->exit) |
| 758 | return 0; |
| 759 | else |
| 760 | dvb_frontend_stop (fe); |
| 761 | } |
| 762 | |
| 763 | if (signal_pending(current)) |
| 764 | return -EINTR; |
| 765 | if (down_interruptible (&fepriv->sem)) |
| 766 | return -EINTR; |
| 767 | |
| 768 | fepriv->state = FESTATE_IDLE; |
| 769 | fepriv->exit = 0; |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 770 | fepriv->thread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | mb(); |
| 772 | |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 773 | fe_thread = kthread_run(dvb_frontend_thread, fe, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 774 | "kdvb-ad-%i-fe-%i", fe->dvb->num,fe->id); |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 775 | if (IS_ERR(fe_thread)) { |
| 776 | ret = PTR_ERR(fe_thread); |
| 777 | printk("dvb_frontend_start: failed to start kthread (%d)\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | up(&fepriv->sem); |
| 779 | return ret; |
| 780 | } |
Herbert Poetzl | 8eec142 | 2007-02-08 14:32:43 -0300 | [diff] [blame] | 781 | fepriv->thread = fe_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 785 | static void dvb_frontend_get_frequeny_limits(struct dvb_frontend *fe, |
| 786 | u32 *freq_min, u32 *freq_max) |
| 787 | { |
| 788 | *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min); |
| 789 | |
| 790 | if (fe->ops.info.frequency_max == 0) |
| 791 | *freq_max = fe->ops.tuner_ops.info.frequency_max; |
| 792 | else if (fe->ops.tuner_ops.info.frequency_max == 0) |
| 793 | *freq_max = fe->ops.info.frequency_max; |
| 794 | else |
| 795 | *freq_max = min(fe->ops.info.frequency_max, fe->ops.tuner_ops.info.frequency_max); |
| 796 | |
| 797 | if (*freq_min == 0 || *freq_max == 0) |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 798 | printk(KERN_WARNING "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n", |
| 799 | fe->dvb->num,fe->id); |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 800 | } |
| 801 | |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 802 | static int dvb_frontend_check_parameters(struct dvb_frontend *fe, |
| 803 | struct dvb_frontend_parameters *parms) |
| 804 | { |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 805 | u32 freq_min; |
| 806 | u32 freq_max; |
| 807 | |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 808 | /* range check: frequency */ |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 809 | dvb_frontend_get_frequeny_limits(fe, &freq_min, &freq_max); |
| 810 | if ((freq_min && parms->frequency < freq_min) || |
| 811 | (freq_max && parms->frequency > freq_max)) { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 812 | printk(KERN_WARNING "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n", |
| 813 | fe->dvb->num, fe->id, parms->frequency, freq_min, freq_max); |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 814 | return -EINVAL; |
| 815 | } |
| 816 | |
| 817 | /* range check: symbol rate */ |
| 818 | if (fe->ops.info.type == FE_QPSK) { |
| 819 | if ((fe->ops.info.symbol_rate_min && |
| 820 | parms->u.qpsk.symbol_rate < fe->ops.info.symbol_rate_min) || |
| 821 | (fe->ops.info.symbol_rate_max && |
| 822 | parms->u.qpsk.symbol_rate > fe->ops.info.symbol_rate_max)) { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 823 | printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n", |
| 824 | fe->dvb->num, fe->id, parms->u.qpsk.symbol_rate, |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 825 | fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max); |
| 826 | return -EINVAL; |
| 827 | } |
| 828 | |
| 829 | } else if (fe->ops.info.type == FE_QAM) { |
| 830 | if ((fe->ops.info.symbol_rate_min && |
| 831 | parms->u.qam.symbol_rate < fe->ops.info.symbol_rate_min) || |
| 832 | (fe->ops.info.symbol_rate_max && |
| 833 | parms->u.qam.symbol_rate > fe->ops.info.symbol_rate_max)) { |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 834 | printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n", |
| 835 | fe->dvb->num, fe->id, parms->u.qam.symbol_rate, |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 836 | fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max); |
| 837 | return -EINVAL; |
| 838 | } |
| 839 | } |
| 840 | |
Janne Grunau | f51fad8 | 2009-09-01 19:24:08 -0300 | [diff] [blame] | 841 | /* check for supported modulation */ |
| 842 | if (fe->ops.info.type == FE_QAM && |
| 843 | (parms->u.qam.modulation > QAM_AUTO || |
| 844 | !((1 << (parms->u.qam.modulation + 10)) & fe->ops.info.caps))) { |
| 845 | printk(KERN_WARNING "DVB: adapter %i frontend %i modulation %u not supported\n", |
| 846 | fe->dvb->num, fe->id, parms->u.qam.modulation); |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 850 | return 0; |
| 851 | } |
| 852 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 853 | static struct dtv_cmds_h dtv_cmds[] = { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 854 | [DTV_TUNE] = { |
| 855 | .name = "DTV_TUNE", |
| 856 | .cmd = DTV_TUNE, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 857 | .set = 1, |
| 858 | }, |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 859 | [DTV_CLEAR] = { |
| 860 | .name = "DTV_CLEAR", |
| 861 | .cmd = DTV_CLEAR, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 862 | .set = 1, |
| 863 | }, |
| 864 | |
| 865 | /* Set */ |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 866 | [DTV_FREQUENCY] = { |
| 867 | .name = "DTV_FREQUENCY", |
| 868 | .cmd = DTV_FREQUENCY, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 869 | .set = 1, |
| 870 | }, |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 871 | [DTV_BANDWIDTH_HZ] = { |
| 872 | .name = "DTV_BANDWIDTH_HZ", |
| 873 | .cmd = DTV_BANDWIDTH_HZ, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 874 | .set = 1, |
| 875 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 876 | [DTV_MODULATION] = { |
| 877 | .name = "DTV_MODULATION", |
| 878 | .cmd = DTV_MODULATION, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 879 | .set = 1, |
| 880 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 881 | [DTV_INVERSION] = { |
| 882 | .name = "DTV_INVERSION", |
| 883 | .cmd = DTV_INVERSION, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 884 | .set = 1, |
| 885 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 886 | [DTV_DISEQC_MASTER] = { |
| 887 | .name = "DTV_DISEQC_MASTER", |
| 888 | .cmd = DTV_DISEQC_MASTER, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 889 | .set = 1, |
| 890 | .buffer = 1, |
| 891 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 892 | [DTV_SYMBOL_RATE] = { |
| 893 | .name = "DTV_SYMBOL_RATE", |
| 894 | .cmd = DTV_SYMBOL_RATE, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 895 | .set = 1, |
| 896 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 897 | [DTV_INNER_FEC] = { |
| 898 | .name = "DTV_INNER_FEC", |
| 899 | .cmd = DTV_INNER_FEC, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 900 | .set = 1, |
| 901 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 902 | [DTV_VOLTAGE] = { |
| 903 | .name = "DTV_VOLTAGE", |
| 904 | .cmd = DTV_VOLTAGE, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 905 | .set = 1, |
| 906 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 907 | [DTV_TONE] = { |
| 908 | .name = "DTV_TONE", |
| 909 | .cmd = DTV_TONE, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 910 | .set = 1, |
| 911 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 912 | [DTV_PILOT] = { |
| 913 | .name = "DTV_PILOT", |
| 914 | .cmd = DTV_PILOT, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 915 | .set = 1, |
| 916 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 917 | [DTV_ROLLOFF] = { |
| 918 | .name = "DTV_ROLLOFF", |
| 919 | .cmd = DTV_ROLLOFF, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 920 | .set = 1, |
| 921 | }, |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 922 | [DTV_DELIVERY_SYSTEM] = { |
| 923 | .name = "DTV_DELIVERY_SYSTEM", |
| 924 | .cmd = DTV_DELIVERY_SYSTEM, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 925 | .set = 1, |
| 926 | }, |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 927 | [DTV_HIERARCHY] = { |
| 928 | .name = "DTV_HIERARCHY", |
| 929 | .cmd = DTV_HIERARCHY, |
| 930 | .set = 1, |
| 931 | }, |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 932 | [DTV_CODE_RATE_HP] = { |
| 933 | .name = "DTV_CODE_RATE_HP", |
| 934 | .cmd = DTV_CODE_RATE_HP, |
| 935 | .set = 1, |
| 936 | }, |
| 937 | [DTV_CODE_RATE_LP] = { |
| 938 | .name = "DTV_CODE_RATE_LP", |
| 939 | .cmd = DTV_CODE_RATE_LP, |
| 940 | .set = 1, |
| 941 | }, |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 942 | [DTV_GUARD_INTERVAL] = { |
| 943 | .name = "DTV_GUARD_INTERVAL", |
| 944 | .cmd = DTV_GUARD_INTERVAL, |
| 945 | .set = 1, |
| 946 | }, |
| 947 | [DTV_TRANSMISSION_MODE] = { |
| 948 | .name = "DTV_TRANSMISSION_MODE", |
| 949 | .cmd = DTV_TRANSMISSION_MODE, |
| 950 | .set = 1, |
| 951 | }, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 952 | /* Get */ |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 953 | [DTV_DISEQC_SLAVE_REPLY] = { |
| 954 | .name = "DTV_DISEQC_SLAVE_REPLY", |
| 955 | .cmd = DTV_DISEQC_SLAVE_REPLY, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 956 | .set = 0, |
| 957 | .buffer = 1, |
| 958 | }, |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 959 | [DTV_API_VERSION] = { |
| 960 | .name = "DTV_API_VERSION", |
| 961 | .cmd = DTV_API_VERSION, |
| 962 | .set = 0, |
| 963 | }, |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 964 | [DTV_CODE_RATE_HP] = { |
| 965 | .name = "DTV_CODE_RATE_HP", |
| 966 | .cmd = DTV_CODE_RATE_HP, |
| 967 | .set = 0, |
| 968 | }, |
| 969 | [DTV_CODE_RATE_LP] = { |
| 970 | .name = "DTV_CODE_RATE_LP", |
| 971 | .cmd = DTV_CODE_RATE_LP, |
| 972 | .set = 0, |
| 973 | }, |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 974 | [DTV_GUARD_INTERVAL] = { |
| 975 | .name = "DTV_GUARD_INTERVAL", |
| 976 | .cmd = DTV_GUARD_INTERVAL, |
| 977 | .set = 0, |
| 978 | }, |
| 979 | [DTV_TRANSMISSION_MODE] = { |
| 980 | .name = "DTV_TRANSMISSION_MODE", |
| 981 | .cmd = DTV_TRANSMISSION_MODE, |
| 982 | .set = 0, |
| 983 | }, |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 984 | [DTV_HIERARCHY] = { |
| 985 | .name = "DTV_HIERARCHY", |
| 986 | .cmd = DTV_HIERARCHY, |
| 987 | .set = 0, |
| 988 | }, |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 989 | }; |
| 990 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 991 | static void dtv_property_dump(struct dtv_property *tvp) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 992 | { |
| 993 | int i; |
| 994 | |
Steven Toth | 82d7669 | 2008-10-06 20:44:04 -0300 | [diff] [blame] | 995 | if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) { |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 996 | printk(KERN_WARNING "%s: tvp.cmd = 0x%08x undefined\n", |
Darron Broad | 4aae8ef | 2008-10-03 11:50:00 -0300 | [diff] [blame] | 997 | __func__, tvp->cmd); |
| 998 | return; |
| 999 | } |
| 1000 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1001 | dprintk("%s() tvp.cmd = 0x%08x (%s)\n" |
| 1002 | ,__func__ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1003 | ,tvp->cmd |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1004 | ,dtv_cmds[ tvp->cmd ].name); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1005 | |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1006 | if(dtv_cmds[ tvp->cmd ].buffer) { |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1007 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1008 | dprintk("%s() tvp.u.buffer.len = 0x%02x\n" |
| 1009 | ,__func__ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1010 | ,tvp->u.buffer.len); |
| 1011 | |
| 1012 | for(i = 0; i < tvp->u.buffer.len; i++) |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1013 | dprintk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n" |
| 1014 | ,__func__ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1015 | ,i |
| 1016 | ,tvp->u.buffer.data[i]); |
| 1017 | |
| 1018 | } else |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1019 | dprintk("%s() tvp.u.data = 0x%08x\n", __func__, tvp->u.data); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1020 | } |
| 1021 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1022 | static int is_legacy_delivery_system(fe_delivery_system_t s) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1023 | { |
| 1024 | if((s == SYS_UNDEFINED) || (s == SYS_DVBC_ANNEX_AC) || |
Devin Heitmueller | 3fa37de | 2008-11-16 00:33:32 -0300 | [diff] [blame] | 1025 | (s == SYS_DVBC_ANNEX_B) || (s == SYS_DVBT) || (s == SYS_DVBS) || |
| 1026 | (s == SYS_ATSC)) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1027 | return 1; |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1032 | /* Synchronise the legacy tuning parameters into the cache, so that demodulator |
| 1033 | * drivers can use a single set_frontend tuning function, regardless of whether |
| 1034 | * it's being used for the legacy or new API, reducing code and complexity. |
| 1035 | */ |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1036 | static void dtv_property_cache_sync(struct dvb_frontend *fe, |
| 1037 | struct dvb_frontend_parameters *p) |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1038 | { |
| 1039 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1040 | |
| 1041 | c->frequency = p->frequency; |
| 1042 | c->inversion = p->inversion; |
| 1043 | |
| 1044 | switch (fe->ops.info.type) { |
| 1045 | case FE_QPSK: |
Darron Broad | e5cefa8 | 2008-10-03 11:53:18 -0300 | [diff] [blame] | 1046 | c->modulation = QPSK; /* implied for DVB-S in legacy API */ |
| 1047 | c->rolloff = ROLLOFF_35;/* implied for DVB-S */ |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1048 | c->symbol_rate = p->u.qpsk.symbol_rate; |
| 1049 | c->fec_inner = p->u.qpsk.fec_inner; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1050 | c->delivery_system = SYS_DVBS; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1051 | break; |
| 1052 | case FE_QAM: |
| 1053 | c->symbol_rate = p->u.qam.symbol_rate; |
| 1054 | c->fec_inner = p->u.qam.fec_inner; |
| 1055 | c->modulation = p->u.qam.modulation; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1056 | c->delivery_system = SYS_DVBC_ANNEX_AC; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1057 | break; |
| 1058 | case FE_OFDM: |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1059 | if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ) |
| 1060 | c->bandwidth_hz = 6000000; |
| 1061 | else if (p->u.ofdm.bandwidth == BANDWIDTH_7_MHZ) |
| 1062 | c->bandwidth_hz = 7000000; |
| 1063 | else if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) |
| 1064 | c->bandwidth_hz = 8000000; |
| 1065 | else |
| 1066 | /* Including BANDWIDTH_AUTO */ |
| 1067 | c->bandwidth_hz = 0; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1068 | c->code_rate_HP = p->u.ofdm.code_rate_HP; |
| 1069 | c->code_rate_LP = p->u.ofdm.code_rate_LP; |
| 1070 | c->modulation = p->u.ofdm.constellation; |
| 1071 | c->transmission_mode = p->u.ofdm.transmission_mode; |
| 1072 | c->guard_interval = p->u.ofdm.guard_interval; |
| 1073 | c->hierarchy = p->u.ofdm.hierarchy_information; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1074 | c->delivery_system = SYS_DVBT; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1075 | break; |
| 1076 | case FE_ATSC: |
| 1077 | c->modulation = p->u.vsb.modulation; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1078 | if ((c->modulation == VSB_8) || (c->modulation == VSB_16)) |
| 1079 | c->delivery_system = SYS_ATSC; |
| 1080 | else |
| 1081 | c->delivery_system = SYS_DVBC_ANNEX_B; |
Steven Toth | ee33c52 | 2008-09-11 23:52:32 -0300 | [diff] [blame] | 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1086 | /* Ensure the cached values are set correctly in the frontend |
| 1087 | * legacy tuning structures, for the advanced tuning API. |
| 1088 | */ |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1089 | static void dtv_property_legacy_params_sync(struct dvb_frontend *fe) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1090 | { |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1091 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1092 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1093 | struct dvb_frontend_parameters *p = &fepriv->parameters; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1094 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1095 | p->frequency = c->frequency; |
| 1096 | p->inversion = c->inversion; |
| 1097 | |
| 1098 | switch (fe->ops.info.type) { |
| 1099 | case FE_QPSK: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1100 | dprintk("%s() Preparing QPSK req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1101 | p->u.qpsk.symbol_rate = c->symbol_rate; |
| 1102 | p->u.qpsk.fec_inner = c->fec_inner; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1103 | c->delivery_system = SYS_DVBS; |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1104 | break; |
| 1105 | case FE_QAM: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1106 | dprintk("%s() Preparing QAM req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1107 | p->u.qam.symbol_rate = c->symbol_rate; |
| 1108 | p->u.qam.fec_inner = c->fec_inner; |
| 1109 | p->u.qam.modulation = c->modulation; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1110 | c->delivery_system = SYS_DVBC_ANNEX_AC; |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1111 | break; |
| 1112 | case FE_OFDM: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1113 | dprintk("%s() Preparing OFDM req\n", __func__); |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1114 | if (c->bandwidth_hz == 6000000) |
| 1115 | p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ; |
| 1116 | else if (c->bandwidth_hz == 7000000) |
| 1117 | p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ; |
| 1118 | else if (c->bandwidth_hz == 8000000) |
| 1119 | p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ; |
| 1120 | else |
| 1121 | p->u.ofdm.bandwidth = BANDWIDTH_AUTO; |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1122 | p->u.ofdm.code_rate_HP = c->code_rate_HP; |
| 1123 | p->u.ofdm.code_rate_LP = c->code_rate_LP; |
| 1124 | p->u.ofdm.constellation = c->modulation; |
| 1125 | p->u.ofdm.transmission_mode = c->transmission_mode; |
| 1126 | p->u.ofdm.guard_interval = c->guard_interval; |
| 1127 | p->u.ofdm.hierarchy_information = c->hierarchy; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1128 | c->delivery_system = SYS_DVBT; |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1129 | break; |
| 1130 | case FE_ATSC: |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1131 | dprintk("%s() Preparing VSB req\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1132 | p->u.vsb.modulation = c->modulation; |
Steven Toth | 80a773c | 2008-09-12 00:53:50 -0300 | [diff] [blame] | 1133 | if ((c->modulation == VSB_8) || (c->modulation == VSB_16)) |
| 1134 | c->delivery_system = SYS_ATSC; |
| 1135 | else |
| 1136 | c->delivery_system = SYS_DVBC_ANNEX_B; |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | /* Ensure the cached values are set correctly in the frontend |
| 1142 | * legacy tuning structures, for the legacy tuning API. |
| 1143 | */ |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1144 | static void dtv_property_adv_params_sync(struct dvb_frontend *fe) |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1145 | { |
| 1146 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1147 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 1148 | struct dvb_frontend_parameters *p = &fepriv->parameters; |
| 1149 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1150 | p->frequency = c->frequency; |
| 1151 | p->inversion = c->inversion; |
| 1152 | |
| 1153 | switch(c->modulation) { |
Steven Toth | 0a6393a | 2008-10-06 21:06:48 -0300 | [diff] [blame] | 1154 | case PSK_8: |
| 1155 | case APSK_16: |
Manu Abraham | 9785482 | 2008-10-14 19:48:07 -0300 | [diff] [blame] | 1156 | case APSK_32: |
Steven Toth | 0a6393a | 2008-10-06 21:06:48 -0300 | [diff] [blame] | 1157 | case QPSK: |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1158 | p->u.qpsk.symbol_rate = c->symbol_rate; |
| 1159 | p->u.qpsk.fec_inner = c->fec_inner; |
| 1160 | break; |
| 1161 | default: |
| 1162 | break; |
| 1163 | } |
| 1164 | |
| 1165 | if(c->delivery_system == SYS_ISDBT) { |
| 1166 | /* Fake out a generic DVB-T request so we pass validation in the ioctl */ |
| 1167 | p->frequency = c->frequency; |
| 1168 | p->inversion = INVERSION_AUTO; |
| 1169 | p->u.ofdm.constellation = QAM_AUTO; |
| 1170 | p->u.ofdm.code_rate_HP = FEC_AUTO; |
| 1171 | p->u.ofdm.code_rate_LP = FEC_AUTO; |
| 1172 | p->u.ofdm.bandwidth = BANDWIDTH_AUTO; |
| 1173 | p->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO; |
| 1174 | p->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO; |
| 1175 | p->u.ofdm.hierarchy_information = HIERARCHY_AUTO; |
| 1176 | } |
| 1177 | } |
| 1178 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1179 | static void dtv_property_cache_submit(struct dvb_frontend *fe) |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1180 | { |
| 1181 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1182 | |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1183 | /* For legacy delivery systems we don't need the delivery_system to |
| 1184 | * be specified, but we populate the older structures from the cache |
| 1185 | * so we can call set_frontend on older drivers. |
| 1186 | */ |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1187 | if(is_legacy_delivery_system(c->delivery_system)) { |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1188 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1189 | dprintk("%s() legacy, modulation = %d\n", __func__, c->modulation); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1190 | dtv_property_legacy_params_sync(fe); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1191 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1192 | } else { |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1193 | dprintk("%s() adv, modulation = %d\n", __func__, c->modulation); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1194 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1195 | /* For advanced delivery systems / modulation types ... |
| 1196 | * we seed the lecacy dvb_frontend_parameters structure |
| 1197 | * so that the sanity checking code later in the IOCTL processing |
| 1198 | * can validate our basic frequency ranges, symbolrates, modulation |
| 1199 | * etc. |
| 1200 | */ |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1201 | dtv_property_adv_params_sync(fe); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1202 | } |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1203 | } |
| 1204 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1205 | static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file, |
| 1206 | unsigned int cmd, void *parg); |
| 1207 | static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file, |
| 1208 | unsigned int cmd, void *parg); |
| 1209 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1210 | static int dtv_property_process_get(struct dvb_frontend *fe, |
| 1211 | struct dtv_property *tvp, |
| 1212 | struct inode *inode, struct file *file) |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1213 | { |
| 1214 | int r = 0; |
| 1215 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1216 | dtv_property_dump(tvp); |
| 1217 | |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1218 | /* Allow the frontend to validate incoming properties */ |
| 1219 | if (fe->ops.get_property) |
| 1220 | r = fe->ops.get_property(fe, tvp); |
| 1221 | |
| 1222 | if (r < 0) |
| 1223 | return r; |
| 1224 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1225 | switch(tvp->cmd) { |
| 1226 | case DTV_FREQUENCY: |
| 1227 | tvp->u.data = fe->dtv_property_cache.frequency; |
| 1228 | break; |
| 1229 | case DTV_MODULATION: |
| 1230 | tvp->u.data = fe->dtv_property_cache.modulation; |
| 1231 | break; |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1232 | case DTV_BANDWIDTH_HZ: |
| 1233 | tvp->u.data = fe->dtv_property_cache.bandwidth_hz; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1234 | break; |
| 1235 | case DTV_INVERSION: |
| 1236 | tvp->u.data = fe->dtv_property_cache.inversion; |
| 1237 | break; |
| 1238 | case DTV_SYMBOL_RATE: |
| 1239 | tvp->u.data = fe->dtv_property_cache.symbol_rate; |
| 1240 | break; |
| 1241 | case DTV_INNER_FEC: |
| 1242 | tvp->u.data = fe->dtv_property_cache.fec_inner; |
| 1243 | break; |
| 1244 | case DTV_PILOT: |
| 1245 | tvp->u.data = fe->dtv_property_cache.pilot; |
| 1246 | break; |
| 1247 | case DTV_ROLLOFF: |
| 1248 | tvp->u.data = fe->dtv_property_cache.rolloff; |
| 1249 | break; |
| 1250 | case DTV_DELIVERY_SYSTEM: |
| 1251 | tvp->u.data = fe->dtv_property_cache.delivery_system; |
| 1252 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1253 | case DTV_VOLTAGE: |
| 1254 | tvp->u.data = fe->dtv_property_cache.voltage; |
| 1255 | break; |
| 1256 | case DTV_TONE: |
| 1257 | tvp->u.data = fe->dtv_property_cache.sectone; |
| 1258 | break; |
Steven Toth | eacf8d8 | 2008-09-26 00:29:49 -0300 | [diff] [blame] | 1259 | case DTV_API_VERSION: |
| 1260 | tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR; |
| 1261 | break; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1262 | case DTV_CODE_RATE_HP: |
| 1263 | tvp->u.data = fe->dtv_property_cache.code_rate_HP; |
| 1264 | break; |
| 1265 | case DTV_CODE_RATE_LP: |
| 1266 | tvp->u.data = fe->dtv_property_cache.code_rate_LP; |
| 1267 | break; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1268 | case DTV_GUARD_INTERVAL: |
| 1269 | tvp->u.data = fe->dtv_property_cache.guard_interval; |
| 1270 | break; |
| 1271 | case DTV_TRANSMISSION_MODE: |
| 1272 | tvp->u.data = fe->dtv_property_cache.transmission_mode; |
| 1273 | break; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1274 | case DTV_HIERARCHY: |
| 1275 | tvp->u.data = fe->dtv_property_cache.hierarchy; |
| 1276 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1277 | default: |
| 1278 | r = -1; |
| 1279 | } |
| 1280 | |
| 1281 | return r; |
| 1282 | } |
| 1283 | |
Mauro Carvalho Chehab | 072ce0c | 2009-01-05 01:19:06 -0300 | [diff] [blame] | 1284 | static int dtv_property_process_set(struct dvb_frontend *fe, |
| 1285 | struct dtv_property *tvp, |
| 1286 | struct inode *inode, |
| 1287 | struct file *file) |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1288 | { |
| 1289 | int r = 0; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1290 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1291 | dtv_property_dump(tvp); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1292 | |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1293 | /* Allow the frontend to validate incoming properties */ |
| 1294 | if (fe->ops.set_property) |
| 1295 | r = fe->ops.set_property(fe, tvp); |
| 1296 | |
| 1297 | if (r < 0) |
| 1298 | return r; |
| 1299 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1300 | switch(tvp->cmd) { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1301 | case DTV_CLEAR: |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1302 | /* Reset a cache of data specific to the frontend here. This does |
| 1303 | * not effect hardware. |
| 1304 | */ |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1305 | dprintk("%s() Flushing property cache\n", __func__); |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1306 | memset(&fe->dtv_property_cache, 0, sizeof(struct dtv_frontend_properties)); |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1307 | fe->dtv_property_cache.state = tvp->cmd; |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1308 | fe->dtv_property_cache.delivery_system = SYS_UNDEFINED; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1309 | break; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1310 | case DTV_TUNE: |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1311 | /* interpret the cache of data, build either a traditional frontend |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1312 | * tunerequest so we can pass validation in the FE_SET_FRONTEND |
| 1313 | * ioctl. |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1314 | */ |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1315 | fe->dtv_property_cache.state = tvp->cmd; |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1316 | dprintk("%s() Finalised property cache\n", __func__); |
Steven Toth | d5748f1 | 2008-09-12 00:27:13 -0300 | [diff] [blame] | 1317 | dtv_property_cache_submit(fe); |
| 1318 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1319 | r |= dvb_frontend_ioctl_legacy(inode, file, FE_SET_FRONTEND, |
| 1320 | &fepriv->parameters); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1321 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1322 | case DTV_FREQUENCY: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1323 | fe->dtv_property_cache.frequency = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1324 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1325 | case DTV_MODULATION: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1326 | fe->dtv_property_cache.modulation = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1327 | break; |
Steven Toth | 75b7f94 | 2008-09-13 16:56:34 -0300 | [diff] [blame] | 1328 | case DTV_BANDWIDTH_HZ: |
| 1329 | fe->dtv_property_cache.bandwidth_hz = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1330 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1331 | case DTV_INVERSION: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1332 | fe->dtv_property_cache.inversion = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1333 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1334 | case DTV_SYMBOL_RATE: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1335 | fe->dtv_property_cache.symbol_rate = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1336 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1337 | case DTV_INNER_FEC: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1338 | fe->dtv_property_cache.fec_inner = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1339 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1340 | case DTV_PILOT: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1341 | fe->dtv_property_cache.pilot = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1342 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1343 | case DTV_ROLLOFF: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1344 | fe->dtv_property_cache.rolloff = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1345 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1346 | case DTV_DELIVERY_SYSTEM: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1347 | fe->dtv_property_cache.delivery_system = tvp->u.data; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1348 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1349 | case DTV_VOLTAGE: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1350 | fe->dtv_property_cache.voltage = tvp->u.data; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1351 | r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_VOLTAGE, |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1352 | (void *)fe->dtv_property_cache.voltage); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1353 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1354 | case DTV_TONE: |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1355 | fe->dtv_property_cache.sectone = tvp->u.data; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1356 | r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_TONE, |
Steven Toth | 56f0680 | 2008-09-11 10:19:27 -0300 | [diff] [blame] | 1357 | (void *)fe->dtv_property_cache.sectone); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1358 | break; |
Steven Toth | a4de91b | 2008-10-06 21:55:46 -0300 | [diff] [blame] | 1359 | case DTV_CODE_RATE_HP: |
| 1360 | fe->dtv_property_cache.code_rate_HP = tvp->u.data; |
| 1361 | break; |
| 1362 | case DTV_CODE_RATE_LP: |
| 1363 | fe->dtv_property_cache.code_rate_LP = tvp->u.data; |
| 1364 | break; |
Steven Toth | b87625f | 2008-10-06 21:56:59 -0300 | [diff] [blame] | 1365 | case DTV_GUARD_INTERVAL: |
| 1366 | fe->dtv_property_cache.guard_interval = tvp->u.data; |
| 1367 | break; |
| 1368 | case DTV_TRANSMISSION_MODE: |
| 1369 | fe->dtv_property_cache.transmission_mode = tvp->u.data; |
| 1370 | break; |
Steven Toth | ef526f4 | 2008-10-06 22:01:47 -0300 | [diff] [blame] | 1371 | case DTV_HIERARCHY: |
| 1372 | fe->dtv_property_cache.hierarchy = tvp->u.data; |
| 1373 | break; |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1374 | default: |
| 1375 | r = -1; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1376 | } |
| 1377 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1378 | return r; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1379 | } |
| 1380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | static int dvb_frontend_ioctl(struct inode *inode, struct file *file, |
| 1382 | unsigned int cmd, void *parg) |
| 1383 | { |
| 1384 | struct dvb_device *dvbdev = file->private_data; |
| 1385 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1386 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | int err = -EOPNOTSUPP; |
| 1388 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1389 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Adrian Bunk | 813ce47 | 2007-08-01 10:13:36 -0300 | [diff] [blame] | 1391 | if (fepriv->exit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | return -ENODEV; |
| 1393 | |
| 1394 | if ((file->f_flags & O_ACCMODE) == O_RDONLY && |
| 1395 | (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT || |
| 1396 | cmd == FE_DISEQC_RECV_SLAVE_REPLY)) |
| 1397 | return -EPERM; |
| 1398 | |
| 1399 | if (down_interruptible (&fepriv->sem)) |
| 1400 | return -ERESTARTSYS; |
| 1401 | |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1402 | if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY)) |
| 1403 | err = dvb_frontend_ioctl_properties(inode, file, cmd, parg); |
Steven Toth | 4dd88be | 2008-09-13 15:09:07 -0300 | [diff] [blame] | 1404 | else { |
| 1405 | fe->dtv_property_cache.state = DTV_UNDEFINED; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1406 | err = dvb_frontend_ioctl_legacy(inode, file, cmd, parg); |
Steven Toth | 4dd88be | 2008-09-13 15:09:07 -0300 | [diff] [blame] | 1407 | } |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1408 | |
| 1409 | up(&fepriv->sem); |
| 1410 | return err; |
| 1411 | } |
| 1412 | |
| 1413 | static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file, |
| 1414 | unsigned int cmd, void *parg) |
| 1415 | { |
| 1416 | struct dvb_device *dvbdev = file->private_data; |
| 1417 | struct dvb_frontend *fe = dvbdev->priv; |
Igor M. Liplianin | e6f9ec8 | 2008-09-12 14:49:06 -0300 | [diff] [blame] | 1418 | int err = 0; |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1419 | |
| 1420 | struct dtv_properties *tvps = NULL; |
| 1421 | struct dtv_property *tvp = NULL; |
| 1422 | int i; |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1423 | |
| 1424 | dprintk("%s\n", __func__); |
| 1425 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1426 | if(cmd == FE_SET_PROPERTY) { |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1427 | tvps = (struct dtv_properties __user *)parg; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1428 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1429 | dprintk("%s() properties.num = %d\n", __func__, tvps->num); |
| 1430 | dprintk("%s() properties.props = %p\n", __func__, tvps->props); |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1431 | |
| 1432 | /* Put an arbitrary limit on the number of messages that can |
| 1433 | * be sent at once */ |
Steven Toth | 6068f50 | 2008-10-06 22:46:08 -0300 | [diff] [blame] | 1434 | if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1435 | return -EINVAL; |
| 1436 | |
| 1437 | tvp = (struct dtv_property *) kmalloc(tvps->num * |
| 1438 | sizeof(struct dtv_property), GFP_KERNEL); |
| 1439 | if (!tvp) { |
| 1440 | err = -ENOMEM; |
| 1441 | goto out; |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1442 | } |
| 1443 | |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1444 | if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) { |
| 1445 | err = -EFAULT; |
| 1446 | goto out; |
| 1447 | } |
| 1448 | |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 1449 | for (i = 0; i < tvps->num; i++) { |
| 1450 | (tvp + i)->result = dtv_property_process_set(fe, tvp + i, inode, file); |
| 1451 | err |= (tvp + i)->result; |
| 1452 | } |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1453 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1454 | if(fe->dtv_property_cache.state == DTV_TUNE) |
| 1455 | dprintk("%s() Property cache is full, tuning\n", __func__); |
Steven Toth | bfbf2da | 2008-09-12 01:37:37 -0300 | [diff] [blame] | 1456 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1457 | } else |
| 1458 | if(cmd == FE_GET_PROPERTY) { |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1459 | |
| 1460 | tvps = (struct dtv_properties __user *)parg; |
| 1461 | |
Steven Toth | a1bc84c | 2008-10-17 00:20:19 -0300 | [diff] [blame] | 1462 | dprintk("%s() properties.num = %d\n", __func__, tvps->num); |
| 1463 | dprintk("%s() properties.props = %p\n", __func__, tvps->props); |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1464 | |
| 1465 | /* Put an arbitrary limit on the number of messages that can |
| 1466 | * be sent at once */ |
Steven Toth | 6068f50 | 2008-10-06 22:46:08 -0300 | [diff] [blame] | 1467 | if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1468 | return -EINVAL; |
| 1469 | |
| 1470 | tvp = (struct dtv_property *) kmalloc(tvps->num * |
| 1471 | sizeof(struct dtv_property), GFP_KERNEL); |
| 1472 | if (!tvp) { |
| 1473 | err = -ENOMEM; |
| 1474 | goto out; |
| 1475 | } |
| 1476 | |
| 1477 | if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) { |
| 1478 | err = -EFAULT; |
| 1479 | goto out; |
| 1480 | } |
| 1481 | |
Steven Toth | d48cb40 | 2008-09-26 00:16:25 -0300 | [diff] [blame] | 1482 | for (i = 0; i < tvps->num; i++) { |
| 1483 | (tvp + i)->result = dtv_property_process_get(fe, tvp + i, inode, file); |
| 1484 | err |= (tvp + i)->result; |
| 1485 | } |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1486 | |
| 1487 | if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) { |
| 1488 | err = -EFAULT; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | |
Steven Toth | 363429a | 2008-09-12 01:34:28 -0300 | [diff] [blame] | 1492 | } else |
| 1493 | err = -EOPNOTSUPP; |
| 1494 | |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1495 | out: |
| 1496 | kfree(tvp); |
Steven Toth | 13c97bf | 2008-09-04 21:19:43 -0300 | [diff] [blame] | 1497 | return err; |
| 1498 | } |
| 1499 | |
| 1500 | static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file, |
| 1501 | unsigned int cmd, void *parg) |
| 1502 | { |
| 1503 | struct dvb_device *dvbdev = file->private_data; |
| 1504 | struct dvb_frontend *fe = dvbdev->priv; |
| 1505 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
| 1506 | int err = -EOPNOTSUPP; |
| 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | switch (cmd) { |
| 1509 | case FE_GET_INFO: { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1510 | struct dvb_frontend_info* info = parg; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1511 | memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info)); |
Oliver Endriss | c471b33 | 2007-08-09 01:03:42 -0300 | [diff] [blame] | 1512 | dvb_frontend_get_frequeny_limits(fe, &info->frequency_min, &info->frequency_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
| 1514 | /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't |
| 1515 | * do it, it is done for it. */ |
| 1516 | info->caps |= FE_CAN_INVERSION_AUTO; |
| 1517 | err = 0; |
| 1518 | break; |
| 1519 | } |
| 1520 | |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 1521 | case FE_READ_STATUS: { |
| 1522 | fe_status_t* status = parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 1524 | /* if retune was requested but hasn't occured yet, prevent |
| 1525 | * that user get signal state from previous tuning */ |
Janne Grunau | 0188625 | 2009-09-01 19:23:09 -0300 | [diff] [blame] | 1526 | if (fepriv->state == FESTATE_RETUNE || |
| 1527 | fepriv->state == FESTATE_ERROR) { |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 1528 | err=0; |
| 1529 | *status = 0; |
| 1530 | break; |
| 1531 | } |
| 1532 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1533 | if (fe->ops.read_status) |
| 1534 | err = fe->ops.read_status(fe, status); |
Peter Beutner | 6757ccc | 2005-07-07 17:57:36 -0700 | [diff] [blame] | 1535 | break; |
| 1536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | case FE_READ_BER: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1538 | if (fe->ops.read_ber) |
| 1539 | err = fe->ops.read_ber(fe, (__u32*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | break; |
| 1541 | |
| 1542 | case FE_READ_SIGNAL_STRENGTH: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1543 | if (fe->ops.read_signal_strength) |
| 1544 | err = fe->ops.read_signal_strength(fe, (__u16*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | break; |
| 1546 | |
| 1547 | case FE_READ_SNR: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1548 | if (fe->ops.read_snr) |
| 1549 | err = fe->ops.read_snr(fe, (__u16*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | break; |
| 1551 | |
| 1552 | case FE_READ_UNCORRECTED_BLOCKS: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1553 | if (fe->ops.read_ucblocks) |
| 1554 | err = fe->ops.read_ucblocks(fe, (__u32*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | break; |
| 1556 | |
| 1557 | |
| 1558 | case FE_DISEQC_RESET_OVERLOAD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1559 | if (fe->ops.diseqc_reset_overload) { |
| 1560 | err = fe->ops.diseqc_reset_overload(fe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | fepriv->state = FESTATE_DISEQC; |
| 1562 | fepriv->status = 0; |
| 1563 | } |
| 1564 | break; |
| 1565 | |
| 1566 | case FE_DISEQC_SEND_MASTER_CMD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1567 | if (fe->ops.diseqc_send_master_cmd) { |
| 1568 | 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] | 1569 | fepriv->state = FESTATE_DISEQC; |
| 1570 | fepriv->status = 0; |
| 1571 | } |
| 1572 | break; |
| 1573 | |
| 1574 | case FE_DISEQC_SEND_BURST: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1575 | if (fe->ops.diseqc_send_burst) { |
| 1576 | 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] | 1577 | fepriv->state = FESTATE_DISEQC; |
| 1578 | fepriv->status = 0; |
| 1579 | } |
| 1580 | break; |
| 1581 | |
| 1582 | case FE_SET_TONE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1583 | if (fe->ops.set_tone) { |
| 1584 | 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] | 1585 | fepriv->tone = (fe_sec_tone_mode_t) parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | fepriv->state = FESTATE_DISEQC; |
| 1587 | fepriv->status = 0; |
| 1588 | } |
| 1589 | break; |
| 1590 | |
| 1591 | case FE_SET_VOLTAGE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1592 | if (fe->ops.set_voltage) { |
| 1593 | err = fe->ops.set_voltage(fe, (fe_sec_voltage_t) parg); |
Andrew de Quincey | 6445401 | 2006-04-06 14:32:23 -0300 | [diff] [blame] | 1594 | fepriv->voltage = (fe_sec_voltage_t) parg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | fepriv->state = FESTATE_DISEQC; |
| 1596 | fepriv->status = 0; |
| 1597 | } |
| 1598 | break; |
| 1599 | |
| 1600 | case FE_DISHNETWORK_SEND_LEGACY_CMD: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1601 | if (fe->ops.dishnetwork_send_legacy_command) { |
| 1602 | err = fe->ops.dishnetwork_send_legacy_command(fe, (unsigned long) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | fepriv->state = FESTATE_DISEQC; |
| 1604 | fepriv->status = 0; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1605 | } else if (fe->ops.set_voltage) { |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1606 | /* |
| 1607 | * NOTE: This is a fallback condition. Some frontends |
| 1608 | * (stv0299 for instance) take longer than 8msec to |
| 1609 | * respond to a set_voltage command. Those switches |
| 1610 | * need custom routines to switch properly. For all |
| 1611 | * other frontends, the following shoule work ok. |
| 1612 | * Dish network legacy switches (as used by Dish500) |
| 1613 | * are controlled by sending 9-bit command words |
| 1614 | * spaced 8msec apart. |
| 1615 | * the actual command word is switch/port dependant |
| 1616 | * so it is up to the userspace application to send |
| 1617 | * the right command. |
| 1618 | * The command must always start with a '0' after |
| 1619 | * initialization, so parg is 8 bits and does not |
| 1620 | * include the initialization or start bit |
| 1621 | */ |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1622 | unsigned long swcmd = ((unsigned long) parg) << 1; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1623 | struct timeval nexttime; |
| 1624 | struct timeval tv[10]; |
| 1625 | int i; |
| 1626 | u8 last = 1; |
| 1627 | if (dvb_frontend_debug) |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1628 | printk("%s switch command: 0x%04lx\n", __func__, swcmd); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1629 | do_gettimeofday(&nexttime); |
| 1630 | if (dvb_frontend_debug) |
| 1631 | memcpy(&tv[0], &nexttime, sizeof(struct timeval)); |
| 1632 | /* before sending a command, initialize by sending |
| 1633 | * a 32ms 18V to the switch |
| 1634 | */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1635 | fe->ops.set_voltage(fe, SEC_VOLTAGE_18); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1636 | dvb_frontend_sleep_until(&nexttime, 32000); |
| 1637 | |
| 1638 | for (i = 0; i < 9; i++) { |
| 1639 | if (dvb_frontend_debug) |
| 1640 | do_gettimeofday(&tv[i + 1]); |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1641 | if ((swcmd & 0x01) != last) { |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1642 | /* set voltage to (last ? 13V : 18V) */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1643 | fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1644 | last = (last) ? 0 : 1; |
| 1645 | } |
Hans Verkuil | c6eb8ea | 2008-09-03 17:11:54 -0300 | [diff] [blame] | 1646 | swcmd = swcmd >> 1; |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1647 | if (i != 8) |
| 1648 | dvb_frontend_sleep_until(&nexttime, 8000); |
| 1649 | } |
| 1650 | if (dvb_frontend_debug) { |
| 1651 | 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] | 1652 | __func__, fe->dvb->num); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 1653 | for (i = 1; i < 10; i++) |
| 1654 | printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); |
| 1655 | } |
| 1656 | err = 0; |
| 1657 | fepriv->state = FESTATE_DISEQC; |
| 1658 | fepriv->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | } |
| 1660 | break; |
| 1661 | |
| 1662 | case FE_DISEQC_RECV_SLAVE_REPLY: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1663 | if (fe->ops.diseqc_recv_slave_reply) |
| 1664 | 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] | 1665 | break; |
| 1666 | |
| 1667 | case FE_ENABLE_HIGH_LNB_VOLTAGE: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1668 | if (fe->ops.enable_high_lnb_voltage) |
| 1669 | err = fe->ops.enable_high_lnb_voltage(fe, (long) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | break; |
| 1671 | |
| 1672 | case FE_SET_FRONTEND: { |
| 1673 | struct dvb_frontend_tune_settings fetunesettings; |
| 1674 | |
Steven Toth | e7fee0f3 | 2008-09-11 10:23:01 -0300 | [diff] [blame] | 1675 | if(fe->dtv_property_cache.state == DTV_TUNE) { |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1676 | if (dvb_frontend_check_parameters(fe, &fepriv->parameters) < 0) { |
| 1677 | err = -EINVAL; |
| 1678 | break; |
| 1679 | } |
| 1680 | } else { |
| 1681 | if (dvb_frontend_check_parameters(fe, parg) < 0) { |
| 1682 | err = -EINVAL; |
| 1683 | break; |
| 1684 | } |
Oliver Endriss | 1fab46f | 2007-07-23 21:00:36 -0300 | [diff] [blame] | 1685 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1686 | memcpy (&fepriv->parameters, parg, |
| 1687 | sizeof (struct dvb_frontend_parameters)); |
Steven Toth | 1d78cac | 2008-09-13 18:15:17 -0300 | [diff] [blame] | 1688 | dtv_property_cache_sync(fe, &fepriv->parameters); |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
| 1691 | memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings)); |
| 1692 | memcpy(&fetunesettings.parameters, parg, |
| 1693 | sizeof (struct dvb_frontend_parameters)); |
| 1694 | |
| 1695 | /* force auto frequency inversion if requested */ |
| 1696 | if (dvb_force_auto_inversion) { |
| 1697 | fepriv->parameters.inversion = INVERSION_AUTO; |
| 1698 | fetunesettings.parameters.inversion = INVERSION_AUTO; |
| 1699 | } |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1700 | if (fe->ops.info.type == FE_OFDM) { |
Uwe Kleine-König | 1b3c371 | 2007-02-17 19:23:03 +0100 | [diff] [blame] | 1701 | /* without hierarchical coding code_rate_LP is irrelevant, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | * so we tolerate the otherwise invalid FEC_NONE setting */ |
| 1703 | if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE && |
| 1704 | fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE) |
| 1705 | fepriv->parameters.u.ofdm.code_rate_LP = FEC_AUTO; |
| 1706 | } |
| 1707 | |
| 1708 | /* get frontend-specific tuning settings */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1709 | if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000; |
| 1711 | fepriv->max_drift = fetunesettings.max_drift; |
| 1712 | fepriv->step_size = fetunesettings.step_size; |
| 1713 | } else { |
| 1714 | /* default values */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1715 | switch(fe->ops.info.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | case FE_QPSK: |
| 1717 | fepriv->min_delay = HZ/20; |
| 1718 | fepriv->step_size = fepriv->parameters.u.qpsk.symbol_rate / 16000; |
| 1719 | fepriv->max_drift = fepriv->parameters.u.qpsk.symbol_rate / 2000; |
| 1720 | break; |
| 1721 | |
| 1722 | case FE_QAM: |
| 1723 | fepriv->min_delay = HZ/20; |
| 1724 | fepriv->step_size = 0; /* no zigzag */ |
| 1725 | fepriv->max_drift = 0; |
| 1726 | break; |
| 1727 | |
| 1728 | case FE_OFDM: |
| 1729 | fepriv->min_delay = HZ/20; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1730 | fepriv->step_size = fe->ops.info.frequency_stepsize * 2; |
| 1731 | fepriv->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | break; |
| 1733 | case FE_ATSC: |
Manu Abraham | 4821fb1 | 2006-06-21 10:27:00 -0300 | [diff] [blame] | 1734 | fepriv->min_delay = HZ/20; |
| 1735 | fepriv->step_size = 0; |
| 1736 | fepriv->max_drift = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | break; |
| 1738 | } |
| 1739 | } |
| 1740 | if (dvb_override_tune_delay > 0) |
| 1741 | fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000; |
| 1742 | |
| 1743 | fepriv->state = FESTATE_RETUNE; |
Igor M. Liplianin | 1d06059 | 2008-11-09 11:35:13 -0300 | [diff] [blame] | 1744 | |
| 1745 | /* Request the search algorithm to search */ |
| 1746 | fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; |
| 1747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | dvb_frontend_wakeup(fe); |
| 1749 | dvb_frontend_add_event(fe, 0); |
| 1750 | fepriv->status = 0; |
| 1751 | err = 0; |
| 1752 | break; |
| 1753 | } |
| 1754 | |
| 1755 | case FE_GET_EVENT: |
| 1756 | err = dvb_frontend_get_event (fe, parg, file->f_flags); |
| 1757 | break; |
| 1758 | |
| 1759 | case FE_GET_FRONTEND: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1760 | if (fe->ops.get_frontend) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | memcpy (parg, &fepriv->parameters, sizeof (struct dvb_frontend_parameters)); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1762 | err = fe->ops.get_frontend(fe, (struct dvb_frontend_parameters*) parg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | } |
| 1764 | break; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1765 | |
| 1766 | case FE_SET_FRONTEND_TUNE_MODE: |
Hans Verkuil | e18828e | 2006-01-09 15:25:28 -0200 | [diff] [blame] | 1767 | fepriv->tune_mode_flags = (unsigned long) parg; |
Trent Piepho | 1b172e0 | 2006-06-29 13:16:04 -0300 | [diff] [blame] | 1768 | err = 0; |
Andrew de Quincey | 36cb557 | 2006-01-09 15:25:07 -0200 | [diff] [blame] | 1769 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | }; |
| 1771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | return err; |
| 1773 | } |
| 1774 | |
Steven Toth | 6b73eea | 2008-09-04 01:12:25 -0300 | [diff] [blame] | 1775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait) |
| 1777 | { |
| 1778 | struct dvb_device *dvbdev = file->private_data; |
| 1779 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1780 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1782 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | |
| 1784 | poll_wait (file, &fepriv->events.wait_queue, wait); |
| 1785 | |
| 1786 | if (fepriv->events.eventw != fepriv->events.eventr) |
| 1787 | return (POLLIN | POLLRDNORM | POLLPRI); |
| 1788 | |
| 1789 | return 0; |
| 1790 | } |
| 1791 | |
| 1792 | static int dvb_frontend_open(struct inode *inode, struct file *file) |
| 1793 | { |
| 1794 | struct dvb_device *dvbdev = file->private_data; |
| 1795 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1796 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1797 | struct dvb_adapter *adapter = fe->dvb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | int ret; |
| 1799 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1800 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1802 | if (adapter->mfe_shared) { |
| 1803 | mutex_lock (&adapter->mfe_lock); |
Darron Broad | 6594690 | 2008-10-15 13:37:59 -0300 | [diff] [blame] | 1804 | |
| 1805 | if (adapter->mfe_dvbdev == NULL) |
| 1806 | adapter->mfe_dvbdev = dvbdev; |
| 1807 | |
| 1808 | else if (adapter->mfe_dvbdev != dvbdev) { |
| 1809 | struct dvb_device |
| 1810 | *mfedev = adapter->mfe_dvbdev; |
| 1811 | struct dvb_frontend |
| 1812 | *mfe = mfedev->priv; |
| 1813 | struct dvb_frontend_private |
| 1814 | *mfepriv = mfe->frontend_priv; |
| 1815 | int mferetry = (dvb_mfe_wait_time << 1); |
| 1816 | |
| 1817 | mutex_unlock (&adapter->mfe_lock); |
| 1818 | while (mferetry-- && (mfedev->users != -1 || |
| 1819 | mfepriv->thread != NULL)) { |
| 1820 | if(msleep_interruptible(500)) { |
| 1821 | if(signal_pending(current)) |
| 1822 | return -EINTR; |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1823 | } |
| 1824 | } |
Darron Broad | 6594690 | 2008-10-15 13:37:59 -0300 | [diff] [blame] | 1825 | |
| 1826 | mutex_lock (&adapter->mfe_lock); |
| 1827 | if(adapter->mfe_dvbdev != dvbdev) { |
| 1828 | mfedev = adapter->mfe_dvbdev; |
| 1829 | mfe = mfedev->priv; |
| 1830 | mfepriv = mfe->frontend_priv; |
| 1831 | if (mfedev->users != -1 || |
| 1832 | mfepriv->thread != NULL) { |
| 1833 | mutex_unlock (&adapter->mfe_lock); |
| 1834 | return -EBUSY; |
| 1835 | } |
| 1836 | adapter->mfe_dvbdev = dvbdev; |
| 1837 | } |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1838 | } |
| 1839 | } |
| 1840 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1841 | if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { |
| 1842 | if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1843 | goto err0; |
Steven Toth | ba7e6f3 | 2006-09-25 12:41:53 -0300 | [diff] [blame] | 1844 | } |
| 1845 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1846 | if ((ret = dvb_generic_open (inode, file)) < 0) |
| 1847 | goto err1; |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 1848 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1849 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { |
Andrew de Quincey | 04c56d0 | 2006-07-10 03:34:14 -0300 | [diff] [blame] | 1850 | /* normal tune mode when opened R/W */ |
| 1851 | fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT; |
| 1852 | fepriv->tone = -1; |
| 1853 | fepriv->voltage = -1; |
| 1854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | ret = dvb_frontend_start (fe); |
| 1856 | if (ret) |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1857 | goto err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | |
| 1859 | /* empty event queue */ |
| 1860 | fepriv->events.eventr = fepriv->events.eventw = 0; |
| 1861 | } |
| 1862 | |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1863 | if (adapter->mfe_shared) |
| 1864 | mutex_unlock (&adapter->mfe_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | return ret; |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1866 | |
| 1867 | err2: |
| 1868 | dvb_generic_release(inode, file); |
| 1869 | err1: |
| 1870 | if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) |
| 1871 | fe->ops.ts_bus_ctrl(fe, 0); |
Darron Broad | 59b1842 | 2008-10-11 11:44:05 -0300 | [diff] [blame] | 1872 | err0: |
| 1873 | if (adapter->mfe_shared) |
| 1874 | mutex_unlock (&adapter->mfe_lock); |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1875 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | static int dvb_frontend_release(struct inode *inode, struct file *file) |
| 1879 | { |
| 1880 | struct dvb_device *dvbdev = file->private_data; |
| 1881 | struct dvb_frontend *fe = dvbdev->priv; |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1882 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 1883 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1885 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | |
| 1887 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) |
| 1888 | fepriv->release_jiffies = jiffies; |
| 1889 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 1890 | ret = dvb_generic_release (inode, file); |
| 1891 | |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1892 | if (dvbdev->users == -1) { |
| 1893 | if (fepriv->exit == 1) { |
| 1894 | fops_put(file->f_op); |
| 1895 | file->f_op = NULL; |
| 1896 | wake_up(&dvbdev->wait_queue); |
| 1897 | } |
| 1898 | if (fe->ops.ts_bus_ctrl) |
| 1899 | fe->ops.ts_bus_ctrl(fe, 0); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 1900 | } |
Oliver Endriss | 48136e1 | 2007-08-25 12:00:23 -0300 | [diff] [blame] | 1901 | |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 1902 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Jan Engelhardt | 784e29d | 2009-01-11 06:12:43 -0300 | [diff] [blame] | 1905 | static const struct file_operations dvb_frontend_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | .owner = THIS_MODULE, |
| 1907 | .ioctl = dvb_generic_ioctl, |
| 1908 | .poll = dvb_frontend_poll, |
| 1909 | .open = dvb_frontend_open, |
| 1910 | .release = dvb_frontend_release |
| 1911 | }; |
| 1912 | |
| 1913 | int dvb_register_frontend(struct dvb_adapter* dvb, |
| 1914 | struct dvb_frontend* fe) |
| 1915 | { |
| 1916 | struct dvb_frontend_private *fepriv; |
| 1917 | static const struct dvb_device dvbdev_template = { |
| 1918 | .users = ~0, |
| 1919 | .writers = 1, |
| 1920 | .readers = (~0)-1, |
| 1921 | .fops = &dvb_frontend_fops, |
| 1922 | .kernel_ioctl = dvb_frontend_ioctl |
| 1923 | }; |
| 1924 | |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1925 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1927 | if (mutex_lock_interruptible(&frontend_mutex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | return -ERESTARTSYS; |
| 1929 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1930 | fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | if (fe->frontend_priv == NULL) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1932 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | return -ENOMEM; |
| 1934 | } |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1935 | fepriv = fe->frontend_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | |
| 1937 | init_MUTEX (&fepriv->sem); |
| 1938 | init_waitqueue_head (&fepriv->wait_queue); |
| 1939 | init_waitqueue_head (&fepriv->events.wait_queue); |
Matthias Kaehlcke | 03b7612 | 2007-07-30 14:58:10 -0300 | [diff] [blame] | 1940 | mutex_init(&fepriv->events.mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | fe->dvb = dvb; |
| 1942 | fepriv->inversion = INVERSION_OFF; |
| 1943 | |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 1944 | printk ("DVB: registering adapter %i frontend %i (%s)...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | fe->dvb->num, |
Steven Toth | 363c35f | 2008-10-11 11:05:50 -0300 | [diff] [blame] | 1946 | fe->id, |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 1947 | fe->ops.info.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
| 1949 | dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template, |
| 1950 | fe, DVB_DEVICE_FRONTEND); |
| 1951 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1952 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | return 0; |
| 1954 | } |
| 1955 | EXPORT_SYMBOL(dvb_register_frontend); |
| 1956 | |
| 1957 | int dvb_unregister_frontend(struct dvb_frontend* fe) |
| 1958 | { |
Johannes Stezenbach | 0c53c70 | 2005-05-16 21:54:24 -0700 | [diff] [blame] | 1959 | struct dvb_frontend_private *fepriv = fe->frontend_priv; |
Harvey Harrison | 46b4f7c | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1960 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
Markus Rechberger | 57861b4 | 2007-04-14 10:19:18 -0300 | [diff] [blame] | 1962 | mutex_lock(&frontend_mutex); |
Markus Rechberger | ca5be9c | 2007-04-14 10:18:58 -0300 | [diff] [blame] | 1963 | dvb_frontend_stop (fe); |
Markus Rechberger | 57861b4 | 2007-04-14 10:19:18 -0300 | [diff] [blame] | 1964 | mutex_unlock(&frontend_mutex); |
| 1965 | |
| 1966 | if (fepriv->dvbdev->users < -1) |
| 1967 | wait_event(fepriv->dvbdev->wait_queue, |
| 1968 | fepriv->dvbdev->users==-1); |
| 1969 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1970 | mutex_lock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | dvb_unregister_device (fepriv->dvbdev); |
Andrew de Quincey | d995506 | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 1972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | /* fe is invalid now */ |
| 1974 | kfree(fepriv); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1975 | mutex_unlock(&frontend_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | return 0; |
| 1977 | } |
| 1978 | EXPORT_SYMBOL(dvb_unregister_frontend); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 1979 | |
Mauro Carvalho Chehab | 149ef72 | 2008-04-29 21:38:46 -0300 | [diff] [blame] | 1980 | #ifdef CONFIG_MEDIA_ATTACH |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 1981 | void dvb_frontend_detach(struct dvb_frontend* fe) |
| 1982 | { |
| 1983 | void *ptr; |
| 1984 | |
| 1985 | if (fe->ops.release_sec) { |
| 1986 | fe->ops.release_sec(fe); |
| 1987 | symbol_put_addr(fe->ops.release_sec); |
| 1988 | } |
| 1989 | if (fe->ops.tuner_ops.release) { |
| 1990 | fe->ops.tuner_ops.release(fe); |
| 1991 | symbol_put_addr(fe->ops.tuner_ops.release); |
| 1992 | } |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 1993 | if (fe->ops.analog_ops.release) { |
| 1994 | fe->ops.analog_ops.release(fe); |
| 1995 | symbol_put_addr(fe->ops.analog_ops.release); |
| 1996 | } |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 1997 | ptr = (void*)fe->ops.release; |
| 1998 | if (ptr) { |
| 1999 | fe->ops.release(fe); |
| 2000 | symbol_put_addr(ptr); |
| 2001 | } |
| 2002 | } |
| 2003 | #else |
| 2004 | void dvb_frontend_detach(struct dvb_frontend* fe) |
| 2005 | { |
| 2006 | if (fe->ops.release_sec) |
| 2007 | fe->ops.release_sec(fe); |
| 2008 | if (fe->ops.tuner_ops.release) |
| 2009 | fe->ops.tuner_ops.release(fe); |
Michael Krufky | 2426a27 | 2007-12-21 11:34:45 -0300 | [diff] [blame] | 2010 | if (fe->ops.analog_ops.release) |
| 2011 | fe->ops.analog_ops.release(fe); |
Andrew de Quincey | f52a838 | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 2012 | if (fe->ops.release) |
| 2013 | fe->ops.release(fe); |
| 2014 | } |
| 2015 | #endif |
| 2016 | EXPORT_SYMBOL(dvb_frontend_detach); |