1*b5bf5b67SJeff Mahoney #include <linux/config.h> 2*b5bf5b67SJeff Mahoney #include <linux/kernel.h> 3*b5bf5b67SJeff Mahoney #include <linux/stat.h> 4*b5bf5b67SJeff Mahoney #include <asm/macio.h> 5*b5bf5b67SJeff Mahoney 6*b5bf5b67SJeff Mahoney 7*b5bf5b67SJeff Mahoney #define macio_config_of_attr(field, format_string) \ 8*b5bf5b67SJeff Mahoney static ssize_t \ 9*b5bf5b67SJeff Mahoney field##_show (struct device *dev, struct device_attribute *attr, \ 10*b5bf5b67SJeff Mahoney char *buf) \ 11*b5bf5b67SJeff Mahoney { \ 12*b5bf5b67SJeff Mahoney struct macio_dev *mdev = to_macio_device (dev); \ 13*b5bf5b67SJeff Mahoney return sprintf (buf, format_string, mdev->ofdev.node->field); \ 14*b5bf5b67SJeff Mahoney } 15*b5bf5b67SJeff Mahoney 16*b5bf5b67SJeff Mahoney static ssize_t 17*b5bf5b67SJeff Mahoney compatible_show (struct device *dev, struct device_attribute *attr, char *buf) 18*b5bf5b67SJeff Mahoney { 19*b5bf5b67SJeff Mahoney struct of_device *of; 20*b5bf5b67SJeff Mahoney char *compat; 21*b5bf5b67SJeff Mahoney int cplen; 22*b5bf5b67SJeff Mahoney int length = 0; 23*b5bf5b67SJeff Mahoney 24*b5bf5b67SJeff Mahoney of = &to_macio_device (dev)->ofdev; 25*b5bf5b67SJeff Mahoney compat = (char *) get_property(of->node, "compatible", &cplen); 26*b5bf5b67SJeff Mahoney if (!compat) { 27*b5bf5b67SJeff Mahoney *buf = '\0'; 28*b5bf5b67SJeff Mahoney return 0; 29*b5bf5b67SJeff Mahoney } 30*b5bf5b67SJeff Mahoney while (cplen > 0) { 31*b5bf5b67SJeff Mahoney int l; 32*b5bf5b67SJeff Mahoney length += sprintf (buf, "%s\n", compat); 33*b5bf5b67SJeff Mahoney buf += length; 34*b5bf5b67SJeff Mahoney l = strlen (compat) + 1; 35*b5bf5b67SJeff Mahoney compat += l; 36*b5bf5b67SJeff Mahoney cplen -= l; 37*b5bf5b67SJeff Mahoney } 38*b5bf5b67SJeff Mahoney 39*b5bf5b67SJeff Mahoney return length; 40*b5bf5b67SJeff Mahoney } 41*b5bf5b67SJeff Mahoney 42*b5bf5b67SJeff Mahoney macio_config_of_attr (name, "%s\n"); 43*b5bf5b67SJeff Mahoney macio_config_of_attr (type, "%s\n"); 44*b5bf5b67SJeff Mahoney 45*b5bf5b67SJeff Mahoney struct device_attribute macio_dev_attrs[] = { 46*b5bf5b67SJeff Mahoney __ATTR_RO(name), 47*b5bf5b67SJeff Mahoney __ATTR_RO(type), 48*b5bf5b67SJeff Mahoney __ATTR_RO(compatible), 49*b5bf5b67SJeff Mahoney __ATTR_NULL 50*b5bf5b67SJeff Mahoney }; 51