summaryrefslogtreecommitdiff
path: root/schulung_tools/drivers/modules/hellodriver/patches-leds/0002-hello-add-pci-memory-mapping.patch
blob: 0a11a57fffd471cd51a34beabef743e5847a6c81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From 3afec946845a02a8fce94d00abda9b4c8abcbce0 Mon Sep 17 00:00:00 2001
From: John Ogness <john.ogness@linutronix.de>
Date: Fri, 15 Feb 2019 11:03:59 +0106
Subject: [PATCH 3/7] hello: add pci memory mapping

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 hello.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/hello.c b/hello.c
index db50302..58a64e5 100644
--- a/hello.c
+++ b/hello.c
@@ -12,6 +12,7 @@ struct hello_dev {
 	struct device *dev;
 	struct cdev cdev;
 	unsigned int minor;
+	void __iomem *mem;
 };
 
 #define HELLO_MAX_DEVICES 10
@@ -120,6 +121,12 @@ static int hello_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	pci_set_master(pdev);
 
+	hello->mem = pci_iomap(pdev, 2, 0);
+	if (!hello->mem) {
+		ret = -ENOMEM;
+		goto err_regions;
+	}
+
 	devt = MKDEV(MAJOR(hello_devt), hello->minor);
 
 	cdev_init(&hello->cdev, &hello_fops);
@@ -127,7 +134,7 @@ static int hello_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	ret = cdev_add(&hello->cdev, devt, 1);
 	if (ret != 0) {
 		dev_err(&pdev->dev, "cdev_add failed\n");
-		goto err_regions;
+		goto err_iomap;
 	}
 
 	dev = device_create(hello_class, &pdev->dev, devt, hello,
@@ -144,6 +151,8 @@ static int hello_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 err_cdev:
 	cdev_del(&hello->cdev);
+err_iomap:
+	pci_iounmap(pdev, hello->mem);
 err_regions:
 	pci_release_regions(pdev);
 err_enable:
@@ -159,6 +168,7 @@ static void hello_remove(struct pci_dev *pdev)
 
 	device_destroy(hello_class, MKDEV(MAJOR(hello_devt), hello->minor));
 	cdev_del(&hello->cdev);
+	pci_iounmap(pdev, hello->mem);
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
 	pci_set_drvdata(pdev, NULL);
-- 
2.11.0