]> git.proxmox.com Git - mirror_edk2.git/blame - Omap35xxPkg/Gpio/Gpio.c
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / Omap35xxPkg / Gpio / Gpio.c
CommitLineData
1e57a462 1/** @file\r
2\r
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
3402aac7 4\r
1e57a462 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 <Library/IoLib.h>\r
18#include <Library/OmapLib.h>\r
19#include <Library/UefiBootServicesTableLib.h>\r
20\r
21#include <Protocol/EmbeddedGpio.h>\r
22\r
23#include <Omap3530/Omap3530.h>\r
24\r
25EFI_STATUS\r
26Get (\r
27 IN EMBEDDED_GPIO *This,\r
28 IN EMBEDDED_GPIO_PIN Gpio,\r
29 OUT UINTN *Value\r
30 )\r
31{\r
32 UINTN Port;\r
33 UINTN Pin;\r
34 UINT32 DataInRegister;\r
35\r
36 if (Value == NULL)\r
37 {\r
38 return EFI_UNSUPPORTED;\r
39 }\r
40\r
41 Port = GPIO_PORT(Gpio);\r
42 Pin = GPIO_PIN(Gpio);\r
43\r
44 DataInRegister = GpioBase(Port) + GPIO_DATAIN;\r
45\r
46 if (MmioRead32 (DataInRegister) & GPIO_DATAIN_MASK(Pin)) {\r
47 *Value = 1;\r
48 } else {\r
49 *Value = 0;\r
50 }\r
51\r
52 return EFI_SUCCESS;\r
53}\r
54\r
55EFI_STATUS\r
56Set (\r
57 IN EMBEDDED_GPIO *This,\r
58 IN EMBEDDED_GPIO_PIN Gpio,\r
59 IN EMBEDDED_GPIO_MODE Mode\r
60 )\r
61{\r
62 UINTN Port;\r
63 UINTN Pin;\r
64 UINT32 OutputEnableRegister;\r
65 UINT32 SetDataOutRegister;\r
66 UINT32 ClearDataOutRegister;\r
67\r
68 Port = GPIO_PORT(Gpio);\r
69 Pin = GPIO_PIN(Gpio);\r
70\r
71 OutputEnableRegister = GpioBase(Port) + GPIO_OE;\r
72 SetDataOutRegister = GpioBase(Port) + GPIO_SETDATAOUT;\r
73 ClearDataOutRegister = GpioBase(Port) + GPIO_CLEARDATAOUT;\r
74\r
75 switch (Mode)\r
76 {\r
77 case GPIO_MODE_INPUT:\r
78 MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_INPUT(Pin));\r
79 break;\r
80\r
81 case GPIO_MODE_OUTPUT_0:\r
82 MmioWrite32 (ClearDataOutRegister, GPIO_CLEARDATAOUT_BIT(Pin));\r
83 MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin));\r
84 break;\r
85\r
86 case GPIO_MODE_OUTPUT_1:\r
87 MmioWrite32 (SetDataOutRegister, GPIO_SETDATAOUT_BIT(Pin));\r
88 MmioAndThenOr32(OutputEnableRegister, ~GPIO_OE_MASK(Pin), GPIO_OE_OUTPUT(Pin));\r
89 break;\r
90\r
91 default:\r
92 return EFI_UNSUPPORTED;\r
93 }\r
94\r
95 return EFI_SUCCESS;\r
96}\r
97\r
98EFI_STATUS\r
99GetMode (\r
100 IN EMBEDDED_GPIO *This,\r
101 IN EMBEDDED_GPIO_PIN Gpio,\r
102 OUT EMBEDDED_GPIO_MODE *Mode\r
103 )\r
104{\r
105 return EFI_UNSUPPORTED;\r
106}\r
107\r
108EFI_STATUS\r
109SetPull (\r
110 IN EMBEDDED_GPIO *This,\r
111 IN EMBEDDED_GPIO_PIN Gpio,\r
112 IN EMBEDDED_GPIO_PULL Direction\r
113 )\r
114{\r
115 return EFI_UNSUPPORTED;\r
116}\r
117\r
118EMBEDDED_GPIO Gpio = {\r
119 Get,\r
120 Set,\r
121 GetMode,\r
122 SetPull\r
123};\r
124\r
125EFI_STATUS\r
126GpioInitialize (\r
127 IN EFI_HANDLE ImageHandle,\r
128 IN EFI_SYSTEM_TABLE *SystemTable\r
129 )\r
130{\r
131 EFI_STATUS Status;\r
3402aac7 132\r
1e57a462 133 Status = gBS->InstallMultipleProtocolInterfaces(&ImageHandle, &gEmbeddedGpioProtocolGuid, &Gpio, NULL);\r
134 return Status;\r
135}\r