summaryrefslogtreecommitdiff
path: root/schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2019-02-15 13:16:28 +0106
committerJohn Ogness <john.ogness@linutronix.de>2019-02-15 13:16:28 +0106
commitf19259fb36ffe74a11325c14ee2260a8e323b8ee (patch)
tree6cf02a4fcedfa1451c164f6c3a44a0781f41a571 /schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch
parent9fffe2a41d0aa2b47c589db2523707a9e14ab5a1 (diff)
schulung_tools: drivers: remove modules subdir
There is no need for the extra directory level. Move all the example modules to the parent "drivers" directory and delete the modules directory. Signed-off-by: John Ogness <john.ogness@linutronix.de>
Diffstat (limited to 'schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch')
-rw-r--r--schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch185
1 files changed, 185 insertions, 0 deletions
diff --git a/schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch b/schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch
new file mode 100644
index 0000000..35dc817
--- /dev/null
+++ b/schulung_tools/drivers/hellodriver/patches-leds/0001-hello-change-from-platform-to-pci-bus.patch
@@ -0,0 +1,185 @@
+From 28357d61e0ec39851ca88a09b04ce876b8758448 Mon Sep 17 00:00:00 2001
+From: John Ogness <john.ogness@linutronix.de>
+Date: Fri, 15 Feb 2019 12:11:27 +0100
+Subject: [PATCH 2/7] hello: change from platform to pci bus
+
+Signed-off-by: John Ogness <john.ogness@linutronix.de>
+---
+ hello.c | 89 +++++++++++++++++++++++++++++++----------------------------------
+ 1 file changed, 43 insertions(+), 46 deletions(-)
+
+diff --git a/hello.c b/hello.c
+index 7f78d06..db50302 100644
+--- a/hello.c
++++ b/hello.c
+@@ -5,9 +5,8 @@
+ #include <linux/uaccess.h>
+ #include <linux/slab.h>
+ #include <linux/device.h>
+-#include <linux/platform_device.h>
++#include <linux/pci.h>
+ #include <linux/cdev.h>
+-#include <linux/of.h>
+
+ struct hello_dev {
+ struct device *dev;
+@@ -77,7 +76,7 @@ static const struct file_operations hello_fops = {
+ .write = hello_write,
+ };
+
+-static int hello_probe(struct platform_device *pdev)
++static int hello_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+ {
+ struct hello_dev *hello;
+ struct device *dev;
+@@ -90,15 +89,7 @@ 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_out;
+- }
+-#else
+- hello->minor = (unsigned)pdev->id;
+-#endif
++ hello->minor = 1;
+
+ if (hello->minor >= HELLO_MAX_DEVICES) {
+ dev_err(&pdev->dev, "invalid index: %u\n", hello->minor);
+@@ -107,7 +98,27 @@ static int hello_probe(struct platform_device *pdev)
+ }
+
+ hello->dev = &pdev->dev;
+- platform_set_drvdata(pdev, hello);
++ pci_set_drvdata(pdev, hello);
++
++ ret = pci_enable_device(pdev);
++ if (ret) {
++ dev_err(&pdev->dev, "failed to enable device\n");
++ goto err_drvdata;
++ }
++
++ if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
++ dev_err(&pdev->dev, "failed to find base address\n");
++ ret = -ENODEV;
++ goto err_enable;
++ }
++
++ ret = pci_request_regions(pdev, "hello");
++ if (ret) {
++ dev_err(&pdev->dev, "failed to request resources\n");
++ goto err_enable;
++ }
++
++ pci_set_master(pdev);
+
+ devt = MKDEV(MAJOR(hello_devt), hello->minor);
+
+@@ -116,7 +127,7 @@ static int hello_probe(struct platform_device *pdev)
+ ret = cdev_add(&hello->cdev, devt, 1);
+ if (ret != 0) {
+ dev_err(&pdev->dev, "cdev_add failed\n");
+- goto err_drvdata;
++ goto err_regions;
+ }
+
+ dev = device_create(hello_class, &pdev->dev, devt, hello,
+@@ -133,43 +144,41 @@ static int hello_probe(struct platform_device *pdev)
+
+ err_cdev:
+ cdev_del(&hello->cdev);
++err_regions:
++ pci_release_regions(pdev);
++err_enable:
++ pci_disable_device(pdev);
+ err_drvdata:
+- platform_set_drvdata(pdev, NULL);
+-err_out:
++ pci_set_drvdata(pdev, NULL);
+ return ret;
+ }
+
+-static int hello_remove(struct platform_device *pdev)
++static void hello_remove(struct pci_dev *pdev)
+ {
+- struct hello_dev *hello = platform_get_drvdata(pdev);
++ struct hello_dev *hello = pci_get_drvdata(pdev);
+
+ device_destroy(hello_class, MKDEV(MAJOR(hello_devt), hello->minor));
+ cdev_del(&hello->cdev);
+- platform_set_drvdata(pdev, NULL);
++ pci_release_regions(pdev);
++ pci_disable_device(pdev);
++ pci_set_drvdata(pdev, NULL);
+
+ dev_info(&pdev->dev, "GOODBYE! I was hello device %d!\n", hello->minor);
+-
+- return 0;
+ }
+
+-static const struct of_device_id hello_match[] = {
+- { .compatible = "virtual,hello", },
++static const struct pci_device_id hello_id_table[] = {
++ { 0x1af4, 0x1110, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0 },
+ { /* end of table */ }
+ };
++MODULE_DEVICE_TABLE(pci, hello_id_table);
+
+-static struct platform_driver hello_driver = {
+- .driver = {
+- .name = "hello",
+- .of_match_table = hello_match,
+- },
++static struct pci_driver hello_driver = {
++ .name = "hello",
++ .id_table = hello_id_table,
+ .probe = hello_probe,
+ .remove = hello_remove,
+ };
+
+-#ifndef CONFIG_OF
+-static struct platform_device *pdevs[3];
+-#endif
+-
+ static int __init hello_init(void)
+ {
+ int ret;
+@@ -187,16 +196,10 @@ static int __init hello_init(void)
+ goto err_region;
+ }
+
+- ret = platform_driver_register(&hello_driver);
++ ret = pci_register_driver(&hello_driver);
+ if (ret != 0)
+ goto err_class;
+
+-#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_class:
+@@ -210,13 +213,7 @@ 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);
++ pci_unregister_driver(&hello_driver);
+ class_destroy(hello_class);
+ unregister_chrdev_region(hello_devt, HELLO_MAX_DEVICES);
+ }
+--
+2.11.0
+