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>
29 #define CHIP_REG_OR(reg_addr, value) (*(volatile unsigned int *)(reg_addr) |= (unsigned int)(value))
30 #define CHIP_REG_AND(reg_addr, value) (*(volatile unsigned int *)(reg_addr) &= (unsigned int)(value))
31 #define CHIP_REG_GET(reg_addr) (*(volatile unsigned int *)(reg_addr))
32 #define CHIP_REG_SET(reg_addr, value) (*(volatile unsigned int *)(reg_addr) = (unsigned int)(value))
34 #define SCI_ASSERT(condition) BUG_ON(!(condition))
35 #define SCI_PASSERT(condition, format...) \
38 printf("function :%s\r\n", __FUNCTION__);\
43 #define ADI_PHYS ADI_BASE
44 #define __adi_virt_to_phys(x) ((x) - SPRD_ADI_BASE + ADI_PHYS)
46 /*****************************************************************************
47 * Description: this function performs read operation to the analog die reg . *
48 * it will disable all interrupt and polling the ready bit, *
49 * and return a half-word value after read complete. *
50 * Global Resource Dependence: *
52 * Note: return register value *
53 ******************************************************************************/
54 unsigned short ADI_Analogdie_reg_read (unsigned int addr)
57 unsigned int adi_rd_data;
60 local_irq_save(flags);
64 //SCI_ASSERT ( (addr>=ANA_REG_ADDR_START) && (addr<=ANA_REG_ADDR_END));
67 addr = __adi_virt_to_phys(addr);
68 CHIP_REG_SET (ADI_ARM_RD_CMD, addr);
70 //wait read operation complete, RD_data[31] will be cleared after the read operation complete
73 adi_rd_data = CHIP_REG_GET (ADI_RD_DATA);
75 while (adi_rd_data & BIT_31);
77 //rd_data high part should be the address of the last read operation
78 //SCI_ASSERT ( (adi_rd_data & 0xFFFF0000) == ((addr) <<16));
80 //read operation complete
83 local_irq_restore(flags);
85 return ( (unsigned short) (adi_rd_data & 0x0000FFFF));
88 /*****************************************************************************
89 * Description: this function performs write operation to the analog die reg . *
90 * it will write the analog die register if the fifo is not full *
91 * It will polling the fifo full status til it is not full *
92 * Global Resource Dependence: *
95 ******************************************************************************/
96 void ADI_Analogdie_reg_write (unsigned int addr, unsigned short data)
100 do ////ADI_wait_fifo_empty
102 if ( ( (CHIP_REG_GET (ADI_FIFO_STS) & ( (unsigned int) ADI_FIFO_EMPTY)) != 0))
107 while (1);/*lint !e506*/
109 CHIP_REG_SET (addr, data);
113 /*****************************************************************************
114 * Description: this function is used to init analog to digital module. *
115 * it will enable adi_acc and soft reset adi_module, *
116 * and then config the priority of each channel. *
117 * Global Resource Dependence: *
120 ******************************************************************************/
123 // volatile ADI_CFG_REG_T *adi_handle = (ADI_CFG_REG_T *) ADI_BASE_ADDR;
125 //enable ADI_ACC to put the adi master to normal operation mode
126 CHIP_REG_OR (GR_GEN0, GEN0_ADI_EN);
129 CHIP_REG_OR (GR_SOFT_RST, ADI_SOFT_RST);
131 unsigned int wait = 50;
135 CHIP_REG_AND (GR_SOFT_RST, (~ADI_SOFT_RST));
137 //Please refer to Section 5. Program guide, SC8800G Analog-Digital Interface module Implementation Specifications.doc
138 CHIP_REG_AND (ADI_CTL_REG, (~ARM_SERCLK_EN));
140 //config channel priority
141 CHIP_REG_SET (ADI_CHANNEL_PRI, ( (0<<INT_STEAL_PRI) | (1<<STC_WR_PRI) | (0<<ARM_WR_PRI)
142 | (0<<ARM_RD_PRI) | (0<<DSP_WR_PRI) | (0<<DSP_RD_PRI)
143 | (1<<RFT_WR_PRI) | (1<<PD_WR_PRI)));