Tom Rini | 10e4779 | 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 | 2bc10cf | 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 | 4502755 | 2010-08-08 05:17:06 +0530 | [diff] [blame] | 10 | |
Simon Glass | 2ee8ada | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 11 | #include <blk.h> |
Simon Glass | 175e766 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 12 | #include <dm.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 13 | #include <config.h> |
| 14 | #include <watchdog.h> |
| 15 | #include <command.h> |
| 16 | #include <image.h> |
| 17 | #include <asm/byteorder.h> |
Heiko Schocher | 2559e0f | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 18 | #include <asm/io.h> |
Simon Glass | 175e766 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 19 | #include <dm/device-internal.h> |
| 20 | #include <dm/uclass-internal.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 21 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 22 | #include <ide.h> |
| 23 | #include <ata.h> |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 24 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 25 | #ifdef CONFIG_LED_STATUS |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | # include <status_led.h> |
| 27 | #endif |
Grant Likely | ffc2dd7 | 2007-02-20 09:04:34 +0100 | [diff] [blame] | 28 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | /* Current I/O Device */ |
Bin Meng | 1946db2 | 2017-09-10 05:12:53 -0700 | [diff] [blame] | 30 | static int curr_device; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 31 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 32 | int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 33 | { |
Simon Glass | 8a8b768 | 2017-07-29 11:34:57 -0600 | [diff] [blame] | 34 | if (argc == 2) { |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 35 | if (strncmp(argv[1], "res", 3) == 0) { |
Simon Glass | 175e766 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 36 | struct udevice *dev; |
| 37 | int ret; |
| 38 | |
Heiko Schocher | 65d94db | 2017-06-07 17:33:09 +0200 | [diff] [blame] | 39 | puts("\nReset IDE: "); |
Simon Glass | 175e766 | 2023-04-25 10:54:30 -0600 | [diff] [blame] | 40 | ret = uclass_find_first_device(UCLASS_IDE, &dev); |
| 41 | ret = device_remove(dev, DM_REMOVE_NORMAL); |
| 42 | if (!ret) |
| 43 | ret = device_chld_unbind(dev, NULL); |
| 44 | if (ret) { |
| 45 | printf("Cannot remove IDE (err=%dE)\n", ret); |
| 46 | return CMD_RET_FAILURE; |
| 47 | } |
| 48 | |
| 49 | ret = uclass_first_device_err(UCLASS_IDE, &dev); |
| 50 | if (ret) { |
| 51 | printf("Init failed (err=%dE)\n", ret); |
| 52 | return CMD_RET_FAILURE; |
| 53 | } |
| 54 | |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 55 | return 0; |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 56 | } |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 57 | } |
Simon Glass | 8a8b768 | 2017-07-29 11:34:57 -0600 | [diff] [blame] | 58 | |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame] | 59 | return blk_common_cmd(argc, argv, UCLASS_IDE, &curr_device); |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 60 | } |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 61 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 62 | int do_diskboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Simon Glass | 43a464a | 2016-05-01 11:36:00 -0600 | [diff] [blame] | 63 | { |
| 64 | return common_diskboot(cmdtp, "ide", argc, argv); |
| 65 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 66 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 67 | U_BOOT_CMD(ide, 5, 1, do_ide, |
| 68 | "IDE sub-system", |
| 69 | "reset - reset IDE controller\n" |
| 70 | "ide info - show available IDE devices\n" |
| 71 | "ide device [dev] - show or set current device\n" |
| 72 | "ide part [dev] - print partition table of one or all IDE devices\n" |
| 73 | "ide read addr blk# cnt\n" |
| 74 | "ide write addr blk# cnt - read/write `cnt'" |
| 75 | " blocks starting at block `blk#'\n" |
| 76 | " to/from memory address `addr'"); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | |
Wolfgang Denk | 2bc10cf | 2011-10-29 09:41:40 +0000 | [diff] [blame] | 78 | U_BOOT_CMD(diskboot, 3, 1, do_diskboot, |
| 79 | "boot from IDE device", "loadAddr dev:part"); |