1 /*************************************************************************************
2 * Copyright (C) 2005 Bogdan D. bogdand@users.sourceforge.net
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
5 * software and associated documentation files (the "Software"), to deal in the Software
6 * without restriction, including without limitation the rights to use, copy, modify,
7 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in all copies or
11 * substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
15 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 * Except as contained in this notice, the name of the author shall not be used in advertising or
20 * otherwise to promote the sale, use or other dealings in this Software without prior written
21 * authorization from the author.
23 ************************************************************************************/
25 #ifdef HAVE_XORG_CONFIG_H
26 #include <xorg-config.h>
34 UDA1380Ptr
Detect_uda1380(I2CBusPtr b
, I2CSlaveAddr addr
)
39 t
= xcalloc(1, sizeof(UDA1380Rec
));
40 if(t
== NULL
) return NULL
;
45 t
->d
.DevName
= "UDA1380 Stereo audion coder-decoder";
48 t
->d
.DevName
= "Generic UDAxxxx";
51 t
->d
.SlaveAddr
= addr
;
54 t
->d
.StartTimeout
= b
->StartTimeout
;
55 t
->d
.BitTimeout
= b
->BitTimeout
;
56 t
->d
.AcknTimeout
= b
->AcknTimeout
;
57 t
->d
.ByteTimeout
= b
->ByteTimeout
;
59 if(!I2C_WriteRead(&(t
->d
), NULL
, 0, &a
, 1))
65 /* set default parameters */
66 if(!I2CDevInit(&(t
->d
)))
72 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 stereo coder-decoder detected\n");
77 Bool
uda1380_init(UDA1380Ptr t
)
85 tmp
= (1 << 13) | (1 << 10) | ( 1 << 8) | (1 << 7) | (1 << 6) | (1 << 3) | (1 << 1);
86 data
[1] = (CARD8
)((tmp
>> 8) & 0xff);
87 data
[2] = (CARD8
)(tmp
& 0xff);
88 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
91 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 failed to initialize\n");
95 /* Analog mixer (AVC) */
97 /* the analog mixer is muted initially */
100 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
103 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 failed to initialize\n");
107 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 initialized\n");
112 void uda1380_shutdown(UDA1380Ptr t
)
121 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
123 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 failed to shutdown\n");
126 void uda1380_setvolume(UDA1380Ptr t
, INT32 value
)
130 * We have to scale the value ranging from -1000 to 1000 to 0x2c to 0
132 CARD8 volume
= 47 - (CARD8
)((value
+ 1000) * 47 / 2000);
135 t
->analog_mixer_settings
= ((volume
<< 8) & 0x3f00) | (volume
& 0x3f);
137 /* Analog mixer (AVC) */
139 data
[1] = volume
& 0x3f;
140 data
[2] = volume
& 0x3f;
141 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
143 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 failed to set volume\n");
146 void uda1380_mute(UDA1380Ptr t
, Bool mute
)
153 /* Analog mixer (AVC) */
157 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
159 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 failed to mute\n");
163 /* Analog mixer (AVC) */
165 data
[1] = (CARD8
)((t
->analog_mixer_settings
>> 8) & 0x3f);
166 data
[2] = (CARD8
)(t
->analog_mixer_settings
& 0x3f);
167 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
169 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
,X_INFO
,"UDA1380 failed to unmute\n");
173 void uda1380_getstatus(UDA1380Ptr t
)
177 void uda1380_setparameters(UDA1380Ptr t
)
181 void uda1380_dumpstatus(UDA1380Ptr t
)