]> Git Repo - J-u-boot.git/blame - cmd/sata.c
bootm: Drop arguments from do_bootm_states()
[J-u-boot.git] / cmd / sata.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
c7057b52
DL
2/*
3 * Copyright (C) 2000-2005, DENX Software Engineering
4 * Wolfgang Denk <[email protected]>
5 * Copyright (C) Procsys. All rights reserved.
6 * Mushtaq Khan <[email protected]>
7 * <[email protected]>
8 * Copyright (C) 2008 Freescale Semiconductor, Inc.
9 * Dave Liu <[email protected]>
c7057b52
DL
10 */
11
12#include <common.h>
f19f1ecb 13#include <ahci.h>
e6f6f9e6 14#include <blk.h>
f19f1ecb 15#include <dm.h>
c7057b52
DL
16#include <command.h>
17#include <part.h>
18#include <sata.h>
f19f1ecb
SG
19#include <dm/device-internal.h>
20#include <dm/uclass-internal.h>
c7057b52 21
088f1b19 22static int sata_curr_device = -1;
c7057b52 23
f19f1ecb
SG
24int sata_remove(int devnum)
25{
26#ifdef CONFIG_AHCI
27 struct udevice *dev;
28 int rc;
29
e33a5c6b 30 blk_unbind_all(UCLASS_AHCI);
2d7818d0 31
f19f1ecb
SG
32 rc = uclass_find_device(UCLASS_AHCI, devnum, &dev);
33 if (!rc && !dev)
34 rc = uclass_find_first_device(UCLASS_AHCI, &dev);
35 if (rc || !dev) {
36 printf("Cannot find SATA device %d (err=%d)\n", devnum, rc);
37 return CMD_RET_FAILURE;
38 }
39
40 rc = device_remove(dev, DM_REMOVE_NORMAL);
41 if (rc) {
42 printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name,
43 rc);
44 return CMD_RET_FAILURE;
45 }
46
47 return 0;
48#else
49 return sata_stop();
50#endif
51}
52
53int sata_probe(int devnum)
54{
55#ifdef CONFIG_AHCI
56 struct udevice *dev;
f19f1ecb
SG
57 int rc;
58
59 rc = uclass_get_device(UCLASS_AHCI, devnum, &dev);
60 if (rc)
61 rc = uclass_find_first_device(UCLASS_AHCI, &dev);
62 if (rc) {
63 printf("Cannot probe SATA device %d (err=%d)\n", devnum, rc);
64 return CMD_RET_FAILURE;
65 }
b3860bfe
MZ
66 if (!dev) {
67 printf("No SATA device found!\n");
68 return CMD_RET_FAILURE;
69 }
f19f1ecb
SG
70 rc = sata_scan(dev);
71 if (rc) {
72 printf("Cannot scan SATA device %d (err=%d)\n", devnum, rc);
73 return CMD_RET_FAILURE;
74 }
75
f19f1ecb
SG
76 return 0;
77#else
78 return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
79#endif
80}
81
09140113
SG
82static int do_sata(struct cmd_tbl *cmdtp, int flag, int argc,
83 char *const argv[])
c7057b52
DL
84{
85 int rc = 0;
86
f19f1ecb
SG
87 if (argc >= 2) {
88 int devnum = 0;
89
90 if (argc == 3)
0b1284eb 91 devnum = (int)dectoul(argv[2], NULL);
f19f1ecb
SG
92 if (!strcmp(argv[1], "stop"))
93 return sata_remove(devnum);
d957c28a 94
f19f1ecb
SG
95 if (!strcmp(argv[1], "init")) {
96 if (sata_curr_device != -1) {
97 rc = sata_remove(devnum);
98 if (rc)
99 return rc;
100 }
d957c28a 101
f19f1ecb
SG
102 return sata_probe(devnum);
103 }
d957c28a 104 }
cf7e399f
MF
105
106 /* If the user has not yet run `sata init`, do it now */
aa6ab905 107 if (sata_curr_device == -1) {
f19f1ecb 108 rc = sata_probe(0);
7e83f1d5
TK
109 if (rc)
110 return rc;
f19f1ecb 111 sata_curr_device = 0;
aa6ab905 112 }
cf7e399f 113
e33a5c6b 114 return blk_common_cmd(argc, argv, UCLASS_AHCI, &sata_curr_device);
c7057b52
DL
115}
116
117U_BOOT_CMD(
118 sata, 5, 1, do_sata,
2fb2604d 119 "SATA sub system",
85dafbb8 120 "init - init SATA sub system\n"
f19f1ecb 121 "sata stop [dev] - disable SATA sub system or device\n"
c7057b52
DL
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"
a89c33db
WD
126 "sata write addr blk# cnt"
127);
This page took 0.515035 seconds and 4 git commands to generate.