wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
Wolfgang Denk | 34c202c | 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 | 113bfe4 | 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 | f98984c | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 35 | #include <asm/io.h> |
Grant Likely | 735dd97 | 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 | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 40 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | #ifdef CONFIG_8xx |
| 42 | # include <mpc8xx.h> |
| 43 | #endif |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 44 | |
wdenk | 132ba5f | 2004-02-27 08:20:54 +0000 | [diff] [blame] | 45 | #ifdef CONFIG_MPC5xxx |
| 46 | #include <mpc5xxx.h> |
| 47 | #endif |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 48 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | #include <ide.h> |
| 50 | #include <ata.h> |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 51 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_STATUS_LED |
| 53 | # include <status_led.h> |
| 54 | #endif |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 55 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 56 | #ifdef CONFIG_IDE_8xx_DIRECT |
| 57 | DECLARE_GLOBAL_DATA_PTR; |
| 58 | #endif |
| 59 | |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 60 | #ifdef __PPC__ |
| 61 | # define EIEIO __asm__ volatile ("eieio") |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 62 | # define SYNC __asm__ volatile ("sync") |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 63 | #else |
| 64 | # define EIEIO /* nothing */ |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 65 | # define SYNC /* nothing */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
wdenk | 15647dc | 2003-10-09 19:00:25 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_IDE_8xx_DIRECT |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | /* Timings for IDE Interface |
| 70 | * |
| 71 | * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk |
| 72 | * 70 165 30 PIO-Mode 0, [ns] |
| 73 | * 4 9 2 [Cycles] |
| 74 | * 50 125 20 PIO-Mode 1, [ns] |
| 75 | * 3 7 2 [Cycles] |
| 76 | * 30 100 15 PIO-Mode 2, [ns] |
| 77 | * 2 6 1 [Cycles] |
| 78 | * 30 80 10 PIO-Mode 3, [ns] |
| 79 | * 2 5 1 [Cycles] |
| 80 | * 25 70 10 PIO-Mode 4, [ns] |
| 81 | * 2 4 1 [Cycles] |
| 82 | */ |
| 83 | |
| 84 | const static pio_config_t pio_config_ns [IDE_MAX_PIO_MODE+1] = |
| 85 | { |
| 86 | /* Setup Length Hold */ |
| 87 | { 70, 165, 30 }, /* PIO-Mode 0, [ns] */ |
| 88 | { 50, 125, 20 }, /* PIO-Mode 1, [ns] */ |
| 89 | { 30, 101, 15 }, /* PIO-Mode 2, [ns] */ |
| 90 | { 30, 80, 10 }, /* PIO-Mode 3, [ns] */ |
| 91 | { 25, 70, 10 }, /* PIO-Mode 4, [ns] */ |
| 92 | }; |
| 93 | |
| 94 | static pio_config_t pio_config_clk [IDE_MAX_PIO_MODE+1]; |
| 95 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 96 | #ifndef CONFIG_SYS_PIO_MODE |
| 97 | #define CONFIG_SYS_PIO_MODE 0 /* use a relaxed default */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | static int pio_mode = CONFIG_SYS_PIO_MODE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 100 | |
| 101 | /* Make clock cycles and always round up */ |
| 102 | |
| 103 | #define PCMCIA_MK_CLKS( t, T ) (( (t) * (T) + 999U ) / 1000U ) |
| 104 | |
wdenk | 15647dc | 2003-10-09 19:00:25 +0000 | [diff] [blame] | 105 | #endif /* CONFIG_IDE_8xx_DIRECT */ |
| 106 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | /* ------------------------------------------------------------------------- */ |
| 108 | |
| 109 | /* Current I/O Device */ |
| 110 | static int curr_device = -1; |
| 111 | |
| 112 | /* Current offset for IDE0 / IDE1 bus access */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS] = { |
| 114 | #if defined(CONFIG_SYS_ATA_IDE0_OFFSET) |
| 115 | CONFIG_SYS_ATA_IDE0_OFFSET, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | #if defined(CONFIG_SYS_ATA_IDE1_OFFSET) && (CONFIG_SYS_IDE_MAXBUS > 1) |
| 118 | CONFIG_SYS_ATA_IDE1_OFFSET, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 119 | #endif |
| 120 | }; |
| 121 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 123 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 124 | block_dev_desc_t ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE]; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 125 | /* ------------------------------------------------------------------------- */ |
| 126 | |
| 127 | #ifdef CONFIG_IDE_LED |
Wolfgang Denk | 953b7e6 | 2010-06-13 18:28:54 +0200 | [diff] [blame] | 128 | # if !defined(CONFIG_BMS2003) && \ |
| 129 | !defined(CONFIG_CPC45) && \ |
| 130 | !defined(CONFIG_KUP4K) && \ |
| 131 | !defined(CONFIG_KUP4X) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 132 | static void ide_led (uchar led, uchar status); |
| 133 | #else |
wdenk | 1f53a41 | 2002-12-04 23:39:58 +0000 | [diff] [blame] | 134 | extern void ide_led (uchar led, uchar status); |
| 135 | #endif |
| 136 | #else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | #define ide_led(a,b) /* dummy */ |
| 138 | #endif |
| 139 | |
| 140 | #ifdef CONFIG_IDE_RESET |
| 141 | static void ide_reset (void); |
| 142 | #else |
| 143 | #define ide_reset() /* dummy */ |
| 144 | #endif |
| 145 | |
| 146 | static void ide_ident (block_dev_desc_t *dev_desc); |
| 147 | static uchar ide_wait (int dev, ulong t); |
| 148 | |
| 149 | #define IDE_TIME_OUT 2000 /* 2 sec timeout */ |
| 150 | |
| 151 | #define ATAPI_TIME_OUT 7000 /* 7 sec timeout (5 sec seems to work...) */ |
| 152 | |
| 153 | #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */ |
| 154 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 155 | static void input_data(int dev, ulong *sect_buf, int words); |
Wolfgang Denk | 96d04c3 | 2011-04-30 23:29:55 +0200 | [diff] [blame] | 156 | static void output_data(int dev, const ulong *sect_buf, int words); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 157 | static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len); |
| 158 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 159 | #ifndef CONFIG_SYS_ATA_PORT_ADDR |
| 160 | #define CONFIG_SYS_ATA_PORT_ADDR(port) (port) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 161 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | |
| 163 | #ifdef CONFIG_ATAPI |
| 164 | static void atapi_inquiry(block_dev_desc_t *dev_desc); |
Grant Likely | eb867a7 | 2007-02-20 09:05:45 +0100 | [diff] [blame] | 165 | ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 166 | #endif |
| 167 | |
| 168 | |
| 169 | #ifdef CONFIG_IDE_8xx_DIRECT |
| 170 | static void set_pcmcia_timing (int pmode); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 171 | #endif |
| 172 | |
| 173 | /* ------------------------------------------------------------------------- */ |
| 174 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 175 | 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] | 176 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 177 | int rcode = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 178 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 179 | switch (argc) { |
| 180 | case 0: |
| 181 | case 1: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 182 | return CMD_RET_USAGE; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 183 | case 2: |
| 184 | if (strncmp(argv[1], "res", 3) == 0) { |
| 185 | puts("\nReset IDE" |
| 186 | #ifdef CONFIG_IDE_8xx_DIRECT |
| 187 | " on PCMCIA " PCMCIA_SLOT_MSG |
| 188 | #endif |
| 189 | ": "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 190 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 191 | ide_init(); |
| 192 | return 0; |
| 193 | } else if (strncmp(argv[1], "inf", 3) == 0) { |
| 194 | int i; |
| 195 | |
| 196 | putc('\n'); |
| 197 | |
| 198 | for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) { |
| 199 | if (ide_dev_desc[i].type == DEV_TYPE_UNKNOWN) |
| 200 | continue; /* list only known devices */ |
| 201 | printf("IDE device %d: ", i); |
| 202 | dev_print(&ide_dev_desc[i]); |
| 203 | } |
| 204 | return 0; |
| 205 | |
| 206 | } else if (strncmp(argv[1], "dev", 3) == 0) { |
| 207 | if ((curr_device < 0) |
| 208 | || (curr_device >= CONFIG_SYS_IDE_MAXDEVICE)) { |
| 209 | puts("\nno IDE devices available\n"); |
| 210 | return 1; |
| 211 | } |
| 212 | printf("\nIDE device %d: ", curr_device); |
| 213 | dev_print(&ide_dev_desc[curr_device]); |
| 214 | return 0; |
| 215 | } else if (strncmp(argv[1], "part", 4) == 0) { |
| 216 | int dev, ok; |
| 217 | |
| 218 | for (ok = 0, dev = 0; |
| 219 | dev < CONFIG_SYS_IDE_MAXDEVICE; |
| 220 | ++dev) { |
| 221 | if (ide_dev_desc[dev].part_type != |
| 222 | PART_TYPE_UNKNOWN) { |
| 223 | ++ok; |
| 224 | if (dev) |
| 225 | putc('\n'); |
| 226 | print_part(&ide_dev_desc[dev]); |
| 227 | } |
| 228 | } |
| 229 | if (!ok) { |
| 230 | puts("\nno IDE devices available\n"); |
| 231 | rcode++; |
| 232 | } |
| 233 | return rcode; |
| 234 | } |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 235 | return CMD_RET_USAGE; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 236 | case 3: |
| 237 | if (strncmp(argv[1], "dev", 3) == 0) { |
| 238 | int dev = (int) simple_strtoul(argv[2], NULL, 10); |
| 239 | |
| 240 | printf("\nIDE device %d: ", dev); |
| 241 | if (dev >= CONFIG_SYS_IDE_MAXDEVICE) { |
| 242 | puts("unknown device\n"); |
| 243 | return 1; |
| 244 | } |
| 245 | dev_print(&ide_dev_desc[dev]); |
| 246 | /*ide_print (dev); */ |
| 247 | |
| 248 | if (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN) |
| 249 | return 1; |
| 250 | |
| 251 | curr_device = dev; |
| 252 | |
| 253 | puts("... is now current device\n"); |
| 254 | |
| 255 | return 0; |
| 256 | } else if (strncmp(argv[1], "part", 4) == 0) { |
| 257 | int dev = (int) simple_strtoul(argv[2], NULL, 10); |
| 258 | |
| 259 | if (ide_dev_desc[dev].part_type != PART_TYPE_UNKNOWN) { |
| 260 | print_part(&ide_dev_desc[dev]); |
| 261 | } else { |
| 262 | printf("\nIDE device %d not available\n", |
| 263 | dev); |
| 264 | rcode = 1; |
| 265 | } |
| 266 | return rcode; |
| 267 | } |
| 268 | |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 269 | return CMD_RET_USAGE; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 270 | default: |
| 271 | /* at least 4 args */ |
| 272 | |
| 273 | if (strcmp(argv[1], "read") == 0) { |
| 274 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 275 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 276 | ulong n; |
| 277 | |
| 278 | #ifdef CONFIG_SYS_64BIT_LBA |
| 279 | lbaint_t blk = simple_strtoull(argv[3], NULL, 16); |
| 280 | |
| 281 | printf("\nIDE read: device %d block # %lld, count %ld ... ", |
| 282 | curr_device, blk, cnt); |
| 283 | #else |
| 284 | lbaint_t blk = simple_strtoul(argv[3], NULL, 16); |
| 285 | |
| 286 | printf("\nIDE read: device %d block # %ld, count %ld ... ", |
| 287 | curr_device, blk, cnt); |
| 288 | #endif |
| 289 | |
| 290 | n = ide_dev_desc[curr_device].block_read(curr_device, |
| 291 | blk, cnt, |
| 292 | (ulong *)addr); |
| 293 | /* flush cache after read */ |
| 294 | flush_cache(addr, |
| 295 | cnt * ide_dev_desc[curr_device].blksz); |
| 296 | |
| 297 | printf("%ld blocks read: %s\n", |
| 298 | n, (n == cnt) ? "OK" : "ERROR"); |
| 299 | if (n == cnt) |
| 300 | return 0; |
| 301 | else |
| 302 | return 1; |
| 303 | } else if (strcmp(argv[1], "write") == 0) { |
| 304 | ulong addr = simple_strtoul(argv[2], NULL, 16); |
| 305 | ulong cnt = simple_strtoul(argv[4], NULL, 16); |
| 306 | ulong n; |
| 307 | |
| 308 | #ifdef CONFIG_SYS_64BIT_LBA |
| 309 | lbaint_t blk = simple_strtoull(argv[3], NULL, 16); |
| 310 | |
| 311 | printf("\nIDE write: device %d block # %lld, count %ld ... ", |
| 312 | curr_device, blk, cnt); |
| 313 | #else |
| 314 | lbaint_t blk = simple_strtoul(argv[3], NULL, 16); |
| 315 | |
| 316 | printf("\nIDE write: device %d block # %ld, count %ld ... ", |
| 317 | curr_device, blk, cnt); |
| 318 | #endif |
| 319 | n = ide_write(curr_device, blk, cnt, (ulong *) addr); |
| 320 | |
| 321 | printf("%ld blocks written: %s\n", |
| 322 | n, (n == cnt) ? "OK" : "ERROR"); |
| 323 | if (n == cnt) |
| 324 | return 0; |
| 325 | else |
| 326 | return 1; |
| 327 | } else { |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 328 | return CMD_RET_USAGE; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | return rcode; |
| 332 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 335 | 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] | 336 | { |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame^] | 337 | return common_diskboot(cmdtp, "ide", argc, argv); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /* ------------------------------------------------------------------------- */ |
| 341 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 342 | inline void __ide_outb(int dev, int port, unsigned char val) |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 343 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 344 | debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n", |
| 345 | dev, port, val, |
| 346 | (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port))); |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 347 | |
| 348 | #if defined(CONFIG_IDE_AHB) |
| 349 | if (port) { |
| 350 | /* write command */ |
| 351 | ide_write_register(dev, port, val); |
| 352 | } else { |
| 353 | /* write data */ |
| 354 | outb(val, (ATA_CURR_BASE(dev))); |
| 355 | } |
| 356 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 357 | outb(val, (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port))); |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 358 | #endif |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 359 | } |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 360 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 361 | void ide_outb(int dev, int port, unsigned char val) |
| 362 | __attribute__ ((weak, alias("__ide_outb"))); |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 363 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 364 | inline unsigned char __ide_inb(int dev, int port) |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 365 | { |
| 366 | uchar val; |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 367 | |
| 368 | #if defined(CONFIG_IDE_AHB) |
| 369 | val = ide_read_register(dev, port); |
| 370 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 371 | val = inb((ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port))); |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 372 | #endif |
| 373 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 374 | debug("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n", |
| 375 | dev, port, |
| 376 | (ATA_CURR_BASE(dev) + CONFIG_SYS_ATA_PORT_ADDR(port)), val); |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 377 | return val; |
| 378 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 379 | |
Kim Phillips | 2df72b8 | 2009-05-19 12:53:36 -0500 | [diff] [blame] | 380 | unsigned char ide_inb(int dev, int port) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 381 | __attribute__ ((weak, alias("__ide_inb"))); |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 382 | |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 383 | #ifdef CONFIG_TUNE_PIO |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 384 | inline int __ide_set_piomode(int pio_mode) |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 385 | { |
| 386 | return 0; |
| 387 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 388 | |
| 389 | inline int ide_set_piomode(int pio_mode) |
| 390 | __attribute__ ((weak, alias("__ide_set_piomode"))); |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 391 | #endif |
| 392 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 393 | void ide_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 394 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 395 | |
| 396 | #ifdef CONFIG_IDE_8xx_DIRECT |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 397 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 398 | volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia); |
| 399 | #endif |
| 400 | unsigned char c; |
| 401 | int i, bus; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 402 | |
Wolfgang Denk | 953b7e6 | 2010-06-13 18:28:54 +0200 | [diff] [blame] | 403 | #if defined(CONFIG_SC3) |
Wolfgang Denk | 9045f33 | 2007-06-08 10:24:58 +0200 | [diff] [blame] | 404 | unsigned int ata_reset_time = ATA_RESET_TIME; |
Wolfgang Denk | 51056dd | 2007-04-11 17:22:55 +0200 | [diff] [blame] | 405 | #endif |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 406 | #ifdef CONFIG_IDE_8xx_PCCARD |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 407 | extern int pcmcia_on(void); |
| 408 | extern int ide_devices_found; /* Initialized in check_ide_device() */ |
| 409 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 410 | |
| 411 | #ifdef CONFIG_IDE_PREINIT |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 412 | extern int ide_preinit(void); |
| 413 | |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 414 | WATCHDOG_RESET(); |
| 415 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 416 | if (ide_preinit()) { |
| 417 | puts("ide_preinit failed\n"); |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 418 | return; |
| 419 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 420 | #endif /* CONFIG_IDE_PREINIT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 421 | |
| 422 | #ifdef CONFIG_IDE_8xx_PCCARD |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 423 | extern int pcmcia_on(void); |
| 424 | extern int ide_devices_found; /* Initialized in check_ide_device() */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 425 | |
| 426 | WATCHDOG_RESET(); |
| 427 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 428 | ide_devices_found = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 429 | /* initialize the PCMCIA IDE adapter card */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 430 | pcmcia_on(); |
| 431 | if (!ide_devices_found) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 432 | return; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 433 | udelay(1000000); /* 1 s */ |
| 434 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 435 | |
| 436 | WATCHDOG_RESET(); |
| 437 | |
wdenk | 15647dc | 2003-10-09 19:00:25 +0000 | [diff] [blame] | 438 | #ifdef CONFIG_IDE_8xx_DIRECT |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 439 | /* Initialize PIO timing tables */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 440 | for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) { |
| 441 | pio_config_clk[i].t_setup = |
| 442 | PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk); |
| 443 | pio_config_clk[i].t_length = |
| 444 | PCMCIA_MK_CLKS(pio_config_ns[i].t_length, |
| 445 | gd->bus_clk); |
| 446 | pio_config_clk[i].t_hold = |
| 447 | PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk); |
| 448 | debug("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk" |
| 449 | " hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup, |
| 450 | pio_config_clk[i].t_setup, pio_config_ns[i].t_length, |
| 451 | pio_config_clk[i].t_length, pio_config_ns[i].t_hold, |
| 452 | pio_config_clk[i].t_hold); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 453 | } |
wdenk | 15647dc | 2003-10-09 19:00:25 +0000 | [diff] [blame] | 454 | #endif /* CONFIG_IDE_8xx_DIRECT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 455 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 456 | /* |
| 457 | * Reset the IDE just to be sure. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 458 | * Light LED's to show |
| 459 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 460 | ide_led((LED_IDE1 | LED_IDE2), 1); /* LED's on */ |
| 461 | |
| 462 | /* ATAPI Drives seems to need a proper IDE Reset */ |
| 463 | ide_reset(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 464 | |
| 465 | #ifdef CONFIG_IDE_8xx_DIRECT |
| 466 | /* PCMCIA / IDE initialization for common mem space */ |
| 467 | pcmp->pcmc_pgcrb = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 468 | |
| 469 | /* start in PIO mode 0 - most relaxed timings */ |
| 470 | pio_mode = 0; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 471 | set_pcmcia_timing(pio_mode); |
wdenk | 15647dc | 2003-10-09 19:00:25 +0000 | [diff] [blame] | 472 | #endif /* CONFIG_IDE_8xx_DIRECT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 473 | |
| 474 | /* |
| 475 | * Wait for IDE to get ready. |
| 476 | * According to spec, this can take up to 31 seconds! |
| 477 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 478 | for (bus = 0; bus < CONFIG_SYS_IDE_MAXBUS; ++bus) { |
| 479 | int dev = |
| 480 | bus * (CONFIG_SYS_IDE_MAXDEVICE / |
| 481 | CONFIG_SYS_IDE_MAXBUS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 482 | |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 483 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 484 | /* Skip non-ide devices from probing */ |
| 485 | if ((ide_devices_found & (1 << bus)) == 0) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 486 | ide_led((LED_IDE1 | LED_IDE2), 0); /* LED's off */ |
wdenk | 6069ff2 | 2003-02-28 00:49:47 +0000 | [diff] [blame] | 487 | continue; |
| 488 | } |
| 489 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 490 | printf("Bus %d: ", bus); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 491 | |
| 492 | ide_bus_ok[bus] = 0; |
| 493 | |
| 494 | /* Select device |
| 495 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 496 | udelay(100000); /* 100 ms */ |
| 497 | ide_outb(dev, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(dev)); |
| 498 | udelay(100000); /* 100 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 499 | i = 0; |
| 500 | do { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 501 | udelay(10000); /* 10 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 502 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 503 | c = ide_inb(dev, ATA_STATUS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 504 | i++; |
Wolfgang Denk | 953b7e6 | 2010-06-13 18:28:54 +0200 | [diff] [blame] | 505 | #if defined(CONFIG_SC3) |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 506 | if (i > (ata_reset_time * 100)) { |
| 507 | #else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 508 | if (i > (ATA_RESET_TIME * 100)) { |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 509 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 510 | puts("** Timeout **\n"); |
| 511 | /* LED's off */ |
| 512 | ide_led((LED_IDE1 | LED_IDE2), 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 513 | return; |
| 514 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 515 | if ((i >= 100) && ((i % 100) == 0)) |
| 516 | putc('.'); |
| 517 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 518 | } while (c & ATA_STAT_BUSY); |
| 519 | |
| 520 | if (c & (ATA_STAT_BUSY | ATA_STAT_FAULT)) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 521 | puts("not available "); |
| 522 | debug("Status = 0x%02X ", c); |
| 523 | #ifndef CONFIG_ATAPI /* ATAPI Devices do not set DRDY */ |
| 524 | } else if ((c & ATA_STAT_READY) == 0) { |
| 525 | puts("not available "); |
| 526 | debug("Status = 0x%02X ", c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 527 | #endif |
| 528 | } else { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 529 | puts("OK "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 530 | ide_bus_ok[bus] = 1; |
| 531 | } |
| 532 | WATCHDOG_RESET(); |
| 533 | } |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 534 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 535 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 536 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 537 | ide_led((LED_IDE1 | LED_IDE2), 0); /* LED's off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 538 | |
| 539 | curr_device = -1; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 540 | for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 541 | #ifdef CONFIG_IDE_LED |
| 542 | int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2; |
| 543 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 544 | ide_dev_desc[i].type = DEV_TYPE_UNKNOWN; |
| 545 | ide_dev_desc[i].if_type = IF_TYPE_IDE; |
| 546 | ide_dev_desc[i].dev = i; |
| 547 | ide_dev_desc[i].part_type = PART_TYPE_UNKNOWN; |
| 548 | ide_dev_desc[i].blksz = 0; |
| 549 | ide_dev_desc[i].lba = 0; |
| 550 | ide_dev_desc[i].block_read = ide_read; |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 551 | ide_dev_desc[i].block_write = ide_write; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 552 | if (!ide_bus_ok[IDE_BUS(i)]) |
| 553 | continue; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 554 | ide_led(led, 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 555 | ide_ident(&ide_dev_desc[i]); |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 556 | ide_led(led, 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 557 | dev_print(&ide_dev_desc[i]); |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 558 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 559 | if ((ide_dev_desc[i].lba > 0) && (ide_dev_desc[i].blksz > 0)) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 560 | /* initialize partition type */ |
| 561 | init_part(&ide_dev_desc[i]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 562 | if (curr_device < 0) |
| 563 | curr_device = i; |
| 564 | } |
| 565 | } |
| 566 | WATCHDOG_RESET(); |
| 567 | } |
| 568 | |
| 569 | /* ------------------------------------------------------------------------- */ |
| 570 | |
Matthew McClintock | df3fc52 | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 571 | #ifdef CONFIG_PARTITIONS |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 572 | block_dev_desc_t *ide_get_dev(int dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 573 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 574 | return (dev < CONFIG_SYS_IDE_MAXDEVICE) ? &ide_dev_desc[dev] : NULL; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 575 | } |
Matthew McClintock | df3fc52 | 2011-05-24 05:31:19 +0000 | [diff] [blame] | 576 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 577 | |
| 578 | |
| 579 | #ifdef CONFIG_IDE_8xx_DIRECT |
| 580 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 581 | static void set_pcmcia_timing(int pmode) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 582 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 583 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 584 | volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia); |
| 585 | ulong timings; |
| 586 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 587 | debug("Set timing for PIO Mode %d\n", pmode); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 588 | |
| 589 | timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold) |
| 590 | | PCMCIA_SST(pio_config_clk[pmode].t_setup) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 591 | | PCMCIA_SL(pio_config_clk[pmode].t_length); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 592 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 593 | /* |
| 594 | * IDE 0 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 595 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 596 | pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0; |
| 597 | pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 |
| 598 | #if (CONFIG_SYS_PCMCIA_POR0 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 599 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 600 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 601 | ; |
| 602 | debug("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 603 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 604 | pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1; |
| 605 | pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 |
| 606 | #if (CONFIG_SYS_PCMCIA_POR1 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 607 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 608 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 609 | ; |
| 610 | debug("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 611 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 612 | pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2; |
| 613 | pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 |
| 614 | #if (CONFIG_SYS_PCMCIA_POR2 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 615 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 616 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 617 | ; |
| 618 | debug("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 619 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 620 | pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3; |
| 621 | pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 |
| 622 | #if (CONFIG_SYS_PCMCIA_POR3 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 623 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 624 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 625 | ; |
| 626 | debug("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 627 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 628 | /* |
| 629 | * IDE 1 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 630 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 631 | pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4; |
| 632 | pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 |
| 633 | #if (CONFIG_SYS_PCMCIA_POR4 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 634 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 635 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 636 | ; |
| 637 | debug("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 638 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 639 | pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5; |
| 640 | pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 |
| 641 | #if (CONFIG_SYS_PCMCIA_POR5 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 642 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 643 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 644 | ; |
| 645 | debug("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 646 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 647 | pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6; |
| 648 | pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 |
| 649 | #if (CONFIG_SYS_PCMCIA_POR6 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 650 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 651 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 652 | ; |
| 653 | debug("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 654 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 655 | pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7; |
| 656 | pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 |
| 657 | #if (CONFIG_SYS_PCMCIA_POR7 != 0) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 658 | | timings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 659 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 660 | ; |
| 661 | debug("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 662 | |
| 663 | } |
| 664 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 665 | #endif /* CONFIG_IDE_8xx_DIRECT */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 666 | |
| 667 | /* ------------------------------------------------------------------------- */ |
| 668 | |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 669 | /* We only need to swap data if we are running on a big endian cpu. */ |
| 670 | /* But Au1x00 cpu:s already swaps data in big endian mode! */ |
Shinya Kuribayashi | c6dc8a7 | 2011-02-05 19:07:00 +0900 | [diff] [blame] | 671 | #if defined(__LITTLE_ENDIAN) || \ |
| 672 | (defined(CONFIG_SOC_AU1X00) && !defined(CONFIG_GTH2)) |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 673 | #define input_swap_data(x,y,z) input_data(x,y,z) |
| 674 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 675 | static void input_swap_data(int dev, ulong *sect_buf, int words) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 676 | { |
Wolfgang Denk | 77efe35 | 2010-09-19 21:28:25 +0200 | [diff] [blame] | 677 | #if defined(CONFIG_CPC45) |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 678 | uchar i; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 679 | volatile uchar *pbuf_even = |
| 680 | (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN); |
| 681 | volatile uchar *pbuf_odd = |
| 682 | (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD); |
| 683 | ushort *dbuf = (ushort *) sect_buf; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 684 | |
| 685 | while (words--) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 686 | for (i = 0; i < 2; i++) { |
| 687 | *(((uchar *) (dbuf)) + 1) = *pbuf_even; |
| 688 | *(uchar *) dbuf = *pbuf_odd; |
| 689 | dbuf += 1; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
wdenk | f4733a0 | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 692 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 693 | volatile ushort *pbuf = |
| 694 | (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 695 | ushort *dbuf = (ushort *) sect_buf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 696 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 697 | debug("in input swap data base for read is %lx\n", |
| 698 | (unsigned long) pbuf); |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 699 | |
| 700 | while (words--) { |
Wolfgang Denk | 0c32d96 | 2006-06-16 17:32:31 +0200 | [diff] [blame] | 701 | #ifdef __MIPS__ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 702 | *dbuf++ = swab16p((u16 *) pbuf); |
| 703 | *dbuf++ = swab16p((u16 *) pbuf); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 704 | #elif defined(CONFIG_PCS440EP) |
| 705 | *dbuf++ = *pbuf; |
| 706 | *dbuf++ = *pbuf; |
Wolfgang Denk | 0c32d96 | 2006-06-16 17:32:31 +0200 | [diff] [blame] | 707 | #else |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 708 | *dbuf++ = ld_le16(pbuf); |
| 709 | *dbuf++ = ld_le16(pbuf); |
Wolfgang Denk | 0c32d96 | 2006-06-16 17:32:31 +0200 | [diff] [blame] | 710 | #endif /* !MIPS */ |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 711 | } |
| 712 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 713 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 714 | #endif /* __LITTLE_ENDIAN || CONFIG_AU1X00 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 715 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 716 | |
Albert Aribaud | f2a37fc | 2010-08-08 05:17:05 +0530 | [diff] [blame] | 717 | #if defined(CONFIG_IDE_SWAP_IO) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 718 | static void output_data(int dev, const ulong *sect_buf, int words) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 719 | { |
Wolfgang Denk | 77efe35 | 2010-09-19 21:28:25 +0200 | [diff] [blame] | 720 | #if defined(CONFIG_CPC45) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 721 | uchar *dbuf; |
| 722 | volatile uchar *pbuf_even; |
| 723 | volatile uchar *pbuf_odd; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 724 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 725 | pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN); |
| 726 | pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD); |
| 727 | dbuf = (uchar *) sect_buf; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 728 | while (words--) { |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 729 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 730 | *pbuf_even = *dbuf++; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 731 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 732 | *pbuf_odd = *dbuf++; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 733 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 734 | *pbuf_even = *dbuf++; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 735 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 736 | *pbuf_odd = *dbuf++; |
| 737 | } |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 738 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 739 | ushort *dbuf; |
| 740 | volatile ushort *pbuf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 741 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 742 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 743 | dbuf = (ushort *) sect_buf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 744 | while (words--) { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 745 | #if defined(CONFIG_PCS440EP) |
| 746 | /* not tested, because CF was write protected */ |
| 747 | EIEIO; |
| 748 | *pbuf = ld_le16(dbuf++); |
| 749 | EIEIO; |
| 750 | *pbuf = ld_le16(dbuf++); |
| 751 | #else |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 752 | EIEIO; |
| 753 | *pbuf = *dbuf++; |
| 754 | EIEIO; |
| 755 | *pbuf = *dbuf++; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 756 | #endif |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 757 | } |
| 758 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 759 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 760 | #else /* ! CONFIG_IDE_SWAP_IO */ |
| 761 | static void output_data(int dev, const ulong *sect_buf, int words) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 762 | { |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 763 | #if defined(CONFIG_IDE_AHB) |
| 764 | ide_write_data(dev, sect_buf, words); |
| 765 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 766 | outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1); |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 767 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 768 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 769 | #endif /* CONFIG_IDE_SWAP_IO */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 770 | |
Albert Aribaud | f2a37fc | 2010-08-08 05:17:05 +0530 | [diff] [blame] | 771 | #if defined(CONFIG_IDE_SWAP_IO) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 772 | static void input_data(int dev, ulong *sect_buf, int words) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 773 | { |
Wolfgang Denk | 77efe35 | 2010-09-19 21:28:25 +0200 | [diff] [blame] | 774 | #if defined(CONFIG_CPC45) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 775 | uchar *dbuf; |
| 776 | volatile uchar *pbuf_even; |
| 777 | volatile uchar *pbuf_odd; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 778 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 779 | pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN); |
| 780 | pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD); |
| 781 | dbuf = (uchar *) sect_buf; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 782 | while (words--) { |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 783 | *dbuf++ = *pbuf_even; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 784 | EIEIO; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 785 | SYNC; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 786 | *dbuf++ = *pbuf_odd; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 787 | EIEIO; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 788 | SYNC; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 789 | *dbuf++ = *pbuf_even; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 790 | EIEIO; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 791 | SYNC; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 792 | *dbuf++ = *pbuf_odd; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 793 | EIEIO; |
| 794 | SYNC; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 795 | } |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 796 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 797 | ushort *dbuf; |
| 798 | volatile ushort *pbuf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 799 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 800 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 801 | dbuf = (ushort *) sect_buf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 802 | |
| 803 | debug("in input data base for read is %lx\n", (unsigned long) pbuf); |
| 804 | |
| 805 | while (words--) { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 806 | #if defined(CONFIG_PCS440EP) |
| 807 | EIEIO; |
| 808 | *dbuf++ = ld_le16(pbuf); |
| 809 | EIEIO; |
| 810 | *dbuf++ = ld_le16(pbuf); |
| 811 | #else |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 812 | EIEIO; |
| 813 | *dbuf++ = *pbuf; |
| 814 | EIEIO; |
| 815 | *dbuf++ = *pbuf; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 816 | #endif |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 817 | } |
| 818 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 819 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 820 | #else /* ! CONFIG_IDE_SWAP_IO */ |
| 821 | static void input_data(int dev, ulong *sect_buf, int words) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 822 | { |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 823 | #if defined(CONFIG_IDE_AHB) |
| 824 | ide_read_data(dev, sect_buf, words); |
| 825 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 826 | insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, words << 1); |
Macpaul Lin | 0abddf8 | 2011-04-11 20:45:32 +0000 | [diff] [blame] | 827 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 830 | #endif /* CONFIG_IDE_SWAP_IO */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 831 | |
| 832 | /* ------------------------------------------------------------------------- |
| 833 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 834 | static void ide_ident(block_dev_desc_t *dev_desc) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 835 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 836 | unsigned char c; |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 837 | hd_driveid_t iop; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 838 | |
wdenk | 64f70be | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 839 | #ifdef CONFIG_ATAPI |
| 840 | int retries = 0; |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 841 | #endif |
| 842 | |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 843 | #ifdef CONFIG_TUNE_PIO |
| 844 | int pio_mode; |
| 845 | #endif |
| 846 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 847 | #if 0 |
| 848 | int mode, cycle_time; |
| 849 | #endif |
| 850 | int device; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 851 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 852 | device = dev_desc->dev; |
| 853 | printf(" Device %d: ", device); |
| 854 | |
| 855 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 856 | /* Select device |
| 857 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 858 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 859 | dev_desc->if_type = IF_TYPE_IDE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 860 | #ifdef CONFIG_ATAPI |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 861 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 862 | retries = 0; |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 863 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 864 | /* Warning: This will be tricky to read */ |
| 865 | while (retries <= 1) { |
| 866 | /* check signature */ |
| 867 | if ((ide_inb(device, ATA_SECT_CNT) == 0x01) && |
| 868 | (ide_inb(device, ATA_SECT_NUM) == 0x01) && |
| 869 | (ide_inb(device, ATA_CYL_LOW) == 0x14) && |
| 870 | (ide_inb(device, ATA_CYL_HIGH) == 0xEB)) { |
| 871 | /* ATAPI Signature found */ |
| 872 | dev_desc->if_type = IF_TYPE_ATAPI; |
| 873 | /* |
| 874 | * Start Ident Command |
| 875 | */ |
| 876 | ide_outb(device, ATA_COMMAND, ATAPI_CMD_IDENT); |
| 877 | /* |
| 878 | * Wait for completion - ATAPI devices need more time |
| 879 | * to become ready |
| 880 | */ |
| 881 | c = ide_wait(device, ATAPI_TIME_OUT); |
| 882 | } else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 883 | #endif |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 884 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 885 | /* |
| 886 | * Start Ident Command |
| 887 | */ |
| 888 | ide_outb(device, ATA_COMMAND, ATA_CMD_IDENT); |
| 889 | |
| 890 | /* |
| 891 | * Wait for completion |
| 892 | */ |
| 893 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 894 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 895 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
| 896 | |
| 897 | if (((c & ATA_STAT_DRQ) == 0) || |
| 898 | ((c & (ATA_STAT_FAULT | ATA_STAT_ERR)) != 0)) { |
wdenk | 64f70be | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 899 | #ifdef CONFIG_ATAPI |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 900 | { |
| 901 | /* |
| 902 | * Need to soft reset the device |
| 903 | * in case it's an ATAPI... |
| 904 | */ |
| 905 | debug("Retrying...\n"); |
| 906 | ide_outb(device, ATA_DEV_HD, |
| 907 | ATA_LBA | ATA_DEVICE(device)); |
| 908 | udelay(100000); |
| 909 | ide_outb(device, ATA_COMMAND, 0x08); |
| 910 | udelay(500000); /* 500 ms */ |
| 911 | } |
| 912 | /* |
| 913 | * Select device |
| 914 | */ |
| 915 | ide_outb(device, ATA_DEV_HD, |
| 916 | ATA_LBA | ATA_DEVICE(device)); |
| 917 | retries++; |
| 918 | #else |
| 919 | return; |
| 920 | #endif |
| 921 | } |
| 922 | #ifdef CONFIG_ATAPI |
| 923 | else |
| 924 | break; |
| 925 | } /* see above - ugly to read */ |
wdenk | 64f70be | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 926 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 927 | if (retries == 2) /* Not found */ |
wdenk | 64f70be | 2004-09-28 20:34:50 +0000 | [diff] [blame] | 928 | return; |
| 929 | #endif |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 930 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 931 | input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 932 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 933 | ident_cpy((unsigned char *) dev_desc->revision, iop.fw_rev, |
| 934 | sizeof(dev_desc->revision)); |
| 935 | ident_cpy((unsigned char *) dev_desc->vendor, iop.model, |
| 936 | sizeof(dev_desc->vendor)); |
| 937 | ident_cpy((unsigned char *) dev_desc->product, iop.serial_no, |
| 938 | sizeof(dev_desc->product)); |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 939 | #ifdef __LITTLE_ENDIAN |
| 940 | /* |
Richard Retanubun | bcdf1d2 | 2008-11-06 14:01:51 -0500 | [diff] [blame] | 941 | * firmware revision, model, and serial number have Big Endian Byte |
| 942 | * order in Word. Convert all three to little endian. |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 943 | * |
| 944 | * See CF+ and CompactFlash Specification Revision 2.0: |
Richard Retanubun | bcdf1d2 | 2008-11-06 14:01:51 -0500 | [diff] [blame] | 945 | * 6.2.1.6: Identify Drive, Table 39 for more details |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 946 | */ |
| 947 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 948 | strswab(dev_desc->revision); |
| 949 | strswab(dev_desc->vendor); |
| 950 | strswab(dev_desc->product); |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 951 | #endif /* __LITTLE_ENDIAN */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 952 | |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 953 | if ((iop.config & 0x0080) == 0x0080) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 954 | dev_desc->removable = 1; |
| 955 | else |
| 956 | dev_desc->removable = 0; |
| 957 | |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 958 | #ifdef CONFIG_TUNE_PIO |
| 959 | /* Mode 0 - 2 only, are directly determined by word 51. */ |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 960 | pio_mode = iop.tPIO; |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 961 | if (pio_mode > 2) { |
| 962 | printf("WARNING: Invalid PIO (word 51 = %d).\n", pio_mode); |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 963 | /* Force it to dead slow, and hope for the best... */ |
| 964 | pio_mode = 0; |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /* Any CompactFlash Storage Card that supports PIO mode 3 or above |
| 968 | * shall set bit 1 of word 53 to one and support the fields contained |
| 969 | * in words 64 through 70. |
| 970 | */ |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 971 | if (iop.field_valid & 0x02) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 972 | /* |
| 973 | * Mode 3 and above are possible. Check in order from slow |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 974 | * to fast, so we wind up with the highest mode allowed. |
| 975 | */ |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 976 | if (iop.eide_pio_modes & 0x01) |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 977 | pio_mode = 3; |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 978 | if (iop.eide_pio_modes & 0x02) |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 979 | pio_mode = 4; |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 980 | if (ata_id_is_cfa((u16 *)&iop)) { |
| 981 | if ((iop.cf_advanced_caps & 0x07) == 0x01) |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 982 | pio_mode = 5; |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 983 | if ((iop.cf_advanced_caps & 0x07) == 0x02) |
Steven A. Falco | 36c2d30 | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 984 | pio_mode = 6; |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | /* System-specific, depends on bus speeds, etc. */ |
| 989 | ide_set_piomode(pio_mode); |
| 990 | #endif /* CONFIG_TUNE_PIO */ |
| 991 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 992 | #if 0 |
| 993 | /* |
| 994 | * Drive PIO mode autoselection |
| 995 | */ |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 996 | mode = iop.tPIO; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 997 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 998 | printf("tPIO = 0x%02x = %d\n", mode, mode); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 999 | if (mode > 2) { /* 2 is maximum allowed tPIO value */ |
| 1000 | mode = 2; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1001 | debug("Override tPIO -> 2\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1002 | } |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 1003 | if (iop.field_valid & 2) { /* drive implements ATA2? */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1004 | debug("Drive implements ATA2\n"); |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 1005 | if (iop.capability & 8) { /* drive supports use_iordy? */ |
| 1006 | cycle_time = iop.eide_pio_iordy; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1007 | } else { |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 1008 | cycle_time = iop.eide_pio; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1009 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1010 | debug("cycle time = %d\n", cycle_time); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1011 | mode = 4; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1012 | if (cycle_time > 120) |
| 1013 | mode = 3; /* 120 ns for PIO mode 4 */ |
| 1014 | if (cycle_time > 180) |
| 1015 | mode = 2; /* 180 ns for PIO mode 3 */ |
| 1016 | if (cycle_time > 240) |
| 1017 | mode = 1; /* 240 ns for PIO mode 4 */ |
| 1018 | if (cycle_time > 383) |
| 1019 | mode = 0; /* 383 ns for PIO mode 4 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1020 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1021 | printf("PIO mode to use: PIO %d\n", mode); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1022 | #endif /* 0 */ |
| 1023 | |
| 1024 | #ifdef CONFIG_ATAPI |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1025 | if (dev_desc->if_type == IF_TYPE_ATAPI) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1026 | atapi_inquiry(dev_desc); |
| 1027 | return; |
| 1028 | } |
| 1029 | #endif /* CONFIG_ATAPI */ |
| 1030 | |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 1031 | #ifdef __BIG_ENDIAN |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1032 | /* swap shorts */ |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 1033 | dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16); |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1034 | #else /* ! __BIG_ENDIAN */ |
wdenk | c3f9d49 | 2004-03-14 00:59:59 +0000 | [diff] [blame] | 1035 | /* |
| 1036 | * do not swap shorts on little endian |
| 1037 | * |
| 1038 | * See CF+ and CompactFlash Specification Revision 2.0: |
| 1039 | * 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details. |
| 1040 | */ |
Marek Vasut | b18eabf | 2011-08-20 09:15:13 +0000 | [diff] [blame] | 1041 | dev_desc->lba = iop.lba_capacity; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1042 | #endif /* __BIG_ENDIAN */ |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1043 | |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1044 | #ifdef CONFIG_LBA48 |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1045 | if (iop.command_set_2 & 0x0400) { /* LBA 48 support */ |
wdenk | 6e59238 | 2004-04-18 17:39:38 +0000 | [diff] [blame] | 1046 | dev_desc->lba48 = 1; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1047 | dev_desc->lba = (unsigned long long) iop.lba48_capacity[0] | |
| 1048 | ((unsigned long long) iop.lba48_capacity[1] << 16) | |
| 1049 | ((unsigned long long) iop.lba48_capacity[2] << 32) | |
| 1050 | ((unsigned long long) iop.lba48_capacity[3] << 48); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1051 | } else { |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1052 | dev_desc->lba48 = 0; |
| 1053 | } |
| 1054 | #endif /* CONFIG_LBA48 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1055 | /* assuming HD */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1056 | dev_desc->type = DEV_TYPE_HARDDISK; |
| 1057 | dev_desc->blksz = ATA_BLOCKSIZE; |
| 1058 | dev_desc->lun = 0; /* just to fill something in... */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1059 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1060 | #if 0 /* only used to test the powersaving mode, |
| 1061 | * if enabled, the drive goes after 5 sec |
| 1062 | * in standby mode */ |
| 1063 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 1064 | c = ide_wait(device, IDE_TIME_OUT); |
| 1065 | ide_outb(device, ATA_SECT_CNT, 1); |
| 1066 | ide_outb(device, ATA_LBA_LOW, 0); |
| 1067 | ide_outb(device, ATA_LBA_MID, 0); |
| 1068 | ide_outb(device, ATA_LBA_HIGH, 0); |
| 1069 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 1070 | ide_outb(device, ATA_COMMAND, 0xe3); |
| 1071 | udelay(50); |
| 1072 | c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1073 | #endif |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | /* ------------------------------------------------------------------------- */ |
| 1078 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1079 | ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1080 | { |
| 1081 | ulong n = 0; |
| 1082 | unsigned char c; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1083 | unsigned char pwrsave = 0; /* power save */ |
| 1084 | |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1085 | #ifdef CONFIG_LBA48 |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1086 | unsigned char lba48 = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1087 | |
Guennadi Liakhovetski | 413bf58 | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 1088 | if (blknr & 0x0000fffff0000000ULL) { |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1089 | /* more than 28 bits used, use 48bit mode */ |
| 1090 | lba48 = 1; |
| 1091 | } |
| 1092 | #endif |
Marek Vasut | 5bbe10d | 2011-10-25 11:39:15 +0200 | [diff] [blame] | 1093 | debug("ide_read dev %d start %lX, blocks %lX buffer at %lX\n", |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1094 | device, blknr, blkcnt, (ulong) buffer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1095 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1096 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1097 | |
| 1098 | /* Select device |
| 1099 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1100 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 1101 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1102 | |
| 1103 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1104 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1105 | goto IDE_READ_E; |
| 1106 | } |
| 1107 | |
| 1108 | /* first check if the drive is in Powersaving mode, if yes, |
| 1109 | * increase the timeout value */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1110 | ide_outb(device, ATA_COMMAND, ATA_CMD_CHK_PWR); |
| 1111 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1112 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1113 | c = ide_wait(device, IDE_TIME_OUT); /* can't take over 500 ms */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1114 | |
| 1115 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1116 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1117 | goto IDE_READ_E; |
| 1118 | } |
| 1119 | if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1120 | printf("No Powersaving mode %X\n", c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1121 | } else { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1122 | c = ide_inb(device, ATA_SECT_CNT); |
| 1123 | debug("Powersaving %02X\n", c); |
| 1124 | if (c == 0) |
| 1125 | pwrsave = 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | while (blkcnt-- > 0) { |
| 1130 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1131 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1132 | |
| 1133 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1134 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1135 | break; |
| 1136 | } |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1137 | #ifdef CONFIG_LBA48 |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1138 | if (lba48) { |
| 1139 | /* write high bits */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1140 | ide_outb(device, ATA_SECT_CNT, 0); |
| 1141 | ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1142 | #ifdef CONFIG_SYS_64BIT_LBA |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1143 | ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF); |
| 1144 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF); |
Guennadi Liakhovetski | 413bf58 | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 1145 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1146 | ide_outb(device, ATA_LBA_MID, 0); |
| 1147 | ide_outb(device, ATA_LBA_HIGH, 0); |
Guennadi Liakhovetski | 413bf58 | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 1148 | #endif |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1149 | } |
| 1150 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1151 | ide_outb(device, ATA_SECT_CNT, 1); |
| 1152 | ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); |
| 1153 | ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF); |
| 1154 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1155 | |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1156 | #ifdef CONFIG_LBA48 |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1157 | if (lba48) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1158 | ide_outb(device, ATA_DEV_HD, |
| 1159 | ATA_LBA | ATA_DEVICE(device)); |
| 1160 | ide_outb(device, ATA_COMMAND, ATA_CMD_READ_EXT); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1161 | |
| 1162 | } else |
| 1163 | #endif |
| 1164 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1165 | ide_outb(device, ATA_DEV_HD, ATA_LBA | |
| 1166 | ATA_DEVICE(device) | ((blknr >> 24) & 0xF)); |
| 1167 | ide_outb(device, ATA_COMMAND, ATA_CMD_READ); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1168 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1169 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1170 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1171 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1172 | if (pwrsave) { |
| 1173 | /* may take up to 4 sec */ |
| 1174 | c = ide_wait(device, IDE_SPIN_UP_TIME_OUT); |
| 1175 | pwrsave = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1176 | } else { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1177 | /* can't take over 500 ms */ |
| 1178 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1181 | if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) != |
| 1182 | ATA_STAT_DRQ) { |
Heiko Schocher | 4b142fe | 2009-12-03 11:21:21 +0100 | [diff] [blame] | 1183 | #if defined(CONFIG_SYS_64BIT_LBA) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1184 | printf("Error (no IRQ) dev %d blk %lld: status 0x%02x\n", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1185 | device, blknr, c); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1186 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1187 | printf("Error (no IRQ) dev %d blk %ld: status 0x%02x\n", |
| 1188 | device, (ulong) blknr, c); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1189 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1190 | break; |
| 1191 | } |
| 1192 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1193 | input_data(device, buffer, ATA_SECTORWORDS); |
| 1194 | (void) ide_inb(device, ATA_STATUS); /* clear IRQ */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1195 | |
| 1196 | ++n; |
| 1197 | ++blknr; |
Greg Lopp | 0b94504 | 2007-04-13 08:02:24 +0200 | [diff] [blame] | 1198 | buffer += ATA_BLOCKSIZE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1199 | } |
| 1200 | IDE_READ_E: |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1201 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1202 | return (n); |
| 1203 | } |
| 1204 | |
| 1205 | /* ------------------------------------------------------------------------- */ |
| 1206 | |
| 1207 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1208 | ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void *buffer) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1209 | { |
| 1210 | ulong n = 0; |
| 1211 | unsigned char c; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1212 | |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1213 | #ifdef CONFIG_LBA48 |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1214 | unsigned char lba48 = 0; |
| 1215 | |
Guennadi Liakhovetski | 413bf58 | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 1216 | if (blknr & 0x0000fffff0000000ULL) { |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1217 | /* more than 28 bits used, use 48bit mode */ |
| 1218 | lba48 = 1; |
| 1219 | } |
| 1220 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1221 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1222 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1223 | |
| 1224 | /* Select device |
| 1225 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1226 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1227 | |
| 1228 | while (blkcnt-- > 0) { |
| 1229 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1230 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1231 | |
| 1232 | if (c & ATA_STAT_BUSY) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1233 | printf("IDE read: device %d not ready\n", device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1234 | goto WR_OUT; |
| 1235 | } |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1236 | #ifdef CONFIG_LBA48 |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1237 | if (lba48) { |
| 1238 | /* write high bits */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1239 | ide_outb(device, ATA_SECT_CNT, 0); |
| 1240 | ide_outb(device, ATA_LBA_LOW, (blknr >> 24) & 0xFF); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1241 | #ifdef CONFIG_SYS_64BIT_LBA |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1242 | ide_outb(device, ATA_LBA_MID, (blknr >> 32) & 0xFF); |
| 1243 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 40) & 0xFF); |
Guennadi Liakhovetski | 413bf58 | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 1244 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1245 | ide_outb(device, ATA_LBA_MID, 0); |
| 1246 | ide_outb(device, ATA_LBA_HIGH, 0); |
Guennadi Liakhovetski | 413bf58 | 2008-04-28 14:36:06 +0200 | [diff] [blame] | 1247 | #endif |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1248 | } |
| 1249 | #endif |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1250 | ide_outb(device, ATA_SECT_CNT, 1); |
| 1251 | ide_outb(device, ATA_LBA_LOW, (blknr >> 0) & 0xFF); |
| 1252 | ide_outb(device, ATA_LBA_MID, (blknr >> 8) & 0xFF); |
| 1253 | ide_outb(device, ATA_LBA_HIGH, (blknr >> 16) & 0xFF); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1254 | |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1255 | #ifdef CONFIG_LBA48 |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1256 | if (lba48) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1257 | ide_outb(device, ATA_DEV_HD, |
| 1258 | ATA_LBA | ATA_DEVICE(device)); |
| 1259 | ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE_EXT); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1260 | |
| 1261 | } else |
| 1262 | #endif |
| 1263 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1264 | ide_outb(device, ATA_DEV_HD, ATA_LBA | |
| 1265 | ATA_DEVICE(device) | ((blknr >> 24) & 0xF)); |
| 1266 | ide_outb(device, ATA_COMMAND, ATA_CMD_WRITE); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1267 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1268 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1269 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1270 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1271 | /* can't take over 500 ms */ |
| 1272 | c = ide_wait(device, IDE_TIME_OUT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1273 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1274 | if ((c & (ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR)) != |
| 1275 | ATA_STAT_DRQ) { |
Heiko Schocher | 4b142fe | 2009-12-03 11:21:21 +0100 | [diff] [blame] | 1276 | #if defined(CONFIG_SYS_64BIT_LBA) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1277 | printf("Error (no IRQ) dev %d blk %lld: status 0x%02x\n", |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1278 | device, blknr, c); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1279 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1280 | printf("Error (no IRQ) dev %d blk %ld: status 0x%02x\n", |
| 1281 | device, (ulong) blknr, c); |
wdenk | c40b295 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 1282 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1283 | goto WR_OUT; |
| 1284 | } |
| 1285 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1286 | output_data(device, buffer, ATA_SECTORWORDS); |
| 1287 | c = ide_inb(device, ATA_STATUS); /* clear IRQ */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1288 | ++n; |
| 1289 | ++blknr; |
Greg Lopp | 0b94504 | 2007-04-13 08:02:24 +0200 | [diff] [blame] | 1290 | buffer += ATA_BLOCKSIZE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1291 | } |
| 1292 | WR_OUT: |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1293 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1294 | return (n); |
| 1295 | } |
| 1296 | |
| 1297 | /* ------------------------------------------------------------------------- */ |
| 1298 | |
| 1299 | /* |
| 1300 | * copy src to dest, skipping leading and trailing blanks and null |
| 1301 | * terminate the string |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1302 | * "len" is the size of available memory including the terminating '\0' |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1303 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1304 | static void ident_cpy(unsigned char *dst, unsigned char *src, |
| 1305 | unsigned int len) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1306 | { |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1307 | unsigned char *end, *last; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1308 | |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1309 | last = dst; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1310 | end = src + len - 1; |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1311 | |
| 1312 | /* reserve space for '\0' */ |
| 1313 | if (len < 2) |
| 1314 | goto OUT; |
wdenk | efa329c | 2004-03-23 20:18:25 +0000 | [diff] [blame] | 1315 | |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1316 | /* skip leading white space */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1317 | while ((*src) && (src < end) && (*src == ' ')) |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1318 | ++src; |
| 1319 | |
| 1320 | /* copy string, omitting trailing white space */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1321 | while ((*src) && (src < end)) { |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1322 | *dst++ = *src; |
| 1323 | if (*src++ != ' ') |
| 1324 | last = dst; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1325 | } |
wdenk | 7d7ce41 | 2004-03-17 01:13:07 +0000 | [diff] [blame] | 1326 | OUT: |
| 1327 | *last = '\0'; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | /* ------------------------------------------------------------------------- */ |
| 1331 | |
| 1332 | /* |
| 1333 | * Wait until Busy bit is off, or timeout (in ms) |
| 1334 | * Return last status |
| 1335 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1336 | static uchar ide_wait(int dev, ulong t) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1337 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1338 | ulong delay = 10 * t; /* poll every 100 us */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1339 | uchar c; |
| 1340 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1341 | while ((c = ide_inb(dev, ATA_STATUS)) & ATA_STAT_BUSY) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1342 | udelay(100); |
| 1343 | if (delay-- == 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1344 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1345 | } |
| 1346 | return (c); |
| 1347 | } |
| 1348 | |
| 1349 | /* ------------------------------------------------------------------------- */ |
| 1350 | |
| 1351 | #ifdef CONFIG_IDE_RESET |
| 1352 | extern void ide_set_reset(int idereset); |
| 1353 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1354 | static void ide_reset(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1355 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1356 | #if defined(CONFIG_SYS_PB_12V_ENABLE) || defined(CONFIG_SYS_PB_IDE_MOTOR) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1357 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1358 | #endif |
| 1359 | int i; |
| 1360 | |
| 1361 | curr_device = -1; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1362 | for (i = 0; i < CONFIG_SYS_IDE_MAXBUS; ++i) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1363 | ide_bus_ok[i] = 0; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1364 | for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1365 | ide_dev_desc[i].type = DEV_TYPE_UNKNOWN; |
| 1366 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1367 | ide_set_reset(1); /* assert reset */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1368 | |
Martin Krause | e175eac | 2008-04-03 13:37:56 +0200 | [diff] [blame] | 1369 | /* the reset signal shall be asserted for et least 25 us */ |
| 1370 | udelay(25); |
| 1371 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1372 | WATCHDOG_RESET(); |
| 1373 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1374 | #ifdef CONFIG_SYS_PB_12V_ENABLE |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1375 | /* 12V Enable output OFF */ |
| 1376 | immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_12V_ENABLE); |
| 1377 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1378 | immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_12V_ENABLE); |
| 1379 | immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_12V_ENABLE); |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1380 | immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_12V_ENABLE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1381 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1382 | /* wait 500 ms for the voltage to stabilize */ |
| 1383 | for (i = 0; i < 500; ++i) |
| 1384 | udelay(1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1385 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1386 | /* 12V Enable output ON */ |
| 1387 | immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_12V_ENABLE; |
| 1388 | #endif /* CONFIG_SYS_PB_12V_ENABLE */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1389 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1390 | #ifdef CONFIG_SYS_PB_IDE_MOTOR |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1391 | /* configure IDE Motor voltage monitor pin as input */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1392 | immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_IDE_MOTOR); |
| 1393 | immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_IDE_MOTOR); |
| 1394 | immr->im_cpm.cp_pbdir &= ~(CONFIG_SYS_PB_IDE_MOTOR); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1395 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1396 | /* wait up to 1 s for the motor voltage to stabilize */ |
| 1397 | for (i = 0; i < 1000; ++i) { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1398 | if ((immr->im_cpm.cp_pbdat & CONFIG_SYS_PB_IDE_MOTOR) != 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1399 | break; |
| 1400 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1401 | udelay(1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | if (i == 1000) { /* Timeout */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1405 | printf("\nWarning: 5V for IDE Motor missing\n"); |
| 1406 | #ifdef CONFIG_STATUS_LED |
| 1407 | #ifdef STATUS_LED_YELLOW |
| 1408 | status_led_set(STATUS_LED_YELLOW, STATUS_LED_ON); |
| 1409 | #endif |
| 1410 | #ifdef STATUS_LED_GREEN |
| 1411 | status_led_set(STATUS_LED_GREEN, STATUS_LED_OFF); |
| 1412 | #endif |
| 1413 | #endif /* CONFIG_STATUS_LED */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1414 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1415 | #endif /* CONFIG_SYS_PB_IDE_MOTOR */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1416 | |
| 1417 | WATCHDOG_RESET(); |
| 1418 | |
| 1419 | /* de-assert RESET signal */ |
| 1420 | ide_set_reset(0); |
| 1421 | |
| 1422 | /* wait 250 ms */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1423 | for (i = 0; i < 250; ++i) |
| 1424 | udelay(1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1427 | #endif /* CONFIG_IDE_RESET */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1428 | |
| 1429 | /* ------------------------------------------------------------------------- */ |
| 1430 | |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 1431 | #if defined(CONFIG_IDE_LED) && \ |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 1432 | !defined(CONFIG_CPC45) && \ |
wdenk | e2ffd59 | 2004-12-31 09:32:47 +0000 | [diff] [blame] | 1433 | !defined(CONFIG_KUP4K) && \ |
| 1434 | !defined(CONFIG_KUP4X) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1435 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1436 | static uchar led_buffer; /* Buffer for current LED status */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1437 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1438 | static void ide_led(uchar led, uchar status) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1439 | { |
| 1440 | uchar *led_port = LED_PORT; |
| 1441 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1442 | if (status) /* switch LED on */ |
| 1443 | led_buffer |= led; |
| 1444 | else /* switch LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1445 | led_buffer &= ~led; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1446 | |
| 1447 | *led_port = led_buffer; |
| 1448 | } |
| 1449 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1450 | #endif /* CONFIG_IDE_LED */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1451 | |
Heiko Schocher | 3887c3f | 2009-09-23 07:56:08 +0200 | [diff] [blame] | 1452 | #if defined(CONFIG_OF_IDE_FIXUP) |
| 1453 | int ide_device_present(int dev) |
| 1454 | { |
| 1455 | if (dev >= CONFIG_SYS_IDE_MAXBUS) |
| 1456 | return 0; |
| 1457 | return (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN ? 0 : 1); |
| 1458 | } |
| 1459 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1460 | /* ------------------------------------------------------------------------- */ |
| 1461 | |
| 1462 | #ifdef CONFIG_ATAPI |
| 1463 | /**************************************************************************** |
| 1464 | * ATAPI Support |
| 1465 | */ |
| 1466 | |
Albert Aribaud | f2a37fc | 2010-08-08 05:17:05 +0530 | [diff] [blame] | 1467 | #if defined(CONFIG_IDE_SWAP_IO) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1468 | /* since ATAPI may use commands with not 4 bytes alligned length |
| 1469 | * we have our own transfer functions, 2 bytes alligned */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1470 | static void output_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1471 | { |
Wolfgang Denk | 77efe35 | 2010-09-19 21:28:25 +0200 | [diff] [blame] | 1472 | #if defined(CONFIG_CPC45) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1473 | uchar *dbuf; |
| 1474 | volatile uchar *pbuf_even; |
| 1475 | volatile uchar *pbuf_odd; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1476 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1477 | pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN); |
| 1478 | pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD); |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1479 | while (shorts--) { |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 1480 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1481 | *pbuf_even = *dbuf++; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 1482 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1483 | *pbuf_odd = *dbuf++; |
| 1484 | } |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1485 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1486 | ushort *dbuf; |
| 1487 | volatile ushort *pbuf; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1488 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1489 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 1490 | dbuf = (ushort *) sect_buf; |
wdenk | db01a2e | 2004-04-15 23:14:49 +0000 | [diff] [blame] | 1491 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1492 | debug("in output data shorts base for read is %lx\n", |
| 1493 | (unsigned long) pbuf); |
wdenk | db01a2e | 2004-04-15 23:14:49 +0000 | [diff] [blame] | 1494 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1495 | while (shorts--) { |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 1496 | EIEIO; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1497 | *pbuf = *dbuf++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1498 | } |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1499 | #endif |
| 1500 | } |
| 1501 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1502 | static void input_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1503 | { |
Wolfgang Denk | 77efe35 | 2010-09-19 21:28:25 +0200 | [diff] [blame] | 1504 | #if defined(CONFIG_CPC45) |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1505 | uchar *dbuf; |
| 1506 | volatile uchar *pbuf_even; |
| 1507 | volatile uchar *pbuf_odd; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1508 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1509 | pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN); |
| 1510 | pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD); |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1511 | while (shorts--) { |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 1512 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1513 | *dbuf++ = *pbuf_even; |
wdenk | 5cf91d6 | 2004-04-23 20:32:05 +0000 | [diff] [blame] | 1514 | EIEIO; |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 1515 | *dbuf++ = *pbuf_odd; |
| 1516 | } |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1517 | #else |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1518 | ushort *dbuf; |
| 1519 | volatile ushort *pbuf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1520 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1521 | pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG); |
| 1522 | dbuf = (ushort *) sect_buf; |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1523 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1524 | debug("in input data shorts base for read is %lx\n", |
| 1525 | (unsigned long) pbuf); |
wdenk | 1a344f2 | 2005-02-03 23:00:49 +0000 | [diff] [blame] | 1526 | |
| 1527 | while (shorts--) { |
| 1528 | EIEIO; |
| 1529 | *dbuf++ = *pbuf; |
| 1530 | } |
| 1531 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1534 | #else /* ! CONFIG_IDE_SWAP_IO */ |
| 1535 | static void output_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1536 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1537 | outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1540 | static void input_data_shorts(int dev, ushort *sect_buf, int shorts) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1541 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1542 | insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1545 | #endif /* CONFIG_IDE_SWAP_IO */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1546 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1547 | /* |
| 1548 | * Wait until (Status & mask) == res, or timeout (in ms) |
| 1549 | * Return last status |
| 1550 | * This is used since some ATAPI CD ROMs clears their Busy Bit first |
| 1551 | * and then they set their DRQ Bit |
| 1552 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1553 | static uchar atapi_wait_mask(int dev, ulong t, uchar mask, uchar res) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1554 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1555 | ulong delay = 10 * t; /* poll every 100 us */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1556 | uchar c; |
| 1557 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1558 | /* prevents to read the status before valid */ |
| 1559 | c = ide_inb(dev, ATA_DEV_CTL); |
| 1560 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1561 | while (((c = ide_inb(dev, ATA_STATUS)) & mask) != res) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1562 | /* break if error occurs (doesn't make sense to wait more) */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1563 | if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1564 | break; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1565 | udelay(100); |
| 1566 | if (delay-- == 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1567 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1568 | } |
| 1569 | return (c); |
| 1570 | } |
| 1571 | |
| 1572 | /* |
| 1573 | * issue an atapi command |
| 1574 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1575 | unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen, |
| 1576 | unsigned char *buffer, int buflen) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1577 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1578 | unsigned char c, err, mask, res; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1579 | int n; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1580 | |
| 1581 | ide_led(DEVICE_LED(device), 1); /* LED on */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1582 | |
| 1583 | /* Select device |
| 1584 | */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1585 | mask = ATA_STAT_BUSY | ATA_STAT_DRQ; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1586 | res = 0; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1587 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
| 1588 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1589 | if ((c & mask) != res) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1590 | printf("ATAPI_ISSUE: device %d not ready status %X\n", device, |
| 1591 | c); |
| 1592 | err = 0xFF; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1593 | goto AI_OUT; |
| 1594 | } |
| 1595 | /* write taskfile */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1596 | ide_outb(device, ATA_ERROR_REG, 0); /* no DMA, no overlaped */ |
| 1597 | ide_outb(device, ATA_SECT_CNT, 0); |
| 1598 | ide_outb(device, ATA_SECT_NUM, 0); |
| 1599 | ide_outb(device, ATA_CYL_LOW, (unsigned char) (buflen & 0xFF)); |
| 1600 | ide_outb(device, ATA_CYL_HIGH, |
| 1601 | (unsigned char) ((buflen >> 8) & 0xFF)); |
| 1602 | ide_outb(device, ATA_DEV_HD, ATA_LBA | ATA_DEVICE(device)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1603 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1604 | ide_outb(device, ATA_COMMAND, ATAPI_CMD_PACKET); |
| 1605 | udelay(50); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1606 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1607 | mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1608 | res = ATA_STAT_DRQ; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1609 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1610 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1611 | if ((c & mask) != res) { /* DRQ must be 1, BSY 0 */ |
| 1612 | printf("ATAPI_ISSUE: Error (no IRQ) before sending ccb dev %d status 0x%02x\n", |
| 1613 | device, c); |
| 1614 | err = 0xFF; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1615 | goto AI_OUT; |
| 1616 | } |
| 1617 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1618 | /* write command block */ |
| 1619 | output_data_shorts(device, (unsigned short *) ccb, ccblen / 2); |
| 1620 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1621 | /* ATAPI Command written wait for completition */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1622 | udelay(5000); /* device must set bsy */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1623 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1624 | mask = ATA_STAT_DRQ | ATA_STAT_BUSY | ATA_STAT_ERR; |
| 1625 | /* |
| 1626 | * if no data wait for DRQ = 0 BSY = 0 |
| 1627 | * if data wait for DRQ = 1 BSY = 0 |
| 1628 | */ |
| 1629 | res = 0; |
| 1630 | if (buflen) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1631 | res = ATA_STAT_DRQ; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1632 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
| 1633 | if ((c & mask) != res) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1634 | if (c & ATA_STAT_ERR) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1635 | err = (ide_inb(device, ATA_ERROR_REG)) >> 4; |
| 1636 | debug("atapi_issue 1 returned sense key %X status %02X\n", |
| 1637 | err, c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1638 | } else { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1639 | printf("ATAPI_ISSUE: (no DRQ) after sending ccb (%x) status 0x%02x\n", |
| 1640 | ccb[0], c); |
| 1641 | err = 0xFF; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1642 | } |
| 1643 | goto AI_OUT; |
| 1644 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1645 | n = ide_inb(device, ATA_CYL_HIGH); |
| 1646 | n <<= 8; |
| 1647 | n += ide_inb(device, ATA_CYL_LOW); |
| 1648 | if (n > buflen) { |
| 1649 | printf("ERROR, transfer bytes %d requested only %d\n", n, |
| 1650 | buflen); |
| 1651 | err = 0xff; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1652 | goto AI_OUT; |
| 1653 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1654 | if ((n == 0) && (buflen < 0)) { |
| 1655 | printf("ERROR, transfer bytes %d requested %d\n", n, buflen); |
| 1656 | err = 0xff; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1657 | goto AI_OUT; |
| 1658 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1659 | if (n != buflen) { |
| 1660 | debug("WARNING, transfer bytes %d not equal with requested %d\n", |
| 1661 | n, buflen); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1662 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1663 | if (n != 0) { /* data transfer */ |
| 1664 | debug("ATAPI_ISSUE: %d Bytes to transfer\n", n); |
| 1665 | /* we transfer shorts */ |
| 1666 | n >>= 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1667 | /* ok now decide if it is an in or output */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1668 | if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) { |
| 1669 | debug("Write to device\n"); |
| 1670 | output_data_shorts(device, (unsigned short *) buffer, |
| 1671 | n); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1672 | } else { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1673 | debug("Read from device @ %p shorts %d\n", buffer, n); |
| 1674 | input_data_shorts(device, (unsigned short *) buffer, |
| 1675 | n); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1676 | } |
| 1677 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1678 | udelay(5000); /* seems that some CD ROMs need this... */ |
| 1679 | mask = ATA_STAT_BUSY | ATA_STAT_ERR; |
| 1680 | res = 0; |
| 1681 | c = atapi_wait_mask(device, ATAPI_TIME_OUT, mask, res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1682 | if ((c & ATA_STAT_ERR) == ATA_STAT_ERR) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1683 | err = (ide_inb(device, ATA_ERROR_REG) >> 4); |
| 1684 | debug("atapi_issue 2 returned sense key %X status %X\n", err, |
| 1685 | c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1686 | } else { |
| 1687 | err = 0; |
| 1688 | } |
| 1689 | AI_OUT: |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1690 | ide_led(DEVICE_LED(device), 0); /* LED off */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1691 | return (err); |
| 1692 | } |
| 1693 | |
| 1694 | /* |
| 1695 | * sending the command to atapi_issue. If an status other than good |
| 1696 | * returns, an request_sense will be issued |
| 1697 | */ |
| 1698 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 1699 | #define ATAPI_DRIVE_NOT_READY 100 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1700 | #define ATAPI_UNIT_ATTN 10 |
| 1701 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1702 | unsigned char atapi_issue_autoreq(int device, |
| 1703 | unsigned char *ccb, |
| 1704 | int ccblen, |
| 1705 | unsigned char *buffer, int buflen) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1706 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1707 | unsigned char sense_data[18], sense_ccb[12]; |
| 1708 | unsigned char res, key, asc, ascq; |
| 1709 | int notready, unitattn; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1710 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1711 | unitattn = ATAPI_UNIT_ATTN; |
| 1712 | notready = ATAPI_DRIVE_NOT_READY; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1713 | |
| 1714 | retry: |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1715 | res = atapi_issue(device, ccb, ccblen, buffer, buflen); |
| 1716 | if (res == 0) |
| 1717 | return 0; /* Ok */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1718 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1719 | if (res == 0xFF) |
| 1720 | return 0xFF; /* error */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1721 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1722 | debug("(auto_req)atapi_issue returned sense key %X\n", res); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1723 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1724 | memset(sense_ccb, 0, sizeof(sense_ccb)); |
| 1725 | memset(sense_data, 0, sizeof(sense_data)); |
| 1726 | sense_ccb[0] = ATAPI_CMD_REQ_SENSE; |
| 1727 | sense_ccb[4] = 18; /* allocation Length */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1728 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1729 | res = atapi_issue(device, sense_ccb, 12, sense_data, 18); |
| 1730 | key = (sense_data[2] & 0xF); |
| 1731 | asc = (sense_data[12]); |
| 1732 | ascq = (sense_data[13]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1733 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1734 | debug("ATAPI_CMD_REQ_SENSE returned %x\n", res); |
| 1735 | debug(" Sense page: %02X key %02X ASC %02X ASCQ %02X\n", |
| 1736 | sense_data[0], key, asc, ascq); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1737 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1738 | if ((key == 0)) |
| 1739 | return 0; /* ok device ready */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1740 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1741 | if ((key == 6) || (asc == 0x29) || (asc == 0x28)) { /* Unit Attention */ |
| 1742 | if (unitattn-- > 0) { |
| 1743 | udelay(200 * 1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1744 | goto retry; |
| 1745 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1746 | printf("Unit Attention, tried %d\n", ATAPI_UNIT_ATTN); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1747 | goto error; |
| 1748 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1749 | if ((asc == 0x4) && (ascq == 0x1)) { |
| 1750 | /* not ready, but will be ready soon */ |
| 1751 | if (notready-- > 0) { |
| 1752 | udelay(200 * 1000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1753 | goto retry; |
| 1754 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1755 | printf("Drive not ready, tried %d times\n", |
| 1756 | ATAPI_DRIVE_NOT_READY); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1757 | goto error; |
| 1758 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1759 | if (asc == 0x3a) { |
| 1760 | debug("Media not present\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1761 | goto error; |
| 1762 | } |
wdenk | c7de829 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 1763 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1764 | printf("ERROR: Unknown Sense key %02X ASC %02X ASCQ %02X\n", key, asc, |
| 1765 | ascq); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1766 | error: |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1767 | debug("ERROR Sense key %02X ASC %02X ASCQ %02X\n", key, asc, ascq); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1768 | return (0xFF); |
| 1769 | } |
| 1770 | |
| 1771 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1772 | static void atapi_inquiry(block_dev_desc_t *dev_desc) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1773 | { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1774 | unsigned char ccb[12]; /* Command descriptor block */ |
| 1775 | unsigned char iobuf[64]; /* temp buf */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1776 | unsigned char c; |
| 1777 | int device; |
| 1778 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1779 | device = dev_desc->dev; |
| 1780 | dev_desc->type = DEV_TYPE_UNKNOWN; /* not yet valid */ |
| 1781 | dev_desc->block_read = atapi_read; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1782 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1783 | memset(ccb, 0, sizeof(ccb)); |
| 1784 | memset(iobuf, 0, sizeof(iobuf)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1785 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1786 | ccb[0] = ATAPI_CMD_INQUIRY; |
| 1787 | ccb[4] = 40; /* allocation Legnth */ |
| 1788 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 40); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1789 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1790 | debug("ATAPI_CMD_INQUIRY returned %x\n", c); |
| 1791 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1792 | return; |
| 1793 | |
| 1794 | /* copy device ident strings */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1795 | ident_cpy((unsigned char *) dev_desc->vendor, &iobuf[8], 8); |
| 1796 | ident_cpy((unsigned char *) dev_desc->product, &iobuf[16], 16); |
| 1797 | ident_cpy((unsigned char *) dev_desc->revision, &iobuf[32], 5); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1798 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1799 | dev_desc->lun = 0; |
| 1800 | dev_desc->lba = 0; |
| 1801 | dev_desc->blksz = 0; |
| 1802 | dev_desc->type = iobuf[0] & 0x1f; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1803 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1804 | if ((iobuf[1] & 0x80) == 0x80) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1805 | dev_desc->removable = 1; |
| 1806 | else |
| 1807 | dev_desc->removable = 0; |
| 1808 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1809 | memset(ccb, 0, sizeof(ccb)); |
| 1810 | memset(iobuf, 0, sizeof(iobuf)); |
| 1811 | ccb[0] = ATAPI_CMD_START_STOP; |
| 1812 | ccb[4] = 0x03; /* start */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1813 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1814 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1815 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1816 | debug("ATAPI_CMD_START_STOP returned %x\n", c); |
| 1817 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1818 | return; |
| 1819 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1820 | memset(ccb, 0, sizeof(ccb)); |
| 1821 | memset(iobuf, 0, sizeof(iobuf)); |
| 1822 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1823 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1824 | debug("ATAPI_CMD_UNIT_TEST_READY returned %x\n", c); |
| 1825 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1826 | return; |
| 1827 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1828 | memset(ccb, 0, sizeof(ccb)); |
| 1829 | memset(iobuf, 0, sizeof(iobuf)); |
| 1830 | ccb[0] = ATAPI_CMD_READ_CAP; |
| 1831 | c = atapi_issue_autoreq(device, ccb, 12, (unsigned char *) iobuf, 8); |
| 1832 | debug("ATAPI_CMD_READ_CAP returned %x\n", c); |
| 1833 | if (c != 0) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1834 | return; |
| 1835 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1836 | debug("Read Cap: LBA %02X%02X%02X%02X blksize %02X%02X%02X%02X\n", |
| 1837 | iobuf[0], iobuf[1], iobuf[2], iobuf[3], |
| 1838 | iobuf[4], iobuf[5], iobuf[6], iobuf[7]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1839 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1840 | dev_desc->lba = ((unsigned long) iobuf[0] << 24) + |
| 1841 | ((unsigned long) iobuf[1] << 16) + |
| 1842 | ((unsigned long) iobuf[2] << 8) + ((unsigned long) iobuf[3]); |
| 1843 | dev_desc->blksz = ((unsigned long) iobuf[4] << 24) + |
| 1844 | ((unsigned long) iobuf[5] << 16) + |
| 1845 | ((unsigned long) iobuf[6] << 8) + ((unsigned long) iobuf[7]); |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1846 | #ifdef CONFIG_LBA48 |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1847 | /* ATAPI devices cannot use 48bit addressing (ATA/ATAPI v7) */ |
| 1848 | dev_desc->lba48 = 0; |
wdenk | 42dfe7a | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 1849 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1850 | return; |
| 1851 | } |
| 1852 | |
| 1853 | |
| 1854 | /* |
| 1855 | * atapi_read: |
| 1856 | * we transfer only one block per command, since the multiple DRQ per |
| 1857 | * command is not yet implemented |
| 1858 | */ |
| 1859 | #define ATAPI_READ_MAX_BYTES 2048 /* we read max 2kbytes */ |
| 1860 | #define ATAPI_READ_BLOCK_SIZE 2048 /* assuming CD part */ |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1861 | #define ATAPI_READ_MAX_BLOCK (ATAPI_READ_MAX_BYTES/ATAPI_READ_BLOCK_SIZE) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1862 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1863 | ulong atapi_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1864 | { |
| 1865 | ulong n = 0; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1866 | unsigned char ccb[12]; /* Command descriptor block */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1867 | ulong cnt; |
| 1868 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1869 | debug("atapi_read dev %d start %lX, blocks %lX buffer at %lX\n", |
| 1870 | device, blknr, blkcnt, (ulong) buffer); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1871 | |
| 1872 | do { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1873 | if (blkcnt > ATAPI_READ_MAX_BLOCK) |
| 1874 | cnt = ATAPI_READ_MAX_BLOCK; |
| 1875 | else |
| 1876 | cnt = blkcnt; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1877 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1878 | ccb[0] = ATAPI_CMD_READ_12; |
| 1879 | ccb[1] = 0; /* reserved */ |
| 1880 | ccb[2] = (unsigned char) (blknr >> 24) & 0xFF; /* MSB Block */ |
| 1881 | ccb[3] = (unsigned char) (blknr >> 16) & 0xFF; /* */ |
| 1882 | ccb[4] = (unsigned char) (blknr >> 8) & 0xFF; |
| 1883 | ccb[5] = (unsigned char) blknr & 0xFF; /* LSB Block */ |
| 1884 | ccb[6] = (unsigned char) (cnt >> 24) & 0xFF; /* MSB Block cnt */ |
| 1885 | ccb[7] = (unsigned char) (cnt >> 16) & 0xFF; |
| 1886 | ccb[8] = (unsigned char) (cnt >> 8) & 0xFF; |
| 1887 | ccb[9] = (unsigned char) cnt & 0xFF; /* LSB Block */ |
| 1888 | ccb[10] = 0; /* reserved */ |
| 1889 | ccb[11] = 0; /* reserved */ |
| 1890 | |
| 1891 | if (atapi_issue_autoreq(device, ccb, 12, |
| 1892 | (unsigned char *) buffer, |
| 1893 | cnt * ATAPI_READ_BLOCK_SIZE) |
| 1894 | == 0xFF) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1895 | return (n); |
| 1896 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1897 | n += cnt; |
| 1898 | blkcnt -= cnt; |
| 1899 | blknr += cnt; |
| 1900 | buffer += (cnt * ATAPI_READ_BLOCK_SIZE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1901 | } while (blkcnt > 0); |
| 1902 | return (n); |
| 1903 | } |
| 1904 | |
| 1905 | /* ------------------------------------------------------------------------- */ |
| 1906 | |
| 1907 | #endif /* CONFIG_ATAPI */ |
| 1908 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1909 | U_BOOT_CMD(ide, 5, 1, do_ide, |
| 1910 | "IDE sub-system", |
| 1911 | "reset - reset IDE controller\n" |
| 1912 | "ide info - show available IDE devices\n" |
| 1913 | "ide device [dev] - show or set current device\n" |
| 1914 | "ide part [dev] - print partition table of one or all IDE devices\n" |
| 1915 | "ide read addr blk# cnt\n" |
| 1916 | "ide write addr blk# cnt - read/write `cnt'" |
| 1917 | " blocks starting at block `blk#'\n" |
| 1918 | " to/from memory address `addr'"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1919 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 1920 | U_BOOT_CMD(diskboot, 3, 1, do_diskboot, |
| 1921 | "boot from IDE device", "loadAddr dev:part"); |