]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - cmd/sata.c
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>
18 #include <dm/device-internal.h>
19 #include <dm/uclass-internal.h>
21 static int sata_curr_device
= -1;
23 int sata_remove(int devnum
)
29 rc
= uclass_find_device(UCLASS_AHCI
, devnum
, &dev
);
31 rc
= uclass_find_first_device(UCLASS_AHCI
, &dev
);
33 printf("Cannot find SATA device %d (err=%d)\n", devnum
, rc
);
34 return CMD_RET_FAILURE
;
37 rc
= device_remove(dev
, DM_REMOVE_NORMAL
);
39 printf("Cannot remove SATA device '%s' (err=%d)\n", dev
->name
,
41 return CMD_RET_FAILURE
;
50 int sata_probe(int devnum
)
57 rc
= uclass_get_device(UCLASS_AHCI
, devnum
, &dev
);
59 rc
= uclass_find_first_device(UCLASS_AHCI
, &dev
);
61 printf("Cannot probe SATA device %d (err=%d)\n", devnum
, rc
);
62 return CMD_RET_FAILURE
;
66 printf("Cannot scan SATA device %d (err=%d)\n", devnum
, rc
);
67 return CMD_RET_FAILURE
;
70 rc
= blk_get_from_parent(dev
, &blk
);
72 struct blk_desc
*desc
= dev_get_uclass_platdata(blk
);
74 if (desc
->lba
> 0 && desc
->blksz
> 0)
80 return sata_initialize() < 0 ? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
84 static int do_sata(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
92 devnum
= (int)simple_strtoul(argv
[2], NULL
, 10);
93 if (!strcmp(argv
[1], "stop"))
94 return sata_remove(devnum
);
96 if (!strcmp(argv
[1], "init")) {
97 if (sata_curr_device
!= -1) {
98 rc
= sata_remove(devnum
);
103 return sata_probe(devnum
);
107 /* If the user has not yet run `sata init`, do it now */
108 if (sata_curr_device
== -1) {
112 sata_curr_device
= 0;
115 return blk_common_cmd(argc
, argv
, IF_TYPE_SATA
, &sata_curr_device
);
121 "init - init SATA sub system\n"
122 "sata stop [dev] - disable SATA sub system or device\n"
123 "sata info - show available SATA devices\n"
124 "sata device [dev] - show or set current device\n"
125 "sata part [dev] - print partition table\n"
126 "sata read addr blk# cnt\n"
127 "sata write addr blk# cnt"