hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
/** @file
  Header file for GpioPrivateLib.
  All function in this library is available for PEI, DXE, and SMM,
 
  Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
 
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#ifndef _GPIO_PRIVATE_LIB_H_
#define _GPIO_PRIVATE_LIB_H_
 
#include <GpioConfig.h>
#include <Library/PchPcrLib.h>
 
//
// Structure for native pin data
//
typedef struct {
  GPIO_PAD       Pad;
  GPIO_PAD_MODE  Mode;
} GPIO_PAD_NATIVE_FUNCTION;
 
//
// Below defines are based on GPIO_CONFIG structure fields
//
#define B_GPIO_PAD_MODE_MASK                            0xF
#define N_GPIO_PAD_MODE_BIT_POS                         0
#define B_GPIO_HOSTSW_OWN_MASK                          0x3
#define N_GPIO_HOSTSW_OWN_BIT_POS                       0
#define B_GPIO_DIRECTION_MASK                           0x1F
#define B_GPIO_DIRECTION_DIR_MASK                       0x7
#define N_GPIO_DIRECTION_DIR_BIT_POS                    0
#define B_GPIO_DIRECTION_INV_MASK                       0x18
#define N_GPIO_DIRECTION_INV_BIT_POS                    3
#define B_GPIO_OUTPUT_MASK                              0x3
#define N_GPIO_OUTPUT_BIT_POS                           0
#define N_GPIO_INT_CONFIG_INT_SOURCE_BIT_POS            0
#define N_GPIO_INT_CONFIG_INT_TYPE_BIT_POS              5
#define B_GPIO_RESET_CONFIG_RESET_MASK                  0x3F
#define N_GPIO_RESET_CONFIG_OLD_RESET_TYPE              BIT1
#define B_GPIO_RESET_CONFIG_OLD_RESET_MASK              0xF
#define N_GPIO_RESET_CONFIG_RESET_BIT_POS               0
#define B_GPIO_RESET_CONFIG_GPD_RESET_MASK              (BIT5 | BIT4)
#define B_GPIO_RESET_CONFIG_GPP_RESET_MASK              (BIT3 | BIT2)
#define N_GPIO_ELECTRICAL_CONFIG_TERMINATION_BIT_POS    0
#define N_GPIO_OTHER_CONFIG_RXRAW_BIT_POS               0
 
//
// Structure for storing information about registers offset, community,
// maximal pad number for available groups
//
typedef struct {
  PCH_SBI_PID  Community;
  UINT16       PadOwnOffset;
  UINT16       HostOwnOffset;
  UINT16       GpiIsOffset;
  UINT16       GpiIeOffset;
  UINT16       GpiGpeStsOffset;
  UINT16       GpiGpeEnOffset;
  UINT16       SmiStsOffset;
  UINT16       SmiEnOffset;
  UINT16       NmiStsOffset;
  UINT16       NmiEnOffset;
  UINT16       PadCfgLockOffset;
  UINT16       PadCfgLockTxOffset;
  UINT16       PadCfgOffset;
  UINT16       PadPerGroup;
} GPIO_GROUP_INFO;
 
//
// If in GPIO_GROUP_INFO structure certain register doesn't exist
// it will have value equal to NO_REGISTER_FOR_PROPERTY
//
#define NO_REGISTER_FOR_PROPERTY 0xFFFF
 
/**
  This procedure will retrieve address and length of GPIO info table
 
  @param[out]  GpioGroupInfoTableLength   Length of GPIO group table
 
  @retval Pointer to GPIO group table
**/
CONST GPIO_GROUP_INFO*
GpioGetGroupInfoTable (
  OUT UINT32              *GpioGroupInfoTableLength
  );
 
typedef struct {
  CONST CHAR8*    GpioGroupPrefix;
  CONST GPIO_PAD  FirstUniqueGpio;
  CONST CHAR8**   GroupUniqueNames;
  CONST UINT32    UniqueNamesTableSize;
} GPIO_GROUP_NAME_INFO;
 
//
// Helper macros for initializing GPIO_GROUP_NAME_INFO structures
//
#define GPIO_GROUP_NAME(GroupName,FirstUniqueGpio,GroupUniqueNamesTable) \
  {GroupName, FirstUniqueGpio, GroupUniqueNamesTable, ARRAY_SIZE (GroupUniqueNamesTable)}
 
