summaryrefslogtreecommitdiff
path: root/Platform/BroxtonPlatformPkg/Common/Library/PmicLib/PmicLibNull.c
blob: b0abe480cfc306f9b9abdd776d73c29566e0bd9b (plain)
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
/** @file
  Dxe Library for PMIC public API.

  Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/


#include <Uefi.h>
#include <Library/DebugLib.h>
#include "PmicPrivate.h"


struct PmicObject *gPmicObj = NULL;

extern struct PmicObject DmObj;


struct PmicObject *gPmicSupportList[] = {
  &DmObj,  //dummy
};


PMIC_TYPE gPmicType = PMIC_TYPE_NONE;   //global flag to record current probed PMIC type. We could use it to avoid probe HW every time in API.

/**
  Reads an 8-bit PMIC register.

  Reads the 8-bit PMIC register specified by Register.
  The 8-bit read value is returned.

  @param[in]  BaseAddress     - IPC operation address for target PMIC device.
  @param[in]  Register        - The PMIC register to read.

  @retval UINT8               - The value read.
**/
UINT8
EFIAPI
PmicRead8 (
  IN UINT8                     BaseAddress,
  IN UINT8                     Register
  )
{
  RETURN_IF_POINTER_NULL(PmicRead8, 0xff)
  return gPmicObj->PmicRead8(BaseAddress, Register);
}

/**
  Writes an 8-bit PMIC register with a 8-bit value.

  Writes the 8-bit PMIC register specified by Register with the value specified
  by Value and return the operation status.

  @param[in]  BaseAddress     - IPC operation address for target PMIC device.
  @param[in]  Register        - The PMIC register to write.
  @param[in]  Value           - The value to write to the PMIC register.

  @retval EFI_SUCCESS         - Write bytes to PMIC device successfully
  @retval Others              - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicWrite8 (
  IN UINT8                     BaseAddress,
  IN UINT8                     Register,
  IN UINT8                     Value
  )
{
  RETURN_IF_POINTER_NULL(PmicWrite8, EFI_UNSUPPORTED)
  return gPmicObj->PmicWrite8(BaseAddress, Register, Value);
}

/**
  Get previous shutdown root cause.

  @param[in, out]  ShutdownCause - The data to store shutdown root cause.

  @retval EFI_SUCCESS            - Get shutdown root cause successfully.
  @retval Others                 - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicGetShutdownCause (
  IN OUT UINT32    *ShutdownCause
  )
{
  RETURN_IF_POINTER_NULL(PmicGetShutdownCause, EFI_UNSUPPORTED)
  return gPmicObj->PmicGetShutdownCause(ShutdownCause);
}

/**
  Get previous reset root cause

  @param[in, out]  ResetSrc     - The data to store reset root cause

  @retval EFI_SUCCESS           - Get reset root cause successfully.
  @retval EFI_INVALID_PARAMETER - ResetSrc is NULL.
**/
EFI_STATUS
EFIAPI
PmicGetResetSrc (UINT32 *ResetSrc)
{
  RETURN_IF_POINTER_NULL(PmicGetResetSrc, EFI_UNSUPPORTED)
  return gPmicObj->PmicGetResetSrc(ResetSrc);
}

/**
  Get the cause of system wake event.

  @param[in, out]  WakeCause   - The data to store the cause of wake event.

  @retval EFI_SUCCESS          - Get wake cause successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicGetWakeCause (
  IN OUT UINT32    *WakeCause
  )
{
  RETURN_IF_POINTER_NULL(PmicGetWakeCause, EFI_UNSUPPORTED)
  return gPmicObj->PmicGetWakeCause(WakeCause);
}

/**
  Get power source detection result.

  @param[in, out]  PowerSrcIrq   - The data to the cause of wake event.

  @retval EFI_SUCCESS            - Get power source successfully.
  @retval Others                 - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicGetPwrSrcIrq (
  IN OUT UINT32    *PowerSrcIrq
  )
{
  RETURN_IF_POINTER_NULL(PmicGetPwrSrcIrq, EFI_UNSUPPORTED)
  return gPmicObj->PmicGetPwrSrcIrq(PowerSrcIrq);
}

/**
  Battery Detection Status

  @retval TRUE                - Connected
  @retval FALSE               - Disconnected
**/
BOOLEAN
EFIAPI
PmicIsBatOn (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicIsBatOn, TRUE)
  return gPmicObj->PmicIsBatOn();
}

/**
  AC/DC Adapter Detection Status

  @retval TRUE                - Connected
  @retval FALSE               - Disconnected
**/
BOOLEAN
EFIAPI
PmicIsACOn (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicIsACOn, TRUE)
  return gPmicObj->PmicIsACOn();
}

/**
  VBUS Detection Status

  It can be used to detect whether USB charger is connected.

  @retval TRUE                - Connected
  @retval FALSE               - Disconnected
**/
BOOLEAN
EFIAPI
PmicVbusStatus (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicVbusStatus, TRUE)
  return gPmicObj->PmicVbusStatus();
}

