blob: 27f5eefc508f4afbe240d4d96c9aaf1d4ab191d1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -04002#include <linux/kernel.h>
3#include <linux/stat.h>
4#include <asm/macio.h>
5
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -04006static ssize_t
7compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
8{
Grant Likely2dc11582010-08-06 09:25:50 -06009 struct platform_device *of;
Jeremy Kerr018a3d12006-07-12 15:40:29 +100010 const char *compat;
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040011 int cplen;
12 int length = 0;
13
14 of = &to_macio_device (dev)->ofdev;
Grant Likely61c7a082010-04-13 16:12:29 -070015 compat = of_get_property(of->dev.of_node, "compatible", &cplen);
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040016 if (!compat) {
17 *buf = '\0';
18 return 0;
19 }
20 while (cplen > 0) {
21 int l;
22 length += sprintf (buf, "%s\n", compat);
23 buf += length;
24 l = strlen (compat) + 1;
25 compat += l;
26 cplen -= l;
27 }
28
29 return length;
30}
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020031static DEVICE_ATTR_RO(compatible);
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040032
scwhab@suse.dedcb34ab2005-10-28 17:46:20 -070033static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
34 char *buf)
35{
Rob Herring0634c292017-03-22 09:16:27 -050036 return of_device_modalias(dev, buf, PAGE_SIZE);
scwhab@suse.dedcb34ab2005-10-28 17:46:20 -070037}
38
Olaf Hering140b9322008-04-24 23:16:00 +100039static ssize_t devspec_show(struct device *dev,
40 struct device_attribute *attr, char *buf)
41{
Grant Likely2dc11582010-08-06 09:25:50 -060042 struct platform_device *ofdev;
Olaf Hering140b9322008-04-24 23:16:00 +100043
Grant Likely2dc11582010-08-06 09:25:50 -060044 ofdev = to_platform_device(dev);
Rob Herringb6a945a2017-07-18 16:43:12 -050045 return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
Olaf Hering140b9322008-04-24 23:16:00 +100046}
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020047static DEVICE_ATTR_RO(modalias);
48static DEVICE_ATTR_RO(devspec);
Olaf Hering140b9322008-04-24 23:16:00 +100049
Rob Herring0bdba862018-09-04 16:27:44 -050050static ssize_t name_show(struct device *dev,
51 struct device_attribute *attr, char *buf)
52{
53 return sprintf(buf, "%pOFn\n", dev->of_node);
54}
55static DEVICE_ATTR_RO(name);
56
Rob Herringbf82d372018-11-16 16:11:01 -060057static ssize_t type_show(struct device *dev,
58 struct device_attribute *attr, char *buf)
59{
60 return sprintf(buf, "%s\n", of_node_get_device_type(dev->of_node));
61}
62static DEVICE_ATTR_RO(type);
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040063
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020064static struct attribute *macio_dev_attrs[] = {
65 &dev_attr_name.attr,
66 &dev_attr_type.attr,
67 &dev_attr_compatible.attr,
68 &dev_attr_modalias.attr,
69 &dev_attr_devspec.attr,
70 NULL,
71};
72
73static const struct attribute_group macio_dev_group = {
74 .attrs = macio_dev_attrs,
75};
76
77const struct attribute_group *macio_dev_groups[] = {
78 &macio_dev_group,
79 NULL,
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040080};