Skip to contentSkip to conversation

ASoC: Add max98925 codec driver

PATCH In review Anish Kumar 4 participants 9 messages Jan 15, 2015 – Jan 17, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: Add max98925 codec driver

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

---
 sound/soc/codecs/max98925.c | 954 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98925.h | 842 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1796 insertions(+)
 create mode 100644 sound/soc/codecs/max98925.c
 create mode 100644 sound/soc/codecs/max98925.h
sound/soc/codecs/max98925.c new file +954 -0
new file mode 100644
index 0000000..ab78064
@@ -0,0 +1,954 @@
+/*
+ * max98925.c -- ALSA SoC Stereo MAX98925 driver
+ *
+ * Copyright 2013-15 Maxim Integrated Products
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
+#include <linux/cdev.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include <sound/max98925.h>
+#include "max98925.h"
+
+static struct reg_default max98925_reg[] = {
+	{ 0x00, 0x00 }, /* Battery Voltage Data */
+	{ 0x01, 0x00 }, /* Boost Voltage Data */
+	{ 0x02, 0x00 }, /* Live Status0 */
+	{ 0x03, 0x00 }, /* Live Status1 */
+	{ 0x04, 0x00 }, /* Live Status2 */
+	{ 0x05, 0x00 }, /* State0 */
+	{ 0x06, 0x00 }, /* State1 */
+	{ 0x07, 0x00 }, /* State2 */
+	{ 0x08, 0x00 }, /* Flag0 */
+	{ 0x09, 0x00 }, /* Flag1 */
+	{ 0x0A, 0x00 }, /* Flag2 */
+	{ 0x0B, 0x00 }, /* IRQ Enable0 */
+	{ 0x0C, 0x00 }, /* IRQ Enable1 */
+	{ 0x0D, 0x00 }, /* IRQ Enable2 */
+	{ 0x0E, 0x00 }, /* IRQ Clear0 */
+	{ 0x0F, 0x00 }, /* IRQ Clear1 */
+	{ 0x10, 0x00 }, /* IRQ Clear2 */
+	{ 0x11, 0xC0 }, /* Map0 */
+	{ 0x12, 0x00 }, /* Map1 */
+	{ 0x13, 0x00 }, /* Map2 */
+	{ 0x14, 0xF0 }, /* Map3 */
+	{ 0x15, 0x00 }, /* Map4 */
+	{ 0x16, 0xAB }, /* Map5 */
+	{ 0x17, 0x89 }, /* Map6 */
+	{ 0x18, 0x00 }, /* Map7 */
+	{ 0x19, 0x00 }, /* Map8 */
+	{ 0x1A, 0x06 }, /* DAI Clock Mode 1 */
+	{ 0x1B, 0xC0 }, /* DAI Clock Mode 2 */
+	{ 0x1C, 0x00 }, /* DAI Clock Divider Denominator MSBs */
+	{ 0x1D, 0x00 }, /* DAI Clock Divider Denominator LSBs */
+	{ 0x1E, 0xF0 }, /* DAI Clock Divider Numerator MSBs */
+	{ 0x1F, 0x00 }, /* DAI Clock Divider Numerator LSBs */
+	{ 0x20, 0x50 }, /* Format */
+	{ 0x21, 0x00 }, /* TDM Slot Select */
+	{ 0x22, 0x00 }, /* DOUT Configuration VMON */
+	{ 0x23, 0x00 }, /* DOUT Configuration IMON */
+	{ 0x24, 0x00 }, /* DOUT Configuration VBAT */
+	{ 0x25, 0x00 }, /* DOUT Configuration VBST */
+	{ 0x26, 0x00 }, /* DOUT Configuration FLAG */
+	{ 0x27, 0xFF }, /* DOUT HiZ Configuration 1 */
+	{ 0x28, 0xFF }, /* DOUT HiZ Configuration 2 */
+	{ 0x29, 0xFF }, /* DOUT HiZ Configuration 3 */
+	{ 0x2A, 0xFF }, /* DOUT HiZ Configuration 4 */
+	{ 0x2B, 0x02 }, /* DOUT Drive Strength */
+	{ 0x2C, 0x90 }, /* Filters */
+	{ 0x2D, 0x00 }, /* Gain */
+	{ 0x2E, 0x02 }, /* Gain Ramping */
+	{ 0x2F, 0x00 }, /* Speaker Amplifier */
+	{ 0x30, 0x0A }, /* Threshold */
+	{ 0x31, 0x00 }, /* ALC Attack */
+	{ 0x32, 0x80 }, /* ALC Atten and Release */
+	{ 0x33, 0x00 }, /* ALC Infinite Hold Release */
+	{ 0x34, 0x92 }, /* ALC Configuration */
+	{ 0x35, 0x01 }, /* Boost Converter */
+	{ 0x36, 0x00 }, /* Block Enable */
+	{ 0x37, 0x00 }, /* Configuration */
+	{ 0x38, 0x00 }, /* Global Enable */
+	{ 0x3A, 0x00 }, /* Boost Limiter */
+	{ 0xFF, 0x50 }, /* Revision ID */
+};
+
+static bool max98925_volatile_register(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case MAX98925_R000_VBAT_DATA:
+	case MAX98925_R001_VBST_DATA:
+	case MAX98925_R002_LIVE_STATUS0:
+	case MAX98925_R003_LIVE_STATUS1:
+	case MAX98925_R004_LIVE_STATUS2:
+	case MAX98925_R005_STATE0:
+	case MAX98925_R006_STATE1:
+	case MAX98925_R007_STATE2:
+	case MAX98925_R008_FLAG0:
+	case MAX98925_R009_FLAG1:
+	case MAX98925_R00A_FLAG2:
+	case MAX98925_R0FF_VERSION:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static bool max98925_readable_register(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case MAX98925_R00E_IRQ_CLEAR0:
+	case MAX98925_R00F_IRQ_CLEAR1:
+	case MAX98925_R010_IRQ_CLEAR2:
+	case MAX98925_R033_ALC_HOLD_RLS:
+		return false;
+	default:
+		return true;
+	}
+};
+
+static const unsigned int max98925_spk_tlv[] = {
+	TLV_DB_RANGE_HEAD(1),
+	1, 31, TLV_DB_SCALE_ITEM(-600, 100, 0),
+};
+
+static int max98925_spk_gain_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+
+	ucontrol->value.integer.value[0] = max98925->spk_gain;
+	pr_debug("%s: spk_gain setting returned %d\n", __func__,
+				(int) ucontrol->value.integer.value[0]);
+	return 0;
+}
+
+static int max98925_spk_gain_put(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	unsigned int sel = ucontrol->value.integer.value[0];
+
+	if (sel < ((1 << M98925_SPK_GAIN_WIDTH) - 1)) {
+		regmap_update_bits(max98925->regmapL, MAX98925_R02D_GAIN,
+			M98925_SPK_GAIN_MASK, sel << M98925_SPK_GAIN_SHIFT);
+		regmap_update_bits(max98925->regmapR, MAX98925_R02D_GAIN,
+			M98925_SPK_GAIN_MASK, sel << M98925_SPK_GAIN_SHIFT);
+
+		max98925->spk_gain = sel;
+
+		pr_debug("%s: spk_gain set to %d\n", __func__, sel);
+	} else {
+		pr_debug("%s: valid speaker gain settings: %d to %d\n",
+			__func__, 0,
+			((1 << M98925_SPK_GAIN_WIDTH) - 1));
+	}
+	return 0;
+}
+
+static int max98925_reg_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol, unsigned int reg,
+		unsigned int mask, unsigned int shift)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	int data;
+
+	regmap_read(max98925->regmapL, reg, &data);
+	ucontrol->value.integer.value[0] =
+		(data & mask) >> shift;
+	return 0;
+}
+
+static int max98925_reg_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol, unsigned int reg,
+		unsigned int mask, unsigned int shift)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	unsigned int sel = ucontrol->value.integer.value[0];
+
+	regmap_update_bits(max98925->regmapL, reg, mask, sel << shift);
+	regmap_update_bits(max98925->regmapR, reg, mask, sel << shift);
+
+	pr_debug("%s: register 0x%02X, value 0x%02X\n", __func__, reg, sel);
+	return 0;
+}
+
+static int max98925_spk_ramp_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_get(kcontrol, ucontrol, MAX98925_R02E_GAIN_RAMPING,
+			M98925_SPK_RMP_EN_MASK, M98925_SPK_RMP_EN_SHIFT);
+}
+
+static int max98925_spk_ramp_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_put(kcontrol, ucontrol, MAX98925_R02E_GAIN_RAMPING,
+			M98925_SPK_RMP_EN_MASK, M98925_SPK_RMP_EN_SHIFT);
+}
+
+static int max98925_spk_zcd_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_get(kcontrol, ucontrol, MAX98925_R02E_GAIN_RAMPING,
+			M98925_SPK_ZCD_EN_MASK, M98925_SPK_ZCD_EN_SHIFT);
+}
+
+static int max98925_spk_zcd_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_put(kcontrol, ucontrol, MAX98925_R02E_GAIN_RAMPING,
+			M98925_SPK_ZCD_EN_MASK, M98925_SPK_ZCD_EN_SHIFT);
+}
+
+static int max98925_alc_en_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_get(kcontrol, ucontrol, MAX98925_R030_THRESHOLD,
+			M98925_ALC_EN_MASK, M98925_ALC_EN_SHIFT);
+}
+
+static int max98925_alc_en_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_put(kcontrol, ucontrol, MAX98925_R030_THRESHOLD,
+			M98925_ALC_EN_MASK, M98925_ALC_EN_SHIFT);
+}
+
+static int max98925_alc_threshold_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_get(kcontrol, ucontrol, MAX98925_R030_THRESHOLD,
+			M98925_ALC_TH_MASK, M98925_ALC_TH_SHIFT);
+}
+
+static int max98925_alc_threshold_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_put(kcontrol, ucontrol, MAX98925_R030_THRESHOLD,
+			M98925_ALC_TH_MASK, M98925_ALC_TH_SHIFT);
+}
+
+static const char * const max98925_boost_voltage_text[] = {"8.5V", "8.25V",
+		"8.0V", "7.75V", "7.5V", "7.25V", "7.0V", "6.75V",
+		"6.5V", "6.5V", "6.5V", "6.5V", "6.5V", "6.5V",
+		"6.5V", "6.5V"};
+
+static const struct soc_enum max98925_boost_voltage_enum =
+	SOC_ENUM_SINGLE(MAX98925_R037_CONFIGURATION, M98925_BST_VOUT_SHIFT, 15,
+			max98925_boost_voltage_text);
+
+static int max98925_boost_voltage_get(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_get(kcontrol, ucontrol, MAX98925_R037_CONFIGURATION,
+			M98925_BST_VOUT_MASK, M98925_BST_VOUT_SHIFT);
+}
+
+static int max98925_boost_voltage_put(struct snd_kcontrol *kcontrol,
+		struct snd_ctl_elem_value *ucontrol)
+{
+	return max98925_reg_put(kcontrol, ucontrol, MAX98925_R037_CONFIGURATION,
+			M98925_BST_VOUT_MASK, M98925_BST_VOUT_SHIFT);
+}
+
+static const struct snd_kcontrol_new max98925_snd_controls[] = {
+
+	SOC_SINGLE_EXT_TLV("Speaker Gain", MAX98925_R02D_GAIN,
+		M98925_SPK_GAIN_SHIFT, (1<<M98925_SPK_GAIN_WIDTH)-1, 0,
+		max98925_spk_gain_get, max98925_spk_gain_put, max98925_spk_tlv),
+
+	SOC_SINGLE_EXT("Speaker Ramp", 0, 0, 1, 0,
+		max98925_spk_ramp_get, max98925_spk_ramp_put),
+
+	SOC_SINGLE_EXT("Speaker ZCD", 0, 0, 1, 0,
+		max98925_spk_zcd_get, max98925_spk_zcd_put),
+
+	SOC_SINGLE_EXT("ALC Enable", 0, 0, 1, 0,
+		max98925_alc_en_get, max98925_alc_en_put),
+
+	SOC_SINGLE_EXT("ALC Threshold", 0, 0, (1<<M98925_ALC_TH_WIDTH)-1, 0,
+		max98925_alc_threshold_get, max98925_alc_threshold_put),
+
+	SOC_ENUM_EXT("Boost Output Voltage", max98925_boost_voltage_enum,
+		max98925_boost_voltage_get, max98925_boost_voltage_put),
+};
+
+static int max98925_add_widgets(struct snd_soc_codec *codec)
+{
+	int ret;
+
+	ret = snd_soc_add_codec_controls(codec, max98925_snd_controls,
+		ARRAY_SIZE(max98925_snd_controls));
+	return 0;
+}
+
+/* codec sample rate and n/m dividers parameter table */
+static const struct {
+	int rate;
+	int  sr;
+	int divisors[3][2];
+} rate_table[] = {
+	{
+		.rate = 8000,
+		.sr = 0,
+		.divisors = { {1, 375}, {5, 1764}, {1, 384} }
+	},
+	{
+		.rate = 11025,
+		.sr = 1,
+		.divisors = { {147, 40000}, {1, 256}, {147, 40960} }
+	},
+	{
+		.rate = 12000,
+		.sr = 2,
+		.divisors = { {1, 250}, {5, 1176}, {1, 256} }
+	},
+	{
+		.rate = 16000,
+		.sr = 3,
+		.divisors = { {2, 375}, {5, 882}, {1, 192} }
+	},
+	{
+		.rate = 22050,
+		.sr = 4,
+		.divisors = { {147, 20000}, {1, 128}, {147, 20480} }
+	},
+	{
+		.rate = 24000,
+		.sr = 5,
+		.divisors = { {1, 125}, {5, 588}, {1, 128} }
+	},
+	{
+		.rate = 32000,
+		.sr = 6,
+		.divisors = { {4, 375}, {5, 441}, {1, 96} }
+	},
+	{
+		.rate = 44100,
+		.sr = 7,
+		.divisors = { {147, 10000}, {1, 64}, {147, 10240} }
+	},
+	{
+		.rate = 48000,
+		.sr = 8,
+		.divisors = { {2, 125}, {5, 294}, {1, 64} }
+	},
+};
+
+static inline int max98925_rate_value(int rate,
+		int clock, int *value, int *n, int *m)
+{
+	int ret = -EINVAL;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(rate_table); i++) {
+		if (rate_table[i].rate >= rate) {
+			*value = rate_table[i].sr;
+			*n = rate_table[i].divisors[clock][0];
+			*m = rate_table[i].divisors[clock][1];
+			ret = 0;
+			break;
+		}
+	}
+	pr_debug("%s: sample rate is %d, returning %d\n",
+				__func__, rate_table[i].rate, *value);
+	return ret;
+}
+
+static int max98925_set_tdm_slot(struct snd_soc_dai *codec_dai,
+	unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
+{
+	pr_info("%s: tx_mask 0x%X, rx_mask 0x%X, slots %d, slot width %d\n",
+			__func__, tx_mask, rx_mask, slots, slot_width);
+	return 0;
+}
+
+static void max98925_set_sense_data(struct max98925_priv *max98925)
+{
+	/*
+	 * 1. set VMON slots
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R022_DOUT_CFG_VMON,
+			M98925_DAI_VMON_EN_MASK, M98925_DAI_VMON_EN_MASK);
+	regmap_update_bits(max98925->regmapL, MAX98925_R022_DOUT_CFG_VMON,
+			M98925_DAI_VMON_SLOT_MASK, M98925_DAI_VMON_SLOT_00_01);
+	/*
+	 * 2. set IMON slots
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R023_DOUT_CFG_IMON,
+			M98925_DAI_IMON_EN_MASK, M98925_DAI_IMON_EN_MASK);
+	regmap_update_bits(max98925->regmapL, MAX98925_R023_DOUT_CFG_IMON,
+			M98925_DAI_IMON_SLOT_MASK, M98925_DAI_IMON_SLOT_02_03);
+}
+
+static void max98925_set_slave(struct max98925_priv *max98925)
+{
+	/*
+	 * 1. use BCLK instead of MCLK
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01A_DAI_CLK_MODE1,
+			M98925_DAI_CLK_SOURCE_MASK, M98925_DAI_CLK_SOURCE_MASK);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01A_DAI_CLK_MODE1,
+			M98925_DAI_CLK_SOURCE_MASK, M98925_DAI_CLK_SOURCE_MASK);
+	/*
+	 * 2. set DAI to slave mode
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_MAS_MASK, 0);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_MAS_MASK, 0);
+	/*
+	 * 3. set BLCKs to LRCLKs to 64
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_BSEL_MASK, M98925_DAI_BSEL_64);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_BSEL_MASK, M98925_DAI_BSEL_64);
+
+	max98925_set_sense_data(max98925);
+}
+
+static void max98925_set_master(struct max98925_priv *max98925)
+{
+	/*
+	 * 1. use MCLK for Left channel, right channel always BCLK
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01A_DAI_CLK_MODE1,
+			M98925_DAI_CLK_SOURCE_MASK, 0);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01A_DAI_CLK_MODE1,
+			M98925_DAI_CLK_SOURCE_MASK, M98925_DAI_CLK_SOURCE_MASK);
+	/*
+	 * 2. set left channel DAI to master mode, right channel always slave
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_MAS_MASK, M98925_DAI_MAS_MASK);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_MAS_MASK, 0);
+}
+
+static int max98925_dai_set_fmt(struct snd_soc_dai *codec_dai,
+				 unsigned int fmt)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	struct max98925_cdata *cdata;
+	unsigned int invert = 0;
+
+	pr_debug("%s: fmt 0x%08X\n", __func__, fmt);
+	cdata = &max98925->dai[0];
+	cdata->fmt = fmt;
+
+	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+	case SND_SOC_DAIFMT_CBS_CFS:
+		max98925_set_slave(max98925);
+		break;
+	case SND_SOC_DAIFMT_CBM_CFM:
+		max98925_set_master(max98925);
+		break;
+	case SND_SOC_DAIFMT_CBS_CFM:
+	case SND_SOC_DAIFMT_CBM_CFS:
+	default:
+		dev_err(codec->dev, "DAI clock mode unsupported");
+		return -EINVAL;
+	}
+
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+	case SND_SOC_DAIFMT_LEFT_J:
+		break;
+	case SND_SOC_DAIFMT_DSP_A:
+	default:
+		dev_err(codec->dev, "DAI format unsupported, fmt:0x%x", fmt);
+		return -EINVAL;
+	}
+	pr_debug("DAI format supported, fmt:0x%x", fmt);
+
+	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+	case SND_SOC_DAIFMT_NB_NF:
+		break;
+	case SND_SOC_DAIFMT_NB_IF:
+		invert = M98925_DAI_WCI_MASK;
+		break;
+	case SND_SOC_DAIFMT_IB_NF:
+		invert = M98925_DAI_BCI_MASK;
+		break;
+	case SND_SOC_DAIFMT_IB_IF:
+		invert = M98925_DAI_BCI_MASK | M98925_DAI_WCI_MASK;
+		break;
+	default:
+		dev_err(codec->dev, "DAI invert mode unsupported");
+		return -EINVAL;
+	}
+
+	regmap_update_bits(max98925->regmapL, MAX98925_R020_FORMAT,
+			M98925_DAI_BCI_MASK | M98925_DAI_BCI_MASK, invert);
+	regmap_update_bits(max98925->regmapR, MAX98925_R020_FORMAT,
+			M98925_DAI_BCI_MASK | M98925_DAI_BCI_MASK, invert);
+	return 0;
+}
+
+static int max98925_set_bias_level(struct snd_soc_codec *codec,
+				   enum snd_soc_bias_level level)
+{
+	codec->dapm.bias_level = level;
+	return 0;
+}
+
+static int max98925_set_clock(struct max98925_priv *max98925, unsigned int rate)
+{
+	unsigned int dai_sr = 0;
+	unsigned int clock;
+	unsigned int mdll;
+	unsigned int n;
+	unsigned int m;
+
+	switch (max98925->sysclk) {
+	case 6000000:
+		clock = 0;
+		mdll  = M98925_MDLL_MULT_MCLKx16;
+		break;
+	case 11289600:
+		clock = 1;
+		mdll  = M98925_MDLL_MULT_MCLKx8;
+		break;
+	case 12000000:
+		clock = 0;
+		mdll  = M98925_MDLL_MULT_MCLKx8;
+		break;
+	case 12288000:
+		clock = 2;
+		mdll  = M98925_MDLL_MULT_MCLKx8;
+		break;
+	default:
+		dev_info(max98925->codec->dev, "unsupported sysclk %d\n",
+					max98925->sysclk);
+		return -EINVAL;
+	}
+
+	if (max98925_rate_value(rate, clock, &dai_sr, &n, &m))
+		return -EINVAL;
+
+	/*
+	 * 1. set DAI_SR to correct LRCLK frequency
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_SR_MASK, dai_sr << M98925_DAI_SR_SHIFT);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01B_DAI_CLK_MODE2,
+			M98925_DAI_SR_MASK, dai_sr << M98925_DAI_SR_SHIFT);
+	/*
+	 * 2. set DAI m divider
+	 */
+	regmap_write(max98925->regmapL, MAX98925_R01C_DAI_CLK_DIV_M_MSBS,
+			m >> 8);
+	regmap_write(max98925->regmapL, MAX98925_R01D_DAI_CLK_DIV_M_LSBS,
+			m & 0xFF);
+	/*
+	 * 3. set DAI n divider
+	 */
+	regmap_write(max98925->regmapL, MAX98925_R01E_DAI_CLK_DIV_N_MSBS,
+			n >> 8);
+	regmap_write(max98925->regmapL, MAX98925_R01F_DAI_CLK_DIV_N_LSBS,
+			n & 0xFF);
+	/*
+	 * 4. set MDLL
+	 */
+	regmap_update_bits(max98925->regmapL, MAX98925_R01A_DAI_CLK_MODE1,
+			M98925_MDLL_MULT_MASK, mdll << M98925_MDLL_MULT_SHIFT);
+	regmap_update_bits(max98925->regmapR, MAX98925_R01A_DAI_CLK_MODE1,
+			M98925_MDLL_MULT_MASK, mdll << M98925_MDLL_MULT_SHIFT);
+
+	return 0;
+}
+
+static int max98925_dai_hw_params(struct snd_pcm_substream *substream,
+				   struct snd_pcm_hw_params *params,
+				   struct snd_soc_dai *dai)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	struct max98925_cdata *cdata;
+	unsigned int rate;
+
+	cdata = &max98925->dai[0];
+	rate = params_rate(params);
+
+	switch (params_format(params)) {
+	case SNDRV_PCM_FORMAT_S16_LE:
+		regmap_update_bits(max98925->regmapL, MAX98925_R020_FORMAT,
+				M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_16);
+		regmap_update_bits(max98925->regmapR, MAX98925_R020_FORMAT,
+				M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_16);
+		break;
+	case SNDRV_PCM_FORMAT_S24_LE:
+		regmap_update_bits(max98925->regmapL, MAX98925_R020_FORMAT,
+				M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_32);
+		regmap_update_bits(max98925->regmapR, MAX98925_R020_FORMAT,
+				M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_32);
+		pr_debug("%s: (really set to 32 bits)\n", __func__);
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		regmap_update_bits(max98925->regmapL, MAX98925_R020_FORMAT,
+				M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_32);
+		regmap_update_bits(max98925->regmapR, MAX98925_R020_FORMAT,
+				M98925_DAI_CHANSZ_MASK, M98925_DAI_CHANSZ_32);
+		break;
+	default:
+		pr_err("%s: format unsupported %d",
+				__func__, params_format(params));
+		return -EINVAL;
+	}
+	pr_debug("%s: format supported %d", __func__, params_format(params));
+	return max98925_set_clock(max98925, rate);
+}
+
+static int max98925_dai_set_sysclk(struct snd_soc_dai *dai,
+				   int clk_id, unsigned int freq, int dir)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+
+	pr_debug("%s: clk_id %d, freq %d, dir %d\n",
+				__func__, clk_id, freq, dir);
+	max98925->sysclk = freq;
+	return 0;
+}
+
+static int max98925_dai_digital_mute(struct snd_soc_dai *codec_dai, int mute)
+{
+	struct max98925_priv *max98925 =
+				snd_soc_codec_get_drvdata(codec_dai->codec);
+
+	pr_debug("%s: mute %d\n", __func__, mute);
+	if (mute) {
+		regmap_update_bits(max98925->regmapL, MAX98925_R02D_GAIN,
+			M98925_SPK_GAIN_MASK, 0x00);
+		regmap_update_bits(max98925->regmapR, MAX98925_R02D_GAIN,
+			M98925_SPK_GAIN_MASK, 0x00);
+
+		regmap_update_bits(max98925->regmapL,
+			MAX98925_R038_GLOBAL_ENABLE, M98925_EN_MASK, 0x0);
+		regmap_update_bits(max98925->regmapR,
+			MAX98925_R038_GLOBAL_ENABLE, M98925_EN_MASK, 0x0);
+	} else	{
+		regmap_update_bits(max98925->regmapL, MAX98925_R02D_GAIN,
+			M98925_SPK_GAIN_MASK, max98925->spk_gain);
+		regmap_update_bits(max98925->regmapR, MAX98925_R02D_GAIN,
+			M98925_SPK_GAIN_MASK, max98925->spk_gain);
+
+		regmap_update_bits(max98925->regmapL,
+			MAX98925_R036_BLOCK_ENABLE,
+			M98925_BST_EN_MASK | M98925_SPK_EN_MASK |
+			M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK,
+			M98925_BST_EN_MASK | M98925_SPK_EN_MASK |
+			M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK);
+		regmap_update_bits(max98925->regmapR,
+			MAX98925_R036_BLOCK_ENABLE,
+			M98925_BST_EN_MASK | M98925_SPK_EN_MASK |
+			M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK,
+			M98925_BST_EN_MASK | M98925_SPK_EN_MASK |
+			M98925_ADC_IMON_EN_MASK | M98925_ADC_VMON_EN_MASK);
+
+		regmap_write(max98925->regmapL, MAX98925_R038_GLOBAL_ENABLE,
+			M98925_EN_MASK);
+		regmap_write(max98925->regmapR, MAX98925_R038_GLOBAL_ENABLE,
+			M98925_EN_MASK);
+	}
+	return 0;
+}
+
+#define MAX98925_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
+			SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
+
+static struct snd_soc_dai_ops max98925_dai_ops = {
+	.set_sysclk = max98925_dai_set_sysclk,
+	.set_fmt = max98925_dai_set_fmt,
+	.set_tdm_slot = max98925_set_tdm_slot,
+	.hw_params = max98925_dai_hw_params,
+	.digital_mute = max98925_dai_digital_mute,
+};
+
+static struct snd_soc_dai_driver max98925_dai[] = {
+	{
+		.name = "max98925-aif1",
+		.playback = {
+			.stream_name = "HiFi Playback",
+			.channels_min = 1,
+			.channels_max = 2,
+			.rates = SNDRV_PCM_RATE_8000_48000,
+			.formats = MAX98925_FORMATS,
+		},
+		.capture = {
+			.stream_name = "HiFi Capture",
+			.channels_min = 1,
+			.channels_max = 2,
+			.rates = SNDRV_PCM_RATE_8000_48000,
+			.formats = MAX98925_FORMATS,
+		},
+		.ops = &max98925_dai_ops,
+	}
+};
+
+static void max98925_handle_pdata(struct snd_soc_codec *codec)
+{
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	struct max98925_pdata *pdata = max98925->pdata;
+
+	if (!pdata) {
+		dev_dbg(codec->dev, "No platform data\n");
+		return;
+	}
+}
+
+static int max98925_probe(struct snd_soc_codec *codec)
+{
+	struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+	struct max98925_cdata *cdata;
+	int ret = 0;
+	int reg = 0;
+
+	dev_info(codec->dev, "build number %s\n", MAX98925_REVISION);
+
+	max98925->codec = codec;
+	codec->control_data = max98925->regmapL;
+	ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_I2C);
+	if (ret != 0) {
+		dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+		return ret;
+	}
+
+	max98925->sysclk = (unsigned)-1;
+	max98925->spk_gain = 0x14;
+
+	cdata = &max98925->dai[0];
+	cdata->rate = (unsigned)-1;
+	cdata->fmt  = (unsigned)-1;
+
+	reg = 0;
+	ret = regmap_read(max98925->regmapL, MAX98925_R0FF_VERSION, &reg);
+	if ((ret < 0) ||
+		((reg != MAX98925_VERSION) && (reg != MAX98925_VERSION1))) {
+		dev_err(codec->dev,
+			"L device initialization error (%d 0x%02X)\n",
+			ret,
+			reg);
+		goto err_access;
+	}
+	dev_info(codec->dev, "L device version 0x%02X\n", reg);
+
+	if (max98925->regmapR != NULL) {
+		reg = 0;
+		ret = regmap_read(max98925->regmapR,
+				MAX98925_R0FF_VERSION, &reg);
+		if ((ret < 0) || ((reg != MAX98925_VERSION)
+				&& (reg != MAX98925_VERSION1))) {
+			dev_err(codec->dev,
+				"R device initialization error (%d 0x%02X)\n",
+				ret, reg);
+			goto err_access;
+		}
+		dev_info(codec->dev, "R device version 0x%02X\n", reg);
+	}
+	regmap_write(max98925->regmapL, MAX98925_R038_GLOBAL_ENABLE, 0x00);
+	regmap_write(max98925->regmapR, MAX98925_R038_GLOBAL_ENABLE, 0x00);
+
+	/* It's not the default but we need to set DAI_DLY */
+	regmap_write(max98925->regmapL,
+				MAX98925_R020_FORMAT, M98925_DAI_DLY_MASK);
+	regmap_write(max98925->regmapR,
+				MAX98925_R020_FORMAT, M98925_DAI_DLY_MASK);
+
+	regmap_write(max98925->regmapL,
+				MAX98925_R021_TDM_SLOT_SELECT, 0xC8);
+	regmap_write(max98925->regmapR,
+				MAX98925_R021_TDM_SLOT_SELECT, 0xC8);
+
+	regmap_write(max98925->regmapL,
+				MAX98925_R027_DOUT_HIZ_CFG1, 0xFF);
+	regmap_write(max98925->regmapL,
+				MAX98925_R028_DOUT_HIZ_CFG2, 0xFF);
+	regmap_write(max98925->regmapL,
+				MAX98925_R029_DOUT_HIZ_CFG3, 0xFF);
+	regmap_write(max98925->regmapL,
+				MAX98925_R02A_DOUT_HIZ_CFG4, 0xF0);
+	regmap_write(max98925->regmapR,
+				MAX98925_R027_DOUT_HIZ_CFG1, 0xFF);
+	regmap_write(max98925->regmapR,
+				MAX98925_R028_DOUT_HIZ_CFG2, 0xFF);
+	regmap_write(max98925->regmapR,
+				MAX98925_R029_DOUT_HIZ_CFG3, 0xFF);
+	regmap_write(max98925->regmapR,
+				MAX98925_R02A_DOUT_HIZ_CFG4, 0x0F);
+
+	regmap_write(max98925->regmapL,
+				MAX98925_R02C_FILTERS, 0xD8);
+	regmap_write(max98925->regmapR,
+				MAX98925_R02C_FILTERS, 0xD8);
+
+	regmap_write(max98925->regmapL,
+				MAX98925_R034_ALC_CONFIGURATION, 0xF8);
+	regmap_write(max98925->regmapR,
+				MAX98925_R034_ALC_CONFIGURATION, 0xF8);
+
+	regmap_write(max98925->regmapL,
+				MAX98925_R037_CONFIGURATION, 0xF0);
+	regmap_write(max98925->regmapR,
+				MAX98925_R037_CONFIGURATION, 0xF0);
+
+	/* Disable ALC muting */
+	regmap_write(max98925->regmapL,
+				MAX98925_R03A_BOOST_LIMITER, 0xF8);
+	regmap_write(max98925->regmapR,
+				MAX98925_R03A_BOOST_LIMITER, 0xF8);
+
+	regmap_update_bits(max98925->regmapL, MAX98925_R02D_GAIN,
+			M98925_DAC_IN_SEL_MASK, M98925_DAC_IN_SEL_LEFT_DAI);
+	regmap_update_bits(max98925->regmapR, MAX98925_R02D_GAIN,
+			M98925_DAC_IN_SEL_MASK, M98925_DAC_IN_SEL_RIGHT_DAI);
+
+	max98925_handle_pdata(codec);
+	max98925_add_widgets(codec);
+err_access:
+	return ret;
+}
+
+static struct snd_soc_codec_driver soc_codec_dev_max98925 = {
+	.probe            = max98925_probe,
+	.set_bias_level   = max98925_set_bias_level,
+};
+
+static const struct regmap_config max98925_regmap = {
+	.reg_bits         = 8,
+	.val_bits         = 8,
+	.max_register     = MAX98925_R0FF_VERSION,
+	.reg_defaults     = max98925_reg,
+	.num_reg_defaults = ARRAY_SIZE(max98925_reg),
+	.volatile_reg     = max98925_volatile_register,
+	.readable_reg     = max98925_readable_register,
+	.cache_type       = REGCACHE_RBTREE,
+};
+
+/* There should be a second MAX98925 on the board */
+static struct i2c_board_info max98925_i2c_second[] = {
+	{
+		I2C_BOARD_INFO("max98925R", 0x32),
+	}
+};
+
+struct i2c_client *add_second_device(int busnum)
+{
+	struct i2c_client *i2c = NULL;
+	struct i2c_adapter *adapter;
+
+	adapter = i2c_get_adapter(busnum);
+	if (adapter != NULL)
+		i2c = i2c_new_device(adapter, max98925_i2c_second);
+
+	return i2c;
+}
+
+static int max98925_i2c_probe(struct i2c_client *i2c_l,
+			     const struct i2c_device_id *id)
+{
+	struct max98925_priv *max98925;
+	struct i2c_client *i2c_r;
+	int ret;
+
+	pr_info("%s: enter, device '%s'\n", __func__, id->name);
+	if (strcmp(id->name, "max98925R") == 0)
+		return 0;
+
+	max98925 = kzalloc(sizeof(struct max98925_priv), GFP_KERNEL);
+	if (max98925 == NULL)
+		return -ENOMEM;
+
+	max98925->devtype = id->driver_data;
+	i2c_set_clientdata(i2c_l, max98925);
+	max98925->control_data = i2c_l;
+	max98925->pdata = i2c_l->dev.platform_data;
+
+	max98925->regmapL = regmap_init_i2c(i2c_l, &max98925_regmap);
+	if (IS_ERR(max98925->regmapL)) {
+		ret = PTR_ERR(max98925->regmapL);
+		dev_err(&i2c_l->dev, "Failed to allocate regmapL: %d\n", ret);
+		goto err_out;
+	}
+
+	/* Check for second MAX98925 */
+	i2c_r = add_second_device(2);
+
+	if (IS_ERR(i2c_r)) {
+		dev_err(&i2c_l->dev, "second MAX98925 not found\n");
+		ret = -ENODEV;
+		goto err_out;
+	} else {
+		max98925->regmapR = regmap_init_i2c(i2c_r, &max98925_regmap);
+		if (IS_ERR(max98925->regmapR)) {
+			ret = PTR_ERR(max98925->regmapR);
+			dev_err(&i2c_r->dev,
+				"Failed to allocate regmapR: %d\n", ret);
+			goto err_out;
+		}
+	}
+	ret = snd_soc_register_codec(&i2c_l->dev, &soc_codec_dev_max98925,
+			max98925_dai, ARRAY_SIZE(max98925_dai));
+err_out:
+	if (ret < 0) {
+		if (max98925->regmapL)
+			regmap_exit(max98925->regmapL);
+		if (max98925->regmapR)
+			regmap_exit(max98925->regmapR);
+		kfree(max98925);
+	}
+	return ret;
+}
+
+static int max98925_i2c_remove(struct i2c_client *client)
+{
+	struct max98925_priv *max98925 = dev_get_drvdata(&client->dev);
+
+	snd_soc_unregister_codec(&client->dev);
+	if (max98925->regmapL)
+		regmap_exit(max98925->regmapL);
+	if (max98925->regmapR)
+		regmap_exit(max98925->regmapL);
+	kfree(i2c_get_clientdata(client));
+	return 0;
+}
+
+static const struct i2c_device_id max98925_i2c_id[] = {
+	{ "max98925", MAX98925 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, max98925_i2c_id);
+
+static struct i2c_driver max98925_i2c_driver = {
+	.driver = {
+		.name = "max98925",
+		.owner = THIS_MODULE,
+		.pm = NULL,
+	},
+	.probe  = max98925_i2c_probe,
+	.remove = max98925_i2c_remove,
+	.id_table = max98925_i2c_id,
+};
+
+module_i2c_driver(max98925_i2c_driver);
+
+MODULE_DESCRIPTION("ALSA SoC MAX98925 Stereo driver");
+MODULE_AUTHOR("Ralph Birt <[email protected]>, Anish kumar <[email protected]>");
+MODULE_LICENSE("GPL");
sound/soc/codecs/max98925.h new file +842 -0

842 lines not on this page · raw message

Signature · 1 line
1.9.3
#1 lore raw
Quoted 13 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

---
 sound/soc/codecs/max98925.c | 954 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98925.h | 842 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1796 insertions(+)
 create mode 100644 sound/soc/codecs/max98925.c
 create mode 100644 sound/soc/codecs/max98925.h
sound/soc/codecs/max98925.c +0 -0

[ snip ]

sound/soc/codecs/max98925.c line 274

Quoted 6 lines
sound/soc/codecs/max98925.c +6 -0
+static const struct snd_kcontrol_new max98925_snd_controls[] = {
+
+       SOC_SINGLE_EXT_TLV("Speaker Gain", MAX98925_R02D_GAIN,
+               M98925_SPK_GAIN_SHIFT, (1<<M98925_SPK_GAIN_WIDTH)-1, 0,
+               max98925_spk_gain_get, max98925_spk_gain_put, max98925_spk_tlv),
+

You can use BIT(XXX_SHIFT) macro for 1<<XXX_SHIFT operations, makes the code a little cleaner to look at.

sound/soc/codecs/max98925.c line 296

Quoted 7 lines
sound/soc/codecs/max98925.c +7 -0
+
+static int max98925_add_widgets(struct snd_soc_codec *codec)
+{
+       int ret;
+
+       ret = snd_soc_add_codec_controls(codec, max98925_snd_controls,
+               ARRAY_SIZE(max98925_snd_controls));

Instead, you may only update controls and num_controls member of snd_soc_codec_driver structure.

sound/soc/codecs/max98925.c line 452

Quoted 9 lines
sound/soc/codecs/max98925.c +9 -0
+static int max98925_dai_set_fmt(struct snd_soc_dai *codec_dai,
+                                unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+       struct max98925_cdata *cdata;
+       unsigned int invert = 0;
+
+       pr_debug("%s: fmt 0x%08X\n", __func__, fmt);

better to use dev_dbg.

sound/soc/codecs/max98925.c line 626

Quoted 8 lines
sound/soc/codecs/max98925.c +8 -0
+static int max98925_dai_set_sysclk(struct snd_soc_dai *dai,
+                                  int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+
+       pr_debug("%s: clk_id %d, freq %d, dir %d\n",
+                               __func__, clk_id, freq, dir);

Please use dev_dbg whenever possible.

Quoted 6 lines
sound/soc/codecs/max98925.c +6 -0
+       if (max98925->regmapR != NULL) {
+               reg = 0;
+               ret = regmap_read(max98925->regmapR,
+                               MAX98925_R0FF_VERSION, &reg);
+               if ((ret < 0) || ((reg != MAX98925_VERSION)
+                               && (reg != MAX98925_VERSION1))) {

sound/soc/codecs/max98925.c line 768

Quoted 10 lines
sound/soc/codecs/max98925.c +10 -0
+                       dev_err(codec->dev,
+                               "R device initialization error (%d 0x%02X)\n",
+                               ret, reg);
+                       goto err_access;
+               }
+               dev_info(codec->dev, "R device version 0x%02X\n", reg);
+       }
+       regmap_write(max98925->regmapL, MAX98925_R038_GLOBAL_ENABLE, 0x00);
+       regmap_write(max98925->regmapR, MAX98925_R038_GLOBAL_ENABLE, 0x00);
+

Since most of the places the writes to regmapL and regmapR are duplicated, it might be a good idea to move the calls to a function and call that function with appropriate parameters instead.

Something like:
max98925_regmap_write_stereo(max98925, MAX98925_R038_GLOBAL_ENABLE, 0x00);

same applies for regmap_update_bits() call too.

sound/soc/codecs/max98925.c line 875

Quoted 12 lines
sound/soc/codecs/max98925.c +12 -0
+static int max98925_i2c_probe(struct i2c_client *i2c_l,
+                            const struct i2c_device_id *id)
+{
+       struct max98925_priv *max98925;
+       struct i2c_client *i2c_r;
+       int ret;
+
+       pr_info("%s: enter, device '%s'\n", __func__, id->name);
+       if (strcmp(id->name, "max98925R") == 0)
+               return 0;
+
+       max98925 = kzalloc(sizeof(struct max98925_priv), GFP_KERNEL);

devm_kzalloc ? no need to call kfree() in the exit path.

sound/soc/codecs/max98925.c line 884

Quoted 9 lines
sound/soc/codecs/max98925.c +9 -0
+       if (max98925 == NULL)
+               return -ENOMEM;
+
+       max98925->devtype = id->driver_data;
+       i2c_set_clientdata(i2c_l, max98925);
+       max98925->control_data = i2c_l;
+       max98925->pdata = i2c_l->dev.platform_data;
+
+       max98925->regmapL = regmap_init_i2c(i2c_l, &max98925_regmap);

devm_regmap_init_i2c? You won't have call regmap_exit() explicitly.

Quoted 5 lines
sound/soc/codecs/max98925.h new file +0 -0
new file mode 100644
index 0000000..9d89d34

[ snip ]

sound/soc/codecs/max98925.h line 87

Quoted 7 lines
sound/soc/codecs/max98925.h new file +7 -0
+
+/* MAX98925 Register Bit Fields */
+
+/* MAX98925_R002_LIVE_STATUS0 */
+#define M98925_THERMWARN_STATUS_MASK           (1<<3)
+#define M98925_THERMWARN_STATUS_SHIFT          3
+#define M98925_THERMWARN_STATUS_WIDTH          1

Please consider using a macro to create the mask value from shift and width, that is less error-prone. Something like this:

#define M98925_MASK(SHIFT, WIDTH) ((BIT(WIDTH)-1) << SHIFT) #define M98925_THERMWARN_STATUS_MASK \
M98925_MASK(M98925_THERMWARN_STATUS_SHIFT, M98925_THERMWARN_STATUS_WIDTH)

Also, for single bit definitions, you can get rid of the WIDTH definitions unless you are using them in the code, just use BIT(xxx_SHIFT) macro to define the mask.

Also, many of the defines are not used at all. Nothing against keeping them (for better representation of the hardware), but you may also consider removing them now and adding them as and when they are used in the code.

Signature · 1 line
Tushar Behera
author
#2 lore raw
Quoted 17 lines · Tushar Behera
Quoted 13 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

---
 sound/soc/codecs/max98925.c | 954 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/max98925.h | 842 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 1796 insertions(+)
 create mode 100644 sound/soc/codecs/max98925.c
 create mode 100644 sound/soc/codecs/max98925.h
sound/soc/codecs/max98925.c +0 -0

[ snip ]

Quoted 9 lines

sound/soc/codecs/max98925.c line 274

Quoted 6 lines
sound/soc/codecs/max98925.c +6 -0
+static const struct snd_kcontrol_new max98925_snd_controls[] = {
+
+       SOC_SINGLE_EXT_TLV("Speaker Gain", MAX98925_R02D_GAIN,
+               M98925_SPK_GAIN_SHIFT, (1<<M98925_SPK_GAIN_WIDTH)-1, 0,
+               max98925_spk_gain_get, max98925_spk_gain_put, max98925_spk_tlv),
+

You can use BIT(XXX_SHIFT) macro for 1<<XXX_SHIFT operations, makes the code a little cleaner to look at.

will do it.

Quoted 11 lines

sound/soc/codecs/max98925.c line 296

Quoted 8 lines
sound/soc/codecs/max98925.c +7 -0
+
+static int max98925_add_widgets(struct snd_soc_codec *codec)
+{
+       int ret;
+
+       ret = snd_soc_add_codec_controls(codec, max98925_snd_controls,
+               ARRAY_SIZE(max98925_snd_controls));

Instead, you may only update controls and num_controls member of snd_soc_codec_driver structure.

will do it.

Quoted 13 lines

sound/soc/codecs/max98925.c line 452

Quoted 10 lines
sound/soc/codecs/max98925.c +9 -0
+static int max98925_dai_set_fmt(struct snd_soc_dai *codec_dai,
+                                unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+       struct max98925_cdata *cdata;
+       unsigned int invert = 0;
+
+       pr_debug("%s: fmt 0x%08X\n", __func__, fmt);

better to use dev_dbg.

Quoted 10 lines

sound/soc/codecs/max98925.c line 626

Quoted 8 lines
sound/soc/codecs/max98925.c +8 -0
+static int max98925_dai_set_sysclk(struct snd_soc_dai *dai,
+                                  int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
+
+       pr_debug("%s: clk_id %d, freq %d, dir %d\n",
+                               __func__, clk_id, freq, dir);

Please use dev_dbg whenever possible.

will do it.

Quoted 18 lines
Quoted 7 lines
sound/soc/codecs/max98925.c +6 -0
+       if (max98925->regmapR != NULL) {
+               reg = 0;
+               ret = regmap_read(max98925->regmapR,
+                               MAX98925_R0FF_VERSION, &reg);
+               if ((ret < 0) || ((reg != MAX98925_VERSION)
+                               && (reg != MAX98925_VERSION1))) {

sound/soc/codecs/max98925.c line 768

Quoted 10 lines
sound/soc/codecs/max98925.c +10 -0
+                       dev_err(codec->dev,
+                               "R device initialization error (%d 0x%02X)\n",
+                               ret, reg);
+                       goto err_access;
+               }
+               dev_info(codec->dev, "R device version 0x%02X\n", reg);
+       }
+       regmap_write(max98925->regmapL, MAX98925_R038_GLOBAL_ENABLE, 0x00);
+       regmap_write(max98925->regmapR, MAX98925_R038_GLOBAL_ENABLE, 0x00);
+
Quoted 8 lines

Since most of the places the writes to regmapL and regmapR are duplicated, it might be a good idea to move the calls to a function and call that function with appropriate parameters instead.

Something like:
max98925_regmap_write_stereo(max98925, MAX98925_R038_GLOBAL_ENABLE, 0x00);

same applies for regmap_update_bits() call too.

nice suggestion.

Quoted 16 lines

sound/soc/codecs/max98925.c line 875

Quoted 13 lines
sound/soc/codecs/max98925.c +12 -0
+static int max98925_i2c_probe(struct i2c_client *i2c_l,
+                            const struct i2c_device_id *id)
+{
+       struct max98925_priv *max98925;
+       struct i2c_client *i2c_r;
+       int ret;
+
+       pr_info("%s: enter, device '%s'\n", __func__, id->name);
+       if (strcmp(id->name, "max98925R") == 0)
+               return 0;
+
+       max98925 = kzalloc(sizeof(struct max98925_priv), GFP_KERNEL);

devm_kzalloc ? no need to call kfree() in the exit path.

Quoted 11 lines

sound/soc/codecs/max98925.c line 884

Quoted 9 lines
sound/soc/codecs/max98925.c +9 -0
+       if (max98925 == NULL)
+               return -ENOMEM;
+
+       max98925->devtype = id->driver_data;
+       i2c_set_clientdata(i2c_l, max98925);
+       max98925->control_data = i2c_l;
+       max98925->pdata = i2c_l->dev.platform_data;
+
+       max98925->regmapL = regmap_init_i2c(i2c_l, &max98925_regmap);

devm_regmap_init_i2c? You won't have call regmap_exit() explicitly.

ok.

Quoted 24 lines
Quoted 6 lines
sound/soc/codecs/max98925.h new file +0 -0
new file mode 100644
index 0000000..9d89d34

[ snip ]

sound/soc/codecs/max98925.h line 87

Quoted 7 lines
sound/soc/codecs/max98925.h new file +7 -0
+
+/* MAX98925 Register Bit Fields */
+
+/* MAX98925_R002_LIVE_STATUS0 */
+#define M98925_THERMWARN_STATUS_MASK           (1<<3)
+#define M98925_THERMWARN_STATUS_SHIFT          3
+#define M98925_THERMWARN_STATUS_WIDTH          1

Please consider using a macro to create the mask value from shift and width, that is less error-prone. Something like this:

#define M98925_MASK(SHIFT, WIDTH) ((BIT(WIDTH)-1) << SHIFT) #define M98925_THERMWARN_STATUS_MASK \
M98925_MASK(M98925_THERMWARN_STATUS_SHIFT, M98925_THERMWARN_STATUS_WIDTH)

Quoted 8 lines

Also, for single bit definitions, you can get rid of the WIDTH definitions unless you are using them in the code, just use BIT(xxx_SHIFT) macro to define the mask.

Also, many of the defines are not used at all. Nothing against keeping them (for better representation of the hardware), but you may also consider removing them now and adding them as and when they are used in the code.

I would rather keep the defines which are not used as it is script generated file
and i would rather not touch it.

Quoted 3 lines

--
Tushar Behera

#3 lore raw
In reply to Anish Kumar
Quoted 5 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

Please make sure to submit drivers against the latest development version of the ASoC tree (http://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/log/?h=for-next). This has a couple of outdated things and won't even compile.

sound/soc/codecs/max98925.c line 123

Quoted 5 lines
sound/soc/codecs/max98925.c new file +5 -0
+
+static const unsigned int max98925_spk_tlv[] = {
+	TLV_DB_RANGE_HEAD(1),
+	1, 31, TLV_DB_SCALE_ITEM(-600, 100, 0),
+};

DECLARE_TLV_DB_SCALE(...)

sound/soc/codecs/max98925.c line 296

Quoted 6 lines
sound/soc/codecs/max98925.c new file +6 -0
+static int max98925_add_widgets(struct snd_soc_codec *codec)
+{
+	int ret;
+
+	ret = snd_soc_add_codec_controls(codec, max98925_snd_controls,
+		ARRAY_SIZE(max98925_snd_controls));

Assign this to the controls and num_controls fields of the CODEC driver instead of manually calling add_codec_controls.

[...]

Quoted 8 lines
sound/soc/codecs/max98925.c new file +8 -0
+static int max98925_set_tdm_slot(struct snd_soc_dai *codec_dai,
+	unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
+{
+	pr_info("%s: tx_mask 0x%X, rx_mask 0x%X, slots %d, slot width %d\n",
+			__func__, tx_mask, rx_mask, slots, slot_width);
+	return 0;
+}
+

[...]

sound/soc/codecs/max98925.c line 511

Quoted 7 lines
sound/soc/codecs/max98925.c new file +7 -0
+static int max98925_set_bias_level(struct snd_soc_codec *codec,
+				   enum snd_soc_bias_level level)
+{
+	codec->dapm.bias_level = level;
+	return 0;
+}
+

Drop all those all empty callbacks

Quoted 1 line

+static struct snd_soc_dai_ops max98925_dai_ops = {

const

Quoted 7 lines
sound/soc/codecs/max98925.c new file +7 -0
+	.set_sysclk = max98925_dai_set_sysclk,
+	.set_fmt = max98925_dai_set_fmt,
+	.set_tdm_slot = max98925_set_tdm_slot,
+	.hw_params = max98925_dai_hw_params,
+	.digital_mute = max98925_dai_digital_mute,
+};
+

[...]

Quoted 1 line

+static struct snd_soc_codec_driver soc_codec_dev_max98925 = {

const

sound/soc/codecs/max98925.c line 831

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+	.probe            = max98925_probe,
+	.set_bias_level   = max98925_set_bias_level,

You'll need at least some kind of DAPM, otherwise you CODEC won't do anything.

Quoted 2 lines
(quoted diff) +2 -0
+};
+

[...]

Quoted 18 lines
sound/soc/codecs/max98925.c new file +18 -0
+/* There should be a second MAX98925 on the board */
+static struct i2c_board_info max98925_i2c_second[] = {
+	{
+		I2C_BOARD_INFO("max98925R", 0x32),
+	}
+};
+
+struct i2c_client *add_second_device(int busnum)
+{
+	struct i2c_client *i2c = NULL;
+	struct i2c_adapter *adapter;
+
+	adapter = i2c_get_adapter(busnum);
+	if (adapter != NULL)
+		i2c = i2c_new_device(adapter, max98925_i2c_second);
+
+	return i2c;
+}

[...]

sound/soc/codecs/max98925.c line 892

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+	/* Check for second MAX98925 */
+	i2c_r = add_second_device(2);

If there are two devices instantiate them properly and create two CODEC devices, not some kind of hackery like this.

[...]

author
#4 lore raw
Quoted 6 lines · Lars-Peter Clausen
Quoted 5 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

Quoted 7 lines
Quoted 1 line

Please make sure to submit drivers against the latest development version of the ASoC tree
(http://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/log/?h=for-next).
This has a couple of outdated things and won't even compile.

When i checked on IRC i was told that linux-next is good. Anyway will rebase it against this one.

Quoted 9 lines

sound/soc/codecs/max98925.c line 123

Quoted 6 lines
sound/soc/codecs/max98925.c new file +5 -0
+
+static const unsigned int max98925_spk_tlv[] = {
+       TLV_DB_RANGE_HEAD(1),
+       1, 31, TLV_DB_SCALE_ITEM(-600, 100, 0),
+};

DECLARE_TLV_DB_SCALE(...)

ok.

Quoted 12 lines

sound/soc/codecs/max98925.c line 296

Quoted 7 lines
sound/soc/codecs/max98925.c new file +6 -0
+static int max98925_add_widgets(struct snd_soc_codec *codec)
+{
+       int ret;
+
+       ret = snd_soc_add_codec_controls(codec, max98925_snd_controls,
+               ARRAY_SIZE(max98925_snd_controls));

Assign this to the controls and num_controls fields of the CODEC driver instead of manually calling add_codec_controls.

will be taken care.

Quoted 16 lines

[...]

Quoted 11 lines
(quoted diff) +2 -0
+static int max98925_set_tdm_slot(struct snd_soc_dai *codec_dai,
+       unsigned int tx_mask, unsigned int rx_mask, int slots, int

slot_width)

(quoted diff) +2 -0
+{
+       pr_info("%s: tx_mask 0x%X, rx_mask 0x%X, slots %d, slot width

%d\n",

sound/soc/codecs/max98925.c new file +4 -0
+                       __func__, tx_mask, rx_mask, slots, slot_width);
+       return 0;
+}
+

[...]

Quoted 1 line
Quoted 10 lines

sound/soc/codecs/max98925.c line 511

Quoted 7 lines
sound/soc/codecs/max98925.c new file +7 -0
+static int max98925_set_bias_level(struct snd_soc_codec *codec,
+                                  enum snd_soc_bias_level level)
+{
+       codec->dapm.bias_level = level;
+       return 0;
+}
+

Drop all those all empty callbacks

ok.

Quoted 20 lines
Quoted 3 lines

+static struct snd_soc_dai_ops max98925_dai_ops = {

const

Quoted 7 lines
sound/soc/codecs/max98925.c new file +7 -0
+       .set_sysclk = max98925_dai_set_sysclk,
+       .set_fmt = max98925_dai_set_fmt,
+       .set_tdm_slot = max98925_set_tdm_slot,
+       .hw_params = max98925_dai_hw_params,
+       .digital_mute = max98925_dai_digital_mute,
+};
+

[...]

Quoted 2 lines

+static struct snd_soc_codec_driver soc_codec_dev_max98925 = {

Quoted 8 lines

const

sound/soc/codecs/max98925.c line 831

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+       .probe            = max98925_probe,
+       .set_bias_level   = max98925_set_bias_level,

You'll need at least some kind of DAPM, otherwise you CODEC won't do anything.

Yes this is most important comment. I wrongly mentioned this as codec but rather it is just mono Class DG audio amplifier so it doesn't need any dapm connections. Mixer commands is good enough for this and i will change this in commit text as well.

Quoted 27 lines
Quoted 3 lines
(quoted diff) +2 -0
+};
+

[...]

Quoted 19 lines
sound/soc/codecs/max98925.c new file +18 -0
+/* There should be a second MAX98925 on the board */
+static struct i2c_board_info max98925_i2c_second[] = {
+       {
+               I2C_BOARD_INFO("max98925R", 0x32),
+       }
+};
+
+struct i2c_client *add_second_device(int busnum)
+{
+       struct i2c_client *i2c = NULL;
+       struct i2c_adapter *adapter;
+
+       adapter = i2c_get_adapter(busnum);
+       if (adapter != NULL)
+               i2c = i2c_new_device(adapter, max98925_i2c_second);
+
+       return i2c;
+}

[...]

Quoted 1 line
Quoted 6 lines

sound/soc/codecs/max98925.c line 892

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+       /* Check for second MAX98925 */
+       i2c_r = add_second_device(2);

If there are two devices instantiate them properly and create two CODEC devices, not some kind of hackery like this.

Ok but this is just audio amplifier do we still need that?

Quoted 3 lines

[...]

#5 lore raw
Quoted 10 lines · anish
Quoted 9 lines · Lars-Peter Clausen
Quoted 6 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

Quoted 7 lines
Quoted 4 lines

Please make sure to submit drivers against the latest development version of the ASoC tree
(http://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/log/?h=for-next).
This has a couple of outdated things and won't even compile.

When i checked on IRC i was told that linux-next is good. Anyway will rebase it against this one.

Yes, that was me who said that. But this driver will neither compile against linux-next nor asoc/for-next.

Which raises another issue, the driver doesn't add any Makefile or Kconfig entries, so even if it would compile you still can compile it.

Quoted 9 lines
Quoted 9 lines
Quoted 1 line

+static struct snd_soc_codec_driver soc_codec_dev_max98925 = {

const

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+       .probe            = max98925_probe,
+       .set_bias_level   = max98925_set_bias_level,
Quoted 7 lines
Quoted 2 lines

You'll need at least some kind of DAPM, otherwise you CODEC won't do anything.

Yes this is most important comment. I wrongly mentioned this as codec but rather it is just mono Class DG audio amplifier so it doesn't need any dapm connections. Mixer commands is good enough for this and i will change this in commit text as well.

Even a amplifier will have a output input and a audio output. Those should be properly modeled in DAPM.

Quoted 27 lines
Quoted 27 lines
Quoted 3 lines
(quoted diff) +2 -0
+};
+

[...]

Quoted 19 lines
sound/soc/codecs/max98925.c new file +18 -0
+/* There should be a second MAX98925 on the board */
+static struct i2c_board_info max98925_i2c_second[] = {
+       {
+               I2C_BOARD_INFO("max98925R", 0x32),
+       }
+};
+
+struct i2c_client *add_second_device(int busnum)
+{
+       struct i2c_client *i2c = NULL;
+       struct i2c_adapter *adapter;
+
+       adapter = i2c_get_adapter(busnum);
+       if (adapter != NULL)
+               i2c = i2c_new_device(adapter, max98925_i2c_second);
+
+       return i2c;
+}

[...]

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

sound/soc/codecs/max98925.c line 892

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+       /* Check for second MAX98925 */
+       i2c_r = add_second_device(2);

If there are two devices instantiate them properly and create two CODEC devices, not some kind of hackery like this.

Ok but this is just audio amplifier do we still need that?

Yes! There is no conceptual difference between a CODEC or an amplifier driver at that level.

- Lars

author
#6 lore raw
Quoted 29 lines · Lars-Peter Clausen
Quoted 19 lines · anish
Quoted 16 lines · Lars-Peter Clausen
Quoted 7 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

Please make sure to submit drivers against the latest development version of
the ASoC tree

Quoted 7 lines
Quoted 2 lines

(http://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/log/?h=for-next).
This has a couple of outdated things and won't even compile.

When i checked on IRC i was told that linux-next is good. Anyway will rebase
it against this one.

Quoted 20 lines

Yes, that was me who said that. But this driver will neither compile against linux-next nor asoc/for-next.

Which raises another issue, the driver doesn't add any Makefile or Kconfig entries, so even if it would compile you still can compile it.

Quoted 13 lines
Quoted 13 lines
Quoted 1 line

+static struct snd_soc_codec_driver soc_codec_dev_max98925 = {

const

sound/soc/codecs/max98925.c line 831

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+       .probe            = max98925_probe,
+       .set_bias_level   = max98925_set_bias_level,

You'll need at least some kind of DAPM, otherwise you CODEC won't do anything.

As already mentioned over IRC this is just a basic power amplifier connected through i2s interface. Currently we do all the mixer settings by using the mixer control
and ALSA callbacks such as prepare, hw_params are doing the other jobs.

I can create dapm path to represent the internals of amplifier but i was wondering
can i tie it to the codec dai?
If yes i can represent codec dai as AIF_IN and DAC as output. So that whenever codec dai is started it will trigger PA as well. Is that ok?

Quoted 59 lines
Quoted 6 lines

Yes this is most important comment. I wrongly mentioned this as codec but rather it is just mono Class DG audio amplifier so it doesn't need any dapm connections. Mixer commands is good enough for this and i will change this in commit text as well.

Even a amplifier will have a output input and a audio output. Those should be properly modeled in DAPM.

Quoted 36 lines
Quoted 36 lines
Quoted 3 lines
(quoted diff) +2 -0
+};
+

[...]

Quoted 20 lines
sound/soc/codecs/max98925.c new file +18 -0
+/* There should be a second MAX98925 on the board */
+static struct i2c_board_info max98925_i2c_second[] = {
+       {
+               I2C_BOARD_INFO("max98925R", 0x32),
+       }
+};
+
+struct i2c_client *add_second_device(int busnum)
+{
+       struct i2c_client *i2c = NULL;
+       struct i2c_adapter *adapter;
+
+       adapter = i2c_get_adapter(busnum);
+       if (adapter != NULL)
+               i2c = i2c_new_device(adapter, max98925_i2c_second);
+
+       return i2c;
+}

[...]

Quoted 4 lines
sound/soc/codecs/max98925.c new file +2 -0
+       /* Check for second MAX98925 */
+       i2c_r = add_second_device(2);
Quoted 5 lines
Quoted 2 lines

If there are two devices instantiate them properly and create two CODEC devices, not some kind of hackery like this.

Ok but this is just audio amplifier do we still need that?

Yes! There is no conceptual difference between a CODEC or an amplifier driver at that level.

- Lars

#7 lore raw

Ccing mark and Liam

Quoted 123 lines
Quoted 32 lines · anish
Quoted 22 lines · Lars-Peter Clausen

On 01/16/2015 10:00 PM, anish wrote:

Quoted 16 lines · Lars-Peter Clausen
Quoted 9 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

Please make sure to submit drivers against the latest development version of
the ASoC tree

Quoted 7 lines
Quoted 2 lines

(http://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/log/?h=for-next).
This has a couple of outdated things and won't even compile.

When i checked on IRC i was told that linux-next is good. Anyway will rebase
it against this one.

Quoted 20 lines

Yes, that was me who said that. But this driver will neither compile against linux-next nor asoc/for-next.

Which raises another issue, the driver doesn't add any Makefile or Kconfig entries, so even if it would compile you still can compile it.

Quoted 13 lines
Quoted 13 lines
Quoted 1 line

+static struct snd_soc_codec_driver soc_codec_dev_max98925 = {

const

sound/soc/codecs/max98925.c line 831

Quoted 2 lines
sound/soc/codecs/max98925.c new file +2 -0
+       .probe            = max98925_probe,
+       .set_bias_level   = max98925_set_bias_level,

You'll need at least some kind of DAPM, otherwise you CODEC won't do anything.

As already mentioned over IRC this is just a basic power amplifier connected through i2s interface. Currently we do all the mixer settings by using the mixer control
and ALSA callbacks such as prepare, hw_params are doing the other jobs.

I can create dapm path to represent the internals of amplifier but i was wondering
can i tie it to the codec dai?
If yes i can represent codec dai as AIF_IN and DAC as output. So that whenever codec dai is started it will trigger PA as well. Is that ok?

Quoted 59 lines
Quoted 6 lines

Yes this is most important comment. I wrongly mentioned this as codec but rather it is just mono Class DG audio amplifier so it doesn't need any dapm connections. Mixer commands is good enough for this and i will change this in commit text as well.

Even a amplifier will have a output input and a audio output. Those should be properly modeled in DAPM.

Quoted 36 lines
Quoted 36 lines
Quoted 3 lines
(quoted diff) +2 -0
+};
+

[...]

Quoted 20 lines
sound/soc/codecs/max98925.c new file +18 -0
+/* There should be a second MAX98925 on the board */
+static struct i2c_board_info max98925_i2c_second[] = {
+       {
+               I2C_BOARD_INFO("max98925R", 0x32),
+       }
+};
+
+struct i2c_client *add_second_device(int busnum)
+{
+       struct i2c_client *i2c = NULL;
+       struct i2c_adapter *adapter;
+
+       adapter = i2c_get_adapter(busnum);
+       if (adapter != NULL)
+               i2c = i2c_new_device(adapter, max98925_i2c_second);
+
+       return i2c;
+}

[...]

Quoted 4 lines
sound/soc/codecs/max98925.c new file +2 -0
+       /* Check for second MAX98925 */
+       i2c_r = add_second_device(2);
Quoted 5 lines
Quoted 2 lines

If there are two devices instantiate them properly and create two CODEC devices, not some kind of hackery like this.

Ok but this is just audio amplifier do we still need that?

Yes! There is no conceptual difference between a CODEC or an amplifier driver at that level.

- Lars

maintainer
#8 lore raw
In reply to Lars-Peter Clausen
Quoted 10 lines · Lars-Peter Clausen
Quoted 5 lines · Anish Kumar

From: Anish Kumar <[email protected]>

This patch adds the max98925 codec driver.

Please make sure to submit drivers against the latest development version of the ASoC tree (http://git.kernel.org/cgit/linux/kernel/git/broonie/sound.git/log/?h=for-next).
This has a couple of outdated things and won't even compile.

Also remember to CC the ASoC maintainers (me and Liam).