/
0027-Allow-more-than-one-instance-of-generic-devices.patch
68 lines (60 loc) · 2.14 KB
/
0027-Allow-more-than-one-instance-of-generic-devices.patch
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
65
66
67
From d3b3e1f8efe742df7b322237905faabab787813b Mon Sep 17 00:00:00 2001
From: Pantelis Antoniou <panto@antoniou-consulting.com>
Date: Fri, 30 Nov 2012 12:23:29 +0200
Subject: [PATCH 27/32] Allow more than one instance of generic devices
Generate unique name to allow more than one instance of devices.
---
drivers/capebus/capebus-driver.c | 19 ++++++++++++++++++-
include/linux/capebus.h | 7 ++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/capebus/capebus-driver.c b/drivers/capebus/capebus-driver.c
index 82b1d1b..a299c77 100644
--- a/drivers/capebus/capebus-driver.c
+++ b/drivers/capebus/capebus-driver.c
@@ -441,13 +441,30 @@ capebus_of_platform_compatible_device_create(struct cape_dev *dev,
{
struct device_node *node;
struct platform_device *pdev;
+ char *name, *buf;
node = capebus_of_compatible_device_property_match(dev, matches, prop,
prop_value);
if (node == NULL)
return ERR_PTR(-ENXIO);
- pdev = of_platform_device_create(node, pdev_name, dev->bus->dev.parent);
+ /* create system-wide unique name */
+ buf = kasprintf(GFP_KERNEL, "%d:%d-%s.%d",
+ dev->bus->busno, dev->slot->slotno,
+ pdev_name, dev->slot->next_pdevid++);
+ if (buf == NULL)
+ return ERR_PTR(-ENOMEM);
+
+ name = devm_kzalloc(&dev->dev, strlen(buf) + 1, GFP_KERNEL);
+ kfree(buf);
+
+ if (name == NULL)
+ return ERR_PTR(-ENOMEM);
+
+ /* safe */
+ strcpy(name, buf);
+
+ pdev = of_platform_device_create(node, name, &dev->dev);
/* release the reference to the node */
of_node_put(node);
diff --git a/include/linux/capebus.h b/include/linux/capebus.h
index 7524401..2f8ab7b 100644
--- a/include/linux/capebus.h
+++ b/include/linux/capebus.h
@@ -43,9 +43,10 @@ struct cape_slot;
struct cape_slot {
struct list_head node;
- struct cape_bus *bus; /* the bus this slot is on */
- int slotno; /* index of this slot */
- struct cape_dev *dev; /* the device (if found) */
+ struct cape_bus *bus; /* the bus this slot is on */
+ int slotno; /* index of this slot */
+ struct cape_dev *dev; /* the device (if found) */
+ unsigned int next_pdevid; /* next assigned pdev_id */
};
struct cape_driver {
--
1.7.7.6