Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for CTAG face2|4 Audio Card #104

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arch/arm/boot/dts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ dtb-$(CONFIG_SOC_AM33XX) += \
am335x-boneblack-cape-bone-argus.dtb \
am335x-bone-cape-bone-argus.dtb \
am335x-arduino-tre.dtb \
am335x-bonegreen-ctag-face.dtb \
am335x-bonegreen-wireless-led-hack.dtb \
am335x-bonegreen-wireless.dtb \
am335x-olimex-som.dtb \
Expand Down Expand Up @@ -527,6 +528,7 @@ dtb-$(CONFIG_SOC_DRA7XX) += \
am571x-idk.dtb \
am571x-idk-lcd-osd.dtb \
am571x-idk-lcd-osd101t2587.dtb \
am57xx-beagle-x15-ctag.dtb \
am572x-idk.dtb \
am572x-idk-lcd-osd.dtb \
am572x-idk-lcd-osd101t2587.dtb \
Expand Down
125 changes: 125 additions & 0 deletions arch/arm/boot/dts/am335x-bonegreen-ctag-face.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Base device tree for BeagleBone Green with CTAG face2|4 Audio Card
*
* Author: Henrik Langer <[email protected]>
* based on
BeagleBone Black and BeagleBone Green device tree
*
* 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.
*/
/dts-v1/;

#include "am33xx.dtsi"
#include "am335x-bone-common.dtsi"
//#include "am33xx-overlay-edma-fix.dtsi" // leads to problems with SPI

/ {
model = "TI AM335x BeagleBone Green AudioCard";
compatible = "ti,am335x-bone-green", "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";

/*
Optional SW SPI interface
(see BB-CTAG-SW-8CH-00A0.dts for more details)
*/
spi_gpio: spi_gpio {
compatible = "spi-gpio";
#address-cells = <1>;
#size-cells = <0>;

gpio-sck = <&gpio2 11 0>;
gpio-mosi = <&gpio2 9 0>;
gpio-miso = <&gpio2 8 0>;
cs-gpios = <&gpio2 10 0 &gpio2 13 0>;
num-chipselects = <2>;

status = "disabled";
};
};

&ldo3_reg {
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
regulator-always-on;
};

&mmc1 {
vmmc-supply = <&vmmcsd_fixed>;
};

&mmc2 {
vmmc-supply = <&vmmcsd_fixed>;
pinctrl-names = "default";
pinctrl-0 = <&emmc_pins>;
bus-width = <8>;
status = "okay";
};

&cpu0_opp_table {
/*
* All PG 2.0 silicon may not support 1GHz but some of the early
* BeagleBone Blacks have PG 2.0 silicon which is guaranteed
* to support 1GHz OPP so enable it for PG 2.0 on this board.
*/
oppnitro@1000000000 {
opp-supported-hw = <0x06 0x0100>;
};
};

