1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun #include <linux/kernel.h>
3*4882a593Smuzhiyun #include <linux/of.h>
4*4882a593Smuzhiyun #include <linux/stat.h>
5*4882a593Smuzhiyun /* FIX UP */
6*4882a593Smuzhiyun #include "soundbus.h"
7*4882a593Smuzhiyun
modalias_show(struct device * dev,struct device_attribute * attr,char * buf)8*4882a593Smuzhiyun static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
9*4882a593Smuzhiyun char *buf)
10*4882a593Smuzhiyun {
11*4882a593Smuzhiyun struct soundbus_dev *sdev = to_soundbus_device(dev);
12*4882a593Smuzhiyun struct platform_device *of = &sdev->ofdev;
13*4882a593Smuzhiyun int length;
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun if (*sdev->modalias) {
16*4882a593Smuzhiyun strlcpy(buf, sdev->modalias, sizeof(sdev->modalias) + 1);
17*4882a593Smuzhiyun strcat(buf, "\n");
18*4882a593Smuzhiyun length = strlen(buf);
19*4882a593Smuzhiyun } else {
20*4882a593Smuzhiyun length = sprintf(buf, "of:N%pOFn%c%s\n",
21*4882a593Smuzhiyun of->dev.of_node, 'T',
22*4882a593Smuzhiyun of_node_get_device_type(of->dev.of_node));
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun return length;
26*4882a593Smuzhiyun }
27*4882a593Smuzhiyun static DEVICE_ATTR_RO(modalias);
28*4882a593Smuzhiyun
name_show(struct device * dev,struct device_attribute * attr,char * buf)29*4882a593Smuzhiyun static ssize_t name_show(struct device *dev,
30*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun struct soundbus_dev *sdev = to_soundbus_device(dev);
33*4882a593Smuzhiyun struct platform_device *of = &sdev->ofdev;
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun return sprintf(buf, "%pOFn\n", of->dev.of_node);
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun static DEVICE_ATTR_RO(name);
38*4882a593Smuzhiyun
type_show(struct device * dev,struct device_attribute * attr,char * buf)39*4882a593Smuzhiyun static ssize_t type_show(struct device *dev,
40*4882a593Smuzhiyun struct device_attribute *attr, char *buf)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun struct soundbus_dev *sdev = to_soundbus_device(dev);
43*4882a593Smuzhiyun struct platform_device *of = &sdev->ofdev;
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun return sprintf(buf, "%s\n", of_node_get_device_type(of->dev.of_node));
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun static DEVICE_ATTR_RO(type);
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun struct attribute *soundbus_dev_attrs[] = {
50*4882a593Smuzhiyun &dev_attr_name.attr,
51*4882a593Smuzhiyun &dev_attr_type.attr,
52*4882a593Smuzhiyun &dev_attr_modalias.attr,
53*4882a593Smuzhiyun NULL,
54*4882a593Smuzhiyun };
55