]>
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 | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <Uefi.h>\r | |
17 | \r | |
18 | #include <Library/BaseLib.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/PcdLib.h>\r | |
21 | #include <Library/UefiBootServicesTableLib.h>\r | |
22 | \r | |
23 | #include <Protocol/FdtClient.h>\r | |
24 | \r | |
25 | RETURN_STATUS\r | |
26 | EFIAPI\r | |
27 | ArmVirtPL031FdtClientLibConstructor (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | EFI_STATUS Status;\r | |
32 | FDT_CLIENT_PROTOCOL *FdtClient;\r | |
33 | INT32 Node;\r | |
34 | CONST UINT64 *Reg;\r | |
35 | UINT32 RegSize;\r | |
36 | UINT64 RegBase;\r | |
a79d29b6 | 37 | RETURN_STATUS PcdStatus;\r |
658e7a41 AB |
38 | \r |
39 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r | |
40 | (VOID **)&FdtClient);\r | |
41 | ASSERT_EFI_ERROR (Status);\r | |
42 | \r | |
43 | Status = FdtClient->FindCompatibleNode (FdtClient, "arm,pl031", &Node);\r | |
44 | if (EFI_ERROR (Status)) {\r | |
45 | DEBUG ((EFI_D_WARN, "%a: No 'arm,pl031' compatible DT node found\n",\r | |
46 | __FUNCTION__));\r | |
47 | return EFI_SUCCESS;\r | |
48 | }\r | |
49 | \r | |
50 | Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r | |
51 | (CONST VOID **)&Reg, &RegSize);\r | |
52 | if (EFI_ERROR (Status)) {\r | |
53 | DEBUG ((EFI_D_WARN,\r | |
54 | "%a: No 'reg' property found in 'arm,pl031' compatible DT node\n",\r | |
55 | __FUNCTION__));\r | |
56 | return EFI_SUCCESS;\r | |
57 | }\r | |
58 | \r | |
59 | ASSERT (RegSize == 16);\r | |
60 | \r | |
61 | RegBase = SwapBytes64 (Reg[0]);\r | |
62 | ASSERT (RegBase < MAX_UINT32);\r | |
63 | \r | |
a79d29b6 LE |
64 | PcdStatus = PcdSet32S (PcdPL031RtcBase, (UINT32)RegBase);\r |
65 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
658e7a41 AB |
66 | \r |
67 | DEBUG ((EFI_D_INFO, "Found PL031 RTC @ 0x%Lx\n", RegBase));\r | |
68 | \r | |
d5256ba9 AB |
69 | //\r |
70 | // UEFI takes ownership of the RTC hardware, and exposes its functionality\r | |
71 | // through the UEFI Runtime Services GetTime, SetTime, etc. This means we\r | |
72 | // need to disable it in the device tree to prevent the OS from attaching\r | |
73 | // its device driver as well.\r | |
74 | //\r | |
75 | Status = FdtClient->SetNodeProperty (FdtClient, Node, "status",\r | |
76 | "disabled", sizeof ("disabled"));\r | |
77 | if (EFI_ERROR (Status)) {\r | |
78 | DEBUG ((EFI_D_WARN, "Failed to set PL031 status to 'disabled'\n"));\r | |
658e7a41 AB |
79 | }\r |
80 | \r | |
81 | return EFI_SUCCESS;\r | |
82 | }\r |