免费注册 查看新帖 |

Chinaunix

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

这是我在S3C2410上写的一个驱动程序,各位大哥帮我看看(第一次写),运行出错了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-11 15:21 |只看该作者 |倒序浏览
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/irq.h>
#include <linux/delay.h>

#include <asm/hardware.h>


#define DEVICE_NAME        "touchsensor"
#define BUTTON_MAJOR 234


#define IDX_REG 0x10000000
#define CON_REG 0x10000001

#define CMD_REG  0x00
#define DAT_REG  0x01
#define STA_REG  0x02
#define INT_REG  0x03

#define AUX_REG  0x05
#define CID0_REG 0x06
#define CID1_REG 0x07
#define OPS_REG  0x08
#define BUFC_REG 0x09
#define CLK0_REG 0x10

#define IOC_REG  0x14

#define IEN_REG  0x16

#define F0T0_REG 0x20
#define F0T1_REG 0x21
#define F1T0_REG 0x22
#define F1T1_REG 0x23


static int touch_value = 0;
static DECLARE_WAIT_QUEUE_HEAD(touch_wait);


static int touchsensor_read(struct file * file, char * buffer, size_t count, loff_t *ppos)
{  

   
        
      if ( copy_to_user(buffer, &touch_value, sizeof touch_value))
      {printk("aaa\n");
       return -EFAULT;}
        return sizeof touch_value;
        
}

static int touchsensor_write(struct file * file, const char * buffer, size_t count, loff_t *ppos)
{
     
        
         
       return -EINVAL;;
}         
   
static int touchsensor_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
        switch(cmd) {
        default:
                return -EINVAL;
        }
}

static int touchsensor_open(struct inode *inode, struct file *filp)
{
       
                 printk("open success \n");
                 MOD_INC_USE_COUNT;
        return 0;
}

static int touchsensor_release(struct inode *inode, struct file *file)
{
         MOD_DEC_USE_COUNT;
        return 0;
}

static struct file_operations touchsensor_fops = {
        owner:        THIS_MODULE,
        ioctl:  touchsensor_ioctl,
  read: touchsensor_read,
        write: touchsensor_write,
        open: touchsensor_open,
        release: touchsensor_release,
};

static devfs_handle_t devfs_handle;
static int __init touchsensor_init(void)
{
        int ret;
         int *a,*b,*c;
         
        ret = register_chrdev(BUTTON_MAJOR, DEVICE_NAME, &touchsensor_fops);
        if (ret < 0) {
          printk(DEVICE_NAME " can't register major number\n");
          return ret;
        }
       
        devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT,
                                BUTTON_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR, &touchsensor_fops, NULL);
                               
                        printk("hello \n");
                        c=GPACON;
                          * c=0x0002001;
        a=IDX_REG;
        * a=CMD_REG;
        b=CON_REG;
        * b=0x82;
        * b=0x02;
        * b=0x42;
        * a=CID0_REG;
        touch_value=* b;
        printk("%d\n",touch_value);
       
        return 0;
}

static void __exit touchsensor_exit(void)
{
        devfs_unregister(devfs_handle);
        unregister_chrdev(BUTTON_MAJOR, DEVICE_NAME);
}

module_init(touchsensor_init);
module_exit(touchsensor_exit);
MODULE_LICENSE("GPL");

运行后insmod,在dmesg下显示:
hello
Unable to handle kernel paging request at virtual address 007fffff
pgd = c3dc4000
*pgd = 00000000, *pmd = 00000000
Internal error: Oops: ffffffff
CPU: 0
pc : [<c4840210>]    lr : [<c0023950>]    Not tainted
sp : c3d83edc  ip : c3d83e94  fp : c3d83f04
r10: c3d82000  r9 : 02027948  r8 : ffffffea
r7 : 00000060  r6 : c4840400  r5 : c48403ac  r4 : 00000000
r3 : 00002001  r2 : 007fffff  r1 : 10000000  r0 : c48403ec
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  Segment user
Control: C000317F  Table: 33DC4000  DAC: 00000015
Process insmod (pid: 29, stackpage=c3d83000)
Stack: (0xc3d83ecc to 0xc3d84000)
3ec0:                            c0023950 c4840210 60000013 ffffffff 00000000
3ee0: 00002180 c4840400 00000000 c4840000 00000000 c3d33000 c3d83fa4 c3d83f08
3f00: c0024804 c48401a0 c3d33000 c3d83f1c c3d35000 0000000c c029cb20 00000060
3f20: c015761c c4840060 00000580 00000000 00000000 00000000 0000

论坛徽章:
0
2 [报告]
发表于 2006-08-12 14:36 |只看该作者
  1.                         c=GPACON;
  2.                           * c=0x0002001;
  3.         a=IDX_REG;
  4.         * a=CMD_REG;
  5.         b=CON_REG;
  6.         * b=0x82;
  7.         * b=0x02;
  8.         * b=0x42;
  9.         * a=CID0_REG;
  10.         touch_value=* b;
复制代码


你这里应该是操作触摸板的寄存器吧?
看看附带的驱动怎么操作寄存器的吧,我看到有用__raw_readl,__raw_writel操作32位的

论坛徽章:
0
3 [报告]
发表于 2006-08-14 09:52 |只看该作者
以下是2410的datasheet里的资料,请各位帮小弟看看,指点个方向
I/O PORT CONTROL REGISTER
PORT A CONTROL REGISTERS (GPACON/GPADAT)
Register Address R/W Description Reset Value
GPACON 0x56000000 R/W Configure the pins of port A 0x7FFFFF
GPADAT 0x56000004 R/W The data register for port A Undefined
Reserved 0x56000008 – Reserved Undefined
Reserved 0x5600000C – Reserved Undefined
GPACON Bit Description
GPA22 [22] 0 = Output 1 = nFCE
GPA21 [21] 0 = Output 1 = nRSTOUT
(nRSTOUT = nRESET & nWDTRST & SW_RESET(MISCCR[16]))
GPA20 [20] 0 = Output 1 = nFRE
GPA19 [19] 0 = Output 1 = nFWE
GPA18 [18] 0 = Output 1 = ALE
GPA17 [17] 0 = Output 1 = CLE
GPA16 [16] 0 = Output 1 = nGCS5
GPA15 [15] 0 = Output 1 = nGCS4
GPA14 [14] 0 = Output 1 = nGCS3
GPA13 [13] 0 = Output 1 = nGCS2
GPA12 [12] 0 = Output 1 = nGCS1
GPA11 [11] 0 = Output 1 = ADDR26
GPA10 [10] 0 = Output 1 = ADDR25
GPA9 [9] 0 = Output 1 = ADDR24
GPA8 [8] 0 = Output 1 = ADDR23
GPA7 [7] 0 = Output 1 = ADDR22
GPA6 [6] 0 = Output 1 = ADDR21
GPA5 [5] 0 = Output 1 = ADDR20
GPA4 [4] 0 = Output 1 = ADDR19
GPA3 [3] 0 = Output 1 = ADDR18
GPA2 [2] 0 = Output 1 = ADDR17
GPA1 [1] 0 = Output 1 = ADDR16
GPA0 [0] 0 = Output 1 = ADDR0
GPADAT Bit Description
GPA[22:0] [22:0] When the port is configured as output port, the pin state is the same as the
that of the corresponding bit.
When the port is configured as functional pin, undefined value will be read.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP