2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-05-01 17:36:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000-2005, DENX Software Engineering
|
|
|
|
* Wolfgang Denk <wd@denx.de>
|
|
|
|
* Copyright (C) Procsys. All rights reserved.
|
|
|
|
* Mushtaq Khan <mushtaq_k@procsys.com>
|
|
|
|
* <mushtaqk_921@yahoo.co.in>
|
|
|
|
* Copyright (C) 2008 Freescale Semiconductor, Inc.
|
|
|
|
* Dave Liu <daveliu@freescale.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2017-07-29 17:35:15 +00:00
|
|
|
#include <ahci.h>
|
2020-05-10 17:39:58 +00:00
|
|
|
#include <blk.h>
|
2016-05-01 17:36:26 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:39:58 +00:00
|
|
|
#include <part.h>
|
2016-05-01 17:36:11 +00:00
|
|
|
#include <sata.h>
|
2023-10-11 20:26:42 +00:00
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
2016-05-01 17:36:11 +00:00
|
|
|
|
2017-07-29 17:35:15 +00:00
|
|
|
int sata_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ahci_ops *ops = ahci_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->reset)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
return ops->reset(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sata_dm_port_status(struct udevice *dev, int port)
|
|
|
|
{
|
|
|
|
struct ahci_ops *ops = ahci_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->port_status)
|
|
|
|
return -ENOSYS;
|
2016-05-01 17:36:11 +00:00
|
|
|
|
2017-07-29 17:35:15 +00:00
|
|
|
return ops->port_status(dev, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
int sata_scan(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ahci_ops *ops = ahci_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->scan)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
return ops->scan(dev);
|
|
|
|
}
|
|
|
|
|
2023-10-11 20:26:42 +00:00
|
|
|
int sata_rescan(bool verbose)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
printf("Removing devices on SATA bus...\n");
|
|
|
|
|
|
|
|
blk_unbind_all(UCLASS_AHCI);
|
|
|
|
|
|
|
|
ret = uclass_find_first_device(UCLASS_AHCI, &dev);
|
|
|
|
if (ret || !dev) {
|
|
|
|
printf("Cannot find SATA device (err=%d)\n", ret);
|
2023-11-02 18:51:15 +00:00
|
|
|
return -ENOENT;
|
2023-10-11 20:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = device_remove(dev, DM_REMOVE_NORMAL);
|
|
|
|
if (ret) {
|
|
|
|
printf("Cannot remove SATA device '%s' (err=%d)\n", dev->name, ret);
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
printf("Rescanning SATA bus for devices...\n");
|
|
|
|
|
|
|
|
ret = uclass_probe_all(UCLASS_AHCI);
|
|
|
|
|
2023-10-07 03:34:28 +00:00
|
|
|
if (ret == -ENODEV) {
|
|
|
|
if (verbose)
|
|
|
|
printf("No SATA block device found\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-11 20:26:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-01 17:36:26 +00:00
|
|
|
static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, void *dst)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, const void *buffer)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2016-05-01 17:36:11 +00:00
|
|
|
|
2016-05-01 17:36:26 +00:00
|
|
|
static const struct blk_ops sata_blk_ops = {
|
|
|
|
.read = sata_bread,
|
|
|
|
.write = sata_bwrite,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sata_blk) = {
|
|
|
|
.name = "sata_blk",
|
|
|
|
.id = UCLASS_BLK,
|
|
|
|
.ops = &sata_blk_ops,
|
|
|
|
};
|