2005-07-06 15:26:27 -04:00
# include <linux/kernel.h>
# include <linux/stat.h>
# include <asm/macio.h>
# define macio_config_of_attr(field, format_string) \
static ssize_t \
field # # _show ( struct device * dev , struct device_attribute * attr , \
char * buf ) \
{ \
struct macio_dev * mdev = to_macio_device ( dev ) ; \
2010-04-13 16:12:29 -07:00
return sprintf ( buf , format_string , mdev - > ofdev . dev . of_node - > field ) ; \
2017-06-06 14:17:12 +02:00
} \
static DEVICE_ATTR_RO ( field ) ;
2005-07-06 15:26:27 -04:00
static ssize_t
compatible_show ( struct device * dev , struct device_attribute * attr , char * buf )
{
2010-08-06 09:25:50 -06:00
struct platform_device * of ;
2006-07-12 15:40:29 +10:00
const char * compat ;
2005-07-06 15:26:27 -04:00
int cplen ;
int length = 0 ;
of = & to_macio_device ( dev ) - > ofdev ;
2010-04-13 16:12:29 -07:00
compat = of_get_property ( of - > dev . of_node , " compatible " , & cplen ) ;
2005-07-06 15:26:27 -04:00
if ( ! compat ) {
* buf = ' \0 ' ;
return 0 ;
}
while ( cplen > 0 ) {
int l ;
length + = sprintf ( buf , " %s \n " , compat ) ;
buf + = length ;
l = strlen ( compat ) + 1 ;
compat + = l ;
cplen - = l ;
}
return length ;
}
2017-06-06 14:17:12 +02:00
static DEVICE_ATTR_RO ( compatible ) ;
2005-07-06 15:26:27 -04:00
2005-10-28 17:46:20 -07:00
static ssize_t modalias_show ( struct device * dev , struct device_attribute * attr ,
char * buf )
{
2017-03-22 09:16:27 -05:00
return of_device_modalias ( dev , buf , PAGE_SIZE ) ;
2005-10-28 17:46:20 -07:00
}
2008-04-24 23:16:00 +10:00
static ssize_t devspec_show ( struct device * dev ,
struct device_attribute * attr , char * buf )
{
2010-08-06 09:25:50 -06:00
struct platform_device * ofdev ;
2008-04-24 23:16:00 +10:00
2010-08-06 09:25:50 -06:00
ofdev = to_platform_device ( dev ) ;
2017-07-18 16:43:12 -05:00
return sprintf ( buf , " %pOF \n " , ofdev - > dev . of_node ) ;
2008-04-24 23:16:00 +10:00
}
2017-06-06 14:17:12 +02:00
static DEVICE_ATTR_RO ( modalias ) ;
static DEVICE_ATTR_RO ( devspec ) ;
2008-04-24 23:16:00 +10:00
2005-07-06 15:26:27 -04:00
macio_config_of_attr ( name , " %s \n " ) ;
macio_config_of_attr ( type , " %s \n " ) ;
2017-06-06 14:17:12 +02:00
static struct attribute * macio_dev_attrs [ ] = {
& dev_attr_name . attr ,
& dev_attr_type . attr ,
& dev_attr_compatible . attr ,
& dev_attr_modalias . attr ,
& dev_attr_devspec . attr ,
NULL ,
} ;
static const struct attribute_group macio_dev_group = {
. attrs = macio_dev_attrs ,
} ;
const struct attribute_group * macio_dev_groups [ ] = {
& macio_dev_group ,
NULL ,
2005-07-06 15:26:27 -04:00
} ;