linux driver template

/*
 * sound/arm/omap/omap-alsa-twl4030.c
 *
 * Codec driver for TWL4030 for OMAP processors
 *
 * Copyright (C) 2007 Texas Instruments, Inc.
 *
 * This package 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.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * History:
 *  -------
 *  2006-01-18 Nishanth Menon - Created
 *  2006-09-15 Jian Zhang - Ported to ALSA
 *  2007-04-16 Leonides Martinez - Added ALSA controls
 */

#define XXX_VER "0.1"

#ifdef MATRIX_DEBUG
#define MATRIXPT(x...) do{ printf(x...)}while(0)
#else
#define MATRIXPT(x...) do{}while(0)
#endif

//you can use modinfo to get informations of this modules
int log_level = 1;
module_param(log_level, int, 0);
MODULE_PARM_DESC(log_level, "log_level: 0 (none), 1 (less), 2 (more), 3 (verbose)");

..........................


    atomic_t open_flag;


static /*const */ struct file_operations xxx_audio_fops =
{
    owner:        THIS_MODULE,
    read:        xxx_read,
    write:        xxx_write,
    poll:        xxx_poll,
    ioctl:        xxx_ioctl,
    open:        xxx_open,
    release:    xxx_release,
};
static int xxx_open(struct inode *inode, struct file *file)
{
    /* wait for device to become free */

    if (!atomic_dec_and_test(&xxx_state.open_flag))
    {
        atomic_inc(&xxx_state.open_flag);
        return -EBUSY; // already open
    } 
}

static int at6600_release(struct inode *inode, struct file *file)
{

    atomic_inc(&xxx_state.open_flag); 

}
static int __init init_xxx(void)
{
    //only one thread can open this device       
    atomic_set(&xxx_state.open_flag,1);

    //dynamic allocate major and minor, you can read form  /proc/devices
    //if a char dev
    unsigned int major;
    major = register_chrdev (0 ,XXX_DEV_NAME, & XXX_fops);

    //if a blk dev;
    major = register_blkdev(0, XXX_NAME);

}

module_init (xxx_init);
module_exit (xxx_exit);

MODULE_AUTHOR("cindy qin");
MODULE_DESCRIPTION("xxx Driver");
MODULE_LICENSE ("GPL");
MODULE_VERSION(XXX_VER);








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值