Re: [alsa-devel] [PATCH v4] ASoC: Add MediaTek MT6660 Speaker Amp Driver
From: Sriram Periyasamy
Date: Thu Jan 09 2020 - 12:18:48 EST
On Tue, Jan 07, 2020 at 11:09:05AM +0800, Jeff Chang wrote:
> From: Jeff Chang <jeff_chang@xxxxxxxxxxx>
>
> The MT6660 is a boosted BTL class-D amplifier with V/I sensing.
> A built-in DC-DC step-up converter is used to provide efficient
> power for class-D amplifier with multi-level class-G operation.
> The digital audio interface supports I2S, left-justified,
> right-justified, TDM and DSP A/B format for audio in with a data
> out used for chip information like voltage sense and current
> sense, which are able to be monitored via DATAO through proper
>
> diff --git a/sound/soc/codecs/mt6660.c b/sound/soc/codecs/mt6660.c
> new file mode 100644
> index 0000000..b8fc53b
> --- /dev/null
> +++ b/sound/soc/codecs/mt6660.c
> @@ -0,0 +1,628 @@
> +
> +struct codec_reg_val {
> + u32 addr;
> + u32 mask;
> + u32 data;
> +};
packed structures could have been better.
> +
> +struct reg_size_table {
> + u32 addr;
> + u8 size;
> +};
here as well.
> +static int mt6660_get_reg_size(uint32_t addr)
> +{
> + int i = 0;
redundant initialization.
> +
> + for (i = 0; i < ARRAY_SIZE(mt6660_reg_size_table); i++) {
> + if (mt6660_reg_size_table[i].addr == addr)
> + return mt6660_reg_size_table[i].size;
> + }
> + return 1;
> +}
> +
> +static int mt6660_reg_write(void *context, unsigned int reg, unsigned int val)
> +{
> + struct mt6660_chip *chip = context;
> + int size = mt6660_get_reg_size(reg);
> + u8 reg_data[4] = {0};
> + int i = 0, ret = 0;
redundant initialization.
> +
> + for (i = 0; i < size; i++)
> + reg_data[size - i - 1] = (val >> (8 * i)) & 0xff;
> +
> + ret = i2c_smbus_write_i2c_block_data(chip->i2c, reg, size, reg_data);
> + if (ret < 0)
> + return ret;
> + return 0;
one return can be removed.
> +}
> +
> +static int mt6660_reg_read(void *context, unsigned int reg, unsigned int *val)
> +{
> + struct mt6660_chip *chip = context;
> + int size = mt6660_get_reg_size(reg);
> + int i = 0, ret = 0;
redundant initialization.
> +
> +static int mt6660_codec_dac_event(struct snd_soc_dapm_widget *w,
> + struct snd_kcontrol *kcontrol, int event)
> +{
> + switch (event) {
> + case SND_SOC_DAPM_POST_PMU:
> + usleep_range(1000, 1100);
> + break;
> + }
switch is redundant for one condition.
> + return 0;
> +}
> +
> +static int mt6660_codec_classd_event(struct snd_soc_dapm_widget *w,
> + struct snd_kcontrol *kcontrol, int event)
> +{
> + struct snd_soc_component *component =
> + snd_soc_dapm_to_component(w->dapm);
> + int ret = 0;
redundant intialization.
> +static inline int _mt6660_chip_power_on(struct mt6660_chip *chip, int on_off)
inline must here and other places also? Doesn't look like very small code.
> +{
> + u8 reg_data = 0;
> + int ret = 0;
> +
redundant intialization.
> +
> +static int mt6660_apply_plat_data(struct mt6660_chip *chip,
> + struct snd_soc_component *component)
> +{
> + size_t i = 0;
> + int num = chip->plat_data.init_setting_num;
> + int ret = 0;
> +
redundant intialization and please take care of all places.
> +static inline int _mt6660_chip_sw_reset(struct mt6660_chip *chip)
> +{
> + int ret;
> +
> + /* turn on main pll first, then trigger reset */
> + ret = regmap_write(chip->regmap, 0x03, 0x00);
> + if (ret < 0)
> + return ret;
> + ret = regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, 0x80);
error check not needed?
> +static int mt6660_parse_dt(struct mt6660_chip *chip, struct device *dev)
> +{
> + struct device_node *np = dev->of_node;
> + u32 val;
> + size_t i = 0;
> +
> + if (!np) {
> + dev_err(dev, "no device node\n");
> + return -EINVAL;
> + }
> +
> + if (of_property_read_u32(np, "rt,init_setting_num", &val)) {
> + dev_err(dev, "no init setting\n");
> + chip->plat_data.init_setting_num = 0;
> + } else {
> + chip->plat_data.init_setting_num = val;
> + }
> +
> + chip->plat_data.init_setting_addr =
> + devm_kzalloc(dev, sizeof(u32) *
> + chip->plat_data.init_setting_num, GFP_KERNEL);
> + chip->plat_data.init_setting_mask =
> + devm_kzalloc(dev, sizeof(u32) *
> + chip->plat_data.init_setting_num, GFP_KERNEL);
> + chip->plat_data.init_setting_val =
> + devm_kzalloc(dev, sizeof(u32) *
> + chip->plat_data.init_setting_num, GFP_KERNEL);
> +
memory allocation failures not taken care of and if
chip->plat_data.init_setting_num is 0, allocation required.
> diff --git a/sound/soc/codecs/mt6660.h b/sound/soc/codecs/mt6660.h
> new file mode 100644
> index 0000000..6c40b40
> --- /dev/null
> +++ b/sound/soc/codecs/mt6660.h
> +
> +struct mt6660_platform_data {
> + u8 init_setting_num;
> + u32 *init_setting_addr;
> + u32 *init_setting_mask;
> + u32 *init_setting_val;
> +};
packed could have been better.
> +
> +struct mt6660_chip {
> + struct i2c_client *i2c;
> + struct device *dev;
> + struct platform_device *param_dev;
> + struct mt6660_platform_data plat_data;
> + struct mutex io_lock;
> + struct regmap *regmap;
> + u16 chip_rev;
> +};
> +
here as well.
Thanks,
Sriram.
--