1
/*************************************************************************************
2
* $Id: uda1380.c,v 1.5 2005/09/24 21:56:00 bogdand Exp $
4
* Copyright (C) 2005 Bogdan D. bogdand@users.sourceforge.net
6
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
7
* software and associated documentation files (the "Software"), to deal in the Software
8
* without restriction, including without limitation the rights to use, copy, modify,
9
* merge, publish, distribute, sublicense, and/or sell copies of the Software,
10
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice shall be included in all copies or
13
* substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
17
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM,
18
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
* Except as contained in this notice, the name of the author shall not be used in advertising or
22
* otherwise to promote the sale, use or other dealings in this Software without prior written
23
* authorization from the author.
26
* Revision 1.5 2005/09/24 21:56:00 bogdand
27
* Changed the license to a X/MIT one
29
* Revision 1.4 2005/07/13 20:19:37 sandmann
30
* xc/programs/Xserver/hw/xfree86/drivers/i2c/*.c: include xorg-config.h
32
* xserver/xorg/hw/xfree86/i2c/Makefile.am: Add i2c drivers
34
* Revision 1.3 2005/07/11 02:29:50 ajax
35
* Prep for modular builds by adding guarded #include "config.h" everywhere.
37
* Revision 1.2 2005/07/01 22:43:11 daniels
38
* Change all misc.h and os.h references to <X11/foo.h>.
41
************************************************************************************/
43
#ifdef HAVE_XORG_CONFIG_H
44
#include <xorg-config.h>
52
UDA1380Ptr Detect_uda1380(I2CBusPtr b, I2CSlaveAddr addr)
57
t = xcalloc(1, sizeof(UDA1380Rec));
58
if(t == NULL) return NULL;
63
t->d.DevName = "UDA1380 Stereo audion coder-decoder";
66
t->d.DevName = "Generic UDAxxxx";
69
t->d.SlaveAddr = addr;
72
t->d.StartTimeout = b->StartTimeout;
73
t->d.BitTimeout = b->BitTimeout;
74
t->d.AcknTimeout = b->AcknTimeout;
75
t->d.ByteTimeout = b->ByteTimeout;
77
if(!I2C_WriteRead(&(t->d), NULL, 0, &a, 1))
83
/* set default parameters */
84
if(!I2CDevInit(&(t->d)))
90
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 stereo coder-decoder detected\n");
95
Bool uda1380_init(UDA1380Ptr t)
103
tmp = (1 << 13) | (1 << 10) | ( 1 << 8) | (1 << 7) | (1 << 6) | (1 << 3) | (1 << 1);
104
data[1] = (CARD8)((tmp >> 8) & 0xff);
105
data[2] = (CARD8)(tmp & 0xff);
106
ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
109
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to initialize\n");
113
/* Analog mixer (AVC) */
115
/* the analog mixer is muted initially */
118
ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
121
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to initialize\n");
125
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 initialized\n");
130
void uda1380_shutdown(UDA1380Ptr t)
139
ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
141
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to shutdown\n");
144
void uda1380_setvolume(UDA1380Ptr t, INT32 value)
148
* We have to scale the value ranging from -1000 to 1000 to 0x2c to 0
150
CARD8 volume = 47 - (CARD8)((value + 1000) * 47 / 2000);
153
t->analog_mixer_settings = ((volume << 8) & 0x3f00) | (volume & 0x3f);
155
/* Analog mixer (AVC) */
157
data[1] = volume & 0x3f;
158
data[2] = volume & 0x3f;
159
ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
161
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to set volume\n");
164
void uda1380_mute(UDA1380Ptr t, Bool mute)
171
/* Analog mixer (AVC) */
175
ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
177
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to mute\n");
181
/* Analog mixer (AVC) */
183
data[1] = (CARD8)((t->analog_mixer_settings >> 8) & 0x3f);
184
data[2] = (CARD8)(t->analog_mixer_settings & 0x3f);
185
ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
187
xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to unmute\n");
191
void uda1380_getstatus(UDA1380Ptr t)
195
void uda1380_setparameters(UDA1380Ptr t)
199
void uda1380_dumpstatus(UDA1380Ptr t)