Lines Matching +full:divider +full:- +full:val
4 * SPDX-License-Identifier: Apache-2.0
28 #define DEV_CFG(dev) ((const struct wm8904_driver_config *const)dev->config)
30 static void wm8904_write_reg(const struct device *dev, uint8_t reg, uint16_t val);
31 static void wm8904_read_reg(const struct device *dev, uint8_t reg, uint16_t *val);
32 static void wm8904_update_reg(const struct device *dev, uint8_t reg, uint16_t mask, uint16_t val);
60 return -EINVAL; in wm8904_protocol_config()
75 uint16_t word_size = cfg->i2s.word_size; in wm8904_audio_fmt_config()
77 switch (cfg->i2s.frame_clk_freq) { in wm8904_audio_fmt_config()
106 LOG_WRN("Invalid codec sample rate: %d", cfg->i2s.frame_clk_freq); in wm8904_audio_fmt_config()
107 return -EINVAL; in wm8904_audio_fmt_config()
111 fs = (mclk >> (mclkDiv & 0x1U)) / cfg->i2s.frame_clk_freq; in wm8904_audio_fmt_config()
146 return -EINVAL; in wm8904_audio_fmt_config()
156 switch (cfg->i2s.word_size) { in wm8904_audio_fmt_config()
171 cfg->i2s.word_size); in wm8904_audio_fmt_config()
186 uint16_t val, in wm8904_out_update() argument
192 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT2_LEFT, mask, val); in wm8904_out_update()
196 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT2_RIGHT, mask, val); in wm8904_out_update()
200 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT1_LEFT, mask, val); in wm8904_out_update()
204 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT1_RIGHT, mask, val); in wm8904_out_update()
208 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT1_LEFT, mask, val); in wm8904_out_update()
209 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT1_RIGHT, mask, val); in wm8904_out_update()
210 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT2_LEFT, mask, val); in wm8904_out_update()
211 wm8904_update_reg(dev, WM8904_REG_ANALOG_OUT2_RIGHT, mask, val); in wm8904_out_update()
215 return -EINVAL; in wm8904_out_update()
222 const uint16_t val = WM8904_REGVAL_OUT_VOL(0, 0, 1, volume); in wm8904_out_volume_config() local
227 return wm8904_out_update(dev, channel, val, mask); in wm8904_out_volume_config()
232 const uint16_t val = WM8904_REGVAL_OUT_VOL(mute, 0, 0, 0); in wm8904_out_mute_config() local
235 return wm8904_out_update(dev, channel, val, mask); in wm8904_out_mute_config()
242 uint16_t val in wm8904_in_update() argument
247 wm8904_update_reg(dev, WM8904_REG_ANALOG_LEFT_IN_0, mask, val); in wm8904_in_update()
251 wm8904_update_reg(dev, WM8904_REG_ANALOG_RIGHT_IN_0, mask, val); in wm8904_in_update()
255 wm8904_update_reg(dev, WM8904_REG_ANALOG_LEFT_IN_0, mask, val); in wm8904_in_update()
256 wm8904_update_reg(dev, WM8904_REG_ANALOG_RIGHT_IN_0, mask, val); in wm8904_in_update()
260 return -EINVAL; in wm8904_in_update()
266 const uint16_t val = WM8904_REGVAL_IN_VOL(0, volume); in wm8904_in_volume_config() local
269 return wm8904_in_update(dev, channel, val, mask); in wm8904_in_volume_config()
274 const uint16_t val = WM8904_REGVAL_IN_VOL(mute, 0); in wm8904_in_mute_config() local
277 return wm8904_in_update(dev, channel, val, mask); in wm8904_in_mute_config()
283 return -EINVAL; in wm8904_route_input()
286 uint8_t val = WM8904_REGVAL_INSEL(0, input - 1, input - 1, 0); in wm8904_route_input() local
303 return -EINVAL; in wm8904_route_input()
306 wm8904_update_reg(dev, reg, mask, val); in wm8904_route_input()
312 uint32_t sampleRate = cfg->i2s.frame_clk_freq; in wm8904_set_master_clock()
313 uint32_t bitWidth = cfg->i2s.word_size; in wm8904_set_master_clock()
324 LOG_ERR("Invalid BCLK clock divider configured."); in wm8904_set_master_clock()
369 audioInterface |= (uint16_t)bclkDiv / 10U - 1U; in wm8904_set_master_clock()
403 /* bclk divider */ in wm8904_set_master_clock()
409 /* LRCLK direction and divider */ in wm8904_set_master_clock()
419 if (cfg->dai_type >= AUDIO_DAI_TYPE_INVALID) { in wm8904_configure()
421 return -EINVAL; in wm8904_configure()
426 if (cfg->dai_route == AUDIO_ROUTE_BYPASS) { in wm8904_configure()
468 /* DAC_MONO=0, DAC_SB_FILT-0, DAC_MUTERATE=0, DAC_UNMUTE RAMP=0, in wm8904_configure()
487 wm8904_protocol_config(dev, cfg->dai_type); in wm8904_configure()
489 (uint16_t)(dev_cfg->clock_source)); in wm8904_configure()
491 if (dev_cfg->clock_source == 0) { in wm8904_configure()
492 int err = clock_control_on(dev_cfg->mclk_dev, dev_cfg->mclk_name); in wm8904_configure()
498 err = clock_control_get_rate(dev_cfg->mclk_dev, dev_cfg->mclk_name, in wm8904_configure()
499 &cfg->mclk_freq); in wm8904_configure()
505 wm8904_audio_fmt_config(dev, &cfg->dai_cfg, cfg->mclk_freq); in wm8904_configure()
507 if ((cfg->dai_cfg.i2s.options & I2S_OPT_FRAME_CLK_MASTER) == I2S_OPT_FRAME_CLK_MASTER) { in wm8904_configure()
508 wm8904_set_master_clock(dev, &cfg->dai_cfg, cfg->mclk_freq); in wm8904_configure()
515 switch (cfg->dai_route) { in wm8904_configure()
545 audio_channel_t channel, audio_property_value_t val) in wm8904_set_property() argument
549 return wm8904_out_volume_config(dev, channel, val.vol); in wm8904_set_property()
552 return wm8904_out_mute_config(dev, channel, val.mute); in wm8904_set_property()
555 return wm8904_in_volume_config(dev, channel, val.vol); in wm8904_set_property()
558 return wm8904_in_mute_config(dev, channel, val.mute); in wm8904_set_property()
561 return -EINVAL; in wm8904_set_property()
585 static void wm8904_write_reg(const struct device *dev, uint8_t reg, uint16_t val) in wm8904_write_reg() argument
593 data[1] = (val >> 8) & 0xff; in wm8904_write_reg()
594 data[2] = val & 0xff; in wm8904_write_reg()
596 ret = i2c_write(dev_cfg->i2c.bus, data, 3, dev_cfg->i2c.addr); in wm8904_write_reg()
602 LOG_DBG("REG:%02u VAL:%#02x", reg, val); in wm8904_write_reg()
605 static void wm8904_read_reg(const struct device *dev, uint8_t reg, uint16_t *val) in wm8904_read_reg() argument
611 ret = i2c_write_read(dev_cfg->i2c.bus, dev_cfg->i2c.addr, ®, sizeof(reg), &value, in wm8904_read_reg()
614 *val = (value >> 8) & 0xff; in wm8904_read_reg()
615 *val += ((value & 0xff) << 8); in wm8904_read_reg()
617 LOG_DBG("REG:%02u VAL:%#02x", reg, *val); in wm8904_read_reg()
621 static void wm8904_update_reg(const struct device *dev, uint8_t reg, uint16_t mask, uint16_t val) in wm8904_update_reg() argument
627 LOG_DBG("try write mask %#x val %#x", mask, val); in wm8904_update_reg()
633 new_value = (reg_val & ~mask) | (val & mask); in wm8904_update_reg()