Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 2 | #include <linux/kernel.h> |
| 3 | #include <linux/stat.h> |
| 4 | #include <asm/macio.h> |
| 5 | |
| 6 | |
| 7 | #define macio_config_of_attr(field, format_string) \ |
| 8 | static ssize_t \ |
| 9 | field##_show (struct device *dev, struct device_attribute *attr, \ |
| 10 | char *buf) \ |
| 11 | { \ |
| 12 | struct macio_dev *mdev = to_macio_device (dev); \ |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 13 | return sprintf (buf, format_string, mdev->ofdev.dev.of_node->field); \ |
Greg Kroah-Hartman | 60bb70a | 2017-06-06 14:17:12 +0200 | [diff] [blame] | 14 | } \ |
| 15 | static DEVICE_ATTR_RO(field); |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 16 | |
| 17 | static ssize_t |
| 18 | compatible_show (struct device *dev, struct device_attribute *attr, char *buf) |
| 19 | { |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 20 | struct platform_device *of; |
Jeremy Kerr | 018a3d1 | 2006-07-12 15:40:29 +1000 | [diff] [blame] | 21 | const char *compat; |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 22 | int cplen; |
| 23 | int length = 0; |
| 24 | |
| 25 | of = &to_macio_device (dev)->ofdev; |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 26 | compat = of_get_property(of->dev.of_node, "compatible", &cplen); |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 27 | if (!compat) { |
| 28 | *buf = '\0'; |
| 29 | return 0; |
| 30 | } |
| 31 | while (cplen > 0) { |
| 32 | int l; |
| 33 | length += sprintf (buf, "%s\n", compat); |
| 34 | buf += length; |
| 35 | l = strlen (compat) + 1; |
| 36 | compat += l; |
| 37 | cplen -= l; |
| 38 | } |
| 39 | |
| 40 | return length; |
| 41 | } |
Greg Kroah-Hartman | 60bb70a | 2017-06-06 14:17:12 +0200 | [diff] [blame] | 42 | static DEVICE_ATTR_RO(compatible); |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 43 | |
scwhab@suse.de | dcb34ab | 2005-10-28 17:46:20 -0700 | [diff] [blame] | 44 | static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, |
| 45 | char *buf) |
| 46 | { |
Rob Herring | 0634c29 | 2017-03-22 09:16:27 -0500 | [diff] [blame] | 47 | return of_device_modalias(dev, buf, PAGE_SIZE); |
scwhab@suse.de | dcb34ab | 2005-10-28 17:46:20 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Olaf Hering | 140b932 | 2008-04-24 23:16:00 +1000 | [diff] [blame] | 50 | static ssize_t devspec_show(struct device *dev, |
| 51 | struct device_attribute *attr, char *buf) |
| 52 | { |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 53 | struct platform_device *ofdev; |
Olaf Hering | 140b932 | 2008-04-24 23:16:00 +1000 | [diff] [blame] | 54 | |
Grant Likely | 2dc1158 | 2010-08-06 09:25:50 -0600 | [diff] [blame] | 55 | ofdev = to_platform_device(dev); |
Rob Herring | b6a945a | 2017-07-18 16:43:12 -0500 | [diff] [blame] | 56 | return sprintf(buf, "%pOF\n", ofdev->dev.of_node); |
Olaf Hering | 140b932 | 2008-04-24 23:16:00 +1000 | [diff] [blame] | 57 | } |
Greg Kroah-Hartman | 60bb70a | 2017-06-06 14:17:12 +0200 | [diff] [blame] | 58 | static DEVICE_ATTR_RO(modalias); |
| 59 | static DEVICE_ATTR_RO(devspec); |
Olaf Hering | 140b932 | 2008-04-24 23:16:00 +1000 | [diff] [blame] | 60 | |
Rob Herring | 0bdba86 | 2018-09-04 16:27:44 -0500 | [diff] [blame^] | 61 | static ssize_t name_show(struct device *dev, |
| 62 | struct device_attribute *attr, char *buf) |
| 63 | { |
| 64 | return sprintf(buf, "%pOFn\n", dev->of_node); |
| 65 | } |
| 66 | static DEVICE_ATTR_RO(name); |
| 67 | |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 68 | macio_config_of_attr (type, "%s\n"); |
| 69 | |
Greg Kroah-Hartman | 60bb70a | 2017-06-06 14:17:12 +0200 | [diff] [blame] | 70 | static struct attribute *macio_dev_attrs[] = { |
| 71 | &dev_attr_name.attr, |
| 72 | &dev_attr_type.attr, |
| 73 | &dev_attr_compatible.attr, |
| 74 | &dev_attr_modalias.attr, |
| 75 | &dev_attr_devspec.attr, |
| 76 | NULL, |
| 77 | }; |
| 78 | |
| 79 | static const struct attribute_group macio_dev_group = { |
| 80 | .attrs = macio_dev_attrs, |
| 81 | }; |
| 82 | |
| 83 | const struct attribute_group *macio_dev_groups[] = { |
| 84 | &macio_dev_group, |
| 85 | NULL, |
Jeff Mahoney | b5bf5b6 | 2005-07-06 15:26:27 -0400 | [diff] [blame] | 86 | }; |