summaryrefslogtreecommitdiff
path: root/components/codec-wm8731/wm8731.h
blob: 9cb60e59654eb076d55dae00eeb6741727cc94cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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