~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/i2c/uda1380.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************************
 
2
 * $Id: uda1380.c,v 1.5 2005/09/24 21:56:00 bogdand Exp $
 
3
 * 
 
4
 * Copyright (C) 2005 Bogdan D. bogdand@users.sourceforge.net
 
5
 *
 
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:
 
11
 *
 
12
 * The above copyright notice and this permission notice shall be included in all copies or 
 
13
 * substantial portions of the Software.
 
14
 *
 
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.
 
20
 *
 
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.
 
24
 *
 
25
 * $Log: uda1380.c,v $
 
26
 * Revision 1.5  2005/09/24 21:56:00  bogdand
 
27
 * Changed the license to a X/MIT one
 
28
 *
 
29
 * Revision 1.4  2005/07/13 20:19:37  sandmann
 
30
 * xc/programs/Xserver/hw/xfree86/drivers/i2c/*.c: include xorg-config.h
 
31
 * instead of config.h
 
32
 * xserver/xorg/hw/xfree86/i2c/Makefile.am: Add i2c drivers
 
33
 *
 
34
 * Revision 1.3  2005/07/11 02:29:50  ajax
 
35
 * Prep for modular builds by adding guarded #include "config.h" everywhere.
 
36
 *
 
37
 * Revision 1.2  2005/07/01 22:43:11  daniels
 
38
 * Change all misc.h and os.h references to <X11/foo.h>.
 
39
 *
 
40
 *
 
41
 ************************************************************************************/
 
42
 
 
43
#ifdef HAVE_XORG_CONFIG_H
 
44
#include <xorg-config.h>
 
45
#endif
 
46
 
 
47
#include "xf86.h"
 
48
#include "xf86i2c.h"
 
49
#include "uda1380.h"
 
50
#include "i2c_def.h"
 
51
 
 
52
UDA1380Ptr Detect_uda1380(I2CBusPtr b, I2CSlaveAddr addr)
 
53
{
 
54
        UDA1380Ptr t;
 
55
        I2CByte a;
 
56
  
 
57
        t = xcalloc(1, sizeof(UDA1380Rec));
 
58
        if(t == NULL) return NULL;
 
59
        switch(addr)
 
60
        {
 
61
                case UDA1380_ADDR_1:
 
62
                case UDA1380_ADDR_2:
 
63
                        t->d.DevName = "UDA1380 Stereo audion coder-decoder";
 
64
                        break;
 
65
                default:
 
66
                        t->d.DevName = "Generic UDAxxxx";
 
67
                break;
 
68
        }
 
69
        t->d.SlaveAddr = addr;
 
70
        t->d.pI2CBus = b;
 
71
        t->d.NextDev = NULL;
 
72
        t->d.StartTimeout = b->StartTimeout;
 
73
        t->d.BitTimeout = b->BitTimeout;
 
74
        t->d.AcknTimeout = b->AcknTimeout;
 
75
        t->d.ByteTimeout = b->ByteTimeout;
 
76
  
 
77
        if(!I2C_WriteRead(&(t->d), NULL, 0, &a, 1))
 
78
        {
 
79
                xfree(t);
 
80
                return NULL;
 
81
        }
 
82
  
 
83
        /* set default parameters */
 
84
        if(!I2CDevInit(&(t->d)))
 
85
        {
 
86
                xfree(t);
 
87
                return NULL;
 
88
        }
 
89
  
 
90
        xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 stereo coder-decoder detected\n");
 
91
 
 
92
        return t;  
 
93
}
 
94
 
 
95
Bool uda1380_init(UDA1380Ptr t)
 
96
{
 
97
        CARD8 data[3];
 
98
        CARD16 tmp;
 
99
        Bool ret;
 
100
 
 
101
        /* Power control */
 
102
        data[0] = 0x02;
 
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);
 
107
        if (ret == FALSE)
 
108
        {
 
109
                xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to initialize\n");
 
110
                return FALSE;
 
111
        }
 
112
 
 
113
        /* Analog mixer  (AVC) */
 
114
        data[0] = 0x03;
 
115
        /* the analog mixer is muted initially */
 
116
        data[1] = 0x3f;
 
117
        data[2] = 0x3f;
 
118
        ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
 
119
        if (ret == FALSE)
 
120
        {
 
121
                xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to initialize\n");
 
122
                return FALSE;
 
123
        }
 
124
                  
 
125
        xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 initialized\n");
 
126
 
 
127
        return TRUE;
 
128
}
 
129
 
 
130
void uda1380_shutdown(UDA1380Ptr t)
 
131
{
 
132
        CARD8 data[3];
 
133
        Bool ret;
 
134
 
 
135
        /* Power control */
 
136
        data[0] = 0x02;
 
137
        data[1] = 0;
 
138
        data[2] = 0;
 
139
        ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
 
140
        if (ret == FALSE)
 
141
                xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to shutdown\n");
 
142
}
 
143
 
 
144
void uda1380_setvolume(UDA1380Ptr t, INT32 value)
 
145
{
 
146
        CARD8 data[3];
 
147
        /*
 
148
         * We have to scale the value ranging from -1000 to 1000 to 0x2c to 0
 
149
         */
 
150
        CARD8 volume = 47 - (CARD8)((value + 1000) * 47 / 2000);
 
151
        Bool ret;
 
152
                  
 
153
        t->analog_mixer_settings = ((volume << 8) & 0x3f00) | (volume & 0x3f);
 
154
                                         
 
155
        /* Analog mixer  (AVC) */
 
156
        data[0] = 0x03;
 
157
        data[1] = volume & 0x3f;
 
158
        data[2] = volume & 0x3f;
 
159
        ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
 
160
        if (ret == FALSE)
 
161
                xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to set volume\n");
 
162
}
 
163
 
 
164
void uda1380_mute(UDA1380Ptr t, Bool mute)
 
165
{
 
166
        CARD8 data[3];
 
167
        Bool ret;
 
168
                  
 
169
        if (mute == TRUE)
 
170
        {
 
171
                /* Analog mixer  (AVC) */
 
172
                data[0] = 0x03;
 
173
                data[1] = 0xff;
 
174
                data[2] = 0xff;
 
175
                ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
 
176
                if (ret == FALSE)
 
177
                        xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to mute\n");
 
178
        }
 
179
        else
 
180
        {
 
181
                /* Analog mixer  (AVC) */
 
182
                data[0] = 0x03;
 
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);
 
186
                if (ret == FALSE)
 
187
                        xf86DrvMsg(t->d.pI2CBus->scrnIndex,X_INFO,"UDA1380 failed to unmute\n");
 
188
        }
 
189
}
 
190
 
 
191
void uda1380_getstatus(UDA1380Ptr t)
 
192
{
 
193
}
 
194
 
 
195
void uda1380_setparameters(UDA1380Ptr t)
 
196
{
 
197
}
 
198
 
 
199
void uda1380_dumpstatus(UDA1380Ptr t)
 
200
{
 
201
}