]>
Commit | Line | Data |
---|---|---|
658e7a41 AB |
1 | /** @file\r |
2 | FDT client library for ARM's PL031 RTC driver\r | |
3 | \r | |
4 | Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r | |
5 | \r | |
9792fb0e | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
658e7a41 AB |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include <Uefi.h>\r | |
11 | \r | |
12 | #include <Library/BaseLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/PcdLib.h>\r | |
15 | #include <Library/UefiBootServicesTableLib.h>\r | |
16 | \r | |
17 | #include <Protocol/FdtClient.h>\r | |
18 | \r | |
19 | RETURN_STATUS\r | |
20 | EFIAPI\r | |
21 | ArmVirtPL031FdtClientLibConstructor (\r | |
22 | VOID\r | |
23 | )\r | |
24 | {\r | |
25 | EFI_STATUS Status;\r | |
26 | FDT_CLIENT_PROTOCOL *FdtClient;\r | |
27 | INT32 Node;\r | |
28 | CONST UINT64 *Reg;\r | |
29 | UINT32 RegSize;\r | |
30 | UINT64 RegBase;\r | |
a79d29b6 | 31 | RETURN_STATUS PcdStatus;\r |
658e7a41 AB |
32 | \r |
33 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r | |
34 | (VOID **)&FdtClient);\r | |
35 | ASSERT_EFI_ERROR (Status);\r | |
36 | \r | |
37 | Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);\r | |
38 | if (EFI_ERROR (Status)) {\r | |
39 | DEBUG ((EFI_D_WARN, "%a: No 'arm,pl031' compatible DT node found\n",\r | |
40 | __FUNCTION__));\r | |
41 | return EFI_SUCCESS;\r | |
42 | }\r | |
43 | \r | |
44 | Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r | |
45 | (CONST VOID **)&Reg, &RegSize);\r | |
46 | if (EFI_ERROR (Status)) {\r | |
47 | DEBUG ((EFI_D_WARN,\r | |
48 | "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",\r | |
49 | __FUNCTION__));\r | |
50 | return EFI_SUCCESS;\r | |
51 | }\r | |
52 | \r | |
53 | ASSERT (RegSize == 16);\r | |
54 | \r | |
55 | RegBase = SwapBytes64 (Reg[0]);\r | |
56 | ASSERT (RegBase < MAX_UINT32);\r | |
57 | \r | |
a79d29b6 LE |
58 | PcdStatus = PcdSet32S (PcdPL031RtcBase, (UINT32)RegBase);\r |
59 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
658e7a41 AB |
60 | \r |
61 | DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));\r | |
62 | \r | |
d5256ba9 AB |
63 | //\r |
64 | // UEFI takes ownership of the RTC hardware, and exposes its functionality\r | |
65 | // through the UEFI Runtime Services GetTime, SetTime, etc. This means we\r | |
66 | // need to disable it in the device tree to prevent the OS from attaching\r | |
67 | // its device driver as well.\r | |
68 | //\r | |
69 | Status = FdtClient->SetNodeProperty (FdtClient, Node, "status",\r | |
70 | "disabled", sizeof ("disabled"));\r | |
71 | if (EFI_ERROR (Status)) {\r | |
72 | DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n"));\r | |
658e7a41 AB |
73 | }\r |
74 | \r | |
75 | return EFI_SUCCESS;\r | |
76 | }\r |