1414 *
1515 * see Documentation/dvb/README.dvb-usb for more information
1616 */
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)
1832
1933struct gp8psk_fe_state {
2034 struct dvb_frontend fe ;
21- struct dvb_usb_device * d ;
35+ void * priv ;
36+ const struct gp8psk_fe_ops * ops ;
37+ bool is_rev1 ;
2238 u8 lock ;
2339 u16 snr ;
2440 unsigned long next_status_check ;
@@ -29,22 +45,24 @@ static int gp8psk_tuned_to_DCII(struct dvb_frontend *fe)
2945{
3046 struct gp8psk_fe_state * st = fe -> demodulator_priv ;
3147 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 );
3350 return status & bmDCtuned ;
3451}
3552
3653static int gp8psk_set_tuner_mode (struct dvb_frontend * fe , int mode )
3754{
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 );
4058}
4159
4260static int gp8psk_fe_update_status (struct gp8psk_fe_state * st )
4361{
4462 u8 buf [6 ];
4563 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 );
4866 st -> snr = (buf [1 ]) << 8 | buf [0 ];
4967 st -> next_status_check = jiffies + (st -> status_check_interval * HZ )/1000 ;
5068 }
@@ -116,13 +134,12 @@ static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_front
116134
117135static int gp8psk_fe_set_frontend (struct dvb_frontend * fe )
118136{
119- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
137+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
120138 struct dtv_frontend_properties * c = & fe -> dtv_property_cache ;
121139 u8 cmd [10 ];
122140 u32 freq = c -> frequency * 1000 ;
123- int gp_product_id = le16_to_cpu (state -> d -> udev -> descriptor .idProduct );
124141
125- deb_fe ("%s()\n" , __func__ );
142+ dprintk ("%s()\n" , __func__ );
126143
127144 cmd [4 ] = freq & 0xff ;
128145 cmd [5 ] = (freq >> 8 ) & 0xff ;
@@ -136,21 +153,21 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
136153 switch (c -> delivery_system ) {
137154 case SYS_DVBS :
138155 if (c -> modulation != QPSK ) {
139- deb_fe ("%s: unsupported modulation selected (%d)\n" ,
156+ dprintk ("%s: unsupported modulation selected (%d)\n" ,
140157 __func__ , c -> modulation );
141158 return - EOPNOTSUPP ;
142159 }
143160 c -> fec_inner = FEC_AUTO ;
144161 break ;
145162 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__ );
147164 break ;
148165 case SYS_TURBO :
149- deb_fe ("%s: Turbo-FEC delivery system selected\n" , __func__ );
166+ dprintk ("%s: Turbo-FEC delivery system selected\n" , __func__ );
150167 break ;
151168
152169 default :
153- deb_fe ("%s: unsupported delivery system selected (%d)\n" ,
170+ dprintk ("%s: unsupported delivery system selected (%d)\n" ,
154171 __func__ , c -> delivery_system );
155172 return - EOPNOTSUPP ;
156173 }
@@ -161,9 +178,9 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
161178 cmd [3 ] = (c -> symbol_rate >> 24 ) & 0xff ;
162179 switch (c -> modulation ) {
163180 case QPSK :
164- if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM )
181+ if (st -> is_rev1 )
165182 if (gp8psk_tuned_to_DCII (fe ))
166- gp8psk_bcm4500_reload ( state -> d );
183+ st -> ops -> reload ( st -> priv );
167184 switch (c -> fec_inner ) {
168185 case FEC_1_2 :
169186 cmd [9 ] = 0 ; break ;
@@ -207,18 +224,18 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend *fe)
207224 cmd [9 ] = 0 ;
208225 break ;
209226 default : /* Unknown modulation */
210- deb_fe ("%s: unsupported modulation selected (%d)\n" ,
227+ dprintk ("%s: unsupported modulation selected (%d)\n" ,
211228 __func__ , c -> modulation );
212229 return - EOPNOTSUPP ;
213230 }
214231
215- if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM )
232+ if (st -> is_rev1 )
216233 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 );
218235
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 ;
222239
223240 return 0 ;
224241}
@@ -228,9 +245,9 @@ static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
228245{
229246 struct gp8psk_fe_state * st = fe -> demodulator_priv ;
230247
231- deb_fe ("%s\n" ,__func__ );
248+ dprintk ("%s\n" , __func__ );
232249
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 ,
234251 m -> msg , m -> msg_len )) {
235252 return - EINVAL ;
236253 }
@@ -243,12 +260,12 @@ static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
243260 struct gp8psk_fe_state * st = fe -> demodulator_priv ;
244261 u8 cmd ;
245262
246- deb_fe ("%s\n" ,__func__ );
263+ dprintk ("%s\n" , __func__ );
247264
248265 /* These commands are certainly wrong */
249266 cmd = (burst == SEC_MINI_A ) ? 0x00 : 0x01 ;
250267
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 ,
252269 & cmd , 0 )) {
253270 return - EINVAL ;
254271 }
@@ -258,10 +275,10 @@ static int gp8psk_fe_send_diseqc_burst(struct dvb_frontend *fe,
258275static int gp8psk_fe_set_tone (struct dvb_frontend * fe ,
259276 enum fe_sec_tone_mode tone )
260277{
261- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
278+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
262279
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 )) {
265282 return - EINVAL ;
266283 }
267284 return 0 ;
@@ -270,9 +287,9 @@ static int gp8psk_fe_set_tone(struct dvb_frontend *fe,
270287static int gp8psk_fe_set_voltage (struct dvb_frontend * fe ,
271288 enum fe_sec_voltage voltage )
272289{
273- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
290+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
274291
275- if (gp8psk_usb_out_op ( state -> d , SET_LNB_VOLTAGE ,
292+ if (st -> ops -> out ( st -> priv , SET_LNB_VOLTAGE ,
276293 voltage == SEC_VOLTAGE_18 , 0 , NULL , 0 )) {
277294 return - EINVAL ;
278295 }
@@ -281,52 +298,60 @@ static int gp8psk_fe_set_voltage(struct dvb_frontend *fe,
281298
282299static int gp8psk_fe_enable_high_lnb_voltage (struct dvb_frontend * fe , long onoff )
283300{
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 );
286304}
287305
288306static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend * fe , unsigned long sw_cmd )
289307{
290- struct gp8psk_fe_state * state = fe -> demodulator_priv ;
308+ struct gp8psk_fe_state * st = fe -> demodulator_priv ;
291309 u8 cmd = sw_cmd & 0x7f ;
292310
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 ))
295312 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 ))
299316 return - EINVAL ;
300- }
301317
302318 return 0 ;
303319}
304320
305321static void gp8psk_fe_release (struct dvb_frontend * fe )
306322{
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 );
309326}
310327
311328static struct dvb_frontend_ops gp8psk_fe_ops ;
312329
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 )
314332{
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 ;
329334
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 );
330355
331356static struct dvb_frontend_ops gp8psk_fe_ops = {
332357 .delsys = { SYS_DVBS },
0 commit comments