summaryrefslogtreecommitdiff
path: root/Documentation/DocBook/cg2900_fm_radio.tmpl
blob: 2cdbf146ff42e30b3ee9642809f96961a9189a46 (plain)
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
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>

<book id="STE-CG2900-fm-driver-template">
 <bookinfo>
  <title>V4L FM Radio Driver for CG2900</title>
  <authorgroup>
   <author>
    <firstname>Hemant</firstname>
    <surname>Gupta</surname>
    <affiliation>
     <address>
      <email>hemant.gupta@stericsson.com</email>
     </address>
    </affiliation>
   </author>
  </authorgroup>
  <copyright>
   <year>2010</year>
   <holder>ST-Ericsson</holder>
  </copyright>
  <subjectset>
    <subject>
      <subjectterm>Connectivity</subjectterm>
    </subject>
  </subjectset>
  <legalnotice>
   <!-- Do NOT remove the legal notice below -->
  <para>
     This documentation is free software; you can redistribute
     it and/or modify it under the terms of the GNU General Public
     License as published by the Free Software Foundation; either
     version 2 of the License, or (at your option) any later
     version.
   </para>
   <para>
     This program is distributed in the hope that it will be
     useful, but WITHOUT ANY WARRANTY; without even the implied
     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     See the GNU General Public License for more details.
   </para>
   <para>
     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., 59 Temple Place, Suite 330, Boston,
     MA 02111-1307 USA
   </para>
   <para>
     For more details see the file COPYING in the source
     distribution of Linux.
   </para>
  </legalnotice>
 </bookinfo>
 <toc></toc>
 <chapter id="intro">
  <title>Introduction</title>
  <!-- Do NOT change the chapter id or title! -->
  <para>
    This documentation describes the functions provided by the CG2900 FM Driver.
  </para>
 </chapter>
 <chapter id="gettingstarted">
  <title>Getting Started</title>
  <!-- Do NOT change the chapter id or title! -->
  <para>
     There are no special compilation flags needed to build the CG2900
     FM Driver.
  </para>
  <para>
    There must be coeffecient and firmware files that match the used chip version inside the firmware folder.
    The files:
    <itemizedlist>
      <listitem><para>cg2900_fm_bt_src_coeff_info.fw.org</para></listitem>
      <listitem><para>cg2900_fm_ext_src_coeff_info.fw.org</para></listitem>
      <listitem><para>cg2900_fm_fm_coeff_info.fw.org</para></listitem>
      <listitem><para>cg2900_fm_fm_prog_info.fw.org</para></listitem>
    </itemizedlist>
    handle the mapping between chip version and correct firmware files (firmware and coeffecient files).
    The necessary firmware and coeffecient files should be placed with the extension <constant>.fw.org</constant>.
    Note that there is a limitation in the Kernel firmware system regarding name length of a file.
  </para>
  <section id="basic-tutorial">
    <title>Basic Tutorial</title>
    <para>
      To enable the CG2900 FM Driver using KConfig go to <constant>Device Drivers -> Multimedia devices </constant>
      and enable the following:
    <itemizedlist>
      <listitem><para>Video For Linux</para></listitem>
      <listitem><para>Enable Video For Linux API 1 compatible Layer</para></listitem>
      <listitem><para>Radio Adapters</para></listitem>
      <listitem><para>Radio Adapter -> ST-Ericsson CG2900 FM Radio support</para></listitem>
    </itemizedlist>
      Select the driver as built in kernel object.
    </para>
    </section>
 </chapter>
 <chapter id="concepts">
  <title>Concepts</title>
  <!-- Do NOT change the chapter id or title! -->
  <para>
     The CG2900 FM driver acts as an interface between Video4Linux and CG2900-Protocol Driver. It configures the FM chip in FM Rx or FM Tx mode. It also sends the unformatted RDS data to the application for decoding while in FM rx mode and sends the formatted RDS data to FM Chip while in Tx mode.
   </para>
   <para>
     <variablelist>
       <varlistentry>
         <term>FM Driver Working</term>
         <listitem>
         <para>
           In order to send and receive data on an H:4 channel, the FM Driver opens the channel by registering with the CG2900 Protocol driver. After this the FM driver encapsulates the user operation into specific HCI comamnds and sends that data to the CG2900 Connectivity Controller and waits till the response for the previous command is received. FM Driver in this way maintains the flow control.
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </para>
 </chapter>
 <chapter id="Tasks">
   <title>Tasks</title>
   <!-- Do NOT change the chapter id or title! -->
   <section id="Switching-On-FM">
     <title>Switch On FM</title>
     <para>
		FM specific tasks
     </para>
     <variablelist>
       <varlistentry>
         <term>Switching On FM</term>
         <listitem>
         <para>
           For switching on FM the character device /dev/radio0 should be opened from user space. This sets the FM Radio in Idle mode. For configuring the FM Radio in Rx or Tx mode the IOCTL's VIDIOC_S_TUNER and VIDIOC_S_MODULATOR respectively.
           <programlisting>
		int fd;
		fd = open("/dev/radio0", O_RDONLY);
		if(fd &lt; 0) {
			printf("open:error!!!\n");
			goto err;
		}
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="Switching-Off-FM">
     <title>Switch Off FM</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Switching Off FM</term>
         <listitem>
         <para>
           For switching OFF FM the character device /dev/radio0 should be closed from user space.
           <programlisting>
		if(fd &gt;= 0)
			close(fd);
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
  <section id="Rx-Mode">
     <title>Switching To FM Rx Mode</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Switching To FM Rx Mode</term>
         <listitem>
         <para>
           For switching on FM Rx mode the IOCTL VIDIOC_S_TUNER should be called with appropriate parameters.
           <programlisting>
			memset(&amp;tuner, 0, sizeof(tuner));
			tuner.index = 0;
			tuner.rxsubchans |= V4L2_TUNER_SUB_STEREO;
			if (ioctl(fd, VIDIOC_S_TUNER, &amp;tuner) &lt; 0) {
				  printf("VIDIOC_S_TUNER:error!!\n");
				  return;
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="Tx-Mode">
     <title>Switching To FM Tx Mode</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Switching To FM Tx Mode</term>
         <listitem>
         <para>
           For switching on FM Tx mode the IOCTL VIDIOC_S_MODULATOR should be
		   called with appropriate parameters.
           <programlisting>
			memset(&amp;modulator, 0, sizeof(modulator));
			modulator.index = 0;
			modulator.txsubchans |= V4L2_TUNER_SUB_STEREO;
			if (ioctl(fd, VIDIOC_S_MODULATOR, &amp;modulator) &lt; 0) {
				  printf("VIDIOC_S_MODULATOR:error!!\n");
				  return;
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="FM-Standby">
     <title>Standby</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Making the FM Radio go in Standby Mode</term>
         <listitem>
         <para>
           For making the FM Radio go in Standby mode, the IOCTL VIDIOC_S_CTRL should be used. The id of the v4l2_control structure should be set to V4L2_CID_CG2900_RADIO_CHIP_STATE and the value of v4l2_control structure should be set as V4L2_CG2900_RADIO_STANDBY.
           <programlisting>
		struct v4l2_control sctrl;
		int ret;
		sctrl.id = V4L2_CID_CG2900_RADIO_CHIP_STATE;
                sctrl.value = V4L2_CG2900_RADIO_STANDBY;
                ret = ioctl(fd, VIDIOC_S_CTRL, &amp;sctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_CTRL:error!!\n");
		}
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="Powerup-from-standby">
     <title>Powering Up FM From Standby Mode</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Powering Up FM Radio from Standby Mode</term>
         <listitem>
         <para>
           For powering up FM radio again from standby mode, the IOCTL VIDIOC_S_CTRL should be used. The id of the v4l2_control structure should be set to V4L2_CID_CG2900_RADIO_CHIP_STATE and the value of v4l2_control structure should be set as V4L2_CG2900_RADIO_POWERUP.
           <programlisting>
		struct v4l2_control sctrl;
		int ret;
		sctrl.id = V4L2_CID_CG2900_RADIO_CHIP_STATE;
                sctrl.value = V4L2_CG2900_RADIO_POWERUP;
                ret = ioctl(fd, VIDIOC_S_CTRL, &amp;sctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_CTRL:error!!\n");
		}
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="tune-frequency">
     <title>Tune Channel</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Tune to a particular station</term>
         <listitem>
         <para>
           for tuning to a particular station, the IOCTL VIDIOC_S_FREQUENCY should be used. The frequency of the v4l2_frequency structure should be converted to V4L2 format.
           <programlisting>
		struct v4l2_frequency freq;
		int ret;
		/* Convert frequency in Hz to V4L2 Format */
		freq.frequency = (frequency * 2)/ 125;
                ret = ioctl(fd, VIDIOC_S_FREQUENCY, &amp;freq);
		if (ret &lt; 0) {
			printf("VIDIOC_S_FREQUENCY:error!!\n");
		}
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="get-frequency">
     <title>Get Tuned Channel</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Get the Currently tuned Station Frequncy</term>
         <listitem>
         <para>
           for tuning to a particular station, the IOCTL VIDIOC_G_FREQUENCY should be used. The frequency returned in the v4l2_frequency structure would be in V4L2 format.
           <programlisting>
		struct v4l2_frequency freq;
		int ret;
                ret = ioctl(fd, VIDIOC_G_FREQUENCY, &amp;freq);
		if (ret &lt; 0) {
			printf("VIDIOC_G_FREQUENCY:error!!\n");
			*frequency = 0;
			return;
		}
		/* Convert frequency to Hz from V4L2 Format */
		*frequency = (freq.frequency * 125)/2;
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="get-signal-strength">
     <title>Retreive Signal Strength</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Retreive Signal Strength</term>
         <listitem>
         <para>
           For retreiving the Signal strength of the currently tuned channel in FM Rx mode, IOCTL VIDIOC_G_TUNER should be called. The current signal strength would be represented by the parameter signal of the v4l2_tuner strucure.
           <programlisting>
		void get_signal_strength(int *rssi)
		{
			struct v4l2_tuner tuner;
			int ret;
			memset(&amp;tuner, 0, sizeof(tuner));
			tuner.index = 0;
			ret = ioctl(fd, VIDIOC_G_TUNER, &amp;tuner);
			if (ret &lt; 0) {
				printf("VIDIOC_G_TUNER:error!!\n");
				*rssi = 0;
				return;
			}
			*rssi = tuner.signal;
		}
           </programlisting>
Note: Currently the retrieved signal strength is in decimals and not in "dBuV", proper external conversion required.
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="band-scan">
     <title>Band Scan</title>
     <para>
       <!-- Driver loading Parameters:Not Applicable -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Band Scan</term>
         <listitem>
         <para>
           For doing a band scan, ie search for all available stations in the entire FM band, IOCTL VIDIOC_S_CTRL should be used with parameter id of the v4l2_control structure should be set to V4L2_CID_CG2900_RADIO_BANDSCAN and the value of v4l2_control structure should be set as V4L2_CG2900_RADIO_BANDSCAN_START. If the IOCTL returns successfully, a common thread (which should have been created at the start of the application and is already polling to FM driver for multiple other interrupts including events related to Block Scan and Search Frequency operation) which polls with an infinite timeout iteratively until the end of the user-space application, when poll in one iteration is complete. When poll is complete, thread will make an IOCTL call with VIDIOC_G_EXT_CTRLS with parameter id set to V4L2_CID_CG2900_RADIO_GET_INTERRUPT and the data structure FmInterrupt.controls-&gt;string associated with V4L2_CID_CG2900_RADIO_GET_INTERRUPT shall contain the interrupt retrieved from FMD. Interrupts received in this manner from FMD can be any of the following.
	   <itemizedlist>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_UNKNOWN</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_SEARCH_COMPLETED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_BAND_SCAN_COMPLETED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_BLOCK_SCAN_COMPLETED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_SCAN_CANCELLED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_MONO_STEREO_TRANSITION</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_DEVICE_RESET</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_RDS_RECEIVED</para></listitem>
	   </itemizedlist>

For Band Scan it shall be V4L2_CG2900_RADIO_INTERRUPT_BAND_SCAN_COMPLETE, an appropriate handler should be then called from thethread to retrieve the found stations along with RSSI using the IOCTL VIDIOC_G_EXT_CTRLS, this IOCTL should be used with parameters as described in example code. Note that the common thread for capturing synchronous as well asynchronous events used here is FmInterruptMonitoringThread. It shall be used in other sections i.e. Block Scan, Cancel Scan, Search Frequency and Mono Stereo Transition.
           <programlisting>
			void Band_Scan()
		{
			struct v4l2_control sctrl
			int ret;
			sctrl.id = V4L2_CID_CG2900_RADIO_BANDSCAN;
			sctrl.value = V4L2_CG2900_RADIO_BANDSCAN_START;
			ret = ioctl(fd, VIDIOC_S_CTRL, &amp;sctrl);
			if (ret &lt; 0) {
				printf("VIDIOC_S_CTRL:error!!\n");
			}
			pthread_create(&amp;fmScanThread, NULL, FmScanThread, NULL);
		}

		static void *FmInterruptMonitoringThread(void *param)
		{
			struct v4l2_ext_controls FmInterrupt;
			struct pollfd pollFd;
			long * p = NULL;
			int index, ret, count = 0;
			int interrupt, interrupt_reason;
			int err;

			while(closeApp) {
			pollFd.fd = fd;
			pollFd.events = POLLRDNORM;
				/* wait infinitely for interrupt */
				timeout = -1;
				ret = poll(&amp;pollFd, 1, timeout);
				if(!closeApp)
					break;
				if(ret) {
				if(pollFd.revents &amp; POLLRDNORM)
				{
						/* Get the interrupt */
						FmInterrupt.count = 0;
						FmInterrupt.ctrl_class = V4L2_CTRL_CLASS_USER;
						FmInterrupt.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
						if(!FmInterrupt.controls)
							goto error;
						FmInterrupt.controls-&gt;id = V4L2_CID_CG2900_RADIO_GET_INTERRUPT;
						FmInterrupt.controls-&gt;size = 2;
						FmInterrupt.controls-&gt;string = (int *)malloc(sizeof(int) * FmInterrupt.controls-&gt;size);
						interrupt_buffer_pointer = FmInterrupt.controls-&gt;string;
						if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp;FmInterrupt) &lt; 0) {
							printf("VIDIOC_G_EXT_CTRLS:error!!\n");
							ret_val = -1;
							goto error_free_ext_control_string;
						}

						if(!ret_val) {
							interrupt = *interrupt_buffer_pointer;
							interrupt_reason = *(interrupt_buffer_pointer + 1);
							printf("Interrupt = %d, , Result = %d\n", interrupt, interrupt_reason);
							if(interrupt_reason == 0) {
								switch(interrupt)
								{
								case V4L2_CG2900_RADIO_INTERRUPT_BAND_SCAN_COMPLETED:
								/* Band Scan Completed */
								HandleBandScanCompletion();
								otherOperationInProgress = 0;
								break;

								}
							}
						}
error_free_ext_control_string:
						free(FmInterrupt.controls-&gt;string);
error_free_ext_control_control:
						free(FmInterrupt.controls);
error:
						otherOperationInProgress = 0;
					} else {
						printf ("FmInterruptMonitoringThread : poll returned = %d\n", ret);
					}
				}
			}
                        return 0;
		}

		static void HandleBandScanCompletion()
		{
			struct v4l2_ext_controls scanResult;
			long * band_scan_pointer = NULL;
			int err;
			int index, ret, count = 0;

			/* Get the Number Of Channels */
					scanResult.count = 0;
					scanResult.ctrl_class = V4L2_CTRL_CLASS_USER;
					scanResult.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
			if(!scanResult.controls)
				goto done;
			scanResult.controls-&gt;id = V4L2_CID_CG2900_RADIO_BANDSCAN_GET_RESULTS;
			scanResult.controls-&gt;size = 0;
			scanResult.controls-&gt;string = NULL;
					err = ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp; scanResult);

				if (err &lt; 0 &amp; &amp; errno !=  ENOSPC) {
					printf("VIDIOC_G_EXT_CTRLS:error!!\n");
				goto error_free_ext_control_control;
				}

			if(scanResult.controls-&gt;size &gt; 0 )
				{
				scanResult.controls-&gt;string = (long *)malloc(sizeof(long) * 2 * scanResult.controls-&gt;size );
				band_scan_pointer = scanResult.controls-&gt;string;
				printf("\n\n\n==================================\n");
				printf("\nNumber of Channels Found = %d \n", scanResult.controls-&gt;size);
				printf("\n==================================\n");
				if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp;scanResult) &lt; 0) {
						printf("VIDIOC_G_EXT_CTRLS:error!!\n");
					goto error_free_ext_control_string;
					}
				printf("\n================================\n");
				printf("\nSNo. 	Frequency(MHz)	RSSI\n");
				printf("\n================================\n");
				for (index = 0, count = 0; index &lt; scanResult.controls-&gt;size; index ++, count +=2) {
					printf("%d   	 %d.%d   	%d\n", index + 1,
						MEGAHRTZ((*(band_scan_pointer +count + 0) * 125) / 2),
						*(band_scan_pointer + count + 1));
					}
				printf("\n================================\n");
		error_free_ext_control_string:
				free(band_scan_pointer);
				}
			else if(scanResult.controls-&gt;size == 0)
				{
				printf("\nNo channels found during scanning!!\n");
				}
		error_free_ext_control_control:
				free(scanResult.controls);
		done:
			otherOperationInProgress = 0;
			}

           </programlisting>
           Note: Currently the retrieved signal strength is in decimals and not in "dBuV", proper external conversion required.
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
    <section id="block-scan">
     <title>Block Scan</title>
     <para>
       <!-- Driver loading Parameters:Not Applicable -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Block Scan</term>
         <listitem>
         <para>
           The Block Scan functionality will take two inputs, start and stop frequency (V4L2 compliance) and enables the host to scan all channels with in that range for RSSI values. The measured channels will be stored in a list in order of channel number and the  block scan feature to identify "empty" channels for transmission. And for doing a block scan, IOCTL VIDIOC_S_EXT_CTRL with parameter id of the v4l2_control structure should be set to V4L2_CID_FM_RADIO_BLOCKSCAN_START. If the IOCTL returns successfully, a common thread (which should have been created at the start of the application and is already polling to FM driver for multiple other interrupts including events related to Band Scan and Search Frequency operation) which polls with an infinite timeout iteratively until the end of the user-space application, when poll in one iteration is complete. When poll is complete, thread will make an IOCTL call with VIDIOC_G_EXT_CTRLS with parameter id set to V4L2_CID_CG2900_RADIO_GET_INTERRUPT and the data structure FmInterrupt.controls-&gt;string associated with V4L2_CID_CG2900_RADIO_GET_INTERRUPT shall contain the interrupt retrieved from FMD. Interrupts received in this manner from FMD can be any of the following.
	   <itemizedlist>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_UNKNOWN</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_SEARCH_COMPLETED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_BAND_SCAN_COMPLETED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_BLOCK_SCAN_COMPLETED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_SCAN_CANCELLED</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_MONO_STEREO_TRANSITION</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_DEVICE_RESET</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_INTERRUPT_RDS_RECEIVED</para></listitem>
           </itemizedlist>