#define GPIO_GROUP_NAME_BASIC(GroupName) \
  {GroupName, 0, NULL, 0}
 
/**
  Returns GPIO_GROUP_NAME_INFO corresponding to the give GpioPad
 
  @param[in]  GroupIndex  Group index
 
  @retval  GPIO_GROUP_NAME_INFO*  Pointer to the GPIO_GROUP_NAME_INFO
  @retval  NULL                   If no group descriptor was found
**/
CONST
GPIO_GROUP_NAME_INFO*
GpioGetGroupNameInfo (
  IN UINT32  GroupIndex
  );
 
/**
  Get GPIO Chipset ID specific to PCH generation and series
**/
UINT32
GpioGetThisChipsetId (
  VOID
  );
 
/**
  This procedure is used to check if GpioPad is valid for certain chipset
 
  @param[in]  GpioPad             GPIO pad
 
  @retval TRUE                    This pin is valid on this chipset
          FALSE                   Incorrect pin
**/
BOOLEAN
GpioIsCorrectPadForThisChipset (
  IN  GPIO_PAD        GpioPad
  );
 
/**
  Generates GPIO name from GpioPad
  This function returns pointer to the static buffer.
 
  @param[in] GpioPad  GpioPad
 
  @retval CHAR8*  Pointer to the GPIO name
**/
CHAR8*
GpioName (
  IN GPIO_PAD  GpioPad
  );
 
/**
  This procedure will get value of selected gpio register
 
  @param[in]  Group               GPIO group number
  @param[in]  Offset              GPIO register offset
  @param[out] RegVal              Value of gpio register
 
  @retval EFI_SUCCESS             The function completed successfully
  @retval EFI_INVALID_PARAMETER   Invalid group or pad number
**/
EFI_STATUS
GpioGetReg (
  IN  GPIO_GROUP              Group,
  IN  UINT32                  Offset,
  OUT UINT32                  *RegVal
  );
 
/**
  This procedure will set value of selected gpio register
 
  @param[in] Group               GPIO group number
  @param[in] Offset              GPIO register offset
  @param[in] RegVal              Value of gpio register
 
  @retval EFI_SUCCESS            The function completed successfully
  @retval EFI_INVALID_PARAMETER  Invalid group or pad number
**/
EFI_STATUS
GpioSetReg (
  IN GPIO_GROUP              Group,
  IN UINT32                  Offset,
  IN UINT32                  RegVal
  );
 
/**
  This procedure is used by PchSmiDispatcher and will return information
  needed to register GPI SMI.
 
  @param[in]  Index                   GPI SMI number
  @param[out] GpioPin                 GPIO pin
  @param[out] GpiSmiBitOffset         GPI SMI bit position within GpiSmi Registers
  @param[out] GpiHostSwOwnRegAddress  Address of HOSTSW_OWN register
  @param[out] GpiSmiStsRegAddress     Address of GPI SMI status register
 
  @retval EFI_SUCCESS             The function completed successfully
  @retval EFI_INVALID_PARAMETER   Invalid group or pad number
**/
EFI_STATUS
GpioGetPadAndSmiRegs (
  IN UINT32            Index,
  OUT GPIO_PAD         *GpioPin,
  OUT UINT8            *GpiSmiBitOffset,
  OUT UINT32           *GpiHostSwOwnRegAddress,
  OUT UINT32           *GpiSmiStsRegAddress
  );
 
/**
  This procedure will set GPIO Driver IRQ number
 
  @param[in]  Irq                 Irq number
 
  @retval EFI_SUCCESS             The function completed successfully
  @retval EFI_INVALID_PARAMETER   Invalid IRQ number
**/
EFI_STATUS
GpioSetIrq (
  IN  UINT8          Irq
  );
 
/**
  This function provides GPIO Community PortIDs
 
  @param[out] NativePinsTable                Table with GPIO COMMx SBI PortIDs
 
  @retval      Number of communities
**/
UINT32
GpioGetComSbiPortIds (
  OUT PCH_SBI_PID    **GpioComSbiIds
  );
 
