diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-03-28 20:36:59 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-03-28 20:36:59 +0000 |
commit | d1a93d8a0c508adce8cf12cec823b675260f2896 (patch) | |
tree | d20290ef655a89660567904a8dbc447a8873e03a /firmware/drivers | |
parent | 66a295223063dabf434ae0b276455a40b35e383a (diff) | |
download | rockbox-d1a93d8a0c508adce8cf12cec823b675260f2896.tar.gz rockbox-d1a93d8a0c508adce8cf12cec823b675260f2896.zip |
Simplification and correction of the TLV320 driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9326 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/tlv320.c | 74 |
1 files changed, 22 insertions, 52 deletions
diff --git a/firmware/drivers/tlv320.c b/firmware/drivers/tlv320.c index da64c0e69e..bae1f59f95 100644 --- a/firmware/drivers/tlv320.c +++ b/firmware/drivers/tlv320.c | |||
@@ -41,21 +41,7 @@ struct tlv320_info | |||
41 | int vol_r; | 41 | int vol_r; |
42 | } tlv320; | 42 | } tlv320; |
43 | 43 | ||
44 | /* Definition of a playback configuration to start with */ | 44 | /* Shadow registers */ |
45 | #define NUM_DEFAULT_REGS 10 | ||
46 | unsigned tlv320_defaults[2*NUM_DEFAULT_REGS] = | ||
47 | { | ||
48 | REG_PC, PC_ON | PC_OSC | PC_CLK | PC_DAC | ~PC_OUT, /* do we need to enable osciliator and clock? */ | ||
49 | REG_LLIV, LLIV_LIM, /* mute adc input */ | ||
50 | REG_RLIV, RLIV_RIM, /* mute adc input */ | ||
51 | REG_LHV, LHV_LHV(HEADPHONE_MUTE), /* mute headphone */ | ||
52 | REG_RHV, RHV_RHV(HEADPHONE_MUTE), /* mute headphone */ | ||
53 | REG_AAP, AAP_MICM, /* mute microphone */ | ||
54 | REG_DAP, DAP_DEEMP_DIS, /* de-emphasis control: disabled */ | ||
55 | REG_DAIF, DAIF_FOR_I2S | DAIF_IWL_24 | ~DAIF_MS, /* i2s with 24 bit data len and slave mode */ | ||
56 | REG_SRC, 0, /* ToDo */ | ||
57 | REG_DIA, DIA_ACT, /* activate digital interface */ | ||
58 | }; | ||
59 | unsigned tlv320_regs[0xf]; | 45 | unsigned tlv320_regs[0xf]; |
60 | 46 | ||
61 | void tlv320_write_reg(unsigned reg, unsigned value) | 47 | void tlv320_write_reg(unsigned reg, unsigned value) |
@@ -63,7 +49,8 @@ void tlv320_write_reg(unsigned reg, unsigned value) | |||
63 | unsigned char data[3]; | 49 | unsigned char data[3]; |
64 | 50 | ||
65 | data[0] = TLV320_ADDR; | 51 | data[0] = TLV320_ADDR; |
66 | data[1] = reg << 1; | 52 | /* The register address is the high 7 bits and the data the low 9 bits */ |
53 | data[1] = (reg << 1) | ((value >> 8) & 1); | ||
67 | data[2] = value & 0xff; | 54 | data[2] = value & 0xff; |
68 | 55 | ||
69 | if (i2c_write(1, data, 3) != 3) | 56 | if (i2c_write(1, data, 3) != 3) |
@@ -75,22 +62,6 @@ void tlv320_write_reg(unsigned reg, unsigned value) | |||
75 | tlv320_regs[reg] = value; | 62 | tlv320_regs[reg] = value; |
76 | } | 63 | } |
77 | 64 | ||
78 | /* Returns 0 if successful or -1 if some register failed */ | ||
79 | void tlv320_set_regs(void) | ||
80 | { | ||
81 | int i; | ||
82 | memset(tlv320_regs, 0, sizeof(tlv320_regs)); | ||
83 | |||
84 | /* Initialize all registers */ | ||
85 | for (i=0; i<NUM_DEFAULT_REGS; i++) | ||
86 | { | ||
87 | unsigned reg = tlv320_defaults[i*2+0]; | ||
88 | unsigned value = tlv320_defaults[i*2+1]; | ||
89 | |||
90 | tlv320_write_reg(reg, value); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /* public functions */ | 65 | /* public functions */ |
95 | 66 | ||
96 | /** | 67 | /** |
@@ -98,8 +69,19 @@ void tlv320_set_regs(void) | |||
98 | */ | 69 | */ |
99 | void tlv320_init(void) | 70 | void tlv320_init(void) |
100 | { | 71 | { |
101 | tlv320_reset(); | 72 | memset(tlv320_regs, 0, sizeof(tlv320_regs)); |
102 | tlv320_set_regs(); | 73 | |
74 | /* Initialize all registers */ | ||
75 | |||
76 | tlv320_write_reg(REG_PC, 0x00); /* All ON */ | ||
77 | tlv320_set_linein_vol(0, 0); | ||
78 | tlv320_mute(true); | ||
79 | tlv320_write_reg(REG_AAP, AAP_DAC|AAP_MICM); | ||
80 | tlv320_write_reg(REG_DAP, 0x00); /* No deemphasis */ | ||
81 | tlv320_write_reg(REG_DAIF, DAIF_IWL_16|DAIF_FOR_I2S); | ||
82 | tlv320_set_headphone_vol(0, 0); | ||
83 | tlv320_write_reg(REG_DIA, DIA_ACT); | ||
84 | tlv320_write_reg(REG_SRC, SRC_CLKIN); | ||
103 | } | 85 | } |
104 | 86 | ||
105 | /** | 87 | /** |
@@ -110,18 +92,6 @@ void tlv320_reset(void) | |||
110 | tlv320_write_reg(REG_RR, RR_RESET); | 92 | tlv320_write_reg(REG_RR, RR_RESET); |
111 | } | 93 | } |
112 | 94 | ||
113 | void tlv320_enable_output(bool enable) | ||
114 | { | ||
115 | unsigned value = tlv320_regs[REG_PC]; | ||
116 | |||
117 | if (enable) | ||
118 | value |= PC_OUT; | ||
119 | else | ||
120 | value &= ~PC_OUT; | ||
121 | |||
122 | tlv320_write_reg(REG_PC, value); | ||
123 | } | ||
124 | |||
125 | /** | 95 | /** |
126 | * Sets left and right headphone volume (127(max) to 48(muted)) | 96 | * Sets left and right headphone volume (127(max) to 48(muted)) |
127 | */ | 97 | */ |
@@ -135,8 +105,8 @@ void tlv320_set_headphone_vol(int vol_l, int vol_r) | |||
135 | tlv320.vol_r = vol_r; | 105 | tlv320.vol_r = vol_r; |
136 | 106 | ||
137 | /* set new values in local register holders */ | 107 | /* set new values in local register holders */ |
138 | value_l |= LHV_LHV(vol_l); | 108 | value_l = LHV_LHV(vol_l); |
139 | value_r |= LHV_LHV(vol_r); | 109 | value_r = RHV_RHV(vol_r); |
140 | 110 | ||
141 | /* update */ | 111 | /* update */ |
142 | tlv320_write_reg(REG_LHV, value_l); | 112 | tlv320_write_reg(REG_LHV, value_l); |
@@ -169,13 +139,13 @@ void tlv320_mute(bool mute) | |||
169 | 139 | ||
170 | if (mute) | 140 | if (mute) |
171 | { | 141 | { |
172 | value_l |= LHV_LHV(HEADPHONE_MUTE); | 142 | value_l = LHV_LHV(HEADPHONE_MUTE); |
173 | value_r |= RHV_RHV(HEADPHONE_MUTE); | 143 | value_r = RHV_RHV(HEADPHONE_MUTE); |
174 | } | 144 | } |
175 | else | 145 | else |
176 | { | 146 | { |
177 | value_l |= LHV_LHV(tlv320.vol_l); | 147 | value_l = LHV_LHV(tlv320.vol_l); |
178 | value_r |= RHV_RHV(tlv320.vol_r); | 148 | value_r = RHV_RHV(tlv320.vol_r); |
179 | } | 149 | } |
180 | 150 | ||
181 | tlv320_write_reg(REG_LHV, value_r); | 151 | tlv320_write_reg(REG_LHV, value_r); |