Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 3 | * (C) Copyright 2000-2011 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * IDE support |
| 9 | */ |
Albert Aribaud | 113bfe4 | 2010-08-08 05:17:06 +0530 | [diff] [blame] | 10 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 11 | #include <common.h> |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 12 | #include <blk.h> |
Simon Glass | 80778f5 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 13 | #include <dm.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 14 | #include <config.h> |
| 15 | #include <watchdog.h> |
| 16 | #include <command.h> |
| 17 | #include <image.h> |
| 18 | #include <asm/byteorder.h> |
Heiko Schocher | f98984c | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 19 | #include <asm/io.h> |
Simon Glass | 80778f5 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 20 | #include <dm/device-internal.h> |
| 21 | #include <dm/uclass-internal.h> |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 22 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 23 | #include <ide.h> |
| 24 | #include <ata.h> |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 25 | |
Uri Mashiach | 2d8d190 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 26 | #ifdef CONFIG_LED_STATUS |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 27 | # include <status_led.h> |
| 28 | #endif |
Grant Likely | 735dd97 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 29 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | /* Current I/O Device */ |
Bin Meng | 584f316 | 2017-09-10 05:12:53 -0700 | [diff] [blame] | 31 | static int curr_device; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 33 | int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 34 | { |
Simon Glass | 09ed0d6 | 2017-07-29 11:34:57 -0600 | [diff] [blame] | 35 | if (argc == 2) { |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 36 | if (strncmp(argv[1], "res", 3) == 0) { |
Simon Glass | 80778f5 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 37 | struct udevice *dev; |
| 38 | int ret; |
| 39 | |
Heiko Schocher | 5b8e76c | 2017-06-07 17:33:09 +0200 | [diff] [blame] | 40 | puts("\nReset IDE: "); |
Simon Glass | 80778f5 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 41 | ret = uclass_find_first_device(UCLASS_IDE, &dev); |
| 42 | ret = device_remove(dev, DM_REMOVE_NORMAL); |
| 43 | if (!ret) |
| 44 | ret = device_chld_unbind(dev, NULL); |
| 45 | if (ret) { |
| 46 | printf("Cannot remove IDE (err=%dE)\n", ret); |
| 47 | return CMD_RET_FAILURE; |
| 48 | } |
| 49 | |
| 50 | ret = uclass_first_device_err(UCLASS_IDE, &dev); |
| 51 | if (ret) { |
| 52 | printf("Init failed (err=%dE)\n", ret); |
| 53 | return CMD_RET_FAILURE; |
| 54 | } |
| 55 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 56 | return 0; |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 57 | } |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 58 | } |
Simon Glass | 09ed0d6 | 2017-07-29 11:34:57 -0600 | [diff] [blame] | 59 | |
Simon Glass | e33a5c6 | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 60 | return blk_common_cmd(argc, argv, UCLASS_IDE, &curr_device); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 63 | int do_diskboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 64 | { |
Rob Herring | 7405a13 | 2012-09-21 04:02:30 +0000 | [diff] [blame] | 65 | return common_diskboot(cmdtp, "ide", argc, argv); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 68 | U_BOOT_CMD(ide, 5, 1, do_ide, |
| 69 | "IDE sub-system", |
| 70 | "reset - reset IDE controller\n" |
| 71 | "ide info - show available IDE devices\n" |
| 72 | "ide device [dev] - show or set current device\n" |
| 73 | "ide part [dev] - print partition table of one or all IDE devices\n" |
| 74 | "ide read addr blk# cnt\n" |
| 75 | "ide write addr blk# cnt - read/write `cnt'" |
| 76 | " blocks starting at block `blk#'\n" |
| 77 | " to/from memory address `addr'"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 78 | |
Wolfgang Denk | 34c202c | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 79 | U_BOOT_CMD(diskboot, 3, 1, do_diskboot, |
| 80 | "boot from IDE device", "loadAddr dev:part"); |