For Block Scan it shall be V4L2_CG2900_RADIO_INTERRUPT_BLOCK_SCAN_COMPLETED, an appropriate handler should be then called from thethread to retrieve the found stations along with RSSI using the IOCTL VIDIOC_G_EXT_CTRLS, this IOCTL should be used with parameters as described in example code. Note that the common thread for capturing synchronous as well asynchronous events used here is FmInterruptMonitoringThread. It shall be used in other sections i.e. Band Scan, Cancel Scan, Search Frequency and Mono Stereo Transition. When poll is complete, the found stations along with RSSI should be retrieved using the IOCTL VIDIOC_G_EXT_CTRLS should be used with parameters as described in example code.
           <programlisting>
		void Block_Scan()
		{
			struct v4l2_ext_controls ext_ctrl;
			long *p = NULL;
		        int index;
		        int ret_val;
			if(1 == mode) {
		        otherOperationInProgress = 1;
			ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_USER;
			ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
			ext_ctrl.count = 0;
			ext_ctrl.controls-&gt;id = V4L2_CID_CG2900_RADIO_BLOCKSCAN_START;
			ext_ctrl.controls-&gt;size = 2;
			ext_ctrl.controls-&gt;string = (long *)malloc(sizeof(long) * ext_ctrl.controls-&gt;size);
			p = ext_ctrl.controls-&gt;string;
			*p = (StartFreq * 2)/ 125;
			*(p + 1) = (EndFreq * 2)/ 125;;
			if (ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp;ext_ctrl) &lt; 0)
				printf("APP_BlockScanStart:VIDIOC_S_EXT_CTRLS:error!!\n");
			free(ext_ctrl.controls-&gt;string);
			free(ext_ctrl.controls);
			pthread_create(&amp;fmBlockScanThread, NULL, FmBlockScanThread, NULL);
		}

		static void *FmInterruptMonitoringThread(void *param)
		{
			struct v4l2_ext_controls FmInterrupt;
			struct pollfd pollFd;
			long * p = NULL;
			int index, ret, count = 0;
			int interrupt, interrupt_reason;
			int err;

			while(closeApp) {
				pollFd.fd = fd;
				pollFd.events = POLLRDNORM;
				/* wait infinitely for interrupt */
				timeout = -1;
				ret = poll(&amp;pollFd, 1, timeout);
				if(!closeApp)
					break;
				if(ret) {
					if(pollFd.revents &amp; POLLRDNORM)
					{
						/* Get the interrupt */
						FmInterrupt.count = 0;
						FmInterrupt.ctrl_class = V4L2_CTRL_CLASS_USER;
						FmInterrupt.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
						if(!FmInterrupt.controls)
							goto error;
						FmInterrupt.controls-&gt;id = V4L2_CID_CG2900_RADIO_GET_INTERRUPT;
						FmInterrupt.controls-&gt;size = 2;
						FmInterrupt.controls-&gt;string = (int *)malloc(sizeof(int) * FmInterrupt.controls-&gt;size);
						interrupt_buffer_pointer = FmInterrupt.controls-&gt;string;
						if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp;FmInterrupt) &lt; 0) {
							printf("VIDIOC_G_EXT_CTRLS:error!!\n");
							ret_val = -1;
							goto error_free_ext_control_string;
						}

						if(!ret_val) {
							interrupt = *interrupt_buffer_pointer;
							interrupt_reason = *(interrupt_buffer_pointer + 1);
							printf("Interrupt = %d, , Result = %d\n", interrupt, interrupt_reason);
							if(interrupt_reason == 0) {
								switch(interrupt)
								{
								case V4L2_CG2900_RADIO_INTERRUPT_BLOCK_SCAN_COMPLETED:
								/* Block Scan Completed */
								HandleBlockScanCompletion();
								otherOperationInProgress = 0;
								break;
								}
							}
						}
error_free_ext_control_string:
						free(FmInterrupt.controls-&gt;string);
error_free_ext_control_control:
						free(FmInterrupt.controls);
error:
						otherOperationInProgress = 0;
					} else {
						printf ("FmInterruptMonitoringThread : poll returned = %d\n", ret);
					}
				}
			}
			return 0;
		}

		static void HandleBlockScanCompletion()
		{
			struct v4l2_ext_controls blockscanResult;
			long * block_scan_pointer = NULL;
			int index, ret;
			int err;
			int current_grid = -1;
			FILE *fp;
			long start_freq = StartFreq;
			long next_freq_offset = 0;

			fp = fopen("/sys/module/radio_cg2900/parameters/grid", "r");
			if(fp != NULL)
			{
				/* Retrieve the currently set grid to determine the next channel is 50 Khz, 100 Khz or 200 Khz apart */
				fscanf(fp, "%d", &amp;current_grid);
				fclose(fp);
			}

			if(current_grid == 0) {
				next_freq_offset = 50000;
			} else if	(current_grid == 1) {
				next_freq_offset = 100000;
			} else if (current_grid == 2) {
				next_freq_offset = 200000;
			}

				        /* Get the Number Of Channels */
				        blockscanResult.count = 0;
				        blockscanResult.ctrl_class = V4L2_CTRL_CLASS_USER;
				        blockscanResult.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
			if(!blockscanResult.controls)
				goto done;
			blockscanResult.controls-&gt;id = V4L2_CID_CG2900_RADIO_BLOCKSCAN_GET_RESULTS;
			blockscanResult.controls-&gt;size = 0;

			blockscanResult.controls-&gt;string = NULL;
				        err = ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp;blockscanResult);

					if (err &lt; 0 &amp;&amp; errno !=  ENOSPC) {
						printf("VIDIOC_G_EXT_CTRLS:error!!\n");
				goto error_free_ext_control_control;
					}

			if(blockscanResult.controls-&gt;size &gt; 0)
			{
				blockscanResult.controls-&gt;string = (long *)malloc(sizeof(long) * blockscanResult.controls-&gt;size );
				block_scan_pointer = blockscanResult.controls-&gt;string;
			        if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp;blockscanResult) &lt; 0) {
			                printf("VIDIOC_G_EXT_CTRLS:error!!\n");
					goto error_free_ext_control_string;
			        }
				printf("\n================================\n");
				printf("\nMHz.	RSSI\n");
				printf("\n================================\n");
				for (index = 0; index &lt; blockscanResult.controls-&gt;size; index ++) {
					printf("%d.%d		%d\n", MEGAHRTZ(start_freq), *(block_scan_pointer + index));
					start_freq += next_freq_offset;
			        }
				printf("\n================================\n");
		error_free_ext_control_string:
				free(block_scan_pointer);
			        }
			else if(blockscanResult.controls-&gt;size == 0)
				{
				      printf("\nNo channels found during Block Scan!!\n");
				}
		error_free_ext_control_control:
				free(blockscanResult.controls);
		done:
		  otherOperationInProgress = 0;
	   }


           </programlisting>
           Note: Currently the retrieved signal strength is in decimals and not in "dBuV", proper external conversion required.
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="cancel-scan-seek">
     <title>Cancel Scan</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Cancel Scan/Seek</term>
         <listitem>
         <para>
           This is used for stopping an active Band Scan, Seek operation and Block Scan. IOCTL VIDIOC_S_CTRL should be used with parameter id of the v4l2_control structure. For Eg incase of Band scan the parameter id should be set to V4L2_CID_CG2900_RADIO_BANDSCAN and the value of v4l2_control structure should be set as V4L2_CG2900_RADIO_BANDSCAN_STOP. The example thread shown in following code snippet FmInterruptMonitoringThread shall have already been started as mentioned in Band Scan and Block sections, it shall receive an asynchronous event V4L2_CG2900_RADIO_INTERRUPT_SCAN_CANCELLED.
           <programlisting>
		struct v4l2_control sctrl;
		int ret;
		sctrl.id = V4L2_CID_CG2900_RADIO_BANDSCAN;
		sctrl.value = V4L2_CG2900_RADIO_BANDSCAN_STOP;
		ret = ioctl(fd, VIDIOC_S_CTRL, &amp;sctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_CTRL:error!!\n");
		}

		static void *FmInterruptMonitoringThread(void *param)
		{
			struct v4l2_ext_controls FmInterrupt;
			struct pollfd pollFd;
			long * p = NULL;
			int index, ret, count = 0;
			int interrupt, interrupt_reason;
			int err;

			while(closeApp) {
				pollFd.fd = fd;
				pollFd.events = POLLRDNORM;
				/* wait infinitely for interrupt */
				timeout = -1;
				ret = poll(&amp;pollFd, 1, timeout);
				if(!closeApp)
					break;
				if(ret) {
					if(pollFd.revents &amp; POLLRDNORM)
					{
						/* Get the interrupt */
						FmInterrupt.count = 0;
						FmInterrupt.ctrl_class = V4L2_CTRL_CLASS_USER;
						FmInterrupt.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
						if(!FmInterrupt.controls)
							goto error;
						FmInterrupt.controls-&gt;id = V4L2_CID_CG2900_RADIO_GET_INTERRUPT;
						FmInterrupt.controls-&gt;size = 2;
						FmInterrupt.controls-&gt;string = (int *)malloc(sizeof(int) * FmInterrupt.controls-&gt;size);
						interrupt_buffer_pointer = FmInterrupt.controls-&gt;string;
						if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &amp;FmInterrupt) &lt; 0) {
							printf("VIDIOC_G_EXT_CTRLS:error!!\n");
							ret_val = -1;
							goto error_free_ext_control_string;
						}

						if(!ret_val) {
							interrupt = *interrupt_buffer_pointer;
							interrupt_reason = *(interrupt_buffer_pointer + 1);
							printf("Interrupt = %d, , Result = %d\n", interrupt, interrupt_reason);
							if(interrupt_reason == 0) {
								switch(interrupt)
								{
								case V4L2_CG2900_RADIO_INTERRUPT_SCAN_CANCELLED:
								/* Scan/Search/Block Scan Cancelled */
								printf(" Scan cancelled by user\n");
								otherOperationInProgress = 0;
								break;
								}
							}
						}
error_free_ext_control_string:
						free(FmInterrupt.controls-&gt;string);
error_free_ext_control_control:
						free(FmInterrupt.controls);
error:
						otherOperationInProgress = 0;
					} else {
						printf ("FmInterruptMonitoringThread : poll returned = %d\n", ret);
					}
				}
			}
			return 0;
		}

           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="rds-receive">
     <title>RDS Receive</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>RDS Receive</term>
         <listitem>
         <para>
           For enabling/disabling RDS for FM Rx, IOCTL VIDIOC_S_TUNER should be used with parameter rxsubchans of the v4l2_tuner structure set to V4L2_TUNER_SUB_RDS if rds needs to be enabled and the same value must not be set in case rds is to be disabled. Once RDS data is available, the appplication would be signalled waiting on poll. If the Interrupt retrieved using V4L2_CID_CG2900_RADIO_GET_INTERRUPT is V4L2_CG2900_RADIO_INTERRUPT_RDS_RECEIVED, RDS data can be retrieved using the read() functionality from the CG2900 FM driver. The RDS data received from FM Driver should be parsed in user space to retrive RDS information i.e Radio Text, Program Service Name, Program Identification, Program Type, Alternate Frequency, etc.
           <programlisting>
           void rds_rx_set(bool enable_rds)
           {
		struct v4l2_tuner tuner;
		int ret;
		memset(&amp;tuner, 0, sizeof(tuner));
		tuner.index = 0;
		if(enable_rds)
			tuner.rxsubchans |= V4L2_TUNER_SUB_RDS;
		else
			tuner.rxsubchans &amp; = ~V4L2_TUNER_SUB_RDS;
		ret = ioctl(fd, VIDIOC_S_TUNER, &amp;tuner);
		if (ret &lt; 0) {
			printf("VIDIOC_S_TUNER:error!!\n");
		}
	   }
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="af-update_switch">
     <title>AF Update and Switching</title>
     <para>
      <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>AF Update &amp; Switching</term>
         <listitem>
	 <para>Alternate Frequency (AF) Handling needs to be done in user space.</para>
	 <para>The application should use the AF RDS group data to compose a list of AFs when tuned to a new channel.</para>
	 <para>When the reception of the currently tuned frequency falls below a set threshold, it can decide to switch to one of the alternative frequencies for this channel.
	 </para>
	 <para>The application can perform an AF Update, which returns the RSSI value for all or some of the channel's AFs. Thus allowing the hardware to switch to the AF with the highest RSSI.  The AF Update could be designed to stop as soon as it finds an AF with an acceptable RSSI level. In the event that all the AF RSSI values are lower than the base channel, the AF Switch would not be necessary.
	 </para>
	 <para>To know the RSSI of the alternative frequencies (V4L2 compliance), the application can use the IOCTL VIDIOC_S_CTRL with parameter id set to V4L2_CID_CG2900_RADIO_RDS_AF_UPDATE_START, and the parameter value be set as the frequency in Hz for a channel from the AF List. If this call returns successfully,  the RSSI of the frequency can then be retrieved. Using IOCTL VIDIOC_G_CTRL, with the parameter id set to V4L2_CID_CG2900_RADIO_RDS_AF_UPDATE_GET_RESULT, and the output parameter value will contain the RSSI of the AF frequency.
	 </para>
	 <para>If it is still deemed necessary to switch channels, the next step is then to switch to an alternative frequency in the AF list. This can be done using the IOCTL VIDIOC_S_EXT_CTRLS, with:
	 </para>
	  <itemizedlist>
	   <listitem><para>Parameter id set to V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_START</para></listitem>
	   <listitem><para>Parameter size set to 2</para></listitem>
	   <listitem><para>Parameters filled as below (string field of the parameter) </para></listitem>
	   <listitem><para>Control class parameter set to V4L2_CTRL_CLASS_USER</para></listitem>
	   <listitem><para>The AF switch frequency in Hz</para></listitem>
	   <listitem><para>Expected PI code </para></listitem>
           </itemizedlist>
         <para>The application can check if the AF switch succeeded or not using the IOCTL VIDIOC_G_CTRL, with parameter id set to V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_GET_RESULT, and the output parameter value will contain the AF switch conclusion.
         </para>
	 <para> The example code below illustrates both the aforementioned functionalities.</para>
	<para>
	   <programlisting>
           void PerformAFUpdate(long AF_Frequency, int *AF_Rssi)
           {
		struct v4l2_control sctrl, gctrl;
		int ret;
		sctrl.id = V4L2_CID_CG2900_RADIO_RDS_AF_UPDATE_START;
		sctrl.value = AF_Frequency;
		ret = ioctl(fd, VIDIOC_S_CTRL, &amp; sctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_CTRL:error!!\n");
		}
		gctrl.id = V4L2_CID_CG2900_RADIO_RDS_AF_UPDATE_GET_RESULT;
		ret = ioctl(fd, VIDIOC_G_CTRL, &amp; gctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_G_CTRL:error!!\n");
		}
		*AF_Rssi = gctrl.value;
	   }
           void PerformAFSwitch(long AF_BestFrequency, int AF_ExpectedPI, int *AF_SwitchConclusion)
           {
		struct v4l2_control gctrl;
		struct v4l2_ext_controls ext_ctrl;
		int ret;
		int conclusion;
		long freq;
		long *p = NULL;
		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_USER;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls->id = V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_START;
		ext_ctrl.controls->size = 2;
		ext_ctrl.controls->string = (long *)malloc(sizeof(long) * ext_ctrl.controls->size);
		p = ext_ctrl.controls->string;
		*p = (AF_BestFrequency * 2)/ 125;
		*(p+1) = (long)AF_ExpectedPI;
		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRLS:error!!\n");
		}
		free(ext_ctrl.controls->string);
		free(ext_ctrl.controls);
		gctrl.id = V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_GET_RESULT;
		ret = ioctl(fd, VIDIOC_G_CTRL, &amp; gctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_G_CTRL:error!!\n");
		}
		*AF_SwitchConclusion = gctrl.value;
	   }
           </programlisting>
              Note: For V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_GET_RESULT returned values are:
               <itemizedlist>
                 <listitem><para> -1 AF Switch failed, the AF-RSSI was too low.</para></listitem>
                 <listitem><para> -2 AF Switch failed, the AF-PI Doesn't correlate.</para></listitem>
                 <listitem><para> -3 AF Switch failed, the AF-RDS SYNC Lost.</para></listitem>
               </itemizedlist>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="rds-transmit">
     <title>RDS Transmit</title>
     <para>
      <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>RDS Transmit</term>
         <listitem>
         <para>
           For enabling/disabling RDS for FM Tx, IOCTL VIDIOC_S_MODULATOR should be used with parameter txsubchans of the v4l2_modulator structure set to V4L2_TUNER_SUB_RDS if rds needs to be enabled and the same value must not be set in case rds is to be disabled. For Trasmitting RDS Data like PI, PTY, PSN, RT, VIDIOC_S_EXT_CTRLS IOCTL should be used with the id set to V4L2_CID_RDS_TX_PI, V4L2_CID_RDS_TX_PTY, V4L2_CID_RDS_TX_PS_NAME and V4L2_CID_RDS_TX_RADIO_TEXT respectively. Below example shows how to transmit various RDS functionalities.
           <programlisting>
           void rds_tx_set(bool enable_rds)
           {
		struct v4l2_modulator modulator;
		int ret;
		memset(&amp;modulator, 0, sizeof(modulator));
		modulator.index = 0;
		if(enable_rds)
			modulator.txsubchans |= V4L2_TUNER_SUB_RDS;
		else
			modulator.txsubchans &amp; = ~V4L2_TUNER_SUB_RDS;
		ret = ioctl(fd, VIDIOC_S_MODULATOR, &amp; modulator);
		if (ret &lt; 0) {
			printf("VIDIOC_S_MODULATOR:error!!\n");
		}
	   }
           void rds_tx_PI(void *value)
           {
		struct v4l2_ext_controls ext_ctrl;
		int ret;
		unsigned short *pi_code = (unsigned short *)value;
		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_FM_TX;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls->id = V4L2_CID_RDS_TX_PI;
		ext_ctrl.controls->size = 0;
		ext_ctrl.controls->string = NULL;
		ext_ctrl.controls->value = *pi_code;
		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRLS:error!!\n");
		}
		free(ext_ctrl.controls);
	   }
           void rds_tx_PTY(void *value)
           {
		struct v4l2_ext_controls ext_ctrl;
		int ret;
		unsigned short *pty_code = (unsigned short *)value;
		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_FM_TX;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls->id = V4L2_CID_RDS_TX_PTY;
		ext_ctrl.controls->size = 0;
		ext_ctrl.controls->string = NULL;
		ext_ctrl.controls->value = *pty_code;
		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRLS:error!!\n");
		}
		free(ext_ctrl.controls);
	   }
           void rds_tx_PSN(void *value)
           {
		struct v4l2_ext_controls ext_ctrl;
		int ret;
		char *psn = (char *)value;
		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_FM_TX;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls->id = V4L2_CID_RDS_TX_PS_NAME;
		ext_ctrl.controls->size = strlen(psn);
		ext_ctrl.controls->value = 0;
		ext_ctrl.controls->string = (char *)malloc(ext_ctrl.controls->size);
		memcpy(ext_ctrl.controls->string, psn, ext_ctrl.controls->size);
		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRLS:error!!\n");
		}
		free(ext_ctrl.controls->string);
		free(ext_ctrl.controls);
	   }
           void rds_tx_RT(void *value)
           {
		struct v4l2_ext_controls ext_ctrl;
		int ret;
		char *radio_text = (char *)value;
		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_FM_TX;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls->id = V4L2_CID_RDS_TX_RADIO_TEXT;
		ext_ctrl.controls->size = strlen(radio_text);
		ext_ctrl.controls->value = 0;
		ext_ctrl.controls->string = (char *)malloc(ext_ctrl.controls->size);
		memcpy(ext_ctrl.controls->string, radio_text, ext_ctrl.controls->size);
		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRLS:error!!\n");
		}
		free(ext_ctrl.controls->string);
		free(ext_ctrl.controls);
	   }
	   </programlisting>
		 Note: RDS default parameters
                <itemizedlist>
                   <listitem><para>Programme Identification code[PI]: Default value -> 0x1234</para></listitem>
                   <listitem><para>Programme Type[PTY]: Default value -> OTHER_MUSIC</para></listitem>
                   <listitem><para>Music/Speech switch[M/S]: Default value -> Music</para></listitem>
                   <listitem><para>Programme Service name[PS]: Default value -> FM Xmit</para></listitem>
                   <listitem><para>Radio text[RT]: Default value -> Default Radio Text</para></listitem>
                 </itemizedlist>
        </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="internal-test-tone-generator">
     <title>Test Tone Generation</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>1. Enabling-Disabling test tone</term>
         <listitem>
         <para>
         1. For setting the test tone status, application should use IOCTL VIDIOC_S_CTRL with its parameter id set to V4L2_CID_CG2900_RADIO_TEST_TONE_GENERATOR_SET_STATUS and parameter value set to any of the following :
	  <itemizedlist>
	   <listitem><para>Turn off test tone - use V4L2_CG2900_RADIO_TEST_TONE_GEN_OFF</para></listitem>
	   <listitem><para>Turn on test tone - use  V4L2_CG2900_RADIO_TEST_TONE_GEN_ON_WO_SRC</para></listitem>
	   <listitem><para>Turn on with sample rate correction - use V4L2_CG2900_RADIO_TEST_TONE_GEN_ON_W_SRC</para></listitem>
           </itemizedlist>
           <programlisting>
           void SetTestToneStatus(int state)
           {
		struct v4l2_control sctrl;
		int ret;
		sctrl.id = V4L2_CID_CG2900_RADIO_TEST_TONE_GENERATOR_SET_STATUS;
		sctrl.value = state;
		ret = ioctl(fd, VIDIOC_S_CTRL, &amp; sctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_CTRL:error!!\n");
		}
	   }
           </programlisting>
         </para>
         </listitem>
         </varlistentry>

         <varlistentry>
	 <term>2. Test Tone Connect</term>
         <listitem>
         <para>
	 2. The internal test tone can be used following modes: FMR (receiver mode) and FMT (transmitter mode). Each of the waves, or the sum of them, can be used as audio source for the receiver audio outputs, or for the transmitter audio input. This can be done by means of command "Test Tone Connect". For the receiver, all available audio outputs will be connected to the tone generator. After switching FM to another mode, the command "Test Tone Connect" must be executed again to set up a connection in the new mode.
	 </para>

         <para>
         The IOCTL VIDIOC_S_EXT_CTRLS is used to perform Test Tone Connect operation, with following parameters:
         </para>
           <itemizedlist>
	   <listitem><para>Parameter id set to V4L2_CID_CG2900_RADIO_TEST_TONE_CONNECT</para></listitem>
	   <listitem><para>Parameter size set to 2</para></listitem>
	   <listitem><para>Control class parameter set to V4L2_CTRL_CLASS_USER</para></listitem>
	   <listitem><para>Parameters value filled as below in code snippet(string field of the parameter) </para></listitem>
	   <listitem><para>First byte of Parameter value shall contain connect parameter for left audio output </para></listitem>
	   <listitem><para>Second byte of Parameter value shall contain connect parameter forright audio output </para></listitem>
           </itemizedlist>

         <para>
         Value of either of Parameter values (for left or right audio outputs)can assume values:
         </para>
	   <itemizedlist>
	   <listitem><para>V4L2_CG2900_RADIO_TEST_TONE_NORMAL_AUDIO - Normal Audio</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_TEST_TONE_ZERO - Zero</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_TEST_TONE_TONE_1 - Tone_1</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_TEST_TONE_TONE_2 - Tone_2</para></listitem>
	   <listitem><para>V4L2_CG2900_RADIO_TEST_TONE_TONE_SUM - Tone_Sum</para></listitem>
           </itemizedlist>

           <programlisting>
           void TestToneConnect(u8 left_audio_mode, u8 right_audio_mode)
           {
		u8 *test_tone_connect_ptr = NULL;
		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_USER;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls-&gt;id = V4L2_CID_CG2900_RADIO_TEST_TONE_CONNECT;
		ext_ctrl.controls-&gt;size = 2;
		ext_ctrl.controls-&gt;string = (u8 *)malloc(sizeof(u8) * ext_ctrl.controls-&gt;size);
		test_tone_connect_ptr = ext_ctrl.controls-&gt;string;
		*(test_tone_connect_ptr) = left_audio_mode;
		*(test_tone_connect_ptr + 1) = right_audio_mode;

		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRL:error!!\n");
		}
	   }
           </programlisting>

         </listitem>
         </varlistentry>

         <varlistentry>
         <term>3. Test Tone Set Parameters</term>
         <listitem>
         <para>
         3. The tone generator is capable of generating two different sine waves with adjustable offset, amplitude, phase offset and frequency. These properties can be changed with command "Test Tone Set Params"
	 </para>

         <para>
         The IOCTL VIDIOC_S_EXT_CTRLS is used to perform Test Tone Set Parameters operation, with following parameters:
         </para>
           <itemizedlist>
	   <listitem><para>Parameter id set to V4L2_CID_CG2900_RADIO_TEST_TONE_SET_PARAMS</para></listitem>
	   <listitem><para>Parameter size set to 6</para></listitem>
	   <listitem><para>Control class parameter set to V4L2_CTRL_CLASS_USER</para></listitem>
	   <listitem><para>Parameters value filled as below in code snippet(string field of the parameter) </para></listitem>
	   <listitem><para>First word of Parameter value shall contain tone_gen (0: tone_1, 1:tone_2)</para></listitem>
	   <listitem><para>Second word of Parameter value shall contain frequency ([0x0000..0x7FFF], (default = 0x064D))</para></listitem>
	   <listitem><para>Third word of Parameter value shall contain volume ([0x0000..0x7FFF], (default = 0x0CCD))</para></listitem>
	   <listitem><para>Fourth word of Parameter value shall contain phase offset([0x8000..0x7FFF], (default = 0x0000))</para></listitem>
	   <listitem><para>Fifth word of Parameter value shall contain DC to add to tone([0x8000..0x7FFF], (default = 0x0000))</para></listitem>
	   <listitem><para>Sixth word of Parameter value shall contain waveform type(0=sine shaped, 1=Pulse shaped)</para></listitem>
           </itemizedlist>

           <programlisting>
           void Sample_TestToneSetParams()
           {
		u8 *test_tone_connect_ptr = NULL;
                u8 tone_gen =0, waveform = 1;     /* Tone_Gen = Tone_1, waveform type = pulse shaped */
                u16 frequency = 0x064D, volume = 0x0CCD, phase_offset = 0x0000, dc=0x0000;

		ext_ctrl.ctrl_class = V4L2_CTRL_CLASS_USER;
		ext_ctrl.controls = (struct v4l2_ext_control *) malloc(sizeof(struct v4l2_ext_control));
		ext_ctrl.count = 0;
		ext_ctrl.controls-&gt;id = V4L2_CID_CG2900_RADIO_TEST_TONE_CONNECT;
		ext_ctrl.controls-&gt;size = 6;
		ext_ctrl.controls-&gt;string = (u16 *)malloc(sizeof(u16) * ext_ctrl.controls-&gt;size);
		test_tone_connect_ptr = ext_ctrl.controls-&gt;string;
		*(test_tone_connect_ptr) = tone_gen;
		*(test_tone_connect_ptr + 1) = frequency;
		*(test_tone_connect_ptr + 2) = volume;
		*(test_tone_connect_ptr + 3) = phase_offset;
		*(test_tone_connect_ptr + 4) = dc;
		*(test_tone_connect_ptr + 5) = waveform;

		ret = ioctl(fd, VIDIOC_S_EXT_CTRLS, &amp; ext_ctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_EXT_CTRL:error!!\n");
		}
	}
           </programlisting>

         </listitem>

       </varlistentry>
     </variablelist>
   </section>
   <section id="de-emphasis-filter">
     <title>Test Tone Generation</title>
     <para>
        <!-- Do NOT change the chapter id or title! -->
     </para>
     <variablelist>
       <varlistentry>
         <term>Set De-Emphasis Filter</term>
         <listitem>
         <para>
         To apply de-emphasis filter to the FM received signal to compansate for
         preemphasis that has been applied to the signal by the FM transmitter. IOCTL VIDIOC_S_CTRL is used in with parameter id set to V4L2_CID_CG2900_RADIO_TUNE_DEEMPHASIS and parameter value can take following values:
	 <itemizedlist>
	   <listitem><para>Disable de-emphasis - use V4L2_CG2900_RADIO_DEEMPHASIS_DISABLED</para></listitem>
	   <listitem><para>De-emphasis with 50 micro seconds - use  V4L2_CG2900_RADIO_DEEMPHASIS_50_uS</para></listitem>
	   <listitem><para>De-emphasis filter with 75 micro seconds - use V4L2_CG2900_RADIO_DEEMPHASIS_75_uS</para></listitem>
         </itemizedlist>

           <programlisting>
           void SetDeemphasisLevel(int deemphasis_level)
           {
		struct v4l2_control sctrl;
		int ret;
		sctrl.id = V4L2_CID_CG2900_RADIO_TUNE_DEEMPHASIS ;
		sctrl.value = deemphasis_level;
		ret = ioctl(fd, VIDIOC_S_CTRL, &amp; sctrl);
		if (ret &lt; 0) {
			printf("VIDIOC_S_CTRL:error!!\n");
		}
	   }
           </programlisting>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>

 </chapter>
 <chapter id="driver-configuration">
   <title>Driver Configuration and Interaction</title>
   <!-- Do NOT change the chapter id or title! -->
   <para>
     For debug purposes the variable cg2900_fm_debug_level in the file cg2900_fm_driver.c can be changed to set how much debug printouts
     that shall be generated.
     <itemizedlist>
       <listitem><para>1 = Error logs</para></listitem>
       <listitem><para>2 = Info logs, e.g. function entries</para></listitem>
       <listitem><para>3 = Debug logs</para></listitem>
       <listitem><para>4 = HCI logs, i.e. contents of the transferred data</para></listitem>
     </itemizedlist>
       </para>
   <section id="driver-implemented-operations">
     <title>Implemented operations in driver</title>
     <para>
       </para>
     <para>
       <table>
         <title> Supported device driver operations when using character device </title>
         <tgroup cols="2"><tbody>
           <row><entry> open </entry> <entry> Opening a character device will Initialize the FM Chip and download the firmware files.</entry> </row>
           <row><entry> close </entry> <entry> Closes a character device will deinitialize the FM Chip.</entry> </row>
           <row><entry> poll </entry> <entry> Polling a character device will check if there is requested data is available or not.</entry> </row>
           <row><entry> read </entry> <entry> Reading from a character device reads RDS data from the Chip</entry> </row>
         </tbody></tgroup>
       </table>
     </para>
   </section>
   <section id="driver-loading">
     <title>Driver loading parameters</title>
     <para>
      </para>
     <variablelist>
       <varlistentry>
         <term>radio_nr</term>
         <listitem>
         <para>
           <variablelist>
             <varlistentry>
               <term>Parameter type</term>
               <listitem><synopsis><type>int</type></synopsis></listitem>
             </varlistentry>
             <varlistentry>
               <term>Default value</term>
               <listitem><para>0</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Runtime readable/modifiable</term>
               <listitem><para>Readable</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Description</term>
               <listitem>
               <para>
                 The parameter radio_nr in radio-cg2900.c can be set to register a particular minor number with Video4Linux. Currently this parameter is set to 0 by default, signifying that the "\dev\radio0" is the character device assigned to CG2900 FM Driver in Video4Linux.
		 If the Platform has more than 1 radio drivers, the radio_nr parameter should be changed in file radio-cg2900.c.
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Checking the Radio Number</term>
               <listitem>
               <para>
	       cat sys/module/radio_cg2900/parameters/radio_nr
               </para>
               <para>
		The above command gets the radio number registered with
		Video4Linux. This is used for opening the FM Radio
		character device from user space.
               </para>
               </listitem>
             </varlistentry>
           </variablelist>
         </para>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term>grid</term>
         <listitem>
         <para>
           <variablelist>
             <varlistentry>
               <term>Parameter type</term>
               <listitem><synopsis><type>int</type></synopsis></listitem>
             </varlistentry>
             <varlistentry>
               <term>Default value</term>
               <listitem><para>1</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Runtime readable/modifiable</term>
               <listitem><para>Readable</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Description</term>
               <listitem>
               <para>
                 The parameter grid in radio-cg2900.c defines the spacing to be used in Khz while switching on FM Radio.
                 <itemizedlist>
                   <listitem><para>0:  50 kHz (China)</para></listitem>
                   <listitem><para>1: 100 kHz (Europe, Japan)</para></listitem>
                   <listitem><para>2: 200 kHz (USA)</para></listitem>
                </itemizedlist>
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Changing the Grid</term>
               <listitem>
               <para>
		echo 1 &gt; /sys/module/radio_cg2900/parameters/grid.
               </para>
               <para>
		The above command sets the radio band spacing between
		two adjacent radio channels, in this case sets to 100KHz
		suitable for Europe. The change is applicable before
		switching on FM Radio, otherwise the change takes effect
		from next FM switch on.
               </para>
               <para>
		Note: The Grid parameter cannot be changed during FM radio is operational.
               </para>
               <para>
		The user must change the grid value and restart the FM radio when moving into a different radio region.
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Checking the current Grid Value</term>
               <listitem>
               <para>
		cat sys/module/radio_cg2900/parameters/grid.
               </para>
               <para>
		The above command gets the radio band spacing
		between two adjacent radio channels currently set.
               </para>
               </listitem>
             </varlistentry>
            </variablelist>
         </para>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term>band</term>
         <listitem>
         <para>
           <variablelist>
             <varlistentry>
               <term>Parameter type</term>
               <listitem><synopsis><type>int</type></synopsis></listitem>
             </varlistentry>
             <varlistentry>
               <term>Default value</term>
               <listitem><para>0</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Runtime readable/modifiable</term>
               <listitem><para>Readable</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Description</term>
               <listitem>
               <para>
                 The parameter band in radio-cg2900.c defines the band to be used while switching on FM Radio.
                 <itemizedlist>
                   <listitem><para>0: 87.5 - 108 MHz (USA, Europe)</para></listitem>
                   <listitem><para>1: 76   -  90 MHz (Japan)</para></listitem>
                   <listitem><para>2: 70   - 108 MHz (China wide band)</para></listitem>
                </itemizedlist>
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Changing the Band</term>
               <listitem>
               <para>
		echo 0 &gt; /sys/module/radio_cg2900/parameters/band.
               </para>
               <para>
		The above command sets the FM band to be used.
		In this case, it sets the FM band 87.5 - 100 MHz.
		The change is applicable before switching on FM Radio,
		otherwise the change takes effect from next FM switch on.
               </para>
               <para>
		Note: The band parameter cannot be changed during FM radio is operational.
               </para>
               <para>
		The user must change the band value and restart the FM radio when moving into a different radio region.
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Checking the current Band Value</term>
               <listitem>
               <para>
		cat sys/module/radio_cg2900/parameters/band.
               </para>
               <para>
		The above command gets the current radio band set.
               </para>
               </listitem>
             </varlistentry>
           </variablelist>
         </para>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term>cg2900_fm_debug_level</term>
         <listitem>
         <para>
           <variablelist>
             <varlistentry>
               <term>Parameter type</term>
               <listitem><synopsis><type>int</type></synopsis></listitem>
             </varlistentry>
             <varlistentry>
               <term>Default value</term>
               <listitem><para>1</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Runtime readable/modifiable</term>
               <listitem><para>Readable</para></listitem>
             </varlistentry>
             <varlistentry>
               <term>Description</term>
               <listitem>
               <para>
                 The parameter CG2900_fm_debug_level in platformosapi.c defines the debug level that is currently used.
                 The higher the debug level the more print-outs are received in the terminal window.
                 The following values are supported:
                <itemizedlist>
				<listitem><para>1 = Error logs</para></listitem>
				<listitem><para>2 = Info logs, e.g. function entries</para></listitem>
				<listitem><para>3 = Debug logs</para></listitem>
				<listitem><para>4 = HCI logs, i.e. contents of the transferred data</para></listitem>
				</itemizedlist>
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Changing the Log Level</term>
               <listitem>
               <para>
		echo 3 &gt; /sys/module/radio_cg2900/parameters/cg2900_fm_debug_level.
               </para>
               <para>
		The above command sets the Logging level of FM Driver.
		In this case, it set will print all the debug messages
		except the HCI commands exchanged with FM Chip.
               </para>
               </listitem>
             </varlistentry>
             <varlistentry>
               <term>Checking the current Log Level</term>
               <listitem>
               <para>
		cat sys/module/radio_cg2900/parameters/cg2900_fm_debug_level.
               </para>
               <para>
		The above command gets the current debug log level set.
               </para>
               </listitem>
             </varlistentry>
           </variablelist>
         </para>
         </listitem>
       </varlistentry>
     </variablelist>
     <para>
     </para>
   </section>
   <section id="driver-ioctl">
     <title>Driver IO Control</title>
     <para>
       Describes the FM driver IO control parameters
     </para>
     <variablelist>
       <varlistentry>
         <term><constant>VIDIOC_QUERYCAP</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Get</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_capability</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_QUERYCAP</constant> IOCTL is used to query the capabilities supported by FM Driver. IF the FM Driver supports FM Rx it should set the capabilities field bit should be bitwise OR'd with V4L2_CAP_TUNER, otherwise if it supports FM Tx, the capabilities field bit should  be bitwise OR'd with V4L2_CAP_MODULATOR.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to retrive the Capabilities successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
	<varlistentry>
         <term><constant>VIDIOC_G_TUNER</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Get</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_tuner</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_G_TUNER</constant> IOCTL gets the FM Radio Tuner properties supported by FM Radio. It is also used to retrieve RDS status, mono/stereo status and Signal strength of the tuned channel. These values are valid when FM is configured using IOCTL VIDIOC_S_TUNER, i.e in FM Rx mode.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to retrive the tuner properties successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
                 </itemizedlist>
		Note: Currently the retrieved signal strength is in decimals and not in "dBuV", proper external conversion required.
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_S_TUNER</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_tuner</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_S_TUNER</constant> IOCTL configures the FM radio in Rx mode. Only 1 FM Tuner is supported by FM Driver.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to set the tuner properties successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
	<varlistentry>
         <term><constant>VIDIOC_G_MODULATOR</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Get</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_tuner</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
                The <constant>VIDIOC_G_MODULATOR</constant> IOCTL gets the FM Radio Modulator properties supported by FM Radio. It is also used to retrieve RDS status and mono/stereo status. These values are valid when FM is configured using IOCTL VIDIOC_S_MODULATOR, i.e in FM Tx mode.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to retrive the tuner properties successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_S_MODULATOR</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_modulator</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_S_MODULATOR</constant> IOCTL configures the FM radio in Tx mode. Only 1 FM Modulator is supported by FM Driver.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to set the modulator properties successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_S_FREQUENCY</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_frequency</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_S_FREQUENCY</constant> IOCTL sets the frequency on FM radio in Rx or Tx mode. The frequency parameter passed is in V4L2 format.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to set the frequency successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_G_FREQUENCY</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_modulator</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_G_FREQUENCY</constant> IOCTL retrives the currently set frequency on FM Radio in Rx or Tx mode.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to get the frequency successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_S_HW_FREQ_SEEK</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_hw_freq_seek</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_S_HW_FREQ_SEEK</constant> IOCTL starts the seek operation when FM Radio is configured in Rx mode. The direction parameter indicates the direction of seeking from the current station. At present the FM Driver ignores the wrap_Around parameter and unconditional wrap around is supported. If the operation is started successfully, the application should use poll() to identify when the seek is over.
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to start the seek successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_G_CTRL</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Get</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_control</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_G_CTRL</constant> IOCTL to retrive value of a paticular control. The following controls are supported by FM Driver:
               <itemizedlist>
               <listitem><para>
               V4L2_CID_AUDIO_VOLUME
               </para></listitem>
               <listitem><para>
               V4L2_CID_AUDIO_MUTE
               </para></listitem>
               <listitem><para>
               V4L2_CID_AUDIO_BALANCE
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_RSSI_THRESHOLD
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_SELECT_ANTENNA
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_RDS_AF_UPDATE_GET_RESULT
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_GET_RESULT
               </para></listitem>
               </itemizedlist>
               Generic returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to retrive the value of the control successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
              Note: For V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_GET_RESULT returned values are:
               <itemizedlist>
                 <listitem><para> -1 AF Switch failed, the AF-RSSI was too low.</para></listitem>
                 <listitem><para> -2 AF Switch failed, the AF-PI Doesn't correlate.</para></listitem>
                 <listitem><para> -3 AF Switch failed, the AF-RDS SYNC Lost.</para></listitem>
               </itemizedlist>
              </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_S_CTRL</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_control</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
              <para>
               The <constant>VIDIOC_S_CTRL</constant> IOCTL to set value of a paticular control. The following controls are supported by FM Driver:
               <itemizedlist>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_CHIP_STATE
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_BANDSCAN
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_BLOCKSCAN_START
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_SELECT_ANTENNA
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_RSSI_THRESHOLD
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_RDS_AF_UPDATE_START
               </para></listitem>
               </itemizedlist>
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to set the value of the control successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_G_EXT_CTRLS</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Get</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_ext_controls</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_G_EXT_CTRLS</constant> IOCTL to retrive value of a paticular control. This is used when a control class is defined or when the value to be retrieved is more than 1 parameter(s). Only V4L2_CTRL_CLASS_FM_TX class is supported for this IOCTL in FM Driver. The following controls are supported by FM Driver:
               <itemizedlist>
               <listitem><para>
               V4L2_CID_RDS_TX_DEVIATION
               </para></listitem>
               <listitem><para>
               V4L2_CID_PILOT_TONE_ENABLED
               </para></listitem>
               <listitem><para>
               V4L2_CID_PILOT_TONE_DEVIATION
               </para></listitem>
               <listitem><para>
               V4L2_CID_TUNE_PREEMPHASIS
               </para></listitem>
               <listitem><para>
               V4L2_CID_TUNE_POWER_LEVEL
               </para></listitem>
               </itemizedlist>
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to retrive the value(s) of the control successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
       <varlistentry>
         <term><constant>VIDIOC_S_EXT_CTRLS</constant></term>
         <listitem>
         <variablelist>
           <varlistentry>
             <term>Direction</term>
             <listitem><para>Set</para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Parameter</term>
             <listitem><synopsis><type>v4l2_ext_controls</type></synopsis></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>
               The <constant>VIDIOC_S_CTRL</constant> IOCTL to set value of a paticular control when the parameters to be set are more than 1 parameter or when a control class is defined. At present only the V4L2_CTRL_CLASS_FM_TX and V4L2_CTRL_CLASS_USER control classes are supported by FM Driver. The following controls are supported by FM Driver:
               <itemizedlist>
               <listitem><para>
               V4L2_CID_RDS_TX_DEVIATION
               </para></listitem>
               <listitem><para>
               V4L2_CID_RDS_TX_PI
               </para></listitem>
               <listitem><para>
               V4L2_CID_RDS_TX_PTY
               </para></listitem>
               <listitem><para>
               V4L2_CID_RDS_TX_PS_NAME
               </para></listitem>
               <listitem><para>
               V4L2_CID_RDS_TX_RADIO_TEXT
               </para></listitem>
               <listitem><para>
               V4L2_CID_PILOT_TONE_ENABLED
               </para></listitem>
               <listitem><para>
               V4L2_CID_PILOT_TONE_DEVIATION
               </para></listitem>
               <listitem><para>
               V4L2_CID_TUNE_PREEMPHASIS
               </para></listitem>
               <listitem><para>
               V4L2_CID_TUNE_POWER_LEVEL
               </para></listitem>
               <listitem><para>
               V4L2_CID_CG2900_RADIO_RDS_AF_SWITCH_START
               </para></listitem>
               </itemizedlist>
               Returned values are:
               <itemizedlist>
                 <listitem><para>If IOCTL is able to set the value of the control successfully without errors the IOCTL function will return 0.</para></listitem>
                 <listitem><para>A negative value will indicate error.</para></listitem>
               </itemizedlist>
             </para>
             </listitem>
           </varlistentry>
         </variablelist>
         </listitem>
       </varlistentry>
     </variablelist>
   </section>
   <section id="driver-sysfs">
     <title>Driver Interaction with Sysfs</title>
     <para>
       Not Applicable
     </para>
   </section>
   <section id="driver-proc">
     <title>Driver Interaction using /proc filesystem</title>
     <para>
       Not Applicable
      </para>
   </section>
   <section id="driver-other">
     <title>Other means for Driver Interaction</title>
     <para>
      Not Applicable
     </para>
   </section>
 <section id="driver-node">
   <title>Driver Node File</title>
     <variablelist>
     <varlistentry>
       <term>FM Radio Device</term>
       <listitem>
         <variablelist>
           <varlistentry>
             <term>File</term>
             <listitem><para><filename>/dev/radio0</filename></para></listitem>
           </varlistentry>
           <varlistentry>
             <term>Description</term>
             <listitem>
             <para>The radio device for FM Radio.</para>
             </listitem>
           </varlistentry>
         </variablelist>
       </listitem>
     </varlistentry>
    </variablelist>
  </section>
 </chapter>
 <chapter id="bugs">
   <title>Known Bugs And Limitations</title>
     <para>
     <variablelist>
     <varlistentry>
       <term>No known issues.</term>
       <listitem>
         <para>
           <!-- Do NOT change the chapter id or title! -->
         </para>
       </listitem>
     </varlistentry>
     </variablelist>
  </para>
 </chapter>
 <chapter id="internal-functions">
   <title>Internal Functions Provided</title>
   <para>
	List of internal functions used in FM Driver.
   </para>
   <!-- Do NOT change the chapter id or title! -->
    <section id="radio-cg2900.c">
    <title>radio-cg2900.c</title>
!Idrivers/media/radio/CG2900/radio-cg2900.c
  </section>
  <section id="cg2900_fm_api.h">
    <title>cg2900_fm_api.h</title>
!Idrivers/media/radio/CG2900/cg2900_fm_api.h
  </section>
  <section id="cg2900_fm_api.c">
    <title>cg2900_fm_api.c</title>
!Idrivers/media/radio/CG2900/cg2900_fm_api.c
  </section>
  <section id="cg2900_fm_driver.h">
    <title>cg2900_fm_driver.h</title>
!Idrivers/media/radio/CG2900/cg2900_fm_driver.h
  </section>
  <section id="cg2900_fm_driver.c">
    <title>cg2900_fm_driver.c</title>
!Idrivers/media/radio/CG2900/cg2900_fm_driver.c
  </section>
 </chapter>
</book>