Lines Matching +full:i2c +full:- +full:retry +full:- +full:count
1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * --
11 * --
27 mask = emu->audigy ? A_PTR_ADDRESS_MASK : PTR_ADDRESS_MASK; in snd_emu10k1_ptr_read()
35 mask = ((1 << size) - 1) << offset; in snd_emu10k1_ptr_read()
37 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ptr_read()
38 outl(regptr, emu->port + PTR); in snd_emu10k1_ptr_read()
39 val = inl(emu->port + DATA); in snd_emu10k1_ptr_read()
40 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ptr_read()
44 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ptr_read()
45 outl(regptr, emu->port + PTR); in snd_emu10k1_ptr_read()
46 val = inl(emu->port + DATA); in snd_emu10k1_ptr_read()
47 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ptr_read()
62 mask = emu->audigy ? A_PTR_ADDRESS_MASK : PTR_ADDRESS_MASK; in snd_emu10k1_ptr_write()
70 mask = ((1 << size) - 1) << offset; in snd_emu10k1_ptr_write()
73 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ptr_write()
74 outl(regptr, emu->port + PTR); in snd_emu10k1_ptr_write()
75 data |= inl(emu->port + DATA) & ~mask; in snd_emu10k1_ptr_write()
76 outl(data, emu->port + DATA); in snd_emu10k1_ptr_write()
77 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ptr_write()
79 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ptr_write()
80 outl(regptr, emu->port + PTR); in snd_emu10k1_ptr_write()
81 outl(data, emu->port + DATA); in snd_emu10k1_ptr_write()
82 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ptr_write()
97 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ptr20_read()
98 outl(regptr, emu->port + 0x20 + PTR); in snd_emu10k1_ptr20_read()
99 val = inl(emu->port + 0x20 + DATA); in snd_emu10k1_ptr20_read()
100 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ptr20_read()
114 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ptr20_write()
115 outl(regptr, emu->port + 0x20 + PTR); in snd_emu10k1_ptr20_write()
116 outl(data, emu->port + 0x20 + DATA); in snd_emu10k1_ptr20_write()
117 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ptr20_write()
128 /* This function is not re-entrant, so protect against it. */ in snd_emu10k1_spi_write()
129 spin_lock(&emu->spi_lock); in snd_emu10k1_spi_write()
130 if (emu->card_capabilities->ca0108_chip) in snd_emu10k1_spi_write()
169 spin_unlock(&emu->spi_lock); in snd_emu10k1_spi_write()
173 /* The ADC does not support i2c read, so only write is implemented */
181 int retry; in snd_emu10k1_i2c_write() local
185 dev_err(emu->card->dev, "i2c_write: invalid values.\n"); in snd_emu10k1_i2c_write()
186 return -EINVAL; in snd_emu10k1_i2c_write()
189 /* This function is not re-entrant, so protect against it. */ in snd_emu10k1_i2c_write()
190 spin_lock(&emu->i2c_lock); in snd_emu10k1_i2c_write()
194 /* This controls the I2C connected to the WM8775 ADC Codec */ in snd_emu10k1_i2c_write()
198 for (retry = 0; retry < 10; retry++) { in snd_emu10k1_i2c_write()
199 /* Send the data to i2c */ in snd_emu10k1_i2c_write()
213 dev_warn(emu->card->dev, in snd_emu10k1_i2c_write()
214 "emu10k1:I2C:timeout status=0x%x\n", in snd_emu10k1_i2c_write()
224 if (retry == 10) { in snd_emu10k1_i2c_write()
225 dev_err(emu->card->dev, "Writing to ADC failed!\n"); in snd_emu10k1_i2c_write()
226 dev_err(emu->card->dev, "status=0x%x, reg=%d, value=%d\n", in snd_emu10k1_i2c_write()
229 err = -EINVAL; in snd_emu10k1_i2c_write()
232 spin_unlock(&emu->i2c_lock); in snd_emu10k1_i2c_write()
245 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu1010_fpga_write()
246 outl(reg, emu->port + A_IOCFG); in snd_emu1010_fpga_write()
248 outl(reg | 0x80, emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */ in snd_emu1010_fpga_write()
250 outl(value, emu->port + A_IOCFG); in snd_emu1010_fpga_write()
252 outl(value | 0x80 , emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */ in snd_emu1010_fpga_write()
253 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu1010_fpga_write()
264 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu1010_fpga_read()
265 outl(reg, emu->port + A_IOCFG); in snd_emu1010_fpga_read()
267 outl(reg | 0x80, emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */ in snd_emu1010_fpga_read()
269 *value = ((inl(emu->port + A_IOCFG) >> 8) & 0x7f); in snd_emu1010_fpga_read()
270 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu1010_fpga_read()
293 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_intr_enable()
294 enable = inl(emu->port + INTE) | intrenb; in snd_emu10k1_intr_enable()
295 outl(enable, emu->port + INTE); in snd_emu10k1_intr_enable()
296 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_intr_enable()
304 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_intr_disable()
305 enable = inl(emu->port + INTE) & ~intrenb; in snd_emu10k1_intr_disable()
306 outl(enable, emu->port + INTE); in snd_emu10k1_intr_disable()
307 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_intr_disable()
315 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_intr_enable()
318 outl(CLIEH << 16, emu->port + PTR); in snd_emu10k1_voice_intr_enable()
319 val = inl(emu->port + DATA); in snd_emu10k1_voice_intr_enable()
320 val |= 1 << (voicenum - 32); in snd_emu10k1_voice_intr_enable()
322 outl(CLIEL << 16, emu->port + PTR); in snd_emu10k1_voice_intr_enable()
323 val = inl(emu->port + DATA); in snd_emu10k1_voice_intr_enable()
326 outl(val, emu->port + DATA); in snd_emu10k1_voice_intr_enable()
327 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_intr_enable()
335 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_intr_disable()
338 outl(CLIEH << 16, emu->port + PTR); in snd_emu10k1_voice_intr_disable()
339 val = inl(emu->port + DATA); in snd_emu10k1_voice_intr_disable()
340 val &= ~(1 << (voicenum - 32)); in snd_emu10k1_voice_intr_disable()
342 outl(CLIEL << 16, emu->port + PTR); in snd_emu10k1_voice_intr_disable()
343 val = inl(emu->port + DATA); in snd_emu10k1_voice_intr_disable()
346 outl(val, emu->port + DATA); in snd_emu10k1_voice_intr_disable()
347 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_intr_disable()
354 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_intr_ack()
357 outl(CLIPH << 16, emu->port + PTR); in snd_emu10k1_voice_intr_ack()
358 voicenum = 1 << (voicenum - 32); in snd_emu10k1_voice_intr_ack()
360 outl(CLIPL << 16, emu->port + PTR); in snd_emu10k1_voice_intr_ack()
363 outl(voicenum, emu->port + DATA); in snd_emu10k1_voice_intr_ack()
364 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_intr_ack()
372 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_half_loop_intr_enable()
375 outl(HLIEH << 16, emu->port + PTR); in snd_emu10k1_voice_half_loop_intr_enable()
376 val = inl(emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_enable()
377 val |= 1 << (voicenum - 32); in snd_emu10k1_voice_half_loop_intr_enable()
379 outl(HLIEL << 16, emu->port + PTR); in snd_emu10k1_voice_half_loop_intr_enable()
380 val = inl(emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_enable()
383 outl(val, emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_enable()
384 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_half_loop_intr_enable()
392 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_half_loop_intr_disable()
395 outl(HLIEH << 16, emu->port + PTR); in snd_emu10k1_voice_half_loop_intr_disable()
396 val = inl(emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_disable()
397 val &= ~(1 << (voicenum - 32)); in snd_emu10k1_voice_half_loop_intr_disable()
399 outl(HLIEL << 16, emu->port + PTR); in snd_emu10k1_voice_half_loop_intr_disable()
400 val = inl(emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_disable()
403 outl(val, emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_disable()
404 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_half_loop_intr_disable()
411 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_half_loop_intr_ack()
414 outl(HLIPH << 16, emu->port + PTR); in snd_emu10k1_voice_half_loop_intr_ack()
415 voicenum = 1 << (voicenum - 32); in snd_emu10k1_voice_half_loop_intr_ack()
417 outl(HLIPL << 16, emu->port + PTR); in snd_emu10k1_voice_half_loop_intr_ack()
420 outl(voicenum, emu->port + DATA); in snd_emu10k1_voice_half_loop_intr_ack()
421 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_half_loop_intr_ack()
429 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_set_loop_stop()
432 outl(SOLEH << 16, emu->port + PTR); in snd_emu10k1_voice_set_loop_stop()
433 sol = inl(emu->port + DATA); in snd_emu10k1_voice_set_loop_stop()
434 sol |= 1 << (voicenum - 32); in snd_emu10k1_voice_set_loop_stop()
436 outl(SOLEL << 16, emu->port + PTR); in snd_emu10k1_voice_set_loop_stop()
437 sol = inl(emu->port + DATA); in snd_emu10k1_voice_set_loop_stop()
440 outl(sol, emu->port + DATA); in snd_emu10k1_voice_set_loop_stop()
441 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_set_loop_stop()
449 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_voice_clear_loop_stop()
452 outl(SOLEH << 16, emu->port + PTR); in snd_emu10k1_voice_clear_loop_stop()
453 sol = inl(emu->port + DATA); in snd_emu10k1_voice_clear_loop_stop()
454 sol &= ~(1 << (voicenum - 32)); in snd_emu10k1_voice_clear_loop_stop()
456 outl(SOLEL << 16, emu->port + PTR); in snd_emu10k1_voice_clear_loop_stop()
457 sol = inl(emu->port + DATA); in snd_emu10k1_voice_clear_loop_stop()
460 outl(sol, emu->port + DATA); in snd_emu10k1_voice_clear_loop_stop()
461 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_voice_clear_loop_stop()
466 volatile unsigned count; in snd_emu10k1_wait() local
469 curtime = inl(emu->port + WC) >> 6; in snd_emu10k1_wait()
470 while (wait-- > 0) { in snd_emu10k1_wait()
471 count = 0; in snd_emu10k1_wait()
472 while (count++ < 16384) { in snd_emu10k1_wait()
473 newtime = inl(emu->port + WC) >> 6; in snd_emu10k1_wait()
477 if (count > 16384) in snd_emu10k1_wait()
485 struct snd_emu10k1 *emu = ac97->private_data; in snd_emu10k1_ac97_read()
489 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ac97_read()
490 outb(reg, emu->port + AC97ADDRESS); in snd_emu10k1_ac97_read()
491 val = inw(emu->port + AC97DATA); in snd_emu10k1_ac97_read()
492 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ac97_read()
498 struct snd_emu10k1 *emu = ac97->private_data; in snd_emu10k1_ac97_write()
501 spin_lock_irqsave(&emu->emu_lock, flags); in snd_emu10k1_ac97_write()
502 outb(reg, emu->port + AC97ADDRESS); in snd_emu10k1_ac97_write()
503 outw(data, emu->port + AC97DATA); in snd_emu10k1_ac97_write()
504 spin_unlock_irqrestore(&emu->emu_lock, flags); in snd_emu10k1_ac97_write()
554 for (i = 31; i > 0; i--) { in snd_emu10k1_rate_to_pitch()
556 return (((unsigned int) (i - 15) << 20) + in snd_emu10k1_rate_to_pitch()