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