Lines Matching +full:bus +full:- +full:err

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Routines for control of the TEA6330T circuit via i2c bus
16 MODULE_DESCRIPTION("Routines for control of the TEA6330T circuit via i2c bus");
27 #define TEA6330T_FCH 0x10 /* select fader channels - front or rear */
30 #define TEA6330T_EQN 0x40 /* equalizer switchover (0=equalizer-on) */
35 struct snd_i2c_bus *bus; member
45 int snd_tea6330t_detect(struct snd_i2c_bus *bus, int equalizer) in snd_tea6330t_detect() argument
49 snd_i2c_lock(bus); in snd_tea6330t_detect()
50 res = snd_i2c_probeaddr(bus, TEA6330T_ADDR); in snd_tea6330t_detect()
51 snd_i2c_unlock(bus); in snd_tea6330t_detect()
59 snd_i2c_write(tea->bus, TEA6330T_ADDR, addr, value, 1);
71 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_tea6330t_info_master_volume()
72 uinfo->count = 2; in snd_tea6330t_info_master_volume()
73 uinfo->value.integer.min = 0; in snd_tea6330t_info_master_volume()
74 uinfo->value.integer.max = 43; in snd_tea6330t_info_master_volume()
83 snd_i2c_lock(tea->bus); in snd_tea6330t_get_master_volume()
84 ucontrol->value.integer.value[0] = tea->mleft - 0x14; in snd_tea6330t_get_master_volume()
85 ucontrol->value.integer.value[1] = tea->mright - 0x14; in snd_tea6330t_get_master_volume()
86 snd_i2c_unlock(tea->bus); in snd_tea6330t_get_master_volume()
94 int change, count, err; in snd_tea6330t_put_master_volume() local
98 val1 = (ucontrol->value.integer.value[0] % 44) + 0x14; in snd_tea6330t_put_master_volume()
99 val2 = (ucontrol->value.integer.value[1] % 44) + 0x14; in snd_tea6330t_put_master_volume()
100 snd_i2c_lock(tea->bus); in snd_tea6330t_put_master_volume()
101 change = val1 != tea->mleft || val2 != tea->mright; in snd_tea6330t_put_master_volume()
102 tea->mleft = val1; in snd_tea6330t_put_master_volume()
103 tea->mright = val2; in snd_tea6330t_put_master_volume()
105 if (tea->regs[TEA6330T_SADDR_VOLUME_LEFT] != 0) { in snd_tea6330t_put_master_volume()
107 bytes[count++] = tea->regs[TEA6330T_SADDR_VOLUME_LEFT] = tea->mleft; in snd_tea6330t_put_master_volume()
109 if (tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] != 0) { in snd_tea6330t_put_master_volume()
112 bytes[count++] = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] = tea->mright; in snd_tea6330t_put_master_volume()
115 err = snd_i2c_sendbytes(tea->device, bytes, count); in snd_tea6330t_put_master_volume()
116 if (err < 0) in snd_tea6330t_put_master_volume()
117 change = err; in snd_tea6330t_put_master_volume()
119 snd_i2c_unlock(tea->bus); in snd_tea6330t_put_master_volume()
135 snd_i2c_lock(tea->bus); in snd_tea6330t_get_master_switch()
136 ucontrol->value.integer.value[0] = tea->regs[TEA6330T_SADDR_VOLUME_LEFT] == 0 ? 0 : 1; in snd_tea6330t_get_master_switch()
137 ucontrol->value.integer.value[1] = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] == 0 ? 0 : 1; in snd_tea6330t_get_master_switch()
138 snd_i2c_unlock(tea->bus); in snd_tea6330t_get_master_switch()
146 int change, err; in snd_tea6330t_put_master_switch() local
150 val1 = ucontrol->value.integer.value[0] & 1; in snd_tea6330t_put_master_switch()
151 val2 = ucontrol->value.integer.value[1] & 1; in snd_tea6330t_put_master_switch()
152 snd_i2c_lock(tea->bus); in snd_tea6330t_put_master_switch()
153 oval1 = tea->regs[TEA6330T_SADDR_VOLUME_LEFT] == 0 ? 0 : 1; in snd_tea6330t_put_master_switch()
154 oval2 = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] == 0 ? 0 : 1; in snd_tea6330t_put_master_switch()
156 tea->regs[TEA6330T_SADDR_VOLUME_LEFT] = val1 ? tea->mleft : 0; in snd_tea6330t_put_master_switch()
157 tea->regs[TEA6330T_SADDR_VOLUME_RIGHT] = val2 ? tea->mright : 0; in snd_tea6330t_put_master_switch()
159 bytes[1] = tea->regs[TEA6330T_SADDR_VOLUME_LEFT]; in snd_tea6330t_put_master_switch()
160 bytes[2] = tea->regs[TEA6330T_SADDR_VOLUME_RIGHT]; in snd_tea6330t_put_master_switch()
161 err = snd_i2c_sendbytes(tea->device, bytes, 3); in snd_tea6330t_put_master_switch()
162 if (err < 0) in snd_tea6330t_put_master_switch()
163 change = err; in snd_tea6330t_put_master_switch()
164 snd_i2c_unlock(tea->bus); in snd_tea6330t_put_master_switch()
178 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_tea6330t_info_bass()
179 uinfo->count = 1; in snd_tea6330t_info_bass()
180 uinfo->value.integer.min = 0; in snd_tea6330t_info_bass()
181 uinfo->value.integer.max = tea->max_bass; in snd_tea6330t_info_bass()
190 ucontrol->value.integer.value[0] = tea->bass; in snd_tea6330t_get_bass()
198 int change, err; in snd_tea6330t_put_bass() local
202 val1 = ucontrol->value.integer.value[0] % (tea->max_bass + 1); in snd_tea6330t_put_bass()
203 snd_i2c_lock(tea->bus); in snd_tea6330t_put_bass()
204 tea->bass = val1; in snd_tea6330t_put_bass()
205 val1 += tea->equalizer ? 7 : 3; in snd_tea6330t_put_bass()
206 change = tea->regs[TEA6330T_SADDR_BASS] != val1; in snd_tea6330t_put_bass()
208 bytes[1] = tea->regs[TEA6330T_SADDR_BASS] = val1; in snd_tea6330t_put_bass()
209 err = snd_i2c_sendbytes(tea->device, bytes, 2); in snd_tea6330t_put_bass()
210 if (err < 0) in snd_tea6330t_put_bass()
211 change = err; in snd_tea6330t_put_bass()
212 snd_i2c_unlock(tea->bus); in snd_tea6330t_put_bass()
226 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_tea6330t_info_treble()
227 uinfo->count = 1; in snd_tea6330t_info_treble()
228 uinfo->value.integer.min = 0; in snd_tea6330t_info_treble()
229 uinfo->value.integer.max = tea->max_treble; in snd_tea6330t_info_treble()
238 ucontrol->value.integer.value[0] = tea->treble; in snd_tea6330t_get_treble()
246 int change, err; in snd_tea6330t_put_treble() local
250 val1 = ucontrol->value.integer.value[0] % (tea->max_treble + 1); in snd_tea6330t_put_treble()
251 snd_i2c_lock(tea->bus); in snd_tea6330t_put_treble()
252 tea->treble = val1; in snd_tea6330t_put_treble()
254 change = tea->regs[TEA6330T_SADDR_TREBLE] != val1; in snd_tea6330t_put_treble()
256 bytes[1] = tea->regs[TEA6330T_SADDR_TREBLE] = val1; in snd_tea6330t_put_treble()
257 err = snd_i2c_sendbytes(tea->device, bytes, 2); in snd_tea6330t_put_treble()
258 if (err < 0) in snd_tea6330t_put_treble()
259 change = err; in snd_tea6330t_put_treble()
260 snd_i2c_unlock(tea->bus); in snd_tea6330t_put_treble()
267 TEA6330T_BASS("Tone Control - Bass", 0),
268 TEA6330T_TREBLE("Tone Control - Treble", 0)
273 kfree(device->private_data); in snd_tea6330_free()
277 struct snd_i2c_bus *bus, in snd_tea6330t_update_mixer() argument
284 int err; in snd_tea6330t_update_mixer() local
290 return -ENOMEM; in snd_tea6330t_update_mixer()
291 err = snd_i2c_device_create(bus, "TEA6330T", TEA6330T_ADDR, &device); in snd_tea6330t_update_mixer()
292 if (err < 0) { in snd_tea6330t_update_mixer()
294 return err; in snd_tea6330t_update_mixer()
296 tea->device = device; in snd_tea6330t_update_mixer()
297 tea->bus = bus; in snd_tea6330t_update_mixer()
298 tea->equalizer = equalizer; in snd_tea6330t_update_mixer()
299 tea->fader = fader; in snd_tea6330t_update_mixer()
300 device->private_data = tea; in snd_tea6330t_update_mixer()
301 device->private_free = snd_tea6330_free; in snd_tea6330t_update_mixer()
303 snd_i2c_lock(bus); in snd_tea6330t_update_mixer()
306 tea->regs[TEA6330T_SADDR_FADER] = 0x3f; in snd_tea6330t_update_mixer()
307 tea->regs[TEA6330T_SADDR_AUDIO_SWITCH] = equalizer ? 0 : TEA6330T_EQN; in snd_tea6330t_update_mixer()
309 if (!tea->equalizer) { in snd_tea6330t_update_mixer()
310 tea->max_bass = 9; in snd_tea6330t_update_mixer()
311 tea->max_treble = 8; in snd_tea6330t_update_mixer()
313 tea->bass = 4; in snd_tea6330t_update_mixer()
315 tea->treble = 4; in snd_tea6330t_update_mixer()
317 tea->max_bass = 5; in snd_tea6330t_update_mixer()
318 tea->max_treble = 0; in snd_tea6330t_update_mixer()
320 tea->bass = 4; in snd_tea6330t_update_mixer()
322 tea->treble = 0; in snd_tea6330t_update_mixer()
324 tea->mleft = tea->mright = 0x14; in snd_tea6330t_update_mixer()
325 tea->regs[TEA6330T_SADDR_BASS] = default_bass; in snd_tea6330t_update_mixer()
326 tea->regs[TEA6330T_SADDR_TREBLE] = default_treble; in snd_tea6330t_update_mixer()
331 bytes[idx+1] = tea->regs[idx]; in snd_tea6330t_update_mixer()
332 err = snd_i2c_sendbytes(device, bytes, 7); in snd_tea6330t_update_mixer()
333 if (err < 0) in snd_tea6330t_update_mixer()
336 strcat(card->mixername, ",TEA6330T"); in snd_tea6330t_update_mixer()
337 err = snd_component_add(card, "TEA6330T"); in snd_tea6330t_update_mixer()
338 if (err < 0) in snd_tea6330t_update_mixer()
343 if (tea->treble == 0 && !strcmp(knew->name, "Tone Control - Treble")) in snd_tea6330t_update_mixer()
345 err = snd_ctl_add(card, snd_ctl_new1(knew, tea)); in snd_tea6330t_update_mixer()
346 if (err < 0) in snd_tea6330t_update_mixer()
350 snd_i2c_unlock(bus); in snd_tea6330t_update_mixer()
354 snd_i2c_unlock(bus); in snd_tea6330t_update_mixer()
356 return err; in snd_tea6330t_update_mixer()