xref: /linux/drivers/macintosh/macio_sysfs.c (revision 60bb70aa761ca4090a718926f8299364a0c61ae0)
1b5bf5b67SJeff Mahoney #include <linux/kernel.h>
2b5bf5b67SJeff Mahoney #include <linux/stat.h>
3b5bf5b67SJeff Mahoney #include <asm/macio.h>
4b5bf5b67SJeff Mahoney 
5b5bf5b67SJeff Mahoney 
6b5bf5b67SJeff Mahoney #define macio_config_of_attr(field, format_string)			\
7b5bf5b67SJeff Mahoney static ssize_t								\
8b5bf5b67SJeff Mahoney field##_show (struct device *dev, struct device_attribute *attr,	\
9b5bf5b67SJeff Mahoney               char *buf)						\
10b5bf5b67SJeff Mahoney {									\
11b5bf5b67SJeff Mahoney 	struct macio_dev *mdev = to_macio_device (dev);			\
1261c7a080SGrant Likely 	return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \
13*60bb70aaSGreg Kroah-Hartman }									\
14*60bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(field);
15b5bf5b67SJeff Mahoney 
16b5bf5b67SJeff Mahoney static ssize_t
17b5bf5b67SJeff Mahoney compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
18b5bf5b67SJeff Mahoney {
192dc11581SGrant Likely 	struct platform_device *of;
20018a3d1dSJeremy Kerr 	const char *compat;
21b5bf5b67SJeff Mahoney 	int cplen;
22b5bf5b67SJeff Mahoney 	int length = 0;
23b5bf5b67SJeff Mahoney 
24b5bf5b67SJeff Mahoney 	of = &to_macio_device (dev)->ofdev;
2561c7a080SGrant Likely 	compat = of_get_property(of->dev.of_node, "compatible", &cplen);
26b5bf5b67SJeff Mahoney 	if (!compat) {
27b5bf5b67SJeff Mahoney 		*buf = '\0';
28b5bf5b67SJeff Mahoney 		return 0;
29b5bf5b67SJeff Mahoney 	}
30b5bf5b67SJeff Mahoney 	while (cplen > 0) {
31b5bf5b67SJeff Mahoney 		int l;
32b5bf5b67SJeff Mahoney 		length += sprintf (buf, "%s\n", compat);
33b5bf5b67SJeff Mahoney 		buf += length;
34b5bf5b67SJeff Mahoney 		l = strlen (compat) + 1;
35b5bf5b67SJeff Mahoney 		compat += l;
36b5bf5b67SJeff Mahoney 		cplen -= l;
37b5bf5b67SJeff Mahoney 	}
38b5bf5b67SJeff Mahoney 
39b5bf5b67SJeff Mahoney 	return length;
40b5bf5b67SJeff Mahoney }
41*60bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(compatible);
42b5bf5b67SJeff Mahoney 
43dcb34abbSscwhab@suse.de static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
44dcb34abbSscwhab@suse.de 			      char *buf)
45dcb34abbSscwhab@suse.de {
460634c295SRob Herring 	return of_device_modalias(dev, buf, PAGE_SIZE);
47dcb34abbSscwhab@suse.de }
48dcb34abbSscwhab@suse.de 
49140b932fSOlaf Hering static ssize_t devspec_show(struct device *dev,
50140b932fSOlaf Hering 				struct device_attribute *attr, char *buf)
51140b932fSOlaf Hering {
522dc11581SGrant Likely 	struct platform_device *ofdev;
53140b932fSOlaf Hering 
542dc11581SGrant Likely 	ofdev = to_platform_device(dev);
5561c7a080SGrant Likely 	return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
56140b932fSOlaf Hering }
57*60bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(modalias);
58*60bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(devspec);
59140b932fSOlaf Hering 
60b5bf5b67SJeff Mahoney macio_config_of_attr (name, "%s\n");
61b5bf5b67SJeff Mahoney macio_config_of_attr (type, "%s\n");
62b5bf5b67SJeff Mahoney 
63*60bb70aaSGreg Kroah-Hartman static struct attribute *macio_dev_attrs[] = {
64*60bb70aaSGreg Kroah-Hartman 	&dev_attr_name.attr,
65*60bb70aaSGreg Kroah-Hartman 	&dev_attr_type.attr,
66*60bb70aaSGreg Kroah-Hartman 	&dev_attr_compatible.attr,
67*60bb70aaSGreg Kroah-Hartman 	&dev_attr_modalias.attr,
68*60bb70aaSGreg Kroah-Hartman 	&dev_attr_devspec.attr,
69*60bb70aaSGreg Kroah-Hartman 	NULL,
70*60bb70aaSGreg Kroah-Hartman };
71*60bb70aaSGreg Kroah-Hartman 
72*60bb70aaSGreg Kroah-Hartman static const struct attribute_group macio_dev_group = {
73*60bb70aaSGreg Kroah-Hartman 	.attrs = macio_dev_attrs,
74*60bb70aaSGreg Kroah-Hartman };
75*60bb70aaSGreg Kroah-Hartman 
76*60bb70aaSGreg Kroah-Hartman const struct attribute_group *macio_dev_groups[] = {
77*60bb70aaSGreg Kroah-Hartman 	&macio_dev_group,
78*60bb70aaSGreg Kroah-Hartman 	NULL,
79b5bf5b67SJeff Mahoney };
80