First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / i2c / uda1380.c
blobdefda3cdc7c179bc65cc556e4f1ad349bb66a01a
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>
27 #endif
29 #include "xf86.h"
30 #include "xf86i2c.h"
31 #include "uda1380.h"
32 #include "i2c_def.h"
34 UDA1380Ptr Detect_uda1380(I2CBusPtr b, I2CSlaveAddr addr)
36 UDA1380Ptr t;
37 I2CByte a;
39 t = xcalloc(1, sizeof(UDA1380Rec));
40 if(t == NULL) return NULL;
41 switch(addr)
43 case UDA1380_ADDR_1:
44 case UDA1380_ADDR_2:
45 t->d.DevName = "UDA1380 Stereo audion coder-decoder";
46 break;
47 default:
48 t->d.DevName = "Generic UDAxxxx";
49 break;
51 t->d.SlaveAddr = addr;
52 t->d.pI2CBus = b;
53 t->d.NextDev = NULL;
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))
61 xfree(t);
62 return NULL;
65 /* set default parameters */
66 if(!I2CDevInit(&(t->d)))
68 xfree(t);
69 return NULL;
72 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 stereo coder-decoder detected\n");
74 return t;
77 Bool uda1380_init(UDA1380Ptr t)
79 CARD8 data[3];
80 CARD16 tmp;
81 Bool ret;
83 /* Power control */
84 data[0] = 0x02;
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);
89 if (ret == FALSE)
91 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to initialize\n");
92 return FALSE;
95 /* Analog mixer (AVC) */
96 data[0] = 0x03;
97 /* the analog mixer is muted initially */
98 data[1] = 0x3f;
99 data[2] = 0x3f;
100 ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
101 if (ret == FALSE)
103 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to initialize\n");
104 return FALSE;
107 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 initialized\n");
109 return TRUE;
112 void uda1380_shutdown(UDA1380Ptr t)
114 CARD8 data[3];
115 Bool ret;
117 /* Power control */
118 data[0] = 0x02;
119 data[1] = 0;
120 data[2] = 0;
121 ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
122 if (ret == FALSE)
123 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to shutdown\n");
126 void uda1380_setvolume(UDA1380Ptr t, INT32 value)
128 CARD8 data[3];
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);
133 Bool ret;
135 t->analog_mixer_settings = ((volume << 8) & 0x3f00) | (volume & 0x3f);
137 /* Analog mixer (AVC) */
138 data[0] = 0x03;
139 data[1] = volume & 0x3f;
140 data[2] = volume & 0x3f;
141 ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
142 if (ret == FALSE)
143 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to set volume\n");
146 void uda1380_mute(UDA1380Ptr t, Bool mute)
148 CARD8 data[3];
149 Bool ret;
151 if (mute == TRUE)
153 /* Analog mixer (AVC) */
154 data[0] = 0x03;
155 data[1] = 0xff;
156 data[2] = 0xff;
157 ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
158 if (ret == FALSE)
159 xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to mute\n");
161 else
163 /* Analog mixer (AVC) */
164 data[0] = 0x03;
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);
168 if (ret == FALSE)
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)