ckfwq/linux-3.0.4/drivers/spi/adc/adc-sysfs.c

124 lines
2.8 KiB
C

/*
* ADC subsystem, sysfs interface
*
* Copyright (C) 2013-10
* Author: Davied <apple_guet@126.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/rtc.h>
#include <linux/adc-core.h>
#ifdef CONFIG_ADC_SYS_DEBUG
#define DBG(msg...) do { \
printk(KERN_INFO msg); \
} while (0)
#else
#define DBG(msg...) do { } while(0)
#endif
/* device attributes */
static ssize_t
adc_sysfs_show_name(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", to_adc_device(dev)->name);
}
static ssize_t
adc_sysfs_show_pbat(struct device *dev, struct device_attribute *attr,
char *buf)
{
int result = 0;
struct adc_core_dev *adc = to_adc_device(dev);
result = adc->ops->convert(CMD_AD_CON_PBAT);
printk(KERN_INFO "pbat = %d\n", result);
sprintf(buf, "%d\n", result);
return 0;
}
static ssize_t
adc_sysfs_show_ch0(struct device *dev, struct device_attribute *attr,
char *buf)
{
int result = 0;
struct adc_core_dev *adc = to_adc_device(dev);
result = adc->ops->convert(CMD_AD_CON_CH0);
printk(KERN_INFO "ch0 = %d\n", result);
sprintf(buf, "%d\n", result);
return 0;
}
static ssize_t
adc_sysfs_show_ch1(struct device *dev, struct device_attribute *attr,
char *buf)
{
int result = 0;
struct adc_core_dev *adc = to_adc_device(dev);
result = adc->ops->convert(CMD_AD_CON_CH1);
printk(KERN_INFO "ch1 = %d\n", result);
sprintf(buf, "%d\n", result);
return 0;
}
static ssize_t
adc_sysfs_show_ch2(struct device *dev, struct device_attribute *attr,
char *buf)
{
int result = 0;
struct adc_core_dev *adc = to_adc_device(dev);
result = adc->ops->convert(CMD_AD_CON_CH2);
printk(KERN_INFO "ch2 = %d\n", result);
sprintf(buf, "%d\n", result);
return 0;
}
static ssize_t
adc_sysfs_show_ch3(struct device *dev, struct device_attribute *attr,
char *buf)
{
int result = 0;
struct adc_core_dev *adc = to_adc_device(dev);
result = adc->ops->convert(CMD_AD_CON_CH3);
printk(KERN_INFO "ch3 = %d\n", result);
sprintf(buf, "%d\n", result);
return 0;
}
static struct device_attribute adc_attrs[] = {
__ATTR(name, S_IRUGO, adc_sysfs_show_name, NULL),
__ATTR(pbat, S_IRUGO, adc_sysfs_show_pbat, NULL),
__ATTR(ch0, S_IRUGO, adc_sysfs_show_ch0, NULL),
__ATTR(ch1, S_IRUGO, adc_sysfs_show_ch1, NULL),
__ATTR(ch2, S_IRUGO, adc_sysfs_show_ch2, NULL),
__ATTR(ch3, S_IRUGO, adc_sysfs_show_ch3, NULL),
{ },
};
void adc_sysfs_add_device(struct adc_core_dev *adc)
{
/* do nothing */
}
void adc_sysfs_del_device(struct adc_core_dev *adc)
{
/* do nothing */
}
void __init adc_sysfs_init(struct class *adc_class)
{
adc_class->dev_attrs = adc_attrs;
}