blob: 84437d3d346b4f261f000f3f578a382c6e477699 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass3665a402016-05-01 11:36:11 -06002/*
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>
Simon Glass3665a402016-05-01 11:36:11 -060010 */
11
Simon Glass821bb522017-07-29 11:35:15 -060012#include <ahci.h>
Simon Glass655306c2020-05-10 11:39:58 -060013#include <blk.h>
Simon Glass7d741ac2016-05-01 11:36:26 -060014#include <dm.h>
Simon Glass655306c2020-05-10 11:39:58 -060015#include <part.h>
Simon Glass3665a402016-05-01 11:36:11 -060016#include <sata.h>
Tony Dinha87cbb82023-10-11 13:26:42 -070017#include <dm/device-internal.h>
18#include <dm/uclass-internal.h>
Simon Glass3665a402016-05-01 11:36:11 -060019
Simon Glass821bb522017-07-29 11:35:15 -060020int sata_reset(struct udevice *dev)
21{
22 struct ahci_ops *ops = ahci_get_ops(dev);
23
24 if (!ops->reset)
25 return -ENOSYS;
26
27 return ops->reset(dev);
28}
29
30int sata_dm_port_status(struct udevice *dev, int port)
31{
32 struct ahci_ops *ops = ahci_get_ops(dev);
33
34 if (!ops->port_status)
35 return -ENOSYS;
Simon Glass3665a402016-05-01 11:36:11 -060036
Simon Glass821bb522017-07-29 11:35:15 -060037 return ops->port_status(dev, port);
38}
39
40int sata_scan(struct udevice *dev)
41{
42 struct ahci_ops *ops = ahci_get_ops(dev);
43
44 if (!ops->scan)
45 return -ENOSYS;
46
47 return ops->scan(dev);
48}
49
Tony Dinha87cbb82023-10-11 13:26:42 -070050int sata_rescan(bool verbose)
51{
52 int ret;
53 struct udevice *dev;
54
55 if (verbose)
56 printf("Removing devices on SATA bus...\n");
57
58 blk_unbind_all(UCLASS_AHCI);
59
60 ret = uclass_find_first_device(UCLASS_AHCI, &dev);
61 if (ret || !dev) {
62 printf("Cannot find SATA device (err=%d)\n", ret);
Tony Dinh81356b42023-11-02 11:51:15 -070063 return -ENOENT;
Tony Dinha87cbb82023-10-11 13:26:42 -070064 }
65
66 ret = device_remove(dev, DM_REMOVE_NORMAL);
67 if (ret) {
68 printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name, ret);
69 return -ENOSYS;
70 }
71
72 if (verbose)
73 printf("Rescanning SATA bus for devices...\n");
74
75 ret = uclass_probe_all(UCLASS_AHCI);
76
Tony Dinhe240edf2023-10-06 20:34:28 -070077 if (ret == -ENODEV) {
78 if (verbose)
79 printf("No SATA block device found\n");
80 return 0;
81 }
82
Tony Dinha87cbb82023-10-11 13:26:42 -070083 return ret;
84}
85
Simon Glass7d741ac2016-05-01 11:36:26 -060086static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
87 lbaint_t blkcnt, void *dst)
88{
89 return -ENOSYS;
90}
91
92static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
93 lbaint_t blkcnt, const void *buffer)
94{
95 return -ENOSYS;
96}
Simon Glass3665a402016-05-01 11:36:11 -060097
Simon Glass7d741ac2016-05-01 11:36:26 -060098static const struct blk_ops sata_blk_ops = {
99 .read = sata_bread,
100 .write = sata_bwrite,
101};
102
103U_BOOT_DRIVER(sata_blk) = {
104 .name = "sata_blk",
105 .id = UCLASS_BLK,
106 .ops = &sata_blk_ops,
107};