1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2000-2011
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6 
7 /*
8  * IDE support
9  */
10 
11 #include <blk.h>
12 #include <dm.h>
13 #include <config.h>
14 #include <watchdog.h>
15 #include <command.h>
16 #include <image.h>
17 #include <asm/byteorder.h>
18 #include <asm/io.h>
19 #include <dm/device-internal.h>
20 #include <dm/uclass-internal.h>
21 
22 #include <ata.h>
23 
24 #ifdef CONFIG_LED_STATUS
25 # include <status_led.h>
26 #endif
27 
28 /* Current I/O Device	*/
29 static int curr_device;
30 
do_ide(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])31 int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
32 {
33 	if (argc == 2) {
34 		if (strncmp(argv[1], "res", 3) == 0) {
35 			struct udevice *dev;
36 			int ret;
37 
38 			puts("\nReset IDE: ");
39 			ret = uclass_find_first_device(UCLASS_IDE, &dev);
40 			ret = device_remove(dev, DM_REMOVE_NORMAL);
41 			if (!ret)
42 				ret = device_chld_unbind(dev, NULL);
43 			if (ret) {
44 				printf("Cannot remove IDE (err=%dE)\n", ret);
45 				return CMD_RET_FAILURE;
46 			}
47 
48 			ret = uclass_first_device_err(UCLASS_IDE, &dev);
49 			if (ret) {
50 				printf("Init failed (err=%dE)\n", ret);
51 				return CMD_RET_FAILURE;
52 			}
53 
54 			return 0;
55 		}
56 	}
57 
58 	return blk_common_cmd(argc, argv, UCLASS_IDE, &curr_device);
59 }
60 
do_diskboot(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])61 int do_diskboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
62 {
63 	return common_diskboot(cmdtp, "ide", argc, argv);
64 }
65 
66 U_BOOT_CMD(ide, 5, 1, do_ide,
67 	   "IDE sub-system",
68 	   "reset - reset IDE controller\n"
69 	   "ide info  - show available IDE devices\n"
70 	   "ide device [dev] - show or set current device\n"
71 	   "ide part [dev] - print partition table of one or all IDE devices\n"
72 	   "ide read  addr blk# cnt\n"
73 	   "ide write addr blk# cnt - read/write `cnt'"
74 	   " blocks starting at block `blk#'\n"
75 	   "    to/from memory address `addr'");
76 
77 U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
78 	   "boot from IDE device", "loadAddr dev:part");
79