xref: /linux/drivers/macintosh/macio_sysfs.c (revision 0634c2958927198797bf9e55d26fb51cce4c22b4)
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); \
13b5bf5b67SJeff Mahoney }
14b5bf5b67SJeff Mahoney 
15b5bf5b67SJeff Mahoney static ssize_t
16b5bf5b67SJeff Mahoney compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
17b5bf5b67SJeff Mahoney {
182dc11581SGrant Likely 	struct platform_device *of;
19018a3d1dSJeremy Kerr 	const char *compat;
20b5bf5b67SJeff Mahoney 	int cplen;
21b5bf5b67SJeff Mahoney 	int length = 0;
22b5bf5b67SJeff Mahoney 
23b5bf5b67SJeff Mahoney 	of = &to_macio_device (dev)->ofdev;
2461c7a080SGrant Likely 	compat = of_get_property(of->dev.of_node, "compatible", &cplen);
25b5bf5b67SJeff Mahoney 	if (!compat) {
26b5bf5b67SJeff Mahoney 		*buf = '\0';
27b5bf5b67SJeff Mahoney 		return 0;
28b5bf5b67SJeff Mahoney 	}
29b5bf5b67SJeff Mahoney 	while (cplen > 0) {
30b5bf5b67SJeff Mahoney 		int l;
31b5bf5b67SJeff Mahoney 		length += sprintf (buf, "%s\n", compat);
32b5bf5b67SJeff Mahoney 		buf += length;
33b5bf5b67SJeff Mahoney 		l = strlen (compat) + 1;
34b5bf5b67SJeff Mahoney 		compat += l;
35b5bf5b67SJeff Mahoney 		cplen -= l;
36b5bf5b67SJeff Mahoney 	}
37b5bf5b67SJeff Mahoney 
38b5bf5b67SJeff Mahoney 	return length;
39b5bf5b67SJeff Mahoney }
40b5bf5b67SJeff Mahoney 
41dcb34abbSscwhab@suse.de static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
42dcb34abbSscwhab@suse.de 			      char *buf)
43dcb34abbSscwhab@suse.de {
44*0634c295SRob Herring 	return of_device_modalias(dev, buf, PAGE_SIZE);
45dcb34abbSscwhab@suse.de }
46dcb34abbSscwhab@suse.de 
47140b932fSOlaf Hering static ssize_t devspec_show(struct device *dev,
48140b932fSOlaf Hering 				struct device_attribute *attr, char *buf)
49140b932fSOlaf Hering {
502dc11581SGrant Likely 	struct platform_device *ofdev;
51140b932fSOlaf Hering 
522dc11581SGrant Likely 	ofdev = to_platform_device(dev);
5361c7a080SGrant Likely 	return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
54140b932fSOlaf Hering }
55140b932fSOlaf Hering 
56b5bf5b67SJeff Mahoney macio_config_of_attr (name, "%s\n");
57b5bf5b67SJeff Mahoney macio_config_of_attr (type, "%s\n");
58b5bf5b67SJeff Mahoney 
59b5bf5b67SJeff Mahoney struct device_attribute macio_dev_attrs[] = {
60b5bf5b67SJeff Mahoney 	__ATTR_RO(name),
61b5bf5b67SJeff Mahoney 	__ATTR_RO(type),
62b5bf5b67SJeff Mahoney 	__ATTR_RO(compatible),
63dcb34abbSscwhab@suse.de 	__ATTR_RO(modalias),
64140b932fSOlaf Hering 	__ATTR_RO(devspec),
65b5bf5b67SJeff Mahoney 	__ATTR_NULL
66b5bf5b67SJeff Mahoney };
67