Commit f19f1ecb6025f0e2afb237a59b24462c5340787a
Committed by
Jaehoon Chung
1 parent
752126a05a
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
dm: sata: Support driver model with the 'sata' command
Update this command to support driver model. This has a different way of starting and stopping SATA. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 3 changed files with 89 additions and 13 deletions Side-by-side Diff
cmd/sata.c
... | ... | @@ -11,33 +11,106 @@ |
11 | 11 | */ |
12 | 12 | |
13 | 13 | #include <common.h> |
14 | +#include <ahci.h> | |
15 | +#include <dm.h> | |
14 | 16 | #include <command.h> |
15 | 17 | #include <part.h> |
16 | 18 | #include <sata.h> |
19 | +#include <dm/device-internal.h> | |
20 | +#include <dm/uclass-internal.h> | |
17 | 21 | |
18 | 22 | static int sata_curr_device = -1; |
19 | 23 | |
24 | +int sata_remove(int devnum) | |
25 | +{ | |
26 | +#ifdef CONFIG_AHCI | |
27 | + struct udevice *dev; | |
28 | + int rc; | |
29 | + | |
30 | + rc = uclass_find_device(UCLASS_AHCI, devnum, &dev); | |
31 | + if (!rc && !dev) | |
32 | + rc = uclass_find_first_device(UCLASS_AHCI, &dev); | |
33 | + if (rc || !dev) { | |
34 | + printf("Cannot find SATA device %d (err=%d)\n", devnum, rc); | |
35 | + return CMD_RET_FAILURE; | |
36 | + } | |
37 | + | |
38 | + rc = device_remove(dev, DM_REMOVE_NORMAL); | |
39 | + if (rc) { | |
40 | + printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name, | |
41 | + rc); | |
42 | + return CMD_RET_FAILURE; | |
43 | + } | |
44 | + | |
45 | + return 0; | |
46 | +#else | |
47 | + return sata_stop(); | |
48 | +#endif | |
49 | +} | |
50 | + | |
51 | +int sata_probe(int devnum) | |
52 | +{ | |
53 | +#ifdef CONFIG_AHCI | |
54 | + struct udevice *dev; | |
55 | + struct udevice *blk; | |
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 | + rc = sata_scan(dev); | |
66 | + if (rc) { | |
67 | + printf("Cannot scan SATA device %d (err=%d)\n", devnum, rc); | |
68 | + return CMD_RET_FAILURE; | |
69 | + } | |
70 | + | |
71 | + rc = blk_get_from_parent(dev, &blk); | |
72 | + if (!rc) { | |
73 | + struct blk_desc *desc = dev_get_uclass_platdata(blk); | |
74 | + | |
75 | + if (desc->lba > 0 && desc->blksz > 0) | |
76 | + part_init(desc); | |
77 | + } | |
78 | + | |
79 | + return 0; | |
80 | +#else | |
81 | + return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS; | |
82 | +#endif | |
83 | +} | |
84 | + | |
20 | 85 | static int do_sata(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
21 | 86 | { |
22 | 87 | int rc = 0; |
23 | 88 | |
24 | - if (argc == 2 && strcmp(argv[1], "stop") == 0) | |
25 | - return sata_stop(); | |
89 | + if (argc >= 2) { | |
90 | + int devnum = 0; | |
26 | 91 | |
27 | - if (argc == 2 && strcmp(argv[1], "init") == 0) { | |
28 | - if (sata_curr_device != -1) | |
29 | - sata_stop(); | |
92 | + if (argc == 3) | |
93 | + devnum = (int)simple_strtoul(argv[2], NULL, 10); | |
94 | + if (!strcmp(argv[1], "stop")) | |
95 | + return sata_remove(devnum); | |
30 | 96 | |
31 | - return (sata_initialize() < 0) ? | |
32 | - CMD_RET_FAILURE : CMD_RET_SUCCESS; | |
97 | + if (!strcmp(argv[1], "init")) { | |
98 | + if (sata_curr_device != -1) { | |
99 | + rc = sata_remove(devnum); | |
100 | + if (rc) | |
101 | + return rc; | |
102 | + } | |
103 | + | |
104 | + return sata_probe(devnum); | |
105 | + } | |
33 | 106 | } |
34 | 107 | |
35 | 108 | /* If the user has not yet run `sata init`, do it now */ |
36 | 109 | if (sata_curr_device == -1) { |
37 | - rc = sata_initialize(); | |
38 | - if (rc == -1) | |
110 | + rc = sata_probe(0); | |
111 | + if (rc < 0) | |
39 | 112 | return CMD_RET_FAILURE; |
40 | - sata_curr_device = rc; | |
113 | + sata_curr_device = 0; | |
41 | 114 | } |
42 | 115 | |
43 | 116 | return blk_common_cmd(argc, argv, IF_TYPE_SATA, &sata_curr_device); |
... | ... | @@ -47,7 +120,7 @@ |
47 | 120 | sata, 5, 1, do_sata, |
48 | 121 | "SATA sub system", |
49 | 122 | "init - init SATA sub system\n" |
50 | - "sata stop - disable SATA sub system\n" | |
123 | + "sata stop [dev] - disable SATA sub system or device\n" | |
51 | 124 | "sata info - show available SATA devices\n" |
52 | 125 | "sata device [dev] - show or set current device\n" |
53 | 126 | "sata part [dev] - print partition table\n" |
common/splash_source.c
include/sata.h
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | #define __SATA_H__ |
3 | 3 | #include <part.h> |
4 | 4 | |
5 | -#if !defined(CONFIG_DM_SCSI) | |
5 | +#if !defined(CONFIG_DM_SCSI) && !defined(CONFIG_AHCI) | |
6 | 6 | int init_sata(int dev); |
7 | 7 | int reset_sata(int dev); |
8 | 8 | int scan_sata(int dev); |
... | ... | @@ -17,6 +17,9 @@ |
17 | 17 | |
18 | 18 | extern struct blk_desc sata_dev_desc[]; |
19 | 19 | #endif |
20 | + | |
21 | +int sata_probe(int devnum); | |
22 | +int sata_remove(int devnum); | |
20 | 23 | |
21 | 24 | #endif |
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1
-
mentioned in commit 7e83f1