Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/kernel.h>
0003 #include <linux/of.h>
0004 #include <linux/of_device.h>
0005 #include <linux/stat.h>
0006 #include <asm/macio.h>
0007 
0008 static ssize_t
0009 compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
0010 {
0011     struct platform_device *of;
0012     const char *compat;
0013     int cplen;
0014     int length = 0;
0015 
0016     of = &to_macio_device (dev)->ofdev;
0017     compat = of_get_property(of->dev.of_node, "compatible", &cplen);
0018     if (!compat) {
0019         *buf = '\0';
0020         return 0;
0021     }
0022     while (cplen > 0) {
0023         int l;
0024         length += sprintf (buf, "%s\n", compat);
0025         buf += length;
0026         l = strlen (compat) + 1;
0027         compat += l;
0028         cplen -= l;
0029     }
0030 
0031     return length;
0032 }
0033 static DEVICE_ATTR_RO(compatible);
0034 
0035 static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
0036                   char *buf)
0037 {
0038     return of_device_modalias(dev, buf, PAGE_SIZE);
0039 }
0040 
0041 static ssize_t devspec_show(struct device *dev,
0042                 struct device_attribute *attr, char *buf)
0043 {
0044     struct platform_device *ofdev;
0045 
0046     ofdev = to_platform_device(dev);
0047     return sprintf(buf, "%pOF\n", ofdev->dev.of_node);
0048 }
0049 static DEVICE_ATTR_RO(modalias);
0050 static DEVICE_ATTR_RO(devspec);
0051 
0052 static ssize_t name_show(struct device *dev,
0053              struct device_attribute *attr, char *buf)
0054 {
0055     return sprintf(buf, "%pOFn\n", dev->of_node);
0056 }
0057 static DEVICE_ATTR_RO(name);
0058 
0059 static ssize_t type_show(struct device *dev,
0060              struct device_attribute *attr, char *buf)
0061 {
0062     return sprintf(buf, "%s\n", of_node_get_device_type(dev->of_node));
0063 }
0064 static DEVICE_ATTR_RO(type);
0065 
0066 static struct attribute *macio_dev_attrs[] = {
0067     &dev_attr_name.attr,
0068     &dev_attr_type.attr,
0069     &dev_attr_compatible.attr,
0070     &dev_attr_modalias.attr,
0071     &dev_attr_devspec.attr,
0072     NULL,
0073 };
0074 
0075 static const struct attribute_group macio_dev_group = {
0076     .attrs = macio_dev_attrs,
0077 };
0078 
0079 const struct attribute_group *macio_dev_groups[] = {
0080     &macio_dev_group,
0081     NULL,
0082 };