Lines Matching +full:chip +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Routines for control of the AK4114 via I2C and 4-wire serial interface
25 static void ak4114_init_regs(struct ak4114 *chip);
29 ak4114->write(ak4114->private_data, reg, val); in reg_write()
31 ak4114->regmap[reg] = val; in reg_write()
33 ak4114->txcsb[reg-AK4114_REG_TXCSB0] = val; in reg_write()
38 return ak4114->read(ak4114->private_data, reg); in reg_read()
48 …2x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < ARRAY_SIZE(ak4114->regmap) ? ak4114->regmap[i] :…
52 static void snd_ak4114_free(struct ak4114 *chip) in snd_ak4114_free() argument
54 atomic_inc(&chip->wq_processing); /* don't schedule new work */ in snd_ak4114_free()
55 cancel_delayed_work_sync(&chip->work); in snd_ak4114_free()
56 kfree(chip); in snd_ak4114_free()
61 struct ak4114 *chip = device->device_data; in snd_ak4114_dev_free() local
62 snd_ak4114_free(chip); in snd_ak4114_dev_free()
71 struct ak4114 *chip; in snd_ak4114_create() local
78 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in snd_ak4114_create()
79 if (chip == NULL) in snd_ak4114_create()
80 return -ENOMEM; in snd_ak4114_create()
81 spin_lock_init(&chip->lock); in snd_ak4114_create()
82 chip->card = card; in snd_ak4114_create()
83 chip->read = read; in snd_ak4114_create()
84 chip->write = write; in snd_ak4114_create()
85 chip->private_data = private_data; in snd_ak4114_create()
86 INIT_DELAYED_WORK(&chip->work, ak4114_stats); in snd_ak4114_create()
87 atomic_set(&chip->wq_processing, 0); in snd_ak4114_create()
88 mutex_init(&chip->reinit_mutex); in snd_ak4114_create()
91 chip->regmap[reg] = pgm[reg]; in snd_ak4114_create()
93 chip->txcsb[reg] = txcsb[reg]; in snd_ak4114_create()
95 ak4114_init_regs(chip); in snd_ak4114_create()
97 chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); in snd_ak4114_create()
98 chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); in snd_ak4114_create()
100 err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops); in snd_ak4114_create()
105 *r_ak4114 = chip; in snd_ak4114_create()
109 snd_ak4114_free(chip); in snd_ak4114_create()
114 void snd_ak4114_reg_write(struct ak4114 *chip, unsigned char reg, unsigned char mask, unsigned char… in snd_ak4114_reg_write() argument
117 reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val); in snd_ak4114_reg_write()
119 reg_write(chip, reg, in snd_ak4114_reg_write()
120 (chip->txcsb[reg-AK4114_REG_TXCSB0] & ~mask) | val); in snd_ak4114_reg_write()
124 static void ak4114_init_regs(struct ak4114 *chip) in ak4114_init_regs() argument
126 unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg; in ak4114_init_regs()
128 /* bring the chip to reset state and powerdown state */ in ak4114_init_regs()
129 reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN)); in ak4114_init_regs()
132 reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN); in ak4114_init_regs()
135 reg_write(chip, reg, chip->regmap[reg]); in ak4114_init_regs()
137 reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); in ak4114_init_regs()
139 reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN); in ak4114_init_regs()
142 void snd_ak4114_reinit(struct ak4114 *chip) in snd_ak4114_reinit() argument
144 if (atomic_inc_return(&chip->wq_processing) == 1) in snd_ak4114_reinit()
145 cancel_delayed_work_sync(&chip->work); in snd_ak4114_reinit()
146 mutex_lock(&chip->reinit_mutex); in snd_ak4114_reinit()
147 ak4114_init_regs(chip); in snd_ak4114_reinit()
148 mutex_unlock(&chip->reinit_mutex); in snd_ak4114_reinit()
150 if (atomic_dec_and_test(&chip->wq_processing)) in snd_ak4114_reinit()
151 schedule_delayed_work(&chip->work, HZ / 10); in snd_ak4114_reinit()
172 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ak4114_in_error_info()
173 uinfo->count = 1; in snd_ak4114_in_error_info()
174 uinfo->value.integer.min = 0; in snd_ak4114_in_error_info()
175 uinfo->value.integer.max = LONG_MAX; in snd_ak4114_in_error_info()
182 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_in_error_get() local
184 spin_lock_irq(&chip->lock); in snd_ak4114_in_error_get()
185 ucontrol->value.integer.value[0] = in snd_ak4114_in_error_get()
186 chip->errors[kcontrol->private_value]; in snd_ak4114_in_error_get()
187 chip->errors[kcontrol->private_value] = 0; in snd_ak4114_in_error_get()
188 spin_unlock_irq(&chip->lock); in snd_ak4114_in_error_get()
197 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_in_bit_get() local
198 unsigned char reg = kcontrol->private_value & 0xff; in snd_ak4114_in_bit_get()
199 unsigned char bit = (kcontrol->private_value >> 8) & 0xff; in snd_ak4114_in_bit_get()
200 unsigned char inv = (kcontrol->private_value >> 31) & 1; in snd_ak4114_in_bit_get()
202 ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv; in snd_ak4114_in_bit_get()
209 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ak4114_rate_info()
210 uinfo->count = 1; in snd_ak4114_rate_info()
211 uinfo->value.integer.min = 0; in snd_ak4114_rate_info()
212 uinfo->value.integer.max = 192000; in snd_ak4114_rate_info()
219 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_rate_get() local
221 ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1)); in snd_ak4114_rate_get()
227 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_ak4114_spdif_info()
228 uinfo->count = 1; in snd_ak4114_spdif_info()
235 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_get() local
239 ucontrol->value.iec958.status[i] = reg_read(chip, AK4114_REG_RXCSB0 + i); in snd_ak4114_spdif_get()
246 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_playback_get() local
250 ucontrol->value.iec958.status[i] = chip->txcsb[i]; in snd_ak4114_spdif_playback_get()
257 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_playback_put() local
261 reg_write(chip, AK4114_REG_TXCSB0 + i, ucontrol->value.iec958.status[i]); in snd_ak4114_spdif_playback_put()
267 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_ak4114_spdif_mask_info()
268 uinfo->count = 1; in snd_ak4114_spdif_mask_info()
275 memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE); in snd_ak4114_spdif_mask_get()
281 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ak4114_spdif_pinfo()
282 uinfo->value.integer.min = 0; in snd_ak4114_spdif_pinfo()
283 uinfo->value.integer.max = 0xffff; in snd_ak4114_spdif_pinfo()
284 uinfo->count = 4; in snd_ak4114_spdif_pinfo()
291 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_pget() local
294 ucontrol->value.integer.value[0] = 0xf8f2; in snd_ak4114_spdif_pget()
295 ucontrol->value.integer.value[1] = 0x4e1f; in snd_ak4114_spdif_pget()
296 tmp = reg_read(chip, AK4114_REG_Pc0) | (reg_read(chip, AK4114_REG_Pc1) << 8); in snd_ak4114_spdif_pget()
297 ucontrol->value.integer.value[2] = tmp; in snd_ak4114_spdif_pget()
298 tmp = reg_read(chip, AK4114_REG_Pd0) | (reg_read(chip, AK4114_REG_Pd1) << 8); in snd_ak4114_spdif_pget()
299 ucontrol->value.integer.value[3] = tmp; in snd_ak4114_spdif_pget()
305 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in snd_ak4114_spdif_qinfo()
306 uinfo->count = AK4114_REG_QSUB_SIZE; in snd_ak4114_spdif_qinfo()
313 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_qget() local
317 ucontrol->value.bytes.data[i] = reg_read(chip, AK4114_REG_QSUB_ADDR + i); in snd_ak4114_spdif_qget()
333 .name = "IEC958 V-Bit Errors",
341 .name = "IEC958 C-CRC Errors",
349 .name = "IEC958 Q-CRC Errors",
400 .name = "IEC958 Q-subcode Capture Default",
415 .name = "IEC958 Non-PCM Bitstream",
443 struct ak4114 *ak4114 = entry->private_data; in snd_ak4114_proc_regs_read()
445 /* all ak4114 registers 0x00 - 0x1f */ in snd_ak4114_proc_regs_read()
454 snd_card_ro_proc_new(ak4114->card, "ak4114", ak4114, in snd_ak4114_proc_init()
467 return -EINVAL; in snd_ak4114_build()
468 ak4114->playback_substream = ply_substream; in snd_ak4114_build()
469 ak4114->capture_substream = cap_substream; in snd_ak4114_build()
473 return -ENOMEM; in snd_ak4114_build()
474 if (strstr(kctl->id.name, "Playback")) { in snd_ak4114_build()
477 ak4114->kctls[idx] = NULL; in snd_ak4114_build()
480 kctl->id.device = ply_substream->pcm->device; in snd_ak4114_build()
481 kctl->id.subdevice = ply_substream->number; in snd_ak4114_build()
483 kctl->id.device = cap_substream->pcm->device; in snd_ak4114_build()
484 kctl->id.subdevice = cap_substream->number; in snd_ak4114_build()
486 err = snd_ctl_add(ak4114->card, kctl); in snd_ak4114_build()
489 ak4114->kctls[idx] = kctl; in snd_ak4114_build()
493 schedule_delayed_work(&ak4114->work, HZ / 10); in snd_ak4114_build()
503 if (!ak4114->kctls[0]) in ak4114_notify()
507 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
508 &ak4114->kctls[0]->id); in ak4114_notify()
510 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
511 &ak4114->kctls[1]->id); in ak4114_notify()
513 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
514 &ak4114->kctls[2]->id); in ak4114_notify()
516 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
517 &ak4114->kctls[3]->id); in ak4114_notify()
521 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
522 &ak4114->kctls[4]->id); in ak4114_notify()
525 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
526 &ak4114->kctls[9]->id); in ak4114_notify()
528 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
529 &ak4114->kctls[10]->id); in ak4114_notify()
532 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
533 &ak4114->kctls[11]->id); in ak4114_notify()
535 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
536 &ak4114->kctls[12]->id); in ak4114_notify()
538 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
539 &ak4114->kctls[13]->id); in ak4114_notify()
541 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
542 &ak4114->kctls[14]->id); in ak4114_notify()
556 …struct snd_pcm_runtime *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime :… in snd_ak4114_check_rate_and_errors()
566 spin_lock_irqsave(&ak4114->lock, _flags); in snd_ak4114_check_rate_and_errors()
568 ak4114->errors[AK4114_PARITY_ERRORS]++; in snd_ak4114_check_rate_and_errors()
570 ak4114->errors[AK4114_V_BIT_ERRORS]++; in snd_ak4114_check_rate_and_errors()
572 ak4114->errors[AK4114_CCRC_ERRORS]++; in snd_ak4114_check_rate_and_errors()
574 ak4114->errors[AK4114_QCRC_ERRORS]++; in snd_ak4114_check_rate_and_errors()
575 …c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK411… in snd_ak4114_check_rate_and_errors()
577 c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0); in snd_ak4114_check_rate_and_errors()
578 ak4114->rcs0 = rcs0 & ~(AK4114_QINT | AK4114_CINT); in snd_ak4114_check_rate_and_errors()
579 ak4114->rcs1 = rcs1; in snd_ak4114_check_rate_and_errors()
580 spin_unlock_irqrestore(&ak4114->lock, _flags); in snd_ak4114_check_rate_and_errors()
583 if (ak4114->change_callback && (c0 | c1) != 0) in snd_ak4114_check_rate_and_errors()
584 ak4114->change_callback(ak4114, c0, c1); in snd_ak4114_check_rate_and_errors()
589 if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) { in snd_ak4114_check_rate_and_errors()
590 snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags); in snd_ak4114_check_rate_and_errors()
591 if (snd_pcm_running(ak4114->capture_substream)) { in snd_ak4114_check_rate_and_errors()
592 // printk(KERN_DEBUG "rate changed (%i <- %i)\n", runtime->rate, res); in snd_ak4114_check_rate_and_errors()
593 snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING); in snd_ak4114_check_rate_and_errors()
596 snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags); in snd_ak4114_check_rate_and_errors()
604 struct ak4114 *chip = container_of(work, struct ak4114, work.work); in ak4114_stats() local
606 if (atomic_inc_return(&chip->wq_processing) == 1) in ak4114_stats()
607 snd_ak4114_check_rate_and_errors(chip, chip->check_flags); in ak4114_stats()
608 if (atomic_dec_and_test(&chip->wq_processing)) in ak4114_stats()
609 schedule_delayed_work(&chip->work, HZ / 10); in ak4114_stats()
613 void snd_ak4114_suspend(struct ak4114 *chip) in snd_ak4114_suspend() argument
615 atomic_inc(&chip->wq_processing); /* don't schedule new work */ in snd_ak4114_suspend()
616 cancel_delayed_work_sync(&chip->work); in snd_ak4114_suspend()
620 void snd_ak4114_resume(struct ak4114 *chip) in snd_ak4114_resume() argument
622 atomic_dec(&chip->wq_processing); in snd_ak4114_resume()
623 snd_ak4114_reinit(chip); in snd_ak4114_resume()