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 **---------------------------------------------------------------------------*/
26 #include <asm/arch/regs_adi.h>
27 #include <asm/arch/adi_hal_internal.h>
28 #include <asm/proc/system.h>
30 #define TIMEOUT_ADI (300)//for 8810 fpga
31 #define CHIP_REG_OR(reg_addr, value) (*(volatile unsigned int *)(reg_addr) |= (unsigned int)(value))
32 #define CHIP_REG_AND(reg_addr, value) (*(volatile unsigned int *)(reg_addr) &= (unsigned int)(value))
33 #define CHIP_REG_GET(reg_addr) (*(volatile unsigned int *)(reg_addr))
34 #define CHIP_REG_SET(reg_addr, value) (*(volatile unsigned int *)(reg_addr) = (unsigned int)(value))
36 #define SCI_ASSERT(condition) BUG_ON(!(condition))
37 #define SCI_PASSERT(condition, format...) \
40 printf("function :%s\r\n", __FUNCTION__);\
45 #define ADI_PHYS ADI_BASE
46 #define __adi_virt_to_phys(x) ((x) - SPRD_ADI_BASE + ADI_PHYS)
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 unsigned short ADI_Analogdie_reg_read (unsigned int addr)
59 unsigned int adi_rd_data;
61 int timeout = TIMEOUT_ADI;
62 local_irq_save(flags);
66 //SCI_ASSERT ( (addr>=ANA_REG_ADDR_START) && (addr<=ANA_REG_ADDR_END));
69 addr = __adi_virt_to_phys(addr);
70 CHIP_REG_SET (ADI_ARM_RD_CMD, addr);
72 //wait read operation complete, RD_data[31] will be cleared after the read operation complete
74 adi_rd_data = CHIP_REG_GET (ADI_RD_DATA);
77 } while (adi_rd_data & BIT_31);
79 //rd_data high part should be the address of the last read operation
80 //SCI_ASSERT ( (adi_rd_data & 0xFFFF0000) == ((addr) <<16));
82 //read operation complete
85 local_irq_restore(flags);
87 return ( (unsigned short) (adi_rd_data & 0x0000FFFF));
91 /*****************************************************************************
92 * Description: this function performs write operation to the analog die reg . *
93 * it will write the analog die register if the fifo is not full *
94 * It will polling the fifo full status til it is not full *
95 * Global Resource Dependence: *
98 ******************************************************************************/
99 void ADI_Analogdie_reg_write (unsigned int addr, unsigned short data)
102 int timeout = TIMEOUT_ADI;
103 do {////ADI_wait_fifo_empty
104 if ( ( (CHIP_REG_GET (ADI_FIFO_STS) & ( (unsigned int) ADI_FIFO_EMPTY)) != 0))
109 return;//NEED TO return ERROR.
110 } while (1);/*lint !e506*/
112 CHIP_REG_SET (addr, data);
116 /*****************************************************************************
117 * Description: this function is used to init analog to digital module. *
118 * it will enable adi_acc and soft reset adi_module, *
119 * and then config the priority of each channel. *
120 * Global Resource Dependence: *
123 ******************************************************************************/
126 // volatile ADI_CFG_REG_T *adi_handle = (ADI_CFG_REG_T *) ADI_BASE_ADDR;
128 //enable ADI_ACC to put the adi master to normal operation mode
129 CHIP_REG_OR (GR_GEN0, GEN0_ADI_EN);
132 CHIP_REG_OR (GR_SOFT_RST, ADI_SOFT_RST);
134 unsigned int wait = 50;
138 CHIP_REG_AND (GR_SOFT_RST, (~ADI_SOFT_RST));
140 //Please refer to Section 5. Program guide, SC8800G Analog-Digital Interface module Implementation Specifications.doc
141 CHIP_REG_AND (ADI_CTL_REG, (~ARM_SERCLK_EN));
143 //config channel priority
144 CHIP_REG_SET (ADI_CHANNEL_PRI, ( (0<<INT_STEAL_PRI) | (1<<STC_WR_PRI) | (0<<ARM_WR_PRI)
145 | (0<<ARM_RD_PRI) | (0<<DSP_WR_PRI) | (0<<DSP_RD_PRI)
146 | (1<<RFT_WR_PRI) | (1<<PD_WR_PRI)));