ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / media / dvb / frontends / dvb_dummy_fe.c
1 /* 
2  *  Driver for Dummy Frontend 
3  *
4  *  Written by Emard <emard@softhome.net>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20  */    
21
22 #include <linux/module.h>
23 #include <linux/init.h>
24
25 #include "dvb_frontend.h"
26
27 static int sct = 0;
28
29
30 /* depending on module parameter sct deliver different infos
31  */
32
33 static struct dvb_frontend_info dvb_s_dummyfe_info = {
34         .name                   = "DVB-S dummy frontend",
35         .type                   = FE_QPSK,
36         .frequency_min          = 950000,
37         .frequency_max          = 2150000,
38         .frequency_stepsize     = 250,           /* kHz for QPSK frontends */
39         .frequency_tolerance    = 29500,
40         .symbol_rate_min        = 1000000,
41         .symbol_rate_max        = 45000000,
42 /*      .symbol_rate_tolerance  = ???,*/
43         .notifier_delay          = 50,                /* 1/20 s */
44         .caps = FE_CAN_INVERSION_AUTO | 
45         FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
46         FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
47         FE_CAN_QPSK
48 };
49
50 static struct dvb_frontend_info dvb_c_dummyfe_info = {
51         .name = "DVB-C dummy frontend",
52         .type = FE_QAM,
53         .frequency_stepsize = 62500,
54         .frequency_min = 51000000,
55         .frequency_max = 858000000,
56         .symbol_rate_min = (57840000/2)/64,     /* SACLK/64 == (XIN/2)/64 */
57         .symbol_rate_max = (57840000/2)/4,      /* SACLK/4 */
58 #if 0
59         .frequency_tolerance    = ???,
60         .symbol_rate_tolerance  = ???,  /* ppm */  /* == 8% (spec p. 5) */
61         .notifier_delay         = ?,
62 #endif
63         .caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 |
64                 FE_CAN_QAM_128 | FE_CAN_QAM_256 | 
65                 FE_CAN_FEC_AUTO | FE_CAN_INVERSION_AUTO
66 };
67
68 static struct dvb_frontend_info dvb_t_dummyfe_info = {
69         .name = "DVB-T dummy frontend",
70         .type = FE_OFDM,
71         .frequency_min = 0,
72         .frequency_max = 863250000,
73         .frequency_stepsize = 62500,
74         /*.frequency_tolerance = */     /* FIXME: 12% of SR */
75         .symbol_rate_min = 0,           /* FIXME */
76         .symbol_rate_max = 9360000,     /* FIXME */
77         .symbol_rate_tolerance = 4000,
78         .notifier_delay = 0,
79         .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
80                         FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
81                         FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
82                         FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
83                         FE_CAN_TRANSMISSION_MODE_AUTO |
84                         FE_CAN_GUARD_INTERVAL_AUTO |
85                         FE_CAN_HIERARCHY_AUTO,
86 };
87
88 struct dvb_frontend_info *frontend_info(void)
89 {
90         switch(sct)
91         {
92         case 2:
93                 return &dvb_t_dummyfe_info;
94         case 1:
95                 return &dvb_c_dummyfe_info;
96         case 0:
97         default:
98                 return &dvb_s_dummyfe_info;
99         }
100 }
101
102
103 static int dvbdummyfe_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg)
104 {
105         switch (cmd) {
106         case FE_GET_INFO:
107                 memcpy (arg, frontend_info(), 
108                         sizeof(struct dvb_frontend_info));
109                 break;
110
111         case FE_READ_STATUS:
112         {
113                 fe_status_t *status = arg;
114                 *status = FE_HAS_SIGNAL
115                         | FE_HAS_CARRIER
116                         | FE_HAS_VITERBI
117                         | FE_HAS_SYNC
118                         | FE_HAS_LOCK;
119                 break;
120         }
121
122         case FE_READ_BER:
123         {
124                 u32 *ber = (u32 *) arg;
125                 *ber = 0;
126                 break;
127         }
128
129         case FE_READ_SIGNAL_STRENGTH:
130         {
131                 u8 signal = 0xff;
132                 *((u16*) arg) = (signal << 8) | signal;
133                 break;
134         }
135
136         case FE_READ_SNR:
137         {
138                 u8 snr = 0xf0;
139                 *(u16*) arg = (snr << 8) | snr;
140                 break;
141         }
142
143         case FE_READ_UNCORRECTED_BLOCKS: 
144                 *(u32*) arg = 0;
145                 break;
146
147         case FE_SET_FRONTEND:
148                 break;
149
150         case FE_GET_FRONTEND:
151                 break;
152
153         case FE_SLEEP:
154                 return 0;
155
156         case FE_INIT:
157                 return 0;
158
159         case FE_SET_TONE:
160                 return -EOPNOTSUPP;
161
162         case FE_SET_VOLTAGE:
163                 return 0;
164
165         default:
166                 return -EOPNOTSUPP;
167         }
168         return 0;
169
170
171
172 static int dvbdummyfe_attach (struct dvb_i2c_bus *i2c, void **data)
173 {
174         return dvb_register_frontend (dvbdummyfe_ioctl, i2c, NULL, frontend_info());
175 }
176
177
178 static void dvbdummyfe_detach (struct dvb_i2c_bus *i2c, void *data)
179 {
180         dvb_unregister_frontend (dvbdummyfe_ioctl, i2c);
181 }
182
183
184 static int __init init_dvbdummyfe (void)
185 {
186         return dvb_register_i2c_device (THIS_MODULE,
187                                         dvbdummyfe_attach, 
188                                         dvbdummyfe_detach);
189 }
190
191
192 static void __exit exit_dvbdummyfe (void)
193 {
194         dvb_unregister_i2c_device (dvbdummyfe_attach);
195 }
196
197
198 module_init(init_dvbdummyfe);
199 module_exit(exit_dvbdummyfe);
200
201
202 MODULE_DESCRIPTION("DVB DUMMY Frontend");
203 MODULE_AUTHOR("Emard");
204 MODULE_LICENSE("GPL");
205 MODULE_PARM(sct, "i");