天嵌 ARM开发社区

 找回密码
 注册
查看: 4603|回复: 5

input输入子系统遇到加载出错,请教大家

[复制链接]
fengc234 发表于 2012-12-11 10:58:55 | 显示全部楼层 |阅读模式
驱动如下:
/*************************************

NAME:EmbedSky_hello.c
COPYRIGHT:www.embedsky.net

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

#include <linux/device.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
//#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/string.h>
//#include <asm/unistd.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/interrupt.h>
#include <linux/irqreturn.h>
#include <linux/input.h>

//#define DEVICE_NAME "EmbedSky_buttons4"

struct buttons_irq_desc
{
        int irq;
        int pin;
        int pin_setting;
        int key_val;
        char *name;
};

static struct buttons_irq_desc *irq_pd;
static struct input_dev *buttons_dev;
static struct timer_list  buttons_timer;

static struct buttons_irq_desc buttons_irqs[4] =
{
        {IRQ_EINT0, S3C2410_GPF0, S3C2410_GPF0_EINT0, KEY_L,              "KEY0"},
        {IRQ_EINT1, S3C2410_GPF1, S3C2410_GPF1_EINT1, KEY_S,              "KEY1"},
        {IRQ_EINT2, S3C2410_GPF2, S3C2410_GPF2_EINT2, KEY_ENTER,     "KEY2"},
        {IRQ_EINT4, S3C2410_GPF4, S3C2410_GPF4_EINT4, KEY_LEFTSHIFT, "KEY3"},
};

static irqreturn_t buttons_interrupt(int irq, void *dev_id)
{
        irq_pd = (struct buttons_irq_desc *)dev_id;
        mod_timer(&buttons_timer, jiffies+HZ/100);
        return IRQ_RETVAL(IRQ_HANDLED);
}

static void buttons_timer_function(unsigned long data)
{
        struct buttons_irq_desc *buttons_ack = irq_pd;
        int key_up;
        if(buttons_ack)
                return;
        key_up = s3c2410_gpio_getpin(buttons_ack->pin);
        if(key_up)
        {
                input_event(buttons_dev, EV_KEY, buttons_ack->key_val, 0);
                input_sync(buttons_dev);
        }
        else
        {
                input_event(buttons_dev, EV_KEY, buttons_ack->key_val, 1);
                input_sync(buttons_dev);
        }
}

//static int __init buttons_init(void)
static int buttons_init(void)
{
        int err, i;       
        buttons_dev = input_allocate_device();
        if(!buttons_dev)
        {
                printk(KERN_ERR "Unable to allocate the input device!/n");       
                return -ENOMEM;
        }
        set_bit(EV_KEY, buttons_dev->evbit);
        set_bit(EV_REP, buttons_dev->evbit);
       
        set_bit(KEY_L, buttons_dev->keybit);
        set_bit(KEY_S, buttons_dev->keybit);
        set_bit(KEY_ENTER, buttons_dev->keybit);
        set_bit(KEY_LEFTSHIFT, buttons_dev->keybit);

        err = input_register_device(buttons_dev);                       
        if (err)
        {
                printk(KERN_ERR "Failed to register device!/n");
                input_free_device(buttons_dev);
                return err;
        }
        init_timer(&buttons_timer);
        buttons_timer.function = buttons_timer_function;
        add_timer(&buttons_timer);

        for(i=0; i<4; i++)
        {
                s3c2410_gpio_cfgpin(buttons_irqs.pin, buttons_irqs.pin_setting);       
                err = request_irq(buttons_irqs.irq, buttons_interrupt, IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, buttons_irqs.name, (void *)&buttons_irqs);
                if(err)
                        break;
        }
        if(err)
        {
                i--;
                for(; i>0; i--)
                {
                        disable_irq(buttons_irqs.irq);
                        free_irq(buttons_irqs.irq, (void *)&buttons_irqs);
                }
                return -EBUSY;
        }
        printk(KERN_ERR "register device has success!/n");
        return 0;
}

//static void __exit buttons_exit(void)
static void buttons_exit(void)
{
        int i;
        for(i=0; i<4; i++)
        {
                disable_irq(buttons_irqs.irq);
                free_irq(buttons_irqs.irq, (void *)&buttons_irqs);
        }
        del_timer(&buttons_timer);
        input_unregister_device(buttons_dev);
        input_free_device(buttons_dev);
}

module_init(buttons_init);
module_exit(buttons_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("www.embedsky.net");
MODULE_DESCRIPTION("GPIO control for EmbedSky SKY2440/TQ2440 Board");


出错现象如下:
[root@EmbedSky /lib]# insmod EmbedSky_buttons4.ko
input: Unspecified device as /devices/virtual/input/input1
register device has success!/n<1>Unable to handle kernel NULL pointer dereference at virtual address 00000004
pgd = c3a54000
[00000004] *pgd=33a45031, *pte=00000000, *ppte=00000000
Internal error: Oops: 17 [#1]
Modules linked in: EmbedSky_buttons4 [last unloaded: EmbedSky_buttons4]
CPU: 0    Not tainted  (2.6.30.4-EmbedSky #10)
PC is at buttons_timer_function+0x1c/0x88 [EmbedSky_buttons4]
LR is at run_timer_softirq+0x1ac/0x22c
pc : [<bf0032a8>]    lr : [<c009ce40>]    psr: 60000013
sp : c3a5bee0  ip : c3a5bf00  fp : c3a5befc
r10: c0441148  r9 : c03fc070  r8 : c3a5a000
r7 : bf00328c  r6 : c3a5bf10  r5 : bf003ae8  r4 : 00000000
r3 : 80000013  r2 : c3a5bf10  r1 : bf003ae8  r0 : 00000000
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: c000717f  Table: 33a54000  DAC: 00000015
Process sh (pid: 448, stack limit = 0xc3a5a268)
Stack: (0xc3a5bee0 to 0xc3a5c000)
bee0: c0440940 00000100 c3a5bf10 bf00328c c3a5bf44 c3a5bf00 c009ce40 bf00329c
bf00: c3a5bf24 c0441748 c0441548 c0441348 c3a5bf10 c3a5bf10 c3a5bf3c 00000004
bf20: 00000081 00000100 c3a5a000 c04407a0 c04407a0 0000000a c3a5bf7c c3a5bf48
bf40: c0098120 c009cca4 c03fd6bc c03fa6d8 0000001e 0000001e c0409230 00000000
bf60: 00000001 001e4000 c3a5a000 00000000 c3a5bf8c c3a5bf80 c00981f0 c00980b8
bf80: c3a5bfac c3a5bf90 c0080048 c00981b8 ffffffff f4000000 00004000 00000001
bfa0: 00000000 c3a5bfb0 c0080c40 c0080010 001debc0 00000000 fbad248c 00000000
bfc0: 00000000 001e74c8 001e01f4 00000001 001e4000 001e44a0 00000000 be95bed4
bfe0: 001e74c8 be95b420 000febdc 000feb4c 60000010 ffffffff 304d5031 304d5431
Backtrace:
[<bf00328c>] (buttons_timer_function+0x0/0x88 [EmbedSky_buttons4]) from [<c009ce40>] (run_timer_softirq+0x1ac/0x22c)
r7:bf00328c r6:c3a5bf10 r5:00000100 r4:c0440940
[<c009cc94>] (run_timer_softirq+0x0/0x22c) from [<c0098120>] (__do_softirq+0x78/0x100)
[<c00980a8>] (__do_softirq+0x0/0x100) from [<c00981f0>] (irq_exit+0x48/0x50)
[<c00981a8>] (irq_exit+0x0/0x50) from [<c0080048>] (_text+0x48/0x70)
[<c0080000>] (_text+0x0/0x70) from [<c0080c40>] (__irq_usr+0x40/0xc0)
Exception stack(0xc3a5bfb0 to 0xc3a5bff8)
bfa0:                                     001debc0 00000000 fbad248c 00000000
bfc0: 00000000 001e74c8 001e01f4 00000001 001e4000 001e44a0 00000000 be95bed4
bfe0: 001e74c8 be95b420 000febdc 000feb4c 60000010 ffffffff                  
r7:00000001 r6:00004000 r5:f4000000 r4:ffffffff
Code: e59f5070 e595401c e3540000 189da8f0 (e5940004)
Kernel panic - not syncing: Fatal exception in interrupt
Backtrace:
[<c0084fd4>] (dump_backtrace+0x0/0x10c) from [<c0313ef0>] (dump_stack+0x18/0x1c)
r7:bf0032ac r6:c041fe80 r5:bf0032a8 r4:bf0032a8
[<c0313ed8>] (dump_stack+0x0/0x1c) from [<c0313f40>] (panic+0x4c/0x124)
[<c0313ef4>] (panic+0x0/0x124) from [<c00852c0>] (die+0x1e0/0x214)
r3:00000100 r2:00000080 r1:c041fe80 r0:c039f694
[<c00850e0>] (die+0x0/0x214) from [<c0087528>] (__do_kernel_fault+0x6c/0x7c)
[<c00874bc>] (__do_kernel_fault+0x0/0x7c) from [<c0087684>] (do_page_fault+0x14c/0x25c)
r7:c383b200 r6:00000004 r5:c3a5becc r4:c3894300
[<c0087538>] (do_page_fault+0x0/0x25c) from [<c00801e0>] (do_DataAbort+0x38/0x9c)
[<c00801a8>] (do_DataAbort+0x0/0x9c) from [<c0080a00>] (__dabt_svc+0x40/0x60)
Exception stack(0xc3a5be98 to 0xc3a5bee0)
be80:                                                       00000000 bf003ae8
bea0: c3a5bf10 80000013 00000000 bf003ae8 c3a5bf10 bf00328c c3a5a000 c03fc070
bec0: c0441148 c3a5befc c3a5bf00 c3a5bee0 c009ce40 bf0032a8 60000013 ffffffff
[<bf00328c>] (buttons_timer_function+0x0/0x88 [EmbedSky_buttons4]) from [<c009ce40>] (run_timer_softirq+0x1ac/0x22c)
r7:bf00328c r6:c3a5bf10 r5:00000100 r4:c0440940
[<c009cc94>] (run_timer_softirq+0x0/0x22c) from [<c0098120>] (__do_softirq+0x78/0x100)
[<c00980a8>] (__do_softirq+0x0/0x100) from [<c00981f0>] (irq_exit+0x48/0x50)
[<c00981a8>] (irq_exit+0x0/0x50) from [<c0080048>] (_text+0x48/0x70)
[<c0080000>] (_text+0x0/0x70) from [<c0080c40>] (__irq_usr+0x40/0xc0)
Exception stack(0xc3a5bfb0 to 0xc3a5bff8)
bfa0:                                     001debc0 00000000 fbad248c 00000000
bfc0: 00000000 001e74c8 001e01f4 00000001 001e4000 001e44a0 00000000 be95bed4
bfe0: 001e74c8 be95b420 000febdc 000feb4c 60000010 ffffffff                  
r7:00000001 r6:00004000 r5:f4000000 r4:ffffffff
TQ-ZQL 发表于 2012-12-11 11:12:45 | 显示全部楼层
本帖最后由 TQ-ZQL 于 2012-12-11 11:16 编辑

你的问题好像是定时器的,先去掉定时器看下,或者在add之前加个timer.expires = jiffies + TIMER_DELAY;
 楼主| fengc234 发表于 2012-12-11 11:13:54 | 显示全部楼层
好的,我去看看
 楼主| fengc234 发表于 2012-12-11 11:23:31 | 显示全部楼层
我把定时器部分注释之后,不再出现这么多错误代码了,但是还有两个疑问:
1、加载驱动时,仍会出现“input: Unspecified device as /devices/virtual/input/input0”
2、定时器在输入子系统中为啥会出现冲突呢
TQ-ZQL 发表于 2012-12-11 14:44:56 | 显示全部楼层
本帖最后由 TQ-ZQL 于 2012-12-11 17:39 编辑

你input的名子没有写。定时器那里看下是不是启动的时候没有写timer.expires。
cestlavie007 发表于 2013-1-30 00:00:09 | 显示全部楼层
timer处理函数里,是不是应该是
  if(!buttons_ack)
                 return;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-28 07:28 , Processed in 1.032266 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表