summaryrefslogtreecommitdiff
path: root/components/codec-wm8731
diff options
context:
space:
mode:
Diffstat (limited to 'components/codec-wm8731')
-rw-r--r--components/codec-wm8731/wm8731.c159
-rw-r--r--components/codec-wm8731/wm8731.dir41
-rw-r--r--components/codec-wm8731/wm8731.h215
3 files changed, 415 insertions, 0 deletions
diff --git a/components/codec-wm8731/wm8731.c b/components/codec-wm8731/wm8731.c
new file mode 100644
index 0000000..5b5a4e6
--- /dev/null
+++ b/components/codec-wm8731/wm8731.c
@@ -0,0 +1,159 @@
+/* ----------------------------------------------------------------------------
+ * ATMEL Microcontroller Software Support
+ * ----------------------------------------------------------------------------
+ * Copyright (c) 2008, Atmel Corporation
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the disclaimer below.
+ *
+ * Atmel's name may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
+ * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ----------------------------------------------------------------------------
+ */
+
+ //------------------------------------------------------------------------------
+/// \unit
+///
+/// !Purpose
+///
+/// WM8731 driver
+///
+/// !Usage
+///
+/// Explanation on the usage of the code made available through the header file.
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Headers
+//------------------------------------------------------------------------------
+#include "wm8731.h"
+#include <board.h>
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Internal functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+/// Read data from WM8731 Register.
+/// \param pTwid pointer to twi driver structure
+/// \param device twi slave address
+/// \param regAddr register address to read.
+//------------------------------------------------------------------------------
+unsigned short WM8731_Read(Twid *pTwid,
+ unsigned int device,
+ unsigned int regAddr)
+{
+ unsigned short bitsDataRegister;
+ unsigned char Tdata[2]={0,0};
+
+ TWID_Read(pTwid, device, regAddr, 0, Tdata, 2, 0);
+ bitsDataRegister = (Tdata[0] << 8) | Tdata[1];
+ return bitsDataRegister;
+}
+
+//------------------------------------------------------------------------------
+/// Write data to WM8731 Register.
+/// \param pTwid pointer to twi driver structure
+/// \param device twi slave address
+/// \param regAddr register address to read.
+/// \param data data to write
+//------------------------------------------------------------------------------
+void WM8731_Write(Twid *pTwid,
+ unsigned int device,
+ unsigned int regAddr,
+ unsigned short data)
+{
+ unsigned char tmpData[2];
+ unsigned short tmp;
+ tmp = ((regAddr & 0x7f) << 9) | (data & 0x1ff);
+
+ tmpData[0] = (tmp & 0xff00) >> 8;
+ tmpData[1] = tmp & 0xff;
+ TWID_Write(pTwid, device, regAddr, 0, tmpData, 2, 0);
+}
+
+//------------------------------------------------------------------------------
+/// Init WM8731 to DAC mode.
+/// \param pTwid pointer to twi driver structure
+/// \param device twi slave address
+//------------------------------------------------------------------------------
+unsigned char WM8731_DAC_Init(Twid *pTwid,
+ unsigned int device)
+{
+ // reset
+ WM8731_Write(pTwid, device, WM8731_REG_RESET, 0);
+
+ // analogue audio path control
+ WM8731_Write(pTwid, device, WM8731_REG_ANALOGUE_PATH_CTRL, 0x12);
+
+ // digital audio path control
+ WM8731_Write(pTwid, device, WM8731_REG_DIGITAL_PATH_CTRL, 0x00);
+
+ // power down control
+ WM8731_Write(pTwid, device, WM8731_REG_PWDOWN_CTRL, 0x7);
+
+ // Active control
+ WM8731_Write(pTwid, device, WM8731_REG_ACTIVE_CTRL, 0x01);
+
+ return 0;
+}
+
+//------------------------------------------------------------------------------
+/// Power down WM8731 DAC.
+/// \param pTwid pointer to twi driver structure
+/// \param device twi slave address
+//------------------------------------------------------------------------------
+void WM8731_DAC_PD(Twid *pTwid,
+ unsigned int device)
+{
+ // power down control
+ WM8731_Write(pTwid, device, WM8731_REG_PWDOWN_CTRL, 0xf);
+}
+
+
+//------------------------------------------------------------------------------
+/// Set WM8731 volume
+/// \param pTwid pointer to twi driver structure
+/// \param device twi slave address
+/// \param register register address
+/// \param value register value, valid value is between 0x30 to 0x7f
+//------------------------------------------------------------------------------
+unsigned char WM8731_VolumeSet(Twid *pTwid,
+ unsigned int device,
+ unsigned short value)
+{
+ unsigned short regValue;
+
+ value &= WM8731_LHPVOL_BITS;
+ regValue = WM8731_LRHPBOTH_BIT | WM8731_LZCEN_BIT | value;
+ WM8731_Write(pTwid, device, WM8731_REG_LEFT_HPOUT, regValue);
+ regValue = WM8731_RZCEN_BIT | WM8731_RLHPBOTH_BIT | value;
+ WM8731_Write(pTwid, device, WM8731_REG_RIGHT_HPOUT, value);
+
+ return 0;
+}
+
diff --git a/components/codec-wm8731/wm8731.dir b/components/codec-wm8731/wm8731.dir
new file mode 100644
index 0000000..58a29b9
--- /dev/null
+++ b/components/codec-wm8731/wm8731.dir
@@ -0,0 +1,41 @@
+/* ----------------------------------------------------------------------------
+ * ATMEL Microcontroller Software Support
+ * ----------------------------------------------------------------------------
+ * Copyright (c) 2008, Atmel Corporation
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the disclaimer below.
+ *
+ * Atmel's name may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
+ * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \dir
+///
+/// !!!Purpose
+///
+/// This directory contains APIs for WM8731 Codec.
+///
+/// !!!Contents
+///
+/// - wm8731.h api definition for WM8731 Codec.
+/// - wm8731.c driver for WM8731 Codec.
+//------------------------------------------------------------------------------
diff --git a/components/codec-wm8731/wm8731.h b/components/codec-wm8731/wm8731.h
new file mode 100644
index 0000000..9cb60e5
--- /dev/null
+++ b/components/codec-wm8731/wm8731.h
@@ -0,0 +1,215 @@
+/* ----------------------------------------------------------------------------
+ * ATMEL Microcontroller Software Support
+ * ----------------------------------------------------------------------------
+ * Copyright (c) 2008, Atmel Corporation
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the disclaimer below.
+ *
+ * Atmel's name may not be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
+ * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ----------------------------------------------------------------------------
+ */
+
+//------------------------------------------------------------------------------
+/// \unit
+///
+/// !!!Purpose
+///
+/// Definition of methods for WM8731 driver.
+///
+/// !!!Usage
+///
+/// -# WM8731_Read
+/// -# WM8731_Write
+/// -# WM8731_DAC_Init
+//------------------------------------------------------------------------------
+
+#ifndef WM8731_H
+#define WM8731_H
+
+#include "board.h"
+#include "twi/twid.h"
+
+//------------------------------------------------------------------------------
+// Definitions
+//------------------------------------------------------------------------------
+
+#define WM8731_CSB_STATE (0x0 << 0)
+
+/// Slave address
+//#define WM8731_SLAVE_ADDRESS 0x1a | WM8731_CSB_STATE
+#define WM8731_SLAVE_ADDRESS 0x1b
+
+
+/// Reset register
+#define WM8731_REG_RESET 0x0F
+
+/// Left Line in register
+#define WM8731_REG_LEFT_lINEIN 0x0
+/// Left line input volume control
+#define WM8731_LINVOL_BITS (0x1f << 0)
+/// Left line input mute to ADC
+#define WM8731_LINMUTE_BIT (0x1 << 7)
+/// Left to right channel line input volume and mute data load control
+#define WM8731_LRINBOTH_BIT (0x0 << 8)
+
+/// Right Line in register
+#define WM8731_REG_RIGHT_lINEIN 0x1
+/// Right line input volume control
+#define WM8731_RINVOL_BITS (0x1f << 0)
+/// Right line input mute to ADC
+#define WM8731_RINMUTE_BIT (0x1 << 7)
+/// Right to right channel line input volume and mute data load control
+#define WM8731_RLINBOTH_BIT (0x0 << 8)
+
+/// Left Headphone out register
+#define WM8731_REG_LEFT_HPOUT 0x2
+/// Left chnnel headphone output volume control
+#define WM8731_LHPVOL_BITS (0x7f << 0)
+/// Left channel zero cross detect enable
+#define WM8731_LZCEN_BIT (0x1 << 7)
+/// Left to right channel headphone volume, mute and zero cross data load control
+#define WM8731_LRHPBOTH_BIT (0x1 << 8)
+
+/// Right Headphone out register
+#define WM8731_REG_RIGHT_HPOUT 0x3
+/// Right chnnel headphone output volume control
+#define WM8731_RHPVOL_BITS (0x7f << 0)
+/// Right channel zero cross detect enable
+#define WM8731_RZCEN_BIT (0x1 << 7)
+/// Right to right channel headphone volume, mute and zero cross data load control
+#define WM8731_RLHPBOTH_BIT (0x1 << 8)
+
+/// Analogue audio path control register
+#define WM8731_REG_ANALOGUE_PATH_CTRL 0x4
+
+/// Digital audio path control register
+#define WM8731_REG_DIGITAL_PATH_CTRL 0x5
+
+/// Power down control register
+#define WM8731_REG_PWDOWN_CTRL 0x6
+/// LineIn power down
+#define WM8731_LINEINPD_BIT (0x1 << 0)
+#define WM8731_ENABLE_LINEINPD (0x1 << 0)
+#define WM8731_DISABLE_LINEINPD (0x0 << 0)
+/// Mic power down
+#define WM8731_MICPD_BIT (0x1 << 1)
+#define WM8731_ENABLE_MICPD (0x1 << 1)
+#define WM8731_DISABLE_MICPD (0x0 << 1)
+/// ADC power down
+#define WM8731_ADCPD_BIT (0x1 << 2)
+#define WM8731_ENABLE_ADCPD (0x1 << 2)
+#define WM8731_DISABLE_ADCPD (0x0 << 2)
+/// DAC power down
+#define WM8731_DACPD_BIT (0x1 << 3)
+#define WM8731_ENABLE_DACPD (0x1 << 3)
+#define WM8731_DISABLE_DACPD (0x0 << 3)
+/// OUT power down
+#define WM8731_OUTPD_BIT (0x1 << 4)
+#define WM8731_ENABLE_OUTPD (0x1 << 4)
+#define WM8731_DISABLE_OUTPD (0x0 << 4)
+/// OSC power down
+#define WM8731_OSCBIT (0x1 << 5)
+#define WM8731_ENABLE_OSCPD (0x1 << 5)
+#define WM8731_DISABLE_OSCPD (0x0 << 5)
+/// CLKOUT powerdown
+#define WM8731_CLKOUTPD_BIT (0x1 << 6)
+#define WM8731_ENABLE_CLKOUTPD (0x1 << 6)
+#define WM8731_DISABLE_CLKOUTPD (0x0 << 6)
+/// Power off device
+#define WM8731_POWEROFF_BIT (0x1 << 7)
+#define WM8731_DEV_POWER_OFF (0x1 << 7)
+#define WM8731_DEV_POWER_ON (0x0 << 7)
+
+/// Interface format register
+#define WM8731_REG_DA_INTERFACE_FORMAT 0x7
+/// Format
+#define WM8731_FORMAT_BITS (0x3 << 0)
+#define WM8731_FORMAT_MSB_LEFT_JUSTIFIED (0x0 << 0)
+#define WM8731_FORMAT_MSB_RIGHT_JUSTIFIED (0x1 << 0)
+#define WM8731_FORMAT_I2S (0x2 << 0)
+#define WM8731_FORMAT_DSP (0x3 << 0)
+/// Input audio data bit length select
+#define WM8731_IWL_BITS (0x3 << 2)
+#define WM8731_IWL_16_BIT (0x0 << 2)
+#define WM8731_IWL_20_BIT (0x1 << 2)
+#define WM8731_IWL_24_BIT (0x2 << 2)
+#define WM8731_IWL_32_BIT (0x3 << 2)
+/// DACLRC phase control
+#define WM8731_IRP_BITS (0x1 << 4)
+/// DAC Left right clock swap
+#define WM8731_IRSWAP_BIT (0x1 << 5)
+/// Master slave mode control
+#define WM8731_MS_BIT (0x1 << 6)
+#define WM8731_ENABLE_MASTER_MODE (0x1 << 6)
+#define WM8731_ENABLE_SLAVE_MODE (0x0 << 6)
+/// Bit clock invert
+#define WM8731_BCLKINV_BIT (0x1 << 7)
+
+/// Sampling control
+#define WM8731_REG_SAMPLECTRL 0x8
+/// Mode select, usb mode, normal mode
+#define WM8731_USBNORMAL_BIT (0x1 << 0)
+#define WM8731_NORMAL_MODE (0x1 << 0)
+#define WM8731_USB_MODE (0x1 << 1)
+/// Base over-sampling rate
+#define WM8731_BOSR_BIT (0x1 << 1)
+#define WM8731_USB_250FS (0x0 << 1)
+#define WM8731_USB_272FS (0x1 << 1)
+#define WM8731_NORMAL_256FS (0x0 << 1)
+#define WM8731_NORMAL_128_192_384_FS (0x1 << 1)
+/// Sample rate control
+#define WM8731_SR_BITS (0xf << 2)
+///
+#define WM8731_CLKIDIV2_BIT (0x1 << 6)
+///
+#define WM8731_CLKODIV2_BIT (0x1 << 7)
+
+/// Active control register
+#define WM8731_REG_ACTIVE_CTRL 0x9
+/// Activate interface
+#define WM8731_ACTIVE_BIT (0x1 << 0)
+#define WM8731_ACTIVE_INTERFACE_ACTIVE (0x1 << 1)
+#define WM8731_ACTIVE_INTERFACE_INACTIVE (0x0 << 1)
+
+
+//------------------------------------------------------------------------------
+// Exported functions
+//------------------------------------------------------------------------------
+
+extern unsigned short WM8731_Read(Twid *pTwid,
+ unsigned int device,
+ unsigned int register);
+
+extern void WM8731_Write(Twid *pTwid,
+ unsigned int device,
+ unsigned int register,
+ unsigned short data);
+
+extern unsigned char WM8731_DAC_Init(Twid *pTwid,
+ unsigned int device);
+extern void WM8731_DAC_PD(Twid *pTwid,
+ unsigned int device);
+extern unsigned char WM8731_VolumeSet(Twid *pTwid,
+ unsigned int device,
+ unsigned short value);
+
+#endif // WM8731_H
+
personal git repositories of Harald Welte. Your mileage may vary