| 1 | #ifdef HAVE_XORG_CONFIG_H |
| 2 | #include <xorg-config.h> |
| 3 | #endif |
| 4 | |
| 5 | #include "xf86.h" |
| 6 | #include "xf86i2c.h" |
| 7 | #include "tda8425.h" |
| 8 | #include "i2c_def.h" |
| 9 | |
| 10 | #define TDA8425(a,b) { \ |
| 11 | data[0]=a; \ |
| 12 | data[1]=b; \ |
| 13 | I2C_WriteRead(&(t->d), data, 2, NULL, 0); \ |
| 14 | } |
| 15 | |
| 16 | TDA8425Ptr |
| 17 | Detect_tda8425(I2CBusPtr b, I2CSlaveAddr addr, Bool force) |
| 18 | { |
| 19 | TDA8425Ptr t; |
| 20 | |
| 21 | t = calloc(1, sizeof(TDA8425Rec)); |
| 22 | if (t == NULL) |
| 23 | return NULL; |
| 24 | t->d.DevName = "TDA8425 BTSC Stereo Audio Processor"; |
| 25 | t->d.SlaveAddr = addr; |
| 26 | t->d.pI2CBus = b; |
| 27 | t->d.NextDev = NULL; |
| 28 | t->d.StartTimeout = b->StartTimeout; |
| 29 | t->d.BitTimeout = b->BitTimeout; |
| 30 | t->d.AcknTimeout = b->AcknTimeout; |
| 31 | t->d.ByteTimeout = b->ByteTimeout; |
| 32 | |
| 33 | if (!force && !I2CProbeAddress(b, addr)) { |
| 34 | free(t); |
| 35 | return NULL; |
| 36 | } |
| 37 | |
| 38 | /* set default parameters */ |
| 39 | if (!I2CDevInit(&(t->d))) { |
| 40 | free(t); |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | return t; |
| 45 | } |
| 46 | |
| 47 | Bool |
| 48 | tda8425_init(TDA8425Ptr t) |
| 49 | { |
| 50 | t->stereo = 3; /* 3 = Spacial 2 = Linear 1 = Pseudo 0 = Forced mono */ |
| 51 | t->v_left = 0xFF; /* FF - C0 */ |
| 52 | t->v_right = 0xFF; /* FF - C0 */ |
| 53 | t->bass = 0xF6; /* 0xFF - 0xF0 */ |
| 54 | t->treble = 0xF6; /* 0xFF - 0xF0 */ |
| 55 | t->src_sel = 3; /* 3 - stereo */ |
| 56 | t->mute = TRUE; |
| 57 | t->mux = 0; /* 0 - source one, 1 -source 2 */ |
| 58 | |
| 59 | tda8425_setaudio(t); |
| 60 | return TRUE; |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | tda8425_setaudio(TDA8425Ptr t) |
| 65 | { |
| 66 | I2CByte data[2]; |
| 67 | |
| 68 | TDA8425(0x00, t->v_left); |
| 69 | TDA8425(0x01, t->v_right); |
| 70 | TDA8425(0x02, t->bass); |
| 71 | TDA8425(0x03, t->treble); |
| 72 | TDA8425(0x08, |
| 73 | 0xC0 | (t->mute ? 0x20 : 0x0) | (t->stereo << 3) | (t-> |
| 74 | src_sel << 1) | |
| 75 | t->mux); |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | tda8425_mute(TDA8425Ptr t, Bool mute) |
| 80 | { |
| 81 | t->mute = mute; |
| 82 | tda8425_setaudio(t); |
| 83 | } |