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
/**
*
*  Copyright (c) 2018, Marvell International Ltd. All rights reserved.
*
*  SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/
 
#include <Protocol/I2cIo.h>
 
#include <Pi/PiI2c.h>
 
#include "MvPca95xxDxe.h"
 
STATIC PCA95XX *mPca95xxInstance;
 
STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
  {
    {
      HARDWARE_DEVICE_PATH,
      HW_VENDOR_DP,
      {
        (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
                 sizeof (MV_GPIO_DRIVER_TYPE)),
        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
      },
    },
    EFI_CALLER_ID_GUID
  },
  MV_GPIO_DRIVER_TYPE_PCA95XX,
  {
    END_DEVICE_PATH_TYPE,
    END_ENTIRE_DEVICE_PATH_SUBTYPE,
    {
      sizeof(EFI_DEVICE_PATH_PROTOCOL),
      0
    }
  }
};
 
STATIC PCA95XX_PIN_COUNT mPca95xxPinCount[PCA95XX_MAX_ID] = {
  PCA9505_PIN_COUNT,
  PCA9534_PIN_COUNT,
  PCA9535_PIN_COUNT,
  PCA9536_PIN_COUNT,
  PCA9537_PIN_COUNT,
  PCA9538_PIN_COUNT,
  PCA9539_PIN_COUNT,
  PCA9554_PIN_COUNT,
  PCA9555_PIN_COUNT,
  PCA9556_PIN_COUNT,
  PCA9557_PIN_COUNT,
};
 
#if !defined(MDEPKG_NDEBUG)
/**
 
Routine Description:
 
  Verifies if controller index / GPIO pin values
  are within proper boundaries.
 
Arguments:
 
  ControllerIndex - index of controller
  GpioPin - which pin to read
 
Returns:
 
  EFI_SUCCESS           - GPIO pin / controller index are proper
  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
**/
STATIC
EFI_STATUS
MvPca95xxValidate (
  IN UINTN ControllerIndex,
  IN UINTN GpioPin
  )
{
  UINTN ControllerId;
 
  if (ControllerIndex >= mPca95xxInstance->GpioExpanderCount) {
    DEBUG ((DEBUG_ERROR,
      "%a: Invalid GPIO ControllerIndex: %d\n",
      __FUNCTION__,
      ControllerIndex));
    return EFI_INVALID_PARAMETER;
  }
 
  ControllerId = mPca95xxInstance->GpioExpanders[ControllerIndex].ChipId;
 
  if (GpioPin >= mPca95xxPinCount[ControllerId]) {
    DEBUG ((DEBUG_ERROR,
      "%a: GPIO pin #%d not available in Controller#%d\n",
      __FUNCTION__,
      GpioPin,
      ControllerIndex));
    return EFI_INVALID_PARAMETER;
  }
 
  return EFI_SUCCESS;
}
#endif
 
EFI_STATUS
EFIAPI
MvPca95xxGetI2c (
  IN     UINTN                 ControllerIndex,
  IN OUT EFI_I2C_IO_PROTOCOL **I2cIo
  )
{
  UINTN        I2cBus, I2cAddress;
  UINTN        HandleCount, Index;
  EFI_HANDLE  *HandleBuffer;
  EFI_STATUS   Status;
 
  I2cBus = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cBus;
  I2cAddress = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cAddress;
 
  /* Locate Handles of all EfiI2cIoProtocol producers */
  Status = gBS->LocateHandleBuffer (ByProtocol,
                  &gEfiI2cIoProtocolGuid,
                  NULL,
                  &HandleCount,
                  &HandleBuffer);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
    return Status;
  }
 
  /* Iterate over all protocol producers and pick one upon DeviceIndex match */
  for (Index = 0; Index < HandleCount; Index++) {
    Status = gBS->OpenProtocol (HandleBuffer[Index],
                    &gEfiI2cIoProtocolGuid,
                    (VOID **)I2cIo,
                    gImageHandle,
                    NULL,
                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    if (EFI_ERROR (Status)) {
      DEBUG ((DEBUG_ERROR, "%a: Unable to open protocol\n", __FUNCTION__));
      gBS->FreePool (HandleBuffer);
      return Status;
    }
    if ((*I2cIo)->DeviceIndex == I2C_DEVICE_INDEX (I2cBus, I2cAddress)) {
      gBS->FreePool (HandleBuffer);
      return EFI_SUCCESS;
    }
  }
 
  gBS->FreePool (HandleBuffer);
 
  return EFI_NOT_FOUND;
}
 
EFI_STATUS
EFIAPI
MvPca95xxI2cTransfer (
  IN EFI_I2C_IO_PROTOCOL *I2cIo,
  IN UINT8                Address,
  IN UINT8               *Buffer,
  IN UINT32               Flag
  )
{
  EFI_I2C_REQUEST_PACKET *RequestPacket;
  UINTN RequestPacketSize;
  UINT8 AddressBuffer;
  EFI_STATUS Status;
 
  RequestPacketSize = sizeof (UINTN) +
                      sizeof (EFI_I2C_OPERATION) * PCA95XX_OPERATION_COUNT;
  RequestPacket = AllocateZeroPool (RequestPacketSize);
  if (RequestPacket == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
 
  /* Operations contain address and payload, consecutively. */
  RequestPacket->OperationCount = PCA95XX_OPERATION_COUNT;
  RequestPacket->Operation[0].LengthInBytes = PCA95XX_OPERATION_LENGTH;
  RequestPacket->Operation[0].Buffer = &AddressBuffer;
  RequestPacket->Operation[0].Buffer[0] = Address & MAX_UINT8;
  RequestPacket->Operation[1].LengthInBytes = PCA95XX_OPERATION_LENGTH;
  RequestPacket->Operation[1].Buffer = Buffer;
  RequestPacket->Operation[1].Flags = Flag;
 
  Status = I2cIo->QueueRequest (I2cIo, 0, NULL, RequestPacket, NULL);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR,
      "%a: transmission error: 0x%d\n",
      __FUNCTION__,
      Status));
  }
 
  gBS->FreePool(RequestPacket);
 
  return Status;
}
 
STATIC
EFI_STATUS
MvPca95xxReadRegs (
  IN  EFI_I2C_IO_PROTOCOL *I2cIo,
  IN  UINT8                Reg,
  OUT UINT8               *RegVal
  )
{
  return MvPca95xxI2cTransfer (I2cIo, Reg, RegVal, I2C_FLAG_READ);
}
 
STATIC
EFI_STATUS
MvPca95xxWriteRegs (
  IN  EFI_I2C_IO_PROTOCOL *I2cIo,
  IN  UINTN                Reg,
  IN  UINT8                RegVal
  )
{
  return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, I2C_FLAG_NORESTART);
}
 
STATIC
EFI_STATUS
MvPca95xxSetOutputValue (
  IN UINTN               ControllerIndex,
  IN UINTN               GpioPin,
  IN EMBEDDED_GPIO_MODE  Mode
  )
{
  EFI_I2C_IO_PROTOCOL *I2cIo;
  EFI_STATUS Status;
  UINT8 RegVal;
  UINTN Bank;
 
  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
    return EFI_DEVICE_ERROR;
  }
 
  Bank = GpioPin / PCA95XX_BANK_SIZE;
 
  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, &RegVal);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
    return EFI_DEVICE_ERROR;
  }
 
  if (Mode == GPIO_MODE_OUTPUT_1) {
    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
  } else {
    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
  }
 
  Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, RegVal);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to write device register\n", __FUNCTION__));
    return EFI_DEVICE_ERROR;
  }
 
  return EFI_SUCCESS;
}
 
STATIC
EFI_STATUS
MvPca95xxSetDirection (
  IN UINTN              ControllerIndex,
  IN UINTN              GpioPin,
  IN EMBEDDED_GPIO_MODE Mode
  )
{
  EFI_I2C_IO_PROTOCOL *I2cIo;
  EFI_STATUS Status;
  UINT8 RegVal;
  UINTN Bank;
 
  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
    return Status;
  }
 
  Bank = GpioPin / PCA95XX_BANK_SIZE;
 
  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, &RegVal);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
    return Status;
  }
 
  if (Mode == GPIO_MODE_INPUT) {
    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
  } else {
    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
  }
 
  Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, RegVal);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to write device register\n", __FUNCTION__));
    return Status;
  }
 
  return EFI_SUCCESS;
}
 
STATIC
EFI_STATUS
MvPca95xxReadMode (
  IN  UINTN               ControllerIndex,
  IN  UINTN               GpioPin,
  OUT EMBEDDED_GPIO_MODE *Mode
  )
{
  EFI_I2C_IO_PROTOCOL *I2cIo;
  EFI_STATUS Status;
  UINT8 RegVal;
  UINTN Bank;
 
  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
 
  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
    return Status;
  }
 
  Bank = GpioPin / PCA95XX_BANK_SIZE;
 
  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, &RegVal);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
    return Status;
  }
 
  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
    *Mode = GPIO_MODE_INPUT;
  } else {
    Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
    if (EFI_ERROR (Status)) {
      DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
      return Status;
    }
 
    if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
      *Mode = GPIO_MODE_OUTPUT_1;
    } else {
      *Mode = GPIO_MODE_OUTPUT_0;
    }
  }
 
  return EFI_SUCCESS;
}
 
/**
 
Routine Description:
 
  Gets the mode (function) of a GPIO pin
 
Arguments:
 
  This  - pointer to protocol
  Gpio  - which pin
  Mode  - pointer to output mode value
 
Returns:
 
  EFI_SUCCESS           - mode value retrieved
  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
 
**/
STATIC
EFI_STATUS
MvPca95xxGetMode (
  IN  EMBEDDED_GPIO       *This,
  IN  EMBEDDED_GPIO_PIN    Gpio,
  OUT EMBEDDED_GPIO_MODE  *Mode
  )
{
  EFI_STATUS Status;
  UINTN ControllerIndex;
  UINTN GpioPin;
 
  GpioPin = GPIO_PIN (Gpio);
  ControllerIndex = GPIO_PORT (Gpio);
 
  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
 
  Status = MvPca95xxReadMode (ControllerIndex, GpioPin, Mode);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR,
      "%a: fail to get pin %d of controller#%d mode\n",
      __FUNCTION__,
      GpioPin,
      ControllerIndex));
  }
 
  return Status;
}
 
/**
 
Routine Description:
 
  Gets the state of a GPIO pin
 
Arguments:
 
  This  - pointer to protocol
  Gpio  - which pin to read
  Value - state of the pin
 
Returns:
 
  EFI_SUCCESS           - GPIO state returned in Value
  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
**/
STATIC
EFI_STATUS
MvPca95xxGet (
  IN  EMBEDDED_GPIO      *This,
  IN  EMBEDDED_GPIO_PIN   Gpio,
  OUT UINTN              *Value
  )
{
  EFI_I2C_IO_PROTOCOL *I2cIo;
  EFI_STATUS Status;
  UINTN ControllerIndex;
  UINTN GpioPin;
  UINT8 RegVal;
  UINTN Bank;
 
  GpioPin = GPIO_PIN (Gpio);
  ControllerIndex = GPIO_PORT (Gpio);
 
  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
 
  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
    return Status;
  }
 
  Bank = GpioPin / PCA95XX_BANK_SIZE;
 
  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
    return Status;
  }
 
  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
    *Value = 1;
  } else {
    *Value = 0;
  }
 
  return EFI_SUCCESS;
}
 
/**
 
Routine Description:
 
  Sets the state of a GPIO pin
 
Arguments:
 
  This  - pointer to protocol
  Gpio  - which pin to modify
  Mode  - mode to set
 
Returns:
 
  EFI_SUCCESS           - GPIO set as requested
  EFI_UNSUPPORTED       - Mode is not supported
  EFI_INVALID_PARAMETER - Gpio pin is out of range
**/
STATIC
EFI_STATUS
MvPca95xxSet (
  IN EMBEDDED_GPIO       *This,
  IN EMBEDDED_GPIO_PIN   Gpio,
  IN EMBEDDED_GPIO_MODE  Mode
  )
{
  EFI_STATUS Status;
  UINTN ControllerIndex;
  UINTN GpioPin;
 
  GpioPin = GPIO_PIN (Gpio);
  ControllerIndex = GPIO_PORT (Gpio);
 
  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
 
  switch (Mode) {
  case GPIO_MODE_OUTPUT_0:
  case GPIO_MODE_OUTPUT_1:
    Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Mode);
    if (EFI_ERROR (Status)) {
      DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
      return Status;
    }
 
  /* Fall-through */
  case GPIO_MODE_INPUT:
    Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, Mode);
    if (EFI_ERROR (Status)) {
      DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
      return Status;
    }
    break;
 
  default:
    return EFI_UNSUPPORTED;
  }
 
  return EFI_SUCCESS;
}
 
/**
 
Routine Description:
 
  Sets the pull-up / pull-down resistor of a GPIO pin
 
Arguments:
 
  This  - pointer to protocol
  Gpio  - which pin
  Direction - pull-up, pull-down, or none
 
Returns:
 
  EFI_UNSUPPORTED - Can not perform the requested operation
 
**/
EFI_STATUS
EFIAPI
MvPca95xxSetPull (
  IN EMBEDDED_GPIO       *This,
  IN EMBEDDED_GPIO_PIN   Gpio,
  IN EMBEDDED_GPIO_PULL  Direction
  )
{
  return EFI_UNSUPPORTED;
}
 
STATIC
VOID
MvPca95xxInitProtocol (
  IN EMBEDDED_GPIO *GpioProtocol
  )
{
  GpioProtocol->Get     = MvPca95xxGet;
  GpioProtocol->Set     = MvPca95xxSet;
  GpioProtocol->GetMode = MvPca95xxGetMode;
  GpioProtocol->SetPull = MvPca95xxSetPull;
}
 
EFI_STATUS
EFIAPI
MvPca95xxEntryPoint (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
{
  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
  MV_GPIO_DEVICE_PATH *Pca95xxDevicePath;
  EFI_STATUS Status;
 
  /* Obtain list of available controllers */
  Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
                  NULL,
                  (VOID **)&MvBoardProtocol);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR,
      "%a: Cannot locate BoardDesc protocol\n",
      __FUNCTION__));
    return Status;
  }
 
  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
             &GpioDescription);
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_ERROR,
      "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
      __FUNCTION__));
    return Status;
  } else if (GpioDescription->GpioExpanders == NULL) {
    /* Silently exit, if the board does not support the controllers */
    return EFI_SUCCESS;
  }
 
  Pca95xxDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
                        &mDevicePathTemplate);
  if (Pca95xxDevicePath == NULL) {
    DEBUG ((DEBUG_ERROR,
      "%a: Fail to allocate Pca95xxDevicePath\n",
      __FUNCTION__));
    return EFI_OUT_OF_RESOURCES;
  }
 
  mPca95xxInstance = AllocateZeroPool (sizeof (PCA95XX));
  if (mPca95xxInstance == NULL) {
    DEBUG ((DEBUG_ERROR,
      "%a: Fail to allocate mPca95xxInstance\n",
      __FUNCTION__));
    Status = EFI_OUT_OF_RESOURCES;
    goto ErrPca95xxInstanceAlloc;
  }
 
  MvPca95xxInitProtocol (&mPca95xxInstance->GpioProtocol);
 
  mPca95xxInstance->Signature = PCA95XX_GPIO_SIGNATURE;
  mPca95xxInstance->GpioExpanders = GpioDescription->GpioExpanders;
  mPca95xxInstance->GpioExpanderCount = GpioDescription->GpioExpanderCount;
 
  Status = gBS->InstallMultipleProtocolInterfaces (
                  &(mPca95xxInstance->ControllerHandle),
                  &gEmbeddedGpioProtocolGuid,
                  &(mPca95xxInstance->GpioProtocol),
                  &gEfiDevicePathProtocolGuid,
                  (EFI_DEVICE_PATH_PROTOCOL *)Pca95xxDevicePath,
                  NULL);
  if (EFI_ERROR (Status)) {
    goto ErrInstallProtocols;
  }
 
  return EFI_SUCCESS;
 
ErrInstallProtocols:
  gBS->FreePool (mPca95xxInstance);
 
ErrPca95xxInstanceAlloc:
  gBS->FreePool (Pca95xxDevicePath);
 
  return Status;
}