1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2000-2005, DENX Software Engineering
4 * Wolfgang Denk <wd@denx.de>
5 * Copyright (C) Procsys. All rights reserved.
6 * Mushtaq Khan <mushtaq_k@procsys.com>
7 * <mushtaqk_921@yahoo.co.in>
8 * Copyright (C) 2008 Freescale Semiconductor, Inc.
9 * Dave Liu <daveliu@freescale.com>
19 #include <dm/device-internal.h>
20 #include <dm/uclass-internal.h>
22 static int sata_curr_device = -1;
24 int sata_remove(int devnum)
30 blk_unbind_all(IF_TYPE_SATA);
32 rc = uclass_find_device(UCLASS_AHCI, devnum, &dev);
34 rc = uclass_find_first_device(UCLASS_AHCI, &dev);
36 printf("Cannot find SATA device %d (err=%d)\n", devnum, rc);
37 return CMD_RET_FAILURE;
40 rc = device_remove(dev, DM_REMOVE_NORMAL);
42 printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name,
44 return CMD_RET_FAILURE;
53 int sata_probe(int devnum)
59 rc = uclass_get_device(UCLASS_AHCI, devnum, &dev);
61 rc = uclass_find_first_device(UCLASS_AHCI, &dev);
63 printf("Cannot probe SATA device %d (err=%d)\n", devnum, rc);
64 return CMD_RET_FAILURE;
67 printf("No SATA device found!\n");
68 return CMD_RET_FAILURE;
72 printf("Cannot scan SATA device %d (err=%d)\n", devnum, rc);
73 return CMD_RET_FAILURE;
78 return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
82 static int do_sata(struct cmd_tbl *cmdtp, int flag, int argc,
91 devnum = (int)simple_strtoul(argv[2], NULL, 10);
92 if (!strcmp(argv[1], "stop"))
93 return sata_remove(devnum);
95 if (!strcmp(argv[1], "init")) {
96 if (sata_curr_device != -1) {
97 rc = sata_remove(devnum);
102 return sata_probe(devnum);
106 /* If the user has not yet run `sata init`, do it now */
107 if (sata_curr_device == -1) {
111 sata_curr_device = 0;
114 return blk_common_cmd(argc, argv, IF_TYPE_SATA, &sata_curr_device);
120 "init - init SATA sub system\n"
121 "sata stop [dev] - disable SATA sub system or device\n"
122 "sata info - show available SATA devices\n"
123 "sata device [dev] - show or set current device\n"
124 "sata part [dev] - print partition table\n"
125 "sata read addr blk# cnt\n"
126 "sata write addr blk# cnt"