blob: d2451e58acb97986441889a205612591afcb8433 [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
6
7#define macio_config_of_attr(field, format_string) \
8static ssize_t \
9field##_show (struct device *dev, struct device_attribute *attr, \
10 char *buf) \
11{ \
12 struct macio_dev *mdev = to_macio_device (dev); \
Grant Likely61c7a082010-04-13 16:12:29 -070013 return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020014} \
15static DEVICE_ATTR_RO(field);
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040016
17static ssize_t
18compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
19{
Grant Likely2dc11582010-08-06 09:25:50 -060020 struct platform_device *of;
Jeremy Kerr018a3d12006-07-12 15:40:29 +100021 const char *compat;
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040022 int cplen;
23 int length = 0;
24
25 of = &to_macio_device (dev)->ofdev;
Grant Likely61c7a082010-04-13 16:12:29 -070026 compat = of_get_property(of->dev.of_node, "compatible", &cplen);
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040027 if (!compat) {
28 *buf = '\0';
29 return 0;
30 }
31 while (cplen > 0) {
32 int l;
33 length += sprintf (buf, "%s\n", compat);
34 buf += length;
35 l = strlen (compat) + 1;
36 compat += l;
37 cplen -= l;
38 }
39
40 return length;
41}
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020042static DEVICE_ATTR_RO(compatible);
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040043
scwhab@suse.dedcb34ab2005-10-28 17:46:20 -070044static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
45 char *buf)
46{
Rob Herring0634c292017-03-22 09:16:27 -050047 return of_device_modalias(dev, buf, PAGE_SIZE);
scwhab@suse.dedcb34ab2005-10-28 17:46:20 -070048}
49
Olaf Hering140b9322008-04-24 23:16:00 +100050static ssize_t devspec_show(struct device *dev,
51 struct device_attribute *attr, char *buf)
52{
Grant Likely2dc11582010-08-06 09:25:50 -060053 struct platform_device *ofdev;
Olaf Hering140b9322008-04-24 23:16:00 +100054
Grant Likely2dc11582010-08-06 09:25:50 -060055 ofdev = to_platform_device(dev);
Rob Herringb6a945a2017-07-18 16:43:12 -050056 return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
Olaf Hering140b9322008-04-24 23:16:00 +100057}
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020058static DEVICE_ATTR_RO(modalias);
59static DEVICE_ATTR_RO(devspec);
Olaf Hering140b9322008-04-24 23:16:00 +100060
Rob Herring0bdba862018-09-04 16:27:44 -050061static ssize_t name_show(struct device *dev,
62 struct device_attribute *attr, char *buf)
63{
64 return sprintf(buf, "%pOFn\n", dev->of_node);
65}
66static DEVICE_ATTR_RO(name);
67
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040068macio_config_of_attr (type, "%s\n");
69
Greg Kroah-Hartman60bb70a2017-06-06 14:17:12 +020070static struct attribute *macio_dev_attrs[] = {
71 &dev_attr_name.attr,
72 &dev_attr_type.attr,
73 &dev_attr_compatible.attr,
74 &dev_attr_modalias.attr,
75 &dev_attr_devspec.attr,
76 NULL,
77};
78
79static const struct attribute_group macio_dev_group = {
80 .attrs = macio_dev_attrs,
81};
82
83const struct attribute_group *macio_dev_groups[] = {
84 &macio_dev_group,
85 NULL,
Jeff Mahoneyb5bf5b62005-07-06 15:26:27 -040086};