Chinaunix首页 | 论坛 | 博客
  • 博客访问: 844637
  • 博文数量: 489
  • 博客积分: 475
  • 博客等级: 下士
  • 技术积分: 3087
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 16:28
文章分类

全部博文(489)

文章存档

2013年(7)

2012年(301)

2011年(181)

分类:

2011-12-22 21:09:51

/*************************************

PWM的驱动,在TX2440A上做测试

维护记录: 2009-10-28 V1.0 

linux内核:2.6.31    

*************************************/

 

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

 

#define DEVICE_NAME  "TX2440-Beep"

static int BEEP_MAJOR=0;     /* 主设备号 */

 

static int TX2440_beep_ioctl(

    struct inode *inode,

    struct file *file,

    unsigned int cmd,

    unsigned long arg)

{

    unsigned long temp;

    if(cmd <= 0)

    {

        temp = __raw_readl(S3C2410_GPBCON);    //GPBCON

        temp &= ~3;

        temp |= 1;

        __raw_writel(temp, S3C2410_GPBCON);

 

        temp = __raw_readl(S3C2410_GPBDAT);    //GPBDAT

        temp &= ~1;

        __raw_writel(temp, S3C2410_GPBDAT);

    }

    else

    {

        temp = __raw_readl(S3C2410_GPBCON);    //GPBCON

        temp &= ~3;

        temp |= 2;

        __raw_writel(temp, S3C2410_GPBCON);

 

        temp = __raw_readl(S3C2410_TCFG0); //TCFG0

        temp &= ~0xff;

        temp |= 15;

        __raw_writel(temp, S3C2410_TCFG0);

 

        temp = __raw_readl(S3C2410_TCFG1); //TCFG1

        temp &= ~0xf;

        temp |= 2;

        __raw_writel(temp, S3C2410_TCFG1);

 

        temp = (50000000/128)/cmd;

        __raw_writel(temp, S3C2410_TCNTB(0));

 

        temp >>= 1;

        __raw_writel(temp, S3C2410_TCMPB(0));

 

        temp = __raw_readl(S3C2410_TCON);  //TCON

        temp &= ~0x1f;

        temp |= 0xb;

        __raw_writel(temp, S3C2410_TCON);

 

        temp &= ~2;

        __raw_writel(temp, S3C2410_TCON); 

    }

    return 0;

}

 

static struct file_operations TX2440_beep_fops = {

    .owner =   THIS_MODULE,

    .ioctl =   TX2440_beep_ioctl,

};

 

static struct class *beep_class;

 

static int __init TX2440_beep_init(void)

{

    printk("TX2440 BEEP DRIVER MODULE INIT\n");

 

    BEEP_MAJOR = register_chrdev(0, DEVICE_NAME, &TX2440_beep_fops);

    if (BEEP_MAJOR < 0) {

      printk(DEVICE_NAME " can't register major number\n");

      return BEEP_MAJOR;

    }

    printk("register TX2440-Beep Driver OK! Major = %d\n", BEEP_MAJOR);

 

    beep_class = class_create(THIS_MODULE, DEVICE_NAME);

    if(IS_ERR(beep_class))

    {

        printk("Err: failed in TX2440-Beep class. \n");

        return -1;

    }

 

    device_create(beep_class, NULL, MKDEV(BEEP_MAJOR, 0), NULL, DEVICE_NAME);

 

    printk(DEVICE_NAME " initialized\n");

    return 0;

 

}

 

static void __exit TX2440_beep_exit(void)

{

    unregister_chrdev(BEEP_MAJOR, DEVICE_NAME);

    device_destroy(beep_class, MKDEV(BEEP_MAJOR, 0));

    class_destroy(beep_class);                     

}

 

module_init(TX2440_beep_init);

module_exit(TX2440_beep_exit);

 

 

MODULE_AUTHOR("www.txmcu.com");    

MODULE_DESCRIPTION("TX2440 Beep Driver");

MODULE_LICENSE("GPL");      

 

源代码: TX2440_beep.rar  

测试程序: beep.rar   

阅读(268) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~