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