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