blob: ddc87d3a0bb95d0f36789267d5ac0c709c963ce6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00002/*
Wolfgang Denk2bc10cf2011-10-29 09:41:40 +00003 * (C) Copyright 2000-2011
wdenkc6097192002-11-03 00:24:07 +00004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkc6097192002-11-03 00:24:07 +00005 */
6
7/*
8 * IDE support
9 */
Albert Aribaud45027552010-08-08 05:17:06 +053010
wdenkc6097192002-11-03 00:24:07 +000011#include <common.h>
Simon Glass2ee8ada2016-02-29 15:25:52 -070012#include <blk.h>
Simon Glass175e7662023-04-25 10:54:30 -060013#include <dm.h>
wdenkc6097192002-11-03 00:24:07 +000014#include <config.h>
15#include <watchdog.h>
16#include <command.h>
17#include <image.h>
18#include <asm/byteorder.h>
Heiko Schocher2559e0f2007-08-28 17:39:14 +020019#include <asm/io.h>
Simon Glass175e7662023-04-25 10:54:30 -060020#include <dm/device-internal.h>
21#include <dm/uclass-internal.h>
Grant Likelyffc2dd72007-02-20 09:04:34 +010022
wdenkc6097192002-11-03 00:24:07 +000023#include <ide.h>
24#include <ata.h>
Grant Likelyffc2dd72007-02-20 09:04:34 +010025
Uri Mashiach4892d392017-01-19 10:51:45 +020026#ifdef CONFIG_LED_STATUS
wdenkc6097192002-11-03 00:24:07 +000027# include <status_led.h>
28#endif
Grant Likelyffc2dd72007-02-20 09:04:34 +010029
wdenkc6097192002-11-03 00:24:07 +000030/* Current I/O Device */
Bin Meng1946db22017-09-10 05:12:53 -070031static int curr_device;
wdenkc6097192002-11-03 00:24:07 +000032
Simon Glassed38aef2020-05-10 11:40:03 -060033int do_ide(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glass43a464a2016-05-01 11:36:00 -060034{
Simon Glass8a8b7682017-07-29 11:34:57 -060035 if (argc == 2) {
Simon Glass43a464a2016-05-01 11:36:00 -060036 if (strncmp(argv[1], "res", 3) == 0) {
Simon Glass175e7662023-04-25 10:54:30 -060037 struct udevice *dev;
38 int ret;
39
Heiko Schocher65d94db2017-06-07 17:33:09 +020040 puts("\nReset IDE: ");
Simon Glass175e7662023-04-25 10:54:30 -060041 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
Simon Glass43a464a2016-05-01 11:36:00 -060056 return 0;
Simon Glass43a464a2016-05-01 11:36:00 -060057 }
Simon Glass43a464a2016-05-01 11:36:00 -060058 }
Simon Glass8a8b7682017-07-29 11:34:57 -060059
Simon Glassdbfa32c2022-08-11 19:34:59 -060060 return blk_common_cmd(argc, argv, UCLASS_IDE, &curr_device);
Simon Glass43a464a2016-05-01 11:36:00 -060061}
wdenkf602aa02004-03-13 23:29:43 +000062
Simon Glassed38aef2020-05-10 11:40:03 -060063int do_diskboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glass43a464a2016-05-01 11:36:00 -060064{
65 return common_diskboot(cmdtp, "ide", argc, argv);
66}
wdenkc6097192002-11-03 00:24:07 +000067
Wolfgang Denk2bc10cf2011-10-29 09:41:40 +000068U_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'");
wdenk57b2d802003-06-27 21:31:46 +000078
Wolfgang Denk2bc10cf2011-10-29 09:41:40 +000079U_BOOT_CMD(diskboot, 3, 1, do_diskboot,
80 "boot from IDE device", "loadAddr dev:part");