blob: 784d9bbeacb47985d9727f47e4d84726715f9487 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassd97dc8a2016-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 Glassd97dc8a2016-05-01 11:36:11 -060010 */
11
12#include <common.h>
Simon Glassb8341f12017-07-29 11:35:15 -060013#include <ahci.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060014#include <blk.h>
Simon Glassf5a14af2016-05-01 11:36:26 -060015#include <dm.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060016#include <part.h>
Simon Glassd97dc8a2016-05-01 11:36:11 -060017#include <sata.h>
Tony Dinha7527fb2023-10-11 13:26:42 -070018#include <dm/device-internal.h>
19#include <dm/uclass-internal.h>
Simon Glassd97dc8a2016-05-01 11:36:11 -060020
Simon Glassb8341f12017-07-29 11:35:15 -060021int sata_reset(struct udevice *dev)
22{
23 struct ahci_ops *ops = ahci_get_ops(dev);
24
25 if (!ops->reset)
26 return -ENOSYS;
27
28 return ops->reset(dev);
29}
30
31int sata_dm_port_status(struct udevice *dev, int port)
32{
33 struct ahci_ops *ops = ahci_get_ops(dev);
34
35 if (!ops->port_status)
36 return -ENOSYS;
37
38 return ops->port_status(dev, port);
39}
40
41int sata_scan(struct udevice *dev)
42{
43 struct ahci_ops *ops = ahci_get_ops(dev);
44
45 if (!ops->scan)
46 return -ENOSYS;
47
48 return ops->scan(dev);
49}
50
Tony Dinha7527fb2023-10-11 13:26:42 -070051int sata_rescan(bool verbose)
52{
53 int ret;
54 struct udevice *dev;
55
56 if (verbose)
57 printf("Removing devices on SATA bus...\n");
58
59 blk_unbind_all(UCLASS_AHCI);
60
61 ret = uclass_find_first_device(UCLASS_AHCI, &dev);
62 if (ret || !dev) {
63 printf("Cannot find SATA device (err=%d)\n", ret);
Tony Dinhee2ce292023-11-02 11:51:15 -070064 return -ENOENT;
Tony Dinha7527fb2023-10-11 13:26:42 -070065 }
66
67 ret = device_remove(dev, DM_REMOVE_NORMAL);
68 if (ret) {
69 printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name, ret);
70 return -ENOSYS;
71 }
72
73 if (verbose)
74 printf("Rescanning SATA bus for devices...\n");
75
76 ret = uclass_probe_all(UCLASS_AHCI);
77
Tony Dinh10529202023-10-06 20:34:28 -070078 if (ret == -ENODEV) {
79 if (verbose)
80 printf("No SATA block device found\n");
81 return 0;
82 }
83
Tony Dinha7527fb2023-10-11 13:26:42 -070084 return ret;
85}
86
Simon Glassf5a14af2016-05-01 11:36:26 -060087static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
88 lbaint_t blkcnt, void *dst)
89{
90 return -ENOSYS;
91}
92
93static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
94 lbaint_t blkcnt, const void *buffer)
95{
96 return -ENOSYS;
97}
Simon Glassd97dc8a2016-05-01 11:36:11 -060098
Simon Glassf5a14af2016-05-01 11:36:26 -060099static const struct blk_ops sata_blk_ops = {
100 .read = sata_bread,
101 .write = sata_bwrite,
102};
103
104U_BOOT_DRIVER(sata_blk) = {
105 .name = "sata_blk",
106 .id = UCLASS_BLK,
107 .ops = &sata_blk_ops,
108};