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()
41 static void snd_ak4114_free(struct ak4114 *chip) in snd_ak4114_free() argument
43 atomic_inc(&chip->wq_processing); /* don't schedule new work */ in snd_ak4114_free()
44 cancel_delayed_work_sync(&chip->work); in snd_ak4114_free()
45 kfree(chip); in snd_ak4114_free()
50 struct ak4114 *chip = device->device_data; in snd_ak4114_dev_free() local
51 snd_ak4114_free(chip); in snd_ak4114_dev_free()
60 struct ak4114 *chip; in snd_ak4114_create() local
67 chip = kzalloc(sizeof(*chip), GFP_KERNEL); in snd_ak4114_create()
68 if (chip == NULL) in snd_ak4114_create()
69 return -ENOMEM; in snd_ak4114_create()
70 spin_lock_init(&chip->lock); in snd_ak4114_create()
71 chip->card = card; in snd_ak4114_create()
72 chip->read = read; in snd_ak4114_create()
73 chip->write = write; in snd_ak4114_create()
74 chip->private_data = private_data; in snd_ak4114_create()
75 INIT_DELAYED_WORK(&chip->work, ak4114_stats); in snd_ak4114_create()
76 atomic_set(&chip->wq_processing, 0); in snd_ak4114_create()
77 mutex_init(&chip->reinit_mutex); in snd_ak4114_create()
80 chip->regmap[reg] = pgm[reg]; in snd_ak4114_create()
82 chip->txcsb[reg] = txcsb[reg]; in snd_ak4114_create()
84 ak4114_init_regs(chip); in snd_ak4114_create()
86 chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT); in snd_ak4114_create()
87 chip->rcs1 = reg_read(chip, AK4114_REG_RCS1); in snd_ak4114_create()
89 err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops); in snd_ak4114_create()
94 *r_ak4114 = chip; in snd_ak4114_create()
98 snd_ak4114_free(chip); in snd_ak4114_create()
103 void snd_ak4114_reg_write(struct ak4114 *chip, unsigned char reg, unsigned char mask, unsigned char… in snd_ak4114_reg_write() argument
106 reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val); in snd_ak4114_reg_write()
108 reg_write(chip, reg, in snd_ak4114_reg_write()
109 (chip->txcsb[reg-AK4114_REG_TXCSB0] & ~mask) | val); in snd_ak4114_reg_write()
113 static void ak4114_init_regs(struct ak4114 *chip) in ak4114_init_regs() argument
115 unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg; in ak4114_init_regs()
117 /* bring the chip to reset state and powerdown state */ in ak4114_init_regs()
118 reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN)); in ak4114_init_regs()
121 reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN); in ak4114_init_regs()
124 reg_write(chip, reg, chip->regmap[reg]); in ak4114_init_regs()
126 reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]); in ak4114_init_regs()
128 reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN); in ak4114_init_regs()
131 void snd_ak4114_reinit(struct ak4114 *chip) in snd_ak4114_reinit() argument
133 if (atomic_inc_return(&chip->wq_processing) == 1) in snd_ak4114_reinit()
134 cancel_delayed_work_sync(&chip->work); in snd_ak4114_reinit()
135 mutex_lock(&chip->reinit_mutex); in snd_ak4114_reinit()
136 ak4114_init_regs(chip); in snd_ak4114_reinit()
137 mutex_unlock(&chip->reinit_mutex); in snd_ak4114_reinit()
139 if (atomic_dec_and_test(&chip->wq_processing)) in snd_ak4114_reinit()
140 schedule_delayed_work(&chip->work, HZ / 10); in snd_ak4114_reinit()
161 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ak4114_in_error_info()
162 uinfo->count = 1; in snd_ak4114_in_error_info()
163 uinfo->value.integer.min = 0; in snd_ak4114_in_error_info()
164 uinfo->value.integer.max = LONG_MAX; in snd_ak4114_in_error_info()
171 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_in_error_get() local
173 spin_lock_irq(&chip->lock); in snd_ak4114_in_error_get()
174 ucontrol->value.integer.value[0] = in snd_ak4114_in_error_get()
175 chip->errors[kcontrol->private_value]; in snd_ak4114_in_error_get()
176 chip->errors[kcontrol->private_value] = 0; in snd_ak4114_in_error_get()
177 spin_unlock_irq(&chip->lock); in snd_ak4114_in_error_get()
186 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_in_bit_get() local
187 unsigned char reg = kcontrol->private_value & 0xff; in snd_ak4114_in_bit_get()
188 unsigned char bit = (kcontrol->private_value >> 8) & 0xff; in snd_ak4114_in_bit_get()
189 unsigned char inv = (kcontrol->private_value >> 31) & 1; in snd_ak4114_in_bit_get()
191 ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv; in snd_ak4114_in_bit_get()
198 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ak4114_rate_info()
199 uinfo->count = 1; in snd_ak4114_rate_info()
200 uinfo->value.integer.min = 0; in snd_ak4114_rate_info()
201 uinfo->value.integer.max = 192000; in snd_ak4114_rate_info()
208 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_rate_get() local
210 ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1)); in snd_ak4114_rate_get()
216 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_ak4114_spdif_info()
217 uinfo->count = 1; in snd_ak4114_spdif_info()
224 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_get() local
228 ucontrol->value.iec958.status[i] = reg_read(chip, AK4114_REG_RXCSB0 + i); in snd_ak4114_spdif_get()
235 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_playback_get() local
239 ucontrol->value.iec958.status[i] = chip->txcsb[i]; in snd_ak4114_spdif_playback_get()
246 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_playback_put() local
250 reg_write(chip, AK4114_REG_TXCSB0 + i, ucontrol->value.iec958.status[i]); in snd_ak4114_spdif_playback_put()
256 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_ak4114_spdif_mask_info()
257 uinfo->count = 1; in snd_ak4114_spdif_mask_info()
264 memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE); in snd_ak4114_spdif_mask_get()
270 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_ak4114_spdif_pinfo()
271 uinfo->value.integer.min = 0; in snd_ak4114_spdif_pinfo()
272 uinfo->value.integer.max = 0xffff; in snd_ak4114_spdif_pinfo()
273 uinfo->count = 4; in snd_ak4114_spdif_pinfo()
280 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_pget() local
283 ucontrol->value.integer.value[0] = 0xf8f2; in snd_ak4114_spdif_pget()
284 ucontrol->value.integer.value[1] = 0x4e1f; in snd_ak4114_spdif_pget()
285 tmp = reg_read(chip, AK4114_REG_Pc0) | (reg_read(chip, AK4114_REG_Pc1) << 8); in snd_ak4114_spdif_pget()
286 ucontrol->value.integer.value[2] = tmp; in snd_ak4114_spdif_pget()
287 tmp = reg_read(chip, AK4114_REG_Pd0) | (reg_read(chip, AK4114_REG_Pd1) << 8); in snd_ak4114_spdif_pget()
288 ucontrol->value.integer.value[3] = tmp; in snd_ak4114_spdif_pget()
294 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in snd_ak4114_spdif_qinfo()
295 uinfo->count = AK4114_REG_QSUB_SIZE; in snd_ak4114_spdif_qinfo()
302 struct ak4114 *chip = snd_kcontrol_chip(kcontrol); in snd_ak4114_spdif_qget() local
306 ucontrol->value.bytes.data[i] = reg_read(chip, AK4114_REG_QSUB_ADDR + i); in snd_ak4114_spdif_qget()
322 .name = "IEC958 V-Bit Errors",
330 .name = "IEC958 C-CRC Errors",
338 .name = "IEC958 Q-CRC Errors",
389 .name = "IEC958 Q-subcode Capture Default",
404 .name = "IEC958 Non-PCM Bitstream",
432 struct ak4114 *ak4114 = entry->private_data; in snd_ak4114_proc_regs_read()
434 /* all ak4114 registers 0x00 - 0x1f */ in snd_ak4114_proc_regs_read()
443 snd_card_ro_proc_new(ak4114->card, "ak4114", ak4114, in snd_ak4114_proc_init()
456 return -EINVAL; in snd_ak4114_build()
457 ak4114->playback_substream = ply_substream; in snd_ak4114_build()
458 ak4114->capture_substream = cap_substream; in snd_ak4114_build()
462 return -ENOMEM; in snd_ak4114_build()
463 if (strstr(kctl->id.name, "Playback")) { in snd_ak4114_build()
466 ak4114->kctls[idx] = NULL; in snd_ak4114_build()
469 kctl->id.device = ply_substream->pcm->device; in snd_ak4114_build()
470 kctl->id.subdevice = ply_substream->number; in snd_ak4114_build()
472 kctl->id.device = cap_substream->pcm->device; in snd_ak4114_build()
473 kctl->id.subdevice = cap_substream->number; in snd_ak4114_build()
475 err = snd_ctl_add(ak4114->card, kctl); in snd_ak4114_build()
478 ak4114->kctls[idx] = kctl; in snd_ak4114_build()
482 schedule_delayed_work(&ak4114->work, HZ / 10); in snd_ak4114_build()
492 if (!ak4114->kctls[0]) in ak4114_notify()
496 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
497 &ak4114->kctls[0]->id); in ak4114_notify()
499 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
500 &ak4114->kctls[1]->id); in ak4114_notify()
502 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
503 &ak4114->kctls[2]->id); in ak4114_notify()
505 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
506 &ak4114->kctls[3]->id); in ak4114_notify()
510 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
511 &ak4114->kctls[4]->id); in ak4114_notify()
514 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
515 &ak4114->kctls[9]->id); in ak4114_notify()
517 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
518 &ak4114->kctls[10]->id); in ak4114_notify()
521 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
522 &ak4114->kctls[11]->id); in ak4114_notify()
524 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
525 &ak4114->kctls[12]->id); in ak4114_notify()
527 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
528 &ak4114->kctls[13]->id); in ak4114_notify()
530 snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, in ak4114_notify()
531 &ak4114->kctls[14]->id); in ak4114_notify()
545 …struct snd_pcm_runtime *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime :… in snd_ak4114_check_rate_and_errors()
555 spin_lock_irqsave(&ak4114->lock, _flags); in snd_ak4114_check_rate_and_errors()
557 ak4114->errors[AK4114_PARITY_ERRORS]++; in snd_ak4114_check_rate_and_errors()
559 ak4114->errors[AK4114_V_BIT_ERRORS]++; in snd_ak4114_check_rate_and_errors()
561 ak4114->errors[AK4114_CCRC_ERRORS]++; in snd_ak4114_check_rate_and_errors()
563 ak4114->errors[AK4114_QCRC_ERRORS]++; in snd_ak4114_check_rate_and_errors()
564 …c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK411… in snd_ak4114_check_rate_and_errors()
566 c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0); in snd_ak4114_check_rate_and_errors()
567 ak4114->rcs0 = rcs0 & ~(AK4114_QINT | AK4114_CINT); in snd_ak4114_check_rate_and_errors()
568 ak4114->rcs1 = rcs1; in snd_ak4114_check_rate_and_errors()
569 spin_unlock_irqrestore(&ak4114->lock, _flags); in snd_ak4114_check_rate_and_errors()
572 if (ak4114->change_callback && (c0 | c1) != 0) in snd_ak4114_check_rate_and_errors()
573 ak4114->change_callback(ak4114, c0, c1); in snd_ak4114_check_rate_and_errors()
578 if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) { in snd_ak4114_check_rate_and_errors()
579 snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags); in snd_ak4114_check_rate_and_errors()
580 if (snd_pcm_running(ak4114->capture_substream)) { in snd_ak4114_check_rate_and_errors()
581 snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING); in snd_ak4114_check_rate_and_errors()
584 snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags); in snd_ak4114_check_rate_and_errors()
592 struct ak4114 *chip = container_of(work, struct ak4114, work.work); in ak4114_stats() local
594 if (atomic_inc_return(&chip->wq_processing) == 1) in ak4114_stats()
595 snd_ak4114_check_rate_and_errors(chip, chip->check_flags); in ak4114_stats()
596 if (atomic_dec_and_test(&chip->wq_processing)) in ak4114_stats()
597 schedule_delayed_work(&chip->work, HZ / 10); in ak4114_stats()
601 void snd_ak4114_suspend(struct ak4114 *chip) in snd_ak4114_suspend() argument
603 atomic_inc(&chip->wq_processing); /* don't schedule new work */ in snd_ak4114_suspend()
604 cancel_delayed_work_sync(&chip->work); in snd_ak4114_suspend()
608 void snd_ak4114_resume(struct ak4114 *chip) in snd_ak4114_resume() argument
610 atomic_dec(&chip->wq_processing); in snd_ak4114_resume()
611 snd_ak4114_reinit(chip); in snd_ak4114_resume()