-
Notifications
You must be signed in to change notification settings - Fork 1
/
sms1xxx-frontend.c
960 lines (855 loc) · 28.1 KB
/
sms1xxx-frontend.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
/* SMS1XXX - Siano DVB-T USB driver for FreeBSD 8.0 and higher:
*
* Copyright (C) 2008-2014, Ganaël Laplanche, http://contribs.martymac.org
*
* This driver contains code taken from the FreeBSD dvbusb driver:
*
* Copyright (C) 2006-2007, Raaf
* Copyright (C) 2004-2006, Patrick Boettcher
*
* This driver contains code taken from the Linux siano driver:
*
* Siano Mobile Silicon, Inc.
* MDTV receiver kernel modules.
* Copyright (C) 2006-2009, Uri Shkolnik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* * * *
* Device frontend
* (handles frontend0 device).
* * * *
*/
/* poll(2) stuff */
#include <sys/poll.h>
/* File-descriptor ioctls */
#include <sys/types.h>
#include <sys/filio.h>
/* Our stuff */
#include "sms1xxx.h"
#include "sms1xxx-usb.h"
#include "sms1xxx-frontend.h"
/* Linux stuff */
#include "linux/dvb/frontend.h"
#include "linux/dvb/version.h"
static d_open_t sms1xxx_frontend_open;
static d_close_t sms1xxx_frontend_close;
static d_poll_t sms1xxx_frontend_poll;
static d_ioctl_t sms1xxx_frontend_ioctl;
static struct cdevsw sms1xxx_frontend_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_NEEDGIANT,
.d_open = sms1xxx_frontend_open,
.d_close = sms1xxx_frontend_close,
.d_poll = sms1xxx_frontend_poll,
.d_ioctl = sms1xxx_frontend_ioctl,
.d_name = "sms1xxx_frontend",
};
/*********************
* Private functions *
*********************/
static int
sms1xxx_frontend_open(struct cdev *dev, int flag, int mode, struct thread *p)
{
int err = 0;
struct sms1xxx_softc *sc = dev->si_drv1;
#ifdef SMS1XXX_DEBUG
int unit = device_get_unit(sc->sc_dev);
TRACE(TRACE_OPEN,"flag=%d mode=%d unit=%d\n",flag,mode,unit);
#endif
if(sc == NULL || sc->sc_dying) {
TRACE(TRACE_MODULE,"dying! sc=%p\n",sc);
return (ENXIO);
}
if(sc->feopen) {
TRACE(TRACE_OPEN,"busy!\n");
return (EBUSY);
}
sc->feopen = 1;
err = sms1xxx_usb_ref(sc);
if(err)
sc->feopen = 0;
return (err);
}
static int
sms1xxx_frontend_close(struct cdev *dev, int flag, int mode, struct thread *p)
{
struct sms1xxx_softc *sc = dev->si_drv1;
#ifdef SMS1XXX_DEBUG
int unit = device_get_unit(sc->sc_dev);
TRACE(TRACE_OPEN,"flag=%d mode=%d unit=%d\n",flag,mode,unit);
#endif
if(sc == NULL || sc->sc_dying) {
TRACE(TRACE_OPEN,"dying! sc=%p\n",sc);
return (ENXIO);
}
sc->feopen = 0;
sms1xxx_usb_deref(sc);
return (0);
}
static int
sms1xxx_frontend_poll(struct cdev *dev, int events, struct thread *p)
{
struct sms1xxx_softc *sc = dev->si_drv1;
int revents = 0;
TRACE(TRACE_POLL,"thread=%p events=%d\n", p, events);
/*
* XXX Limited events support, see FE_GET_EVENT for more explanations.
* Block only if fe_status has changed since last FE_GET_EVENT.
*/
if(sc->fe_event) {
revents |= events & (POLLIN | POLLRDNORM | POLLPRI);
TRACE(TRACE_POLL,"poll not blocking\n");
}
#ifdef SMS1XXX_DEBUG
else {
TRACE(TRACE_POLL,"will block\n");
}
#endif
return (revents);
}
static int
sms1xxx_frontend_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
struct thread *pthread)
{
struct sms1xxx_softc *sc = dev->si_drv1;
struct sms1xxx_frontend *fe;
void *arg = addr;
int err = 0;
if(sc == NULL || sc->sc_dying) {
TRACE(TRACE_IOCTL,"dying! sc=%p\n",sc);
return (ENXIO);
}
fe = sc->device->frontend;
/* Just return 0 for those two special ioctls */
if((cmd == FIOASYNC) || (cmd == FIONBIO))
return (err);
/* Set DVBv5 cache state to DTV_UNDEFINED for legacy (DVBv3) ioctls */
if((cmd != FE_SET_PROPERTY) && (cmd != FE_GET_PROPERTY))
sc->dtv_property_cache.state = DTV_UNDEFINED;
switch(cmd) {
case FE_GET_INFO:
memcpy(arg,&fe->info, sizeof(struct dvb_frontend_info));
TRACE(TRACE_IOCTL,"FE_GET_INFO\n");
break;
case FE_READ_STATUS:
err = fe->read_status(sc,(fe_status_t*)arg);
TRACE(TRACE_IOCTL,"FE_READ_STATUS=%d\n",err);
break;
case FE_READ_BER:
err = fe->read_ber(sc,(u32*)arg);
TRACE(TRACE_IOCTL,"FE_READ_BER=%d\n",err);
break;
case FE_READ_SIGNAL_STRENGTH:
err = fe->read_signal_strength(sc,(u16*)arg);
TRACE(TRACE_IOCTL,"FE_READ_SIGNAL_STRENGTH=%d\n",err);
break;
case FE_READ_SNR:
err = fe->read_snr(sc,(u16*)arg);
TRACE(TRACE_IOCTL,"FE_READ_SNR=%d\n",err);
break;
case FE_READ_UNCORRECTED_BLOCKS:
err = fe->read_ucblocks(sc,(u32*)arg);
TRACE(TRACE_IOCTL,"FE_READ_UNCORRECTED_BLOCKS=%d\n",err);
break;
case FE_SET_FRONTEND:
err = fe->set_frontend(sc,(struct dvb_frontend_parameters *)arg);
TRACE(TRACE_IOCTL,"FE_SET_FRONTEND=%d\n",err);
break;
case FE_GET_EVENT:
{
/*
* XXX Events are not fully implemented, just simulated.
* This ioctl will fail and return EWOULDBLOCK if fe_status
* has not changed (fe_event == 0) since its last call.
* When successfull, the ioctl returns an event generated on the
* fly, corresponding to the current state of the frontend.
*
* In other words, we simulate a queue with a single event.
*/
struct dvb_frontend_event *ev = arg;
if(!sc->fe_event)
err = EWOULDBLOCK; /* fe_status has not changed, block! */
fe->get_frontend(sc,&ev->parameters);
fe->read_status(sc,&ev->status);
sc->fe_event = 0;
TRACE(TRACE_IOCTL,"FE_GET_EVENT (status=%d)\n",ev->status);
break;
}
case FE_GET_FRONTEND:
err = fe->get_frontend(sc,(struct dvb_frontend_parameters *)arg);
TRACE(TRACE_IOCTL,"FE_GET_FRONTEND=%d\n",err);
break;
case FE_SET_FRONTEND_TUNE_MODE:
/* XXX Unsupported, just return 0 */
break;
case FE_SET_PROPERTY:
err = fe->set_property(sc,(struct dtv_properties *)arg);
TRACE(TRACE_IOCTL,"FE_SET_PROPERTY=%d\n",err);
break;
case FE_GET_PROPERTY:
err = fe->get_property(sc,(struct dtv_properties *)arg);
TRACE(TRACE_IOCTL,"FE_GET_PROPERTY=%d\n",err);
break;
default:
ERR("unknown ioctl: 0x%lx\n",cmd);
err = ENOTTY;
break;
}
return (err);
}
/* Change status LED state on a frontend event */
static inline int
sms1xxx_frontend_status_led_feedback(struct sms1xxx_softc *sc)
{
if (!(sc->fe_status & FE_HAS_LOCK))
return (sms1xxx_gpio_status_led_feedback(sc, SMS_LED_OFF));
return (sms1xxx_gpio_status_led_feedback(sc,
(sc->legacy_ber == 0) ? SMS_LED_HI : SMS_LED_LO));
}
static int
sms1xxx_frontend_clear_cache(struct sms1xxx_softc *sc);
/********************
* Public functions *
********************/
void
sms1xxx_frontend_init(struct sms1xxx_softc *sc)
{
/* Initialize the cache to the proper values */
/* XXX Force DVB-T */
sc->dtv_property_cache.delivery_system = SYS_DVBT;
sms1xxx_frontend_clear_cache(sc);
sc->frontenddev = make_dev(&sms1xxx_frontend_cdevsw,
device_get_unit(sc->sc_dev),
UID_ROOT, GID_WHEEL, 0666,
"dvb/adapter%d/frontend0",
device_get_unit(sc->sc_dev));
if (sc->frontenddev != NULL)
sc->frontenddev->si_drv1 = sc;
TRACE(TRACE_MODULE,"created frontend0 device, addr=%p\n",sc->frontenddev);
}
void
sms1xxx_frontend_exit(struct sms1xxx_softc *sc)
{
if(sc->frontenddev != NULL) {
TRACE(TRACE_MODULE,"destroying frontend0, addr=%p\n",sc->frontenddev);
destroy_dev(sc->frontenddev);
sc->frontenddev = NULL;
}
}
int
sms1xxx_frontend_read_status(struct sms1xxx_softc *sc, fe_status_t *status)
{
TRACE(TRACE_IOCTL,"\n");
int err = sms1xxx_usb_getstatistics(sc);
*status=sc->fe_status;
sms1xxx_frontend_status_led_feedback(sc);
return (err);
}
int
sms1xxx_frontend_read_ber(struct sms1xxx_softc *sc, u32 *ber)
{
TRACE(TRACE_IOCTL,"\n");
int err = sms1xxx_usb_getstatistics(sc);
*ber=sc->legacy_ber;
sms1xxx_frontend_status_led_feedback(sc);
return (err);
}
int
sms1xxx_frontend_read_signal_strength(struct sms1xxx_softc *sc, u16 *strength)
{
TRACE(TRACE_IOCTL,"\n");
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
int err = sms1xxx_usb_getstatistics(sc);
s32 power = (s32)(c->strength.stat[0].uvalue);
if (power < -95)
*strength = 0;
else if (power > -29)
*strength = 65535;
else
*strength = (power + 95) * 65535 / 66;
sms1xxx_frontend_status_led_feedback(sc);
return (err);
}
int
sms1xxx_frontend_read_snr(struct sms1xxx_softc *sc, u16 *snr)
{
TRACE(TRACE_IOCTL,"\n");
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
int err = sms1xxx_usb_getstatistics(sc);
*snr = c->cnr.stat[0].svalue / 100;
sms1xxx_frontend_status_led_feedback(sc);
return (err);
}
int
sms1xxx_frontend_read_ucblocks(struct sms1xxx_softc *sc, u32 *ucblocks)
{
TRACE(TRACE_IOCTL,"\n");
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
int err = sms1xxx_usb_getstatistics(sc);
*ucblocks=c->block_error.stat[0].uvalue;
sms1xxx_frontend_status_led_feedback(sc);
return (err);
}
static int
sms1xxx_frontend_fep_to_c(const struct dvb_frontend_parameters *p,
struct dtv_frontend_properties *c);
int
sms1xxx_frontend_set_frontend(struct sms1xxx_softc *sc,
struct dvb_frontend_parameters *fep)
{
TRACE(TRACE_IOCTL,"\n");
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
sms1xxx_frontend_stats_not_ready(sc);
c->strength.stat[0].uvalue = 0;
c->cnr.stat[0].uvalue = 0;
/* Update DVBv3 fe_params state */
memcpy(&sc->fe_params, fep,
sizeof(struct dvb_frontend_parameters));
/* Update DVBv5 dtv_property_cache state */
/* XXX Force DVB-T */
sc->dtv_property_cache.delivery_system = SYS_DVBT;
return (sms1xxx_frontend_fep_to_c(
(const struct dvb_frontend_parameters *)&sc->fe_params,
&sc->dtv_property_cache
) || sms1xxx_usb_setfrequency(
sc,
sc->fe_params.frequency + sc->device->freq_offset,
sc->fe_params.u.ofdm.bandwidth
));
}
int
sms1xxx_frontend_get_frontend(struct sms1xxx_softc *sc,
struct dvb_frontend_parameters *fep)
{
TRACE(TRACE_IOCTL,"\n");
memcpy(fep, &sc->fe_params,
sizeof(struct dvb_frontend_parameters));
return (0);
}
int
sms1xxx_frontend_get_tune_settings(struct sms1xxx_softc *sc,
struct dvb_frontend_tune_settings *tune)
{
TRACE(TRACE_IOCTL,"\n");
tune->min_delay_ms = 400;
tune->step_size = 250000;
tune->max_drift = 0;
return (0);
}
/* Below are functions that add minimal DVBv5 support */
enum dvbv3_emulation_type {
DVBV3_UNKNOWN,
DVBV3_QPSK,
DVBV3_QAM,
DVBV3_OFDM,
DVBV3_ATSC,
};
static enum dvbv3_emulation_type
dvbv3_type(u32 delivery_system)
{
switch (delivery_system) {
case SYS_DVBC_ANNEX_A:
case SYS_DVBC_ANNEX_C:
return DVBV3_QAM;
case SYS_DVBS:
case SYS_DVBS2:
case SYS_TURBO:
case SYS_ISDBS:
case SYS_DSS:
return DVBV3_QPSK;
case SYS_DVBT:
case SYS_DVBT2:
case SYS_ISDBT:
case SYS_DTMB:
return DVBV3_OFDM;
case SYS_ATSC:
case SYS_ATSCMH:
case SYS_DVBC_ANNEX_B:
return DVBV3_ATSC;
case SYS_UNDEFINED:
case SYS_ISDBC:
case SYS_DVBH:
case SYS_DAB:
default:
/*
* Doesn't know how to emulate those types and/or
* there's no frontend driver from this type yet
* with some emulation code, so, we're not sure yet how
* to handle them, or they're not compatible with a DVBv3 call.
*/
return DVBV3_UNKNOWN;
}
}
/* Clear DVBv5 property cache
Upstream name: dvb_frontend_clear_cache() */
static int
sms1xxx_frontend_clear_cache(struct sms1xxx_softc *sc)
{
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
TRACE(TRACE_FRONTEND,"Clearing cache for delivery system %d\n",
c->delivery_system);
u32 delsys = c->delivery_system;
memset(c, 0, offsetof(struct dtv_frontend_properties, strength));
c->delivery_system = delsys;
c->state = DTV_CLEAR;
c->transmission_mode = TRANSMISSION_MODE_AUTO;
c->bandwidth_hz = 0; /* AUTO */
c->guard_interval = GUARD_INTERVAL_AUTO;
c->hierarchy = HIERARCHY_AUTO;
c->symbol_rate = 0;
c->code_rate_HP = FEC_AUTO;
c->code_rate_LP = FEC_AUTO;
c->fec_inner = FEC_AUTO;
c->rolloff = ROLLOFF_AUTO;
c->voltage = SEC_VOLTAGE_OFF;
c->sectone = SEC_TONE_OFF;
c->pilot = PILOT_AUTO;
c->isdbt_partial_reception = 0;
c->isdbt_sb_mode = 0;
c->isdbt_sb_subchannel = 0;
c->isdbt_sb_segment_idx = 0;
c->isdbt_sb_segment_count = 0;
c->isdbt_layer_enabled = 0;
for (int i = 0; i < 3; i++) {
c->layer[i].fec = FEC_AUTO;
c->layer[i].modulation = QAM_AUTO;
c->layer[i].interleaving = 0;
c->layer[i].segment_count = 0;
}
c->stream_id = NO_STREAM_ID_FILTER;
switch (c->delivery_system) {
case SYS_DVBS:
case SYS_DVBS2:
case SYS_TURBO:
c->modulation = QPSK; /* implied for DVB-S in legacy API */
c->rolloff = ROLLOFF_35;/* implied for DVB-S */
break;
case SYS_ATSC:
c->modulation = VSB_8;
break;
default:
c->modulation = QAM_AUTO;
break;
}
c->lna = LNA_AUTO;
return (0);
}
/* DVBv3 dvb_frontend_parameters to DVBv5 dtv_frontend_properties cache sync
Upstream name: dtv_property_cache_sync() */
static int
sms1xxx_frontend_fep_to_c(const struct dvb_frontend_parameters *p,
struct dtv_frontend_properties *c)
{
TRACE(TRACE_FRONTEND,"Converting (legacy) dvb_frontend_parameters to "
"(new) dtv_frontend_properties cache\n");
c->frequency = p->frequency;
c->inversion = p->inversion;
switch (dvbv3_type(c->delivery_system)) {
case DVBV3_QPSK:
c->symbol_rate = p->u.qpsk.symbol_rate;
c->fec_inner = p->u.qpsk.fec_inner;
break;
case DVBV3_QAM:
c->symbol_rate = p->u.qam.symbol_rate;
c->fec_inner = p->u.qam.fec_inner;
c->modulation = p->u.qam.modulation;
break;
case DVBV3_OFDM:
switch (p->u.ofdm.bandwidth) {
case BANDWIDTH_10_MHZ:
c->bandwidth_hz = 10000000;
break;
case BANDWIDTH_8_MHZ:
c->bandwidth_hz = 8000000;
break;
case BANDWIDTH_7_MHZ:
c->bandwidth_hz = 7000000;
break;
case BANDWIDTH_6_MHZ:
c->bandwidth_hz = 6000000;
break;
case BANDWIDTH_5_MHZ:
c->bandwidth_hz = 5000000;
break;
case BANDWIDTH_1_712_MHZ:
c->bandwidth_hz = 1712000;
break;
case BANDWIDTH_AUTO:
c->bandwidth_hz = 0;
}
c->code_rate_HP = p->u.ofdm.code_rate_HP;
c->code_rate_LP = p->u.ofdm.code_rate_LP;
c->modulation = p->u.ofdm.constellation;
c->transmission_mode = p->u.ofdm.transmission_mode;
c->guard_interval = p->u.ofdm.guard_interval;
c->hierarchy = p->u.ofdm.hierarchy_information;
break;
case DVBV3_ATSC:
c->modulation = p->u.vsb.modulation;
if (c->delivery_system == SYS_ATSCMH)
break;
if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
c->delivery_system = SYS_ATSC;
else
c->delivery_system = SYS_DVBC_ANNEX_B;
break;
case DVBV3_UNKNOWN:
TRACE(TRACE_FRONTEND,"Unknown delivery system\n");
return (EINVAL);
}
return (0);
}
/* DVBv5 dtv_frontend_properties cache to DVBv3 dvb_frontend_parameters sync
Upstream name: dtv_property_legacy_params_sync() */
static int
sms1xxx_frontend_c_to_fep(const struct dtv_frontend_properties *c,
struct dvb_frontend_parameters *p)
{
TRACE(TRACE_FRONTEND,"Converting (new) dtv_frontend_properties cache to "
"(legacy) dvb_frontend_parameters\n");
p->frequency = c->frequency;
p->inversion = c->inversion;
switch (dvbv3_type(c->delivery_system)) {
case DVBV3_QPSK:
p->u.qpsk.symbol_rate = c->symbol_rate;
p->u.qpsk.fec_inner = c->fec_inner;
break;
case DVBV3_QAM:
p->u.qam.symbol_rate = c->symbol_rate;
p->u.qam.fec_inner = c->fec_inner;
p->u.qam.modulation = c->modulation;
break;
case DVBV3_OFDM:
switch (c->bandwidth_hz) {
case 10000000:
p->u.ofdm.bandwidth = BANDWIDTH_10_MHZ;
break;
case 8000000:
p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
break;
case 7000000:
p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
break;
case 6000000:
p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
break;
case 5000000:
p->u.ofdm.bandwidth = BANDWIDTH_5_MHZ;
break;
case 1712000:
p->u.ofdm.bandwidth = BANDWIDTH_1_712_MHZ;
break;
case 0:
default:
p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
}
p->u.ofdm.code_rate_HP = c->code_rate_HP;
p->u.ofdm.code_rate_LP = c->code_rate_LP;
p->u.ofdm.constellation = c->modulation;
p->u.ofdm.transmission_mode = c->transmission_mode;
p->u.ofdm.guard_interval = c->guard_interval;
p->u.ofdm.hierarchy_information = c->hierarchy;
break;
case DVBV3_ATSC:
p->u.vsb.modulation = c->modulation;
break;
case DVBV3_UNKNOWN:
TRACE(TRACE_FRONTEND,"Unknown delivery system\n");
return (EINVAL);
}
return (0);
}
/* Set a single frontend property
Upstream name: dtv_property_process_set() */
static int
sms1xxx_frontend_set_single_property(struct sms1xxx_softc *sc,
struct dtv_property *tvp)
{
TRACE(TRACE_FRONTEND,"Setting single property, cmd=%d\n", tvp->cmd);
int err = 0;
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
if(tvp->cmd == DTV_TUNE)
c->state = tvp->cmd;
#if 0
/* TODO Reset cache state to prevent from tuning again when setting a
single property ? Reset to DTV_UNDEFINED, DTV_CLEAR or tvp->cmd ? */
else
c->state = DTV_UNDEFINED;
#endif
switch(tvp->cmd) {
case DTV_CLEAR:
/*
* Reset a cache of data specific to the frontend here. This does
* not affect hardware.
*/
sms1xxx_frontend_clear_cache(sc);
break;
case DTV_TUNE:
/* Update DVBv3 fe_params state */
err = sms1xxx_frontend_c_to_fep(
(const struct dtv_frontend_properties *)c,
&sc->fe_params);
TRACE(TRACE_FRONTEND,"Finalised property cache\n");
/* Effective tuning is then performed through
a call to sms1xxx_usb_setfrequency() within
sms1xxx_frontend_set_properties() */
break;
case DTV_FREQUENCY:
c->frequency = tvp->u.data;
break;
case DTV_MODULATION:
c->modulation = tvp->u.data;
break;
case DTV_BANDWIDTH_HZ:
c->bandwidth_hz = tvp->u.data;
break;
case DTV_INVERSION:
c->inversion = tvp->u.data;
break;
case DTV_SYMBOL_RATE:
c->symbol_rate = tvp->u.data;
break;
case DTV_INNER_FEC:
c->fec_inner = tvp->u.data;
break;
case DTV_PILOT:
c->pilot = tvp->u.data;
break;
case DTV_ROLLOFF:
c->rolloff = tvp->u.data;
break;
case DTV_DELIVERY_SYSTEM:
/* XXX Force DVB-T */
c->delivery_system = SYS_DVBT;
break;
case DTV_CODE_RATE_HP:
c->code_rate_HP = tvp->u.data;
break;
case DTV_CODE_RATE_LP:
c->code_rate_LP = tvp->u.data;
break;
case DTV_GUARD_INTERVAL:
c->guard_interval = tvp->u.data;
break;
case DTV_TRANSMISSION_MODE:
c->transmission_mode = tvp->u.data;
break;
case DTV_HIERARCHY:
c->hierarchy = tvp->u.data;
break;
case DTV_INTERLEAVING:
c->interleaving = tvp->u.data;
break;
/* Multistream support */
case DTV_STREAM_ID:
case DTV_DVBT2_PLP_ID_LEGACY:
c->stream_id = tvp->u.data;
break;
default:
TRACE(TRACE_FRONTEND,"Unsupported frontend property (%d)\n",
tvp->cmd);
err = EINVAL;
}
return (err);
}
/* Get a single frontend property
Upstream name: dtv_property_process_get() */
static int
sms1xxx_frontend_get_single_property(struct sms1xxx_softc *sc,
struct dtv_property *tvp)
{
TRACE(TRACE_FRONTEND,"Getting single property, cmd=%d\n", tvp->cmd);
int err = 0;
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
switch(tvp->cmd) {
case DTV_ENUM_DELSYS:
/* XXX Force DVB-T */
tvp->u.buffer.len = 1;
tvp->u.buffer.data[0] = SYS_DVBT;
break;
case DTV_FREQUENCY:
tvp->u.data = c->frequency;
break;
case DTV_MODULATION:
tvp->u.data = c->modulation;
break;
case DTV_BANDWIDTH_HZ:
tvp->u.data = c->bandwidth_hz;
break;
case DTV_INVERSION:
tvp->u.data = c->inversion;
break;
case DTV_SYMBOL_RATE:
tvp->u.data = c->symbol_rate;
break;
case DTV_INNER_FEC:
tvp->u.data = c->fec_inner;
break;
case DTV_PILOT:
tvp->u.data = c->pilot;
break;
case DTV_ROLLOFF:
tvp->u.data = c->rolloff;
break;
case DTV_DELIVERY_SYSTEM:
tvp->u.data = c->delivery_system;
break;
case DTV_API_VERSION:
tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
break;
case DTV_CODE_RATE_HP:
tvp->u.data = c->code_rate_HP;
break;
case DTV_CODE_RATE_LP:
tvp->u.data = c->code_rate_LP;
break;
case DTV_GUARD_INTERVAL:
tvp->u.data = c->guard_interval;
break;
case DTV_TRANSMISSION_MODE:
tvp->u.data = c->transmission_mode;
break;
case DTV_HIERARCHY:
tvp->u.data = c->hierarchy;
break;
case DTV_INTERLEAVING:
tvp->u.data = c->interleaving;
break;
/* Multistream support */
case DTV_STREAM_ID:
case DTV_DVBT2_PLP_ID_LEGACY:
tvp->u.data = c->stream_id;
break;
/* Fill quality measures */
case DTV_STAT_SIGNAL_STRENGTH:
tvp->u.st = c->strength;
break;
case DTV_STAT_CNR:
tvp->u.st = c->cnr;
break;
case DTV_STAT_PRE_ERROR_BIT_COUNT:
tvp->u.st = c->pre_bit_error;
break;
case DTV_STAT_PRE_TOTAL_BIT_COUNT:
tvp->u.st = c->pre_bit_count;
break;
case DTV_STAT_POST_ERROR_BIT_COUNT:
tvp->u.st = c->post_bit_error;
break;
case DTV_STAT_POST_TOTAL_BIT_COUNT:
tvp->u.st = c->post_bit_count;
break;
case DTV_STAT_ERROR_BLOCK_COUNT:
tvp->u.st = c->block_error;
break;
case DTV_STAT_TOTAL_BLOCK_COUNT:
tvp->u.st = c->block_count;
break;
default:
TRACE(TRACE_FRONTEND,"Unsupported frontend property (%d)\n",
tvp->cmd);
err = EINVAL;
}
return (err);
}
/* Set an array of frontend properties
Upstream name: dvb_frontend_ioctl_properties()/FE_SET_PROPERTY */
int
sms1xxx_frontend_set_properties(struct sms1xxx_softc *sc,
struct dtv_properties *parg)
{
TRACE(TRACE_FRONTEND,"Setting %d properties\n", parg->num);
struct dtv_property *tvp = parg->props;
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
int err = 0;
int i;
/* Put an arbitrary limit on the number of messages that can
* be sent at once */
if ((parg->num == 0) || (parg->num > DTV_IOCTL_MAX_MSGS))
return (EINVAL);
for (i = 0; i < parg->num; i++) {
err = sms1xxx_frontend_set_single_property(sc, tvp + i);
(tvp + i)->result = err;
if (err != 0)
return (err);
}
/* Check cache state and tune if DTV_TUNE property has been set */
if (c->state == DTV_TUNE) {
TRACE(TRACE_FRONTEND,"Property cache is full, tuning! sc=%p\n",sc);
return (sms1xxx_usb_setfrequency(
sc,
sc->fe_params.frequency + sc->device->freq_offset,
sc->fe_params.u.ofdm.bandwidth
));
}
return (0);
}
/* Get an array of frontend properties
Upstream name: dvb_frontend_ioctl_properties()/FE_GET_PROPERTY */
int
sms1xxx_frontend_get_properties(struct sms1xxx_softc *sc,
struct dtv_properties *parg)
{
TRACE(TRACE_FRONTEND,"Getting %d properties\n", parg->num);
struct dtv_property *tvp = parg->props;
int err = 0;
int i;
/* Put an arbitrary limit on the number of messages that can
* be sent at once */
if ((parg->num == 0) || (parg->num > DTV_IOCTL_MAX_MSGS))
return (EINVAL);
for (i = 0; i < parg->num; i++) {
err = sms1xxx_frontend_get_single_property(sc, tvp + i);
(tvp + i)->result = err;
if (err != 0)
return (err);
}
return (0);
}
void
sms1xxx_frontend_stats_not_ready(struct sms1xxx_softc *sc)
{
struct dtv_frontend_properties *c = &sc->dtv_property_cache;
int i, n_layers;
switch (sc->mode) {
case DEVICE_MODE_ISDBT:
case DEVICE_MODE_ISDBT_BDA:
n_layers = 4;
break;
default:
n_layers = 1;
}
/* Global stats */
c->strength.len = 1;
c->cnr.len = 1;
c->strength.stat[0].scale = FE_SCALE_DECIBEL;
c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
/* Per-layer stats */
c->post_bit_error.len = n_layers;
c->post_bit_count.len = n_layers;
c->block_error.len = n_layers;
c->block_count.len = n_layers;
/*
* Put all of them at FE_SCALE_NOT_AVAILABLE. They're dynamically
* changed when the stats become available.
*/
for (i = 0; i < n_layers; i++) {
c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
}
return;
}