/* linux/drivers/dmatek/pad4412_led/led.c
*
* DMATEK
* lyp
* 2016.04.12
*
*/
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/power_supply.h>
#include <linux/delay.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/timer.h>
#include <linux/jiffies.h>
#include <linux/irq.h>
#include <linux/wakelock.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <asm/mach-types.h>
#include <mach/hardware.h>
#include <mach/gpio-dma4412.h>
#include <plat/gpio-cfg.h>
#include <plat/adc.h>
#include <linux/memory.h>
#include <linux/io.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h>
#define LED_ON 1
#define LED_OFF 0
#define LED_MAJOR 230
#define led_name "led"
#define EXYNOS4412_BASEADDR 0x11400000
#define EXYNOS4412_GPK3CON (* (volatile unsigned int *)0x114000A0)//(EXYNOS4412_BASEADDR + 0xA0)
#define EXYNOS4412_GPK3DAT (* (volatile unsigned int *)0x114000A4)//(EXYNOS4412_BASEADDR + 0xA4)
#define GPIO_GPK3_LED18 EXYNOS4_GPK3(3) //led 18
#define GPIO_GPK3_LED19 EXYNOS4_GPK3(4) //led 19
static void led_off(int led_num)
{
//int gpk3dat;
//gpk3dat = __raw_readl(EXYNOS4412_GPK3DAT);
switch(led_num)
{
case 1: //led1
//gpk3dat &=~(1<<3); //D18
gpio_direction_output(GPIO_GPK3_LED18,0);
break;
case 2: //led2
//gpk3dat &=~(1<<4); //D19
gpio_direction_output(GPIO_GPK3_LED19,0);
break;
default:
break;
}
//__raw_writel(gpk3dat,EXYNOS4412_GPK3DAT);
}
static void led_on(int led_num)
{
//int gpk3dat;
//gpk3dat = __raw_readl(EXYNOS4412_GPK3DAT);//S3C_GPBDAT
switch(led_num)
{
case 1: //led1
//gpk3dat |= (1<<3); //D18
gpio_direction_output(GPIO_GPK3_LED18,1);
break;
case 2: //led2
//gpk3dat |= (1<<4); //D19
gpio_direction_output(GPIO_GPK3_LED19,1);
break;
default:
break;
}
//__raw_writel(gpk3dat,EXYNOS4412_GPK3DAT);
}
static ssize_t led_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
{
return count;
}
static ssize_t led_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
{
return 0;
}
static int led_open(struct inode *inode, struct file *file)
{
printk("led_open +++++++1\n" );
gpio_direction_output(GPIO_GPK3_LED18,0);
gpio_direction_output(GPIO_GPK3_LED19,0);
/*unsigned int val;
val = readl(EXYNOS4412_GPK3CON);
val &= ~ (0xff <<0);
val |= (1 << 12)|(1<<16);
writel(val, EXYNOS4412_GPK3CON); //将GPK3和GPK4设置为输出模式
val = readl(EXYNOS4412_GPK3DAT);
val &= ~ ((1 <<3)|(1<<4));
writel(val, EXYNOS4412_GPK3DAT); //将GPK3和GPK4置为低*/
printk("led_open -------1\n" );
return 0;
}
/* release command for led device file */
static int led_close(struct inode *inode, struct file *file)
{
// printk("led_close +++1\n");
return 0;
}
/* ioctl command for led device file */
//static int led_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
static int led_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret = 0;
int num;
printk("cmd=%d\n",cmd);
switch(cmd)
{
case LED_ON:
//printk("&&&&&&&&&& LED ON &&&&&&&&&&&&&&\n");
ret = copy_from_user(&num, (int *)arg, sizeof(int));
if(ret != 0)
{
printk("gpio_ioctl: copy_from_user failed\n");
return(-EFAULT);
}
printk("--------LED ON,num = %d-----------\n",num);
led_on(num);
break;
case LED_OFF:
ret = copy_from_user(&num, (int *)arg, sizeof(int));
if(ret != 0)
{
printk("gpio_ioctl: copy_from_user failed\n");
return(-EFAULT);
}
printk("********LED OFF,num = %d**********\n",num);
led_off(num);
break;
default:
break;
}
return 0;
}
static const struct file_operations led_fops = {
.owner = THIS_MODULE,
.read = led_read,
.write = led_write,
.open = led_open,
.release = led_close,
.unlocked_ioctl = led_ioctl,
};
static int __init led_init(void)
{
int retval;
retval = register_chrdev(LED_MAJOR,led_name,&led_fops);
if(retval < 0)
{
printk(KERN_WARNING "can't register major number %d\n",LED_MAJOR);
return retval;
}
printk("LED driver register success!\n");
return 0;
}
static void __exit led_exit(void)
{
unregister_chrdev(LED_MAJOR,led_name);
printk("LED driver release success!\n");
}
module_init(led_init);
module_exit(led_exit);
MODULE_AUTHOR("lyp");
MODULE_DESCRIPTION("led driver");
MODULE_LICENSE("GPL");
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![ogv](https://img-home.csdnimg.cn/images/20210720083646.png)
![ogv](https://img-home.csdnimg.cn/images/20210720083646.png)
![ogv](https://img-home.csdnimg.cn/images/20210720083646.png)
![ogv](https://img-home.csdnimg.cn/images/20210720083646.png)
![ogv](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![ogv](https://img-home.csdnimg.cn/images/20210720083646.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 3 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/53dd6348f7ef4e6eb35ffe5899a17daf_lyp461340781.jpg!1)
lyp461340781
- 粉丝: 11
- 资源: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)