/* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
 * All rights reserved.
 *
 * This software is supplied "AS IS" without any warranties.
 * RDA assumes no responsibility or liability for the use of the software,
 * conveys no license or title under any patent, copyright, or mask work
 * right to the product. RDA reserves the right to make changes in the
 * software without notification.  RDA also make no representation or
 * warranty that such application will be suitable for the specified use
 * without further testing or modification.
 */

#ifndef _RFAD_H_
#define _RFAD_H_

// Auto generated by dtools(see dtools.txt for its version).
// Don't edit it manually!

#define REG_RFAD_BASE (0x18100000)

typedef volatile struct
{
    uint32_t mod_en;              // 0x00000000
    uint32_t ram_addr_map_cfg;    // 0x00000004
    uint32_t gpo_immdata;         // 0x00000008
    uint32_t spi_immdata;         // 0x0000000c
    uint32_t spi_cfg;             // 0x00000010
    uint32_t spi_rxdata;          // 0x00000014
    uint32_t debug_data;          // 0x00000018
    uint32_t rf_gpo_ctrl;         // 0x0000001c
    uint32_t framl_rfad;          // 0x00000020
    uint32_t framc_err_up;        // 0x00000024
    uint32_t data_time_err_up;    // 0x00000028
    uint32_t framc_err_dn;        // 0x0000002c
    uint32_t data_time_err_dn;    // 0x00000030
    uint32_t framl_err;           // 0x00000034
    uint32_t dont_insert__err_up; // 0x00000038
    uint32_t dont_insert__err_dn; // 0x0000003c
    uint32_t __64[1008];          // 0x00000040
    uint32_t down_mem;            // 0x00001000
    uint32_t __4100[1023];        // 0x00001004
    uint32_t up_mem;              // 0x00002000
} HWP_RFAD_T;

#define hwp_rfad ((HWP_RFAD_T *)REG_ACCESS_ADDRESS(REG_RFAD_BASE))

// mod_en
typedef union {
    uint32_t v;
    struct
    {
        uint32_t mod_dn_en : 1; // [0]
        uint32_t mod_up_en : 1; // [1]
        uint32_t __31_2 : 30;   // [31:2]
    } b;
} REG_RFAD_MOD_EN_T;

// ram_addr_map_cfg
typedef union {
    uint32_t v;
    struct
    {
        uint32_t ram2_start_addr_dn : 8; // [7:0]
        uint32_t ram3_start_addr_dn : 8; // [15:8]
        uint32_t ram2_start_addr_up : 8; // [23:16]
        uint32_t ram3_start_addr_up : 8; // [31:24]
    } b;
} REG_RFAD_RAM_ADDR_MAP_CFG_T;

// gpo_immdata
typedef union {
    uint32_t v;
    struct
    {
        uint32_t gpo : 14;     // [13:0]
        uint32_t spi_rw : 1;   // [14]
        uint32_t spi_sel : 1;  // [15]
        uint32_t up_sel : 1;   // [16]
        uint32_t __31_17 : 15; // [31:17]
    } b;
} REG_RFAD_GPO_IMMDATA_T;

// spi_cfg
typedef union {
    uint32_t v;
    struct
    {
        uint32_t tx_data_len : 5; // [4:0]
        uint32_t rx_data_len : 5; // [9:5]
        uint32_t spol : 1;        // [10]
        uint32_t cpol : 1;        // [11]
        uint32_t cpha : 1;        // [12]
        uint32_t sec : 1;         // [13]
        uint32_t rd_edge : 1;     // [14]
        uint32_t rd_inter : 2;    // [16:15]
        uint32_t ms : 1;          // [17]
        uint32_t dux : 1;         // [18]
        uint32_t cs_inv : 1;      // [19]
        uint32_t frq_div_wr : 3;  // [22:20]
        uint32_t frq_div_rd : 3;  // [25:23]
        uint32_t distance : 4;    // [29:26]
        uint32_t __31_30 : 2;     // [31:30]
    } b;
} REG_RFAD_SPI_CFG_T;

