[PATCHv3 3/6] ASoC: codec: cpcap: new codec

2017-07-25 Thread Sebastian Reichel
Motorola CPCAP is a PMIC with audio functionality, that can be
found on Motorola Droid 4 and probably a few other phones from
Motorola's Droid series.

The driver has been written from scratch using Motorola's Android
driver, register dumps from running Android and datasheet for NXP
MC13783UG (which is similar to Motorola CPCAP, but not the same).

The chip provides two audio interfaces, that can be muxed to two
different audio codecs. One provides support for stereo output
(named StDAC or HiFi), while the other only provides mono output
(named Voice). Only the Voice codec provides a Capture interface.

Signed-off-by: Sebastian Reichel 
---
 sound/soc/codecs/Kconfig  |5 +
 sound/soc/codecs/Makefile |2 +
 sound/soc/codecs/cpcap.c  | 1594 +
 3 files changed, 1601 insertions(+)
 create mode 100644 sound/soc/codecs/cpcap.c

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 6c78b0b49b81..1615e5acc8fd 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -401,6 +401,11 @@ config SND_SOC_ALC5632
 config SND_SOC_BT_SCO
tristate "Dummy BT SCO codec driver"
 
+config SND_SOC_CPCAP
+   tristate "Motorola CPCAP codec"
+   depends on MFD_CPCAP
+   default MFD_CPCAP
+
 config SND_SOC_CQ0093VC
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 1755a54e3dc9..607f9ce84bc4 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -35,6 +35,7 @@ snd-soc-ak4671-objs := ak4671.o
 snd-soc-ak5386-objs := ak5386.o
 snd-soc-arizona-objs := arizona.o
 snd-soc-bt-sco-objs := bt-sco.o
+snd-soc-cpcap-objs := cpcap.o
 snd-soc-cq93vc-objs := cq93vc.o
 snd-soc-cs35l32-objs := cs35l32.o
 snd-soc-cs35l33-objs := cs35l33.o
@@ -273,6 +274,7 @@ obj-$(CONFIG_SND_SOC_ALC5632)   += snd-soc-alc5632.o
 obj-$(CONFIG_SND_SOC_ARIZONA)  += snd-soc-arizona.o
 obj-$(CONFIG_SND_SOC_BT_SCO)   += snd-soc-bt-sco.o
 obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
+obj-$(CONFIG_SND_SOC_CPCAP)+= snd-soc-cpcap.o
 obj-$(CONFIG_SND_SOC_CS35L32)  += snd-soc-cs35l32.o
 obj-$(CONFIG_SND_SOC_CS35L33)  += snd-soc-cs35l33.o
 obj-$(CONFIG_SND_SOC_CS35L34)  += snd-soc-cs35l34.o
