xref: /linux/drivers/macintosh/macio_sysfs.c (revision 0bdba867f01d69cffefee707504d3155a30f2d0f)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2b5bf5b67SJeff Mahoney #include <linux/kernel.h>
3b5bf5b67SJeff Mahoney #include <linux/stat.h>
4b5bf5b67SJeff Mahoney #include <asm/macio.h>
5b5bf5b67SJeff Mahoney 
6b5bf5b67SJeff Mahoney 
7b5bf5b67SJeff Mahoney #define macio_config_of_attr(field, format_string)			\
8b5bf5b67SJeff Mahoney static ssize_t								\
9b5bf5b67SJeff Mahoney field##_show (struct device *dev, struct device_attribute *attr,	\
10b5bf5b67SJeff Mahoney               char *buf)						\
11b5bf5b67SJeff Mahoney {									\
12b5bf5b67SJeff Mahoney 	struct macio_dev *mdev = to_macio_device (dev);			\
1361c7a080SGrant Likely 	return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \
1460bb70aaSGreg Kroah-Hartman }									\
1560bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(field);
16b5bf5b67SJeff Mahoney 
17b5bf5b67SJeff Mahoney static ssize_t
18b5bf5b67SJeff Mahoney compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
19b5bf5b67SJeff Mahoney {
202dc11581SGrant Likely 	struct platform_device *of;
21018a3d1dSJeremy Kerr 	const char *compat;
22b5bf5b67SJeff Mahoney 	int cplen;
23b5bf5b67SJeff Mahoney 	int length = 0;
24b5bf5b67SJeff Mahoney 
25b5bf5b67SJeff Mahoney 	of = &to_macio_device (dev)->ofdev;
2661c7a080SGrant Likely 	compat = of_get_property(of->dev.of_node, "compatible", &cplen);
27b5bf5b67SJeff Mahoney 	if (!compat) {
28b5bf5b67SJeff Mahoney 		*buf = '\0';
29b5bf5b67SJeff Mahoney 		return 0;
30b5bf5b67SJeff Mahoney 	}
31b5bf5b67SJeff Mahoney 	while (cplen > 0) {
32b5bf5b67SJeff Mahoney 		int l;
33b5bf5b67SJeff Mahoney 		length += sprintf (buf, "%s\n", compat);
34b5bf5b67SJeff Mahoney 		buf += length;
35b5bf5b67SJeff Mahoney 		l = strlen (compat) + 1;
36b5bf5b67SJeff Mahoney 		compat += l;
37b5bf5b67SJeff Mahoney 		cplen -= l;
38b5bf5b67SJeff Mahoney 	}
39b5bf5b67SJeff Mahoney 
40b5bf5b67SJeff Mahoney 	return length;
41b5bf5b67SJeff Mahoney }
4260bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(compatible);
43b5bf5b67SJeff Mahoney 
44dcb34abbSscwhab@suse.de static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
45dcb34abbSscwhab@suse.de 			      char *buf)
46dcb34abbSscwhab@suse.de {
470634c295SRob Herring 	return of_device_modalias(dev, buf, PAGE_SIZE);
48dcb34abbSscwhab@suse.de }
49dcb34abbSscwhab@suse.de 
50140b932fSOlaf Hering static ssize_t devspec_show(struct device *dev,
51140b932fSOlaf Hering 				struct device_attribute *attr, char *buf)
52140b932fSOlaf Hering {
532dc11581SGrant Likely 	struct platform_device *ofdev;
54140b932fSOlaf Hering 
552dc11581SGrant Likely 	ofdev = to_platform_device(dev);
56b6a945aeSRob Herring 	return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
57140b932fSOlaf Hering }
5860bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(modalias);
5960bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(devspec);
60140b932fSOlaf Hering 
61*0bdba867SRob Herring static ssize_t name_show(struct device *dev,
62*0bdba867SRob Herring 			 struct device_attribute *attr, char *buf)
63*0bdba867SRob Herring {
64*0bdba867SRob Herring 	return sprintf(buf, "%pOFn\n", dev->of_node);
65*0bdba867SRob Herring }
66*0bdba867SRob Herring static DEVICE_ATTR_RO(name);
67*0bdba867SRob Herring 
68b5bf5b67SJeff Mahoney macio_config_of_attr (type, "%s\n");
69b5bf5b67SJeff Mahoney 
7060bb70aaSGreg Kroah-Hartman static struct attribute *macio_dev_attrs[] = {
7160bb70aaSGreg Kroah-Hartman 	&dev_attr_name.attr,
7260bb70aaSGreg Kroah-Hartman 	&dev_attr_type.attr,
7360bb70aaSGreg Kroah-Hartman 	&dev_attr_compatible.attr,
7460bb70aaSGreg Kroah-Hartman 	&dev_attr_modalias.attr,
7560bb70aaSGreg Kroah-Hartman 	&dev_attr_devspec.attr,
7660bb70aaSGreg Kroah-Hartman 	NULL,
7760bb70aaSGreg Kroah-Hartman };
7860bb70aaSGreg Kroah-Hartman 
7960bb70aaSGreg Kroah-Hartman static const struct attribute_group macio_dev_group = {
8060bb70aaSGreg Kroah-Hartman 	.attrs = macio_dev_attrs,
8160bb70aaSGreg Kroah-Hartman };
8260bb70aaSGreg Kroah-Hartman 
8360bb70aaSGreg Kroah-Hartman const struct attribute_group *macio_dev_groups[] = {
8460bb70aaSGreg Kroah-Hartman 	&macio_dev_group,
8560bb70aaSGreg Kroah-Hartman 	NULL,
86b5bf5b67SJeff Mahoney };
87