Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | d97dc8a | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 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> |
Simon Glass | d97dc8a | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | b8341f1 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 13 | #include <ahci.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 14 | #include <blk.h> |
Simon Glass | f5a14af | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 16 | #include <part.h> |
Simon Glass | d97dc8a | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 17 | #include <sata.h> |
Tony Dinh | a7527fb | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 18 | #include <dm/device-internal.h> |
| 19 | #include <dm/uclass-internal.h> |
Simon Glass | d97dc8a | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 20 | |
Simon Glass | b8341f1 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 21 | int 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 | |
| 31 | int 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 | |
| 41 | int 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 Dinh | a7527fb | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 51 | int 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 Dinh | ee2ce29 | 2023-11-02 11:51:15 -0700 | [diff] [blame] | 64 | return -ENOENT; |
Tony Dinh | a7527fb | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 65 | } |
| 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 Dinh | 1052920 | 2023-10-06 20:34:28 -0700 | [diff] [blame] | 78 | if (ret == -ENODEV) { |
| 79 | if (verbose) |
| 80 | printf("No SATA block device found\n"); |
| 81 | return 0; |
| 82 | } |
| 83 | |
Tony Dinh | a7527fb | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 84 | return ret; |
| 85 | } |
| 86 | |
Simon Glass | f5a14af | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 87 | static unsigned long sata_bread(struct udevice *dev, lbaint_t start, |
| 88 | lbaint_t blkcnt, void *dst) |
| 89 | { |
| 90 | return -ENOSYS; |
| 91 | } |
| 92 | |
| 93 | static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start, |
| 94 | lbaint_t blkcnt, const void *buffer) |
| 95 | { |
| 96 | return -ENOSYS; |
| 97 | } |
Simon Glass | d97dc8a | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 98 | |
Simon Glass | f5a14af | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 99 | static const struct blk_ops sata_blk_ops = { |
| 100 | .read = sata_bread, |
| 101 | .write = sata_bwrite, |
| 102 | }; |
| 103 | |
| 104 | U_BOOT_DRIVER(sata_blk) = { |
| 105 | .name = "sata_blk", |
| 106 | .id = UCLASS_BLK, |
| 107 | .ops = &sata_blk_ops, |
| 108 | }; |