xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/v4l/dev-sdr.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun.. _sdr:
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun**************************************
6*4882a593SmuzhiyunSoftware Defined Radio Interface (SDR)
7*4882a593Smuzhiyun**************************************
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunSDR is an abbreviation of Software Defined Radio, the radio device which
10*4882a593Smuzhiyunuses application software for modulation or demodulation. This interface
11*4882a593Smuzhiyunis intended for controlling and data streaming of such devices.
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunSDR devices are accessed through character device special files named
14*4882a593Smuzhiyun``/dev/swradio0`` to ``/dev/swradio255`` with major number 81 and
15*4882a593Smuzhiyundynamically allocated minor numbers 0 to 255.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunQuerying Capabilities
19*4882a593Smuzhiyun=====================
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunDevices supporting the SDR receiver interface set the
22*4882a593Smuzhiyun``V4L2_CAP_SDR_CAPTURE`` and ``V4L2_CAP_TUNER`` flag in the
23*4882a593Smuzhiyun``capabilities`` field of struct
24*4882a593Smuzhiyun:c:type:`v4l2_capability` returned by the
25*4882a593Smuzhiyun:ref:`VIDIOC_QUERYCAP` ioctl. That flag means the
26*4882a593Smuzhiyundevice has an Analog to Digital Converter (ADC), which is a mandatory
27*4882a593Smuzhiyunelement for the SDR receiver.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunDevices supporting the SDR transmitter interface set the
30*4882a593Smuzhiyun``V4L2_CAP_SDR_OUTPUT`` and ``V4L2_CAP_MODULATOR`` flag in the
31*4882a593Smuzhiyun``capabilities`` field of struct
32*4882a593Smuzhiyun:c:type:`v4l2_capability` returned by the
33*4882a593Smuzhiyun:ref:`VIDIOC_QUERYCAP` ioctl. That flag means the
34*4882a593Smuzhiyundevice has an Digital to Analog Converter (DAC), which is a mandatory
35*4882a593Smuzhiyunelement for the SDR transmitter.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunAt least one of the read/write, streaming or asynchronous I/O methods
38*4882a593Smuzhiyunmust be supported.
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunSupplemental Functions
42*4882a593Smuzhiyun======================
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunSDR devices can support :ref:`controls <control>`, and must support
45*4882a593Smuzhiyunthe :ref:`tuner` ioctls. Tuner ioctls are used for setting the
46*4882a593SmuzhiyunADC/DAC sampling rate (sampling frequency) and the possible radio
47*4882a593Smuzhiyunfrequency (RF).
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunThe ``V4L2_TUNER_SDR`` tuner type is used for setting SDR device ADC/DAC
50*4882a593Smuzhiyunfrequency, and the ``V4L2_TUNER_RF`` tuner type is used for setting
51*4882a593Smuzhiyunradio frequency. The tuner index of the RF tuner (if any) must always
52*4882a593Smuzhiyunfollow the SDR tuner index. Normally the SDR tuner is #0 and the RF
53*4882a593Smuzhiyuntuner is #1.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunThe :ref:`VIDIOC_S_HW_FREQ_SEEK` ioctl is
56*4882a593Smuzhiyunnot supported.
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunData Format Negotiation
60*4882a593Smuzhiyun=======================
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunThe SDR device uses the :ref:`format` ioctls to select the
63*4882a593Smuzhiyuncapture and output format. Both the sampling resolution and the data
64*4882a593Smuzhiyunstreaming format are bound to that selectable format. In addition to the
65*4882a593Smuzhiyunbasic :ref:`format` ioctls, the
66*4882a593Smuzhiyun:ref:`VIDIOC_ENUM_FMT` ioctl must be supported as
67*4882a593Smuzhiyunwell.
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunTo use the :ref:`format` ioctls applications set the ``type``
70*4882a593Smuzhiyunfield of a struct :c:type:`v4l2_format` to
71*4882a593Smuzhiyun``V4L2_BUF_TYPE_SDR_CAPTURE`` or ``V4L2_BUF_TYPE_SDR_OUTPUT`` and use
72*4882a593Smuzhiyunthe struct :c:type:`v4l2_sdr_format` ``sdr`` member
73*4882a593Smuzhiyunof the ``fmt`` union as needed per the desired operation. Currently
74*4882a593Smuzhiyunthere are two fields, ``pixelformat`` and ``buffersize``, of
75*4882a593Smuzhiyunstruct :c:type:`v4l2_sdr_format` which are used.
76*4882a593SmuzhiyunContent of the ``pixelformat`` is V4L2 FourCC code of the data format.
77*4882a593SmuzhiyunThe ``buffersize`` field is maximum buffer size in bytes required for
78*4882a593Smuzhiyundata transfer, set by the driver in order to inform application.
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun.. c:type:: v4l2_sdr_format
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun.. flat-table:: struct v4l2_sdr_format
86*4882a593Smuzhiyun    :header-rows:  0
87*4882a593Smuzhiyun    :stub-columns: 0
88*4882a593Smuzhiyun    :widths:       1 1 2
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun    * - __u32
91*4882a593Smuzhiyun      - ``pixelformat``
92*4882a593Smuzhiyun      - The data format or type of compression, set by the application.
93*4882a593Smuzhiyun	This is a little endian
94*4882a593Smuzhiyun	:ref:`four character code <v4l2-fourcc>`. V4L2 defines SDR
95*4882a593Smuzhiyun	formats in :ref:`sdr-formats`.
96*4882a593Smuzhiyun    * - __u32
97*4882a593Smuzhiyun      - ``buffersize``
98*4882a593Smuzhiyun      - Maximum size in bytes required for data. Value is set by the
99*4882a593Smuzhiyun	driver.
100*4882a593Smuzhiyun    * - __u8
101*4882a593Smuzhiyun      - ``reserved[24]``
102*4882a593Smuzhiyun      - This array is reserved for future extensions. Drivers and
103*4882a593Smuzhiyun	applications must set it to zero.
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun
106*4882a593SmuzhiyunAn SDR device may support :ref:`read/write <rw>` and/or streaming
107*4882a593Smuzhiyun(:ref:`memory mapping <mmap>` or :ref:`user pointer <userp>`) I/O.
108