/**
  This procedure will perform special handling of GPP_A_12.
 
  @param[in]  None
 
  @retval None
**/
VOID
GpioA12SpecialHandling (
  VOID
  );
 
//
// Structure which stores information needed to map GPIO Group
// to 1-Tier GPE. Configuration is needed both in PMC and GPIO IP.
// Because GPE_DWx can handle only 32 pins only single double word can
// be mapped at a time. Each DW for a group has different configuration in PMC and GPIO
//
typedef struct {
  GPIO_GROUP  Group;
  UINT8       GroupDw;
  UINT8       PmcGpeDwxVal;
  UINT8       GpioGpeDwxVal;
} GPIO_GROUP_TO_GPE_MAPPING;
 
/**
  Get information for GPIO Group required to program GPIO and PMC for desired 1-Tier GPE mapping
 
  @param[out] GpioGroupToGpeMapping        Table with GPIO Group to GPE mapping
  @param[out] GpioGroupToGpeMappingLength  GPIO Group to GPE mapping table length
**/
VOID
GpioGetGroupToGpeMapping (
  OUT GPIO_GROUP_TO_GPE_MAPPING  **GpioGroupToGpeMapping,
  OUT UINT32                     *GpioGroupToGpeMappingLength
  );
 
/**
  This procedure will return Port ID of GPIO Community from GpioPad
 
  @param[in] GpioPad            GpioPad
 
  @retval GpioCommunityPortId   Port ID of GPIO Community
**/
UINT8
GpioGetGpioCommunityPortIdFromGpioPad (
  IN GPIO_PAD        GpioPad
  );
 
/**
  This procedure will return PadCfg address from GpioPad
 
  @param[in] GpioPad            GpioPad
 
  @retval GpioPadCfgAddress     PadCfg Address of GpioPad
**/
UINT32
GpioGetGpioPadCfgAddressFromGpioPad (
  IN GPIO_PAD        GpioPad
  );
 
/**
  This procedure is used to unlock all GPIO pads.
  This function can only be called when platform is still in HOSTIA_BOOT_SAI.
**/
VOID
GpioUnlockAllPads (
  VOID
  );
 
/**
  This procedure will check if GpioPad is owned by host.
 
  @param[in] GpioPad       GPIO pad
 
  @retval TRUE             GPIO pad is owned by host
  @retval FALSE            GPIO pad is not owned by host and should not be used with GPIO lib API
**/
BOOLEAN
GpioIsPadHostOwned (
  IN GPIO_PAD             GpioPad
  );
 
 
/**
  This procedure will check if GpioPad argument is valid.
  Function will check below conditions:
   - GpioPad represents a pad for current PCH
   - GpioPad belongs to valid GpioGroup
   - GPIO PadNumber is not greater than number of pads for this group
 
  @param[in] GpioPad       GPIO pad
 
  @retval TRUE             GPIO pad is valid and can be used with GPIO lib API
  @retval FALSE            GPIO pad is invalid and cannot be used with GPIO lib API
**/
BOOLEAN
GpioIsPadValid (
  IN GPIO_PAD             GpioPad
  );
 
/**
  This procedure will read GPIO Pad Configuration register
 
  @param[in] GpioPad          GPIO pad
  @param[in] DwReg            Choose PADCFG register: 0:DW0, 1:DW1
 
  @retval PadCfgRegValue      PADCFG_DWx value
**/
UINT32
GpioReadPadCfgReg (
  IN GPIO_PAD             GpioPad,
  IN UINT8                DwReg
  );
 
/**
  This procedure will write or read GPIO Pad Configuration register
 
  @param[in] GpioPad              GPIO pad
  @param[in] DwReg                Choose PADCFG register: 0:DW0, 1:DW1
  @param[in] PadCfgAndMask        Mask to be AND'ed with PADCFG reg value
  @param[in] PadCfgOrMask         Mask to be OR'ed with PADCFG reg value
 
  @retval none
**/
VOID
GpioWritePadCfgReg (
  IN GPIO_PAD             GpioPad,
  IN UINT8                DwReg,
  IN UINT32               PadCfgAndMask,
  IN UINT32               PadCfgOrMask
  );
 