// debug_data
typedef union {
    uint32_t v;
    struct
    {
        uint32_t ram_rd_addr_dn : 9;     // [8:0], read only
        uint32_t __11_9 : 3;             // [11:9]
        uint32_t time_err_dn : 1;        // [12], read only
        uint32_t addr_err_dn : 1;        // [13], read only
        uint32_t insert_err_dn_flag : 1; // [14], read only
        uint32_t framc_err_dn_flag : 1;  // [15], read only
        uint32_t ram_rd_addr_up : 9;     // [24:16], read only
        uint32_t __27_25 : 3;            // [27:25]
        uint32_t time_err_up : 1;        // [28], read only
        uint32_t addr_err_up : 1;        // [29], read only
        uint32_t insert_err_up_flag : 1; // [30], read only
        uint32_t framc_err_up_flag : 1;  // [31], read only
    } b;
} REG_RFAD_DEBUG_DATA_T;

// framl_rfad
typedef union {
    uint32_t v;
    struct
    {
        uint32_t framc_rfad : 16;    // [15:0]
        uint32_t dn_en : 1;          // [16]
        uint32_t up_en : 1;          // [17]
        uint32_t dont_insert_en : 1; // [18]
        uint32_t __31_19 : 13;       // [31:19]
    } b;
} REG_RFAD_FRAML_RFAD_T;

// framc_err_up
typedef union {
    uint32_t v;
    struct
    {
        uint32_t framc_err_up : 24;     // [23:0], read only
        uint32_t framc_err_up_flag : 1; // [24], read only
        uint32_t __31_25 : 7;           // [31:25]
    } b;
} REG_RFAD_FRAMC_ERR_UP_T;

// data_time_err_up
typedef union {
    uint32_t v;
    struct
    {
        uint32_t data_time_err_up : 24; // [23:0], read only
        uint32_t ram_rd_addr_up : 8;    // [31:24], read only
    } b;
} REG_RFAD_DATA_TIME_ERR_UP_T;

// framc_err_dn
typedef union {
    uint32_t v;
    struct
    {
        uint32_t framc_err_dn : 24;     // [23:0], read only
        uint32_t framc_err_dn_flag : 1; // [24], read only
        uint32_t __31_25 : 7;           // [31:25]
    } b;
} REG_RFAD_FRAMC_ERR_DN_T;

// data_time_err_dn
typedef union {
    uint32_t v;
    struct
    {
        uint32_t data_time_err_dn : 24; // [23:0], read only
        uint32_t ram_rd_addr_dn : 8;    // [31:24], read only
    } b;
} REG_RFAD_DATA_TIME_ERR_DN_T;

// framl_err
typedef union {
    uint32_t v;
    struct
    {
        uint32_t framl_err_dn : 16; // [15:0], read only
        uint32_t framl_err_up : 16; // [31:16], read only
    } b;
} REG_RFAD_FRAML_ERR_T;

// dont_insert__err_up
typedef union {
    uint32_t v;
    struct
    {
        uint32_t framc_err_up : 24;  // [23:0], read only
        uint32_t ram_rd_addr_up : 8; // [31:24], read only
    } b;
} REG_RFAD_DONT_INSERT__ERR_UP_T;

// dont_insert__err_dn
typedef union {
    uint32_t v;
    struct
    {
        uint32_t framc_err_dn : 24;  // [23:0], read only
        uint32_t ram_rd_addr_dn : 8; // [31:24], read only
    } b;
} REG_RFAD_DONT_INSERT__ERR_DN_T;

// mod_en
#define RFAD_MOD_DN_EN (1 << 0)
#define RFAD_MOD_UP_EN (1 << 1)

// ram_addr_map_cfg
#define RFAD_RAM2_START_ADDR_DN(n) (((n)&0xff) << 0)
#define RFAD_RAM3_START_ADDR_DN(n) (((n)&0xff) << 8)
#define RFAD_RAM2_START_ADDR_UP(n) (((n)&0xff) << 16)
#define RFAD_RAM3_START_ADDR_UP(n) (((n)&0xff) << 24)

