88 lines
2.1 KiB
C
88 lines
2.1 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/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/adc-core.h>
|
|
|
|
|
|
#ifdef CONFIG_ADC_PROC_DEBUG
|
|
#define DBG(msg...) do { \
|
|
printk(KERN_INFO msg); \
|
|
} while (0)
|
|
#else
|
|
#define DBG(msg...) do { } while(0)
|
|
#endif
|
|
|
|
|
|
static int adc_proc_show(struct seq_file *seq, void *offset)
|
|
{
|
|
int result = 0;
|
|
struct adc_core_dev *adc = seq->private;
|
|
|
|
result = adc->ops->convert(CMD_AD_CON_PBAT);
|
|
seq_printf(seq, "PBAT:%d\n", result);
|
|
result = adc->ops->convert(CMD_AD_CON_CH0);
|
|
seq_printf(seq, "CH0:%d\n", result);
|
|
result = adc->ops->convert(CMD_AD_CON_CH1);
|
|
seq_printf(seq, "CH1:%d\n", result);
|
|
result = adc->ops->convert(CMD_AD_CON_CH2);
|
|
seq_printf(seq, "CH2:%d\n", result);
|
|
result = adc->ops->convert(CMD_AD_CON_CH3);
|
|
seq_printf(seq, "CH3:%d\n", result);
|
|
if (adc->ops->proc)
|
|
adc->ops->proc(adc->dev.parent, seq);
|
|
return 0;
|
|
}
|
|
|
|
static int adc_proc_open(struct inode *inode, struct file *file)
|
|
{
|
|
int ret;
|
|
struct adc_core_dev *adc = PDE(inode)->data;
|
|
|
|
if (!try_module_get(THIS_MODULE)) {
|
|
DBG("!!!!!!try_module_get error!!!!!!\n");
|
|
return -ENODEV;
|
|
}
|
|
ret = single_open(file, adc_proc_show, adc);
|
|
if (ret)
|
|
module_put(THIS_MODULE);
|
|
return ret;
|
|
}
|
|
|
|
static int adc_proc_release(struct inode *inode, struct file *file)
|
|
{
|
|
int res = single_release(inode, file);
|
|
module_put(THIS_MODULE);
|
|
return res;
|
|
}
|
|
|
|
static const struct file_operations adc_proc_fops = {
|
|
.open = adc_proc_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = adc_proc_release,
|
|
};
|
|
|
|
void adc_proc_add_device(struct adc_core_dev *adc)
|
|
{
|
|
if (adc->id == 0)
|
|
proc_create_data("driver/adc", 0, NULL, &adc_proc_fops, adc);
|
|
}
|
|
|
|
void adc_proc_del_device(struct adc_core_dev *adc)
|
|
{
|
|
if (adc->id == 0)
|
|
remove_proc_entry("driver/adc", NULL);
|
|
}
|
|
|