wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 2 | * (C) Copyright 2000-2011 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * IDE support |
| 27 | */ |
Albert Aribaud | 4502755 | 2010-08-08 05:17:06 +0530 | [diff] [blame] | 28 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | #include <common.h> |
| 30 | #include <config.h> |
| 31 | #include <watchdog.h> |
| 32 | #include <command.h> |
| 33 | #include <image.h> |
| 34 | #include <asm/byteorder.h> |
Heiko Schocher | 2559e0f | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 35 | #include <asm/io.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 36 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 37 | #if defined(CONFIG_IDE_8xx_DIRECT) || defined(CONFIG_IDE_PCMCIA) |
| 38 | # include <pcmcia.h> |
| 39 | #endif |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 40 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | #include <ide.h> |
| 42 | #include <ata.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 43 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | #ifdef CONFIG_STATUS_LED |
| 45 | # include <status_led.h> |
| 46 | #endif |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 47 | |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 48 | #ifdef __PPC__ |
| 49 | # define EIEIO __asm__ volatile ("eieio") |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 50 | # define SYNC __asm__ volatile ("sync") |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 51 | #else |
| 52 | # define EIEIO /* nothing */ |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 53 | # define SYNC /* nothing */ |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 54 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 56 | /* ------------------------------------------------------------------------- */ |
| 57 | |
| 58 | /* Current I/O Device */ |
| 59 | static int curr_device = -1; |
| 60 | |
| 61 | /* Current offset for IDE0 / IDE1 bus access */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 62 | ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = { |
| 63 | #if defined(CONFIG_SYS_ATA_IDE0_OFFSET) |
| 64 | CONFIG_SYS_ATA_IDE0_OFFSET, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 66 | #if defined(CONFIG_SYS_ATA_IDE1_OFFSET) && (CONFIG_SYS_IDE_MAXBUS > 1) |
| 67 | CONFIG_SYS_ATA_IDE1_OFFSET, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 68 | #endif |
| 69 | }; |
| 70 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 72 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | block_dev_desc_t ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | /* ------------------------------------------------------------------------- */ |
| 75 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_IDE_RESET |
| 77 | static void ide_reset (void); |
| 78 | #else |
| 79 | #define ide_reset() /* dummy */ |
| 80 | #endif |
| 81 | |
| 82 | static void ide_ident (block_dev_desc_t *dev_desc); |
| 83 | static uchar ide_wait (int dev, ulong t); |
| 84 | |
| 85 | #define IDE_TIME_OUT 2000 /* 2 sec timeout */ |
| 86 | |
| 87 | #define ATAPI_TIME_OUT 7000 /* 7 sec timeout (5 sec seems to work...) */ |
| 88 | |
| 89 | #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */ |
| 90 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 91 | static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len); |
| 92 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | #ifndef CONFIG_SYS_ATA_PORT_ADDR |
| 94 | #define CONFIG_SYS_ATA_PORT_ADDR(port) (port) |
Heiko Schocher | 633e03a | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 95 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 96 | |
| 97 | #ifdef CONFIG_ATAPI |
| 98 | static void atapi_inquiry(block_dev_desc_t *dev_desc); |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 99 | static ulong atapi_read(int device, ulong blknr, lbaint_t blkcnt, |
| 100 | void *buffer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | #endif |
| 102 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | |
| 104 | /* ------------------------------------------------------------------------- */ |
| 105 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 106 | int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 108 | int rcode = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 109 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 110 | switch (argc) { |
| 111 | case 0: |
| 112 | case 1: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 113 | return CMD_RET_USAGE; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 114 | case 2: |
| 115 | if (strncmp(argv[1], "res", 3) == 0) { |
| 116 | puts("\nReset IDE" |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 117 | #ifdef CONFIG_IDE_8xx_DIRECT |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 118 | " on PCMCIA " PCMCIA_SLOT_MSG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 119 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 120 | ": "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 122 | ide_init(); |
| 123 | return 0; |
| 124 | } else if (strncmp(argv[1], "inf", 3) == 0) { |
| 125 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 127 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 128 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 129 | for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) { |
| 130 | if (ide_dev_desc[i].type == DEV_TYPE_UNKNOWN) |
| 131 | continue; /* list only known devices */ |
| 132 | printf("IDE device %d: ", i); |
| 133 | dev_print(&ide_dev_desc[i]); |
| 134 | } |
| 135 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 137 | } else if (strncmp(argv[1], "dev", 3) == 0) { |
| 138 | if ((curr_device < 0) |
| 139 | || (curr_device >= CONFIG_SYS_IDE_MAXDEVICE)) { |
| 140 | puts("\nno IDE devices available\n"); |
| 141 | return 1; |
| 142 | } |
| 143 | printf("\nIDE device %d: ", curr_device); |
| 144 | dev_print(&ide_dev_desc[curr_device]); |
| 145 | return 0; |
| 146 | } else if (strncmp(argv[1], "part", 4) == 0) { |
| 147 | int dev, ok; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 148 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 149 | for (ok = 0, dev = 0; |
| 150 | dev < CONFIG_SYS_IDE_MAXDEVICE; |
| 151 | ++dev) { |
| 152 | if (ide_dev_desc[dev].part_type != |
| 153 | PART_TYPE_UNKNOWN) { |
| 154 | ++ok; |
| 155 | if (dev) |
| 156 | putc('\n'); |
| 157 | print_part(&ide_dev_desc[dev]); |
| 158 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 159 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 160 | if (!ok) { |
| 161 | puts("\nno IDE devices available\n"); |
| 162 | rcode++; |
| 163 | } |
| 164 | return rcode; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | } |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 166 | return CMD_RET_USAGE; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 167 | case 3: |
| 168 | if (strncmp(argv[1], "dev", 3) == 0) { |
| 169 | int dev = (int) simple_strtoul(argv[2], NULL, 10); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 171 | printf("\nIDE device %d: ", dev); |
| 172 | if (dev >= CONFIG_SYS_IDE_MAXDEVICE) { |
| 173 | puts("unknown device\n"); |
| 174 | return 1; |
| 175 | } |
| 176 | dev_print(&ide_dev_desc[dev]); |
| 177 | /*ide_print (dev); */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 178 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 179 | if (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN) |
| 180 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 181 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 182 | curr_device = dev; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 184 | puts("... is now current device\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 185 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 186 | return 0; |
| 187 | } else if (strncmp(argv[1], "part", 4) == 0) { |
| 188 | int dev = (int) simple_strtoul(argv[2], NULL, 10); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 189 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 190 | if (ide_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 191 | print_part(&ide_dev_desc[dev]); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 192 | } else { |
| 193 | printf("\nIDE device %d not available\n", |
| 194 | dev); |
| 195 | rcode = 1; |
| 196 | } |
| 197 | return rcode; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 198 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 199 | |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 200 | return CMD_RET_USAGE; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 201 | default: |
| 202 | /* at least 4 args */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 203 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 204 | if (strcmp(argv[1], "read") == 0) { |
| 205 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 206 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 207 | ulong n; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 208 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 209 | #ifdef CONFIG_SYS_64BIT_LBA |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 210 | lbaint_t blk = simple_strtoull(argv[3], NULL, 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 211 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 212 | printf("\nIDE read: device %d block # %lld, count %ld ... ", |
| 213 | curr_device, blk, cnt); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 214 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 215 | lbaint_t blk = simple_strtoul(argv[3], NULL, 16); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 216 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 217 | printf("\nIDE read: device %d block # %ld, count %ld ... ", |
| 218 | curr_device, blk, cnt); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 219 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 220 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 221 | n = ide_dev_desc[curr_device].block_read(curr_device, |
| 222 | blk, cnt, |
| 223 | (ulong *)addr); |
| 224 | /* flush cache after read */ |
| 225 | flush_cache(addr, |
| 226 | cnt * ide_dev_desc[curr_device].blksz); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 227 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 228 | printf("%ld blocks read: %s\n", |
| 229 | n, (n == cnt) ? "OK" : "ERROR"); |
| 230 | if (n == cnt) |
| 231 | return 0; |
| 232 | else |
| 233 | return 1; |
| 234 | } else if (strcmp(argv[1], "write") == 0) { |
| 235 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 236 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 237 | ulong n; |
| 238 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 239 | #ifdef CONFIG_SYS_64BIT_LBA |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 240 | lbaint_t blk = simple_strtoull(argv[3], NULL, 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 241 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 242 | printf("\nIDE write: device %d block # %lld, count %ld ... ", |
| 243 | curr_device, blk, cnt); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 244 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 245 | lbaint_t blk = simple_strtoul(argv[3], NULL, 16); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 246 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 247 | printf("\nIDE write: device %d block # %ld, count %ld ... ", |
| 248 | curr_device, blk, cnt); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 249 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 250 | n = ide_write(curr_device, blk, cnt, (ulong *) addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 251 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 252 | printf("%ld blocks written: %s\n", |
| 253 | n, (n == cnt) ? "OK" : "ERROR"); |
| 254 | if (n == cnt) |
| 255 | return 0; |
| 256 | else |
| 257 | return 1; |
| 258 | } else { |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 259 | return CMD_RET_USAGE; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 260 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 261 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 262 | return rcode; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 263 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 266 | int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 267 | { |
Rob Herring | a20cbf9 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 268 | return common_diskboot(cmdtp, "ide", argc, argv); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Pavel Herrmann | 95b0cb5 | 2012-10-07 05:56:10 +0000 | [diff] [blame] | 271 | /* ------------------------------------------------------------------------- */ |
| 272 | |
| 273 | void __ide_led(uchar led, uchar status) |
| 274 | { |
| 275 | #if defined(CONFIG_IDE_LED) && defined(PER8_BASE) /* required by LED_PORT */ |
| 276 | static uchar led_buffer; /* Buffer for current LED status */ |
| 277 | |
| 278 | uchar *led_port = LED_PORT; |
| 279 | |
| 280 | if (status) /* switch LED on */ |
| 281 | led_buffer |= led; |
| 282 | else /* switch LED off */ |
| 283 | led_buffer &= ~led; |
| 284 | |
| 285 | *led_port = led_buffer; |
| 286 | #endif |
| 287 | } |
| 288 | |
| 289 | void ide_led(uchar led, uchar status) |
| 290 | __attribute__ ((weak, alias("__ide_led"))); |
| 291 | |
| 292 | #ifndef CONFIG_IDE_LED /* define LED macros, they are not used anyways */ |
| 293 | # define DEVICE_LED(x) 0 |
| 294 | # define LED_IDE1 1 |
| 295 | # define LED_IDE2 2 |
| 296 | #endif |
| 297 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 298 | /* ------------------------------------------------------------------------- */ |
| 299 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 300 | inline void __ide_outb(int dev, int port, unsigned char val) |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 301 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 302 | debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n", |
| 303 | dev, port, val, |
| 304 | (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port))); |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 305 | |
| 306 | #if defined(CONFIG_IDE_AHB) |
| 307 | if (port) { |
| 308 | /* write command */ |
| 309 | ide_write_register(dev, port, val); |
| 310 | } else { |
| 311 | /* write data */ |
| 312 | outb(val, (ATA_CURR_BASE(dev))); |
| 313 | } |
| 314 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 315 | outb(val, (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port))); |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 316 | #endif |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 317 | } |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 318 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 319 | void ide_outb(int dev, int port, unsigned char val) |
| 320 | __attribute__ ((weak, alias("__ide_outb"))); |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 321 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 322 | inline unsigned char __ide_inb(int dev, int port) |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 323 | { |
| 324 | uchar val; |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 325 | |
| 326 | #if defined(CONFIG_IDE_AHB) |
| 327 | val = ide_read_register(dev, port); |
| 328 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 329 | val = inb((ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port))); |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 330 | #endif |
| 331 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 332 | debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n", |
| 333 | dev, port, |
| 334 | (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)), val); |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 335 | return val; |
| 336 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 337 | |
Kim Phillips | 8167f3c | 2009-05-19 12:53:36 -0500 | [diff] [blame] | 338 | unsigned char ide_inb(int dev, int port) |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 339 | __attribute__ ((weak, alias("__ide_inb"))); |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 340 | |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 341 | #ifdef CONFIG_TUNE_PIO |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 342 | inline int __ide_set_piomode(int pio_mode) |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 343 | { |
| 344 | return 0; |
| 345 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 346 | |
| 347 | inline int ide_set_piomode(int pio_mode) |
| 348 | __attribute__ ((weak, alias("__ide_set_piomode"))); |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 349 | #endif |
| 350 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 351 | void ide_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 352 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 353 | unsigned char c; |
| 354 | int i, bus; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 355 | |
wdenk | 7f00b94 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 356 | #ifdef CONFIG_IDE_8xx_PCCARD |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 357 | extern int ide_devices_found; /* Initialized in check_ide_device() */ |
| 358 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
wdenk | 7f00b94 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 359 | |
| 360 | #ifdef CONFIG_IDE_PREINIT |
| 361 | WATCHDOG_RESET(); |
| 362 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 363 | if (ide_preinit()) { |
| 364 | puts("ide_preinit failed\n"); |
wdenk | 7f00b94 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 365 | return; |
| 366 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 367 | #endif /* CONFIG_IDE_PREINIT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 368 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 369 | WATCHDOG_RESET(); |
| 370 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 371 | /* |
| 372 | * Reset the IDE just to be sure. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 373 | * Light LED's to show |
| 374 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 375 | ide_led((LED_IDE1 | LED_IDE2), 1); /* LED's on */ |
| 376 | |
| 377 | /* ATAPI Drives seems to need a proper IDE Reset */ |
| 378 | ide_reset(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 379 | |
Pavel Herrmann | 2c13c4a | 2012-10-09 07:01:56 +0000 | [diff] [blame] | 380 | #ifdef CONFIG_IDE_INIT_POSTRESET |
| 381 | WATCHDOG_RESET(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 382 | |
Pavel Herrmann | 2c13c4a | 2012-10-09 07:01:56 +0000 | [diff] [blame] | 383 | if (ide_init_postreset()) { |
| 384 | puts("ide_preinit_postreset failed\n"); |
| 385 | return; |
| 386 | } |
| 387 | #endif /* CONFIG_IDE_INIT_POSTRESET */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 388 | |
| 389 | /* |
| 390 | * Wait for IDE to get ready. |
| 391 | * According to spec, this can take up to 31 seconds! |
| 392 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 393 | for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) { |
| 394 | int dev = |
| 395 | bus * (CONFIG_SYS_IDE_MAXDEVICE / |
| 396 | CONFIG_SYS_IDE_MAXBUS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 397 | |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 398 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 399 | /* Skip non-ide devices from probing */ |
| 400 | if ((ide_devices_found & (1 << bus)) == 0) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 401 | ide_led((LED_IDE1 | LED_IDE2), 0); /* LED's off */ |
wdenk | 4fc9569 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 402 | continue; |
| 403 | } |
| 404 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 405 | printf("Bus %d: ", bus); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 406 | |
| 407 | ide_bus_ok[bus] = 0; |
| 408 | |
| 409 | /* Select device |
| 410 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 411 | udelay(100000); /* 100 ms */ |
| 412 | ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev)); |
| 413 | udelay(100000); /* 100 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 414 | i = 0; |
| 415 | do { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 416 | udelay(10000); /* 10 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 417 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 418 | c = ide_inb(dev, ATA_STATUS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 419 | i++; |
| 420 | if (i > (ATA_RESET_TIME * 100)) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 421 | puts("** Timeout **\n"); |
| 422 | /* LED's off */ |
| 423 | ide_led((LED_IDE1 | LED_IDE2), 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 424 | return; |
| 425 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 426 | if ((i >= 100) && ((i % 100) == 0)) |
| 427 | putc('.'); |
| 428 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 429 | } while (c & ATA_STAT_BUSY); |
| 430 | |
| 431 | if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 432 | puts("not available "); |
| 433 | debug("Status = 0x%02X ", c); |
| 434 | #ifndef CONFIG_ATAPI /* ATAPI Devices do not set DRDY */ |
| 435 | } else if ((c & ATA_STAT_READY) == 0) { |
| 436 | puts("not available "); |
| 437 | debug("Status = 0x%02X ", c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 438 | #endif |
| 439 | } else { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 440 | puts("OK "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 441 | ide_bus_ok[bus] = 1; |
| 442 | } |
| 443 | WATCHDOG_RESET(); |
| 444 | } |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 445 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 446 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 447 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 448 | ide_led((LED_IDE1 | LED_IDE2), 0); /* LED's off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | |
| 450 | curr_device = -1; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 451 | for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 453 | ide_dev_desc[i].type = DEV_TYPE_UNKNOWN; |
| 454 | ide_dev_desc[i].if_type = IF_TYPE_IDE; |
| 455 | ide_dev_desc[i].dev = i; |
| 456 | ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN; |
| 457 | ide_dev_desc[i].blksz = 0; |
| 458 | ide_dev_desc[i].lba = 0; |
| 459 | ide_dev_desc[i].block_read = ide_read; |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 460 | ide_dev_desc[i].block_write = ide_write; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 461 | if (!ide_bus_ok[IDE_BUS(i)]) |
| 462 | continue; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 463 | ide_led(led, 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 464 | ide_ident(&ide_dev_desc[i]); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 465 | ide_led(led, 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 466 | dev_print(&ide_dev_desc[i]); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 467 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 468 | if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 469 | /* initialize partition type */ |
| 470 | init_part(&ide_dev_desc[i]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 471 | if (curr_device < 0) |
| 472 | curr_device = i; |
| 473 | } |
| 474 | } |
| 475 | WATCHDOG_RESET(); |
| 476 | } |
| 477 | |
| 478 | /* ------------------------------------------------------------------------- */ |
| 479 | |
Matthew McClintock | 6252b4f | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 480 | #ifdef CONFIG_PARTITIONS |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 481 | block_dev_desc_t *ide_get_dev(int dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 482 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 483 | return (dev < CONFIG_SYS_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 484 | } |
Matthew McClintock | 6252b4f | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 485 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 486 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 487 | /* ------------------------------------------------------------------------- */ |
| 488 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 489 | void ide_input_swap_data(int dev, ulong *sect_buf, int words) |
| 490 | __attribute__ ((weak, alias("__ide_input_swap_data"))); |
| 491 | |
| 492 | void ide_input_data(int dev, ulong *sect_buf, int words) |
| 493 | __attribute__ ((weak, alias("__ide_input_data"))); |
| 494 | |
| 495 | void ide_output_data(int dev, const ulong *sect_buf, int words) |
| 496 | __attribute__ ((weak, alias("__ide_output_data"))); |
| 497 | |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 498 | /* We only need to swap data if we are running on a big endian cpu. */ |
Pavel Herrmann | 3597c52 | 2012-10-09 07:10:08 +0000 | [diff] [blame] | 499 | #if defined(__LITTLE_ENDIAN) |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 500 | void __ide_input_swap_data(int dev, ulong *sect_buf, int words) |
| 501 | { |
| 502 | ide_input_data(dev, sect_buf, words); |
| 503 | } |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 504 | #else |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 505 | void __ide_input_swap_data(int dev, ulong *sect_buf, int words) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 506 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 507 | volatile ushort *pbuf = |
| 508 | (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 509 | ushort *dbuf = (ushort *) sect_buf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 510 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 511 | debug("in input swap data base for read is %lx\n", |
| 512 | (unsigned long) pbuf); |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 513 | |
| 514 | while (words--) { |
Wolfgang Denk | 39c7642 | 2006-06-16 17:32:31 +0200 | [diff] [blame] | 515 | #ifdef __MIPS__ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 516 | *dbuf++ = swab16p((u16 *) pbuf); |
| 517 | *dbuf++ = swab16p((u16 *) pbuf); |
Wolfgang Denk | 39c7642 | 2006-06-16 17:32:31 +0200 | [diff] [blame] | 518 | #else |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 519 | *dbuf++ = ld_le16(pbuf); |
| 520 | *dbuf++ = ld_le16(pbuf); |
Wolfgang Denk | 39c7642 | 2006-06-16 17:32:31 +0200 | [diff] [blame] | 521 | #endif /* !MIPS */ |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 522 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 523 | } |
Pavel Herrmann | 3597c52 | 2012-10-09 07:10:08 +0000 | [diff] [blame] | 524 | #endif /* __LITTLE_ENDIAN */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 525 | |
| 526 | |
Albert Aribaud | 036c6b4 | 2010-08-08 05:17:05 +0530 | [diff] [blame] | 527 | #if defined(CONFIG_IDE_SWAP_IO) |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 528 | void __ide_output_data(int dev, const ulong *sect_buf, int words) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 529 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 530 | ushort *dbuf; |
| 531 | volatile ushort *pbuf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 532 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 533 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 534 | dbuf = (ushort *) sect_buf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 535 | while (words--) { |
| 536 | EIEIO; |
| 537 | *pbuf = *dbuf++; |
| 538 | EIEIO; |
| 539 | *pbuf = *dbuf++; |
| 540 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 541 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 542 | #else /* ! CONFIG_IDE_SWAP_IO */ |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 543 | void __ide_output_data(int dev, const ulong *sect_buf, int words) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 544 | { |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 545 | #if defined(CONFIG_IDE_AHB) |
| 546 | ide_write_data(dev, sect_buf, words); |
| 547 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 548 | outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1); |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 549 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 550 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 551 | #endif /* CONFIG_IDE_SWAP_IO */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 552 | |
Albert Aribaud | 036c6b4 | 2010-08-08 05:17:05 +0530 | [diff] [blame] | 553 | #if defined(CONFIG_IDE_SWAP_IO) |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 554 | void __ide_input_data(int dev, ulong *sect_buf, int words) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 555 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 556 | ushort *dbuf; |
| 557 | volatile ushort *pbuf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 558 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 559 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 560 | dbuf = (ushort *) sect_buf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 561 | |
| 562 | debug("in input data base for read is %lx\n", (unsigned long) pbuf); |
| 563 | |
| 564 | while (words--) { |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 565 | EIEIO; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 566 | *dbuf++ = *pbuf; |
wdenk | f6925c7 | 2005-01-22 18:26:04 +0000 | [diff] [blame] | 567 | EIEIO; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 568 | *dbuf++ = *pbuf; |
wdenk | 2f99a69 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 569 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 570 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 571 | #else /* ! CONFIG_IDE_SWAP_IO */ |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 572 | void __ide_input_data(int dev, ulong *sect_buf, int words) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 573 | { |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 574 | #if defined(CONFIG_IDE_AHB) |
| 575 | ide_read_data(dev, sect_buf, words); |
| 576 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 577 | insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1); |
Macpaul Lin | d1e4994 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 578 | #endif |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 581 | #endif /* CONFIG_IDE_SWAP_IO */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 582 | |
| 583 | /* ------------------------------------------------------------------------- |
| 584 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 585 | static void ide_ident(block_dev_desc_t *dev_desc) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 586 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 587 | unsigned char c; |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 588 | hd_driveid_t iop; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 589 | |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 590 | #ifdef CONFIG_ATAPI |
| 591 | int retries = 0; |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 592 | #endif |
| 593 | |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 594 | #ifdef CONFIG_TUNE_PIO |
| 595 | int pio_mode; |
| 596 | #endif |
| 597 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 598 | #if 0 |
| 599 | int mode, cycle_time; |
| 600 | #endif |
| 601 | int device; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 602 | |
| 603 | device = dev_desc->dev; |
| 604 | printf(" Device %d: ", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 605 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 606 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 607 | /* Select device |
| 608 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 609 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 610 | dev_desc->if_type = IF_TYPE_IDE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 611 | #ifdef CONFIG_ATAPI |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 612 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 613 | retries = 0; |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 614 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 615 | /* Warning: This will be tricky to read */ |
| 616 | while (retries <= 1) { |
| 617 | /* check signature */ |
| 618 | if ((ide_inb(device, ATA_SECT_CNT) == 0x01) && |
| 619 | (ide_inb(device, ATA_SECT_NUM) == 0x01) && |
| 620 | (ide_inb(device, ATA_CYL_LOW) == 0x14) && |
| 621 | (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) { |
| 622 | /* ATAPI Signature found */ |
| 623 | dev_desc->if_type = IF_TYPE_ATAPI; |
| 624 | /* |
| 625 | * Start Ident Command |
| 626 | */ |
| 627 | ide_outb(device, ATA_COMMAND, ATAPI_CMD_IDENT); |
| 628 | /* |
| 629 | * Wait for completion - ATAPI devices need more time |
| 630 | * to become ready |
| 631 | */ |
| 632 | c = ide_wait(device, ATAPI_TIME_OUT); |
| 633 | } else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 634 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 635 | { |
| 636 | /* |
| 637 | * Start Ident Command |
| 638 | */ |
| 639 | ide_outb(device, ATA_COMMAND, ATA_CMD_IDENT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 640 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 641 | /* |
| 642 | * Wait for completion |
| 643 | */ |
| 644 | c = ide_wait(device, IDE_TIME_OUT); |
| 645 | } |
| 646 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 647 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 648 | if (((c & ATA_STAT_DRQ) == 0) || |
| 649 | ((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) { |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 650 | #ifdef CONFIG_ATAPI |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 651 | { |
| 652 | /* |
| 653 | * Need to soft reset the device |
| 654 | * in case it's an ATAPI... |
| 655 | */ |
| 656 | debug("Retrying...\n"); |
| 657 | ide_outb(device, ATA_DEV_HD, |
| 658 | ATA_LBA | ATA_DEVICE(device)); |
| 659 | udelay(100000); |
| 660 | ide_outb(device, ATA_COMMAND, 0x08); |
| 661 | udelay(500000); /* 500 ms */ |
| 662 | } |
| 663 | /* |
| 664 | * Select device |
| 665 | */ |
| 666 | ide_outb(device, ATA_DEV_HD, |
| 667 | ATA_LBA | ATA_DEVICE(device)); |
| 668 | retries++; |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 669 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 670 | return; |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 671 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 672 | } |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 673 | #ifdef CONFIG_ATAPI |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 674 | else |
| 675 | break; |
| 676 | } /* see above - ugly to read */ |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 677 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 678 | if (retries == 2) /* Not found */ |
wdenk | e2d6d74 | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 679 | return; |
| 680 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 681 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 682 | ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 683 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 684 | ident_cpy((unsigned char *) dev_desc->revision, iop.fw_rev, |
| 685 | sizeof(dev_desc->revision)); |
| 686 | ident_cpy((unsigned char *) dev_desc->vendor, iop.model, |
| 687 | sizeof(dev_desc->vendor)); |
| 688 | ident_cpy((unsigned char *) dev_desc->product, iop.serial_no, |
| 689 | sizeof(dev_desc->product)); |
wdenk | acd9b10 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 690 | #ifdef __LITTLE_ENDIAN |
| 691 | /* |
Richard Retanubun | 54f3062 | 2008-11-06 14:01:51 -0500 | [diff] [blame] | 692 | * firmware revision, model, and serial number have Big Endian Byte |
| 693 | * order in Word. Convert all three to little endian. |
wdenk | acd9b10 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 694 | * |
| 695 | * See CF+ and CompactFlash Specification Revision 2.0: |
Richard Retanubun | 54f3062 | 2008-11-06 14:01:51 -0500 | [diff] [blame] | 696 | * 6.2.1.6: Identify Drive, Table 39 for more details |
wdenk | acd9b10 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 697 | */ |
| 698 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 699 | strswab(dev_desc->revision); |
| 700 | strswab(dev_desc->vendor); |
| 701 | strswab(dev_desc->product); |
wdenk | acd9b10 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 702 | #endif /* __LITTLE_ENDIAN */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 703 | |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 704 | if ((iop.config & 0x0080) == 0x0080) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 705 | dev_desc->removable = 1; |
| 706 | else |
| 707 | dev_desc->removable = 0; |
| 708 | |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 709 | #ifdef CONFIG_TUNE_PIO |
| 710 | /* Mode 0 - 2 only, are directly determined by word 51. */ |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 711 | pio_mode = iop.tPIO; |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 712 | if (pio_mode > 2) { |
| 713 | printf("WARNING: Invalid PIO (word 51 = %d).\n", pio_mode); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 714 | /* Force it to dead slow, and hope for the best... */ |
| 715 | pio_mode = 0; |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | /* Any CompactFlash Storage Card that supports PIO mode 3 or above |
| 719 | * shall set bit 1 of word 53 to one and support the fields contained |
| 720 | * in words 64 through 70. |
| 721 | */ |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 722 | if (iop.field_valid & 0x02) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 723 | /* |
| 724 | * Mode 3 and above are possible. Check in order from slow |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 725 | * to fast, so we wind up with the highest mode allowed. |
| 726 | */ |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 727 | if (iop.eide_pio_modes & 0x01) |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 728 | pio_mode = 3; |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 729 | if (iop.eide_pio_modes & 0x02) |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 730 | pio_mode = 4; |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 731 | if (ata_id_is_cfa((u16 *)&iop)) { |
| 732 | if ((iop.cf_advanced_caps & 0x07) == 0x01) |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 733 | pio_mode = 5; |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 734 | if ((iop.cf_advanced_caps & 0x07) == 0x02) |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 735 | pio_mode = 6; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | /* System-specific, depends on bus speeds, etc. */ |
| 740 | ide_set_piomode(pio_mode); |
| 741 | #endif /* CONFIG_TUNE_PIO */ |
| 742 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 743 | #if 0 |
| 744 | /* |
| 745 | * Drive PIO mode autoselection |
| 746 | */ |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 747 | mode = iop.tPIO; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 748 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 749 | printf("tPIO = 0x%02x = %d\n", mode, mode); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 750 | if (mode > 2) { /* 2 is maximum allowed tPIO value */ |
| 751 | mode = 2; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 752 | debug("Override tPIO -> 2\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 753 | } |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 754 | if (iop.field_valid & 2) { /* drive implements ATA2? */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 755 | debug("Drive implements ATA2\n"); |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 756 | if (iop.capability & 8) { /* drive supports use_iordy? */ |
| 757 | cycle_time = iop.eide_pio_iordy; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 758 | } else { |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 759 | cycle_time = iop.eide_pio; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 760 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 761 | debug("cycle time = %d\n", cycle_time); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 762 | mode = 4; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 763 | if (cycle_time > 120) |
| 764 | mode = 3; /* 120 ns for PIO mode 4 */ |
| 765 | if (cycle_time > 180) |
| 766 | mode = 2; /* 180 ns for PIO mode 3 */ |
| 767 | if (cycle_time > 240) |
| 768 | mode = 1; /* 240 ns for PIO mode 4 */ |
| 769 | if (cycle_time > 383) |
| 770 | mode = 0; /* 383 ns for PIO mode 4 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 771 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 772 | printf("PIO mode to use: PIO %d\n", mode); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 773 | #endif /* 0 */ |
| 774 | |
| 775 | #ifdef CONFIG_ATAPI |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 776 | if (dev_desc->if_type == IF_TYPE_ATAPI) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 777 | atapi_inquiry(dev_desc); |
| 778 | return; |
| 779 | } |
| 780 | #endif /* CONFIG_ATAPI */ |
| 781 | |
wdenk | acd9b10 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 782 | #ifdef __BIG_ENDIAN |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 783 | /* swap shorts */ |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 784 | dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 785 | #else /* ! __BIG_ENDIAN */ |
wdenk | acd9b10 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 786 | /* |
| 787 | * do not swap shorts on little endian |
| 788 | * |
| 789 | * See CF+ and CompactFlash Specification Revision 2.0: |
| 790 | * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details. |
| 791 | */ |
Marek Vasut | e49757e | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 792 | dev_desc->lba = iop.lba_capacity; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 793 | #endif /* __BIG_ENDIAN */ |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 794 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 795 | #ifdef CONFIG_LBA48 |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 796 | if (iop.command_set_2 & 0x0400) { /* LBA 48 support */ |
wdenk | 0593920 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 797 | dev_desc->lba48 = 1; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 798 | dev_desc->lba = (unsigned long long) iop.lba48_capacity[0] | |
| 799 | ((unsigned long long) iop.lba48_capacity[1] << 16) | |
| 800 | ((unsigned long long) iop.lba48_capacity[2] << 32) | |
| 801 | ((unsigned long long) iop.lba48_capacity[3] << 48); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 802 | } else { |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 803 | dev_desc->lba48 = 0; |
| 804 | } |
| 805 | #endif /* CONFIG_LBA48 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 806 | /* assuming HD */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 807 | dev_desc->type = DEV_TYPE_HARDDISK; |
| 808 | dev_desc->blksz = ATA_BLOCKSIZE; |
| 809 | dev_desc->lun = 0; /* just to fill something in... */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 810 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 811 | #if 0 /* only used to test the powersaving mode, |
| 812 | * if enabled, the drive goes after 5 sec |
| 813 | * in standby mode */ |
| 814 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 815 | c = ide_wait(device, IDE_TIME_OUT); |
| 816 | ide_outb(device, ATA_SECT_CNT, 1); |
| 817 | ide_outb(device, ATA_LBA_LOW, 0); |
| 818 | ide_outb(device, ATA_LBA_MID, 0); |
| 819 | ide_outb(device, ATA_LBA_HIGH, 0); |
| 820 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 821 | ide_outb(device, ATA_COMMAND, 0xe3); |
| 822 | udelay(50); |
| 823 | c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 824 | #endif |
| 825 | } |
| 826 | |
| 827 | |
| 828 | /* ------------------------------------------------------------------------- */ |
| 829 | |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 830 | ulong ide_read(int device, ulong blknr, lbaint_t blkcnt, void *buffer) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 831 | { |
| 832 | ulong n = 0; |
| 833 | unsigned char c; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 834 | unsigned char pwrsave = 0; /* power save */ |
| 835 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 836 | #ifdef CONFIG_LBA48 |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 837 | unsigned char lba48 = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 838 | |
Guennadi Liakhovetski | b71f1ca | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 839 | if (blknr & 0x0000fffff0000000ULL) { |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 840 | /* more than 28 bits used, use 48bit mode */ |
| 841 | lba48 = 1; |
| 842 | } |
| 843 | #endif |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 844 | debug("ide_read dev %d start %lX, blocks " LBAF " buffer at %lX\n", |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 845 | device, blknr, blkcnt, (ulong) buffer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 846 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 847 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 848 | |
| 849 | /* Select device |
| 850 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 851 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 852 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 853 | |
| 854 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 855 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 856 | goto IDE_READ_E; |
| 857 | } |
| 858 | |
| 859 | /* first check if the drive is in Powersaving mode, if yes, |
| 860 | * increase the timeout value */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 861 | ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_PWR); |
| 862 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 863 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 864 | c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 865 | |
| 866 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 867 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 868 | goto IDE_READ_E; |
| 869 | } |
| 870 | if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 871 | printf("No Powersaving mode %X\n", c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 872 | } else { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 873 | c = ide_inb(device, ATA_SECT_CNT); |
| 874 | debug("Powersaving %02X\n", c); |
| 875 | if (c == 0) |
| 876 | pwrsave = 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | |
| 880 | while (blkcnt-- > 0) { |
| 881 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 882 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 883 | |
| 884 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 885 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 886 | break; |
| 887 | } |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 888 | #ifdef CONFIG_LBA48 |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 889 | if (lba48) { |
| 890 | /* write high bits */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 891 | ide_outb(device, ATA_SECT_CNT, 0); |
| 892 | ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 893 | #ifdef CONFIG_SYS_64BIT_LBA |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 894 | ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF); |
| 895 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF); |
Guennadi Liakhovetski | b71f1ca | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 896 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 897 | ide_outb(device, ATA_LBA_MID, 0); |
| 898 | ide_outb(device, ATA_LBA_HIGH, 0); |
Guennadi Liakhovetski | b71f1ca | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 899 | #endif |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 900 | } |
| 901 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 902 | ide_outb(device, ATA_SECT_CNT, 1); |
| 903 | ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); |
| 904 | ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF); |
| 905 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 906 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 907 | #ifdef CONFIG_LBA48 |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 908 | if (lba48) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 909 | ide_outb(device, ATA_DEV_HD, |
| 910 | ATA_LBA | ATA_DEVICE(device)); |
| 911 | ide_outb(device, ATA_COMMAND, ATA_CMD_READ_EXT); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 912 | |
| 913 | } else |
| 914 | #endif |
| 915 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 916 | ide_outb(device, ATA_DEV_HD, ATA_LBA | |
| 917 | ATA_DEVICE(device) | ((blknr >> 24) & 0xF)); |
| 918 | ide_outb(device, ATA_COMMAND, ATA_CMD_READ); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 919 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 920 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 921 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 922 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 923 | if (pwrsave) { |
| 924 | /* may take up to 4 sec */ |
| 925 | c = ide_wait(device, IDE_SPIN_UP_TIME_OUT); |
| 926 | pwrsave = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 927 | } else { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 928 | /* can't take over 500 ms */ |
| 929 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 932 | if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) != |
| 933 | ATA_STAT_DRQ) { |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 934 | printf("Error (no IRQ) dev %d blk %ld: status %#02x\n", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 935 | device, blknr, c); |
| 936 | break; |
| 937 | } |
| 938 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 939 | ide_input_data(device, buffer, ATA_SECTORWORDS); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 940 | (void) ide_inb(device, ATA_STATUS); /* clear IRQ */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 941 | |
| 942 | ++n; |
| 943 | ++blknr; |
Greg Lopp | 50abf9f | 2007-04-13 08:02:24 +0200 | [diff] [blame] | 944 | buffer += ATA_BLOCKSIZE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 945 | } |
| 946 | IDE_READ_E: |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 947 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 948 | return (n); |
| 949 | } |
| 950 | |
| 951 | /* ------------------------------------------------------------------------- */ |
| 952 | |
| 953 | |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 954 | ulong ide_write(int device, ulong blknr, lbaint_t blkcnt, const void *buffer) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 955 | { |
| 956 | ulong n = 0; |
| 957 | unsigned char c; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 958 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 959 | #ifdef CONFIG_LBA48 |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 960 | unsigned char lba48 = 0; |
| 961 | |
Guennadi Liakhovetski | b71f1ca | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 962 | if (blknr & 0x0000fffff0000000ULL) { |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 963 | /* more than 28 bits used, use 48bit mode */ |
| 964 | lba48 = 1; |
| 965 | } |
| 966 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 967 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 968 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 969 | |
| 970 | /* Select device |
| 971 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 972 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 973 | |
| 974 | while (blkcnt-- > 0) { |
| 975 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 976 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 977 | |
| 978 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 979 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 980 | goto WR_OUT; |
| 981 | } |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 982 | #ifdef CONFIG_LBA48 |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 983 | if (lba48) { |
| 984 | /* write high bits */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 985 | ide_outb(device, ATA_SECT_CNT, 0); |
| 986 | ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 987 | #ifdef CONFIG_SYS_64BIT_LBA |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 988 | ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF); |
| 989 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF); |
Guennadi Liakhovetski | b71f1ca | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 990 | #else |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 991 | ide_outb(device, ATA_LBA_MID, 0); |
| 992 | ide_outb(device, ATA_LBA_HIGH, 0); |
Guennadi Liakhovetski | b71f1ca | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 993 | #endif |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 994 | } |
| 995 | #endif |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 996 | ide_outb(device, ATA_SECT_CNT, 1); |
| 997 | ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); |
| 998 | ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF); |
| 999 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1000 | |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1001 | #ifdef CONFIG_LBA48 |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1002 | if (lba48) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1003 | ide_outb(device, ATA_DEV_HD, |
| 1004 | ATA_LBA | ATA_DEVICE(device)); |
| 1005 | ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE_EXT); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1006 | |
| 1007 | } else |
| 1008 | #endif |
| 1009 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1010 | ide_outb(device, ATA_DEV_HD, ATA_LBA | |
| 1011 | ATA_DEVICE(device) | ((blknr >> 24) & 0xF)); |
| 1012 | ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE); |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1013 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1014 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1015 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1016 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1017 | /* can't take over 500 ms */ |
| 1018 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1019 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1020 | if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) != |
| 1021 | ATA_STAT_DRQ) { |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 1022 | printf("Error (no IRQ) dev %d blk %ld: status %#02x\n", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1023 | device, blknr, c); |
| 1024 | goto WR_OUT; |
| 1025 | } |
| 1026 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1027 | ide_output_data(device, buffer, ATA_SECTORWORDS); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1028 | c = ide_inb(device, ATA_STATUS); /* clear IRQ */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1029 | ++n; |
| 1030 | ++blknr; |
Greg Lopp | 50abf9f | 2007-04-13 08:02:24 +0200 | [diff] [blame] | 1031 | buffer += ATA_BLOCKSIZE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1032 | } |
| 1033 | WR_OUT: |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1034 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1035 | return (n); |
| 1036 | } |
| 1037 | |
| 1038 | /* ------------------------------------------------------------------------- */ |
| 1039 | |
| 1040 | /* |
| 1041 | * copy src to dest, skipping leading and trailing blanks and null |
| 1042 | * terminate the string |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1043 | * "len" is the size of available memory including the terminating '\0' |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1044 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1045 | static void ident_cpy(unsigned char *dst, unsigned char *src, |
| 1046 | unsigned int len) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1047 | { |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1048 | unsigned char *end, *last; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1049 | |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1050 | last = dst; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1051 | end = src + len - 1; |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1052 | |
| 1053 | /* reserve space for '\0' */ |
| 1054 | if (len < 2) |
| 1055 | goto OUT; |
wdenk | c12081a | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 1056 | |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1057 | /* skip leading white space */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1058 | while ((*src) && (src < end) && (*src == ' ')) |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1059 | ++src; |
| 1060 | |
| 1061 | /* copy string, omitting trailing white space */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1062 | while ((*src) && (src < end)) { |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1063 | *dst++ = *src; |
| 1064 | if (*src++ != ' ') |
| 1065 | last = dst; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1066 | } |
wdenk | 18bd81e | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1067 | OUT: |
| 1068 | *last = '\0'; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | /* ------------------------------------------------------------------------- */ |
| 1072 | |
| 1073 | /* |
| 1074 | * Wait until Busy bit is off, or timeout (in ms) |
| 1075 | * Return last status |
| 1076 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1077 | static uchar ide_wait(int dev, ulong t) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1078 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1079 | ulong delay = 10 * t; /* poll every 100 us */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1080 | uchar c; |
| 1081 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1082 | while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1083 | udelay(100); |
| 1084 | if (delay-- == 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1085 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1086 | } |
| 1087 | return (c); |
| 1088 | } |
| 1089 | |
| 1090 | /* ------------------------------------------------------------------------- */ |
| 1091 | |
| 1092 | #ifdef CONFIG_IDE_RESET |
| 1093 | extern void ide_set_reset(int idereset); |
| 1094 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1095 | static void ide_reset(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1096 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1097 | int i; |
| 1098 | |
| 1099 | curr_device = -1; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1100 | for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1101 | ide_bus_ok[i] = 0; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1102 | for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1103 | ide_dev_desc[i].type = DEV_TYPE_UNKNOWN; |
| 1104 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1105 | ide_set_reset(1); /* assert reset */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1106 | |
Martin Krause | 7e35caf | 2008-04-03 13:37:56 +0200 | [diff] [blame] | 1107 | /* the reset signal shall be asserted for et least 25 us */ |
| 1108 | udelay(25); |
| 1109 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1110 | WATCHDOG_RESET(); |
| 1111 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1112 | /* de-assert RESET signal */ |
| 1113 | ide_set_reset(0); |
| 1114 | |
| 1115 | /* wait 250 ms */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1116 | for (i = 0; i < 250; ++i) |
| 1117 | udelay(1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1120 | #endif /* CONFIG_IDE_RESET */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1121 | |
| 1122 | /* ------------------------------------------------------------------------- */ |
| 1123 | |
Heiko Schocher | ffb293a | 2009-09-23 07:56:08 +0200 | [diff] [blame] | 1124 | #if defined(CONFIG_OF_IDE_FIXUP) |
| 1125 | int ide_device_present(int dev) |
| 1126 | { |
| 1127 | if (dev >= CONFIG_SYS_IDE_MAXBUS) |
| 1128 | return 0; |
| 1129 | return (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1); |
| 1130 | } |
| 1131 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1132 | /* ------------------------------------------------------------------------- */ |
| 1133 | |
| 1134 | #ifdef CONFIG_ATAPI |
| 1135 | /**************************************************************************** |
| 1136 | * ATAPI Support |
| 1137 | */ |
| 1138 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1139 | void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts) |
| 1140 | __attribute__ ((weak, alias("__ide_input_data_shorts"))); |
| 1141 | |
| 1142 | void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts) |
| 1143 | __attribute__ ((weak, alias("__ide_output_data_shorts"))); |
| 1144 | |
| 1145 | |
Albert Aribaud | 036c6b4 | 2010-08-08 05:17:05 +0530 | [diff] [blame] | 1146 | #if defined(CONFIG_IDE_SWAP_IO) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1147 | /* since ATAPI may use commands with not 4 bytes alligned length |
| 1148 | * we have our own transfer functions, 2 bytes alligned */ |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1149 | void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1150 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1151 | ushort *dbuf; |
| 1152 | volatile ushort *pbuf; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1153 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1154 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 1155 | dbuf = (ushort *) sect_buf; |
wdenk | 634d2f7 | 2004-04-15 23:14:49 +0000 | [diff] [blame] | 1156 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1157 | debug("in output data shorts base for read is %lx\n", |
| 1158 | (unsigned long) pbuf); |
wdenk | 634d2f7 | 2004-04-15 23:14:49 +0000 | [diff] [blame] | 1159 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1160 | while (shorts--) { |
wdenk | 20c98a6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 1161 | EIEIO; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1162 | *pbuf = *dbuf++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1163 | } |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1166 | void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1167 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1168 | ushort *dbuf; |
| 1169 | volatile ushort *pbuf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1170 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1171 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 1172 | dbuf = (ushort *) sect_buf; |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1173 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1174 | debug("in input data shorts base for read is %lx\n", |
| 1175 | (unsigned long) pbuf); |
wdenk | f1276d4 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1176 | |
| 1177 | while (shorts--) { |
| 1178 | EIEIO; |
| 1179 | *dbuf++ = *pbuf; |
| 1180 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1183 | #else /* ! CONFIG_IDE_SWAP_IO */ |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1184 | void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1185 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1186 | outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1189 | void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1190 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1191 | insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts); |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1194 | #endif /* CONFIG_IDE_SWAP_IO */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1195 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1196 | /* |
| 1197 | * Wait until (Status & mask) == res, or timeout (in ms) |
| 1198 | * Return last status |
| 1199 | * This is used since some ATAPI CD ROMs clears their Busy Bit first |
| 1200 | * and then they set their DRQ Bit |
| 1201 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1202 | static uchar atapi_wait_mask(int dev, ulong t, uchar mask, uchar res) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1203 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1204 | ulong delay = 10 * t; /* poll every 100 us */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1205 | uchar c; |
| 1206 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1207 | /* prevents to read the status before valid */ |
| 1208 | c = ide_inb(dev, ATA_DEV_CTL); |
| 1209 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1210 | while (((c = ide_inb(dev, ATA_STATUS)) & mask) != res) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1211 | /* break if error occurs (doesn't make sense to wait more) */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1212 | if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1213 | break; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1214 | udelay(100); |
| 1215 | if (delay-- == 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1216 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1217 | } |
| 1218 | return (c); |
| 1219 | } |
| 1220 | |
| 1221 | /* |
| 1222 | * issue an atapi command |
| 1223 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1224 | unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen, |
| 1225 | unsigned char *buffer, int buflen) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1226 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1227 | unsigned char c, err, mask, res; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1228 | int n; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1229 | |
| 1230 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1231 | |
| 1232 | /* Select device |
| 1233 | */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1234 | mask = ATA_STAT_BUSY | ATA_STAT_DRQ; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1235 | res = 0; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1236 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 1237 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1238 | if ((c & mask) != res) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1239 | printf("ATAPI_ISSUE: device %d not ready status %X\n", device, |
| 1240 | c); |
| 1241 | err = 0xFF; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1242 | goto AI_OUT; |
| 1243 | } |
| 1244 | /* write taskfile */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1245 | ide_outb(device, ATA_ERROR_REG, 0); /* no DMA, no overlaped */ |
| 1246 | ide_outb(device, ATA_SECT_CNT, 0); |
| 1247 | ide_outb(device, ATA_SECT_NUM, 0); |
| 1248 | ide_outb(device, ATA_CYL_LOW, (unsigned char) (buflen & 0xFF)); |
| 1249 | ide_outb(device, ATA_CYL_HIGH, |
| 1250 | (unsigned char) ((buflen >> 8) & 0xFF)); |
| 1251 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1252 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1253 | ide_outb(device, ATA_COMMAND, ATAPI_CMD_PACKET); |
| 1254 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1255 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1256 | mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1257 | res = ATA_STAT_DRQ; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1258 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1259 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1260 | if ((c & mask) != res) { /* DRQ must be 1, BSY 0 */ |
| 1261 | printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d status 0x%02x\n", |
| 1262 | device, c); |
| 1263 | err = 0xFF; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1264 | goto AI_OUT; |
| 1265 | } |
| 1266 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1267 | /* write command block */ |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1268 | ide_output_data_shorts(device, (unsigned short *) ccb, ccblen / 2); |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1269 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1270 | /* ATAPI Command written wait for completition */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1271 | udelay(5000); /* device must set bsy */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1272 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1273 | mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR; |
| 1274 | /* |
| 1275 | * if no data wait for DRQ = 0 BSY = 0 |
| 1276 | * if data wait for DRQ = 1 BSY = 0 |
| 1277 | */ |
| 1278 | res = 0; |
| 1279 | if (buflen) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1280 | res = ATA_STAT_DRQ; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1281 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
| 1282 | if ((c & mask) != res) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1283 | if (c & ATA_STAT_ERR) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1284 | err = (ide_inb(device, ATA_ERROR_REG)) >> 4; |
| 1285 | debug("atapi_issue 1 returned sense key %X status %02X\n", |
| 1286 | err, c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1287 | } else { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1288 | printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x) status 0x%02x\n", |
| 1289 | ccb[0], c); |
| 1290 | err = 0xFF; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1291 | } |
| 1292 | goto AI_OUT; |
| 1293 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1294 | n = ide_inb(device, ATA_CYL_HIGH); |
| 1295 | n <<= 8; |
| 1296 | n += ide_inb(device, ATA_CYL_LOW); |
| 1297 | if (n > buflen) { |
| 1298 | printf("ERROR, transfer bytes %d requested only %d\n", n, |
| 1299 | buflen); |
| 1300 | err = 0xff; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1301 | goto AI_OUT; |
| 1302 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1303 | if ((n == 0) && (buflen < 0)) { |
| 1304 | printf("ERROR, transfer bytes %d requested %d\n", n, buflen); |
| 1305 | err = 0xff; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1306 | goto AI_OUT; |
| 1307 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1308 | if (n != buflen) { |
| 1309 | debug("WARNING, transfer bytes %d not equal with requested %d\n", |
| 1310 | n, buflen); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1311 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1312 | if (n != 0) { /* data transfer */ |
| 1313 | debug("ATAPI_ISSUE: %d Bytes to transfer\n", n); |
| 1314 | /* we transfer shorts */ |
| 1315 | n >>= 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1316 | /* ok now decide if it is an in or output */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1317 | if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) { |
| 1318 | debug("Write to device\n"); |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1319 | ide_output_data_shorts(device, |
| 1320 | (unsigned short *) buffer, n); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1321 | } else { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1322 | debug("Read from device @ %p shorts %d\n", buffer, n); |
Pavel Herrmann | 35ad9a8 | 2012-10-09 07:04:39 +0000 | [diff] [blame] | 1323 | ide_input_data_shorts(device, |
| 1324 | (unsigned short *) buffer, n); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1325 | } |
| 1326 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1327 | udelay(5000); /* seems that some CD ROMs need this... */ |
| 1328 | mask = ATA_STAT_BUSY | ATA_STAT_ERR; |
| 1329 | res = 0; |
| 1330 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1331 | if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1332 | err = (ide_inb(device, ATA_ERROR_REG) >> 4); |
| 1333 | debug("atapi_issue 2 returned sense key %X status %X\n", err, |
| 1334 | c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1335 | } else { |
| 1336 | err = 0; |
| 1337 | } |
| 1338 | AI_OUT: |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1339 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1340 | return (err); |
| 1341 | } |
| 1342 | |
| 1343 | /* |
| 1344 | * sending the command to atapi_issue. If an status other than good |
| 1345 | * returns, an request_sense will be issued |
| 1346 | */ |
| 1347 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1348 | #define ATAPI_DRIVE_NOT_READY 100 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1349 | #define ATAPI_UNIT_ATTN 10 |
| 1350 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1351 | unsigned char atapi_issue_autoreq(int device, |
| 1352 | unsigned char *ccb, |
| 1353 | int ccblen, |
| 1354 | unsigned char *buffer, int buflen) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1355 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1356 | unsigned char sense_data[18], sense_ccb[12]; |
| 1357 | unsigned char res, key, asc, ascq; |
| 1358 | int notready, unitattn; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1359 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1360 | unitattn = ATAPI_UNIT_ATTN; |
| 1361 | notready = ATAPI_DRIVE_NOT_READY; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1362 | |
| 1363 | retry: |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1364 | res = atapi_issue(device, ccb, ccblen, buffer, buflen); |
| 1365 | if (res == 0) |
| 1366 | return 0; /* Ok */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1367 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1368 | if (res == 0xFF) |
| 1369 | return 0xFF; /* error */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1370 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1371 | debug("(auto_req)atapi_issue returned sense key %X\n", res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1372 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1373 | memset(sense_ccb, 0, sizeof(sense_ccb)); |
| 1374 | memset(sense_data, 0, sizeof(sense_data)); |
| 1375 | sense_ccb[0] = ATAPI_CMD_REQ_SENSE; |
| 1376 | sense_ccb[4] = 18; /* allocation Length */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1377 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1378 | res = atapi_issue(device, sense_ccb, 12, sense_data, 18); |
| 1379 | key = (sense_data[2] & 0xF); |
| 1380 | asc = (sense_data[12]); |
| 1381 | ascq = (sense_data[13]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1382 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1383 | debug("ATAPI_CMD_REQ_SENSE returned %x\n", res); |
| 1384 | debug(" Sense page: %02X key %02X ASC %02X ASCQ %02X\n", |
| 1385 | sense_data[0], key, asc, ascq); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1386 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1387 | if ((key == 0)) |
| 1388 | return 0; /* ok device ready */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1389 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1390 | if ((key == 6) || (asc == 0x29) || (asc == 0x28)) { /* Unit Attention */ |
| 1391 | if (unitattn-- > 0) { |
| 1392 | udelay(200 * 1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1393 | goto retry; |
| 1394 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1395 | printf("Unit Attention, tried %d\n", ATAPI_UNIT_ATTN); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1396 | goto error; |
| 1397 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1398 | if ((asc == 0x4) && (ascq == 0x1)) { |
| 1399 | /* not ready, but will be ready soon */ |
| 1400 | if (notready-- > 0) { |
| 1401 | udelay(200 * 1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1402 | goto retry; |
| 1403 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1404 | printf("Drive not ready, tried %d times\n", |
| 1405 | ATAPI_DRIVE_NOT_READY); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1406 | goto error; |
| 1407 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1408 | if (asc == 0x3a) { |
| 1409 | debug("Media not present\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1410 | goto error; |
| 1411 | } |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 1412 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1413 | printf("ERROR: Unknown Sense key %02X ASC %02X ASCQ %02X\n", key, asc, |
| 1414 | ascq); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1415 | error: |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1416 | debug("ERROR Sense key %02X ASC %02X ASCQ %02X\n", key, asc, ascq); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1417 | return (0xFF); |
| 1418 | } |
| 1419 | |
| 1420 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1421 | static void atapi_inquiry(block_dev_desc_t *dev_desc) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1422 | { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1423 | unsigned char ccb[12]; /* Command descriptor block */ |
| 1424 | unsigned char iobuf[64]; /* temp buf */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1425 | unsigned char c; |
| 1426 | int device; |
| 1427 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1428 | device = dev_desc->dev; |
| 1429 | dev_desc->type = DEV_TYPE_UNKNOWN; /* not yet valid */ |
| 1430 | dev_desc->block_read = atapi_read; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1431 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1432 | memset(ccb, 0, sizeof(ccb)); |
| 1433 | memset(iobuf, 0, sizeof(iobuf)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1434 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1435 | ccb[0] = ATAPI_CMD_INQUIRY; |
| 1436 | ccb[4] = 40; /* allocation Legnth */ |
| 1437 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 40); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1438 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1439 | debug("ATAPI_CMD_INQUIRY returned %x\n", c); |
| 1440 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1441 | return; |
| 1442 | |
| 1443 | /* copy device ident strings */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1444 | ident_cpy((unsigned char *) dev_desc->vendor, &iobuf[8], 8); |
| 1445 | ident_cpy((unsigned char *) dev_desc->product, &iobuf[16], 16); |
| 1446 | ident_cpy((unsigned char *) dev_desc->revision, &iobuf[32], 5); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1447 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1448 | dev_desc->lun = 0; |
| 1449 | dev_desc->lba = 0; |
| 1450 | dev_desc->blksz = 0; |
| 1451 | dev_desc->type = iobuf[0] & 0x1f; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1452 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1453 | if ((iobuf[1] & 0x80) == 0x80) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1454 | dev_desc->removable = 1; |
| 1455 | else |
| 1456 | dev_desc->removable = 0; |
| 1457 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1458 | memset(ccb, 0, sizeof(ccb)); |
| 1459 | memset(iobuf, 0, sizeof(iobuf)); |
| 1460 | ccb[0] = ATAPI_CMD_START_STOP; |
| 1461 | ccb[4] = 0x03; /* start */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1462 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1463 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1464 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1465 | debug("ATAPI_CMD_START_STOP returned %x\n", c); |
| 1466 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1467 | return; |
| 1468 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1469 | memset(ccb, 0, sizeof(ccb)); |
| 1470 | memset(iobuf, 0, sizeof(iobuf)); |
| 1471 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1472 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1473 | debug("ATAPI_CMD_UNIT_TEST_READY returned %x\n", c); |
| 1474 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1475 | return; |
| 1476 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1477 | memset(ccb, 0, sizeof(ccb)); |
| 1478 | memset(iobuf, 0, sizeof(iobuf)); |
| 1479 | ccb[0] = ATAPI_CMD_READ_CAP; |
| 1480 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 8); |
| 1481 | debug("ATAPI_CMD_READ_CAP returned %x\n", c); |
| 1482 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1483 | return; |
| 1484 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1485 | debug("Read Cap: LBA %02X%02X%02X%02X blksize %02X%02X%02X%02X\n", |
| 1486 | iobuf[0], iobuf[1], iobuf[2], iobuf[3], |
| 1487 | iobuf[4], iobuf[5], iobuf[6], iobuf[7]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1488 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1489 | dev_desc->lba = ((unsigned long) iobuf[0] << 24) + |
| 1490 | ((unsigned long) iobuf[1] << 16) + |
| 1491 | ((unsigned long) iobuf[2] << 8) + ((unsigned long) iobuf[3]); |
| 1492 | dev_desc->blksz = ((unsigned long) iobuf[4] << 24) + |
| 1493 | ((unsigned long) iobuf[5] << 16) + |
| 1494 | ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]); |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1495 | #ifdef CONFIG_LBA48 |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1496 | /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */ |
| 1497 | dev_desc->lba48 = 0; |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1498 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1499 | return; |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | /* |
| 1504 | * atapi_read: |
| 1505 | * we transfer only one block per command, since the multiple DRQ per |
| 1506 | * command is not yet implemented |
| 1507 | */ |
| 1508 | #define ATAPI_READ_MAX_BYTES 2048 /* we read max 2kbytes */ |
| 1509 | #define ATAPI_READ_BLOCK_SIZE 2048 /* assuming CD part */ |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1510 | #define ATAPI_READ_MAX_BLOCK (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1511 | |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 1512 | ulong atapi_read(int device, ulong blknr, lbaint_t blkcnt, void *buffer) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1513 | { |
| 1514 | ulong n = 0; |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1515 | unsigned char ccb[12]; /* Command descriptor block */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1516 | ulong cnt; |
| 1517 | |
Simon Glass | 11926fb | 2012-10-29 05:24:04 +0000 | [diff] [blame^] | 1518 | debug("atapi_read dev %d start %lX, blocks " LBAF " buffer at %lX\n", |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1519 | device, blknr, blkcnt, (ulong) buffer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1520 | |
| 1521 | do { |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1522 | if (blkcnt > ATAPI_READ_MAX_BLOCK) |
| 1523 | cnt = ATAPI_READ_MAX_BLOCK; |
| 1524 | else |
| 1525 | cnt = blkcnt; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1526 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1527 | ccb[0] = ATAPI_CMD_READ_12; |
| 1528 | ccb[1] = 0; /* reserved */ |
| 1529 | ccb[2] = (unsigned char) (blknr >> 24) & 0xFF; /* MSB Block */ |
| 1530 | ccb[3] = (unsigned char) (blknr >> 16) & 0xFF; /* */ |
| 1531 | ccb[4] = (unsigned char) (blknr >> 8) & 0xFF; |
| 1532 | ccb[5] = (unsigned char) blknr & 0xFF; /* LSB Block */ |
| 1533 | ccb[6] = (unsigned char) (cnt >> 24) & 0xFF; /* MSB Block cnt */ |
| 1534 | ccb[7] = (unsigned char) (cnt >> 16) & 0xFF; |
| 1535 | ccb[8] = (unsigned char) (cnt >> 8) & 0xFF; |
| 1536 | ccb[9] = (unsigned char) cnt & 0xFF; /* LSB Block */ |
| 1537 | ccb[10] = 0; /* reserved */ |
| 1538 | ccb[11] = 0; /* reserved */ |
| 1539 | |
| 1540 | if (atapi_issue_autoreq(device, ccb, 12, |
| 1541 | (unsigned char *) buffer, |
| 1542 | cnt * ATAPI_READ_BLOCK_SIZE) |
| 1543 | == 0xFF) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1544 | return (n); |
| 1545 | } |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1546 | n += cnt; |
| 1547 | blkcnt -= cnt; |
| 1548 | blknr += cnt; |
| 1549 | buffer += (cnt * ATAPI_READ_BLOCK_SIZE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1550 | } while (blkcnt > 0); |
| 1551 | return (n); |
| 1552 | } |
| 1553 | |
| 1554 | /* ------------------------------------------------------------------------- */ |
| 1555 | |
| 1556 | #endif /* CONFIG_ATAPI */ |
| 1557 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1558 | U_BOOT_CMD(ide, 5, 1, do_ide, |
| 1559 | "IDE sub-system", |
| 1560 | "reset - reset IDE controller\n" |
| 1561 | "ide info - show available IDE devices\n" |
| 1562 | "ide device [dev] - show or set current device\n" |
| 1563 | "ide part [dev] - print partition table of one or all IDE devices\n" |
| 1564 | "ide read addr blk# cnt\n" |
| 1565 | "ide write addr blk# cnt - read/write `cnt'" |
| 1566 | " blocks starting at block `blk#'\n" |
| 1567 | " to/from memory address `addr'"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1568 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1569 | U_BOOT_CMD(diskboot, 3, 1, do_diskboot, |
| 1570 | "boot from IDE device", "loadAddr dev:part"); |