├── ssm4567 ├── stdint.h ├── resource.h ├── ssm4567.rc ├── spb.h ├── trace.h ├── ssm4567.inf ├── registers.h ├── ssm4567.h ├── ssm4567.vcxproj ├── spb.c └── ssm4567.c ├── README.md ├── ssm4567.sln ├── LICENSE.txt ├── .gitignore └── ssm4567 Package └── ssm4567 Package.vcxproj /ssm4567/stdint.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define BIT(nr) (1UL << (nr)) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ssm4567 2 | SSM4567 Amplifier Driver 3 | 4 | Tested on HP Chromebook 13. Should work for several Skylake chromebooks. -------------------------------------------------------------------------------- /ssm4567/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by ssm4567.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 | -------------------------------------------------------------------------------- /ssm4567/ssm4567.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation All Rights Reserved 4 | 5 | Module Name: 6 | 7 | ssm4567.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 "Analog Devices SSM4567 Amplifier" 18 | #define VER_INTERNALNAME_STR "ssm4567.sys" 19 | #define VER_ORIGINALFILENAME_STR "ssm4567.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 "Analog Devices SSM4567 Amplifier" 40 | 41 | #include "common.ver" -------------------------------------------------------------------------------- /ssm4567/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 | ); -------------------------------------------------------------------------------- /ssm4567/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 | -------------------------------------------------------------------------------- /ssm4567/ssm4567.inf: -------------------------------------------------------------------------------- 1 | ;/*++ 2 | ; 3 | ;Copyright (c) CoolStar. All rights reserved. 4 | ; 5 | ;Module Name: 6 | ; ssm4567.inf 7 | ; 8 | ;Abstract: 9 | ; INF file for installing the Analog Devices SSM4567 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 = 2/23/2022,1.0.0 20 | CatalogFile = ssm4567.cat 21 | PnpLockdown=1 22 | 23 | [DestinationDirs] 24 | DefaultDestDir = 12 25 | 26 | ; ================= Class section ===================== 27 | 28 | [SourceDisksNames] 29 | 1 = %DiskId1%,,,"" 30 | 31 | [SourceDisksFiles] 32 | ssm4567.sys = 1,, 33 | 34 | ;***************************************** 35 | ; ssm4567 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 | %ssm4567.DeviceDesc%=Ts3a227e_Device, ACPI\INT343B 45 | 46 | [Ts3a227e_Device.NT] 47 | CopyFiles=Drivers_Dir 48 | 49 | [Drivers_Dir] 50 | ssm4567.sys 51 | 52 | ;-------------- Service installation 53 | [Ts3a227e_Device.NT.Services] 54 | AddService = ssm4567,%SPSVCINST_ASSOCSERVICE%, Ts3a227e_Service_Inst 55 | 56 | ; -------------- ssm4567 driver install sections 57 | [Ts3a227e_Service_Inst] 58 | DisplayName = %ssm4567.SVCDESC% 59 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 60 | StartType = 3 ; SERVICE_DEMAND_START 61 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 62 | ServiceBinary = %12%\ssm4567.sys 63 | LoadOrderGroup = Base 64 | 65 | [Strings] 66 | SPSVCINST_ASSOCSERVICE= 0x00000002 67 | StdMfg = "CoolStar" 68 | DiskId1 = "Analog Devices SSM4567 Installation Disk #1" 69 | ssm4567.DeviceDesc = "Analog Devices SSM4567 Amplifier" 70 | ssm4567.SVCDESC = "Analog Devices SSM4567 Service" 71 | -------------------------------------------------------------------------------- /ssm4567/registers.h: -------------------------------------------------------------------------------- 1 | #include "stdint.h" 2 | 3 | #define SSM4567_REG_POWER_CTRL 0x00 4 | #define SSM4567_REG_AMP_SNS_CTRL 0x01 5 | #define SSM4567_REG_DAC_CTRL 0x02 6 | #define SSM4567_REG_DAC_VOLUME 0x03 7 | #define SSM4567_REG_SAI_CTRL_1 0x04 8 | #define SSM4567_REG_SAI_CTRL_2 0x05 9 | #define SSM4567_REG_SAI_PLACEMENT_1 0x06 10 | #define SSM4567_REG_SAI_PLACEMENT_2 0x07 11 | #define SSM4567_REG_SAI_PLACEMENT_3 0x08 12 | #define SSM4567_REG_SAI_PLACEMENT_4 0x09 13 | #define SSM4567_REG_SAI_PLACEMENT_5 0x0a 14 | #define SSM4567_REG_SAI_PLACEMENT_6 0x0b 15 | #define SSM4567_REG_BATTERY_V_OUT 0x0c 16 | #define SSM4567_REG_LIMITER_CTRL_1 0x0d 17 | #define SSM4567_REG_LIMITER_CTRL_2 0x0e 18 | #define SSM4567_REG_LIMITER_CTRL_3 0x0f 19 | #define SSM4567_REG_STATUS_1 0x10 20 | #define SSM4567_REG_STATUS_2 0x11 21 | #define SSM4567_REG_FAULT_CTRL 0x12 22 | #define SSM4567_REG_PDM_CTRL 0x13 23 | #define SSM4567_REG_MCLK_RATIO 0x14 24 | #define SSM4567_REG_BOOST_CTRL_1 0x15 25 | #define SSM4567_REG_BOOST_CTRL_2 0x16 26 | #define SSM4567_REG_SOFT_RESET 0xff 27 | 28 | /* POWER_CTRL */ 29 | #define SSM4567_POWER_APWDN_EN BIT(7) 30 | #define SSM4567_POWER_BSNS_PWDN BIT(6) 31 | #define SSM4567_POWER_VSNS_PWDN BIT(5) 32 | #define SSM4567_POWER_ISNS_PWDN BIT(4) 33 | #define SSM4567_POWER_BOOST_PWDN BIT(3) 34 | #define SSM4567_POWER_AMP_PWDN BIT(2) 35 | #define SSM4567_POWER_VBAT_ONLY BIT(1) 36 | #define SSM4567_POWER_SPWDN BIT(0) 37 | 38 | /* DAC_CTRL */ 39 | #define SSM4567_DAC_HV BIT(7) 40 | #define SSM4567_DAC_MUTE BIT(6) 41 | #define SSM4567_DAC_HPF BIT(5) 42 | #define SSM4567_DAC_LPM BIT(4) 43 | #define SSM4567_DAC_FS_MASK 0x7 44 | #define SSM4567_DAC_FS_8000_12000 0x0 45 | #define SSM4567_DAC_FS_16000_24000 0x1 46 | #define SSM4567_DAC_FS_32000_48000 0x2 47 | #define SSM4567_DAC_FS_64000_96000 0x3 48 | #define SSM4567_DAC_FS_128000_192000 0x4 49 | 50 | /* SAI_CTRL_1 */ 51 | #define SSM4567_SAI_CTRL_1_BCLK BIT(6) 52 | #define SSM4567_SAI_CTRL_1_TDM_BLCKS_MASK (0x3 << 4) 53 | #define SSM4567_SAI_CTRL_1_TDM_BLCKS_32 (0x0 << 4) 54 | #define SSM4567_SAI_CTRL_1_TDM_BLCKS_48 (0x1 << 4) 55 | #define SSM4567_SAI_CTRL_1_TDM_BLCKS_64 (0x2 << 4) 56 | #define SSM4567_SAI_CTRL_1_FSYNC BIT(3) 57 | #define SSM4567_SAI_CTRL_1_LJ BIT(2) 58 | #define SSM4567_SAI_CTRL_1_TDM BIT(1) 59 | #define SSM4567_SAI_CTRL_1_PDM BIT(0) 60 | 61 | /* SAI_CTRL_2 */ 62 | #define SSM4567_SAI_CTRL_2_AUTO_SLOT BIT(3) 63 | #define SSM4567_SAI_CTRL_2_TDM_SLOT_MASK 0x7 64 | #define SSM4567_SAI_CTRL_2_TDM_SLOT(x) (x) -------------------------------------------------------------------------------- /ssm4567.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}") = "ssm4567", "ssm4567\ssm4567.vcxproj", "{36580C07-EDC3-4C2B-B45F-6AB017E01A5D}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssm4567 Package", "ssm4567 Package\ssm4567 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 2021 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. -------------------------------------------------------------------------------- /ssm4567/ssm4567.h: -------------------------------------------------------------------------------- 1 | #if !defined(_SSM4567_H_) 2 | #define _SSM4567_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 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | #include "spb.h" 23 | 24 | #define JACKDESC_RGB(r, g, b) \ 25 | ((COLORREF)((r << 16) | (g << 8) | (b))) 26 | 27 | // 28 | // String definitions 29 | // 30 | 31 | #define DRIVERNAME "ssm4567.sys: " 32 | 33 | #define SSM4567_POOL_TAG (ULONG) 'B343' 34 | 35 | #define true 1 36 | #define false 0 37 | 38 | #pragma pack(push,1) 39 | typedef struct _IntcSSTArg 40 | { 41 | int32_t chipModel; 42 | int32_t sstQuery; 43 | int32_t caller; 44 | int32_t querySize; 45 | 46 | #ifdef __GNUC__ 47 | char EndOfHeader[0]; 48 | #endif 49 | 50 | uint8_t deviceInD0; 51 | #ifdef __GNUC__ 52 | char EndOfPowerCfg[0]; 53 | #endif 54 | 55 | int32_t dword11; 56 | GUID guid; 57 | 58 | #ifdef __GNUC__ 59 | char EndOfGUID[0]; 60 | #endif 61 | uint8_t byte25; 62 | int32_t dword26; 63 | int32_t dword2A; 64 | int32_t dword2E; 65 | int32_t dword32; 66 | int32_t dword36; 67 | int32_t dword3A; 68 | int32_t dword3E; 69 | uint8_t byte42; 70 | uint8_t byte43; 71 | char padding[90]; //idk what this is for 72 | } IntcSSTArg, * PIntcSSTArg; 73 | #pragma pack(pop) 74 | 75 | typedef enum { 76 | CSAudioEndpointTypeDSP, 77 | CSAudioEndpointTypeSpeaker, 78 | CSAudioEndpointTypeHeadphone, 79 | CSAudioEndpointTypeMicArray, 80 | CSAudioEndpointTypeMicJack 81 | } CSAudioEndpointType; 82 | 83 | typedef enum { 84 | CSAudioEndpointRegister, 85 | CSAudioEndpointStart, 86 | CSAudioEndpointStop, 87 | CSAudioEndpointOverrideFormat 88 | } CSAudioEndpointRequest; 89 | 90 | typedef struct CSAUDIOFORMATOVERRIDE { 91 | UINT16 channels; 92 | UINT16 frequency; 93 | UINT16 bitsPerSample; 94 | UINT16 validBitsPerSample; 95 | BOOL force32BitOutputContainer; 96 | } CsAudioFormatOverride; 97 | 98 | typedef struct CSAUDIOARG { 99 | UINT32 argSz; 100 | CSAudioEndpointType endpointType; 101 | CSAudioEndpointRequest endpointRequest; 102 | union { 103 | CsAudioFormatOverride formatOverride; 104 | }; 105 | } CsAudioArg, * PCsAudioArg; 106 | 107 | typedef struct _SSM4567_CONTEXT 108 | { 109 | 110 | WDFDEVICE FxDevice; 111 | 112 | WDFQUEUE ReportQueue; 113 | 114 | SPB_CONTEXT I2CContext; 115 | 116 | BOOLEAN SetUID; 117 | INT32 UID; 118 | 119 | BOOLEAN DevicePoweredOn; 120 | INT8 IntcSSTStatus; 121 | 122 | WDFWORKITEM IntcSSTWorkItem; 123 | PCALLBACK_OBJECT IntcSSTHwMultiCodecCallback; 124 | PVOID IntcSSTCallbackObj; 125 | 126 | PCALLBACK_OBJECT CSAudioAPICallback; 127 | PVOID CSAudioAPICallbackObj; 128 | 129 | BOOL CSAudioManaged; 130 | 131 | IntcSSTArg sstArgTemp; 132 | 133 | } SSM4567_CONTEXT, *PSSM4567_CONTEXT; 134 | 135 | WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(SSM4567_CONTEXT, GetDeviceContext) 136 | 137 | // 138 | // Function definitions 139 | // 140 | 141 | DRIVER_INITIALIZE DriverEntry; 142 | 143 | EVT_WDF_DRIVER_UNLOAD Ssm4567DriverUnload; 144 | 145 | EVT_WDF_DRIVER_DEVICE_ADD Ssm4567EvtDeviceAdd; 146 | 147 | EVT_WDFDEVICE_WDM_IRP_PREPROCESS Ssm4567EvtWdmPreprocessMnQueryId; 148 | 149 | EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL Ssm4567EvtInternalDeviceControl; 150 | 151 | // 152 | // Helper macros 153 | // 154 | 155 | #define DEBUG_LEVEL_ERROR 1 156 | #define DEBUG_LEVEL_INFO 2 157 | #define DEBUG_LEVEL_VERBOSE 3 158 | 159 | #define DBG_INIT 1 160 | #define DBG_PNP 2 161 | #define DBG_IOCTL 4 162 | 163 | #if 0 164 | #define Ssm4567Print(dbglevel, dbgcatagory, fmt, ...) { \ 165 | if (Ssm4567DebugLevel >= dbglevel && \ 166 | (Ssm4567DebugCatagories && dbgcatagory)) \ 167 | { \ 168 | DbgPrint(DRIVERNAME); \ 169 | DbgPrint(fmt, __VA_ARGS__); \ 170 | } \ 171 | } 172 | #else 173 | #define Ssm4567Print(dbglevel, fmt, ...) { \ 174 | } 175 | #endif 176 | 177 | #endif -------------------------------------------------------------------------------- /ssm4567/ssm4567.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 | ssm4567 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.1 88 | 89 | 90 | 91 | 92 | true 93 | trace.h 94 | true 95 | false 96 | 97 | 98 | 1.0.1 99 | 100 | 101 | 102 | 103 | true 104 | trace.h 105 | true 106 | false 107 | 108 | 109 | 1.0.1 110 | 111 | 112 | 113 | 114 | true 115 | trace.h 116 | true 117 | false 118 | 119 | 120 | 1.0.1 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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /ssm4567 Package/ssm4567 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 | ssm4567_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 | -------------------------------------------------------------------------------- /ssm4567/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 "ssm4567.h" 22 | #include "spb.h" 23 | #include 24 | 25 | static ULONG Ssm4567DebugLevel = 100; 26 | static ULONG Ssm4567DebugCatagories = DBG_INIT || DBG_PNP || DBG_IOCTL; 27 | 28 | NTSTATUS 29 | SpbDoWriteDataSynchronously( 30 | IN SPB_CONTEXT* SpbContext, 31 | IN PVOID Data, 32 | IN ULONG Length 33 | ) 34 | /*++ 35 | 36 | Routine Description: 37 | 38 | This helper routine abstracts creating and sending an I/O 39 | request (I2C Write) to the Spb I/O target. 40 | 41 | Arguments: 42 | 43 | SpbContext - Pointer to the current device context 44 | Address - The I2C register address to write to 45 | Data - A buffer to receive the data at at the above address 46 | Length - The amount of data to be read from the above address 47 | 48 | Return Value: 49 | 50 | NTSTATUS Status indicating success or failure 51 | 52 | --*/ 53 | { 54 | PUCHAR buffer; 55 | ULONG length; 56 | WDFMEMORY memory; 57 | WDF_MEMORY_DESCRIPTOR memoryDescriptor; 58 | NTSTATUS status; 59 | 60 | length = Length; 61 | memory = NULL; 62 | 63 | if (length > DEFAULT_SPB_BUFFER_SIZE) 64 | { 65 | status = WdfMemoryCreate( 66 | WDF_NO_OBJECT_ATTRIBUTES, 67 | NonPagedPool, 68 | SSM4567_POOL_TAG, 69 | length, 70 | &memory, 71 | (PVOID*)&buffer); 72 | 73 | if (!NT_SUCCESS(status)) 74 | { 75 | Ssm4567Print( 76 | DEBUG_LEVEL_ERROR, 77 | DBG_IOCTL, 78 | "Error allocating memory for Spb write - %!STATUS!", 79 | status); 80 | goto exit; 81 | } 82 | 83 | WDF_MEMORY_DESCRIPTOR_INIT_HANDLE( 84 | &memoryDescriptor, 85 | memory, 86 | NULL); 87 | } 88 | else 89 | { 90 | buffer = (PUCHAR)WdfMemoryGetBuffer(SpbContext->WriteMemory, NULL); 91 | 92 | WDF_MEMORY_DESCRIPTOR_INIT_BUFFER( 93 | &memoryDescriptor, 94 | (PVOID)buffer, 95 | length); 96 | } 97 | 98 | RtlCopyMemory(buffer, Data, length); 99 | 100 | status = WdfIoTargetSendWriteSynchronously( 101 | SpbContext->SpbIoTarget, 102 | NULL, 103 | &memoryDescriptor, 104 | NULL, 105 | NULL, 106 | NULL); 107 | 108 | if (!NT_SUCCESS(status)) 109 | { 110 | Ssm4567Print( 111 | DEBUG_LEVEL_ERROR, 112 | DBG_IOCTL, 113 | "Error writing to Spb - %!STATUS!", 114 | status); 115 | goto exit; 116 | } 117 | 118 | exit: 119 | 120 | if (NULL != memory) 121 | { 122 | WdfObjectDelete(memory); 123 | } 124 | 125 | return status; 126 | } 127 | 128 | NTSTATUS 129 | SpbWriteDataSynchronously( 130 | IN SPB_CONTEXT* SpbContext, 131 | IN PVOID Data, 132 | IN ULONG Length 133 | ) 134 | /*++ 135 | 136 | Routine Description: 137 | 138 | This routine abstracts creating and sending an I/O 139 | request (I2C Write) to the Spb I/O target and utilizes 140 | a helper routine to do work inside of locked code. 141 | 142 | Arguments: 143 | 144 | SpbContext - Pointer to the current device context 145 | Address - The I2C register address to write to 146 | Data - A buffer to receive the data at at the above address 147 | Length - The amount of data to be read from the above address 148 | 149 | Return Value: 150 | 151 | NTSTATUS Status indicating success or failure 152 | 153 | --*/ 154 | { 155 | NTSTATUS status; 156 | 157 | WdfWaitLockAcquire(SpbContext->SpbLock, NULL); 158 | 159 | status = SpbDoWriteDataSynchronously( 160 | SpbContext, 161 | Data, 162 | Length); 163 | 164 | WdfWaitLockRelease(SpbContext->SpbLock); 165 | 166 | return status; 167 | } 168 | 169 | NTSTATUS 170 | SpbXferDataSynchronously( 171 | _In_ SPB_CONTEXT* SpbContext, 172 | _In_ PVOID SendData, 173 | _In_ ULONG SendLength, 174 | _In_reads_bytes_(Length) PVOID Data, 175 | _In_ ULONG Length 176 | ) 177 | /*++ 178 | Routine Description: 179 | This helper routine abstracts creating and sending an I/O 180 | request (I2C Read) to the Spb I/O target. 181 | Arguments: 182 | SpbContext - Pointer to the current device context 183 | Address - The I2C register address to read from 184 | Data - A buffer to receive the data at at the above address 185 | Length - The amount of data to be read from the above address 186 | Return Value: 187 | NTSTATUS Status indicating success or failure 188 | --*/ 189 | { 190 | PUCHAR buffer; 191 | WDFMEMORY memory; 192 | WDF_MEMORY_DESCRIPTOR memoryDescriptor; 193 | NTSTATUS status; 194 | ULONG_PTR bytesRead; 195 | 196 | WdfWaitLockAcquire(SpbContext->SpbLock, NULL); 197 | 198 | memory = NULL; 199 | status = STATUS_INVALID_PARAMETER; 200 | bytesRead = 0; 201 | 202 | // 203 | // Xfer transactions start by writing an address pointer 204 | // 205 | status = SpbDoWriteDataSynchronously( 206 | SpbContext, 207 | SendData, 208 | SendLength); 209 | 210 | if (!NT_SUCCESS(status)) 211 | { 212 | Ssm4567Print( 213 | DEBUG_LEVEL_ERROR, 214 | DBG_IOCTL, 215 | "Error setting address pointer for Spb read - %!STATUS!", 216 | status); 217 | goto exit; 218 | } 219 | 220 | if (Length > DEFAULT_SPB_BUFFER_SIZE) 221 | { 222 | status = WdfMemoryCreate( 223 | WDF_NO_OBJECT_ATTRIBUTES, 224 | NonPagedPool, 225 | SSM4567_POOL_TAG, 226 | Length, 227 | &memory, 228 | (PVOID*)&buffer); 229 | 230 | if (!NT_SUCCESS(status)) 231 | { 232 | Ssm4567Print( 233 | DEBUG_LEVEL_ERROR, 234 | DBG_IOCTL, 235 | "Error allocating memory for Spb read - %!STATUS!", 236 | status); 237 | goto exit; 238 | } 239 | 240 | WDF_MEMORY_DESCRIPTOR_INIT_HANDLE( 241 | &memoryDescriptor, 242 | memory, 243 | NULL); 244 | } 245 | else 246 | { 247 | buffer = (PUCHAR)WdfMemoryGetBuffer(SpbContext->ReadMemory, NULL); 248 | 249 | WDF_MEMORY_DESCRIPTOR_INIT_BUFFER( 250 | &memoryDescriptor, 251 | (PVOID)buffer, 252 | Length); 253 | } 254 | 255 | 256 | status = WdfIoTargetSendReadSynchronously( 257 | SpbContext->SpbIoTarget, 258 | NULL, 259 | &memoryDescriptor, 260 | NULL, 261 | NULL, 262 | &bytesRead); 263 | 264 | if (!NT_SUCCESS(status) || 265 | bytesRead != Length) 266 | { 267 | Ssm4567Print( 268 | DEBUG_LEVEL_ERROR, 269 | DBG_IOCTL, 270 | "Error reading from Spb - %!STATUS!", 271 | status); 272 | goto exit; 273 | } 274 | 275 | // 276 | // Copy back to the caller's buffer 277 | // 278 | RtlCopyMemory(Data, buffer, Length); 279 | 280 | exit: 281 | if (NULL != memory) 282 | { 283 | WdfObjectDelete(memory); 284 | } 285 | 286 | WdfWaitLockRelease(SpbContext->SpbLock); 287 | 288 | return status; 289 | } 290 | 291 | VOID 292 | SpbTargetDeinitialize( 293 | IN WDFDEVICE FxDevice, 294 | IN SPB_CONTEXT* SpbContext 295 | ) 296 | /*++ 297 | 298 | Routine Description: 299 | 300 | This helper routine is used to free any members added to the SPB_CONTEXT, 301 | note the SPB I/O target is parented to the device and will be 302 | closed and free'd when the device is removed. 303 | 304 | Arguments: 305 | 306 | FxDevice - Handle to the framework device object 307 | SpbContext - Pointer to the current device context 308 | 309 | Return Value: 310 | 311 | NTSTATUS Status indicating success or failure 312 | 313 | --*/ 314 | { 315 | UNREFERENCED_PARAMETER(FxDevice); 316 | UNREFERENCED_PARAMETER(SpbContext); 317 | 318 | // 319 | // Free any SPB_CONTEXT allocations here 320 | // 321 | if (SpbContext->SpbLock != NULL) 322 | { 323 | WdfObjectDelete(SpbContext->SpbLock); 324 | } 325 | 326 | if (SpbContext->ReadMemory != NULL) 327 | { 328 | WdfObjectDelete(SpbContext->ReadMemory); 329 | } 330 | 331 | if (SpbContext->WriteMemory != NULL) 332 | { 333 | WdfObjectDelete(SpbContext->WriteMemory); 334 | } 335 | } 336 | 337 | NTSTATUS 338 | SpbTargetInitialize( 339 | IN WDFDEVICE FxDevice, 340 | IN SPB_CONTEXT* SpbContext 341 | ) 342 | /*++ 343 | 344 | Routine Description: 345 | 346 | This helper routine opens the Spb I/O target and 347 | initializes a request object used for the lifetime 348 | of communication between this driver and Spb. 349 | 350 | Arguments: 351 | 352 | FxDevice - Handle to the framework device object 353 | SpbContext - Pointer to the current device context 354 | 355 | Return Value: 356 | 357 | NTSTATUS Status indicating success or failure 358 | 359 | --*/ 360 | { 361 | WDF_OBJECT_ATTRIBUTES objectAttributes; 362 | WDF_IO_TARGET_OPEN_PARAMS openParams; 363 | UNICODE_STRING spbDeviceName; 364 | WCHAR spbDeviceNameBuffer[RESOURCE_HUB_PATH_SIZE]; 365 | NTSTATUS status; 366 | 367 | WDF_OBJECT_ATTRIBUTES_INIT(&objectAttributes); 368 | objectAttributes.ParentObject = FxDevice; 369 | 370 | status = WdfIoTargetCreate( 371 | FxDevice, 372 | &objectAttributes, 373 | &SpbContext->SpbIoTarget); 374 | 375 | if (!NT_SUCCESS(status)) 376 | { 377 | Ssm4567Print( 378 | DEBUG_LEVEL_ERROR, 379 | DBG_IOCTL, 380 | "Error creating IoTarget object - %!STATUS!", 381 | status); 382 | 383 | WdfObjectDelete(SpbContext->SpbIoTarget); 384 | goto exit; 385 | } 386 | 387 | RtlInitEmptyUnicodeString( 388 | &spbDeviceName, 389 | spbDeviceNameBuffer, 390 | sizeof(spbDeviceNameBuffer)); 391 | 392 | status = RESOURCE_HUB_CREATE_PATH_FROM_ID( 393 | &spbDeviceName, 394 | SpbContext->I2cResHubId.LowPart, 395 | SpbContext->I2cResHubId.HighPart); 396 | 397 | if (!NT_SUCCESS(status)) 398 | { 399 | Ssm4567Print( 400 | DEBUG_LEVEL_ERROR, 401 | DBG_IOCTL, 402 | "Error creating Spb resource hub path string - %!STATUS!", 403 | status); 404 | goto exit; 405 | } 406 | 407 | WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME( 408 | &openParams, 409 | &spbDeviceName, 410 | (GENERIC_READ | GENERIC_WRITE)); 411 | 412 | openParams.ShareAccess = 0; 413 | openParams.CreateDisposition = FILE_OPEN; 414 | openParams.FileAttributes = FILE_ATTRIBUTE_NORMAL; 415 | 416 | status = WdfIoTargetOpen(SpbContext->SpbIoTarget, &openParams); 417 | 418 | if (!NT_SUCCESS(status)) 419 | { 420 | Ssm4567Print( 421 | DEBUG_LEVEL_ERROR, 422 | DBG_IOCTL, 423 | "Error opening Spb target for communication - %!STATUS!", 424 | status); 425 | goto exit; 426 | } 427 | 428 | // 429 | // Allocate some fixed-size buffers from NonPagedPool for typical 430 | // Spb transaction sizes to avoid pool fragmentation in most cases 431 | // 432 | status = WdfMemoryCreate( 433 | WDF_NO_OBJECT_ATTRIBUTES, 434 | NonPagedPool, 435 | SSM4567_POOL_TAG, 436 | DEFAULT_SPB_BUFFER_SIZE, 437 | &SpbContext->WriteMemory, 438 | NULL); 439 | 440 | if (!NT_SUCCESS(status)) 441 | { 442 | Ssm4567Print( 443 | DEBUG_LEVEL_ERROR, 444 | DBG_IOCTL, 445 | "Error allocating default memory for Spb write - %!STATUS!", 446 | status); 447 | goto exit; 448 | } 449 | 450 | status = WdfMemoryCreate( 451 | WDF_NO_OBJECT_ATTRIBUTES, 452 | NonPagedPool, 453 | SSM4567_POOL_TAG, 454 | DEFAULT_SPB_BUFFER_SIZE, 455 | &SpbContext->ReadMemory, 456 | NULL); 457 | 458 | if (!NT_SUCCESS(status)) 459 | { 460 | Ssm4567Print( 461 | DEBUG_LEVEL_ERROR, 462 | DBG_IOCTL, 463 | "Error allocating default memory for Spb read - %!STATUS!", 464 | status); 465 | goto exit; 466 | } 467 | 468 | // 469 | // Allocate a waitlock to guard access to the default buffers 470 | // 471 | status = WdfWaitLockCreate( 472 | WDF_NO_OBJECT_ATTRIBUTES, 473 | &SpbContext->SpbLock); 474 | 475 | if (!NT_SUCCESS(status)) 476 | { 477 | Ssm4567Print( 478 | DEBUG_LEVEL_ERROR, 479 | DBG_IOCTL, 480 | "Error creating Spb Waitlock - %!STATUS!", 481 | status); 482 | goto exit; 483 | } 484 | 485 | exit: 486 | 487 | if (!NT_SUCCESS(status)) 488 | { 489 | SpbTargetDeinitialize(FxDevice, SpbContext); 490 | } 491 | 492 | return status; 493 | } -------------------------------------------------------------------------------- /ssm4567/ssm4567.c: -------------------------------------------------------------------------------- 1 | #include "ssm4567.h" 2 | #include "registers.h" 3 | 4 | #define bool int 5 | 6 | static ULONG Ssm4567DebugLevel = 100; 7 | static ULONG Ssm4567DebugCatagories = 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 | Ssm4567Print(DEBUG_LEVEL_INFO, DBG_INIT, 20 | "Driver Entry\n"); 21 | 22 | WDF_DRIVER_CONFIG_INIT(&config, Ssm4567EvtDeviceAdd); 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 | Ssm4567Print(DEBUG_LEVEL_ERROR, DBG_INIT, 40 | "WdfDriverCreate failed with status 0x%x\n", status); 41 | } 42 | 43 | return status; 44 | } 45 | 46 | NTSTATUS ssm4567_reg_read( 47 | _In_ PSSM4567_CONTEXT pDevice, 48 | uint8_t reg, 49 | uint8_t* data 50 | ) { 51 | uint8_t raw_data = 0; 52 | NTSTATUS status = SpbXferDataSynchronously(&pDevice->I2CContext, ®, sizeof(uint8_t), &raw_data, sizeof(uint8_t)); 53 | *data = raw_data; 54 | return status; 55 | } 56 | 57 | NTSTATUS ssm4567_reg_write( 58 | _In_ PSSM4567_CONTEXT pDevice, 59 | uint8_t reg, 60 | uint8_t data 61 | ) { 62 | uint8_t buf[2]; 63 | buf[0] = reg; 64 | buf[1] = data; 65 | return SpbWriteDataSynchronously(&pDevice->I2CContext, buf, sizeof(buf)); 66 | } 67 | 68 | NTSTATUS ssm4567_reg_update( 69 | _In_ PSSM4567_CONTEXT pDevice, 70 | uint8_t reg, 71 | uint8_t mask, 72 | uint8_t val 73 | ) { 74 | uint8_t tmp = 0, orig = 0; 75 | 76 | NTSTATUS status = ssm4567_reg_read(pDevice, reg, &orig); 77 | if (!NT_SUCCESS(status)) { 78 | return status; 79 | } 80 | 81 | tmp = orig & ~mask; 82 | tmp |= val & mask; 83 | 84 | if (tmp != orig) { 85 | status = ssm4567_reg_write(pDevice, reg, tmp); 86 | } 87 | return status; 88 | } 89 | 90 | NTSTATUS ssm4567_set_power( 91 | _In_ PSSM4567_CONTEXT pDevice, 92 | _In_ BOOLEAN enable 93 | ) { 94 | NTSTATUS status; 95 | if (enable) { 96 | status = ssm4567_reg_write(pDevice, SSM4567_REG_SOFT_RESET, 0x00); 97 | if (!NT_SUCCESS(status)) { 98 | return status; 99 | } 100 | } 101 | 102 | status = ssm4567_reg_update(pDevice, SSM4567_REG_POWER_CTRL, 103 | SSM4567_POWER_SPWDN, enable ? 0 : SSM4567_POWER_SPWDN); 104 | return status; 105 | } 106 | 107 | NTSTATUS 108 | GetDeviceUID( 109 | _In_ WDFDEVICE FxDevice, 110 | _In_ PINT32 PUID 111 | ) 112 | { 113 | NTSTATUS status = STATUS_ACPI_NOT_INITIALIZED; 114 | ACPI_EVAL_INPUT_BUFFER_EX inputBuffer; 115 | RtlZeroMemory(&inputBuffer, sizeof(inputBuffer)); 116 | 117 | inputBuffer.Signature = ACPI_EVAL_INPUT_BUFFER_SIGNATURE_EX; 118 | status = RtlStringCchPrintfA( 119 | inputBuffer.MethodName, 120 | sizeof(inputBuffer.MethodName), 121 | "_UID" 122 | ); 123 | if (!NT_SUCCESS(status)) { 124 | return status; 125 | } 126 | 127 | WDFMEMORY outputMemory; 128 | PACPI_EVAL_OUTPUT_BUFFER outputBuffer; 129 | size_t outputArgumentBufferSize = 32; 130 | size_t outputBufferSize = FIELD_OFFSET(ACPI_EVAL_OUTPUT_BUFFER, Argument) + outputArgumentBufferSize; 131 | 132 | WDF_OBJECT_ATTRIBUTES attributes; 133 | WDF_OBJECT_ATTRIBUTES_INIT(&attributes); 134 | attributes.ParentObject = FxDevice; 135 | 136 | status = WdfMemoryCreate(&attributes, 137 | NonPagedPoolNx, 138 | 0, 139 | outputBufferSize, 140 | &outputMemory, 141 | (PVOID*)&outputBuffer); 142 | if (!NT_SUCCESS(status)) { 143 | return status; 144 | } 145 | 146 | RtlZeroMemory(outputBuffer, outputBufferSize); 147 | 148 | WDF_MEMORY_DESCRIPTOR inputMemDesc; 149 | WDF_MEMORY_DESCRIPTOR outputMemDesc; 150 | WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&inputMemDesc, &inputBuffer, (ULONG)sizeof(inputBuffer)); 151 | WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&outputMemDesc, outputMemory, NULL); 152 | 153 | status = WdfIoTargetSendInternalIoctlSynchronously( 154 | WdfDeviceGetIoTarget(FxDevice), 155 | NULL, 156 | IOCTL_ACPI_EVAL_METHOD_EX, 157 | &inputMemDesc, 158 | &outputMemDesc, 159 | NULL, 160 | NULL 161 | ); 162 | if (!NT_SUCCESS(status)) { 163 | goto Exit; 164 | } 165 | 166 | if (outputBuffer->Signature != ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE) { 167 | goto Exit; 168 | } 169 | 170 | if (outputBuffer->Count < 1) { 171 | goto Exit; 172 | } 173 | 174 | uint32_t uid; 175 | if (outputBuffer->Argument[0].DataLength >= 4) { 176 | uid = *(uint32_t*)outputBuffer->Argument->Data; 177 | } 178 | else if (outputBuffer->Argument[0].DataLength >= 2) { 179 | uid = *(uint16_t*)outputBuffer->Argument->Data; 180 | } 181 | else { 182 | uid = *(uint8_t*)outputBuffer->Argument->Data; 183 | } 184 | if (PUID) { 185 | *PUID = uid; 186 | } 187 | else { 188 | status = STATUS_ACPI_INVALID_ARGUMENT; 189 | } 190 | Exit: 191 | if (outputMemory != WDF_NO_HANDLE) { 192 | WdfObjectDelete(outputMemory); 193 | } 194 | return status; 195 | } 196 | 197 | int IntCSSTArg2 = 1; 198 | int CsAudioArg2 = 1; 199 | 200 | VOID 201 | UpdateIntcSSTStatus( 202 | IN PSSM4567_CONTEXT pDevice, 203 | int sstStatus 204 | ) { 205 | IntcSSTArg* SSTArg = &pDevice->sstArgTemp; 206 | RtlZeroMemory(SSTArg, sizeof(IntcSSTArg)); 207 | 208 | if (pDevice->IntcSSTHwMultiCodecCallback) { 209 | if (sstStatus != 1 || pDevice->IntcSSTStatus) { 210 | SSTArg->chipModel = 4567; 211 | SSTArg->caller = 0xc0000165; //gmaxcodec 212 | if (sstStatus) { 213 | if (sstStatus == 1) { 214 | if (!pDevice->IntcSSTStatus) { 215 | return; 216 | } 217 | SSTArg->sstQuery = 12; 218 | SSTArg->dword11 = 2; 219 | SSTArg->querySize = 21; 220 | } 221 | else { 222 | SSTArg->sstQuery = 11; 223 | SSTArg->querySize = 20; 224 | } 225 | 226 | SSTArg->deviceInD0 = (pDevice->DevicePoweredOn != 0); 227 | } 228 | else { 229 | SSTArg->sstQuery = 10; 230 | SSTArg->querySize = 18; 231 | SSTArg->deviceInD0 = 1; 232 | } 233 | ExNotifyCallback(pDevice->IntcSSTHwMultiCodecCallback, SSTArg, &IntCSSTArg2); 234 | } 235 | } 236 | } 237 | 238 | VOID 239 | IntcSSTWorkItemFunc( 240 | IN WDFWORKITEM WorkItem 241 | ) 242 | { 243 | WDFDEVICE Device = (WDFDEVICE)WdfWorkItemGetParentObject(WorkItem); 244 | PSSM4567_CONTEXT pDevice = GetDeviceContext(Device); 245 | 246 | UpdateIntcSSTStatus(pDevice, 0); 247 | } 248 | 249 | DEFINE_GUID(GUID_SST_RTK_1, 250 | 0xDFF21CE2, 0xF70F, 0x11D0, 0xB9, 0x17, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96); //Headphones 251 | DEFINE_GUID(GUID_SST_RTK_2, 252 | 0xDFF21CE1, 0xF70F, 0x11D0, 0xB9, 0x17, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96); //InsideMobileLid 253 | DEFINE_GUID(GUID_SST_RTK_3, 254 | 0xDFF21BE1, 0xF70F, 0x11D0, 0xB9, 0x17, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96); //Also InsideMobileLid? 255 | DEFINE_GUID(GUID_SST_RTK_4, 256 | 0xDFF21FE3, 0xF70F, 0x11D0, 0xB9, 0x17, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96); //Line out 257 | 258 | VOID 259 | IntcSSTCallbackFunction( 260 | IN WDFWORKITEM WorkItem, 261 | IntcSSTArg* SSTArgs, 262 | PVOID Argument2 263 | ) { 264 | if (!WorkItem) { 265 | return; 266 | } 267 | WDFDEVICE Device = (WDFDEVICE)WdfWorkItemGetParentObject(WorkItem); 268 | PSSM4567_CONTEXT pDevice = GetDeviceContext(Device); 269 | 270 | if (Argument2 == &IntCSSTArg2) { 271 | return; 272 | } 273 | 274 | //gmaxCodec checks that querySize is greater than 0x10 first thing 275 | if (SSTArgs->querySize <= 0x10) { 276 | return; 277 | } 278 | 279 | //Intel Caller: 0xc00000a3 (STATUS_DEVICE_NOT_READY) 280 | //GMax Caller: 0xc0000165 281 | 282 | if (SSTArgs->chipModel == 4567) { 283 | /* 284 | 285 | Gmax (no SST driver): 286 | init: sstQuery = 10 287 | dwordc = 18 288 | deviceInD0 = 1 289 | 290 | stop: sstQuery = 11 291 | dwordc = 20 292 | deviceInD0 = 0 293 | */ 294 | 295 | /* 296 | 297 | Gmax (SST driver) 298 | post-init: sstQuery = 12 299 | dwordc = 21 300 | dword11 = 2 301 | 302 | */ 303 | if (Argument2 != &IntCSSTArg2) { //Intel SST is calling us 304 | bool checkCaller = (SSTArgs->caller != 0); 305 | 306 | if (SSTArgs->sstQuery == 11) { 307 | if (SSTArgs->querySize >= 0x15) { 308 | if (SSTArgs->deviceInD0 == 0) { 309 | pDevice->IntcSSTStatus = 0; //SST is inactive 310 | SSTArgs->caller = STATUS_SUCCESS; 311 | //mark device as inactive? 312 | } 313 | else { 314 | SSTArgs->caller = STATUS_INVALID_PARAMETER_5; 315 | } 316 | } 317 | else { 318 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 319 | } 320 | } 321 | 322 | //SST Query 1: 323 | // sstQuery: 10, querySize: 0x9e, dword11: 0x0 324 | // deviceInD0: 0x1, byte25: 0 325 | 326 | if (SSTArgs->sstQuery == 10) { //gmax responds no matter what 327 | if (SSTArgs->querySize >= 0x15) { 328 | if (SSTArgs->deviceInD0 == 1) { 329 | pDevice->IntcSSTStatus = 1; 330 | SSTArgs->caller = STATUS_SUCCESS; 331 | //mark device as active?? 332 | } 333 | else { 334 | SSTArgs->caller = STATUS_INVALID_PARAMETER_5; 335 | } 336 | } 337 | else { 338 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 339 | } 340 | } 341 | 342 | //SST Query 2: 343 | // sstQuery: 2048, querySize: 0x9e, dword11: 0x00 344 | // deviceInD0: 0, byte25: 0 345 | 346 | if (SSTArgs->sstQuery == 2048) { 347 | if (SSTArgs->querySize >= 0x11) { 348 | SSTArgs->deviceInD0 = 1; 349 | SSTArgs->caller = STATUS_SUCCESS; 350 | } 351 | else { 352 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 353 | } 354 | } 355 | 356 | //SST Query 3: 357 | // sstQuery: 2051, querySize: 0x9e, dword11: 0x00 358 | // deviceInD0: 0, byte25: 0 359 | 360 | if (SSTArgs->sstQuery == 2051) { 361 | if (SSTArgs->querySize >= 0x9E) { 362 | if (SSTArgs->deviceInD0) { 363 | SSTArgs->caller = STATUS_INVALID_PARAMETER; 364 | } 365 | else { 366 | 367 | SSTArgs->deviceInD0 = 0; 368 | SSTArgs->dword11 = (1 << 24) | 0; 369 | 370 | SSTArgs->guid = GUID_SST_RTK_2; 371 | 372 | SSTArgs->byte25 = 1; 373 | SSTArgs->dword26 = KSAUDIO_SPEAKER_STEREO; //Channel Mapping 374 | SSTArgs->dword2A = JACKDESC_RGB(255, 174, 201); //Color (gmax sets to 0) 375 | SSTArgs->dword2E = eConnTypeOtherAnalog; //EPcxConnectionType 376 | SSTArgs->dword32 = eGeoLocInsideMobileLid; //EPcxGeoLocation 377 | SSTArgs->dword36 = eGenLocInternal; //genLocation? 378 | SSTArgs->dword3A = ePortConnIntegratedDevice; //portConnection? 379 | SSTArgs->dword3E = 1; //isConnected? 380 | SSTArgs->byte42 = 0; 381 | SSTArgs->byte43 = 0; 382 | SSTArgs->caller = STATUS_SUCCESS; 383 | } 384 | } 385 | else { 386 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 387 | } 388 | } 389 | 390 | //This is the minimum for SST to initialize. Everything after is extra 391 | //SST Query 4: 392 | // sstQuery: 2054, querySize: 0x9e, dword11: 0x00 393 | // deviceInD0: 0, byte25: 0 394 | if (SSTArgs->sstQuery == 2054) { 395 | if (SSTArgs->querySize >= 0x9E) { 396 | if (SSTArgs->deviceInD0) { 397 | SSTArgs->caller = STATUS_INVALID_PARAMETER; 398 | } 399 | else { 400 | SSTArgs->dword11 = 2; 401 | SSTArgs->caller = STATUS_SUCCESS; 402 | } 403 | } 404 | else { 405 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 406 | } 407 | } 408 | 409 | //SST Query 5: 410 | // sstQuery: 2055, querySize: 0x9e, dword11: 0x00 411 | // deviceInD0: 0, byte25: 0 412 | 413 | if (SSTArgs->sstQuery == 2055) { 414 | if (SSTArgs->querySize < 0x22) { 415 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 416 | } 417 | else { 418 | SSTArgs->caller = STATUS_NOT_SUPPORTED; 419 | } 420 | } 421 | 422 | //SST Query 6: 423 | // sstQuery: 13, querySize: 0x9e, dword11: 0x00 424 | // deviceInD0: 1, byte25: 0 425 | if (SSTArgs->sstQuery == 13) { 426 | if (SSTArgs->querySize >= 0x14) { 427 | if (SSTArgs->deviceInD0) { 428 | pDevice->IntcSSTStatus = 1; 429 | SSTArgs->caller = STATUS_SUCCESS; 430 | 431 | //UpdateIntcSSTStatus(pDevice, 1); 432 | } 433 | else { 434 | SSTArgs->caller = STATUS_INVALID_PARAMETER; 435 | } 436 | } 437 | else { 438 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 439 | } 440 | } 441 | 442 | //SST Query 7: 443 | // sstQuery: 2064, querySize: 0x9e, dword11: 0x00 444 | // deviceInD0: 0, byte25: 0 445 | if (SSTArgs->sstQuery == 2064) { 446 | if (SSTArgs->querySize >= 0x19) { 447 | if (!SSTArgs->deviceInD0) { 448 | unsigned int data1 = SSTArgs->guid.Data1; 449 | //DbgPrint("data1: %d\n", data1); 450 | if (data1 != -1 && data1 < 1) { 451 | SSTArgs->dword11 = 0; //no feedback on ssm4567 452 | SSTArgs->caller = STATUS_SUCCESS; 453 | } 454 | else { 455 | SSTArgs->caller = STATUS_INVALID_PARAMETER; 456 | } 457 | } 458 | else { 459 | SSTArgs->caller = STATUS_INVALID_PARAMETER; 460 | } 461 | } 462 | else { 463 | SSTArgs->caller = STATUS_BUFFER_TOO_SMALL; 464 | } 465 | } 466 | 467 | if (checkCaller) { 468 | if (SSTArgs->caller != STATUS_SUCCESS) { 469 | //DbgPrint("Warning: Returned error 0x%x; query: %d\n", SSTArgs->caller, SSTArgs->sstQuery); 470 | } 471 | } 472 | } 473 | } 474 | else { 475 | //On SST Init: chipModel = 0, caller = 0xc00000a3, sstQuery = 10, dwordc: 0x9e 476 | 477 | if (SSTArgs->sstQuery == 10 && pDevice->IntcSSTWorkItem) { 478 | WdfWorkItemEnqueue(pDevice->IntcSSTWorkItem); //SST driver was installed after us... 479 | } 480 | } 481 | } 482 | 483 | NTSTATUS 484 | StartCodec( 485 | PSSM4567_CONTEXT pDevice 486 | ) { 487 | NTSTATUS status = STATUS_SUCCESS; 488 | if (!pDevice->SetUID) { 489 | status = STATUS_INVALID_DEVICE_STATE; 490 | return status; 491 | } 492 | 493 | //Power on Amp 494 | status = ssm4567_set_power(pDevice, TRUE); 495 | if (!NT_SUCCESS(status)) { 496 | return status; 497 | } 498 | 499 | //Set Format 500 | uint8_t fmt = SSM4567_SAI_CTRL_1_BCLK | SSM4567_SAI_CTRL_1_TDM; 501 | 502 | status = ssm4567_reg_update(pDevice, SSM4567_REG_SAI_CTRL_1, 503 | SSM4567_SAI_CTRL_1_BCLK | 504 | SSM4567_SAI_CTRL_1_FSYNC | 505 | SSM4567_SAI_CTRL_1_LJ | 506 | SSM4567_SAI_CTRL_1_TDM | 507 | SSM4567_SAI_CTRL_1_PDM, 508 | fmt); 509 | if (!NT_SUCCESS(status)) { 510 | return status; 511 | } 512 | 513 | unsigned int rate = 48000; //48Khz 24 bit for SST 514 | uint8_t format = SSM4567_DAC_FS_32000_48000; 515 | if (rate >= 8000 && rate <= 12000) 516 | format = SSM4567_DAC_FS_8000_12000; 517 | else if (rate >= 16000 && rate <= 24000) 518 | format = SSM4567_DAC_FS_16000_24000; 519 | else if (rate >= 32000 && rate <= 48000) 520 | format = SSM4567_DAC_FS_32000_48000; 521 | else if (rate >= 64000 && rate <= 96000) 522 | format = SSM4567_DAC_FS_64000_96000; 523 | else if (rate >= 128000 && rate <= 192000) 524 | format = SSM4567_DAC_FS_128000_192000; 525 | status = ssm4567_reg_update(pDevice, SSM4567_REG_DAC_CTRL, 526 | SSM4567_DAC_FS_MASK, 527 | format); 528 | if (!NT_SUCCESS(status)) { 529 | return status; 530 | } 531 | 532 | //Set TDM Slot 533 | uint8_t slot = (uint8_t)pDevice->UID; 534 | status = ssm4567_reg_update(pDevice, SSM4567_REG_SAI_CTRL_2, SSM4567_SAI_CTRL_2_AUTO_SLOT | SSM4567_SAI_CTRL_2_TDM_SLOT_MASK, SSM4567_SAI_CTRL_2_TDM_SLOT(slot)); 535 | if (!NT_SUCCESS(status)) { 536 | return status; 537 | } 538 | 539 | //Set width to 48 540 | status = ssm4567_reg_update(pDevice, SSM4567_REG_SAI_CTRL_1, SSM4567_SAI_CTRL_1_TDM_BLCKS_MASK, SSM4567_SAI_CTRL_1_TDM_BLCKS_48); 541 | if (!NT_SUCCESS(status)) { 542 | return status; 543 | } 544 | 545 | //Ensure unmuted 546 | status = ssm4567_reg_update(pDevice, SSM4567_REG_DAC_CTRL, SSM4567_DAC_MUTE, 0); 547 | if (!NT_SUCCESS(status)) { 548 | return status; 549 | } 550 | 551 | //Enable high pass filter & low power mode 552 | status = ssm4567_reg_update(pDevice, SSM4567_REG_DAC_CTRL, SSM4567_DAC_HPF | SSM4567_DAC_LPM, SSM4567_DAC_HPF | SSM4567_DAC_LPM); 553 | if (!NT_SUCCESS(status)) { 554 | return status; 555 | } 556 | 557 | //Enable Amp Boost 558 | status = ssm4567_reg_update(pDevice, SSM4567_REG_POWER_CTRL, SSM4567_POWER_BOOST_PWDN, 0); 559 | if (!NT_SUCCESS(status)) { 560 | return status; 561 | } 562 | 563 | //Disable Battery/Voltage/Current Sense 564 | status = ssm4567_reg_update(pDevice, SSM4567_REG_POWER_CTRL, 565 | SSM4567_POWER_BSNS_PWDN | 566 | SSM4567_POWER_VSNS_PWDN | 567 | SSM4567_POWER_ISNS_PWDN, 568 | SSM4567_POWER_BSNS_PWDN | 569 | SSM4567_POWER_VSNS_PWDN | 570 | SSM4567_POWER_ISNS_PWDN); 571 | if (!NT_SUCCESS(status)) { 572 | return status; 573 | } 574 | 575 | //Set Default Volume 576 | status = ssm4567_reg_update(pDevice, SSM4567_REG_DAC_VOLUME, 0xFF, 0x40); //0x40 = 0 db 577 | if (!NT_SUCCESS(status)) { 578 | return status; 579 | } 580 | 581 | /*for (int i = 0; i <= 0x16; i++) { 582 | unsigned int data; 583 | if (NT_SUCCESS(ssm4567_reg_read(pDevice, i, &data))) { 584 | DbgPrint("Reg 0x%x: 0x%x\n", i, data); 585 | } 586 | }*/ 587 | 588 | pDevice->DevicePoweredOn = TRUE; 589 | return status; 590 | } 591 | 592 | NTSTATUS 593 | StopCodec( 594 | PSSM4567_CONTEXT pDevice 595 | ) { 596 | NTSTATUS status; 597 | status = ssm4567_set_power(pDevice, FALSE); 598 | if (!NT_SUCCESS(status)) { 599 | return status; 600 | } 601 | 602 | pDevice->DevicePoweredOn = FALSE; 603 | return status; 604 | } 605 | 606 | VOID 607 | CSAudioRegisterEndpoint( 608 | PSSM4567_CONTEXT pDevice 609 | ) { 610 | CsAudioArg arg; 611 | RtlZeroMemory(&arg, sizeof(CsAudioArg)); 612 | arg.argSz = sizeof(CsAudioArg); 613 | arg.endpointType = CSAudioEndpointTypeSpeaker; 614 | arg.endpointRequest = CSAudioEndpointRegister; 615 | ExNotifyCallback(pDevice->CSAudioAPICallback, &arg, &CsAudioArg2); 616 | } 617 | 618 | VOID 619 | CsAudioCallbackFunction( 620 | IN PSSM4567_CONTEXT pDevice, 621 | CsAudioArg* arg, 622 | PVOID Argument2 623 | ) { 624 | if (!pDevice) { 625 | return; 626 | } 627 | 628 | if (Argument2 == &CsAudioArg2) { 629 | return; 630 | } 631 | 632 | pDevice->CSAudioManaged = TRUE; 633 | 634 | CsAudioArg localArg; 635 | RtlZeroMemory(&localArg, sizeof(CsAudioArg)); 636 | RtlCopyMemory(&localArg, arg, min(arg->argSz, sizeof(CsAudioArg))); 637 | 638 | if (localArg.endpointType == CSAudioEndpointTypeDSP && localArg.endpointRequest == CSAudioEndpointRegister) { 639 | CSAudioRegisterEndpoint(pDevice); 640 | } 641 | else if (localArg.endpointType != CSAudioEndpointTypeSpeaker) { 642 | return; 643 | } 644 | 645 | if (localArg.endpointRequest == CSAudioEndpointStop) { 646 | StopCodec(pDevice); 647 | } 648 | if (localArg.endpointRequest == CSAudioEndpointStart) { 649 | StartCodec(pDevice); 650 | } 651 | } 652 | 653 | NTSTATUS 654 | OnPrepareHardware( 655 | _In_ WDFDEVICE FxDevice, 656 | _In_ WDFCMRESLIST FxResourcesRaw, 657 | _In_ WDFCMRESLIST FxResourcesTranslated 658 | ) 659 | /*++ 660 | 661 | Routine Description: 662 | 663 | This routine caches the SPB resource connection ID. 664 | 665 | Arguments: 666 | 667 | FxDevice - a handle to the framework device object 668 | FxResourcesRaw - list of translated hardware resources that 669 | the PnP manager has assigned to the device 670 | FxResourcesTranslated - list of raw hardware resources that 671 | the PnP manager has assigned to the device 672 | 673 | Return Value: 674 | 675 | Status 676 | 677 | --*/ 678 | { 679 | PSSM4567_CONTEXT pDevice = GetDeviceContext(FxDevice); 680 | BOOLEAN fSpbResourceFound = FALSE; 681 | NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES; 682 | 683 | UNREFERENCED_PARAMETER(FxResourcesRaw); 684 | 685 | // 686 | // Parse the peripheral's resources. 687 | // 688 | 689 | ULONG resourceCount = WdfCmResourceListGetCount(FxResourcesTranslated); 690 | 691 | for (ULONG i = 0; i < resourceCount; i++) 692 | { 693 | PCM_PARTIAL_RESOURCE_DESCRIPTOR pDescriptor; 694 | UCHAR Class; 695 | UCHAR Type; 696 | 697 | pDescriptor = WdfCmResourceListGetDescriptor( 698 | FxResourcesTranslated, i); 699 | 700 | switch (pDescriptor->Type) 701 | { 702 | case CmResourceTypeConnection: 703 | // 704 | // Look for I2C or SPI resource and save connection ID. 705 | // 706 | Class = pDescriptor->u.Connection.Class; 707 | Type = pDescriptor->u.Connection.Type; 708 | if (Class == CM_RESOURCE_CONNECTION_CLASS_SERIAL && 709 | Type == CM_RESOURCE_CONNECTION_TYPE_SERIAL_I2C) 710 | { 711 | if (fSpbResourceFound == FALSE) 712 | { 713 | status = STATUS_SUCCESS; 714 | pDevice->I2CContext.I2cResHubId.LowPart = pDescriptor->u.Connection.IdLowPart; 715 | pDevice->I2CContext.I2cResHubId.HighPart = pDescriptor->u.Connection.IdHighPart; 716 | fSpbResourceFound = TRUE; 717 | } 718 | else 719 | { 720 | } 721 | } 722 | break; 723 | default: 724 | // 725 | // Ignoring all other resource types. 726 | // 727 | break; 728 | } 729 | } 730 | 731 | // 732 | // An SPB resource is required. 733 | // 734 | 735 | if (fSpbResourceFound == FALSE) 736 | { 737 | status = STATUS_NOT_FOUND; 738 | } 739 | 740 | status = SpbTargetInitialize(FxDevice, &pDevice->I2CContext); 741 | 742 | if (!NT_SUCCESS(status)) 743 | { 744 | return status; 745 | } 746 | 747 | status = GetDeviceUID(FxDevice, &pDevice->UID); 748 | if (!NT_SUCCESS(status)) { 749 | return status; 750 | } 751 | pDevice->SetUID = TRUE; 752 | 753 | if (pDevice->UID == 0) { 754 | WDF_OBJECT_ATTRIBUTES attributes; 755 | WDF_WORKITEM_CONFIG workitemConfig; 756 | 757 | WDF_OBJECT_ATTRIBUTES_INIT(&attributes); 758 | WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&attributes, SSM4567_CONTEXT); 759 | attributes.ParentObject = FxDevice; 760 | WDF_WORKITEM_CONFIG_INIT(&workitemConfig, IntcSSTWorkItemFunc); 761 | status = WdfWorkItemCreate(&workitemConfig, 762 | &attributes, 763 | &pDevice->IntcSSTWorkItem); 764 | if (!NT_SUCCESS(status)) 765 | { 766 | return status; 767 | } 768 | } 769 | 770 | return status; 771 | } 772 | 773 | NTSTATUS 774 | OnReleaseHardware( 775 | _In_ WDFDEVICE FxDevice, 776 | _In_ WDFCMRESLIST FxResourcesTranslated 777 | ) 778 | /*++ 779 | 780 | Routine Description: 781 | 782 | Arguments: 783 | 784 | FxDevice - a handle to the framework device object 785 | FxResourcesTranslated - list of raw hardware resources that 786 | the PnP manager has assigned to the device 787 | 788 | Return Value: 789 | 790 | Status 791 | 792 | --*/ 793 | { 794 | PSSM4567_CONTEXT pDevice = GetDeviceContext(FxDevice); 795 | NTSTATUS status = STATUS_SUCCESS; 796 | 797 | UNREFERENCED_PARAMETER(FxResourcesTranslated); 798 | 799 | if (pDevice->SetUID && pDevice->UID == 0) { 800 | UpdateIntcSSTStatus(pDevice, 2); 801 | } 802 | 803 | SpbTargetDeinitialize(FxDevice, &pDevice->I2CContext); 804 | 805 | if (pDevice->IntcSSTCallbackObj) { 806 | ExUnregisterCallback(pDevice->IntcSSTCallbackObj); 807 | pDevice->IntcSSTCallbackObj = NULL; 808 | } 809 | 810 | if (pDevice->IntcSSTWorkItem) { 811 | WdfWorkItemFlush(pDevice->IntcSSTWorkItem); 812 | WdfObjectDelete(pDevice->IntcSSTWorkItem); 813 | pDevice->IntcSSTWorkItem = NULL; 814 | } 815 | 816 | if (pDevice->IntcSSTHwMultiCodecCallback) { 817 | ObfDereferenceObject(pDevice->IntcSSTHwMultiCodecCallback); 818 | pDevice->IntcSSTHwMultiCodecCallback = NULL; 819 | } 820 | 821 | if (pDevice->CSAudioAPICallbackObj) { 822 | ExUnregisterCallback(pDevice->CSAudioAPICallbackObj); 823 | pDevice->CSAudioAPICallbackObj = NULL; 824 | } 825 | 826 | if (pDevice->CSAudioAPICallback) { 827 | ObfDereferenceObject(pDevice->CSAudioAPICallback); 828 | pDevice->CSAudioAPICallback = NULL; 829 | } 830 | 831 | return status; 832 | } 833 | 834 | NTSTATUS 835 | OnSelfManagedIoInit( 836 | _In_ 837 | WDFDEVICE FxDevice 838 | ) { 839 | PSSM4567_CONTEXT pDevice = GetDeviceContext(FxDevice); 840 | NTSTATUS status = STATUS_SUCCESS; 841 | 842 | if (!pDevice->SetUID) { 843 | status = STATUS_INVALID_DEVICE_STATE; 844 | return status; 845 | } 846 | 847 | if (pDevice->UID == 0) { //Hook onto the first SSM codec 848 | UNICODE_STRING IntcAudioSSTMultiHwCodecAPI; 849 | RtlInitUnicodeString(&IntcAudioSSTMultiHwCodecAPI, L"\\CallBack\\IntcAudioSSTMultiHwCodecAPI"); 850 | 851 | 852 | OBJECT_ATTRIBUTES attributes; 853 | InitializeObjectAttributes(&attributes, 854 | &IntcAudioSSTMultiHwCodecAPI, 855 | OBJ_KERNEL_HANDLE | OBJ_OPENIF | OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 856 | NULL, 857 | NULL 858 | ); 859 | status = ExCreateCallback(&pDevice->IntcSSTHwMultiCodecCallback, &attributes, TRUE, TRUE); 860 | if (!NT_SUCCESS(status)) { 861 | 862 | return status; 863 | } 864 | 865 | pDevice->IntcSSTCallbackObj = ExRegisterCallback(pDevice->IntcSSTHwMultiCodecCallback, 866 | IntcSSTCallbackFunction, 867 | pDevice->IntcSSTWorkItem 868 | ); 869 | if (!pDevice->IntcSSTCallbackObj) { 870 | 871 | return STATUS_NO_CALLBACK_ACTIVE; 872 | } 873 | 874 | UpdateIntcSSTStatus(pDevice, 0); 875 | } 876 | 877 | // CS Audio Callback 878 | 879 | UNICODE_STRING CSAudioCallbackAPI; 880 | RtlInitUnicodeString(&CSAudioCallbackAPI, L"\\CallBack\\CsAudioCallbackAPI"); 881 | 882 | 883 | OBJECT_ATTRIBUTES attributes; 884 | InitializeObjectAttributes(&attributes, 885 | &CSAudioCallbackAPI, 886 | OBJ_KERNEL_HANDLE | OBJ_OPENIF | OBJ_CASE_INSENSITIVE | OBJ_PERMANENT, 887 | NULL, 888 | NULL 889 | ); 890 | status = ExCreateCallback(&pDevice->CSAudioAPICallback, &attributes, TRUE, TRUE); 891 | if (!NT_SUCCESS(status)) { 892 | return status; 893 | } 894 | 895 | pDevice->CSAudioAPICallbackObj = ExRegisterCallback(pDevice->CSAudioAPICallback, 896 | CsAudioCallbackFunction, 897 | pDevice 898 | ); 899 | if (!pDevice->CSAudioAPICallbackObj) { 900 | 901 | return STATUS_NO_CALLBACK_ACTIVE; 902 | } 903 | 904 | CSAudioRegisterEndpoint(pDevice); 905 | 906 | return status; 907 | } 908 | 909 | NTSTATUS 910 | OnD0Entry( 911 | _In_ WDFDEVICE FxDevice, 912 | _In_ WDF_POWER_DEVICE_STATE FxPreviousState 913 | ) 914 | /*++ 915 | 916 | Routine Description: 917 | 918 | This routine allocates objects needed by the driver. 919 | 920 | Arguments: 921 | 922 | FxDevice - a handle to the framework device object 923 | FxPreviousState - previous power state 924 | 925 | Return Value: 926 | 927 | Status 928 | 929 | --*/ 930 | { 931 | UNREFERENCED_PARAMETER(FxPreviousState); 932 | 933 | PSSM4567_CONTEXT pDevice = GetDeviceContext(FxDevice); 934 | NTSTATUS status = STATUS_SUCCESS; 935 | 936 | if (!pDevice->CSAudioManaged) { 937 | status = StartCodec(pDevice); 938 | } 939 | 940 | return status; 941 | } 942 | 943 | NTSTATUS 944 | OnD0Exit( 945 | _In_ WDFDEVICE FxDevice, 946 | _In_ WDF_POWER_DEVICE_STATE FxPreviousState 947 | ) 948 | /*++ 949 | 950 | Routine Description: 951 | 952 | This routine destroys objects needed by the driver. 953 | 954 | Arguments: 955 | 956 | FxDevice - a handle to the framework device object 957 | FxPreviousState - previous power state 958 | 959 | Return Value: 960 | 961 | Status 962 | 963 | --*/ 964 | { 965 | UNREFERENCED_PARAMETER(FxPreviousState); 966 | 967 | PSSM4567_CONTEXT pDevice = GetDeviceContext(FxDevice); 968 | NTSTATUS status = STATUS_SUCCESS; 969 | 970 | status = StopCodec(pDevice); 971 | 972 | return STATUS_SUCCESS; 973 | } 974 | 975 | NTSTATUS 976 | Ssm4567EvtDeviceAdd( 977 | IN WDFDRIVER Driver, 978 | IN PWDFDEVICE_INIT DeviceInit 979 | ) 980 | { 981 | NTSTATUS status = STATUS_SUCCESS; 982 | WDF_IO_QUEUE_CONFIG queueConfig; 983 | WDF_OBJECT_ATTRIBUTES attributes; 984 | WDFDEVICE device; 985 | WDFQUEUE queue; 986 | PSSM4567_CONTEXT devContext; 987 | 988 | UNREFERENCED_PARAMETER(Driver); 989 | 990 | PAGED_CODE(); 991 | 992 | Ssm4567Print(DEBUG_LEVEL_INFO, DBG_PNP, 993 | "Ssm4567EvtDeviceAdd called\n"); 994 | 995 | { 996 | WDF_PNPPOWER_EVENT_CALLBACKS pnpCallbacks; 997 | WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpCallbacks); 998 | 999 | pnpCallbacks.EvtDevicePrepareHardware = OnPrepareHardware; 1000 | pnpCallbacks.EvtDeviceReleaseHardware = OnReleaseHardware; 1001 | pnpCallbacks.EvtDeviceSelfManagedIoInit = OnSelfManagedIoInit; 1002 | pnpCallbacks.EvtDeviceD0Entry = OnD0Entry; 1003 | pnpCallbacks.EvtDeviceD0Exit = OnD0Exit; 1004 | 1005 | WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpCallbacks); 1006 | } 1007 | 1008 | // 1009 | // Setup the device context 1010 | // 1011 | 1012 | WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, SSM4567_CONTEXT); 1013 | 1014 | // 1015 | // Create a framework device object.This call will in turn create 1016 | // a WDM device object, attach to the lower stack, and set the 1017 | // appropriate flags and attributes. 1018 | // 1019 | 1020 | status = WdfDeviceCreate(&DeviceInit, &attributes, &device); 1021 | 1022 | if (!NT_SUCCESS(status)) 1023 | { 1024 | Ssm4567Print(DEBUG_LEVEL_ERROR, DBG_PNP, 1025 | "WdfDeviceCreate failed with status code 0x%x\n", status); 1026 | 1027 | return status; 1028 | } 1029 | 1030 | { 1031 | WDF_DEVICE_STATE deviceState; 1032 | WDF_DEVICE_STATE_INIT(&deviceState); 1033 | 1034 | deviceState.NotDisableable = WdfFalse; 1035 | WdfDeviceSetDeviceState(device, &deviceState); 1036 | } 1037 | 1038 | WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchParallel); 1039 | 1040 | queueConfig.EvtIoInternalDeviceControl = Ssm4567EvtInternalDeviceControl; 1041 | 1042 | status = WdfIoQueueCreate(device, 1043 | &queueConfig, 1044 | WDF_NO_OBJECT_ATTRIBUTES, 1045 | &queue 1046 | ); 1047 | 1048 | if (!NT_SUCCESS(status)) 1049 | { 1050 | Ssm4567Print(DEBUG_LEVEL_ERROR, DBG_PNP, 1051 | "WdfIoQueueCreate failed 0x%x\n", status); 1052 | 1053 | return status; 1054 | } 1055 | 1056 | // 1057 | // Create manual I/O queue to take care of hid report read requests 1058 | // 1059 | 1060 | devContext = GetDeviceContext(device); 1061 | 1062 | devContext->FxDevice = device; 1063 | devContext->CSAudioManaged = FALSE; 1064 | 1065 | WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual); 1066 | 1067 | queueConfig.PowerManaged = WdfFalse; 1068 | 1069 | status = WdfIoQueueCreate(device, 1070 | &queueConfig, 1071 | WDF_NO_OBJECT_ATTRIBUTES, 1072 | &devContext->ReportQueue 1073 | ); 1074 | 1075 | if (!NT_SUCCESS(status)) 1076 | { 1077 | Ssm4567Print(DEBUG_LEVEL_ERROR, DBG_PNP, 1078 | "WdfIoQueueCreate failed 0x%x\n", status); 1079 | 1080 | return status; 1081 | } 1082 | 1083 | return status; 1084 | } 1085 | 1086 | VOID 1087 | Ssm4567EvtInternalDeviceControl( 1088 | IN WDFQUEUE Queue, 1089 | IN WDFREQUEST Request, 1090 | IN size_t OutputBufferLength, 1091 | IN size_t InputBufferLength, 1092 | IN ULONG IoControlCode 1093 | ) 1094 | { 1095 | NTSTATUS status = STATUS_SUCCESS; 1096 | WDFDEVICE device; 1097 | PSSM4567_CONTEXT devContext; 1098 | 1099 | UNREFERENCED_PARAMETER(OutputBufferLength); 1100 | UNREFERENCED_PARAMETER(InputBufferLength); 1101 | 1102 | device = WdfIoQueueGetDevice(Queue); 1103 | devContext = GetDeviceContext(device); 1104 | 1105 | switch (IoControlCode) 1106 | { 1107 | default: 1108 | status = STATUS_NOT_SUPPORTED; 1109 | break; 1110 | } 1111 | 1112 | WdfRequestComplete(Request, status); 1113 | 1114 | return; 1115 | } --------------------------------------------------------------------------------