A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

ata: Unify more of the ATA drivers into the common code

The goal of this was to have the ipod6g's ata driver report
proper vendor/model information from storage_info()

Change-Id: I64c1aee87c817cac23c90e062333a4ba3545dfaf

+66 -83
+56
firmware/drivers/ata-common.c
··· 20 20 21 21 /* This is intended to be #included into the ATA driver */ 22 22 23 + static sector_t total_sectors; 24 + static uint32_t log_sector_size; 25 + static uint16_t identify_info[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR; 26 + #ifdef HAVE_LBA48 27 + static bool ata_lba48 = false; /* set for 48 bit addressing */ 28 + #endif 29 + static bool canflush = true; 30 + static int spinup_time = 0; 31 + static struct mutex ata_mutex SHAREDBSS_ATTR; 32 + 33 + int ata_spinup_time(void) 34 + { 35 + return spinup_time; 36 + } 37 + 38 + #ifdef STORAGE_GET_INFO 39 + void ata_get_info(IF_MD(int drive,)struct storage_info *info) 40 + { 41 + unsigned short *src,*dest; 42 + static char vendor[8]; 43 + static char product[16]; 44 + static char revision[4]; 45 + #ifdef HAVE_MULTIDRIVE 46 + (void)drive; /* unused for now */ 47 + #endif 48 + int i; 49 + 50 + info->sector_size = log_sector_size; 51 + info->num_sectors = total_sectors; 52 + 53 + src = (unsigned short*)&identify_info[27]; 54 + dest = (unsigned short*)vendor; 55 + for (i=0;i<4;i++) 56 + dest[i] = htobe16(src[i]); 57 + info->vendor=vendor; 58 + 59 + src = (unsigned short*)&identify_info[31]; 60 + dest = (unsigned short*)product; 61 + for (i=0;i<8;i++) 62 + dest[i] = htobe16(src[i]); 63 + info->product=product; 64 + 65 + src = (unsigned short*)&identify_info[23]; 66 + dest = (unsigned short*)revision; 67 + for (i=0;i<2;i++) 68 + dest[i] = htobe16(src[i]); 69 + info->revision=revision; 70 + } 71 + #endif 72 + 73 + 23 74 #ifdef MAX_PHYS_SECTOR_SIZE 24 75 25 76 #ifdef MAX_VARIABLE_LOG_SECTOR ··· 40 91 /* buffer for reading and writing large physical sectors */ 41 92 static struct sector_cache_entry sector_cache STORAGE_ALIGN_ATTR; 42 93 static uint16_t phys_sector_mult = 1; 94 + 95 + static int ata_transfer_sectors(uint64_t start, 96 + int incount, 97 + void* inbuf, 98 + int write); 43 99 44 100 static int cache_sector(sector_t sector) 45 101 {
+2 -52
firmware/drivers/ata.c
··· 90 90 91 91 static int ata_state = ATA_BOOT; 92 92 93 - static struct mutex ata_mutex SHAREDBSS_ATTR; 94 93 static int ata_device; /* device 0 (master) or 1 (slave) */ 95 94 96 - static int spinup_time = 0; 97 95 #if (CONFIG_LED == LED_REAL) 98 96 static bool ata_led_enabled = true; 99 97 static bool ata_led_on = false; 100 98 #endif 101 99 102 100 static long sleep_timeout = 5*HZ; 103 - #ifdef HAVE_LBA48 104 - static bool ata_lba48 = false; /* set for 48 bit addressing */ 105 - #endif 106 - static bool canflush = true; 107 101 108 102 static long last_disk_activity = -1; 109 103 #ifdef HAVE_ATA_POWER_OFF 110 104 static long power_off_tick = 0; 111 105 #endif 112 106 113 - static sector_t total_sectors; 114 - static uint32_t log_sector_size; 115 107 static uint8_t multisectors; /* number of supported multisectors */ 116 - 117 - static unsigned short identify_info[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR; 118 108 119 109 #ifdef HAVE_ATA_DMA 120 110 static int dma_mode = 0; ··· 146 136 return false; 147 137 #endif 148 138 } 139 + 140 + #include "ata-common.c" 149 141 150 142 #ifndef ATA_TARGET_POLLING 151 143 static ICODE_ATTR int wait_for_bsy(void) ··· 593 585 594 586 return ret; 595 587 } 596 - 597 - #include "ata-common.c" 598 588 599 589 #ifndef MAX_PHYS_SECTOR_SIZE 600 590 int ata_read_sectors(IF_MD(int drive,) ··· 1217 1207 { 1218 1208 return last_disk_activity; 1219 1209 } 1220 - 1221 - int ata_spinup_time(void) 1222 - { 1223 - return spinup_time; 1224 - } 1225 - 1226 - #ifdef STORAGE_GET_INFO 1227 - void ata_get_info(IF_MD(int drive,)struct storage_info *info) 1228 - { 1229 - unsigned short *src,*dest; 1230 - static char vendor[8]; 1231 - static char product[16]; 1232 - static char revision[4]; 1233 - #ifdef HAVE_MULTIDRIVE 1234 - (void)drive; /* unused for now */ 1235 - #endif 1236 - int i; 1237 - 1238 - info->sector_size = log_sector_size; 1239 - info->num_sectors = total_sectors; 1240 - 1241 - src = (unsigned short*)&identify_info[27]; 1242 - dest = (unsigned short*)vendor; 1243 - for (i=0;i<4;i++) 1244 - dest[i] = htobe16(src[i]); 1245 - info->vendor=vendor; 1246 - 1247 - src = (unsigned short*)&identify_info[31]; 1248 - dest = (unsigned short*)product; 1249 - for (i=0;i<8;i++) 1250 - dest[i] = htobe16(src[i]); 1251 - info->product=product; 1252 - 1253 - src = (unsigned short*)&identify_info[23]; 1254 - dest = (unsigned short*)revision; 1255 - for (i=0;i<2;i++) 1256 - dest[i] = htobe16(src[i]); 1257 - info->revision=revision; 1258 - } 1259 - #endif 1260 1210 1261 1211 #ifdef HAVE_ATA_DMA 1262 1212 /* Returns last DMA mode as set by set_features() */
+8 -31
firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
··· 65 65 66 66 /** static, private data **/ 67 67 static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR; 68 - static uint16_t identify_info[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR; 69 68 static bool ceata; 70 - static bool ata_lba48; 71 69 static bool ata_dma; 72 - static uint64_t ata_total_sectors; 73 - static uint32_t log_sector_size; 74 - static struct mutex ata_mutex; 75 70 static struct semaphore ata_wakeup; 76 71 static long ata_last_activity_value = -1; 77 72 static long ata_sleep_timeout = 7 * HZ; 78 73 static bool ata_powered; 79 - static bool canflush = true; 80 74 static struct semaphore mmc_wakeup; 81 75 static struct semaphore mmc_comp_wakeup; 82 - static int spinup_time = 0; 83 76 #ifdef HAVE_ATA_DMA 84 77 static int dma_mode = 0; 85 78 static uint32_t ata_dma_flags; ··· 89 82 static const bool ata_error_srst = true; 90 83 91 84 static int ata_reset(void); 85 + 86 + #include "ata-common.c" 92 87 93 88 static uint16_t ata_read_cbr(uint32_t volatile* reg) 94 89 { ··· 758 753 759 754 spinup_time = current_tick - spinup_start; 760 755 761 - ata_total_sectors = (identify_info[61] << 16) | identify_info[60]; 762 - if (ceata || (identify_info[83] & BIT(10) && ata_total_sectors == 0x0FFFFFFF)) 756 + total_sectors = (identify_info[61] << 16) | identify_info[60]; 757 + if (ceata || (identify_info[83] & BIT(10) && total_sectors == 0x0FFFFFFF)) 763 758 { 764 - ata_total_sectors = ((uint64_t)identify_info[103] << 48) | 759 + total_sectors = ((uint64_t)identify_info[103] << 48) | 765 760 ((uint64_t)identify_info[102] << 32) | 766 761 ((uint64_t)identify_info[101] << 16) | 767 762 identify_info[100]; ··· 902 897 return rc; 903 898 } 904 899 905 - static int ata_transfer_sectors(uint64_t sector, uint32_t count, void* buffer, bool write) 900 + static int ata_transfer_sectors(uint64_t sector, int count, void* buffer, int write) 906 901 { 907 902 if (!ata_powered) 908 903 ata_power_up(); 909 - if (sector + count > ata_total_sectors) 904 + if (sector + count > total_sectors) 910 905 RET_ERR(0); 911 906 ata_set_active(); 912 907 if (ata_dma && write) ··· 1013 1008 mutex_unlock(&ata_mutex); 1014 1009 return rc; 1015 1010 } 1016 - 1017 - #include "ata-common.c" 1018 1011 1019 1012 #ifndef MAX_PHYS_SECTOR_SIZE 1020 1013 int ata_read_sectors(IF_MD(int drive,) sector_t start, int incount, ··· 1134 1127 ata_set_active(); 1135 1128 } 1136 1129 1137 - #ifdef STORAGE_GET_INFO 1138 - void ata_get_info(IF_MD(int drive,) struct storage_info *info) 1139 - { 1140 - info->sector_size = log_sector_size; 1141 - info->num_sectors = ata_total_sectors; 1142 - info->vendor = "Apple"; 1143 - info->product = "iPod Classic"; 1144 - info->revision = "1.0"; 1145 - } 1146 - #endif 1147 - 1148 1130 long ata_last_disk_activity(void) 1149 1131 { 1150 1132 return ata_last_activity_value; ··· 1158 1140 semaphore_init(&mmc_comp_wakeup, 1, 0); 1159 1141 ceata = PDAT(11) & BIT(1); 1160 1142 ata_powered = false; 1161 - ata_total_sectors = 0; 1143 + total_sectors = 0; 1162 1144 1163 1145 /* get identify_info */ 1164 1146 mutex_lock(&ata_mutex); ··· 1253 1235 unsigned short* ata_get_identify(void) 1254 1236 { 1255 1237 return identify_info; 1256 - } 1257 - 1258 - int ata_spinup_time(void) 1259 - { 1260 - return spinup_time; 1261 1238 } 1262 1239 1263 1240 #ifdef HAVE_ATA_DMA