]> Git Repo - J-u-boot.git/blob - cmd/sata.c
Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[J-u-boot.git] / cmd / sata.c
1 // SPDX-License-Identifier: GPL-2.0+
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]>
10  */
11
12 #include <ahci.h>
13 #include <blk.h>
14 #include <dm.h>
15 #include <command.h>
16 #include <part.h>
17 #include <sata.h>
18 #include <dm/device-internal.h>
19 #include <dm/uclass-internal.h>
20
21 static int sata_curr_device = -1;
22
23 int sata_remove(int devnum)
24 {
25 #ifdef CONFIG_AHCI
26         struct udevice *dev;
27         int rc;
28
29         blk_unbind_all(UCLASS_AHCI);
30
31         rc = uclass_find_device(UCLASS_AHCI, devnum, &dev);
32         if (!rc && !dev)
33                 rc = uclass_find_first_device(UCLASS_AHCI, &dev);
34         if (rc || !dev) {
35                 printf("Cannot find SATA device %d (err=%d)\n", devnum, rc);
36                 return CMD_RET_FAILURE;
37         }
38
39         rc = device_remove(dev, DM_REMOVE_NORMAL);
40         if (rc) {
41                 printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name,
42                        rc);
43                 return CMD_RET_FAILURE;
44         }
45
46         return 0;
47 #else
48         return sata_stop();
49 #endif
50 }
51
52 int sata_probe(int devnum)
53 {
54 #ifdef CONFIG_AHCI
55         struct udevice *dev;
56         int rc;
57
58         rc = uclass_get_device(UCLASS_AHCI, devnum, &dev);
59         if (rc)
60                 rc = uclass_find_first_device(UCLASS_AHCI, &dev);
61         if (rc) {
62                 printf("Cannot probe SATA device %d (err=%d)\n", devnum, rc);
63                 return CMD_RET_FAILURE;
64         }
65         if (!dev) {
66                 printf("No SATA device found!\n");
67                 return CMD_RET_FAILURE;
68         }
69         rc = sata_scan(dev);
70         if (rc) {
71                 printf("Cannot scan SATA device %d (err=%d)\n", devnum, rc);
72                 return CMD_RET_FAILURE;
73         }
74
75         return 0;
76 #else
77         return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
78 #endif
79 }
80
81 static int do_sata(struct cmd_tbl *cmdtp, int flag, int argc,
82                    char *const argv[])
83 {
84         int rc = 0;
85
86         if (argc >= 2) {
87                 int devnum = 0;
88
89                 if (argc == 3)
90                         devnum = (int)dectoul(argv[2], NULL);
91                 if (!strcmp(argv[1], "stop"))
92                         return sata_remove(devnum);
93
94                 if (!strcmp(argv[1], "init")) {
95                         if (sata_curr_device != -1) {
96                                 rc = sata_remove(devnum);
97                                 if (rc)
98                                         return rc;
99                         }
100
101                         return sata_probe(devnum);
102                 }
103         }
104
105         /* If the user has not yet run `sata init`, do it now */
106         if (sata_curr_device == -1) {
107                 rc = sata_probe(0);
108                 if (rc)
109                         return rc;
110                 sata_curr_device = 0;
111         }
112
113         return blk_common_cmd(argc, argv, UCLASS_AHCI, &sata_curr_device);
114 }
115
116 U_BOOT_CMD(
117         sata, 5, 1, do_sata,
118         "SATA sub system",
119         "init - init SATA sub system\n"
120         "sata stop [dev] - disable SATA sub system or device\n"
121         "sata info - show available SATA devices\n"
122         "sata device [dev] - show or set current device\n"
123         "sata part [dev] - print partition table\n"
124         "sata read addr blk# cnt\n"
125         "sata write addr blk# cnt"
126 );
This page took 0.02992 seconds and 4 git commands to generate.