]>
git.ipfire.org Git - people/ms/u-boot.git/blob - cmd/sata.c
2 * Copyright (C) 2000-2005, DENX Software Engineering
3 * Wolfgang Denk <wd@denx.de>
4 * Copyright (C) Procsys. All rights reserved.
5 * Mushtaq Khan <mushtaq_k@procsys.com>
6 * <mushtaqk_921@yahoo.co.in>
7 * Copyright (C) 2008 Freescale Semiconductor, Inc.
8 * Dave Liu <daveliu@freescale.com>
10 * SPDX-License-Identifier: GPL-2.0+
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 rc
= uclass_find_device(UCLASS_AHCI
, devnum
, &dev
);
32 rc
= uclass_find_first_device(UCLASS_AHCI
, &dev
);
34 printf("Cannot find SATA device %d (err=%d)\n", devnum
, rc
);
35 return CMD_RET_FAILURE
;
38 rc
= device_remove(dev
, DM_REMOVE_NORMAL
);
40 printf("Cannot remove SATA device '%s' (err=%d)\n", dev
->name
,
42 return CMD_RET_FAILURE
;
51 int sata_probe(int devnum
)
58 rc
= uclass_get_device(UCLASS_AHCI
, devnum
, &dev
);
60 rc
= uclass_find_first_device(UCLASS_AHCI
, &dev
);
62 printf("Cannot probe SATA device %d (err=%d)\n", devnum
, rc
);
63 return CMD_RET_FAILURE
;
67 printf("Cannot scan SATA device %d (err=%d)\n", devnum
, rc
);
68 return CMD_RET_FAILURE
;
71 rc
= blk_get_from_parent(dev
, &blk
);
73 struct blk_desc
*desc
= dev_get_uclass_platdata(blk
);
75 if (desc
->lba
> 0 && desc
->blksz
> 0)
81 return sata_initialize() < 0 ? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
85 static int do_sata(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
93 devnum
= (int)simple_strtoul(argv
[2], NULL
, 10);
94 if (!strcmp(argv
[1], "stop"))
95 return sata_remove(devnum
);
97 if (!strcmp(argv
[1], "init")) {
98 if (sata_curr_device
!= -1) {
99 rc
= sata_remove(devnum
);
104 return sata_probe(devnum
);
108 /* If the user has not yet run `sata init`, do it now */
109 if (sata_curr_device
== -1) {
112 return CMD_RET_FAILURE
;
113 sata_curr_device
= 0;
116 return blk_common_cmd(argc
, argv
, IF_TYPE_SATA
, &sata_curr_device
);
122 "init - init SATA sub system\n"
123 "sata stop [dev] - disable SATA sub system or device\n"
124 "sata info - show available SATA devices\n"
125 "sata device [dev] - show or set current device\n"
126 "sata part [dev] - print partition table\n"
127 "sata read addr blk# cnt\n"
128 "sata write addr blk# cnt"