From: Pavel Herrmann <morpheus.ibis@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 04/11] DM: add sata_legacy driver for blockctrl
Date: Thu, 20 Sep 2012 21:37:40 +0200 [thread overview]
Message-ID: <1348169867-2917-5-git-send-email-morpheus.ibis@gmail.com> (raw)
In-Reply-To: <1348169867-2917-1-git-send-email-morpheus.ibis@gmail.com>
This driver works by wrapping the old SATA API to new blockctrl API
Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
drivers/blockctrl/Makefile | 1 +
drivers/blockctrl/sata_legacy.c | 166 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 167 insertions(+)
create mode 100644 drivers/blockctrl/sata_legacy.c
diff --git a/drivers/blockctrl/Makefile b/drivers/blockctrl/Makefile
index 21a9094..5df1ce1 100644
--- a/drivers/blockctrl/Makefile
+++ b/drivers/blockctrl/Makefile
@@ -22,6 +22,7 @@ include $(TOPDIR)/config.mk
LIB := $(obj)libblockctrl.o
COBJS-${CONFIG_DM_BLOCK} := core.o
+COBJS-${CONFIG_BLOCK_SATA_LEGACY} += sata_legacy.o
COBJS := $(COBJS-y)
SRCS := $(COBJS:.o=.c)
diff --git a/drivers/blockctrl/sata_legacy.c b/drivers/blockctrl/sata_legacy.c
new file mode 100644
index 0000000..9cc41a2
--- /dev/null
+++ b/drivers/blockctrl/sata_legacy.c
@@ -0,0 +1,166 @@
+/*
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <dm/blockctrl.h>
+#include <dm/structures.h>
+#include <dm/manager.h>
+#include <sata.h>
+
+block_dev_desc_t sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE];
+
+static lbaint_t read(struct instance *i, int port, lbaint_t start,
+ lbaint_t length, void *buffer)
+{
+ return sata_read(port, start, length, buffer);
+}
+
+static lbaint_t write(struct instance *i, int port, lbaint_t start,
+ lbaint_t length, void *buffer)
+{
+ return sata_write(port, start, length, buffer);
+}
+
+static int scan(struct instance *i, int port)
+{
+ int error;
+
+ error = scan_sata(port);
+ if (error)
+ return error;
+
+ if (!sata_dev_desc[port].lba)
+ return -ENOENT;
+
+ return 0;
+}
+
+static int get_port_count(struct instance *i)
+{
+ return CONFIG_SYS_SATA_MAX_DEVICE;
+}
+
+static int get_port_option(struct instance *i, int port,
+ enum blockctrl_port_option_code op, struct option *result)
+{
+ switch (op) {
+ case BLKP_OPT_IFTYPE:
+ result->flags = OPTION_TYPE_U;
+ result->data.data_u = BLKP_IFTYPE_SATA;
+ return 0;
+ case BLKP_OPT_IFSPEED:
+ result->flags = OPTION_TYPE_U;
+ result->data.data_u = 150;
+ return 0;
+ case BLKP_OPT_BLOCKSIZE:
+ result->flags = OPTION_TYPE_U;
+ result->data.data_u = sata_dev_desc[port].blksz;
+ return 0;
+ case BLKP_OPT_BLOCKCOUNT:
+ result->flags = OPTION_TYPE_U;
+ result->data.data_u = sata_dev_desc[port].lba;
+ return 0;
+ case BLKP_OPT_REMOVABLE:
+ result->flags = OPTION_TYPE_U;
+ result->data.data_u = sata_dev_desc[port].removable;
+ return 0;
+ case BLKP_OPT_LBA48:
+#ifdef CONFIG_LBA48
+ result->flags = OPTION_TYPE_U;
+ result->data.data_u = sata_dev_desc[port].lba48;
+ return 0;
+#else
+ return -EINVAL;
+#endif
+ case BLKP_OPT_VENDOR:
+ result->flags = OPTION_TYPE_S;
+ result->data.data_s = sata_dev_desc[port].vendor;
+ return 0;
+ case BLKP_OPT_PRODUCT:
+ result->flags = OPTION_TYPE_S;
+ result->data.data_s = sata_dev_desc[port].product;
+ return 0;
+ case BLKP_OPT_REVISION:
+ result->flags = OPTION_TYPE_S;
+ result->data.data_s = sata_dev_desc[port].revision;
+ return 0;
+ }
+ return -EINVAL;
+}
+
+static struct blockctrl_ops ops = {
+ .read = read,
+ .write = write,
+ .scan = scan,
+ .get_port_count = get_port_count,
+ .get_port_option = get_port_option,
+};
+
+static int sata_init(void)
+{
+ int rc;
+ int i;
+
+ for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) {
+ memset(&sata_dev_desc[i], 0, sizeof(struct block_dev_desc));
+ sata_dev_desc[i].if_type = IF_TYPE_SATA;
+ sata_dev_desc[i].dev = i;
+ sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
+ sata_dev_desc[i].type = DEV_TYPE_HARDDISK;
+ sata_dev_desc[i].lba = 0;
+ sata_dev_desc[i].blksz = 512;
+ sata_dev_desc[i].block_read = sata_read;
+ sata_dev_desc[i].block_write = sata_write;
+
+ rc = init_sata(i);
+ if (!rc)
+ rc = scan_sata(i);
+ }
+ return rc;
+}
+
+static int bind(struct instance *dev)
+{
+ return core_bind(CORE_BLOCKCTRL, dev, &ops, NULL);
+}
+
+static int probe(struct instance *dev)
+{
+ return sata_init();
+}
+
+static int reloc(struct instance *dev, struct instance *old)
+{
+ return core_replace(CORE_BLOCKCTRL, dev, old);
+}
+
+static int remove(struct instance *dev)
+{
+ return 0;
+}
+
+static int unbind(struct instance *dev)
+{
+ return core_unbind(CORE_BLOCKDEV, dev);
+}
+
+U_BOOT_DRIVER(sata_legacy, bind, probe, reloc, remove, unbind);
--
1.7.12
next prev parent reply other threads:[~2012-09-20 19:37 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-20 19:37 [U-Boot] [PATCH 00/11] Add DM blockdev subsystem Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 01/11] DM: add block device core Pavel Herrmann
2012-09-20 19:58 ` Marek Vasut
2012-09-21 7:11 ` Pavel Herrmann
2012-09-21 12:39 ` Marek Vasut
2012-09-21 13:27 ` Pavel Herrmann
2012-09-21 13:53 ` Marek Vasut
2012-09-21 14:57 ` Pavel Herrmann
2012-09-21 15:34 ` Marek Vasut
2012-09-21 15:48 ` Pavel Herrmann
2012-09-21 15:55 ` Marek Vasut
2012-09-21 17:19 ` Pavel Herrmann
2012-09-21 18:00 ` Marek Vasut
2012-09-21 18:53 ` Pavel Herrmann
2012-09-21 19:17 ` Marek Vasut
2012-09-21 19:29 ` Pavel Herrmann
2012-09-21 21:11 ` Marek Vasut
2012-09-21 23:43 ` Pavel Herrmann
2012-09-22 0:09 ` Marek Vasut
2012-09-22 9:39 ` Pavel Herrmann
2012-09-22 13:33 ` Marek Vasut
2012-09-22 13:59 ` Pavel Herrmann
2012-09-24 12:23 ` Pavel Herrmann
2012-09-20 20:49 ` [U-Boot] [U-Boot-DM] " Vikram Narayanan
2012-09-21 7:09 ` Pavel Herrmann
2012-09-21 12:39 ` Marek Vasut
2012-09-20 19:37 ` [U-Boot] [PATCH 02/11] DM: add support for scanning DOS partitions to blockdev core Pavel Herrmann
2012-09-20 20:03 ` Marek Vasut
2012-09-21 7:22 ` Pavel Herrmann
2012-09-21 12:47 ` Marek Vasut
2012-09-21 13:18 ` Pavel Herrmann
2012-09-21 13:54 ` Marek Vasut
2012-09-20 19:37 ` [U-Boot] [PATCH 03/11] DM: add block controller core Pavel Herrmann
2012-09-20 20:05 ` Marek Vasut
2012-09-21 7:21 ` Pavel Herrmann
2012-09-21 12:51 ` Marek Vasut
2012-09-21 13:14 ` Pavel Herrmann
2012-09-21 13:56 ` Marek Vasut
2012-09-21 15:04 ` Pavel Herrmann
2012-09-21 13:33 ` Pavel Herrmann
2012-09-21 13:58 ` Marek Vasut
2012-09-21 15:09 ` Pavel Herrmann
2012-09-21 15:39 ` Marek Vasut
2012-09-21 15:46 ` Pavel Herrmann
2012-09-21 16:08 ` Marek Vasut
2012-09-21 17:22 ` Pavel Herrmann
2012-09-21 18:01 ` Marek Vasut
2012-09-21 19:15 ` Pavel Herrmann
2012-09-21 19:22 ` Marek Vasut
2012-09-20 19:37 ` Pavel Herrmann [this message]
2012-09-20 19:37 ` [U-Boot] [PATCH 05/11] DM: add ata and partition blockdev drivers Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 06/11] DM: add cmd_block command Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 07/11] DM: use new blockdev API in FAT Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 08/11] DM: use new blockdev API in ext2 Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 09/11] DM: use new blockdev API in reiserfs Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 10/11] DM: use new blockdev API in ZFS Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 11/11] DM: switch sandbox to DM blockdev Pavel Herrmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1348169867-2917-5-git-send-email-morpheus.ibis@gmail.com \
--to=morpheus.ibis@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox