| 1 | /***************************************************************************//** |
| 2 | * @file ssm2518.c |
| 3 | * @brief Driver File for SSM2518 Driver. |
| 4 | * @author ATofan ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2012(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | * |
| 39 | ******************************************************************************** |
| 40 | * SVN Revision: $WCREV$ |
| 41 | *******************************************************************************/ |
| 42 | |
| 43 | #include "xil_io.h" |
| 44 | #include "audio_data.h" |
| 45 | #include "ssm2518.h" |
| 46 | #include "i2c_axi.h" |
| 47 | |
| 48 | volatile int rxData = 0x00; |
| 49 | |
| 50 | /***************************************************************************** |
| 51 | * @brief Write to an internal SSM2518 Register. |
| 52 | * |
| 53 | * @param regAddr - register address. |
| 54 | * @param data - data to be written. |
| 55 | * |
| 56 | * @return None. |
| 57 | ******************************************************************************/ |
| 58 | void SSM2518_WriteReg(char regAddr, unsigned char data) |
| 59 | { |
| 60 | unsigned char txBuffer[1] = {0x00}; |
| 61 | |
| 62 | txBuffer[0] = data; |
| 63 | I2C_Write_axi(I2C_BASEADDR, SSM2518_I2C_ADDR, regAddr, 1, txBuffer); |
| 64 | } |
| 65 | |
| 66 | /***************************************************************************** |
| 67 | * @brief Read from an internal SSM2518 Register. |
| 68 | * |
| 69 | * @param regAddr - register address. |
| 70 | * |
| 71 | * @return rxBuffer[0] - data read from device. |
| 72 | ******************************************************************************/ |
| 73 | unsigned char SSM2518_ReadReg(char regAddr) |
| 74 | { |
| 75 | unsigned char rxBuffer[1] = {0x00}; |
| 76 | |
| 77 | I2C_Read_axi(I2C_BASEADDR, SSM2518_I2C_ADDR, regAddr, 1, rxBuffer); |
| 78 | |
| 79 | return(rxBuffer[0]); |
| 80 | } |
| 81 | |
| 82 | /***************************************************************************** |
| 83 | * @brief Initialize SSM2518 |
| 84 | * |
| 85 | * @param None. |
| 86 | * |
| 87 | * @return None. |
| 88 | ******************************************************************************/ |
| 89 | void SSM2518_Init(void) |
| 90 | { |
| 91 | xil_printf("\n\rInitializing SSM2518 via I2C..."); |
| 92 | SSM2518_WriteReg(SSM2518_Reset_Power_Control, 0x04); |
| 93 | SSM2518_WriteReg(SSM2518_Edge_Clock_Control, 0x00); |
| 94 | SSM2518_WriteReg(SSM2518_Serial_Interface_Sample_Rate_Control, 0x02); |
| 95 | SSM2518_WriteReg(SSM2518_Serial_Interface_Control, 0x00); |
| 96 | SSM2518_WriteReg(SSM2518_Channel_Mapping_Control, 0x01); |
| 97 | SSM2518_WriteReg(SSM2518_Left_Volume_Control, 0x40); |
| 98 | SSM2518_WriteReg(SSM2518_Right_Volume_Control, 0x40); |
| 99 | SSM2518_WriteReg(SSM2518_Volume_Mute_Control, 0x80); |
| 100 | SSM2518_WriteReg(SSM2518_Fault_Control_1, 0x0C); |
| 101 | SSM2518_WriteReg(SSM2518_Power_Fault_Control, 0x80); |
| 102 | xil_printf(" Done!\n\r"); |
| 103 | } |