summaryrefslogtreecommitdiff
path: root/schulung_tools/drivers/modules/hellodriver/hello.c
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2018-09-28 15:56:36 +0200
committerJohn Ogness <john.ogness@linutronix.de>2018-09-28 15:56:36 +0200
commit666fea80ee365a69a65e828c19349d23d0500713 (patch)
tree5fb64130e54edaca7ae3ae1bbb35602d8e420144 /schulung_tools/drivers/modules/hellodriver/hello.c
parentbd9f17af0eb9f7dfba48c92f469ef15fe0a340c4 (diff)
hello driver: add x86 support
Supporting x86 allows us to quickly show the hello driver in action directly from the x86 trainer image. It also shows how platform devices can be added on architectures that do not support device trees. Signed-off-by: John Ogness <john.ogness@linutronix.de>
Diffstat (limited to 'schulung_tools/drivers/modules/hellodriver/hello.c')
-rw-r--r--schulung_tools/drivers/modules/hellodriver/hello.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/schulung_tools/drivers/modules/hellodriver/hello.c b/schulung_tools/drivers/modules/hellodriver/hello.c
index caded6d..328c587 100644
--- a/schulung_tools/drivers/modules/hellodriver/hello.c
+++ b/schulung_tools/drivers/modules/hellodriver/hello.c
@@ -89,11 +89,15 @@ static int hello_probe(struct platform_device *pdev)
return -ENOMEM;
}
+#ifdef CONFIG_OF
ret = of_property_read_u32(pdev->dev.of_node, "index", &hello->minor);
if (ret < 0) {
dev_err(&pdev->dev, "no index specified\n");
goto err_out1;
}
+#else
+ hello->minor = (unsigned)pdev->id;
+#endif
if (hello->minor >= HELLO_MAX_DEVICES) {
dev_err(&pdev->dev, "invalid index: %u\n", hello->minor);
@@ -161,6 +165,10 @@ static struct platform_driver hello_driver = {
.remove = hello_remove,
};
+#ifndef CONFIG_OF
+static struct platform_device *pdevs[3];
+#endif
+
static int __init hello_init(void)
{
int ret;
@@ -182,6 +190,12 @@ static int __init hello_init(void)
if (ret != 0)
goto err_out2;
+#ifndef CONFIG_OF
+ pdevs[0] = platform_device_register_simple("hello", 1, NULL, 0);
+ pdevs[1] = platform_device_register_simple("hello", 3, NULL, 0);
+ pdevs[2] = platform_device_register_simple("hello", 5, NULL, 0);
+#endif
+
return 0;
err_out2:
@@ -195,6 +209,12 @@ static void __exit hello_exit(void)
{
printk(KERN_INFO "%s\n", __func__);
+#ifndef CONFIG_OF
+ platform_device_unregister(pdevs[0]);
+ platform_device_unregister(pdevs[1]);
+ platform_device_unregister(pdevs[2]);
+#endif
+
platform_driver_unregister(&hello_driver);
class_destroy(hello_class);
unregister_chrdev_region(hello_devt, HELLO_MAX_DEVICES);