14
14
*
15
15
* see Documentation/dvb/README.dvb-usb for more information
16
16
*/
17
- #include "gp8psk.h"
17
+
18
+ #define pr_fmt (fmt ) KBUILD_MODNAME ": " fmt
19
+
20
+ #include "gp8psk-fe.h"
21
+ #include "dvb_frontend.h"
22
+
23
+ static int debug ;
24
+ module_param (debug , int , 0644 );
25
+ MODULE_PARM_DESC (debug , "Turn on/off debugging (default:off)." );
26
+
27
+ #define dprintk (fmt , arg ...) do { \
28
+ if (debug) \
29
+ printk(KERN_DEBUG pr_fmt("%s: " fmt), \
30
+ __func__, ##arg); \
31
+ } while (0)
18
32
19
33
struct gp8psk_fe_state {
20
34
struct dvb_frontend fe ;
21
- struct dvb_usb_device * d ;
35
+ void * priv ;
36
+ const struct gp8psk_fe_ops * ops ;
37
+ bool is_rev1 ;
22
38
u8 lock ;
23
39
u16 snr ;
24
40
unsigned long next_status_check ;
@@ -29,22 +45,24 @@ static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
29
45
{
30
46
struct gp8psk_fe_state * st = fe -> demodulator_priv ;
31
47
u8 status ;
32
- gp8psk_usb_in_op (st -> d , GET_8PSK_CONFIG , 0 , 0 , & status , 1 );
48
+
49
+ st -> ops -> in (st -> priv , GET_8PSK_CONFIG , 0 , 0 , & status , 1 );
33
50
return status & bmDCtuned ;
34
51
}
35
52
36
53
static int gp8psk_set_tuner_mode (struct dvb_frontend * fe , int mode )
37
54
{
38
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
39
- return gp8psk_usb_out_op (state -> d , SET_8PSK_CONFIG , mode , 0 , NULL , 0 );
55
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
56
+
57
+ return st -> ops -> out (st -> priv , SET_8PSK_CONFIG , mode , 0 , NULL , 0 );
40
58
}
41
59
42
60
static int gp8psk_fe_update_status (struct gp8psk_fe_state * st )
43
61
{
44
62
u8 buf [6 ];
45
63
if (time_after (jiffies ,st -> next_status_check )) {
46
- gp8psk_usb_in_op (st -> d , GET_SIGNAL_LOCK , 0 ,0 , & st -> lock ,1 );
47
- gp8psk_usb_in_op (st -> d , GET_SIGNAL_STRENGTH , 0 ,0 , buf ,6 );
64
+ st -> ops -> in (st -> priv , GET_SIGNAL_LOCK , 0 , 0 , & st -> lock , 1 );
65
+ st -> ops -> in (st -> priv , GET_SIGNAL_STRENGTH , 0 , 0 , buf , 6 );
48
66
st -> snr = (buf [1 ]) << 8 | buf [0 ];
49
67
st -> next_status_check = jiffies + (st -> status_check_interval * HZ )/1000 ;
50
68
}
@@ -116,13 +134,12 @@ static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_front
116
134
117
135
static int gp8psk_fe_set_frontend (struct dvb_frontend * fe )
118
136
{
119
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
137
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
120
138
struct dtv_frontend_properties * c = & fe -> dtv_property_cache ;
121
139
u8 cmd [10 ];
122
140
u32 freq = c -> frequency * 1000 ;
123
- int gp_product_id = le16_to_cpu (state -> d -> udev -> descriptor .idProduct );
124
141
125
- deb_fe ("%s()\n" , __func__ );
142
+ dprintk ("%s()\n" , __func__ );
126
143
127
144
cmd [4 ] = freq & 0xff ;
128
145
cmd [5 ] = (freq >> 8 ) & 0xff ;
@@ -136,21 +153,21 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
136
153
switch (c -> delivery_system ) {
137
154
case SYS_DVBS :
138
155
if (c -> modulation != QPSK ) {
139
- deb_fe ("%s: unsupported modulation selected (%d)\n" ,
156
+ dprintk ("%s: unsupported modulation selected (%d)\n" ,
140
157
__func__ , c -> modulation );
141
158
return - EOPNOTSUPP ;
142
159
}
143
160
c -> fec_inner = FEC_AUTO ;
144
161
break ;
145
162
case SYS_DVBS2 : /* kept for backwards compatibility */
146
- deb_fe ("%s: DVB-S2 delivery system selected\n" , __func__ );
163
+ dprintk ("%s: DVB-S2 delivery system selected\n" , __func__ );
147
164
break ;
148
165
case SYS_TURBO :
149
- deb_fe ("%s: Turbo-FEC delivery system selected\n" , __func__ );
166
+ dprintk ("%s: Turbo-FEC delivery system selected\n" , __func__ );
150
167
break ;
151
168
152
169
default :
153
- deb_fe ("%s: unsupported delivery system selected (%d)\n" ,
170
+ dprintk ("%s: unsupported delivery system selected (%d)\n" ,
154
171
__func__ , c -> delivery_system );
155
172
return - EOPNOTSUPP ;
156
173
}
@@ -161,9 +178,9 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
161
178
cmd [3 ] = (c -> symbol_rate >> 24 ) & 0xff ;
162
179
switch (c -> modulation ) {
163
180
case QPSK :
164
- if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM )
181
+ if (st -> is_rev1 )
165
182
if (gp8psk_tuned_to_DCII (fe ))
166
- gp8psk_bcm4500_reload ( state -> d );
183
+ st -> ops -> reload ( st -> priv );
167
184
switch (c -> fec_inner ) {
168
185
case FEC_1_2 :
169
186
cmd [9 ] = 0 ; break ;
@@ -207,18 +224,18 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
207
224
cmd [9 ] = 0 ;
208
225
break ;
209
226
default : /* Unknown modulation */
210
- deb_fe ("%s: unsupported modulation selected (%d)\n" ,
227
+ dprintk ("%s: unsupported modulation selected (%d)\n" ,
211
228
__func__ , c -> modulation );
212
229
return - EOPNOTSUPP ;
213
230
}
214
231
215
- if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM )
232
+ if (st -> is_rev1 )
216
233
gp8psk_set_tuner_mode (fe , 0 );
217
- gp8psk_usb_out_op ( state -> d , TUNE_8PSK , 0 , 0 , cmd , 10 );
234
+ st -> ops -> out ( st -> priv , TUNE_8PSK , 0 , 0 , cmd , 10 );
218
235
219
- state -> lock = 0 ;
220
- state -> next_status_check = jiffies ;
221
- state -> status_check_interval = 200 ;
236
+ st -> lock = 0 ;
237
+ st -> next_status_check = jiffies ;
238
+ st -> status_check_interval = 200 ;
222
239
223
240
return 0 ;
224
241
}
@@ -228,9 +245,9 @@ static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
228
245
{
229
246
struct gp8psk_fe_state * st = fe -> demodulator_priv ;
230
247
231
- deb_fe ("%s\n" ,__func__ );
248
+ dprintk ("%s\n" , __func__ );
232
249
233
- if (gp8psk_usb_out_op (st -> d , SEND_DISEQC_COMMAND , m -> msg [0 ], 0 ,
250
+ if (st -> ops -> out (st -> priv , SEND_DISEQC_COMMAND , m -> msg [0 ], 0 ,
234
251
m -> msg , m -> msg_len )) {
235
252
return - EINVAL ;
236
253
}
@@ -243,12 +260,12 @@ static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
243
260
struct gp8psk_fe_state * st = fe -> demodulator_priv ;
244
261
u8 cmd ;
245
262
246
- deb_fe ("%s\n" ,__func__ );
263
+ dprintk ("%s\n" , __func__ );
247
264
248
265
/* These commands are certainly wrong */
249
266
cmd = (burst == SEC_MINI_A ) ? 0x00 : 0x01 ;
250
267
251
- if (gp8psk_usb_out_op (st -> d , SEND_DISEQC_COMMAND , cmd , 0 ,
268
+ if (st -> ops -> out (st -> priv , SEND_DISEQC_COMMAND , cmd , 0 ,
252
269
& cmd , 0 )) {
253
270
return - EINVAL ;
254
271
}
@@ -258,10 +275,10 @@ static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
258
275
static int gp8psk_fe_set_tone (struct dvb_frontend * fe ,
259
276
enum fe_sec_tone_mode tone )
260
277
{
261
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
278
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
262
279
263
- if (gp8psk_usb_out_op ( state -> d , SET_22KHZ_TONE ,
264
- (tone == SEC_TONE_ON ), 0 , NULL , 0 )) {
280
+ if (st -> ops -> out ( st -> priv , SET_22KHZ_TONE ,
281
+ (tone == SEC_TONE_ON ), 0 , NULL , 0 )) {
265
282
return - EINVAL ;
266
283
}
267
284
return 0 ;
@@ -270,9 +287,9 @@ static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
270
287
static int gp8psk_fe_set_voltage (struct dvb_frontend * fe ,
271
288
enum fe_sec_voltage voltage )
272
289
{
273
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
290
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
274
291
275
- if (gp8psk_usb_out_op ( state -> d , SET_LNB_VOLTAGE ,
292
+ if (st -> ops -> out ( st -> priv , SET_LNB_VOLTAGE ,
276
293
voltage == SEC_VOLTAGE_18 , 0 , NULL , 0 )) {
277
294
return - EINVAL ;
278
295
}
@@ -281,52 +298,60 @@ static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
281
298
282
299
static int gp8psk_fe_enable_high_lnb_voltage (struct dvb_frontend * fe , long onoff )
283
300
{
284
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
285
- return gp8psk_usb_out_op (state -> d , USE_EXTRA_VOLT , onoff , 0 ,NULL ,0 );
301
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
302
+
303
+ return st -> ops -> out (st -> priv , USE_EXTRA_VOLT , onoff , 0 , NULL , 0 );
286
304
}
287
305
288
306
static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend * fe , unsigned long sw_cmd )
289
307
{
290
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
308
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
291
309
u8 cmd = sw_cmd & 0x7f ;
292
310
293
- if (gp8psk_usb_out_op (state -> d ,SET_DN_SWITCH , cmd , 0 ,
294
- NULL , 0 )) {
311
+ if (st -> ops -> out (st -> priv , SET_DN_SWITCH , cmd , 0 , NULL , 0 ))
295
312
return - EINVAL ;
296
- }
297
- if (gp8psk_usb_out_op ( state -> d , SET_LNB_VOLTAGE , !!(sw_cmd & 0x80 ),
298
- 0 , NULL , 0 )) {
313
+
314
+ if (st -> ops -> out ( st -> priv , SET_LNB_VOLTAGE , !!(sw_cmd & 0x80 ),
315
+ 0 , NULL , 0 ))
299
316
return - EINVAL ;
300
- }
301
317
302
318
return 0 ;
303
319
}
304
320
305
321
static void gp8psk_fe_release (struct dvb_frontend * fe )
306
322
{
307
- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
308
- kfree (state );
323
+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
324
+
325
+ kfree (st );
309
326
}
310
327
311
328
static struct dvb_frontend_ops gp8psk_fe_ops ;
312
329
313
- struct dvb_frontend * gp8psk_fe_attach (struct dvb_usb_device * d )
330
+ struct dvb_frontend * gp8psk_fe_attach (const struct gp8psk_fe_ops * ops ,
331
+ void * priv , bool is_rev1 )
314
332
{
315
- struct gp8psk_fe_state * s = kzalloc (sizeof (struct gp8psk_fe_state ), GFP_KERNEL );
316
- if (s == NULL )
317
- goto error ;
318
-
319
- s -> d = d ;
320
- memcpy (& s -> fe .ops , & gp8psk_fe_ops , sizeof (struct dvb_frontend_ops ));
321
- s -> fe .demodulator_priv = s ;
322
-
323
- goto success ;
324
- error :
325
- return NULL ;
326
- success :
327
- return & s -> fe ;
328
- }
333
+ struct gp8psk_fe_state * st ;
329
334
335
+ if (!ops || !ops -> in || !ops -> out || !ops -> reload ) {
336
+ pr_err ("Error! gp8psk-fe ops not defined.\n" );
337
+ return NULL ;
338
+ }
339
+
340
+ st = kzalloc (sizeof (struct gp8psk_fe_state ), GFP_KERNEL );
341
+ if (!st )
342
+ return NULL ;
343
+
344
+ memcpy (& st -> fe .ops , & gp8psk_fe_ops , sizeof (struct dvb_frontend_ops ));
345
+ st -> fe .demodulator_priv = st ;
346
+ st -> ops = ops ;
347
+ st -> priv = priv ;
348
+ st -> is_rev1 = is_rev1 ;
349
+
350
+ pr_info ("Frontend %sattached\n" , is_rev1 ? "revision 1 " : "" );
351
+
352
+ return & st -> fe ;
353
+ }
354
+ EXPORT_SYMBOL_GPL (gp8psk_fe_attach );
330
355
331
356
static struct dvb_frontend_ops gp8psk_fe_ops = {
332
357
.delsys = { SYS_DVBS },
0 commit comments