mini2440 pmw驱动-linux3.10.59
2014-12-26 10:50
856 查看
mini2440 pmw驱动-linux3.10.59
/* linux/drivers/char/mini2440_pwm.c * Copyright (c) 2013 Feng Guoqing * * mini2440 PWM Driver * * 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/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/poll.h> #include <linux/interrupt.h> #include <linux/gpio.h> #include <asm/irq.h> #include <asm/io.h> #include <asm/uaccess.h> #include <mach/regs-gpio.h> #include <mach/hardware.h> #include <plat/regs-timer.h> #include <mach/regs-irq.h> #include <asm/mach/time.h> #include <linux/clk.h> #include <linux/cdev.h> #include <linux/device.h> #include <linux/miscdevice.h> #define DEVICE_NAME "pwm" #define PWM_IOCTL_SET_FREQ 1 #define PWM_IOCTL_STOP 0 static struct semaphore lock; /* freq: pclk/50/16/65536 ~ pclk/50/16 * if pclk = 50MHz, freq is 1Hz to 62500Hz * human ear : 20Hz~ 20000Hz */ static void PWM_Set_Freq( unsigned long freq ) //??pwm???,??????? { unsigned long tcon; unsigned long tcnt; unsigned long tcfg1; unsigned long tcfg0; struct clk *clk_p; unsigned long pclk; s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0); tcon = __raw_readl(S3C2410_TCON); tcfg1 = __raw_readl(S3C2410_TCFG1); tcfg0 = __raw_readl(S3C2410_TCFG0); tcfg0 &= ~S3C2410_TCFG_PRESCALER0_MASK; tcfg0 |= (50 - 1); tcfg1 &= ~S3C2410_TCFG1_MUX0_MASK; tcfg1 |= S3C2410_TCFG1_MUX0_DIV16; __raw_writel(tcfg1, S3C2410_TCFG1); __raw_writel(tcfg0, S3C2410_TCFG0); clk_p = clk_get(NULL, "pclk"); pclk = clk_get_rate(clk_p); tcnt = (pclk/50/16)/freq; __raw_writel(tcnt, S3C2410_TCNTB(0)); __raw_writel(tcnt/2, S3C2410_TCMPB(0)); tcon &= ~0x1f; tcon |= 0xb; //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0 __raw_writel(tcon, S3C2410_TCON); tcon &= ~2; //clear manual update bit __raw_writel(tcon, S3C2410_TCON); } static void PWM_Stop(void) { s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPIO_OUTPUT); gpio_set_value(S3C2410_GPB(0), 0); } static int s3c24xx_pwm_open(struct inode *inode, struct file *file) { if (!down_trylock(&lock)){ return 0; } else { return -EBUSY; } } static int s3c24xx_pwm_close(struct inode *inode, struct file *file) { PWM_Stop(); up(&lock); return 0; } static long s3c24xx_pwm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { switch (cmd) { case PWM_IOCTL_SET_FREQ: //if cmd=1 ???case PWM_IOCTL_SET_FREQ if (arg == 0) return -EINVAL; PWM_Set_Freq(arg); break; case PWM_IOCTL_STOP: // if cmd=2 case PWM_IOCTL_STOP PWM_Stop(); break; } return 0; } static struct file_operations dev_fops = { .owner = THIS_MODULE, .open = s3c24xx_pwm_open, .release = s3c24xx_pwm_close, .unlocked_ioctl = s3c24xx_pwm_ioctl, }; static struct miscdevice misc = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME, .fops = &dev_fops, }; static int __init dev_init(void) { int ret; sema_init(&lock, 1); ret = misc_register(&misc); printk (DEVICE_NAME"\tinitialized\n"); return ret; } static void __exit dev_exit(void) { misc_deregister(&misc); } module_init(dev_init); module_exit(dev_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("FriendlyARM Inc."); MODULE_DESCRIPTION("S3C2410/S3C2440 PWM Driver");
相关文章推荐
- mini2440 touchscreen驱动--linux-3.10.59
- mini2440 buttons的驱动-linux3.10.59
- mini2440 adc驱动--linux-3.10.59
- mini2440Led驱动——linux-3.10.59
- mini2440 backlight驱动--linux-3.10.59
- Linux-2.6.32.2内核在mini2440上的移植(四)---激活RTC驱动
- 触摸屏驱动移植(mini2440,linux-2.6.32.7)
- linuxmini2440I2S驱动
- linux sd卡驱动分析,基于mini2440,sdio mmc sd卡驱动编写
- Linux-2.6.32.2内核在mini2440上的移植(十四)---移植看门狗驱动
- nandflash驱动移植-《Mini2440_Linux移植开发实战指南》
- Linux-2.6.32.2内核在mini2440上的移植(五)---添加LCD背光驱动
- Linux-2.6.32.2内核在mini2440上的移植(九)---触摸屏驱动移植
- Linux-2.6.32.2内核在mini2440上的移植(十二)---移植I2C EEPROM驱动
- Linux-2.6.32.2内核在mini2440上的移植(六)---LCD驱动移植
- Linux-2.6.32.2内核在mini2440上的移植(十六)---基于中断的按键驱动移植
- mini2440触摸屏驱动在linux-2.6.32.2的移植
- Linux触摸屏驱动学习,mini2440
- 基于mini2440上的Linux驱动动态加载问题
- Linux驱动学习——网络接口DM9000驱动学习 mini2440