&am33xx_pinmux {
mcasp0_pins: mcasp0_pins {
pinctrl-single,pins = <
0x1ac (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_ahclkx */
0x19c (PIN_OUTPUT_PULLDOWN | MUX_MODE2) /* mcasp0_axr2 */
0x194 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_fsx */
0x190 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_aclkx */
0x1a4 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_fsr */
0x078 (PIN_INPUT_PULLDOWN | MUX_MODE6) /* mcasp0_aclkr */
0x198 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr0 */
0x06c (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* gpio1[27] (enable oscillator) */
>;
};

mcasp0_pins_sleep: mcasp0_pins_sleep {
pinctrl-single,pins = <
0x1ac (PIN_INPUT_PULLDOWN | MUX_MODE7) /* mcasp0_ahclkx */
0x19c (PIN_INPUT_PULLDOWN | MUX_MODE7) /* mcasp0_axr2 */
0x194 (PIN_INPUT_PULLDOWN | MUX_MODE7) /* mcasp0_fsx */
0x190 (PIN_INPUT_PULLDOWN | MUX_MODE7) /* mcasp0_aclkx */
0x1a4 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_fsr */
0x078 (PIN_INPUT_PULLDOWN | MUX_MODE6) /* mcasp0_aclkr */
0x198 (PIN_INPUT_PULLDOWN | MUX_MODE7) /* mcasp0_axr0 */
0x06c (PIN_INPUT_PULLDOWN | MUX_MODE7) /* gpio1[27] */
>;
};
};

&mcasp0 {
pinctrl-names = "default", "sleep";
pinctrl-0 = <&mcasp0_pins>;
pinctrl-1 = <&mcasp0_pins_sleep>;
status = "okay";
op-mode = <0>; /* MCASP_IIS_MODE */
tdm-slots = <2>;
serial-dir = < /* 0: INACTIVE, 1: TX, 2: RX */
2 0 1 0
>;
tx-num-evt = <1>;
rx-num-evt = <1>;
};

/ {
clk_mcasp0_fixed: clk_mcasp0_fixed {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <24576000>;
};

clk_mcasp0: clk_mcasp0 {
#clock-cells = <0>;
compatible = "gpio-gate-clock";
clocks = <&clk_mcasp0_fixed>;
enable-gpios = <&gpio1 27 0>; /* BeagleBone Black Clk enable on GPIO1_27 */
};
};
85 changes: 85 additions & 0 deletions arch/arm/boot/dts/am57xx-beagle-x15-ctag.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Device tree for BeagleBoard-X15 with CTAG face2|4 Audio Card
*
* Author: Henrik Langer <[email protected]>
*
* 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 "am57xx-beagle-x15.dts"

/ {
sound2: sound@2 {
compatible = "ctag,face-2-4";
model = "CTAG face-2-4 8CH";
audio-codec = <&ad193x>;
mcasp-controller = <&mcasp2>;
audiocard-tdm-slots = <8>;
codec-clock-rate = <24576000>;
bb-device = <1>; //0 = BBB/BBG, 1 = BB-X15
cpu-clock-rate = <22579200>;
audio-routing =
"Line Out", "DAC1OUT",
"Line Out", "DAC2OUT",
"Line Out", "DAC3OUT",
"Line Out", "DAC4OUT",
"ADC1IN", "Line In",
"ADC2IN", "Line In";
};
};

&dra7_pmx_core {
mcasp2_pins_default: mcasp2_pins_default {
pinctrl-single,pins = <
0x2F8 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp2_fsx | P17.52 */
0x2F4 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp2_aclkx | P17.21 */
0x300 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp2_fsr | P17.57 */
0x2FC (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp2_aclkr | P17.44 */
0x30C (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mcasp2_axr2 | P17.18 */
0x304 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp2_axr0 | P17.54 */
>;
};

mcspi3_pins_default: mcspi3_pins_default {
pinctrl-single,pins = <
0x2E0 (PIN_OUTPUT_PULLUP | MUX_MODE3) /* spi3_cs0 | P16.3 */
0x2D4 (PIN_INPUT_PULLUP | MUX_MODE3) /* spi3_sclk | P16.34 */
0x2DC (PIN_INPUT_PULLUP | MUX_MODE3) /* spi3_d0 | P16.33 */
0x2D8 (PIN_OUTPUT_PULLDOWN | MUX_MODE3) /* spi3_d1 | P16.4 */
>;
};
};

&mcspi3 {
pinctrl-names = "default";
pinctrl-0 = <&mcspi3_pins_default>;
status = "okay";

ad193x: ad193x@0{
compatible = "analog,ad1938";
reg = <0>;
status = "okay";
spi-max-frequency = <100000>;
};
};

&mcasp2 {
#sound-dai-cells = <0>;
//assigned-clocks = <&mcasp2_ahclkx_mux>, <&mcasp2_ahclkr_mux>;
assigned-clocks = <&mcasp2_ahclkx_mux>;
assigned-clock-parents = <&sys_clkin2>; /* 22579200 Hz (see dra7xx-clocks.dtsi) */
pinctrl-names = "default";
pinctrl-0 = <&mcasp2_pins_default>;
status = "okay";

op-mode = <0>; /* MCASP_IIS_MODE */
tdm-slots = <8>;
/* 4 serializers */
serial-dir = < /* 0: INACTIVE, 1: TX, 2: RX */
2 0 1 0
>;
tx-num-evt = <8>;
rx-num-evt = <8>;
};
1 change: 1 addition & 0 deletions arch/arm/configs/bb.org_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ CONFIG_SND_SOC=m
CONFIG_SND_EDMA_SOC=m
CONFIG_SND_AM33XX_SOC_EVM=m
CONFIG_SND_AM33XX_SOC_WILINK8_BT=m
CONFIG_SND_DAVINCI_SOC_CTAG_FACE_2_4=m
CONFIG_SND_SOC_FSL_SSI=m
CONFIG_SND_SOC_FSL_SPDIF=m
CONFIG_SND_SOC_IMX_AUDMUX=m
Expand Down
8 changes: 6 additions & 2 deletions sound/soc/codecs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,16 @@ config SND_SOC_AD193X
tristate

config SND_SOC_AD193X_SPI
tristate
tristate "Analog Devices AD193x CODEC (SPI)"
depends on SPI_MASTER
select SND_SOC_AD193X
select REGMAP_SPI

config SND_SOC_AD193X_I2C
tristate
tristate "Analog Devices AD193x CODEC (I2C)"
depends on I2C
select SND_SOC_AD193X
select REGMAP_I2C

config SND_SOC_AD1980
select REGMAP_AC97
Expand Down
40 changes: 36 additions & 4 deletions sound/soc/codecs/ad193x.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Licensed under the GPL-2 or later.
*/

#define DEBUG 1

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
Expand Down Expand Up @@ -274,7 +276,7 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
int word_len = 0, master_rate = 0;
int word_len = 0, master_rate = 0, sample_rate = 0, i, ret;
struct snd_soc_codec *codec = dai->codec;
struct ad193x_priv *ad193x = snd_soc_codec_get_drvdata(codec);

Expand All @@ -292,6 +294,22 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
break;
}

/* sample rate */
switch(params_rate(params)){
case 48000:
sample_rate = 0;
break;
case 96000:
sample_rate = 1;
break;
case 192000:
sample_rate = 2;
break;
default:
sample_rate = 0; //48 kHz
break;
}

switch (ad193x->sysclk) {
case 12288000:
master_rate = AD193X_PLL_INPUT_256;
Expand All @@ -307,6 +325,12 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
break;
}

regmap_update_bits(ad193x->regmap, AD193X_DAC_CTRL0,
0x06, sample_rate << 1);

regmap_update_bits(ad193x->regmap, AD193X_ADC_CTRL0,
0xC0, sample_rate << 6);

regmap_update_bits(ad193x->regmap, AD193X_PLL_CLK_CTRL0,
AD193X_PLL_INPUT_MASK, master_rate);

Expand All @@ -318,6 +342,11 @@ static int ad193x_hw_params(struct snd_pcm_substream *substream,
regmap_update_bits(ad193x->regmap, AD193X_ADC_CTRL1,
AD193X_ADC_WORD_LEN_MASK, word_len);

for(i=0; i<=16; i++){
regmap_read(ad193x->regmap , i, &ret) ;
dev_dbg(codec->dev, "AD193X register %d:\t0x%x", i, ret);
}

return 0;
}

Expand Down Expand Up @@ -372,11 +401,14 @@ static int ad193x_codec_probe(struct snd_soc_codec *codec)
regmap_write(ad193x->regmap, AD193X_ADC_CTRL0, 0x3);
/* sata delay=1, adc aux mode */
regmap_write(ad193x->regmap, AD193X_ADC_CTRL1, 0x43);
/* 256 bclks per frame */
regmap_write(ad193x->regmap, AD193X_ADC_CTRL2, 0x20);
}

/* pll input: mclki/xi */
regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */
regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL1, 0x04);
/* pll input: mclki/xi, xtal oscillator enabled */
regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL0, 0x80); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */
/* adc / dac clock source: mclk */
regmap_write(ad193x->regmap, AD193X_PLL_CLK_CTRL1, 0x00);

