sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / soc / codecs / sigmadsp.c
blobd53680ac78e42d0bb0979afcbea8e77046d181b9
1 /*
2 * Load Analog Devices SigmaStudio firmware files
4 * Copyright 2009-2014 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
7 */
9 #include <linux/crc32.h>
10 #include <linux/firmware.h>
11 #include <linux/kernel.h>
12 #include <linux/i2c.h>
13 #include <linux/regmap.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include <sound/control.h>
18 #include <sound/soc.h>
20 #include "sigmadsp.h"
22 #define SIGMA_MAGIC "ADISIGM"
24 #define SIGMA_FW_CHUNK_TYPE_DATA 0
25 #define SIGMA_FW_CHUNK_TYPE_CONTROL 1
26 #define SIGMA_FW_CHUNK_TYPE_SAMPLERATES 2
28 struct sigmadsp_control {
29 struct list_head head;
30 uint32_t samplerates;
31 unsigned int addr;
32 unsigned int num_bytes;
33 const char *name;
34 struct snd_kcontrol *kcontrol;
35 bool cached;
36 uint8_t cache[];
39 struct sigmadsp_data {
40 struct list_head head;
41 uint32_t samplerates;
42 unsigned int addr;
43 unsigned int length;
44 uint8_t data[];
47 struct sigma_fw_chunk {
48 __le32 length;
49 __le32 tag;
50 __le32 samplerates;
51 } __packed;
53 struct sigma_fw_chunk_data {
54 struct sigma_fw_chunk chunk;
55 __le16 addr;
56 uint8_t data[];
57 } __packed;
59 struct sigma_fw_chunk_control {
60 struct sigma_fw_chunk chunk;
61 __le16 type;
62 __le16 addr;
63 __le16 num_bytes;
64 const char name[];
65 } __packed;
67 struct sigma_fw_chunk_samplerate {
68 struct sigma_fw_chunk chunk;
69 __le32 samplerates[];
70 } __packed;
72 struct sigma_firmware_header {
73 unsigned char magic[7];
74 u8 version;
75 __le32 crc;
76 } __packed;
78 enum {
79 SIGMA_ACTION_WRITEXBYTES = 0,
80 SIGMA_ACTION_WRITESINGLE,
81 SIGMA_ACTION_WRITESAFELOAD,
82 SIGMA_ACTION_END,
85 struct sigma_action {
86 u8 instr;
87 u8 len_hi;
88 __le16 len;
89 __be16 addr;
90 unsigned char payload[];
91 } __packed;
93 static int sigmadsp_write(struct sigmadsp *sigmadsp, unsigned int addr,
94 const uint8_t data[], size_t len)
96 return sigmadsp->write(sigmadsp->control_data, addr, data, len);
99 static int sigmadsp_read(struct sigmadsp *sigmadsp, unsigned int addr,
100 uint8_t data[], size_t len)
102 return sigmadsp->read(sigmadsp->control_data, addr, data, len);
105 static int sigmadsp_ctrl_info(struct snd_kcontrol *kcontrol,
106 struct snd_ctl_elem_info *info)
108 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
110 info->type = SNDRV_CTL_ELEM_TYPE_BYTES;
111 info->count = ctrl->num_bytes;
113 return 0;
116 static int sigmadsp_ctrl_write(struct sigmadsp *sigmadsp,
117 struct sigmadsp_control *ctrl, void *data)
119 /* safeload loads up to 20 bytes in a atomic operation */
120 if (ctrl->num_bytes > 4 && ctrl->num_bytes <= 20 && sigmadsp->ops &&
121 sigmadsp->ops->safeload)
122 return sigmadsp->ops->safeload(sigmadsp, ctrl->addr, data,
123 ctrl->num_bytes);
124 else
125 return sigmadsp_write(sigmadsp, ctrl->addr, data,
126 ctrl->num_bytes);
129 static int sigmadsp_ctrl_put(struct snd_kcontrol *kcontrol,
130 struct snd_ctl_elem_value *ucontrol)
132 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
133 struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
134 uint8_t *data;
135 int ret = 0;
137 mutex_lock(&sigmadsp->lock);
139 data = ucontrol->value.bytes.data;
141 if (!(kcontrol->vd[0].access & SNDRV_CTL_ELEM_ACCESS_INACTIVE))
142 ret = sigmadsp_ctrl_write(sigmadsp, ctrl, data);
144 if (ret == 0) {
145 memcpy(ctrl->cache, data, ctrl->num_bytes);
146 ctrl->cached = true;
149 mutex_unlock(&sigmadsp->lock);
151 return ret;
154 static int sigmadsp_ctrl_get(struct snd_kcontrol *kcontrol,
155 struct snd_ctl_elem_value *ucontrol)
157 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
158 struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
159 int ret = 0;
161 mutex_lock(&sigmadsp->lock);
163 if (!ctrl->cached) {
164 ret = sigmadsp_read(sigmadsp, ctrl->addr, ctrl->cache,
165 ctrl->num_bytes);
168 if (ret == 0) {
169 ctrl->cached = true;
170 memcpy(ucontrol->value.bytes.data, ctrl->cache,
171 ctrl->num_bytes);
174 mutex_unlock(&sigmadsp->lock);
176 return ret;
179 static void sigmadsp_control_free(struct snd_kcontrol *kcontrol)
181 struct sigmadsp_control *ctrl = (void *)kcontrol->private_value;
183 ctrl->kcontrol = NULL;
186 static bool sigma_fw_validate_control_name(const char *name, unsigned int len)
188 unsigned int i;
190 for (i = 0; i < len; i++) {
191 /* Normal ASCII characters are valid */
192 if (name[i] < ' ' || name[i] > '~')
193 return false;
196 return true;
199 static int sigma_fw_load_control(struct sigmadsp *sigmadsp,
200 const struct sigma_fw_chunk *chunk, unsigned int length)
202 const struct sigma_fw_chunk_control *ctrl_chunk;
203 struct sigmadsp_control *ctrl;
204 unsigned int num_bytes;
205 size_t name_len;
206 char *name;
207 int ret;
209 if (length <= sizeof(*ctrl_chunk))
210 return -EINVAL;
212 ctrl_chunk = (const struct sigma_fw_chunk_control *)chunk;
214 name_len = length - sizeof(*ctrl_chunk);
215 if (name_len >= SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
216 name_len = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1;
218 /* Make sure there are no non-displayable characaters in the string */
219 if (!sigma_fw_validate_control_name(ctrl_chunk->name, name_len))
220 return -EINVAL;
222 num_bytes = le16_to_cpu(ctrl_chunk->num_bytes);
223 ctrl = kzalloc(sizeof(*ctrl) + num_bytes, GFP_KERNEL);
224 if (!ctrl)
225 return -ENOMEM;
227 name = kzalloc(name_len + 1, GFP_KERNEL);
228 if (!name) {
229 ret = -ENOMEM;
230 goto err_free_ctrl;
232 memcpy(name, ctrl_chunk->name, name_len);
233 name[name_len] = '\0';
234 ctrl->name = name;
236 ctrl->addr = le16_to_cpu(ctrl_chunk->addr);
237 ctrl->num_bytes = num_bytes;
238 ctrl->samplerates = le32_to_cpu(chunk->samplerates);
240 list_add_tail(&ctrl->head, &sigmadsp->ctrl_list);
242 return 0;
244 err_free_ctrl:
245 kfree(ctrl);
247 return ret;
250 static int sigma_fw_load_data(struct sigmadsp *sigmadsp,
251 const struct sigma_fw_chunk *chunk, unsigned int length)
253 const struct sigma_fw_chunk_data *data_chunk;
254 struct sigmadsp_data *data;
256 if (length <= sizeof(*data_chunk))
257 return -EINVAL;
259 data_chunk = (struct sigma_fw_chunk_data *)chunk;
261 length -= sizeof(*data_chunk);
263 data = kzalloc(sizeof(*data) + length, GFP_KERNEL);
264 if (!data)
265 return -ENOMEM;
267 data->addr = le16_to_cpu(data_chunk->addr);
268 data->length = length;
269 data->samplerates = le32_to_cpu(chunk->samplerates);
270 memcpy(data->data, data_chunk->data, length);
271 list_add_tail(&data->head, &sigmadsp->data_list);
273 return 0;
276 static int sigma_fw_load_samplerates(struct sigmadsp *sigmadsp,
277 const struct sigma_fw_chunk *chunk, unsigned int length)
279 const struct sigma_fw_chunk_samplerate *rate_chunk;
280 unsigned int num_rates;
281 unsigned int *rates;
282 unsigned int i;
284 rate_chunk = (const struct sigma_fw_chunk_samplerate *)chunk;
286 num_rates = (length - sizeof(*rate_chunk)) / sizeof(__le32);
288 if (num_rates > 32 || num_rates == 0)
289 return -EINVAL;
291 /* We only allow one samplerates block per file */
292 if (sigmadsp->rate_constraints.count)
293 return -EINVAL;
295 rates = kcalloc(num_rates, sizeof(*rates), GFP_KERNEL);
296 if (!rates)
297 return -ENOMEM;
299 for (i = 0; i < num_rates; i++)
300 rates[i] = le32_to_cpu(rate_chunk->samplerates[i]);
302 sigmadsp->rate_constraints.count = num_rates;
303 sigmadsp->rate_constraints.list = rates;
305 return 0;
308 static int sigmadsp_fw_load_v2(struct sigmadsp *sigmadsp,
309 const struct firmware *fw)
311 struct sigma_fw_chunk *chunk;
312 unsigned int length, pos;
313 int ret;
316 * Make sure that there is at least one chunk to avoid integer
317 * underflows later on. Empty firmware is still valid though.
319 if (fw->size < sizeof(*chunk) + sizeof(struct sigma_firmware_header))
320 return 0;
322 pos = sizeof(struct sigma_firmware_header);
324 while (pos < fw->size - sizeof(*chunk)) {
325 chunk = (struct sigma_fw_chunk *)(fw->data + pos);
327 length = le32_to_cpu(chunk->length);
329 if (length > fw->size - pos || length < sizeof(*chunk))
330 return -EINVAL;
332 switch (le32_to_cpu(chunk->tag)) {
333 case SIGMA_FW_CHUNK_TYPE_DATA:
334 ret = sigma_fw_load_data(sigmadsp, chunk, length);
335 break;
336 case SIGMA_FW_CHUNK_TYPE_CONTROL:
337 ret = sigma_fw_load_control(sigmadsp, chunk, length);
338 break;
339 case SIGMA_FW_CHUNK_TYPE_SAMPLERATES:
340 ret = sigma_fw_load_samplerates(sigmadsp, chunk, length);
341 break;
342 default:
343 dev_warn(sigmadsp->dev, "Unknown chunk type: %d\n",
344 chunk->tag);
345 ret = 0;
346 break;
349 if (ret)
350 return ret;
353 * This can not overflow since if length is larger than the
354 * maximum firmware size (0x4000000) we'll error out earilier.
356 pos += ALIGN(length, sizeof(__le32));
359 return 0;
362 static inline u32 sigma_action_len(struct sigma_action *sa)
364 return (sa->len_hi << 16) | le16_to_cpu(sa->len);
367 static size_t sigma_action_size(struct sigma_action *sa)
369 size_t payload = 0;
371 switch (sa->instr) {
372 case SIGMA_ACTION_WRITEXBYTES:
373 case SIGMA_ACTION_WRITESINGLE:
374 case SIGMA_ACTION_WRITESAFELOAD:
375 payload = sigma_action_len(sa);
376 break;
377 default:
378 break;
381 payload = ALIGN(payload, 2);
383 return payload + sizeof(struct sigma_action);
387 * Returns a negative error value in case of an error, 0 if processing of
388 * the firmware should be stopped after this action, 1 otherwise.
390 static int process_sigma_action(struct sigmadsp *sigmadsp,
391 struct sigma_action *sa)
393 size_t len = sigma_action_len(sa);
394 struct sigmadsp_data *data;
396 pr_debug("%s: instr:%i addr:%#x len:%zu\n", __func__,
397 sa->instr, sa->addr, len);
399 switch (sa->instr) {
400 case SIGMA_ACTION_WRITEXBYTES:
401 case SIGMA_ACTION_WRITESINGLE:
402 case SIGMA_ACTION_WRITESAFELOAD:
403 if (len < 3)
404 return -EINVAL;
406 data = kzalloc(sizeof(*data) + len - 2, GFP_KERNEL);
407 if (!data)
408 return -ENOMEM;
410 data->addr = be16_to_cpu(sa->addr);
411 data->length = len - 2;
412 memcpy(data->data, sa->payload, data->length);
413 list_add_tail(&data->head, &sigmadsp->data_list);
414 break;
415 case SIGMA_ACTION_END:
416 return 0;
417 default:
418 return -EINVAL;
421 return 1;
424 static int sigmadsp_fw_load_v1(struct sigmadsp *sigmadsp,
425 const struct firmware *fw)
427 struct sigma_action *sa;
428 size_t size, pos;
429 int ret;
431 pos = sizeof(struct sigma_firmware_header);
433 while (pos + sizeof(*sa) <= fw->size) {
434 sa = (struct sigma_action *)(fw->data + pos);
436 size = sigma_action_size(sa);
437 pos += size;
438 if (pos > fw->size || size == 0)
439 break;
441 ret = process_sigma_action(sigmadsp, sa);
443 pr_debug("%s: action returned %i\n", __func__, ret);
445 if (ret <= 0)
446 return ret;
449 if (pos != fw->size)
450 return -EINVAL;
452 return 0;
455 static void sigmadsp_firmware_release(struct sigmadsp *sigmadsp)
457 struct sigmadsp_control *ctrl, *_ctrl;
458 struct sigmadsp_data *data, *_data;
460 list_for_each_entry_safe(ctrl, _ctrl, &sigmadsp->ctrl_list, head) {
461 kfree(ctrl->name);
462 kfree(ctrl);
465 list_for_each_entry_safe(data, _data, &sigmadsp->data_list, head)
466 kfree(data);
468 INIT_LIST_HEAD(&sigmadsp->ctrl_list);
469 INIT_LIST_HEAD(&sigmadsp->data_list);
472 static void devm_sigmadsp_release(struct device *dev, void *res)
474 sigmadsp_firmware_release((struct sigmadsp *)res);
477 static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
479 const struct sigma_firmware_header *ssfw_head;
480 const struct firmware *fw;
481 int ret;
482 u32 crc;
484 /* first load the blob */
485 ret = request_firmware(&fw, name, sigmadsp->dev);
486 if (ret) {
487 pr_debug("%s: request_firmware() failed with %i\n", __func__, ret);
488 goto done;
491 /* then verify the header */
492 ret = -EINVAL;
495 * Reject too small or unreasonable large files. The upper limit has been
496 * chosen a bit arbitrarily, but it should be enough for all practical
497 * purposes and having the limit makes it easier to avoid integer
498 * overflows later in the loading process.
500 if (fw->size < sizeof(*ssfw_head) || fw->size >= 0x4000000) {
501 dev_err(sigmadsp->dev, "Failed to load firmware: Invalid size\n");
502 goto done;
505 ssfw_head = (void *)fw->data;
506 if (memcmp(ssfw_head->magic, SIGMA_MAGIC, ARRAY_SIZE(ssfw_head->magic))) {
507 dev_err(sigmadsp->dev, "Failed to load firmware: Invalid magic\n");
508 goto done;
511 crc = crc32(0, fw->data + sizeof(*ssfw_head),
512 fw->size - sizeof(*ssfw_head));
513 pr_debug("%s: crc=%x\n", __func__, crc);
514 if (crc != le32_to_cpu(ssfw_head->crc)) {
515 dev_err(sigmadsp->dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
516 le32_to_cpu(ssfw_head->crc), crc);
517 goto done;
520 switch (ssfw_head->version) {
521 case 1:
522 ret = sigmadsp_fw_load_v1(sigmadsp, fw);
523 break;
524 case 2:
525 ret = sigmadsp_fw_load_v2(sigmadsp, fw);
526 break;
527 default:
528 dev_err(sigmadsp->dev,
529 "Failed to load firmware: Invalid version %d. Supported firmware versions: 1, 2\n",
530 ssfw_head->version);
531 ret = -EINVAL;
532 break;
535 if (ret)
536 sigmadsp_firmware_release(sigmadsp);
538 done:
539 release_firmware(fw);
541 return ret;
544 static int sigmadsp_init(struct sigmadsp *sigmadsp, struct device *dev,
545 const struct sigmadsp_ops *ops, const char *firmware_name)
547 sigmadsp->ops = ops;
548 sigmadsp->dev = dev;
550 INIT_LIST_HEAD(&sigmadsp->ctrl_list);
551 INIT_LIST_HEAD(&sigmadsp->data_list);
552 mutex_init(&sigmadsp->lock);
554 return sigmadsp_firmware_load(sigmadsp, firmware_name);
558 * devm_sigmadsp_init() - Initialize SigmaDSP instance
559 * @dev: The parent device
560 * @ops: The sigmadsp_ops to use for this instance
561 * @firmware_name: Name of the firmware file to load
563 * Allocates a SigmaDSP instance and loads the specified firmware file.
565 * Returns a pointer to a struct sigmadsp on success, or a PTR_ERR() on error.
567 struct sigmadsp *devm_sigmadsp_init(struct device *dev,
568 const struct sigmadsp_ops *ops, const char *firmware_name)
570 struct sigmadsp *sigmadsp;
571 int ret;
573 sigmadsp = devres_alloc(devm_sigmadsp_release, sizeof(*sigmadsp),
574 GFP_KERNEL);
575 if (!sigmadsp)
576 return ERR_PTR(-ENOMEM);
578 ret = sigmadsp_init(sigmadsp, dev, ops, firmware_name);
579 if (ret) {
580 devres_free(sigmadsp);
581 return ERR_PTR(ret);
584 devres_add(dev, sigmadsp);
586 return sigmadsp;
588 EXPORT_SYMBOL_GPL(devm_sigmadsp_init);
590 static int sigmadsp_rate_to_index(struct sigmadsp *sigmadsp, unsigned int rate)
592 unsigned int i;
594 for (i = 0; i < sigmadsp->rate_constraints.count; i++) {
595 if (sigmadsp->rate_constraints.list[i] == rate)
596 return i;
599 return -EINVAL;
602 static unsigned int sigmadsp_get_samplerate_mask(struct sigmadsp *sigmadsp,
603 unsigned int samplerate)
605 int samplerate_index;
607 if (samplerate == 0)
608 return 0;
610 if (sigmadsp->rate_constraints.count) {
611 samplerate_index = sigmadsp_rate_to_index(sigmadsp, samplerate);
612 if (samplerate_index < 0)
613 return 0;
615 return BIT(samplerate_index);
616 } else {
617 return ~0;
621 static bool sigmadsp_samplerate_valid(unsigned int supported,
622 unsigned int requested)
624 /* All samplerates are supported */
625 if (!supported)
626 return true;
628 return supported & requested;
631 static int sigmadsp_alloc_control(struct sigmadsp *sigmadsp,
632 struct sigmadsp_control *ctrl, unsigned int samplerate_mask)
634 struct snd_kcontrol_new template;
635 struct snd_kcontrol *kcontrol;
637 memset(&template, 0, sizeof(template));
638 template.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
639 template.name = ctrl->name;
640 template.info = sigmadsp_ctrl_info;
641 template.get = sigmadsp_ctrl_get;
642 template.put = sigmadsp_ctrl_put;
643 template.private_value = (unsigned long)ctrl;
644 template.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
645 if (!sigmadsp_samplerate_valid(ctrl->samplerates, samplerate_mask))
646 template.access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
648 kcontrol = snd_ctl_new1(&template, sigmadsp);
649 if (!kcontrol)
650 return -ENOMEM;
652 kcontrol->private_free = sigmadsp_control_free;
653 ctrl->kcontrol = kcontrol;
655 return snd_ctl_add(sigmadsp->component->card->snd_card, kcontrol);
658 static void sigmadsp_activate_ctrl(struct sigmadsp *sigmadsp,
659 struct sigmadsp_control *ctrl, unsigned int samplerate_mask)
661 struct snd_card *card = sigmadsp->component->card->snd_card;
662 struct snd_kcontrol_volatile *vd;
663 struct snd_ctl_elem_id id;
664 bool active;
665 bool changed = false;
667 active = sigmadsp_samplerate_valid(ctrl->samplerates, samplerate_mask);
669 down_write(&card->controls_rwsem);
670 if (!ctrl->kcontrol) {
671 up_write(&card->controls_rwsem);
672 return;
675 id = ctrl->kcontrol->id;
676 vd = &ctrl->kcontrol->vd[0];
677 if (active == (bool)(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)) {
678 vd->access ^= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
679 changed = true;
681 up_write(&card->controls_rwsem);
683 if (active && changed) {
684 mutex_lock(&sigmadsp->lock);
685 if (ctrl->cached)
686 sigmadsp_ctrl_write(sigmadsp, ctrl, ctrl->cache);
687 mutex_unlock(&sigmadsp->lock);
690 if (changed)
691 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, &id);
695 * sigmadsp_attach() - Attach a sigmadsp instance to a ASoC component
696 * @sigmadsp: The sigmadsp instance to attach
697 * @component: The component to attach to
699 * Typically called in the components probe callback.
701 * Note, once this function has been called the firmware must not be released
702 * until after the ALSA snd_card that the component belongs to has been
703 * disconnected, even if sigmadsp_attach() returns an error.
705 int sigmadsp_attach(struct sigmadsp *sigmadsp,
706 struct snd_soc_component *component)
708 struct sigmadsp_control *ctrl;
709 unsigned int samplerate_mask;
710 int ret;
712 sigmadsp->component = component;
714 samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp,
715 sigmadsp->current_samplerate);
717 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head) {
718 ret = sigmadsp_alloc_control(sigmadsp, ctrl, samplerate_mask);
719 if (ret)
720 return ret;
723 return 0;
725 EXPORT_SYMBOL_GPL(sigmadsp_attach);
728 * sigmadsp_setup() - Setup the DSP for the specified samplerate
729 * @sigmadsp: The sigmadsp instance to configure
730 * @samplerate: The samplerate the DSP should be configured for
732 * Loads the appropriate firmware program and parameter memory (if not already
733 * loaded) and enables the controls for the specified samplerate. Any control
734 * parameter changes that have been made previously will be restored.
736 * Returns 0 on success, a negative error code otherwise.
738 int sigmadsp_setup(struct sigmadsp *sigmadsp, unsigned int samplerate)
740 struct sigmadsp_control *ctrl;
741 unsigned int samplerate_mask;
742 struct sigmadsp_data *data;
743 int ret;
745 if (sigmadsp->current_samplerate == samplerate)
746 return 0;
748 samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp, samplerate);
749 if (samplerate_mask == 0)
750 return -EINVAL;
752 list_for_each_entry(data, &sigmadsp->data_list, head) {
753 if (!sigmadsp_samplerate_valid(data->samplerates,
754 samplerate_mask))
755 continue;
756 ret = sigmadsp_write(sigmadsp, data->addr, data->data,
757 data->length);
758 if (ret)
759 goto err;
762 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
763 sigmadsp_activate_ctrl(sigmadsp, ctrl, samplerate_mask);
765 sigmadsp->current_samplerate = samplerate;
767 return 0;
768 err:
769 sigmadsp_reset(sigmadsp);
771 return ret;
773 EXPORT_SYMBOL_GPL(sigmadsp_setup);
776 * sigmadsp_reset() - Notify the sigmadsp instance that the DSP has been reset
777 * @sigmadsp: The sigmadsp instance to reset
779 * Should be called whenever the DSP has been reset and parameter and program
780 * memory need to be re-loaded.
782 void sigmadsp_reset(struct sigmadsp *sigmadsp)
784 struct sigmadsp_control *ctrl;
786 list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
787 sigmadsp_activate_ctrl(sigmadsp, ctrl, false);
789 sigmadsp->current_samplerate = 0;
791 EXPORT_SYMBOL_GPL(sigmadsp_reset);
794 * sigmadsp_restrict_params() - Applies DSP firmware specific constraints
795 * @sigmadsp: The sigmadsp instance
796 * @substream: The substream to restrict
798 * Applies samplerate constraints that may be required by the firmware Should
799 * typically be called from the CODEC/component drivers startup callback.
801 * Returns 0 on success, a negative error code otherwise.
803 int sigmadsp_restrict_params(struct sigmadsp *sigmadsp,
804 struct snd_pcm_substream *substream)
806 if (sigmadsp->rate_constraints.count == 0)
807 return 0;
809 return snd_pcm_hw_constraint_list(substream->runtime, 0,
810 SNDRV_PCM_HW_PARAM_RATE, &sigmadsp->rate_constraints);
812 EXPORT_SYMBOL_GPL(sigmadsp_restrict_params);
814 MODULE_LICENSE("GPL");