Skip to content

Commit 803f1ca

Browse files
Johannes Thumshirngregkh
authored andcommitted
mcb: export bus information via sysfs
Export information about the bus stored in the FPGA's header to userspace via sysfs, instead of hiding it in pr_debug()s from everyone. Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: Andreas Werner <[email protected]> Tested-by: Andreas Werner <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 18d2881 commit 803f1ca

File tree

5 files changed

+103
-11
lines changed

5 files changed

+103
-11
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
What: /sys/bus/mcb/devices/mcb:X
2+
Date: March 2016
3+
KernelVersion: 4.7
4+
Contact: Johannes Thumshirn <[email protected]>
5+
Description: Hardware chip or device hosting the MEN chameleon bus
6+
7+
What: /sys/bus/mcb/devices/mcb:X/revision
8+
Date: March 2016
9+
KernelVersion: 4.7
10+
Contact: Johannes Thumshirn <[email protected]>
11+
Description: The FPGA's revision number
12+
13+
What: /sys/bus/mcb/devices/mcb:X/minor
14+
Date: March 2016
15+
KernelVersion: 4.7
16+
Contact: Johannes Thumshirn <[email protected]>
17+
Description: The FPGA's minor number
18+
19+
What: /sys/bus/mcb/devices/mcb:X/model
20+
Date: March 2016
21+
KernelVersion: 4.7
22+
Contact: Johannes Thumshirn <[email protected]>
23+
Description: The FPGA's model number
24+
25+
What: /sys/bus/mcb/devices/mcb:X/name
26+
Date: March 2016
27+
KernelVersion: 4.7
28+
Contact: Johannes Thumshirn <[email protected]>
29+
Description: The FPGA's name

drivers/mcb/mcb-core.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,60 @@ static void mcb_shutdown(struct device *dev)
9090
mdrv->shutdown(mdev);
9191
}
9292

93+
static ssize_t revision_show(struct device *dev, struct device_attribute *attr,
94+
char *buf)
95+
{
96+
struct mcb_bus *bus = to_mcb_bus(dev);
97+
98+
return scnprintf(buf, PAGE_SIZE, "%d\n", bus->revision);
99+
}
100+
static DEVICE_ATTR_RO(revision);
101+
102+
static ssize_t model_show(struct device *dev, struct device_attribute *attr,
103+
char *buf)
104+
{
105+
struct mcb_bus *bus = to_mcb_bus(dev);
106+
107+
return scnprintf(buf, PAGE_SIZE, "%c\n", bus->model);
108+
}
109+
static DEVICE_ATTR_RO(model);
110+
111+
static ssize_t minor_show(struct device *dev, struct device_attribute *attr,
112+
char *buf)
113+
{
114+
struct mcb_bus *bus = to_mcb_bus(dev);
115+
116+
return scnprintf(buf, PAGE_SIZE, "%d\n", bus->minor);
117+
}
118+
static DEVICE_ATTR_RO(minor);
119+
120+
static ssize_t name_show(struct device *dev, struct device_attribute *attr,
121+
char *buf)
122+
{
123+
struct mcb_bus *bus = to_mcb_bus(dev);
124+
125+
return scnprintf(buf, PAGE_SIZE, "%s\n", bus->name);
126+
}
127+
static DEVICE_ATTR_RO(name);
128+
129+
static struct attribute *mcb_bus_attrs[] = {
130+
&dev_attr_revision.attr,
131+
&dev_attr_model.attr,
132+
&dev_attr_minor.attr,
133+
&dev_attr_name.attr,
134+
NULL,
135+
};
136+
137+
static const struct attribute_group mcb_carrier_group = {
138+
.attrs = mcb_bus_attrs,
139+
};
140+
141+
static const struct attribute_group *mcb_carrier_groups[] = {
142+
&mcb_carrier_group,
143+
NULL,
144+
};
145+
146+
93147
static struct bus_type mcb_bus_type = {
94148
.name = "mcb",
95149
.match = mcb_match,
@@ -99,6 +153,11 @@ static struct bus_type mcb_bus_type = {
99153
.shutdown = mcb_shutdown,
100154
};
101155

156+
static struct device_type mcb_carrier_device_type = {
157+
.name = "mcb-carrier",
158+
.groups = mcb_carrier_groups,
159+
};
160+
102161
/**
103162
* __mcb_register_driver() - Register a @mcb_driver at the system
104163
* @drv: The @mcb_driver
@@ -205,6 +264,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
205264
device_initialize(&bus->dev);
206265
bus->dev.parent = carrier;
207266
bus->dev.bus = &mcb_bus_type;
267+
bus->dev.type = &mcb_carrier_device_type;
208268

209269
dev_set_name(&bus->dev, "mcb:%d", bus_nr);
210270
rc = device_add(&bus->dev);

drivers/mcb/mcb-internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#define PCI_VENDOR_ID_MEN 0x1a88
77
#define PCI_DEVICE_ID_MEN_CHAMELEON 0x4d45
8-
#define CHAMELEON_FILENAME_LEN 12
98
#define CHAMELEONV2_MAGIC 0xabce
109
#define CHAM_HEADER_SIZE 0x200
1110

drivers/mcb/mcb-parse.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,11 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
113113
}
114114
p += hsize;
115115

116-
pr_debug("header->revision = %d\n", header->revision);
117-
pr_debug("header->model = 0x%x ('%c')\n", header->model,
118-
header->model);
119-
pr_debug("header->minor = %d\n", header->minor);
120-
pr_debug("header->bus_type = 0x%x\n", header->bus_type);
121-
122-
123-
pr_debug("header->magic = 0x%x\n", header->magic);
124-
pr_debug("header->filename = \"%.*s\"\n", CHAMELEON_FILENAME_LEN,
125-
header->filename);
116+
bus->revision = header->revision;
117+
bus->model = header->model;
118+
bus->minor = header->minor;
119+
snprintf(bus->name, CHAMELEON_FILENAME_LEN + 1, "%s",
120+
header->filename);
126121

127122
for_each_chameleon_cell(dtype, p) {
128123
switch (dtype) {

include/linux/mcb.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/device.h>
1616
#include <linux/irqreturn.h>
1717

18+
#define CHAMELEON_FILENAME_LEN 12
19+
1820
struct mcb_driver;
1921
struct mcb_device;
2022

@@ -25,11 +27,18 @@ struct mcb_device;
2527
* @carrier: pointer to carrier device
2628
* @bus_nr: mcb bus number
2729
* @get_irq: callback to get IRQ number
30+
* @revision: the FPGA's revision number
31+
* @model: the FPGA's model number
32+
* @filename: the FPGA's name
2833
*/
2934
struct mcb_bus {
3035
struct device dev;
3136
struct device *carrier;
3237
int bus_nr;
38+
u8 revision;
39+
char model;
40+
u8 minor;
41+
char name[CHAMELEON_FILENAME_LEN + 1];
3342
int (*get_irq)(struct mcb_device *dev);
3443
};
3544
#define to_mcb_bus(b) container_of((b), struct mcb_bus, dev)

0 commit comments

Comments
 (0)