source: svn/trunk/zas_dstar/devices/STA323/STA323W.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 9.4 KB
Line 
1/*==========================================================================
2 * Copyright (c) 2005 Digital Stream Technologies Inc.  All Rights Reserved.
3 *
4 * Module:      sta323w.c
5 * Author:              Arzhna, arzhna@dstreamtech.com
6 * Description: STA323W, Audio Sound Controller
7 *
8 ==========================================================================*/
9 
10#include "dsthalcommon.h"
11#include "STA323W_reg.h"
12#include "STA323W.h"
13
14#ifndef USE_12288_MCLK
15#define USE_12288_MCLK 0
16#endif
17
18#define STA_DEBUG       1
19
20#define I2C_STA323W_WRITE               0x34
21#define I2C_STA323W_READ                0x35
22
23
24
25extern DS_U32 gdhlExtDbgLvl;
26
27void STA323W_ReadConfig(void);
28
29DS_U8 DEFAULT_CH_VOL = DEFAULT_CH_DTV_VOL_9W_12V_REG;
30DS_U8 DEFAULT_CH_DTV_VOL = DEFAULT_CH_DTV_VOL_9W_12V_REG;
31DS_U8 DEFAULT_CH_CAP_VOL = DEFAULT_CH_CAP_VOL_9W_12V_REG;
32DS_U8   I2C_STA_WRITE   = I2C_STA323W_WRITE;
33DS_U8   I2C_STA_READ    = I2C_STA323W_READ;
34
35int SRS_COMP = SRS_COMP_9W_12V;
36int AVL_COMP = AVL_COMP_9W_12V;
37
38/*=====================================================================
39        Register Write Function
40 =====================================================================*/
41int STA323W_SetAddress( DS_U8 read, DS_U8 write) // 323W ¿Í 333W,333BW°¡ ADDRESS°¡ ´Ù¸£±â ¶§¹®¿¡ ±âÁ¸ DEFINEÀ¸·Î 󸮵Ǵø ºÎºÐÀ» º¯¼ö·Î
42{
43        int retVal = 0;
44        I2C_STA_WRITE   = write;
45        I2C_STA_READ    = read;
46        return retVal;
47}
48
49int STA323W_RegWrite( DS_U8 regNum, DS_U8 data )
50{
51        int retVal = 0;
52
53        if ( regNum > STA323W_COEF_WRT_CTRL ) {
54                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed, line = %d\n", __FUNCTION__, __LINE__);
55                retVal = -1;
56                return retVal;
57        }
58
59        retVal = DHL_SYS_I2cWrite( I2C_STA_WRITE, TRUE, regNum, &data, 1 );
60       
61        if ( retVal != 0 )
62                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed.\n", __FUNCTION__);
63               
64        return retVal;
65}
66
67int STA323W_RegWriteMultiple( DS_U8 regNum, DS_U8 *data, DS_U8 Len )
68{
69        int retVal = 0;
70
71        if ( regNum > STA323W_COEF_WRT_CTRL ) {
72                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed, line = %d\n", __FUNCTION__, __LINE__);
73                retVal = -1;
74                return retVal;
75        }
76
77        retVal = DHL_SYS_I2cWrite( I2C_STA_WRITE, TRUE, regNum, data, Len );
78       
79        if ( retVal != 0 )
80                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed.\n", __FUNCTION__);
81               
82        return retVal;
83}
84
85/*=====================================================================
86        Register Write Function
87 =====================================================================*/
88
89int STA323W_RegRead( DS_U8 regNum, DS_U8 *data )
90{
91        int retVal = 0;
92
93        if ( regNum > STA323W_COEF_WRT_CTRL ) {
94                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed, line = %d\n", __FUNCTION__, __LINE__);
95                retVal = -1;
96                return retVal;
97        }
98#if 0
99        retVal = DHL_SYS_I2cWrite( I2C_STA323W_READ, TRUE, regNum, 0, 0 );
100        if ( retVal != 0 )
101                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed.\n", __FUNCTION__);
102#endif
103
104        retVal = DHL_SYS_I2cWriteAndRead( I2C_STA_READ, TRUE, regNum, data, 1 );
105        if ( retVal != 0 )
106                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed.\n", __FUNCTION__);
107               
108        return retVal;
109}
110
111int STA323W_RegReadMultiple( DS_U8 regNum, DS_U8 *data, DS_U8 Len )
112{
113        int retVal = 0;
114
115        if ( regNum > STA323W_COEF_WRT_CTRL ) {
116                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed, line = %d\n", __FUNCTION__, __LINE__);
117                retVal = -1;
118                return retVal;
119        }
120
121        retVal = DHL_SYS_I2cRead( I2C_STA_READ, TRUE, regNum, data, Len );
122       
123        if ( retVal != 0 )
124                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| failed.\n", __FUNCTION__);
125               
126        return retVal;
127}
128
129
130#if STA_DEBUG//BK
131void sta_r(int reg)
132{
133        DS_U8 data;
134        STA323W_RegRead(reg, &data);
135        DHL_DbgPrintf(0,DHLDBG_EXT, "STA read: [0x%x]=0x%x\n",reg, (int)data);
136}
137void sta_w(int reg, DS_U8 data)
138{
139        DS_U8 data1;
140        STA323W_RegRead(reg, &data1);
141        DHL_DbgPrintf(0,DHLDBG_EXT, "STA befor: [0x%x]=0x%x\n", reg, (int)data1);
142        STA323W_RegWrite(reg,data);
143        STA323W_RegRead(reg, &data1);
144        DHL_DbgPrintf(0,DHLDBG_EXT, "STA after: [0x%x]=0x%x\n", reg, (int)data1);
145}
146#endif
147
148
149
150/*=====================================================================
151        Chip Control Function
152 =====================================================================*/
153static int g_STA323W_Intialized = 0;
154int STA323W_Init(void)
155{
156        int err = 0;
157
158        if ( g_STA323W_Intialized == 1 )
159                return err;
160
161#if USE_12288_MCLK
162        err |= STA323W_RegWrite(STA323W_CONFIG_A, 0x63);       
163#else
164        err |= STA323W_RegWrite(STA323W_CONFIG_A, 0x61);       
165#endif
166        err |= STA323W_RegWrite(STA323W_CONFIG_B, 0x82);       
167        err |= STA323W_RegWrite(STA323W_CONFIG_D, 0x70);                                // drc mode enable
168        err |= STA323W_RegWrite(STA323W_CONFIG_E, 0xC0);// Soft volume update, Zero-Crossing Volume Update »ç¿ë
169        err |= STA323W_RegWrite(STA323W_CONFIG_F, 0xdc);       
170        err |= STA323W_RegWrite(STA323W_AUTO_MODE1, 0x80);
171        err |= STA323W_RegWrite(STA323W_MVOL, DEFAULT_MASTER_VOL);              // default °ªÀº Á¶Á¤ÀÌ ÇÊ¿ä
172        err |= STA323W_RegWrite(STA323W_CH1_VOL, DEFAULT_CH_VOL);               // default : 0x42
173        err |= STA323W_RegWrite(STA323W_CH2_VOL, DEFAULT_CH_VOL);               // default : 0x42
174        err |= STA323W_RegWrite(STA323W_CH3_VOL, DEFAULT_CH_VOL);               // default : 0x42
175        err |= STA323W_RegWrite(STA323W_MMUTE, 0);
176
177        //
178        // hwatk/20061025
179        // AVL Function enable½Ã »ç¿ëµÇ´Â Limiter°ªÀ» 0x70 --> 0x57·Î º¯°æ.
180        // ÀÌ´Â Reference TV Graph¸¦ µû¸£¸ç, AVL Enable½Ã¿¡¸¸ Àû¿ëµÇ¹Ç·Î Dolby/SRS µî¿¡´Â ¹«°ü.
181        //
182        err |= STA323W_RegWrite(STA323W_LMT1_ATRT, 0x57);
183        err |= STA323W_RegWrite(STA323W_LMT2_ATRT, 0x57);
184       
185        if(err){
186                DHL_DbgPrintf(0,DHLDBG_EXT, "%s| STA323W Volume Initialize Failed!, lines = %d\n",__FUNCTION__,__LINE__);
187                return err;
188        }               
189       
190        //printf("%s| STA323W Configuration Success!\n",__FUNCTION__);
191
192#if 0//STA_DEBUG//BK TEST
193                ZMon_AddCommand( "sta_r","sta_r","sta_r reg", "i", sta_r);
194                ZMon_AddCommand( "sta_w","sta_w","sta_w", "ii", sta_w);
195                ZMon_AddCommand( "sta_dump","sta_dump","sta_dump", "", STA323W_ReadConfig);
196#endif
197
198        g_STA323W_Intialized = 1;
199       
200        return err;
201}
202
203int STA323W_SetMVolume(DS_U16 Vol)
204{
205        int err = 0;
206       
207        if ( g_STA323W_Intialized == 0 )
208                STA323W_Init();
209               
210        err = STA323W_RegWrite(STA323W_MVOL, Vol);
211        if(err)
212                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegWrite failed.\n", __FUNCTION__);
213       
214        return err;
215}
216
217int STA323W_GetMVolume(DS_U16 *Vol)
218{
219        int err = 0;
220
221        if ( g_STA323W_Intialized == 0 )
222                err = STA323W_Init();
223               
224        err = STA323W_RegRead(STA323W_MVOL, (DS_U8*)Vol);       //org
225
226        if(err)
227                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegRead failed.\n", __FUNCTION__);
228
229        return err;     
230}
231
232int STA323W_SetMMute(DS_BOOL bMute)
233{
234        int err = 0;   
235
236        if ( g_STA323W_Intialized == 0 )
237                err = STA323W_Init();
238                       
239        if(bMute)
240                err = STA323W_RegWrite(STA323W_MMUTE, 1);
241        else
242                err = STA323W_RegWrite(STA323W_MMUTE, 0);
243       
244        if(err)
245                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegWrite failed.\n", __FUNCTION__);
246       
247        return err;     
248}
249
250int STA323W_GetMMute(DS_BOOL *bMute)
251{
252        int err = 0;   
253        DS_U8 data;
254       
255        if ( g_STA323W_Intialized == 0 )
256                err = STA323W_Init();
257
258        err = STA323W_RegRead(STA323W_MMUTE, &data);   
259        if(err)
260                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegRead failed.\n", __FUNCTION__);   
261       
262        if(data) 
263                *bMute = TRUE;
264        else   
265                *bMute = FALSE;
266               
267               
268        return err;     
269}
270
271int STA323W_SetTone(INT16 Treble, INT16 Bass)
272{
273        int err = 0;
274        DS_U8 Tone;     
275       
276        Tone = (DS_U8)((Treble<<4)|Bass);
277
278        if ( g_STA323W_Intialized == 0 )
279                err = STA323W_Init();
280       
281        err = STA323W_RegWrite(STA323W_TONE_CONTROL, Tone);
282        if(err)
283                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegWrite failed.\n", __FUNCTION__);
284               
285        return err;     
286}
287
288int STA323W_GetTone(INT16* Treble, INT16 *Bass)
289{
290        int err = 0;
291        DS_U8 Tone;     
292
293        if ( g_STA323W_Intialized == 0 )
294                err = STA323W_Init();
295       
296        err = STA323W_RegRead(STA323W_TONE_CONTROL, &Tone);
297        if(err)
298                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegRead failed.\n", __FUNCTION__);
299                                       
300        *Treble = (INT16)(Tone>>4);
301        *Bass   = (INT16)(Tone&0x0f);
302       
303        return err;     
304}
305
306int STA323W_SetAVLMode(/*STA323W_AMGC*/int avlMode)
307{
308        int err = 0;
309        DS_U8 data1, data2;
310
311        if ( g_STA323W_Intialized == 0 )
312                err = STA323W_Init();
313
314        if(avlMode){
315                data1=0x10;
316                data2=0x50;
317        }else{
318                data1=0x00;
319                data2=0x40;
320        }
321
322        err = STA323W_RegWrite(STA323W_CH1_CONFIG, data1);
323        if(err)
324                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s:%d| STA323W_RegWrite failed.\n",__FUNCTION__, __LINE__);       
325
326        err = STA323W_RegWrite(STA323W_CH2_CONFIG, data2);
327        if(err)
328                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s:%d| STA323W_RegWrite failed.\n",__FUNCTION__, __LINE__);       
329       
330        return err;
331}
332
333int STA323W_GetAVLMode(/*STA323W_AMGC*/int *avlMode)
334{
335        int err = 0;
336        DS_U8 data;
337        DS_U8 mode;
338
339        if ( g_STA323W_Intialized == 0 )
340                err = STA323W_Init();
341       
342        err = STA323W_RegRead(STA323W_AUTO_MODE1, &data);
343        if(err)
344                DHL_DbgPrintf(0,DHLDBG_EXT, "|%s| STA323W_RegRead failed.\n",__FUNCTION__);
345       
346        mode = ((data>>4) & 0x3);
347       
348        switch(mode){
349                case 0:
350                        *avlMode = STA323W_AMGC_USER;
351                        break;
352                case 1:
353                        *avlMode = STA323W_AMGC_ACNC;
354                        break;
355                case 2:
356                        *avlMode = STA323W_AMGC_ACLC;
357                        break;
358                case 3:
359                        *avlMode = STA323W_AMGC_DRC;
360                        break;
361        }
362       
363        return err;
364}
365
366int STA323W_SetChannelVol(DS_U8 Ch1, DS_U8 Ch2)
367{
368        int err=0;
369
370        if ( g_STA323W_Intialized == 0 )
371                err = STA323W_Init();
372       
373        err |= STA323W_RegWrite(STA323W_CH1_VOL, Ch2);          // L
374        err |= STA323W_RegWrite(STA323W_CH2_VOL, Ch1);          // R
375       
376        //DHL_DbgPrintf(0,DHLDBG_EXT, "%s| L: 0x%lx, R: 0x%lx, line=%d\n",__FUNCTION__,(DS_U32)Ch1,(DS_U32)Ch2,__LINE__);
377       
378        return err;
379}
380
381int STA323W_GetChannelVol(DS_U8 *Ch1, DS_U8 *Ch2)
382{
383        int err=0;
384
385        if ( g_STA323W_Intialized == 0 )
386                err = STA323W_Init();
387       
388        err |= STA323W_RegRead(STA323W_CH1_VOL, Ch1);           // L
389        err |= STA323W_RegRead(STA323W_CH2_VOL, Ch2);           // R
390       
391        return err;     
392}
393
394void STA323W_ReadConfig(void)
395{
396        int err = 0;
397        DS_U8 data;     
398        int i;
399       
400        for(i=0;i<0x26;i++){
401                if(i!=0 && i%4==0)
402                        printf("\n");
403                err = STA323W_RegRead(i, &data );
404                printf("Reg[0x%2xl]:0x%2lx  ",i,(DS_U32)data);
405        }
406}
407
408
409
410
411
Note: See TracBrowser for help on using the repository browser.