Advertisement
Guest User

Armada 7k8k v2 diff

a guest
Jan 9th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 78.81 KB | None | 0 0
  1. diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.dec
  2. index 20a32ef..12bac55 100644
  3. --- a/Silicon/Marvell/Marvell.dec
  4. +++ b/Silicon/Marvell/Marvell.dec
  5. @@ -216,7 +216,6 @@
  6.  [Protocols]
  7.    gMarvellBoardDescProtocolGuid            = { 0xebed8738, 0xd4a6, 0x4001, { 0xa9, 0xc9, 0x52, 0xb0, 0xcb, 0x7d, 0xdb, 0xf9 }}
  8.    gMarvellEepromProtocolGuid               = { 0x71954bda, 0x60d3, 0x4ef8, { 0x8e, 0x3c, 0x0e, 0x33, 0x9f, 0x3b, 0xc2, 0x2b }}
  9. -  gMarvellGpioProtocolGuid                 = { 0x8b01a5b7, 0xc570, 0x4e97, { 0x80, 0x95, 0x4f, 0x74, 0x2a, 0x8d, 0x7d, 0x43 }}
  10.    gMarvellMdioProtocolGuid                 = { 0x40010b03, 0x5f08, 0x496a, { 0xa2, 0x64, 0x10, 0x5e, 0x72, 0xd3, 0x71, 0xaa }}
  11.    gMarvellPhyProtocolGuid                  = { 0x32f48a43, 0x37e3, 0x4acf, { 0x93, 0xc4, 0x3e, 0x57, 0xa7, 0xb0, 0xfb, 0xdc }}
  12.    gMarvellSpiMasterProtocolGuid            = { 0x23de66a3, 0xf666, 0x4b3e, { 0xaa, 0xa2, 0x68, 0x9b, 0x18, 0xae, 0x2e, 0x19 }}
  13. diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
  14. index b26f55b..c995515 100644
  15. --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
  16. +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
  17. @@ -25,6 +25,7 @@
  18.    Armada70x0DbBoardDescLib.c
  19.  
  20.  [Packages]
  21. +  EmbeddedPkg/EmbeddedPkg.dec
  22.    MdeModulePkg/MdeModulePkg.dec
  23.    MdePkg/MdePkg.dec
  24.    Silicon/Marvell/Marvell.dec
  25. diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  26. index bbe7ff8..8d33e1d 100644
  27. --- a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  28. +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  29. @@ -32,6 +32,7 @@
  30.    NonDiscoverableInitLib.c
  31.  
  32.  [Packages]
  33. +  EmbeddedPkg/EmbeddedPkg.dec
  34.    MdePkg/MdePkg.dec
  35.    MdeModulePkg/MdeModulePkg.dec
  36.    Silicon/Marvell/Marvell.dec
  37. @@ -41,7 +42,7 @@
  38.    IoLib
  39.  
  40.  [Protocols]
  41. -  gMarvellGpioProtocolGuid
  42. +  gEmbeddedGpioProtocolGuid
  43.  
  44.  [Depex]
  45.    gMarvellPlatformInitCompleteProtocolGuid
  46. diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
  47. index 2d39d96..786b7f0 100644
  48. --- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
  49. +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
  50. @@ -25,6 +25,7 @@
  51.    Armada80x0DbBoardDescLib.c
  52.  
  53.  [Packages]
  54. +  EmbeddedPkg/EmbeddedPkg.dec
  55.    MdeModulePkg/MdeModulePkg.dec
  56.    MdePkg/MdePkg.dec
  57.    Silicon/Marvell/Marvell.dec
  58. diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  59. index 00b5ed5..e69e48a 100644
  60. --- a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  61. +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  62. @@ -33,6 +33,7 @@
  63.    NonDiscoverableInitLib.c
  64.  
  65.  [Packages]
  66. +  EmbeddedPkg/EmbeddedPkg.dec
  67.    MdePkg/MdePkg.dec
  68.    MdeModulePkg/MdeModulePkg.dec
  69.    Silicon/Marvell/Marvell.dec
  70. @@ -42,7 +43,7 @@
  71.    IoLib
  72.  
  73.  [Protocols]
  74. -  gMarvellGpioProtocolGuid
  75. +  gEmbeddedGpioProtocolGuid
  76.  
  77.  [Depex]
  78.    gMarvellPlatformInitCompleteProtocolGuid
  79. diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
  80. index 63a4f66..43e4b9e 100644
  81. --- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
  82. +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
  83. @@ -25,6 +25,7 @@
  84.    Armada80x0McBinBoardDescLib.c
  85.  
  86.  [Packages]
  87. +  EmbeddedPkg/EmbeddedPkg.dec
  88.    MdeModulePkg/MdeModulePkg.dec
  89.    MdePkg/MdePkg.dec
  90.    Silicon/Marvell/Marvell.dec
  91. diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  92. index 66720d2..d0190b6 100644
  93. --- a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  94. +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
  95. @@ -33,6 +33,7 @@
  96.    NonDiscoverableInitLib.c
  97.  
  98.  [Packages]
  99. +  EmbeddedPkg/EmbeddedPkg.dec
  100.    MdePkg/MdePkg.dec
  101.    MdeModulePkg/MdeModulePkg.dec
  102.    Silicon/Marvell/Marvell.dec
  103. @@ -42,7 +43,7 @@
  104.    IoLib
  105.  
  106.  [Protocols]
  107. -  gMarvellGpioProtocolGuid
  108. +  gEmbeddedGpioProtocolGuid
  109.  
  110.  [Depex]
  111.    gMarvellPlatformInitCompleteProtocolGuid
  112. diff --git a/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf b/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
  113. index 5503463..e707fe9 100644
  114. --- a/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
  115. +++ b/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
  116. @@ -25,6 +25,7 @@
  117.    PlatInitDxe.c
  118.  
  119.  [Packages]
  120. +  EmbeddedPkg/EmbeddedPkg.dec
  121.    MdeModulePkg/MdeModulePkg.dec
  122.    MdePkg/MdePkg.dec
  123.    Silicon/Marvell/Marvell.dec
  124. diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
  125. index 2b73b73..48a320c 100644
  126. --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
  127. +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
  128. @@ -24,6 +24,7 @@
  129.    Armada7k8kSoCDescLib.c
  130.  
  131.  [Packages]
  132. +  EmbeddedPkg/EmbeddedPkg.dec
  133.    MdeModulePkg/MdeModulePkg.dec
  134.    MdePkg/MdePkg.dec
  135.    Silicon/Marvell/Marvell.dec
  136. diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
  137. index 0b93948..0b641fe 100644
  138. --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
  139. +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
  140. @@ -42,6 +42,7 @@
  141.    MvBoardDescDxe.h
  142.  
  143.  [Packages]
  144. +  EmbeddedPkg/EmbeddedPkg.dec
  145.    MdeModulePkg/MdeModulePkg.dec
  146.    MdePkg/MdePkg.dec
  147.    Silicon/Marvell/Marvell.dec
  148. diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
  149. index 2d56433..5ff9130 100644
  150. --- a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
  151. +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
  152. @@ -24,6 +24,7 @@
  153.    MvGpioDxe.h
  154.  
  155.  [Packages]
  156. +  EmbeddedPkg/EmbeddedPkg.dec
  157.    MdeModulePkg/MdeModulePkg.dec
  158.    MdePkg/MdePkg.dec
  159.    Silicon/Marvell/Marvell.dec
  160. @@ -36,8 +37,8 @@
  161.    UefiLib
  162.  
  163.  [Protocols]
  164. +  gEmbeddedGpioProtocolGuid
  165.    gMarvellBoardDescProtocolGuid
  166. -  gMarvellGpioProtocolGuid
  167.  
  168.  [Depex]
  169.    TRUE
  170. diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
  171. index 3066732..3b1ab4e 100644
  172. --- a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
  173. +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
  174. @@ -24,6 +24,7 @@
  175.    MvPca95xxDxe.h
  176.  
  177.  [Packages]
  178. +  EmbeddedPkg/EmbeddedPkg.dec
  179.    MdeModulePkg/MdeModulePkg.dec
  180.    MdePkg/MdePkg.dec
  181.    Silicon/Marvell/Marvell.dec
  182. @@ -37,8 +38,8 @@
  183.  [Protocols]
  184.    gEfiDriverBindingProtocolGuid
  185.    gEfiI2cIoProtocolGuid
  186. +  gEmbeddedGpioProtocolGuid
  187.    gMarvellBoardDescProtocolGuid
  188. -  gMarvellGpioProtocolGuid
  189.  
  190.  [Depex]
  191.    TRUE
  192. diff --git a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
  193. index 0eef350..e5bd370 100755
  194. --- a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
  195. +++ b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
  196. @@ -41,6 +41,7 @@
  197.    MvI2cDxe.c
  198.  
  199.  [Packages]
  200. +  EmbeddedPkg/EmbeddedPkg.dec
  201.    MdePkg/MdePkg.dec
  202.    MdeModulePkg/MdeModulePkg.dec
  203.    ArmPlatformPkg/ArmPlatformPkg.dec
  204. diff --git a/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf b/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
  205. index 739576f..8a877da 100644
  206. --- a/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
  207. +++ b/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
  208. @@ -45,6 +45,7 @@
  209.  [Packages]
  210.    ArmPkg/ArmPkg.dec
  211.    ArmPlatformPkg/ArmPlatformPkg.dec
  212. +  EmbeddedPkg/EmbeddedPkg.dec
  213.    MdeModulePkg/MdeModulePkg.dec
  214.    MdePkg/MdePkg.dec
  215.    Silicon/Marvell/Marvell.dec
  216. diff --git a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
  217. index 00c738a..09c5842 100644
  218. --- a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
  219. +++ b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
  220. @@ -35,6 +35,7 @@
  221.    XenonSdMmcOverride.h
  222.  
  223.  [Packages]
  224. +  EmbeddedPkg/EmbeddedPkg.dec
  225.    MdePkg/MdePkg.dec
  226.    MdeModulePkg/MdeModulePkg.dec
  227.    Silicon/Marvell/Marvell.dec
  228. diff --git a/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf b/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
  229. index 36f498b..c360edd 100644
  230. --- a/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
  231. +++ b/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
  232. @@ -41,6 +41,7 @@
  233.  [Packages]
  234.    MdePkg/MdePkg.dec
  235.    MdeModulePkg/MdeModulePkg.dec
  236. +  EmbeddedPkg/EmbeddedPkg.dec
  237.    ArmPkg/ArmPkg.dec
  238.    ArmPlatformPkg/ArmPlatformPkg.dec
  239.    Silicon/Marvell/Marvell.dec
  240. diff --git a/Silicon/Marvell/Library/IcuLib/IcuLib.inf b/Silicon/Marvell/Library/IcuLib/IcuLib.inf
  241. index 0010141..ea662be 100644
  242. --- a/Silicon/Marvell/Library/IcuLib/IcuLib.inf
  243. +++ b/Silicon/Marvell/Library/IcuLib/IcuLib.inf
  244. @@ -24,6 +24,7 @@
  245.    IcuLib.c
  246.  
  247.  [Packages]
  248. +  EmbeddedPkg/EmbeddedPkg.dec
  249.    MdeModulePkg/MdeModulePkg.dec
  250.    MdePkg/MdePkg.dec
  251.    Silicon/Marvell/Marvell.dec
  252. diff --git a/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf b/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
  253. index e2381f4..805a057 100644
  254. --- a/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
  255. +++ b/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
  256. @@ -41,6 +41,7 @@
  257.  [Packages]
  258.    ArmPkg/ArmPkg.dec
  259.    ArmPlatformPkg/ArmPlatformPkg.dec
  260. +  EmbeddedPkg/EmbeddedPkg.dec
  261.    MdeModulePkg/MdeModulePkg.dec
  262.    MdePkg/MdePkg.dec
  263.    Silicon/Marvell/Marvell.dec
  264. diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
  265. new file mode 100644
  266. index 0000000..8a0e424
  267. --- /dev/null
  268. +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
  269. @@ -0,0 +1,23 @@
  270. +/**
  271. +*
  272. +*  Copyright (c) 2018, Marvell International Ltd. All rights reserved.
  273. +*
  274. +*  This program and the accompanying materials are licensed and made available
  275. +*  under the terms and conditions of the BSD License which accompanies this
  276. +*  distribution. The full text of the license may be found at
  277. +*  http://opensource.org/licenses/bsd-license.php
  278. +*
  279. +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  280. +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  281. +*
  282. +**/
  283. +#ifndef __NON_DISCOVERABLE_INIT_LIB_H__
  284. +#define __NON_DISCOVERABLE_INIT_LIB_H__
  285. +
  286. +#define ARMADA_70x0_DB_IO_EXPANDER0       0
  287. +#define ARMADA_70x0_DB_VBUS0_PIN          0
  288. +#define ARMADA_70x0_DB_VBUS0_LIMIT_PIN    4
  289. +#define ARMADA_70x0_DB_VBUS1_PIN          1
  290. +#define ARMADA_70x0_DB_VBUS1_LIMIT_PIN    5
  291. +
  292. +#endif
  293. diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
  294. new file mode 100644
  295. index 0000000..64373ff
  296. --- /dev/null
  297. +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
  298. @@ -0,0 +1,28 @@
  299. +/**
  300. +*
  301. +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
  302. +*  Copyright (c) 2018, Marvell International Ltd. All rights reserved.
  303. +*
  304. +*  This program and the accompanying materials are licensed and made available
  305. +*  under the terms and conditions of the BSD License which accompanies this
  306. +*  distribution. The full text of the license may be found at
  307. +*  http://opensource.org/licenses/bsd-license.php
  308. +*
  309. +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  310. +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  311. +*
  312. +**/
  313. +#ifndef __NON_DISCOVERABLE_INIT_LIB_H__
  314. +#define __NON_DISCOVERABLE_INIT_LIB_H__
  315. +
  316. +#define ARMADA_80x0_DB_IO_EXPANDER0       0
  317. +#define ARMADA_80x0_DB_VBUS0_PIN          0
  318. +#define ARMADA_80x0_DB_VBUS0_LIMIT_PIN    4
  319. +#define ARMADA_80x0_DB_VBUS1_PIN          1
  320. +#define ARMADA_80x0_DB_VBUS1_LIMIT_PIN    5
  321. +
  322. +#define ARMADA_80x0_DB_IO_EXPANDER1       1
  323. +#define ARMADA_80x0_DB_VBUS2_PIN          0
  324. +#define ARMADA_80x0_DB_VBUS2_LIMIT_PIN    4
  325. +
  326. +#endif
  327. diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
  328. new file mode 100644
  329. index 0000000..38e1f20
  330. --- /dev/null
  331. +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
  332. @@ -0,0 +1,20 @@
  333. +/**
  334. +*
  335. +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
  336. +*  Copyright (c) 2018, Marvell International Ltd. All rights reserved.
  337. +*
  338. +*  This program and the accompanying materials are licensed and made available
  339. +*  under the terms and conditions of the BSD License which accompanies this
  340. +*  distribution. The full text of the license may be found at
  341. +*  http://opensource.org/licenses/bsd-license.php
  342. +*
  343. +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  344. +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  345. +*
  346. +**/
  347. +#ifndef __NON_DISCOVERABLE_INIT_LIB_H__
  348. +#define __NON_DISCOVERABLE_INIT_LIB_H__
  349. +
  350. +#define ARMADA_80x0_MCBIN_VBUS0_PIN               15
  351. +
  352. +#endif
  353. diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
  354. index 85dd67c..bfc8639 100644
  355. --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
  356. +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
  357. @@ -22,7 +22,7 @@
  358.  // Common macros
  359.  //
  360.  #define MV_SOC_CP_BASE(Cp)               (0xF2000000 + ((Cp) * 0x2000000))
  361. -#define MV_SOC_AP_COUNT                  1
  362. +#define MV_SOC_AP806_COUNT               1
  363.  
  364.  //
  365.  // Platform description of AHCI controllers
  366. @@ -41,8 +41,8 @@
  367.  //
  368.  // Platform description of GPIO controllers
  369.  //
  370. -#define MV_SOC_AP_GPIO_BASE              0xF06F5040
  371. -#define MV_SOC_AP_GPIO_PIN_COUNT         20
  372. +#define MV_SOC_AP806_GPIO_BASE           0xF06F5040
  373. +#define MV_SOC_AP806_GPIO_PIN_COUNT      20
  374.  #define MV_SOC_GPIO_PER_CP_COUNT         2
  375.  #define MV_SOC_CP_GPIO_BASE(Gpio)        (0x440100 + ((Gpio) * 0x40))
  376.  #define MV_SOC_CP_GPIO_PIN_COUNT(Gpio)   ((Gpio) == 0 ? 32 : 31)
  377. diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
  378. index 48744dc..4e5422b 100644
  379. --- a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
  380. +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
  381. @@ -29,24 +29,21 @@
  382.  
  383.  #include <Uefi/UefiBaseType.h>
  384.  
  385. -#define GPIO_SIGNATURE                   SIGNATURE_32 ('G', 'P', 'I', 'O')
  386. +#define MV_GPIO_SIGNATURE        SIGNATURE_32 ('G', 'P', 'I', 'O')
  387.  
  388. -#ifndef BIT
  389. -#define BIT(nr)                          (1 << (nr))
  390. -#endif
  391. -
  392. -// Marvell GPIO Controller Registers
  393. -#define GPIO_DATA_OUT_REG                (0x0)
  394. -#define GPIO_OUT_EN_REG                  (0x4)
  395. -#define GPIO_BLINK_EN_REG                (0x8)
  396. -#define GPIO_DATA_IN_POL_REG             (0xc)
  397. -#define GPIO_DATA_IN_REG                 (0x10)
  398. +// Marvell MV_GPIO Controller Registers
  399. +#define MV_GPIO_DATA_OUT_REG     (0x0)
  400. +#define MV_GPIO_OUT_EN_REG       (0x4)
  401. +#define MV_GPIO_BLINK_EN_REG     (0x8)
  402. +#define MV_GPIO_DATA_IN_POL_REG  (0xc)
  403. +#define MV_GPIO_DATA_IN_REG      (0x10)
  404.  
  405.  typedef struct {
  406. -  MARVELL_GPIO_PROTOCOL   GpioProtocol;
  407. -  MV_BOARD_GPIO_DESC      *Desc;
  408. -  UINTN                   Signature;
  409. -  EFI_HANDLE              Handle;
  410. +  EMBEDDED_GPIO     GpioProtocol;
  411. +  GPIO_CONTROLLER  *SoCGpio;
  412. +  UINTN             GpioDeviceCount;
  413. +  UINTN             Signature;
  414. +  EFI_HANDLE        Handle;
  415.  } MV_GPIO;
  416.  
  417.  #endif // __MV_GPIO_H__
  418. diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
  419. index 43daee0..1fed739 100644
  420. --- a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
  421. +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
  422. @@ -32,10 +32,6 @@
  423.  
  424.  #define PCA95XX_GPIO_SIGNATURE   SIGNATURE_32 ('I', 'O', 'E', 'X')
  425.  
  426. -#ifndef BIT
  427. -#define BIT(nr)                  (1 << (nr))
  428. -#endif
  429. -
  430.  #define PCA95XX_INPUT_REG        0x0
  431.  #define PCA95XX_OUTPUT_REG       0x2
  432.  #define PCA95XX_DIRECTION_REG    0x6
  433. @@ -58,17 +54,12 @@ typedef enum {
  434.    PCA9557_PIN_COUNT = 16,
  435.  } PCA95XX_PIN_COUNT;
  436.  
  437. -typedef enum {
  438. -  PCA95XX_READ,
  439. -  PCA95XX_WRITE,
  440. -} PCA95XX_OPERATION;
  441. -
  442.  typedef struct {
  443. -  MARVELL_GPIO_PROTOCOL   GpioProtocol;
  444. -  MV_I2C_IO_EXPANDER_DESC *ControllerDesc;
  445. -  UINTN                   ControllerCount;
  446. -  UINTN                   Signature;
  447. -  EFI_HANDLE              ControllerHandle;
  448. +  EMBEDDED_GPIO      GpioProtocol;
  449. +  MV_GPIO_EXPANDER  *GpioExpanders;
  450. +  UINTN              GpioExpanderCount;
  451. +  UINTN              Signature;
  452. +  EFI_HANDLE         ControllerHandle;
  453.  } PCA95XX;
  454.  
  455.  #endif
  456. diff --git a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
  457. index 7629c86..6ec5ace 100644
  458. --- a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
  459. +++ b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
  460. @@ -31,20 +31,20 @@ typedef struct {
  461.    UINTN ChipId;
  462.    UINTN I2cAddress;
  463.    UINTN I2cBus;
  464. -} MV_I2C_IO_EXPANDER_DESC;
  465. +} MV_GPIO_EXPANDER;
  466.  
  467.  typedef struct {
  468. -  MV_SOC_GPIO_DESC        *SoC;
  469. -  UINTN                    GpioDevCount;
  470. -  MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
  471. -  UINTN                    I2cIoExpanderCount;
  472. -} MV_BOARD_GPIO_DESC;
  473. +  GPIO_CONTROLLER  *SoCGpio;
  474. +  UINTN             GpioDeviceCount;
  475. +  MV_GPIO_EXPANDER *GpioExpanders;
  476. +  UINTN             GpioExpanderCount;
  477. +} MV_BOARD_GPIO_DESCRIPTION;
  478.  
  479.  EFI_STATUS
  480.  EFIAPI
  481. -ArmadaBoardDescGpioGet (
  482. -  IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
  483. -  IN OUT UINTN                    *I2cIoExpanderCount
  484. +ArmadaBoardGpioExpanderGet (
  485. +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
  486. +  IN OUT UINTN             *GpioExpanderCount
  487.    );
  488.  
  489.  //
  490. diff --git a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
  491. index f3d4f80..26b075a 100644
  492. --- a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
  493. +++ b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
  494. @@ -17,6 +17,8 @@
  495.  #include <Library/MvComPhyLib.h>
  496.  #include <Library/NonDiscoverableDeviceRegistrationLib.h>
  497.  
  498. +#include <Protocol/EmbeddedGpio.h>
  499. +
  500.  //
  501.  // ComPhy SoC description
  502.  //
  503. @@ -48,16 +50,11 @@ ArmadaSoCDescCpBaseGet (
  504.  //
  505.  // GPIO devices description template definition
  506.  //
  507. -typedef struct {
  508. -  UINTN GpioBaseAddress;
  509. -  UINTN GpioPinCount;
  510. -} MV_SOC_GPIO_DESC;
  511. -
  512.  EFI_STATUS
  513.  EFIAPI
  514. -ArmadaSoCDescGpioGet (
  515. -  IN OUT MV_SOC_GPIO_DESC  **GpioDesc,
  516. -  IN OUT UINTN              *DescCount
  517. +ArmadaSoCGpioGet (
  518. +  IN OUT GPIO_CONTROLLER  **SoCGpioDescription,
  519. +  IN OUT UINTN             *Count
  520.    );
  521.  
  522.  //
  523. diff --git a/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
  524. index eaffce3..18de24f 100644
  525. --- a/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
  526. +++ b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
  527. @@ -20,7 +20,7 @@
  528.  
  529.  NON_DISCOVERABLE_DEVICE_INIT
  530.  EFIAPI
  531. -GetInitializerForType (
  532. +NonDiscoverableDeviceInitializerGet (
  533.    IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
  534.    IN  UINTN                         Index
  535.    );
  536. diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h
  537. index e06d689..02905ea 100644
  538. --- a/Silicon/Marvell/Include/Protocol/BoardDesc.h
  539. +++ b/Silicon/Marvell/Include/Protocol/BoardDesc.h
  540. @@ -50,9 +50,9 @@ EFI_STATUS
  541.  
  542.  typedef
  543.  EFI_STATUS
  544. -(EFIAPI *MV_BOARD_DESC_GPIO_GET) (
  545. -  IN MARVELL_BOARD_DESC_PROTOCOL  *This,
  546. -  IN OUT MV_BOARD_GPIO_DESC      **GpioDesc
  547. +(EFIAPI *MV_BOARD_GPIO_DESCRIPTION_GET) (
  548. +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
  549. +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
  550.    );
  551.  
  552.  typedef
  553. @@ -113,7 +113,6 @@ VOID
  554.  struct _MARVELL_BOARD_DESC_PROTOCOL {
  555.    MV_BOARD_DESC_AHCI_GET         BoardDescAhciGet;
  556.    MV_BOARD_DESC_COMPHY_GET       BoardDescComPhyGet;
  557. -  MV_BOARD_DESC_GPIO_GET         BoardDescGpioGet;
  558.    MV_BOARD_DESC_I2C_GET          BoardDescI2cGet;
  559.    MV_BOARD_DESC_MDIO_GET         BoardDescMdioGet;
  560.    MV_BOARD_DESC_PP2_GET          BoardDescPp2Get;
  561. @@ -121,6 +120,7 @@ struct _MARVELL_BOARD_DESC_PROTOCOL {
  562.    MV_BOARD_DESC_UTMI_GET         BoardDescUtmiGet;
  563.    MV_BOARD_DESC_XHCI_GET         BoardDescXhciGet;
  564.    MV_BOARD_DESC_FREE             BoardDescFree;
  565. +  MV_BOARD_GPIO_DESCRIPTION_GET  GpioDescriptionGet;
  566.  };
  567.  
  568.  #endif // __MARVELL_BOARD_DESC_PROTOCOL_H__
  569. diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
  570. index a335cab..8bddd2f 100644
  571. --- a/Silicon/Marvell/Include/Protocol/MvGpio.h
  572. +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
  573. @@ -11,8 +11,8 @@
  574.  *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  575.  *
  576.  **/
  577. -#ifndef __MARVELL_GPIO_PROTOCOL_H__
  578. -#define __MARVELL_GPIO_PROTOCOL_H__
  579. +#ifndef __MV_GPIO_PROTOCOL_H__
  580. +#define __MV_GPIO_PROTOCOL_H__
  581.  
  582.  #include <Uefi.h>
  583.  
  584. @@ -21,19 +21,22 @@
  585.  #include <Library/MemoryAllocationLib.h>
  586.  #include <Library/UefiBootServicesTableLib.h>
  587.  
  588. -extern EFI_GUID gMarvellGpioProtocolGuid;
  589. -
  590. -typedef struct _MARVELL_GPIO_PROTOCOL MARVELL_GPIO_PROTOCOL;
  591. +#include <Protocol/EmbeddedGpio.h>
  592.  
  593.  typedef enum {
  594. -  GPIO_MODE_INPUT                 = 0x0,
  595. -  GPIO_MODE_OUTPUT                = 0x1
  596. -} MARVELL_GPIO_MODE;
  597. +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
  598. +  MV_GPIO_DRIVER_TYPE_PCA95X,
  599. +} MV_GPIO_DRIVER_TYPE;
  600.  
  601.  typedef enum {
  602. -  GPIO_DRIVER_TYPE_SOC_CONTROLLER = 0x0,
  603. -  GPIO_DRIVER_TYPE_PCA95XX        = 0x1
  604. -} MARVELL_GPIO_DRIVER_TYPE;
  605. +  MV_GPIO_AP806_CONTROLLER0,
  606. +  MV_GPIO_CP0_CONTROLLER0,
  607. +  MV_GPIO_CP0_CONTROLLER1,
  608. +  MV_GPIO_CP1_CONTROLLER0,
  609. +  MV_GPIO_CP1_CONTROLLER1,
  610. +  MV_GPIO_CP2_CONTROLLER0,
  611. +  MV_GPIO_CP2_CONTROLLER1,
  612. +} MV_GPIO_SOC_CONTROLLER_TYPE;
  613.  
  614.  typedef enum {
  615.    PCA9505_ID,
  616. @@ -48,74 +51,64 @@ typedef enum {
  617.    PCA9556_ID,
  618.    PCA9557_ID,
  619.    PCA95XX_MAX_ID,
  620. -} MARVELL_IO_EXPANDER_TYPE_PCA95XX;
  621. -
  622. -typedef
  623. -EFI_STATUS
  624. -(EFIAPI *MV_GPIO_DIRECTION_OUTPUT) (
  625. -  IN  MARVELL_GPIO_PROTOCOL *This,
  626. -  IN  UINTN ControllerIndex,
  627. -  IN  UINTN GpioPin,
  628. -  IN  BOOLEAN Value
  629. -  );
  630. -
  631. -typedef
  632. -EFI_STATUS
  633. -(EFIAPI *MV_GPIO_DIRECTION_INPUT) (
  634. -  IN  MARVELL_GPIO_PROTOCOL *This,
  635. -  IN  UINTN ControllerIndex,
  636. -  IN  UINTN GpioPin
  637. -  );
  638. -
  639. -typedef
  640. -EFI_STATUS
  641. -(EFIAPI *MV_GPIO_GET_FUNCTION) (
  642. -  IN  MARVELL_GPIO_PROTOCOL *This,
  643. -  IN  UINTN ControllerIndex,
  644. -  IN  UINTN GpioPin,
  645. -  OUT MARVELL_GPIO_MODE *Mode
  646. -  );
  647. -
  648. -typedef
  649. -EFI_STATUS
  650. -(EFIAPI *MV_GPIO_GET_VALUE) (
  651. -  IN  MARVELL_GPIO_PROTOCOL *This,
  652. -  IN  UINTN ControllerIndex,
  653. -  IN  UINTN GpioPin,
  654. -  OUT BOOLEAN *Value
  655. -  );
  656. -
  657. -typedef
  658. -EFI_STATUS
  659. -(EFIAPI *MV_GPIO_SET_VALUE) (
  660. -  IN  MARVELL_GPIO_PROTOCOL *This,
  661. -  IN  UINTN ControllerIndex,
  662. -  IN  UINTN GpioPin,
  663. -  IN  BOOLEAN Value
  664. -  );
  665. -
  666. -struct _MARVELL_GPIO_PROTOCOL {
  667. -  MV_GPIO_DIRECTION_INPUT       DirectionInput;
  668. -  MV_GPIO_DIRECTION_OUTPUT      DirectionOutput;
  669. -  MV_GPIO_GET_FUNCTION          GetFunction;
  670. -  MV_GPIO_GET_VALUE             GetValue;
  671. -  MV_GPIO_SET_VALUE             SetValue;
  672. -};
  673. +} MV_GPIO_EXPANDER_TYPE_PCA95XX;
  674.  
  675.  typedef struct {
  676. -  VENDOR_DEVICE_PATH            Header;
  677. -  MARVELL_GPIO_DRIVER_TYPE      GpioDriverType;
  678. -  EFI_DEVICE_PATH_PROTOCOL      End;
  679. +  VENDOR_DEVICE_PATH        Header;
  680. +  MV_GPIO_DRIVER_TYPE       GpioDriverType;
  681. +  EFI_DEVICE_PATH_PROTOCOL  End;
  682.  } MV_GPIO_DEVICE_PATH;
  683.  
  684.  typedef struct {
  685. -  UINTN                         ControllerId;
  686. -  UINTN                         PinNumber;
  687. -  BOOLEAN                       ActiveHigh;
  688. -} GPIO_PIN_DESC;
  689. +  UINTN    ControllerId;
  690. +  UINTN    PinNumber;
  691. +  BOOLEAN  ActiveHigh;
  692. +} MV_GPIO_PIN;
  693.  
  694.  /*
  695. - * Select desired protocol producer upon MARVELL_GPIO_DRIVER_TYPE
  696. + * Check if the driver type matches the requested value.
  697. + * In case of the success open the GPIO protocol and return.
  698. + */
  699. +STATIC
  700. +inline
  701. +EFI_STATUS
  702. +EFIAPI
  703. +MvGpioFindMatchingDriver (
  704. +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
  705. +  IN     EFI_HANDLE             HandleBuffer,
  706. +  IN     EFI_DEVICE_PATH       *DevicePath,
  707. +  IN OUT EMBEDDED_GPIO        **GpioProtocol
  708. +  )
  709. +{
  710. +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
  711. +  EFI_STATUS           Status;
  712. +
  713. +  while (!IsDevicePathEndType (DevicePath)) {
  714. +    /* Check if GpioDriverType matches one found in the device path */
  715. +    GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
  716. +    if (GpioDevicePath->GpioDriverType != GpioDriverType) {
  717. +      DevicePath = NextDevicePathNode (DevicePath);
  718. +      continue;
  719. +    }
  720. +
  721. +    /*
  722. +     * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
  723. +     * the consumer is not obliged to call CloseProtocol.
  724. +     */
  725. +    Status = gBS->OpenProtocol (HandleBuffer,
  726. +                    &gEmbeddedGpioProtocolGuid,
  727. +                    (VOID **)GpioProtocol,
  728. +                    gImageHandle,
  729. +                    NULL,
  730. +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
  731. +    return Status;
  732. +  }
  733. +
  734. +  return EFI_NOT_FOUND;
  735. +}
  736. +
  737. +/*
  738. + * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE
  739.   * field of driver's MV_GPIO_DEVICE_PATH.
  740.   */
  741.  STATIC
  742. @@ -123,20 +116,19 @@ inline
  743.  EFI_STATUS
  744.  EFIAPI
  745.  MvGpioGetProtocol (
  746. -  IN     MARVELL_GPIO_DRIVER_TYPE     GpioDriverType,
  747. -  IN OUT MARVELL_GPIO_PROTOCOL      **GpioProtocol
  748. +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
  749. +  IN OUT EMBEDDED_GPIO        **GpioProtocol
  750.    )
  751.  {
  752. -  MV_GPIO_DEVICE_PATH *GpioDevicePath;
  753.    EFI_DEVICE_PATH     *DevicePath;
  754.    EFI_HANDLE          *HandleBuffer;
  755.    EFI_STATUS           Status;
  756.    UINTN                HandleCount;
  757.    UINTN                Index;
  758.  
  759. -  /* Locate Handles of all MARVELL_GPIO_PROTOCOL producers */
  760. +  /* Locate Handles of all EMBEDDED_GPIO producers */
  761.    Status = gBS->LocateHandleBuffer (ByProtocol,
  762. -                  &gMarvellGpioProtocolGuid,
  763. +                  &gEmbeddedGpioProtocolGuid,
  764.                    NULL,
  765.                    &HandleCount,
  766.                    &HandleBuffer);
  767. @@ -159,41 +151,32 @@ MvGpioGetProtocol (
  768.        continue;
  769.      }
  770.  
  771. -    while (!IsDevicePathEndType (DevicePath)) {
  772. -      /* Check if GpioDriverType matches one found in the device path */
  773. -      GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
  774. -      if (GpioDevicePath->GpioDriverType != GpioDriverType) {
  775. -        DevicePath = NextDevicePathNode (DevicePath);
  776. -        continue;
  777. -      }
  778. -
  779. -      /*
  780. -       * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
  781. -       * the consumer is not obliged to call CloseProtocol.
  782. -       */
  783. -      Status = gBS->OpenProtocol (HandleBuffer[Index],
  784. -                      &gMarvellGpioProtocolGuid,
  785. -                      (VOID **)GpioProtocol,
  786. -                      gImageHandle,
  787. -                      NULL,
  788. -                      EFI_OPEN_PROTOCOL_GET_PROTOCOL);
  789. -      if (EFI_ERROR (Status)) {
  790. -        DEBUG ((DEBUG_ERROR,
  791. -          "%a: Unable to open GPIO protocol\n",
  792. -          __FUNCTION__));
  793. -        gBS->FreePool (HandleBuffer);
  794. -        return Status;
  795. -      }
  796. -
  797. -      gBS->FreePool (HandleBuffer);
  798. -
  799. -      return EFI_SUCCESS;
  800. +    /*
  801. +     * Check if the driver type matches the requested value.
  802. +     * In case of the success open the GPIO protocol and return.
  803. +     * If there is no match, repeat procedure with the next handle.
  804. +     */
  805. +    Status = MvGpioFindMatchingDriver (GpioDriverType,
  806. +               HandleBuffer[Index],
  807. +               DevicePath,
  808. +               GpioProtocol);
  809. +    if (Status == EFI_NOT_FOUND) {
  810. +      continue;
  811. +    } else if (EFI_ERROR (Status)) {
  812. +      DEBUG ((DEBUG_ERROR,
  813. +        "%a: Unable to open GPIO protocol\n",
  814. +        __FUNCTION__));
  815.      }
  816. +
  817. +    gBS->FreePool (HandleBuffer);
  818. +
  819. +    return Status;
  820.    }
  821.  
  822. +  /* No matching GPIO protocol producer was found */
  823.    gBS->FreePool (HandleBuffer);
  824.  
  825. -  return EFI_UNSUPPORTED;
  826. +  return EFI_NOT_FOUND;
  827.  }
  828.  
  829. -#endif // __MARVELL_GPIO_PROTOCOL_H__
  830. +#endif // __MV_GPIO_PROTOCOL_H__
  831. diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
  832. index 7d788fb..9595b01 100644
  833. --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
  834. +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
  835. @@ -24,6 +24,29 @@
  836.  #include <Protocol/MvGpio.h>
  837.  
  838.  //
  839. +// GPIO Expander
  840. +//
  841. +STATIC MV_GPIO_EXPANDER mGpioExpander = {
  842. +  PCA9555_ID,
  843. +  0x21,
  844. +  0x0,
  845. +};
  846. +
  847. +
  848. +EFI_STATUS
  849. +EFIAPI
  850. +ArmadaBoardGpioExpanderGet (
  851. +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
  852. +  IN OUT UINTN             *GpioExpanderCount
  853. +  )
  854. +{
  855. +  *GpioExpanderCount = 1;
  856. +  *GpioExpanders = &mGpioExpander;
  857. +
  858. +  return EFI_SUCCESS;
  859. +}
  860. +
  861. +//
  862.  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
  863.  //
  864.  STATIC
  865. @@ -48,12 +71,6 @@ MV_BOARD_SDMMC_DESC mSdMmcDescTemplate[] = {
  866.    }
  867.  };
  868.  
  869. -STATIC MV_I2C_IO_EXPANDER_DESC mI2cIoExpanderDescTemplate = {
  870. -  PCA9555_ID,
  871. -  0x21,
  872. -  0x0,
  873. -};
  874. -
  875.  EFI_STATUS
  876.  EFIAPI
  877.  ArmadaBoardDescSdMmcGet (
  878. @@ -66,16 +83,3 @@ ArmadaBoardDescSdMmcGet (
  879.  
  880.    return EFI_SUCCESS;
  881.  }
  882. -
  883. -EFI_STATUS
  884. -EFIAPI
  885. -ArmadaBoardDescGpioGet (
  886. -  IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
  887. -  IN OUT UINTN                    *I2cIoExpanderCount
  888. -  )
  889. -{
  890. -  *I2cIoExpanderCount = 1;
  891. -  *I2cIoExpanderDesc = &mI2cIoExpanderDescTemplate;
  892. -
  893. -  return EFI_SUCCESS;
  894. -}
  895. diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  896. index a93576e..586b189 100644
  897. --- a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  898. +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  899. @@ -25,13 +25,9 @@
  900.  #include <Protocol/MvGpio.h>
  901.  #include <Protocol/NonDiscoverableDevice.h>
  902.  
  903. -#define ARMADA_70x0_DB_IO_EXPANDER0       0
  904. -#define ARMADA_70x0_DB_VBUS0_PIN          0
  905. -#define ARMADA_70x0_DB_VBUS0_LIMIT_PIN    4
  906. -#define ARMADA_70x0_DB_VBUS1_PIN          1
  907. -#define ARMADA_70x0_DB_VBUS1_LIMIT_PIN    5
  908. +#include "NonDiscoverableInitLib.h"
  909.  
  910. -STATIC CONST GPIO_PIN_DESC mArmada70x0DbVbusEn[] = {
  911. +STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
  912.    {
  913.      ARMADA_70x0_DB_IO_EXPANDER0,
  914.      ARMADA_70x0_DB_VBUS0_PIN,
  915. @@ -57,28 +53,29 @@ STATIC CONST GPIO_PIN_DESC mArmada70x0DbVbusEn[] = {
  916.  STATIC
  917.  EFI_STATUS
  918.  EFIAPI
  919. -Armada70x0DbInitXhciVbus (
  920. -  IN  NON_DISCOVERABLE_DEVICE       *This
  921. +XhciInit (
  922. +  IN  NON_DISCOVERABLE_DEVICE  *This
  923.    )
  924.  {
  925. -  CONST GPIO_PIN_DESC     *VbusEnPinDesc;
  926. -  MARVELL_GPIO_PROTOCOL   *GpioProtocol;
  927. -  EFI_STATUS              Status;
  928. -  UINTN                   Index;
  929. +  CONST MV_GPIO_PIN   *VbusPin;
  930. +  EMBEDDED_GPIO_MODE   Mode;
  931. +  EMBEDDED_GPIO_PIN    Gpio;
  932. +  EMBEDDED_GPIO       *GpioProtocol;
  933. +  EFI_STATUS           Status;
  934. +  UINTN                Index;
  935.  
  936. -  Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
  937. +  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
  938.    if (EFI_ERROR (Status)) {
  939.      DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
  940.      return Status;
  941.    }
  942.  
  943. -  VbusEnPinDesc = mArmada70x0DbVbusEn;
  944. -  for (Index = 0; Index < ARRAY_SIZE (mArmada70x0DbVbusEn); Index++) {
  945. -    GpioProtocol->DirectionOutput (GpioProtocol,
  946. -                    VbusEnPinDesc->ControllerId,
  947. -                    VbusEnPinDesc->PinNumber,
  948. -                    VbusEnPinDesc->ActiveHigh);
  949. -    VbusEnPinDesc++;
  950. +  VbusPin = mXhciVbusPins;
  951. +  for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
  952. +    Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
  953. +    Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
  954. +    GpioProtocol->Set (GpioProtocol, Gpio, Mode);
  955. +    VbusPin++;
  956.    }
  957.  
  958.    return EFI_SUCCESS;
  959. @@ -86,13 +83,13 @@ Armada70x0DbInitXhciVbus (
  960.  
  961.  NON_DISCOVERABLE_DEVICE_INIT
  962.  EFIAPI
  963. -GetInitializerForType (
  964. +NonDiscoverableDeviceInitializerGet (
  965.    IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
  966.    IN  UINTN                         Index
  967.    )
  968.  {
  969.    if (Type == NonDiscoverableDeviceTypeXhci) {
  970. -        return Armada70x0DbInitXhciVbus;
  971. +        return XhciInit;
  972.    }
  973.  
  974.    return NULL;
  975. diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
  976. index ef6023f..a1ac4bf 100644
  977. --- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
  978. +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
  979. @@ -24,6 +24,35 @@
  980.  #include <Protocol/MvGpio.h>
  981.  
  982.  //
  983. +// GPIO Expanders
  984. +//
  985. +STATIC MV_GPIO_EXPANDER mGpioExpanders[] = {
  986. +  {
  987. +    PCA9555_ID,
  988. +    0x21,
  989. +    0x0,
  990. +  },
  991. +  {
  992. +    PCA9555_ID,
  993. +    0x25,
  994. +    0x0,
  995. +  },
  996. +};
  997. +
  998. +EFI_STATUS
  999. +EFIAPI
  1000. +ArmadaBoardGpioExpanderGet (
  1001. +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
  1002. +  IN OUT UINTN             *GpioExpanderCount
  1003. +  )
  1004. +{
  1005. +  *GpioExpanderCount = ARRAY_SIZE (mGpioExpanders);
  1006. +  *GpioExpanders = mGpioExpanders;
  1007. +
  1008. +  return EFI_SUCCESS;
  1009. +}
  1010. +
  1011. +//
  1012.  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
  1013.  //
  1014.  STATIC
  1015. @@ -48,19 +77,6 @@ MV_BOARD_SDMMC_DESC mSdMmcDescTemplate[] = {
  1016.    }
  1017.  };
  1018.  
  1019. -STATIC MV_I2C_IO_EXPANDER_DESC mI2cIoExpanderDescTemplate[] = {
  1020. -  {
  1021. -    PCA9555_ID,
  1022. -    0x21,
  1023. -    0x0,
  1024. -  },
  1025. -  {
  1026. -    PCA9555_ID,
  1027. -    0x25,
  1028. -    0x0,
  1029. -  },
  1030. -};
  1031. -
  1032.  EFI_STATUS
  1033.  EFIAPI
  1034.  ArmadaBoardDescSdMmcGet (
  1035. @@ -73,16 +89,3 @@ ArmadaBoardDescSdMmcGet (
  1036.  
  1037.    return EFI_SUCCESS;
  1038.  }
  1039. -
  1040. -EFI_STATUS
  1041. -EFIAPI
  1042. -ArmadaBoardDescGpioGet (
  1043. -  IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
  1044. -  IN OUT UINTN                    *I2cIoExpanderCount
  1045. -  )
  1046. -{
  1047. -  *I2cIoExpanderCount = ARRAY_SIZE (mI2cIoExpanderDescTemplate);
  1048. -  *I2cIoExpanderDesc = mI2cIoExpanderDescTemplate;
  1049. -
  1050. -  return EFI_SUCCESS;
  1051. -}
  1052. diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  1053. index 05f6b89..3988f9a 100644
  1054. --- a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  1055. +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  1056. @@ -25,17 +25,9 @@
  1057.  #include <Protocol/MvGpio.h>
  1058.  #include <Protocol/NonDiscoverableDevice.h>
  1059.  
  1060. -#define ARMADA_80x0_DB_IO_EXPANDER0       0
  1061. -#define ARMADA_80x0_DB_VBUS0_PIN          0
  1062. -#define ARMADA_80x0_DB_VBUS0_LIMIT_PIN    4
  1063. -#define ARMADA_80x0_DB_VBUS1_PIN          1
  1064. -#define ARMADA_80x0_DB_VBUS1_LIMIT_PIN    5
  1065. +#include "NonDiscoverableInitLib.h"
  1066.  
  1067. -#define ARMADA_80x0_DB_IO_EXPANDER1       1
  1068. -#define ARMADA_80x0_DB_VBUS2_PIN          0
  1069. -#define ARMADA_80x0_DB_VBUS2_LIMIT_PIN    4
  1070. -
  1071. -STATIC CONST GPIO_PIN_DESC mArmada80x0DbVbusEn[] = {
  1072. +STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
  1073.    {
  1074.      ARMADA_80x0_DB_IO_EXPANDER0,
  1075.      ARMADA_80x0_DB_VBUS0_PIN,
  1076. @@ -71,28 +63,29 @@ STATIC CONST GPIO_PIN_DESC mArmada80x0DbVbusEn[] = {
  1077.  STATIC
  1078.  EFI_STATUS
  1079.  EFIAPI
  1080. -Armada80x0DbInitXhciVbus (
  1081. -  IN  NON_DISCOVERABLE_DEVICE       *This
  1082. +XhciInit (
  1083. +  IN  NON_DISCOVERABLE_DEVICE  *This
  1084.    )
  1085.  {
  1086. -  CONST GPIO_PIN_DESC     *VbusEnPinDesc;
  1087. -  MARVELL_GPIO_PROTOCOL   *GpioProtocol;
  1088. -  EFI_STATUS              Status;
  1089. -  UINTN                   Index;
  1090. +  CONST MV_GPIO_PIN   *VbusPin;
  1091. +  EMBEDDED_GPIO_MODE   Mode;
  1092. +  EMBEDDED_GPIO_PIN    Gpio;
  1093. +  EMBEDDED_GPIO       *GpioProtocol;
  1094. +  EFI_STATUS           Status;
  1095. +  UINTN                Index;
  1096.  
  1097. -  Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
  1098. +  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
  1099.    if (EFI_ERROR (Status)) {
  1100.      DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
  1101.      return Status;
  1102.    }
  1103.  
  1104. -  VbusEnPinDesc = mArmada80x0DbVbusEn;
  1105. -  for (Index = 0; Index < ARRAY_SIZE (mArmada80x0DbVbusEn); Index++) {
  1106. -    GpioProtocol->DirectionOutput (GpioProtocol,
  1107. -                    VbusEnPinDesc->ControllerId,
  1108. -                    VbusEnPinDesc->PinNumber,
  1109. -                    VbusEnPinDesc->ActiveHigh);
  1110. -    VbusEnPinDesc++;
  1111. +  VbusPin = mXhciVbusPins;
  1112. +  for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
  1113. +    Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
  1114. +    Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
  1115. +    GpioProtocol->Set (GpioProtocol, Gpio, Mode);
  1116. +    VbusPin++;
  1117.    }
  1118.  
  1119.    return EFI_SUCCESS;
  1120. @@ -100,13 +93,13 @@ Armada80x0DbInitXhciVbus (
  1121.  
  1122.  NON_DISCOVERABLE_DEVICE_INIT
  1123.  EFIAPI
  1124. -GetInitializerForType (
  1125. +NonDiscoverableDeviceInitializerGet (
  1126.    IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
  1127.    IN  UINTN                         Index
  1128.    )
  1129.  {
  1130.    if (Type == NonDiscoverableDeviceTypeXhci) {
  1131. -        return Armada80x0DbInitXhciVbus;
  1132. +        return XhciInit;
  1133.    }
  1134.  
  1135.    return NULL;
  1136. diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
  1137. index 3f4e404..32596ad 100644
  1138. --- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
  1139. +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
  1140. @@ -22,6 +22,23 @@
  1141.  #include <Library/UefiBootServicesTableLib.h>
  1142.  
  1143.  //
  1144. +// GPIO Expander
  1145. +//
  1146. +EFI_STATUS
  1147. +EFIAPI
  1148. +ArmadaBoardGpioExpanderGet (
  1149. +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
  1150. +  IN OUT UINTN             *GpioExpanderCount
  1151. +  )
  1152. +{
  1153. +  /* No GPIO expanders on board */
  1154. +  *GpioExpanders = NULL;
  1155. +  *GpioExpanderCount = 0;
  1156. +
  1157. +  return EFI_SUCCESS;
  1158. +}
  1159. +
  1160. +//
  1161.  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
  1162.  //
  1163.  STATIC
  1164. @@ -58,17 +75,3 @@ ArmadaBoardDescSdMmcGet (
  1165.  
  1166.    return EFI_SUCCESS;
  1167.  }
  1168. -
  1169. -EFI_STATUS
  1170. -EFIAPI
  1171. -ArmadaBoardDescGpioGet (
  1172. -  IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
  1173. -  IN OUT UINTN                    *I2cIoExpanderCount
  1174. -  )
  1175. -{
  1176. -  /* No I2C IO expanders on board */
  1177. -  *I2cIoExpanderDesc = NULL;
  1178. -  *I2cIoExpanderCount = 0;
  1179. -
  1180. -  return EFI_SUCCESS;
  1181. -}
  1182. diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  1183. index 764b3b8..676feeb 100644
  1184. --- a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  1185. +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
  1186. @@ -25,11 +25,10 @@
  1187.  #include <Protocol/MvGpio.h>
  1188.  #include <Protocol/NonDiscoverableDevice.h>
  1189.  
  1190. -#define ARMADA_80x0_CP0_CONTROLLER1_INDEX   2
  1191. -#define ARMADA_80x0_MCBIN_VBUS0_PIN         15
  1192. +#include "NonDiscoverableInitLib.h"
  1193.  
  1194. -STATIC CONST GPIO_PIN_DESC mArmada80x0McBinVbusEn = {
  1195. -  ARMADA_80x0_CP0_CONTROLLER1_INDEX,
  1196. +STATIC CONST MV_GPIO_PIN mXhciVbusPin = {
  1197. +  MV_GPIO_CP0_CONTROLLER1,
  1198.    ARMADA_80x0_MCBIN_VBUS0_PIN,
  1199.    TRUE,
  1200.  };
  1201. @@ -37,36 +36,35 @@ STATIC CONST GPIO_PIN_DESC mArmada80x0McBinVbusEn = {
  1202.  STATIC
  1203.  EFI_STATUS
  1204.  EFIAPI
  1205. -Armada80x0McBinInitXhciVbus (
  1206. -  IN  NON_DISCOVERABLE_DEVICE       *This
  1207. +XhciInit (
  1208. +  IN  NON_DISCOVERABLE_DEVICE  *This
  1209.    )
  1210.  {
  1211. -  MARVELL_GPIO_PROTOCOL   *GpioProtocol;
  1212. -  EFI_STATUS              Status;
  1213. +  EMBEDDED_GPIO  *GpioProtocol;
  1214. +  EFI_STATUS      Status;
  1215.  
  1216. -  Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_SOC_CONTROLLER, &GpioProtocol);
  1217. +  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER, &GpioProtocol);
  1218.    if (EFI_ERROR (Status)) {
  1219.      DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
  1220.      return Status;
  1221.    }
  1222.  
  1223. -  GpioProtocol->DirectionOutput (GpioProtocol,
  1224. -                  mArmada80x0McBinVbusEn.ControllerId,
  1225. -                  mArmada80x0McBinVbusEn.PinNumber,
  1226. -                  mArmada80x0McBinVbusEn.ActiveHigh);
  1227. +  GpioProtocol->Set (GpioProtocol,
  1228. +                  GPIO (mXhciVbusPin.ControllerId, mXhciVbusPin.PinNumber),
  1229. +                  GPIO_MODE_OUTPUT_1);
  1230.  
  1231.    return Status;
  1232.  }
  1233.  
  1234.  NON_DISCOVERABLE_DEVICE_INIT
  1235.  EFIAPI
  1236. -GetInitializerForType (
  1237. +NonDiscoverableDeviceInitializerGet (
  1238.    IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
  1239.    IN  UINTN                         Index
  1240.    )
  1241.  {
  1242.    if (Type == NonDiscoverableDeviceTypeXhci) {
  1243. -        return Armada80x0McBinInitXhciVbus;
  1244. +        return XhciInit;
  1245.    }
  1246.  
  1247.    return NULL;
  1248. diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
  1249. index 7db4ec7..5b72c20 100644
  1250. --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
  1251. +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
  1252. @@ -74,37 +74,37 @@ ArmadaSoCDescCpBaseGet (
  1253.  
  1254.  EFI_STATUS
  1255.  EFIAPI
  1256. -ArmadaSoCDescGpioGet (
  1257. -  IN OUT MV_SOC_GPIO_DESC  **GpioDesc,
  1258. -  IN OUT UINTN             *DescCount
  1259. +ArmadaSoCGpioGet (
  1260. +  IN OUT GPIO_CONTROLLER  **SoCGpioDescription,
  1261. +  IN OUT UINTN             *Count
  1262.    )
  1263.  {
  1264. -  MV_SOC_GPIO_DESC *Desc;
  1265. +  GPIO_CONTROLLER *GpioInstance;
  1266.    UINTN CpCount, CpIndex, Index;
  1267.  
  1268.    CpCount = FixedPcdGet8 (PcdMaxCpCount);
  1269.  
  1270. -  *DescCount = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP_COUNT;
  1271. -  Desc = AllocateZeroPool (*DescCount * sizeof (MV_SOC_GPIO_DESC));
  1272. -  if (Desc == NULL) {
  1273. +  *Count = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP806_COUNT;
  1274. +  GpioInstance = AllocateZeroPool (*Count * sizeof (GPIO_CONTROLLER));
  1275. +  if (GpioInstance == NULL) {
  1276.      DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
  1277.      return EFI_OUT_OF_RESOURCES;
  1278.    }
  1279.  
  1280. -  *GpioDesc = Desc;
  1281. +  *SoCGpioDescription = GpioInstance;
  1282.  
  1283. -  /* AP GPIO controller */
  1284. -  Desc->GpioBaseAddress = MV_SOC_AP_GPIO_BASE;
  1285. -  Desc->GpioPinCount = MV_SOC_AP_GPIO_PIN_COUNT;
  1286. -  Desc++;
  1287. +  /* AP806 GPIO controller */
  1288. +  GpioInstance->RegisterBase = MV_SOC_AP806_GPIO_BASE;
  1289. +  GpioInstance->InternalGpioCount = MV_SOC_AP806_GPIO_PIN_COUNT;
  1290. +  GpioInstance++;
  1291.  
  1292. -  /* CP GPIO controllers */
  1293. +  /* CP110 GPIO controllers */
  1294.    for (CpIndex = 0; CpIndex < CpCount; CpIndex++) {
  1295.      for (Index = 0; Index < MV_SOC_GPIO_PER_CP_COUNT; Index++) {
  1296. -      Desc->GpioBaseAddress = MV_SOC_CP_BASE (CpIndex) +
  1297. -                              MV_SOC_CP_GPIO_BASE (Index);
  1298. -      Desc->GpioPinCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
  1299. -      Desc++;
  1300. +      GpioInstance->RegisterBase = MV_SOC_CP_BASE (CpIndex) +
  1301. +                                   MV_SOC_CP_GPIO_BASE (Index);
  1302. +      GpioInstance->InternalGpioCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
  1303. +      GpioInstance++;
  1304.      }
  1305.    }
  1306.  
  1307. diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
  1308. index c5305b7..e348b85 100644
  1309. --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
  1310. +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
  1311. @@ -100,47 +100,42 @@ MvBoardDescComPhyGet (
  1312.  
  1313.  STATIC
  1314.  EFI_STATUS
  1315. -MvBoardDescGpioGet (
  1316. -  IN MARVELL_BOARD_DESC_PROTOCOL  *This,
  1317. -  IN OUT MV_BOARD_GPIO_DESC      **GpioDesc
  1318. +MvBoardGpioDescriptionGet (
  1319. +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
  1320. +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
  1321.    )
  1322.  {
  1323. -  MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
  1324. -  UINTN SoCGpioCount, I2cIoExpanderCount;
  1325. -  STATIC MV_BOARD_GPIO_DESC *BoardDesc;
  1326. -  MV_SOC_GPIO_DESC *SoCDesc;
  1327. +  MV_BOARD_GPIO_DESCRIPTION *Description;
  1328. +  UINTN SoCGpioCount, GpioExpanderCount;
  1329. +  MV_GPIO_EXPANDER *GpioExpanders;
  1330. +  GPIO_CONTROLLER *SoCGpio;
  1331.    EFI_STATUS Status;
  1332.  
  1333. -  if (BoardDesc != NULL) {
  1334. -    *GpioDesc = BoardDesc;
  1335. -    return EFI_SUCCESS;
  1336. -  }
  1337. -
  1338.    /* Get SoC data about all available GPIO controllers */
  1339. -  Status = ArmadaSoCDescGpioGet (&SoCDesc, &SoCGpioCount);
  1340. +  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
  1341.    if (EFI_ERROR (Status)) {
  1342.      return Status;
  1343.    }
  1344.  
  1345.    /* Get per-board information about all available I2C IO expanders */
  1346. -  Status = ArmadaBoardDescGpioGet (&I2cIoExpanderDesc, &I2cIoExpanderCount);
  1347. +  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
  1348.    if (EFI_ERROR (Status)) {
  1349.      return Status;
  1350.    }
  1351.  
  1352.    /* Allocate and fill board description */
  1353. -  BoardDesc = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESC));
  1354. -  if (BoardDesc == NULL) {
  1355. +  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));
  1356. +  if (Description == NULL) {
  1357.      DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
  1358.      return EFI_OUT_OF_RESOURCES;
  1359.    }
  1360.  
  1361. -  BoardDesc->SoC = SoCDesc;
  1362. -  BoardDesc->GpioDevCount = SoCGpioCount;
  1363. -  BoardDesc->I2cIoExpanderDesc = I2cIoExpanderDesc;
  1364. -  BoardDesc->I2cIoExpanderCount = I2cIoExpanderCount;
  1365. +  Description->SoCGpio = SoCGpio;
  1366. +  Description->GpioDeviceCount = SoCGpioCount;
  1367. +  Description->GpioExpanders = GpioExpanders;
  1368. +  Description->GpioExpanderCount = GpioExpanderCount;
  1369.  
  1370. -  *GpioDesc = BoardDesc;
  1371. +  *GpioDescription = Description;
  1372.  
  1373.    return EFI_SUCCESS;
  1374.  }
  1375. @@ -611,7 +606,6 @@ MvBoardDescInitProtocol (
  1376.  {
  1377.    BoardDescProtocol->BoardDescAhciGet = MvBoardDescAhciGet;
  1378.    BoardDescProtocol->BoardDescComPhyGet = MvBoardDescComPhyGet;
  1379. -  BoardDescProtocol->BoardDescGpioGet = MvBoardDescGpioGet;
  1380.    BoardDescProtocol->BoardDescI2cGet = MvBoardDescI2cGet;
  1381.    BoardDescProtocol->BoardDescMdioGet = MvBoardDescMdioGet;
  1382.    BoardDescProtocol->BoardDescPp2Get = MvBoardDescPp2Get;
  1383. @@ -619,6 +613,7 @@ MvBoardDescInitProtocol (
  1384.    BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
  1385.    BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
  1386.    BoardDescProtocol->BoardDescFree = MvBoardDescFree;
  1387. +  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
  1388.  
  1389.    return EFI_SUCCESS;
  1390.  }
  1391. diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
  1392. index fc2d416..4d5e530 100644
  1393. --- a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
  1394. +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
  1395. @@ -16,21 +16,21 @@
  1396.  
  1397.  STATIC MV_GPIO *mGpioInstance;
  1398.  
  1399. -STATIC MV_GPIO_DEVICE_PATH mGpioDevicePathTemplate = {
  1400. +STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
  1401.    {
  1402.      {
  1403.        HARDWARE_DEVICE_PATH,
  1404.        HW_VENDOR_DP,
  1405.        {
  1406.          (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
  1407. -                 sizeof (MARVELL_GPIO_DRIVER_TYPE)),
  1408. +                 sizeof (MV_GPIO_DRIVER_TYPE)),
  1409.          (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
  1410. -                 sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
  1411. +                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
  1412.        },
  1413.      },
  1414.      EFI_CALLER_ID_GUID
  1415.    },
  1416. -  GPIO_DRIVER_TYPE_SOC_CONTROLLER,
  1417. +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
  1418.    {
  1419.      END_DEVICE_PATH_TYPE,
  1420.      END_ENTIRE_DEVICE_PATH_SUBTYPE,
  1421. @@ -41,14 +41,32 @@ STATIC MV_GPIO_DEVICE_PATH mGpioDevicePathTemplate = {
  1422.    }
  1423.  };
  1424.  
  1425. +#if !defined(MDEPKG_NDEBUG)
  1426. +/**
  1427. +
  1428. +Routine Description:
  1429. +
  1430. +  Verifies if controller index / GPIO pin values
  1431. +  are within proper boundaries.
  1432. +
  1433. +Arguments:
  1434. +
  1435. +  ControllerIndex - index of controller
  1436. +  GpioPin - which pin to read
  1437. +
  1438. +Returns:
  1439. +
  1440. +  EFI_SUCCESS           - GPIO pin / controller index are proper
  1441. +  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
  1442. +**/
  1443.  STATIC
  1444.  EFI_STATUS
  1445.  MvGpioValidate (
  1446. -  IN  UINTN ControllerIndex,
  1447. -  IN  UINTN GpioPin
  1448. +  IN UINTN ControllerIndex,
  1449. +  IN UINTN GpioPin
  1450.    )
  1451.  {
  1452. -  if (ControllerIndex >= mGpioInstance->Desc->GpioDevCount) {
  1453. +  if (ControllerIndex >= mGpioInstance->GpioDeviceCount) {
  1454.      DEBUG ((DEBUG_ERROR,
  1455.        "%a: Invalid GPIO ControllerIndex: %d\n",
  1456.        __FUNCTION__,
  1457. @@ -56,7 +74,7 @@ MvGpioValidate (
  1458.      return EFI_INVALID_PARAMETER;
  1459.    }
  1460.  
  1461. -  if (GpioPin >= mGpioInstance->Desc->SoC[ControllerIndex].GpioPinCount) {
  1462. +  if (GpioPin >= mGpioInstance->SoCGpio[ControllerIndex].InternalGpioCount) {
  1463.      DEBUG ((DEBUG_ERROR,
  1464.        "%a: GPIO pin #%d not available in Controller#%d\n",
  1465.        __FUNCTION__,
  1466. @@ -67,165 +85,200 @@ MvGpioValidate (
  1467.  
  1468.    return EFI_SUCCESS;
  1469.  }
  1470. +#endif
  1471.  
  1472. -STATIC
  1473. -EFI_STATUS
  1474. -MvGpioDirectionOutput (
  1475. -  IN  MARVELL_GPIO_PROTOCOL *This,
  1476. -  IN  UINTN ControllerIndex,
  1477. -  IN  UINTN GpioPin,
  1478. -  IN  BOOLEAN Value
  1479. -  )
  1480. -{
  1481. -  UINTN BaseAddress;
  1482. -  EFI_STATUS Status;
  1483. +/**
  1484.  
  1485. -  Status = MvGpioValidate (ControllerIndex, GpioPin);
  1486. -  if (EFI_ERROR (Status)) {
  1487. -    DEBUG ((DEBUG_ERROR,
  1488. -      "%a: Fail to set output for pin #%d\n",
  1489. -      __FUNCTION__,
  1490. -      GpioPin));
  1491. -    return Status;
  1492. -  }
  1493. +Routine Description:
  1494.  
  1495. -  BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
  1496. +  Gets the mode (function) of a GPIO pin
  1497.  
  1498. -  MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
  1499. -    ~BIT (GpioPin),
  1500. -    (Value) << GpioPin);
  1501. +Arguments:
  1502.  
  1503. -  MmioAnd32 (BaseAddress + GPIO_OUT_EN_REG, ~BIT (GpioPin));
  1504. +  This  - pointer to protocol
  1505. +  Gpio  - which pin
  1506. +  Mode  - pointer to output mode value
  1507.  
  1508. -  return EFI_SUCCESS;
  1509. -}
  1510. +Returns:
  1511.  
  1512. +  EFI_SUCCESS           - mode value retrieved
  1513. +  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
  1514. +
  1515. +**/
  1516.  STATIC
  1517.  EFI_STATUS
  1518. -MvGpioDirectionInput (
  1519. -  IN  MARVELL_GPIO_PROTOCOL *This,
  1520. -  IN  UINTN ControllerIndex,
  1521. -  IN  UINTN GpioPin
  1522. +MvGpioGetMode (
  1523. +  IN  EMBEDDED_GPIO       *This,
  1524. +  IN  EMBEDDED_GPIO_PIN    Gpio,
  1525. +  OUT EMBEDDED_GPIO_MODE  *Mode
  1526.    )
  1527.  {
  1528. +  UINTN ControllerIndex;
  1529.    UINTN BaseAddress;
  1530. -  EFI_STATUS Status;
  1531. +  UINTN GpioPin;
  1532.  
  1533. -  Status = MvGpioValidate (ControllerIndex, GpioPin);
  1534. -  if (EFI_ERROR (Status)) {
  1535. -    DEBUG ((DEBUG_ERROR,
  1536. -      "%a: Fail to set input for pin #%d\n",
  1537. -      __FUNCTION__,
  1538. -      GpioPin));
  1539. -    return Status;
  1540. -  }
  1541. +  GpioPin = GPIO_PIN (Gpio);
  1542. +  ControllerIndex = GPIO_PORT (Gpio);
  1543. +
  1544. +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
  1545.  
  1546. -  BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
  1547. +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
  1548.  
  1549. -  MmioOr32 (BaseAddress + GPIO_OUT_EN_REG, BIT (GpioPin));
  1550. +  if (MmioRead32 (BaseAddress + MV_GPIO_OUT_EN_REG) & (1 << GpioPin)) {
  1551. +    *Mode = GPIO_MODE_INPUT;
  1552. +  } else {
  1553. +    if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
  1554. +      *Mode = GPIO_MODE_OUTPUT_1;
  1555. +    } else {
  1556. +      *Mode = GPIO_MODE_OUTPUT_0;
  1557. +    }
  1558. +  }
  1559.  
  1560.    return EFI_SUCCESS;
  1561.  }
  1562.  
  1563. +/**
  1564. +
  1565. +Routine Description:
  1566. +
  1567. +  Gets the state of a GPIO pin
  1568. +
  1569. +Arguments:
  1570. +
  1571. +  This  - pointer to protocol
  1572. +  Gpio  - which pin to read
  1573. +  Value - state of the pin
  1574. +
  1575. +Returns:
  1576. +
  1577. +  EFI_SUCCESS           - GPIO state returned in Value
  1578. +  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
  1579. +**/
  1580.  STATIC
  1581.  EFI_STATUS
  1582. -MvGpioGetFunction (
  1583. -  IN  MARVELL_GPIO_PROTOCOL *This,
  1584. -  IN  UINTN ControllerIndex,
  1585. -  IN  UINTN GpioPin,
  1586. -  OUT MARVELL_GPIO_MODE *Mode
  1587. +MvGpioGet (
  1588. +  IN  EMBEDDED_GPIO      *This,
  1589. +  IN  EMBEDDED_GPIO_PIN   Gpio,
  1590. +  OUT UINTN              *Value
  1591.    )
  1592.  {
  1593. -  UINT32 RegVal;
  1594. +  UINTN ControllerIndex;
  1595.    UINTN BaseAddress;
  1596. -  EFI_STATUS Status;
  1597. +  UINTN GpioPin;
  1598.  
  1599. -  Status = MvGpioValidate (ControllerIndex, GpioPin);
  1600. -  if (EFI_ERROR (Status)) {
  1601. -    DEBUG ((DEBUG_ERROR,
  1602. -      "%a: Fail to get function of pin #%d\n",
  1603. -      __FUNCTION__,
  1604. -      GpioPin));
  1605. -    return Status;
  1606. -  }
  1607. +  GpioPin = GPIO_PIN (Gpio);
  1608. +  ControllerIndex = GPIO_PORT (Gpio);
  1609.  
  1610. -  BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
  1611. +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
  1612.  
  1613. -  RegVal = MmioRead32 (BaseAddress + GPIO_OUT_EN_REG);
  1614. -  *Mode = ((RegVal & BIT (GpioPin)) ? GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
  1615. +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
  1616. +
  1617. +  if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
  1618. +    *Value = 1;
  1619. +  } else {
  1620. +    *Value = 0;
  1621. +  }
  1622.  
  1623.    return EFI_SUCCESS;
  1624.  }
  1625.  
  1626. +/**
  1627. +
  1628. +Routine Description:
  1629. +
  1630. +  Sets the state of a GPIO pin
  1631. +
  1632. +Arguments:
  1633. +
  1634. +  This  - pointer to protocol
  1635. +  Gpio  - which pin to modify
  1636. +  Mode  - mode to set
  1637. +
  1638. +Returns:
  1639. +
  1640. +  EFI_SUCCESS           - GPIO set as requested
  1641. +  EFI_UNSUPPORTED       - Mode is not supported
  1642. +  EFI_INVALID_PARAMETER - Gpio pin is out of range
  1643. +**/
  1644.  STATIC
  1645.  EFI_STATUS
  1646. -MvGpioGetValue (
  1647. -  IN     MARVELL_GPIO_PROTOCOL *This,
  1648. -  IN     UINTN ControllerIndex,
  1649. -  IN     UINTN GpioPin,
  1650. -  IN OUT BOOLEAN *Value
  1651. +MvGpioSet (
  1652. +  IN EMBEDDED_GPIO       *This,
  1653. +  IN EMBEDDED_GPIO_PIN    Gpio,
  1654. +  IN EMBEDDED_GPIO_MODE   Mode
  1655.    )
  1656.  {
  1657. +  UINTN ControllerIndex;
  1658.    UINTN BaseAddress;
  1659. -  EFI_STATUS Status;
  1660. +  UINTN GpioPin;
  1661.  
  1662. -  Status = MvGpioValidate (ControllerIndex, GpioPin);
  1663. -  if (EFI_ERROR (Status)) {
  1664. -    DEBUG ((DEBUG_ERROR,
  1665. -      "%a: Fail to get value of pin #%d\n",
  1666. -      __FUNCTION__,
  1667. -      GpioPin));
  1668. -    return Status;
  1669. -  }
  1670. +  GpioPin = GPIO_PIN (Gpio);
  1671. +  ControllerIndex = GPIO_PORT (Gpio);
  1672. +
  1673. +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
  1674. +
  1675. +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
  1676.  
  1677. -  BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
  1678. +  switch (Mode) {
  1679. +  case GPIO_MODE_OUTPUT_0:
  1680. +    MmioAnd32 (BaseAddress + MV_GPIO_DATA_OUT_REG, ~(1 << GpioPin));
  1681. +    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
  1682. +    break;
  1683.  
  1684. -  *Value = !!(MmioRead32 (BaseAddress + GPIO_DATA_IN_REG) & BIT (GpioPin));
  1685. +  case GPIO_MODE_OUTPUT_1:
  1686. +    MmioOr32 (BaseAddress + MV_GPIO_DATA_OUT_REG, (1 << GpioPin));
  1687. +    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
  1688. +    break;
  1689.  
  1690. +  case GPIO_MODE_INPUT:
  1691. +    MmioOr32 (BaseAddress + MV_GPIO_OUT_EN_REG, (1 << GpioPin));
  1692. +    break;
  1693. +
  1694. +  default:
  1695. +    return EFI_UNSUPPORTED;
  1696. +  }
  1697. +
  1698.    return EFI_SUCCESS;
  1699.  }
  1700.  
  1701. -STATIC
  1702. -EFI_STATUS
  1703. -MvGpioSetValue (
  1704. -  IN  MARVELL_GPIO_PROTOCOL *This,
  1705. -  IN  UINTN ControllerIndex,
  1706. -  IN  UINTN GpioPin,
  1707. -  IN  BOOLEAN Value
  1708. -  )
  1709. -{
  1710. -  UINTN BaseAddress;
  1711. -  EFI_STATUS Status;
  1712. +/**
  1713.  
  1714. -  Status = MvGpioValidate (ControllerIndex, GpioPin);
  1715. -  if (EFI_ERROR (Status)) {
  1716. -    DEBUG ((DEBUG_ERROR,
  1717. -      "%a: Fail to get value of pin #%d\n",
  1718. -      __FUNCTION__,
  1719. -      GpioPin));
  1720. -    return Status;
  1721. -  }
  1722. +Routine Description:
  1723.  
  1724. -  BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
  1725. +  Sets the pull-up / pull-down resistor of a GPIO pin
  1726.  
  1727. -  MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
  1728. -    ~BIT (GpioPin),
  1729. -    Value << GpioPin);
  1730. +Arguments:
  1731.  
  1732. -  return EFI_SUCCESS;
  1733. +  This  - pointer to protocol
  1734. +  Gpio  - which pin
  1735. +  Direction - pull-up, pull-down, or none
  1736. +
  1737. +Returns:
  1738. +
  1739. +  EFI_UNSUPPORTED - Can not perform the requested operation
  1740. +
  1741. +**/
  1742. +EFI_STATUS
  1743. +EFIAPI
  1744. +MvGpioSetPull (
  1745. +  IN  EMBEDDED_GPIO       *This,
  1746. +  IN  EMBEDDED_GPIO_PIN   Gpio,
  1747. +  IN  EMBEDDED_GPIO_PULL  Direction
  1748. +  )
  1749. +{
  1750. +  return EFI_UNSUPPORTED;
  1751.  }
  1752.  
  1753.  STATIC
  1754.  VOID
  1755.  MvGpioInitProtocol (
  1756. -  IN MARVELL_GPIO_PROTOCOL *GpioProtocol
  1757. +  IN EMBEDDED_GPIO *GpioProtocol
  1758.    )
  1759.  {
  1760. -  GpioProtocol->DirectionInput  = MvGpioDirectionInput;
  1761. -  GpioProtocol->DirectionOutput = MvGpioDirectionOutput;
  1762. -  GpioProtocol->GetFunction     = MvGpioGetFunction;
  1763. -  GpioProtocol->GetValue        = MvGpioGetValue;
  1764. -  GpioProtocol->SetValue        = MvGpioSetValue;
  1765. +  GpioProtocol->Get     = MvGpioGet;
  1766. +  GpioProtocol->Set     = MvGpioSet;
  1767. +  GpioProtocol->GetMode = MvGpioGetMode;
  1768. +  GpioProtocol->SetPull = MvGpioSetPull;
  1769.  }
  1770.  
  1771.  EFI_STATUS
  1772. @@ -235,13 +288,13 @@ MvGpioEntryPoint (
  1773.    IN EFI_SYSTEM_TABLE *SystemTable
  1774.    )
  1775.  {
  1776. -  MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
  1777. +  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
  1778. +  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
  1779.    MV_GPIO_DEVICE_PATH *GpioDevicePath;
  1780. -  MV_BOARD_GPIO_DESC *Desc;
  1781.    EFI_STATUS Status;
  1782.  
  1783.    GpioDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
  1784. -                     &mGpioDevicePathTemplate);
  1785. +                     &mDevicePathTemplate);
  1786.    if (GpioDevicePath == NULL) {
  1787.      return EFI_OUT_OF_RESOURCES;
  1788.    }
  1789. @@ -255,7 +308,7 @@ MvGpioEntryPoint (
  1790.    /* Obtain list of available controllers */
  1791.    Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
  1792.                    NULL,
  1793. -                  (VOID **)&BoardDescProtocol);
  1794. +                  (VOID **)&MvBoardProtocol);
  1795.    if (EFI_ERROR (Status)) {
  1796.      DEBUG ((DEBUG_ERROR,
  1797.        "%a: Cannot locate BoardDesc protocol\n",
  1798. @@ -263,7 +316,8 @@ MvGpioEntryPoint (
  1799.      goto ErrLocateBoardDesc;
  1800.    }
  1801.  
  1802. -  Status = BoardDescProtocol->BoardDescGpioGet (BoardDescProtocol, &Desc);
  1803. +  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
  1804. +             &GpioDescription);
  1805.    if (EFI_ERROR (Status)) {
  1806.      DEBUG ((DEBUG_ERROR,
  1807.        "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
  1808. @@ -271,23 +325,43 @@ MvGpioEntryPoint (
  1809.      goto ErrLocateBoardDesc;
  1810.    }
  1811.  
  1812. -  mGpioInstance->Signature = GPIO_SIGNATURE;
  1813. -  mGpioInstance->Desc = Desc;
  1814. +  mGpioInstance->Signature = MV_GPIO_SIGNATURE;
  1815. +  mGpioInstance->GpioDeviceCount = GpioDescription->GpioDeviceCount;
  1816. +  mGpioInstance->SoCGpio = AllocateCopyPool (sizeof (GPIO_CONTROLLER) *
  1817. +                             GpioDescription->GpioDeviceCount,
  1818. +                             GpioDescription->SoCGpio);
  1819. +  if (mGpioInstance->SoCGpio == NULL) {
  1820. +    DEBUG ((DEBUG_ERROR,
  1821. +      "%a: Fail to copy GPIO SoC controllers description\n",
  1822. +      __FUNCTION__));
  1823. +    Status = EFI_OUT_OF_RESOURCES;
  1824. +    goto ErrAllocateSoCGpio;
  1825. +  }
  1826.  
  1827.    MvGpioInitProtocol (&mGpioInstance->GpioProtocol);
  1828.  
  1829.    Status = gBS->InstallMultipleProtocolInterfaces (&(mGpioInstance->Handle),
  1830. -                  &gMarvellGpioProtocolGuid,
  1831. +                  &gEmbeddedGpioProtocolGuid,
  1832.                    &(mGpioInstance->GpioProtocol),
  1833.                    &gEfiDevicePathProtocolGuid,
  1834.                    (EFI_DEVICE_PATH_PROTOCOL *)GpioDevicePath,
  1835.                    NULL);
  1836.    if (EFI_ERROR (Status)) {
  1837. -    goto ErrLocateBoardDesc;
  1838. +    goto ErrInstallProtocols;
  1839.    }
  1840.  
  1841. +  gBS->FreePool (GpioDescription->SoCGpio);
  1842. +  gBS->FreePool (GpioDescription);
  1843. +
  1844.    return EFI_SUCCESS;
  1845.  
  1846. +ErrInstallProtocols:
  1847. +  gBS->FreePool (mGpioInstance->SoCGpio);
  1848. +
  1849. +ErrAllocateSoCGpio:
  1850. +  gBS->FreePool (GpioDescription->SoCGpio);
  1851. +  gBS->FreePool (GpioDescription);
  1852. +
  1853.  ErrLocateBoardDesc:
  1854.    gBS->FreePool (mGpioInstance);
  1855.  
  1856. diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
  1857. index f4a474e..37c2b27 100644
  1858. --- a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
  1859. +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
  1860. @@ -20,21 +20,21 @@
  1861.  
  1862.  STATIC PCA95XX *mPca95xxInstance;
  1863.  
  1864. -STATIC MV_GPIO_DEVICE_PATH mPca95xxDevicePathTemplate = {
  1865. +STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
  1866.    {
  1867.      {
  1868.        HARDWARE_DEVICE_PATH,
  1869.        HW_VENDOR_DP,
  1870.        {
  1871.          (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
  1872. -                 sizeof (MARVELL_GPIO_DRIVER_TYPE)),
  1873. +                 sizeof (MV_GPIO_DRIVER_TYPE)),
  1874.          (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
  1875. -                 sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
  1876. +                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
  1877.        },
  1878.      },
  1879.      EFI_CALLER_ID_GUID
  1880.    },
  1881. -  GPIO_DRIVER_TYPE_PCA95XX,
  1882. +  MV_GPIO_DRIVER_TYPE_PCA95XX,
  1883.    {
  1884.      END_DEVICE_PATH_TYPE,
  1885.      END_ENTIRE_DEVICE_PATH_SUBTYPE,
  1886. @@ -59,6 +59,24 @@ STATIC PCA95XX_PIN_COUNT mPca95xxPinCount[PCA95XX_MAX_ID] = {
  1887.    PCA9557_PIN_COUNT,
  1888.  };
  1889.  
  1890. +#if !defined(MDEPKG_NDEBUG)
  1891. +/**
  1892. +
  1893. +Routine Description:
  1894. +
  1895. +  Verifies if controller index / GPIO pin values
  1896. +  are within proper boundaries.
  1897. +
  1898. +Arguments:
  1899. +
  1900. +  ControllerIndex - index of controller
  1901. +  GpioPin - which pin to read
  1902. +
  1903. +Returns:
  1904. +
  1905. +  EFI_SUCCESS           - GPIO pin / controller index are proper
  1906. +  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
  1907. +**/
  1908.  STATIC
  1909.  EFI_STATUS
  1910.  MvPca95xxValidate (
  1911. @@ -68,7 +86,7 @@ MvPca95xxValidate (
  1912.  {
  1913.    UINTN ControllerId;
  1914.  
  1915. -  if (ControllerIndex >= mPca95xxInstance->ControllerCount) {
  1916. +  if (ControllerIndex >= mPca95xxInstance->GpioExpanderCount) {
  1917.      DEBUG ((DEBUG_ERROR,
  1918.        "%a: Invalid GPIO ControllerIndex: %d\n",
  1919.        __FUNCTION__,
  1920. @@ -76,7 +94,7 @@ MvPca95xxValidate (
  1921.      return EFI_INVALID_PARAMETER;
  1922.    }
  1923.  
  1924. -  ControllerId = mPca95xxInstance->ControllerDesc[ControllerIndex].ChipId;
  1925. +  ControllerId = mPca95xxInstance->GpioExpanders[ControllerIndex].ChipId;
  1926.  
  1927.    if (GpioPin >= mPca95xxPinCount[ControllerId]) {
  1928.      DEBUG ((DEBUG_ERROR,
  1929. @@ -89,6 +107,7 @@ MvPca95xxValidate (
  1930.  
  1931.    return EFI_SUCCESS;
  1932.  }
  1933. +#endif
  1934.  
  1935.  EFI_STATUS
  1936.  EFIAPI
  1937. @@ -102,8 +121,8 @@ MvPca95xxGetI2c (
  1938.    EFI_HANDLE  *HandleBuffer;
  1939.    EFI_STATUS   Status;
  1940.  
  1941. -  I2cBus = mPca95xxInstance->ControllerDesc[ControllerIndex].I2cBus;
  1942. -  I2cAddress = mPca95xxInstance->ControllerDesc[ControllerIndex].I2cAddress;
  1943. +  I2cBus = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cBus;
  1944. +  I2cAddress = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cAddress;
  1945.  
  1946.    /* Locate Handles of all EfiI2cIoProtocol producers */
  1947.    Status = gBS->LocateHandleBuffer (ByProtocol,
  1948. @@ -146,7 +165,7 @@ MvPca95xxI2cTransfer (
  1949.    IN EFI_I2C_IO_PROTOCOL *I2cIo,
  1950.    IN UINT8                Address,
  1951.    IN UINT8               *Buffer,
  1952. -  IN PCA95XX_OPERATION    Operation
  1953. +  IN UINT32               Flag
  1954.    )
  1955.  {
  1956.    EFI_I2C_REQUEST_PACKET *RequestPacket;
  1957. @@ -168,8 +187,7 @@ MvPca95xxI2cTransfer (
  1958.    RequestPacket->Operation[0].Buffer[0] = Address & MAX_UINT8;
  1959.    RequestPacket->Operation[1].LengthInBytes = PCA95XX_OPERATION_LENGTH;
  1960.    RequestPacket->Operation[1].Buffer = Buffer;
  1961. -  RequestPacket->Operation[1].Flags = (Operation == PCA95XX_READ ?
  1962. -                                       I2C_FLAG_READ : I2C_FLAG_NORESTART);
  1963. +  RequestPacket->Operation[1].Flags = Flag;
  1964.  
  1965.    Status = I2cIo->QueueRequest (I2cIo, 0, NULL, RequestPacket, NULL);
  1966.    if (EFI_ERROR (Status)) {
  1967. @@ -192,7 +210,7 @@ MvPca95xxReadRegs (
  1968.    OUT UINT8               *RegVal
  1969.    )
  1970.  {
  1971. -  return MvPca95xxI2cTransfer (I2cIo, Reg, RegVal, PCA95XX_READ);
  1972. +  return MvPca95xxI2cTransfer (I2cIo, Reg, RegVal, I2C_FLAG_READ);
  1973.  }
  1974.  
  1975.  STATIC
  1976. @@ -203,15 +221,15 @@ MvPca95xxWriteRegs (
  1977.    IN  UINT8                RegVal
  1978.    )
  1979.  {
  1980. -  return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, PCA95XX_WRITE);
  1981. +  return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, I2C_FLAG_NORESTART);
  1982.  }
  1983.  
  1984.  STATIC
  1985.  EFI_STATUS
  1986.  MvPca95xxSetOutputValue (
  1987. -  IN UINTN   ControllerIndex,
  1988. -  IN UINTN   GpioPin,
  1989. -  IN BOOLEAN Value
  1990. +  IN UINTN               ControllerIndex,
  1991. +  IN UINTN               GpioPin,
  1992. +  IN EMBEDDED_GPIO_MODE  Mode
  1993.    )
  1994.  {
  1995.    EFI_I2C_IO_PROTOCOL *I2cIo;
  1996. @@ -233,10 +251,10 @@ MvPca95xxSetOutputValue (
  1997.      return EFI_DEVICE_ERROR;
  1998.    }
  1999.  
  2000. -  if (Value) {
  2001. -    RegVal |= BIT (GpioPin % PCA95XX_BANK_SIZE);
  2002. +  if (Mode == GPIO_MODE_OUTPUT_1) {
  2003. +    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
  2004.    } else {
  2005. -    RegVal &= ~BIT (GpioPin % PCA95XX_BANK_SIZE);
  2006. +    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
  2007.    }
  2008.  
  2009.    Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, RegVal);
  2010. @@ -251,9 +269,9 @@ MvPca95xxSetOutputValue (
  2011.  STATIC
  2012.  EFI_STATUS
  2013.  MvPca95xxSetDirection (
  2014. -  IN UINTN             ControllerIndex,
  2015. -  IN UINTN             GpioPin,
  2016. -  IN MARVELL_GPIO_MODE Direction
  2017. +  IN UINTN              ControllerIndex,
  2018. +  IN UINTN              GpioPin,
  2019. +  IN EMBEDDED_GPIO_MODE Mode
  2020.    )
  2021.  {
  2022.    EFI_I2C_IO_PROTOCOL *I2cIo;
  2023. @@ -275,10 +293,10 @@ MvPca95xxSetDirection (
  2024.      return Status;
  2025.    }
  2026.  
  2027. -  if (Direction == GPIO_MODE_INPUT) {
  2028. -    RegVal |= BIT (GpioPin % PCA95XX_BANK_SIZE);
  2029. +  if (Mode == GPIO_MODE_INPUT) {
  2030. +    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
  2031.    } else {
  2032. -    RegVal &= ~BIT (GpioPin % PCA95XX_BANK_SIZE);
  2033. +    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
  2034.    }
  2035.  
  2036.    Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, RegVal);
  2037. @@ -292,10 +310,10 @@ MvPca95xxSetDirection (
  2038.  
  2039.  STATIC
  2040.  EFI_STATUS
  2041. -MvPca95xxIsOutput (
  2042. -  IN  UINTN              ControllerIndex,
  2043. -  IN  UINTN              GpioPin,
  2044. -  OUT MARVELL_GPIO_MODE *Mode
  2045. +MvPca95xxReadMode (
  2046. +  IN  UINTN               ControllerIndex,
  2047. +  IN  UINTN               GpioPin,
  2048. +  OUT EMBEDDED_GPIO_MODE *Mode
  2049.    )
  2050.  {
  2051.    EFI_I2C_IO_PROTOCOL *I2cIo;
  2052. @@ -303,14 +321,7 @@ MvPca95xxIsOutput (
  2053.    UINT8 RegVal;
  2054.    UINTN Bank;
  2055.  
  2056. -  Status = MvPca95xxValidate (ControllerIndex, GpioPin);
  2057. -  if (EFI_ERROR (Status)) {
  2058. -    DEBUG ((DEBUG_ERROR,
  2059. -      "%a: invalid pin/controller data\n",
  2060. -      __FUNCTION__,
  2061. -      GpioPin));
  2062. -    return Status;
  2063. -  }
  2064. +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
  2065.  
  2066.    Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
  2067.    if (EFI_ERROR (Status)) {
  2068. @@ -326,97 +337,61 @@ MvPca95xxIsOutput (
  2069.      return Status;
  2070.    }
  2071.  
  2072. -  *Mode = ((RegVal & BIT (GpioPin % PCA95XX_BANK_SIZE)) ?
  2073. -           GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
  2074. +  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
  2075. +    *Mode = GPIO_MODE_INPUT;
  2076. +  } else {
  2077. +    Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
  2078. +    if (EFI_ERROR (Status)) {
  2079. +      DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
  2080. +      return Status;
  2081. +    }
  2082. +
  2083. +    if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
  2084. +      *Mode = GPIO_MODE_OUTPUT_1;
  2085. +    } else {
  2086. +      *Mode = GPIO_MODE_OUTPUT_0;
  2087. +    }
  2088. +  }
  2089.  
  2090.    return EFI_SUCCESS;
  2091.  }
  2092.  
  2093. -STATIC
  2094. -EFI_STATUS
  2095. -MvPca95xxDirectionOutput (
  2096. -  IN MARVELL_GPIO_PROTOCOL *This,
  2097. -  IN UINTN                  ControllerIndex,
  2098. -  IN UINTN                  GpioPin,
  2099. -  IN BOOLEAN                Value
  2100. -  )
  2101. -{
  2102. -  EFI_STATUS Status;
  2103. -
  2104. -  Status = MvPca95xxValidate (ControllerIndex, GpioPin);
  2105. -  if (EFI_ERROR (Status)) {
  2106. -    DEBUG ((DEBUG_ERROR,
  2107. -      "%a: invalid pin/controller data\n",
  2108. -      __FUNCTION__,
  2109. -      GpioPin));
  2110. -    return Status;
  2111. -  }
  2112. -
  2113. -  /* Configure output value. */
  2114. -  Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Value);
  2115. -  if (EFI_ERROR (Status)) {
  2116. -    DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
  2117. -    return EFI_DEVICE_ERROR;
  2118. -  }
  2119. +/**
  2120.  
  2121. -  /* Configure direction as output. */
  2122. -  Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, GPIO_MODE_OUTPUT);
  2123. -  if (EFI_ERROR (Status)) {
  2124. -    DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
  2125. -  }
  2126. +Routine Description:
  2127.  
  2128. -  return Status;
  2129. -}
  2130. +  Gets the mode (function) of a GPIO pin
  2131.  
  2132. -STATIC
  2133. -EFI_STATUS
  2134. -MvPca95xxDirectionInput (
  2135. -  IN MARVELL_GPIO_PROTOCOL *This,
  2136. -  IN UINTN                  ControllerIndex,
  2137. -  IN UINTN                  GpioPin
  2138. -  )
  2139. -{
  2140. -  EFI_STATUS Status;
  2141. +Arguments:
  2142.  
  2143. -  Status = MvPca95xxValidate (ControllerIndex, GpioPin);
  2144. -  if (EFI_ERROR (Status)) {
  2145. -    DEBUG ((DEBUG_ERROR,
  2146. -      "%a: invalid pin/controller data\n",
  2147. -      __FUNCTION__,
  2148. -      GpioPin));
  2149. -    return Status;
  2150. -  }
  2151. +  This  - pointer to protocol
  2152. +  Gpio  - which pin
  2153. +  Mode  - pointer to output mode value
  2154.  
  2155. -  /* Configure direction as input. */
  2156. -  Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, GPIO_MODE_INPUT);
  2157. -  if (EFI_ERROR (Status)) {
  2158. -    DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
  2159. -  }
  2160. +Returns:
  2161.  
  2162. -  return Status;
  2163. -}
  2164. +  EFI_SUCCESS           - mode value retrieved
  2165. +  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
  2166.  
  2167. +**/
  2168.  STATIC
  2169.  EFI_STATUS
  2170. -MvPca95xxGetFunction (
  2171. -  IN  MARVELL_GPIO_PROTOCOL *This,
  2172. -  IN  UINTN                  ControllerIndex,
  2173. -  IN  UINTN                  GpioPin,
  2174. -  OUT MARVELL_GPIO_MODE     *Mode
  2175. +MvPca95xxGetMode (
  2176. +  IN  EMBEDDED_GPIO       *This,
  2177. +  IN  EMBEDDED_GPIO_PIN    Gpio,
  2178. +  OUT EMBEDDED_GPIO_MODE  *Mode
  2179.    )
  2180.  {
  2181.    EFI_STATUS Status;
  2182. +  UINTN ControllerIndex;
  2183. +  UINTN GpioPin;
  2184.  
  2185. -  Status = MvPca95xxValidate (ControllerIndex, GpioPin);
  2186. -  if (EFI_ERROR (Status)) {
  2187. -    DEBUG ((DEBUG_ERROR,
  2188. -      "%a: invalid pin/controller data\n",
  2189. -      __FUNCTION__,
  2190. -      GpioPin));
  2191. -    return Status;
  2192. -  }
  2193. +  GpioPin = GPIO_PIN (Gpio);
  2194. +  ControllerIndex = GPIO_PORT (Gpio);
  2195.  
  2196. -  Status = MvPca95xxIsOutput (ControllerIndex, GpioPin, Mode);
  2197. +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
  2198. +
  2199. +  Status = MvPca95xxReadMode (ControllerIndex, GpioPin, Mode);
  2200.    if (EFI_ERROR (Status)) {
  2201.      DEBUG ((DEBUG_ERROR,
  2202.        "%a: fail to get pin %d of controller#%d mode\n",
  2203. @@ -428,28 +403,42 @@ MvPca95xxGetFunction (
  2204.    return Status;
  2205.  }
  2206.  
  2207. +/**
  2208. +
  2209. +Routine Description:
  2210. +
  2211. +  Gets the state of a GPIO pin
  2212. +
  2213. +Arguments:
  2214. +
  2215. +  This  - pointer to protocol
  2216. +  Gpio  - which pin to read
  2217. +  Value - state of the pin
  2218. +
  2219. +Returns:
  2220. +
  2221. +  EFI_SUCCESS           - GPIO state returned in Value
  2222. +  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
  2223. +**/
  2224.  STATIC
  2225.  EFI_STATUS
  2226. -MvPca95xxGetValue (
  2227. -  IN     MARVELL_GPIO_PROTOCOL *This,
  2228. -  IN     UINTN                  ControllerIndex,
  2229. -  IN     UINTN                  GpioPin,
  2230. -  IN OUT BOOLEAN               *Value
  2231. +MvPca95xxGet (
  2232. +  IN  EMBEDDED_GPIO      *This,
  2233. +  IN  EMBEDDED_GPIO_PIN   Gpio,
  2234. +  OUT UINTN              *Value
  2235.    )
  2236.  {
  2237.    EFI_I2C_IO_PROTOCOL *I2cIo;
  2238.    EFI_STATUS Status;
  2239. +  UINTN ControllerIndex;
  2240. +  UINTN GpioPin;
  2241.    UINT8 RegVal;
  2242.    UINTN Bank;
  2243.  
  2244. -  Status = MvPca95xxValidate (ControllerIndex, GpioPin);
  2245. -  if (EFI_ERROR (Status)) {
  2246. -    DEBUG ((DEBUG_ERROR,
  2247. -      "%a: invalid pin/controller data\n",
  2248. -      __FUNCTION__,
  2249. -      GpioPin));
  2250. -    return Status;
  2251. -  }
  2252. +  GpioPin = GPIO_PIN (Gpio);
  2253. +  ControllerIndex = GPIO_PORT (Gpio);
  2254. +
  2255. +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
  2256.  
  2257.    Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
  2258.    if (EFI_ERROR (Status)) {
  2259. @@ -465,51 +454,113 @@ MvPca95xxGetValue (
  2260.      return Status;
  2261.    }
  2262.  
  2263. -  *Value = !!(RegVal & BIT (GpioPin % PCA95XX_BANK_SIZE));
  2264. +  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
  2265. +    *Value = 1;
  2266. +  } else {
  2267. +    *Value = 0;
  2268. +  }
  2269.  
  2270.    return EFI_SUCCESS;
  2271.  }
  2272.  
  2273. +/**
  2274. +
  2275. +Routine Description:
  2276. +
  2277. +  Sets the state of a GPIO pin
  2278. +
  2279. +Arguments:
  2280. +
  2281. +  This  - pointer to protocol
  2282. +  Gpio  - which pin to modify
  2283. +  Mode  - mode to set
  2284. +
  2285. +Returns:
  2286. +
  2287. +  EFI_SUCCESS           - GPIO set as requested
  2288. +  EFI_UNSUPPORTED       - Mode is not supported
  2289. +  EFI_INVALID_PARAMETER - Gpio pin is out of range
  2290. +**/
  2291.  STATIC
  2292.  EFI_STATUS
  2293. -MvPca95xxSetValue (
  2294. -  IN MARVELL_GPIO_PROTOCOL *This,
  2295. -  IN UINTN                  ControllerIndex,
  2296. -  IN UINTN                  GpioPin,
  2297. -  IN BOOLEAN                Value
  2298. +MvPca95xxSet (
  2299. +  IN EMBEDDED_GPIO       *This,
  2300. +  IN EMBEDDED_GPIO_PIN   Gpio,
  2301. +  IN EMBEDDED_GPIO_MODE  Mode
  2302.    )
  2303.  {
  2304.    EFI_STATUS Status;
  2305. +  UINTN ControllerIndex;
  2306. +  UINTN GpioPin;
  2307.  
  2308. -  Status = MvPca95xxValidate (ControllerIndex, GpioPin);
  2309. -  if (EFI_ERROR (Status)) {
  2310. -    DEBUG ((DEBUG_ERROR,
  2311. -      "%a: invalid pin/controller data\n",
  2312. -      __FUNCTION__,
  2313. -      GpioPin));
  2314. -    return Status;
  2315. -  }
  2316. +  GpioPin = GPIO_PIN (Gpio);
  2317. +  ControllerIndex = GPIO_PORT (Gpio);
  2318.  
  2319. -  Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Value);
  2320. -  if (EFI_ERROR (Status)) {
  2321. -    DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
  2322. +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
  2323. +
  2324. +  switch (Mode) {
  2325. +  case GPIO_MODE_OUTPUT_0:
  2326. +  case GPIO_MODE_OUTPUT_1:
  2327. +    Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Mode);
  2328. +    if (EFI_ERROR (Status)) {
  2329. +      DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
  2330. +      return Status;
  2331. +    }
  2332. +
  2333. +  /* Fall-through */
  2334. +  case GPIO_MODE_INPUT:
  2335. +    Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, Mode);
  2336. +    if (EFI_ERROR (Status)) {
  2337. +      DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
  2338. +      return Status;
  2339. +    }
  2340. +    break;
  2341. +
  2342. +  default:
  2343. +    return EFI_UNSUPPORTED;
  2344.    }
  2345.  
  2346. -  return Status;
  2347. +  return EFI_SUCCESS;
  2348.  }
  2349.  
  2350. +/**
  2351. +
  2352. +Routine Description:
  2353. +
  2354. +  Sets the pull-up / pull-down resistor of a GPIO pin
  2355. +
  2356. +Arguments:
  2357. +
  2358. +  This  - pointer to protocol
  2359. +  Gpio  - which pin
  2360. +  Direction - pull-up, pull-down, or none
  2361. +
  2362. +Returns:
  2363. +
  2364. +  EFI_UNSUPPORTED - Can not perform the requested operation
  2365. +
  2366. +**/
  2367. +EFI_STATUS
  2368. +EFIAPI
  2369. +MvPca95xxSetPull (
  2370. +  IN EMBEDDED_GPIO       *This,
  2371. +  IN EMBEDDED_GPIO_PIN   Gpio,
  2372. +  IN EMBEDDED_GPIO_PULL  Direction
  2373. +  )
  2374. +{
  2375. +  return EFI_UNSUPPORTED;
  2376. +}
  2377.  
  2378.  STATIC
  2379.  VOID
  2380.  MvPca95xxInitProtocol (
  2381. -  IN MARVELL_GPIO_PROTOCOL *GpioProtocol
  2382. +  IN EMBEDDED_GPIO *GpioProtocol
  2383.    )
  2384.  {
  2385. -  GpioProtocol->DirectionInput  = MvPca95xxDirectionInput;
  2386. -  GpioProtocol->DirectionOutput = MvPca95xxDirectionOutput;
  2387. -  GpioProtocol->GetFunction     = MvPca95xxGetFunction;
  2388. -  GpioProtocol->GetValue        = MvPca95xxGetValue;
  2389. -  GpioProtocol->SetValue        = MvPca95xxSetValue;
  2390. +  GpioProtocol->Get     = MvPca95xxGet;
  2391. +  GpioProtocol->Set     = MvPca95xxSet;
  2392. +  GpioProtocol->GetMode = MvPca95xxGetMode;
  2393. +  GpioProtocol->SetPull = MvPca95xxSetPull;
  2394.  }
  2395.  
  2396.  EFI_STATUS
  2397. @@ -519,15 +570,15 @@ MvPca95xxEntryPoint (
  2398.    IN EFI_SYSTEM_TABLE *SystemTable
  2399.    )
  2400.  {
  2401. -  MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
  2402. +  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
  2403. +  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
  2404.    MV_GPIO_DEVICE_PATH *Pca95xxDevicePath;
  2405. -  MV_BOARD_GPIO_DESC *GpioDesc;
  2406.    EFI_STATUS Status;
  2407.  
  2408.    /* Obtain list of available controllers */
  2409.    Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
  2410.                    NULL,
  2411. -                  (VOID **)&BoardDescProtocol);
  2412. +                  (VOID **)&MvBoardProtocol);
  2413.    if (EFI_ERROR (Status)) {
  2414.      DEBUG ((DEBUG_ERROR,
  2415.        "%a: Cannot locate BoardDesc protocol\n",
  2416. @@ -535,24 +586,26 @@ MvPca95xxEntryPoint (
  2417.      return Status;
  2418.    }
  2419.  
  2420. -  Status = BoardDescProtocol->BoardDescGpioGet (BoardDescProtocol, &GpioDesc);
  2421. -  if (EFI_ERROR (Status) || !GpioDesc->I2cIoExpanderDesc) {
  2422. +  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
  2423. +             &GpioDescription);
  2424. +  if (EFI_ERROR (Status)) {
  2425.      DEBUG ((DEBUG_ERROR,
  2426.        "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
  2427.        __FUNCTION__));
  2428.      return Status;
  2429. -  } else if (!GpioDesc->I2cIoExpanderDesc) {
  2430. +  } else if (GpioDescription->GpioExpanders == NULL) {
  2431.      /* Silently exit, if the board does not support the controllers */
  2432.      return EFI_SUCCESS;
  2433.    }
  2434.  
  2435.    Pca95xxDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
  2436. -    &mPca95xxDevicePathTemplate);
  2437. +                        &mDevicePathTemplate);
  2438.    if (Pca95xxDevicePath == NULL) {
  2439.      DEBUG ((DEBUG_ERROR,
  2440.        "%a: Fail to allocate Pca95xxDevicePath\n",
  2441.        __FUNCTION__));
  2442. -    return EFI_OUT_OF_RESOURCES;
  2443. +    Status = EFI_OUT_OF_RESOURCES;
  2444. +    goto ErrPca95xxDevicePathAlloc;
  2445.    }
  2446.  
  2447.    mPca95xxInstance = AllocateZeroPool (sizeof (PCA95XX));
  2448. @@ -560,33 +613,39 @@ MvPca95xxEntryPoint (
  2449.      DEBUG ((DEBUG_ERROR,
  2450.        "%a: Fail to allocate mPca95xxInstance\n",
  2451.        __FUNCTION__));
  2452. +    Status = EFI_OUT_OF_RESOURCES;
  2453.      goto ErrPca95xxInstanceAlloc;
  2454.    }
  2455.  
  2456.    MvPca95xxInitProtocol (&mPca95xxInstance->GpioProtocol);
  2457.  
  2458.    mPca95xxInstance->Signature = PCA95XX_GPIO_SIGNATURE;
  2459. -  mPca95xxInstance->ControllerDesc = GpioDesc->I2cIoExpanderDesc;
  2460. -  mPca95xxInstance->ControllerCount = GpioDesc->I2cIoExpanderCount;
  2461. +  mPca95xxInstance->GpioExpanders = GpioDescription->GpioExpanders;
  2462. +  mPca95xxInstance->GpioExpanderCount = GpioDescription->GpioExpanderCount;
  2463.  
  2464.    Status = gBS->InstallMultipleProtocolInterfaces (
  2465.                    &(mPca95xxInstance->ControllerHandle),
  2466. -                  &gMarvellGpioProtocolGuid,
  2467. +                  &gEmbeddedGpioProtocolGuid,
  2468.                    &(mPca95xxInstance->GpioProtocol),
  2469.                    &gEfiDevicePathProtocolGuid,
  2470.                    (EFI_DEVICE_PATH_PROTOCOL *)Pca95xxDevicePath,
  2471.                    NULL);
  2472.    if (EFI_ERROR (Status)) {
  2473. -    goto ErrLocateBoardDesc;
  2474. +    goto ErrInstallProtocols;
  2475.    }
  2476.  
  2477. +  gBS->FreePool (GpioDescription);
  2478. +
  2479.    return EFI_SUCCESS;
  2480.  
  2481. -ErrLocateBoardDesc:
  2482. +ErrInstallProtocols:
  2483.    gBS->FreePool (mPca95xxInstance);
  2484.  
  2485.  ErrPca95xxInstanceAlloc:
  2486.    gBS->FreePool (Pca95xxDevicePath);
  2487.  
  2488. +ErrPca95xxDevicePathAlloc:
  2489. +  gBS->FreePool (GpioDescription);
  2490. +
  2491.    return Status;
  2492.  }
  2493. diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
  2494. index 031293e..74040b2 100644
  2495. --- a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
  2496. +++ b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
  2497. @@ -58,7 +58,9 @@ NonDiscoverableInitXhci (
  2498.      Status = RegisterNonDiscoverableMmioDevice (
  2499.                       NonDiscoverableDeviceTypeXhci,
  2500.                       Desc[i].SoC->XhciDmaType,
  2501. -                     GetInitializerForType (NonDiscoverableDeviceTypeXhci, i),
  2502. +                     NonDiscoverableDeviceInitializerGet (
  2503. +                       NonDiscoverableDeviceTypeXhci,
  2504. +                       i),
  2505.                       NULL,
  2506.                       1,
  2507.                       Desc[i].SoC->XhciBaseAddress,
  2508. @@ -87,7 +89,9 @@ NonDiscoverableInitAhci (
  2509.      Status = RegisterNonDiscoverableMmioDevice (
  2510.                       NonDiscoverableDeviceTypeAhci,
  2511.                       Desc[i].SoC->AhciDmaType,
  2512. -                     GetInitializerForType (NonDiscoverableDeviceTypeAhci, i),
  2513. +                     NonDiscoverableDeviceInitializerGet (
  2514. +                       NonDiscoverableDeviceTypeAhci,
  2515. +                       i),
  2516.                       NULL,
  2517.                       1,
  2518.                       Desc[i].SoC->AhciBaseAddress,
  2519. @@ -116,7 +120,9 @@ NonDiscoverableInitSdhci (
  2520.      Status = RegisterNonDiscoverableMmioDevice (
  2521.                       NonDiscoverableDeviceTypeSdhci,
  2522.                       Desc[i].SoC->SdMmcDmaType,
  2523. -                     GetInitializerForType (NonDiscoverableDeviceTypeSdhci, i),
  2524. +                     NonDiscoverableDeviceInitializerGet (
  2525. +                       NonDiscoverableDeviceTypeSdhci,
  2526. +                       i),
  2527.                       NULL,
  2528.                       1,
  2529.                       Desc[i].SoC->SdMmcBaseAddress,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement