主题 : S5PV210 访问0xE2500000寄存器报错 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 89466
精华: 0
发帖: 26
金钱: 130 两
威望: 26 点
综合积分: 52 分
注册时间: 2013-03-28
最后登录: 2014-07-30
楼主  发表于: 2014-07-07 09:49

 S5PV210 访问0xE2500000寄存器报错

我想配置PWM,代码如下:
#include <linux/delay.h>
#include <linux/poll.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>

#include <mach/regs-irq.h>
#include <asm/mach/time.h>

#include <linux/cdev.h>
#include <linux/device.h>

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/clk.h>
#include <linux/device.h>
#include <asm/io.h>
#include <mach/hardware.h>
#include <mach/regs-gpio.h>
#include <plat/regs-timer.h>


#include <linux/platform_device.h>
#include <linux/fb.h>
#include <linux/backlight.h>
#include <linux/err.h>
#include <linux/pwm.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>

#include <mach/gpio.h>
#include <plat/gpio-cfg.h>

#define DEVICE_NAME     "aibo_pwm"

#define PWM_IOCTL_SET_FREQ        1
#define PWM_IOCTL_STOP            2

static struct semaphore lock;

#define REMAP_SIZE 0x14

#define PWMTIMER_BASE 0xE2500000

#define TCFG0  (*(volatile unsigned long *)(PWMTIMER_BASE + 0x00))
#define TCFG1  (*(volatile unsigned long *)(PWMTIMER_BASE + 0x04))
#define TCON  (*(volatile unsigned long *)(PWMTIMER_BASE + 0x08)) // 控制寄存器
#define TCNTB0  (*(volatile unsigned long *)(PWMTIMER_BASE + 0x0c)) // 计数缓冲寄存器
#define TCMPB0  (*(volatile unsigned long *)(PWMTIMER_BASE + 0x10)) // 比较计数寄存器


/*---------------------------------------------------------------------------------------
    Timer 0 Freq=20KHz  Duty=0~100%
  * human ear : 20Hz~ 20KHz
------------------------------------------------------------------------------------------ */
static void PWM_Set(unsigned int duty)
{
    unsigned long tcon;
    unsigned long tcnt;
    unsigned long tcfg1;
    unsigned long tcfg0;
    unsigned long tmp;        //debug

    struct clk *clk_p;
    unsigned long pclk;

    //get cpu clock
    clk_p = clk_get(NULL, "pclk");    
    pclk  = clk_get_rate(clk_p);
    
    /*---------------------------------------------------------
        printk()    //Debug only
    ----------------------------------------------------------*/

    /*---------------------------------------------------------
            Timer0 pwm output
    --------------------------------------------------------*/

    tcon  = readl(TCON);
    printk("Tcon=%x\n",tcon);        //Only Timer4 is running
    tcfg1 = readl(TCFG1);
    printk("Tcfg1=%x\n",tcfg1);        //All mux=1/2
    tcfg0 = readl(TCFG0);
    printk("Tcfg0=%x\n",tcfg0);        //prescaler0=None,prescaler1=2

    /*tcon  = __raw_readl(S3C2410_TCON);
    printk("Tcon=%x\n",tcon);        //Only Timer4 is running
    tcfg1 = __raw_readl(S3C2410_TCFG1);
    printk("Tcfg1=%x\n",tcfg1);        //All mux=1/2
    tcfg0 = __raw_readl(S3C2410_TCFG0);
    printk("Tcfg0=%x\n",tcfg0);        //prescaler0=None,prescaler1=2*/

    //set GPB0 as tout0, pwm output mode
    //s3c_gpio_cfgpin(S5PV210_GPB(0), S3C_GPIO_SFN(2));
    s3c_gpio_cfgpin(S5PV210_GPB(0), 0x02);
    //prescaler0= 50
    tcfg0 &= ~S3C2410_TCFG_PRESCALER0_MASK;
    tcfg0 |= (50 - 1);
    //mux0 = 1/2    
    tcfg1 &= ~S3C2410_TCFG1_MUX0_MASK;
    tcfg1 |= S3C2410_TCFG1_MUX0_DIV2;

    writel(tcfg0, TCFG0);
    writel(tcfg1, TCFG1);
    
    //__raw_writel(tcfg0, S3C2410_TCFG0);
    //__raw_writel(tcfg1, S3C2410_TCFG1);

    tcnt  = (pclk/50)/1000;    //Freq=20KHz

    writel(tcnt, TCNTB0);            //write to Timer0 TCNTB
    //__raw_writel(tcnt, S3C2410_TCNTB(0));            //write to Timer0 TCNTB

    tmp= readl(TCNTB0);
    //tmp= __raw_readl(S3C2410_TCNTB(0));
    printk("S3C2410_TCNTB(0)=%x\n",tmp);

    writel(duty*tcnt/100,TCMPB0);    //write to Timer0 TCMPB
    //__raw_writel(duty*tcnt/100, S3C2410_TCMPB(0));    //write to Timer0 TCMPB

    tmp= readl(TCMPB0);
    //tmp= __raw_readl(S3C2410_TCMPB(0));
    printk("S3C2410_TCMPB(0)=%x\n",tmp);

    tcon &= ~0x1f;
    tcon |= 0xb;        //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
    writel(tcon, TCON);
    //__raw_writel(tcon, S3C2410_TCON);
    tcon &= ~2;            //clear manual update bit
    writel(tcon, TCON);
    //__raw_writel(tcon, S3C2410_TCON);
    printk("Tcon=%x\n",tcon);
    return 0;
}

