blob: 89cd516f3d6eb35a068aa3ce205052b8ec201d61 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass3665a402016-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 Glass3665a402016-05-01 11:36:11 -060010 */
11
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020012#define LOG_CATEGORY UCLASS_AHCI
13
Simon Glass821bb522017-07-29 11:35:15 -060014#include <ahci.h>
Simon Glass655306c2020-05-10 11:39:58 -060015#include <blk.h>
Simon Glass7d741ac2016-05-01 11:36:26 -060016#include <dm.h>
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020017#include <log.h>
Simon Glass655306c2020-05-10 11:39:58 -060018#include <part.h>
Simon Glass3665a402016-05-01 11:36:11 -060019#include <sata.h>
Tony Dinha87cbb82023-10-11 13:26:42 -070020#include <dm/device-internal.h>
21#include <dm/uclass-internal.h>
Simon Glass3665a402016-05-01 11:36:11 -060022
Simon Glass821bb522017-07-29 11:35:15 -060023int 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
33int 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 Glass3665a402016-05-01 11:36:11 -060039
Simon Glass821bb522017-07-29 11:35:15 -060040 return ops->port_status(dev, port);
41}
42
43int 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 Dinha87cbb82023-10-11 13:26:42 -070053int sata_rescan(bool verbose)
54{
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020055 struct uclass *uc;
56 struct udevice *dev; /* SATA controller */
Tony Dinha87cbb82023-10-11 13:26:42 -070057 int ret;
Tony Dinha87cbb82023-10-11 13:26:42 -070058
59 if (verbose)
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020060 printf("scanning bus for devices...\n");
Tony Dinha87cbb82023-10-11 13:26:42 -070061
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020062 ret = uclass_get(UCLASS_AHCI, &uc);
63 if (ret)
64 return ret;
Tony Dinha87cbb82023-10-11 13:26:42 -070065
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020066 /* 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 Dinha87cbb82023-10-11 13:26:42 -070076 }
77
Tony Dinha87cbb82023-10-11 13:26:42 -070078 if (verbose)
79 printf("Rescanning SATA bus for devices...\n");
80
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020081 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 Dinhe240edf2023-10-06 20:34:28 -070085 }
86
Heinrich Schuchardtd4991492024-08-14 09:10:37 +020087 return 0;
Tony Dinha87cbb82023-10-11 13:26:42 -070088}
89
Simon Glass7d741ac2016-05-01 11:36:26 -060090static unsigned long sata_bread(struct udevice *dev, lbaint_t start,
91 lbaint_t blkcnt, void *dst)
92{
93 return -ENOSYS;
94}
95
96static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start,
97 lbaint_t blkcnt, const void *buffer)
98{
99 return -ENOSYS;
100}
Simon Glass3665a402016-05-01 11:36:11 -0600101
Simon Glass7d741ac2016-05-01 11:36:26 -0600102static const struct blk_ops sata_blk_ops = {
103 .read = sata_bread,
104 .write = sata_bwrite,
105};
106
107U_BOOT_DRIVER(sata_blk) = {
108 .name = "sata_blk",
109 .id = UCLASS_BLK,
110 .ops = &sata_blk_ops,
111};