/**
  This procedure will set GPIO mode
 
  @param[in]  GpioPad             GPIO pad
  @param[out] PadModeValue        GPIO pad mode value
 
  @retval EFI_SUCCESS             The function completed successfully
  @retval EFI_INVALID_PARAMETER   Invalid group or pad number
**/
EFI_STATUS
GpioSetPadMode (
  IN GPIO_PAD                GpioPad,
  IN GPIO_PAD_MODE           PadModeValue
  );
 
/**
  This procedure will get GPIO mode
 
  @param[in]  GpioPad             GPIO pad
  @param[out] PadModeValue        GPIO pad mode value
 
  @retval EFI_SUCCESS             The function completed successfully
  @retval EFI_INVALID_PARAMETER   Invalid group or pad number
**/
EFI_STATUS
GpioGetPadMode (
  IN  GPIO_PAD                 GpioPad,
  OUT GPIO_PAD_MODE            *PadModeValue
  );
 
/**
  This procedure will check if group is within DeepSleepWell.
 
  @param[in]  Group               GPIO Group
 
  @retval GroupWell               TRUE:  This is DSW Group
                                  FALSE: This is not DSW Group
**/
BOOLEAN
GpioIsDswGroup (
  IN  GPIO_GROUP         Group
  );
 
/**
  The function performs GPIO Power Management programming.
**/
VOID
GpioConfigurePm (
  VOID
  );
 
/**
  This function sets SerialIo I2C controller pins into native mode
 
  @param[in]  SerialIoI2cControllerNumber   I2C controller
  @param[in]  GpioTermination               GPIO termination type
 
  @retval Status
**/
EFI_STATUS
GpioEnableSerialIoI2c (
  IN  UINT32                  SerialIoI2cControllerNumber,
  IN  GPIO_ELECTRICAL_CONFIG  GpioTermination
  );
 
/**
  This function sets SerialIo UART controller pins into native mode
 
  @param[in]  SerialIoUartControllerNumber   UART controller
  @param[in]  HardwareFlowControl            Hardware Flow control
  @param[in]  PinMuxing                      UART controller pin muxing
 
  @retval Status
**/
EFI_STATUS
GpioEnableSerialIoUart (
  IN  UINT32            SerialIoUartControllerNumber,
  IN  BOOLEAN           HardwareFlowControl,
  IN  UINT32            PinMuxing
  );
 
/**
  This function sets SerialIo SPI controller pins into native mode
 
  @param[in]  SerialIoSpiControllerNumber   SPI controller
 
  @retval Status
**/
EFI_STATUS
GpioEnableSerialIoSpi (
  IN  UINT32            SerialIoSpiControllerNumber
  );
 
/**
  This function sets ISH I2C controller pins into native mode
 
  @param[in]  IshI2cControllerNumber   I2C controller
 
  @retval Status
**/
EFI_STATUS
GpioEnableIshI2c (
  IN  UINT32            IshI2cControllerNumber
  );
 
/**
  This function sets ISH UART controller pins into native mode
 
  @param[in]  IshUartControllerNumber   UART controller
 
  @retval Status
**/
EFI_STATUS
GpioEnableIshUart (
  IN  UINT32            IshUartControllerNumber
  );
 
/**
  This function sets ISH SPI controller pins into native mode
 
  @param[in]  IshSpiControllerNumber   SPI controller
 
  @retval Status
**/
EFI_STATUS
GpioEnableIshSpi (
  IN  UINT32            IshSpiControllerNumber
  );
 
/**
  This function sets ISH GP pin into native mode
 
  @param[in]  IshGpPinNumber   ISH GP pin number
 
  @retval Status
**/
EFI_STATUS
GpioEnableIshGpPin (
  IN  UINT32            IshGpPinNumber
  );
 
/**
  This function sets SCS SD card controller pins into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableScsSdCard (
  VOID
  );
 
/**
  This function enables SCS SD Card controller card detect pin
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableScsSdCardDetect (
  VOID
  );
 
/**
  This function sets SCS eMMC controller pins into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableScsEmmc (
  VOID
  );
 
/**
  This function sets HDA Link pins into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableHdaLink (
  VOID
  );
 
/**
  This function sets HDA DMIC pins into native mode
 
  @param[in]  DmicNumber   DMIC number
 
  @retval Status
**/
EFI_STATUS
GpioEnableHdaDmic (
  IN  UINT32            DmicNumber
  );
 
