WIP FPC-III support
[linux/fpc-iii.git] / sound / soc / codecs / sigmadsp.c
blob76c77dc8ecf751d76b2e6d3fa039046d1e9fcac9
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Load Analog Devices SigmaStudio firmware files
5 * Copyright 2009-2014 Analog Devices Inc.
6 */
8 #include <linux/crc32.h>
9 #include <linux/firmware.h>
10 #include <linux/kernel.h>
11 #include <linux/i2c.h>
12 #include <linux/regmap.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
16 #include <sound/control.h>
17 #include <sound/soc.h>
19 #include "sigmadsp.h"
21 #define SIGMA_MAGIC "ADISIGM"
23 #define SIGMA_FW_CHUNK_TYPE_DATA 0
24 #define SIGMA_FW_CHUNK_TYPE_CONTROL 1
25 #define SIGMA_FW_CHUNK_TYPE_SAMPLERATES 2
27 struct sigmadsp_control {
28 struct list_head head;
29 uint32_t samplerates;
30 unsigned int addr;
31 unsigned int num_bytes;
32 const char *name;
33 struct snd_kcontrol *kcontrol;
34 bool cached;
35 uint8_t cache[];
38 struct sigmadsp_data {
39 struct list_head head;
40 uint32_t samplerates;
41 unsigned int addr;
42 unsigned int length;
43 uint8_t data[];
46 struct sigma_fw_chunk {
47 __le32 length;
48 __le32 tag;
49 __le32 samplerates;
50 } __packed;
52 struct sigma_fw_chunk_data {
53 struct sigma_fw_chunk chunk;
54 __le16 addr;
55 uint8_t data[];
56 } __packed;
58 struct sigma_fw_chunk_control {
59 struct sigma_fw_chunk chunk;
60 __le16 type;
61 __le16 addr;
62 __le16 num_bytes;
63 const char name[];
64 } __packed;
66 struct sigma_fw_chunk_samplerate {
67 struct sigma_fw_chunk chunk;
68 __le32 samplerates[];
69 } __packed;
71 struct sigma_firmware_header {
72 unsigned char magic[7];
73 u8 version;
74 __le32 crc;
75 } __packed;
77 enum {
78 SIGMA_ACTION_WRITEXBYTES = 0,
79 SIGMA_ACTION_WRITESINGLE,
80 SIGMA_ACTION_WRITESAFELOAD,
81 SIGMA_ACTION_END,
84 struct sigma_action {
85 u8 instr;
86 u8 len_hi;
87 __le16 len;
88 __be16 addr;
89 unsigned char payload[];
90 } __packed;
92 static int sigmadsp_write(struct sigmadsp *sigmadsp, unsigned int addr,
93 const uint8_t data[], size_t len)
95 return sigmadsp->write(sigmadsp->control_data, addr, data, len);
98 static int sigmadsp_read(struct sigmadsp *sigmadsp, unsigned int addr,
99 uint8_t data[], size_t len)
101 return sigmadsp->read(sigmadsp->control_data, addr, data, len);
104 static int sigmadsp_ctrl_info(struct snd_kcontrol *kcontrol,
105 struct snd_ctl_elem_info *info)
107 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
109 info->type = SNDRV_CTL_ELEM_TYPE_BYTES;
110 info->count = ctrl->num_bytes;
112 return 0;
115 static int sigmadsp_ctrl_write(struct sigmadsp *sigmadsp,
116 struct sigmadsp_control *ctrl, void *data)
118 /* safeload loads up to 20 bytes in a atomic operation */
119 if (ctrl->num_bytes <= 20 && sigmadsp->ops && sigmadsp->ops->safeload)
120 return sigmadsp->ops->safeload(sigmadsp, ctrl->addr, data,
121 ctrl->num_bytes);
122 else
123 return sigmadsp_write(sigmadsp, ctrl->addr, data,
124 ctrl->num_bytes);
127 static int sigmadsp_ctrl_put(struct snd_kcontrol *kcontrol,
128 struct snd_ctl_elem_value *ucontrol)
130 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
131 struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
132 uint8_t *data;
133 int ret = 0;
135 mutex_lock(&sigmadsp->lock);
137 data = ucontrol->value.bytes.data;
139 if (!(kcontrol->vd[0].access & SNDRV_CTL_ELEM_ACCESS_INACTIVE))
140 ret = sigmadsp_ctrl_write(sigmadsp, ctrl, data);
142 if (ret == 0) {
143 memcpy(ctrl->cache, data, ctrl->num_bytes);
144 ctrl->cached = true;
147 mutex_unlock(&sigmadsp->lock);
149 return ret;
152 static int sigmadsp_ctrl_get(struct snd_kcontrol *kcontrol,
153 struct snd_ctl_elem_value *ucontrol)
155 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
156 struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
157 int ret = 0;
159 mutex_lock(&sigmadsp->lock);
161 if (!ctrl->cached) {
162 ret = sigmadsp_read(sigmadsp, ctrl->addr, ctrl->cache,
163 ctrl->num_bytes);
166 if (ret == 0) {
167 ctrl->cached = true;
168 memcpy(ucontrol->value.bytes.data, ctrl->cache,
169 ctrl->num_bytes);
172 mutex_unlock(&sigmadsp->lock);
174 return ret;
177 static void sigmadsp_control_free(struct snd_kcontrol *kcontrol)
179 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
181 ctrl->kcontrol = NULL;
184 static bool sigma_fw_validate_control_name(const char *name, unsigned int len)
186 unsigned int i;
188 for (i = 0; i < len; i++) {
189 /* Normal ASCII characters are valid */
190 if (name[i] < ' ' || name[i] > '~')
191 return false;
194 return true;
197 static int sigma_fw_load_control(struct sigmadsp *sigmadsp,
198 const struct sigma_fw_chunk *chunk, unsigned int length)
200 const struct sigma_fw_chunk_control *ctrl_chunk;
201 struct sigmadsp_control *ctrl;
202 unsigned int num_bytes;
203 size_t name_len;
204 char *name;
205 int ret;
207 if (length <= sizeof(*ctrl_chunk))
208 return -EINVAL;
210 ctrl_chunk = (const struct sigma_fw_chunk_control *)chunk;
212 name_len = length - sizeof(*ctrl_chunk);
213 if (name_len >= SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
214 name_len = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1;
216 /* Make sure there are no non-displayable characaters in the string */
217 if (!sigma_fw_validate_control_name(ctrl_chunk->name, name_len))
218 return -EINVAL;
220 num_bytes = le16_to_cpu(ctrl_chunk->num_bytes);
221 ctrl = kzalloc(sizeof(*ctrl) + num_bytes, GFP_KERNEL);
222 if (!ctrl)
223 return -ENOMEM;
225 name = kzalloc(name_len + 1, GFP_KERNEL);
226 if (!name) {
227 ret = -ENOMEM;
228 goto err_free_ctrl;
230 memcpy(name, ctrl_chunk->name, name_len);
231 name[name_len] = '\0';
232 ctrl->name = name;
234 ctrl->addr = le16_to_cpu(ctrl_chunk->addr);
235 ctrl->num_bytes = num_bytes;
236 ctrl->samplerates = le32_to_cpu(chunk->samplerates);
238 list_add_tail(&ctrl->head, &sigmadsp->ctrl_list);
240 return 0;
242 err_free_ctrl:
243 kfree(ctrl);
245 return ret;
248 static int sigma_fw_load_data(struct sigmadsp *sigmadsp,
249 const struct sigma_fw_chunk *chunk, unsigned int length)
251 const struct sigma_fw_chunk_data *data_chunk;
252 struct sigmadsp_data *data;
254 if (length <= sizeof(*data_chunk))
255 return -EINVAL;
257 data_chunk = (struct sigma_fw_chunk_data *)chunk;
259 length -= sizeof(*data_chunk);
261 data = kzalloc(sizeof(*data) + length, GFP_KERNEL);
262 if (!data)
263 return -ENOMEM;
265 data->addr = le16_to_cpu(data_chunk->addr);
266 data->length = length;
267 data->samplerates = le32_to_cpu(chunk->samplerates);
268 memcpy(data->data, data_chunk->data, length);
269 list_add_tail(&data->head, &sigmadsp->data_list);
271 return 0;
274 static int sigma_fw_load_samplerates(struct sigmadsp *sigmadsp,
275 const struct sigma_fw_chunk *chunk, unsigned int length)
277 const struct sigma_fw_chunk_samplerate *rate_chunk;
278 unsigned int num_rates;
279 unsigned int *rates;
280 unsigned int i;
282 rate_chunk = (const struct sigma_fw_chunk_samplerate *)chunk;
284 num_rates = (length - sizeof(*rate_chunk)) / sizeof(__le32);
286 if (num_rates > 32 || num_rates == 0)
287 return -EINVAL;
289 /* We only allow one samplerates block per file */
290 if (sigmadsp->rate_constraints.count)
291 return -EINVAL;
293 rates = kcalloc(num_rates, sizeof(*rates), GFP_KERNEL);
294 if (!rates)
295 return -ENOMEM;
297 for (i = 0; i < num_rates; i++)
298 rates[i] = le32_to_cpu(rate_chunk->samplerates[i]);
300 sigmadsp->rate_constraints.count = num_rates;
301 sigmadsp->rate_constraints.list = rates;
303 return 0;
306 static int sigmadsp_fw_load_v2(struct sigmadsp *sigmadsp,
307 const struct firmware *fw)
309 struct sigma_fw_chunk *chunk;
310 unsigned int length, pos;
311 int ret;
314 * Make sure that there is at least one chunk to avoid integer
315 * underflows later on. Empty firmware is still valid though.
317 if (fw->size < sizeof(*chunk) + sizeof(struct sigma_firmware_header))
318 return 0;
320 pos = sizeof(struct sigma_firmware_header);
322 while (pos < fw->size - sizeof(*chunk)) {
323 chunk = (struct sigma_fw_chunk *)(fw->data + pos);
325 length = le32_to_cpu(chunk->length);
327 if (length > fw->size - pos || length < sizeof(*chunk))
328 return -EINVAL;
330 switch (le32_to_cpu(chunk->tag)) {
331 case SIGMA_FW_CHUNK_TYPE_DATA:
332 ret = sigma_fw_load_data(sigmadsp, chunk, length);
333 break;
334 case SIGMA_FW_CHUNK_TYPE_CONTROL:
335 ret = sigma_fw_load_control(sigmadsp, chunk, length);
336 break;
337 case SIGMA_FW_CHUNK_TYPE_SAMPLERATES:
338 ret = sigma_fw_load_samplerates(sigmadsp, chunk, length);
339 break;
340 default:
341 dev_warn(sigmadsp->dev, "Unknown chunk type: %d\n",
342 chunk->tag);
343 ret = 0;
344 break;
347 if (ret)
348 return ret;
351 * This can not overflow since if length is larger than the
352 * maximum firmware size (0x4000000) we'll error out earilier.
354 pos += ALIGN(length, sizeof(__le32));
357 return 0;
360 static inline u32 sigma_action_len(struct sigma_action *sa)
362 return (sa->len_hi << 16) | le16_to_cpu(sa->len);
365 static size_t sigma_action_size(struct sigma_action *sa)
367 size_t payload = 0;
369 switch (sa->instr) {
370 case SIGMA_ACTION_WRITEXBYTES:
371 case SIGMA_ACTION_WRITESINGLE:
372 case SIGMA_ACTION_WRITESAFELOAD:
373 payload = sigma_action_len(sa);
374 break;
375 default:
376 break;
379 payload = ALIGN(payload, 2);
381 return payload + sizeof(struct sigma_action);
385 * Returns a negative error value in case of an error, 0 if processing of
386 * the firmware should be stopped after this action, 1 otherwise.
388 static int process_sigma_action(struct sigmadsp *sigmadsp,
389 struct sigma_action *sa)
391 size_t len = sigma_action_len(sa);
392 struct sigmadsp_data *data;
394 pr_debug("%s: instr:%i addr:%#x len:%zu\n", __func__,
395 sa->instr, sa->addr, len);
397 switch (sa->instr) {
398 case SIGMA_ACTION_WRITEXBYTES:
399 case SIGMA_ACTION_WRITESINGLE:
400 case SIGMA_ACTION_WRITESAFELOAD:
401 if (len < 3)
402 return -EINVAL;
404 data = kzalloc(sizeof(*data) + len - 2, GFP_KERNEL);
405 if (!data)
406 return -ENOMEM;
408 data->addr = be16_to_cpu(sa->addr);
409 data->length = len - 2;
410 memcpy(data->data, sa->payload, data->length);
411 list_add_tail(&data->head, &sigmadsp->data_list);
412 break;
413 case SIGMA_ACTION_END:
414 return 0;
415 default:
416 return -EINVAL;
419 return 1;
422 static int sigmadsp_fw_load_v1(struct sigmadsp *sigmadsp,
423 const struct firmware *fw)
425 struct sigma_action *sa;
426 size_t size, pos;
427 int ret;
429 pos = sizeof(struct sigma_firmware_header);
431 while (pos + sizeof(*sa) <= fw->size) {
432 sa = (struct sigma_action *)(fw->data + pos);
434 size = sigma_action_size(sa);
435 pos += size;
436 if (pos > fw->size || size == 0)
437 break;
439 ret = process_sigma_action(sigmadsp, sa);
441 pr_debug("%s: action returned %i\n", __func__, ret);
443 if (ret <= 0)
444 return ret;
447 if (pos != fw->size)
448 return -EINVAL;
450 return 0;
453 static void sigmadsp_firmware_release(struct sigmadsp *sigmadsp)
455 struct sigmadsp_control *ctrl, *_ctrl;
456 struct sigmadsp_data *data, *_data;
458 list_for_each_entry_safe(ctrl, _ctrl, &sigmadsp->ctrl_list, head) {
459 kfree(ctrl->name);
460 kfree(ctrl);
463 list_for_each_entry_safe(data, _data, &sigmadsp->data_list, head)
464 kfree(data);
466 INIT_LIST_HEAD(&sigmadsp->ctrl_list);
467 INIT_LIST_HEAD(&sigmadsp->data_list);
470 static void devm_sigmadsp_release(struct device *dev, void *res)
472 sigmadsp_firmware_release((struct sigmadsp *)res);
475 static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
477 const struct sigma_firmware_header *ssfw_head;
478 const struct firmware *fw;
479 int ret;
480 u32 crc;
482 /* first load the blob */
483 ret = request_firmware(&fw, name, sigmadsp->dev);
484 if (ret) {
485 pr_debug("%s: request_firmware() failed with %i\n", __func__, ret);
486 goto done;
489 /* then verify the header */
490 ret = -EINVAL;
493 * Reject too small or unreasonable large files. The upper limit has been
494 * chosen a bit arbitrarily, but it should be enough for all practical
495 * purposes and having the limit makes it easier to avoid integer
496 * overflows later in the loading process.
498 if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000) {
499 dev_err(sigmadsp->dev, "Failed to load firmware: Invalid size\n");
500 goto done;
503 ssfw_head = (void *)fw->data;
504 if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) {
505 dev_err(sigmadsp->dev, "Failed to load firmware: Invalid magic\n");
506 goto done;
509 crc = crc32(0, fw->data + sizeof(*ssfw_head),
510 fw->size - sizeof(*ssfw_head));
511 pr_debug("%s: crc=%x\n", __func__, crc);
512 if (crc != le32_to_cpu(ssfw_head->crc)) {
513 dev_err(sigmadsp->dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
514 le32_to_cpu(ssfw_head->crc), crc);
515 goto done;
518 switch (ssfw_head->version) {
519 case 1:
520 ret = sigmadsp_fw_load_v1(sigmadsp, fw);
521 break;
522 case 2:
523 ret = sigmadsp_fw_load_v2(sigmadsp, fw);
524 break;
525 default:
526 dev_err(sigmadsp->dev,
527 "Failed to load firmware: Invalid version %d. Supported firmware versions: 1, 2\n",
528 ssfw_head->version);
529 ret = -EINVAL;
530 break;
533 if (ret)
534 sigmadsp_firmware_release(sigmadsp);
536 done:
537 release_firmware(fw);
539 return ret;
542 static int sigmadsp_init(struct sigmadsp *sigmadsp, struct device *dev,
543 const struct sigmadsp_ops *ops, const char *firmware_name)
545 sigmadsp->ops = ops;
546 sigmadsp->dev = dev;
548 INIT_LIST_HEAD(&sigmadsp->ctrl_list);
549 INIT_LIST_HEAD(&sigmadsp->data_list);
550 mutex_init(&sigmadsp->lock);
552 return sigmadsp_firmware_load(sigmadsp, firmware_name);
556 * devm_sigmadsp_init() - Initialize SigmaDSP instance
557 * @dev: The parent device
558 * @ops: The sigmadsp_ops to use for this instance
559 * @firmware_name: Name of the firmware file to load
561 * Allocates a SigmaDSP instance and loads the specified firmware file.
563 * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
565 struct sigmadsp *devm_sigmadsp_init(struct device *dev,
566 const struct sigmadsp_ops *ops, const char *firmware_name)
568 struct sigmadsp *sigmadsp;
569 int ret;
571 sigmadsp = devres_alloc(devm_sigmadsp_release, sizeof(*sigmadsp),
572 GFP_KERNEL);
573 if (!sigmadsp)
574 return ERR_PTR(-ENOMEM);
576 ret = sigmadsp_init(sigmadsp, dev, ops, firmware_name);
577 if (ret) {
578 devres_free(sigmadsp);
579 return ERR_PTR(ret);
582 devres_add(dev, sigmadsp);
584 return sigmadsp;
586 EXPORT_SYMBOL_GPL(devm_sigmadsp_init);
588 static int sigmadsp_rate_to_index(struct sigmadsp *sigmadsp, unsigned int rate)
590 unsigned int i;
592 for (i = 0; i < sigmadsp->rate_constraints.count; i++) {
593 if (sigmadsp->rate_constraints.list[i] == rate)
594 return i;
597 return -EINVAL;
600 static unsigned int sigmadsp_get_samplerate_mask(struct sigmadsp *sigmadsp,
601 unsigned int samplerate)
603 int samplerate_index;
605 if (samplerate == 0)
606 return 0;
608 if (sigmadsp->rate_constraints.count) {
609 samplerate_index = sigmadsp_rate_to_index(sigmadsp, samplerate);
610 if (samplerate_index < 0)
611 return 0;
613 return BIT(samplerate_index);
614 } else {
615 return ~0;
619 static bool sigmadsp_samplerate_valid(unsigned int supported,
620 unsigned int requested)
622 /* All samplerates are supported */
623 if (!supported)
624 return true;
626 return supported & requested;
629 static int sigmadsp_alloc_control(struct sigmadsp *sigmadsp,
630 struct sigmadsp_control *ctrl, unsigned int samplerate_mask)
632 struct snd_kcontrol_new template;
633 struct snd_kcontrol *kcontrol;
635 memset(&template, 0, sizeof(template));
636 template.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
637 template.name = ctrl->name;
638 template.info = sigmadsp_ctrl_info;
639 template.get = sigmadsp_ctrl_get;
640 template.put = sigmadsp_ctrl_put;
641 template.private_value = (unsigned long)ctrl;
642 template.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
643 if (!sigmadsp_samplerate_valid(ctrl->samplerates, samplerate_mask))
644 template.access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
646 kcontrol = snd_ctl_new1(&template, sigmadsp);
647 if (!kcontrol)
648 return -ENOMEM;
650 kcontrol->private_free = sigmadsp_control_free;
651 ctrl->kcontrol = kcontrol;
653 return snd_ctl_add(sigmadsp->component->card->snd_card, kcontrol);
656 static void sigmadsp_activate_ctrl(struct sigmadsp *sigmadsp,
657 struct sigmadsp_control *ctrl, unsigned int samplerate_mask)
659 struct snd_card *card = sigmadsp->component->card->snd_card;
660 struct snd_kcontrol_volatile *vd;
661 struct snd_ctl_elem_id id;
662 bool active;
663 bool changed = false;
665 active = sigmadsp_samplerate_valid(ctrl->samplerates, samplerate_mask);
667 down_write(&card->controls_rwsem);
668 if (!ctrl->kcontrol) {
669 up_write(&card->controls_rwsem);
670 return;
673 id = ctrl->kcontrol->id;
674 vd = &ctrl->kcontrol->vd[0];
675 if (active == (bool)(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)) {
676 vd->access ^= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
677 changed = true;
679 up_write(&card->controls_rwsem);
681 if (active && changed) {
682 mutex_lock(&sigmadsp->lock);
683 if (ctrl->cached)
684 sigmadsp_ctrl_write(sigmadsp, ctrl, ctrl->cache);
685 mutex_unlock(&sigmadsp->lock);
688 if (changed)
689 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, &id);
693 * sigmadsp_attach() - Attach a sigmadsp instance to a ASoC component
694 * @sigmadsp: The sigmadsp instance to attach
695 * @component: The component to attach to
697 * Typically called in the components probe callback.
699 * Note, once this function has been called the firmware must not be released
700 * until after the ALSA snd_card that the component belongs to has been
701 * disconnected, even if sigmadsp_attach() returns an error.
703 int sigmadsp_attach(struct sigmadsp *sigmadsp,
704 struct snd_soc_component *component)
706 struct sigmadsp_control *ctrl;
707 unsigned int samplerate_mask;
708 int ret;
710 sigmadsp->component = component;
712 samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp,
713 sigmadsp->current_samplerate);
715 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head) {
716 ret = sigmadsp_alloc_control(sigmadsp, ctrl, samplerate_mask);
717 if (ret)
718 return ret;
721 return 0;
723 EXPORT_SYMBOL_GPL(sigmadsp_attach);
726 * sigmadsp_setup() - Setup the DSP for the specified samplerate
727 * @sigmadsp: The sigmadsp instance to configure
728 * @samplerate: The samplerate the DSP should be configured for
730 * Loads the appropriate firmware program and parameter memory (if not already
731 * loaded) and enables the controls for the specified samplerate. Any control
732 * parameter changes that have been made previously will be restored.
734 * Returns 0 on success, a negative error code otherwise.
736 int sigmadsp_setup(struct sigmadsp *sigmadsp, unsigned int samplerate)
738 struct sigmadsp_control *ctrl;
739 unsigned int samplerate_mask;
740 struct sigmadsp_data *data;
741 int ret;
743 if (sigmadsp->current_samplerate == samplerate)
744 return 0;
746 samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp, samplerate);
747 if (samplerate_mask == 0)
748 return -EINVAL;
750 list_for_each_entry(data, &sigmadsp->data_list, head) {
751 if (!sigmadsp_samplerate_valid(data->samplerates,
752 samplerate_mask))
753 continue;
754 ret = sigmadsp_write(sigmadsp, data->addr, data->data,
755 data->length);
756 if (ret)
757 goto err;
760 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
761 sigmadsp_activate_ctrl(sigmadsp, ctrl, samplerate_mask);
763 sigmadsp->current_samplerate = samplerate;
765 return 0;
766 err:
767 sigmadsp_reset(sigmadsp);
769 return ret;
771 EXPORT_SYMBOL_GPL(sigmadsp_setup);
774 * sigmadsp_reset() - Notify the sigmadsp instance that the DSP has been reset
775 * @sigmadsp: The sigmadsp instance to reset
777 * Should be called whenever the DSP has been reset and parameter and program
778 * memory need to be re-loaded.
780 void sigmadsp_reset(struct sigmadsp *sigmadsp)
782 struct sigmadsp_control *ctrl;
784 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
785 sigmadsp_activate_ctrl(sigmadsp, ctrl, false);
787 sigmadsp->current_samplerate = 0;
789 EXPORT_SYMBOL_GPL(sigmadsp_reset);
792 * sigmadsp_restrict_params() - Applies DSP firmware specific constraints
793 * @sigmadsp: The sigmadsp instance
794 * @substream: The substream to restrict
796 * Applies samplerate constraints that may be required by the firmware Should
797 * typically be called from the CODEC/component drivers startup callback.
799 * Returns 0 on success, a negative error code otherwise.
801 int sigmadsp_restrict_params(struct sigmadsp *sigmadsp,
802 struct snd_pcm_substream *substream)
804 if (sigmadsp->rate_constraints.count == 0)
805 return 0;
807 return snd_pcm_hw_constraint_list(substream->runtime, 0,
808 SNDRV_PCM_HW_PARAM_RATE, &sigmadsp->rate_constraints);
810 EXPORT_SYMBOL_GPL(sigmadsp_restrict_params);
812 MODULE_LICENSE("GPL");