@@ -46,7 +46,7 @@ IRX_ID(MODNAME, 2, 7);
4646#define M_PRINTF (format , args ...) \
4747 printf(MODNAME ": " format, ##args)
4848
49- #define U64_2XU32 (val ) ((u32*)val)[1], ((u32*)val)[0]
49+ #define U64_2XU32 (val ) ((u32 *)val)[1], ((u32 *)val)[0]
5050
5151#define BANNER "ATA device driver %s - Copyright (c) 2003 Marcus R. Brown\n"
5252#define VERSION "v1.2"
@@ -182,7 +182,7 @@ typedef struct _ata_cmd_state
182182static ata_cmd_state_t atad_cmd_state ;
183183
184184#ifdef ATA_ENABLE_BDM
185- #define NUM_DEVICES 2
185+ #define NUM_DEVICES 2
186186#define ATA_BD_SECTOR_SIZE 512
187187static struct block_device g_ata_bd [NUM_DEVICES ];
188188#endif
@@ -307,14 +307,14 @@ int _start(int argc, char *argv[])
307307 int i ;
308308
309309 for (i = 0 ; i < NUM_DEVICES ; ++ i ) {
310- g_ata_bd [i ].priv = (void * )& atad_devinfo [i ];
311- g_ata_bd [i ].name = "ata" ;
312- g_ata_bd [i ].devNr = i ;
313- g_ata_bd [i ].parNr = 0 ;
314- g_ata_bd [i ].parId = 0x00 ;
315- g_ata_bd [i ].sectorSize = 512 ;
310+ g_ata_bd [i ].priv = (void * )& atad_devinfo [i ];
311+ g_ata_bd [i ].name = "ata" ;
312+ g_ata_bd [i ].devNr = i ;
313+ g_ata_bd [i ].parNr = 0 ;
314+ g_ata_bd [i ].parId = 0x00 ;
315+ g_ata_bd [i ].sectorSize = 512 ;
316316 g_ata_bd [i ].sectorOffset = 0 ;
317- g_ata_bd [i ].sectorCount = 0 ;
317+ g_ata_bd [i ].sectorCount = 0 ;
318318
319319 g_ata_bd [i ].read = ata_bd_read ;
320320 g_ata_bd [i ].write = ata_bd_write ;
@@ -912,19 +912,19 @@ int ata_device_sector_io64(int device, void *buf, u64 lba, u32 nsectors, int dir
912912 len = (nsectors > 65536 ) ? 65536 : nsectors ;
913913
914914 /* Combine bits 24-31 and bits 0-7 of lba into sector. */
915- sector = ((lba >> 16 ) & 0xff00 ) | (lba & 0xff );
916- lcyl = ((lba >> 24 ) & 0xff00 ) | ((lba >> 8 ) & 0xff );
917- hcyl = ((lba >> 32 ) & 0xff00 ) | ((lba >> 16 ) & 0xff );
915+ sector = ((lba >> 16 ) & 0xff00 ) | (lba & 0xff );
916+ lcyl = ((lba >> 24 ) & 0xff00 ) | ((lba >> 8 ) & 0xff );
917+ hcyl = ((lba >> 32 ) & 0xff00 ) | ((lba >> 16 ) & 0xff );
918918
919919 /* In v1.04, LBA was enabled here. */
920920 select = (device << 4 ) & 0xffff ;
921921 command = (dir == 1 ) ? ATA_C_WRITE_DMA_EXT : ATA_C_READ_DMA_EXT ;
922922 } else {
923923 /* Setup for 28-bit LBA. */
924924 len = (nsectors > 256 ) ? 256 : nsectors ;
925- sector = lba & 0xff ;
926- lcyl = (lba >> 8 ) & 0xff ;
927- hcyl = (lba >> 16 ) & 0xff ;
925+ sector = lba & 0xff ;
926+ lcyl = (lba >> 8 ) & 0xff ;
927+ hcyl = (lba >> 16 ) & 0xff ;
928928
929929 /* In v1.04, LBA was enabled here. */
930930 select = ((device << 4 ) | ((lba >> 24 ) & 0xf )) & 0xffff ;
@@ -1142,8 +1142,22 @@ static int ata_init_devices(ata_devinfo_t *devinfo)
11421142
11431143 devinfo [i ].security_status = ata_param [ATA_ID_SECURITY_STATUS ];
11441144
1145+ u8 maxUDMA = 4 ;
1146+ #ifdef ATA_ENABLE_MAXUDMA
1147+ maxUDMA = 6 ;
1148+ #endif
1149+
11451150 /* Ultra DMA mode 4. */
1146- ata_device_set_transfer_mode (i , ATA_XFER_MODE_UDMA , 4 );
1151+ u8 udmaMode = 4 ;
1152+ /* Check the highest UDMA mode supported */
1153+ for (int j = maxUDMA ; j >= 0 ; j -- ) {
1154+ /* Check if the current UDMA mode is supported, store it and exit from the loop. */
1155+ if (((ata_param [ATA_ID_UDMA_CONTROL ] & 0xFF ) & (1 << j )) != 0 ) {
1156+ udmaMode = j ;
1157+ break ;
1158+ }
1159+ }
1160+ ata_device_set_transfer_mode (i , ATA_XFER_MODE_UDMA , udmaMode );
11471161 ata_device_smart_enable (i );
11481162 /* Set standby timer to 21min 15s. */
11491163 ata_device_idle (i , 0xff );
@@ -1330,7 +1344,7 @@ static int ata_bd_read(struct block_device *bd, u64 sector, void *buffer, u16 co
13301344
13311345static int ata_bd_write (struct block_device * bd , u64 sector , const void * buffer , u16 count )
13321346{
1333- if (ata_device_sector_io64 (bd -> devNr , (void * )buffer , sector , count , ATA_DIR_WRITE ) != 0 ) {
1347+ if (ata_device_sector_io64 (bd -> devNr , (void * )buffer , sector , count , ATA_DIR_WRITE ) != 0 ) {
13341348 return - EIO ;
13351349 }
13361350
0 commit comments