/**
  This function sets HDA SSP interface pins into native mode
 
  @param[in]  SspInterfaceNumber   SSPx interface number
 
  @retval Status
**/
EFI_STATUS
GpioEnableHdaSsp (
  IN  UINT32            SspInterfaceNumber
  );
 
/**
  This function sets HDA SSP Master Clock into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableHdaSspMasterClock (
  VOID
  );
 
/**
  This function sets HDA SoundWire interface pins into native mode
 
  @param[in]  SndwInterfaceNumber   SNDWx interface number
 
  @retval Status
**/
EFI_STATUS
GpioEnableHdaSndw (
  IN  UINT32            SndwInterfaceNumber
  );
 
/**
  This function sets SMBUS controller pins into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableSmbus (
  VOID
  );
 
/**
  This function sets SMBUS ALERT pins into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableSmbusAlert (
  VOID
  );
 
/**
  This function enables USB OverCurrent pins by setting
  USB2 OCB pins into native mode
 
  @param[in]  OcPinNumber            USB OC pin number
 
  @retval Status
**/
EFI_STATUS
GpioEnableUsbOverCurrent (
  IN  UINTN   OcPinNumber
  );
 
/**
  This function sets SATA DevSlp pins into native mode
 
  @param[in]  SataCtrlIndex       SATA controller index
  @param[in]  SataPort            SATA port number
 
  @retval Status
**/
EFI_STATUS
GpioEnableSataDevSlpPin (
  IN  UINT32  SataCtrlIndex,
  IN  UINTN   SataPort
  );
 
/**
  This function checks if SataDevSlp pin is in native mode
 
  @param[in]  SataCtrlIndex       SATA controller index
  @param[in]  SataPort            SATA port
  @param[out] DevSlpPad           DevSlpPad
                                  This is an optional parameter and may be NULL.
 
  @retval TRUE                    DevSlp is in native mode
          FALSE                   DevSlp is not in native mode
**/
BOOLEAN
GpioIsSataDevSlpPinEnabled (
  IN  UINT32          SataCtrlIndex,
  IN  UINTN           SataPort,
  OUT GPIO_PAD        *DevSlpPad  OPTIONAL
  );
 
/**
  This function sets SATAGPx pin into native mode
 
  @param[in]  SataCtrlIndex       SATA controller index
  @param[in]  SataPort            SATA port number
 
  @retval Status
**/
EFI_STATUS
GpioEnableSataGpPin (
  IN  UINT32  SataCtrlIndex,
  IN  UINTN   SataPort
  );
 
/**
  This function provides SATA GP pin data
 
  @param[in]  SataCtrlIndex       SATA controller index
  @param[in]  SataPort            SATA port number
  @param[out] NativePin           SATA GP pin
**/
VOID
GpioGetSataGpPin (
  IN  UINT32                    SataCtrlIndex,
  IN  UINTN                     SataPort,
  OUT GPIO_PAD_NATIVE_FUNCTION  *NativePin
  );
 
/**
  This function sets SATA LED pin into native mode. SATA LED indicates
  SATA controller activity
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableSataLed (
  VOID
  );
 
/**
  Returns pad for given CLKREQ# index.
 
  @param[in]  ClkreqIndex       CLKREQ# number
 
  @return CLKREQ# pad.
**/
GPIO_PAD
GpioGetClkreqPad (
  IN     UINT32   ClkreqIndex
  );
 
/**
  Enables CLKREQ# pad in native mode.
 
  @param[in]  ClkreqIndex       CLKREQ# number
 
  @return none
**/
VOID
GpioEnableClkreq (
  IN     UINT32   ClkreqIndex
  );
 
