First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / i2c / tda9850.c
blob5b0c581ed595e44eac3e9a96b4658dc28bd7c19f
1 #ifdef HAVE_XORG_CONFIG_H
2 #include <xorg-config.h>
3 #endif
5 #include "xf86.h"
6 #include "xf86i2c.h"
7 #include "tda9850.h"
8 #include "i2c_def.h"
10 #define TDA9850(a,b) { \
11 data[0]=a; \
12 data[1]=b; \
13 I2C_WriteRead(&(t->d), data, 2, NULL, 0); \
16 TDA9850Ptr Detect_tda9850(I2CBusPtr b, I2CSlaveAddr addr)
18 TDA9850Ptr t;
19 I2CByte a;
21 t = xcalloc(1, sizeof(TDA9850Rec));
22 if(t == NULL) return NULL;
23 switch(addr)
25 case TDA9850_ADDR_1:
26 t->d.DevName = "TDA9850 BTSC Stereo+SAP Audio Processor";
27 break;
28 default:
29 t->d.DevName = "Generic TDAxxxx";
30 break;
32 t->d.SlaveAddr = addr;
33 t->d.pI2CBus = b;
34 t->d.NextDev = NULL;
35 t->d.StartTimeout = b->StartTimeout;
36 t->d.BitTimeout = b->BitTimeout;
37 t->d.AcknTimeout = b->AcknTimeout;
38 t->d.ByteTimeout = b->ByteTimeout;
40 if(!I2C_WriteRead(&(t->d), NULL, 0, &a, 1))
42 xfree(t);
43 return NULL;
46 /* set default parameters */
47 if(!I2CDevInit(&(t->d)))
49 xfree(t);
50 return NULL;
53 return t;
56 Bool tda9850_init(TDA9850Ptr t)
58 t->stereo = 1;
59 t->sap = 0;
60 t->mute = TRUE;
61 t->sap_mute = TRUE;
62 tda9850_setaudio(t);
63 return TRUE;
66 void tda9850_setaudio(TDA9850Ptr t)
68 CARD8 data[2];
70 if(t->mux==2)
72 TDA9850(0x04,0x0F); TDA9850(0x05,0x0F); TDA9850(0x06, 0x58);
73 TDA9850(0x07,0x07); TDA9850(0x08,0x00);
74 TDA9850(0x09,0x00); TDA9850(0x0A,0x03);
75 } else
77 TDA9850(0x04,0x07); TDA9850(0x05,0x07);
78 TDA9850(0x06,0x58); TDA9850(0x07,0x07);
79 TDA9850(0x08,0x10); TDA9850(0x09,0x10);
80 TDA9850(0x0A,0x03);
83 TDA9850(0x06,(t->stereo<<6)|(t->sap<<7)|(t->mute?0x8:0)|(t->sap_mute?0x10:0x0));
86 void tda9850_mute(TDA9850Ptr t, Bool mute)
88 CARD8 data[2];
90 xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO, "tda9850_mute %s\n", mute ? "on" : "off");
91 t->mute = mute;
93 TDA9850(0x06,(t->stereo<<6)|(t->sap<<7)|(t->mute?0x8:0x0)|(t->sap_mute?0x10:0x0));
96 void tda9850_sap_mute(TDA9850Ptr t, Bool sap_mute)
98 CARD8 data[2];
100 xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO, "tda9850_sap_mute %s\n", sap_mute ? "on" : "off");
101 t->sap_mute = sap_mute;
103 TDA9850(0x06,(t->stereo<<6)|(t->sap<<7)|(t->mute?0x8:0x0)|(t->sap_mute?0x10:0x0));
106 CARD16 tda9850_getstatus(TDA9850Ptr t)
108 CARD16 status;
110 I2C_WriteRead(&(t->d), NULL, 0, (I2CByte *)&status, 2);
111 return status;