// gpo_immdata
#define RFAD_GPO(n) (((n)&0x3fff) << 0)
#define RFAD_SPI_RW (1 << 14)
#define RFAD_SPI_SEL (1 << 15)
#define RFAD_UP_SEL (1 << 16)

// spi_cfg
#define RFAD_TX_DATA_LEN(n) (((n)&0x1f) << 0)
#define RFAD_RX_DATA_LEN(n) (((n)&0x1f) << 5)
#define RFAD_SPOL (1 << 10)
#define RFAD_CPOL (1 << 11)
#define RFAD_CPHA (1 << 12)
#define RFAD_SEC (1 << 13)
#define RFAD_RD_EDGE (1 << 14)
#define RFAD_RD_INTER(n) (((n)&0x3) << 15)
#define RFAD_MS (1 << 17)
#define RFAD_DUX (1 << 18)
#define RFAD_CS_INV (1 << 19)
#define RFAD_FRQ_DIV_WR(n) (((n)&0x7) << 20)
#define RFAD_FRQ_DIV_RD(n) (((n)&0x7) << 23)
#define RFAD_DISTANCE(n) (((n)&0xf) << 26)

// debug_data
#define RFAD_DEBUG_DATA_RAM_RD_ADDR_DN(n) (((n)&0x1ff) << 0)
#define RFAD_TIME_ERR_DN (1 << 12)
#define RFAD_ADDR_ERR_DN (1 << 13)
#define RFAD_INSERT_ERR_DN_FLAG (1 << 14)
#define RFAD_DEBUG_DATA_FRAMC_ERR_DN_FLAG (1 << 15)
#define RFAD_DEBUG_DATA_RAM_RD_ADDR_UP(n) (((n)&0x1ff) << 16)
#define RFAD_TIME_ERR_UP (1 << 28)
#define RFAD_ADDR_ERR_UP (1 << 29)
#define RFAD_INSERT_ERR_UP_FLAG (1 << 30)
#define RFAD_DEBUG_DATA_FRAMC_ERR_UP_FLAG (1 << 31)

// framl_rfad
#define RFAD_FRAMC_RFAD(n) (((n)&0xffff) << 0)
#define RFAD_DN_EN (1 << 16)
#define RFAD_UP_EN (1 << 17)
#define RFAD_DONT_INSERT_EN (1 << 18)

// framc_err_up
#define RFAD_FRAMC_ERR_UP(n) (((n)&0xffffff) << 0)
#define RFAD_FRAMC_ERR_UP_FRAMC_ERR_UP_FLAG (1 << 24)

// data_time_err_up
#define RFAD_DATA_TIME_ERR_UP(n) (((n)&0xffffff) << 0)
#define RFAD_DATA_TIME_ERR_UP_RAM_RD_ADDR_UP(n) (((n)&0xff) << 24)

// framc_err_dn
#define RFAD_FRAMC_ERR_DN(n) (((n)&0xffffff) << 0)
#define RFAD_FRAMC_ERR_DN_FRAMC_ERR_DN_FLAG (1 << 24)

// data_time_err_dn
#define RFAD_DATA_TIME_ERR_DN(n) (((n)&0xffffff) << 0)
#define RFAD_DATA_TIME_ERR_DN_RAM_RD_ADDR_DN(n) (((n)&0xff) << 24)

// framl_err
#define RFAD_FRAML_ERR_DN(n) (((n)&0xffff) << 0)
#define RFAD_FRAML_ERR_UP(n) (((n)&0xffff) << 16)

// dont_insert__err_up
#define RFAD_FRAMC_ERR_UP(n) (((n)&0xffffff) << 0)
#define RFAD_DONT_INSERT__ERR_UP_RAM_RD_ADDR_UP(n) (((n)&0xff) << 24)

// dont_insert__err_dn
#define RFAD_FRAMC_ERR_DN(n) (((n)&0xffffff) << 0)
#define RFAD_DONT_INSERT__ERR_DN_RAM_RD_ADDR_DN(n) (((n)&0xff) << 24)

#endif // _RFAD_H_