/**
  This function sets PCHHOT pin into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnablePchHot (
  VOID
  );
 
/**
  This function sets VRALERTB pin into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioEnableVrAlert (
  VOID
  );
 
/**
  This function sets CPU GP pins into native mode
 
  @param[in]  CpuGpPinNum               CPU GP pin number
 
  @retval Status
**/
EFI_STATUS
GpioEnableCpuGpPin (
  IN  UINT32                            CpuGpPinNum
  );
 
/**
This function sets CPU C10 Gate pins into native mode
 
@retval Status
**/
EFI_STATUS
GpioEnableCpuC10GatePin (
  VOID
  );
 
//
// DDSP_HPD pins
//
typedef enum {
  GpioDdspHpd0 = 0x00,
  GpioDdspHpd1 = 0x01,
  GpioDdspHpd2 = 0x02,
  GpioDdspHpd3 = 0x03,
  GpioDdspHpd4 = 0x04,
  GpioDdspHpdA = 0x10,
  GpioDdspHpdB = 0x11,
  GpioDdspHpdC = 0x12
} GPIO_DDSP_HPD;
 
/**
  This function sets DDSP_HPDx pin into native mode
 
  @param[in]  DdspHpdPin     DDSP_HPDx pin
 
  @retval Status
**/
EFI_STATUS
GpioEnableDpHotPlugDetect (
  IN GPIO_DDSP_HPD  DdspHpdPin
  );
 
/**
  This function sets HPD, VDDEN, BKLTEN and BKLTCTL pins into native mode for eDP Panel
 
  @retval Status
**/
EFI_STATUS
GpioEnableEdpPins (
  VOID
  );
 
//
// DDPx pins
//
typedef enum {
  GpioDdp1 = 0x01,
  GpioDdp2 = 0x02,
  GpioDdp3 = 0x03,
  GpioDdp4 = 0x04,
  GpioDdpA = 0x10,
  GpioDdpB = 0x11,
  GpioDdpC = 0x12,
  GpioDdpD = 0x13,
  GpioDdpF = 0x15,
} GPIO_DDP;
 
/**
  This function sets DDP pins into native mode
 
  @param[in]  DdpInterface   DDPx interface
 
  @retval Status
**/
EFI_STATUS
GpioEnableDpInterface (
  IN  GPIO_DDP            DdpInterface
  );
 
/**
  This function configures GPIO connection between CNVi and CRF
 
  @retval Status
**/
EFI_STATUS
GpioConfigureCnviCrfConnection (
  VOID
  );
 
/**
  This function enables CNVi RF Reset pin
**/
VOID
GpioEnableCnviRfResetPin (
  VOID
  );
 
/**
  This function enables CNVi MODEM CLKREQ pin
**/
VOID
GpioEnableCnviModemClkReqPin (
  VOID
  );
 
/**
  CNVi Bluetooth UART connection options
**/
typedef enum {
  GpioCnviBtUartNotConnected,
  GpioCnviBtUartToSerialIoUart0,
  GpioCnviBtUartToIshUart0,
  GpioCnviBtUartToExternalPads
} VGPIO_CNVI_BT_UART_CONNECTION_TYPE;
 
/**
  This function configures virtual GPIO connection for CNVi Bluetooth UART
 
  @param[in]  ConnectionType
 
  @retval Status
**/
EFI_STATUS
GpioConfigureCnviBtUartConnection (
  IN  VGPIO_CNVI_BT_UART_CONNECTION_TYPE  ConnectionType
  );
 
/**
  CNVi Bluetooth I2S connection options
**/
typedef enum {
  GpioCnviBtI2sNotConnected,
  GpioCnviBtI2sToSsp0,
  GpioCnviBtI2sToSsp1,
  GpioCnviBtI2sToSsp2,
  GpioCnviBtI2sToExternalPads
} VGPIO_CNVI_BT_I2S_CONNECTION_TYPE;
 
/**
  This function configures virtual GPIO connection for CNVi Bluetooth I2S
 
  @param[in]  ConnectionType
 
  @retval Status
**/
EFI_STATUS
GpioConfigureCnviBtI2sConnection (
  IN  VGPIO_CNVI_BT_I2S_CONNECTION_TYPE  ConnectionType
  );
 
