1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2b5bf5b67SJeff Mahoney #include <linux/kernel.h>
3*a486e512SChristophe Leroy #include <linux/of.h>
4*a486e512SChristophe Leroy #include <linux/of_device.h>
5b5bf5b67SJeff Mahoney #include <linux/stat.h>
6b5bf5b67SJeff Mahoney #include <asm/macio.h>
7b5bf5b67SJeff Mahoney
8b5bf5b67SJeff Mahoney static ssize_t
compatible_show(struct device * dev,struct device_attribute * attr,char * buf)9b5bf5b67SJeff Mahoney compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
10b5bf5b67SJeff Mahoney {
112dc11581SGrant Likely struct platform_device *of;
12018a3d1dSJeremy Kerr const char *compat;
13b5bf5b67SJeff Mahoney int cplen;
14b5bf5b67SJeff Mahoney int length = 0;
15b5bf5b67SJeff Mahoney
16b5bf5b67SJeff Mahoney of = &to_macio_device (dev)->ofdev;
1761c7a080SGrant Likely compat = of_get_property(of->dev.of_node, "compatible", &cplen);
18b5bf5b67SJeff Mahoney if (!compat) {
19b5bf5b67SJeff Mahoney *buf = '\0';
20b5bf5b67SJeff Mahoney return 0;
21b5bf5b67SJeff Mahoney }
22b5bf5b67SJeff Mahoney while (cplen > 0) {
23b5bf5b67SJeff Mahoney int l;
24b5bf5b67SJeff Mahoney length += sprintf (buf, "%s\n", compat);
25b5bf5b67SJeff Mahoney buf += length;
26b5bf5b67SJeff Mahoney l = strlen (compat) + 1;
27b5bf5b67SJeff Mahoney compat += l;
28b5bf5b67SJeff Mahoney cplen -= l;
29b5bf5b67SJeff Mahoney }
30b5bf5b67SJeff Mahoney
31b5bf5b67SJeff Mahoney return length;
32b5bf5b67SJeff Mahoney }
3360bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(compatible);
34b5bf5b67SJeff Mahoney
modalias_show(struct device * dev,struct device_attribute * attr,char * buf)35dcb34abbSscwhab@suse.de static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
36dcb34abbSscwhab@suse.de char *buf)
37dcb34abbSscwhab@suse.de {
380634c295SRob Herring return of_device_modalias(dev, buf, PAGE_SIZE);
39dcb34abbSscwhab@suse.de }
40dcb34abbSscwhab@suse.de
devspec_show(struct device * dev,struct device_attribute * attr,char * buf)41140b932fSOlaf Hering static ssize_t devspec_show(struct device *dev,
42140b932fSOlaf Hering struct device_attribute *attr, char *buf)
43140b932fSOlaf Hering {
442dc11581SGrant Likely struct platform_device *ofdev;
45140b932fSOlaf Hering
462dc11581SGrant Likely ofdev = to_platform_device(dev);
47b6a945aeSRob Herring return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
48140b932fSOlaf Hering }
4960bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(modalias);
5060bb70aaSGreg Kroah-Hartman static DEVICE_ATTR_RO(devspec);
51140b932fSOlaf Hering
name_show(struct device * dev,struct device_attribute * attr,char * buf)520bdba867SRob Herring static ssize_t name_show(struct device *dev,
530bdba867SRob Herring struct device_attribute *attr, char *buf)
540bdba867SRob Herring {
550bdba867SRob Herring return sprintf(buf, "%pOFn\n", dev->of_node);
560bdba867SRob Herring }
570bdba867SRob Herring static DEVICE_ATTR_RO(name);
580bdba867SRob Herring
type_show(struct device * dev,struct device_attribute * attr,char * buf)59bf82d375SRob Herring static ssize_t type_show(struct device *dev,
60bf82d375SRob Herring struct device_attribute *attr, char *buf)
61bf82d375SRob Herring {
62bf82d375SRob Herring return sprintf(buf, "%s\n", of_node_get_device_type(dev->of_node));
63bf82d375SRob Herring }
64bf82d375SRob Herring static DEVICE_ATTR_RO(type);
65b5bf5b67SJeff Mahoney
6660bb70aaSGreg Kroah-Hartman static struct attribute *macio_dev_attrs[] = {
6760bb70aaSGreg Kroah-Hartman &dev_attr_name.attr,
6860bb70aaSGreg Kroah-Hartman &dev_attr_type.attr,
6960bb70aaSGreg Kroah-Hartman &dev_attr_compatible.attr,
7060bb70aaSGreg Kroah-Hartman &dev_attr_modalias.attr,
7160bb70aaSGreg Kroah-Hartman &dev_attr_devspec.attr,
7260bb70aaSGreg Kroah-Hartman NULL,
7360bb70aaSGreg Kroah-Hartman };
7460bb70aaSGreg Kroah-Hartman
7560bb70aaSGreg Kroah-Hartman static const struct attribute_group macio_dev_group = {
7660bb70aaSGreg Kroah-Hartman .attrs = macio_dev_attrs,
7760bb70aaSGreg Kroah-Hartman };
7860bb70aaSGreg Kroah-Hartman
7960bb70aaSGreg Kroah-Hartman const struct attribute_group *macio_dev_groups[] = {
8060bb70aaSGreg Kroah-Hartman &macio_dev_group,
8160bb70aaSGreg Kroah-Hartman NULL,
82b5bf5b67SJeff Mahoney };
83