diff --git a/sound/soc/codecs/cpcap.c b/sound/soc/codecs/cpcap.c
new file mode 100644
index ..f52a6b7b1737
--- /dev/null
+++ b/sound/soc/codecs/cpcap.c
@@ -0,0 +1,1594 @@
+/*
+ * ALSA SoC CPCAP codec driver
+ *
+ * Copyright (C) 2017 Sebastian Reichel 
+ *
+ * Very loosely based on original driver from Motorola:
+ * Copyright (C) 2007 - 2009 Motorola, Inc.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Register 513 CPCAP_REG_CC --- CODEC */
+#define CPCAP_BIT_CDC_CLK215
+#define CPCAP_BIT_CDC_CLK114
+#define CPCAP_BIT_CDC_CLK013
+#define CPCAP_BIT_CDC_SR3 12
+#define CPCAP_BIT_CDC_SR2 11
+#define CPCAP_BIT_CDC_SR1 10
+#define CPCAP_BIT_CDC_SR0 9
+#define CPCAP_BIT_CDC_CLOCK_TREE_RESET8
+#define CPCAP_BIT_MIC2_CDC_EN 7
+#define CPCAP_BIT_CDC_EN_RX   6
+#define CPCAP_BIT_DF_RESET5
+#define CPCAP_BIT_MIC1_CDC_EN 4
+#define CPCAP_BIT_AUDOHPF_1  3
+#define CPCAP_BIT_AUDOHPF_0  2
+#define CPCAP_BIT_AUDIHPF_1  1
+#define CPCAP_BIT_AUDIHPF_0  0
+
+/* Register 514 CPCAP_REG_CDI--- CODEC Digital Audio Interface */
+#define CPCAP_BIT_CDC_PLL_SEL 15
+#define CPCAP_BIT_CLK_IN_SEL  13
+#define CPCAP_BIT_DIG_AUD_IN  12
+#define CPCAP_BIT_CDC_CLK_EN  11
+#define CPCAP_BIT_CDC_DIG_AUD_FS1 10
+#define CPCAP_BIT_CDC_DIG_AUD_FS0 9
+#define CPCAP_BIT_MIC2_TIMESLOT2  8
+#define CPCAP_BIT_MIC2_TIMESLOT1  7
+#define CPCAP_BIT_MIC2_TIMESLOT0  6
+#define CPCAP_BIT_MIC1_RX_TIMESLOT2   5
+#define CPCAP_BIT_MIC1_RX_TIMESLOT1   4
+#define CPCAP_BIT_MIC1_RX_TIMESLOT0   3
+#define CPCAP_BIT_FS_INV  2
+#define CPCAP_BIT_CLK_INV 1
+#define CPCAP_BIT_SMB_CDC 0
+
+/* Register 515 CPCAP_REG_SDAC   --- Stereo DAC */
+#define CPCAP_BIT_FSYNC_CLK_IN_COMMON 11
+#define CPCAP_BIT_SLAVE_PLL_CLK_INPUT 10
+#define CPCAP_BIT_ST_CLOCK_TREE_RESET 9
+#define CPCAP_BIT_DF_RESET_ST_DAC 8
+#define CPCAP_BIT_ST_SR3  7

[PATCHv3 3/6] ASoC: codec: cpcap: new codec

2017-07-25 Thread Sebastian Reichel
Motorola CPCAP is a PMIC with audio functionality, that can be
found on Motorola Droid 4 and probably a few other phones from
Motorola's Droid series.

The driver has been written from scratch using Motorola's Android
driver, register dumps from running Android and datasheet for NXP
MC13783UG (which is similar to Motorola CPCAP, but not the same).

The chip provides two audio interfaces, that can be muxed to two
different audio codecs. One provides support for stereo output
(named StDAC or HiFi), while the other only provides mono output
(named Voice). Only the Voice codec provides a Capture interface.

Signed-off-by: Sebastian Reichel 
---
 sound/soc/codecs/Kconfig  |5 +
 sound/soc/codecs/Makefile |2 +
 sound/soc/codecs/cpcap.c  | 1594 +
 3 files changed, 1601 insertions(+)
 create mode 100644 sound/soc/codecs/cpcap.c

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 6c78b0b49b81..1615e5acc8fd 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -401,6 +401,11 @@ config SND_SOC_ALC5632
 config SND_SOC_BT_SCO
tristate "Dummy BT SCO codec driver"
 
+config SND_SOC_CPCAP
+   tristate "Motorola CPCAP codec"
+   depends on MFD_CPCAP
+   default MFD_CPCAP
+
 config SND_SOC_CQ0093VC
tristate
 
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 1755a54e3dc9..607f9ce84bc4 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -35,6 +35,7 @@ snd-soc-ak4671-objs := ak4671.o
 snd-soc-ak5386-objs := ak5386.o
 snd-soc-arizona-objs := arizona.o
 snd-soc-bt-sco-objs := bt-sco.o
+snd-soc-cpcap-objs := cpcap.o
 snd-soc-cq93vc-objs := cq93vc.o
 snd-soc-cs35l32-objs := cs35l32.o
 snd-soc-cs35l33-objs := cs35l33.o