/**
  CNVi MultiFunction UART connection options
**/
typedef enum {
  GpioCnviMfUart1NotConnected,
  GpioCnviMfUart1ToSerialIoUart2,
  GpioCnviMfUart1ToIshUart0,
  GpioCnviMfUart1ToExternalPads
} VGPIO_CNVI_MF_UART1_CONNECTION_TYPE;
 
/**
  This function configures virtual GPIO connection for CNVi MFUART1
 
  @param[in]  ConnectionType
 
  @retval Status
**/
EFI_STATUS
GpioConfigureCnviMfUart1Connection (
  IN  VGPIO_CNVI_MF_UART1_CONNECTION_TYPE  ConnectionType
  );
 
 
/**
  This function sets CNVi Bluetooth Enable value
 
  @param[in] Value                CNVi BT enable value
                                  0: Disable, 1: Enable
  @retval Status
**/
EFI_STATUS
GpioSetCnviBtEnState (
   IN  UINT32  Value
  );
 
/**
  CNVi Bluetooth UART connection options
**/
typedef enum {
  GpioCnviBtIfUart = 0,
  GpioCnviBtIfUsb,
} VGPIO_CNVI_BT_INTERFACE;
 
/**
  This function sets CNVi Bluetooth main host interface
 
  @param[in] BtInterface          CNVi BT Interface Select value
                                  GpioCnviBtIfUart: UART, GpioCnviBtIfUsb: USB
  @retval Status
**/
EFI_STATUS
GpioSetCnviBtInterface (
  IN  VGPIO_CNVI_BT_INTERFACE  BtInterface
  );
 
/**
  This function sets CNVi Bluetooth Wireless Charging support
 
  @param[in] BtWirelessCharging   CNVi BT Wireless Charging support
                                  0: Normal BT operation (no Wireless Charging support)
                                  1: Enable BT Wireless Charging
  @retval Status
**/
EFI_STATUS
GpioSetCnviBtWirelessCharging (
  IN  UINT32  BtWirelessCharging
  );
 
/**
  This function enables and configures CNVi Bluetooth Host wake-up interrupt
 
  @param[in] None
 
  @retval Status
**/
EFI_STATUS
GpioConfigureCnviBtHostWakeInt (
  VOID
  );
 
/**
  CNVi WiFi mode
**/
typedef enum {
  GpioCnviWiFiEnabled,
  GpioCnviWiFiAuto
} VGPIO_CNVI_WIFI_MODE;
 
/**
  This function sets CNVi WiFi mode
 
  @param[in] Value                CNVi WiFi Mode value
                                  GpioCnviWiFiAuto: WiFi is automatically enabled/disabled by WiFi core
                                  GpioCnviWiFiEnabled: WiFi is enabled regardless of WiFi core decision
  @retval Status
**/
EFI_STATUS
GpioSetCnviWifiMode (
  IN  VGPIO_CNVI_WIFI_MODE  WiFiMode
  );
 
/**
  This function enables IMGU CLKOUT native pin
 
  @param[in] None
 
  @retval Status
**/
EFI_STATUS
GpioEnableImguClkOut (
  VOID
  );
 
/**
  Power button debounce configuration
  Debounce time can be specified in microseconds. Only certain values according
  to below formula are supported:
   DebounceTime = (2 ^ PADCFG_DW2.DEBOUNCE)*(glitch filter clock period).
  RTC clock with f = 32 KHz is used for glitch filter.
   DebounceTime = (2 ^ PADCFG_DW2.DEBOUNCE)*(31.25 us).
  Supported DebounceTime values are following:
   DebounceTime = 0 -> Debounce feature disabled
   DebounceTime > 0 && < 250us -> Not supported
   DebounceTime = 250us - 1024000us -> Supported range (DebounceTime = 250us * 2^n)
  For values not supported by HW, they will be rounded down to closest supported one
 
  @param[in] DebounceTime    Debounce Time in microseconds
                             If Debounce Time = 0, Debouncer feature will be disabled
                             Function will set DebounceTime argument to rounded supported value
**/
VOID
GpioSetPwrBtnDebounceTimer (
  IN UINT32                DebounceTime
  );
 
/**
  Configure LPC GPIO
**/
VOID
LpcConfigureGpio (
  VOID
  );
 
#endif // _GPIO_PRIVATE_LIB_H_