From: Marc Kleine-Budde <mkl@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v3 13/13] sandbox: hostfile: completely switch to OF based probing
Date: Tue, 3 Mar 2015 13:14:59 +0100 [thread overview]
Message-ID: <1425384899-18809-14-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1425384899-18809-1-git-send-email-mkl@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
arch/sandbox/board/hostfile.c | 98 ++++++++++++++++-------
arch/sandbox/mach-sandbox/include/mach/hostfile.h | 11 ++-
arch/sandbox/os/common.c | 2 +-
3 files changed, 77 insertions(+), 34 deletions(-)
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 3e6435983b56..c6fd80fd8761 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -27,8 +27,11 @@
#include <mach/hostfile.h>
#include <xfuncs.h>
+#include <linux/err.h>
+
struct hf_priv {
struct cdev cdev;
+ const char *filename;
int fd;
};
@@ -56,9 +59,9 @@ static ssize_t hf_write(struct cdev *cdev, const void *buf, size_t count, loff_t
static void hf_info(struct device_d *dev)
{
- struct hf_platform_data *hf = dev->platform_data;
+ struct hf_priv *priv = dev->priv;
- printf("file: %s\n", hf->filename);
+ printf("file: %s\n", priv->filename);
}
static struct file_operations hf_fops = {
@@ -69,53 +72,94 @@ static struct file_operations hf_fops = {
static int hf_probe(struct device_d *dev)
{
- struct hf_platform_data *hf = dev->platform_data;
struct hf_priv *priv = xzalloc(sizeof(*priv));
struct resource *res;
+ int err;
res = dev_get_resource(dev, IORESOURCE_MEM, 0);
if (IS_ERR(res))
return PTR_ERR(res);
- priv->fd = hf->fd;
- priv->cdev.name = hf->devname;
priv->cdev.size = resource_size(res);
+
+ if (!dev->device_node)
+ return -ENODEV;
+
+ err = of_property_read_u32(dev->device_node, "fd", &priv->fd);
+ if (err)
+ return err;
+
+ err = of_property_read_string(dev->device_node, "filename", &priv->filename);
+ if (err)
+ return err;
+
+ priv->cdev.name = dev->device_node->name;
priv->cdev.dev = dev;
priv->cdev.ops = &hf_fops;
priv->cdev.priv = priv;
dev->info = hf_info;
+ dev->priv = priv;
-#ifdef CONFIG_FS_DEVFS
- devfs_create(&priv->cdev);
-#endif
-
- return 0;
+ return devfs_create(&priv->cdev);
}
+static __maybe_unused struct of_device_id hostfile_dt_ids[] = {
+ {
+ .compatible = "barebox,hostfile",
+ }, {
+ /* sentinel */
+ }
+};
+
static struct driver_d hf_drv = {
.name = "hostfile",
+ .of_compatible = DRV_OF_COMPAT(hostfile_dt_ids),
.probe = hf_probe,
};
coredevice_platform_driver(hf_drv);
-int barebox_register_filedev(struct hf_platform_data *hf)
+static int of_hostfile_fixup(struct device_node *root, void *ctx)
{
- struct device_d *dev;
- struct resource *res;
-
- dev = xzalloc(sizeof(*dev));
- strcpy(dev->name, "hostfile");
- dev->id = DEVICE_ID_DYNAMIC;
- dev->platform_data = hf;
-
- res = xzalloc(sizeof(struct resource));
- res[0].start = hf->base;
- res[0].end = hf->base + hf->size - 1;
- res[0].flags = IORESOURCE_MEM;
-
- dev->resource = res;
- dev->num_resources = 1;
+ struct hf_info *hf = ctx;
+ struct device_node *node;
+ uint32_t reg[] = {
+ hf->base >> 32,
+ hf->base,
+ hf->size
+ };
+ int ret;
+
+ node = of_new_node(root, hf->devname);
+
+ ret = of_property_write_u32(node, "fd", hf->fd);
+ if (ret)
+ return ret;
+
+ ret = of_property_write_u32_array(node, "reg", reg, ARRAY_SIZE(reg));
+ if (ret)
+ return ret;
+
+ ret = of_property_write_u32(node, "#address-cells", 2);
+ if (ret)
+ return ret;
+
+ ret = of_property_write_u32(node, "#size-cells", 1);
+ if (ret)
+ return ret;
+
+ ret = of_set_property(node, "compatible", hostfile_dt_ids->compatible,
+ strlen(hostfile_dt_ids->compatible) + 1, 1);
+ if (ret)
+ return ret;
+
+ ret = of_set_property(node, "filename", hf->filename,
+ strlen(hf->filename) + 1, 1);
+
+ return ret;
+}
- return sandbox_add_device(dev);
+int barebox_register_filedev(struct hf_info *hf)
+{
+ return of_register_fixup(of_hostfile_fixup, hf);
}
diff --git a/arch/sandbox/mach-sandbox/include/mach/hostfile.h b/arch/sandbox/mach-sandbox/include/mach/hostfile.h
index 747063182cf3..627fe28e765b 100644
--- a/arch/sandbox/mach-sandbox/include/mach/hostfile.h
+++ b/arch/sandbox/mach-sandbox/include/mach/hostfile.h
@@ -1,15 +1,14 @@
#ifndef __ASM_ARCH_HOSTFILE_H
#define __ASM_ARCH_HOSTFILE_H
-struct hf_platform_data {
+struct hf_info {
int fd;
- size_t size;
unsigned long base;
- char *filename;
- char *devname;
+ size_t size;
+ const char *devname;
+ const char *filename;
};
-int barebox_register_filedev(struct hf_platform_data *hf);
+int barebox_register_filedev(struct hf_info *hf);
#endif /* __ASM_ARCH_HOSTFILE_H */
-
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 7aa0f5d3f2e0..d6273918906b 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -208,13 +208,13 @@ extern void mem_malloc_init(void *start, void *end);
static int add_image(char *str, char *devname_template, int *devname_number)
{
+ struct hf_info *hf = malloc(sizeof(struct hf_info));
char *filename, *devname;
char tmp[16];
int readonly = 0;
struct stat s;
char *opt;
int fd, ret;
- struct hf_platform_data *hf = malloc(sizeof(struct hf_platform_data));
if (!hf)
return -1;
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-03-03 12:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 12:14 [PATCH v3 00/13] sandbox OF integration Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 01/13] sandbox: add support to pass dtb to barebox Marc Kleine-Budde
2015-03-03 20:43 ` Sascha Hauer
2015-03-03 21:41 ` Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 02/13] sandbox: add sample dts Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 03/13] sandbox: activate OF support in defconfig Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 04/13] sandbox: hostfile: clarify variable names Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 05/13] sandbox: hostfile: probe(): add missing pointer from cdev.dev to dev Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 06/13] sandbox: hostfile: remove struct hf_platform_data from hf_priv Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 07/13] sandbox: hostfile: move fd from platform data to priv Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 08/13] sandbox: hostfile: probe driver earlier Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 09/13] sandbox: hostfile: use the memory resource to determine the size not the platform_data Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 10/13] sandbox: hostfile: is always mmpad'ed Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 11/13] sandbox: move device name generation for image/env into add_image() Marc Kleine-Budde
2015-03-03 12:14 ` [PATCH v3 12/13] sandbox: hostfile: improve --image parameter to support "dev=file" Marc Kleine-Budde
2015-03-03 12:14 ` Marc Kleine-Budde [this message]
2015-03-04 10:35 ` [PATCH v3 00/13] sandbox OF integration Sascha Hauer
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=1425384899-18809-14-git-send-email-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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