Move vendor library code for ad936x RFIC to /thirdparty; use git submodule (#689)

This PR creates a git submodule for the analogdevicesinc/no-OS code, moving it from host/libraries/libbladeRF/src/driver/thirdparty/adi/ to thirdparty/analogdevicesinc/no-OS and adjusting the build process accordingly.

The build process will handle the git submodule init / git submodule update as required, or it may be done manually before the build. It will then copy the necessary files to the build tree, apply a series of patches for local modifications, and then build it as libad936x.

There are no changes to the build steps, although the build will fail if git submodule init/update needs to happen but can't (e.g. if github is not reachable).

* thirdparty: add no-OS library submodule

Adds a submodule for https://github.com/analogdevicesinc/no-OS/, pinned
at commit 0bba46e.

* thirdparty: patch and build libad936x

Add cmake file for libad936x

Move our local mods into patch files

* host: libbladeRF: transition to libad936x

Transitions libbladeRF (particularly bladerf2.c) to use the libad936x
package, compiled separately.

This also adds ad936x.h, a driver header file that contains the
necessary things from libad936x.  This is cleaner than just importing
ad9361_api.h, due to the significant dependency/include challenges that
ensue...

* host: fix up libad936x build

Don't use ExternalProject, instead just add it as a subdirectory

Create a FindPatcher.cmake for the patch-or-git selector

Clean up and streamline the ad936x cmakelists

Clean up libbladeRF cmakelist formatting

* thirdparty: fix no-OS patch 0003

* host: ad936x: fixup build errors/warnings on macOS

* thirdparty/adi: patch to chop out ad9361_parse_fir

ad9361_parse_fir refers to sscanf, which is not readily available in the
Nios II library. We don't use this function, so it can go.

* libbladeRF: remove vestigial adi files

* debian: rm thirdparty ADI tree from license file

* host: thirdparty: fix git package handling

* host: thirdparty/ad936x: specify patches in order

It turns out that there's no guarantee that file(GLOB)
will output the patch files in the alphabetical order.

* Revert "debian: rm thirdparty ADI tree from license file"

This reverts commit 36cf335c0e.

* debian: update path in ADI copyright
This commit is contained in:
Rey Tucker 2018-11-12 18:13:58 -05:00 • committed by GitHub
commit 48ec0a40a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 2937 additions and 14865 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "thirdparty/analogdevicesinc/no-OS"]
path = thirdparty/analogdevicesinc/no-OS
url = https://github.com/analogdevicesinc/no-OS/

View file

@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 2.8)
# Indicate that this is a top-level build
set(BLADERF_TOP_LEVEL_BUILD ON)
#####################################################################
# Choose which major components to build
#####################################################################

8
debian/copyright vendored
View file

@ -104,10 +104,6 @@ Copyright: 2013-2018 Nuand LLC
2013 Daniel Gröber
License: LGPL-2.1+
Files: host/libraries/libbladeRF/src/driver/thirdparty/adi/*
Copyright: 2013-2015 Analog Devices, Inc.
License: AnalogDevices
Files: host/utilities/*
Copyright: 2013-2018 Nuand LLC
2013 Daniel Gröber
@ -133,6 +129,10 @@ Copyright: 2005 Colin Percival
2013 Daniel Gröber
License: BSD-2-clause
Files: thirdparty/analogdevicesinc/no-OS/*
Copyright: 2013-2015 Analog Devices, Inc.
License: AnalogDevices
License: AGPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as

View file

@ -73,6 +73,20 @@ endif()
include(CheckLibraryExists)
check_library_exists(c clock_gettime "time.h" HAVE_CLOCK_GETTIME)
################################################################################
# Build third-party libraries
################################################################################
# TODO: the build will fail unless this is enabled.
option(BUILD_AD936X
"Include support for the Analog Devices AD936x RFIC."
ON)
option(BUILD_AD936X_DEBUG
"Enable debugging output for the AD936x library."
OFF)
# We do this prior to the rest of host/common, as the compile options are
# going to be different.
add_subdirectory(common/thirdparty/ad936x)
################################################################################
# Compiler configuration
################################################################################

View file

@ -0,0 +1,42 @@
if(DEFINED __INCLUDED_BLADERF_FIND_PATCHER)
return()
endif()
set(__INCLUDED_BLADERF_FIND_PATCHER TRUE)
# Look for the packages we want
find_package(Patch QUIET)
find_package(Git QUIET)
# Work around cross-platform case sensitivity issues
if(PATCH_FOUND)
set(Patch_FOUND ${PATCH_FOUND})
if (PATCH_EXECUTABLE)
set(Patch_EXECUTABLE ${PATCH_EXECUTABLE})
endif()
endif()
if(GIT_FOUND)
set(Git_FOUND ${GIT_FOUND})
if (GIT_EXECUTABLE)
set(Git_EXECUTABLE ${GIT_EXECUTABLE})
endif()
endif()
# patch is preferred, but git-apply is also okay.
if(Patch_FOUND)
set(Patcher_FOUND TRUE)
set(Patcher_EXECUTABLE ${Patch_EXECUTABLE})
elseif(Git_FOUND)
set(Patcher_FOUND TRUE)
set(Patcher_EXECUTABLE ${Git_EXECUTABLE};--bare;apply;-)
else()
set(Patcher_FOUND FALSE)
endif()
if(NOT Patcher_FOUND AND Patcher_FIND_REQUIRED)
message(FATAL_ERROR "FindPatcher: Could not find either 'patch' or 'git'!")
endif()
if(Patcher_FOUND AND NOT Patcher_FIND_QUIETLY)
message(STATUS "FindPatcher: found ${Patcher_EXECUTABLE}")
endif()

View file

@ -0,0 +1,198 @@
message(STATUS "libad936x: Configuring build...")
################################################################################
# Paths
################################################################################
# Repository root
set(LIBAD936X_BLADERF_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../..")
# Source directory for local files (patches, platform_bladerf2, etc)
set(LIBAD936X_LOCAL_DIR "${LIBAD936X_BLADERF_ROOT}/thirdparty/analogdevicesinc/no-OS_local")
# libbladeRF relative path
set(LIBAD936X_LIBBLADERF_DIR "${LIBAD936X_BLADERF_ROOT}/host/libraries/libbladeRF")
# Patch files live here
set(LIBAD936X_PATCH_DIR "${LIBAD936X_LOCAL_DIR}/patches")
# Platform files
set(LIBAD936X_PLATFORM_DIR "${LIBAD936X_LOCAL_DIR}/platform_bladerf2")
# Upstream source (clean)
set(LIBAD936X_UPSTREAM_DIR "${LIBAD936X_LOCAL_DIR}/../no-OS/ad9361/sw")
# Upstream source (patched)
set(LIBAD936X_UPSTREAM_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
################################################################################
# Configure build
################################################################################
add_library(ad936x STATIC
${LIBAD936X_UPSTREAM_BUILD_DIR}/ad9361.c
${LIBAD936X_UPSTREAM_BUILD_DIR}/ad9361_api.c
${LIBAD936X_UPSTREAM_BUILD_DIR}/ad9361_conv.c
${LIBAD936X_UPSTREAM_BUILD_DIR}/util.c
${LIBAD936X_PLATFORM_DIR}/platform.c
${LIBAD936X_PLATFORM_DIR}/adc_core.c
${LIBAD936X_PLATFORM_DIR}/dac_core.c
${LIBAD936X_PLATFORM_DIR}/params.c
)
target_compile_options(ad936x PRIVATE
-DNUAND_MODIFICATIONS
-Wall -Os
)
if(NOT MSVC)
target_compile_options(ad936x PRIVATE
-ffunction-sections
-fdata-sections
-fPIC
-std=gnu11
)
endif(NOT MSVC)
if(NOT MSVC AND NOT APPLE)
target_compile_options(ad936x PRIVATE
-Wno-unused-but-set-variable
)
endif(NOT MSVC AND NOT APPLE)
if(APPLE)
target_compile_options(ad936x PRIVATE
-Wno-absolute-value
)
endif(APPLE)
if(BUILD_AD936X_DEBUG)
message(STATUS "libad936x: Enabling debugging output")
target_compile_options(ad936x PRIVATE -D_DEBUG)
endif(BUILD_AD936X_DEBUG)
target_include_directories(ad936x PUBLIC
${LIBAD936X_PLATFORM_DIR}
${LIBAD936X_UPSTREAM_BUILD_DIR}
${LIBAD936X_LIBBLADERF_DIR}/src
${LIBAD936X_LIBBLADERF_DIR}/include
${LIBAD936X_BLADERF_ROOT}/host/common/include
${LIBAD936X_BLADERF_ROOT}/firmware_common
# host_config.h: two possible paths
# we can't use find_file to find this, as it hasn't been generated yet
${CMAKE_CURRENT_BINARY_DIR}/../../../host/common/include
${CMAKE_CURRENT_BINARY_DIR}/../../../common/include
)
################################################################################
# Dependencies
################################################################################
if(MSVC)
target_include_directories(ad936x PUBLIC ${MSVC_C99_INCLUDES})
find_package(LibPThreadsWin32 REQUIRED)
if(LIBPTHREADSWIN32_FOUND)
set(HAVE_THREADS true)
target_include_directories(ad936x PUBLIC ${LIBPTHREADSWIN32_INCLUDE_DIRS})
set(LIBAD936X_LIBS
${LIBAD936X_LIBS} ${LIBPTHREADSWIN32_LIBRARIES})
else()
set(HAVE_THREADS false)
endif()
else(MSVC)
find_package(Threads REQUIRED)
if(Threads_FOUND)
set(HAVE_THREADS true)
else()
set(HAVE_THREADS false)
endif()
target_link_libraries(ad936x ${CMAKE_THREAD_LIBS_INIT})
endif(MSVC)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_include_directories(ad936x PUBLIC /usr/include/malloc)
endif()
# If the submodule hasn't been initialized/updated, do so
if(NOT IS_DIRECTORY ${LIBAD936X_UPSTREAM_DIR})
message(STATUS "libad936x: Attempting to initialize missing submodule")
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule init
WORKING_DIRECTORY ${LIBAD936X_BLADERF_ROOT}
)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update
WORKING_DIRECTORY ${LIBAD936X_BLADERF_ROOT}
)
endif()
endif()
# Then, re-check for submodule...
if(NOT IS_DIRECTORY ${LIBAD936X_UPSTREAM_DIR})
message(FATAL_ERROR "Directory ${LIBAD936X_UPSTREAM_DIR} was not found. "
"It appears that this submodule has not been properly "
"initialized. Please run 'git submodule init' and "
"'git submodule update', and then re-run cmake.")
endif()
################################################################################
# Copy files and apply patches
################################################################################
# Copy needed files from the upstream repository
set(LIBAD936X_UPSTREAM_FILES
ad9361.c
ad9361.h
ad9361_api.c
ad9361_api.h
ad9361_conv.c
common.h
config.h
util.c
util.h
)
foreach(cpfile IN ITEMS ${LIBAD936X_UPSTREAM_FILES})
configure_file(
"${LIBAD936X_UPSTREAM_DIR}/${cpfile}"
"${LIBAD936X_UPSTREAM_BUILD_DIR}/"
COPYONLY
)
endforeach(cpfile)
# Patch the upstream files
set(LIBAD936X_PATCHES
0001-0bba46e-nuand-modifications.patch
0002-0bba46e-pr-561.patch
0003-0bba46e-pr-573.patch
0004-0bba46e-pr-598.patch
0005-0bba46e-rm-ad9361_parse_fir.patch
0006-0bba46e-compilefix.patch
)
find_package(Patcher REQUIRED)
foreach(patchfile IN ITEMS ${LIBAD936X_PATCHES})
message(STATUS "libad936x: Applying patch: ${patchfile}")
execute_process(
COMMAND ${Patcher_EXECUTABLE} -p3
INPUT_FILE ${LIBAD936X_PATCH_DIR}/${patchfile}
WORKING_DIRECTORY "${LIBAD936X_UPSTREAM_BUILD_DIR}"
OUTPUT_QUIET
RESULT_VARIABLE resultcode
ERROR_VARIABLE errvar
)
if(resultcode)
message(FATAL_ERROR "Failed to apply ${patchfile}: ${errvar}")
endif(resultcode)
endforeach(patchfile)
message(STATUS "libad936x: Build configured")

View file

@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.8.5)
project(libbladeRF C)
################################################################################
# Version information
################################################################################
@ -47,6 +48,7 @@ if (NOT EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_LIBDIR lib)
endif()
################################################################################
# Configuration options
################################################################################
@ -87,9 +89,11 @@ option(ENABLE_RFIC_TIMING_CALIBRATION
OFF
)
##############################
# Backend Support
##############################
option(ENABLE_BACKEND_USB
"Enable USB backends. Required when using the bladeRF with a host machine."
ON
@ -126,9 +130,11 @@ configure_file(
@ONLY
)
################################################################################
# Additional compiler options
################################################################################
if(ENABLE_LIBBLADERF_LOGGING)
add_definitions(-DLOGGING_ENABLED)
endif()
@ -167,10 +173,10 @@ else()
endif()
################################################################################
# Include paths
################################################################################
set(LIBBLADERF_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
@ -181,10 +187,10 @@ set(LIBBLADERF_INCLUDES
)
################################################################################
# Build dependencies
################################################################################
if(MSVC)
set(LIBBLADERF_INCLUDES ${LIBBLADERF_INCLUDES} ${MSVC_C99_INCLUDES})
@ -289,25 +295,22 @@ if(ENABLE_USB_DEV_RESET_ON_OPEN)
add_definitions(-DENABLE_USB_DEV_RESET_ON_OPEN=1)
endif()
if(BUILD_AD936X)
set(LIBBLADERF_LIBS ${LIBBLADERF_LIBS} ad936x)
endif(BUILD_AD936X)
include_directories(${LIBBLADERF_INCLUDES})
################################################################################
# Configure source files
################################################################################
set(LIBBLADERF_AD9361_SOURCE
src/driver/thirdparty/adi/ad9361.c
src/driver/thirdparty/adi/ad9361_api.c
src/driver/thirdparty/adi/ad9361_conv.c
src/driver/thirdparty/adi/adc_core.c
src/driver/thirdparty/adi/dac_core.c
src/driver/thirdparty/adi/util.c
src/driver/thirdparty/adi/platform.c
set(LIBBLADERF_SOURCE_BLADERF2
src/board/bladerf2/bladerf2.c
src/board/bladerf2/capabilities.c
src/board/bladerf2/compatibility.c
)
if(NOT MSVC)
set_source_files_properties(${LIBBLADERF_AD9361_SOURCE} PROPERTIES COMPILE_FLAGS "-std=gnu11")
endif(NOT MSVC)
set(LIBBLADERF_SOURCE
src/backend/backend.c
src/driver/spi_flash.c
@ -323,10 +326,6 @@ set(LIBBLADERF_SOURCE
src/board/bladerf1/calibration.c
src/board/bladerf1/flash.c
src/board/bladerf1/image.c
src/board/bladerf2/bladerf2.c
src/board/bladerf2/capabilities.c
src/board/bladerf2/compatibility.c
src/board/bladerf2/params.c
src/board/board.c
src/expansion/xb100.c
src/expansion/xb200.c
@ -350,9 +349,12 @@ set(LIBBLADERF_SOURCE
${BLADERF_FPGA_COMMON_SOURCE_DIR}/lms.c
${BLADERF_FPGA_COMMON_SOURCE_DIR}/band_select.c
${BLADERF_HOST_COMMON_SOURCE_DIR}/parse.c
${LIBBLADERF_AD9361_SOURCE}
)
if(BUILD_AD936X)
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} ${LIBBLADERF_SOURCE_BLADERF2})
endif()
if (MSVC)
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/bladerf.rc)
endif()
@ -373,7 +375,7 @@ if(ENABLE_BACKEND_USB)
endif()
if(LIBUSB_FOUND AND ENABLE_BACKEND_LIBUSB)
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} src/backend//usb/libusb.c)
set(LIBBLADERF_SOURCE ${LIBBLADERF_SOURCE} src/backend/usb/libusb.c)
endif()
if(ENABLE_BACKEND_CYAPI)
@ -419,6 +421,7 @@ endif()
add_library(libbladerf_shared SHARED ${LIBBLADERF_SOURCE})
################################################################################
# Build configuration
################################################################################
@ -448,9 +451,11 @@ set_target_properties(libbladerf_shared PROPERTIES SOVERSION ${VERSION_INFO_MAJO
include(Shortfile)
define_file_basename_for_sources(libbladerf_shared)
################################################################################
# Generate pkg-config file
################################################################################
add_subdirectory(include)
foreach(inc ${LIBBLADERF_INCLUDE_DIR})
list(APPEND LIBBLADERF_PC_CFLAGS "-I${inc}")
@ -495,9 +500,11 @@ install(
)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
################################################################################
# Library installation information
################################################################################
install(TARGETS libbladerf_shared
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so/.dylib
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # .a/.lib
@ -508,11 +515,14 @@ install(TARGETS libbladerf_shared
################################################################################
# Informational output
################################################################################
message(STATUS "libbladeRF version: ${VERSION_INFO}")
################################################################################
# Doxygen documentation
################################################################################
if(BUILD_LIBBLADERF_DOC_EXAMPLES)
add_subdirectory(doc/examples)
endif()

View file

@ -37,11 +37,11 @@
#include "capabilities.h"
#include "compatibility.h"
#include "driver/ad936x.h"
#include "driver/fpga_trigger.h"
#include "driver/fx3_fw.h"
#include "driver/ina219.h"
#include "driver/spi_flash.h"
#include "driver/thirdparty/adi/ad9361_api.h"
#include "backend/backend_config.h"
#include "backend/usb/usb.h"
@ -511,23 +511,23 @@ static const struct bladerf_range bladerf2_pll_refclk_range = {
/* RF Ports */
static const struct bladerf_ad9361_port_name_map bladerf2_rx_port_map[] = {
{ FIELD_INIT(.name, "A_BALANCED"), FIELD_INIT(.id, A_BALANCED), },
{ FIELD_INIT(.name, "B_BALANCED"), FIELD_INIT(.id, B_BALANCED), },
{ FIELD_INIT(.name, "C_BALANCED"), FIELD_INIT(.id, C_BALANCED), },
{ FIELD_INIT(.name, "A_N"), FIELD_INIT(.id, A_N), },
{ FIELD_INIT(.name, "A_P"), FIELD_INIT(.id, A_P), },
{ FIELD_INIT(.name, "B_N"), FIELD_INIT(.id, B_N), },
{ FIELD_INIT(.name, "B_P"), FIELD_INIT(.id, B_P), },
{ FIELD_INIT(.name, "C_N"), FIELD_INIT(.id, C_N), },
{ FIELD_INIT(.name, "C_P"), FIELD_INIT(.id, C_P), },
{ FIELD_INIT(.name, "TX_MON1"), FIELD_INIT(.id, TX_MON1), },
{ FIELD_INIT(.name, "TX_MON2"), FIELD_INIT(.id, TX_MON2), },
{ FIELD_INIT(.name, "TX_MON1_2"), FIELD_INIT(.id, TX_MON1_2), },
{ FIELD_INIT(.name, "A_BALANCED"), FIELD_INIT(.id, AD936X_A_BALANCED), },
{ FIELD_INIT(.name, "B_BALANCED"), FIELD_INIT(.id, AD936X_B_BALANCED), },
{ FIELD_INIT(.name, "C_BALANCED"), FIELD_INIT(.id, AD936X_C_BALANCED), },
{ FIELD_INIT(.name, "A_N"), FIELD_INIT(.id, AD936X_A_N), },
{ FIELD_INIT(.name, "A_P"), FIELD_INIT(.id, AD936X_A_P), },
{ FIELD_INIT(.name, "B_N"), FIELD_INIT(.id, AD936X_B_N), },
{ FIELD_INIT(.name, "B_P"), FIELD_INIT(.id, AD936X_B_P), },
{ FIELD_INIT(.name, "C_N"), FIELD_INIT(.id, AD936X_C_N), },
{ FIELD_INIT(.name, "C_P"), FIELD_INIT(.id, AD936X_C_P), },
{ FIELD_INIT(.name, "TX_MON1"), FIELD_INIT(.id, AD936X_TX_MON1), },
{ FIELD_INIT(.name, "TX_MON2"), FIELD_INIT(.id, AD936X_TX_MON2), },
{ FIELD_INIT(.name, "TX_MON1_2"), FIELD_INIT(.id, AD936X_TX_MON1_2), },
};
static const struct bladerf_ad9361_port_name_map bladerf2_tx_port_map[] = {
{ FIELD_INIT(.name, "TXA"), FIELD_INIT(.id, TXA), },
{ FIELD_INIT(.name, "TXB"), FIELD_INIT(.id, TXB), },
{ FIELD_INIT(.name, "TXA"), FIELD_INIT(.id, AD936X_TXA), },
{ FIELD_INIT(.name, "TXB"), FIELD_INIT(.id, AD936X_TXB), },
};
static const struct range_band_map bladerf2_rx_range_band_map[] = {
@ -581,12 +581,12 @@ static const struct band_port_map bladerf2_rx_band_port_map[] = {
{
FIELD_INIT(.band, BAND_LOW),
FIELD_INIT(.spdt, RFFE_CONTROL_SPDT_LOWBAND),
FIELD_INIT(.ad9361_port, B_BALANCED),
FIELD_INIT(.ad9361_port, AD936X_B_BALANCED),
},
{
FIELD_INIT(.band, BAND_HIGH),
FIELD_INIT(.spdt, RFFE_CONTROL_SPDT_HIGHBAND),
FIELD_INIT(.ad9361_port, A_BALANCED),
FIELD_INIT(.ad9361_port, AD936X_A_BALANCED),
},
};
@ -599,12 +599,12 @@ static const struct band_port_map bladerf2_tx_band_port_map[] = {
{
FIELD_INIT(.band, BAND_LOW),
FIELD_INIT(.spdt, RFFE_CONTROL_SPDT_LOWBAND),
FIELD_INIT(.ad9361_port, TXB),
FIELD_INIT(.ad9361_port, AD936X_TXB),
},
{
FIELD_INIT(.band, BAND_HIGH),
FIELD_INIT(.spdt, RFFE_CONTROL_SPDT_HIGHBAND),
FIELD_INIT(.ad9361_port, TXA),
FIELD_INIT(.ad9361_port, AD936X_TXA),
},
};
@ -647,13 +647,13 @@ static int bladerf2_get_sample_rate(struct bladerf *dev,
/* Externs */
/******************************************************************************/
extern AD9361_InitParam ad9361_init_params;
extern AD9361_RXFIRConfig ad9361_init_rx_fir_config;
extern AD9361_TXFIRConfig ad9361_init_tx_fir_config;
extern AD9361_RXFIRConfig ad9361_init_rx_fir_config_dec2;
extern AD9361_TXFIRConfig ad9361_init_tx_fir_config_int2;
extern AD9361_RXFIRConfig ad9361_init_rx_fir_config_dec4;
extern AD9361_TXFIRConfig ad9361_init_tx_fir_config_int4;
extern AD9361_InitParam bladerf2_rfic_init_params;
extern AD9361_RXFIRConfig bladerf2_rfic_rx_fir_config;
extern AD9361_TXFIRConfig bladerf2_rfic_tx_fir_config;
extern AD9361_RXFIRConfig bladerf2_rfic_rx_fir_config_dec2;
extern AD9361_TXFIRConfig bladerf2_rfic_tx_fir_config_int2;
extern AD9361_RXFIRConfig bladerf2_rfic_rx_fir_config_dec4;
extern AD9361_TXFIRConfig bladerf2_rfic_tx_fir_config_int4;
extern const float ina219_r_shunt;
@ -1182,7 +1182,7 @@ static int bladerf2_initialize(struct bladerf *dev)
/* Initialize AD9361 */
log_debug("%s: ad9361_init starting\n", __FUNCTION__);
status = ad9361_init(&board_data->phy, &ad9361_init_params, dev);
status = ad9361_init(&board_data->phy, &bladerf2_rfic_init_params, dev);
log_debug("%s: ad9361_init complete, status = %d\n", __FUNCTION__, status);
if (status < 0) {
RETURN_ERROR_AD9361("ad9361_init", status);
@ -1476,7 +1476,7 @@ static int bladerf2_open(struct bladerf *dev, struct bladerf_devinfo *devinfo)
/* Get FPGA size */
status = spi_flash_read_fpga_size(dev, &board_data->fpga_size);
if (status < 0) {
log_warning("Failed to get FPGA size: %s\n", bladerf_strerror(status));
log_warning("Failed to get FPGA size %s\n", bladerf_strerror(status));
}
if (getenv("BLADERF_FORCE_FPGA_A9")) {
@ -2219,12 +2219,12 @@ static int bladerf2_set_gain_mode(struct bladerf *dev,
switch (ch) {
case BLADERF_CHANNEL_RX(0):
ad9361_channel = 0;
gc_mode = ad9361_init_params.gc_rx1_mode;
gc_mode = bladerf2_rfic_init_params.gc_rx1_mode;
break;
case BLADERF_CHANNEL_RX(1):
ad9361_channel = 1;
gc_mode = ad9361_init_params.gc_rx2_mode;
gc_mode = bladerf2_rfic_init_params.gc_rx2_mode;
break;
default:
@ -3001,11 +3001,13 @@ static const struct {
FIELD_INIT(.shift, 0),
},
[BLADERF_CORR_PHASE] = {
FIELD_INIT(.reg, {REG_RX1_INPUT_A_PHASE_CORR, REG_RX1_INPUT_BC_PHASE_CORR}),
FIELD_INIT(.reg, { AD936X_REG_RX1_INPUT_A_PHASE_CORR,
AD936X_REG_RX1_INPUT_BC_PHASE_CORR }),
FIELD_INIT(.shift, 6),
},
[BLADERF_CORR_GAIN] = {
FIELD_INIT(.reg, {REG_RX1_INPUT_A_GAIN_CORR, REG_RX1_INPUT_BC_PHASE_CORR}),
FIELD_INIT(.reg, { AD936X_REG_RX1_INPUT_A_GAIN_CORR,
AD936X_REG_RX1_INPUT_BC_PHASE_CORR }),
FIELD_INIT(.shift, 6),
}
},
@ -3019,47 +3021,57 @@ static const struct {
FIELD_INIT(.shift, 0),
},
[BLADERF_CORR_PHASE] = {
FIELD_INIT(.reg, {REG_RX2_INPUT_A_PHASE_CORR, REG_RX2_INPUT_BC_PHASE_CORR}),
FIELD_INIT(.reg, { AD936X_REG_RX2_INPUT_A_PHASE_CORR,
AD936X_REG_RX2_INPUT_BC_PHASE_CORR }),
FIELD_INIT(.shift, 6),
},
[BLADERF_CORR_GAIN] = {
FIELD_INIT(.reg, {REG_RX2_INPUT_A_GAIN_CORR, REG_RX2_INPUT_BC_PHASE_CORR}),
FIELD_INIT(.reg, { AD936X_REG_RX2_INPUT_A_GAIN_CORR,
AD936X_REG_RX2_INPUT_BC_PHASE_CORR }),
FIELD_INIT(.shift, 6),
}
},
[BLADERF_CHANNEL_TX(0)].corr = {
[BLADERF_CORR_DCOFF_I] = {
FIELD_INIT(.reg, {REG_TX1_OUT_1_OFFSET_I, REG_TX1_OUT_2_OFFSET_I}),
FIELD_INIT(.reg, { AD936X_REG_TX1_OUT_1_OFFSET_I,
AD936X_REG_TX1_OUT_2_OFFSET_I }),
FIELD_INIT(.shift, 5),
},
[BLADERF_CORR_DCOFF_Q] = {
FIELD_INIT(.reg, {REG_TX1_OUT_1_OFFSET_Q, REG_TX1_OUT_2_OFFSET_Q}),
FIELD_INIT(.reg, { AD936X_REG_TX1_OUT_1_OFFSET_Q,
AD936X_REG_TX1_OUT_2_OFFSET_Q }),
FIELD_INIT(.shift, 5),
},
[BLADERF_CORR_PHASE] = {
FIELD_INIT(.reg, {REG_TX1_OUT_1_PHASE_CORR, REG_TX1_OUT_2_PHASE_CORR}),
FIELD_INIT(.reg, { AD936X_REG_TX1_OUT_1_PHASE_CORR,
AD936X_REG_TX1_OUT_2_PHASE_CORR }),
FIELD_INIT(.shift, 6),
},
[BLADERF_CORR_GAIN] = {
FIELD_INIT(.reg, {REG_TX1_OUT_1_GAIN_CORR, REG_TX1_OUT_2_GAIN_CORR}),
FIELD_INIT(.reg, { AD936X_REG_TX1_OUT_1_GAIN_CORR,
AD936X_REG_TX1_OUT_2_GAIN_CORR }),
FIELD_INIT(.shift, 6),
}
},
[BLADERF_CHANNEL_TX(1)].corr = {
[BLADERF_CORR_DCOFF_I] = {
FIELD_INIT(.reg, {REG_TX2_OUT_1_OFFSET_I, REG_TX2_OUT_2_OFFSET_I}),
FIELD_INIT(.reg, { AD936X_REG_TX2_OUT_1_OFFSET_I,
AD936X_REG_TX2_OUT_2_OFFSET_I }),
FIELD_INIT(.shift, 5),
},
[BLADERF_CORR_DCOFF_Q] = {
FIELD_INIT(.reg, {REG_TX2_OUT_1_OFFSET_Q, REG_TX2_OUT_2_OFFSET_Q}),
FIELD_INIT(.reg, { AD936X_REG_TX2_OUT_1_OFFSET_Q,
AD936X_REG_TX2_OUT_2_OFFSET_Q }),
FIELD_INIT(.shift, 5),
},
[BLADERF_CORR_PHASE] = {
FIELD_INIT(.reg, {REG_TX2_OUT_1_PHASE_CORR, REG_TX2_OUT_2_PHASE_CORR}),
FIELD_INIT(.reg, { AD936X_REG_TX2_OUT_1_PHASE_CORR,
AD936X_REG_TX2_OUT_2_PHASE_CORR }),
FIELD_INIT(.shift, 6),
},
[BLADERF_CORR_GAIN] = {
FIELD_INIT(.reg, {REG_TX2_OUT_1_GAIN_CORR, REG_TX2_OUT_2_GAIN_CORR}),
FIELD_INIT(.reg, { AD936X_REG_TX2_OUT_1_GAIN_CORR,
AD936X_REG_TX2_OUT_2_GAIN_CORR }),
FIELD_INIT(.shift, 6),
}
},
@ -3074,16 +3086,16 @@ static const struct {
/* A band */
{
/* I */
{REG_INPUT_A_OFFSETS_1, REG_RX1_INPUT_A_OFFSETS},
{AD936X_REG_INPUT_A_OFFSETS_1, AD936X_REG_RX1_INPUT_A_OFFSETS},
/* Q */
{REG_RX1_INPUT_A_OFFSETS, REG_RX1_INPUT_A_Q_OFFSET},
{AD936X_REG_RX1_INPUT_A_OFFSETS, AD936X_REG_RX1_INPUT_A_Q_OFFSET},
},
/* B/C band */
{
/* I */
{REG_INPUT_BC_OFFSETS_1, REG_RX1_INPUT_BC_OFFSETS},
{AD936X_REG_INPUT_BC_OFFSETS_1, AD936X_REG_RX1_INPUT_BC_OFFSETS},
/* Q */
{REG_RX1_INPUT_BC_OFFSETS, REG_RX1_INPUT_BC_Q_OFFSET},
{AD936X_REG_RX1_INPUT_BC_OFFSETS, AD936X_REG_RX1_INPUT_BC_Q_OFFSET},
},
},
/* Channel 2 */
@ -3091,16 +3103,16 @@ static const struct {
/* A band */
{
/* I */
{REG_RX2_INPUT_A_I_OFFSET, REG_RX2_INPUT_A_OFFSETS},
{AD936X_REG_RX2_INPUT_A_I_OFFSET, AD936X_REG_RX2_INPUT_A_OFFSETS},
/* Q */
{REG_RX2_INPUT_A_OFFSETS, REG_INPUT_A_OFFSETS_1},
{AD936X_REG_RX2_INPUT_A_OFFSETS, AD936X_REG_INPUT_A_OFFSETS_1},
},
/* B/C band */
{
/* I */
{REG_RX2_INPUT_BC_I_OFFSET, REG_RX2_INPUT_BC_OFFSETS},
{AD936X_REG_RX2_INPUT_BC_I_OFFSET, AD936X_REG_RX2_INPUT_BC_OFFSETS},
/* Q */
{REG_RX2_INPUT_BC_OFFSETS, REG_INPUT_BC_OFFSETS_1},
{AD936X_REG_RX2_INPUT_BC_OFFSETS, AD936X_REG_INPUT_BC_OFFSETS_1},
},
},
};
@ -3161,7 +3173,7 @@ static int bladerf2_get_correction(struct bladerf *dev,
RETURN_ERROR_AD9361("ad9361_get_tx_rf_port_output", status);
}
low_band = (mode == TXA);
low_band = (mode == AD936X_TXA);
} else {
uint32_t mode;
@ -3171,11 +3183,11 @@ static int bladerf2_get_correction(struct bladerf *dev,
}
/* Check if RX RF port mode is supported */
if (mode != A_BALANCED && mode != B_BALANCED && mode != C_BALANCED) {
if (mode != AD936X_A_BALANCED && mode != AD936X_B_BALANCED && mode != AD936X_C_BALANCED) {
RETURN_ERROR_STATUS("mode", BLADERF_ERR_UNSUPPORTED);
}
low_band = (mode == A_BALANCED);
low_band = (mode == AD936X_A_BALANCED);
}
if ((corr == BLADERF_CORR_DCOFF_I || corr == BLADERF_CORR_DCOFF_Q) &&
@ -3294,7 +3306,7 @@ static int bladerf2_set_correction(struct bladerf *dev,
RETURN_ERROR_AD9361("ad9361_get_tx_rf_port_output", status);
}
low_band = (mode == TXA);
low_band = (mode == AD936X_TXA);
} else {
uint32_t mode;
@ -3304,11 +3316,11 @@ static int bladerf2_set_correction(struct bladerf *dev,
}
/* Check if RX RF port mode is supported */
if (mode != A_BALANCED && mode != B_BALANCED && mode != C_BALANCED) {
if (mode != AD936X_A_BALANCED && mode != AD936X_B_BALANCED && mode != AD936X_C_BALANCED) {
RETURN_ERROR_STATUS("mode", BLADERF_ERR_UNSUPPORTED);
}
low_band = (mode == A_BALANCED);
low_band = (mode == AD936X_A_BALANCED);
}
if ((corr == BLADERF_CORR_DCOFF_I || corr == BLADERF_CORR_DCOFF_Q) &&
@ -3400,7 +3412,8 @@ static int bladerf2_set_correction(struct bladerf *dev,
}
}
reg = (BLADERF_CHANNEL_IS_TX(ch)) ? REG_TX_FORCE_BITS : REG_FORCE_BITS;
reg = (BLADERF_CHANNEL_IS_TX(ch)) ? AD936X_REG_TX_FORCE_BITS
: AD936X_REG_FORCE_BITS;
/* Read force bit register */
status = ad9361_spi_read(board_data->phy->spi, reg);
@ -4686,7 +4699,7 @@ int bladerf_get_rfic_register(struct bladerf *dev,
CHECK_BOARD_STATE_LOCKED(STATE_FPGA_LOADED);
address = AD_READ | AD_CNT(1) | address;
address = AD936X_READ | AD936X_CNT(1) | address;
status = dev->backend->ad9361_spi_read(dev, address, &data);
if (status < 0) {
@ -4720,7 +4733,7 @@ int bladerf_set_rfic_register(struct bladerf *dev,
CHECK_BOARD_STATE_LOCKED(STATE_FPGA_LOADED);
address = AD_WRITE | AD_CNT(1) | address;
address = AD936X_WRITE | AD936X_CNT(1) | address;
data = (((uint64_t)val) << 56);
@ -4899,19 +4912,19 @@ int bladerf_set_rfic_rx_fir(struct bladerf *dev, bladerf_rfic_rxfir rxfir)
switch (rxfir) {
case BLADERF_RFIC_RXFIR_BYPASS:
fir_config = &ad9361_init_rx_fir_config;
fir_config = &bladerf2_rfic_rx_fir_config;
enable = 0;
break;
case BLADERF_RFIC_RXFIR_DEC1:
fir_config = &ad9361_init_rx_fir_config;
fir_config = &bladerf2_rfic_rx_fir_config;
enable = 1;
break;
case BLADERF_RFIC_RXFIR_DEC2:
fir_config = &ad9361_init_rx_fir_config_dec2;
fir_config = &bladerf2_rfic_rx_fir_config_dec2;
enable = 1;
break;
case BLADERF_RFIC_RXFIR_DEC4:
fir_config = &ad9361_init_rx_fir_config_dec4;
fir_config = &bladerf2_rfic_rx_fir_config_dec4;
enable = 1;
break;
default:
@ -4983,19 +4996,19 @@ int bladerf_set_rfic_tx_fir(struct bladerf *dev, bladerf_rfic_txfir txfir)
switch (txfir) {
case BLADERF_RFIC_TXFIR_BYPASS:
fir_config = &ad9361_init_tx_fir_config;
fir_config = &bladerf2_rfic_tx_fir_config;
enable = 0;
break;
case BLADERF_RFIC_TXFIR_INT1:
fir_config = &ad9361_init_tx_fir_config;
fir_config = &bladerf2_rfic_tx_fir_config;
enable = 1;
break;
case BLADERF_RFIC_TXFIR_INT2:
fir_config = &ad9361_init_tx_fir_config_int2;
fir_config = &bladerf2_rfic_tx_fir_config_int2;
enable = 1;
break;
case BLADERF_RFIC_TXFIR_INT4:
fir_config = &ad9361_init_tx_fir_config_int4;
fir_config = &bladerf2_rfic_tx_fir_config_int4;
enable = 1;
break;
default:

View file

@ -0,0 +1,856 @@
/**
* @file ad936x.h
*
* @brief Interface to the library for the AD936X RFIC family
*
* Copyright (c) 2018 Nuand LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef AD936X_H_
#define AD936X_H_
/**
* The purpose of this header file is to allow the use of libad9361 without
* including all of the unnecessary defines, etc, used during compilation.
*
* This file is largely copied from the files named in each section. Only
* necessary declarations are present.
*
* In general, defines are prefixed with AD936X_ to avoid conflicts.
*
* Comments have been removed for brevity. Please see the original header
* files from the third-party ADI library for further details.
*/
/******************************************************************************
* From common.h
******************************************************************************/
struct clk_onecell_data {
struct clk **clks;
uint32_t clk_num;
};
/******************************************************************************
* From ad9361.h
******************************************************************************/
#define AD936X_REG_TX1_OUT_1_PHASE_CORR 0x08E
#define AD936X_REG_TX1_OUT_1_GAIN_CORR 0x08F
#define AD936X_REG_TX2_OUT_1_PHASE_CORR 0x090
#define AD936X_REG_TX2_OUT_1_GAIN_CORR 0x091
#define AD936X_REG_TX1_OUT_1_OFFSET_I 0x092
#define AD936X_REG_TX1_OUT_1_OFFSET_Q 0x093
#define AD936X_REG_TX2_OUT_1_OFFSET_I 0x094
#define AD936X_REG_TX2_OUT_1_OFFSET_Q 0x095
#define AD936X_REG_TX1_OUT_2_PHASE_CORR 0x096
#define AD936X_REG_TX1_OUT_2_GAIN_CORR 0x097
#define AD936X_REG_TX2_OUT_2_PHASE_CORR 0x098
#define AD936X_REG_TX2_OUT_2_GAIN_CORR 0x099
#define AD936X_REG_TX1_OUT_2_OFFSET_I 0x09A
#define AD936X_REG_TX1_OUT_2_OFFSET_Q 0x09B
#define AD936X_REG_TX2_OUT_2_OFFSET_I 0x09C
#define AD936X_REG_TX2_OUT_2_OFFSET_Q 0x09D
#define AD936X_REG_TX_FORCE_BITS 0x09F
#define AD936X_REG_RX1_INPUT_A_PHASE_CORR 0x170
#define AD936X_REG_RX1_INPUT_A_GAIN_CORR 0x171
#define AD936X_REG_RX2_INPUT_A_PHASE_CORR 0x172
#define AD936X_REG_RX2_INPUT_A_GAIN_CORR 0x173
#define AD936X_REG_RX1_INPUT_A_Q_OFFSET 0x174
#define AD936X_REG_RX1_INPUT_A_OFFSETS 0x175
#define AD936X_REG_INPUT_A_OFFSETS_1 0x176
#define AD936X_REG_RX2_INPUT_A_OFFSETS 0x177
#define AD936X_REG_RX2_INPUT_A_I_OFFSET 0x178
#define AD936X_REG_RX1_INPUT_BC_PHASE_CORR 0x179
#define AD936X_REG_RX1_INPUT_BC_GAIN_CORR 0x17A
#define AD936X_REG_RX2_INPUT_BC_PHASE_CORR 0x17B
#define AD936X_REG_RX2_INPUT_BC_GAIN_CORR 0x17C
#define AD936X_REG_RX1_INPUT_BC_Q_OFFSET 0x17D
#define AD936X_REG_RX1_INPUT_BC_OFFSETS 0x17E
#define AD936X_REG_INPUT_BC_OFFSETS_1 0x17F
#define AD936X_REG_RX2_INPUT_BC_OFFSETS 0x180
#define AD936X_REG_RX2_INPUT_BC_I_OFFSET 0x181
#define AD936X_REG_FORCE_BITS 0x182
#define AD936X_READ (0 << 15)
#define AD936X_WRITE (1 << 15)
#define AD936X_CNT(x) ((((x)-1) & 0x7) << 12)
#define AD936X_ADDR(x) ((x)&0x3FF)
enum dev_id { ID_AD9361, ID_AD9364, ID_AD9363A };
enum ad9361_clocks {
BB_REFCLK,
RX_REFCLK,
TX_REFCLK,
BBPLL_CLK,
ADC_CLK,
R2_CLK,
R1_CLK,
CLKRF_CLK,
RX_SAMPL_CLK,
DAC_CLK,
T2_CLK,
T1_CLK,
CLKTF_CLK,
TX_SAMPL_CLK,
RX_RFPLL_INT,
TX_RFPLL_INT,
RX_RFPLL_DUMMY,
TX_RFPLL_DUMMY,
RX_RFPLL,
TX_RFPLL,
NUM_AD9361_CLKS,
EXT_REF_CLK,
};
enum rx_gain_table_name {
TBL_200_1300_MHZ,
TBL_1300_4000_MHZ,
TBL_4000_6000_MHZ,
RXGAIN_TBLS_END,
};
enum rx_gain_table_type {
RXGAIN_FULL_TBL,
RXGAIN_SPLIT_TBL,
};
struct rx_gain_info {
enum rx_gain_table_type tbl_type;
int32_t starting_gain_db;
int32_t max_gain_db;
int32_t gain_step_db;
int32_t max_idx;
int32_t idx_step_offset;
};
enum ad9361_pdata_rx_freq {
BBPLL_FREQ,
ADC_FREQ,
R2_FREQ,
R1_FREQ,
CLKRF_FREQ,
RX_SAMPL_FREQ,
NUM_RX_CLOCKS,
};
enum ad9361_pdata_tx_freq {
IGNORE_FREQ,
DAC_FREQ,
T2_FREQ,
T1_FREQ,
CLKTF_FREQ,
TX_SAMPL_FREQ,
NUM_TX_CLOCKS,
};
struct ad9361_fastlock_entry {
//#define FASTLOOK_INIT 1
uint8_t flags;
uint8_t alc_orig;
uint8_t alc_written;
};
struct ad9361_fastlock {
uint8_t save_profile;
uint8_t current_profile[2];
struct ad9361_fastlock_entry entry[2][8];
};
enum ad9361_bist_mode {
BIST_DISABLE,
BIST_INJ_TX,
BIST_INJ_RX,
};
enum ad9361_clkout {
CLKOUT_DISABLE,
BUFFERED_XTALN_DCXO,
ADC_CLK_DIV_2,
ADC_CLK_DIV_3,
ADC_CLK_DIV_4,
ADC_CLK_DIV_8,
ADC_CLK_DIV_16,
};
enum rf_gain_ctrl_mode {
RF_GAIN_MGC,
RF_GAIN_FASTATTACK_AGC,
RF_GAIN_SLOWATTACK_AGC,
RF_GAIN_HYBRID_AGC
};
enum f_agc_target_gain_index_type {
MAX_GAIN,
SET_GAIN,
OPTIMIZED_GAIN,
NO_GAIN_CHANGE,
};
enum rssi_restart_mode {
AGC_IN_FAST_ATTACK_MODE_LOCKS_THE_GAIN,
EN_AGC_PIN_IS_PULLED_HIGH,
ENTERS_RX_MODE,
GAIN_CHANGE_OCCURS,
SPI_WRITE_TO_REGISTER,
GAIN_CHANGE_OCCURS_OR_EN_AGC_PIN_PULLED_HIGH,
};
struct rssi_control {
enum rssi_restart_mode restart_mode;
bool rssi_unit_is_rx_samples;
uint32_t rssi_delay;
uint32_t rssi_wait;
uint32_t rssi_duration;
};
struct port_control {
uint8_t pp_conf[3];
uint8_t rx_clk_data_delay;
uint8_t tx_clk_data_delay;
uint8_t digital_io_ctrl;
uint8_t lvds_bias_ctrl;
uint8_t lvds_invert[2];
uint8_t clk_out_drive;
uint8_t dataclk_drive;
uint8_t data_port_drive;
uint8_t clk_out_slew;
uint8_t dataclk_slew;
uint8_t data_port_slew;
};
struct ctrl_outs_control {
uint8_t index;
uint8_t en_mask;
};
struct elna_control {
uint16_t gain_mdB;
uint16_t bypass_loss_mdB;
uint32_t settling_delay_ns;
bool elna_1_control_en;
bool elna_2_control_en;
bool elna_in_gaintable_all_index_en;
};
struct auxadc_control {
int8_t offset;
uint32_t temp_time_inteval_ms;
uint32_t temp_sensor_decimation;
bool periodic_temp_measuremnt;
uint32_t auxadc_clock_rate;
uint32_t auxadc_decimation;
};
struct auxdac_control {
uint16_t dac1_default_value;
uint16_t dac2_default_value;
bool auxdac_manual_mode_en;
bool dac1_in_rx_en;
bool dac1_in_tx_en;
bool dac1_in_alert_en;
bool dac2_in_rx_en;
bool dac2_in_tx_en;
bool dac2_in_alert_en;
uint8_t dac1_rx_delay_us;
uint8_t dac1_tx_delay_us;
uint8_t dac2_rx_delay_us;
uint8_t dac2_tx_delay_us;
};
struct gpo_control {
bool gpo0_inactive_state_high_en;
bool gpo1_inactive_state_high_en;
bool gpo2_inactive_state_high_en;
bool gpo3_inactive_state_high_en;
bool gpo0_slave_rx_en;
bool gpo0_slave_tx_en;
bool gpo1_slave_rx_en;
bool gpo1_slave_tx_en;
bool gpo2_slave_rx_en;
bool gpo2_slave_tx_en;
bool gpo3_slave_rx_en;
bool gpo3_slave_tx_en;
uint8_t gpo0_rx_delay_us;
uint8_t gpo0_tx_delay_us;
uint8_t gpo1_rx_delay_us;
uint8_t gpo1_tx_delay_us;
uint8_t gpo2_rx_delay_us;
uint8_t gpo2_tx_delay_us;
uint8_t gpo3_rx_delay_us;
uint8_t gpo3_tx_delay_us;
};
struct tx_monitor_control {
bool tx_mon_track_en;
bool one_shot_mode_en;
uint32_t low_high_gain_threshold_mdB;
uint8_t low_gain_dB;
uint8_t high_gain_dB;
uint16_t tx_mon_delay;
uint16_t tx_mon_duration;
uint8_t tx1_mon_front_end_gain;
uint8_t tx2_mon_front_end_gain;
uint8_t tx1_mon_lo_cm;
uint8_t tx2_mon_lo_cm;
};
struct gain_control {
enum rf_gain_ctrl_mode rx1_mode;
enum rf_gain_ctrl_mode rx2_mode;
uint8_t adc_ovr_sample_size;
uint8_t adc_small_overload_thresh;
uint8_t adc_large_overload_thresh;
uint16_t lmt_overload_high_thresh;
uint16_t lmt_overload_low_thresh;
uint16_t dec_pow_measuremnt_duration;
uint8_t low_power_thresh;
bool dig_gain_en;
uint8_t max_dig_gain;
bool mgc_rx1_ctrl_inp_en;
bool mgc_rx2_ctrl_inp_en;
uint8_t mgc_inc_gain_step;
uint8_t mgc_dec_gain_step;
uint8_t mgc_split_table_ctrl_inp_gain_mode;
uint8_t agc_attack_delay_extra_margin_us;
uint8_t agc_outer_thresh_high;
uint8_t agc_outer_thresh_high_dec_steps;
uint8_t agc_inner_thresh_high;
uint8_t agc_inner_thresh_high_dec_steps;
uint8_t agc_inner_thresh_low;
uint8_t agc_inner_thresh_low_inc_steps;
uint8_t agc_outer_thresh_low;
uint8_t agc_outer_thresh_low_inc_steps;
uint8_t adc_small_overload_exceed_counter;
uint8_t adc_large_overload_exceed_counter;
uint8_t adc_large_overload_inc_steps;
bool adc_lmt_small_overload_prevent_gain_inc;
uint8_t lmt_overload_large_exceed_counter;
uint8_t lmt_overload_small_exceed_counter;
uint8_t lmt_overload_large_inc_steps;
uint8_t dig_saturation_exceed_counter;
uint8_t dig_gain_step_size;
bool sync_for_gain_counter_en;
uint32_t gain_update_interval_us;
bool immed_gain_change_if_large_adc_overload;
bool immed_gain_change_if_large_lmt_overload;
uint32_t f_agc_dec_pow_measuremnt_duration;
uint32_t f_agc_state_wait_time_ns;
bool f_agc_allow_agc_gain_increase;
uint8_t f_agc_lp_thresh_increment_time;
uint8_t f_agc_lp_thresh_increment_steps;
uint8_t f_agc_lock_level;
bool f_agc_lock_level_lmt_gain_increase_en;
uint8_t f_agc_lock_level_gain_increase_upper_limit;
uint8_t f_agc_lpf_final_settling_steps;
uint8_t f_agc_lmt_final_settling_steps;
uint8_t f_agc_final_overrange_count;
bool f_agc_gain_increase_after_gain_lock_en;
enum f_agc_target_gain_index_type f_agc_gain_index_type_after_exit_rx_mode;
bool f_agc_use_last_lock_level_for_set_gain_en;
uint8_t f_agc_optimized_gain_offset;
bool f_agc_rst_gla_stronger_sig_thresh_exceeded_en;
uint8_t f_agc_rst_gla_stronger_sig_thresh_above_ll;
bool f_agc_rst_gla_engergy_lost_sig_thresh_exceeded_en;
bool f_agc_rst_gla_engergy_lost_goto_optim_gain_en;
uint8_t f_agc_rst_gla_engergy_lost_sig_thresh_below_ll;
uint8_t f_agc_energy_lost_stronger_sig_gain_lock_exit_cnt;
bool f_agc_rst_gla_large_adc_overload_en;
bool f_agc_rst_gla_large_lmt_overload_en;
bool f_agc_rst_gla_en_agc_pulled_high_en;
enum f_agc_target_gain_index_type f_agc_rst_gla_if_en_agc_pulled_high_mode;
uint8_t f_agc_power_measurement_duration_in_state5;
};
struct ad9361_phy_platform_data {
bool rx2tx2;
bool fdd;
bool fdd_independent_mode;
bool split_gt;
bool use_extclk;
bool ensm_pin_pulse_mode;
bool ensm_pin_ctrl;
bool debug_mode;
bool tdd_use_dual_synth;
bool tdd_skip_vco_cal;
bool use_ext_rx_lo;
bool use_ext_tx_lo;
bool rx1rx2_phase_inversion_en;
bool qec_tracking_slow_mode_en;
uint8_t dc_offset_update_events;
uint8_t dc_offset_attenuation_high;
uint8_t dc_offset_attenuation_low;
uint8_t rf_dc_offset_count_high;
uint8_t rf_dc_offset_count_low;
uint8_t dig_interface_tune_skipmode;
uint8_t dig_interface_tune_fir_disable;
uint8_t lo_powerdown_managed_en;
uint32_t dcxo_coarse;
uint32_t dcxo_fine;
uint32_t rf_rx_input_sel;
uint32_t rf_tx_output_sel;
uint32_t rx1tx1_mode_use_rx_num;
uint32_t rx1tx1_mode_use_tx_num;
uint32_t rx_path_clks[NUM_RX_CLOCKS];
uint32_t tx_path_clks[NUM_TX_CLOCKS];
uint32_t trx_synth_max_fref;
uint64_t rx_synth_freq;
uint64_t tx_synth_freq;
uint32_t rf_rx_bandwidth_Hz;
uint32_t rf_tx_bandwidth_Hz;
int32_t tx_atten;
bool update_tx_gain_via_alert;
uint32_t rx_fastlock_delay_ns;
uint32_t tx_fastlock_delay_ns;
bool trx_fastlock_pinctrl_en[2];
enum ad9361_clkout ad9361_clkout_mode;
struct gain_control gain_ctrl;
struct rssi_control rssi_ctrl;
struct port_control port_ctrl;
struct ctrl_outs_control ctrl_outs_ctrl;
struct elna_control elna_ctrl;
struct auxadc_control auxadc_ctrl;
struct auxdac_control auxdac_ctrl;
struct gpo_control gpo_ctrl;
struct tx_monitor_control txmon_ctrl;
int32_t gpio_resetb;
int32_t gpio_sync;
int32_t gpio_cal_sw1;
int32_t gpio_cal_sw2;
};
struct ad9361_rf_phy {
enum dev_id dev_sel;
uint8_t id_no;
struct spi_device *spi;
struct gpio_device *gpio;
struct clk *clk_refin;
struct clk *clks[NUM_AD9361_CLKS];
struct refclk_scale *ref_clk_scale[NUM_AD9361_CLKS];
struct clk_onecell_data clk_data;
uint32_t (*ad9361_rfpll_ext_recalc_rate)(struct refclk_scale *clk_priv);
int32_t (*ad9361_rfpll_ext_round_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
int32_t (*ad9361_rfpll_ext_set_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
struct ad9361_phy_platform_data *pdata;
uint8_t prev_ensm_state;
uint8_t curr_ensm_state;
uint8_t cached_rx_rfpll_div;
uint8_t cached_tx_rfpll_div;
uint8_t cached_synth_pd[2];
struct rx_gain_info rx_gain[RXGAIN_TBLS_END];
enum rx_gain_table_name current_table;
bool ensm_pin_ctl_en;
bool auto_cal_en;
uint64_t last_tx_quad_cal_freq;
uint32_t last_tx_quad_cal_phase;
uint64_t current_tx_lo_freq;
uint64_t current_rx_lo_freq;
bool current_tx_use_tdd_table;
bool current_rx_use_tdd_table;
uint32_t flags;
uint32_t cal_threshold_freq;
uint32_t current_rx_bw_Hz;
uint32_t current_tx_bw_Hz;
uint32_t rxbbf_div;
uint32_t rate_governor;
bool bypass_rx_fir;
bool bypass_tx_fir;
bool rx_eq_2tx;
bool filt_valid;
uint32_t filt_rx_path_clks[NUM_RX_CLOCKS];
uint32_t filt_tx_path_clks[NUM_TX_CLOCKS];
uint32_t filt_rx_bw_Hz;
uint32_t filt_tx_bw_Hz;
uint8_t tx_fir_int;
uint8_t tx_fir_ntaps;
uint8_t rx_fir_dec;
uint8_t rx_fir_ntaps;
uint8_t agc_mode[2];
bool rfdc_track_en;
bool bbdc_track_en;
bool quad_track_en;
bool txmon_tdd_en;
uint16_t auxdac1_value;
uint16_t auxdac2_value;
uint32_t tx1_atten_cached;
uint32_t tx2_atten_cached;
struct ad9361_fastlock fastlock;
struct axiadc_converter *adc_conv;
struct axiadc_state *adc_state;
int32_t bist_loopback_mode;
int32_t bist_config;
enum ad9361_bist_mode bist_prbs_mode;
enum ad9361_bist_mode bist_tone_mode;
uint32_t bist_tone_freq_Hz;
uint32_t bist_tone_level_dB;
uint32_t bist_tone_mask;
bool bbpll_initialized;
};
struct rf_rx_gain {
uint32_t ant;
int32_t gain_db;
uint32_t fgt_lmt_index;
uint32_t lmt_gain;
uint32_t lpf_gain;
uint32_t digital_gain;
uint32_t lna_index;
uint32_t tia_index;
uint32_t mixer_index;
};
struct rf_rssi {
uint32_t ant;
uint32_t symbol;
uint32_t preamble;
int32_t multiplier;
uint8_t duration;
};
int32_t ad9361_set_tx_atten(struct ad9361_rf_phy *phy,
uint32_t atten_mdb,
bool tx1,
bool tx2,
bool immed);
int32_t ad9361_get_tx_atten(struct ad9361_rf_phy *phy, uint32_t tx_num);
int32_t ad9361_get_rx_gain(struct ad9361_rf_phy *phy,
uint32_t rx_id,
struct rf_rx_gain *rx_gain);
int32_t ad9361_spi_read(struct spi_device *spi, uint32_t reg);
int32_t ad9361_spi_write(struct spi_device *spi, uint32_t reg, uint32_t val);
void ad9361_get_bist_loopback(struct ad9361_rf_phy *phy, int32_t *mode);
int32_t ad9361_bist_loopback(struct ad9361_rf_phy *phy, int32_t mode);
/******************************************************************************
* From ad9361_api.h
******************************************************************************/
typedef struct {
enum dev_id dev_sel;
uint8_t id_no;
uint32_t reference_clk_rate;
uint8_t two_rx_two_tx_mode_enable;
uint8_t one_rx_one_tx_mode_use_rx_num;
uint8_t one_rx_one_tx_mode_use_tx_num;
uint8_t frequency_division_duplex_mode_enable;
uint8_t frequency_division_duplex_independent_mode_enable;
uint8_t tdd_use_dual_synth_mode_enable;
uint8_t tdd_skip_vco_cal_enable;
uint32_t tx_fastlock_delay_ns;
uint32_t rx_fastlock_delay_ns;
uint8_t rx_fastlock_pincontrol_enable;
uint8_t tx_fastlock_pincontrol_enable;
uint8_t external_rx_lo_enable;
uint8_t external_tx_lo_enable;
uint8_t dc_offset_tracking_update_event_mask;
uint8_t dc_offset_attenuation_high_range;
uint8_t dc_offset_attenuation_low_range;
uint8_t dc_offset_count_high_range;
uint8_t dc_offset_count_low_range;
uint8_t split_gain_table_mode_enable;
uint32_t trx_synthesizer_target_fref_overwrite_hz;
uint8_t qec_tracking_slow_mode_enable;
uint8_t ensm_enable_pin_pulse_mode_enable;
uint8_t ensm_enable_txnrx_control_enable;
uint8_t tx_lo_powerdown_managed_enable;
uint64_t rx_synthesizer_frequency_hz;
uint64_t tx_synthesizer_frequency_hz;
uint32_t rx_path_clock_frequencies[6];
uint32_t tx_path_clock_frequencies[6];
uint32_t rf_rx_bandwidth_hz;
uint32_t rf_tx_bandwidth_hz;
uint32_t rx_rf_port_input_select;
uint32_t tx_rf_port_input_select;
int32_t tx_attenuation_mdB;
uint8_t update_tx_gain_in_alert_enable;
uint8_t xo_disable_use_ext_refclk_enable;
uint32_t dcxo_coarse_and_fine_tune[2];
uint32_t clk_output_mode_select;
uint8_t gc_rx1_mode;
uint8_t gc_rx2_mode;
uint8_t gc_adc_large_overload_thresh;
uint8_t gc_adc_ovr_sample_size;
uint8_t gc_adc_small_overload_thresh;
uint16_t gc_dec_pow_measurement_duration;
uint8_t gc_dig_gain_enable;
uint16_t gc_lmt_overload_high_thresh;
uint16_t gc_lmt_overload_low_thresh;
uint8_t gc_low_power_thresh;
uint8_t gc_max_dig_gain;
uint8_t mgc_dec_gain_step;
uint8_t mgc_inc_gain_step;
uint8_t mgc_rx1_ctrl_inp_enable;
uint8_t mgc_rx2_ctrl_inp_enable;
uint8_t mgc_split_table_ctrl_inp_gain_mode;
uint8_t agc_adc_large_overload_exceed_counter;
uint8_t agc_adc_large_overload_inc_steps;
uint8_t agc_adc_lmt_small_overload_prevent_gain_inc_enable;
uint8_t agc_adc_small_overload_exceed_counter;
uint8_t agc_dig_gain_step_size;
uint8_t agc_dig_saturation_exceed_counter;
uint32_t agc_gain_update_interval_us;
uint8_t agc_immed_gain_change_if_large_adc_overload_enable;
uint8_t agc_immed_gain_change_if_large_lmt_overload_enable;
uint8_t agc_inner_thresh_high;
uint8_t agc_inner_thresh_high_dec_steps;
uint8_t agc_inner_thresh_low;
uint8_t agc_inner_thresh_low_inc_steps;
uint8_t agc_lmt_overload_large_exceed_counter;
uint8_t agc_lmt_overload_large_inc_steps;
uint8_t agc_lmt_overload_small_exceed_counter;
uint8_t agc_outer_thresh_high;
uint8_t agc_outer_thresh_high_dec_steps;
uint8_t agc_outer_thresh_low;
uint8_t agc_outer_thresh_low_inc_steps;
uint32_t agc_attack_delay_extra_margin_us;
uint8_t agc_sync_for_gain_counter_enable;
uint32_t fagc_dec_pow_measuremnt_duration;
uint32_t fagc_state_wait_time_ns;
uint8_t fagc_allow_agc_gain_increase;
uint32_t fagc_lp_thresh_increment_time;
uint32_t fagc_lp_thresh_increment_steps;
uint8_t fagc_lock_level_lmt_gain_increase_en;
uint32_t fagc_lock_level_gain_increase_upper_limit;
uint32_t fagc_lpf_final_settling_steps;
uint32_t fagc_lmt_final_settling_steps;
uint32_t fagc_final_overrange_count;
uint8_t fagc_gain_increase_after_gain_lock_en;
uint32_t fagc_gain_index_type_after_exit_rx_mode;
uint8_t fagc_use_last_lock_level_for_set_gain_en;
uint8_t fagc_rst_gla_stronger_sig_thresh_exceeded_en;
uint32_t fagc_optimized_gain_offset;
uint32_t fagc_rst_gla_stronger_sig_thresh_above_ll;
uint8_t fagc_rst_gla_engergy_lost_sig_thresh_exceeded_en;
uint8_t fagc_rst_gla_engergy_lost_goto_optim_gain_en;
uint32_t fagc_rst_gla_engergy_lost_sig_thresh_below_ll;
uint32_t fagc_energy_lost_stronger_sig_gain_lock_exit_cnt;
uint8_t fagc_rst_gla_large_adc_overload_en;
uint8_t fagc_rst_gla_large_lmt_overload_en;
uint8_t fagc_rst_gla_en_agc_pulled_high_en;
uint32_t fagc_rst_gla_if_en_agc_pulled_high_mode;
uint32_t fagc_power_measurement_duration_in_state5;
uint32_t rssi_delay;
uint32_t rssi_duration;
uint8_t rssi_restart_mode;
uint8_t rssi_unit_is_rx_samples_enable;
uint32_t rssi_wait;
uint32_t aux_adc_decimation;
uint32_t aux_adc_rate;
uint8_t aux_dac_manual_mode_enable;
uint32_t aux_dac1_default_value_mV;
uint8_t aux_dac1_active_in_rx_enable;
uint8_t aux_dac1_active_in_tx_enable;
uint8_t aux_dac1_active_in_alert_enable;
uint32_t aux_dac1_rx_delay_us;
uint32_t aux_dac1_tx_delay_us;
uint32_t aux_dac2_default_value_mV;
uint8_t aux_dac2_active_in_rx_enable;
uint8_t aux_dac2_active_in_tx_enable;
uint8_t aux_dac2_active_in_alert_enable;
uint32_t aux_dac2_rx_delay_us;
uint32_t aux_dac2_tx_delay_us;
uint32_t temp_sense_decimation;
uint16_t temp_sense_measurement_interval_ms;
int8_t temp_sense_offset_signed;
uint8_t temp_sense_periodic_measurement_enable;
uint8_t ctrl_outs_enable_mask;
uint8_t ctrl_outs_index;
uint32_t elna_settling_delay_ns;
uint32_t elna_gain_mdB;
uint32_t elna_bypass_loss_mdB;
uint8_t elna_rx1_gpo0_control_enable;
uint8_t elna_rx2_gpo1_control_enable;
uint8_t elna_gaintable_all_index_enable;
uint8_t digital_interface_tune_skip_mode;
uint8_t digital_interface_tune_fir_disable;
uint8_t pp_tx_swap_enable;
uint8_t pp_rx_swap_enable;
uint8_t tx_channel_swap_enable;
uint8_t rx_channel_swap_enable;
uint8_t rx_frame_pulse_mode_enable;
uint8_t two_t_two_r_timing_enable;
uint8_t invert_data_bus_enable;
uint8_t invert_data_clk_enable;
uint8_t fdd_alt_word_order_enable;
uint8_t invert_rx_frame_enable;
uint8_t fdd_rx_rate_2tx_enable;
uint8_t swap_ports_enable;
uint8_t single_data_rate_enable;
uint8_t lvds_mode_enable;
uint8_t half_duplex_mode_enable;
uint8_t single_port_mode_enable;
uint8_t full_port_enable;
uint8_t full_duplex_swap_bits_enable;
uint32_t delay_rx_data;
uint32_t rx_data_clock_delay;
uint32_t rx_data_delay;
uint32_t tx_fb_clock_delay;
uint32_t tx_data_delay;
uint32_t lvds_bias_mV;
uint8_t lvds_rx_onchip_termination_enable;
uint8_t rx1rx2_phase_inversion_en;
uint8_t lvds_invert1_control;
uint8_t lvds_invert2_control;
uint8_t clk_out_drive;
uint8_t dataclk_drive;
uint8_t data_port_drive;
uint8_t clk_out_slew;
uint8_t dataclk_slew;
uint8_t data_port_slew;
uint8_t gpo0_inactive_state_high_enable;
uint8_t gpo1_inactive_state_high_enable;
uint8_t gpo2_inactive_state_high_enable;
uint8_t gpo3_inactive_state_high_enable;
uint8_t gpo0_slave_rx_enable;
uint8_t gpo0_slave_tx_enable;
uint8_t gpo1_slave_rx_enable;
uint8_t gpo1_slave_tx_enable;
uint8_t gpo2_slave_rx_enable;
uint8_t gpo2_slave_tx_enable;
uint8_t gpo3_slave_rx_enable;
uint8_t gpo3_slave_tx_enable;
uint8_t gpo0_rx_delay_us;
uint8_t gpo0_tx_delay_us;
uint8_t gpo1_rx_delay_us;
uint8_t gpo1_tx_delay_us;
uint8_t gpo2_rx_delay_us;
uint8_t gpo2_tx_delay_us;
uint8_t gpo3_rx_delay_us;
uint8_t gpo3_tx_delay_us;
uint32_t low_high_gain_threshold_mdB;
uint32_t low_gain_dB;
uint32_t high_gain_dB;
uint8_t tx_mon_track_en;
uint8_t one_shot_mode_en;
uint32_t tx_mon_delay;
uint32_t tx_mon_duration;
uint32_t tx1_mon_front_end_gain;
uint32_t tx2_mon_front_end_gain;
uint32_t tx1_mon_lo_cm;
uint32_t tx2_mon_lo_cm;
int32_t gpio_resetb;
int32_t gpio_sync;
int32_t gpio_cal_sw1;
int32_t gpio_cal_sw2;
uint32_t (*ad9361_rfpll_ext_recalc_rate)(struct refclk_scale *clk_priv);
int32_t (*ad9361_rfpll_ext_round_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
int32_t (*ad9361_rfpll_ext_set_rate)(struct refclk_scale *clk_priv,
uint32_t rate);
} AD9361_InitParam;
typedef struct {
uint32_t rx; /* 1, 2, 3(both) */
int32_t rx_gain; /* -12, -6, 0, 6 */
uint32_t rx_dec; /* 1, 2, 4 */
int16_t rx_coef[128];
uint8_t rx_coef_size;
uint32_t rx_path_clks[6];
uint32_t rx_bandwidth;
} AD9361_RXFIRConfig;
typedef struct {
uint32_t tx; /* 1, 2, 3(both) */
int32_t tx_gain; /* -6, 0 */
uint32_t tx_int; /* 1, 2, 4 */
int16_t tx_coef[128];
uint8_t tx_coef_size;
uint32_t tx_path_clks[6];
uint32_t tx_bandwidth;
} AD9361_TXFIRConfig;
#define AD936X_A_BALANCED 0
#define AD936X_B_BALANCED 1
#define AD936X_C_BALANCED 2
#define AD936X_A_N 3
#define AD936X_A_P 4
#define AD936X_B_N 5
#define AD936X_B_P 6
#define AD936X_C_N 7
#define AD936X_C_P 8
#define AD936X_TX_MON1 9
#define AD936X_TX_MON2 10
#define AD936X_TX_MON1_2 11
#define AD936X_TXA 0
#define AD936X_TXB 1
int32_t ad9361_init(struct ad9361_rf_phy **ad9361_phy,
AD9361_InitParam *init_param,
void *userdata);
int32_t ad9361_deinit(struct ad9361_rf_phy *phy);
int32_t ad9361_set_rx_rf_gain(struct ad9361_rf_phy *phy,
uint8_t ch,
int32_t gain_db);
int32_t ad9361_set_rx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t bandwidth_hz);
int32_t ad9361_get_rx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t *bandwidth_hz);
int32_t ad9361_set_rx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t sampling_freq_hz);
int32_t ad9361_get_rx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t *sampling_freq_hz);
int32_t ad9361_set_rx_lo_freq(struct ad9361_rf_phy *phy, uint64_t lo_freq_hz);
int32_t ad9361_get_rx_lo_freq(struct ad9361_rf_phy *phy, uint64_t *lo_freq_hz);
int32_t ad9361_get_rx_rssi(struct ad9361_rf_phy *phy,
uint8_t ch,
struct rf_rssi *rssi);
int32_t ad9361_set_rx_gain_control_mode(struct ad9361_rf_phy *phy,
uint8_t ch,
uint8_t gc_mode);
int32_t ad9361_get_rx_gain_control_mode(struct ad9361_rf_phy *phy,
uint8_t ch,
uint8_t *gc_mode);
int32_t ad9361_set_rx_fir_config(struct ad9361_rf_phy *phy,
AD9361_RXFIRConfig fir_cfg);
int32_t ad9361_set_rx_fir_en_dis(struct ad9361_rf_phy *phy, uint8_t en_dis);
int32_t ad9361_set_rx_rf_port_input(struct ad9361_rf_phy *phy, uint32_t mode);
int32_t ad9361_get_rx_rf_port_input(struct ad9361_rf_phy *phy, uint32_t *mode);
int32_t ad9361_set_tx_attenuation(struct ad9361_rf_phy *phy,
uint8_t ch,
uint32_t attenuation_mdb);
int32_t ad9361_get_tx_attenuation(struct ad9361_rf_phy *phy,
uint8_t ch,
uint32_t *attenuation_mdb);
int32_t ad9361_set_tx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t bandwidth_hz);
int32_t ad9361_get_tx_rf_bandwidth(struct ad9361_rf_phy *phy,
uint32_t *bandwidth_hz);
int32_t ad9361_set_tx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t sampling_freq_hz);
int32_t ad9361_get_tx_sampling_freq(struct ad9361_rf_phy *phy,
uint32_t *sampling_freq_hz);
int32_t ad9361_set_tx_lo_freq(struct ad9361_rf_phy *phy, uint64_t lo_freq_hz);
int32_t ad9361_get_tx_lo_freq(struct ad9361_rf_phy *phy, uint64_t *lo_freq_hz);
int32_t ad9361_set_tx_fir_config(struct ad9361_rf_phy *phy,
AD9361_TXFIRConfig fir_cfg);
int32_t ad9361_set_tx_fir_en_dis(struct ad9361_rf_phy *phy, uint8_t en_dis);
int32_t ad9361_get_tx_rssi(struct ad9361_rf_phy *phy,
uint8_t ch,
uint32_t *rssi_db_x_1000);
int32_t ad9361_set_tx_rf_port_output(struct ad9361_rf_phy *phy, uint32_t mode);
int32_t ad9361_get_tx_rf_port_output(struct ad9361_rf_phy *phy, uint32_t *mode);
int32_t ad9361_get_temp(struct ad9361_rf_phy *phy);
#endif // AD936X_H_

View file

@ -1,25 +0,0 @@
# Subtree Instructions
These sources are derived from a subtree of https://github.com/analogdevicesinc/no-OS.
## Updating the subtree
Fetch new vendor master:
```
git remote add adi-no-os https://github.com/analogdevicesinc/no-OS.git
git fetch adi-no-os master
git checkout adi-no-os/master
```
Update the `adi-subtree` subtree branch:
```
git subtree split --prefix=ad9361/sw/ -b adi-subtree
```
Merge the updated subtree:
```
git subtree merge -P host/libraries/libbladeRF/src/driver/thirdparty/adi adi-subtree --squash
```

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,508 +0,0 @@
/***************************************************************************//**
* @file ad9361_api.h
* @brief Header file of AD9361 API Driver.
* @author DBogdan (dragos.bogdan@analog.com)
********************************************************************************
* Copyright 2013(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef AD9361_API_H_
#define AD9361_API_H_
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "util.h"
/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
typedef struct
{
/* Device selection */
enum dev_id dev_sel;
/* Identification number */
uint8_t id_no;
/* Reference Clock */
uint32_t reference_clk_rate;
/* Base Configuration */
uint8_t two_rx_two_tx_mode_enable; /* adi,2rx-2tx-mode-enable */
uint8_t one_rx_one_tx_mode_use_rx_num; /* adi,1rx-1tx-mode-use-rx-num */
uint8_t one_rx_one_tx_mode_use_tx_num; /* adi,1rx-1tx-mode-use-tx-num */
uint8_t frequency_division_duplex_mode_enable; /* adi,frequency-division-duplex-mode-enable */
uint8_t frequency_division_duplex_independent_mode_enable; /* adi,frequency-division-duplex-independent-mode-enable */
uint8_t tdd_use_dual_synth_mode_enable; /* adi,tdd-use-dual-synth-mode-enable */
uint8_t tdd_skip_vco_cal_enable; /* adi,tdd-skip-vco-cal-enable */
uint32_t tx_fastlock_delay_ns; /* adi,tx-fastlock-delay-ns */
uint32_t rx_fastlock_delay_ns; /* adi,rx-fastlock-delay-ns */
uint8_t rx_fastlock_pincontrol_enable; /* adi,rx-fastlock-pincontrol-enable */
uint8_t tx_fastlock_pincontrol_enable; /* adi,tx-fastlock-pincontrol-enable */
uint8_t external_rx_lo_enable; /* adi,external-rx-lo-enable */
uint8_t external_tx_lo_enable; /* adi,external-tx-lo-enable */
uint8_t dc_offset_tracking_update_event_mask; /* adi,dc-offset-tracking-update-event-mask */
uint8_t dc_offset_attenuation_high_range; /* adi,dc-offset-attenuation-high-range */
uint8_t dc_offset_attenuation_low_range; /* adi,dc-offset-attenuation-low-range */
uint8_t dc_offset_count_high_range; /* adi,dc-offset-count-high-range */
uint8_t dc_offset_count_low_range; /* adi,dc-offset-count-low-range */
uint8_t split_gain_table_mode_enable; /* adi,split-gain-table-mode-enable */
uint32_t trx_synthesizer_target_fref_overwrite_hz; /* adi,trx-synthesizer-target-fref-overwrite-hz */
uint8_t qec_tracking_slow_mode_enable; /* adi,qec-tracking-slow-mode-enable */
/* ENSM Control */
uint8_t ensm_enable_pin_pulse_mode_enable; /* adi,ensm-enable-pin-pulse-mode-enable */
uint8_t ensm_enable_txnrx_control_enable; /* adi,ensm-enable-txnrx-control-enable */
/* LO Control */
uint64_t rx_synthesizer_frequency_hz; /* adi,rx-synthesizer-frequency-hz */
uint64_t tx_synthesizer_frequency_hz; /* adi,tx-synthesizer-frequency-hz */
/* Rate & BW Control */
uint32_t rx_path_clock_frequencies[6]; /* adi,rx-path-clock-frequencies */
uint32_t tx_path_clock_frequencies[6]; /* adi,tx-path-clock-frequencies */
uint32_t rf_rx_bandwidth_hz; /* adi,rf-rx-bandwidth-hz */
uint32_t rf_tx_bandwidth_hz; /* adi,rf-tx-bandwidth-hz */
/* RF Port Control */
uint32_t rx_rf_port_input_select; /* adi,rx-rf-port-input-select */
uint32_t tx_rf_port_input_select; /* adi,tx-rf-port-input-select */
/* TX Attenuation Control */
int32_t tx_attenuation_mdB; /* adi,tx-attenuation-mdB */
uint8_t update_tx_gain_in_alert_enable; /* adi,update-tx-gain-in-alert-enable */
/* Reference Clock Control */
uint8_t xo_disable_use_ext_refclk_enable; /* adi,xo-disable-use-ext-refclk-enable */
uint32_t dcxo_coarse_and_fine_tune[2]; /* adi,dcxo-coarse-and-fine-tune */
uint32_t clk_output_mode_select; /* adi,clk-output-mode-select */
/* Gain Control */
uint8_t gc_rx1_mode; /* adi,gc-rx1-mode */
uint8_t gc_rx2_mode; /* adi,gc-rx2-mode */
uint8_t gc_adc_large_overload_thresh; /* adi,gc-adc-large-overload-thresh */
uint8_t gc_adc_ovr_sample_size; /* adi,gc-adc-ovr-sample-size */
uint8_t gc_adc_small_overload_thresh; /* adi,gc-adc-small-overload-thresh */
uint16_t gc_dec_pow_measurement_duration; /* adi,gc-dec-pow-measurement-duration */
uint8_t gc_dig_gain_enable; /* adi,gc-dig-gain-enable */
uint16_t gc_lmt_overload_high_thresh; /* adi,gc-lmt-overload-high-thresh */
uint16_t gc_lmt_overload_low_thresh; /* adi,gc-lmt-overload-low-thresh */
uint8_t gc_low_power_thresh; /* adi,gc-low-power-thresh */
uint8_t gc_max_dig_gain; /* adi,gc-max-dig-gain */
/* Gain MGC Control */
uint8_t mgc_dec_gain_step; /* adi,mgc-dec-gain-step */
uint8_t mgc_inc_gain_step; /* adi,mgc-inc-gain-step */
uint8_t mgc_rx1_ctrl_inp_enable; /* adi,mgc-rx1-ctrl-inp-enable */
uint8_t mgc_rx2_ctrl_inp_enable; /* adi,mgc-rx2-ctrl-inp-enable */
uint8_t mgc_split_table_ctrl_inp_gain_mode; /* adi,mgc-split-table-ctrl-inp-gain-mode */
/* Gain AGC Control */
uint8_t agc_adc_large_overload_exceed_counter; /* adi,agc-adc-large-overload-exceed-counter */
uint8_t agc_adc_large_overload_inc_steps; /* adi,agc-adc-large-overload-inc-steps */
uint8_t agc_adc_lmt_small_overload_prevent_gain_inc_enable; /* adi,agc-adc-lmt-small-overload-prevent-gain-inc-enable */
uint8_t agc_adc_small_overload_exceed_counter; /* adi,agc-adc-small-overload-exceed-counter */
uint8_t agc_dig_gain_step_size; /* adi,agc-dig-gain-step-size */
uint8_t agc_dig_saturation_exceed_counter; /* adi,agc-dig-saturation-exceed-counter */
uint32_t agc_gain_update_interval_us; /* adi,agc-gain-update-interval-us */
uint8_t agc_immed_gain_change_if_large_adc_overload_enable; /* adi,agc-immed-gain-change-if-large-adc-overload-enable */
uint8_t agc_immed_gain_change_if_large_lmt_overload_enable; /* adi,agc-immed-gain-change-if-large-lmt-overload-enable */
uint8_t agc_inner_thresh_high; /* adi,agc-inner-thresh-high */
uint8_t agc_inner_thresh_high_dec_steps; /* adi,agc-inner-thresh-high-dec-steps */
uint8_t agc_inner_thresh_low; /* adi,agc-inner-thresh-low */
uint8_t agc_inner_thresh_low_inc_steps; /* adi,agc-inner-thresh-low-inc-steps */
uint8_t agc_lmt_overload_large_exceed_counter; /* adi,agc-lmt-overload-large-exceed-counter */
uint8_t agc_lmt_overload_large_inc_steps; /* adi,agc-lmt-overload-large-inc-steps */
uint8_t agc_lmt_overload_small_exceed_counter; /* adi,agc-lmt-overload-small-exceed-counter */
uint8_t agc_outer_thresh_high; /* adi,agc-outer-thresh-high */
uint8_t agc_outer_thresh_high_dec_steps; /* adi,agc-outer-thresh-high-dec-steps */
uint8_t agc_outer_thresh_low; /* adi,agc-outer-thresh-low */
uint8_t agc_outer_thresh_low_inc_steps; /* adi,agc-outer-thresh-low-inc-steps */
uint32_t agc_attack_delay_extra_margin_us; /* adi,agc-attack-delay-extra-margin-us */
uint8_t agc_sync_for_gain_counter_enable; /* adi,agc-sync-for-gain-counter-enable */
/* Fast AGC */
uint32_t fagc_dec_pow_measuremnt_duration; /* adi,fagc-dec-pow-measurement-duration */
uint32_t fagc_state_wait_time_ns; /* adi,fagc-state-wait-time-ns */
/* Fast AGC - Low Power */
uint8_t fagc_allow_agc_gain_increase; /* adi,fagc-allow-agc-gain-increase-enable */
uint32_t fagc_lp_thresh_increment_time; /* adi,fagc-lp-thresh-increment-time */
uint32_t fagc_lp_thresh_increment_steps; /* adi,fagc-lp-thresh-increment-steps */
/* Fast AGC - Lock Level */
uint32_t fagc_lock_level; /* adi,fagc-lock-level */
uint8_t fagc_lock_level_lmt_gain_increase_en; /* adi,fagc-lock-level-lmt-gain-increase-enable */
uint32_t fagc_lock_level_gain_increase_upper_limit; /* adi,fagc-lock-level-gain-increase-upper-limit */
/* Fast AGC - Peak Detectors and Final Settling */
uint32_t fagc_lpf_final_settling_steps; /* adi,fagc-lpf-final-settling-steps */
uint32_t fagc_lmt_final_settling_steps; /* adi,fagc-lmt-final-settling-steps */
uint32_t fagc_final_overrange_count; /* adi,fagc-final-overrange-count */
/* Fast AGC - Final Power Test */
uint8_t fagc_gain_increase_after_gain_lock_en; /* adi,fagc-gain-increase-after-gain-lock-enable */
/* Fast AGC - Unlocking the Gain */
uint32_t fagc_gain_index_type_after_exit_rx_mode; /* adi,fagc-gain-index-type-after-exit-rx-mode */
uint8_t fagc_use_last_lock_level_for_set_gain_en; /* adi,fagc-use-last-lock-level-for-set-gain-enable */
uint8_t fagc_rst_gla_stronger_sig_thresh_exceeded_en; /* adi,fagc-rst-gla-stronger-sig-thresh-exceeded-enable */
uint32_t fagc_optimized_gain_offset; /* adi,fagc-optimized-gain-offset */
uint32_t fagc_rst_gla_stronger_sig_thresh_above_ll; /* adi,fagc-rst-gla-stronger-sig-thresh-above-ll */
uint8_t fagc_rst_gla_engergy_lost_sig_thresh_exceeded_en; /* adi,fagc-rst-gla-engergy-lost-sig-thresh-exceeded-enable */
uint8_t fagc_rst_gla_engergy_lost_goto_optim_gain_en; /* adi,fagc-rst-gla-engergy-lost-goto-optim-gain-enable */
uint32_t fagc_rst_gla_engergy_lost_sig_thresh_below_ll; /* adi,fagc-rst-gla-engergy-lost-sig-thresh-below-ll */
uint32_t fagc_energy_lost_stronger_sig_gain_lock_exit_cnt; /* adi,fagc-energy-lost-stronger-sig-gain-lock-exit-cnt */
uint8_t fagc_rst_gla_large_adc_overload_en; /* adi,fagc-rst-gla-large-adc-overload-enable */
uint8_t fagc_rst_gla_large_lmt_overload_en; /* adi,fagc-rst-gla-large-lmt-overload-enable */
uint8_t fagc_rst_gla_en_agc_pulled_high_en; /* adi,fagc-rst-gla-en-agc-pulled-high-enable */
uint32_t fagc_rst_gla_if_en_agc_pulled_high_mode; /* adi,fagc-rst-gla-if-en-agc-pulled-high-mode */
uint32_t fagc_power_measurement_duration_in_state5; /* adi,fagc-power-measurement-duration-in-state5 */
/* RSSI Control */
uint32_t rssi_delay; /* adi,rssi-delay */
uint32_t rssi_duration; /* adi,rssi-duration */
uint8_t rssi_restart_mode; /* adi,rssi-restart-mode */
uint8_t rssi_unit_is_rx_samples_enable; /* adi,rssi-unit-is-rx-samples-enable */
uint32_t rssi_wait; /* adi,rssi-wait */
/* Aux ADC Control */
uint32_t aux_adc_decimation; /* adi,aux-adc-decimation */
uint32_t aux_adc_rate; /* adi,aux-adc-rate */
/* AuxDAC Control */
uint8_t aux_dac_manual_mode_enable; /* adi,aux-dac-manual-mode-enable */
uint32_t aux_dac1_default_value_mV; /* adi,aux-dac1-default-value-mV */
uint8_t aux_dac1_active_in_rx_enable; /* adi,aux-dac1-active-in-rx-enable */
uint8_t aux_dac1_active_in_tx_enable; /* adi,aux-dac1-active-in-tx-enable */
uint8_t aux_dac1_active_in_alert_enable; /* adi,aux-dac1-active-in-alert-enable */
uint32_t aux_dac1_rx_delay_us; /* adi,aux-dac1-rx-delay-us */
uint32_t aux_dac1_tx_delay_us; /* adi,aux-dac1-tx-delay-us */
uint32_t aux_dac2_default_value_mV; /* adi,aux-dac2-default-value-mV */
uint8_t aux_dac2_active_in_rx_enable; /* adi,aux-dac2-active-in-rx-enable */
uint8_t aux_dac2_active_in_tx_enable; /* adi,aux-dac2-active-in-tx-enable */
uint8_t aux_dac2_active_in_alert_enable; /* adi,aux-dac2-active-in-alert-enable */
uint32_t aux_dac2_rx_delay_us; /* adi,aux-dac2-rx-delay-us */
uint32_t aux_dac2_tx_delay_us; /* adi,aux-dac2-tx-delay-us */
/* Temperature Sensor Control */
uint32_t temp_sense_decimation; /* adi,temp-sense-decimation */
uint16_t temp_sense_measurement_interval_ms; /* adi,temp-sense-measurement-interval-ms */
int8_t temp_sense_offset_signed; /* adi,temp-sense-offset-signed */
uint8_t temp_sense_periodic_measurement_enable; /* adi,temp-sense-periodic-measurement-enable */
/* Control Out Setup */
uint8_t ctrl_outs_enable_mask; /* adi,ctrl-outs-enable-mask */
uint8_t ctrl_outs_index; /* adi,ctrl-outs-index */
/* External LNA Control */
uint32_t elna_settling_delay_ns; /* adi,elna-settling-delay-ns */
uint32_t elna_gain_mdB; /* adi,elna-gain-mdB */
uint32_t elna_bypass_loss_mdB; /* adi,elna-bypass-loss-mdB */
uint8_t elna_rx1_gpo0_control_enable; /* adi,elna-rx1-gpo0-control-enable */
uint8_t elna_rx2_gpo1_control_enable; /* adi,elna-rx2-gpo1-control-enable */
uint8_t elna_gaintable_all_index_enable; /* adi,elna-gaintable-all-index-enable */
/* Digital Interface Control */
uint8_t digital_interface_tune_skip_mode; /* adi,digital-interface-tune-skip-mode */
uint8_t digital_interface_tune_fir_disable; /* adi,digital-interface-tune-fir-disable */
uint8_t pp_tx_swap_enable; /* adi,pp-tx-swap-enable */
uint8_t pp_rx_swap_enable; /* adi,pp-rx-swap-enable */
uint8_t tx_channel_swap_enable; /* adi,tx-channel-swap-enable */
uint8_t rx_channel_swap_enable; /* adi,rx-channel-swap-enable */
uint8_t rx_frame_pulse_mode_enable; /* adi,rx-frame-pulse-mode-enable */
uint8_t two_t_two_r_timing_enable; /* adi,2t2r-timing-enable */
uint8_t invert_data_bus_enable; /* adi,invert-data-bus-enable */
uint8_t invert_data_clk_enable; /* adi,invert-data-clk-enable */
uint8_t fdd_alt_word_order_enable; /* adi,fdd-alt-word-order-enable */
uint8_t invert_rx_frame_enable; /* adi,invert-rx-frame-enable */
uint8_t fdd_rx_rate_2tx_enable; /* adi,fdd-rx-rate-2tx-enable */
uint8_t swap_ports_enable; /* adi,swap-ports-enable */
uint8_t single_data_rate_enable; /* adi,single-data-rate-enable */
uint8_t lvds_mode_enable; /* adi,lvds-mode-enable */
uint8_t half_duplex_mode_enable; /* adi,half-duplex-mode-enable */
uint8_t single_port_mode_enable; /* adi,single-port-mode-enable */
uint8_t full_port_enable; /* adi,full-port-enable */
uint8_t full_duplex_swap_bits_enable; /* adi,full-duplex-swap-bits-enable */
uint32_t delay_rx_data; /* adi,delay-rx-data */
uint32_t rx_data_clock_delay; /* adi,rx-data-clock-delay */
uint32_t rx_data_delay; /* adi,rx-data-delay */
uint32_t tx_fb_clock_delay; /* adi,tx-fb-clock-delay */
uint32_t tx_data_delay; /* adi,tx-data-delay */
uint32_t lvds_bias_mV; /* adi,lvds-bias-mV */
uint8_t lvds_rx_onchip_termination_enable; /* adi,lvds-rx-onchip-termination-enable */
uint8_t rx1rx2_phase_inversion_en; /* adi,rx1-rx2-phase-inversion-enable */
uint8_t lvds_invert1_control; /* adi,lvds-invert1-control */
uint8_t lvds_invert2_control; /* adi,lvds-invert2-control */
uint8_t clk_out_drive;
uint8_t dataclk_drive;
uint8_t data_port_drive;
uint8_t clk_out_slew;
uint8_t dataclk_slew;
uint8_t data_port_slew;
/* GPO Control */
uint8_t gpo0_inactive_state_high_enable; /* adi,gpo0-inactive-state-high-enable */
uint8_t gpo1_inactive_state_high_enable; /* adi,gpo1-inactive-state-high-enable */
uint8_t gpo2_inactive_state_high_enable; /* adi,gpo2-inactive-state-high-enable */
uint8_t gpo3_inactive_state_high_enable; /* adi,gpo3-inactive-state-high-enable */
uint8_t gpo0_slave_rx_enable; /* adi,gpo0-slave-rx-enable */
uint8_t gpo0_slave_tx_enable; /* adi,gpo0-slave-tx-enable */
uint8_t gpo1_slave_rx_enable; /* adi,gpo1-slave-rx-enable */
uint8_t gpo1_slave_tx_enable; /* adi,gpo1-slave-tx-enable */
uint8_t gpo2_slave_rx_enable; /* adi,gpo2-slave-rx-enable */
uint8_t gpo2_slave_tx_enable; /* adi,gpo2-slave-tx-enable */
uint8_t gpo3_slave_rx_enable; /* adi,gpo3-slave-rx-enable */
uint8_t gpo3_slave_tx_enable; /* adi,gpo3-slave-tx-enable */
uint8_t gpo0_rx_delay_us; /* adi,gpo0-rx-delay-us */
uint8_t gpo0_tx_delay_us; /* adi,gpo0-tx-delay-us */
uint8_t gpo1_rx_delay_us; /* adi,gpo1-rx-delay-us */
uint8_t gpo1_tx_delay_us; /* adi,gpo1-tx-delay-us */
uint8_t gpo2_rx_delay_us; /* adi,gpo2-rx-delay-us */
uint8_t gpo2_tx_delay_us; /* adi,gpo2-tx-delay-us */
uint8_t gpo3_rx_delay_us; /* adi,gpo3-rx-delay-us */
uint8_t gpo3_tx_delay_us; /* adi,gpo3-tx-delay-us */
/* Tx Monitor Control */
uint32_t low_high_gain_threshold_mdB; /* adi,txmon-low-high-thresh */
uint32_t low_gain_dB; /* adi,txmon-low-gain */
uint32_t high_gain_dB; /* adi,txmon-high-gain */
uint8_t tx_mon_track_en; /* adi,txmon-dc-tracking-enable */
uint8_t one_shot_mode_en; /* adi,txmon-one-shot-mode-enable */
uint32_t tx_mon_delay; /* adi,txmon-delay */
uint32_t tx_mon_duration; /* adi,txmon-duration */
uint32_t tx1_mon_front_end_gain; /* adi,txmon-1-front-end-gain */
uint32_t tx2_mon_front_end_gain; /* adi,txmon-2-front-end-gain */
uint32_t tx1_mon_lo_cm; /* adi,txmon-1-lo-cm */
uint32_t tx2_mon_lo_cm; /* adi,txmon-2-lo-cm */
/* GPIO definitions */
int32_t gpio_resetb; /* reset-gpios */
/* MCS Sync */
int32_t gpio_sync; /* sync-gpios */
int32_t gpio_cal_sw1; /* cal-sw1-gpios */
int32_t gpio_cal_sw2; /* cal-sw2-gpios */
/* External LO clocks */
uint32_t (*ad9361_rfpll_ext_recalc_rate)(struct refclk_scale *clk_priv);
int32_t (*ad9361_rfpll_ext_round_rate)(struct refclk_scale *clk_priv, uint32_t rate);
int32_t (*ad9361_rfpll_ext_set_rate)(struct refclk_scale *clk_priv, uint32_t rate);
}AD9361_InitParam;
typedef struct
{
uint32_t rx; /* 1, 2, 3(both) */
int32_t rx_gain; /* -12, -6, 0, 6 */
uint32_t rx_dec; /* 1, 2, 4 */
int16_t rx_coef[128];
uint8_t rx_coef_size;
uint32_t rx_path_clks[6];
uint32_t rx_bandwidth;
}AD9361_RXFIRConfig;
typedef struct
{
uint32_t tx; /* 1, 2, 3(both) */
int32_t tx_gain; /* -6, 0 */
uint32_t tx_int; /* 1, 2, 4 */
int16_t tx_coef[128];
uint8_t tx_coef_size;
uint32_t tx_path_clks[6];
uint32_t tx_bandwidth;
}AD9361_TXFIRConfig;
enum ad9361_ensm_mode {
ENSM_MODE_TX,
ENSM_MODE_RX,
ENSM_MODE_ALERT,
ENSM_MODE_FDD,
ENSM_MODE_WAIT,
ENSM_MODE_SLEEP,
ENSM_MODE_PINCTRL,
ENSM_MODE_PINCTRL_FDD_INDEP,
};
#define ENABLE 1
#define DISABLE 0
#define RX1 0
#define RX2 1
#define TX1 0
#define TX2 1
#define A_BALANCED 0
#define B_BALANCED 1
#define C_BALANCED 2
#define A_N 3
#define A_P 4
#define B_N 5
#define B_P 6
#define C_N 7
#define C_P 8
#define TX_MON1 9
#define TX_MON2 10
#define TX_MON1_2 11
#define TXA 0
#define TXB 1
#define MODE_1x1 1
#define MODE_2x2 2
#define HIGHEST_OSR 0
#define NOMINAL_OSR 1
#define INT_LO 0
#define EXT_LO 1
/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
/* Initialize the AD9361 part. */
int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_param, void *userdata);
/* Deinitialize the AD9361 part. */
int32_t ad9361_deinit (struct ad9361_rf_phy *phy);
/* Set the Enable State Machine (ENSM) mode. */
int32_t ad9361_set_en_state_machine_mode (struct ad9361_rf_phy *phy, uint32_t mode);
/* Get the Enable State Machine (ENSM) mode. */
int32_t ad9361_get_en_state_machine_mode (struct ad9361_rf_phy *phy, uint32_t *mode);
/* Set the receive RF gain for the selected channel. */
int32_t ad9361_set_rx_rf_gain (struct ad9361_rf_phy *phy, uint8_t ch, int32_t gain_db);
/* Get current receive RF gain for the selected channel. */
int32_t ad9361_get_rx_rf_gain (struct ad9361_rf_phy *phy, uint8_t ch, int32_t *gain_db);
/* Set the RX RF bandwidth. */
int32_t ad9361_set_rx_rf_bandwidth (struct ad9361_rf_phy *phy, uint32_t bandwidth_hz);
/* Get the RX RF bandwidth. */
int32_t ad9361_get_rx_rf_bandwidth (struct ad9361_rf_phy *phy, uint32_t *bandwidth_hz);
/* Set the RX sampling frequency. */
int32_t ad9361_set_rx_sampling_freq (struct ad9361_rf_phy *phy, uint32_t sampling_freq_hz);
/* Get current RX sampling frequency. */
int32_t ad9361_get_rx_sampling_freq (struct ad9361_rf_phy *phy, uint32_t *sampling_freq_hz);
/* Set the RX LO frequency. */
int32_t ad9361_set_rx_lo_freq (struct ad9361_rf_phy *phy, uint64_t lo_freq_hz);
/* Get current RX LO frequency. */
int32_t ad9361_get_rx_lo_freq (struct ad9361_rf_phy *phy, uint64_t *lo_freq_hz);
/* Switch between internal and external LO. */
int32_t ad9361_set_rx_lo_int_ext(struct ad9361_rf_phy *phy, uint8_t int_ext);
/* Get the RSSI for the selected channel. */
int32_t ad9361_get_rx_rssi (struct ad9361_rf_phy *phy, uint8_t ch, struct rf_rssi *rssi);
/* Set the gain control mode for the selected channel. */
int32_t ad9361_set_rx_gain_control_mode (struct ad9361_rf_phy *phy, uint8_t ch, uint8_t gc_mode);
/* Get the gain control mode for the selected channel. */
int32_t ad9361_get_rx_gain_control_mode (struct ad9361_rf_phy *phy, uint8_t ch, uint8_t *gc_mode);
/* Set the RX FIR filter configuration. */
int32_t ad9361_set_rx_fir_config (struct ad9361_rf_phy *phy, AD9361_RXFIRConfig fir_cfg);
/* Get the RX FIR filter configuration. */
int32_t ad9361_get_rx_fir_config(struct ad9361_rf_phy *phy, uint8_t rx_ch, AD9361_RXFIRConfig *fir_cfg);
/* Enable/disable the RX FIR filter. */
int32_t ad9361_set_rx_fir_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Get the status of the RX FIR filter. */
int32_t ad9361_get_rx_fir_en_dis (struct ad9361_rf_phy *phy, uint8_t *en_dis);
/* Enable/disable the RX RFDC Tracking. */
int32_t ad9361_set_rx_rfdc_track_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Get the status of the RX RFDC Tracking. */
int32_t ad9361_get_rx_rfdc_track_en_dis (struct ad9361_rf_phy *phy, uint8_t *en_dis);
/* Enable/disable the RX BasebandDC Tracking. */
int32_t ad9361_set_rx_bbdc_track_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Get the status of the RX BasebandDC Tracking. */
int32_t ad9361_get_rx_bbdc_track_en_dis (struct ad9361_rf_phy *phy, uint8_t *en_dis);
/* Enable/disable the RX Quadrature Tracking. */
int32_t ad9361_set_rx_quad_track_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Get the status of the RX Quadrature Tracking. */
int32_t ad9361_get_rx_quad_track_en_dis (struct ad9361_rf_phy *phy, uint8_t *en_dis);
/* Set the RX RF input port. */
int32_t ad9361_set_rx_rf_port_input (struct ad9361_rf_phy *phy, uint32_t mode);
/* Get the selected RX RF input port. */
int32_t ad9361_get_rx_rf_port_input (struct ad9361_rf_phy *phy, uint32_t *mode);
/* Store RX fastlock profile. */
int32_t ad9361_rx_fastlock_store(struct ad9361_rf_phy *phy, uint32_t profile);
/* Recall RX fastlock profile. */
int32_t ad9361_rx_fastlock_recall(struct ad9361_rf_phy *phy, uint32_t profile);
/* Load RX fastlock profile. */
int32_t ad9361_rx_fastlock_load(struct ad9361_rf_phy *phy, uint32_t profile, uint8_t *values);
/* Save RX fastlock profile. */
int32_t ad9361_rx_fastlock_save(struct ad9361_rf_phy *phy, uint32_t profile, uint8_t *values);
/* Set power down TX LO/Synthesizers */
int32_t ad9361_set_rx_lo_powerdown(struct ad9361_rf_phy *phy, uint8_t pd);
/* Get power down TX LO/Synthesizers */
int32_t ad9361_get_rx_lo_powerdown(struct ad9361_rf_phy *phy, uint8_t *pd);
/* Set the transmit attenuation for the selected channel. */
int32_t ad9361_set_tx_attenuation (struct ad9361_rf_phy *phy, uint8_t ch, uint32_t attenuation_mdb);
/* Get current transmit attenuation for the selected channel. */
int32_t ad9361_get_tx_attenuation (struct ad9361_rf_phy *phy, uint8_t ch, uint32_t *attenuation_mdb);
/* Set the TX RF bandwidth. */
int32_t ad9361_set_tx_rf_bandwidth (struct ad9361_rf_phy *phy, uint32_t bandwidth_hz);
/* Get the TX RF bandwidth. */
int32_t ad9361_get_tx_rf_bandwidth (struct ad9361_rf_phy *phy, uint32_t *bandwidth_hz);
/* Set the TX sampling frequency. */
int32_t ad9361_set_tx_sampling_freq (struct ad9361_rf_phy *phy, uint32_t sampling_freq_hz);
/* Get current TX sampling frequency. */
int32_t ad9361_get_tx_sampling_freq (struct ad9361_rf_phy *phy, uint32_t *sampling_freq_hz);
/* Set the TX LO frequency. */
int32_t ad9361_set_tx_lo_freq (struct ad9361_rf_phy *phy, uint64_t lo_freq_hz);
/* Get current TX LO frequency. */
int32_t ad9361_get_tx_lo_freq (struct ad9361_rf_phy *phy, uint64_t *lo_freq_hz);
/* Switch between internal and external LO. */
int32_t ad9361_set_tx_lo_int_ext(struct ad9361_rf_phy *phy, uint8_t int_ext);
/* Set the TX FIR filter configuration. */
int32_t ad9361_set_tx_fir_config (struct ad9361_rf_phy *phy, AD9361_TXFIRConfig fir_cfg);
/* Get the TX FIR filter configuration. */
int32_t ad9361_get_tx_fir_config(struct ad9361_rf_phy *phy, uint8_t tx_ch, AD9361_TXFIRConfig *fir_cfg);
/* Enable/disable the TX FIR filter. */
int32_t ad9361_set_tx_fir_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Get the status of the TX FIR filter. */
int32_t ad9361_get_tx_fir_en_dis (struct ad9361_rf_phy *phy, uint8_t *en_dis);
/* Get the TX RSSI for the selected channel. */
int32_t ad9361_get_tx_rssi (struct ad9361_rf_phy *phy, uint8_t ch, uint32_t *rssi_db_x_1000);
/* Set the TX RF output port. */
int32_t ad9361_set_tx_rf_port_output (struct ad9361_rf_phy *phy, uint32_t mode);
/* Get the selected TX RF output port. */
int32_t ad9361_get_tx_rf_port_output (struct ad9361_rf_phy *phy, uint32_t *mode);
/* Enable/disable the auto calibration. */
int32_t ad9361_set_tx_auto_cal_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Get the status of the auto calibration flag. */
int32_t ad9361_get_tx_auto_cal_en_dis (struct ad9361_rf_phy *phy, uint8_t *en_dis);
/* Store TX fastlock profile. */
int32_t ad9361_tx_fastlock_store(struct ad9361_rf_phy *phy, uint32_t profile);
/* Recall TX fastlock profile. */
int32_t ad9361_tx_fastlock_recall(struct ad9361_rf_phy *phy, uint32_t profile);
/* Load TX fastlock profile. */
int32_t ad9361_tx_fastlock_load(struct ad9361_rf_phy *phy, uint32_t profile, uint8_t *values);
/* Save TX fastlock profile. */
int32_t ad9361_tx_fastlock_save(struct ad9361_rf_phy *phy, uint32_t profile, uint8_t *values);
/* Set power down TX LO/Synthesizers */
int32_t ad9361_set_tx_lo_powerdown(struct ad9361_rf_phy *phy, uint8_t pd);
/* Get power down TX LO/Synthesizers */
int32_t ad9361_get_tx_lo_powerdown(struct ad9361_rf_phy *phy, uint8_t *pd);
/* Set the RX and TX path rates. */
int32_t ad9361_set_trx_path_clks(struct ad9361_rf_phy *phy, uint32_t *rx_path_clks, uint32_t *tx_path_clks);
/* Get the RX and TX path rates. */
int32_t ad9361_get_trx_path_clks(struct ad9361_rf_phy *phy, uint32_t *rx_path_clks, uint32_t *tx_path_clks);
/* Power Down RX/TX LO/Synthesizers */
int32_t ad9361_set_trx_lo_powerdown(struct ad9361_rf_phy *phy, uint8_t pd_rx, uint8_t pd_tx);
/* Set the number of channels mode. */
int32_t ad9361_set_no_ch_mode(struct ad9361_rf_phy *phy, uint8_t no_ch_mode);
/* Do multi chip synchronization. */
int32_t ad9361_do_mcs(struct ad9361_rf_phy *phy_master, struct ad9361_rf_phy *phy_slave);
/* Enable/disable the TRX FIR filters. */
int32_t ad9361_set_trx_fir_en_dis (struct ad9361_rf_phy *phy, uint8_t en_dis);
/* Set the OSR rate governor. */
int32_t ad9361_set_trx_rate_gov (struct ad9361_rf_phy *phy, uint32_t rate_gov);
/* Get the OSR rate governor. */
int32_t ad9361_get_trx_rate_gov (struct ad9361_rf_phy *phy, uint32_t *rate_gov);
/* Perform the selected calibration. */
int32_t ad9361_do_calib(struct ad9361_rf_phy *phy, uint32_t cal, int32_t arg);
/* Load and enable TRX FIR filters configurations. */
int32_t ad9361_trx_load_enable_fir(struct ad9361_rf_phy *phy,
AD9361_RXFIRConfig rx_fir_cfg,
AD9361_TXFIRConfig tx_fir_cfg);
/* Do DCXO coarse tuning. */
int32_t ad9361_do_dcxo_tune_coarse(struct ad9361_rf_phy *phy,
uint32_t coarse);
/* Do DCXO fine tuning. */
int32_t ad9361_do_dcxo_tune_fine(struct ad9361_rf_phy *phy,
uint32_t fine);
#endif

View file

@ -1,733 +0,0 @@
/***************************************************************************//**
* @file ad9361_conv.c
* @brief Implementation of AD9361 Conv Driver.
********************************************************************************
* Copyright 2014-2015(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <inttypes.h>
#include <string.h>
#include "ad9361.h"
#include "platform.h"
#include "config.h"
#ifndef AXI_ADC_NOT_PRESENT
/**
* HDL loopback enable/disable.
* @param phy The AD9361 state structure.
* @param enable Enable/disable option.
* @return 0 in case of success, negative error code otherwise.
*/
int32_t ad9361_hdl_loopback(struct ad9361_rf_phy *phy, bool enable)
{
struct axiadc_converter *conv = phy->adc_conv;
struct axiadc_state *st = phy->adc_state;
int32_t addr, chan;
uint32_t version, reg;
int ret;
ret = axiadc_read(st, 0x4000, &version);
if (ret < 0)
return ret;
/* Still there but implemented a bit different */
if (PCORE_VERSION_MAJOR(version) > 7)
addr = 0x4418;
else
addr = 0x4414;
for (chan = 0; chan < conv->chip_info->num_channels; chan++) {
ret = axiadc_read(st, addr + (chan) * 0x40, &reg);
if (ret < 0)
return ret;
if (PCORE_VERSION_MAJOR(version) > 7) {
if (enable && reg != 0x8) {
conv->scratch_reg[chan] = reg;
reg = 0x8;
} else if (reg == 0x8) {
reg = conv->scratch_reg[chan];
}
} else {
/* DAC_LB_ENB If set enables loopback of receive data */
if (enable)
reg |= BIT(1);
else
reg &= ~BIT(1);
}
ret = axiadc_write(st, addr + (chan) * 0x40, reg);
if (ret < 0)
return ret;
}
return 0;
}
/**
* Set IO delay.
* @param st The AXI ADC state structure.
* @param lane Lane number.
* @param val Value.
* @param tx The Synthesizer TX = 1, RX = 0.
* @return 0 in case of success, negative error code otherwise.
*/
static int32_t ad9361_iodelay_set(struct axiadc_state *st, unsigned lane,
unsigned val, bool tx)
{
if (tx) {
if (PCORE_VERSION_MAJOR(st->pcore_version) > 8)
return axiadc_write(st, 0x4000 + ADI_REG_DELAY(lane), val);
else
return -ENODEV;
}
return axiadc_idelay_set(st, lane, val);
}
/**
* Set midscale IO delay.
* @param phy The AD9361 state structure.
* @param tx The Synthesizer TX = 1, RX = 0.
* @return 0 in case of success, negative error code otherwise.
*/
static int32_t ad9361_midscale_iodelay(struct ad9361_rf_phy *phy, bool tx)
{
struct axiadc_state *st = phy->adc_state;
int32_t ret = 0, i;
for (i = 0; i < 7; i++)
ret |= ad9361_iodelay_set(st, i, 15, tx);
return 0;
}
/**
* Digital tune IO delay.
* @param phy The AD9361 state structure.
* @param tx The Synthesizer TX = 1, RX = 0.
* @return 0 in case of success, negative error code otherwise.
*/
static int32_t ad9361_dig_tune_iodelay(struct ad9361_rf_phy *phy, bool tx)
{
struct axiadc_converter *conv = phy->adc_conv;
struct axiadc_state *st = phy->adc_state;
int32_t ret, i, j, chan, num_chan;
uint32_t tmp, stat, s0, c0;
uint8_t field[32];
num_chan = (conv->chip_info->num_channels > 4) ? 4 : conv->chip_info->num_channels;
for (i = 0; i < 7; i++) {
for (j = 0; j < 32; j++) {
ad9361_iodelay_set(st, i, j, tx);
mdelay(1);
for (chan = 0; chan < num_chan; chan++) {
ret = axiadc_write(st, ADI_REG_CHAN_STATUS(chan),
ADI_PN_ERR | ADI_PN_OOS);
if (ret < 0)
return ret;
}
mdelay(10);
for (chan = 0, stat = 0; chan < num_chan; chan++) {
ret = axiadc_read(st, ADI_REG_CHAN_STATUS(chan), &tmp);
if (ret < 0)
return ret;
stat |= tmp;
}
field[j] = stat;
}
c0 = ad9361_find_opt(&field[0], 32, &s0);
ad9361_iodelay_set(st, i, s0 + c0 / 2, tx);
dev_dbg(&phy->spi->dev,
"%s Lane %"PRId32", window cnt %"PRIu32" , start %"PRIu32", IODELAY set to %"PRIu32"\n",
tx ? "TX" :"RX", i , c0, s0, s0 + c0 / 2);
}
return 0;
}
/**
* Digital tune verbose print.
* @param phy The AD9361 state structure.
* @param field Field.
* @param tx The Synthesizer TX = 1, RX = 0.
* @return 0 in case of success, negative error code otherwise.
*/
static void ad9361_dig_tune_verbose_print(struct ad9361_rf_phy *phy,
uint8_t field[][16], bool tx)
{
int32_t i, j;
printk("SAMPL CLK: %"PRIu32" tuning: %s\n",
clk_get_rate(phy, phy->ref_clk_scale[RX_SAMPL_CLK]), tx ? "TX" : "RX");
printk(" ");
for (i = 0; i < 16; i++)
printk("%"PRIx32":", i);
printk("\n");
for (i = 0; i < 2; i++) {
printk("%"PRIx32":", i);
for (j = 0; j < 16; j++) {
printk("%c ", (field[i][j] ? '#' : 'o'));
}
printk("\n");
}
printk("\n");
}
/**
* Digital interface timing analysis.
* @param phy The AD9361 state structure.
* @param buf The buffer.
* @param buflen The buffer length.
* @return The size in case of success, negative error code otherwise.
*/
int32_t ad9361_dig_interface_timing_analysis(struct ad9361_rf_phy *phy,
char *buf, int32_t buflen)
{
struct axiadc_state *st = phy->adc_state;
int32_t ret, i, j, chan, len = 0;
uint32_t tmp, stat;
uint8_t field[16][16];
uint8_t rx;
dev_dbg(&phy->spi->dev, "%s:\n", __func__);
rx = ad9361_spi_read(phy->spi, REG_RX_CLOCK_DATA_DELAY);
ad9361_bist_prbs(phy, BIST_INJ_RX);
for (i = 0; i < 16; i++) {
for (j = 0; j < 16; j++) {
ad9361_spi_write(phy->spi, REG_RX_CLOCK_DATA_DELAY,
DATA_CLK_DELAY(j) | RX_DATA_DELAY(i));
for (chan = 0; chan < 4; chan++) {
ret = axiadc_write(st, ADI_REG_CHAN_STATUS(chan),
ADI_PN_ERR | ADI_PN_OOS);
if (ret < 0)
return ret;
}
mdelay(1);
ret = axiadc_read(st, ADI_REG_STATUS, &stat);
if (ret < 0)
return ret;
if (stat & ADI_STATUS) {
for (chan = 0, stat = 0; chan < 4; chan++) {
ret = axiadc_read(st, ADI_REG_CHAN_STATUS(chan), &tmp);
if (ret < 0)
return ret;
stat |= tmp;
}
} else {
stat = 1;
}
field[i][j] = stat;
}
}
ad9361_spi_write(phy->spi, REG_RX_CLOCK_DATA_DELAY, rx);
ad9361_bist_prbs(phy, BIST_DISABLE);
len += snprintf(buf + len, buflen, "CLK: %"PRIu32" Hz 'o' = PASS\n",
clk_get_rate(phy, phy->ref_clk_scale[RX_SAMPL_CLK]));
len += snprintf(buf + len, buflen, "DC");
for (i = 0; i < 16; i++)
len += snprintf(buf + len, buflen, "%"PRIx32":", i);
len += snprintf(buf + len, buflen, "\n");
for (i = 0; i < 16; i++) {
len += snprintf(buf + len, buflen, "%"PRIx32":", i);
for (j = 0; j < 16; j++) {
len += snprintf(buf + len, buflen, "%c ",
(field[i][j] ? '.' : 'o'));
}
len += snprintf(buf + len, buflen, "\n");
}
len += snprintf(buf + len, buflen, "\n");
return len;
}
/**
* Digital tune.
* @param phy The AD9361 state structure.
* @param max_freq Maximum frequency.
* @param flags Flags: BE_VERBOSE, BE_MOREVERBOSE, DO_IDELAY, DO_ODELAY.
* @return 0 in case of success, negative error code otherwise.
*/
int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
enum dig_tune_flags flags)
{
struct axiadc_converter *conv = phy->adc_conv;
struct axiadc_state *st = phy->adc_state;
int32_t ret, i, j, k, chan, t, num_chan, c0, c1, err = 0;
uint32_t stat, s0, s1, tmp, saved = 0;
uint8_t field[2][16];
uint32_t saved_dsel[4], saved_chan_ctrl6[4], saved_chan_ctrl0[4];
uint32_t rates[3] = {25000000U, 40000000U, 61440000U};
uint32_t hdl_dac_version;
dev_dbg(&phy->spi->dev, "%s: freq %"PRIu32" flags 0x%X\n", __func__,
max_freq, flags);
ret = axiadc_read(st, 0x4000, &hdl_dac_version);
if (ret < 0)
return ret;
if ((phy->pdata->dig_interface_tune_skipmode == 2) ||
(flags & RESTORE_DEFAULT)) {
/* skip completely and use defaults */
ad9361_spi_write(phy->spi, REG_RX_CLOCK_DATA_DELAY,
phy->pdata->port_ctrl.rx_clk_data_delay);
ad9361_spi_write(phy->spi, REG_TX_CLOCK_DATA_DELAY,
phy->pdata->port_ctrl.tx_clk_data_delay);
return 0;
}
/* Mute TX, we don't want to transmit the PRBS */
ad9361_tx_mute(phy, 1);
if (flags & DO_IDELAY)
ad9361_midscale_iodelay(phy, 0);
if (flags & DO_ODELAY)
ad9361_midscale_iodelay(phy, 1);
if (!phy->pdata->fdd) {
ad9361_set_ensm_mode(phy, true, false);
ad9361_ensm_force_state(phy, ENSM_STATE_FDD);
} else {
ad9361_ensm_force_state(phy, ENSM_STATE_ALERT);
ad9361_ensm_restore_prev_state(phy);
}
num_chan = (conv->chip_info->num_channels > 4) ? 4 :
conv->chip_info->num_channels;
ad9361_bist_prbs(phy, BIST_INJ_RX);
for (t = 0; t < 2; t++) {
memset(field, 0, 32);
for (k = 0; (uint32_t)k < (max_freq ? ARRAY_SIZE(rates) : 1); k++) {
if (max_freq)
ad9361_set_trx_clock_chain_freq(phy,
((phy->pdata->port_ctrl.pp_conf[2] & LVDS_MODE) || !phy->pdata->rx2tx2) ?
rates[k] : rates[k] / 2);
for (i = 0; i < 2; i++) {
for (j = 0; j < 16; j++) {
ad9361_spi_write(phy->spi,
REG_RX_CLOCK_DATA_DELAY + t,
RX_DATA_DELAY(i == 0 ? j : 0) |
DATA_CLK_DELAY(i ? j : 0));
for (chan = 0; chan < num_chan; chan++) {
ret = axiadc_write(st, ADI_REG_CHAN_STATUS(chan),
ADI_PN_ERR | ADI_PN_OOS);
if (ret < 0)
return ret;
}
mdelay(4);
ret = axiadc_read(st, ADI_REG_STATUS, &stat);
if (ret < 0)
return ret;
if ((t == 1) || (stat & ADI_STATUS)) {
for (chan = 0, stat = 0; chan < num_chan; chan++) {
ret = axiadc_read(st, ADI_REG_CHAN_STATUS(chan), &tmp);
if (ret < 0)
return ret;
stat |= tmp;
}
} else {
stat = 1;
}
field[i][j] |= stat;
}
}
if ((flags & BE_MOREVERBOSE) && max_freq) {
ad9361_dig_tune_verbose_print(phy, field, t);
}
}
c0 = ad9361_find_opt(&field[0][0], 16, &s0);
c1 = ad9361_find_opt(&field[1][0], 16, &s1);
if (c0 <= 0 && c1 <= 0) {
ad9361_dig_tune_verbose_print(phy, field, t);
dev_err(&phy->spi->dev, "%s: Tuning %s FAILED!", __func__,
t ? "TX" : "RX");
err |= -EIO;
} else if ((flags & BE_VERBOSE) && !(flags & BE_MOREVERBOSE)) {
ad9361_dig_tune_verbose_print(phy, field, t);
}
if (c1 > c0)
ad9361_spi_write(phy->spi, REG_RX_CLOCK_DATA_DELAY + t,
DATA_CLK_DELAY(s1 + c1 / 2) |
RX_DATA_DELAY(0));
else
ad9361_spi_write(phy->spi, REG_RX_CLOCK_DATA_DELAY + t,
DATA_CLK_DELAY(0) |
RX_DATA_DELAY(s0 + c0 / 2));
if (t == 0) {
if (flags & DO_IDELAY)
ad9361_dig_tune_iodelay(phy, 0);
/* Now do the loopback and tune the digital out */
ad9361_bist_prbs(phy, BIST_DISABLE);
ret = axiadc_write(st, ADI_REG_RSTN, ADI_MMCM_RSTN);
if (ret < 0)
return ret;
ret = axiadc_write(st, ADI_REG_RSTN, ADI_RSTN | ADI_MMCM_RSTN);
if (ret < 0)
return ret;
if (phy->pdata->dig_interface_tune_skipmode == 1) {
/* skip TX */
if (!(flags & SKIP_STORE_RESULT))
phy->pdata->port_ctrl.rx_clk_data_delay =
ad9361_spi_read(phy->spi, REG_RX_CLOCK_DATA_DELAY);
if (!phy->pdata->fdd) {
ad9361_set_ensm_mode(phy, phy->pdata->fdd,
phy->pdata->ensm_pin_ctrl);
ad9361_ensm_restore_prev_state(phy);
}
ad9361_tx_mute(phy, 0);
return 0;
}
ad9361_bist_loopback(phy, 1);
ret = axiadc_write(st, 0x4000 + ADI_REG_RSTN, ADI_RSTN | ADI_MMCM_RSTN);
if (ret < 0)
return ret;
for (chan = 0; chan < num_chan; chan++) {
ret = axiadc_read(st, ADI_REG_CHAN_CNTRL(chan), &saved_chan_ctrl0[chan]);
if (ret < 0)
return ret;
ret = axiadc_write(st, ADI_REG_CHAN_CNTRL(chan),
ADI_FORMAT_SIGNEXT | ADI_FORMAT_ENABLE |
ADI_ENABLE | ADI_IQCOR_ENB);
if (ret < 0)
return ret;
ret = axiadc_set_pnsel(st, chan, ADC_PN_CUSTOM);
if (ret < 0)
return ret;
ret = axiadc_read(st, 0x4414 + (chan) * 0x40, &saved_chan_ctrl6[chan]);
if (ret < 0)
return ret;
if (PCORE_VERSION_MAJOR(hdl_dac_version) > 7)
{
ret = axiadc_read(st, 0x4418 + (chan) * 0x40, &saved_dsel[chan]);
if (ret < 0)
return ret;
ret = axiadc_write(st, 0x4418 + (chan) * 0x40, 9);
if (ret < 0)
return ret;
ret = axiadc_write(st, 0x4414 + (chan) * 0x40, 0); /* !IQCOR_ENB */
if (ret < 0)
return ret;
ret = axiadc_write(st, 0x4044, 0x1);
if (ret < 0)
return ret;
} else {
ret = axiadc_write(st, 0x4414 + (chan) * 0x40, 1); /* DAC_PN_ENB */
if (ret < 0)
return ret;
}
}
if (PCORE_VERSION_MAJOR(hdl_dac_version) < 8) {
ret = axiadc_read(st, 0x4048, &tmp);
if (ret < 0)
return ret;
saved = tmp;
tmp &= ~0xF;
tmp |= 1;
ret = axiadc_write(st, 0x4048, tmp);
if (ret < 0)
return ret;
}
} else {
if (flags & DO_ODELAY)
ad9361_dig_tune_iodelay(phy, 1);
ad9361_bist_loopback(phy, 0);
if (PCORE_VERSION_MAJOR(hdl_dac_version) < 8) {
ret = axiadc_write(st, 0x4048, saved);
if (ret < 0)
return ret;
}
for (chan = 0; chan < num_chan; chan++) {
ret = axiadc_write(st, ADI_REG_CHAN_CNTRL(chan),
saved_chan_ctrl0[chan]);
if (ret < 0)
return ret;
ret = axiadc_set_pnsel(st, chan, ADC_PN9);
if (ret < 0)
return ret;
if (PCORE_VERSION_MAJOR(hdl_dac_version) > 7)
{
ret = axiadc_write(st, 0x4418 + (chan) * 0x40, saved_dsel[chan]);
if (ret < 0)
return ret;
ret = axiadc_write(st, 0x4044, 0x1);
if (ret < 0)
return ret;
}
ret = axiadc_write(st, 0x4414 + (chan) * 0x40, saved_chan_ctrl6[chan]);
if (ret < 0)
return ret;
}
if (err == -EIO) {
ad9361_spi_write(phy->spi, REG_RX_CLOCK_DATA_DELAY,
phy->pdata->port_ctrl.rx_clk_data_delay);
ad9361_spi_write(phy->spi, REG_TX_CLOCK_DATA_DELAY,
phy->pdata->port_ctrl.tx_clk_data_delay);
if (!max_freq)
err = 0;
} else if (!(flags & SKIP_STORE_RESULT)) {
phy->pdata->port_ctrl.rx_clk_data_delay =
ad9361_spi_read(phy->spi, REG_RX_CLOCK_DATA_DELAY);
phy->pdata->port_ctrl.tx_clk_data_delay =
ad9361_spi_read(phy->spi, REG_TX_CLOCK_DATA_DELAY);
/* Print the end result of the above calibration */
printk("%s: Digital Interface Timing\n", __func__);
printk("%s: rx_data_clock_delay %d\n", __func__,
phy->pdata->port_ctrl.rx_clk_data_delay >> 4);
printk("%s: rx_data_delay %d\n", __func__,
phy->pdata->port_ctrl.rx_clk_data_delay & 0xF);
printk("%s: tx_fb_clock_delay %d\n", __func__,
phy->pdata->port_ctrl.tx_clk_data_delay >> 4);
printk("%s: tx_data_delay %d\n", __func__,
phy->pdata->port_ctrl.tx_clk_data_delay & 0xF);
}
if (!phy->pdata->fdd) {
ad9361_set_ensm_mode(phy, phy->pdata->fdd, phy->pdata->ensm_pin_ctrl);
ad9361_ensm_restore_prev_state(phy);
}
ret = axiadc_write(st, ADI_REG_RSTN, ADI_MMCM_RSTN);
if (ret < 0)
return ret;
ret = axiadc_write(st, ADI_REG_RSTN, ADI_RSTN | ADI_MMCM_RSTN);
if (ret < 0)
return ret;
ad9361_tx_mute(phy, 0);
return err;
}
}
return -EINVAL;
}
/**
* Setup the AD9361 device.
* @param phy The AD9361 state structure.
* @return 0 in case of success, negative error code otherwise.
*/
int32_t ad9361_post_setup(struct ad9361_rf_phy *phy)
{
struct axiadc_converter *conv = phy->adc_conv;
struct axiadc_state *st = phy->adc_state;
int32_t rx2tx2 = phy->pdata->rx2tx2;
int32_t num_chan, flags;
uint32_t tmp;
int32_t i, ret;
num_chan = (conv->chip_info->num_channels > 4) ? 4 : conv->chip_info->num_channels;
ret = axiadc_write(st, ADI_REG_CNTRL, rx2tx2 ? 0 : ADI_R1_MODE);
if (ret < 0)
return ret;
ret = axiadc_read(st, 0x4048, &tmp);
if (ret < 0)
return ret;
if (!rx2tx2) {
ret = axiadc_write(st, 0x4048, tmp | BIT(5)); /* R1_MODE */
if (ret < 0)
return ret;
ret = axiadc_write(st, 0x404c,
(phy->pdata->port_ctrl.pp_conf[2] & LVDS_MODE) ? 1 : 0); /* RATE */
if (ret < 0)
return ret;
}
else {
tmp &= ~BIT(5);
ret = axiadc_write(st, 0x4048, tmp);
if (ret < 0)
return ret;
ret = axiadc_write(st, 0x404c,
(phy->pdata->port_ctrl.pp_conf[2] & LVDS_MODE) ? 3 : 1); /* RATE */
if (ret < 0)
return ret;
}
#ifdef ALTERA_PLATFORM
ret = axiadc_write(st, 0x404c, 1);
if (ret < 0)
return ret;
#endif
for (i = 0; i < num_chan; i++) {
ret = axiadc_write(st, ADI_REG_CHAN_CNTRL_1(i), ADI_DCFILT_OFFSET(0));
if (ret < 0)
return ret;
ret = axiadc_write(st, ADI_REG_CHAN_CNTRL_2(i),
(i & 1) ? 0x00004000 : 0x40000000);
if (ret < 0)
return ret;
ret = axiadc_write(st, ADI_REG_CHAN_CNTRL(i),
ADI_FORMAT_SIGNEXT | ADI_FORMAT_ENABLE |
ADI_ENABLE | ADI_IQCOR_ENB);
if (ret < 0)
return ret;
}
flags = BE_VERBOSE | BE_MOREVERBOSE;
ret = axiadc_read(st, 0x0004, &tmp);
if (ret < 0)
return ret;
ret = ad9361_dig_tune(phy, ((conv->chip_info->num_channels > 4) || tmp) ? 0 : 61440000, flags);
if (ret < 0)
return ret;
if (flags & (DO_IDELAY | DO_ODELAY)) {
ret = axiadc_read(st, ADI_REG_ID, &tmp);
if (ret < 0)
return ret;
ret = ad9361_dig_tune(phy, (tmp) ? 0 : 61440000, flags & BE_VERBOSE);
if (ret < 0)
return ret;
}
ret = ad9361_set_trx_clock_chain(phy,
phy->pdata->rx_path_clks,
phy->pdata->tx_path_clks);
ad9361_ensm_force_state(phy, ENSM_STATE_ALERT);
ad9361_ensm_restore_prev_state(phy);
return ret;
}
#else
/**
* HDL loopback enable/disable.
* @param phy The AD9361 state structure.
* @param enable Enable/disable option.
* @return 0 in case of success, negative error code otherwise.
*/
int32_t ad9361_hdl_loopback(struct ad9361_rf_phy *phy, bool enable)
{
return -ENODEV;
}
/**
* Digital tune.
* @param phy The AD9361 state structure.
* @param max_freq Maximum frequency.
* @param flags Flags: BE_VERBOSE, BE_MOREVERBOSE, DO_IDELAY, DO_ODELAY.
* @return 0 in case of success, negative error code otherwise.
*/
int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
enum dig_tune_flags flags)
{
return 0;
}
/**
* Setup the AD9361 device.
* @param phy The AD9361 state structure.
* @return 0 in case of success, negative error code otherwise.
*/
int32_t ad9361_post_setup(struct ad9361_rf_phy *phy)
{
return 0;
}
#endif

View file

@ -1,75 +0,0 @@
/***************************************************************************//**
* @file common.h
* @brief Header file of Common Driver.
* @author DBogdan (dragos.bogdan@analog.com)
********************************************************************************
* Copyright 2013(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef COMMON_H_
#define COMMON_H_
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <stdint.h>
#include <errno.h>
#include <stdbool.h>
/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
struct clk {
const char *name;
uint32_t rate;
};
struct clk_hw {
struct clk *clk;
};
struct clk_init_data {
const char *name;
const struct clk_ops *ops;
const char **parent_names;
uint8_t num_parents;
uint32_t flags;
};
struct clk_onecell_data {
struct clk **clks;
uint32_t clk_num;
};
#endif

View file

@ -1,67 +0,0 @@
/***************************************************************************//**
* @file config.h
* @brief Config file of AD9361/API Driver.
* @author DBogdan (dragos.bogdan@analog.com)
********************************************************************************
* Copyright 2015(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef CONFIG_H_
#define CONFIG_H_
#define HAVE_VERBOSE_MESSAGES /* Recommended during development prints errors and warnings */
//#define HAVE_DEBUG_MESSAGES /* For Debug purposes only */
/*
* In case memory footprint is a concern these options allow
* to disable unused functionality which may free up a few kb
*/
#define HAVE_SPLIT_GAIN_TABLE 1 /* only set to 0 in case split_gain_table_mode_enable = 0*/
#define HAVE_TDD_SYNTH_TABLE 1 /* only set to 0 in case split_gain_table_mode_enable = 0*/
#define AD9361_DEVICE 1 /* set it 1 if AD9361 device is used, 0 otherwise */
#define AD9364_DEVICE 0 /* set it 1 if AD9364 device is used, 0 otherwise */
#define AD9363A_DEVICE 0 /* set it 1 if AD9363A device is used, 0 otherwise */
//#define CONSOLE_COMMANDS
//#define XILINX_PLATFORM
#define ALTERA_PLATFORM
//#define FMCOMMS5
//#define PICOZED_SDR
//#define PICOZED_SDR_CMOS
//#define CAPTURE_SCRIPT
//#define AXI_ADC_NOT_PRESENT
//#define TDD_SWITCH_STATE_EXAMPLE
#endif

View file

@ -1,349 +0,0 @@
/***************************************************************************//**
* @file util.c
* @brief Implementation of Util Driver.
* @author DBogdan (dragos.bogdan@analog.com)
********************************************************************************
* Copyright 2013(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "util.h"
#include "string.h"
#include "platform.h"
/******************************************************************************/
/*************************** Macros Definitions *******************************/
/******************************************************************************/
#define BITS_PER_LONG 32
/***************************************************************************//**
* @brief clk_prepare_enable
*******************************************************************************/
int32_t clk_prepare_enable(struct clk *clk)
{
if (clk) {
// Unused variable - fix compiler warning
}
return 0;
}
/***************************************************************************//**
* @brief clk_get_rate
*******************************************************************************/
uint32_t clk_get_rate(struct ad9361_rf_phy *phy,
struct refclk_scale *clk_priv)
{
uint32_t rate = 0;
uint32_t source;
source = clk_priv->source;
switch (source) {
case TX_REFCLK:
case RX_REFCLK:
case BB_REFCLK:
rate = ad9361_clk_factor_recalc_rate(clk_priv,
phy->clk_refin->rate);
break;
case TX_RFPLL_INT:
case RX_RFPLL_INT:
rate = ad9361_rfpll_int_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
break;
case RX_RFPLL_DUMMY:
case TX_RFPLL_DUMMY:
rate = ad9361_rfpll_dummy_recalc_rate(clk_priv);
break;
case TX_RFPLL:
case RX_RFPLL:
rate = ad9361_rfpll_recalc_rate(clk_priv);
break;
case BBPLL_CLK:
rate = ad9361_bbpll_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
break;
case ADC_CLK:
case R2_CLK:
case R1_CLK:
case CLKRF_CLK:
case RX_SAMPL_CLK:
case DAC_CLK:
case T2_CLK:
case T1_CLK:
case CLKTF_CLK:
case TX_SAMPL_CLK:
rate = ad9361_clk_factor_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
break;
default:
break;
}
return rate;
}
/***************************************************************************//**
* @brief clk_set_rate
*******************************************************************************/
int32_t clk_set_rate(struct ad9361_rf_phy *phy,
struct refclk_scale *clk_priv,
uint32_t rate)
{
uint32_t source;
int32_t i;
uint32_t round_rate;
source = clk_priv->source;
if(phy->clks[source]->rate != rate)
{
switch (source) {
case TX_REFCLK:
case RX_REFCLK:
case BB_REFCLK:
round_rate = ad9361_clk_factor_round_rate(clk_priv, rate,
&phy->clk_refin->rate);
ad9361_clk_factor_set_rate(clk_priv, round_rate,
phy->clk_refin->rate);
phy->clks[source]->rate = ad9361_clk_factor_recalc_rate(clk_priv,
phy->clk_refin->rate);
break;
case TX_RFPLL_INT:
case RX_RFPLL_INT:
round_rate = ad9361_rfpll_int_round_rate(clk_priv, rate,
&phy->clks[clk_priv->parent_source]->rate);
ad9361_rfpll_int_set_rate(clk_priv, round_rate,
phy->clks[clk_priv->parent_source]->rate);
phy->clks[source]->rate = ad9361_rfpll_int_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
break;
case RX_RFPLL_DUMMY:
case TX_RFPLL_DUMMY:
ad9361_rfpll_dummy_set_rate(clk_priv, rate);
break;
case TX_RFPLL:
case RX_RFPLL:
round_rate = ad9361_rfpll_round_rate(clk_priv, rate);
ad9361_rfpll_set_rate(clk_priv, round_rate);
phy->clks[source]->rate = ad9361_rfpll_recalc_rate(clk_priv);
break;
case BBPLL_CLK:
round_rate = ad9361_bbpll_round_rate(clk_priv, rate,
&phy->clks[clk_priv->parent_source]->rate);
ad9361_bbpll_set_rate(clk_priv, round_rate,
phy->clks[clk_priv->parent_source]->rate);
phy->clks[source]->rate = ad9361_bbpll_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
phy->bbpll_initialized = true;
break;
case ADC_CLK:
case R2_CLK:
case R1_CLK:
case CLKRF_CLK:
case RX_SAMPL_CLK:
case DAC_CLK:
case T2_CLK:
case T1_CLK:
case CLKTF_CLK:
case TX_SAMPL_CLK:
round_rate = ad9361_clk_factor_round_rate(clk_priv, rate,
&phy->clks[clk_priv->parent_source]->rate);
ad9361_clk_factor_set_rate(clk_priv, round_rate,
phy->clks[clk_priv->parent_source]->rate);
phy->clks[source]->rate = ad9361_clk_factor_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
break;
default:
break;
}
for(i = BB_REFCLK; i < BBPLL_CLK; i++)
{
phy->clks[i]->rate = ad9361_clk_factor_recalc_rate(phy->ref_clk_scale[i],
phy->clk_refin->rate);
}
phy->clks[BBPLL_CLK]->rate = ad9361_bbpll_recalc_rate(phy->ref_clk_scale[BBPLL_CLK],
phy->clks[phy->ref_clk_scale[BBPLL_CLK]->parent_source]->rate);
for(i = ADC_CLK; i < RX_RFPLL_INT; i++)
{
phy->clks[i]->rate = ad9361_clk_factor_recalc_rate(phy->ref_clk_scale[i],
phy->clks[phy->ref_clk_scale[i]->parent_source]->rate);
}
for(i = RX_RFPLL_INT; i < RX_RFPLL_DUMMY; i++)
{
phy->clks[i]->rate = ad9361_rfpll_int_recalc_rate(phy->ref_clk_scale[i],
phy->clks[phy->ref_clk_scale[i]->parent_source]->rate);
}
for(i = RX_RFPLL_DUMMY; i < RX_RFPLL; i++)
{
phy->clks[i]->rate = ad9361_rfpll_dummy_recalc_rate(phy->ref_clk_scale[i]);
}
for(i = RX_RFPLL; i < NUM_AD9361_CLKS; i++)
{
phy->clks[i]->rate = ad9361_rfpll_recalc_rate(phy->ref_clk_scale[i]);
}
} else {
if ((source == BBPLL_CLK) && !phy->bbpll_initialized) {
round_rate = ad9361_bbpll_round_rate(clk_priv, rate,
&phy->clks[clk_priv->parent_source]->rate);
ad9361_bbpll_set_rate(clk_priv, round_rate,
phy->clks[clk_priv->parent_source]->rate);
phy->clks[source]->rate = ad9361_bbpll_recalc_rate(clk_priv,
phy->clks[clk_priv->parent_source]->rate);
phy->bbpll_initialized = true;
}
}
return 0;
}
/***************************************************************************//**
* @brief int_sqrt
*******************************************************************************/
uint32_t int_sqrt(uint32_t x)
{
uint32_t b, m, y = 0;
if (x <= 1)
return x;
m = 1UL << (BITS_PER_LONG - 2);
while (m != 0) {
b = y + m;
y >>= 1;
if (x >= b) {
x -= b;
y += m;
}
m >>= 2;
}
return y;
}
/***************************************************************************//**
* @brief ilog2
*******************************************************************************/
int32_t ilog2(int32_t x)
{
int32_t A = !(!(x >> 16));
int32_t count = 0;
int32_t x_copy = x;
count = count + (A << 4);
x_copy = (((~A + 1) & (x >> 16)) + (~(~A + 1) & x));
A = !(!(x_copy >> 8));
count = count + (A << 3);
x_copy = (((~A + 1) & (x_copy >> 8)) + (~(~A + 1) & x_copy));
A = !(!(x_copy >> 4));
count = count + (A << 2);
x_copy = (((~A + 1) & (x_copy >> 4)) + (~(~A + 1) & x_copy));
A = !(!(x_copy >> 2));
count = count + (A << 1);
x_copy = (((~A + 1) & (x_copy >> 2)) + (~(~A + 1) & x_copy));
A = !(!(x_copy >> 1));
count = count + A;
return count;
}
/***************************************************************************//**
* @brief do_div
*******************************************************************************/
uint64_t do_div(uint64_t* n, uint64_t base)
{
uint64_t mod = 0;
mod = *n % base;
*n = *n / base;
return mod;
}
/***************************************************************************//**
* @brief find_first_bit
*******************************************************************************/
uint32_t find_first_bit(uint32_t word)
{
int32_t num = 0;
if ((word & 0xffff) == 0) {
num += 16;
word >>= 16;
}
if ((word & 0xff) == 0) {
num += 8;
word >>= 8;
}
if ((word & 0xf) == 0) {
num += 4;
word >>= 4;
}
if ((word & 0x3) == 0) {
num += 2;
word >>= 2;
}
if ((word & 0x1) == 0)
num += 1;
return num;
}
/***************************************************************************//**
* @brief ERR_PTR
*******************************************************************************/
void * ERR_PTR(long error)
{
uintptr_t val = error;
return (void *) val;
}
/***************************************************************************//**
* @brief zmalloc
*******************************************************************************/
void *zmalloc(size_t size)
{
void *ptr = malloc(size);
if (ptr)
memset(ptr, 0, size);
mdelay(1);
return ptr;
}

View file

@ -1,141 +0,0 @@
/***************************************************************************//**
* @file util.h
* @brief Header file of Util driver.
* @author DBogdan (dragos.bogdan@analog.com)
********************************************************************************
* Copyright 2013(c) Analog Devices, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* - Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* - The use of this software may or may not infringe the patent rights
* of one or more patent holders. This license does not release you
* from the requirement that you obtain separate licenses from these
* patent holders to use this software.
* - Use of the software either in source or binary form, must be run
* on or directly connected to an Analog Devices Inc. component.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef NO_OS_PORT_H_
#define NO_OS_PORT_H_
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "ad9361.h"
#include "common.h"
#include "config.h"
#include "adc_core.h"
#include "dac_core.h"
/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
#define SUCCESS 0
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
#define min(x, y) (((x) < (y)) ? (x) : (y))
#define min_t(type, x, y) (type)min((type)(x), (type)(y))
#define max(x, y) (((x) > (y)) ? (x) : (y))
#define max_t(type, x, y) (type)max((type)(x), (type)(y))
#define clamp(val, min_val, max_val) (max(min((val), (max_val)), (min_val)))
#define clamp_t(type, val, min_val, max_val) (type)clamp((type)(val), (type)(min_val), (type)(max_val))
#define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
#define DIV_ROUND_CLOSEST(x, divisor) (((x) + (divisor) / 2) / (divisor))
#define BIT(x) (1 << (x))
#define CLK_IGNORE_UNUSED BIT(3)
#define CLK_GET_RATE_NOCACHE BIT(6)
#if defined(HAVE_VERBOSE_MESSAGES)
#define dev_err(dev, format, ...) { printf(format, ## __VA_ARGS__);printf("\n"); }
#define dev_warn(dev, format, ...) { printf(format, ## __VA_ARGS__);printf("\n"); }
#if defined(HAVE_DEBUG_MESSAGES)
#define dev_dbg(dev, format, ...) { printf(format, ## __VA_ARGS__);printf("\n"); }
#else
#define dev_dbg(dev, format, ...) {;}
#endif
#define printk(format, ...) printf(format, ## __VA_ARGS__)
#else
#define dev_err(dev, format, ...) {;}
#define dev_warn(dev, format, ...) {;}
#define dev_dbg(dev, format, ...) {;}
#define printk(format, ...) {;}
#endif
struct spi_device {
void *userdata;
};
struct gpio_device {
void *userdata;
};
struct axiadc_state {
struct ad9361_rf_phy *phy;
uint32_t pcore_version;
struct dds_state dac_dds_state;
void *userdata;
};
struct axiadc_chip_info {
char *name;
int32_t num_channels;
};
struct axiadc_converter {
struct axiadc_chip_info *chip_info;
uint32_t scratch_reg[16];
};
#ifdef WIN32
#include "basetsd.h"
typedef SSIZE_T ssize_t;
#define strsep(s, ct) 0
#define snprintf(s, n, format, ...) 0
#define __func__ __FUNCTION__
#endif
/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
int32_t clk_prepare_enable(struct clk *clk);
uint32_t clk_get_rate(struct ad9361_rf_phy *phy,
struct refclk_scale *clk_priv);
int32_t clk_set_rate(struct ad9361_rf_phy *phy,
struct refclk_scale *clk_priv,
uint32_t rate);
uint32_t int_sqrt(uint32_t x);
int32_t ilog2(int32_t x);
uint64_t do_div(uint64_t* n,
uint64_t base);
uint32_t find_first_bit(uint32_t word);
void * ERR_PTR(long error);
void *zmalloc(size_t size);
#endif

1
thirdparty/analogdevicesinc/no-OS vendored Submodule

@ -0,0 +1 @@
Subproject commit 0bba46e6f6f75785a65d425ece37d0a04daf6157

View file

@ -0,0 +1,919 @@
diff --git a/ad9361/sw/ad9361.c b/ad9361/sw/ad9361.c
index fb41cec..b82d6f3 100644
--- a/ad9361/sw/ad9361.c
+++ b/ad9361/sw/ad9361.c
@@ -577,7 +577,15 @@ int32_t ad9361_spi_readm(struct spi_device *spi, uint32_t reg,
buf[0] = cmd >> 8;
buf[1] = cmd & 0xFF;
+#ifdef NUAND_MODIFICATIONS
+ // no-op to clear warning
+ buf[0] = buf[1];
+
+ // use alternate spi_read
+ ret = spi_read(spi, cmd, rbuf, num);
+#else
ret = spi_write_then_read(spi, &buf[0], 2, rbuf, num);
+#endif // NUAND_MODIFICATIONS
if (ret < 0) {
dev_err(&spi->dev, "Read Error %"PRId32, ret);
return ret;
@@ -668,7 +676,13 @@ int32_t ad9361_spi_write(struct spi_device *spi,
buf[1] = cmd & 0xFF;
buf[2] = val;
+#ifdef NUAND_MODIFICATIONS
+ // use alternate spi_write
+ ret = spi_write(spi, cmd, &(buf[2]), 1);
+#else
ret = spi_write_then_read(spi, buf, 3, NULL, 0);
+#endif // NUAND_MODIFICATIONS
+
if (ret < 0) {
dev_err(&spi->dev, "Write Error %"PRId32, ret);
return ret;
@@ -749,7 +763,17 @@ static int32_t ad9361_spi_writem(struct spi_device *spi,
for (i = 0; i < num; i++)
buf[2 + i] = tbuf[i];
#endif
+
+#ifdef NUAND_MODIFICATIONS
+ // no-op to clear warning
+ buf[0] = buf[1];
+
+ // use alternate spi_write
+ ret = spi_write(spi, cmd, tbuf, num);
+#else
ret = spi_write_then_read(spi, buf, num + 2, NULL, 0);
+#endif // NUAND_MODIFICATIONS
+
if (ret < 0) {
dev_err(&spi->dev, "Write Error %"PRId32, ret);
return ret;
@@ -814,11 +838,22 @@ int32_t ad9361_find_opt(uint8_t *field, uint32_t size, uint32_t *ret_start)
{
int32_t i, cnt = 0, max_cnt = 0, start, max_start = 0;
+#ifdef NUAND_MODIFICATIONS
+ // add check for failed optimal value search
+ bool found_0 = false;
+ bool found_1 = false;
+#endif // NUAND_MODIFICATIONS
+
for(i = 0, start = -1; i < (int64_t)size; i++) {
if (field[i] == 0) {
if (start == -1)
start = i;
cnt++;
+
+#ifdef NUAND_MODIFICATIONS
+ found_0 = true;
+#endif // NUAND_MODIFICATIONS
+
} else {
if (cnt > max_cnt) {
max_cnt = cnt;
@@ -826,6 +861,11 @@ int32_t ad9361_find_opt(uint8_t *field, uint32_t size, uint32_t *ret_start)
}
start = -1;
cnt = 0;
+
+#ifdef NUAND_MODIFICATIONS
+ found_1 = true;
+#endif // NUAND_MODIFICATIONS
+
}
}
@@ -836,6 +876,13 @@ int32_t ad9361_find_opt(uint8_t *field, uint32_t size, uint32_t *ret_start)
*ret_start = max_start;
+#ifdef NUAND_MODIFICATIONS
+ if (!found_0 || !found_1) {
+ // All of the values were the same. This is not a healthy result.
+ return -1;
+ }
+#endif // NUAND_MODIFICATIONS
+
return max_cnt;
}
@@ -871,6 +918,17 @@ int32_t ad9361_1rx1tx_channel_map(struct ad9361_rf_phy *phy, bool tx, int32_t ch
*/
int32_t ad9361_reset(struct ad9361_rf_phy *phy)
{
+#ifdef NUAND_MODIFICATIONS
+ // use alternate gpio accessors
+ if (gpio_is_valid(phy->gpio, phy->pdata->gpio_resetb)) {
+ gpio_set_value(phy->gpio, phy->pdata->gpio_resetb, 0);
+ mdelay(1);
+ gpio_set_value(phy->gpio, phy->pdata->gpio_resetb, 1);
+ mdelay(1);
+ dev_dbg(&phy->spi->dev, "%s: by GPIO", __func__);
+ return 0;
+ }
+#else
if (gpio_is_valid(phy->pdata->gpio_resetb)) {
gpio_set_value(phy->pdata->gpio_resetb, 0);
mdelay(1);
@@ -879,6 +937,7 @@ int32_t ad9361_reset(struct ad9361_rf_phy *phy)
dev_dbg(&phy->spi->dev, "%s: by GPIO", __func__);
return 0;
}
+#endif // NUAND_MODIFICATIONS
/* SPI Soft Reset was removed from the register map, since it doesn't
* work reliably. Without a prober HW reset randomness may happen.
@@ -3378,7 +3437,17 @@ static int32_t ad9361_pp_port_setup(struct ad9361_rf_phy *phy, bool restore_c3)
ad9361_spi_write(spi, REG_RX_CLOCK_DATA_DELAY, pd->port_ctrl.rx_clk_data_delay);
ad9361_spi_write(spi, REG_TX_CLOCK_DATA_DELAY, pd->port_ctrl.tx_clk_data_delay);
+#ifdef NUAND_MODIFICATIONS
+ // set up digital interface slew and drive strength
+ ad9361_spi_write(spi, REG_LVDS_BIAS_CTRL, pd->port_ctrl.lvds_bias_ctrl | CLK_OUT_SLEW(pd->port_ctrl.clk_out_slew));
+ ad9361_spi_write(spi, REG_DIGITAL_IO_CTRL, DATACLK_SLEW(pd->port_ctrl.dataclk_slew) | DATA_PORT_SLEW(pd->port_ctrl.data_port_slew));
+ ad9361_spi_writef(spi, REG_DIGITAL_IO_CTRL, DATACLK_DRIVE, pd->port_ctrl.dataclk_drive);
+ ad9361_spi_writef(spi, REG_DIGITAL_IO_CTRL, DATA_PORT_DRIVE, pd->port_ctrl.data_port_drive);
+ ad9361_spi_writef(spi, REG_DIGITAL_IO_CTRL, CLK_OUT_DRIVE, pd->port_ctrl.clk_out_drive);
+#else
ad9361_spi_write(spi, REG_LVDS_BIAS_CTRL, pd->port_ctrl.lvds_bias_ctrl);
+#endif // NUAND_MODIFICATIONS
+
// ad9361_spi_write(spi, REG_DIGITAL_IO_CTRL, pd->port_ctrl.digital_io_ctrl);
ad9361_spi_write(spi, REG_LVDS_INVERT_CTRL1, pd->port_ctrl.lvds_invert[0]);
ad9361_spi_write(spi, REG_LVDS_INVERT_CTRL2, pd->port_ctrl.lvds_invert[1]);
@@ -4893,26 +4962,49 @@ int32_t ad9361_mcs(struct ad9361_rf_phy *phy, int32_t step)
MCS_REFCLK_SCALE_EN, 1);
break;
case 2:
+#ifdef NUAND_MODIFICATIONS
+ // use alternate gpio accessors
+ if(!gpio_is_valid(phy->gpio, phy->pdata->gpio_sync))
+ break;
+#else
if(!gpio_is_valid(phy->pdata->gpio_sync))
break;
+#endif // NUAND_MODIFICATIONS
/*
* NOTE: This is not a regular GPIO -
* HDL ensures Multi-chip Synchronization SYNC_IN Pulse Timing
* relative to rising and falling edge of REF_CLK
*/
+#ifdef NUAND_MODIFICATIONS
+ // use alternate gpio accessors
+ if(!gpio_is_valid(phy->gpio, phy->pdata->gpio_sync))
+ break;
+ gpio_set_value(phy->gpio, phy->pdata->gpio_sync, 1);
+ gpio_set_value(phy->gpio, phy->pdata->gpio_sync, 0);
+#else
gpio_set_value(phy->pdata->gpio_sync, 1);
gpio_set_value(phy->pdata->gpio_sync, 0);
break;
+#endif // NUAND_MODIFICATIONS
case 3:
ad9361_spi_writef(phy->spi, REG_MULTICHIP_SYNC_AND_TX_MON_CTRL,
mcs_mask, MCS_BB_ENABLE | MCS_DIGITAL_CLK_ENABLE | MCS_RF_ENABLE);
break;
case 4:
+#ifdef NUAND_MODIFICATIONS
+ // use alternate gpio accessors
+ if(!gpio_is_valid(phy->gpio, phy->pdata->gpio_sync))
+ break;
+ gpio_set_value(phy->gpio, phy->pdata->gpio_sync, 1);
+ gpio_set_value(phy->gpio, phy->pdata->gpio_sync, 0);
+ break;
+#else
if(!gpio_is_valid(phy->pdata->gpio_sync))
break;
gpio_set_value(phy->pdata->gpio_sync, 1);
gpio_set_value(phy->pdata->gpio_sync, 0);
break;
+#endif // NUAND_MODIFICATIONS
case 5:
ad9361_spi_writef(phy->spi, REG_MULTICHIP_SYNC_AND_TX_MON_CTRL,
mcs_mask, MCS_RF_ENABLE);
@@ -5758,10 +5850,20 @@ int32_t ad9361_validate_enable_fir(struct ad9361_rf_phy *phy)
#else
int32_t i;
uint32_t num;
+#ifdef NUAND_MODIFICATIONS
+ // fix memory overrun :x
+ num = sizeof(rx)/sizeof(rx[0]);
+#else
num = sizeof(rx);
+#endif // NUAND_MODIFICATIONS
for (i = 0; i < num; i++)
rx[i] = phy->filt_rx_path_clks[i];
+#ifdef NUAND_MODIFICATIONS
+ // fix memory overrun :x
+ num = sizeof(tx)/sizeof(tx[0]);
+#else
num = sizeof(tx);
+#endif // NUAND_MODIFICATIONS
for (i = 0; i < num; i++)
tx[i] = phy->filt_tx_path_clks[i];
#endif
diff --git a/ad9361/sw/ad9361.h b/ad9361/sw/ad9361.h
index 376978d..03aea32 100644
--- a/ad9361/sw/ad9361.h
+++ b/ad9361/sw/ad9361.h
@@ -3042,6 +3042,15 @@ struct port_control {
uint8_t digital_io_ctrl;
uint8_t lvds_bias_ctrl;
uint8_t lvds_invert[2];
+#ifdef NUAND_MODIFICATIONS
+ // add digital interface drive and clock skew
+ uint8_t clk_out_drive;
+ uint8_t dataclk_drive;
+ uint8_t data_port_drive;
+ uint8_t clk_out_slew;
+ uint8_t dataclk_slew;
+ uint8_t data_port_slew;
+#endif // NUAND_MODIFICATIONS
};
struct ctrl_outs_control {
@@ -3115,7 +3124,12 @@ enum ad9361_pdata_rx_freq {
};
enum ad9361_pdata_tx_freq {
+#ifdef NUAND_MODIFICATIONS
+ // this is a name conflict on some platforms
+ IGNORE_FREQ,
+#else
IGNORE,
+#endif // NUAND_MODIFICATIONS
DAC_FREQ,
T2_FREQ,
T1_FREQ,
@@ -3310,6 +3324,10 @@ struct ad9361_rf_phy {
enum dev_id dev_sel;
uint8_t id_no;
struct spi_device *spi;
+#ifdef NUAND_MODIFICATIONS
+ // add gpio device struct
+ struct gpio_device *gpio;
+#endif // NUAND_MODIFICATIONS
struct clk *clk_refin;
struct clk *clks[NUM_AD9361_CLKS];
struct refclk_scale *ref_clk_scale[NUM_AD9361_CLKS];
diff --git a/ad9361/sw/ad9361_api.c b/ad9361/sw/ad9361_api.c
index f565163..180315d 100644
--- a/ad9361/sw/ad9361_api.c
+++ b/ad9361/sw/ad9361_api.c
@@ -72,7 +72,12 @@ static struct axiadc_chip_info axiadc_chip_info_tbl[] =
*
* Note: This function will/may affect the data path.
*/
+#ifdef NUAND_MODIFICATIONS
+// add *userdata parameter
+int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_param, void *userdata)
+#else
int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_param)
+#endif // NUAND_MODIFICATIONS
{
struct ad9361_rf_phy *phy;
int32_t ret = 0;
@@ -89,6 +94,14 @@ int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_p
return -ENOMEM;
}
+#ifdef NUAND_MODIFICATIONS
+ // allocate gpio struct
+ phy->gpio = (struct gpio_device *)zmalloc(sizeof(*phy->gpio));
+ if (!phy->gpio) {
+ return -ENOMEM;
+ }
+#endif // NUAND_MODIFICATIONS
+
phy->clk_refin = (struct clk *)zmalloc(sizeof(*phy->clk_refin));
if (!phy->clk_refin) {
return -ENOMEM;
@@ -111,6 +124,15 @@ int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_p
phy->adc_state->phy = phy;
#endif
+#ifdef NUAND_MODIFICATIONS
+ /* Ensure phy->clks and phy->ref_clk_scale are adequately nulled */
+ for (size_t i = 0; i < NUM_AD9361_CLKS; ++i) {
+ phy->clks[i] = NULL;
+ phy->ref_clk_scale[i] = NULL;
+ }
+ phy->clk_data.clks = NULL;
+#endif // NUAND_MODIFICATIONS
+
/* Device selection */
phy->dev_sel = init_param->dev_sel;
@@ -338,6 +360,16 @@ int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_p
phy->pdata->port_ctrl.lvds_bias_ctrl |= (init_param->lvds_rx_onchip_termination_enable << 5);
phy->pdata->rx1rx2_phase_inversion_en = init_param->rx1rx2_phase_inversion_en;
+#ifdef NUAND_MODIFICATIONS
+ // settings for digital interface drive and slew
+ phy->pdata->port_ctrl.clk_out_drive = init_param->clk_out_drive & 0x1;
+ phy->pdata->port_ctrl.dataclk_drive = init_param->dataclk_drive & 0x1;
+ phy->pdata->port_ctrl.data_port_drive = init_param->data_port_drive & 0x1;
+ phy->pdata->port_ctrl.clk_out_slew = init_param->clk_out_slew & 0x3;
+ phy->pdata->port_ctrl.dataclk_slew = init_param->dataclk_slew & 0x3;
+ phy->pdata->port_ctrl.data_port_slew = init_param->data_port_slew & 0x3;
+#endif // NUAND_MODIFICATIONS
+
/* GPO Control */
phy->pdata->gpo_ctrl.gpo0_inactive_state_high_en = init_param->gpo0_inactive_state_high_enable;
phy->pdata->gpo_ctrl.gpo1_inactive_state_high_en = init_param->gpo1_inactive_state_high_enable;
@@ -407,11 +439,28 @@ int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_p
phy->bist_tone_level_dB = 0;
phy->bist_tone_mask = 0;
+#ifdef NUAND_MODIFICATIONS
+ // initialize SPI and GPIO
+ ret = spi_init(phy, userdata);
+ if (ret < 0) {
+ goto out;
+ }
+
+ ret = gpio_init(phy, userdata);
+ if (ret < 0) {
+ goto out;
+ }
+#endif // NUAND_MODIFICATIONS
+
ad9361_reset(phy);
ret = ad9361_spi_read(phy->spi, REG_PRODUCT_ID);
if ((ret & PRODUCT_ID_MASK) != PRODUCT_ID_9361) {
printf("%s : Unsupported PRODUCT_ID 0x%X", __func__, (unsigned int)ret);
+#ifdef NUAND_MODIFICATIONS
+ // this missing newline, so help me god...
+ printf("\n");
+#endif // NUAND_MODIFICATIONS
ret = -ENODEV;
goto out;
}
@@ -432,8 +481,16 @@ int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_p
goto out;
#ifndef AXI_ADC_NOT_PRESENT
+#ifdef NUAND_MODIFICATIONS
+ // use alternate axiadc accessors
+ axiadc_init(phy, userdata);
+ ret = axiadc_read(phy->adc_state, ADI_REG_VERSION, &(phy->adc_state->pcore_version));
+ if (ret < 0)
+ goto out;
+#else
axiadc_init(phy);
phy->adc_state->pcore_version = axiadc_read(phy->adc_state, ADI_REG_VERSION);
+#endif // NUAND_MODIFICATIONS
#endif
ad9361_init_gain_tables(phy);
@@ -449,7 +506,10 @@ int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_p
goto out;
#endif
+#ifndef NUAND_MODIFICATIONS
+ // reduce console noise
printf("%s : AD936x Rev %d successfully initialized\n", __func__, (int)rev);
+#endif // !NUAND_MODIFICATIONS
*ad9361_phy = phy;
@@ -463,12 +523,60 @@ out:
#endif
free(phy->clk_refin);
free(phy->pdata);
+
+#ifdef NUAND_MODIFICATIONS
+ // free gpio struct, and also the clock stuff
+ free(phy->gpio);
+ free(phy->clk_data.clks);
+ for (size_t i = 0; i < NUM_AD9361_CLKS; ++i) {
+ free(phy->clks[i]);
+ free(phy->ref_clk_scale[i]);
+ }
+#endif // NUAND_MODIFICATIONS
+
free(phy);
printf("%s : AD936x initialization error\n", __func__);
return -ENODEV;
}
+#ifdef NUAND_MODIFICATIONS
+/**
+ * Deinitialize the AD9361 part.
+ * @return 0 in case of success, negative error code otherwise.
+ */
+int32_t ad9361_deinit (struct ad9361_rf_phy *phy)
+{
+ if (phy) {
+ /* Put AD9361 part into reset */
+ if (gpio_is_valid(phy->gpio, phy->pdata->gpio_resetb)) {
+ gpio_set_value(phy->gpio, phy->pdata->gpio_resetb, 0);
+ }
+ }
+
+ if (phy) {
+ free(phy->spi);
+ free(phy->gpio);
+#ifndef AXI_ADC_NOT_PRESENT
+ free(phy->adc_conv);
+ free(phy->adc_state);
+#endif
+ free(phy->clk_refin);
+ free(phy->clk_data.clks);
+ free(phy->pdata);
+
+ for (size_t i = 0; i < NUM_AD9361_CLKS; ++i) {
+ free(phy->clks[i]);
+ free(phy->ref_clk_scale[i]);
+ }
+
+ free(phy);
+ }
+
+ return 0;
+}
+#endif // NUAND_MODIFICATIONS
+
/**
* Set the Enable State Machine (ENSM) mode.
* @param phy The AD9361 current state structure.
@@ -1797,8 +1905,14 @@ int32_t ad9361_set_no_ch_mode(struct ad9361_rf_phy *phy, uint8_t no_ch_mode)
phy->clks[TX_RFPLL]->rate = ad9361_rfpll_recalc_rate(phy->ref_clk_scale[TX_RFPLL]);
#ifndef AXI_ADC_NOT_PRESENT
+#ifdef NUAND_MODIFICATIONS
+ // use alternate axiadc accessors
+ axiadc_init(phy, phy->adc_state->userdata);
+#else
axiadc_init(phy);
+#endif // NUAND_MODIFICATIONS
#endif
+
ad9361_setup(phy);
#ifndef AXI_ADC_NOT_PRESENT
/* platform specific wrapper to call ad9361_post_setup() */
diff --git a/ad9361/sw/ad9361_api.h b/ad9361/sw/ad9361_api.h
index 77ffa44..ff5d7c5 100644
--- a/ad9361/sw/ad9361_api.h
+++ b/ad9361/sw/ad9361_api.h
@@ -240,6 +240,15 @@ typedef struct
uint8_t rx1rx2_phase_inversion_en; /* adi,rx1-rx2-phase-inversion-enable */
uint8_t lvds_invert1_control; /* adi,lvds-invert1-control */
uint8_t lvds_invert2_control; /* adi,lvds-invert2-control */
+#ifdef NUAND_MODIFICATIONS
+ // add digital interface drive and clock slew
+ uint8_t clk_out_drive;
+ uint8_t dataclk_drive;
+ uint8_t data_port_drive;
+ uint8_t clk_out_slew;
+ uint8_t dataclk_slew;
+ uint8_t data_port_slew;
+#endif // NUAND_MODIFICATIONS
/* GPO Control */
uint8_t gpo0_inactive_state_high_enable; /* adi,gpo0-inactive-state-high-enable */
uint8_t gpo1_inactive_state_high_enable; /* adi,gpo1-inactive-state-high-enable */
@@ -355,8 +364,15 @@ enum ad9361_ensm_mode {
/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/
+#ifdef NUAND_MODIFICATIONS
+/* Initialize the AD9361 part. */
+int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_param, void *userdata);
+/* Deinitialize the AD9361 part. */
+int32_t ad9361_deinit (struct ad9361_rf_phy *phy);
+#else
/* Initialize the AD9361 part. */
int32_t ad9361_init (struct ad9361_rf_phy **ad9361_phy, AD9361_InitParam *init_param);
+#endif // NUAND_MODIFICATIONS
/* Set the Enable State Machine (ENSM) mode. */
int32_t ad9361_set_en_state_machine_mode (struct ad9361_rf_phy *phy, uint32_t mode);
/* Get the Enable State Machine (ENSM) mode. */
diff --git a/ad9361/sw/ad9361_conv.c b/ad9361/sw/ad9361_conv.c
index b20cb71..0491f91 100644
--- a/ad9361/sw/ad9361_conv.c
+++ b/ad9361/sw/ad9361_conv.c
@@ -59,7 +59,18 @@ int32_t ad9361_hdl_loopback(struct ad9361_rf_phy *phy, bool enable)
struct axiadc_state *st = phy->adc_state;
int32_t reg, addr, chan;
+#ifdef NUAND_MODIFICATIONS
+ int ret;
+ uint32_t readval;
+
+ ret = axiadc_read(st, 0x4000, &readval);
+ if (ret < 0)
+ return ret;
+
+ uint32_t version = readval;
+#else
uint32_t version = axiadc_read(st, 0x4000);
+#endif // NUAND_MODIFICATIONS
/* Still there but implemented a bit different */
if (PCORE_VERSION_MAJOR(version) > 7)
@@ -68,7 +79,15 @@ int32_t ad9361_hdl_loopback(struct ad9361_rf_phy *phy, bool enable)
addr = 0x4414;
for (chan = 0; chan < conv->chip_info->num_channels; chan++) {
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_read(st, addr + (chan) * 0x40, &readval);
+ if (ret < 0)
+ return ret;
+
+ reg = (int32_t)readval;
+#else
reg = axiadc_read(st, addr + (chan) * 0x40);
+#endif // NUAND_MODIFICATIONS
if (PCORE_VERSION_MAJOR(version) > 7) {
if (enable && reg != 0x8) {
@@ -156,10 +175,23 @@ static int32_t ad9361_dig_tune_iodelay(struct ad9361_rf_phy *phy, bool tx)
ADI_PN_ERR | ADI_PN_OOS);
mdelay(10);
+#ifdef NUAND_MODIFICATIONS
+ uint32_t stat, tmp;
+
+ for (chan = 0, stat = 0; chan < num_chan; chan++) {
+ ret = axiadc_read(st, ADI_REG_CHAN_STATUS(chan), &tmp);
+ if (ret < 0)
+ return ret;
+ stat |= tmp;
+ }
+ field[j] = stat;
+#else
+
for (chan = 0, ret = 0; chan < num_chan; chan++)
ret |= axiadc_read(st, ADI_REG_CHAN_STATUS(chan));
field[j] = ret;
+#endif // NUAND_MODIFICATIONS
}
c0 = ad9361_find_opt(&field[0], 32, &s0);
@@ -233,6 +265,23 @@ int32_t ad9361_dig_interface_timing_analysis(struct ad9361_rf_phy *phy,
mdelay(1);
+#ifdef NUAND_MODIFICATIONS
+ uint32_t tmp, stat;
+ ret = axiadc_read(st, ADI_REG_STATUS, &stat);
+ if (ret < 0)
+ return ret;
+
+ if (stat & ADI_STATUS) {
+ for (chan = 0, stat = 0; chan < 4; chan++) {
+ ret = axiadc_read(st, ADI_REG_CHAN_STATUS(chan), &tmp);
+ if (ret < 0)
+ return ret;
+ stat |= tmp;
+ }
+ } else {
+ stat = 1;
+ }
+#else
if (axiadc_read(st, ADI_REG_STATUS) & ADI_STATUS) {
for (chan = 0, ret = 0; chan < 4; chan++)
ret |= axiadc_read(st, ADI_REG_CHAN_STATUS(chan));
@@ -240,6 +289,7 @@ int32_t ad9361_dig_interface_timing_analysis(struct ad9361_rf_phy *phy,
else {
ret = 1;
}
+#endif // NUAND_MODIFICATIONS
field[i][j] = ret;
}
@@ -291,7 +341,13 @@ int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
dev_dbg(&phy->spi->dev, "%s: freq %"PRIu32" flags 0x%X\n", __func__,
max_freq, flags);
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_read(st, 0x4000, &hdl_dac_version);
+ if (ret < 0)
+ return ret;
+#else
hdl_dac_version = axiadc_read(st, 0x4000);
+#endif // NUAND_MODIFICATIONS
if ((phy->pdata->dig_interface_tune_skipmode == 2) ||
(flags & RESTORE_DEFAULT)) {
@@ -345,6 +401,25 @@ int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
ADI_PN_ERR | ADI_PN_OOS);
mdelay(4);
+#ifdef NUAND_MODIFICATIONS
+ uint32_t stat;
+ ret = axiadc_read(st, ADI_REG_STATUS, &stat);
+ if (ret < 0)
+ return ret;
+
+ if ((t == 1) || (stat & ADI_STATUS)) {
+ for (chan = 0, stat = 0; chan < num_chan; chan++) {
+ ret = axiadc_read(st, ADI_REG_CHAN_STATUS(chan), &tmp);
+ if (ret < 0)
+ return ret;
+ stat |= tmp;
+ }
+ } else {
+ stat = 1;
+ }
+
+ field[i][j] |= stat;
+#else
if ((t == 1) || (axiadc_read(st, ADI_REG_STATUS) & ADI_STATUS)) {
for (chan = 0, ret = 0; chan < num_chan; chan++) {
ret |= axiadc_read(st, ADI_REG_CHAN_STATUS(chan));
@@ -355,6 +430,7 @@ int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
}
field[i][j] |= ret;
+#endif // NUAND_MODIFICATIONS
}
}
if ((flags & BE_MOREVERBOSE) && max_freq) {
@@ -414,6 +490,48 @@ int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
axiadc_write(st, 0x4000 + ADI_REG_RSTN, ADI_RSTN | ADI_MMCM_RSTN);
for (chan = 0; chan < num_chan; chan++) {
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_read(st, ADI_REG_CHAN_CNTRL(chan), &saved_chan_ctrl0[chan]);
+ if (ret < 0)
+ return ret;
+
+ ret = axiadc_write(st, ADI_REG_CHAN_CNTRL(chan),
+ ADI_FORMAT_SIGNEXT | ADI_FORMAT_ENABLE |
+ ADI_ENABLE | ADI_IQCOR_ENB);
+ if (ret < 0)
+ return ret;
+
+ ret = axiadc_set_pnsel(st, chan, ADC_PN_CUSTOM);
+ if (ret < 0)
+ return ret;
+
+ ret = axiadc_read(st, 0x4414 + (chan) * 0x40, &saved_chan_ctrl6[chan]);
+ if (ret < 0)
+ return ret;
+
+ if (PCORE_VERSION_MAJOR(hdl_dac_version) > 7)
+ {
+ ret = axiadc_read(st, 0x4418 + (chan) * 0x40, &saved_dsel[chan]);
+ if (ret < 0)
+ return ret;
+
+ ret = axiadc_write(st, 0x4418 + (chan) * 0x40, 9);
+ if (ret < 0)
+ return ret;
+
+ ret = axiadc_write(st, 0x4414 + (chan) * 0x40, 0); /* !IQCOR_ENB */
+ if (ret < 0)
+ return ret;
+
+ ret = axiadc_write(st, 0x4044, 0x1);
+ if (ret < 0)
+ return ret;
+ } else {
+ ret = axiadc_write(st, 0x4414 + (chan) * 0x40, 1); /* DAC_PN_ENB */
+ if (ret < 0)
+ return ret;
+ }
+#else
saved_chan_ctrl0[chan] = axiadc_read(st, ADI_REG_CHAN_CNTRL(chan));
axiadc_write(st, ADI_REG_CHAN_CNTRL(chan),
ADI_FORMAT_SIGNEXT | ADI_FORMAT_ENABLE |
@@ -429,10 +547,18 @@ int32_t ad9361_dig_tune(struct ad9361_rf_phy *phy, uint32_t max_freq,
}
else
axiadc_write(st, 0x4414 + (chan) * 0x40, 1); /* DAC_PN_ENB */
-
+#endif // NUAND_MODIFICATIONS
}
if (PCORE_VERSION_MAJOR(hdl_dac_version) < 8) {
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_read(st, 0x4048, &tmp);
+ if (ret < 0)
+ return ret;
+
+ saved = tmp;
+#else
saved = tmp = axiadc_read(st, 0x4048);
+#endif // NUAND_MODIFICATIONS
tmp &= ~0xF;
tmp |= 1;
axiadc_write(st, 0x4048, tmp);
@@ -508,8 +634,21 @@ int32_t ad9361_post_setup(struct ad9361_rf_phy *phy)
num_chan = (conv->chip_info->num_channels > 4) ? 4 : conv->chip_info->num_channels;
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_write(st, ADI_REG_CNTRL, rx2tx2 ? 0 : ADI_R1_MODE);
+ if (ret < 0)
+ return ret;
+
+ uint32_t u32tmp;
+ ret = axiadc_read(st, 0x4048, &u32tmp);
+ if (ret < 0)
+ return ret;
+
+ tmp = (int32_t)u32tmp;
+#else
axiadc_write(st, ADI_REG_CNTRL, rx2tx2 ? 0 : ADI_R1_MODE);
tmp = axiadc_read(st, 0x4048);
+#endif // NUAND_MODIFICATIONS
if (!rx2tx2) {
axiadc_write(st, 0x4048, tmp | BIT(5)); /* R1_MODE */
@@ -539,14 +678,29 @@ int32_t ad9361_post_setup(struct ad9361_rf_phy *phy)
flags = 0x0;
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_read(st, 0x0004, &u32tmp);
+ if (ret < 0)
+ return ret;
+ ret = ad9361_dig_tune(phy, ((conv->chip_info->num_channels > 4) ||
+ u32tmp) ? 0 : 61440000, flags);
+#else
ret = ad9361_dig_tune(phy, ((conv->chip_info->num_channels > 4) ||
axiadc_read(st, 0x0004)) ? 0 : 61440000, flags);
+#endif // NUAND_MODIFICATIONS
if (ret < 0)
return ret;
if (flags & (DO_IDELAY | DO_ODELAY)) {
+#ifdef NUAND_MODIFICATIONS
+ ret = axiadc_read(st, ADI_REG_ID, &u32tmp);
+ if (ret < 0)
+ return ret;
+ ret = ad9361_dig_tune(phy, u32tmp ? 0 : 61440000, flags & BE_VERBOSE);
+#else
ret = ad9361_dig_tune(phy, (axiadc_read(st, ADI_REG_ID)) ?
0 : 61440000, flags & BE_VERBOSE);
+#endif // NUAND_MODIFICATIONS
if (ret < 0)
return ret;
}
diff --git a/ad9361/sw/common.h b/ad9361/sw/common.h
index bd4b7f7..b140494 100644
--- a/ad9361/sw/common.h
+++ b/ad9361/sw/common.h
@@ -47,6 +47,10 @@
/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
+#ifdef NUAND_MODIFICATIONS
+// just use errno
+#include <errno.h>
+#else
#define EIO 5 /* I/O error */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
@@ -54,15 +58,22 @@
#define ENODEV 19 /* No such device */
#define EINVAL 22 /* Invalid argument */
#define ETIMEDOUT 110 /* Connection timed out */
+#endif // NUAND_MODIFICATIONS
/******************************************************************************/
/*************************** Types Declarations *******************************/
/******************************************************************************/
+
+#ifdef NUAND_MODIFICATIONS
+// just use stdbool
+#include <stdbool.h>
+#else
#if defined (__STDC__) && (__STDC_VERSION__ >= 199901L)
#include <stdbool.h>
#else
typedef enum { false, true } bool;
#endif
+#endif // NUAND_MODIFICATIONS
struct clk {
const char *name;
diff --git a/ad9361/sw/config.h b/ad9361/sw/config.h
index 3997bd5..37c9da8 100644
--- a/ad9361/sw/config.h
+++ b/ad9361/sw/config.h
@@ -39,6 +39,12 @@
#ifndef CONFIG_H_
#define CONFIG_H_
+// BEGIN Nuand modification
+#ifndef NUAND_MODIFICATIONS
+#define NUAND_MODIFICATIONS
+#endif // !NUAND_MODIFICATIONS
+// END Nuand modification
+
#define HAVE_VERBOSE_MESSAGES /* Recommended during development prints errors and warnings */
//#define HAVE_DEBUG_MESSAGES /* For Debug purposes only */
@@ -64,4 +70,11 @@
//#define AXI_ADC_NOT_PRESENT
//#define TDD_SWITCH_STATE_EXAMPLE
+#ifdef NUAND_MODIFICATIONS
+#define ALTERA_PLATFORM
+#ifdef AD9361_DEBUG
+#define _DEBUG
+#endif // AD9361_DEBUG
+#endif // NUAND_MODIFICATIONS
+
#endif
diff --git a/ad9361/sw/util.h b/ad9361/sw/util.h
index 3c88529..f4f7385 100644
--- a/ad9361/sw/util.h
+++ b/ad9361/sw/util.h
@@ -50,12 +50,24 @@
#include "common.h"
#include "config.h"
+#ifdef NUAND_MODIFICATIONS
+// include adc/dac core headers
+#include "adc_core.h"
+#include "dac_core.h"
+#endif // NUAND_MODIFICATIONS
/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
#define SUCCESS 0
+#ifdef NUAND_MODIFICATIONS
+// guard on ARRAY_SIZE (already defined in libbladeRF)
+#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif
+#else
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#endif // NUAND_MODIFICATIONS
#define min(x, y) (((x) < (y)) ? (x) : (y))
#define min_t(type, x, y) (type)min((type)(x), (type)(y))
#define max(x, y) (((x) > (y)) ? (x) : (y))
@@ -68,6 +80,24 @@
#define CLK_IGNORE_UNUSED BIT(3)
#define CLK_GET_RATE_NOCACHE BIT(6)
+#ifdef NUAND_MODIFICATIONS
+// Fix a whole slew of MSVC compiler errors...
+#if defined(HAVE_VERBOSE_MESSAGES)
+#define dev_err(dev, format, ...) {printf(format, ## __VA_ARGS__);printf("\n"); }
+#define dev_warn(dev, format, ...) {printf(format, ## __VA_ARGS__);printf("\n"); }
+#if defined(HAVE_DEBUG_MESSAGES)
+#define dev_dbg(dev, format, ...) {printf(format, ## __VA_ARGS__);printf("\n"); }
+#else
+#define dev_dbg(dev, format, ...) { if (0) printf(format, ## __VA_ARGS__); }
+#endif
+#define printk(format, ...) printf(format, ## __VA_ARGS__)
+#else
+#define dev_err(dev, format, ...) { if (0) printf(format, ## __VA_ARGS__); }
+#define dev_warn(dev, format, ...) { if (0) printf(format, ## __VA_ARGS__); }
+#define dev_dbg(dev, format, ...) { if (0) printf(format, ## __VA_ARGS__); }
+#define printk(format, ...) { if (0) printf(format, ## __VA_ARGS__); }
+#endif
+#else
#if defined(HAVE_VERBOSE_MESSAGES)
#define dev_err(dev, format, ...) ({printf(format, ## __VA_ARGS__);printf("\n"); })
#define dev_warn(dev, format, ...) ({printf(format, ## __VA_ARGS__);printf("\n"); })
@@ -83,18 +113,39 @@
#define dev_dbg(dev, format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
#define printk(format, ...) ({ if (0) printf(format, ## __VA_ARGS__); })
#endif
+#endif // NUAND_MODIFICATIONS
struct device {
+#ifdef NUAND_MODIFICATIONS
+ // fix MSVC code C2016
+ void *noop;
+#endif // NUAND_MODIFICATIONS
};
struct spi_device {
struct device dev;
uint8_t id_no;
+#ifdef NUAND_MODIFICATIONS
+ // add userdata field
+ void *userdata;
+#endif // NUAND_MODIFICATIONS
+};
+
+#ifdef NUAND_MODIFICATIONS
+// gpio_device struct
+struct gpio_device {
+ void *userdata;
};
+#endif // NUAND_MODIFICATIONS
struct axiadc_state {
struct ad9361_rf_phy *phy;
uint32_t pcore_version;
+#ifdef NUAND_MODIFICATIONS
+ // add DAC DDS state, userdata
+ struct dds_state dac_dds_state;
+ void *userdata;
+#endif // NUAND_MODIFICATIONS
};
struct axiadc_chip_info {

View file

@ -0,0 +1,16 @@
diff --git a/host/libraries/libbladeRF/src/driver/thirdparty/adi/ad9361.c b/host/libraries/libbladeRF/src/driver/thirdparty/adi/ad9
361.c
index 49a79cc6..2cd3d26d 100644
--- a/ad9361/sw/ad9361.c
+++ b/ad9361/sw/ad9361.c
@@ -39,7 +39,10 @@
/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
+#include "host_config.h"
+#if 0 == BLADERF_OS_FREEBSD
#include <malloc.h>
+#endif // BLADERF_OS_FREEBSD
#include <limits.h>
#include <stdint.h>
#include <stdio.h>

View file

@ -0,0 +1,12 @@
--- a/ad9361/sw/util.c 2018-10-10 13:49:03.308273015 -0400
+++ b/ad9361/sw/util.c 2018-10-10 13:51:59.641443929 -0400
@@ -329,7 +329,8 @@
*******************************************************************************/
void * ERR_PTR(long error)
{
- return (void *) error;
+ uintptr_t val = error;
+ return (void *) val;
}
/***************************************************************************//**

View file

@ -0,0 +1,13 @@
diff --git a/host/libraries/libbladeRF/src/driver/thirdparty/adi/ad9361.h b/host/libraries/libbladeRF/src/driver/thirdparty/adi/ad9361.h
index 71b19ff8..f97bc3c9 100644
--- a/ad9361/sw/ad9361.h
+++ b/ad9361/sw/ad9361.h
@@ -2843,7 +2843,7 @@
#define MIN_SYNTH_FREF 10000000UL /* 10 MHz */
#define MIN_VCO_FREQ_HZ 6000000000ULL
#define MAX_CARRIER_FREQ_HZ 6000000000ULL
-#define MIN_CARRIER_FREQ_HZ 70000000ULL
+#define MIN_CARRIER_FREQ_HZ 47000000ULL /* Nuand modification */
#define AD9363A_MAX_CARRIER_FREQ_HZ 3800000000ULL
#define AD9363A_MIN_CARRIER_FREQ_HZ 325000000ULL

View file

@ -0,0 +1,18 @@
--- a/ad9361/sw/ad9361.c 2018-10-11 13:41:55.693429324 -0400
+++ b/ad9361/sw/ad9361.c 2018-10-11 15:23:09.688625891 -0400
@@ -5614,6 +5614,7 @@
return ad9361_verify_fir_filter_coef(phy, dest, ntaps, coef);
}
+#ifndef NUAND_MODIFICATIONS
/**
* Parse the FIR filter file/buffer.
* @param phy The AD9361 state structure.
@@ -5785,6 +5786,7 @@
return size;
}
+#endif // !NUAND_MODIFICATIONS
/**
* Validate FIR filter configuration - on pass enable.

View file

@ -0,0 +1,16 @@
diff --git a/host/libraries/libbladeRF/src/driver/thirdparty/adi/ad9361.c b/host/libraries/libbladeRF/src/driver/thirdparty/adi/ad9361.c
index 2cd3d26d..b3b5a1bb 100644
--- a/ad9361/sw/ad9361.c
+++ b/ad9361/sw/ad9361.c
@@ -40,9 +40,9 @@
/***************************** Include Files **********************************/
/******************************************************************************/
#include "host_config.h"
-#if 0 == BLADERF_OS_FREEBSD
+#if !defined(BLADERF_OS_FREEBSD) && !defined(BLADERF_OS_OSX)
#include <malloc.h>
-#endif // BLADERF_OS_FREEBSD
+#endif // BLADERF_OS_FREEBSD + BLADERF_OS_OSX
#include <limits.h>
#include <stdint.h>
#include <stdio.h>

View file

@ -0,0 +1,712 @@
#include "ad9361_api.h"
#include "platform.h"
/**
* Reference:
* https://wiki.analog.com/resources/tools-software/linux-drivers/iio-transceiver/ad9361-customization
*
* N/A = not applicable due to other setting; changes may unmask these
* DEFAULT = changed during device initialization
*/
AD9361_InitParam bladerf2_rfic_init_params = {
/* Device selection */
ID_AD9361, // AD9361 RF Agile Transceiver // dev_sel
/* Identification number */
0, // Chip ID 0 // id_no
/* Reference Clock */
38400000UL, // RefClk = 38.4 MHz // reference_clk_rate
/* Base Configuration */
1, // use 2Rx2Tx mode // two_rx_two_tx_mode_enable *** adi,2rx-2tx-mode-enable
1, // N/A when two_rx_two_tx_mode_enable = 1 // one_rx_one_tx_mode_use_rx_num *** adi,1rx-1tx-mode-use-rx-num
1, // N/A when two_rx_two_tx_mode_enable = 1 // one_rx_one_tx_mode_use_tx_num *** adi,1rx-1tx-mode-use-tx-num
1, // use FDD mode // frequency_division_duplex_mode_enable *** adi,frequency-division-duplex-mode-enable
1, // use independent FDD mode // frequency_division_duplex_independent_mode_enable *** adi,frequency-division-duplex-independent-mode-enable
0, // N/A when frequency_division_duplex_mode_enable = 1 // tdd_use_dual_synth_mode_enable *** adi,tdd-use-dual-synth-mode-enable
0, // N/A when frequency_division_duplex_mode_enable = 1 // tdd_skip_vco_cal_enable *** adi,tdd-skip-vco-cal-enable
0, // TX fastlock delay = 0 ns // tx_fastlock_delay_ns *** adi,tx-fastlock-delay-ns
0, // RX fastlock delay = 0 ns // rx_fastlock_delay_ns *** adi,rx-fastlock-delay-ns
0, // RX fastlock pin control disabled // rx_fastlock_pincontrol_enable *** adi,rx-fastlock-pincontrol-enable
0, // TX fastlock pin control disabled // tx_fastlock_pincontrol_enable *** adi,tx-fastlock-pincontrol-enable
0, // use internal RX LO // external_rx_lo_enable *** adi,external-rx-lo-enable
0, // use internal TX LO // external_tx_lo_enable *** adi,external-tx-lo-enable
5, // apply new tracking word: on gain change, after exiting RX state // dc_offset_tracking_update_event_mask *** adi,dc-offset-tracking-update-event-mask
6, // atten value for DC tracking, RX LO > 4 GHz // dc_offset_attenuation_high_range *** adi,dc-offset-attenuation-high-range
5, // atten value for DC tracking, RX LO < 4 GHz // dc_offset_attenuation_low_range *** adi,dc-offset-attenuation-low-range
0x28, // loop gain for DC tracking, RX LO > 4 GHz // dc_offset_count_high_range *** adi,dc-offset-count-high-range
0x32, // loop gain for DC tracking, RX LO < 4 GHz // dc_offset_count_low_range *** adi,dc-offset-count-low-range
0, // use full gain table // split_gain_table_mode_enable *** adi,split-gain-table-mode-enable
MAX_SYNTH_FREF, // f_ref window 80 MHz // trx_synthesizer_target_fref_overwrite_hz *** adi,trx-synthesizer-target-fref-overwrite-hz
0, // don't use improved RX QEC tracking // qec_tracking_slow_mode_enable *** adi,qec-tracking-slow-mode-enable
/* ENSM Control */
0, // use level mode on ENABLE and TXNRX pins // ensm_enable_pin_pulse_mode_enable *** adi,ensm-enable-pin-pulse-mode-enable
0, // use SPI writes for ENSM state, not ENABLE/TXNRX pins // ensm_enable_txnrx_control_enable *** adi,ensm-enable-txnrx-control-enable
/* LO Control */
2400000000UL, // DEFAULT // rx_synthesizer_frequency_hz *** adi,rx-synthesizer-frequency-hz
2400000000UL, // DEFAULT // tx_synthesizer_frequency_hz *** adi,tx-synthesizer-frequency-hz
/* Rate & BW Control */
{ 983040000, 245760000, 122880000, 61440000, 30720000, 30720000 }, // DEFAULT // uint32_t rx_path_clock_frequencies[6] *** adi,rx-path-clock-frequencies
{ 983040000, 122880000, 122880000, 61440000, 30720000, 30720000 }, // DEFAULT // uint32_t tx_path_clock_frequencies[6] *** adi,tx-path-clock-frequencies
18000000, // DEFAULT // rf_rx_bandwidth_hz *** adi,rf-rx-bandwidth-hz
18000000, // DEFAULT // rf_tx_bandwidth_hz *** adi,rf-tx-bandwidth-hz
/* RF Port Control */
0, // DEFAULT // rx_rf_port_input_select *** adi,rx-rf-port-input-select
0, // DEFAULT // tx_rf_port_input_select *** adi,tx-rf-port-input-select
/* TX Attenuation Control */
10000, // DEFAULT // tx_attenuation_mdB *** adi,tx-attenuation-mdB
0, // N/A when frequency_division_duplex_mode_enable = 1 // update_tx_gain_in_alert_enable *** adi,update-tx-gain-in-alert-enable
/* Reference Clock Control */
1, // Expect external clock into XTALN // xo_disable_use_ext_refclk_enable *** adi,xo-disable-use-ext-refclk-enable
{3, 5920}, // ~0 ppm DCXO trim (N/A if ext clk) // dcxo_coarse_and_fine_tune[2] *** adi,dcxo-coarse-and-fine-tune
CLKOUT_DISABLE, // disable clkout pin (see enum ad9361_clkout) // clk_output_mode_select *** adi,clk-output-mode-select
/* Gain Control */
RF_GAIN_SLOWATTACK_AGC, // RX1 BLADERF_GAIN_DEFAULT = slow attack AGC // gc_rx1_mode *** adi,gc-rx1-mode
RF_GAIN_SLOWATTACK_AGC, // RX2 BLADERF_GAIN_DEFAULT = slow attack AGC // gc_rx2_mode *** adi,gc-rx2-mode
58, // magic AGC setting, see AD9361 docs // gc_adc_large_overload_thresh *** adi,gc-adc-large-overload-thresh
4, // magic AGC setting, see AD9361 docs // gc_adc_ovr_sample_size *** adi,gc-adc-ovr-sample-size
47, // magic AGC setting, see AD9361 docs // gc_adc_small_overload_thresh *** adi,gc-adc-small-overload-thresh
8192, // magic AGC setting, see AD9361 docs // gc_dec_pow_measurement_duration *** adi,gc-dec-pow-measurement-duration
0, // magic AGC setting, see AD9361 docs // gc_dig_gain_enable *** adi,gc-dig-gain-enable
800, // magic AGC setting, see AD9361 docs // gc_lmt_overload_high_thresh *** adi,gc-lmt-overload-high-thresh
704, // magic AGC setting, see AD9361 docs // gc_lmt_overload_low_thresh *** adi,gc-lmt-overload-low-thresh
24, // magic AGC setting, see AD9361 docs // gc_low_power_thresh *** adi,gc-low-power-thresh
15, // magic AGC setting, see AD9361 docs // gc_max_dig_gain *** adi,gc-max-dig-gain
/* Gain MGC Control */
2, // N/A when mgc_rx(1,2)_ctrl_inp_enable = 0 // mgc_dec_gain_step *** adi,mgc-dec-gain-step
2, // N/A when mgc_rx(1,2)_ctrl_inp_enable = 0 // mgc_inc_gain_step *** adi,mgc-inc-gain-step
0, // don't use CTRL_IN for RX1 MGC stepping // mgc_rx1_ctrl_inp_enable *** adi,mgc-rx1-ctrl-inp-enable
0, // don't use CTRL_IN for RX2 MGC stepping // mgc_rx2_ctrl_inp_enable *** adi,mgc-rx2-ctrl-inp-enable
0, // N/A when mgc_rx(1,2)_ctrl_inp_enable = 0 // mgc_split_table_ctrl_inp_gain_mode *** adi,mgc-split-table-ctrl-inp-gain-mode
/* Gain AGC Control */
10, // magic AGC setting, see AD9361 docs // agc_adc_large_overload_exceed_counter *** adi,agc-adc-large-overload-exceed-counter
2, // magic AGC setting, see AD9361 docs // agc_adc_large_overload_inc_steps *** adi,agc-adc-large-overload-inc-steps
0, // magic AGC setting, see AD9361 docs // agc_adc_lmt_small_overload_prevent_gain_inc_enable *** adi,agc-adc-lmt-small-overload-prevent-gain-inc-enable
10, // magic AGC setting, see AD9361 docs // agc_adc_small_overload_exceed_counter *** adi,agc-adc-small-overload-exceed-counter
4, // magic AGC setting, see AD9361 docs // agc_dig_gain_step_size *** adi,agc-dig-gain-step-size
3, // magic AGC setting, see AD9361 docs // agc_dig_saturation_exceed_counter *** adi,agc-dig-saturation-exceed-counter
1000, // magic AGC setting, see AD9361 docs // agc_gain_update_interval_us *** adi,agc-gain-update-interval-us
0, // magic AGC setting, see AD9361 docs // agc_immed_gain_change_if_large_adc_overload_enable *** adi,agc-immed-gain-change-if-large-adc-overload-enable
0, // magic AGC setting, see AD9361 docs // agc_immed_gain_change_if_large_lmt_overload_enable *** adi,agc-immed-gain-change-if-large-lmt-overload-enable
10, // magic AGC setting, see AD9361 docs // agc_inner_thresh_high *** adi,agc-inner-thresh-high
1, // magic AGC setting, see AD9361 docs // agc_inner_thresh_high_dec_steps *** adi,agc-inner-thresh-high-dec-steps
12, // magic AGC setting, see AD9361 docs // agc_inner_thresh_low *** adi,agc-inner-thresh-low
1, // magic AGC setting, see AD9361 docs // agc_inner_thresh_low_inc_steps *** adi,agc-inner-thresh-low-inc-steps
10, // magic AGC setting, see AD9361 docs // agc_lmt_overload_large_exceed_counter *** adi,agc-lmt-overload-large-exceed-counter
2, // magic AGC setting, see AD9361 docs // agc_lmt_overload_large_inc_steps *** adi,agc-lmt-overload-large-inc-steps
10, // magic AGC setting, see AD9361 docs // agc_lmt_overload_small_exceed_counter *** adi,agc-lmt-overload-small-exceed-counter
5, // magic AGC setting, see AD9361 docs // agc_outer_thresh_high *** adi,agc-outer-thresh-high
2, // magic AGC setting, see AD9361 docs // agc_outer_thresh_high_dec_steps *** adi,agc-outer-thresh-high-dec-steps
18, // magic AGC setting, see AD9361 docs // agc_outer_thresh_low *** adi,agc-outer-thresh-low
2, // magic AGC setting, see AD9361 docs // agc_outer_thresh_low_inc_steps *** adi,agc-outer-thresh-low-inc-steps
1, // magic AGC setting, see AD9361 docs // agc_attack_delay_extra_margin_us; *** adi,agc-attack-delay-extra-margin-us
0, // magic AGC setting, see AD9361 docs // agc_sync_for_gain_counter_enable *** adi,agc-sync-for-gain-counter-enable
/* Fast AGC */
64, // magic AGC setting, see AD9361 docs // fagc_dec_pow_measuremnt_duration *** adi,fagc-dec-pow-measurement-duration
260, // magic AGC setting, see AD9361 docs // fagc_state_wait_time_ns *** adi,fagc-state-wait-time-ns
/* Fast AGC - Low Power */
0, // magic AGC setting, see AD9361 docs // fagc_allow_agc_gain_increase *** adi,fagc-allow-agc-gain-increase-enable
5, // magic AGC setting, see AD9361 docs // fagc_lp_thresh_increment_time *** adi,fagc-lp-thresh-increment-time
1, // magic AGC setting, see AD9361 docs // fagc_lp_thresh_increment_steps *** adi,fagc-lp-thresh-increment-steps
/* Fast AGC - Lock Level */
10, // magic AGC setting, see AD9361 docs // fagc_lock_level *** adi,fagc-lock-level
1, // magic AGC setting, see AD9361 docs // fagc_lock_level_lmt_gain_increase_en *** adi,fagc-lock-level-lmt-gain-increase-enable
5, // magic AGC setting, see AD9361 docs // fagc_lock_level_gain_increase_upper_limit *** adi,fagc-lock-level-gain-increase-upper-limit
/* Fast AGC - Peak Detectors and Final Settling */
1, // magic AGC setting, see AD9361 docs // fagc_lpf_final_settling_steps *** adi,fagc-lpf-final-settling-steps
1, // magic AGC setting, see AD9361 docs // fagc_lmt_final_settling_steps *** adi,fagc-lmt-final-settling-steps
3, // magic AGC setting, see AD9361 docs // fagc_final_overrange_count *** adi,fagc-final-overrange-count
/* Fast AGC - Final Power Test */
0, // magic AGC setting, see AD9361 docs // fagc_gain_increase_after_gain_lock_en *** adi,fagc-gain-increase-after-gain-lock-enable
/* Fast AGC - Unlocking the Gain */
0, // magic AGC setting, see AD9361 docs // fagc_gain_index_type_after_exit_rx_mode *** adi,fagc-gain-index-type-after-exit-rx-mode
1, // magic AGC setting, see AD9361 docs // fagc_use_last_lock_level_for_set_gain_en *** adi,fagc-use-last-lock-level-for-set-gain-enable
1, // magic AGC setting, see AD9361 docs // fagc_rst_gla_stronger_sig_thresh_exceeded_en *** adi,fagc-rst-gla-stronger-sig-thresh-exceeded-enable
5, // magic AGC setting, see AD9361 docs // fagc_optimized_gain_offset *** adi,fagc-optimized-gain-offset
10, // magic AGC setting, see AD9361 docs // fagc_rst_gla_stronger_sig_thresh_above_ll *** adi,fagc-rst-gla-stronger-sig-thresh-above-ll
1, // magic AGC setting, see AD9361 docs // fagc_rst_gla_engergy_lost_sig_thresh_exceeded_en *** adi,fagc-rst-gla-engergy-lost-sig-thresh-exceeded-enable
1, // magic AGC setting, see AD9361 docs // fagc_rst_gla_engergy_lost_goto_optim_gain_en *** adi,fagc-rst-gla-engergy-lost-goto-optim-gain-enable
10, // magic AGC setting, see AD9361 docs // fagc_rst_gla_engergy_lost_sig_thresh_below_ll *** adi,fagc-rst-gla-engergy-lost-sig-thresh-below-ll
8, // magic AGC setting, see AD9361 docs // fagc_energy_lost_stronger_sig_gain_lock_exit_cnt *** adi,fagc-energy-lost-stronger-sig-gain-lock-exit-cnt
1, // magic AGC setting, see AD9361 docs // fagc_rst_gla_large_adc_overload_en *** adi,fagc-rst-gla-large-adc-overload-enable
1, // magic AGC setting, see AD9361 docs // fagc_rst_gla_large_lmt_overload_en *** adi,fagc-rst-gla-large-lmt-overload-enable
0, // magic AGC setting, see AD9361 docs // fagc_rst_gla_en_agc_pulled_high_en *** adi,fagc-rst-gla-en-agc-pulled-high-enable
0, // magic AGC setting, see AD9361 docs // fagc_rst_gla_if_en_agc_pulled_high_mode *** adi,fagc-rst-gla-if-en-agc-pulled-high-mode
64, // magic AGC setting, see AD9361 docs // fagc_power_measurement_duration_in_state5 *** adi,fagc-power-measurement-duration-in-state5
/* RSSI Control */
1, // settling delay on RSSI algo restart = 1 μs // rssi_delay *** adi,rssi-delay
1000, // total RSSI measurement duration = 1000 μs // rssi_duration *** adi,rssi-duration
GAIN_CHANGE_OCCURS, // reset RSSI accumulator on gain change event // rssi_restart_mode *** adi,rssi-restart-mode
0, // RSSI control values are in microseconds // rssi_unit_is_rx_samples_enable *** adi,rssi-unit-is-rx-samples-enable
1, // wait 1 μs between RSSI measurements // rssi_wait *** adi,rssi-wait
/* Aux ADC Control */
/* bladeRF Micro: N/A, pin tied to GND */
256, // AuxADC decimate by 256 // aux_adc_decimation *** adi,aux-adc-decimation
40000000UL, // AuxADC sample rate 40 MHz // aux_adc_rate *** adi,aux-adc-rate
/* AuxDAC Control */
/* bladeRF Micro: AuxDAC1 is TP7 and AUXDAC_TRIM, AuxDAC2 is TP8 */
1, // AuxDAC does not slave the ENSM // aux_dac_manual_mode_enable *** adi,aux-dac-manual-mode-enable
0, // AuxDAC1 default value = 0 mV // aux_dac1_default_value_mV *** adi,aux-dac1-default-value-mV
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac1_active_in_rx_enable *** adi,aux-dac1-active-in-rx-enable
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac1_active_in_tx_enable *** adi,aux-dac1-active-in-tx-enable
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac1_active_in_alert_enable *** adi,aux-dac1-active-in-alert-enable
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac1_rx_delay_us *** adi,aux-dac1-rx-delay-us
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac1_tx_delay_us *** adi,aux-dac1-tx-delay-us
0, // AuxDAC2 default value = 0 mV // aux_dac2_default_value_mV *** adi,aux-dac2-default-value-mV
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac2_active_in_rx_enable *** adi,aux-dac2-active-in-rx-enable
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac2_active_in_tx_enable *** adi,aux-dac2-active-in-tx-enable
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac2_active_in_alert_enable *** adi,aux-dac2-active-in-alert-enable
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac2_rx_delay_us *** adi,aux-dac2-rx-delay-us
0, // N/A when aux_dac_manual_mode_enable = 1 // aux_dac2_tx_delay_us *** adi,aux-dac2-tx-delay-us
/* Temperature Sensor Control */
256, // Temperature sensor decimate by 256 // temp_sense_decimation *** adi,temp-sense-decimation
1000, // Measure temperature every 1000 ms // temp_sense_measurement_interval_ms *** adi,temp-sense-measurement-interval-ms
206, // Offset = +206 degrees C // temp_sense_offset_signed *** adi,temp-sense-offset-signed
1, // Periodic temperature measurements enabled // temp_sense_periodic_measurement_enable *** adi,temp-sense-periodic-measurement-enable
/* Control Out Setup */
/* See https://wiki.analog.com/resources/tools-software/linux-drivers/iio-transceiver/ad9361-customization#control_output_setup */
0xFF, // Enable all CTRL_OUT bits // ctrl_outs_enable_mask *** adi,ctrl-outs-enable-mask
0, // CTRL_OUT index is 0 // ctrl_outs_index *** adi,ctrl-outs-index
/* External LNA Control */
/* bladeRF Micro: GPO_0 is TP3, GPO_1 is TP4 */
0, // N/A when elna_rx(1,2)_gpo(0,1)_control_enable = 0 // elna_settling_delay_ns *** adi,elna-settling-delay-ns
0, // MUST be 0 when elna_rx(1,2)_gpo(0,1)_control_enable = 0 // elna_gain_mdB *** adi,elna-gain-mdB
0, // MUST be 0 when elna_rx(1,2)_gpo(0,1)_control_enable = 0 // elna_bypass_loss_mdB *** adi,elna-bypass-loss-mdB
0, // Ext LNA Ctrl bit in Rx1 gain table does NOT set GPO0 state // elna_rx1_gpo0_control_enable *** adi,elna-rx1-gpo0-control-enable
0, // Ext LNA Ctrl bit in Rx2 gain table does NOT set GPO1 state // elna_rx2_gpo1_control_enable *** adi,elna-rx2-gpo1-control-enable
0, // N/A when elna_rx(1,2)_gpo(0,1)_control_enable = 0 // elna_gaintable_all_index_enable *** adi,elna-gaintable-all-index-enable
/* Digital Interface Control */
#ifdef ENABLE_AD9361_DIGITAL_INTERFACE_TIMING_VERIFICATION
/* Calibrate the digital interface delay (hardware validation) */
0, // Don't skip digital interface tuning // digital_interface_tune_skip_mode *** adi,digital-interface-tune-skip-mode
#else
/* Use hardcoded digital interface delay values (production) */
2, // Skip RX and TX tuning; use hardcoded values below // digital_interface_tune_skip_mode *** adi,digital-interface-tune-skip-mode
#endif // ENABLE_AD9361_DIGITAL_INTERFACE_TIMING_VERIFICATION
0, // ?? UNDOCUMENTED ?? // digital_interface_tune_fir_disable *** adi,digital-interface-tune-fir-disable
1, // Swap I and Q (spectral inversion) // pp_tx_swap_enable *** adi,pp-tx-swap-enable
1, // Swap I and Q (spectral inversion) // pp_rx_swap_enable *** adi,pp-rx-swap-enable
0, // Don't swap TX1 and TX2 // tx_channel_swap_enable *** adi,tx-channel-swap-enable
0, // Don't swap RX1 and RX2 // rx_channel_swap_enable *** adi,rx-channel-swap-enable
1, // Toggle RX_FRAME with 50% duty cycle // rx_frame_pulse_mode_enable *** adi,rx-frame-pulse-mode-enable
0, // Data port timing reflects # of enabled signal paths // two_t_two_r_timing_enable *** adi,2t2r-timing-enable
0, // Don't invert data bus // invert_data_bus_enable *** adi,invert-data-bus-enable
0, // Don't invert data clock // invert_data_clk_enable *** adi,invert-data-clk-enable
0, // MUST be 0 when lvds_mode_enable = 1 // fdd_alt_word_order_enable *** adi,fdd-alt-word-order-enable
0, // Don't invert RX_FRAME // invert_rx_frame_enable *** adi,invert-rx-frame-enable
0, // Don't make RX sample rate 2x the TX sample rate // fdd_rx_rate_2tx_enable *** adi,fdd-rx-rate-2tx-enable
0, // MUST be 0 when lvds_mode_enable = 1 // swap_ports_enable *** adi,swap-ports-enable
0, // MUST be 0 when lvds_mode_enable = 1 // single_data_rate_enable *** adi,single-data-rate-enable
1, // Use LVDS mode on data port // lvds_mode_enable *** adi,lvds-mode-enable
0, // MUST be 0 when lvds_mode_enable = 1 // half_duplex_mode_enable *** adi,half-duplex-mode-enable
0, // MUST be 0 when lvds_mode_enable = 1 // single_port_mode_enable *** adi,single-port-mode-enable
0, // MUST be 0 when lvds_mode_enable = 1 // full_port_enable *** adi,full-port-enable
0, // MUST be 0 when lvds_mode_enable = 1 // full_duplex_swap_bits_enable *** adi,full-duplex-swap-bits-enable
0, // RX_DATA delay rel to RX_FRAME = 0 DATA_CLK/2 cycles // delay_rx_data *** adi,delay-rx-data
// Approx 0.3 ns/LSB on next 4 values
5, // DATA_CLK delay = 1.5 ns // rx_data_clock_delay *** adi,rx-data-clock-delay
0, // RX_DATA/RX_FRAME delay = 0 ns // rx_data_delay *** adi,rx-data-delay
0, // FB_CLK delay = 0 ns // tx_fb_clock_delay *** adi,tx-fb-clock-delay
5, // TX_DATA/TX_FRAME delay = 1.5 ns // tx_data_delay *** adi,tx-data-delay
300, // LVDS driver bias 300 mV // lvds_bias_mV *** adi,lvds-bias-mV
1, // Enable LVDS on-chip termination // lvds_rx_onchip_termination_enable *** adi,lvds-rx-onchip-termination-enable
0, // RX1 and RX2 are not phase-aligned // rx1rx2_phase_inversion_en *** adi,rx1-rx2-phase-inversion-enable
0xFF, // Default signal inversion mappings // lvds_invert1_control *** adi,lvds-invert1-control
0x0F, // Default signal inversion mappings // lvds_invert2_control *** adi,lvds-invert2-control
1, // CLK_OUT drive increased by ~20% // clk_out_drive
1, // DATA_CLK drive increased by ~20% // dataclk_drive
1, // Data port drive increased by ~20% // data_port_drive
0, // CLK_OUT minimum slew (fastest rise/fall) // clk_out_slew
0, // DATA_CLK minimum slew (fastest rise/fall) // dataclk_slew
0, // Data port minimum slew (fastest rise/fall) // data_port_slew
/* GPO Control */
0, // GPO0 is LOW in Sleep/Wait/Alert states // gpo0_inactive_state_high_enable *** adi,gpo0-inactive-state-high-enable
0, // GPO1 is LOW in Sleep/Wait/Alert states // gpo1_inactive_state_high_enable *** adi,gpo1-inactive-state-high-enable
0, // GPO2 is LOW in Sleep/Wait/Alert states // gpo2_inactive_state_high_enable *** adi,gpo2-inactive-state-high-enable
0, // GPO3 is LOW in Sleep/Wait/Alert states // gpo3_inactive_state_high_enable *** adi,gpo3-inactive-state-high-enable
0, // GPO0 does not change state when entering RX state // gpo0_slave_rx_enable *** adi,gpo0-slave-rx-enable
0, // GPO0 does not change state when entering TX state // gpo0_slave_tx_enable *** adi,gpo0-slave-tx-enable
0, // GPO1 does not change state when entering RX state // gpo1_slave_rx_enable *** adi,gpo1-slave-rx-enable
0, // GPO1 does not change state when entering TX state // gpo1_slave_tx_enable *** adi,gpo1-slave-tx-enable
0, // GPO2 does not change state when entering RX state // gpo2_slave_rx_enable *** adi,gpo2-slave-rx-enable
0, // GPO2 does not change state when entering TX state // gpo2_slave_tx_enable *** adi,gpo2-slave-tx-enable
0, // GPO3 does not change state when entering RX state // gpo3_slave_rx_enable *** adi,gpo3-slave-rx-enable
0, // GPO3 does not change state when entering TX state // gpo3_slave_tx_enable *** adi,gpo3-slave-tx-enable
0, // N/A when gpo0_slave_rx_enable = 0 // gpo0_rx_delay_us *** adi,gpo0-rx-delay-us
0, // N/A when gpo0_slave_tx_enable = 0 // gpo0_tx_delay_us *** adi,gpo0-tx-delay-us
0, // N/A when gpo1_slave_rx_enable = 0 // gpo1_rx_delay_us *** adi,gpo1-rx-delay-us
0, // N/A when gpo1_slave_tx_enable = 0 // gpo1_tx_delay_us *** adi,gpo1-tx-delay-us
0, // N/A when gpo2_slave_rx_enable = 0 // gpo2_rx_delay_us *** adi,gpo2-rx-delay-us
0, // N/A when gpo2_slave_tx_enable = 0 // gpo2_tx_delay_us *** adi,gpo2-tx-delay-us
0, // N/A when gpo3_slave_rx_enable = 0 // gpo3_rx_delay_us *** adi,gpo3-rx-delay-us
0, // N/A when gpo3_slave_tx_enable = 0 // gpo3_tx_delay_us *** adi,gpo3-tx-delay-us
/* Tx Monitor Control */
/* bladeRF Micro: N/A, TX_MON1 and TX_MON2 tied to GND */
37000, // N/A // low_high_gain_threshold_mdB *** adi,txmon-low-high-thresh
0, // N/A // low_gain_dB *** adi,txmon-low-gain
24, // N/A // high_gain_dB *** adi,txmon-high-gain
0, // N/A // tx_mon_track_en *** adi,txmon-dc-tracking-enable
0, // N/A // one_shot_mode_en *** adi,txmon-one-shot-mode-enable
511, // N/A // tx_mon_delay *** adi,txmon-delay
8192, // N/A // tx_mon_duration *** adi,txmon-duration
2, // N/A // tx1_mon_front_end_gain *** adi,txmon-1-front-end-gain
2, // N/A // tx2_mon_front_end_gain *** adi,txmon-2-front-end-gain
48, // N/A // tx1_mon_lo_cm *** adi,txmon-1-lo-cm
48, // N/A // tx2_mon_lo_cm *** adi,txmon-2-lo-cm
/* GPIO definitions */
RFFE_CONTROL_RESET_N, // Reset using RFFE bit 0 // gpio_resetb *** reset-gpios
/* MCS Sync */
-1, // Future use (MCS Sync) // gpio_sync *** sync-gpios
-1, // Future use (MCS Sync) // gpio_cal_sw1 *** cal-sw1-gpios
-1, // Future use (MCS Sync) // gpio_cal_sw2 *** cal-sw2-gpios
/* External LO clocks */
NULL, // Future use (RX_EXT_LO, TX_EXT_LO control) // (*ad9361_rfpll_ext_recalc_rate)()
NULL, // Future use (RX_EXT_LO, TX_EXT_LO control) // (*ad9361_rfpll_ext_round_rate)()
NULL // Future use (RX_EXT_LO, TX_EXT_LO control) // (*ad9361_rfpll_ext_set_rate)()
};
/**
* AD9361 FIR Filters
*
* The AD9361 RFIC provides programmable FIR filters on both the RX and TX
* paths.
*
* On TX, the signal path is:
*
* DIGITAL:
* [ Programmable TX FIR ] -> [ HB1 ] -> [ HB2 ] -> [ HB3/INT3 ] -> [ DAC ]
* ANALOG:
* [ DAC ] -> [ BB LPF ] -> [ Secondary LPF ] -> ...
*
* The Programmable TX FIR is a programmable polyphase FIR filter, which can
* interpolate by 1, 2, 4, or be bypassed. Taps are stored in 16-bit
* twos-complement. If interpolating by 1, there is a limit of 64 taps;
* otherwise, the limit is 128 taps.
*
* HB1 and HB2 are fixed-coefficient half-band interpolating filters, and can
* interpolate by 2 or be bypassed. HB3/INT3 is a fixed-coefficient
* interpolating filter, and can interpolate by 2 or 3, or be bypassed.
*
* BB LPF is a third-order Butterworth LPF, and the Secondary LPF is a
* single-pole low-pass filter. Both have programmable corner frequencies.
*
* On RX, the signal path is:
*
* ANALOG:
* ... -> [ TIA LPF ] -> [ BB LPF ] -> [ ADC ]
* DIGITAL:
* [ ADC ] -> [ HB3/DEC3 ] -> [ HB2 ] -> [ HB1 ] -> [ Programmable RX FIR ]
*
* The TIA LPF is a transimpedance amplifier which applies a single-pole
* low-pass filter, and the BB LPF is a third-order Butterworth low-pass
* filter. Both have programmable corner frequencies.
*
* HB3/DEC3 is a fixed-coefficient decimating filter, and can decimate by a
* factor of 2 or 3, or be bypassed. HB2 is a fixed-coefficient half-band
* decimating filter, and can decimate by a factor of 2 or be bypassed. HB1
* is a fixed-coefficient half-band decimating filter, and can also decimate by
* a factor of 2 or be bypassed.
*
* The Programmable RX FIR filter is a programmable polyphase filter, which can
* decimate by a factor of 1, 2, or 4, or be bypassed. Similar to the TX FIR,
* taps are stored in 16-bit twos-complement. The maximum number of taps is
* limited to the ratio of the sample clock to the filter's output rate,
* multiplied by 16, up to a maximum of 128 taps. There is a fixed +6 dB gain,
* so the below RX filters are configured for a -6 dB gain to effect a net gain
* of 0 dB.
*
* In practice, the decimation/interpolation settings must match for both the
* RX and TX FIR filters. If they differ, TX quadrature calibration (and likely
* other calibrations) will fail.
*
*
* This file specifies four filters:
* bladerf2_rfic_rx_fir_config = decimate by 1 RX FIR
* bladerf2_rfic_tx_fir_config = interpolate by 1 TX FIR
* bladerf2_rfic_rx_fir_config_dec2 = decimate by 2 RX FIR
* bladerf2_rfic_tx_fir_config_int2 = interpolate by 2 TX FIR
*
* The first two (the 1x filters) are the default, and should provide
* reasonable performance under most circumstances. The other two filters are
* primarily intended for situations requiring a flatter TX spectrum,
* particularly when the ratio of sample rate to signal bandwidth is low.
*/
AD9361_RXFIRConfig bladerf2_rfic_rx_fir_config = {
3, // rx (RX1 = 1, RX2 = 2, both = 3)
-6, // rx_gain (-12, -6, 0, or 6 dB)
1, // rx_dec (decimate by 1, 2, or 4)
/**
* RX FIR Filter
* Built using https://github.com/analogdevicesinc/libad9361-iio
* Branch: filter_generation
* Commit: f749cef974f687f696226455dc7684277886cf3b
*
* This filter is intended to improve the flatness of the RX spectrum. It
* is a 64-tap, decimate-by-1 filter.
*
* Design parameters:
*
* fdp.Rdata = 30720000;
* fdp.RxTx = "Rx";
* fdp.Type = "Lowpass";
* fdp.DAC_div = 1;
* fdp.HB3 = 2;
* fdp.HB2 = 2;
* fdp.HB1 = 2;
* fdp.FIR = 1;
* fdp.PLL_mult = 4;
* fdp.converter_rate = 245760000;
* fdp.PLL_rate = 983040000;
* fdp.Fpass = fdp.Rdata*0.42;
* fdp.Fstop = fdp.Rdata*0.50;
* fdp.Fcenter = 0;
* fdp.Apass = 0.125;
* fdp.Astop = 85;
* fdp.phEQ = -1;
* fdp.wnom = 17920000;
* fdp.caldiv = 7;
* fdp.RFbw = 22132002;
* fdp.FIRdBmin = 0;
* fdp.int_FIR = 1;
*/
{
0, 0, 0, 1, -1, 3, -6, 11,
-19, 33, -53, 84, -129, 193, -282, 404,
-565, 777, -1052, 1401, -1841, 2390, -3071, 3911,
-4947, 6230, -7833, 9888, -12416, 15624, -21140, 32767,
32767, -21140, 15624, -12416, 9888, -7833, 6230, -4947,
3911, -3071, 2390, -1841, 1401, -1052, 777, -565,
404, -282, 193, -129, 84, -53, 33, -19,
11, -6, 3, -1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
}, // rx_coef[128]
64, // rx_coef_size
{0, 0, 0, 0, 0, 0}, // rx_path_clks[6]
0 // rx_bandwidth
};
AD9361_TXFIRConfig bladerf2_rfic_tx_fir_config = {
3, // tx (TX1 = 1, TX2 = 2, both = 3)
0, // tx_gain (-6 or 0 dB)
1, // tx_int (interpolate by 1, 2, or 4)
/**
* TX FIR Filter
*
* This filter literally does nothing, but it is here as a placeholder.
*/
{
32767, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
0, 0, 0, 0, 0, 0, 0, 0, // unused
}, // tx_coef[128]
64, // tx_coef_size
{0, 0, 0, 0, 0, 0}, // tx_path_clks[6]
0 // tx_bandwidth
};
AD9361_RXFIRConfig bladerf2_rfic_rx_fir_config_dec2 = {
3, // rx (RX1 = 1, RX2 = 2, both = 3)
-6, // rx_gain (-12, -6, 0, or 6 dB)
2, // rx_dec (decimate by 1, 2, or 4)
/**
* RX FIR Filter
* Built using https://github.com/analogdevicesinc/libad9361-iio
* Branch: filter_generation
* Commit: f749cef974f687f696226455dc7684277886cf3b
*
* This filter is intended to improve the flatness of the RX spectrum.
*
* It is a 128-tap, decimate-by-2 filter. Note that you MUST use a
* interpolate-by-2 filter on TX if you are using this filter.
*
* Design parameters:
*
* fdp.Rdata = 15360000;
* fdp.RxTx = "Rx";
* fdp.Type = "Lowpass";
* fdp.DAC_div = 1;
* fdp.HB3 = 2;
* fdp.HB2 = 2;
* fdp.HB1 = 2;
* fdp.FIR = 2;
* fdp.PLL_mult = 4;
* fdp.converter_rate = 245760000;
* fdp.PLL_rate = 983040000;
* fdp.Fpass = fdp.Rdata*0.45;
* fdp.Fstop = fdp.Rdata*0.50;
* fdp.Fcenter = 0;
* fdp.Apass = 0.1250;
* fdp.Astop = 85;
* fdp.phEQ = 217;
* fdp.wnom = 8800000;
* fdp.caldiv = 19;
* fdp.RFbw = 8472407;
* fdp.FIRdBmin = 0;
* fdp.int_FIR = 1;
*/
{
22, 125, 207, 190, 15, -98, -45, 91,
60, -76, -90, 69, 115, -47, -147, 22,
173, 18, -198, -66, 211, 127, -214, -194,
200, 269, -168, -345, 113, 419, -36, -484,
-66, 536, 193, -566, -343, 568, 513, -535,
-699, 458, 897, -329, -1099, 140, 1296, 120,
-1479, -464, 1636, 912, -1750, -1496, 1797, 2275,
-1734, -3378, 1464, 5120, -659, -8461, -2238, 18338,
32689, 24727, 4100, -7107, -2663, 4128, 2513, -2578,
-2378, 1567, 2184, -861, -1953, 351, 1703, 22,
-1446, -290, 1190, 474, -942, -590, 710, 650,
-498, -664, 311, 642, -150, -593, 18, 524,
86, -444, -162, 357, 211, -271, -238, 189,
245, -116, -237, 53, 216, -2, -187, -37,
154, 64, -119, -82, 87, 89, -56, -96,
30, 99, 3, -120, -107, 0, 56, 45,
}, // rx_coef[128]
128, // rx_coef_size
{0, 0, 0, 0, 0, 0}, // rx_path_clks[6]
0 // rx_bandwidth
};
AD9361_TXFIRConfig bladerf2_rfic_tx_fir_config_int2 = {
3, // tx (TX1 = 1, TX2 = 2, both = 3)
0, // tx_gain (-6 or 0 dB)
2, // tx_int (interpolate by 1, 2, or 4)
/**
* TX FIR Filter
* Built using https://github.com/analogdevicesinc/libad9361-iio
* Branch: filter_generation
* Commit: f749cef974f687f696226455dc7684277886cf3b
*
* This filter is intended to improve the flatness of the TX spectrum.
*
* It is a 128-tap, interpolate-by-2 filter. Note that you MUST use a
* decimate-by-2 filter on RX if you are using this filter.
*
* Design parameters:
*
* fdp.Rdata = 15360000;
* fdp.RxTx = "Tx";
* fdp.Type = "Lowpass";
* fdp.DAC_div = 1;
* fdp.HB3 = 2;
* fdp.HB2 = 2;
* fdp.HB1 = 2;
* fdp.FIR = 2;
* fdp.PLL_mult = 4;
* fdp.converter_rate = 245760000;
* fdp.PLL_rate = 983040000;
* fdp.Fpass = fdp.Rdata*0.45;
* fdp.Fstop = fdp.Rdata*0.50;
* fdp.Fcenter = 0;
* fdp.Apass = 0.1250;
* fdp.Astop = 85;
* fdp.phEQ = 217;
* fdp.wnom = 8800000;
* fdp.caldiv = 19;
* fdp.RFbw = 8472407;
* fdp.FIRdBmin = 0;
* fdp.int_FIR = 1;
*/
{
20, 104, 183, 161, 0, -129, -82, 61,
69, -65, -108, 31, 117, -15, -145, -23,
155, 61, -167, -113, 163, 167, -149, -227,
116, 286, -67, -342, -3, 388, 91, -421,
-197, 433, 321, -420, -457, 376, 602, -294,
-749, 171, 891, 1, -1019, -225, 1123, 507,
-1190, -855, 1205, 1279, -1148, -1800, 984, 2456,
-656, -3329, 31, 4619, 1275, -6897, -4889, 12679,
29822, 27710, 9244, -5193, -4330, 2732, 3367, -1405,
-2793, 571, 2318, -25, -1901, -338, 1527, 574,
-1189, -716, 885, 787, -617, -802, 383, 774,
-187, -714, 25, 632, 101, -535, -193, 432,
254, -330, -289, 232, 299, -143, -291, 66,
267, -3, -234, -46, 192, 79, -153, -103,
107, 109, -76, -117, 32, 103, -19, -115,
-35, 83, 34, -120, -204, -134, -42, 12,
}, // tx_coef[128]
128, // tx_coef_size
{0, 0, 0, 0, 0, 0}, // tx_path_clks[6]
0 // tx_bandwidth
};
AD9361_RXFIRConfig bladerf2_rfic_rx_fir_config_dec4 = {
3, // rx (RX1 = 1, RX2 = 2, both = 3)
-6, // rx_gain (-12, -6, 0, or 6 dB)
4, // rx_dec (decimate by 1, 2, or 4)
/**
* RX FIR Filter
* Built using https://github.com/analogdevicesinc/libad9361-iio
* Branch: filter_generation
* Commit: f749cef974f687f696226455dc7684277886cf3b
*
* This filter is intended to allow sample rates down to 520834 sps.
*
* It is a 128-tap, decimate-by-4 filter. Note that you MUST use a
* interpolate-by-4 filter on TX if you are using this filter.
*
* Design parameters:
*
* fdp.Rdata = 520834;
* fdp.RxTx = "Rx";
* fdp.Type = "Lowpass";
* fdp.DAC_div = 1;
* fdp.HB3 = 3;
* fdp.HB2 = 2;
* fdp.HB1 = 2;
* fdp.FIR = 4;
* fdp.PLL_mult = 32;
* fdp.converter_rate = 25000000;
* fdp.PLL_rate = 800000000;
* fdp.Fpass = fdp.Rdata*0.375;
* fdp.Fstop = fdp.Rdata*0.50;
* fdp.Fcenter = 0;
* fdp.Apass = 0.125;
* fdp.Astop = 85;
* fdp.phEQ = 217;
* fdp.wnom = 347220;
* fdp.caldiv = 309;
* fdp.RFbw = 433256;
* fdp.FIRdBmin = 0;
* fdp.int_FIR = 1;
*/
{
-30, -24, -46, -54, -28, -6, 50, 82,
108, 84, 28, -60, -136, -172, -132, -24,
122, 244, 280, 192, -2, -238, -410, -428,
-250, 80, 436, 656, 614, 276, -252, -760,
-1006, -830, -234, 580, 1272, 1494, 1060, 48,
-1178, -2086, -2192, -1284, 420, 2296, 3504, 3324,
1502, -1544, -4746, -6664, -5978, -1984, 5054, 13852,
22416, 28606, 30790, 28370, 21974, 13264, 4422, -2522,
-6282, -6630, -4358, -892, 2236, 3914, 3762, 2144,
-80, -1948, -2774, -2376, -1078, 486, 1652, 2008,
1510, 466, -640, -1352, -1434, -928, -110, 652,
1060, 990, 532, -82, -586, -792, -654, -274,
164, 480, 562, 410, 118, -178, -362, -378,
-244, -34, 154, 256, 240, 136, -4, -116,
-168, -144, -74, 14, 74, 102, 76, 38,
-28, -54, -96, -68, -82, -26, -34, -2,
}, // rx_coef[128]
128, // rx_coef_size
{0, 0, 0, 0, 0, 0}, // rx_path_clks[6]
0 // rx_bandwidth
};
AD9361_TXFIRConfig bladerf2_rfic_tx_fir_config_int4 = {
3, // tx (TX1 = 1, TX2 = 2, both = 3)
0, // tx_gain (-6 or 0 dB)
4, // tx_int (interpolate by 1, 2, or 4)
/**
* TX FIR Filter
* Built using https://github.com/analogdevicesinc/libad9361-iio
* Branch: filter_generation
* Commit: f749cef974f687f696226455dc7684277886cf3b
*
* This filter is intended to allow sample rates down to 520834 sps.
*
* It is a 128-tap, interpolate-by-4 filter. Note that you MUST use a
* decimate-by-4 filter on RX if you are using this filter.
*
* Design parameters:
*
* fdp.Rdata = 520834;
* fdp.RxTx = "Tx";
* fdp.Type = "Lowpass";
* fdp.DAC_div = 1;
* fdp.HB3 = 3;
* fdp.HB2 = 2;
* fdp.HB1 = 2;
* fdp.FIR = 4;
* fdp.PLL_mult = 32;
* fdp.converter_rate = 25000000;
* fdp.PLL_rate = 800000000;
* fdp.Fpass = fdp.Rdata*0.375;
* fdp.Fstop = fdp.Rdata*0.50;
* fdp.Fcenter = 0;
* fdp.Apass = 0.125;
* fdp.Astop = 85;
* fdp.phEQ = 217;
* fdp.wnom = 347220;
* fdp.caldiv = 309;
* fdp.RFbw = 1253611;
* fdp.FIRdBmin = 0;
* fdp.int_FIR = 1;
*/
{
-18, 2, -14, 16, 34, 76, 104, 124,
108, 62, -12, -86, -136, -128, -58, 58,
174, 242, 214, 84, -110, -294, -382, -310,
-84, 226, 494, 586, 426, 40, -434, -796,
-860, -538, 92, 792, 1258, 1226, 622, -386,
-1406, -1972, -1730, -628, 1002, 2522, 3200, 2526,
466, -2400, -4986, -6012, -4444, 90, 7064, 15112,
22370, 27018, 27836, 24590, 18120, 10072, 2400, -3220,
-5868, -5578, -3214, -106, 2446, 3584, 3126, 1508,
-464, -1970, -2484, -1940, -696, 666, 1590, 1764,
1212, 244, -706, -1258, -1242, -732, 10, 656,
964, 850, 412, -134, -560, -710, -560, -208,
178, 444, 500, 352, 88, -172, -330, -336,
-212, -24, 144, 230, 218, 124, 2, -100,
-146, -126, -62, 18, 82, 110, 98, 60,
12, -28, -52, -56, -50, -32, -18, -8,
}, // tx_coef[128]
128, // tx_coef_size
{0, 0, 0, 0, 0, 0}, // tx_path_clks[6]
0 // tx_bandwidth
};
const float ina219_r_shunt = 0.001F;