Lines Matching +full:chip +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Routines for control of the AK4117 via 4-wire serial interface
27 ak4117->write(ak4117->private_data, reg, val);
28 if (reg < sizeof(ak4117->regmap))
29 ak4117->regmap[reg] = val;
34 return ak4117->read(ak4117->private_data, reg);
37 static void snd_ak4117_free(struct ak4117 *chip)
39 timer_shutdown_sync(&chip->timer);
40 kfree(chip);
45 struct ak4117 *chip = device->device_data;
46 snd_ak4117_free(chip);
53 struct ak4117 *chip;
60 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
61 if (chip == NULL)
62 return -ENOMEM;
63 spin_lock_init(&chip->lock);
64 chip->card = card;
65 chip->read = read;
66 chip->write = write;
67 chip->private_data = private_data;
68 timer_setup(&chip->timer, snd_ak4117_timer, 0);
71 chip->regmap[reg] = pgm[reg];
72 snd_ak4117_reinit(chip);
74 chip->rcs0 = reg_read(chip, AK4117_REG_RCS0) & ~(AK4117_QINT | AK4117_CINT | AK4117_STC);
75 chip->rcs1 = reg_read(chip, AK4117_REG_RCS1);
76 chip->rcs2 = reg_read(chip, AK4117_REG_RCS2);
78 err = snd_device_new(card, SNDRV_DEV_CODEC, chip, &ops);
83 *r_ak4117 = chip;
87 snd_ak4117_free(chip);
91 void snd_ak4117_reg_write(struct ak4117 *chip, unsigned char reg, unsigned char mask, unsigned char val)
95 reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val);
98 void snd_ak4117_reinit(struct ak4117 *chip)
100 unsigned char old = chip->regmap[AK4117_REG_PWRDN], reg;
102 timer_delete(&chip->timer);
103 chip->init = 1;
104 /* bring the chip to reset state and powerdown state */
105 reg_write(chip, AK4117_REG_PWRDN, 0);
108 reg_write(chip, AK4117_REG_PWRDN, (old | AK4117_RST) & ~AK4117_PWN);
111 reg_write(chip, reg, chip->regmap[reg]);
113 reg_write(chip, AK4117_REG_PWRDN, old | AK4117_RST | AK4117_PWN);
114 chip->init = 0;
115 mod_timer(&chip->timer, 1 + jiffies);
135 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
136 uinfo->count = 1;
137 uinfo->value.integer.min = 0;
138 uinfo->value.integer.max = LONG_MAX;
145 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
147 guard(spinlock_irq)(&chip->lock);
148 ucontrol->value.integer.value[0] =
149 chip->errors[kcontrol->private_value];
150 chip->errors[kcontrol->private_value] = 0;
159 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
160 unsigned char reg = kcontrol->private_value & 0xff;
161 unsigned char bit = (kcontrol->private_value >> 8) & 0xff;
162 unsigned char inv = (kcontrol->private_value >> 31) & 1;
164 ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv;
171 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
172 uinfo->count = 1;
173 uinfo->value.integer.min = 0;
174 uinfo->value.integer.max = 1;
181 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
183 ucontrol->value.integer.value[0] = (chip->regmap[AK4117_REG_IO] & AK4117_IPS) ? 1 : 0;
190 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
194 guard(spinlock_irq)(&chip->lock);
195 old_val = chip->regmap[AK4117_REG_IO];
196 change = !!ucontrol->value.integer.value[0] != ((old_val & AK4117_IPS) ? 1 : 0);
198 reg_write(chip, AK4117_REG_IO, (old_val & ~AK4117_IPS) | (ucontrol->value.integer.value[0] ? AK4117_IPS : 0));
205 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
206 uinfo->count = 1;
207 uinfo->value.integer.min = 0;
208 uinfo->value.integer.max = 192000;
215 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
217 ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4117_REG_RCS1));
223 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
224 uinfo->count = 1;
231 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
235 ucontrol->value.iec958.status[i] = reg_read(chip, AK4117_REG_RXCSB0 + i);
241 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
242 uinfo->count = 1;
249 memset(ucontrol->value.iec958.status, 0xff, AK4117_REG_RXCSB_SIZE);
255 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
256 uinfo->value.integer.min = 0;
257 uinfo->value.integer.max = 0xffff;
258 uinfo->count = 4;
265 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
268 ucontrol->value.integer.value[0] = 0xf8f2;
269 ucontrol->value.integer.value[1] = 0x4e1f;
270 tmp = reg_read(chip, AK4117_REG_Pc0) | (reg_read(chip, AK4117_REG_Pc1) << 8);
271 ucontrol->value.integer.value[2] = tmp;
272 tmp = reg_read(chip, AK4117_REG_Pd0) | (reg_read(chip, AK4117_REG_Pd1) << 8);
273 ucontrol->value.integer.value[3] = tmp;
279 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
280 uinfo->count = AK4117_REG_QSUB_SIZE;
287 struct ak4117 *chip = snd_kcontrol_chip(kcontrol);
291 ucontrol->value.bytes.data[i] = reg_read(chip, AK4117_REG_QSUB_ADDR + i);
307 .name = "IEC958 V-Bit Errors",
315 .name = "IEC958 C-CRC Errors",
323 .name = "IEC958 Q-CRC Errors",
359 .name = "IEC958 Q-subcode Capture Default",
374 .name = "IEC958 Non-PCM Bitstream",
405 return -EINVAL;
406 ak4117->substream = cap_substream;
410 return -ENOMEM;
411 kctl->id.device = cap_substream->pcm->device;
412 kctl->id.subdevice = cap_substream->number;
413 err = snd_ctl_add(ak4117->card, kctl);
416 ak4117->kctls[idx] = kctl;
431 struct snd_pcm_runtime *runtime = ak4117->substream ? ak4117->substream->runtime : NULL;
442 scoped_guard(spinlock_irqsave, &ak4117->lock) {
444 ak4117->errors[AK4117_PARITY_ERRORS]++;
446 ak4117->errors[AK4117_V_BIT_ERRORS]++;
448 ak4117->errors[AK4117_CCRC_ERRORS]++;
450 ak4117->errors[AK4117_QCRC_ERRORS]++;
451 c0 = (ak4117->rcs0 & (AK4117_QINT | AK4117_CINT | AK4117_STC | AK4117_AUDION | AK4117_AUTO | AK4117_UNLCK)) ^
453 c1 = (ak4117->rcs1 & (AK4117_DTSCD | AK4117_NPCM | AK4117_PEM | 0x0f)) ^
455 ak4117->rcs0 = rcs0 & ~(AK4117_QINT | AK4117_CINT | AK4117_STC);
456 ak4117->rcs1 = rcs1;
457 ak4117->rcs2 = rcs2;
461 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[0]->id);
463 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[1]->id);
465 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[2]->id);
467 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[3]->id);
471 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[4]->id);
474 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[6]->id);
476 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[8]->id);
479 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[9]->id);
481 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[10]->id);
483 snd_ctl_notify(ak4117->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4117->kctls[11]->id);
485 if (ak4117->change_callback && (c0 | c1) != 0)
486 ak4117->change_callback(ak4117, c0, c1);
491 if (!(flags & AK4117_CHECK_NO_RATE) && runtime && runtime->rate != res) {
492 snd_pcm_stream_lock_irqsave(ak4117->substream, _flags);
493 if (snd_pcm_running(ak4117->substream)) {
494 snd_pcm_stop(ak4117->substream, SNDRV_PCM_STATE_DRAINING);
495 wake_up(&runtime->sleep);
498 snd_pcm_stream_unlock_irqrestore(ak4117->substream, _flags);
505 struct ak4117 *chip = timer_container_of(chip, t, timer);
507 if (chip->init)
509 snd_ak4117_check_rate_and_errors(chip, 0);
510 mod_timer(&chip->timer, 1 + jiffies);