Lines Matching +full:bus +full:- +full:err
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Routines for control of the CS8427 via i2c bus
48 int err; in snd_cs8427_reg_write() local
53 err = snd_i2c_sendbytes(device, buf, 2); in snd_cs8427_reg_write()
54 if (err != 2) { in snd_cs8427_reg_write()
55 dev_err(device->bus->card->dev, in snd_cs8427_reg_write()
57 buf[0], buf[1], err); in snd_cs8427_reg_write()
58 return err < 0 ? err : -EIO; in snd_cs8427_reg_write()
67 int err; in snd_cs8427_reg_read() local
70 err = snd_i2c_sendbytes(device, ®, 1); in snd_cs8427_reg_read()
71 if (err != 1) { in snd_cs8427_reg_read()
72 dev_err(device->bus->card->dev, in snd_cs8427_reg_read()
74 return err < 0 ? err : -EIO; in snd_cs8427_reg_read()
76 err = snd_i2c_readbytes(device, &buf, 1); in snd_cs8427_reg_read()
77 if (err != 1) { in snd_cs8427_reg_read()
78 dev_err(device->bus->card->dev, in snd_cs8427_reg_read()
80 return err < 0 ? err : -EIO; in snd_cs8427_reg_read()
87 struct cs8427 *chip = device->private_data; in snd_cs8427_select_corudata()
88 int err; in snd_cs8427_select_corudata() local
91 if (udata != (chip->regmap[CS8427_REG_CSDATABUF] & udata)) { in snd_cs8427_select_corudata()
92 chip->regmap[CS8427_REG_CSDATABUF] &= ~CS8427_BSEL; in snd_cs8427_select_corudata()
93 chip->regmap[CS8427_REG_CSDATABUF] |= udata; in snd_cs8427_select_corudata()
94 err = snd_cs8427_reg_write(device, CS8427_REG_CSDATABUF, in snd_cs8427_select_corudata()
95 chip->regmap[CS8427_REG_CSDATABUF]); in snd_cs8427_select_corudata()
96 if (err < 0) in snd_cs8427_select_corudata()
97 return err; in snd_cs8427_select_corudata()
107 struct cs8427 *chip = device->private_data; in snd_cs8427_send_corudata()
109 chip->playback.hw_udata : chip->playback.hw_status; in snd_cs8427_send_corudata()
111 int err, idx; in snd_cs8427_send_corudata() local
115 err = snd_cs8427_select_corudata(device, udata); in snd_cs8427_send_corudata()
116 if (err < 0) in snd_cs8427_send_corudata()
117 return err; in snd_cs8427_send_corudata()
122 chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK; in snd_cs8427_send_corudata()
123 chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS | in snd_cs8427_send_corudata()
125 err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF, in snd_cs8427_send_corudata()
126 chip->regmap[CS8427_REG_UDATABUF]); in snd_cs8427_send_corudata()
127 return err < 0 ? err : 0; in snd_cs8427_send_corudata()
134 return -EIO; in snd_cs8427_send_corudata()
140 kfree(device->private_data); in snd_cs8427_free()
143 int snd_cs8427_init(struct snd_i2c_bus *bus, in snd_cs8427_init() argument
163 24-bit, 64*Fsi */ in snd_cs8427_init()
166 = I2S, 24-bit, 64*Fsi */ in snd_cs8427_init()
176 Registers 32-55 window to CS buffer in snd_cs8427_init()
177 Inhibit D->E transfers from overwriting first 5 bytes of CS data. in snd_cs8427_init()
178 Inhibit D->E transfers (all) of CS data. in snd_cs8427_init()
179 Allow E->F transfer of CS data. in snd_cs8427_init()
187 Inhibit D->E transfers. in snd_cs8427_init()
188 Inhibit E->F transfers. */ in snd_cs8427_init()
191 struct cs8427 *chip = device->private_data; in snd_cs8427_init()
192 int err; in snd_cs8427_init() local
195 snd_i2c_lock(bus); in snd_cs8427_init()
196 err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER); in snd_cs8427_init()
197 if (err != CS8427_VER8427A) { in snd_cs8427_init()
199 dev_warn(device->bus->card->dev, in snd_cs8427_init()
201 err); in snd_cs8427_init()
202 err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER); in snd_cs8427_init()
204 if (err != CS8427_VER8427A) { in snd_cs8427_init()
205 snd_i2c_unlock(bus); in snd_cs8427_init()
206 dev_err(device->bus->card->dev, in snd_cs8427_init()
208 CS8427_VER8427A, err); in snd_cs8427_init()
209 dev_err(device->bus->card->dev, in snd_cs8427_init()
211 return -EFAULT; in snd_cs8427_init()
214 err = snd_cs8427_reg_write(device, CS8427_REG_CLOCKSOURCE, 0x00); in snd_cs8427_init()
215 if (err < 0) in snd_cs8427_init()
218 memcpy(chip->regmap + (initvals1[0] & 0x7f), initvals1 + 1, 6); in snd_cs8427_init()
219 err = snd_i2c_sendbytes(device, initvals1, 7); in snd_cs8427_init()
220 if (err != 7) { in snd_cs8427_init()
221 err = err < 0 ? err : -EIO; in snd_cs8427_init()
228 err = snd_i2c_sendbytes(device, buf, 7); in snd_cs8427_init()
229 if (err != 7) in snd_cs8427_init()
232 memcpy(chip->regmap + (initvals2[0] & 0x7f), initvals2 + 1, 3); in snd_cs8427_init()
233 err = snd_i2c_sendbytes(device, initvals2, 4); in snd_cs8427_init()
234 if (err != 4) { in snd_cs8427_init()
235 err = err < 0 ? err : -EIO; in snd_cs8427_init()
240 memset(buf + 4, 0, 24 - 4); in snd_cs8427_init()
243 memcpy(chip->playback.def_status, buf, 24); in snd_cs8427_init()
244 memcpy(chip->playback.pcm_status, buf, 24); in snd_cs8427_init()
245 snd_i2c_unlock(bus); in snd_cs8427_init()
253 snd_i2c_unlock(bus); in snd_cs8427_init()
255 return err; in snd_cs8427_init()
259 int snd_cs8427_create(struct snd_i2c_bus *bus, in snd_cs8427_create() argument
264 int err; in snd_cs8427_create() local
268 err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7), in snd_cs8427_create()
270 if (err < 0) in snd_cs8427_create()
271 return err; in snd_cs8427_create()
272 chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL); in snd_cs8427_create()
275 return -ENOMEM; in snd_cs8427_create()
277 device->private_free = snd_cs8427_free; in snd_cs8427_create()
281 chip->reset_timeout = reset_timeout; in snd_cs8427_create()
283 err = snd_cs8427_init(bus, device); in snd_cs8427_create()
284 if (err) in snd_cs8427_create()
295 dev_dbg(device->bus->card->dev, "reg[0x%x] = 0x%x\n", xx+1, buf[xx]); in snd_cs8427_create()
305 return err < 0 ? err : -EIO; in snd_cs8427_create()
323 chip = cs8427->private_data; in snd_cs8427_reset()
324 snd_i2c_lock(cs8427->bus); in snd_cs8427_reset()
325 if ((chip->regmap[CS8427_REG_CLOCKSOURCE] & CS8427_RXDAES3INPUT) == in snd_cs8427_reset()
328 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK); in snd_cs8427_reset()
330 chip->regmap[CS8427_REG_CLOCKSOURCE]); in snd_cs8427_reset()
332 chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RUN | CS8427_RXDILRCK; in snd_cs8427_reset()
334 chip->regmap[CS8427_REG_CLOCKSOURCE]); in snd_cs8427_reset()
336 snd_i2c_unlock(cs8427->bus); in snd_cs8427_reset()
337 end_time = jiffies + chip->reset_timeout; in snd_cs8427_reset()
339 snd_i2c_lock(cs8427->bus); in snd_cs8427_reset()
341 snd_i2c_unlock(cs8427->bus); in snd_cs8427_reset()
346 snd_i2c_lock(cs8427->bus); in snd_cs8427_reset()
347 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK; in snd_cs8427_reset()
349 chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RXDAES3INPUT; in snd_cs8427_reset()
351 chip->regmap[CS8427_REG_CLOCKSOURCE]); in snd_cs8427_reset()
352 snd_i2c_unlock(cs8427->bus); in snd_cs8427_reset()
358 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_cs8427_in_status_info()
359 uinfo->count = 1; in snd_cs8427_in_status_info()
360 uinfo->value.integer.min = 0; in snd_cs8427_in_status_info()
361 uinfo->value.integer.max = 255; in snd_cs8427_in_status_info()
371 snd_i2c_lock(device->bus); in snd_cs8427_in_status_get()
372 data = snd_cs8427_reg_read(device, kcontrol->private_value); in snd_cs8427_in_status_get()
373 snd_i2c_unlock(device->bus); in snd_cs8427_in_status_get()
376 ucontrol->value.integer.value[0] = data; in snd_cs8427_in_status_get()
383 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in snd_cs8427_qsubcode_info()
384 uinfo->count = 10; in snd_cs8427_qsubcode_info()
393 int err; in snd_cs8427_qsubcode_get() local
395 snd_i2c_lock(device->bus); in snd_cs8427_qsubcode_get()
396 err = snd_i2c_sendbytes(device, ®, 1); in snd_cs8427_qsubcode_get()
397 if (err != 1) { in snd_cs8427_qsubcode_get()
398 dev_err(device->bus->card->dev, in snd_cs8427_qsubcode_get()
400 snd_i2c_unlock(device->bus); in snd_cs8427_qsubcode_get()
401 return err < 0 ? err : -EIO; in snd_cs8427_qsubcode_get()
403 err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10); in snd_cs8427_qsubcode_get()
404 if (err != 10) { in snd_cs8427_qsubcode_get()
405 dev_err(device->bus->card->dev, in snd_cs8427_qsubcode_get()
406 "unable to read Q-subcode bytes from CS8427\n"); in snd_cs8427_qsubcode_get()
407 snd_i2c_unlock(device->bus); in snd_cs8427_qsubcode_get()
408 return err < 0 ? err : -EIO; in snd_cs8427_qsubcode_get()
410 snd_i2c_unlock(device->bus); in snd_cs8427_qsubcode_get()
417 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cs8427_spdif_info()
418 uinfo->count = 1; in snd_cs8427_spdif_info()
426 struct cs8427 *chip = device->private_data; in snd_cs8427_spdif_get()
428 snd_i2c_lock(device->bus); in snd_cs8427_spdif_get()
429 memcpy(ucontrol->value.iec958.status, chip->playback.def_status, 24); in snd_cs8427_spdif_get()
430 snd_i2c_unlock(device->bus); in snd_cs8427_spdif_get()
438 struct cs8427 *chip = device->private_data; in snd_cs8427_spdif_put()
439 unsigned char *status = kcontrol->private_value ? in snd_cs8427_spdif_put()
440 chip->playback.pcm_status : chip->playback.def_status; in snd_cs8427_spdif_put()
441 struct snd_pcm_runtime *runtime = chip->playback.substream ? in snd_cs8427_spdif_put()
442 chip->playback.substream->runtime : NULL; in snd_cs8427_spdif_put()
443 int err, change; in snd_cs8427_spdif_put() local
445 snd_i2c_lock(device->bus); in snd_cs8427_spdif_put()
446 change = memcmp(ucontrol->value.iec958.status, status, 24) != 0; in snd_cs8427_spdif_put()
447 memcpy(status, ucontrol->value.iec958.status, 24); in snd_cs8427_spdif_put()
448 if (change && (kcontrol->private_value ? in snd_cs8427_spdif_put()
450 err = snd_cs8427_send_corudata(device, 0, status, 24); in snd_cs8427_spdif_put()
451 if (err < 0) in snd_cs8427_spdif_put()
452 change = err; in snd_cs8427_spdif_put()
454 snd_i2c_unlock(device->bus); in snd_cs8427_spdif_put()
461 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in snd_cs8427_spdif_mask_info()
462 uinfo->count = 1; in snd_cs8427_spdif_mask_info()
469 memset(ucontrol->value.iec958.status, 0xff, 24); in snd_cs8427_spdif_mask_get()
520 .name = "IEC958 Q-subcode Capture Default",
530 struct cs8427 *chip = cs8427->private_data; in snd_cs8427_iec958_build()
533 int err; in snd_cs8427_iec958_build() local
536 return -EINVAL; in snd_cs8427_iec958_build()
540 return -ENOMEM; in snd_cs8427_iec958_build()
541 kctl->id.device = play_substream->pcm->device; in snd_cs8427_iec958_build()
542 kctl->id.subdevice = play_substream->number; in snd_cs8427_iec958_build()
543 err = snd_ctl_add(cs8427->bus->card, kctl); in snd_cs8427_iec958_build()
544 if (err < 0) in snd_cs8427_iec958_build()
545 return err; in snd_cs8427_iec958_build()
546 if (! strcmp(kctl->id.name, in snd_cs8427_iec958_build()
548 chip->playback.pcm_ctl = kctl; in snd_cs8427_iec958_build()
551 chip->playback.substream = play_substream; in snd_cs8427_iec958_build()
552 chip->capture.substream = cap_substream; in snd_cs8427_iec958_build()
553 if (snd_BUG_ON(!chip->playback.pcm_ctl)) in snd_cs8427_iec958_build()
554 return -EIO; in snd_cs8427_iec958_build()
565 return -ENXIO; in snd_cs8427_iec958_active()
566 chip = cs8427->private_data; in snd_cs8427_iec958_active()
568 memcpy(chip->playback.pcm_status, in snd_cs8427_iec958_active()
569 chip->playback.def_status, 24); in snd_cs8427_iec958_active()
570 chip->playback.pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; in snd_cs8427_iec958_active()
572 chip->playback.pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; in snd_cs8427_iec958_active()
574 snd_ctl_notify(cs8427->bus->card, in snd_cs8427_iec958_active()
576 &chip->playback.pcm_ctl->id); in snd_cs8427_iec958_active()
586 int err, reset; in snd_cs8427_iec958_pcm() local
589 return -ENXIO; in snd_cs8427_iec958_pcm()
590 chip = cs8427->private_data; in snd_cs8427_iec958_pcm()
591 status = chip->playback.pcm_status; in snd_cs8427_iec958_pcm()
592 snd_i2c_lock(cs8427->bus); in snd_cs8427_iec958_pcm()
609 err = snd_cs8427_send_corudata(cs8427, 0, status, 24); in snd_cs8427_iec958_pcm()
610 if (err > 0) in snd_cs8427_iec958_pcm()
611 snd_ctl_notify(cs8427->bus->card, in snd_cs8427_iec958_pcm()
613 &chip->playback.pcm_ctl->id); in snd_cs8427_iec958_pcm()
614 reset = chip->rate != rate; in snd_cs8427_iec958_pcm()
615 chip->rate = rate; in snd_cs8427_iec958_pcm()
616 snd_i2c_unlock(cs8427->bus); in snd_cs8427_iec958_pcm()
619 return err < 0 ? err : 0; in snd_cs8427_iec958_pcm()