From: Sriram Periyasamy <sriram.oqensourz@gmail.com>
To: Jeff Chang <richtek.jeff.chang@gmail.com>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
tiwai@suse.com, lgirdwood@gmail.com, matthias.bgg@gmail.com,
broonie@kernel.org, jeff_chang@richtek.com,
linux-arm-kernel@lists.infradead.org
Subject: Re: [alsa-devel] [PATCH v4] ASoC: Add MediaTek MT6660 Speaker Amp Driver
Date: Thu, 9 Jan 2020 22:48:36 +0530 [thread overview]
Message-ID: <20200109171833.GA2709@sriram-VirtualBox> (raw)
In-Reply-To: <1578366545-30251-1-git-send-email-richtek.jeff.chang@gmail.com>
On Tue, Jan 07, 2020 at 11:09:05AM +0800, Jeff Chang wrote:
> From: Jeff Chang <jeff_chang@richtek.com>
>
> 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.
--
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
WARNING: multiple messages have this Message-ID (diff)
From: Sriram Periyasamy <sriram.oqensourz@gmail.com>
To: Jeff Chang <richtek.jeff.chang@gmail.com>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
tiwai@suse.com, lgirdwood@gmail.com, matthias.bgg@gmail.com,
broonie@kernel.org, jeff_chang@richtek.com,
linux-arm-kernel@lists.infradead.org
Subject: Re: [alsa-devel] [PATCH v4] ASoC: Add MediaTek MT6660 Speaker Amp Driver
Date: Thu, 9 Jan 2020 22:48:36 +0530 [thread overview]
Message-ID: <20200109171833.GA2709@sriram-VirtualBox> (raw)
In-Reply-To: <1578366545-30251-1-git-send-email-richtek.jeff.chang@gmail.com>
On Tue, Jan 07, 2020 at 11:09:05AM +0800, Jeff Chang wrote:
> From: Jeff Chang <jeff_chang@richtek.com>
>
> 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.
--
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
WARNING: multiple messages have this Message-ID (diff)
From: Sriram Periyasamy <sriram.oqensourz@gmail.com>
To: Jeff Chang <richtek.jeff.chang@gmail.com>
Cc: lgirdwood@gmail.com, alsa-devel@alsa-project.org,
linux-kernel@vger.kernel.org, tiwai@suse.com,
jeff_chang@richtek.com, broonie@kernel.org,
matthias.bgg@gmail.com, linux-arm-kernel@lists.infradead.org
Subject: Re: [alsa-devel] [PATCH v4] ASoC: Add MediaTek MT6660 Speaker Amp Driver
Date: Thu, 9 Jan 2020 22:48:36 +0530 [thread overview]
Message-ID: <20200109171833.GA2709@sriram-VirtualBox> (raw)
In-Reply-To: <1578366545-30251-1-git-send-email-richtek.jeff.chang@gmail.com>
On Tue, Jan 07, 2020 at 11:09:05AM +0800, Jeff Chang wrote:
> From: Jeff Chang <jeff_chang@richtek.com>
>
> 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.
--
next prev parent reply other threads:[~2020-01-09 17:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 3:09 [alsa-devel] [PATCH v4] ASoC: Add MediaTek MT6660 Speaker Amp Driver Jeff Chang
2020-01-07 3:09 ` Jeff Chang
2020-01-07 3:09 ` Jeff Chang
2020-01-09 17:18 ` Sriram Periyasamy [this message]
2020-01-09 17:18 ` [alsa-devel] " Sriram Periyasamy
2020-01-09 17:18 ` Sriram Periyasamy
2020-01-09 18:57 ` Takashi Iwai
2020-01-09 18:57 ` Takashi Iwai
2020-01-09 18:57 ` Takashi Iwai
-- strict thread matches above, loose matches on Subject: below --
2019-12-26 2:30 Jeff Chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200109171833.GA2709@sriram-VirtualBox \
--to=sriram.oqensourz@gmail.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=jeff_chang@richtek.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=richtek.jeff.chang@gmail.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.