void PWM_Stop( void )
{
    //TOUT0 OUTPUT
    s3c_gpio_cfgpin(S5PV210_GPB(0), S3C_GPIO_OUTPUT);
    gpio_set_value(S5PV210_GPB(0), 1);
}

static int s3c24xx_pwm_ioctl(struct file *file, unsigned int cmd, unsigned int duty_tmp)
{
    switch (cmd) {
        case PWM_IOCTL_SET_FREQ:
            PWM_Set(duty_tmp);
            break;

        case PWM_IOCTL_STOP:
            PWM_Stop();
            break;
    }
    /*gpio_set_value(S5PV210_GPB(0), !cmd);
    printk(DEVICE_NAME": %d %d\n", duty_tmp, cmd);*/

    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;

    ret = gpio_request(S5PV210_GPB(0), DEVICE_NAME);
    if (ret) {
        printk("request GPIO %d for pwm failed\n", S5PV210_GPB(0));
        return ret;
    }

    s3c_gpio_cfgpin(S5PV210_GPB(0), S3C_GPIO_OUTPUT);
    gpio_set_value(S5PV210_GPB(0), 0);

    //init_MUTEX(&lock);
    //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");


报错:
[   11.333523] Unable to handle kernel paging request at virtual address e250008
[   11.333592] pgd = dbfa4000
[   11.333617] [e2500008] *pgd=3bc5b811, *pte=00000000, *ppte=00000000
[   11.333677] Internal error: Oops: 7 [#1] PREEMPT
[   11.333718] Modules linked in: aibo_pwm aibo_gpio libertas_sdio libertas zd10
[   11.357023] CPU: 0    Not tainted  (3.0.8-FriendlyARM #3)
[   11.362401] PC is at s3c24xx_pwm_ioctl+0x3c/0x170 [aibo_pwm]
[   11.368028] LR is at s3c24xx_pwm_ioctl+0x38/0x170 [aibo_pwm]
[   11.373662] pc : [<bf1e905c>]    lr : [<bf1e9058>]    psr: 20000013
[   11.373666] sp : dbf93ef8  ip : 00000000  fp : 00000000
[   11.385098] r10: dc2086c0  r9 : dbf92000  r8 : c017f7e8
[   11.390298] r7 : 0000000f  r6 : 000003e8  r5 : 000003e8  r4 : e2500000
[   11.396797] r3 : 00000000  r2 : c08dba38  r1 : c0801ce8  r0 : 03f9c2e0
[   11.403298] Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
[   11.410403] Control: 10c5387d  Table: 3bfa4019  DAC: 00000015
[   11.416121]
[   11.416124] SP: 0xdbf93e78:
[   11.420366] 3e78  dbcd6c00 dbf93ef8 dbf93f78 00000000 dbf93ebc dbf92000 dbf90
[   11.428512] 3e98  ffffffff dbf93ee4 000003e8 0000000f c017f7e8 c017f12c 03f98
[   11.436658] 3eb8  c08dba38 00000000 e2500000 000003e8 000003e8 0000000f c0170
[   11.444804] 3ed8  dc2086c0 00000000 00000000 dbf93ef8 bf1e9058 bf1e905c 2000f
[   11.452949] 3ef8  bf1e9020 dbf59c00 000003e8 000003e8 0000000f c017f7e8 dc20c
[   11.461095] 3f18  00000101 00000004 00000000 00000000 00000000 00000020 00000
[   11.469241] 3f38  0000000f dbf576e4 dbf59c00 00000020 dbf92000 dc2086c0 00008
[   11.477387] 3f58  c08cc340 dbfb0000 dbf59c00 0000000f dbf59c00 000003e8 0000f
[   11.485534]
[   11.485536] R1: 0xc0801c68:
[   11.489779] 1c68  6b6c6373 636d6d5f 00000000 6b6c6373 63666d5f 00000000 6b6cf
[   11.497925] 1c88  00000000 6b6c6373 6433675f 00000000 6b6c6373 6973635f 00003
[   11.506071] 1ca8  6970735f 00000000 6b6c6373 6977705f 00000000 6b6c6373 6d770
[   11.514217] 1cc8  6b6c6368 656d695f 0000006d 6d6f7273 00000063 5f6b6c63 00741
[   11.522362] 1ce8  6b6c6370 00000000 00746f72 6765706a 00000000 2d633269 696d0
[   11.530508] 1d08  696d6468 00000000 6e657674 00000063 00007076 6d697364 0000f
[   11.538654] 1d28  68627375 0074736f 6f636663 0000006e 73636573 00000073 6b635
[   11.546800] 1d48  74737973 72656d69 00000000 656d6974 00007372 5f733269 00300
[   11.554946]
[   11.554949] R2: 0xc08db9b8:
[   11.559192] b9b8  c0802e74 ffffffff 00000000 00000000 00000000 00000000 0000c
[   11.567338] b9d8  c08db9a8 c08dba08 00000000 c08db978 c0802e7c ffffffff 00000
[   11.575484] b9f8  00000000 00000000 00000000 c018ee4c c08db9d8 c08dba38 00000
[   11.583630] ba18  c0802e84 ffffffff 00000000 07f385c0 00000000 c08dba68 0000c
[   11.591775] ba38  c08dba08 c08d9940 00000000 00000000 c0801ce8 ffffffff 00000
[   11.599921] ba58  00000000 c08dba68 00000000 c018ee4c c018ee5c 00000000 00000
[   11.608067] ba78  00000000 00000000 00000000 00000000 c07fff4c ffffffff 00000
[   11.616213] ba98  00000000 00000000 00000000 00000000 00000000 00000000 00000
[   11.624360]
[   11.624362] R4: 0xe24fff80:
[   11.628605] ff80  00000000 00000000 00000000 00000000 00000000 00000000 00000
[   11.636751] ffa0  00000000 00000000 00000000 00000000 00000000 00000000 00000
[   11.644897] ffc0  00000000 00000000 00000000 00000000 00000000 00000000 00000
[   11.653043] ffe0  00000000 00000000 00000000 00000000 00000000 00000000 00000
[   11.661189] 0000  ******** ******** ******** ******** ******** ******** *****
[   11.669335] 0020  ******** ******** ******** ******** ******** ******** *****
[   11.677480] 0040  ******** ******** ******** ******** ******** ******** *****
[   11.685626] 0060  ******** ******** ******** ******** ******** ******** *****
[   11.693773]
[   11.693775] R8: 0xc017f768:
[   11.698018] f768  e24fee13 3798f107 e28d1008 e3a08000 e357080f e2270000 2a00e
[   11.706164] f788  e1a02007 e28d1008 e3a00000 eb00082e e28fe014 e1a07000 e28de
[   11.714310] f7a8  3891000f 3798f107 eaffffef e5ad0008 e1a02007 e1a0100d e3a02
[   11.722456] f7c8  eaffffb4 e320f000 e320f000 e320f000 e320f000 e320f000 c08dc
[   11.730602] f7e8  c01ac90c c01a18b8 c017fdf0 c0213c50 c0213cc0 c0213058 c0214
[   11.738748] f808  c0213080 c0220ef4 c0220cb0 c017fe00 c02129dc c01b8484 c022c
[   11.746894] f828  c01caabc c01b8484 c01b8484 c02135d0 c01a9ae8 c022f8a4 c01bc
[   11.755039] f848  c01cae7c c01b8484 c01a856c c01b8484 c01b8484 c01ada34 c01b4
[   11.763186]
[   11.763188] R9: 0xdbf91f80:
[   11.767432] 1f80  0002057f c01a1904 00000001 00000001 401f775c 401f775c 00004
[   11.775577] 1fa0  00000001 c017f640 00000001 401f775c 00000001 401fd870 00001
[   11.783723] 1fc0  00000001 401f775c 401f775c 000000f8 00000001 0001d198 0000f
[   11.791869] 1fe0  00099f14 bebdfc80 00099f30 4015f224 60000010 00000001 00000
[   11.800015] 2000  00000000 00000002 00000000 dbdef740 c08deb1c 00000000 00000
[   11.808161] 2020  dbf92000 c08ddf80 c08ddf80 dbdecd00 dbdb4380 00000000 dbf98
[   11.816307] 2040  c0682188 00000000 00000000 00000000 00000000 00000000 01010
[   11.824452] 2060  40f564c0 00000000 00000000 00000000 00000000 00000000 00000
[   11.832599]
[   11.832601] R10: 0xdc208640:
[   11.836931] 8640  dead4ead ffffffff ffffffff dc20864c dc20864c 00000000 00008
[   11.845077] 8660  00000000 00000000 c068d980 000200da c08effb8 00000001 deadf
[   11.853223] 8680  ffffffff dc208684 dc208684 00000000 dc208690 dc208690 00000
[   11.861369] 86a0  00000000 00000000 00000000 ffffffff ffffffff dc6fb990 dc208
[   11.869515] 86c0  000021b0 00000000 00000000 c0949f80 dbde5400 00000001 deadf
[   11.877660] 86e0  ffffffff 00000000 00000007 00000001 00000001 dead4ead fffff
[   11.885806] 8700  dc208700 dc208700 00000000 00000000 dc2086ec 00000000 00000
[   11.893952] 8720  dc208720 dc208720 dc208728 dc208728 dc207df0 dc209070 dc208
[   11.902100] Process test2 (pid: 1167, stack limit = 0xdbf922f0)
[   11.907993] Stack: (0xdbf93ef8 to 0xdbf94000)
[   11.912327] 3ee0:                                                       bf1e0
[   11.920475] 3f00: 000003e8 000003e8 0000000f c017f7e8 dc2086c0 c02227fc 00004
[   11.928620] 3f20: 00000000 00000000 00000000 00000020 00000001 dbf576c0 00004
[   11.936767] 3f40: dbf59c00 00000020 dbf92000 dc2086c0 00000000 c0211e78 c08c0
[   11.944913] 3f60: dbf59c00 0000000f dbf59c00 000003e8 00000001 0000000f c0170
[   11.953058] 3f80: 00000000 c0222d6c dbf92000 00000000 be856bcc be856b24 00010
[   11.961204] 3fa0: 00000036 c017f640 be856b24 000161b8 0000000f 00000001 00004
[   11.969350] 3fc0: be856b24 000161b8 be856bb0 00000036 00000000 00000000 400f0
[   11.977496] 3fe0: 00000000 be856b18 0000aedc 40ed74ec 60000010 0000000f 3fff1
[   11.985670] [<bf1e905c>] (s3c24xx_pwm_ioctl+0x3c/0x170 [aibo_pwm]) from [<c0)
[   11.995611] [<c02227fc>] (do_vfs_ioctl+0x80/0x5b8) from [<c0222d6c>] (sys_io)
[   12.003844] [<c0222d6c>] (sys_ioctl+0x38/0x60) from [<c017f640>] (ret_fast_s)
[   12.012247] Code: e1a04000 eb3e982a eb3e9791 e34e4250 (e5943008)
[   12.019549] ---[ end trace e84a0a3985a0941d ]---
[   19.524174] eth0: no IPv6 routers present


请求帮忙,谢谢!