blob: f2389c2fb2509499dfcd9d751d62e9679c85e60b [file] [log] [blame]
Christina Quast53b21052014-12-09 15:34:35 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2009, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30
31/**
32 * \file
33 *
34 * Implementation WM8731 driver.
35 *
36 */
37
38#ifndef WM8731_H
39#define WM8731_H
40
41#include "board.h"
42
43/*----------------------------------------------------------------------------
44 * Definitions
45 *----------------------------------------------------------------------------*/
46#define WM8731_CSB_STATE (0x0 << 0)
47
48/** Slave address */
49//#define WM8731_SLAVE_ADDRESS 0x1a | WM8731_CSB_STATE*/
50#define WM8731_SLAVE_ADDRESS 0x1b
51
52
53/** Reset register*/
54#define WM8731_REG_RESET 0x0F
55
56/** Left Line in register*/
57#define WM8731_REG_LEFT_lINEIN 0x0
58/** Left line input volume control*/
59#define WM8731_LINVOL_BITS (0x1f << 0)
60/** Left line input mute to ADC*/
61#define WM8731_LINMUTE_BIT (0x1 << 7)
62/** Left to right channel line input volume and mute data load control*/
63#define WM8731_LRINBOTH_BIT (0x0 << 8)
64
65/** Right Line in register*/
66#define WM8731_REG_RIGHT_lINEIN 0x1
67/** Right line input volume control*/
68#define WM8731_RINVOL_BITS (0x1f << 0)
69/** Right line input mute to ADC*/
70#define WM8731_RINMUTE_BIT (0x1 << 7)
71/** Right to right channel line input volume and mute data load control*/
72#define WM8731_RLINBOTH_BIT (0x0 << 8)
73
74/** Left Headphone out register*/
75#define WM8731_REG_LEFT_HPOUT 0x2
76/** Left chnnel headphone output volume control*/
77#define WM8731_LHPVOL_BITS (0x7f << 0)
78/** Left channel zero cross detect enable*/
79#define WM8731_LZCEN_BIT (0x1 << 7)
80/** Left to right channel headphone volume, mute and zero cross data load control*/
81#define WM8731_LRHPBOTH_BIT (0x1 << 8)
82
83/** Right Headphone out register*/
84#define WM8731_REG_RIGHT_HPOUT 0x3
85/** Right chnnel headphone output volume control*/
86#define WM8731_RHPVOL_BITS (0x7f << 0)
87/** Right channel zero cross detect enable*/
88#define WM8731_RZCEN_BIT (0x1 << 7)
89/** Right to right channel headphone volume, mute and zero cross data load control*/
90#define WM8731_RLHPBOTH_BIT (0x1 << 8)
91
92/** Analogue audio path control register*/
93#define WM8731_REG_ANALOGUE_PATH_CTRL 0x4
94
95/** Digital audio path control register*/
96#define WM8731_REG_DIGITAL_PATH_CTRL 0x5
97
98/** Power down control register*/
99#define WM8731_REG_PWDOWN_CTRL 0x6
100/** LineIn power down*/
101#define WM8731_LINEINPD_BIT (0x1 << 0)
102#define WM8731_ENABLE_LINEINPD (0x1 << 0)
103#define WM8731_DISABLE_LINEINPD (0x0 << 0)
104/** Mic power down*/
105#define WM8731_MICPD_BIT (0x1 << 1)
106#define WM8731_ENABLE_MICPD (0x1 << 1)
107#define WM8731_DISABLE_MICPD (0x0 << 1)
108/** ADC power down*/
109#define WM8731_ADCPD_BIT (0x1 << 2)
110#define WM8731_ENABLE_ADCPD (0x1 << 2)
111#define WM8731_DISABLE_ADCPD (0x0 << 2)
112/** DAC power down*/
113#define WM8731_DACPD_BIT (0x1 << 3)
114#define WM8731_ENABLE_DACPD (0x1 << 3)
115#define WM8731_DISABLE_DACPD (0x0 << 3)
116/** OUT power down*/
117#define WM8731_OUTPD_BIT (0x1 << 4)
118#define WM8731_ENABLE_OUTPD (0x1 << 4)
119#define WM8731_DISABLE_OUTPD (0x0 << 4)
120/** OSC power down*/
121#define WM8731_OSCBIT (0x1 << 5)
122#define WM8731_ENABLE_OSCPD (0x1 << 5)
123#define WM8731_DISABLE_OSCPD (0x0 << 5)
124/** CLKOUT powerdown*/
125#define WM8731_CLKOUTPD_BIT (0x1 << 6)
126#define WM8731_ENABLE_CLKOUTPD (0x1 << 6)
127#define WM8731_DISABLE_CLKOUTPD (0x0 << 6)
128/** Power off device*/
129#define WM8731_POWEROFF_BIT (0x1 << 7)
130#define WM8731_DEV_POWER_OFF (0x1 << 7)
131#define WM8731_DEV_POWER_ON (0x0 << 7)
132
133/** Interface format register*/
134#define WM8731_REG_DA_INTERFACE_FORMAT 0x7
135/** Format*/
136#define WM8731_FORMAT_BITS (0x3 << 0)
137#define WM8731_FORMAT_MSB_LEFT_JUSTIFIED (0x0 << 0)
138#define WM8731_FORMAT_MSB_RIGHT_JUSTIFIED (0x1 << 0)
139#define WM8731_FORMAT_I2S (0x2 << 0)
140#define WM8731_FORMAT_DSP (0x3 << 0)
141/** Input audio data bit length select*/
142#define WM8731_IWL_BITS (0x3 << 2)
143#define WM8731_IWL_16_BIT (0x0 << 2)
144#define WM8731_IWL_20_BIT (0x1 << 2)
145#define WM8731_IWL_24_BIT (0x2 << 2)
146#define WM8731_IWL_32_BIT (0x3 << 2)
147/** DACLRC phase control*/
148#define WM8731_IRP_BITS (0x1 << 4)
149/** DAC Left right clock swap*/
150#define WM8731_IRSWAP_BIT (0x1 << 5)
151/** Master slave mode control*/
152#define WM8731_MS_BIT (0x1 << 6)
153#define WM8731_ENABLE_MASTER_MODE (0x1 << 6)
154#define WM8731_ENABLE_SLAVE_MODE (0x0 << 6)
155/** Bit clock invert*/
156#define WM8731_BCLKINV_BIT (0x1 << 7)
157
158/** Sampling control*/
159#define WM8731_REG_SAMPLECTRL 0x8
160/** Mode select, usb mode, normal mode*/
161#define WM8731_USBNORMAL_BIT (0x1 << 0)
162#define WM8731_NORMAL_MODE (0x1 << 0)
163#define WM8731_USB_MODE (0x1 << 1)
164/** Base over-sampling rate*/
165#define WM8731_BOSR_BIT (0x1 << 1)
166#define WM8731_USB_250FS (0x0 << 1)
167#define WM8731_USB_272FS (0x1 << 1)
168#define WM8731_NORMAL_256FS (0x0 << 1)
169#define WM8731_NORMAL_128_192_384_FS (0x1 << 1)
170/** Sample rate control*/
171#define WM8731_SR_BITS (0xf << 2)
172#define WM8731_CLKIDIV2_BIT (0x1 << 6)
173#define WM8731_CLKODIV2_BIT (0x1 << 7)
174
175/** Active control register*/
176#define WM8731_REG_ACTIVE_CTRL 0x9
177/** Activate interface*/
178#define WM8731_ACTIVE_BIT (0x1 << 0)
179#define WM8731_ACTIVE_INTERFACE_ACTIVE (0x1 << 1)
180#define WM8731_ACTIVE_INTERFACE_INACTIVE (0x0 << 1)
181
182
183/*----------------------------------------------------------------------------
184 * Exported functions
185 *----------------------------------------------------------------------------*/
186
187extern uint16_t WM8731_Read(Twid *pTwid, uint32_t device, uint32_t regAddr);
188extern void WM8731_Write(Twid *pTwid, uint32_t device, uint32_t regAddr, uint16_t data);
189extern uint8_t WM8731_DAC_Init(Twid *pTwid, uint32_t device);
190extern uint8_t WM8731_VolumeSet(Twid *pTwid, uint32_t device, uint16_t value);
191
192#endif // WM8731_H
193
194