dm: sata: Add support for driver-model block devices

Add driver-model block-device support to the SATA implementation. This is
just a dummy implementation for now, since the SATA low-level API uses
numbered devices and that doesn't fit with driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2016-05-01 11:36:26 -06:00
parent e8c0a2509c
commit f5a14af9c4

View File

@ -11,6 +11,7 @@
*/
#include <common.h>
#include <dm.h>
#include <sata.h>
struct blk_desc sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
@ -22,6 +23,19 @@ struct blk_desc *sata_get_dev(int dev)
}
#endif
#ifdef CONFIG_BLK
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;
}
#else
static unsigned long sata_bread(struct blk_desc *block_dev, lbaint_t start,
lbaint_t blkcnt, void *dst)
{
@ -33,6 +47,7 @@ static unsigned long sata_bwrite(struct blk_desc *block_dev, lbaint_t start,
{
return sata_write(block_dev->devnum, start, blkcnt, buffer);
}
#endif
int __sata_initialize(void)
{
@ -48,9 +63,10 @@ int __sata_initialize(void)
sata_dev_desc[i].lba = 0;
sata_dev_desc[i].blksz = 512;
sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz);
#ifndef CONFIG_BLK
sata_dev_desc[i].block_read = sata_bread;
sata_dev_desc[i].block_write = sata_bwrite;
#endif
rc = init_sata(i);
if (!rc) {
rc = scan_sata(i);
@ -78,9 +94,22 @@ __weak int __sata_stop(void)
}
int sata_stop(void) __attribute__((weak, alias("__sata_stop")));
#ifdef CONFIG_BLK
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,
};
#else
U_BOOT_LEGACY_BLK(sata) = {
.if_typename = "sata",
.if_type = IF_TYPE_SATA,
.max_devs = CONFIG_SYS_SATA_MAX_DEVICE,
.desc = sata_dev_desc,
};
#endif