免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1998 | 回复: 1
打印 上一主题 下一主题

一个简单的触摸驱动,为什么没有输出任何信息? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-30 17:36 |只看该作者 |倒序浏览

编译完生成ts.ko后
用insmod ts.ko时,出现input: Unspecified device as /devices/virtual/input/input0警告,但是ts.ko还是添加成功。
如果没有出现预期的结果:
按下:输出  pen down
松开:输出  pen up

我用的板子是s3c6410,求高手指教!在线等候。。。
#include <linux/module.h>

#include <linux/init.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/sched.h>
#include <linux/pm.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/io.h>
#include <linux/clk.h>

static struct input_dev *ts_dev;

struct adc_regs {
        unsigned long adccon;
        unsigned long adctsc;
        unsigned long adcdly;
        unsigned long adcdat0;
        unsigned long adcdat1;
        unsigned long adcupdn;
        unsigned long adcclrint;
        unsigned long reserved;
        unsigned long adcclrintpndnup;
};

static struct adc_regs *adc_regs;

static void enter_wait_for_pen_down(void)
{
        adc_regs->adctsc = 0xd3;
}

static void enter_wait_for_pen_up(void)
{
        adc_regs->adctsc = 0x1d3;
}


static irqreturn_t ts_pen_down_up_isr(int irq, void *dev_id)
{
        if (adc_regs->adcdat0 & (1<<15))
        {
                printk("pen up\n");
                enter_wait_for_pen_down();
        }
        else
        {
                printk("pen down\n");
                enter_wait_for_pen_up();
        }

        adc_regs->adcclrintpndnup = 0;

        return IRQ_HANDLED;
}

static int ts_init(void)
{
        struct clk *clk;
       
        /* 1. 分配input_dev */
        ts_dev = input_allocate_device();
       
        /* 2. 设置 */
        /* 2.1 能产生哪类事件 */
        set_bit(EV_KEY, ts_dev->evbit);
        set_bit(EV_ABS, ts_dev->evbit);
       
        /* 2.2 能产生这类事件里的哪些事件 */
        set_bit(BTN_TOUCH, ts_dev->keybit);
        input_set_abs_params(ts_dev, ABS_X, 0, 0xfff, 0, 0);
        input_set_abs_params(ts_dev, ABS_Y, 0, 0xfff, 0, 0);
        input_set_abs_params(ts_dev, ABS_PRESSURE, 0, 1, 0, 0);
       
        /* 3. 注册 */
        input_register_device(ts_dev);
       
        /* 4. 硬件相关 */
        adc_regs = ioremap(0x7E00B000, sizeof(struct adc_regs));

        clk = clk_get(NULL, "adc");
        clk_enable(clk);  /* PCLK_GATE[12]设为1 */

        /* bit[16]   : 1 = 12-bit A/D conversion
         * bit[14]   : 1 - enable A/D converter prescaler enable
         * bit[13:6] : A/D converter prescaler value,
         *             PCLK=66500000, adcclk=pclk/(n+1)
         *             取值13, adclk=66.5MHz/14=4.75
         *
         */
        adc_regs->adccon = (1<<16) | (1<<14) | (13<<6);

        adc_regs->adcclrintpndnup = 0;
        request_irq(IRQ_TC, ts_pen_down_up_isr, IRQF_SHARED, "pen_down_up", 1);

        /* 进入"wait for interrupt mode", 等待触摸笔按下或松开的模式 */
        enter_wait_for_pen_down();
        return 0;
}

static void ts_exit(void)
{
        free_irq(IRQ_TC, 1);
        iounmap(adc_regs);
        input_unregister_device(ts_dev);
        input_free_device(ts_dev);
}

module_init(ts_init);
module_exit(ts_exit);
MODULE_LICENSE("GPL");

论坛徽章:
0
2 [报告]
发表于 2012-09-30 22:31 |只看该作者
编译内核的时候,除了配置make menuconfig
[ ]   Touchscreens  --->   除掉之外,应该在其他地方不用配置什么的了吧!
我在cat /pro/interrupts 时结果如下

/ # cat /proc/interrupts
           CPU0
16:        106    s3c-uart  s3c6400-uart
18:        175    s3c-uart  s3c6400-uart
35:          0         VIC  s3c-fimc0
36:          0         VIC  s3c-fimc1
40:          0         VIC  s3c-g3d
41:          0         VIC  s3c-vpp
42:          0         VIC  s3c-rotator
43:          0         VIC  s3c-g2d
44:          0         VIC  TV_ENCODER
45:          0         VIC  TV_SCALER
47:          0         VIC  s3c-jpeg
48:          0         VIC  s3c-mfc
62:      42841         VIC  s3c-lcd
68:          6         VIC  AC97
73:          9         VIC  s3cspi-dma, s3cspi-dma
79:         36         VIC  ohci_hcd:usb1
80:          0         VIC  s3c-spi
82:          4         VIC  s3c2440-i2c
88:         22         VIC  mmc0
89:         41         VIC  mmc1
90:          1         VIC  s3c-udc
98:          8   s3c-timer  pwm_timer2
100:       5021   s3c-timer  pwm_timer4
108:       3600    s3c-eint  eth0
113:          1    s3c-eint  mmc0
151:          0  s3c-eint-group  mcp2515

不知道,加入自己的驱动之后,是不是还有某个地方被我忽略了,求各位指点!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP