]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppyCtrl.c
Isa Floppy driver code scrub.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / IsaFloppyCtrl.c
index fab96051fdeb7de1632786e6870bb1572e91e035..60df61f08197e5dd7c5947407cca190c51001d13 100644 (file)
@@ -1,15 +1,7 @@
-/**@file\r
-  ISA Floppy Driver\r
-  1. Support two types diskette drive\r
-     1.44M drive and 2.88M drive (and now only support 1.44M)\r
-  2. Support two diskette drives\r
-  3. Use DMA channel 2 to transfer data\r
-  4. Do not use interrupt\r
-  5. Support diskette change line signal and write protect\r
-\r
-  The internal function for the floppy driver\r
+/** @file\r
+  Internal floppy disk controller programming functions for the floppy driver.\r
   \r
-Copyright (c) 2006 - 2007, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -23,13 +15,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "IsaFloppy.h"\r
 \r
 /**\r
-\r
-  Detect the floppy drive is presented or not\r
+  Detect whether a floppy drive is present or not.\r
  \r
-  @param  FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV\r
-  @retval EFI_SUCCESS    Drive is presented\r
-  @retval EFI_NOT_FOUND  Drive is not presented\r
+  @param[in] FdcDev  A pointer to the FDC_BLK_IO_DEV\r
 \r
+  @retval EFI_SUCCESS    The floppy disk drive is present\r
+  @retval EFI_NOT_FOUND  The floppy disk drive is not present\r
 **/\r
 EFI_STATUS\r
 DiscoverFddDevice (\r
@@ -40,9 +31,6 @@ DiscoverFddDevice (
 \r
   FdcDev->BlkIo.Media = &FdcDev->BlkMedia;\r
 \r
-  //\r
-  // Call FddIndentify subroutine\r
-  //\r
   Status = FddIdentify (FdcDev);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_NOT_FOUND;\r
@@ -59,13 +47,13 @@ DiscoverFddDevice (
 }\r
 \r
 /**\r
-\r
-  Do recalibrate  and see the drive is presented or not\r
-  Set the media parameters\r
+  Do recalibrate and check if the drive is present or not\r
+  and set the media parameters if the driver is present.\r
   \r
-  @param FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV\r
-  @return the drive is presented or not\r
+  @param[in] FdcDev  A pointer to the FDC_BLK_IO_DEV\r
 \r
+  @retval EFI_SUCCESS       The floppy disk drive is present\r
+  @retval EFI_DEVICE_ERROR  The floppy disk drive is not present\r
 **/\r
 EFI_STATUS\r
 FddIdentify (\r
@@ -94,9 +82,6 @@ FddIdentify (
   //\r
   FdcDev->BlkIo.Media->RemovableMedia = TRUE;\r
   FdcDev->BlkIo.Media->MediaPresent   = TRUE;\r
-  //\r
-  // investigate\r
-  //\r
   FdcDev->BlkIo.Media->MediaId = 0;\r
 \r
   //\r
@@ -137,10 +122,9 @@ FddIdentify (
 }\r
 \r
 /**\r
-\r
-  Reset the Floppy Logic Drive\r
+  Reset the Floppy Logic Drive.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev FDC_BLK_IO_DEV * : A pointer to the FDC_BLK_IO_DEV\r
   \r
   @retval EFI_SUCCESS:    The Floppy Logic Drive is reset\r
   @retval EFI_DEVICE_ERROR: The Floppy Logic Drive is not functioning correctly and\r
@@ -152,7 +136,7 @@ FddReset (
   IN FDC_BLK_IO_DEV  *FdcDev\r
   )\r
 {\r
-  UINT8 data;\r
+  UINT8 Data;\r
   UINT8 StatusRegister0;\r
   UINT8 PresentCylinderNumber;\r
   UINTN Index;\r
@@ -179,9 +163,9 @@ FddReset (
   //         use bit0 & bit1 to  select the logic drive\r
   //         write "0" to bit2\r
   //\r
-  data = 0x0;\r
-  data = (UINT8) (data | (SELECT_DRV & FdcDev->Disk));\r
-  FdcWritePort (FdcDev, FDC_REGISTER_DOR, data);\r
+  Data = 0x0;\r
+  Data = (UINT8) (Data | (SELECT_DRV & FdcDev->Disk));\r
+  FdcWritePort (FdcDev, FDC_REGISTER_DOR, Data);\r
 \r
   //\r
   // wait some time,at least 120us\r
@@ -193,8 +177,8 @@ FddReset (
   //   write "1" to bit2\r
   //   write "1" to bit3 : enable DMA\r
   //\r
-  data |= 0x0C;\r
-  FdcWritePort (FdcDev, FDC_REGISTER_DOR, data);\r
+  Data |= 0x0C;\r
+  FdcWritePort (FdcDev, FDC_REGISTER_DOR, Data);\r
 \r
   //\r
   // Experience value\r
@@ -236,16 +220,13 @@ FddReset (
 }\r
 \r
 /**\r
-\r
-  Turn the drive's motor on\r
-  The drive's motor must be on before any command can be executed\r
+  Turn the floppy disk drive's motor on.\r
+  The drive's motor must be on before any command can be executed.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV\r
+  @param[in] FdcDev  A pointer to the FDC_BLK_IO_DEV\r
   \r
-  @retval  EFI_SUCCESS:       Turn the drive's motor on successfully\r
-  @retval  EFI_DEVICE_ERROR:    The drive is busy, so can not turn motor on\r
-  @retval  EFI_INVALID_PARAMETER: Fail to Set timer(Cancel timer)\r
-\r
+  @retval  EFI_SUCCESS            The drive's motor was turned on successfully\r
+  @retval  EFI_DEVICE_ERROR       The drive is busy, so can not turn motor on\r
 **/\r
 EFI_STATUS\r
 MotorOn (\r
@@ -253,7 +234,7 @@ MotorOn (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINT8       data;\r
+  UINT8       DorData;\r
 \r
   //\r
   // Control of the floppy drive motors is a big pain. If motor is off, you have\r
@@ -269,17 +250,15 @@ MotorOn (
   // Cancel the timer\r
   //\r
   Status = gBS->SetTimer (FdcDev->Event, TimerCancel, 0);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
   //\r
   // Get the motor status\r
   //\r
-  data = FdcReadPort (FdcDev, FDC_REGISTER_DOR);\r
+  DorData = FdcReadPort (FdcDev, FDC_REGISTER_DOR);\r
 \r
-  if (((FdcDev->Disk == FDC_DISK0) && ((data & 0x10) == 0x10)) ||\r
-      ((FdcDev->Disk == FDC_DISK1) && ((data & 0x21) == 0x21))\r
+  if (((FdcDev->Disk == FdcDisk0) && ((DorData & 0x10) == 0x10)) ||\r
+      ((FdcDev->Disk == FdcDisk1) && ((DorData & 0x21) == 0x21))\r
       ) {\r
     return EFI_SUCCESS;\r
   }\r
@@ -293,21 +272,21 @@ MotorOn (
   //\r
   // for drive A: 1CH, drive B: 2DH\r
   //\r
-  data = 0x0C;\r
-  data = (UINT8) (data | (SELECT_DRV & FdcDev->Disk));\r
-  if (FdcDev->Disk == FDC_DISK0) {\r
+  DorData = 0x0C;\r
+  DorData = (UINT8) (DorData | (SELECT_DRV & FdcDev->Disk));\r
+  if (FdcDev->Disk == FdcDisk0) {\r
     //\r
     // drive A\r
     //\r
-    data |= DRVA_MOTOR_ON;\r
+    DorData |= DRVA_MOTOR_ON;\r
   } else {\r
     //\r
     // drive B\r
     //\r
-    data |= DRVB_MOTOR_ON;\r
+    DorData |= DRVB_MOTOR_ON;\r
   }\r
 \r
-  FdcWritePort (FdcDev, FDC_REGISTER_DOR, data);\r
+  FdcWritePort (FdcDev, FDC_REGISTER_DOR, DorData);\r
 \r
   //\r
   // Experience value\r
@@ -318,15 +297,12 @@ MotorOn (
 }\r
 \r
 /**\r
-\r
-  Set a Timer and when Timer goes off, turn the motor off\r
-  \r
+  Set a Timer and when Timer goes off, turn the motor off.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV * : A pointer to the Data Structure FDC_BLK_IO_DEV\r
+  @param[in] FdcDev  A pointer to the FDC_BLK_IO_DEV\r
   \r
-  @retval  EFI_SUCCESS:       Set the Timer successfully\r
-  @retval  EFI_INVALID_PARAMETER: Fail to Set the timer\r
-\r
+  @retval  EFI_SUCCESS            Set the Timer successfully\r
+  @retval  EFI_INVALID_PARAMETER  Fail to Set the timer\r
 **/\r
 EFI_STATUS\r
 MotorOff (\r
@@ -340,15 +316,14 @@ MotorOff (
 }\r
 \r
 /**\r
-  Detect the disk in the drive is changed or not\r
-  \r
+  Detect whether the disk in the drive is changed or not.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param[in] FdcDev  A pointer to FDC_BLK_IO_DEV\r
   \r
-  @retval  EFI_SUCCESS:    No disk media change\r
-  @retval  EFI_DEVICE_ERROR: Fail to do the recalibrate or seek operation\r
-  @retval  EFI_NO_MEDIA:   No disk in the drive\r
-  @retval  EFI_MEDIA_CHANGED:  There is a new disk in the drive\r
+  @retval  EFI_SUCCESS        No disk media change\r
+  @retval  EFI_DEVICE_ERROR   Fail to do the recalibrate or seek operation\r
+  @retval  EFI_NO_MEDIA       No disk in the drive\r
+  @retval  EFI_MEDIA_CHANGED  There is a new disk in the drive\r
 **/\r
 EFI_STATUS\r
 DisketChanged (\r
@@ -356,19 +331,19 @@ DisketChanged (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINT8       data;\r
+  UINT8       Data;\r
 \r
   //\r
   // Check change line\r
   //\r
-  data = FdcReadPort (FdcDev, FDC_REGISTER_DIR);\r
+  Data = FdcReadPort (FdcDev, FDC_REGISTER_DIR);\r
 \r
   //\r
   // Io delay\r
   //\r
   MicroSecondDelay (50);\r
 \r
-  if ((data & DIR_DCL) == 0x80) {\r
+  if ((Data & DIR_DCL) == 0x80) {\r
     //\r
     // disk change line is active\r
     //\r
@@ -386,14 +361,14 @@ DisketChanged (
       //\r
     }\r
 \r
-    data = FdcReadPort (FdcDev, FDC_REGISTER_DIR);\r
+    Data = FdcReadPort (FdcDev, FDC_REGISTER_DIR);\r
 \r
     //\r
     // Io delay\r
     //\r
     MicroSecondDelay (50);\r
 \r
-    if ((data & DIR_DCL) == 0x80) {\r
+    if ((Data & DIR_DCL) == 0x80) {\r
       return EFI_NO_MEDIA;\r
     }\r
 \r
@@ -406,13 +381,12 @@ DisketChanged (
 /**\r
   Do the Specify command, this command sets DMA operation\r
   and the initial values for each of the three internal\r
-  times: HUT, SRT and HLT\r
+  times: HUT, SRT and HLT.\r
   \r
-  @param FdcDev    Pointer to instance of FDC_BLK_IO_DEV\r
+  @param[in] FdcDev  Pointer to instance of FDC_BLK_IO_DEV\r
   \r
-  @retval  EFI_SUCCESS:    Execute the Specify command successfully\r
-  @retval  EFI_DEVICE_ERROR: Fail to execute the command\r
-\r
+  @retval EFI_SUCCESS       Execute the Specify command successfully\r
+  @retval EFI_DEVICE_ERROR  Fail to execute the command\r
 **/\r
 EFI_STATUS\r
 Specify (\r
@@ -447,9 +421,9 @@ Specify (
 }\r
 \r
 /**\r
-  Set the head of floppy drive to track 0\r
+  Set the head of floppy drive to track 0.\r
  \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV\r
   @retval EFI_SUCCESS:    Execute the Recalibrate operation successfully\r
   @retval EFI_DEVICE_ERROR: Fail to execute the Recalibrate operation\r
 \r
@@ -474,7 +448,7 @@ Recalibrate (
     //\r
     // drive select\r
     //\r
-    if (FdcDev->Disk == FDC_DISK0) {\r
+    if (FdcDev->Disk == FdcDisk0) {\r
       Command.DiskHeadSel = 0;\r
       //\r
       // 0\r
@@ -521,9 +495,9 @@ Recalibrate (
 }\r
 \r
 /**\r
-  Set the head of floppy drive to the new cylinder\r
+  Set the head of floppy drive to the new cylinder.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV\r
   @param  Lba EFI_LBA     : The logic block address want to seek\r
   \r
   @retval  EFI_SUCCESS:    Execute the Seek operation successfully\r
@@ -573,7 +547,7 @@ Seek (
 \r
   ZeroMem (&Command, sizeof (FDD_SEEK_CMD));\r
   Command.CommandCode = SEEK_CMD;\r
-  if (FdcDev->Disk == FDC_DISK0) {\r
+  if (FdcDev->Disk == FdcDisk0) {\r
     Command.DiskHeadSel = 0;\r
     //\r
     // 0\r
@@ -625,9 +599,9 @@ Seek (
 \r
 /**\r
   Do the Sense Interrupt Status command, this command\r
-  resets the interrupt signal\r
+  resets the interrupt signal.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV\r
   @param  StatusRegister0 UINT8 *: Be used to save Status Register 0 read from FDC\r
   @param  PresentCylinderNumber  UINT8 *: Be used to save present cylinder number\r
                                     read from FDC\r
@@ -643,10 +617,10 @@ SenseIntStatus (
   IN OUT UINT8           *PresentCylinderNumber\r
   )\r
 {\r
-  UINT8 command;\r
+  UINT8 Command;\r
 \r
-  command = SENSE_INT_STATUS_CMD;\r
-  if (EFI_ERROR (DataOutByte (FdcDev, &command))) {\r
+  Command = SENSE_INT_STATUS_CMD;\r
+  if (EFI_ERROR (DataOutByte (FdcDev, &Command))) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
@@ -662,9 +636,9 @@ SenseIntStatus (
 }\r
 \r
 /**\r
-  Do the Sense Drive Status command\r
+  Do the Sense Drive Status command.\r
   \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV\r
   @param  Lba EFI_LBA     : Logic block address\r
   \r
   @retval  EFI_SUCCESS:    Execute the Sense Drive Status command successfully\r
@@ -693,7 +667,7 @@ SenseDrvStatus (
   ZeroMem (&Command, sizeof (FDD_COMMAND_PACKET2));\r
   Command.CommandCode = SENSE_DRV_STATUS_CMD;\r
 \r
-  if (FdcDev->Disk == FDC_DISK0) {\r
+  if (FdcDev->Disk == FdcDisk0) {\r
     Command.DiskHeadSel = 0;\r
   } else {\r
     Command.DiskHeadSel = 1;\r
@@ -725,10 +699,9 @@ SenseDrvStatus (
 }\r
 \r
 /**\r
-  Update the disk media properties and if necessary\r
-                        reinstall Block I/O interface\r
+  Update the disk media properties and if necessary reinstall Block I/O interface.\r
  \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV\r
   \r
   @retval  EFI_SUCCESS:    Do the operation successfully\r
   @retval  EFI_DEVICE_ERROR: Fail to the operation\r
@@ -740,13 +713,13 @@ DetectMedia (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  BOOLEAN     bReset;\r
-  BOOLEAN     bReadOnlyLastTime;\r
-  BOOLEAN     bMediaPresentLastTime;\r
+  BOOLEAN     Reset;\r
+  BOOLEAN     ReadOnlyLastTime;\r
+  BOOLEAN     MediaPresentLastTime;\r
 \r
-  bReset                = FALSE;\r
-  bReadOnlyLastTime     = FdcDev->BlkIo.Media->ReadOnly;\r
-  bMediaPresentLastTime = FdcDev->BlkIo.Media->MediaPresent;\r
+  Reset                = FALSE;\r
+  ReadOnlyLastTime     = FdcDev->BlkIo.Media->ReadOnly;\r
+  MediaPresentLastTime = FdcDev->BlkIo.Media->MediaPresent;\r
 \r
   //\r
   // Check disk change\r
@@ -756,7 +729,7 @@ DetectMedia (
   if (Status == EFI_MEDIA_CHANGED) {\r
     FdcDev->BlkIo.Media->MediaId++;\r
     FdcDev->BlkIo.Media->MediaPresent = TRUE;\r
-    bReset = TRUE;\r
+    Reset = TRUE;\r
   } else if (Status == EFI_NO_MEDIA) {\r
     FdcDev->BlkIo.Media->MediaPresent = FALSE;\r
   } else if (Status != EFI_SUCCESS) {\r
@@ -779,15 +752,15 @@ DetectMedia (
     }\r
   }\r
 \r
-  if (FdcDev->BlkIo.Media->MediaPresent && (bReadOnlyLastTime != FdcDev->BlkIo.Media->ReadOnly)) {\r
-    bReset = TRUE;\r
+  if (FdcDev->BlkIo.Media->MediaPresent && (ReadOnlyLastTime != FdcDev->BlkIo.Media->ReadOnly)) {\r
+    Reset = TRUE;\r
   }\r
 \r
-  if (bMediaPresentLastTime != FdcDev->BlkIo.Media->MediaPresent) {\r
-    bReset = TRUE;\r
+  if (MediaPresentLastTime != FdcDev->BlkIo.Media->MediaPresent) {\r
+    Reset = TRUE;\r
   }\r
 \r
-  if (bReset) {\r
+  if (Reset) {\r
     Status = gBS->ReinstallProtocolInterface (\r
                     FdcDev->Handle,\r
                     &gEfiBlockIoProtocolGuid,\r
@@ -804,9 +777,9 @@ DetectMedia (
 }\r
 \r
 /**\r
-  Set the data rate and so on\r
+  Set the data rate and so on.\r
  \r
-  @param  FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev  A pointer to FDC_BLK_IO_DEV\r
 \r
   @retval EFI_SUCCESS success to set the data rate\r
 **/\r
@@ -837,9 +810,9 @@ Setup (
 }\r
 \r
 /**\r
-  Read or Write a number of blocks in the same cylinder\r
+  Read or Write a number of blocks in the same cylinder.\r
  \r
-  @param  FdcDev      A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param  FdcDev      A pointer to FDC_BLK_IO_DEV\r
   @param  HostAddress device address \r
   @param  Lba         The starting logic block address to read from on the device\r
   @param  NumberOfBlocks The number of block wanted to be read or write\r
@@ -952,7 +925,7 @@ ReadWriteDataSector (
 \r
     MicroSecondDelay (50);\r
     Times = Times - 1;\r
-  } while (Times);\r
+  } while (Times >= 0);\r
 \r
   if (Times == 0) {\r
     return EFI_TIMEOUT;\r
@@ -987,7 +960,7 @@ ReadWriteDataSector (
 }\r
 \r
 /**\r
-  Fill in FDD command's parameter\r
+  Fill in FDD command's parameter.\r
   \r
   @param FdcDev   Pointer to instance of FDC_BLK_IO_DEV\r
   @param Lba      The starting logic block address to read from on the device\r
@@ -1011,7 +984,7 @@ FillPara (
   //\r
   // Fill the command parameter\r
   //\r
-  if (FdcDev->Disk == FDC_DISK0) {\r
+  if (FdcDev->Disk == FdcDisk0) {\r
     Command->DiskHeadSel = 0;\r
   } else {\r
     Command->DiskHeadSel = 1;\r
@@ -1028,23 +1001,22 @@ FillPara (
 }\r
 \r
 /**\r
-  Read result byte from Data Register of FDC\r
-  \r
-  @param FdcDev  Pointer to instance of FDC_BLK_IO_DEV\r
-  @param Pointer UINT8 *: Be used to save result byte read from FDC\r
+  Read result byte from Data Register of FDC.\r
   \r
+  @param FdcDev   Pointer to instance of FDC_BLK_IO_DEV\r
+  @param Pointer  Buffer to store the byte read from FDC\r
   \r
-  @retval  EFI_SUCCESS:    Read result byte from FDC successfully\r
-  @retval  EFI_DEVICE_ERROR: The FDC is not ready to be read\r
+  @retval EFI_SUCCESS       Read result byte from FDC successfully\r
+  @retval EFI_DEVICE_ERROR  The FDC is not ready to be read\r
 \r
 **/\r
 EFI_STATUS\r
 DataInByte (\r
-  IN     FDC_BLK_IO_DEV  *FdcDev,\r
-  IN OUT UINT8           *Pointer\r
+  IN  FDC_BLK_IO_DEV  *FdcDev,\r
+  OUT UINT8           *Pointer\r
   )\r
 {\r
-  UINT8 data;\r
+  UINT8 Data;\r
 \r
   //\r
   // wait for 1ms and detect the FDC is ready to be read\r
@@ -1056,19 +1028,19 @@ DataInByte (
     //\r
   }\r
 \r
-  data = FdcReadPort (FdcDev, FDC_REGISTER_DTR);\r
+  Data = FdcReadPort (FdcDev, FDC_REGISTER_DTR);\r
 \r
   //\r
   // Io delay\r
   //\r
   MicroSecondDelay (50);\r
 \r
-  *Pointer = data;\r
+  *Pointer = Data;\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Write command byte to Data Register of FDC\r
+  Write command byte to Data Register of FDC.\r
   \r
   @param FdcDev  Pointer to instance of FDC_BLK_IO_DEV\r
   @param Pointer Be used to save command byte written to FDC\r
@@ -1083,21 +1055,21 @@ DataOutByte (
   IN UINT8           *Pointer\r
   )\r
 {\r
-  UINT8 data;\r
+  UINT8 Data;\r
 \r
   //\r
   // wait for 1ms and detect the FDC is ready to be written\r
   //\r
   if (EFI_ERROR (FddDRQReady (FdcDev, DATA_OUT, 1))) {\r
-    return EFI_DEVICE_ERROR;\r
     //\r
-    // is not ready\r
+    // Not ready\r
     //\r
+    return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  data = *Pointer;\r
+  Data = *Pointer;\r
 \r
-  FdcWritePort (FdcDev, FDC_REGISTER_DTR, data);\r
+  FdcWritePort (FdcDev, FDC_REGISTER_DTR, Data);\r
 \r
   //\r
   // Io delay\r
@@ -1108,8 +1080,7 @@ DataOutByte (
 }\r
 \r
 /**\r
-  Detect the specified floppy logic drive is busy or\r
-  not within a period of time\r
+  Detect the specified floppy logic drive is busy or not within a period of time.\r
   \r
   @param FdcDev           Indicate it is drive A or drive B\r
   @param TimeoutInSeconds the time period for waiting\r
@@ -1139,7 +1110,7 @@ FddWaitForBSYClear (
   //\r
   // set mask: for drive A set bit0 & bit4; for drive B set bit1 & bit4\r
   //\r
-  Mask  = (UINT8) ((FdcDev->Disk == FDC_DISK0 ? MSR_DAB : MSR_DBB) | MSR_CB);\r
+  Mask  = (UINT8) ((FdcDev->Disk == FdcDisk0 ? MSR_DAB : MSR_DBB) | MSR_CB);\r
 \r
   Delay = ((TimeoutInSeconds * STALL_1_MSECOND) / 50) + 1;\r
   do {\r
@@ -1153,7 +1124,7 @@ FddWaitForBSYClear (
 \r
     MicroSecondDelay (50);\r
     Delay = Delay - 1;\r
-  } while (Delay);\r
+  } while (Delay >= 0);\r
 \r
   if (Delay == 0) {\r
     return EFI_TIMEOUT;\r
@@ -1164,7 +1135,7 @@ FddWaitForBSYClear (
 \r
 /**\r
 \r
-  Routine Description:  Determine whether FDC is ready to write or read\r
+  Routine Description:  Determine whether FDC is ready to write or read.\r
   \r
   @param  FdcDev Pointer to instance of FDC_BLK_IO_DEV\r
   @param  Dio BOOLEAN:      Indicate the FDC is waiting to write or read\r
@@ -1213,7 +1184,7 @@ FddDRQReady (
     // Stall for 50 us\r
     //\r
     Delay = Delay - 1;\r
-  } while (Delay);\r
+  } while (Delay >= 0);\r
 \r
   if (Delay == 0) {\r
     return EFI_NOT_READY;\r
@@ -1226,8 +1197,7 @@ FddDRQReady (
 }\r
 \r
 /**\r
-  Set FDC control structure's attribute according to\r
-  result \r
+  Set FDC control structure's attribute according to result. \r
 \r
   @param Result  Point to result structure\r
   @param FdcDev  FDC control structure\r
@@ -1261,14 +1231,14 @@ CheckResult (
   //\r
   // Check Status Register1\r
   //\r
-  if (Result->Status1 & (STS1_EN | STS1_DE | STS1_OR | STS1_ND | STS1_NW | STS1_MA)) {\r
+  if ((Result->Status1 & (STS1_EN | STS1_DE | STS1_OR | STS1_ND | STS1_NW | STS1_MA)) != 0) {\r
     FdcDev->ControllerState->NeedRecalibrate = TRUE;\r
     return EFI_DEVICE_ERROR;\r
   }\r
   //\r
   // Check Status Register2\r
   //\r
-  if (Result->Status2 & (STS2_CM | STS2_DD | STS2_WC | STS2_BC | STS2_MD)) {\r
+  if ((Result->Status2 & (STS2_CM | STS2_DD | STS2_WC | STS2_BC | STS2_MD)) != 0) {\r
     FdcDev->ControllerState->NeedRecalibrate = TRUE;\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -1277,7 +1247,7 @@ CheckResult (
 }\r
 \r
 /**\r
-  Check the drive status information\r
+  Check the drive status information.\r
   \r
   @param StatusRegister3  the value of Status Register 3\r
   \r
@@ -1290,7 +1260,7 @@ CheckStatus3 (
   IN UINT8 StatusRegister3\r
   )\r
 {\r
-  if (StatusRegister3 & STS3_WP) {\r
+  if ((StatusRegister3 & STS3_WP) != 0) {\r
     return EFI_WRITE_PROTECTED;\r
   }\r
 \r
@@ -1298,10 +1268,9 @@ CheckStatus3 (
 }\r
 \r
 /**\r
-  Calculate the number of block in the same cylinder\r
-  according to LBA\r
+  Calculate the number of block in the same cylinder according to LBA.\r
   \r
-  @param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
+  @param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV\r
   @param LBA EFI_LBA:      The starting logic block address\r
   @param NumberOfBlocks UINTN: The number of blocks\r
   \r
@@ -1335,7 +1304,7 @@ GetTransferBlockCount (
 }\r
 \r
 /**\r
-  When the Timer(2s) off, turn the drive's motor off\r
+  When the Timer(2s) off, turn the drive's motor off.\r
   \r
   @param Event EFI_EVENT: Event(the timer) whose notification function is being\r
                      invoked\r
@@ -1350,35 +1319,36 @@ FddTimerProc (
   )\r
 {\r
   FDC_BLK_IO_DEV  *FdcDev;\r
-  UINT8           data;\r
+  UINT8           Data;\r
 \r
   FdcDev = (FDC_BLK_IO_DEV *) Context;\r
 \r
   //\r
   // Get the motor status\r
   //\r
-  data = FdcReadPort (FdcDev, FDC_REGISTER_DOR);\r
+  Data = FdcReadPort (FdcDev, FDC_REGISTER_DOR);\r
 \r
-  if (((FdcDev->Disk == FDC_DISK0) && ((data & 0x10) != 0x10)) ||\r
-      ((FdcDev->Disk == FDC_DISK1) && ((data & 0x21) != 0x21))\r
+  if (((FdcDev->Disk == FdcDisk0) && ((Data & 0x10) != 0x10)) ||\r
+      ((FdcDev->Disk == FdcDisk1) && ((Data & 0x21) != 0x21))\r
       ) {\r
     return ;\r
   }\r
   //\r
   // the motor is on, so need motor off\r
   //\r
-  data = 0x0C;\r
-  data = (UINT8) (data | (SELECT_DRV & FdcDev->Disk));\r
-  FdcWritePort (FdcDev, FDC_REGISTER_DOR, data);\r
+  Data = 0x0C;\r
+  Data = (UINT8) (Data | (SELECT_DRV & FdcDev->Disk));\r
+  FdcWritePort (FdcDev, FDC_REGISTER_DOR, Data);\r
   MicroSecondDelay (500);\r
 }\r
 \r
 /**\r
-  Read I/O port for FDC\r
+  Read an I/O port of FDC.\r
  \r
-  @param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
-  @param Offset The offset address of port\r
+  @param[in] FdcDev  A pointer to FDC_BLK_IO_DEV.\r
+  @param[in] Offset  The address offset of the I/O port.\r
 \r
+  @retval  8-bit data read from the I/O port.\r
 **/\r
 UINT8\r
 FdcReadPort (\r
@@ -1386,29 +1356,27 @@ FdcReadPort (
   IN UINT32          Offset\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
   UINT8       Data;\r
 \r
-  //\r
-  // Call IsaIo\r
-  //\r
-  FdcDev->IsaIo->Io.Read (\r
-                      FdcDev->IsaIo,\r
-                      EfiIsaIoWidthUint8,\r
-                      FdcDev->BaseAddress + Offset,\r
-                      1,\r
-                      &Data\r
-                      );\r
+  Status = FdcDev->IsaIo->Io.Read (\r
+                            FdcDev->IsaIo,\r
+                            EfiIsaIoWidthUint8,\r
+                            FdcDev->BaseAddress + Offset,\r
+                            1,\r
+                            &Data\r
+                            );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   return Data;\r
 }\r
 \r
 /**\r
-  Write I/O port for FDC\r
+  Write an I/O port of FDC.\r
  \r
-  @param FdcDev FDC_BLK_IO_DEV *: A pointer to Data Structure FDC_BLK_IO_DEV\r
-  @param Offset The offset address of port\r
-  @param Data   Value written to port\r
-  \r
+  @param[in] FdcDev  A pointer to FDC_BLK_IO_DEV\r
+  @param[in] Offset  The address offset of the I/O port\r
+  @param[in] Data    8-bit Value written to the I/O port\r
 **/\r
 VOID\r
 FdcWritePort (\r
@@ -1417,16 +1385,15 @@ FdcWritePort (
   IN UINT8           Data\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
 \r
-  //\r
-  // Call IsaIo\r
-  //\r
-  FdcDev->IsaIo->Io.Write (\r
-                      FdcDev->IsaIo,\r
-                      EfiIsaIoWidthUint8,\r
-                      FdcDev->BaseAddress + Offset,\r
-                      1,\r
-                      &Data\r
-                      );\r
+  Status = FdcDev->IsaIo->Io.Write (\r
+                            FdcDev->IsaIo,\r
+                            EfiIsaIoWidthUint8,\r
+                            FdcDev->BaseAddress + Offset,\r
+                            1,\r
+                            &Data\r
+                            );\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r