├── README.md ├── rt5514 ├── resource.h ├── rt5514.rc ├── spb.h ├── trace.h ├── rt5514.inf ├── rt5514.h ├── rt5514.vcxproj ├── registers.h ├── spb.c └── rt5514.c ├── rt5514.sln ├── LICENSE.txt ├── .gitignore └── rt5514 Package └── rt5514 Package.vcxproj /README.md: -------------------------------------------------------------------------------- 1 | # rt5514 2 | RT5514 Microphone Array 3 | 4 | Tested on Pixelbook. Used with CoolStar SST Audio -------------------------------------------------------------------------------- /rt5514/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by rt5514.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /rt5514/rt5514.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation All Rights Reserved 4 | 5 | Module Name: 6 | 7 | rt5514.rc 8 | 9 | Abstract: 10 | 11 | --*/ 12 | 13 | #include 14 | 15 | #define VER_FILETYPE VFT_DRV 16 | #define VER_FILESUBTYPE VFT2_DRV_SOUND 17 | #define VER_FILEDESCRIPTION_STR "Realtek ALC5514 I2S Microphone" 18 | #define VER_INTERNALNAME_STR "rt5514.sys" 19 | #define VER_ORIGINALFILENAME_STR "rt5514.sys" 20 | 21 | #define VER_LEGALCOPYRIGHT_YEARS "2023" 22 | #define VER_LEGALCOPYRIGHT_STR "Copyright (C) " VER_LEGALCOPYRIGHT_YEARS " CoolStar." 23 | 24 | #define VER_FILEVERSION 1,0,0,0 25 | #define VER_PRODUCTVERSION_STR "1.0.0.0" 26 | #define VER_PRODUCTVERSION 1,0,0,0 27 | #define LVER_PRODUCTVERSION_STR L"1.0.0.0" 28 | 29 | #define VER_FILEFLAGSMASK (VS_FF_DEBUG | VS_FF_PRERELEASE) 30 | #ifdef DEBUG 31 | #define VER_FILEFLAGS (VS_FF_DEBUG) 32 | #else 33 | #define VER_FILEFLAGS (0) 34 | #endif 35 | 36 | #define VER_FILEOS VOS_NT_WINDOWS32 37 | 38 | #define VER_COMPANYNAME_STR "CoolStar" 39 | #define VER_PRODUCTNAME_STR "Realtek ALC5514 I2S Microphone" 40 | 41 | #include "common.ver" -------------------------------------------------------------------------------- /rt5514/spb.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | Copyright (c) Microsoft Corporation. All Rights Reserved. 3 | Sample code. Dealpoint ID #843729. 4 | 5 | Module Name: 6 | 7 | spb.h 8 | 9 | Abstract: 10 | 11 | This module contains the touch driver I2C helper definitions. 12 | 13 | Environment: 14 | 15 | Kernel Mode 16 | 17 | Revision History: 18 | 19 | --*/ 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | 26 | #define DEFAULT_SPB_BUFFER_SIZE 64 27 | #define RESHUB_USE_HELPER_ROUTINES 28 | 29 | // 30 | // SPB (I2C) context 31 | // 32 | 33 | typedef struct _SPB_CONTEXT 34 | { 35 | WDFIOTARGET SpbIoTarget; 36 | LARGE_INTEGER I2cResHubId; 37 | WDFMEMORY WriteMemory; 38 | WDFMEMORY ReadMemory; 39 | WDFWAITLOCK SpbLock; 40 | } SPB_CONTEXT; 41 | 42 | NTSTATUS 43 | SpbXferDataSynchronously( 44 | _In_ SPB_CONTEXT* SpbContext, 45 | _In_ PVOID SendData, 46 | _In_ ULONG SendLength, 47 | _In_reads_bytes_(Length) PVOID Data, 48 | _In_ ULONG Length 49 | ); 50 | 51 | VOID 52 | SpbTargetDeinitialize( 53 | IN WDFDEVICE FxDevice, 54 | IN SPB_CONTEXT* SpbContext 55 | ); 56 | 57 | NTSTATUS 58 | SpbTargetInitialize( 59 | IN WDFDEVICE FxDevice, 60 | IN SPB_CONTEXT* SpbContext 61 | ); 62 | 63 | NTSTATUS 64 | SpbWriteDataSynchronously( 65 | IN SPB_CONTEXT* SpbContext, 66 | IN PVOID Data, 67 | IN ULONG Length 68 | ); -------------------------------------------------------------------------------- /rt5514/trace.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef _TRACE_H_ 4 | #define _TRACE_H_ 5 | 6 | extern "C" 7 | { 8 | // 9 | // Tracing Definitions: 10 | // 11 | // Control GUID: 12 | // {73e3b785-f5fb-423e-94a9-56627fea9053} 13 | // 14 | 15 | #define WPP_CONTROL_GUIDS \ 16 | WPP_DEFINE_CONTROL_GUID( \ 17 | SpbTestToolTraceGuid, \ 18 | (73e3b785,f5fb,423e,94a9,56627fea9053), \ 19 | WPP_DEFINE_BIT(TRACE_FLAG_WDFLOADING) \ 20 | WPP_DEFINE_BIT(TRACE_FLAG_SPBAPI) \ 21 | WPP_DEFINE_BIT(TRACE_FLAG_OTHER) \ 22 | ) 23 | } 24 | 25 | #define WPP_LEVEL_FLAGS_LOGGER(level,flags) WPP_LEVEL_LOGGER(flags) 26 | #define WPP_LEVEL_FLAGS_ENABLED(level, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= level) 27 | 28 | #define Trace CyapaPrint 29 | #define FuncEntry 30 | #define FuncExit 31 | #define WPP_INIT_TRACING 32 | #define WPP_CLEANUP 33 | #define TRACE_FLAG_SPBAPI 0 34 | #define TRACE_FLAG_WDFLOADING 0 35 | 36 | // begin_wpp config 37 | // FUNC FuncEntry{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS); 38 | // FUNC FuncExit{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS); 39 | // USEPREFIX(FuncEntry, "%!STDPREFIX! [%!FUNC!] --> entry"); 40 | // USEPREFIX(FuncExit, "%!STDPREFIX! [%!FUNC!] <--"); 41 | // end_wpp 42 | 43 | #endif _TRACE_H_ 44 | -------------------------------------------------------------------------------- /rt5514/rt5514.inf: -------------------------------------------------------------------------------- 1 | ;/*++ 2 | ; 3 | ;Copyright (c) CoolStar. All rights reserved. 4 | ; 5 | ;Module Name: 6 | ; rt5514.inf 7 | ; 8 | ;Abstract: 9 | ; INF file for installing the Realtek ALC5514 I2S Amplifier Driver 10 | ; 11 | ; 12 | ;--*/ 13 | 14 | [Version] 15 | Signature = "$WINDOWS NT$" 16 | Class = Media 17 | ClassGuid = {4d36e96c-e325-11ce-bfc1-08002be10318} 18 | Provider = CoolStar 19 | DriverVer = 12/21/2022,1.0.0 20 | CatalogFile = rt5514.cat 21 | PnpLockdown=1 22 | 23 | [DestinationDirs] 24 | DefaultDestDir = 12 25 | 26 | ; ================= Class section ===================== 27 | 28 | [SourceDisksNames] 29 | 1 = %DiskId1%,,,"" 30 | 31 | [SourceDisksFiles] 32 | rt5514.sys = 1,, 33 | 34 | ;***************************************** 35 | ; rt5514 Install Section 36 | ;***************************************** 37 | 38 | [Manufacturer] 39 | %StdMfg%=Standard,NTAMD64 40 | 41 | ; Decorated model section take precedence over undecorated 42 | ; ones on XP and later. 43 | [Standard.NTAMD64] 44 | %rt5514.DeviceDesc%=Rt5514_Device, ACPI\10EC5514 45 | 46 | [Rt5514_Device.NT] 47 | CopyFiles=Drivers_Dir 48 | 49 | [Drivers_Dir] 50 | rt5514.sys 51 | 52 | ;-------------- Service installation 53 | [Rt5514_Device.NT.Services] 54 | AddService = rt5514,%SPSVCINST_ASSOCSERVICE%, Rt5514_Service_Inst 55 | 56 | ; -------------- rt5514 driver install sections 57 | [Rt5514_Service_Inst] 58 | DisplayName = %rt5514.SVCDESC% 59 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 60 | StartType = 3 ; SERVICE_DEMAND_START 61 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 62 | ServiceBinary = %12%\rt5514.sys 63 | LoadOrderGroup = Base 64 | 65 | [Strings] 66 | SPSVCINST_ASSOCSERVICE= 0x00000002 67 | StdMfg = "CoolStar" 68 | DiskId1 = "Realtek 5514 Installation Disk #1" 69 | rt5514.DeviceDesc = "Realtek ALC5514 I2S Microphone" 70 | rt5514.SVCDESC = "Realtek 5514 Service" 71 | -------------------------------------------------------------------------------- /rt5514.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32922.545 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rt5514", "rt5514\rt5514.vcxproj", "{36580C07-EDC3-4C2B-B45F-6AB017E01A5D}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rt5514 Package", "rt5514 Package\rt5514 Package.vcxproj", "{3DAE7ED3-003A-4495-8352-3D7B5B5D846F}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D} = {36580C07-EDC3-4C2B-B45F-6AB017E01A5D} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Win32 = Debug|Win32 16 | Debug|x64 = Debug|x64 17 | Release|Win32 = Release|Win32 18 | Release|x64 = Release|x64 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Debug|Win32.Build.0 = Debug|Win32 23 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Debug|Win32.Deploy.0 = Debug|Win32 24 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Debug|x64.ActiveCfg = Debug|x64 25 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Debug|x64.Build.0 = Debug|x64 26 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Debug|x64.Deploy.0 = Debug|x64 27 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Release|Win32.ActiveCfg = Release|Win32 28 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Release|Win32.Build.0 = Release|Win32 29 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Release|Win32.Deploy.0 = Release|Win32 30 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Release|x64.ActiveCfg = Release|x64 31 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Release|x64.Build.0 = Release|x64 32 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D}.Release|x64.Deploy.0 = Release|x64 33 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Debug|Win32.ActiveCfg = Debug|Win32 34 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Debug|Win32.Build.0 = Debug|Win32 35 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Debug|Win32.Deploy.0 = Debug|Win32 36 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Debug|x64.ActiveCfg = Debug|x64 37 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Debug|x64.Build.0 = Debug|x64 38 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Debug|x64.Deploy.0 = Debug|x64 39 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Release|Win32.ActiveCfg = Release|Win32 40 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Release|Win32.Build.0 = Release|Win32 41 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Release|Win32.Deploy.0 = Release|Win32 42 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Release|x64.ActiveCfg = Release|x64 43 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Release|x64.Build.0 = Release|x64 44 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F}.Release|x64.Deploy.0 = Release|x64 45 | EndGlobalSection 46 | GlobalSection(SolutionProperties) = preSolution 47 | HideSolutionNode = FALSE 48 | EndGlobalSection 49 | GlobalSection(ExtensibilityGlobals) = postSolution 50 | SolutionGuid = {9A2670CD-596B-41B9-958C-215F7069D30B} 51 | EndGlobalSection 52 | EndGlobal 53 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2022 CoolStar 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | 16 | ====================== Windows Driver Samples License ====================== 17 | 18 | The Microsoft Public License (MS-PL) 19 | Copyright (c) 2015 Microsoft 20 | 21 | This license governs use of the accompanying software. If you use the software, you 22 | accept this license. If you do not accept the license, do not use the software. 23 | 24 | 1. Definitions 25 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the 26 | same meaning here as under U.S. copyright law. 27 | A "contribution" is the original software, or any additions or changes to the software. 28 | A "contributor" is any person that distributes its contribution under this license. 29 | "Licensed patents" are a contributor's patent claims that read directly on its contribution. 30 | 31 | 2. Grant of Rights 32 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 33 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 34 | 35 | 3. Conditions and Limitations 36 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 37 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. 38 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. 39 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. 40 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. -------------------------------------------------------------------------------- /rt5514/rt5514.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RT5514_H_) 2 | #define _RT5514_H_ 3 | 4 | #pragma warning(disable:4200) // suppress nameless struct/union warning 5 | #pragma warning(disable:4201) // suppress nameless struct/union warning 6 | #pragma warning(disable:4214) // suppress bit field types other than int warning 7 | #include 8 | #include 9 | 10 | #pragma warning(default:4200) 11 | #pragma warning(default:4201) 12 | #pragma warning(default:4214) 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include "spb.h" 21 | 22 | // 23 | // String definitions 24 | // 25 | 26 | #define DRIVERNAME "rt5514.sys: " 27 | 28 | #define RT5514_POOL_TAG (ULONG) '4155' 29 | 30 | #define true 1 31 | #define false 0 32 | 33 | typedef enum { 34 | CSAudioEndpointTypeDSP, 35 | CSAudioEndpointTypeSpeaker, 36 | CSAudioEndpointTypeHeadphone, 37 | CSAudioEndpointTypeMicArray, 38 | CSAudioEndpointTypeMicJack 39 | } CSAudioEndpointType; 40 | 41 | typedef enum { 42 | CSAudioEndpointRegister, 43 | CSAudioEndpointStart, 44 | CSAudioEndpointStop, 45 | CSAudioEndpointOverrideFormat 46 | } CSAudioEndpointRequest; 47 | 48 | typedef struct CSAUDIOFORMATOVERRIDE { 49 | UINT16 channels; 50 | UINT16 frequency; 51 | UINT16 bitsPerSample; 52 | UINT16 validBitsPerSample; 53 | BOOLEAN force32BitOutputContainer; 54 | } CsAudioFormatOverride; 55 | 56 | typedef struct CSAUDIOARG { 57 | UINT32 argSz; 58 | CSAudioEndpointType endpointType; 59 | CSAudioEndpointRequest endpointRequest; 60 | union { 61 | CsAudioFormatOverride formatOverride; 62 | }; 63 | } CsAudioArg, * PCsAudioArg; 64 | 65 | typedef struct _RT5514_CONTEXT 66 | { 67 | 68 | WDFDEVICE FxDevice; 69 | 70 | WDFQUEUE ReportQueue; 71 | 72 | SPB_CONTEXT I2CContext; 73 | 74 | BOOLEAN DevicePoweredOn; 75 | 76 | PCALLBACK_OBJECT CSAudioAPICallback; 77 | PVOID CSAudioAPICallbackObj; 78 | 79 | BOOLEAN CSAudioManaged; 80 | 81 | } RT5514_CONTEXT, *PRT5514_CONTEXT; 82 | 83 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(RT5514_CONTEXT, GetDeviceContext) 84 | 85 | // 86 | // Function definitions 87 | // 88 | 89 | DRIVER_INITIALIZE DriverEntry; 90 | 91 | EVT_WDF_DRIVER_UNLOAD Rt5514DriverUnload; 92 | 93 | EVT_WDF_DRIVER_DEVICE_ADD Rt5514EvtDeviceAdd; 94 | 95 | EVT_WDFDEVICE_WDM_IRP_PREPROCESS Rt5514EvtWdmPreprocessMnQueryId; 96 | 97 | EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL Rt5514EvtInternalDeviceControl; 98 | 99 | // 100 | // Helper macros 101 | // 102 | 103 | #define DEBUG_LEVEL_ERROR 1 104 | #define DEBUG_LEVEL_INFO 2 105 | #define DEBUG_LEVEL_VERBOSE 3 106 | 107 | #define DBG_INIT 1 108 | #define DBG_PNP 2 109 | #define DBG_IOCTL 4 110 | 111 | #if 0 112 | #define Rt5514Print(dbglevel, dbgcatagory, fmt, ...) { \ 113 | if (Rt5514DebugLevel >= dbglevel && \ 114 | (Rt5514DebugCatagories && dbgcatagory)) \ 115 | { \ 116 | DbgPrint(DRIVERNAME); \ 117 | DbgPrint(fmt, __VA_ARGS__); \ 118 | } \ 119 | } 120 | #else 121 | #define Rt5514Print(dbglevel, fmt, ...) { \ 122 | } 123 | #endif 124 | 125 | #endif -------------------------------------------------------------------------------- /rt5514/rt5514.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {36580C07-EDC3-4C2B-B45F-6AB017E01A5D} 23 | {1bc93793-694f-48fe-9372-81e2b05556fd} 24 | v4.5 25 | 11.0 26 | Win8.1 Debug 27 | Win32 28 | rt5514 29 | 30 | 31 | 32 | Windows10 33 | true 34 | WindowsKernelModeDriver10.0 35 | Driver 36 | KMDF 37 | 38 | 39 | Windows10 40 | false 41 | WindowsKernelModeDriver10.0 42 | Driver 43 | KMDF 44 | 45 | 46 | Windows10 47 | true 48 | WindowsKernelModeDriver10.0 49 | Driver 50 | KMDF 51 | 52 | 53 | Windows10 54 | false 55 | WindowsKernelModeDriver10.0 56 | Driver 57 | KMDF 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | DbgengKernelDebugger 69 | 70 | 71 | DbgengKernelDebugger 72 | 73 | 74 | DbgengKernelDebugger 75 | 76 | 77 | DbgengKernelDebugger 78 | 79 | 80 | 81 | true 82 | trace.h 83 | true 84 | false 85 | 86 | 87 | 1.0.0 88 | 89 | 90 | 91 | 92 | true 93 | trace.h 94 | true 95 | false 96 | 97 | 98 | 1.0.0 99 | 100 | 101 | 102 | 103 | true 104 | trace.h 105 | true 106 | false 107 | 108 | 109 | 1.0.0 110 | 111 | 112 | 113 | 114 | true 115 | trace.h 116 | true 117 | false 118 | 119 | 120 | 1.0.0 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015/2017 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # Visual Studio 2017 auto generated files 34 | Generated\ Files/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # Benchmark Results 50 | BenchmarkDotNet.Artifacts/ 51 | 52 | # .NET Core 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_h.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *_wpftmp.csproj 81 | *.log 82 | *.vspscc 83 | *.vssscc 84 | .builds 85 | *.pidb 86 | *.svclog 87 | *.scc 88 | 89 | # Chutzpah Test files 90 | _Chutzpah* 91 | 92 | # Visual C++ cache files 93 | ipch/ 94 | *.aps 95 | *.ncb 96 | *.opendb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | *.VC.db 101 | *.VC.VC.opendb 102 | 103 | # Visual Studio profiler 104 | *.psess 105 | *.vsp 106 | *.vspx 107 | *.sap 108 | 109 | # Visual Studio Trace Files 110 | *.e2e 111 | 112 | # TFS 2012 Local Workspace 113 | $tf/ 114 | 115 | # Guidance Automation Toolkit 116 | *.gpState 117 | 118 | # ReSharper is a .NET coding add-in 119 | _ReSharper*/ 120 | *.[Rr]e[Ss]harper 121 | *.DotSettings.user 122 | 123 | # JustCode is a .NET coding add-in 124 | .JustCode 125 | 126 | # TeamCity is a build add-in 127 | _TeamCity* 128 | 129 | # DotCover is a Code Coverage Tool 130 | *.dotCover 131 | 132 | # AxoCover is a Code Coverage Tool 133 | .axoCover/* 134 | !.axoCover/settings.json 135 | 136 | # Visual Studio code coverage results 137 | *.coverage 138 | *.coveragexml 139 | 140 | # NCrunch 141 | _NCrunch_* 142 | .*crunch*.local.xml 143 | nCrunchTemp_* 144 | 145 | # MightyMoose 146 | *.mm.* 147 | AutoTest.Net/ 148 | 149 | # Web workbench (sass) 150 | .sass-cache/ 151 | 152 | # Installshield output folder 153 | [Ee]xpress/ 154 | 155 | # DocProject is a documentation generator add-in 156 | DocProject/buildhelp/ 157 | DocProject/Help/*.HxT 158 | DocProject/Help/*.HxC 159 | DocProject/Help/*.hhc 160 | DocProject/Help/*.hhk 161 | DocProject/Help/*.hhp 162 | DocProject/Help/Html2 163 | DocProject/Help/html 164 | 165 | # Click-Once directory 166 | publish/ 167 | 168 | # Publish Web Output 169 | *.[Pp]ublish.xml 170 | *.azurePubxml 171 | # Note: Comment the next line if you want to checkin your web deploy settings, 172 | # but database connection strings (with potential passwords) will be unencrypted 173 | *.pubxml 174 | *.publishproj 175 | 176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 177 | # checkin your Azure Web App publish settings, but sensitive information contained 178 | # in these scripts will be unencrypted 179 | PublishScripts/ 180 | 181 | # NuGet Packages 182 | *.nupkg 183 | # The packages folder can be ignored because of Package Restore 184 | **/[Pp]ackages/* 185 | # except build/, which is used as an MSBuild target. 186 | !**/[Pp]ackages/build/ 187 | # Uncomment if necessary however generally it will be regenerated when needed 188 | #!**/[Pp]ackages/repositories.config 189 | # NuGet v3's project.json files produces more ignorable files 190 | *.nuget.props 191 | *.nuget.targets 192 | 193 | # Microsoft Azure Build Output 194 | csx/ 195 | *.build.csdef 196 | 197 | # Microsoft Azure Emulator 198 | ecf/ 199 | rcf/ 200 | 201 | # Windows Store app package directories and files 202 | AppPackages/ 203 | BundleArtifacts/ 204 | Package.StoreAssociation.xml 205 | _pkginfo.txt 206 | *.appx 207 | 208 | # Visual Studio cache files 209 | # files ending in .cache can be ignored 210 | *.[Cc]ache 211 | # but keep track of directories ending in .cache 212 | !*.[Cc]ache/ 213 | 214 | # Others 215 | ClientBin/ 216 | ~$* 217 | *~ 218 | *.dbmdl 219 | *.dbproj.schemaview 220 | *.jfm 221 | *.pfx 222 | *.publishsettings 223 | orleans.codegen.cs 224 | 225 | # Including strong name files can present a security risk 226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 227 | #*.snk 228 | 229 | # Since there are multiple workflows, uncomment next line to ignore bower_components 230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 231 | #bower_components/ 232 | 233 | # RIA/Silverlight projects 234 | Generated_Code/ 235 | 236 | # Backup & report files from converting an old project file 237 | # to a newer Visual Studio version. Backup files are not needed, 238 | # because we have git ;-) 239 | _UpgradeReport_Files/ 240 | Backup*/ 241 | UpgradeLog*.XML 242 | UpgradeLog*.htm 243 | ServiceFabricBackup/ 244 | *.rptproj.bak 245 | 246 | # SQL Server files 247 | *.mdf 248 | *.ldf 249 | *.ndf 250 | 251 | # Business Intelligence projects 252 | *.rdl.data 253 | *.bim.layout 254 | *.bim_*.settings 255 | *.rptproj.rsuser 256 | 257 | # Microsoft Fakes 258 | FakesAssemblies/ 259 | 260 | # GhostDoc plugin setting file 261 | *.GhostDoc.xml 262 | 263 | # Node.js Tools for Visual Studio 264 | .ntvs_analysis.dat 265 | node_modules/ 266 | 267 | # Visual Studio 6 build log 268 | *.plg 269 | 270 | # Visual Studio 6 workspace options file 271 | *.opt 272 | 273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 274 | *.vbw 275 | 276 | # Visual Studio LightSwitch build output 277 | **/*.HTMLClient/GeneratedArtifacts 278 | **/*.DesktopClient/GeneratedArtifacts 279 | **/*.DesktopClient/ModelManifest.xml 280 | **/*.Server/GeneratedArtifacts 281 | **/*.Server/ModelManifest.xml 282 | _Pvt_Extensions 283 | 284 | # Paket dependency manager 285 | .paket/paket.exe 286 | paket-files/ 287 | 288 | # FAKE - F# Make 289 | .fake/ 290 | 291 | # JetBrains Rider 292 | .idea/ 293 | *.sln.iml 294 | 295 | # CodeRush personal settings 296 | .cr/personal 297 | 298 | # Python Tools for Visual Studio (PTVS) 299 | __pycache__/ 300 | *.pyc 301 | 302 | # Cake - Uncomment if you are using it 303 | # tools/** 304 | # !tools/packages.config 305 | 306 | # Tabs Studio 307 | *.tss 308 | 309 | # Telerik's JustMock configuration file 310 | *.jmconfig 311 | 312 | # BizTalk build output 313 | *.btp.cs 314 | *.btm.cs 315 | *.odx.cs 316 | *.xsd.cs 317 | 318 | # OpenCover UI analysis results 319 | OpenCover/ 320 | 321 | # Azure Stream Analytics local run output 322 | ASALocalRun/ 323 | 324 | # MSBuild Binary and Structured Log 325 | *.binlog 326 | 327 | # NVidia Nsight GPU debugger configuration file 328 | *.nvuser 329 | 330 | # MFractors (Xamarin productivity tool) working folder 331 | .mfractor/ 332 | 333 | # Local History for Visual Studio 334 | .localhistory/ 335 | -------------------------------------------------------------------------------- /rt5514 Package/rt5514 Package.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {3DAE7ED3-003A-4495-8352-3D7B5B5D846F} 23 | {4605da2c-74a5-4865-98e1-152ef136825f} 24 | v4.5 25 | 11.0 26 | Win8.1 Debug 27 | Win32 28 | rt5514_Package 29 | $(LatestTargetPlatformVersion) 30 | 31 | 32 | 33 | Windows10 34 | true 35 | WindowsKernelModeDriver10.0 36 | Utility 37 | Package 38 | true 39 | 40 | 41 | Windows10 42 | false 43 | WindowsKernelModeDriver10.0 44 | Utility 45 | Package 46 | true 47 | 48 | 49 | Windows10 50 | true 51 | WindowsKernelModeDriver10.0 52 | Utility 53 | Package 54 | true 55 | 56 | 57 | Windows10 58 | false 59 | WindowsKernelModeDriver10.0 60 | Utility 61 | Package 62 | true 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | DbgengKernelDebugger 74 | False 75 | True 76 | 77 | 78 | 79 | False 80 | False 81 | True 82 | 83 | 133563 84 | 85 | 86 | DbgengKernelDebugger 87 | False 88 | True 89 | 90 | 91 | 92 | False 93 | False 94 | True 95 | 96 | 133563 97 | 98 | 99 | DbgengKernelDebugger 100 | False 101 | True 102 | 103 | 104 | 105 | False 106 | False 107 | True 108 | 109 | 133563 110 | 111 | 112 | DbgengKernelDebugger 113 | False 114 | True 115 | 116 | 117 | 118 | False 119 | False 120 | True 121 | 122 | 133563 123 | 124 | 125 | 126 | SHA256 127 | 128 | 129 | 130 | 131 | SHA256 132 | 133 | 134 | 135 | 136 | SHA256 137 | 138 | 139 | 140 | 141 | SHA256 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | {36580c07-edc3-4c2b-b45f-6ab017e01a5d} 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /rt5514/registers.h: -------------------------------------------------------------------------------- 1 | #ifndef __RT5514_H__ 2 | #define __RT5514_H__ 3 | 4 | #define RT5514_DEVICE_ID 0x10ec5514 5 | 6 | #define RT5514_RESET 0x2000 7 | #define RT5514_PWR_ANA1 0x2004 8 | #define RT5514_PWR_ANA2 0x2008 9 | #define RT5514_I2S_CTRL1 0x2010 10 | #define RT5514_I2S_CTRL2 0x2014 11 | #define RT5514_VAD_CTRL6 0x2030 12 | #define RT5514_EXT_VAD_CTRL 0x206c 13 | #define RT5514_DIG_IO_CTRL 0x2070 14 | #define RT5514_PAD_CTRL1 0x2080 15 | #define RT5514_DMIC_DATA_CTRL 0x20a0 16 | #define RT5514_DIG_SOURCE_CTRL 0x20a4 17 | #define RT5514_SRC_CTRL 0x20ac 18 | #define RT5514_DOWNFILTER2_CTRL1 0x20d0 19 | #define RT5514_PLL_SOURCE_CTRL 0x2100 20 | #define RT5514_CLK_CTRL1 0x2104 21 | #define RT5514_CLK_CTRL2 0x2108 22 | #define RT5514_PLL3_CALIB_CTRL1 0x2110 23 | #define RT5514_PLL3_CALIB_CTRL4 0x2120 24 | #define RT5514_PLL3_CALIB_CTRL5 0x2124 25 | #define RT5514_PLL3_CALIB_CTRL6 0x2128 26 | #define RT5514_DELAY_BUF_CTRL1 0x2140 27 | #define RT5514_DELAY_BUF_CTRL3 0x2148 28 | #define RT5514_ASRC_IN_CTRL1 0x2180 29 | #define RT5514_DOWNFILTER0_CTRL1 0x2190 30 | #define RT5514_DOWNFILTER0_CTRL2 0x2194 31 | #define RT5514_DOWNFILTER0_CTRL3 0x2198 32 | #define RT5514_DOWNFILTER1_CTRL1 0x21a0 33 | #define RT5514_DOWNFILTER1_CTRL2 0x21a4 34 | #define RT5514_DOWNFILTER1_CTRL3 0x21a8 35 | #define RT5514_ANA_CTRL_LDO10 0x2200 36 | #define RT5514_ANA_CTRL_LDO18_16 0x2204 37 | #define RT5514_ANA_CTRL_ADC12 0x2210 38 | #define RT5514_ANA_CTRL_ADC21 0x2214 39 | #define RT5514_ANA_CTRL_ADC22 0x2218 40 | #define RT5514_ANA_CTRL_ADC23 0x221c 41 | #define RT5514_ANA_CTRL_MICBST 0x2220 42 | #define RT5514_ANA_CTRL_ADCFED 0x2224 43 | #define RT5514_ANA_CTRL_INBUF 0x2228 44 | #define RT5514_ANA_CTRL_VREF 0x222c 45 | #define RT5514_ANA_CTRL_PLL3 0x2240 46 | #define RT5514_ANA_CTRL_PLL1_1 0x2260 47 | #define RT5514_ANA_CTRL_PLL1_2 0x2264 48 | #define RT5514_DMIC_LP_CTRL 0x2e00 49 | #define RT5514_MISC_CTRL_DSP 0x2e04 50 | #define RT5514_DSP_CTRL1 0x2f00 51 | #define RT5514_DSP_CTRL3 0x2f08 52 | #define RT5514_DSP_CTRL4 0x2f10 53 | #define RT5514_VENDOR_ID1 0x2ff0 54 | #define RT5514_VENDOR_ID2 0x2ff4 55 | 56 | #define RT5514_DSP_MAPPING 0x18000000 57 | 58 | /* RT5514_PWR_ANA1 (0x2004) */ 59 | #define RT5514_POW_LDO18_IN (0x1 << 5) 60 | #define RT5514_POW_LDO18_IN_BIT 5 61 | #define RT5514_POW_LDO18_ADC (0x1 << 4) 62 | #define RT5514_POW_LDO18_ADC_BIT 4 63 | #define RT5514_POW_LDO21 (0x1 << 3) 64 | #define RT5514_POW_LDO21_BIT 3 65 | #define RT5514_POW_BG_LDO18_IN (0x1 << 2) 66 | #define RT5514_POW_BG_LDO18_IN_BIT 2 67 | #define RT5514_POW_BG_LDO21 (0x1 << 1) 68 | #define RT5514_POW_BG_LDO21_BIT 1 69 | 70 | /* RT5514_PWR_ANA2 (0x2008) */ 71 | #define RT5514_POW_PLL1 (0x1 << 18) 72 | #define RT5514_POW_PLL1_BIT 18 73 | #define RT5514_POW_PLL1_LDO (0x1 << 16) 74 | #define RT5514_POW_PLL1_LDO_BIT 16 75 | #define RT5514_POW_BG_MBIAS (0x1 << 15) 76 | #define RT5514_POW_BG_MBIAS_BIT 15 77 | #define RT5514_POW_MBIAS (0x1 << 14) 78 | #define RT5514_POW_MBIAS_BIT 14 79 | #define RT5514_POW_VREF2 (0x1 << 13) 80 | #define RT5514_POW_VREF2_BIT 13 81 | #define RT5514_POW_VREF1 (0x1 << 12) 82 | #define RT5514_POW_VREF1_BIT 12 83 | #define RT5514_POWR_LDO16 (0x1 << 11) 84 | #define RT5514_POWR_LDO16_BIT 11 85 | #define RT5514_POWL_LDO16 (0x1 << 10) 86 | #define RT5514_POWL_LDO16_BIT 10 87 | #define RT5514_POW_ADC2 (0x1 << 9) 88 | #define RT5514_POW_ADC2_BIT 9 89 | #define RT5514_POW_INPUT_BUF (0x1 << 8) 90 | #define RT5514_POW_INPUT_BUF_BIT 8 91 | #define RT5514_POW_ADC1_R (0x1 << 7) 92 | #define RT5514_POW_ADC1_R_BIT 7 93 | #define RT5514_POW_ADC1_L (0x1 << 6) 94 | #define RT5514_POW_ADC1_L_BIT 6 95 | #define RT5514_POW2_BSTR (0x1 << 5) 96 | #define RT5514_POW2_BSTR_BIT 5 97 | #define RT5514_POW2_BSTL (0x1 << 4) 98 | #define RT5514_POW2_BSTL_BIT 4 99 | #define RT5514_POW_BSTR (0x1 << 3) 100 | #define RT5514_POW_BSTR_BIT 3 101 | #define RT5514_POW_BSTL (0x1 << 2) 102 | #define RT5514_POW_BSTL_BIT 2 103 | #define RT5514_POW_ADCFEDR (0x1 << 1) 104 | #define RT5514_POW_ADCFEDR_BIT 1 105 | #define RT5514_POW_ADCFEDL (0x1 << 0) 106 | #define RT5514_POW_ADCFEDL_BIT 0 107 | 108 | /* RT5514_I2S_CTRL1 (0x2010) */ 109 | #define RT5514_TDM_MODE2 (0x1 << 30) 110 | #define RT5514_TDM_MODE2_SFT 30 111 | #define RT5514_TDM_MODE (0x1 << 28) 112 | #define RT5514_TDM_MODE_SFT 28 113 | #define RT5514_I2S_LR_MASK (0x1 << 26) 114 | #define RT5514_I2S_LR_SFT 26 115 | #define RT5514_I2S_LR_NOR (0x0 << 26) 116 | #define RT5514_I2S_LR_INV (0x1 << 26) 117 | #define RT5514_I2S_BP_MASK (0x1 << 25) 118 | #define RT5514_I2S_BP_SFT 25 119 | #define RT5514_I2S_BP_NOR (0x0 << 25) 120 | #define RT5514_I2S_BP_INV (0x1 << 25) 121 | #define RT5514_I2S_DF_MASK (0x7 << 16) 122 | #define RT5514_I2S_DF_SFT 16 123 | #define RT5514_I2S_DF_I2S (0x0 << 16) 124 | #define RT5514_I2S_DF_LEFT (0x1 << 16) 125 | #define RT5514_I2S_DF_PCM_A (0x2 << 16) 126 | #define RT5514_I2S_DF_PCM_B (0x3 << 16) 127 | #define RT5514_TDMSLOT_SEL_RX_MASK (0x3 << 10) 128 | #define RT5514_TDMSLOT_SEL_RX_SFT 10 129 | #define RT5514_TDMSLOT_SEL_RX_4CH (0x1 << 10) 130 | #define RT5514_TDMSLOT_SEL_RX_6CH (0x2 << 10) 131 | #define RT5514_TDMSLOT_SEL_RX_8CH (0x3 << 10) 132 | #define RT5514_CH_LEN_RX_MASK (0x3 << 8) 133 | #define RT5514_CH_LEN_RX_SFT 8 134 | #define RT5514_CH_LEN_RX_16 (0x0 << 8) 135 | #define RT5514_CH_LEN_RX_20 (0x1 << 8) 136 | #define RT5514_CH_LEN_RX_24 (0x2 << 8) 137 | #define RT5514_CH_LEN_RX_32 (0x3 << 8) 138 | #define RT5514_TDMSLOT_SEL_TX_MASK (0x3 << 6) 139 | #define RT5514_TDMSLOT_SEL_TX_SFT 6 140 | #define RT5514_TDMSLOT_SEL_TX_4CH (0x1 << 6) 141 | #define RT5514_TDMSLOT_SEL_TX_6CH (0x2 << 6) 142 | #define RT5514_TDMSLOT_SEL_TX_8CH (0x3 << 6) 143 | #define RT5514_CH_LEN_TX_MASK (0x3 << 4) 144 | #define RT5514_CH_LEN_TX_SFT 4 145 | #define RT5514_CH_LEN_TX_16 (0x0 << 4) 146 | #define RT5514_CH_LEN_TX_20 (0x1 << 4) 147 | #define RT5514_CH_LEN_TX_24 (0x2 << 4) 148 | #define RT5514_CH_LEN_TX_32 (0x3 << 4) 149 | #define RT5514_I2S_DL_MASK (0x3 << 0) 150 | #define RT5514_I2S_DL_SFT 0 151 | #define RT5514_I2S_DL_16 (0x0 << 0) 152 | #define RT5514_I2S_DL_20 (0x1 << 0) 153 | #define RT5514_I2S_DL_24 (0x2 << 0) 154 | #define RT5514_I2S_DL_8 (0x3 << 0) 155 | 156 | /* RT5514_I2S_CTRL2 (0x2014) */ 157 | #define RT5514_TDM_DOCKING_MODE (0x1 << 31) 158 | #define RT5514_TDM_DOCKING_MODE_SFT 31 159 | #define RT5514_TDM_DOCKING_VALID_CH_MASK (0x1 << 29) 160 | #define RT5514_TDM_DOCKING_VALID_CH_SFT 29 161 | #define RT5514_TDM_DOCKING_VALID_CH2 (0x0 << 29) 162 | #define RT5514_TDM_DOCKING_VALID_CH4 (0x1 << 29) 163 | #define RT5514_TDM_DOCKING_START_MASK (0x1 << 28) 164 | #define RT5514_TDM_DOCKING_START_SFT 28 165 | #define RT5514_TDM_DOCKING_START_SLOT0 (0x0 << 28) 166 | #define RT5514_TDM_DOCKING_START_SLOT4 (0x1 << 28) 167 | 168 | /* RT5514_DIG_SOURCE_CTRL (0x20a4) */ 169 | #define RT5514_AD1_DMIC_INPUT_SEL (0x1 << 1) 170 | #define RT5514_AD1_DMIC_INPUT_SEL_SFT 1 171 | #define RT5514_AD0_DMIC_INPUT_SEL (0x1 << 0) 172 | #define RT5514_AD0_DMIC_INPUT_SEL_SFT 0 173 | 174 | /* RT5514_PLL_SOURCE_CTRL (0x2100) */ 175 | #define RT5514_PLL_1_SEL_MASK (0x7 << 12) 176 | #define RT5514_PLL_1_SEL_SFT 12 177 | #define RT5514_PLL_1_SEL_SCLK (0x3 << 12) 178 | #define RT5514_PLL_1_SEL_MCLK (0x4 << 12) 179 | 180 | /* RT5514_CLK_CTRL1 (0x2104) */ 181 | #define RT5514_CLK_AD_ANA1_EN (0x1 << 31) 182 | #define RT5514_CLK_AD_ANA1_EN_BIT 31 183 | #define RT5514_CLK_AD1_EN (0x1 << 24) 184 | #define RT5514_CLK_AD1_EN_BIT 24 185 | #define RT5514_CLK_AD0_EN (0x1 << 23) 186 | #define RT5514_CLK_AD0_EN_BIT 23 187 | #define RT5514_CLK_DMIC_OUT_SEL_MASK (0x7 << 8) 188 | #define RT5514_CLK_DMIC_OUT_SEL_SFT 8 189 | #define RT5514_CLK_AD_ANA1_SEL_MASK (0xf << 0) 190 | #define RT5514_CLK_AD_ANA1_SEL_SFT 0 191 | 192 | /* RT5514_CLK_CTRL2 (0x2108) */ 193 | #define RT5514_CLK_AD1_ASRC_EN (0x1 << 17) 194 | #define RT5514_CLK_AD1_ASRC_EN_BIT 17 195 | #define RT5514_CLK_AD0_ASRC_EN (0x1 << 16) 196 | #define RT5514_CLK_AD0_ASRC_EN_BIT 16 197 | #define RT5514_CLK_SYS_DIV_OUT_MASK (0x7 << 8) 198 | #define RT5514_CLK_SYS_DIV_OUT_SFT 8 199 | #define RT5514_SEL_ADC_OSR_MASK (0x7 << 4) 200 | #define RT5514_SEL_ADC_OSR_SFT 4 201 | #define RT5514_CLK_SYS_PRE_SEL_MASK (0x3 << 0) 202 | #define RT5514_CLK_SYS_PRE_SEL_SFT 0 203 | #define RT5514_CLK_SYS_PRE_SEL_MCLK (0x2 << 0) 204 | #define RT5514_CLK_SYS_PRE_SEL_PLL (0x3 << 0) 205 | 206 | /* RT5514_DOWNFILTER_CTRL (0x2190 0x2194 0x21a0 0x21a4) */ 207 | #define RT5514_AD_DMIC_MIX (0x1 << 11) 208 | #define RT5514_AD_DMIC_MIX_BIT 11 209 | #define RT5514_AD_AD_MIX (0x1 << 10) 210 | #define RT5514_AD_AD_MIX_BIT 10 211 | #define RT5514_AD_AD_MUTE (0x1 << 7) 212 | #define RT5514_AD_AD_MUTE_BIT 7 213 | #define RT5514_AD_GAIN_MASK (0x3f << 1) 214 | #define RT5514_AD_GAIN_SFT 1 215 | 216 | /* RT5514_ANA_CTRL_MICBST (0x2220) */ 217 | #define RT5514_SEL_BSTL_MASK (0xf << 4) 218 | #define RT5514_SEL_BSTL_SFT 4 219 | #define RT5514_SEL_BSTR_MASK (0xf << 0) 220 | #define RT5514_SEL_BSTR_SFT 0 221 | 222 | /* RT5514_ANA_CTRL_PLL1_1 (0x2260) */ 223 | #define RT5514_PLL_K_MAX 0x1f 224 | #define RT5514_PLL_K_MASK (RT5514_PLL_K_MAX << 16) 225 | #define RT5514_PLL_K_SFT 16 226 | #define RT5514_PLL_N_MAX 0x1ff 227 | #define RT5514_PLL_N_MASK (RT5514_PLL_N_MAX << 7) 228 | #define RT5514_PLL_N_SFT 4 229 | #define RT5514_PLL_M_MAX 0xf 230 | #define RT5514_PLL_M_MASK (RT5514_PLL_M_MAX << 0) 231 | #define RT5514_PLL_M_SFT 0 232 | 233 | /* RT5514_ANA_CTRL_PLL1_2 (0x2264) */ 234 | #define RT5514_PLL_M_BP (0x1 << 2) 235 | #define RT5514_PLL_M_BP_SFT 2 236 | #define RT5514_PLL_K_BP (0x1 << 1) 237 | #define RT5514_PLL_K_BP_SFT 1 238 | #define RT5514_EN_LDO_PLL1 (0x1 << 0) 239 | #define RT5514_EN_LDO_PLL1_BIT 0 240 | 241 | #define RT5514_PLL_INP_MAX 40000000 242 | #define RT5514_PLL_INP_MIN 256000 243 | 244 | /* System Clock Source */ 245 | enum { 246 | RT5514_SCLK_S_MCLK, 247 | RT5514_SCLK_S_PLL1, 248 | }; 249 | 250 | /* PLL1 Source */ 251 | enum { 252 | RT5514_PLL1_S_MCLK, 253 | RT5514_PLL1_S_BCLK, 254 | }; 255 | 256 | #endif /* __RT5514_H__ */ -------------------------------------------------------------------------------- /rt5514/spb.c: -------------------------------------------------------------------------------- 1 | /*++ 2 | Copyright (c) Microsoft Corporation. All Rights Reserved. 3 | Sample code. Dealpoint ID #843729. 4 | 5 | Module Name: 6 | 7 | spb.c 8 | 9 | Abstract: 10 | 11 | Contains all I2C-specific functionality 12 | 13 | Environment: 14 | 15 | Kernel mode 16 | 17 | Revision History: 18 | 19 | --*/ 20 | 21 | #include "rt5514.h" 22 | #include "spb.h" 23 | #include 24 | #include 25 | 26 | static ULONG Rt5514DebugLevel = 100; 27 | static ULONG Rt5514DebugCatagories = DBG_INIT || DBG_PNP || DBG_IOCTL; 28 | 29 | NTSTATUS 30 | SpbDoWriteDataSynchronously( 31 | IN SPB_CONTEXT* SpbContext, 32 | IN PVOID Data, 33 | IN ULONG Length 34 | ) 35 | /*++ 36 | 37 | Routine Description: 38 | 39 | This helper routine abstracts creating and sending an I/O 40 | request (I2C Write) to the Spb I/O target. 41 | 42 | Arguments: 43 | 44 | SpbContext - Pointer to the current device context 45 | Address - The I2C register address to write to 46 | Data - A buffer to receive the data at at the above address 47 | Length - The amount of data to be read from the above address 48 | 49 | Return Value: 50 | 51 | NTSTATUS Status indicating success or failure 52 | 53 | --*/ 54 | { 55 | PUCHAR buffer; 56 | ULONG length; 57 | WDFMEMORY memory; 58 | WDF_MEMORY_DESCRIPTOR memoryDescriptor; 59 | NTSTATUS status; 60 | 61 | length = Length; 62 | memory = NULL; 63 | 64 | if (length > DEFAULT_SPB_BUFFER_SIZE) 65 | { 66 | status = WdfMemoryCreate( 67 | WDF_NO_OBJECT_ATTRIBUTES, 68 | NonPagedPool, 69 | RT5514_POOL_TAG, 70 | length, 71 | &memory, 72 | (PVOID*)&buffer); 73 | 74 | if (!NT_SUCCESS(status)) 75 | { 76 | Rt5514Print( 77 | DEBUG_LEVEL_ERROR, 78 | DBG_IOCTL, 79 | "Error allocating memory for Spb write - %!STATUS!", 80 | status); 81 | goto exit; 82 | } 83 | 84 | WDF_MEMORY_DESCRIPTOR_INIT_HANDLE( 85 | &memoryDescriptor, 86 | memory, 87 | NULL); 88 | } 89 | else 90 | { 91 | buffer = (PUCHAR)WdfMemoryGetBuffer(SpbContext->WriteMemory, NULL); 92 | 93 | WDF_MEMORY_DESCRIPTOR_INIT_BUFFER( 94 | &memoryDescriptor, 95 | (PVOID)buffer, 96 | length); 97 | } 98 | 99 | RtlCopyMemory(buffer, Data, length); 100 | 101 | status = WdfIoTargetSendWriteSynchronously( 102 | SpbContext->SpbIoTarget, 103 | NULL, 104 | &memoryDescriptor, 105 | NULL, 106 | NULL, 107 | NULL); 108 | 109 | if (!NT_SUCCESS(status)) 110 | { 111 | Rt5514Print( 112 | DEBUG_LEVEL_ERROR, 113 | DBG_IOCTL, 114 | "Error writing to Spb - %!STATUS!", 115 | status); 116 | goto exit; 117 | } 118 | 119 | exit: 120 | 121 | if (NULL != memory) 122 | { 123 | WdfObjectDelete(memory); 124 | } 125 | 126 | return status; 127 | } 128 | 129 | NTSTATUS 130 | SpbLockController( 131 | IN SPB_CONTEXT* SpbContext 132 | ) 133 | /*++ 134 | Routine Description: 135 | This routine sends a lock command to the SPB controller. 136 | Arguments: 137 | pDevice - a pointer to the device context 138 | FxRequest - the framework request object 139 | Return Value: 140 | None 141 | --*/ 142 | { 143 | NTSTATUS status; 144 | 145 | // 146 | // Initialize the SPB request for lock and send. 147 | // 148 | 149 | status = WdfIoTargetSendIoctlSynchronously( 150 | SpbContext->SpbIoTarget, 151 | NULL, 152 | IOCTL_SPB_LOCK_CONTROLLER, 153 | NULL, 154 | NULL, 155 | NULL, 156 | NULL); 157 | 158 | if (!NT_SUCCESS(status)) 159 | { 160 | Rt5514Print( 161 | DEBUG_LEVEL_ERROR, 162 | DBG_IOCTL, 163 | "Failed to send SPB request for " 164 | "IOCTL_SPB_LOCK_CONTROLLER - %!STATUS!", 165 | status); 166 | } 167 | return status; 168 | } 169 | 170 | NTSTATUS 171 | SpbUnlockController( 172 | IN SPB_CONTEXT* SpbContext 173 | ) 174 | /*++ 175 | Routine Description: 176 | This routine sends a lock command to the SPB controller. 177 | Arguments: 178 | pDevice - a pointer to the device context 179 | FxRequest - the framework request object 180 | Return Value: 181 | None 182 | --*/ 183 | { 184 | NTSTATUS status; 185 | 186 | // 187 | // Initialize the SPB request for lock and send. 188 | // 189 | 190 | status = WdfIoTargetSendIoctlSynchronously( 191 | SpbContext->SpbIoTarget, 192 | NULL, 193 | IOCTL_SPB_UNLOCK_CONTROLLER, 194 | NULL, 195 | NULL, 196 | NULL, 197 | NULL); 198 | 199 | if (!NT_SUCCESS(status)) 200 | { 201 | Rt5514Print( 202 | DEBUG_LEVEL_ERROR, 203 | DBG_IOCTL, 204 | "Failed to send SPB request for " 205 | "IOCTL_SPB_UNLOCK_CONTROLLER - %!STATUS!", 206 | status); 207 | } 208 | return status; 209 | } 210 | 211 | NTSTATUS 212 | SpbWriteDataSynchronously( 213 | IN SPB_CONTEXT* SpbContext, 214 | IN PVOID Data, 215 | IN ULONG Length 216 | ) 217 | /*++ 218 | 219 | Routine Description: 220 | 221 | This routine abstracts creating and sending an I/O 222 | request (I2C Write) to the Spb I/O target and utilizes 223 | a helper routine to do work inside of locked code. 224 | 225 | Arguments: 226 | 227 | SpbContext - Pointer to the current device context 228 | Address - The I2C register address to write to 229 | Data - A buffer to receive the data at at the above address 230 | Length - The amount of data to be read from the above address 231 | 232 | Return Value: 233 | 234 | NTSTATUS Status indicating success or failure 235 | 236 | --*/ 237 | { 238 | NTSTATUS status; 239 | 240 | WdfWaitLockAcquire(SpbContext->SpbLock, NULL); 241 | 242 | status = SpbDoWriteDataSynchronously( 243 | SpbContext, 244 | Data, 245 | Length); 246 | 247 | WdfWaitLockRelease(SpbContext->SpbLock); 248 | 249 | return status; 250 | } 251 | 252 | NTSTATUS 253 | SpbXferDataSynchronously( 254 | _In_ SPB_CONTEXT* SpbContext, 255 | _In_ PVOID SendData, 256 | _In_ ULONG SendLength, 257 | _In_reads_bytes_(Length) PVOID Data, 258 | _In_ ULONG Length 259 | ) 260 | /*++ 261 | Routine Description: 262 | This helper routine abstracts creating and sending an I/O 263 | request (I2C Read) to the Spb I/O target. 264 | Arguments: 265 | SpbContext - Pointer to the current device context 266 | Address - The I2C register address to read from 267 | Data - A buffer to receive the data at at the above address 268 | Length - The amount of data to be read from the above address 269 | Return Value: 270 | NTSTATUS Status indicating success or failure 271 | --*/ 272 | { 273 | PUCHAR buffer; 274 | WDFMEMORY memory; 275 | WDF_MEMORY_DESCRIPTOR memoryDescriptor; 276 | NTSTATUS status; 277 | ULONG_PTR bytesRead; 278 | 279 | WdfWaitLockAcquire(SpbContext->SpbLock, NULL); 280 | SpbLockController(SpbContext); 281 | 282 | memory = NULL; 283 | status = STATUS_INVALID_PARAMETER; 284 | bytesRead = 0; 285 | 286 | // 287 | // Xfer transactions start by writing an address pointer 288 | // 289 | status = SpbDoWriteDataSynchronously( 290 | SpbContext, 291 | SendData, 292 | SendLength); 293 | 294 | if (!NT_SUCCESS(status)) 295 | { 296 | Rt5514Print( 297 | DEBUG_LEVEL_ERROR, 298 | DBG_IOCTL, 299 | "Error setting address pointer for Spb read - %!STATUS!", 300 | status); 301 | goto exit; 302 | } 303 | 304 | if (Length > DEFAULT_SPB_BUFFER_SIZE) 305 | { 306 | status = WdfMemoryCreate( 307 | WDF_NO_OBJECT_ATTRIBUTES, 308 | NonPagedPool, 309 | RT5514_POOL_TAG, 310 | Length, 311 | &memory, 312 | (PVOID*)&buffer); 313 | 314 | if (!NT_SUCCESS(status)) 315 | { 316 | Rt5514Print( 317 | DEBUG_LEVEL_ERROR, 318 | DBG_IOCTL, 319 | "Error allocating memory for Spb read - %!STATUS!", 320 | status); 321 | goto exit; 322 | } 323 | 324 | WDF_MEMORY_DESCRIPTOR_INIT_HANDLE( 325 | &memoryDescriptor, 326 | memory, 327 | NULL); 328 | } 329 | else 330 | { 331 | buffer = (PUCHAR)WdfMemoryGetBuffer(SpbContext->ReadMemory, NULL); 332 | 333 | WDF_MEMORY_DESCRIPTOR_INIT_BUFFER( 334 | &memoryDescriptor, 335 | (PVOID)buffer, 336 | Length); 337 | } 338 | 339 | 340 | status = WdfIoTargetSendReadSynchronously( 341 | SpbContext->SpbIoTarget, 342 | NULL, 343 | &memoryDescriptor, 344 | NULL, 345 | NULL, 346 | &bytesRead); 347 | 348 | if (!NT_SUCCESS(status) || 349 | bytesRead != Length) 350 | { 351 | Rt5514Print( 352 | DEBUG_LEVEL_ERROR, 353 | DBG_IOCTL, 354 | "Error reading from Spb - %!STATUS!", 355 | status); 356 | goto exit; 357 | } 358 | 359 | // 360 | // Copy back to the caller's buffer 361 | // 362 | RtlCopyMemory(Data, buffer, Length); 363 | 364 | exit: 365 | if (NULL != memory) 366 | { 367 | WdfObjectDelete(memory); 368 | } 369 | 370 | SpbUnlockController(SpbContext); 371 | WdfWaitLockRelease(SpbContext->SpbLock); 372 | 373 | return status; 374 | } 375 | 376 | VOID 377 | SpbTargetDeinitialize( 378 | IN WDFDEVICE FxDevice, 379 | IN SPB_CONTEXT* SpbContext 380 | ) 381 | /*++ 382 | 383 | Routine Description: 384 | 385 | This helper routine is used to free any members added to the SPB_CONTEXT, 386 | note the SPB I/O target is parented to the device and will be 387 | closed and free'd when the device is removed. 388 | 389 | Arguments: 390 | 391 | FxDevice - Handle to the framework device object 392 | SpbContext - Pointer to the current device context 393 | 394 | Return Value: 395 | 396 | NTSTATUS Status indicating success or failure 397 | 398 | --*/ 399 | { 400 | UNREFERENCED_PARAMETER(FxDevice); 401 | UNREFERENCED_PARAMETER(SpbContext); 402 | 403 | // 404 | // Free any SPB_CONTEXT allocations here 405 | // 406 | if (SpbContext->SpbLock != NULL) 407 | { 408 | WdfObjectDelete(SpbContext->SpbLock); 409 | } 410 | 411 | if (SpbContext->ReadMemory != NULL) 412 | { 413 | WdfObjectDelete(SpbContext->ReadMemory); 414 | } 415 | 416 | if (SpbContext->WriteMemory != NULL) 417 | { 418 | WdfObjectDelete(SpbContext->WriteMemory); 419 | } 420 | } 421 | 422 | NTSTATUS 423 | SpbTargetInitialize( 424 | IN WDFDEVICE FxDevice, 425 | IN SPB_CONTEXT* SpbContext 426 | ) 427 | /*++ 428 | 429 | Routine Description: 430 | 431 | This helper routine opens the Spb I/O target and 432 | initializes a request object used for the lifetime 433 | of communication between this driver and Spb. 434 | 435 | Arguments: 436 | 437 | FxDevice - Handle to the framework device object 438 | SpbContext - Pointer to the current device context 439 | 440 | Return Value: 441 | 442 | NTSTATUS Status indicating success or failure 443 | 444 | --*/ 445 | { 446 | WDF_OBJECT_ATTRIBUTES objectAttributes; 447 | WDF_IO_TARGET_OPEN_PARAMS openParams; 448 | UNICODE_STRING spbDeviceName; 449 | WCHAR spbDeviceNameBuffer[RESOURCE_HUB_PATH_SIZE]; 450 | NTSTATUS status; 451 | 452 | WDF_OBJECT_ATTRIBUTES_INIT(&objectAttributes); 453 | objectAttributes.ParentObject = FxDevice; 454 | 455 | status = WdfIoTargetCreate( 456 | FxDevice, 457 | &objectAttributes, 458 | &SpbContext->SpbIoTarget); 459 | 460 | if (!NT_SUCCESS(status)) 461 | { 462 | Rt5514Print( 463 | DEBUG_LEVEL_ERROR, 464 | DBG_IOCTL, 465 | "Error creating IoTarget object - %!STATUS!", 466 | status); 467 | 468 | WdfObjectDelete(SpbContext->SpbIoTarget); 469 | goto exit; 470 | } 471 | 472 | RtlInitEmptyUnicodeString( 473 | &spbDeviceName, 474 | spbDeviceNameBuffer, 475 | sizeof(spbDeviceNameBuffer)); 476 | 477 | status = RESOURCE_HUB_CREATE_PATH_FROM_ID( 478 | &spbDeviceName, 479 | SpbContext->I2cResHubId.LowPart, 480 | SpbContext->I2cResHubId.HighPart); 481 | 482 | if (!NT_SUCCESS(status)) 483 | { 484 | Rt5514Print( 485 | DEBUG_LEVEL_ERROR, 486 | DBG_IOCTL, 487 | "Error creating Spb resource hub path string - %!STATUS!", 488 | status); 489 | goto exit; 490 | } 491 | 492 | WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME( 493 | &openParams, 494 | &spbDeviceName, 495 | (GENERIC_READ | GENERIC_WRITE)); 496 | 497 | openParams.ShareAccess = 0; 498 | openParams.CreateDisposition = FILE_OPEN; 499 | openParams.FileAttributes = FILE_ATTRIBUTE_NORMAL; 500 | 501 | status = WdfIoTargetOpen(SpbContext->SpbIoTarget, &openParams); 502 | 503 | if (!NT_SUCCESS(status)) 504 | { 505 | Rt5514Print( 506 | DEBUG_LEVEL_ERROR, 507 | DBG_IOCTL, 508 | "Error opening Spb target for communication - %!STATUS!", 509 | status); 510 | goto exit; 511 | } 512 | 513 | // 514 | // Allocate some fixed-size buffers from NonPagedPool for typical 515 | // Spb transaction sizes to avoid pool fragmentation in most cases 516 | // 517 | status = WdfMemoryCreate( 518 | WDF_NO_OBJECT_ATTRIBUTES, 519 | NonPagedPool, 520 | RT5514_POOL_TAG, 521 | DEFAULT_SPB_BUFFER_SIZE, 522 | &SpbContext->WriteMemory, 523 | NULL); 524 | 525 | if (!NT_SUCCESS(status)) 526 | { 527 | Rt5514Print( 528 | DEBUG_LEVEL_ERROR, 529 | DBG_IOCTL, 530 | "Error allocating default memory for Spb write - %!STATUS!", 531 | status); 532 | goto exit; 533 | } 534 | 535 | status = WdfMemoryCreate( 536 | WDF_NO_OBJECT_ATTRIBUTES, 537 | NonPagedPool, 538 | RT5514_POOL_TAG, 539 | DEFAULT_SPB_BUFFER_SIZE, 540 | &SpbContext->ReadMemory, 541 | NULL); 542 | 543 | if (!NT_SUCCESS(status)) 544 | { 545 | Rt5514Print( 546 | DEBUG_LEVEL_ERROR, 547 | DBG_IOCTL, 548 | "Error allocating default memory for Spb read - %!STATUS!", 549 | status); 550 | goto exit; 551 | } 552 | 553 | // 554 | // Allocate a waitlock to guard access to the default buffers 555 | // 556 | status = WdfWaitLockCreate( 557 | WDF_NO_OBJECT_ATTRIBUTES, 558 | &SpbContext->SpbLock); 559 | 560 | if (!NT_SUCCESS(status)) 561 | { 562 | Rt5514Print( 563 | DEBUG_LEVEL_ERROR, 564 | DBG_IOCTL, 565 | "Error creating Spb Waitlock - %!STATUS!", 566 | status); 567 | goto exit; 568 | } 569 | 570 | exit: 571 | 572 | if (!NT_SUCCESS(status)) 573 | { 574 | SpbTargetDeinitialize(FxDevice, SpbContext); 575 | } 576 | 577 | return status; 578 | } -------------------------------------------------------------------------------- /rt5514/rt5514.c: -------------------------------------------------------------------------------- 1 | #include "rt5514.h" 2 | #include "registers.h" 3 | 4 | #define bool int 5 | 6 | static ULONG Rt5514DebugLevel = 100; 7 | static ULONG Rt5514DebugCatagories = DBG_INIT || DBG_PNP || DBG_IOCTL; 8 | 9 | NTSTATUS 10 | DriverEntry( 11 | __in PDRIVER_OBJECT DriverObject, 12 | __in PUNICODE_STRING RegistryPath 13 | ) 14 | { 15 | NTSTATUS status = STATUS_SUCCESS; 16 | WDF_DRIVER_CONFIG config; 17 | WDF_OBJECT_ATTRIBUTES attributes; 18 | 19 | Rt5514Print(DEBUG_LEVEL_INFO, DBG_INIT, 20 | "Driver Entry\n"); 21 | 22 | WDF_DRIVER_CONFIG_INIT(&config, Rt5514EvtDeviceAdd); 23 | 24 | WDF_OBJECT_ATTRIBUTES_INIT(&attributes); 25 | 26 | // 27 | // Create a framework driver object to represent our driver. 28 | // 29 | 30 | status = WdfDriverCreate(DriverObject, 31 | RegistryPath, 32 | &attributes, 33 | &config, 34 | WDF_NO_HANDLE 35 | ); 36 | 37 | if (!NT_SUCCESS(status)) 38 | { 39 | Rt5514Print(DEBUG_LEVEL_ERROR, DBG_INIT, 40 | "WdfDriverCreate failed with status 0x%x\n", status); 41 | } 42 | 43 | return status; 44 | } 45 | 46 | #define RT5514_DSP_MAPPING 0x18000000 47 | 48 | static NTSTATUS rt5514_reg_write(PRT5514_CONTEXT pDevice, uint16_t reg, uint32_t data) 49 | { 50 | uint32_t reg32 = reg | RT5514_DSP_MAPPING; 51 | uint32_t rawdata[2]; 52 | rawdata[0] = RtlUlongByteSwap(reg32); 53 | rawdata[1] = RtlUlongByteSwap(data); 54 | return SpbWriteDataSynchronously(&pDevice->I2CContext, rawdata, sizeof(rawdata)); 55 | } 56 | static NTSTATUS rt5514_reg_read(PRT5514_CONTEXT pDevice, uint16_t reg, uint32_t* data) 57 | { 58 | uint32_t reg32 = RT5514_DSP_MAPPING | reg; 59 | uint32_t reg_swap = RtlUlongByteSwap(reg32); 60 | uint32_t data_swap = 0; 61 | NTSTATUS ret = SpbXferDataSynchronously(&pDevice->I2CContext, ®_swap, sizeof(uint32_t), &data_swap, sizeof(uint32_t)); 62 | *data = RtlUlongByteSwap(data_swap); 63 | return ret; 64 | } 65 | 66 | static NTSTATUS rt5514_reg_update( 67 | _In_ PRT5514_CONTEXT pDevice, 68 | uint16_t reg, 69 | uint32_t mask, 70 | uint32_t val 71 | ) { 72 | uint32_t tmp = 0, orig = 0; 73 | 74 | NTSTATUS status = rt5514_reg_read(pDevice, reg, &orig); 75 | if (!NT_SUCCESS(status)) { 76 | return status; 77 | } 78 | 79 | tmp = orig & ~mask; 80 | tmp |= val & mask; 81 | 82 | if (tmp != orig) { 83 | status = rt5514_reg_write(pDevice, reg, tmp); 84 | } 85 | return status; 86 | } 87 | 88 | struct reg { 89 | UINT32 reg; 90 | UINT32 val; 91 | }; 92 | 93 | 94 | static NTSTATUS rt5514_reg_burstWrite(PRT5514_CONTEXT pDevice, struct reg* regs, int regCount) { 95 | NTSTATUS status = STATUS_NO_MEMORY; 96 | for (int i = 0; i < regCount; i++) { 97 | struct reg* regToSet = ®s[i]; 98 | 99 | uint32_t reg32 = regToSet->reg; 100 | uint32_t rawdata[2]; 101 | rawdata[0] = RtlUlongByteSwap(reg32); 102 | rawdata[1] = RtlUlongByteSwap(regToSet->val); 103 | 104 | status = SpbWriteDataSynchronously(&pDevice->I2CContext, rawdata, sizeof(rawdata)); 105 | if (!NT_SUCCESS(status)) { 106 | return status; 107 | } 108 | } 109 | return status; 110 | } 111 | 112 | NTSTATUS 113 | StartCodec( 114 | PRT5514_CONTEXT pDevice 115 | ) { 116 | NTSTATUS status = STATUS_SUCCESS; 117 | 118 | 119 | uint32_t val = 0; 120 | rt5514_reg_read(pDevice, RT5514_VENDOR_ID2, &val); 121 | if (val != RT5514_DEVICE_ID) { 122 | rt5514_reg_read(pDevice, RT5514_VENDOR_ID2, &val); 123 | if (val != RT5514_DEVICE_ID) { 124 | return STATUS_INVALID_DEVICE_STATE; 125 | } 126 | } 127 | 128 | 129 | struct reg rt5514_i2c_patch[] = { 130 | {0x1800101c, 0x00000000}, 131 | {0x18001100, 0x0000031f}, 132 | {0x18001104, 0x00000007}, 133 | {0x18001108, 0x00000000}, 134 | {0x1800110c, 0x00000000}, 135 | {0x18001110, 0x00000000}, 136 | {0x18001114, 0x00000001}, 137 | {0x18001118, 0x00000000}, 138 | {0x18002f08, 0x00000006}, 139 | {0x18002f00, 0x00055149}, 140 | {0x18002f00, 0x0005514b}, 141 | {0x18002f00, 0x00055149}, 142 | {0xfafafafa, 0x00000001}, 143 | {0x18002f10, 0x00000001}, 144 | {0x18002f10, 0x00000000}, 145 | {0x18002f10, 0x00000001}, 146 | {0xfafafafa, 0x00000001}, 147 | {0x18002000, 0x000010ec}, 148 | {0xfafafafa, 0x00000000}, 149 | }; 150 | 151 | status = rt5514_reg_burstWrite(pDevice, rt5514_i2c_patch, sizeof(rt5514_i2c_patch) / sizeof(struct reg)); 152 | if (!NT_SUCCESS(status)) { 153 | return status; 154 | } 155 | 156 | static struct reg rt5514_patch[] = { 157 | {RT5514_DIG_IO_CTRL | RT5514_DSP_MAPPING, 0x00000040}, 158 | {RT5514_CLK_CTRL1 | RT5514_DSP_MAPPING, 0x38020041}, 159 | {RT5514_SRC_CTRL | RT5514_DSP_MAPPING, 0x44000eee}, 160 | {RT5514_ANA_CTRL_LDO10 | RT5514_DSP_MAPPING, 0x00028604}, 161 | {RT5514_ANA_CTRL_ADCFED | RT5514_DSP_MAPPING, 0x00000800}, 162 | {RT5514_ASRC_IN_CTRL1 | RT5514_DSP_MAPPING, 0x00000003}, 163 | {RT5514_DOWNFILTER0_CTRL3 | RT5514_DSP_MAPPING, 0x10000342}, 164 | {RT5514_DOWNFILTER1_CTRL3 | RT5514_DSP_MAPPING, 0x10000342}, 165 | }; 166 | 167 | status = rt5514_reg_burstWrite(pDevice, rt5514_patch, sizeof(rt5514_patch) / sizeof(struct reg)); 168 | if (!NT_SUCCESS(status)) { 169 | return status; 170 | } 171 | 172 | // Set TDM slot 173 | { 174 | unsigned int val = RT5514_TDM_MODE; 175 | unsigned int val2 = 0; 176 | 177 | //tx mask 0xF 178 | val2 = RT5514_TDM_DOCKING_MODE | RT5514_TDM_DOCKING_VALID_CH4 | 179 | RT5514_TDM_DOCKING_START_SLOT0; 180 | 181 | //8 slots 182 | val |= RT5514_TDMSLOT_SEL_RX_8CH | RT5514_TDMSLOT_SEL_TX_8CH; 183 | 184 | //16 slot width 185 | 186 | rt5514_reg_update(pDevice, RT5514_I2S_CTRL1, RT5514_TDM_MODE | 187 | RT5514_TDMSLOT_SEL_RX_MASK | RT5514_TDMSLOT_SEL_TX_MASK | 188 | RT5514_CH_LEN_RX_MASK | RT5514_CH_LEN_TX_MASK | 189 | RT5514_TDM_MODE2, val); 190 | rt5514_reg_update(pDevice, RT5514_I2S_CTRL2, 191 | RT5514_TDM_DOCKING_MODE | RT5514_TDM_DOCKING_VALID_CH_MASK | 192 | RT5514_TDM_DOCKING_START_MASK, val2); 193 | } 194 | 195 | //Set sysclk + PLL 196 | 197 | rt5514_reg_write(pDevice, RT5514_CLK_CTRL1, 0x39820342); 198 | rt5514_reg_write(pDevice, RT5514_CLK_CTRL2, 0x00030112); 199 | 200 | //set DAI fmt 201 | 202 | rt5514_reg_update(pDevice, RT5514_I2S_CTRL1, RT5514_I2S_DF_MASK | RT5514_I2S_BP_MASK | RT5514_I2S_LR_MASK, RT5514_I2S_DF_PCM_B); 203 | 204 | //set capture volumes 205 | 206 | rt5514_reg_write(pDevice, RT5514_DOWNFILTER0_CTRL1, 0x0002046f); 207 | rt5514_reg_write(pDevice, RT5514_DOWNFILTER0_CTRL2, 0x0002046f); 208 | 209 | rt5514_reg_write(pDevice, RT5514_DOWNFILTER1_CTRL1, 0x0002046f); 210 | rt5514_reg_write(pDevice, RT5514_DOWNFILTER1_CTRL2, 0x0002046f); 211 | 212 | pDevice->DevicePoweredOn = TRUE; 213 | return status; 214 | } 215 | 216 | NTSTATUS 217 | StopCodec( 218 | PRT5514_CONTEXT pDevice 219 | ) { 220 | NTSTATUS status = STATUS_SUCCESS; 221 | 222 | pDevice->DevicePoweredOn = FALSE; 223 | return status; 224 | } 225 | 226 | int CsAudioArg2 = 1; 227 | 228 | VOID 229 | CSAudioRegisterEndpoint( 230 | PRT5514_CONTEXT pDevice 231 | ) { 232 | CsAudioArg arg; 233 | RtlZeroMemory(&arg, sizeof(CsAudioArg)); 234 | arg.argSz = sizeof(CsAudioArg); 235 | arg.endpointType = CSAudioEndpointTypeMicArray; 236 | arg.endpointRequest = CSAudioEndpointRegister; 237 | ExNotifyCallback(pDevice->CSAudioAPICallback, &arg, &CsAudioArg2); 238 | 239 | RtlZeroMemory(&arg, sizeof(CsAudioArg)); 240 | arg.argSz = sizeof(CsAudioArg); 241 | arg.endpointType = CSAudioEndpointTypeMicArray; 242 | arg.endpointRequest = CSAudioEndpointOverrideFormat; 243 | arg.formatOverride.force32BitOutputContainer = TRUE; 244 | ExNotifyCallback(pDevice->CSAudioAPICallback, &arg, &CsAudioArg2); 245 | } 246 | 247 | VOID 248 | CsAudioCallbackFunction( 249 | IN PRT5514_CONTEXT pDevice, 250 | CsAudioArg* arg, 251 | PVOID Argument2 252 | ) { 253 | if (!pDevice) { 254 | return; 255 | } 256 | 257 | if (Argument2 == &CsAudioArg2) { 258 | return; 259 | } 260 | 261 | pDevice->CSAudioManaged = TRUE; 262 | 263 | CsAudioArg localArg; 264 | RtlZeroMemory(&localArg, sizeof(CsAudioArg)); 265 | RtlCopyMemory(&localArg, arg, min(arg->argSz, sizeof(CsAudioArg))); 266 | 267 | if (localArg.endpointType == CSAudioEndpointTypeDSP && localArg.endpointRequest == CSAudioEndpointRegister) { 268 | CSAudioRegisterEndpoint(pDevice); 269 | } 270 | else if (localArg.endpointType != CSAudioEndpointTypeMicArray) { 271 | return; 272 | } 273 | 274 | if (localArg.endpointRequest == CSAudioEndpointStop) { 275 | StopCodec(pDevice); 276 | } 277 | if (localArg.endpointRequest == CSAudioEndpointStart) { 278 | StartCodec(pDevice); 279 | } 280 | } 281 | 282 | NTSTATUS 283 | OnPrepareHardware( 284 | _In_ WDFDEVICE FxDevice, 285 | _In_ WDFCMRESLIST FxResourcesRaw, 286 | _In_ WDFCMRESLIST FxResourcesTranslated 287 | ) 288 | /*++ 289 | 290 | Routine Description: 291 | 292 | This routine caches the SPB resource connection ID. 293 | 294 | Arguments: 295 | 296 | FxDevice - a handle to the framework device object 297 | FxResourcesRaw - list of translated hardware resources that 298 | the PnP manager has assigned to the device 299 | FxResourcesTranslated - list of raw hardware resources that 300 | the PnP manager has assigned to the device 301 | 302 | Return Value: 303 | 304 | Status 305 | 306 | --*/ 307 | { 308 | PRT5514_CONTEXT pDevice = GetDeviceContext(FxDevice); 309 | BOOLEAN fSpbResourceFound = FALSE; 310 | NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES; 311 | 312 | UNREFERENCED_PARAMETER(FxResourcesRaw); 313 | 314 | // 315 | // Parse the peripheral's resources. 316 | // 317 | 318 | ULONG resourceCount = WdfCmResourceListGetCount(FxResourcesTranslated); 319 | 320 | for (ULONG i = 0; i < resourceCount; i++) 321 | { 322 | PCM_PARTIAL_RESOURCE_DESCRIPTOR pDescriptor; 323 | UCHAR Class; 324 | UCHAR Type; 325 | 326 | pDescriptor = WdfCmResourceListGetDescriptor( 327 | FxResourcesTranslated, i); 328 | 329 | switch (pDescriptor->Type) 330 | { 331 | case CmResourceTypeConnection: 332 | // 333 | // Look for I2C or SPI resource and save connection ID. 334 | // 335 | Class = pDescriptor->u.Connection.Class; 336 | Type = pDescriptor->u.Connection.Type; 337 | if (Class == CM_RESOURCE_CONNECTION_CLASS_SERIAL && 338 | Type == CM_RESOURCE_CONNECTION_TYPE_SERIAL_I2C) 339 | { 340 | if (fSpbResourceFound == FALSE) 341 | { 342 | status = STATUS_SUCCESS; 343 | pDevice->I2CContext.I2cResHubId.LowPart = pDescriptor->u.Connection.IdLowPart; 344 | pDevice->I2CContext.I2cResHubId.HighPart = pDescriptor->u.Connection.IdHighPart; 345 | fSpbResourceFound = TRUE; 346 | } 347 | else 348 | { 349 | } 350 | } 351 | break; 352 | default: 353 | // 354 | // Ignoring all other resource types. 355 | // 356 | break; 357 | } 358 | } 359 | 360 | // 361 | // An SPB resource is required. 362 | // 363 | 364 | if (fSpbResourceFound == FALSE) 365 | { 366 | status = STATUS_NOT_FOUND; 367 | } 368 | 369 | status = SpbTargetInitialize(FxDevice, &pDevice->I2CContext); 370 | 371 | if (!NT_SUCCESS(status)) 372 | { 373 | return status; 374 | } 375 | 376 | return status; 377 | } 378 | 379 | NTSTATUS 380 | OnReleaseHardware( 381 | _In_ WDFDEVICE FxDevice, 382 | _In_ WDFCMRESLIST FxResourcesTranslated 383 | ) 384 | /*++ 385 | 386 | Routine Description: 387 | 388 | Arguments: 389 | 390 | FxDevice - a handle to the framework device object 391 | FxResourcesTranslated - list of raw hardware resources that 392 | the PnP manager has assigned to the device 393 | 394 | Return Value: 395 | 396 | Status 397 | 398 | --*/ 399 | { 400 | PRT5514_CONTEXT pDevice = GetDeviceContext(FxDevice); 401 | NTSTATUS status = STATUS_SUCCESS; 402 | 403 | UNREFERENCED_PARAMETER(FxResourcesTranslated); 404 | 405 | SpbTargetDeinitialize(FxDevice, &pDevice->I2CContext); 406 | 407 | if (pDevice->CSAudioAPICallbackObj) { 408 | ExUnregisterCallback(pDevice->CSAudioAPICallbackObj); 409 | pDevice->CSAudioAPICallbackObj = NULL; 410 | } 411 | 412 | if (pDevice->CSAudioAPICallback) { 413 | ObfDereferenceObject(pDevice->CSAudioAPICallback); 414 | pDevice->CSAudioAPICallback = NULL; 415 | } 416 | 417 | return status; 418 | } 419 | 420 | NTSTATUS 421 | OnSelfManagedIoInit( 422 | _In_ 423 | WDFDEVICE FxDevice 424 | ) { 425 | PRT5514_CONTEXT pDevice = GetDeviceContext(FxDevice); 426 | NTSTATUS status = STATUS_SUCCESS; 427 | 428 | // CS Audio Callback 429 | 430 | UNICODE_STRING CSAudioCallbackAPI; 431 | RtlInitUnicodeString(&CSAudioCallbackAPI, L"\\CallBack\\CsAudioCallbackAPI"); 432 | 433 | 434 | OBJECT_ATTRIBUTES attributes; 435 | InitializeObjectAttributes(&attributes, 436 | &CSAudioCallbackAPI, 437 | OBJ_KERNEL_HANDLE | OBJ_OPENIF | OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 438 | NULL, 439 | NULL 440 | ); 441 | status = ExCreateCallback(&pDevice->CSAudioAPICallback, &attributes, TRUE, TRUE); 442 | if (!NT_SUCCESS(status)) { 443 | 444 | return status; 445 | } 446 | 447 | pDevice->CSAudioAPICallbackObj = ExRegisterCallback(pDevice->CSAudioAPICallback, 448 | CsAudioCallbackFunction, 449 | pDevice 450 | ); 451 | if (!pDevice->CSAudioAPICallbackObj) { 452 | 453 | return STATUS_NO_CALLBACK_ACTIVE; 454 | } 455 | 456 | CSAudioRegisterEndpoint(pDevice); 457 | 458 | return status; 459 | } 460 | 461 | NTSTATUS 462 | OnD0Entry( 463 | _In_ WDFDEVICE FxDevice, 464 | _In_ WDF_POWER_DEVICE_STATE FxPreviousState 465 | ) 466 | /*++ 467 | 468 | Routine Description: 469 | 470 | This routine allocates objects needed by the driver. 471 | 472 | Arguments: 473 | 474 | FxDevice - a handle to the framework device object 475 | FxPreviousState - previous power state 476 | 477 | Return Value: 478 | 479 | Status 480 | 481 | --*/ 482 | { 483 | UNREFERENCED_PARAMETER(FxPreviousState); 484 | 485 | PRT5514_CONTEXT pDevice = GetDeviceContext(FxDevice); 486 | NTSTATUS status = STATUS_SUCCESS; 487 | 488 | status = StartCodec(pDevice); 489 | 490 | return status; 491 | } 492 | 493 | NTSTATUS 494 | OnD0Exit( 495 | _In_ WDFDEVICE FxDevice, 496 | _In_ WDF_POWER_DEVICE_STATE FxPreviousState 497 | ) 498 | /*++ 499 | 500 | Routine Description: 501 | 502 | This routine destroys objects needed by the driver. 503 | 504 | Arguments: 505 | 506 | FxDevice - a handle to the framework device object 507 | FxPreviousState - previous power state 508 | 509 | Return Value: 510 | 511 | Status 512 | 513 | --*/ 514 | { 515 | UNREFERENCED_PARAMETER(FxPreviousState); 516 | 517 | PRT5514_CONTEXT pDevice = GetDeviceContext(FxDevice); 518 | NTSTATUS status = STATUS_SUCCESS; 519 | 520 | status = StopCodec(pDevice); 521 | 522 | return STATUS_SUCCESS; 523 | } 524 | 525 | NTSTATUS 526 | Rt5514EvtDeviceAdd( 527 | IN WDFDRIVER Driver, 528 | IN PWDFDEVICE_INIT DeviceInit 529 | ) 530 | { 531 | NTSTATUS status = STATUS_SUCCESS; 532 | WDF_IO_QUEUE_CONFIG queueConfig; 533 | WDF_OBJECT_ATTRIBUTES attributes; 534 | WDFDEVICE device; 535 | WDFQUEUE queue; 536 | PRT5514_CONTEXT devContext; 537 | 538 | UNREFERENCED_PARAMETER(Driver); 539 | 540 | PAGED_CODE(); 541 | 542 | Rt5514Print(DEBUG_LEVEL_INFO, DBG_PNP, 543 | "Rt5514EvtDeviceAdd called\n"); 544 | 545 | { 546 | WDF_PNPPOWER_EVENT_CALLBACKS pnpCallbacks; 547 | WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpCallbacks); 548 | 549 | pnpCallbacks.EvtDevicePrepareHardware = OnPrepareHardware; 550 | pnpCallbacks.EvtDeviceReleaseHardware = OnReleaseHardware; 551 | pnpCallbacks.EvtDeviceSelfManagedIoInit = OnSelfManagedIoInit; 552 | pnpCallbacks.EvtDeviceD0Entry = OnD0Entry; 553 | pnpCallbacks.EvtDeviceD0Exit = OnD0Exit; 554 | 555 | WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpCallbacks); 556 | } 557 | 558 | // 559 | // Setup the device context 560 | // 561 | 562 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, RT5514_CONTEXT); 563 | 564 | // 565 | // Create a framework device object.This call will in turn create 566 | // a WDM device object, attach to the lower stack, and set the 567 | // appropriate flags and attributes. 568 | // 569 | 570 | status = WdfDeviceCreate(&DeviceInit, &attributes, &device); 571 | 572 | if (!NT_SUCCESS(status)) 573 | { 574 | Rt5514Print(DEBUG_LEVEL_ERROR, DBG_PNP, 575 | "WdfDeviceCreate failed with status code 0x%x\n", status); 576 | 577 | return status; 578 | } 579 | 580 | { 581 | WDF_DEVICE_STATE deviceState; 582 | WDF_DEVICE_STATE_INIT(&deviceState); 583 | 584 | deviceState.NotDisableable = WdfFalse; 585 | WdfDeviceSetDeviceState(device, &deviceState); 586 | } 587 | 588 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchParallel); 589 | 590 | queueConfig.EvtIoInternalDeviceControl = Rt5514EvtInternalDeviceControl; 591 | 592 | status = WdfIoQueueCreate(device, 593 | &queueConfig, 594 | WDF_NO_OBJECT_ATTRIBUTES, 595 | &queue 596 | ); 597 | 598 | if (!NT_SUCCESS(status)) 599 | { 600 | Rt5514Print(DEBUG_LEVEL_ERROR, DBG_PNP, 601 | "WdfIoQueueCreate failed 0x%x\n", status); 602 | 603 | return status; 604 | } 605 | 606 | // 607 | // Create manual I/O queue to take care of hid report read requests 608 | // 609 | 610 | devContext = GetDeviceContext(device); 611 | 612 | devContext->FxDevice = device; 613 | 614 | WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual); 615 | 616 | queueConfig.PowerManaged = WdfFalse; 617 | 618 | status = WdfIoQueueCreate(device, 619 | &queueConfig, 620 | WDF_NO_OBJECT_ATTRIBUTES, 621 | &devContext->ReportQueue 622 | ); 623 | 624 | if (!NT_SUCCESS(status)) 625 | { 626 | Rt5514Print(DEBUG_LEVEL_ERROR, DBG_PNP, 627 | "WdfIoQueueCreate failed 0x%x\n", status); 628 | 629 | return status; 630 | } 631 | 632 | return status; 633 | } 634 | 635 | VOID 636 | Rt5514EvtInternalDeviceControl( 637 | IN WDFQUEUE Queue, 638 | IN WDFREQUEST Request, 639 | IN size_t OutputBufferLength, 640 | IN size_t InputBufferLength, 641 | IN ULONG IoControlCode 642 | ) 643 | { 644 | NTSTATUS status = STATUS_SUCCESS; 645 | WDFDEVICE device; 646 | PRT5514_CONTEXT devContext; 647 | 648 | UNREFERENCED_PARAMETER(OutputBufferLength); 649 | UNREFERENCED_PARAMETER(InputBufferLength); 650 | 651 | device = WdfIoQueueGetDevice(Queue); 652 | devContext = GetDeviceContext(device); 653 | 654 | switch (IoControlCode) 655 | { 656 | default: 657 | status = STATUS_NOT_SUPPORTED; 658 | break; 659 | } 660 | 661 | WdfRequestComplete(Request, status); 662 | 663 | return; 664 | } --------------------------------------------------------------------------------