Skip to contentSkip to conversation

ASoC: MAX9877: add MAX9877 amp driver

PATCH In review Joonyoung Shim 2 participants 4 messages Jul 14, 2009 – Jul 15, 2009

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

PATCH 1/1 ASoC: MAX9877: add MAX9877 amp driver

The MAX9877 combines a high-efficiency Class D audio power amplifier with a stereo Class AB capacitor-less DirectDrive headphone amplifier.

The max9877_add_controls() is called to register the MAX9877 specific controls on machine specific init() of the machine driver.

The datasheet for the MAX9877 can find at the following url:
http://datasheets.maxim-ic.com/en/ds/MAX9877.pdf

---
Hi,

I added amp driver in codec directory of ASoC. This is because of mail about amp driver the past.
http://www.spinics.net/lists/alsa-devel/msg24876.html

Please review, thank you.

 sound/soc/codecs/Kconfig   |    4 +
 sound/soc/codecs/Makefile  |    6 +
 sound/soc/codecs/max9877.c |  246 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/max9877.h |   37 +++++++
 4 files changed, 293 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/max9877.c
 create mode 100644 sound/soc/codecs/max9877.h
sound/soc/codecs/Kconfig +4 -0
index b674d3a..8930557 100644
@@ -188,3 +188,7 @@ config SND_SOC_WM9712
 
 config SND_SOC_WM9713
 	tristate
+
+# Amp
+config SND_SOC_MAX9877
+	tristate
sound/soc/codecs/Makefile +6 -0
index 301eb08..cf111c9 100644
@@ -38,6 +38,9 @@ snd-soc-wm9705-objs := wm9705.o
 snd-soc-wm9712-objs := wm9712.o
 snd-soc-wm9713-objs := wm9713.o
 
+# Amp
+snd-soc-max9877-objs := max9877.o
+
 obj-$(CONFIG_SND_SOC_AC97_CODEC)	+= snd-soc-ac97.o
 obj-$(CONFIG_SND_SOC_AD1980)	+= snd-soc-ad1980.o
 obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
@@ -77,3 +80,6 @@ obj-$(CONFIG_SND_SOC_WM9081)	+= snd-soc-wm9081.o
 obj-$(CONFIG_SND_SOC_WM9705)	+= snd-soc-wm9705.o
 obj-$(CONFIG_SND_SOC_WM9712)	+= snd-soc-wm9712.o
 obj-$(CONFIG_SND_SOC_WM9713)	+= snd-soc-wm9713.o
+
+# Amp
+obj-$(CONFIG_SND_SOC_MAX9877)	+= snd-soc-max9877.o
sound/soc/codecs/max9877.c new file +246 -0

246 lines not on this page · raw message

sound/soc/codecs/max9877.h new file +37 -0
new file mode 100644
index 0000000..6da7229
@@ -0,0 +1,37 @@
+/*
+ * max9877.h  --  amp driver for max9877
+ *
+ * Copyright (C) 2009 Samsung Electronics Co.Ltd
+ * Author: Joonyoung Shim <[email protected]>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef _MAX9877_H
+#define _MAX9877_H
+
+#define MAX9877_INPUT_MODE		0x00
+#define MAX9877_SPK_VOLUME		0x01
+#define MAX9877_HPL_VOLUME		0x02
+#define MAX9877_HPR_VOLUME		0x03
+#define MAX9877_OUTPUT_MODE		0x04
+
+/* MAX9877_INPUT_MODE */
+#define MAX9877_INB			(1 << 4)
+#define MAX9877_INA			(1 << 5)
+#define MAX9877_ZCD			(1 << 6)
+
+/* MAX9877_OUTPUT_MODE */
+#define MAX9877_OUTMODE_MASK		(15 << 0)
+#define MAX9877_OSC_MASK		(3 << 4)
+#define MAX9877_OSC_OFFSET		4
+#define MAX9877_BYPASS			(1 << 6)
+#define MAX9877_SHDN			(1 << 7)
+
+extern int max9877_add_controls(struct snd_soc_codec *codec);
+
+#endif
Signature · 1 line
1.6.0.4
#1 lore raw

On Tue, Jul 14, 2009 at 03:39:37PM +0900, Joonyoung Shim wrote:

Overall this looks great, thanks. Clearly it's not an ideal approach but it gets the job done and it can be adapted to use core features as they're added.

A couple of relatively nitpicky issues below:

sound/soc/codecs/Kconfig config SND_SOC_WM9712 · line 194

Quoted 9 lines

+++ b/sound/soc/codecs/Kconfig

sound/soc/codecs/Kconfig +4 -0
@@ -188,3 +188,7 @@ config SND_SOC_WM9712
 
 config SND_SOC_WM9713
 	tristate
+
+# Amp
+config SND_SOC_MAX9877
+	tristate

I'd add it to SND_SOC_ALL_CODECS too - while it's not strictly a CODEC the point of the Kconfig option is to get build coverage and this driver will benefit from that as much as others.

sound/soc/codecs/max9877.c line 148

Quoted 5 lines
sound/soc/codecs/max9877.c new file +5 -0
+static const char *max9877_osc_mode[] = {
+	"1176KHz",
+	"1100KHz",
+	"700KHz",
+};

Would this be better as platform data for the device?

sound/soc/codecs/max9877.c line 170