/**
  USB ID Detection Status

  @retval UINT8               - Value depends on each PMIC operation.
**/
UINT8
EFIAPI
PmicUSBIDStatus (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicUSBIDStatus, TRUE)
  return gPmicObj->PmicUSBIDStatus();
}

/**
  Clear previous shutdown root cause.

  @retval EFI_SUCCESS          - Clear shutdown root cause successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicClearShutdownCause (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicClearShutdownCause, EFI_UNSUPPORTED)

  return gPmicObj->PmicClearShutdownCause();
}

/**
  Clear the cause of system wake event.

  @retval EFI_SUCCESS          - Clear wake cause successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicClearWakeCause (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicClearWakeCause, EFI_UNSUPPORTED)
  return gPmicObj->PmicClearWakeCause();
}

/**
  Clear the cause of system reset.

  @retval EFI_SUCCESS          - Clear reset cause successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicClearResetSrc (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicClearResetSrc, EFI_UNSUPPORTED)
  return gPmicObj->PmicClearResetSrc();
}

/**
  Initialize PMIC thermal detection capability.

  @retval EFI_SUCCESS          - Initialize thermal detection successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicThermInit (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicThermInit, EFI_UNSUPPORTED)
  return gPmicObj->PmicThermInit();
}

/**
  Initialize PMIC GPIO pin.

  Initialize PMIC GPIO pin in order to get boardid/memcfgid/.. etc later

  @param[in] PlatformInfo      - Platform information with GPIO setting.

  @retval EFI_SUCCESS          - Initialize GPIO pin successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicGpioInit (
  IN VOID    *PlatformInfo
  )
{
  RETURN_IF_POINTER_NULL(PmicGpioInit, EFI_UNSUPPORTED)
  return gPmicObj->PmicGpioInit(PlatformInfo);
}

/**
  Initializes PMIC device.

  @retval EFI_SUCCESS          - Initialize PMIC successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicIntrInit (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicIntrInit, EFI_UNSUPPORTED)
  return gPmicObj->PmicIntrInit();
}

/**
  Initializes Burst Control Unit (BCU) hardware.

  The BCU has several different knobs (input stimuli configuration, interrupts,
  and output actions) that allow the Software and Firmware to change the BCU response
  behavior once these events occur. These BCU control knobs allow for a change in the
  BCU behavior in responding to these triggers and can be completely customized as
  necessary by the specific system implementation.

  @retval EFI_SUCCESS          - Initializes BCU hardware successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicBcuInit (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicBcuInit, EFI_UNSUPPORTED)
  return gPmicObj->PmicBcuInit();
}

/**
  Initializes other miscellaneous functions on PMIC device.

  @retval EFI_SUCCESS          - Initializes miscellaneous functions successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicMiscInit (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicMiscInit, EFI_UNSUPPORTED)
  return gPmicObj->PmicMiscInit ();
}

/**
  Turn on or off VBUS for OTG

  @param[in]  Enable           - TRUE : turn on VBUS
                                 FALSE: turn off VBUS

  @retval EFI_SUCCESS          - Turn on/off VBUS successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicVbusControl (
  IN BOOLEAN    Enable
  )
{
  RETURN_IF_POINTER_NULL(PmicVbusControl, EFI_UNSUPPORTED)
  return gPmicObj->PmicVbusControl(Enable);
}

/**
  Turn on or off 5V VBUS for USB2/3 HOST

  @param[in]  Enable           - TRUE : turn on V5P0S
                                 FALSE: turn off V5P0S

  @retval EFI_SUCCESS          - Turn on/off V5P0S successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicVhostControl (
  IN BOOLEAN    Enable
  )
{
  RETURN_IF_POINTER_NULL(PmicVhostControl, EFI_UNSUPPORTED)
  return gPmicObj->PmicVhostControl(Enable);
}

/**
  Get PMIC Vendor ID and Device ID

  @param[in, out] VenId        - Vendor ID
  @param[in, out] DevId        - Device ID

  @retval EFI_SUCCESS          - Get Vendor ID and Device ID successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicGetDevID (
  IN OUT UINT8    *VenId,
  IN OUT UINT8    *DevId
  )
{
  RETURN_IF_POINTER_NULL(PmicGetDevID, EFI_UNSUPPORTED)
  return gPmicObj->PmicGetDevID(VenId, DevId);
}

/**
  This procedure will get PMIC Stepping

  @retval PMIC Stepping
**/
UINT8
EFIAPI
PmicStepping (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicStepping, 0xff);

  return gPmicObj->PmicStepping();
}

/**
  Get PMIC device instance

  @retval PMIC_TYPE            - Device type is defined in PMIC_TYPE.
**/
PMIC_TYPE
EFIAPI
PmicGetDeviceType (
  VOID
  )
{
  return gPmicObj->PmicType;
}

/**
  Get battery voltage.

  @retval UINT16               - ADC result for battery voltage.
**/
UINT16
EFIAPI
PmicGetVBAT (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicGetVBAT, 0xff)
  return gPmicObj->PmicGetVBAT();
}

/**
  Get battery capacity.

  @retval UINT16               - Remaining percentage of battery capacity.
**/
UINT16
EFIAPI
PmicGetBatteryCap (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicGetBatteryCap, 0xff)
  return gPmicObj->PmicGetBatteryCap();
}

/**
  Get power button status

  @retval TRUE                  - Power button pressed.
  @retval FALSE                 - Power button released.
**/
BOOLEAN
EFIAPI
PmicIsPwrBtnPressed (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicIsPwrBtnPressed, TRUE)

  return gPmicObj->PmicIsPwrBtnPressed();
}

/**
  Disable the capability to shutdown platform using power button.

  @param[out] ButtonHoldTime   - If the power button is disabled successfully,
                                 this contains the time in seconds need to hold power button to shutdown platform.

  @retval EFI_SUCCESS          - Succeed to disable power button
  @retval Others               - Failed to disable power button
**/
EFI_STATUS
EFIAPI
PmicDisablePowerButton (
  OUT UINT8    *ButtonHoldTime
  )
{
  RETURN_IF_POINTER_NULL(PmicDisablePowerButton, EFI_UNSUPPORTED)
  return gPmicObj->PmicDisablePowerButton(ButtonHoldTime);
}

/**
  Enable the capability to shutdown platform using power button.

  @param[in] ButtonHoldTime    - Time in seconds to shut down the platform if power button is enabled and hold

  @retval EFI_SUCCESS          - Succeed to enable power button
  @retval Others               - Filed to enable power button
**/
EFI_STATUS
EFIAPI
PmicEnablePowerButton (
  IN UINT8    ButtonHoldTime
  )
{
  RETURN_IF_POINTER_NULL(PmicEnablePowerButton, EFI_UNSUPPORTED)
  return gPmicObj->PmicEnablePowerButton(ButtonHoldTime);
}

/**
  Set VDDQ to 1.35V for DDR3L

  @retval EFI_SUCCESS          - Succeed to Set VDDQ
  @retval Others               - Filed to Set VDDQ
**/
EFI_STATUS
EFIAPI
PmicSetVDDQ (
  VOID
  )
{
  RETURN_IF_POINTER_NULL(PmicSetVDDQ, EFI_UNSUPPORTED)
  return gPmicObj->PmicSetVDDQ();
}

/**
  Probe to find the correct PMIC object.

  After probling, g_pmic_obj points to correct PMIC object
  This routine is invoked when library is loaded .

  @retval TRUE                - There is one PMIC object found.
  @retval FALSE               - No PMIC object found.
**/
BOOLEAN
EFIAPI
PmicProbe (
  VOID
  )
{
  gPmicObj = &DmObj;
  return FALSE;
}

/**
  Read charger's register provided by PMIC.

  @param[in]  Offset           - The charger's register to read.
  @param[out] Value            - The value read.

  @retval EFI_SUCCESS          - Read charger's register successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicChargerRead (
  IN  UINT8     Offset,
  OUT UINT8     *Value
  )
{
  RETURN_IF_POINTER_NULL(PmicChargerRead, EFI_UNSUPPORTED)
  return gPmicObj->PmicChargerRead(Offset, Value);
}

/**
  Write charger's register provided by PMIC.

  @param[in] Offset            - The charger's register to write.
  @param[in] Value             - The value written.

  @retval EFI_SUCCESS          - Write charger's register successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicChargerWrite (
  IN UINT8    Offset,
  IN UINT8    Value
  )
{
  RETURN_IF_POINTER_NULL(PmicChargerWrite, EFI_UNSUPPORTED)
  return gPmicObj->PmicChargerWrite(Offset, Value);
}

/**
  Detect charger type and charger presence.

  @param[out] ChargerPresent   - TRUE : Charger present.
                                 FALSE: Charger not present.
  @param[out] ChargerType      - Charger type - SDP/DCP/CDP... etc.

  @retval EFI_SUCCESS          - Detect charger type and charger presence successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicDetectCharger (
  OUT BOOLEAN    *ChargerPresent,
  OUT UINT8      *ChargerType
  )
{
  RETURN_IF_POINTER_NULL(PmicDetectCharger, EFI_UNSUPPORTED)
  return gPmicObj->PmicDetectCharger(ChargerPresent, ChargerType);
}

/**
  Controls external USB PHY reset

  @param[in] Enable            - TRUE : OUTOFRESET - external PHY is out of reset
                                 FALSE: INRESET - external PHY is in reset

  @retval EFI_SUCCESS          - Controls external USB PHY successfully.
  @retval Others               - Status depends on each PMIC operation.
**/
EFI_STATUS
EFIAPI
PmicUSBSwitchControl (
  IN BOOLEAN    Enable
  )
{
  RETURN_IF_POINTER_NULL(PmicUSBSwitchControl, EFI_UNSUPPORTED)
  return gPmicObj->PmicUSBSwitchControl(Enable);
}

/**
  Pmic library constructor

  PMIC type is probed in this function. It is invoked every time Pmiclib is loaded.

  @retval  EFI_SUCCESS         - Construct PMIC instance successfully.
**/
RETURN_STATUS
EFIAPI
PmicLibConstructor (
  VOID
  )
{
  PmicProbe();
  return EFI_SUCCESS;
}