打印
[嵌入式linux]

嵌入式LINUX驱动问题(file_operations)

[复制链接]
1715|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wuyunzdh|  楼主 | 2008-10-23 12:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

请问一下,我的开发板完整的AD驱动程序为什么没有file_operations结构。
能不能帮忙解释一下,
驱动一般都有file_operations结构来定义接口函数的呀!
如:
struct file_operations scull_fops = { .owner =  THIS_MODULE,

.llseek =  scull_llseek,

.read =  scull_read,

.write =  scull_write,

.ioctl =  scull_ioctl,

.open =  scull_open,

.release =  scull_release,};



我把源码贴给大家看看:

/*
* s3c2410-adc.c
*
* S3C2410 ADC 
*  exclusive with s3c2410-ts.c
*
* Author: SeonKon Choi <bushi@mizi.com>
* Date  : $Date: 2003/01/20 14:24:49 $ 
*
* $Revision: 1.1.2.6 $
*

   Fri Dec 03 2002 SeonKon Choi <bushi@mizi.com>
   - initial

*
* This file is subject to the terms and conditions of the GNU General Public
* License.  See the file COPYING in the main directory of this archive
* for more details.
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#include <linux/sched.h>
#include <linux/irq.h>
#include <linux/delay.h>

#include <asm/hardware.h>
#include <asm/semaphore.h>

#undef DEBUG

#ifdef DEBUG
#define DPRINTK(x...) {printk(__FUNCTION__"(%d): ",__LINE__);printk(##x);}
#else
#define DPRINTK(x...) (void)(0)
#endif

#define START_ADC_AIN(x) 

  ADCCON = PRESCALE_EN | PRSCVL(255) | ADC_INPUT((x)) ; 
  ADCCON |= ADC_START; 
}

static struct semaphore adc_lock;
static wait_queue_head_t *adc_wait;

static void adcdone_int_handler(int irq, void *dev_id, struct pt_regs *reg)
{
wake_up(adc_wait);
}

int s3c2410_adc_read(int ain, wait_queue_head_t *wait)
{
int ret = 0;

if (down_interruptible(&adc_lock))
  return -ERESTARTSYS;

adc_wait = wait;

START_ADC_AIN(ain);
sleep_on_timeout(adc_wait, HZ/100); /* 10ms */

#if 0
if (signal_pending(current)) {
  up(&adc_lock);
  return -ERESTARTSYS;
}
#endif

ret = ADCDAT0 ;

up(&adc_lock);

adc_wait = NULL;

DPRINTK("AIN[%d] = 0x%04x, %d ", ain, ret, ADCCON & 0x80 ? 1:0);

return (ret & 0x3ff);
}

int __init s3c2410_adc_init(void)
{
init_MUTEX(&adc_lock);

/* normal ADC */
ADCTSC = 0; //XP_PST(NOP_MODE);

if (request_irq(IRQ_ADC_DONE, adcdone_int_handler, SA_INTERRUPT,
   "ADC", NULL) < 0)
  goto irq_err;

return 0;

irq_err:

return 1;
}

module_init(s3c2410_adc_init);

#ifdef MODULE
void __exit s3c2410_adc_exit(void)
{
free_irq(IRQ_ADC_DONE, NULL);
}

module_exit(s3c2410_adc_exit);
MODULE_LICENSE("GPL");
#endif


相关帖子

沙发
wuyunzdh|  楼主 | 2008-10-27 10:43 | 只看该作者

用为什么没有提供接口函数呀?

用户程序怎么通过调用read函数来找到驱动程序中的s3c2410_adc_read函数
为什么没有提供接口函数呀?

使用特权

评论回复
板凳
realrots| | 2008-10-29 11:10 | 只看该作者

应该有定义,你没有找到吧

使用特权

评论回复
地板
圆圈| | 2008-11-5 11:26 | 只看该作者

一般都是有的

一般都是有的,除非,你用的文件系统(VFS)比较特殊。
linux驱动建立在VFS文件系统基础之上~~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

24

主题

71

帖子

0

粉丝