]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
d97dc8a0 SG |
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]> | |
d97dc8a0 SG |
10 | */ |
11 | ||
101d9a6a HS |
12 | #define LOG_CATEGORY UCLASS_AHCI |
13 | ||
b8341f1c | 14 | #include <ahci.h> |
e6f6f9e6 | 15 | #include <blk.h> |
f5a14af9 | 16 | #include <dm.h> |
101d9a6a | 17 | #include <log.h> |
e6f6f9e6 | 18 | #include <part.h> |
d97dc8a0 | 19 | #include <sata.h> |
a7527fbb TD |
20 | #include <dm/device-internal.h> |
21 | #include <dm/uclass-internal.h> | |
d97dc8a0 | 22 | |
b8341f1c SG |
23 | int sata_reset(struct udevice *dev) |
24 | { | |
25 | struct ahci_ops *ops = ahci_get_ops(dev); | |
26 | ||
27 | if (!ops->reset) | |
28 | return -ENOSYS; | |
29 | ||
30 | return ops->reset(dev); | |
31 | } | |
32 | ||
33 | int sata_dm_port_status(struct udevice *dev, int port) | |
34 | { | |
35 | struct ahci_ops *ops = ahci_get_ops(dev); | |
36 | ||
37 | if (!ops->port_status) | |
38 | return -ENOSYS; | |
d97dc8a0 | 39 | |
b8341f1c SG |
40 | return ops->port_status(dev, port); |
41 | } | |
42 | ||
43 | int sata_scan(struct udevice *dev) | |
44 | { | |
45 | struct ahci_ops *ops = ahci_get_ops(dev); | |
46 | ||
47 | if (!ops->scan) | |
48 | return -ENOSYS; | |
49 | ||
50 | return ops->scan(dev); | |
51 | } | |
52 | ||
a7527fbb TD |
53 | int sata_rescan(bool verbose) |
54 | { | |
101d9a6a HS |
55 | struct uclass *uc; |
56 | struct udevice *dev; /* SATA controller */ | |
a7527fbb | 57 | int ret; |
a7527fbb TD |
58 | |
59 | if (verbose) | |
101d9a6a HS |
60 | printf("scanning bus for devices...\n"); |
61 | ||
62 | ret = uclass_get(UCLASS_AHCI, &uc); | |
63 | if (ret) | |
64 | return ret; | |
65 | ||
66 | /* Remove all children of SATA devices (blk and bootdev) */ | |
67 | uclass_foreach_dev(dev, uc) { | |
68 | log_debug("unbind %s\n", dev->name); | |
69 | ret = device_chld_remove(dev, NULL, DM_REMOVE_NORMAL); | |
70 | if (!ret) | |
71 | ret = device_chld_unbind(dev, NULL); | |
72 | if (ret && verbose) { | |
73 | log_err("Unbinding from %s failed (%dE)\n", | |
74 | dev->name, ret); | |
75 | } | |
a7527fbb TD |
76 | } |
77 | ||
78 | if (verbose) | |
79 | printf("Rescanning SATA bus for devices...\n"); | |
80 | ||
101d9a6a HS |
81 | uclass_foreach_dev_probe(UCLASS_AHCI, dev) { |
82 | ret = sata_scan(dev); | |
83 | if (ret && verbose) | |
84 | log_err("Scanning %s failed (%dE)\n", dev->name, ret); | |
1052920a TD |
85 | } |
86 | ||
101d9a6a | 87 | return 0; |
a7527fbb TD |
88 | } |
89 | ||
f5a14af9 SG |
90 | static unsigned long sata_bread(struct udevice *dev, lbaint_t start, |
91 | lbaint_t blkcnt, void *dst) | |
92 | { | |
93 | return -ENOSYS; | |
94 | } | |
95 | ||
96 | static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start, | |
97 | lbaint_t blkcnt, const void *buffer) | |
98 | { | |
99 | return -ENOSYS; | |
100 | } | |
d97dc8a0 | 101 | |
f5a14af9 SG |
102 | static const struct blk_ops sata_blk_ops = { |
103 | .read = sata_bread, | |
104 | .write = sata_bwrite, | |
105 | }; | |
106 | ||
107 | U_BOOT_DRIVER(sata_blk) = { | |
108 | .name = "sata_blk", | |
109 | .id = UCLASS_BLK, | |
110 | .ops = &sata_blk_ops, | |
111 | }; |