@@ -273,6 +274,7 @@ obj-$(CONFIG_SND_SOC_ALC5632)   += snd-soc-alc5632.o
 obj-$(CONFIG_SND_SOC_ARIZONA)  += snd-soc-arizona.o
 obj-$(CONFIG_SND_SOC_BT_SCO)   += snd-soc-bt-sco.o
 obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
+obj-$(CONFIG_SND_SOC_CPCAP)+= snd-soc-cpcap.o
 obj-$(CONFIG_SND_SOC_CS35L32)  += snd-soc-cs35l32.o
 obj-$(CONFIG_SND_SOC_CS35L33)  += snd-soc-cs35l33.o
 obj-$(CONFIG_SND_SOC_CS35L34)  += snd-soc-cs35l34.o
diff --git a/sound/soc/codecs/cpcap.c b/sound/soc/codecs/cpcap.c
new file mode 100644
index ..f52a6b7b1737
--- /dev/null
+++ b/sound/soc/codecs/cpcap.c
@@ -0,0 +1,1594 @@
+/*
+ * ALSA SoC CPCAP codec driver
+ *
+ * Copyright (C) 2017 Sebastian Reichel 
+ *
+ * Very loosely based on original driver from Motorola:
+ * Copyright (C) 2007 - 2009 Motorola, Inc.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Register 513 CPCAP_REG_CC --- CODEC */
+#define CPCAP_BIT_CDC_CLK215
+#define CPCAP_BIT_CDC_CLK114
+#define CPCAP_BIT_CDC_CLK013
+#define CPCAP_BIT_CDC_SR3 12
+#define CPCAP_BIT_CDC_SR2 11
+#define CPCAP_BIT_CDC_SR1 10
+#define CPCAP_BIT_CDC_SR0 9
+#define CPCAP_BIT_CDC_CLOCK_TREE_RESET8
+#define CPCAP_BIT_MIC2_CDC_EN 7
+#define CPCAP_BIT_CDC_EN_RX   6
+#define CPCAP_BIT_DF_RESET5
+#define CPCAP_BIT_MIC1_CDC_EN 4
+#define CPCAP_BIT_AUDOHPF_1  3
+#define CPCAP_BIT_AUDOHPF_0  2
+#define CPCAP_BIT_AUDIHPF_1  1
+#define CPCAP_BIT_AUDIHPF_0  0
+
+/* Register 514 CPCAP_REG_CDI--- CODEC Digital Audio Interface */
+#define CPCAP_BIT_CDC_PLL_SEL 15
+#define CPCAP_BIT_CLK_IN_SEL  13
+#define CPCAP_BIT_DIG_AUD_IN  12
+#define CPCAP_BIT_CDC_CLK_EN  11
+#define CPCAP_BIT_CDC_DIG_AUD_FS1 10
+#define CPCAP_BIT_CDC_DIG_AUD_FS0 9
+#define CPCAP_BIT_MIC2_TIMESLOT2  8
+#define CPCAP_BIT_MIC2_TIMESLOT1  7
+#define CPCAP_BIT_MIC2_TIMESLOT0  6
+#define CPCAP_BIT_MIC1_RX_TIMESLOT2   5
+#define CPCAP_BIT_MIC1_RX_TIMESLOT1   4
+#define CPCAP_BIT_MIC1_RX_TIMESLOT0   3
+#define CPCAP_BIT_FS_INV  2
+#define CPCAP_BIT_CLK_INV 1
+#define CPCAP_BIT_SMB_CDC 0
+
+/* Register 515 CPCAP_REG_SDAC   --- Stereo DAC */
+#define CPCAP_BIT_FSYNC_CLK_IN_COMMON 11
+#define CPCAP_BIT_SLAVE_PLL_CLK_INPUT 10
+#define CPCAP_BIT_ST_CLOCK_TREE_RESET 9
+#define CPCAP_BIT_DF_RESET_ST_DAC 8
+#define CPCAP_BIT_ST_SR3  7
+#define CPCAP_BIT_ST_SR2  6
+#define