sigmadsp
struct sigmadsp *sigmadsp;
static int adau1701_safeload(struct sigmadsp *sigmadsp, unsigned int addr,
struct i2c_client *client = to_i2c_client(sigmadsp->dev);
sigmadsp_reset(adau1701->sigmadsp);
ret = sigmadsp_setup(adau1701->sigmadsp, rate);
return sigmadsp_restrict_params(adau1701->sigmadsp, substream);
ret = sigmadsp_attach(adau1701->sigmadsp, component);
adau1701->sigmadsp = devm_sigmadsp_init_i2c(client,
if (IS_ERR(adau1701->sigmadsp)) {
ret = PTR_ERR(adau1701->sigmadsp);
ret = regmap_raw_write(sigmadsp->control_data,
ret = regmap_raw_write(sigmadsp->control_data,
ret = regmap_raw_write(sigmadsp->control_data,
ret = regmap_raw_write(sigmadsp->control_data,
adau->sigmadsp = devm_sigmadsp_init_regmap(dev, regmap,
adau->sigmadsp = devm_sigmadsp_init_regmap(dev, regmap,
if (IS_ERR(adau->sigmadsp)) {
PTR_ERR(adau->sigmadsp));
adau->sigmadsp = NULL;
if (adau->sigmadsp) {
if (adau->sigmadsp)
return sigmadsp_restrict_params(adau->sigmadsp, substream);
if (adau->sigmadsp->current_samplerate == rate)
ret = sigmadsp_setup(adau->sigmadsp, rate);
if (!adau->sigmadsp)
ret = sigmadsp_attach(adau->sigmadsp, component);
static int adau17x1_safeload(struct sigmadsp *sigmadsp, unsigned int addr,
struct sigmadsp *sigmadsp;
struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client,
struct sigmadsp *sigmadsp;
sigmadsp = devm_sigmadsp_init(&client->dev, ops, firmware_name);
if (IS_ERR(sigmadsp))
return sigmadsp;
sigmadsp->control_data = client;
sigmadsp->write = sigmadsp_write_i2c;
sigmadsp->read = sigmadsp_read_i2c;
return sigmadsp;
struct sigmadsp *devm_sigmadsp_init_regmap(struct device *dev,
struct sigmadsp *sigmadsp;
sigmadsp = devm_sigmadsp_init(dev, ops, firmware_name);
if (IS_ERR(sigmadsp))
return sigmadsp;
sigmadsp->control_data = regmap;
sigmadsp->write = sigmadsp_write_regmap;
sigmadsp->read = sigmadsp_read_regmap;
return sigmadsp;
static int sigmadsp_read(struct sigmadsp *sigmadsp, unsigned int addr,
return sigmadsp->read(sigmadsp->control_data, addr, data, len);
static int sigmadsp_ctrl_write(struct sigmadsp *sigmadsp,
if (ctrl->num_bytes <= 20 && sigmadsp->ops && sigmadsp->ops->safeload)
return sigmadsp->ops->safeload(sigmadsp, ctrl->addr, data,
return sigmadsp_write(sigmadsp, ctrl->addr, data,
struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
mutex_lock(&sigmadsp->lock);
ret = sigmadsp_ctrl_write(sigmadsp, ctrl, data);
mutex_unlock(&sigmadsp->lock);
struct sigmadsp *sigmadsp = snd_kcontrol_chip(kcontrol);
mutex_lock(&sigmadsp->lock);
ret = sigmadsp_read(sigmadsp, ctrl->addr, ctrl->cache,
mutex_unlock(&sigmadsp->lock);
static int sigma_fw_load_control(struct sigmadsp *sigmadsp,
list_add_tail(&ctrl->head, &sigmadsp->ctrl_list);
static int sigma_fw_load_data(struct sigmadsp *sigmadsp,
list_add_tail(&data->head, &sigmadsp->data_list);
static int sigma_fw_load_samplerates(struct sigmadsp *sigmadsp,
if (sigmadsp->rate_constraints.count)
sigmadsp->rate_constraints.count = num_rates;
sigmadsp->rate_constraints.list = rates;
static int sigmadsp_fw_load_v2(struct sigmadsp *sigmadsp,
ret = sigma_fw_load_data(sigmadsp, chunk, length);
ret = sigma_fw_load_control(sigmadsp, chunk, length);
ret = sigma_fw_load_samplerates(sigmadsp, chunk, length);
dev_warn(sigmadsp->dev, "Unknown chunk type: %d\n",
static int process_sigma_action(struct sigmadsp *sigmadsp,
list_add_tail(&data->head, &sigmadsp->data_list);
static int sigmadsp_fw_load_v1(struct sigmadsp *sigmadsp,
ret = process_sigma_action(sigmadsp, sa);
static void sigmadsp_firmware_release(struct sigmadsp *sigmadsp)
list_for_each_entry_safe(ctrl, _ctrl, &sigmadsp->ctrl_list, head) {
list_for_each_entry_safe(data, _data, &sigmadsp->data_list, head)
INIT_LIST_HEAD(&sigmadsp->ctrl_list);
INIT_LIST_HEAD(&sigmadsp->data_list);
sigmadsp_firmware_release((struct sigmadsp *)res);
static int sigmadsp_firmware_load(struct sigmadsp *sigmadsp, const char *name)
ret = request_firmware(&fw, name, sigmadsp->dev);
dev_err(sigmadsp->dev, "Failed to load firmware: Invalid size\n");
dev_err(sigmadsp->dev, "Failed to load firmware: Invalid magic\n");
dev_err(sigmadsp->dev, "Failed to load firmware: Wrong crc checksum: expected %x got %x\n",
ret = sigmadsp_fw_load_v1(sigmadsp, fw);
ret = sigmadsp_fw_load_v2(sigmadsp, fw);
dev_err(sigmadsp->dev,
sigmadsp_firmware_release(sigmadsp);
static int sigmadsp_init(struct sigmadsp *sigmadsp, struct device *dev,
sigmadsp->ops = ops;
sigmadsp->dev = dev;
INIT_LIST_HEAD(&sigmadsp->ctrl_list);
INIT_LIST_HEAD(&sigmadsp->data_list);
mutex_init(&sigmadsp->lock);
return sigmadsp_firmware_load(sigmadsp, firmware_name);
struct sigmadsp *devm_sigmadsp_init(struct device *dev,
struct sigmadsp *sigmadsp;
sigmadsp = devres_alloc(devm_sigmadsp_release, sizeof(*sigmadsp),
if (!sigmadsp)
ret = sigmadsp_init(sigmadsp, dev, ops, firmware_name);
devres_free(sigmadsp);
devres_add(dev, sigmadsp);
return sigmadsp;
static int sigmadsp_rate_to_index(struct sigmadsp *sigmadsp, unsigned int rate)
for (i = 0; i < sigmadsp->rate_constraints.count; i++) {
if (sigmadsp->rate_constraints.list[i] == rate)
static unsigned int sigmadsp_get_samplerate_mask(struct sigmadsp *sigmadsp,
if (sigmadsp->rate_constraints.count) {
samplerate_index = sigmadsp_rate_to_index(sigmadsp, samplerate);
static int sigmadsp_alloc_control(struct sigmadsp *sigmadsp,
kcontrol = snd_ctl_new1(&template, sigmadsp);
return snd_ctl_add(sigmadsp->component->card->snd_card, kcontrol);
static void sigmadsp_activate_ctrl(struct sigmadsp *sigmadsp,
struct snd_card *card = sigmadsp->component->card->snd_card;
mutex_lock(&sigmadsp->lock);
sigmadsp_ctrl_write(sigmadsp, ctrl, ctrl->cache);
mutex_unlock(&sigmadsp->lock);
int sigmadsp_attach(struct sigmadsp *sigmadsp,
sigmadsp->component = component;
samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp,
sigmadsp->current_samplerate);
list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head) {
ret = sigmadsp_alloc_control(sigmadsp, ctrl, samplerate_mask);
int sigmadsp_setup(struct sigmadsp *sigmadsp, unsigned int samplerate)
if (sigmadsp->current_samplerate == samplerate)
samplerate_mask = sigmadsp_get_samplerate_mask(sigmadsp, samplerate);
list_for_each_entry(data, &sigmadsp->data_list, head) {
ret = sigmadsp_write(sigmadsp, data->addr, data->data,
list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
sigmadsp_activate_ctrl(sigmadsp, ctrl, samplerate_mask);
sigmadsp->current_samplerate = samplerate;
sigmadsp_reset(sigmadsp);
void sigmadsp_reset(struct sigmadsp *sigmadsp)
list_for_each_entry(ctrl, &sigmadsp->ctrl_list, head)
sigmadsp_activate_ctrl(sigmadsp, ctrl, false);
sigmadsp->current_samplerate = 0;
int sigmadsp_restrict_params(struct sigmadsp *sigmadsp,
if (sigmadsp->rate_constraints.count == 0)
SNDRV_PCM_HW_PARAM_RATE, &sigmadsp->rate_constraints);
static int sigmadsp_write(struct sigmadsp *sigmadsp, unsigned int addr,
return sigmadsp->write(sigmadsp->control_data, addr, data, len);
struct sigmadsp;
int (*safeload)(struct sigmadsp *sigmadsp, unsigned int addr,
struct sigmadsp *devm_sigmadsp_init(struct device *dev,
int sigmadsp_restrict_params(struct sigmadsp *sigmadsp,
struct sigmadsp *devm_sigmadsp_init_regmap(struct device *dev,
struct sigmadsp *devm_sigmadsp_init_i2c(struct i2c_client *client,
int sigmadsp_attach(struct sigmadsp *sigmadsp,
int sigmadsp_setup(struct sigmadsp *sigmadsp, unsigned int samplerate);
void sigmadsp_reset(struct sigmadsp *sigmadsp);