]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - windows-iot-driver/drivers.git/blobdiff - LM3643/TxnwLedLm3643/Driver.c
LM3643 Initial Commit : Synchronous Boost Dual LED Flash Driver
[windows-iot-driver/drivers.git] / LM3643 / TxnwLedLm3643 / Driver.c
diff --git a/LM3643/TxnwLedLm3643/Driver.c b/LM3643/TxnwLedLm3643/Driver.c
new file mode 100644 (file)
index 0000000..30b6463
--- /dev/null
@@ -0,0 +1,279 @@
+/*++\r
+Copyright (c) Texas Instruments Inc. All Rights Reserved.\r
+Sample code for Dual LED FLASH LM3643.\r
+\r
+The MIT License (MIT)\r
+\r
+Permission is hereby granted, free of charge, to any person obtaining a copy\r
+of this software and associated documentation files (the "Software"), to deal\r
+in the Software without restriction, including without limitation the rights\r
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+copies of the Software, and to permit persons to whom the Software is\r
+furnished to do so, subject to the following conditions:\r
+\r
+The above copyright notice and this permission notice shall be included in\r
+all copies or substantial portions of the Software.\r
+\r
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+THE SOFTWARE.\r
+\r
+Module Name:\r
+\r
+    driver.c\r
+\r
+Abstract:\r
+\r
+    This file contains the driver entry points and callbacks.\r
+\r
+Environment:\r
+\r
+    Kernel-mode Driver Framework\r
+\r
+--*/\r
+\r
+#include "driver.h"\r
+#include "driver.tmh"\r
+#include "Public.h"\r
+\r
+#ifdef ALLOC_PRAGMA\r
+#pragma alloc_text (INIT, DriverEntry)\r
+#pragma alloc_text (PAGE, TxnwLedLm3643EvtDeviceAdd)\r
+#pragma alloc_text (PAGE, TxnwLedLm3643EvtDriverContextCleanup)\r
+#endif\r
+
+#define TXN_DEVICE_NAME L"TxnwLedLm3643"\r
+\r
+NTSTATUS\r
+DriverEntry(\r
+    _In_ PDRIVER_OBJECT  DriverObject,\r
+    _In_ PUNICODE_STRING RegistryPath\r
+    )\r
+/*++\r
+\r
+Routine Description:\r
+    DriverEntry initializes the driver and is the first routine called by the\r
+    system after the driver is loaded. DriverEntry specifies the other entry\r
+    points in the function driver, such as EvtDevice and DriverUnload.\r
+\r
+Parameters Description:\r
+\r
+    DriverObject - represents the instance of the function driver that is loaded\r
+    into memory. DriverEntry must initialize members of DriverObject before it\r
+    returns to the caller. DriverObject is allocated by the system before the\r
+    driver is loaded, and it is released by the system after the system unloads\r
+    the function driver from memory.\r
+\r
+    RegistryPath - represents the driver specific path in the Registry.\r
+    The function driver can use the path to store driver related data between\r
+    reboots. The path does not store hardware instance specific data.\r
+\r
+Return Value:\r
+\r
+    STATUS_SUCCESS if successful,\r
+    STATUS_UNSUCCESSFUL otherwise.\r
+\r
+--*/\r
+{\r
+    WDF_DRIVER_CONFIG config;\r
+    NTSTATUS status;\r
+    WDF_OBJECT_ATTRIBUTES attributes;\r
+\r
+    //\r
+    // Initialize WPP Tracing\r
+    //\r
+    WPP_INIT_TRACING( DriverObject, RegistryPath );\r
+\r
+\r
+    //\r
+    // Register a cleanup callback so that we can call WPP_CLEANUP when\r
+    // the framework driver object is deleted during driver unload.\r
+    //\r
+    WDF_OBJECT_ATTRIBUTES_INIT(&attributes);\r
+    attributes.EvtCleanupCallback = TxnwLedLm3643EvtDriverContextCleanup;\r
+\r
+    WDF_DRIVER_CONFIG_INIT(&config,\r
+                           TxnwLedLm3643EvtDeviceAdd\r
+                           );\r
+\r
+    status = WdfDriverCreate(DriverObject,\r
+                             RegistryPath,\r
+                             &attributes,\r
+                             &config,\r
+                             WDF_NO_HANDLE\r
+                             );\r
+\r
+    if (!NT_SUCCESS(status)) {\r
+        WPP_CLEANUP(DriverObject);\r
+        return status;\r
+    }\r
+\r
+    return status;\r
+}\r
+\r
+NTSTATUS\r
+TxnwLedLm3643EvtDeviceAdd(\r
+    _In_    WDFDRIVER       Driver,\r
+    _Inout_ PWDFDEVICE_INIT DeviceInit\r
+    )\r
+/*++\r
+Routine Description:\r
+\r
+    EvtDeviceAdd is called by the framework in response to AddDevice\r
+    call from the PnP manager. We create and initialize a device object to\r
+    represent a new instance of the device.\r
+\r
+Arguments:\r
+\r
+    Driver - Handle to a framework driver object created in DriverEntry\r
+\r
+    DeviceInit - Pointer to a framework-allocated WDFDEVICE_INIT structure.\r
+\r
+Return Value:\r
+\r
+    NTSTATUS\r
+\r
+--*/\r
+{\r
+       WDF_OBJECT_ATTRIBUTES attributes;\r
+       PDEVICE_EXTENSION devContext;\r
+       WDFDEVICE fxDevice;\r
+       WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;\r
+       WDF_IO_QUEUE_CONFIG queueConfig;\r
+    NTSTATUS status;\r
+\r
+\r
+    UNREFERENCED_PARAMETER(Driver);\r
+\r
+    PAGED_CODE();\r
+\r
+       WdfDeviceInitSetPowerPolicyOwnership(DeviceInit, FALSE);\r
+       //\r
+       // This driver handles D0 Entry and Exit to power on and off the\r
+       // controller. It also handles prepare/release hardware so that it \r
+       // can acquire and free SPB resources needed to communicate with the  \r
+       // touch controller.\r
+       //\r
+       WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);\r
+\r
+       pnpPowerCallbacks.EvtDeviceD0Entry = OnD0Entry;\r
+       pnpPowerCallbacks.EvtDeviceD0Exit = OnD0Exit;\r
+       pnpPowerCallbacks.EvtDevicePrepareHardware = OnPrepareHardware;\r
+       pnpPowerCallbacks.EvtDeviceReleaseHardware = OnReleaseHardware;\r
+\r
+       WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);\r
+\r
+       //\r
+       // Create a framework device object. This call will in turn create\r
+       // a WDM device object, attach to the lower stack, and set the\r
+       // appropriate flags and attributes.\r
+       //\r
+       WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, DEVICE_EXTENSION);\r
+\r
+       status = WdfDeviceCreate(&DeviceInit, &attributes, &fxDevice);\r
+\r
+       if (!NT_SUCCESS(status))\r
+       {\r
+               goto exit;\r
+       }\r
+\r
+       devContext = GetDeviceContext(fxDevice);\r
+       devContext->FxDevice = fxDevice;\r
+\r
+       //\r
+       // Create a parallel dispatch queue to handle requests\r
+       //\r
+       WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(\r
+               &queueConfig,\r
+               WdfIoQueueDispatchSequential);\r
+       \r
+       queueConfig.EvtIoDeviceControl = OnDeviceControl;\r
+       queueConfig.PowerManaged = WdfFalse;\r
+\r
+       status = WdfIoQueueCreate(\r
+               fxDevice,\r
+               &queueConfig,\r
+               WDF_NO_OBJECT_ATTRIBUTES,\r
+               &devContext->DefaultQueue);\r
+\r
+       if (!NT_SUCCESS(status))\r
+       {\r
+               goto exit;\r
+       }\r
+\r
+       //\r
+       // Register a manual I/O queue for Read Requests. This queue will be used \r
+       // for storing read-requests until data is available to complete them.\r
+       //\r
+       WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual);\r
+\r
+       queueConfig.PowerManaged = WdfFalse;\r
+\r
+       status = WdfIoQueueCreate(\r
+               fxDevice,\r
+               &queueConfig,\r
+               WDF_NO_OBJECT_ATTRIBUTES,\r
+               &devContext->PingPongQueue);\r
+\r
+       if (!NT_SUCCESS(status))\r
+       {\r
+               goto exit;\r
+       }\r
+       //\r
+       // Register one last manual I/O queue for parking idle power\r
+       // requests. This queue stores idle requests until they're cancelled,\r
+       // and could be used to complete a wait/wake request.\r
+       //\r
+\r
+       WDF_IO_QUEUE_CONFIG_INIT(&queueConfig, WdfIoQueueDispatchManual);\r
+\r
+       queueConfig.PowerManaged = WdfFalse;\r
+\r
+       status = WdfIoQueueCreate(\r
+               fxDevice,\r
+               &queueConfig,\r
+               WDF_NO_OBJECT_ATTRIBUTES,\r
+               &devContext->IdleQueue\r
+               );\r
+\r
+       if (!NT_SUCCESS(status))\r
+       {\r
+               goto exit;\r
+       }\r
+\r
+       DECLARE_CONST_UNICODE_STRING(symbolicLink, L"\\DosDevices\\" LM3643_DEVICE_NAME);\r
+       status = WdfDeviceCreateSymbolicLink(fxDevice, &symbolicLink);\r
+       \r
+exit:\r
+    return status;\r
+}\r
+\r
+VOID\r
+TxnwLedLm3643EvtDriverContextCleanup(\r
+    _In_ WDFOBJECT DriverObject\r
+    )\r
+/*++\r
+Routine Description:\r
+\r
+    Free all the resources allocated in DriverEntry.\r
+\r
+Arguments:\r
+\r
+    DriverObject - handle to a WDF Driver object.\r
+\r
+Return Value:\r
+\r
+    VOID.\r
+\r
+--*/\r
+{\r
+    UNREFERENCED_PARAMETER(DriverObject);\r
+\r
+    PAGED_CODE ();\r
+\r
+    WPP_CLEANUP( WdfDriverWdmGetDriverObject( (WDFDRIVER) DriverObject) );\r
+}\r