Quoted 7 lines
sound/soc/codecs/max9877.c new file +7 -0
+static const struct snd_kcontrol_new max9877_controls[] = {
+	SOC_SINGLE_EXT_TLV("MAX9877 Amp HP Left Playback Volume",
+			MAX9877_HPL_VOLUME, 0, 31, 0,
+			max9877_get_reg, max9877_set_reg, max9877_output_tlv),
+	SOC_SINGLE_EXT_TLV("MAX9877 Amp HP Right Playback Volume",
+			MAX9877_HPR_VOLUME, 0, 31, 0,
+			max9877_get_reg, max9877_set_reg, max9877_output_tlv),

Ideally these would be a SOC_DOUBLE_EXT_TLV() but we don't have that yet
- would you mind sending a patch for that?

sound/soc/codecs/max9877.c line 198

Quoted 7 lines
sound/soc/codecs/max9877.c new file +7 -0
+/* This function is called from ASoC machine driver */
+int max9877_add_controls(struct snd_soc_codec *codec)
+{
+	return snd_soc_add_controls(codec, max9877_controls,
+			ARRAY_SIZE(max9877_controls));
+}
+

This should have an EXPORT_SYMBOL_GPL() to allow it to be used from machine drivers which are built modular.

#2 lore raw
Quoted 6 lines · Mark Brown

On Tue, Jul 14, 2009 at 03:39:37PM +0900, Joonyoung Shim wrote:

Overall this looks great, thanks. Clearly it's not an ideal approach but it gets the job done and it can be adapted to use core features as they're added.

Thank you for your review.

Quoted 5 lines

A couple of relatively nitpicky issues below:

Quoted 3 lines

+++ b/sound/soc/codecs/Kconfig

(quoted diff) +0 -0
@@ -188,3 +188,7 @@ config SND_SOC_WM9712
 
Quoted 11 lines

sound/soc/codecs/Kconfig config SND_SOC_WM9712 · line 194

Quoted 6 lines
sound/soc/codecs/Kconfig +4 -0
 config SND_SOC_WM9713
 	tristate
+
+# Amp
+config SND_SOC_MAX9877
+	tristate

I'd add it to SND_SOC_ALL_CODECS too - while it's not strictly a CODEC the point of the Kconfig option is to get build coverage and this driver will benefit from that as much as others.

OK, i will add it.

Quoted 8 lines

sound/soc/codecs/max9877.c line 148

Quoted 5 lines
sound/soc/codecs/max9877.c new file +5 -0
+static const char *max9877_osc_mode[] = {
+	"1176KHz",
+	"1100KHz",
+	"700KHz",
+};

Would this be better as platform data for the device?

I'm not sure about this, but if this would be platform data, does it means the osc_mode should not be changed through a control?

Quoted 11 lines

sound/soc/codecs/max9877.c line 170

Quoted 7 lines
sound/soc/codecs/max9877.c new file +7 -0
+static const struct snd_kcontrol_new max9877_controls[] = {
+	SOC_SINGLE_EXT_TLV("MAX9877 Amp HP Left Playback Volume",
+			MAX9877_HPL_VOLUME, 0, 31, 0,
+			max9877_get_reg, max9877_set_reg, max9877_output_tlv),
+	SOC_SINGLE_EXT_TLV("MAX9877 Amp HP Right Playback Volume",
+			MAX9877_HPR_VOLUME, 0, 31, 0,
+			max9877_get_reg, max9877_set_reg, max9877_output_tlv),

Ideally these would be a SOC_DOUBLE_EXT_TLV() but we don't have that yet
- would you mind sending a patch for that?

I think these would be a SOC_DOUBLE_R_EXT_TLV() because HP Left register and HP Right register are different. If this is right, i will send a patch for this.

Quoted 11 lines

sound/soc/codecs/max9877.c line 198

Quoted 7 lines
sound/soc/codecs/max9877.c new file +7 -0
+/* This function is called from ASoC machine driver */
+int max9877_add_controls(struct snd_soc_codec *codec)
+{
+	return snd_soc_add_controls(codec, max9877_controls,
+			ARRAY_SIZE(max9877_controls));
+}
+

This should have an EXPORT_SYMBOL_GPL() to allow it to be used from machine drivers which are built modular.

OK, i will add it.

#3 lore raw
Quoted 12 lines · Joonyoung Shim
Quoted 9 lines · Mark Brown

sound/soc/codecs/max9877.c line 170

Quoted 6 lines
sound/soc/codecs/max9877.c new file +6 -0
+	SOC_SINGLE_EXT_TLV("MAX9877 Amp HP Left Playback Volume",
+			MAX9877_HPL_VOLUME, 0, 31, 0,
+			max9877_get_reg, max9877_set_reg, max9877_output_tlv),
+	SOC_SINGLE_EXT_TLV("MAX9877 Amp HP Right Playback Volume",
+			MAX9877_HPR_VOLUME, 0, 31, 0,
+			max9877_get_reg, max9877_set_reg, max9877_output_tlv),

Ideally these would be a SOC_DOUBLE_EXT_TLV() but we don't have that yet
- would you mind sending a patch for that?

Quoted 3 lines

I think these would be a SOC_DOUBLE_R_EXT_TLV() because HP Left register and HP Right register are different. If this is right, i will send a patch for this.

Yes, that sounds right (though if you want to add both macros I won't stop you!).