]> git.proxmox.com Git - mirror_edk2.git/blame - OptionRomPkg/Bus/Usb/FtdiUsbSerialDxe/ComponentName.c
OptionRomPkg: Added bus driver for FTDI USB to serial adapters
[mirror_edk2.git] / OptionRomPkg / Bus / Usb / FtdiUsbSerialDxe / ComponentName.c
CommitLineData
3f1484f6
AD
1/** @file\r
2 UEFI Component Name(2) protocol implementation for USB Serial driver.\r
3\r
4Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD\r
7License which accompanies this distribution. The full text of the license may\r
8be found at http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "FtdiUsbSerialDriver.h"\r
16\r
17//\r
18// EFI Component Name Protocol\r
19//\r
20GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbSerialComponentName = {\r
21 (EFI_COMPONENT_NAME_GET_DRIVER_NAME) UsbSerialComponentNameGetDriverName,\r
22 (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) UsbSerialComponentNameGetControllerName,\r
23 "eng"\r
24};\r
25\r
26//\r
27// EFI Component Name 2 Protocol\r
28//\r
29GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbSerialComponentName2 = {\r
30 UsbSerialComponentNameGetDriverName,\r
31 UsbSerialComponentNameGetControllerName,\r
32 "en"\r
33};\r
34\r
35//\r
36// Driver name string table\r
37//\r
38GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbSerialDriverNameTable[] = {\r
39 { "eng;en", L"FTDI-232 USB Serial Driver" },\r
40 { NULL , NULL }\r
41};\r
42\r
43/**\r
44 Retrieves a Unicode string that is the user readable name of the driver.\r
45\r
46 This function retrieves the user readable name of a driver in the form of a\r
47 Unicode string. If the driver specified by This has a user readable name in\r
48 the language specified by Language, then a pointer to the driver name is\r
49 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
50 by This does not support the language specified by Language,\r
51 then EFI_UNSUPPORTED is returned.\r
52\r
53 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
54 EFI_COMPONENT_NAME_PROTOCOL instance.\r
55 @param Language A pointer to a Null-terminated ASCII string\r
56 array indicating the language. This is the\r
57 language of the driver name that the caller is\r
58 requesting, and it must match one of the\r
59 languages specified in SupportedLanguages. The\r
60 number of languages supported by a driver is up\r
61 to the driver writer. Language is specified\r
62 in RFC 4646 or ISO 639-2 language code format.\r
63 @param DriverName A pointer to the Unicode string to return.\r
64 This Unicode string is the name of the\r
65 driver specified by This in the language\r
66 specified by Language.\r
67\r
68 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
69 This and the language specified by Language was\r
70 returned in DriverName.\r
71 @retval EFI_INVALID_PARAMETER Language is NULL.\r
72 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
73 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
74 the language specified by Language.\r
75\r
76**/\r
77EFI_STATUS\r
78EFIAPI\r
79UsbSerialComponentNameGetDriverName (\r
80 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
81 IN CHAR8 *Language,\r
82 OUT CHAR16 **DriverName\r
83 )\r
84{\r
85 return LookupUnicodeString2 (\r
86 Language,\r
87 This->SupportedLanguages,\r
88 mUsbSerialDriverNameTable,\r
89 DriverName,\r
90 (BOOLEAN)(This == &gUsbSerialComponentName2)\r
91 );\r
92}\r
93\r
94\r
95/**\r
96 Retrieves a Unicode string that is the user readable name of the controller\r
97 that is being managed by a driver.\r
98\r
99 This function retrieves the user readable name of the controller specified by\r
100 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
101 driver specified by This has a user readable name in the language specified by\r
102 Language, then a pointer to the controller name is returned in ControllerName,\r
103 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
104 managing the controller specified by ControllerHandle and ChildHandle,\r
105 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
106 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
107\r
108 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
109 EFI_COMPONENT_NAME_PROTOCOL instance.\r
110 @param ControllerHandle The handle of a controller that the driver\r
111 specified by This is managing. This handle\r
112 specifies the controller whose name is to be\r
113 returned.\r
114 @param ChildHandle The handle of the child controller to retrieve\r
115 the name of. This is an optional parameter that\r
116 may be NULL. It will be NULL for device\r
117 drivers. It will also be NULL for a bus drivers\r
118 that wish to retrieve the name of the bus\r
119 controller. It will not be NULL for a bus\r
120 driver that wishes to retrieve the name of a\r
121 child controller.\r
122 @param Language A pointer to a Null-terminated ASCII string\r
123 array indicating the language. This is the\r
124 language of the driver name that the caller is\r
125 requesting, and it must match one of the\r
126 languages specified in SupportedLanguages. The\r
127 number of languages supported by a driver is up\r
128 to the driver writer. Language is specified in\r
129 RFC 4646 or ISO 639-2 language code format.\r
130 @param ControllerName A pointer to the Unicode string to return.\r
131 This Unicode string is the name of the\r
132 controller specified by ControllerHandle and\r
133 ChildHandle in the language specified by\r
134 Language from the point of view of the driver\r
135 specified by This.\r
136\r
137 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
138 the language specified by Language for the\r
139 driver specified by This was returned in\r
140 DriverName.\r
141 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
142 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
143 EFI_HANDLE.\r
144 @retval EFI_INVALID_PARAMETER Language is NULL.\r
145 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
146 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
147 managing the controller specified by\r
148 ControllerHandle and ChildHandle.\r
149 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
150 the language specified by Language.\r
151\r
152**/\r
153EFI_STATUS\r
154EFIAPI\r
155UsbSerialComponentNameGetControllerName (\r
156 IN EFI_COMPONENT_NAME2_PROTOCOL *This,\r
157 IN EFI_HANDLE ControllerHandle,\r
158 IN EFI_HANDLE ChildHandle OPTIONAL,\r
159 IN CHAR8 *Language,\r
160 OUT CHAR16 **ControllerName\r
161 )\r
162{\r
163 EFI_STATUS Status;\r
164 USB_SER_DEV *UsbSerDev;\r
165 EFI_SERIAL_IO_PROTOCOL *SerialIo;\r
166 EFI_USB_IO_PROTOCOL *UsbIoProtocol;\r
167 \r
168 //\r
169 // This is a device driver, so ChildHandle must be NULL.\r
170 //\r
171 if (ChildHandle != NULL) {\r
172 return EFI_UNSUPPORTED;\r
173 }\r
174\r
175 //\r
176 // Check Controller's handle\r
177 //\r
178 Status = gBS->OpenProtocol (\r
179 ControllerHandle,\r
180 &gEfiUsbIoProtocolGuid,\r
181 (VOID **) &UsbIoProtocol,\r
182 gUsbSerialDriverBinding.DriverBindingHandle,\r
183 ControllerHandle,\r
184 EFI_OPEN_PROTOCOL_BY_DRIVER\r
185 );\r
186 if (!EFI_ERROR (Status)) {\r
187 gBS->CloseProtocol (\r
188 ControllerHandle,\r
189 &gEfiUsbIoProtocolGuid,\r
190 gUsbSerialDriverBinding.DriverBindingHandle,\r
191 ControllerHandle\r
192 );\r
193\r
194 return EFI_UNSUPPORTED;\r
195 }\r
196\r
197 if (Status != EFI_ALREADY_STARTED) {\r
198 return EFI_UNSUPPORTED;\r
199 }\r
200 //\r
201 // Get the device context\r
202 //\r
203 Status = gBS->OpenProtocol (\r
204 ControllerHandle,\r
205 &gEfiSerialIoProtocolGuid,\r
206 (VOID **) &SerialIo,\r
207 gUsbSerialDriverBinding.DriverBindingHandle,\r
208 ControllerHandle,\r
209 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
210 );\r
211 if (EFI_ERROR (Status)) {\r
212 return Status;\r
213 }\r
214\r
215 UsbSerDev = USB_SER_DEV_FROM_THIS (SerialIo);\r
216\r
217 return LookupUnicodeString2 (\r
218 Language,\r
219 This->SupportedLanguages,\r
220 UsbSerDev->ControllerNameTable,\r
221 ControllerName,\r
222 (BOOLEAN)(This == &gUsbSerialComponentName2)\r
223 );\r
224}\r