1 /******************************************************************************
2 ** File Name: adi_phy_v3.c *
5 ** Copyright: 2010 Spreatrum, Incoporated. All Rights Reserved. *
6 ** Description: This file defines the basic operation interfaces of *
7 ** Analog to Digital Module. *
9 ******************************************************************************
11 ******************************************************************************
13 ** ------------------------------------------------------------------------- *
14 ** DATE NAME DESCRIPTION *
15 ** 2/25/2010 Tim Luo Create. *
17 ******************************************************************************/
20 /**---------------------------------------------------------------------------*
22 **---------------------------------------------------------------------------*/
23 #include "sci_types.h"
26 #include "adi_hal_internal.h"
29 typedef struct ADI_CFG_REG_TAG
31 volatile uint32 clk_div;
32 volatile uint32 ctl_reg;
33 volatile uint32 channel_pri;
34 volatile uint32 int_en;
35 volatile uint32 int_raw_sts;
36 volatile uint32 int_mask_st;
37 volatile uint32 int_clr;
38 volatile uint32 reserved_0;
39 volatile uint32 reserved_1;
40 volatile uint32 arm_rd_cmd;
41 volatile uint32 rd_data;
42 volatile uint32 fifo_sts;
44 volatile uint32 req_sts;
48 /*****************************************************************************
49 * Description: this function performs read operation to the analog die reg . *
50 * it will disable all interrupt and polling the ready bit, *
51 * and return a half-word value after read complete. *
52 * Global Resource Dependence: *
54 * Note: return register value *
55 ******************************************************************************/
56 PUBLIC uint16 ADI_Analogdie_reg_read (uint32 addr)
63 CHIP_REG_SET(ADI_ARM_RD_CMD, addr);
65 //wait read operation complete, RD_data[31] will be cleared after the read operation complete
68 adi_rd_data = CHIP_REG_GET(ADI_RD_DATA);
70 while (adi_rd_data & BIT_31);
73 return ( (uint16) (adi_rd_data & 0x0000FFFF));
76 /*****************************************************************************
77 * Description: this function performs write operation to the analog die reg . *
78 * it will write the analog die register if the fifo is not full *
79 * It will polling the fifo full status til it is not full *
80 * Global Resource Dependence: *
83 ******************************************************************************/
84 PUBLIC void ADI_Analogdie_reg_write (uint32 addr, uint16 data)
87 do{ ////ADI_wait_fifo_empty
88 if (((CHIP_REG_GET(ADI_FIFO_STS) & ((uint32)ADI_FIFO_EMPTY)) != 0))
94 CHIP_REG_SET(addr, data);
98 /*****************************************************************************
99 * Description: this function is used to init analog to digital module. *
100 * it will enable adi_acc and soft reset adi_module, *
101 * and then config the priority of each channel. *
102 * Global Resource Dependence: *
105 ******************************************************************************/
106 PUBLIC void ADI_init (void)
108 // volatile ADI_CFG_REG_T *adi_handle = (ADI_CFG_REG_T *) ADI_BASE_ADDR;
110 //enable ADI_ACC to put the adi master to normal operation mode
111 CHIP_REG_OR(GR_GEN0, GEN0_ADI_EN);
114 CHIP_REG_OR(GR_SOFT_RST, ADI_SOFT_RST);
120 CHIP_REG_AND(GR_SOFT_RST, (~ADI_SOFT_RST));
122 //Please refer to Section 5. Program guide, SC8800G Analog-Digital Interface module Implementation Specifications.doc
123 CHIP_REG_AND(ADI_CTL_REG,(~ARM_SERCLK_EN));
125 //config channel priority
126 CHIP_REG_SET(ADI_CHANNEL_PRI, ((0<<INT_STEAL_PRI) | (1<<STC_WR_PRI) | (0<<ARM_WR_PRI)
127 | (0<<ARM_RD_PRI) | (0<<DSP_WR_PRI) | (0<<DSP_RD_PRI)
128 | (1<<RFT_WR_PRI) | (1<<PD_WR_PRI)));