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 | |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 12 | #define LOG_CATEGORY UCLASS_AHCI |
| 13 | |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 14 | #include <ahci.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 15 | #include <blk.h> |
Simon Glass | 7d741ac | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 16 | #include <dm.h> |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 17 | #include <log.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 18 | #include <part.h> |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 19 | #include <sata.h> |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 20 | #include <dm/device-internal.h> |
| 21 | #include <dm/uclass-internal.h> |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 22 | |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 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 | |
| 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; |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 39 | |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 40 | return ops->port_status(dev, port); |
| 41 | } |
| 42 | |
| 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 | |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 53 | int sata_rescan(bool verbose) |
| 54 | { |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 55 | struct uclass *uc; |
| 56 | struct udevice *dev; /* SATA controller */ |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 57 | int ret; |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 58 | |
| 59 | if (verbose) |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 60 | printf("scanning bus for devices...\n"); |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 61 | |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 62 | ret = uclass_get(UCLASS_AHCI, &uc); |
| 63 | if (ret) |
| 64 | return ret; |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 65 | |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 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 | } |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 78 | if (verbose) |
| 79 | printf("Rescanning SATA bus for devices...\n"); |
| 80 | |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 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); |
Tony Dinh | e240edf | 2023-10-06 20:34:28 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Heinrich Schuchardt | d499149 | 2024-08-14 09:10:37 +0200 | [diff] [blame] | 87 | return 0; |
Tony Dinh | a87cbb8 | 2023-10-11 13:26:42 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Simon Glass | 7d741ac | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 90 | static unsigned long sata_bread(struct udevice *dev, lbaint_t start, |
| 91 | lbaint_t blkcnt, void *dst) |
| 92 | { |
| 93 | return -ENOSYS; |
| 94 | } |
| 95 | |
| 96 | static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start, |
| 97 | lbaint_t blkcnt, const void *buffer) |
| 98 | { |
| 99 | return -ENOSYS; |
| 100 | } |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 101 | |
Simon Glass | 7d741ac | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 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 | }; |