/* adc only */
if (ad193x_has_adc(ad193x)) {
Expand Down
6 changes: 6 additions & 0 deletions sound/soc/davinci/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ config SND_DA850_SOC_EVM
Say Y if you want to add support for SoC audio on TI
DA850/OMAP-L138 EVM

config SND_DAVINCI_SOC_CTAG_FACE_2_4
tristate "SoC Audio Support for CTAG face-2-4 Audio Card (AD1938)"
depends on SND_DAVINCI_SOC_MCASP
select SND_SOC_AD193X_SPI
help
Say Y if you want to add support for CTAG face-2-4 Audio Card
2 changes: 2 additions & 0 deletions sound/soc/davinci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ snd-soc-edma-objs := edma-pcm.o
snd-soc-davinci-i2s-objs := davinci-i2s.o
snd-soc-davinci-mcasp-objs:= davinci-mcasp.o
snd-soc-davinci-vcif-objs:= davinci-vcif.o
snd-soc-davinci-ctag-face-2-4-objs := davinci-ctag-face-2-4.o

obj-$(CONFIG_SND_EDMA_SOC) += snd-soc-edma.o
obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o
obj-$(CONFIG_SND_DAVINCI_SOC_VCIF) += snd-soc-davinci-vcif.o
obj-$(CONFIG_SND_DAVINCI_SOC_CTAG_FACE_2_4) += snd-soc-davinci-ctag-face-2-4.o

# Generic DAVINCI/AM33xx Machine Support
snd-soc-evm-objs := davinci-evm.o
Expand Down
Loading