1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2000-2005, DENX Software Engineering
4 * Wolfgang Denk <wd@denx.de>
5 * Copyright (C) Procsys. All rights reserved.
6 * Mushtaq Khan <mushtaq_k@procsys.com>
7 * <mushtaqk_921@yahoo.co.in>
8 * Copyright (C) 2008 Freescale Semiconductor, Inc.
9 * Dave Liu <daveliu@freescale.com>
10 */
11
12 #define LOG_CATEGORY UCLASS_AHCI
13
14 #include <ahci.h>
15 #include <blk.h>
16 #include <dm.h>
17 #include <log.h>
18 #include <part.h>
19 #include <sata.h>
20 #include <dm/device-internal.h>
21 #include <dm/uclass-internal.h>
22
sata_reset(struct udevice * dev)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
sata_dm_port_status(struct udevice * dev,int port)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;
39
40 return ops->port_status(dev, port);
41 }
42
sata_scan(struct udevice * dev)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
sata_rescan(bool verbose)53 int sata_rescan(bool verbose)
54 {
55 struct uclass *uc;
56 struct udevice *dev; /* SATA controller */
57 int ret;
58
59 if (verbose)
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 }
76 }
77
78 if (verbose)
79 printf("Rescanning SATA bus for devices...\n");
80
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);
85 }
86
87 return 0;
88 }
89
sata_bread(struct udevice * dev,lbaint_t start,lbaint_t blkcnt,void * dst)90 static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
91 lbaint_t blkcnt, void *dst)
92 {
93 return -ENOSYS;
94 }
95
sata_bwrite(struct udevice * dev,lbaint_t start,lbaint_t blkcnt,const void * buffer)96 static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
97 lbaint_t blkcnt, const void *buffer)
98 {
99 return -ENOSYS;
100 }
101
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 };
112