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>
35 Detect_uda1380(I2CBusPtr b
, I2CSlaveAddr addr
)
40 t
= calloc(1, sizeof(UDA1380Rec
));
46 t
->d
.DevName
= "UDA1380 Stereo audion coder-decoder";
49 t
->d
.DevName
= "Generic UDAxxxx";
52 t
->d
.SlaveAddr
= addr
;
55 t
->d
.StartTimeout
= b
->StartTimeout
;
56 t
->d
.BitTimeout
= b
->BitTimeout
;
57 t
->d
.AcknTimeout
= b
->AcknTimeout
;
58 t
->d
.ByteTimeout
= b
->ByteTimeout
;
60 if (!I2C_WriteRead(&(t
->d
), NULL
, 0, &a
, 1)) {
65 /* set default parameters */
66 if (!I2CDevInit(&(t
->d
))) {
71 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
72 "UDA1380 stereo coder-decoder detected\n");
78 uda1380_init(UDA1380Ptr t
)
87 (1 << 13) | (1 << 10) | (1 << 8) | (1 << 7) | (1 << 6) | (1 << 3) | (1
90 data
[1] = (CARD8
) ((tmp
>> 8) & 0xff);
91 data
[2] = (CARD8
) (tmp
& 0xff);
92 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
94 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
95 "UDA1380 failed to initialize\n");
99 /* Analog mixer (AVC) */
101 /* the analog mixer is muted initially */
104 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
106 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
107 "UDA1380 failed to initialize\n");
111 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
, "UDA1380 initialized\n");
117 uda1380_shutdown(UDA1380Ptr t
)
126 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
128 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
129 "UDA1380 failed to shutdown\n");
133 uda1380_setvolume(UDA1380Ptr t
, INT32 value
)
138 * We have to scale the value ranging from -1000 to 1000 to 0x2c to 0
140 CARD8 volume
= 47 - (CARD8
) ((value
+ 1000) * 47 / 2000);
143 t
->analog_mixer_settings
= ((volume
<< 8) & 0x3f00) | (volume
& 0x3f);
145 /* Analog mixer (AVC) */
147 data
[1] = volume
& 0x3f;
148 data
[2] = volume
& 0x3f;
149 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
151 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
152 "UDA1380 failed to set volume\n");
156 uda1380_mute(UDA1380Ptr t
, Bool mute
)
162 /* Analog mixer (AVC) */
166 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
168 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
169 "UDA1380 failed to mute\n");
172 /* Analog mixer (AVC) */
174 data
[1] = (CARD8
) ((t
->analog_mixer_settings
>> 8) & 0x3f);
175 data
[2] = (CARD8
) (t
->analog_mixer_settings
& 0x3f);
176 ret
= I2C_WriteRead(&(t
->d
), data
, 3, NULL
, 0);
178 xf86DrvMsg(t
->d
.pI2CBus
->scrnIndex
, X_INFO
,
179 "UDA1380 failed to unmute\n");
184 uda1380_getstatus(UDA1380Ptr t
)
189 uda1380_setparameters(UDA1380Ptr t
)
194 uda1380_dumpstatus(UDA1380Ptr t
)