]> git.proxmox.com Git - mirror_edk2.git/blame - Omap35xxPkg/TPS65950Dxe/TPS65950.c
ARM Packages: Fixed line endings
[mirror_edk2.git] / Omap35xxPkg / TPS65950Dxe / TPS65950.c
CommitLineData
1e57a462 1/** @file\r
2\r
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
4 \r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Uefi.h>\r
16\r
17#include <TPS65950.h>\r
18\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23\r
24#include <Protocol/EmbeddedExternalDevice.h>\r
25#include <Protocol/SmbusHc.h>\r
26\r
27EFI_SMBUS_HC_PROTOCOL *Smbus;\r
28\r
29EFI_STATUS\r
30Read (\r
31 IN EMBEDDED_EXTERNAL_DEVICE *This,\r
32 IN UINTN Register,\r
33 IN UINTN Length,\r
34 OUT VOID *Buffer\r
35 )\r
36{\r
37 EFI_STATUS Status;\r
38 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; \r
39 UINT8 DeviceRegister;\r
40 UINTN DeviceRegisterLength = 1;\r
41\r
42 SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);\r
43 DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);\r
44\r
45 //Write DeviceRegister.\r
46 Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceRegisterLength, &DeviceRegister);\r
47 if (EFI_ERROR(Status)) {\r
48 return Status;\r
49 }\r
50\r
51 //Read Data\r
52 Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusReadBlock, FALSE, &Length, Buffer);\r
53 return Status;\r
54}\r
55\r
56EFI_STATUS\r
57Write (\r
58 IN EMBEDDED_EXTERNAL_DEVICE *This,\r
59 IN UINTN Register,\r
60 IN UINTN Length,\r
61 IN VOID *Buffer\r
62 )\r
63{\r
64 EFI_STATUS Status;\r
65 EFI_SMBUS_DEVICE_ADDRESS SlaveAddress; \r
66 UINT8 DeviceRegister;\r
67 UINTN DeviceBufferLength = Length + 1;\r
68 UINT8 *DeviceBuffer;\r
69\r
70 SlaveAddress.SmbusDeviceAddress = EXTERNAL_DEVICE_REGISTER_TO_SLAVE_ADDRESS(Register);\r
71 DeviceRegister = (UINT8)EXTERNAL_DEVICE_REGISTER_TO_REGISTER(Register);\r
72\r
73 //Prepare buffer for writing\r
74 DeviceBuffer = (UINT8 *)AllocatePool(DeviceBufferLength);\r
75 if (DeviceBuffer == NULL) {\r
76 Status = EFI_OUT_OF_RESOURCES;\r
77 goto exit;\r
78 }\r
79\r
80 //Set Device register followed by data to write.\r
81 DeviceBuffer[0] = DeviceRegister;\r
82 CopyMem(&DeviceBuffer[1], Buffer, Length);\r
83\r
84 //Write Data\r
85 Status = Smbus->Execute(Smbus, SlaveAddress, 0, EfiSmbusWriteBlock, FALSE, &DeviceBufferLength, DeviceBuffer);\r
86 if (EFI_ERROR(Status)) {\r
87 goto exit;\r
88 }\r
89\r
90exit:\r
91 if (DeviceBuffer) {\r
92 FreePool(DeviceBuffer);\r
93 }\r
94\r
95 return Status;\r
96}\r
97\r
98EMBEDDED_EXTERNAL_DEVICE ExternalDevice = {\r
99 Read,\r
100 Write\r
101};\r
102\r
103EFI_STATUS\r
104TPS65950Initialize (\r
105 IN EFI_HANDLE ImageHandle,\r
106 IN EFI_SYSTEM_TABLE *SystemTable\r
107 )\r
108{\r
109 EFI_STATUS Status;\r
110 \r
111 Status = gBS->LocateProtocol(&gEfiSmbusHcProtocolGuid, NULL, (VOID **)&Smbus);\r
112 ASSERT_EFI_ERROR(Status);\r
113 \r
114 Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedExternalDeviceProtocolGuid, &ExternalDevice, NULL);\r
115 return Status;\r
116}\r