162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci.. _sdr:
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci**************************************
662306a36Sopenharmony_ciSoftware Defined Radio Interface (SDR)
762306a36Sopenharmony_ci**************************************
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciSDR is an abbreviation of Software Defined Radio, the radio device which
1062306a36Sopenharmony_ciuses application software for modulation or demodulation. This interface
1162306a36Sopenharmony_ciis intended for controlling and data streaming of such devices.
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciSDR devices are accessed through character device special files named
1462306a36Sopenharmony_ci``/dev/swradio0`` to ``/dev/swradio255`` with major number 81 and
1562306a36Sopenharmony_cidynamically allocated minor numbers 0 to 255.
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciQuerying Capabilities
1962306a36Sopenharmony_ci=====================
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciDevices supporting the SDR receiver interface set the
2262306a36Sopenharmony_ci``V4L2_CAP_SDR_CAPTURE`` and ``V4L2_CAP_TUNER`` flag in the
2362306a36Sopenharmony_ci``capabilities`` field of struct
2462306a36Sopenharmony_ci:c:type:`v4l2_capability` returned by the
2562306a36Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. That flag means the
2662306a36Sopenharmony_cidevice has an Analog to Digital Converter (ADC), which is a mandatory
2762306a36Sopenharmony_cielement for the SDR receiver.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciDevices supporting the SDR transmitter interface set the
3062306a36Sopenharmony_ci``V4L2_CAP_SDR_OUTPUT`` and ``V4L2_CAP_MODULATOR`` flag in the
3162306a36Sopenharmony_ci``capabilities`` field of struct
3262306a36Sopenharmony_ci:c:type:`v4l2_capability` returned by the
3362306a36Sopenharmony_ci:ref:`VIDIOC_QUERYCAP` ioctl. That flag means the
3462306a36Sopenharmony_cidevice has an Digital to Analog Converter (DAC), which is a mandatory
3562306a36Sopenharmony_cielement for the SDR transmitter.
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciAt least one of the read/write or streaming I/O methods
3862306a36Sopenharmony_cimust be supported.
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciSupplemental Functions
4262306a36Sopenharmony_ci======================
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciSDR devices can support :ref:`controls <control>`, and must support
4562306a36Sopenharmony_cithe :ref:`tuner` ioctls. Tuner ioctls are used for setting the
4662306a36Sopenharmony_ciADC/DAC sampling rate (sampling frequency) and the possible radio
4762306a36Sopenharmony_cifrequency (RF).
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ciThe ``V4L2_TUNER_SDR`` tuner type is used for setting SDR device ADC/DAC
5062306a36Sopenharmony_cifrequency, and the ``V4L2_TUNER_RF`` tuner type is used for setting
5162306a36Sopenharmony_ciradio frequency. The tuner index of the RF tuner (if any) must always
5262306a36Sopenharmony_cifollow the SDR tuner index. Normally the SDR tuner is #0 and the RF
5362306a36Sopenharmony_cituner is #1.
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciThe :ref:`VIDIOC_S_HW_FREQ_SEEK` ioctl is
5662306a36Sopenharmony_cinot supported.
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ciData Format Negotiation
6062306a36Sopenharmony_ci=======================
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciThe SDR device uses the :ref:`format` ioctls to select the
6362306a36Sopenharmony_cicapture and output format. Both the sampling resolution and the data
6462306a36Sopenharmony_cistreaming format are bound to that selectable format. In addition to the
6562306a36Sopenharmony_cibasic :ref:`format` ioctls, the
6662306a36Sopenharmony_ci:ref:`VIDIOC_ENUM_FMT` ioctl must be supported as
6762306a36Sopenharmony_ciwell.
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciTo use the :ref:`format` ioctls applications set the ``type``
7062306a36Sopenharmony_cifield of a struct :c:type:`v4l2_format` to
7162306a36Sopenharmony_ci``V4L2_BUF_TYPE_SDR_CAPTURE`` or ``V4L2_BUF_TYPE_SDR_OUTPUT`` and use
7262306a36Sopenharmony_cithe struct :c:type:`v4l2_sdr_format` ``sdr`` member
7362306a36Sopenharmony_ciof the ``fmt`` union as needed per the desired operation. Currently
7462306a36Sopenharmony_cithere are two fields, ``pixelformat`` and ``buffersize``, of
7562306a36Sopenharmony_cistruct :c:type:`v4l2_sdr_format` which are used.
7662306a36Sopenharmony_ciContent of the ``pixelformat`` is V4L2 FourCC code of the data format.
7762306a36Sopenharmony_ciThe ``buffersize`` field is maximum buffer size in bytes required for
7862306a36Sopenharmony_cidata transfer, set by the driver in order to inform application.
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci.. c:type:: v4l2_sdr_format
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci.. flat-table:: struct v4l2_sdr_format
8662306a36Sopenharmony_ci    :header-rows:  0
8762306a36Sopenharmony_ci    :stub-columns: 0
8862306a36Sopenharmony_ci    :widths:       1 1 2
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci    * - __u32
9162306a36Sopenharmony_ci      - ``pixelformat``
9262306a36Sopenharmony_ci      - The data format or type of compression, set by the application.
9362306a36Sopenharmony_ci	This is a little endian
9462306a36Sopenharmony_ci	:ref:`four character code <v4l2-fourcc>`. V4L2 defines SDR
9562306a36Sopenharmony_ci	formats in :ref:`sdr-formats`.
9662306a36Sopenharmony_ci    * - __u32
9762306a36Sopenharmony_ci      - ``buffersize``
9862306a36Sopenharmony_ci      - Maximum size in bytes required for data. Value is set by the
9962306a36Sopenharmony_ci	driver.
10062306a36Sopenharmony_ci    * - __u8
10162306a36Sopenharmony_ci      - ``reserved[24]``
10262306a36Sopenharmony_ci      - This array is reserved for future extensions. Drivers and
10362306a36Sopenharmony_ci	applications must set it to zero.
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciAn SDR device may support :ref:`read/write <rw>` and/or streaming
10762306a36Sopenharmony_ci(:ref:`memory mapping <mmap>` or :ref:`user pointer <userp>`) I/O.
108